KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > processor > ProcessorOutputElem


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ProcessorOutputElem.java,v 1.18 2004/02/11 18:15:50 minchau Exp $
18  */

19 package org.apache.xalan.processor;
20
21 import javax.xml.transform.OutputKeys JavaDoc;
22 import javax.xml.transform.TransformerException JavaDoc;
23
24 import org.apache.xalan.templates.ElemTemplateElement;
25 import org.apache.xalan.templates.OutputProperties;
26 import org.apache.xml.serializer.OutputPropertiesFactory;
27 import org.apache.xml.utils.QName;
28 import org.apache.xml.utils.SystemIDResolver;
29 import org.xml.sax.Attributes JavaDoc;
30
31 /**
32  * TransformerFactory for xsl:output markup.
33  * @see <a HREF="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
34  * @see <a HREF="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
35  */

36 class ProcessorOutputElem extends XSLTElementProcessor
37 {
38
39   /** The output properties, set temporarily while the properties are
40    * being set from the attributes, and then nulled after that operation
41    * is completed. */

42   private OutputProperties m_outputProperties;
43
44   /**
45    * Set the cdata-section-elements property from the attribute value.
46    * @see javax.xml.transform.OutputKeys#CDATA_SECTION_ELEMENTS
47    * @param newValue non-null reference to processed attribute value.
48    */

49   public void setCdataSectionElements(java.util.Vector JavaDoc newValue)
50   {
51     m_outputProperties.setQNameProperties(OutputKeys.CDATA_SECTION_ELEMENTS, newValue);
52   }
53
54   /**
55    * Set the doctype-public property from the attribute value.
56    * @see javax.xml.transform.OutputKeys#DOCTYPE_PUBLIC
57    * @param newValue non-null reference to processed attribute value.
58    */

59   public void setDoctypePublic(String JavaDoc newValue)
60   {
61     m_outputProperties.setProperty(OutputKeys.DOCTYPE_PUBLIC, newValue);
62   }
63
64   /**
65    * Set the doctype-system property from the attribute value.
66    * @see javax.xml.transform.OutputKeys#DOCTYPE_SYSTEM
67    * @param newValue non-null reference to processed attribute value.
68    */

69   public void setDoctypeSystem(String JavaDoc newValue)
70   {
71     m_outputProperties.setProperty(OutputKeys.DOCTYPE_SYSTEM, newValue);
72   }
73
74   /**
75    * Set the encoding property from the attribute value.
76    * @see javax.xml.transform.OutputKeys#ENCODING
77    * @param newValue non-null reference to processed attribute value.
78    */

79   public void setEncoding(String JavaDoc newValue)
80   {
81     m_outputProperties.setProperty(OutputKeys.ENCODING, newValue);
82   }
83
84   /**
85    * Set the indent property from the attribute value.
86    * @see javax.xml.transform.OutputKeys#INDENT
87    * @param newValue non-null reference to processed attribute value.
88    */

89   public void setIndent(boolean newValue)
90   {
91     m_outputProperties.setBooleanProperty(OutputKeys.INDENT, newValue);
92   }
93
94   /**
95    * Set the media type property from the attribute value.
96    * @see javax.xml.transform.OutputKeys#MEDIA_TYPE
97    * @param newValue non-null reference to processed attribute value.
98    */

99   public void setMediaType(String JavaDoc newValue)
100   {
101     m_outputProperties.setProperty(OutputKeys.MEDIA_TYPE, newValue);
102   }
103
104   /**
105    * Set the method property from the attribute value.
106    * @see javax.xml.transform.OutputKeys#METHOD
107    * @param newValue non-null reference to processed attribute value.
108    */

109   public void setMethod(org.apache.xml.utils.QName newValue)
110   {
111     m_outputProperties.setQNameProperty(OutputKeys.METHOD, newValue);
112   }
113
114   /**
115    * Set the omit-xml-declaration property from the attribute value.
116    * @see javax.xml.transform.OutputKeys#OMIT_XML_DECLARATION
117    * @param newValue processed attribute value.
118    */

119   public void setOmitXmlDeclaration(boolean newValue)
120   {
121     m_outputProperties.setBooleanProperty(OutputKeys.OMIT_XML_DECLARATION, newValue);
122   }
123
124   /**
125    * Set the standalone property from the attribute value.
126    * @see javax.xml.transform.OutputKeys#STANDALONE
127    * @param newValue processed attribute value.
128    */

129   public void setStandalone(boolean newValue)
130   {
131     m_outputProperties.setBooleanProperty(OutputKeys.STANDALONE, newValue);
132   }
133
134   /**
135    * Set the version property from the attribute value.
136    * @see javax.xml.transform.OutputKeys#VERSION
137    * @param newValue non-null reference to processed attribute value.
138    */

139   public void setVersion(String JavaDoc newValue)
140   {
141     m_outputProperties.setProperty(OutputKeys.VERSION, newValue);
142   }
143   
144   /**
145    * Set a foreign property from the attribute value.
146    * @param newValue non-null reference to attribute value.
147    */

148   public void setForeignAttr(String JavaDoc attrUri, String JavaDoc attrLocalName, String JavaDoc attrRawName, String JavaDoc attrValue)
149   {
150     QName key = new QName(attrUri, attrLocalName);
151     m_outputProperties.setProperty(key, attrValue);
152   }
153   
154   /**
155    * Set a foreign property from the attribute value.
156    * @param newValue non-null reference to attribute value.
157    */

158   public void addLiteralResultAttribute(String JavaDoc attrUri, String JavaDoc attrLocalName, String JavaDoc attrRawName, String JavaDoc attrValue)
159   {
160     QName key = new QName(attrUri, attrLocalName);
161     m_outputProperties.setProperty(key, attrValue);
162   }
163
164   /**
165    * Receive notification of the start of an xsl:output element.
166    *
167    * @param handler The calling StylesheetHandler/TemplatesBuilder.
168    * @param uri The Namespace URI, or the empty string if the
169    * element has no Namespace URI or if Namespace
170    * processing is not being performed.
171    * @param localName The local name (without prefix), or the
172    * empty string if Namespace processing is not being
173    * performed.
174    * @param rawName The raw XML 1.0 name (with prefix), or the
175    * empty string if raw names are not available.
176    * @param attributes The attributes attached to the element. If
177    * there are no attributes, it shall be an empty
178    * Attributes object.
179    *
180    * @throws org.xml.sax.SAXException
181    */

182   public void startElement(
183           StylesheetHandler handler, String JavaDoc uri, String JavaDoc localName, String JavaDoc rawName, Attributes JavaDoc attributes)
184             throws org.xml.sax.SAXException JavaDoc
185   {
186     // Hmmm... for the moment I don't think I'll have default properties set for this. -sb
187
m_outputProperties = new OutputProperties();
188
189     m_outputProperties.setDOMBackPointer(handler.getOriginatingNode());
190     m_outputProperties.setLocaterInfo(handler.getLocator());
191     m_outputProperties.setUid(handler.nextUid());
192     setPropertiesFromAttributes(handler, rawName, attributes, this);
193     
194     // Access this only from the Hashtable level... we don't want to
195
// get default properties.
196
String JavaDoc entitiesFileName =
197       (String JavaDoc) m_outputProperties.getProperties().get(OutputPropertiesFactory.S_KEY_ENTITIES);
198
199     if (null != entitiesFileName)
200     {
201       try
202       {
203         String JavaDoc absURL = SystemIDResolver.getAbsoluteURI(entitiesFileName,
204                     handler.getBaseIdentifier());
205         m_outputProperties.getProperties().put(OutputPropertiesFactory.S_KEY_ENTITIES, absURL);
206       }
207       catch(TransformerException JavaDoc te)
208       {
209         handler.error(te.getMessage(), te);
210       }
211     }
212     
213     handler.getStylesheet().setOutput(m_outputProperties);
214     
215     ElemTemplateElement parent = handler.getElemTemplateElement();
216     parent.appendChild(m_outputProperties);
217     
218     m_outputProperties = null;
219   }
220 }
221
Popular Tags