Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/log/package.html URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/log/package.html?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/log/package.html (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/log/package.html Thu Nov 3 05:41:06 2005 @@ -0,0 +1,25 @@ + + + + LogKit related utilities + + +

LogKit related utilities

+

+

+ + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/log/package.html ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/mime.types URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/mime.types?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/mime.types (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/mime.types Thu Nov 3 05:41:06 2005 @@ -0,0 +1,28 @@ +# MIME type mappings +text/plain txt text +text/html html htm +text/xml xml +text/css css +text/rtf rtf +application/rtf rtf +text/vnd.wap.wml wml +image/jpeg jpeg jpg jpe +image/png png +image/gif gif +image/tiff tiff tif +image/svg+xml svg svgz +image/svg-xml svg +application/pdf pdf +model/vrml wrl +application/smil smil +text/javascript js +application/x-javascript js +text/vbscript vbs +application/zip zip +video/mpeg mpeg mpg mpe +video/quicktime mov +audio/midi mid +audio/mpeg mp3 +text/x-vcard vcf +text/rdf rdf +application/octet-stream Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/mime.types ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractDOMFragment.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractDOMFragment.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractDOMFragment.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractDOMFragment.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,72 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.cocoon.xml.dom.DOMStreamer; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +/** + * Abstract implementation of {@link XMLFragment} for objects that are more + * easily represented as a DOM. + * + *

The {@link #toSAX} method is implemented by streaming (using a + * {@link DOMStreamer}) the results of the {@link #toDOM} that must be + * implemented by concrete subclasses.

+ * + * @author Sylvain Wallez + * @version CVS $Id: AbstractDOMFragment.java 55391 2004-10-23 18:15:02Z cziegeler $ + */ +public abstract class AbstractDOMFragment implements XMLFragment { + + /** + * Generates SAX events representing the object's state by serializing the + * result of toDOM(). + */ + public void toSAX(ContentHandler handler) throws SAXException { + // The ServiceManager is unknown here : use JAXP to create a document + DocumentBuilder builder; + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new SAXException("Couldn't get a DocumentBuilder", e); + } + + Document doc = builder.newDocument(); + + // Create a DocumentFragment that will hold the results of toDOM() + // (which can create several top-level elements) + Node df = doc.createDocumentFragment(); + + // Build the DOM representation of this object + try { + toDOM(df); + } catch(Exception e) { + throw new SAXException("Exception while converting object to DOM", e); + } + + // Stream the document fragment + handler.startDocument(); + new DOMStreamer(handler).stream(df); + handler.endDocument(); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractDOMFragment.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractSAXFragment.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractSAXFragment.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractSAXFragment.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractSAXFragment.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.cocoon.xml.dom.DOMBuilder; +import org.w3c.dom.Node; + +/** + * Abstract implementation of {@link XMLFragment} for objects that are more + * easily represented as SAX events. + * + *

The {@link #toDOM} method is implemented by piping in a {@link DOMBuilder} + * the results of {@link #toSAX} that must be implemented by concrete + * subclasses.

+ * + * @author Sylvain Wallez + * @version CVS $Id: AbstractSAXFragment.java 53979 2004-10-07 14:26:29Z vgritsenko $ + */ +public abstract class AbstractSAXFragment implements XMLFragment { + + /** + * Appends children representing the object's state to the given node + * by using the results of toSAX(). + */ + public void toDOM(Node node) throws Exception { + toSAX(new DOMBuilder(node)); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractSAXFragment.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLConsumer.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLConsumer.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLConsumer.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLConsumer.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,215 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + +/** + * This abstract class provides default implementation of the methods specified + * by the XMLConsumer interface. + * + * @author Pierpaolo Fumagalli + * (Apache Software Foundation) + * @version CVS $Id: AbstractXMLConsumer.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public abstract class AbstractXMLConsumer extends AbstractLogEnabled implements XMLConsumer { + + /** + * Receive an object for locating the origin of SAX document events. + * + * @param locator An object that can return the location of any SAX + * document event. + */ + public void setDocumentLocator(Locator locator) { + } + + /** + * Receive notification of the beginning of a document. + */ + public void startDocument() + throws SAXException { + } + + /** + * Receive notification of the end of a document. + */ + public void endDocument() + throws SAXException { + } + + /** + * Begin the scope of a prefix-URI Namespace mapping. + * + * @param prefix The Namespace prefix being declared. + * @param uri The Namespace URI the prefix is mapped to. + */ + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + } + + /** + * End the scope of a prefix-URI mapping. + * + * @param prefix The prefix that was being mapping. + */ + public void endPrefixMapping(String prefix) + throws SAXException { + } + + /** + * Receive notification of the beginning of an element. + * + * @param uri The Namespace URI, or the empty string if the element has no + * Namespace URI or if Namespace + * processing is not being performed. + * @param loc The local name (without prefix), or the empty string if + * Namespace processing is not being performed. + * @param raw The raw XML 1.0 name (with prefix), or the empty string if + * raw names are not available. + * @param a The attributes attached to the element. If there are no + * attributes, it shall be an empty Attributes object. + */ + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + } + + + /** + * Receive notification of the end of an element. + * + * @param uri The Namespace URI, or the empty string if the element has no + * Namespace URI or if Namespace + * processing is not being performed. + * @param loc The local name (without prefix), or the empty string if + * Namespace processing is not being performed. + * @param raw The raw XML 1.0 name (with prefix), or the empty string if + * raw names are not available. + */ + public void endElement(String uri, String loc, String raw) + throws SAXException { + } + + /** + * Receive notification of character data. + * + * @param ch The characters from the XML document. + * @param start The start position in the array. + * @param len The number of characters to read from the array. + */ + public void characters(char ch[], int start, int len) + throws SAXException { + } + + /** + * Receive notification of ignorable whitespace in element content. + * + * @param ch The characters from the XML document. + * @param start The start position in the array. + * @param len The number of characters to read from the array. + */ + public void ignorableWhitespace(char ch[], int start, int len) + throws SAXException { + } + + /** + * Receive notification of a processing instruction. + * + * @param target The processing instruction target. + * @param data The processing instruction data, or null if none was + * supplied. + */ + public void processingInstruction(String target, String data) + throws SAXException { + } + + /** + * Receive notification of a skipped entity. + * + * @param name The name of the skipped entity. If it is a parameter + * entity, the name will begin with '%'. + */ + public void skippedEntity(String name) + throws SAXException { + } + + /** + * Report the start of DTD declarations, if any. + * + * @param name The document type name. + * @param publicId The declared public identifier for the external DTD + * subset, or null if none was declared. + * @param systemId The declared system identifier for the external DTD + * subset, or null if none was declared. + */ + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + } + + /** + * Report the end of DTD declarations. + */ + public void endDTD() + throws SAXException { + } + + /** + * Report the beginning of an entity. + * + * @param name The name of the entity. If it is a parameter entity, the + * name will begin with '%'. + */ + public void startEntity(String name) + throws SAXException { + } + + /** + * Report the end of an entity. + * + * @param name The name of the entity that is ending. + */ + public void endEntity(String name) + throws SAXException { + } + + /** + * Report the start of a CDATA section. + */ + public void startCDATA() + throws SAXException { + } + + /** + * Report the end of a CDATA section. + */ + public void endCDATA() + throws SAXException { + } + + + /** + * Report an XML comment anywhere in the document. + * + * @param ch An array holding the characters in the comment. + * @param start The starting position in the array. + * @param len The number of characters to use from the array. + */ + public void comment(char ch[], int start, int len) + throws SAXException { + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLConsumer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLPipe.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLPipe.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLPipe.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLPipe.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,231 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; + +/** + * This class provides a bridge class to connect to existing content + * handlers and lexical handlers. + * + * @author Stefano Mazzocchi + * @version CVS $Id: AbstractXMLPipe.java 233343 2005-08-18 18:06:44Z sylvain $ + */ +public abstract class AbstractXMLPipe extends AbstractXMLProducer + implements XMLPipe { + + /** + * Receive an object for locating the origin of SAX document events. + * + * @param locator An object that can return the location of any SAX + * document event. + */ + public void setDocumentLocator(Locator locator) { + contentHandler.setDocumentLocator(locator); + } + + /** + * Receive notification of the beginning of a document. + */ + public void startDocument() + throws SAXException { + contentHandler.startDocument(); + } + + /** + * Receive notification of the end of a document. + */ + public void endDocument() + throws SAXException { + contentHandler.endDocument(); + } + + /** + * Begin the scope of a prefix-URI Namespace mapping. + * + * @param prefix The Namespace prefix being declared. + * @param uri The Namespace URI the prefix is mapped to. + */ + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + contentHandler.startPrefixMapping(prefix, uri); + } + + /** + * End the scope of a prefix-URI mapping. + * + * @param prefix The prefix that was being mapping. + */ + public void endPrefixMapping(String prefix) + throws SAXException { + contentHandler.endPrefixMapping(prefix); + } + + /** + * Receive notification of the beginning of an element. + * + * @param uri The Namespace URI, or the empty string if the element has no + * Namespace URI or if Namespace + * processing is not being performed. + * @param loc The local name (without prefix), or the empty string if + * Namespace processing is not being performed. + * @param raw The raw XML 1.0 name (with prefix), or the empty string if + * raw names are not available. + * @param a The attributes attached to the element. If there are no + * attributes, it shall be an empty Attributes object. + */ + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + contentHandler.startElement(uri, loc, raw, a); + } + + + /** + * Receive notification of the end of an element. + * + * @param uri The Namespace URI, or the empty string if the element has no + * Namespace URI or if Namespace + * processing is not being performed. + * @param loc The local name (without prefix), or the empty string if + * Namespace processing is not being performed. + * @param raw The raw XML 1.0 name (with prefix), or the empty string if + * raw names are not available. + */ + public void endElement(String uri, String loc, String raw) + throws SAXException { + contentHandler.endElement(uri, loc, raw); + } + + /** + * Receive notification of character data. + * + * @param c The characters from the XML document. + * @param start The start position in the array. + * @param len The number of characters to read from the array. + */ + public void characters(char c[], int start, int len) + throws SAXException { + contentHandler.characters(c, start, len); + } + + /** + * Receive notification of ignorable whitespace in element content. + * + * @param c The characters from the XML document. + * @param start The start position in the array. + * @param len The number of characters to read from the array. + */ + public void ignorableWhitespace(char c[], int start, int len) + throws SAXException { + contentHandler.ignorableWhitespace(c, start, len); + } + + /** + * Receive notification of a processing instruction. + * + * @param target The processing instruction target. + * @param data The processing instruction data, or null if none was + * supplied. + */ + public void processingInstruction(String target, String data) + throws SAXException { + contentHandler.processingInstruction(target, data); + } + + /** + * Receive notification of a skipped entity. + * + * @param name The name of the skipped entity. If it is a parameter + * entity, the name will begin with '%'. + */ + public void skippedEntity(String name) + throws SAXException { + contentHandler.skippedEntity(name); + } + + /** + * Report the start of DTD declarations, if any. + * + * @param name The document type name. + * @param publicId The declared public identifier for the external DTD + * subset, or null if none was declared. + * @param systemId The declared system identifier for the external DTD + * subset, or null if none was declared. + */ + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + lexicalHandler.startDTD(name, publicId, systemId); + } + + /** + * Report the end of DTD declarations. + */ + public void endDTD() + throws SAXException { + lexicalHandler.endDTD(); + } + + /** + * Report the beginning of an entity. + * + * @param name The name of the entity. If it is a parameter entity, the + * name will begin with '%'. + */ + public void startEntity(String name) + throws SAXException { + lexicalHandler.startEntity(name); + } + + /** + * Report the end of an entity. + * + * @param name The name of the entity that is ending. + */ + public void endEntity(String name) + throws SAXException { + lexicalHandler.endEntity(name); + } + + /** + * Report the start of a CDATA section. + */ + public void startCDATA() + throws SAXException { + lexicalHandler.startCDATA(); + } + + /** + * Report the end of a CDATA section. + */ + public void endCDATA() + throws SAXException { + lexicalHandler.endCDATA(); + } + + /** + * Report an XML comment anywhere in the document. + * + * @param ch An array holding the characters in the comment. + * @param start The starting position in the array. + * @param len The number of characters to use from the array. + */ + public void comment(char ch[], int start, int len) + throws SAXException { + lexicalHandler.comment(ch, start, len); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLPipe.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLProducer.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLProducer.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLProducer.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLProducer.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,87 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.avalon.excalibur.pool.Recyclable; +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.xml.sax.ContentHandler; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.DefaultHandler; + +/** + * This abstract class provides default implementation of the methods specified + * by the XMLProducer interface. + * + * @author Pierpaolo Fumagalli + * (Apache Software Foundation) + * @version CVS $Id: AbstractXMLProducer.java 225810 2005-07-28 16:11:03Z sylvain $ + */ +public abstract class AbstractXMLProducer extends AbstractLogEnabled + implements XMLProducer, Recyclable { + + protected static final ContentHandler EMPTY_CONTENT_HANDLER = new DefaultHandler(); + + /** The XMLConsumer receiving SAX events. */ + protected XMLConsumer xmlConsumer; + + /** The ContentHandler receiving SAX events. */ + protected ContentHandler contentHandler = EMPTY_CONTENT_HANDLER; + + /** The LexicalHandler receiving SAX events. */ + protected LexicalHandler lexicalHandler = DefaultLexicalHandler.NULL_HANDLER; + + /** + * Set the XMLConsumer that will receive XML data. + *
+ * This method will simply call setContentHandler(consumer) + * and setLexicalHandler(consumer). + */ + public void setConsumer(XMLConsumer consumer) { + this.xmlConsumer = consumer; + setContentHandler(consumer); + setLexicalHandler(consumer); + } + + /** + * Set the ContentHandler that will receive XML data. + *
+ * Subclasses may retrieve this ContentHandler instance + * accessing the protected super.contentHandler field. + */ + public void setContentHandler(ContentHandler handler) { + this.contentHandler = handler; + } + + /** + * Set the LexicalHandler that will receive XML data. + *
+ * Subclasses may retrieve this LexicalHandler instance + * accessing the protected super.lexicalHandler field. + */ + public void setLexicalHandler(LexicalHandler handler) { + this.lexicalHandler = handler; + } + + /** + * Recycle the producer by removing references, and resetting handlers to + * null (empty) implementations. + */ + public void recycle() { + this.xmlConsumer = null; + this.contentHandler = EMPTY_CONTENT_HANDLER; + this.lexicalHandler = DefaultLexicalHandler.NULL_HANDLER; + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AbstractXMLProducer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributeTypes.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributeTypes.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributeTypes.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributeTypes.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +/** + * Insert the type's description here. + * + * @author Volker Schmitt + * @version CVS $Id: AttributeTypes.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public interface AttributeTypes +{ + String CDATA = "CDATA"; + String ENTITY = "ENTITY"; + String ENTITIES = "ENTITIES"; + String ID = "ID"; + String IDREF = "IDREF"; + String IDREFS = "IDREFS"; + String NAME = "NAME"; + String NAMES = "NAMES"; + String NMTOKEN = "NMTOKEN"; + String NMTOKENS = "NMTOKENS"; + String NOTATION = "NOTATION"; + String NUMBER = "NUMBER"; + String NUMBERS = "NUMBERS"; + String NUTOKEN = "NUTOKEN"; + String NUTOKENS = "NUTOKENS"; +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributeTypes.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributesImpl.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributesImpl.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributesImpl.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributesImpl.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,114 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.xml.sax.Attributes; + +/** + * A helper Class creating SAX Attributes + * + * @author Volker Schmitt + * @version CVS $Id: AttributesImpl.java 230421 2005-08-05 09:29:42Z cziegeler $ + */ +public class AttributesImpl extends org.xml.sax.helpers.AttributesImpl { + + /** + * Constructor + */ + public AttributesImpl() { + super(); + } + + /** + * Constructor + */ + public AttributesImpl(Attributes attr) { + super(attr); + } + + /** + * Add an attribute of type CDATA with empty Namespace to the end of the list. + * + *

For the sake of speed, this method does no checking + * to see if the attribute is already in the list: that is + * the responsibility of the application.

+ * + * @param localName The local name. + * @param value The attribute value. + */ + public void addCDATAAttribute(String localName, String value) { + addAttribute("", localName, localName, AttributeTypes.CDATA, value); + } + + /** + * Add an attribute of type CDATA with the namespace to the end of the list. + * + *

For the sake of speed, this method does no checking + * to see if the attribute is already in the list: that is + * the responsibility of the application.

+ * + * @param namespace The namespace. + * @param localName The local name. + * @param value The attribute value. + */ + public void addCDATAAttribute(String namespace, String localName, String value) { + addAttribute(namespace, localName, localName, AttributeTypes.CDATA, value); + } + + /** + * Add an attribute of type CDATA to the end of the list. + * + *

For the sake of speed, this method does no checking + * to see if the attribute is already in the list: that is + * the responsibility of the application.

+ * + * @param uri The Namespace URI, or the empty string if + * none is available or Namespace processing is not + * being performed. + * @param localName The local name, or the empty string if + * Namespace processing is not being performed. + * @param qName The qualified (prefixed) name, or the empty string + * if qualified names are not available. + * @param value The attribute value. + */ + public void addCDATAAttribute(String uri, + String localName, + String qName, + String value) { + addAttribute(uri, localName, qName, AttributeTypes.CDATA, value); + } + + /** + * Remove an attribute + */ + public void removeAttribute(String localName) { + final int index = this.getIndex(localName); + if ( index != -1 ) { + this.removeAttribute(index); + } + } + + /** + * Remove an attribute + */ + public void removeAttribute(String uri, String localName) { + final int index = this.getIndex(uri, localName); + if ( index != -1 ) { + this.removeAttribute(index); + } + } +} + \ No newline at end of file Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/AttributesImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ContentHandlerWrapper.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ContentHandlerWrapper.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ContentHandlerWrapper.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ContentHandlerWrapper.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,272 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.avalon.excalibur.pool.Recyclable; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; + +/** + * This class is an utility class "wrapping" around a SAX version 2.0 + * ContentHandler and forwarding it those events received throug + * its XMLConsumers interface. + *
+ * + * @author Davanum Srinivas + * (Apache Software Foundation, Computer Associates) + * @version CVS $Id: ContentHandlerWrapper.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public class ContentHandlerWrapper extends AbstractXMLConsumer implements Recyclable { + + /** The current ContentHandler. */ + protected ContentHandler contentHandler; + + /** The optional LexicalHandler */ + protected LexicalHandler lexicalHandler; + + /** + * Create a new ContentHandlerWrapper instance. + */ + public ContentHandlerWrapper() { + super(); + } + + /** + * Create a new ContentHandlerWrapper instance. + */ + public ContentHandlerWrapper(ContentHandler contentHandler) { + this(); + this.setContentHandler(contentHandler); + } + + /** + * Create a new ContentHandlerWrapper instance. + */ + public ContentHandlerWrapper(ContentHandler contentHandler, + LexicalHandler lexicalHandler) { + this(); + this.setContentHandler(contentHandler); + this.setLexicalHandler(lexicalHandler); + } + + /** + * Set the ContentHandler that will receive XML data. + * + * @exception IllegalStateException If the ContentHandler + * was already set. + */ + public void setContentHandler(ContentHandler contentHandler) + throws IllegalStateException { + if (this.contentHandler!=null) throw new IllegalStateException(); + this.contentHandler=contentHandler; + } + + /** + * Set the LexicalHandler that will receive XML data. + * + * @exception IllegalStateException If the LexicalHandler + * was already set. + */ + public void setLexicalHandler(LexicalHandler lexicalHandler) + throws IllegalStateException { + if (this.lexicalHandler!=null) throw new IllegalStateException(); + this.lexicalHandler=lexicalHandler; + } + + public void recycle () { + this.contentHandler = null; + this.lexicalHandler = null; + } + + /** + * Receive an object for locating the origin of SAX document events. + */ + public void setDocumentLocator (Locator locator) { + if (this.contentHandler==null) return; + else this.contentHandler.setDocumentLocator(locator); + } + + /** + * Receive notification of the beginning of a document. + */ + public void startDocument () + throws SAXException { + if (this.contentHandler==null) + throw new SAXException("ContentHandler not set"); + this.contentHandler.startDocument(); + } + + /** + * Receive notification of the end of a document. + */ + public void endDocument () + throws SAXException { + this.contentHandler.endDocument(); + } + + /** + * Begin the scope of a prefix-URI Namespace mapping. + */ + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + if (this.contentHandler==null) + throw new SAXException("ContentHandler not set"); + this.contentHandler.startPrefixMapping(prefix, uri); + } + + /** + * End the scope of a prefix-URI mapping. + */ + public void endPrefixMapping(String prefix) + throws SAXException { + this.contentHandler.endPrefixMapping(prefix); + } + + /** + * Receive notification of the beginning of an element. + */ + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + this.contentHandler.startElement(uri, loc, raw, a); + } + + + /** + * Receive notification of the end of an element. + */ + public void endElement(String uri, String loc, String raw) + throws SAXException { + this.contentHandler.endElement(uri, loc, raw); + } + + /** + * Receive notification of character data. + */ + public void characters(char ch[], int start, int len) + throws SAXException { + this.contentHandler.characters(ch,start,len); + } + + /** + * Receive notification of ignorable whitespace in element content. + */ + public void ignorableWhitespace(char ch[], int start, int len) + throws SAXException { + this.contentHandler.ignorableWhitespace(ch,start,len); + } + + /** + * Receive notification of a processing instruction. + */ + public void processingInstruction(String target, String data) + throws SAXException { + this.contentHandler.processingInstruction(target,data); + } + + /** + * Receive notification of a skipped entity. + * + * @param name The name of the skipped entity. If it is a parameter + * entity, the name will begin with '%'. + */ + public void skippedEntity(String name) + throws SAXException { + this.contentHandler.skippedEntity(name); + } + + /** + * Report the start of DTD declarations, if any. + * + * @param name The document type name. + * @param publicId The declared public identifier for the external DTD + * subset, or null if none was declared. + * @param systemId The declared system identifier for the external DTD + * subset, or null if none was declared. + */ + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.startDTD(name, publicId, systemId); + } + + /** + * Report the end of DTD declarations. + */ + public void endDTD() + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.endDTD(); + } + + /** + * Report the beginning of an entity. + * + * @param name The name of the entity. If it is a parameter entity, the + * name will begin with '%'. + */ + public void startEntity(String name) + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.startEntity(name); + } + + /** + * Report the end of an entity. + * + * @param name The name of the entity that is ending. + */ + public void endEntity(String name) + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.endEntity(name); + } + + /** + * Report the start of a CDATA section. + */ + public void startCDATA() + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.startCDATA(); + } + + /** + * Report the end of a CDATA section. + */ + public void endCDATA() + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.endCDATA(); + } + + + /** + * Report an XML comment anywhere in the document. + * + * @param ch An array holding the characters in the comment. + * @param start The starting position in the array. + * @param len The number of characters to use from the array. + */ + public void comment(char ch[], int start, int len) + throws SAXException { + if (this.lexicalHandler != null) + this.lexicalHandler.comment(ch, start, len); + } + +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ContentHandlerWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DefaultLexicalHandler.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DefaultLexicalHandler.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DefaultLexicalHandler.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DefaultLexicalHandler.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,61 @@ +/* + * Copyright 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; + +/** + * Default implementation of SAX's LexicalHandler interface. Empty implementation + * of all methods so that you only have to redefine the ones of interest. + * + * @version $Id: DefaultLexicalHandler.java 225806 2005-07-28 16:01:18Z sylvain $ + */ +public class DefaultLexicalHandler implements LexicalHandler { + + /** + * Shared instance that can be used when lexical events should be ignored. + */ + public static final LexicalHandler NULL_HANDLER = new DefaultLexicalHandler(); + + public void startDTD(String name, String publicId, String systemId) throws SAXException { + // nothing + } + + public void endDTD() throws SAXException { + // nothing + } + + public void startEntity(String name) throws SAXException { + // nothing + } + + public void endEntity(String name) throws SAXException { + // nothing + } + + public void startCDATA() throws SAXException { + // nothing + } + + public void endCDATA() throws SAXException { + // nothing + } + + public void comment(char[] ch, int start, int length) throws SAXException { + // nothing + } +} \ No newline at end of file Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DefaultLexicalHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DocumentHandlerAdapter.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DocumentHandlerAdapter.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DocumentHandlerAdapter.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/DocumentHandlerAdapter.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,203 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +import org.xml.sax.AttributeList; +import org.xml.sax.ContentHandler; +import org.xml.sax.DocumentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * This class is an utility class "adapting" a SAX version 1.0 + * DocumentHandler, to SAX version 2 ContentHandler. + *
+ * This class fully supports XML namespaces, converting xmlns and + * xmlns:... element attributes into appropriate + * startPrefixMapping(...) and endPrefixMapping(...) + * calls. + * + * @author Pierpaolo Fumagalli + * (Apache Software Foundation) + * @version CVS $Id: DocumentHandlerAdapter.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public class DocumentHandlerAdapter extends AbstractXMLProducer +implements DocumentHandler { + + /** The element-oriented namespace-uri stacked mapping table. */ + private Hashtable stackedNS=new Hashtable(); + /** The current namespaces table. */ + private NamespacesTable namespaces=new NamespacesTable(); + /** The current stack depth.*/ + private int stack=0; + + /** + * Create a new DocumentHandlerAdapter instance. + */ + public DocumentHandlerAdapter() { + super(); + } + + /** + * Create a new DocumentHandlerAdapter instance. + */ + public DocumentHandlerAdapter(XMLConsumer consumer) { + this(); + super.setConsumer(consumer); + } + + /** + * Create a new DocumentHandlerAdapter instance. + */ + public DocumentHandlerAdapter(ContentHandler content) { + this(); + super.setContentHandler(content); + } + + /** + * Receive an object for locating the origin of SAX document events. + */ + public void setDocumentLocator (Locator locator) { + if (super.contentHandler==null) return; + else super.contentHandler.setDocumentLocator(locator); + } + + /** + * Receive notification of the beginning of a document. + */ + public void startDocument () + throws SAXException { + if (super.contentHandler==null) + throw new SAXException("ContentHandler not set"); + super.contentHandler.startDocument(); + } + + /** + * Receive notification of the end of a document. + */ + public void endDocument () + throws SAXException { + if (super.contentHandler==null) + throw new SAXException("ContentHandler not set"); + super.contentHandler.endDocument(); + } + + /** + * Receive notification of the beginning of an element. + */ + public void startElement (String name, AttributeList a) + throws SAXException { + if (super.contentHandler==null) + throw new SAXException("ContentHandler not set"); + // Check for namespace declarations (two loops because we're not sure + // about attribute ordering. + AttributesImpl a2=new AttributesImpl(); + Vector nslist=new Vector(); + for (int x=0; x5) pre=att.substring(6); + this.namespaces.addDeclaration(pre,uri); + nslist.addElement(pre); + super.contentHandler.startPrefixMapping(pre,uri); + } + } + if (nslist.size()>0) this.stackedNS.put(new Integer(this.stack),nslist); + // Resolve the element namespaced name + NamespacesTable.Name w=this.namespaces.resolve(null,name,null,null); + // Second loop through attributes to fill AttributesImpl + for (int x=0; xDocumentHandler and forwarding it those events received throug + * its XMLConsumers interface. + *
+ * This class fully supports XML namespaces, converting + * startPrefixMapping(...) and endPrefixMapping(...) + * calls into appropriate xmlns and xmlns:... element + * attributes. + * + * @author Pierpaolo Fumagalli + * (Apache Software Foundation) + * @version CVS $Id: DocumentHandlerWrapper.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public class DocumentHandlerWrapper extends AbstractXMLConsumer implements LogEnabled /*, Recyclable*/ { + + protected Logger log; + + /** The current namespaces table. */ + private NamespacesTable namespaces=new NamespacesTable(); + /** The vector of namespaces declarations to include in the next element. */ + private Vector undecl=new Vector(); + + /** The current DocumentHandler. */ + protected DocumentHandler documentHandler=null; + + /** + * Create a new DocumentHandlerWrapper instance. + */ + public DocumentHandlerWrapper() { + super(); + } + + /** + * Create a new DocumentHandlerWrapper instance. + */ + public DocumentHandlerWrapper(DocumentHandler document) { + this(); + this.setDocumentHandler(document); + } + + /** + * Provide component with a logger. + * + * @param logger the logger + */ + public void enableLogging(Logger logger) { + if (this.log == null) { + this.log = logger; + } + } + + /** + * Implementation of the recycle method + */ + public void recycle() { + this.documentHandler = null; + } + + /** + * Set the DocumentHandler that will receive XML data. + * + * @exception IllegalStateException If the DocumentHandler + * was already set. + */ + public void setDocumentHandler(DocumentHandler document) + throws IllegalStateException { + if (this.documentHandler!=null) throw new IllegalStateException(); + this.documentHandler=document; + } + + /** + * Receive an object for locating the origin of SAX document events. + */ + public void setDocumentLocator (Locator locator) { + if (this.documentHandler==null) return; + else this.documentHandler.setDocumentLocator(locator); + } + + /** + * Receive notification of the beginning of a document. + */ + public void startDocument () + throws SAXException { + if (this.documentHandler==null) + throw new SAXException("DocumentHandler not set"); + this.documentHandler.startDocument(); + } + + /** + * Receive notification of the end of a document. + */ + public void endDocument () + throws SAXException { + if (this.documentHandler==null) + throw new SAXException("DocumentHandler not set"); + this.documentHandler.endDocument(); + } + + /** + * Begin the scope of a prefix-URI Namespace mapping. + */ + public void startPrefixMapping(String prefix, String uri) + throws SAXException { + this.undecl.addElement(this.namespaces.addDeclaration(prefix,uri)); + } + + /** + * End the scope of a prefix-URI mapping. + */ + public void endPrefixMapping(String prefix) + throws SAXException { + if (namespaces.removeDeclaration(prefix)==null) + throw new SAXException("Namespace prefix \""+prefix+ + "\" never declared"); + } + + /** + * Receive notification of the beginning of an element. + */ + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + if (this.documentHandler==null) + throw new SAXException("DocumentHandler not set"); + NamespacesTable.Name name=this.namespaces.resolve(uri,raw,null,loc); + // Create the AttributeList + AttributeListImpl a2=new AttributeListImpl(); + // Set the xmlns:...="..." attributes + if (this.undecl.size()>0) { + for (int x=0; x0) aname="xmlns:"+dec.getPrefix(); + a2.addAttribute(aname,"CDATA",dec.getUri()); + } + this.undecl.clear(); + } + // Set the real attributes + for (int x=0; xOvidiu Predescu + * @version CVS $Id: EmbeddedXMLPipe.java 53971 2004-10-07 14:03:55Z vgritsenko $ + */ +public class EmbeddedXMLPipe extends AbstractXMLPipe { + + private boolean inDTD; + + /** + * Creates an EmbeddedXMLPipe that writes into the given XMLConsumer. + */ + public EmbeddedXMLPipe(XMLConsumer consumer) { + setConsumer(consumer); + } + + /** + * Creates an EmbeddedXMLPipe that writes into the given ContentHandler. + */ + public EmbeddedXMLPipe(ContentHandler handler) { + setContentHandler(handler); + if (handler instanceof LexicalHandler) { + setLexicalHandler((LexicalHandler) handler); + } + } + + /** + * Creates an EmbeddedXMLPipe that writes into the given ContentHandler. + */ + public EmbeddedXMLPipe(ContentHandler contentHandler, LexicalHandler lexicalHandler) { + setContentHandler(contentHandler); + setLexicalHandler(lexicalHandler); + } + + /** + * Ignore the startDocument event: this method does nothing. + * + * @exception SAXException if an error occurs + */ + public void startDocument() throws SAXException { + } + + /** + * Ignore the endDocument event: this method does nothing. + * + * @exception SAXException if an error occurs + */ + public void endDocument() throws SAXException { + } + + /** + * Ignore the startDTD event: this method does nothing. + * + * @exception SAXException if an error occurs + */ + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + // Ignored + this.inDTD = true; + } + + /** + * Ignore the endDTD event: this method does nothing. + * + * @exception SAXException if an error occurs + */ + public void endDTD() throws SAXException { + // Ignored + this.inDTD = false; + } + + /** + * Ignore all comment events if between + * startDTD/endDTD events. + * + * @exception SAXException if an error occurs + */ + public void comment(char ch[], int start, int len) + throws SAXException { + if (!inDTD) { + super.comment(ch, start, len); + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/EmbeddedXMLPipe.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ImmutableAttributesImpl.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ImmutableAttributesImpl.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ImmutableAttributesImpl.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ImmutableAttributesImpl.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,74 @@ +/* + * Copyright 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.xml.sax.Attributes; + +/** + * Immutable attributes + * + * @version $Id: ImmutableAttributesImpl.java 164043 2005-04-21 12:11:55Z vgritsenko $ + */ +public class ImmutableAttributesImpl extends AttributesImpl { + + public ImmutableAttributesImpl() { + super(); + } + + public ImmutableAttributesImpl(Attributes attrs) { + super(attrs); + } + + public void clear() { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void removeAttribute(int index) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setLocalName(int index, String localName) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setQName(int index, String qName) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setType(int index, String type) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setURI(int index, String uri) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setValue(int index, String value) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setAttributes(Attributes atts) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { + throw new UnsupportedOperationException("immutable attributes"); + } + + public void addAttribute(String uri, String localName, String qName, String type, String value) { + throw new UnsupportedOperationException("immutable attributes"); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/ImmutableAttributesImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/IncludeXMLConsumer.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/IncludeXMLConsumer.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/IncludeXMLConsumer.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/IncludeXMLConsumer.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,248 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXResult; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; +import org.w3c.dom.Node; + +/** + * A special purpose XMLConsumer which can: + *
    + *
  • Trim empty characters if + * {@link #setIgnoreEmptyCharacters(boolean) ignoreEmptyCharacters} is set. + *
  • Ignore root element if + * {@link #setIgnoreRootElement(boolean) ignoreRootElement} is set. + *
  • Ignore startDocument, endDocument events. + *
  • Ignore startDTD, endDTD, and all comments within DTD. + *
+ * + *

It is more complicated version of {@link EmbeddedXMLPipe} which, except + * being used to include other files into the SAX events stream, can perform + * optional operations described above.

+ * + * @see EmbeddedXMLPipe + * @author Berin Loritsch + * @author Carsten Ziegeler + * @version CVS $Id: IncludeXMLConsumer.java 326891 2005-10-20 11:33:28Z cziegeler $ + */ +public class IncludeXMLConsumer implements XMLConsumer { + + /** The TrAX factory for serializing xml */ + private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); + + private final ContentHandler contentHandler; + private final LexicalHandler lexicalHandler; + + private boolean ignoreEmptyCharacters; + private boolean ignoreRootElement; + private int ignoreRootElementCount; + private boolean inDTD; + + /** + * Constructor + */ + public IncludeXMLConsumer (XMLConsumer consumer) { + this.contentHandler = consumer; + this.lexicalHandler = consumer; + } + + /** + * Constructor + */ + public IncludeXMLConsumer (ContentHandler contentHandler, LexicalHandler lexicalHandler) { + this.contentHandler = contentHandler; + this.lexicalHandler = lexicalHandler; + } + + /** + * Constructor + */ + public IncludeXMLConsumer (ContentHandler contentHandler) { + this.contentHandler = contentHandler; + this.lexicalHandler = contentHandler instanceof LexicalHandler ? (LexicalHandler)contentHandler : null; + } + + /** + * Utility method to stream a DOM node into the provided content handler, + * lexical handler. + * + * @param node The DOM Node to be included + * @param contentHandler The SAX ContentHandler receiving the information + * @param lexicalHandler The SAX LexicalHandler receiving the information (optional) + */ + public static void includeNode(Node node, + ContentHandler contentHandler, + LexicalHandler lexicalHandler) + throws SAXException { + if (node != null) { + if (node.getNodeType() == Node.TEXT_NODE){ + String value = node.getNodeValue(); + contentHandler.characters(value.toCharArray(), 0, value.length()); + } else { + try { + IncludeXMLConsumer filter = new IncludeXMLConsumer(contentHandler, lexicalHandler); + Transformer transformer = FACTORY.newTransformer(); + DOMSource source = new DOMSource(node); + SAXResult result = new SAXResult(filter); + result.setLexicalHandler(filter); + transformer.transform(source, result); + } catch (TransformerConfigurationException e) { + throw new SAXException("TransformerConfigurationException", e); + } catch (TransformerException e) { + throw new SAXException("TransformerException", e); + } + } + } + } + + /** + * Control SAX event handling. + * If set to true all empty characters events are ignored. + * The default is false. + */ + public void setIgnoreEmptyCharacters(boolean value) { + this.ignoreEmptyCharacters = value; + } + + /** + * Control SAX event handling. + * If set to true the root element is ignored. + * The default is false. + */ + public void setIgnoreRootElement(boolean value) { + this.ignoreRootElement = value; + this.ignoreRootElementCount = 0; + } + + // + // ContentHandler interface + // + + public void setDocumentLocator(Locator loc) { + this.contentHandler.setDocumentLocator(loc); + } + + public void startDocument() throws SAXException { + // Ignored + } + + public void endDocument() throws SAXException { + // Ignored + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + this.contentHandler.startPrefixMapping(prefix, uri); + } + + public void endPrefixMapping(String prefix) throws SAXException { + this.contentHandler.endPrefixMapping(prefix); + } + + public void startElement(String uri, String local, String qName, Attributes attr) throws SAXException { + if (this.ignoreRootElement == false || + this.ignoreRootElementCount > 0) { + this.contentHandler.startElement(uri,local,qName,attr); + } + this.ignoreRootElementCount++; + } + + public void endElement(String uri, String local, String qName) throws SAXException { + this.ignoreRootElementCount--; + if (!this.ignoreRootElement || this.ignoreRootElementCount > 0) { + this.contentHandler.endElement(uri, local, qName); + } + } + + public void characters(char[] ch, int start, int end) throws SAXException { + if (this.ignoreEmptyCharacters) { + String text = new String(ch, start, end).trim(); + if (text.length() > 0) { + this.contentHandler.characters(text.toCharArray(), 0, text.length()); + } + } else { + this.contentHandler.characters(ch, start, end); + } + } + + public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException { + if (!this.ignoreEmptyCharacters) { + this.contentHandler.ignorableWhitespace(ch, start, end); + } + } + + public void processingInstruction(String name, String value) throws SAXException { + this.contentHandler.processingInstruction(name, value); + } + + public void skippedEntity(String ent) throws SAXException { + this.contentHandler.skippedEntity(ent); + } + + // + // LexicalHandler interface + // + + public void startDTD(String name, String public_id, String system_id) + throws SAXException { + // Ignored + this.inDTD = true; + } + + public void endDTD() throws SAXException { + // Ignored + this.inDTD = false; + } + + public void startEntity(String name) throws SAXException { + if (lexicalHandler != null) { + lexicalHandler.startEntity(name); + } + } + + public void endEntity(String name) throws SAXException { + if (lexicalHandler != null) { + lexicalHandler.endEntity(name); + } + } + + public void startCDATA() throws SAXException { + if (lexicalHandler != null) { + lexicalHandler.startCDATA(); + } + } + + public void endCDATA() throws SAXException { + if (lexicalHandler != null) { + lexicalHandler.endCDATA(); + } + } + + public void comment(char ary[], int start, int length) throws SAXException { + if (!inDTD && lexicalHandler != null) { + lexicalHandler.comment(ary,start,length); + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/IncludeXMLConsumer.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/LoggingContentHandler.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/LoggingContentHandler.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/LoggingContentHandler.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/LoggingContentHandler.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,125 @@ +/* + * Copyright 1999-2004 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.xml; + +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.ContentHandler; + +/** + * Logging content handler logs all events going through to the logger. + * + * @author Vadim Gritsenko + * @version CVS $Id: LoggingContentHandler.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public class LoggingContentHandler extends AbstractLogEnabled implements ContentHandler { + + /** + * All debug messages from this handler are prefixed with this id. + */ + String id; + + /** The current ContentHandler. */ + ContentHandler contentHandler; + + /** + * Creates new LoggingContentHandler with specified + * id and destination contentHandler. + */ + public LoggingContentHandler(String id, ContentHandler contentHandler) { + this.id = id; + this.contentHandler = contentHandler; + } + + public void setDocumentLocator(Locator locator) { + log("setDocumentLocator", ""); + contentHandler.setDocumentLocator(locator); + } + + public void startDocument() throws SAXException { + log("startDocument", ""); + this.contentHandler.startDocument(); + } + + public void endDocument() throws SAXException { + log ("endDocument", ""); + this.contentHandler.endDocument(); + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + log ("startPrefixMapping", "prefix="+prefix+",uri="+uri); + this.contentHandler.startPrefixMapping(prefix,uri); + } + + public void endPrefixMapping(String prefix) throws SAXException { + log ("endPrefixMapping", "prefix="+prefix); + this.contentHandler.endPrefixMapping(prefix); + } + + public void startElement(String uri, String loc, String raw, Attributes a) + throws SAXException { + log ("startElement", "uri="+uri+",local="+loc+",raw="+raw); + for (int i = 0; i < a.getLength(); i++) { + log (" ", Integer.toString(i + 1) + + ". uri=" + a.getURI(i) + + ",local=" + a.getLocalName(i) + + ",qname=" + a.getQName(i) + + ",type=" + a.getType(i) + + ",value=" + a.getValue(i)); + } + this.contentHandler.startElement(uri,loc,raw,a); + } + + + public void endElement(String uri, String loc, String qname) throws SAXException { + log ("endElement", "uri="+uri+",local="+loc+",qname="+qname); + this.contentHandler.endElement(uri,loc,qname); + } + + public void characters(char ch[], int start, int len) throws SAXException { + log ("characters", new String(ch,start,len)); + this.contentHandler.characters(ch,start,len); + } + + public void ignorableWhitespace(char ch[], int start, int len) throws SAXException { + log ("ignorableWhitespace", new String(ch,start,len)); + this.contentHandler.ignorableWhitespace(ch,start,len); + } + + public void processingInstruction(String target, String data) throws SAXException { + log ("processingInstruction", "target="+target+",data="+data); + this.contentHandler.processingInstruction(target,data); + } + + public void skippedEntity(String name) throws SAXException { + log ("skippedEntity", "name="+name); + this.contentHandler.skippedEntity(name); + } + + private void log(String location, String description) { + StringBuffer logEntry = new StringBuffer(); + logEntry.append(id); + logEntry.append("["); + logEntry.append(location); + logEntry.append("] "); + logEntry.append(description); + logEntry.append("\n"); + getLogger().debug(logEntry.toString()); + // System.out.print(logEntry.toString()); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/xml/LoggingContentHandler.java ------------------------------------------------------------------------------ svn:eol-style = native