aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llxml/llxmltree.cpp
diff options
context:
space:
mode:
authorMcCabe Maxsted2010-07-07 11:40:20 -0700
committerMcCabe Maxsted2010-07-07 11:40:20 -0700
commit35eaded540f31378845b7a88e212a86a68825040 (patch)
tree05a91e33fe0de6afa555afa2c350b889e770bbcb /linden/indra/llxml/llxmltree.cpp
parentCleaned up the grid manager layout some (diff)
downloadmeta-impy-35eaded540f31378845b7a88e212a86a68825040.zip
meta-impy-35eaded540f31378845b7a88e212a86a68825040.tar.gz
meta-impy-35eaded540f31378845b7a88e212a86a68825040.tar.bz2
meta-impy-35eaded540f31378845b7a88e212a86a68825040.tar.xz
Updated hipporestrequest code to hippo 0.6.3
Diffstat (limited to 'linden/indra/llxml/llxmltree.cpp')
-rw-r--r--linden/indra/llxml/llxmltree.cpp119
1 files changed, 117 insertions, 2 deletions
diff --git a/linden/indra/llxml/llxmltree.cpp b/linden/indra/llxml/llxmltree.cpp
index 1bce5d2..aa34f79 100644
--- a/linden/indra/llxml/llxmltree.cpp
+++ b/linden/indra/llxml/llxmltree.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2002&license=viewergpl$ 5 * $LicenseInfo:firstyear=2002&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2002-2009, Linden Research, Inc. 7 * Copyright (c) 2002-2010, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -50,6 +50,7 @@ LLStdStringTable LLXmlTree::sAttributeKeys(1024);
50 50
51LLXmlTree::LLXmlTree() 51LLXmlTree::LLXmlTree()
52 : mRoot( NULL ), 52 : mRoot( NULL ),
53 mParser(0),
53 mNodeNames(512) 54 mNodeNames(512)
54{ 55{
55} 56}
@@ -83,6 +84,39 @@ BOOL LLXmlTree::parseFile(const std::string &path, BOOL keep_contents)
83 return success; 84 return success;
84} 85}
85 86
87bool LLXmlTree::parseBufferStart(bool keep_contents)
88{
89 if (mRoot) delete mRoot;
90 mRoot = NULL;
91
92 if (mParser) delete mParser;
93 mParser = new LLXmlTreeParser(this);
94 mParser->parseBufferStart(keep_contents);
95 return (mParser != 0);
96}
97
98bool LLXmlTree::parseBuffer(const char *buf, int len)
99{
100 bool success = mParser->parseBuffer(buf, len);
101 if (!success) {
102 S32 line_number = mParser->getCurrentLineNumber();
103 const char* error = mParser->getErrorString();
104 llwarns << "LLXmlTree parse failed in line " << line_number << ": " << error << llendl;
105 delete mParser;
106 mParser = 0;
107 }
108 return success;
109}
110
111bool LLXmlTree::parseBufferFinalize()
112{
113 bool success = mParser->parseBufferFinalize(&mRoot);
114 delete mParser;
115 mParser = 0;
116 return success;
117}
118
119
86void LLXmlTree::dump() 120void LLXmlTree::dump()
87{ 121{
88 if( mRoot ) 122 if( mRoot )
@@ -102,6 +136,25 @@ void LLXmlTree::dumpNode( LLXmlTreeNode* node, const std::string& prefix )
102 } 136 }
103} 137}
104 138
139void LLXmlTree::write(std::string &buffer) const
140{
141 if (mRoot) writeNode(mRoot, buffer, "");
142}
143
144void LLXmlTree::writeNode(LLXmlTreeNode *node, std::string &buffer, const std::string &indent) const
145{
146 if (!node->getFirstChild()) {
147 node->writeNoChild(buffer, indent);
148 } else {
149 node->writeStart(buffer, indent);
150 std::string newIndent = indent + " ";
151 for (LLXmlTreeNode *child=node->getFirstChild(); child; child=node->getNextChild())
152 writeNode(child, buffer, newIndent);
153 node->writeEnd(buffer, indent);
154 }
155}
156
157
105////////////////////////////////////////////////////////////// 158//////////////////////////////////////////////////////////////
106// LLXmlTreeNode 159// LLXmlTreeNode
107 160
@@ -139,6 +192,43 @@ void LLXmlTreeNode::dump( const std::string& prefix )
139 llcont << llendl; 192 llcont << llendl;
140} 193}
141 194
195void LLXmlTreeNode::writeNoChild(std::string &buffer, const std::string &indent) const
196{
197 if (!mContents.empty()) {
198 writeStart(buffer, indent);
199 writeEnd(buffer, indent);
200 } else {
201 buffer += indent + '<' + mName;
202 writeAttributes(buffer);
203 buffer += "/>\n";
204 }
205}
206
207void LLXmlTreeNode::writeStart(std::string &buffer, const std::string &indent) const
208{
209 buffer += indent + '<' + mName;
210 writeAttributes(buffer);
211 buffer += ">\n";
212}
213
214void LLXmlTreeNode::writeEnd(std::string &buffer, const std::string &indent) const
215{
216 if (!mContents.empty()) {
217 buffer += indent + " " + mContents + '\n';
218 }
219 buffer += indent + "</" + mName + ">\n";
220}
221
222void LLXmlTreeNode::writeAttributes(std::string &buffer) const
223{
224 attribute_map_t::const_iterator it, end = mAttributes.end();
225 for (it=mAttributes.begin(); it!=end; ++it) {
226 LLStdStringHandle key = it->first;
227 const std::string *value = it->second;
228 buffer += ' ' + *key + "=\"" + *value + '"';
229 }
230}
231
142BOOL LLXmlTreeNode::hasAttribute(const std::string& name) 232BOOL LLXmlTreeNode::hasAttribute(const std::string& name)
143{ 233{
144 LLStdStringHandle canonical_name = LLXmlTree::sAttributeKeys.addString( name ); 234 LLStdStringHandle canonical_name = LLXmlTree::sAttributeKeys.addString( name );
@@ -527,7 +617,7 @@ BOOL LLXmlTreeParser::parseFile(const std::string &path, LLXmlTreeNode** root, B
527 617
528 BOOL success = LLXmlParser::parseFile(path); 618 BOOL success = LLXmlParser::parseFile(path);
529 619
530 *root = mRoot; 620 if (root) *root = mRoot;
531 mRoot = NULL; 621 mRoot = NULL;
532 622
533 if( success ) 623 if( success )
@@ -539,6 +629,31 @@ BOOL LLXmlTreeParser::parseFile(const std::string &path, LLXmlTreeNode** root, B
539 return success; 629 return success;
540} 630}
541 631
632void LLXmlTreeParser::parseBufferStart(BOOL keep_contents)
633{
634 llassert(!mRoot);
635 llassert(!mCurrent);
636 mKeepContents = keep_contents;
637}
638
639bool LLXmlTreeParser::parseBuffer(const char *buf, int len)
640{
641 return (LLXmlParser::parse(buf, len, false) != 0);
642}
643
644bool LLXmlTreeParser::parseBufferFinalize(LLXmlTreeNode** root)
645{
646 bool success = (LLXmlParser::parse(0, 0, true) != 0);
647
648 if (root) *root = mRoot;
649 mRoot = NULL;
650
651 llassert(!success || !mCurrent);
652 mCurrent = NULL;
653
654 return success;
655}
656
542 657
543const std::string& LLXmlTreeParser::tabs() 658const std::string& LLXmlTreeParser::tabs()
544{ 659{