version 1.1.1.1, 2001/01/14 19:53:23
|
version 1.10, 2001/06/16 17:30:38
|
|
|
//BEGIN_LICENSE |
//%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// copy of this software and associated documentation files (the "Software"), |
// of this software and associated documentation files (the "Software"), to |
// to deal in the Software without restriction, including without limitation |
// deal in the Software without restriction, including without limitation the |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// and/or sell copies of the Software, and to permit persons to whom the |
// sell copies of the Software, and to permit persons to whom the Software is |
// Software is furnished to do so, subject to the following conditions: |
// furnished to do so, subject to the following conditions: |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// DEALINGS IN THE SOFTWARE. |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
//END_LICENSE |
//============================================================================== |
//BEGIN_HISTORY |
|
// | // |
// Author: |
// Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// $Log$ |
// Modified By: |
// Revision 1.1.1.1 2001/01/14 19:53:23 mike |
|
// Pegasus import |
|
// | // |
// |
//%///////////////////////////////////////////////////////////////////////////// |
//END_HISTORY |
|
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
// | // |
|
|
#include <cstdlib> | #include <cstdlib> |
#include <cstring> | #include <cstring> |
#include "XmlParser.h" | #include "XmlParser.h" |
|
#include "Logger.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
#define PEGASUS_ARRAY_T XmlEntry |
|
# include "ArrayImpl.h" |
|
#undef PEGASUS_ARRAY_T |
|
|
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
// | // |
// Static helper functions | // Static helper functions |
|
|
for (; *p; p++) | for (; *p; p++) |
{ | { |
if (*p == '\n') | if (*p == '\n') |
std::cout << "\\n"; |
PEGASUS_STD(cout) << "\\n"; |
else if (*p == '\r') | else if (*p == '\r') |
std::cout << "\\r"; |
PEGASUS_STD(cout) << "\\r"; |
else if (*p == '\t') | else if (*p == '\t') |
std::cout << "\\t"; |
PEGASUS_STD(cout) << "\\t"; |
else | else |
std::cout << *p; |
PEGASUS_STD(cout) << *p; |
} | } |
} | } |
| |
|
|
// | // |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
| |
static char* _xmlMessages[] = |
static const char* _xmlMessages[] = |
{ | { |
"Bad opening element", | "Bad opening element", |
"Bad closing element", | "Bad closing element", |
|
|
result.append(": on line "); | result.append(": on line "); |
result.append(buffer); | result.append(buffer); |
| |
if (message.getLength()) |
if (message.size()) |
{ | { |
result.append(": "); | result.append(": "); |
result.append(message); | result.append(message); |
|
|
XmlSemanticError::XmlSemanticError( | XmlSemanticError::XmlSemanticError( |
Uint32 lineNumber, | Uint32 lineNumber, |
const String& message) | const String& message) |
: XmlException(XmlException::VALIDATION_ERROR, lineNumber, message) |
: XmlException(XmlException::SEMANTIC_ERROR, lineNumber, message) |
{ | { |
| |
} | } |
|
|
Boolean XmlParser::_getElementName(char*& p) | Boolean XmlParser::_getElementName(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') | if (!isalpha(*p) && *p != '_') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
} |
|
| |
while (*p && | while (*p && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) | (isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
|
|
openCloseElement = false; | openCloseElement = false; |
| |
if (!isalpha(*p) && *p != '_') | if (!isalpha(*p) && *p != '_') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
} |
|
| |
while (*p && | while (*p && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) | (isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
|
|
void XmlParser::_getAttributeNameAndEqual(char*& p) | void XmlParser::_getAttributeNameAndEqual(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') | if (!isalpha(*p) && *p != '_') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); |
} |
|
| |
while (*p && | while (*p && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) | (isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
|
|
_skipWhitespace(p); | _skipWhitespace(p); |
| |
if (*p != '=') | if (*p != '=') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); |
} |
|
| |
p++; | p++; |
| |
|
|
// ATTN-B: handle values contained in semiquotes: | // ATTN-B: handle values contained in semiquotes: |
| |
if (*p != '"' && *p != '\'') | if (*p != '"' && *p != '\'') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} |
|
| |
char startChar = *p++; | char startChar = *p++; |
| |
|
|
p++; | p++; |
| |
if (*p != startChar) | if (*p != startChar) |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} |
|
| |
*p++ = '\0'; | *p++ = '\0'; |
} | } |
|
|
entry.text = ++p; | entry.text = ++p; |
| |
if (!_getElementName(p)) | if (!_getElementName(p)) |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw(XmlException(XmlException::BAD_END_TAG, _line)); | throw(XmlException(XmlException::BAD_END_TAG, _line)); |
} |
|
| |
return; | return; |
} | } |
|
|
} | } |
} | } |
else | else |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
} |
|
| |
//-------------------------------------------------------------------------- | //-------------------------------------------------------------------------- |
// Grab all the attributes: | // Grab all the attributes: |
|
|
_getAttributeNameAndEqual(p); | _getAttributeNameAndEqual(p); |
| |
if (*p != '"' && *p != '\'') | if (*p != '"' && *p != '\'') |
{ |
|
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} |
|
| |
attr.value = p + 1; | attr.value = p + 1; |
_getAttributeValue(p); | _getAttributeValue(p); |
|
|
| |
if (!(p[0] == '?' && p[1] == '>') && !isspace(*p)) | if (!(p[0] == '?' && p[1] == '>') && !isspace(*p)) |
{ | { |
std::cout << __LINE__ << std::endl; |
|
throw XmlException( | throw XmlException( |
XmlException::BAD_ATTRIBUTE_VALUE, _line); | XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} | } |
|
|
{ | { |
// The next thing must be a space or a '>': | // The next thing must be a space or a '>': |
| |
std::cout << __LINE__ << std::endl; |
|
throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} | } |
| |
|
|
| |
void XmlEntry::print() const | void XmlEntry::print() const |
{ | { |
std::cout << "=== " << _typeStrings[type] << " "; |
PEGASUS_STD(cout) << "=== " << _typeStrings[type] << " "; |
| |
Boolean needQuotes = type == XmlEntry::CDATA || type == XmlEntry::CONTENT; | Boolean needQuotes = type == XmlEntry::CDATA || type == XmlEntry::CONTENT; |
| |
if (needQuotes) | if (needQuotes) |
std::cout << "\""; |
PEGASUS_STD(cout) << "\""; |
| |
_printValue(text); | _printValue(text); |
| |
if (needQuotes) | if (needQuotes) |
std::cout << "\""; |
PEGASUS_STD(cout) << "\""; |
| |
std::cout << '\n'; |
PEGASUS_STD(cout) << '\n'; |
| |
for (Uint32 i = 0; i < attributeCount; i++) | for (Uint32 i = 0; i < attributeCount; i++) |
{ | { |
std::cout << " " << attributes[i].name << "=\""; |
PEGASUS_STD(cout) << " " << attributes[i].name << "=\""; |
_printValue(attributes[i].value); | _printValue(attributes[i].value); |
std::cout << "\"" << std::endl; |
PEGASUS_STD(cout) << "\"" << PEGASUS_STD(endl); |
} | } |
} | } |
| |
|
|
return true; | return true; |
} | } |
| |
|
void XmlAppendCString(Array<Sint8>& out, const char* str) |
|
{ |
|
out.append(str, strlen(str)); |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |