com.oxygenxml.validate.nvdl
Class SchemaImpl.Handler

java.lang.Object
  extended by com.thaiopensource.xml.sax.DelegatingContentHandler
      extended by com.oxygenxml.validate.nvdl.SchemaImpl.Handler
All Implemented Interfaces:
SchemaFuture, ContentHandler
Enclosing class:
SchemaImpl

private class SchemaImpl.Handler
extends DelegatingContentHandler
implements SchemaFuture

This class is registered as content handler on the XMLReader that parses the NVDL script. It creates the Schema representation for this script and also validates the script against the NVDL schema.


Nested Class Summary
(package private)  class SchemaImpl.Handler.ModeData
           
 
Field Summary
private  CountingErrorHandler ceh
          A counting error handler that wraps the error handler.
private  String defaultSchemaType
          The value of rules/@schemaType
private  ErrorHandler eh
          The error handler.
private  int foreignDepth
          For ignoring foreign elements.
private  boolean hadError
          Flag indicating that we encountered an error.
private  Localizer localizer
          Convert error keys to messages.
private  Locator locator
          Error locator.
(package private)  SchemaImpl.Handler.ModeData md
          Stores mode data.
private  Stack modeDataStack
          Keeps the elements from mode data stack.
private  Stack nvdlStack
          Keeps the elements from NVDL representing the current context.
private  SchemaReceiverImpl sr
          The schema receiver.
private  Validator validator
          The validator that checks the script against the NVDL RelaxNG schema.
private  XmlBaseHandler xmlBaseHandler
          Handle xml:base attributes.
 
Constructor Summary
SchemaImpl.Handler(SchemaReceiverImpl sr)
          Creates a handler.
 
Method Summary
private  Schema createSubSchema(boolean isAttributesSchema)
          Creates a sub schema for the ending validate action (this is called from finishValidate).
 void endElement(String namespaceURI, String localName, String qName)
          End element callback.
(package private)  void error(String key)
          Report a no arguments error from a key.
(package private)  void error(String key, String arg)
          Report an one argument error.
(package private)  void error(String key, String arg, Locator locator)
          Report an one argument error with location.
(package private)  void error(String key, String arg1, String arg2)
          Report a two arguments error.
private  void finishIncludedMode()
          Notification that the mode element ends.
private  void finishMode()
          Notification that the mode element ends.
private  void finishNestedMode()
          Notification that the mode element ends.
private  void finishValidate()
          Notification that the validate element ends.
private  ModeUsage getModeUsage(Attributes attributes)
          Creates a mode usage that matches current mode and uses further the mode specified by the useMode attribute.
private  String getNs(Attributes attributes)
          Get the namespace from the ns attribute.
 Schema getSchema()
           
private  String getSchema(Attributes attributes)
          Get the URI specified by a schema attribute and if we have a relative location resolve that against the base URI taking into account also eventual xml:base attributes.
private  String getSchemaType(Attributes attributes)
          Get the schema type
private  Mode getUseMode(Attributes attributes)
          Get the Mode for the useMode attribute.
private  void parseAllow(Attributes attributes)
          Parse an allow action.
private  void parseAnyNamespace(Attributes attributes)
          Parse an anyNamespace rule.
private  void parseAttach(Attributes attributes)
          Parse an attach action.
private  void parseAttachPlaceholder(Attributes attributes)
          Parse an attachPlaceholder action.
private  void parseCancelNestedActions(Attributes attributes)
          Parse a cancel nested actions action.
private  void parseContext(Attributes attributes)
          Parse context dependent mode usages.
private  void parseIncludedMode(Attributes attributes)
          Parse a mode element.
private  void parseMode(Attributes attributes)
          Parse a mode element.
private  void parseNamespace(Attributes attributes)
          Parse a namespace rule.
private  void parseNestedMode(Attributes attributes)
          Parse a mode element.
private  void parseOption(Attributes attributes)
          Parse a validate option.
private  void parseReject(Attributes attributes)
          Parse a reject action.
private  void parseRule(String ns, Attributes attributes)
          Parse namespace and anyNamespace rules/
private  void parseRules(Attributes attributes)
          Parse the rules element.
private  void parseTrigger(Attributes attributes)
          Parse a trigger element.
private  void parseUnwrap(Attributes attributes)
          Parse an unwrap action.
private  void parseValidate(Attributes attributes)
          Parse a validate action.
 void setDocumentLocator(Locator locator)
          Callback with the document locator.
 void startDocument()
          On start document.
 void startElement(String uri, String localName, String qName, Attributes attributes)
          Start element callback.
private  ElementsOrAttributes toElementsOrAttributes(String value, ElementsOrAttributes defaultValue)
          Get an ElementsOrAttributes instance depending on the match attribute value.
 RuntimeException unwrapException(RuntimeException e)
           
 
Methods inherited from class com.thaiopensource.xml.sax.DelegatingContentHandler
characters, endDocument, endPrefixMapping, getDelegate, ignorableWhitespace, processingInstruction, setDelegate, skippedEntity, startPrefixMapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sr

private final SchemaReceiverImpl sr
The schema receiver. Used to cretae other schemas and access options.


hadError

private boolean hadError
Flag indicating that we encountered an error.


eh

private final ErrorHandler eh
The error handler.


ceh

private final CountingErrorHandler ceh
A counting error handler that wraps the error handler. It is useful to stop early if we encounter errors.


localizer

private final Localizer localizer
Convert error keys to messages.


locator

private Locator locator
Error locator.


xmlBaseHandler

private final XmlBaseHandler xmlBaseHandler
Handle xml:base attributes.


foreignDepth

private int foreignDepth
For ignoring foreign elements.


defaultSchemaType

private String defaultSchemaType
The value of rules/@schemaType


validator

private Validator validator
The validator that checks the script against the NVDL RelaxNG schema.


md

SchemaImpl.Handler.ModeData md
Stores mode data.


modeDataStack

private Stack modeDataStack
Keeps the elements from mode data stack.


nvdlStack

private Stack nvdlStack
Keeps the elements from NVDL representing the current context.

Constructor Detail

SchemaImpl.Handler

SchemaImpl.Handler(SchemaReceiverImpl sr)
Creates a handler.

Parameters:
sr - The Schema Receiver implementation for NVDL schemas.
Method Detail

setDocumentLocator

public void setDocumentLocator(Locator locator)
Callback with the document locator.

Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DelegatingContentHandler
Parameters:
locator - The document locator.

startDocument

public void startDocument()
                   throws SAXException
On start document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DelegatingContentHandler
Throws:
SAXException

getSchema

public Schema getSchema()
                 throws IncorrectSchemaException,
                        SAXException
Specified by:
getSchema in interface SchemaFuture
Throws:
IncorrectSchemaException
SAXException

unwrapException

public RuntimeException unwrapException(RuntimeException e)
                                 throws SAXException,
                                        IOException,
                                        IncorrectSchemaException
Specified by:
unwrapException in interface SchemaFuture
Throws:
SAXException
IOException
IncorrectSchemaException

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException
Start element callback.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DelegatingContentHandler
Parameters:
uri - The namespace uri for this element.
localName - The element local name.
qName - The element qualified name.
attributes - The attributes of this element.
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
End element callback.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DelegatingContentHandler
Parameters:
namespaceURI - The namespace uri for this element.
localName - The element local name.
qName - The element qualified name.
Throws:
SAXException

parseRules

private void parseRules(Attributes attributes)
Parse the rules element. Initializes the start mode the current mode the defaultSchemaType

Parameters:
attributes - The rule element attributes.

parseMode

private void parseMode(Attributes attributes)
                throws SAXException
Parse a mode element.

Parameters:
attributes - The element attributes.
Throws:
SAXException

parseIncludedMode

private void parseIncludedMode(Attributes attributes)
                        throws SAXException
Parse a mode element.

Parameters:
attributes - The element attributes.
Throws:
SAXException

parseNestedMode

private void parseNestedMode(Attributes attributes)
                      throws SAXException
Parse a mode element.

Parameters:
attributes - The element attributes.
Throws:
SAXException

parseNamespace

private void parseNamespace(Attributes attributes)
                     throws SAXException
Parse a namespace rule.

Parameters:
attributes - The namespace element attributes.
Throws:
SAXException

parseAnyNamespace

private void parseAnyNamespace(Attributes attributes)
                        throws SAXException
Parse an anyNamespace rule.

Parameters:
attributes - The anyNamespace element attributes.
Throws:
SAXException

parseRule

private void parseRule(String ns,
                       Attributes attributes)
                throws SAXException
Parse namespace and anyNamespace rules/

Parameters:
ns - The namespace, ##any for anyNamespace
attributes - The rule attributes.
Throws:
SAXException

parseValidate

private void parseValidate(Attributes attributes)
                    throws SAXException
Parse a validate action.

Parameters:
attributes - The validate element attributes.
Throws:
SAXException

finishValidate

private void finishValidate()
                     throws SAXException
Notification that the validate element ends.

Throws:
SAXException

finishMode

private void finishMode()
                 throws SAXException
Notification that the mode element ends.

Throws:
SAXException

finishIncludedMode

private void finishIncludedMode()
                         throws SAXException
Notification that the mode element ends.

Throws:
SAXException

finishNestedMode

private void finishNestedMode()
                       throws SAXException
Notification that the mode element ends.

Throws:
SAXException

createSubSchema

private Schema createSubSchema(boolean isAttributesSchema)
                        throws IOException,
                               IncorrectSchemaException,
                               SAXException
Creates a sub schema for the ending validate action (this is called from finishValidate).

Parameters:
isAttributesSchema - If the schema is intended to validate only attributes.
Returns:
A Schema.
Throws:
IOException
IncorrectSchemaException
SAXException

parseOption

private void parseOption(Attributes attributes)
                  throws SAXException
Parse a validate option.

Parameters:
attributes - The option element attributes.
Throws:
SAXException

parseTrigger

private void parseTrigger(Attributes attributes)
                   throws SAXException
Parse a trigger element.

Parameters:
attributes - The trigger element attributes.
Throws:
SAXException

parseAttach

private void parseAttach(Attributes attributes)
Parse an attach action.

Parameters:
attributes - The attach element attributes.

parseUnwrap

private void parseUnwrap(Attributes attributes)
Parse an unwrap action.

Parameters:
attributes - The unwrap element attributes.

parseAttachPlaceholder

private void parseAttachPlaceholder(Attributes attributes)
Parse an attachPlaceholder action.

Parameters:
attributes - The attachPlaceholder element attributes.

parseAllow

private void parseAllow(Attributes attributes)
Parse an allow action.

Parameters:
attributes - The allow element attributes.

parseReject

private void parseReject(Attributes attributes)
Parse a reject action.

Parameters:
attributes - The reject element attributes.

parseCancelNestedActions

private void parseCancelNestedActions(Attributes attributes)
Parse a cancel nested actions action.

Parameters:
attributes - The cancelNestedActions element attributes.

parseContext

private void parseContext(Attributes attributes)
                   throws SAXException
Parse context dependent mode usages.

Parameters:
attributes - The context element attributes.
Throws:
SAXException

getSchema

private String getSchema(Attributes attributes)
                  throws SAXException
Get the URI specified by a schema attribute and if we have a relative location resolve that against the base URI taking into account also eventual xml:base attributes.

Parameters:
attributes - The validate element attributes.
Returns:
A resolved URI as string.
Throws:
SAXException - If the schema contains a fragment id.

getSchemaType

private String getSchemaType(Attributes attributes)
Get the schema type

Parameters:
attributes - The attributes
Returns:
The value of the schemaType attribute.

toElementsOrAttributes

private ElementsOrAttributes toElementsOrAttributes(String value,
                                                    ElementsOrAttributes defaultValue)
Get an ElementsOrAttributes instance depending on the match attribute value.

Parameters:
value - The match attribute value.
defaultValue - The default value if value is null.
Returns:
an ElementsOrAttributes constant.

getModeUsage

private ModeUsage getModeUsage(Attributes attributes)
Creates a mode usage that matches current mode and uses further the mode specified by the useMode attribute.

Parameters:
attributes - The action element attributes.
Returns:
A mode usage from currentMode to the mode specified by the useMode attribute.

getUseMode

private Mode getUseMode(Attributes attributes)
Get the Mode for the useMode attribute.

Parameters:
attributes - the attributes
Returns:
the mode with the useMode name or the special Mode.CURRENT mode that will be resolved to the current mode in a Mode usage.

getNs

private String getNs(Attributes attributes)
              throws SAXException
Get the namespace from the ns attribute. Also check that the namespace is an absolute URI and report an error otherwise.

Parameters:
attributes - The list of attributes of the namespace element
Returns:
The ns value.
Throws:
SAXException

error

void error(String key)
     throws SAXException
Report a no arguments error from a key.

Parameters:
key - The error key.
Throws:
SAXException

error

void error(String key,
           String arg)
     throws SAXException
Report an one argument error.

Parameters:
key - The error key.
arg - The argument.
Throws:
SAXException

error

void error(String key,
           String arg,
           Locator locator)
     throws SAXException
Report an one argument error with location.

Parameters:
key - The error key.
arg - The argument.
locator - The location.
Throws:
SAXException

error

void error(String key,
           String arg1,
           String arg2)
     throws SAXException
Report a two arguments error.

Parameters:
key - The error key.
arg1 - The first argument.
arg2 - The second argument.
Throws:
SAXException