diff options
Diffstat (limited to 'indra/llxml/llxmlnode.h')
| -rw-r--r-- | indra/llxml/llxmlnode.h | 182 |
1 files changed, 104 insertions, 78 deletions
diff --git a/indra/llxml/llxmlnode.h b/indra/llxml/llxmlnode.h index 58cef95ce0..9df37ccb6f 100644 --- a/indra/llxml/llxmlnode.h +++ b/indra/llxml/llxmlnode.h @@ -2,30 +2,25 @@ * @file llxmlnode.h * @brief LLXMLNode definition * - * $LicenseInfo:firstyear=2000&license=viewergpl$ - * - * Copyright (c) 2000-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2000&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -33,7 +28,7 @@ #define LL_LLXMLNODE_H #ifndef XML_STATIC -#define XML_STATIC 1 +#define XML_STATIC #endif #ifdef LL_STANDALONE #include <expat.h> @@ -43,10 +38,11 @@ #include <map> #include "indra_constants.h" -#include "llmemory.h" -#include "llthread.h" +#include "llpointer.h" +#include "llthread.h" // LLThreadSafeRefCount #include "llstring.h" #include "llstringtable.h" +#include "llfile.h" class LLVector3; @@ -75,7 +71,7 @@ struct CompareAttributes class LLXMLNode; typedef LLPointer<LLXMLNode> LLXMLNodePtr; -typedef std::multimap<LLString, LLXMLNodePtr > LLXMLNodeList; +typedef std::multimap<std::string, LLXMLNodePtr > LLXMLNodeList; typedef std::multimap<const LLStringTableEntry *, LLXMLNodePtr > LLXMLChildList; typedef std::map<const LLStringTableEntry *, LLXMLNodePtr, CompareAttributes> LLXMLAttribList; @@ -87,12 +83,13 @@ class LLVector3d; class LLVector4; class LLVector4U; -struct LLXMLChildren +struct LLXMLChildren : public LLThreadSafeRefCount { LLXMLChildList map; // Map of children names->pointers LLXMLNodePtr head; // Head of the double-linked list LLXMLNodePtr tail; // Tail of the double-linked list }; +typedef LLPointer<LLXMLChildren> LLXMLChildrenPtr; class LLXMLNode : public LLThreadSafeRefCount { @@ -122,18 +119,20 @@ protected: public: LLXMLNode(); - LLXMLNode(const LLString& name, BOOL is_attribute); + LLXMLNode(const char* name, BOOL is_attribute); LLXMLNode(LLStringTableEntry* name, BOOL is_attribute); + LLXMLNode(const LLXMLNode& rhs); + LLXMLNodePtr deepCopy(); BOOL isNull(); BOOL deleteChild(LLXMLNode* child); - void addChild(LLXMLNodePtr new_parent); + void addChild(LLXMLNodePtr new_child, LLXMLNodePtr after_child = LLXMLNodePtr(NULL)); void setParent(LLXMLNodePtr new_parent); // reparent if necessary // Serialization static bool parseFile( - LLString filename, + const std::string& filename, LLXMLNodePtr& node, LLXMLNode* defaults_tree); static bool parseBuffer( @@ -146,19 +145,30 @@ public: LLXMLNodePtr& node, LLXMLNode* defaults); static bool updateNode( - LLXMLNodePtr& node, - LLXMLNodePtr& update_node); - static void writeHeaderToFile(LLFILE *fOut); - void writeToFile(LLFILE *fOut, LLString indent = LLString()); - void writeToOstream(std::ostream& output_stream, const LLString& indent = LLString()); + LLXMLNodePtr& node, + LLXMLNodePtr& update_node); + static LLXMLNodePtr replaceNode(LLXMLNodePtr node, LLXMLNodePtr replacement_node); + + static bool getLayeredXMLNode(const std::string &xui_filename, LLXMLNodePtr& root, + const std::vector<std::string>& paths); + + + // Write standard XML file header: + // <?xml version="1.0" encoding="utf-8" standalone="yes" ?> + static void writeHeaderToFile(LLFILE *out_file); + + // Write XML to file with one attribute per line. + // XML escapes values as they are written. + void writeToFile(LLFILE *out_file, const std::string& indent = std::string(), bool use_type_decorations=true); + void writeToOstream(std::ostream& output_stream, const std::string& indent = std::string(), bool use_type_decorations=true); // Utility - void findName(const LLString& name, LLXMLNodeList &results); + void findName(const std::string& name, LLXMLNodeList &results); void findName(LLStringTableEntry* name, LLXMLNodeList &results); - void findID(const LLString& id, LLXMLNodeList &results); + void findID(const std::string& id, LLXMLNodeList &results); - virtual LLXMLNodePtr createChild(const LLString& name, BOOL is_attribute); + virtual LLXMLNodePtr createChild(const char* name, BOOL is_attribute); virtual LLXMLNodePtr createChild(LLStringTableEntry* name, BOOL is_attribute); @@ -170,60 +180,70 @@ public: U32 getLongValue(U32 expected_length, U64 *array, Encoding encoding = ENCODING_DEFAULT); U32 getFloatValue(U32 expected_length, F32 *array, Encoding encoding = ENCODING_DEFAULT); U32 getDoubleValue(U32 expected_length, F64 *array, Encoding encoding = ENCODING_DEFAULT); - U32 getStringValue(U32 expected_length, LLString *array); + U32 getStringValue(U32 expected_length, std::string *array); U32 getUUIDValue(U32 expected_length, LLUUID *array); U32 getNodeRefValue(U32 expected_length, LLXMLNode **array); - BOOL hasAttribute(const LLString& name ); - - BOOL getAttributeBOOL(const LLString& name, BOOL& value ); - BOOL getAttributeU8(const LLString& name, U8& value ); - BOOL getAttributeS8(const LLString& name, S8& value ); - BOOL getAttributeU16(const LLString& name, U16& value ); - BOOL getAttributeS16(const LLString& name, S16& value ); - BOOL getAttributeU32(const LLString& name, U32& value ); - BOOL getAttributeS32(const LLString& name, S32& value ); - BOOL getAttributeF32(const LLString& name, F32& value ); - BOOL getAttributeF64(const LLString& name, F64& value ); - BOOL getAttributeColor(const LLString& name, LLColor4& value ); - BOOL getAttributeColor4(const LLString& name, LLColor4& value ); - BOOL getAttributeColor4U(const LLString& name, LLColor4U& value ); - BOOL getAttributeVector3(const LLString& name, LLVector3& value ); - BOOL getAttributeVector3d(const LLString& name, LLVector3d& value ); - BOOL getAttributeQuat(const LLString& name, LLQuaternion& value ); - BOOL getAttributeUUID(const LLString& name, LLUUID& value ); - BOOL getAttributeString(const LLString& name, LLString& value ); + BOOL hasAttribute(const char* name ); + + // these are designed to be more generic versions of the functions + // rather than relying on LL-types + bool getAttribute_bool(const char* name, bool& value ); + + BOOL getAttributeBOOL(const char* name, BOOL& value ); + BOOL getAttributeU8(const char* name, U8& value ); + BOOL getAttributeS8(const char* name, S8& value ); + BOOL getAttributeU16(const char* name, U16& value ); + BOOL getAttributeS16(const char* name, S16& value ); + BOOL getAttributeU32(const char* name, U32& value ); + BOOL getAttributeS32(const char* name, S32& value ); + BOOL getAttributeF32(const char* name, F32& value ); + BOOL getAttributeF64(const char* name, F64& value ); + BOOL getAttributeColor(const char* name, LLColor4& value ); + BOOL getAttributeColor4(const char* name, LLColor4& value ); + BOOL getAttributeColor4U(const char* name, LLColor4U& value ); + BOOL getAttributeVector3(const char* name, LLVector3& value ); + BOOL getAttributeVector3d(const char* name, LLVector3d& value ); + BOOL getAttributeQuat(const char* name, LLQuaternion& value ); + BOOL getAttributeUUID(const char* name, LLUUID& value ); + BOOL getAttributeString(const char* name, std::string& value ); const ValueType& getType() const { return mType; } U32 getLength() const { return mLength; } U32 getPrecision() const { return mPrecision; } - const LLString& getValue() const { return mValue; } - LLString getTextContents() const; + const std::string& getValue() const { return mValue; } + std::string getSanitizedValue() const; + std::string getTextContents() const; const LLStringTableEntry* getName() const { return mName; } BOOL hasName(const char* name) const { return mName == gStringTable.checkStringEntry(name); } - BOOL hasName(LLString name) const { return mName == gStringTable.checkStringEntry(name.c_str()); } - const LLString& getID() const { return mID; } + BOOL hasName(const std::string& name) const { return mName == gStringTable.checkStringEntry(name.c_str()); } + const std::string& getID() const { return mID; } U32 getChildCount() const; // getChild returns a Null LLXMLNode (not a NULL pointer) if there is no such child. // This child has no value so any getTYPEValue() calls on it will return 0. - bool getChild(const LLString& name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); + bool getChild(const char* name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); bool getChild(const LLStringTableEntry* name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); - void getChildren(const LLString& name, LLXMLNodeList &children, BOOL use_default_if_missing = TRUE) const; + void getChildren(const char* name, LLXMLNodeList &children, BOOL use_default_if_missing = TRUE) const; void getChildren(const LLStringTableEntry* name, LLXMLNodeList &children, BOOL use_default_if_missing = TRUE) const; + + // recursively finds all children at any level matching name + void getDescendants(const LLStringTableEntry* name, LLXMLNodeList &children) const; - bool getAttribute(const LLString& name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); + bool getAttribute(const char* name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); bool getAttribute(const LLStringTableEntry* name, LLXMLNodePtr& node, BOOL use_default_if_missing = TRUE); + S32 getLineNumber(); + // The following skip over attributes - LLXMLNodePtr getFirstChild(); - LLXMLNodePtr getNextSibling(); + LLXMLNodePtr getFirstChild() const; + LLXMLNodePtr getNextSibling() const; LLXMLNodePtr getRoot(); // Setters - bool setAttributeString(const LLString& attr, const LLString& value); + bool setAttributeString(const char* attr, const std::string& value); void setBoolValue(const BOOL value) { setBoolValue(1, &value); } void setByteValue(const U8 value, Encoding encoding = ENCODING_DEFAULT) { setByteValue(1, &value, encoding); } @@ -232,7 +252,7 @@ public: void setLongValue(const U64 value, Encoding encoding = ENCODING_DEFAULT) { setLongValue(1, &value, encoding); } void setFloatValue(const F32 value, Encoding encoding = ENCODING_DEFAULT, U32 precision = 0) { setFloatValue(1, &value, encoding); } void setDoubleValue(const F64 value, Encoding encoding = ENCODING_DEFAULT, U32 precision = 0) { setDoubleValue(1, &value, encoding); } - void setStringValue(const LLString value) { setStringValue(1, &value); } + void setStringValue(const std::string& value) { setStringValue(1, &value); } void setUUIDValue(const LLUUID value) { setUUIDValue(1, &value); } void setNodeRefValue(const LLXMLNode *value) { setNodeRefValue(1, &value); } @@ -243,16 +263,17 @@ public: void setLongValue(U32 length, const U64 *array, Encoding encoding = ENCODING_DEFAULT); void setFloatValue(U32 length, const F32 *array, Encoding encoding = ENCODING_DEFAULT, U32 precision = 0); void setDoubleValue(U32 length, const F64 *array, Encoding encoding = ENCODING_DEFAULT, U32 precision = 0); - void setStringValue(U32 length, const LLString *array); + void setStringValue(U32 length, const std::string *array); void setUUIDValue(U32 length, const LLUUID *array); void setNodeRefValue(U32 length, const LLXMLNode **array); - void setValue(const LLString& value); - void setName(const LLString& name); + void setValue(const std::string& value); + void setName(const std::string& name); void setName(LLStringTableEntry* name); + void setLineNumber(S32 line_number); + // Escapes " (quot) ' (apos) & (amp) < (lt) > (gt) - // TomY TODO: Make this private - static LLString escapeXML(const LLString& xml); + static std::string escapeXML(const std::string& xml); // Set the default node corresponding to this default node void setDefault(LLXMLNode *default_node); @@ -265,20 +286,20 @@ public: // Delete any child nodes that aren't among the tree's children, recursive void scrubToTree(LLXMLNode *tree); - BOOL deleteChildren(const LLString& name); + BOOL deleteChildren(const std::string& name); BOOL deleteChildren(LLStringTableEntry* name); void setAttributes(ValueType type, U32 precision, Encoding encoding, U32 length); - void appendValue(const LLString& value); +// void appendValue(const std::string& value); // Unused // Unit Testing void createUnitTest(S32 max_num_children); - BOOL performUnitTest(LLString &error_buffer); + BOOL performUnitTest(std::string &error_buffer); protected: BOOL removeChild(LLXMLNode* child); public: - LLString mID; // The ID attribute of this node + std::string mID; // The ID attribute of this node XML_Parser *mParser; // Temporary pointer while loading @@ -289,9 +310,10 @@ public: U32 mPrecision; // The number of BITS per array item ValueType mType; // The value type Encoding mEncoding; // The value encoding + S32 mLineNumber; // line number in source file, if applicable LLXMLNode* mParent; // The parent node - LLXMLChildren* mChildren; // The child nodes + LLXMLChildrenPtr mChildren; // The child nodes LLXMLAttribList mAttributes; // The attribute nodes LLXMLNodePtr mPrev; // Double-linked list previous node LLXMLNodePtr mNext; // Double-linked list next node @@ -301,7 +323,11 @@ public: protected: LLStringTableEntry *mName; // The name of this node - LLString mValue; // The value of this node (use getters/setters only) + + // The value of this node (use getters/setters only) + // Values are not XML-escaped in memory + // They may contain " (quot) ' (apos) & (amp) < (lt) > (gt) + std::string mValue; LLXMLNodePtr mDefault; // Mirror node in the default tree |
