You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2004/08/27 23:37:13 UTC

cvs commit: xml-xalan/java/src/org/apache/xml/serializer CharInfo.java ToHTMLStream.java ToStream.java

minchau     2004/08/27 14:37:13

  Modified:    java/src/org/apache/xml/serializer CharInfo.java
                        ToHTMLStream.java ToStream.java
  Log:
  Minor changes to CharInfo to map charaters to decorated entities (e.g. "<" ) 
  rather than just entity names (e.g. "lt"), which is a minor performance improvement.
  
  Revision  Changes    Path
  1.13      +67 -14    xml-xalan/java/src/org/apache/xml/serializer/CharInfo.java
  
  Index: CharInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/CharInfo.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CharInfo.java	1 Apr 2004 18:45:30 -0000	1.12
  +++ CharInfo.java	27 Aug 2004 21:37:12 -0000	1.13
  @@ -48,8 +48,8 @@
    */
   class CharInfo
   {
  -    /** Lookup table for characters to entity references. */
  -    private Hashtable m_charToEntityRef = new Hashtable();
  +    /** Given a character, lookup a String to output (e.g. a decorated entity reference). */
  +    private Hashtable m_charToString = new Hashtable();
   
       /**
        * The name of the HTML entities file.
  @@ -353,16 +353,23 @@
        */
       private void defineEntity(String name, char value)
       {
  -        CharKey character = new CharKey(value);
  -
  -        m_charToEntityRef.put(character, name);
  -        set(value);
  +        StringBuffer sb = new StringBuffer("&");
  +        sb.append(name);
  +        sb.append(';');
  +        String entityString = sb.toString();
  +        
  +        defineChar2StringMapping(entityString, value);
       }
   
       private CharKey m_charKey = new CharKey();
   
       /**
  -     * Resolve a character to an entity reference name.
  +     * Map a character to a String. For example given
  +     * the character '>' this method would return the fully decorated
  +     * entity name "<".
  +     * Strings for entity references are loaded from a properties file,
  +     * but additional mappings defined through calls to defineChar2String()
  +     * are possible. Such entity reference mappings could be over-ridden.
        *
        * This is reusing a stored key object, in an effort to avoid
        * heap activity. Unfortunately, that introduces a threading risk.
  @@ -372,16 +379,17 @@
        * keyed directly from the character's integer value; see DTM's
        * string pool for a related solution.
        *
  -     * @param value character value that should be resolved to a name.
  +     * @param value The character that should be resolved to
  +     * a String, e.g. resolve '>' to  "<".
        *
  -     * @return name of character entity, or null if not found.
  +     * @return The String that the character is mapped to, or null if not found.
        * @xsl.usage internal
        */
  -    synchronized public String getEntityNameForChar(char value)
  +    synchronized public String getOutputStringForChar(char value)
       {
           // CharKey m_charKey = new CharKey(); //Alternative to synchronized
           m_charKey.setChar(value);
  -        return (String) m_charToEntityRef.get(m_charKey);
  +        return (String) m_charToString.get(m_charKey);
       }
       
       /**
  @@ -439,7 +447,10 @@
        */
       public final boolean isTextASCIIClean(int value)
       {
  -        return isCleanTextASCII[value];
  +        boolean ret = isCleanTextASCII[value];
  +        if (ret == false)
  +        System.out.flush();
  +        return ret;
       }
       
   //  In the future one might want to use the array directly and avoid
  @@ -547,7 +558,9 @@
        * 0, 1, 2 ... up to the maximum that was specified at
        * the creation of the set.
        */
  -    private final void set(int i) {        
  +    private final void set(int i) {   
  +        setASCIIdirty(i);
  +             
           int j = (i >> SHIFT_PER_WORD); // this word is used
           int k = j + 1;       
           
  @@ -606,4 +619,44 @@
           }
           return extra;
       }    
  +    
  +    /**
  +     * If the character is a printable ASCII character then
  +     * mark it as not clean and needing replacement with
  +     * a String on output.
  +     * @param ch
  +     */
  +    private void setASCIIdirty(int j) 
  +    {
  +        if (0 <= j && j < ASCII_MAX) 
  +        {
  +            isCleanTextASCII[j] = false;
  +            isSpecialTextASCII[j] = true;
  +        } 
  +    }
  +
  +    /**
  +     * If the character is a printable ASCII character then
  +     * mark it as and not needing replacement with
  +     * a String on output.
  +     * @param ch
  +     */    
  +    private void setASCIIclean(int j)
  +    {
  +        if (0 <= j && j < ASCII_MAX) 
  +        {        
  +            isCleanTextASCII[j] = true;
  +            isSpecialTextASCII[j] = false;
  +        }
  +    }
  +    
  +    void defineChar2StringMapping(String outputString, char inputChar) 
  +    {
  +        CharKey character = new CharKey(inputChar);
  +        m_charToString.put(character, outputString);
  +        set(inputChar);        
  +    }
  +
  +   
  +
   }
  
  
  
  1.32      +2 -4      xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java
  
  Index: ToHTMLStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ToHTMLStream.java	21 Jul 2004 21:29:46 -0000	1.31
  +++ ToHTMLStream.java	27 Aug 2004 21:37:13 -0000	1.32
  @@ -1333,12 +1333,10 @@
                       }
                       else
                       */
  -                    String entityName = m_charInfo.getEntityNameForChar(ch);
  +                    String entityName = m_charInfo.getOutputStringForChar(ch);
                       if (null != entityName)
                       {
  -                        writer.write('&');
                           writer.write(entityName);
  -                        writer.write(';');
                       }
                       else if (escapingNotNeeded(ch))
                       {
  
  
  
  1.33      +5 -6      xml-xalan/java/src/org/apache/xml/serializer/ToStream.java
  
  Index: ToStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToStream.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ToStream.java	22 Jul 2004 21:43:18 -0000	1.32
  +++ ToStream.java	27 Aug 2004 21:37:13 -0000	1.33
  @@ -1054,13 +1054,11 @@
               // or if this is a character from attribute value and a special one of those
               if ((fromTextNode && m_charInfo.isSpecialTextChar(ch)) || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch)))
               {
  -                String entityRef = m_charInfo.getEntityNameForChar(ch);
  +                String entityRef = m_charInfo.getOutputStringForChar(ch);
   
                   if (null != entityRef)
                   {
  -                    writer.write('&');
                       writer.write(entityRef);
  -                    writer.write(';');
                   }
                   else
                       return i;
  @@ -1656,9 +1654,10 @@
               }
               else
               {
  -                if (!escapingNotNeeded(ch) || 
  +                if ((!escapingNotNeeded(ch) || 
                       (  (fromTextNode && m_charInfo.isSpecialTextChar(ch))
  -                     || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch))))
  +                     || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch)))) 
  +                && m_elemContext.m_currentElemDepth > 0)
                   {
                       writer.write("&#");
                       writer.write(Integer.toString(ch));
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org