List of usage examples for org.apache.commons.lang BooleanUtils toBoolean
public static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:org.eclipse.wb.internal.core.utils.binding.ValueUtils.java
/** * Extract <code>boolean</code> from given object. *///from w w w . ja va2s. c o m public static boolean objectToBoolean(Object value) { // extract from Boolean if (value instanceof Boolean) { Boolean booleanObject = (Boolean) value; return booleanObject.booleanValue(); } // extract from Object String stringObject = ObjectUtils.toString(value); return BooleanUtils.toBoolean(stringObject); }
From source file:org.efaps.ui.wicket.components.picker.PickerCallBack.java
/** * Check if for the current values the escape is activated.<br> * Default: true,<br>/*from ww w . ja v a 2s .c om*/ * key exits: null = false else evaluation of given String * @param _map map to be checked * @return boolean */ private boolean escape(final Map<String, Object> _map) { boolean ret = true; if (_map.containsKey(EFapsKey.PICKER_DEACTIVATEESCAPE.getKey())) { final Object value = _map.get(EFapsKey.PICKER_DEACTIVATEESCAPE.getKey()); if (value == null) { ret = false; } else { ret = BooleanUtils.toBoolean(EFapsKey.PICKER_DEACTIVATEESCAPE.getKey()); } } return ret; }
From source file:org.ejbca.extra.db.BaseCertRequest.java
/** * Returns the CREATEUSER used in this request, and converts it to boolean * @return true or false/*from w w w. j a va 2 s . c o m*/ */ public boolean createOrEditUser() { String ret = (String) data.get(CREATEOREDITEUSER); return BooleanUtils.toBoolean(ret); }
From source file:org.fabrician.enabler.KarafContainer.java
@Override protected void doInit(List<RuntimeContextVariable> additionalVariables) throws Exception { getEngineLogger().fine("doInit invoked"); clusterFeatureInfo = (KarafClusteringInfo) ContainerUtils.getFeatureInfo(KarafClusteringInfo.FEATURE_NAME, this, getCurrentDomain()); httpFeatureInfo = (HttpFeatureInfo) ContainerUtils.getFeatureInfo(Feature.HTTP_FEATURE_NAME, this, getCurrentDomain());//from ww w. j a v a2 s . c o m boolean httpEnabled = isHttpEnabled(); boolean httpsEnabled = isHttpsEnabled(); if (!httpEnabled && !httpsEnabled) { throw new Exception("HTTP or HTTPS must be enabled in the Domain"); } if (httpEnabled && !DynamicVarsUtils.validateIntegerVariable(this, HttpFeatureInfo.HTTP_PORT_VAR)) { throw new Exception("HTTP is enabled but the " + HttpFeatureInfo.HTTP_PORT_VAR + " runtime context variable is not set"); } if (httpsEnabled && !DynamicVarsUtils.validateIntegerVariable(this, HttpFeatureInfo.HTTPS_PORT_VAR)) { throw new Exception("HTTPS is enabled but the " + HttpFeatureInfo.HTTPS_PORT_VAR + " runtime context variable is not set"); } if (DynamicVarsUtils.variableHasValue(KARAF_DEBUG, "true") && !DynamicVarsUtils.validateIntegerVariable(this, KARAF_DEBUG_PORT)) { throw new Exception(KARAF_DEBUG_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_JMX_RMI_SERVER_PORT)) { throw new Exception(KARAF_JMX_RMI_SERVER_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_JMX_RMI_REGISTRY_PORT)) { throw new Exception(KARAF_JMX_RMI_REGISTRY_PORT + " runtime context variable is not set properly"); } if (!DynamicVarsUtils.validateIntegerVariable(this, KARAF_SSH_PORT)) { throw new Exception(KARAF_SSH_PORT + " runtime context variable is not set properly"); } String bindAllStr = getStringVariableValue(BIND_ON_ALL_LOCAL_ADDRESSES, "true"); boolean bindAll = BooleanUtils.toBoolean(bindAllStr); String karafBindAddress = bindAll ? "0.0.0.0" : getStringVariableValue(LISTEN_ADDRESS_VAR); additionalVariables.add(new RuntimeContextVariable(KARAF_BIND_ADDRESS, karafBindAddress, RuntimeContextVariable.STRING_TYPE)); additionalVariables.add(new RuntimeContextVariable(KARAF_JMX_SERVICE_URL, getJmxServiceUrl(), RuntimeContextVariable.STRING_TYPE, "Karaf JMX service url")); if (clusterFeatureInfo == null) { additionalVariables.add(new RuntimeContextVariable(CELLAR_CLUSTERING_ENABLED, "false", RuntimeContextVariable.STRING_TYPE)); } else { String group_membership = StringUtils .trimToEmpty(resolveVariables(clusterFeatureInfo.getGroupMembership())); group_membership = StringUtils.isBlank(group_membership) ? "default" : group_membership; String[] groups = StringUtils.splitByWholeSeparator(group_membership, ","); for (String g : groups) { if (StringUtils.trimToEmpty(g).isEmpty()) { throw new Exception( "'Cellar Group Membership' value specified in the Clustering feature is not set properly."); } } group_membership = StringUtils.join(groups, ","); // get rid of some misplaced "," additionalVariables.add(new RuntimeContextVariable(CELLAR_CLUSTERING_ENABLED, "true", RuntimeContextVariable.STRING_TYPE)); additionalVariables.add(new RuntimeContextVariable(CELLAR_GROUP_MEMBERSHIP, group_membership, RuntimeContextVariable.STRING_TYPE)); } super.doInit(additionalVariables); }
From source file:org.fao.geonet.kernel.search.LuceneQueryBuilder.java
/** * Add search privilege criteria to a query. * //from w ww . java 2s. c o m * @param luceneQueryInput user and system input * @param query query being built */ private void addPrivilegeQuery(LuceneQueryInput luceneQueryInput, BooleanQuery query) { // Set user groups privileges Set<String> groups = luceneQueryInput.getGroups(); String editable$ = luceneQueryInput.getEditable(); boolean editable = BooleanUtils.toBoolean(editable$); BooleanQuery groupsQuery = new BooleanQuery(); boolean groupsQueryEmpty = true; BooleanClause.Occur groupOccur = LuceneUtils.convertRequiredAndProhibitedToOccur(false, false); if (!CollectionUtils.isEmpty(groups)) { for (String group : groups) { if (StringUtils.isNotBlank(group)) { if (!editable) { // add to view TermQuery viewQuery = new TermQuery(new Term(LuceneIndexField._OP0, group.trim())); BooleanClause viewClause = new BooleanClause(viewQuery, groupOccur); groupsQueryEmpty = false; groupsQuery.add(viewClause); } // add to edit TermQuery editQuery = new TermQuery(new Term(LuceneIndexField._OP2, group.trim())); BooleanClause editClause = new BooleanClause(editQuery, groupOccur); groupsQueryEmpty = false; groupsQuery.add(editClause); } } } // // owner: this goes in groups query. This way if you are logged in you // can retrieve the results you are allowed // to see by your groups, plus any that you own not assigned to any // group. // String owner = luceneQueryInput.getOwner(); if (owner != null) { TermQuery ownerQuery = new TermQuery(new Term(LuceneIndexField.OWNER, owner)); BooleanClause.Occur ownerOccur = LuceneUtils.convertRequiredAndProhibitedToOccur(false, false); BooleanClause ownerClause = new BooleanClause(ownerQuery, ownerOccur); groupsQueryEmpty = false; groupsQuery.add(ownerClause); } // // "dummy" -- to go in groups query, to retrieve everything for // Administrator users. // boolean admin = luceneQueryInput.getAdmin(); if (admin) { TermQuery adminQuery = new TermQuery(new Term(LuceneIndexField.DUMMY, "0")); BooleanClause adminClause = new BooleanClause(adminQuery, groupOccur); groupsQueryEmpty = false; groupsQuery.add(adminClause); } // // GroupOwner: destroy groups query and rewrite to get results with // specified groupOwner (usually goes with admin) // Set<String> groupOwners = luceneQueryInput.getGroupOwners(); if (!CollectionUtils.isEmpty(groupOwners)) { groupsQuery = new BooleanQuery(); for (String groupOwner : groupOwners) { TermQuery groupOwnerQuery = new TermQuery(new Term(LuceneIndexField.GROUP_OWNER, groupOwner)); BooleanClause groupOwnerClause = new BooleanClause(groupOwnerQuery, groupOccur); groupsQueryEmpty = false; groupsQuery.add(groupOwnerClause); } } // Add the privilege part of the query if (!groupsQueryEmpty) { BooleanClause.Occur groupsOccur = LuceneUtils.convertRequiredAndProhibitedToOccur(true, false); BooleanClause groupsClause = new BooleanClause(groupsQuery, groupsOccur); query.add(groupsClause); } }
From source file:org.fao.geonet.services.util.SearchDefaults.java
/** * Returns default values for the search parameters. If request params are * set, they're used. If parameters have changed in the user session, they * are read out here./*from ww w .j a v a2 s.c o m*/ * * @param srvContext the service context * @param request the request * @return the default search */ public static Element getDefaultSearch(UserSession session, Element request) { Element result = new Element(Jeeves.Elem.REQUEST); // Add Request result = merge(result, request); // Add session if (session != null) { // If the session default parameters is missing or is set to 'true', 'on' or 'yes', merge the stored // session parameters with the other parameters. if (BooleanUtils.toBoolean(Util.getParam(request, USE_SESSION_DEFAULTS, Boolean.TRUE.toString()))) { Element sessionElement = (Element) session.getProperty(Geonet.Session.MAIN_SEARCH); // Set params in session for future use result = merge(result, sessionElement); } } // Add default params result = merge(result, DEFAULT_PARAMS); // Update session if (session != null) { session.setProperty(Geonet.Session.MAIN_SEARCH, result); } return result; }
From source file:org.gbif.portal.web.controller.download.DownloadController.java
/** * Retrieve a set of file properties from the file descriptor and the file itself. * // w w w . ja va 2 s . c o m * @param file * @param fileDescriptor * @return * @throws FileNotFoundException * @throws IOException * @throws ParseException */ private Map<String, Object> getFileProperties(File file, File fileDescriptor) throws FileNotFoundException, IOException, ParseException { Map<String, Object> loadedProperties = new HashMap<String, Object>(); if (fileDescriptor.exists()) { FileInputStream fInput = new FileInputStream(fileDescriptor); Properties properties = new Properties(); properties.load(fInput); String createdDate = properties.getProperty("createdDate"); Date created = null; if (createdDate != null) { SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy HHmm.ss"); created = sdf.parse(createdDate); loadedProperties.put("createdDate", created); } boolean displayTimeTaken = BooleanUtils.toBoolean(properties.getProperty("displayTimeTaken")); if (created != null && displayTimeTaken) { if (file != null) { Date lastModified = new Date(file.lastModified()); long timeTakenInMillis = lastModified.getTime() - created.getTime(); loadedProperties.put("timeTakenInMillis", timeTakenInMillis); } } String fileType = properties.getProperty("fileType"); String fileDescription = properties.getProperty("fileDescription"); String originalUrl = properties.getProperty("originalUrl"); if (fileType != null) loadedProperties.put("fileType", fileType); if (fileDescription != null) loadedProperties.put("fileDescription", fileDescription); if (originalUrl != null) loadedProperties.put("originalUrl", originalUrl); } return loadedProperties; }
From source file:org.hippoecm.frontend.model.TraceMonitorTest.java
@Test public void testDefault() throws Exception { boolean enabled = BooleanUtils.toBoolean(System.getProperty(TraceMonitor.ENABLED_PROP)); int maxSize = NumberUtils.toInt(System.getProperty(TraceMonitor.MAX_PROP), -1); if (maxSize < 0) { maxSize = TraceMonitor.DEFAULT_MAX_SIZE; }// w ww . j av a 2 s . c o m if (!enabled) { log.info("Testing the default setting without any system properties..."); for (int i = 1; i <= maxSize; i++) { TraceMonitor.track(MockNode.root().addNode("node-" + i, "nt:unstructured")); assertEquals(0, TraceMonitor.getSize()); } } else { if (maxSize == 0) { log.info("Testing the setting with `-DTraceMonitor.enabled=true -DTraceMonitor.max=0' ..."); for (int i = 1; i <= maxSize; i++) { TraceMonitor.track(MockNode.root().addNode("node-" + i, "nt:unstructured")); assertEquals(i, TraceMonitor.getSize()); } int doubledMaxSize = 2 * maxSize; for (int i = maxSize; i <= doubledMaxSize; i++) { TraceMonitor.track(MockNode.root().addNode("node-" + i, "nt:unstructured")); assertEquals(i, TraceMonitor.getSize()); } } else { log.info( "Testing the setting with `-DTraceMonitor.enabled=true -DTraceMonitor.max=N' (N is 2000 by default) ..."); for (int i = 1; i <= maxSize; i++) { TraceMonitor.track(MockNode.root().addNode("node-" + i, "nt:unstructured")); assertEquals(i, TraceMonitor.getSize()); } // one more cycle to track, but the size shouldn't increase over the maximum. for (int i = 1; i <= maxSize; i++) { TraceMonitor.track(MockNode.root().addNode("node-" + i, "nt:unstructured")); assertEquals(maxSize, TraceMonitor.getSize()); } } } }
From source file:org.hoteia.qalingo.core.cache.CustomVelocityLayoutView.java
@Override protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception { try {/*w ww . j ava 2 s .co m*/ // EhCacheCacheManager ehCacheCacheManager = (EhCacheCacheManager) getAttributesMap().get("ehCacheCacheManager"); // CacheManager cacheManager = ehCacheCacheManager.getCacheManager(); // String cacheName = (String) getAttributesMap().get("cacheName"); // Cache cache = cacheManager != null && StringUtils.isNotEmpty(cacheName) ? cacheManager.getCache(cacheName) : null; HttpServletRequest request = ((ChainedContext) context).getRequest(); boolean isGet = StringUtils.equals("GET", request.getMethod()); Object contextUseCache = context.get("useCache"); Boolean useCache = Boolean.TRUE; if (contextUseCache instanceof Boolean) { useCache = (Boolean) contextUseCache; } else if (contextUseCache instanceof String) { useCache = BooleanUtils.toBoolean((String) contextUseCache); } boolean cacheable = useCache != null ? useCache : !isAjax(request) && isGet; // if (!cacheable || cache == null) { template.merge(context, response.getWriter()); // } else { // StringWriter outputWriter = new StringWriter(); // template.merge(context, outputWriter); // outputWriter.close(); // String output = outputWriter.toString(); // // cache.put(new Element(getRequestKey(request), output)); // // response.getWriter().write(output); // } } catch (MethodInvocationException ex) { logger.error("Fail to merge template.", ex); Throwable cause = ex.getWrappedThrowable(); throw new NestedServletException( "Method invocation failed during rendering of Velocity view with name '" + getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() + "], method '" + ex.getMethodName() + "'", cause == null ? ex : cause); } }
From source file:org.hoteia.qalingo.core.domain.AbstractAttribute.java
public void setValue(String value) throws ParseException { AttributeDefinition attributeDefinition = getAttributeDefinition(); if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_SHORT_STRING) { setShortStringValue(value);//from w ww . j a va 2 s . c o m } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_LONG_STRING) { setLongStringValue(value); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_DOUBLE) { setDoubleValue(new Double(value)); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_FLOAT) { setFloatValue(new Float(value)); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_INTEGER) { setIntegerValue(new Integer(value)); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_BLOB) { setBlobValue(value.getBytes()); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_BOOLEAN) { setBooleanValue(BooleanUtils.toBoolean(value)); } else if (attributeDefinition.getAttributeType() == AttributeDefinition.ATTRIBUTE_TYPE_DATE) { setDateValue(AttributeDefinition.fullAttributeDateFormat.parse(value)); } }