001: /* ValidatorPlugin.java NanoXML/Java
002: *
003: * $Revision: 1.17 $
004: * $Date: 2005/01/05 17:20:04 $
005: * $Name: $
006: *
007: * This file is part of NanoXML 2 for Java.
008: * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009: *
010: * This software is provided 'as-is', without any express or implied warranty.
011: * In no event will the authors be held liable for any damages arising from the
012: * use of this software.
013: *
014: * Permission is granted to anyone to use this software for any purpose,
015: * including commercial applications, and to alter it and redistribute it
016: * freely, subject to the following restrictions:
017: *
018: * 1. The origin of this software must not be misrepresented; you must not
019: * claim that you wrote the original software. If you use this software in
020: * a product, an acknowledgment in the product documentation would be
021: * appreciated but is not required.
022: *
023: * 2. Altered source versions must be plainly marked as such, and must not be
024: * misrepresented as being the original software.
025: *
026: * 3. This notice may not be removed or altered from any source distribution.
027: */
028:
029: package net.n3.nanoxml;
030:
031: import java.io.Reader;
032: import java.io.IOException;
033: import java.util.Properties;
034:
035: /**
036: * ValidatorPlugin allows the application to insert additional validators into
037: * NanoXML.
038: *
039: * @author Marc De Scheemaecker
040: * @version $Name: $, $Revision: 1.17 $
041: */
042: public class ValidatorPlugin implements IXMLValidator {
043:
044: /**
045: * The delegate.
046: */
047: private IXMLValidator delegate;
048:
049: /**
050: * Initializes the plugin.
051: */
052: public ValidatorPlugin() {
053: this .delegate = null;
054: }
055:
056: /**
057: * Cleans up the object when it's destroyed.
058: */
059: protected void finalize() throws Throwable {
060: this .delegate = null;
061: super .finalize();
062: }
063:
064: /**
065: * Returns the delegate.
066: */
067: public IXMLValidator getDelegate() {
068: return this .delegate;
069: }
070:
071: /**
072: * Sets the delegate.
073: *
074: * @param delegate the delegate
075: */
076: public void setDelegate(IXMLValidator delegate) {
077: this .delegate = delegate;
078: }
079:
080: /**
081: * Sets the parameter entity resolver.
082: *
083: * @param resolver the entity resolver.
084: */
085: public void setParameterEntityResolver(IXMLEntityResolver resolver) {
086: this .delegate.setParameterEntityResolver(resolver);
087: }
088:
089: /**
090: * Returns the parameter entity resolver.
091: *
092: * @return the entity resolver.
093: */
094: public IXMLEntityResolver getParameterEntityResolver() {
095: return this .delegate.getParameterEntityResolver();
096: }
097:
098: /**
099: * Parses the DTD. The validator object is responsible for reading the
100: * full DTD.
101: *
102: * @param publicID the public ID, which may be null.
103: * @param reader the reader to read the DTD from.
104: * @param entityResolver the entity resolver.
105: * @param external true if the DTD is external.
106: *
107: * @throws java.lang.Exception
108: * if something went wrong.
109: */
110: public void parseDTD(String publicID, IXMLReader reader,
111: IXMLEntityResolver entityResolver, boolean external)
112: throws Exception {
113: this .delegate.parseDTD(publicID, reader, entityResolver,
114: external);
115: }
116:
117: /**
118: * Indicates that an element has been started.
119: *
120: * @param name the name of the element.
121: * @param systemId the system ID of the XML data of the element.
122: * @param lineNr the line number in the XML data of the element.
123: *
124: * @throws java.lang.Exception
125: * if the element could not be validated.
126: */
127: public void elementStarted(String name, String systemId, int lineNr)
128: throws Exception {
129: this .delegate.elementStarted(name, systemId, lineNr);
130: }
131:
132: /**
133: * Indicates that the current element has ended.
134: *
135: * @param name the name of the element.
136: * @param systemId the system ID of the XML data of the element.
137: * @param lineNr the line number in the XML data of the element.
138: *
139: * @throws java.lang.Exception
140: * if the element could not be validated.
141: */
142: public void elementEnded(String name, String systemId, int lineNr)
143: throws Exception {
144: this .delegate.elementEnded(name, systemId, lineNr);
145: }
146:
147: /**
148: * Indicates that an attribute has been added to the current element.
149: *
150: * @param key the name of the attribute.
151: * @param value the value of the attribute.
152: * @param systemId the system ID of the XML data of the element.
153: * @param lineNr the line number in the XML data of the element.
154: *
155: * @throws java.lang.Exception
156: * if the attribute could not be validated.
157: */
158: public void elementAttributesProcessed(String name,
159: Properties extraAttributes, String systemId, int lineNr)
160: throws Exception {
161: this .delegate.elementAttributesProcessed(name, extraAttributes,
162: systemId, lineNr);
163: }
164:
165: /**
166: * This method is called when the attributes of an XML element have been
167: * processed.
168: * If there are attributes with a default value which have not been
169: * specified yet, they have to be put into <I>extraAttributes</I>.
170: *
171: * @param name the name of the element.
172: * @param extraAttributes where to put extra attributes.
173: * @param systemId the system ID of the XML data of the element.
174: * @param lineNr the line number in the XML data of the element.
175: *
176: * @throws java.lang.Exception
177: * if the element could not be validated.
178: */
179: public void attributeAdded(String key, String value,
180: String systemId, int lineNr) throws Exception {
181: this .delegate.attributeAdded(key, value, systemId, lineNr);
182: }
183:
184: /**
185: * Indicates that a new #PCDATA element has been encountered.
186: *
187: * @param systemId the system ID of the XML data of the element.
188: * @param lineNr the line number in the XML data of the element.
189: *
190: * @throws java.lang.Exception
191: * if the element could not be validated.
192: */
193: public void PCDataAdded(String systemId, int lineNr)
194: throws Exception {
195: this .delegate.PCDataAdded(systemId, lineNr);
196: }
197:
198: /**
199: * Throws an XMLValidationException to indicate that an element is missing.
200: *
201: * @param systemID the system ID of the XML data of the element
202: * @param lineNr the line number in the XML data of the element
203: * @param parentElementName the name of the parent element
204: * @param missingElementName the name of the missing element
205: *
206: * @throws net.n3.nanoxml.XMLValidationException
207: * of course :-)
208: */
209: public void missingElement(String systemID, int lineNr,
210: String parentElementName, String missingElementName)
211: throws XMLValidationException {
212: XMLUtil.errorMissingElement(systemID, lineNr,
213: parentElementName, missingElementName);
214: }
215:
216: /**
217: * Throws an XMLValidationException to indicate that an element is
218: * unexpected.
219: *
220: * @param systemID the system ID of the XML data of the
221: * element
222: * @param lineNr the line number in the XML data of the
223: * element
224: * @param parentElementName the name of the parent element
225: * @param unexpectedElementName the name of the missing element
226: *
227: * @throws net.n3.nanoxml.XMLValidationException
228: * of course :-)
229: */
230: public void unexpectedElement(String systemID, int lineNr,
231: String parentElementName, String unexpectedElementName)
232: throws XMLValidationException {
233: XMLUtil.errorUnexpectedElement(systemID, lineNr,
234: parentElementName, unexpectedElementName);
235: }
236:
237: /**
238: * Throws an XMLValidationException to indicate that an attribute is
239: * missing.
240: *
241: * @param systemID the system ID of the XML data of the element
242: * @param lineNr the line number in the XML data of the element
243: * @param elementName the name of the element
244: * @param attributeName the name of the missing attribute
245: *
246: * @throws net.n3.nanoxml.XMLValidationException
247: * of course :-)
248: */
249: public void missingAttribute(String systemID, int lineNr,
250: String elementName, String attributeName)
251: throws XMLValidationException {
252: XMLUtil.errorMissingAttribute(systemID, lineNr, elementName,
253: attributeName);
254: }
255:
256: /**
257: * Throws an XMLValidationException to indicate that an attribute is
258: * unexpected.
259: *
260: * @param systemID the system ID of the XML data of the element
261: * @param lineNr the line number in the XML data of the element
262: * @param elementName the name of the element
263: * @param attributeName the name of the unexpected attribute
264: *
265: * @throws net.n3.nanoxml.XMLValidationException
266: * of course :-)
267: */
268: public void unexpectedAttribute(String systemID, int lineNr,
269: String elementName, String attributeName)
270: throws XMLValidationException {
271: XMLUtil.errorUnexpectedAttribute(systemID, lineNr, elementName,
272: attributeName);
273: }
274:
275: /**
276: * Throws an XMLValidationException to indicate that an attribute has an
277: * invalid value.
278: *
279: * @param systemID the system ID of the XML data of the element
280: * @param lineNr the line number in the XML data of the element
281: * @param elementName the name of the element
282: * @param attributeName the name of the attribute
283: * @param attributeValue the value of the attribute
284: *
285: * @throws net.n3.nanoxml.XMLValidationException
286: * of course :-)
287: */
288: public void invalidAttributeValue(String systemID, int lineNr,
289: String elementName, String attributeName,
290: String attributeValue) throws XMLValidationException {
291: XMLUtil.errorInvalidAttributeValue(systemID, lineNr,
292: elementName, attributeName, attributeValue);
293: }
294:
295: /**
296: * Throws an XMLValidationException to indicate that a #PCDATA element was
297: * missing.
298: *
299: * @param systemID the system ID of the XML data of the element
300: * @param lineNr the line number in the XML data of the element
301: * @param parentElementName the name of the parent element
302: *
303: * @throws net.n3.nanoxml.XMLValidationException
304: * of course :-)
305: */
306: public void missingPCData(String systemID, int lineNr,
307: String parentElementName) throws XMLValidationException {
308: XMLUtil.errorMissingPCData(systemID, lineNr, parentElementName);
309: }
310:
311: /**
312: * Throws an XMLValidationException to indicate that a #PCDATA element was
313: * unexpected.
314: *
315: * @param systemID the system ID of the XML data of the element
316: * @param lineNr the line number in the XML data of the element
317: * @param parentElementName the name of the parent element
318: *
319: * @throws net.n3.nanoxml.XMLValidationException
320: * of course :-)
321: */
322: public void unexpectedPCData(String systemID, int lineNr,
323: String parentElementName) throws XMLValidationException {
324: XMLUtil.errorUnexpectedPCData(systemID, lineNr,
325: parentElementName);
326: }
327:
328: /**
329: * Throws an XMLValidationException.
330: *
331: * @param systemID the system ID of the XML data of the element
332: * @param lineNr the line number in the XML data of the element
333: * @param message the error message
334: * @param elementName the name of the element (may be null)
335: * @param attributeName the name of the attribute (may be null)
336: * @param attributeValue the value of the attribute (may be null)
337: *
338: * @throws net.n3.nanoxml.XMLValidationException
339: * of course :-)
340: */
341: public void validationError(String systemID, int lineNr,
342: String message, String elementName, String attributeName,
343: String attributeValue) throws XMLValidationException {
344: XMLUtil.validationError(systemID, lineNr, message, elementName,
345: attributeName, attributeValue);
346: }
347:
348: }
|