sboag       99/12/15 13:53:08

  Modified:    src/org/apache/xalan/xpath/xml ElemDesc.java
                        FormatterToHTML.java FormatterToXML.java
               src/org/apache/xalan/xslt FuncDocument.java
                        XSLTEngineImpl.java
  Log:
  Several output related bugs fixed (including Stefano's quote in the attribute 
bug).  NSPC19 bug fixed also.
  
  Revision  Changes    Path
  1.2       +11 -10    xml-xalan/src/org/apache/xalan/xpath/xml/ElemDesc.java
  
  Index: ElemDesc.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/ElemDesc.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElemDesc.java     1999/12/13 07:40:11     1.1
  +++ ElemDesc.java     1999/12/15 21:53:07     1.2
  @@ -65,24 +65,24 @@
     
     static final int EMPTY = (1 << 1);
     static final int FLOW = (1 << 2);
  -  static final int BLOCK = (1 << 3)|FLOW;
  +  static final int BLOCK = (1 << 3);
     static final int BLOCKFORM = (1 << 4);
     static final int BLOCKFORMFIELDSET = (1 << 5);
     static final int CDATA = (1 << 6);
     static final int PCDATA = (1 << 7);
     static final int RAW = (1 << 8);
  -  static final int INLINE = (1 << 9)|FLOW;
  +  static final int INLINE = (1 << 9);
     static final int INLINEA = (1 << 10);
     static final int INLINELABEL = (1 << 11);
  -  static final int FONTSTYLE = (1 << 12)|INLINE|INLINEA|INLINELABEL;
  -  static final int PHRASE = (1 << 13)|INLINE|INLINEA|INLINELABEL;
  -  static final int FORMCTRL = (1 << 14)|INLINE|INLINEA;
  -  static final int SPECIAL = (1 << 15)|INLINE|INLINELABEL;
  -  static final int ASPECIAL = (1 << 16)|INLINEA;
  +  static final int FONTSTYLE = (1 << 12);
  +  static final int PHRASE = (1 << 13);
  +  static final int FORMCTRL = (1 << 14);
  +  static final int SPECIAL = (1 << 15);
  +  static final int ASPECIAL = (1 << 16);
     static final int HEADMISC = (1 << 17);
  -  static final int HEAD = (1 << 18)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
  -  static final int LIST = (1 << 19)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
  -  static final int PREFORMATTED = (1 << 
20)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
  +  static final int HEAD = (1 << 18);
  +  static final int LIST = (1 << 19);
  +  static final int PREFORMATTED = (1 << 20);
     static final int WHITESPACESENSITIVE = (1 << 21);
   
     static final int ATTRURL = (1 << 1);
  @@ -95,6 +95,7 @@
     
     boolean is(int flags)
     {
  +    int which = (m_flags & flags);
       return (m_flags & flags) != 0;
     }
     
  
  
  
  1.16      +38 -80    
xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToHTML.java
  
  Index: FormatterToHTML.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToHTML.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FormatterToHTML.java      1999/12/15 16:25:13     1.15
  +++ FormatterToHTML.java      1999/12/15 21:53:07     1.16
  @@ -238,6 +238,9 @@
       elemDesc = (ElemDesc)m_elementFlags.get("BLOCKQUOTE");
       elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
   
  +    elemDesc = (ElemDesc)m_elementFlags.get("Q");
  +    elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
  +
       elemDesc = (ElemDesc)m_elementFlags.get("INS");
       elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
   
  @@ -624,13 +627,16 @@
       for (int i = 0;  i < len;  i ++)
       {
         char ch = stringArray[i];
  -      int b1 = (int)((((int)ch) & MASK1) >> 8);
         // if first 8 bytes are 0, no need to append them.
  -      if (b1 != 0)
  +      if ((ch < 9) || (ch > 127) || (ch == '"'))
         {       
  +        int b1 = (int)((((int)ch) & MASK1) >> 8);
           int b2 = (int)(((int)ch) & MASK2);
  -        accum("%");
  -        accum(Integer.toHexString(b1));
  +        if(b1 != 0)
  +        {
  +          accum("%");
  +          accum(Integer.toHexString(b1));
  +        }
           accum("%");
           accum(Integer.toHexString(b2));              
         }      
  @@ -653,12 +659,13 @@
     public void writeAttrString(String string, String encoding)
       throws SAXException
     {
  -    int strLen = string.length();
  -    // char chars[] = string.toCharArray();
  +    // int strLen = string.length();
  +    char chars[] = string.toCharArray();
  +    int strLen = chars.length;
       for (int i = 0;  i < strLen;  i ++)
       {
         // char ch = chars[i];
  -      char ch = string.charAt(i);
  +      char ch = chars[i];
         if((ch < SPECIALSSIZE) && (m_attrCharsMap[ch] != 'S'))
         {
           accum(ch);
  @@ -667,82 +674,33 @@
         {
           accum(ch); // no escaping in this case, as specified in 15.2
         }
  -      else if (0xd800 <= ch && ch < 0xdc00) 
  +      else if (!accumDefaultEntity(ch, i, chars, strLen, false))
         {
  -        // UTF-16 surrogate
  -        int next;
  -        if (i+1 >= string.length()) 
  -        {
  -          throw new SAXException("Invalid UTF-16 surrogate detected: "
  -            +Integer.toHexString(ch)+ " ?");
  -        }
  -        else 
  +        if (0xd800 <= ch && ch < 0xdc00) 
           {
  -          next = string.charAt(++i);
  -          if (!(0xdc00 <= next && next < 0xe000))
  +          // UTF-16 surrogate
  +          int next;
  +          if (i+1 >= string.length()) 
  +          {
               throw new SAXException("Invalid UTF-16 surrogate detected: "
  -              +Integer.toHexString(ch)+" "+Integer.toHexString(next));
  -          next = ((ch-0xd800)<<10)+next-0xdc00+0x00010000;
  -        }
  -        accum("&#x");
  -        accum(Integer.toHexString(next));
  -        accum(";");
  -        /*} else if (null != ctbc && !ctbc.canConvert(ch)) {
  -        accum("&#x");
  -        accum(Integer.toString((int)ch, 16));
  -        accum(";");*/
  -      }
  -      else
  -      {
  -        if ((0x0D == ch) && ((i+1) < strLen) && (0x0A==string.charAt(i+1))) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if ((0x0A == ch) && ((i+1) < strLen) && 
(0x0D==string.charAt(i+1))) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if (0x0D == ch) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if ('\n' == ch) 
  -        {
  -          outputLineSep();
  -        }
  -        else if (10 == ch) 
  -        {
  -          outputLineSep();
  -        }
  -        else if ('&' == ch) 
  -        {
  -          // From the spec:
  -          // The html output method should not escape a & character 
  -          // occurring in an attribute value immediately followed by a 
  -          // { character (see Section B.7.1 of the HTML 4.0 Recommendation). 
  -          // For example, a start-tag written in the stylesheet as
  -          //
  -          // <BODY bgcolor='&amp;{{randomrbg}};'>
  -          // should be output as
  -          // 
  -          // <BODY bgcolor='&{randomrbg};'>
  -
  -          if(((i+1) < strLen) && ('{'==string.charAt(i+1)))
  -            accum('&');
  -          else
  -            accum("&amp;");
  -        }
  -        else if ('"' == ch) 
  -        {
  -          accum("&quot;");
  -        }
  -        else if((ch >= 9) && (ch <= 126))
  -        {
  -          accum(ch);
  -        }
  +              +Integer.toHexString(ch)+ " ?");
  +          }
  +          else 
  +          {
  +            next = string.charAt(++i);
  +            if (!(0xdc00 <= next && next < 0xe000))
  +              throw new SAXException("Invalid UTF-16 surrogate detected: "
  +                +Integer.toHexString(ch)+" "+Integer.toHexString(next));
  +            next = ((ch-0xd800)<<10)+next-0xdc00+0x00010000;
  +          }
  +          accum("&#x");
  +          accum(Integer.toHexString(next));
  +          accum(";");
  +          /*} else if (null != ctbc && !ctbc.canConvert(ch)) {
  +          accum("&#x");
  +          accum(Integer.toString((int)ch, 16));
  +          accum(";");*/
  +        }        
           else if((ch >= 160) && (ch <= 255))
           {
             accum("&");
  
  
  
  1.14      +156 -135  
xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java
  
  Index: FormatterToXML.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FormatterToXML.java       1999/12/13 19:13:07     1.13
  +++ FormatterToXML.java       1999/12/15 21:53:07     1.14
  @@ -254,10 +254,10 @@
       int nSpecials = m_attrSpecialChars.length;
       for(int i = 0; i < nSpecials; i++)
       {
  -      m_attrCharsMap[(int)i] = 'S';
  +      m_attrCharsMap[(int)m_attrSpecialChars[i]] = 'S';
       }
  -    m_charsMap[0x0A] = 'S';
  -    m_charsMap[0x0D] = 'S';
  +    m_attrCharsMap[0x0A] = 'S';
  +    m_attrCharsMap[0x0D] = 'S';
     }
   
     /**
  @@ -431,7 +431,7 @@
       if(this.m_encoding.equals(DEFAULT_MIME_ENCODING) || 
          this.m_encoding.equals("WINDOWS-1250") ||
          this.m_encoding.equals("US-ASCII") ||
  -       this.m_encoding.equals("US-ASCII"))
  +       this.m_encoding.equals("ASCII"))
       {
         m_bytesEqualChars = true;
         m_outputStream = output;
  @@ -440,8 +440,39 @@
       else
       {
         String javaEncoding = this.convertMime2JavaEncoding(this.m_encoding);
  -      
  -      init( new OutputStreamWriter( output, javaEncoding ), format );
  +      OutputStreamWriter osw = null;
  +      try
  +      {
  +        osw = new OutputStreamWriter(output, javaEncoding);
  +      }
  +      catch(Exception e)
  +      {
  +        try
  +        {
  +          if(javaEncoding.startsWith("ISO"))
  +          {
  +            javaEncoding = javaEncoding.substring(3);
  +            try
  +            {
  +              osw = new OutputStreamWriter(output, javaEncoding);
  +            }
  +            catch(Exception e2)
  +            {
  +              osw = new OutputStreamWriter(output, m_encoding);
  +            }
  +          }
  +          else
  +          {
  +            osw = new OutputStreamWriter(output, m_encoding);
  +          }
  +        }
  +        catch(Exception e3)
  +        {
  +          System.out.println("Java VM does not support encoding: 
"+m_encoding+" or "+javaEncoding);
  +          osw = new OutputStreamWriter(output);
  +        }
  +      }
  +      init( osw, format );
       }
     }
     
  @@ -970,6 +1001,7 @@
       {
         // System.out.println("Flushing chars...");
         this.m_writer.write(m_charBuf, 0, m_pos);
  +      this.m_writer.flush();
         m_pos = 0;
       }
       catch(IOException ioe)
  @@ -1048,99 +1080,7 @@
           accum(ch);
         }
         else
  -      {
  -        if ((0x0D == ch) && ((i+1) < end) && (0x0A==chars[i+1])) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if ((0x0A == ch) && ((i+1) < end) && (0x0D==chars[i+1])) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if (0x0D == ch) 
  -        {
  -          outputLineSep();
  -          i++;
  -        }
  -        else if ('\n' == ch) 
  -        {
  -          outputLineSep();
  -        }
  -        else if ('<' == ch) 
  -        {
  -          accum('&');
  -          accum('l');
  -          accum('t');
  -          accum(';');
  -        }
  -        else if ('>' == ch) 
  -        {
  -          accum('&');
  -          accum('g');
  -          accum('t');
  -          accum(';');
  -        }
  -        else if ('&' == ch) 
  -        {
  -          accum('&');
  -          accum('a');
  -          accum('m');
  -          accum('p');
  -          accum(';');
  -          /**
  -          } else if ('"' == ch) {
  -          sb.append("&quot;");
  -          } else if ('\'' == ch) {
  -          sb.append("&apos;");
  -          */
  -        }
  -        else if (m_isUTF8 && (0xd800 <= ch && ch < 0xdc00)) 
  -        {
  -          // UTF-16 surrogate
  -          int next;
  -          if (i+1 >= length) 
  -          {
  -            throw new SAXException("Invalid UTF-16 surrogate detected: "
  -              +Integer.toHexString(ch)+ " ?");
  -          }
  -          else 
  -          {
  -            next = chars[++i];
  -            if (!(0xdc00 <= next && next < 0xe000))
  -              throw new SAXException("Invalid UTF-16 surrogate detected: "
  -                +Integer.toHexString(ch)+" "+Integer.toHexString(next));
  -            next = ((ch-0xd800)<<10)+next-0xdc00+0x00010000;
  -          }
  -          accum('&');
  -          accum('#');
  -          accum('x');
  -          String intStr = Integer.toHexString(next);
  -          int nIntStr = intStr.length();
  -          for(int k = 0; k < nIntStr; k++)
  -          {
  -            accum(intStr.charAt(k));
  -          }
  -          accum(';');
  -          /*} else if (null != ctbc && !ctbc.canConvert(ch)) {
  -          sb.append("&#x");
  -          sb.append(Integer.toString((int)ch, 16));
  -          sb.append(";");*/
  -        }
  -        else
  -        {
  -          accum('&');
  -          accum('#');
  -          String intStr = Integer.toString(ch);
  -          int nIntStr = intStr.length();
  -          for(int k = 0; k < nIntStr; k++)
  -          {
  -            accum(intStr.charAt(k));
  -          }
  -          accum(';');
  -        }
  -      }
  +        accumDefaultEscape(ch, i, chars, end, false);
       }
       
       m_isprevtext = true;
  @@ -1333,6 +1273,121 @@
       accum(name);
       accum(";");
     }
  +  
  +  /**
  +   * Handle one of the default entities, return false if it 
  +   * is not a default entity.
  +   */
  +  final boolean accumDefaultEntity(char ch, int i, char[] chars, int len, 
boolean escLF)
  +    throws SAXException
  +  {
  +    if (!escLF && (0x0D == ch) && ((i+1) < len) && (0x0A==chars[i+1])) 
  +    {
  +      outputLineSep();
  +      i++;
  +    }
  +    else if (!escLF && (0x0A == ch) && ((i+1) < len) && (0x0D==chars[i+1])) 
  +    {
  +      outputLineSep();
  +      i++;
  +    }
  +    else if (!escLF && 0x0D == ch) 
  +    {
  +      outputLineSep();
  +      i++;
  +    }
  +    else if (!escLF && '\n' == ch) 
  +    {
  +      outputLineSep();
  +    }
  +    else if ('<' == ch) 
  +    {
  +      accum('&');
  +      accum('l');
  +      accum('t');
  +      accum(';');
  +    }
  +    else if ('>' == ch) 
  +    {
  +      accum('&');
  +      accum('g');
  +      accum('t');
  +      accum(';');
  +    }
  +    else if ('&' == ch) 
  +    {
  +      accum('&');
  +      accum('a');
  +      accum('m');
  +      accum('p');
  +      accum(';');
  +    }
  +    else if ('"' == ch) 
  +    {
  +      accum('&');
  +      accum('q');
  +      accum('u');
  +      accum('o');
  +      accum('t');
  +      accum(';');
  +    }
  +    else if ('\'' == ch) 
  +    {
  +      accum('&');
  +      accum('a');
  +      accum('p');
  +      accum('o');
  +      accum('s');
  +      accum(';');
  +    }
  +    else
  +    {
  +      return false;
  +    }
  +    return true;
  +  }
  +  
  +  /**
  +   * Escape and accum a character.
  +   */
  +  final void accumDefaultEscape(char ch, int i, char[] chars, int len, 
boolean escLF)
  +    throws SAXException
  +  {
  +    if(!accumDefaultEntity(ch, i, chars, len, escLF))
  +    {
  +      if (0xd800 <= ch && ch < 0xdc00) 
  +      {
  +        // UTF-16 surrogate
  +        int next;
  +        if (i+1 >= len) 
  +        {
  +          throw new SAXException("Invalid UTF-16 surrogate detected: "
  +            +Integer.toHexString(ch)+ " ?");
  +        }
  +        else 
  +        {
  +          next = chars[++i];
  +          if (!(0xdc00 <= next && next < 0xe000))
  +            throw new SAXException("Invalid UTF-16 surrogate detected: "
  +              +Integer.toHexString(ch)+" "+Integer.toHexString(next));
  +          next = ((ch-0xd800)<<10)+next-0xdc00+0x00010000;
  +        }
  +        accum("&#x");
  +        accum(Integer.toHexString(next));
  +        accum(";");
  +        /*} else if (null != ctbc && !ctbc.canConvert(ch)) {
  +        sb.append("&#x");
  +        sb.append(Integer.toString((int)ch, 16));
  +        sb.append(";");*/
  +      }
  +      else 
  +      {
  +        accum("&#");
  +        accum(Integer.toString(ch));
  +        accum(";");
  +      }
  +    }
  +  }
   
     /**
      * Returns the specified <var>string</var> after substituting 
<VAR>specials</VAR>,
  @@ -1353,43 +1408,9 @@
       {
         char ch = stringChars[i];
         if((ch < SPECIALSSIZE) && (m_attrCharsMap[ch] != 'S'))
  -      {
           accum(ch);
  -      }
  -      else
  -      {
  -        if (0xd800 <= ch && ch < 0xdc00) 
  -        {
  -          // UTF-16 surrogate
  -          int next;
  -          if (i+1 >= string.length()) 
  -          {
  -            throw new SAXException("Invalid UTF-16 surrogate detected: "
  -              +Integer.toHexString(ch)+ " ?");
  -          }
  -          else 
  -          {
  -            next = string.charAt(++i);
  -            if (!(0xdc00 <= next && next < 0xe000))
  -              throw new SAXException("Invalid UTF-16 surrogate detected: "
  -                +Integer.toHexString(ch)+" "+Integer.toHexString(next));
  -            next = ((ch-0xd800)<<10)+next-0xdc00+0x00010000;
  -          }
  -          accum("&#x");
  -          accum(Integer.toHexString(next));
  -          accum(";");
  -          /*} else if (null != ctbc && !ctbc.canConvert(ch)) {
  -          sb.append("&#x");
  -          sb.append(Integer.toString((int)ch, 16));
  -          sb.append(";");*/
  -        }
  -        else 
  -        {
  -          accum("&#");
  -          accum(Integer.toString(ch));
  -          accum(";");
  -        }
  -      }
  +      else 
  +        accumDefaultEscape(ch, i, stringChars, len, true);
       }
     }
     
  
  
  
  1.7       +3 -2      xml-xalan/src/org/apache/xalan/xslt/FuncDocument.java
  
  Index: FuncDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/FuncDocument.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FuncDocument.java 1999/12/15 16:25:13     1.6
  +++ FuncDocument.java 1999/12/15 21:53:08     1.7
  @@ -145,8 +145,9 @@
         }
         
         Document newDoc = getDoc(path, execContext, context, ref, base);
  -      // nodes.mutableNodeset().addNode(newDoc);     
  -      mnl.addNodeInDocOrder(newDoc, true, execContext);
  +      // nodes.mutableNodeset().addNode(newDoc);  
  +      if(null != newDoc)
  +        mnl.addNodeInDocOrder(newDoc, true, execContext);
       }
       return nodes;
     }
  
  
  
  1.22      +21 -13    xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java
  
  Index: XSLTEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- XSLTEngineImpl.java       1999/12/15 16:25:13     1.21
  +++ XSLTEngineImpl.java       1999/12/15 21:53:08     1.22
  @@ -1817,23 +1817,27 @@
     {
       // flushPending();
   
  -    DocumentHandler savedFormatterListener = m_flistener;
   
       DocumentFragment resultFragment = createDocFrag();
   
  -    String savedPendingName = m_pendingElementName;
  -    m_pendingElementName = null;
  -    AttributeListImpl savedPendingAttributes = m_pendingAttributes;
  -    m_pendingAttributes = new AttributeListImpl();
  +    DocumentHandler savedFListener = this.m_flistener;
  +    boolean savedMustFlushStartDoc = this.m_mustFlushStartDoc;
  +    boolean savedPendingStartDoc = this.m_pendingStartDoc;
  +    String savedPendingName = this.m_pendingElementName;
  +    this.m_pendingElementName = null;
  +    AttributeListImpl savedPendingAttributes = this.m_pendingAttributes;
  +    this.m_pendingAttributes = new AttributeListImpl();
   
       m_flistener = new FormatterToDOM(m_resultTreeFactory, resultFragment);
   
       templateParent.executeChildren(this, sourceTree, sourceNode, mode);
   
       // flushPending();
  -    m_flistener = savedFormatterListener;
  -    m_pendingElementName = savedPendingName;
  -    m_pendingAttributes = savedPendingAttributes;
  +    this.m_pendingElementName = savedPendingName;
  +    this.m_pendingAttributes = savedPendingAttributes;
  +    this.m_mustFlushStartDoc = savedMustFlushStartDoc;
  +    this.m_pendingStartDoc = savedPendingStartDoc;
  +    this.m_flistener = savedFListener;
   
       return resultFragment;
     }
  @@ -3897,13 +3901,17 @@
      */
     private String excludePrefix(String name)
     {
  -    int indexOfNSSep = name.indexOf(':');
  -    if(indexOfNSSep > 0)
  +    if(null != m_stylesheetRoot) // Just extra defensive
       {
  -      String prefix = name.substring(0, indexOfNSSep);
  -      if(m_stylesheetRoot.getExcludeResultPrefixes().contains(prefix))
  +      int indexOfNSSep = name.indexOf(':');
  +      if(indexOfNSSep > 0)
         {
  -        name = name.substring(indexOfNSSep+1);
  +        String prefix = name.substring(0, indexOfNSSep);
  +        StringToStringTable erp = 
m_stylesheetRoot.getExcludeResultPrefixes();
  +        if((null != erp) && erp.contains(prefix))
  +        {
  +          name = name.substring(indexOfNSSep+1);
  +        }
         }
       }
       return name;
  
  
  

Reply via email to