1 package org.apache.maven.plugin.changes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.logging.Log;
23 import org.xml.sax.Attributes;
24 import org.xml.sax.SAXException;
25 import org.xml.sax.helpers.DefaultHandler;
26
27 import javax.xml.parsers.SAXParser;
28 import javax.xml.parsers.SAXParserFactory;
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38 public class ChangesXML
39 extends DefaultHandler
40 {
41 private Action action;
42
43 private List actionList;
44
45 private Release release;
46
47 private StringBuffer currentElement = new StringBuffer( 1024 );
48
49 private String currentName;
50
51 private List releaseList;
52
53 private String author;
54
55 private String authorEmail;
56
57 private String title;
58
59 public ChangesXML( File xmlPath, Log log )
60 {
61 SAXParserFactory factory = SAXParserFactory.newInstance();
62
63 try
64 {
65 SAXParser saxParser = factory.newSAXParser();
66
67 saxParser.parse( xmlPath, this );
68 }
69 catch ( Throwable t )
70 {
71 log.error( "An error occured when parsing the changes.xml file:", t );
72 }
73 }
74
75 public void setAuthor( String author )
76 {
77 this.author = author;
78 }
79
80 public String getAuthor()
81 {
82 return author;
83 }
84
85 public void setAuthorEmail( String authorEmail )
86 {
87 this.authorEmail = authorEmail;
88 }
89
90 public String getAuthorEmail()
91 {
92 return authorEmail;
93 }
94
95 public void setReleaseList( List releaseList )
96 {
97 this.releaseList = releaseList;
98 }
99
100 public List getReleaseList()
101 {
102 return releaseList;
103 }
104
105 public void setTitle( String title )
106 {
107 this.title = title;
108 }
109
110 public String getTitle()
111 {
112 return title;
113 }
114
115 public void characters( char[] buf, int offset, int len )
116 throws SAXException
117 {
118 currentElement.append( buf, offset, len );
119 }
120
121 public void endElement( String namespaceURI, String sName, String qName )
122 throws SAXException
123 {
124 if ( qName.equals( "title" ) )
125 {
126 this.title = currentElement.toString().trim();
127 }
128 else if ( qName.equals( "author" ) )
129 {
130 this.author = currentElement.toString().trim();
131 }
132 else if ( qName.equals( "action" ) )
133 {
134 action.setAction( currentElement.toString().trim() );
135
136 actionList.add( action );
137 }
138 else if ( qName.equals( "release" ) )
139 {
140 release.setAction( actionList );
141
142 releaseList.add( release );
143 }
144
145 currentElement.setLength( 0 );
146 }
147
148 public void startElement( String namespaceURI, String sName, String qName, Attributes attrs )
149 throws SAXException
150 {
151 if ( qName.equals( "title" ) )
152 {
153 this.title = "";
154 }
155 else if ( qName.equals( "author" ) )
156 {
157 this.authorEmail = attrs.getValue( "email" );
158
159 this.author = "";
160 }
161 else if ( qName.equals( "body" ) )
162 {
163 releaseList = new ArrayList();
164 }
165 else if ( qName.equals( "release" ) )
166 {
167 release = new Release();
168
169 release.setDateRelease( attrs.getValue( "date" ) );
170
171 release.setVersion( attrs.getValue( "version" ) );
172
173 release.setDescription( attrs.getValue( "description" ) );
174
175 actionList = new ArrayList();
176 }
177 else if ( qName.equals( "action" ) )
178 {
179 action = new Action();
180
181 action.setDev( attrs.getValue( "dev" ) );
182
183 action.setDueTo( attrs.getValue( "due-to" ) );
184
185 action.setDueToEmail( attrs.getValue( "due-to-email" ) );
186
187 action.setType( attrs.getValue( "type" ) );
188
189 action.setIssue( attrs.getValue( "issue" ) );
190 }
191
192 currentName = qName;
193 }
194 }