Source Code Cross Referenced for SvnXmlRepositoriesFileHandler.java in  » Source-Control » statsvn » net » sf » statsvn » input » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Source Control » statsvn » net.sf.statsvn.input 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.statsvn.input;
002:
003:        import javax.xml.parsers.ParserConfigurationException;
004:
005:        import org.xml.sax.Attributes;
006:        import org.xml.sax.SAXException;
007:        import org.xml.sax.SAXParseException;
008:        import org.xml.sax.helpers.DefaultHandler;
009:
010:        /**
011:         * This is the SAX parser for the repositories xml file. This xml file 
012:         * identifies the line counts xml files for all repositories for which 
013:         * SVN stats have been compiled.
014:         * 
015:         * @author Gunter Mussbacher <gunterm@site.uottawa.ca>
016:         * 
017:         * @version $Id: SvnXmlRepositoriesFileHandler.java 144 2006-11-19 19:35:09Z benoitx $
018:         */
019:        public class SvnXmlRepositoriesFileHandler extends DefaultHandler {
020:
021:            private static final String FATAL_ERROR_MESSAGE = "Invalid StatSvn repositories file.";
022:            private static final String REPOSITORIES = "repositories";
023:            private static final String REPOSITORY = "repository";
024:            private static final String UUID = "uuid";
025:            private static final String FILE = "file";
026:            private String lastElement = "";
027:            private RepositoriesBuilder repositoriesBuilder;
028:
029:            /**
030:             * Default constructor
031:             * 
032:             * @param repositoriesBuilder
033:             *            the RepositoriesBuilder to which to send back the repository information.
034:             */
035:            public SvnXmlRepositoriesFileHandler(
036:                    final RepositoriesBuilder repositoriesBuilder) {
037:                this .repositoriesBuilder = repositoriesBuilder;
038:            }
039:
040:            /**
041:             * Makes sure the last element received is appropriate.
042:             * 
043:             * @param last
044:             *            the expected last element.
045:             * @throws SAXException
046:             *             unexpected event.
047:             */
048:            private void checkLastElement(final String last)
049:                    throws SAXException {
050:                if (!lastElement.equals(last)) {
051:                    fatalError(FATAL_ERROR_MESSAGE);
052:                }
053:            }
054:
055:            /**
056:             * Handles the end of an xml element and redirects to the appropriate end* method.
057:             * 
058:             * @throws SAXException
059:             *             unexpected event.
060:             */
061:            public void endElement(final String uri, final String localName,
062:                    final String qName) throws SAXException {
063:                super .endElement(uri, localName, qName);
064:                String eName = localName; // element name
065:                if ("".equals(eName)) {
066:                    eName = qName; // namespaceAware = false
067:                }
068:
069:                if (eName.equals(REPOSITORIES)) {
070:                    endRepositories();
071:                } else if (eName.equals(REPOSITORY)) {
072:                    endRepository();
073:                } else {
074:                    fatalError(FATAL_ERROR_MESSAGE);
075:                }
076:            }
077:
078:            /**
079:             * End of repositories element.
080:             * 
081:             * @throws SAXException
082:             *             unexpected event.
083:             */
084:            private void endRepositories() throws SAXException {
085:                checkLastElement(REPOSITORIES);
086:                lastElement = "";
087:            }
088:
089:            /**
090:             * End of repository element.
091:             * 
092:             * @throws SAXException
093:             *             unexpected event.
094:             */
095:            private void endRepository() throws SAXException {
096:                checkLastElement(REPOSITORY);
097:                lastElement = REPOSITORIES;
098:            }
099:
100:            /**
101:             * Throws a fatal error with the specified message.
102:             * 
103:             * @param message
104:             *            the reason for the error
105:             * @throws SAXException
106:             *             the error
107:             */
108:            private void fatalError(final String message) throws SAXException {
109:                fatalError(new SAXParseException(message, null));
110:            }
111:
112:            /**
113:             * Handles the start of an xml element and redirects to the appropriate start* method.
114:             * 
115:             * @throws SAXException
116:             *             unexpected event.
117:             */
118:            public void startElement(final String uri, final String localName,
119:                    final String qName, final Attributes attributes)
120:                    throws SAXException {
121:                super .startElement(uri, localName, qName, attributes);
122:
123:                String eName = localName; // element name
124:                if ("".equals(eName)) {
125:                    eName = qName; // namespaceAware = false
126:                }
127:
128:                if (eName.equals(REPOSITORIES)) {
129:                    startRepositories();
130:                } else if (eName.equals(REPOSITORY)) {
131:                    startRepository(attributes);
132:                } else {
133:                    fatalError(FATAL_ERROR_MESSAGE);
134:                }
135:            }
136:
137:            /**
138:             * Handles the start of the document. Initializes the repository builder.
139:             * 
140:             * @throws SAXException
141:             *             unable to build the root.
142:             */
143:            private void startRepositories() throws SAXException {
144:                checkLastElement("");
145:                lastElement = REPOSITORIES;
146:                try {
147:                    repositoriesBuilder.buildRoot();
148:                } catch (final ParserConfigurationException e) {
149:                    fatalError(FATAL_ERROR_MESSAGE);
150:                }
151:            }
152:
153:            /**
154:             * Handles start of a repository. Initializes repositories builder for use with repository.
155:             * 
156:             * @param attributes
157:             *            element's xml attributes.
158:             * @throws SAXException
159:             *             missing some data.
160:             */
161:            private void startRepository(final Attributes attributes)
162:                    throws SAXException {
163:                checkLastElement(REPOSITORIES);
164:                lastElement = REPOSITORY;
165:                if (attributes != null && attributes.getValue(UUID) != null
166:                        && attributes.getValue(FILE) != null) {
167:                    final String uuid = attributes.getValue(UUID);
168:                    final String file = attributes.getValue(FILE);
169:                    repositoriesBuilder.buildRepository(uuid, file);
170:                } else {
171:                    fatalError(FATAL_ERROR_MESSAGE);
172:                }
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.