org.exist
Class Parser

java.lang.Object
  extended byjava.util.Observable
      extended byorg.exist.Parser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler

public class Parser
extends java.util.Observable
implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.ErrorHandler, org.xml.sax.EntityResolver

Parser parses a given input document via SAX and stores it to the database. It automatically handles index-creation.

Author:
wolf

Field Summary
protected  DBBroker broker
           
protected  XMLString charBuf
           
 Collection collection
           
protected  int currentLine
           
protected  java.lang.StringBuffer currentPath
           
protected  DocumentImpl document
           
protected  java.lang.String fileName
           
protected  java.lang.String ignorePrefix
           
protected  boolean insideDTD
           
protected  int level
           
protected  org.xml.sax.Locator locator
           
protected  int normalize
           
protected  org.xml.sax.XMLReader parser
           
protected  java.util.Stack prefixes
           
protected  boolean privileged
           
protected  ProgressIndicator progress
           
protected  boolean replace
           
protected  org.apache.xml.resolver.tools.CatalogResolver resolver
           
protected  org.w3c.dom.Element rootNode
           
static int SPARSE_IDENTIFIERS
           
protected  java.util.Stack stack
           
protected  User user
           
protected  boolean validate
           
 
Constructor Summary
Parser(DBBroker broker, User user, boolean replace)
          Create a new parser using the given database broker and user to store the document.
Parser(DBBroker broker, User user, boolean replace, boolean priv)
          Create a new parser using the given database broker and user to store the document.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
           
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(java.lang.String namespace, java.lang.String name, java.lang.String qname)
           
 void endEntity(java.lang.String name)
           
 void endPrefixMapping(java.lang.String prefix)
           
 void error(org.xml.sax.SAXParseException e)
           
 void fatalError(org.xml.sax.SAXParseException e)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 DocumentImpl parse(byte[] data, java.lang.String xmlFileName)
           
 DocumentImpl parse(Collection coll, byte[] data, java.lang.String xmlFileName)
           
 DocumentImpl parse(Collection collection, java.io.File file, java.lang.String xmlFileName)
          Parse and store a document, using the given file and collection.
 DocumentImpl parse(Collection coll, org.xml.sax.InputSource is, java.lang.String fileName)
          Parse and store a document using the given input source and collection.
 DocumentImpl parse(Collection coll, org.w3c.dom.Node node, java.lang.String xmlFileName)
           
 DocumentImpl parse(Collection coll, java.lang.String str, java.lang.String xmlFileName)
          Parse and store a document from the given string and collection.
 DocumentImpl parse(java.io.File file, java.lang.String xmlFileName)
          Parse and store a document using the given file.
 DocumentImpl parse(org.xml.sax.InputSource src)
          Parse and store a document using the given input source.
 DocumentImpl parse(java.lang.String str, java.lang.String xmlFileName)
          Parse and store a document from the given string.
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Try to resolve external entities.
 void scan(org.xml.sax.InputSource src)
          Prepare for storing the document.
 void scan(org.xml.sax.InputSource src, java.lang.String xmlFileName)
          Prepare for storing the document.
 void scan(java.io.InputStream inStream, java.lang.String xmlFileName)
          Prepare for storing the document.
 void scan(org.w3c.dom.Node node, java.lang.String xmlFileName)
          Prepare for storing the document.
 void setBroker(DBBroker broker)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void setOverwrite(boolean overwrite)
           
 void setUser(User user)
           
 void skippedEntity(java.lang.String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 void startElement(java.lang.String namespace, java.lang.String name, java.lang.String qname, org.xml.sax.Attributes attributes)
           
 void startEntity(java.lang.String name)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 DocumentImpl store(org.xml.sax.InputSource src)
          Actually store the document to the database.
 DocumentImpl store(org.w3c.dom.Node node)
          Actually store the document to the database.
 void warning(org.xml.sax.SAXParseException e)
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPARSE_IDENTIFIERS

public static final int SPARSE_IDENTIFIERS
See Also:
Constant Field Values

collection

public Collection collection

broker

protected DBBroker broker

charBuf

protected XMLString charBuf

currentLine

protected int currentLine

currentPath

protected java.lang.StringBuffer currentPath

document

protected DocumentImpl document

fileName

protected java.lang.String fileName

insideDTD

protected boolean insideDTD

validate

protected boolean validate

level

protected int level

locator

protected org.xml.sax.Locator locator

normalize

protected int normalize

parser

protected org.xml.sax.XMLReader parser

prefixes

protected java.util.Stack prefixes

progress

protected ProgressIndicator progress

replace

protected boolean replace

resolver

protected org.apache.xml.resolver.tools.CatalogResolver resolver

rootNode

protected org.w3c.dom.Element rootNode

stack

protected java.util.Stack stack

user

protected User user

privileged

protected boolean privileged

ignorePrefix

protected java.lang.String ignorePrefix
Constructor Detail

Parser

public Parser(DBBroker broker,
              User user,
              boolean replace)
       throws EXistException
Create a new parser using the given database broker and user to store the document.

Parameters:
broker -
user - user identity
replace - replace existing documents?
Throws:
EXistException

Parser

public Parser(DBBroker broker,
              User user,
              boolean replace,
              boolean priv)
       throws EXistException
Create a new parser using the given database broker and user to store the document.

Parameters:
broker -
user - user identity
replace - replace existing documents?
Throws:
EXistException
Method Detail

setBroker

public void setBroker(DBBroker broker)

setOverwrite

public void setOverwrite(boolean overwrite)

setUser

public void setUser(User user)

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface org.xml.sax.ContentHandler

comment

public void comment(char[] ch,
                    int start,
                    int length)
Specified by:
comment in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

endDocument

public void endDocument()
Specified by:
endDocument in interface org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String namespace,
                       java.lang.String name,
                       java.lang.String qname)
Specified by:
endElement in interface org.xml.sax.ContentHandler

endEntity

public void endEntity(java.lang.String name)
Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler

parse

public DocumentImpl parse(org.xml.sax.InputSource src)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document using the given input source.

Parameters:
src -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(Collection coll,
                          org.xml.sax.InputSource is,
                          java.lang.String fileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document using the given input source and collection.

Parameters:
coll -
is -
fileName -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(java.io.File file,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document using the given file.

Parameters:
file -
xmlFileName -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(Collection collection,
                          java.io.File file,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document, using the given file and collection.

Parameters:
collection -
file -
xmlFileName -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(java.lang.String str,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document from the given string.

Parameters:
str -
xmlFileName -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(Collection coll,
                          java.lang.String str,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Parse and store a document from the given string and collection.

Parameters:
coll -
str -
xmlFileName -
Returns:
DocumentImpl
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(byte[] data,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(Collection coll,
                          byte[] data,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

parse

public DocumentImpl parse(Collection coll,
                          org.w3c.dom.Node node,
                          java.lang.String xmlFileName)
                   throws org.xml.sax.SAXException,
                          java.io.IOException,
                          PermissionDeniedException
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler

scan

public void scan(java.io.InputStream inStream,
                 java.lang.String xmlFileName)
          throws org.xml.sax.SAXException,
                 java.io.IOException,
                 PermissionDeniedException
Prepare for storing the document. The document is parsed for validation. If a document with the same name exists and updates are allowed, the old document is removed.

Parameters:
inStream - InputStream
xmlFileName - the name of the document
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

scan

public void scan(org.xml.sax.InputSource src)
          throws org.xml.sax.SAXException,
                 java.io.IOException,
                 PermissionDeniedException
Prepare for storing the document. The document is parsed for validation. If a document with the same name exists and updates are allowed, the old document is removed. The name of the document is determined from the InputSource.

Parameters:
src - Description of the Parameter
Throws:
org.xml.sax.SAXException - Description of the Exception
java.io.IOException - Description of the Exception
PermissionDeniedException - Description of the Exception

scan

public void scan(org.xml.sax.InputSource src,
                 java.lang.String xmlFileName)
          throws org.xml.sax.SAXException,
                 java.io.IOException,
                 PermissionDeniedException
Prepare for storing the document. The document is parsed for validation. If a document with the same name exists and updates are allowed, the old document is removed.

Parameters:
src - InputSource
xmlFileName - name of the document
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

scan

public void scan(org.w3c.dom.Node node,
                 java.lang.String xmlFileName)
          throws org.xml.sax.SAXException,
                 java.io.IOException,
                 PermissionDeniedException
Prepare for storing the document. The document is parsed for validation. If a document with the same name exists and updates are allowed, the old document is removed.

Parameters:
xmlFileName - name of the document
Throws:
org.xml.sax.SAXException
java.io.IOException
PermissionDeniedException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

skippedEntity

public void skippedEntity(java.lang.String name)
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler

startCDATA

public void startCDATA()
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler

startDocument

public void startDocument()
Specified by:
startDocument in interface org.xml.sax.ContentHandler

startElement

public void startElement(java.lang.String namespace,
                         java.lang.String name,
                         java.lang.String qname,
                         org.xml.sax.Attributes attributes)
Specified by:
startElement in interface org.xml.sax.ContentHandler

startEntity

public void startEntity(java.lang.String name)
Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler

store

public DocumentImpl store(org.xml.sax.InputSource src)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
Actually store the document to the database. scan() should have been called before.

Returns:
Description of the Return Value
Throws:
org.xml.sax.SAXException - Description of the Exception
java.io.IOException - Description of the Exception

store

public DocumentImpl store(org.w3c.dom.Node node)
                   throws org.xml.sax.SAXException,
                          java.io.IOException
Actually store the document to the database. scan() should have been called before.

Returns:
Description of the Return Value
Throws:
org.xml.sax.SAXException - Description of the Exception
java.io.IOException - Description of the Exception

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Specified by:
warning in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException
Try to resolve external entities. This method forwards the request to the resolver. If that fails, the method replaces absolute file names with relative ones and retries to resolve. This makes it possible to use relative file names in the catalog.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Throws:
org.xml.sax.SAXException
java.io.IOException
See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)


Copyright (C) Wolfgang Meier. All rights reserved.