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

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

Introduction

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

Prototype

public static Boolean toBooleanObject(String str) 

Source Link

Document

Converts a String to a Boolean.

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

Usage

From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java

/**
 * {@inheritDoc}/*  w  ww.  j av  a 2s  . c  o m*/
 */
@Override
public void disableZabbixMonitoring(Long instanceNo) {
    // ?
    if (instanceNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceNo");
    }

    // ??
    Instance instance = instanceDao.read(instanceNo);
    if (instance == null) {
        // ?????
        throw new AutoApplicationException("ESERVICE-000403", instanceNo);
    }

    // ZABBIX_INSTANCE??
    ZabbixInstance zabbixInstance = zabbixInstanceDao.read(instanceNo);
    if (zabbixInstance == null) {
        // ?????
        throw new AutoApplicationException("ESERVICE-000422", instanceNo);
    }

    // Zabbix(config.properties?zabbix.useZabbix)??
    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isNotTrue(useZabbix)) {
        // Zabbix?true?
        throw new AutoApplicationException("ESERVICE-000423", instanceNo);
    }

    // ?OS??
    InstanceStatus instanceStatus = getInstanceStatus(instance);
    if (instanceStatus != InstanceStatus.RUNNING) {
        // ?OS?RUNNING?
        throw new AutoApplicationException("ESERVICE-000426", instance.getInstanceName());
    }

    // Zabbix??
    ZabbixInstanceStatus zabbixInstanceStatus = ZabbixInstanceStatus.fromStatus(zabbixInstance.getStatus());
    if (zabbixInstanceStatus != ZabbixInstanceStatus.MONITORING) {
        // Zabbix??MONITORING?
        throw new AutoApplicationException("ESERVICE-000427", instance.getInstanceName());
    }

    // Zabbix
    zabbixHostProcess.stopHost(instanceNo);
}

From source file:org.apache.cocoon.acting.InputModuleAction.java

public void configure(Configuration conf) throws ConfigurationException {
    super.configure(conf);
    String tmp = (String) this.settings.get("single-value", "false");
    this.settings.put("single-value", BooleanUtils.toBooleanObject(tmp));
}

From source file:org.apache.cocoon.ajax.AjaxRequestSelector.java

public Object getSelectorContext(Map objectModel, Parameters parameters) {
    Request req = ObjectModelHelper.getRequest(objectModel);
    return BooleanUtils.toBooleanObject(AjaxHelper.isAjaxRequest(req));
}

From source file:org.apache.cocoon.components.elementprocessor.types.Attribute.java

/**
 * A convenience method to get the value of the attribute as a
 * boolean. Understands these value strings in a case-insensitive
 * fashion://w  ww.  j a  v a 2s.  c  o m
 * <ul>
 *     <li>t/f
 *     <li>true/false
 *     <li>y/n
 *     <li>yes/no
 *      <li>on/off
 * </ul>
 *
 * @return the value of the Attribute as a boolean
 *
 * @exception IllegalArgumentException if the value does not
 *            represent a boolean
 */

public boolean getValueAsBoolean() {
    // Match case for: true, false, yes, no, on, off.
    Boolean rvalue = BooleanUtils.toBooleanObject(_value);
    if (rvalue != null) {
        return rvalue.booleanValue();
    }
    // Lets try with "t", "f"
    try {
        rvalue = BooleanUtils.toBooleanObject(_value, "t", "f", null);
    } catch (IllegalArgumentException iae) {
        rvalue = null;
    }
    if (rvalue != null) {
        return rvalue.booleanValue();
    }
    // Try now "y", "n"
    try {
        rvalue = BooleanUtils.toBooleanObject(_value, "y", "n", null);
    } catch (IllegalArgumentException iae) {
        rvalue = null;
    }
    if (rvalue != null) {
        return rvalue.booleanValue();
    } else {
        throw new IllegalArgumentException("Value [" + _value + "] does not represent a boolean value");
    }
}

From source file:org.apache.cocoon.components.flow.javascript.ScriptableResult.java

ScriptableResult(Scriptable scope, ResultSet rs, int startRow, int maxRows)
        throws SQLException, PropertyException, NotAFunctionException, JavaScriptException {
    Context cx = Context.getCurrentContext();
    Scriptable rowMap = cx.newObject(scope, "Array");
    put("rows", this, rowMap);
    Scriptable rowByIndex = cx.newObject(scope, "Array");
    put("rowsByIndex", this, rowByIndex);

    ResultSetMetaData rsmd = rs.getMetaData();
    int noOfColumns = rsmd.getColumnCount();

    // Create the column name array
    Scriptable columnNames = cx.newObject(scope, "Array", new Object[] { new Integer(noOfColumns) });
    put("columnNames", this, columnNames);
    for (int i = 1; i <= noOfColumns; i++) {
        columnNames.put(i - 1, columnNames, rsmd.getColumnName(i));
    }/*from ww  w  . j a  v  a2s.  co m*/

    // Throw away all rows upto startRow
    for (int i = 0; i < startRow; i++) {
        rs.next();
    }

    // Process the remaining rows upto maxRows
    int processedRows = 0;
    int index = 0;
    boolean isLimited = false;
    while (rs.next()) {
        if ((maxRows != -1) && (processedRows == maxRows)) {
            isLimited = true;
            break;
        }
        Scriptable columns = cx.newObject(scope, "Array", new Object[] { new Integer(noOfColumns) });
        Scriptable columnMap = new Row();
        columnMap.setParentScope(columns.getParentScope());
        columnMap.setPrototype(getObjectPrototype(scope));

        // JDBC uses 1 as the lowest index!
        for (int i = 1; i <= noOfColumns; i++) {
            Object value = rs.getObject(i);
            if (rs.wasNull()) {
                value = null;
            }
            columns.put(i - 1, columns, value);
            columnMap.put(rsmd.getColumnName(i), columnMap, value);
        }
        rowMap.put(index, rowMap, columnMap);
        rowByIndex.put(index, rowByIndex, columns);
        processedRows++;
        index++;
    }
    put("rowCount", this, new Integer(index));
    put("isLimitedByMaxRows", this, BooleanUtils.toBooleanObject(isLimited));
}

From source file:org.apache.cocoon.components.pipeline.impl.CachingPointProcessingPipeline.java

/**
 * Add a transformer./*from  w w  w .  j av  a 2  s .c o m*/
 */
public void addTransformer(String role, String source, Parameters param, Parameters hintParam)
        throws ProcessingException {
    super.addTransformer(role, source, param, hintParam);

    // check the hint param for a "caching-point" hint
    String pipelinehint = null;
    try {
        pipelinehint = hintParam.getParameter("caching-point", null);

        if (this.getLogger().isDebugEnabled()) {
            getLogger().debug("transformer caching-point pipeline-hint is set to: " + pipelinehint);
        }
    } catch (Exception ex) {
        if (this.getLogger().isWarnEnabled()) {
            getLogger().warn("caching-point hint Exception, pipeline-hint ignored: " + ex);
        }
    }

    // add caching point flag
    // default value is false
    this.isCachePoint.add(BooleanUtils.toBooleanObject(this.nextIsCachePoint));

    // if this transformer is manually set to "caching-point" (via pipeline-hint)
    // then ensure the next component is caching.
    this.nextIsCachePoint = BooleanUtils.toBoolean(pipelinehint);
}

From source file:org.apache.cocoon.components.treeprocessor.sitemap.MountNode.java

public MountNode(VariableResolver prefix, VariableResolver source, TreeProcessor parentProcessor,
        boolean checkReload, boolean passThrough) {
    this.prefix = prefix;
    this.source = source;
    this.parentProcessor = parentProcessor;
    this.checkReload = checkReload;
    this.passThrough = BooleanUtils.toBooleanObject(passThrough);
}

From source file:org.apache.cocoon.components.xslt.TraxProcessor.java

/**
 * Get the TransformerFactory associated with the given classname. If the
 * class can't be found or the given class doesn't implement the required
 * interface, the default factory is returned.
 *//*from w  w  w  . ja  v a 2  s . c om*/
private SAXTransformerFactory getTransformerFactory(String factoryName) {
    SAXTransformerFactory _factory;

    if (null == factoryName) {
        _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
    } else {
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            if (loader == null) {
                loader = getClass().getClassLoader();
            }
            _factory = (SAXTransformerFactory) loader.loadClass(factoryName).newInstance();
        } catch (ClassNotFoundException cnfe) {
            getLogger().error("Cannot find the requested TrAX factory '" + factoryName
                    + "'. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        } catch (ClassCastException cce) {
            getLogger().error("The indicated class '" + factoryName
                    + "' is not a TrAX Transformer Factory. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        } catch (Exception e) {
            getLogger().error("Error found loading the requested TrAX Transformer Factory '" + factoryName
                    + "'. Using default TrAX Transformer Factory instead.");
            if (m_factory != null)
                return m_factory;
            _factory = (SAXTransformerFactory) TransformerFactory.newInstance();
        }
    }

    _factory.setErrorListener(new TraxErrorListener(getLogger(), null));
    _factory.setURIResolver(this);

    // FIXME (SM): implementation-specific parameter passing should be
    // made more extensible.
    if (_factory.getClass().getName().equals("org.apache.xalan.processor.TransformerFactoryImpl")) {
        _factory.setAttribute("http://xml.apache.org/xalan/features/incremental",
                BooleanUtils.toBooleanObject(m_incrementalProcessing));
    }
    // SAXON 8 will not report errors unless version warning is set to false.
    if (_factory.getClass().getName().equals("net.sf.saxon.TransformerFactoryImpl")) {
        _factory.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
    }

    return _factory;
}

From source file:org.apache.cocoon.faces.taglib.UIComponentTag.java

protected final void setBooleanProperty(UIComponent component, String name, String value) {
    if (value != null) {
        if (FacesUtils.isExpression(value)) {
            ValueBinding vb = createValueBinding(value);
            component.setValueBinding(name, vb);
        } else {//from w ww .j  a va  2s.  com
            component.getAttributes().put(name, BooleanUtils.toBooleanObject(value));
        }
    }
}

From source file:org.apache.cocoon.forms.formmodel.BooleanField.java

public void readFromRequest(FormContext formContext) {
    if (!getCombinedState().isAcceptingInputs()) {
        return;//from  ww w .j  a va2  s . c  o  m
    }

    validationError = null;
    Object oldValue = value;
    String param = formContext.getRequest().getParameter(getRequestParameterName());

    value = BooleanUtils.toBooleanObject(definition.getTrueParamValue().equals(param));

    if (!value.equals(oldValue)) {
        getForm().addWidgetEvent(new ValueChangedEvent(this, oldValue, value));
    }
}