cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1347619 - /cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
Date Thu, 07 Jun 2012 13:59:31 GMT
Author: ilgrosso
Date: Thu Jun  7 13:59:30 2012
New Revision: 1347619

URL: http://svn.apache.org/viewvc?rev=1347619&view=rev
Log:
Formatting commit - please ignore

Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java?rev=1347619&r1=1347618&r2=1347619&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
Thu Jun  7 13:59:30 2012
@@ -28,7 +28,6 @@ import java.net.URLConnection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import org.apache.cocoon.pipeline.ProcessingException;
 import org.apache.cocoon.sax.AbstractSAXTransformer;
 import org.apache.cocoon.sax.SAXConsumer;
@@ -87,8 +86,8 @@ public final class XIncludeTransformer e
     /**
      * Logger.
      */
-    private static final Logger LOG =
-            LoggerFactory.getLogger(XIncludeTransformer.class);
+    private static final Logger LOG = LoggerFactory.getLogger(XIncludeTransformer.class);
+
     /**
      * The nesting level of xi:include elements that have been encountered.
      */
@@ -110,20 +109,19 @@ public final class XIncludeTransformer e
     private int documentLevel = 0;
 
     /**
-     * Locator of the current stream, stored here so that it can be restored after
-     * another document send its content to the consumer.
+     * 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;
 
     /**
-     * The base URL from which document will be included, if XInclude element
-     * points to a relative path.
+     * The base URL from which document will be included, if XInclude element points to a
relative path.
      */
     private URL baseUrl;
 
     /**
-     * Keep a map of namespaces prefix in the source document to pass it
-     * to the XPointerContext for correct namespace identification.
+     * 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>();
 
@@ -135,12 +133,12 @@ public final class XIncludeTransformer e
      *
      * @param baseUrl
      */
-    public XIncludeTransformer(URL baseUrl) {
+    public XIncludeTransformer(final URL baseUrl) {
         this.setBaseUrl(baseUrl);
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> configuration) {
+    public void setConfiguration(final Map<String, ? extends Object> configuration)
{
         this.setBaseUrl((URL) configuration.get(BASE_URL));
     }
 
@@ -148,13 +146,13 @@ public final class XIncludeTransformer e
      *
      * @param baseUrl
      */
-    public void setBaseUrl(URL baseUrl) {
+    public void setBaseUrl(final URL baseUrl) {
         this.baseUrl = baseUrl;
     }
 
     /**
-     * Eventually previous errors don't reset local variables status, so
-     * every time a new consumer is set, local variables should be re-initialized
+     * Eventually previous errors don't reset local variables status, so every time a new
consumer is set, local
+     * variables should be re-initialized
      */
     @Override
     protected void setSAXConsumer(final SAXConsumer xmlConsumer) {
@@ -165,17 +163,14 @@ public final class XIncludeTransformer e
     }
 
     /**
-     * Determine whether the pipe is currently in a state where contents
-     * should be evaluated, i.e. xi:include elements should be resolved
-     * and elements in other namespaces should be copied through. Will
-     * return false for fallback contents within a successful xi:include,
-     * and true for contents outside any xi:include or within an xi:fallback
+     * Determine whether the pipe is currently in a state where contents should be evaluated,
i.e. xi:include elements
+     * should be resolved and elements in other namespaces should be copied through. Will
return false for fallback
+     * contents within a successful xi:include, and true for contents outside any xi:include
or within an xi:fallback
      * for an unsuccessful xi:include.
      */
     private boolean isEvaluatingContent() {
-        return this.xIncludeElementLevel == 0 ||
-            this.fallbackElementLevel > 0
-                    && this.fallbackElementLevel == this.useFallbackLevel;
+        return this.xIncludeElementLevel == 0 || this.fallbackElementLevel > 0
+                && this.fallbackElementLevel == this.useFallbackLevel;
     }
 
     /**
@@ -187,10 +182,10 @@ public final class XIncludeTransformer e
             return UNKNOWN_LOCATION;
         } else {
             return this.locator.getSystemId()
-                + ":"
-                + this.locator.getColumnNumber()
-                + ":"
-                + this.locator.getLineNumber();
+                    + ":"
+                    + this.locator.getColumnNumber()
+                    + ":"
+                    + this.locator.getLineNumber();
         }
     }
 
@@ -220,6 +215,7 @@ public final class XIncludeTransformer e
     @Override
     public void startElement(final String uri, final String localName, final String name,
final Attributes atts)
             throws SAXException {
+
         if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
             // Handle xi:include:
             if (XINCLUDE_INCLUDE.equals(localName)) {
@@ -267,30 +263,30 @@ public final class XIncludeTransformer e
      */
     private void processXIncludeElement(String href, final String parse, String xpointer,
String encoding,
             final String accept, final String acceptLanguage) throws SAXException {
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("Processing XInclude element: href="
-                 + href
-                 + ", parse="
-                 + parse
-                 + ", xpointer="
-                 + xpointer
-                 + ", encoding="
-                 + encoding
-                 + ", accept="
-                 + accept
-                 + ", acceptLanguage="
-                 + acceptLanguage);
+                    + href
+                    + ", parse="
+                    + parse
+                    + ", xpointer="
+                    + xpointer
+                    + ", encoding="
+                    + encoding
+                    + ", accept="
+                    + accept
+                    + ", acceptLanguage="
+                    + acceptLanguage);
         }
 
         int fragmentIdentifierPos = href.indexOf('#');
         if (fragmentIdentifierPos != -1) {
             if (LOG.isWarnEnabled()) {
-                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.");
+                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);
@@ -300,7 +296,8 @@ public final class XIncludeTransformer e
 
         // An empty or absent href is a reference to the current document -- this can be
different than the current base
         if (!isNotEmpty(href)) {
-            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).");
         }
         URL source = this.createSource(href);
         URLConnection urlConnection = null;
@@ -313,12 +310,12 @@ public final class XIncludeTransformer e
         }
 
         if (urlConnection != null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Parse type=" + parse);
-            }
+            LOG.debug("Parse type={}", parse);
 
             if (XINCLUDE_PARSE_XML.equals(parse)) {
-                /* sends Accept and Accept-Language */
+                /*
+                 * sends Accept and Accept-Language
+                 */
                 if (urlConnection instanceof HttpURLConnection) {
                     HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
 
@@ -352,14 +349,10 @@ public final class XIncludeTransformer e
                     } catch (ParseException e) {
                         // this exception is thrown in case of an invalid xpointer expression
                         this.useFallbackLevel++;
-                        if (LOG.isErrorEnabled()) {
-                            LOG.error("Error parsing XPointer expression, will try to use
fallback.", e);
-                        }
+                        LOG.error("Error parsing XPointer expression, will try to use fallback.",
e);
                     } catch (IOException e) {
                         this.useFallbackLevel++;
-                        if (LOG.isErrorEnabled()) {
-                            LOG.error("Error processing an xInclude, will try to use fallback.",
e);
-                        }
+                        LOG.error("Error processing an xInclude, will try to use fallback.",
e);
                     }
                 } else {
                     // just parse the whole document and stream it
@@ -368,7 +361,7 @@ public final class XIncludeTransformer e
             } else if (XINCLUDE_PARSE_TEXT.equals(parse)) {
                 if (xpointer != null) {
                     throw new SAXException("xpointer attribute must not be present when parse='text':
"
-                         + this.getLocation());
+                            + this.getLocation());
                 }
 
                 // content type will be string like "text/xml; charset=UTF-8" or "text/xml"
@@ -385,13 +378,10 @@ public final class XIncludeTransformer e
                         if (charset.startsWith(CHARSET)) {
                             charset = charset.substring(CHARSET.length()).trim();
                             // strip quotes, if present
-                            if (charset.charAt(0) == '"'
-                                && charset.charAt(charset.length() - 1) == '"'
-                                || charset.charAt(0) == '\''
-                                    && charset.charAt(charset.length() - 1)
-                                        == '\'') {
-                                encoding =
-                                    charset.substring(1, charset.length() - 1);
+                            if (charset.charAt(0) == '"' && charset.charAt(charset.length()
- 1) == '"'
+                                    || charset.charAt(0) == '\'' && charset.charAt(charset.length()
- 1) == '\'') {
+
+                                encoding = charset.substring(1, charset.length() - 1);
                             }
                         } else {
                             encoding = DEFAULT_CHARSET;
@@ -417,19 +407,15 @@ public final class XIncludeTransformer e
                     }
                 } catch (IOException e) {
                     this.useFallbackLevel++;
-                    if (LOG.isErrorEnabled()) {
-                        LOG.error("Error including text: ", e);
-                    }
+                    LOG.error("Error including text: ", e);
                 } finally {
                     closeQuietly(reader);
                     closeQuietly(isr);
                     closeQuietly(is);
                 }
             } else {
-                throw new SAXException("Found 'parse' attribute with unknown value "
-                     + parse
-                     + " at "
-                     + this.getLocation());
+                throw new SAXException("Found 'parse' attribute with unknown value " + parse
+ " at "
+                        + this.getLocation());
             }
         }
     }
@@ -441,23 +427,17 @@ public final class XIncludeTransformer e
      */
     private URL createSource(final String sourceAtt) {
         try {
-            URL source = null;
+            URL source;
             if (sourceAtt.contains(":")) {
                 source = new URL(sourceAtt);
             } else {
                 source = new URL(this.baseUrl, sourceAtt);
             }
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Including source: " + source);
-            }
+            LOG.debug("Including source: {}", source);
 
             return source;
         } catch (MalformedURLException e) {
-            String message = "Can't parse URL " + sourceAtt;
-            if (LOG.isErrorEnabled()) {
-                LOG.error(message, e);
-            }
-            throw new ProcessingException(message, e);
+            throw new ProcessingException("Can't parse URL " + sourceAtt, e);
         }
     }
 
@@ -611,10 +591,7 @@ public final class XIncludeTransformer e
      */
     @Override
     public void setDocumentLocator(final Locator locator) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("setDocumentLocator called "
-                    + locator.getSystemId());
-        }
+        LOG.debug("setDocumentLocator called {}", locator.getSystemId());
 
         this.locator = locator;
         this.getSAXConsumer().setDocumentLocator(locator);



Mime
View raw message