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.soaplab.services.cmdline.ChoiceListParameter.java
/************************************************************************** * Extract and return values for this parameter from 'inputs', or * from default. Actually, it does not return values from * 'inputs', but if the 'inputs' have a TRUE value for this * parameter, then the tag of this parameter is returned as its * value.//from w ww. j a v a2 s.c o m * * Return an empty array (not null) if there was no value in * 'inputs' and no default value is defined. * * The returned value can have more values because this parameter * represents zero, one or more booleans. * * Parameter 'job' (where this parameter belongs to) is not used * here. **************************************************************************/ protected String[] getValues(Map<String, Object> inputs, Job job) throws ParameterException { List<String> values = new ArrayList<String>(); // look for values of individual 'bools' which are subparts of // this parameter, concatenate values if more of them found for (ParamDef boolDef : ((ChoiceParamDef) paramDef).bools) { // extract value from input - look only for TRUE, // and ignore default value, for now Object value = ignoreArray(inputs.get(boolDef.id)); if (value != null && StringUtils.isNotBlank(value.toString())) if (BooleanUtils.toBoolean(value.toString())) { // if a TRUE value found, add it to the result values.add(boolDef.get(ParamDef.TAG)); } } if (values.size() > 0) return values.toArray(new String[] {}); // if we have not found _any_ value... boolean useDefaults = paramDef.is(ParamDef.USE_DEFAULTS); // for ZERO_OR_MORE type, and without a need to use defaults, // just return an empty array if (((ChoiceParamDef) paramDef).choiceType == ChoiceParamDef.ZERO_OR_MORE && !useDefaults) { return ArrayUtils.EMPTY_STRING_ARRAY; } // for ONE_OR_MORE type, look for defaults (if there are more // default values I am adding them here all, but AppLab1 was // just taking the last found value - what is more correct?) for (ParamDef boolDef : ((ChoiceParamDef) paramDef).bools) { // if a positive default found, remember it (it may be // used if USE_DEFAULTS is on) if (BooleanUtils.toBoolean(boolDef.dflt)) { values.add(boolDef.get(ParamDef.TAG)); } } if (values.size() > 0 && useDefaults) return values.toArray(new String[] {}); // if the value is still empty, we have a problem because the // choice type must be now ONE_OR_MORE - and we have nothing, // what a shame... throw new ParameterException(paramDef.id, "At least one option must be specified for: " + paramDef.get(SoaplabConstants.DATA_PROMPT)); }
From source file:org.soaplab.services.cmdline.ChoiceParameter.java
/************************************************************************** * Extract and return value for this parameter from 'inputs', or * from default. Actually, it does not return a value from * 'inputs', but if the 'inputs' have a TRUE value for this * parameter, then the tag of this parameter is returned as its * value./*from w w w. ja va 2 s . co m*/ * * Return an empty array (not null) if there was no value in * 'inputs' and no default value is defined. * * The returned array is expected to have always maximum one * element. * * Parameter 'job' (where this parameter belongs to) is not used * here. **************************************************************************/ protected String[] getValues(Map<String, Object> inputs, Job job) throws ParameterException { // look for values of individual 'bools' which are subparts of // this parameter, stop when the first is found for (ParamDef boolDef : ((ChoiceParamDef) paramDef).bools) { // extract value from input - look only for TRUE, // and ignore default value, for now Object value = ignoreArray(inputs.get(boolDef.id)); if (value != null && StringUtils.isNotBlank(value.toString())) if (BooleanUtils.toBoolean(value.toString())) { // a TRUE value found return new String[] { boolDef.get(ParamDef.TAG) }; } } // for ZERO_OR_ONE type, we do not need to use defaults, just // return an empty array if (((ChoiceParamDef) paramDef).choiceType == ChoiceParamDef.ZERO_OR_ONE) return ArrayUtils.EMPTY_STRING_ARRAY; // no defaults needed // for JUST_ONE type, if we are here it means that no value // was found - not for a single boolean sub-parameter; find // the first (should be the only one) default value for (ParamDef boolDef : ((ChoiceParamDef) paramDef).bools) { if (BooleanUtils.toBoolean(boolDef.dflt)) { // a TRUE default value found return new String[] { boolDef.get(ParamDef.TAG) }; } } // if we are here it means that no value was found for // JUST_ONE type (and no default was specified) throw new ParameterException(paramDef.id, "At least one option must be specified."); }
From source file:org.soaplab.services.Config.java
/************************************************************************** * Almost the same functionality as {@link #getString getString} * method - see there details about parameters - except that it * expects property value to be a boolean. <p> * * For the property values 'true', 'on', 'yes' (case insensitive), * and for an empty value it returns true. For other values, false * is returned. If the property does not exist at all, the * 'defaultValue' is returned. <p> **************************************************************************/ public static boolean isEnabled(String key, boolean defaultValue, String serviceName, Object owner) { String strValue = getString(key, null, serviceName, owner); if (strValue == null) return defaultValue; if (StringUtils.isBlank(strValue)) return true; return BooleanUtils.toBoolean(strValue); }
From source file:org.soaplab.services.metadata.PropertiesBag.java
/************************************************************************** * Returns true if an option defined by a 'key' is present and has * a true value. Used for elements of type String and Boolean. **************************************************************************/ public boolean is(String key) { if (containsKey(key)) { Object value = get(key);/*from w w w .j a v a 2 s. c o m*/ if (value instanceof Boolean) return ((Boolean) value).booleanValue(); return BooleanUtils.toBoolean((String) value); } return false; }
From source file:org.soaplab.services.Reporter.java
/****************************************************************************** * Retrieve and return all available results, set so far. ******************************************************************************/ public Map<String, Object> getResults() throws SoaplabException { Map<String, Object> results = percy.getResults(job.getId()); if (!results.containsKey(SoaplabConstants.RESULT_REPORT)) { results.put(SoaplabConstants.RESULT_REPORT, createReportResult()); }/* w w w. j a va2 s. c o m*/ results.put(SoaplabConstants.RESULT_DETAILED_STATUS, createDetailedStatusResult()); // in special cases, some (non-URL) outputs may be ignored // (added May 2011) if (metadataAccessor != null) { List<String> toBeIgnored = new ArrayList<String>(); Map<String, Object>[] resultSpec = MetadataUtils.outputSpec2Map(metadataAccessor); // find those to be ignored... for (int i = 0; i < resultSpec.length; i++) { String name = (String) resultSpec[i].get(SoaplabConstants.RESULT_NAME); if (name.endsWith(SoaplabConstants.URL_RESULT_SUFFIX)) { continue; // never ignore the URL-based results } // only outputs with a specific option in metadata are ignored String ignored = (String) resultSpec[i].get(SoaplabConstants.IGNORED_RESULT); if (ignored != null && BooleanUtils.toBoolean(ignored)) { toBeIgnored.add(name); } } // ...and remove them from the result for (String name : toBeIgnored) { results.remove(name); } } return results; }
From source file:org.sonar.plugins.codesize.CodeSizeBatchExtension.java
public boolean shouldExecuteOnProject(Project project) { String value = project.getConfiguration().getString(CodesizeConstants.SONAR_CODESIZE_ACTIVE); return BooleanUtils.toBoolean(value); }
From source file:org.sonar.plugins.web.markup.validation.MarkupReport.java
/** * Parse report, read errors and warnings. *//*from ww w . j ava 2s . com*/ private void parse(File reportFile) { this.reportFile = reportFile; if (!reportFile.exists()) { throw new SonarException("File does not exist: " + reportFile.getPath()); } Document document = parseSoapMessage(reportFile); if (document != null) { NodeList nodeList = document.getElementsByTagName("m:validity"); for (int i = 0; i < nodeList.getLength(); i++) { valid = BooleanUtils.toBoolean(nodeList.item(i).getTextContent()); } nodeList = document.getElementsByTagName("m:error"); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); errors.add(createMessage(element)); } nodeList = document.getElementsByTagName("m:warning"); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); warnings.add(createMessage(element)); } } }
From source file:org.sparkcommerce.core.web.processor.OnePageCheckoutProcessor.java
/** * This method is responsible of populating the variables necessary to draw the checkout page. * This logic is highly dependent on your layout. If your layout does not follow the same flow * as the HeatClinic demo, you will need to override with your own custom layout implementation * * @param localVars//from ww w. j ava2 s . c om */ protected void populateSectionViewStates(Map<String, Object> localVars) { boolean orderInfoPopulated = hasPopulatedOrderInfo(CartState.getCart()); boolean billingPopulated = hasPopulatedBillingAddress(CartState.getCart()); boolean shippingPopulated = hasPopulatedShippingAddress(CartState.getCart()); localVars.put("orderInfoPopulated", orderInfoPopulated); localVars.put("billingPopulated", billingPopulated); localVars.put("shippingPopulated", shippingPopulated); //Logic to show/hide sections based on state of the order // show all sections including header unless specifically hidden // (e.g. hide shipping if no shippable items in order or hide billing section if the order payment doesn't need // an address i.e. PayPal Express) boolean showBillingInfoSection = true; boolean showShippingInfoSection = true; boolean showAllPaymentMethods = true; int numShippableFulfillmentGroups = calculateNumShippableFulfillmentGroups(); if (numShippableFulfillmentGroups == 0) { showShippingInfoSection = false; } boolean orderContainsThirdPartyPayment = false; boolean orderContainsUnconfirmedCreditCard = false; OrderPayment unconfirmedCC = null; if (CartState.getCart().getPayments() != null) { for (OrderPayment payment : CartState.getCart().getPayments()) { if (payment.isActive() && PaymentType.THIRD_PARTY_ACCOUNT.equals(payment.getType())) { orderContainsThirdPartyPayment = true; } if (payment.isActive() && (PaymentType.CREDIT_CARD.equals(payment.getType()) && !PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType()))) { orderContainsUnconfirmedCreditCard = true; unconfirmedCC = payment; } } } //Toggle the Payment Info Section based on what payments were applied to the order //(e.g. Third Party Account (i.e. PayPal Express) or Gift Cards/Customer Credit) Money orderTotalAfterAppliedPayments = CartState.getCart().getTotalAfterAppliedPayments(); if (orderContainsThirdPartyPayment || orderContainsUnconfirmedCreditCard) { showBillingInfoSection = false; showAllPaymentMethods = false; } else if (orderTotalAfterAppliedPayments != null && orderTotalAfterAppliedPayments.isZero()) { //If all the applied payments (e.g. gift cards) cover the entire amount //we don't need to show all payment method options. showAllPaymentMethods = false; } localVars.put("showBillingInfoSection", showBillingInfoSection); localVars.put("showAllPaymentMethods", showAllPaymentMethods); localVars.put("orderContainsThirdPartyPayment", orderContainsThirdPartyPayment); localVars.put("orderContainsUnconfirmedCreditCard", orderContainsUnconfirmedCreditCard); localVars.put("unconfirmedCC", unconfirmedCC); //The Sections are all initialized to INACTIVE view List<CheckoutSectionDTO> drawnSections = new LinkedList<CheckoutSectionDTO>(); CheckoutSectionDTO orderInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.ORDER_INFO, orderInfoPopulated); CheckoutSectionDTO billingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.BILLING_INFO, billingPopulated); CheckoutSectionDTO shippingInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.SHIPPING_INFO, shippingPopulated); CheckoutSectionDTO paymentInfoSection = new CheckoutSectionDTO(CheckoutSectionViewType.PAYMENT_INFO, false); String orderInfoHelpMessage = (String) localVars.get("orderInfoHelpMessage"); String billingInfoHelpMessage = (String) localVars.get("billingInfoHelpMessage"); String shippingInfoHelpMessage = (String) localVars.get("shippingInfoHelpMessage"); //Add the Order Info Section drawnSections.add(orderInfoSection); //Add the Billing Section if (showBillingInfoSection) { billingInfoSection.setHelpMessage(orderInfoHelpMessage); drawnSections.add(billingInfoSection); } //Add the Shipping Section if (showShippingInfoSection) { if (showBillingInfoSection) { shippingInfoSection.setHelpMessage(billingInfoHelpMessage); } else { shippingInfoSection.setHelpMessage(orderInfoHelpMessage); } drawnSections.add(shippingInfoSection); } //Add the Payment Section if (showShippingInfoSection) { paymentInfoSection.setHelpMessage(shippingInfoHelpMessage); } else if (showBillingInfoSection) { paymentInfoSection.setHelpMessage(billingInfoHelpMessage); } else { paymentInfoSection.setHelpMessage(orderInfoHelpMessage); } drawnSections.add(paymentInfoSection); //Logic to toggle state between form view, saved view, and inactive view //This is dependent on the layout of your checkout form. Override this if layout is different. //initialize first view to always be a FORM view CheckoutSectionDTO firstSection = drawnSections.get(0); firstSection.setState(CheckoutSectionStateType.FORM); //iterate through all the drawn sections and set their state based on the state of the other sections. for (ListIterator<CheckoutSectionDTO> itr = drawnSections.listIterator(); itr.hasNext();) { CheckoutSectionDTO previousSection = null; if (itr.hasPrevious()) { previousSection = drawnSections.get(itr.previousIndex()); } CheckoutSectionDTO section = itr.next(); //if the previous section is populated, set this section to a Form View if (previousSection != null && previousSection.isPopulated()) { section.setState(CheckoutSectionStateType.FORM); } //If this sections is populated then set this section to the Saved View if (section.isPopulated()) { section.setState(CheckoutSectionStateType.SAVED); } //Custom Logic to handle a state where there may have been an error on the Payment Gateway //and the customer is booted back to the checkout page and will have to re-enter their billing address //and payment information as there may have been an error on either. Since, to handle all gateways with the same layout //we are breaking the Billing Address Form from the Payment Info Form, to serve a better UX, we will have hide the payment info as //the customer will need to re-enter their billing address to try again. //{@see DefaultPaymentGatewayCheckoutService where payments are invalidated on an unsuccessful transaction} if (CheckoutSectionViewType.PAYMENT_INFO.equals(section.getView())) { if (showBillingInfoSection && !billingPopulated) { section.setState(CheckoutSectionStateType.INACTIVE); section.setHelpMessage(billingInfoHelpMessage); } } //Finally, if the edit button is explicitly clicked, set the section to Form View SparkRequestContext blcContext = SparkRequestContext.getSparkRequestContext(); HttpServletRequest request = blcContext.getRequest(); boolean editOrderInfo = BooleanUtils.toBoolean(request.getParameter("edit-order-info")); boolean editBillingInfo = BooleanUtils.toBoolean(request.getParameter("edit-billing")); boolean editShippingInfo = BooleanUtils.toBoolean(request.getParameter("edit-shipping")); if (CheckoutSectionViewType.ORDER_INFO.equals(section.getView()) && editOrderInfo) { section.setState(CheckoutSectionStateType.FORM); } else if (CheckoutSectionViewType.BILLING_INFO.equals(section.getView()) && editBillingInfo) { section.setState(CheckoutSectionStateType.FORM); } else if (CheckoutSectionViewType.SHIPPING_INFO.equals(section.getView()) && editShippingInfo) { section.setState(CheckoutSectionStateType.FORM); } } localVars.put("checkoutSectionDTOs", drawnSections); }
From source file:org.springbyexample.enterprise.solr.CatalogItemMarshaller.java
/** * Implementation of <code>Unmarshaller</code> *//*from w ww . ja v a2s .c om*/ @SuppressWarnings("unchecked") public Object unmarshal(Source source) throws XmlMappingException, IOException { List<CatalogItem> lResults = new ArrayList<CatalogItem>(); if (source instanceof StreamSource) { InputStream in = null; try { in = ((StreamSource) source).getInputStream(); SAXReader reader = new SAXReader(); Document document = reader.read(in); List<Node> lNodes = document.selectNodes("//response/result[@name='response']/doc/*"); CatalogItem item = null; // loop over all matching nodes in order, so can create a new bean // instance on the first match and add it to the results on the last for (Node node : lNodes) { if (BooleanUtils.toBoolean(node.valueOf("./@name='id'"))) { item = new CatalogItem(); item.setId(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='inStock'"))) { item.setInStock(BooleanUtils.toBoolean(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='manu'"))) { item.setManufacturer(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='name'"))) { item.setName(node.getText()); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='popularity'"))) { item.setPopularity(Integer.parseInt(node.getText())); } else if (BooleanUtils.toBoolean(node.valueOf("./@name='price'"))) { item.setPrice(Float.parseFloat(node.getText())); lResults.add(item); } } } catch (DocumentException e) { throw new UnmarshallingFailureException(e.getMessage(), e); } finally { IOUtils.closeQuietly(in); } logger.debug("Unmarshalled bean of size {}.", lResults.size()); } return lResults; }
From source file:org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction.java
private String buildArtifactVersionForReferencedJob(ProcessItem routeProcess, String jobId) { boolean isSnapshot = BooleanUtils.toBoolean((String) routeProcess.getProperty().getAdditionalProperties() .get(MavenConstants.NAME_PUBLISH_AS_SNAPSHOT)); String jobArtifactVersion = getJobProcessItemVersion(jobId); if (jobArtifactVersion == null || jobArtifactVersion.isEmpty()) { return ""; }/*from ww w . j a v a 2s. c o m*/ if (!jobArtifactVersion.endsWith(MavenConstants.SNAPSHOT) && isSnapshot) { jobArtifactVersion += MavenConstants.SNAPSHOT; } else if (jobArtifactVersion.endsWith(MavenConstants.SNAPSHOT) && !isSnapshot) { jobArtifactVersion = jobArtifactVersion.substring(0, jobArtifactVersion.lastIndexOf(MavenConstants.SNAPSHOT)); } return jobArtifactVersion; }