summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-11-19 02:42:19 +0000
committerkitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-11-19 02:42:19 +0000
commit4d733b09c3e6f1a1ca91b21ed0fb1b06a22a2cd2 (patch)
tree5c15d1cbbc500b98cb06cf625d43999f6528e801
parent057b391a8e7d92f02df5167bf722ac2c339f7806 (diff)
downloadATCD-4d733b09c3e6f1a1ca91b21ed0fb1b06a22a2cd2.tar.gz
Mon Nov 18 20:30:30 2002 Krishnakumar B <kitty@cs.wustl.edu>
-rw-r--r--ACEXML/common/CharStream.h3
-rw-r--r--ACEXML/common/Encoding.cpp2
-rw-r--r--ACEXML/common/FileCharStream.cpp6
-rw-r--r--ACEXML/common/FileCharStream.h2
-rw-r--r--ACEXML/common/HttpCharStream.cpp2
-rw-r--r--ACEXML/common/HttpCharStream.h3
-rw-r--r--ACEXML/common/LocatorImpl.cpp4
-rw-r--r--ACEXML/common/NamespaceSupport.cpp20
-rw-r--r--ACEXML/common/StrCharStream.cpp8
-rw-r--r--ACEXML/common/StrCharStream.h3
-rw-r--r--ACEXML/common/StreamFactory.cpp9
-rw-r--r--ACEXML/common/ZipCharStream.cpp213
-rw-r--r--ACEXML/common/ZipCharStream.h133
-rw-r--r--ACEXML/examples/SAXPrint/Print_Handler.cpp9
-rw-r--r--ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp9
-rw-r--r--ACEXML/examples/SAXPrint/main.cpp139
-rw-r--r--ACEXML/parser/parser/Parser.cpp140
-rw-r--r--ACEXML/parser/parser/Parser.h11
-rw-r--r--ChangeLog42
-rw-r--r--ChangeLogs/ChangeLog-03a42
20 files changed, 664 insertions, 136 deletions
diff --git a/ACEXML/common/CharStream.h b/ACEXML/common/CharStream.h
index 1b5c199f527..06d0efad61a 100644
--- a/ACEXML/common/CharStream.h
+++ b/ACEXML/common/CharStream.h
@@ -57,8 +57,7 @@ public:
/**
* Read the next batch of ACEXML_Char strings
*/
- virtual int read (ACEXML_Char *str,
- size_t len) = 0;
+ virtual int read (ACEXML_Char *str, size_t len) = 0;
/**
* Peek the next ACEXML_Char in the CharStream. Return the
diff --git a/ACEXML/common/Encoding.cpp b/ACEXML/common/Encoding.cpp
index 9ca972816b8..9bf788ff649 100644
--- a/ACEXML/common/Encoding.cpp
+++ b/ACEXML/common/Encoding.cpp
@@ -52,7 +52,7 @@ ACEXML_Encoding::get_encoding (const char* input)
return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF8];
else
{
- ACE_ERROR ((LM_ERROR, "Unknown encoding. Assuming UTF-8\n"));
+ // ACE_ERROR ((LM_ERROR, "Unknown encoding. Assuming UTF-8\n"));
return ACEXML_Encoding::encoding_names_[ACEXML_Encoding::UTF8];
}
}
diff --git a/ACEXML/common/FileCharStream.cpp b/ACEXML/common/FileCharStream.cpp
index 1d7811494ef..68aa2949013 100644
--- a/ACEXML/common/FileCharStream.cpp
+++ b/ACEXML/common/FileCharStream.cpp
@@ -53,8 +53,8 @@ ACEXML_FileCharStream::determine_encoding (void)
else
{
this->encoding_ = ACE::strnew (temp);
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("File's encoding is %s\n"),
- this->encoding_));
+// ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("File's encoding is %s\n"),
+// this->encoding_));
}
// Rewind the stream
this->rewind();
@@ -115,7 +115,7 @@ int
ACEXML_FileCharStream::read (ACEXML_Char *str,
size_t len)
{
- return ACE_OS::fread (str, len, sizeof (ACEXML_Char), this->infile_);
+ return ACE_OS::fread (str, sizeof (ACEXML_Char), len, this->infile_);
}
int
diff --git a/ACEXML/common/FileCharStream.h b/ACEXML/common/FileCharStream.h
index d71792aac59..9feb5dcfbe2 100644
--- a/ACEXML/common/FileCharStream.h
+++ b/ACEXML/common/FileCharStream.h
@@ -54,7 +54,7 @@ public:
/**
* 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.
+ * return an ACEXML_Char, 0 if EOF is reached, or 1 if succeed.
*/
virtual int get (ACEXML_Char& ch);
diff --git a/ACEXML/common/HttpCharStream.cpp b/ACEXML/common/HttpCharStream.cpp
index 2f1a9d4d754..d5f7f244471 100644
--- a/ACEXML/common/HttpCharStream.cpp
+++ b/ACEXML/common/HttpCharStream.cpp
@@ -320,7 +320,7 @@ ACEXML_HttpCharStream::determine_encoding (void)
else
{
this->encoding_ = ACE::strnew (temp);
- ACE_DEBUG ((LM_DEBUG, "URI's encoding is %s\n", this->encoding_));
+ // ACE_DEBUG ((LM_DEBUG, "URI's encoding is %s\n", this->encoding_));
}
// Move over the byte-order-mark if present.
for (int j = 0; j < 3; ++j)
diff --git a/ACEXML/common/HttpCharStream.h b/ACEXML/common/HttpCharStream.h
index 59813c51eb7..6a164605d0f 100644
--- a/ACEXML/common/HttpCharStream.h
+++ b/ACEXML/common/HttpCharStream.h
@@ -62,8 +62,7 @@ public:
/**
* Read the next batch of ACEXML_Char strings
*/
- virtual int read (ACEXML_Char *str,
- size_t len);
+ virtual int read (ACEXML_Char *str, size_t len);
/**
* Peek the next ACEXML_Char in the CharStream. Return the
diff --git a/ACEXML/common/LocatorImpl.cpp b/ACEXML/common/LocatorImpl.cpp
index d7f0d1028bc..ec04b231512 100644
--- a/ACEXML/common/LocatorImpl.cpp
+++ b/ACEXML/common/LocatorImpl.cpp
@@ -25,8 +25,8 @@ ACEXML_LocatorImpl::ACEXML_LocatorImpl (const ACEXML_Char* systemId,
ACEXML_LocatorImpl::ACEXML_LocatorImpl (const ACEXML_Locator& locator)
- : publicId_ (ACE::strnew (locator.getPublicId ())),
- systemId_ (ACE::strnew (locator.getSystemId ())),
+ : publicId_ (locator.getPublicId() ? ACE::strnew(locator.getPublicId ()): 0),
+ systemId_ (locator.getSystemId() ? ACE::strnew(locator.getSystemId ()): 0),
lineNumber_ (locator.getLineNumber ()),
columnNumber_ (locator.getColumnNumber ())
{
diff --git a/ACEXML/common/NamespaceSupport.cpp b/ACEXML/common/NamespaceSupport.cpp
index 5f385d6a706..d4f27ba71c4 100644
--- a/ACEXML/common/NamespaceSupport.cpp
+++ b/ACEXML/common/NamespaceSupport.cpp
@@ -79,6 +79,9 @@ int
ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char *prefix,
const ACEXML_Char *uri)
{
+ if (!prefix || !uri)
+ return -1;
+
// Unless predefined by w3.org(?) NS prefix can never start with
// "xml".
if (ACE_OS_String::strcmp (ACEXML_TABOO_NS_PREFIX, prefix) == 0)
@@ -109,6 +112,9 @@ ACEXML_NamespaceSupport::getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const
const ACEXML_Char *
ACEXML_NamespaceSupport::getPrefix (const ACEXML_Char *uri) const
{
+ if (!uri)
+ return 0;
+
ACEXML_NS_CONTEXT_ENTRY *entry;
for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
@@ -143,6 +149,9 @@ int
ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri,
ACEXML_STR_LIST &prefixes) const
{
+ if (!uri)
+ return -1;
+
ACEXML_NS_CONTEXT_ENTRY *entry;
for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
@@ -160,6 +169,9 @@ ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri,
const ACEXML_Char *
ACEXML_NamespaceSupport::getURI (const ACEXML_Char *prefix) const
{
+ if (!prefix)
+ return 0;
+
ACEXML_NS_CONTEXT_ENTRY *entry;
if (this->effective_context_->find (ACEXML_String (prefix, 0, 0),
@@ -233,14 +245,16 @@ ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName,
ACEXML_NS_CONTEXT_ENTRY *entry;
- if (this->effective_context_->find (prefix, entry) == 0)
- uri = entry->int_id_.c_str ();
+ if (prefix != ACEXML_DEFAULT_NS_PREFIX)
+ {
+ if (this->effective_context_->find (prefix, entry) == 0)
+ uri = entry->int_id_.c_str ();
+ }
else
{
uri = ACEXML_DEFAULT_NS_PREFIX;
return -1;
}
-
return 0;
}
diff --git a/ACEXML/common/StrCharStream.cpp b/ACEXML/common/StrCharStream.cpp
index 4ea75a3743c..9bfcc95072c 100644
--- a/ACEXML/common/StrCharStream.cpp
+++ b/ACEXML/common/StrCharStream.cpp
@@ -76,7 +76,7 @@ ACEXML_StrCharStream::determine_encoding (void)
else
{
this->encoding_ = ACE::strnew (temp);
- ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
+ // ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
}
return 0;
}
@@ -93,23 +93,19 @@ ACEXML_StrCharStream::get (ACEXML_Char& ch)
if (this->start_ != 0 && this->ptr_ != this->end_)
{
ch = *this->ptr_++;
-
return 0;
}
-
return -1;
}
int
-ACEXML_StrCharStream::read (ACEXML_Char *str,
- size_t len)
+ACEXML_StrCharStream::read (ACEXML_Char *str, size_t len)
{
if (this->start_ != 0 &&
this->ptr_ != this->end_)
{
if (len * sizeof (ACEXML_Char) > (size_t) (this->end_ - this->ptr_))
len = this->end_ - this->ptr_;
-
ACE_OS_String::strncpy (str, this->ptr_, len);
this->ptr_ += len;
return len;
diff --git a/ACEXML/common/StrCharStream.h b/ACEXML/common/StrCharStream.h
index 6321decb9a2..0898ab2f1d1 100644
--- a/ACEXML/common/StrCharStream.h
+++ b/ACEXML/common/StrCharStream.h
@@ -68,8 +68,7 @@ public:
/**
* Read the next batch of ACEXML_Char strings
*/
- virtual int read (ACEXML_Char *str,
- size_t len);
+ virtual int read (ACEXML_Char *str, size_t len);
/**
* Peek the next ACEXML_Char in the CharStream. Return the
diff --git a/ACEXML/common/StreamFactory.cpp b/ACEXML/common/StreamFactory.cpp
index df458e61697..ec3933d0d02 100644
--- a/ACEXML/common/StreamFactory.cpp
+++ b/ACEXML/common/StreamFactory.cpp
@@ -3,6 +3,7 @@
#include "ACEXML/common/StreamFactory.h"
#include "ACEXML/common/FileCharStream.h"
#include "ACEXML/common/HttpCharStream.h"
+#include "ACEXML/common/ZipCharStream.h"
ACE_RCSID (common, StreamFactory, "$Id$")
@@ -11,8 +12,8 @@ ACEXML_StreamFactory::create_stream (const ACEXML_Char* uri)
{
if (uri == 0)
return 0;
-
ACEXML_FileCharStream* fstream = 0;
+ ACEXML_ZipCharStream* zstream = 0;
ACEXML_HttpCharStream* hstream = 0;
if (ACE_OS::strstr (uri, ACE_TEXT("ftp://")) != 0)
@@ -33,6 +34,12 @@ ACEXML_StreamFactory::create_stream (const ACEXML_Char* uri)
if (fstream->open (uri) != -1)
return fstream;
}
+ else
+ {
+ ACE_NEW_RETURN (zstream, ACEXML_ZipCharStream, 0);
+ if (zstream->open (uri) != -1)
+ return zstream;
+ }
return 0;
}
diff --git a/ACEXML/common/ZipCharStream.cpp b/ACEXML/common/ZipCharStream.cpp
new file mode 100644
index 00000000000..f16bc77f463
--- /dev/null
+++ b/ACEXML/common/ZipCharStream.cpp
@@ -0,0 +1,213 @@
+// $Id$
+
+#include "ACEXML/common/ZipCharStream.h"
+#include "ace/ACE.h"
+
+
+ACEXML_ZipCharStream::ACEXML_ZipCharStream (void)
+ : filename_ (0), encoding_ (0), size_ (0), infile_ (NULL), pos_ (0),
+ limit_ (0)
+{
+}
+
+ACEXML_ZipCharStream::~ACEXML_ZipCharStream (void)
+{
+ this->close();
+}
+
+int
+ACEXML_ZipCharStream::open (const ACEXML_Char *name)
+{
+ delete[] this->filename_;
+ this->filename_ = 0;
+
+ delete[] this->encoding_;
+ this->encoding_ = 0;
+
+ this->infile_ = zzip_fopen (name, ACE_TEXT ("r"));
+ if (this->infile_ == NULL)
+ return -1;
+
+ this->filename_ = ACE::strnew (ACE::basename (name));
+ if (this->determine_encoding() == -1)
+ return -1;
+ return 0;
+}
+
+int
+ACEXML_ZipCharStream::determine_encoding (void)
+{
+ char input[4];
+ int retval = 0;
+ int i = 0;
+ for (; i < 4 && (input[i] = this->peekchar_i(i)); ++i)
+ ;
+ if (i < 4)
+ return -1;
+ const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input);
+ if (!temp)
+ return -1;
+ else
+ {
+ this->encoding_ = ACE::strnew (temp);
+ // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("File's encoding is %s\n"),
+// this->encoding_));
+ }
+ // Move over the byte-order-mark if present.
+ char ch;
+ for (int j = 0; j < 3; ++j)
+ {
+ if ((ch = this->peekchar_i()) < 0)
+ return -1;
+ if (ch == '\xFF' || ch == '\xFE' || ch == '\xEF' || ch == '\xBB' ||
+ ch == '\xBF')
+ this->get(ch);
+ else
+ break;
+ }
+ return 0;
+}
+
+void
+ACEXML_ZipCharStream::rewind()
+{
+ zzip_rewind (this->infile_);
+}
+
+int
+ACEXML_ZipCharStream::available (void)
+{
+ long curr;
+ if ((curr = zzip_tell (this->infile_)) < 0)
+ return -1;
+ return (this->size_ - curr);
+}
+
+int
+ACEXML_ZipCharStream::close (void)
+{
+ if (this->infile_ != NULL)
+ zzip_close (this->infile_);
+ delete[] this->filename_;
+ delete[] this->encoding_;
+ this->size_ = 0;
+ return 0;
+}
+
+
+int
+ACEXML_ZipCharStream::getchar_i (char& ch)
+{
+ if (this->pos_ < this->limit_)
+ {
+ ch = this->buf_[this->pos_++];
+ return 0;
+ }
+ this->limit_ = zzip_read (this->infile_, this->buf_, sizeof (this->buf_));
+ if (this->limit_ == 0)
+ return -1;
+ this->pos_ = 0;
+ ch = this->buf_[this->pos_++];
+ return 0;
+}
+
+int
+ACEXML_ZipCharStream::peekchar_i (int offset)
+{
+ if (offset > sizeof (this->buf_))
+ return -1;
+ if (this->pos_ + offset < this->limit_)
+ return this->buf_[this->pos_ + offset];
+ int i = 0;
+ for (; this->pos_ < this->limit_; ++this->pos_, ++i)
+ this->buf_[i] = this->buf_[this->pos_];
+ this->limit_ = zzip_read (this->infile_, this->buf_ + i,
+ sizeof (this->buf_) - i);
+ this->limit_ += i;
+ if (this->limit_ == 0)
+ return -1;
+ this->pos_ = 0;
+ return this->buf_[this->pos_ + offset];
+}
+
+int
+ACEXML_ZipCharStream::read (ACEXML_Char *str, size_t len)
+{
+ for (size_t i = 0; i < len && this->pos_ < this->limit_; ++i)
+ str[i] = this->buf_[this->pos_++];
+ if (i == len)
+ return len;
+ len = len - i;
+ return zzip_fread (str + i, sizeof (ACEXML_Char), len, this->infile_);
+}
+
+int
+ACEXML_ZipCharStream::get (ACEXML_Char& ch)
+{
+#if defined (ACE_USES_WCHAR)
+ return this->get_i (ch);
+#else
+ return this->getchar_i (ch);
+#endif /* ACE_USES_WCHAR */
+}
+
+
+int
+ACEXML_ZipCharStream::peek (void)
+{
+#if defined (ACE_USES_WCHAR)
+ return this->peek_i();
+#else
+ return this->peekchar_i();
+#endif /* ACE_USES_WCHAR */
+}
+
+const ACEXML_Char*
+ACEXML_ZipCharStream::getEncoding (void)
+{
+ return this->encoding_;
+}
+
+#if defined (ACE_USES_WCHAR)
+int
+ACEXML_ZipCharStream::get_i (ACEXML_Char& ch)
+{
+ if (ACE_OS::strcmp (this->encoding_, ACE_TEXT ("UTF-8")) == 0)
+ return this->getchar_i (ch);
+
+ int BE = (ACE_OS::strcmp (this->encoding_,
+ ACE_TEXT ("UTF-16BE")) == 0) ? 1 : 0;
+ ACEXML_Char input[2];
+ int i = 0;
+ for (; i < 2 && (this->getchar_i (input[i]) == 0); ++i)
+ ;
+ if (i < 2)
+ {
+ ch = 0;
+ return -1;
+ }
+ ch = BE ? input[0] << 8 | input[1] : input[1] << 8 | input[0];
+ return 0;
+}
+
+int
+ACEXML_ZipCharStream::peek_i (void)
+{
+ // If we are reading a UTF-8 encoded file, just use the plain unget.
+ if (ACE_OS::strcmp (this->encoding_, ACE_TEXT ("UTF-8")) == 0)
+ return this->peekchar_i();
+
+ // Peek into the stream. This reads two characters off the stream, keeps
+ // it in peek_.
+ int BE = (ACE_OS::strcmp (this->encoding_,
+ ACE_TEXT ("UTF-16BE")) == 0) ? 1 : 0;
+
+ ACEXML_Char input[2];
+ int i = 0;
+ for (; i < 2 && (input[i] = this->peekchar_i (i)); ++i)
+ ;
+ if (i < 2)
+ return -1;
+ return (BE ? input[0] << 8 | input[1] : input[1] << 8 | input[0]);
+}
+#endif /* ACE_USES_WCHAR */
diff --git a/ACEXML/common/ZipCharStream.h b/ACEXML/common/ZipCharStream.h
new file mode 100644
index 00000000000..1515be76a98
--- /dev/null
+++ b/ACEXML/common/ZipCharStream.h
@@ -0,0 +1,133 @@
+// -*- C++ -*-
+
+//=============================================================================
+/**
+ * @file ZipCharStream.h
+ *
+ * $Id$
+ *
+ * @author Krishnakumar B <kitty@cs.wustl.edu>
+ */
+//=============================================================================
+
+#ifndef _ACEXML_ZIPCHARSTREAM_H_
+#define _ACEXML_ZIPCHARSTREAM_H_
+
+#include "ace/pre.h"
+#include "ACEXML/common/ACEXML_Export.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+#pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ACEXML/common/CharStream.h"
+#include "ACEXML/common/Encoding.h"
+#include "zziplib.h"
+
+// Ugly wart to get aroung a macro version of read
+#undef read
+
+/**
+ * @class ACEXML_ZipCharStream ZipCharStream.h "ACEXML/common/ZipCharStream.h"
+ *
+ * An implementation of ACEXML_CharStream for reading input from a ZIP archive.
+ */
+class ACEXML_Export ACEXML_ZipCharStream : public ACEXML_CharStream
+{
+public:
+ /// Default constructor.
+ ACEXML_ZipCharStream (void);
+
+ /// Destructor
+ virtual ~ACEXML_ZipCharStream (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 EOF 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);
+
+ /**
+ * Determine the encoding of the file.
+ */
+ virtual int determine_encoding (void);
+
+
+ /**
+ * Peek the next ACEXML_Char in the CharStream. Return the
+ * character if success, -1 if EOF is reached.
+ */
+ virtual int peek (void);
+
+ /**
+ * Resets the file pointer to the beginning of the stream.
+ */
+ virtual void rewind (void);
+
+ /*
+ * Get the character encoding for a byte stream or URI.
+ */
+ virtual const ACEXML_Char *getEncoding (void);
+
+protected:
+
+ /** Read the next character as a normal character. Return -1 if EOF is
+ * reached, else return 0.
+ */
+ virtual int getchar_i (char& ch);
+
+ /**
+ * Peek @c offset bytes into the stream and return the character at @c
+ * offset. If EOF is reached, return -1.
+ */
+ virtual int peekchar_i (int offset = 0);
+
+private:
+
+#if defined (ACE_USES_WCHAR)
+ /**
+ * Read the next character from the stream taking into account the
+ * encoding of the file.
+ */
+ int get_i (ACEXML_Char& ch);
+
+ /**
+ * Return the next character from the stream taking into account the
+ * encoding of the file. Subsequent call to get() returns this
+ * character.
+ */
+ int peek_i (void);
+
+#endif /* ACE_USES_WCHAR */
+
+ ACEXML_Char* filename_;
+ ACEXML_Char* encoding_;
+ off_t size_;
+ ZZIP_FILE* infile_;
+ char buf_[80];
+ int pos_;
+ int limit_;
+};
+
+#include "ace/post.h"
+
+#endif /* _ACEXML_ZIPCHARSTREAM_H_ */
diff --git a/ACEXML/examples/SAXPrint/Print_Handler.cpp b/ACEXML/examples/SAXPrint/Print_Handler.cpp
index a8a232a6bfb..3d50bb0f620 100644
--- a/ACEXML/examples/SAXPrint/Print_Handler.cpp
+++ b/ACEXML/examples/SAXPrint/Print_Handler.cpp
@@ -75,10 +75,8 @@ ACEXML_Print_Handler::ignorableWhitespace (const ACEXML_Char *,
ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event ignorableWhitespace () ***************\n")));
+// ACE_DEBUG ((LM_DEBUG,
+// ACE_TEXT ("* Event ignorableWhitespace () ***************\n")));
}
void
@@ -99,8 +97,7 @@ ACEXML_Print_Handler::setDocumentLocator (ACEXML_Locator * locator)
{
this->locator_ = locator;
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event setDocumentLocator () ***************\n")));
+ // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("* Event setDocumentLocator () ***************\n")));
}
void
diff --git a/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
index 921f04d881c..008fb19f46e 100644
--- a/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
+++ b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
@@ -76,10 +76,8 @@ ACEXML_SAXPrint_Handler::ignorableWhitespace (const ACEXML_Char *,
int ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event ignorableWhitespace () ***************\n")));
+// ACE_DEBUG ((LM_DEBUG,
+// ACE_TEXT ("* Event ignorableWhitespace () ***************\n")));
}
void
@@ -101,8 +99,7 @@ ACEXML_SAXPrint_Handler::setDocumentLocator (ACEXML_Locator * locator)
{
this->locator_ = locator;
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event setDocumentLocator () ***************\n")));
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("* Event setDocumentLocator () ***************\n")));
}
void
diff --git a/ACEXML/examples/SAXPrint/main.cpp b/ACEXML/examples/SAXPrint/main.cpp
index 6986744dd18..f9db2084d15 100644
--- a/ACEXML/examples/SAXPrint/main.cpp
+++ b/ACEXML/examples/SAXPrint/main.cpp
@@ -2,6 +2,7 @@
#include "ACEXML/common/FileCharStream.h"
#include "ACEXML/common/HttpCharStream.h"
+#include "ACEXML/common/ZipCharStream.h"
#include "ACEXML/common/StrCharStream.h"
#include "ACEXML/parser/parser/Parser.h"
#include "Print_Handler.h"
@@ -16,10 +17,11 @@ static void
usage (const ACE_TCHAR* program)
{
ACE_ERROR ((LM_ERROR,
- ACE_TEXT ("Usage: %s [-sl] [-f <filename> | -u <url>]\n")
+ ACE_TEXT ("Usage: %s [-sl] [-f <filename> | -u <url> | -z <ZIP Archive>]\n")
ACE_TEXT (" -s: Use SAXPrint_Handler (Default is Print_Handler)\n")
ACE_TEXT (" -l: Parse the internal strings (test the StrCharStream class)\n")
ACE_TEXT (" -f: Specify the filename when -l is not specified\n")
+ ACE_TEXT (" -z: Specify that the file is inside a ZIP archive\n")
ACE_TEXT (" -u: URL specifying the path to the file\n"),
program));
}
@@ -30,30 +32,34 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
ACEXML_Char* filename = 0;
int sax = 0; // Use SAXPrint handler or not.
int str = 0;
+ int zip = 0;
ACEXML_Char* url = 0;
- ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("sf:lu:"));
+ ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("sf:lu:z"));
int c;
while ((c = get_opt ()) != EOF)
{
switch (c)
{
- case 's':
- sax = 1;
- break;
- case 'l':
- str = 1;
- break;
- case 'f':
- filename = get_opt.opt_arg ();
- break;
- case 'u':
- url = get_opt.opt_arg();
- break;
- default:
- usage(argv[0]);
- return -1;
+ case 's':
+ sax = 1;
+ break;
+ case 'l':
+ str = 1;
+ break;
+ case 'f':
+ filename = get_opt.opt_arg ();
+ break;
+ case 'u':
+ url = get_opt.opt_arg();
+ break;
+ case 'z':
+ zip = 1;
+ break;
+ default:
+ usage(argv[0]);
+ return -1;
}
}
@@ -67,56 +73,67 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
ACEXML_CharStream *stm = 0;
ACEXML_FileCharStream *fstm = 0;
ACEXML_HttpCharStream *ustm = 0;
- if (filename != 0)
- {
- ACE_NEW_RETURN (fstm,
- ACEXML_FileCharStream (),
- -1);
-
- if (fstm->open (filename) != 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("Failed to open XML file: %s\n"),
- filename),
- -1);
- stm = fstm;
- }
- else if (url != 0)
- {
+ ACEXML_ZipCharStream* zstm = 0;
+ if (filename != 0)
+ {
+ if (zip)
+ {
+ ACE_NEW_RETURN (zstm, ACEXML_ZipCharStream(), -1);
+ if (zstm->open (filename) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Failed to open XML file: %s\n"),
+ filename),
+ -1);
+ stm = zstm;
+ }
+ else
+ {
+ ACE_NEW_RETURN (fstm, ACEXML_FileCharStream (), -1);
+ if (fstm->open (filename) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Failed to open XML file: %s\n"),
+ filename),
+ -1);
+ stm = fstm;
+ }
+ }
+ else if (url != 0)
+ {
- ACE_NEW_RETURN (ustm,
- ACEXML_HttpCharStream (),
- -1);
- if (ustm->open (url) != 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("Failed to open URL : %s\n"),
- url),
- -1);
- stm = ustm;
- }
- else {
- ACE_NEW_RETURN (stm,
- ACEXML_StrCharStream (test_string),
- -1);
- }
+ ACE_NEW_RETURN (ustm,
+ ACEXML_HttpCharStream (),
+ -1);
+ if (ustm->open (url) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Failed to open URL : %s\n"),
+ url),
+ -1);
+ stm = ustm;
+ }
+ else {
+ ACE_NEW_RETURN (stm,
+ ACEXML_StrCharStream (test_string),
+ -1);
+ }
ACEXML_Char* name = (filename == 0) ? url : filename;
- if (sax == 0)
- ACE_NEW_RETURN (handler,
+ if (sax == 0)
+ ACE_NEW_RETURN (handler,
ACEXML_Print_Handler (name),
- -1);
- else
- ACE_NEW_RETURN (handler,
+ -1);
+ else
+ ACE_NEW_RETURN (handler,
ACEXML_SAXPrint_Handler (name),
- -1);
+ -1);
- ACEXML_Parser parser;
- ACEXML_InputSource* input = 0;
- ACE_NEW_RETURN (input, ACEXML_InputSource (stm), -1);
+ ACEXML_Parser parser;
+ ACEXML_InputSource* input = 0;
+ ACE_NEW_RETURN (input, ACEXML_InputSource (stm), -1);
- parser.setContentHandler (handler);
- parser.setDTDHandler (handler);
- parser.setErrorHandler (handler);
- parser.setEntityResolver (handler);
+ parser.setContentHandler (handler);
+ parser.setDTDHandler (handler);
+ parser.setErrorHandler (handler);
+ parser.setEntityResolver (handler);
ACEXML_TRY_NEW_ENV
{
@@ -127,7 +144,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_UNUSED_ARG (ex);
ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Exception occurred. Exiting...\n")));
- }
+ }
ACEXML_ENDTRY;
return 0;
}
diff --git a/ACEXML/parser/parser/Parser.cpp b/ACEXML/parser/parser/Parser.cpp
index 7af4537a3f0..3d50dce87a3 100644
--- a/ACEXML/parser/parser/Parser.cpp
+++ b/ACEXML/parser/parser/Parser.cpp
@@ -24,6 +24,9 @@ ACEXML_Parser::namespaces_feature_[] = ACE_TEXT ("http://xml.org/sax/features/na
const ACEXML_Char
ACEXML_Parser::namespace_prefixes_feature_[] = ACE_TEXT ("http://xml.org/sax/features/namespace-prefixes");
+const ACEXML_Char
+ACEXML_Parser::validation_feature_[] = ACE_TEXT ("http://xml.org/sax/features/validation");
+
ACEXML_Parser::ACEXML_Parser (void)
: dtd_handler_ (0),
entity_resolver_ (0),
@@ -126,16 +129,18 @@ ACEXML_Parser::parse (ACEXML_InputSource *input ACEXML_ENV_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK;
}
- fwd = this->get();
+ fwd = this->peek();
}
switch (fwd)
{
case '?':
+ this->get();
this->parse_processing_instruction (ACEXML_ENV_SINGLE_ARG_PARAMETER);
ACEXML_CHECK;
xmldecl_defined = 1;
break;
case '!':
+ this->get();
fwd = this->peek ();
if (fwd == 'D' && !doctype_defined) // DOCTYPE
{
@@ -174,6 +179,13 @@ ACEXML_Parser::parse (ACEXML_InputSource *input ACEXML_ENV_ARG_DECL)
}
}
+ if (this->validate_ && !doctype_defined)
+ {
+ this->warning (ACE_TEXT ("No doctypeDecl in valid document")
+ ACEXML_ENV_ARG_PARAMETER);
+ ACEXML_CHECK;
+ }
+
// Now parse root element.
this->parse_element (1 ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK;
@@ -298,7 +310,7 @@ ACEXML_Parser::parse_external_dtd (ACEXML_ENV_SINGLE_ARG_DECL)
}
if (ip)
{
- if (this->switch_input (ip) != 0)
+ if (this->switch_input (ip, (uri ? uri : systemId), publicId) != 0)
return -1;
}
else
@@ -377,6 +389,7 @@ ACEXML_Parser::parse_external_subset (ACEXML_ENV_SINGLE_ARG_DECL)
{
this->ref_state_ = ACEXML_ParserInt::IN_EXT_DTD;
this->external_subset_ = 1;
+ int nrelems = 0;
ACEXML_Char nextch = this->skip_whitespace();
do {
switch (nextch)
@@ -412,8 +425,10 @@ ACEXML_Parser::parse_external_subset (ACEXML_ENV_SINGLE_ARG_DECL)
ACEXML_CHECK_RETURN (-1);
break;
case 0:
- this->pop_context (0 ACEXML_ENV_ARG_PARAMETER);
+ nrelems = this->pop_context (0 ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
+ if (nrelems == 1)
+ return 0;
break;
default:
this->fatal_error (ACE_TEXT ("Invalid content in external DTD")
@@ -633,7 +648,7 @@ ACEXML_Parser::parse_markup_decl (ACEXML_ENV_SINGLE_ARG_DECL)
this->fatal_error (ACE_TEXT ("Unexpected end-of-file")
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
- default:
+ default:
this->fatal_error (ACE_TEXT ("Invalid markupDecl")
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
@@ -772,7 +787,8 @@ ACEXML_Parser::parse_element (int is_root ACEXML_ENV_ARG_DECL)
}
ACEXML_AttributesImpl attributes;
ACEXML_Char ch;
- const ACEXML_Char *ns_uri, *ns_lname; // namespace URI and localName
+ const ACEXML_Char* ns_uri = 0;
+ const ACEXML_Char* ns_lname = 0; // namespace URI and localName
for (int start_element_done = 0; start_element_done == 0;)
{
ch = this->skip_whitespace ();
@@ -1017,13 +1033,15 @@ ACEXML_Parser::parse_content (const ACEXML_Char* startname,
if (this->peek () == '#')
{
ACEXML_Char buf[7];
- if (this->parse_char_reference (buf, sizeof (buf)) != 0)
+ size_t len = sizeof (buf);
+ if (this->parse_char_reference (buf, len) != 0)
{
// [WFC: Legal Character]
this->fatal_error (ACE_TEXT ("Invalid CharacterRef")
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
+ cdata_length += len;
}
else
{
@@ -1318,7 +1336,7 @@ ACEXML_Parser::parse_attlist_decl (ACEXML_ENV_SINGLE_ARG_DECL)
if (!this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER)
&& !count)
this->fatal_error(ACE_TEXT ("Expecting space between element "
- "name and AttDef")
+ "name and AttDef")
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
attname = this->parse_attname (ACEXML_ENV_SINGLE_ARG_PARAMETER);
@@ -1339,14 +1357,17 @@ ACEXML_Parser::parse_attlist_decl (ACEXML_ENV_SINGLE_ARG_DECL)
ACEXML_CHECK_RETURN (-1);
if (!count)
{
- this->fatal_error(ACE_TEXT ("Expecting space between AttName and "
- "AttType") ACEXML_ENV_ARG_PARAMETER);
+ this->fatal_error(ACE_TEXT ("Expecting space between AttType and"
+ " DefaultDecl")
+ ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
this->parse_defaultdecl (ACEXML_ENV_SINGLE_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
- count = this->skip_whitespace_count(&fwd);
+ count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
+ ACEXML_CHECK_RETURN (-1);
+ this->skip_whitespace_count(&fwd);
}
this->get (); // consume closing '>'
return 0;
@@ -1376,7 +1397,7 @@ ACEXML_Parser::check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_DECL)
else
{
this->fatal_error(ACE_TEXT ("Illegal PERef within markupDecl")
- ACEXML_ENV_ARG_PARAMETER);
+ ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
}
@@ -1394,7 +1415,6 @@ ACEXML_Char*
ACEXML_Parser::parse_attname (ACEXML_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
- ACEXML_Char fwd = this->get();
// Parse attribute name
ACEXML_Char *att_name = this->parse_name ();
if (att_name == 0)
@@ -1488,7 +1508,7 @@ ACEXML_Parser::parse_tokenized_type (ACEXML_ENV_SINGLE_ARG_DECL)
switch (ch)
{
case 'I':
- if (this->get () == 'D')
+ if (this->get () == 'D')
{
if (this->peek() != 'R' && this->is_whitespace (this->peek()))
{
@@ -1609,7 +1629,7 @@ ACEXML_Parser::parse_atttype (ACEXML_ENV_SINGLE_ARG_DECL)
switch (nextch)
{
case 'C': // CDATA
- if (this->parse_token (ACE_TEXT ("DATA")) < 0)
+ if (this->parse_token (ACE_TEXT ("CDATA")) < 0)
{
this->fatal_error(ACE_TEXT ("Expecting keyword 'CDATA'")
ACEXML_ENV_ARG_PARAMETER);
@@ -1626,7 +1646,7 @@ ACEXML_Parser::parse_atttype (ACEXML_ENV_SINGLE_ARG_DECL)
case 'N': // NMTOKEN, NMTOKENS, or NOTATION
this->get();
nextch = this->peek();
- if (nextch != 'M' || nextch != 'O')
+ if (nextch != 'M' && nextch != 'O')
{
this->fatal_error (ACE_TEXT ("Expecting keyword 'NMTOKEN', "
"'NMTOKENS' or 'NOTATION'")
@@ -1665,6 +1685,7 @@ ACEXML_Parser::parse_atttype (ACEXML_ENV_SINGLE_ARG_DECL)
this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
do {
+ this->skip_whitespace_count();
ACEXML_Char *notation_name = this->parse_name ();
if (notation_name == 0)
{
@@ -1681,15 +1702,17 @@ ACEXML_Parser::parse_atttype (ACEXML_ENV_SINGLE_ARG_DECL)
{
this->fatal_error (ACE_TEXT ("Expecting a ')' after a "
"NotationType declaration")
- ACEXML_ENV_ARG_PARAMETER);
+ ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
}
break;
case '(': // EnumeratedType - Enumeration
+ this->get();
this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
do {
+ this->skip_whitespace_count();
ACEXML_Char *token_name = this->parse_nmtoken ();
if (token_name == 0)
{
@@ -1706,7 +1729,7 @@ ACEXML_Parser::parse_atttype (ACEXML_ENV_SINGLE_ARG_DECL)
{
this->fatal_error (ACE_TEXT ("Expecting a ')' after a "
"Enumeration declaration")
- ACEXML_ENV_ARG_PARAMETER);
+ ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
break;
@@ -1746,8 +1769,8 @@ ACEXML_Parser::parse_notation_decl (ACEXML_ENV_SINGLE_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
- count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
- ACEXML_CHECK_RETURN (-1);
+ count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
+ ACEXML_CHECK_RETURN (-1);
if (!count)
{
this->fatal_error (ACE_TEXT ("Expecting a space between notation name "
@@ -1868,6 +1891,8 @@ ACEXML_Parser::parse_element_decl (ACEXML_ENV_SINGLE_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
+ count = this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
+ ACEXML_CHECK_RETURN (-1);
if (this->skip_whitespace () != '>')
{
this->fatal_error (ACE_TEXT ("Expecting '>' after element defintion")
@@ -1951,6 +1976,8 @@ ACEXML_Parser::parse_child (int skip_open_paren ACEXML_ENV_ARG_DECL)
switch (nextch)
{
case '(':
+ this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
+ ACEXML_CHECK_RETURN (-1);
this->parse_child (0 ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
break;
@@ -1965,6 +1992,26 @@ ACEXML_Parser::parse_child (int skip_open_paren ACEXML_ENV_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
+ // 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.
+ }
+
// @@ Inform validator of the new element here.
break;
}
@@ -2004,6 +2051,7 @@ ACEXML_Parser::parse_child (int skip_open_paren ACEXML_ENV_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
+ break;
case ')':
break;
default:
@@ -2012,12 +2060,15 @@ ACEXML_Parser::parse_child (int skip_open_paren ACEXML_ENV_ARG_DECL)
ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
}
- this->get (); // consume , | or )
+ nextch = this->get(); // Consume the `,' or `|' or `)'
+ if (nextch == ')')
+ break;
this->check_for_PE_reference (ACEXML_ENV_SINGLE_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
this->skip_whitespace_count (&nextch);
} while (nextch != ')');
+
// Check for trailing '?', '*', '+'
nextch = this->peek ();
switch (nextch)
@@ -2041,7 +2092,7 @@ ACEXML_Parser::parse_child (int skip_open_paren ACEXML_ENV_ARG_DECL)
}
int
-ACEXML_Parser::parse_char_reference (ACEXML_Char *buf, size_t len)
+ACEXML_Parser::parse_char_reference (ACEXML_Char *buf, size_t& len)
{
if (len < 7) // Max size of a CharRef plus terminating '\0'
return -1;
@@ -2082,6 +2133,7 @@ ACEXML_Parser::parse_char_reference (ACEXML_Char *buf, size_t len)
return -1;
#endif
buf [clen] = 0;
+ len = clen;
for (int j = 0; j < clen; ++j)
this->obstack_.grow (buf[j]);
return 0;
@@ -2151,7 +2203,8 @@ ACEXML_Parser::parse_attvalue (ACEXML_Char *&str ACEXML_ENV_ARG_DECL)
if (this->peek () == '#')
{
ACEXML_Char buf[7];
- if (this->parse_char_reference (buf, sizeof (buf)) != 0)
+ size_t len = sizeof (buf);
+ if (this->parse_char_reference (buf, len) != 0)
{
// [WFC: Legal Character]
this->fatal_error (ACE_TEXT ("Invalid CharacterRef")
@@ -2265,10 +2318,13 @@ ACEXML_Parser::parse_entity_reference (ACEXML_ENV_SINGLE_ARG_DECL)
if (!this->external_entity_)
{
ACEXML_StrCharStream* str = 0;
+ // ACE_DEBUG ((LM_DEBUG,
+ // ACE_TEXT ("Entity is %s\n Replacement Text is : %s\n"),
+ // replace, entity));
ACE_NEW_RETURN (str, ACEXML_StrCharStream (entity), 0);
if (str)
{
- if (this->switch_input (str) != 0)
+ if (this->switch_input (str, replace) != 0)
{
this->fatal_error (ACE_TEXT ("Unable to create internal input "
"stream")
@@ -2292,7 +2348,7 @@ ACEXML_Parser::parse_entity_reference (ACEXML_ENV_SINGLE_ARG_DECL)
}
if (ip)
{
- if (this->switch_input (ip) != 0)
+ if (this->switch_input (ip, (uri ? uri : systemId), publicId) != 0)
{
this->fatal_error (ACE_TEXT ("Internal Parser Error")
ACEXML_ENV_ARG_PARAMETER);
@@ -2382,10 +2438,13 @@ ACEXML_Parser::parse_PE_reference (ACEXML_ENV_SINGLE_ARG_DECL)
const ACEXML_Char ch = '\x20';
str = ch + str + ch;
}
+ // ACE_DEBUG ((LM_DEBUG,
+ // ACE_TEXT ("Entity is %s\n Replacement Text is : %s\n"),
+ // replace, str.c_str()));
ACE_NEW_RETURN (sstream, ACEXML_StrCharStream (str.c_str()), 0);
if (sstream)
{
- if (this->switch_input (sstream) != 0)
+ if (this->switch_input (sstream, replace) != 0)
{
this->fatal_error (ACE_TEXT ("Error in switching InputSource")
ACEXML_ENV_ARG_PARAMETER);
@@ -2408,7 +2467,7 @@ ACEXML_Parser::parse_PE_reference (ACEXML_ENV_SINGLE_ARG_DECL)
}
if (ip)
{
- if (this->switch_input (ip) != 0)
+ if (this->switch_input (ip, (uri ? uri : systemId), publicId) != 0)
{
this->fatal_error (ACE_TEXT ("Error in switching InputSource")
ACEXML_ENV_ARG_PARAMETER);
@@ -2489,7 +2548,8 @@ ACEXML_Parser::parse_entity_value (ACEXML_Char *&str
if (!this->external_entity_)
{
ACEXML_Char buf[7];
- if (this->parse_char_reference (buf, sizeof (buf)) != 0)
+ size_t len = sizeof (buf);
+ if (this->parse_char_reference (buf, len) != 0)
{
// [WFC: Legal Character]
this->fatal_error (ACE_TEXT ("Invalid character "
@@ -2513,7 +2573,7 @@ ACEXML_Parser::parse_entity_value (ACEXML_Char *&str
this->obstack_.grow (ch);
break;
case 0:
- nrelems = this->pop_context (0 ACEXML_ENV_ARG_PARAMETER);
+ this->pop_context (0 ACEXML_ENV_ARG_PARAMETER);
ACEXML_CHECK_RETURN (-1);
break;
default:
@@ -2747,11 +2807,7 @@ ACEXML_Parser::switch_input (ACEXML_InputSource* input,
const ACEXML_Char* publicId)
{
ACEXML_LocatorImpl* locator = 0;
- if (!systemId && this->current_ && this->current_->getLocator())
- locator = ACE_const_cast (ACEXML_LocatorImpl*,
- this->current_->getLocator());
- if (!locator)
- ACE_NEW_RETURN (locator, ACEXML_LocatorImpl (systemId, publicId), -1);
+ ACE_NEW_RETURN (locator, ACEXML_LocatorImpl (systemId, publicId), -1);
ACEXML_Parser_Context* new_context = 0;
ACE_NEW_RETURN (new_context, ACEXML_Parser_Context(input, locator), -1);
if (this->push_context (new_context) != 0)
@@ -2796,7 +2852,7 @@ ACEXML_Parser::pop_context (int GE_ref ACEXML_ENV_ARG_DECL)
ACEXML_CHECK_RETURN (-1);
}
ACEXML_String reference;
- if (GE_ref)
+ if (GE_ref && this->GE_reference_.size() > 0)
{
if (this->GE_reference_.pop (reference) < 0)
{
@@ -2805,7 +2861,7 @@ ACEXML_Parser::pop_context (int GE_ref ACEXML_ENV_ARG_DECL)
ACEXML_CHECK_RETURN (-1);
}
}
- else
+ else if (this->PE_reference_.size() > 0)
{
if (this->PE_reference_.pop (reference) < 0)
{
@@ -2830,7 +2886,7 @@ ACEXML_Parser::pop_context (int GE_ref ACEXML_ENV_ARG_DECL)
// Set up Locator.
if (this->content_handler_)
this->content_handler_->setDocumentLocator (this->current_->getLocator());
- return 0;
+ return nrelems;
}
int
@@ -2851,7 +2907,10 @@ ACEXML_Parser::getFeature (const ACEXML_Char *name ACEXML_ENV_ARG_DECL)
{
return this->namespace_prefixes_;
}
-
+ else if (ACE_OS::strcmp (name, ACEXML_Parser::validation_feature_) == 0)
+ {
+ return this->validate_;
+ }
ACEXML_THROW_RETURN (ACEXML_SAXNotRecognizedException (name), -1);
}
@@ -2879,6 +2938,11 @@ ACEXML_Parser::setFeature (const ACEXML_Char *name,
this->namespace_prefixes_ = (boolean_value == 0 ? 0 : 1);
return;
}
+ else if (ACE_OS::strcmp (name, ACEXML_Parser::validation_feature_) == 0)
+ {
+ this->validate_ = (boolean_value == 0 ? 0 : 1);
+ return;
+ }
ACEXML_THROW (ACEXML_SAXNotRecognizedException (name));
}
@@ -3156,7 +3220,7 @@ ACEXML_Parser::parse_processing_instruction (ACEXML_ENV_SINGLE_ARG_DECL)
void
ACEXML_Parser::reset (void)
{
- if (this->ctx_stack_.pop (this->current_) != -1)
+ if (this->ctx_stack_.pop (this->current_) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Mismatched push/pop of Context stack")));
delete this->current_;
ACEXML_String temp;
diff --git a/ACEXML/parser/parser/Parser.h b/ACEXML/parser/parser/Parser.h
index d7f0cd9012c..c92af489869 100644
--- a/ACEXML/parser/parser/Parser.h
+++ b/ACEXML/parser/parser/Parser.h
@@ -231,7 +231,7 @@ protected:
*
* @retval 0 on success and -1 otherwise.
*/
- int parse_char_reference (ACEXML_Char *buf, size_t len);
+ int parse_char_reference (ACEXML_Char *buf, size_t& len);
/**
* Parse a reference name, i.e., foo in "&foo;" or "%foo;". The first
@@ -786,6 +786,15 @@ private:
*/
static const ACEXML_Char namespace_prefixes_feature_[];
+ /**
+ * @var validation_feature_
+ *
+ * This constant string defines the SAX XML Validation feature. When
+ * this feature is enabled, the parser validates the document in
+ * addition to checking for well-formedness.
+ */
+ static const ACEXML_Char validation_feature_[];
+
/* @} */
/// Keeping track of the handlers. We do not manage the memory for
diff --git a/ChangeLog b/ChangeLog
index 0d0ea2ce7a8..56810ab1e60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,45 @@
+Mon Nov 18 20:30:30 2002 Krishnakumar B <kitty@cs.wustl.edu>
+
+ * ACEXML/common/CharStream.h:
+ * ACEXML/common/Encoding.cpp:
+ * ACEXML/common/FileCharStream.cpp:
+ * ACEXML/common/FileCharStream.h:
+ * ACEXML/common/StrCharStream.cpp:
+ * ACEXML/common/StrCharStream.h:
+ * ACEXML/common/HttpCharStream.cpp:
+ * ACEXML/common/HttpCharStream.h:
+
+ Fixed a number of minor typos and debugging statements.
+
+ * ACEXML/common/LocatorImpl.cpp: Check for a valid string before
+ assigning it to the new Locator.
+
+ * ACEXML/common/NamespaceSupport.cpp:
+
+ Make sure that we don't have a null prefix before trying to
+ dereference the prefix.
+
+ * ACEXML/common/ZipCharStream.cpp:
+ * ACEXML/common/ZipCharStream.h:
+
+ New stream which reads files from a ZIP archive.
+
+ * ACEXML/common/StreamFactory.cpp:
+
+ Modified to accomodate ZipCharStream.
+
+ * ACEXML/examples/SAXPrint/Print_Handler.cpp:
+ * ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp:
+ * ACEXML/examples/SAXPrint/main.cpp:
+
+ Commented out a lot of unnecessary debug statements.
+
+ * ACEXML/parser/parser/Parser.cpp:
+ * ACEXML/parser/parser/Parser.h:
+
+ Lots of bugfixes. Finally we parse the XML version of XHTML
+ specification without dumping core.
+
Sat Nov 16 21:18:55 2002 Krishnakumar B <kitty@cs.wustl.edu>
* ACEXML/parser/parser/Parser.cpp:
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index 0d0ea2ce7a8..56810ab1e60 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,45 @@
+Mon Nov 18 20:30:30 2002 Krishnakumar B <kitty@cs.wustl.edu>
+
+ * ACEXML/common/CharStream.h:
+ * ACEXML/common/Encoding.cpp:
+ * ACEXML/common/FileCharStream.cpp:
+ * ACEXML/common/FileCharStream.h:
+ * ACEXML/common/StrCharStream.cpp:
+ * ACEXML/common/StrCharStream.h:
+ * ACEXML/common/HttpCharStream.cpp:
+ * ACEXML/common/HttpCharStream.h:
+
+ Fixed a number of minor typos and debugging statements.
+
+ * ACEXML/common/LocatorImpl.cpp: Check for a valid string before
+ assigning it to the new Locator.
+
+ * ACEXML/common/NamespaceSupport.cpp:
+
+ Make sure that we don't have a null prefix before trying to
+ dereference the prefix.
+
+ * ACEXML/common/ZipCharStream.cpp:
+ * ACEXML/common/ZipCharStream.h:
+
+ New stream which reads files from a ZIP archive.
+
+ * ACEXML/common/StreamFactory.cpp:
+
+ Modified to accomodate ZipCharStream.
+
+ * ACEXML/examples/SAXPrint/Print_Handler.cpp:
+ * ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp:
+ * ACEXML/examples/SAXPrint/main.cpp:
+
+ Commented out a lot of unnecessary debug statements.
+
+ * ACEXML/parser/parser/Parser.cpp:
+ * ACEXML/parser/parser/Parser.h:
+
+ Lots of bugfixes. Finally we parse the XML version of XHTML
+ specification without dumping core.
+
Sat Nov 16 21:18:55 2002 Krishnakumar B <kitty@cs.wustl.edu>
* ACEXML/parser/parser/Parser.cpp: