sboag       99/12/13 18:11:03

  Modified:    src/org/apache/xalan/xpath/xml FormatterToHTML.java
  Log:
  Don't escape '<', don't escape '&' if followed by '{', for time being use 
URLEncoder to escape URL attributes.
  
  Revision  Changes    Path
  1.12      +50 -25    
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FormatterToHTML.java      1999/12/13 19:13:07     1.11
  +++ FormatterToHTML.java      1999/12/14 02:11:03     1.12
  @@ -367,6 +367,8 @@
     {
       super.initAttrCharsMap();
       m_attrCharsMap[(int)'\n'] = 'S';
  +    m_attrCharsMap[(int)'<'] = '\0';
  +    m_attrCharsMap[(int)'>'] = '\0';
       m_charsMap[0x0A] = 'S';
       m_charsMap[0x0D] = 'S';
     }
  @@ -640,33 +642,42 @@
     public void writeAttrURI(String string, String encoding)
       throws SAXException
     {
  -    char[] stringArray = string.toCharArray();
  -    int len = stringArray.length;
  -
  -    for (int i = 0;  i < len;  i ++)
  +    // Not sure if it's OK to use the URLEncoder...
  +    if(true)
       {
  -      char ch = stringArray[i];
  -      if(((ch > 0x1F) &&   // X'00 - 1F' not valid
  -         (ch < 0x7F)) &&   // X'7F' not valid
  -         !isURLEscapeChar(ch)  ) // characters in the table
  -      {
  -        accum(ch);   // valid character, append it
  -      }
  -      else
  +      string = java.net.URLEncoder.encode(string);
  +      accum(string);
  +    }
  +    else
  +    {
  +      char[] stringArray = string.toCharArray();
  +      int len = stringArray.length;
  +
  +      for (int i = 0;  i < len;  i ++)
         {
  -        // need to escape the character
  -        int mask1  = 0xFF00;
  -        int mask2  = 0x00FF;
  -        int b1 = (int)((((int)ch) & mask1) >> 8);
  -        int b2 = (int)(((int)ch) & mask2);
  -        // if first 8 bytes are 0, no need to append them.
  -        if (b1 != 0)
  -        {     
  +        char ch = stringArray[i];
  +        if(((ch > 0x1F) &&   // X'00 - 1F' not valid
  +            (ch < 0x7F)) &&   // X'7F' not valid
  +           !isURLEscapeChar(ch)  ) // characters in the table
  +        {
  +          accum(ch);   // valid character, append it
  +        }
  +        else
  +        {
  +          // need to escape the character
  +          int mask1  = 0xFF00;
  +          int mask2  = 0x00FF;
  +          int b1 = (int)((((int)ch) & mask1) >> 8);
  +          int b2 = (int)(((int)ch) & mask2);
  +          // if first 8 bytes are 0, no need to append them.
  +          if (b1 != 0)
  +          {   
  +            accum("%");
  +            accum(Integer.toHexString(b1));
  +          }  
             accum("%");
  -          accum(Integer.toHexString(b1));
  -        }    
  -        accum("%");
  -        accum(Integer.toHexString(b2));              
  +          accum(Integer.toHexString(b2));            
  +        }
         }
       }
     }
  @@ -749,7 +760,21 @@
           }
           else if ('&' == ch) 
           {
  -          accum("&amp;");
  +          // 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) 
           {
  
  
  

Reply via email to