|
From: <to...@us...> - 2007-01-29 22:09:59
|
Revision: 9
http://techne-dev.svn.sourceforge.net/techne-dev/?rev=9&view=rev
Author: tonit
Date: 2007-01-29 14:09:59 -0800 (Mon, 29 Jan 2007)
Log Message:
-----------
Added Paths:
-----------
sandbox/tonit/techne.farrt/src/techne/farrt/parser/
sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXHandler.java
sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXParser.java
sandbox/tonit/techne.farrt/src/techne/farrt/parser/ParseException.java
Added: sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXHandler.java
===================================================================
--- sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXHandler.java (rev 0)
+++ sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXHandler.java 2007-01-29 22:09:59 UTC (rev 9)
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package techne.farrt.parser;
+
+import java.util.Properties;
+
+/**
+ * Interface for SAX handler with kXML
+ */
+public interface KXml2SAXHandler {
+
+ /**
+ * Method called when parsing text
+ *
+ * @param ch
+ * @param offset
+ * @param length
+ * @exception SAXException
+ */
+ public void characters(char[] ch, int offset, int length) throws Exception;
+
+ /**
+ * Method called when a tag opens
+ *
+ * @param uri
+ * @param localName
+ * @param qName
+ * @param attrib
+ * @exception SAXException
+ **/
+ public void startElement(
+ String uri,
+ String localName,
+ String qName,
+ Properties attrib)
+ throws Exception;
+ /**
+ * Method called when a tag closes
+ *
+ * @param uri
+ * @param localName
+ * @param qName
+ * @exception SAXException
+ */
+ public void endElement(
+ java.lang.String uri,
+ java.lang.String localName,
+ java.lang.String qName)
+ throws Exception;
+
+ public void processingInstruction(String target,
+ String data)
+ throws Exception;
+
+ public void setLineNumber(int lineNumber);
+
+ public void setColumnNumber(int columnNumber);
+}
Added: sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXParser.java
===================================================================
--- sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXParser.java (rev 0)
+++ sandbox/tonit/techne.farrt/src/techne/farrt/parser/KXml2SAXParser.java 2007-01-29 22:09:59 UTC (rev 9)
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package techne.farrt.parser;
+
+import java.io.Reader;
+import java.util.Properties;
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * The KXml2SAXParser extends the XmlParser from kxml. This is a very
+ * simple parser that does not take into account the DTD
+ *
+ */
+public class KXml2SAXParser extends KXmlParser {
+
+ public String uri="uri";
+
+ private Reader reader;
+
+ /**
+ * The constructor for a parser, it receives a java.io.Reader.
+ *
+ * @param reader The reader
+ * @throws XmlPullParserException
+ */
+ public KXml2SAXParser(Reader reader) throws XmlPullParserException {
+ super();
+ this.reader=reader;
+ setInput(reader);
+ }
+
+ /**
+ * Parser from the reader provided in the constructor, and call
+ * the startElement and endElement in a KxmlHandler
+ *
+ * @param reader The reader
+ * @exception Exception thrown by the superclass
+ */
+ public void parseXML(KXml2SAXHandler handler) throws Exception {
+
+ while (next() != XmlPullParser.END_DOCUMENT) {
+ handler.setLineNumber(getLineNumber());
+ handler.setColumnNumber(getColumnNumber());
+ if (getEventType() == XmlPullParser.START_TAG) {
+ Properties props = new Properties();
+ for (int i = 0; i < getAttributeCount(); i++) {
+ props.put(getAttributeName(i), getAttributeValue(i));
+ }
+ handler.startElement(
+ getNamespace(),
+ getName(),
+ getName(),
+ props);
+ } else if (getEventType() == XmlPullParser.END_TAG) {
+ handler.endElement(getNamespace(), getName(), getName());
+ } else if (getEventType() == XmlPullParser.TEXT) {
+ String text = getText();
+ handler.characters(text.toCharArray(),0,text.length());
+ } else if (getEventType() == XmlPullParser.PROCESSING_INSTRUCTION) {
+ // TODO extract the target from the evt.getText()
+ handler.processingInstruction(null,getText());
+ } else {
+ // do nothing
+ }
+ }
+ }
+}
Added: sandbox/tonit/techne.farrt/src/techne/farrt/parser/ParseException.java
===================================================================
--- sandbox/tonit/techne.farrt/src/techne/farrt/parser/ParseException.java (rev 0)
+++ sandbox/tonit/techne.farrt/src/techne/farrt/parser/ParseException.java 2007-01-29 22:09:59 UTC (rev 9)
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package techne.farrt.parser;
+
+public class ParseException extends Exception
+{
+ Exception m_originalException;
+
+ public ParseException(String msg, Exception originalException) {
+ super(msg);
+ m_originalException = originalException;
+ }
+
+ public Exception getException() {
+ return m_originalException;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|