org.bibop.xml.xforge
Class XForgeProcessor

java.lang.Object
  |
  +--org.bibop.xml.AbstractSAXProcessor
        |
        +--org.bibop.xml.xforge.XForgeProcessor
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configurable, org.xml.sax.ContentHandler, DOMProcessor, org.xml.sax.ext.LexicalHandler, org.apache.avalon.framework.logger.LogEnabled, PrefixesMonitor, Processor, SAXProcessor, XMLConsumer, XMLProducer
Direct Known Subclasses:
XForgeC1Processor, XForgeC2Transformer

public class XForgeProcessor
extends AbstractSAXProcessor
implements DOMProcessor, org.apache.avalon.framework.configuration.Configurable, PrefixesMonitor, org.apache.avalon.framework.logger.LogEnabled

The main entry point for the x:forge framework. The class is responsible for receiving XML SAX events, delegate x:forge related events to the appropriate x:forge components and pass through unchanged the remaining SAX events. In a typical SAX environment usually an application invokes a parser setting itself as the ContentHandler. In a x:forge enviroment the XForgeprocessor should be set as the ContentHandler of the parser and the application should be set as the XForgeProcessor ContentHandler. As an example:

 XForgeProcessor xfp = new XForgeProcessor();
 xfp.configure(Configuration conf);
 parser.setContentHandler(xfp);
 xfp.setContenHandler(this);
 parser.parse();
 

Version:
1.0
Author:
Alberto Garoffolo

Field Summary
private  java.util.List activePrefixes
           
private  org.apache.avalon.excalibur.component.ExcaliburComponentManager componentManager
           
static java.lang.String DEFAULT_ENCODING
           
protected  java.lang.Boolean lastifresult
           
protected  org.apache.avalon.framework.logger.Logger log
           
private  ProcessingOptions po
           
static java.lang.String XFORGE_CONTEXTS_XMLNS_URI
          XForge declaration contexts namespace
static java.lang.String XFORGE_DEFAULT_CONTEXT_CLASS
          The XForge default context identifier
static java.lang.Class XFORGE_DEFAULT_VARIABLES_CONTEXT
          The XForge default context identifier
static java.lang.String XFORGE_NAME
          Deprecated.  
static java.lang.String XFORGE_XMLNS_AUTOMATION_URI
          The XForge components namespace
static java.lang.String XFORGE_XMLNS_URI
          The XForge namespace
private  ElementsStack xForgeStack
           
 
Fields inherited from class org.bibop.xml.AbstractSAXProcessor
contentHandler, lexicalHandler
 
Constructor Summary
XForgeProcessor()
           
 
Method Summary
 void characters(char[] ch, int start, int len)
          Receive notification of character data.
private  void clearStatus()
           
 void comment(char[] ch, int start, int len)
          Report an XML comment anywhere in the document.
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
          Configures the application based on a Avalon Configuration object.
protected  void debug(java.lang.String str)
           
 void enableLogging(org.apache.avalon.framework.logger.Logger logger)
          Provide component with a logger.
 void endCDATA()
          Report the end of a CDATA section.
 void endDocument()
          Receive notification of the end of a document.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(java.lang.String uri, java.lang.String loc, java.lang.String raw)
          Receive notification of the end of an element.
 void endEntity(java.lang.String name)
          Report the end of an entity.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI mapping.
 java.util.List getActivePrefixes()
          Keep track of namespaces added by previous elements.
private  org.xml.sax.ContentHandler getCurrentContentHandler()
           
private  org.xml.sax.ext.LexicalHandler getCurrentLexicalHandler()
           
private  PrefixesMonitor getCurrentPrefixesMonitor()
           
static java.lang.Object getVariableValue(PrefixesMonitor prefixes, java.lang.String name)
           
static java.lang.Object getVariableValue(java.lang.String name)
           
 void ignorableWhitespace(char[] ch, int start, int len)
          Receive notification of ignorable whitespace in element content.
private  boolean isInNamespace(java.lang.String ns)
           
 org.w3c.dom.Document process(org.w3c.dom.Document document)
          Allows using DOM structures in the x:forge framework.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
protected  void resetIf()
           
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive an object for locating the origin of SAX document events.
 void setParentPrefixesMonitor(PrefixesMonitor parent)
          Sets the (previous) namespace prefixes monitor.
 void setProcessingOptions(ProcessingOptions aPO)
           
static void setVariableValue(PrefixesMonitor prefixes, java.lang.String name, java.lang.Object value)
           
static void setVariableValue(java.lang.String name, java.lang.Object value)
           
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDocument()
          Receive notification of the beginning of a document.
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report the start of DTD declarations, if any.
 void startElement(java.lang.String uri, java.lang.String loc, java.lang.String raw, org.xml.sax.Attributes a)
          Receive notification of the beginning of an element.
 void startEntity(java.lang.String name)
          Report the beginning of an entity.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 
Methods inherited from class org.bibop.xml.AbstractSAXProcessor
setConsumer, setContentHandler, setLexicalHandler, toSax
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

po

private ProcessingOptions po

log

protected org.apache.avalon.framework.logger.Logger log

lastifresult

protected java.lang.Boolean lastifresult

XFORGE_DEFAULT_CONTEXT_CLASS

public static final java.lang.String XFORGE_DEFAULT_CONTEXT_CLASS
The XForge default context identifier

See Also:
Constant Field Values

XFORGE_DEFAULT_VARIABLES_CONTEXT

public static final java.lang.Class XFORGE_DEFAULT_VARIABLES_CONTEXT
The XForge default context identifier


XFORGE_XMLNS_URI

public static final java.lang.String XFORGE_XMLNS_URI
The XForge namespace

See Also:
Constant Field Values

XFORGE_XMLNS_AUTOMATION_URI

public static final java.lang.String XFORGE_XMLNS_AUTOMATION_URI
The XForge components namespace

See Also:
Constant Field Values

XFORGE_CONTEXTS_XMLNS_URI

public static final java.lang.String XFORGE_CONTEXTS_XMLNS_URI
XForge declaration contexts namespace

See Also:
Constant Field Values

XFORGE_NAME

public static final java.lang.String XFORGE_NAME
Deprecated.  

The x:forge prefix declaration.

See Also:
Constant Field Values

componentManager

private org.apache.avalon.excalibur.component.ExcaliburComponentManager componentManager

xForgeStack

private ElementsStack xForgeStack

activePrefixes

private java.util.List activePrefixes

DEFAULT_ENCODING

public static java.lang.String DEFAULT_ENCODING
Constructor Detail

XForgeProcessor

public XForgeProcessor()
Method Detail

resetIf

protected void resetIf()

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Provide component with a logger.

Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled
Parameters:
logger - the logger

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configures the application based on a Avalon Configuration object. A typical XForge configuration would look like this:
   <?xml version="1.0"?>
   <xforge>
     <components>
       <component role="process">
         <component-instance name="HelloWorld"
           class="org.bibop.xml.xforge.component.examples.HelloWorldComponent" />
       </component>
     </components>
   </xforge>
 

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
conf - An Avalon Configuration Object
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - Exception due to misconfiguration

clearStatus

private void clearStatus()

setProcessingOptions

public void setProcessingOptions(ProcessingOptions aPO)

process

public org.w3c.dom.Document process(org.w3c.dom.Document document)
                             throws java.lang.Exception
Allows using DOM structures in the x:forge framework. This will allow x:forge to be used in DOM based environments such as Cocoon 1.

Specified by:
process in interface DOMProcessor
Parameters:
document - a Document object to be processed
Returns:
The processed document.
Throws:
java.lang.Exception - Fooooooooof fight

debug

protected void debug(java.lang.String str)

getCurrentPrefixesMonitor

private PrefixesMonitor getCurrentPrefixesMonitor()

getVariableValue

public static java.lang.Object getVariableValue(java.lang.String name)
                                         throws ParserError,
                                                XForgeException
ParserError
XForgeException

getVariableValue

public static java.lang.Object getVariableValue(PrefixesMonitor prefixes,
                                                java.lang.String name)
                                         throws ParserError,
                                                XForgeException
ParserError
XForgeException

setVariableValue

public static void setVariableValue(java.lang.String name,
                                    java.lang.Object value)
                             throws ParserError,
                                    XForgeException
ParserError
XForgeException

setVariableValue

public static void setVariableValue(PrefixesMonitor prefixes,
                                    java.lang.String name,
                                    java.lang.Object value)
                             throws ParserError,
                                    XForgeException
ParserError
XForgeException

getCurrentContentHandler

private org.xml.sax.ContentHandler getCurrentContentHandler()

getCurrentLexicalHandler

private org.xml.sax.ext.LexicalHandler getCurrentLexicalHandler()

isInNamespace

private boolean isInNamespace(java.lang.String ns)

getActivePrefixes

public java.util.List getActivePrefixes()
                                 throws XForgeException
Keep track of namespaces added by previous elements.

Specified by:
getActivePrefixes in interface PrefixesMonitor
Returns:
A list of previously declared PrefixEntry objects
Throws:
XForgeException - In this particular context the Exception will never be thrown

setParentPrefixesMonitor

public void setParentPrefixesMonitor(PrefixesMonitor parent)
                              throws XForgeException
Sets the (previous) namespace prefixes monitor. Used to recursively retrieve the list of active prefixes.

Specified by:
setParentPrefixesMonitor in interface PrefixesMonitor
Parameters:
parent - the parent object implementing PrefixesMonitor interface.
Throws:
XForgeException - never thrown here

startElement

public void startElement(java.lang.String uri,
                         java.lang.String loc,
                         java.lang.String raw,
                         org.xml.sax.Attributes a)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class AbstractSAXProcessor
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
a - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String loc,
                       java.lang.String raw)
                throws org.xml.sax.SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class AbstractSAXProcessor
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
org.xml.sax.SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Receive an object for locating the origin of SAX document events.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class AbstractSAXProcessor
Parameters:
locator - An object that can return the location of any SAX document event.

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class AbstractSAXProcessor
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receive notification of the end of a document.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class AbstractSAXProcessor
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Begin the scope of a prefix-URI Namespace mapping.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class AbstractSAXProcessor
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
End the scope of a prefix-URI mapping.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
endPrefixMapping in class AbstractSAXProcessor
Parameters:
prefix - The prefix that was being mapping.
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int len)
                throws org.xml.sax.SAXException
Receive notification of character data.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class AbstractSAXProcessor
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int len)
                         throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Overrides:
ignorableWhitespace in class AbstractSAXProcessor
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Overrides:
processingInstruction in class AbstractSAXProcessor
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Receive notification of a skipped entity.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Overrides:
skippedEntity in class AbstractSAXProcessor
Parameters:
name - The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
org.xml.sax.SAXException

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws org.xml.sax.SAXException
Report the start of DTD declarations, if any.

Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler
Overrides:
startDTD in class AbstractSAXProcessor
Parameters:
name - The document type name.
publicId - The declared public identifier for the external DTD subset, or null if none was declared.
systemId - The declared system identifier for the external DTD subset, or null if none was declared.
org.xml.sax.SAXException

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Report the end of DTD declarations.

Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler
Overrides:
endDTD in class AbstractSAXProcessor
org.xml.sax.SAXException

startEntity

public void startEntity(java.lang.String name)
                 throws org.xml.sax.SAXException
Report the beginning of an entity.

Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler
Overrides:
startEntity in class AbstractSAXProcessor
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
org.xml.sax.SAXException

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Report the end of an entity.

Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler
Overrides:
endEntity in class AbstractSAXProcessor
Parameters:
name - The name of the entity that is ending.
org.xml.sax.SAXException

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Report the start of a CDATA section.

Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
startCDATA in class AbstractSAXProcessor
org.xml.sax.SAXException

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Report the end of a CDATA section.

Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
endCDATA in class AbstractSAXProcessor
org.xml.sax.SAXException

comment

public void comment(char[] ch,
                    int start,
                    int len)
             throws org.xml.sax.SAXException
Report an XML comment anywhere in the document.

Specified by:
comment in interface org.xml.sax.ext.LexicalHandler
Overrides:
comment in class AbstractSAXProcessor
Parameters:
ch - An array holding the characters in the comment.
start - The starting position in the array.
len - The number of characters to use from the array.
org.xml.sax.SAXException


Copyright 2003 Bibop Research International. All Rights Reserved.