1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 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 "Xerces" 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, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.xni;
  58. /**
  59. * The XMLAttributes interface defines a collection of attributes for
  60. * an element. In the parser, the document source would scan the entire
  61. * start element and collect the attributes. The attributes are
  62. * communicated to the document handler in the startElement method.
  63. * <p>
  64. * The attributes are read-write so that subsequent stages in the document
  65. * pipeline can modify the values or change the attributes that are
  66. * propogated to the next stage.
  67. *
  68. * @see XMLDocumentHandler#startElement
  69. *
  70. * @author Andy Clark, IBM
  71. *
  72. * @version $Id: XMLAttributes.java,v 1.9 2003/01/23 17:27:12 sandygao Exp $
  73. */
  74. public interface XMLAttributes {
  75. //
  76. // XMLAttributes methods
  77. //
  78. /**
  79. * Adds an attribute. The attribute's non-normalized value of the
  80. * attribute will have the same value as the attribute value until
  81. * set using the <code>setNonNormalizedValue</code> method. Also,
  82. * the added attribute will be marked as specified in the XML instance
  83. * document unless set otherwise using the <code>setSpecified</code>
  84. * method.
  85. * <p>
  86. * <strong>Note:</strong> If an attribute of the same name already
  87. * exists, the old values for the attribute are replaced by the new
  88. * values.
  89. *
  90. * @param attrName The attribute name.
  91. * @param attrType The attribute type. The type name is determined by
  92. * the type specified for this attribute in the DTD.
  93. * For example: "CDATA", "ID", "NMTOKEN", etc. However,
  94. * attributes of type enumeration will have the type
  95. * value specified as the pipe ('|') separated list of
  96. * the enumeration values prefixed by an open
  97. * parenthesis and suffixed by a close parenthesis.
  98. * For example: "(true|false)".
  99. * @param attrValue The attribute value.
  100. *
  101. * @return Returns the attribute index.
  102. *
  103. * @see #setNonNormalizedValue
  104. * @see #setSpecified
  105. */
  106. public int addAttribute(QName attrName, String attrType, String attrValue);
  107. /**
  108. * Removes all of the attributes. This method will also remove all
  109. * entities associated to the attributes.
  110. */
  111. public void removeAllAttributes();
  112. /**
  113. * Removes the attribute at the specified index.
  114. * <p>
  115. * <strong>Note:</strong> This operation changes the indexes of all
  116. * attributes following the attribute at the specified index.
  117. *
  118. * @param attrIndex The attribute index.
  119. */
  120. public void removeAttributeAt(int attrIndex);
  121. /**
  122. * Returns the number of attributes in the list.
  123. * <p>
  124. * Once you know the number of attributes, you can iterate
  125. * through the list.
  126. *
  127. * @see #getURI(int)
  128. * @see #getLocalName(int)
  129. * @see #getQName(int)
  130. * @see #getType(int)
  131. * @see #getValue(int)
  132. */
  133. public int getLength();
  134. /**
  135. * Look up the index of an attribute by XML 1.0 qualified name.
  136. *
  137. * @param qName The qualified (prefixed) name.
  138. *
  139. * @return The index of the attribute, or -1 if it does not
  140. * appear in the list.
  141. */
  142. public int getIndex(String qName);
  143. /**
  144. * Look up the index of an attribute by Namespace name.
  145. *
  146. * @param uri The Namespace URI, or the empty string if
  147. * the name has no Namespace URI.
  148. * @param localName The attribute's local name.
  149. *
  150. * @return The index of the attribute, or -1 if it does not
  151. * appear in the list.
  152. */
  153. public int getIndex(String uri, String localPart);
  154. /**
  155. * Sets the name of the attribute at the specified index.
  156. *
  157. * @param attrIndex The attribute index.
  158. * @param attrName The new attribute name.
  159. */
  160. public void setName(int attrIndex, QName attrName);
  161. /**
  162. * Sets the fields in the given QName structure with the values
  163. * of the attribute name at the specified index.
  164. *
  165. * @param attrIndex The attribute index.
  166. * @param attrName The attribute name structure to fill in.
  167. */
  168. public void getName(int attrIndex, QName attrName);
  169. /**
  170. * Returns the prefix of the attribute at the specified index.
  171. *
  172. * @param index The index of the attribute.
  173. */
  174. public String getPrefix(int index);
  175. /**
  176. * Look up an attribute's Namespace URI by index.
  177. *
  178. * @param index The attribute index (zero-based).
  179. *
  180. * @return The Namespace URI, or the empty string if none
  181. * is available, or null if the index is out of
  182. * range.
  183. *
  184. * @see #getLength
  185. */
  186. public String getURI(int index);
  187. /**
  188. * Look up an attribute's local name by index.
  189. *
  190. * @param index The attribute index (zero-based).
  191. *
  192. * @return The local name, or the empty string if Namespace
  193. * processing is not being performed, or null
  194. * if the index is out of range.
  195. *
  196. * @see #getLength
  197. */
  198. public String getLocalName(int index);
  199. /**
  200. * Look up an attribute's XML 1.0 qualified name by index.
  201. *
  202. * @param index The attribute index (zero-based).
  203. *
  204. * @return The XML 1.0 qualified name, or the empty string
  205. * if none is available, or null if the index
  206. * is out of range.
  207. *
  208. * @see #getLength
  209. */
  210. public String getQName(int index);
  211. /**
  212. * Sets the type of the attribute at the specified index.
  213. *
  214. * @param attrIndex The attribute index.
  215. * @param attrType The attribute type. The type name is determined by
  216. * the type specified for this attribute in the DTD.
  217. * For example: "CDATA", "ID", "NMTOKEN", etc. However,
  218. * attributes of type enumeration will have the type
  219. * value specified as the pipe ('|') separated list of
  220. * the enumeration values prefixed by an open
  221. * parenthesis and suffixed by a close parenthesis.
  222. * For example: "(true|false)".
  223. */
  224. public void setType(int attrIndex, String attrType);
  225. /**
  226. * Look up an attribute's type by index.
  227. * <p>
  228. * The attribute type is one of the strings "CDATA", "ID",
  229. * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
  230. * or "NOTATION" (always in upper case).
  231. * <p>
  232. * If the parser has not read a declaration for the attribute,
  233. * or if the parser does not report attribute types, then it must
  234. * return the value "CDATA" as stated in the XML 1.0 Recommentation
  235. * (clause 3.3.3, "Attribute-Value Normalization").
  236. * <p>
  237. * For an enumerated attribute that is not a notation, the
  238. * parser will report the type as "NMTOKEN".
  239. *
  240. * @param index The attribute index (zero-based).
  241. *
  242. * @return The attribute's type as a string, or null if the
  243. * index is out of range.
  244. *
  245. * @see #getLength
  246. */
  247. public String getType(int index);
  248. /**
  249. * Look up an attribute's type by XML 1.0 qualified name.
  250. * <p>
  251. * See {@link #getType(int) getType(int)} for a description
  252. * of the possible types.
  253. *
  254. * @param qName The XML 1.0 qualified name.
  255. *
  256. * @return The attribute type as a string, or null if the
  257. * attribute is not in the list or if qualified names
  258. * are not available.
  259. */
  260. public String getType(String qName);
  261. /**
  262. * Look up an attribute's type by Namespace name.
  263. * <p>
  264. * See {@link #getType(int) getType(int)} for a description
  265. * of the possible types.
  266. *
  267. * @param uri The Namespace URI, or the empty String if the
  268. * name has no Namespace URI.
  269. * @param localName The local name of the attribute.
  270. *
  271. * @return The attribute type as a string, or null if the
  272. * attribute is not in the list or if Namespace
  273. * processing is not being performed.
  274. */
  275. public String getType(String uri, String localName);
  276. /**
  277. * Sets the value of the attribute at the specified index. This
  278. * method will overwrite the non-normalized value of the attribute.
  279. *
  280. * @param attrIndex The attribute index.
  281. * @param attrValue The new attribute value.
  282. *
  283. * @see #setNonNormalizedValue
  284. */
  285. public void setValue(int attrIndex, String attrValue);
  286. /**
  287. * Look up an attribute's value by index.
  288. * <p>
  289. * If the attribute value is a list of tokens (IDREFS,
  290. * ENTITIES, or NMTOKENS), the tokens will be concatenated
  291. * into a single string with each token separated by a
  292. * single space.
  293. *
  294. * @param index The attribute index (zero-based).
  295. *
  296. * @return The attribute's value as a string, or null if the
  297. * index is out of range.
  298. *
  299. * @see #getLength
  300. */
  301. public String getValue(int index);
  302. /**
  303. * Look up an attribute's value by XML 1.0 qualified name.
  304. * <p>
  305. * See {@link #getValue(int) getValue(int)} for a description
  306. * of the possible values.
  307. *
  308. * @param qName The XML 1.0 qualified name.
  309. *
  310. * @return The attribute value as a string, or null if the
  311. * attribute is not in the list or if qualified names
  312. * are not available.
  313. */
  314. public String getValue(String qName);
  315. /**
  316. * Look up an attribute's value by Namespace name.
  317. * <p>
  318. * See {@link #getValue(int) getValue(int)} for a description
  319. * of the possible values.
  320. *
  321. * @param uri The Namespace URI, or the empty String if the
  322. * name has no Namespace URI.
  323. * @param localName The local name of the attribute.
  324. *
  325. * @return The attribute value as a string, or null if the
  326. * attribute is not in the list.
  327. */
  328. public String getValue(String uri, String localName);
  329. /**
  330. * Sets the non-normalized value of the attribute at the specified
  331. * index.
  332. *
  333. * @param attrIndex The attribute index.
  334. * @param attrValue The new non-normalized attribute value.
  335. */
  336. public void setNonNormalizedValue(int attrIndex, String attrValue);
  337. /**
  338. * Returns the non-normalized value of the attribute at the specified
  339. * index. If no non-normalized value is set, this method will return
  340. * the same value as the <code>getValue(int)</code> method.
  341. *
  342. * @param attrIndex The attribute index.
  343. */
  344. public String getNonNormalizedValue(int attrIndex);
  345. /**
  346. * Sets whether an attribute is specified in the instance document
  347. * or not.
  348. *
  349. * @param attrIndex The attribute index.
  350. * @param specified True if the attribute is specified in the instance
  351. * document.
  352. */
  353. public void setSpecified(int attrIndex, boolean specified);
  354. /**
  355. * Returns true if the attribute is specified in the instance document.
  356. *
  357. * @param attrIndex The attribute index.
  358. */
  359. public boolean isSpecified(int attrIndex);
  360. /**
  361. * Look up an augmentation by attribute's index.
  362. *
  363. * @param attributeIndex The attribute index.
  364. * @return Augmentations
  365. */
  366. public Augmentations getAugmentations (int attributeIndex);
  367. /**
  368. * Look up an augmentation by namespace name.
  369. *
  370. * @param uri The Namespace URI, or the empty string if
  371. * the name has no Namespace URI.
  372. * @param localPart
  373. * @return Augmentations
  374. */
  375. public Augmentations getAugmentations (String uri, String localPart);
  376. /**
  377. * Look up an augmentation by XML 1.0 qualified name.
  378. * <p>
  379. *
  380. * @param qName The XML 1.0 qualified name.
  381. *
  382. * @return Augmentations
  383. *
  384. */
  385. public Augmentations getAugmentations(String qName);
  386. /**
  387. * Sets the augmentations of the attribute at the specified index.
  388. *
  389. * @param attrIndex The attribute index.
  390. * @param augs The augmentations.
  391. */
  392. public void setAugmentations(int attrIndex, Augmentations augs);
  393. } // interface XMLAttributes