home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.parser;
-
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.Reader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Locale;
- import java.util.Stack;
- import org.xml.sax.AttributeList;
- import org.xml.sax.DTDHandler;
- import org.xml.sax.DocumentHandler;
- import org.xml.sax.EntityResolver;
- import org.xml.sax.ErrorHandler;
- import org.xml.sax.HandlerBase;
- import org.xml.sax.InputSource;
- import org.xml.sax.Parser;
- import org.xml.sax.SAXException;
- import org.xml.sax.SAXParseException;
- import org.xml.sax.helpers.LocatorImpl;
-
- public class SAXDriver implements Parser, AttributeList, ErrorListener, TagHandler, StreamProducer {
- static HandlerBase s_defaulthandler = new HandlerBase();
- com.ibm.xml.parser.Parser parser;
- Locale locale;
- EntityResolver entityHandler;
- DTDHandler dtdHandler;
- DocumentHandler documentHandler;
- ErrorHandler errorHandler;
- TXAttribute[] attributes;
- DTD dtd;
- String currentSystemID;
- Stack stack;
- int depth;
- RuntimeException userException;
- boolean pause;
-
- public void setLocale(Locale var1) throws SAXException {
- this.locale = var1;
- if (this.parser != null) {
- this.parser.setLocale(var1);
- }
-
- }
-
- public void setEntityResolver(EntityResolver var1) {
- this.entityHandler = var1;
- }
-
- public void setDTDHandler(DTDHandler var1) {
- this.dtdHandler = var1;
- }
-
- public void setDocumentHandler(DocumentHandler var1) {
- this.documentHandler = var1;
- }
-
- public void setErrorHandler(ErrorHandler var1) {
- this.errorHandler = var1;
- }
-
- public void parse(InputSource var1) throws SAXException {
- this.depth = 0;
- this.pause = false;
- this.stack = new Stack();
- this.currentSystemID = var1.getSystemId();
- this.documentHandler.startDocument();
-
- try {
- this.parser = new com.ibm.xml.parser.Parser(this.currentSystemID, this, this);
- this.parser.setSAXDriver(this);
- if (this.locale != null) {
- this.parser.setLocale(this.locale);
- }
-
- this.parser.setElementFactory(new SAXDocument(this));
- this.parser.setTagHandler(this);
- this.stack.push(this.currentSystemID);
- if (var1.getByteStream() != null) {
- this.parser.readStream(var1.getByteStream());
- } else if (var1.getCharacterStream() != null) {
- this.parser.readStream(var1.getCharacterStream());
- } else {
- this.parser.readStream(this.getInputStream(this.currentSystemID, (String)null, this.currentSystemID));
- }
-
- if (this.userException == null) {
- this.documentHandler.endDocument();
- }
- } catch (SAXException var9) {
- throw var9;
- } catch (ExceptionWrapper var10) {
- throw var10.wrapped;
- } catch (Exception var11) {
- throw new SAXException(var11);
- } finally {
- this.parser = null;
- this.attributes = null;
- this.dtd = null;
- this.currentSystemID = null;
- this.stack = null;
- this.userException = null;
- }
-
- }
-
- public void parse(String var1) throws SAXException {
- this.parse(new InputSource(var1));
- }
-
- public int getLength() {
- return this.attributes.length;
- }
-
- public String getName(int var1) {
- return this.attributes[var1].getName();
- }
-
- public String getType(int var1) {
- int var2 = this.attributes[var1].getType();
- if (var2 == 0) {
- var2 = 1;
- }
-
- return AttDef.S_TYPESTR[var2];
- }
-
- public String getType(String var1) {
- int var2 = this.searchAttribute(var1);
- return var2 < 0 ? null : this.getType(var2);
- }
-
- public String getValue(int var1) {
- return this.attributes[var1].getValue();
- }
-
- public String getValue(String var1) {
- int var2 = this.searchAttribute(var1);
- return var2 < 0 ? null : this.getValue(var2);
- }
-
- public Source getInputStream(String var1, String var2, String var3) throws IOException, RuntimeException {
- Source var4 = null;
- String var5 = this.currentSystemID;
- if (var3 != null) {
- try {
- this.stack.push(var5);
- this.currentSystemID = var3;
- InputSource var6 = this.entityHandler.resolveEntity(var2, var3);
- if (var6 != null) {
- if (var6.getSystemId() != null) {
- this.currentSystemID = var3 = var6.getSystemId();
- }
-
- if (var6.getByteStream() != null) {
- var4 = new Source(var6.getByteStream());
- } else if (var6.getCharacterStream() != null) {
- var4 = new Source(var6.getCharacterStream());
- }
- }
-
- if (var4 == null) {
- URL var7;
- if (var5 == null) {
- var7 = new URL(var3);
- } else {
- var7 = new URL(new URL(var5), var3);
- }
-
- this.currentSystemID = var7.toString();
- var4 = new Source(var7.openStream());
- }
- } catch (MalformedURLException var8) {
- var4 = new Source(new FileInputStream(var3));
- } catch (SAXException var9) {
- throw new ExceptionWrapper(this, var9);
- }
- }
-
- return var4;
- }
-
- public void closeInputStream(Source var1) {
- try {
- this.currentSystemID = (String)this.stack.pop();
- } catch (Exception var2) {
- }
- }
-
- public void loadCatalog(Reader var1) throws IOException {
- }
-
- public int error(String var1, int var2, int var3, Object var4, String var5) throws RuntimeException {
- if (this.userException != null) {
- throw this.userException;
- } else {
- LocatorImpl var6 = new LocatorImpl();
- var6.setSystemId(var1);
- var6.setLineNumber(var2);
- var6.setColumnNumber(var3);
- SAXParseException var7 = new SAXParseException(var5, var6);
- boolean var8 = var4 instanceof String && ((String)var4).startsWith("W_");
- boolean var9 = var4 instanceof String && ((String)var4).startsWith("V_");
-
- try {
- if (var8) {
- this.errorHandler.warning(var7);
- } else if (var9) {
- this.errorHandler.error(var7);
- } else {
- this.errorHandler.fatalError(var7);
- }
-
- return 0;
- } catch (SAXException var11) {
- this.userException = new ExceptionWrapper(this, var11);
- throw this.userException;
- }
- }
- }
-
- public void handleStartTag(TXElement var1, boolean var2) throws RuntimeException {
- ++this.depth;
- if (!this.pause) {
- this.attributes = var1.getAttributeArray();
-
- try {
- this.documentHandler.startElement(var1.getNodeName(), this);
- } catch (SAXException var4) {
- throw new ExceptionWrapper(this, var4);
- }
-
- this.attributes = null;
- }
-
- }
-
- public void handleEndTag(TXElement var1, boolean var2) throws RuntimeException {
- --this.depth;
- if (!this.pause) {
- try {
- this.documentHandler.endElement(var1.getNodeName());
- } catch (SAXException var4) {
- throw new ExceptionWrapper(this, var4);
- }
- }
- }
-
- private int searchAttribute(String var1) {
- for(int var2 = 0; var2 < this.attributes.length; ++var2) {
- if (var1.equals(this.attributes[var2].getName())) {
- return var2;
- }
- }
-
- return -1;
- }
-
- void pauseEvent(boolean var1) {
- this.pause = var1;
- }
-
- public SAXDriver() {
- this.entityHandler = s_defaulthandler;
- this.dtdHandler = s_defaulthandler;
- this.documentHandler = s_defaulthandler;
- this.errorHandler = s_defaulthandler;
- this.pause = false;
- }
- }
-