cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r485031 - in /cocoon/trunk: blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/ blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/ core/cocoo...
Date Sat, 09 Dec 2006 19:01:20 GMT
Author: cziegeler
Date: Sat Dec  9 11:01:18 2006
New Revision: 485031

URL: http://svn.apache.org/viewvc?view=rev&rev=485031
Log:
Reduce usage of xmlizer (which handles only xml anyway)

Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
    cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/RSSTransformer.java?view=diff&rev=485031&r1=485030&r2=485031
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-sitemap/src/main/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
Sat Dec  9 11:01:18 2006
@@ -16,25 +16,17 @@
  */
 package org.apache.cocoon.portal.transformation;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.Serializable;
-import java.util.Map;
 
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
-import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
-import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
-import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.portal.util.HtmlSaxParser;
 import org.apache.cocoon.transformation.AbstractSAXTransformer;
 import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.validity.NOPValidity;
-import org.apache.excalibur.xmlizer.XMLizer;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
@@ -49,9 +41,6 @@
 extends AbstractSAXTransformer
 implements CacheableProcessingComponent {
 
-    /** The xmlizer for converting html to xml. */
-    protected XMLizer xmlizer;
-
     /** The filter */
     protected XMLConsumer filter;
 
@@ -75,28 +64,7 @@
             final String text = this.endTextRecording();
             final String html = "<html><body>"+text+"</body></html>";
 
-            Object parsed = null;            
-            XMLByteStreamCompiler serializer = new XMLByteStreamCompiler(); 
-            try {
-                InputStream inputStream = new ByteArrayInputStream(html.getBytes());
-                this.xmlizer.toSAX(inputStream,
-                                    "text/html",
-                                    null,
-                                    serializer);
-                // if no exception occurs, everything is fine!
-                parsed = serializer.getSAXFragment();
-            } catch (Exception ignore) {
-                // just ignore all exceptions
-            } finally {
-                this.manager.release( serializer );
-            }
-            if ( parsed != null ) {
-                XMLByteStreamInterpreter deserializer = new XMLByteStreamInterpreter();
-                deserializer.setConsumer( this.filter );
-                deserializer.deserialize( parsed );
-            } else {
-                this.sendTextEvent(text);
-            }
+            HtmlSaxParser.parseString(html, this.filter);
         }
         super.endElement(uri,name,raw);
     }
@@ -105,29 +73,11 @@
      * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
      */
     public void recycle() {
-        this.manager.release( this.xmlizer );
-        this.xmlizer = null;
         this.filter = null;
         super.recycle();
     }
 
-    /**
-     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
-     */
-    public void setup(SourceResolver resolver,
-                       Map objectModel,
-                       String src,
-                       Parameters par)
-    throws ProcessingException, SAXException, IOException {
-        super.setup(resolver, objectModel, src, par);
-        try {
-            this.xmlizer = (XMLizer)this.manager.lookup(XMLizer.ROLE);
-        } catch (ServiceException ce) {
-            throw new ProcessingException("Unable to lookup component.", ce);
-        }
-    }
-
-   static class HTMLFilter extends IncludeXMLConsumer {
+    static class HTMLFilter extends IncludeXMLConsumer {
 
        int bodyCount = 0;
 

Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java?view=diff&rev=485031&r1=485030&r2=485031
==============================================================================
--- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java
(original)
+++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java
Sat Dec  9 11:01:18 2006
@@ -45,6 +45,7 @@
 import org.apache.cocoon.caching.validity.NamedEvent;
 import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
 import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
+import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.xml.ContentHandlerWrapper;
 import org.apache.cocoon.xml.XMLConsumer;
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java?view=diff&rev=485031&r1=485030&r2=485031
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/SourceUtil.java
Sat Dec  9 11:01:18 2006
@@ -67,7 +67,7 @@
  *
  * @version $Id$
  */
-public final class SourceUtil {
+public abstract class SourceUtil {
 
     /**
      * Get the current sitemap component manager.
@@ -91,16 +91,12 @@
         }
     }
 
-    /** Avoid instantiation */
-    private SourceUtil() {
-    }
-
     /**
      * Generates SAX events from the XMLizable and handle SAXException.
      *
      * @param  source    the data
      */
-    static public void toSAX(XMLizable source,
+    static public void toSAX(XMLizable      source,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         try {
@@ -140,7 +136,7 @@
      * @param  source    the data
      * @throws ProcessingException if no suitable converter is found
      */
-    static public void toSAX(Source source,
+    static public void toSAX(Source         source,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         toSAX(getSitemapServiceManager(),
@@ -158,8 +154,8 @@
      * @param  source    the data
      * @throws ProcessingException if no suitable converter is found
      */
-    static public void toSAX(Source source,
-                             String mimeTypeHint,
+    static public void toSAX(Source         source,
+                             String         mimeTypeHint,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         toSAX(getSitemapServiceManager(),
@@ -177,8 +173,8 @@
      * @throws ProcessingException if no suitable converter is found
      */
     static public void toSAX(ServiceManager manager,
-                             Source source,
-                             String mimeTypeHint,
+                             Source         source,
+                             String         mimeTypeHint,
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java?view=diff&rev=485031&r1=485030&r2=485031
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
Sat Dec  9 11:01:18 2006
@@ -20,7 +20,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -48,16 +47,18 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.validity.AggregatedValidity;
 import org.apache.excalibur.store.Store;
+import org.apache.excalibur.xml.sax.SAXParser;
 import org.apache.excalibur.xml.sax.XMLizable;
 import org.apache.excalibur.xml.xslt.XSLTProcessor;
 import org.apache.excalibur.xml.xslt.XSLTProcessorException;
-import org.apache.excalibur.xmlizer.XMLizer;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -99,7 +100,7 @@
     /** Map of pairs of System ID's / validities of the included stylesheets */
     protected Map m_includesMap = new HashMap();
 
-    protected XMLizer m_xmlizer;
+    protected SAXParser saxParser;
 
     /** The ServiceManager */
     protected ServiceManager m_manager;
@@ -113,7 +114,7 @@
      */
     public void service(final ServiceManager manager) throws ServiceException {
         m_manager = manager;
-        m_xmlizer = (XMLizer) m_manager.lookup(XMLizer.ROLE);
+        saxParser = (SAXParser) m_manager.lookup(SAXParser.ROLE);
         m_resolver = (SourceResolver) m_manager.lookup(SourceResolver.ROLE);
 
         if (m_manager.hasService(Store.TRANSIENT_STORE)) {
@@ -122,7 +123,7 @@
     }
 
     /**
-     * Initialize
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
         m_factory = getTransformerFactory(m_transformerFactory);
@@ -130,16 +131,15 @@
     }
 
     /**
-     * Disposable
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
         if (null != m_manager) {
             m_manager.release(m_store);
             m_manager.release(m_resolver);
-            m_manager.release(m_xmlizer);
             m_manager = null;
         }
-        m_xmlizer = null;
+        saxParser = null;
         m_store = null;
         m_resolver = null;
     }
@@ -301,14 +301,12 @@
         }
     }
 
-    private void sourceToSAX(Source source, ContentHandler handler) throws SAXException,
IOException, SourceException {
+    private void sourceToSAX(Source source, ContentHandler handler)
+    throws SAXException, IOException, SourceException, ProcessingException {
         if (source instanceof XMLizable) {
             ((XMLizable) source).toSAX(handler);
         } else {
-            final InputStream inputStream = source.getInputStream();
-            final String mimeType = source.getMimeType();
-            final String systemId = source.getURI();
-            m_xmlizer.toSAX(inputStream, mimeType, systemId, handler);
+            this.saxParser.parse(SourceUtil.getInputSource(source), handler);
         }
     }
 



Mime
View raw message