Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / net / n3 / nanoxml / ValidatorPlugin.java @ 15280

History | View | Annotate | Download (15.3 KB)

1
/* ValidatorPlugin.java                                            NanoXML/Java
2
 *
3
 * $Revision: 1.1 $
4
 * $Date: 2006/06/14 07:29:07 $
5
 * $Name:  $
6
 *
7
 * This file is part of NanoXML 2 for Java.
8
 * Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved.
9
 *
10
 * This software is provided 'as-is', without any express or implied warranty.
11
 * In no event will the authors be held liable for any damages arising from the
12
 * use of this software.
13
 *
14
 * Permission is granted to anyone to use this software for any purpose,
15
 * including commercial applications, and to alter it and redistribute it
16
 * freely, subject to the following restrictions:
17
 *
18
 *  1. The origin of this software must not be misrepresented; you must not
19
 *     claim that you wrote the original software. If you use this software in
20
 *     a product, an acknowledgment in the product documentation would be
21
 *     appreciated but is not required.
22
 *
23
 *  2. Altered source versions must be plainly marked as such, and must not be
24
 *     misrepresented as being the original software.
25
 *
26
 *  3. This notice may not be removed or altered from any source distribution.
27
 */
28

    
29
package net.n3.nanoxml;
30

    
31

    
32
import java.util.Properties;
33

    
34

    
35
/**
36
 * ValidatorPlugin allows the application to insert additional validators into
37
 * NanoXML.
38
 *
39
 * @author Marc De Scheemaecker
40
 * @version $Name:  $, $Revision: 1.1 $
41
 */
42
public class ValidatorPlugin
43
    implements IXMLValidator
44
{
45

    
46
    /**
47
     * The delegate.
48
     */
49
    private IXMLValidator delegate;
50
    
51
    
52
    /**
53
     * Initializes the plugin.
54
     */
55
    public ValidatorPlugin()
56
    {
57
        this.delegate = null;
58
    }
59
    
60
    
61
    /**
62
     * Cleans up the object when it's destroyed.
63
     */
64
    protected void finalize()
65
        throws Throwable
66
    {
67
        this.delegate = null;
68
        super.finalize();
69
    }
70
    
71
    
72
    /**
73
     * Returns the delegate.
74
     */
75
    public IXMLValidator getDelegate()
76
    {
77
        return this.delegate;
78
    }
79
    
80
    
81
    /**
82
     * Sets the delegate.
83
     *
84
     * @param delegate the delegate
85
     */
86
    public void setDelegate(IXMLValidator delegate)
87
    {
88
        this.delegate = delegate;
89
    }
90
    
91
    
92
    /**
93
     * Sets the parameter entity resolver.
94
     *
95
     * @param resolver the entity resolver.
96
     */
97
    public void setParameterEntityResolver(IXMLEntityResolver resolver)
98
    {
99
        this.delegate.setParameterEntityResolver(resolver);
100
    }
101
    
102
    
103
    /**
104
     * Returns the parameter entity resolver.
105
     *
106
     * @return the entity resolver.
107
     */
108
    public IXMLEntityResolver getParameterEntityResolver()
109
    {
110
        return this.delegate.getParameterEntityResolver();
111
    }
112
    
113
    
114
    /**
115
     * Parses the DTD. The validator object is responsible for reading the
116
     * full DTD.
117
     *
118
     * @param publicID       the public ID, which may be null.
119
     * @param reader         the reader to read the DTD from.
120
     * @param entityResolver the entity resolver.
121
     * @param external       true if the DTD is external.
122
     *
123
     * @throws java.lang.Exception
124
     *     if something went wrong.
125
     */
126
    public void parseDTD(String             publicID,
127
                         IXMLReader         reader,
128
                         IXMLEntityResolver entityResolver,
129
                         boolean            external)
130
        throws Exception
131
    {
132
        this.delegate.parseDTD(publicID, reader, entityResolver, external);
133
    }
134

    
135
    
136
    /**
137
     * Indicates that an element has been started.
138
     *
139
     * @param name       the name of the element.
140
     * @param nsPrefix   the prefix used to identify the namespace
141
     * @param nsSystemId the system ID associated with the namespace
142
     * @param systemId   the system ID of the XML data of the element.
143
     * @param lineNr     the line number in the XML data of the element.
144
     *
145
     * @throws java.lang.Exception
146
     *     if the element could not be validated.
147
     */
148
    public void elementStarted(String name,
149
                               String nsPrefix,
150
                               String nsSystemId,
151
                               String systemId,
152
                               int    lineNr)
153
        throws Exception
154
    {
155
        this.delegate.elementStarted(name, nsPrefix, nsSystemId, systemId,
156
                                     lineNr);
157
    }
158
    
159
    
160
    /**
161
     * Indicates that the current element has ended.
162
     *
163
     * @param name       the name of the element.
164
     * @param nsPrefix   the prefix used to identify the namespace
165
     * @param nsSystemId the system ID associated with the namespace
166
     * @param systemId   the system ID of the XML data of the element.
167
     * @param lineNr     the line number in the XML data of the element.
168
     *
169
     * @throws java.lang.Exception
170
     *     if the element could not be validated.
171
     */
172
    public void elementEnded(String name,
173
                             String nsPrefix,
174
                             String nsSystemId,
175
                             String systemId,
176
                             int    lineNr)
177
        throws Exception
178
    {
179
        this.delegate.elementEnded(name, nsPrefix, nsSystemId, systemId,
180
                                   lineNr);
181
    }
182
    
183
    
184
    /**
185
     * Indicates that an attribute has been added to the current element.
186
     *
187
     * @param name            the name of the element.
188
     * @param nsPrefix        the prefix used to identify the namespace
189
     * @param nsSystemId      the system ID associated with the namespace
190
     * @param extraAttributes where to put extra attributes.
191
     * @param systemId        the system ID of the XML data of the element.
192
     * @param lineNr          the line number in the XML data of the element.
193
     *
194
     * @throws java.lang.Exception
195
     *     if the attribute could not be validated.
196
     */
197
    public void elementAttributesProcessed(String     name,
198
                                           String     nsPrefix,
199
                                           String     nsSystemId,
200
                                           Properties extraAttributes,
201
                                           String     systemId,
202
                                           int        lineNr)
203
        throws Exception
204
    {
205
        this.delegate.elementAttributesProcessed(name, nsPrefix, nsSystemId,
206
                                                 extraAttributes, systemId,
207
                                                 lineNr);
208
    }
209
    
210
    
211
    /**
212
     * This method is called when the attributes of an XML element have been
213
     * processed.
214
     * If there are attributes with a default value which have not been
215
     * specified yet, they have to be put into <I>extraAttributes</I>.
216
     *
217
     * @param key        the name of the attribute.
218
     * @param nsPrefix   the prefix used to identify the namespace
219
     * @param nsSystemId the system ID associated with the namespace
220
     * @param value      the value of the attribute.
221
     * @param systemId   the system ID of the XML data of the element.
222
     * @param lineNr     the line number in the XML data of the element.
223
     *
224
     * @throws java.lang.Exception
225
     *     if the element could not be validated.
226
     */
227
    public void attributeAdded(String key,
228
                               String nsPrefix,
229
                               String nsSystemId,
230
                               String value,
231
                               String systemId,
232
                               int    lineNr)
233
        throws Exception
234
    {
235
        this.delegate.attributeAdded(key, nsPrefix, nsSystemId, value,
236
                                     systemId, lineNr);
237
    }
238
    
239
    
240
    /**
241
     * Indicates that a new #PCDATA element has been encountered.
242
     *
243
     * @param systemId the system ID of the XML data of the element.
244
     * @param lineNr   the line number in the XML data of the element.
245
     *
246
     * @throws java.lang.Exception
247
     *     if the element could not be validated.
248
     */
249
    public void PCDataAdded(String systemId,
250
                            int    lineNr)
251
        throws Exception
252
    {
253
        this.delegate.PCDataAdded(systemId, lineNr);
254
    }
255
    
256
    
257
    /**
258
     * Throws an XMLValidationException to indicate that an element is missing.
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 parentElementName  the name of the parent element
263
     * @param missingElementName the name of the missing element
264
     *
265
     * @throws net.n3.nanoxml.XMLValidationException
266
     *      of course :-)
267
     */
268
    public void missingElement(String systemID,
269
                               int    lineNr,
270
                               String parentElementName,
271
                               String missingElementName)
272
        throws XMLValidationException
273
    {
274
        XMLUtil.errorMissingElement(systemID, lineNr, parentElementName,
275
                                    missingElementName);
276
    }
277

    
278

    
279
    /**
280
     * Throws an XMLValidationException to indicate that an element is
281
     * unexpected.
282
     *
283
     * @param systemID              the system ID of the XML data of the
284
     *                              element
285
     * @param lineNr                the line number in the XML data of the
286
     *                              element
287
     * @param parentElementName     the name of the parent element
288
     * @param unexpectedElementName the name of the missing element
289
     *
290
     * @throws net.n3.nanoxml.XMLValidationException
291
     *      of course :-)
292
     */
293
    public void unexpectedElement(String systemID,
294
                                  int    lineNr,
295
                                  String parentElementName,
296
                                  String unexpectedElementName)
297
        throws XMLValidationException
298
    {
299
        XMLUtil.errorUnexpectedElement(systemID, lineNr, parentElementName,
300
                                       unexpectedElementName);
301
    }
302

    
303

    
304
    /**
305
     * Throws an XMLValidationException to indicate that an attribute is
306
     * missing.
307
     *
308
     * @param systemID      the system ID of the XML data of the element
309
     * @param lineNr        the line number in the XML data of the element
310
     * @param elementName   the name of the element
311
     * @param attributeName the name of the missing attribute
312
     *
313
     * @throws net.n3.nanoxml.XMLValidationException
314
     *      of course :-)
315
     */
316
    public void missingAttribute(String systemID,
317
                                 int    lineNr,
318
                                 String elementName,
319
                                 String attributeName)
320
        throws XMLValidationException
321
    {
322
        XMLUtil.errorMissingAttribute(systemID, lineNr, elementName,
323
                                      attributeName);
324
    }
325

    
326

    
327
    /**
328
     * Throws an XMLValidationException to indicate that an attribute is
329
     * unexpected.
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 elementName   the name of the element
334
     * @param attributeName the name of the unexpected attribute
335
     *
336
     * @throws net.n3.nanoxml.XMLValidationException
337
     *      of course :-)
338
     */
339
    public void unexpectedAttribute(String systemID,
340
                                    int    lineNr,
341
                                    String elementName,
342
                                    String attributeName)
343
        throws XMLValidationException
344
    {
345
        XMLUtil.errorUnexpectedAttribute(systemID, lineNr, elementName,
346
                                         attributeName);
347
    }
348

    
349

    
350
    /**
351
     * Throws an XMLValidationException to indicate that an attribute has an
352
     * invalid value.
353
     *
354
     * @param systemID       the system ID of the XML data of the element
355
     * @param lineNr         the line number in the XML data of the element
356
     * @param elementName    the name of the element
357
     * @param attributeName  the name of the attribute
358
     * @param attributeValue the value of the attribute
359
     *
360
     * @throws net.n3.nanoxml.XMLValidationException
361
     *      of course :-)
362
     */
363
    public void invalidAttributeValue(String systemID,
364
                                      int    lineNr,
365
                                      String elementName,
366
                                      String attributeName,
367
                                      String attributeValue)
368
        throws XMLValidationException
369
    {
370
        XMLUtil.errorInvalidAttributeValue(systemID, lineNr, elementName,
371
                                           attributeName, attributeValue);
372
    }
373

    
374

    
375
    /**
376
     * Throws an XMLValidationException to indicate that a #PCDATA element was
377
     * missing.
378
     *
379
     * @param systemID          the system ID of the XML data of the element
380
     * @param lineNr            the line number in the XML data of the element
381
     * @param parentElementName the name of the parent element
382
     *
383
     * @throws net.n3.nanoxml.XMLValidationException
384
     *      of course :-)
385
     */
386
    public void missingPCData(String systemID,
387
                              int    lineNr,
388
                              String parentElementName)
389
        throws XMLValidationException
390
    {
391
        XMLUtil.errorMissingPCData(systemID, lineNr, parentElementName);
392
    }
393

    
394

    
395
    /**
396
     * Throws an XMLValidationException to indicate that a #PCDATA element was
397
     * unexpected.
398
     *
399
     * @param systemID          the system ID of the XML data of the element
400
     * @param lineNr            the line number in the XML data of the element
401
     * @param parentElementName the name of the parent element
402
     *
403
     * @throws net.n3.nanoxml.XMLValidationException
404
     *      of course :-)
405
     */
406
    public void unexpectedPCData(String systemID,
407
                                 int    lineNr,
408
                                 String parentElementName)
409
        throws XMLValidationException
410
    {
411
        XMLUtil.errorUnexpectedPCData(systemID, lineNr, parentElementName);
412
    }
413

    
414

    
415
    /**
416
     * Throws an XMLValidationException.
417
     *
418
     * @param systemID       the system ID of the XML data of the element
419
     * @param lineNr         the line number in the XML data of the element
420
     * @param message        the error message
421
     * @param elementName    the name of the element (may be null)
422
     * @param attributeName  the name of the attribute (may be null)
423
     * @param attributeValue the value of the attribute (may be null)
424
     *
425
     * @throws net.n3.nanoxml.XMLValidationException
426
     *      of course :-)
427
     */
428
    public void validationError(String systemID,
429
                                int    lineNr,
430
                                String message,
431
                                String elementName,
432
                                String attributeName,
433
                                String attributeValue)
434
        throws XMLValidationException
435
    {
436
        XMLUtil.validationError(systemID, lineNr, message, elementName,
437
                                attributeName, attributeValue);
438
    }
439

    
440
}