morten      01/09/17 01:20:55

  Modified:    java/src/org/apache/xalan/xsltc/compiler LiteralElement.java
                        Param.java ParameterRef.java
                        ParentLocationPath.java Variable.java
                        VariableBase.java VariableRef.java
               java/src/org/apache/xalan/xsltc/dom DOMImpl.java
                        MatchingIterator.java ReverseIterator.java
                        StepIterator.java
               java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
                        TextOutput.java
               java/src/org/apache/xalan/xsltc/trax DOM2SAX.java
  Log:
  Several bugfixes and fixes for regressions recently introduced by other
  bugfixes.
  PR:           n/a
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.11      +11 -11    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
  
  Index: LiteralElement.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LiteralElement.java       2001/08/14 11:51:26     1.10
  +++ LiteralElement.java       2001/09/17 08:20:54     1.11
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LiteralElement.java,v 1.10 2001/08/14 11:51:26 morten Exp $
  + * @(#)$Id: LiteralElement.java,v 1.11 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -360,16 +360,6 @@
        il.append(DUP2); // duplicate these 2 args for endElement
        il.append(methodGen.startElement());
   
  -     // Output all attributes
  -     if (_attributeElements != null) {
  -         final int count = _attributeElements.size();
  -         for (int i = 0; i < count; i++) {
  -             SyntaxTreeNode node = 
  -                 (SyntaxTreeNode)_attributeElements.elementAt(i);
  -             node.translate(classGen, methodGen);
  -         }
  -     }
  -
        // Compile code to emit namespace attributes
        if (_accessedPrefixes != null) {
            Enumeration e = _accessedPrefixes.keys();
  @@ -383,6 +373,16 @@
                    il.append(new PUSH(cpg,uri));
                    il.append(methodGen.namespace());
                }
  +         }
  +     }
  +
  +     // Output all attributes
  +     if (_attributeElements != null) {
  +         final int count = _attributeElements.size();
  +         for (int i = 0; i < count; i++) {
  +             SyntaxTreeNode node = 
  +                 (SyntaxTreeNode)_attributeElements.elementAt(i);
  +             node.translate(classGen, methodGen);
            }
        }
        
  
  
  
  1.12      +1 -26     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java
  
  Index: Param.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Param.java        2001/08/28 12:43:08     1.11
  +++ Param.java        2001/09/17 08:20:54     1.12
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Param.java,v 1.11 2001/08/28 12:43:08 morten Exp $
  + * @(#)$Id: Param.java,v 1.12 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -173,31 +173,6 @@
        // element itself does not).
        return Type.Void;
       }
  -
  -    /**
  -     * Compile the value of the parameter, which is either in an expression 
in
  -     * a 'select' attribute, or in the parameter element's body
  -     */
  -    public void translateValue(ClassGenerator classGen,
  -                            MethodGenerator methodGen) {
  -     // Compile expression is 'select' attribute if present
  -     if (_select != null) {
  -         _select.translate(classGen, methodGen);
  -         _type.translateBox(classGen, methodGen);
  -         _select.startResetIterator(classGen, methodGen);
  -     }
  -     // If not, compile result tree from parameter body if present.
  -     else if (hasContents()) {
  -         compileResultTree(classGen, methodGen);
  -     }
  -     // If neither are present then store empty string in parameter slot
  -     else {
  -         final ConstantPoolGen cpg = classGen.getConstantPool();
  -         final InstructionList il = methodGen.getInstructionList();
  -         il.append(new PUSH(cpg, Constants.EMPTYSTRING));
  -     }
  -    }
  -
   
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
   
  
  
  
  1.7       +3 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParameterRef.java
  
  Index: ParameterRef.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParameterRef.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ParameterRef.java 2001/08/28 12:43:08     1.6
  +++ ParameterRef.java 2001/09/17 08:20:54     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ParameterRef.java,v 1.6 2001/08/28 12:43:08 morten Exp $
  + * @(#)$Id: ParameterRef.java,v 1.7 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -82,8 +82,8 @@
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final InstructionList il = methodGen.getInstructionList();
  -             
  -     String name = _variable.getVariable();
  +
  +     final String name = _variable.getVariable();
   
        if (_variable.isLocal()) {
            if (classGen.isExternal()) {
  
  
  
  1.6       +1 -10     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java
  
  Index: ParentLocationPath.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParentLocationPath.java   2001/09/13 12:30:15     1.5
  +++ ParentLocationPath.java   2001/09/17 08:20:54     1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ParentLocationPath.java,v 1.5 2001/09/13 12:30:15 tmiller Exp $
  + * @(#)$Id: ParentLocationPath.java,v 1.6 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -122,15 +122,6 @@
        }
        return(false);
       }
  -
  -    /*
  -    public void blockIteratorReset() {
  -     if (_path instanceof RelativeLocationPath)
  -         ((RelativeLocationPath)_path).blockIteratorReset();
  -     if (_step instanceof Step)
  -         ((Step)_step).blockIteratorReset();
  -    }
  -    */
   
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
        final ConstantPoolGen cpg = classGen.getConstantPool();
  
  
  
  1.16      +1 -24     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java
  
  Index: Variable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Variable.java     2001/09/12 14:30:46     1.15
  +++ Variable.java     2001/09/17 08:20:54     1.16
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Variable.java,v 1.15 2001/09/12 14:30:46 morten Exp $
  + * @(#)$Id: Variable.java,v 1.16 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -209,29 +209,6 @@
            else
                il.append(new ACONST_NULL()); // and 'null' for anything else
            il.append(_type.STORE(_local.getIndex()));
  -     }
  -    }
  -
  -    /**
  -     * Compile the value of the variable, which is either in an expression in
  -     * a 'select' attribute, or in the variable elements body
  -     */
  -    public void translateValue(ClassGenerator classGen,
  -                            MethodGenerator methodGen) {
  -     // Compile expression is 'select' attribute if present
  -     if (_select != null) {
  -         _select.translate(classGen, methodGen);
  -         _select.startResetIterator(classGen, methodGen);
  -     }
  -     // If not, compile result tree from parameter body if present.
  -     else if (hasContents()) {
  -         compileResultTree(classGen, methodGen);
  -     }
  -     // If neither are present then store empty string in variable
  -     else {
  -         final ConstantPoolGen cpg = classGen.getConstantPool();
  -         final InstructionList il = methodGen.getInstructionList();
  -         il.append(new PUSH(cpg, Constants.EMPTYSTRING));
        }
       }
   
  
  
  
  1.4       +24 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java
  
  Index: VariableBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VariableBase.java 2001/08/28 12:43:08     1.3
  +++ VariableBase.java 2001/09/17 08:20:54     1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: VariableBase.java,v 1.3 2001/08/28 12:43:08 morten Exp $
  + * @(#)$Id: VariableBase.java,v 1.4 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -234,6 +234,29 @@
        */
       public boolean isLocal() {
        return _isLocal;
  +    }
  +
  +    /**
  +     * Compile the value of the variable, which is either in an expression in
  +     * a 'select' attribute, or in the variable elements body
  +     */
  +    public void translateValue(ClassGenerator classGen,
  +                            MethodGenerator methodGen) {
  +     // Compile expression is 'select' attribute if present
  +     if (_select != null) {
  +         _select.translate(classGen, methodGen);
  +         _select.startResetIterator(classGen, methodGen);
  +     }
  +     // If not, compile result tree from parameter body if present.
  +     else if (hasContents()) {
  +         compileResultTree(classGen, methodGen);
  +     }
  +     // If neither are present then store empty string in variable
  +     else {
  +         final ConstantPoolGen cpg = classGen.getConstantPool();
  +         final InstructionList il = methodGen.getInstructionList();
  +         il.append(new PUSH(cpg, Constants.EMPTYSTRING));
  +     }
       }
   
   }
  
  
  
  1.8       +3 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java
  
  Index: VariableRef.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- VariableRef.java  2001/08/28 12:43:08     1.7
  +++ VariableRef.java  2001/09/17 08:20:54     1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: VariableRef.java,v 1.7 2001/08/28 12:43:08 morten Exp $
  + * @(#)$Id: VariableRef.java,v 1.8 2001/09/17 08:20:54 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -102,12 +102,12 @@
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final InstructionList il = methodGen.getInstructionList();
                
  -     String name = _variable.getVariable();
  -
        if (_type.implementedAsMethod()) {
            // Fall-through for variables that are implemented as methods
            return;
        }
  +
  +     final String name = _variable.getVariable();
   
        if (_variable.isLocal()) {
            if (classGen.isExternal() || _escaped) {
  
  
  
  1.25      +11 -5     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
  
  Index: DOMImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DOMImpl.java      2001/09/12 14:56:00     1.24
  +++ DOMImpl.java      2001/09/17 08:20:55     1.25
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOMImpl.java,v 1.24 2001/09/12 14:56:00 morten Exp $
  + * @(#)$Id: DOMImpl.java,v 1.25 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -1438,7 +1438,12 @@
            }
            return END;
        }
  -    
  +
  +     public NodeIterator reset() {
  +         _source.reset();
  +         return this;
  +     }
  +
        public void setMark() {
            _source.setMark();
        }
  @@ -1743,7 +1748,7 @@
        * Returns the (String) value of any node in the tree
        */
       public String getNodeValue(final int node) {
  -     if (node == NULL) return EMPTYSTRING;
  +     if ((node == NULL) || (node > _treeNodeLimit)) return EMPTYSTRING;
        switch(_type[node]) {
        case ROOT:
            return getNodeValue(_offsetOrChild[node]);
  @@ -2460,8 +2465,9 @@
             child != NULL;
             child = _nextSibling[child]) {
            switch (_type[child]) {
  -         case TEXT:
            case COMMENT:
  +             break;
  +         case TEXT:
                buffer.append(_text,
                              _offsetOrChild[child],
                              _lengthOrAttr[child]);
  @@ -2898,7 +2904,7 @@
            shiftAttributes(_currentNode);
            resizeArrays(_currentNode + _currentAttributeNode, _currentNode);
            appendAttributes();
  -         _treeNodeLimit = _currentNode;
  +         _treeNodeLimit = _currentNode + _currentAttributeNode;
   
            // Fill the _namespace[] and _uriArray[] array
            _namespace = new short[namesSize];
  
  
  
  1.2       +5 -4      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/MatchingIterator.java
  
  Index: MatchingIterator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/MatchingIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MatchingIterator.java     2001/04/17 18:52:32     1.1
  +++ MatchingIterator.java     2001/09/17 08:20:55     1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: MatchingIterator.java,v 1.1 2001/04/17 18:52:32 sboag Exp $
  + * @(#)$Id: MatchingIterator.java,v 1.2 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -69,7 +69,7 @@
   public final class MatchingIterator extends NodeIteratorBase {
       private NodeIterator _source;
       private final int    _match;
  -    private int _matchPos, _matchLast = -1;
  +    private int          _matchPos, _matchLast = -1;
        
       public MatchingIterator(int match, NodeIterator source) {
        _source = source;
  @@ -92,7 +92,7 @@
       public NodeIterator setStartNode(int node) {
        if (_isRestartable) {
            // iterator is not a clone
  -         _source.setStartNode(_startNode = node);
  +         _source.setStartNode(node);
   
            // Calculate the position of the node in the set
            final int match = _match;
  @@ -107,7 +107,8 @@
       }
   
       public NodeIterator reset() {
  -     return this;    // should not be called
  +     _source.reset();
  +     return this;
       }
       
       public int next() {
  
  
  
  1.3       +7 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/ReverseIterator.java
  
  Index: ReverseIterator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/ReverseIterator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReverseIterator.java      2001/08/14 12:50:13     1.2
  +++ ReverseIterator.java      2001/09/17 08:20:55     1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ReverseIterator.java,v 1.2 2001/08/14 12:50:13 morten Exp $
  + * @(#)$Id: ReverseIterator.java,v 1.3 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -98,11 +98,15 @@
                _data[_last++] = node;
            }
        }
  +     _startNode = _current = _last;
  +     return this;
  +    }
   
  -     _current = _last;
  +    public NodeIterator reset() {
  +     _current = _startNode;
        return this;
       }
  -     
  +
       public int getPosition() {
        return (_last - _current);
       }
  
  
  
  1.4       +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/StepIterator.java
  
  Index: StepIterator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/StepIterator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StepIterator.java 2001/08/16 12:06:45     1.3
  +++ StepIterator.java 2001/09/17 08:20:55     1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StepIterator.java,v 1.3 2001/08/16 12:06:45 morten Exp $
  + * @(#)$Id: StepIterator.java,v 1.4 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -105,7 +105,7 @@
       }
   
       public NodeIterator reset() {
  -     _source.setStartNode(_startNode);
  +     //_source.setStartNode(_startNode);
        _source.reset();
        int node = _source.next();
        _iterator.setStartNode(node);
  
  
  
  1.13      +2 -6      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
  
  Index: BasisLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BasisLibrary.java 2001/08/27 09:07:21     1.12
  +++ BasisLibrary.java 2001/09/17 08:20:55     1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: BasisLibrary.java,v 1.12 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: BasisLibrary.java,v 1.13 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -89,11 +89,7 @@
        * Standard function count(node-set)
        */
       public static int countF(NodeIterator iterator) {
  -     int counter = 0;
  -     while (iterator.next() != NodeIterator.END) {
  -         ++counter;
  -     }
  -     return counter;
  +     return(iterator.getLast());
       }
   
       /**
  
  
  
  1.28      +35 -16    
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java
  
  Index: TextOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- TextOutput.java   2001/09/12 12:23:04     1.27
  +++ TextOutput.java   2001/09/17 08:20:55     1.28
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TextOutput.java,v 1.27 2001/09/12 12:23:04 morten Exp $
  + * @(#)$Id: TextOutput.java,v 1.28 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -461,7 +461,7 @@
            // Output escaped characters if required. Non-ASCII characters
               // within HTML attributes should _NOT_ be escaped.
            else if (_escapeChars) {
  -             if (_outputType == HTML) {
  +             if ((_outputType == HTML) && (!_qnameStack.isEmpty())) {
                    final String qname = (String)_qnameStack.peek();
                    if ((qname.equals("style")) || (qname.equals("script"))) {
                        _saxHandler.characters(ch, off, len);
  @@ -520,7 +520,6 @@
   
            _qnameStack.push(elementName);
   
  -         // bug fix 2807, <[EMAIL PROTECTED]>
            if (_cdata != null) {
                if (_cdata.get(elementName) != null) {
                    _cdataStack.push(new Integer(_depth));
  @@ -596,30 +595,50 @@
        if (_startTagOpen) {
   
            // URL-encode href attributes in HTML output
  -         if ((_outputType == HTML) && (name.equals("href"))) {
  -             _attributes.add(name, URLEncoder.encode(value));
  -             return;
  +         if (_outputType == HTML) {
  +             if  (name.toLowerCase().equals("href")) {
  +                 if (value.startsWith("http")) {
  +                     _attributes.add(name, URLEncoder.encode(value));
  +                     return;
  +                 }
  +             }
            }
   
            // Intercept namespace declarations and handle them separately
  -         if (name.startsWith("xmlns")) {
  -             if (name.length() == 5)
  -                 namespace(EMPTYSTRING,value);
  -             else
  -                 namespace(name.substring(6),value);
  +         if (name.startsWith("xml")) {
  +             if (name.startsWith("xmlns")) {
  +                 if (name.length() == 5)
  +                     namespace(EMPTYSTRING, value);
  +                 else
  +                     namespace(name.substring(6),value);
  +             }
  +             else {
  +                 namespace(name, value);
  +             }
            }
            else {
  -             final int col = name.lastIndexOf(':');
  -             if (col > 0) {
  -                 final String prefix = name.substring(0,col);
  -                 final String localname = name.substring(col+1);
  +             // If this attribute was created using an <xsl:attribute>
  +             // element with a 'namespace' attribute and a 'name' attribute
  +             // containing an AVT, then we might get an attribute name on
  +             // a strange format like 'prefix1:prefix2:localpart', where
  +             // prefix1 is from the AVT and prefix2 from the namespace.
  +             final int endcol = name.lastIndexOf(':');
  +             final int startcol = name.indexOf(':');
  +             if (endcol > 0) {
  +                 final String localname = name.substring(endcol+1);
  +                 final String prefix = name.substring(0,startcol);
                    final String uri = lookupNamespace(prefix);
                    if (uri == null) {
                        throw new TransletException("Namespace for prefix "+
                                                    prefix+" has not been "+
                                                    "declared.");
                    }
  -                 if (uri.equals(EMPTYSTRING)) name = localname;
  +                 // Omit prefix (use default) if the namespace URI is null
  +                 if (uri.equals(EMPTYSTRING))
  +                     name = localname;
  +                 // Construct new QName if we've got two alt. prefixes
  +                 else if (endcol != startcol)
  +                     name = prefix+':'+localname;
                }
                if (_outputType == HTML)
                    _attributes.add(name, value);
  
  
  
  1.7       +96 -102   
xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java
  
  Index: DOM2SAX.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/DOM2SAX.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DOM2SAX.java      2001/08/03 13:32:37     1.6
  +++ DOM2SAX.java      2001/09/17 08:20:55     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOM2SAX.java,v 1.6 2001/08/03 13:32:37 tmiller Exp $
  + * @(#)$Id: DOM2SAX.java,v 1.7 2001/09/17 08:20:55 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -81,31 +81,38 @@
   import org.w3c.dom.Entity;
   import org.w3c.dom.Notation;
   
  +import org.apache.xalan.xsltc.runtime.AttributeList;
  +
   public class DOM2SAX implements XMLReader , Locator {
       private Document _dom = null;
  -    private ContentHandler _contentHdlr = null;
  +    private ContentHandler _sax = null;
    
       public DOM2SAX(Node root) {
        _dom = (Document)root;
       }
   
       public ContentHandler getContentHandler() { 
  -     return _contentHdlr;
  +     return _sax;
       }
  +
       public DTDHandler getDTDHandler() { 
        return null;
       }
  +
       public ErrorHandler getErrorHandler() {
        return null;
       }
  +
       public boolean getFeature(String name) throws SAXNotRecognizedException,
        SAXNotSupportedException
       {
        return false;
       }
  +
       public void setFeature(String name, boolean value) throws 
        SAXNotRecognizedException, SAXNotSupportedException 
       {
  +     
       }
   
       public void parse(InputSource unused) throws IOException, SAXException {
  @@ -113,82 +120,69 @@
           parse(currNode);
       }
   
  -    private void parse(Node currNode) throws IOException, SAXException {
  +    private void parse(Node node) throws IOException, SAXException {
           Node first = null;
  -     if (currNode == null ) return;
  +     if (node == null ) return;
   
  -        switch (currNode.getNodeType()) {
  -            case Node.ATTRIBUTE_NODE :
  -                    break;
  -            case Node.CDATA_SECTION_NODE :
  -                    break;
  -            case Node.COMMENT_NODE :
  -                    break;
  -            case Node.DOCUMENT_FRAGMENT_NODE :
  -                    break;
  -            case Node.DOCUMENT_NODE :
  -                    _contentHdlr.setDocumentLocator(this);
  -                    _contentHdlr.startDocument();
  -                    Node next = currNode.getFirstChild();
  -                    while ( next != null ) {
  -                        parse(next);
  -                        next = next.getNextSibling();
  -                    }
  -                    _contentHdlr.endDocument();
  -                    break;
  -            case Node.DOCUMENT_TYPE_NODE :
  -                    break;
  -            case Node.ELEMENT_NODE :
  -                    AttributesImpl attrList = new AttributesImpl();
  -                    NamedNodeMap map = currNode.getAttributes();
  -                    int length = map.getLength();
  -                    for (int i=0; i<length; i++ ){
  -                        Node attrNode = map.item(i);
  -                        short code = attrNode.getNodeType();
  -                        attrList.addAttribute(attrNode.getNamespaceURI(),
  -                            attrNode.getLocalName(),
  -                            attrNode.getNodeName(),
  -                            getNodeTypeFromCode(code),  // must be better way
  -                            attrNode.getNodeValue());
  -                    }
  -                    _contentHdlr.startElement(currNode.getNamespaceURI(),
  -                        currNode.getLocalName(), currNode.getNodeName(),
  -                        attrList);
  -                    next = currNode.getFirstChild();
  -                    while ( next != null ) {
  -                        parse(next);
  -                        next = next.getNextSibling();
  -                    }
  -                    _contentHdlr.endElement(currNode.getNamespaceURI(),
  -                        currNode.getLocalName(), currNode.getNodeName());
  -                    break;
  -            case Node.ENTITY_NODE :
  -                    //Entity edecl = (Entity)currNode;
  -                    //String name = edecl.getNotationName();
  -                    //if ( name != null ) {
  -                    //   
_contentHdlr.unparsedEntityDecl(currNode.getNodeName(),
  -                    //      edecl.getPublicId(), edecl.getSystemId(), name);
  -                    //}
  -                    break;
  -             case Node.ENTITY_REFERENCE_NODE :
  -                    break;
  -             case Node.NOTATION_NODE :
  -                    //Notation ndecl = (Notation)currNode;
  -                    //_contentHdlr.notationDecl(currNode.getNodeName(),
  -                     //   ndecl.getPublicId(), ndecl.getSystemId());
  -                    break;
  -             case Node.PROCESSING_INSTRUCTION_NODE :
  -                    
_contentHdlr.processingInstruction(currNode.getNodeName(),
  -                        currNode.getNodeValue());
  -                    break;
  -             case Node.TEXT_NODE :
  -                    String data = currNode.getNodeValue();
  -                    length = data.length();
  -                    char[] array = new char[length];
  -                    data.getChars(0, length, array, 0);
  -                    _contentHdlr.characters(array, 0, length);
  -                    break;
  -            }
  +        switch (node.getNodeType()) {
  +     case Node.ATTRIBUTE_NODE:         // handled by ELEMENT_NODE
  +     case Node.COMMENT_NODE:           // should be handled!!!
  +     case Node.CDATA_SECTION_NODE:
  +     case Node.DOCUMENT_FRAGMENT_NODE:
  +     case Node.DOCUMENT_TYPE_NODE :
  +     case Node.ENTITY_NODE :
  +     case Node.ENTITY_REFERENCE_NODE:
  +     case Node.NOTATION_NODE :
  +         // These node types are ignored!!!
  +         break;
  +
  +     case Node.DOCUMENT_NODE:
  +         _sax.setDocumentLocator(this);
  +         _sax.startDocument();
  +         Node next = node.getFirstChild();
  +         while (next != null) {
  +             parse(next);
  +             next = next.getNextSibling();
  +         }
  +         _sax.endDocument();
  +         break;
  +
  +     case Node.ELEMENT_NODE:
  +         // Gather all attribute node of the element
  +         AttributeList attrs = new AttributeList();
  +         NamedNodeMap map = node.getAttributes();
  +         int length = map.getLength();
  +         for (int i=0; i<length; i++ ) {
  +             Node attr = map.item(i);
  +             attrs.add(attr.getNodeName(), attr.getNodeValue());
  +         }
  +
  +         // Generate SAX event to start element
  +         _sax.startElement(node.getNamespaceURI(), node.getLocalName(),
  +                           node.getNodeName(), attrs);
  +
  +         // Traverse all child nodes of the element (if any)
  +         next = node.getFirstChild();
  +         while ( next != null ) {
  +             parse(next);
  +             next = next.getNextSibling();
  +         }
  +
  +         // Generate SAX event to close element
  +         _sax.endElement(node.getNamespaceURI(),
  +                                 node.getLocalName(), node.getNodeName());
  +         break;
  +
  +     case Node.PROCESSING_INSTRUCTION_NODE:
  +         _sax.processingInstruction(node.getNodeName(),
  +                                    node.getNodeValue());
  +         break;
  +
  +     case Node.TEXT_NODE:
  +         final String data = node.getNodeValue();
  +         _sax.characters(data.toCharArray(), 0, data.length());
  +         break;
  +     }
       }
   
       public void parse(String sysId) throws IOException, SAXException {
  @@ -198,7 +192,7 @@
        NullPointerException 
       {
        if (handler == null ) throw new NullPointerException();
  -     _contentHdlr = handler;
  +     _sax = handler;
       }
       public void setDTDHandler(DTDHandler handler) throws 
NullPointerException {
        if (handler == null )  throw new NullPointerException();
  @@ -236,30 +230,30 @@
       private String getNodeTypeFromCode(short code) {
        String retval = null;
        switch (code) {
  -                case Node.ATTRIBUTE_NODE : 
  -                 retval = "ATTRIBUTE_NODE"; break; 
  -                case Node.CDATA_SECTION_NODE :
  -                 retval = "CDATA_SECTION_NODE"; break; 
  -                case Node.COMMENT_NODE :
  -                 retval = "COMMENT_NODE"; break; 
  -                case Node.DOCUMENT_FRAGMENT_NODE :
  -                 retval = "DOCUMENT_FRAGMENT_NODE"; break; 
  -                case Node.DOCUMENT_NODE :
  -                 retval = "DOCUMENT_NODE"; break; 
  -                case Node.DOCUMENT_TYPE_NODE :
  -                 retval = "DOCUMENT_TYPE_NODE"; break; 
  -                case Node.ELEMENT_NODE :
  -                 retval = "ELEMENT_NODE"; break; 
  -                case Node.ENTITY_NODE :
  -                 retval = "ENTITY_NODE"; break; 
  -                case Node.ENTITY_REFERENCE_NODE :
  -                 retval = "ENTITY_REFERENCE_NODE"; break; 
  -                case Node.NOTATION_NODE :
  -                 retval = "NOTATION_NODE"; break; 
  -                case Node.PROCESSING_INSTRUCTION_NODE :
  -                 retval = "PROCESSING_INSTRUCTION_NODE"; break; 
  -                case Node.TEXT_NODE:
  -                 retval = "TEXT_NODE"; break; 
  +     case Node.ATTRIBUTE_NODE : 
  +         retval = "ATTRIBUTE_NODE"; break; 
  +     case Node.CDATA_SECTION_NODE :
  +         retval = "CDATA_SECTION_NODE"; break; 
  +     case Node.COMMENT_NODE :
  +         retval = "COMMENT_NODE"; break; 
  +     case Node.DOCUMENT_FRAGMENT_NODE :
  +         retval = "DOCUMENT_FRAGMENT_NODE"; break; 
  +     case Node.DOCUMENT_NODE :
  +         retval = "DOCUMENT_NODE"; break; 
  +     case Node.DOCUMENT_TYPE_NODE :
  +         retval = "DOCUMENT_TYPE_NODE"; break; 
  +     case Node.ELEMENT_NODE :
  +         retval = "ELEMENT_NODE"; break; 
  +     case Node.ENTITY_NODE :
  +         retval = "ENTITY_NODE"; break; 
  +     case Node.ENTITY_REFERENCE_NODE :
  +         retval = "ENTITY_REFERENCE_NODE"; break; 
  +     case Node.NOTATION_NODE :
  +         retval = "NOTATION_NODE"; break; 
  +     case Node.PROCESSING_INSTRUCTION_NODE :
  +         retval = "PROCESSING_INSTRUCTION_NODE"; break; 
  +     case Node.TEXT_NODE:
  +         retval = "TEXT_NODE"; break; 
           }
        return retval;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to