Author: vgritsenko Date: Tue Apr 26 09:43:13 2005 New Revision: 164815 URL: http://svn.apache.org/viewcvs?rev=164815&view=rev Log: Use EMPTY_PROPERTIES
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/notification/Notifier.java cocoon/trunk/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java cocoon/trunk/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java cocoon/trunk/src/java/org/apache/cocoon/serialization/TextSerializer.java cocoon/trunk/src/java/org/apache/cocoon/sitemap/DefaultContentAggregator.java cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java cocoon/trunk/src/java/org/apache/cocoon/xml/dom/DOMUtil.java cocoon/trunk/src/samples/org/apache/cocoon/samples/errorhandling/ExceptionGenerator.java cocoon/trunk/src/samples/org/apache/cocoon/samples/parentcm/Generator.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/notification/Notifier.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/notification/Notifier.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/notification/Notifier.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/notification/Notifier.java Tue Apr 26 09:43:13 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.apache.cocoon.components.notification; import org.apache.cocoon.Constants; +import org.apache.cocoon.xml.XMLUtils; import org.apache.commons.lang.StringEscapeUtils; import org.xml.sax.ContentHandler; @@ -32,7 +33,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id$ + * @version $Id$ */ public class Notifier { @@ -134,16 +135,15 @@ } ch.endElement(URI, "message", PREFIX + ":message"); - ch.startElement(URI, "description", PREFIX + ":description", - new AttributesImpl()); + ch.startElement(URI, "description", PREFIX + ":description", XMLUtils.EMPTY_ATTRIBUTES); ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length()); ch.endElement(URI, "description", PREFIX + ":description"); Map extraDescriptions = n.getExtraDescriptions(); - Iterator keyIter = extraDescriptions.keySet().iterator(); - while (keyIter.hasNext()) { - String key = (String) keyIter.next(); - String value = String.valueOf(extraDescriptions.get(key)); + for (Iterator i = extraDescriptions.entrySet().iterator(); i.hasNext(); ) { + final Map.Entry me = (Map.Entry) i.next(); + String key = (String) me.getKey(); + String value = String.valueOf(me.getValue()); atts = new AttributesImpl(); atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key); Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java Tue Apr 26 09:43:13 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -55,9 +55,11 @@ * @author Michael Homeijer * @author Nicola Ken Barozzi ([EMAIL PROTECTED]) * @author Bernhard Huber ([EMAIL PROTECTED]) - * @version CVS $Id: LinkStatusGenerator.java,v 1.10 2004/05/26 14:11:34 cziegeler Exp $ + * @version $Id$ */ -public class LinkStatusGenerator extends ServiceableGenerator implements Recyclable, Configurable { +public class LinkStatusGenerator extends ServiceableGenerator + implements Recyclable, Configurable { + /** The URI of the namespace of this generator. */ protected static final String URI = "http://apache.org/cocoon/linkstatus/2.0"; @@ -75,7 +77,7 @@ protected static final String STATUS_ATTR_NAME = "status"; protected static final String MESSAGE_ATTR_NAME = "message"; - protected AttributesImpl attributes = new AttributesImpl(); + protected AttributesImpl attributes; /** * Config element name specifying expected link content-typ. @@ -312,7 +314,7 @@ } public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) - throws ProcessingException, SAXException, IOException { + throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, par); @@ -333,7 +335,7 @@ * if the requsted URI wasn't found */ public void generate() - throws SAXException, ProcessingException { + throws SAXException, ProcessingException { try { crawled = new HashSet(); @@ -656,6 +658,5 @@ super.recycle(); this.attributes = null; - //this.excludeCrawlingURL = null; } } Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/generation/SessionAttributeGenerator.java Tue Apr 26 09:43:13 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,12 +33,12 @@ /** * @cocoon.sitemap.component.documentation - * Generates a document from a session attribute. - * + * Generates a document from a session attribute. + * * @cocoon.sitemap.component.name sessionattribute * @cocoon.sitemap.component.label content * @cocoon.sitemap.component.logger sitemap.generator.sessionattribute - * + * * Generates a document from a session attribute. The attribute may be a DOM * node, an <code>XMLizable</code>, or any other object, and is streamed using * the same rules as for <xsp:expr> in XSPs (see [EMAIL PROTECTED] @@ -73,7 +73,7 @@ * @see org.apache.cocoon.transformation.WriteDOMSessionTransformer * @author <a href="mailto:[EMAIL PROTECTED]">Cédric Damioli</a> * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> - * @version CVS $Id: SessionAttributeGenerator.java,v 1.5 2004/05/26 14:11:34 cziegeler Exp $ + * @version $Id$ */ public class SessionAttributeGenerator extends AbstractGenerator { @@ -91,12 +91,12 @@ */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { - + super.setup(resolver, objectModel, src, par); - + // Get the element name (can be null if the object is a DOM or an XMLizable) this.elementName = par.getParameter(ELEMENT_NAME, null); - + // Get the attribute name String attrName = par.getParameter(ATTR_NAME, src); if (attrName == null) { @@ -111,7 +111,7 @@ if (session != null) { this.attrObject = session.getAttribute(attrName); } - + // Controls if (this.attrObject == null) { if (this.elementName == null) { @@ -132,7 +132,7 @@ ! (this.attrObject instanceof XMLizable) && ! (this.attrObject instanceof Node)) { - String msg = "Session attribute '" + attrName + "' needs an enclosing element : class is " + + String msg = "Session attribute '" + attrName + "' needs an enclosing element : class is " + this.attrObject.getClass().getName(); getLogger().warn(msg); @@ -144,17 +144,18 @@ /** * Generate XML data */ - public void generate() throws IOException, SAXException, ProcessingException { + public void generate() + throws IOException, SAXException, ProcessingException { xmlConsumer.startDocument(); if (this.elementName != null) { - xmlConsumer.startElement("", this.elementName, this.elementName, new AttributesImpl()); + xmlConsumer.startElement("", this.elementName, this.elementName, XMLUtils.EMPTY_ATTRIBUTES); XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer), this.attrObject); xmlConsumer.endElement("", this.elementName, this.elementName); } else { XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer), this.attrObject); } - + xmlConsumer.endDocument(); } } Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java Tue Apr 26 09:43:13 2005 @@ -38,6 +38,8 @@ import org.apache.cocoon.core.Core; import org.apache.cocoon.core.Settings; import org.apache.cocoon.environment.SourceResolver; +import org.apache.cocoon.xml.XMLUtils; + import org.apache.commons.lang.SystemUtils; import org.apache.excalibur.store.Store; import org.apache.excalibur.store.StoreJanitor; @@ -510,7 +512,7 @@ AttributesImpl ai = (atts == null) ? new AttributesImpl() : new AttributesImpl(atts); ai.addAttribute(namespace, "name", "name", "CDATA", name); this.xmlConsumer.startElement(namespace, "value", "value", ai); - this.xmlConsumer.startElement(namespace, "line", "line", new AttributesImpl()); + this.xmlConsumer.startElement(namespace, "line", "line", XMLUtils.EMPTY_ATTRIBUTES); if (value != null) { this.xmlConsumer.characters(value.toCharArray(), 0, value.length()); @@ -536,7 +538,7 @@ for (int i = 0; i < values.size(); i++) { String value = (String) values.get(i); if (value != null) { - this.xmlConsumer.startElement(namespace, "line", "line", new AttributesImpl()); + this.xmlConsumer.startElement(namespace, "line", "line", XMLUtils.EMPTY_ATTRIBUTES); this.xmlConsumer.characters(value.toCharArray(), 0, value.length()); this.xmlConsumer.endElement(namespace, "line", "line"); } Modified: cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java Tue Apr 26 09:43:13 2005 @@ -25,6 +25,8 @@ import org.apache.cocoon.util.TraxErrorHandler; import org.apache.cocoon.xml.AbstractXMLPipe; import org.apache.cocoon.xml.XMLConsumer; +import org.apache.cocoon.xml.XMLUtils; + import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.NOPValidity; import org.xml.sax.Attributes; @@ -320,7 +322,7 @@ // Output a single element handler.startDocument(); handler.startPrefixMapping(prefix, uri); - handler.startElement(uri, "element", "", new AttributesImpl()); + handler.startElement(uri, "element", "", XMLUtils.EMPTY_ATTRIBUTES); handler.endPrefixMapping(prefix); handler.endDocument(); Modified: cocoon/trunk/src/java/org/apache/cocoon/serialization/TextSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/serialization/TextSerializer.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/serialization/TextSerializer.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/serialization/TextSerializer.java Tue Apr 26 09:43:13 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,6 +18,8 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.CascadingIOException; +import org.apache.cocoon.xml.XMLUtils; + import org.xml.sax.SAXException; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; @@ -38,7 +40,7 @@ * should wrap all the text inside it. * * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id: TextSerializer.java,v 1.3 2004/03/05 13:02:58 bdelacretaz Exp $ + * @version $Id$ */ public class TextSerializer extends AbstractTextSerializer { @@ -73,23 +75,23 @@ this.setContentHandler(handler); this.setLexicalHandler(handler); } catch (Exception e) { - final String message = "Cannot set TextSerializer outputstream"; + final String message = "Cannot set TextSerializer outputstream"; throw new CascadingIOException(message, e); } } public void startElement(String uri, String loc, String raw, Attributes a) - throws SAXException { + throws SAXException { this.hasRootElement = true; super.startElement(uri, loc, raw, a); } public void characters(char c[], int start, int len) - throws SAXException { + throws SAXException { if (!this.hasRootElement) { this.hasRootElement = this.hadNoRootElement = true; getLogger().warn("Encountered text before root element. Creating <text> wrapper element."); - super.startElement("", "text", "text", new AttributesImpl()); + super.startElement("", "text", "text", XMLUtils.EMPTY_ATTRIBUTES); } super.characters(c, start, len); } Modified: cocoon/trunk/src/java/org/apache/cocoon/sitemap/DefaultContentAggregator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/sitemap/DefaultContentAggregator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/sitemap/DefaultContentAggregator.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/sitemap/DefaultContentAggregator.java Tue Apr 26 09:43:13 2005 @@ -27,6 +27,7 @@ import org.apache.cocoon.generation.Generator; import org.apache.cocoon.xml.ContentHandlerWrapper; import org.apache.cocoon.xml.XMLConsumer; +import org.apache.cocoon.xml.XMLUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.excalibur.source.Source; @@ -35,7 +36,6 @@ import org.apache.excalibur.source.impl.validity.AggregatedValidity; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; import java.io.Serializable; @@ -51,10 +51,9 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version $Id$ */ -public class DefaultContentAggregator - extends ContentHandlerWrapper - implements Generator, CacheableProcessingComponent, Serviceable, - ContentAggregator { +public class DefaultContentAggregator extends ContentHandlerWrapper + implements Generator, CacheableProcessingComponent, + Serviceable, ContentAggregator { /** The root element of the aggregated content */ protected Element rootElement; @@ -62,9 +61,6 @@ /** The aggregated parts */ protected ArrayList parts = new ArrayList(); - /** Empty attributes */ - private static final Attributes EMPTY_ATTRS = new AttributesImpl(); - /** Indicates the position in the stack of the root element of the aggregated content */ private int rootElementIndex; @@ -311,7 +307,7 @@ if (!element.namespace.equals("")) { this.contentHandler.startPrefixMapping(element.prefix, element.namespace); } - this.contentHandler.startElement(element.namespace, element.name, qname, EMPTY_ATTRS); + this.contentHandler.startElement(element.namespace, element.name, qname, XMLUtils.EMPTY_ATTRIBUTES); } /** Modified: cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java Tue Apr 26 09:43:13 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,12 +101,20 @@ * is invoked. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id$ + * @version $Id$ */ public abstract class AbstractSAXTransformer extends AbstractTransformer implements Serviceable, Configurable, Recyclable { + + /** + * Empty attributes (for performance). This can be used + * do create own attributes, but make sure to clean them + * afterwords. + */ + protected static final Attributes EMPTY_ATTRIBUTES = XMLUtils.EMPTY_ATTRIBUTES; + /** * The trax <code>TransformerFactory</code> used by this transformer. */ @@ -213,13 +221,6 @@ private boolean isInitialized; /** - * Empty attributes (for performance). This can be used - * do create own attributes, but make sure to clean them - * afterwords. - */ - protected AttributesImpl emptyAttributes = new AttributesImpl(); - - /** * The namespaces and their prefixes */ private final List namespaces = new ArrayList(5); @@ -626,7 +627,7 @@ DOMBuilder builder = new DOMBuilder(this.tfactory); addRecorder(builder); builder.startDocument(); - builder.startElement("", "cocoon", "cocoon", new AttributesImpl()); + builder.startElement("", "cocoon", "cocoon", EMPTY_ATTRIBUTES); sendStartPrefixMapping(); } @@ -755,7 +756,7 @@ */ public void sendStartElementEvent(String localname) throws SAXException { - startElement("", localname, localname, emptyAttributes); + startElement("", localname, localname, EMPTY_ATTRIBUTES); } /** @@ -769,7 +770,7 @@ public void sendStartElementEventNS(String localname) throws SAXException { startElement(this.namespaceURI, - localname, this.ourPrefix + ':' + localname, emptyAttributes); + localname, this.ourPrefix + ':' + localname, EMPTY_ATTRIBUTES); } /** Modified: cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java Tue Apr 26 09:43:13 2005 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,11 +122,10 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @author <a href="mailto:[EMAIL PROTECTED]">Andrew C. Oliver</a> - * @version CVS $Id$ + * @version $Id$ */ -public class CIncludeTransformer -extends AbstractSAXTransformer -implements Disposable, CacheableProcessingComponent { +public class CIncludeTransformer extends AbstractSAXTransformer + implements Disposable, CacheableProcessingComponent { public static final String CINCLUDE_NAMESPACE_URI = "http://apache.org/cocoon/include/1.0"; public static final String CINCLUDE_INCLUDE_ELEMENT = "include"; @@ -505,14 +504,13 @@ // usual no caching stuff if (!"".equals(element)) { - AttributesImpl attrs = new AttributesImpl(); if (!ns.equals("")) { super.startPrefixMapping(prefix, ns); } super.startElement(ns, element, (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element), - attrs); + XMLUtils.EMPTY_ATTRIBUTES); } Source source = null; Modified: cocoon/trunk/src/java/org/apache/cocoon/xml/dom/DOMUtil.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/xml/dom/DOMUtil.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/xml/dom/DOMUtil.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/xml/dom/DOMUtil.java Tue Apr 26 09:43:13 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,22 +15,9 @@ */ package org.apache.cocoon.xml.dom; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; - import org.apache.cocoon.ProcessingException; import org.apache.cocoon.xml.IncludeXMLConsumer; + import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.excalibur.source.SourceParameters; @@ -48,14 +35,28 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.TransformerException; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; /** * This class is a utility class for miscellaneous DOM functions, like * getting and setting values of nodes. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: DOMUtil.java,v 1.11 2004/05/25 14:24:01 cziegeler Exp $ + * @version $Id$ */ public final class DOMUtil { @@ -267,7 +268,7 @@ DOMBuilder builder = new DOMBuilder(); builder.startDocument(); - builder.startElement("", "root", "root", new AttributesImpl()); + builder.startElement("", "root", "root", XMLUtils.EMPTY_ATTRIBUTES); IncludeXMLConsumer filter = new IncludeXMLConsumer(builder, builder); parser.parse(input, filter); @@ -493,8 +494,8 @@ /** * Implementation for <code>java.util.Map</code> : * For each entry an element is created with the childs key and value - * Outputs the value and the key by calling [EMAIL PROTECTED] #valueOf(Node, Object)} - * on each value and key of the Map. + * Outputs the value and the key by calling [EMAIL PROTECTED] #valueOf(Node, Object)} + * on each value and key of the Map. * * @param parent The node getting the value * @param v the Map @@ -504,19 +505,19 @@ Iterator iterator = v.keySet().iterator(); Node mapNode = parent.getOwnerDocument().createElementNS(null, "java.util.map"); parent.appendChild(mapNode); - while (iterator.hasNext()) { - Object key = iterator.next(); + for (Iterator iter = v.entrySet().iterator(); iter.hasNext();) { + final Map.Entry me = (Map.Entry) iter.next(); Node entryNode = mapNode.getOwnerDocument().createElementNS(null, "entry"); mapNode.appendChild(entryNode); Node keyNode = entryNode.getOwnerDocument().createElementNS(null, "key"); entryNode.appendChild(keyNode); - valueOf(keyNode, key); + valueOf(keyNode, me.getKey()); Node valueNode = entryNode.getOwnerDocument().createElementNS(null, "value"); entryNode.appendChild(valueNode); - valueOf(valueNode, v.get(key)); + valueOf(valueNode, me.getValue()); } } } @@ -589,12 +590,12 @@ * * @throws TransformerException */ - public static Node getSingleNode(Node contextNode, String str, - XPathProcessor processor) + public static Node getSingleNode(Node contextNode, String str, + XPathProcessor processor) throws TransformerException { String[] pathComponents = buildPathArray(str); if (pathComponents == null) { - return processor.selectSingleNode(contextNode, str); + return processor.selectSingleNode(contextNode, str); } else { return getFirstNodeFromPath(contextNode, pathComponents, false); } @@ -834,7 +835,7 @@ * @throws ProcessingException If the node is not found. */ public static boolean getValueAsBooleanOf(Node root, String path, - XPathProcessor processor) + XPathProcessor processor) throws ProcessingException { String value = getValueOf(root, path, processor); if (value == null) { @@ -863,7 +864,7 @@ if (value != null) { return Boolean.valueOf(value).booleanValue(); } - return defaultValue; + return defaultValue; } /** @@ -898,7 +899,7 @@ if (pathComponents != null) { return getNodeListFromPath(contextNode, pathComponents); } - return processor.selectNodeList(contextNode, str); + return processor.selectNodeList(contextNode, str); } /** Modified: cocoon/trunk/src/samples/org/apache/cocoon/samples/errorhandling/ExceptionGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/samples/org/apache/cocoon/samples/errorhandling/ExceptionGenerator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/samples/org/apache/cocoon/samples/errorhandling/ExceptionGenerator.java (original) +++ cocoon/trunk/src/samples/org/apache/cocoon/samples/errorhandling/ExceptionGenerator.java Tue Apr 26 09:43:13 2005 @@ -20,10 +20,9 @@ import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.generation.AbstractGenerator; +import org.apache.cocoon.xml.XMLUtils; -import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; import java.util.Map; @@ -59,11 +58,10 @@ */ public void generate() throws ProcessingException , SAXException, IOException { - Attributes noAttrs = new AttributesImpl(); this.contentHandler.startDocument(); - this.contentHandler.startElement("", "html", "html", noAttrs); - this.contentHandler.startElement("", "body", "body", noAttrs); - this.contentHandler.startElement("", "p", "p", noAttrs); + this.contentHandler.startElement("", "html", "html", XMLUtils.EMPTY_ATTRIBUTES); + this.contentHandler.startElement("", "body", "body", XMLUtils.EMPTY_ATTRIBUTES); + this.contentHandler.startElement("", "p", "p", XMLUtils.EMPTY_ATTRIBUTES); String text = ExceptionAction.exception(this.exception, this.code); this.contentHandler.characters(text.toCharArray(), 0, text.length()); Modified: cocoon/trunk/src/samples/org/apache/cocoon/samples/parentcm/Generator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/samples/org/apache/cocoon/samples/parentcm/Generator.java?rev=164815&r1=164814&r2=164815&view=diff ============================================================================== --- cocoon/trunk/src/samples/org/apache/cocoon/samples/parentcm/Generator.java (original) +++ cocoon/trunk/src/samples/org/apache/cocoon/samples/parentcm/Generator.java Tue Apr 26 09:43:13 2005 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * + * Copyright 1999-2005 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,6 +19,7 @@ import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.service.ServiceException; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.generation.ServiceableGenerator; import org.xml.sax.SAXException; @@ -35,7 +36,7 @@ * <code>Time</code> component. * * @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a> - * @version CVS $Id: Generator.java,v 1.3 2004/05/24 12:42:44 cziegeler Exp $ + * @version $Id$ */ public class Generator extends ServiceableGenerator implements Poolable { @@ -64,13 +65,12 @@ /** * Generate XML data. */ - public void generate() throws SAXException, ProcessingException { - AttributesImpl emptyAttributes = new AttributesImpl(); + public void generate() + throws SAXException, ProcessingException { contentHandler.startDocument(); - contentHandler.startElement("", "time", "time", emptyAttributes); + contentHandler.startElement("", "time", "time", XMLUtils.EMPTY_ATTRIBUTES); char[] text = this.time.toString().toCharArray(); - contentHandler.characters(text, 0, text.length); contentHandler.endElement("", "time", "time");