|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CatalogHandler.java | 100% | 100% | 100% | 100% |
|
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 | 21 |
CatalogHandler( final List entitys ) |
36 |
{ |
|
37 | 21 |
if( null == entitys ) |
38 |
{ |
|
39 | 1 |
throw new NullPointerException( "entitys" ); |
40 |
} |
|
41 |
|
|
42 | 20 |
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 | 59 |
public void startElement( final String uri, |
55 |
final String localName, |
|
56 |
final String qName, |
|
57 |
final Attributes attributes ) |
|
58 |
throws SAXException
|
|
59 |
{ |
|
60 | 59 |
if( "catalog".equals( qName ) ) |
61 |
{ |
|
62 | 20 |
final String version = attributes.getValue( "version" );
|
63 | 20 |
if( null == version ) |
64 |
{ |
|
65 | 1 |
final String message = |
66 |
"'version' attribute must be specified for catalog element.";
|
|
67 | 1 |
throw new SAXException( message ); |
68 |
} |
|
69 | 19 |
else if( !"1.0".equals( version ) ) |
70 |
{ |
|
71 | 1 |
final String message = |
72 |
"'version' attribute must have value of '1.0' for catalog element.";
|
|
73 | 1 |
throw new SAXException( message ); |
74 |
} |
|
75 |
} |
|
76 | 39 |
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 | 38 |
final String publicId = attributes.getValue( "publicId" );
|
84 | 38 |
final String systemId = attributes.getValue( "systemId" );
|
85 | 38 |
final String resource = attributes.getValue( "resource" );
|
86 |
|
|
87 | 38 |
if( null == publicId && null == systemId ) |
88 |
{ |
|
89 | 1 |
final String message = |
90 |
"One of publicId or systemId attributes must be specified " +
|
|
91 |
"for entity element.";
|
|
92 | 1 |
throw new SAXException( message ); |
93 |
} |
|
94 | 37 |
if( null == resource ) |
95 |
{ |
|
96 | 1 |
final String message = |
97 |
"resource attribute must be specified for entity element.";
|
|
98 | 1 |
throw new SAXException( message ); |
99 |
} |
|
100 |
|
|
101 | 36 |
m_entitys.add( new EntityInfo( publicId, systemId, resource ) );
|
102 |
} |
|
103 |
else
|
|
104 |
{ |
|
105 | 1 |
final String message = "unknown element " + qName + "."; |
106 | 1 |
throw new SAXException( message ); |
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
|
|