forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stev...@apache.org
Subject cvs commit: xml-forrest/src/scratchpad/src/java/org/apache/forrest/yer/use/cocoon HierarchyGenerator.java
Date Fri, 18 Apr 2003 06:46:10 GMT
stevenn     2003/04/17 23:46:10

  Modified:    src/documentation/content/xdocs cap.xml
               src/resources/conf dtd.xmap faq.xmap forrest.xmap
               src/resources/conf/old sitemap.xmap
               src/resources/convert/cocoon sitemap.xmap
  Added:       src/java/components/org/apache/cocoon/acting/sourcetype
                        DocDeclRule.java DocumentElementRule.java
                        ProcessingInstructionRule.java SourceInfo.java
                        SourceType.java SourceTypeAction.java
                        SourceTypeRule.java XmlSchemaRule.java
               src/java/components/org/apache/cocoon/generation
                        XNIConfigurableFileGenerator.java
  Removed:     src/scratchpad/lib jakarta-oro-2.0.6.jar nekopull.jar
               src/scratchpad/src/java/org/apache/forrest/components/generator
                        XNIConfigurableFileGenerator.java
               src/scratchpad/src/java/org/apache/forrest/components/sourcetype
                        DocDeclRule.java DocumentElementRule.java
                        ProcessingInstructionRule.java SourceInfo.java
                        SourceType.java SourceTypeAction.java
                        SourceTypeRule.java XmlSchemaRule.java
               src/scratchpad/src/java/org/apache/forrest/sax
                        SAXConvenience.java
               src/scratchpad/src/java/org/apache/forrest/yer/hierarchy
                        AttributeReader.java Collection.java Entry.java
                        EntryFactory.java EntryList.java EntryVisitor.java
                        HierarchyConfig.java HierarchyConstants.java
                        HierarchyReader.java SimpleEntryList.java
                        SortingEntryList.java
               src/scratchpad/src/java/org/apache/forrest/yer/impl/fs
                        CollectionImpl.java FileEntryConstants.java
                        FileEntryFactory.java FileEntryImpl.java
                        ItemImpl.java
               src/scratchpad/src/java/org/apache/forrest/yer/libre
                        EntryFilter.java EntrySorter.java
                        LibreAttributeReader.java LibreConfig.java
                        LibreConfigBuilder.java LibreConfigHelper.java
                        LibreConstants.java PropertyAttributeReader.java
                        XPathAttributeReader.java
               src/scratchpad/src/java/org/apache/forrest/yer/use/cli
                        HierarchyDump.java
               src/scratchpad/src/java/org/apache/forrest/yer/use/cocoon
                        HierarchyGenerator.java
  Log:
  moved sourcetype & nekodtd scratchpad sources out of scratchpad, and dropped libre/yer
  
  Revision  Changes    Path
  1.2       +1 -1      xml-forrest/src/documentation/content/xdocs/cap.xml
  
  Index: cap.xml
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/documentation/content/xdocs/cap.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- cap.xml	8 Sep 2002 21:48:38 -0000	1.1
  +++ cap.xml	18 Apr 2003 06:46:08 -0000	1.2
  @@ -24,7 +24,7 @@
         <title>Configuration</title> 
         <p>The action should be declared and configured in the map:actions
           section of the sitemap. Example:</p> 
  -      <source><![CDATA[<map:action name="sourcetype" src="org.apache.forrest.components.sourcetype.SourceTypeAction">
  +      <source><![CDATA[<map:action name="sourcetype" src="org.apache.cocoon.acting.sourcetype.SourceTypeAction">
     <sourcetype name="documentv11">
       <document-declaration public-id="-//APACHE//DTD Documentation V1.1//EN"/>
     </sourcetype>
  
  
  
  1.5       +1 -1      xml-forrest/src/resources/conf/dtd.xmap
  
  Index: dtd.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/conf/dtd.xmap,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- dtd.xmap	24 Mar 2003 03:17:01 -0000	1.4
  +++ dtd.xmap	18 Apr 2003 06:46:08 -0000	1.5
  @@ -3,7 +3,7 @@
   <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
     <map:components>
       <map:generators default="file">
  -      <map:generator name="nekodtd" src="org.apache.forrest.components.generator.XNIConfigurableFileGenerator" />
  +      <map:generator name="nekodtd" src="org.apache.cocoon.generation.XNIConfigurableFileGenerator" />
       </map:generators>
       <map:serializers default="html"/>
       <map:transformers default="xslt"/>
  
  
  
  1.7       +1 -1      xml-forrest/src/resources/conf/faq.xmap
  
  Index: faq.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/conf/faq.xmap,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- faq.xmap	24 Mar 2003 03:17:01 -0000	1.6
  +++ faq.xmap	18 Apr 2003 06:46:08 -0000	1.7
  @@ -8,7 +8,7 @@
       <map:readers default="resource"/>
       <map:matchers default="wildcard"/>
       <map:actions>
  -      <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.forrest.components.sourcetype.SourceTypeAction">
  +      <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.cocoon.acting.sourcetype.SourceTypeAction">
           <sourcetype name="faq-v10">
             <document-declaration public-id="-//APACHE//DTD FAQ V1.0//EN" />
           </sourcetype>
  
  
  
  1.10      +1 -1      xml-forrest/src/resources/conf/forrest.xmap
  
  Index: forrest.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/conf/forrest.xmap,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- forrest.xmap	10 Apr 2003 10:08:20 -0000	1.9
  +++ forrest.xmap	18 Apr 2003 06:46:08 -0000	1.10
  @@ -10,7 +10,7 @@
       <map:readers default="resource"/>
       <map:matchers default="wildcard"/>
       <map:actions>
  -      <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.forrest.components.sourcetype.SourceTypeAction">
  +      <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.cocoon.acting.sourcetype.SourceTypeAction">
           <sourcetype name="document-v10">
             <document-declaration public-id="-//APACHE//DTD Documentation V1.0//EN" />
           </sourcetype>
  
  
  
  1.2       +2 -2      xml-forrest/src/resources/conf/old/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/conf/old/sitemap.xmap,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap.xmap	15 Mar 2003 06:14:24 -0000	1.1
  +++ sitemap.xmap	18 Apr 2003 06:46:08 -0000	1.2
  @@ -11,7 +11,7 @@
   
            <map:generator name="libre" src="org.apache.forrest.yer.use.cocoon.HierarchyGenerator" label="content" />
   
  -         <map:generator name="nekodtd" src="org.apache.forrest.components.generator.XNIConfigurableFileGenerator" label="content" />
  +         <map:generator name="nekodtd" src="org.apache.cocoon.generation.XNIConfigurableFileGenerator" label="content" />
   
            <map:generator name="textparser" src="org.apache.cocoon.generation.TextParserGenerator" label="content" />
   
  @@ -102,7 +102,7 @@
   <!-- <map:action logger="sitemap.action.request" name="request" src="org.apache.cocoon.acting.RequestParamAction"/> -->
            <map:action logger="sitemap.action.resource-exists" name="resource-exists" src="org.apache.cocoon.acting.ResourceExistsAction" />
   
  -         <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.forrest.components.sourcetype.SourceTypeAction">
  +         <map:action logger="sitemap.action.sourcetype" name="sourcetype" src="org.apache.cocoon.acting.sourcetype.SourceTypeAction">
               <sourcetype name="document-v11">
                  <document-declaration public-id="-//APACHE//DTD Documentation V1.1//EN" />
               </sourcetype>
  
  
  
  1.2       +1 -1      xml-forrest/src/resources/convert/cocoon/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/resources/convert/cocoon/sitemap.xmap,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap.xmap	21 Nov 2002 00:49:28 -0000	1.1
  +++ sitemap.xmap	18 Apr 2003 06:46:08 -0000	1.2
  @@ -11,7 +11,7 @@
      <map:generator  name="directory"   src="org.apache.cocoon.generation.DirectoryGenerator" label="content"/>
      <map:generator  name="html"        src="org.apache.cocoon.generation.HTMLGenerator" label="content"/>
      <map:generator  name="libre"       src="org.apache.forrest.yer.use.cocoon.HierarchyGenerator" label="content"/>
  -   <map:generator  name="nekodtd"     src="org.apache.forrest.components.generator.XNIConfigurableFileGenerator" label="content"/>
  +   <map:generator  name="nekodtd"     src="org.apache.cocoon.generation.XNIConfigurableFileGenerator" label="content"/>
      <!-- FIXME: Change this once better view handling is implemented -->
      <map:generator  name="file-nolabel" src="org.apache.cocoon.generation.FileGenerator"/>
     </map:generators>
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/DocDeclRule.java
  
  Index: DocDeclRule.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.*;
  
  /**
   * Rule which checks that the public id has a certain value.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class DocDeclRule implements SourceTypeRule
  {
      protected String publicId;
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          publicId = configuration.getAttribute("public-id");
      }
  
      public boolean matches(SourceInfo sourceInfo)
      {
          if (publicId.equals(sourceInfo.getPublicId()))
              return true;
          else
              return false;
      }
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/DocumentElementRule.java
  
  Index: DocumentElementRule.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * A Rule which checks the local name and namespace of the document element.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class DocumentElementRule implements SourceTypeRule
  {
      protected String localName;
      protected String namespace;
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          localName = configuration.getAttribute("local-name", null);
          namespace = configuration.getAttribute("namespace", null);
          if (localName == null && namespace == null)
              throw new ConfigurationException("Missing local-name and/or namespace attribute on document-element element at " + configuration.getLocation());
      }
  
      public boolean matches(SourceInfo sourceInfo)
      {
          if (localName != null && namespace != null
                  && localName.equals(sourceInfo.getDocumentElementLocalName())
                  && namespace.equals(sourceInfo.getDocumentElementNamespace()))
              return true;
          else if (localName != null && localName.equals(sourceInfo.getDocumentElementLocalName()))
              return true;
          else if (namespace != null && namespace.equals(sourceInfo.getDocumentElementNamespace()))
              return true;
          else
              return false;
      }
  
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/ProcessingInstructionRule.java
  
  Index: ProcessingInstructionRule.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * A rule which checks that a processing instruction with certain data is present.
   */
  public class ProcessingInstructionRule implements SourceTypeRule
  {
      protected String target;
      protected String data;
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          target = configuration.getAttribute("target");
          data = configuration.getAttribute("data", null);
      }
  
      public boolean matches(SourceInfo sourceInfo)
      {
          if (sourceInfo.hasProcessingInstruction(target))
          {
              if (sourceInfo.getProcessingInstructionData(target) == null && data == null)
                  return true;
              if (sourceInfo.getProcessingInstructionData(target) != null && sourceInfo.getProcessingInstructionData(target).equals(data))
                  return true;
          }
          return false;
      }
  
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/SourceInfo.java
  
  Index: SourceInfo.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import java.util.HashMap;
  
  /**
   * Contains information about an XML file. More precisely, the publicId, the processing instructions
   * occuring before the document element, the local name and namespace of the document element, and
   * the value of the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes. All of these
   * attributes can be null.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class SourceInfo
  {
      protected String publicId;
      protected String documentElementLocalName;
      protected String documentElementNamespace;
      protected String xsiSchemaLocation;
      protected String xsiNoNamespaceSchemaLocation;
      protected HashMap processingInstructions = new HashMap();
  
      public String getPublicId()
      {
          return publicId;
      }
  
      public void setPublicId(String publicId)
      {
          this.publicId = publicId;
      }
  
      public String getDocumentElementLocalName()
      {
          return documentElementLocalName;
      }
  
      public void setDocumentElementLocalName(String documentElementLocalName)
      {
          this.documentElementLocalName = documentElementLocalName;
      }
  
      public String getDocumentElementNamespace()
      {
          return documentElementNamespace;
      }
  
      public void setDocumentElementNamespace(String documentElementNamespace)
      {
          this.documentElementNamespace = documentElementNamespace;
      }
  
      public String getXsiSchemaLocation()
      {
          return xsiSchemaLocation;
      }
  
      public void setXsiSchemaLocation(String xsiSchemaLocation)
      {
          this.xsiSchemaLocation = xsiSchemaLocation;
      }
  
      public String getXsiNoNamespaceSchemaLocation()
      {
          return xsiNoNamespaceSchemaLocation;
      }
  
      public void setXsiNoNamespaceSchemaLocation(String xsiNoNamespaceSchemaLocation)
      {
          this.xsiNoNamespaceSchemaLocation = xsiNoNamespaceSchemaLocation;
      }
  
      public void addProcessingInstruction(String target, String data)
      {
          processingInstructions.put(target, data);
      }
  
      public boolean hasProcessingInstruction(String target)
      {
          return processingInstructions.containsKey(target);
      }
  
      public String getProcessingInstructionData(String target)
      {
          return (String)processingInstructions.get(target);
      }
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/SourceType.java
  
  Index: SourceType.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.*;
  
  import java.util.*;
  
  /**
   * Represents a sourcetype. A sourcetype has a name and a number of rules
   * which are used to determine if a certain document is of this sourcetype.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class SourceType implements Configurable
  {
      protected List rules = new ArrayList();
      protected String name;
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          name = configuration.getAttribute("name");
  
          Configuration[] ruleConfs = configuration.getChildren();
          for (int i = 0; i < ruleConfs.length; i++)
          {
              SourceTypeRule rule;
              if (ruleConfs[i].getName().equals("document-declaration"))
                  rule = new DocDeclRule();
              else if (ruleConfs[i].getName().equals("processing-instruction"))
                  rule = new ProcessingInstructionRule();
              else if (ruleConfs[i].getName().equals("w3c-xml-schema"))
                  rule = new ProcessingInstructionRule();
              else if (ruleConfs[i].getName().equals("document-element"))
                  rule = new DocumentElementRule();
              else
                  throw new ConfigurationException("Unsupported element " + ruleConfs[i].getName() + " at "
                          + ruleConfs[i].getLocation());
  
              rule.configure(ruleConfs[i]);
              rules.add(rule);
          }
      }
  
      public boolean matches(SourceInfo sourceInfo)
      {
          Iterator rulesIt = rules.iterator();
          boolean matches = true;
          while (rulesIt.hasNext())
          {
              SourceTypeRule rule = (SourceTypeRule)rulesIt.next();
              matches = matches && rule.matches(sourceInfo);
              if (!matches)
                  return false;
          }
          return matches;
      }
  
      public String getName()
      {
          return name;
      }
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/SourceTypeAction.java
  
  Index: SourceTypeAction.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.cyberneko.pull.XMLPullParser;
  import org.cyberneko.pull.XMLEvent;
  import org.cyberneko.pull.event.*;
  import org.cyberneko.pull.parsers.Xerces2;
  import org.apache.xerces.xni.parser.XMLInputSource;
  import org.apache.avalon.framework.configuration.*;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceNotFoundException;
  
  import java.io.InputStream;
  import java.util.*;
  
  /**
   * An action that assigns a "sourcetype" to a source. See the external documentation for
   * more information.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class SourceTypeAction extends AbstractLogEnabled implements Configurable, ThreadSafe, Action
  {
      protected List sourceTypes = new ArrayList();
      protected static final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          Configuration[] sourceTypeConfs = configuration.getChildren("sourcetype");
          for (int i = 0; i < sourceTypeConfs.length; i++)
          {
              SourceType sourceType = new SourceType();
              sourceType.configure(sourceTypeConfs[i]);
              sourceTypes.add(sourceType);
          }
      }
  
      public Map act(Redirector redirector, SourceResolver sourceResolver, Map objectModel, String src, Parameters parameters)
              throws Exception
      {
          if (src == null || src.equals(""))
              throw new Exception("SourceTypeAction: src attribute should be defined and non-empty.");
          Source source = sourceResolver.resolveURI(src);
          XMLPullParser parser = new Xerces2();
          try {
            InputStream is = source.getInputStream();
            parser.setInputSource(new XMLInputSource(null, src, null, is, null));
          } catch (SourceNotFoundException e) {
            getLogger().warn("Source '"+source+"' not found");
            return null;
          }
  
          // load nothing external
          parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
          parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
          parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
  
          // note: namespace-aware parsing is by default true
  
          SourceInfo sourceInfo = new SourceInfo();
          // pull-parse the document until we reach the document element and put the collected information
          // into the sourceInfo object
          try
          {
              XMLEvent event;
              while ((event = parser.nextEvent()) != null)
              {
                  if (event.type == XMLEvent.DOCTYPE_DECL)
                  {
                      DoctypeDeclEvent doctypeDeclEvent = (DoctypeDeclEvent)event;
                      sourceInfo.setPublicId(doctypeDeclEvent.pubid);
                  }
                  else if (event.type == XMLEvent.PROCESSING_INSTRUCTION)
                  {
                      ProcessingInstructionEvent piEvent = (ProcessingInstructionEvent)event;
                      sourceInfo.addProcessingInstruction(piEvent.target, piEvent.data != null ? piEvent.data.toString() : null);
                  }
                  else if (event.type == XMLEvent.ELEMENT)
                  {
                      ElementEvent elementEvent = (ElementEvent)event;
                      sourceInfo.setDocumentElementLocalName(elementEvent.element.localpart);
                      sourceInfo.setDocumentElementNamespace(elementEvent.element.uri);
  
                      sourceInfo.setXsiSchemaLocation(elementEvent.attributes.getValue(XSI_NAMESPACE, "schemaLocation"));
                      sourceInfo.setXsiNoNamespaceSchemaLocation(elementEvent.attributes.getValue(XSI_NAMESPACE, "noNamespaceSchemaLocation"));
  
                      // stop parsing after the root element
                      break;
                  }
              }
          }
          finally
          {
              // this will also close the inputstream
              parser.cleanup();
          }
  
          // Run over the SourceTypes until one is found that matches the information collected in sourceInfo
          Iterator sourceTypeIt = sourceTypes.iterator();
          while (sourceTypeIt.hasNext())
          {
              SourceType sourceType = (SourceType)sourceTypeIt.next();
              if (sourceType.matches(sourceInfo))
              {
                  HashMap returnMap = new HashMap();
                  returnMap.put("sourcetype", sourceType.getName());
                  if (getLogger().isDebugEnabled())
                      getLogger().debug("SourceTypeAction: found sourcetype " + sourceType.getName() + " for source " + src);
                  return returnMap;
              }
          }
          if (getLogger().isDebugEnabled())
              getLogger().debug("SourceTypeAction: found no sourcetype for source " + src);
          return null;
      }
  }
  
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/SourceTypeRule.java
  
  Index: SourceTypeRule.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.Configurable;
  
  /**
   * Interface to be implemented by all soucetype-defining rules.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public interface SourceTypeRule extends Configurable
  {
      /**
       * Returns true if this rule is satisfied by the given SourceInfo.
       */
      public boolean matches(SourceInfo sourceInfo);
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/acting/sourcetype/XmlSchemaRule.java
  
  Index: XmlSchemaRule.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.acting.sourcetype;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * A Rule which checks the value of the xsi:schemaLocation and xsi:noNamespaceSchemaLocation
   * attributes.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   */
  public class XmlSchemaRule implements SourceTypeRule
  {
      protected String schemaLocation;
      protected String noNamespaceSchemaLocation;
  
      public void configure(Configuration configuration) throws ConfigurationException
      {
          schemaLocation = configuration.getAttribute("schema-location", null);
          noNamespaceSchemaLocation = configuration.getAttribute("no-namespace-schema-location", null);
          if (schemaLocation == null && noNamespaceSchemaLocation == null)
              throw new ConfigurationException("Missing schema-location and/or no-namespace-schema-location attribute on w3c-xml-schema element at " + configuration.getLocation());
      }
  
      public boolean matches(SourceInfo sourceInfo)
      {
          if (schemaLocation != null && noNamespaceSchemaLocation != null
                  && schemaLocation.equals(sourceInfo.getXsiSchemaLocation())
                  && noNamespaceSchemaLocation.equals(sourceInfo.getXsiNoNamespaceSchemaLocation()))
              return true;
          else if (schemaLocation != null && noNamespaceSchemaLocation == null && schemaLocation.equals(sourceInfo.getXsiSchemaLocation()))
              return true;
          else if (schemaLocation == null && noNamespaceSchemaLocation != null && noNamespaceSchemaLocation.equals(sourceInfo.getXsiNoNamespaceSchemaLocation()))
              return true;
          else
              return false;
      }
  
  }
  
  
  
  1.1                  xml-forrest/src/java/components/org/apache/cocoon/generation/XNIConfigurableFileGenerator.java
  
  Index: XNIConfigurableFileGenerator.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 Forrest" 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 (INCLUDING, 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 based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.cocoon.generation;
  
  import org.apache.cocoon.generation.ComposerGenerator;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.ResourceNotFoundException;
  import org.apache.cocoon.components.source.SourceUtil;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.caching.CacheableProcessingComponent;
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.excalibur.xml.EntityResolver;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.xerces.xni.parser.XMLParserConfiguration;
  import org.apache.xerces.xni.parser.XMLConfigurationException;
  import org.apache.xerces.util.EntityResolverWrapper;
  import org.apache.xerces.parsers.AbstractSAXParser;
  import org.apache.excalibur.source.*;
  
  import org.xml.sax.*;
  
  import java.util.Map;
  import java.io.IOException;
  
  
  /** Class <code>org.apache.forrest.components.generator.XNIConfigurableFileGenerator</code>
   *  This class implements a Cocoon Generator that is configurable through
   *  the XNI mechanism that is built into xerces 2.x
   *  The generator is used with:
   *
      <map:generators default="">
        <map:generator name="nekodtd" src="org.apache.forrest.components.generator.XNIConfigurableFileGenerator" label="content" />
      </map:generators>
   *
   * and:
   *
     <map:match pattern="foobar">
       <map:generate type="nekodtd" src="resources/schema/dtd/{1}.dtd">
         <map:parameter name="config-class" value="org.cyberneko.dtd.DTDConfiguration" />
       </map:generate>
       <map:serialize type="xml"/>
     </map:match>
   *
   * TODO: check how some XNIConfigurableXMLReader component (Excalibur style
   *   like the JaxpParser) can be built to do this.  Then the complete
   *   parser can be recycled.
   *
   * @author $Author: stevenn $
   * @version CVS $Id: XNIConfigurableFileGenerator.java,v 1.1 2003/04/18 06:46:09 stevenn Exp $
   */
  public class XNIConfigurableFileGenerator
  extends ComposerGenerator implements CacheableProcessingComponent, Recyclable
  {
  
    /** Default constructor
     *
     */
    public XNIConfigurableFileGenerator()
    {
    }
  
    public static final String CONFIGCLASS_PARAMETER = "config-class";
    public static final String FULL_ENTITY_RESOLVER_PROPERTY_URI =
        org.apache.xerces.impl.Constants.XERCES_PROPERTY_PREFIX +
        org.apache.xerces.impl.Constants.ENTITY_RESOLVER_PROPERTY;
    /** The  source */
    private Source inputSource;
  
    /** The XNIConfiguredParser */
    XMLParserConfiguration parserConfig;
  
    /**
     * Recycle this component.
     * All instance variables are set to <code>null</code>.
     */
    public void recycle() {
      if (this.inputSource != null) {
        this.resolver.release(inputSource);
        this.inputSource = null;
      }
      super.recycle();
   }
  
    /**
     * Copy paste en serious cut from cocoon HTML Generator
     */
    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
    throws ProcessingException, SAXException, IOException {
      super.setup(resolver, objectModel, src, par);
      String parserName = null;
  
      try {
          this.inputSource = resolver.resolveURI(super.source);
          parserName = par.getParameter(CONFIGCLASS_PARAMETER);
          parserConfig = (XMLParserConfiguration)Class.forName(parserName).newInstance();
      } catch(ParameterException e) {
        getLogger().error("Missing parameter " + CONFIGCLASS_PARAMETER, e);
        throw new ProcessingException("XNIConfigurable.setup()",e);
      } catch(InstantiationException e) {
        getLogger().error("Can not make instance of " + parserName, e);
        throw new ProcessingException("XNIConfigurable.setup()",e);
      } catch(IllegalAccessException e) {
        getLogger().error("Can not access constructor of " + parserName, e);
        throw new ProcessingException("XNIConfigurable.setup()",e);
      } catch(ClassNotFoundException e) {
        getLogger().error("Can not find " + parserName, e);
        throw new ProcessingException("XNIConfigurable.setup()",e);
      } catch (SourceException e) {
        getLogger().error("Can not resolve " + super.source);
        throw SourceUtil.handle("Unable to resolve " + super.source, e);
      }
    }
  
    /**
     * 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 this.inputSource.getURI();
    }
  
    /**
     * 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() {
      if (this.inputSource.getLastModified() != 0) {
        this.inputSource.getValidity();
      }
      return null;
    }
  
    /**
     * Generate XML data.
     */
    public void generate()
    throws IOException, SAXException, ProcessingException {
      EntityResolver catalogResolver = null;
      final String[] extendRecognizedProperties = {FULL_ENTITY_RESOLVER_PROPERTY_URI};
      try {
        getLogger().debug("XNIConfigurable generator start generate()");
  
        //TODO?: Make XNIConfigurableParser an avalon component in it's own right
        //      Let the resolver and namespace stuff be configured and composed on that level.
        //  some ideas on this: (any others?)
        // - build a XNIConfigurableParser Component Interface with its ROLE
        // - add a XNIConfigurableParserSelector that can select() based on full qualified class name
        // - and release() after usage
        // the select method could do 6 next lines:
        catalogResolver = (EntityResolver)this.manager.lookup(EntityResolver.ROLE);
        parserConfig.addRecognizedProperties(extendRecognizedProperties);
        parserConfig.setProperty(FULL_ENTITY_RESOLVER_PROPERTY_URI, new EntityResolverWrapper(catalogResolver));
        final XMLReader parser = new AbstractSAXParser(parserConfig){};
        parser.setFeature("http://xml.org/sax/features/namespaces", true);
        parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        parser.setContentHandler(this.contentHandler);
        parser.parse(new InputSource(this.inputSource.getInputStream()));
  
      } catch (IOException e){
        getLogger().warn("XNIConfigurable.generate()", e);
        throw new ResourceNotFoundException("Could not get resource to process:\n["
                + "src = " + this.inputSource.getURI() + "]\n", e);
      } catch (SAXException e){
        getLogger().error("XNIConfigurable.generate()", e);
        throw e;
      } catch (XMLConfigurationException e) {
        getLogger().error( "Misconfig " + e.getType(), e);
        throw new ProcessingException("XNIConfigurable.generate()",e);
      } catch (Exception e){
        getLogger().error("Some strange thing just happened!!", e);
        throw new ProcessingException("XNIConfigurable.generate()",e);
      } finally {
        this.manager.release((Component)catalogResolver);
      }
    }
  }
  
  
  

Mime
View raw message