garyp       00/11/17 12:37:13

  Modified:    java/src/org/apache/xalan/processor
                        ProcessorPreserveSpace.java
                        ProcessorStripSpace.java
               java/src/org/apache/xalan/templates Stylesheet.java
                        StylesheetComposed.java TemplateList.java
                        TemplateSubPatternAssociation.java
                        WhiteSpaceInfo.java
  Log:
  Process templates and whitespace stripping with proper precedence.
  
  Revision  Changes    Path
  1.5       +19 -1     
xml-xalan/java/src/org/apache/xalan/processor/ProcessorPreserveSpace.java
  
  Index: ProcessorPreserveSpace.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorPreserveSpace.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProcessorPreserveSpace.java       2000/11/13 16:26:50     1.4
  +++ ProcessorPreserveSpace.java       2000/11/17 20:37:11     1.5
  @@ -58,6 +58,9 @@
   
   import javax.xml.transform.TransformerException;
   import org.xml.sax.Attributes;
  +import org.apache.xalan.templates.Stylesheet;
  +import org.apache.xalan.templates.WhiteSpaceInfo;
  +import org.apache.xpath.XPath;
   
   import java.util.Vector;
   
  @@ -118,7 +121,22 @@
             StylesheetHandler handler, String uri, String localName, String 
rawName, Attributes attributes)
               throws org.xml.sax.SAXException
     {
  +
       setPropertiesFromAttributes(handler, rawName, attributes, this);
  -    handler.getStylesheet().setPreserveSpaces(getElements());
  +
  +    Stylesheet thisSheet = handler.getStylesheet();
  +    Vector xpaths = getElements();
  +
  +    for (int i = 0; i < xpaths.size(); i++)
  +    {
  +      WhiteSpaceInfo wsi = new WhiteSpaceInfo((XPath) xpaths.elementAt(i), 
false, thisSheet);
  +
  +      // We do the push and pop here to force StylesheetHandler to assign us 
a Uid.
  +
  +      handler.pushElemTemplateElement(wsi);
  +      wsi = (WhiteSpaceInfo) handler.popElemTemplateElement();
  +
  +      thisSheet.setPreserveSpaces(wsi);
  +    }
     }
   }
  
  
  
  1.5       +20 -1     
xml-xalan/java/src/org/apache/xalan/processor/ProcessorStripSpace.java
  
  Index: ProcessorStripSpace.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorStripSpace.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProcessorStripSpace.java  2000/11/13 16:26:50     1.4
  +++ ProcessorStripSpace.java  2000/11/17 20:37:11     1.5
  @@ -58,6 +58,9 @@
   
   import javax.xml.transform.TransformerException;
   import org.xml.sax.Attributes;
  +import org.apache.xalan.templates.Stylesheet;
  +import org.apache.xalan.templates.WhiteSpaceInfo;
  +import org.apache.xpath.XPath;
   
   import java.util.Vector;
   
  @@ -93,6 +96,22 @@
               throws org.xml.sax.SAXException
     {
       setPropertiesFromAttributes(handler, rawName, attributes, this);
  -    handler.getStylesheet().setStripSpaces(getElements());
  +
  +    Stylesheet thisSheet = handler.getStylesheet();
  +    Vector xpaths = getElements();
  +
  +    for (int i = 0; i < xpaths.size(); i++)
  +    {
  +      WhiteSpaceInfo wsi = new WhiteSpaceInfo((XPath) xpaths.elementAt(i), 
true, thisSheet);
  +
  +      // We do the push and pop here to force StylesheetHandler to assign us 
a Uid
  +      // like a real ElementTemplateElement.
  +
  +      handler.pushElemTemplateElement(wsi);
  +      wsi = (WhiteSpaceInfo) handler.popElemTemplateElement();
  +
  +      thisSheet.setStripSpaces(wsi);
  +    }
  +
     }
   }
  
  
  
  1.14      +10 -24    
xml-xalan/java/src/org/apache/xalan/templates/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/Stylesheet.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Stylesheet.java   2000/11/13 16:27:11     1.13
  +++ Stylesheet.java   2000/11/17 20:37:11     1.14
  @@ -651,22 +651,15 @@
      *
      * NEEDSDOC @param v
      */
  -  public void setStripSpaces(Vector v)
  +  public void setStripSpaces(WhiteSpaceInfo wsi)
     {
   
       if (null == m_whitespaceStrippingElements)
       {
  -      m_whitespaceStrippingElements = v;
  +      m_whitespaceStrippingElements = new Vector();
       }
  -    else
  -    {
  -      int n = v.size();
   
  -      for (int i = 0; i < n; i++)
  -      {
  -        m_whitespaceStrippingElements.addElement(v.elementAt(i));
  -      }
  -    }
  +    m_whitespaceStrippingElements.addElement(wsi);
     }
   
     /**
  @@ -679,13 +672,13 @@
      *
      * @throws ArrayIndexOutOfBoundsException
      */
  -  public XPath getStripSpace(int i) throws ArrayIndexOutOfBoundsException
  +  public WhiteSpaceInfo getStripSpace(int i) throws 
ArrayIndexOutOfBoundsException
     {
   
       if (null == m_whitespaceStrippingElements)
         throw new ArrayIndexOutOfBoundsException();
   
  -    return (XPath) m_whitespaceStrippingElements.elementAt(i);
  +    return (WhiteSpaceInfo) m_whitespaceStrippingElements.elementAt(i);
     }
   
     /**
  @@ -712,22 +705,15 @@
      *
      * NEEDSDOC @param v
      */
  -  public void setPreserveSpaces(Vector v)
  +  public void setPreserveSpaces(WhiteSpaceInfo wsi)
     {
   
       if (null == m_whitespacePreservingElements)
       {
  -      m_whitespacePreservingElements = v;
  +      m_whitespacePreservingElements = new Vector();
       }
  -    else
  -    {
  -      int n = v.size();
   
  -      for (int i = 0; i < n; i++)
  -      {
  -        m_whitespacePreservingElements.addElement(v.elementAt(i));
  -      }
  -    }
  +    m_whitespacePreservingElements.addElement(wsi);
     }
   
     /**
  @@ -740,13 +726,13 @@
      *
      * @throws ArrayIndexOutOfBoundsException
      */
  -  public XPath getPreserveSpace(int i) throws ArrayIndexOutOfBoundsException
  +  public WhiteSpaceInfo getPreserveSpace(int i) throws 
ArrayIndexOutOfBoundsException
     {
   
       if (null == m_whitespacePreservingElements)
         throw new ArrayIndexOutOfBoundsException();
   
  -    return (XPath) m_whitespacePreservingElements.elementAt(i);
  +    return (WhiteSpaceInfo) m_whitespacePreservingElements.elementAt(i);
     }
   
     /**
  
  
  
  1.18      +3 -7      
xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java
  
  Index: StylesheetComposed.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- StylesheetComposed.java   2000/11/15 18:09:02     1.17
  +++ StylesheetComposed.java   2000/11/17 20:37:11     1.18
  @@ -348,9 +348,7 @@
           if (null == m_whiteSpaceInfoList)
             m_whiteSpaceInfoList = new WhitespaceList(this);
   
  -        XPath match = included.getStripSpace(i);
  -
  -        m_whiteSpaceInfoList.setTemplate(new WhiteSpaceInfo(match, true), 
i+k);
  +        m_whiteSpaceInfoList.setTemplate(included.getStripSpace(i));
         }
   
         n = included.getPreserveSpaceCount();
  @@ -359,10 +357,8 @@
         {
           if (null == m_whiteSpaceInfoList)
             m_whiteSpaceInfoList = new WhitespaceList(this);
  -
  -        XPath match = included.getPreserveSpace(i);
   
  -        m_whiteSpaceInfoList.setTemplate(new WhiteSpaceInfo(match, false), 
i+k);
  +        m_whiteSpaceInfoList.setTemplate(included.getPreserveSpace(i));
         }
       }
     }
  @@ -689,7 +685,7 @@
         for (int i = 0; i < n; i++)
         {
           ElemTemplate template = included.getTemplate(i);
  -        m_templateList.setTemplate(template, template.getUid());
  +        m_templateList.setTemplate(template);
         }
       }
   
  
  
  
  1.21      +16 -11    
xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java
  
  Index: TemplateList.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TemplateList.java 2000/11/15 18:09:02     1.20
  +++ TemplateList.java 2000/11/17 20:37:11     1.21
  @@ -99,7 +99,7 @@
      *
      * @param template
      */
  -  public void setTemplate(ElemTemplate template, int pos)
  +  public void setTemplate(ElemTemplate template)
     {
       if (null != template.getName())
       {
  @@ -122,7 +122,7 @@
   
         if (matchExpr instanceof StepPattern)
         {
  -        insertPatternInTable((StepPattern) matchExpr, template, pos);
  +        insertPatternInTable((StepPattern) matchExpr, template);
         }
         else if (matchExpr instanceof UnionPattern)
         {
  @@ -132,7 +132,7 @@
   
           for (int i = 0; i < n; i++)
           {
  -          insertPatternInTable(pats[i], template, pos);
  +          insertPatternInTable(pats[i], template);
           }
         }
         else
  @@ -247,13 +247,12 @@
     {
   
       // Sort first by decreasing priority (highest priority is at front),
  +    // then by import level (higher level is at front),
       // then by document order (later in document is at front).
  -    // GLP:  This routine sorts by the document order obtained by 
getDocOrderPos() on
  -    //       the item.  However, this is only the sequence within the 
individual
  -    //       sheet, not within a composed sheet.  This needs to be fixed.
   
       double priority = getPriorityOrScore(item);
       double workPriority;
  +    int importLevel = item.getImportLevel();
       int docOrder = item.getDocOrderPos();
       TemplateSubPatternAssociation insertPoint = head;
       TemplateSubPatternAssociation next;
  @@ -283,8 +282,12 @@
             break;
           else if (priority < workPriority)
             insertPoint = next;
  -        else if (docOrder >= next.getDocOrderPos())      // priorities are 
equal
  +        else if (importLevel > next.getImportLevel())   // priorities are 
equal
             break;
  +        else if (importLevel < next.getImportLevel())
  +          insertPoint = next;
  +        else if (docOrder >= next.getDocOrderPos())     // priorities, 
import are equal
  +          break;
           else
             insertPoint = next;
         }
  @@ -297,6 +300,10 @@
           insertBefore = true;
         else if (priority < workPriority)
           insertBefore = false;
  +      else if (importLevel > insertPoint.getImportLevel())
  +        insertBefore = true;
  +      else if (importLevel < insertPoint.getImportLevel())
  +        insertBefore = false;
         else if (docOrder >= insertPoint.getDocOrderPos())
           insertBefore = true;
         else
  @@ -352,10 +359,8 @@
      *
      * @param pattern
      * @param template
  -   * @param pos
      */
  -  private void insertPatternInTable(StepPattern pattern,
  -                                    ElemTemplate template, int pos)
  +  private void insertPatternInTable(StepPattern pattern, ElemTemplate 
template)
     {
   
       String target = pattern.getTargetString();
  @@ -364,7 +369,7 @@
       {
         String pstring = template.getMatch().getPatternString();
         TemplateSubPatternAssociation association =
  -        new TemplateSubPatternAssociation(template, pattern, pstring, pos);
  +        new TemplateSubPatternAssociation(template, pattern, pstring);
   
         // See if there's already one there
         boolean isWildCard = association.isWild();
  
  
  
  1.6       +19 -14    
xml-xalan/java/src/org/apache/xalan/templates/TemplateSubPatternAssociation.java
  
  Index: TemplateSubPatternAssociation.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateSubPatternAssociation.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TemplateSubPatternAssociation.java        2000/11/13 16:27:11     1.5
  +++ TemplateSubPatternAssociation.java        2000/11/17 20:37:11     1.6
  @@ -77,9 +77,6 @@
     /** NEEDSDOC Field m_stepPattern          */
     StepPattern m_stepPattern;
   
  -  /** NEEDSDOC Field m_posInStylesheet          */
  -  private int m_posInStylesheet;
  -
     /** NEEDSDOC Field m_pattern          */
     private String m_pattern;
   
  @@ -100,15 +97,12 @@
      * @param template The node that contains the template for this pattern.
      * @param pattern An executable XSLT StepPattern.
      * @param pat For now a Nodelist that contains old-style element patterns.
  -   * @param posInStylesheet The document-order position of the template in 
the stylesheet.
      */
  -  TemplateSubPatternAssociation(ElemTemplate template, StepPattern pattern,
  -                                String pat, int posInStylesheet)
  +  TemplateSubPatternAssociation(ElemTemplate template, StepPattern pattern, 
String pat)
     {
   
       m_pattern = pat;
       m_template = template;
  -    m_posInStylesheet = posInStylesheet;
       m_stepPattern = pattern;
       m_targetString = m_stepPattern.getTargetString();
       m_wild = m_targetString.equals("*");
  @@ -223,25 +217,36 @@
     }
   
     /**
  +   * Get the pattern string for diagnostic purposes.
  +   *
  +   * @return The pattern string for diagnostic purposes.
  +   *
  +   */
  +  public String getPattern()
  +  {
  +    return m_pattern;
  +  }
  +
  +  /**
      * Return the position of the template in document
      * order in the stylesheet.
      *
  -   * @return The position of the template in stylesheet.
  +   * @return The position of the template in the overall template order.
      */
     public int getDocOrderPos()
     {
  -    return m_posInStylesheet;
  +    return m_template.getUid();
     }
   
     /**
  -   * Get the pattern string for diagnostic purposes.
  +   * Return the import level associated with the stylesheet into which  
  +   * this template is composed.
      *
  -   * @return The pattern string for diagnostic purposes.
  -   *
  +   * @return The import level of this template.
      */
  -  public String getPattern()
  +  public int getImportLevel()
     {
  -    return m_pattern;
  +    return m_template.getStylesheetComposed().getImportCountComposed();
     }
   
     /**
  
  
  
  1.4       +3 -1      
xml-xalan/java/src/org/apache/xalan/templates/WhiteSpaceInfo.java
  
  Index: WhiteSpaceInfo.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/WhiteSpaceInfo.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WhiteSpaceInfo.java       2000/10/30 18:50:07     1.3
  +++ WhiteSpaceInfo.java       2000/11/17 20:37:11     1.4
  @@ -88,11 +88,13 @@
      * NEEDSDOC @param matchPattern
      * NEEDSDOC @param shouldStripSpace
      */
  -  WhiteSpaceInfo(XPath matchPattern, boolean shouldStripSpace)
  +  public WhiteSpaceInfo(XPath matchPattern, boolean shouldStripSpace, 
Stylesheet thisSheet)
     {
   
       m_shouldStripSpace = shouldStripSpace;
   
       setMatch(matchPattern);
  +
  +    setStylesheet(thisSheet);
     }
   }
  
  
  

Reply via email to