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.okj.commons.jexl.functions.DecodeFunction.java

/**
 * /*from   w  w  w  .  j  a  va2s .  c  o m*/
 * @param val
 * @param trueValue
 * @param falseValue
 * @return
 */
public String code(int val, String trueValue, String falseValue) {
    boolean b = BooleanUtils.toBoolean(val);
    if (b) {
        return trueValue;
    } else {
        return falseValue;
    }
}

From source file:org.okj.commons.web.session.SessionOperator.java

/**
 * /*from ww  w  .j  a  va  2  s  . c o m*/
 * 
 * @param request
 * @return
 */
public static boolean isLogin(HttpServletRequest request) {
    boolean islogin = false;
    if (request != null) {
        HttpSession session = request.getSession();
        return BooleanUtils.toBoolean((Boolean) session.getAttribute(IS_LOGIN));
    }
    return islogin;
}

From source file:org.okj.commons.web.taglib.Functions.java

/**
 * /*from  w  w  w.j  a v  a 2  s  .c om*/
 * @param object
 * @param trueValue
 * @param falseValue
 * @return
 */
public static String iff(Object object, String trueValue, String falseValue) {
    String valueStr = String.valueOf(object);
    if (StringUtils.equals("1", valueStr)) {
        valueStr = "true";
    }
    if (StringUtils.equals("0", valueStr)) {
        valueStr = "false";
    }
    boolean value = BooleanUtils.toBoolean(valueStr);
    if (value) {
        return trueValue;
    }
    return falseValue;
}

From source file:org.onehippo.forge.camel.component.hippo.HippoEventConsumer.java

@Override
protected void doStart() throws Exception {
    super.doStart();

    final boolean persistedEventConsumer = BooleanUtils.toBoolean((String) endpoint.getProperty("_persisted"));

    if (persistedEventConsumer) {
        LOG.info("Registering a persisted event consumer because the _persisted parameter set to true.");

        HippoPersistedEventListener listener = new HippoPersistedEventListener();

        final String channelName = (String) endpoint.getProperty("_channelName");

        if (StringUtils.isEmpty(channelName)) {
            throw new RuntimeCamelException(
                    "Channel name must be specified for a persisted event consumer with '_channelName' parameter!");
        }// w w w .  j av  a  2 s .  c  o m

        listener.setChannelName(channelName);

        final String[] eventCategories = StringUtils.split((String) endpoint.getProperty("category"), ",");

        if (ArrayUtils.isNotEmpty(eventCategories) && StringUtils.isNotEmpty(eventCategories[0])) {
            listener.setEventCategory(eventCategories[0]);
        }

        if (endpoint.hasProperty("_onlyNewEvents")) {
            listener.setOnlyNewEvents(BooleanUtils.toBoolean((String) endpoint.getProperty("_onlyNewEvents")));
        }

        HippoServiceRegistry.registerService(listener, HippoEventBus.class);

        persistedEventListener = listener;

    } else {
        LOG.info(
                "Registering a local event consumer because the _persisted parameter unspecified or set to false.");

        HippoLocalEventListener listener = new HippoLocalEventListener();
        HippoServiceRegistry.registerService(listener, HippoEventBus.class);
        localEventListener = listener;

    }
}

From source file:org.onehippo.forge.content.exim.repository.jaxrs.param.ExecutionParams.java

public void setPublishOnImport(String publishOnImport) {
    if (StringUtils.equalsIgnoreCase(publishOnImport, PUBLISH_ON_IMPORT_LIVE)) {
        this.publishOnImport = PUBLISH_ON_IMPORT_LIVE;
    } else if (StringUtils.equalsIgnoreCase(publishOnImport, PUBLISH_ON_IMPORT_ALL)
            || BooleanUtils.toBoolean(publishOnImport)) {
        this.publishOnImport = PUBLISH_ON_IMPORT_ALL;
    } else {//  www.  j  a  va  2 s  .  c o  m
        this.publishOnImport = PUBLISH_ON_IMPORT_NONE;
    }
}

From source file:org.onehippo.forge.content.pojo.common.jcr.DefaultJcrContentValueConverter.java

@Override
public Value toJcrValue(String typeName, String stringValue) throws ContentNodeException {
    if (stringValue == null) {
        throw new IllegalArgumentException("Cannot convert null to a JCR value.");
    }//from w w w.ja  va  2s .c om

    ContentPropertyType type = ContentPropertyType.valueOf(typeName);
    Value jcrValue = null;

    try {
        final ValueFactory valueFactory = getSession().getValueFactory();

        switch (type) {
        case STRING:
            jcrValue = valueFactory.createValue(stringValue);
            break;
        case DATE:
            jcrValue = valueFactory.createValue(ISO8601.parse(stringValue));
            break;
        case BOOLEAN:
            jcrValue = valueFactory.createValue(BooleanUtils.toBoolean(stringValue));
            break;
        case LONG:
            jcrValue = valueFactory.createValue(NumberUtils.toLong(stringValue));
            break;
        case DOUBLE:
            jcrValue = valueFactory.createValue(NumberUtils.toDouble(stringValue));
            break;
        case DECIMAL:
            jcrValue = valueFactory.createValue(new BigDecimal(stringValue));
            break;
        default:
            break;
        }
    } catch (RepositoryException e) {
        throw new ContentNodeException(e.toString(), e);
    }

    return jcrValue;
}

From source file:org.opencastproject.adminui.endpoint.AbstractEventEndpoint.java

@POST
@Path("{eventId}/comment")
@Produces(MediaType.APPLICATION_JSON)/*w w w .  j  a v  a  2 s  . co  m*/
@RestQuery(name = "createeventcomment", description = "Creates a comment related to the event given by the identifier", returnDescription = "The comment related to the event as JSON", pathParameters = {
        @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = {
                @RestParameter(name = "text", isRequired = true, description = "The comment text", type = TEXT),
                @RestParameter(name = "resolved", isRequired = false, description = "The comment resolved status", type = RestParameter.Type.BOOLEAN),
                @RestParameter(name = "reason", isRequired = false, description = "The comment reason", type = STRING) }, reponses = {
                        @RestResponse(description = "The comment has been created.", responseCode = HttpServletResponse.SC_CREATED),
                        @RestResponse(description = "If no text ist set.", responseCode = HttpServletResponse.SC_BAD_REQUEST),
                        @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response createEventComment(@PathParam("eventId") String eventId, @FormParam("text") String text,
        @FormParam("reason") String reason, @FormParam("resolved") Boolean resolved) throws Exception {
    Opt<Event> optEvent = getEvent(eventId);
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);

    if (StringUtils.isBlank(text))
        return Response.status(Status.BAD_REQUEST).build();

    User author = getSecurityService().getUser();
    try {
        Comment createdComment = Comment.create(Option.<Long>none(), text, author, reason,
                BooleanUtils.toBoolean(reason));
        createdComment = getEventCommentService().updateComment(eventId, createdComment);
        List<Comment> comments = getEventCommentService().getComments(eventId);
        updateCommentCatalog(optEvent.get(), comments);
        return Response.created(getCommentUrl(eventId, createdComment.getId().get()))
                .entity(createdComment.toJson().toJson()).build();
    } catch (Exception e) {
        logger.error("Unable to create a comment on the event {}: {}", eventId,
                ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}

From source file:org.opencastproject.adminui.endpoint.ThemesEndpoint.java

@POST
@Path("")/*from  ww w .  j a va  2s.c o m*/
@RestQuery(name = "createTheme", description = "Add a theme", returnDescription = "Return the created theme", restParameters = {
        @RestParameter(name = "default", description = "Whether the theme is default", isRequired = true, type = Type.BOOLEAN),
        @RestParameter(name = "name", description = "The theme name", isRequired = true, type = Type.STRING),
        @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT),
        @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN),
        @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN),
        @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN),
        @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN),
        @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN),
        @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING),
        @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING),
        @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING),
        @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING),
        @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING),
        @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING),
        @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING),
        @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING), }, reponses = {
                @RestResponse(responseCode = SC_OK, description = "Theme created"),
                @RestResponse(responseCode = SC_BAD_REQUEST, description = "The theme references a non-existing file") })
public Response createTheme(@FormParam("default") boolean isDefault, @FormParam("name") String name,
        @FormParam("description") String description, @FormParam("bumperActive") Boolean bumperActive,
        @FormParam("trailerActive") Boolean trailerActive,
        @FormParam("titleSlideActive") Boolean titleSlideActive,
        @FormParam("licenseSlideActive") Boolean licenseSlideActive,
        @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile,
        @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile,
        @FormParam("titleSlideBackground") String titleSlideBackground,
        @FormParam("licenseSlideBackground") String licenseSlideBackground,
        @FormParam("titleSlideMetadata") String titleSlideMetadata,
        @FormParam("licenseSlideDescription") String licenseSlideDescription,
        @FormParam("watermarkPosition") String watermarkPosition) {
    User creator = securityService.getUser();

    Theme theme = new Theme(Option.<Long>none(), new Date(), isDefault, creator, name,
            StringUtils.trimToNull(description), BooleanUtils.toBoolean(bumperActive),
            StringUtils.trimToNull(bumperFile), BooleanUtils.toBoolean(trailerActive),
            StringUtils.trimToNull(trailerFile), BooleanUtils.toBoolean(titleSlideActive),
            StringUtils.trimToNull(titleSlideMetadata), StringUtils.trimToNull(titleSlideBackground),
            BooleanUtils.toBoolean(licenseSlideActive), StringUtils.trimToNull(licenseSlideBackground),
            StringUtils.trimToNull(licenseSlideDescription), BooleanUtils.toBoolean(watermarkActive),
            StringUtils.trimToNull(watermarkFile), StringUtils.trimToNull(watermarkPosition));

    try {
        persistReferencedFiles(theme);
    } catch (NotFoundException e) {
        logger.warn("A file that is referenced in theme '{}' was not found: {}", theme, e.getMessage());
        return R.badRequest("Referenced non-existing file");
    } catch (IOException e) {
        logger.warn("Error while persisting file: {}", e.getMessage());
        return R.serverError();
    }

    try {
        Theme createdTheme = themesServiceDatabase.updateTheme(theme);
        return RestUtils.okJson(themeToJSON(createdTheme));
    } catch (ThemesServiceDatabaseException e) {
        logger.error("Unable to create a theme");
        return RestUtil.R.serverError();
    }
}

From source file:org.opencastproject.adminui.endpoint.ThemesEndpoint.java

@PUT
@Path("{themeId}")
@RestQuery(name = "updateTheme", description = "Updates a theme", returnDescription = "Return the updated theme", pathParameters = {
        @RestParameter(name = "themeId", description = "The theme identifier", isRequired = true, type = Type.INTEGER) }, restParameters = {
                @RestParameter(name = "default", description = "Whether the theme is default", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "name", description = "The theme name", isRequired = false, type = Type.STRING),
                @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT),
                @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN),
                @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING),
                @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING),
                @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING),
                @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING),
                @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING),
                @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING),
                @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING),
                @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING), }, reponses = {
                        @RestResponse(responseCode = SC_OK, description = "Theme updated"),
                        @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found."), })
public Response updateTheme(@PathParam("themeId") long themeId, @FormParam("default") Boolean isDefault,
        @FormParam("name") String name, @FormParam("description") String description,
        @FormParam("bumperActive") Boolean bumperActive, @FormParam("trailerActive") Boolean trailerActive,
        @FormParam("titleSlideActive") Boolean titleSlideActive,
        @FormParam("licenseSlideActive") Boolean licenseSlideActive,
        @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile,
        @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile,
        @FormParam("titleSlideBackground") String titleSlideBackground,
        @FormParam("licenseSlideBackground") String licenseSlideBackground,
        @FormParam("titleSlideMetadata") String titleSlideMetadata,
        @FormParam("licenseSlideDescription") String licenseSlideDescription,
        @FormParam("watermarkPosition") String watermarkPosition) throws NotFoundException {
    try {/* w  w w. j av a  2  s .co  m*/
        Theme origTheme = themesServiceDatabase.getTheme(themeId);

        if (isDefault == null)
            isDefault = origTheme.isDefault();
        if (StringUtils.isBlank(name))
            name = origTheme.getName();
        if (StringUtils.isEmpty(description))
            description = origTheme.getDescription();
        if (bumperActive == null)
            bumperActive = origTheme.isBumperActive();
        if (StringUtils.isEmpty(bumperFile))
            bumperFile = origTheme.getBumperFile();
        if (trailerActive == null)
            trailerActive = origTheme.isTrailerActive();
        if (StringUtils.isEmpty(trailerFile))
            trailerFile = origTheme.getTrailerFile();
        if (titleSlideActive == null)
            titleSlideActive = origTheme.isTitleSlideActive();
        if (StringUtils.isEmpty(titleSlideMetadata))
            titleSlideMetadata = origTheme.getTitleSlideMetadata();
        if (StringUtils.isEmpty(titleSlideBackground))
            titleSlideBackground = origTheme.getTitleSlideBackground();
        if (licenseSlideActive == null)
            licenseSlideActive = origTheme.isLicenseSlideActive();
        if (StringUtils.isEmpty(licenseSlideBackground))
            licenseSlideBackground = origTheme.getLicenseSlideBackground();
        if (StringUtils.isEmpty(licenseSlideDescription))
            licenseSlideDescription = origTheme.getLicenseSlideDescription();
        if (watermarkActive == null)
            watermarkActive = origTheme.isWatermarkActive();
        if (StringUtils.isEmpty(watermarkFile))
            watermarkFile = origTheme.getWatermarkFile();
        if (StringUtils.isEmpty(watermarkPosition))
            watermarkPosition = origTheme.getWatermarkPosition();

        Theme theme = new Theme(origTheme.getId(), origTheme.getCreationDate(), isDefault,
                origTheme.getCreator(), name, StringUtils.trimToNull(description),
                BooleanUtils.toBoolean(bumperActive), StringUtils.trimToNull(bumperFile),
                BooleanUtils.toBoolean(trailerActive), StringUtils.trimToNull(trailerFile),
                BooleanUtils.toBoolean(titleSlideActive), StringUtils.trimToNull(titleSlideMetadata),
                StringUtils.trimToNull(titleSlideBackground), BooleanUtils.toBoolean(licenseSlideActive),
                StringUtils.trimToNull(licenseSlideBackground), StringUtils.trimToNull(licenseSlideDescription),
                BooleanUtils.toBoolean(watermarkActive), StringUtils.trimToNull(watermarkFile),
                StringUtils.trimToNull(watermarkPosition));

        try {
            updateReferencedFiles(origTheme, theme);
        } catch (IOException e) {
            logger.warn("Error while persisting file: {}", e.getMessage());
            return R.serverError();
        } catch (NotFoundException e) {
            logger.warn("A file that is referenced in theme '{}' was not found: {}", theme, e.getMessage());
            return R.badRequest("Referenced non-existing file");
        }

        Theme updatedTheme = themesServiceDatabase.updateTheme(theme);
        return RestUtils.okJson(themeToJSON(updatedTheme));
    } catch (ThemesServiceDatabaseException e) {
        logger.error("Unable to update theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
}

From source file:org.opencastproject.comments.CommentParser.java

private static Comment commentFromManifest(Node commentNode, UserDirectoryService userDirectoryService)
        throws UnsupportedElementException {
    try {/*from   w  ww . j a  va  2  s  .co m*/
        // id
        Long id = null;
        Double idAsDouble = ((Number) xpath.evaluate("@id", commentNode, XPathConstants.NUMBER)).doubleValue();
        if (!idAsDouble.isNaN())
            id = idAsDouble.longValue();

        // text
        String text = (String) xpath.evaluate("text/text()", commentNode, XPathConstants.STRING);

        // Author
        Node authorNode = (Node) xpath.evaluate("author", commentNode, XPathConstants.NODE);
        User author = userFromManifest(authorNode, userDirectoryService);

        // ResolvedStatus
        Boolean resolved = BooleanUtils
                .toBoolean((Boolean) xpath.evaluate("@resolved", commentNode, XPathConstants.BOOLEAN));

        // Reason
        String reason = (String) xpath.evaluate("reason/text()", commentNode, XPathConstants.STRING);
        if (StringUtils.isNotBlank(reason))
            reason = reason.trim();

        // CreationDate
        String creationDateString = (String) xpath.evaluate("creationDate/text()", commentNode,
                XPathConstants.STRING);
        Date creationDate = new Date(DateTimeSupport.fromUTC(creationDateString));

        // ModificationDate
        String modificationDateString = (String) xpath.evaluate("modificationDate/text()", commentNode,
                XPathConstants.STRING);
        Date modificationDate = new Date(DateTimeSupport.fromUTC(modificationDateString));

        // Create comment
        Comment comment = Comment.create(Option.option(id), text.trim(), author, reason, resolved, creationDate,
                modificationDate);

        // Replies
        NodeList replyNodes = (NodeList) xpath.evaluate("replies/reply", commentNode, XPathConstants.NODESET);
        for (int i = 0; i < replyNodes.getLength(); i++) {
            comment.addReply(replyFromManifest(replyNodes.item(i), userDirectoryService));
        }

        return comment;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException("Error while reading comment information from manifest", e);
    } catch (Exception e) {
        if (e instanceof UnsupportedElementException)
            throw (UnsupportedElementException) e;
        throw new UnsupportedElementException(
                "Error while reading comment creation or modification date information from manifest", e);
    }
}