cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/xml IncludeXMLConsumer.java
Date Wed, 25 Apr 2001 13:51:36 GMT
dims        01/04/25 06:51:36

  Modified:    src/org/apache/cocoon/components/saxconnector Tag:
                        xml-cocoon2 XIncludeSAXConnector.java
               src/org/apache/cocoon/xml Tag: xml-cocoon2
                        IncludeXMLConsumer.java
  Log:
  Updated XIncludeSAXConnector. Not ready yet.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +89 -82    xml-cocoon/src/org/apache/cocoon/components/saxconnector/Attic/XIncludeSAXConnector.java
  
  Index: XIncludeSAXConnector.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/saxconnector/Attic/XIncludeSAXConnector.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- XIncludeSAXConnector.java	2001/04/24 22:05:58	1.1.2.4
  +++ XIncludeSAXConnector.java	2001/04/25 13:51:31	1.1.2.5
  @@ -10,10 +10,12 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   import java.util.Stack;
  +import java.util.ArrayList;
   
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.Locator;
  +import org.xml.sax.helpers.AttributesImpl;
   
   import org.apache.cocoon.Roles;
   import org.apache.avalon.component.Component;
  @@ -23,7 +25,7 @@
   import org.apache.avalon.component.ComponentManager;
   import org.apache.avalon.component.ComponentException;
   import org.apache.avalon.component.Composable;
  -import org.apache.excalibur.pool.Poolable;
  +import org.apache.excalibur.pool.Recyclable;
   
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.components.url.URLFactory;
  @@ -33,7 +35,7 @@
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
   import org.apache.cocoon.xml.XMLProducer;
  -import org.apache.cocoon.xml.XIncludeContentHandler;
  +import org.apache.cocoon.xml.IncludeXMLConsumer;
   
   
   import org.xml.sax.SAXException;
  @@ -45,42 +47,26 @@
   /**
    * Copy of code from XIncludeTransformer as a starting point for XIncludeSAXConnector.
    * @author <a href="dims@yahoo.com">Davanum Srinivas</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/04/24 22:05:58 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/04/25 13:51:31 $
    */
  -public class XIncludeSAXConnector extends AbstractXMLPipe implements Composable, Poolable,
SAXConnector, Disposable {
  +public class XIncludeSAXConnector extends AbstractXMLPipe implements Composable, Recyclable,
SAXConnector, Disposable {
   
  -    protected URLFactory urlFactory;
  +    /** Stacks namespaces during processing */
  +    //private ArrayList currentNS = new ArrayList();
   
  +    /** The current <code>ComponentManager</code>. */
       protected ComponentManager manager = null;
   
  -    public static final String XMLBASE_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
  -    public static final String XMLBASE_ATTRIBUTE = "base";
  -
       public static final String XINCLUDE_NAMESPACE_URI = "http://www.w3.org/1999/XML/xinclude";
       public static final String XINCLUDE_INCLUDE_ELEMENT = "include";
  -    public static final String XINCLUDE_INCLUDE_ELEMENT_HREF_ATTRIBUTE = "href";
  +    public static final String XINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE = "src";
  +    public static final String XINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE = "element";
  +    public static final String XINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE = "ns";
  +    public static final String XINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE = "prefix";
   
       /** The current <code>Environment</code>. */
       protected Environment environment;
   
  -    protected URL base_xmlbase_uri = null;
  -
  -    /** The current XMLBase URI. We start with an empty "dummy" URL. **/
  -    protected URL current_xmlbase_uri = null;
  -
  -    /** This is a stack of xml:base attributes which belong to our ancestors **/
  -    protected Stack xmlbase_stack = new Stack();
  -
  -    /** namespace uri of the last element which had an xml:base attribute **/
  -    protected String last_xmlbase_element_uri = "";
  -
  -    protected Stack xmlbase_element_uri_stack = new Stack();
  -
  -    /** name of the last element which had an xml:base attribute **/
  -    protected String last_xmlbase_element_name = "";
  -
  -    protected Stack xmlbase_element_name_stack = new Stack();
  -
       public void setup(EntityResolver resolver, Map objectModel,
                         String source, Parameters parameters)
               throws ProcessingException, SAXException, IOException {
  @@ -89,28 +75,18 @@
   
       public void compose(ComponentManager manager) {
           this.manager = manager;
  -        try {
  -            this.urlFactory = (URLFactory)this.manager.lookup(Roles.URL_FACTORY);
  -        } catch (Exception e) {
  -            getLogger().error("cannot obtain URLFactory", e);
  -        }
       }
   
       public void startElement(String uri, String name, String raw, Attributes attr) throws
SAXException {
           String value;
  -        if ((value = attr.getValue(XMLBASE_NAMESPACE_URI,XMLBASE_ATTRIBUTE)) != null) {
  -            try {
  -                startXMLBaseAttribute(uri,name,value);
  -            } catch (MalformedURLException e) {
  -                getLogger().debug("XIncludeSAXConnector", e);
  -                throw new SAXException(e);
  -            }
  -        }
   
           if (uri != null && name != null && uri.equals(XINCLUDE_NAMESPACE_URI)
&& name.equals(XINCLUDE_INCLUDE_ELEMENT)) {
  -            String href = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_HREF_ATTRIBUTE);
  +            String src = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE);
  +            String element = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE);
  +            String ns = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE);
  +            String prefix = attr.getValue("",XINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE);
               try {
  -                processXIncludeElement(href);
  +                processXIncludeElement(src, element, ns, prefix);
               } catch (MalformedURLException e) {
                   getLogger().debug("XIncludeSAXConnector", e);
                   throw new SAXException(e);
  @@ -120,53 +96,69 @@
               }
               return;
           }
  -        super.startElement(uri,name,raw,attr);
  +
  +        //if (uri.equals("")) {
  +        //    uri = (String)this.getNS();
  +        //}
  +        //this.pushNS(uri);
  +        super.startElement(uri, name, raw, attr);
       }
   
       public void endElement(String uri, String name, String raw) throws SAXException {
  -        if (last_xmlbase_element_uri.equals(uri) && last_xmlbase_element_name.equals(name))
{
  -            endXMLBaseAttribute();
  -        }
           if (uri != null && name != null && uri.equals(XINCLUDE_NAMESPACE_URI)
&& name.equals(XINCLUDE_INCLUDE_ELEMENT)) {
               return;
           }
  +        //super.endElement((String)this.popNS(),name,raw);
           super.endElement(uri,name,raw);
       }
   
  +    //private void startElem(String namespaceURI, String prefix, String name) throws SAXException
{
  +    //    this.pushNS(namespaceURI);
  +    //    AttributesImpl attrs = new AttributesImpl();
  +    //    String qname = name;
  +    //    if (!namespaceURI.equals("")) {
  +    //        super.startPrefixMapping(prefix, namespaceURI);
  +    //        if (!prefix.equals("")) {
  +    //            attrs.addAttribute("", prefix, "xmlns:" + prefix, "CDATA", namespaceURI);
  +    //        } else {
  +    //            attrs.addAttribute("", "xmlns", "xmlns", "CDATA", namespaceURI);
  +    //        }
  +    //    }
  +    //    super.startElement(namespaceURI, name, name, attrs);
  +    //}
  +
  +    //private void endElem(String prefix, String name) throws SAXException {
  +    //    String ns = this.popNS();
  +    //    super.endElement(ns, name, name);
  +    //    if (!ns.equals("")) {
  +    //        super.endPrefixMapping(prefix);
  +    //    }
  +    //}
  +
  +    //private String pushNS(String ns) {
  +    //    currentNS.add(ns);
  +    //    return ns;
  +    //}
  +
  +    //private String popNS() {
  +    //    int last = currentNS.size()-1;
  +    //    String ns = (String)currentNS.get(last);
  +    //    currentNS.remove(last);
  +    //    return ns;
  +    //}
  +
  +    //private String getNS() {
  +    //    int last = currentNS.size()-1;
  +    //    return (String)currentNS.get(last);
  +    //}
  +
       public void setDocumentLocator(Locator locator) {
  -        try {
  -            base_xmlbase_uri = urlFactory.getURL(locator.getSystemId());
  -            if (current_xmlbase_uri == null) {
  -                current_xmlbase_uri = base_xmlbase_uri;
  -            }
  -        } catch (MalformedURLException e) {getLogger().debug("XIncludeSAXConnector", e);}
           super.setDocumentLocator(locator);
       }
  -
  -    protected void startXMLBaseAttribute(String uri, String name, String value) throws
MalformedURLException {
  -        if (current_xmlbase_uri != null) {
  -            xmlbase_stack.push(current_xmlbase_uri);
  -        }
  -        current_xmlbase_uri = urlFactory.getURL(value);
  -
  -        xmlbase_element_uri_stack.push(last_xmlbase_element_uri);
  -        last_xmlbase_element_uri = uri;
  -
  -        xmlbase_element_name_stack.push(last_xmlbase_element_name);
  -        last_xmlbase_element_name = name;
  -    }
   
  -    protected void endXMLBaseAttribute() {
  -        if (xmlbase_stack.size() > 0) {
  -            current_xmlbase_uri = (URL)xmlbase_stack.pop();
  -        } else {
  -            current_xmlbase_uri = base_xmlbase_uri;
  -        }
  -        last_xmlbase_element_uri = (String)xmlbase_element_uri_stack.pop();
  -        last_xmlbase_element_name = (String)xmlbase_element_name_stack.pop();
  -    }
  +    protected void processXIncludeElement(String src, String element, String ns, String
prefix) 
  +        throws SAXException,MalformedURLException,IOException {
   
  -    protected void processXIncludeElement(String href) throws SAXException,MalformedURLException,IOException
{
           ComponentSelector selector = null;
           Sitemap sitemap = null;
           EventPipeline eventPipeline = null;
  @@ -174,19 +166,30 @@
           try {
               selector = (ComponentSelector) manager.lookup(Roles.SERVERPAGES);
               sitemap = (Sitemap) selector.select("sitemap");
  -            getLogger().debug("Processing XInclude element: href="+href+", sitemap="+sitemap);
  +            getLogger().debug("Processing XInclude element: src=" + src 
  +                                + ", sitemap=" + sitemap
  +                                + ", element=" + element
  +                                + ", ns=" + ns
  +                                + ", prefix=" + prefix);
   
               eventPipeline = (EventPipeline)this.manager.lookup(Roles.EVENT_PIPELINE);
               pipeline = (StreamPipeline)this.manager.lookup(Roles.STREAM_PIPELINE);
               pipeline.setEventPipeline(eventPipeline);
   
  -            ((XMLProducer)eventPipeline).setConsumer(this);
  +            IncludeXMLConsumer consumer = new IncludeXMLConsumer(this);
   
  -            this.environment.pushURI(href);
  +            //if (!element.equals(""))
  +            //    this.startElem(ns, prefix, element);
  +
  +            ((XMLProducer)eventPipeline).setConsumer(consumer);
  +
  +            this.environment.pushURI(src);
               sitemap.process(this.environment, pipeline, eventPipeline);
               eventPipeline.process(this.environment);
               this.environment.popURI();
   
  +            //if (!element.equals(""))
  +            //    this.endElem(prefix, element);
           } catch (Exception e) {
               getLogger().error("Error selecting sitemap",e);
           } finally {
  @@ -201,10 +204,14 @@
                   this.manager.release((Component)pipeline);
           }
       }
  +
  +    public void dispose() {
  +    }
   
  -    public void dispose()
  -    {
  -        if(this.urlFactory != null)
  -            this.manager.release((Component)this.urlFactory);
  +    /**
  +     * Recycle the producer by removing references
  +     */
  +    public void recycle () {
  +        //this.currentNS.clear();
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +92 -49    xml-cocoon/src/org/apache/cocoon/xml/Attic/IncludeXMLConsumer.java
  
  Index: IncludeXMLConsumer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/xml/Attic/IncludeXMLConsumer.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- IncludeXMLConsumer.java	2000/12/22 18:08:59	1.1.2.1
  +++ IncludeXMLConsumer.java	2001/04/25 13:51:34	1.1.2.2
  @@ -11,6 +11,7 @@
   import org.xml.sax.ContentHandler;
   import org.xml.sax.Locator;
   import org.xml.sax.SAXException;
  +import org.xml.sax.ext.LexicalHandler;
   
   /**
    * A special purpose <code>XMLConsumer</code> used for including files.
  @@ -18,56 +19,98 @@
    * </code>endDocument</code> messages.
    *
    * @author <a href="mailto:bloritsch@apache.org>Berin Loritsch</a>
  - * @version $Revision: 1.1.2.1 $ $Date: 2000/12/22 18:08:59 $
  + * @version $Revision: 1.1.2.2 $ $Date: 2001/04/25 13:51:34 $
    */
   public class IncludeXMLConsumer extends AbstractXMLConsumer {
  -      final private ContentHandler contentHandler;
  +    final private ContentHandler contentHandler;
  +    final private LexicalHandler lexicalHandler;
   
  -      public IncludeXMLConsumer (ContentHandler parentHandler) {
  -          this.contentHandler = parentHandler;
  -      }
  -
  -      public void setDocumentLocator(Locator loc) {
  -          this.contentHandler.setDocumentLocator(loc);
  -      }
  -
  -      public void startDocument() throws SAXException {
  -          // Ignored
  -      }
  -
  -      public void endDocument() throws SAXException {
  -          // Ignored
  -      }
  -
  -      public void startPrefixMapping(String prefix, String uri) throws SAXException {
  -          this.contentHandler.startPrefixMapping(prefix, uri);
  -      }
  -
  -      public void endPrefixMapping(String prefix) throws SAXException {
  -          this.contentHandler.endPrefixMapping(prefix);
  -      }
  -
  -      public void startElement(String uri, String local, String qName, Attributes attr)
throws SAXException {
  -          this.contentHandler.startElement(uri, local, qName, attr);
  -      }
  -
  -      public void endElement(String uri, String local, String qName) throws SAXException
{
  -          this.contentHandler.endElement(uri, local, qName);
  -      }
  -
  -      public void characters(char[] ch, int start, int end) throws SAXException {
  -          this.contentHandler.characters(ch, start, end);
  -      }
  -
  -      public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException
{
  -          this.contentHandler.ignorableWhitespace(ch, start, end);
  -      }
  -
  -      public void processingInstruction(String name, String value) throws SAXException
{
  -          this.processingInstruction(name, value);
  -      }
  -
  -      public void skippedEntity(String ent) throws SAXException {
  -          this.skippedEntity(ent);
  -      }
  +    public IncludeXMLConsumer (XMLConsumer consumer) {
  +        this.contentHandler = (ContentHandler)consumer;
  +        this.lexicalHandler = (LexicalHandler)consumer;
  +    }
  +
  +    public IncludeXMLConsumer (ContentHandler contentHandler, LexicalHandler lexicalHandler)
{
  +        this.contentHandler = contentHandler;
  +        this.lexicalHandler = lexicalHandler;
  +    }
  +
  +    public IncludeXMLConsumer (ContentHandler contentHandler) {
  +        this.contentHandler = contentHandler;
  +        this.lexicalHandler = null;
  +    }
  +
  +    public void setDocumentLocator(Locator loc) {
  +        this.contentHandler.setDocumentLocator(loc);
  +    }
  +
  +    public void startDocument() throws SAXException {
  +        // Ignored
  +    }
  +
  +    public void endDocument() throws SAXException {
  +        // Ignored
  +    }
  +
  +    public void startPrefixMapping(String prefix, String uri) throws SAXException {
  +        this.contentHandler.startPrefixMapping(prefix, uri);
  +    }
  +
  +    public void endPrefixMapping(String prefix) throws SAXException {
  +        this.contentHandler.endPrefixMapping(prefix);
  +    }
  +
  +    public void startElement(String uri, String local, String qName, Attributes attr) throws
SAXException {
  +        this.contentHandler.startElement(uri, local, qName, attr);
  +    }
  +
  +    public void endElement(String uri, String local, String qName) throws SAXException
{
  +        this.contentHandler.endElement(uri, local, qName);
  +    }
  +
  +    public void characters(char[] ch, int start, int end) throws SAXException {
  +        this.contentHandler.characters(ch, start, end);
  +    }
  +
  +    public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException
{
  +        this.contentHandler.ignorableWhitespace(ch, start, end);
  +    }
  +
  +    public void processingInstruction(String name, String value) throws SAXException {
  +        this.processingInstruction(name, value);
  +    }
  +
  +    public void skippedEntity(String ent) throws SAXException {
  +        this.skippedEntity(ent);
  +    }
  +
  +    public void startDTD(String name, String public_id, String system_id)
  +        throws SAXException {
  +        lexicalHandler.startDTD(name,public_id,system_id);
  +    }
  +
  +    public void endDTD() throws SAXException {
  +        lexicalHandler.endDTD();
  +    }
  +
  +    public void startEntity(String name) throws SAXException {
  +        lexicalHandler.startEntity(name);
  +    }
  +
  +    public void endEntity(String name) throws SAXException {
  +        lexicalHandler.endEntity(name);
  +    }
  +
  +    public void startCDATA() throws SAXException {
  +        lexicalHandler.startCDATA();
  +    }
  +
  +    public void endCDATA() throws SAXException {
  +        lexicalHandler.endCDATA();
  +    }
  +
  +    public void comment(char ary[], int start, int length)
  +        throws SAXException {
  +        lexicalHandler.comment(ary,start,length);
  +    }
   }
  
  
  

----------------------------------------------------------------------
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