[daisy-commits] [daisy] commit 4668: /trunk/daisy/applications/daisywiki/frontend/

Karel Vervaeke karel at outerthought.org
Fri Mar 28 10:26:39 CET 2008


I realized the commit message was a bit short so here is the longer
version:

---
Replaced fop 0.94 with fop 0.95beta. This fixes missing page numbers
from the index in book pdfs.

The page numbers were missing because fop 0.94 does not support
page-number-citation for fo:inline (actually it does not support the
id's on fo:inline).

- Changed dependencies:
  batik 1.6 -> 1.7
  xmlgraphics-commons 1.2 -> 1.3
  (new) xml-apis-ext-1.4.03
---

Note: the svn log message has not been changed, the pre-revprop-change
hook is missing or broken in our svn repository.

On Fri, 2008-03-28 at 09:10 +0000, karel at cocoondev.org wrote:
> User: karel
> Date: 2008/03/28 10:10 AM
> 
> Added:
>  /trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/
>   AbstractDOMSerializer.java, SVGSerializer.java
> 
> Modified:
>  /trunk/daisy/applications/daisywiki/frontend/
>   maven.xml, project.xml
> 
> Log:
>  Replaced fop 0.94 with fop 0.95beta
> 
> File Changes:
> 
> Directory: /trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/
> ============================================================================================================
> 
> File [added]: AbstractDOMSerializer.java
> Delta lines: +238 -0
> ===================================================================
> --- trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/AbstractDOMSerializer.java	                        (rev 0)
> +++ trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/AbstractDOMSerializer.java	2008-03-28 09:10:05 UTC (rev 4668)
> @@ -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.outerj.daisy.frontend.components.batik;
> +
> +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.serialization.AbstractSerializer;
> +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.
> + */
> +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);
> +    }
> +}
> 
> 
> Property changes on: trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/AbstractDOMSerializer.java
> ___________________________________________________________________
> Name: svn:eol-style
>    + native
> 
> File [added]: SVGSerializer.java
> Delta lines: +244 -0
> ===================================================================
> --- trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/SVGSerializer.java	                        (rev 0)
> +++ trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/SVGSerializer.java	2008-03-28 09:10:05 UTC (rev 4668)
> @@ -0,0 +1,244 @@
> +/*
> + * 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.outerj.daisy.frontend.components.batik;
> +
> +import java.awt.Color;
> +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;
> +import org.apache.avalon.framework.context.Context;
> +import org.apache.avalon.framework.context.ContextException;
> +import org.apache.avalon.framework.context.Contextualizable;
> +import org.apache.batik.transcoder.Transcoder;
> +import org.apache.batik.transcoder.TranscoderInput;
> +import org.apache.batik.transcoder.TranscoderOutput;
> +import org.apache.batik.transcoder.TranscodingHints;
> +import org.apache.batik.util.ParsedURL;
> +import org.apache.cocoon.Constants;
> +import org.apache.cocoon.caching.CacheableProcessingComponent;
> +import org.apache.cocoon.components.transcoder.ExtendableTranscoderFactory;
> +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.ObjectModelHelper;
> +import org.apache.cocoon.environment.http.HttpEnvironment;
> +import org.apache.cocoon.serialization.Serializer;
> +import org.apache.cocoon.sitemap.SitemapModelComponent;
> +import org.apache.cocoon.util.ClassUtils;
> +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.Locator;
> +
> +/**
> + * 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 at yahoo.com">Davanum Srinivas</a>
> + * @author <a href="mailto:rossb at apache.org">Ross Burton</a>
> + * @version $Id: SVGSerializer.java 433543 2006-08-22 06:22:54Z crossley $
> + */
> +public class SVGSerializer extends AbstractDOMSerializer implements Serializer, Configurable, CacheableProcessingComponent, Contextualizable, SitemapModelComponent {
> +
> +    /**
> +     * Get the context
> +     */
> +    public void contextualize(Context context) throws ContextException {
> +        ParsedContextURLProtocolHandler.setContext(
> +            (org.apache.cocoon.environment.Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT));
> +        ParsedURL.registerHandler(new ParsedContextURLProtocolHandler());
> +        ParsedURL.registerHandler(new ParsedResourceURLProtocolHandler());
> +    }
> +
> +    /** Document locator */
> +    private Locator locator;
> +    
> +    /** The current <code>mime-type</code>. */
> +    private String mimetype;
> +
> +    /** The current <code>Transcoder</code>.  */
> +    Transcoder transcoder;
> +
> +    /** The Transcoder Factory to use */
> +    TranscoderFactory factory = ExtendableTranscoderFactory.getTranscoderFactoryImplementation();
> +    
> +    /**
> +    * Set the configurations for this serializer.
> +    */
> +    public void configure(Configuration conf) throws ConfigurationException {
> +        this.mimetype = conf.getAttribute("mime-type");
> +        if (getLogger().isDebugEnabled()) {
> +            getLogger().debug("mime-type: " + mimetype);
> +        }
> +
> +        // Using the Transcoder Factory, get the default transcoder
> +        // for this MIME type.
> +        this.transcoder = factory.createTranscoder(mimetype);
> +
> +        // Iterate through the parameters, looking for a transcoder reference
> +        Configuration[] parameters = conf.getChildren("parameter");
> +        for (int i = 0; i < parameters.length; i++) {
> +            String name = parameters[i].getAttribute("name");
> +            if ("transcoder".equals(name)) {
> +                String transcoderName = parameters[i].getAttribute("value");
> +                try {
> +                    this.transcoder = (Transcoder)ClassUtils.newInstance(transcoderName);
> +                } catch (Exception ex) {
> +                    if (getLogger().isDebugEnabled()) {
> +                        getLogger().debug("Cannot load  class " + transcoderName, ex);
> +                    }
> +                    throw new ConfigurationException("Cannot load class " + transcoderName, ex);
> +                }
> +            }
> +        }
> +        // Do we have a transcoder yet?
> +        if (this.transcoder == null ) {
> +            throw new ConfigurationException(
> +                "Could not autodetect transcoder for SVGSerializer and "
> +                + "no transcoder was specified in the sitemap configuration."
> +            );
> +        }
> +
> +        // Now run through the other parameters, using them as hints
> +        // to the transcoder
> +        for (int i = 0; i < parameters.length; i++ ) {
> +            String name = parameters[i].getAttribute("name");
> +            // Skip over the parameters we've dealt with. Ensure this
> +            // is kept in sync with the above list!
> +            if ("transcoder".equals(name)) {
> +                continue;
> +            }
> +
> +            // Now try and get the hints out
> +            try {
> +                // Turn it into a key name (assume the current Batik style continues!
> +                name = ("KEY_" + name).toUpperCase();
> +                // Use reflection to get a reference to the key object
> +                TranscodingHints.Key key = (TranscodingHints.Key)
> +                    (transcoder.getClass().getField(name).get(transcoder));
> +                Object value;
> +                String keyType = parameters[i].getAttribute("type", "STRING").toUpperCase();
> +                if ("FLOAT".equals(keyType)) {
> +                    // Can throw an exception.
> +                    value = new Float(parameters[i].getAttributeAsFloat("value"));
> +                } else if ("INTEGER".equals(keyType)) {
> +                    // Can throw an exception.
> +                    value = new Integer(parameters[i].getAttributeAsInteger("value"));
> +                } else if ("BOOLEAN".equals(keyType)) {
> +                    // Can throw an exception.
> +                    value = BooleanUtils.toBooleanObject(parameters[i].getAttributeAsBoolean("value"));
> +                } else if ("COLOR".equals(keyType)) {
> +                    // Can throw an exception
> +                    String stringValue = parameters[i].getAttribute("value");
> +                    if (stringValue.startsWith("#")) {
> +                        stringValue = stringValue.substring(1);
> +                    }
> +                    value = new Color(Integer.parseInt(stringValue, 16));
> +                } else {
> +                    // Assume String, and get the value. Allow an empty string.
> +                    value = parameters[i].getAttribute("value", "");
> +                }
> +                if(getLogger().isDebugEnabled()) {
> +                    getLogger().debug("Adding hint \"" + name + "\" with value \"" + value.toString() + "\"");
> +                }
> +                transcoder.addTranscodingHint(key, value);
> +            } catch (ClassCastException ex) {
> +                // This is only thrown from the String keyType... line
> +                throw new ConfigurationException("Specified key (" + name + ") is not a valid Batik Transcoder key.", ex);
> +            } catch (ConfigurationException ex) {
> +                throw new ConfigurationException("Name or value not specified.", ex);
> +            } catch (IllegalAccessException ex) {
> +                throw new ConfigurationException("Cannot access the key for parameter \"" + name + "\"", ex);
> +            } catch (NoSuchFieldException ex) {
> +                throw new ConfigurationException("No field available for parameter \"" + name + "\"", ex);
> +            }
> +        }
> +    }
> +
> +    /**
> +     * Receive DOM Document to transcode.
> +     */
> +    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:req.getRequestURL().toString());
> +        transInput.setURI(documentUrl);
> +
> +        // Buffering is done by the pipeline (See shouldSetContentLength)
> +        TranscoderOutput transOutput = new TranscoderOutput(this.output);
> +        transcoder.transcode(transInput, transOutput);
> +    }
> +
> +    /**
> +     * Return the MIME type.
> +     */
> +    public String getMimeType() {
> +        return mimetype;
> +    }
> +
> +    /**
> +     * Generate the unique key.
> +     * This key must be unique inside the space of this component.
> +     * This method must be invoked before the getValidity() method.
> +     *
> +     * @return The generated key or <code>0</code> if the component
> +     *              is currently not cacheable.
> +     */
> +    public Serializable getKey() {
> +        return "1";
> +    }
> +
> +    /**
> +     * Generate the validity object.
> +     * Before this method can be invoked the getKey() method
> +     * must be invoked.
> +     *
> +     * @return The generated validity object or <code>null</code> if the
> +     *         component is currently not cacheable.
> +     */
> +    public SourceValidity getValidity() {
> +        return NOPValidity.SHARED_INSTANCE;
> +    }
> +
> +    /**
> +     * Returns true so the pipeline implementation will buffer generated
> +     * output and write content length to the response.
> +     * <p>Batik's PNGTranscoder closes the output stream, therefore we
> +     * cannot pass the output stream directly to Batik and have to
> +     * instruct pipeline to buffer it. If we do not buffer, we would get
> +     * an exception when
> +     * {@link org.apache.cocoon.Cocoon#process(org.apache.cocoon.environment.Environment)}
> +     * tries to close the stream.
> +     */
> +    public boolean shouldSetContentLength() {
> +        return true;
> +    }
> +
> +    public void setDocumentLocator(Locator locator) {
> +        this.locator = locator;
> +    }
> +    
> +}
> \ No newline at end of file
> 
> 
> Property changes on: trunk/daisy/applications/daisywiki/frontend/src/java/org/outerj/daisy/frontend/components/batik/SVGSerializer.java
> ___________________________________________________________________
> Name: svn:eol-style
>    + native
> 
> Directory: /trunk/daisy/applications/daisywiki/frontend/
> ========================================================
> 
> File [modified]: maven.xml
> Delta lines: +6 -0
> ===================================================================
> --- trunk/daisy/applications/daisywiki/frontend/maven.xml	2008-03-28 09:07:03 UTC (rev 4667)
> +++ trunk/daisy/applications/daisywiki/frontend/maven.xml	2008-03-28 09:10:05 UTC (rev 4668)
> @@ -373,6 +373,12 @@
>        <fileset dir="${cocoon.custom.lib.core}" includes="commons-io-*.jar"/>
>      </delete>
>      <copy file="${pom.getDependencyPath('commons-io:commons-io')}" todir="${cocoon.custom.lib.core}"/>
> +
> +    <!-- Replace batik.  Dependency increased to version 1.7 by FOP 0.95beta -->
> +    <delete>
> +      <fileset dir="${cocoon.custom.lib.core}" includes="batik-all-*.jar"/>
> +    </delete>
> +    <copy file="${pom.getDependencyPath('batik:batik-all')}" todir="${cocoon.custom.lib.core}"/>
>    </goal>
>  
>    <!-- gets cocoon-webapp into this project -->
> 
> File [modified]: project.xml
> Delta lines: +14 -3
> ===================================================================
> --- trunk/daisy/applications/daisywiki/frontend/project.xml	2008-03-28 09:07:03 UTC (rev 4667)
> +++ trunk/daisy/applications/daisywiki/frontend/project.xml	2008-03-28 09:10:05 UTC (rev 4668)
> @@ -314,22 +314,33 @@
>          <daisy.exclude.from.webapp>true</daisy.exclude.from.webapp>
>        </properties>
>      </dependency>
> -    <!-- Dependencies for FOP 0.93 (which is not included with the Cocoon 2.1.x series) -->
> +    <!-- Dependencies for FOP 0.95beta (which is not included with the Cocoon 2.1.x series) -->
>      <dependency>
>        <groupId>fop</groupId>
>        <artifactId>fop</artifactId>
> -      <version>0.94-jdk14</version>
> +      <version>0.95beta</version>
>      </dependency>
>      <dependency>
>        <groupId>xmlgraphics-commons</groupId>
>        <artifactId>xmlgraphics-commons</artifactId>
> -      <version>1.2</version>
> +      <version>1.3</version>
>      </dependency>
>      <dependency>
>        <groupId>commons-io</groupId>
>        <artifactId>commons-io</artifactId>
>        <version>1.3.2</version>
>      </dependency>
> +    <dependency>
> +      <groupId>batik</groupId>
> +      <artifactId>batik-all</artifactId>
> +      <version>1.7</version>
> +    </dependency>
> +    <!-- xml-apis-ext.jar was introduced in FOP 0.95beta without a version number. md5 sum matches -1.3.04.jar -->
> +    <dependency>
> +      <groupId>xml-apis</groupId>
> +      <artifactId>xml-apis-ext</artifactId>
> +      <version>1.3.04</version>
> +    </dependency>
>    </dependencies>
>  
>    <build>
> 
> _______________________________________________
> daisy-commits mailing list
> daisy-commits at lists.cocoondev.org
> http://lists.cocoondev.org/mailman/listinfo/daisy-commits


More information about the daisy mailing list