• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id: ProcessorOutputElem.java 468640 2006-10-28 06:53:53Z minchau $
20  */
21 package org.apache.xalan.processor;
22 
23 import javax.xml.transform.OutputKeys;
24 import javax.xml.transform.TransformerException;
25 
26 import org.apache.xalan.templates.ElemTemplateElement;
27 import org.apache.xalan.templates.OutputProperties;
28 import org.apache.xml.serializer.OutputPropertiesFactory;
29 import org.apache.xml.utils.QName;
30 import org.apache.xml.utils.SystemIDResolver;
31 import org.xml.sax.Attributes;
32 
33 /**
34  * TransformerFactory for xsl:output markup.
35  * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
36  * @see <a href="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
37  */
38 class ProcessorOutputElem extends XSLTElementProcessor
39 {
40     static final long serialVersionUID = 3513742319582547590L;
41 
42   /** The output properties, set temporarily while the properties are
43    *  being set from the attributes, and then nulled after that operation
44    *  is completed.  */
45   private OutputProperties m_outputProperties;
46 
47   /**
48    * Set the cdata-section-elements property from the attribute value.
49    * @see javax.xml.transform.OutputKeys#CDATA_SECTION_ELEMENTS
50    * @param newValue non-null reference to processed attribute value.
51    */
setCdataSectionElements(java.util.Vector newValue)52   public void setCdataSectionElements(java.util.Vector newValue)
53   {
54     m_outputProperties.setQNameProperties(OutputKeys.CDATA_SECTION_ELEMENTS, newValue);
55   }
56 
57   /**
58    * Set the doctype-public property from the attribute value.
59    * @see javax.xml.transform.OutputKeys#DOCTYPE_PUBLIC
60    * @param newValue non-null reference to processed attribute value.
61    */
setDoctypePublic(String newValue)62   public void setDoctypePublic(String newValue)
63   {
64     m_outputProperties.setProperty(OutputKeys.DOCTYPE_PUBLIC, newValue);
65   }
66 
67   /**
68    * Set the doctype-system property from the attribute value.
69    * @see javax.xml.transform.OutputKeys#DOCTYPE_SYSTEM
70    * @param newValue non-null reference to processed attribute value.
71    */
setDoctypeSystem(String newValue)72   public void setDoctypeSystem(String newValue)
73   {
74     m_outputProperties.setProperty(OutputKeys.DOCTYPE_SYSTEM, newValue);
75   }
76 
77   /**
78    * Set the encoding property from the attribute value.
79    * @see javax.xml.transform.OutputKeys#ENCODING
80    * @param newValue non-null reference to processed attribute value.
81    */
setEncoding(String newValue)82   public void setEncoding(String newValue)
83   {
84     m_outputProperties.setProperty(OutputKeys.ENCODING, newValue);
85   }
86 
87   /**
88    * Set the indent property from the attribute value.
89    * @see javax.xml.transform.OutputKeys#INDENT
90    * @param newValue non-null reference to processed attribute value.
91    */
setIndent(boolean newValue)92   public void setIndent(boolean newValue)
93   {
94     m_outputProperties.setBooleanProperty(OutputKeys.INDENT, newValue);
95   }
96 
97   /**
98    * Set the media type property from the attribute value.
99    * @see javax.xml.transform.OutputKeys#MEDIA_TYPE
100    * @param newValue non-null reference to processed attribute value.
101    */
setMediaType(String newValue)102   public void setMediaType(String newValue)
103   {
104     m_outputProperties.setProperty(OutputKeys.MEDIA_TYPE, newValue);
105   }
106 
107   /**
108    * Set the method property from the attribute value.
109    * @see javax.xml.transform.OutputKeys#METHOD
110    * @param newValue non-null reference to processed attribute value.
111    */
setMethod(org.apache.xml.utils.QName newValue)112   public void setMethod(org.apache.xml.utils.QName newValue)
113   {
114     m_outputProperties.setQNameProperty(OutputKeys.METHOD, newValue);
115   }
116 
117   /**
118    * Set the omit-xml-declaration property from the attribute value.
119    * @see javax.xml.transform.OutputKeys#OMIT_XML_DECLARATION
120    * @param newValue processed attribute value.
121    */
setOmitXmlDeclaration(boolean newValue)122   public void setOmitXmlDeclaration(boolean newValue)
123   {
124     m_outputProperties.setBooleanProperty(OutputKeys.OMIT_XML_DECLARATION, newValue);
125   }
126 
127   /**
128    * Set the standalone property from the attribute value.
129    * @see javax.xml.transform.OutputKeys#STANDALONE
130    * @param newValue processed attribute value.
131    */
setStandalone(boolean newValue)132   public void setStandalone(boolean newValue)
133   {
134     m_outputProperties.setBooleanProperty(OutputKeys.STANDALONE, newValue);
135   }
136 
137   /**
138    * Set the version property from the attribute value.
139    * @see javax.xml.transform.OutputKeys#VERSION
140    * @param newValue non-null reference to processed attribute value.
141    */
setVersion(String newValue)142   public void setVersion(String newValue)
143   {
144     m_outputProperties.setProperty(OutputKeys.VERSION, newValue);
145   }
146 
147   /**
148    * Set a foreign property from the attribute value.
149    * @param newValue non-null reference to attribute value.
150    */
setForeignAttr(String attrUri, String attrLocalName, String attrRawName, String attrValue)151   public void setForeignAttr(String attrUri, String attrLocalName, String attrRawName, String attrValue)
152   {
153     QName key = new QName(attrUri, attrLocalName);
154     m_outputProperties.setProperty(key, attrValue);
155   }
156 
157   /**
158    * Set a foreign property from the attribute value.
159    * @param newValue non-null reference to attribute value.
160    */
addLiteralResultAttribute(String attrUri, String attrLocalName, String attrRawName, String attrValue)161   public void addLiteralResultAttribute(String attrUri, String attrLocalName, String attrRawName, String attrValue)
162   {
163     QName key = new QName(attrUri, attrLocalName);
164     m_outputProperties.setProperty(key, attrValue);
165   }
166 
167   /**
168    * Receive notification of the start of an xsl:output element.
169    *
170    * @param handler The calling StylesheetHandler/TemplatesBuilder.
171    * @param uri The Namespace URI, or the empty string if the
172    *        element has no Namespace URI or if Namespace
173    *        processing is not being performed.
174    * @param localName The local name (without prefix), or the
175    *        empty string if Namespace processing is not being
176    *        performed.
177    * @param rawName The raw XML 1.0 name (with prefix), or the
178    *        empty string if raw names are not available.
179    * @param attributes The attributes attached to the element.  If
180    *        there are no attributes, it shall be an empty
181    *        Attributes object.
182    *
183    * @throws org.xml.sax.SAXException
184    */
startElement( StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)185   public void startElement(
186           StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
187             throws org.xml.sax.SAXException
188   {
189     // Hmmm... for the moment I don't think I'll have default properties set for this. -sb
190     m_outputProperties = new OutputProperties();
191 
192     m_outputProperties.setDOMBackPointer(handler.getOriginatingNode());
193     m_outputProperties.setLocaterInfo(handler.getLocator());
194     m_outputProperties.setUid(handler.nextUid());
195     setPropertiesFromAttributes(handler, rawName, attributes, this);
196 
197     // Access this only from the Hashtable level... we don't want to
198     // get default properties.
199     String entitiesFileName =
200       (String) m_outputProperties.getProperties().get(OutputPropertiesFactory.S_KEY_ENTITIES);
201 
202     if (null != entitiesFileName)
203     {
204       try
205       {
206         String absURL = SystemIDResolver.getAbsoluteURI(entitiesFileName,
207                     handler.getBaseIdentifier());
208         m_outputProperties.getProperties().put(OutputPropertiesFactory.S_KEY_ENTITIES, absURL);
209       }
210       catch(TransformerException te)
211       {
212         handler.error(te.getMessage(), te);
213       }
214     }
215 
216     handler.getStylesheet().setOutput(m_outputProperties);
217 
218     ElemTemplateElement parent = handler.getElemTemplateElement();
219     parent.appendChild(m_outputProperties);
220 
221     m_outputProperties = null;
222   }
223 }
224