cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/transformation AbstractSAXTransformer.java
Date Sat, 09 Aug 2003 19:48:54 GMT
cziegeler    2003/08/09 12:48:54

  Modified:    src/java/org/apache/cocoon/transformation
                        AbstractSAXTransformer.java
  Log:
  Better namespace support for own transformers
  
  Revision  Changes    Path
  1.5       +72 -6     cocoon-2.1/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
  
  Index: AbstractSAXTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractSAXTransformer.java	19 Jun 2003 11:19:25 -0000	1.4
  +++ AbstractSAXTransformer.java	9 Aug 2003 19:48:54 -0000	1.5
  @@ -197,9 +197,11 @@
        */
       protected AttributesImpl emptyAttributes = new AttributesImpl();
   
  -    /** The namespaces */
  +    /** The namespaces and their prefixes */
       private List namespaces = new ArrayList(5);
  -
  +    /** The current prefix for our namespace */
  +    private String ourPrefix;
  +    
       /**
        * Avalon Configurable Interface
        */
  @@ -270,6 +272,7 @@
           this.parameters = null;
           this.source = null;
           this.namespaces.clear();
  +        this.ourPrefix = null;
       }
   
       /**
  @@ -739,6 +742,20 @@
        * Send SAX events to the next pipeline component.
        * The startElement event for the given element is send
        * to the next component in the current pipeline.
  +     * The element has the namespace of the transformer,
  +     * but not attributes
  +     * @param localname The name of the event.
  +     */
  +    public void sendStartElementEventNS(String localname)
  +    throws SAXException {
  +        this.startElement(this.namespaceURI, 
  +                          localname, this.ourPrefix+':' + localname, emptyAttributes);
  +    }
  +
  +    /**
  +     * Send SAX events to the next pipeline component.
  +     * The startElement event for the given element is send
  +     * to the next component in the current pipeline.
        * The element has no namespace.
        * @param localname The name of the event.
        * @param attr The Attributes of the element
  @@ -750,6 +767,20 @@
   
       /**
        * Send SAX events to the next pipeline component.
  +     * The startElement event for the given element is send
  +     * to the next component in the current pipeline.
  +     * The element has the namespace of the transformer.
  +     * @param localname The name of the event.
  +     * @param attr The Attributes of the element
  +     */
  +    public void sendStartElementEventNS(String localname, Attributes attr)
  +    throws SAXException {
  +        this.startElement(this.namespaceURI, 
  +                          localname, this.ourPrefix+':' + localname, attr);
  +    }
  +
  +    /**
  +     * Send SAX events to the next pipeline component.
        * The endElement event for the given element is send
        * to the next component in the current pipeline.
        * The element has no namespace.
  @@ -762,6 +793,19 @@
   
       /**
        * Send SAX events to the next pipeline component.
  +     * The endElement event for the given element is send
  +     * to the next component in the current pipeline.
  +     * The element has the namespace of the transformer.
  +     * @param localname The name of the event.
  +     */
  +    public void sendEndElementEventNS(String localname)
  +    throws SAXException {
  +        this.endElement(this.namespaceURI,
  +                         localname, this.ourPrefix+':' + localname);
  +    }
  +
  +    /**
  +     * Send SAX events to the next pipeline component.
        * The node is parsed and the events are send to
        * the next component in the pipeline.
        * @param node The tree to be included.
  @@ -854,6 +898,9 @@
       public void startPrefixMapping(String prefix, String uri)
       throws SAXException {
           if (prefix != null) this.namespaces.add(new String[] {prefix, uri});
  +        if ( this.namespaceURI != null && this.namespaceURI.equals(uri)) {
  +            this.ourPrefix = prefix;
  +        }
           if (this.ignoreEventsCount == 0) super.startPrefixMapping(prefix, uri);
       }
   
  @@ -868,18 +915,37 @@
               int l = this.namespaces.size();
               int i = l-1;
               String currentPrefix;
  -            while (found == false && i >= 0) {
  +            while (!found && i >= 0) {
                   currentPrefix = ((String[])this.namespaces.get(i))[0];
  -                if (currentPrefix.equals(prefix) == true) {
  +                if (currentPrefix.equals(prefix)) {
                       found = true;
                   } else {
                       i--;
                   }
               }
  -            if (found == false) {
  +            if (!found) {
                   throw new SAXException("Namespace for prefix '"+ prefix + "' not found.");
               }
               this.namespaces.remove(i);
  +            if ( prefix.equals(this.ourPrefix) ) {
  +                this.ourPrefix = null;
  +                // now search if we have a different prefix for our namespace
  +                found = false;
  +                l = this.namespaces.size();
  +                i = l-1;
  +                String currentNS;
  +                while (!found && i >= 0) {
  +                    currentNS = ((String[])this.namespaces.get(i))[1];
  +                    if (currentNS.equals(this.namespaceURI)) {
  +                        found = true;
  +                    } else {
  +                        i--;
  +                    }
  +                }
  +                if ( found ) {
  +                    this.ourPrefix = ((String[])this.namespaces.get(i))[0];
  +                }
  +            }
           }
           if (this.ignoreEventsCount == 0) super.endPrefixMapping(prefix);
       }
  
  
  

Mime
View raw message