src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.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: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.trax;
  25 
  26 import com.sun.org.apache.xalan.internal.XalanConstants;
  27 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
  28 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
  29 import java.io.File;
  30 import java.io.FileOutputStream;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.io.OutputStream;
  34 import java.io.Reader;
  35 import java.io.Writer;
  36 import java.net.URI;
  37 import java.net.URL;
  38 import java.net.URLConnection;
  39 import java.net.UnknownServiceException;
  40 import java.util.Enumeration;
  41 import java.util.Properties;
  42 import java.util.StringTokenizer;
  43 import java.util.Vector;
  44 import java.lang.reflect.Constructor;
  45 
  46 import javax.xml.parsers.DocumentBuilder;
  47 import javax.xml.parsers.DocumentBuilderFactory;
  48 import javax.xml.parsers.ParserConfigurationException;
  49 import javax.xml.stream.XMLEventReader;
  50 import javax.xml.stream.XMLStreamReader;
  51 import javax.xml.transform.ErrorListener;
  52 import javax.xml.transform.OutputKeys;
  53 import javax.xml.transform.Result;
  54 import javax.xml.transform.Source;
  55 import javax.xml.transform.Transformer;
  56 import javax.xml.transform.TransformerException;
  57 import javax.xml.transform.URIResolver;
  58 import javax.xml.transform.dom.DOMResult;
  59 import javax.xml.transform.dom.DOMSource;
  60 import javax.xml.transform.sax.SAXResult;
  61 import javax.xml.transform.sax.SAXSource;
  62 import javax.xml.transform.stax.StAXResult;
  63 import javax.xml.transform.stax.StAXSource;


1067                     value != null && value.toLowerCase().equals("yes"));
1068             }
1069             else if (name.equals(OutputPropertiesFactory.S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL +"indent-amount")) {
1070                 if (value != null) {
1071                     handler.setIndentAmount(Integer.parseInt(value));
1072                 }
1073             }
1074             else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) {
1075                 if (value != null) {
1076                     handler.setIndentAmount(Integer.parseInt(value));
1077                 }
1078             }
1079             else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
1080                 if (value != null && value.equals("yes")) {
1081                     handler.setIsStandalone(true);
1082                 }
1083             }
1084             else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
1085                 if (value != null) {
1086                     StringTokenizer e = new StringTokenizer(value);
1087                     Vector uriAndLocalNames = null;
1088                     while (e.hasMoreTokens()) {
1089                         final String token = e.nextToken();
1090 
1091                         // look for the last colon, as the String may be
1092                         // something like "http://abc.com:local"
1093                         int lastcolon = token.lastIndexOf(':');
1094                         String uri;
1095                         String localName;
1096                         if (lastcolon > 0) {
1097                             uri = token.substring(0, lastcolon);
1098                             localName = token.substring(lastcolon+1);
1099                         } else {
1100                             // no colon at all, lets hope this is the
1101                             // local name itself then
1102                             uri = null;
1103                             localName = token;
1104                         }
1105 
1106                         if (uriAndLocalNames == null) {
1107                             uriAndLocalNames = new Vector();
1108                         }
1109                         // add the uri/localName as a pair, in that order
1110                         uriAndLocalNames.addElement(uri);
1111                         uriAndLocalNames.addElement(localName);
1112                     }
1113                     handler.setCdataSectionElements(uriAndLocalNames);
1114                 }
1115             }
1116         }
1117 
1118         // Call setDoctype() if needed
1119         if (doctypePublic != null || doctypeSystem != null) {
1120             handler.setDoctype(doctypeSystem, doctypePublic);
1121         }
1122     }
1123 
1124     /**
1125      * Internal method to create the initial set of properties. There
1126      * are two layers of properties: the default layer and the base layer.
1127      * The latter contains properties defined in the stylesheet or by
1128      * the user using this API.
1129      */
1130     private Properties createOutputProperties(Properties outputProperties) {
1131         final Properties defaults = new Properties();


   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: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $
  24  */
  25 
  26 package com.sun.org.apache.xalan.internal.xsltc.trax;
  27 
  28 import com.sun.org.apache.xalan.internal.XalanConstants;
  29 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
  30 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
  31 import java.io.File;
  32 import java.io.FileOutputStream;
  33 import java.io.IOException;
  34 import java.io.InputStream;
  35 import java.io.OutputStream;
  36 import java.io.Reader;
  37 import java.io.Writer;
  38 import java.net.URI;
  39 import java.net.URL;
  40 import java.net.URLConnection;
  41 import java.net.UnknownServiceException;
  42 import java.util.Enumeration;
  43 import java.util.Properties;
  44 import java.util.StringTokenizer;
  45 import java.util.ArrayList;
  46 import java.lang.reflect.Constructor;
  47 
  48 import javax.xml.parsers.DocumentBuilder;
  49 import javax.xml.parsers.DocumentBuilderFactory;
  50 import javax.xml.parsers.ParserConfigurationException;
  51 import javax.xml.stream.XMLEventReader;
  52 import javax.xml.stream.XMLStreamReader;
  53 import javax.xml.transform.ErrorListener;
  54 import javax.xml.transform.OutputKeys;
  55 import javax.xml.transform.Result;
  56 import javax.xml.transform.Source;
  57 import javax.xml.transform.Transformer;
  58 import javax.xml.transform.TransformerException;
  59 import javax.xml.transform.URIResolver;
  60 import javax.xml.transform.dom.DOMResult;
  61 import javax.xml.transform.dom.DOMSource;
  62 import javax.xml.transform.sax.SAXResult;
  63 import javax.xml.transform.sax.SAXSource;
  64 import javax.xml.transform.stax.StAXResult;
  65 import javax.xml.transform.stax.StAXSource;


1069                     value != null && value.toLowerCase().equals("yes"));
1070             }
1071             else if (name.equals(OutputPropertiesFactory.S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL +"indent-amount")) {
1072                 if (value != null) {
1073                     handler.setIndentAmount(Integer.parseInt(value));
1074                 }
1075             }
1076             else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) {
1077                 if (value != null) {
1078                     handler.setIndentAmount(Integer.parseInt(value));
1079                 }
1080             }
1081             else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) {
1082                 if (value != null && value.equals("yes")) {
1083                     handler.setIsStandalone(true);
1084                 }
1085             }
1086             else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
1087                 if (value != null) {
1088                     StringTokenizer e = new StringTokenizer(value);
1089                     ArrayList<String> uriAndLocalNames = null;
1090                     while (e.hasMoreTokens()) {
1091                         final String token = e.nextToken();
1092 
1093                         // look for the last colon, as the String may be
1094                         // something like "http://abc.com:local"
1095                         int lastcolon = token.lastIndexOf(':');
1096                         String uri;
1097                         String localName;
1098                         if (lastcolon > 0) {
1099                             uri = token.substring(0, lastcolon);
1100                             localName = token.substring(lastcolon+1);
1101                         } else {
1102                             // no colon at all, lets hope this is the
1103                             // local name itself then
1104                             uri = null;
1105                             localName = token;
1106                         }
1107 
1108                         if (uriAndLocalNames == null) {
1109                             uriAndLocalNames = new ArrayList<>();
1110                         }
1111                         // add the uri/localName as a pair, in that order
1112                         uriAndLocalNames.add(uri);
1113                         uriAndLocalNames.add(localName);
1114                     }
1115                     handler.setCdataSectionElements(uriAndLocalNames);
1116                 }
1117             }
1118         }
1119 
1120         // Call setDoctype() if needed
1121         if (doctypePublic != null || doctypeSystem != null) {
1122             handler.setDoctype(doctypeSystem, doctypePublic);
1123         }
1124     }
1125 
1126     /**
1127      * Internal method to create the initial set of properties. There
1128      * are two layers of properties: the default layer and the base layer.
1129      * The latter contains properties defined in the stylesheet or by
1130      * the user using this API.
1131      */
1132     private Properties createOutputProperties(Properties outputProperties) {
1133         final Properties defaults = new Properties();