You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by il...@apache.org on 2013/02/27 14:40:13 UTC

svn commit: r1450774 - in /cocoon/branches/BRANCH_2_1_X: ./ lib/ lib/endorsed/ lib/optional/ misc/notes/ src/blocks/batik/java/org/apache/cocoon/serialization/ src/blocks/fop/java/org/apache/cocoon/components/

Author: ilgrosso
Date: Wed Feb 27 13:40:12 2013
New Revision: 1450774

URL: http://svn.apache.org/r1450774
Log:
[COCOON-2295] #resolve

Added:
    cocoon/branches/BRANCH_2_1_X/lib/endorsed/xml-apis-ext-1.4.01.jar   (with props)
    cocoon/branches/BRANCH_2_1_X/lib/optional/batik-all-1.7.jar   (with props)
    cocoon/branches/BRANCH_2_1_X/lib/optional/fop-1.1.jar   (with props)
    cocoon/branches/BRANCH_2_1_X/lib/optional/xmlgraphics-commons-1.5.jar   (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java   (with props)
Removed:
    cocoon/branches/BRANCH_2_1_X/lib/optional/batik-all-1.6.jar
    cocoon/branches/BRANCH_2_1_X/lib/optional/fop-0.95.jar
    cocoon/branches/BRANCH_2_1_X/lib/optional/xmlgraphics-commons-1.3.1.jar
    cocoon/branches/BRANCH_2_1_X/src/blocks/fop/java/org/apache/cocoon/components/
Modified:
    cocoon/branches/BRANCH_2_1_X/   (props changed)
    cocoon/branches/BRANCH_2_1_X/lib/jars.xml
    cocoon/branches/BRANCH_2_1_X/misc/notes/review-jars.txt
    cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java

Propchange: cocoon/branches/BRANCH_2_1_X/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Feb 27 13:40:12 2013
@@ -19,4 +19,3 @@ bin
 prj.el
 dist
 nbproject
-.cocoon.sh.swp

Added: cocoon/branches/BRANCH_2_1_X/lib/endorsed/xml-apis-ext-1.4.01.jar
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/lib/endorsed/xml-apis-ext-1.4.01.jar?rev=1450774&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/branches/BRANCH_2_1_X/lib/endorsed/xml-apis-ext-1.4.01.jar
------------------------------------------------------------------------------
    svn:mime-type = application/jar

Modified: cocoon/branches/BRANCH_2_1_X/lib/jars.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/lib/jars.xml?rev=1450774&r1=1450773&r2=1450774&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/lib/jars.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/lib/jars.xml Wed Feb 27 13:40:12 2013
@@ -309,13 +309,25 @@
   </file>
 
   <file>
+    <title>The XML APIs - External component</title>
+    <description>
+      The External Components portion of xml-commons contains interfaces
+      that are defined by external standards organizations.
+    </description>
+    <ant-target>external</ant-target>
+    <used-by>Cocoon</used-by>
+    <lib>endorsed/xml-apis-ext-1.4.01.jar</lib>
+    <homepage>http://xml.apache.org/commons/</homepage>
+  </file>
+
+  <file>
     <title>Batik</title>
     <description>
       Batik is a Java based toolkit for applications which handle images in
       the Scalable Vector Graphics (SVG) format for various purposes, such as
       viewing, generation or manipulation.</description>
     <used-by>SVG serializer (batik block)</used-by>
-    <lib>optional/batik-all-1.6.jar</lib>
+    <lib>optional/batik-all-1.7.jar</lib>
     <homepage>http://xmlgraphics.apache.org/batik/</homepage>
   </file>
 
@@ -435,7 +447,7 @@
       the XSL recommendation and then turns it into a PDF document.
     </description>
     <used-by>FOP serializer (fop block)</used-by>
-    <lib>optional/fop-0.95.jar</lib>
+    <lib>optional/fop-1.1.jar</lib>
     <homepage>http://xml.apache.org/fop/</homepage>
   </file>
 
@@ -446,7 +458,7 @@
       used by Apache Batik and Apache FOP.
     </description>
     <used-by>FOP serializer (fop block)</used-by>
-    <lib>optional/xmlgraphics-commons-1.3.1.jar</lib>
+    <lib>optional/xmlgraphics-commons-1.5.jar</lib>
     <homepage>http://xmlgraphics.apache.org/commons/</homepage>
   </file>
 

Added: cocoon/branches/BRANCH_2_1_X/lib/optional/batik-all-1.7.jar
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/lib/optional/batik-all-1.7.jar?rev=1450774&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/branches/BRANCH_2_1_X/lib/optional/batik-all-1.7.jar
------------------------------------------------------------------------------
    svn:mime-type = application/jar

Added: cocoon/branches/BRANCH_2_1_X/lib/optional/fop-1.1.jar
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/lib/optional/fop-1.1.jar?rev=1450774&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/branches/BRANCH_2_1_X/lib/optional/fop-1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/jar

Added: cocoon/branches/BRANCH_2_1_X/lib/optional/xmlgraphics-commons-1.5.jar
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/lib/optional/xmlgraphics-commons-1.5.jar?rev=1450774&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cocoon/branches/BRANCH_2_1_X/lib/optional/xmlgraphics-commons-1.5.jar
------------------------------------------------------------------------------
    svn:mime-type = application/jar

Modified: cocoon/branches/BRANCH_2_1_X/misc/notes/review-jars.txt
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/misc/notes/review-jars.txt?rev=1450774&r1=1450773&r2=1450774&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/misc/notes/review-jars.txt (original)
+++ cocoon/branches/BRANCH_2_1_X/misc/notes/review-jars.txt Wed Feb 27 13:40:12 2013
@@ -166,7 +166,7 @@ L: lib/optional/batik-all-1.6.jar
 F: C:
 R: batik-1.7
 http://xmlgraphics.apache.org/batik/
-U: To be done.
+U: Done.
 
 L: lib/optional/bsf-2.4.0.jar
 F: X:
@@ -239,9 +239,9 @@ R: excalibur-datasource-2.1
 
 L: lib/optional/fop-0.95.jar
 F: C:
-R: fop-1.0 (J: 4)
+R: fop-1.1 (J: 4)
 http://xmlgraphics.apache.org/fop/
-U: To be done.
+U: Done.
 
 L: lib/optional/geronimo-spec-activation-1.0.2-rc4.jar
 F: X:
@@ -419,7 +419,7 @@ L: lib/optional/xmlgraphics-commons-1.3.
 F: C:
 R: xmlgraphics-commons-1.5
 http://xmlgraphics.apache.org/commons/
-U: To be done.
+U: Done.
 
 L: lib/optional/xmlrpc-1.1.jar
 F: X:

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java?rev=1450774&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java Wed Feb 27 13:40:12 2013
@@ -0,0 +1,238 @@
+/*
+ * 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.serialization;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.component.Composable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.xml.dom.DOMBuilder;
+import org.w3c.dom.Document;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ * Important notice: adapted from AbstractDOMTransformer
+ * 
+ * An Abstract DOM Serializer, for use when a serializer needs a DOM-based
+ * view of the document.
+ * Subclass this interface and implement <code>serialize(Document doc)</code>.
+ * If you need a ComponentManager there is an instance variable
+ * <code>manager</code> for use.
+ *
+ * Users will want to override getMimeType()
+ *
+ * Authors of AbstractDOMTransformer can be found in the original file.
+ * @see org.apache.cocoon.transformation.AbstractDOMTransformer
+ */
+public abstract class AbstractDOMSerializer extends AbstractSerializer
+        implements DOMBuilder.Listener, Composable, Disposable {
+
+    /**
+     *  The SAX entity resolver
+     */
+    protected SourceResolver resolver;
+
+    /**
+     *  The request object model
+     */
+    protected Map objectModel;
+
+    /**
+     *  The URI requested
+     */
+    protected String source;
+
+    /**
+     *  Parameters in the sitemap
+     */
+    protected Parameters parameters;
+
+    /**
+     * A <code>ComponentManager</code> which is available for use.
+     */
+    protected ComponentManager manager;
+
+    /**
+     * The <code>DOMBuilder</code> used to build DOM tree out of
+     *incoming SAX events.
+     */
+    protected DOMBuilder builder;
+
+
+    public AbstractDOMSerializer() {
+        super();
+        this.builder = new DOMBuilder(this);
+    }
+
+    /**
+     * Set the component manager.
+     */
+    public void compose(ComponentManager manager) {
+        this.manager = manager;
+    }
+
+    /**
+     * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
+     * the source and sitemap <code>Parameters</code> used to process the request.
+     *
+     * If you wish to process the parameters, override this method, call
+     * <code>super()</code> and then add your code.
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+            throws ProcessingException, SAXException, IOException {
+
+        this.resolver = resolver;
+        this.objectModel = objectModel;
+        this.source = src;
+        this.parameters = par;
+    }
+
+    /**
+     * Recycle the component.
+     */
+    public void recycle() {
+        this.resolver = null;
+        this.source = null;
+        this.objectModel = null;
+        this.parameters = null;
+        this.builder.recycle();
+    }
+
+    /**
+     * dispose
+     */
+    public void dispose() {
+        this.builder = null;
+        this.manager = null;
+    }
+
+    public void notify(Document doc) throws SAXException {
+        // Call the user's serialize method
+        try {
+            serialize(doc);
+        } catch (Exception ex) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Got transcoder exception calling serialize(doc), rethrowing", ex);
+            }
+            throw new SAXException("Exception calling serialize(doc)", ex);
+        }
+    }
+
+    /**
+     * This method is called when the Document is finished.
+     * @param doc The DOM Document object representing this SAX stream
+     * 
+     * Subclasses should write their representation of the document to the output stream (see AbstractSerializer)
+     */
+    protected abstract void serialize(Document doc) throws Exception;
+
+    //
+    // SAX Methods. Send incoming SAX events to the DOMBuilder.
+    //
+
+    public void setDocumentLocator(Locator locator) {
+        builder.setDocumentLocator(locator);
+    }
+
+    public void startDocument() throws SAXException {
+        builder.startDocument();
+    }
+
+    public void endDocument() throws SAXException {
+        builder.endDocument();
+    }
+
+    public void startPrefixMapping(String prefix, String uri) throws SAXException {
+        builder.startPrefixMapping(prefix, uri);
+    }
+
+    public void endPrefixMapping(String prefix) throws SAXException {
+        builder.endPrefixMapping(prefix);
+    }
+
+    public void startElement(String uri, String loc, String raw, Attributes a)
+            throws SAXException {
+        builder.startElement(uri, loc, raw, a);
+    }
+
+    public void endElement(String uri, String loc, String raw)
+            throws SAXException {
+        builder.endElement(uri, loc, raw);
+    }
+
+    public void characters(char c[], int start, int len)
+            throws SAXException {
+        builder.characters(c, start, len);
+    }
+
+    public void ignorableWhitespace(char c[], int start, int len)
+            throws SAXException {
+        builder.ignorableWhitespace(c, start, len);
+    }
+
+    public void processingInstruction(String target, String data)
+            throws SAXException {
+        builder.processingInstruction(target, data);
+    }
+
+    public void skippedEntity(String name)
+            throws SAXException {
+        builder.skippedEntity(name);
+    }
+
+    public void startDTD(String name, String publicId, String systemId)
+            throws SAXException {
+        builder.startDTD(name, publicId, systemId);
+    }
+
+    public void endDTD()
+            throws SAXException {
+        builder.endDTD();
+    }
+
+    public void startEntity(String name)
+            throws SAXException {
+        builder.startEntity(name);
+    }
+
+    public void endEntity(String name)
+            throws SAXException {
+        builder.endEntity(name);
+    }
+
+    public void startCDATA()
+            throws SAXException {
+        builder.startCDATA();
+    }
+
+    public void endCDATA()
+            throws SAXException {
+        builder.endCDATA();
+    }
+
+    public void comment(char ch[], int start, int len)
+            throws SAXException {
+        builder.comment(ch, start, len);
+    }
+}

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/AbstractDOMSerializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java?rev=1450774&r1=1450773&r2=1450774&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java Wed Feb 27 13:40:12 2013
@@ -17,9 +17,11 @@
 package org.apache.cocoon.serialization;
 
 import java.awt.Color;
-import java.io.OutputStream;
 import java.io.Serializable;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpUtils;
+
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -30,7 +32,6 @@ import org.apache.batik.transcoder.Trans
 import org.apache.batik.transcoder.TranscoderInput;
 import org.apache.batik.transcoder.TranscoderOutput;
 import org.apache.batik.transcoder.TranscodingHints;
-import org.apache.batik.transcoder.TranscoderException;
 import org.apache.batik.util.ParsedURL;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.caching.CacheableProcessingComponent;
@@ -38,23 +39,27 @@ import org.apache.cocoon.components.tran
 import org.apache.cocoon.components.transcoder.TranscoderFactory;
 import org.apache.cocoon.components.url.ParsedContextURLProtocolHandler;
 import org.apache.cocoon.components.url.ParsedResourceURLProtocolHandler;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.sitemap.SitemapModelComponent;
 import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.xml.dom.SVGBuilder;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.validity.NOPValidity;
 import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
 
 /**
  * A <a href="http://xml.apache.org/batik/">Batik</a> based Serializer for generating PNG/JPEG images
+ * 
+ * sitemap parameter: documentURL (by default httprequest.requestURL is used). The documentURI is used by Batik
+ * to select script interpreters.  If the URI is invalid script interpretation will fail.
+ * (See batik 1.7 BridgeContext.java line 96-100) 
  *
  * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
  * @author <a href="mailto:rossb@apache.org">Ross Burton</a>
  * @version $Id$
  */
-public class SVGSerializer extends SVGBuilder
-implements Serializer, Configurable, CacheableProcessingComponent, Contextualizable {
+public class SVGSerializer extends AbstractDOMSerializer 
+implements Serializer, Configurable, CacheableProcessingComponent, Contextualizable, SitemapModelComponent {
 
     /**
      * Get the context
@@ -65,10 +70,7 @@ implements Serializer, Configurable, Cac
         ParsedURL.registerHandler(new ParsedContextURLProtocolHandler());
         ParsedURL.registerHandler(new ParsedResourceURLProtocolHandler());
     }
-
-    /** The current <code>OutputStream</code>. */
-    private OutputStream output;
-
+    
     /** The current <code>mime-type</code>. */
     private String mimetype;
 
@@ -78,32 +80,9 @@ implements Serializer, Configurable, Cac
     /** The Transcoder Factory to use */
     TranscoderFactory factory = ExtendableTranscoderFactory.getTranscoderFactoryImplementation();
     
-//    private ServiceManager manager;
-
-//    private SourceResolver resolver;
-
-    /**
-     * Set the <code>OutputStream</code> where the XML should be serialized.
-     */
-    public void setOutputStream(OutputStream out) {
-        this.output = out;
-        
-        // Give the source resolver to Batik
-        //SourceProtocolHandler.setup(this.resolver);
-    }
-    
-/*    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-        this.resolver = (SourceResolver)this.manager.lookup(SourceResolver.ROLE);
-    }
-
-    public void dispose() {
-        this.manager.release(this.resolver);
-    }
-*/
     /**
-     * Set the configurations for this serializer.
-     */
+    * Set the configurations for this serializer.
+    */
     public void configure(Configuration conf) throws ConfigurationException {
         this.mimetype = conf.getAttribute("mime-type");
         if (getLogger().isDebugEnabled()) {
@@ -195,34 +174,18 @@ implements Serializer, Configurable, Cac
     }
 
     /**
-     * Receive notification of a successfully completed DOM tree generation.
+     * Receive DOM Document to transcode.
      */
-    public void notify(Document doc) throws SAXException {
-        
-        try {
-            TranscoderInput transInput = new TranscoderInput(doc);
-
-            // Buffering is done by the pipeline (See shouldSetContentLength)
-            TranscoderOutput transOutput = new TranscoderOutput(this.output);
-            transcoder.transcode(transInput, transOutput);
-        } catch (TranscoderException ex) {
-            if (ex.getException() != null) {
-                if (getLogger().isDebugEnabled()) {
-                    getLogger().debug("Got transcoder exception writing image, rethrowing nested exception", ex);
-                }
-                throw new SAXException("Exception writing image", ex.getException());
-            }
-
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Got transcoder exception writing image, rethrowing", ex);
-            }
-            throw new SAXException("Exception writing image", ex);
-        } catch (Exception ex) {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Got exception writing image, rethrowing", ex);
-            }
-            throw new SAXException("Exception writing image", ex);
-        }
+    public void serialize(Document doc) throws Exception {
+        TranscoderInput transInput = new TranscoderInput(doc);
+        HttpServletRequest req = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
+        String documentUrl = parameters.getParameter("documentUrl", 
+                req == null ? null : HttpUtils.getRequestURL(req).toString());
+        transInput.setURI(documentUrl);
+
+        // Buffering is done by the pipeline (See shouldSetContentLength)
+        TranscoderOutput transOutput = new TranscoderOutput(this.output);
+        transcoder.transcode(transInput, transOutput);
     }
 
     /**
@@ -269,4 +232,4 @@ implements Serializer, Configurable, Cac
     public boolean shouldSetContentLength() {
         return true;
     }
-}
+}
\ No newline at end of file