[richfaces-svn-commits] JBoss Rich Faces SVN: r15795 - in root/cdk/trunk/plugins/xinclude/src: main/java/org/apache/cocoon/pipeline/component/xpointer and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Sun Nov 1 11:32:35 EST 2009


Author: Alex.Kolonitsky
Date: 2009-11-01 11:32:35 -0500 (Sun, 01 Nov 2009)
New Revision: 15795

Modified:
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/ProcessingException.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/SAXConsumer.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java
   root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java
   root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java
Log:
Code style policy
https://jira.jboss.org/jira/browse/RFPL-195

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/ProcessingException.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/ProcessingException.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/ProcessingException.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
+
+
 package org.apache.cocoon.pipeline.component.sax;
 
 import org.xml.sax.SAXException;
@@ -33,39 +35,42 @@
 @SuppressWarnings("serial")
 public class ProcessingException extends SAXException {
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 */
-	public ProcessingException() {
-		// TODO Auto-generated constructor stub
-	}
+    /**
+     * <p class="changed_added_4_0"></p>
+     */
+    public ProcessingException() {
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @param message
-	 */
-	public ProcessingException(String message) {
-		super(message);
-		// TODO Auto-generated constructor stub
-	}
+        // TODO Auto-generated constructor stub
+    }
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @param cause
-	 */
-	public ProcessingException(Exception cause) {
-		super(cause);
-		// TODO Auto-generated constructor stub
-	}
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @param cause
+     */
+    public ProcessingException(Exception cause) {
+        super(cause);
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @param message
-	 * @param cause
-	 */
-	public ProcessingException(String message, Exception cause) {
-		super(message, cause);
-		// TODO Auto-generated constructor stub
-	}
+        // TODO Auto-generated constructor stub
+    }
 
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @param message
+     */
+    public ProcessingException(String message) {
+        super(message);
+
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @param message
+     * @param cause
+     */
+    public ProcessingException(String message, Exception cause) {
+        super(message, cause);
+
+        // TODO Auto-generated constructor stub
+    }
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/SAXConsumer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/SAXConsumer.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/SAXConsumer.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
+
+
 package org.apache.cocoon.pipeline.component.sax;
 
 import org.xml.sax.ContentHandler;
@@ -31,6 +33,4 @@
  * @author asmirnov at exadel.com
  *
  */
-public interface SAXConsumer extends ContentHandler, LexicalHandler {
-
-}
+public interface SAXConsumer extends ContentHandler, LexicalHandler {}

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,190 +1,133 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.sax;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
 import org.apache.cocoon.pipeline.component.xpointer.XPointer;
 import org.apache.cocoon.pipeline.component.xpointer.XPointerContext;
 import org.apache.cocoon.pipeline.component.xpointer.parser.ParseException;
 import org.apache.cocoon.pipeline.component.xpointer.parser.XPointerFrameworkParser;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
+
+import org.xml.sax.*;
 import org.xml.sax.ext.EntityResolver2;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
 import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.XMLReaderFactory;
 
+import java.io.IOException;
 
-public final class XIncludeTransformer
-        implements SAXConsumer {
+import java.net.URI;
 
-    private static final class DummyLexicalHandler implements LexicalHandler {
-		public void startEntity(String name) throws SAXException {
-		}
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
-		public void startDTD(String name, String publicId, String systemId)
-				throws SAXException {
-		}
-
-		public void startCDATA() throws SAXException {
-		}
-
-		public void endEntity(String name) throws SAXException {
-		}
-
-		public void endDTD() throws SAXException {
-		}
-
-		public void endCDATA() throws SAXException {
-		}
-
-		public void comment(char[] ch, int start, int length) throws SAXException {
-			
-		}
-	}
-
-	private static final String XINCLUDE_NAMESPACE_URI = "http://www.w3.org/2001/XInclude";
-
-    private static final String XINCLUDE_INCLUDE = "include";
-
-    private static final String XINCLUDE_FALLBACK = "fallback";
-
-    private static final String XINCLUDE_HREF = "href";
-
-    private static final String XINCLUDE_XPOINTER = "xpointer";
-
-    private static final String XINCLUDE_PARSE = "parse";
-
-    private static final String XINCLUDE_ENCODING = "encoding";
-
+public final class XIncludeTransformer implements SAXConsumer {
     private static final String DEFAULT_CHARSET = "UTF-8";
-
+    private static final String HTTP_ACCEPT = "Accept";
+    private static final String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
+    private static final String UNKNOWN_LOCATION = "unknow location";
     private static final String XINCLUDE_ACCEPT = "accept";
-
     private static final String XINCLUDE_ACCEPT_LANGUAGE = "accept-language";
-
+    private static final String XINCLUDE_ENCODING = "encoding";
+    private static final String XINCLUDE_FALLBACK = "fallback";
+    private static final String XINCLUDE_HREF = "href";
+    private static final String XINCLUDE_INCLUDE = "include";
+    private static final String XINCLUDE_NAMESPACE_URI = "http://www.w3.org/2001/XInclude";
+    private static final String XINCLUDE_PARSE = "parse";
+    private static final String XINCLUDE_PARSE_TEXT = "text";
     private static final String XINCLUDE_PARSE_XML = "xml";
+    private static final String XINCLUDE_XPOINTER = "xpointer";
+    private static final Log LOG = LogFactory.getLog(XIncludeTransformer.class);
 
-    private static final String XINCLUDE_PARSE_TEXT = "text";
+    /** The nesting level of fallback that should be used */
+    private int useFallbackLevel = 0;
 
-    private static final String UNKNOWN_LOCATION = "unknow location";
-
-    private static final String HTTP_ACCEPT = "Accept";
-
-    private static final String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
-
-
-    private static final Log logger = LogFactory.getLog(XIncludeTransformer.class);
     /** The nesting level of xi:include elements that have been encountered. */
     private int xIncludeElementLevel = 0;
 
-    /** The nesting level of fallback that should be used */
-    private int useFallbackLevel = 0;
+    /**
+     * Keep a map of namespaces prefix in the source document to pass it
+     * to the XPointerContext for correct namespace identification.
+     */
+    private final Map<String, String> namespaces = new HashMap<String, String>();
+    private URI baseUri;
+    private ContentHandler contentHandler;
 
     /** The nesting level of xi:fallback elements that have been encountered. */
     private int fallbackElementLevel;
+    private LexicalHandler lexicalHandler;
 
     /**
      * Locator of the current stream, stored here so that it can be restored after
      * another document send its content to the consumer.
      */
     private Locator locator;
+    private EntityResolver2 resolver;
 
-    private URI baseUri;
+    public XIncludeTransformer() {
 
-    /** 
-     * Keep a map of namespaces prefix in the source document to pass it
-     * to the XPointerContext for correct namespace identification. 
-     */
-    private final Map<String, String> namespaces = new HashMap<String, String>();
+        // default empty constructor
+    }
 
-    private ContentHandler contentHandler;
+    public XIncludeTransformer(URI baseUri) {
+        this.setBaseUri(baseUri);
+    }
 
-	private LexicalHandler lexicalHandler;
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @return the resolver
+     */
+    public EntityResolver2 getResolver() {
+        return resolver;
+    }
 
-	private EntityResolver2 resolver;
-	public XIncludeTransformer() {
-	    // default empty constructor
-	}
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @param resolver the resolver to set
+     */
+    public void setResolver(EntityResolver2 resolver) {
+        this.resolver = resolver;
+    }
 
-	public XIncludeTransformer(URI baseUri) {
-	    this.setBaseUri(baseUri);
-	}
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @return the contentHandler
+     */
+    public ContentHandler getContentHandler() {
+        return contentHandler;
+    }
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @return the resolver
-	 */
-	public EntityResolver2 getResolver() {
-		return resolver;
-	}
+    /**
+     * <p class="changed_added_4_0"></p>
+     * @return the lexicalHandler
+     */
+    public LexicalHandler getLexicalHandler() {
+        if (lexicalHandler == null) {
+            lexicalHandler = new DummyLexicalHandler();
+        }
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @param resolver the resolver to set
-	 */
-	public void setResolver(EntityResolver2 resolver) {
-		this.resolver = resolver;
-	}
+        return lexicalHandler;
+    }
 
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @return the contentHandler
-	 */
-	public ContentHandler getContentHandler() {
-		return contentHandler;
-	}
-
-	/**
-	 * <p class="changed_added_4_0"></p>
-	 * @return the lexicalHandler
-	 */
-	public LexicalHandler getLexicalHandler() {
-		if (lexicalHandler == null) {
-			lexicalHandler = new DummyLexicalHandler();
-			
-		}
-
-		return lexicalHandler;
-	}
-
-	public void setBaseUri(URI baseUri) {
+    public void setBaseUri(URI baseUri) {
         this.baseUri = baseUri;
     }
 
@@ -194,10 +137,12 @@
      */
     public void setContentHandler(ContentHandler delegateHandler) {
         this.contentHandler = delegateHandler;
+
         if (delegateHandler instanceof LexicalHandler) {
-			lexicalHandler = (LexicalHandler) delegateHandler;
-		}
-		this.xIncludeElementLevel = 0;
+            lexicalHandler = (LexicalHandler) delegateHandler;
+        }
+
+        this.xIncludeElementLevel = 0;
         this.fallbackElementLevel = 0;
         this.useFallbackLevel = 0;
     }
@@ -211,18 +156,14 @@
      * for an unsuccessful xi:include.
      */
     private boolean isEvaluatingContent() {
-        return xIncludeElementLevel == 0 ||
-            (fallbackElementLevel > 0 && fallbackElementLevel == useFallbackLevel);
+        return xIncludeElementLevel == 0 || (fallbackElementLevel > 0 && fallbackElementLevel == useFallbackLevel);
     }
 
     private String getLocation() {
         if (locator == null) {
             return UNKNOWN_LOCATION;
         } else {
-            return locator.getSystemId()
-                + ":"
-                + locator.getColumnNumber()
-                + ":" + locator.getLineNumber();
+            return locator.getSystemId() + ":" + locator.getColumnNumber() + ":" + locator.getLineNumber();
         }
     }
 
@@ -238,16 +179,17 @@
         }
     }
 
-    public void startElement(String uri, String localName, String name,
-            Attributes atts) throws SAXException {
+    public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
         if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
+
             // Handle xi:include:
             if (XINCLUDE_INCLUDE.equals(localName)) {
+
                 // Process the include, unless in an ignored fallback:
                 if (isEvaluatingContent()) {
                     String href = atts.getValue("", XINCLUDE_HREF);
-
                     String parse = atts.getValue("", XINCLUDE_PARSE);
+
                     // Default for @parse is "xml"
                     if (parse == null) {
                         parse = XINCLUDE_PARSE_XML;
@@ -255,182 +197,191 @@
 
                     String xpointer = atts.getValue("", XINCLUDE_XPOINTER);
                     String encoding = atts.getValue("", XINCLUDE_ENCODING);
-
                     String accept = atts.getValue("", XINCLUDE_ACCEPT);
                     String acceptLanguage = atts.getValue("", XINCLUDE_ACCEPT_LANGUAGE);
 
-                    processXIncludeElement(href, parse, xpointer, encoding,
-                            accept, acceptLanguage);
+                    processXIncludeElement(href, parse, xpointer, encoding, accept, acceptLanguage);
                 }
+
                 xIncludeElementLevel++;
             } else if (XINCLUDE_FALLBACK.equals(localName)) {
+
                 // Handle xi:fallback
                 fallbackElementLevel++;
             } else {
+
                 // Unknown element:
-                throw new SAXException("Unknown XInclude element "
-                        + localName
-                        + " at "
-                        + getLocation());
+                throw new SAXException("Unknown XInclude element " + localName + " at " + getLocation());
             }
         } else if (isEvaluatingContent()) {
+
             // Copy other elements through when appropriate:
             getContentHandler().startElement(uri, localName, name, atts);
         }
     }
 
-    private void processXIncludeElement(String href, String parse,
-            String xpointer, String encoding, String accept,
+    private void processXIncludeElement(String href, String parse, String xpointer, String encoding, String accept,
             String acceptLanguage) throws SAXException {
-        if (logger.isDebugEnabled()) {
-            logger.debug("Processing XInclude element: href="
-                    + href
-                    + ", parse="
-                    + parse
-                    + ", xpointer="
-                    + xpointer
-                    + ", encoding="
-                    + encoding
-                    + ", accept="
-                    + accept
-                    + ", acceptLanguage="
-                    + acceptLanguage);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Processing XInclude element: href=" + href + ", parse=" + parse + ", xpointer=" + xpointer
+                      + ", encoding=" + encoding + ", accept=" + accept + ", acceptLanguage=" + acceptLanguage);
         }
 
         int fragmentIdentifierPos = href.indexOf('#');
+
         if (fragmentIdentifierPos != -1) {
-            logger.warn("Fragment identifer found in 'href' attribute: "
-                    + href + 
-                    "\nFragment identifiers are forbidden by the XInclude specification. "
-                    + "They are still handled by XIncludeTransformer for backward "
-                    + "compatibility, but their use is deprecated and will be prohibited "
-                    + "in a future release.  Use the 'xpointer' attribute instead.");
+            LOG.warn("Fragment identifer found in 'href' attribute: " + href
+                     + "\nFragment identifiers are forbidden by the XInclude specification. "
+                     + "They are still handled by XIncludeTransformer for backward "
+                     + "compatibility, but their use is deprecated and will be prohibited "
+                     + "in a future release.  Use the 'xpointer' attribute instead.");
+
             if (xpointer == null) {
                 xpointer = href.substring(fragmentIdentifierPos + 1);
             }
+
             href = href.substring(0, fragmentIdentifierPos);
         }
 
         // An empty or absent href is a reference to the current document -- this can be different than the current base
         if (href == null || href.length() == 0) {
-            throw new SAXException("XIncludeTransformer: encountered empty href (= href pointing to the current document).");
+            throw new SAXException(
+                "XIncludeTransformer: encountered empty href (= href pointing to the current document).");
         }
+
         InputSource source = createSource(href);
-            if (logger.isDebugEnabled()) {
-                logger.debug("Parse type=" + parse);
-            }
 
-            if (XINCLUDE_PARSE_XML.equals(parse)) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Parse type=" + parse);
+        }
 
-                    try {
-                        if (xpointer != null && xpointer.length() > 0) {
-                        XPointer xPointer = XPointerFrameworkParser.parse(xpointer);
-                        XPointerContext xPointerContext = new XPointerContext(xpointer, source, this, resolver);
-                        for (Entry<String, String> namespace : namespaces.entrySet()) {
-                            xPointerContext.addPrefix(namespace.getKey(), namespace.getValue());
-                        }
-                        xPointer.process(xPointerContext);
-                        } else {
-                            // just parses the document and streams it
-                            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
-                            xmlReader.setContentHandler(this);
-                            xmlReader.setEntityResolver(resolver);
-                            xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
-                            xmlReader.parse(source);
-                        }
-                    } catch (ParseException e) {
-                        // this exception is thrown in case of an invalid xpointer expression
-                        useFallbackLevel++;
-                        logger.error("Error parsing XPointer expression, will try to use fallback.", e);
-                    } catch (IOException e) {
-                        useFallbackLevel++;
-                        logger.error("Error processing an xInclude, will try to use fallback.", e);
-                    } catch (SAXException e) {
-                        useFallbackLevel++;
-                        logger.error("Error processing an xInclude, will try to use fallback.", e);
-					}
-            } else if (XINCLUDE_PARSE_TEXT.equals(parse)) {
-                if (xpointer != null) {
-                    throw new SAXException("xpointer attribute must not be present when parse='text': "
-                            + getLocation());
+        if (XINCLUDE_PARSE_XML.equals(parse)) {
+            try {
+                if (xpointer != null && xpointer.length() > 0) {
+                    XPointer xPointer = XPointerFrameworkParser.parse(xpointer);
+                    XPointerContext xPointerContext = new XPointerContext(xpointer, source, this, resolver);
+
+                    for (Entry<String, String> namespace : namespaces.entrySet()) {
+                        xPointerContext.addPrefix(namespace.getKey(), namespace.getValue());
+                    }
+
+                    xPointer.process(xPointerContext);
+                } else {
+
+                    // just parses the document and streams it
+                    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+
+                    xmlReader.setContentHandler(this);
+                    xmlReader.setEntityResolver(resolver);
+                    xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this);
+                    xmlReader.parse(source);
                 }
-                // TODO - read source as text.
-                if(null != source.getCharacterStream()){
-                	// use reader
-                } else if (null != source.getByteStream()) {
-					// use stream, detect encoding
-				} else if (null != source.getSystemId()) {
-					// get from url.
-				} else {
-					useFallbackLevel++;
-                    logger.error("Can't read XInclude href "
-	                        + href
-	                        + " at "
-	                        + getLocation());
-				}
+            } catch (ParseException e) {
+
+                // this exception is thrown in case of an invalid xpointer expression
+                useFallbackLevel++;
+                LOG.error("Error parsing XPointer expression, will try to use fallback.", e);
+            } catch (IOException e) {
+                useFallbackLevel++;
+                LOG.error("Error processing an xInclude, will try to use fallback.", e);
+            } catch (SAXException e) {
+                useFallbackLevel++;
+                LOG.error("Error processing an xInclude, will try to use fallback.", e);
+            }
+        } else if (XINCLUDE_PARSE_TEXT.equals(parse)) {
+            if (xpointer != null) {
+                throw new SAXException("xpointer attribute must not be present when parse='text': " + getLocation());
+            }
+
+            // TODO - read source as text.
+            if (null != source.getCharacterStream()) {
+
+                // use reader
+            } else if (null != source.getByteStream()) {
+
+                // use stream, detect encoding
+            } else if (null != source.getSystemId()) {
+
+                // get from url.
             } else {
-                throw new SAXException("Found 'parse' attribute with unknown value "
-                        + parse
-                        + " at "
-                        + getLocation());
+                useFallbackLevel++;
+                LOG.error("Can't read XInclude href " + href + " at " + getLocation());
             }
+        } else {
+            throw new SAXException("Found 'parse' attribute with unknown value " + parse + " at " + getLocation());
+        }
     }
 
     private InputSource createSource(String sourceAtt) throws SAXException {
         try {
-    		InputSource source = null;
-    		URI sourceURI = URI.create(sourceAtt);
-    		if(!sourceURI.isAbsolute() && null != this.baseUri){
-    			sourceAtt = this.baseUri.resolve(sourceURI).toString();
-    		}
-        	if(null != resolver){
-				source = resolver.resolveEntity(null, sourceAtt);
-        	}
-            if(null == source){
-            	source = new InputSource(sourceAtt);
+            InputSource source = null;
+            URI sourceURI = URI.create(sourceAtt);
+
+            if (!sourceURI.isAbsolute() && null != this.baseUri) {
+                sourceAtt = this.baseUri.resolve(sourceURI).toString();
             }
-            if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Including source: " + sourceAtt);
+
+            if (null != resolver) {
+                source = resolver.resolveEntity(null, sourceAtt);
             }
+
+            if (null == source) {
+                source = new InputSource(sourceAtt);
+            }
+
+            if (this.LOG.isDebugEnabled()) {
+                this.LOG.debug("Including source: " + sourceAtt);
+            }
+
             return source;
         } catch (IllegalArgumentException e) {
             String message = "Invalid xinclude URI " + sourceAtt;
-            this.logger.error(message, e);
+
+            this.LOG.error(message, e);
+
             throw new ProcessingException(message, e);
-		} catch (IOException e) {
+        } catch (IOException e) {
             String message = "Can't resolve URL " + sourceAtt;
-            this.logger.error(message, e);
+
+            this.LOG.error(message, e);
+
             throw new ProcessingException(message, e);
-		}
+        }
     }
 
-    public void endElement(String uri, String localName, String name)
-            throws SAXException {
+    public void endElement(String uri, String localName, String name) throws SAXException {
+
         // Handle elements in xinclude namespace:
         if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
+
             // Handle xi:include:
             if (XINCLUDE_INCLUDE.equals(localName)) {
                 xIncludeElementLevel--;
+
                 if (useFallbackLevel > xIncludeElementLevel) {
                     useFallbackLevel = xIncludeElementLevel;
                 }
             } else if (XINCLUDE_FALLBACK.equals(localName)) {
+
                 // Handle xi:fallback:
                 fallbackElementLevel--;
             }
         } else if (isEvaluatingContent()) {
+
             // Copy other elements through when appropriate:
             getContentHandler().endElement(uri, localName, name);
         }
     }
 
-    public void startPrefixMapping(String prefix, String uri)
-            throws SAXException {
+    public void startPrefixMapping(String prefix, String uri) throws SAXException {
         if (isEvaluatingContent()) {
+
             // removed xinclude namespace from result document
             if (!uri.equals(XINCLUDE_NAMESPACE_URI)) {
                 getContentHandler().startPrefixMapping(prefix, uri);
             }
+
             namespaces.put(prefix, uri);
         }
     }
@@ -454,12 +405,13 @@
         }
     }
 
-    public void startDTD(String name, String publicId, String systemId)
-            throws SAXException {
+    public void startDTD(String name, String publicId, String systemId) throws SAXException {
+
         // ignoring DTD
     }
 
     public void endDTD() throws SAXException {
+
         // ignoring DTD
     }
 
@@ -475,34 +427,32 @@
         }
     }
 
-    public void characters(char[] ch, int start, int length)
-            throws SAXException {
+    public void characters(char[] ch, int start, int length) throws SAXException {
         if (isEvaluatingContent()) {
             getContentHandler().characters(ch, start, length);
         }
     }
 
-    public void ignorableWhitespace(char[] ch, int start, int length)
-            throws SAXException {
+    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
         if (isEvaluatingContent()) {
             getContentHandler().ignorableWhitespace(ch, start, length);
         }
     }
 
     public void comment(char[] ch, int start, int length) throws SAXException {
+
         // skip comments
     }
 
-    public void processingInstruction(String target, String data)
-            throws SAXException {
+    public void processingInstruction(String target, String data) throws SAXException {
         if (isEvaluatingContent()) {
             getContentHandler().processingInstruction(target, data);
         }
     }
 
     public void setDocumentLocator(Locator locator) {
-        if (logger.isDebugEnabled()) {
-            logger.debug("setDocumentLocator called " + locator.getSystemId());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("setDocumentLocator called " + locator.getSystemId());
         }
 
         this.locator = locator;
@@ -515,4 +465,19 @@
         }
     }
 
+    private static final class DummyLexicalHandler implements LexicalHandler {
+        public void startEntity(String name) throws SAXException {}
+
+        public void startDTD(String name, String publicId, String systemId) throws SAXException {}
+
+        public void startCDATA() throws SAXException {}
+
+        public void endEntity(String name) throws SAXException {}
+
+        public void endDTD() throws SAXException {}
+
+        public void endCDATA() throws SAXException {}
+
+        public void comment(char[] ch, int start, int length) throws SAXException {}
+    }
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,20 +1,21 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
@@ -33,5 +34,4 @@
      * Otherwise this method should return false.
      */
     boolean process(XPointerContext xpointerContext) throws SAXException, IOException;
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,28 +1,31 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
 import java.io.IOException;
 
 import org.apache.cocoon.pipeline.util.dom.DOMUtils;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+
 import org.xml.sax.SAXException;
 
 /**
@@ -33,28 +36,27 @@
  * and a validating parser. Currently, this means its unuseable within Cocoon.
  */
 public final class ShorthandPart implements PointerPart {
-
     private String shorthand;
 
     public ShorthandPart(String shorthand) {
         this.shorthand = shorthand;
     }
 
-    public boolean process(XPointerContext xpointerContext)
-            throws SAXException, IOException {
+    public boolean process(XPointerContext xpointerContext) throws SAXException, IOException {
         Document document = xpointerContext.getDocument();
         Element element = document.getElementById(shorthand);
+
         if (element != null) {
             DOMUtils.stream(element, xpointerContext.getXmlConsumer());
+
             return true;
         } else {
-            if (xpointerContext.getLogger().isDebugEnabled())
-                xpointerContext.getLogger().debug("XPointer: found no element with id "
-                        + shorthand
-                        + " in document "
-                        + xpointerContext.getSource());
+            if (xpointerContext.getLogger().isDebugEnabled()) {
+                xpointerContext.getLogger().debug("XPointer: found no element with id " + shorthand + " in document "
+                                                  + xpointerContext.getSource());
+            }
         }
+
         return false;
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,20 +1,21 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
@@ -22,21 +23,16 @@
 
 import org.xml.sax.SAXException;
 
-
 public final class UnsupportedPart implements PointerPart {
-
     private String schemeName;
 
     public UnsupportedPart(String schemeName) {
         this.schemeName = schemeName;
     }
 
-    public boolean process(XPointerContext xpointerContext)
-            throws SAXException, IOException {
-        throw new SAXException("Scheme "
-                + schemeName
-                + " not supported by this XPointer implementation, as used in the fragment identifier "
-                + xpointerContext.getXPointer());
+    public boolean process(XPointerContext xpointerContext) throws SAXException, IOException {
+        throw new SAXException("Scheme " + schemeName
+                               + " not supported by this XPointer implementation, as used in the fragment identifier "
+                               + xpointerContext.getXPointer());
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,32 +1,32 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
 import java.io.IOException;
+
 import java.util.LinkedList;
 import java.util.List;
 
 import org.xml.sax.SAXException;
 
-
 public final class XPointer {
-
     private final List<PointerPart> pointerParts = new LinkedList<PointerPart>();
 
     public void addPart(PointerPart part) {
@@ -38,5 +38,4 @@
             pointerPart.process(xpointerContext);
         }
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,72 +1,62 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
-import java.io.IOException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.NamespaceContext;
-
 import org.apache.cocoon.pipeline.component.sax.SAXConsumer;
 import org.apache.cocoon.pipeline.component.sax.XIncludeTransformer;
 import org.apache.cocoon.pipeline.util.dom.DOMUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.w3c.dom.Document;
+
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
+import javax.xml.namespace.NamespaceContext;
 
-public final class XPointerContext implements NamespaceContext {
+import java.io.IOException;
 
-    private final static String XML = "xml";
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
-    private final static String XMLNS = "xmlns";
-
-    private final static String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
-
-    private final static String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
-
+public final class XPointerContext implements NamespaceContext {
+    private static final String XML = "xml";
+    private static final String XMLNS = "xmlns";
+    private static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
+    private static final String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+    private static final Log LOGGER = LogFactory.getLog(XIncludeTransformer.class);
     private Map<String, String> prefixes = new HashMap<String, String>();
-
-    private String xPointer;
-
+    private Document document;
+    private final EntityResolver resolver;
     private InputSource source;
-    
-
+    private String xPointer;
     private SAXConsumer xmlConsumer;
 
-    private static final Log logger = LogFactory.getLog(XIncludeTransformer.class);
-
-    private Document document;
-
-	private final EntityResolver resolver;
-
     public XPointerContext(String xPointer, InputSource source, SAXConsumer xmlConsumer, EntityResolver resolver) {
         this.xPointer = xPointer;
         this.source = source;
         this.xmlConsumer = xmlConsumer;
-		this.resolver = resolver;
+        this.resolver = resolver;
     }
 
     public String getXPointer() {
@@ -82,24 +72,23 @@
     }
 
     public Log getLogger() {
-        return logger;
+        return LOGGER;
     }
 
     public Document getDocument() throws IOException, SAXException {
         if (document == null) {
-            document = DOMUtils.toDOM(source,resolver);
+            document = DOMUtils.toDOM(source, resolver);
         }
+
         return document;
     }
 
     public void addPrefix(String prefix, String namespaceURI) {
-        if (prefix.equalsIgnoreCase(XML)
-                || prefix.equals(XMLNS)) {
+        if (prefix.equalsIgnoreCase(XML) || prefix.equals(XMLNS)) {
             return;
         }
 
-        if (namespaceURI.equals(XML_NAMESPACE)
-                || namespaceURI.equals(XMLNS_NAMESPACE)) {
+        if (namespaceURI.equals(XML_NAMESPACE) || namespaceURI.equals(XMLNS_NAMESPACE)) {
             return;
         }
 
@@ -116,9 +105,9 @@
     }
 
     @SuppressWarnings("unchecked")
+
     // This method isn't necessary for XPath processing either.
     public Iterator getPrefixes(String namespaceURI) {
         throw new UnsupportedOperationException();
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,20 +1,21 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
@@ -28,62 +29,60 @@
 
 import org.apache.cocoon.pipeline.component.sax.SAXConsumer;
 import org.apache.cocoon.pipeline.util.dom.DOMUtils;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
+
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.LocatorImpl;
 
-
 public final class XPointerPart implements PointerPart {
-
-    private final static XPathFactory XPF = XPathFactory.newInstance();
-
+    private static final XPathFactory XPF = XPathFactory.newInstance();
     private String expression;
 
     public XPointerPart(String expression) {
         this.expression = expression;
     }
 
-    public boolean process(XPointerContext xpointerContext)
-            throws SAXException, IOException {
+    public boolean process(XPointerContext xpointerContext) throws SAXException, IOException {
         Document document = xpointerContext.getDocument();
-
         XPath xpath = XPF.newXPath();
+
         xpath.setNamespaceContext(xpointerContext);
 
         XPathExpression xpathExpression;
+
         try {
             xpathExpression = xpath.compile(expression);
         } catch (XPathExpressionException e) {
-            throw new SAXException("XPointer: expression \""
-                    + expression
-                    + "\" is not a valid XPath expression", e);
+            throw new SAXException("XPointer: expression \"" + expression + "\" is not a valid XPath expression", e);
         }
 
         try {
-            NodeList nodeList =
-                (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET);
+            NodeList nodeList = (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET);
+
             if (nodeList.getLength() > 0) {
                 SAXConsumer consumer = xpointerContext.getXmlConsumer();
                 LocatorImpl locator = new LocatorImpl();
+
                 locator.setSystemId(xpointerContext.getSource().toString());
                 consumer.setDocumentLocator(locator);
+
                 for (int i = 0; i < nodeList.getLength(); i++) {
                     DOMUtils.stream(nodeList.item(i), consumer);
                 }
+
                 return true;
             } else {
-                if (xpointerContext.getLogger().isDebugEnabled())
-                    xpointerContext.getLogger().debug("XPointer: expression \""
-                            + expression
-                            + "\" gave no results.");
+                if (xpointerContext.getLogger().isDebugEnabled()) {
+                    xpointerContext.getLogger().debug("XPointer: expression \"" + expression + "\" gave no results.");
+                }
+
                 return false;
             }
         } catch (XPathExpressionException e) {
-            throw new SAXException("XPointer: impossible to select DOM fragment using expression \""
-                    + expression
-                    + "\", see nested exception", e);
+            throw new SAXException("XPointer: impossible to select DOM fragment using expression \"" + expression
+                                   + "\", see nested exception", e);
         }
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,20 +1,21 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.xpointer;
 
@@ -22,13 +23,10 @@
 
 import org.xml.sax.SAXException;
 
-
 public final class XmlnsPart implements PointerPart {
-
+    private String namespace;
     private String prefix;
 
-    private String namespace;
-
     /**
      * Creates an XmlnsPart.
      */
@@ -37,10 +35,9 @@
         this.namespace = namespace;
     }
 
-    public boolean process(XPointerContext xpointerContext)
-            throws SAXException, IOException {
+    public boolean process(XPointerContext xpointerContext) throws SAXException, IOException {
         xpointerContext.addPrefix(prefix, namespace);
+
         return false;
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,26 +1,28 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.util.dom;
 
 import java.util.Map.Entry;
 
 import org.apache.cocoon.pipeline.component.sax.SAXConsumer;
+
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 import org.w3c.dom.EntityReference;
@@ -28,18 +30,16 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.ProcessingInstruction;
 import org.w3c.dom.Text;
+
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
-
 final class DOMStreamer {
-    
-    private SAXConsumer xmlConsumer;
-
     private ElementInfo currentElementInfo;
 
     /** Counter used when generating new namespace prefixes. */
     private int newPrefixCounter;
+    private SAXConsumer xmlConsumer;
 
     public DOMStreamer(SAXConsumer xmlConsumer) {
         this.xmlConsumer = xmlConsumer;
@@ -49,17 +49,21 @@
      * Start the production of SAX events.
      */
     public void stream(Node node) throws SAXException {
+
         // Start document only if we're streaming a document
-        boolean isDoc = (node.getNodeType() == Node.DOCUMENT_NODE);
+        boolean isDoc = node.getNodeType() == Node.DOCUMENT_NODE;
+
         if (isDoc) {
             xmlConsumer.startDocument();
         }
 
         Node top = node;
+
         while (null != node) {
             startNode(node);
 
             Node nextNode = node.getFirstChild();
+
             while (null == nextNode) {
                 endNode(node);
 
@@ -68,6 +72,7 @@
                 }
 
                 nextNode = node.getNextSibling();
+
                 if (null == nextNode) {
                     node = node.getParentNode();
 
@@ -75,6 +80,7 @@
                         if (null != node) {
                             endNode(node);
                         }
+
                         nextNode = null;
 
                         break;
@@ -92,250 +98,292 @@
 
     private void startNode(Node node) throws SAXException {
         switch (node.getNodeType()) {
-        case Node.COMMENT_NODE:
-            // ignore comment
-            break;
+            case Node.COMMENT_NODE :
 
-        case Node.DOCUMENT_FRAGMENT_NODE:
-            // ??;
-            break;
-        
-        case Node.DOCUMENT_NODE:
-            break;
+                // ignore comment
+                break;
 
-        case Node.ELEMENT_NODE:
-            NamedNodeMap atts = node.getAttributes();
-            int nAttrs = atts.getLength();
+            case Node.DOCUMENT_FRAGMENT_NODE :
 
-            // create a list of localy declared namespace prefixes
-            currentElementInfo = new ElementInfo(currentElementInfo);
-            for (int i = 0; i < nAttrs; i++) {
-                Node attr = atts.item(i);
-                String attrName = attr.getNodeName();
+                // ??;
+                break;
 
-                if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
-                    int index;
-                    String prefix = (index = attrName.indexOf(":")) < 0
-                            ? "" : attrName.substring(index + 1);
+            case Node.DOCUMENT_NODE :
+                break;
 
-                    currentElementInfo.put(prefix, attr.getNodeValue());
+            case Node.ELEMENT_NODE :
+                NamedNodeMap atts = node.getAttributes();
+                int nAttrs = atts.getLength();
+
+                // create a list of localy declared namespace prefixes
+                currentElementInfo = new ElementInfo(currentElementInfo);
+
+                for (int i = 0; i < nAttrs; i++) {
+                    Node attr = atts.item(i);
+                    String attrName = attr.getNodeName();
+
+                    if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
+                        int index = attrName.indexOf(":");
+                        String prefix = index < 0 ? "" : attrName.substring(index + 1);
+
+                        currentElementInfo.put(prefix, attr.getNodeValue());
+                    }
                 }
-            }
 
-            String namespaceURI = node.getNamespaceURI();
-            String prefix = node.getPrefix();
-            String localName = node.getLocalName();
+                String namespaceURI = node.getNamespaceURI();
+                String prefix = node.getPrefix();
+                String localName = node.getLocalName();
 
-            if (localName == null) {
-                // this is an element created with createElement instead of createElementNS
-                String[] prefixAndLocalName = getPrefixAndLocalName(node.getNodeName());
-                prefix = prefixAndLocalName[0];
-                localName = prefixAndLocalName[1];
-                // note: if prefix is null, there can still be a default namespace...
-                namespaceURI = getNamespaceForPrefix(prefix, (Element)node);
-            }
+                if (localName == null) {
 
-            if (namespaceURI != null) {
-                // no prefix means: make this the default namespace
-                if (prefix == null) {
-                    prefix = "";
+                    // this is an element created with createElement instead of createElementNS
+                    String[] prefixAndLocalName = getPrefixAndLocalName(node.getNodeName());
+
+                    prefix = prefixAndLocalName[0];
+                    localName = prefixAndLocalName[1];
+
+                    // note: if prefix is null, there can still be a default namespace...
+                    namespaceURI = getNamespaceForPrefix(prefix, (Element) node);
                 }
-                // check that is declared
-                String uri = currentElementInfo.findNamespaceURI(prefix);
-                if (uri != null && uri.equals(namespaceURI)) {
-                    // System.out.println("namespace is declared");
-                    // prefix is declared correctly, do nothing
-                } else if (uri != null) {
-                    // System.out.println("prefix is declared with other namespace, overwriting it");
-                    // prefix exists but is bound to another namespace, overwrite it
-                    currentElementInfo.put(prefix, namespaceURI);
+
+                if (namespaceURI != null) {
+
+                    // no prefix means: make this the default namespace
+                    if (prefix == null) {
+                        prefix = "";
+                    }
+
+                    // check that is declared
+                    String uri = currentElementInfo.findNamespaceURI(prefix);
+
+                    if (uri != null && uri.equals(namespaceURI)) {
+
+                        // System.out.println("namespace is declared");
+                        // prefix is declared correctly, do nothing
+                    } else if (uri != null) {
+
+                        // System.out.println("prefix is declared with other namespace, overwriting it");
+                        // prefix exists but is bound to another namespace, overwrite it
+                        currentElementInfo.put(prefix, namespaceURI);
+                    } else {
+
+                        // System.out.println("prefix is not yet declared, declaring it now");
+                        currentElementInfo.put(prefix, namespaceURI);
+                    }
                 } else {
-                    // System.out.println("prefix is not yet declared, declaring it now");
-                    currentElementInfo.put(prefix, namespaceURI);
+
+                    // element has no namespace
+                    // check if there is a default namespace, if so undeclare it
+                    String uri = currentElementInfo.findNamespaceURI("");
+
+                    if (uri != null && uri.length() > 0) {
+
+                        // System.out.println("undeclaring default namespace");
+                        currentElementInfo.put("", "");
+                    }
                 }
-            } else {
-                // element has no namespace
-                // check if there is a default namespace, if so undeclare it
-                String uri = currentElementInfo.findNamespaceURI("");
-                if (uri != null && uri.length() > 0) {
-                    // System.out.println("undeclaring default namespace");
-                    currentElementInfo.put("", "");
+
+                // SAX uses empty string to denote no namespace, while DOM uses null.
+                if (namespaceURI == null) {
+                    namespaceURI = "";
                 }
-            }
 
-            // SAX uses empty string to denote no namespace, while DOM uses null.
-            if (namespaceURI == null)
-                namespaceURI = "";
+                String qName;
 
-            String qName;
-            if (prefix != null && prefix.length() > 0) {
-                qName = prefix + ":" + localName;
-            } else {
-                qName = localName;
-            }
+                if (prefix != null && prefix.length() > 0) {
+                    qName = prefix + ":" + localName;
+                } else {
+                    qName = localName;
+                }
 
-            // make the attributes
-            AttributesImpl newAttrs = new AttributesImpl();
-            for (int i = 0; i < nAttrs; i++) {
-                Node attr = atts.item(i);
-                String attrName = attr.getNodeName();
-                String assignedAttrPrefix = null;
+                // make the attributes
+                AttributesImpl newAttrs = new AttributesImpl();
 
-                // only do non-namespace attributes
-                if (!(attrName.equals("xmlns") || attrName.startsWith("xmlns:"))) {
-                    String attrPrefix;
-                    String attrLocalName;
-                    String attrNsURI;
+                for (int i = 0; i < nAttrs; i++) {
+                    Node attr = atts.item(i);
+                    String attrName = attr.getNodeName();
+                    String assignedAttrPrefix = null;
 
-                    if (attr.getLocalName() == null) {
-                        // this is an attribute created with setAttribute instead of setAttributeNS
-                        String[] prefixAndLocalName = getPrefixAndLocalName(attrName);
-                        attrPrefix = prefixAndLocalName[0];
-                        // the statement below causes the attribute to keep its prefix even if it is not
-                        // bound to a namespace (to support pre-namespace XML).
-                        assignedAttrPrefix = attrPrefix;
-                        attrLocalName = prefixAndLocalName[1];
-                        // note: if prefix is null, the attribute has no namespace (namespace defaulting
-                        // does not apply to attributes)
-                        if (attrPrefix != null)
-                            attrNsURI = getNamespaceForPrefix(attrPrefix, (Element) node);
-                        else
-                            attrNsURI = null;
-                    } else {
-                        attrLocalName = attr.getLocalName();
-                        attrPrefix = attr.getPrefix();
-                        attrNsURI = attr.getNamespaceURI();
-                    }
+                    // only do non-namespace attributes
+                    if (!(attrName.equals("xmlns") || attrName.startsWith("xmlns:"))) {
+                        String attrPrefix;
+                        String attrLocalName;
+                        String attrNsURI;
 
-                    if (attrNsURI != null) {
-                        String declaredUri = currentElementInfo.findNamespaceURI(attrPrefix);
-                        // if the prefix is null, or the prefix has not been declared, or conflicts with an in-scope binding
-                        if (declaredUri == null || !declaredUri.equals(attrNsURI)) {
-                            String availablePrefix = currentElementInfo.findPrefix(attrNsURI);
-                            if (availablePrefix != null && !availablePrefix.equals(""))
-                                assignedAttrPrefix = availablePrefix;
-                            else {
-                                if (attrPrefix != null && declaredUri == null) {
-                                    // prefix is not null and is not yet declared: declare it
-                                    assignedAttrPrefix = attrPrefix;
-                                    currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+                        if (attr.getLocalName() == null) {
+
+                            // this is an attribute created with setAttribute instead of setAttributeNS
+                            String[] prefixAndLocalName = getPrefixAndLocalName(attrName);
+
+                            attrPrefix = prefixAndLocalName[0];
+
+                            // the statement below causes the attribute to keep its prefix even if it is not
+                            // bound to a namespace (to support pre-namespace XML).
+                            assignedAttrPrefix = attrPrefix;
+                            attrLocalName = prefixAndLocalName[1];
+
+                            // note: if prefix is null, the attribute has no namespace (namespace defaulting
+                            // does not apply to attributes)
+                            if (attrPrefix != null) {
+                                attrNsURI = getNamespaceForPrefix(attrPrefix, (Element) node);
+                            } else {
+                                attrNsURI = null;
+                            }
+                        } else {
+                            attrLocalName = attr.getLocalName();
+                            attrPrefix = attr.getPrefix();
+                            attrNsURI = attr.getNamespaceURI();
+                        }
+
+                        if (attrNsURI != null) {
+                            String declaredUri = currentElementInfo.findNamespaceURI(attrPrefix);
+
+                            // if the prefix is null, or the prefix has not been declared, or conflicts
+                            // with an in-scope binding
+                            if (declaredUri == null || !declaredUri.equals(attrNsURI)) {
+                                String availablePrefix = currentElementInfo.findPrefix(attrNsURI);
+
+                                if (availablePrefix != null && !availablePrefix.equals("")) {
+                                    assignedAttrPrefix = availablePrefix;
                                 } else {
-                                    // attribute has no prefix (which is not allowed for namespaced attributes) or
-                                    // the prefix is already bound to something else: generate a new prefix
-                                    newPrefixCounter++;
-                                    assignedAttrPrefix = "NS" + newPrefixCounter;
-                                    currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+                                    if (attrPrefix != null && declaredUri == null) {
+
+                                        // prefix is not null and is not yet declared: declare it
+                                        assignedAttrPrefix = attrPrefix;
+                                        currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+                                    } else {
+
+                                        // attribute has no prefix (which is not allowed for namespaced attributes) or
+                                        // the prefix is already bound to something else: generate a new prefix
+                                        newPrefixCounter++;
+                                        assignedAttrPrefix = "NS" + newPrefixCounter;
+                                        currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+                                    }
                                 }
+                            } else {
+                                assignedAttrPrefix = attrPrefix;
                             }
+                        }
+
+                        String assignedAttrNsURI = attrNsURI != null ? attrNsURI : "";
+                        String attrQName;
+
+                        if (assignedAttrPrefix != null) {
+                            attrQName = assignedAttrPrefix + ":" + attrLocalName;
                         } else {
-                            assignedAttrPrefix = attrPrefix;
+                            attrQName = attrLocalName;
                         }
-                    }
 
-                    String assignedAttrNsURI = attrNsURI != null ? attrNsURI : "";
-                    String attrQName;
-                    if (assignedAttrPrefix != null) {
-                        attrQName = assignedAttrPrefix + ":" + attrLocalName;
-                    } else {
-                        attrQName = attrLocalName;
+                        newAttrs.addAttribute(assignedAttrNsURI, attrLocalName, attrQName, "CDATA",
+                                              attr.getNodeValue());
                     }
-                    newAttrs.addAttribute(assignedAttrNsURI, attrLocalName, attrQName, "CDATA", attr.getNodeValue());
                 }
-            }
 
-            // add local namespace declaration and fire startPrefixMapping events
-            if (currentElementInfo.namespaceDeclarations != null && currentElementInfo.namespaceDeclarations.size() > 0) {
-                for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
-                    String pr = (String) entry.getKey();
-                    String ns = (String) entry.getValue();
-                    // the following lines enable the creation of explicit xmlns attributes
-                    //String pr1 = pr.equals("") ? "xmlns" : pr;
-                    //String qn = pr.equals("") ? "xmlns" : "xmlns:" + pr;
-                    //newAttrs.addAttribute("", pr1, qn, "CDATA", ns);
-                    // System.out.println("starting prefix mapping  for prefix " + pr + " for " + ns);
-                    xmlConsumer.startPrefixMapping(pr, ns);
+                // add local namespace declaration and fire startPrefixMapping events
+                if (currentElementInfo.namespaceDeclarations != null
+                        && currentElementInfo.namespaceDeclarations.size() > 0) {
+                    for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
+                        String pr = (String) entry.getKey();
+                        String ns = (String) entry.getValue();
+
+                        // the following lines enable the creation of explicit xmlns attributes
+                        // String pr1 = pr.equals("") ? "xmlns" : pr;
+                        // String qn = pr.equals("") ? "xmlns" : "xmlns:" + pr;
+                        // newAttrs.addAttribute("", pr1, qn, "CDATA", ns);
+                        // System.out.println("starting prefix mapping  for prefix " + pr + " for " + ns);
+                        xmlConsumer.startPrefixMapping(pr, ns);
+                    }
                 }
-            }
 
-            xmlConsumer.startElement(namespaceURI, localName, qName, newAttrs);
+                xmlConsumer.startElement(namespaceURI, localName, qName, newAttrs);
+                currentElementInfo.localName = localName;
+                currentElementInfo.namespaceURI = namespaceURI;
+                currentElementInfo.qName = qName;
 
-            currentElementInfo.localName = localName;
-            currentElementInfo.namespaceURI = namespaceURI;
-            currentElementInfo.qName = qName;
-            break;
-        case Node.PROCESSING_INSTRUCTION_NODE:
-            {
+                break;
+
+            case Node.PROCESSING_INSTRUCTION_NODE :
                 ProcessingInstruction pi = (ProcessingInstruction) node;
+
                 xmlConsumer.processingInstruction(pi.getNodeName(), pi.getData());
-            }
-            break;
-        case Node.CDATA_SECTION_NODE:
-            {
-                if (xmlConsumer != null)
+
+                break;
+
+            case Node.CDATA_SECTION_NODE :
+                if (xmlConsumer != null) {
                     xmlConsumer.startCDATA();
+                }
 
                 dispatchChars(node);
 
-                if (xmlConsumer != null)
+                if (xmlConsumer != null) {
                     xmlConsumer.endCDATA();
-            }
-            break;
-        case Node.TEXT_NODE:
-            {
+                }
+
+                break;
+
+            case Node.TEXT_NODE :
                 dispatchChars(node);
-            }
-            break;
-        case Node.ENTITY_REFERENCE_NODE:
-            {
+
+                break;
+
+            case Node.ENTITY_REFERENCE_NODE :
                 EntityReference eref = (EntityReference) node;
 
                 if (xmlConsumer != null) {
                     xmlConsumer.startEntity(eref.getNodeName());
                 } else {
+
                     // warning("Can not output entity to a pure SAX xmlConsumer");
                 }
-            }
-            break;
-        default :
+
+                break;
+
+            default :
+        }
     }
-    }
 
     private void endNode(Node node) throws SAXException {
         switch (node.getNodeType()) {
-        case Node.DOCUMENT_NODE:
-            break;
+            case Node.DOCUMENT_NODE :
+                break;
 
-        case Node.ELEMENT_NODE:
-            xmlConsumer.endElement(currentElementInfo.namespaceURI,
-                    currentElementInfo.localName, currentElementInfo.qName);
+            case Node.ELEMENT_NODE :
+                xmlConsumer.endElement(currentElementInfo.namespaceURI, currentElementInfo.localName,
+                                       currentElementInfo.qName);
 
-            // generate endPrefixMapping events if needed
-            if (currentElementInfo.namespaceDeclarations != null && currentElementInfo.namespaceDeclarations.size() > 0) {
-                for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
-                    xmlConsumer.endPrefixMapping((String) entry.getKey());
+                // generate endPrefixMapping events if needed
+                if (currentElementInfo.namespaceDeclarations != null
+                        && currentElementInfo.namespaceDeclarations.size() > 0) {
+                    for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
+                        xmlConsumer.endPrefixMapping((String) entry.getKey());
+                    }
                 }
-            }
 
-            currentElementInfo = currentElementInfo.parent;
-            break;
-        case Node.CDATA_SECTION_NODE:
-            break;
-        case Node.ENTITY_REFERENCE_NODE:
-            {
+                currentElementInfo = currentElementInfo.parent;
+
+                break;
+
+            case Node.CDATA_SECTION_NODE :
+                break;
+
+            case Node.ENTITY_REFERENCE_NODE :
                 EntityReference eref = (EntityReference) node;
 
                 if (xmlConsumer != null) {
                     xmlConsumer.endEntity(eref.getNodeName());
                 }
-            }
-            break;
-        default :
+
+                break;
+
+            default :
+        }
     }
-    }
 
     private void dispatchChars(Node node) throws SAXException {
         final String data = ((Text) node).getData();
-        if ( data != null ) {
+
+        if (data != null) {
             xmlConsumer.characters(data.toCharArray(), 0, data.length());
         }
     }
@@ -358,35 +406,49 @@
      * @return the namespace, or null if not found.
      */
     private String getNamespaceForPrefix(String prefix, Element namespaceContext) {
-        int type;
-        Node parent = namespaceContext;
+        if (prefix == null) {
+            prefix = "";
+        }
+
         String namespace = null;
 
-        if (prefix == null)
-            prefix = "";
-
         if (prefix.equals("xml")) {
             namespace = "http://www.w3.org/XML/1998/namespace";
-        } else if(prefix.equals("xmlns")) {
+        } else if (prefix.equals("xmlns")) {
             namespace = "http://www.w3.org/2000/xmlns/";
         } else {
+
             // Attribute name for this prefix's declaration
             String declname = (prefix.length() == 0) ? "xmlns" : "xmlns:" + prefix;
 
             // Scan until we run out of Elements or have resolved the namespace
-            while ((null != parent) && (null == namespace)
-               && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
-                   || (type == Node.ENTITY_REFERENCE_NODE))) {
+            Node parent = namespaceContext;
+            int type = -1;
+
+            if (parent != null) {
+                type = parent.getNodeType();
+            }
+
+            while (parent != null && namespace == null
+                    && (type == Node.ELEMENT_NODE || type == Node.ENTITY_REFERENCE_NODE)) {
                 if (type == Node.ELEMENT_NODE) {
-                    Attr attr= ((Element)parent).getAttributeNode(declname);
+                    Attr attr = ((Element) parent).getAttributeNode(declname);
+
                     if (attr != null) {
                         namespace = attr.getNodeValue();
+
                         break;
                     }
                 }
+
                 parent = parent.getParentNode();
+
+                if (parent != null) {
+                    type = parent.getNodeType();
+                }
             }
         }
+
         return namespace;
     }
 
@@ -397,8 +459,10 @@
      * second one is the localName
      */
     private String[] getPrefixAndLocalName(String nodeName) {
-        String prefix, localName;
+        String prefix;
+        String localName;
         int colonPos = nodeName.indexOf(":");
+
         if (colonPos != -1) {
             prefix = nodeName.substring(0, colonPos);
             localName = nodeName.substring(colonPos + 1, nodeName.length());
@@ -406,7 +470,7 @@
             prefix = null;
             localName = nodeName;
         }
+
         return new String[] {prefix, localName};
-   }
-
+    }
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,67 +1,68 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.util.dom;
 
-import java.io.IOException;
-import java.net.URL;
+import org.apache.cocoon.pipeline.component.sax.SAXConsumer;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.cocoon.pipeline.component.sax.SAXConsumer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
+import java.io.IOException;
+
 public final class DOMUtils {
+    private static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
 
-    private final static DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
-    
     static {
-    	DBF.setNamespaceAware(true);
-    	DBF.setXIncludeAware(false);
+        DBF.setNamespaceAware(true);
+        DBF.setXIncludeAware(false);
     }
 
     private DOMUtils() {
+
         // instances are not allowed
     }
-    
+
     public static Document toDOM(InputSource source, EntityResolver resolver) throws SAXException, IOException {
         DocumentBuilder documentBuilder;
+
         try {
-        	
-        	// TODO - configuration
+
+            // TODO - configuration
             documentBuilder = DBF.newDocumentBuilder();
             documentBuilder.setEntityResolver(resolver);
+
             return documentBuilder.parse(source);
         } catch (ParserConfigurationException e) {
-            throw new SAXException("Error during XPointer evaluation while trying to load "
-                    + source, e);
+            throw new SAXException("Error during XPointer evaluation while trying to load " + source, e);
         }
     }
 
     public static void stream(Node node, SAXConsumer xmlConsumer) throws SAXException {
         new DOMStreamer(xmlConsumer).stream(node);
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,20 +1,21 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.util.dom;
 
@@ -22,19 +23,13 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
-
 final class ElementInfo {
+    Map<String, String> namespaceDeclarations = null;
+    String localName;
+    String namespaceURI;
+    ElementInfo parent;
+    String qName;
 
-    public String localName;
-
-    public String namespaceURI;
-
-    public String qName;
-
-    public Map<String, String> namespaceDeclarations = null;
-
-    public ElementInfo parent;
-
     public ElementInfo(ElementInfo parent) {
         this.parent = parent;
     }
@@ -44,8 +39,10 @@
      * an existing one.
      */
     public void put(String prefix, String namespaceURI) {
-        if (namespaceDeclarations == null)
+        if (namespaceDeclarations == null) {
             namespaceDeclarations = new HashMap<String, String>();
+        }
+
         namespaceDeclarations.put(prefix, namespaceURI);
     }
 
@@ -53,8 +50,10 @@
      * Finds a prefix declared on this element.
      */
     public String getPrefix(String namespaceURI) {
-        if (namespaceDeclarations == null || namespaceDeclarations.size() == 0)
+        if (namespaceDeclarations == null || namespaceDeclarations.size() == 0) {
             return null;
+        }
+
         // note: there could be more than one prefix for the same namespaceURI, but
         // we return the first found one.
         for (Entry<String, String> entry : namespaceDeclarations.entrySet()) {
@@ -62,6 +61,7 @@
                 return (String) entry.getKey();
             }
         }
+
         return null;
     }
 
@@ -69,8 +69,9 @@
      * Finds a namespace URI declared on this element.
      */
     public String getNamespaceURI(String prefix) {
-        if (namespaceDeclarations == null || namespaceDeclarations.size() == 0)
+        if (namespaceDeclarations == null || namespaceDeclarations.size() == 0) {
             return null;
+        }
 
         return (String) namespaceDeclarations.get(prefix);
     }
@@ -81,13 +82,16 @@
     public String findPrefix(String namespaceURI) {
         if (namespaceDeclarations != null && namespaceDeclarations.size() != 0) {
             String prefix = getPrefix(namespaceURI);
+
             if (prefix != null) {
                 return prefix;
             }
         }
+
         if (parent != null) {
             return parent.findPrefix(namespaceURI);
         }
+
         return null;
     }
 
@@ -97,14 +101,16 @@
     public String findNamespaceURI(String prefix) {
         if (namespaceDeclarations != null && namespaceDeclarations.size() != 0) {
             String uri = (String) namespaceDeclarations.get(prefix);
+
             if (uri != null) {
                 return uri;
             }
         }
+
         if (parent != null) {
             return parent.findNamespaceURI(prefix);
         }
+
         return null;
     }
-
 }

Modified: root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java	2009-11-01 16:31:55 UTC (rev 15794)
+++ root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java	2009-11-01 16:32:35 UTC (rev 15795)
@@ -1,27 +1,30 @@
+
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.pipeline.component.sax;
 
 import static junit.framework.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
+
 import java.net.URL;
+
 import java.util.Properties;
 
 import javax.xml.transform.TransformerFactory;
@@ -30,91 +33,95 @@
 import javax.xml.transform.stream.StreamResult;
 
 import org.custommonkey.xmlunit.Diff;
+
 import org.junit.Ignore;
 import org.junit.Test;
+
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
-
 public final class XIncludeTransformerTest {
+    private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY =
+        (SAXTransformerFactory) TransformerFactory.newInstance();
 
-    private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY = (SAXTransformerFactory) TransformerFactory
-    .newInstance();
     /**
      * A pipeline that reads from a file and perform a simple XInclude operation.
      */
     @Test
     public void testPipelineWithXInclude() throws Exception {
-        internalXIncludeTest("xinclude-xml.xml",
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n  <test/>\n</x>");
+        internalXIncludeTest("xinclude-xml.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n  <test/>\n</x>");
     }
 
     /**
      * A pipeline that performs an XInclude operation, including just text.
-     **/
+     */
     @Test
     @Ignore
     public void testPipelineWithXIncludeText() throws Exception {
-        internalXIncludeTest("xinclude-text-only.xml",
+        internalXIncludeTest(
+            "xinclude-text-only.xml",
             "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n  in girum imus nocte et cosumimur igni\n</x>");
     }
 
     /**
      * A pipeline that performs an XInclude operation, forced to use the fallback.
-     **/
+     */
     @Test
     public void testPipelineWithXIncludeFallback() throws Exception {
-        internalXIncludeTest("xinclude-fallback.xml",
-                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n  \n        <error>the linked document has not found</error>\n    \n</x>");
+        internalXIncludeTest(
+            "xinclude-fallback.xml",
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n  \n        <error>the linked document has not found</error>\n    \n</x>");
     }
 
     /**
      * A pipeline that performs an XInclude operation and use XPointer to extract
      * a fragment from the included document.
-     **/
+     */
     @Test
-   public void testPipelineWithXIncludeAndXPointer() throws Exception {
-       internalXIncludeTest("xinclude-xpointer.xml",
-               "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n  <p>\n      <xsl:value-of select=\"$myParam\"/>\n    </p>\n</x>");
-   }
+    public void testPipelineWithXIncludeAndXPointer() throws Exception {
+        internalXIncludeTest(
+            "xinclude-xpointer.xml",
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n  <p>\n      <xsl:value-of select=\"$myParam\"/>\n    </p>\n</x>");
+    }
 
     /**
      * A pipeline that performs an XInclude operation and use the deprecated
      * XPointer to extract a fragment from the included document.
-     **/
+     */
     @Test
-   public void testPipelineWithXIncludeAndDeprecatedXPointer() throws Exception {
-       internalXIncludeTest("xinclude-deprecated_xpointer.xml",
-       "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n  <p>\n      <xsl:value-of select=\"$myParam\"/>\n    </p>\n</x>");
-   }
+    public void testPipelineWithXIncludeAndDeprecatedXPointer() throws Exception {
+        internalXIncludeTest(
+            "xinclude-deprecated_xpointer.xml",
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n  <p>\n      <xsl:value-of select=\"$myParam\"/>\n    </p>\n</x>");
+    }
 
-   /**
-    * 
-    */
-   private void internalXIncludeTest(String testResource, String expectedDocument) throws Exception {
-       URL base = getClass().getResource("/");
-       URL source = new URL(base, testResource);
+    /**
+     *
+     */
+    private void internalXIncludeTest(String testResource, String expectedDocument) throws Exception {
+        URL base = getClass().getResource("/");
+        URL source = new URL(base, testResource);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        TransformerHandler transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
+        Properties properties = new Properties();
 
+        properties.put("method", "xml");
+        transformerHandler.getTransformer().setOutputProperties(properties);
+        transformerHandler.setResult(new StreamResult(baos));
 
-       ByteArrayOutputStream baos = new ByteArrayOutputStream();
-       TransformerHandler transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
-       Properties properties = new Properties();
-       properties.put("method", "xml");
-       transformerHandler.getTransformer().setOutputProperties(properties);
-       transformerHandler.setResult(new StreamResult(baos));
-       
-       XIncludeTransformer xinclude = new XIncludeTransformer(base.toURI());
-       xinclude.setContentHandler(transformerHandler);
-       XMLReader xmlReader = XMLReaderFactory.createXMLReader();
-       xmlReader.setContentHandler(xinclude);
-       xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", xinclude);
-       xmlReader.parse(source.toExternalForm());
+        XIncludeTransformer xinclude = new XIncludeTransformer(base.toURI());
 
-       String actualDocument = new String(baos.toByteArray());
+        xinclude.setContentHandler(transformerHandler);
 
-       Diff diff = new Diff(expectedDocument, actualDocument);
-       assertTrue("XInclude transformation didn't work as expected " + diff,
-               diff.identical());
-   }
+        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
 
+        xmlReader.setContentHandler(xinclude);
+        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", xinclude);
+        xmlReader.parse(source.toExternalForm());
+
+        String actualDocument = new String(baos.toByteArray());
+        Diff diff = new Diff(expectedDocument, actualDocument);
+
+        assertTrue("XInclude transformation didn't work as expected " + diff, diff.identical());
+    }
 }



More information about the richfaces-svn-commits mailing list