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.hoteia.qalingo.web.mvc.controller.security.LoginController.java

@RequestMapping(FoUrls.LOGIN_URL)
public ModelAndView login(final HttpServletRequest request, final Model model) throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            FoUrls.LOGIN.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final Locale locale = requestData.getLocale();

    // SANITY CHECK: Customer logged
    if (securityUtil.isAuthenticated()) {
        final String url = urlService.generateUrl(FoUrls.PERSONAL_DETAILS, requestUtil.getRequestData(request));
        return new ModelAndView(new RedirectView(url));
    }/*from   w ww  .  j  av  a  2  s. c om*/

    // SANITY CHECK : Param from spring-security
    String error = request.getParameter(RequestConstants.REQUEST_PARAMETER_AUTH_ERROR);
    if (BooleanUtils.toBoolean(error)) {
        model.addAttribute(ModelConstants.AUTH_HAS_FAIL, BooleanUtils.toBoolean(error));
        model.addAttribute(ModelConstants.AUTH_ERROR_MESSAGE,
                getCommonMessage(ScopeCommonMessage.AUTH, "login_or_password_are_wrong", locale));
    }

    overrideDefaultPageTitle(request, modelAndView, FoUrls.LOGIN.getKey());

    model.addAttribute(ModelConstants.BREADCRUMB_VIEW_BEAN, buildBreadcrumbViewBean(requestData));

    return modelAndView;
}

From source file:org.hoteia.qalingo.web.mvc.controller.security.LoginController.java

@RequestMapping(FoUrls.CART_AUTH_URL)
public ModelAndView checkoutAuth(final HttpServletRequest request, final Model model) throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            FoUrls.LOGIN.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final Locale locale = requestData.getLocale();

    // SANITY CHECK: Customer logged
    final Customer currentCustomer = requestData.getCustomer();
    if (currentCustomer != null) {
        final String url = urlService.generateRedirectUrl(FoUrls.CART_DELIVERY,
                requestUtil.getRequestData(request));
        return new ModelAndView(new RedirectView(url));
    }/*from   w  w  w .  ja v a2 s .  com*/

    // SANITY CHECK : Param from spring-security
    String error = request.getParameter(RequestConstants.REQUEST_PARAMETER_AUTH_ERROR);
    if (BooleanUtils.toBoolean(error)) {
        model.addAttribute(ModelConstants.AUTH_HAS_FAIL, BooleanUtils.toBoolean(error));
        model.addAttribute(ModelConstants.AUTH_ERROR_MESSAGE,
                getCommonMessage(ScopeCommonMessage.AUTH, "login_or_password_are_wrong", locale));
    }

    overrideDefaultPageTitle(request, modelAndView, FoUrls.CART_AUTH.getKey());

    modelAndView.addObject(ModelConstants.CHECKOUT_STEP, 2);

    return modelAndView;
}

From source file:org.inquidia.kettle.plugins.tokenreplacement.TokenReplacement.java

public synchronized boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (TokenReplacementMeta) smi;/*from  w  w  w. j a v a 2  s .  co  m*/
    data = (TokenReplacementData) sdi;

    boolean result = true;
    Object[] r = getRow(); // This also waits for a row to be finished.

    if (first && r != null) {
        first = false;

        data.inputRowMeta = getInputRowMeta();
        data.outputRowMeta = getInputRowMeta().clone();

        if (meta.getOutputType().equalsIgnoreCase("field")) {
            meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

        }
        if (meta.getOutputType().equalsIgnoreCase("file") && !meta.isOutputFileNameInField()) {
            if (meta.getOutputFileName() != null) {
                String filename = meta.buildFilename(meta.getOutputFileName(), getTransMeta(), getCopy(),
                        getPartitionID(), data.splitnr);
                openNewOutputFile(filename);
            } else {
                throw new KettleException("Output file name cannot be null.");
            }
        }
    }

    if (r == null) {
        // no more input to be expected...
        closeAllOutputFiles();
        setOutputDone();
        return false;
    }

    if (meta.getOutputType().equalsIgnoreCase("file") && !meta.isOutputFileNameInField()
            && meta.getSplitEvery() > 0 && data.rowNumber % meta.getSplitEvery() == 0) {
        if (data.rowNumber > 0) {
            closeAllOutputFiles();
            data.splitnr++;
            String filename = meta.buildFilename(meta.getOutputFileName(), getTransMeta(), getCopy(),
                    getPartitionID(), data.splitnr);
            openNewOutputFile(filename);
        }
    }

    String outputFilename = "";
    if (meta.getOutputType().equalsIgnoreCase("file") && !meta.isOutputFileNameInField()) {
        outputFilename = meta.buildFilename(meta.getOutputFileName(), getTransMeta(), getCopy(),
                getPartitionID(), data.splitnr);
    } else if (meta.getOutputType().equalsIgnoreCase("file") && meta.isOutputFileNameInField()) {
        String filenameValue = data.inputRowMeta.getString(r,
                environmentSubstitute(meta.getOutputFileNameField()), "");
        if (!Const.isEmpty(filenameValue)) {
            outputFilename = filenameValue;
        } else {
            throw new KettleException("Filename cannot be empty.");
        }
    }

    //Create token resolver
    TokenResolver resolver = new TokenResolver();

    for (TokenReplacementField field : meta.getTokenReplacementFields()) {
        if (data.inputRowMeta.indexOfValue(field.getName()) >= 0) {
            String fieldValue = environmentSubstitute(data.inputRowMeta.getString(r, field.getName(), null));
            if (fieldValue == null && !BooleanUtils
                    .toBoolean(Const.getEnvironmentVariable("KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL", "N"))) {
                fieldValue = Const.nullToEmpty(fieldValue);
            }
            resolver.addToken(field.getTokenName(), fieldValue);
        } else {
            throw new KettleValueException("Field " + field.getName() + " not found on input stream.");
        }
    }

    Reader reader;
    String inputFilename = "";

    if (meta.getInputType().equalsIgnoreCase("text")) {
        reader = new TokenReplacingReader(resolver, new StringReader(meta.getInputText()),
                environmentSubstitute(meta.getTokenStartString()),
                environmentSubstitute(meta.getTokenEndString()));

    } else if (meta.getInputType().equalsIgnoreCase("field")) {
        if (data.inputRowMeta.indexOfValue(meta.getInputFieldName()) >= 0) {
            String inputString = data.inputRowMeta.getString(r, meta.getInputFieldName(), "");
            reader = new TokenReplacingReader(resolver, new StringReader(inputString),
                    environmentSubstitute(meta.getTokenStartString()),
                    environmentSubstitute(meta.getTokenEndString()));

        } else {
            throw new KettleValueException(
                    "Input field " + meta.getInputFieldName() + " not found on input stream.");
        }
    } else if (meta.getInputType().equalsIgnoreCase("file")) {
        if (meta.isInputFileNameInField()) {
            if (data.inputRowMeta.indexOfValue(environmentSubstitute(meta.getInputFileNameField())) >= 0) {
                inputFilename = data.inputRowMeta.getString(r,
                        environmentSubstitute(meta.getInputFileNameField()), "");
            } else {
                throw new KettleValueException("Input filename field "
                        + environmentSubstitute(meta.getInputFileNameField()) + " not found on input stream.");
            }
        } else {
            inputFilename = environmentSubstitute(meta.getInputFileName());
        }

        if (Const.isEmpty(inputFilename)) {
            throw new KettleValueException("Input filename cannot be empty");
        }

        FileObject file = KettleVFS.getFileObject(inputFilename, getTransMeta());
        reader = new TokenReplacingReader(resolver,
                new InputStreamReader(KettleVFS.getInputStream(inputFilename, getTransMeta())),
                environmentSubstitute(meta.getTokenStartString()),
                environmentSubstitute(meta.getTokenEndString()));

        if (meta.isAddInputFileNameToResult()) {
            ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL,
                    KettleVFS.getFileObject(inputFilename, getTransMeta()), getTransMeta().getName(),
                    getStepname());
            resultFile.setComment(BaseMessages.getString(PKG, "TokenReplacement.AddInputResultFile"));
            addResultFile(resultFile);
        }
    } else {
        throw new KettleException("Unsupported input type " + meta.getInputType());
    }

    Writer stringWriter = null;
    OutputStream bufferedWriter = null;

    if (meta.getOutputType().equalsIgnoreCase("field")) {
        stringWriter = new StringBufferWriter(new StringBuffer(5000));
    } else if (meta.getOutputType().equalsIgnoreCase("file")) {

        if (inputFilename.equals(outputFilename)) {
            throw new KettleException("Input and output filenames must not be the same " + inputFilename);
        }

        int fileIndex = data.openFiles.indexOf(outputFilename);
        if (fileIndex < 0) {
            openNewOutputFile(outputFilename);
            fileIndex = data.openFiles.indexOf(outputFilename);
        }

        bufferedWriter = data.openBufferedWriters.get(fileIndex);

    } else {
        throw new KettleException("Unsupported output type " + meta.getOutputType());
    }

    String output = "";

    try {
        char[] cbuf = new char[5000];
        StringBuffer sb = new StringBuffer();
        int length = 0;
        while ((length = reader.read(cbuf)) > 0) {
            if (meta.getOutputType().equalsIgnoreCase("field")) {
                stringWriter.write(cbuf, 0, length);
            } else if (meta.getOutputType().equalsIgnoreCase("file")) {
                CharBuffer cBuffer = CharBuffer.wrap(cbuf, 0, length);
                ByteBuffer bBuffer = Charset.forName(meta.getOutputFileEncoding()).encode(cBuffer);
                byte[] bytes = new byte[bBuffer.limit()];
                bBuffer.get(bytes);
                bufferedWriter.write(bytes);

            } //No else.  Anything else will be thrown to a Kettle exception prior to getting here.
            cbuf = new char[5000];
        }

        if (meta.getOutputType().equalsIgnoreCase("field")) {
            output += stringWriter.toString();
        } else if (meta.getOutputType().equalsIgnoreCase("file")) {
            bufferedWriter.write(meta.getOutputFileFormatString().getBytes());
        }
    } catch (IOException ex) {
        throw new KettleException(ex.getMessage(), ex);
    } finally {
        try {
            reader.close();
            if (stringWriter != null) {
                stringWriter.close();
            }

            reader = null;
            stringWriter = null;

        } catch (IOException ex) {
            throw new KettleException(ex.getMessage(), ex);
        }

    }

    if (meta.getOutputType().equalsIgnoreCase("field")) {
        r = RowDataUtil.addValueData(r, data.outputRowMeta.size() - 1, output);
    } else if (meta.getOutputType().equalsIgnoreCase("file")) {
        incrementLinesWritten();
    }

    putRow(data.outputRowMeta, r); // in case we want it to go further...
    data.rowNumber++;
    if (checkFeedback(getLinesOutput())) {
        logBasic("linenr " + getLinesOutput());
    }

    return result;
}

From source file:org.inquidia.mondrian.dynamicschemaprocessor.KettleDynamicSchemaProcessor.java

public String processSchema(String schemaUrl, Util.PropertyList connectInfo) throws Exception {
    if (LOGGER.getLevel() == null) {
        LOGGER.setLevel(Level.ERROR);
    }/*from   w w w  .  j  a  v a2s .  co  m*/

    boolean cacheEnabled = BooleanUtils.toBoolean(connectInfo.get("cacheEnabled", "Y"));

    String schemaValue = null;

    IPentahoSession session = PentahoSessionHolder.getSession();
    String schemaCacheKey = CacheUtils.KeyBuilder.buildSessionSchemaKey(session, schemaUrl);

    if (cacheEnabled) {

        schemaValue = (String) CacheUtils.get(CacheUtils.Region.SCHEMA_REGION, schemaCacheKey);
    }

    if (schemaValue == null) {
        LOGGER.info("Starting schema processing " + schemaUrl);
        schemaValue = getSchema(schemaUrl, connectInfo, cacheEnabled);
        if (cacheEnabled) {
            CacheUtils.put(CacheUtils.Region.SCHEMA_REGION, schemaCacheKey, schemaValue);
        }
    } else {
        LOGGER.info("Got schema from cache " + schemaUrl);
    }

    if (schemaValue == null) {
        LOGGER.error(schemaUrl + " Schema returned from transformation is null!");
        throw new KettleException(schemaUrl + " Schema returned from transformation is null!");
    }

    LOGGER.debug("Outputting schema\n" + schemaValue);
    return schemaValue;
}

From source file:org.jamwiki.servlets.TranslationServlet.java

/**
 *
 *///from  w  w  w  .j  av a  2 s . com
private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String language = this.retrieveLanguage(request);
    SortedProperties translations = new SortedProperties(
            Environment.loadProperties("ApplicationResources.properties"));
    if (!StringUtils.isBlank(language)) {
        String filename = filename(language);
        // add all translated keys to the base translation list
        translations.putAll(Environment.loadProperties(filename));
        // if the user wants to see only untranslated values, return the intersection of the base
        // translation list and the translated file list
        if (BooleanUtils.toBoolean(request.getParameter("hideTranslated"))) {
            Map tmp = Utilities.intersect(translations,
                    Environment.loadProperties("ApplicationResources.properties"));
            translations = new SortedProperties();
            translations.putAll(tmp);
            next.addObject("hideTranslated", true);
        }
    }
    pageInfo.setContentJsp(JSP_ADMIN_TRANSLATION);
    pageInfo.setAdmin(true);
    pageInfo.setPageTitle(new WikiMessage("translation.title"));
    next.addObject("translations", new TreeMap(translations));
    next.addObject("codes", this.retrieveTranslationCodes());
    next.addObject("language", language);
    SortedProperties defaultTranslations = new SortedProperties(
            Environment.loadProperties("ApplicationResources.properties"));
    next.addObject("defaultTranslations", new TreeMap(defaultTranslations));
}

From source file:org.jboss.windup.decorator.xml.XPathSummaryDecorator.java

public void setInline(String inline) {
    this.inline = BooleanUtils.toBoolean(inline);
}

From source file:org.jboss.windup.WindupMain.java

public void processInput(CommandLine line, Options options) {
    // automatically generate the help statement

    try {/*from ww w. ja va  2s.c om*/
        // parse the command line arguments

        if (line.getOptions().length < 1) {
            HELP_FORMATTER.printHelp(WINDUP_COMMAND, options);
        } else {
            // Map the environment settings from the input arguments.
            WindupEnvironment settings = new WindupEnvironment();
            if (line.hasOption("javaPkgs")) {
                settings.setPackageSignature(line.getOptionValue("javaPkgs"));
            }
            if (line.hasOption("excludePkgs")) {
                settings.setExcludeSignature(line.getOptionValue("excludePkgs"));
            }

            if (line.hasOption("targetPlatform")) {
                settings.setTargetPlatform(line.getOptionValue("targetPlatform"));
            }

            if (line.hasOption("fetchRemote")) {
                settings.setFetchRemote(line.getOptionValue("fetchRemote"));
            }

            String inputLocation = line.getOptionValue("input");
            inputLocation = StringUtils.trim(inputLocation);
            File inputPath = new File(inputLocation);

            File outputPath = null;
            String outputLocation = line.getOptionValue("output");
            outputLocation = StringUtils.trim(outputLocation);
            if (StringUtils.isNotBlank(outputLocation)) {
                outputPath = new File(outputLocation);
            }

            boolean isSource = false;
            if (BooleanUtils.toBoolean(line.getOptionValue("source"))) {
                isSource = true;
            }
            settings.setSource(isSource);

            boolean captureLog = false;
            if (BooleanUtils.toBoolean(line.getOptionValue("captureLog"))) {
                captureLog = true;
            }

            String logLevel = line.getOptionValue("logLevel");
            logLevel = StringUtils.trim(logLevel);

            settings.setCaptureLog(captureLog);
            settings.setLogLevel(logLevel);

            // Run Windup.
            ReportEngine engine = new ReportEngine(settings);
            engine.process(inputPath, outputPath);
        }
    } catch (FileNotFoundException e) {
        LOG.error("Input does not exist:" + e.getMessage(), e);
        HELP_FORMATTER.printHelp(WINDUP_COMMAND, options);
    } catch (IOException e) {
        LOG.error("Exception while writing report: " + e.getMessage(), e);
        HELP_FORMATTER.printHelp(WINDUP_COMMAND, options);
    }
}

From source file:org.jfrog.teamcity.agent.GenericBuildInfoExtractor.java

@Override
protected void appendRunnerSpecificDetails(BuildInfoBuilder builder, Object object) throws Exception {
    builder.type(BuildType.GENERIC);// w  ww  . ja  va 2s  . co  m
    builder.buildAgent(new BuildAgent(runnerContext.getRunType()));
    boolean isUsesSpecs = BooleanUtils
            .toBoolean(runnerContext.getRunnerParameters().get(RunnerParameterKeys.USE_SPECS));
    if (!isUsesSpecs || !isSpecValid()) {
        return;
    }
    deployDetailsArtifacts = Lists.newArrayList();
    Set<DeployDetails> deployDitailsSet;
    SpecsHelper specsHelper = new SpecsHelper(new TeamcityAgenBuildInfoLog(logger));
    Spec uploadSpec;
    try {
        uploadSpec = specsHelper.getDownloadUploadSpec(
                runnerContext.getRunnerParameters().get(RunnerParameterKeys.UPLOAD_SPEC));
        if (!isValidUploadFile(uploadSpec)) {
            return;
        }
        deployDitailsSet = specsHelper.getDeployDetails(uploadSpec, runnerContext.getWorkingDirectory());
    } catch (IOException e) {
        throw new Exception(
                String.format("Could not collect artifacts details from the spec: %s", e.getMessage()), e);
    }
    for (DeployDetails deployDetails : deployDitailsSet) {
        deployDetailsArtifacts.add(new DeployDetailsArtifact(deployDetails));
    }

}

From source file:org.ktc.soapui.maven.extension.TestVerifyMojo.java

@Override
public void performExecute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Checking if SoapUI Test(s) failed");
    String soapuiTestsHaveFailuresOrErrors = project.getProperties().getProperty(TEST_FAILURES_AND_ERRORS_KEY);
    if (BooleanUtils.toBoolean(soapuiTestsHaveFailuresOrErrors)) {
        throw new MojoFailureException("SoapUI Test(s) failed: see logs and/or check the printReport"
                + " (if necessary, set the option to true)");
    }//w  w  w.java 2 s  .c o  m
    getLog().info("No SoapUI Tests failed");
}

From source file:org.kuali.kra.budget.core.BudgetServiceImpl.java

private boolean isAuthorizedToAccess(String budgetCategoryTypeCode) {
    boolean isAuthorized = true;
    if (budgetCategoryTypeCode.contains(Constants.COLON)) {
        if (GlobalVariables.getUserSession() != null) {
            // TODO : this is a quick hack for KC 3.1.1 to provide authorization check for dwr/ajax call. dwr/ajax will be replaced by
            // jquery/ajax in rice 2.0
            String[] invalues = StringUtils.split(budgetCategoryTypeCode, Constants.COLON);
            String docFormKey = invalues[1];
            if (StringUtils.isBlank(docFormKey)) {
                isAuthorized = false;// www.  ja v  a  2s  .  co m
            } else {
                Object formObj = GlobalVariables.getUserSession().retrieveObject(docFormKey);
                if (formObj == null || !(formObj instanceof BudgetForm)) {
                    isAuthorized = false;
                } else {
                    Map<String, String> editModes = ((BudgetForm) formObj).getEditingMode();
                    isAuthorized = BooleanUtils
                            .toBoolean(editModes.get(AuthorizationConstants.EditMode.FULL_ENTRY))
                            || BooleanUtils.toBoolean(editModes.get(AuthorizationConstants.EditMode.VIEW_ONLY))
                            || BooleanUtils.toBoolean(editModes.get("modifyBudgtes"))
                            || BooleanUtils.toBoolean(editModes.get("viewBudgets"))
                            || BooleanUtils.toBoolean(editModes.get("addBudget"));
                }
            }

        } else {
            // TODO : it seemed that tomcat has this issue intermittently ?
            LOG.info("dwr/ajax does not have session ");
        }
    }
    return isAuthorized;
}