version 1.18.6.1, 2003/07/29 15:08:29
|
version 1.32.2.1, 2005/09/28 02:07:30
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2005//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
|
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) | // Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// Modified By: |
// Modified By: David Dillard, VERITAS Software Corp. |
|
// (david.dillard@veritas.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#include "XmlParser.h" | #include "XmlParser.h" |
#include "Logger.h" | #include "Logger.h" |
#include "ExceptionRep.h" | #include "ExceptionRep.h" |
|
#include "CharSet.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
{ "'", 6, '\'' } | { "'", 6, '\'' } |
}; | }; |
| |
|
|
|
// Implements a check for a whitespace character, without calling |
|
// isspace( ). The isspace( ) function is locale-sensitive, |
|
// and incorrectly flags some chars above 0x7f as whitespace. This |
|
// causes the XmlParser to incorrectly parse UTF-8 data. |
|
// |
|
// Section 2.3 of XML 1.0 Standard (http://www.w3.org/TR/REC-xml) |
|
// defines white space as: |
|
// S ::= (#x20 | #x9 | #xD | #xA)+ |
|
static inline int _isspace(char c) |
|
{ |
|
return CharSet::is_space(c); |
|
} |
|
|
static Uint32 _REFERENCES_SIZE = (sizeof(_references) / sizeof(_references[0])); | static Uint32 _REFERENCES_SIZE = (sizeof(_references) / sizeof(_references[0])); |
| |
// Remove all redundant spaces from the given string: | // Remove all redundant spaces from the given string: |
| |
static void _normalize(char* text) | static void _normalize(char* text) |
{ | { |
Uint32 length = strlen(text); |
|
char* p = text; | char* p = text; |
char* end = p + length; |
char* end = p + strlen(text); |
| |
// Remove leading spaces: | // Remove leading spaces: |
| |
while (isspace(*p)) |
while (_isspace(*p)) |
p++; | p++; |
| |
if (p != text) | if (p != text) |
|
|
{ | { |
// Advance to the next space: | // Advance to the next space: |
| |
while (*p && !isspace(*p)) |
while (*p && !_isspace(*p)) |
p++; | p++; |
| |
if (!*p) | if (!*p) |
|
|
| |
char* q = p++; | char* q = p++; |
| |
while (isspace(*p)) |
while (_isspace(*p)) |
p++; | p++; |
| |
// Discard trailing spaces (if we are at the end): | // Discard trailing spaces (if we are at the end): |
|
|
| |
// Remove the redundant spaces: | // Remove the redundant spaces: |
| |
Uint32 n = p - q; |
const size_t n = p - q; |
| |
if (n > 1) | if (n > 1) |
{ | { |
|
|
"Common.XmlParser.SEMANTIC_ERROR" | "Common.XmlParser.SEMANTIC_ERROR" |
}; | }; |
| |
// l10n TODO replace _formMessage with the commented one and uncomment |
// l10n replace _formMessage (comment out the old one) |
// the new constructors |
|
/* | /* |
static String _formMessage(Uint32 code, Uint32 line, const String& message) | static String _formMessage(Uint32 code, Uint32 line, const String& message) |
{ | { |
|
|
MessageLoaderParms& msgParms) | MessageLoaderParms& msgParms) |
: Exception(_formPartialMessage(code, lineNumber)) | : Exception(_formPartialMessage(code, lineNumber)) |
{ | { |
|
if (msgParms.default_msg.size()) |
|
{ |
|
msgParms.default_msg = ": " + msgParms.default_msg; |
|
} |
_rep->message.append(MessageLoader::getMessage(msgParms)); | _rep->message.append(MessageLoader::getMessage(msgParms)); |
} | } |
| |
|
|
| |
void XmlParser::_skipWhitespace(char*& p) | void XmlParser::_skipWhitespace(char*& p) |
{ | { |
while (*p && isspace(*p)) |
while (*p && _isspace(*p)) |
{ | { |
if (*p == '\n') | if (*p == '\n') |
_line++; | _line++; |
|
|
| |
Boolean XmlParser::_getElementName(char*& p) | Boolean XmlParser::_getElementName(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
// The next character must be a space: | // The next character must be a space: |
| |
if (isspace(*p)) |
if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); | _skipWhitespace(p); |
|
|
{ | { |
openCloseElement = false; | openCloseElement = false; |
| |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
// The next character must be a space: | // The next character must be a space: |
| |
if (isspace(*p)) |
if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); | _skipWhitespace(p); |
|
|
| |
void XmlParser::_getAttributeNameAndEqual(char*& p) | void XmlParser::_getAttributeNameAndEqual(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
char* term = p; | char* term = p; |
|
|
| |
void XmlParser::_substituteReferences(char* text) | void XmlParser::_substituteReferences(char* text) |
{ | { |
Uint32 rem = strlen(text); |
size_t rem = strlen(text); |
| |
for (char* p = text; *p; p++, rem--) | for (char* p = text; *p; p++, rem--) |
{ | { |
|
|
| |
return; | return; |
} | } |
else if (isalpha(*p) || *p == '_') |
else if ((((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
{ | { |
entry.type = XmlEntry::START_TAG; | entry.type = XmlEntry::START_TAG; |
entry.text = p; | entry.text = p; |
|
|
{ | { |
// The next thing must a space or a "?>": | // The next thing must a space or a "?>": |
| |
if (!(p[0] == '?' && p[1] == '>') && !isspace(*p)) |
if (!(p[0] == '?' && p[1] == '>') && !_isspace(*p)) |
{ | { |
throw XmlException( | throw XmlException( |
XmlException::BAD_ATTRIBUTE_VALUE, _line); | XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} | } |
} | } |
else if (!(*p == '>' || (p[0] == '/' && p[1] == '>') || isspace(*p))) |
else if (!(*p == '>' || (p[0] == '/' && p[1] == '>') || _isspace(*p))) |
{ | { |
// The next thing must be a space or a '>': | // The next thing must be a space or a '>': |
| |
|
|
{ | { |
first = str; | first = str; |
| |
while (isspace(*first)) |
while (_isspace(*first)) |
first++; | first++; |
| |
if (!*first) | if (!*first) |
|
|
| |
last = first + strlen(first); | last = first + strlen(first); |
| |
while (last != first && isspace(last[-1])) |
while (last != first && _isspace(last[-1])) |
last--; | last--; |
} | } |
| |
|
|
if (!end || end != last) | if (!end || end != last) |
return false; | return false; |
| |
value = Uint32(tmp); |
value = static_cast<Real32>(tmp); |
return true; | return true; |
} | } |
| |
|
|
if (!getAttributeValue(name, tmp)) | if (!getAttributeValue(name, tmp)) |
return false; | return false; |
| |
value = tmp; |
value = String(tmp); |
return true; | return true; |
} | } |
| |
void XmlAppendCString(Array<Sint8>& out, const char* str) |
void XmlAppendCString(Array<char>& out, const char* str) |
{ | { |
out.append(str, strlen(str)); |
out.append(str, static_cast<Uint32>(strlen(str))); |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |