Skip to content

Commit b60344d

Browse files
committed
committed latest 1.3 snapshot
1 parent b7a945d commit b60344d

18 files changed

+483
-22
lines changed

XML/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile
33
#
4-
# $Id: //poco/Main/XML/Makefile#11 $
4+
# $Id: //poco/Main/XML/Makefile#12 $
55
#
66
# Makefile for Poco XML
77
#
@@ -22,7 +22,7 @@ objects = AbstractContainerNode AbstractNode Attr AttrMap Attributes \
2222
NamespaceSupport Node NodeFilter NodeIterator NodeList Notation \
2323
ParserEngine ProcessingInstruction SAXException SAXParser Text \
2424
TreeWalker WhitespaceFilter XMLException XMLFilter XMLFilterImpl XMLReader \
25-
XMLString XMLWriter xmlparse xmlrole xmltok
25+
XMLString XMLWriter NodeAppender xmlparse xmlrole xmltok
2626

2727
target = PocoXML
2828
target_version = $(LIBVERSION)

XML/XML_vs71.vcproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@
538538
<File
539539
RelativePath=".\include\Poco\DOM\Node.h">
540540
</File>
541+
<File
542+
RelativePath=".\include\Poco\Dom\NodeAppender.h">
543+
</File>
541544
<File
542545
RelativePath=".\include\Poco\DOM\NodeFilter.h">
543546
</File>
@@ -659,6 +662,9 @@
659662
<File
660663
RelativePath=".\src\Node.cpp">
661664
</File>
665+
<File
666+
RelativePath=".\src\NodeAppender.cpp">
667+
</File>
662668
<File
663669
RelativePath=".\src\NodeFilter.cpp">
664670
</File>

XML/XML_vs80.vcproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="Windows-1252"?>
22
<VisualStudioProject
33
ProjectType="Visual C++"
4-
Version="8,00"
4+
Version="8.00"
55
Name="XML"
66
ProjectGUID="{9E211743-85FE-4977-82F3-4F04B40C912D}"
77
>
@@ -735,6 +735,10 @@
735735
RelativePath=".\include\Poco\DOM\Node.h"
736736
>
737737
</File>
738+
<File
739+
RelativePath=".\include\Poco\DOM\NodeAppender.h"
740+
>
741+
</File>
738742
<File
739743
RelativePath=".\include\Poco\Dom\NodeFilter.h"
740744
>
@@ -895,6 +899,10 @@
895899
RelativePath=".\src\Node.cpp"
896900
>
897901
</File>
902+
<File
903+
RelativePath=".\src\NodeAppender.cpp"
904+
>
905+
</File>
898906
<File
899907
RelativePath=".\src\NodeFilter.cpp"
900908
>

XML/include/Poco/DOM/AbstractContainerNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// AbstractContainerNode.h
33
//
4-
// $Id: //poco/Main/XML/include/Poco/DOM/AbstractContainerNode.h#2 $
4+
// $Id: //poco/Main/XML/include/Poco/DOM/AbstractContainerNode.h#3 $
55
//
66
// Library: XML
77
// Package: DOM
@@ -77,6 +77,7 @@ class XML_API AbstractContainerNode: public AbstractNode
7777
AbstractNode* _pFirstChild;
7878

7979
friend class AbstractNode;
80+
friend class NodeAppender;
8081
};
8182

8283

XML/include/Poco/DOM/AbstractNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// AbstractNode.h
33
//
4-
// $Id: //poco/Main/XML/include/Poco/DOM/AbstractNode.h#2 $
4+
// $Id: //poco/Main/XML/include/Poco/DOM/AbstractNode.h#3 $
55
//
66
// Library: XML
77
// Package: DOM
@@ -135,6 +135,7 @@ class XML_API AbstractNode: public Node
135135
friend class Attr;
136136
friend class CharacterData;
137137
friend class DOMBuilder;
138+
friend class NodeAppender;
138139
};
139140

140141

XML/include/Poco/DOM/DOMWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DOMWriter.h
33
//
4-
// $Id: //poco/Main/XML/include/Poco/DOM/DOMWriter.h#3 $
4+
// $Id: //poco/Main/XML/include/Poco/DOM/DOMWriter.h#4 $
55
//
66
// Library: XML
77
// Package: DOM
@@ -94,7 +94,7 @@ class XML_API DOMWriter
9494

9595
void writeNode(const std::string& systemId, const Node* pNode);
9696
/// Writes the XML for the given node to the file specified in systemId,
97-
/// using a standard file output stream (std::ofstream).
97+
/// using a standard file output stream (Poco::FileOutputStream).
9898

9999
private:
100100
std::string _encodingName;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// NodeAppender.h
3+
//
4+
// $Id: //poco/Main/XML/include/Poco/DOM/NodeAppender.h#1 $
5+
//
6+
// Library: XML
7+
// Package: DOM
8+
// Module: NodeAppender
9+
//
10+
// Definition of the NodeAppender class.
11+
//
12+
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
13+
// and Contributors.
14+
//
15+
// Permission is hereby granted, free of charge, to any person or organization
16+
// obtaining a copy of the software and accompanying documentation covered by
17+
// this license (the "Software") to use, reproduce, display, distribute,
18+
// execute, and transmit the Software, and to prepare derivative works of the
19+
// Software, and to permit third-parties to whom the Software is furnished to
20+
// do so, all subject to the following:
21+
//
22+
// The copyright notices in the Software and this entire statement, including
23+
// the above license grant, this restriction and the following disclaimer,
24+
// must be included in all copies of the Software, in whole or in part, and
25+
// all derivative works of the Software, unless such copies or derivative
26+
// works are solely in the form of machine-executable object code generated by
27+
// a source language processor.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32+
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33+
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35+
// DEALINGS IN THE SOFTWARE.
36+
//
37+
38+
39+
#ifndef DOM_NodeAppender_INCLUDED
40+
#define DOM_NodeAppender_INCLUDED
41+
42+
43+
#include "Poco/XML/XML.h"
44+
#include "Poco/DOM/Node.h"
45+
46+
47+
namespace Poco {
48+
namespace XML {
49+
50+
51+
class AbstractNode;
52+
class Element;
53+
54+
55+
class XML_API NodeAppender
56+
/// The NodeAppender class provides a very fast way to
57+
/// build larger DOM documents.
58+
///
59+
/// In the DOM, child nodes are usually appended to a parent
60+
/// node using the appendChild() method. For nodes containing
61+
/// more than a few children, this method can be quite slow,
62+
/// due to the way it's implemented, and because of the
63+
/// requirements of the DOM specification.
64+
///
65+
/// While the NodeAppender is being used on an Element, no
66+
/// children-modifying methods of that Element must be used.
67+
///
68+
/// This class is not part of the DOM specification.
69+
{
70+
public:
71+
NodeAppender(Element* parent);
72+
/// Creates the NodeAppender for the given parent node,
73+
/// which must be an Element.
74+
75+
~NodeAppender();
76+
/// Destroys the NodeAppender.
77+
78+
void appendChild(Node* newChild);
79+
/// Appends the node newChild to the end of the list of children of
80+
/// the parent node specified in the constructor.
81+
/// If the newChild is already in the tree, it is first removed.
82+
///
83+
/// NewChild can be a DocumentFragment. In this case, all children
84+
/// of the fragment become children of the parent element.
85+
///
86+
/// In order to speed up the function, no DOM events
87+
/// are fired.
88+
89+
private:
90+
NodeAppender();
91+
NodeAppender(const NodeAppender&);
92+
NodeAppender& operator = (const NodeAppender&);
93+
94+
Element* _pParent;
95+
AbstractNode* _pLast;
96+
};
97+
98+
99+
} } // namespace Poco::XML
100+
101+
102+
#endif // #include "Poco/XML/XML.h"
103+

XML/include/Poco/SAX/EntityResolverImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// EntityResolverImpl.h
33
//
4-
// $Id: //poco/Main/XML/include/Poco/SAX/EntityResolverImpl.h#2 $
4+
// $Id: //poco/Main/XML/include/Poco/SAX/EntityResolverImpl.h#3 $
55
//
66
// Library: XML
77
// Package: SAX
@@ -58,7 +58,7 @@ class XML_API EntityResolverImpl: public EntityResolver
5858
/// for an InputSource.
5959
///
6060
/// If the system ID is not a valid URI, it is
61-
/// interpreted as a filesystem path and a ifstream
61+
/// interpreted as a filesystem path and a Poco::FileInputStream
6262
/// is opened for it.
6363
{
6464
public:
@@ -78,7 +78,7 @@ class XML_API EntityResolverImpl: public EntityResolver
7878
/// for the given systemId, which is interpreted as an URI.
7979
///
8080
/// If the systemId is not a valid URI, it is interpreted as
81-
/// a local filesystem path and an ifstream is opened for it.
81+
/// a local filesystem path and a Poco::FileInputStream is opened for it.
8282

8383
void releaseInputSource(InputSource* pSource);
8484
/// Deletes the InputSource's stream.

XML/src/DOMWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DOMWriter.cpp
33
//
4-
// $Id: //poco/Main/XML/src/DOMWriter.cpp#13 $
4+
// $Id: //poco/Main/XML/src/DOMWriter.cpp#14 $
55
//
66
// Library: XML
77
// Package: DOM
@@ -45,7 +45,7 @@
4545
#include "Poco/SAX/LexicalHandler.h"
4646
#include "Poco/XML/XMLException.h"
4747
#include "Poco/Path.h"
48-
#include <fstream>
48+
#include "Poco/FileStream.h"
4949

5050

5151
namespace Poco {
@@ -104,7 +104,7 @@ void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode)
104104

105105
void DOMWriter::writeNode(const std::string& systemId, const Node* pNode)
106106
{
107-
std::ofstream ostr(Poco::Path::transcode(systemId).c_str());
107+
Poco::FileOutputStream ostr(systemId);
108108
if (ostr.good())
109109
writeNode(ostr, pNode);
110110
else

XML/src/NodeAppender.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//
2+
// NodeAppender.cpp
3+
//
4+
// $Id: //poco/Main/XML/src/NodeAppender.cpp#1 $
5+
//
6+
// Library: XML
7+
// Package: DOM
8+
// Module: NodeAppender
9+
//
10+
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
11+
// and Contributors.
12+
//
13+
// Permission is hereby granted, free of charge, to any person or organization
14+
// obtaining a copy of the software and accompanying documentation covered by
15+
// this license (the "Software") to use, reproduce, display, distribute,
16+
// execute, and transmit the Software, and to prepare derivative works of the
17+
// Software, and to permit third-parties to whom the Software is furnished to
18+
// do so, all subject to the following:
19+
//
20+
// The copyright notices in the Software and this entire statement, including
21+
// the above license grant, this restriction and the following disclaimer,
22+
// must be included in all copies of the Software, in whole or in part, and
23+
// all derivative works of the Software, unless such copies or derivative
24+
// works are solely in the form of machine-executable object code generated by
25+
// a source language processor.
26+
//
27+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30+
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31+
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33+
// DEALINGS IN THE SOFTWARE.
34+
//
35+
36+
37+
#include "Poco/DOM/NodeAppender.h"
38+
#include "Poco/DOM/Element.h"
39+
#include "Poco/DOM/DOMException.h"
40+
41+
42+
namespace Poco {
43+
namespace XML {
44+
45+
46+
NodeAppender::NodeAppender(Element* parent):
47+
_pParent(parent),
48+
_pLast(0)
49+
{
50+
poco_check_ptr (parent);
51+
52+
_pLast = static_cast<AbstractNode*>(_pParent->lastChild());
53+
}
54+
55+
56+
NodeAppender::~NodeAppender()
57+
{
58+
}
59+
60+
61+
void NodeAppender::appendChild(Node* newChild)
62+
{
63+
poco_check_ptr (newChild);
64+
poco_assert (_pLast == 0 || _pLast->_pNext == 0);
65+
66+
if (static_cast<AbstractNode*>(newChild)->_pOwner != _pParent->_pOwner)
67+
throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
68+
69+
if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)
70+
{
71+
AbstractContainerNode* pFrag = static_cast<AbstractContainerNode*>(newChild);
72+
AbstractNode* pChild = pFrag->_pFirstChild;
73+
if (pChild)
74+
{
75+
if (_pLast)
76+
_pLast->_pNext = pChild;
77+
else
78+
_pParent->_pFirstChild = pChild;
79+
while (pChild)
80+
{
81+
_pLast = pChild;
82+
pChild->_pParent = _pParent;
83+
pChild = pChild->_pNext;
84+
}
85+
pFrag->_pFirstChild = 0;
86+
}
87+
}
88+
else
89+
{
90+
AbstractNode* pAN = static_cast<AbstractNode*>(newChild);
91+
pAN->duplicate();
92+
if (pAN->_pParent)
93+
pAN->_pParent->removeChild(pAN);
94+
pAN->_pParent = _pParent;
95+
if (_pLast)
96+
_pLast->_pNext = pAN;
97+
else
98+
_pParent->_pFirstChild = pAN;
99+
_pLast = pAN;
100+
}
101+
}
102+
103+
104+
} } // namespace Poco::XML

0 commit comments

Comments
 (0)