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.apache.cocoon.transformation.LDAPTransformer.java

protected void endShowAttributeElement() {
    switch (current_state) {
    case LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT:
        if (!BooleanUtils.toBoolean(current_value.toString())) {
            getCurrentQuery().showAttribute = false;
        }//from  w w w  . j a va 2 s  .  co  m
        current_state = getCurrentQuery().toDo;
        break;
    default:
        throwIllegalStateException("Not expecting a end show-attribute element");
    }
}

From source file:org.apache.cocoon.transformation.LDAPTransformer.java

protected void endDerefLinkElement() {
    switch (current_state) {
    case LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT:
        getCurrentQuery().deref_link = BooleanUtils.toBoolean(current_value.toString());
        current_state = getCurrentQuery().toDo;
        break;/*from   w w  w .java  2 s .c  o m*/
    default:
        throwIllegalStateException("Not expecting a end deref-link element");
    }
}

From source file:org.apache.cocoon.transformation.LDAPTransformer.java

protected void endDebugElement() {
    switch (current_state) {
    case LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT:
        getCurrentQuery().debug = BooleanUtils.toBoolean(current_value.toString());
        current_state = getCurrentQuery().toDo;
        break;//  ww w.  jav a 2  s .co m
    default:
        throwIllegalStateException("Not expecting a end debug element");
    }
}

From source file:org.apache.cocoon.transformation.LuceneIndexTransformer.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {

    if (processing == STATE_GROUND) {
        if (LUCENE_URI.equals(namespaceURI) && LUCENE_QUERY_ELEMENT.equals(localName)) {
            String sCreate = atts.getValue(LUCENE_QUERY_CREATE_ATTRIBUTE);
            createIndex = BooleanUtils.toBoolean(sCreate);

            String analyzerClassname = atts.getValue(LUCENE_QUERY_ANALYZER_ATTRIBUTE);
            String indexDirectory = atts.getValue(LUCENE_QUERY_DIRECTORY_ATTRIBUTE);
            String mergeFactor = atts.getValue(LUCENE_QUERY_MERGE_FACTOR_ATTRIBUTE);

            queryConfiguration = new IndexerConfiguration(
                    analyzerClassname != null ? analyzerClassname : setupConfiguration.analyzerClassname,
                    indexDirectory != null ? indexDirectory : setupConfiguration.indexDirectory,
                    mergeFactor != null ? Integer.parseInt(mergeFactor) : setupConfiguration.mergeFactor);

            if (!createIndex) {
                // Not asked to create the index - but check if this is necessary anyway:
                try {
                    IndexReader reader = openReader();
                    reader.close();//from ww  w .  j  a v a2 s  . c o  m
                } catch (IOException ioe) {
                    // couldn't open the index - so recreate it
                    createIndex = true;
                }
            }
            // propagate the lucene:index to the next stage in the pipeline
            super.startElement(namespaceURI, localName, qName, atts);
            processing = STATE_QUERY;
        } else {
            super.startElement(namespaceURI, localName, qName, atts);
        }
    } else if (processing == STATE_QUERY) {
        // processing a lucene:index - expecting a lucene:document
        if (LUCENE_URI.equals(namespaceURI) && LUCENE_DOCUMENT_ELEMENT.equals(localName)) {
            this.bodyDocumentURL = atts.getValue(LUCENE_DOCUMENT_URL_ATTRIBUTE);
            if (this.bodyDocumentURL == null) {
                throw new SAXException("<lucene:document> must have @url attribute");
            }

            // Remember the time the document indexing began
            this.documentStartTime = System.currentTimeMillis();
            // remember these attributes so they can be passed on to the next stage in the pipeline,
            // when this document element is ended.
            this.documentAttributes = new AttributesImpl(atts);
            this.bodyText = new StringBuffer();
            this.bodyDocument = new Document();
            this.elementStack.clear();
            processing = STATE_DOCUMENT;
        } else {
            throw new SAXException("<lucene:index> element can contain only <lucene:document> elements!");
        }
    } else if (processing == STATE_DOCUMENT) {
        elementStack.push(new IndexHelperField(localName, new AttributesImpl(atts)));
    }
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Handle input elements. Calls startCheckableElement or
 * startNonCheckableElement.//from   w w w.ja v  a 2  s  .  c  om
 */
protected void startInputElement(String uri, String name, String raw, Attributes attr) throws SAXException {

    // @value = request.getParameterValues(@name)
    String aName = getName(attr.getValue("name"));
    String fixed = attr.getValue(this.fixedName);

    if (getLogger().isDebugEnabled())
        getLogger().debug("startInputElement " + name + " attributes " + this.printAttributes(attr));
    if (aName == null || this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed))) {
        this.relayStartElement(uri, name, raw, attr);

    } else {
        if (getLogger().isDebugEnabled())
            getLogger().debug("replacing");

        attr = this.normalizeAttributes(attr);

        AttributesImpl attributes = null;
        if (attr instanceof AttributesImpl) {
            attributes = (AttributesImpl) attr;
        } else {
            attributes = new AttributesImpl(attr);
        }
        String type = attributes.getValue("type");
        switch (((Integer) inputTypes.get(type, defaultType)).intValue()) {
        case TYPE_CHECKBOX:
        case TYPE_RADIO:
            this.startCheckableElement(aName, uri, name, raw, attributes);
            break;

        case TYPE_DEFAULT:
            this.startNonCheckableElement(aName, uri, name, raw, attributes);
            break;
        }
        this.values = null;
    }
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Handle select elements. Sets up some instance variables for
 * following option elements.//  www. j av  a2 s  .co m
 */
protected void startSelectElement(String uri, String name, String raw, Attributes attr) throws SAXException {

    // this.values = request.getParameterValues(@name)
    String aName = getName(attr.getValue("name"));
    String fixed = attr.getValue(this.fixedName);
    this.values = null;
    if (getLogger().isDebugEnabled())
        getLogger().debug("startSelectElement " + name + " attributes " + this.printAttributes(attr));
    if (aName != null && !(this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed)))) {
        if (attr.getIndex("multiple") > -1) {
            this.values = this.getValues(aName);
        } else {
            Object val = this.getNextValue(aName);
            if (val != null) {
                this.values = new Object[1];
                this.values[0] = val;
            } else {
                this.values = null;
            }
        }
        attr = this.normalizeAttributes(attr);
    }
    this.relayStartElement(uri, name, raw, attr);
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Handles textarea elements. Skips nested events if request
 * parameter with same name exists./*  ww  w. j  a  va  2 s. c o m*/
 */
protected void startTextareaElement(String uri, String name, String raw, Attributes attributes)
        throws SAXException {

    String aName = getName(attributes.getValue("name"));
    String fixed = attributes.getValue(this.fixedName);
    Object value = null;
    if (getLogger().isDebugEnabled())
        getLogger().debug("startTextareaElement " + name + " attributes " + this.printAttributes(attributes));
    if (aName != null) {
        value = this.getNextValue(aName);
    }
    if (value == null || this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed))) {
        this.relayStartElement(uri, name, raw, attributes);
    } else {
        if (getLogger().isDebugEnabled())
            getLogger().debug("replacing");
        this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
        String valString = String.valueOf(value);
        this.characters(valString.toCharArray(), 0, valString.length());
        // well, this doesn't really work out nicely. do it the hard way.
        if (this.ignoreEventsCount == 0)
            this.skipChildrenOnly = true;
        this.ignoreEventsCount++;
    }
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Start processing a form element. Sets protection indicator if attribute
 * "fixed" is present and either "true" or "yes". Removes attribute "fixed"
 * if present.//w w  w  . j av  a 2 s.  c  om
 * @param uri The namespace of the element.
 * @param name The local name of the element.
 * @param raw The qualified name of the element.
 * @param attr The attributes of the element.
 */
protected void startFormElement(String uri, String name, String raw, Attributes attr) throws SAXException {

    String fixed = attr.getValue(this.fixedName);
    if (this.useFormName) {
        this.formName = attr.getValue("name");
    }
    if (fixed == null) {
        this.relayStartElement(uri, name, raw, attr);
    } else {
        if (!this.fixed && BooleanUtils.toBoolean(fixed)) {
            this.fixed = true;
        }
        // remove attributes not meant for client
        AttributesImpl attributes = null;
        if (attr instanceof AttributesImpl) {
            attributes = (AttributesImpl) attr;
        } else {
            attributes = new AttributesImpl(attr);
        }
        attributes.removeAttribute(attributes.getIndex(this.fixedName));
        this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
    }
}

From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java

/**
 * Start recording repeat element contents and push repeat expression and
 * variable to repeater stack. Only start recording, if no other recorder is
 * currently running./*www.  j  a  v a2 s  .c o  m*/
 *
 * @param uri
 * @param name
 * @param raw
 * @param attr
 * @throws SAXException
 */
protected void startRepeatElement(String uri, String name, String raw, Attributes attr) throws SAXException {

    if (this.recordingCount == 0) {
        if (!(this.fixed || BooleanUtils.toBoolean(attr.getValue(this.fixedName)))) {
            RepeaterStatus status = new RepeaterStatus("${" + attr.getValue("using") + "}", 0,
                    attr.getValue("on"));
            this.repeater.add(status);
            this.startRecording();
            this.recordingCount++;
        } else {
            this.relayStartElement(uri, name, raw, attr);
        }
    } else {
        this.relayStartElement(uri, name, raw, attr);
        this.recordingCount++;
    }
}

From source file:org.apache.cocoon.xml.dom.DOMUtil.java

/**
 * Get the boolean value of the node specified by the XPath.
 * This works similar to xsl:value-of. If the node exists and has a value
 * this value is converted to a boolean, e.g. "true" or "false" as value
 * will result into the corresponding boolean values.
 * If the node does not exist, the <CODE>defaultValue</CODE> is returned.
 *
 * @param root The node to start the search.
 * @param path XPath search expression./*w  w w. j  av a 2s.  c  o m*/
 * @param defaultValue Default boolean value.
 * @return     The value of the node or <CODE>defaultValue</CODE>
 */
public static boolean getValueOfNodeAsBoolean(XPathProcessor processor, Node root, String path,
        boolean defaultValue) throws ProcessingException {
    String value = getValueOfNode(processor, root, path);
    if (value != null) {
        return BooleanUtils.toBoolean(value);
    }
    return defaultValue;
}