You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2009/06/08 10:05:41 UTC

svn commit: r782553 [2/2] - in /incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter: ./ impl/

Copied: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java (from r782538, incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HTMLSerializer.java)
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java?p2=incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java&p1=incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HTMLSerializer.java&r1=782538&r2=782553&rev=782553&view=diff
==============================================================================
--- incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HTMLSerializer.java (original)
+++ incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java Mon Jun  8 08:05:41 2009
@@ -24,19 +24,18 @@
 import org.apache.sling.rewriter.ProcessingComponentConfiguration;
 import org.apache.sling.rewriter.ProcessingContext;
 import org.apache.sling.rewriter.Serializer;
+import org.apache.sling.rewriter.SerializerFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
  * This sax serializer serializes html-
- * @scr.component metatype="no" factory="org.apache.sling.rewriter.Serializer/html-serializer"
+ * @scr.component metatype="no"
+ * @scr.service
+ * @scr.property name="pipeline.type" value="html-serializer"
  */
-public class HTMLSerializer implements Serializer {
-
-    private PrintWriter delegatee;
-
-    private List<String> emptyTags;
+public class HtmlSerializerFactory implements SerializerFactory {
 
     private static final List<String> DEFAULT_EMPTY_TAGS;
     static {
@@ -54,148 +53,162 @@
     }
 
     /**
-     * @see org.apache.sling.rewriter.Serializer#init(org.apache.sling.rewriter.ProcessingContext, org.apache.sling.rewriter.ProcessingComponentConfiguration)
+     * @see org.apache.sling.rewriter.SerializerFactory#createSerializer()
      */
-    public void init(ProcessingContext pipelineContext, ProcessingComponentConfiguration config)
-    throws IOException {
-        final PrintWriter writer = pipelineContext.getWriter();
-        if (writer == null) {
-            throw new IllegalArgumentException("Writer must not be null");
-        }
-        this.delegatee = writer;
-        this.emptyTags = DEFAULT_EMPTY_TAGS;
+    public Serializer createSerializer() {
+        return new HtmlSerializer();
     }
 
+    public class HtmlSerializer implements Serializer {
 
-    /**
-     * @see org.xml.sax.ContentHandler#endDocument()
-     */
-    public void endDocument() throws SAXException {
-        this.delegatee.flush();
-    }
+        private PrintWriter delegatee;
 
-    /**
-     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
-     */
-    public void startElement(String uri, String localName, String name,
-            Attributes atts) throws SAXException {
-        boolean endSlash = false;
-        this.delegatee.write('<');
-        this.delegatee.write(localName);
-        final String quotesString = atts.getValue(HtmlGenerator.NAMESPACE, HtmlGenerator.QUOTES_ATTR);
-        for(int i=0; i<atts.getLength(); i++) {
-            if (HtmlGenerator.END_SLASH_ATTR.equals(atts.getQName(i))) {
-                endSlash = true;
-            } else if (!HtmlGenerator.NAMESPACE.equals(atts.getURI(i))) {
-                this.delegatee.write(' ');
-                this.delegatee.write(atts.getLocalName(i));
-                final String value = atts.getValue(i);
-                if ( value != null ) {
-                    this.delegatee.write('=');
-                    final char quoteChar;
-                    if ( quotesString != null && quotesString.length() > i ) {
-                        quoteChar = quotesString.charAt(i);
-                    } else {
-                        quoteChar = '\"';
-                    }
-                    this.delegatee.write(quoteChar);
-                    this.delegatee.write(value);
-                    this.delegatee.write(quoteChar);
-                }
+        private List<String> emptyTags;
+
+        /**
+         * @see org.apache.sling.rewriter.Serializer#init(org.apache.sling.rewriter.ProcessingContext, org.apache.sling.rewriter.ProcessingComponentConfiguration)
+         */
+        public void init(ProcessingContext pipelineContext, ProcessingComponentConfiguration config)
+        throws IOException {
+            final PrintWriter writer = pipelineContext.getWriter();
+            if (writer == null) {
+                throw new IllegalArgumentException("Writer must not be null");
             }
+            this.delegatee = writer;
+            this.emptyTags = DEFAULT_EMPTY_TAGS;
         }
 
-        if (endSlash) {
-            // XHTML
-            this.delegatee.write("/");
-        }
 
-        this.delegatee.write(">");
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#endDocument()
+         */
+        public void endDocument() throws SAXException {
+            this.delegatee.flush();
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void endElement(String uri, String localName, String name)
-            throws SAXException {
-        if (!emptyTags.contains(localName)) {
-            this.delegatee.write("</");
+        /**
+         * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+         */
+        public void startElement(String uri, String localName, String name,
+                Attributes atts) throws SAXException {
+            boolean endSlash = false;
+            this.delegatee.write('<');
             this.delegatee.write(localName);
-            this.delegatee.write('>');
+            final String quotesString = atts.getValue(HtmlGeneratorFactory.NAMESPACE, HtmlGeneratorFactory.QUOTES_ATTR);
+            for(int i=0; i<atts.getLength(); i++) {
+                if (HtmlGeneratorFactory.END_SLASH_ATTR.equals(atts.getQName(i))) {
+                    endSlash = true;
+                } else if (!HtmlGeneratorFactory.NAMESPACE.equals(atts.getURI(i))) {
+                    this.delegatee.write(' ');
+                    this.delegatee.write(atts.getLocalName(i));
+                    final String value = atts.getValue(i);
+                    if ( value != null ) {
+                        this.delegatee.write('=');
+                        final char quoteChar;
+                        if ( quotesString != null && quotesString.length() > i ) {
+                            quoteChar = quotesString.charAt(i);
+                        } else {
+                            quoteChar = '\"';
+                        }
+                        this.delegatee.write(quoteChar);
+                        this.delegatee.write(value);
+                        this.delegatee.write(quoteChar);
+                    }
+                }
+            }
+
+            if (endSlash) {
+                // XHTML
+                this.delegatee.write("/");
+            }
+
+            this.delegatee.write(">");
         }
-    }
 
+        /**
+         * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+         */
+        public void endElement(String uri, String localName, String name)
+                throws SAXException {
+            if (!emptyTags.contains(localName)) {
+                this.delegatee.write("</");
+                this.delegatee.write(localName);
+                this.delegatee.write('>');
+            }
+        }
 
-    /**
-     * Called by HtmlParser if character data and tags are to be output for which no
-     * special handling is necessary.
-     *
-     * @param buffer Character data
-     * @param offset Offset where character data starts
-     * @param length The length of the character data
-     */
-    public void characters(char[] buffer, int offset, int length)
-    throws SAXException {
-        //this.checkStartElement(false);
 
-        // special hack for flush request, see bug #20068
-        if (length == 0) {
-            this.delegatee.flush();
-        } else {
-            this.delegatee.write(buffer, offset, length);
+        /**
+         * Called by HtmlParser if character data and tags are to be output for which no
+         * special handling is necessary.
+         *
+         * @param buffer Character data
+         * @param offset Offset where character data starts
+         * @param length The length of the character data
+         */
+        public void characters(char[] buffer, int offset, int length)
+        throws SAXException {
+            //this.checkStartElement(false);
+
+            // special hack for flush request, see bug #20068
+            if (length == 0) {
+                this.delegatee.flush();
+            } else {
+                this.delegatee.write(buffer, offset, length);
+            }
         }
-    }
 
-    /**
-     * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
-     */
-    public void endPrefixMapping(String prefix) throws SAXException {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
+         */
+        public void endPrefixMapping(String prefix) throws SAXException {
+            // not used atm
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
-     */
-    public void ignorableWhitespace(char[] ch, int start, int length)
-            throws SAXException {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
+         */
+        public void ignorableWhitespace(char[] ch, int start, int length)
+                throws SAXException {
+            // not used atm
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
-     */
-    public void processingInstruction(String target, String data)
-            throws SAXException {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
+         */
+        public void processingInstruction(String target, String data)
+                throws SAXException {
+            // not used atm
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
-     */
-    public void setDocumentLocator(Locator locator) {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
+         */
+        public void setDocumentLocator(Locator locator) {
+            // not used atm
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
-     */
-    public void skippedEntity(String name) throws SAXException {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
+         */
+        public void skippedEntity(String name) throws SAXException {
+            // not used atm
+        }
 
-    /**
-     * @see org.xml.sax.ContentHandler#startDocument()
-     */
-    public void startDocument() throws SAXException {
-        // not used atm
-    }
+        /**
+         * @see org.xml.sax.ContentHandler#startDocument()
+         */
+        public void startDocument() throws SAXException {
+            // not used atm
+        }
 
 
-    /**
-     * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
-     */
-    public void startPrefixMapping(String prefix, String uri)
-            throws SAXException {
-        // not used atm
+        /**
+         * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
+         */
+        public void startPrefixMapping(String prefix, String uri)
+                throws SAXException {
+            // not used atm
+        }
     }
-}
\ No newline at end of file
+}

Propchange: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/HtmlSerializerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java?rev=782553&r1=782552&r2=782553&view=diff
==============================================================================
--- incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java (original)
+++ incubator/sling/whiteboard/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java Mon Jun  8 08:05:41 2009
@@ -18,9 +18,6 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
 
 import org.apache.sling.rewriter.Generator;
 import org.apache.sling.rewriter.PipelineConfiguration;
@@ -30,7 +27,6 @@
 import org.apache.sling.rewriter.ProcessorConfiguration;
 import org.apache.sling.rewriter.Serializer;
 import org.apache.sling.rewriter.Transformer;
-import org.osgi.service.component.ComponentInstance;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -43,9 +39,6 @@
     /** Empty array of transformers. */
     private static final Transformer[] EMPTY_TRANSFORMERS = new Transformer[0];
 
-    /** The used instances. */
-    private List<ComponentInstance> instances;
-
     /** The starting point of the pipeline. */
     private Generator generator;
 
@@ -71,9 +64,6 @@
         final PipelineConfiguration config = (PipelineConfiguration)c;
         final ProcessingComponentConfiguration[] transformerConfigs = config.getTransformerConfigurations();
 
-        final int pipelineSize = 5 + (transformerConfigs != null ? transformerConfigs.length : 0);
-        this.instances = new ArrayList<ComponentInstance>(pipelineSize);
-
         // create components and initialize them
 
         // lets get custom rewriter transformers
@@ -134,13 +124,13 @@
     throws IOException {
         final ComponentType component;
         if ( typeClass == Generator.class ) {
-            component = (ComponentType)this.factoryCache.getGenerator(type, this.instances);
+            component = (ComponentType)this.factoryCache.getGenerator(type);
             // we keep the generator
             this.generator = (Generator)component;
         } else if ( typeClass == Transformer.class ) {
-            component = (ComponentType)this.factoryCache.getTransformer(type, this.instances);
+            component = (ComponentType)this.factoryCache.getTransformer(type);
         } else if ( typeClass == Serializer.class ) {
-            component = (ComponentType)this.factoryCache.getSerializer(type, this.instances);
+            component = (ComponentType)this.factoryCache.getSerializer(type);
         } else {
             component = null;
         }
@@ -179,11 +169,6 @@
             final IOException ioe = new IOException("Pipeline exception.");
             ioe.initCause(se);
             throw ioe;
-        } finally {
-            final Iterator<ComponentInstance> instanceIter = this.instances.iterator();
-            while ( instanceIter.hasNext() ) {
-                instanceIter.next().dispose();
-            }
         }
     }
 }