List of usage examples for org.apache.commons.lang BooleanUtils toBooleanObject
public static Boolean toBooleanObject(String str)
Converts a String to a Boolean.
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:org.apache.cocoon.forms.formmodel.Form.java
/** * End the current form processing after the current phase. * * @param redisplayForm indicates if the form should be redisplayed to the user. *//*from w w w. ja v a 2 s.com*/ public void endProcessing(boolean redisplayForm) { // Set the indicator that terminates the form processing. // If redisplayForm is true, interaction is not finished and process() must // return false, hence the negation below. this.endProcessing = BooleanUtils.toBooleanObject(!redisplayForm); }
From source file:org.apache.cocoon.forms.generation.JXMacrosHelper.java
protected boolean pushWidget(String path, boolean unused) throws SAXException { Widget parent = peekWidget();//from www . j av a 2 s.co m if (path == null || path.length() == 0) { throw new FormsRuntimeException("Missing 'id' attribute on template instruction"); } Widget widget = parent.lookupWidget(path); if (widget == null) { throw new FormsRuntimeException(parent + " has no child named '" + path + "'", parent.getLocation()); } String id = widget.getFullName(); // Is there an updated widget at a higher level in the template? boolean inUpdatedTemplate = ((Boolean) widgetStack.peek(1)).booleanValue(); boolean display; if (ajaxRequest) { // An Ajax request. We will send partial updates if (inUpdatedTemplate) { // A parent widget has been updated: redisplay this one also display = true; } else if (this.updatedWidgets.contains(id)) { // Widget has been updated. We are now in an updated template section, // and widgets have to be surrounded with <bu:replace> inUpdatedTemplate = true; display = true; } else if (this.childUpdatedWidgets.contains(id)) { // A child need to be updated display = true; } else { // Doesn't need to be displayed display = false; } } else { // Not an ajax request if (ajaxTemplate) { // Surround all widgets with <bu:replace>, which the bu tranformer will use to check structure // consistency and add an id attribute to its child elements. inUpdatedTemplate = true; } // Display the widget display = true; } if (display) { // Widget needs to be displayed, but does it actually allows it? if (widget.getState().isDisplayingValues()) { if (inUpdatedTemplate) { // Updated part of an Ajax template: surround with <bu:replace> startBuReplace(id); } } else { if (ajaxTemplate) { // Generate a placeholder, so that the page can be updated later startBuReplace(id); AttributesImpl attrs = new AttributesImpl(); attrs.addCDATAAttribute("id", id); this.cocoonConsumer.startElement(FormsConstants.INSTANCE_NS, "placeholder", FormsConstants.INSTANCE_PREFIX_COLON + "placeholder", attrs); this.cocoonConsumer.endElement(FormsConstants.INSTANCE_NS, "placeholder", FormsConstants.INSTANCE_PREFIX_COLON + "placeholder"); endBuReplace(id); } // Production finished for this widget display = false; } } if (display) { this.widgetStack.push(BooleanUtils.toBooleanObject(inUpdatedTemplate)); this.widgetStack.push(widget); } return display; }
From source file:org.apache.cocoon.generation.CalendarGenerator.java
/** * Set the request parameters. Must be called before the generate method. * * @param resolver the SourceResolver object * @param objectModel a <code>Map</code> containing model object * @param src the source URI (ignored) * @param par configuration parameters *//*from ww w.java 2 s . com*/ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, par); this.cacheKeyParList = new ArrayList(); this.cacheKeyParList.add(src); // Determine the locale String langString = par.getParameter("lang", null); locale = Locale.getDefault(); if (langString != null) { this.cacheKeyParList.add(langString); String countryString = par.getParameter("country", ""); if (!"".equals(countryString)) { this.cacheKeyParList.add(countryString); } locale = new Locale(langString, countryString); } // Determine year and month. Default is current year and month. Calendar now = Calendar.getInstance(locale); this.year = par.getParameterAsInteger("year", now.get(Calendar.YEAR)); this.cacheKeyParList.add(String.valueOf(this.year)); this.month = par.getParameterAsInteger("month", now.get(Calendar.MONTH) + 1) - 1; this.cacheKeyParList.add(String.valueOf(this.month)); String dateFormatString = par.getParameter("dateFormat", null); this.cacheKeyParList.add(dateFormatString); if (dateFormatString != null) { this.dateFormatter = new SimpleDateFormat(dateFormatString, locale); } else { this.dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, locale); } this.padWeeks = par.getParameterAsBoolean("padWeeks", false); this.cacheKeyParList.add(BooleanUtils.toBooleanObject(this.padWeeks)); this.monthFormatter = new SimpleDateFormat("MMMM", locale); this.attributes = new AttributesImpl(); }
From source file:org.apache.cocoon.portal.impl.LinkInfo.java
public String getBase(Boolean secure) { // if no information is provided, we stay with the same protocol if (secure == null) { secure = BooleanUtils.toBooleanObject(this.isSecure); }/*from ww w .j a v a 2 s. co m*/ if (secure.booleanValue()) { return this.secureLinkBase + this.url.toString(); } return this.httpLinkBase + this.url.toString(); }
From source file:org.apache.cocoon.portal.pluto.om.common.PreferenceImpl.java
/** * @see org.apache.pluto.om.common.PreferenceCtrl#setReadOnly(java.lang.String) *//*from w ww.java 2s . co m*/ public void setReadOnly(String readOnly) { this.readOnly = BooleanUtils.toBooleanObject(readOnly); }
From source file:org.apache.cocoon.portal.transformation.HTMLRootTransformer.java
public Serializable getKey() { return new Boolean[] { BooleanUtils.toBooleanObject(this.addMode), BooleanUtils.toBooleanObject(this.ignoreRootElement) }; }
From source file:org.apache.cocoon.serialization.AbstractTextSerializer.java
/** * Checks if the used Trax implementation correctly handles namespaces set using * <code>startPrefixMapping()</code>, but wants them also as 'xmlns:' attributes. * <p>//from w w w.j a v a 2s.c om * The check consists in sending SAX events representing a minimal namespaced document * with namespaces defined only with calls to <code>startPrefixMapping</code> (no * xmlns:xxx attributes) and check if they are present in the resulting text. */ protected boolean needsNamespacesAsAttributes() throws Exception { SAXTransformerFactory factory = getTransformerFactory(); Boolean cacheValue = (Boolean) needsNamespaceCache.get(factory.getClass().getName()); if (cacheValue != null) { return cacheValue.booleanValue(); } else { // Serialize a minimal document to check how namespaces are handled. StringWriter writer = new StringWriter(); String uri = "namespaceuri"; String prefix = "nsp"; String check = "xmlns:" + prefix + "='" + uri + "'"; TransformerHandler handler = this.getTransformerHandler(); handler.getTransformer().setOutputProperties(format); handler.setResult(new StreamResult(writer)); // Output a single element handler.startDocument(); handler.startPrefixMapping(prefix, uri); handler.startElement(uri, "element", "element", XMLUtils.EMPTY_ATTRIBUTES); handler.endElement(uri, "element", "element"); handler.endPrefixMapping(prefix); handler.endDocument(); String text = writer.toString(); // Check if the namespace is there (replace " by ' to be sure of what we search in) boolean needsIt = (text.replace('"', '\'').indexOf(check) == -1); String msg = needsIt ? " needs namespace attributes (will be slower)." : " handles correctly namespaces."; getLogger().debug("Trax handler " + handler.getClass().getName() + msg); needsNamespaceCache.put(factory.getClass().getName(), BooleanUtils.toBooleanObject(needsIt)); return needsIt; } }
From source file:org.apache.cocoon.serialization.SVGSerializer.java
/** * Set the configurations for this serializer. *//* w ww .jav a 2 s. c o m*/ public void configure(Configuration conf) throws ConfigurationException { this.mimetype = conf.getAttribute("mime-type"); if (getLogger().isDebugEnabled()) { getLogger().debug("mime-type: " + mimetype); } // Using the Transcoder Factory, get the default transcoder // for this MIME type. this.transcoder = factory.createTranscoder(mimetype); // Iterate through the parameters, looking for a transcoder reference Configuration[] parameters = conf.getChildren("parameter"); for (int i = 0; i < parameters.length; i++) { String name = parameters[i].getAttribute("name"); if ("transcoder".equals(name)) { String transcoderName = parameters[i].getAttribute("value"); try { this.transcoder = (Transcoder) ClassUtils.newInstance(transcoderName); } catch (Exception ex) { if (getLogger().isDebugEnabled()) { getLogger().debug("Cannot load class " + transcoderName, ex); } throw new ConfigurationException("Cannot load class " + transcoderName, ex); } } } // Do we have a transcoder yet? if (this.transcoder == null) { throw new ConfigurationException("Could not autodetect transcoder for SVGSerializer and " + "no transcoder was specified in the sitemap configuration."); } // Now run through the other parameters, using them as hints // to the transcoder for (int i = 0; i < parameters.length; i++) { String name = parameters[i].getAttribute("name"); // Skip over the parameters we've dealt with. Ensure this // is kept in sync with the above list! if ("transcoder".equals(name)) { continue; } // Now try and get the hints out try { // Turn it into a key name (assume the current Batik style continues! name = ("KEY_" + name).toUpperCase(); // Use reflection to get a reference to the key object TranscodingHints.Key key = (TranscodingHints.Key) (transcoder.getClass().getField(name) .get(transcoder)); Object value; String keyType = parameters[i].getAttribute("type", "STRING").toUpperCase(); if ("FLOAT".equals(keyType)) { // Can throw an exception. value = new Float(parameters[i].getAttributeAsFloat("value")); } else if ("INTEGER".equals(keyType)) { // Can throw an exception. value = new Integer(parameters[i].getAttributeAsInteger("value")); } else if ("BOOLEAN".equals(keyType)) { // Can throw an exception. value = BooleanUtils.toBooleanObject(parameters[i].getAttributeAsBoolean("value")); } else if ("COLOR".equals(keyType)) { // Can throw an exception String stringValue = parameters[i].getAttribute("value"); if (stringValue.startsWith("#")) { stringValue = stringValue.substring(1); } value = new Color(Integer.parseInt(stringValue, 16)); } else { // Assume String, and get the value. Allow an empty string. value = parameters[i].getAttribute("value", ""); } if (getLogger().isDebugEnabled()) { getLogger().debug("Adding hint \"" + name + "\" with value \"" + value.toString() + "\""); } transcoder.addTranscodingHint(key, value); } catch (ClassCastException ex) { // This is only thrown from the String keyType... line throw new ConfigurationException( "Specified key (" + name + ") is not a valid Batik Transcoder key.", ex); } catch (ConfigurationException ex) { throw new ConfigurationException("Name or value not specified.", ex); } catch (IllegalAccessException ex) { throw new ConfigurationException("Cannot access the key for parameter \"" + name + "\"", ex); } catch (NoSuchFieldException ex) { throw new ConfigurationException("No field available for parameter \"" + name + "\"", ex); } } }
From source file:org.apache.cocoon.taglib.core.ForEachSupport.java
protected ForEachIterator toForEachIterator(boolean[] a) { Boolean[] wrapped = new Boolean[a.length]; for (int i = 0; i < a.length; i++) wrapped[i] = BooleanUtils.toBooleanObject(a[i]); return new SimpleForEachIterator(Arrays.asList(wrapped).iterator()); }
From source file:org.apache.cocoon.transformation.CIncludeTransformer.java
public void startTransformingElement(String uri, String name, String raw, Attributes attr) throws ProcessingException, IOException, SAXException { // Element: include if (name.equals(CINCLUDE_INCLUDE_ELEMENT)) { String stripRootValue = attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE); boolean stripRoot = StringUtils.equals(stripRootValue, "true"); processCIncludeElement(attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE), attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE), attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE), attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE), attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE), stripRoot, false); // Element: includexml } else if (name.equals(CINCLUDE_INCLUDEXML_ELEMENT) && this.state == STATE_OUTSIDE) { this.state = STATE_INCLUDE; String ignoreErrors = attr.getValue("", CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE); if (ignoreErrors == null || ignoreErrors.length() == 0) { ignoreErrors = "false"; }/*from w w w . ja va 2 s .c o m*/ this.stack.push(BooleanUtils.toBooleanObject(this.ignoreEmptyCharacters)); this.stack.push(BooleanUtils.toBooleanObject(this.ignoreWhitespaces)); this.stack.push(ignoreErrors); this.ignoreEmptyCharacters = false; this.ignoreWhitespaces = true; // target } else if (name.equals(CINCLUDE_SRC_ELEMENT) && this.state == STATE_INCLUDE) { this.startTextRecording(); // configparameters } else if (name.equals(CINCLUDE_CONFIGURATION_ELEMENT) && this.state == STATE_INCLUDE) { stack.push("end"); // parameters } else if (name.equals(CINCLUDE_PARAMETERS_ELEMENT) && this.state == STATE_INCLUDE) { stack.push("end"); // parameter } else if (name.equals(CINCLUDE_PARAMETER_ELEMENT) && this.state == STATE_INCLUDE) { // parameter name } else if (name.equals(CINCLUDE_NAME_ELEMENT) && this.state == STATE_INCLUDE) { this.startTextRecording(); // parameter value } else if (name.equals(CINCLUDE_VALUE_ELEMENT) && this.state == STATE_INCLUDE) { this.startSerializedXMLRecording(XMLUtils.createPropertiesForXML(true)); } else if (name.equals(CINCLUDE_CACHED_INCLUDE_ELEMENT)) { String src = processCIncludeElement(attr.getValue("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE), null, null, null, null, false, this.cacheManager != null); if (this.compiling) { this.srcAttributes.addAttribute("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE, CINCLUDE_SRC_ELEMENT, "CDATA", src); super.startTransformingElement(uri, CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT, raw + "p", this.srcAttributes); this.srcAttributes.clear(); } } else { super.startTransformingElement(uri, name, raw, attr); } }