1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.jsr168.pluto.xml;
35
36 import org.xml.sax.Attributes;
37 import org.xml.sax.SAXException;
38 import org.xml.sax.helpers.DefaultHandler;
39
40 import java.util.Stack;
41
42
43
44
45
46 class ServicesXMLHandler extends DefaultHandler
47 {
48 private final Stack _stack;
49 private final ServicesXML _servicesXml;
50
51
52
53
54 ServicesXMLHandler( )
55 {
56 _stack = new Stack( );
57 _servicesXml = new ServicesXML( );
58 }
59
60
61
62
63
64
65 ServicesXML getServicesXML( )
66 {
67 return _servicesXml;
68 }
69
70
71
72
73 public void endElement( String uri, String localName, String qName )
74 throws SAXException
75 {
76 if ( "service".equals( qName ) )
77 {
78 _stack.pop( );
79 }
80 else if ( !"services".equals( qName ) && !"properties".equals( qName ) && !"property".equals( qName ) )
81 {
82 throw new SAXException( "End Element '" + qName + "' non géré!" );
83 }
84 }
85
86
87
88
89 public void startElement( final String uri, final String localName, final String qName, final Attributes attributes )
90 throws SAXException
91 {
92 if ( "service".equals( qName ) )
93 {
94 final String serviceBase = attributes.getValue( "serviceBase" );
95 final String implementation = attributes.getValue( "implementation" );
96
97 final ServiceXML serviceXml = new ServiceXML( serviceBase, implementation );
98 _servicesXml.addService( serviceXml );
99 _stack.push( serviceXml );
100 }
101 else if ( "property".equals( qName ) )
102 {
103 final String name = attributes.getValue( "name" );
104 final String value = attributes.getValue( "value" );
105
106 final ServiceXML serviceXml = (ServiceXML) _stack.peek( );
107 serviceXml.addProperty( name, value );
108 }
109 else if ( !"services".equals( qName ) && !"properties".equals( qName ) )
110 {
111 throw new SAXException( "Start Element '" + qName + "' unknown!" );
112 }
113 }
114 }