src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");


   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: AbstractTranslet.java,v 1.6 2006/06/19 19:49:03 spericas Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.runtime;
  25 
  26 import com.sun.org.apache.xalan.internal.XalanConstants;
  27 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
  28 import java.io.File;
  29 import java.io.FileOutputStream;
  30 import java.io.BufferedOutputStream;
  31 import java.text.DecimalFormat;
  32 import java.text.DecimalFormatSymbols;
  33 import java.util.ArrayList;
  34 import java.util.Enumeration;
  35 import java.util.Vector;
  36 import javax.xml.transform.Templates;
  37 import javax.xml.parsers.DocumentBuilderFactory;
  38 import org.w3c.dom.Document;
  39 import org.w3c.dom.DOMImplementation;
  40 import javax.xml.parsers.ParserConfigurationException;
  41 
  42 import com.sun.org.apache.xml.internal.dtm.DTM;
  43 
  44 import com.sun.org.apache.xalan.internal.xsltc.DOM;
  45 import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
  46 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
  47 import com.sun.org.apache.xalan.internal.xsltc.Translet;
  48 import com.sun.org.apache.xalan.internal.xsltc.TransletException;
  49 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
  50 import com.sun.org.apache.xalan.internal.xsltc.dom.KeyIndex;
  51 import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
  52 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  53 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;

  54 
  55 /**
  56  * @author Jacek Ambroziak
  57  * @author Santiago Pericas-Geertsen
  58  * @author Morten Jorgensen
  59  * @author G. Todd Miller
  60  * @author John Howard, JohnH@schemasoft.com
  61  */
  62 public abstract class AbstractTranslet implements Translet {
  63 
  64     // These attributes are extracted from the xsl:output element. They also
  65     // appear as fields (with the same type, only public) in Output.java
  66     public String  _version = "1.0";
  67     public String  _method = null;
  68     public String  _encoding = "UTF-8";
  69     public boolean _omitHeader = false;
  70     public String  _standalone = null;
  71     //see OutputPropertiesFactory.ORACLE_IS_STANDALONE
  72     public boolean  _isStandalone = false;
  73     public String  _doctypePublic = null;
  74     public String  _doctypeSystem = null;
  75     public boolean _indent = false;
  76     public String  _mediaType = null;
  77     public Vector _cdata = null;
  78     public int _indentamount = -1;
  79 
  80     public static final int FIRST_TRANSLET_VERSION = 100;
  81     public static final int VER_SPLIT_NAMES_ARRAY = 101;
  82     public static final int CURRENT_TRANSLET_VERSION = VER_SPLIT_NAMES_ARRAY;
  83 
  84     // Initialize Translet version field to base value.  A class that extends
  85     // AbstractTranslet may override this value to a more recent translet
  86     // version; if it doesn't override the value (because it was compiled
  87     // before the notion of a translet version was introduced, it will get
  88     // this default value).
  89     protected int transletVersion = FIRST_TRANSLET_VERSION;
  90 
  91     // DOM/translet handshaking - the arrays are set by the compiled translet
  92     protected String[] namesArray;
  93     protected String[] urisArray;
  94     protected int[]    typesArray;
  95     protected String[] namespaceArray;
  96 
  97     // The Templates object that is used to create this Translet instance


 625      * output handler
 626      */
 627     public final void characters(final String string,
 628                                  SerializationHandler handler)
 629         throws TransletException {
 630         if (string != null) {
 631            //final int length = string.length();
 632            try {
 633                handler.characters(string);
 634            } catch (Exception e) {
 635                throw new TransletException(e);
 636            }
 637         }
 638     }
 639 
 640     /**
 641      * Add's a name of an element whose text contents should be output as CDATA
 642      */
 643     public void addCdataElement(String name) {
 644         if (_cdata == null) {
 645             _cdata = new Vector();
 646         }
 647 
 648         int lastColon = name.lastIndexOf(':');
 649 
 650         if (lastColon > 0) {
 651             String uri = name.substring(0, lastColon);
 652             String localName = name.substring(lastColon+1);
 653             _cdata.addElement(uri);
 654             _cdata.addElement(localName);
 655         } else {
 656             _cdata.addElement(null);
 657             _cdata.addElement(name);
 658         }
 659     }
 660 
 661     /**
 662      * Transfer the output settings to the output post-processor
 663      */
 664     protected void transferOutputSettings(SerializationHandler handler) {
 665         if (_method != null) {
 666             if (_method.equals("xml")) {
 667                 if (_standalone != null) {
 668                     handler.setStandalone(_standalone);
 669                 }
 670                 if (_omitHeader) {
 671                     handler.setOmitXMLDeclaration(true);
 672                 }
 673                 handler.setCdataSectionElements(_cdata);
 674                 if (_version != null) {
 675                     handler.setVersion(_version);
 676                 }
 677                 handler.setIndent(_indent);


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one
   7  * or more contributor license agreements. See the NOTICE file
   8  * distributed with this work for additional information
   9  * regarding copyright ownership. The ASF licenses this file
  10  * to you under the Apache License, Version 2.0 (the  "License");
  11  * you may not use this file except in compliance with the License.
  12  * You may obtain a copy of the License at
  13  *
  14  *     http://www.apache.org/licenses/LICENSE-2.0
  15  *
  16  * Unless required by applicable law or agreed to in writing, software
  17  * distributed under the License is distributed on an "AS IS" BASIS,
  18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19  * See the License for the specific language governing permissions and
  20  * limitations under the License.
  21  */
  22 /*
  23  * $Id: AbstractTranslet.java,v 1.6 2006/06/19 19:49:03 spericas Exp $
  24  */
  25 
  26 package com.sun.org.apache.xalan.internal.xsltc.runtime;
  27 
  28 import com.sun.org.apache.xalan.internal.XalanConstants;
  29 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
  30 import java.io.File;
  31 import java.io.FileOutputStream;
  32 import java.io.BufferedOutputStream;
  33 import java.text.DecimalFormat;
  34 import java.text.DecimalFormatSymbols;
  35 import java.util.ArrayList;
  36 import java.util.Enumeration;

  37 import javax.xml.transform.Templates;
  38 import javax.xml.parsers.DocumentBuilderFactory;
  39 import org.w3c.dom.Document;
  40 import org.w3c.dom.DOMImplementation;
  41 import javax.xml.parsers.ParserConfigurationException;
  42 
  43 import com.sun.org.apache.xml.internal.dtm.DTM;
  44 
  45 import com.sun.org.apache.xalan.internal.xsltc.DOM;
  46 import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
  47 import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
  48 import com.sun.org.apache.xalan.internal.xsltc.Translet;
  49 import com.sun.org.apache.xalan.internal.xsltc.TransletException;
  50 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
  51 import com.sun.org.apache.xalan.internal.xsltc.dom.KeyIndex;
  52 import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
  53 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  54 import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
  55 import com.sun.org.apache.xml.internal.serializer.ToStream;
  56 
  57 /**
  58  * @author Jacek Ambroziak
  59  * @author Santiago Pericas-Geertsen
  60  * @author Morten Jorgensen
  61  * @author G. Todd Miller
  62  * @author John Howard, JohnH@schemasoft.com
  63  */
  64 public abstract class AbstractTranslet implements Translet {
  65 
  66     // These attributes are extracted from the xsl:output element. They also
  67     // appear as fields (with the same type, only public) in Output.java
  68     public String  _version = "1.0";
  69     public String  _method = null;
  70     public String  _encoding = "UTF-8";
  71     public boolean _omitHeader = false;
  72     public String  _standalone = null;
  73     //see OutputPropertiesFactory.ORACLE_IS_STANDALONE
  74     public boolean  _isStandalone = false;
  75     public String  _doctypePublic = null;
  76     public String  _doctypeSystem = null;
  77     public boolean _indent = false;
  78     public String  _mediaType = null;
  79     public ArrayList<String> _cdata = null;
  80     public int _indentamount = -1;
  81 
  82     public static final int FIRST_TRANSLET_VERSION = 100;
  83     public static final int VER_SPLIT_NAMES_ARRAY = 101;
  84     public static final int CURRENT_TRANSLET_VERSION = VER_SPLIT_NAMES_ARRAY;
  85 
  86     // Initialize Translet version field to base value.  A class that extends
  87     // AbstractTranslet may override this value to a more recent translet
  88     // version; if it doesn't override the value (because it was compiled
  89     // before the notion of a translet version was introduced, it will get
  90     // this default value).
  91     protected int transletVersion = FIRST_TRANSLET_VERSION;
  92 
  93     // DOM/translet handshaking - the arrays are set by the compiled translet
  94     protected String[] namesArray;
  95     protected String[] urisArray;
  96     protected int[]    typesArray;
  97     protected String[] namespaceArray;
  98 
  99     // The Templates object that is used to create this Translet instance


 627      * output handler
 628      */
 629     public final void characters(final String string,
 630                                  SerializationHandler handler)
 631         throws TransletException {
 632         if (string != null) {
 633            //final int length = string.length();
 634            try {
 635                handler.characters(string);
 636            } catch (Exception e) {
 637                throw new TransletException(e);
 638            }
 639         }
 640     }
 641 
 642     /**
 643      * Add's a name of an element whose text contents should be output as CDATA
 644      */
 645     public void addCdataElement(String name) {
 646         if (_cdata == null) {
 647             _cdata = new ArrayList<>();
 648         }
 649 
 650         int lastColon = name.lastIndexOf(':');
 651 
 652         if (lastColon > 0) {
 653             String uri = name.substring(0, lastColon);
 654             String localName = name.substring(lastColon+1);
 655             _cdata.add(uri);
 656             _cdata.add(localName);
 657         } else {
 658             _cdata.add(null);
 659             _cdata.add(name);
 660         }
 661     }
 662 
 663     /**
 664      * Transfer the output settings to the output post-processor
 665      */
 666     protected void transferOutputSettings(SerializationHandler handler) {
 667         if (_method != null) {
 668             if (_method.equals("xml")) {
 669                 if (_standalone != null) {
 670                     handler.setStandalone(_standalone);
 671                 }
 672                 if (_omitHeader) {
 673                     handler.setOmitXMLDeclaration(true);
 674                 }
 675                 handler.setCdataSectionElements(_cdata);
 676                 if (_version != null) {
 677                     handler.setVersion(_version);
 678                 }
 679                 handler.setIndent(_indent);