diff options
author | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-01-24 21:00:02 +0000 |
---|---|---|
committer | nanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-01-24 21:00:02 +0000 |
commit | 5d1316e5fc220213cfce1d06513855c9854cb643 (patch) | |
tree | 49bed976854b1a2a1db3070ac916dbe649c80f28 /ACEXML/parser | |
parent | f909ea671a7999cb7ac237bc47a4372b5697b579 (diff) | |
download | ATCD-5d1316e5fc220213cfce1d06513855c9854cb643.tar.gz |
ChangeLogTag:Thu Jan 24 14:53:38 2002 Nanbor Wang <nanbor@cs.wustl.edu>
Diffstat (limited to 'ACEXML/parser')
22 files changed, 4402 insertions, 0 deletions
diff --git a/ACEXML/parser/Makefile b/ACEXML/parser/Makefile new file mode 100644 index 00000000000..9a519bc492b --- /dev/null +++ b/ACEXML/parser/Makefile @@ -0,0 +1,17 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the client programs that test the ACE network services +#---------------------------------------------------------------------------- + +DIRS = parser + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nolocal.GNU diff --git a/ACEXML/parser/debug_validator/Debug_Attributes_Builder.cpp b/ACEXML/parser/debug_validator/Debug_Attributes_Builder.cpp new file mode 100644 index 00000000000..214ef8007f4 --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_Attributes_Builder.cpp @@ -0,0 +1,218 @@ +// $Id$ + +#include "common/SAXExceptions.h" +#include "parser/debug_validator/Debug_Attributes_Builder.h" + +ACEXML_Debug_Attribute_Builder::ACEXML_Debug_Attribute_Builder () + : type_ (ERROR_TYPE), + default_decl_ (INVALID) +{ +} + +ACEXML_Debug_Attribute_Builder::ACEXML_Debug_Attribute_Builder (const ACEXML_Debug_Attribute_Builder &rhs) + : name_ (rhs.name_), + type_ (rhs.type_), + default_decl_ (rhs.default_decl_), + default_value_ (rhs.default_value_), + att_value_queue_ (rhs.att_value_queue_) +{ +} + +ACEXML_Debug_Attribute_Builder::~ACEXML_Debug_Attribute_Builder () +{ +} + +int +ACEXML_Debug_Attribute_Builder::setName (const ACEXML_Char *n) +{ + this->name_.set (n, 0); + return 0; +} + +const ACEXML_Char * +ACEXML_Debug_Attribute_Builder::getName (void) +{ + return this->name_.fast_rep (); +} + +int +ACEXML_Debug_Attribute_Builder::setAttType (const ATT_TYPE type, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) +{ + if (this->type_ == ERROR_TYPE) + { + this->type_ = type; + return 0; + } + xmlenv.exception (new ACEXML_SAXParseException ("Attribute type redefinition in Debug Validator")); + return -1; +} + +int +ACEXML_Debug_Attribute_Builder::insertList (const ACEXML_Char *n, + ACEXML_Env &) + // ACE_THORW_SPEC ((ACEXML_SAXException)) +{ + ACEXML_String str (n, 0, 0); + + this->att_value_queue_.enqueue_tail (str); + return 0; +} + +int +ACEXML_Debug_Attribute_Builder::setDefault (const DEFAULT_DECL def, + const ACEXML_Char *value, + ACEXML_Env &) + // ACE_THORW_SPEC ((ACEXML_SAXException)) +{ + this->default_decl_ = def; + this->default_value_.set (value, 0); + return 0; +} + +int +ACEXML_Debug_Attribute_Builder::validAttr (void) +{ + // @@ Not implemented. Always return 1 (true) for now. + return 1; +} + +void +ACEXML_Debug_Attribute_Builder::dump (void) +{ + cout << this->name_ << " "; + + switch (this->type_) + { + case CDATA: + cout << "CDATA "; + break; + case ID: + cout << "ID "; + break; + case IDREF: + cout << "IDREF "; + break; + case IDREFS: + cout << "IDREFS "; + break; + case ENTITY: + cout << "ENTITY "; + break; + case ENTITIES: + cout << "ENTITIES "; + break; + case NMTOKEN: + cout << "NMTOKEN "; + break; + case NMTOKENS: + cout << "NMTOKENS "; + break; + case NOTATION: + cout << "NOTATION "; + // Fall thru + case ENUMERATION: + { + cout << "("; + ACEXML_STRING_QUEUE_ITERATOR iter (this->att_value_queue_); + ACEXML_String *n = 0; + + while (iter.advance () != 0) + { + if (n == 0) + cout << " | "; + iter.next (n); + cout << *n; + } + cout << ") "; + } + break; + default: + cout << "*** UNKNOW TYPE ***"; + break; + } + + switch (this->default_decl_) + { + case REQUIRED: + cout << "#REQUIRED"; + break; + case IMPLIED: + cout << "#IMPLIED"; + break; + case FIXED: + cout << "#FIXED " << this->default_value_; + break; + default: + cout << "**** UNDEFINED DEFAULT DECL ****"; + break; + } +} +// ======================================== + +ACEXML_Debug_Attributes_Builder::ACEXML_Debug_Attributes_Builder () +{ +} + +ACEXML_Debug_Attributes_Builder::~ACEXML_Debug_Attributes_Builder () +{ +} + +int +ACEXML_Debug_Attributes_Builder::setElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + this->element_name_.set (qName, 0); + return 0; +} + +ACEXML_Attribute_Def_Builder * +ACEXML_Debug_Attributes_Builder::getAttribute_Def_Builder () +{ + ACEXML_Attribute_Def_Builder *tmp; + + ACE_NEW_RETURN (tmp, + ACEXML_Debug_Attribute_Builder (), + 0); + return tmp; +} + +int +ACEXML_Debug_Attributes_Builder::insertAttribute (ACEXML_Attribute_Def_Builder *def, + ACEXML_Env &xmlenv) +{ + ACEXML_Attribute_Def_Builder::VAR ptr (def); + + if (def != 0) + { + ACEXML_String attname (def->getName (), 0, 0); + ACEXML_Debug_Attribute_Builder *ptr = + ACE_dynamic_cast (ACEXML_Debug_Attribute_Builder *, def); + this->attributes_.bind (attname, *ptr); + return 0; + } + xmlenv.exception (new ACEXML_SAXParseException ("ACEXML_Debug_Attributes_Builder internal error")); + return -1; +} + +void +ACEXML_Debug_Attributes_Builder::dump (void) +{ + // @@ Print print. + cout << "<!ATTLIST " << this->element_name_ << endl; + + ACEXML_ATT_MAP_ITER iter (this->attributes_); + ACEXML_ATT_MAP_ENTRY *item; + + while (iter.advance () != 0) + { + iter.next (item); + cout << "\n\t"; + item->int_id_.dump (); + } + cout << ">" << endl; +} diff --git a/ACEXML/parser/debug_validator/Debug_Attributes_Builder.h b/ACEXML/parser/debug_validator/Debug_Attributes_Builder.h new file mode 100644 index 00000000000..b727e29e72f --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_Attributes_Builder.h @@ -0,0 +1,170 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Debug_Attributes_Builder.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_DEBUG_ATTRIBUTES_BUILDER_H_ +#define _ACEXML_DEBUG_ATTRIBUTES_BUILDER_H_ + +#include "common/Attributes_Def_Builder.h" +#include "parser/debug_validator/Debug_DTD_Manager_Export.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Unbounded_Queue.h" + +typedef ACE_Unbounded_Queue<ACEXML_String> ACEXML_STRING_QUEUE; +typedef ACE_Unbounded_Queue_Iterator<ACEXML_String> ACEXML_STRING_QUEUE_ITERATOR; + +/** + * @ class ACEXML_Debug_Attribute_Builder Debug_Attributes_Builder.h "parser/debug_validator/Debug_Attributes_Builder.h" + * + * This class prints out the Attribute definition for debugging purpose. + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Debug_Attribute_Builder + : public ACEXML_Attribute_Def_Builder +{ +public: + ACEXML_Debug_Attribute_Builder (); + + ACEXML_Debug_Attribute_Builder (const ACEXML_Debug_Attribute_Builder &rhs); + + virtual ~ACEXML_Debug_Attribute_Builder (); + + /** + * Specify the name of the attribute. + */ + virtual int setName (const ACEXML_Char *n); + virtual const ACEXML_Char *getName (void); + + /** + * Set the attribute type. + */ + virtual int setAttType (const ATT_TYPE type, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Insert an element for NOTATION or ENUMERATION type attribute. + */ + virtual int insertList (const ACEXML_Char *Name, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Set default attribute declaration. + */ + virtual int setDefault (const DEFAULT_DECL def, + const ACEXML_Char *value, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Check validity of the current attribute definition being built. + * + * @retval 0 if the attribute is not a valid combo. + */ + virtual int validAttr (void); + + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void); +private: + /// Attribute name. + ACEXML_String name_; + + /// Type of attribute. + ATT_TYPE type_; + + /// Default value type. + DEFAULT_DECL default_decl_; + + /// Default attribute value. + ACEXML_String default_value_; + + /// Holds a queue of enumerated attribute values. + ACEXML_STRING_QUEUE att_value_queue_; +}; + +typedef ACE_Hash_Map_Entry<ACEXML_String, + ACEXML_Debug_Attribute_Builder> ACEXML_ATT_MAP_ENTRY; + +typedef ACE_Hash_Map_Manager_Ex <ACEXML_String, + ACEXML_Debug_Attribute_Builder, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ATT_MAP; + +typedef ACE_Hash_Map_Iterator_Ex<ACEXML_String, + ACEXML_Debug_Attribute_Builder, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ATT_MAP_ITER; + +typedef ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, + ACEXML_Debug_Attribute_Builder, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ATT_MAP_REVERSE_ITER; + +/** + * @ class ACEXML_Debug_Attributes_Builder Debug_Attributes_Builder.h "parser/debug_validator/Debug_Attributes_Builder.h" + * + * This class prints out Attribute definitions for debugging purpose. + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Debug_Attributes_Builder + : public ACEXML_Attributes_Def_Builder +{ +public: + ACEXML_Debug_Attributes_Builder (); + + virtual ~ACEXML_Debug_Attributes_Builder (); + + /** + * Set the element name that the attribute builder applies. + * + * @retval 0 if valid, -1 otherwise. + */ + virtual int setElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Acquire an Attribute_Builder. + */ + virtual ACEXML_Attribute_Def_Builder *getAttribute_Def_Builder (); + + /** + * Add a definition for one attribute. + */ + virtual int insertAttribute (ACEXML_Attribute_Def_Builder *def, + ACEXML_Env &xmlenv); + + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void); +protected: + /// The name of the element type these attributes applied. + ACEXML_String element_name_; + + /// Collection of attributes. + ACEXML_ATT_MAP attributes_; +}; + + + +#endif /* _ACEXML_DEBUG_ATTRIBUTES_BUILDER_H_ */ diff --git a/ACEXML/parser/debug_validator/Debug_DTD_Manager.cpp b/ACEXML/parser/debug_validator/Debug_DTD_Manager.cpp new file mode 100644 index 00000000000..034ac1fbd9a --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_DTD_Manager.cpp @@ -0,0 +1,77 @@ +// -*- C++ -*- $Id$ + +#include "common/SAXExceptions.h" +#include "parser/debug_validator/Debug_DTD_Manager.h" +#include "parser/debug_validator/Debug_Element_Builder.h" +#include "parser/debug_validator/Debug_Attributes_Builder.h" + +ACEXML_Debug_DTD_Manager::ACEXML_Debug_DTD_Manager () +{ + +} + +ACEXML_Debug_DTD_Manager::~ACEXML_Debug_DTD_Manager () +{ + +} + +ACEXML_Element_Def_Builder * +ACEXML_Debug_DTD_Manager::getElement_Def_Builder () +{ + return new ACEXML_Debug_Element_Builder (); +} + +int +ACEXML_Debug_DTD_Manager::insertElement_Definition (ACEXML_Element_Def_Builder *def, + ACEXML_Env &xmlenv) +{ + ACEXML_Element_Def_Builder::VAR ptr (def); + + if (def != 0) + { + ptr->dump (); + return 0; + } + + xmlenv.exception (new ACEXML_SAXParseException ("ACEXML_Debug_Attributes_Builder internal error")); + return -1; +} + +ACEXML_Attributes_Def_Builder * +ACEXML_Debug_DTD_Manager::getAttribute_Def_Builder () +{ + ACEXML_Attributes_Def_Builder *tmp; + ACE_NEW_RETURN (tmp, + ACEXML_Debug_Attributes_Builder (), + 0); + return tmp; +} + +int +ACEXML_Debug_DTD_Manager::insertAttributes_Definition (ACEXML_Attributes_Def_Builder *def, + ACEXML_Env &xmlenv) +{ + ACEXML_Attributes_Def_Builder::VAR ptr (def); + if (def != 0) + { + ptr->dump (); + return 0; + } + + xmlenv.exception (new ACEXML_SAXParseException ("ACEXML_Debug_Attributes_Builder internal error")); + return -1; +} + +ACEXML_Validator * +ACEXML_Debug_DTD_Manager::getValidator (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) +{ + ACE_UNUSED_ARG (namespaceURI); + ACE_UNUSED_ARG (localName); + ACE_UNUSED_ARG (qName); + + xmlenv.exception (new ACEXML_SAXNotSupportedException ()); + return 0; +} diff --git a/ACEXML/parser/debug_validator/Debug_DTD_Manager.h b/ACEXML/parser/debug_validator/Debug_DTD_Manager.h new file mode 100644 index 00000000000..0e03740cc99 --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_DTD_Manager.h @@ -0,0 +1,71 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Debug_DTD_Manager.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_DEBUG_DTD_Manager_H_ +#define _ACEXML_DEBUG_DTD_Manager_H_ + +#include "common/DTD_Manager.h" +#include "parser/debug_validator/Debug_DTD_Manager_Export.h" + +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Debug_DTD_Manager : public ACEXML_DTD_Manager +{ +public: + ACEXML_Debug_DTD_Manager (); + + virtual ~ACEXML_Debug_DTD_Manager (); + + /** + * Acquire a pointer to an element definition builder. + * The XML parser use this interface to acquire the + * definition builder and use the builder to create + * the DTD element definition. The resulting builder + * is then registered with the DTD Manager or destroyed + * if error occured when the builder encountered errors. + * + * @retval 0 if error occurs creating the builder. + */ + virtual ACEXML_Element_Def_Builder *getElement_Def_Builder (); + + /** + * Insert a new element definition into the DTD Manager. + * + * @retval 0 if success, -1 if error. + */ + virtual int insertElement_Definition (ACEXML_Element_Def_Builder *def, + ACEXML_Env &xmlenv); + + /** + * Acquire a pointer to an attributes definition builder. + * + */ + virtual ACEXML_Attributes_Def_Builder *getAttribute_Def_Builder (); + + /** + * Insert a new attributes definition into the DTD Manager. + * + * @retval 0 if success, -1 otherwise. + */ + virtual int insertAttributes_Definition (ACEXML_Attributes_Def_Builder *def, + ACEXML_Env &xmlenv); + + /** + * Acquire an element validator to validate an XML element. + * + * @todo I haven't figured out what memory management scheme + * we should use for the acquired validator. + */ + virtual ACEXML_Validator *getValidator (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv); +}; + +#endif /* _ACEXML_DTD_Manager_H_ */ diff --git a/ACEXML/parser/debug_validator/Debug_DTD_Manager_Export.h b/ACEXML/parser/debug_validator/Debug_DTD_Manager_Export.h new file mode 100644 index 00000000000..b4cf1c8a536 --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_DTD_Manager_Export.h @@ -0,0 +1,38 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl -s ACEXML_DEBUG_DTD_MANAGER +// ------------------------------ +#ifndef ACEXML_DEBUG_DTD_MANAGER_EXPORT_H +#define ACEXML_DEBUG_DTD_MANAGER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (ACEXML_DEBUG_DTD_MANAGER_HAS_DLL) +# define ACEXML_DEBUG_DTD_MANAGER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && ACEXML_DEBUG_DTD_MANAGER_HAS_DLL */ + +#if !defined (ACEXML_DEBUG_DTD_MANAGER_HAS_DLL) +# define ACEXML_DEBUG_DTD_MANAGER_HAS_DLL 1 +#endif /* ! ACEXML_DEBUG_DTD_MANAGER_HAS_DLL */ + +#if defined (ACEXML_DEBUG_DTD_MANAGER_HAS_DLL) && (ACEXML_DEBUG_DTD_MANAGER_HAS_DLL == 1) +# if defined (ACEXML_DEBUG_DTD_MANAGER_BUILD_DLL) +# define ACEXML_DEBUG_DTD_MANAGER_Export ACE_Proper_Export_Flag +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* ACEXML_DEBUG_DTD_MANAGER_BUILD_DLL */ +# define ACEXML_DEBUG_DTD_MANAGER_Export ACE_Proper_Import_Flag +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ACEXML_DEBUG_DTD_MANAGER_BUILD_DLL */ +#else /* ACEXML_DEBUG_DTD_MANAGER_HAS_DLL == 1 */ +# define ACEXML_DEBUG_DTD_MANAGER_Export +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARATION(T) +# define ACEXML_DEBUG_DTD_MANAGER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* ACEXML_DEBUG_DTD_MANAGER_HAS_DLL == 1 */ + +#endif /* ACEXML_DEBUG_DTD_MANAGER_EXPORT_H */ + +// End of auto generated file. diff --git a/ACEXML/parser/debug_validator/Debug_Element_Builder.cpp b/ACEXML/parser/debug_validator/Debug_Element_Builder.cpp new file mode 100644 index 00000000000..aff04a4e0f4 --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_Element_Builder.cpp @@ -0,0 +1,154 @@ +// $Id$ + +#include "common/SAXExceptions.h" +#include "parser/debug_validator/Debug_Element_Builder.h" + +ACEXML_Debug_Element_Builder::ACEXML_Debug_Element_Builder () + : type_ (UNDEFINED), + root_ (0) +{ +} + +ACEXML_Debug_Element_Builder::~ACEXML_Debug_Element_Builder () +{ + delete this->root_; +} + +int +ACEXML_Debug_Element_Builder::setElementName (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *qName, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + this->element_.set (qName, 0); + return 0; +} + +int +ACEXML_Debug_Element_Builder::setContentType (CONTENT_TYPE type, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->type_ == UNDEFINED) + { + this->type_ = type; + return 0; + } + + xmlenv.exception (new ACEXML_SAXParseException ("Element type redefinition in Debug_Validator.")); + return -1; +} + +int +ACEXML_Debug_Element_Builder::insertMixedElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACEXML_Element_Tree_Name_Node *node; + + // @@ We should "throw" an exception here instead of returning -1. + ACE_NEW_RETURN (node, + ACEXML_Element_Tree_Name_Node (qName), + -1); + + if (this->root_ == 0) + // @@ Memory leak if fail? + ACE_NEW_RETURN (this->root_, + ACEXML_Element_Tree_List_Node (), + -1); + + + return this->root_->insert (node); +} + +int +ACEXML_Debug_Element_Builder::startChildGroup () +{ + ACEXML_Element_Tree_List_Node *lnode; + + ACE_NEW_RETURN (lnode, + ACEXML_Element_Tree_List_Node (), + -1); + + if (this->root_ == 0) + { + this->root_ = lnode; + } + else + { + // @@ check error? + this->root_->insert (lnode); + } + + this->active_list_.push (lnode); + return 0; +} + +int +ACEXML_Debug_Element_Builder::endChildGroup (CARDINALITY card, + ACEXML_Env &xmlenv) +{ + this->active_list_.pop (); + return 0; +} + +int +ACEXML_Debug_Element_Builder::setChoice () +{ + this->active_list_.top ()->set (ACEXML_Element_Tree_List_Node::CHOICE); + return 0; +} + +int +ACEXML_Debug_Element_Builder::setSequence () +{ + this->active_list_.top ()->set (ACEXML_Element_Tree_List_Node::SEQUENCE); + return 0; +} + +int +ACEXML_Debug_Element_Builder::insertElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACEXML_Element_Tree_Name_Node *node; + + // @@ We should "throw" an exception here instead of returning -1. + ACE_NEW_RETURN (node, + ACEXML_Element_Tree_Name_Node (qName), + -1); + + return this->active_list_.top ()->insert (node); +} + +void +ACEXML_Debug_Element_Builder::dump () +{ + cout << "<!ELEMENT " << this->element_; + + // @@ Also dump element contentspec here. + switch (this->type_) + { + case EMPTY: + cout << "EMPTY"; + break; + case ANY: + cout << "ANY"; + break; + case MIXED: + case CHILDREN: + // @@ Dump the content of this->root_ + cout << "*** not implemented ***"; + break; + default: + cout << "*** Unidentified element type ***"; + break; + } + + cout << ">" << endl; +} diff --git a/ACEXML/parser/debug_validator/Debug_Element_Builder.h b/ACEXML/parser/debug_validator/Debug_Element_Builder.h new file mode 100644 index 00000000000..28f3864a5b1 --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_Element_Builder.h @@ -0,0 +1,123 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Debug_Element_Builder.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_DEBUG_ELEMENT_BUILDER_H_ +#define _ACEXML_DEBUG_ELEMENT_BUILDER_H_ + +#include "common/Element_Def_Builder.h" +#include "parser/debug_validator/Debug_DTD_Manager_Export.h" +#include "parser/debug_validator/Element_Tree.h" + +/** + * @ class ACEXML_Debug_Element_Builder Debug_Element_Builder.h "parser/debug_validator/Debug_Element_Builder.h" + * + * This class prints out the element definition for debugging purpose. + * + * @todo This class is not namespace-aware. + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Debug_Element_Builder + : public ACEXML_Element_Def_Builder +{ +public: + ACEXML_Debug_Element_Builder (); + + virtual ~ACEXML_Debug_Element_Builder (); + + /** + * Define the name of the element. + * + * @retval 0 if valid, -1 otherwise. + */ + virtual int setElementName (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Define the content type of the element. + * + * @retval 0 if valid, -1 otherwise. + */ + virtual int setContentType (CONTENT_TYPE type, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Insert one more element into Mixed definition. + */ + virtual int insertMixedElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Start a new group of children. + */ + virtual int startChildGroup (); + + /** + * End a new group of children. + * + * @retval 0 on success. + */ + virtual int endChildGroup (CARDINALITY card, + ACEXML_Env &xmlenv); + + /** + * Set the type of current child group to Choice. + * + * @retval 0 on success, -1 if the type of the child group has + * already been set and this action conflicts with the previous + * setting. + */ + virtual int setChoice (); + + /** + * Set the type of current child group to Sequence. + * + * @retval 0 on success, -1 if the type of the child group has + * already been set and this action conflicts with the previous + * setting. + */ + virtual int setSequence (); + + /** + * Insert an new element into the current child group. + * + * @retval 0 on success, -1 otherwise. + */ + virtual int insertElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void); +private: + CONTENT_TYPE type_; + + ACEXML_String element_; + + ACEXML_Element_Tree_List_Node *root_; + + ACEXML_Element_Tree_List_Stack active_list_; +}; + +#endif /* _ACEXML_DEBUG_ELEMENT_BUILDER_H_ */ diff --git a/ACEXML/parser/debug_validator/Debug_Validator.dsp b/ACEXML/parser/debug_validator/Debug_Validator.dsp new file mode 100644 index 00000000000..82c34b7c67b --- /dev/null +++ b/ACEXML/parser/debug_validator/Debug_Validator.dsp @@ -0,0 +1,143 @@ +# Microsoft Developer Studio Project File - Name="Debug_Validator" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=Debug_Validator - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Debug_Validator.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Debug_Validator.mak" CFG="Debug_Validator - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Debug_Validator - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "Debug_Validator - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Debug_Validator - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEBUG_VALIDATOR_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\.." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_DEBUG_DTD_MANAGER_BUILD_DLL" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 ace.lib ACEXML.lib /nologo /dll /machine:I386 /out:"../../../bin/ACEXML_Debug_DTD_Manager.dll" /libpath:"../../../ace" /libpath:"../../Common"
+
+!ELSEIF "$(CFG)" == "Debug_Validator - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEBUG_VALIDATOR_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\.." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_DEBUG_DTD_MANAGER_BUILD_DLL" /YX /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib ACEXMLd.lib /nologo /dll /debug /machine:I386 /out:"../../../bin/ACEXML_Debug_DTD_Managerd.dll" /pdbtype:sept /libpath:"../../../ace" /libpath:"../../Common"
+
+!ENDIF
+
+# Begin Target
+
+# Name "Debug_Validator - Win32 Release"
+# Name "Debug_Validator - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Debug_Attributes_Builder.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug_DTD_Manager.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug_Element_Builder.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Element_Tree.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Debug_Attributes_Builder.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug_DTD_Manager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug_DTD_Manager_Export.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Debug_Element_Builder.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Element_Tree.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\Element_Tree.i
+# End Source File
+# End Target
+# End Project
diff --git a/ACEXML/parser/debug_validator/Element_Tree.cpp b/ACEXML/parser/debug_validator/Element_Tree.cpp new file mode 100644 index 00000000000..beaf642c3bd --- /dev/null +++ b/ACEXML/parser/debug_validator/Element_Tree.cpp @@ -0,0 +1,72 @@ +// $Id$ + +#include "parser/debug_validator/Element_Tree.h" + +#if !defined (__ACEXML_INLINE__) +# include "parser/debug_validator/Element_Tree.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_Element_Tree_Node::~ACEXML_Element_Tree_Node () +{ + delete this->next_; +} + +ACE_ALLOC_HOOK_DEFINE (ACEXML_Element_Tree_Node) + +void +ACEXML_Element_Tree_Name_Node::dump () +{ + cout << this->name_; +} + +ACE_ALLOC_HOOK_DEFINE (ACEXML_Element_Tree_Name_Node) + +ACEXML_Element_Tree_List_Node::~ACEXML_Element_Tree_List_Node (void) +{ + delete this->head_; +} + +int +ACEXML_Element_Tree_List_Node::insert (ACEXML_Element_Tree_Node *node) +{ + if (this->head_ == 0) + { + this->tail_ = this->head_ = node; + } + else + { + this->tail_->next (node); + this->tail_ = node; + } + return 0; +} + +void +ACEXML_Element_Tree_List_Node::dump (void) +{ + ACEXML_Element_Tree_Node *ptr = this->head_; + const ACEXML_Char *separator = (this->type_ == SEQUENCE) ? " , " : " | "; + + cout << "("; + + if (ptr != 0) + { + ptr->dump (); + ptr = ptr->next (); + + while (ptr != 0) + { + cout << separator; + ptr->dump (); + ptr->next (); + } + } + + cout << ")"; +} + +ACE_ALLOC_HOOK_DEFINE (ACEXML_Element_Tree_List_Node) + + + +ACE_ALLOC_HOOK_DEFINE (ACEXML_Element_Tree_List_Stack) diff --git a/ACEXML/parser/debug_validator/Element_Tree.h b/ACEXML/parser/debug_validator/Element_Tree.h new file mode 100644 index 00000000000..8cfe49431fa --- /dev/null +++ b/ACEXML/parser/debug_validator/Element_Tree.h @@ -0,0 +1,151 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Element_Tree.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_ELEMENT_TREE_H_ +#define _ACEXML_ELEMENT_TREE_H_ + +#include "common/XML_Types.h" +#include "parser/debug_validator/Debug_DTD_Manager_Export.h" + +/** + * @ class ACEXML_Element_Tree_Node Element_Tree.h "parser/debug_validator/Element_Tree.h" + * + * @brief An abstract base class for describing DTD child element definition. + * + * @sa ACEXML_Element_Tree_Name_Node, ACEXML_Element_Tree_List_Node + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Element_Tree_Node +{ +public: + + /// Default constructor. + ACEXML_Element_Tree_Node (); + + /// Destructor + virtual ~ACEXML_Element_Tree_Node (); + + /// Accessor for next element in chain + ACEXML_Element_Tree_Node *next (); + void next (ACEXML_Element_Tree_Node *n); + + /// Displaying the content. + virtual void dump () = 0; + + ACE_ALLOC_HOOK_DECLARE; + +protected: + ACEXML_Element_Tree_Node *next_; +}; + +/** + * @ class ACEXML_Element_Tree_Name_Node Element_Tree.h "parser/debug_validator/Element_Tree.h" + * + * @brief An abstract base class for describing a name node in a DTD + * child element definition. + * + * @sa ACEXML_Element_Tree_Node, ACEXML_Element_Tree_List_Node + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Element_Tree_Name_Node + : public ACEXML_Element_Tree_Node +{ +public: + /// Constructor. + ACEXML_Element_Tree_Name_Node (const ACEXML_Char *name, + int release = 1); + + /// Change the name of this node. + void set (const ACEXML_Char *name, + int release = 1); + + virtual void dump (); + + ACE_ALLOC_HOOK_DECLARE; +protected: + ACEXML_String name_; +}; + +class ACEXML_Element_Tree_List_Stack; + +/** + * @ class ACEXML_Element_Tree_List_Node Element_Tree.h "parser/debug_validator/Element_Tree.h" + * + * @brief An abstract base class for describing a node list in + * a DTD child element definition. + * + * @sa ACEXML_Element_Tree_Node, ACEXML_Element_Tree_Name_Node + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Element_Tree_List_Node + : public ACEXML_Element_Tree_Node +{ +public: + friend class ACEXML_Element_Tree_List_Stack; + + typedef enum { + SEQUENCE, + CHOICE + } LIST_TYPE; + + /// Default constructor. + ACEXML_Element_Tree_List_Node (void); + + /// Destructor. + virtual ~ACEXML_Element_Tree_List_Node (void); + + /// Insert a new ACEXML_Element_Tree_Node into the list. + int insert (ACEXML_Element_Tree_Node *node); + + /// Get/set the type of list. + LIST_TYPE get (void); + int set (LIST_TYPE type); + + virtual void dump (); + + ACE_ALLOC_HOOK_DECLARE; +protected: + LIST_TYPE type_; + + ACEXML_Element_Tree_Node *head_; + + ACEXML_Element_Tree_Node *tail_; + + ACEXML_Element_Tree_List_Node *pop_next_; +}; + +/** + * @ class ACEXML_Element_Tree_List_Stack Element_Tree.h "parser/debug_validator/Element_Tree.h" + * + * @brief A class for managing a stack of ACEXML_Element_Tree_List_Node's. + * + * @sa ACEXML_Element_Tree_List_Node + */ +class ACEXML_DEBUG_DTD_MANAGER_Export ACEXML_Element_Tree_List_Stack +{ +public: + ACEXML_Element_Tree_List_Stack (); + + void push (ACEXML_Element_Tree_List_Node *n); + + ACEXML_Element_Tree_List_Node *pop (void); + + ACEXML_Element_Tree_List_Node *top (void); + + int empty (void); + + ACE_ALLOC_HOOK_DECLARE; + +protected: + ACEXML_Element_Tree_List_Node *top_; +}; + +#if defined (__ACEXML_INLINE__) +# include "parser/debug_validator/Element_Tree.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_ELEMENT_TREE_H_ */ diff --git a/ACEXML/parser/debug_validator/Element_Tree.i b/ACEXML/parser/debug_validator/Element_Tree.i new file mode 100644 index 00000000000..4b408835403 --- /dev/null +++ b/ACEXML/parser/debug_validator/Element_Tree.i @@ -0,0 +1,92 @@ +// $Id$ + +ACEXML_INLINE +ACEXML_Element_Tree_Node::ACEXML_Element_Tree_Node () + : next_ (0) +{ +} + +ACEXML_INLINE ACEXML_Element_Tree_Node * +ACEXML_Element_Tree_Node::next () +{ + return this->next_; +} + +ACEXML_INLINE void +ACEXML_Element_Tree_Node::next (ACEXML_Element_Tree_Node * n) +{ + this->next_ = n; +} + +ACEXML_INLINE +ACEXML_Element_Tree_Name_Node::ACEXML_Element_Tree_Name_Node (const ACEXML_Char *name, + int release) + : name_ (name, 0, release) +{ +} + +ACEXML_INLINE void +ACEXML_Element_Tree_Name_Node::set (const ACEXML_Char *name, + int release) +{ + this->name_.set (name, release); +} + +ACEXML_INLINE +ACEXML_Element_Tree_List_Node::ACEXML_Element_Tree_List_Node (void) + : type_ (SEQUENCE), + head_ (0), + tail_ (0), + pop_next_ (0) +{ +} + +ACEXML_INLINE ACEXML_Element_Tree_List_Node::LIST_TYPE +ACEXML_Element_Tree_List_Node::get (void) +{ + return this->type_; +} + +ACEXML_INLINE int +ACEXML_Element_Tree_List_Node::set (ACEXML_Element_Tree_List_Node::LIST_TYPE type) +{ + this->type_ = type; + return 0; +} + +ACEXML_INLINE +ACEXML_Element_Tree_List_Stack::ACEXML_Element_Tree_List_Stack (void) + : top_ (0) +{ +} + +ACEXML_INLINE ACEXML_Element_Tree_List_Node * +ACEXML_Element_Tree_List_Stack::top () +{ + return this->top_; +} + +ACEXML_INLINE void +ACEXML_Element_Tree_List_Stack::push (ACEXML_Element_Tree_List_Node *n) +{ + n->pop_next_ = this->top_; + this->top_ = n; +} + +ACEXML_INLINE ACEXML_Element_Tree_List_Node * +ACEXML_Element_Tree_List_Stack::pop () +{ + if (this->top_ != 0) + { + ACEXML_Element_Tree_List_Node *ptr = this->top_; + this->top_ = this->top_->pop_next_; + return ptr; + } + return 0; +} + +ACEXML_INLINE int +ACEXML_Element_Tree_List_Stack::empty () +{ + return this->top_ == 0; +} diff --git a/ACEXML/parser/parser/Entity_Manager.cpp b/ACEXML/parser/parser/Entity_Manager.cpp new file mode 100644 index 00000000000..59054a7411e --- /dev/null +++ b/ACEXML/parser/parser/Entity_Manager.cpp @@ -0,0 +1,48 @@ +// $Id$ + +#include "parser/parser/Entity_Manager.h" + +#if !defined (__ACEXML_INLINE__) +# include "parser/parser/Entity_Manager.i" +#endif /* __ACEXML_INLINE__ */ + +static const ACEXML_Char amp_name[] = {'a', 'm', 'p', 0 }; +static const ACEXML_Char amp_value[] = {'&', 0}; +static const ACEXML_Char lt_name[] = {'l', 't', 0}; +static const ACEXML_Char lt_value[] = {'<', 0}; +static const ACEXML_Char gt_name[] = {'g', 't', 0}; +static const ACEXML_Char gt_value[] = {'>', 0}; +static const ACEXML_Char apos_name[] = {'a', 'p', 'o', 's', 0}; +static const ACEXML_Char apos_value[] = {'\'', 0}; +static const ACEXML_Char quot_name[] = {'q', 'u', 'o', 't', 0}; +static const ACEXML_Char quot_value[] = {'"', 0}; + +ACEXML_Entity_Manager::ACEXML_Entity_Manager (void) + : entities_ () +{ + // @@ No way to know if these bindings success or not. + + ACEXML_String ampname (amp_name, 0, 0); + ACEXML_String ampvalue (amp_value, 0, 0); + this->entities_.bind (ampname, ampvalue); + + ACEXML_String ltname (lt_name, 0, 0); + ACEXML_String ltvalue (lt_value, 0, 0); + this->entities_.bind (ltname, ltvalue); + + ACEXML_String gtname (gt_name, 0, 0); + ACEXML_String gtvalue (gt_value, 0, 0); + this->entities_.bind (gtname, gtvalue); + + ACEXML_String aposname (apos_name, 0, 0); + ACEXML_String aposvalue (apos_value, 0, 0); + this->entities_.bind (aposname, aposvalue); + + ACEXML_String quotname (quot_name, 0, 0); + ACEXML_String quotvalue (quot_value, 0, 0); + this->entities_.bind (quotname, quotvalue); +} + +ACEXML_Entity_Manager::~ACEXML_Entity_Manager (void) +{ +} diff --git a/ACEXML/parser/parser/Entity_Manager.h b/ACEXML/parser/parser/Entity_Manager.h new file mode 100644 index 00000000000..205715e7a4e --- /dev/null +++ b/ACEXML/parser/parser/Entity_Manager.h @@ -0,0 +1,71 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Entity_Manager.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef ACEXML_ENTITY_MANAGER_H +#define ACEXML_ENTITY_MANAGER_H + +#include "common/XML_Types.h" +#include "parser/parser/Parser_export.h" +#include "ace/Hash_Map_Manager.h" + +typedef ACE_Hash_Map_Entry<ACEXML_String, + ACEXML_String> ACEXML_ENTITY_ENTRY; + +typedef ACE_Hash_Map_Manager_Ex<ACEXML_String, + ACEXML_String, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ENTITIES_MANAGER; + +typedef ACE_Hash_Map_Iterator_Ex<ACEXML_String, + ACEXML_String, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ENTITIES_MANAGER_ITER; + +typedef ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, + ACEXML_String, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_ENTITIES_MANAGER_REVERSE_ITER; + +/** + * @class ACEXML_Entity_Manager Entity_Manager.h "parser/parser/Entity_Manager.h" + * + * @brief Class to manage and resolve entity references. + * + * @todo Fill in details for this class. + */ +class ACEXML_PARSER_Export ACEXML_Entity_Manager +{ +public: + /// Default constructor. + ACEXML_Entity_Manager (void); + + /// Destructor. + ~ACEXML_Entity_Manager (void); + + /// Add a new entity declaration. + int add_entity (const ACEXML_Char *ref, + const ACEXML_Char *value); + + /// Resolve an entity reference. + const ACEXML_String *resolve_entity (const ACEXML_Char *ref); + +private: + ACEXML_ENTITIES_MANAGER entities_; +}; + +#if defined (__ACEXML_INLINE__) +# include "parser/parser/Entity_Manager.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_ENTITY_MANAGER_H */ diff --git a/ACEXML/parser/parser/Entity_Manager.i b/ACEXML/parser/parser/Entity_Manager.i new file mode 100644 index 00000000000..696b82b64e4 --- /dev/null +++ b/ACEXML/parser/parser/Entity_Manager.i @@ -0,0 +1,21 @@ +// $Id$ + +ACEXML_INLINE int +ACEXML_Entity_Manager::add_entity (const ACEXML_Char *ref, + const ACEXML_Char *v) +{ + ACEXML_String name (ref, 0, 0); + ACEXML_String value (v, 0, 0); + return this->entities_.bind (name, value); +} + +ACEXML_INLINE const ACEXML_String * +ACEXML_Entity_Manager::resolve_entity (const ACEXML_Char *ref) +{ + ACEXML_ENTITY_ENTRY *entry; + + if (this->entities_.find (ACEXML_String (ref, 0, 0), + entry) == 0) + return &entry->int_id_; + return 0; +} diff --git a/ACEXML/parser/parser/Makefile b/ACEXML/parser/parser/Makefile new file mode 100644 index 00000000000..b7f43cee2ec --- /dev/null +++ b/ACEXML/parser/parser/Makefile @@ -0,0 +1,40 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the server-side ACE network services +#---------------------------------------------------------------------------- + +LIB = libACEXML_Parser.a +SHLIB = libACEXML_Parser.$(SOEXT) + +FILES = Entity_Manager \ + Parser + +DEFS = $(addsuffix .h,$(FILES)) +LSRC = $(addsuffix .cpp,$(FILES)) + +LIBS += $(ACELIB) +CCFLAGS += -I ../.. + +BUILD = $(VLIB) $(VSHLIB) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. diff --git a/ACEXML/parser/parser/Parser.cpp b/ACEXML/parser/parser/Parser.cpp new file mode 100644 index 00000000000..baf7de05ac4 --- /dev/null +++ b/ACEXML/parser/parser/Parser.cpp @@ -0,0 +1,2085 @@ +// $Id$ + +#include "parser/parser/Parser.h" +#include "common/Transcode.h" +#include "common/AttributesImpl.h" + +#if !defined (__ACEXML_INLINE__) +# include "parser/parser/Parser.i" +#endif /* __ACEXML_INLINE__ */ + +/*** +TO-DO: + +END-OF-LINE handling: x read quoted string + ignore whitespace + processing instruction + x element contents + +Figure out how to handle namespace here: +and when to invoke start/endPrefixMapping? + +Make sure we are freezing the obstack in all cases. + +***/ + +static const ACEXML_Char default_attribute_type[] = {'C', 'D', 'A', 'T', 'A', 0}; +static const ACEXML_Char empty_string[] = { 0 }; + +const ACEXML_Char +ACEXML_Parser::simple_parsing_name_[] = { 'S', 'i', 'm', 'p', 'l', 'e', 0 }; + +ACEXML_Parser::ACEXML_Parser (void) + : dtd_handler_ (0), + entity_resolver_ (0), + content_handler_ (0), + error_handler_ (0), + instream_ (0), + doctype_ (0), + dtd_system_ (0), + dtd_public_ (0), + simple_parsing_ (0) +{ +} + +ACEXML_Parser::~ACEXML_Parser (void) +{ +} + +int +ACEXML_Parser::getFeature (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (ACE_OS_String::strcmp (name, ACEXML_Parser::simple_parsing_name_) == 0) + return this->simple_parsing_; + + xmlenv.exception (new ACEXML_SAXNotRecognizedException ()); + return -1; +} + +void * +ACEXML_Parser::getProperty (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + // @@ Not implemented. + ACE_UNUSED_ARG (name); + + xmlenv.exception (new ACEXML_SAXNotSupportedException ()); + return 0; +} + +void +ACEXML_Parser::setFeature (const ACEXML_Char *name, + int boolean_value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (ACE_OS_String::strcmp (name, ACEXML_Parser::simple_parsing_name_) == 0) + this->simple_parsing_ = (boolean_value == 0 ? 0 : 1); + + xmlenv.exception (new ACEXML_SAXNotRecognizedException ()); +} + +void +ACEXML_Parser::setProperty (const ACEXML_Char *name, + void *value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + // @@ Not implemented. + ACE_UNUSED_ARG (name); + ACE_UNUSED_ARG (value); + + xmlenv.exception (new ACEXML_SAXNotSupportedException ()); +} + + +void +ACEXML_Parser::parse (ACEXML_InputSource *input, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (input == 0) + { + xmlenv.exception (new ACEXML_SAXException + (ACE_LIB_TEXT ("No valid input source available"))); + return; + } + + // @@ Set up Locator. + + if ((this->instream_ = input->getCharStream ()) == 0) + { + xmlenv.exception (new ACEXML_SAXException + (ACE_LIB_TEXT ("No valid input source available"))); + return; + } + + if (this->simple_parsing_ == 0) + { + this->parse_xml_prolog (xmlenv); + ACEXML_CHECK; + } + // @@ Should startDocument come before or after parsing the DTD definition? + this->content_handler_->startDocument (xmlenv); + ACEXML_CHECK; + + int doctype_defined = 0; + + for (int prolog_done = 0; prolog_done == 0; ) + { + if (this->skip_whitespace (0) != '<') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting '<'"))); + return; + + } + ACEXML_Char fwd = this->peek (); + switch (fwd) + { + case '!': + this->get (); // consume the '!' + fwd = this->peek (); + if (fwd == 'D' && !doctype_defined) // DOCTYPE + { + // This will also take care of the trailing MISC block if any. + this->parse_doctypedecl (xmlenv); + ACEXML_CHECK; + doctype_defined = 1; + break; + } + else if (fwd == '-') // COMMENT + { + if (this->grok_comment () < 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid comment"))); + return; + } + } + else + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Duplicate DOCTYPE definitions"))); + return; + } + break; + case '?': + this->parse_processing_instruction (xmlenv); + ACEXML_CHECK; + break; + case 0: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + break; + default: // Root element begins + prolog_done = 1; + break; + } + } + + // Now parse root element. + this->parse_element (1, xmlenv); + ACEXML_CHECK; + + this->content_handler_->endDocument (xmlenv); + // ACEXML_CHECK; +} + +void +ACEXML_Parser::parse (const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // @@ Not implemented. + ACE_UNUSED_ARG (systemId); + + xmlenv.exception (new ACEXML_SAXNotSupportedException ()); + return ; +} + + +ACEXML_Char +ACEXML_Parser::skip_whitespace (ACEXML_Char **whitespace) +{ + ACEXML_Char ch = this->get (); + + if (this->is_whitespace (ch) == 0) + { + if (whitespace != 0) + *whitespace = 0; + return ch; + } + + do + { + if (whitespace != 0) + this->obstack_.grow (ch); + ch = this->get (); + } + while (this->is_whitespace (ch)); + + if (whitespace != 0) + *whitespace = this->obstack_.freeze (); + + return ch; +} + +int +ACEXML_Parser::skip_whitespace_count (ACEXML_Char *peeky) +{ + int wscount = 0; + ACEXML_Char dummy; + ACEXML_Char &forward = (peeky == 0 ? dummy : *peeky); + + for (;this->is_whitespace ((forward = this->peek ())); ++wscount) + this->get (); + + return wscount; +} + +void +ACEXML_Parser::parse_xml_prolog (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->get () != '<' || + this->get () != '?' || + this->get () != 'x' || + this->get () != 'm' || + this->get () != 'l') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + + ACEXML_Char *astring; + + if (this->skip_whitespace (0) != 'v' || // Discard whitespace + this->get () != 'e' || + this->get () != 'r' || + this->get () != 's' || + this->get () != 'i' || + this->get () != 'o' || + this->get () != 'n' || + this->skip_equal () != 0 || + this->get_quoted_string (astring) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + + // @@ Handle version number here. + + int xmldecl_state = 0; + int seen_encoding = 0; + + while (1) + { + ACEXML_Char fwd = this->peek (); + if (fwd != '?') + { + fwd = this->skip_whitespace (0); // Discard whitespace + if (fwd == '?') + { + // Do nothing. Fall down to consume the '?' + // and wrap up the XML Decl parsing. + } + else if (xmldecl_state == 0 && fwd == 'e') + { + if (this->get () == 'n' && + this->get () == 'c' && + this->get () == 'o' && + this->get () == 'd' && + this->get () == 'i' && + this->get () == 'n' && + this->get () == 'g' && + this->skip_equal () == 0 && + this->get_quoted_string (astring) == 0) + { + seen_encoding = 1; + // @@ Handle encoding here. We don't handle + // various encodings for this parser. + + continue; + } + else + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + } + else if (xmldecl_state < 2 && fwd == 's') + { + if (this->get () == 't' && + this->get () == 'a' && + this->get () == 'n' && + this->get () == 'd' && + this->get () == 'a' && + this->get () == 'l' && + this->get () == 'o' && + this->get () == 'n' && + this->get () == 'g' && + this->skip_equal () == 0 && + this->get_quoted_string (astring) == 0) + { + xmldecl_state = 2; + if (ACE_OS::strcmp (astring, ACE_LIB_TEXT ("yes")) == 0) + { + // @@ This is a standalone XML file. + continue; + } + else if (ACE_OS::strcmp (astring, ACE_LIB_TEXT ("no")) == 0) + { + // @@ This is not a stand alone XML file. + continue; + } + } + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + else + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + } + + + this->get (); // consume '?' + + if (this->get() != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unrecognized XML Decl"))); + return; + } + return; + } + // End parsing XML Decl. +} + +int +ACEXML_Parser::grok_comment (void) +{ + /// Simply filter out all the comment + int state = 0; + + if (this->get () != '-' || // Skip the opening "<!--" + this->get () != '-' || // completely. + this->get () == '-') // and at least something not '-'. + return -1; + + while (state < 3) // Waiting for the trailing three + // character '-->'. Notice that + // according to the spec, '--->' + // is not a valid closing comment + // sequence. But we'll let it pass + // anyway. + { + ACEXML_Char fwd = this->get (); + if ((fwd == '-' && state < 2) || + (fwd == '>' && state == 2)) + state += 1; + else + state = 0; // Reset parse state. + } + return 0; +} + +ACEXML_Char * +ACEXML_Parser::read_name (ACEXML_Char ch) +{ + if (ch == 0) + { + ch = this->get (); + + if (this->is_whitespace (ch)) + // No white space is allowed here. + return 0; + } + else if (this->is_nonname (ch)) + return 0; + + while (1) + { + this->obstack_.grow (ch); + ch = this->peek (); + if (this->is_nonname (ch)) + break; + ch = this->get (); + }; + + return this->obstack_.freeze (); +} + +int +ACEXML_Parser::parse_processing_instruction (ACEXML_Env &xmlenv) +{ + if (this->get () != '?') + { // How did we get here? + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal error"))); + return -1; + } + const ACEXML_Char *pitarget = this->read_name (); + ACEXML_Char *instruction = 0; + + if (ACE_OS_String::strcasecmp (ACE_LIB_TEXT ("xml"), pitarget) != 0) + { // Invalid PITarget name. + xmlenv.exception + (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("PITarget name cannot start with 'xml'"))); + return -1; + } + + int state = 0; + ACEXML_Char ch = this->skip_whitespace (0); + + while (state < 2) + { + switch (ch) + { + case '?': + if (state == 0) + state = 1; + break; + case '>': + if (state == 1) + { + instruction = this->obstack_.freeze (); + this->content_handler_->processingInstruction (pitarget, + instruction, + xmlenv); + ACEXML_CHECK_RETURN (-1); + return 0; + } + break; + case 0x0D: // End-of-Line handling + ch = (this->peek () == 0x0A ? this->get () : 0x0A); + // Fall thru... + default: + if (state == 1) + this->obstack_.grow ('?'); + this->obstack_.grow (ch); + state = 0; + } + ch = this->get (); + } + return -1; +} + +int +ACEXML_Parser::parse_doctypedecl (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->get () != 'D' || + this->get () != 'O' || + this->get () != 'C' || + this->get () != 'T' || + this->get () != 'Y' || + this->get () != 'P' || + this->get () != 'E') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword 'DOCTYPE'"))); + return -1; + } + + ACEXML_Char nextch = this->skip_whitespace (0); + if (nextch == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting a DOCTYPE name"))); + return -1; + } + + this->doctype_ = this->read_name (nextch); + + this->skip_whitespace_count (&nextch); + + if (nextch == 'S' || nextch == 'P') // ExternalID defined + { + this->parse_external_id_and_ref (this->dtd_public_, + this->dtd_system_, + xmlenv); + if (xmlenv.exception () != 0) + return -1; + else if (this->dtd_public_ == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("ACEXML Parser got external DTD id: SYSTEM %s\n"), + this->dtd_system_)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("==> ACEXML Parser got DTD external id: PUBLIC %s %s\n"), + this->dtd_public_, this->dtd_system_)); + } + + nextch = this->skip_whitespace (0); + switch (nextch) + { + case '[': // Internal DTD definitionl + if (this->parse_internal_dtd (xmlenv) < 0) + return -1; // Error in markupdecl + break; + case '>': // End of DTD definition + // this is an XML document without a dectypedecl. + return 0; + case '0': + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + return -1; + default: + break; + } + + if (this->skip_whitespace (0) != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal error"))); + return -1; + } + return 0; +} + +void +ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // Parse STag. + + const ACEXML_Char *startname = this->read_name (); + + if (startname == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + return; + } + + if (is_root && + this->doctype_ != 0 && + ACE_OS_String::strcmp (startname, this->doctype_) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Root element missing."))); + return; + } + + const ACEXML_Char *endname = 0; + ACEXML_AttributesImpl attributes; + ACEXML_Char ch; + int new_namespace = 0; + const ACEXML_Char *ns_uri, *ns_lname; // namespace URI and localName + + for (int start_element_done = 0; start_element_done == 0;) + { + ch = this->skip_whitespace (0); + + switch (ch) + { + case 0: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal error"))); + return; + + case '/': + if (this->get () != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expectint '>'"))); + return; + } + else + { + this->xml_namespace_.processName (startname, ns_uri, ns_lname, 0); + this->content_handler_->startElement (ns_uri, + ns_lname, + startname, + &attributes, + xmlenv); + ACEXML_CHECK; + this->content_handler_->endElement (ns_uri, ns_lname, startname, xmlenv); + ACEXML_CHECK; + } + if (new_namespace != 0) + this->xml_namespace_.popContext (); + return; + + case '>': + this->xml_namespace_.processName (startname, ns_uri, ns_lname, 0); + this->content_handler_->startElement (ns_uri, + ns_lname, + startname, + &attributes, + xmlenv); + ACEXML_CHECK; + start_element_done = 1; + break; + default: + { + ACEXML_Char *attvalue = 0; + ACEXML_Char *attname = this->read_name (ch); + + if (attname == 0 || + this->skip_equal () != 0 || + this->get_quoted_string (attvalue) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading attribute"))); + return; + } + + // Handling new namespace if any. Notice that the order of namespace + // declaration does matter. + if (attname[0] == 'x' && + attname[1] == 'm' && + attname[2] == 'l' && + attname[3] == 'n' && + attname[4] == 's') + { + if (new_namespace == 0) + { + this->xml_namespace_.pushContext (); + new_namespace = 1; + } + + ACE_Tokenizer ns_att (attname); + ns_att.delimiter_replace (':', 0); + ACEXML_Char *xmlns_prefix, *ns_name; + + xmlns_prefix = ns_att.next (); + ns_name = ns_att.next (); + + if (ns_name == 0) + { + // @@ Check return value? + this->xml_namespace_.declarePrefix (empty_string, + attvalue); + } + else + { + // @@ Check return value? + this->xml_namespace_.declarePrefix (ns_name, + attvalue); + } + } + else + { + const ACEXML_Char *uri, *lName; + this->xml_namespace_.processName (attname, uri, lName, 1); + + attributes.addAttribute (uri, + lName, + attname, + default_attribute_type, + attvalue); + } + } + break; + } + } + + ACEXML_Char *cdata; + size_t cdata_length = 0; + + // Parse element contents. + while (1) + { + ch = this->get (); + + switch (ch) + { + case 0: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal error"))); + return; + + case '<': + // Push out old 'characters' event. + if (cdata_length != 0) + { + cdata = this->obstack_.freeze (); + this->content_handler_->characters (cdata, + 0, + cdata_length, + xmlenv); + ACEXML_CHECK; + cdata_length = 0; + } + + switch (this->peek ()) + { + case '!': // a comment or a CDATA section. + this->get (); // consume '!' + ch = this->peek (); + if (ch == '-') // a comment + { + if (this->grok_comment () < 0) + { + xmlenv.exception + (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error parsing comment"))); + return ; + } + } + else if (ch == '[') // a CDATA section. + { + this->parse_cdata (xmlenv); + ACEXML_CHECK; + } + else + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected character"))); + return; + } + break; + case '?': // a PI. + this->parse_processing_instruction (xmlenv); + ACEXML_CHECK; + break; + case '/': // an ETag. + this->get (); // consume '/' + endname = this->read_name (); + if (endname == 0 || + ACE_OS_String::strcmp (startname, endname) != 0) + { + xmlenv.exception + (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Mismatched End-tag encountered"))); + return ; + } + if (this->skip_whitespace (0) != '>') + { + xmlenv.exception + (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting '>' in an end-tag"))); + return; + } + this->content_handler_->endElement (ns_uri, + ns_lname, + endname, + xmlenv); + ACEXML_CHECK; + + if (new_namespace != 0) + this->xml_namespace_.popContext (); + return; + + default: // a new nested element? + this->parse_element (0, xmlenv); + ACEXML_CHECK; + break; + } + break; + case '&': + { + const ACEXML_String *replace = 0; + ACEXML_String charval; + ACEXML_Char buffer[6]; + + if (this->peek () == '#') + { + if (this->parse_char_reference (buffer, 6) != 0) + { + // not referring to any character exception? + return; + } + charval.set (buffer, 0); + replace = &charval; + } + else + replace = this->parse_reference (); + + if (replace == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal Error?"))); + return; + } + if (this->try_grow_cdata (replace->length (), cdata_length, xmlenv) == 0) + { + cdata_length = replace->length (); + for (size_t i = 0; i < replace->length (); ++i) + this->obstack_.grow ((*replace)[i]); + } + else + return; + } + break; + case 0x0D: // End-of-Line handling + ch = (this->peek () == 0x0A ? this->get () : 0x0A); + // Fall thru... + default: + ++cdata_length; + cdata = this->obstack_.grow (ch); + if (cdata == 0) + { + cdata = this->obstack_.freeze (); + this->content_handler_->characters (cdata, + 0, + cdata_length, + xmlenv); + ACEXML_CHECK; + this->obstack_.grow (ch); + cdata_length = 1; // the missing char. + } + } + } + +} + +int +ACEXML_Parser::parse_char_reference (ACEXML_Char *buf, size_t len) +{ + if (this->get () != '#') + { + // Internal error. + return -1; + } + + int hex = 0; + + if (this->peek () == 'x') + { + hex = 1; + this->get (); + } + + int more_digit = 0; + ACEXML_UCS4 sum = 0; + + while (1) + { + ACEXML_Char ch = this->get (); + switch (ch) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + sum = sum * (hex ? 16 : 10) + (ch - '0'); + break; + case 'a': + case 'A': + if (!hex) + return -1; + sum = sum * 16 + 10; + break; + case 'b': + case 'B': + if (!hex) + return -1; + sum = sum * 16 + 11; + break; + case 'c': + case 'C': + if (!hex) + return -1; + sum = sum * 16 + 12; + break; + case 'd': + case 'D': + if (!hex) + return -1; + sum = sum * 16 + 13; + break; + case 'e': + case 'E': + if (!hex) + return -1; + sum = sum * 16 + 14; + break; + case 'f': + case 'F': + if (!hex) + return -1; + sum = sum * 16 + 15; + break; + case ';': + if (more_digit == 0) // no digit exist??? + return -1; + int clen; +#if defined (ACE_USES_WCHAR) // UTF-16 + if ((clen = ACEXML_Transcoder::ucs42utf16 (sum, buf, len)) < 0) + return -1; + +#elif 1 // or UTF-8 + if ((clen = ACEXML_Transcoder::ucs42utf8 (sum, buf, len)) < 0) + return -1; +#elif 0 // UCS 4, not likely + buf [0] = sum; + buf [1] = 0; +#endif + buf [clen] = 0; + return 0; + default: + return -1; + } + more_digit = 1; + } + return -1; +} + +const ACEXML_String * +ACEXML_Parser::parse_reference (void) +{ + // @@ We'll use a temporary buffer here as the Obstack are most likely + // be in use when we come here. This put a limit on the max length of + // a reference. + ACEXML_Char ref[MAXPATHLEN]; + + size_t loc = 0; + + while (loc < MAXPATHLEN -1) + { + ACEXML_Char ch = this->get (); + if (ch == ';') + { + ref[loc] = 0; + break; + } + else + ref[loc++] = ch; + } + + return this->entities_.resolve_entity (ref); +} + +int +ACEXML_Parser::parse_cdata (ACEXML_Env &xmlenv) +{ + if (this->get () != '[' || + this->get () != 'C' || + this->get () != 'D' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'A' || + this->get () != '[') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("'[CDATA[' expected"))); + return -1; + } + + int parse_state = 0; + size_t datalen = 0; + + while (1) + { + ACEXML_Char ch; + ACEXML_Char *cdata; + + ch = this->get (); + // Anything goes except the sequence "]]>". + switch (parse_state) + { + case 2: + if (ch == ']') + { + parse_state = 3; + continue; + } + break; + case 3: + if (ch == '>') // Yay! + { + cdata = this->obstack_.freeze (); + this->content_handler_->characters (cdata, + 0, + datalen, + xmlenv); + // ACEXML_CHECK_RETURN (-1); + return 0; + } + break; + default: + if (ch == ']') + { + parse_state = 2; + continue; + } + else + parse_state = 1; + } + while (parse_state > 0) + { + if (this->try_grow_cdata (1, datalen, xmlenv) < 0) + return -1; + + if (parse_state != 1) + this->obstack_.grow (']'); + else + { + if (ch == 0x0D) + ch = (this->peek () == 0x0A ? this->get () : 0x0A); + this->obstack_.grow (ch); + } + ++datalen; + --parse_state; + } + }; + ACE_NOTREACHED (return -1); +} + +int +ACEXML_Parser::try_grow_cdata (size_t size, size_t &len, ACEXML_Env &xmlenv) +{ + if (this->obstack_.request (size) != 0) + { + if (len != 0) + { + ACEXML_Char *cdata = this->obstack_.freeze (); + if (cdata == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal Error growing CDATA buffer"))); + return -1; + } + this->content_handler_->characters (cdata, + 0, + len, + xmlenv); + ACEXML_CHECK_RETURN (-1); + len = 0; // reset counter + if (this->obstack_.request (size) == 0) + return 0; + } + + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Internal error, buffer overflowed"))); + return -1; + } + return 0; +} + +int +ACEXML_Parser::skip_equal (void) +{ + if (this->skip_whitespace (0) != '=') + return -1; + + while (this->is_whitespace (this->peek ())) + this->get (); + return 0; +} + +int +ACEXML_Parser::get_quoted_string (ACEXML_Char *&str) +{ + ACEXML_Char quote = this->get (); + if (quote != '\'' && quote != '"') // Not a quoted string found. + return -1; + + while (1) + { + ACEXML_Char ch = this->get (); + + // @@ Deoes not handle buffer overflow yet. + if (ch == quote) + { + str = this->obstack_.freeze (); + return 0; + } + + const ACEXML_String *replace = 0; + ACEXML_String charval; + ACEXML_Char buffer[6]; + size_t i = 0; + + switch (ch) + { + case '&': + + if (this->peek () == '#') + { + if (this->parse_char_reference (buffer, 6) != 0) + { + // xmlenv.exception (new ACEXML_SAXParseException + //(ACE_LIB_TEXT ("CharRef does not resolves to a valid character"))); + return -1; + } + charval.set (buffer, 0); + replace = &charval; + } + else + replace = this->parse_reference (); + + if (replace == 0) + { + // xmlenv.exception (new ACEXML_SAXParseException + // (ACE_LIB_TEXT ("Undefined reference"))); + return -1; + } + for (i = 0; i < replace->length (); ++i) + this->obstack_.grow ((*replace)[i]); + // handle reference here. + break; + case 0x0D: // End-of-Line handling + ch = (this->peek () == 0x0A ? this->get () : 0x0A); + // Fall thru... + default: + this->obstack_.grow (ch); + break; + } + } +} + +int +ACEXML_Parser::parse_internal_dtd (ACEXML_Env &xmlenv) +{ + ACEXML_Char nextch = this->skip_whitespace (0); + + do { + switch (nextch) + { + case '<': // Start of markup Decl. + nextch = this->peek (); + switch (nextch) + { + case '!': + this->get (); // Discard '!' + nextch = this->peek (); + switch (nextch) + { + case 'E': // An ELEMENT or ENTITY decl + this->get (); + nextch = this->peek (); + switch (nextch) + { + case 'L': + if (this->parse_element_decl (xmlenv) < 0) + return -1; + break; + + case 'N': + if (this->parse_entity_decl (xmlenv) < 0) + return -1; + break; + + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid keyword in decl spec"))); + return -1; + } + break; + + case 'A': // An ATTLIST decl + if (this->parse_attlist_decl (xmlenv) < 0) + return -1; + break; + + case 'N': // A NOTATION decl + if (this->parse_notation_decl (xmlenv) < 0) + return -1; + break; + + case '-': // a comment. + if (this->grok_comment () < 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error parsing comment"))); + return -1; + } + break; + case 0: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + return -1; + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid char. follows '<!' in markupdecl"))); + return -1; + } + break; + + case '?': // PI + this->parse_processing_instruction (xmlenv); + ACEXML_CHECK_RETURN (-1); + break; + + case 0: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + return -1; + + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid char. follow '<' in markupdecl"))); + return -1; + } + break; + + case '%': // DeclSep. Define new PEreference... + break; + + case ']': // End of internal definitions. + return 0; // Not applicable when parsing external DTD spec. + + case 0: // This may not be an error if we decide + // to generalize this function to handle both + // internal and external DTD definitions. + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpected EOF"))); + return -1; + + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting markupdecl or DecSep"))); + return -1; + }; + + // To fully conform with the spec., whitespaces are only allowed + // following a 'DeclSep' section. However, I found it + // hard/impossible to eliminate all the whitespaces between + // markupdecls. + + nextch = this->skip_whitespace (0); + + } while (1); + + ACE_NOTREACHED (return -1;) +} + +int +ACEXML_Parser::parse_element_decl (ACEXML_Env &xmlenv) +{ + if (this->get () != 'L' || + this->get () != 'E' || + this->get () != 'M' || + this->get () != 'E' || + this->get () != 'N' || + this->get () != 'T' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ELEMENT'"))); + return -1; + } + + ACEXML_Char *element_name = this->read_name (); + if (element_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading element name while defining ELEMENT."))); + return -1; + } + + ACEXML_Char nextch ; + this->skip_whitespace_count (&nextch); + + switch (nextch) + { + case 'E': // EMPTY + if (this->get () != 'E' || + this->get () != 'M' || + this->get () != 'P' || + this->get () != 'T' || + this->get () != 'Y') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `EMPTY' in ELEMENT definition."))); + return -1; + } + break; + case 'A': // ANY + if (this->get () != 'A' || + this->get () != 'N' || + this->get () != 'Y') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ANY' in ELEMENT definition."))); + return -1; + } + break; + case '(': // children + this->parse_children_definition (xmlenv); + if (xmlenv.exception () != 0) + return -1; + break; + default: // error + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading ELEMENT definition."))); + return -1; + } + if (this->skip_whitespace (0) != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting '>' in ELEMENT definition."))); + return -1; + } + return 0; +} + +int +ACEXML_Parser::parse_entity_decl (ACEXML_Env &xmlenv) +{ + ACEXML_Char nextch; + + if (this->get () != 'N' || + this->get () != 'T' || + this->get () != 'I' || + this->get () != 'T' || + this->get () != 'Y' || + this->skip_whitespace_count (&nextch) == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ENTITY'"))); + return -1; + } + + int is_GEDecl = 1; + if (nextch == '%') // This is a PEDecl. + { + is_GEDecl = 0; + this->get (); // consume the '%' + if (this->skip_whitespace_count (&nextch) == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Can't use a reference when defining entity name"))); + return -1; + } + } + + ACEXML_Char *entity_name = this->read_name (); + if (entity_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading ENTITY name."))); + return -1; + } + + this->skip_whitespace_count (&nextch); + + if (nextch == '\'' || nextch == '"') + { + ACEXML_Char *entity_value = 0; + + if (this->get_quoted_string (entity_value) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading ENTITY value."))); + return -1; + } + + if (is_GEDecl) + { + if (this->entities_.add_entity (entity_name, entity_value) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error storing entity definition (duplicate definition?)"))); + return -1; + } + } + else + { + // @@ need to implement PEdecl lookup mechanism + xmlenv.exception (new ACEXML_SAXNotSupportedException ()); + return -1; + } + } + else + { + ACEXML_Char *systemid, *publicid; + + this->parse_external_id_and_ref (publicid, systemid, xmlenv); + if (xmlenv.exception () != 0) + return -1; + + if (systemid == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid ExternalID definition (system ID missing.)"))); + return -1; + } + + this->skip_whitespace_count (&nextch); + if (nextch == 'N') // NDATA section followed + { + if (is_GEDecl == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Unexpecting keyword NDATA in PEDecl."))); + return -1; + } + + if (this->get () != 'N' || + this->get () != 'D' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'A' || + this->skip_whitespace_count (&nextch) == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword NDATA."))); + return -1; + } + + ACEXML_Char *ndata = this->read_name (); + this->dtd_handler_->unparsedEntityDecl (entity_name, + publicid, + systemid, + ndata, + xmlenv); + if (xmlenv.exception () != 0) + return -1; + } + else + { + // @@ Need to support external CharStream sources + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("ENTITY: (%s) "), + entity_name)); + + if (publicid == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("SYSTEM %s\n"), + systemid)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("PUBLIC %s %s\n"), + publicid, systemid)); + } + } + + // End of ENTITY definition + if (this->skip_whitespace (0) != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting end of ENTITY definition."))); + return -1; + } + return 0; +} + +int +ACEXML_Parser::parse_attlist_decl (ACEXML_Env &xmlenv) +{ + if (this->get () != 'A' || + this->get () != 'T' || + this->get () != 'T' || + this->get () != 'L' || + this->get () != 'I' || + this->get () != 'S' || + this->get () != 'T' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ATTLIST'"))); + return -1; + } + + ACEXML_Char *element_name = this->read_name (); + if (element_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading element name while defining ATTLIST."))); + return -1; + } + + ACEXML_Char nextch = this->skip_whitespace (0); + + // Parse AttDef* + while (nextch != '>') + { + // Parse attribute name + ACEXML_Char *att_name = this->read_name (nextch); + if (att_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading attribute name while defining ATTLIST."))); + return -1; + } + + /* + Parse AttType: + Possible keywords: + CDATA // StringType + ID // TokenizedType + IDREF + IDREFS + ENTITY + ENTITIES + NMTOKEN + NMTOKENS + NOTATION // EnumeratedType - NotationTYpe + ( // EnumeratedType - Enumeration + */ + nextch = this->skip_whitespace (0); + switch (nextch) + { + case 'C': // CDATA + if (this->get () != 'D' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'A' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `CDATA' while defining ATTLIST."))); + return -1; + } + // Else, we have successfully identified the type of the attribute as CDATA + // @@ Set up validator appropriately here. + break; + case 'I': // ID, IDREF, or, IDREFS + if (this->get () == 'D') + { + if (this->skip_whitespace_count (&nextch) > 0) + { + // We have successfully identified the type of the attribute as ID + // @@ Set up validator as such. + break; + } + if (this->get () == 'R' && + this->get () == 'E' && + this->get () == 'F') + { + if (this->skip_whitespace_count (&nextch) > 0) + { + // We have successfully identified the type of + // the attribute as IDREF + // @@ Set up validator as such. + break; + } + else if (nextch == 'S' && + this->get () && // consume the 'S' + this->skip_whitespace_count () != 0) + { + // We have successfully identified the type of + // the attribute as IDREFS + // @@ Set up validator as such. + break; + } + } + } + // Admittedly, this error message is not precise enough + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ID', `IDREF', or `IDREFS' while defining ATTLIST."))); + return -1; + case 'E': // ENTITY or ENTITIES + if (this->get () == 'N' && + this->get () == 'T' && + this->get () == 'I' && + this->get () == 'T') + { + nextch = this->get (); + if (nextch == 'Y') + { + // We have successfully identified the type of + // the attribute as ENTITY + // @@ Set up validator as such. + } + else if (nextch == 'I'&& + this->get () == 'E' && + this->get () == 'S') + { + // We have successfully identified the type of + // the attribute as ENTITIES + // @@ Set up validator as such. + } + if (this->skip_whitespace_count () > 0) + { + // success + break; + } + } + // Admittedly, this error message is not precise enough + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `ENTITY', or `ENTITIES' while defining ATTLIST."))); + return -1; + case 'N': // NMTOKEN, NMTOKENS, or, NOTATION + nextch = this->get (); + if (nextch != 'M' || nextch != 'O') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `NMTOKEN', `NMTOKENS', or `NOTATION' while defining ATTLIST."))); + return -1; + } + if (nextch == 'M') + { + if (this->get () == 'T' && + this->get () == 'O' && + this->get () == 'K' && + this->get () == 'E' && + this->get () == 'N') + { + if (this->skip_whitespace_count (&nextch) > 0) + { + // We have successfully identified the type of + // the attribute as NMTOKEN + // @@ Set up validator as such. + break; + } + else if (nextch == 'S' && this->skip_whitespace_count () > 0) + { + // We have successfully identified the type of + // the attribute as NMTOKENS + // @@ Set up validator as such. + break; + } + } + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `NMTOKEN' or `NMTOKENS' while defining ATTLIST."))); + return -1; + } + else // NOTATION + { + if (this->get () != 'T' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'I' || + this->get () != 'O' || + this->get () != 'N' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `NOTATION' while defining ATTLIST."))); + return -1; + } + + if (this->get () != '(') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting `(' following NOTATION while defining ATTLIST."))); + return -1; + } + + this->skip_whitespace_count (); + + do { + ACEXML_Char *notation_name = this->read_name (); + if (notation_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading NOTATION name while defining ATTLIST."))); + return -1; + } + // @@ get another notation name, set up validator as such + this->skip_whitespace_count (&nextch); + } while (nextch != ')'); + + this->get (); // consume the closing paren. + this->skip_whitespace_count (); + } + break; + case '(': // EnumeratedType - Enumeration + this->skip_whitespace_count (); + + do { + ACEXML_Char *token_name = this->read_name (); // @@ need a special read_nmtoken? + if (token_name == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading enumerated nmtoken name while defining ATTLIST."))); + return -1; + } + // @@ get another nmtoken, set up validator as such + this->skip_whitespace_count (&nextch); + } while (nextch != ')'); + + this->get (); // consume the closing paren. + this->skip_whitespace_count (); + break; + default: + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid Attribute Type while defining ATTLIST."))); + return -1; + } + break; + } + + /* + Parse DefaultDecl: + #REQUIRED + #IMPLIED + #FIXED + quoted string // #FIXED + */ + nextch = this->peek (); + switch (nextch) + { + case '#': + this->get (); // consume the '#' + switch (this->get ()) + { + case 'R': + if (this->get () != 'E' || + this->get () != 'Q' || + this->get () != 'U' || + this->get () != 'I' || + this->get () != 'R' || + this->get () != 'E' || + this->get () != 'D') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `#REQUIRED' while defining ATTLIST."))); + return -1; + } + // We now know this attribute is required + // @@ Set up the validator as such. + break; + case 'I': + if (this->get () != 'M' || + this->get () != 'P' || + this->get () != 'L' || + this->get () != 'I' || + this->get () != 'E' || + this->get () != 'D') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `#IMPLIED' while defining ATTLIST."))); + return -1; + } + // We now know this attribute is impleid. + // @@ Set up the validator as such. + break; + case 'F': + if (this->get () != 'I' || + this->get () != 'X' || + this->get () != 'E' || + this->get () != 'D' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `#FIXED' while defining ATTLIST."))); + return -1; + } + // We now know this attribute is fixed. + + ACEXML_Char *fixed_attr; + if (this->get_quoted_string (fixed_attr) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error parsing `#FIXED' attribute value while defining ATTLIST."))); + return -1; + } + // @@ set up validator + break; + default: + break; + } + break; + case '\'': + case '"': + ACEXML_Char *fixed_attr; + if (this->get_quoted_string (fixed_attr) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error parsing `#FIXED' attribute value while defining ATTLIST."))); + return -1; + } + // @@ set up validator + break; + default: + break; + } + this->skip_whitespace_count (&nextch); + }; + + this->get (); // consume closing '>' + + return 0; +} + +int +ACEXML_Parser::parse_notation_decl (ACEXML_Env &xmlenv) +{ + if (this->get () != 'N' || + this->get () != 'O' || + this->get () != 'T' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'I' || + this->get () != 'O' || + this->get () != 'N' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `NOTATION'"))); + return -1; + } + + ACEXML_Char *notation = this->read_name (); + if (notation == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Invalid notation name."))); + return -1; + } + + this->skip_whitespace_count (); + ACEXML_Char *systemid, *publicid; + + this->parse_external_id_and_ref (publicid, systemid, xmlenv); + if (xmlenv.exception () != 0) + return -1; + + if (this->get () != '>') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting NOTATION closing '>'."))); + return -1; + } + + this->dtd_handler_->notationDecl (notation, + publicid, + systemid, + xmlenv); + if (xmlenv.exception () != 0) + return -1; + + return 0; +} + +int +ACEXML_Parser::parse_external_id_and_ref (ACEXML_Char *&publicId, + ACEXML_Char *&systemId, + ACEXML_Env &xmlenv) +{ + publicId = systemId = 0; + ACEXML_Char nextch = this->get (); + + switch (nextch) + { + case 'S': // External SYSTEM id. + if (this->get () != 'Y' || + this->get () != 'S' || + this->get () != 'T' || + this->get () != 'E' || + this->get () != 'M' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword 'SYSTEM'"))); + return -1; + } + if (this->get_quoted_string (systemId) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error while parsing SYSTEM literal for SYSTEM id."))); + return -1; + } + break; + case 'P': // External PUBLIC id or previously defined PUBLIC id. + if (this->get () != 'U' || + this->get () != 'B' || + this->get () != 'L' || + this->get () != 'I' || + this->get () != 'C' || + this->skip_whitespace_count () == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword 'PUBLIC'"))); + return -1; + } + if (this->get_quoted_string (publicId) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error while parsing public literal for PUBLIC id."))); + return -1; + } + + this->skip_whitespace_count (&nextch); + if (nextch == '\'' || nextch == '"') // not end of NOTATION yet. + { + if (this->get_quoted_string (systemId) != 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error while parsing system literal for PUBLIC id."))); + return -1; + } + } + break; + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting either keyword `SYSTEM' or `PUBLIC'."))); + return -1; + } + return 0; +} + +int +ACEXML_Parser::parse_children_definition (ACEXML_Env &xmlenv) +{ + this->get (); // consume the '(' + + ACEXML_Char nextch; + int subelement_number = 0; + this->skip_whitespace_count (&nextch); + + switch (nextch) + { + case '#': // Mixed element, + if (this->get () != '#' || + this->get () != 'P' || + this->get () != 'C' || + this->get () != 'D' || + this->get () != 'A' || + this->get () != 'T' || + this->get () != 'A') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting keyword `#PCDATA' while defining an element."))); + return -1; + } + + this->skip_whitespace_count (&nextch); + + while (nextch != ')') + { + if (this->get () != '|') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting end of Mixed section while defining an element."))); + return -1; + } + this->skip_whitespace_count (); + + ACEXML_Char *name = this->read_name (); + // @@ name will be used in the Validator later. + ACE_UNUSED_ARG (name); + ++subelement_number; + // @@ Install Mixed element name into the validator. + this->skip_whitespace_count (&nextch); + } + + if (this->get () != ')' || + (subelement_number && this->get () != '*')) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting closing `)*' or ')' while defining an element."))); + return -1; + } + // @@ close the element definition in the validator. + break; + default: + if (this->parse_child (1, xmlenv) != 0 || + xmlenv.exception () != 0) + return -1; + } + + return 0; +} + +int +ACEXML_Parser::parse_child (int skip_open_paren, + ACEXML_Env &xmlenv) +{ + // Conditionally consume the open paren. + if (skip_open_paren == 0 && + this->get () != '(') + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting opening `(' while defining an element."))); + return -1; + } + + ACEXML_Char node_type = 0; + ACEXML_Char nextch; + + do { + this->skip_whitespace_count (&nextch); + switch (nextch) + { + case '(': + this->parse_child (0, xmlenv); + if (xmlenv.exception () != 0) + return -1; + break; + default: + // must be an element name here. + ACEXML_Char *subelement = this->read_name (); + if (subelement == 0) + { + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Error reading sub-element name while defining an element."))); + return -1; + } + // @@ Inform validator of the new element here. + break; + } + + this->skip_whitespace_count (&nextch); + switch (nextch) + { + case '|': + switch (node_type) + { + case 0: + node_type = '|'; + // @@ inform validator of this new type?? + break; + case '|': + break; + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting `,', `|', or `)' while defining an element."))); + return -1; + } + break; + case ',': + switch (node_type) + { + case 0: + node_type = ','; + // @@ inform validator of this new type?? + break; + case ',': + break; + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting `,', `|', or `)'while defining an element."))); + return -1; + } + case ')': + break; + default: + xmlenv.exception (new ACEXML_SAXParseException + (ACE_LIB_TEXT ("Expecting `,', `|', or `)' while defining an element."))); + return -1; + } + this->get (); // consume , | or ) + } while (nextch != ')'); + + // Check for trailing '?', '*', '+' + nextch = this->peek (); + switch (nextch) + { + case '?': + // @@ Consume the character and inform validator as such, + this->get (); + break; + case '*': + // @@ Consume the character and inform validator as such, + this->get (); + break; + case '+': + // @@ Consume the character and inform validator as such, + this->get (); + break; + default: + break; // not much to do. + } + + return 0; +} diff --git a/ACEXML/parser/parser/Parser.dsp b/ACEXML/parser/parser/Parser.dsp new file mode 100644 index 00000000000..dc6d6c6560a --- /dev/null +++ b/ACEXML/parser/parser/Parser.dsp @@ -0,0 +1,123 @@ +# Microsoft Developer Studio Project File - Name="ACEXML_Parser" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=ACEXML_Parser - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Parser.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Parser.mak" CFG="ACEXML_Parser - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "ACEXML_Parser - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "ACEXML_Parser - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "ACEXML_Parser - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_PARSER_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\.." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_PARSER_BUILD_DLL" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 ace.lib ACEXML.lib /nologo /dll /machine:I386 /out:"../../../bin/ACEXML_Parser.dll" /libpath:"../../../ace" /libpath:"../../Common"
+
+!ELSEIF "$(CFG)" == "ACEXML_Parser - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_PARSER_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\.." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ACEXML_PARSER_BUILD_DLL" /YX /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib ACEXMLd.lib /nologo /dll /debug /machine:I386 /out:"../../../bin/ACEXML_Parserd.dll" /pdbtype:sept /libpath:"../../../ace" /libpath:"../../Common"
+
+!ENDIF
+
+# Begin Target
+
+# Name "ACEXML_Parser - Win32 Release"
+# Name "ACEXML_Parser - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Entity_Manager.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Parser.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Entity_Manager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Parser.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Parser_export.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/ACEXML/parser/parser/Parser.dsw b/ACEXML/parser/parser/Parser.dsw new file mode 100644 index 00000000000..c2e1b8458e6 --- /dev/null +++ b/ACEXML/parser/parser/Parser.dsw @@ -0,0 +1,28 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Parser"=.\Parser.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
diff --git a/ACEXML/parser/parser/Parser.h b/ACEXML/parser/parser/Parser.h new file mode 100644 index 00000000000..df19607e160 --- /dev/null +++ b/ACEXML/parser/parser/Parser.h @@ -0,0 +1,469 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Parser.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_BASIC_PARSER_H_ +#define _ACEXML_BASIC_PARSER_H_ + +#include "common/XMLReader.h" +#include "common/LocatorImpl.h" +#include "common/NamespaceSupport.h" +#include "common/CharStream.h" +#include "parser/parser/Parser_export.h" +#include "ace/Obstack.h" +#include "ace/Functor.h" +#include "ace/SString.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Containers_T.h" +#include "parser/parser/Entity_Manager.h" + +/** + * @class ACEXML_Parser Parser.h "parser/parser/Parser.h" + * + * @brief A SAX based parser. + * + */ +class ACEXML_PARSER_Export ACEXML_Parser : public ACEXML_XMLReader +{ +public: + /// Default constructor. + ACEXML_Parser (void); + + /// Destructor. + virtual ~ACEXML_Parser (void); + + /* + * Return the current content handler. + */ + virtual ACEXML_ContentHandler *getContentHandler (void) const; + + /* + * Return the current DTD handler. + */ + virtual ACEXML_DTDHandler *getDTDHandler (void) const; + + /* + * Return the current entity resolver. + */ + virtual ACEXML_EntityResolver *getEntityResolver (void) const; + + /* + * Return the current error handler. + */ + virtual ACEXML_ErrorHandler *getErrorHandler (void) const; + + /** + * Look up the value of a feature. This method allows + * programmers to check whether a specific feature has been + * activated in the parser. + */ + virtual int getFeature (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) + ; + + /* + * Look up the value of a property. + */ + virtual void * getProperty (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) + ; + + /* + * Parse an XML document. + */ + virtual void parse (ACEXML_InputSource *input, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Parse an XML document from a system identifier (URI). + */ + virtual void parse (const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // @@ throw IOException??? + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Allow an application to register a content event handler. + */ + virtual void setContentHandler (ACEXML_ContentHandler *handler); + + /* + * Allow an application to register a DTD event handler. + */ + virtual void setDTDHandler (ACEXML_DTDHandler *handler); + + /* + * Allow an application to register an entity resolver. + */ + virtual void setEntityResolver (ACEXML_EntityResolver *resolver); + + /* + * Allow an application to register an error event handler. + */ + virtual void setErrorHandler (ACEXML_ErrorHandler *handler); + + /** + * Activating or deactivating a feature. + */ + virtual void setFeature (const ACEXML_Char *name, + int boolean_value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) + ; + + /* + * Set the value of a property. + */ + virtual void setProperty (const ACEXML_Char *name, + void *value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) + ; + + // *** Helper functions for parsing XML + + /** + * Skip any whitespaces encounter until the first non-whitespace + * character is encountered and consumed from the current input + * CharStream. + * + * @param whitespace Return a pointer to the string of skipped + * whitespace after proper conversion. Null if there's no + * whitespace found. + * + * @retval The first none-white space characters (which will be + * consumed from the CharStream.) If no whitespace is found, it + * will return 0. + * + * @sa skip_whitespace_count + */ + ACEXML_Char skip_whitespace (ACEXML_Char **whitespace); + + /** + * Skip any whitespaces encounter until the first non-whitespace + * character. The first non-whitespace character is not consumed. + * This method does peek into the input CharStream and therefore + * is more expensive than @ref skip_whitespace. + * + * @param peek If non-null, @a peek points to a ACEXML_Char where + * skip_whitespace_count store the first non-whitespace + * character it sees (character is not removed from the stream.) + * + * @retval The number of whitespace characters consumed. + * + * @sa skip_whitespace + */ + int skip_whitespace_count (ACEXML_Char *peek = 0); + + /** + * Check if a character @a c is a whitespace. + * + * @retval 1 if @a c is a valid white space character. 0 otherwise. + */ + int is_whitespace (ACEXML_Char c); + + /** + * Check if a character @a c is a whitespace or '='. + * + * @retval 1 if true, 0 otherwise. + */ + int is_whitespace_or_equal (ACEXML_Char c); + + /** + * Check if a character @a c is a valid character for nonterminal NAME. + * + * @retval 1 if true, 0 otherwise. + */ + int is_nonname (ACEXML_Char c); + + /** + * Skip an equal sign. + * + * @retval 0 when succeeds, -1 if no equal sign is found. + */ + int skip_equal (void); + + /** + * Get a quoted string. Quoted strings are used to specify + * attribute values and this routine will replace character and + * entity references on-the-fly. Parameter entities are not allowed + * (or replaced) in this function. (But regular entities are.) + * + * @param str returns the un-quoted string. + * + * @retval 0 on success, -1 otherwise. + */ + int get_quoted_string (ACEXML_Char *&str); + + /** + * Parse a PI statement. The first character encountered + * should always be '?' in the PI prefix "@<?". + * + * @retval 0 on success, -1 otherwise. + */ + int parse_processing_instruction (ACEXML_Env &xmlenv); + + /** + * Skip over a comment. The first character encountered + * should always be the first '-' in the comment prefix + * "@<@!--". + */ + int grok_comment (); + + /** + * Read a name from the input CharStream (until white space). + * If @a ch @!= 0, then we have already consumed the first name + * character from the input CharStream, otherwise, read_name + * will use this->get() to acquire the initial character. + * + * @retval A pointer to the string in the obstack, 0 if it's not + * a valid name. + */ + ACEXML_Char *read_name (ACEXML_Char ch = 0); + + /** + * Parse the DOCTYPE declaration. The first character encountered + * should always be 'D' in doctype prefix: "@<@!DOCTYPE". + */ + int parse_doctypedecl (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Parse an XML element. The first character encountered should + * be the first character of the element "Name". + * + * @param is_root If not 0, then we are expecting to see the "root" + * element now, and the next element's name need to match the name + * defined in DOCTYPE definition, i.e., @a this->doctype_. + * + * @todo Instead of simply checking for the root element based on the + * argument @a is_root, we should instead either pass in some sort + * of validator or allow the function to return the element name so it + * can be used in a validator. + */ + void parse_element (int is_root, ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /** + * Parse XML Prolog. + */ + void parse_xml_prolog (ACEXML_Env &xmlenv); + + /** + * Parse a character reference, i.e., " " or "". The first + * character encountered should be the '#' char. + * + * @param buf points to a character buffer for + * the result. + * @param len specifies the capacities of the buffer. + * + * @retval 0 on success and -1 otherwise. + */ + int parse_char_reference (ACEXML_Char *buf, size_t len); + + /** + * Parse an entity reference, i.e., "&". The first character + * encountered should be the character following '&'. + * + * @retval A pointer to the resolved const ACEXML_String if success + * (previously defined), 0 otherwise. + */ + const ACEXML_String *parse_reference (void); + + /** + * Parse a CDATA section. The first character should always be the first + * '[' in CDATA definition. + * + * @retval 0 on success, -1 otherwise. + */ + int parse_cdata (ACEXML_Env &xmlenv); + + /** + * Parse a "markupdecl" section, this includes both "markupdecl" and + * "DeclSep" sections in XML specification + */ + int parse_internal_dtd (ACEXML_Env &xmlenv); + + /** + * Parse an "ELEMENT" decl. The first character this method + * expects is always the 'L' (the second char) in the word + * "ELEMENT". + * + * @retval 0 on success, -1 otherwise. + */ + int parse_element_decl (ACEXML_Env &xmlenv); + + /** + * Parse an "ENTITY" decl. The first character this method expects + * is always the 'N' (the second char) in the word "ENTITY". + * + * @retval 0 on success, -1 otherwise. + */ + int parse_entity_decl (ACEXML_Env &xmlenv); + + /** + * Parse an "ATTLIST" decl. Thse first character this method + * expects is always the 'A' (the first char) in the word + * "ATTLIST". + * + * @retval 0 on success, -1 otherwise. + */ + int parse_attlist_decl (ACEXML_Env &xmlenv); + + /** + *Parse a "NOTATION" decl. The first character this method + * expects is always the 'N' (the first char) in the word + * "NOTATION". + * + * @retval 0 on success, -1 otherwise. + */ + int parse_notation_decl (ACEXML_Env &xmlenv); + + /** + * Parse an ExternalID or a reference to PUBLIC ExternalID. + * Possible cases are in the forms of: <code> + * + * SYSTEM 'quoted string representing system resource' + * PUBLIC 'quoted name of public ID' 'quoted resource' + * PUBLIC 'quoted name we are referring to' + * </code> + * + * The first character this function sees must be either 'S' or 'P'. + * When the function finishes parsing, the input stream points + * at the first non-whitespace character. + * + * @param publicID returns the unquoted publicID read. If none + * is available, it will be reset to 0. + * @param systemID returns the unquoted systemID read. If none + * is available, it will be reset to 0. + * + * @retval 0 on success, -1 otherwise. + */ + int parse_external_id_and_ref (ACEXML_Char *&publicId, + ACEXML_Char *&systemId, + ACEXML_Env &xmlenv); + + /** + * Parse the "children" and "Mixed" non-terminals in contentspec. + * + * The first character this function sees must be the first + * open paren '(' in children. + * + * @retval 0 on success, -1 otherwise. + */ + int parse_children_definition (ACEXML_Env &xmlenv); + + /** + * Parse a @c cp non-terminal. @c cp can either be a @c seq or a @c choice. + * This function calls itself recursively. + * + * @param skip_open_paren when non-zero, it indicates that the open paren of + * the @c seq or @c choice has already been removed from the input + * stream. + * + * @retval 0 on success, -1 otherwise. + */ + int parse_child (int skip_open_paren, + ACEXML_Env &xmlenv); + +protected: + /// Get a character. + ACEXML_Char get (void); + + /// Peek a character. + ACEXML_Char peek (void); + + /** + * Check if more data can be added to a character buffer in obstack. + * If not, the existing data in the buffer will be cleared out by + * freezing the segment and pass it out thru a content_handler_->characters () + * call. @a counter records the length of the existing data in + * obstack. + */ + int try_grow_cdata (size_t size, size_t &len, ACEXML_Env &xmlenv); + + // Feature names: + + /** + * \addtogroup acexml_parser_features + * @{ + */ + + /** + * @var simple_parsing_name_ + * + * This constant string defines the name of "simple XML parsing" + * feature. When this feature is enable, ACEXML parser is allowed + * to parse a simple XML stream without mandated XML prolog + * and no DTD defintion. + */ + static const ACEXML_Char simple_parsing_name_[]; + + /* @} */ + +private: + /** + * Check and dispatch errors/warnings to ErrorHandler. + * + * @retval 0 if the error/warning is handled successfully, -1, if + * the handler doesn't know how to handle the error/exceptions. + */ + int check_exception (ACEXML_Env &xmlenv); + + /// Keeping track of the handlers. We do not manage + /// the memory for handlers. + ACEXML_DTDHandler *dtd_handler_; + ACEXML_EntityResolver *entity_resolver_; + ACEXML_ContentHandler *content_handler_; + ACEXML_ErrorHandler *error_handler_; + + /// @@ Feature and properties management structure here. + /// Current input char stream. + ACEXML_CharStream *instream_; + + /// My doctype, if any. + ACEXML_Char *doctype_; + + /// External DTD System Literal, if any. + ACEXML_Char *dtd_system_; + + /// External DTD Public Literal, if any. + ACEXML_Char *dtd_public_; + + ACE_Obstack_T<ACEXML_Char> obstack_; + + ACEXML_NamespaceSupport xml_namespace_; + + ACEXML_Entity_Manager entities_; + + // Locator + ACEXML_LocatorImpl locator_; + + // Feature flags & + int simple_parsing_; + +}; + +#if defined (__ACEXML_INLINE__) +# include "parser/parser/Parser.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_BASIC_PARSER_H_ */ diff --git a/ACEXML/parser/parser/Parser.i b/ACEXML/parser/parser/Parser.i new file mode 100644 index 00000000000..e949673e0f5 --- /dev/null +++ b/ACEXML/parser/parser/Parser.i @@ -0,0 +1,144 @@ +//============================================================================= +/** + * @file Parser.i + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +ACEXML_INLINE ACEXML_ContentHandler * +ACEXML_Parser::getContentHandler (void) const +{ + return this->content_handler_; +} + +ACEXML_INLINE ACEXML_DTDHandler * +ACEXML_Parser::getDTDHandler (void) const +{ + return this->dtd_handler_; +} + +ACEXML_INLINE ACEXML_EntityResolver * +ACEXML_Parser::getEntityResolver (void) const +{ + return this->entity_resolver_; +} + +ACEXML_INLINE ACEXML_ErrorHandler * +ACEXML_Parser::getErrorHandler (void) const +{ + return this->error_handler_; +} + +ACEXML_INLINE void +ACEXML_Parser::setContentHandler (ACEXML_ContentHandler *handler) +{ + this->content_handler_ = handler; +} + +ACEXML_INLINE void +ACEXML_Parser::setDTDHandler (ACEXML_DTDHandler *handler) +{ + this->dtd_handler_ = handler; +} + +ACEXML_INLINE void +ACEXML_Parser::setEntityResolver (ACEXML_EntityResolver *resolver) +{ + this->entity_resolver_ = resolver; +} + +ACEXML_INLINE void +ACEXML_Parser::setErrorHandler (ACEXML_ErrorHandler *handler) +{ + this->error_handler_ = handler; +} + +ACEXML_INLINE int +ACEXML_Parser::is_whitespace (ACEXML_Char c) +{ + switch (c) + { + case 0x20: + case 0x9: + case 0xd: + case 0xa: + return 1; + default: + return 0; + } +} + + +ACEXML_INLINE int +ACEXML_Parser::is_whitespace_or_equal (ACEXML_Char c) +{ + switch (c) + { + case 0x20: + case 0x9: + case 0xd: + case 0xa: + case '=': + return 1; + default: + return 0; + } +} + +ACEXML_INLINE int +ACEXML_Parser::is_nonname (ACEXML_Char c) +{ + switch (c) + { + case 0x20: + case 0x9: + case 0xd: + case 0xa: + case '=': + case '/': + case '?': + case '>': + case '<': + case ')': + case '(': + case '+': + case '*': + case '\'': + case '"': + case ',': + case '|': + return 1; + default: + return 0; + } +} + +ACEXML_INLINE ACEXML_Char +ACEXML_Parser::get (void) +{ + // Using an extra level of indirection so we can + // manage document location in the future. + + if (this->instream_ != 0) + { + ACEXML_Char ch; + this->instream_->get (ch); + return ch; + } + return 0; +} + +ACEXML_INLINE ACEXML_Char +ACEXML_Parser::peek (void) +{ + // Using an extra level of indirection so we can + // manage document location in the future. + + if (this->instream_ != 0) + return this->instream_->peek (); + return 0; + +} diff --git a/ACEXML/parser/parser/Parser_export.h b/ACEXML/parser/parser/Parser_export.h new file mode 100644 index 00000000000..71630ccd962 --- /dev/null +++ b/ACEXML/parser/parser/Parser_export.h @@ -0,0 +1,47 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Parser_export.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl +// ------------------------------ +#ifndef ACEXML_PARSER_EXPORT_H +#define ACEXML_PARSER_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (ACEXML_PARSER_HAS_DLL) +# define ACEXML_PARSER_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && ACEXML_PARSER_HAS_DLL */ + +#if !defined (ACEXML_PARSER_HAS_DLL) +# define ACEXML_PARSER_HAS_DLL 1 +#endif /* ! ACEXML_PARSER_HAS_DLL */ + +#if defined (ACEXML_PARSER_HAS_DLL) && (ACEXML_PARSER_HAS_DLL == 1) +# if defined (ACEXML_PARSER_BUILD_DLL) +# define ACEXML_PARSER_Export ACE_Proper_Export_Flag +# define ACEXML_PARSER_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define ACEXML_PARSER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* ACEXML_PARSER_BUILD_DLL */ +# define ACEXML_PARSER_Export ACE_Proper_Import_Flag +# define ACEXML_PARSER_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define ACEXML_PARSER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ACEXML_PARSER_BUILD_DLL */ +#else /* ACEXML_PARSER_HAS_DLL == 1 */ +# define ACEXML_PARSER_Export +# define ACEXML_PARSER_SINGLETON_DECLARATION(T) +# define ACEXML_PARSER_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* ACEXML_PARSER_HAS_DLL == 1 */ + +#endif /* ACEXML_PARSER_EXPORT_H */ + +// End of auto generated file. |