Commit e3e434fd authored by SAINT-MARCEL Frederic's avatar SAINT-MARCEL Frederic
Browse files

add ParserRDF

parent 06a6b0db
/*
* Created by IntelliJ IDEA.
* User: administrateur
* Date: 22 mai 2002
* Time: 15:49:04
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package fr.fluxmedia.flowcomposer;
// Imported SAX Classes
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException ;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.XMLFilterImpl;
//Imported JAVA Classes
import java.util.*;
import java.io.*;
import java.util.Stack ;
public class ParserRDF extends DefaultHandler {
/** The XML Parser class */
private static final String
DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
private static final int DEFAULT=0;
private static final int COLOR=1;
private static final int X=2;
private static final int Y=3;
private int mode = DEFAULT;
public Vector process = new Vector();
/** XML Parser */
javax.xml.parsers.SAXParser iParser = null;
/*------------------------------------------ CONSTRUCTOR -----------------------------*/
/** The constructor, build the XML Parser but not parse the document */
public ParserRDF() {
try {
javax.xml.parsers.SAXParserFactory iParserFactory = javax.xml.parsers.SAXParserFactory.newInstance();
iParserFactory.setValidating(false); // no DTD for RDF and annotations so far
iParserFactory.setNamespaceAware(true);
iParser = iParserFactory.newSAXParser();
} catch (javax.xml.parsers.ParserConfigurationException CNFE) {
System.out.println("FMParser :Error [" + CNFE +"]");
} catch (org.xml.sax.SAXException SaxE) {
System.out.println("FMParser :Error [" + SaxE +"]");
}
}
/*------------------------------------------- END CONSTRUCTOR ------------------------*/
/** Parse the document given in parameter */
public void newParse(String uri) {
try {
iParser.parse(uri,this);
} catch (SAXException SE) {
System.err.println("[FMParser]Erreur SAX(" + SE+")");
System.err.println("[FMParser]Erreur SAX(" + SE.getMessage()+")");
System.err.println("[FMParser]Erreur SAX(" + SE.getException()+")");
SE.printStackTrace();
} catch (java.io.IOException IOE) {
System.err.println("[FMParser]Erreur IO(" + IOE+")");
}
}
/** Call by the XML parser at the begining of an element */
public final void startElement(String namespaceURI, String localName, String qname, Attributes atts) {
if (namespaceURI.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns")) {
//System.out.println(localName);
if (localName.equals("Description")) {
mode = DEFAULT;
process.add(atts.getValue("about"));
}
}
else if (localName.equals("color"))
{mode = COLOR;}
else if (localName.equals("x"))
{mode = X;}
else if (localName.equals("y"))
{mode = Y;}
}
/** Call by the XML parser at the end of an element */
public final void endElement(String namespaceURI,String pName, String qName ) {
if ((pName.equals("color"))||(pName.equals("x"))||(pName.equals("y")))
{mode = DEFAULT;}
}
/* The content of the tags */
/* No content in Transmorpher so far but in XSLT code */
public void characters(char ch[], int start, int length) {
String content = "";
int end = start + length;
//System.out.println(mode);
for( int i = start; i < end ; i++ ) {content = content + ch[i];}
if (mode==COLOR)
process.add(content);
else if (mode==X)
process.add(content);
else if (mode==Y)
process.add(content);
}
public void print() {
for (Enumeration e = process.elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
}
public void warning(SAXParseException exception)
throws SAXException
{
System.err.println("warning");
}
public void error(SAXParseException ex)
{
System.err.print("Error!! ");
System.err.println(ex);
System.err.println(ex.getLineNumber());
}
public void fatalError(SAXParseException ex) throws SAXException
{
System.err.print("Fatal Error!! ");
System.err.println(ex);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment