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:info.magnolia.cms.util.BooleanUtil.java
/** * Behaves much like org.apache.commons.lang.BooleanUtils but returns the defaultValue if * the input string is null, empty, or unrecognized. *///from w w w. ja v a 2s .co m public static boolean toBoolean(String s, boolean defaultValue) { final Boolean b = BooleanUtils.toBooleanObject(s); return b == null ? defaultValue : b.booleanValue(); }
From source file:com.mindquarry.webapp.ajax.LightboxRequestSelector.java
public Object getSelectorContext(Map objectModel, Parameters parameters) { Request req = ObjectModelHelper.getRequest(objectModel); return BooleanUtils.toBooleanObject(req.getParameter(LIGHTBOX_REQUEST) != null); }
From source file:com.redhat.rhn.frontend.dto.BooleanWrapper.java
/** * Sets the boolean value to true if the aBool is 1, false if aBool is 0. * @param aBool the value to be used//from www. ja v a2 s . co m */ public void setBool(Integer aBool) { bool = BooleanUtils.toBooleanObject(aBool); }
From source file:com.redhat.rhn.frontend.action.user.UserPrefSetupAction.java
/** {@inheritDoc} */ public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {//from ww w.j av a2 s .co m DynaActionForm form = (DynaActionForm) formIn; RequestContext requestContext = new RequestContext(request); Long uid = requestContext.getParamAsLong("uid"); //UserPreferences under /rhn/users needs parameter, but /rhn/account does not if (request.getRequestURL().toString().indexOf("/rhn/users/") != -1 && uid == null) { throw new BadParameterException("Invalid [null] value for parameter uid"); } User user = UserManager.lookupUser(requestContext.getCurrentUser(), uid); request.setAttribute(RhnHelper.TARGET_USER, user); if (user == null) { user = requestContext.getCurrentUser(); } form.set("uid", user.getId()); form.set("emailNotif", BooleanUtils.toBooleanObject(user.getEmailNotify())); form.set("pagesize", new Integer(user.getPageSize())); form.set("csvSeparator", user.getCsvSeparator()); setupTasks(form, user); request.setAttribute("pagesizes", getPageSizes()); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }
From source file:com.haulmont.cuba.gui.xml.layout.loaders.FilterLoader.java
@Override public void loadComponent() { assignXmlDescriptor(resultComponent, element); assignFrame(resultComponent);// ww w .ja v a 2 s .com loadAlign(resultComponent, element); loadVisible(resultComponent, element); loadEnable(resultComponent, element); loadStyleName(resultComponent, element); loadMargin(resultComponent, element); loadIcon(resultComponent, element); loadCaption(resultComponent, element); loadDescription(resultComponent, element); loadWidth(resultComponent, element, "100%"); loadCollapsible(resultComponent, element, true); loadSettingsEnabled(resultComponent, element); loadBorderVisible(resultComponent, element); String useMaxResults = element.attributeValue("useMaxResults"); resultComponent.setUseMaxResults(useMaxResults == null || Boolean.parseBoolean(useMaxResults)); String textMaxResults = element.attributeValue("textMaxResults"); resultComponent.setTextMaxResults(Boolean.parseBoolean(textMaxResults)); final String manualApplyRequired = element.attributeValue("manualApplyRequired"); resultComponent.setManualApplyRequired(BooleanUtils.toBooleanObject(manualApplyRequired)); String editable = element.attributeValue("editable"); resultComponent.setEditable(editable == null || Boolean.parseBoolean(editable)); String columnsCount = element.attributeValue("columnsCount"); if (!Strings.isNullOrEmpty(columnsCount)) { resultComponent.setColumnsCount(Integer.parseInt(columnsCount)); } String folderActionsEnabled = element.attributeValue("folderActionsEnabled"); if (folderActionsEnabled != null) { resultComponent.setFolderActionsEnabled(Boolean.parseBoolean(folderActionsEnabled)); } String datasource = element.attributeValue("datasource"); if (!StringUtils.isBlank(datasource)) { CollectionDatasource ds = (CollectionDatasource) context.getDsContext().get(datasource); if (ds == null) { throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId()); } resultComponent.setDatasource(ds); } Frame frame = context.getFrame(); String applyTo = element.attributeValue("applyTo"); if (!StringUtils.isEmpty(applyTo)) { context.addPostInitTask((context1, window) -> { Component c = frame.getComponent(applyTo); if (c == null) { throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context1.getFullFrameId()); } resultComponent.setApplyTo(c); }); } String modeSwitchVisible = element.attributeValue("modeSwitchVisible"); resultComponent.setModeSwitchVisible(modeSwitchVisible == null || Boolean.parseBoolean(modeSwitchVisible)); context.addPostInitTask((context1, window) -> { ((FilterImplementation) resultComponent).loadFiltersAndApplyDefault(); String defaultMode = element.attributeValue("defaultMode"); if (defaultMode != null && "fts".equals(defaultMode)) { resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE); } }); }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * //from w w w . j a va 2 s .com * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }
From source file:de.hybris.platform.acceleratorservices.config.impl.AbstractConfigLookup.java
@Override public boolean getBoolean(final String key, final boolean defaultValue) { final String property = getProperty(key); if (property != null && !property.isEmpty()) { try {/*from w ww .ja v a2s . c o m*/ return Boolean.TRUE.equals(BooleanUtils.toBooleanObject(property)); } catch (final NumberFormatException ex) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to parse boolean property value for key [" + key + "] value was [" + property + "]", ex); } } } return defaultValue; }
From source file:jp.primecloud.auto.process.zabbix.ZabbixHostProcess.java
public void startHost(Long instanceNo) { ZabbixInstance zabbixInstance = zabbixInstanceDao.read(instanceNo); if (zabbixInstance == null) { // Zabbix??? throw new AutoException("EPROCESS-000401", instanceNo); }/* w ww . j a v a2 s . c o m*/ Instance instance = instanceDao.read(instanceNo); Platform platform = platformDao.read(instance.getPlatformNo()); // if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100301", instanceNo, instance.getInstanceName())); } ZabbixProcessClient zabbixProcessClient = zabbixProcessClientFactory.createZabbixProcessClient(); String hostid = zabbixInstance.getHostid(); log.info("********hostid:" + hostid); //??? String hostname = getHostName(instance.getFqdn()); //IP/DNS? Boolean useIp = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useIp")); //ZabbixID? String proxyHostid = getProxyHostid(zabbixProcessClient); //IP String zabbixListenIp = getZabbixListenIp(zabbixProcessClient, instance, platform); if (StringUtils.isEmpty(hostid)) { List<Hostgroup> hostgroups = getInitHostgroups(zabbixProcessClient, instance); // ? hostid = zabbixProcessClient.createHost(hostname, instance.getFqdn(), hostgroups, true, useIp, zabbixListenIp, proxyHostid); // processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, null, instance, "ZabbixRegist", new Object[] { instance.getFqdn(), hostid }); // ? zabbixInstance.setHostid(hostid); zabbixInstance.setStatus(ZabbixInstanceStatus.MONITORING.toString()); zabbixInstanceDao.update(zabbixInstance); } else { // ? zabbixProcessClient.updateHost(hostid, hostname, instance.getFqdn(), null, true, useIp, zabbixListenIp, proxyHostid); // ? zabbixInstance.setStatus(ZabbixInstanceStatus.MONITORING.toString()); zabbixInstanceDao.update(zabbixInstance); // processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, null, instance, "ZabbixStart", new Object[] { instance.getFqdn(), hostid }); } // ?? Image image = imageDao.read(instance.getImageNo()); String templateName = image.getZabbixTemplate(); if (StringUtils.isEmpty(templateName)) { // TODO: ?????????? templateName = Config.getProperty("zabbix.basetemplate"); } Template template = zabbixProcessClient.getTemplateByName(templateName); boolean ret = zabbixProcessClient.addTemplate(hostid, template); if (ret) { // processLogger.writeLogSupport(ProcessLogger.LOG_DEBUG, null, instance, "ZabbixTemplateAdd", new Object[] { instance.getFqdn(), templateName }); } // if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100302", instanceNo, instance.getInstanceName())); } }
From source file:info.magnolia.cms.gui.dialog.DialogControlImpl.java
public void setConfig(String key, boolean value) { this.config.put(key, BooleanUtils.toBooleanObject(value).toString()); }
From source file:info.magnolia.cms.beans.config.Server.java
/** * Cache server content from the config repository. *//* w ww .j a va2 s . c om*/ private static void cacheServerConfiguration(Content page) { boolean isAdmin = page.getNodeData("admin").getBoolean(); //$NON-NLS-1$ Server.cachedContent.put("admin", BooleanUtils.toBooleanObject(isAdmin)); //$NON-NLS-1$ String ext = page.getNodeData("defaultExtension").getString(); //$NON-NLS-1$ Server.cachedContent.put("defaultExtension", ext); //$NON-NLS-1$ String basicRealm = page.getNodeData("basicRealm").getString(); //$NON-NLS-1$ Server.cachedContent.put("basicRealm", basicRealm); //$NON-NLS-1$ Server.cachedContent.put("404URI", page.getNodeData("ResourceNotAvailableURIMapping").getString()); //$NON-NLS-1$ //$NON-NLS-2$ boolean visibleToObinary = page.getNodeData("visibleToObinary").getBoolean(); //$NON-NLS-1$ Server.cachedContent.put("visibleToObinary", BooleanUtils.toBooleanObject(visibleToObinary)); //$NON-NLS-1$ }