Alignment API and Server 4.1.${version.update}

fr.inrialpes.exmo.align.parser
Class XMLParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by fr.inrialpes.exmo.align.parser.XMLParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class XMLParser
extends DefaultHandler

This class allows the creation of a parser for an Alignment file. The class is called by: AlignmentParser parser = new AlignmentParser( debugLevel ); Alignment alignment = parser.parse( input ); input can be a URI as a String, an InputStream This new version (January 2004) parses the alignment description in RDF/XML/OWL format


Field Summary
protected  int alignLevel
          The level at which we found the Alignment tag.
protected  Alignment alignment
          the alignment that is parsed We always create a URIAlignment (we could also use a BasicAlignment).
protected  Cell cell
          the relation content as text...
protected  Object cl1
          the first entity of a cell
protected  Object cl2
          the second entity of a cell
protected  String content
          the content found as text...
(package private)  Ontology curronto
           
protected  int debugMode
          level of debug/warning information
protected  boolean embedded
          The parsing level, if equal to 3 we are in the Alignment if equal to 5 we are in a cell and can find metadata
protected  Extensions extensions
          Cell extensions (default null)
protected  String id
          the cell id as text...
protected  String measure
          the measure content as text...
(package private)  Ontology onto1
          the first Ontology
(package private)  Ontology onto2
          the second Ontology
protected  int parseLevel
          The parsing level, if equal to 3 we are in the Alignment if equal to 5 we are in a cell and can find metadata
protected  SAXParser parser
          XML Parser
protected  String relation
          the relation content as text...
protected  String sem
          the semantics of the cell (default first-order)...
protected  String uri
          a URI to a process
 
Constructor Summary
XMLParser()
          Creates an XML Parser.
XMLParser(int debugMode)
          Creates an XML Parser.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Put the content in a variable
 void endElement(String namespaceURI, String pName, String qName)
          Called by the XML parser at the end of an element.
private  Object getEntity(Object ontology, String name)
           
 void initAlignment(URIAlignment al)
          Allows to have the parser filling an existing alignment instead of creating a new one
 Alignment parse(InputStream s)
          Parses a string instead of a URI
 Alignment parse(Reader r)
          Parses a reader, used for reading from a string
 Alignment parse(String uri)
          Parses the document corresponding to the URI given in parameter If the current process has links (import or include) to others documents then they are parsed.
 void setEmbedded(boolean b)
           
 void startElement(String namespaceURI, String pName, String qname, Attributes atts)
          Called by the XML parser at the begining of an element.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugMode

protected int debugMode
level of debug/warning information


uri

protected String uri
a URI to a process


onto1

Ontology onto1
the first Ontology


curronto

Ontology curronto

onto2

Ontology onto2
the second Ontology


alignment

protected Alignment alignment
the alignment that is parsed We always create a URIAlignment (we could also use a BasicAlignment). This is a pitty but the idea of creating a particular alignment is not in accordance with using an interface.


content

protected String content
the content found as text...


cl1

protected Object cl1
the first entity of a cell


cl2

protected Object cl2
the second entity of a cell


cell

protected Cell cell
the relation content as text...


relation

protected String relation
the relation content as text...


id

protected String id
the cell id as text...


sem

protected String sem
the semantics of the cell (default first-order)...


extensions

protected Extensions extensions
Cell extensions (default null)


measure

protected String measure
the measure content as text...


parser

protected SAXParser parser
XML Parser


parseLevel

protected int parseLevel
The parsing level, if equal to 3 we are in the Alignment if equal to 5 we are in a cell and can find metadata


embedded

protected boolean embedded
The parsing level, if equal to 3 we are in the Alignment if equal to 5 we are in a cell and can find metadata


alignLevel

protected int alignLevel
The level at which we found the Alignment tag. It is -1 outside the alignment.

Constructor Detail

XMLParser

public XMLParser()
          throws ParserConfigurationException,
                 SAXException
Creates an XML Parser.

Throws:
ParserConfigurationException
SAXException

XMLParser

public XMLParser(int debugMode)
          throws ParserConfigurationException,
                 SAXException
Creates an XML Parser.

Parameters:
debugMode - The value of the debug mode
Throws:
ParserConfigurationException
SAXException
Method Detail

setEmbedded

public void setEmbedded(boolean b)

parse

public Alignment parse(String uri)
                throws AlignmentException
Parses the document corresponding to the URI given in parameter If the current process has links (import or include) to others documents then they are parsed.

Parameters:
uri - URI of the document to parse
Throws:
AlignmentException

parse

public Alignment parse(Reader r)
                throws AlignmentException
Parses a reader, used for reading from a string

Parameters:
r - the reader from which to parse
Throws:
AlignmentException

parse

public Alignment parse(InputStream s)
                throws AlignmentException
Parses a string instead of a URI

Parameters:
s - String the string to parse
Throws:
AlignmentException

initAlignment

public void initAlignment(URIAlignment al)
Allows to have the parser filling an existing alignment instead of creating a new one

Parameters:
al - URIAlignment the alignment to be returned by the parser Note that this function is also useful for reseting the parser and using it once again by parser.initAlignment( null ) Otherwise, this may lead to errors.

startElement

public void startElement(String namespaceURI,
                         String pName,
                         String qname,
                         Attributes atts)
                  throws SAXException
Called by the XML parser at the begining of an element. The corresponing graph component is create for each element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Parameters:
namespaceURI - The namespace of the current element
pName - The local name of the current element
qname - The name of the current element
atts - The attributes name of the current element
Throws:
SAXException

getEntity

private Object getEntity(Object ontology,
                         String name)
                  throws SAXException
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
Put the content in a variable

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler

endElement

public void endElement(String namespaceURI,
                       String pName,
                       String qName)
                throws SAXException
Called by the XML parser at the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Parameters:
namespaceURI - The namespace of the current element
pName - The local name of the current element
qName - The name of the current element
Throws:
SAXException

Alignment API and Server 4.1.${version.update}

(C) INRIA & friends, 2003-${curryear}