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:net.ageto.gyrex.impex.common.steps.impl.filename.FirstFilenameInAlphabeticalOrder.java

@SuppressWarnings("unchecked")
@Override/*from   w  w w .  jav a  2 s  .co m*/
protected StatusStep process() {

    // file path
    String filepath = (String) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILEPATH.name());

    // file extensions
    ArrayList<String> fileExtension = (ArrayList<String>) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_FILE_EXTENSION_FILTER.name());

    String[] fileExtensionsArray = fileExtension == null ? null : (String[]) fileExtension.toArray();

    // recursive, include subdirectories
    Boolean recursive = (Boolean) getInputParam(
            FirstFilenameInAlphabeticalOrderDefinition.InputParamNames.INPUT_INCLUDE_SUBDIRECTORIES.name());

    // all files from the given file path
    Collection<File> listFiles = FileUtils.listFiles(new File(filepath), fileExtensionsArray,
            BooleanUtils.toBoolean(recursive));

    if (listFiles.size() == 0) {
        processWarn("No file was found in folder \"{0}\" with file extension \"{1}\".", filepath,
                StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*"));
        // cancel process
        return StatusStep.CANCEL;
    }

    // fetch first file (alphabetical order)
    for (File file : listFiles) {
        setOutputParam(FirstFilenameInAlphabeticalOrderDefinition.OutputParamNames.OUTPUT_FILENAME.name(),
                file.getAbsolutePath());
        processInfo("File \"{0}\" was found in folder \"{1}\" with file extension \"{2}\".",
                file.getAbsolutePath(), filepath,
                StringUtils.defaultIfEmpty(StringUtils.join(fileExtensionsArray, " "), "*"));
        break;
    }

    processInfo("{0} has been completed successfully.", ID);

    return StatusStep.OK;
}

From source file:mitm.common.properties.PropertyUtils.java

/**
 * Returns the property as a boolean. If propery is not found, or the property is not something that can
 * be represented a boolean, defaultValue will be returned.
 *///  w ww. ja v a 2s.  co m
public static boolean getBooleanProperty(Properties properties, String name, boolean defaultValue) {
    boolean result = defaultValue;

    Object value = properties.get(name);

    if (value == null) {
        value = properties.getProperty(name);
    }

    if (value instanceof String) {
        result = BooleanUtils.toBoolean((String) value);
    } else if (value instanceof Boolean) {
        result = (Boolean) value;
    }

    return result;
}

From source file:br.com.autonomiccs.autonomic.plugin.common.daos.AutonomiccsSystemVmTemplateJdbcDao.java

private boolean executeTemplateQueryAndRetrieveBoolean(String templateName, String sql) {
    Integer numberOfRegister = getJdbcTemplate().queryForObject(sql, new Object[] { templateName },
            Integer.class);
    if (numberOfRegister > 1) {
        throw new CloudRuntimeException(String.format("More than one template with name [%s]", templateName));
    }/*from www.  j  av  a2s  .com*/
    return BooleanUtils.toBoolean(numberOfRegister);
}

From source file:fr.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 Localization currentLocalization = requestUtil.getCurrentLocalization(request);
    final Locale locale = currentLocalization.getLocale();

    // SANITY CHECK: Customer logged
    final Customer currentCustomer = requestUtil.getCurrentCustomer(request);
    if (currentCustomer != null) {
        final String url = urlService.generateUrl(FoUrls.PERSONAL_DETAILS, requestUtil.getRequestData(request));
        return new ModelAndView(new RedirectView(url));
    }/*from   w  w w . j av a 2 s.  c o  m*/

    // 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,
                getSpecificMessage(ScopeWebMessage.AUTH, "login_or_password_are_wrong", locale));
    }

    return modelAndView;
}

From source file:au.org.ala.layers.web.LayersService.java

/**
 * This method returns a single layer, provided an id
 *
 * @param req//  w w w.j a  v a 2 s .c o m
 * @return
 */
@RequestMapping(value = "/layer/{id}", method = RequestMethod.GET)
public @ResponseBody Layer layerObject(@PathVariable("id") String id, HttpServletRequest req) {
    Layer l = null;
    try {
        boolean enabledOnly = true;
        if (req.getParameter("enabledOnly") != null) {
            enabledOnly = BooleanUtils.toBoolean(req.getParameter("enabledOnly"));
        }
        l = layerDao.getLayerById(Integer.parseInt(id), enabledOnly);
    } catch (Exception e) {
    }

    if (l == null) {
        l = layerDao.getLayerByName(id);
    }

    return l;
}

From source file:com.dsh105.holoapi.command.sub.TouchCommand.java

@Command(command = "touch add <id> <command...>", description = "Add an action to perform when a certain hologram is touched", permission = "holoapi.holo.touch.add")
public boolean add(final CommandEvent event) {
    if (!(event.sender() instanceof Conversable)) {
        event.respond(Lang.NOT_CONVERSABLE.getValue());
    }/*w  w w .  java2  s. c  o m*/

    final Hologram hologram = HoloAPI.getManager().getHologram(event.variable("id"));
    if (hologram == null) {
        event.respond(Lang.HOLOGRAM_NOT_FOUND.getValue("id", event.variable("id")));
        return true;
    }

    InputFactory.buildBasicConversation().withFirstPrompt(new SimpleInputPrompt(new YesNoFunction() {
        @Override
        public void onFunction(ConversationContext context, String input) {
            hologram.addTouchAction(
                    new CommandTouchAction(event.variable("command"), BooleanUtils.toBoolean(input)));
        }

        @Override
        public String getSuccessMessage(ConversationContext context, String input) {
            return Lang.COMMAND_TOUCH_ACTION_ADDED.getValue()
                    .replace("%command%", "/" + event.variable("command"))
                    .replace("%id%", hologram.getSaveId());
        }

        @Override
        public String getPromptText(ConversationContext context) {
            return Lang.YES_NO_COMMAND_TOUCH_ACTION_AS_CONSOLE.getValue();
        }

        @Override
        public String getFailedText(ConversationContext context, String invalidInput) {
            return Lang.YES_NO_INPUT_INVALID.getValue();
        }
    })).buildConversation((Conversable) event.sender()).begin();
    return true;
}

From source file:com.ibm.watson.app.common.persistence.jpa.impl.UnmanagedPersistenceEntityProvider.java

protected void getDatabaseConnectionProperties(ConfigurationService cfgService,
        Map<String, String> properties) {
    if (logger.isDebugEnabled())
        logger.debug("getDatabaseConnectionProperties() >> ");

    properties.put("openjpa.jdbc.SynchronizeMappings", "false");

    if (BooleanUtils.toBoolean(cfgService.getProperty("jpa.enable.trace", "false"))) {
        properties.put("openjpa.Log", "Runtime=TRACE");
    }/*from w  w  w .j a  v  a2  s .  c om*/

    if (useDerby) {
        // Following are for Derby

        // DBCP = Database connection pool from Apache commons
        properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
        properties.put("openjpa.ConnectionProperties",
                "DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=" + cfgService.getProperty("db.url"));
        properties.put("openjpa.ConnectionURL", cfgService.getProperty("db.url"));
        properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema");

        // properties.put("javax.persistence.jdbc.url", cfgService.getProperty("db.url"));
        // properties.put("javax.persistence.jdbc.user", "APP");
        // properties.put("javax.persistence.jdbc.password", "APP");
    }
}

From source file:com.redhat.rhn.domain.monitoring.notification.Criteria.java

/**
 * @param inverted The inverted boolean to set.
 *///  w  w  w.  ja  va 2s  . com
private void setInvertedBool(boolean inverted0) {
    setInverted(BooleanUtils.toBoolean(inverted0) ? '1' : '0');
}

From source file:net.sf.gazpachoquest.services.user.impl.GroupServiceImpl.java

@Transactional(readOnly = true)
@Override//from  ww  w.j av  a2 s  .  co m
public boolean isUserInGroup(Integer userId, Integer groupId) {
    return BooleanUtils.toBoolean(((GroupRepository) repository).isUserInGroup(userId, groupId));
}

From source file:com.tesora.dve.common.catalog.Collations.java

public boolean getIsDefault() {
    return BooleanUtils.toBoolean(isDefault);
}