Package org.web3d.x3d.jaxp
Class X3DSAVAdapter
java.lang.Object
org.web3d.x3d.jaxp.X3DSAVAdapter
- All Implemented Interfaces:
ContentHandler
,LexicalHandler
- Direct Known Subclasses:
X3DSAVAdapterTolerant
Interface adapter between XML input from a Simple API for XML (SAX) source to
the Simple API for VRML Parsing (SAV) source used by the other parsers.
The implementation is a simplistic way for quickly getting XML content into the normal VRML input sources by adapting the SAX feeds to SAV feeds.
- Version:
- $Revision: 1.48 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.j3d.util.HashSet
<String> Set of permitted public IDsprotected static final org.j3d.util.HashSet
<String> Set of permitted system IDsprotected static final String
String constant of the AS attributeMapping of reserved attribute names strings to constantsprotected StringBuffer
The buffer to put all the scripting string into as we're building up CDATA information.protected boolean
Flag to say we need to check next for a valid scene tagprotected boolean
Flag indicating if the X3D namespace is set as the one that does not need to be prepended.protected static final String
String constant of the Class attributeprotected static final int
protected static final int
protected static final int
protected static final String
String constant of the containerField attributeprotected static final int
protected static final String
Name of the property file holding the default container fieldsprotected static final String
Message when we couldn't read the container properties fileprotected Properties
Property for container fieldsprotected ContentHandler
Reference to the registered content handler if we have oneprotected IntStack
Stack of fieldDeclDepth counts as we traverse the script and proto instance declarations, particularly field value callsprotected static final String
String constant of the DEF attributeprotected static final int
protected IntStack
Stack of protoBodyDepth counts as we traverse the script and proto declarations.Mapping of element names strings to constantsprotected String
Stored extern proto url to smooth model differencesprotected org.j3d.util.ErrorReporter
Reporter instance for handing out errorsprotected static final int
protected static final int
protected static final int
protected static final int
Mapping of field access type strings to constant integersprotected int
Flag to say we're in the processing of any field element right nowprotected String
The full URL of the current worldprotected static final int
protected static final int
protected boolean
Flag to say we're in the processing of a script fields right nowprotected static final String
Message because the DTD name is wrongprotected static final String
Message because the PUBLIC ID is wrongprotected static final String
Message because the SYSTEM ID is wrongprotected static final int
protected static final int
protected static final String
String constant of the name attributeprotected static final int
protected org.j3d.util.HashSet
<String> A set of prefixes that we know about for the namespace IDs.protected static final String
Message when we couldn't find any container properties fileprotected static final String
Message when no profile was givenprotected static final String
Message when there was no scene tag providedprotected boolean
Should we attempt to makeup for missing lexical eventsprotected static final String
String constant of the profile attributeprotected static final int
protected static final int
protected static final int
protected static final int
protected ProtoHandler
Reference to the registered proto handler if we have oneprotected static final int
protected RouteHandler
Reference to the registered route handler if we have oneprotected DocumentLocator
The SAV locator to find error informationprotected Locator
The document SAX locator to find error informationprotected static final int
protected static final int
protected BooleanStack
Stack holding proto and script declaration semanticsprotected ScriptHandler
Reference to the registered script handler if we have oneprotected BooleanStack
Stack of flags on whether a Script had a url.Map the spec version to version stringMap the public ID to the spec versionprotected static final org.j3d.util.HashSet
<String> Set of permitted schema IDsprotected static final String
Message when transitional content detectedprotected static final String
Message for a bad field access typeprotected static final String
Message when transitional content detectedprotected static final String
When we get an element with an ID as a stock element type, but have no idea what it is.protected static final String
String constant of the USE attributeprotected static final int
protected static final String
Message when no profile was givenprotected boolean
Flag to say the previous startNode() was actually a USEprotected static final String
String constant of the value attributeprotected static final String
String constant of the version attributeprotected String
The version string defined by the specprotected String
World URL, for passing on to the listenerprotected static final int
protected String
The ID string that is associated with the X3D namespace from the incoming document.protected static final String
Keyword describing the XML encoding for the start doc call -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Notification of character data to be added to the document.void
comment
(char[] ch, int start, int length) Report an XML comment anywhere in the document.void
endCDATA()
Report the end of a CDATA section.void
End the current document that is being parsed.void
endDTD()
Report the end of DTD declarations.void
endElement
(String namespace, String name, String qName) End the element processing.void
Report the end of an entity.void
endPrefixMapping
(String prefix) End the mapping for the named prefixprotected void
End a script.Get the currently setContentHandler
instance.Get the currently setProtoHandler
instance.Get the currently setRouteHandler
instance.Get the currently setScriptHandler
instance.void
ignorableWhitespace
(char[] ch, int start, int length) Notification of ignorable whitespace.protected void
loadContainerProperties
(float specVersion) Load the properties files for the given spec version.protected int
processFieldAccess
(String type, String fieldName) Turn the field access type string into one of the standard contentsvoid
processingInstruction
(String target, String data) Notification that a processing instruction has been added.void
Set the node handler to the given instance.void
Set the saxLocator used to report error information back to the user.void
setErrorReporter
(org.j3d.util.ErrorReporter reporter) Register an error reporter with the manager so that any errors generated by the loading of script code can be reported in a nice, pretty fashion.void
setLoadState
(String worldURL, String fullURL, boolean overrideLex) Set the loading state.void
Set the proto handler to the given instance.void
Set the route handler to the given instance.void
Set the script handler to the given instance.void
skippedEntity
(String name) Notification of an entity that was skipped during the processing.void
Report the start of a CDATA section.void
Start a new document to be parsed.void
Report the start of DTD declarations, if any.void
startElement
(String namespace, String localName, String qName, Attributes attribs) Start the processing of a new element with the given collection of attribute information.void
startEntity
(String name) Report the beginning of some internal and external XML entities.void
startPrefixMapping
(String prefix, String uri) Start the prefix mapping for a particular element or attribute.protected void
Start of a script declaration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
CONTAINER_PROPS_FILE
Name of the property file holding the default container fields- See Also:
-
INVALID_DTD_NAME_MSG
-
INVALID_PUBLIC_ID_MSG
Message because the PUBLIC ID is wrong- See Also:
-
INVALID_SYSTEM_ID_MSG
Message because the SYSTEM ID is wrong- See Also:
-
TRANSITIONAL_HEADER_MSG
Message when transitional content detected- See Also:
-
UNKNOWN_DTD_MSG
-
UNKNOWN_ACCESS_TYPE_MSG
-
NO_PROFILE_MSG
-
NO_SCENE_TAG_MSG
Message when there was no scene tag provided- See Also:
-
USE_WITH_KIDS_MSG
-
NO_CONTAINER_PROPS_MSG
Message when we couldn't find any container properties file- See Also:
-
CONTAINER_PROPS_READ_ERR
Message when we couldn't read the container properties file- See Also:
-
UNKNOWN_ELEMENT_MSG
When we get an element with an ID as a stock element type, but have no idea what it is. Basically we should never see this message, but it is there for safety.- See Also:
-
XML_ENCODING
Keyword describing the XML encoding for the start doc call- See Also:
-
X3D_TAG
protected static final int X3D_TAG- See Also:
-
COMPONENT_TAG
protected static final int COMPONENT_TAG- See Also:
-
SCENE_TAG
protected static final int SCENE_TAG- See Also:
-
PROTO_DECL_TAG
protected static final int PROTO_DECL_TAG- See Also:
-
EXTERNPROTO_DECL_TAG
protected static final int EXTERNPROTO_DECL_TAG- See Also:
-
IS_TAG
protected static final int IS_TAG- See Also:
-
FIELD_TAG
protected static final int FIELD_TAG- See Also:
-
META_TAG
protected static final int META_TAG- See Also:
-
PROTO_INSTANCE_TAG
protected static final int PROTO_INSTANCE_TAG- See Also:
-
IMPORT_TAG
protected static final int IMPORT_TAG- See Also:
-
EXPORT_TAG
protected static final int EXPORT_TAG- See Also:
-
ROUTE_TAG
protected static final int ROUTE_TAG- See Also:
-
FIELD_VALUE_TAG
protected static final int FIELD_VALUE_TAG- See Also:
-
SCRIPT_TAG
protected static final int SCRIPT_TAG- See Also:
-
CONNECT_TAG
protected static final int CONNECT_TAG- See Also:
-
HEAD_TAG
protected static final int HEAD_TAG- See Also:
-
PROTO_INTERFACE_TAG
protected static final int PROTO_INTERFACE_TAG- See Also:
-
PROTO_BODY_TAG
protected static final int PROTO_BODY_TAG- See Also:
-
NAME_ATTR
-
PROFILE_ATTR
-
VERSION_ATTR
-
VALUE_ATTR
-
DEF_ATTR
-
USE_ATTR
-
AS_ATTR
-
CLASS_ATTR
-
CONTAINER_ATTR
String constant of the containerField attribute- See Also:
-
NAME_ATTR_ID
protected static final int NAME_ATTR_ID- See Also:
-
DEF_ATTR_ID
protected static final int DEF_ATTR_ID- See Also:
-
USE_ATTR_ID
protected static final int USE_ATTR_ID- See Also:
-
CLASS_ATTR_ID
protected static final int CLASS_ATTR_ID- See Also:
-
CONTAINER_ATTR_ID
protected static final int CONTAINER_ATTR_ID- See Also:
-
specVersionMap
-
specStringMap
-
allowedPublicIDs
Set of permitted public IDs -
allowedSystemIDs
Set of permitted system IDs -
systemSchemaIDs
Set of permitted schema IDs -
fieldAccessMap
-
elementMap
-
attributeMap
-
versionString
The version string defined by the spec -
containerFields
Property for container fields -
errorReporter
protected org.j3d.util.ErrorReporter errorReporterReporter instance for handing out errors -
saxLocator
The document SAX locator to find error information -
savLocator
The SAV locator to find error information -
contentHandler
Reference to the registered content handler if we have one -
routeHandler
Reference to the registered route handler if we have one -
scriptHandler
Reference to the registered script handler if we have one -
protoHandler
Reference to the registered proto handler if we have one -
worldURL
World URL, for passing on to the listener -
fullURL
The full URL of the current world -
useIsCurrent
protected boolean useIsCurrentFlag to say the previous startNode() was actually a USE -
characterDataBuffer
The buffer to put all the scripting string into as we're building up CDATA information. -
scriptFlagStack
Stack holding proto and script declaration semantics -
inScript
protected boolean inScriptFlag to say we're in the processing of a script fields right now -
fieldDeclDepth
protected int fieldDeclDepthFlag to say we're in the processing of any field element right now -
depthCountStack
Stack of protoBodyDepth counts as we traverse the script and proto declarations. -
declDepthStack
Stack of fieldDeclDepth counts as we traverse the script and proto instance declarations, particularly field value calls -
overrideLex
protected boolean overrideLexShould we attempt to makeup for missing lexical events -
checkForSceneTag
protected boolean checkForSceneTagFlag to say we need to check next for a valid scene tag -
epUrl
Stored extern proto url to smooth model differences -
scriptUrlStack
Stack of flags on whether a Script had a url. Used to ignore CDATA. -
x3dNamespaceId
The ID string that is associated with the X3D namespace from the incoming document. This will be defined in the X3D tag as one of the attributes. -
namespacePrefixes
A set of prefixes that we know about for the namespace IDs. These will be extracted from the xmlns: values in the X3D tag. -
checkForX3DNamespace
protected boolean checkForX3DNamespaceFlag indicating if the X3D namespace is set as the one that does not need to be prepended. This can be determined from thexsd:noNamespaceSchemaLocation
attribute on the X3D tag. We look for one of the matching schema locations.
-
-
Constructor Details
-
X3DSAVAdapter
public X3DSAVAdapter()Construct a default instance of this class.
-
-
Method Details
-
setLoadState
Set the loading state. Generally this is information that is gotten from the lexicalHandler. Seems XSLT transformation is keeping the lex handler to itself.- Parameters:
worldURL
- the worldURLfullURL
- the full URLoverrideLex
- Enable if lexicalHandling not working.
-
comment
public void comment(char[] ch, int start, int length) Report an XML comment anywhere in the document.- Specified by:
comment
in interfaceLexicalHandler
-
startDTD
Report the start of DTD declarations, if any. There are two formal doctypes supported. The first type is the required type by the X3D specification:<!DOCTYPE X3D PUBLIC "-//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specification/x3d/x3d-3_0.dtd">
The second type are the transitional DOCTYPEs used during development of the X3D specification.<!DOCTYPE X3D PUBLIC "http://www.web3D.org/TaskGroups/x3d/translation/x3d-compact.dtd" "/www.web3D.org/TaskGroups/x3d/translation/x3d-compact.dtd">
<!DOCTYPE X3D PUBLIC "http://www.web3d.org/specifications/x3d-3.0.dtd" "/www.web3d.org/TaskGroups/x3d/translation/x3d-3.0.dtd">
It is advised that these forms are never used, it is for transitional content only. When this header is detected, a warning message is generated on the output, but parsing continues normally.- Specified by:
startDTD
in interfaceLexicalHandler
- Parameters:
name
- The DTD name stringpublicId
- The Public ID used for the contentsystemId
- The system ID used for the content- Throws:
SAXException
-
endDTD
public void endDTD()Report the end of DTD declarations. Does nothing.- Specified by:
endDTD
in interfaceLexicalHandler
-
startCDATA
public void startCDATA()Report the start of a CDATA section. Script data for the URLs are sent this way.- Specified by:
startCDATA
in interfaceLexicalHandler
-
endCDATA
public void endCDATA()Report the end of a CDATA section.- Specified by:
endCDATA
in interfaceLexicalHandler
-
startEntity
Report the beginning of some internal and external XML entities.- Specified by:
startEntity
in interfaceLexicalHandler
- Parameters:
name
-
-
endEntity
Report the end of an entity.- Specified by:
endEntity
in interfaceLexicalHandler
- Parameters:
name
-
-
setDocumentLocator
Set the saxLocator used to report error information back to the user. Setting a value of null will clear the current saxLocator.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Parameters:
loc
- The saxLocator to use or null to clear
-
startDocument
Start a new document to be parsed. If the instance is currently in the middle of parsing a document, this will throw an exception. Does nothing because the document start is assumed to be sent to the SAV content handler after the DTD has been read.- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
- The document is currently being parsed
-
endDocument
End the current document that is being parsed. Cleans up any internal structures currently in use but leaves the Document object about to work with.- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
- Not thrown in this implementation
-
startPrefixMapping
Start the prefix mapping for a particular element or attribute. Not implemented yet- Specified by:
startPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- The prefix string useduri
- The namespace URI the prefix is mapped to- Throws:
SAXException
- Not thrown in this implementation
-
endPrefixMapping
End the mapping for the named prefix- Specified by:
endPrefixMapping
in interfaceContentHandler
- Parameters:
prefix
- The prefix to stop the URI mapping for- Throws:
SAXException
- Not thrown in this implementation
-
startElement
public void startElement(String namespace, String localName, String qName, Attributes attribs) throws SAXException Start the processing of a new element with the given collection of attribute information.- Specified by:
startElement
in interfaceContentHandler
- Parameters:
namespace
- The namespace for the element. Null if not usedlocalName
- The local name of the element to createqName
- The qualified name of the element including prefixattribs
- The collection of attributes to use- Throws:
SAXException
- The element can't be found in the underlying factory
-
endElement
End the element processing.- Specified by:
endElement
in interfaceContentHandler
- Parameters:
namespace
- The namespace for the element. Null if not usedname
- The local name of the element to createqName
- The qualified name of the element including prefix- Throws:
SAXException
- Not thrown in this implementation
-
characters
Notification of character data to be added to the document. If we are currently parsing a CDATA section then we just append the string to the current string.- Specified by:
characters
in interfaceContentHandler
- Parameters:
ch
- The characters to add as a commentstart
- The start position in the character arraylength
- The number of characters to use as a comment- Throws:
SAXException
- The node containing the characters in is invalid
-
ignorableWhitespace
Notification of ignorable whitespace. If we are set to ignore whitespace then this method does nothing. If we do not ignore it then we add it to the current CDATA section if we are processing a CDATA, else append it as data to the current top node- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Parameters:
ch
- The characters to add as a commentstart
- The start position in the character arraylength
- The number of characters to use as a comment- Throws:
SAXException
- The node containing the characters in is invalid
-
processingInstruction
Notification that a processing instruction has been added. Ignored.- Specified by:
processingInstruction
in interfaceContentHandler
- Parameters:
target
- The target instruction namedata
- Data associated with the instruction- Throws:
SAXException
- The instruction is invalid
-
skippedEntity
Notification of an entity that was skipped during the processing. Not implemented yet.- Specified by:
skippedEntity
in interfaceContentHandler
- Parameters:
name
- The name of the entity that was skipped- Throws:
SAXException
- Not thrown in this implementation
-
setErrorReporter
public void setErrorReporter(org.j3d.util.ErrorReporter reporter) Register an error reporter with the manager so that any errors generated by the loading of script code can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old.- Parameters:
reporter
- The instance to use or null
-
getContentHandler
Get the currently setContentHandler
instance. If nothing is set it will return null.- Returns:
- The currently set node handler.
-
setContentHandler
Set the node handler to the given instance. If the value is null it will clear the currently set instance.- Parameters:
ch
- The content handler instance to use
-
getScriptHandler
Get the currently setScriptHandler
instance. If nothing is set it will return null.- Returns:
- The currently set script handler.
-
setScriptHandler
Set the script handler to the given instance. If the value is null it will clear the currently set instance.- Parameters:
sh
- The script handler instance to use
-
getProtoHandler
Get the currently setProtoHandler
instance. If nothing is set it will return null.- Returns:
- The currently set proto handler.
-
setProtoHandler
Set the proto handler to the given instance. If the value is null it will clear the currently set instance.- Parameters:
ph
- The proto handler instance to use
-
getRouteHandler
Get the currently setRouteHandler
instance. If nothing is set it will return null.- Returns:
- The currently set route handler.
-
setRouteHandler
Set the route handler to the given instance. If the value is null it will clear the currently set instance.- Parameters:
rh
- The route handler instance to use
-
processFieldAccess
Turn the field access type string into one of the standard contents- Parameters:
type
- A string representing the access typefieldName
- The name of the field to process- Returns:
- The access type as an int from FieldConstants constants
- Throws:
SAXException
-
loadContainerProperties
protected void loadContainerProperties(float specVersion) Load the properties files for the given spec version.- Parameters:
specVersion
- The spec version in floating point format
-
startScript
protected void startScript()Start of a script declaration. -
endScript
protected void endScript()End a script. Sends url data from the CDATA block.
-