List of usage examples for org.apache.commons.lang BooleanUtils toBooleanObject
public static Boolean toBooleanObject(String str)
Converts a String to a Boolean.
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:mitm.application.djigzo.james.mailets.AbstractDjigzoMailet.java
@Override public final void init() throws MessagingException { log = getInitParameter(Parameter.LOG.name); String param = getInitParameter(Parameter.LOG_LEVEL.name); if (param != null) { logLevel = LogLevel.valueOf(param.trim().toUpperCase()); }//from www . ja v a 2s. c om if (logLevel == null) { logLevel = LogLevel.INFO; } param = getInitParameter(Parameter.CATCH_RUNTIMEEXCEPTIONS.name); if (param != null) { Boolean bool = BooleanUtils.toBooleanObject(param); if (bool == null) { throw new IllegalArgumentException(param + " is not a valid boolean."); } catchRuntimeExceptions = bool; } param = getInitParameter(Parameter.CATCH_ERRORS.name); if (param != null) { Boolean bool = BooleanUtils.toBooleanObject(param); if (bool == null) { throw new IllegalArgumentException(param + " is not a valid boolean."); } catchErrors = bool; } StrBuilder sb = new StrBuilder(); sb.append("catchRuntimeExceptions: "); sb.append(catchRuntimeExceptions); sb.append("; "); sb.append("catchErrors: "); sb.append(catchErrors); getLogger().info(sb.toString()); initMailet(); }
From source file:lodsve.core.config.properties.PropertyConverter.java
/** * Convert the specified object into a Boolean. Internally the * {@code org.apache.commons.lang.BooleanUtils} class from the <a * href="http://commons.apache.org/lang/">Commons Lang</a> project is used * to perform this conversion. This class accepts some more tokens for the * boolean value of <b>true</b>, e.g. {@code yes} and {@code on}. Please * refer to the documentation of this class for more details. * /*from w ww. j a v a2 s . c om*/ * @param value * the value to convert * @return the converted value * @throws ConversionException * thrown if the value cannot be converted to a boolean */ public static Boolean toBoolean(Object value) throws ConversionException { if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { Boolean b = BooleanUtils.toBooleanObject((String) value); if (b == null) { throw new ConversionException("The value " + value + " can't be converted to a Boolean object"); } return b; } else { throw new ConversionException("The value " + value + " can't be converted to a Boolean object"); } }
From source file:jp.primecloud.auto.process.zabbix.ZabbixHostProcess.java
public void stopHost(Long instanceNo) { ZabbixInstance zabbixInstance = zabbixInstanceDao.read(instanceNo); if (zabbixInstance == null) { // Zabbix??? throw new AutoException("EPROCESS-000401", instanceNo); }//from www. jav a 2 s.c om if (StringUtils.isEmpty(zabbixInstance.getHostid())) { // ??????? return; } Instance instance = instanceDao.read(instanceNo); // if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100303", instanceNo, instance.getInstanceName())); } ZabbixProcessClient zabbixProcessClient = zabbixProcessClientFactory.createZabbixProcessClient(); // ? try { //??? String hostname = getHostName(instance.getFqdn()); //IP/DNS? Boolean useIp = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useIp")); //ZabbixID? String proxyHostid = getProxyHostid(zabbixProcessClient); zabbixProcessClient.updateHost(zabbixInstance.getHostid(), hostname, instance.getFqdn(), null, false, useIp, null, proxyHostid); // processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, null, instance, "ZabbixStop", new Object[] { instance.getFqdn(), zabbixInstance.getHostid() }); // ? zabbixInstance.setStatus(ZabbixInstanceStatus.UN_MONITORING.toString()); zabbixInstanceDao.update(zabbixInstance); } catch (AutoException ignore) { // ??????? log.warn(ignore.getMessage()); } // if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100304", instanceNo, instance.getInstanceName())); } }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * @param dataTypeClass/*from w w w. j a va 2 s . co m*/ * @param untypedValue * @return */ public static Object toDataType(Class<?> dataTypeClass, Object untypedValue) { if ((dataTypeClass == null) || (untypedValue == null) || ClassUtils.isAssignable(untypedValue.getClass(), dataTypeClass)) { if (Date.class == dataTypeClass) { return DateUtils.truncate(untypedValue, Calendar.DATE); } return untypedValue; } Object v = null; String strUntypedValue = null; boolean isStringUntypedValue = untypedValue instanceof String; Number numUntypedValue = null; boolean isNumberUntypedValue = untypedValue instanceof Number; if (isStringUntypedValue) { strUntypedValue = (String) untypedValue; } if (isNumberUntypedValue) { numUntypedValue = (Number) untypedValue; } if (dataTypeClass == boolean.class || dataTypeClass == Boolean.class) { if (isNumberUntypedValue) { v = BooleanUtils.toBooleanObject(numUntypedValue.intValue()); } else if (isStringUntypedValue) { v = BooleanUtils.toBooleanObject(strUntypedValue); } } else if (dataTypeClass == Integer.class) { if (isNumberUntypedValue) { v = new Integer(numUntypedValue.intValue()); } else if (isStringUntypedValue) { v = NumberUtils.createInteger(strUntypedValue); } } else if (dataTypeClass == Double.class) { if (isNumberUntypedValue) { v = new Double(numUntypedValue.doubleValue()); } else if (isStringUntypedValue) { v = NumberUtils.createDouble(strUntypedValue); } } else if (dataTypeClass == Date.class) { if (isNumberUntypedValue) { v = DateUtils.truncate(new Date(numUntypedValue.longValue()), Calendar.DATE); } } else { v = ObjectUtils.toString(untypedValue); } return v; }
From source file:mitm.application.djigzo.james.mailets.SendMailTemplate.java
@Override public void initMailet() throws MessagingException { getLogger().info("Initializing mailet: " + getMailetName()); templateBuilder = SystemServices.getTemplateBuilder(); loadTemplate();/*from w ww.j a v a2 s . co m*/ String param = getInitParameter(Parameter.PROCESSOR.name); if (param != null) { processor = param; } removeSMTPExtensions = getInitRemoveSMTPExtensions(); ignoreMissingRecipients = getIgnoreMissingRecipients(); param = getInitParameter(Parameter.PASS_THROUGH.name); if (param != null) { Boolean bool = BooleanUtils.toBooleanObject(param); if (bool == null) { throw new IllegalArgumentException(param + " is not a valid boolean."); } passThrough = bool; } passThroughProcessor = getInitParameter(Parameter.PASS_THROUGH_PROCESSOR.name); StrBuilder sb = new StrBuilder(); sb.append("template: "); sb.append(templateFile); sb.appendSeparator("; "); sb.appendSeparator("; "); sb.append("processor: "); sb.append(processor); sb.appendSeparator("; "); sb.append("removeSMTPExtensions: "); sb.append(removeSMTPExtensions); sb.appendSeparator("; "); sb.append("ignoreMissingRecipients: "); sb.append(ignoreMissingRecipients); sb.appendSeparator("; "); sb.append("passThrough"); sb.append(passThrough); sb.appendSeparator("; "); sb.append("passThroughProcessor"); sb.append(passThroughProcessor); getLogger().info(sb.toString()); }
From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
protected void loadFontPreferences(Element element) { // load font preferences String fontFamily = element.attributeValue("fontFamily"); String fontSize = element.attributeValue("fontSize"); String fontStyle = element.attributeValue("fontStyle"); String fontUnderline = element.attributeValue("fontUnderline"); if (!StringUtils.isBlank(fontFamily) && !StringUtils.isBlank(fontSize) && !StringUtils.isBlank(fontUnderline) && !StringUtils.isBlank(fontStyle)) { try {//from ww w . j a v a2 s.c o m int size = Integer.parseInt(fontSize); int style = Integer.parseInt(fontStyle); String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames(); int fontIndex = Arrays.asList(availableFonts).indexOf(fontFamily); if (fontIndex < 0) { log.debug("Unsupported font family, font settings not loaded"); return; } Configuration configuration = AppBeans.get(Configuration.NAME); DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class); int sizeIndex = desktopConfig.getAvailableFontSizes().indexOf(size); if (sizeIndex < 0) { log.debug("Unsupported font size, font settings not loaded"); return; } Boolean underline = BooleanUtils.toBooleanObject(fontUnderline); @SuppressWarnings("MagicConstant") Font font = new Font(fontFamily, style, size); if (underline != null && Boolean.TRUE.equals(underline)) { Map<TextAttribute, Integer> attributes = new HashMap<>(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); font = font.deriveFont(attributes); } table.setFont(font); } catch (NumberFormatException ex) { log.debug("Broken font definition in user setting"); } } }
From source file:jp.primecloud.auto.service.impl.ComponentServiceImpl.java
/** * {@inheritDoc}/*w ww . ja v a2 s . c o m*/ */ @Override public List<ComponentDto> getComponents(Long farmNo) { // ??? List<Component> components = new ArrayList<Component>(); List<Component> allComponents = componentDao.readByFarmNo(farmNo); for (Component component : allComponents) { // ??? if (BooleanUtils.isTrue(component.getLoadBalancer())) { continue; } components.add(component); } // ???? List<Long> componentNos = new ArrayList<Long>(); for (Component component : components) { componentNos.add(component.getComponentNo()); } // ?????? Map<Long, List<ComponentInstance>> componentInstanceMap = new LinkedHashMap<Long, List<ComponentInstance>>(); for (Long componentNo : componentNos) { componentInstanceMap.put(componentNo, new ArrayList<ComponentInstance>()); } List<ComponentInstance> tmpComponentInstances = componentInstanceDao.readInComponentNos(componentNos); for (ComponentInstance componentInstance : tmpComponentInstances) { // ????????? if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) { ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); if (status == ComponentInstanceStatus.STOPPED) { continue; } } componentInstanceMap.get(componentInstance.getComponentNo()).add(componentInstance); } Farm farm = farmDao.read(farmNo); List<Instance> instances = instanceDao.readByFarmNo(farmNo); Map<Long, Instance> instanceMap = new HashMap<Long, Instance>(); for (Instance instance : instances) { instanceMap.put(instance.getInstanceNo(), instance); } List<ComponentDto> dtos = new ArrayList<ComponentDto>(); for (Component component : components) { ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo()); List<InstanceConfig> instanceConfigs = instanceConfigDao.readByComponentNo(component.getComponentNo()); List<ComponentConfig> componentConfigs = componentConfigDao .readByComponentNo(component.getComponentNo()); List<ComponentInstance> componentInstances = componentInstanceMap.get(component.getComponentNo()); List<ComponentInstanceDto> componentInstanceDtos = new ArrayList<ComponentInstanceDto>(); // ??????? for (ComponentInstance componentInstance : componentInstances) { Instance instance = instanceMap.get(componentInstance.getInstanceNo()); ComponentInstanceStatus status = getComponentInstanceStatus(farm, componentInstance, instance); componentInstance.setStatus(status.toString()); } // ???? ComponentStatus componentStatus = getComponentStatus(componentInstances); // DTO??URL? for (ComponentInstance componentInstance : componentInstances) { ComponentInstanceDto componentInstanceDto = new ComponentInstanceDto(); componentInstanceDto.setComponentInstance(componentInstance); Instance instance = instanceMap.get(componentInstance.getInstanceNo()); // for (Instance tmpInstance : instances) { // if (componentInstance.getInstanceNo().equals(tmpInstance.getInstanceNo())) { // instance = tmpInstance; // break; // } // } String url; Boolean showPublicIp = BooleanUtils.toBooleanObject(Config.getProperty("ui.showPublicIp")); if (BooleanUtils.isTrue(showPublicIp)) { //ui.showPublicIp = true ???URL?PublicIp url = createUrl(instance.getPublicIp(), component.getComponentTypeNo()); } else { //ui.showPublicIp = false ???URL?PrivateIp url = createUrl(instance.getPrivateIp(), component.getComponentTypeNo()); } componentInstanceDto.setUrl(url); componentInstanceDtos.add(componentInstanceDto); } // // TODO: ???????? // for (ComponentInstanceDto componentInstanceDto : componentInstances) { // ComponentInstance componentInstance = componentInstanceDto.getComponentInstance(); // ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); // if (BooleanUtils.isTrue(componentInstance.getEnabled())) { // if (status == ComponentInstanceStatus.STOPPED) { // Instance instance = instanceMap.get(componentInstance.getInstanceNo()); // InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus()); // if (instanceStatus == InstanceStatus.WARNING) { // // ?Waring??????Warning?? // componentInstance.setStatus(ComponentInstanceStatus.WARNING.toString()); // } else if (BooleanUtils.isTrue(farm.getScheduled())) { // // ??????Starting?? // componentInstance.setStatus(ComponentInstanceStatus.STARTING.toString()); // } // } else if (status == ComponentInstanceStatus.RUNNING // && BooleanUtils.isTrue(componentInstance.getConfigure())) { // if (BooleanUtils.isTrue(farm.getScheduled())) { // // ???Running??????Configuring?? // componentInstance.setStatus(ComponentInstanceStatus.CONFIGURING.toString()); // } // } // } else { // if (status == ComponentInstanceStatus.RUNNING || status == ComponentInstanceStatus.WARNING) { // if (BooleanUtils.isTrue(farm.getScheduled())) { // // ??????Stopping?? // componentInstance.setStatus(ComponentInstanceStatus.STOPPING.toString()); // } // } // } // } // // ???? // ComponentStatus componentStatus; // Set<ComponentInstanceStatus> statuses = new HashSet<ComponentInstanceStatus>(); // for (ComponentInstanceDto componentInstanceDto : componentInstances) { // statuses.add(ComponentInstanceStatus // .fromStatus(componentInstanceDto.getComponentInstance().getStatus())); // } // if (statuses.contains(ComponentInstanceStatus.WARNING)) { // componentStatus = ComponentStatus.WARNING; // } else if (statuses.contains(ComponentInstanceStatus.CONFIGURING)) { // componentStatus = ComponentStatus.CONFIGURING; // } else if (statuses.contains(ComponentInstanceStatus.RUNNING)) { // if (statuses.contains(ComponentInstanceStatus.STARTING)) { // componentStatus = ComponentStatus.CONFIGURING; // } else if (statuses.contains(ComponentInstanceStatus.STOPPING)) { // componentStatus = ComponentStatus.CONFIGURING; // } else { // componentStatus = ComponentStatus.RUNNING; // } // } else if (statuses.contains(ComponentInstanceStatus.STARTING)) { // componentStatus = ComponentStatus.STARTING; // } else if (statuses.contains(ComponentInstanceStatus.STOPPING)) { // componentStatus = ComponentStatus.STOPPING; // } else { // componentStatus = ComponentStatus.STOPPED; // } // Collections.sort(componentInstanceDtos, Comparators.COMPARATOR_COMPONENT_INSTANCE_DTO); ComponentDto dto = new ComponentDto(); dto.setComponent(component); dto.setComponentType(componentType); dto.setComponentConfigs(componentConfigs); dto.setComponentInstances(componentInstanceDtos); dto.setInstanceConfigs(instanceConfigs); dto.setStatus(componentStatus.toString()); dtos.add(dto); } // Collections.sort(dtos, Comparators.COMPARATOR_COMPONENT_DTO); return dtos; }
From source file:jp.primecloud.auto.service.impl.FarmServiceImpl.java
/** * {@inheritDoc}/*w ww. j a va 2 s . co m*/ */ @Override public Long createFarm(Long userNo, String farmName, String comment) { // ? if (userNo == null) { throw new AutoApplicationException("ECOMMON-000003", "userNo"); } if (farmName == null || farmName.length() == 0) { throw new AutoApplicationException("ECOMMON-000003", "farmName"); } // ?? if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", farmName)) { throw new AutoApplicationException("ECOMMON-000012", "farmName"); } // TODO: ?? // ????? Farm checkFarm = farmDao.readByFarmName(farmName); if (checkFarm != null) { // ??????? throw new AutoApplicationException("ESERVICE-000201", farmName); } // ??? // TODO: ??????? String domainName = farmName + "." + Config.getProperty("dns.domain"); // ?? Farm farm = new Farm(); farm.setFarmName(farmName); farm.setUserNo(userNo); farm.setComment(comment); farm.setDomainName(domainName); farm.setScheduled(false); farm.setComponentProcessing(false); farmDao.create(farm); List<Platform> platforms = platformDao.readAll(); for (Platform platform : platforms) { // TODO CLOUD BRANCHING // VMware?? if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) { if (vmwareKeyPairDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0) { // ???VLAN? VmwareNetwork publicNetwork = null; VmwareNetwork privateNetwork = null; List<VmwareNetwork> vmwareNetworks = vmwareNetworkDao .readByPlatformNo(platform.getPlatformNo()); for (VmwareNetwork vmwareNetwork : vmwareNetworks) { if (vmwareNetwork.getFarmNo() != null) { continue; } if (BooleanUtils.isTrue(vmwareNetwork.getPublicNetwork())) { if (publicNetwork == null) { publicNetwork = vmwareNetwork; } } else { if (privateNetwork == null) { privateNetwork = vmwareNetwork; } } } // VLAN? if (publicNetwork != null) { publicNetwork.setFarmNo(farm.getFarmNo()); vmwareNetworkDao.update(publicNetwork); } if (privateNetwork != null) { privateNetwork.setFarmNo(farm.getFarmNo()); vmwareNetworkDao.update(privateNetwork); } } // VCloud?? } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType())) { //????????????vApp?? if (BooleanUtils.isTrue(platform.getSelectable()) && vcloudCertificateDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0 && vcloudKeyPairDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0) { //vApp? IaasGatewayWrapper gateway = iaasGatewayFactory.createIaasGateway(userNo, platform.getPlatformNo()); gateway.createMyCloud(farmName); } // Azure?? } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) { // ???? // OpenStack?? } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) { // ???? } } // VCloud?(iaasGateWay??????)??Zabbix???????? // ???? Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix")); if (BooleanUtils.isTrue(useZabbix)) { zabbixHostProcess.createFarmHostgroup(farm.getFarmNo()); } // eventLogger.log(EventLogLevel.INFO, farm.getFarmNo(), farmName, null, null, null, null, "FarmCreate", null, null, null); return farm.getFarmNo(); }
From source file:com.adaptris.core.management.BootstrapProperties.java
public static boolean isEnabled(Properties p, String key) { String val = PropertyHelper.getPropertyIgnoringCase(p, key); return BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(val), enabledByDefault(key)); }
From source file:com.hybris.backoffice.cockpitng.search.DefaultAdvancedSearchOperatorServiceTest.java
protected DataAttribute createMockDataAttributeTemplate(final boolean isAtomic, final Class valueTypeClass, final DataAttribute.AttributeType attributeType) { final DataAttribute dataAttribute = Mockito.mock(DataAttribute.class); final DataType valueType = Mockito.mock(DataType.class); Mockito.when(BooleanUtils.toBooleanObject(valueType.isAtomic())) .thenReturn(BooleanUtils.toBooleanObject(isAtomic)); Mockito.when(valueType.getClazz()).thenReturn(valueTypeClass); Mockito.when(dataAttribute.getValueType()).thenReturn(valueType); Mockito.when(dataAttribute.getAttributeType()).thenReturn(attributeType); Assertions.assertThat(dataAttribute.getValueType().isAtomic()).isEqualTo(isAtomic); Assertions.assertThat(dataAttribute.getValueType().getClazz()).isEqualTo(valueTypeClass); Assertions.assertThat(dataAttribute.getAttributeType()).isEqualTo(attributeType); return dataAttribute; }