santiagopg    2002/12/17 07:27:24

  Modified:    java/src/org/apache/xalan/xsltc/cmdline Compile.java
               java/src/org/apache/xalan/xsltc/compiler Mode.java
                        StepPattern.java xpath.cup
               java/src/org/apache/xalan/xsltc/runtime/output
                        StreamHTMLOutput.java StreamOutput.java
                        StreamTextOutput.java StreamXMLOutput.java
  Log:
  Changes:
  
   - Fixed matching problem reported by Ivelin Ivanov (Cocoon).
   - Added support for namespaces when output is HTML.
   - Set new version of XSLTC to be 1.4.0.
  
  Revision  Changes    Path
  1.14      +3 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Compile.java
  
  Index: Compile.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Compile.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Compile.java      17 Sep 2002 22:01:25 -0000      1.13
  +++ Compile.java      17 Dec 2002 15:27:23 -0000      1.14
  @@ -82,8 +82,8 @@
   
       // Versioning numbers  for the compiler -v option output
       private static int VERSION_MAJOR = 1;
  -    private static int VERSION_MINOR = 2;
  -    private static int VERSION_DELTA = 1;
  +    private static int VERSION_MINOR = 4;
  +    private static int VERSION_DELTA = 0;
    
   
       // This variable should be set to false to prevent any methods in this 
  
  
  
  1.26      +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java
  
  Index: Mode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Mode.java 29 Oct 2002 17:23:51 -0000      1.25
  +++ Mode.java 17 Dec 2002 15:27:23 -0000      1.26
  @@ -423,7 +423,7 @@
                _patternGroups[kernelType];
        }
   
  -     if (patterns == null) {
  +     if (patterns.size() == 0) {
            patterns.addElement(pattern);
        }
        else {
  
  
  
  1.19      +11 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- StepPattern.java  29 Oct 2002 17:23:51 -0000      1.18
  +++ StepPattern.java  17 Dec 2002 15:27:23 -0000      1.19
  @@ -87,6 +87,8 @@
       private boolean _isEpsilon = false;
       private int     _contextCase;
   
  +    private double  _priority = Double.MAX_VALUE;
  +
       public StepPattern(int axis, int nodeType, Vector predicates) {
        _axis = axis;
        _nodeType = nodeType;
  @@ -108,6 +110,10 @@
       public int getNodeType() {
        return _nodeType;
       }
  +
  +    public void setPriority(double priority) {
  +     _priority = priority;
  +    }
       
       public StepPattern getKernelPattern() {
        return this;
  @@ -127,6 +133,10 @@
       }
   
       public double getDefaultPriority() {
  +     if (_priority != Double.MAX_VALUE) {
  +         return _priority;
  +     }
  +
        if (hasPredicates()) {
            return 0.5;
        }
  
  
  
  1.45      +86 -14    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup
  
  Index: xpath.cup
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- xpath.cup 29 Oct 2002 17:23:51 -0000      1.44
  +++ xpath.cup 17 Dec 2002 15:27:23 -0000      1.45
  @@ -129,6 +129,84 @@
             _xsltc.setCallsNodeset(flag);
       }
   
  +    /**
  +     * This method is similar to findNodeType(int, Object) except that it
  +     * creates a StepPattern instead of just returning a node type. It also 
  +     * differs in the way it handles "{uri}:*" and "{uri}:@*". The last two 
  +     * patterns are expanded as "*[namespace-uri() = 'uri']" and 
  +     * "@*[namespace-uri() = 'uri']", respectively. This expansion 
considerably 
  +     * simplifies the grouping of patterns in the Mode class. For this
  +     * expansion to be correct, the priority of the pattern/template must be
  +     * set to -0.25 (when no other predicates are present).
  +     */
  +    public StepPattern createStepPattern(int axis, Object test, Vector 
predicates) {
  +     int nodeType;
  +
  +     if (test == null) {  // "*"
  +         nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE : 
  +             (axis == Axis.NAMESPACE) ? -1 : NodeTest.ELEMENT;
  +
  +         return new StepPattern(axis, nodeType, predicates);
  +        }
  +        else if (test instanceof Integer) {
  +         nodeType = ((Integer) test).intValue();
  +
  +         return new StepPattern(axis, nodeType, predicates);
  +        }
  +        else {
  +         QName name = (QName)test;
  +         boolean setPriority = false;
  +
  +         if (axis == Axis.NAMESPACE) {
  +             nodeType = (name.toString().equals("*")) ? -1
  +                             : _xsltc.registerNamespace(name);
  +            }
  +         else {
  +             final String uri = name.getNamespace();
  +             final String local = name.getLocalPart();
  +             final QName namespace_uri = 
  +                 _parser.getQNameIgnoreDefaultNs("namespace-uri");
  +
  +             // Expand {uri}:* to *[namespace-uri() = 'uri'] - same for @*
  +             if (uri != null && (local.equals("*") || local.equals("@*"))) {
  +                 if (predicates == null) {
  +                     predicates = new Vector(2);
  +                 }
  +
  +                 // Priority is set by hand if no other predicates exist
  +                 setPriority = (predicates.size() == 0);
  +
  +                 predicates.add(
  +                     new Predicate(
  +                         new EqualityExpr(Operators.EQ, 
  +                             new NamespaceUriCall(namespace_uri), 
  +                             new LiteralExpr(uri))));
  +             }
  +
  +             if (local.equals("*")) {
  +                 nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
  +                     : NodeTest.ELEMENT;
  +             }
  +             else if (local.equals("@*")) {
  +                 nodeType = NodeTest.ATTRIBUTE;
  +             }
  +             else {
  +                 nodeType = (axis == Axis.ATTRIBUTE) ? 
_xsltc.registerAttribute(name)
  +                     : _xsltc.registerElement(name); 
  +             }
  +         }
  +
  +         final StepPattern result = new StepPattern(axis, nodeType, 
predicates); 
  +
  +         // Set priority for case prefix:* and prefix:@* (no predicates)
  +         if (setPriority) {
  +             result.setPriority(-0.25);
  +         }
  +
  +         return result;
  +     }
  +    }
  +
       public int findNodeType(int axis, Object test) {
        if (test == null) {  // *
            return (axis == Axis.ATTRIBUTE) ? 
  @@ -353,16 +431,12 @@
   
   StepPattern ::= NodeTestPattern:nt
               {: 
  -             final int nodeType = parser.findNodeType(Axis.CHILD, nt);
  -             RESULT = new StepPattern(
  -                  (nodeType == NodeTest.ATTRIBUTE) ? Axis.ATTRIBUTE : 
Axis.CHILD,
  -                  nodeType, null);
  +             RESULT = parser.createStepPattern(Axis.CHILD, nt, null);
               :}
   
               | NodeTestPattern:nt Predicates:pp
  -            {: RESULT = new StepPattern(Axis.CHILD,
  -                                        parser.findNodeType(Axis.CHILD, nt),
  -                                        pp);
  +            {: 
  +             RESULT = parser.createStepPattern(Axis.CHILD, nt, pp);
               :}
   
               | ProcessingInstructionPattern:pip
  @@ -372,16 +446,14 @@
               {: RESULT = (ProcessingInstructionPattern)pip.setPredicates(pp); 
:}
   
               | ChildOrAttributeAxisSpecifier:axis NodeTestPattern:nt
  -            {: RESULT=new StepPattern(axis.intValue(),
  -                                      parser.findNodeType(axis.intValue(), 
nt),
  -                                      null);
  +            {: 
  +            RESULT = parser.createStepPattern(axis.intValue(), nt, null);
               :}
   
            | ChildOrAttributeAxisSpecifier:axis
                  NodeTestPattern:nt Predicates:pp
  -            {: RESULT = new StepPattern(axis.intValue(),
  -                                        
parser.findNodeType(axis.intValue(),nt),
  -                                        pp);
  +            {: 
  +            RESULT = parser.createStepPattern(axis.intValue(), nt, pp);
               :}
   
               | ChildOrAttributeAxisSpecifier:axis 
ProcessingInstructionPattern:pip
  
  
  
  1.20      +4 -6      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java
  
  Index: StreamHTMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- StreamHTMLOutput.java     7 Nov 2002 20:07:52 -0000       1.19
  +++ StreamHTMLOutput.java     17 Dec 2002 15:27:24 -0000      1.20
  @@ -99,6 +99,7 @@
        super(output);
        _buffer = new WriterOutputBuffer(_writer);
        setIndent(true);  // default for HTML
  +     initNamespaces();
   // System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
  @@ -106,6 +107,7 @@
        super(writer, encoding);
        _buffer = new WriterOutputBuffer(_writer);
        setIndent(true);  // default for HTML
  +     initNamespaces();
   //System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
  @@ -115,6 +117,7 @@
        super(out, encoding);
        _buffer = new WriterOutputBuffer(_writer);
        setIndent(true);  // default for HTML
  +     initNamespaces();
   //System.out.println("StreamHTMLOutput.<init> this = " + this);
       }
   
  @@ -301,11 +304,6 @@
        catch (Exception e) {
            // ignore
        }
  -    }
  -
  -    public void namespace(String prefix, String uri) throws 
TransletException 
  -    { 
  -     // ignore when method type is HTML
       }
   
       public void setCdataElements(Hashtable elements) { 
  
  
  
  1.23      +71 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java
  
  Index: StreamOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- StreamOutput.java 7 Nov 2002 20:07:52 -0000       1.22
  +++ StreamOutput.java 17 Dec 2002 15:27:24 -0000      1.23
  @@ -74,6 +74,7 @@
   import java.util.Hashtable;
   
   import org.apache.xalan.xsltc.TransletException;
  +import org.apache.xalan.xsltc.runtime.BasisLibrary;
   
   abstract public class StreamOutput extends OutputBase {
   
  @@ -314,5 +315,74 @@
            _buffer.append(' ');
        }
        _buffer.append("-->");
  +    }
  +
  +    public void namespace(final String prefix, final String uri)
  +     throws TransletException 
  +    {
  +// System.out.println("namespace prefix = " + prefix + " uri = " + uri);
  +     final String escaped = escapeString(uri);
  +
  +     if (_startTagOpen) {
  +         if (pushNamespace(prefix, escaped)) {
  +             if (prefix != null && prefix != EMPTYSTRING) {
  +                 // Ignore if not default NS and if uri is ""
  +                 if (escaped.length() > 0) {
  +                     _buffer.append(' ').append(XMLNS_PREFIX)
  +                            .append(':').append(prefix)
  +                            .append("=\"").append(escaped).append('"');
  +                 }
  +             }
  +             else {
  +                 _buffer.append(' ').append(XMLNS_PREFIX)
  +                        .append("=\"").append(escaped).append('"');
  +             }
  +
  +         }
  +     }
  +     else if (prefix != EMPTYSTRING || uri != EMPTYSTRING) {
  +         BasisLibrary.runTimeError(BasisLibrary.STRAY_NAMESPACE_ERR,
  +                                   prefix, escaped);
  +     }
  +    }
  +
  +    /**
  +     * This method escapes special characters used in attribute values
  +     */
  +    protected String escapeString(String value) {
  +     final char[] ch = value.toCharArray();
  +     final int limit = ch.length;
  +     StringBuffer result = new StringBuffer();
  +     
  +     int offset = 0;
  +     for (int i = 0; i < limit; i++) {
  +         switch (ch[i]) {
  +         case '&':
  +             result.append(ch, offset, i - offset).append(AMP);
  +             offset = i + 1;
  +             break;
  +         case '"':
  +             result.append(ch, offset, i - offset).append(QUOT);
  +             offset = i + 1;
  +             break;
  +         case '<':
  +             result.append(ch, offset, i - offset).append(LT);
  +             offset = i + 1;
  +             break;
  +         case '>':
  +             result.append(ch, offset, i - offset).append(GT);
  +             offset = i + 1;
  +             break;
  +         case '\n':
  +             result.append(ch, offset, i - offset).append(CRLF);
  +             offset = i + 1;
  +             break;
  +         }
  +     }
  +
  +     if (offset < limit) {
  +         result.append(ch, offset, limit - offset);
  +     }
  +     return result.toString();
       }
   }
  
  
  
  1.4       +6 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamTextOutput.java
  
  Index: StreamTextOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamTextOutput.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StreamTextOutput.java     10 Sep 2002 15:25:05 -0000      1.3
  +++ StreamTextOutput.java     17 Dec 2002 15:27:24 -0000      1.4
  @@ -123,5 +123,10 @@
        throws TransletException
       {
       }
  +
  +    public void namespace(final String prefix, final String uri)
  +     throws TransletException 
  +    {
  +    }
   }
   
  
  
  
  1.22      +1 -70     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java
  
  Index: StreamXMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- StreamXMLOutput.java      9 Oct 2002 19:19:20 -0000       1.21
  +++ StreamXMLOutput.java      17 Dec 2002 15:27:24 -0000      1.22
  @@ -291,35 +291,6 @@
        return temp; 
       }
   
  -   public void namespace(final String prefix, final String uri)
  -     throws TransletException 
  -    {
  -// System.out.println("namespace prefix = " + prefix + " uri = " + uri);
  -     final String escaped = escapeString(uri);
  -
  -     if (_startTagOpen) {
  -         if (pushNamespace(prefix, escaped)) {
  -             if (prefix != null && prefix != EMPTYSTRING) {
  -                 // Ignore if not default NS and if uri is ""
  -                 if (escaped.length() > 0) {
  -                     _buffer.append(' ').append(XMLNS_PREFIX)
  -                            .append(':').append(prefix)
  -                            .append("=\"").append(escaped).append('"');
  -                 }
  -             }
  -             else {
  -                 _buffer.append(' ').append(XMLNS_PREFIX)
  -                        .append("=\"").append(escaped).append('"');
  -             }
  -
  -         }
  -     }
  -     else if (prefix != EMPTYSTRING || uri != EMPTYSTRING) {
  -         BasisLibrary.runTimeError(BasisLibrary.STRAY_NAMESPACE_ERR,
  -                                   prefix, escaped);
  -     }
  -    }
  -
       protected void closeStartTag() throws TransletException {
        super.closeStartTag();
   
  @@ -401,46 +372,6 @@
        if (offset < limit) {
            _buffer.append(ch, offset, limit - offset);
        }
  -    }
  -
  -    /**
  -     * This method escapes special characters used in attribute values
  -     */
  -    private String escapeString(String value) {
  -     final char[] ch = value.toCharArray();
  -     final int limit = ch.length;
  -     StringBuffer result = new StringBuffer();
  -     
  -     int offset = 0;
  -     for (int i = 0; i < limit; i++) {
  -         switch (ch[i]) {
  -         case '&':
  -             result.append(ch, offset, i - offset).append(AMP);
  -             offset = i + 1;
  -             break;
  -         case '"':
  -             result.append(ch, offset, i - offset).append(QUOT);
  -             offset = i + 1;
  -             break;
  -         case '<':
  -             result.append(ch, offset, i - offset).append(LT);
  -             offset = i + 1;
  -             break;
  -         case '>':
  -             result.append(ch, offset, i - offset).append(GT);
  -             offset = i + 1;
  -             break;
  -         case '\n':
  -             result.append(ch, offset, i - offset).append(CRLF);
  -             offset = i + 1;
  -             break;
  -         }
  -     }
  -
  -     if (offset < limit) {
  -         result.append(ch, offset, limit - offset);
  -     }
  -     return result.toString();
       }
   
       /**
  
  
  

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

Reply via email to