Example usage for org.apache.commons.lang BooleanUtils toBoolean

List of usage examples for org.apache.commons.lang BooleanUtils toBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils toBoolean.

Prototype

public static boolean toBoolean(String str) 

Source Link

Document

Converts a String to a boolean (optimised for performance).

'true', 'on' or 'yes' (case insensitive) will return true.

Usage

From source file:org.talend.dataprep.transformation.actions.line.MakeLineHeader.java

@Override
public void applyOnLine(DataSetRow row, ActionContext context) {
    Map<String, String> parameters = context.getParameters();
    String skipUntilStr = parameters.get(SKIP_UNTIL);
    // default is true
    boolean skipPreviousRows = StringUtils.isBlank(skipUntilStr) || BooleanUtils.toBoolean(skipUntilStr);

    long tdpId = row.getTdpId();
    long rowId = NumberUtils.toLong(parameters.get(ImplicitParameters.ROW_ID.getKey()), 0);

    if (skipPreviousRows && (tdpId < rowId)) {
        row.setDeleted(true);//from w ww .  j a  v  a2  s .  c  om
    } else if (context.getFilter().test(row)) {
        setHeadersFromRow(row, context);
    } else {
        setRemainingRowColumnsNames(context);
    }
}

From source file:org.talend.designer.esb.webservice.WebServiceNode.java

public boolean getBooleanValue(String key) {
    Object value = getParamValue(key);
    if (value == null) {
        return false;
    }/*from  w ww .ja va  2 s.  co  m*/
    if (value instanceof Boolean) {
        return (Boolean) value;
    }
    return BooleanUtils.toBoolean(value.toString());
}

From source file:org.tonguetied.web.KeywordController.java

private boolean isFilterApplied(final HttpSession session) {
    final Boolean isFilterApplied = (Boolean) session.getAttribute(APPLY_FILTER);
    return BooleanUtils.toBoolean(isFilterApplied);
}

From source file:org.unitedinternet.cosmo.calendar.ICalDate.java

/**
 * Parses any time.
 * @param str The string.
 */
private void parseAnyTime(String str) {
    anytime = BooleanUtils.toBoolean(str);
}

From source file:org.webguitoolkit.ui.controls.form.OptionControl.java

public void loadFrom(Object data) {
    if (managedByGroup)
        return;/*w  ww.  j a  v  a2 s  .c o m*/

    boolean val;
    if (data == null) {
        val = false;
    } else {
        Object fromModel = PropertyAccessor.retrieveProperty(data, getProperty());
        if (fromModel == null) {
            val = false;
        } else {
            if (getOptionValue() != null) {
                val = getOptionValue().equals(fromModel.toString());
            } else {
                val = BooleanUtils.toBoolean((fromModel.toString()));
            }
        }
    }
    // The type must be boolean indicating if this thingi is set or not
    setSelected(val);
}

From source file:org.wso2.carbon.identity.password.policy.handler.PasswordPolicyValidationHandler.java

@Override
public void handleEvent(Event event) throws IdentityEventException {

    Map<String, Object> eventProperties = event.getEventProperties();

    String userName = (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME);
    String tenantDomain = (String) eventProperties.get(IdentityEventConstants.EventProperty.TENANT_DOMAIN);
    Object credentials = eventProperties.get(IdentityEventConstants.EventProperty.CREDENTIAL);

    Property[] identityProperties;/*from  ww w .  j a v a2 s .  co m*/
    try {
        identityProperties = IdentityPasswordPolicyServiceDataHolder.getInstance()
                .getIdentityGovernanceService().getConfiguration(getPropertyNames(), tenantDomain);
    } catch (IdentityGovernanceException e) {
        throw new IdentityEventException("Error while retrieving password policy properties.", e);
    }

    /*initialize to default values*/
    boolean passwordPolicyValidation = false;
    String pwMinLength = "6";
    String pwMaxLength = "12";
    String pwPattern = "^((?=.*\\\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&*])).{0,100}$";
    String errorMsg = "Password pattern policy violated. Password should contain a digit[0-9], a lower case "
            + "letter[a-z], an upper case letter[A-Z], one of !@#$%&* characters";

    for (Property identityProperty : identityProperties) {

        if (identityProperty == null) {
            continue;
        }

        String propertyName = identityProperty.getName();
        String propertyValue = identityProperty.getValue();

        if (PasswordPolicyConstants.PW_POLICY_ENABLE.equals(propertyName)) {
            passwordPolicyValidation = BooleanUtils.toBoolean(propertyValue);
            if (!passwordPolicyValidation) {
                if (log.isDebugEnabled()) {
                    log.debug("Password Policy validation is disabled");
                }
                return;
            }
            continue;
        } else if (PasswordPolicyConstants.PW_POLICY_MIN_LENGTH.equals(propertyName)) {
            if (NumberUtils.isNumber(propertyValue) && Integer.parseInt(propertyValue) > 0) {
                pwMinLength = propertyValue;
            } else {
                log.warn("Password Policy MIN Length is not correct hence using default value: " + pwMinLength);
            }
            continue;
        } else if (PasswordPolicyConstants.PW_POLICY_MAX_LENGTH.equals(propertyName)) {
            if (NumberUtils.isNumber(propertyValue) && Integer.parseInt(propertyValue) > 0) {
                pwMaxLength = propertyValue;
            } else {
                log.warn("Password Policy MAX Length is not correct hence using default value: " + pwMaxLength);
            }
            continue;
        } else if (PasswordPolicyConstants.PW_POLICY_PATTERN.equals(propertyName)) {
            if (StringUtils.isNotBlank(propertyValue)) {
                pwPattern = propertyValue;
            } else {
                log.warn("Password Policy Pattern is not correct hence using default value: " + pwPattern);
            }
            continue;
        } else if (PasswordPolicyConstants.PW_POLICY_ERROR_MSG.equals(propertyName)) {
            if (StringUtils.isNotBlank(propertyValue)) {
                errorMsg = propertyValue;
            } else {
                log.warn("Password Policy Error Msg cannot be Empty hence using default Msg: " + errorMsg);
            }
            continue;
        }
    }

    PolicyRegistry policyRegistry = new PolicyRegistry();

    String pwLengthPolicyCls = configs.getModuleProperties()
            .getProperty(PasswordPolicyConstants.PW_POLICY_LENGTH_CLASS);
    String pwNamePolicyCls = configs.getModuleProperties()
            .getProperty(PasswordPolicyConstants.PW_POLICY_NAME_CLASS);
    String pwPatternPolicyCls = configs.getModuleProperties()
            .getProperty(PasswordPolicyConstants.PW_POLICY_PATTERN_CLASS);
    try {
        if (StringUtils.isNotBlank(pwLengthPolicyCls)) {
            DefaultPasswordLengthPolicy defaultPasswordLengthPolicy = (DefaultPasswordLengthPolicy) Class
                    .forName(pwLengthPolicyCls).newInstance();
            HashMap pwPolicyLengthParams = new HashMap<String, String>();
            pwPolicyLengthParams.put("min.length", pwMinLength);
            pwPolicyLengthParams.put("max.length", pwMaxLength);
            defaultPasswordLengthPolicy.init(pwPolicyLengthParams);
            policyRegistry.addPolicy(defaultPasswordLengthPolicy);
        }

        if (StringUtils.isNotBlank(pwNamePolicyCls)) {
            DefaultPasswordNamePolicy defaultPasswordNamePolicy = (DefaultPasswordNamePolicy) Class
                    .forName(pwNamePolicyCls).newInstance();
            policyRegistry.addPolicy(defaultPasswordNamePolicy);
        }

        if (StringUtils.isNotBlank(pwPatternPolicyCls)) {
            DefaultPasswordPatternPolicy defaultPasswordPatternPolicy = (DefaultPasswordPatternPolicy) Class
                    .forName(pwPatternPolicyCls).newInstance();
            HashMap pwPolicyPatternParams = new HashMap<String, String>();
            pwPolicyPatternParams.put("pattern", pwPattern);
            pwPolicyPatternParams.put("errorMsg", errorMsg);
            defaultPasswordPatternPolicy.init(pwPolicyPatternParams);
            policyRegistry.addPolicy(defaultPasswordPatternPolicy);
        }
    } catch (Exception e) {
        throw Utils.handleEventException(
                PasswordPolicyConstants.ErrorMessages.ERROR_CODE_LOADING_PASSWORD_POLICY_CLASSES, null, e);
    }

    try {
        policyRegistry.enforcePasswordPolicies(credentials.toString(), userName);
    } catch (PolicyViolationException e) {
        throw Utils.handleEventException(
                PasswordPolicyConstants.ErrorMessages.ERROR_CODE_VALIDATING_PASSWORD_POLICY, e.getMessage(), e);
    }
}

From source file:org.xwiki.pdf.multipageexport.internal.XslFopPdfExporter.java

/**
 * Prepares and gets the XDOM for a single document.
 * // ww w  . j  a v a2 s  . c  om
 * @param doc the document to get the xdom for
 * @param multiPageSequence whether the pdf changes header on every new document or presents them all as a single
 *            document
 * @param startOnRecto whether this document rendering should always start on recto
 * @param pdfTemplateDoc the template document used for this export
 * @param pagesList the total list of pages to be exported, needed so that the xdom preparation can be done in
 *            context
 * @return the prepared xdom for the passed document
 * @throws Exception in case there are errors parsing this document in XDOM or preparing it
 */
private XDOM getXDOMForDoc(XWikiDocument doc, boolean multiPageSequence, boolean startOnRecto,
        XWikiDocument pdfTemplateDoc, List<String> pagesList) throws Exception {
    XDOM childXdom = (doc == null) ? null : doc.getXDOM();
    childXdom = (childXdom == null) ? null : childXdom.clone();

    // execute the transformations to have the fully transformed xdom here

    // prepare a bit the context
    // 1. put the document on the execution context
    Map<String, Object> backupObjects = new HashMap<String, Object>();
    documentAccessBridge.pushDocumentInContext(backupObjects, doc.getDocumentReference());
    // 2. backup the xwiki context variables since we're gonna put some stuff in there as well
    XWikiContext currentEcXContext = (XWikiContext) execution.getContext().getProperty("xwikicontext");
    String originalDatabase = currentEcXContext.getDatabase();
    String originalAction = currentEcXContext.getAction();
    // we need to change this to mimic properly the export action and allow proper interpretation of the fields in
    // pdf templates. isInRendering engine needs to be true when document content is rendered and false for the rest
    // since otherwise will add some {{html}} macros around the rendered fields which are not in the export action
    // this is true here because we call this service from a page content which is being rendered on view
    Boolean originalIsInRenderingEngine = BooleanUtils
            .toBoolean((Boolean) currentEcXContext.get("isInRenderingEngine"));
    // sdoc is used to determine the syntax of the rendered fields, back it up and set it to the current document
    Object originalSDoc = currentEcXContext.get("sdoc");
    Object originalVContext = currentEcXContext.get("vcontext");
    // prepare here the cdoc on the vcontext which we will replace, for each exported document, with the exported
    // document. we're doing this since cdoc is hackishly used by the pdf header and footer of the pdf template
    // since otherwise there is no other way to obtain the currently exported document
    VelocityContext newVContext = vManager.getVelocityContext();
    Object newVContextOriginalCDoc = newVContext.get("cdoc");
    try {
        // 3. setup xwiki context
        currentEcXContext.setDatabase(doc.getDocumentReference().getWikiReference().getName());
        currentEcXContext.setAction("export");
        // is in rendering engine must be true for document content, false for all the other vms evaluated
        // (header / footer)
        currentEcXContext.put("isInRenderingEngine", true);
        // at this point, the velocity context of the xwiki context and the ones of the execution context are
        // different, because the current document was pushed in the context. So we need to reput it back here,
        // however we back it up because xcontext is never cloned when the context is backed up, so we need to put
        // back the proper one when we're done
        currentEcXContext.put("vcontext", newVContext);
        // prepare the cdoc on the vcontext so that it can be used inside the pdftemplate fields rendering
        newVContext.put("cdoc", newVContext.get("doc"));
        // set current document as the sdoc, since the sdoc is used to get syntax for rendered fields and
        // programming rights check
        currentEcXContext.put("sdoc", doc);
        // 4. display xdom of the document (apply sheet -- if any, perform transformations)
        DocumentDisplayerParameters parameters = new DocumentDisplayerParameters();
        parameters.setTransformationContextIsolated(true);
        parameters.setContentTranslated(true);
        childXdom = documentDisplayer.display(doc, parameters);
        // is in rendering engine must be true for document content, false for all the other vms evaluated
        // (header / footer)
        currentEcXContext.put("isInRenderingEngine", false);
        // 5. process references in the XDOM for export, since they need to be either relative to the pdf (if links
        // to documents in the same pdf export), or absolute (if images or external documents)
        updateXDOMReferences(doc, childXdom, pagesList);
        // 6. decorate the xdom with stuff needed for the export: if multipagesequences, add header and footer,
        // otherwise title and id
        String renderedTitle = doc.getRenderedTitle(Syntax.XHTML_1_0, currentEcXContext);
        if (multiPageSequence) {
            // render document header and footer in this nice context as well, if they are needed
            String renderedHeader = getRenderedField(pdfTemplateDoc, "header", currentEcXContext);
            String renderedFooter = getRenderedField(pdfTemplateDoc, "footer", currentEcXContext);
            childXdom = wrapupXDOMWithHeaders(doc, childXdom, renderedTitle, renderedHeader, renderedFooter,
                    startOnRecto);
        } else {
            // add some title and id in front of the rendered document
            XDOM decoratedXDom = new XDOM(Collections.<Block>emptyList());
            IdBlock idBlock = new IdBlock(
                    "child_" + this.defaultERSerializer.serialize(doc.getDocumentReference()).hashCode());
            // add a title and the content
            String rawTitle = doc.getTitle();
            // we only insert a title if specified or not specified and not extracted up from content (compatibility
            // mode)
            // TODO: fix this condition, it doesn't actually mean that the title was not extracted from document,
            // as the title extracted from document can be the same as the document name, but there is no usable
            // function to find out what is the extracted title
            if (!StringUtils.isEmpty(rawTitle) || (StringUtils.isEmpty(rawTitle)
                    && renderedTitle.equals(doc.getDocumentReference().getName()))) {
                Parser parser = Utils.getComponent(Parser.class, Syntax.PLAIN_1_0.toIdString());
                List<Block> childlist = parser.parse(new StringReader(renderedTitle)).getChildren().get(0)
                        .getChildren();
                int level = 1;
                HeaderLevel hLevel = HeaderLevel.parseInt(level);
                HeaderBlock hBlock = new HeaderBlock(childlist, hLevel, new HashMap<String, String>(),
                        idBlock.getName());

                decoratedXDom.addChild(hBlock);
            } else {
                // Append the id macro -> to be able to link here with the links from documents exported in the same
                // pdf
                decoratedXDom.addChild(idBlock);
            }
            decoratedXDom.addChildren(childXdom.getChildren());
            childXdom = decoratedXDom;
        }
    } finally {
        // restore execution context
        documentAccessBridge.popDocumentFromContext(backupObjects);
        // restore xwiki context
        currentEcXContext.setDatabase(originalDatabase);
        currentEcXContext.setAction(originalAction);
        // make sure to check all these for not-null since context doesn't get null values, and just in case one of
        // them is null, we're dead
        if (originalIsInRenderingEngine != null) {
            currentEcXContext.put("isInRenderingEngine", originalIsInRenderingEngine);
        }
        if (originalVContext != null) {
            currentEcXContext.put("vcontext", originalVContext);
        }
        // restore the original state of the cdoc on the newVContext
        if (newVContextOriginalCDoc != null) {
            newVContext.put("cdoc", newVContextOriginalCDoc);
        } else {
            newVContext.remove("cdoc");
        }
        if (originalSDoc != null) {
            currentEcXContext.put("sdoc", originalSDoc);
        }
    }

    return childXdom;
}

From source file:org.yamj.core.tools.player.davidbox.DavidBoxPlayerPath.java

@JsonProperty("isFolder")
public void setFolder(String folder) {
    this.folder = BooleanUtils.toBoolean(folder);
}

From source file:play.modules.thymeleaf.ThymeleafPlugin.java

@Override
public void onLoad() {
    this.enhancerEnabled = BooleanUtils
            .toBoolean(Play.configuration.getProperty("thymeleaf.enhancer.enabled", "true"));
    Logger.debug("thymeleaf plugin enhancer enabled ? :%s", enhancerEnabled);
}

From source file:pt.webdetails.cte.web.CteApi.java

@GET
@Path(Constants.ENDPOINT_EDITOR + "/{" + PROVIDER + ": [^?]+ }/{ " + PATH + ": [^?]+ }")
@Produces(MimeTypes.HTML)//w w w  .  j  av  a  2  s.co m
public void edit(@PathParam(PROVIDER) String provider, @PathParam(PATH) String path,
        @QueryParam(Constants.PARAM_BYPASS_CACHE) @DefaultValue("false") String bypassCache,
        @Context HttpServletResponse response) throws WebApplicationException {

    try {

        InputStream fis = null;

        if (!StringUtils.isEmpty(path) && isValidProvider(provider)
                && getProvider(provider).canRead(sanitize(path))) {

            fis = getProvider(provider).getFile(sanitize(path));
        }

        PluginIOUtils.writeOutAndFlush(response.getOutputStream(),
                getEngine().getEditor().getEditor(fis, BooleanUtils.toBoolean(bypassCache)));

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}