Source Code Cross Referenced for SAXParser.java in  » Parser » NanoXML » net » n3 » nanoxml » sax » 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 » Parser » NanoXML » net.n3.nanoxml.sax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* SAXParser.java                                                   NanoXML/SAX
002:         *
003:         * $Revision: 1.5 $
004:         * $Date: 2002/03/24 11:39:20 $
005:         * $Name: RELEASE_2_2_1 $
006:         *
007:         * This file is part of the SAX adapter for NanoXML 2 for Java.
008:         * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009:         *
010:         * This software is provided 'as-is', without any express or implied warranty.
011:         * In no event will the authors be held liable for any damages arising from the
012:         * use of this software.
013:         *
014:         * Permission is granted to anyone to use this software for any purpose,
015:         * including commercial applications, and to alter it and redistribute it
016:         * freely, subject to the following restrictions:
017:         *
018:         *  1. The origin of this software must not be misrepresented; you must not
019:         *     claim that you wrote the original software. If you use this software in
020:         *     a product, an acknowledgment in the product documentation would be
021:         *     appreciated but is not required.
022:         *
023:         *  2. Altered source versions must be plainly marked as such, and must not be
024:         *     misrepresented as being the original software.
025:         *
026:         *  3. This notice may not be removed or altered from any source distribution.
027:         */
028:
029:        package net.n3.nanoxml.sax;
030:
031:        import java.io.FileNotFoundException;
032:        import java.io.InputStream;
033:        import java.io.InputStreamReader;
034:        import java.io.IOException;
035:        import java.io.Reader;
036:        import java.io.UnsupportedEncodingException;
037:        import java.net.MalformedURLException;
038:        import java.util.Locale;
039:        import net.n3.nanoxml.IXMLBuilder;
040:        import net.n3.nanoxml.IXMLParser;
041:        import net.n3.nanoxml.IXMLReader;
042:        import net.n3.nanoxml.StdXMLReader;
043:        import net.n3.nanoxml.XMLParserFactory;
044:        import org.xml.sax.Parser;
045:        import org.xml.sax.DocumentHandler;
046:        import org.xml.sax.DTDHandler;
047:        import org.xml.sax.EntityResolver;
048:        import org.xml.sax.ErrorHandler;
049:        import org.xml.sax.HandlerBase;
050:        import org.xml.sax.InputSource;
051:        import org.xml.sax.Locator;
052:        import org.xml.sax.SAXException;
053:        import org.xml.sax.helpers.AttributeListImpl;
054:        import org.xml.sax.helpers.LocatorImpl;
055:
056:        /**
057:         * SAXParser implements the SAX Parser interface. It is the frontend to SAX
058:         * for the NanoXML parser.
059:         *
060:         * @author Marc De Scheemaecker
061:         * @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $
062:         */
063:        public class SAXParser implements  Parser {
064:
065:            /**
066:             * The SAX adapter.
067:             */
068:            private SAXAdapter adapter;
069:
070:            /**
071:             * The client error handler.
072:             */
073:            private ErrorHandler errorHandler;
074:
075:            /**
076:             * The entity resolver.
077:             */
078:            private SAXEntityResolver entityResolver;
079:
080:            /**
081:             * Creates the SAX parser.
082:             */
083:            public SAXParser() {
084:                this .adapter = new SAXAdapter();
085:                this .errorHandler = new HandlerBase();
086:                this .entityResolver = new SAXEntityResolver();
087:            }
088:
089:            /**
090:             * Cleans up the object when it's destroyed.
091:             */
092:            protected void finalize() throws Throwable {
093:                this .adapter = null;
094:                this .errorHandler = null;
095:                this .entityResolver = null;
096:                super .finalize();
097:            }
098:
099:            /**
100:             * Sets the locale. Only locales using the language english are accepted.
101:             *
102:             * @param locale the locale
103:             *
104:             * @exception org.xml.sax.SAXException
105:             *    if <CODE>locale</CODE> is <CODE>null</CODE> or the associated
106:             *    language is not english.
107:             */
108:            public void setLocale(Locale locale) throws SAXException {
109:                if ((locale == null) || (!locale.getLanguage().equals("en"))) {
110:                    throw new SAXException(
111:                            "NanoXML/SAX doesn't support locale: " + locale);
112:                }
113:            }
114:
115:            /**
116:             * Sets the entity resolver.
117:             *
118:             * @param resolver the entity resolver
119:             */
120:            public void setEntityResolver(EntityResolver resolver) {
121:                this .entityResolver.setEntityResolver(resolver);
122:            }
123:
124:            /**
125:             * Sets the DTD handler. As the parser is non-validating, this handler is
126:             * never called.
127:             *
128:             * @param handler the DTD handler
129:             */
130:            public void setDTDHandler(DTDHandler handler) {
131:                // nothing to do
132:            }
133:
134:            /**
135:             * Allows an application to register a document event handler.
136:             *
137:             * @param handler the document handler
138:             */
139:            public void setDocumentHandler(DocumentHandler handler) {
140:                this .adapter.setDocumentHandler(handler);
141:            }
142:
143:            /**
144:             * Allow an application to register an error event handler.
145:             *
146:             * @param handler the error handler
147:             */
148:            public void setErrorHandler(ErrorHandler handler) {
149:                this .errorHandler = handler;
150:            }
151:
152:            /**
153:             * Creates the XML parser.
154:             */
155:            private IXMLParser createParser() throws SAXException {
156:                try {
157:                    return XMLParserFactory.createDefaultXMLParser();
158:                } catch (Exception exception) {
159:                    throw new SAXException(exception);
160:                }
161:            }
162:
163:            /**
164:             * Parse an XML document.
165:             *
166:             * @param source the input source
167:             */
168:            public void parse(InputSource source) throws SAXException,
169:                    IOException {
170:                IXMLParser parser = this .createParser();
171:                parser.setBuilder(this .adapter);
172:                parser.setResolver(this .entityResolver);
173:                Reader reader = source.getCharacterStream();
174:
175:                if (reader != null) {
176:                    parser.setReader(new StdXMLReader(reader));
177:                } else {
178:                    InputStream stream = source.getByteStream();
179:
180:                    if (stream != null) {
181:                        String encoding = source.getEncoding();
182:
183:                        if (encoding != null) {
184:                            try {
185:                                reader = new InputStreamReader(stream, encoding);
186:                                parser.setReader(new StdXMLReader(reader));
187:                            } catch (UnsupportedEncodingException exception) {
188:                                throw new SAXException(exception);
189:                            }
190:                        } else { // if encoding == null
191:                            parser.setReader(new StdXMLReader(stream));
192:                        }
193:                    } else { // if stream == null
194:                        parser.setReader(new StdXMLReader(source.getPublicId(),
195:                                source.getSystemId()));
196:                    }
197:                }
198:
199:                try {
200:                    parser.parse();
201:                    this .adapter.endDocument();
202:                } catch (IOException exception) {
203:                    throw exception;
204:                } catch (Exception exception) {
205:                    throw new SAXException(exception);
206:                } finally {
207:                    reader.close();
208:                }
209:            }
210:
211:            /**
212:             * Parse an XML document from a system identifier (URI).
213:             *
214:             * @param systemId the system ID
215:             */
216:            public void parse(String systemId) throws SAXException, IOException {
217:                IXMLParser parser = this .createParser();
218:                parser.setBuilder(this .adapter);
219:                parser.setReader(new StdXMLReader(null, systemId));
220:
221:                try {
222:                    parser.parse();
223:                    this .adapter.endDocument();
224:                } catch (IOException exception) {
225:                    throw exception;
226:                } catch (Exception exception) {
227:                    throw new SAXException(exception);
228:                }
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.