santiagopg    02/05/21 08:13:25

  Modified:    java/src/org/apache/xalan/xsltc TransletOutputHandler.java
               java/src/org/apache/xalan/xsltc/runtime
                        AbstractTranslet.java SAXAdapter.java
                        TransletOutputBase.java
               java/src/org/apache/xalan/xsltc/runtime/output
                        HtmlOutput.java OutputBase.java StreamOutput.java
  Log:
  New methods added to the translet output handler.
  
  Revision  Changes    Path
  1.9       +6 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java
  
  Index: TransletOutputHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TransletOutputHandler.java        14 May 2002 19:50:21 -0000      1.8
  +++ TransletOutputHandler.java        21 May 2002 15:13:25 -0000      1.9
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TransletOutputHandler.java,v 1.8 2002/05/14 19:50:21 santiagopg 
Exp $
  + * @(#)$Id: TransletOutputHandler.java,v 1.9 2002/05/21 15:13:25 santiagopg 
Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -87,5 +87,10 @@
       public void omitHeader(boolean value);
       public boolean setEscaping(boolean escape) throws TransletException;
       public void setCdataElements(Hashtable elements);
  +    public void setDoctype(String system, String pub);
  +    public void setMediaType(String mediaType);
  +    public void setStandalone(String standalone);
  +    public void setVersion(String version);
       public void close();
  +
   }
  
  
  
  1.36      +2 -9      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
  
  Index: AbstractTranslet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- AbstractTranslet.java     14 May 2002 17:50:04 -0000      1.35
  +++ AbstractTranslet.java     21 May 2002 15:13:25 -0000      1.36
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: AbstractTranslet.java,v 1.35 2002/05/14 17:50:04 santiagopg Exp $
  + * @(#)$Id: AbstractTranslet.java,v 1.36 2002/05/21 15:13:25 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -561,14 +561,7 @@
       /**
        * Transfer the output settings to the output post-processor
        */
  -    protected void transferOutputSettings(TransletOutputHandler output) {
  -
  -     // It is an error if this method is called with anything else than
  -     // the translet post-processor (TextOutput)
  -     if (!(output instanceof TextOutput)) return;
  -
  -     TextOutput handler = (TextOutput)output;
  -
  +    protected void transferOutputSettings(TransletOutputHandler handler) {
        // Transfer the output method setting
        if (_method != null) {
            // Transfer all settings relevant to XML output
  
  
  
  1.13      +6 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java
  
  Index: SAXAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/SAXAdapter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SAXAdapter.java   14 May 2002 19:50:21 -0000      1.12
  +++ SAXAdapter.java   21 May 2002 15:13:25 -0000      1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: SAXAdapter.java,v 1.12 2002/05/14 19:50:21 santiagopg Exp $
  + * @(#)$Id: SAXAdapter.java,v 1.13 2002/05/21 15:13:25 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -190,7 +190,11 @@
       public void setHeader(String header) {}
       public void setIndent(boolean indent) {}
       public void omitHeader(boolean value) {}
  -    public void setCdataElements(Hashtable elements) { }
  +    public void setCdataElements(Hashtable elements) {}
  +    public void setDoctype(String system, String pub) {}
  +    public void setMediaType(String mediaType) {}
  +    public void setStandalone(String standalone) {}
  +    public void setVersion(String version) {}
       public void close() {}
       public String getPrefix(String uri) { return(""); }
   }
  
  
  
  1.9       +5 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java
  
  Index: TransletOutputBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TransletOutputBase.java   14 May 2002 19:50:21 -0000      1.8
  +++ TransletOutputBase.java   21 May 2002 15:13:25 -0000      1.9
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TransletOutputBase.java,v 1.8 2002/05/14 19:50:21 santiagopg Exp 
$
  + * @(#)$Id: TransletOutputBase.java,v 1.9 2002/05/21 15:13:25 santiagopg Exp 
$
    *
    * The Apache Software License, Version 1.1
    *
  @@ -90,5 +90,9 @@
       public void setIndent(boolean indent) {}
       public void omitHeader(boolean value) {}
       public void setCdataElements(Hashtable elements) {}
  +    public void setDoctype(String system, String pub) {}
  +    public void setMediaType(String mediaType) {}
  +    public void setStandalone(String standalone) {}
  +    public void setVersion(String version) {}
       public void close() {}
   }
  
  
  
  1.2       +107 -23   
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/HtmlOutput.java
  
  Index: HtmlOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/HtmlOutput.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HtmlOutput.java   20 May 2002 17:41:38 -0000      1.1
  +++ HtmlOutput.java   21 May 2002 15:13:25 -0000      1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: HtmlOutput.java,v 1.1 2002/05/20 17:41:38 santiagopg Exp $
  + * @(#)$Id: HtmlOutput.java,v 1.2 2002/05/21 15:13:25 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -75,8 +75,12 @@
   
   public class HtmlOutput extends StreamOutput {
   
  -    protected static final Hashtable _emptyElements = new Hashtable();
  -    protected static final String[] tags = { "area", "base", "basefont", 
"br",
  +    private static final String HREF_STR = "href";
  +    private static final String CITE_STR = "cite";
  +    private static final String SRC_STR  = "src";
  +
  +    private static final Hashtable _emptyElements = new Hashtable();
  +    private static final String[] tags = { "area", "base", "basefont", "br",
                                           "col", "frame", "hr", "img", "input",
                                           "isindex", "link", "meta", "param" };
       static {
  @@ -85,18 +89,27 @@
        }
       }
   
  -    public HtmlOutput(Writer writer) {
  +    private boolean _inStyleScript = false;
  +
  +    public HtmlOutput(Writer writer, String encoding) {
        _writer = writer;
  +     _encoding = encoding;
  +     if (encoding.equalsIgnoreCase("iso-8859-1")) {
  +         _is8859Encoded = true;
  +     }
       }
   
       public HtmlOutput(OutputStream out, String encoding) 
        throws IOException
       {
        try {
  -         _writer = new OutputStreamWriter(out, encoding);
  +         _writer = new OutputStreamWriter(out, _encoding = encoding);
  +         if (encoding.equalsIgnoreCase("iso-8859-1")) {
  +             _is8859Encoded = true;
  +         }
        }
        catch (UnsupportedEncodingException e) {
  -         _writer = new OutputStreamWriter(out, "UTF-8");
  +         _writer = new OutputStreamWriter(out, _encoding = "UTF-8");
        }
       }
   
  @@ -145,6 +158,13 @@
   
        _buffer.append('<').append(elementName);
        _startTagOpen = true;
  +     _indentNextEndTag = false;
  +
  +     if (elementName.equalsIgnoreCase("style") || 
  +         elementName.equalsIgnoreCase("script")) 
  +     {
  +         _inStyleScript = true;
  +     }
       }
   
       public void endElement(String elementName) throws TransletException { 
  @@ -152,10 +172,25 @@
            _startTagOpen = false;
            _buffer.append(">");
        }
  +
  +     if (_indent) {
  +         _indentLevel --;
  +         if (_indentNextEndTag) {
  +             indent(_indentNextEndTag);
  +             _indentNextEndTag = true;
  +         }
  +     }
  +
        // Empty elements may not have closing tags
  -     if (_emptyElements.get(elementName.toLowerCase()) == null) {
  +     if (!_emptyElements.containsKey(elementName.toLowerCase())) {
            _buffer.append("</").append(elementName).append('>');
        }
  +     else if (_inStyleScript && 
  +              (elementName.equalsIgnoreCase("style") || 
  +               elementName.equalsIgnoreCase("script"))) 
  +     {
  +         _inStyleScript = false;
  +     }
       }
   
       public void characters(String characters)
  @@ -166,7 +201,7 @@
            _startTagOpen = false;
        }
   
  -     if (_escaping) {
  +     if (_escaping && !_inStyleScript) {
            escapeCharacters(characters.toCharArray(), 0, characters.length());
        }
        else {
  @@ -182,7 +217,7 @@
            _startTagOpen = false;
        }
   
  -     if (_escaping) {
  +     if (_escaping && !_inStyleScript) {
            escapeCharacters(characters, offset, length);
        }
        else {
  @@ -194,8 +229,17 @@
        throws TransletException 
       { 
        if (_startTagOpen) {
  -         _buffer.append(' ').append(attributeName)
  -             .append("=\"").append(attributeValue).append('"');
  +         _buffer.append(' ').append(attributeName).append("=\"");
  +
  +         if (attributeName.equalsIgnoreCase(HREF_STR) || 
  +             attributeName.equalsIgnoreCase(SRC_STR)  || 
  +             attributeName.equals(CITE_STR)) 
  +         {
  +             appendEncodedURL(attributeValue).append('"');
  +         }
  +         else {
  +             appendNonURL(attributeValue).append('"');
  +         }
        }
       }
   
  @@ -235,27 +279,27 @@
        }
       }
   
  +    public void setIndent(boolean indent) { 
  +     _indent = indent;
  +    }
  +
  +    public void omitHeader(boolean value) {
  +        _omitHeader = value;
  +    }
  +
       public void namespace(String prefix, String uri) throws 
TransletException 
       { 
  -     // ignore since method type is HTML
  +     // ignore when method type is HTML
       }
   
       public void setCdataElements(Hashtable elements) { 
  -     // ignore since method type is HTML
  +     // ignore when method type is HTML
       }
   
       public void setType(int type) { 
        // ignore: default is HTML
       }
   
  -    public void setIndent(boolean indent) { 
  -     // ignore: default is off
  -    }
  -
  -    public void omitHeader(boolean value) { 
  -     // ignore: default is on
  -    }
  -
       private void escapeCharacters(char[] ch, int off, int len) {
        int limit = off + len;
        int offset = off;
  @@ -290,8 +334,8 @@
                offset = i + 1;
                break;
            default:
  -             if ( (current >= '\u007F' && current < '\u00A0') ||
  -                  (_is8859Encoded && (current > '\u00FF')) )
  +             if ((current >= '\u007F' && current < '\u00A0') ||
  +                 (_is8859Encoded && current > '\u00FF'))
                {
                    _buffer.append(ch, offset, i - offset);
                    _buffer.append(CHAR_ESC_START);
  @@ -319,4 +363,44 @@
            _indentLevel < MAX_INDENT_LEVEL ? _indentLevel + _indentLevel 
                : MAX_INDENT);
       }
  +
  +    /**
  +     * Replaces whitespaces in a URL with '%20'
  +     */
  +    private StringBuffer appendEncodedURL(String base) {
  +     final int length = base.length();
  +
  +     for (int i = 0; i < length; i++) {
  +         final char ch = base.charAt(i);
  +         if (ch == ' ') {
  +             _buffer.append("%20");
  +         }
  +         else {
  +             _buffer.append(ch);
  +         }
  +     }
  +     return _buffer;
  +    }
  +
  +    /**
  +     * Escape non ASCII characters (> u007F) as &#XXX; entities.
  +     */
  +    private StringBuffer appendNonURL(String base) {
  +     final int length = base.length();
  +
  +        for (int i = 0; i < length; i++){
  +         final char ch = base.charAt(i);
  +
  +         if (ch > '\u007F') {
  +             _buffer.append(CHAR_ESC_START)
  +                    .append(Integer.toString((int) ch))
  +                    .append(';');
  +         }
  +         else {
  +             _buffer.append(ch); 
  +         } 
  +     }
  +     return _buffer;
  +    }
  +
   }
  
  
  
  1.2       +6 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java
  
  Index: OutputBase.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OutputBase.java   17 May 2002 16:52:56 -0000      1.1
  +++ OutputBase.java   21 May 2002 15:13:25 -0000      1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: OutputBase.java,v 1.1 2002/05/17 16:52:56 tmiller Exp $
  + * @(#)$Id: OutputBase.java,v 1.2 2002/05/21 15:13:25 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -89,5 +89,9 @@
        return false;
       }
       public void setCdataElements(Hashtable elements){}
  -    public void close(){}
  +    public void setDoctype(String system, String pub) {}
  +    public void setMediaType(String mediaType) {}
  +    public void setStandalone(String standalone) {}
  +    public void setVersion(String version) {}
  +    public void close() {}
   }
  
  
  
  1.3       +3 -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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StreamOutput.java 20 May 2002 17:41:38 -0000      1.2
  +++ StreamOutput.java 21 May 2002 15:13:25 -0000      1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StreamOutput.java,v 1.2 2002/05/20 17:41:38 santiagopg Exp $
  + * @(#)$Id: StreamOutput.java,v 1.3 2002/05/21 15:13:25 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -98,5 +98,7 @@
       protected int     _indentLevel = 0;
   
       protected boolean _escaping = true;
  +
  +    protected String  _encoding;
   
   }
  
  
  

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

Reply via email to