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 | |
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')
103 files changed, 12315 insertions, 0 deletions
diff --git a/ACEXML/ACEXML.dsw b/ACEXML/ACEXML.dsw new file mode 100644 index 00000000000..9fcc6aabba2 --- /dev/null +++ b/ACEXML/ACEXML.dsw @@ -0,0 +1,59 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "ACEXML_Parser"=.\parser\parser\Parser.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name XML_Common
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "Debug_Validator"=.\PARSER\DEBUG_VALIDATOR\Debug_Validator.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "XML_Common"=.\COMMON\XML_Common.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name Debug_Validator
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/ACEXML/Makefile b/ACEXML/Makefile new file mode 100644 index 00000000000..e355ff86344 --- /dev/null +++ b/ACEXML/Makefile @@ -0,0 +1,20 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the client programs that test the ACE network services +#---------------------------------------------------------------------------- + +DIRS = common \ + parser \ + tests \ + examples + +#---------------------------------------------------------------------------- +# 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/README b/ACEXML/README new file mode 100644 index 00000000000..1e65588029e --- /dev/null +++ b/ACEXML/README @@ -0,0 +1,17 @@ +$Id$ + +ACE XML PARSER Framework README file + +* Character set + +ACE XML only deal with pure unicode encoding. I.e., ACE XML +does not care about language specific encoding information. + +* SAX - The Simple API for XML + +ACE XML Parser interfaces follows the the design of SAX 2.0, which is +a public domain specification for Java. The major difference between +ACE XML Parser interfaces and SAX is that we added an reference of +ACEXML_Env to every SAX method to accomodate platforms/compilers that +don't support C++ exceptions. SAX is defined by David Megginson +<david@megginson.com> diff --git a/ACEXML/common/ACEXML_Export.h b/ACEXML/common/ACEXML_Export.h new file mode 100644 index 00000000000..85ade891148 --- /dev/null +++ b/ACEXML/common/ACEXML_Export.h @@ -0,0 +1,53 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file ACEXML_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_EXPORT_H +#define ACEXML_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (ACEXML_HAS_DLL) +# define ACEXML_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && ACEXML_HAS_DLL */ + +#if defined (ACE_HAS_DLL) +# if !defined (ACEXML_HAS_DLL) +# define ACEXML_HAS_DLL 1 +# endif /* ! ACEXML_HAS_DLL */ +#else +# if !defined (ACEXML_HAS_DLL) +# define ACEXML_HAS_DLL 0 +# endif /* ! ACEXML_HAS_DLL */ +#endif + +#if defined (ACEXML_HAS_DLL) && (ACEXML_HAS_DLL == 1) +# if defined (ACEXML_BUILD_DLL) +# define ACEXML_Export ACE_Proper_Export_Flag +# define ACEXML_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define ACEXML_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* ACEXML_BUILD_DLL */ +# define ACEXML_Export ACE_Proper_Import_Flag +# define ACEXML_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define ACEXML_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ACEXML_BUILD_DLL */ +#else /* ACEXML_HAS_DLL == 1 */ +# define ACEXML_Export +# define ACEXML_SINGLETON_DECLARATION(T) +# define ACEXML_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* ACEXML_HAS_DLL == 1 */ + +#endif /* ACEXML_EXPORT_H */ + +// End of auto generated file. diff --git a/ACEXML/common/Attributes.h b/ACEXML/common/Attributes.h new file mode 100644 index 00000000000..1684d940872 --- /dev/null +++ b/ACEXML/common/Attributes.h @@ -0,0 +1,116 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Attributes.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_ATTRIBUTES_H_ +#define _ACEXML_ATTRIBUTES_H_ + +#include "common/XML_Types.h" + +/** + * @class ACEXML_Attributes Attributes.h "common/Attributes.h" + * + * @brief ACEXML_Attributes defines a collection of attributes of an XML element. + * + * This is an abstract class (interface in Java) that defines + * the API for accessing attributes of an XML entity. + * + * This interface allows access to a list of attributes in three different ways: + * + * - by attribute index; + * - by Namespace-qualified name; or + * - by qualified (prefixed) name. + * + * The list will not contain attributes that were declared #IMPLIED + * but not specified in the start tag. It will also not contain + * attributes used as Namespace declarations (xmlns*) unless the + * http://xml.org/sax/features/namespace-prefixes feature is set to + * true (it is false by default). + * + * If the namespace-prefixes feature (see above) is false, access by + * qualified name may not be available; if the + * http://xml.org/sax/features/namespaces feature is false, access by + * Namespace-qualified names may not be available. + * + * This interface replaces the now-deprecated SAX1 AttributeList + * interface, which does not contain Namespace support. In addition to + * Namespace support, it adds the getIndex methods (below). + * + * The order of attributes in the list is unspecified, and will vary + * from implementation to implementation. + */ +class ACEXML_Export ACEXML_Attributes +{ +public: + /** + * Look up the index of an attribute by XML 1.0 qualified name. + */ + virtual int getIndex (const ACEXML_Char *qName) = 0; + + /** + * Look up the index of an attribute by Namespace name. + */ + virtual int getIndex (const ACEXML_Char *uri, + const ACEXML_Char *localPart) = 0; + + /** + * Return the number of attributes in the list. + */ + virtual size_t getLength (void) = 0; + + /** + * Look up an attribute's local name by index. + */ + virtual const ACEXML_Char *getLocalName (size_t index) = 0; + + /** + * Look up an attribute's XML 1.0 qualified name by index. + */ + virtual const ACEXML_Char *getQName (size_t index) = 0; + + /** + * Look up an attribute's type by index. + */ + virtual const ACEXML_Char *getType (size_t index) = 0; + + /** + * Look up an attribute's type by XML 1.0 qualified name. + */ + virtual const ACEXML_Char *getType (const ACEXML_Char *qName) = 0; + + /** + * Look up an attribute's type by Namespace name. + */ + virtual const ACEXML_Char *getType (const ACEXML_Char *uri, + const ACEXML_Char *localPart) = 0; + + /** + * Look up an attribute's Namespace URI by index. + */ + virtual const ACEXML_Char *getURI (size_t index) = 0; + + /** + * Look up an attribute's value by index. + */ + virtual const ACEXML_Char *getValue (size_t index) = 0; + + /** + * Look up an attribute's value by XML 1.0 qualified name. + */ + virtual const ACEXML_Char *getValue (const ACEXML_Char *qName) = 0; + + /** + * Look up an attribute's value by Namespace name. + */ + virtual const ACEXML_Char *getValue (const ACEXML_Char *uri, + const ACEXML_Char *localPart) = 0; +}; +#endif /* _ACEXML_ ATTRIBUTES_H_ */ diff --git a/ACEXML/common/AttributesImpl.cpp b/ACEXML/common/AttributesImpl.cpp new file mode 100644 index 00000000000..4ca2fcc3003 --- /dev/null +++ b/ACEXML/common/AttributesImpl.cpp @@ -0,0 +1,285 @@ +// -*- C++ -*- $Id$ + +#include "common/AttributesImpl.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/AttributesImpl.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_AttributesImpl::ACEXML_AttributesImpl (int size) + : attrs_ (size) +{ + this->attrs_.size (0); // attrs array contains nothing +} + +ACEXML_AttributesImpl::ACEXML_AttributesImpl (const + ACEXML_AttributesImpl &attrs) + : ACEXML_Attributes (attrs), + attrs_ (attrs.attrs_.size ()) +{ + for (size_t i = 0; i < attrs.attrs_.size (); i++) + this->attrs_[i] = attrs.attrs_[i]; +} + +ACEXML_AttributesImpl::~ACEXML_AttributesImpl (void) +{ +} + +int +ACEXML_AttributesImpl::addAttribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value) +{ + // @@ How do I check for the name here? Which name should + // I use to check for duplication? + + int length = this->attrs_.size (); + + this->attrs_.size (length+1); + this->setAttribute (length, + uri, + localName, + qName, + type, + value); + return length; +} + +int +ACEXML_AttributesImpl::addAttribute (const ACEXML_Attribute &att) +{ + // @@ How do I check for the name here? Which name should + // I use to check for duplication? + + int length = this->attrs_.size (); + + this->attrs_.size (length+1); + this->attrs_[length] = att; + return length; +} + +int +ACEXML_AttributesImpl::removeAttribute (size_t index) +{ + size_t length = this->attrs_.size (); + + if (index >= length) + return -1; + + this->attrs_[index] = this->attrs_[length - 1]; + this->attrs_.size (length - 1); + + return 0; +} + + +int +ACEXML_AttributesImpl::getIndex (const ACEXML_Char *qName) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0) + return i; + + return -1; +} + +int +ACEXML_AttributesImpl::getIndex (const ACEXML_Char *uri, + const ACEXML_Char *localPart) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 && + ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0) + return i; + + return -1; +} + +ACEXML_INLINE size_t +ACEXML_AttributesImpl::getLength (void) +{ + return this->attrs_.size (); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_AttributesImpl::getLocalName (size_t index) +{ + if (index < this->attrs_.size ()) + return this->attrs_[index].localName (); + return 0; +} + + +ACEXML_INLINE const ACEXML_Char * +ACEXML_AttributesImpl::getQName (size_t index) +{ + if (index < this->attrs_.size ()) + return this->attrs_[index].qName (); + return 0; +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_AttributesImpl::getType (size_t index) +{ + if (index < this->attrs_.size ()) + return this->attrs_[index].type (); + return 0; +} + + +const ACEXML_Char * +ACEXML_AttributesImpl::getType (const ACEXML_Char *qName) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0) + return this->attrs_[i].type (); + + return 0; +} + +const ACEXML_Char * +ACEXML_AttributesImpl::getType (const ACEXML_Char *uri, + const ACEXML_Char *localPart) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 && + ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0) + return this->attrs_[i].type (); + + return 0; +} + + +ACEXML_INLINE const ACEXML_Char * +ACEXML_AttributesImpl::getURI (size_t index) +{ + if (index < this->attrs_.size ()) + return this->attrs_[index].uri (); + return 0; +} + + +ACEXML_INLINE const ACEXML_Char * +ACEXML_AttributesImpl::getValue (size_t index) +{ + if (index < this->attrs_.size ()) + return this->attrs_[index].value (); + return 0; +} + +const ACEXML_Char * +ACEXML_AttributesImpl::getValue (const ACEXML_Char *qName) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (qName, this->attrs_[i].qName ()) == 0) + return this->attrs_[i].value (); + + return 0; +} + +const ACEXML_Char * +ACEXML_AttributesImpl::getValue (const ACEXML_Char *uri, + const ACEXML_Char *localPart) +{ + for (size_t i = 0; i < this->attrs_.size (); i++) + if (ACE_OS::strcmp (uri, this->attrs_[i].uri ()) == 0 && + ACE_OS::strcmp (localPart, this->attrs_[i].localName ()) == 0) + return this->attrs_[i].value (); + + return 0; +} + +ACEXML_INLINE int +ACEXML_AttributesImpl::setAttribute (size_t index, + const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].setAttribute (uri, + localName, + qName, + type, + value); + return 0; + } + + return -1; +} + + +ACEXML_INLINE int +ACEXML_AttributesImpl::setLocalName (size_t index, + const ACEXML_Char *localName) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].localName (localName); + return 0; + } + return -1; +} + +ACEXML_INLINE int +ACEXML_AttributesImpl::setQName (size_t index, + const ACEXML_Char *qName) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].qName (qName); + return 0; + } + return -1; +} + + +ACEXML_INLINE int +ACEXML_AttributesImpl::setURI (size_t index, + const ACEXML_Char *uri) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].uri (uri); + return 0; + } + return -1; +} + +ACEXML_INLINE int +ACEXML_AttributesImpl::setType (size_t index, + const ACEXML_Char *type) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].type (type); + return 0; + } + return -1; +} + +ACEXML_INLINE int +ACEXML_AttributesImpl::setValue (size_t index, + const ACEXML_Char *value) +{ + if (index < this->attrs_.size ()) + { + this->attrs_[index].value (value); + return 0; + } + return -1; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Array_Base<ACEXML_Attribute>; +template class ACE_Array<ACEXML_Attribute>; +template class ACE_Array_Iterator<ACEXML_Attribute>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Array_Base<ACEXML_Attribute> +#pragma instantiate ACE_Array<ACEXML_Attribute> +#pragma instantiate ACE_Array_Iterator<ACEXML_Attribute> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/ACEXML/common/AttributesImpl.h b/ACEXML/common/AttributesImpl.h new file mode 100644 index 00000000000..4f69b9a307d --- /dev/null +++ b/ACEXML/common/AttributesImpl.h @@ -0,0 +1,293 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file AttributesImpl.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + + +#ifndef ACEXML_ATTRIBUTESIMPL_H +#define ACEXML_ATTRIBUTESIMPL_H + +#include "common/Attributes.h" +#include "ace/Containers_T.h" + +#if !defined ACEXML_AttributesImpl_Default_Size +#define ACEXML_AttributesImpl_Default_Size 20 +#endif /* ACEXML_AttributesImpl_Default_Size */ + +class ACEXML_AttributesImpl; + +/** + * @class ACEXML_Attribute AttributesImpl.h "common/AttributesImpl.h" + * + * @brief ACEXML_Attribute defines the data structure of an attribute + * + * @sa ACEXML_AttributesImpl + */ +class ACEXML_Export ACEXML_Attribute +{ +public: + friend class ACEXML_AttributesImpl; + + /// Default constructor. + ACEXML_Attribute (void); + + /// Copy constructor. + ACEXML_Attribute (const ACEXML_Attribute &attr); + + /// Initialize all constructor. + ACEXML_Attribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value); + + /// Destructor. + ~ACEXML_Attribute (void); + + /// Set all members. + void setAttribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value); + + /// Set \a uri_. + const ACEXML_Char *uri (void) const; + + /// Get \a uri_. + void uri (const ACEXML_Char *uri); + + /// Set \a localName_. + const ACEXML_Char *localName (void) const; + + /// Get \a localName_. + void localName (const ACEXML_Char *localName); + + /// Set \a qName_. + const ACEXML_Char *qName (void) const; + + /// Get \a qName_. + void qName (const ACEXML_Char *qName); + + /// Set \a type_. + const ACEXML_Char *type (void) const; + + /// Get \a type_. + void type (const ACEXML_Char *type); + + /// Set \a value_. + const ACEXML_Char *value (void) const; + + /// Get \a value_. + void value (const ACEXML_Char *value); + + /// Assignment operator. + ACEXML_Attribute &operator= (const ACEXML_Attribute &rhs); + + /// Comparison operator. + int operator!= (const ACEXML_Attribute&rhs) const; + +private: + /// @var uri_ Namespace URI of an attribute + ACEXML_Char *uri_; + + /// @var localName_ + ACEXML_Char *localName_; + ACEXML_Char *qName_; + ACEXML_Char *type_; + ACEXML_Char *value_; +}; + +/** + * @typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array + */ +typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array; + +/** + * @class ACEXML_AttributesImpl AttributesImpl.h "common/AttributesImpl.h" + * + * @brief ACEXML_AttributesImpl provides the default implementation + * of interface ACEXML_Attributes. + * + * This class provides a default implementation of the SAX2 Attributes + * interface, with the addition of manipulators so that the list can + * be modified or reused. + * + * There are two typical uses of this class: + * + * - to take a persistent snapshot of an Attributes object in a startElement event; or + * - to construct or modify an Attributes object in a SAX2 driver or filter. + * + * This class replaces the now-deprecated SAX1 AttributeListImpl + * class; in addition to supporting the updated Attributes interface + * rather than the deprecated AttributeList interface, it also + * includes a much more efficient implementation using a single array + * rather than a set of Vectors. + * + * @sa ACEXML_Attributes + */ +class ACEXML_Export ACEXML_AttributesImpl + : public ACEXML_Attributes +{ +public: + /** + * Initialize an AttributesImpl that holds <size> attributes. + */ + ACEXML_AttributesImpl (int size = ACEXML_AttributesImpl_Default_Size); + ACEXML_AttributesImpl (const ACEXML_AttributesImpl &attrs); + virtual ~ACEXML_AttributesImpl (void); + + /** + * Add a new attribute using the argument(s) supplied. + * Return -1 if an attribute with the same name already exists. + */ + virtual int addAttribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value); + virtual int addAttribute (const ACEXML_Attribute &att); + + /** + * Remove an attribute from the array. Notice that this + * operation can invalidate previously acquired <index> + * value. (It will repack the array.) + */ + virtual int removeAttribute (size_t index); + + + /** + * Look up the index of an attribute by XML 1.0 qualified name. + * Return -1 if we fail to find a match. + */ + virtual int getIndex (const ACEXML_Char *qName); + + /** + * Look up the index of an attribute by Namespace name. + * Return -1 if we fail to find a match. + */ + virtual int getIndex (const ACEXML_Char *uri, + const ACEXML_Char *localPart); + + /** + * Return the number of attributes in the list. + */ + virtual size_t getLength (void); + + /** + * Look up an attribute's local name by index. + * Return 0 if index is out of range. + */ + virtual const ACEXML_Char *getLocalName (size_t index); + + /** + * Look up an attribute's XML 1.0 qualified name by index. + * Return 0 if index is out of range. + */ + virtual const ACEXML_Char *getQName (size_t index); + + /** + * Look up an attribute's type by index. + * Return 0 if index is out of range. + */ + virtual const ACEXML_Char *getType (size_t index); + + /** + * Look up an attribute's type by XML 1.0 qualified name. + * Return 0 if we fail to find a match. + */ + virtual const ACEXML_Char *getType (const ACEXML_Char *qName); + + /** + * Look up an attribute's type by Namespace name. + * Return 0 if we fail to find a match. + */ + virtual const ACEXML_Char *getType (const ACEXML_Char *uri, + const ACEXML_Char *localPart); + + /** + * Look up an attribute's Namespace URI by index. + * Return 0 if index is out of range. + */ + virtual const ACEXML_Char *getURI (size_t index); + + /** + * Look up an attribute's value by index. + * Return 0 if index is out of range. + */ + virtual const ACEXML_Char *getValue (size_t index); + + /** + * Look up an attribute's value by XML 1.0 qualified name. + * Return 0 if we fail to find a match. + */ + virtual const ACEXML_Char *getValue (const ACEXML_Char *qName); + + /** + * Look up an attribute's value by Namespace name. + * Return 0 if we fail to find a match. + */ + virtual const ACEXML_Char *getValue (const ACEXML_Char *uri, + const ACEXML_Char *localPart); + + /** + * Set an attribute at index. Return -1 if index is out of + * range. + */ + virtual int setAttribute (size_t index, + const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value); + + /** + * Set the localName of the attribute at <index>. + * return -1 if <index> is out of range. + */ + virtual int setLocalName (size_t index, + const ACEXML_Char *localName); + + /** + * Set the qName of the attribute at <index>. + * return -1 if <index> is out of range. + */ + virtual int setQName (size_t index, + const ACEXML_Char *qName); + + /** + * Set the URI of the attribute at <index>. + * return -1 if <index> is out of range. + */ + virtual int setURI (size_t index, + const ACEXML_Char *uri); + + /** + * Set the type of the attribute at <index>. + * return -1 if <index> is out of range. + */ + virtual int setType (size_t index, + const ACEXML_Char *type); + + /** + * Set the value of the attribute at <index>. + * return -1 if <index> is out of range. + */ + virtual int setValue (size_t index, + const ACEXML_Char *value); +private: + /// Container for all attributes. + ACEXML_Attribute_Array attrs_; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/AttributesImpl.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_ATTRIBUTESIMPL_H */ diff --git a/ACEXML/common/AttributesImpl.i b/ACEXML/common/AttributesImpl.i new file mode 100644 index 00000000000..8e9b5ef2d6e --- /dev/null +++ b/ACEXML/common/AttributesImpl.i @@ -0,0 +1,151 @@ +// -*- C++ -*- $Id$ + +#include "ace/ACE.h" + +ACEXML_INLINE +ACEXML_Attribute::ACEXML_Attribute (void) + : uri_ (0), + localName_ (0), + qName_ (0), + type_ (0), + value_ (0) +{ +} + +ACEXML_INLINE +ACEXML_Attribute::ACEXML_Attribute (const ACEXML_Attribute &attr) + : uri_ (ACE::strnew (attr.uri_)), + localName_ (ACE::strnew (attr.localName_)), + qName_ (ACE::strnew (attr.qName_)), + type_ (ACE::strnew (attr.type_)), + value_ (ACE::strnew (attr.value_)) +{ +} + +ACEXML_INLINE +ACEXML_Attribute::ACEXML_Attribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value) + : uri_ (ACE::strnew (uri)), + localName_ (ACE::strnew (localName)), + qName_ (ACE::strnew (qName)), + type_ (ACE::strnew (type)), + value_ (ACE::strnew (value)) +{ +} + +ACEXML_INLINE +ACEXML_Attribute::~ACEXML_Attribute (void) +{ + delete this->uri_; + delete this->localName_; + delete this->qName_; + delete this->type_; + delete this->value_; +} + +ACEXML_INLINE void +ACEXML_Attribute::setAttribute (const ACEXML_Char *uri, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + const ACEXML_Char *type, + const ACEXML_Char *value) +{ + this->uri (uri); + this->qName (qName); + this->localName (localName); + this->type (type); + this->value (value); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Attribute::uri (void) const +{ + return this->uri_; +} + +ACEXML_INLINE void +ACEXML_Attribute::uri (const ACEXML_Char *uri) +{ + delete this->uri_; + this->uri_ = ACE::strnew (uri); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Attribute::localName (void) const +{ + return this->localName_; +} + +ACEXML_INLINE void +ACEXML_Attribute::localName (const ACEXML_Char *localName) +{ + delete this->localName_; + this->localName_ = ACE::strnew (localName); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Attribute::qName (void) const +{ + return this->qName_; +} + +ACEXML_INLINE void +ACEXML_Attribute::qName (const ACEXML_Char *qName) +{ + delete this->qName_; + this->qName_ = ACE::strnew (qName); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Attribute::type (void) const +{ + return this->type_; +} + +ACEXML_INLINE void +ACEXML_Attribute::type (const ACEXML_Char *type) +{ + delete this->type_; + this->type_ = ACE::strnew (type); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Attribute::value (void) const +{ + return this->value_; +} + +ACEXML_INLINE void +ACEXML_Attribute::value (const ACEXML_Char *value) +{ + delete this->value_; + this->value_ = ACE::strnew (value); +} + +ACEXML_INLINE ACEXML_Attribute & +ACEXML_Attribute::operator= (const ACEXML_Attribute &rhs) +{ + if (this != &rhs) // Check for self assignment + { + this->uri (rhs.uri ()); + this->qName (rhs.qName ()); + this->localName (rhs.localName ()); + this->type (rhs.type ()); + this->value (rhs.value ()); + } + return *this; +} + +ACEXML_INLINE int +ACEXML_Attribute::operator!= (const ACEXML_Attribute &rhs) const +{ + return (ACE_OS::strcmp (this->uri_, rhs.uri ()) == 0 && + ACE_OS::strcmp (this->localName_, rhs.localName ()) == 0 && + ACE_OS::strcmp (this->qName_, rhs .qName ()) == 0 && + ACE_OS::strcmp (this->type_, rhs.type ()) == 0 && + ACE_OS::strcmp (this->value_, rhs.value ()) == 0 ? 0 : 1); + +} diff --git a/ACEXML/common/Attributes_Def_Builder.cpp b/ACEXML/common/Attributes_Def_Builder.cpp new file mode 100644 index 00000000000..7ee53696985 --- /dev/null +++ b/ACEXML/common/Attributes_Def_Builder.cpp @@ -0,0 +1,25 @@ +// $Id$ + +#include "common/Attributes_Def_Builder.h" + +ACEXML_Attribute_Def_Builder::~ACEXML_Attribute_Def_Builder () +{ + +} + +ACEXML_Attributes_Def_Builder::~ACEXML_Attributes_Def_Builder () +{ + +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class auto_ptr<ACEXML_Attribute_Def_Builder>; +template class auto_ptr<ACEXML_Attributes_Def_Builder>; +template class ACE_Auto_Basic_Ptr<ACEXML_Attribute_Def_Builder>; +template class ACE_Auto_Basic_Ptr<ACEXML_Attributes_Def_Builder>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate auto_ptr<ACEXML_Attribute_Def_Builder> +#pragma instantiate auto_ptr<ACEXML_Attributes_Def_Builder> +#pragma instantiate ACE_Auto_Basic_Ptr<ACEXML_Attribute_Def_Builder> +#pragma instantiate ACE_Auto_Basic_Ptr<ACEXML_Attributes_Def_Builder> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/ACEXML/common/Attributes_Def_Builder.h b/ACEXML/common/Attributes_Def_Builder.h new file mode 100644 index 00000000000..3a991b419d8 --- /dev/null +++ b/ACEXML/common/Attributes_Def_Builder.h @@ -0,0 +1,151 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Attributes_Def_Builder.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_ATTRIBUTES_DEF_BUILDER_H_ +#define _ACEXML_ATTRIBUTES_DEF_BUILDER_H_ + +#include "common/XML_Types.h" +#include "common/Env.h" + +/** + * @ class ACEXML_Attribute_Def_Builder Attributes_Def_Builder.h "common/Attributes_Def_Builder.h" + * + * @ brief An abstract virtual class defining an interface + * for building an attribute definition from DTD. + * + * This class should be invisible to application programmers and + * is only used for validator implementors. + */ +class ACEXML_Export ACEXML_Attribute_Def_Builder +{ +public: + + typedef auto_ptr<ACEXML_Attribute_Def_Builder> VAR; + + typedef enum { + CDATA, + ID, + IDREF, + IDREFS, + ENTITY, + ENTITIES, + NMTOKEN, + NMTOKENS, + NOTATION, + ENUMERATION, + ERROR_TYPE, + } ATT_TYPE; + + typedef enum { + REQUIRED, + IMPLIED, + FIXED, + INVALID + } DEFAULT_DECL; + + virtual ~ACEXML_Attribute_Def_Builder () = 0; + + /** + * Specify the name of the attribute. + */ + virtual int setName (const ACEXML_Char *n) = 0; + + /** + * Get the name of the attribute. + */ + virtual const ACEXML_Char *getName (void) = 0; + + /** + * Set the attribute type. + */ + virtual int setAttType (const ATT_TYPE type, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Insert an element for NOTATION or ENUMERATION type attribute. + */ + virtual int insertList (const ACEXML_Char *Name, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Set default attribute declaration. + */ + virtual int setDefault (const DEFAULT_DECL def, + const ACEXML_Char *value, + ACEXML_Env &xmlenv) + // ACE_THORW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Check validity of the current attribute definition being built. + * + * @retval 0 if the attribute is not a valid combo. + */ + virtual int validAttr (void) = 0; + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void) = 0; +}; + +/** + * @ class ACEXML_Attributes_Def_Builder Attributes_Def_Builder.h "common/Attributes_Def_Builder.h" + * + * @ brief An abstract virtual class defining an interface + * for building attribute definitions from DTD. + * + * This class should be invisible to application programmers and + * is only used for validator implementors. + */ +class ACEXML_Export ACEXML_Attributes_Def_Builder +{ +public: + + typedef auto_ptr<ACEXML_Attributes_Def_Builder> VAR; + + virtual ~ACEXML_Attributes_Def_Builder () = 0; + + /** + * 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)) + = 0; + + /** + * Acquire an Attribute_Builder. + */ + virtual ACEXML_Attribute_Def_Builder *getAttribute_Def_Builder () = 0; + + /** + * Add a definition for one attribute. + */ + virtual int insertAttribute (ACEXML_Attribute_Def_Builder *def, + ACEXML_Env &xmlenv) = 0; + + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void) = 0; +}; + +#endif /* _ACEXML_ATTRIBUTES_DEF_BUILDER_H_ */ diff --git a/ACEXML/common/CharStream.cpp b/ACEXML/common/CharStream.cpp new file mode 100644 index 00000000000..ada6573be40 --- /dev/null +++ b/ACEXML/common/CharStream.cpp @@ -0,0 +1,7 @@ +// -*- C++ -*- $Id$ + +#include "common/CharStream.h" + +ACEXML_CharStream::~ACEXML_CharStream (void) +{ +} diff --git a/ACEXML/common/CharStream.h b/ACEXML/common/CharStream.h new file mode 100644 index 00000000000..94d44645025 --- /dev/null +++ b/ACEXML/common/CharStream.h @@ -0,0 +1,66 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file CharStream.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_CHARSTREAM_H_ +#define _ACEXML_CHARSTREAM_H_ + +#include "common/XML_Types.h" + +/** + * @class ACEXML_CharStream CharStream.h "common/CharStream.h" + * + * ACEXML_CharStream is an abstract class (interface) which defines + * the basic opertions a parser could use to retrieve XML charater + * sequence. The sequence can be read from a file or a character + * buffer. + */ +class ACEXML_Export ACEXML_CharStream +{ +public: + + /** + * Virtual destructor, must have. + */ + virtual ~ACEXML_CharStream () = 0; + + /** + * Returns the available ACEXML_Char in the buffer. -1 + * if the object is not initialized properly. + */ + virtual int available (void) = 0; + + /** + * Close this stream and release all resources used by it. + */ + virtual int close (void) = 0; + + /** + * Read the next ACEXML_Char. Return -1 if we are not able to + * return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed. + */ + virtual int get (ACEXML_Char& ch) = 0; + + /** + * Read the next batch of ACEXML_Char strings + */ + virtual int read (ACEXML_Char *str, + size_t len) = 0; + + /** + * Peek the next ACEXML_Char in the CharStream. Return the + * character if succeess, -1 if EOS is reached. + */ + virtual int peek (void) = 0; + +}; + +#endif /* _ACEXML_CHARSTREAM_H_ */ diff --git a/ACEXML/common/ContentHandler.h b/ACEXML/common/ContentHandler.h new file mode 100644 index 00000000000..d680a9261c1 --- /dev/null +++ b/ACEXML/common/ContentHandler.h @@ -0,0 +1,138 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file ContentHandler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_CONTENTHANDLER_H_ +#define _ACEXML_CONTENTHANDLER_H_ + +#include "common/Env.h" +#include "common/SAXExceptions.h" +#include "common/Locator.h" +#include "common/Attributes.h" + +/** + * @class ACEXML_ContentHandler ContentHandler.h "common/ContentHandler.h" + * + * @brief ACEXML_ContentHandler + * + * This is the main interface that most SAX applications implement: if + * the application needs to be informed of basic parsing events, it + * implements this interface and registers an instance with the SAX + * parser using the setContentHandler method. The parser uses the + * instance to report basic document-related events like the start and + * end of elements and character data. + * + * The order of events in this interface is very important, and + * mirrors the order of information in the document itself. For + * example, all of an element's content (character data, processing + * instructions, and/or subelements) will appear, in order, between + * the startElement event and the corresponding endElement event. + + */ +class ACEXML_Export ACEXML_ContentHandler +{ +public: + /** + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of the end of a document. + */ + virtual void endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of the end of an element. + */ + virtual void endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * End the scope of a prefix-URI mapping. + */ + virtual void endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of ignorable whitespace in element content. + */ + virtual void ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of a processing instruction. + */ + virtual void processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive an object for locating the origin of SAX document events. + */ + virtual void setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) = 0; + + /** + * Receive notification of a skipped entity. + */ + virtual void skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of the beginning of a document. + */ + virtual void startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of the beginning of an element. + */ + virtual void startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Begin the scope of a prefix-URI Namespace mapping. + */ + virtual void startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; +}; + +#endif /* _ACEXML_CONTENTHANDLER_H_ */ diff --git a/ACEXML/common/DTDHandler.h b/ACEXML/common/DTDHandler.h new file mode 100644 index 00000000000..c8cb7a1f8d2 --- /dev/null +++ b/ACEXML/common/DTDHandler.h @@ -0,0 +1,71 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file DTDHandler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_DTDHANDLER_H_ +#define _ACEXML_DTDHANDLER_H_ + +#include "common/Env.h" +#include "common/SAXExceptions.h" + +/** + * @class ACEXML_DTDHandler DTDHandler.h "common/DTDHandler.h" + * + * @brief ACEXML_DTDHandler + * + * If a SAX application needs information about notations and unparsed + * entities, then the application implements this interface and + * registers an instance with the SAX parser using the parser's + * setDTDHandler method. The parser uses the instance to report + * notation and unparsed entity declarations to the application. + * + * Note that this interface includes only those DTD events that the + * XML recommendation requires processors to report: notation and + * unparsed entity declarations. + * + * The SAX parser may report these events in any order, regardless of + * the order in which the notations and unparsed entities were + * declared; however, all DTD events must be reported after the + * document handler's startDocument event, and before the first + * startElement event. + * + * It is up to the application to store the information for future use + * (perhaps in a hash table or object tree). If the application + * encounters attributes of type "NOTATION", "ENTITY", or "ENTITIES", + * it can use the information that it obtained through this interface + * to find the entity and/or notation corresponding with the attribute + * value. + */ +class ACEXML_Export ACEXML_DTDHandler +{ +public: + /** + * Receive notification of a notation declaration event. + */ + virtual void notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of an unparsed entity declaration event. + */ + virtual void unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; +}; + +#endif /* _ACEXML_DTDHANDLER_H_ */ diff --git a/ACEXML/common/DTD_Manager.cpp b/ACEXML/common/DTD_Manager.cpp new file mode 100644 index 00000000000..bacf4c91f24 --- /dev/null +++ b/ACEXML/common/DTD_Manager.cpp @@ -0,0 +1,8 @@ +// $Id$ + +#include "common/DTD_Manager.h" + +ACEXML_DTD_Manager::~ACEXML_DTD_Manager () +{ + +} diff --git a/ACEXML/common/DTD_Manager.h b/ACEXML/common/DTD_Manager.h new file mode 100644 index 00000000000..3bc81aef694 --- /dev/null +++ b/ACEXML/common/DTD_Manager.h @@ -0,0 +1,75 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file DTD_Manager.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_DTD_Manager_H_ +#define _ACEXML_DTD_Manager_H_ + +#include "common/Attributes_Def_Builder.h" +#include "common/Element_Def_Builder.h" +#include "common/Validator.h" + +/** + * @ class ACEXML_DTD_Manager DTD_Manager.h "common/DTD_Manager.h" + * + * @ todo Fill in the blank. + */ +class ACEXML_Export ACEXML_DTD_Manager +{ +public: + virtual ~ACEXML_DTD_Manager () = 0; + + /** + * 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 () = 0; + + /** + * 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) = 0; + + /** + * Acquire a pointer to an attributes definition builder. + * + */ + virtual ACEXML_Attributes_Def_Builder *getAttribute_Def_Builder () = 0; + + /** + * 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) = 0; + + /** + * 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) = 0; +}; + +#endif /* _ACEXML_DTD_Manager_H_ */ diff --git a/ACEXML/common/DefaultHandler.cpp b/ACEXML/common/DefaultHandler.cpp new file mode 100644 index 00000000000..3ebff8f7ac2 --- /dev/null +++ b/ACEXML/common/DefaultHandler.cpp @@ -0,0 +1,176 @@ +// -*- C++ -*- $Id$ + +#include "common/DefaultHandler.h" +#if !defined (__ACEXML_INLINE__) +# include "common/DefaultHandler.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_DefaultHandler::ACEXML_DefaultHandler (void) +{ + // no-op +} + +ACEXML_DefaultHandler::~ACEXML_DefaultHandler (void) +{ + // no-op +} + +void +ACEXML_DefaultHandler::characters (const ACEXML_Char *, + int, + int, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::endDocument (ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::endElement (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::endPrefixMapping (const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::ignorableWhitespace (const ACEXML_Char *, + int, + int, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::processingInstruction (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::setDocumentLocator (ACEXML_Locator *, + ACEXML_Env &) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::skippedEntity (const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::startDocument (ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::startElement (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Attributes *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::startPrefixMapping (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + + // *** Methods inherit from ACEXML_DTDHandler. + +void +ACEXML_DefaultHandler::notationDecl (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::unparsedEntityDecl (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + + // Methods inherit from ACEXML_EnitityResolver. + +ACEXML_InputSource * +ACEXML_DefaultHandler::resolveEntity (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. + return 0; +} + + // Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ +void +ACEXML_DefaultHandler::error (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::fatalError (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_DefaultHandler::warning (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} diff --git a/ACEXML/common/DefaultHandler.h b/ACEXML/common/DefaultHandler.h new file mode 100644 index 00000000000..c746550c72b --- /dev/null +++ b/ACEXML/common/DefaultHandler.h @@ -0,0 +1,217 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file DefaultHandler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef ACEXML_DEFAULTHANDLER_H +#define ACEXML_DEFAULTHANDLER_H + +#include "common/ContentHandler.h" +#include "common/DTDHandler.h" +#include "common/EntityResolver.h" +#include "common/ErrorHandler.h" + +/** + * @class ACEXML_DefaultHandler DefaultHandler.h "common/DefaultHandler.h" + * + * @brief ACEXML_DefaultHandler + * + * This class is available as a convenience base class for SAX2 + * applications: it provides default implementations for all of the + * callbacks in the four core SAX2 handler classes: + * + * - EntityResolver + * - DTDHandler + * - ContentHandler + * - ErrorHandler + * + * Application writers can extend this class when they need to + * implement only part of an interface; parser writers can instantiate + * this class to provide default handlers when the application has not + * supplied its own. + */ +class ACEXML_Export ACEXML_DefaultHandler + : public ACEXML_ContentHandler, + public ACEXML_DTDHandler, + public ACEXML_EntityResolver, + public ACEXML_ErrorHandler +{ +public: + /** + * Default constructor. + */ + ACEXML_DefaultHandler (void); + + /** + * destructor. + */ + virtual ~ACEXML_DefaultHandler (void); + + // Methods inherit from ACEXML_ContentHandler. + + /* + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of a document. + */ + virtual void endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of an element. + */ + virtual void endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * End the scope of a prefix-URI mapping. + */ + virtual void endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of ignorable whitespace in element content. + */ + virtual void ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a processing instruction. + */ + virtual void processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive an object for locating the origin of SAX document events. + */ + virtual void setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) ; + + /* + * Receive notification of a skipped entity. + */ + virtual void skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of a document. + */ + virtual void startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of an element. + */ + virtual void startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Begin the scope of a prefix-URI Namespace mapping. + */ + virtual void startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // *** Methods inherit from ACEXML_DTDHandler. + + /* + * Receive notification of a notation declaration event. + */ + virtual void notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of an unparsed entity declaration event. + */ + virtual void unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_EnitityResolver. + + /* + * Allow the application to resolve external entities. + */ + virtual ACEXML_InputSource *resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ + virtual void error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a non-recoverable error. + */ + virtual void fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a warning. + */ + virtual void warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/DefaultHandler.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_DEFAULTHANDLER_H */ diff --git a/ACEXML/common/DefaultHandler.i b/ACEXML/common/DefaultHandler.i new file mode 100644 index 00000000000..77b4466a3cb --- /dev/null +++ b/ACEXML/common/DefaultHandler.i @@ -0,0 +1 @@ +// -*- C++ -*- $Id$ diff --git a/ACEXML/common/Element_Def_Builder.cpp b/ACEXML/common/Element_Def_Builder.cpp new file mode 100644 index 00000000000..0063954c9e6 --- /dev/null +++ b/ACEXML/common/Element_Def_Builder.cpp @@ -0,0 +1,17 @@ +// $Id$ + +#include "common/Element_Def_Builder.h" + +ACEXML_Element_Def_Builder::~ACEXML_Element_Def_Builder () +{ + +} + + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class auto_ptr<ACEXML_Element_Def_Builder>; +template class ACE_Auto_Basic_Ptr<ACEXML_Element_Def_Builder>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate auto_ptr<ACEXML_Element_Def_Builder> +#pragma instantiate ACE_Auto_Basic_Ptr<ACEXML_Element_Def_Builder> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/ACEXML/common/Element_Def_Builder.h b/ACEXML/common/Element_Def_Builder.h new file mode 100644 index 00000000000..187ab283423 --- /dev/null +++ b/ACEXML/common/Element_Def_Builder.h @@ -0,0 +1,132 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Element_Def_Builder.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_ELEMENT_DEF_BUILDER_H_ +#define _ACEXML_ELEMENT_DEF_BUILDER_H_ + +#include "ace/Auto_Ptr.h" +#include "common/XML_Types.h" +#include "common/Env.h" + +/** + * @ class ACEXML_Element_Def_Builder Element_Def_Builder.h "common/Element_Def_Builder.h" + * + * @ brief An abstract virtual class that defines the interface + * to define an element definition. + * + * This class defines how to define an element definition after + * parsing a DTD. + */ +class ACEXML_Export ACEXML_Element_Def_Builder +{ +public: + + typedef auto_ptr<ACEXML_Element_Def_Builder> VAR; + + typedef enum { + EMPTY, + ANY, + MIXED, + CHILDREN, + UNDEFINED + } CONTENT_TYPE; + + typedef enum { + ONE, + ZERO_OR_MORE, + ONE_OR_MORE, + ONE_OR_ZERO + } CARDINALITY; + + virtual ~ACEXML_Element_Def_Builder () = 0; + + /** + * 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)) + = 0; + + /** + * 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)) + = 0; + + /** + * 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)) + = 0; + + /** + * Start a new group of children. + */ + virtual int startChildGroup () = 0; + + /** + * End a new group of children. + * + * @retval 0 on success. + */ + virtual int endChildGroup (CARDINALITY card, + ACEXML_Env &xmlenv) = 0; + + /** + * 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 () = 0; + + /** + * 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 () = 0; + + /** + * 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)) + = 0; + + /** + * Dump the content of the attribute definition. + */ + virtual void dump (void) = 0; +}; + +#endif /* _ACEXML_ELEMENT_DEF_BUILDER_H_ */ diff --git a/ACEXML/common/EntityResolver.h b/ACEXML/common/EntityResolver.h new file mode 100644 index 00000000000..913228e2ca0 --- /dev/null +++ b/ACEXML/common/EntityResolver.h @@ -0,0 +1,49 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file EntityResolver.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_ENTITYHANDLER_H_ +#define _ACEXML_ENTITYHANDLER_H_ + +#include "common/Env.h" +#include "common/InputSource.h" + +/** + * @class ACEXML_EntityResolver EntityResolver.h "common/EntityResolver.h" + * + * @brief ACEXML_EntityResolver + * + * If a SAX application needs to implement customized handling for + * external entities, it must implement this interface and register an + * instance with the SAX driver using the setEntityResolver method. + * + * The XML reader will then allow the application to intercept any + * external entities (including the external DTD subset and external + * parameter entities, if any) before including them. + * + * Many SAX applications will not need to implement this interface, + * but it will be especially useful for applications that build XML + * documents from databases or other specialised input sources, or for + * applications that use URI types other than URLs. + */ +class ACEXML_Export ACEXML_EntityResolver +{ +public: + /** + * Allow the application to resolve external entities. + */ + virtual ACEXML_InputSource *resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; +}; + +#endif /* _ACEXML_ENTITYHANDLER_H_ */ diff --git a/ACEXML/common/Env.cpp b/ACEXML/common/Env.cpp new file mode 100644 index 00000000000..412996d8bef --- /dev/null +++ b/ACEXML/common/Env.cpp @@ -0,0 +1,22 @@ +// -*- C++ -*- $Id$ + +#include "common/Env.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/Env.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_Env::ACEXML_Env (void) + : exception_ (0) +{ +} + +ACEXML_Env::ACEXML_Env (const ACEXML_Env &ev) + : exception_ (ev.exception_->duplicate ()) +{ +} + +ACEXML_Env::~ACEXML_Env (void) +{ + delete this->exception_; +} diff --git a/ACEXML/common/Env.h b/ACEXML/common/Env.h new file mode 100644 index 00000000000..23d1aae4474 --- /dev/null +++ b/ACEXML/common/Env.h @@ -0,0 +1,67 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Env.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_ENV_H_ +#define _ACEXML_ENV_H_ +#include "common/Exception.h" + +/** + * @class ACEXML_Env Env.h "common/Env.h" + * + * @brief ACEXML_Env + * + * ACEXML_Env is modeled after CORBA_Environment class. It provides + * a place holder for callees to propagate exceptions back to + * callers. ACEXML does not support native exceptions at this + * moement. + * + * @sa ACEXML_Exception + */ +class ACEXML_Export ACEXML_Env +{ +public: + /// Default constructor. + ACEXML_Env (); + + /// Copy constructor. + ACEXML_Env (const ACEXML_Env &ev); + + /// Destructor. + ~ACEXML_Env (void); + + /// Check if exception has occured. + int exception_occured (void) const; + + /// Clear the exception and reset the evnrionment. + void reset (void); + + /// Return the underlying exception for examination + ACEXML_Exception *exception (void) const; + + /// Set the underlying exception. ACEXML_Env assumes + /// ownership of the exception. + void exception (ACEXML_Exception *exception); + +private: + /// Place holder for exception (if one occurs.) + ACEXML_Exception *exception_; +}; + +// = These macros are used to speed up programming. I hope to +// merge them with ACE_CHECK macros someday. +#define ACEXML_CHECK if (xmlenv.exception ()) return; +#define ACEXML_CHECK_RETURN(VAL) if (xmlenv.exception ()) return VAL; + +#if defined (__ACEXML_INLINE__) +# include "common/Env.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_ENV_H_ */ diff --git a/ACEXML/common/Env.i b/ACEXML/common/Env.i new file mode 100644 index 00000000000..e3b149089b1 --- /dev/null +++ b/ACEXML/common/Env.i @@ -0,0 +1,26 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE int +ACEXML_Env::exception_occured (void) const +{ + return this->exception_ != 0; +} + +ACEXML_INLINE void +ACEXML_Env::reset (void) +{ + this->exception (0); +} + +ACEXML_INLINE ACEXML_Exception * +ACEXML_Env::exception (void) const +{ + return this->exception_; +} + +ACEXML_INLINE void +ACEXML_Env::exception (ACEXML_Exception *ex) +{ + delete this->exception_; + this->exception_ = ex; +} diff --git a/ACEXML/common/ErrorHandler.h b/ACEXML/common/ErrorHandler.h new file mode 100644 index 00000000000..06ddd8408e9 --- /dev/null +++ b/ACEXML/common/ErrorHandler.h @@ -0,0 +1,68 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file ErrorHandler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_ERRORHANDLER_H_ +#define _ACEXML_ERRORHANDLER_H_ + +#include "common/Env.h" +#include "common/SAXExceptions.h" + +/** + * @class ACEXML_ErrorHandler ErrorHandler.h "common/ErrorHandler.h" + * + * @brief ACEXML_ErrorHandler + * + * If a SAX application needs to implement customized error handling, + * it must implement this interface and then register an instance with + * the XML reader using the setErrorHandler method. The parser will + * then report all errors and warnings through this interface. + * + * @b WARNING: If an application does not register an ErrorHandler, + * XML parsing errors will go unreported and bizarre behaviour may + * result. + * + * For XML processing errors, a SAX driver must use this interface + * instead of throwing an exception: it is up to the application to + * decide whether to throw an exception for different types of errors + * and warnings. Note, however, that there is no requirement that the + * parser continue to provide useful information after a call to + * fatalError (in other words, a SAX driver class could catch an + * exception and report a fatalError). + */ +class ACEXML_Export ACEXML_ErrorHandler +{ +public: + /** + * Receive notification of a recoverable error. + */ + virtual void error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of a non-recoverable error. + */ + virtual void fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Receive notification of a warning. + */ + virtual void warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; +}; + +#endif /* _ACEXML_ERRORHANDLER_H_ */ diff --git a/ACEXML/common/Exception.cpp b/ACEXML/common/Exception.cpp new file mode 100644 index 00000000000..f5cde1d4eae --- /dev/null +++ b/ACEXML/common/Exception.cpp @@ -0,0 +1,69 @@ +// -*- C++ -*- $Id$ + +#include "common/Exception.h" +#include "ace/Log_Msg.h" +#include "ace/ACE.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/Exception.i" +#endif /* __ACEXML_INLINE__ */ + +static const ACEXML_Char ACEXML_Exception_name[] = { + 'A', 'C', 'E', 'X', 'M', 'L', + '_', 'E', 'x', 'c', 'e', 'p', + 't', 'i', 'o', 'n', 0}; +const ACEXML_Char *ACEXML_Exception::exception_name_ = ACEXML_Exception_name; + +static const ACEXML_Char ACEXML_Exception_null [] = {0}; +const ACEXML_Char *ACEXML_Exception::null_ = ACEXML_Exception_null; + +ACEXML_Exception::ACEXML_Exception (void) +{ +} + +ACEXML_Exception::ACEXML_Exception (const ACEXML_Exception &) +{ +} + + +ACEXML_Exception::~ACEXML_Exception (void) +{ +} + +const ACEXML_Char * +ACEXML_Exception::id (void) +{ + return ACEXML_Exception::exception_name_; +} + +// @@ An example of how duplicate should be implemented. + +// ACEXML_Exception * +// ACEXML_Exception::duplicate (void) +// { +// ACEXML_Exception *tmp; +// ACE_NEW_RETURN (tmp, +// ACEXML_Exception (*this), +// // Replace ACEXML_Exception with appropriate type. +// 0); +// } + +int +ACEXML_Exception::is_a (const ACEXML_Char *name) +{ + if (name == ACEXML_Exception::exception_name_ + || ACE_OS::strcmp (ACEXML_Exception::exception_name_, + name) == 0) + return 1; + + return 0; +} + +void +ACEXML_Exception::print (void) +{ + // @@ Nanbor, I don't know how to handle the case + // when we define ACEXML_UTF16 as ACEXML_Char + ACE_DEBUG ((LM_DEBUG, + "Exception: ACEXML_Exception\n")); +} diff --git a/ACEXML/common/Exception.h b/ACEXML/common/Exception.h new file mode 100644 index 00000000000..7f285ff3688 --- /dev/null +++ b/ACEXML/common/Exception.h @@ -0,0 +1,69 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Exception.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_EXCEPTION_H_ +#define _ACEXML_EXCEPTION_H_ + +#include "common/XML_Types.h" + +/** + * @class ACEXML_Exception Exception.h "common/Exception.h" + * + * @brief ACEXML_Exception + * + * ACEXML_Exception is the base class for all ACEXML related exceptions. + * Since ACEXML currently does not support native exceptions, all + * exceptions should be thrown thru ACEXML_Env. + * + * @sa ACEXML_Env + */ +class ACEXML_Export ACEXML_Exception +{ +public: + /// Default contructor. + ACEXML_Exception (void); + + /// Copu constructor. + ACEXML_Exception (const ACEXML_Exception &ex); + + /// Destructor. + virtual ~ACEXML_Exception (void); + + /// Accessor for the exception name. + static const ACEXML_Char *name (void); + + /// Return the exception type. (for safe downcast.) + virtual const ACEXML_Char *id (void); + + /// Dynamically create a copy of this exception. + virtual ACEXML_Exception *duplicate (void) = 0; + + /// Check whether this is an exception of type specify by + /// <name>. + virtual int is_a (const ACEXML_Char *name) = 0; + + /// Print out exception using ACE_DEBUG. + virtual void print (void) = 0; + +protected: + /// All exceptions have names. This name is used to identify the + /// type of an exception. + static const ACEXML_Char *exception_name_; + + /// A null string that we return when there's no exception occurred. + static const ACEXML_Char *null_; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/Exception.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_EXCEPTION_H_ */ diff --git a/ACEXML/common/Exception.i b/ACEXML/common/Exception.i new file mode 100644 index 00000000000..5e5438921b6 --- /dev/null +++ b/ACEXML/common/Exception.i @@ -0,0 +1,7 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE const ACEXML_Char * +ACEXML_Exception::name (void) +{ + return ACEXML_Exception::exception_name_; +} diff --git a/ACEXML/common/FileCharStream.cpp b/ACEXML/common/FileCharStream.cpp new file mode 100644 index 00000000000..fb431271d85 --- /dev/null +++ b/ACEXML/common/FileCharStream.cpp @@ -0,0 +1,81 @@ +// $Id$ + +#include "common/FileCharStream.h" +#include "ace/ACE.h" + +ACEXML_FileCharStream::ACEXML_FileCharStream (void) + : filename_ (0), + infile_ (NULL) +{ +} + +ACEXML_FileCharStream::ACEXML_FileCharStream (const ACEXML_Char *name) + : filename_ (), + infile_ (NULL) +{ + this->open (name); +} + + +ACEXML_FileCharStream::~ACEXML_FileCharStream (void) +{ + if (this->infile_ != NULL) + ACE_OS::fclose (this->infile_); + delete this->filename_; +} + +int +ACEXML_FileCharStream::open (const ACEXML_Char *name) +{ + delete this->filename_; + this->filename_ = 0; + + this->infile_ = ACE_OS::fopen (name, ACE_LIB_TEXT ("r")); + if (this->infile_ == NULL) + return -1; + + this->filename_ = ACE::strnew (name); + return 0; +} + +int +ACEXML_FileCharStream::available (void) +{ + // @@ how? + + return -1; +} + +int +ACEXML_FileCharStream::close (void) +{ + delete this->filename_; + this->filename_ = 0; + ACE_OS::fclose (this->infile_); + this->infile_ = NULL; + return 0; +} + +int +ACEXML_FileCharStream::get (ACEXML_Char& ch) +{ + // @@ Error checking? + ch = fgetc (this->infile_); + + return (ch == EOF ? -1 :0); +} + +int +ACEXML_FileCharStream::read (ACEXML_Char *str, + size_t len) +{ + return ACE_OS::fread (str, len, 1, this->infile_); +} + +int +ACEXML_FileCharStream::peek (void) +{ + ACEXML_Char ch = ::fgetc (this->infile_); + ::ungetc (ch, this->infile_); + return ch; +} diff --git a/ACEXML/common/FileCharStream.h b/ACEXML/common/FileCharStream.h new file mode 100644 index 00000000000..e9edfa1b33d --- /dev/null +++ b/ACEXML/common/FileCharStream.h @@ -0,0 +1,76 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file FileCharStream.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_FILECHARSTREAM_H_ +#define _ACEXML_FILECHARSTREAM_H_ + +#include "common/CharStream.h" +#include "ace/streams.h" + +/** + * @class ACEXML_FileCharStream FileCharStream.h "common/FileCharStream.h" + * + * An implementation of ACEXML_CharStream for reading + * input from a file. + */ +class ACEXML_Export ACEXML_FileCharStream : public ACEXML_CharStream +{ +public: + /// Default constructor. + ACEXML_FileCharStream (void); + + /// Construct and opening a file. + ACEXML_FileCharStream (const ACEXML_Char *name); + + /// Destructor + virtual ~ACEXML_FileCharStream (void); + + /// Open a file. + int open (const ACEXML_Char *name); + + /** + * Returns the available ACEXML_Char in the buffer. -1 + * if the object is not initialized properly. + */ + virtual int available (void); + + /** + * Close this stream and release all resources used by it. + */ + virtual int close (void); + + /** + * Read the next ACEXML_Char. Return -1 if we are not able to + * return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed. + */ + virtual int get (ACEXML_Char& ch); + + /** + * Read the next batch of ACEXML_Char strings + */ + virtual int read (ACEXML_Char *str, + size_t len); + + /** + * Peek the next ACEXML_Char in the CharStream. Return the + * character if succeess, -1 if EOS is reached. + */ + virtual int peek (void); + +private: + ACEXML_Char *filename_; + + FILE *infile_; + +}; + +#endif /* _ACEXML_FILECHARSTREAM_H_ */ diff --git a/ACEXML/common/InputSource.cpp b/ACEXML/common/InputSource.cpp new file mode 100644 index 00000000000..1d7035a3f2c --- /dev/null +++ b/ACEXML/common/InputSource.cpp @@ -0,0 +1,100 @@ +// -*- C++ -*- $Id$ + +#include "common/InputSource.h" +#include "ace/ACE.h" + +ACEXML_InputSource::ACEXML_InputSource (void) + : publicId_ (0), + systemId_ (0), + charStream_ (0), + encoding_ (0) +{ +} + +ACEXML_InputSource::ACEXML_InputSource (ACEXML_CharStream *stm) + : publicId_ (0), + systemId_ (0), + charStream_ (stm), + encoding_ (0) +{ +} + + /* + * Create a new input source with a character stream. + * / + InputSource (Reader); + */ + +ACEXML_InputSource::ACEXML_InputSource (const ACEXML_Char *systemId) + : systemId_ (ACE::strnew (systemId)) +{ +} + +ACEXML_InputSource::~ACEXML_InputSource (void) +{ + delete this->publicId_; + delete this->systemId_; + delete this->charStream_; + delete this->encoding_; +} + +ACEXML_CharStream * +ACEXML_InputSource::getCharStream (void) +{ + return this->charStream_; +} + + /* + * Get the character stream for this input source. + * / + virtual Reader *getCharacterStream (void); + */ + +const ACEXML_Char * +ACEXML_InputSource::getEncoding (void) +{ + return this->encoding_; +} + +const ACEXML_Char * +ACEXML_InputSource::getPublicId (void) +{ + return this->publicId_; +} + +const ACEXML_Char * +ACEXML_InputSource::getSystemId (void) +{ + return this->systemId_; +} + +void +ACEXML_InputSource::setCharStream (ACEXML_CharStream *stm) +{ + delete this->charStream_; + this->charStream_ = stm; +} + + /* + * Set the character stream for this input source. + * / + virtual void setCharacterStream (Reader *characterStream); + */ + +void +ACEXML_InputSource::setEncoding (const ACEXML_Char *encoding) +{ + this->encoding_ = ACE::strnew (encoding); +} + +void +ACEXML_InputSource::setPublicId (const ACEXML_Char *publicId) +{ + this->publicId_ = ACE::strnew (publicId); +} + +void +ACEXML_InputSource::setSystemId (const ACEXML_Char *systemId) +{ + this->systemId_ = ACE::strnew (systemId); +} diff --git a/ACEXML/common/InputSource.h b/ACEXML/common/InputSource.h new file mode 100644 index 00000000000..62ab76c6854 --- /dev/null +++ b/ACEXML/common/InputSource.h @@ -0,0 +1,120 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file InputSource.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_INPUTSOURCE_H_ +#define _ACEXML_INPUTSOURCE_H_ + +#include "common/CharStream.h" + +/** + * @class ACEXML_InputSource InputSource.h "common/InputSource.h" + * + * @brief ACEXML_InputSource encapsulates the actual input stream with some + * added information. + * + * This class allows a SAX application to encapsulate information + * about an input source in a single object, which may include a + * public identifier, a system identifier, a byte stream (possibly + * with a specified encoding), and/or a character stream. + * + * There are two places that the application will deliver this input + * source to the parser: as the argument to the Parser.parse method, + * or as the return value of the EntityResolver.resolveEntity method. + * + * The SAX parser will use the InputSource object to determine how to + * read XML input. If there is a character stream available, the + * parser will read that stream directly; if not, the parser will use + * a byte stream, if available; if neither a character stream nor a + * byte stream is available, the parser will attempt to open a URI + * connection to the resource identified by the system identifier. + * + * An InputSource object belongs to the application: the SAX parser + * shall never modify it in any way (it may modify a copy if + * necessary). + * + * @sa ACEXML_CharStream + */ +class ACEXML_Export ACEXML_InputSource +{ +public: + /* + * Default constructor. + */ + ACEXML_InputSource (void); + + /* + * Create a new input source with a ACEXML_Char stream. + * Notice that ACEXML_InputSource assumes the ownership + * of <stream> + */ + ACEXML_InputSource (ACEXML_CharStream *stream); + + /* + * Create a new input source with a system identifier. + */ + ACEXML_InputSource (const ACEXML_Char *systemId); + + /* + * Default destructor. + */ + virtual ~ACEXML_InputSource (void); + + /* + * Get the ACEXML_Char stream for this input source. + */ + virtual ACEXML_CharStream *getCharStream (void); + + /* + * Get the character encoding for a byte stream or URI. + */ + virtual const ACEXML_Char *getEncoding (void); + + /* + * Get the public identifier for this input source. + */ + virtual const ACEXML_Char *getPublicId (void); + + /* + * Get the system identifier for this input source. + */ + virtual const ACEXML_Char *getSystemId (void); + + /* + * Set the ACEXML_Char stream for this input source. + * Notice that ACEXML_InputSource assumes the ownership + * of <stream> + */ + virtual void setCharStream (ACEXML_CharStream *charStream); + + /* + * Set the character encoding, if known. + */ + virtual void setEncoding (const ACEXML_Char *encoding); + + /* + * Set the public identifier for this input source. + */ + virtual void setPublicId (const ACEXML_Char *publicId); + + /* + * Set the public identifier for this input source. + */ + virtual void setSystemId (const ACEXML_Char *systemId); + +private: + ACEXML_Char *publicId_; + ACEXML_Char *systemId_; + ACEXML_CharStream *charStream_; + ACEXML_Char *encoding_; +}; + +#endif /* _ACEXML_INPUTSOURCE_H_ */ diff --git a/ACEXML/common/Locator.h b/ACEXML/common/Locator.h new file mode 100644 index 00000000000..91dd7ef29c6 --- /dev/null +++ b/ACEXML/common/Locator.h @@ -0,0 +1,66 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Locator.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_LOCATOR_H_ +#define _ACEXML_LOCATOR_H_ + +#include "common/XML_Types.h" + +/** + * @class ACEXML_Locator Locator.h "common/Locator.h" + * + * @brief ACEXML_Locator defines operations that an XML locator should support. + * + * If a SAX parser provides location information to the SAX + * application, it does so by implementing this interface and then + * passing an instance to the application using the content handler's + * setDocumentLocator method. The application can use the object to + * obtain the location of any other content handler event in the XML + * source document. + * + * Note that the results returned by the object will be valid only + * during the scope of each content handler method: the application + * will receive unpredictable results if it attempts to use the + * locator at any other time. + * + * SAX parsers are not required to supply a locator, but they are very + * strongly encouraged to do so. If the parser supplies a locator, it + * must do so before reporting any other document events. If no + * locator has been set by the time the application receives the + * startDocument event, the application should assume that a locator + * is not available. + */ +class ACEXML_Export ACEXML_Locator +{ +public: + /* + * Return the column number where the current document event ends. + */ + virtual int getColumnNumber (void) const = 0; + + /* + * Return the line number where the current document event ends. + */ + virtual int getLineNumber (void) const = 0; + + /* + * Return the public identifier for the current document event. + */ + virtual const ACEXML_Char *getPublicId (void) const = 0; + + /* + * Return the system identifier for the current document event. + */ + virtual const ACEXML_Char *getSystemId (void) const = 0; +}; + +#endif /* _ACEXML_LOCATOR_H_ */ diff --git a/ACEXML/common/LocatorImpl.cpp b/ACEXML/common/LocatorImpl.cpp new file mode 100644 index 00000000000..de715a44a0d --- /dev/null +++ b/ACEXML/common/LocatorImpl.cpp @@ -0,0 +1,53 @@ +// -*- C++ -*- $Id$ + +#include "common/LocatorImpl.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/LocatorImpl.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_LocatorImpl::ACEXML_LocatorImpl (void) + : publicId_ (0), + systemId_ (0), + lineNumber_ (0), + columnNumber_ (0) +{ +} + +ACEXML_LocatorImpl::ACEXML_LocatorImpl (const ACEXML_Locator *locator) + : publicId_ (ACE::strnew (locator->getPublicId ())), + systemId_ (ACE::strnew (locator->getSystemId ())), + lineNumber_ (locator->getLineNumber ()), + columnNumber_ (locator->getColumnNumber ()) +{ +} + +ACEXML_LocatorImpl::~ACEXML_LocatorImpl (void) +{ + delete this->publicId_; + delete this->systemId_; +} + +int +ACEXML_LocatorImpl::getColumnNumber (void) const +{ + return this->columnNumber_; +} + +int +ACEXML_LocatorImpl::getLineNumber (void) const +{ + return this->lineNumber_; +} + +const ACEXML_Char * +ACEXML_LocatorImpl::getPublicId (void) const +{ + return this->publicId_; +} + +const ACEXML_Char * +ACEXML_LocatorImpl::getSystemId (void) const +{ + return this->systemId_; +} diff --git a/ACEXML/common/LocatorImpl.h b/ACEXML/common/LocatorImpl.h new file mode 100644 index 00000000000..404457ffaeb --- /dev/null +++ b/ACEXML/common/LocatorImpl.h @@ -0,0 +1,124 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file LocatorImpl.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef ACEXML_LOCALTORIMPL_H +#define ACEXML_LOCALTORIMPL_H + +#include "common/Locator.h" + +/** + * @class ACEXML_LocatorImpl LocatorImpl.h "common/LocatorImpl.h" + * + * @brief ACEXML_LocatorImpl is an implementation of ACEXML_Locator. + * + * This class is available mainly for application writers, who can + * use it to make a persistent snapshot of a locator at any point + * during a document parse: + * + * @code + * ACEXML_Locator locator; + * ACEXML_Locator startloc; + * + * public void setLocator (ACEXML_Locator locator) + * { + * // note the locator + * this.locator = locator; + * } + * + * public void startDocument () + * { + * // save the location of the start of the document + * // for future use. + * ACEXML_Locator startloc = new ACEXML_LocatorImpl(locator); + * } + * @endcode + * + * Normally, parser writers will not use this class, since it is more + * efficient to provide location information only when requested, + * rather than constantly updating a Locator object. + * + * @todo ACEXML parser doesn't support the use of Locator yet. + * + * @sa ACEXML_Locator + */ +class ACEXML_Export ACEXML_LocatorImpl : public ACEXML_Locator +{ +public: + /* + * Default constructor. + */ + ACEXML_LocatorImpl (void); + + /* + * Copy constructor. Create a persistent copy of the current state + * of a locator. When the original locator changes, this copy will + * still keep the original values (and it can be used outside the + * scope of DocumentHandler methods). + */ + ACEXML_LocatorImpl (const ACEXML_Locator *locator); + + /* + * Destructor. + */ + virtual ~ACEXML_LocatorImpl (void); + + /* + * Return the column number where the current document event ends. + */ + virtual int getColumnNumber (void) const; + + /* + * Return the line number where the current document event ends. + */ + virtual int getLineNumber (void) const; + + /* + * Return the public identifier for the current document event. + */ + virtual const ACEXML_Char *getPublicId (void) const; + + /* + * Return the system identifier for the current document event. + */ + virtual const ACEXML_Char *getSystemId (void) const; + + /* + * Set the column number of this locator. + */ + void setColumnNumber (int cn); + + /* + * Set the line number of this locator. + */ + void setLineNumber (int ln); + + /* + * Set the public identifier of this locator. + */ + void setPublicId (const ACEXML_Char *id); + + /* + * Set the system identifier of this locator. + */ + void setSystemId (const ACEXML_Char *id); + +private: + ACEXML_Char *publicId_; + ACEXML_Char *systemId_; + int lineNumber_; + int columnNumber_; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/LocatorImpl.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_LOCALTORIMPL_H */ diff --git a/ACEXML/common/LocatorImpl.i b/ACEXML/common/LocatorImpl.i new file mode 100644 index 00000000000..13871d0707d --- /dev/null +++ b/ACEXML/common/LocatorImpl.i @@ -0,0 +1,29 @@ +// -*- C++ -*- $Id$ + +#include "ace/ACE.h" + +ACEXML_INLINE void +ACEXML_LocatorImpl::setColumnNumber (int cn) +{ + this->columnNumber_ = cn; +} + +ACEXML_INLINE void +ACEXML_LocatorImpl::setLineNumber (int ln) +{ + this->lineNumber_ = ln; +} + +ACEXML_INLINE void +ACEXML_LocatorImpl::setPublicId (const ACEXML_Char *id) +{ + delete this->publicId_; + this->publicId_ = ACE::strnew (id); +} + +ACEXML_INLINE void +ACEXML_LocatorImpl::setSystemId (const ACEXML_Char *id) +{ + delete this->systemId_; + this->systemId_ = ACE::strnew (id); +} diff --git a/ACEXML/common/Makefile b/ACEXML/common/Makefile new file mode 100644 index 00000000000..72cc7f153f7 --- /dev/null +++ b/ACEXML/common/Makefile @@ -0,0 +1,54 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the server-side ACE network services +#---------------------------------------------------------------------------- + +LIB = libACEXML.a +SHLIB = libACEXML.$(SOEXT) + +FILES = Attributes_Def_Builder \ + AttributesImpl \ + CharStream \ + DefaultHandler \ + DTD_Manager \ + Element_Def_Builder \ + Env \ + Exception \ + FileCharStream \ + InputSource \ + LocatorImpl \ + NamespaceSupport \ + SAXExceptions \ + Transcode \ + Validator \ + XMLFilterImpl + +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/common/NamespaceSupport.cpp b/ACEXML/common/NamespaceSupport.cpp new file mode 100644 index 00000000000..949c265eacb --- /dev/null +++ b/ACEXML/common/NamespaceSupport.cpp @@ -0,0 +1,279 @@ +// -*- C++ -*- $Id$ + +#include "common/NamespaceSupport.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/NamespaceSupport.i" +#endif /* __ACEXML_INLINE__ */ + +static const ACEXML_Char ACEXML_XMLNS_PREFIX_name[] = {'x', 'm', 'l', 'n', 's', 0}; +const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name; + +static const ACEXML_Char ACEXML_DEFAULT_NS_PREFIX[] = {0}; + +static const ACEXML_Char ACEXML_NS_SEPARATOR[] = {':', 0}; + +static const ACEXML_Char ACEXML_TABOO_NS_PREFIX[] = {'x', 'm', 'l', 0}; + +static const ACEXML_Char ACEXML_XMLNS_URI_name[] = { + 'h', 't', 't', 'p', ':', '/', '/', + 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', + 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', + 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', 0}; +const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS = ACEXML_XMLNS_URI_name; + + + + +ACEXML_Namespace_Context_Stack::ACEXML_Namespace_Context_Stack (void) + : head_ (0) +{ +} + +ACEXML_Namespace_Context_Stack::~ACEXML_Namespace_Context_Stack (void) +{ + // Clean up stuff. +} + +int +ACEXML_Namespace_Context_Stack::push (ACEXML_NS_CONTEXT *nsc) +{ + struct NS_Node_T *temp = 0; + ACE_NEW_RETURN (temp, struct NS_Node_T, -1); + + temp->item_ = nsc; + temp->next_ = this->head_; + + this->head_ = temp; + return 0; +} + +ACEXML_NS_CONTEXT * +ACEXML_Namespace_Context_Stack::pop (void) +{ + if (this->head_ != 0) + { + struct NS_Node_T *temp = this->head_; + this->head_ = temp->next_; + + ACEXML_NS_CONTEXT* retv = temp->item_; + delete temp; + return retv; + } + return 0; +} + + +ACEXML_NamespaceSupport::ACEXML_NamespaceSupport (void) + : ns_stack_ (), + effective_context_ (0) +{ + // @@ No way to tell if the new fails. + ACE_NEW (effective_context_, + ACEXML_NS_CONTEXT ()); + + ACEXML_String prefix (ACEXML_TABOO_NS_PREFIX, 0, 0); + ACEXML_String uri (ACEXML_XMLNS_URI_name, 0, 0); + this->effective_context_->bind (prefix, uri); +} + +ACEXML_NamespaceSupport::~ACEXML_NamespaceSupport (void) +{ + while (this->popContext () == 0) + ; +} + +int +ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char *prefix, + const ACEXML_Char *uri) +{ + // Unless predefined by w3.org(?) NS prefix can never start with + // "xml". + if (ACE_OS_String::strcmp (ACEXML_TABOO_NS_PREFIX, prefix) == 0) + return -1; + + // @@ No way to check new failure. + ACEXML_String ns_prefix (prefix, 0, 0); + ACEXML_String ns_uri (uri, 0, 0); + + return this->effective_context_->bind (ns_prefix, + ns_uri); +} + +int +ACEXML_NamespaceSupport::getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const +{ + ACEXML_NS_CONTEXT_ENTRY *entry; + + // The prefix for default namespace (empty string) is included in + // the return list. + for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_); + iter.next (entry) != 0; + iter.advance ()) + prefixes.enqueue_tail (entry->ext_id_.c_str ()); + + return 0; +} + +const ACEXML_Char * +ACEXML_NamespaceSupport::getPrefix (const ACEXML_Char *uri) const +{ + ACEXML_NS_CONTEXT_ENTRY *entry; + + for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_); + iter.next (entry) != 0; + iter.advance ()) + if (entry->int_id_ == ACEXML_String (uri, 0, 0) && + entry->ext_id_ != ACEXML_String (ACEXML_DEFAULT_NS_PREFIX, 0, 0)) + return entry->ext_id_.c_str (); + + return 0; // Nothing found. +} + +int +ACEXML_NamespaceSupport::getPrefixes (ACEXML_STR_LIST &prefixes) const +{ + ACEXML_NS_CONTEXT_ENTRY *entry; + + // The prefix for default namespace (empty string) is not included + // in the return list. + for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_); + iter.next (entry) != 0; + iter.advance ()) + if (entry->ext_id_ != ACEXML_String(ACEXML_DEFAULT_NS_PREFIX, 0, 0)) + prefixes.enqueue_tail (entry->ext_id_.c_str ()); + else + continue; + + return 0; +} + +int +ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri, + ACEXML_STR_LIST &prefixes) const +{ + ACEXML_NS_CONTEXT_ENTRY *entry; + + for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_); + iter.next (entry) != 0; + iter.advance ()) + if (entry->int_id_ == ACEXML_String (uri, 0, 0) && + entry->ext_id_ != ACEXML_String (ACEXML_DEFAULT_NS_PREFIX, 0, 0)) + prefixes.enqueue_tail (entry->ext_id_.c_str ()); + else + continue; + + return 0; // Nothing found. +} + +const ACEXML_Char * +ACEXML_NamespaceSupport::getURI (const ACEXML_Char *prefix) const +{ + ACEXML_NS_CONTEXT_ENTRY *entry; + + if (this->effective_context_->find (ACEXML_String (prefix, 0, 0), + entry) == 0) + return entry->int_id_.c_str (); + return 0; +} + +int +ACEXML_NamespaceSupport::popContext (void) +{ + delete this->effective_context_; + + if ((this->effective_context_ = this->ns_stack_.pop ()) == 0) + return -1; + return 0; +} + +int +ACEXML_NamespaceSupport::pushContext (void) +{ + ACEXML_NS_CONTEXT *temp = this->effective_context_; + this->ns_stack_.push (temp); + ACE_NEW_RETURN (this->effective_context_, + ACEXML_NS_CONTEXT (), + -1); + + // @@ Copy everything from the old context the the new one. + ACEXML_NS_CONTEXT_ENTRY *entry; + + for (ACEXML_NS_CONTEXT_ITER iter (*temp); + iter.next (entry) != 0; + iter.advance ()) + this->effective_context_->bind (entry->ext_id_, + entry->int_id_); + + return 0; +} + + +int +ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName, + const ACEXML_Char *&uri, + const ACEXML_Char *&name, + int is_attribute) const +{ + // @@ Need to use different rules to resolve attributes. + ACE_UNUSED_ARG (is_attribute); + + int qlen = ACE_OS_String::strlen (qName); + int len = -1; + for (int i = 0; i < qlen; ++i) + if (qName [i] == ':') + { + len = i; + break; + } + + ACEXML_String prefix; + + if (len == -1) + { + name = qName; + } + else + { + prefix.set (qName, len, 1); + name = qName + len + 1; + } + ACEXML_NS_CONTEXT_ENTRY *entry; + + if (this->effective_context_->find (prefix, entry) == 0) + uri = entry->int_id_.c_str (); + else + { + uri = ACEXML_DEFAULT_NS_PREFIX; + return -1; + } + + return 0; +} + +int +ACEXML_NamespaceSupport::reset (void) +{ + // Not implemented. + return 0; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Hash_Map_Entry<ACEXML_String, ACEXML_String>; +template class ACE_Hash_Map_Manager_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Base_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>; +template class ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>; +template class ACE_Unbounded_Queue<const ACEXML_Char *>; +template class ACE_Unbounded_Queue_Iterator<const ACEXML_Char *>; +template class ACE_Node<const ACEXML_Char *>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Hash_Map_Entry<ACEXML_String, ACEXML_String> +#pragma instantiate ACE_Hash_Map_Manager_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex> +#pragma instantiate ACE_Unbounded_Queue<const ACEXML_Char *> +#pragma instantiate ACE_Unbounded_Queue_Iterator<const ACEXML_Char *> +#pragma instantiate ACE_Node<const ACEXML_Char *> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/ACEXML/common/NamespaceSupport.h b/ACEXML/common/NamespaceSupport.h new file mode 100644 index 00000000000..b712b063c94 --- /dev/null +++ b/ACEXML/common/NamespaceSupport.h @@ -0,0 +1,228 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file NamespaceSupport.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef ACEXML_NAMESPACESUPPORT_H +#define ACEXML_NAMESPACESUPPORT_H + +#include "common/XML_Types.h" +#include "ace/Functor.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Containers_T.h" + +typedef ACE_Hash_Map_Entry<ACEXML_String, + ACEXML_String> ACEXML_NS_CONTEXT_ENTRY; + +typedef ACE_Hash_Map_Manager_Ex<ACEXML_String, + ACEXML_String, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_NS_CONTEXT; + +typedef ACE_Hash_Map_Iterator_Ex<ACEXML_String, + ACEXML_String, + ACE_Hash<ACEXML_String>, + ACE_Equal_To<ACEXML_String>, + ACE_Null_Mutex> ACEXML_NS_CONTEXT_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_NS_CONTEXT_REVERSE_ITER; + +typedef ACE_Unbounded_Queue<const ACEXML_Char *> ACEXML_STR_LIST; + +/** + * @class ACEXML_Namespace_Context_Stack NamespaceSupport.h "common/NamespaceSupport.h" + * + * @brief ACEXML_Namespace_Context_Stack implements a simple stack + * that ACEXML_NamespaceSupport uses to keep track of namespace scopes. + * + * @sa ACEXML_NamespaceSupport + */ +class ACEXML_Export ACEXML_Namespace_Context_Stack +{ +public: + /// Default constructor. + ACEXML_Namespace_Context_Stack (void); + + /// Destructor. + ~ACEXML_Namespace_Context_Stack (void); + + /// Push the old namespace before entering into a new namespace scope. + int push (ACEXML_NS_CONTEXT * old); + + /// Pop the old namespace when exiting a namespace scope. + ACEXML_NS_CONTEXT *pop (void); + +private: + /// Internal stack structure to hold namespace context. + struct NS_Node_T { + ACEXML_NS_CONTEXT *item_; + struct NS_Node_T *next_; + }; + + /// Anchor point for head of stack. + NS_Node_T *head_; +}; + +/** + * @class ACEXML_NamespaceSupport NamespaceSupport.h "common/NamespaceSupport.h" + * + * @brief ACEXML_NamespaceSupport provides namespace management + * operation for an XML parser. + * + * This class encapsulates the logic of Namespace processing: it + * tracks the declarations currently in force for each context and + * automatically processes qualified XML 1.0 names into their + * Namespace parts; it can also be used in reverse for generating XML + * 1.0 from Namespaces. + * + * Namespace support objects are reusable, but the reset method must + * be invoked between each session. + * + * Here is a simple session (in Java :-p): + * @code + * String parts[] = new String[3]; + * NamespaceSupport support = new NamespaceSupport(); + * + * support.pushContext(); + * support.declarePrefix("", "http://www.w3.org/1999/xhtml"); + * support.declarePrefix("dc", "http://www.purl.org/dc#"); + * + * String parts[] = support.processName("p", parts, false); + * System.out.println("Namespace URI: " + parts[0]); + * System.out.println("Local name: " + parts[1]); + * System.out.println("Raw name: " + parts[2]); + * + * String parts[] = support.processName("dc:title", parts, false); + * System.out.println("Namespace URI: " + parts[0]); + * System.out.println("Local name: " + parts[1]); + * System.out.println("Raw name: " + parts[2]); + * + * support.popContext(); + * @endcode + * + * Note that this class is optimized for the use case where most + * elements do not contain Namespace declarations: if the same + * prefix/URI mapping is repeated for each context (for example), this + * class will be somewhat less efficient. + * + * @sa ACEXML_Exception + */ +class ACEXML_Export ACEXML_NamespaceSupport +{ +public: + /** + * Default constructor. + */ + ACEXML_NamespaceSupport (void); + + /** + * Default destructor. + */ + ~ACEXML_NamespaceSupport (void); + + /** + * XMLNS default prefix and URI strings. + */ + static const ACEXML_Char *XMLNS_PREFIX; + static const ACEXML_Char *XMLNS; + + /** + * Declare a Namespace prefix. Return -1 if the prefix was illegal + * or an internal error occured. Return 0 if the prefix gets declared + * successfully, 1 if the prefix replaces an existing prefix definition. + */ + int declarePrefix (const ACEXML_Char *prefix, + const ACEXML_Char *uri); + + /** + * Return all prefixes declared in current context in + * the user-supplied list @a prefixes. It is user's reponsibility + * to ensure the list was empty originally. + */ + int getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const; + + /** + * Return one of the prefixes mapped to a Namespace URI. + */ + const ACEXML_Char *getPrefix (const ACEXML_Char *uri) const; + + /** + * Return all prefixes currently declared in the user-supplied list. + * @@ Known bug: This function should only return user-defined prefixes. + */ + int getPrefixes (ACEXML_STR_LIST &prefixes) const; + + /** + * Return all prefixes currently declared for a URI in the + * user-supplied list. + */ + int getPrefixes (const ACEXML_Char *uri, + ACEXML_STR_LIST &prefixes) const; + + /** + * Look up a prefix and get the currently-mapped Namespace URI. + */ + const ACEXML_Char *getURI (const ACEXML_Char *prefix) const; + + /** + * Revert to the previous namespace context. + */ + int popContext (void); + + /** + * Process a raw XML 1.0 name. + * @a qName is the raw XML name we want to parse, + * @a uri contains the URI string of the raw name. It points to a null + * string if the namespace is not valid or there's no namespace defined. + * @a name contains the original name without the prefix. + * @a is_attribute specifies whether the name is an attribute or not. + * Attributes have different scoping rules from elements. + */ + int processName (const ACEXML_Char *qName, + const ACEXML_Char *&uri, + const ACEXML_Char *&name, + int is_attribute) const; + + /** + * Start a new Namespace context. Prefixes defined in previous + * context are copied over to the new context. + */ + int pushContext (void); + + /** + * Reset this Namespace support object for reuse. + * @todo Not implemented. + */ + int reset (void); + +private: + /** + * Namespace Context stack. When we entering a new namespace + * context, the old context is duplicated and pushed into + * this stack. + */ + ACEXML_Namespace_Context_Stack ns_stack_; + + /** + * The effective namespace context. + */ + ACEXML_NS_CONTEXT *effective_context_; +}; + + +#if defined (__ACEXML_INLINE__) +# include "common/NamespaceSupport.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_NAMESPACESUPPORT_H */ diff --git a/ACEXML/common/NamespaceSupport.i b/ACEXML/common/NamespaceSupport.i new file mode 100644 index 00000000000..e565785c59b --- /dev/null +++ b/ACEXML/common/NamespaceSupport.i @@ -0,0 +1,16 @@ +// -*- C++ -*- $Id$ + +ACE_TEMPLATE_METHOD_SPECIALIZATION +ACEXML_INLINE int +ACE_Equal_To<ACEXML_String>::operator () (const ACEXML_String &lhs, + const ACEXML_String &rhs) const +{ + return lhs == rhs; +} + +ACE_TEMPLATE_METHOD_SPECIALIZATION +ACE_INLINE u_long +ACE_Hash<ACEXML_String>::operator () (const ACEXML_String &t) const +{ + return ACE::hash_pjw (t.c_str ()); +} diff --git a/ACEXML/common/SAXExceptions.cpp b/ACEXML/common/SAXExceptions.cpp new file mode 100644 index 00000000000..9b310d162d8 --- /dev/null +++ b/ACEXML/common/SAXExceptions.cpp @@ -0,0 +1,269 @@ +// -*- C++ -*- $Id$ + +#include "common/SAXExceptions.h" +#include "ace/Log_Msg.h" +#include "ace/ACE.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/SAXExceptions.i" +#endif /* __ACEXML_INLINE__ */ + +static const ACEXML_Char ACEXML_SAXException_name[] = { + 'A', 'C', 'E', 'X', 'M', 'L', + 'S', 'A', 'X', + '_', 'E', 'x', 'c', 'e', 'p', 't', 'i', 'o', 'n', 0}; +const ACEXML_Char *ACEXML_SAXException::exception_name_ = ACEXML_SAXException_name; + +ACEXML_SAXException::ACEXML_SAXException (void) + : message_ (0) +{ +} + +ACEXML_SAXException::ACEXML_SAXException (const ACEXML_Char *msg) + : message_ (ACE::strnew (msg)) +{ +} + +ACEXML_SAXException::ACEXML_SAXException (const ACEXML_SAXException &ex) + : ACEXML_Exception (ex), + message_ (ACE::strnew (ex.message_)) + +{ +} + + +ACEXML_SAXException::~ACEXML_SAXException (void) +{ + delete this->message_; +} + +const ACEXML_Char * +ACEXML_SAXException::id (void) +{ + return ACEXML_SAXException::exception_name_; +} + +ACEXML_Exception * +ACEXML_SAXException::duplicate (void) +{ + ACEXML_Exception *tmp; + ACE_NEW_RETURN (tmp, + ACEXML_SAXException (*this), + // Replace ACEXML_Exception with appropriate type. + 0); + return tmp; +} + +int +ACEXML_SAXException::is_a (const ACEXML_Char *name) +{ + if (name == ACEXML_SAXException::exception_name_ + || ACE_OS::strcmp (ACEXML_Exception::exception_name_, + name) == 0) + return 1; + else + return this->ACEXML_Exception::is_a (name); + + ACE_NOTREACHED (return 0;) +} + +void +ACEXML_SAXException::print (void) +{ + // @@ Nanbor, I don't know how to handle the case + // when we define ACEXML_UTF16 as ACEXML_Char + ACE_DEBUG ((LM_DEBUG, + "Exception: ACEXML_SAXException -- %s\n", + this->message_)); +} + +static const ACEXML_Char ACEXML_SAXNotSupportedException_name[] = { + 'A', 'C', 'E', 'X', 'M', 'L', + 'S', 'A', 'X', + 'N', 'o', 't', + 'S', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd', + '_', 'E', 'x', 'c', 'e', 'p', 't', 'i', 'o', 'n', 0}; +const ACEXML_Char *ACEXML_SAXNotSupportedException::exception_name_ = ACEXML_SAXNotSupportedException_name; + +ACEXML_SAXNotSupportedException::ACEXML_SAXNotSupportedException (void) +{ +} + +ACEXML_SAXNotSupportedException::ACEXML_SAXNotSupportedException (const ACEXML_SAXNotSupportedException &ex) + : ACEXML_SAXException (ex) +{ +} + + +ACEXML_SAXNotSupportedException::~ACEXML_SAXNotSupportedException (void) +{ + delete this->message_; +} + +const ACEXML_Char * +ACEXML_SAXNotSupportedException::id (void) +{ + return ACEXML_SAXNotSupportedException::exception_name_; +} + +ACEXML_Exception * +ACEXML_SAXNotSupportedException::duplicate (void) +{ + ACEXML_Exception *tmp; + ACE_NEW_RETURN (tmp, + ACEXML_SAXNotSupportedException (*this), + // Replace ACEXML_Exception with appropriate type. + 0); + return tmp; +} + +int +ACEXML_SAXNotSupportedException::is_a (const ACEXML_Char *name) +{ + if (name == ACEXML_SAXNotSupportedException::exception_name_ + || ACE_OS::strcmp (ACEXML_Exception::exception_name_, + name) == 0) + return 1; + else + return this->ACEXML_SAXException::is_a (name); + + ACE_NOTREACHED (return 0;) +} + +void +ACEXML_SAXNotSupportedException::print (void) +{ + ACE_DEBUG ((LM_DEBUG, + "Exception: ACEXML_SAXNotSupportedException -- %s\n", + this->message_)); +} + +static const ACEXML_Char ACEXML_SAXNotRecognizedException_name[] = { + 'A', 'C', 'E', 'X', 'M', 'L', + 'S', 'A', 'X', + 'N', 'o', 't', + 'R', 'e', 'c', 'o', 'g', 'n', 'i', 'z', 'e', 'd', + '_', 'E', 'x', 'c', 'e', 'p', 't', 'i', 'o', 'n', 0}; +const ACEXML_Char *ACEXML_SAXNotRecognizedException::exception_name_ = ACEXML_SAXNotRecognizedException_name; + +ACEXML_SAXNotRecognizedException::ACEXML_SAXNotRecognizedException (void) +{ +} + +ACEXML_SAXNotRecognizedException::ACEXML_SAXNotRecognizedException (const ACEXML_Char *msg) + : ACEXML_SAXException (msg) +{ +} + +ACEXML_SAXNotRecognizedException::ACEXML_SAXNotRecognizedException (const ACEXML_SAXNotRecognizedException &ex) + : ACEXML_SAXException (ex) +{ +} + + +ACEXML_SAXNotRecognizedException::~ACEXML_SAXNotRecognizedException (void) +{ + delete this->message_; +} + +const ACEXML_Char * +ACEXML_SAXNotRecognizedException::id (void) +{ + return ACEXML_SAXNotRecognizedException::exception_name_; +} + +ACEXML_Exception * +ACEXML_SAXNotRecognizedException::duplicate (void) +{ + ACEXML_Exception *tmp; + ACE_NEW_RETURN (tmp, + ACEXML_SAXNotRecognizedException (*this), + // Replace ACEXML_Exception with appropriate type. + 0); + return tmp; +} + +int +ACEXML_SAXNotRecognizedException::is_a (const ACEXML_Char *name) +{ + if (name == ACEXML_SAXNotRecognizedException::exception_name_ + || ACE_OS::strcmp (ACEXML_Exception::exception_name_, + name) == 0) + return 1; + else + return this->ACEXML_SAXException::is_a (name); + + ACE_NOTREACHED (return 0;) +} + +void +ACEXML_SAXNotRecognizedException::print (void) +{ + ACE_DEBUG ((LM_DEBUG, + "Exception: ACEXML_SAXNotRecognizedException -- %s\n", + this->message_)); +} + +static const ACEXML_Char ACEXML_SAXParseException_name[] = { + 'A', 'C', 'E', 'X', 'M', 'L', + 'S', 'A', 'X', + 'P', 'a', 'r', 's', 'e', + '_', 'E', 'x', 'c', 'e', 'p', 't', 'i', 'o', 'n', 0}; +const ACEXML_Char *ACEXML_SAXParseException::exception_name_ = ACEXML_SAXParseException_name; + +ACEXML_SAXParseException::ACEXML_SAXParseException (void) +{ +} + +ACEXML_SAXParseException::ACEXML_SAXParseException (const ACEXML_Char *msg) + : ACEXML_SAXException (msg) +{ +} + +ACEXML_SAXParseException::ACEXML_SAXParseException (const ACEXML_SAXParseException &ex) + : ACEXML_SAXException (ex) +{ +} + + +ACEXML_SAXParseException::~ACEXML_SAXParseException (void) +{ +} + +const ACEXML_Char * +ACEXML_SAXParseException::id (void) +{ + return ACEXML_SAXParseException::exception_name_; +} + +ACEXML_Exception * +ACEXML_SAXParseException::duplicate (void) +{ + ACEXML_Exception *tmp; + ACE_NEW_RETURN (tmp, + ACEXML_SAXParseException (*this), + // Replace ACEXML_Exception with appropriate type. + 0); + return tmp; +} + +int +ACEXML_SAXParseException::is_a (const ACEXML_Char *name) +{ + if (name == ACEXML_SAXParseException::exception_name_ + || ACE_OS::strcmp (ACEXML_Exception::exception_name_, + name) == 0) + return 1; + else + return this->ACEXML_SAXException::is_a (name); + + ACE_NOTREACHED (return 0;) +} + +void +ACEXML_SAXParseException::print (void) +{ + ACE_DEBUG ((LM_DEBUG, + "Exception: ACEXML_SAXParseException -- %s\n", + this->message_)); +} diff --git a/ACEXML/common/SAXExceptions.h b/ACEXML/common/SAXExceptions.h new file mode 100644 index 00000000000..8cf909befda --- /dev/null +++ b/ACEXML/common/SAXExceptions.h @@ -0,0 +1,168 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file SAXExceptions.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_SAXEXCEPTIONS_H_ +#define _ACEXML_SAXEXCEPTIONS_H_ + +#include "common/Exception.h" + +/** + * @class ACEXML_SAXException SAXExceptions.h "common/SAXExceptions.h" + * + * @brief ACEXML_SAXException + * + * ACEXML_SAXException is the mother of all SAX related exceptions. + */ +class ACEXML_Export ACEXML_SAXException : public ACEXML_Exception +{ +public: + /// Default constructor. + ACEXML_SAXException (void); + + /// Constructor initializing the exception message. + ACEXML_SAXException (const ACEXML_Char *msg); + + /// Copy constructor. + ACEXML_SAXException (const ACEXML_SAXException &ex); + + /// Destructor. + virtual ~ACEXML_SAXException (void); + + static const ACEXML_Char *name (void); + + virtual const ACEXML_Char *id (void); + + /// Return the extra message accompanying the exception. + const ACEXML_Char *message (void); + + virtual ACEXML_Exception *duplicate (void); + + virtual int is_a (const ACEXML_Char *name); + + virtual void print (void); + +protected: + static const ACEXML_Char *exception_name_; + + /// A message providing more information about the exception being thrown. + ACEXML_Char *message_; +}; + +/** + * @class ACEXML_SAXNotSupportedException SAXExceptions.h "common/SAXExceptions.h" + * + * @brief ACEXML_SAXNotSupportedException + */ +class ACEXML_Export ACEXML_SAXNotSupportedException + : public ACEXML_SAXException +{ +public: + /// Default constructor. + ACEXML_SAXNotSupportedException (void); + + /// Copy constructor. + ACEXML_SAXNotSupportedException (const ACEXML_SAXNotSupportedException &ex); + + /// Destructor. + virtual ~ACEXML_SAXNotSupportedException (void); + + static const ACEXML_Char *name (void); + + virtual const ACEXML_Char *id (void); + + virtual ACEXML_Exception *duplicate (void); + + virtual int is_a (const ACEXML_Char *name); + + virtual void print (void); + +protected: + static const ACEXML_Char *exception_name_; +}; + +/** + * @class ACEXML_SAXNotRecognizedException SAXExceptions.h "common/SAXExceptions.h" + * + * @brief ACEXML_SAXNotRecognizedException + */ +class ACEXML_Export ACEXML_SAXNotRecognizedException + : public ACEXML_SAXException +{ +public: + /// Default constructor. + ACEXML_SAXNotRecognizedException (void); + + /// Constructor with an initializing exception message. + ACEXML_SAXNotRecognizedException (const ACEXML_Char *msg); + + /// Copy constructor. + ACEXML_SAXNotRecognizedException (const ACEXML_SAXNotRecognizedException &ex); + + /// Destructor. + virtual ~ACEXML_SAXNotRecognizedException (void); + + static const ACEXML_Char *name (void); + + virtual const ACEXML_Char *id (void); + + virtual ACEXML_Exception *duplicate (void); + + virtual int is_a (const ACEXML_Char *name); + + virtual void print (void); + +protected: + static const ACEXML_Char *exception_name_; +}; + +/** + * @class ACEXML_SAXParseException SAXExceptions.h "common/SAXExceptions.h" + * + * @brief ACEXML_SAXParseException + * + * @todo This exception needs to provide error location information to behave like + * the real SAXParseException defined in SAX2 spec. + */ +class ACEXML_Export ACEXML_SAXParseException + : public ACEXML_SAXException +{ +public: + /// Default constructor. + ACEXML_SAXParseException (void); + + /// Constructor with an initializing exception message. + ACEXML_SAXParseException (const ACEXML_Char *msg); + + /// Copy constructor. + ACEXML_SAXParseException (const ACEXML_SAXParseException &ex); + + /// Destructor. + virtual ~ACEXML_SAXParseException (void); + + static const ACEXML_Char *name (void); + + virtual const ACEXML_Char *id (void); + + virtual ACEXML_Exception *duplicate (void); + + virtual int is_a (const ACEXML_Char *name); + + virtual void print (void); + +protected: + static const ACEXML_Char *exception_name_; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/SAXExceptions.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_SAXEXCEPTIONS_H_ */ diff --git a/ACEXML/common/SAXExceptions.i b/ACEXML/common/SAXExceptions.i new file mode 100644 index 00000000000..fc1514c2f12 --- /dev/null +++ b/ACEXML/common/SAXExceptions.i @@ -0,0 +1,33 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE const ACEXML_Char * +ACEXML_SAXException::message (void) +{ + return (this->message_ == 0 ? + ACEXML_Exception::null_ : + this->message_); +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_SAXException::name (void) +{ + return ACEXML_SAXException::exception_name_; +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_SAXNotSupportedException::name (void) +{ + return ACEXML_SAXNotSupportedException::exception_name_; +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_SAXNotRecognizedException::name (void) +{ + return ACEXML_SAXNotRecognizedException::exception_name_; +} + +ACEXML_INLINE const ACEXML_Char * +ACEXML_SAXParseException::name (void) +{ + return ACEXML_SAXParseException::exception_name_; +} diff --git a/ACEXML/common/Transcode.cpp b/ACEXML/common/Transcode.cpp new file mode 100644 index 00000000000..8d767eb9e3d --- /dev/null +++ b/ACEXML/common/Transcode.cpp @@ -0,0 +1,83 @@ +// -*- C++ -*- $Id$ + +#include "common/Transcode.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/Transcode.i" +#endif /* __ACEXML_INLINE__ */ + +int +ACEXML_Transcoder::utf8s2utf16s (const ACEXML_UTF8 *src, + ACEXML_UTF16 *dst, + size_t len) +{ + if (src == 0 || dst == 0) + return INVALID_ARGS; + + size_t src_len = ACE_OS::strlen (src) + 1; + + size_t total_len = 0; + int forward; + ACEXML_UCS4 temp; + + while (src_len > 0) + { + if ((forward = ACEXML_Transcoder::utf82ucs4 (src, + src_len, + temp)) <= 0) + return forward; + + src += forward; + src_len -= forward; + + if ((forward = ACEXML_Transcoder::ucs42utf16 (temp, + dst, + len)) <= 0) + return forward; + + total_len += forward; + dst += forward; + len -= forward; + } + + return total_len; +} + +int +ACEXML_Transcoder::utf16s2utf8s (const ACEXML_UTF16 *src, + ACEXML_UTF8 *dst, + size_t len) +{ + if (src == 0 || dst == 0) + return INVALID_ARGS; + + size_t src_len = 1; + for (const ACEXML_UTF16 *p = src; *p++ != 0; ++src_len) + ; + + size_t total_len = 0; + int forward; + ACEXML_UCS4 temp; + + while (src_len > 0) + { + if ((forward = ACEXML_Transcoder::utf162ucs4 (src, + src_len, + temp)) <= 0) + return forward; + + src += forward; + src_len -= forward; + + if ((forward = ACEXML_Transcoder::ucs42utf8 (temp, + dst, + len)) <= 0) + return forward; + + total_len += forward; + dst += forward; + len -= forward; + } + + return total_len; +} diff --git a/ACEXML/common/Transcode.h b/ACEXML/common/Transcode.h new file mode 100644 index 00000000000..4cfcbb80b27 --- /dev/null +++ b/ACEXML/common/Transcode.h @@ -0,0 +1,93 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Transcode.h + * + * This file declares functions to convert char string among different + * unicode encoding (utf8, utf16, utf32) + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_TRANSCODE_H_ +#define _ACEXML_TRANSCODE_H_ +#include "common/XML_Types.h" + +/** + * @class ACEXML_Transcoder Transcode.h "common/Transcode.h" + * + * @brief ACEXML_Transcoder + * + * Wrapper class for performing transcoding among different UNICODE + * encoding. + */ +class ACEXML_Export ACEXML_Transcoder +{ +public: + enum + { + SUCCESS = 0, + DESTINATION_TOO_SHORT = -1, + END_OF_SOURCE = -2, + INVALID_ARGS = -3, + IS_SURROGATE = -4, + NON_UNICODE = -5 + }; + + + // The following functions translate a unicode characters + // into different encoding. Return number of characters put into + // destination or consumed from src if success without + // error, otherwise, return corresponding error code. + static int utf162utf8 (ACEXML_UTF16 src, + ACEXML_UTF8 *dst, + size_t len); + + static int ucs42utf8 (ACEXML_UCS4 src, + ACEXML_UTF8 *dst, + size_t len); + + static int ucs42utf16 (ACEXML_UCS4 src, + ACEXML_UTF16 *dst, + size_t len); + + static int surrogate2utf8 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UTF8 *dst, + size_t len); + + static int surrogate2ucs4 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UCS4 &dst); + + static int utf82ucs4 (const ACEXML_UTF8 *src, + size_t len, + ACEXML_UCS4 &dst); + + static int utf162ucs4 (const ACEXML_UTF16 *src, + size_t len, + ACEXML_UCS4 &dst); + +// static int utf82utf16 (const ACEXML_UTF8 *src, +// size_t len, +// ACEXML_UTF16 &dst); + // This function does not handle surrogates. + + // The following functions are non-inlined: + static int utf8s2utf16s (const ACEXML_UTF8 *src, + ACEXML_UTF16 *dst, + size_t len); + + static int utf16s2utf8s (const ACEXML_UTF16 *src, + ACEXML_UTF8 *dst, + size_t len); +}; + +#if defined (__ACEXML_INLINE__) +# include "common/Transcode.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* _ACEXML_TRANSCODE_H_ */ diff --git a/ACEXML/common/Transcode.i b/ACEXML/common/Transcode.i new file mode 100644 index 00000000000..e9ec3936e80 --- /dev/null +++ b/ACEXML/common/Transcode.i @@ -0,0 +1,234 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE int +ACEXML_Transcoder::utf162utf8 (ACEXML_UTF16 src, + ACEXML_UTF8 *dst, + size_t len) +{ + // Check for valid argument first... + + if (dst == 0) + return INVALID_ARGS; + + if (src < 0x80) + { + if (len < 1) + return DESTINATION_TOO_SHORT; + + *dst = ACE_static_cast (ACEXML_UTF8, src); + return 1; + } + else if (src < 0x800) + { + if (len < 2) + return DESTINATION_TOO_SHORT; + + *dst = 0xc0 | (src / 0x40); + *(dst+1) = 0x80 | (src % 0x40); + return 2; + } + else + { + if (len < 3) + return DESTINATION_TOO_SHORT; + + // Surrogates (0xD800 - 0xDFFF) are not valid unicode values + if (src >= 0xD800 && src < 0xE000) + return IS_SURROGATE; + + *dst = 0xe0 | (src / 0x1000); + *(dst+1) = 0x80 | ((src % 0x1000) / 0x40); + *(dst+2) = 0x80 | (src % 0x40); + return 3; + } + ACE_NOTREACHED (return NON_UNICODE;) +} + +ACEXML_INLINE int +ACEXML_Transcoder::ucs42utf8 (ACEXML_UCS4 src, + ACEXML_UTF8 *dst, + size_t len) +{ + if (src < 0x10000) + { + int retv = ACEXML_Transcoder::utf162utf8 + (ACE_static_cast (ACEXML_UTF16, src), + dst, len); + return (retv == IS_SURROGATE ? NON_UNICODE : retv); + } + else if (src >= 0x100000 && src < 0x110000) + { + if (len < 4) + return DESTINATION_TOO_SHORT; + + if (dst == 0) + return INVALID_ARGS; + + *dst = 0xf0 | (src / 0x40000); + *(dst+1) = 0x80 | ((src % 0x40000) / 0x1000); + *(dst+2) = 0x80 | ((src % 0x1000) / 0x40); + *(dst+3) = 0x80 | (src % 0x40); + return 4; + } + return NON_UNICODE; +} + + +ACEXML_INLINE int +ACEXML_Transcoder::ucs42utf16 (ACEXML_UCS4 src, + ACEXML_UTF16 *dst, + size_t len) +{ + if (dst == 0) + return INVALID_ARGS; + + if (src < 0x10000) + { + if (len < 1) + return DESTINATION_TOO_SHORT; + + if (src >= 0xD800 && src < 0xE000) + return NON_UNICODE; // Surrogates are not valid unicode value + + *dst = ACE_static_cast (ACEXML_UTF16, src); + return 1; + } + else if (src >= 0x100000 && src < 0x110000) + // Scalar values are encoded into surrogates + { + if (len < 2) + return DESTINATION_TOO_SHORT; + + *dst = 0xD800 | (src / 0x400); + *(dst+1) = 0xDC00 | (src % 0x400); + return 2; + } + + return NON_UNICODE; +} + +ACEXML_INLINE int +ACEXML_Transcoder::surrogate2utf8 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UTF8 *dst, + size_t len) +{ + if (len < 3) + return DESTINATION_TOO_SHORT; + + if (dst == 0 || + (high >= 0xD800 && high < 0xDC00) || + (low >= 0xDC00 && low < 0xE000)) + return INVALID_ARGS; + + ACEXML_UCS4 src = (high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000; + *dst = 0xD800 | (src / 0x400); + *(dst+1) = 0xDC00 | (src % 0x400); + return 2; +} + +ACEXML_INLINE int +ACEXML_Transcoder::surrogate2ucs4 (ACEXML_UTF16 high, + ACEXML_UTF16 low, + ACEXML_UCS4 &dst) +{ + if ((high >= 0xD800 && high < 0xDC00) || + (low >= 0xDC00 && low < 0xE000)) + return INVALID_ARGS; + + dst = (high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000; + return SUCCESS; +} + +ACEXML_INLINE int +ACEXML_Transcoder::utf82ucs4 (const ACEXML_UTF8 *the_src, + size_t len, + ACEXML_UCS4 &dst) +{ + if (the_src == 0) + return INVALID_ARGS; + + const unsigned char *src = ACE_reinterpret_cast (const unsigned char *, + the_src); + + size_t forward = 1; + + if (forward > len) + return END_OF_SOURCE; + + if (ACE_static_cast (unsigned char, *src) < 0x80) + dst = *src; + else if ((*src & 0xE0) == 0xC0) + { + dst = (*(src++) & 0x1f) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; // Error transcoding unicode scalar + dst += *src & 0x3f; + } + else if ((*src & 0xF0) == 0xE0) + { + dst = (*src++ & 0x0f) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; + dst = (dst + (*src++ & 0x3f)) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; + dst += *src & 0x3f; + } + else if ((*src & 0xF8) == 0xF0) + { + dst = (*src++ & 0x0f) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; + dst = (dst + (*src++ & 0x3f)) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; + dst = (dst + (*src++ & 0x3f)) * 0x40; + if (++forward > len) + return END_OF_SOURCE; + if ((*src & 0xC0) != 0x80) + return NON_UNICODE; + dst += *src & 0x3f; + } + else + return NON_UNICODE; + + return forward; +} + +ACEXML_INLINE int +ACEXML_Transcoder::utf162ucs4 (const ACEXML_UTF16 *src, + size_t len, + ACEXML_UCS4 &dst) +{ + if (src == 0) + return INVALID_ARGS; + + size_t forward = 1; + if (*src >= 0xDC00 && *src < 0xE000) + { + if (len < 2) + return END_OF_SOURCE; + return ACEXML_Transcoder::surrogate2ucs4 (*src, + *(src+1), + dst); + } + else + { + if (len < 1) + return END_OF_SOURCE; + dst = *src; + } + + return forward; +} diff --git a/ACEXML/common/Validator.cpp b/ACEXML/common/Validator.cpp new file mode 100644 index 00000000000..7e6d4c1e847 --- /dev/null +++ b/ACEXML/common/Validator.cpp @@ -0,0 +1,8 @@ +// $Id$ + +#include "common/Validator.h" + +ACEXML_Validator::~ACEXML_Validator () +{ + +} diff --git a/ACEXML/common/Validator.h b/ACEXML/common/Validator.h new file mode 100644 index 00000000000..6e65043f8a4 --- /dev/null +++ b/ACEXML/common/Validator.h @@ -0,0 +1,57 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Validator.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_VALIDATOR_H_ +#define _ACEXML_VALIDATOR_H_ + +#include "common/Attributes.h" +#include "common/Env.h" + +/** + * @ class ACEXML_Validator Validator.h "common/Validator.h" + * + * @ brief An abstract virtual class defining validator interface. + * + * An validator provides validation service for one XML element. + * ACEXML_Validators are stateful object. Implementations should + * remember the current element encountered and determine if + * it's a valid sequence of child elements. A parser fishes + * out a validator of certain + */ +class ACEXML_Export ACEXML_Validator +{ +public: + virtual ~ACEXML_Validator () = 0; + + /** + * Validate attributes of an element. + * + * @retval 0 if valid, -1 otherwise. + */ + virtual int startElement (ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * Validate the next child element. + * + * @retval 0 if valid, -1 otherwise. + */ + virtual int nextElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; +}; + +#endif /* _ACEXML_VALIDATOR_H_ */ diff --git a/ACEXML/common/XMLFilter.h b/ACEXML/common/XMLFilter.h new file mode 100644 index 00000000000..da09fa723ac --- /dev/null +++ b/ACEXML/common/XMLFilter.h @@ -0,0 +1,46 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file XMLFilter.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_XMLFILTER_H_ +#define _ACEXML_XMLFILTER_H_ + +#include "common/XMLReader.h" + +/** + * @class ACEXML_XMLFilter XMLFilter.h "common/XMLFilter.h" + * + * @brief ACEXML_XMLFilter + * + * An XML filter is like an XML reader, except + * that it obtains its events from another XML reader rather than a + * primary source like an XML document or database. Filters can modify + * a stream of events as they pass on to the final application. + * + * The XMLFilterImpl helper class provides a convenient base for + * creating SAX2 filters, by passing on all ACEXML_EntityResolver, + * ACEXML_DTDHandler, ACEXML_ContentHandler and ACEXML_ErrorHandler + * events automatically. + */ +class ACEXML_Export ACEXML_XMLFilter : public ACEXML_XMLReader +{ +public: + /** + * Get the parent reader. + */ + virtual ACEXML_XMLReader *getParent (void) const = 0; + + /** + * Set the parent reader. + */ + virtual void setParent (ACEXML_XMLReader *parent) = 0; +}; + +#endif /* _ACEXML_XMLFILTER_H_ */ diff --git a/ACEXML/common/XMLFilterImpl.cpp b/ACEXML/common/XMLFilterImpl.cpp new file mode 100644 index 00000000000..e577ee748ce --- /dev/null +++ b/ACEXML/common/XMLFilterImpl.cpp @@ -0,0 +1,380 @@ +// -*- C++ -*- $Id$ + +#include "common/XMLFilterImpl.h" + +#if !defined (__ACEXML_INLINE__) +# include "common/XMLFilterImpl.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_XMLFilterImpl::ACEXML_XMLFilterImpl (void) + : parent_ (0), + locator_ (0), + entityResolver_ (0), + dtdHandler_ (0), + contentHandler_ (0), + errorHandler_ (0) +{ +} + +ACEXML_XMLFilterImpl::ACEXML_XMLFilterImpl (ACEXML_XMLReader *parent) + : parent_ (parent), + locator_ (0), + entityResolver_ (0), + dtdHandler_ (0), + contentHandler_ (0), + errorHandler_ (0) +{ +} + +ACEXML_XMLFilterImpl::~ACEXML_XMLFilterImpl (void) +{ + // @@ How are all the object lifecycles managed? +} + +void +ACEXML_XMLFilterImpl::parse (ACEXML_InputSource *input, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->setupParser () < 0) + { + xmlenv.exception (new ACEXML_SAXException (ACE_LIB_TEXT ("No Parent available"))); + return; + } + this->parent_->parse (input, xmlenv); + return; +} + +void +ACEXML_XMLFilterImpl::parse (const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->setupParser () < 0) + { + xmlenv.exception (new ACEXML_SAXException (ACE_LIB_TEXT ("No Parent available"))); + return; + } + + this->parent_->parse (new ACEXML_InputSource (systemId), + xmlenv); + return; +} + +int +ACEXML_XMLFilterImpl::getFeature (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (this->parent_ != 0) + return this->parent_->getFeature (name, + xmlenv); + + xmlenv.exception (new ACEXML_SAXNotRecognizedException (name)); + return 0; +} + +void * +ACEXML_XMLFilterImpl::getProperty (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (this->parent_ != 0) + return this->parent_->getProperty (name, + xmlenv); + + xmlenv.exception (new ACEXML_SAXNotRecognizedException (name)); + return 0; +} + +void +ACEXML_XMLFilterImpl::setFeature (const ACEXML_Char *name, + int boolean_value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (this->parent_ != 0) + { + this->parent_->setFeature (name, + boolean_value, + xmlenv); + return; + } + + xmlenv.exception (new ACEXML_SAXNotRecognizedException (name)); +} + +void +ACEXML_XMLFilterImpl::setProperty (const ACEXML_Char *name, + void *value, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) +{ + if (this->parent_ != 0) + { + this->parent_->setProperty (name, + value, + xmlenv); + return; + } + + xmlenv.exception (new ACEXML_SAXNotRecognizedException (name)); +} + +ACEXML_XMLReader * +ACEXML_XMLFilterImpl::getParent (void) const +{ + return this->parent_; +} + +void +ACEXML_XMLFilterImpl::setParent (ACEXML_XMLReader *parent) +{ + this->parent_ = parent; +} + +void +ACEXML_XMLFilterImpl::characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->characters (ch, start, length, xmlenv); +} + +void +ACEXML_XMLFilterImpl::endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->endDocument (xmlenv); +} + +void +ACEXML_XMLFilterImpl::endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->endElement (namespaceURI, + localName, + qName, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->endPrefixMapping (prefix, xmlenv); +} + +void +ACEXML_XMLFilterImpl::ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->ignorableWhitespace (ch, + start, + length, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->processingInstruction (target, + data, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->setDocumentLocator (locator, xmlenv); +} + +void +ACEXML_XMLFilterImpl::skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->skippedEntity (name, xmlenv); +} + +void +ACEXML_XMLFilterImpl::startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->startDocument (xmlenv); +} + +void +ACEXML_XMLFilterImpl::startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->startElement (namespaceURI, + localName, + qName, + atts, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->contentHandler_ != 0) + this->contentHandler_->startPrefixMapping (prefix, + uri, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->dtdHandler_ != 0) + this->dtdHandler_->notationDecl (name, + publicId, + systemId, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->dtdHandler_ != 0) + this->dtdHandler_->unparsedEntityDecl (name, + publicId, + systemId, + notationName, + xmlenv); +} + +ACEXML_InputSource * +ACEXML_XMLFilterImpl::resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->entityResolver_ != 0) + return this->entityResolver_->resolveEntity (publicId, + systemId, + xmlenv); + return 0; +} + +void +ACEXML_XMLFilterImpl::error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->errorHandler_ != 0) + this->errorHandler_->error (exception, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->errorHandler_ != 0) + this->errorHandler_->fatalError (exception, + xmlenv); +} + +void +ACEXML_XMLFilterImpl::warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + if (this->errorHandler_ != 0) + this->errorHandler_->warning (exception, + xmlenv); +} + +ACEXML_DTDHandler * +ACEXML_XMLFilterImpl::getDTDHandler (void) const +{ + return this->dtdHandler_; +} + +ACEXML_ContentHandler * +ACEXML_XMLFilterImpl::getContentHandler (void) const +{ + return this->contentHandler_; +} + +ACEXML_EntityResolver * +ACEXML_XMLFilterImpl::getEntityResolver (void) const +{ + return this->entityResolver_; +} + +ACEXML_ErrorHandler * +ACEXML_XMLFilterImpl::getErrorHandler (void) const +{ + return this->errorHandler_; +} + +void +ACEXML_XMLFilterImpl::setDTDHandler (ACEXML_DTDHandler *handler) +{ + this->dtdHandler_ = handler; +} + +void +ACEXML_XMLFilterImpl::setContentHandler (ACEXML_ContentHandler *handler) +{ + this->contentHandler_ = handler; +} + +void +ACEXML_XMLFilterImpl::setEntityResolver (ACEXML_EntityResolver *handler) +{ + this->entityResolver_ = handler; +} + +void +ACEXML_XMLFilterImpl::setErrorHandler (ACEXML_ErrorHandler *handler) +{ + this->errorHandler_ = handler; +} diff --git a/ACEXML/common/XMLFilterImpl.h b/ACEXML/common/XMLFilterImpl.h new file mode 100644 index 00000000000..16429e51146 --- /dev/null +++ b/ACEXML/common/XMLFilterImpl.h @@ -0,0 +1,333 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file XMLFilterImpl.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef ACEXML_XMLFILTERIMPL_H +#define ACEXML_XMLFILTERIMPL_H + +#include "common/XMLFilter.h" +#include "common/XMLReader.h" +#include "common/Locator.h" +#include "common/ContentHandler.h" +#include "common/DTDHandler.h" +#include "common/EntityResolver.h" +#include "common/ErrorHandler.h" + +/** + * @class ACEXML_XMLFilterImpl XMLFilterImpl.h "common/XMLFilterImpl.h" + * + * @brief ACEXML_XMLFilterImpl + * + * This class is designed to sit between an XMLReader and the client + * application's event handlers. By default, it does nothing but pass + * requests up to the reader and events on to the handlers unmodified, + * but subclasses can override specific methods to modify the event + * stream or the configuration requests as they pass through. + */ +class ACEXML_Export ACEXML_XMLFilterImpl + : public ACEXML_XMLFilter, + public ACEXML_ContentHandler, + public ACEXML_DTDHandler, + public ACEXML_EntityResolver, + public ACEXML_ErrorHandler +{ +public: + /** + * Default constructor. Create with no parent. + */ + ACEXML_XMLFilterImpl (void); + + /** + * Construct an XML filter with the specified parent. + */ + ACEXML_XMLFilterImpl (ACEXML_XMLReader *parent); + + /** + * Destructor. + */ + virtual ~ACEXML_XMLFilterImpl (void); + + /* + * Look up the value of a feature. + */ + 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)) + ; + + /* + * Set the state of 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)) + ; + + /* + * Get the parent reader. + */ + virtual ACEXML_XMLReader *getParent (void) const; + + /* + * Set the parent reader. + */ + virtual void setParent (ACEXML_XMLReader *parent); + + /* + * Get the current DTD event handler. + */ + virtual ACEXML_DTDHandler *getDTDHandler (void) const; + + /* + * Get the current content event handler. + */ + virtual ACEXML_ContentHandler *getContentHandler (void) const; + + /* + * Get the current entity resolver. + */ + virtual ACEXML_EntityResolver *getEntityResolver (void) const; + + /* + * Get the current error event handler. + */ + virtual ACEXML_ErrorHandler *getErrorHandler (void) const; + + /* + * Set the DTD event handler. + */ + virtual void setDTDHandler (ACEXML_DTDHandler *handler); + + /* + * Set the content event handler. + */ + virtual void setContentHandler (ACEXML_ContentHandler *handler); + + /* + * Set the entity resolver. + */ + virtual void setEntityResolver (ACEXML_EntityResolver *handler); + + /* + * Set the error event handler. + */ + virtual void setErrorHandler (ACEXML_ErrorHandler *handler); + + /* + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of a document. + */ + virtual void endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of an element. + */ + virtual void endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * End the scope of a prefix-URI mapping. + */ + virtual void endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of ignorable whitespace in element content. + */ + virtual void ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a processing instruction. + */ + virtual void processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive an object for locating the origin of SAX document events. + */ + virtual void setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) ; + + /* + * Receive notification of a skipped entity. + */ + virtual void skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of a document. + */ + virtual void startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of an element. + */ + virtual void startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Begin the scope of a prefix-URI Namespace mapping. + */ + virtual void startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // *** Methods inherit from ACEXML_DTDHandler. + + /* + * Receive notification of a notation declaration event. + */ + virtual void notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of an unparsed entity declaration event. + */ + virtual void unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_EnitityResolver. + + /* + * Allow the application to resolve external entities. + */ + virtual ACEXML_InputSource *resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ + virtual void error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a non-recoverable error. + */ + virtual void fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a warning. + */ + virtual void warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; +protected: + int setupParser (void); + // Set up the event handlers of parent parser to this. + // Returns -1 if no valid parent is set. + +private: + ACEXML_XMLReader *parent_; + ACEXML_Locator *locator_; + ACEXML_EntityResolver *entityResolver_; + ACEXML_DTDHandler *dtdHandler_; + ACEXML_ContentHandler *contentHandler_; + ACEXML_ErrorHandler *errorHandler_; +}; + +#if defined (__ACEXML_INLINE__) +# include "common/XMLFilterImpl.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_XMLFILTERIMPL_H */ diff --git a/ACEXML/common/XMLFilterImpl.i b/ACEXML/common/XMLFilterImpl.i new file mode 100644 index 00000000000..4be2ceeceea --- /dev/null +++ b/ACEXML/common/XMLFilterImpl.i @@ -0,0 +1,14 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE int +ACEXML_XMLFilterImpl::setupParser (void) +{ + if (this->parent_ == 0) + return -1; + + this->parent_->setEntityResolver (this); + this->parent_->setDTDHandler (this); + this->parent_->setContentHandler (this); + this->parent_->setErrorHandler (this); + return 0; +} diff --git a/ACEXML/common/XMLReader.h b/ACEXML/common/XMLReader.h new file mode 100644 index 00000000000..9586c9a3484 --- /dev/null +++ b/ACEXML/common/XMLReader.h @@ -0,0 +1,136 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file XMLReader.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= +#ifndef _ACEXML_XMLREADER_H_ +#define _ACEXML_XMLREADER_H_ + +#include "common/ContentHandler.h" +#include "common/DTDHandler.h" +#include "common/EntityResolver.h" +#include "common/ErrorHandler.h" + +/** + * @class ACEXML_XMLReader XMLReader.h "common/XMLReader.h" + * + * @brief ACEXML_XMLReader + * + * XMLReader is the interface that an XML parser's SAX2 driver must + * implement. This interface allows an application to set and query + * features and properties in the parser, to register event handlers + * for document processing, and to initiate a document parse. + * + * All SAX interfaces are assumed to be synchronous: the parse methods + * must not return until parsing is complete, and readers must wait + * for an event-handler callback to return before reporting the next + * event. + */ +class ACEXML_Export ACEXML_XMLReader +{ +public: + /** + * Return the current content handler. + */ + virtual ACEXML_ContentHandler *getContentHandler (void) const = 0; + + /** + * Return the current DTD handler. + */ + virtual ACEXML_DTDHandler *getDTDHandler (void) const = 0; + + /** + * Return the current entity resolver. + */ + virtual ACEXML_EntityResolver *getEntityResolver (void) const = 0; + + /** + * Return the current error handler. + */ + virtual ACEXML_ErrorHandler *getErrorHandler (void) const = 0; + + /** + * 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)) + = 0; + + /** + * Look up the value of a property. + */ + virtual void * getProperty (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException, + // ACEXML_SAXNotSupportedException)) + = 0; + + /** + * Parse an XML document. + */ + virtual void parse (ACEXML_InputSource *input, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + = 0; + + /** + * 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)) + = 0; + + /** + * Allow an application to register a content event handler. + */ + virtual void setContentHandler (ACEXML_ContentHandler *handler) = 0; + + /** + * Allow an application to register a DTD event handler. + */ + virtual void setDTDHandler (ACEXML_DTDHandler *handler) = 0; + + /** + * Allow an application to register an entity resolver. + */ + virtual void setEntityResolver (ACEXML_EntityResolver *resolver) = 0; + + /** + * Allow an application to register an error event handler. + */ + virtual void setErrorHandler (ACEXML_ErrorHandler *handler) = 0; + + /** + * 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)) + = 0; + + /** + * 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)) + = 0; +}; + +#endif /* _ACEXML_XMLREADER_H_ */ diff --git a/ACEXML/common/XML_Common.dsp b/ACEXML/common/XML_Common.dsp new file mode 100644 index 00000000000..29c6a947fbb --- /dev/null +++ b/ACEXML/common/XML_Common.dsp @@ -0,0 +1,283 @@ +# Microsoft Developer Studio Project File - Name="XML_Common" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=XML_Common - 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 "XML_Common.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 "XML_Common.mak" CFG="XML_Common - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "XML_Common - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "XML_Common - 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)" == "XML_Common - 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 "XML_COMMON_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../.." /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "ACEXML_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 /nologo /dll /machine:I386 /out:"../../bin/ACEXML.dll" /libpath:"w:\ace_wrappers\ace"
+
+!ELSEIF "$(CFG)" == "XML_Common - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "XML_Common___Win32_Debug"
+# PROP BASE Intermediate_Dir "XML_Common___Win32_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 "XML_COMMON_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../.." /I ".." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D ACEXML_HAS_DLL=1 /D "ACEXML_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 /nologo /dll /debug /machine:I386 /out:"../../bin/ACEXMLD.dll" /pdbtype:sept /libpath:"w:\ace_wrappers\ace"
+
+!ENDIF
+
+# Begin Target
+
+# Name "XML_Common - Win32 Release"
+# Name "XML_Common - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Attributes_Def_Builder.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\AttributesImpl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\CharStream.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DefaultHandler.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\DTD_Manager.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Element_Def_Builder.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Env.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Exception.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\FileCharStream.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\InputSource.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\LocatorImpl.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\NamespaceSupport.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\SAXExceptions.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Transcode.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Validator.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLFilterImpl.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\ACEXML_Export.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Attributes.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Attributes_Def_Builder.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\AttributesImpl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\CharStream.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ContentHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DefaultHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DTD_Manager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\DTDHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Element_Def_Builder.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\EntityResolver.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Env.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ErrorHandler.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Exception.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FileCharStream.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\InputSource.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Locator.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\LocatorImpl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\NamespaceSupport.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SAXExceptions.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Transcode.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Validator.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XML_Types.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLFilter.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLFilterImpl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\XMLReader.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 Group "Inline Files"
+
+# PROP Default_Filter "i"
+# Begin Source File
+
+SOURCE=.\Env.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Exception.i
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/ACEXML/common/XML_Types.h b/ACEXML/common/XML_Types.h new file mode 100644 index 00000000000..bcb5edc6e21 --- /dev/null +++ b/ACEXML/common/XML_Types.h @@ -0,0 +1,71 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file XML_Types.h + * + * This file collects the type definitions for data types + * used in ACE XML parser. + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef _ACEXML_XML_TYPES_H_ +# define _ACEXML_XML_TYPES_H_ +# include "ace/OS.h" +# include "ace/SString.h" +# include "common/ACEXML_Export.h" + +# if defined (ACE_HAS_WCHAR) && (ACE_SIZEOF_WCHAR == 2) +typedef wchar_t ACEXML_UTF16; +# else +typedef ACE_USHORT16 ACEXML_UTF16; +# endif /* ACE_HAS_WCHAR && ACE_SIZEOF_WCHAR == 2 */ + +# if defined (ACE_HAS_WCHAR) && (ACE_SIZEOF_WCHAR == 4) +typedef wchar_t ACEXML_UCS4; +# else +typedef ACE_UINT32 ACEXML_UCS4; +# endif /* ACE_HAS_WCHAR && ACE_SIZEOF_WCHAR == 4 */ + +typedef char ACEXML_UTF8; + +/** + * @typedef ACEXML_Char + * ACEXML_Char only maps to ACEXML_UTF16 when ACE_USES_WCHAR is defined. + * Here we assume sizeof (wchar_t) is always 2 bytes. + * + * Defulat XML strings will use UTF-8 encoding. We would like to use + * the string classes in standard C++ Library here. But they are not + * very portable yet (as far as I know,) and I'll just use ACE_CString + * for now, unless UNICODE support is turned on. Notice that you + * should never convert strings between ACE_CString and ACE_WString + * using the built-in conversion functions as they only perform simple + * copy without any encoding conversion. + */ +# if defined (ACE_USES_WCHAR) +typedef ACEXML_UTF16 ACEXML_Char; +typedef ACE_WString ACEXML_String; +# else +typedef ACEXML_UTF8 ACEXML_Char; +typedef ACE_CString ACEXML_String; +# endif /* ACE_USES_WCHAR */ + +# if (!defined (ACEXML_HAS_INLINE) && defined (__ACE_INLINE__)) || (ACEXML_HAS_INLINE == 1) +# define __ACEXML_INLINE__ inline +# else +# if defined (__ACEXML_INLINE__) +# undefine __ACEXML_INLINE__ +# endif /* __ACEXML_INLINE__ */ +# endif /* (!ACEXML_HAS_INLINE) && (__ACE_INLINE__) || (ACEXML_HAS_INLINE == 1) */ + +# if defined (__ACEXML_INLINE__) +# define ACEXML_INLINE inline +# else +# define ACEXML_INLINE +# endif /* __ACEXML_INLINE */ + +#endif /* _ACEXML_XML_TYPE_H_ */ diff --git a/ACEXML/docs/TODO.txt b/ACEXML/docs/TODO.txt new file mode 100644 index 00000000000..022c75c4fc7 --- /dev/null +++ b/ACEXML/docs/TODO.txt @@ -0,0 +1,40 @@ +/** +@page acexml_todo ACEXML TO-DO List + +<ul> + + <li>Make the parser dynamically loadable + + <li>Decouple ACE_Svc_Configurator from ACE Library. Allow users to + load in different configurator/parsers. + + <li>Add Namespace support. The basic supporting mechanisms are + already in place. The parser itself, however, does not take + advantage of them to differentiate the different namespace. + + <li>Add Schema paring ability. It is not clear to me, however, how + to specify which schema a document is associated with. + + <li>Add support for resolving external entities, such as a + schema/namespace definition located on the web. There should be + a factory object to create various kinds of @ref CharStream + based on the URN or <i>PEReference</i> being parsed. + + <li>Add parameterized entity management class. See above. + + <li>A char stream should be able to differentiate the file encoding + and perform the correct transcoding automatically. + + <li>Add a new FileCharStream class that understand UTF-16 encoded files. + + <li>Add a class to determine the encoding of an XML file automatically. + + <li>Need to support ACEXML_Locator in the parser. There's currently + no way to tell the location where the parser is parsing or where + an error occurred. + + <li>Define validator building/calling interfaces. + +</ul> + +*/
\ No newline at end of file diff --git a/ACEXML/docs/bugs.txt b/ACEXML/docs/bugs.txt new file mode 100644 index 00000000000..11baef88416 --- /dev/null +++ b/ACEXML/docs/bugs.txt @@ -0,0 +1,25 @@ +/** +@page acexml_bugs ACEXML Known Bugs + +<ul> + <li>ACEXML currently do not validate an XML files. + + <li>Exception handling is not implemented. Maybe we should not try + to use the environment variables/exceptions scheme again. + Considering changing to a simpler error reporting method. + + <li>Need to verify predefined entities are working correctly. Check + out the SAXPrint example. + + <li>Currently, replacement of parameterized reference (PEReference) is + not working. + + <li>Although most namespace supporting features/interfaces are + there, the parser currently does not interpret namespace. + + <li>I'm sure this list will grow. :) + +</ul> + + +*/
\ No newline at end of file diff --git a/ACEXML/docs/guidelines.txt b/ACEXML/docs/guidelines.txt new file mode 100644 index 00000000000..eb14f5af560 --- /dev/null +++ b/ACEXML/docs/guidelines.txt @@ -0,0 +1,33 @@ +// -*- HTML-Helper -*- $Id$ + +/** +@page acexml_guides ACEXML Programming Guidelines + +<ul> + <li>Character encoding: The default character encoding for ACEXML + can be set at compile time. ACEXML uses UTF-8 encoding in most + platforms where <code>ACEXML_Char</code> maps to + <code>char</code> in this case. When ACE is configured to use + <CODE>wchar</CODE> and <CODE>UNICODE</CODE>, ACEXML uses UTF-16 + encoding and <code>ACEXML_Char</code> maps to + <code>wchar_t</code>. Notice that ACEXML assume + <code>sizeof (wchar_t)</code> is of 2-byte long. For platforms + using 4-byte <code>wchar_t</code>, ACEXML will not work + correctly but it should be trivial to fix.<p> + + <li>Currently, there's only an example showing how to use the parser + under @c $(ACE_ROOT)/XML/examples/SAXPrint/. + + <li>To develop a new validator, one must create a DLL implementing + @c ACEXML_Attributes_Def_Builder, @c + ACEXML_Attribute_Def_Builder, @c ACEXML_Element_Def_Builder, + @c ACEXML_Validator, and @c ACEXML_DTD_Manager. The DLL should + also export a traditional C function called @c + create_dtd_manager. The XML parser itself should also be + modified to support and dynamically link with the new validator. + See @c $(ACE_ROOT)/XML/parser/debug_validator/ for an example. + +</ul> + + +*/
\ No newline at end of file diff --git a/ACEXML/docs/parser_features.txt b/ACEXML/docs/parser_features.txt new file mode 100644 index 00000000000..164ecbe55bd --- /dev/null +++ b/ACEXML/docs/parser_features.txt @@ -0,0 +1,21 @@ +/** -*- HTML-Helper -*- $Id$ +@defgroup acexml_parser_features Configurable Special Features of ACEXML Parser +@{ + +There are special features in ACEXML Parser that can be +activated/deactivated thru @c setFeature. Likewise, whether a feature +has been activated or not can be queried using @c getFeature. + +@sa ACEXML_XMLReader::setFeature +@sa ACEXML_XMLReader::getFeature + +Here is a list of supported features: + +<OL> + <li> None so far. We are integrating a dummy debug validator into + the parser which will use the string "Dummy Debug Validator" to turn + the feature on/off. +</OL> + +@} +*/
\ No newline at end of file diff --git a/ACEXML/docs/readme.txt b/ACEXML/docs/readme.txt new file mode 100644 index 00000000000..f0de833b526 --- /dev/null +++ b/ACEXML/docs/readme.txt @@ -0,0 +1,36 @@ +/** -*- HTML-Helper -*- $Id$ +@mainpage ACEXML - A Small and Portable XML Parser + +@section acexml_synopsis Synopsis +ACEXML is a small footprint and portable framework for integrating XML +parsing ability into user applications. The framework is based on the + <a href="http://www.saxproject.org/"> Simple API for XML +(SAX 2.0) </A> by David Megginson. A simple non-conformant XML parser +is also included in the framework. Since our original motivation was +to use the parser for specifying software composition and +configuration descriptors, at the current stage, the parser does not +fully support all the features specified in the XML specification. + +We do, however, plan to add more features to the parser and will +either release a more versatile parser or allow the current parser to +dynamically load in the extra features in the future. + +@section acexml_features Features of ACEXML +<ul> + <li> ACEXML only recognize UNICODE documents, although they can be + in various different encoding, such as UTF-8, UTF-16, or UCS-4. + Therefore, it might be a problem to handle document containing + multi-byte charatersets. They can, however, be translated into + UNICODE before being parsed by ACEXML parser. +</ul> + + +@section acexml_others Other Topics +<ol> + <li>@ref acexml_parser_features + <li>@ref acexml_guides + <li>@ref acexml_bugs + <li>@ref acexml_todo +</ol> + +*/ diff --git a/ACEXML/examples/Makefile b/ACEXML/examples/Makefile new file mode 100644 index 00000000000..a508ee1d096 --- /dev/null +++ b/ACEXML/examples/Makefile @@ -0,0 +1,17 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the client programs that test the ACE network services +#---------------------------------------------------------------------------- + +DIRS = SAXPrint + +#---------------------------------------------------------------------------- +# 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/examples/SAXPrint/Makefile b/ACEXML/examples/SAXPrint/Makefile new file mode 100644 index 00000000000..4dfd9239bc0 --- /dev/null +++ b/ACEXML/examples/SAXPrint/Makefile @@ -0,0 +1,49 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for repeating token client application +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +LDLIBS = -lACEXML_Parser -lACEXML +FILES = Print_Handler \ + SAXPrint_Handler + +SRC = $(addsuffix .cpp,$(FILES)) +OBJ = $(LSRC:%.cpp=$(VDIR)%.o) +CCFLAGS += -I ../.. + +BIN = main + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# 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.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/ACEXML/examples/SAXPrint/Print_Handler.cpp b/ACEXML/examples/SAXPrint/Print_Handler.cpp new file mode 100644 index 00000000000..5c1d2b9adc4 --- /dev/null +++ b/ACEXML/examples/SAXPrint/Print_Handler.cpp @@ -0,0 +1,251 @@ +// -*- C++ -*- $Id$ + +#include "Print_Handler.h" +#include "ace/ACE.h" +#if !defined (__ACEXML_INLINE__) +# include "Print_Handler.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_Print_Handler::ACEXML_Print_Handler (void) +{ + // no-op +} + +ACEXML_Print_Handler::~ACEXML_Print_Handler (void) +{ + // no-op +} + +void +ACEXML_Print_Handler::characters (const ACEXML_Char *cdata, + int start, + int end, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event characters () ** start: %d end: %d ***************\n%s\n- End event characters () ---------------\n"), + start, end, cdata)); +} + +void +ACEXML_Print_Handler::endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event endDocument () ***************\n"))); +} + +void +ACEXML_Print_Handler::endElement (const ACEXML_Char *uri, + const ACEXML_Char *name, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event endElement (%s, %s, ) ***************\n"), + uri, name, qName)); +} + +void +ACEXML_Print_Handler::endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event endPrefixMapping (%s) ***************\n"), + prefix)); +} + +void +ACEXML_Print_Handler::ignorableWhitespace (const ACEXML_Char *, + int, + int, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event ignorableWhitespace () ***************\n"))); +} + +void +ACEXML_Print_Handler::processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event processingInstruction (%s, %s) ***************\n"), + target, data)); +} + +void +ACEXML_Print_Handler::setDocumentLocator (ACEXML_Locator *, + ACEXML_Env &xmlenv) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event setDocumentLocator () ***************\n"))); +} + +void +ACEXML_Print_Handler::skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event skippedEntity (%s) ***************\n"), + name)); +} + +void +ACEXML_Print_Handler::startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event startDocument () ***************\n"))); +} + +void +ACEXML_Print_Handler::startElement (const ACEXML_Char *uri, + const ACEXML_Char *name, + const ACEXML_Char *qName, + ACEXML_Attributes *alist, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event startElement (%s, %s, %s) ***************\n"), + uri, name, qName)); + + if (alist != 0) + for (size_t i = 0; i < alist->getLength (); ++i) + { + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT (" %s = \"%s\"\n"), + alist->getQName (i), alist->getValue (i))); + } +} + +void +ACEXML_Print_Handler::startPrefixMapping (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +// *** Methods inherit from ACEXML_DTDHandler. + +void +ACEXML_Print_Handler::notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicID, + const ACEXML_Char *systemID, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event notationDecl: (%s) "), + name)); + + if (publicID == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("SYSTEM %s\n"), + systemID)); + else if (systemID == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("PUBLIC %s\n"), + publicID)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("PUBLIC %s %s\n"), + publicID, systemID)); +} + +void +ACEXML_Print_Handler::unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicID, + const ACEXML_Char *systemID, + const ACEXML_Char *notationName, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Unparsed Entity: %s"), + name)); + + if (publicID == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT (" SYSTEM %s"), + systemID)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT (" PUBLIC %s %s"), + publicID, systemID)); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT (" NDATA %s\n"), + notationName)); +} + +// Methods inherit from ACEXML_EnitityResolver. + +ACEXML_InputSource * +ACEXML_Print_Handler::resolveEntity (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. + return 0; +} + +// Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ +void +ACEXML_Print_Handler::error (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_Print_Handler::fatalError (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_Print_Handler::warning (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} diff --git a/ACEXML/examples/SAXPrint/Print_Handler.h b/ACEXML/examples/SAXPrint/Print_Handler.h new file mode 100644 index 00000000000..a9608c6b322 --- /dev/null +++ b/ACEXML/examples/SAXPrint/Print_Handler.h @@ -0,0 +1,197 @@ +// $Id$ + +//============================================================================= +/** + * @file Print_Handler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef ACEXML_PRINT_HANDLER_H +#define ACEXML_PRINT_HANDLER_H + +#include "common/DefaultHandler.h" + +/** + * @class ACEXML_Print_Handler + * + * @brief ACEXML_Print_Handler is an example SAX event handler. + * + * This SAX event handler prints out a detailed event report + * on every event it received. + */ +class ACEXML_Print_Handler : public ACEXML_DefaultHandler +{ +public: + /* + * Default constructor. + */ + ACEXML_Print_Handler (void); + + /* + * Default destructor. + */ + virtual ~ACEXML_Print_Handler (void); + + // Methods inherit from ACEXML_ContentHandler. + + /* + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of a document. + */ + virtual void endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of an element. + */ + virtual void endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * End the scope of a prefix-URI mapping. + */ + virtual void endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of ignorable whitespace in element content. + */ + virtual void ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a processing instruction. + */ + virtual void processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive an object for locating the origin of SAX document events. + */ + virtual void setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) ; + + /* + * Receive notification of a skipped entity. + */ + virtual void skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of a document. + */ + virtual void startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of an element. + */ + virtual void startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Begin the scope of a prefix-URI Namespace mapping. + */ + virtual void startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // *** Methods inherit from ACEXML_DTDHandler. + + /* + * Receive notification of a notation declaration event. + */ + virtual void notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of an unparsed entity declaration event. + */ + virtual void unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_EnitityResolver. + + /* + * Allow the application to resolve external entities. + */ + virtual ACEXML_InputSource *resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ + virtual void error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a non-recoverable error. + */ + virtual void fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a warning. + */ + virtual void warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; +}; + +#endif /* ACEXML_PRINT_HANDLER_H */ diff --git a/ACEXML/examples/SAXPrint/Print_Handler.i b/ACEXML/examples/SAXPrint/Print_Handler.i new file mode 100644 index 00000000000..77b4466a3cb --- /dev/null +++ b/ACEXML/examples/SAXPrint/Print_Handler.i @@ -0,0 +1 @@ +// -*- C++ -*- $Id$ diff --git a/ACEXML/examples/SAXPrint/SAXPrint.dsp b/ACEXML/examples/SAXPrint/SAXPrint.dsp new file mode 100644 index 00000000000..06c3cc09b48 --- /dev/null +++ b/ACEXML/examples/SAXPrint/SAXPrint.dsp @@ -0,0 +1,130 @@ +# Microsoft Developer Studio Project File - Name="SAXPrint" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=SAXPrint - 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 "SAXPrint.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 "SAXPrint.mak" CFG="SAXPrint - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "SAXPrint - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "SAXPrint - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "SAXPrint - 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 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../.." /I "..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /machine:I386
+# ADD LINK32 ace.lib ACEXML.lib ACEXML_Parser.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\ace" /libpath:"..\..\Common" /libpath:"..\..\parser\parser"
+
+!ELSEIF "$(CFG)" == "SAXPrint - 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 /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../../.." /I "..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib ACEXMLd.lib ACEXML_Parserd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\ace" /libpath:"..\..\Common" /libpath:"..\..\parser\parser"
+
+!ENDIF
+
+# Begin Target
+
+# Name "SAXPrint - Win32 Release"
+# Name "SAXPrint - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Print_Handler.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\SAXPrint_Handler.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Print_Handler.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\SAXPrint_Handler.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 Group "Inline Files"
+
+# PROP Default_Filter "i"
+# Begin Source File
+
+SOURCE=.\Print_Handler.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\SAXPrint_Handler.i
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/ACEXML/examples/SAXPrint/SAXPrint.dsw b/ACEXML/examples/SAXPrint/SAXPrint.dsw new file mode 100644 index 00000000000..3ec5cb65624 --- /dev/null +++ b/ACEXML/examples/SAXPrint/SAXPrint.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "SAXPrint"=.\SAXPrint.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp new file mode 100644 index 00000000000..3c8110a2bc8 --- /dev/null +++ b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp @@ -0,0 +1,236 @@ +// -*- C++ -*- $Id$ + +#include "SAXPrint_Handler.h" +#include "ace/ACE.h" +#if !defined (__ACEXML_INLINE__) +# include "SAXPrint_Handler.i" +#endif /* __ACEXML_INLINE__ */ + +ACEXML_SAXPrint_Handler::ACEXML_SAXPrint_Handler (void) + : indent_ (0) +{ + // no-op +} + +ACEXML_SAXPrint_Handler::~ACEXML_SAXPrint_Handler (void) +{ + // no-op +} + +void +ACEXML_SAXPrint_Handler::characters (const ACEXML_Char *cdata, + int start, + int end, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + ACE_UNUSED_ARG (start); + ACE_UNUSED_ARG (end); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("%s"), + cdata)); +} + +void +ACEXML_SAXPrint_Handler::endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n"))); +} + +void +ACEXML_SAXPrint_Handler::endElement (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + this->dec_indent (); + this->print_indent (); + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("</%s>"), + qName)); +} + +void +ACEXML_SAXPrint_Handler::endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event endPrefixMapping (%s) ***************\n"), + prefix)); +} + +void +ACEXML_SAXPrint_Handler::ignorableWhitespace (const ACEXML_Char *, + int, + int, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event ignorableWhitespace () ***************\n"))); +} + +void +ACEXML_SAXPrint_Handler::processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + this->print_indent (); + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("<?%s %s>\n"), + target, data)); +} + +void +ACEXML_SAXPrint_Handler::setDocumentLocator (ACEXML_Locator *, + ACEXML_Env &xmlenv) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event setDocumentLocator () ***************\n"))); +} + +void +ACEXML_SAXPrint_Handler::skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT ("* Event skippedEntity (%s) ***************\n"), + name)); +} + +void +ACEXML_SAXPrint_Handler::startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + +// ACE_DEBUG ((LM_DEBUG, +// ACE_LIB_TEXT ("* Event startDocument () ***************\n"))); +} + +void +ACEXML_SAXPrint_Handler::startElement (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *qName, + ACEXML_Attributes *alist, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + ACE_UNUSED_ARG (xmlenv); + + this->print_indent (); + + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("<%s"), + qName)); + if (alist != 0) + for (size_t i = 0; i < alist->getLength (); ++i) + { + ACE_DEBUG ((LM_DEBUG, + ACE_LIB_TEXT (" %s = \"%s\""), + alist->getQName (i), alist->getValue (i))); + } + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (">"))); + this->inc_indent (); +} + +void +ACEXML_SAXPrint_Handler::startPrefixMapping (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +// *** Methods inherit from ACEXML_DTDHandler. + +void +ACEXML_SAXPrint_Handler::notationDecl (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_SAXPrint_Handler::unparsedEntityDecl (const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +// Methods inherit from ACEXML_EnitityResolver. + +ACEXML_InputSource * +ACEXML_SAXPrint_Handler::resolveEntity (const ACEXML_Char *, + const ACEXML_Char *, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. + return 0; +} + +// Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ +void +ACEXML_SAXPrint_Handler::error (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_SAXPrint_Handler::fatalError (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_SAXPrint_Handler::warning (ACEXML_SAXParseException &, + ACEXML_Env &) + // ACE_THROW_SPEC ((ACEXML_SAXException)) +{ + // No-op. +} + +void +ACEXML_SAXPrint_Handler::print_indent (void) +{ + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n"))); + for (size_t i = 0; i < this->indent_; ++i) + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" "))); +} diff --git a/ACEXML/examples/SAXPrint/SAXPrint_Handler.h b/ACEXML/examples/SAXPrint/SAXPrint_Handler.h new file mode 100644 index 00000000000..90fd8e9f113 --- /dev/null +++ b/ACEXML/examples/SAXPrint/SAXPrint_Handler.h @@ -0,0 +1,208 @@ +// $Id$ + +//============================================================================= +/** + * @file SAXPrint_Handler.h + * + * $Id$ + * + * @author Nanbor Wang <nanbor@cs.wustl.edu> + */ +//============================================================================= + +#ifndef ACEXML_SAXPRINT_HANDLER_H +#define ACEXML_SAXPRINT_HANDLER_H + +#include "common/DefaultHandler.h" + +/** + * @class ACEXML_SAXPrint_Handler + * + * @brief ACEXML_SAXPrint_Handler is an example SAX event handler. + * + * This SAX event handler try to regenerate the XML document it + * reads with correct indentation. + */ +class ACEXML_SAXPrint_Handler : public ACEXML_DefaultHandler +{ +public: + /* + * Default constructor. + */ + ACEXML_SAXPrint_Handler (void); + + /* + * Default destructor. + */ + virtual ~ACEXML_SAXPrint_Handler (void); + + // Methods inherit from ACEXML_ContentHandler. + + /* + * Receive notification of character data. + */ + virtual void characters (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of a document. + */ + virtual void endDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the end of an element. + */ + virtual void endElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * End the scope of a prefix-URI mapping. + */ + virtual void endPrefixMapping (const ACEXML_Char *prefix, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of ignorable whitespace in element content. + */ + virtual void ignorableWhitespace (const ACEXML_Char *ch, + int start, + int length, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a processing instruction. + */ + virtual void processingInstruction (const ACEXML_Char *target, + const ACEXML_Char *data, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive an object for locating the origin of SAX document events. + */ + virtual void setDocumentLocator (ACEXML_Locator *locator, + ACEXML_Env &xmlenv) ; + + /* + * Receive notification of a skipped entity. + */ + virtual void skippedEntity (const ACEXML_Char *name, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of a document. + */ + virtual void startDocument (ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of the beginning of an element. + */ + virtual void startElement (const ACEXML_Char *namespaceURI, + const ACEXML_Char *localName, + const ACEXML_Char *qName, + ACEXML_Attributes *atts, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Begin the scope of a prefix-URI Namespace mapping. + */ + virtual void startPrefixMapping (const ACEXML_Char *prefix, + const ACEXML_Char *uri, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // *** Methods inherit from ACEXML_DTDHandler. + + /* + * Receive notification of a notation declaration event. + */ + virtual void notationDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of an unparsed entity declaration event. + */ + virtual void unparsedEntityDecl (const ACEXML_Char *name, + const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + const ACEXML_Char *notationName, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_EnitityResolver. + + /* + * Allow the application to resolve external entities. + */ + virtual ACEXML_InputSource *resolveEntity (const ACEXML_Char *publicId, + const ACEXML_Char *systemId, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + // Methods inherit from ACEXML_ErrorHandler. + + /* + * Receive notification of a recoverable error. + */ + virtual void error (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a non-recoverable error. + */ + virtual void fatalError (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + /* + * Receive notification of a warning. + */ + virtual void warning (ACEXML_SAXParseException &exception, + ACEXML_Env &xmlenv) + // ACE_THROW_SPEC ((ACEXML_SAXException)) + ; + + void inc_indent (); + void dec_indent (); + void print_indent (); + +private: + size_t indent_; + +}; + +#if defined (__ACEXML_INLINE__) +# include "SAXPrint_Handler.i" +#endif /* __ACEXML_INLINE__ */ +#endif /* ACEXML_SAXPRINT_HANDLER_H */ diff --git a/ACEXML/examples/SAXPrint/SAXPrint_Handler.i b/ACEXML/examples/SAXPrint/SAXPrint_Handler.i new file mode 100644 index 00000000000..2102291ea68 --- /dev/null +++ b/ACEXML/examples/SAXPrint/SAXPrint_Handler.i @@ -0,0 +1,13 @@ +// -*- C++ -*- $Id$ + +ACEXML_INLINE void +ACEXML_SAXPrint_Handler::inc_indent (void) +{ + this->indent_ += 1; +} + +ACEXML_INLINE void +ACEXML_SAXPrint_Handler::dec_indent (void) +{ + this->indent_ -= 1; +} diff --git a/ACEXML/examples/SAXPrint/main.cpp b/ACEXML/examples/SAXPrint/main.cpp new file mode 100644 index 00000000000..5eeafef2c43 --- /dev/null +++ b/ACEXML/examples/SAXPrint/main.cpp @@ -0,0 +1,56 @@ +// $Id$ + +#include "common/FileCharStream.h" +#include "parser/parser/Parser.h" +#include "Print_Handler.h" +#include "SAXPrint_Handler.h" + + +int +main (int argc, ACE_TCHAR *argv[]) +{ + ACEXML_DefaultHandler *handler = 0; + { + if (argc < 2) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_LIB_TEXT ("Usage: %s <XML filename> [-n]\n"), + argv [0]), + -1); + + ACEXML_FileCharStream *fstm = 0; + ACE_NEW_RETURN (fstm, + ACEXML_FileCharStream (), + 1); + + if (fstm->open (argv [1]) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_LIB_TEXT ("Fail to open XML file: %s\n"), + argv [1]), + -1); + + if (argc == 2) // + ACE_NEW_RETURN (handler, + ACEXML_Print_Handler (), + -1); + else + ACE_NEW_RETURN (handler, + ACEXML_SAXPrint_Handler (), + -1); + + ACEXML_Parser parser; + ACEXML_InputSource input(fstm); + + parser.setContentHandler (handler); + parser.setDTDHandler (handler); + parser.setErrorHandler (handler); + parser.setEntityResolver (handler); + + ACEXML_Env xmlenv; + + parser.parse (&input, xmlenv); + if (xmlenv.exception ()) + xmlenv.exception ()->print (); + } + delete handler; + return 0; +} diff --git a/ACEXML/examples/SAXPrint/ns.svc.conf.xml b/ACEXML/examples/SAXPrint/ns.svc.conf.xml new file mode 100644 index 00000000000..a7487dc360f --- /dev/null +++ b/ACEXML/examples/SAXPrint/ns.svc.conf.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<ace:ACE_Svc_Conf xmlns:ace="http://ace.doc.wustl.edu/svcconf"> +<static id="ACE_Service_Manager"> + <params>-d</params> + <params>-p 4911</params> +</static> + +<dynamic id="Test_Task" type="service_object"> A & + <initializer path="CCM_App" init="_make_Test_Task"> + <params>-p 3000</params> + </initializer> +</dynamic> + +<ace:streamdef> + <dynamic id="CCM_App" type="stream" status="active"> + <initializer path="CCM_App" init="make_stream"/> + </dynamic> + <module> + <dynamic id="Device_Adapter" type="module"> + <initializer path="CCM_App" init="make_da"/> + </dynamic> + <dynamic id="Event_Analyzer" type="module"> + <initializer path="CCM_App" init="make_ea"/> + </dynamic> + <dynamic id="Multicast_Router" type="module"> + <initializer path="CCM_App" init="make_mr"> + <params>-p</params> + <params>3001</params> + </initializer> + </dynamic> + </module> +</ace:streamdef> + +<stream id="CCM_App"> + <module> + <remove id="Device_Adapter"/> + <!-- <remove id="Event_Analyzer"/> --> + <!-- <remove id="Multicast_Router"/> --> + <![CDATA[Only a text string. +Do you &expect something more?]]> + </module> +</stream> + +<!-- remove CCM_App --> +<remove id="Test_&Taskebc"/> +</ace:ACE_Svc_Conf>
\ No newline at end of file diff --git a/ACEXML/examples/SAXPrint/svc.conf.xml b/ACEXML/examples/SAXPrint/svc.conf.xml new file mode 100644 index 00000000000..ff0eebe831f --- /dev/null +++ b/ACEXML/examples/SAXPrint/svc.conf.xml @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<!-- This is a test XML file. Most of the stuff here don't make any sense at all --> +<!DOCTYPE ACE_Svc_Conf PUBLIC 'GOODSAM' 'http://ace.cs.wustl.edu/dtd/ACE_SVCCONF.DTD' + [ + <!NOTATION goody PUBLIC 'NBC' 'http://hardcoreace.com/'> + <!NOTATION frodo PUBLIC 'ABC'> + <!NOTATION bilbo SYSTEM "C:/ACE-GUIDELINE"> + <!ENTITY ccm 'CCM_App'> + <!ENTITY pippin PUBLIC 'GOTO' 'http://taozen.com/' NDATA NBC> + <!ENTITY sam PUBLIC 'SHIRE' 'http://taozen.com/'> + <!ENTITY gandolf SYSTEM 'D:/RINGS.DOT'> + <!ELEMENT GOOBEGONE EMPTY> + <!ELEMENT POOPOO ANY> + <!ELEMENT HOHOHO ((BOOBOO, GOOBEGONE)?, (GOOBEGONE|POOPOO)*)+> + <!ELEMENT BOOBOO (#PCDATA | BOOBOO)*> + <!ATTLIST GOOBEGONE + ohmy CDATA #REQUIRED + testing IDREF #IMPLIED> + ]> + +<ACE_Svc_Conf> +<static id="ACE_Service_Manager"> + <params>-d</params> + <params>-p 4911</params> +</static> + +<dynamic id="Test_Task" type="service_object"> A & + <initializer path="CCM_App" init="_make_Test_Task"> + <params>-p 3000</params> + </initializer> +</dynamic> + +<streamdef> + <dynamic id="CCM_App" type="stream" status="active"> + <initializer path="CCM_App" init="make_stream"/> + </dynamic> + <module> + <dynamic id="Device_Adapter" type="module"> + <initializer path="CCM_App" init="make_da"/> + </dynamic> + <dynamic id="Event_Analyzer" type="module"> + <initializer path="CCM_App" init="make_ea"/> + </dynamic> + <dynamic id="Multicast_Router" type="module"> + <initializer path="CCM_App" init="make_mr"> + <params>-p</params> + <params>3001</params> + </initializer> + </dynamic> + </module> +</streamdef> + +<stream id="&ccm;"> + <module> + <remove id="Device_Adapter"/> + <!-- <remove id="Event_Analyzer"/> --> + <!-- <remove id="Multicast_Router"/> --> + <![CDATA[Only a text string. +Do you &expect something more? A]]> +<!-- Noticed that the "&" in the above CDATA section can not be escaped. --> + </module> +</stream> + +<!-- remove CCM_App --> +<remove id="Test_&Taskabc"/> +</ACE_Svc_Conf> diff --git a/ACEXML/examples/test_docs/svcconf.dtd b/ACEXML/examples/test_docs/svcconf.dtd new file mode 100644 index 00000000000..dded178c1f7 --- /dev/null +++ b/ACEXML/examples/test_docs/svcconf.dtd @@ -0,0 +1,65 @@ +<!-- $Id$ --> +<!-- Document Type Definition for XML ACE Service Config files --> + +<!-- An ACE_Svc_Conf document contains zero or more entries --> +<!-- The entries are processed in the order they appear --> +<!-- in the ACE_Svc_Conf file. --> +<!ELEMENT ACE_Svc_Conf (dynamic|static|suspend|resume|remove|stream|streamdef)*> + +<!-- Streams are separate into two elements. One defines how --> +<!-- the stream should be constructed and the other defines --> +<!-- what to do with it. The identity of a stream is defined --> +<!-- in the first dynamic/static element. --> +<!ELEMENT streamdef ((dynamic|static),module)> +<!-- @@ Do we ever need to suspend/resume/remove modules when --> +<!-- constructing a stream? Should we leave only dynamic --> +<!-- and static here? --> +<!ELEMENT module (dynamic|static|suspend|resume|remove)+> + +<!-- A 'stream' element controls the stream object --> +<!-- @@ Likewise, we are reusing the 'module' element here. --> +<!-- Do we ever need to insert new modules into a stream? --> +<!-- Nanbor: I guess we can do that. --> +<!ELEMENT stream (module)> +<!ATTLIST stream id IDREF #REQUIRED> + +<!-- A 'dynamic' entry. --> +<!-- @@ The kind of attributes the corresponding initializer --> +<!-- should take seems to be determined by the 'type' --> +<!-- attribute. Should we further partition the dynamic --> +<!-- element definition into several elements? E.g. into --> +<!-- dyn_service_object/dyn_module/dyn_stream? --> +<!-- Nanbor: Will that be too confusing? --> +<!ELEMENT dynamic (initializer)> +<!ATTLIST dynamic id ID #REQUIRED + status (active|inactive) "active" + type (module|service_object|stream) #REQUIRED> + +<!-- Initializing function for dynamic entry. --> +<!ELEMENT initializer (params)*> +<!ATTLIST initializer init CDATA #REQUIRED + path CDATA #IMPLIED> + +<!-- A 'static' entry takes an ID attribute and an optional --> +<!-- parameter lists. --> +<!ELEMENT static (params)*> +<!ATTLIST static id ID #REQUIRED> + +<!-- A 'suspend' entry takes an ID attribute. --> +<!ELEMENT suspend EMPTY> +<!ATTLIST suspend id IDREF #REQUIRED> + +<!-- A 'resume' entry takes an ID attribute. --> +<!ELEMENT resume EMPTY> +<!ATTLIST resume id IDREF #REQUIRED> + +<!-- A 'remove' entry takes an ID attribute. --> +<!ELEMENT remove EMPTY> +<!ATTLIST remove id IDREF #REQUIRED> + +<!-- A params entry can appear within dynamic and static. --> +<!-- Parameters can appear multiple time and the SAX handler --> +<!-- for Service_Configurator is supposed to concatinate --> +<!-- them together with appropriate white space to separate --> +<!-- parameters appeared in separate elements. --> +<!ELEMENT params (#PCDATA)>
\ No newline at end of file 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. diff --git a/ACEXML/tests/Makefile b/ACEXML/tests/Makefile new file mode 100644 index 00000000000..9b776e0630a --- /dev/null +++ b/ACEXML/tests/Makefile @@ -0,0 +1,47 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for repeating token client application +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +LDLIBS = -lACEXML +BIN = Transcoder_Test \ + NamespaceSupport_Test + +LSRC = $(addsuffix .cpp,$(BIN)) +LOBJ = $(LSRC:%.cpp=$(VDIR)%.o) +#SHOBJ = $(addsuffix .so,$(BIN)) +CCFLAGS += -I ../ + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# 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.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/ACEXML/tests/NamespaceSupport_Test.cpp b/ACEXML/tests/NamespaceSupport_Test.cpp new file mode 100644 index 00000000000..29008ab218a --- /dev/null +++ b/ACEXML/tests/NamespaceSupport_Test.cpp @@ -0,0 +1,144 @@ +// $Id$ + +#include "common/NamespaceSupport.h" + +int main (int, ACE_TCHAR *[]) +{ + ACEXML_NamespaceSupport xmlns; + + xmlns.pushContext(); + xmlns.declarePrefix(ACE_TEXT (""), + ACE_TEXT ("http://www.w3.org/1999/xhtml")); + xmlns.declarePrefix(ACE_TEXT ("dc"), + ACE_TEXT ("http://www.purl.org/dc#")); + xmlns.declarePrefix(ACE_TEXT ("xc"), + ACE_TEXT ("http://www.purl.org/dc#")); + + const ACEXML_Char *lName, *uri; + const ACEXML_Char *n1 = ACE_TEXT ("p"); + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*** Checking processName:\n"))); + if (xmlns.processName (n1, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %s\n"), + n1)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n1)); + + ACEXML_Char *n2 = ACE_TEXT ("dc:title"); + if (xmlns.processName(n2, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %S\n"), + n2)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n2)); + + ACEXML_Char *n3 = ACE_TEXT ("xml:title"); + if (xmlns.processName(n3, uri, lName, 0) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to resolve namespace name %S\n"), + n3)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Namespace URI: %s\nLocal name: %s\nRaw name: %s\n"), + uri, lName, n3)); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\n*** Checking getDeclaredPrefixes\n"))); + + ACEXML_STR_LIST prefixes; + if (xmlns.getDeclaredPrefixes (prefixes) != 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get a list of declared prefixes\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefix\n"))); + const ACEXML_Char *prefix = 0; + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.purl.org/dc#"))) == 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get prefix of http://www.purl.org/dc#\n"))); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Prefix of http://www.purl.org/dc# is %s\n"), + prefix)); + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/1999/xhtml"))) == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Fail to get prefix of http://www.w3.org/1999/xhtml which is okay\n"))); + else + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("ERROR: Prefix of http://www.w3.org/1999/xhtml is %s\n"), + prefix)); + + if ((prefix = xmlns.getPrefix (ACE_TEXT ("http://www.w3.org/XML/1998/namespace"))) == 0) + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("Fail to get prefix of http://www.w3.org/XML/1998/namespace\n"))); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Prefix of http://www.w3.org/XML/1998/namespace is %s\n"), + prefix)); + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes with known URI\n"))); + prefixes.reset (); + + if (xmlns.getPrefixes (ACE_TEXT ("http://www.purl.org/dc#"), prefixes) != 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes based on known URI\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getPrefixes\n"))); + prefixes.reset (); + + if (xmlns.getPrefixes (prefixes) != 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to getPrefixes\n"))); + else + { + ACEXML_STR_LIST::ITERATOR iter = prefixes.begin (); + const ACEXML_Char **prefix = 0; + + for (; iter.next (prefix);iter.advance ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("prefix: \"%s\"\n"), *prefix)); + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n*** Checking getURI\n"))); + const ACEXML_Char *URI = 0; + + if ((URI = xmlns.getURI (ACE_TEXT ("dc"))) == 0) + ACE_DEBUG((LM_ERROR, ACE_TEXT ("Fail to get URI for \"dc\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"dc\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT ("xc"))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xc\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xc\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT ("xml"))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get URI for \"xml\"\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for \"xml\" is %s\n"), URI)); + if ((URI = xmlns.getURI (ACE_TEXT (""))) == 0) + ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Fail to get default namespace URI\n"))); + else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("URI for default namespace is %s\n"), URI)); + + xmlns.popContext(); + + return 0; +} diff --git a/ACEXML/tests/NamespaceSupport_Test.dsp b/ACEXML/tests/NamespaceSupport_Test.dsp new file mode 100644 index 00000000000..efb29315a28 --- /dev/null +++ b/ACEXML/tests/NamespaceSupport_Test.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="NamespaceSupport_Test" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=NamespaceSupport_Test - 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 "NamespaceSupport_Test.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 "NamespaceSupport_Test.mak" CFG="NamespaceSupport_Test - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "NamespaceSupport_Test - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "NamespaceSupport_Test - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "NamespaceSupport_Test - 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 "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../.." /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /machine:I386
+# ADD LINK32 ace.lib ACEXML.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\ace" /libpath:"..\Common"
+
+!ELSEIF "$(CFG)" == "NamespaceSupport_Test - 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 /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../.." /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib ACEXMLd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\ace" /libpath:"..\Common"
+
+!ENDIF
+
+# Begin Target
+
+# Name "NamespaceSupport_Test - Win32 Release"
+# Name "NamespaceSupport_Test - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\NamespaceSupport_Test.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# 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/tests/Tests.dsw b/ACEXML/tests/Tests.dsw new file mode 100644 index 00000000000..e72f066de1a --- /dev/null +++ b/ACEXML/tests/Tests.dsw @@ -0,0 +1,41 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "NamespaceSupport_Test"=.\NamespaceSupport_Test.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "Transcoder_Test"=.\Transcoder_Test.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/ACEXML/tests/Transcoder_Test.cpp b/ACEXML/tests/Transcoder_Test.cpp new file mode 100644 index 00000000000..84b944d708b --- /dev/null +++ b/ACEXML/tests/Transcoder_Test.cpp @@ -0,0 +1,69 @@ +// -*- C++ -*- $Id$ + +#include "common/Transcode.h" +#include "ace/Log_Msg.h" + +void dump_utf16 (const ACEXML_UTF16 *data, + size_t len) +{ + size_t ptr = 0; + + while (1) + { + ACE_DEBUG ((LM_DEBUG, "%04x", data[ptr])); + + if (++ptr >= len) + break; + + if (ptr % 4 == 0) + ACE_DEBUG ((LM_DEBUG, "\n")); + else + ACE_DEBUG ((LM_DEBUG, " ")); + } + ACE_DEBUG ((LM_DEBUG, "\n")); + return; +} + +int +main (int, ACE_TCHAR*[]) +{ + ACEXML_UTF16 org [18]; +// = { 1, 2, 4, 8, 0x10, 0x20, 0x40, +// 0x80, +// 0x100, 0x200, 0x400, +// 0x800, 0x801, 0x802, 0x804, 0x808, 0x810, 0x820, +// 0x840, 0x880, 0x900, 0xa00, 0xc00, +// 0x1000, 0x2000, 0x4000, 0x8000, 0 } + ACEXML_UCS4 temp = 1; + + ACE_OS::memset (org, 0, sizeof org); + size_t x; + + for (x = 0; temp < 0x10000; x++, temp <<= 1) + { + org[x] = ACE_static_cast (ACEXML_UTF16, temp); + } + + ACE_DEBUG ((LM_DEBUG, "Original UTF16 string:\n")); + dump_utf16 (org, x); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + ACEXML_UTF8 decoded [MAXPATHLEN]; + ACE_OS::memset (decoded, 0, sizeof decoded); + + int retv = ACEXML_Transcoder::utf16s2utf8s (org, decoded, MAXPATHLEN); + + ACE_DEBUG ((LM_DEBUG, "Transcoded UTF8 string:\n")); + ACE_HEX_DUMP ((LM_DEBUG, decoded, ACE_OS::strlen (decoded) + 1)); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + ACEXML_UTF16 after [18]; + ACE_OS::memset (after, 0, sizeof after); + retv = ACEXML_Transcoder::utf8s2utf16s (decoded, after, 18); + + ACE_DEBUG ((LM_DEBUG, "Restored UTF16 string:\n")); + dump_utf16 (after, x); + ACE_DEBUG ((LM_DEBUG, "\n\n")); + + return 0; +} diff --git a/ACEXML/tests/Transcoder_Test.dsp b/ACEXML/tests/Transcoder_Test.dsp new file mode 100644 index 00000000000..39a92c39fb0 --- /dev/null +++ b/ACEXML/tests/Transcoder_Test.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="Transcoder_Test" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Transcoder_Test - 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 "Transcoder_Test.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 "Transcoder_Test.mak" CFG="Transcoder_Test - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Transcoder_Test - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "Transcoder_Test - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Transcoder_Test - 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 "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../.." /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /machine:I386
+# ADD LINK32 ace.lib ACEXML.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\ace" /libpath:"..\Common"
+
+!ELSEIF "$(CFG)" == "Transcoder_Test - 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 /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "../.." /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# 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 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 /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib ACEXMLd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\ace" /libpath:"..\Common"
+
+!ENDIF
+
+# Begin Target
+
+# Name "Transcoder_Test - Win32 Release"
+# Name "Transcoder_Test - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Transcoder_Test.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# 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
|