santiagopg    2002/06/26 15:55:08

  Modified:    java/src/org/apache/xalan/xsltc/runtime/output
                        StreamOutput.java StreamUnknownOutput.java
                        TransletOutputHandlerFactory.java
               java/src/org/apache/xalan/xsltc/trax
                        TemplatesHandlerImpl.java TemplatesImpl.java
                        TransformerFactoryImpl.java TransformerImpl.java
  Log:
  Added 'indent-number' attribute to the transformer factory. The value
  of this attribute is the number of spaces that will be used by the
  output system when indentation is turned on.
  
  Revision  Changes    Path
  1.17      +9 -2      
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- StreamOutput.java 24 Jun 2002 20:09:43 -0000      1.16
  +++ StreamOutput.java 26 Jun 2002 22:55:07 -0000      1.17
  @@ -108,6 +108,8 @@
       protected boolean _escaping     = true;
       protected String  _encoding     = "UTF-8";
   
  +    protected int     _indentNumber = 2;
  +
       // protected HashSet _attributes = new HashSet();
       protected Vector _attributes = new Vector();
   
  @@ -138,6 +140,7 @@
        _encoding = output._encoding;
        _is8859Encoded = output._is8859Encoded;
        _buffer = output._buffer;
  +     _indentNumber = output._indentNumber;
       }
   
       protected StreamOutput(Writer writer, String encoding) {
  @@ -160,6 +163,10 @@
        _buffer = new StringBuffer(BUFFER_SIZE);
       }
   
  +    public void setIndentNumber(int value) {
  +     _indentNumber = value;
  +    }
  +
       /**
        * Set the output document system/public identifiers
        */
  @@ -231,7 +238,7 @@
        }
   
        _buffer.append(INDENT, 0, 
  -         _indentLevel < MAX_INDENT_LEVEL ? _indentLevel + _indentLevel 
  +         _indentLevel < MAX_INDENT_LEVEL ? _indentLevel * _indentNumber 
                : MAX_INDENT);
       }
   
  
  
  
  1.7       +5 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamUnknownOutput.java
  
  Index: StreamUnknownOutput.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamUnknownOutput.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StreamUnknownOutput.java  19 Jun 2002 20:36:05 -0000      1.6
  +++ StreamUnknownOutput.java  26 Jun 2002 22:55:07 -0000      1.7
  @@ -285,6 +285,10 @@
        _handler.setCdataElements(elements);
       }
   
  +    public void setIndentNumber(int value) {
  +     _handler.setIndentNumber(value);
  +    }
  +
       private void initStreamOutput() 
        throws TransletException 
       {
  
  
  
  1.12      +18 -8     
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java
  
  Index: TransletOutputHandlerFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TransletOutputHandlerFactory.java 11 Jun 2002 17:03:03 -0000      1.11
  +++ TransletOutputHandlerFactory.java 26 Jun 2002 22:55:07 -0000      1.12
  @@ -89,6 +89,7 @@
       private OutputStream _ostream  = System.out;
       private Writer _writer         = null;
       private Node           _node   = null;
  +    private int _indentNumber      = -1;
       private ContentHandler _handler    = null;
       private LexicalHandler _lexHandler = null;
   
  @@ -135,33 +136,42 @@
           : null;
       }
   
  +    public void setIndentNumber(int value) {
  +     _indentNumber = value;
  +    }
  +
       public TransletOutputHandler getTransletOutputHandler() 
        throws IOException, ParserConfigurationException 
       {
        switch (_outputType) {
            case STREAM:
  +             StreamOutput result = null;
  +
                if (_method == null) {
  -                 return (_writer == null) ? 
  +                 result = (_writer == null) ? 
                        new StreamUnknownOutput(_ostream, _encoding) :
                        new StreamUnknownOutput(_writer, _encoding);
                }
  -
  -             if (_method.equalsIgnoreCase("xml")) {
  -                 return (_writer == null) ? 
  +             else if (_method.equalsIgnoreCase("xml")) {
  +                 result = (_writer == null) ? 
                        new StreamXMLOutput(_ostream, _encoding) :
                        new StreamXMLOutput(_writer, _encoding);
                }
                else if (_method.equalsIgnoreCase("html")) {
  -                 return (_writer == null) ? 
  +                 result = (_writer == null) ? 
                        new StreamHTMLOutput(_ostream, _encoding) :
                        new StreamHTMLOutput(_writer, _encoding);
                }
                else if (_method.equalsIgnoreCase("text")) {
  -                 return (_writer == null) ? 
  +                 result = (_writer == null) ? 
                        new StreamTextOutput(_ostream, _encoding) :
                        new StreamTextOutput(_writer, _encoding);
                }
  -         break;
  +
  +             if (result != null && _indentNumber >= 0) {
  +                 result.setIndentNumber(_indentNumber);
  +             }
  +             return result;
            case DOM:
                _handler = (_node != null) ? new SAX2DOM(_node) : 
                                             new SAX2DOM();
  
  
  
  1.12      +5 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
  
  Index: TemplatesHandlerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TemplatesHandlerImpl.java 17 Jun 2002 18:37:11 -0000      1.11
  +++ TemplatesHandlerImpl.java 26 Jun 2002 22:55:07 -0000      1.12
  @@ -77,6 +77,7 @@
   public class TemplatesHandlerImpl extends Parser implements TemplatesHandler 
{
   
       private String _systemId;
  +    private int    _indentNumber;
   
       // Temporary
       private boolean _oldOutputSystem;
  @@ -84,8 +85,9 @@
       /**
        * Default constructor
        */
  -    protected TemplatesHandlerImpl(boolean oldOutputSystem) {
  +    protected TemplatesHandlerImpl(int indentNumber, boolean 
oldOutputSystem) {
        super(null);
  +     _indentNumber = indentNumber;
        _oldOutputSystem = oldOutputSystem;
       }
   
  @@ -170,7 +172,7 @@
                final byte[][] bytecodes = xsltc.getBytecodes();
                if (bytecodes != null) {
                    return new TemplatesImpl(xsltc.getBytecodes(), 
transletName, 
  -                      getOutputProperties(), _oldOutputSystem);
  +                      getOutputProperties(), _indentNumber, 
_oldOutputSystem);
                }
            }
        }
  
  
  
  1.15      +7 -3      
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
  
  Index: TemplatesImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TemplatesImpl.java        17 Jun 2002 18:37:11 -0000      1.14
  +++ TemplatesImpl.java        26 Jun 2002 22:55:07 -0000      1.15
  @@ -99,6 +99,8 @@
       
       private Properties _outputProperties; 
   
  +    private int _indentNumber;
  +
       // Temporary
       private boolean _oldOutputSystem;
   
  @@ -133,11 +135,13 @@
        * the main translet class, must be supplied
        */
       protected TemplatesImpl(byte[][] bytecodes, String transletName,
  -     Properties outputProperties, boolean oldOutputSystem) 
  +     Properties outputProperties, int indentNumber,
  +     boolean oldOutputSystem) 
       {
        _bytecodes = bytecodes;
        _name      = transletName;
        _outputProperties = outputProperties;
  +     _indentNumber = indentNumber;
        _oldOutputSystem = oldOutputSystem;
       }
   
  @@ -266,7 +270,7 @@
       public Transformer newTransformer()
        throws TransformerConfigurationException {
           return new TransformerImpl(getTransletInstance(), _outputProperties,
  -         _oldOutputSystem);
  +         _indentNumber, _oldOutputSystem);
       }
   
       /**
  
  
  
  1.42      +56 -16    
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
  
  Index: TransformerFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TransformerFactoryImpl.java       18 Jun 2002 13:29:35 -0000      1.41
  +++ TransformerFactoryImpl.java       26 Jun 2002 22:55:07 -0000      1.42
  @@ -144,6 +144,7 @@
       private boolean _debug = false;
       private boolean _disableInlining = false;
       private boolean _oldOutputSystem = false;
  +    private int     _indentNumber    = -1;
   
       /**
        * javax.xml.transform.sax.TransformerFactory implementation.
  @@ -208,26 +209,64 @@
        * @throws IllegalArgumentException
        */
       public void setAttribute(String name, Object value) 
  -     throws IllegalArgumentException { 
  +     throws IllegalArgumentException 
  +    { 
        // Set the default translet name (ie. class name), which will be used
        // for translets that cannot be given a name from their system-id.
  -     if ((name.equals("translet-name")) && (value instanceof String)) {
  -         _defaultTransletName = (String)value;
  +     if (name.equals("translet-name") && value instanceof String) {
  +         _defaultTransletName = (String) value;
  +         return;
        }
        else if (name.equals("debug")) {
  -         _debug = true;
  +         if (value instanceof Boolean) {
  +             _debug = ((Boolean) value).booleanValue();
  +             return;
  +         }
  +         else if (value instanceof String) {
  +             _debug = ((String) value).equalsIgnoreCase("true");
  +             return;
  +         }
        }
  -     else if (name.equals("disable-inlining") && value instanceof Boolean) {
  -         _disableInlining = ((Boolean) value).booleanValue();
  +     else if (name.equals("disable-inlining")) {
  +         if (value instanceof Boolean) {
  +             _disableInlining = ((Boolean) value).booleanValue();
  +             return;
  +         }
  +         else if (value instanceof String) {
  +             _disableInlining = ((String) value).equalsIgnoreCase("true");
  +             return;
  +         }
        }
  -     else if (name.equals("old-output") && value instanceof Boolean) {
  -         _oldOutputSystem = ((Boolean) value).booleanValue();
  +     else if (name.equals("old-output")) {
  +         if (value instanceof Boolean) {
  +             _oldOutputSystem = ((Boolean) value).booleanValue();
  +             return;
  +         }
  +         else if (value instanceof String) {
  +             _oldOutputSystem = ((String) value).equalsIgnoreCase("true");
  +             return;
  +         }
        }
  -     else {
  -         // Throw an exception for all other attributes
  -         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
  -         throw new IllegalArgumentException(err.toString());
  +     else if (name.equals("indent-number")) {
  +         if (value instanceof String) {
  +             try {
  +                 _indentNumber = Integer.parseInt((String) value);
  +                 return;
  +             }
  +             catch (NumberFormatException e) {
  +                 // Falls through
  +             }
  +         }
  +         else if (value instanceof Integer) {
  +             _indentNumber = ((Integer) value).intValue();
  +             return;
  +         }
        }
  +
  +     // Throw an exception for all other attributes
  +     final ErrorMsg err 
  +         = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
  +     throw new IllegalArgumentException(err.toString());
       }
   
       /**
  @@ -346,7 +385,8 @@
   
        // Create a Transformer object and store for other calls
        Templates templates = new TemplatesImpl(bytecodes, _defaultTransletName,
  -         xsltc.getOutputProperties(), _oldOutputSystem);
  +         xsltc.getOutputProperties(), _indentNumber, _oldOutputSystem);
  +
        _copyTransformer = templates.newTransformer();
        if (_uriResolver != null) {
            _copyTransformer.setURIResolver(_uriResolver);
  @@ -534,7 +574,7 @@
            throw new TransformerConfigurationException(err.toString());
        }
        return new TemplatesImpl(bytecodes, transletName, 
  -         xsltc.getOutputProperties(), _oldOutputSystem);
  +         xsltc.getOutputProperties(), _indentNumber, _oldOutputSystem);
       }
   
       /**
  @@ -548,7 +588,7 @@
       public TemplatesHandler newTemplatesHandler() 
        throws TransformerConfigurationException { 
        final TemplatesHandlerImpl handler = 
  -         new TemplatesHandlerImpl(_oldOutputSystem);
  +         new TemplatesHandlerImpl(_indentNumber, _oldOutputSystem);
        handler.init();
        return handler;
       }
  
  
  
  1.51      +11 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- TransformerImpl.java      20 Jun 2002 21:59:59 -0000      1.50
  +++ TransformerImpl.java      26 Jun 2002 22:55:07 -0000      1.51
  @@ -104,6 +104,7 @@
   import org.apache.xalan.xsltc.TransletOutputHandler;
   import org.apache.xalan.xsltc.DOMCache;
   import org.apache.xalan.xsltc.dom.*;
  +import org.apache.xalan.xsltc.compiler.Constants;
   import org.apache.xalan.xsltc.runtime.*;
   import org.apache.xalan.xsltc.runtime.output.*;
   import org.apache.xalan.xsltc.compiler.*;
  @@ -141,6 +142,8 @@
       
       private TransletOutputHandlerFactory _tohFactory = null;
   
  +    private int _indentNumber;
  +
       // Temporary
       private boolean _oldOutputSystem;
   
  @@ -149,12 +152,13 @@
        * Our Transformer objects always need a translet to do the actual work
        */
       protected TransformerImpl(Translet translet, Properties outputProperties,
  -     boolean oldOutputSystem) 
  +     int indentNumber, boolean oldOutputSystem) 
       {
        _translet = (AbstractTranslet) translet;
        _properties = createOutputProperties(outputProperties);
        _oldOutputSystem = oldOutputSystem;
        _propertiesClone = (Properties) _properties.clone();
  +     _indentNumber = indentNumber;
       }
   
       /**
  @@ -240,6 +244,11 @@
        _tohFactory.setEncoding(_encoding);
        if (_method != null) {
            _tohFactory.setOutputMethod(_method);
  +     }
  +
  +     // Set indentation number in the factory
  +     if (_indentNumber >= 0) {
  +         _tohFactory.setIndentNumber(_indentNumber);
        }
   
        // Return the content handler for this Result object
  
  
  

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

Reply via email to