1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.processor;
  58. import javax.xml.transform.OutputKeys;
  59. import java.util.Hashtable;
  60. import org.apache.xalan.templates.OutputProperties;
  61. import org.apache.xalan.templates.StylesheetRoot;
  62. import org.apache.xalan.templates.Stylesheet;
  63. import org.apache.xalan.templates.ElemTemplateElement;
  64. import org.apache.xml.utils.QName;
  65. import org.apache.xml.utils.SystemIDResolver;
  66. import javax.xml.transform.TransformerException;
  67. import org.xml.sax.Attributes;
  68. /**
  69. * TransformerFactory for xsl:output markup.
  70. * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
  71. * @see <a href="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
  72. */
  73. class ProcessorOutputElem extends XSLTElementProcessor
  74. {
  75. /** The output properties, set temporarily while the properties are
  76. * being set from the attributes, and then nulled after that operation
  77. * is completed. */
  78. private OutputProperties m_outputProperties;
  79. /**
  80. * Set the cdata-section-elements property from the attribute value.
  81. * @see javax.xml.transform.OutputKeys#CDATA_SECTION_ELEMENTS
  82. * @param newValue non-null reference to processed attribute value.
  83. */
  84. public void setCdataSectionElements(java.util.Vector newValue)
  85. {
  86. m_outputProperties.setQNameProperties(OutputKeys.CDATA_SECTION_ELEMENTS, newValue);
  87. }
  88. /**
  89. * Set the doctype-public property from the attribute value.
  90. * @see javax.xml.transform.OutputKeys#DOCTYPE_PUBLIC
  91. * @param newValue non-null reference to processed attribute value.
  92. */
  93. public void setDoctypePublic(String newValue)
  94. {
  95. m_outputProperties.setProperty(OutputKeys.DOCTYPE_PUBLIC, newValue);
  96. }
  97. /**
  98. * Set the doctype-system property from the attribute value.
  99. * @see javax.xml.transform.OutputKeys#DOCTYPE_SYSTEM
  100. * @param newValue non-null reference to processed attribute value.
  101. */
  102. public void setDoctypeSystem(String newValue)
  103. {
  104. m_outputProperties.setProperty(OutputKeys.DOCTYPE_SYSTEM, newValue);
  105. }
  106. /**
  107. * Set the encoding property from the attribute value.
  108. * @see javax.xml.transform.OutputKeys#ENCODING
  109. * @param newValue non-null reference to processed attribute value.
  110. */
  111. public void setEncoding(String newValue)
  112. {
  113. m_outputProperties.setProperty(OutputKeys.ENCODING, newValue);
  114. }
  115. /**
  116. * Set the indent property from the attribute value.
  117. * @see javax.xml.transform.OutputKeys#INDENT
  118. * @param newValue non-null reference to processed attribute value.
  119. */
  120. public void setIndent(boolean newValue)
  121. {
  122. m_outputProperties.setBooleanProperty(OutputKeys.INDENT, newValue);
  123. }
  124. /**
  125. * Set the media type property from the attribute value.
  126. * @see javax.xml.transform.OutputKeys#MEDIA_TYPE
  127. * @param newValue non-null reference to processed attribute value.
  128. */
  129. public void setMediaType(String newValue)
  130. {
  131. m_outputProperties.setProperty(OutputKeys.MEDIA_TYPE, newValue);
  132. }
  133. /**
  134. * Set the method property from the attribute value.
  135. * @see javax.xml.transform.OutputKeys#METHOD
  136. * @param newValue non-null reference to processed attribute value.
  137. */
  138. public void setMethod(org.apache.xml.utils.QName newValue)
  139. {
  140. m_outputProperties.setQNameProperty(OutputKeys.METHOD, newValue);
  141. }
  142. /**
  143. * Set the omit-xml-declaration property from the attribute value.
  144. * @see javax.xml.transform.OutputKeys#OMIT_XML_DECLARATION
  145. * @param newValue processed attribute value.
  146. */
  147. public void setOmitXmlDeclaration(boolean newValue)
  148. {
  149. m_outputProperties.setBooleanProperty(OutputKeys.OMIT_XML_DECLARATION, newValue);
  150. }
  151. /**
  152. * Set the standalone property from the attribute value.
  153. * @see javax.xml.transform.OutputKeys#STANDALONE
  154. * @param newValue processed attribute value.
  155. */
  156. public void setStandalone(boolean newValue)
  157. {
  158. m_outputProperties.setBooleanProperty(OutputKeys.STANDALONE, newValue);
  159. }
  160. /**
  161. * Set the version property from the attribute value.
  162. * @see javax.xml.transform.OutputKeys#VERSION
  163. * @param newValue non-null reference to processed attribute value.
  164. */
  165. public void setVersion(String newValue)
  166. {
  167. m_outputProperties.setProperty(OutputKeys.VERSION, newValue);
  168. }
  169. /**
  170. * Set a foreign property from the attribute value.
  171. * @param newValue non-null reference to attribute value.
  172. */
  173. public void setForeignAttr(String attrUri, String attrLocalName, String attrRawName, String attrValue)
  174. {
  175. QName key = new QName(attrUri, attrLocalName);
  176. m_outputProperties.setProperty(key, attrValue);
  177. }
  178. /**
  179. * Set a foreign property from the attribute value.
  180. * @param newValue non-null reference to attribute value.
  181. */
  182. public void addLiteralResultAttribute(String attrUri, String attrLocalName, String attrRawName, String attrValue)
  183. {
  184. QName key = new QName(attrUri, attrLocalName);
  185. m_outputProperties.setProperty(key, attrValue);
  186. }
  187. /**
  188. * Receive notification of the start of an xsl:output element.
  189. *
  190. * @param handler The calling StylesheetHandler/TemplatesBuilder.
  191. * @param uri The Namespace URI, or the empty string if the
  192. * element has no Namespace URI or if Namespace
  193. * processing is not being performed.
  194. * @param localName The local name (without prefix), or the
  195. * empty string if Namespace processing is not being
  196. * performed.
  197. * @param rawName The raw XML 1.0 name (with prefix), or the
  198. * empty string if raw names are not available.
  199. * @param attributes The attributes attached to the element. If
  200. * there are no attributes, it shall be an empty
  201. * Attributes object.
  202. *
  203. * @throws org.xml.sax.SAXException
  204. */
  205. public void startElement(
  206. StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
  207. throws org.xml.sax.SAXException
  208. {
  209. // Hmmm... for the moment I don't think I'll have default properties set for this. -sb
  210. m_outputProperties = new OutputProperties();
  211. m_outputProperties.setDOMBackPointer(handler.getOriginatingNode());
  212. m_outputProperties.setLocaterInfo(handler.getLocator());
  213. m_outputProperties.setUid(handler.nextUid());
  214. setPropertiesFromAttributes(handler, rawName, attributes, this);
  215. // Access this only from the Hashtable level... we don't want to
  216. // get default properties.
  217. String entitiesFileName =
  218. (String) m_outputProperties.getProperties().get(OutputProperties.S_KEY_ENTITIES);
  219. if (null != entitiesFileName)
  220. {
  221. try
  222. {
  223. String absURL = SystemIDResolver.getAbsoluteURI(entitiesFileName,
  224. handler.getBaseIdentifier());
  225. m_outputProperties.getProperties().put(OutputProperties.S_KEY_ENTITIES, absURL);
  226. }
  227. catch(TransformerException te)
  228. {
  229. handler.error(te.getMessage(), te);
  230. }
  231. }
  232. handler.getStylesheet().setOutput(m_outputProperties);
  233. ElemTemplateElement parent = handler.getElemTemplateElement();
  234. parent.appendChild(m_outputProperties);
  235. m_outputProperties = null;
  236. }
  237. }