1 /*
2 * Copyright (C) The Spice Group. All rights reserved.
3 *
4 * This software is published under the terms of the Spice
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.codehaus.spice.configkit;
9
10 import java.util.List;
11 import org.xml.sax.Attributes;
12 import org.xml.sax.SAXException;
13 import org.xml.sax.helpers.DefaultHandler;
14
15 /***
16 * This is the SAX handler that creates a list of entitys. The handler verifies
17 * that the correct version is specified in catalog tag and that the entity tag
18 * has correct attributes specified. See {@link ResolverFactory} for a
19 * description of xml format that is parsed.
20 *
21 * @author Peter Donald
22 * @version $Revision: 1.1 $ $Date: 2003/12/03 03:19:28 $
23 */
24 class CatalogHandler
25 extends DefaultHandler
26 {
27 /*** The list of entitys collected by handler. */
28 private final List m_entitys;
29
30 /***
31 * Create handler that adds entitys to specified list.
32 *
33 * @param entitys the list to add entitys to
34 */
35 CatalogHandler( final List entitys )
36 {
37 if( null == entitys )
38 {
39 throw new NullPointerException( "entitys" );
40 }
41
42 m_entitys = entitys;
43 }
44
45 /***
46 * Process an xml element.
47 *
48 * @param uri the uri of element (ignored)
49 * @param localName the local name of element
50 * @param qName the qualified name (with prefix)
51 * @param attributes the attributes of element
52 * @throws SAXException if unable to parse element
53 */
54 public void startElement( final String uri,
55 final String localName,
56 final String qName,
57 final Attributes attributes )
58 throws SAXException
59 {
60 if( "catalog".equals( qName ) )
61 {
62 final String version = attributes.getValue( "version" );
63 if( null == version )
64 {
65 final String message =
66 "'version' attribute must be specified for catalog element.";
67 throw new SAXException( message );
68 }
69 else if( !"1.0".equals( version ) )
70 {
71 final String message =
72 "'version' attribute must have value of '1.0' for catalog element.";
73 throw new SAXException( message );
74 }
75 }
76 else if( "entity".equals( qName ) )
77 {
78 /*
79 * <entity publicId=""-//PHOENIX/Mx Info DTD Version 1.0//EN""
80 * systemId="http://jakarta.apache.org/phoenix/mxinfo_1_0.dtd"
81 * resource="org/apache/avalon/phoenix/tools/mxinfo.dtd"/>
82 */
83 final String publicId = attributes.getValue( "publicId" );
84 final String systemId = attributes.getValue( "systemId" );
85 final String resource = attributes.getValue( "resource" );
86
87 if( null == publicId && null == systemId )
88 {
89 final String message =
90 "One of publicId or systemId attributes must be specified " +
91 "for entity element.";
92 throw new SAXException( message );
93 }
94 if( null == resource )
95 {
96 final String message =
97 "resource attribute must be specified for entity element.";
98 throw new SAXException( message );
99 }
100
101 m_entitys.add( new EntityInfo( publicId, systemId, resource ) );
102 }
103 else
104 {
105 final String message = "unknown element " + qName + ".";
106 throw new SAXException( message );
107 }
108 }
109 }
This page was automatically generated by Maven