1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999-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.parsers;
  58. import com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar;
  59. import com.sun.org.apache.xerces.internal.util.SymbolTable;
  60. import com.sun.org.apache.xerces.internal.xni.Augmentations;
  61. import com.sun.org.apache.xerces.internal.xni.XMLString;
  62. import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
  63. import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
  64. import com.sun.org.apache.xerces.internal.xni.XMLLocator;
  65. import com.sun.org.apache.xerces.internal.xni.XNIException;
  66. import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  67. import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  68. /**
  69. * @version $Id: DTDParser.java,v 1.10 2002/05/07 19:29:04 elena Exp $
  70. */
  71. public abstract class DTDParser
  72. extends XMLGrammarParser
  73. implements XMLDTDHandler, XMLDTDContentModelHandler {
  74. //
  75. // Data
  76. //
  77. /** fDTDScanner */
  78. protected XMLDTDScanner fDTDScanner;
  79. //
  80. // Constructors
  81. //
  82. /**
  83. *
  84. *
  85. * @param symbolTable
  86. */
  87. public DTDParser(SymbolTable symbolTable) {
  88. super(symbolTable);
  89. }
  90. //
  91. // Methods
  92. //
  93. /**
  94. * getDTDGrammar
  95. *
  96. * @return the grammar created by this parser
  97. */
  98. public DTDGrammar getDTDGrammar() {
  99. return null;
  100. } // getDTDGrammar
  101. //
  102. // XMLDTDHandler methods
  103. //
  104. /**
  105. * This method notifies of the start of an entity. The DTD has the
  106. * pseudo-name of "[dtd]" and parameter entity names start with '%'.
  107. * <p>
  108. * <strong>Note:</strong> Since the DTD is an entity, the handler
  109. * will be notified of the start of the DTD entity by calling the
  110. * startEntity method with the entity name "[dtd]" <em>before</em> calling
  111. * the startDTD method.
  112. *
  113. * @param name The name of the entity.
  114. * @param publicId The public identifier of the entity if the entity
  115. * is external, null otherwise.
  116. * @param systemId The system identifier of the entity if the entity
  117. * is external, null otherwise.
  118. * @param encoding The auto-detected IANA encoding name of the entity
  119. * stream. This value will be null in those situations
  120. * where the entity encoding is not auto-detected (e.g.
  121. * internal parameter entities).
  122. *
  123. * @throws XNIException Thrown by handler to signal an error.
  124. */
  125. public void startEntity(String name, String publicId, String systemId,
  126. String encoding) throws XNIException {
  127. }
  128. /**
  129. * Notifies of the presence of a TextDecl line in an entity. If present,
  130. * this method will be called immediately following the startEntity call.
  131. * <p>
  132. * <strong>Note:</strong> This method is only called for external
  133. * parameter entities referenced in the DTD.
  134. *
  135. * @param version The XML version, or null if not specified.
  136. * @param encoding The IANA encoding name of the entity.
  137. *
  138. * @throws XNIException Thrown by handler to signal an error.
  139. */
  140. public void textDecl(String version, String encoding) throws XNIException {
  141. }
  142. /**
  143. * The start of the DTD.
  144. *
  145. * @throws XNIException Thrown by handler to signal an error.
  146. */
  147. public void startDTD(XMLLocator locator, Augmentations augmentations)
  148. throws XNIException {
  149. }
  150. /**
  151. * A comment.
  152. *
  153. * @param text The text in the comment.
  154. *
  155. * @throws XNIException Thrown by application to signal an error.
  156. */
  157. public void comment(XMLString text, Augmentations augmentations) throws XNIException {
  158. } // comment
  159. /**
  160. * A processing instruction. Processing instructions consist of a
  161. * target name and, optionally, text data. The data is only meaningful
  162. * to the application.
  163. * <p>
  164. * Typically, a processing instruction's data will contain a series
  165. * of pseudo-attributes. These pseudo-attributes follow the form of
  166. * element attributes but are <strong>not</strong> parsed or presented
  167. * to the application as anything other than text. The application is
  168. * responsible for parsing the data.
  169. *
  170. * @param target The target.
  171. * @param data The data or null if none specified.
  172. *
  173. * @throws XNIException Thrown by handler to signal an error.
  174. */
  175. public void processingInstruction(String target, XMLString data,
  176. Augmentations augmentations)
  177. throws XNIException {
  178. } // processingInstruction
  179. /**
  180. * The start of the external subset.
  181. *
  182. * @throws XNIException Thrown by handler to signal an error.
  183. */
  184. public void startExternalSubset(XMLResourceIdentifier identifier,
  185. Augmentations augmentations) throws XNIException {
  186. } // startExternalSubset
  187. /**
  188. * The end of the external subset.
  189. *
  190. * @throws XNIException Thrown by handler to signal an error.
  191. */
  192. public void endExternalSubset(Augmentations augmentations) throws XNIException {
  193. } // endExternalSubset
  194. /**
  195. * An element declaration.
  196. *
  197. * @param name The name of the element.
  198. * @param contentModel The element content model.
  199. *
  200. * @throws XNIException Thrown by handler to signal an error.
  201. */
  202. public void elementDecl(String name, String contentModel,
  203. Augmentations augmentations)
  204. throws XNIException {
  205. } // elementDecl
  206. /**
  207. * The start of an attribute list.
  208. *
  209. * @param elementName The name of the element that this attribute
  210. * list is associated with.
  211. *
  212. * @throws XNIException Thrown by handler to signal an error.
  213. */
  214. public void startAttlist(String elementName,
  215. Augmentations augmentations) throws XNIException {
  216. } // startAttlist
  217. /**
  218. * An attribute declaration.
  219. *
  220. * @param elementName The name of the element that this attribute
  221. * is associated with.
  222. * @param attributeName The name of the attribute.
  223. * @param type The attribute type. This value will be one of
  224. * the following: "CDATA", "ENTITY", "ENTITIES",
  225. * "ENUMERATION", "ID", "IDREF", "IDREFS",
  226. * "NMTOKEN", "NMTOKENS", or "NOTATION".
  227. * @param enumeration If the type has the value "ENUMERATION", this
  228. * array holds the allowed attribute values;
  229. * otherwise, this array is null.
  230. * @param defaultType The attribute default type. This value will be
  231. * one of the following: "#FIXED", "#IMPLIED",
  232. * "#REQUIRED", or null.
  233. * @param defaultValue The attribute default value, or null if no
  234. * default value is specified.
  235. *
  236. * @throws XNIException Thrown by handler to signal an error.
  237. */
  238. public void attributeDecl(String elementName, String attributeName,
  239. String type, String[] enumeration,
  240. String defaultType, XMLString defaultValue,
  241. XMLString nonNormalizedDefaultValue, Augmentations augmentations)
  242. throws XNIException {
  243. } // attributeDecl
  244. /**
  245. * The end of an attribute list.
  246. *
  247. * @throws XNIException Thrown by handler to signal an error.
  248. */
  249. public void endAttlist(Augmentations augmentations) throws XNIException {
  250. } // endAttlist
  251. /**
  252. * An internal entity declaration.
  253. *
  254. * @param name The name of the entity. Parameter entity names start with
  255. * '%', whereas the name of a general entity is just the
  256. * entity name.
  257. * @param text The value of the entity.
  258. * @param nonNormalizedText The non-normalized value of the entity. This
  259. * value contains the same sequence of characters that was in
  260. * the internal entity declaration, without any entity
  261. * references expanded.
  262. *
  263. * @throws XNIException Thrown by handler to signal an error.
  264. */
  265. public void internalEntityDecl(String name, XMLString text,
  266. XMLString nonNormalizedText,
  267. Augmentations augmentations)
  268. throws XNIException {
  269. } // internalEntityDecl(String,XMLString,XMLString)
  270. /**
  271. * An external entity declaration.
  272. *
  273. * @param name The name of the entity. Parameter entity names start
  274. * with '%', whereas the name of a general entity is just
  275. * the entity name.
  276. * @param publicId The public identifier of the entity or null if the
  277. * the entity was specified with SYSTEM.
  278. * @param systemId The system identifier of the entity.
  279. *
  280. * @throws XNIException Thrown by handler to signal an error.
  281. */
  282. public void externalEntityDecl(String name,
  283. XMLResourceIdentifier identifier,
  284. Augmentations augmentations)
  285. throws XNIException {
  286. } // externalEntityDecl
  287. /**
  288. * An unparsed entity declaration.
  289. *
  290. * @param name The name of the entity.
  291. * @param publicId The public identifier of the entity, or null if not
  292. * specified.
  293. * @param systemId The system identifier of the entity, or null if not
  294. * specified.
  295. * @param notation The name of the notation.
  296. *
  297. * @throws XNIException Thrown by handler to signal an error.
  298. */
  299. public void unparsedEntityDecl(String name,
  300. XMLResourceIdentifier identifier,
  301. String notation, Augmentations augmentations)
  302. throws XNIException {
  303. } // unparsedEntityDecl
  304. /**
  305. * A notation declaration
  306. *
  307. * @param name The name of the notation.
  308. * @param publicId The public identifier of the notation, or null if not
  309. * specified.
  310. * @param systemId The system identifier of the notation, or null if not
  311. * specified.
  312. *
  313. * @throws XNIException Thrown by handler to signal an error.
  314. */
  315. public void notationDecl(String name, XMLResourceIdentifier identifier,
  316. Augmentations augmentations)
  317. throws XNIException {
  318. } // notationDecl
  319. /**
  320. * The start of a conditional section.
  321. *
  322. * @param type The type of the conditional section. This value will
  323. * either be CONDITIONAL_INCLUDE or CONDITIONAL_IGNORE.
  324. *
  325. * @throws XNIException Thrown by handler to signal an error.
  326. *
  327. * @see XMLDTDHandler#CONDITIONAL_INCLUDE
  328. * @see XMLDTDHandler#CONDITIONAL_IGNORE
  329. */
  330. public void startConditional(short type, Augmentations augmentations) throws XNIException {
  331. } // startConditional
  332. /**
  333. * The end of a conditional section.
  334. *
  335. * @throws XNIException Thrown by handler to signal an error.
  336. */
  337. public void endConditional(Augmentations augmentations) throws XNIException {
  338. } // endConditional
  339. /**
  340. * The end of the DTD.
  341. *
  342. * @throws XNIException Thrown by handler to signal an error.
  343. */
  344. public void endDTD(Augmentations augmentations) throws XNIException {
  345. } // endDTD
  346. /**
  347. * This method notifies the end of an entity. The DTD has the pseudo-name
  348. * of "[dtd]" and parameter entity names start with '%'.
  349. * <p>
  350. * <strong>Note:</strong> Since the DTD is an entity, the handler
  351. * will be notified of the end of the DTD entity by calling the
  352. * endEntity method with the entity name "[dtd]" <em>after</em> calling
  353. * the endDTD method.
  354. *
  355. * @param name The name of the entity.
  356. *
  357. * @throws XNIException Thrown by handler to signal an error.
  358. */
  359. public void endEntity(String name, Augmentations augmentations) throws XNIException {
  360. }
  361. //
  362. // XMLDTDContentModelHandler methods
  363. //
  364. /**
  365. * The start of a content model. Depending on the type of the content
  366. * model, specific methods may be called between the call to the
  367. * startContentModel method and the call to the endContentModel method.
  368. *
  369. * @param elementName The name of the element.
  370. * @param type The content model type.
  371. *
  372. * @throws XNIException Thrown by handler to signal an error.
  373. *
  374. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_EMPTY
  375. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_ANY
  376. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_MIXED
  377. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  378. */
  379. public void startContentModel(String elementName, short type)
  380. throws XNIException {
  381. } // startContentModel
  382. /**
  383. * A referenced element in a mixed content model. If the mixed content
  384. * model only allows text content, then this method will not be called
  385. * for that model. However, if this method is called for a mixed
  386. * content model, then the zero or more occurrence count is implied.
  387. * <p>
  388. * <strong>Note:</strong> This method is only called after a call to
  389. * the startContentModel method where the type is TYPE_MIXED.
  390. *
  391. * @param elementName The name of the referenced element.
  392. *
  393. * @throws XNIException Thrown by handler to signal an error.
  394. *
  395. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_MIXED
  396. */
  397. public void mixedElement(String elementName) throws XNIException {
  398. } // mixedElement
  399. /**
  400. * The start of a children group.
  401. * <p>
  402. * <strong>Note:</strong> This method is only called after a call to
  403. * the startContentModel method where the type is TYPE_CHILDREN.
  404. * <p>
  405. * <strong>Note:</strong> Children groups can be nested and have
  406. * associated occurrence counts.
  407. *
  408. * @throws XNIException Thrown by handler to signal an error.
  409. *
  410. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  411. */
  412. public void childrenStartGroup() throws XNIException {
  413. } // childrenStartGroup
  414. /**
  415. * A referenced element in a children content model.
  416. *
  417. * @param elementName The name of the referenced element.
  418. *
  419. * @throws XNIException Thrown by handler to signal an error.
  420. *
  421. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  422. */
  423. public void childrenElement(String elementName) throws XNIException {
  424. } // childrenElement
  425. /**
  426. * The separator between choices or sequences of a children content
  427. * model.
  428. * <p>
  429. * <strong>Note:</strong> This method is only called after a call to
  430. * the startContentModel method where the type is TYPE_CHILDREN.
  431. *
  432. * @param separator The type of children separator.
  433. *
  434. * @throws XNIException Thrown by handler to signal an error.
  435. *
  436. * @see XMLDTDContentModelHandler#SEPARATOR_CHOICE
  437. * @see XMLDTDContentModelHandler#SEPARATOR_SEQUENCE
  438. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  439. */
  440. public void childrenSeparator(short separator) throws XNIException {
  441. } // childrenSeparator
  442. /**
  443. * The occurrence count for a child in a children content model.
  444. * <p>
  445. * <strong>Note:</strong> This method is only called after a call to
  446. * the startContentModel method where the type is TYPE_CHILDREN.
  447. *
  448. * @param occurrence The occurrence count for the last children element
  449. * or children group.
  450. *
  451. * @throws XNIException Thrown by handler to signal an error.
  452. *
  453. * @see XMLDTDContentModelHandler#OCCURS_ZERO_OR_ONE
  454. * @see XMLDTDContentModelHandler#OCCURS_ZERO_OR_MORE
  455. * @see XMLDTDContentModelHandler#OCCURS_ONE_OR_MORE
  456. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  457. */
  458. public void childrenOccurrence(short occurrence) throws XNIException {
  459. } // childrenOccurrence
  460. /**
  461. * The end of a children group.
  462. * <p>
  463. * <strong>Note:</strong> This method is only called after a call to
  464. * the startContentModel method where the type is TYPE_CHILDREN.
  465. *
  466. * @see com.sun.org.apache.xerces.internal.impl.dtd.XMLElementDecl#TYPE_CHILDREN
  467. */
  468. public void childrenEndGroup() throws XNIException {
  469. } // childrenEndGroup
  470. /**
  471. * The end of a content model.
  472. *
  473. * @throws XNIException Thrown by handler to signal an error.
  474. */
  475. public void endContentModel() throws XNIException {
  476. } // endContentModel
  477. } // class DTDParser