1. /*
  2. * Copyright 2003-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: ExtendedContentHandler.java,v 1.3 2004/02/17 04:18:18 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.serializer;
  20. import javax.xml.transform.SourceLocator;
  21. import org.xml.sax.SAXException;
  22. /**
  23. * This interface describes extensions to the SAX ContentHandler interface.
  24. * It is intended to be used by a serializer. The methods on this interface will
  25. * implement SAX- like behavior. This allows the gradual collection of
  26. * information rather than having it all up front. For example the call
  27. * <pre>
  28. * startElement(namespaceURI,localName,qName,atts)
  29. * </pre>
  30. * could be replaced with the calls
  31. * <pre>
  32. * startElement(namespaceURI,localName,qName)
  33. * addAttributes(atts)
  34. * </pre>
  35. * If there are no attributes the second call can be dropped. If attributes are
  36. * to be added one at a time with calls to
  37. * <pre>
  38. * addAttribute(namespaceURI, localName, qName, type, value)
  39. * </pre>
  40. */
  41. public interface ExtendedContentHandler extends org.xml.sax.ContentHandler
  42. {
  43. /**
  44. * Add at attribute to the current element
  45. * @param uri the namespace URI of the attribute name
  46. * @param localName the local name of the attribute (without prefix)
  47. * @param rawName the qualified name of the attribute
  48. * @param type the attribute type typically character data (CDATA)
  49. * @param value the value of the attribute
  50. * @throws SAXException
  51. */
  52. public void addAttribute(
  53. String uri,
  54. String localName,
  55. String rawName,
  56. String type,
  57. String value)
  58. throws SAXException;
  59. /**
  60. * Add attributes to the current element
  61. * @param atts the attributes to add.
  62. * @throws SAXException
  63. */
  64. public void addAttributes(org.xml.sax.Attributes atts)
  65. throws org.xml.sax.SAXException;
  66. /**
  67. * Add an attribute to the current element. The namespace URI of the
  68. * attribute will be calculated from the prefix of qName. The local name
  69. * will be derived from qName and the type will be assumed to be "CDATA".
  70. * @param qName
  71. * @param value
  72. */
  73. public void addAttribute(String qName, String value);
  74. /**
  75. * This method is used to notify of a character event, but passing the data
  76. * as a character String rather than the standard character array.
  77. * @param chars the character data
  78. * @throws SAXException
  79. */
  80. public void characters(String chars) throws SAXException;
  81. /**
  82. * This method is used to notify that an element has ended. Unlike the
  83. * standard SAX method
  84. * <pre>
  85. * endElement(namespaceURI,localName,qName)
  86. * </pre>
  87. * only the last parameter is passed. If needed the serializer can derive
  88. * the localName from the qualified name and derive the namespaceURI from
  89. * its implementation.
  90. * @param elemName the fully qualified element name.
  91. * @throws SAXException
  92. */
  93. public void endElement(String elemName) throws SAXException;
  94. /**
  95. * This method is used to notify that an element is starting.
  96. * This method is just like the standard SAX method
  97. * <pre>
  98. * startElement(uri,localName,qname,atts)
  99. * </pre>
  100. * but without the attributes.
  101. * @param uri the namespace URI of the element
  102. * @param localName the local name (without prefix) of the element
  103. * @param qName the qualified name of the element
  104. *
  105. * @throws SAXException
  106. */
  107. public void startElement(String uri, String localName, String qName)
  108. throws org.xml.sax.SAXException;
  109. /**
  110. * This method is used to notify of the start of an element
  111. * @param qName the fully qualified name of the element
  112. * @throws SAXException
  113. */
  114. public void startElement(String qName) throws SAXException;
  115. /**
  116. * This method is used to notify that a prefix mapping is to start, but
  117. * after an element is started. The SAX method call
  118. * <pre>
  119. * startPrefixMapping(prefix,uri)
  120. * </pre>
  121. * is used just before an element starts and applies to the element to come,
  122. * not to the current element. This method applies to the current element.
  123. * For example one could make the calls in this order:
  124. * <pre>
  125. * startElement("prfx8:elem9")
  126. * namespaceAfterStartElement("http://namespace8","prfx8")
  127. * </pre>
  128. *
  129. * @param uri the namespace URI being declared
  130. * @param prefix the prefix that maps to the given namespace
  131. * @throws SAXException
  132. */
  133. public void namespaceAfterStartElement(String uri, String prefix)
  134. throws SAXException;
  135. /**
  136. * This method is used to notify that a prefix maping is to start, which can
  137. * be for the current element, or for the one to come.
  138. * @param prefix the prefix that maps to the given URI
  139. * @param uri the namespace URI of the given prefix
  140. * @param shouldFlush if true this call is like the SAX
  141. * startPrefixMapping(prefix,uri) call and the mapping applies to the
  142. * element to come. If false the mapping applies to the current element.
  143. * @return boolean false if the prefix mapping was already in effect (in
  144. * other words we are just re-declaring), true if this is a new, never
  145. * before seen mapping for the element.
  146. * @throws SAXException
  147. */
  148. public boolean startPrefixMapping(
  149. String prefix,
  150. String uri,
  151. boolean shouldFlush)
  152. throws SAXException;
  153. /**
  154. * Notify of an entity reference.
  155. * @param entityName the name of the entity
  156. * @throws SAXException
  157. */
  158. public void entityReference(String entityName) throws SAXException;
  159. /**
  160. * This method returns an object that has the current namespace mappings in
  161. * effect.
  162. *
  163. * @return NamespaceMappings an object that has the current namespace
  164. * mappings in effect.
  165. */
  166. public NamespaceMappings getNamespaceMappings();
  167. /**
  168. * This method returns the prefix that currently maps to the given namespace
  169. * URI.
  170. * @param uri the namespace URI
  171. * @return String the prefix that currently maps to the given URI.
  172. */
  173. public String getPrefix(String uri);
  174. /**
  175. * This method gets the prefix associated with a current element or
  176. * attribute name.
  177. * @param name the qualified name of an element, or attribute
  178. * @param isElement true if it is an element name, false if it is an
  179. * atttribute name
  180. * @return String the namespace URI associated with the element or
  181. * attribute.
  182. */
  183. public String getNamespaceURI(String name, boolean isElement);
  184. /**
  185. * This method returns the namespace URI currently associated with the
  186. * prefix.
  187. * @param prefix a prefix of an element or attribute.
  188. * @return String the namespace URI currently associated with the prefix.
  189. */
  190. public String getNamespaceURIFromPrefix(String prefix);
  191. /**
  192. * This method is used to set the source locator, which might be used to
  193. * generated an error message.
  194. * @param locator the source locator
  195. */
  196. public void setSourceLocator(SourceLocator locator);
  197. // Bit constants for addUniqueAttribute().
  198. // The attribute value contains no bad characters. A "bad" character is one which
  199. // is greater than 126 or it is one of '<', '>', '&' or '"'.
  200. public static final int NO_BAD_CHARS = 0x1;
  201. // An HTML empty attribute (e.g. <OPTION selected>).
  202. public static final int HTML_ATTREMPTY = 0x2;
  203. // An HTML URL attribute
  204. public static final int HTML_ATTRURL = 0x4;
  205. /**
  206. * Add a unique attribute to the current element.
  207. * The attribute is guaranteed to be unique here. The serializer can write
  208. * it out immediately without saving it in a table first. The integer
  209. * flag contains information about the attribute, which helps the serializer
  210. * to decide whether a particular processing is needed.
  211. *
  212. * @param qName the fully qualified attribute name.
  213. * @param value the attribute value
  214. * @param flags a bitwise flag
  215. */
  216. public void addUniqueAttribute(String qName, String value, int flags)
  217. throws SAXException;
  218. }