H3D API  2.4.1
Classes | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
H3D::X3D::X3DSAX2Handlers Class Reference

This class implements the SAX2 ContentHandler and ErrorHandler interface in order to build an H3D scenegraph from a X3D XML file. More...

#include <H3D/X3DSAX2Handlers.h>

Inherits DefaultHandler.

Classes

class  NodeElement
 Encapsulate a node with its XML containerField attribute. More...
 

Public Member Functions

 X3DSAX2Handlers (DEFNodes *dn=NULL, DEFNodes *_exported_nodes=NULL, PrototypeVector *_proto_declarations=NULL, bool _called_from_proto_declaration=false)
 Constructor. More...
 
 ~X3DSAX2Handlers ()
 Destructor.
 
const AutoRef< Node > & getResultingNode ()
 Get the node that has been generated by the last parsing. More...
 
virtual void startDocument ()
 Handler for the SAX ContentHandler interface. More...
 
virtual void endDocument ()
 Handler for the SAX ContentHandler interface. More...
 
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 Handler for the SAX ContentHandler interface. More...
 
void startCDATA ()
 Handler for the SAX LexicalHandler interface. More...
 
void endCDATA ()
 Handler for the SAX LexicalHandler interface. More...
 
void characters (const XMLCh *const chars, const XMLSize_t length)
 Handler for the SAX DocumentHandler interface. More...
 
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 Handler for the SAX ContentHandler interface. More...
 
void warning (const SAXParseException &exc)
 Handler for the SAX ErrorHandler interface. More...
 
void error (const SAXParseException &exc)
 Handler for the SAX ErrorHandler interface. More...
 
void fatalError (const SAXParseException &exc)
 Handler for the SAX ErrorHandler interface. More...
 

Public Attributes

X3DPrototypeInstanceproto_instance
 If this is set to non-NULL then the parser is used to create an X3DPrototypeInstance. More...
 

Protected Types

typedef std::stack< NodeElementNodeElementStack
 A stack of NodeElements. More...
 

Protected Member Functions

void protoStartElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 This function will be called by startElement if the element is a ProtoDeclare element or a child of it. More...
 
void protoEndElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 This function will be called by endElement if the element is a ProtoDeclare element or a child of it. More...
 
void handleProtoInterfaceFieldElement (const Attributes &attrs)
 This function is called when a field element has been found in a ProtoInterface element. More...
 
void handleConnectElement (const Attributes &attrs, Node *parent)
 This function will be called if a connect element has been found in an IS element. More...
 
void handleRouteElement (const Attributes &attrs, bool route_no_event=false)
 This function will be called if a ROUTE, ROUTE_NO_EVENT or ROUTE_WITH_EVENT element has been found.
 
void handleProgramSettingElement (const Attributes &attrs)
 This function will be called if a PROGRAM_SETTING element has been found.
 
FieldhandleFieldElement (const Attributes &attrs, Node *parent)
 This function will be called if a "field" element has been found that is not part of a ProtoInterface element. More...
 
void handleImportElement (const Attributes &attrs)
 This function will be called if a IMPORT element has been found.
 
void handleExportElement (const Attributes &attrs)
 This function will be called if a EXPORT element has been found.
 
X3DPrototypeInstancehandleProtoInstanceElement (const Attributes &attrs)
 This function will be called if a ProtoInstance element has been found. More...
 
void handleFieldValueElement (const Attributes &attrs, Node *parent)
 This function will be called if a fieldValue element has been found in a ProtoInstance element.
 
void handleExternProtoDeclareElement (const Attributes &attrs)
 This function will be called if a ExternProtoDeclare element has been found.
 
string getLocationString ()
 Returns a string with the current location as given by the current Locator object. More...
 

Protected Attributes

AutoRef< ProtoDeclarationproto_declaration
 Will be set when a ProtoDeclare element is found and it is will be used in protoStartElement and protoEndElement to define a prototype. More...
 
bool called_from_proto_declaration
 If true then this handler is created in proto_declaration so a ProtoDeclare element is allowed at top level.
 
string proto_body
 The string_body string is used when defining ProtoBody. More...
 
unsigned int proto_body_count
 Counter used know when a proto body part has finished. More...
 
H3DInt32 defining_proto_body
 true if we are inside a ProtoBody element.
 
bool defining_proto_interface
 true if we are inside a ProtoInterface element.
 
bool defining_proto_connections
 true if we are inside an IS element.
 
bool defining_extern_proto
 true if we are inside an ExternProtoDeclare element.
 
NodeElementStack node_stack
 A stack of nodes that have been created while traversing the XML structure.
 
bool delete_DEF_map
 If true the DEF_map member will be deleted when the X3DSAX2handlers object is destructed.
 
bool delete_exported_map
 If true the exported_nodes member will be deleted when the X3DSAX2handlers object is destructed.
 
bool delete_proto_declarations
 If true the proto_declarations member will be deleted when the X3DSAX2handlers object is destructed.
 
DEFNodesDEF_map
 A structure containing a map between DEF names and nodes that are found during parsing.
 
DEFNodesexported_nodes
 A list of DEFNodes that contain the nodes that have been exported using the EXPORT statement.
 
PrototypeVector * proto_declarations
 The ProtoDeclarations that have been defined with ProtoDeclare elements.
 
AutoRefVector< H3DScriptNodescript_nodes
 All instances of H3DScriptNode that has been instanced so far during parsing.
 
AutoRef< Noderesulting_node
 The Node that is created during parsing.
 
Locator * locator
 The locator object of the parser. More...
 
bool profile_set
 Set after a profile is found (either in the X3D tag or in a PROFILE statement)
 
bool meta_set
 Set after a META is set.
 
bool inside_cdata
 Set to true while parser is parsing characters inside a CDATA construct.
 
string cdata
 The characters collected inside a CDATA construct. More...
 

Detailed Description

This class implements the SAX2 ContentHandler and ErrorHandler interface in order to build an H3D scenegraph from a X3D XML file.

Member Typedef Documentation

◆ NodeElementStack

A stack of NodeElements.

Used during parsing to keep track of the created Nodes.

Constructor & Destructor Documentation

◆ X3DSAX2Handlers()

H3D::X3D::X3DSAX2Handlers::X3DSAX2Handlers ( DEFNodes dn = NULL,
DEFNodes _exported_nodes = NULL,
PrototypeVector *  _proto_declarations = NULL,
bool  _called_from_proto_declaration = false 
)
inline

Constructor.

Parameters
dnA structure to store the mapping between DEF names and the nodes the reference
_exported_nodesA structure to store the exported nodes.
_proto_declarationsStorage of all proto declarations.
_called_from_proto_declarationTrue if instance is created by ProtoDeclaration class.

References DEF_map, exported_nodes, and proto_declarations.

Member Function Documentation

◆ characters()

void X3DSAX2Handlers::characters ( const XMLCh *const  chars,
const XMLSize_t  length 
)

Handler for the SAX DocumentHandler interface.

if( length > 0 )

Receive notification of character data inside an element.

References length().

◆ endCDATA()

void X3DSAX2Handlers::endCDATA ( )

Handler for the SAX LexicalHandler interface.

Called on start of CDATA.

References H3D::X3D::X3DSAX2Handlers::NodeElement::setCDATA().

◆ endDocument()

void X3DSAX2Handlers::endDocument ( )
virtual

Handler for the SAX ContentHandler interface.

Is called at end of parsing and updates all script nodes named nodes.

◆ endElement()

void X3DSAX2Handlers::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)

Handler for the SAX ContentHandler interface.

Builds the H3D scene graph.

Parameters
urithe URI of the associated namespace for this element
localnamethe local part of the element name
qnamethe QName of this element
Exceptions
X3D::XMLParseError

◆ error()

void X3DSAX2Handlers::error ( const SAXParseException &  exc)

Handler for the SAX ErrorHandler interface.

Throws an X3D::XMLParseError exception with the error information.

Exceptions
X3D::XMLParseError

◆ fatalError()

void X3DSAX2Handlers::fatalError ( const SAXParseException &  exc)

Handler for the SAX ErrorHandler interface.

Throws an XMLParseError exception with the error information.

Exceptions
X3D::XMLParseError

◆ getLocationString()

string X3DSAX2Handlers::getLocationString ( )
protected

Returns a string with the current location as given by the current Locator object.

system id and line number is included. Only valid during event callbacks.

◆ getResultingNode()

const AutoRef<Node>& H3D::X3D::X3DSAX2Handlers::getResultingNode ( )
inline

Get the node that has been generated by the last parsing.

Only valid after a successful call to the parse() function of a SAX2 Parser with class as a ContentHandler.

References resulting_node.

◆ handleConnectElement()

void X3DSAX2Handlers::handleConnectElement ( const Attributes &  attrs,
Node parent 
)
protected

This function will be called if a connect element has been found in an IS element.

The attrs argument are the attributes of the ProtoInterface element and the parent argument is the node of the element that it lies within.

References H3D::X3D::X3DSAX2Handlers::NodeElement::haveConnectElement(), and H3D::X3D::X3DSAX2Handlers::NodeElement::setConnectElement().

◆ handleFieldElement()

Field * X3DSAX2Handlers::handleFieldElement ( const Attributes &  attrs,
Node parent 
)
protected

This function will be called if a "field" element has been found that is not part of a ProtoInterface element.

If successful it returns a new Field with the specified attributes, if not NULL is returned.

◆ handleProtoInstanceElement()

X3DPrototypeInstance * X3DSAX2Handlers::handleProtoInstanceElement ( const Attributes &  attrs)
protected

This function will be called if a ProtoInstance element has been found.

It returns an X3DPrototypeInstance of the specified prototype if it exists, otherwise NULL.

◆ handleProtoInterfaceFieldElement()

void X3DSAX2Handlers::handleProtoInterfaceFieldElement ( const Attributes &  attrs)
protected

This function is called when a field element has been found in a ProtoInterface element.

The attrs argument are the attributes of the field element.

◆ protoEndElement()

void X3DSAX2Handlers::protoEndElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)
protected

This function will be called by endElement if the element is a ProtoDeclare element or a child of it.

It replaces the normal functionallity of startElement

References H3DUtil::AutoRef< class >::get().

◆ protoStartElement()

void X3DSAX2Handlers::protoStartElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attrs 
)
protected

This function will be called by startElement if the element is a ProtoDeclare element or a child of it.

It replaces the normal functionallity of startElement and creates a ProtoDeclaration instead.

◆ startCDATA()

void X3DSAX2Handlers::startCDATA ( )

Handler for the SAX LexicalHandler interface.

Handler for the SAX LexicalHandler interface. Called on start of CDATA.

◆ startDocument()

virtual void H3D::X3D::X3DSAX2Handlers::startDocument ( )
inlinevirtual

Handler for the SAX ContentHandler interface.

Resets the node member to NULL

References resulting_node.

◆ startElement()

void X3DSAX2Handlers::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attrs 
)

Handler for the SAX ContentHandler interface.

Builds the H3D scene graph.

Parameters
urithe URI of the associated namespace for this element
localnamethe local part of the element name
qnamethe QName of this element
attrsthe specified or defaulted attributes.
Exceptions
X3D::XMLParseError

◆ warning()

void X3DSAX2Handlers::warning ( const SAXParseException &  exc)

Handler for the SAX ErrorHandler interface.

Prints a warning message to the Console.

Member Data Documentation

◆ cdata

string H3D::X3D::X3DSAX2Handlers::cdata
protected

The characters collected inside a CDATA construct.

Set in the characters function when inside_cdata is true. Reset in endCDATA fucntion.

◆ locator

Locator* H3D::X3D::X3DSAX2Handlers::locator
protected

The locator object of the parser.

Can be used to retrieve the location of any document handler event in the XML source document.

◆ proto_body

string H3D::X3D::X3DSAX2Handlers::proto_body
protected

The string_body string is used when defining ProtoBody.

All elements will then just be translated to a string to be used by the ProtoDeclaration.

◆ proto_body_count

unsigned int H3D::X3D::X3DSAX2Handlers::proto_body_count
protected

Counter used know when a proto body part has finished.

Will be incremented on each start of element end decremented on end. This means each time it reaches 0 a body element is finished.

◆ proto_declaration

AutoRef< ProtoDeclaration > H3D::X3D::X3DSAX2Handlers::proto_declaration
protected

Will be set when a ProtoDeclare element is found and it is will be used in protoStartElement and protoEndElement to define a prototype.

On end of ProtoDeclare it will be added to proto_declarations and proto_declaration will be set to NULL again;

◆ proto_instance

X3DPrototypeInstance* H3D::X3D::X3DSAX2Handlers::proto_instance

If this is set to non-NULL then the parser is used to create an X3DPrototypeInstance.

This allows the IS and connect elements to be used.


The documentation for this class was generated from the following files: