cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/serialization SVGSerializer.java
Date Mon, 16 Sep 2002 15:35:06 GMT
nicolaken    2002/09/16 08:35:06

  Added:       src/blocks/batik/java/org/apache/cocoon/components/transcoder
                        ExtendableTranscoderFactory.java
                        TranscoderFactory.java
               src/blocks/batik/java/org/apache/cocoon/generation
                        FragmentExtractorGenerator.java
               src/blocks/batik/java/org/apache/cocoon/transformation
                        FragmentExtractorTransformer.java
               src/blocks/batik/java/org/apache/cocoon/components/url
                        ParsedContextURLProtocolHandler.java
                        ParsedResourceURLProtocolHandler.java
               src/blocks/batik/conf svg.generation.xmap
                        svg.serializer.xmap svg.transformer.xmap
               src/blocks/batik/java/org/apache/cocoon/xml/dom
                        SVGBuilder.java
               src/blocks/batik/java/org/apache/cocoon/serialization
                        SVGSerializer.java
  Log:
    <action dev="NKB" type="add">
     Added initial support for compilation of Cocoon blocks, and migrated
     Fop and Batik classes and configuration to the src/blocks dir.
     Blocks that need Avalon components not yet supported.
    </action>
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/components/transcoder/ExtendableTranscoderFactory.java
  
  Index: ExtendableTranscoderFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.transcoder;
  
  import org.apache.batik.transcoder.Transcoder;
  import org.apache.batik.transcoder.image.JPEGTranscoder;
  import org.apache.batik.transcoder.image.PNGTranscoder;
  import org.apache.batik.transcoder.image.TIFFTranscoder;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * An extendable Batik Transcoder factory.
   * When given a MIME type, find a Transcoder which supports that MIME
   * type. This factory is extendable as new <code>Transcoder</code>s can
   * be added at runtime.
   *
   * @author <a href="mailto:rossb@apache.org">Ross Burton</a>
   * @version CVS $Id: ExtendableTranscoderFactory.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class ExtendableTranscoderFactory implements TranscoderFactory {
  
      protected static Map transcoders = new HashMap();
  
      protected final static TranscoderFactory singleton = new ExtendableTranscoderFactory();
  
      private ExtendableTranscoderFactory() {
          // Add the default transcoders which come with Batik
          addTranscoder("image/jpeg", JPEGTranscoder.class);
          addTranscoder("image/jpg", JPEGTranscoder.class);
          addTranscoder("image/png", PNGTranscoder.class);
          addTranscoder("image/tiff", TIFFTranscoder.class);
      }
  
      /**
       * Get a reference to this Transcoder Factory.
       */
      public final static TranscoderFactory getTranscoderFactoryImplementation() {
          return singleton;
      }
  
      /**
       * Create a transcoder for a specified MIME type.
       * @param mimeType The MIME type of the destination format
       * @return A suitable transcoder, or <code>null</code> if one cannot be found
       */
      public Transcoder createTranscoder(String mimeType) {
          Class transcoderClass = (Class) transcoders.get(mimeType);
          if (transcoderClass == null) {
              return null;
          } else {
              try {
                  return (Transcoder) transcoderClass.newInstance();
              } catch (Exception ex) {
                  return null;
              }
          }
      }
  
      /**
       * Add a mapping from the specified MIME type to a transcoder.
       * Note: The transcoder must have a no-argument constructor.
       * @param mimeType The MIME type of the Transcoder
       * @param transcoderClass The <code>Class</code> object for the Transcoder.
       */
      public void addTranscoder(String mimeType, Class transcoderClass) {
          transcoders.put(mimeType, transcoderClass);
      }
  
      /**
       * Remove the mapping from a specified MIME type.
       * @param mimeType The MIME type to remove from the mapping.
       */
      public void removeTranscoder(String mimeType) {
          transcoders.remove(mimeType);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/components/transcoder/TranscoderFactory.java
  
  Index: TranscoderFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.transcoder;
  
  import org.apache.batik.transcoder.Transcoder;
  
  /**
   * Apache Batik Transcoder factory.
   * When given a MIME type, find a Transcoder which supports that MIME type.
   * @author <a href="mailto:rossb@apache.org">Ross Burton</a>
   * @version CVS $Id: TranscoderFactory.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public interface TranscoderFactory {
  
    /**
     * Create a transcoder for a specified MIME type.
     * @param mimeType The MIME type of the destination format
     * @return A suitable transcoder, or <code>null> if one cannot be found
     */
    Transcoder createTranscoder(String mimeType) ;
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/generation/FragmentExtractorGenerator.java
  
  Index: FragmentExtractorGenerator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.generation;
  
  import org.apache.avalon.framework.component.ComponentException;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.caching.CacheableProcessingComponent;
  import org.apache.cocoon.components.sax.XMLDeserializer;
  
  import org.apache.excalibur.store.Store;
  import org.apache.excalibur.source.SourceValidity;
  import org.apache.excalibur.source.impl.validity.NOPValidity;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  
  /** The generation half of FragmentExtractor.
   * FragmentExtractor is a transformer-generator pair which is designed to allow
   * sitemap managers to extract certain nodes from a SAX stream and move them
   * into a separate pipeline. The main use for this is to extract inline SVG
   * images and serve them up through a separate pipeline, usually serializing
   * them to PNG or JPEG format first.
   *
   * This is by no means complete yet, but it should prove useful, particularly
   * for offline generation.
   * <p>
   *
   * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
   * @version CVS $Id: FragmentExtractorGenerator.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class FragmentExtractorGenerator extends ComposerGenerator
          implements CacheableProcessingComponent {
  
      /**
       * Generate the unique key.
       * This key must be unique inside the space of this component.
       *
       * @return The generated key hashes the src
       */
      public java.io.Serializable generateKey() {
          return this.source;
      }
  
      /**
       * Generate the validity object.
       *
       * @return The generated validity object or <code>null</code> if the
       *         component is currently not cacheable.
       */
      public SourceValidity generateValidity() {
          return NOPValidity.SHARED_INSTANCE;
      }
  
      public void generate() throws SAXException {
          // Obtain the fragmentID  (which is simply the filename portion of the source)
          getLogger().debug("FragmentExtractorGenerator retrieving document " + source + ".");
  
          Store store = null;
          XMLDeserializer deserializer = null;
          Object fragment = null;
          try {
              store = (Store) this.manager.lookup(Store.TRANSIENT_STORE);
              fragment = store.get(source);
  
              if (fragment==null)
                throw new SAXException("Could not find frament with id " + source + " in store");
  
              deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE);
              deserializer.setConsumer(this.xmlConsumer);
              deserializer.deserialize(fragment);
  
          } catch (ComponentException ce) {
              getLogger().error("Could not lookup for component.", ce);
              throw new SAXException("Could not lookup for component.", ce);
          } finally
          {
              this.manager.release(store);
              this.manager.release(deserializer);
          }
      }
  }
  
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java
  
  Index: FragmentExtractorTransformer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.transformation;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  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.parameters.Parameters;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.caching.CacheableProcessingComponent;
  import org.apache.cocoon.components.sax.XMLSerializer;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.util.HashUtil;
  import org.apache.excalibur.source.SourceValidity;
  import org.apache.excalibur.source.impl.validity.NOPValidity;
  
  import org.apache.excalibur.store.Store;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  
  /**
   * The transformation half of the FragmentExtractor.
   * This transformer sieves an incoming stream of xml
   * and replaces fragments with an xlink locator pointing to the fragments.
   * <p>
   * The extracted fragments are idendified by their element name and namespace URI.
   * The default is to extract SVG images ("svg" elements in namespace
   * "http://www.w3.org/2000/svg"), but this can be overriden in the configuration:
   * <pre>
   *   &lt;extract-uri&gt;http://my/namespace/uri&lt;/extract-uri&gt;
   *   &lt;extract-element&gt;my-element&lt;/extract-element&gt;
   * </pre>
   * <p>
   *
   * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
   * @version CVS $Id: FragmentExtractorTransformer.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class FragmentExtractorTransformer extends AbstractTransformer
      implements CacheableProcessingComponent, Configurable, Composable, Disposable, Recyclable {
  
      private static final String EXTRACT_URI_NAME = "extract-uri";
      private static final String EXTRACT_ELEMENT_NAME = "extract-element";
  
      private static final String EXTRACT_URI = "http://www.w3.org/2000/svg";
      private static final String EXTRACT_ELEMENT = "svg";
  
      private static final String FE_URI = "http://apache.org/cocoon/fragmentextractor/2.0";
      private static final String XLINK_URI = "http://www.w3c.org/1999/xlink";
  
      private String extractURI;
      private String extractElement;
  
      private static String generatorClass = "org.apache.cocoon.generation.FragmentExtractorGenerator";
  
      /** The component manager instance */
      protected ComponentManager manager = null;
  
      private XMLSerializer serializer;
  
      private Map prefixMap;
  
      private int extractLevel;
  
      private int fragmentID;
  
      private String requestURI;
  
      /**
       * Configure this transformer.
       */
      public void configure(Configuration conf) throws ConfigurationException {
          if (conf != null) {
              this.extractURI = conf.getChild(EXTRACT_URI_NAME).getValue(EXTRACT_URI);
              this.extractElement = conf.getChild(EXTRACT_ELEMENT_NAME).getValue(EXTRACT_ELEMENT);
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("Extraction URI is " + this.extractURI);
                  getLogger().debug("Extraction element is " + this.extractElement);
              }
          }
      }
  
      /** Setup the transformer. */
      public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
              throws ProcessingException, SAXException, IOException {
          extractLevel = 0;
          fragmentID = 0;
          prefixMap = new HashMap();
  
          this.requestURI = ObjectModelHelper.getRequest(objectModel).getSitemapURI();
      }
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager) throws ComponentException {
          this.manager = manager;
      }
  
      /**
       * Release all resources.
       */
      public void dispose() {
          this.manager.release(serializer);
          this.serializer = null;
          this.manager = null;
      }
  
      /**
       * Recycle this component
       */
      public void recycle() {
          this.manager.release(serializer);
          this.serializer = null;
      }
  
      /**
       * Generate the unique key.
       * This key must be unique inside the space of this component.
       *
       * @return The generated key hashes the src
       */
      public java.io.Serializable generateKey() {
          return "1";
      }
  
      /**
       * Generate the validity object.
       *
       * @return The generated validity object or <code>null</code> if the
       *         component is currently not cacheable.
       */
      public SourceValidity generateValidity() {
          return NOPValidity.SHARED_INSTANCE;
      }
  
      /**
       * Receive notification of the beginning of a document.
       */
      public void startDocument() throws SAXException {
          super.startDocument();
      }
  
      /**
       * Receive notification of the end of a document.
       */
      public void endDocument() throws SAXException {
          super.endDocument();
      }
  
      /**
       * Begin the scope of a prefix-URI Namespace mapping.
       *
       * @param prefix The Namespace prefix being declared.
       * @param uri The Namespace URI the prefix is mapped to.
       */
      public void startPrefixMapping(String prefix, String uri)
      throws SAXException {
          if (extractLevel == 0) {
              super.startPrefixMapping(prefix,uri);
              prefixMap.put(prefix,uri);
          } else {
              this.serializer.startPrefixMapping(prefix,uri);
          }
      }
  
      /**
       * End the scope of a prefix-URI mapping.
       *
       * @param prefix The prefix that was being mapping.
       */
      public void endPrefixMapping(String prefix)
      throws SAXException {
          if (extractLevel == 0) {
              super.endPrefixMapping(prefix);
              prefixMap.remove(prefix);
          } else {
              this.serializer.endPrefixMapping(prefix);
          }
      }
  
      /**
       * Receive notification of the beginning of an element.
       *
       * @param uri The Namespace URI, or the empty string if the element has no
       *            Namespace URI or if Namespace
       *            processing is not being performed.
       * @param loc The local name (without prefix), or the empty string if
       *            Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty string if
       *            raw names are not available.
       * @param a The attributes attached to the element. If there are no
       *          attributes, it shall be an empty Attributes object.
       */
      public void startElement(String uri, String loc, String raw, Attributes a)
      throws SAXException {
          if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) {
              extractLevel++;
              fragmentID++;
              if (this.getLogger().isDebugEnabled()) {
                  getLogger().debug("FragmentExtractorTransformer extractLevel now " + extractLevel + ".");
              }
  
              try {
                  this.serializer = (XMLSerializer) this.manager.lookup(XMLSerializer.ROLE);
              } catch (ComponentException ce) {
                  throw new SAXException("Could not lookup for XMLSerializer.", ce);
              }
  
              // Start the DOM document
              this.serializer.startDocument();
  
              Iterator itt = prefixMap.entrySet().iterator();
              while (itt.hasNext()) {
                  Map.Entry entry = (Map.Entry)itt.next();
                  this.serializer.startPrefixMapping(
                      (String)entry.getKey(),
                      (String)entry.getValue()
                  );
              }
          }
  
          if (extractLevel == 0) {
              super.startElement(uri,loc,raw,a);
          } else {
              this.serializer.startElement(uri,loc,raw,a);
          }
      }
  
  
      /**
       * Receive notification of the end of an element.
       *
       * @param uri The Namespace URI, or the empty string if the element has no
       *            Namespace URI or if Namespace
       *            processing is not being performed.
       * @param loc The local name (without prefix), or the empty string if
       *            Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty string if
       *            raw names are not available.
       */
      public void endElement(String uri, String loc, String raw)
      throws SAXException {
          if (extractLevel == 0) {
              super.endElement(uri,loc,raw);
          } else {
              this.serializer.endElement(uri,loc,raw);
              if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) {
                  extractLevel--;
                  if (this.getLogger().isDebugEnabled()) {
                      getLogger().debug("FragmentExtractorTransformer extractLevel now " + extractLevel + ".");
                  }
  
                  if (extractLevel == 0) {
                      // finish building the fragment. remove existing prefix mappings.
                      Iterator itt = prefixMap.entrySet().iterator();
                      while (itt.hasNext()) {
                          Map.Entry entry = (Map.Entry) itt.next();
                          this.serializer.endPrefixMapping(
                              (String)entry.getKey()
                          );
                      }
                      this.serializer.endDocument();
  
                      Store store = null;
                      String id = Long.toHexString((hashCode()^HashUtil.hash(requestURI))+fragmentID);
                      try {
                          store = (Store) this.manager.lookup(Store.TRANSIENT_STORE);
  
                          store.store(id, this.serializer.getSAXFragment());
                      } catch (ComponentException ce) {
                          throw new SAXException("Could not lookup for transient store.", ce);
                      } catch (IOException ioe) {
                          throw new SAXException("Could not store fragment.", ioe);
                      } finally
                      {
                          this.manager.release(store);
                          this.manager.release(this.serializer);
                          this.serializer = null;
                      }
  
                      if (this.getLogger().isDebugEnabled()) {
                          getLogger().debug("FragmentExtractorTransformer stored document " + id + ".");
                      }
  
                      // Insert ref.
                      super.startPrefixMapping("fe", FE_URI);
                      AttributesImpl atts = new AttributesImpl();
                      atts.addAttribute(null,"fragment-id","fragment-id","CDATA",id);
                      super.startElement(FE_URI,"fragment","fe:fragment",atts);
                      super.endElement(FE_URI,"fragment","fe:fragment");
                      super.endPrefixMapping("fe");
                  }
              }
          }
      }
  
      /**
       * Receive notification of character data.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void characters(char c[], int start, int len)
      throws SAXException {
          if (extractLevel == 0) {
              super.characters(c,start,len);
          } else {
              this.serializer.characters(c,start,len);
          }
      }
  
      /**
       * Receive notification of ignorable whitespace in element content.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void ignorableWhitespace(char c[], int start, int len)
      throws SAXException {
          if (extractLevel == 0) {
              super.ignorableWhitespace(c,start,len);
          } else {
              this.serializer.ignorableWhitespace(c,start,len);
          }
      }
  
      /**
       * Receive notification of a processing instruction.
       *
       * @param target The processing instruction target.
       * @param data The processing instruction data, or null if none was
       *             supplied.
       */
      public void processingInstruction(String target, String data)
      throws SAXException {
          if (extractLevel == 0) {
              super.processingInstruction(target,data);
          } else {
              this.serializer.processingInstruction(target,data);
          }
      }
  
      /**
       * Receive notification of a skipped entity.
       *
       * @param name The name of the skipped entity.  If it is a  parameter
       *             entity, the name will begin with '%'.
       */
      public void skippedEntity(String name)
      throws SAXException {
          if (extractLevel == 0) {
              super.skippedEntity(name);
          } else {
              this.serializer.skippedEntity(name);
          }
      }
  
      /**
       * Report the start of DTD declarations, if any.
       *
       * @param name The document type name.
       * @param publicId The declared public identifier for the external DTD
       *                 subset, or null if none was declared.
       * @param systemId The declared system identifier for the external DTD
       *                 subset, or null if none was declared.
       */
      public void startDTD(String name, String publicId, String systemId)
      throws SAXException {
          if (extractLevel == 0) {
              super.startDTD(name,publicId,systemId);
          } else {
              throw new SAXException(
                  "Recieved startDTD after beginning fragment extraction process."
              );
          }
      }
  
      /**
       * Report the end of DTD declarations.
       */
      public void endDTD()
      throws SAXException {
          if (extractLevel == 0) {
              super.endDTD();
          } else {
              throw new SAXException(
                  "Recieved endDTD after beginning fragment extraction process."
              );
          }
      }
  
      /**
       * Report the beginning of an entity.
       *
       * @param name The name of the entity. If it is a parameter entity, the
       *             name will begin with '%'.
       */
      public void startEntity(String name)
      throws SAXException {
          if (extractLevel == 0) {
              super.startEntity(name);
          } else {
              this.serializer.startEntity(name);
          }
      }
  
      /**
       * Report the end of an entity.
       *
       * @param name The name of the entity that is ending.
       */
      public void endEntity(String name)
      throws SAXException {
          if (extractLevel == 0) {
              super.endEntity(name);
          } else {
              this.serializer.endEntity(name);
          }
      }
  
      /**
       * Report the start of a CDATA section.
       */
      public void startCDATA()
      throws SAXException {
          if (extractLevel == 0) {
              super.startCDATA();
          } else {
              this.serializer.startCDATA();
          }
      }
  
      /**
       * Report the end of a CDATA section.
       */
      public void endCDATA()
      throws SAXException {
          if (extractLevel == 0) {
              super.endCDATA();
          } else {
              this.serializer.endCDATA();
          }
      }
  
      /**
       * Report an XML comment anywhere in the document.
       *
       * @param ch An array holding the characters in the comment.
       * @param start The starting position in the array.
       * @param len The number of characters to use from the array.
       */
      public void comment(char ch[], int start, int len)
      throws SAXException {
          if (extractLevel == 0) {
              super.comment(ch,start,len);
          } else {
              this.serializer.comment(ch,start,len);
          }
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/components/url/ParsedContextURLProtocolHandler.java
  
  Index: ParsedContextURLProtocolHandler.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.url;
  
  import org.apache.batik.util.AbstractParsedURLProtocolHandler;
  import org.apache.batik.util.ParsedURL;
  import org.apache.batik.util.ParsedURLData;
  import org.apache.cocoon.environment.Context;
  
  import java.net.MalformedURLException;
  
  
  /**
   * Provide an extension to Batik to handle the "context:" protocol.  This class
   * assumes it will live in a separate classloader as the Context is set statically.
   * Batik uses the Jar file Services extension, so the class is instantiated in
   * an uncontrolled manner (as far as Cocoon is concerned).
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version $Id: ParsedContextURLProtocolHandler.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class ParsedContextURLProtocolHandler extends AbstractParsedURLProtocolHandler {
      private static Context context = null;
  
      /**
       * Set the ServletContext for this protocol.  If it does not exist, you will
       * get NullPointerExceptions!
       */
      public static final void setContext(final Context newContext) {
          if (ParsedContextURLProtocolHandler.context == null) {
              ParsedContextURLProtocolHandler.context = newContext;
          }
      }
  
      /**
       * Create a new instance, this doesn't do much beyond register the type of
       * protocol we handle.
       */
      public ParsedContextURLProtocolHandler() {
          super("context");
      }
  
      /**
       * Getbase.getPath() the ParsedURLData for the context.  Absolute URIs are specified like
       * "context://".
       */
      public ParsedURLData parseURL(String uri) {
          ParsedURLData urldata = null;
          try {
              String path = uri.substring("context:/".length());
              urldata = new ParsedURLData(ParsedContextURLProtocolHandler.context.getResource(path));
          } catch (MalformedURLException mue) {
              StringBuffer baseFile = new StringBuffer(ParsedContextURLProtocolHandler
                                                       .context.getRealPath("/"));
  
              if ( !baseFile.toString().endsWith("/")) {
                  baseFile.append("/");
              }
  
              baseFile.append(baseFile);
              baseFile.append(uri.substring("context://".length()));
  
              urldata = new ParsedURLData();
              urldata.protocol = "file";
              urldata.path = baseFile.toString();
          }
  
          if ("file".equals(urldata.protocol)) {
              urldata.host = null;
              urldata.port = -1;
          } else if (null == urldata.host) {
              urldata.port = -1;
          } else if (urldata.port < 0) {
              urldata.host = null;
          }
  
          return urldata;
      }
  
      /**
       * The build the relative URL.  Relative URIs are specified like "context:".
       */
      public ParsedURLData parseURL(ParsedURL base, String uri) {
          StringBuffer newURI = new StringBuffer("context://");
          newURI.append(base.getPath());
  
          if ( !newURI.toString().endsWith("/") ) {
              newURI.append("/");
          }
  
          newURI.append(uri.substring("context:".length()));
  
          return this.parseURL(newURI.toString());
      }
  }
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/components/url/ParsedResourceURLProtocolHandler.java
  
  Index: ParsedResourceURLProtocolHandler.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.url;
  
  import org.apache.batik.util.AbstractParsedURLProtocolHandler;
  import org.apache.batik.util.ParsedURL;
  import org.apache.batik.util.ParsedURLData;
  
  /**
   * Provide an extension to Batik to handle the "resource:" protocol.  This class
   * uses the <code>Thread.getContextClassLoader()</code> classloader to get resources.
   * It is safe to use this URL with multiple Cocoon webapps running.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version $Id: ParsedResourceURLProtocolHandler.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class ParsedResourceURLProtocolHandler extends AbstractParsedURLProtocolHandler {
  
      /**
       * Create a new instance, this doesn't do much beyond register the type of
       * protocol we handle.
       */
      public ParsedResourceURLProtocolHandler() {
          super("resource");
      }
  
      /**
       * Getbase.getPath() the ParsedURLData for the context.  Absolute URIs are specified like
       * "resource://".
       */
      public ParsedURLData parseURL(String uri) {
          ParsedURLData urldata = null;
          String path = uri.substring("resource:/".length());
          urldata = new ParsedURLData(Thread.currentThread().getContextClassLoader().getResource(path));
  
          if ("file".equals(urldata.protocol)) {
              urldata.host = null;
              urldata.port = -1;
          } else if (null == urldata.host) {
              urldata.port = -1;
          } else if (urldata.port < 0) {
              urldata.host = null;
          }
  
          return urldata;
      }
  
      /**
       * The build the relative URL.  Relative URIs are specified like "resource:".
       */
      public ParsedURLData parseURL(ParsedURL base, String uri) {
          StringBuffer newURI = new StringBuffer("resource://");
          newURI.append(base.getPath());
  
          if ( !newURI.toString().endsWith("/") ) {
              newURI.append("/");
          }
  
          newURI.append(uri.substring("resource:".length()));
  
          return this.parseURL(newURI.toString());
      }
  }
  
  
  1.1                  xml-cocoon2/src/blocks/batik/conf/svg.generation.xmap
  
  Index: svg.generation.xmap
  ===================================================================
  <?xml version="1.0"?>
  <xmap xpath="/sitemap/components/generators" unless="generator[@name='extractor']">
  
     <map:generator label="data" logger="sitemap.generator.extractor" name="extractor" src="org.apache.cocoon.generation.FragmentExtractorGenerator"/>
  </xmap>
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/conf/svg.serializer.xmap
  
  Index: svg.serializer.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <xmap xpath="/sitemap/components/serializers" unless="serializer[@name='svg2jpeg']">
     <map:serializer logger="sitemap.serializer.svgxml" name="svgxml" src="org.apache.cocoon.serialization.XMLSerializer" mime-type="image/svg-xml">
      <doctype-public>-//W3C//DTD SVG 20000303 Stylable//EN</doctype-public>
      <doctype-system>http://www.w3.org/TR/2000/03/WD-SVG-20000303/</doctype-system>
     </map:serializer>
  
      <map:serializer logger="sitemap.serializer.svg2png" name="svg2jpeg" src="org.apache.cocoon.serialization.SVGSerializer" mime-type="image/jpeg">
        <parameter name="quality" type="float" value="0.9"/>
      </map:serializer>
  
      <map:serializer logger="sitemap.serializer.svg2png" name="svg2png" src="org.apache.cocoon.serialization.SVGSerializer" mime-type="image/png"/>
  </xmap>
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/conf/svg.transformer.xmap
  
  Index: svg.transformer.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <xmap xpath="/sitemap/components/transformers" unless="transformer[@name='extractor']">
  
      <map:transformer logger="sitemap.transformer.extractor" name="extractor" src="org.apache.cocoon.transformation.FragmentExtractorTransformer"/>
  </xmap>
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/xml/dom/SVGBuilder.java
  
  Index: SVGBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.xml.dom;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
  import org.apache.batik.dom.svg.SVGDOMImplementation;
  import org.apache.batik.util.XMLResourceDescriptor;
  
  import org.apache.cocoon.xml.XMLConsumer;
  import org.w3c.dom.Document;
  import org.xml.sax.SAXException;
  
  /**
   * The <code>SVGBuilder</code> is a utility class that will generate a
   * SVG-DOM Document from SAX events using Batik's SVGDocumentFactory.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @version CVS $Id: SVGBuilder.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class SVGBuilder extends SAXSVGDocumentFactory implements XMLConsumer, LogEnabled {
      protected Logger log;
  
      private static final String SAX_PARSER
          = "org.apache.xerces.parsers.SAXParser";
  
      private final static String CSS_PARSER_CLASS_NAME =
          "org.apache.batik.css.parser.Parser";
  
      static {
          /* Batik 1.5b1 and below:
          org.apache.batik.css.CSSDocumentHandler.CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME);
          */
  
          // VG: Is it required?
          XMLResourceDescriptor.setCSSParserClassName(CSS_PARSER_CLASS_NAME);
      }
  
      /**
       * Construct a new instance of this TreeGenerator.
       */
      protected SVGBuilder() {
          super(SAX_PARSER);
      }
  
      /**
       * Provide component with a logger.
       * 
       * @param logger the logger
       */
      public void enableLogging(Logger logger) {
          if (this.log == null) {
              this.log = logger;
          }
      }
  
      /**
       * Return the newly built Document.
       */
      public Document getDocument() {
          return(this.document);
      }
  
      /**
       * Receive notification of the beginning of a document.
       *
       * @exception SAXException If this method was not called appropriately.
       */
      public void startDocument()
      throws SAXException {
          try {
              // Create SVG Document
              String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
              this.document = implementation.createDocument(namespaceURI, "svg", null);
              super.startDocument();
          } catch (Exception ex){
              log.error("SVGBuilder: startDocument", ex);
              ex.printStackTrace();
              throw new SAXException("SVGBuilder: startDocument", ex);
          }
      }
  
      /**
       * Receive notification of the beginning of a document.
       *
       * @exception SAXException If this method was not called appropriately.
       */
      public void endDocument ()
      throws SAXException {
          try {
              super.endDocument();
  
              // FIXME: Hack.
              ((org.apache.batik.dom.svg.SVGOMDocument)this.document).setURLObject(new java.net.URL("http://xml.apache.org"));
  
              this.notify(this.document);
          } catch (Exception ex){
              log.error("SVGBuilder: endDocument", ex);
              ex.printStackTrace();
              throw new SAXException("SVGBuilder: endDocument", ex);
          }
      }
  
      /**
       * Receive notification of a successfully completed DOM tree generation.
       */
      protected void notify(Document doc)
      throws SAXException {
  
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/batik/java/org/apache/cocoon/serialization/SVGSerializer.java
  
  Index: SVGSerializer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.serialization;
  
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  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.Environment;
  import org.apache.cocoon.util.ClassUtils;
  import org.apache.cocoon.xml.XMLConsumer;
  import org.apache.cocoon.xml.dom.SVGBuilder;
  import org.apache.excalibur.source.SourceValidity;
  import org.apache.excalibur.source.impl.validity.NOPValidity;
  import org.w3c.dom.Document;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.ext.LexicalHandler;
  
  import java.awt.Color;
  import java.io.BufferedOutputStream;
  import java.io.OutputStream;
  
  /**
   * A Batik based Serializer for generating PNG/JPEG images
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:rossb@apache.org">Ross Burton</a>
   * @version CVS $Id: SVGSerializer.java,v 1.1 2002/09/16 15:35:06 nicolaken Exp $
   */
  public class SVGSerializer extends SVGBuilder
  implements Composable, Serializer, Configurable, Poolable, CacheableProcessingComponent, Contextualizable {
  
      /**
       * 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());
      }
  
      /** The <code>ContentHandler</code> receiving SAX events. */
      private ContentHandler contentHandler=null;
      /** The <code>LexicalHandler</code> receiving SAX events. */
      private LexicalHandler lexicalHandler=null;
      /** The component manager instance */
      private ComponentManager manager=null;
      /** The current <code>Environment</code>. */
      private Environment environment=null;
      /** The current <code>Parameters</code>. */
      private Configuration config=null;
      /** The current <code>OutputStream</code>. */
      private OutputStream output=null;
      /** The current <code>mime-type</code>. */
      private String mimetype = null;
      /** The current <code>Transcoder</code>.  */
      Transcoder transcoder = null;
      /** The Transcoder Factory to use */
      TranscoderFactory factory = ExtendableTranscoderFactory.getTranscoderFactoryImplementation();
  
      /**
       * Set the <code>OutputStream</code> where the XML should be serialized.
       */
      public void setOutputStream(OutputStream out) {
          this.output = new BufferedOutputStream(out);
      }
  
      /**
       * Set the configurations for this serializer.
       */
      public void configure(Configuration conf) throws ConfigurationException {
          this.mimetype = conf.getAttribute("mime-type");
          log.debug("SVGSerializer 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) {
                      log.error("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 = new Boolean(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].getValue("");
                  }
                  // TODO: if (logger.isDebug())
                  log.debug("SVG Serializer: 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);
              }
          }
      }
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      /**
       * Set the <code>XMLConsumer</code> that will receive XML data.
       * <br>
       * This method will simply call <code>setContentHandler(consumer)</code>
       * and <code>setLexicalHandler(consumer)</code>.
       */
      public void setConsumer(XMLConsumer consumer) {
          this.contentHandler=consumer;
          this.lexicalHandler=consumer;
      }
  
      /**
       * Set the <code>ContentHandler</code> that will receive XML data.
       * <br>
       * Subclasses may retrieve this <code>ContentHandler</code> instance
       * accessing the protected <code>super.contentHandler</code> field.
       */
      public void setContentHandler(ContentHandler content) {
          this.contentHandler=content;
      }
  
      /**
       * Set the <code>LexicalHandler</code> that will receive XML data.
       * <br>
       * Subclasses may retrieve this <code>LexicalHandler</code> instance
       * accessing the protected <code>super.lexicalHandler</code> field.
       *
       * @exception IllegalStateException If the <code>LexicalHandler</code> or
       *                                  the <code>XMLConsumer</code> were
       *                                  already set.
       */
      public void setLexicalHandler(LexicalHandler lexical) {
          this.lexicalHandler=lexical;
      }
  
      /**
       * Receive notification of a successfully completed DOM tree generation.
       */
      public void notify(Document doc) throws SAXException {
          try {
              TranscoderInput transInput = new TranscoderInput(doc);
              TranscoderOutput transOutput = new TranscoderOutput(this.output);
              transcoder.transcode(transInput, transOutput);
              //this.output.flush();
          } catch (Exception ex) {
              log.error("SVGSerializer: Exception writing image", ex);
              throw new SAXException("Exception writing image ", ex);
          }
      }
  
      /**
       * 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 generateValidity() method.
       *
       * @return The generated key or <code>0</code> if the component
       *              is currently not cacheable.
       */
      public java.io.Serializable generateKey() {
          return "1";
      }
  
      /**
       * Generate the validity object.
       * Before this method can be invoked the generateKey() method
       * must be invoked.
       *
       * @return The generated validity object or <code>null</code> if the
       *         component is currently not cacheable.
       */
      public SourceValidity generateValidity() {
          return NOPValidity.SHARED_INSTANCE;
      }
  
      /**
       * Test if the component wants to set the content length
       */
      public boolean shouldSetContentLength() {
          return false;
      }
  
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message