alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.catalog.impl.oasis;

import org.xml.sax.*;

/**
 * The class reads XML documents according to specified DTD and
 * translates all related events into CatalogHandler events.
 * 

Usage sample: *

 *    CatalogParser parser = new CatalogParser(...);
 *    parser.parse(new InputSource("..."));
 * 
*

Warning: the class is machine generated. DO NOT MODIFY

*/ public class CatalogParser implements DocumentHandler { private java.lang.StringBuffer buffer; private CatalogHandler handler; private java.util.Stack context; public CatalogParser(final CatalogHandler handler) { this.handler = handler; buffer = new StringBuffer(111); context = new java.util.Stack(); } public void setDocumentLocator(Locator locator) { } public void startDocument() throws SAXException { } public void endDocument() throws SAXException { } public void startElement(java.lang.String name, AttributeList attrs) throws SAXException { dispatch(true); context.push(new Object[] {name, new org.xml.sax.helpers.AttributeListImpl(attrs)}); if ("system".equals(name)) { // NOI18N handler.handle_system(attrs); } else if ("uri".equals(name)) { // NOI18N handler.handle_uri(attrs); } else if ("public".equals(name)) { // NOI18N handler.handle_public(attrs); } else if ("rewriteSystem".equals(name)) { // NOI18N handler.handle_rewriteSystem(attrs); } else if ("delegateSystem".equals(name)) { // NOI18N handler.handle_delegateSystem(attrs); } else if ("catalog".equals(name)) { // NOI18N handler.start_catalog(attrs); } else if ("rewriteURI".equals(name)) { // NOI18N handler.handle_rewriteURI(attrs); } else if ("delegatePublic".equals(name)) { // NOI18N handler.handle_delegatePublic(attrs); } else if ("nextCatalog".equals(name)) { // NOI18N handler.handle_nextCatalog(attrs); } else if ("group".equals(name)) { // NOI18N handler.start_group(attrs); } else if ("delegateURI".equals(name)) { // NOI18N handler.handle_delegateURI(attrs); } } public void endElement(java.lang.String name) throws SAXException { dispatch(false); context.pop(); if ("catalog".equals(name)) { // NOI18N handler.end_catalog(); } else if ("group".equals(name)) { // NOI18N handler.end_group(); } } public void characters(char[] chars, int start, int len) throws SAXException { buffer.append(chars, start, len); } public void ignorableWhitespace(char[] chars, int start, int len) throws SAXException { } public void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException { } private void dispatch(final boolean fireOnlyIfMixed) throws SAXException { if (fireOnlyIfMixed && buffer.length() == 0) return; //skip it Object[] ctx = (Object[]) context.peek(); String here = (String) ctx[0]; AttributeList attrs = (AttributeList) ctx[1]; buffer.delete(0, buffer.length()); } /** * The recognizer entry method taking an InputSource. * @param input InputSource to be parsed. * @throws java.io.IOException on I/O error. * @throws SAXException propagated exception thrown by a DocumentHandler. * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created. * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated. */ public void parse(final InputSource input) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException { parse(input, this); } /** * The recognizer entry method taking a URL. * @param url URL source to be parsed. * @throws java.io.IOException on I/O error. * @throws SAXException propagated exception thrown by a DocumentHandler. * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created. * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated. */ public void parse(final java.net.URL url) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException { parse(new InputSource(url.toExternalForm()), this); } /** * The recognizer entry method taking an Inputsource. * @param input InputSource to be parsed. * @throws java.io.IOException on I/O error. * @throws SAXException propagated exception thrown by a DocumentHandler. * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created. * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated. */ public static void parse(final InputSource input, final CatalogHandler handler) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException { parse(input, new CatalogParser(handler)); } /** * The recognizer entry method taking a URL. * @param url URL source to be parsed. * @throws java.io.IOException on I/O error. * @throws SAXException propagated exception thrown by a DocumentHandler. * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created. * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated. */ public static void parse(final java.net.URL url, final CatalogHandler handler) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException { parse(new InputSource(url.toExternalForm()), handler); } private static void parse(final InputSource input, final CatalogParser recognizer) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException { javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance(); factory.setValidating(true); //the code was generated according DTD factory.setNamespaceAware(false); //the code was generated according DTD Parser parser = factory.newSAXParser().getParser(); parser.setDocumentHandler(recognizer); parser.setErrorHandler(recognizer.getDefaultErrorHandler()); parser.parse(input); } private ErrorHandler getDefaultErrorHandler() { return new ErrorHandler() { public void error(SAXParseException ex) throws SAXException { if (context.isEmpty()) { if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Missing DOCTYPE."); // NOI18N } throw ex; } public void fatalError(SAXParseException ex) throws SAXException { throw ex; } public void warning(SAXParseException ex) throws SAXException { // ignore } }; } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.