From 04d7f61c1b07fcd61ec1f7c76d9305f6bf055f6f Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Fri, 19 Sep 2008 13:46:05 +0000 Subject: [PATCH] fixed line endings --- XML/.cdtproject | 126 +- XML/.project | 172 +- XML/XML.vmsbuild | 152 +- XML/XML_vs71.sln | 84 +- XML/XML_vs71.vcproj | 1616 +- XML/XML_vs80.sln | 76 +- XML/XML_vs80.vcproj | 2174 +-- XML/include/Poco/DOM/AbstractContainerNode.h | 174 +- XML/include/Poco/DOM/AbstractNode.h | 290 +- XML/include/Poco/DOM/Attr.h | 404 +- XML/include/Poco/DOM/AttrMap.h | 174 +- XML/include/Poco/DOM/AutoPtr.h | 114 +- XML/include/Poco/DOM/CDATASection.h | 212 +- XML/include/Poco/DOM/CharacterData.h | 290 +- XML/include/Poco/DOM/ChildNodesList.h | 154 +- XML/include/Poco/DOM/Comment.h | 160 +- XML/include/Poco/DOM/DOMBuilder.h | 268 +- XML/include/Poco/DOM/DOMException.h | 268 +- XML/include/Poco/DOM/DOMImplementation.h | 208 +- XML/include/Poco/DOM/DOMObject.h | 250 +- XML/include/Poco/DOM/DOMParser.h | 258 +- XML/include/Poco/DOM/DOMSerializer.h | 288 +- XML/include/Poco/DOM/DOMWriter.h | 262 +- XML/include/Poco/DOM/DTDMap.h | 178 +- XML/include/Poco/DOM/Document.h | 598 +- XML/include/Poco/DOM/DocumentEvent.h | 174 +- XML/include/Poco/DOM/DocumentFragment.h | 212 +- XML/include/Poco/DOM/DocumentType.h | 294 +- XML/include/Poco/DOM/Element.h | 486 +- XML/include/Poco/DOM/ElementsByTagNameList.h | 212 +- XML/include/Poco/DOM/Entity.h | 296 +- XML/include/Poco/DOM/EntityReference.h | 190 +- XML/include/Poco/DOM/Event.h | 462 +- XML/include/Poco/DOM/EventDispatcher.h | 238 +- XML/include/Poco/DOM/EventException.h | 206 +- XML/include/Poco/DOM/EventListener.h | 158 +- XML/include/Poco/DOM/EventTarget.h | 196 +- XML/include/Poco/DOM/MutationEvent.h | 330 +- XML/include/Poco/DOM/NamedNodeMap.h | 230 +- XML/include/Poco/DOM/Node.h | 510 +- XML/include/Poco/DOM/NodeAppender.h | 206 +- XML/include/Poco/DOM/NodeFilter.h | 336 +- XML/include/Poco/DOM/NodeIterator.h | 378 +- XML/include/Poco/DOM/NodeList.h | 166 +- XML/include/Poco/DOM/Notation.h | 230 +- XML/include/Poco/DOM/ProcessingInstruction.h | 242 +- XML/include/Poco/DOM/Text.h | 202 +- XML/include/Poco/DOM/TreeWalker.h | 466 +- XML/include/Poco/SAX/Attributes.h | 284 +- XML/include/Poco/SAX/AttributesImpl.h | 636 +- XML/include/Poco/SAX/ContentHandler.h | 524 +- XML/include/Poco/SAX/DTDHandler.h | 216 +- XML/include/Poco/SAX/DeclHandler.h | 226 +- XML/include/Poco/SAX/DefaultHandler.h | 210 +- XML/include/Poco/SAX/EntityResolver.h | 216 +- XML/include/Poco/SAX/EntityResolverImpl.h | 200 +- XML/include/Poco/SAX/ErrorHandler.h | 228 +- XML/include/Poco/SAX/InputSource.h | 382 +- XML/include/Poco/SAX/LexicalHandler.h | 294 +- XML/include/Poco/SAX/Locator.h | 250 +- XML/include/Poco/SAX/LocatorImpl.h | 220 +- XML/include/Poco/SAX/NamespaceSupport.h | 434 +- XML/include/Poco/SAX/SAXException.h | 396 +- XML/include/Poco/SAX/SAXParser.h | 238 +- XML/include/Poco/SAX/WhitespaceFilter.h | 206 +- XML/include/Poco/SAX/XMLFilter.h | 166 +- XML/include/Poco/SAX/XMLFilterImpl.h | 308 +- XML/include/Poco/SAX/XMLReader.h | 454 +- XML/include/Poco/XML/Name.h | 320 +- XML/include/Poco/XML/NamePool.h | 192 +- XML/include/Poco/XML/NamespaceStrategy.h | 274 +- XML/include/Poco/XML/ParserEngine.h | 686 +- XML/include/Poco/XML/XML.h | 184 +- XML/include/Poco/XML/XMLException.h | 118 +- XML/include/Poco/XML/XMLStream.h | 186 +- XML/include/Poco/XML/XMLWriter.h | 662 +- XML/include/Poco/XML/expat.h | 2028 +-- XML/include/Poco/XML/expat_external.h | 230 +- XML/samples/DOMParser/DOMParser.vmsbuild | 16 +- XML/samples/DOMParser/DOMParser_vs71.vcproj | 298 +- XML/samples/DOMParser/DOMParser_vs80.vcproj | 426 +- XML/samples/DOMParser/src/DOMParser.cpp | 162 +- XML/samples/DOMWriter/DOMWriter.vmsbuild | 16 +- XML/samples/DOMWriter/DOMWriter_vs71.vcproj | 298 +- XML/samples/DOMWriter/DOMWriter_vs80.vcproj | 426 +- XML/samples/DOMWriter/src/DOMWriter.cpp | 156 +- XML/samples/PrettyPrint/PrettyPrint.vmsbuild | 16 +- .../PrettyPrint/PrettyPrint_vs71.vcproj | 298 +- .../PrettyPrint/PrettyPrint_vs80.vcproj | 426 +- XML/samples/PrettyPrint/src/PrettyPrint.cpp | 156 +- XML/samples/SAXParser/SAXParser.vmsbuild | 16 +- XML/samples/SAXParser/SAXParser_vs71.vcproj | 298 +- XML/samples/SAXParser/SAXParser_vs80.vcproj | 426 +- XML/samples/SAXParser/src/SAXParser.cpp | 430 +- XML/samples/data/sample.xml | 44 +- XML/samples/samples_vs71.sln | 90 +- XML/samples/samples_vs80.sln | 74 +- XML/src/AbstractContainerNode.cpp | 650 +- XML/src/AbstractNode.cpp | 754 +- XML/src/Attr.cpp | 310 +- XML/src/AttrMap.cpp | 290 +- XML/src/Attributes.cpp | 98 +- XML/src/CDATASection.cpp | 192 +- XML/src/CharacterData.cpp | 282 +- XML/src/ChildNodesList.cpp | 184 +- XML/src/Comment.cpp | 164 +- XML/src/ContentHandler.cpp | 98 +- XML/src/DOMBuilder.cpp | 668 +- XML/src/DOMException.cpp | 258 +- XML/src/DOMImplementation.cpp | 206 +- XML/src/DOMObject.cpp | 108 +- XML/src/DOMParser.cpp | 340 +- XML/src/DOMSerializer.cpp | 690 +- XML/src/DOMWriter.cpp | 232 +- XML/src/DTDHandler.cpp | 98 +- XML/src/DTDMap.cpp | 278 +- XML/src/DeclHandler.cpp | 98 +- XML/src/DefaultHandler.cpp | 290 +- XML/src/Document.cpp | 650 +- XML/src/DocumentEvent.cpp | 98 +- XML/src/DocumentFragment.cpp | 184 +- XML/src/DocumentType.cpp | 212 +- XML/src/Element.cpp | 932 +- XML/src/ElementsByTagNameList.cpp | 342 +- XML/src/Entity.cpp | 180 +- XML/src/EntityReference.cpp | 162 +- XML/src/EntityResolver.cpp | 98 +- XML/src/EntityResolverImpl.cpp | 200 +- XML/src/ErrorHandler.cpp | 98 +- XML/src/Event.cpp | 248 +- XML/src/EventDispatcher.cpp | 336 +- XML/src/EventException.cpp | 174 +- XML/src/EventListener.cpp | 98 +- XML/src/EventTarget.cpp | 98 +- XML/src/InputSource.cpp | 204 +- XML/src/LexicalHandler.cpp | 98 +- XML/src/Locator.cpp | 98 +- XML/src/LocatorImpl.cpp | 252 +- XML/src/MutationEvent.cpp | 196 +- XML/src/Name.cpp | 384 +- XML/src/NamePool.cpp | 296 +- XML/src/NamedNodeMap.cpp | 98 +- XML/src/NamespaceSupport.cpp | 418 +- XML/src/Node.cpp | 98 +- XML/src/NodeAppender.cpp | 208 +- XML/src/NodeFilter.cpp | 98 +- XML/src/NodeIterator.cpp | 396 +- XML/src/NodeList.cpp | 98 +- XML/src/Notation.cpp | 170 +- XML/src/ProcessingInstruction.cpp | 202 +- XML/src/SAXException.cpp | 320 +- XML/src/SAXParser.cpp | 506 +- XML/src/Text.cpp | 204 +- XML/src/TreeWalker.cpp | 498 +- XML/src/WhitespaceFilter.cpp | 468 +- XML/src/XMLException.cpp | 102 +- XML/src/XMLFilter.cpp | 98 +- XML/src/XMLFilterImpl.cpp | 670 +- XML/src/XMLReader.cpp | 118 +- XML/src/XMLString.cpp | 172 +- XML/src/XMLWriter.cpp | 1632 +- XML/src/ascii.h | 184 +- XML/src/asciitab.h | 72 +- XML/src/expat_config.h | 118 +- XML/src/iasciitab.h | 74 +- XML/src/internal.h | 146 +- XML/src/latin1tab.h | 72 +- XML/src/nametab.h | 300 +- XML/src/utf8tab.h | 74 +- XML/src/xmlparse.cpp | 12574 ++++++++-------- XML/src/xmlrole.c | 2672 ++-- XML/src/xmlrole.h | 228 +- XML/src/xmltok.c | 3302 ++-- XML/src/xmltok.h | 632 +- XML/src/xmltok_impl.c | 3566 ++--- XML/src/xmltok_impl.h | 92 +- XML/src/xmltok_ns.c | 230 +- XML/testsuite/TestSuite.vmsbuild | 52 +- XML/testsuite/TestSuite_vs71.vcproj | 870 +- XML/testsuite/TestSuite_vs80.vcproj | 1196 +- XML/testsuite/src/AttributesImplTest.cpp | 532 +- XML/testsuite/src/AttributesImplTest.h | 126 +- XML/testsuite/src/ChildNodesTest.cpp | 248 +- XML/testsuite/src/ChildNodesTest.h | 120 +- XML/testsuite/src/DOMTestSuite.cpp | 128 +- XML/testsuite/src/DOMTestSuite.h | 98 +- XML/testsuite/src/DocumentTest.cpp | 620 +- XML/testsuite/src/DocumentTest.h | 132 +- XML/testsuite/src/DocumentTypeTest.cpp | 260 +- XML/testsuite/src/DocumentTypeTest.h | 120 +- XML/testsuite/src/Driver.cpp | 78 +- XML/testsuite/src/ElementTest.cpp | 1316 +- XML/testsuite/src/ElementTest.h | 136 +- XML/testsuite/src/EventTest.cpp | 1186 +- XML/testsuite/src/EventTest.h | 136 +- XML/testsuite/src/NamePoolTest.cpp | 188 +- XML/testsuite/src/NamePoolTest.h | 120 +- XML/testsuite/src/NameTest.cpp | 386 +- XML/testsuite/src/NameTest.h | 130 +- XML/testsuite/src/NamespaceSupportTest.cpp | 424 +- XML/testsuite/src/NamespaceSupportTest.h | 120 +- XML/testsuite/src/NodeAppenderTest.cpp | 324 +- XML/testsuite/src/NodeAppenderTest.h | 122 +- XML/testsuite/src/NodeIteratorTest.cpp | 420 +- XML/testsuite/src/NodeIteratorTest.h | 126 +- XML/testsuite/src/NodeTest.cpp | 2252 +-- XML/testsuite/src/NodeTest.h | 144 +- XML/testsuite/src/ParserWriterTest.cpp | 642 +- XML/testsuite/src/ParserWriterTest.h | 130 +- XML/testsuite/src/SAXParserTest.cpp | 2072 +-- XML/testsuite/src/SAXParserTest.h | 204 +- XML/testsuite/src/SAXTestSuite.cpp | 96 +- XML/testsuite/src/SAXTestSuite.h | 98 +- XML/testsuite/src/TextTest.cpp | 378 +- XML/testsuite/src/TextTest.h | 134 +- XML/testsuite/src/TreeWalkerTest.cpp | 658 +- XML/testsuite/src/TreeWalkerTest.h | 126 +- XML/testsuite/src/WinDriver.cpp | 100 +- XML/testsuite/src/XMLTestSuite.cpp | 104 +- XML/testsuite/src/XMLTestSuite.h | 98 +- XML/testsuite/src/XMLWriterTest.cpp | 1206 +- XML/testsuite/src/XMLWriterTest.h | 180 +- 222 files changed, 45791 insertions(+), 45791 deletions(-) diff --git a/XML/.cdtproject b/XML/.cdtproject index 144f6fe24..f349999f3 100644 --- a/XML/.cdtproject +++ b/XML/.cdtproject @@ -1,63 +1,63 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/.project b/XML/.project index 698d8feb7..c37b3d2b6 100644 --- a/XML/.project +++ b/XML/.project @@ -1,86 +1,86 @@ - - - XML - - - - - - org.eclipse.cdt.make.core.makeBuilder - clean,full,incremental, - - - org.eclipse.cdt.make.core.build.arguments - - - - org.eclipse.cdt.core.errorOutputParser - org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser; - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.environment - - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.build.target.inc - -s - - - org.eclipse.cdt.make.core.enabledIncrementalBuild - true - - - org.eclipse.cdt.make.core.build.location - - - - org.eclipse.cdt.make.core.build.target.clean - clean - - - org.eclipse.cdt.make.core.build.command - make - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - org.eclipse.cdt.make.core.build.target.auto - all - - - org.eclipse.cdt.make.core.stopOnError - true - - - - - org.eclipse.cdt.make.core.ScannerConfigBuilder - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.make.core.makeNature - org.eclipse.cdt.make.core.ScannerConfigNature - org.eclipse.cdt.core.ccnature - - + + + XML + + + + + + org.eclipse.cdt.make.core.makeBuilder + clean,full,incremental, + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser; + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.build.target.inc + -s + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.build.location + + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + + + org.eclipse.cdt.make.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.make.core.makeNature + org.eclipse.cdt.make.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + + diff --git a/XML/XML.vmsbuild b/XML/XML.vmsbuild index e29c1782f..f5cd1333e 100644 --- a/XML/XML.vmsbuild +++ b/XML/XML.vmsbuild @@ -1,76 +1,76 @@ -# -# XML.vmsbuild -# -# $Id: //poco/1.3/XML/XML.vmsbuild#1 $ -# -DEF=HAVE_EXPAT_CONFIG_H,XML_NS,XML_DTD -LIB=PocoXML -AbstractContainerNode -AbstractNode -Attr -AttrMap -Attributes -AttributesImpl -CDATASection -CharacterData -ChildNodesList -Comment -ContentHandler -DOMBuilder -DOMException -DOMImplementation -DOMObject -DOMParser -DOMSerializer -DOMWriter -DTDHandler -DTDMap -DeclHandler -DefaultHandler -Document -DocumentEvent -DocumentFragment -DocumentType -Element -ElementsByTagNameList -Entity -EntityReference -EntityResolver -EntityResolverImpl -ErrorHandler -Event -EventDispatcher -EventException -EventListener -EventTarget -InputSource -LexicalHandler -Locator -LocatorImpl -MutationEvent -Name -NamePool -NamedNodeMap -NamespaceStrategy -NamespaceSupport -Node -NodeFilter -NodeIterator -NodeList -Notation -ParserEngine -ProcessingInstruction -SAXException -SAXParser -Text -TreeWalker -WhitespaceFilter -XMLException -XMLFilter -XMLFilterImpl -XMLReader -XMLString -XMLWriter -xmlparse -xmlrole -xmltok +# +# XML.vmsbuild +# +# $Id: //poco/1.3/XML/XML.vmsbuild#1 $ +# +DEF=HAVE_EXPAT_CONFIG_H,XML_NS,XML_DTD +LIB=PocoXML +AbstractContainerNode +AbstractNode +Attr +AttrMap +Attributes +AttributesImpl +CDATASection +CharacterData +ChildNodesList +Comment +ContentHandler +DOMBuilder +DOMException +DOMImplementation +DOMObject +DOMParser +DOMSerializer +DOMWriter +DTDHandler +DTDMap +DeclHandler +DefaultHandler +Document +DocumentEvent +DocumentFragment +DocumentType +Element +ElementsByTagNameList +Entity +EntityReference +EntityResolver +EntityResolverImpl +ErrorHandler +Event +EventDispatcher +EventException +EventListener +EventTarget +InputSource +LexicalHandler +Locator +LocatorImpl +MutationEvent +Name +NamePool +NamedNodeMap +NamespaceStrategy +NamespaceSupport +Node +NodeFilter +NodeIterator +NodeList +Notation +ParserEngine +ProcessingInstruction +SAXException +SAXParser +Text +TreeWalker +WhitespaceFilter +XMLException +XMLFilter +XMLFilterImpl +XMLReader +XMLString +XMLWriter +xmlparse +xmlrole +xmltok diff --git a/XML/XML_vs71.sln b/XML/XML_vs71.sln index 86210e845..93725b299 100644 --- a/XML/XML_vs71.sln +++ b/XML/XML_vs71.sln @@ -1,42 +1,42 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XML", "XML_vs71.vcproj", "{9E211743-85FE-4977-82F3-4F04B40C912D}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs71.vcproj", "{C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}" - ProjectSection(ProjectDependencies) = postProject - {9E211743-85FE-4977-82F3-4F04B40C912D} = {9E211743-85FE-4977-82F3-4F04B40C912D} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - debug_shared = debug_shared - debug_static = debug_static - release_shared = release_shared - release_static = release_static - EndGlobalSection - GlobalSection(ProjectDependencies) = postSolution - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared.ActiveCfg = debug_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared.Build.0 = debug_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static.ActiveCfg = debug_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static.Build.0 = debug_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared.ActiveCfg = release_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared.Build.0 = release_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static.ActiveCfg = release_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static.Build.0 = release_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared.ActiveCfg = debug_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared.Build.0 = debug_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static.ActiveCfg = debug_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static.Build.0 = debug_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared.ActiveCfg = release_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared.Build.0 = release_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static.ActiveCfg = release_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static.Build.0 = release_static|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XML", "XML_vs71.vcproj", "{9E211743-85FE-4977-82F3-4F04B40C912D}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs71.vcproj", "{C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}" + ProjectSection(ProjectDependencies) = postProject + {9E211743-85FE-4977-82F3-4F04B40C912D} = {9E211743-85FE-4977-82F3-4F04B40C912D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + debug_shared = debug_shared + debug_static = debug_static + release_shared = release_shared + release_static = release_static + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared.ActiveCfg = debug_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared.Build.0 = debug_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static.ActiveCfg = debug_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static.Build.0 = debug_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared.ActiveCfg = release_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared.Build.0 = release_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static.ActiveCfg = release_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static.Build.0 = release_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared.ActiveCfg = debug_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared.Build.0 = debug_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static.ActiveCfg = debug_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static.Build.0 = debug_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared.ActiveCfg = release_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared.Build.0 = release_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static.ActiveCfg = release_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static.Build.0 = release_static|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/XML/XML_vs71.vcproj b/XML/XML_vs71.vcproj index c873b6fd4..b2354f7e8 100644 --- a/XML/XML_vs71.vcproj +++ b/XML/XML_vs71.vcproj @@ -1,808 +1,808 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/XML_vs80.sln b/XML/XML_vs80.sln index 2ef9841fc..04911ed0a 100644 --- a/XML/XML_vs80.sln +++ b/XML/XML_vs80.sln @@ -1,38 +1,38 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XML", "XML_vs80.vcproj", "{9E211743-85FE-4977-82F3-4F04B40C912D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs80.vcproj", "{C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}" - ProjectSection(ProjectDependencies) = postProject - {9E211743-85FE-4977-82F3-4F04B40C912D} = {9E211743-85FE-4977-82F3-4F04B40C912D} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - debug_shared|Win32 = debug_shared|Win32 - debug_static|Win32 = debug_static|Win32 - release_shared|Win32 = release_shared|Win32 - release_static|Win32 = release_static|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static|Win32.ActiveCfg = debug_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static|Win32.Build.0 = debug_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared|Win32.Build.0 = release_shared|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static|Win32.ActiveCfg = release_static|Win32 - {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static|Win32.Build.0 = release_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static|Win32.ActiveCfg = debug_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static|Win32.Build.0 = debug_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared|Win32.Build.0 = release_shared|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static|Win32.ActiveCfg = release_static|Win32 - {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static|Win32.Build.0 = release_static|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XML", "XML_vs80.vcproj", "{9E211743-85FE-4977-82F3-4F04B40C912D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs80.vcproj", "{C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}" + ProjectSection(ProjectDependencies) = postProject + {9E211743-85FE-4977-82F3-4F04B40C912D} = {9E211743-85FE-4977-82F3-4F04B40C912D} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + debug_shared|Win32 = debug_shared|Win32 + debug_static|Win32 = debug_static|Win32 + release_shared|Win32 = release_shared|Win32 + release_static|Win32 = release_static|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static|Win32.ActiveCfg = debug_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.debug_static|Win32.Build.0 = debug_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_shared|Win32.Build.0 = release_shared|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static|Win32.ActiveCfg = release_static|Win32 + {9E211743-85FE-4977-82F3-4F04B40C912D}.release_static|Win32.Build.0 = release_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static|Win32.ActiveCfg = debug_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.debug_static|Win32.Build.0 = debug_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_shared|Win32.Build.0 = release_shared|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static|Win32.ActiveCfg = release_static|Win32 + {C9ACF028-17A1-44C2-8C09-DFD3BD9E7D45}.release_static|Win32.Build.0 = release_static|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/XML/XML_vs80.vcproj b/XML/XML_vs80.vcproj index 52aa5d65d..926c8f021 100644 --- a/XML/XML_vs80.vcproj +++ b/XML/XML_vs80.vcproj @@ -1,1087 +1,1087 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/include/Poco/DOM/AbstractContainerNode.h b/XML/include/Poco/DOM/AbstractContainerNode.h index 45c22c191..f7db74c60 100644 --- a/XML/include/Poco/DOM/AbstractContainerNode.h +++ b/XML/include/Poco/DOM/AbstractContainerNode.h @@ -1,87 +1,87 @@ -// -// AbstractContainerNode.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/AbstractContainerNode.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the AbstractContainerNode class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_AbstractContainerNode_INCLUDED -#define DOM_AbstractContainerNode_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" - - -namespace Poco { -namespace XML { - - -class XML_API AbstractContainerNode: public AbstractNode - /// AbstractContainerNode is an implementation of Node - /// that stores and manages child nodes. - /// - /// Child nodes are organized in a single linked list. -{ -public: - // Node - Node* firstChild() const; - Node* lastChild() const; - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - bool hasChildNodes() const; - bool hasAttributes() const; - -protected: - AbstractContainerNode(Document* pOwnerDocument); - AbstractContainerNode(Document* pOwnerDocument, const AbstractContainerNode& node); - ~AbstractContainerNode(); - - void dispatchNodeRemovedFromDocument(); - void dispatchNodeInsertedIntoDocument(); - -private: - AbstractNode* _pFirstChild; - - friend class AbstractNode; - friend class NodeAppender; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_AbstractContainerNode_INCLUDED +// +// AbstractContainerNode.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/AbstractContainerNode.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the AbstractContainerNode class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_AbstractContainerNode_INCLUDED +#define DOM_AbstractContainerNode_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" + + +namespace Poco { +namespace XML { + + +class XML_API AbstractContainerNode: public AbstractNode + /// AbstractContainerNode is an implementation of Node + /// that stores and manages child nodes. + /// + /// Child nodes are organized in a single linked list. +{ +public: + // Node + Node* firstChild() const; + Node* lastChild() const; + Node* insertBefore(Node* newChild, Node* refChild); + Node* replaceChild(Node* newChild, Node* oldChild); + Node* removeChild(Node* oldChild); + Node* appendChild(Node* newChild); + bool hasChildNodes() const; + bool hasAttributes() const; + +protected: + AbstractContainerNode(Document* pOwnerDocument); + AbstractContainerNode(Document* pOwnerDocument, const AbstractContainerNode& node); + ~AbstractContainerNode(); + + void dispatchNodeRemovedFromDocument(); + void dispatchNodeInsertedIntoDocument(); + +private: + AbstractNode* _pFirstChild; + + friend class AbstractNode; + friend class NodeAppender; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_AbstractContainerNode_INCLUDED diff --git a/XML/include/Poco/DOM/AbstractNode.h b/XML/include/Poco/DOM/AbstractNode.h index 16cd8b9bc..96e66e0da 100644 --- a/XML/include/Poco/DOM/AbstractNode.h +++ b/XML/include/Poco/DOM/AbstractNode.h @@ -1,145 +1,145 @@ -// -// AbstractNode.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/AbstractNode.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the AbstractNode class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_AbstractNode_INCLUDED -#define DOM_AbstractNode_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/Node.h" -#include "Poco/DOM/MutationEvent.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class AbstractContainerNode; -class Attr; -class EventDispatcher; - - -class XML_API AbstractNode: public Node - /// AbstractNode provides a basic implementation - /// of the Node interface for all types of nodes - /// that do not contain other nodes. -{ -public: - // Node - const XMLString& nodeName() const; - const XMLString& getNodeValue() const; - void setNodeValue(const XMLString& value); - Node* parentNode() const; - NodeList* childNodes() const; - Node* firstChild() const; - Node* lastChild() const; - Node* previousSibling() const; - Node* nextSibling() const; - NamedNodeMap* attributes() const; - Document* ownerDocument() const; - Node* insertBefore(Node* newChild, Node* refChild); - Node* replaceChild(Node* newChild, Node* oldChild); - Node* removeChild(Node* oldChild); - Node* appendChild(Node* newChild); - bool hasChildNodes() const; - Node* cloneNode(bool deep) const; - void normalize(); - bool isSupported(const XMLString& feature, const XMLString& version) const; - const XMLString& namespaceURI() const; - XMLString prefix() const; - const XMLString& localName() const; - bool hasAttributes() const; - - // EventTarget - void addEventListener(const XMLString& type, EventListener* listener, bool useCapture); - void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture); - bool dispatchEvent(Event* evt); - - // Extensions - XMLString innerText() const; - - virtual void autoRelease(); - -protected: - AbstractNode(Document* pOwnerDocument); - AbstractNode(Document* pOwnerDocument, const AbstractNode& node); - ~AbstractNode(); - - virtual Node* copyNode(bool deep, Document* pOwnerDocument) const = 0; - - virtual bool events() const; - virtual bool eventsSuspended() const; - void captureEvent(Event* evt); - void bubbleEvent(Event* evt); - void dispatchSubtreeModified(); - void dispatchNodeInserted(); - void dispatchNodeRemoved(); - virtual void dispatchNodeRemovedFromDocument(); - virtual void dispatchNodeInsertedIntoDocument(); - void dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue); - void dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue); - void setOwnerDocument(Document* pOwnerDocument); - - static const XMLString EMPTY_STRING; - -private: - AbstractNode(); - - AbstractContainerNode* _pParent; - AbstractNode* _pNext; - Document* _pOwner; - EventDispatcher* _pEventDispatcher; - - static const XMLString NODE_NAME; - - friend class AbstractContainerNode; - friend class Document; - friend class DocumentFragment; - friend class Element; - friend class Attr; - friend class CharacterData; - friend class DOMBuilder; - friend class NodeAppender; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_AbstractNode_INCLUDED +// +// AbstractNode.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/AbstractNode.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the AbstractNode class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_AbstractNode_INCLUDED +#define DOM_AbstractNode_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/Node.h" +#include "Poco/DOM/MutationEvent.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class AbstractContainerNode; +class Attr; +class EventDispatcher; + + +class XML_API AbstractNode: public Node + /// AbstractNode provides a basic implementation + /// of the Node interface for all types of nodes + /// that do not contain other nodes. +{ +public: + // Node + const XMLString& nodeName() const; + const XMLString& getNodeValue() const; + void setNodeValue(const XMLString& value); + Node* parentNode() const; + NodeList* childNodes() const; + Node* firstChild() const; + Node* lastChild() const; + Node* previousSibling() const; + Node* nextSibling() const; + NamedNodeMap* attributes() const; + Document* ownerDocument() const; + Node* insertBefore(Node* newChild, Node* refChild); + Node* replaceChild(Node* newChild, Node* oldChild); + Node* removeChild(Node* oldChild); + Node* appendChild(Node* newChild); + bool hasChildNodes() const; + Node* cloneNode(bool deep) const; + void normalize(); + bool isSupported(const XMLString& feature, const XMLString& version) const; + const XMLString& namespaceURI() const; + XMLString prefix() const; + const XMLString& localName() const; + bool hasAttributes() const; + + // EventTarget + void addEventListener(const XMLString& type, EventListener* listener, bool useCapture); + void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture); + bool dispatchEvent(Event* evt); + + // Extensions + XMLString innerText() const; + + virtual void autoRelease(); + +protected: + AbstractNode(Document* pOwnerDocument); + AbstractNode(Document* pOwnerDocument, const AbstractNode& node); + ~AbstractNode(); + + virtual Node* copyNode(bool deep, Document* pOwnerDocument) const = 0; + + virtual bool events() const; + virtual bool eventsSuspended() const; + void captureEvent(Event* evt); + void bubbleEvent(Event* evt); + void dispatchSubtreeModified(); + void dispatchNodeInserted(); + void dispatchNodeRemoved(); + virtual void dispatchNodeRemovedFromDocument(); + virtual void dispatchNodeInsertedIntoDocument(); + void dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue); + void dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue); + void setOwnerDocument(Document* pOwnerDocument); + + static const XMLString EMPTY_STRING; + +private: + AbstractNode(); + + AbstractContainerNode* _pParent; + AbstractNode* _pNext; + Document* _pOwner; + EventDispatcher* _pEventDispatcher; + + static const XMLString NODE_NAME; + + friend class AbstractContainerNode; + friend class Document; + friend class DocumentFragment; + friend class Element; + friend class Attr; + friend class CharacterData; + friend class DOMBuilder; + friend class NodeAppender; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_AbstractNode_INCLUDED diff --git a/XML/include/Poco/DOM/Attr.h b/XML/include/Poco/DOM/Attr.h index 41641625b..bcd8fd90f 100644 --- a/XML/include/Poco/DOM/Attr.h +++ b/XML/include/Poco/DOM/Attr.h @@ -1,202 +1,202 @@ -// -// Attr.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Attr.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Attr class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Attr_INCLUDED -#define DOM_Attr_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/DOM/Element.h" -#include "Poco/XML/Name.h" - - -namespace Poco { -namespace XML { - - -class XML_API Attr: public AbstractNode - /// The Attr interface represents an attribute in an Element object. Typically - /// the allowable values for the attribute are defined in a document type definition. - /// - /// Attr objects inherit the Node interface, but since they are not actually - /// child nodes of the element they describe, the DOM does not consider them - /// part of the document tree. Thus, the Node attributes parentNode, previousSibling, - /// and nextSibling have a null value for Attr objects. The DOM takes the view - /// that attributes are properties of elements rather than having a separate - /// identity from the elements they are associated with; this should make it - /// more efficient to implement such features as default attributes associated - /// with all elements of a given type. Furthermore, Attr nodes may not be immediate - /// children of a DocumentFragment. However, they can be associated with Element - /// nodes contained within a DocumentFragment. In short, users and implementors - /// of the DOM need to be aware that Attr nodes have some things in common with - /// other objects inheriting the Node interface, but they also are quite distinct. - /// - /// The attribute's effective value is determined as follows: if this attribute - /// has been explicitly assigned any value, that value is the attribute's effective - /// value; otherwise, if there is a declaration for this attribute, and that - /// declaration includes a default value, then that default value is the attribute's - /// effective value; otherwise, the attribute does not exist on this element - /// in the structure model until it has been explicitly added. Note that the - /// nodeValue attribute on the Attr instance can also be used to retrieve the - /// string version of the attribute's value(s). - /// - /// In XML, where the value of an attribute can contain entity references, the - /// child nodes of the Attr node provide a representation in which entity references - /// are not expanded. These child nodes may be either Text or EntityReference - /// nodes. Because the attribute type may be unknown, there are no tokenized - /// attribute values. -{ -public: - const XMLString& name() const; - /// Returns the name of this attribute. - - bool specified() const; - /// If this attribute was explicitly given a value in the original document, - /// this is true; otherwise, it is false. Note that the implementation is in - /// charge of this attribute, not the user. If the user changes the value of - /// the attribute (even if it ends up having the same value as the default value) - /// then the specified flag is automatically flipped to true. To re-specify - /// the attribute as the default value from the DTD, the user must delete the - /// attribute. The implementation will then make a new attribute available with - /// specified set to false and the default value (if one exists). - /// In summary: - /// - /// * If the attribute has an assigned value in the document then specified - /// is true, and the value is the assigned value. - /// * If the attribute has no assigned value in the document and has a default - /// value in the DTD, then specified is false, and the value is the default - /// value in the DTD. - /// * If the attribute has no assigned value in the document and has a value - /// of #IMPLIED in the DTD, then the attribute does not appear in the structure - /// model of the document. - /// * If the attribute is not associated to any element (i.e. because it - /// was just created or was obtained from some removal or cloning operation) - /// specified is true. - - const XMLString& value() const; - /// Returns the value of the attribute as a string. Character - /// and general entity references are replaced with their values. See also the - /// method getAttribute on the Element interface. - - const XMLString& getValue() const; - /// Returns the value of the attribute as a string. Character - /// and general entity references are replaced with their values. See also the - /// method getAttribute on the Element interface. - - void setValue(const XMLString& value); - /// Sets the value of the attribute as a string. - /// This creates a Text node with the unparsed contents of the string. - /// I.e. any characters that an XML processor would recognize as markup are - /// instead treated as literal text. See also the method setAttribute on the - /// Element interface. - - // DOM Level 2 - Element* ownerElement() const; - /// The Element node this attribute is attached to or null - /// if this attribute is not in use. - - // Node - Node* parentNode() const; - const XMLString& nodeName() const; - const XMLString& getNodeValue() const; - void setNodeValue(const XMLString& value); - unsigned short nodeType() const; - Node* previousSibling() const; - const XMLString& namespaceURI() const; - XMLString prefix() const; - const XMLString& localName() const; - - // Non-standard extensions - XMLString innerText() const; - -protected: - Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified = true); - Attr(Document* pOwnerDocument, const Attr& attr); - ~Attr(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - const Name& _name; - XMLString _value; - bool _specified; - - friend class Document; - friend class Element; - friend class DOMBuilder; -}; - - -// -// inlines -// -inline const XMLString& Attr::name() const -{ - return _name.qname(); -} - - -inline const XMLString& Attr::value() const -{ - return _value; -} - - -inline const XMLString& Attr::getValue() const -{ - return _value; -} - - -inline bool Attr::specified() const -{ - return _specified; -} - - -inline Element* Attr::ownerElement() const -{ - return static_cast(_pParent); -} - - -} } // namespace Poco::XML - - -#endif // DOM_Attr_INCLUDED +// +// Attr.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Attr.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Attr class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Attr_INCLUDED +#define DOM_Attr_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/DOM/Element.h" +#include "Poco/XML/Name.h" + + +namespace Poco { +namespace XML { + + +class XML_API Attr: public AbstractNode + /// The Attr interface represents an attribute in an Element object. Typically + /// the allowable values for the attribute are defined in a document type definition. + /// + /// Attr objects inherit the Node interface, but since they are not actually + /// child nodes of the element they describe, the DOM does not consider them + /// part of the document tree. Thus, the Node attributes parentNode, previousSibling, + /// and nextSibling have a null value for Attr objects. The DOM takes the view + /// that attributes are properties of elements rather than having a separate + /// identity from the elements they are associated with; this should make it + /// more efficient to implement such features as default attributes associated + /// with all elements of a given type. Furthermore, Attr nodes may not be immediate + /// children of a DocumentFragment. However, they can be associated with Element + /// nodes contained within a DocumentFragment. In short, users and implementors + /// of the DOM need to be aware that Attr nodes have some things in common with + /// other objects inheriting the Node interface, but they also are quite distinct. + /// + /// The attribute's effective value is determined as follows: if this attribute + /// has been explicitly assigned any value, that value is the attribute's effective + /// value; otherwise, if there is a declaration for this attribute, and that + /// declaration includes a default value, then that default value is the attribute's + /// effective value; otherwise, the attribute does not exist on this element + /// in the structure model until it has been explicitly added. Note that the + /// nodeValue attribute on the Attr instance can also be used to retrieve the + /// string version of the attribute's value(s). + /// + /// In XML, where the value of an attribute can contain entity references, the + /// child nodes of the Attr node provide a representation in which entity references + /// are not expanded. These child nodes may be either Text or EntityReference + /// nodes. Because the attribute type may be unknown, there are no tokenized + /// attribute values. +{ +public: + const XMLString& name() const; + /// Returns the name of this attribute. + + bool specified() const; + /// If this attribute was explicitly given a value in the original document, + /// this is true; otherwise, it is false. Note that the implementation is in + /// charge of this attribute, not the user. If the user changes the value of + /// the attribute (even if it ends up having the same value as the default value) + /// then the specified flag is automatically flipped to true. To re-specify + /// the attribute as the default value from the DTD, the user must delete the + /// attribute. The implementation will then make a new attribute available with + /// specified set to false and the default value (if one exists). + /// In summary: + /// + /// * If the attribute has an assigned value in the document then specified + /// is true, and the value is the assigned value. + /// * If the attribute has no assigned value in the document and has a default + /// value in the DTD, then specified is false, and the value is the default + /// value in the DTD. + /// * If the attribute has no assigned value in the document and has a value + /// of #IMPLIED in the DTD, then the attribute does not appear in the structure + /// model of the document. + /// * If the attribute is not associated to any element (i.e. because it + /// was just created or was obtained from some removal or cloning operation) + /// specified is true. + + const XMLString& value() const; + /// Returns the value of the attribute as a string. Character + /// and general entity references are replaced with their values. See also the + /// method getAttribute on the Element interface. + + const XMLString& getValue() const; + /// Returns the value of the attribute as a string. Character + /// and general entity references are replaced with their values. See also the + /// method getAttribute on the Element interface. + + void setValue(const XMLString& value); + /// Sets the value of the attribute as a string. + /// This creates a Text node with the unparsed contents of the string. + /// I.e. any characters that an XML processor would recognize as markup are + /// instead treated as literal text. See also the method setAttribute on the + /// Element interface. + + // DOM Level 2 + Element* ownerElement() const; + /// The Element node this attribute is attached to or null + /// if this attribute is not in use. + + // Node + Node* parentNode() const; + const XMLString& nodeName() const; + const XMLString& getNodeValue() const; + void setNodeValue(const XMLString& value); + unsigned short nodeType() const; + Node* previousSibling() const; + const XMLString& namespaceURI() const; + XMLString prefix() const; + const XMLString& localName() const; + + // Non-standard extensions + XMLString innerText() const; + +protected: + Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified = true); + Attr(Document* pOwnerDocument, const Attr& attr); + ~Attr(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + const Name& _name; + XMLString _value; + bool _specified; + + friend class Document; + friend class Element; + friend class DOMBuilder; +}; + + +// +// inlines +// +inline const XMLString& Attr::name() const +{ + return _name.qname(); +} + + +inline const XMLString& Attr::value() const +{ + return _value; +} + + +inline const XMLString& Attr::getValue() const +{ + return _value; +} + + +inline bool Attr::specified() const +{ + return _specified; +} + + +inline Element* Attr::ownerElement() const +{ + return static_cast(_pParent); +} + + +} } // namespace Poco::XML + + +#endif // DOM_Attr_INCLUDED diff --git a/XML/include/Poco/DOM/AttrMap.h b/XML/include/Poco/DOM/AttrMap.h index 43fcccee6..5ee279a4c 100644 --- a/XML/include/Poco/DOM/AttrMap.h +++ b/XML/include/Poco/DOM/AttrMap.h @@ -1,87 +1,87 @@ -// -// AttrMap.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/AttrMap.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the AttrMap class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_AttrMap_INCLUDED -#define DOM_AttrMap_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/NamedNodeMap.h" - - -namespace Poco { -namespace XML { - - -class Element; - - -class XML_API AttrMap: public NamedNodeMap - // This implementation of NamedNodeMap is - // returned by Element::attributes() -{ -public: - Node* getNamedItem(const XMLString& name) const; - Node* setNamedItem(Node* arg); - Node* removeNamedItem(const XMLString& name); - Node* item(unsigned long index) const; - unsigned long length() const; - - Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const; - Node* setNamedItemNS(Node* arg); - Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName); - - void autoRelease(); - -protected: - AttrMap(Element* pElement); - ~AttrMap(); - -private: - AttrMap(); - - Element* _pElement; - - friend class Element; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_AttrMap_INCLUDED +// +// AttrMap.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/AttrMap.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the AttrMap class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_AttrMap_INCLUDED +#define DOM_AttrMap_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/NamedNodeMap.h" + + +namespace Poco { +namespace XML { + + +class Element; + + +class XML_API AttrMap: public NamedNodeMap + // This implementation of NamedNodeMap is + // returned by Element::attributes() +{ +public: + Node* getNamedItem(const XMLString& name) const; + Node* setNamedItem(Node* arg); + Node* removeNamedItem(const XMLString& name); + Node* item(unsigned long index) const; + unsigned long length() const; + + Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const; + Node* setNamedItemNS(Node* arg); + Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName); + + void autoRelease(); + +protected: + AttrMap(Element* pElement); + ~AttrMap(); + +private: + AttrMap(); + + Element* _pElement; + + friend class Element; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_AttrMap_INCLUDED diff --git a/XML/include/Poco/DOM/AutoPtr.h b/XML/include/Poco/DOM/AutoPtr.h index 1fa278593..b51742f45 100644 --- a/XML/include/Poco/DOM/AutoPtr.h +++ b/XML/include/Poco/DOM/AutoPtr.h @@ -1,57 +1,57 @@ -// -// AutoPtr.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/AutoPtr.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Import Poco::AutoPtr into the XML namespace. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMAutoPtr_INCLUDED -#define DOM_DOMAutoPtr_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/AutoPtr.h" - - -namespace Poco { -namespace XML { - - -using Poco::AutoPtr; - - -} } // namespace Poco::XML - - -#endif // DOM_DOMAutoPtr_INCLUDED +// +// AutoPtr.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/AutoPtr.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Import Poco::AutoPtr into the XML namespace. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMAutoPtr_INCLUDED +#define DOM_DOMAutoPtr_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/AutoPtr.h" + + +namespace Poco { +namespace XML { + + +using Poco::AutoPtr; + + +} } // namespace Poco::XML + + +#endif // DOM_DOMAutoPtr_INCLUDED diff --git a/XML/include/Poco/DOM/CDATASection.h b/XML/include/Poco/DOM/CDATASection.h index aa07653b3..cc3d59ff5 100644 --- a/XML/include/Poco/DOM/CDATASection.h +++ b/XML/include/Poco/DOM/CDATASection.h @@ -1,106 +1,106 @@ -// -// CDATASection.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/CDATASection.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM CDATASection class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_CDATASection_INCLUDED -#define DOM_CDATASection_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/Text.h" - - -namespace Poco { -namespace XML { - - -class XML_API CDATASection: public Text - /// CDATA sections are used to escape blocks of text containing characters that - /// would otherwise be regarded as markup. The only delimiter that is recognized - /// in a CDATA section is the "]]>" string that ends the CDATA section. CDATA - /// sections cannot be nested. Their primary purpose is for including material - /// such as XML fragments, without needing to escape all the delimiters. - /// - /// The DOMString attribute of the Text node holds the text that is contained - /// by the CDATA section. Note that this may contain characters that need to - /// be escaped outside of CDATA sections and that, depending on the character - /// encoding ("charset") chosen for serialization, it may be impossible to write - /// out some characters as part of a CDATA section. - /// - /// The CDATASection interface inherits from the CharacterData interface through - /// the Text interface. Adjacent CDATASection nodes are not merged by use of - /// the normalize method on the Element interface. - /// - /// Note: Because no markup is recognized within a CDATASection, character numeric - /// references cannot be used as an escape mechanism when serializing. Therefore, - /// action needs to be taken when serializing a CDATASection with a character - /// encoding where some of the contained characters cannot be represented. Failure - /// to do so would not produce well-formed XML. - /// One potential solution in the serialization process is to end the CDATA - /// section before the character, output the character using a character reference - /// or entity reference, and open a new CDATA section for any further characters - /// in the text node. Note, however, that some code conversion libraries at - /// the time of writing do not return an error or exception when a character - /// is missing from the encoding, making the task of ensuring that data is not - /// corrupted on serialization more difficult. -{ -public: - // Text - Text* splitText(unsigned long offset); - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - CDATASection(Document* pOwnerDocument, const XMLString& data); - CDATASection(Document* pOwnerDocument, const CDATASection& sec); - ~CDATASection(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - static const XMLString NODE_NAME; - - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_CDATASection_INCLUDED +// +// CDATASection.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/CDATASection.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM CDATASection class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_CDATASection_INCLUDED +#define DOM_CDATASection_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/Text.h" + + +namespace Poco { +namespace XML { + + +class XML_API CDATASection: public Text + /// CDATA sections are used to escape blocks of text containing characters that + /// would otherwise be regarded as markup. The only delimiter that is recognized + /// in a CDATA section is the "]]>" string that ends the CDATA section. CDATA + /// sections cannot be nested. Their primary purpose is for including material + /// such as XML fragments, without needing to escape all the delimiters. + /// + /// The DOMString attribute of the Text node holds the text that is contained + /// by the CDATA section. Note that this may contain characters that need to + /// be escaped outside of CDATA sections and that, depending on the character + /// encoding ("charset") chosen for serialization, it may be impossible to write + /// out some characters as part of a CDATA section. + /// + /// The CDATASection interface inherits from the CharacterData interface through + /// the Text interface. Adjacent CDATASection nodes are not merged by use of + /// the normalize method on the Element interface. + /// + /// Note: Because no markup is recognized within a CDATASection, character numeric + /// references cannot be used as an escape mechanism when serializing. Therefore, + /// action needs to be taken when serializing a CDATASection with a character + /// encoding where some of the contained characters cannot be represented. Failure + /// to do so would not produce well-formed XML. + /// One potential solution in the serialization process is to end the CDATA + /// section before the character, output the character using a character reference + /// or entity reference, and open a new CDATA section for any further characters + /// in the text node. Note, however, that some code conversion libraries at + /// the time of writing do not return an error or exception when a character + /// is missing from the encoding, making the task of ensuring that data is not + /// corrupted on serialization more difficult. +{ +public: + // Text + Text* splitText(unsigned long offset); + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + CDATASection(Document* pOwnerDocument, const XMLString& data); + CDATASection(Document* pOwnerDocument, const CDATASection& sec); + ~CDATASection(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + static const XMLString NODE_NAME; + + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_CDATASection_INCLUDED diff --git a/XML/include/Poco/DOM/CharacterData.h b/XML/include/Poco/DOM/CharacterData.h index 308561bcb..659a37556 100644 --- a/XML/include/Poco/DOM/CharacterData.h +++ b/XML/include/Poco/DOM/CharacterData.h @@ -1,145 +1,145 @@ -// -// CharacterData.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/CharacterData.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM CharacterData class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_CharacterData_INCLUDED -#define DOM_CharacterData_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API CharacterData: public AbstractNode - /// The CharacterData interface extends Node with a set of attributes and methods - /// for accessing character data in the DOM. For clarity this set is defined - /// here rather than on each object that uses these attributes and methods. - /// No DOM objects correspond directly to CharacterData, though Text and others - /// do inherit the interface from it. All offsets in this interface start from 0. - /// - /// Text strings in the DOM are represented in either UTF-8 (if XML_UNICODE_WCHAR_T is - /// not defined) or in UTF-16 (if XML_UNICODE_WCHAR_T is defined). - /// Indexing on character data is done in XMLChar units. -{ -public: - const XMLString& data() const; - /// Returns the character data of the node that - /// implements the interface. - - const XMLString& getData() const; - /// Returns the character data of the node that - /// implements the interface. - - void setData(const XMLString& data); - /// Sets the character data of the node that - /// implements the interface. - - unsigned long length() const; - /// Returns the number of XMLChars that are available - /// through getData and substringData. This may have the - /// value zero. - - XMLString substringData(unsigned long offset, unsigned long count) const; - /// Extracts a range of data from the node. - /// If offset and count exceeds the length, then all - /// the characters to the end of the data are returned. - - void appendData(const XMLString& arg); - /// Append the string to the end of the character data - /// of the node. - - void insertData(unsigned long offset, const XMLString& arg); - /// Insert a string at the specified character offset. - - void deleteData(unsigned long offset, unsigned long count); - /// Remove a range of characters from the node. - - void replaceData(unsigned long offset, unsigned long count, const XMLString& arg); - /// Replace the characters starting at the specified character - /// offset with the specified string. - - // Non-standard extensions - XMLString trimmedData() const; - /// Returns the character data of that node with - /// all surrounding whitespace removed. - /// - /// This method is an extension to the W3C Document Object Model. - - // Node - const XMLString& getNodeValue() const; - void setNodeValue(const XMLString& value); - -protected: - CharacterData(Document* pOwnerDocument, const XMLString& data); - CharacterData(Document* pOwnerDocument, const CharacterData& data); - ~CharacterData(); - -private: - XMLString _data; -}; - - -// -// inlines -// -inline const XMLString& CharacterData::data() const -{ - return _data; -} - - -inline const XMLString& CharacterData::getData() const -{ - return _data; -} - - -inline unsigned long CharacterData::length() const -{ - return (unsigned long) _data.length(); -} - - -} } // namespace Poco::XML - - -#endif // DOM_CharacterData_INCLUDED +// +// CharacterData.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/CharacterData.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM CharacterData class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_CharacterData_INCLUDED +#define DOM_CharacterData_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API CharacterData: public AbstractNode + /// The CharacterData interface extends Node with a set of attributes and methods + /// for accessing character data in the DOM. For clarity this set is defined + /// here rather than on each object that uses these attributes and methods. + /// No DOM objects correspond directly to CharacterData, though Text and others + /// do inherit the interface from it. All offsets in this interface start from 0. + /// + /// Text strings in the DOM are represented in either UTF-8 (if XML_UNICODE_WCHAR_T is + /// not defined) or in UTF-16 (if XML_UNICODE_WCHAR_T is defined). + /// Indexing on character data is done in XMLChar units. +{ +public: + const XMLString& data() const; + /// Returns the character data of the node that + /// implements the interface. + + const XMLString& getData() const; + /// Returns the character data of the node that + /// implements the interface. + + void setData(const XMLString& data); + /// Sets the character data of the node that + /// implements the interface. + + unsigned long length() const; + /// Returns the number of XMLChars that are available + /// through getData and substringData. This may have the + /// value zero. + + XMLString substringData(unsigned long offset, unsigned long count) const; + /// Extracts a range of data from the node. + /// If offset and count exceeds the length, then all + /// the characters to the end of the data are returned. + + void appendData(const XMLString& arg); + /// Append the string to the end of the character data + /// of the node. + + void insertData(unsigned long offset, const XMLString& arg); + /// Insert a string at the specified character offset. + + void deleteData(unsigned long offset, unsigned long count); + /// Remove a range of characters from the node. + + void replaceData(unsigned long offset, unsigned long count, const XMLString& arg); + /// Replace the characters starting at the specified character + /// offset with the specified string. + + // Non-standard extensions + XMLString trimmedData() const; + /// Returns the character data of that node with + /// all surrounding whitespace removed. + /// + /// This method is an extension to the W3C Document Object Model. + + // Node + const XMLString& getNodeValue() const; + void setNodeValue(const XMLString& value); + +protected: + CharacterData(Document* pOwnerDocument, const XMLString& data); + CharacterData(Document* pOwnerDocument, const CharacterData& data); + ~CharacterData(); + +private: + XMLString _data; +}; + + +// +// inlines +// +inline const XMLString& CharacterData::data() const +{ + return _data; +} + + +inline const XMLString& CharacterData::getData() const +{ + return _data; +} + + +inline unsigned long CharacterData::length() const +{ + return (unsigned long) _data.length(); +} + + +} } // namespace Poco::XML + + +#endif // DOM_CharacterData_INCLUDED diff --git a/XML/include/Poco/DOM/ChildNodesList.h b/XML/include/Poco/DOM/ChildNodesList.h index 6139d63a5..74249fb1c 100644 --- a/XML/include/Poco/DOM/ChildNodesList.h +++ b/XML/include/Poco/DOM/ChildNodesList.h @@ -1,77 +1,77 @@ -// -// ChildNodesList.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/ChildNodesList.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the ChildNodesList class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_ChildNodesList_INCLUDED -#define DOM_ChildNodesList_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/NodeList.h" - - -namespace Poco { -namespace XML { - - -class XML_API ChildNodesList: public NodeList - // This implementation of NodeList is returned - // by Node::getChildNodes(). -{ -public: - Node* item(unsigned long index) const; - unsigned long length() const; - - void autoRelease(); - -protected: - ChildNodesList(const Node* pParent); - ~ChildNodesList(); - -private: - ChildNodesList(); - - const Node* _pParent; - - friend class AbstractNode; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_ChildNodesList_INCLUDED +// +// ChildNodesList.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/ChildNodesList.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the ChildNodesList class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_ChildNodesList_INCLUDED +#define DOM_ChildNodesList_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/NodeList.h" + + +namespace Poco { +namespace XML { + + +class XML_API ChildNodesList: public NodeList + // This implementation of NodeList is returned + // by Node::getChildNodes(). +{ +public: + Node* item(unsigned long index) const; + unsigned long length() const; + + void autoRelease(); + +protected: + ChildNodesList(const Node* pParent); + ~ChildNodesList(); + +private: + ChildNodesList(); + + const Node* _pParent; + + friend class AbstractNode; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_ChildNodesList_INCLUDED diff --git a/XML/include/Poco/DOM/Comment.h b/XML/include/Poco/DOM/Comment.h index f70a105c7..6b88eb947 100644 --- a/XML/include/Poco/DOM/Comment.h +++ b/XML/include/Poco/DOM/Comment.h @@ -1,80 +1,80 @@ -// -// Comment.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Comment.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Comment class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Comment_INCLUDED -#define DOM_Comment_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/CharacterData.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Comment: public CharacterData - /// This interface inherits from CharacterData and represents the content of - /// a comment, i.e., all the characters between the starting ''. Note that this is the definition of a comment in XML, and, in practice, - /// HTML, although some HTML tools may implement the full SGML comment structure. -{ -public: - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - Comment(Document* pOwnerDocument, const XMLString& data); - Comment(Document* pOwnerDocument, const Comment& comment); - ~Comment(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - static const XMLString NODE_NAME; - - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_Comment_INCLUDED +// +// Comment.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Comment.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Comment class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Comment_INCLUDED +#define DOM_Comment_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/CharacterData.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Comment: public CharacterData + /// This interface inherits from CharacterData and represents the content of + /// a comment, i.e., all the characters between the starting ''. Note that this is the definition of a comment in XML, and, in practice, + /// HTML, although some HTML tools may implement the full SGML comment structure. +{ +public: + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + Comment(Document* pOwnerDocument, const XMLString& data); + Comment(Document* pOwnerDocument, const Comment& comment); + ~Comment(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + static const XMLString NODE_NAME; + + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_Comment_INCLUDED diff --git a/XML/include/Poco/DOM/DOMBuilder.h b/XML/include/Poco/DOM/DOMBuilder.h index f96acc139..22c7eb3a4 100644 --- a/XML/include/Poco/DOM/DOMBuilder.h +++ b/XML/include/Poco/DOM/DOMBuilder.h @@ -1,134 +1,134 @@ -// -// DOMBuilder.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMBuilder.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMBuilder -// -// Definition of the DOMBuilder class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMBuilder_INCLUDED -#define DOM_DOMBuilder_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/LexicalHandler.h" -#include "Poco/SAX/DTDHandler.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XMLReader; -class Document; -class InputSource; -class AbstractNode; -class AbstractContainerNode; -class NamePool; - - -class XML_API DOMBuilder: protected DTDHandler, protected ContentHandler, protected LexicalHandler - /// This class builds a tree representation of an - /// XML document, according to the W3C Document Object Model, Level 1 and 2 - /// specifications. - /// - /// The actual XML parsing is done by an XMLReader, which - /// must be supplied to the DOMBuilder. -{ -public: - DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool = 0); - /// Creates a DOMBuilder using the given XMLReader. - /// If a NamePool is given, it becomes the Document's NamePool. - - virtual ~DOMBuilder(); - /// Destroys the DOMBuilder. - - virtual Document* parse(const XMLString& uri); - /// Parse an XML document from a location identified by an URI. - - virtual Document* parse(InputSource* pInputSource); - /// Parse an XML document from a location identified by an InputSource. - - virtual Document* parseMemoryNP(const char* xml, std::size_t size); - /// Parses an XML document from memory. - -protected: - // DTDHandler - void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); - void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); - - // ContentHandler - void setDocumentLocator(const Locator* loc); - void startDocument(); - void endDocument(); - void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes); - void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); - void characters(const XMLChar ch[], int start, int length); - void ignorableWhitespace(const XMLChar ch[], int start, int length); - void processingInstruction(const XMLString& target, const XMLString& data); - void startPrefixMapping(const XMLString& prefix, const XMLString& uri); - void endPrefixMapping(const XMLString& prefix); - void skippedEntity(const XMLString& name); - - // LexicalHandler - void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); - void endDTD(); - void startEntity(const XMLString& name); - void endEntity(const XMLString& name); - void startCDATA(); - void endCDATA(); - void comment(const XMLChar ch[], int start, int length); - - void appendNode(AbstractNode* pNode); - - void setupParse(); - -private: - static const XMLString EMPTY_STRING; - - XMLReader& _xmlReader; - NamePool* _pNamePool; - Document* _pDocument; - AbstractContainerNode* _pParent; - AbstractNode* _pPrevious; - bool _inCDATA; - bool _namespaces; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DOMBuilder_INCLUDED +// +// DOMBuilder.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMBuilder.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMBuilder +// +// Definition of the DOMBuilder class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMBuilder_INCLUDED +#define DOM_DOMBuilder_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/LexicalHandler.h" +#include "Poco/SAX/DTDHandler.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XMLReader; +class Document; +class InputSource; +class AbstractNode; +class AbstractContainerNode; +class NamePool; + + +class XML_API DOMBuilder: protected DTDHandler, protected ContentHandler, protected LexicalHandler + /// This class builds a tree representation of an + /// XML document, according to the W3C Document Object Model, Level 1 and 2 + /// specifications. + /// + /// The actual XML parsing is done by an XMLReader, which + /// must be supplied to the DOMBuilder. +{ +public: + DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool = 0); + /// Creates a DOMBuilder using the given XMLReader. + /// If a NamePool is given, it becomes the Document's NamePool. + + virtual ~DOMBuilder(); + /// Destroys the DOMBuilder. + + virtual Document* parse(const XMLString& uri); + /// Parse an XML document from a location identified by an URI. + + virtual Document* parse(InputSource* pInputSource); + /// Parse an XML document from a location identified by an InputSource. + + virtual Document* parseMemoryNP(const char* xml, std::size_t size); + /// Parses an XML document from memory. + +protected: + // DTDHandler + void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); + void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); + + // ContentHandler + void setDocumentLocator(const Locator* loc); + void startDocument(); + void endDocument(); + void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes); + void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); + void characters(const XMLChar ch[], int start, int length); + void ignorableWhitespace(const XMLChar ch[], int start, int length); + void processingInstruction(const XMLString& target, const XMLString& data); + void startPrefixMapping(const XMLString& prefix, const XMLString& uri); + void endPrefixMapping(const XMLString& prefix); + void skippedEntity(const XMLString& name); + + // LexicalHandler + void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); + void endDTD(); + void startEntity(const XMLString& name); + void endEntity(const XMLString& name); + void startCDATA(); + void endCDATA(); + void comment(const XMLChar ch[], int start, int length); + + void appendNode(AbstractNode* pNode); + + void setupParse(); + +private: + static const XMLString EMPTY_STRING; + + XMLReader& _xmlReader; + NamePool* _pNamePool; + Document* _pDocument; + AbstractContainerNode* _pParent; + AbstractNode* _pPrevious; + bool _inCDATA; + bool _namespaces; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DOMBuilder_INCLUDED diff --git a/XML/include/Poco/DOM/DOMException.h b/XML/include/Poco/DOM/DOMException.h index 65e9c5cd6..55493eb6c 100644 --- a/XML/include/Poco/DOM/DOMException.h +++ b/XML/include/Poco/DOM/DOMException.h @@ -1,134 +1,134 @@ -// -// DOMException.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMException.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM DOMException class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMException_INCLUDED -#define DOM_DOMException_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLException.h" - - -namespace Poco { -namespace XML { - - -class XML_API DOMException: public XMLException - /// DOM operations only raise exceptions in "exceptional" circumstances, i.e., - /// when an operation is impossible to perform (either for logical reasons, - /// because data is lost, or because the implementation has become unstable). - /// In general, DOM methods return specific error values in ordinary processing - /// situations, such as out-of-bound errors when using NodeList. - /// - /// Implementations should raise other exceptions under other circumstances. - /// For example, implementations should raise an implementation-dependent exception - /// if a null argument is passed when null was not expected. -{ -public: - enum - { - INDEX_SIZE_ERR = 1, /// index or size is negative or greater than allowed value - DOMSTRING_SIZE_ERR, /// the specified range of text does not fit into a DOMString (not used) - HIERARCHY_REQUEST_ERR, /// a node is inserted somewhere it doesn't belong - WRONG_DOCUMENT_ERR, /// a node is used in a different document than the one that created it - INVALID_CHARACTER_ERR, /// an invalid character is specified (not used) - NO_DATA_ALLOWED_ERR, /// data is specified for a node which does not support data - NO_MODIFICATION_ALLOWED_ERR, /// an attempt is made to modify an object where modifications are not allowed - NOT_FOUND_ERR, /// an attempt was made to reference a node in a context where it does not exist - NOT_SUPPORTED_ERR, /// the implementation does not support the type of object requested - INUSE_ATTRIBUTE_ERR, /// an attempt is made to add an attribute that is already in use elsewhere - INVALID_STATE_ERR, /// a parameter or an operation is not supported by the underlying object - SYNTAX_ERR, /// an invalid or illegal string is specified - INVALID_MODIFICATION_ERR, /// an attempt is made to modify the type of the underlying object - NAMESPACE_ERR, /// an attempt is made to create or change an object in a way which is incorrect with regard to namespaces - INVALID_ACCESS_ERR, /// an attempt is made to use an object that is not, or is no longer, usable - - _NUMBER_OF_MESSAGES - }; - - DOMException(unsigned short code); - /// Creates a DOMException with the given error code. - - DOMException(const DOMException& exc); - /// Creates a DOMException by copying another one. - - ~DOMException() throw(); - /// Destroys the DOMException. - - DOMException& operator = (const DOMException& exc); - - const char* name() const throw(); - /// Returns a static string describing the exception. - - const char* className() const throw(); - /// Returns the name of the exception class. - - Poco::Exception* clone() const; - /// Creates an exact copy of the exception. - - void rethrow() const; - /// (Re)Throws the exception. - - unsigned short code() const; - /// Returns the DOM exception code. - -protected: - static const std::string& message(unsigned short code); - -private: - DOMException(); - - unsigned short _code; - - static const std::string MESSAGES[_NUMBER_OF_MESSAGES]; -}; - - -// -// inlines -// -inline unsigned short DOMException::code() const -{ - return _code; -} - - -} } // namespace Poco::XML - - -#endif // DOM_DOMException_INCLUDED +// +// DOMException.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMException.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM DOMException class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMException_INCLUDED +#define DOM_DOMException_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLException.h" + + +namespace Poco { +namespace XML { + + +class XML_API DOMException: public XMLException + /// DOM operations only raise exceptions in "exceptional" circumstances, i.e., + /// when an operation is impossible to perform (either for logical reasons, + /// because data is lost, or because the implementation has become unstable). + /// In general, DOM methods return specific error values in ordinary processing + /// situations, such as out-of-bound errors when using NodeList. + /// + /// Implementations should raise other exceptions under other circumstances. + /// For example, implementations should raise an implementation-dependent exception + /// if a null argument is passed when null was not expected. +{ +public: + enum + { + INDEX_SIZE_ERR = 1, /// index or size is negative or greater than allowed value + DOMSTRING_SIZE_ERR, /// the specified range of text does not fit into a DOMString (not used) + HIERARCHY_REQUEST_ERR, /// a node is inserted somewhere it doesn't belong + WRONG_DOCUMENT_ERR, /// a node is used in a different document than the one that created it + INVALID_CHARACTER_ERR, /// an invalid character is specified (not used) + NO_DATA_ALLOWED_ERR, /// data is specified for a node which does not support data + NO_MODIFICATION_ALLOWED_ERR, /// an attempt is made to modify an object where modifications are not allowed + NOT_FOUND_ERR, /// an attempt was made to reference a node in a context where it does not exist + NOT_SUPPORTED_ERR, /// the implementation does not support the type of object requested + INUSE_ATTRIBUTE_ERR, /// an attempt is made to add an attribute that is already in use elsewhere + INVALID_STATE_ERR, /// a parameter or an operation is not supported by the underlying object + SYNTAX_ERR, /// an invalid or illegal string is specified + INVALID_MODIFICATION_ERR, /// an attempt is made to modify the type of the underlying object + NAMESPACE_ERR, /// an attempt is made to create or change an object in a way which is incorrect with regard to namespaces + INVALID_ACCESS_ERR, /// an attempt is made to use an object that is not, or is no longer, usable + + _NUMBER_OF_MESSAGES + }; + + DOMException(unsigned short code); + /// Creates a DOMException with the given error code. + + DOMException(const DOMException& exc); + /// Creates a DOMException by copying another one. + + ~DOMException() throw(); + /// Destroys the DOMException. + + DOMException& operator = (const DOMException& exc); + + const char* name() const throw(); + /// Returns a static string describing the exception. + + const char* className() const throw(); + /// Returns the name of the exception class. + + Poco::Exception* clone() const; + /// Creates an exact copy of the exception. + + void rethrow() const; + /// (Re)Throws the exception. + + unsigned short code() const; + /// Returns the DOM exception code. + +protected: + static const std::string& message(unsigned short code); + +private: + DOMException(); + + unsigned short _code; + + static const std::string MESSAGES[_NUMBER_OF_MESSAGES]; +}; + + +// +// inlines +// +inline unsigned short DOMException::code() const +{ + return _code; +} + + +} } // namespace Poco::XML + + +#endif // DOM_DOMException_INCLUDED diff --git a/XML/include/Poco/DOM/DOMImplementation.h b/XML/include/Poco/DOM/DOMImplementation.h index 850963cb8..5488e39da 100644 --- a/XML/include/Poco/DOM/DOMImplementation.h +++ b/XML/include/Poco/DOM/DOMImplementation.h @@ -1,104 +1,104 @@ -// -// DOMImplementation.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMImplementation.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM DOMImplementation class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMImplementation_INCLUDED -#define DOM_DOMImplementation_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class DocumentType; -class Document; -class NamePool; - - -class XML_API DOMImplementation - /// The DOMImplementation interface provides a number of methods for - /// performing operations that are independent of any particular instance - /// of the document object model. - /// In this implementation, DOMImplementation is implemented as a singleton. -{ -public: - DOMImplementation(); - /// Creates the DOMImplementation. - - ~DOMImplementation(); - /// Destroys the DOMImplementation. - - bool hasFeature(const XMLString& feature, const XMLString& version) const; - /// Tests if the DOM implementation implements a specific feature. - /// - /// The only supported features are "XML", version "1.0" and "Core", - /// "Events", "MutationEvents" and "Traversal", version "2.0". - - // DOM Level 2 - DocumentType* createDocumentType(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const; - /// Creates an empty DocumentType node. Entity declarations and notations - /// are not made available. Entity reference expansions and default attribute - /// additions do not occur. - - Document* createDocument(const XMLString& namespaceURI, const XMLString& qualifiedName, DocumentType* doctype) const; - /// Creates an XML Document object of the specified type with its document element. - /// - /// Note: You can also create a Document directly using the new operator. - - static const DOMImplementation& instance(); - /// Returns a reference to the default DOMImplementation - /// object. - -private: - static const XMLString FEATURE_XML; - static const XMLString FEATURE_CORE; - static const XMLString FEATURE_EVENTS; - static const XMLString FEATURE_MUTATIONEVENTS; - static const XMLString FEATURE_TRAVERSAL; - static const XMLString VERSION_1_0; - static const XMLString VERSION_2_0; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DOMImplementation_INCLUDED +// +// DOMImplementation.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMImplementation.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM DOMImplementation class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMImplementation_INCLUDED +#define DOM_DOMImplementation_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class DocumentType; +class Document; +class NamePool; + + +class XML_API DOMImplementation + /// The DOMImplementation interface provides a number of methods for + /// performing operations that are independent of any particular instance + /// of the document object model. + /// In this implementation, DOMImplementation is implemented as a singleton. +{ +public: + DOMImplementation(); + /// Creates the DOMImplementation. + + ~DOMImplementation(); + /// Destroys the DOMImplementation. + + bool hasFeature(const XMLString& feature, const XMLString& version) const; + /// Tests if the DOM implementation implements a specific feature. + /// + /// The only supported features are "XML", version "1.0" and "Core", + /// "Events", "MutationEvents" and "Traversal", version "2.0". + + // DOM Level 2 + DocumentType* createDocumentType(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const; + /// Creates an empty DocumentType node. Entity declarations and notations + /// are not made available. Entity reference expansions and default attribute + /// additions do not occur. + + Document* createDocument(const XMLString& namespaceURI, const XMLString& qualifiedName, DocumentType* doctype) const; + /// Creates an XML Document object of the specified type with its document element. + /// + /// Note: You can also create a Document directly using the new operator. + + static const DOMImplementation& instance(); + /// Returns a reference to the default DOMImplementation + /// object. + +private: + static const XMLString FEATURE_XML; + static const XMLString FEATURE_CORE; + static const XMLString FEATURE_EVENTS; + static const XMLString FEATURE_MUTATIONEVENTS; + static const XMLString FEATURE_TRAVERSAL; + static const XMLString VERSION_1_0; + static const XMLString VERSION_2_0; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DOMImplementation_INCLUDED diff --git a/XML/include/Poco/DOM/DOMObject.h b/XML/include/Poco/DOM/DOMObject.h index 3c4cb57a6..f73dd5c51 100644 --- a/XML/include/Poco/DOM/DOMObject.h +++ b/XML/include/Poco/DOM/DOMObject.h @@ -1,125 +1,125 @@ -// -// DOMObject.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMObject.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOMObject class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMObject_INCLUDED -#define DOM_DOMObject_INCLUDED - - -#include "Poco/XML/XML.h" - - -namespace Poco { -namespace XML { - - -class XML_API DOMObject - /// The base class for all objects in the Document Object Model. - /// - /// DOMObject defines the rules for memory management - /// in this implementation of the DOM. Violation of these - /// rules, which are outlined in the following, results - /// in memory leaks or dangling pointers. - /// - /// Every object created by new or by a factory - /// method (for example, Document::create*) must be released - /// with a call to release() or autoRelease() when it - /// is no longer needed. - /// - /// Every object created by cloning or importing another - /// object must be released. - /// For every call to duplicate() there must be a matching - /// call to release(). - /// An object obtained via any other way must not be - /// released, except ownership of it has been explicitely - /// taken with a call to duplicate(). - /// - /// While DOMObjects are safe for use in multithreaded programs, - /// a DOMObject or one of its subclasses must not be accessed - /// from multiple threads simultaneously. -{ -public: - DOMObject(); - /// Creates the DOMObject. - /// The object's reference count is initialized to one. - - void duplicate() const; - /// Increases the object's reference count. - - void release() const; - /// Decreases the object's reference count. - /// If the reference count reaches zero, - /// the object is deleted. - - virtual void autoRelease() = 0; - /// Adds the object to an appropriate - /// AutoReleasePool, which is usually the - /// AutoReleasePool managed by the Document - /// to which this object belongs. - -protected: - virtual ~DOMObject(); - /// Destroys the DOMObject. - -private: - DOMObject(const DOMObject&); - DOMObject& operator = (const DOMObject&); - - mutable int _rc; -}; - - -// -// inlines -// -inline void DOMObject::duplicate() const -{ - ++_rc; -} - - -inline void DOMObject::release() const -{ - if (--_rc == 0) - delete this; -} - - -} } // namespace Poco::XML - - -#endif // DOM_DOMObject_INCLUDED +// +// DOMObject.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMObject.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOMObject class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMObject_INCLUDED +#define DOM_DOMObject_INCLUDED + + +#include "Poco/XML/XML.h" + + +namespace Poco { +namespace XML { + + +class XML_API DOMObject + /// The base class for all objects in the Document Object Model. + /// + /// DOMObject defines the rules for memory management + /// in this implementation of the DOM. Violation of these + /// rules, which are outlined in the following, results + /// in memory leaks or dangling pointers. + /// + /// Every object created by new or by a factory + /// method (for example, Document::create*) must be released + /// with a call to release() or autoRelease() when it + /// is no longer needed. + /// + /// Every object created by cloning or importing another + /// object must be released. + /// For every call to duplicate() there must be a matching + /// call to release(). + /// An object obtained via any other way must not be + /// released, except ownership of it has been explicitely + /// taken with a call to duplicate(). + /// + /// While DOMObjects are safe for use in multithreaded programs, + /// a DOMObject or one of its subclasses must not be accessed + /// from multiple threads simultaneously. +{ +public: + DOMObject(); + /// Creates the DOMObject. + /// The object's reference count is initialized to one. + + void duplicate() const; + /// Increases the object's reference count. + + void release() const; + /// Decreases the object's reference count. + /// If the reference count reaches zero, + /// the object is deleted. + + virtual void autoRelease() = 0; + /// Adds the object to an appropriate + /// AutoReleasePool, which is usually the + /// AutoReleasePool managed by the Document + /// to which this object belongs. + +protected: + virtual ~DOMObject(); + /// Destroys the DOMObject. + +private: + DOMObject(const DOMObject&); + DOMObject& operator = (const DOMObject&); + + mutable int _rc; +}; + + +// +// inlines +// +inline void DOMObject::duplicate() const +{ + ++_rc; +} + + +inline void DOMObject::release() const +{ + if (--_rc == 0) + delete this; +} + + +} } // namespace Poco::XML + + +#endif // DOM_DOMObject_INCLUDED diff --git a/XML/include/Poco/DOM/DOMParser.h b/XML/include/Poco/DOM/DOMParser.h index df43b7f4b..71315b506 100644 --- a/XML/include/Poco/DOM/DOMParser.h +++ b/XML/include/Poco/DOM/DOMParser.h @@ -1,129 +1,129 @@ -// -// DOMParser.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMParser.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMParser -// -// Definition of the DOMParser class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMParser_INCLUDED -#define DOM_DOMParser_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/SAXParser.h" - - -namespace Poco { -namespace XML { - - -class NamePool; -class Document; -class InputSource; -class EntityResolver; - - -class XML_API DOMParser - /// This is a convenience class that combines a - /// DOMBuilder with a SAXParser, with the optional - /// support of a WhitespaceFilter. -{ -public: - DOMParser(NamePool* pNamePool = 0); - /// Creates a new DOMParser. - /// If a NamePool is given, it becomes the Document's NamePool. - - ~DOMParser(); - /// Destroys the DOMParser. - - void setEncoding(const XMLString& encoding); - /// Sets the encoding used by the parser if no - /// encoding is specified in the XML document. - - const XMLString& getEncoding() const; - /// Returns the name of the encoding used by - /// the parser if no encoding is specified in - /// the XML document. - - void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); - /// Adds an encoding to the parser. - - void setFeature(const XMLString& name, bool state); - /// Set the state of a feature. - /// - /// If a feature is not recognized by the DOMParser, it is - /// passed on to the underlying XMLReader. - /// - /// The only currently supported feature is - /// http://www.appinf.com/features/no-whitespace-in-element-content - /// which, when activated, causes the WhitespaceFilter to - /// be used. - - bool getFeature(const XMLString& name) const; - /// Look up the value of a feature. - /// - /// If a feature is not recognized by the DOMParser, the - /// DOMParser queries the underlying SAXParser for the feature. - - Document* parse(const XMLString& uri); - /// Parse an XML document from a location identified by an URI. - - Document* parse(InputSource* pInputSource); - /// Parse an XML document from a location identified by an InputSource. - - Document* parseString(const std::string& xml); - /// Parse an XML document from a string. - - Document* parseMemory(const char* xml, std::size_t size); - /// Parse an XML document from memory. - - EntityResolver* getEntityResolver() const; - /// Returns the entity resolver used by the underlying SAXParser. - - void setEntityResolver(EntityResolver* pEntityResolver); - /// Sets the entity resolver on the underlying SAXParser. - - static const XMLString FEATURE_WHITESPACE; - -private: - SAXParser _saxParser; - NamePool* _pNamePool; - bool _whitespace; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DOMParser_INCLUDED +// +// DOMParser.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMParser.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMParser +// +// Definition of the DOMParser class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMParser_INCLUDED +#define DOM_DOMParser_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/SAXParser.h" + + +namespace Poco { +namespace XML { + + +class NamePool; +class Document; +class InputSource; +class EntityResolver; + + +class XML_API DOMParser + /// This is a convenience class that combines a + /// DOMBuilder with a SAXParser, with the optional + /// support of a WhitespaceFilter. +{ +public: + DOMParser(NamePool* pNamePool = 0); + /// Creates a new DOMParser. + /// If a NamePool is given, it becomes the Document's NamePool. + + ~DOMParser(); + /// Destroys the DOMParser. + + void setEncoding(const XMLString& encoding); + /// Sets the encoding used by the parser if no + /// encoding is specified in the XML document. + + const XMLString& getEncoding() const; + /// Returns the name of the encoding used by + /// the parser if no encoding is specified in + /// the XML document. + + void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); + /// Adds an encoding to the parser. + + void setFeature(const XMLString& name, bool state); + /// Set the state of a feature. + /// + /// If a feature is not recognized by the DOMParser, it is + /// passed on to the underlying XMLReader. + /// + /// The only currently supported feature is + /// http://www.appinf.com/features/no-whitespace-in-element-content + /// which, when activated, causes the WhitespaceFilter to + /// be used. + + bool getFeature(const XMLString& name) const; + /// Look up the value of a feature. + /// + /// If a feature is not recognized by the DOMParser, the + /// DOMParser queries the underlying SAXParser for the feature. + + Document* parse(const XMLString& uri); + /// Parse an XML document from a location identified by an URI. + + Document* parse(InputSource* pInputSource); + /// Parse an XML document from a location identified by an InputSource. + + Document* parseString(const std::string& xml); + /// Parse an XML document from a string. + + Document* parseMemory(const char* xml, std::size_t size); + /// Parse an XML document from memory. + + EntityResolver* getEntityResolver() const; + /// Returns the entity resolver used by the underlying SAXParser. + + void setEntityResolver(EntityResolver* pEntityResolver); + /// Sets the entity resolver on the underlying SAXParser. + + static const XMLString FEATURE_WHITESPACE; + +private: + SAXParser _saxParser; + NamePool* _pNamePool; + bool _whitespace; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DOMParser_INCLUDED diff --git a/XML/include/Poco/DOM/DOMSerializer.h b/XML/include/Poco/DOM/DOMSerializer.h index dd0325946..c7eb01cdb 100644 --- a/XML/include/Poco/DOM/DOMSerializer.h +++ b/XML/include/Poco/DOM/DOMSerializer.h @@ -1,144 +1,144 @@ -// -// DOMSerializer.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMSerializer.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMSerializer -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMSerializer_INCLUDED -#define DOM_DOMSerializer_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/XMLReader.h" - - -namespace Poco { -namespace XML { - - -class Node; -class Element; -class Text; -class Comment; -class ProcessingInstruction; -class Entity; -class CDATASection; -class Notation; -class Document; -class DocumentType; -class DocumentFragment; -class DeclHandler; -class LexicalHandler; - - -class XML_API DOMSerializer: public XMLReader - /// The DOMSerializer serializes a DOM document - /// into a sequence of SAX events which are - /// reported to the registered SAX event - /// handlers. - /// - /// The DOMWriter uses a DOMSerializer with an - /// XMLWriter to serialize a DOM document into - /// textual XML. -{ -public: - DOMSerializer(); - /// Creates the DOMSerializer. - - ~DOMSerializer(); - /// Destroys the DOMSerializer. - - void serialize(const Node* pNode); - /// Serializes a DOM node and its children - /// into a sequence of SAX events, which are - /// reported to the registered SAX event - /// handlers. - - // XMLReader - void setEntityResolver(EntityResolver* pResolver); - EntityResolver* getEntityResolver() const; - void setDTDHandler(DTDHandler* pDTDHandler); - DTDHandler* getDTDHandler() const; - void setContentHandler(ContentHandler* pContentHandler); - ContentHandler* getContentHandler() const; - void setErrorHandler(ErrorHandler* pErrorHandler); - ErrorHandler* getErrorHandler() const; - - void setFeature(const XMLString& featureId, bool state); - bool getFeature(const XMLString& featureId) const; - void setProperty(const XMLString& propertyId, const XMLString& value); - void setProperty(const XMLString& propertyId, void* value); - void* getProperty(const XMLString& propertyId) const; - -protected: - void parse(InputSource* pSource); - /// The DOMSerializer cannot parse an InputSource, - /// so this method simply throws an XMLException when invoked. - - void parse(const XMLString& systemId); - /// The DOMSerializer cannot parse from a system identifier, - /// so this method simply throws an XMLException when invoked. - - void parseMemoryNP(const char* xml, std::size_t size); - /// The DOMSerializer cannot parse from a system identifier, - /// so this method simply throws an XMLException when invoked. - - void iterate(const Node* pNode) const; - void handleNode(const Node* pNode) const; - void handleElement(const Element* pElement) const; - void handleCharacterData(const Text* pText) const; - void handleComment(const Comment* pComment) const; - void handlePI(const ProcessingInstruction* pPI) const; - void handleCDATASection(const CDATASection* pCDATA) const; - void handleDocument(const Document* pDocument) const; - void handleDocumentType(const DocumentType* pDocumentType) const; - void handleFragment(const DocumentFragment* pFragment) const; - void handleNotation(const Notation* pNotation) const; - void handleEntity(const Entity* pEntity) const; - -private: - EntityResolver* _pEntityResolver; - DTDHandler* _pDTDHandler; - ContentHandler* _pContentHandler; - ErrorHandler* _pErrorHandler; - DeclHandler* _pDeclHandler; - LexicalHandler* _pLexicalHandler; - - static const XMLString CDATA; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DOMSerializer_INCLUDED +// +// DOMSerializer.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMSerializer.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMSerializer +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMSerializer_INCLUDED +#define DOM_DOMSerializer_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/XMLReader.h" + + +namespace Poco { +namespace XML { + + +class Node; +class Element; +class Text; +class Comment; +class ProcessingInstruction; +class Entity; +class CDATASection; +class Notation; +class Document; +class DocumentType; +class DocumentFragment; +class DeclHandler; +class LexicalHandler; + + +class XML_API DOMSerializer: public XMLReader + /// The DOMSerializer serializes a DOM document + /// into a sequence of SAX events which are + /// reported to the registered SAX event + /// handlers. + /// + /// The DOMWriter uses a DOMSerializer with an + /// XMLWriter to serialize a DOM document into + /// textual XML. +{ +public: + DOMSerializer(); + /// Creates the DOMSerializer. + + ~DOMSerializer(); + /// Destroys the DOMSerializer. + + void serialize(const Node* pNode); + /// Serializes a DOM node and its children + /// into a sequence of SAX events, which are + /// reported to the registered SAX event + /// handlers. + + // XMLReader + void setEntityResolver(EntityResolver* pResolver); + EntityResolver* getEntityResolver() const; + void setDTDHandler(DTDHandler* pDTDHandler); + DTDHandler* getDTDHandler() const; + void setContentHandler(ContentHandler* pContentHandler); + ContentHandler* getContentHandler() const; + void setErrorHandler(ErrorHandler* pErrorHandler); + ErrorHandler* getErrorHandler() const; + + void setFeature(const XMLString& featureId, bool state); + bool getFeature(const XMLString& featureId) const; + void setProperty(const XMLString& propertyId, const XMLString& value); + void setProperty(const XMLString& propertyId, void* value); + void* getProperty(const XMLString& propertyId) const; + +protected: + void parse(InputSource* pSource); + /// The DOMSerializer cannot parse an InputSource, + /// so this method simply throws an XMLException when invoked. + + void parse(const XMLString& systemId); + /// The DOMSerializer cannot parse from a system identifier, + /// so this method simply throws an XMLException when invoked. + + void parseMemoryNP(const char* xml, std::size_t size); + /// The DOMSerializer cannot parse from a system identifier, + /// so this method simply throws an XMLException when invoked. + + void iterate(const Node* pNode) const; + void handleNode(const Node* pNode) const; + void handleElement(const Element* pElement) const; + void handleCharacterData(const Text* pText) const; + void handleComment(const Comment* pComment) const; + void handlePI(const ProcessingInstruction* pPI) const; + void handleCDATASection(const CDATASection* pCDATA) const; + void handleDocument(const Document* pDocument) const; + void handleDocumentType(const DocumentType* pDocumentType) const; + void handleFragment(const DocumentFragment* pFragment) const; + void handleNotation(const Notation* pNotation) const; + void handleEntity(const Entity* pEntity) const; + +private: + EntityResolver* _pEntityResolver; + DTDHandler* _pDTDHandler; + ContentHandler* _pContentHandler; + ErrorHandler* _pErrorHandler; + DeclHandler* _pDeclHandler; + LexicalHandler* _pLexicalHandler; + + static const XMLString CDATA; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DOMSerializer_INCLUDED diff --git a/XML/include/Poco/DOM/DOMWriter.h b/XML/include/Poco/DOM/DOMWriter.h index 436c66bb3..9d30feeaf 100644 --- a/XML/include/Poco/DOM/DOMWriter.h +++ b/XML/include/Poco/DOM/DOMWriter.h @@ -1,131 +1,131 @@ -// -// DOMWriter.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DOMWriter.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMWriter -// -// Definition of class DOMWriter. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DOMWriter_INCLUDED -#define DOM_DOMWriter_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/XMLStream.h" -#include "Poco/TextEncoding.h" - - -namespace Poco { -namespace XML { - - -class Node; -class Document; - - -class XML_API DOMWriter - /// The DOMWriter uses a DOMSerializer with an - /// XMLWriter to serialize a DOM document into - /// textual XML. -{ -public: - DOMWriter(); - /// Creates a DOMWriter. - - ~DOMWriter(); - /// Destroys a DOMWriter. - - void setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding); - /// Sets the encoding, which will be reflected in the written XML declaration. - - const std::string& getEncoding() const; - /// Returns the encoding name set with setEncoding. - - void setOptions(int options); - /// Sets options for the internal XMLWriter. - /// - /// See class XMLWriter for available options. - - int getOptions() const; - /// Returns the options for the internal XMLWriter. - - void setNewLine(const std::string& newLine); - /// Sets the line ending characters for the internal - /// XMLWriter. See XMLWriter::setNewLine() for a list - /// of supported values. - - const std::string& getNewLine() const; - /// Returns the line ending characters used by the - /// internal XMLWriter. - - void writeNode(XMLByteOutputStream& ostr, const Node* pNode); - /// Writes the XML for the given node to the specified stream. - - void writeNode(const std::string& systemId, const Node* pNode); - /// Writes the XML for the given node to the file specified in systemId, - /// using a standard file output stream (Poco::FileOutputStream). - -private: - std::string _encodingName; - Poco::TextEncoding* _pTextEncoding; - int _options; - std::string _newLine; -}; - - -// -// inlines -// -inline const std::string& DOMWriter::getEncoding() const -{ - return _encodingName; -} - - -inline int DOMWriter::getOptions() const -{ - return _options; -} - - -inline const std::string& DOMWriter::getNewLine() const -{ - return _newLine; -} - - -} } // namespace Poco::XML - - -#endif // DOM_DOMWriter_INCLUDED +// +// DOMWriter.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DOMWriter.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMWriter +// +// Definition of class DOMWriter. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DOMWriter_INCLUDED +#define DOM_DOMWriter_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/XMLStream.h" +#include "Poco/TextEncoding.h" + + +namespace Poco { +namespace XML { + + +class Node; +class Document; + + +class XML_API DOMWriter + /// The DOMWriter uses a DOMSerializer with an + /// XMLWriter to serialize a DOM document into + /// textual XML. +{ +public: + DOMWriter(); + /// Creates a DOMWriter. + + ~DOMWriter(); + /// Destroys a DOMWriter. + + void setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding); + /// Sets the encoding, which will be reflected in the written XML declaration. + + const std::string& getEncoding() const; + /// Returns the encoding name set with setEncoding. + + void setOptions(int options); + /// Sets options for the internal XMLWriter. + /// + /// See class XMLWriter for available options. + + int getOptions() const; + /// Returns the options for the internal XMLWriter. + + void setNewLine(const std::string& newLine); + /// Sets the line ending characters for the internal + /// XMLWriter. See XMLWriter::setNewLine() for a list + /// of supported values. + + const std::string& getNewLine() const; + /// Returns the line ending characters used by the + /// internal XMLWriter. + + void writeNode(XMLByteOutputStream& ostr, const Node* pNode); + /// Writes the XML for the given node to the specified stream. + + void writeNode(const std::string& systemId, const Node* pNode); + /// Writes the XML for the given node to the file specified in systemId, + /// using a standard file output stream (Poco::FileOutputStream). + +private: + std::string _encodingName; + Poco::TextEncoding* _pTextEncoding; + int _options; + std::string _newLine; +}; + + +// +// inlines +// +inline const std::string& DOMWriter::getEncoding() const +{ + return _encodingName; +} + + +inline int DOMWriter::getOptions() const +{ + return _options; +} + + +inline const std::string& DOMWriter::getNewLine() const +{ + return _newLine; +} + + +} } // namespace Poco::XML + + +#endif // DOM_DOMWriter_INCLUDED diff --git a/XML/include/Poco/DOM/DTDMap.h b/XML/include/Poco/DOM/DTDMap.h index 0f4c6a50e..c6d37d4a1 100644 --- a/XML/include/Poco/DOM/DTDMap.h +++ b/XML/include/Poco/DOM/DTDMap.h @@ -1,89 +1,89 @@ -// -// DTDMap.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DTDMap.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DTDMap class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DTDMap_INCLUDED -#define DOM_DTDMap_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/NamedNodeMap.h" - - -namespace Poco { -namespace XML { - - -class DocumentType; - - -class XML_API DTDMap: public NamedNodeMap - /// This implementation of NamedNodeMap - /// is returned by DocumentType::entities() - /// and DocumentType::notations(). -{ -public: - Node* getNamedItem(const XMLString& name) const; - Node* setNamedItem(Node* arg); - Node* removeNamedItem(const XMLString& name); - Node* item(unsigned long index) const; - unsigned long length() const; - - Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const; - Node* setNamedItemNS(Node* arg); - Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName); - - void autoRelease(); - -protected: - DTDMap(const DocumentType* pDocumentType, unsigned short type); - ~DTDMap(); - -private: - DTDMap(); - - const DocumentType* _pDocumentType; - unsigned short _type; - - friend class DocumentType; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DTDMap_INCLUDED +// +// DTDMap.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DTDMap.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DTDMap class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DTDMap_INCLUDED +#define DOM_DTDMap_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/NamedNodeMap.h" + + +namespace Poco { +namespace XML { + + +class DocumentType; + + +class XML_API DTDMap: public NamedNodeMap + /// This implementation of NamedNodeMap + /// is returned by DocumentType::entities() + /// and DocumentType::notations(). +{ +public: + Node* getNamedItem(const XMLString& name) const; + Node* setNamedItem(Node* arg); + Node* removeNamedItem(const XMLString& name); + Node* item(unsigned long index) const; + unsigned long length() const; + + Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const; + Node* setNamedItemNS(Node* arg); + Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName); + + void autoRelease(); + +protected: + DTDMap(const DocumentType* pDocumentType, unsigned short type); + ~DTDMap(); + +private: + DTDMap(); + + const DocumentType* _pDocumentType; + unsigned short _type; + + friend class DocumentType; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DTDMap_INCLUDED diff --git a/XML/include/Poco/DOM/Document.h b/XML/include/Poco/DOM/Document.h index c9e2c843a..0363ed0b5 100644 --- a/XML/include/Poco/DOM/Document.h +++ b/XML/include/Poco/DOM/Document.h @@ -1,299 +1,299 @@ -// -// Document.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Document.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Document class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Document_INCLUDED -#define DOM_Document_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractContainerNode.h" -#include "Poco/DOM/DocumentEvent.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/NamePool.h" -#include "Poco/AutoReleasePool.h" - - -namespace Poco { -namespace XML { - - -class NamePool; -class DocumentType; -class DOMImplementation; -class Element; -class DocumentFragment; -class Text; -class Comment; -class CDATASection; -class ProcessingInstruction; -class Attr; -class EntityReference; -class NodeList; -class Entity; -class Notation; - - -class XML_API Document: public AbstractContainerNode, public DocumentEvent - /// The Document interface represents the entire HTML or XML document. Conceptually, - /// it is the root of the document tree, and provides the primary access to the - /// document's data. - /// - /// Since elements, text nodes, comments, processing instructions, etc. cannot exist - /// outside the context of a Document, the Document interface also contains the - /// factory methods needed to create these objects. The Node objects created have a - /// ownerDocument attribute which associates them with the Document within whose - /// context they were created. -{ -public: - typedef Poco::AutoReleasePool AutoReleasePool; - - Document(NamePool* pNamePool = 0); - /// Creates a new document. If pNamePool == 0, the document - /// creates its own name pool, otherwise it uses the given name pool. - /// Sharing a name pool makes sense for documents containing instances - /// of the same schema, thus reducing memory usage. - - Document(DocumentType* pDocumentType, NamePool* pNamePool = 0); - /// Creates a new document. If pNamePool == 0, the document - /// creates its own name pool, otherwise it uses the given name pool. - /// Sharing a name pool makes sense for documents containing instances - /// of the same schema, thus reducing memory usage. - - NamePool& namePool(); - /// Returns a pointer to the documents Name Pool. - - AutoReleasePool& autoReleasePool(); - /// Returns a pointer to the documents Auto Release Pool. - - void collectGarbage(); - /// Releases all objects in the Auto Release Pool. - - void suspendEvents(); - /// Suspends all events until resumeEvents() is called. - - void resumeEvents(); - /// Resumes all events suspended with suspendEvent(); - - bool eventsSuspended() const; - /// Returns true if events are suspeded. - - bool events() const; - /// Returns true if events are not suspeded. - - const DocumentType* doctype() const; - /// The Document Type Declaration (see DocumentType) associated with this document. - /// For HTML documents as well as XML documents without a document type declaration - /// this returns null. The DOM Level 1 does not support editing the Document - /// Type Declaration. docType cannot be altered in any way, including through - /// the use of methods inherited from the Node interface, such as insertNode - /// or removeNode. - - const DOMImplementation& implementation() const; - /// The DOMImplementation object that handles this document. A DOM application - /// may use objects from multiple implementations. - - Element* documentElement() const; - /// This is a convenience attribute that allows direct access to the child node - /// that is the root element of the document. For HTML documents, this is the - /// element with the tagName "HTML". - - Element* createElement(const XMLString& tagName) const; - /// Creates an element of the type specified. Note that the instance returned - /// implements the Element interface, so attributes can be specified directly - /// on the returned object. - /// - /// In addition, if there are known attributes with default values, Attr nodes - /// representing them are automatically created and attached to the element. - - DocumentFragment* createDocumentFragment() const; - /// Creates an empty DocumentFragment object. - - Text* createTextNode(const XMLString& data) const; - /// Creates a text node given the specified string. - - Comment* createComment(const XMLString& data) const; - /// Creates a comment node given the specified string. - - CDATASection* createCDATASection(const XMLString& data) const; - /// Creates a CDATASection node whose value is the specified string. - - ProcessingInstruction* createProcessingInstruction(const XMLString& target, const XMLString& data) const; - /// Creates a ProcessingInstruction node given the specified target and data strings. - - Attr* createAttribute(const XMLString& name) const; - /// Creates an Attr of the given name. Note that the Attr instance can then - /// be set on an Element using the setAttributeNode method. - - EntityReference* createEntityReference(const XMLString& name) const; - /// Creates an EntityReference object. In addition, if the referenced entity - /// is known, the child list of the EntityReference node is made the same as - /// that of the corresponding Entity node. - - NodeList* getElementsByTagName(const XMLString& name) const; - /// Returns a NodeList of all Elements with a given tag name in the order - /// in which they would be encountered in a preorder traversal of the - /// document tree. - /// - /// The returned NodeList must be released with a call to release() - /// when no longer needed. - - // DOM Level 2 - Node* importNode(Node* importedNode, bool deep); - /// Imports a node from another document to this document. The returned node - /// has no parent; (parentNode is null). The source node is not altered or removed - /// from the original document; this method creates a new copy of the source - /// node. - /// For all nodes, importing a node creates a node object owned by the importing - /// document, with attribute values identical to the source node's nodeName - /// and nodeType, plus the attributes related to namespaces (prefix, localName, - /// and namespaceURI). As in the cloneNode operation on a Node, the source node - /// is not altered. - /// Additional information is copied as appropriate to the nodeType, attempting - /// to mirror the behavior expected if a fragment of XML or HTML source was - /// copied from one document to another, recognizing that the two documents - /// may have different DTDs in the XML case. - - Element* createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const; - /// Creates an element of the given qualified name and namespace URI. - - Attr* createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const; - /// Creates an attribute of the given qualified name and namespace URI. - - NodeList* getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns a NodeList of all the Elements with a given local name and - /// namespace URI in the order in which they are encountered in a - /// preorder traversal of the Document tree. - - Element* getElementById(const XMLString& elementId) const; - /// Returns the Element whose ID is given by elementId. If no such - /// element exists, returns null. Behavior is not defined if more - /// than one element has this ID. - /// - /// Note: The DOM implementation must have information that says - /// which attributes are of type ID. Attributes with the name "ID" - /// are not of type ID unless so defined. Implementations that do - /// not know whether attributes are of type ID or not are expected to - /// return null. This implementation therefore returns null. - /// - /// See also the non-standard two argument variant of getElementById() - /// and getElementByIdNS(). - - // DocumentEvent - Event* createEvent(const XMLString& eventType) const; - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - - // EventTarget - bool dispatchEvent(Event* evt); - - // Extensions - Entity* createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const; - /// Creates an Entity with the given name, publicId, systemId and notationName. - /// - /// This method is not part of the W3C Document Object Model. - - Notation* createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const; - /// Creates a Notation with the given name, publicId and systemId. - /// - /// This method is not part of the W3C Document Object Model. - - Element* getElementById(const XMLString& elementId, const XMLString& idAttribute) const; - /// Returns the first Element whose ID attribute (given in idAttribute) - /// has the given elementId. If no such element exists, returns null. - /// - /// This method is an extension to the W3C Document Object Model. - - Element* getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const; - /// Returns the first Element whose ID attribute (given in idAttributeURI and idAttributeLocalName) - /// has the given elementId. If no such element exists, returns null. - /// - /// This method is an extension to the W3C Document Object Model. - -protected: - ~Document(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - - DocumentType* getDoctype(); - void setDoctype(DocumentType* pDoctype); - -private: - DocumentType* _pDocumentType; - NamePool* _pNamePool; - AutoReleasePool _autoReleasePool; - int _eventSuspendLevel; - - static const XMLString NODE_NAME; - - friend class DOMBuilder; -}; - - -// -// inlines -// -inline NamePool& Document::namePool() -{ - return *_pNamePool; -} - - -inline Document::AutoReleasePool& Document::autoReleasePool() -{ - return _autoReleasePool; -} - - -inline const DocumentType* Document::doctype() const -{ - return _pDocumentType; -} - - -inline DocumentType* Document::getDoctype() -{ - return _pDocumentType; -} - - -} } // namespace Poco::XML - - -#endif // DOM_Document_INCLUDED +// +// Document.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Document.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Document class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Document_INCLUDED +#define DOM_Document_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractContainerNode.h" +#include "Poco/DOM/DocumentEvent.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/NamePool.h" +#include "Poco/AutoReleasePool.h" + + +namespace Poco { +namespace XML { + + +class NamePool; +class DocumentType; +class DOMImplementation; +class Element; +class DocumentFragment; +class Text; +class Comment; +class CDATASection; +class ProcessingInstruction; +class Attr; +class EntityReference; +class NodeList; +class Entity; +class Notation; + + +class XML_API Document: public AbstractContainerNode, public DocumentEvent + /// The Document interface represents the entire HTML or XML document. Conceptually, + /// it is the root of the document tree, and provides the primary access to the + /// document's data. + /// + /// Since elements, text nodes, comments, processing instructions, etc. cannot exist + /// outside the context of a Document, the Document interface also contains the + /// factory methods needed to create these objects. The Node objects created have a + /// ownerDocument attribute which associates them with the Document within whose + /// context they were created. +{ +public: + typedef Poco::AutoReleasePool AutoReleasePool; + + Document(NamePool* pNamePool = 0); + /// Creates a new document. If pNamePool == 0, the document + /// creates its own name pool, otherwise it uses the given name pool. + /// Sharing a name pool makes sense for documents containing instances + /// of the same schema, thus reducing memory usage. + + Document(DocumentType* pDocumentType, NamePool* pNamePool = 0); + /// Creates a new document. If pNamePool == 0, the document + /// creates its own name pool, otherwise it uses the given name pool. + /// Sharing a name pool makes sense for documents containing instances + /// of the same schema, thus reducing memory usage. + + NamePool& namePool(); + /// Returns a pointer to the documents Name Pool. + + AutoReleasePool& autoReleasePool(); + /// Returns a pointer to the documents Auto Release Pool. + + void collectGarbage(); + /// Releases all objects in the Auto Release Pool. + + void suspendEvents(); + /// Suspends all events until resumeEvents() is called. + + void resumeEvents(); + /// Resumes all events suspended with suspendEvent(); + + bool eventsSuspended() const; + /// Returns true if events are suspeded. + + bool events() const; + /// Returns true if events are not suspeded. + + const DocumentType* doctype() const; + /// The Document Type Declaration (see DocumentType) associated with this document. + /// For HTML documents as well as XML documents without a document type declaration + /// this returns null. The DOM Level 1 does not support editing the Document + /// Type Declaration. docType cannot be altered in any way, including through + /// the use of methods inherited from the Node interface, such as insertNode + /// or removeNode. + + const DOMImplementation& implementation() const; + /// The DOMImplementation object that handles this document. A DOM application + /// may use objects from multiple implementations. + + Element* documentElement() const; + /// This is a convenience attribute that allows direct access to the child node + /// that is the root element of the document. For HTML documents, this is the + /// element with the tagName "HTML". + + Element* createElement(const XMLString& tagName) const; + /// Creates an element of the type specified. Note that the instance returned + /// implements the Element interface, so attributes can be specified directly + /// on the returned object. + /// + /// In addition, if there are known attributes with default values, Attr nodes + /// representing them are automatically created and attached to the element. + + DocumentFragment* createDocumentFragment() const; + /// Creates an empty DocumentFragment object. + + Text* createTextNode(const XMLString& data) const; + /// Creates a text node given the specified string. + + Comment* createComment(const XMLString& data) const; + /// Creates a comment node given the specified string. + + CDATASection* createCDATASection(const XMLString& data) const; + /// Creates a CDATASection node whose value is the specified string. + + ProcessingInstruction* createProcessingInstruction(const XMLString& target, const XMLString& data) const; + /// Creates a ProcessingInstruction node given the specified target and data strings. + + Attr* createAttribute(const XMLString& name) const; + /// Creates an Attr of the given name. Note that the Attr instance can then + /// be set on an Element using the setAttributeNode method. + + EntityReference* createEntityReference(const XMLString& name) const; + /// Creates an EntityReference object. In addition, if the referenced entity + /// is known, the child list of the EntityReference node is made the same as + /// that of the corresponding Entity node. + + NodeList* getElementsByTagName(const XMLString& name) const; + /// Returns a NodeList of all Elements with a given tag name in the order + /// in which they would be encountered in a preorder traversal of the + /// document tree. + /// + /// The returned NodeList must be released with a call to release() + /// when no longer needed. + + // DOM Level 2 + Node* importNode(Node* importedNode, bool deep); + /// Imports a node from another document to this document. The returned node + /// has no parent; (parentNode is null). The source node is not altered or removed + /// from the original document; this method creates a new copy of the source + /// node. + /// For all nodes, importing a node creates a node object owned by the importing + /// document, with attribute values identical to the source node's nodeName + /// and nodeType, plus the attributes related to namespaces (prefix, localName, + /// and namespaceURI). As in the cloneNode operation on a Node, the source node + /// is not altered. + /// Additional information is copied as appropriate to the nodeType, attempting + /// to mirror the behavior expected if a fragment of XML or HTML source was + /// copied from one document to another, recognizing that the two documents + /// may have different DTDs in the XML case. + + Element* createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const; + /// Creates an element of the given qualified name and namespace URI. + + Attr* createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const; + /// Creates an attribute of the given qualified name and namespace URI. + + NodeList* getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns a NodeList of all the Elements with a given local name and + /// namespace URI in the order in which they are encountered in a + /// preorder traversal of the Document tree. + + Element* getElementById(const XMLString& elementId) const; + /// Returns the Element whose ID is given by elementId. If no such + /// element exists, returns null. Behavior is not defined if more + /// than one element has this ID. + /// + /// Note: The DOM implementation must have information that says + /// which attributes are of type ID. Attributes with the name "ID" + /// are not of type ID unless so defined. Implementations that do + /// not know whether attributes are of type ID or not are expected to + /// return null. This implementation therefore returns null. + /// + /// See also the non-standard two argument variant of getElementById() + /// and getElementByIdNS(). + + // DocumentEvent + Event* createEvent(const XMLString& eventType) const; + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + + // EventTarget + bool dispatchEvent(Event* evt); + + // Extensions + Entity* createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const; + /// Creates an Entity with the given name, publicId, systemId and notationName. + /// + /// This method is not part of the W3C Document Object Model. + + Notation* createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const; + /// Creates a Notation with the given name, publicId and systemId. + /// + /// This method is not part of the W3C Document Object Model. + + Element* getElementById(const XMLString& elementId, const XMLString& idAttribute) const; + /// Returns the first Element whose ID attribute (given in idAttribute) + /// has the given elementId. If no such element exists, returns null. + /// + /// This method is an extension to the W3C Document Object Model. + + Element* getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const; + /// Returns the first Element whose ID attribute (given in idAttributeURI and idAttributeLocalName) + /// has the given elementId. If no such element exists, returns null. + /// + /// This method is an extension to the W3C Document Object Model. + +protected: + ~Document(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + + DocumentType* getDoctype(); + void setDoctype(DocumentType* pDoctype); + +private: + DocumentType* _pDocumentType; + NamePool* _pNamePool; + AutoReleasePool _autoReleasePool; + int _eventSuspendLevel; + + static const XMLString NODE_NAME; + + friend class DOMBuilder; +}; + + +// +// inlines +// +inline NamePool& Document::namePool() +{ + return *_pNamePool; +} + + +inline Document::AutoReleasePool& Document::autoReleasePool() +{ + return _autoReleasePool; +} + + +inline const DocumentType* Document::doctype() const +{ + return _pDocumentType; +} + + +inline DocumentType* Document::getDoctype() +{ + return _pDocumentType; +} + + +} } // namespace Poco::XML + + +#endif // DOM_Document_INCLUDED diff --git a/XML/include/Poco/DOM/DocumentEvent.h b/XML/include/Poco/DOM/DocumentEvent.h index 7ab5ac4dd..20836fca8 100644 --- a/XML/include/Poco/DOM/DocumentEvent.h +++ b/XML/include/Poco/DOM/DocumentEvent.h @@ -1,87 +1,87 @@ -// -// DocumentEvent.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentEvent.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM DocumentEvent interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DocumentEvent_INCLUDED -#define DOM_DocumentEvent_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Event; - - -class XML_API DocumentEvent - /// The DocumentEvent interface provides a mechanism by which the user can create - /// an Event of a type supported by the implementation. It is expected that - /// the DocumentEvent interface will be implemented on the same object which - /// implements the Document interface in an implementation which supports the - /// Event model. -{ -public: - virtual Event* createEvent(const XMLString& eventType) const = 0; - /// Creates an event of the specified type. - /// - /// The eventType parameter specifies the type of Event interface to be created. - /// If the Event interface specified is supported by the implementation this - /// method will return a new Event of the interface type requested. If the Event - /// is to be dispatched via the dispatchEvent method the appropriate event init - /// method must be called after creation in order to initialize the Event's - /// values. As an example, a user wishing to synthesize some kind of UIEvent - /// would call createEvent with the parameter "UIEvents". The initUIEvent method - /// could then be called on the newly created UIEvent to set the specific type - /// of UIEvent to be dispatched and set its context information. - /// The createEvent method is used in creating Events when it is either inconvenient - /// or unnecessary for the user to create an Event themselves. In cases where - /// the implementation provided Event is insufficient, users may supply their - /// own Event implementations for use with the dispatchEvent method. - -protected: - virtual ~DocumentEvent(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DocumentEvent_INCLUDED +// +// DocumentEvent.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentEvent.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM DocumentEvent interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DocumentEvent_INCLUDED +#define DOM_DocumentEvent_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Event; + + +class XML_API DocumentEvent + /// The DocumentEvent interface provides a mechanism by which the user can create + /// an Event of a type supported by the implementation. It is expected that + /// the DocumentEvent interface will be implemented on the same object which + /// implements the Document interface in an implementation which supports the + /// Event model. +{ +public: + virtual Event* createEvent(const XMLString& eventType) const = 0; + /// Creates an event of the specified type. + /// + /// The eventType parameter specifies the type of Event interface to be created. + /// If the Event interface specified is supported by the implementation this + /// method will return a new Event of the interface type requested. If the Event + /// is to be dispatched via the dispatchEvent method the appropriate event init + /// method must be called after creation in order to initialize the Event's + /// values. As an example, a user wishing to synthesize some kind of UIEvent + /// would call createEvent with the parameter "UIEvents". The initUIEvent method + /// could then be called on the newly created UIEvent to set the specific type + /// of UIEvent to be dispatched and set its context information. + /// The createEvent method is used in creating Events when it is either inconvenient + /// or unnecessary for the user to create an Event themselves. In cases where + /// the implementation provided Event is insufficient, users may supply their + /// own Event implementations for use with the dispatchEvent method. + +protected: + virtual ~DocumentEvent(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DocumentEvent_INCLUDED diff --git a/XML/include/Poco/DOM/DocumentFragment.h b/XML/include/Poco/DOM/DocumentFragment.h index 07bb4c30e..a7bb87faf 100644 --- a/XML/include/Poco/DOM/DocumentFragment.h +++ b/XML/include/Poco/DOM/DocumentFragment.h @@ -1,106 +1,106 @@ -// -// DocumentFragment.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentFragment.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM DocumentFragment class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DocumentFragment_INCLUDED -#define DOM_DocumentFragment_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractContainerNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API DocumentFragment: public AbstractContainerNode - /// DocumentFragment is a "lightweight" or "minimal" Document object. It is - /// very common to want to be able to extract a portion of a document's tree - /// or to create a new fragment of a document. Imagine implementing a user command - /// like cut or rearranging a document by moving fragments around. It is desirable - /// to have an object which can hold such fragments and it is quite natural - /// to use a Node for this purpose. While it is true that a Document object - /// could fulfill this role, a Document object can potentially be a heavyweight - /// object, depending on the underlying implementation. What is really needed - /// for this is a very lightweight object. DocumentFragment is such an object. - /// - /// Furthermore, various operations -- such as inserting nodes as children of - /// another Node -- may take DocumentFragment objects as arguments; this results - /// in all the child nodes of the DocumentFragment being moved to the child - /// list of this node. - /// - /// The children of a DocumentFragment node are zero or more nodes representing - /// the tops of any sub-trees defining the structure of the document. DocumentFragment - /// nodes do not need to be well-formed XML documents (although they do need - /// to follow the rules imposed upon well-formed XML parsed entities, which - /// can have multiple top nodes). For example, a DocumentFragment might have - /// only one child and that child node could be a Text node. Such a structure - /// model represents neither an HTML document nor a well-formed XML document. - /// - /// When a DocumentFragment is inserted into a Document (or indeed any other - /// Node that may take children) the children of the DocumentFragment and not - /// the DocumentFragment itself are inserted into the Node. This makes the DocumentFragment - /// very useful when the user wishes to create nodes that are siblings; the - /// DocumentFragment acts as the parent of these nodes so that the user can - /// use the standard methods from the Node interface, such as insertBefore and - /// appendChild. -{ -public: - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - DocumentFragment(Document* pOwnerDocument); - DocumentFragment(Document* pOwnerDocument, const DocumentFragment& fragment); - ~DocumentFragment(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - static const XMLString NODE_NAME; - - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_DocumentFragment_INCLUDED +// +// DocumentFragment.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentFragment.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM DocumentFragment class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DocumentFragment_INCLUDED +#define DOM_DocumentFragment_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractContainerNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API DocumentFragment: public AbstractContainerNode + /// DocumentFragment is a "lightweight" or "minimal" Document object. It is + /// very common to want to be able to extract a portion of a document's tree + /// or to create a new fragment of a document. Imagine implementing a user command + /// like cut or rearranging a document by moving fragments around. It is desirable + /// to have an object which can hold such fragments and it is quite natural + /// to use a Node for this purpose. While it is true that a Document object + /// could fulfill this role, a Document object can potentially be a heavyweight + /// object, depending on the underlying implementation. What is really needed + /// for this is a very lightweight object. DocumentFragment is such an object. + /// + /// Furthermore, various operations -- such as inserting nodes as children of + /// another Node -- may take DocumentFragment objects as arguments; this results + /// in all the child nodes of the DocumentFragment being moved to the child + /// list of this node. + /// + /// The children of a DocumentFragment node are zero or more nodes representing + /// the tops of any sub-trees defining the structure of the document. DocumentFragment + /// nodes do not need to be well-formed XML documents (although they do need + /// to follow the rules imposed upon well-formed XML parsed entities, which + /// can have multiple top nodes). For example, a DocumentFragment might have + /// only one child and that child node could be a Text node. Such a structure + /// model represents neither an HTML document nor a well-formed XML document. + /// + /// When a DocumentFragment is inserted into a Document (or indeed any other + /// Node that may take children) the children of the DocumentFragment and not + /// the DocumentFragment itself are inserted into the Node. This makes the DocumentFragment + /// very useful when the user wishes to create nodes that are siblings; the + /// DocumentFragment acts as the parent of these nodes so that the user can + /// use the standard methods from the Node interface, such as insertBefore and + /// appendChild. +{ +public: + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + DocumentFragment(Document* pOwnerDocument); + DocumentFragment(Document* pOwnerDocument, const DocumentFragment& fragment); + ~DocumentFragment(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + static const XMLString NODE_NAME; + + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_DocumentFragment_INCLUDED diff --git a/XML/include/Poco/DOM/DocumentType.h b/XML/include/Poco/DOM/DocumentType.h index 055e2c93c..3faec54a6 100644 --- a/XML/include/Poco/DOM/DocumentType.h +++ b/XML/include/Poco/DOM/DocumentType.h @@ -1,147 +1,147 @@ -// -// DocumentType.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentType.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM DocumentType class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_DocumentType_INCLUDED -#define DOM_DocumentType_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractContainerNode.h" - - -namespace Poco { -namespace XML { - - -class NamedNodeMap; - - -class XML_API DocumentType: public AbstractContainerNode - /// Each Document has a doctype attribute whose value is either null or a DocumentType - /// object. The DocumentType interface in the DOM Level 1 Core provides an - /// interface to the list of entities that are defined for the document, and - /// little else because the effect of namespaces and the various XML scheme - /// efforts on DTD representation are not clearly understood as of this writing. - /// - /// The DOM Level 1 doesn't support editing DocumentType nodes. -{ -public: - const XMLString& name() const; - /// The name of the DTD; i.e., the name immediately following the - /// DOCTYPE keyword. - - NamedNodeMap* entities() const; - /// A NamedNodeMap containing the general entities, - /// both external and internal, declared in the DTD. - /// Duplicates are discarded. - /// - /// Note: In this implementation, only the - /// external entities are reported. - /// Every node in this map also implements the - /// Entity interface. - /// - /// The returned NamedNodeMap must be released with a call - /// to release() when no longer needed. - - NamedNodeMap* notations() const; - /// A NamedNodeMap containing the notations declared in the DTD. Duplicates - /// are discarded. Every node in this map also implements the Notation interface. - /// The DOM Level 1 does not support editing notations, therefore notations - /// cannot be altered in any way. - /// - /// The returned NamedNodeMap must be released with a call - /// to release() when no longer needed. - - // DOM Level 2 - const XMLString& publicId() const; - /// Returns the public identifier of the external DTD subset. - - const XMLString& systemId() const; - /// Returns the system identifier of the external DTD subset. - - const XMLString& internalSubset() const; - /// Returns the internal DTD subset. This implementation - /// returns an empty string. - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - DocumentType(Document* pOwner, const XMLString& name, const XMLString& publicId, const XMLString& systemId); - DocumentType(Document* pOwner, const DocumentType& dt); - ~DocumentType(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - XMLString _name; - XMLString _publicId; - XMLString _systemId; - - friend class DOMImplementation; - friend class Document; - friend class DOMBuilder; -}; - - -// -// inlines -// -inline const XMLString& DocumentType::name() const -{ - return _name; -} - - -inline const XMLString& DocumentType::publicId() const -{ - return _publicId; -} - - -inline const XMLString& DocumentType::systemId() const -{ - return _systemId; -} - - -} } // namespace Poco::XML - - -#endif // DOM_DocumentType_INCLUDED +// +// DocumentType.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/DocumentType.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM DocumentType class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_DocumentType_INCLUDED +#define DOM_DocumentType_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractContainerNode.h" + + +namespace Poco { +namespace XML { + + +class NamedNodeMap; + + +class XML_API DocumentType: public AbstractContainerNode + /// Each Document has a doctype attribute whose value is either null or a DocumentType + /// object. The DocumentType interface in the DOM Level 1 Core provides an + /// interface to the list of entities that are defined for the document, and + /// little else because the effect of namespaces and the various XML scheme + /// efforts on DTD representation are not clearly understood as of this writing. + /// + /// The DOM Level 1 doesn't support editing DocumentType nodes. +{ +public: + const XMLString& name() const; + /// The name of the DTD; i.e., the name immediately following the + /// DOCTYPE keyword. + + NamedNodeMap* entities() const; + /// A NamedNodeMap containing the general entities, + /// both external and internal, declared in the DTD. + /// Duplicates are discarded. + /// + /// Note: In this implementation, only the + /// external entities are reported. + /// Every node in this map also implements the + /// Entity interface. + /// + /// The returned NamedNodeMap must be released with a call + /// to release() when no longer needed. + + NamedNodeMap* notations() const; + /// A NamedNodeMap containing the notations declared in the DTD. Duplicates + /// are discarded. Every node in this map also implements the Notation interface. + /// The DOM Level 1 does not support editing notations, therefore notations + /// cannot be altered in any way. + /// + /// The returned NamedNodeMap must be released with a call + /// to release() when no longer needed. + + // DOM Level 2 + const XMLString& publicId() const; + /// Returns the public identifier of the external DTD subset. + + const XMLString& systemId() const; + /// Returns the system identifier of the external DTD subset. + + const XMLString& internalSubset() const; + /// Returns the internal DTD subset. This implementation + /// returns an empty string. + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + DocumentType(Document* pOwner, const XMLString& name, const XMLString& publicId, const XMLString& systemId); + DocumentType(Document* pOwner, const DocumentType& dt); + ~DocumentType(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + XMLString _name; + XMLString _publicId; + XMLString _systemId; + + friend class DOMImplementation; + friend class Document; + friend class DOMBuilder; +}; + + +// +// inlines +// +inline const XMLString& DocumentType::name() const +{ + return _name; +} + + +inline const XMLString& DocumentType::publicId() const +{ + return _publicId; +} + + +inline const XMLString& DocumentType::systemId() const +{ + return _systemId; +} + + +} } // namespace Poco::XML + + +#endif // DOM_DocumentType_INCLUDED diff --git a/XML/include/Poco/DOM/Element.h b/XML/include/Poco/DOM/Element.h index 7578f8366..6f6a3d5f4 100644 --- a/XML/include/Poco/DOM/Element.h +++ b/XML/include/Poco/DOM/Element.h @@ -1,243 +1,243 @@ -// -// Element.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Element.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Element class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Element_INCLUDED -#define DOM_Element_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractContainerNode.h" -#include "Poco/XML/Name.h" - - -namespace Poco { -namespace XML { - - -class Attr; -class NodeList; -class Document; - - -class XML_API Element: public AbstractContainerNode - /// The Element interface represents an element in an XML document. - /// Elements may have attributes associated with them; since the Element interface - /// inherits from Node, the generic Node interface attribute attributes may - /// be used to retrieve the set of all attributes for an element. There are - /// methods on the Element interface to retrieve either an Attr object by name - /// or an attribute value by name. In XML, where an attribute value may contain - /// entity references, an Attr object should be retrieved to examine the possibly - /// fairly complex sub-tree representing the attribute value. -{ -public: - const XMLString& tagName() const; - /// Returns the name of the element. - /// - /// For example, in - /// - /// - /// ... - /// - /// - /// tagName has the value "elementExample". Note that this is case-preserving in XML, - /// as are all of the operations of the DOM. - - const XMLString& getAttribute(const XMLString& name) const; - /// Retrieves an attribute value by name. - /// - /// Returns the attribute's value, if the attribute - /// exists, or an empty string otherwise. - - void setAttribute(const XMLString& name, const XMLString& value); - /// Adds a new attribute. If an attribute with that name is already present - /// in the element, its value is changed to be that of the value parameter. - /// This value is a simple string; it is not parsed as it is being set. So any - /// markup (such as syntax to be recognized as an entity reference) is treated - /// as literal text, and needs to be appropriately escaped by the implementation - /// when it is written out. - - void removeAttribute(const XMLString& name); - /// Removes an attribute by name. - - Attr* getAttributeNode(const XMLString& name) const; - /// Retrieves an Attr node by name. - - Attr* setAttributeNode(Attr* newAttr); - /// Adds a new attribute. If an attribute with that name is already - /// present in the element, it is replaced by the new one. - - Attr* addAttributeNodeNP(Attr* oldAttr, Attr* newAttr); - /// For internal use only. - /// Adds a new attribute after oldAttr. - /// If oldAttr is 0, newAttr is set as first attribute. - /// Returns newAttr. - /// Does not fire any events. - - Attr* removeAttributeNode(Attr* oldAttr); - /// Removes the specified attribute. - - NodeList* getElementsByTagName(const XMLString& name) const; - /// Returns a NodeList of all descendant elements with a given tag - /// name, in the order in which they would be encountered in a - /// preorder traversal of the Element tree. - /// - /// The special name "*" matches all tags. - /// - /// The returned NodeList must be released with a call - /// to release() when no longer needed. - - void normalize(); - /// Puts all Text nodes in the full depth of the sub-tree underneath this Element, - /// including attribute nodes, into a "normal" form where only markup (e.g., - /// tags, comments, processing instructions, CDATA sections, and entity references) - /// separates Text nodes, i.e., there are no adjacent Text nodes. This can be - /// used to ensure that the DOM view of a document is the same as if it were - /// saved and re-loaded, and is useful when operations (such as XPointer - /// lookups) that depend on a particular document tree structure are to be used. - /// - /// Note: In cases where the document contains CDATASections, the normalize - /// operation alone may not be sufficient, since XPointers do not differentiate - /// between Text nodes and CDATASection nodes. - - // DOM Level 2 - const XMLString& getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Retrieves an attribute value by name. - /// - /// Returns the attribute's value, if the attribute - /// exists, or an empty string otherwise. - - void setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value); - /// Adds a new attribute. If an attribute with that name - /// is already present in the element, its value is changed - /// to be that of the value parameter. - - void removeAttributeNS(const XMLString& namespaceURI, const XMLString& localName); - /// Removes an attribute by name. - - Attr* getAttributeNodeNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Retrieves an Attr node by name. - - Attr* setAttributeNodeNS(Attr* newAttr); - /// Adds a new attribute. If an attribute with that name is already - /// present in the element, it is replaced by the new one. - - bool hasAttribute(const XMLString& name) const; - /// Returns true if and only if the element has the specified attribute. - - bool hasAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns true if and only if the element has the specified attribute. - - NodeList* getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns a NodeList of all the descendant Elements with a given local name and namespace URI - /// in the order in which they are encountered in a preorder traversal of this Element tree. - /// - /// The special value "*" matches all namespaces, or local names respectively. - /// - /// The returned NodeList must be released with a call - /// to release() when no longer needed. - - const XMLString& namespaceURI() const; - XMLString prefix() const; - const XMLString& localName() const; - bool hasAttributes() const; - - // Non-standard extensions - XMLString innerText() const; - - Element* getChildElement(const XMLString& name) const; - /// Returns the first child element with the given name, or null - /// if such an element does not exist. - /// - /// This method is an extension to the W3C Document Object Model. - - Element* getChildElementNS(const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns the first child element with the given namespaceURI and localName, - /// or null if such an element does not exist. - /// - /// This method is an extension to the W3C Document Object Model. - - Element* getElementById(const XMLString& elementId, const XMLString& idAttribute) const; - /// Returns the first Element whose ID attribute (given in idAttribute) - /// has the given elementId. If no such element exists, returns null. - /// - /// This method is an extension to the W3C Document Object Model. - - Element* getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const; - /// Returns the first Element whose ID attribute (given in idAttributeURI and idAttributeLocalName) - /// has the given elementId. If no such element exists, returns null. - /// - /// This method is an extension to the W3C Document Object Model. - - // Node - const XMLString& nodeName() const; - NamedNodeMap* attributes() const; - unsigned short nodeType() const; - -protected: - Element(Document* pOwnerDocument, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); - Element(Document* pOwnerDocument, const Element& elem); - ~Element(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - - void dispatchNodeRemovedFromDocument(); - void dispatchNodeInsertedIntoDocument(); - -private: - const Name& _name; - Attr* _pFirstAttr; - - friend class Attr; - friend class Document; - friend class AttrMap; -}; - - -// -// inlines -// -inline const XMLString& Element::tagName() const -{ - return _name.qname(); -} - - -} } // namespace Poco::XML - - -#endif // DOM_Element_INCLUDED +// +// Element.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Element.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Element class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Element_INCLUDED +#define DOM_Element_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractContainerNode.h" +#include "Poco/XML/Name.h" + + +namespace Poco { +namespace XML { + + +class Attr; +class NodeList; +class Document; + + +class XML_API Element: public AbstractContainerNode + /// The Element interface represents an element in an XML document. + /// Elements may have attributes associated with them; since the Element interface + /// inherits from Node, the generic Node interface attribute attributes may + /// be used to retrieve the set of all attributes for an element. There are + /// methods on the Element interface to retrieve either an Attr object by name + /// or an attribute value by name. In XML, where an attribute value may contain + /// entity references, an Attr object should be retrieved to examine the possibly + /// fairly complex sub-tree representing the attribute value. +{ +public: + const XMLString& tagName() const; + /// Returns the name of the element. + /// + /// For example, in + /// + /// + /// ... + /// + /// + /// tagName has the value "elementExample". Note that this is case-preserving in XML, + /// as are all of the operations of the DOM. + + const XMLString& getAttribute(const XMLString& name) const; + /// Retrieves an attribute value by name. + /// + /// Returns the attribute's value, if the attribute + /// exists, or an empty string otherwise. + + void setAttribute(const XMLString& name, const XMLString& value); + /// Adds a new attribute. If an attribute with that name is already present + /// in the element, its value is changed to be that of the value parameter. + /// This value is a simple string; it is not parsed as it is being set. So any + /// markup (such as syntax to be recognized as an entity reference) is treated + /// as literal text, and needs to be appropriately escaped by the implementation + /// when it is written out. + + void removeAttribute(const XMLString& name); + /// Removes an attribute by name. + + Attr* getAttributeNode(const XMLString& name) const; + /// Retrieves an Attr node by name. + + Attr* setAttributeNode(Attr* newAttr); + /// Adds a new attribute. If an attribute with that name is already + /// present in the element, it is replaced by the new one. + + Attr* addAttributeNodeNP(Attr* oldAttr, Attr* newAttr); + /// For internal use only. + /// Adds a new attribute after oldAttr. + /// If oldAttr is 0, newAttr is set as first attribute. + /// Returns newAttr. + /// Does not fire any events. + + Attr* removeAttributeNode(Attr* oldAttr); + /// Removes the specified attribute. + + NodeList* getElementsByTagName(const XMLString& name) const; + /// Returns a NodeList of all descendant elements with a given tag + /// name, in the order in which they would be encountered in a + /// preorder traversal of the Element tree. + /// + /// The special name "*" matches all tags. + /// + /// The returned NodeList must be released with a call + /// to release() when no longer needed. + + void normalize(); + /// Puts all Text nodes in the full depth of the sub-tree underneath this Element, + /// including attribute nodes, into a "normal" form where only markup (e.g., + /// tags, comments, processing instructions, CDATA sections, and entity references) + /// separates Text nodes, i.e., there are no adjacent Text nodes. This can be + /// used to ensure that the DOM view of a document is the same as if it were + /// saved and re-loaded, and is useful when operations (such as XPointer + /// lookups) that depend on a particular document tree structure are to be used. + /// + /// Note: In cases where the document contains CDATASections, the normalize + /// operation alone may not be sufficient, since XPointers do not differentiate + /// between Text nodes and CDATASection nodes. + + // DOM Level 2 + const XMLString& getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Retrieves an attribute value by name. + /// + /// Returns the attribute's value, if the attribute + /// exists, or an empty string otherwise. + + void setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value); + /// Adds a new attribute. If an attribute with that name + /// is already present in the element, its value is changed + /// to be that of the value parameter. + + void removeAttributeNS(const XMLString& namespaceURI, const XMLString& localName); + /// Removes an attribute by name. + + Attr* getAttributeNodeNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Retrieves an Attr node by name. + + Attr* setAttributeNodeNS(Attr* newAttr); + /// Adds a new attribute. If an attribute with that name is already + /// present in the element, it is replaced by the new one. + + bool hasAttribute(const XMLString& name) const; + /// Returns true if and only if the element has the specified attribute. + + bool hasAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns true if and only if the element has the specified attribute. + + NodeList* getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns a NodeList of all the descendant Elements with a given local name and namespace URI + /// in the order in which they are encountered in a preorder traversal of this Element tree. + /// + /// The special value "*" matches all namespaces, or local names respectively. + /// + /// The returned NodeList must be released with a call + /// to release() when no longer needed. + + const XMLString& namespaceURI() const; + XMLString prefix() const; + const XMLString& localName() const; + bool hasAttributes() const; + + // Non-standard extensions + XMLString innerText() const; + + Element* getChildElement(const XMLString& name) const; + /// Returns the first child element with the given name, or null + /// if such an element does not exist. + /// + /// This method is an extension to the W3C Document Object Model. + + Element* getChildElementNS(const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns the first child element with the given namespaceURI and localName, + /// or null if such an element does not exist. + /// + /// This method is an extension to the W3C Document Object Model. + + Element* getElementById(const XMLString& elementId, const XMLString& idAttribute) const; + /// Returns the first Element whose ID attribute (given in idAttribute) + /// has the given elementId. If no such element exists, returns null. + /// + /// This method is an extension to the W3C Document Object Model. + + Element* getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const; + /// Returns the first Element whose ID attribute (given in idAttributeURI and idAttributeLocalName) + /// has the given elementId. If no such element exists, returns null. + /// + /// This method is an extension to the W3C Document Object Model. + + // Node + const XMLString& nodeName() const; + NamedNodeMap* attributes() const; + unsigned short nodeType() const; + +protected: + Element(Document* pOwnerDocument, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); + Element(Document* pOwnerDocument, const Element& elem); + ~Element(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + + void dispatchNodeRemovedFromDocument(); + void dispatchNodeInsertedIntoDocument(); + +private: + const Name& _name; + Attr* _pFirstAttr; + + friend class Attr; + friend class Document; + friend class AttrMap; +}; + + +// +// inlines +// +inline const XMLString& Element::tagName() const +{ + return _name.qname(); +} + + +} } // namespace Poco::XML + + +#endif // DOM_Element_INCLUDED diff --git a/XML/include/Poco/DOM/ElementsByTagNameList.h b/XML/include/Poco/DOM/ElementsByTagNameList.h index ddfcf268e..cd06a7aeb 100644 --- a/XML/include/Poco/DOM/ElementsByTagNameList.h +++ b/XML/include/Poco/DOM/ElementsByTagNameList.h @@ -1,106 +1,106 @@ -// -// ElementsByTagNameList.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/ElementsByTagNameList.h#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the ElementsByTagNameList and ElementsByTagNameListNS classes. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_ElementsByTagNameList_INCLUDED -#define DOM_ElementsByTagNameList_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/NodeList.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API ElementsByTagNameList: public NodeList - // This implementation of NodeList is returned - // by Document::getElementsByTagName() and - // Element::getElementsByTagName(). -{ -public: - Node* item(unsigned long index) const; - unsigned long length() const; - void autoRelease(); - -protected: - ElementsByTagNameList(const Node* pParent, const XMLString& name); - ~ElementsByTagNameList(); - - Node* find(const Node* pParent, unsigned long index) const; - - const Node* _pParent; - XMLString _name; - mutable unsigned long _count; - - friend class Element; - friend class Document; -}; - - -class XML_API ElementsByTagNameListNS: public NodeList - // This implementation of NodeList is returned - // by Document::getElementsByTagNameNS() and - // Element::getElementsByTagNameNS(). -{ -public: - virtual Node* item(unsigned long index) const; - virtual unsigned long length() const; - virtual void autoRelease(); - -protected: - ElementsByTagNameListNS(const Node* pParent, const XMLString& namespaceURI, const XMLString& localName); - ~ElementsByTagNameListNS(); - - Node* find(const Node* pParent, unsigned long index) const; - - const Node* _pParent; - XMLString _localName; - XMLString _namespaceURI; - mutable unsigned long _count; - - friend class Element; - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_ElementsByTagNameList_INCLUDED +// +// ElementsByTagNameList.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/ElementsByTagNameList.h#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the ElementsByTagNameList and ElementsByTagNameListNS classes. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_ElementsByTagNameList_INCLUDED +#define DOM_ElementsByTagNameList_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/NodeList.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API ElementsByTagNameList: public NodeList + // This implementation of NodeList is returned + // by Document::getElementsByTagName() and + // Element::getElementsByTagName(). +{ +public: + Node* item(unsigned long index) const; + unsigned long length() const; + void autoRelease(); + +protected: + ElementsByTagNameList(const Node* pParent, const XMLString& name); + ~ElementsByTagNameList(); + + Node* find(const Node* pParent, unsigned long index) const; + + const Node* _pParent; + XMLString _name; + mutable unsigned long _count; + + friend class Element; + friend class Document; +}; + + +class XML_API ElementsByTagNameListNS: public NodeList + // This implementation of NodeList is returned + // by Document::getElementsByTagNameNS() and + // Element::getElementsByTagNameNS(). +{ +public: + virtual Node* item(unsigned long index) const; + virtual unsigned long length() const; + virtual void autoRelease(); + +protected: + ElementsByTagNameListNS(const Node* pParent, const XMLString& namespaceURI, const XMLString& localName); + ~ElementsByTagNameListNS(); + + Node* find(const Node* pParent, unsigned long index) const; + + const Node* _pParent; + XMLString _localName; + XMLString _namespaceURI; + mutable unsigned long _count; + + friend class Element; + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_ElementsByTagNameList_INCLUDED diff --git a/XML/include/Poco/DOM/Entity.h b/XML/include/Poco/DOM/Entity.h index e9c7ee5b8..27011bfad 100644 --- a/XML/include/Poco/DOM/Entity.h +++ b/XML/include/Poco/DOM/Entity.h @@ -1,148 +1,148 @@ -// -// Entity.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Entity.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Entity class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Entity_INCLUDED -#define DOM_Entity_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractContainerNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Entity: public AbstractContainerNode - /// This interface represents an entity, either parsed or unparsed, in an XML - /// document. Note that this models the entity itself not the entity declaration. - /// Entity declaration modeling has been left for a later Level of the DOM - /// specification. - /// - /// The nodeName attribute that is inherited from Node contains the name of - /// the entity. - /// - /// An XML processor may choose to completely expand entities before the structure - /// model is passed to the DOM; in this case there will be no EntityReference - /// nodes in the document tree. - /// - /// XML does not mandate that a non-validating XML processor read and process - /// entity declarations made in the external subset or declared in external - /// parameter entities. This means that parsed entities declared in the external - /// subset need not be expanded by some classes of applications, and that the - /// replacement value of the entity may not be available. When the replacement - /// value is available, the corresponding Entity node's child list represents - /// the structure of that replacement text. Otherwise, the child list is empty. - /// - /// The resolution of the children of the Entity (the replacement value) may - /// be lazily evaluated; actions by the user (such as calling the childNodes - /// method on the Entity Node) are assumed to trigger the evaluation. - /// - /// The DOM Level 1 does not support editing Entity nodes; if a user wants to - /// make changes to the contents of an Entity, every related EntityReference - /// node has to be replaced in the structure model by a clone of the Entity's - /// contents, and then the desired changes must be made to each of those clones - /// instead. Entity nodes and all their descendants are readonly. - /// - /// An Entity node does not have any parent. -{ -public: - const XMLString& publicId() const; - /// Returns the public identifier associated with - /// the entity, if specified. If the public identifier - /// was not specified, this is the empty string. - - const XMLString& systemId() const; - /// Returns the system identifier associated with - /// the entity, if specified. If the system identifier - /// was not specified, this is the empty string. - - const XMLString& notationName() const; - /// Returns, for unparsed entities, the name of the - /// notation for the entity. For parsed entities, this - /// is the empty string. - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - Entity(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName); - Entity(Document* pOwnerDocument, const Entity& entity); - ~Entity(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - static const XMLString NODE_NAME; - - XMLString _name; - XMLString _publicId; - XMLString _systemId; - XMLString _notationName; - - friend class Document; -}; - - -// -// inlines -// -inline const XMLString& Entity::publicId() const -{ - return _publicId; -} - - -inline const XMLString& Entity::systemId() const -{ - return _systemId; -} - - -inline const XMLString& Entity::notationName() const -{ - return _notationName; -} - - -} } // namespace Poco::XML - - -#endif // DOM_Entity_INCLUDED +// +// Entity.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Entity.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Entity class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Entity_INCLUDED +#define DOM_Entity_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractContainerNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Entity: public AbstractContainerNode + /// This interface represents an entity, either parsed or unparsed, in an XML + /// document. Note that this models the entity itself not the entity declaration. + /// Entity declaration modeling has been left for a later Level of the DOM + /// specification. + /// + /// The nodeName attribute that is inherited from Node contains the name of + /// the entity. + /// + /// An XML processor may choose to completely expand entities before the structure + /// model is passed to the DOM; in this case there will be no EntityReference + /// nodes in the document tree. + /// + /// XML does not mandate that a non-validating XML processor read and process + /// entity declarations made in the external subset or declared in external + /// parameter entities. This means that parsed entities declared in the external + /// subset need not be expanded by some classes of applications, and that the + /// replacement value of the entity may not be available. When the replacement + /// value is available, the corresponding Entity node's child list represents + /// the structure of that replacement text. Otherwise, the child list is empty. + /// + /// The resolution of the children of the Entity (the replacement value) may + /// be lazily evaluated; actions by the user (such as calling the childNodes + /// method on the Entity Node) are assumed to trigger the evaluation. + /// + /// The DOM Level 1 does not support editing Entity nodes; if a user wants to + /// make changes to the contents of an Entity, every related EntityReference + /// node has to be replaced in the structure model by a clone of the Entity's + /// contents, and then the desired changes must be made to each of those clones + /// instead. Entity nodes and all their descendants are readonly. + /// + /// An Entity node does not have any parent. +{ +public: + const XMLString& publicId() const; + /// Returns the public identifier associated with + /// the entity, if specified. If the public identifier + /// was not specified, this is the empty string. + + const XMLString& systemId() const; + /// Returns the system identifier associated with + /// the entity, if specified. If the system identifier + /// was not specified, this is the empty string. + + const XMLString& notationName() const; + /// Returns, for unparsed entities, the name of the + /// notation for the entity. For parsed entities, this + /// is the empty string. + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + Entity(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName); + Entity(Document* pOwnerDocument, const Entity& entity); + ~Entity(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + static const XMLString NODE_NAME; + + XMLString _name; + XMLString _publicId; + XMLString _systemId; + XMLString _notationName; + + friend class Document; +}; + + +// +// inlines +// +inline const XMLString& Entity::publicId() const +{ + return _publicId; +} + + +inline const XMLString& Entity::systemId() const +{ + return _systemId; +} + + +inline const XMLString& Entity::notationName() const +{ + return _notationName; +} + + +} } // namespace Poco::XML + + +#endif // DOM_Entity_INCLUDED diff --git a/XML/include/Poco/DOM/EntityReference.h b/XML/include/Poco/DOM/EntityReference.h index 18df87f9e..29392b51b 100644 --- a/XML/include/Poco/DOM/EntityReference.h +++ b/XML/include/Poco/DOM/EntityReference.h @@ -1,95 +1,95 @@ -// -// EntityReference.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/EntityReference.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM EntityReference class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_EntityReference_INCLUDED -#define DOM_EntityReference_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API EntityReference: public AbstractNode - /// EntityReference objects may be inserted into the structure model when an - /// entity reference is in the source document, or when the user wishes to insert - /// an entity reference. Note that character references and references to predefined - /// entities are considered to be expanded by the HTML or XML processor so that - /// characters are represented by their Unicode equivalent rather than by an - /// entity reference. Moreover, the XML processor may completely expand references - /// to entities while building the structure model, instead of providing EntityReference - /// objects. If it does provide such objects, then for a given EntityReference - /// node, it may be that there is no Entity node representing the referenced - /// entity. If such an Entity exists, then the child list of the EntityReference - /// node is the same as that of the Entity node. - /// - /// As for Entity nodes, EntityReference nodes and all their descendants are - /// readonly. - /// - /// The resolution of the children of the EntityReference (the replacement value - /// of the referenced Entity) may be lazily evaluated; actions by the user (such - /// as calling the childNodes method on the EntityReference node) are assumed - /// to trigger the evaluation. -{ -public: - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - EntityReference(Document* pOwnerDocument, const XMLString& name); - EntityReference(Document* pOwnerDocument, const EntityReference& ref); - ~EntityReference(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - XMLString _name; - - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_EntityReference_INCLUDED +// +// EntityReference.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/EntityReference.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM EntityReference class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_EntityReference_INCLUDED +#define DOM_EntityReference_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API EntityReference: public AbstractNode + /// EntityReference objects may be inserted into the structure model when an + /// entity reference is in the source document, or when the user wishes to insert + /// an entity reference. Note that character references and references to predefined + /// entities are considered to be expanded by the HTML or XML processor so that + /// characters are represented by their Unicode equivalent rather than by an + /// entity reference. Moreover, the XML processor may completely expand references + /// to entities while building the structure model, instead of providing EntityReference + /// objects. If it does provide such objects, then for a given EntityReference + /// node, it may be that there is no Entity node representing the referenced + /// entity. If such an Entity exists, then the child list of the EntityReference + /// node is the same as that of the Entity node. + /// + /// As for Entity nodes, EntityReference nodes and all their descendants are + /// readonly. + /// + /// The resolution of the children of the EntityReference (the replacement value + /// of the referenced Entity) may be lazily evaluated; actions by the user (such + /// as calling the childNodes method on the EntityReference node) are assumed + /// to trigger the evaluation. +{ +public: + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + EntityReference(Document* pOwnerDocument, const XMLString& name); + EntityReference(Document* pOwnerDocument, const EntityReference& ref); + ~EntityReference(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + XMLString _name; + + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_EntityReference_INCLUDED diff --git a/XML/include/Poco/DOM/Event.h b/XML/include/Poco/DOM/Event.h index d6dd92cfb..da5acc407 100644 --- a/XML/include/Poco/DOM/Event.h +++ b/XML/include/Poco/DOM/Event.h @@ -1,231 +1,231 @@ -// -// Event.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Event.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the DOM Event class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Event_INCLUDED -#define DOM_Event_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/DOM/DOMObject.h" - - -namespace Poco { -namespace XML { - - -class EventTarget; -class Document; - - -class XML_API Event: public DOMObject - /// The Event interface is used to provide contextual information about an event - /// to the handler processing the event. An object which implements the Event - /// interface is generally passed as the first parameter to an event handler. - /// More specific context information is passed to event handlers by deriving - /// additional interfaces from Event which contain information directly relating - /// to the type of event they accompany. These derived interfaces are also implemented - /// by the object passed to the event listener. -{ -public: - enum PhaseType - { - CAPTURING_PHASE = 1, /// The event is currently being evaluated at the target EventTarget. - AT_TARGET = 2, /// The current event phase is the bubbling phase. - BUBBLING_PHASE = 3 /// The current event phase is the capturing phase. - }; - - const XMLString& type() const; - /// The name of the event (case-insensitive). The name must be an XML name. - - EventTarget* target() const; - /// Used to indicate the EventTarget to which the event was originally dispatched. - - EventTarget* currentTarget() const; - /// Used to indicate the EventTarget whose EventListeners are currently being - /// processed. This is particularly useful during capturing and bubbling. - - PhaseType eventPhase() const; - /// Used to indicate which phase of event flow is currently being evaluated. - - bool bubbles() const; - /// Used to indicate whether or not an event is a bubbling event. - /// If the event can bubble the value is true, else the value is false. - - bool cancelable() const; - /// Used to indicate whether or not an event can have its default action - /// prevented. If the default action can be prevented the value is - /// true, else the value is false. - - Poco::UInt64 timeStamp() const; - /// Used to specify the time (in milliseconds relative to the epoch) at - /// which the event was created. Due to the fact that some - /// systems may not provide this information the value of timeStamp may - /// be not available for all events. When not available, a - /// value of 0 will be returned. Examples of epoch time are the time of the - /// system start or 0:0:0 UTC 1st January 1970. - /// This implementation always returns 0. - - void stopPropagation(); - /// The stopPropagation method is used prevent further propagation of an - /// event during event flow. If this method is called by - /// any EventListener the event will cease propagating through the tree. - /// The event will complete dispatch to all listeners on the - /// current EventTarget before event flow stops. This method may be used - /// during any stage of event flow. - - void preventDefault(); - /// If an event is cancelable, the preventDefault method is used to signify - /// that the event is to be canceled, meaning any default - /// action normally taken by the implementation as a result of - /// the event will not occur. If, during any stage of event flow, the - /// preventDefault method is called the event is canceled. Any default - /// action associated with the event will not occur. Calling - /// this method for a non-cancelable event has no effect. Once - /// preventDefault has been called it will remain in effect throughout - /// the remainder of the event's propagation. This method may be - /// used during any stage of event flow. - - void initEvent(const XMLString& eventType, bool canBubble, bool isCancelable); - /// The initEvent method is used to initialize the value of an - /// Event created through the DocumentEvent interface. This method - /// may only be called before the Event has been dispatched via the - /// dispatchEvent method, though it may be called multiple - /// times during that phase if necessary. If called multiple - /// times the final invocation takes precedence. If called from - /// a subclass of Event interface only the values specified in the - /// initEvent method are modified, all other attributes are left unchanged. - - void autoRelease(); - -protected: - Event(Document* pOwnerDocument, const XMLString& type); - Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable); - ~Event(); - - bool isCanceled() const; - /// returns true if and only if the event has been cancelled. - - bool isStopped() const; - /// returns true if and only if propagation of the event has been stopped. - - void setTarget(EventTarget* pTarget); - /// sets the target - - void setCurrentPhase(PhaseType phase); - /// sets the current phase - - void setCurrentTarget(EventTarget* pTarget); - /// sets the current target - -private: - Document* _pOwner; - XMLString _type; - EventTarget* _pTarget; - EventTarget* _pCurrentTarget; - PhaseType _currentPhase; - bool _bubbles; - bool _cancelable; - bool _canceled; - bool _stopped; - - friend class AbstractNode; -}; - - -// -// inlines -// -inline const XMLString& Event::type() const -{ - return _type; -} - - -inline EventTarget* Event::target() const -{ - return _pTarget; -} - - -inline EventTarget* Event::currentTarget() const -{ - return _pCurrentTarget; -} - - -inline Event::PhaseType Event::eventPhase() const -{ - return _currentPhase; -} - - -inline bool Event::bubbles() const -{ - return _bubbles; -} - - -inline bool Event::cancelable() const -{ - return _cancelable; -} - - -inline Poco::UInt64 Event::timeStamp() const -{ - return 0; -} - - -inline bool Event::isCanceled() const -{ - return _canceled; -} - - -inline bool Event::isStopped() const -{ - return _stopped; -} - - -} } // namespace Poco::XML - - -#endif // DOM_Event_INCLUDED +// +// Event.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Event.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the DOM Event class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Event_INCLUDED +#define DOM_Event_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/DOM/DOMObject.h" + + +namespace Poco { +namespace XML { + + +class EventTarget; +class Document; + + +class XML_API Event: public DOMObject + /// The Event interface is used to provide contextual information about an event + /// to the handler processing the event. An object which implements the Event + /// interface is generally passed as the first parameter to an event handler. + /// More specific context information is passed to event handlers by deriving + /// additional interfaces from Event which contain information directly relating + /// to the type of event they accompany. These derived interfaces are also implemented + /// by the object passed to the event listener. +{ +public: + enum PhaseType + { + CAPTURING_PHASE = 1, /// The event is currently being evaluated at the target EventTarget. + AT_TARGET = 2, /// The current event phase is the bubbling phase. + BUBBLING_PHASE = 3 /// The current event phase is the capturing phase. + }; + + const XMLString& type() const; + /// The name of the event (case-insensitive). The name must be an XML name. + + EventTarget* target() const; + /// Used to indicate the EventTarget to which the event was originally dispatched. + + EventTarget* currentTarget() const; + /// Used to indicate the EventTarget whose EventListeners are currently being + /// processed. This is particularly useful during capturing and bubbling. + + PhaseType eventPhase() const; + /// Used to indicate which phase of event flow is currently being evaluated. + + bool bubbles() const; + /// Used to indicate whether or not an event is a bubbling event. + /// If the event can bubble the value is true, else the value is false. + + bool cancelable() const; + /// Used to indicate whether or not an event can have its default action + /// prevented. If the default action can be prevented the value is + /// true, else the value is false. + + Poco::UInt64 timeStamp() const; + /// Used to specify the time (in milliseconds relative to the epoch) at + /// which the event was created. Due to the fact that some + /// systems may not provide this information the value of timeStamp may + /// be not available for all events. When not available, a + /// value of 0 will be returned. Examples of epoch time are the time of the + /// system start or 0:0:0 UTC 1st January 1970. + /// This implementation always returns 0. + + void stopPropagation(); + /// The stopPropagation method is used prevent further propagation of an + /// event during event flow. If this method is called by + /// any EventListener the event will cease propagating through the tree. + /// The event will complete dispatch to all listeners on the + /// current EventTarget before event flow stops. This method may be used + /// during any stage of event flow. + + void preventDefault(); + /// If an event is cancelable, the preventDefault method is used to signify + /// that the event is to be canceled, meaning any default + /// action normally taken by the implementation as a result of + /// the event will not occur. If, during any stage of event flow, the + /// preventDefault method is called the event is canceled. Any default + /// action associated with the event will not occur. Calling + /// this method for a non-cancelable event has no effect. Once + /// preventDefault has been called it will remain in effect throughout + /// the remainder of the event's propagation. This method may be + /// used during any stage of event flow. + + void initEvent(const XMLString& eventType, bool canBubble, bool isCancelable); + /// The initEvent method is used to initialize the value of an + /// Event created through the DocumentEvent interface. This method + /// may only be called before the Event has been dispatched via the + /// dispatchEvent method, though it may be called multiple + /// times during that phase if necessary. If called multiple + /// times the final invocation takes precedence. If called from + /// a subclass of Event interface only the values specified in the + /// initEvent method are modified, all other attributes are left unchanged. + + void autoRelease(); + +protected: + Event(Document* pOwnerDocument, const XMLString& type); + Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable); + ~Event(); + + bool isCanceled() const; + /// returns true if and only if the event has been cancelled. + + bool isStopped() const; + /// returns true if and only if propagation of the event has been stopped. + + void setTarget(EventTarget* pTarget); + /// sets the target + + void setCurrentPhase(PhaseType phase); + /// sets the current phase + + void setCurrentTarget(EventTarget* pTarget); + /// sets the current target + +private: + Document* _pOwner; + XMLString _type; + EventTarget* _pTarget; + EventTarget* _pCurrentTarget; + PhaseType _currentPhase; + bool _bubbles; + bool _cancelable; + bool _canceled; + bool _stopped; + + friend class AbstractNode; +}; + + +// +// inlines +// +inline const XMLString& Event::type() const +{ + return _type; +} + + +inline EventTarget* Event::target() const +{ + return _pTarget; +} + + +inline EventTarget* Event::currentTarget() const +{ + return _pCurrentTarget; +} + + +inline Event::PhaseType Event::eventPhase() const +{ + return _currentPhase; +} + + +inline bool Event::bubbles() const +{ + return _bubbles; +} + + +inline bool Event::cancelable() const +{ + return _cancelable; +} + + +inline Poco::UInt64 Event::timeStamp() const +{ + return 0; +} + + +inline bool Event::isCanceled() const +{ + return _canceled; +} + + +inline bool Event::isStopped() const +{ + return _stopped; +} + + +} } // namespace Poco::XML + + +#endif // DOM_Event_INCLUDED diff --git a/XML/include/Poco/DOM/EventDispatcher.h b/XML/include/Poco/DOM/EventDispatcher.h index 129d8ad30..ebfaa058d 100644 --- a/XML/include/Poco/DOM/EventDispatcher.h +++ b/XML/include/Poco/DOM/EventDispatcher.h @@ -1,119 +1,119 @@ -// -// EventDispatcher.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/EventDispatcher.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the EventDispatcher class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_EventDispatcher_INCLUDED -#define DOM_EventDispatcher_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include - - -namespace Poco { -namespace XML { - - -class Event; -class EventListener; - - -class XML_API EventDispatcher - /// This helper class manages event listener subscriptions - /// and event dispatching for AbstractNode. - /// - /// The EventListener list is managed in such a way that - /// event listeners can be added and removed even - /// from within an EventListener, while events are being - /// dispatched. -{ -public: - EventDispatcher(); - /// Creates the EventDispatcher. - - ~EventDispatcher(); - /// Destroys the EventDispatcher. - - void addEventListener(const XMLString& type, EventListener* listener, bool useCapture); - /// Adds an EventListener to the internal list. - - void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture); - /// Removes an EventListener from the internal list. - /// - /// If a dispatch is currently in progress, the list - /// entry is only marked for deletion. - /// If no dispatch is currently in progress, all EventListeners - /// marked for deletion are removed from the list. - - void dispatchEvent(Event* evt); - /// Dispatches the event. - /// - /// Also removes all EventListeners marked for deletion from the - /// event dispatcher list. - - void captureEvent(Event* evt); - /// Dispatches the event in its capturing phase. - /// - /// Also removes all EventListeners marked for deletion from the - /// event dispatcher list. - - void bubbleEvent(Event* evt); - /// Dispatches the event in its bubbling phase. - /// - /// Also removes all EventListeners marked for deletion from the - /// event dispatcher list. - -private: - struct EventListenerItem - { - XMLString type; - EventListener* pListener; - bool useCapture; - }; - - typedef std::list EventListenerList; - - int _inDispatch; - EventListenerList _listeners; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_EventDispatcher_INCLUDED +// +// EventDispatcher.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/EventDispatcher.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the EventDispatcher class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_EventDispatcher_INCLUDED +#define DOM_EventDispatcher_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include + + +namespace Poco { +namespace XML { + + +class Event; +class EventListener; + + +class XML_API EventDispatcher + /// This helper class manages event listener subscriptions + /// and event dispatching for AbstractNode. + /// + /// The EventListener list is managed in such a way that + /// event listeners can be added and removed even + /// from within an EventListener, while events are being + /// dispatched. +{ +public: + EventDispatcher(); + /// Creates the EventDispatcher. + + ~EventDispatcher(); + /// Destroys the EventDispatcher. + + void addEventListener(const XMLString& type, EventListener* listener, bool useCapture); + /// Adds an EventListener to the internal list. + + void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture); + /// Removes an EventListener from the internal list. + /// + /// If a dispatch is currently in progress, the list + /// entry is only marked for deletion. + /// If no dispatch is currently in progress, all EventListeners + /// marked for deletion are removed from the list. + + void dispatchEvent(Event* evt); + /// Dispatches the event. + /// + /// Also removes all EventListeners marked for deletion from the + /// event dispatcher list. + + void captureEvent(Event* evt); + /// Dispatches the event in its capturing phase. + /// + /// Also removes all EventListeners marked for deletion from the + /// event dispatcher list. + + void bubbleEvent(Event* evt); + /// Dispatches the event in its bubbling phase. + /// + /// Also removes all EventListeners marked for deletion from the + /// event dispatcher list. + +private: + struct EventListenerItem + { + XMLString type; + EventListener* pListener; + bool useCapture; + }; + + typedef std::list EventListenerList; + + int _inDispatch; + EventListenerList _listeners; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_EventDispatcher_INCLUDED diff --git a/XML/include/Poco/DOM/EventException.h b/XML/include/Poco/DOM/EventException.h index f2fce538b..4ad7b494e 100644 --- a/XML/include/Poco/DOM/EventException.h +++ b/XML/include/Poco/DOM/EventException.h @@ -1,103 +1,103 @@ -// -// EventException.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/EventException.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the DOM EventException class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_EventException_INCLUDED -#define DOM_EventException_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLException.h" - - -namespace Poco { -namespace XML { - - -class XML_API EventException: public XMLException - /// Event operations may throw an EventException as - /// specified in their method descriptions. -{ -public: - enum - { - UNSPECIFIED_EVENT_TYPE_ERR = 0 /// If the Event's type was not specified by initializing the - /// event before the method was called. Specification of the Event's - /// type as null or an empty string will also trigger this exception. - }; - - EventException(int code); - /// Creates an EventException with the given error code. - - EventException(const EventException& exc); - /// Creates an EventException by copying another one. - - ~EventException() throw(); - /// Destroys the EventException. - - EventException& operator = (const EventException& exc); - - const char* name() const throw(); - /// Returns a static string describing the exception. - - const char* className() const throw(); - /// Returns the name of the exception class. - - unsigned short code() const; - /// Returns the Event exception code. - -protected: - Poco::Exception* clone() const; - -private: - EventException(); -}; - - -// -// inlines -// -inline unsigned short EventException::code() const -{ - return UNSPECIFIED_EVENT_TYPE_ERR; -} - - -} } // namespace Poco::XML - - -#endif // DOM_EventException_INCLUDED +// +// EventException.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/EventException.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the DOM EventException class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_EventException_INCLUDED +#define DOM_EventException_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLException.h" + + +namespace Poco { +namespace XML { + + +class XML_API EventException: public XMLException + /// Event operations may throw an EventException as + /// specified in their method descriptions. +{ +public: + enum + { + UNSPECIFIED_EVENT_TYPE_ERR = 0 /// If the Event's type was not specified by initializing the + /// event before the method was called. Specification of the Event's + /// type as null or an empty string will also trigger this exception. + }; + + EventException(int code); + /// Creates an EventException with the given error code. + + EventException(const EventException& exc); + /// Creates an EventException by copying another one. + + ~EventException() throw(); + /// Destroys the EventException. + + EventException& operator = (const EventException& exc); + + const char* name() const throw(); + /// Returns a static string describing the exception. + + const char* className() const throw(); + /// Returns the name of the exception class. + + unsigned short code() const; + /// Returns the Event exception code. + +protected: + Poco::Exception* clone() const; + +private: + EventException(); +}; + + +// +// inlines +// +inline unsigned short EventException::code() const +{ + return UNSPECIFIED_EVENT_TYPE_ERR; +} + + +} } // namespace Poco::XML + + +#endif // DOM_EventException_INCLUDED diff --git a/XML/include/Poco/DOM/EventListener.h b/XML/include/Poco/DOM/EventListener.h index a0c6cc46a..7df0209e7 100644 --- a/XML/include/Poco/DOM/EventListener.h +++ b/XML/include/Poco/DOM/EventListener.h @@ -1,79 +1,79 @@ -// -// EventListener.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/EventListener.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the DOM EventListener interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_EventListener_INCLUDED -#define DOM_EventListener_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Event; - - -class XML_API EventListener - /// The EventListener interface is the primary method for handling events. Users - /// implement the EventListener interface and register their listener on an - /// EventTarget using the AddEventListener method. The users should also remove - /// their EventListener from its EventTarget after they have completed using - /// the listener. - /// - /// When a Node is copied using the cloneNode method the EventListeners attached - /// to the source Node are not attached to the copied Node. If the user wishes - /// the same EventListeners to be added to the newly created copy the user must - /// add them manually. -{ -public: - virtual void handleEvent(Event* evt) = 0; - /// This method is called whenever an event occurs of the - /// type for which the EventListener interface was registered. - -protected: - virtual ~EventListener(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_EventListener_INCLUDED +// +// EventListener.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/EventListener.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the DOM EventListener interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_EventListener_INCLUDED +#define DOM_EventListener_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Event; + + +class XML_API EventListener + /// The EventListener interface is the primary method for handling events. Users + /// implement the EventListener interface and register their listener on an + /// EventTarget using the AddEventListener method. The users should also remove + /// their EventListener from its EventTarget after they have completed using + /// the listener. + /// + /// When a Node is copied using the cloneNode method the EventListeners attached + /// to the source Node are not attached to the copied Node. If the user wishes + /// the same EventListeners to be added to the newly created copy the user must + /// add them manually. +{ +public: + virtual void handleEvent(Event* evt) = 0; + /// This method is called whenever an event occurs of the + /// type for which the EventListener interface was registered. + +protected: + virtual ~EventListener(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_EventListener_INCLUDED diff --git a/XML/include/Poco/DOM/EventTarget.h b/XML/include/Poco/DOM/EventTarget.h index 55fd88324..4054d513f 100644 --- a/XML/include/Poco/DOM/EventTarget.h +++ b/XML/include/Poco/DOM/EventTarget.h @@ -1,98 +1,98 @@ -// -// EventTarget.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/EventTarget.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the DOM EventTarget interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_EventTarget_INCLUDED -#define DOM_EventTarget_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/DOMObject.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class EventListener; -class Event; - - -class XML_API EventTarget: public DOMObject - /// The EventTarget interface is implemented by all Nodes in an implementation - /// which supports the DOM Event Model. Therefore, this interface can be obtained - /// by using binding-specific casting methods on an instance of the Node interface. - /// The interface allows registration and removal of EventListeners on an EventTarget - /// and dispatch of events to that EventTarget. -{ -public: - virtual void addEventListener(const XMLString& type, EventListener* listener, bool useCapture) = 0; - /// This method allows the registration of event listeners on - /// the event target. If an EventListener is added to an - /// EventTarget while it is processing an event, it will not - /// be triggered by the current actions but may be triggered - /// during a later stage of event flow, such as the bubbling phase. - /// If multiple identical EventListeners are registered on the same - /// EventTarget with the same parameters the duplicate instances are - /// discarded. They do not cause the EventListener to be called twice and since they are - /// discarded they do not need to be removed with the removeEventListener method. - - virtual void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) = 0; - /// This method allows the removal of event listeners from the event - /// target. If an EventListener is removed from an EventTarget while it is - /// processing an event, it will not be triggered by the current actions. - /// EventListeners can never be invoked after being removed. - /// Calling removeEventListener with arguments which do not identify - /// any currently registered EventListener on the EventTarget has no effect. - - virtual bool dispatchEvent(Event* evt) = 0; - /// This method allows the dispatch of events into the implementations - /// event model. Events dispatched in this manner will have the same capturing and - /// bubbling behavior as events dispatched directly by the - /// implementation. The target of the event is the EventTarget on - /// which dispatchEvent is called. - -protected: - virtual ~EventTarget(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_EventTarget_INCLUDED +// +// EventTarget.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/EventTarget.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the DOM EventTarget interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_EventTarget_INCLUDED +#define DOM_EventTarget_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/DOMObject.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class EventListener; +class Event; + + +class XML_API EventTarget: public DOMObject + /// The EventTarget interface is implemented by all Nodes in an implementation + /// which supports the DOM Event Model. Therefore, this interface can be obtained + /// by using binding-specific casting methods on an instance of the Node interface. + /// The interface allows registration and removal of EventListeners on an EventTarget + /// and dispatch of events to that EventTarget. +{ +public: + virtual void addEventListener(const XMLString& type, EventListener* listener, bool useCapture) = 0; + /// This method allows the registration of event listeners on + /// the event target. If an EventListener is added to an + /// EventTarget while it is processing an event, it will not + /// be triggered by the current actions but may be triggered + /// during a later stage of event flow, such as the bubbling phase. + /// If multiple identical EventListeners are registered on the same + /// EventTarget with the same parameters the duplicate instances are + /// discarded. They do not cause the EventListener to be called twice and since they are + /// discarded they do not need to be removed with the removeEventListener method. + + virtual void removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) = 0; + /// This method allows the removal of event listeners from the event + /// target. If an EventListener is removed from an EventTarget while it is + /// processing an event, it will not be triggered by the current actions. + /// EventListeners can never be invoked after being removed. + /// Calling removeEventListener with arguments which do not identify + /// any currently registered EventListener on the EventTarget has no effect. + + virtual bool dispatchEvent(Event* evt) = 0; + /// This method allows the dispatch of events into the implementations + /// event model. Events dispatched in this manner will have the same capturing and + /// bubbling behavior as events dispatched directly by the + /// implementation. The target of the event is the EventTarget on + /// which dispatchEvent is called. + +protected: + virtual ~EventTarget(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_EventTarget_INCLUDED diff --git a/XML/include/Poco/DOM/MutationEvent.h b/XML/include/Poco/DOM/MutationEvent.h index 6ce0053b1..1320f8ff0 100644 --- a/XML/include/Poco/DOM/MutationEvent.h +++ b/XML/include/Poco/DOM/MutationEvent.h @@ -1,165 +1,165 @@ -// -// MutationEvent.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/MutationEvent.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Definition of the DOM MutationEvent class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_MutationEvent_INCLUDED -#define DOM_MutationEvent_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/Event.h" - - -namespace Poco { -namespace XML { - - -class Node; - - -class XML_API MutationEvent: public Event - /// The MutationEvent interface provides specific contextual - /// information associated with Mutation events. -{ -public: - enum AttrChangeType - { - MODIFICATION = 1, /// The Attr was modified in place. - ADDITION = 2, /// The Attr was just added. - REMOVAL = 3 /// The Attr was just removed. - }; - - Node* relatedNode() const; - /// relatedNode is used to identify a secondary node related to a mutation - /// event. For example, if a mutation event is dispatched - /// to a node indicating that its parent has changed, the relatedNode is the - /// changed parent. If an event is instead dispatched to a - /// subtree indicating a node was changed within it, the relatedNode is - /// the changed node. In the case of the DOMAttrModified - /// event it indicates the Attr node which was modified, added, or removed. - - const XMLString& prevValue() const; - /// prevValue indicates the previous value of the Attr node in DOMAttrModified - /// events, and of the CharacterData node in DOMCharDataModified events. - - const XMLString& newValue() const; - /// newValue indicates the new value of the Attr node in DOMAttrModified - /// events, and of the CharacterData node in DOMCharDataModified events. - - const XMLString& attrName() const; - /// attrName indicates the name of the changed Attr node in a DOMAttrModified event. - - AttrChangeType attrChange() const; - /// attrChange indicates the type of change which triggered the - /// DOMAttrModified event. The values can be MODIFICATION, - /// ADDITION, or REMOVAL. - - void initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode, - const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change); - /// The initMutationEvent method is used to initialize the value of a - /// MutationEvent created through the DocumentEvent - /// interface. This method may only be called before the MutationEvent - /// has been dispatched via the dispatchEvent method, - /// though it may be called multiple times during that phase if - /// necessary. If called multiple times, the final invocation takes - /// precedence. - - // Event Types - static const XMLString DOMSubtreeModified; - static const XMLString DOMNodeInserted; - static const XMLString DOMNodeRemoved; - static const XMLString DOMNodeRemovedFromDocument; - static const XMLString DOMNodeInsertedIntoDocument; - static const XMLString DOMAttrModified; - static const XMLString DOMCharacterDataModified; - -protected: - MutationEvent(Document* pOwnerDocument, const XMLString& type); - MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode); - MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode, - const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change); - ~MutationEvent(); - -private: - XMLString _prevValue; - XMLString _newValue; - XMLString _attrName; - AttrChangeType _change; - Node* _pRelatedNode; - - friend class AbstractNode; - friend class Document; -}; - - -// -// inlines -// -inline Node* MutationEvent::relatedNode() const -{ - return _pRelatedNode; -} - - -inline const XMLString& MutationEvent::prevValue() const -{ - return _prevValue; -} - - -inline const XMLString& MutationEvent::newValue() const -{ - return _newValue; -} - - -inline const XMLString& MutationEvent::attrName() const -{ - return _attrName; -} - - -inline MutationEvent::AttrChangeType MutationEvent::attrChange() const -{ - return _change; -} - - -} } // namespace Poco::XML - - -#endif // DOM_MutationEvent_INCLUDED +// +// MutationEvent.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/MutationEvent.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Definition of the DOM MutationEvent class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_MutationEvent_INCLUDED +#define DOM_MutationEvent_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/Event.h" + + +namespace Poco { +namespace XML { + + +class Node; + + +class XML_API MutationEvent: public Event + /// The MutationEvent interface provides specific contextual + /// information associated with Mutation events. +{ +public: + enum AttrChangeType + { + MODIFICATION = 1, /// The Attr was modified in place. + ADDITION = 2, /// The Attr was just added. + REMOVAL = 3 /// The Attr was just removed. + }; + + Node* relatedNode() const; + /// relatedNode is used to identify a secondary node related to a mutation + /// event. For example, if a mutation event is dispatched + /// to a node indicating that its parent has changed, the relatedNode is the + /// changed parent. If an event is instead dispatched to a + /// subtree indicating a node was changed within it, the relatedNode is + /// the changed node. In the case of the DOMAttrModified + /// event it indicates the Attr node which was modified, added, or removed. + + const XMLString& prevValue() const; + /// prevValue indicates the previous value of the Attr node in DOMAttrModified + /// events, and of the CharacterData node in DOMCharDataModified events. + + const XMLString& newValue() const; + /// newValue indicates the new value of the Attr node in DOMAttrModified + /// events, and of the CharacterData node in DOMCharDataModified events. + + const XMLString& attrName() const; + /// attrName indicates the name of the changed Attr node in a DOMAttrModified event. + + AttrChangeType attrChange() const; + /// attrChange indicates the type of change which triggered the + /// DOMAttrModified event. The values can be MODIFICATION, + /// ADDITION, or REMOVAL. + + void initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode, + const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change); + /// The initMutationEvent method is used to initialize the value of a + /// MutationEvent created through the DocumentEvent + /// interface. This method may only be called before the MutationEvent + /// has been dispatched via the dispatchEvent method, + /// though it may be called multiple times during that phase if + /// necessary. If called multiple times, the final invocation takes + /// precedence. + + // Event Types + static const XMLString DOMSubtreeModified; + static const XMLString DOMNodeInserted; + static const XMLString DOMNodeRemoved; + static const XMLString DOMNodeRemovedFromDocument; + static const XMLString DOMNodeInsertedIntoDocument; + static const XMLString DOMAttrModified; + static const XMLString DOMCharacterDataModified; + +protected: + MutationEvent(Document* pOwnerDocument, const XMLString& type); + MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode); + MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode, + const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change); + ~MutationEvent(); + +private: + XMLString _prevValue; + XMLString _newValue; + XMLString _attrName; + AttrChangeType _change; + Node* _pRelatedNode; + + friend class AbstractNode; + friend class Document; +}; + + +// +// inlines +// +inline Node* MutationEvent::relatedNode() const +{ + return _pRelatedNode; +} + + +inline const XMLString& MutationEvent::prevValue() const +{ + return _prevValue; +} + + +inline const XMLString& MutationEvent::newValue() const +{ + return _newValue; +} + + +inline const XMLString& MutationEvent::attrName() const +{ + return _attrName; +} + + +inline MutationEvent::AttrChangeType MutationEvent::attrChange() const +{ + return _change; +} + + +} } // namespace Poco::XML + + +#endif // DOM_MutationEvent_INCLUDED diff --git a/XML/include/Poco/DOM/NamedNodeMap.h b/XML/include/Poco/DOM/NamedNodeMap.h index 08c0577b7..ea36beff1 100644 --- a/XML/include/Poco/DOM/NamedNodeMap.h +++ b/XML/include/Poco/DOM/NamedNodeMap.h @@ -1,115 +1,115 @@ -// -// NamedNodeMap.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/NamedNodeMap.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM NamedNodeMap interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_NamedNodeMap_INCLUDED -#define DOM_NamedNodeMap_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/DOMObject.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Node; - - -class XML_API NamedNodeMap: public DOMObject - /// Objects implementing the NamedNodeMap interface are used to represent collections - /// of nodes that can be accessed by name. Note that NamedNodeMap does not inherit - /// from NodeList; NamedNodeMaps are not maintained in any particular order. - /// Objects contained in an object implementing NamedNodeMap may also be accessed - /// by an ordinal index, but this is simply to allow convenient enumeration - /// of the contents of a NamedNodeMap, and does not imply that the DOM specifies - /// an order to these Nodes. - /// - /// NamedNodeMap objects in the DOM are live. - /// - /// A NamedNodeMap returned from a method must be released with a call to - /// release() when no longer needed. -{ -public: - virtual Node* getNamedItem(const XMLString& name) const = 0; - /// Retrieves a node specified by name. - - virtual Node* setNamedItem(Node* arg) = 0; - /// Adds a node using its nodeName attribute. If a node with that name is already - /// present in this map, it is replaced by the new one. - /// As the nodeName attribute is used to derive the name which the node must - /// be stored under, multiple nodes of certain types (those that have a "special" - /// string value) cannot be stored as the names would clash. This is seen as - /// preferable to allowing nodes to be aliased. - - virtual Node* removeNamedItem(const XMLString& name) = 0; - /// Removes a node specified by name. When this map contains the attributes - /// attached to an element, if the removed attribute is known to have a default - /// value, an attribute immediately appears containing the default value. - - virtual Node* item(unsigned long index) const = 0; - /// Returns the index'th item in the map. If index is greater - /// than or equal to the number of nodes in the map, this - /// returns null. - - virtual unsigned long length() const = 0; - /// Returns the number of nodes in the map. The range of valid - /// child node indices is 0 to length - 1 inclusive. - - // DOM Level 2 - virtual Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const = 0; - /// Retrieves a node specified by name. - - virtual Node* setNamedItemNS(Node* arg) = 0; - /// Adds a node using its nodeName attribute. - /// If a node with that namespace URI and that local name is already - /// present in this map, it is replaced by the new one. - - virtual Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) = 0; - /// Removes a node specified by name. - -protected: - virtual ~NamedNodeMap(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_NamedNodeMap_INCLUDED +// +// NamedNodeMap.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/NamedNodeMap.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM NamedNodeMap interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_NamedNodeMap_INCLUDED +#define DOM_NamedNodeMap_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/DOMObject.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Node; + + +class XML_API NamedNodeMap: public DOMObject + /// Objects implementing the NamedNodeMap interface are used to represent collections + /// of nodes that can be accessed by name. Note that NamedNodeMap does not inherit + /// from NodeList; NamedNodeMaps are not maintained in any particular order. + /// Objects contained in an object implementing NamedNodeMap may also be accessed + /// by an ordinal index, but this is simply to allow convenient enumeration + /// of the contents of a NamedNodeMap, and does not imply that the DOM specifies + /// an order to these Nodes. + /// + /// NamedNodeMap objects in the DOM are live. + /// + /// A NamedNodeMap returned from a method must be released with a call to + /// release() when no longer needed. +{ +public: + virtual Node* getNamedItem(const XMLString& name) const = 0; + /// Retrieves a node specified by name. + + virtual Node* setNamedItem(Node* arg) = 0; + /// Adds a node using its nodeName attribute. If a node with that name is already + /// present in this map, it is replaced by the new one. + /// As the nodeName attribute is used to derive the name which the node must + /// be stored under, multiple nodes of certain types (those that have a "special" + /// string value) cannot be stored as the names would clash. This is seen as + /// preferable to allowing nodes to be aliased. + + virtual Node* removeNamedItem(const XMLString& name) = 0; + /// Removes a node specified by name. When this map contains the attributes + /// attached to an element, if the removed attribute is known to have a default + /// value, an attribute immediately appears containing the default value. + + virtual Node* item(unsigned long index) const = 0; + /// Returns the index'th item in the map. If index is greater + /// than or equal to the number of nodes in the map, this + /// returns null. + + virtual unsigned long length() const = 0; + /// Returns the number of nodes in the map. The range of valid + /// child node indices is 0 to length - 1 inclusive. + + // DOM Level 2 + virtual Node* getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const = 0; + /// Retrieves a node specified by name. + + virtual Node* setNamedItemNS(Node* arg) = 0; + /// Adds a node using its nodeName attribute. + /// If a node with that namespace URI and that local name is already + /// present in this map, it is replaced by the new one. + + virtual Node* removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) = 0; + /// Removes a node specified by name. + +protected: + virtual ~NamedNodeMap(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_NamedNodeMap_INCLUDED diff --git a/XML/include/Poco/DOM/Node.h b/XML/include/Poco/DOM/Node.h index a8ef18330..994f8b2f9 100644 --- a/XML/include/Poco/DOM/Node.h +++ b/XML/include/Poco/DOM/Node.h @@ -1,255 +1,255 @@ -// -// Node.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Node.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Node interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Node_INCLUDED -#define DOM_Node_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/EventTarget.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class NamedNodeMap; -class Document; -class NodeList; - - -class XML_API Node: public EventTarget - /// The Node interface is the primary datatype for the entire Document Object - /// Model. It represents a single node in the document tree. While all objects - /// implementing the Node interface expose methods for dealing with children, - /// not all objects implementing the Node interface may have children. For - /// example, Text nodes may not have children, and adding children to such - /// nodes results in a DOMException being raised. - /// - /// The attributes nodeName, nodeValue and attributes are included as a mechanism - /// to get at node information without casting down to the specific derived - /// interface. In cases where there is no obvious mapping of these attributes - /// for a specific nodeType (e.g., nodeValue for an Element or attributes for - /// a Comment), this returns null. Note that the specialized interfaces may - /// contain additional and more convenient mechanisms to get and set the relevant - /// information. - /// - /// This implementation differs in some ways from the W3C DOM recommendations. - /// For example, the DOM specifies that some methods can return null strings. - /// Instead of null strings, this implementation always returns empty strings. -{ -public: - enum - { - ELEMENT_NODE = 1, /// The node is an Element. - ATTRIBUTE_NODE, /// The node is an Attr. - TEXT_NODE, /// The node is a Text node. - CDATA_SECTION_NODE, /// The node is a CDATASection. - ENTITY_REFERENCE_NODE, /// The node is an EntityReference. - ENTITY_NODE, /// The node is an Entity. - PROCESSING_INSTRUCTION_NODE, /// The node is a ProcessingInstruction. - COMMENT_NODE, /// The node is a Comment. - DOCUMENT_NODE, /// The node is a Document. - DOCUMENT_TYPE_NODE, /// The node is a DocumentType. - DOCUMENT_FRAGMENT_NODE, /// The node is a DocumentFragment. - NOTATION_NODE /// The node is a Notation. - }; - - virtual const XMLString& nodeName() const = 0; - /// Returns the name of this node, depending on its type. - - const XMLString& nodeValue() const; - /// Returns the value of this node, depending on its type. - - virtual const XMLString& getNodeValue() const = 0; - /// Returns the value of this node, depending on its type. - - virtual void setNodeValue(const XMLString& value) = 0; - /// Sets the value of this node. Throws an exception - /// if the node is read-only. - - virtual unsigned short nodeType() const = 0; - /// Returns a code representing the type of the underlying object. - - virtual Node* parentNode() const = 0; - /// The parent of this node. All nodes, except Attr, Document, DocumentFragment, - /// Entity, and Notation may have a parent. However, if a node has just been - /// created and not yet added to the tree, or if it has been removed from the - /// tree, this is null. - - virtual NodeList* childNodes() const = 0; - /// Returns a NodeList containing all children of this node. - /// - /// The returned NodeList must be released with a call - /// to release() when no longer needed. - - virtual Node* firstChild() const = 0; - /// Returns the first child of this node. If there is no such - /// node, this returns null. - - virtual Node* lastChild() const = 0; - /// Returns the last child of this node. If there is no such - /// node, this returns null. - - virtual Node* previousSibling() const = 0; - /// Returns the node immediately preceding this node. If there - /// is no such node, this returns null. - - virtual Node* nextSibling() const = 0; - /// Returns the node immediately following this node. If there - /// is no such node, this returns null. - - virtual NamedNodeMap* attributes() const = 0; - /// Returns a NamedNodeMap containing the attributes of this - /// node (if it is an Element) or null otherwise. - /// - /// The returned NamedNodeMap must be released with a call - /// to release() when no longer needed. - - virtual Document* ownerDocument() const = 0; - /// Returns the Document object associated with this node. - /// This is also the Document object used to create new nodes. - /// When this node is a Document, this is null. - - virtual Node* insertBefore(Node* newChild, Node* refChild) = 0; - /// Inserts the node newChild before the existing child node refChild. - /// - /// If refChild is null, insert newChild at the end of the list of children. - /// If newChild is a DocumentFragment object, all of its children are - /// inserted in the same order, before refChild. If the newChild is already - /// in the tree, it is first removed. - - virtual Node* replaceChild(Node* newChild, Node* oldChild) = 0; - /// Replaces the child node oldChild with newChild in the list of children, - /// and returns the oldChild node. - /// If newChild is a DocumentFragment object, oldChild is replaced by all of - /// the DocumentFragment children, which are inserted in the same order. If - /// the newChild is already in the tree, it is first removed. - - virtual Node* removeChild(Node* oldChild) = 0; - /// Removes the child node indicated by oldChild from the list of children - /// and returns it. - - virtual Node* appendChild(Node* newChild) = 0; - /// Appends the node newChild to the end of the list of children of this node. - /// If newChild is already in the tree, it is first removed. - - virtual bool hasChildNodes() const = 0; - /// This is a convenience method to allow easy determination of whether a - /// node has any children. - /// Returns true if the node has any children, false otherwise. - - virtual Node* cloneNode(bool deep) const = 0; - /// Returns a duplicate of this node, i.e., serves as a generic copy constructor - /// for nodes. The duplicate node has no parent; (parentNode is null.). - /// Cloning an Element copies all attributes and their values, including those - /// generated by the XML processor to represent defaulted attributes, but this - /// method does not copy any text it contains unless it is a deep clone, since - /// the text is contained in a child Text node. Cloning an Attribute directly, - /// as opposed to be cloned as part of an Element cloning operation, returns - /// a specified attribute (specified is true). Cloning any other type of node - /// simply returns a copy of this node. - /// Note that cloning an immutable subtree results in a mutable copy, but the - /// children of an EntityReference clone are readonly. In addition, clones of - /// unspecified Attr nodes are specified. And, cloning Document, DocumentType, - /// Entity, and Notation nodes is implementation dependent. - - // DOM Level 2 - virtual void normalize() = 0; - /// Puts all Text nodes in the full depth of the sub-tree underneath this Node, - /// including attribute nodes, into a "normal" form where only structure (e.g., - /// elements, comments, processing instructions, CDATA sections, and entity - /// references) separates Text nodes, i.e., there are neither adjacent Text - /// nodes nor empty Text nodes. This can be used to ensure that the DOM view - /// of a document is the same as if it were saved and re-loaded, and is useful - /// when operations (such as XPointer lookups) that depend on a particular - /// document tree structure are to be used. - /// - /// Note: In cases where the document contains CDATASections, the normalize - /// operation alone may not be sufficient, since XPointers do not differentiate - /// between Text nodes and CDATASection nodes. - - virtual bool isSupported(const XMLString& feature, const XMLString& version) const = 0; - /// Tests whether the DOM implementation implements a specific - /// feature and that feature is supported by this node. - - virtual const XMLString& namespaceURI() const = 0; - /// Returns the namespace URI of the node. - /// This is not a computed value that is the result of a namespace lookup based on an - /// examination of the namespace declarations in scope. It is merely the namespace URI - /// given at creation time. - /// - /// For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a - /// DOM Level 1 method, such as createElement from the Document interface, this is always the - /// empty string. - - virtual XMLString prefix() const = 0; - /// Returns the namespace prefix from the qualified name of the node. - - virtual const XMLString& localName() const = 0; - /// Returns the local name of the node. - - virtual bool hasAttributes() const = 0; - /// Returns whether this node (if it is an element) has any attributes. - - // Extensions - virtual XMLString innerText() const = 0; - /// Returns a string containing the concatenated values of the node - /// and all its child nodes. - /// - /// This method is not part of the W3C Document Object Model. - -protected: - virtual ~Node(); -}; - - -// -// inlines -// -inline const XMLString& Node::nodeValue() const -{ - return getNodeValue(); -} - - -} } // namespace Poco::XML - - -#endif // DOM_Node_INCLUDED +// +// Node.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Node.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Node interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Node_INCLUDED +#define DOM_Node_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/EventTarget.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class NamedNodeMap; +class Document; +class NodeList; + + +class XML_API Node: public EventTarget + /// The Node interface is the primary datatype for the entire Document Object + /// Model. It represents a single node in the document tree. While all objects + /// implementing the Node interface expose methods for dealing with children, + /// not all objects implementing the Node interface may have children. For + /// example, Text nodes may not have children, and adding children to such + /// nodes results in a DOMException being raised. + /// + /// The attributes nodeName, nodeValue and attributes are included as a mechanism + /// to get at node information without casting down to the specific derived + /// interface. In cases where there is no obvious mapping of these attributes + /// for a specific nodeType (e.g., nodeValue for an Element or attributes for + /// a Comment), this returns null. Note that the specialized interfaces may + /// contain additional and more convenient mechanisms to get and set the relevant + /// information. + /// + /// This implementation differs in some ways from the W3C DOM recommendations. + /// For example, the DOM specifies that some methods can return null strings. + /// Instead of null strings, this implementation always returns empty strings. +{ +public: + enum + { + ELEMENT_NODE = 1, /// The node is an Element. + ATTRIBUTE_NODE, /// The node is an Attr. + TEXT_NODE, /// The node is a Text node. + CDATA_SECTION_NODE, /// The node is a CDATASection. + ENTITY_REFERENCE_NODE, /// The node is an EntityReference. + ENTITY_NODE, /// The node is an Entity. + PROCESSING_INSTRUCTION_NODE, /// The node is a ProcessingInstruction. + COMMENT_NODE, /// The node is a Comment. + DOCUMENT_NODE, /// The node is a Document. + DOCUMENT_TYPE_NODE, /// The node is a DocumentType. + DOCUMENT_FRAGMENT_NODE, /// The node is a DocumentFragment. + NOTATION_NODE /// The node is a Notation. + }; + + virtual const XMLString& nodeName() const = 0; + /// Returns the name of this node, depending on its type. + + const XMLString& nodeValue() const; + /// Returns the value of this node, depending on its type. + + virtual const XMLString& getNodeValue() const = 0; + /// Returns the value of this node, depending on its type. + + virtual void setNodeValue(const XMLString& value) = 0; + /// Sets the value of this node. Throws an exception + /// if the node is read-only. + + virtual unsigned short nodeType() const = 0; + /// Returns a code representing the type of the underlying object. + + virtual Node* parentNode() const = 0; + /// The parent of this node. All nodes, except Attr, Document, DocumentFragment, + /// Entity, and Notation may have a parent. However, if a node has just been + /// created and not yet added to the tree, or if it has been removed from the + /// tree, this is null. + + virtual NodeList* childNodes() const = 0; + /// Returns a NodeList containing all children of this node. + /// + /// The returned NodeList must be released with a call + /// to release() when no longer needed. + + virtual Node* firstChild() const = 0; + /// Returns the first child of this node. If there is no such + /// node, this returns null. + + virtual Node* lastChild() const = 0; + /// Returns the last child of this node. If there is no such + /// node, this returns null. + + virtual Node* previousSibling() const = 0; + /// Returns the node immediately preceding this node. If there + /// is no such node, this returns null. + + virtual Node* nextSibling() const = 0; + /// Returns the node immediately following this node. If there + /// is no such node, this returns null. + + virtual NamedNodeMap* attributes() const = 0; + /// Returns a NamedNodeMap containing the attributes of this + /// node (if it is an Element) or null otherwise. + /// + /// The returned NamedNodeMap must be released with a call + /// to release() when no longer needed. + + virtual Document* ownerDocument() const = 0; + /// Returns the Document object associated with this node. + /// This is also the Document object used to create new nodes. + /// When this node is a Document, this is null. + + virtual Node* insertBefore(Node* newChild, Node* refChild) = 0; + /// Inserts the node newChild before the existing child node refChild. + /// + /// If refChild is null, insert newChild at the end of the list of children. + /// If newChild is a DocumentFragment object, all of its children are + /// inserted in the same order, before refChild. If the newChild is already + /// in the tree, it is first removed. + + virtual Node* replaceChild(Node* newChild, Node* oldChild) = 0; + /// Replaces the child node oldChild with newChild in the list of children, + /// and returns the oldChild node. + /// If newChild is a DocumentFragment object, oldChild is replaced by all of + /// the DocumentFragment children, which are inserted in the same order. If + /// the newChild is already in the tree, it is first removed. + + virtual Node* removeChild(Node* oldChild) = 0; + /// Removes the child node indicated by oldChild from the list of children + /// and returns it. + + virtual Node* appendChild(Node* newChild) = 0; + /// Appends the node newChild to the end of the list of children of this node. + /// If newChild is already in the tree, it is first removed. + + virtual bool hasChildNodes() const = 0; + /// This is a convenience method to allow easy determination of whether a + /// node has any children. + /// Returns true if the node has any children, false otherwise. + + virtual Node* cloneNode(bool deep) const = 0; + /// Returns a duplicate of this node, i.e., serves as a generic copy constructor + /// for nodes. The duplicate node has no parent; (parentNode is null.). + /// Cloning an Element copies all attributes and their values, including those + /// generated by the XML processor to represent defaulted attributes, but this + /// method does not copy any text it contains unless it is a deep clone, since + /// the text is contained in a child Text node. Cloning an Attribute directly, + /// as opposed to be cloned as part of an Element cloning operation, returns + /// a specified attribute (specified is true). Cloning any other type of node + /// simply returns a copy of this node. + /// Note that cloning an immutable subtree results in a mutable copy, but the + /// children of an EntityReference clone are readonly. In addition, clones of + /// unspecified Attr nodes are specified. And, cloning Document, DocumentType, + /// Entity, and Notation nodes is implementation dependent. + + // DOM Level 2 + virtual void normalize() = 0; + /// Puts all Text nodes in the full depth of the sub-tree underneath this Node, + /// including attribute nodes, into a "normal" form where only structure (e.g., + /// elements, comments, processing instructions, CDATA sections, and entity + /// references) separates Text nodes, i.e., there are neither adjacent Text + /// nodes nor empty Text nodes. This can be used to ensure that the DOM view + /// of a document is the same as if it were saved and re-loaded, and is useful + /// when operations (such as XPointer lookups) that depend on a particular + /// document tree structure are to be used. + /// + /// Note: In cases where the document contains CDATASections, the normalize + /// operation alone may not be sufficient, since XPointers do not differentiate + /// between Text nodes and CDATASection nodes. + + virtual bool isSupported(const XMLString& feature, const XMLString& version) const = 0; + /// Tests whether the DOM implementation implements a specific + /// feature and that feature is supported by this node. + + virtual const XMLString& namespaceURI() const = 0; + /// Returns the namespace URI of the node. + /// This is not a computed value that is the result of a namespace lookup based on an + /// examination of the namespace declarations in scope. It is merely the namespace URI + /// given at creation time. + /// + /// For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a + /// DOM Level 1 method, such as createElement from the Document interface, this is always the + /// empty string. + + virtual XMLString prefix() const = 0; + /// Returns the namespace prefix from the qualified name of the node. + + virtual const XMLString& localName() const = 0; + /// Returns the local name of the node. + + virtual bool hasAttributes() const = 0; + /// Returns whether this node (if it is an element) has any attributes. + + // Extensions + virtual XMLString innerText() const = 0; + /// Returns a string containing the concatenated values of the node + /// and all its child nodes. + /// + /// This method is not part of the W3C Document Object Model. + +protected: + virtual ~Node(); +}; + + +// +// inlines +// +inline const XMLString& Node::nodeValue() const +{ + return getNodeValue(); +} + + +} } // namespace Poco::XML + + +#endif // DOM_Node_INCLUDED diff --git a/XML/include/Poco/DOM/NodeAppender.h b/XML/include/Poco/DOM/NodeAppender.h index f14bca1a7..b4d090763 100644 --- a/XML/include/Poco/DOM/NodeAppender.h +++ b/XML/include/Poco/DOM/NodeAppender.h @@ -1,103 +1,103 @@ -// -// NodeAppender.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/NodeAppender.h#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeAppender -// -// Definition of the NodeAppender class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_NodeAppender_INCLUDED -#define DOM_NodeAppender_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/Node.h" - - -namespace Poco { -namespace XML { - - -class AbstractNode; -class Element; - - -class XML_API NodeAppender - /// The NodeAppender class provides a very fast way to - /// build larger DOM documents. - /// - /// In the DOM, child nodes are usually appended to a parent - /// node using the appendChild() method. For nodes containing - /// more than a few children, this method can be quite slow, - /// due to the way it's implemented, and because of the - /// requirements of the DOM specification. - /// - /// While the NodeAppender is being used on an Element, no - /// children-modifying methods of that Element must be used. - /// - /// This class is not part of the DOM specification. -{ -public: - NodeAppender(Element* parent); - /// Creates the NodeAppender for the given parent node, - /// which must be an Element. - - ~NodeAppender(); - /// Destroys the NodeAppender. - - void appendChild(Node* newChild); - /// Appends the node newChild to the end of the list of children of - /// the parent node specified in the constructor. - /// If the newChild is already in the tree, it is first removed. - /// - /// NewChild can be a DocumentFragment. In this case, all children - /// of the fragment become children of the parent element. - /// - /// In order to speed up the function, no DOM events - /// are fired. - -private: - NodeAppender(); - NodeAppender(const NodeAppender&); - NodeAppender& operator = (const NodeAppender&); - - Element* _pParent; - AbstractNode* _pLast; -}; - - -} } // namespace Poco::XML - - -#endif // #include "Poco/XML/XML.h" - +// +// NodeAppender.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/NodeAppender.h#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeAppender +// +// Definition of the NodeAppender class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_NodeAppender_INCLUDED +#define DOM_NodeAppender_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/Node.h" + + +namespace Poco { +namespace XML { + + +class AbstractNode; +class Element; + + +class XML_API NodeAppender + /// The NodeAppender class provides a very fast way to + /// build larger DOM documents. + /// + /// In the DOM, child nodes are usually appended to a parent + /// node using the appendChild() method. For nodes containing + /// more than a few children, this method can be quite slow, + /// due to the way it's implemented, and because of the + /// requirements of the DOM specification. + /// + /// While the NodeAppender is being used on an Element, no + /// children-modifying methods of that Element must be used. + /// + /// This class is not part of the DOM specification. +{ +public: + NodeAppender(Element* parent); + /// Creates the NodeAppender for the given parent node, + /// which must be an Element. + + ~NodeAppender(); + /// Destroys the NodeAppender. + + void appendChild(Node* newChild); + /// Appends the node newChild to the end of the list of children of + /// the parent node specified in the constructor. + /// If the newChild is already in the tree, it is first removed. + /// + /// NewChild can be a DocumentFragment. In this case, all children + /// of the fragment become children of the parent element. + /// + /// In order to speed up the function, no DOM events + /// are fired. + +private: + NodeAppender(); + NodeAppender(const NodeAppender&); + NodeAppender& operator = (const NodeAppender&); + + Element* _pParent; + AbstractNode* _pLast; +}; + + +} } // namespace Poco::XML + + +#endif // #include "Poco/XML/XML.h" + diff --git a/XML/include/Poco/DOM/NodeFilter.h b/XML/include/Poco/DOM/NodeFilter.h index daf49fac0..b6484231a 100644 --- a/XML/include/Poco/DOM/NodeFilter.h +++ b/XML/include/Poco/DOM/NodeFilter.h @@ -1,168 +1,168 @@ -// -// NodeFilter.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/NodeFilter.h#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeFilter -// -// Definition of the DOM NodeFilter interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_NodeFilter_INCLUDED -#define DOM_NodeFilter_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Node; - - -class XML_API NodeFilter - /// Filters are objects that know how to "filter out" nodes. If a NodeIterator - /// or TreeWalker is given a NodeFilter, it applies the filter before it returns - /// the next node. If the filter says to accept the node, the traversal logic - /// returns it; otherwise, traversal looks for the next node and pretends that - /// the node that was rejected was not there. - /// - /// The DOM does not provide any filters. NodeFilter is just an interface that - /// users can implement to provide their own filters. - /// - /// NodeFilters do not need to know how to traverse from node to node, nor do - /// they need to know anything about the data structure that is being traversed. - /// This makes it very easy to write filters, since the only thing they have - /// to know how to do is evaluate a single node. One filter may be used with - /// a number of different kinds of traversals, encouraging code reuse. -{ -public: - enum - { - FILTER_ACCEPT = 1, - /// Accept the node. Navigation methods defined for NodeIterator or TreeWalker will return this node. - - FILTER_REJECT = 2, - /// Reject the node. Navigation methods defined for NodeIterator or TreeWalker - /// will not return this node. For TreeWalker, the children of this node will - /// also be rejected. NodeIterators treat this as a synonym for FILTER_SKIP. - - FILTER_SKIP = 3 - /// Skip this single node. Navigation methods defined for NodeIterator or TreeWalker - /// will not return this node. For both NodeIterator and TreeWalker, the children - /// of this node will still be considered. - }; - - enum WhatToShow - /// These are the available values for the whatToShow parameter used in TreeWalkers - /// and NodeIterators. They are the same as the set of possible types for Node, - /// and their values are derived by using a bit position corresponding to the - /// value of nodeType for the equivalent node type. If a bit in whatToShow is - /// set false, that will be taken as a request to skip over this type of node; - /// the behavior in that case is similar to that of FILTER_SKIP. - /// - /// Note that if node types greater than 32 are ever introduced, they may not - /// be individually testable via whatToShow. If that need should arise, it can - /// be handled by selecting SHOW_ALL together with an appropriate NodeFilter. - { - SHOW_ALL = 0xFFFFFFFF, - /// Show all Nodes. - - SHOW_ELEMENT = 0x00000001, - /// Show Element nodes. - - SHOW_ATTRIBUTE = 0x00000002, - /// Show Attr nodes. This is meaningful only when creating an iterator or tree-walker - /// with an attribute node as its root; in this case, it means that the attribute - /// node will appear in the first position of the iteration or traversal. Since - /// attributes are never children of other nodes, they do not appear when traversing - /// over the document tree. - - SHOW_TEXT = 0x00000004, - /// Show Text nodes. - - SHOW_CDATA_SECTION = 0x00000008, - /// Show CDATASection nodes. - - SHOW_ENTITY_REFERENCE = 0x00000010, - /// Show EntityReference nodes. - - SHOW_ENTITY = 0x00000020, - /// Show Entity nodes. This is meaningful only when creating an iterator or - /// tree-walker with an Entity node as its root; in this case, it means that - /// the Entity node will appear in the first position of the traversal. Since - /// entities are not part of the document tree, they do not appear when traversing - /// over the document tree. - - SHOW_PROCESSING_INSTRUCTION = 0x00000040, - /// Show ProcessingInstruction nodes. - - SHOW_COMMENT = 0x00000080, - /// Show Comment nodes. - - SHOW_DOCUMENT = 0x00000100, - /// Show Document nodes. - - SHOW_DOCUMENT_TYPE = 0x00000200, - /// Show DocumentType nodes. - - SHOW_DOCUMENT_FRAGMENT = 0x00000400, - /// Show DocumentFragment nodes. - - SHOW_NOTATION = 0x00000800 - /// Show Notation nodes. This is meaningful only when creating an iterator or - /// tree-walker with a Notation node as its root; in this case, it means that - /// the Notation node will appear in the first position of the traversal. Since - /// notations are not part of the document tree, they do not appear when traversing - /// over the document tree. - }; - - virtual short acceptNode(Node* node) = 0; - /// Test whether a specified node is visible in the logical view of a TreeWalker - /// or NodeIterator. This function will be called by the implementation of TreeWalker - /// and NodeIterator; it is not normally called directly from user code. (Though - /// you could do so if you wanted to use the same filter to guide your own application - /// logic.) - /// - /// Returns FILTER_ACCEPT, FILTER_REJECT or FILTER_SKIP. - -protected: - virtual ~NodeFilter(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_NodeFilter_INCLUDED +// +// NodeFilter.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/NodeFilter.h#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeFilter +// +// Definition of the DOM NodeFilter interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_NodeFilter_INCLUDED +#define DOM_NodeFilter_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Node; + + +class XML_API NodeFilter + /// Filters are objects that know how to "filter out" nodes. If a NodeIterator + /// or TreeWalker is given a NodeFilter, it applies the filter before it returns + /// the next node. If the filter says to accept the node, the traversal logic + /// returns it; otherwise, traversal looks for the next node and pretends that + /// the node that was rejected was not there. + /// + /// The DOM does not provide any filters. NodeFilter is just an interface that + /// users can implement to provide their own filters. + /// + /// NodeFilters do not need to know how to traverse from node to node, nor do + /// they need to know anything about the data structure that is being traversed. + /// This makes it very easy to write filters, since the only thing they have + /// to know how to do is evaluate a single node. One filter may be used with + /// a number of different kinds of traversals, encouraging code reuse. +{ +public: + enum + { + FILTER_ACCEPT = 1, + /// Accept the node. Navigation methods defined for NodeIterator or TreeWalker will return this node. + + FILTER_REJECT = 2, + /// Reject the node. Navigation methods defined for NodeIterator or TreeWalker + /// will not return this node. For TreeWalker, the children of this node will + /// also be rejected. NodeIterators treat this as a synonym for FILTER_SKIP. + + FILTER_SKIP = 3 + /// Skip this single node. Navigation methods defined for NodeIterator or TreeWalker + /// will not return this node. For both NodeIterator and TreeWalker, the children + /// of this node will still be considered. + }; + + enum WhatToShow + /// These are the available values for the whatToShow parameter used in TreeWalkers + /// and NodeIterators. They are the same as the set of possible types for Node, + /// and their values are derived by using a bit position corresponding to the + /// value of nodeType for the equivalent node type. If a bit in whatToShow is + /// set false, that will be taken as a request to skip over this type of node; + /// the behavior in that case is similar to that of FILTER_SKIP. + /// + /// Note that if node types greater than 32 are ever introduced, they may not + /// be individually testable via whatToShow. If that need should arise, it can + /// be handled by selecting SHOW_ALL together with an appropriate NodeFilter. + { + SHOW_ALL = 0xFFFFFFFF, + /// Show all Nodes. + + SHOW_ELEMENT = 0x00000001, + /// Show Element nodes. + + SHOW_ATTRIBUTE = 0x00000002, + /// Show Attr nodes. This is meaningful only when creating an iterator or tree-walker + /// with an attribute node as its root; in this case, it means that the attribute + /// node will appear in the first position of the iteration or traversal. Since + /// attributes are never children of other nodes, they do not appear when traversing + /// over the document tree. + + SHOW_TEXT = 0x00000004, + /// Show Text nodes. + + SHOW_CDATA_SECTION = 0x00000008, + /// Show CDATASection nodes. + + SHOW_ENTITY_REFERENCE = 0x00000010, + /// Show EntityReference nodes. + + SHOW_ENTITY = 0x00000020, + /// Show Entity nodes. This is meaningful only when creating an iterator or + /// tree-walker with an Entity node as its root; in this case, it means that + /// the Entity node will appear in the first position of the traversal. Since + /// entities are not part of the document tree, they do not appear when traversing + /// over the document tree. + + SHOW_PROCESSING_INSTRUCTION = 0x00000040, + /// Show ProcessingInstruction nodes. + + SHOW_COMMENT = 0x00000080, + /// Show Comment nodes. + + SHOW_DOCUMENT = 0x00000100, + /// Show Document nodes. + + SHOW_DOCUMENT_TYPE = 0x00000200, + /// Show DocumentType nodes. + + SHOW_DOCUMENT_FRAGMENT = 0x00000400, + /// Show DocumentFragment nodes. + + SHOW_NOTATION = 0x00000800 + /// Show Notation nodes. This is meaningful only when creating an iterator or + /// tree-walker with a Notation node as its root; in this case, it means that + /// the Notation node will appear in the first position of the traversal. Since + /// notations are not part of the document tree, they do not appear when traversing + /// over the document tree. + }; + + virtual short acceptNode(Node* node) = 0; + /// Test whether a specified node is visible in the logical view of a TreeWalker + /// or NodeIterator. This function will be called by the implementation of TreeWalker + /// and NodeIterator; it is not normally called directly from user code. (Though + /// you could do so if you wanted to use the same filter to guide your own application + /// logic.) + /// + /// Returns FILTER_ACCEPT, FILTER_REJECT or FILTER_SKIP. + +protected: + virtual ~NodeFilter(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_NodeFilter_INCLUDED diff --git a/XML/include/Poco/DOM/NodeIterator.h b/XML/include/Poco/DOM/NodeIterator.h index 9ecc2ee9a..cf2702a33 100644 --- a/XML/include/Poco/DOM/NodeIterator.h +++ b/XML/include/Poco/DOM/NodeIterator.h @@ -1,189 +1,189 @@ -// -// NodeIterator.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/NodeIterator.h#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeIterator -// -// Definition of the DOM NodeIterator class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_NodeIterator_INCLUDED -#define DOM_NodeIterator_INCLUDED - - -#include "Poco/XML/XML.h" - - -namespace Poco { -namespace XML { - - -class Node; -class NodeFilter; - - -class XML_API NodeIterator - /// Iterators are used to step through a set of nodes, e.g. the set of nodes - /// in a NodeList, the document subtree governed by a particular Node, the results - /// of a query, or any other set of nodes. The set of nodes to be iterated is - /// determined by the implementation of the NodeIterator. DOM Level 2 specifies - /// a single NodeIterator implementation for document-order traversal of a document - /// subtree. - /// - /// A NodeIterator can be directly instantiated using one of its constructors - - /// the DocumentTraversal interface is not needed and therefore not implemented. - /// Unlike most other DOM classes, NodeIterator supports value semantics. - /// - /// If the NodeIterator's current node is removed from the document, the - /// result of calling any of the movement methods is undefined. This behavior does - /// not conform to the DOM Level 2 Traversal specification. -{ -public: - NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter = 0); - /// Creates a NodeIterator over the subtree rooted at the specified node. - - NodeIterator(const NodeIterator& iterator); - /// Creates a NodeIterator by copying another NodeIterator. - - NodeIterator& operator = (const NodeIterator& iterator); - /// Assignment operator. - - ~NodeIterator(); - /// Destroys the NodeIterator. - - Node* root() const; - /// The root node of the NodeIterator, as specified when it was created. - - unsigned long whatToShow() const; - /// This attribute determines which node types are presented via the iterator. - /// The available set of constants is defined in the NodeFilter interface. - /// Nodes not accepted by whatToShow will be skipped, but their children may - /// still be considered. Note that this skip takes precedence over the filter, - /// if any. - - NodeFilter* filter() const; - /// The NodeFilter used to screen nodes. - - bool expandEntityReferences() const; - /// The value of this flag determines whether the children of entity reference - /// nodes are visible to the iterator. If false, they and their descendants - /// will be rejected. Note that this rejection takes precedence over whatToShow - /// and the filter. Also note that this is currently the only situation where - /// NodeIterators may reject a complete subtree rather than skipping individual - /// nodes. - /// - /// To produce a view of the document that has entity references expanded and - /// does not expose the entity reference node itself, use the whatToShow flags - /// to hide the entity reference node and set expandEntityReferences to true - /// when creating the iterator. To produce a view of the document that has entity - /// reference nodes but no entity expansion, use the whatToShow flags to show - /// the entity reference node and set expandEntityReferences to false. - /// - /// This implementation does not support entity reference expansion and - /// thus always returns false. - - Node* nextNode(); - /// Returns the next node in the set and advances the position of the iterator - /// in the set. After a NodeIterator is created, the first call to nextNode() - /// returns the first node in the set. - - Node* previousNode(); - /// Returns the previous node in the set and moves the position of the NodeIterator - /// backwards in the set. - - Node* currentNodeNP() const; - /// Returns the current node in the set. - /// - /// Leaves the NodeIterator unchanged. - /// - /// Warning: This is a proprietary extension to the DOM Level 2 NodeIterator - /// interface. - - void detach(); - /// Detaches the NodeIterator from the set which it iterated over, releasing - /// any computational resources and placing the iterator in the INVALID state. - /// After detach has been invoked, calls to nextNode or previousNode will raise - /// the exception INVALID_STATE_ERR. - -protected: - bool accept(Node* pNode) const; - Node* next() const; - Node* previous() const; - Node* last(); - -private: - NodeIterator(); - - Node* _pRoot; - unsigned long _whatToShow; - NodeFilter* _pFilter; - Node* _pCurrent; -}; - - -// -// inlines -// -inline Node* NodeIterator::root() const -{ - return _pRoot; -} - - -inline Node* NodeIterator::currentNodeNP() const -{ - return _pCurrent; -} - - -inline unsigned long NodeIterator::whatToShow() const -{ - return _whatToShow; -} - - -inline NodeFilter* NodeIterator::filter() const -{ - return _pFilter; -} - - -inline bool NodeIterator::expandEntityReferences() const -{ - return false; -} - - -} } // namespace Poco::XML - - -#endif // DOM_NodeIterator_INCLUDED +// +// NodeIterator.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/NodeIterator.h#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeIterator +// +// Definition of the DOM NodeIterator class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_NodeIterator_INCLUDED +#define DOM_NodeIterator_INCLUDED + + +#include "Poco/XML/XML.h" + + +namespace Poco { +namespace XML { + + +class Node; +class NodeFilter; + + +class XML_API NodeIterator + /// Iterators are used to step through a set of nodes, e.g. the set of nodes + /// in a NodeList, the document subtree governed by a particular Node, the results + /// of a query, or any other set of nodes. The set of nodes to be iterated is + /// determined by the implementation of the NodeIterator. DOM Level 2 specifies + /// a single NodeIterator implementation for document-order traversal of a document + /// subtree. + /// + /// A NodeIterator can be directly instantiated using one of its constructors - + /// the DocumentTraversal interface is not needed and therefore not implemented. + /// Unlike most other DOM classes, NodeIterator supports value semantics. + /// + /// If the NodeIterator's current node is removed from the document, the + /// result of calling any of the movement methods is undefined. This behavior does + /// not conform to the DOM Level 2 Traversal specification. +{ +public: + NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter = 0); + /// Creates a NodeIterator over the subtree rooted at the specified node. + + NodeIterator(const NodeIterator& iterator); + /// Creates a NodeIterator by copying another NodeIterator. + + NodeIterator& operator = (const NodeIterator& iterator); + /// Assignment operator. + + ~NodeIterator(); + /// Destroys the NodeIterator. + + Node* root() const; + /// The root node of the NodeIterator, as specified when it was created. + + unsigned long whatToShow() const; + /// This attribute determines which node types are presented via the iterator. + /// The available set of constants is defined in the NodeFilter interface. + /// Nodes not accepted by whatToShow will be skipped, but their children may + /// still be considered. Note that this skip takes precedence over the filter, + /// if any. + + NodeFilter* filter() const; + /// The NodeFilter used to screen nodes. + + bool expandEntityReferences() const; + /// The value of this flag determines whether the children of entity reference + /// nodes are visible to the iterator. If false, they and their descendants + /// will be rejected. Note that this rejection takes precedence over whatToShow + /// and the filter. Also note that this is currently the only situation where + /// NodeIterators may reject a complete subtree rather than skipping individual + /// nodes. + /// + /// To produce a view of the document that has entity references expanded and + /// does not expose the entity reference node itself, use the whatToShow flags + /// to hide the entity reference node and set expandEntityReferences to true + /// when creating the iterator. To produce a view of the document that has entity + /// reference nodes but no entity expansion, use the whatToShow flags to show + /// the entity reference node and set expandEntityReferences to false. + /// + /// This implementation does not support entity reference expansion and + /// thus always returns false. + + Node* nextNode(); + /// Returns the next node in the set and advances the position of the iterator + /// in the set. After a NodeIterator is created, the first call to nextNode() + /// returns the first node in the set. + + Node* previousNode(); + /// Returns the previous node in the set and moves the position of the NodeIterator + /// backwards in the set. + + Node* currentNodeNP() const; + /// Returns the current node in the set. + /// + /// Leaves the NodeIterator unchanged. + /// + /// Warning: This is a proprietary extension to the DOM Level 2 NodeIterator + /// interface. + + void detach(); + /// Detaches the NodeIterator from the set which it iterated over, releasing + /// any computational resources and placing the iterator in the INVALID state. + /// After detach has been invoked, calls to nextNode or previousNode will raise + /// the exception INVALID_STATE_ERR. + +protected: + bool accept(Node* pNode) const; + Node* next() const; + Node* previous() const; + Node* last(); + +private: + NodeIterator(); + + Node* _pRoot; + unsigned long _whatToShow; + NodeFilter* _pFilter; + Node* _pCurrent; +}; + + +// +// inlines +// +inline Node* NodeIterator::root() const +{ + return _pRoot; +} + + +inline Node* NodeIterator::currentNodeNP() const +{ + return _pCurrent; +} + + +inline unsigned long NodeIterator::whatToShow() const +{ + return _whatToShow; +} + + +inline NodeFilter* NodeIterator::filter() const +{ + return _pFilter; +} + + +inline bool NodeIterator::expandEntityReferences() const +{ + return false; +} + + +} } // namespace Poco::XML + + +#endif // DOM_NodeIterator_INCLUDED diff --git a/XML/include/Poco/DOM/NodeList.h b/XML/include/Poco/DOM/NodeList.h index 7a3ce211b..621e4af9d 100644 --- a/XML/include/Poco/DOM/NodeList.h +++ b/XML/include/Poco/DOM/NodeList.h @@ -1,83 +1,83 @@ -// -// NodeList.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/NodeList.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM NodeList interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_NodeList_INCLUDED -#define DOM_NodeList_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/DOMObject.h" - - -namespace Poco { -namespace XML { - - -class Node; - - -class XML_API NodeList: public DOMObject - /// The NodeList interface provides the abstraction of an ordered - /// collection of nodes, without defining or constraining how this - /// collection is implemented. - /// - /// The items in the NodeList are accessible via an integral index, - /// starting from 0. - /// - /// A NodeList returned from a method must be released with a call to - /// release() when no longer needed. -{ -public: - virtual Node* item(unsigned long index) const = 0; - /// Returns the index'th item in the collection. If index is - /// greater than or equal to the number of nodes in the list, - /// this returns null. - - virtual unsigned long length() const = 0; - /// Returns the number of nodes in the list. The range of valid - /// node indices is 0 to length - 1 inclusive. - -protected: - virtual ~NodeList(); -}; - - -} } // namespace Poco::XML - - -#endif // DOM_NodeList_INCLUDED +// +// NodeList.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/NodeList.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM NodeList interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_NodeList_INCLUDED +#define DOM_NodeList_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/DOMObject.h" + + +namespace Poco { +namespace XML { + + +class Node; + + +class XML_API NodeList: public DOMObject + /// The NodeList interface provides the abstraction of an ordered + /// collection of nodes, without defining or constraining how this + /// collection is implemented. + /// + /// The items in the NodeList are accessible via an integral index, + /// starting from 0. + /// + /// A NodeList returned from a method must be released with a call to + /// release() when no longer needed. +{ +public: + virtual Node* item(unsigned long index) const = 0; + /// Returns the index'th item in the collection. If index is + /// greater than or equal to the number of nodes in the list, + /// this returns null. + + virtual unsigned long length() const = 0; + /// Returns the number of nodes in the list. The range of valid + /// node indices is 0 to length - 1 inclusive. + +protected: + virtual ~NodeList(); +}; + + +} } // namespace Poco::XML + + +#endif // DOM_NodeList_INCLUDED diff --git a/XML/include/Poco/DOM/Notation.h b/XML/include/Poco/DOM/Notation.h index 71ac20b81..cacc7112c 100644 --- a/XML/include/Poco/DOM/Notation.h +++ b/XML/include/Poco/DOM/Notation.h @@ -1,115 +1,115 @@ -// -// Notation.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Notation.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Notation class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Notation_INCLUDED -#define DOM_Notation_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Notation: public AbstractNode - /// This interface represents a notation declared in the DTD. A notation either - /// declares, by name, the format of an unparsed entity (see section 4.7 of - /// the XML 1.0 specification ), - /// or is used for formal declaration of processing - /// instruction targets (see section 2.6 of the XML 1.0 specification). - /// The nodeName attribute inherited from Node is set to the declared name of - /// the notation. - /// - /// The DOM Level 1 does not support editing Notation nodes; they are therefore - /// readonly. - /// - /// A Notation node does not have any parent. -{ -public: - const XMLString& publicId() const; - /// Returns the public identifier of this notation. - /// If not specified, this is an empty string (and not null, - /// as in the DOM specification). - - const XMLString& systemId() const; - /// Returns the system identifier of this notation. - /// If not specified, this is an empty string (and not null, - /// as in the DOM specification). - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - -protected: - Notation(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId); - Notation(Document* pOwnerDocument, const Notation& notation); - ~Notation(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - XMLString _name; - XMLString _publicId; - XMLString _systemId; - - friend class Document; -}; - - -// -// inlines -// -inline const XMLString& Notation::publicId() const -{ - return _publicId; -} - - -inline const XMLString& Notation::systemId() const -{ - return _systemId; -} - - -} } // namespace Poco::XML - - -#endif // DOM_Notation_INCLUDED +// +// Notation.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Notation.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Notation class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Notation_INCLUDED +#define DOM_Notation_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Notation: public AbstractNode + /// This interface represents a notation declared in the DTD. A notation either + /// declares, by name, the format of an unparsed entity (see section 4.7 of + /// the XML 1.0 specification ), + /// or is used for formal declaration of processing + /// instruction targets (see section 2.6 of the XML 1.0 specification). + /// The nodeName attribute inherited from Node is set to the declared name of + /// the notation. + /// + /// The DOM Level 1 does not support editing Notation nodes; they are therefore + /// readonly. + /// + /// A Notation node does not have any parent. +{ +public: + const XMLString& publicId() const; + /// Returns the public identifier of this notation. + /// If not specified, this is an empty string (and not null, + /// as in the DOM specification). + + const XMLString& systemId() const; + /// Returns the system identifier of this notation. + /// If not specified, this is an empty string (and not null, + /// as in the DOM specification). + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + +protected: + Notation(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId); + Notation(Document* pOwnerDocument, const Notation& notation); + ~Notation(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + XMLString _name; + XMLString _publicId; + XMLString _systemId; + + friend class Document; +}; + + +// +// inlines +// +inline const XMLString& Notation::publicId() const +{ + return _publicId; +} + + +inline const XMLString& Notation::systemId() const +{ + return _systemId; +} + + +} } // namespace Poco::XML + + +#endif // DOM_Notation_INCLUDED diff --git a/XML/include/Poco/DOM/ProcessingInstruction.h b/XML/include/Poco/DOM/ProcessingInstruction.h index 1218d330c..76e57b5a1 100644 --- a/XML/include/Poco/DOM/ProcessingInstruction.h +++ b/XML/include/Poco/DOM/ProcessingInstruction.h @@ -1,121 +1,121 @@ -// -// ProcessingInstruction.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/ProcessingInstruction.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM ProcessingInstruction class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_ProcessingInstruction_INCLUDED -#define DOM_ProcessingInstruction_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API ProcessingInstruction: public AbstractNode - /// The ProcessingInstruction interface represents a "processing instruction", - /// used in XML as a way to keep processor-specific information in the text - /// of the document. -{ -public: - const XMLString& target() const; - /// Returns the target of this processing instruction. - /// XML defines this as being the first token following - /// the markup that begins the processing instruction. - - const XMLString& data() const; - /// Returns the content of this processing instruction. This is from the first non - /// white space character after the target to the character immediately preceding - /// the ?>. - - const XMLString& getData() const; - /// Returns the content of this processing instruction. This is from the first non - /// white space character after the target to the character immediately preceding - /// the ?>. - - void setData(const XMLString& data); - /// Sets the content of this processing instruction. - - // Node - const XMLString& nodeName() const; - const XMLString& getNodeValue() const; - void setNodeValue(const XMLString& data); - unsigned short nodeType() const; - -protected: - ProcessingInstruction(Document* pOwnerDocument, const XMLString& target, const XMLString& data); - ProcessingInstruction(Document* pOwnerDocument, const ProcessingInstruction& processingInstruction); - ~ProcessingInstruction(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - XMLString _target; - XMLString _data; - - friend class Document; -}; - - -// -// inlines -// -inline const XMLString& ProcessingInstruction::target() const -{ - return _target; -} - - -inline const XMLString& ProcessingInstruction::data() const -{ - return _data; -} - - -inline const XMLString& ProcessingInstruction::getData() const -{ - return _data; -} - - -} } // namespace Poco::XML - - -#endif // DOM_ProcessingInstruction_INCLUDED +// +// ProcessingInstruction.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/ProcessingInstruction.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM ProcessingInstruction class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_ProcessingInstruction_INCLUDED +#define DOM_ProcessingInstruction_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API ProcessingInstruction: public AbstractNode + /// The ProcessingInstruction interface represents a "processing instruction", + /// used in XML as a way to keep processor-specific information in the text + /// of the document. +{ +public: + const XMLString& target() const; + /// Returns the target of this processing instruction. + /// XML defines this as being the first token following + /// the markup that begins the processing instruction. + + const XMLString& data() const; + /// Returns the content of this processing instruction. This is from the first non + /// white space character after the target to the character immediately preceding + /// the ?>. + + const XMLString& getData() const; + /// Returns the content of this processing instruction. This is from the first non + /// white space character after the target to the character immediately preceding + /// the ?>. + + void setData(const XMLString& data); + /// Sets the content of this processing instruction. + + // Node + const XMLString& nodeName() const; + const XMLString& getNodeValue() const; + void setNodeValue(const XMLString& data); + unsigned short nodeType() const; + +protected: + ProcessingInstruction(Document* pOwnerDocument, const XMLString& target, const XMLString& data); + ProcessingInstruction(Document* pOwnerDocument, const ProcessingInstruction& processingInstruction); + ~ProcessingInstruction(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + XMLString _target; + XMLString _data; + + friend class Document; +}; + + +// +// inlines +// +inline const XMLString& ProcessingInstruction::target() const +{ + return _target; +} + + +inline const XMLString& ProcessingInstruction::data() const +{ + return _data; +} + + +inline const XMLString& ProcessingInstruction::getData() const +{ + return _data; +} + + +} } // namespace Poco::XML + + +#endif // DOM_ProcessingInstruction_INCLUDED diff --git a/XML/include/Poco/DOM/Text.h b/XML/include/Poco/DOM/Text.h index ed36ddff1..4f893e346 100644 --- a/XML/include/Poco/DOM/Text.h +++ b/XML/include/Poco/DOM/Text.h @@ -1,101 +1,101 @@ -// -// Text.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/Text.h#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Definition of the DOM Text class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_Text_INCLUDED -#define DOM_Text_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/DOM/CharacterData.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Text: public CharacterData - /// The Text interface inherits from CharacterData and represents the textual - /// content (termed character data in XML) of an Element or Attr. If there is - /// no markup inside an element's content, the text is contained in a single - /// object implementing the Text interface that is the only child of the element. - /// If there is markup, it is parsed into the information items (elements, comments, - /// etc.) and Text nodes that form the list of children of the element. - /// - /// When a document is first made available via the DOM, there is only one Text - /// node for each block of text. Users may create adjacent Text nodes that represent - /// the contents of a given element without any intervening markup, but should - /// be aware that there is no way to represent the separations between these - /// nodes in XML or HTML, so they will not (in general) persist between DOM - /// editing sessions. The normalize() method on Element merges any such adjacent - /// Text objects into a single node for each block of text. -{ -public: - Text* splitText(unsigned long offset); - /// Breaks this node into two nodes at the specified offset, keeping both in - /// the tree as siblings. This node then only contains all the content up to - /// the offset point. A new node of the same type, which is inserted as the - /// next sibling of this node, contains all the content at and after the offset - /// point. When the offset is equal to the length of this node, the new node - /// has no data. - - // Node - const XMLString& nodeName() const; - unsigned short nodeType() const; - - // Non-standard extensions - XMLString innerText() const; - -protected: - Text(Document* pOwnerDocument, const XMLString& data); - Text(Document* pOwnerDocument, const Text& text); - ~Text(); - - Node* copyNode(bool deep, Document* pOwnerDocument) const; - -private: - static const XMLString NODE_NAME; - - friend class Document; -}; - - -} } // namespace Poco::XML - - -#endif // DOM_Text_INCLUDED +// +// Text.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/Text.h#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Definition of the DOM Text class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_Text_INCLUDED +#define DOM_Text_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/DOM/CharacterData.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Text: public CharacterData + /// The Text interface inherits from CharacterData and represents the textual + /// content (termed character data in XML) of an Element or Attr. If there is + /// no markup inside an element's content, the text is contained in a single + /// object implementing the Text interface that is the only child of the element. + /// If there is markup, it is parsed into the information items (elements, comments, + /// etc.) and Text nodes that form the list of children of the element. + /// + /// When a document is first made available via the DOM, there is only one Text + /// node for each block of text. Users may create adjacent Text nodes that represent + /// the contents of a given element without any intervening markup, but should + /// be aware that there is no way to represent the separations between these + /// nodes in XML or HTML, so they will not (in general) persist between DOM + /// editing sessions. The normalize() method on Element merges any such adjacent + /// Text objects into a single node for each block of text. +{ +public: + Text* splitText(unsigned long offset); + /// Breaks this node into two nodes at the specified offset, keeping both in + /// the tree as siblings. This node then only contains all the content up to + /// the offset point. A new node of the same type, which is inserted as the + /// next sibling of this node, contains all the content at and after the offset + /// point. When the offset is equal to the length of this node, the new node + /// has no data. + + // Node + const XMLString& nodeName() const; + unsigned short nodeType() const; + + // Non-standard extensions + XMLString innerText() const; + +protected: + Text(Document* pOwnerDocument, const XMLString& data); + Text(Document* pOwnerDocument, const Text& text); + ~Text(); + + Node* copyNode(bool deep, Document* pOwnerDocument) const; + +private: + static const XMLString NODE_NAME; + + friend class Document; +}; + + +} } // namespace Poco::XML + + +#endif // DOM_Text_INCLUDED diff --git a/XML/include/Poco/DOM/TreeWalker.h b/XML/include/Poco/DOM/TreeWalker.h index 964695e2e..02921628f 100644 --- a/XML/include/Poco/DOM/TreeWalker.h +++ b/XML/include/Poco/DOM/TreeWalker.h @@ -1,233 +1,233 @@ -// -// TreeWalker.h -// -// $Id: //poco/1.3/XML/include/Poco/DOM/TreeWalker.h#1 $ -// -// Library: XML -// Package: DOM -// Module: TreeWalker -// -// Definition of the DOM TreeWalker class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOM_TreeWalker_INCLUDED -#define DOM_TreeWalker_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Node; -class NodeFilter; - - -class XML_API TreeWalker - /// TreeWalker objects are used to navigate a document tree or subtree using - /// the view of the document defined by their whatToShow flags and filter (if - /// any). Any function which performs navigation using a TreeWalker will automatically - /// support any view defined by a TreeWalker. - /// - /// Omitting nodes from the logical view of a subtree can result in a structure - /// that is substantially different from the same subtree in the complete, unfiltered - /// document. Nodes that are siblings in the TreeWalker view may be children - /// of different, widely separated nodes in the original view. For instance, - /// consider a NodeFilter that skips all nodes except for Text nodes and the - /// root node of a document. In the logical view that results, all text nodes - /// will be siblings and appear as direct children of the root node, no matter - /// how deeply nested the structure of the original document. - /// - /// A TreeWalker can be directly instantiated using one of its constructors - - /// the DocumentTraversal interface is not needed and therefore not implemented. - /// Unlike most other DOM classes, TreeWalker supports value semantics. - /// - /// If the TreeWalker's current node is removed from the document, the - /// result of calling any of the movement methods is undefined. This behavior - /// does not conform to the DOM Level 2 Traversal specification. -{ -public: - TreeWalker(Node* root, unsigned long whatToShow, NodeFilter* pFilter = 0); - /// Creates a TreeWalker over the subtree rooted at the specified node. - - TreeWalker(const TreeWalker& walker); - /// Creates a TreeWalker by copying another NodeIterator. - - TreeWalker& operator = (const TreeWalker& walker); - /// Assignment operator. - - ~TreeWalker(); - /// Destroys the TreeWalker. - - Node* root() const; - /// The root node of the TreeWalker, as specified when it was created. - - unsigned long whatToShow() const; - /// This attribute determines which node types are presented via the TreeWalker. - /// The available set of constants is defined in the NodeFilter interface. Nodes - /// not accepted by whatToShow will be skipped, but their children may still - /// be considered. Note that this skip takes precedence over the filter, if - /// any. - - NodeFilter* filter() const; - /// The NodeFilter used to screen nodes. - - bool expandEntityReferences() const; - /// The value of this flag determines whether the children of entity reference - /// nodes are visible to the iterator. If false, they and their descendants - /// will be rejected. Note that this rejection takes precedence over whatToShow - /// and the filter. Also note that this is currently the only situation where - /// NodeIterators may reject a complete subtree rather than skipping individual - /// nodes. - /// - /// To produce a view of the document that has entity references expanded and - /// does not expose the entity reference node itself, use the whatToShow flags - /// to hide the entity reference node and set expandEntityReferences to true - /// when creating the iterator. To produce a view of the document that has entity - /// reference nodes but no entity expansion, use the whatToShow flags to show - /// the entity reference node and set expandEntityReferences to false. - /// - /// This implementation does not support entity reference expansion and - /// thus always returns false. - - Node* currentNode() const; - /// The node at which the TreeWalker is currently positioned. - /// Alterations to the DOM tree may cause the current node to no longer be accepted - /// by the TreeWalker's associated filter. currentNode may also be explicitly - /// set to any node, whether or not it is within the subtree specified by the - /// root node or would be accepted by the filter and whatToShow flags. Further - /// traversal occurs relative to currentNode even if it is not part of the current - /// view, by applying the filters in the requested direction; if no traversal - /// is possible, currentNode is not changed. - - Node* getCurrentNode() const; - /// See currentNode(). - - void setCurrentNode(Node* pNode); - /// Sets the current node. - - Node* parentNode(); - /// Moves to and returns the closest visible ancestor node of the current node. - /// If the search for parentNode attempts to step upward from the TreeWalker's - /// root node, or if it fails to find a visible ancestor node, this method retains - /// the current position and returns null. - - Node* firstChild(); - /// Moves the TreeWalker to the first visible child of the current node, and - /// returns the new node. If the current node has no visible children, returns - /// null, and retains the current node. - - Node* lastChild(); - /// Moves the TreeWalker to the last visible child of the current node, and - /// returns the new node. If the current node has no visible children, returns - /// null, and retains the current node. - - Node* previousSibling(); - /// Moves the TreeWalker to the previous sibling of the current node, and returns - /// the new node. If the current node has no visible previous sibling, returns - /// null, and retains the current node. - - Node* nextSibling(); - /// Moves the TreeWalker to the next sibling of the current node, and returns - /// the new node. If the current node has no visible next sibling, returns null, - /// and retains the current node. - - Node* previousNode(); - /// Moves the TreeWalker to the previous visible node in document order relative - /// to the current node, and returns the new node. If the current node has no - /// previous node, or if the search for previousNode attempts to step upward - /// from the TreeWalker's root node, returns null, and retains the current node. - - Node* nextNode(); - /// Moves the TreeWalker to the next visible node in document order relative - /// to the current node, and returns the new node. If the current node has no - /// next node, or if the search for nextNode attempts to step upward from the - /// TreeWalker's root node, returns null, and retains the current node. - -protected: - int accept(Node* pNode) const; - Node* next(Node* pNode) const; - Node* previous(Node* pNode) const; - -private: - TreeWalker(); - - Node* _pRoot; - unsigned long _whatToShow; - NodeFilter* _pFilter; - Node* _pCurrent; -}; - - -// -// inlines -// -inline Node* TreeWalker::root() const -{ - return _pRoot; -} - - -inline unsigned long TreeWalker::whatToShow() const -{ - return _whatToShow; -} - - -inline NodeFilter* TreeWalker::filter() const -{ - return _pFilter; -} - - -inline bool TreeWalker::expandEntityReferences() const -{ - return false; -} - - -inline Node* TreeWalker::currentNode() const -{ - return _pCurrent; -} - - -inline Node* TreeWalker::getCurrentNode() const -{ - return _pCurrent; -} - - -} } // namespace Poco::XML - - -#endif // DOM_TreeWalker_INCLUDED +// +// TreeWalker.h +// +// $Id: //poco/1.3/XML/include/Poco/DOM/TreeWalker.h#1 $ +// +// Library: XML +// Package: DOM +// Module: TreeWalker +// +// Definition of the DOM TreeWalker class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOM_TreeWalker_INCLUDED +#define DOM_TreeWalker_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Node; +class NodeFilter; + + +class XML_API TreeWalker + /// TreeWalker objects are used to navigate a document tree or subtree using + /// the view of the document defined by their whatToShow flags and filter (if + /// any). Any function which performs navigation using a TreeWalker will automatically + /// support any view defined by a TreeWalker. + /// + /// Omitting nodes from the logical view of a subtree can result in a structure + /// that is substantially different from the same subtree in the complete, unfiltered + /// document. Nodes that are siblings in the TreeWalker view may be children + /// of different, widely separated nodes in the original view. For instance, + /// consider a NodeFilter that skips all nodes except for Text nodes and the + /// root node of a document. In the logical view that results, all text nodes + /// will be siblings and appear as direct children of the root node, no matter + /// how deeply nested the structure of the original document. + /// + /// A TreeWalker can be directly instantiated using one of its constructors - + /// the DocumentTraversal interface is not needed and therefore not implemented. + /// Unlike most other DOM classes, TreeWalker supports value semantics. + /// + /// If the TreeWalker's current node is removed from the document, the + /// result of calling any of the movement methods is undefined. This behavior + /// does not conform to the DOM Level 2 Traversal specification. +{ +public: + TreeWalker(Node* root, unsigned long whatToShow, NodeFilter* pFilter = 0); + /// Creates a TreeWalker over the subtree rooted at the specified node. + + TreeWalker(const TreeWalker& walker); + /// Creates a TreeWalker by copying another NodeIterator. + + TreeWalker& operator = (const TreeWalker& walker); + /// Assignment operator. + + ~TreeWalker(); + /// Destroys the TreeWalker. + + Node* root() const; + /// The root node of the TreeWalker, as specified when it was created. + + unsigned long whatToShow() const; + /// This attribute determines which node types are presented via the TreeWalker. + /// The available set of constants is defined in the NodeFilter interface. Nodes + /// not accepted by whatToShow will be skipped, but their children may still + /// be considered. Note that this skip takes precedence over the filter, if + /// any. + + NodeFilter* filter() const; + /// The NodeFilter used to screen nodes. + + bool expandEntityReferences() const; + /// The value of this flag determines whether the children of entity reference + /// nodes are visible to the iterator. If false, they and their descendants + /// will be rejected. Note that this rejection takes precedence over whatToShow + /// and the filter. Also note that this is currently the only situation where + /// NodeIterators may reject a complete subtree rather than skipping individual + /// nodes. + /// + /// To produce a view of the document that has entity references expanded and + /// does not expose the entity reference node itself, use the whatToShow flags + /// to hide the entity reference node and set expandEntityReferences to true + /// when creating the iterator. To produce a view of the document that has entity + /// reference nodes but no entity expansion, use the whatToShow flags to show + /// the entity reference node and set expandEntityReferences to false. + /// + /// This implementation does not support entity reference expansion and + /// thus always returns false. + + Node* currentNode() const; + /// The node at which the TreeWalker is currently positioned. + /// Alterations to the DOM tree may cause the current node to no longer be accepted + /// by the TreeWalker's associated filter. currentNode may also be explicitly + /// set to any node, whether or not it is within the subtree specified by the + /// root node or would be accepted by the filter and whatToShow flags. Further + /// traversal occurs relative to currentNode even if it is not part of the current + /// view, by applying the filters in the requested direction; if no traversal + /// is possible, currentNode is not changed. + + Node* getCurrentNode() const; + /// See currentNode(). + + void setCurrentNode(Node* pNode); + /// Sets the current node. + + Node* parentNode(); + /// Moves to and returns the closest visible ancestor node of the current node. + /// If the search for parentNode attempts to step upward from the TreeWalker's + /// root node, or if it fails to find a visible ancestor node, this method retains + /// the current position and returns null. + + Node* firstChild(); + /// Moves the TreeWalker to the first visible child of the current node, and + /// returns the new node. If the current node has no visible children, returns + /// null, and retains the current node. + + Node* lastChild(); + /// Moves the TreeWalker to the last visible child of the current node, and + /// returns the new node. If the current node has no visible children, returns + /// null, and retains the current node. + + Node* previousSibling(); + /// Moves the TreeWalker to the previous sibling of the current node, and returns + /// the new node. If the current node has no visible previous sibling, returns + /// null, and retains the current node. + + Node* nextSibling(); + /// Moves the TreeWalker to the next sibling of the current node, and returns + /// the new node. If the current node has no visible next sibling, returns null, + /// and retains the current node. + + Node* previousNode(); + /// Moves the TreeWalker to the previous visible node in document order relative + /// to the current node, and returns the new node. If the current node has no + /// previous node, or if the search for previousNode attempts to step upward + /// from the TreeWalker's root node, returns null, and retains the current node. + + Node* nextNode(); + /// Moves the TreeWalker to the next visible node in document order relative + /// to the current node, and returns the new node. If the current node has no + /// next node, or if the search for nextNode attempts to step upward from the + /// TreeWalker's root node, returns null, and retains the current node. + +protected: + int accept(Node* pNode) const; + Node* next(Node* pNode) const; + Node* previous(Node* pNode) const; + +private: + TreeWalker(); + + Node* _pRoot; + unsigned long _whatToShow; + NodeFilter* _pFilter; + Node* _pCurrent; +}; + + +// +// inlines +// +inline Node* TreeWalker::root() const +{ + return _pRoot; +} + + +inline unsigned long TreeWalker::whatToShow() const +{ + return _whatToShow; +} + + +inline NodeFilter* TreeWalker::filter() const +{ + return _pFilter; +} + + +inline bool TreeWalker::expandEntityReferences() const +{ + return false; +} + + +inline Node* TreeWalker::currentNode() const +{ + return _pCurrent; +} + + +inline Node* TreeWalker::getCurrentNode() const +{ + return _pCurrent; +} + + +} } // namespace Poco::XML + + +#endif // DOM_TreeWalker_INCLUDED diff --git a/XML/include/Poco/SAX/Attributes.h b/XML/include/Poco/SAX/Attributes.h index 37146d980..046d4b729 100644 --- a/XML/include/Poco/SAX/Attributes.h +++ b/XML/include/Poco/SAX/Attributes.h @@ -1,142 +1,142 @@ -// -// Attributes.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/Attributes.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX2 Attributes Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_Attributes_INCLUDED -#define SAX_Attributes_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Attributes - /// Interface for a list of XML attributes. - /// This interface allows access to a list of attributes in three different ways: - /// 1.by attribute index; - /// 2.by Namespace-qualified name; or - /// 3.by qualified (prefixed) name. - /// - /// The list will not contain attributes that were declared #IMPLIED but not - /// specified in the start tag. It will also not contain - /// attributes used as Namespace declarations (xmlns*) unless the - /// http://xml.org/sax/features/namespace-prefixes - /// feature is set to true (it is false by default). - /// - /// If the namespace-prefixes feature (see above) is false, access by - /// qualified name may not be available; if the - /// http://xml.org/sax/features/namespaces feature is false, access by - /// Namespace-qualified names may not be available. - /// This interface replaces the now-deprecated SAX1 AttributeList interface, - /// which does not contain Namespace support. In - /// addition to Namespace support, it adds the getIndex methods (below). - /// The order of attributes in the list is unspecified, and will vary from - /// implementation to implementation. -{ -public: - virtual int getIndex(const XMLString& name) const = 0; - /// Look up the index of an attribute by a qualified name. - - virtual int getIndex(const XMLString& namespaceURI, const XMLString& localName) const = 0; - /// Look up the index of an attribute by a namspace name. - - virtual int getLength() const = 0; - /// Return the number of attributes in the list. - /// - /// Once you know the number of attributes, you can iterate through the list. - - virtual const XMLString& getLocalName(int i) const = 0; - /// Look up a local attribute name by index. - - virtual const XMLString& getQName(int i) const = 0; - /// Look up a qualified attribute name by index. - - virtual const XMLString& getType(int i) const = 0; - /// Look up an attribute type by index. - /// - /// The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", - /// "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case). - /// - /// If the parser has not read a declaration for the attribute, or if the parser does not - /// report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 - /// Recommendation (clause 3.3.3, "Attribute-Value Normalization"). - /// - /// For an enumerated attribute that is not a notation, the parser will report the type - /// as "NMTOKEN". - - virtual const XMLString& getType(const XMLString& qname) const = 0; - /// Look up an attribute type by a qualified name. - /// - /// See getType(int) for a description of the possible types. - - virtual const XMLString& getType(const XMLString& namespaceURI, const XMLString& localName) const = 0; - /// Look up an attribute type by a namespace name. - /// - /// See getType(int) for a description of the possible types. - - virtual const XMLString& getValue(int i) const = 0; - /// Look up an attribute value by index. - /// - /// If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens - /// will be concatenated into a single string with each token separated by a single space. - - virtual const XMLString& getValue(const XMLString& qname) const = 0; - /// Look up an attribute value by a qualified name. - /// - /// See getValue(int) for a description of the possible values. - - virtual const XMLString& getValue(const XMLString& uri, const XMLString& localName) const = 0; - /// Look up an attribute value by a namespace name. - /// - /// See getValue(int) for a description of the possible values. - - virtual const XMLString& getURI(int i) const = 0; - /// Look up a namespace URI by index. - -protected: - virtual ~Attributes(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_Attributes_INCLUDED +// +// Attributes.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/Attributes.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX2 Attributes Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_Attributes_INCLUDED +#define SAX_Attributes_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Attributes + /// Interface for a list of XML attributes. + /// This interface allows access to a list of attributes in three different ways: + /// 1.by attribute index; + /// 2.by Namespace-qualified name; or + /// 3.by qualified (prefixed) name. + /// + /// The list will not contain attributes that were declared #IMPLIED but not + /// specified in the start tag. It will also not contain + /// attributes used as Namespace declarations (xmlns*) unless the + /// http://xml.org/sax/features/namespace-prefixes + /// feature is set to true (it is false by default). + /// + /// If the namespace-prefixes feature (see above) is false, access by + /// qualified name may not be available; if the + /// http://xml.org/sax/features/namespaces feature is false, access by + /// Namespace-qualified names may not be available. + /// This interface replaces the now-deprecated SAX1 AttributeList interface, + /// which does not contain Namespace support. In + /// addition to Namespace support, it adds the getIndex methods (below). + /// The order of attributes in the list is unspecified, and will vary from + /// implementation to implementation. +{ +public: + virtual int getIndex(const XMLString& name) const = 0; + /// Look up the index of an attribute by a qualified name. + + virtual int getIndex(const XMLString& namespaceURI, const XMLString& localName) const = 0; + /// Look up the index of an attribute by a namspace name. + + virtual int getLength() const = 0; + /// Return the number of attributes in the list. + /// + /// Once you know the number of attributes, you can iterate through the list. + + virtual const XMLString& getLocalName(int i) const = 0; + /// Look up a local attribute name by index. + + virtual const XMLString& getQName(int i) const = 0; + /// Look up a qualified attribute name by index. + + virtual const XMLString& getType(int i) const = 0; + /// Look up an attribute type by index. + /// + /// The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", + /// "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case). + /// + /// If the parser has not read a declaration for the attribute, or if the parser does not + /// report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 + /// Recommendation (clause 3.3.3, "Attribute-Value Normalization"). + /// + /// For an enumerated attribute that is not a notation, the parser will report the type + /// as "NMTOKEN". + + virtual const XMLString& getType(const XMLString& qname) const = 0; + /// Look up an attribute type by a qualified name. + /// + /// See getType(int) for a description of the possible types. + + virtual const XMLString& getType(const XMLString& namespaceURI, const XMLString& localName) const = 0; + /// Look up an attribute type by a namespace name. + /// + /// See getType(int) for a description of the possible types. + + virtual const XMLString& getValue(int i) const = 0; + /// Look up an attribute value by index. + /// + /// If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens + /// will be concatenated into a single string with each token separated by a single space. + + virtual const XMLString& getValue(const XMLString& qname) const = 0; + /// Look up an attribute value by a qualified name. + /// + /// See getValue(int) for a description of the possible values. + + virtual const XMLString& getValue(const XMLString& uri, const XMLString& localName) const = 0; + /// Look up an attribute value by a namespace name. + /// + /// See getValue(int) for a description of the possible values. + + virtual const XMLString& getURI(int i) const = 0; + /// Look up a namespace URI by index. + +protected: + virtual ~Attributes(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_Attributes_INCLUDED diff --git a/XML/include/Poco/SAX/AttributesImpl.h b/XML/include/Poco/SAX/AttributesImpl.h index 0f3306dc3..74bdea0ef 100644 --- a/XML/include/Poco/SAX/AttributesImpl.h +++ b/XML/include/Poco/SAX/AttributesImpl.h @@ -1,318 +1,318 @@ -// -// AttributesImpl.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/AttributesImpl.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Implementation of the SAX2 Attributes Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_AttributesImpl_INCLUDED -#define SAX_AttributesImpl_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/Attributes.h" -#include - - -namespace Poco { -namespace XML { - - -class XML_API AttributesImpl: public Attributes - /// This class provides a default implementation of the SAX2 Attributes interface, - /// with the addition of manipulators so that the list can be modified or reused. - /// - /// There are two typical uses of this class: - /// 1. to take a persistent snapshot of an Attributes object in a startElement event; or - /// 2. to construct or modify an Attributes object in a SAX2 driver or filter. -{ -public: - struct Attribute - { - XMLString localName; - XMLString namespaceURI; - XMLString qname; - XMLString value; - XMLString type; - bool specified; - }; - typedef std::vector AttributeVec; - typedef AttributeVec::const_iterator iterator; - - AttributesImpl(); - /// Creates the AttributesImpl. - - AttributesImpl(const Attributes& attributes); - /// Creates the AttributesImpl by copying another one. - - AttributesImpl(const AttributesImpl& attributes); - /// Creates the AttributesImpl by copying another one. - - ~AttributesImpl(); - /// Destroys the AttributesImpl. - - AttributesImpl& operator = (const AttributesImpl& attributes); - /// Assignment operator. - - int getIndex(const XMLString& name) const; - int getIndex(const XMLString& namespaceURI, const XMLString& localName) const; - int getLength() const; - const XMLString& getLocalName(int i) const; - const XMLString& getQName(int i) const; - const XMLString& getType(int i) const; - const XMLString& getType(const XMLString& qname) const; - const XMLString& getType(const XMLString& namespaceURI, const XMLString& localName) const; - const XMLString& getValue(int i) const; - const XMLString& getValue(const XMLString& qname) const; - const XMLString& getValue(const XMLString& namespaceURI, const XMLString& localName) const; - const XMLString& getURI(int i) const; - - bool isSpecified(int i) const; - /// Returns true unless the attribute value was provided by DTD defaulting. - /// Extension from Attributes2 interface. - - bool isSpecified(const XMLString& qname) const; - /// Returns true unless the attribute value was provided by DTD defaulting. - /// Extension from Attributes2 interface. - - bool isSpecified(const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns true unless the attribute value was provided by DTD defaulting. - /// Extension from Attributes2 interface. - - void setValue(int i, const XMLString& value); - /// Sets the value of an attribute. - - void setValue(const XMLString& qname, const XMLString& value); - /// Sets the value of an attribute. - - void setValue(const XMLString& namespaceURI, const XMLString& localName, const XMLString& value); - /// Sets the value of an attribute. - - void setAttributes(const Attributes& attributes); - /// Copies the attributes from another Attributes object. - - void setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value); - /// Sets an attribute. - - void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value); - /// Adds an attribute to the end of the list. - - void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value, bool specified); - /// Adds an attribute to the end of the list. - - void addAttribute(const XMLChar* namespaceURI, const XMLChar* localName, const XMLChar* qname, const XMLChar* type, const XMLChar* value, bool specified); - /// Adds an attribute to the end of the list. - - Attribute& addAttribute(); - /// Add an (empty) attribute to the end of the list. - /// For internal use only. - /// The returned Attribute element must be filled by the caller. - - void removeAttribute(int i); - /// Removes an attribute. - - void removeAttribute(const XMLString& qname); - /// Removes an attribute. - - void removeAttribute(const XMLString& namespaceURI, const XMLString& localName); - /// Removes an attribute. - - void clear(); - /// Removes all attributes. - - void reserve(std::size_t capacity); - /// Reserves capacity in the internal vector. - - void setLocalName(int i, const XMLString& localName); - /// Sets the local name of an attribute. - - void setQName(int i, const XMLString& qname); - /// Sets the qualified name of an attribute. - - void setType(int i, const XMLString& type); - /// Sets the type of an attribute. - - void setURI(int i, const XMLString& namespaceURI); - /// Sets the namespace URI of an attribute. - - iterator begin() const; - /// Iterator support. - - iterator end() const; - /// Iterator support. - -protected: - Attribute* find(const XMLString& qname) const; - Attribute* find(const XMLString& namespaceURI, const XMLString& localName) const; - -private: - AttributeVec _attributes; - Attribute _empty; -}; - - -// -// inlines -// -inline AttributesImpl::iterator AttributesImpl::begin() const -{ - return _attributes.begin(); -} - - -inline AttributesImpl::iterator AttributesImpl::end() const -{ - return _attributes.end(); -} - - -inline AttributesImpl::Attribute& AttributesImpl::addAttribute() -{ - _attributes.push_back(_empty); - return _attributes.back(); -} - - -inline int AttributesImpl::getLength() const -{ - return (int) _attributes.size(); -} - - -inline const XMLString& AttributesImpl::getLocalName(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].localName; -} - - -inline const XMLString& AttributesImpl::getQName(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].qname; -} - - -inline const XMLString& AttributesImpl::getType(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].type; -} - - -inline const XMLString& AttributesImpl::getType(const XMLString& qname) const -{ - Attribute* pAttr = find(qname); - if (pAttr) - return pAttr->type; - else - return _empty.type; -} - - -inline const XMLString& AttributesImpl::getType(const XMLString& namespaceURI, const XMLString& localName) const -{ - Attribute* pAttr = find(namespaceURI, localName); - if (pAttr) - return pAttr->type; - else - return _empty.type; -} - - -inline const XMLString& AttributesImpl::getValue(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].value; -} - - -inline const XMLString& AttributesImpl::getValue(const XMLString& qname) const -{ - Attribute* pAttr = find(qname); - if (pAttr) - return pAttr->value; - else - return _empty.value; -} - - -inline const XMLString& AttributesImpl::getValue(const XMLString& namespaceURI, const XMLString& localName) const -{ - Attribute* pAttr = find(namespaceURI, localName); - if (pAttr) - return pAttr->value; - else - return _empty.value; -} - - -inline const XMLString& AttributesImpl::getURI(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].namespaceURI; -} - - -inline bool AttributesImpl::isSpecified(int i) const -{ - poco_assert (i < _attributes.size()); - return _attributes[i].specified; -} - - -inline bool AttributesImpl::isSpecified(const XMLString& qname) const -{ - Attribute* pAttr = find(qname); - if (pAttr) - return pAttr->specified; - else - return false; -} - - -inline bool AttributesImpl::isSpecified(const XMLString& namespaceURI, const XMLString& localName) const -{ - Attribute* pAttr = find(namespaceURI, localName); - if (pAttr) - return pAttr->specified; - else - return false; -} - - -} } // namespace Poco::XML - - -#endif // SAX_AttributesImpl_INCLUDED +// +// AttributesImpl.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/AttributesImpl.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Implementation of the SAX2 Attributes Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_AttributesImpl_INCLUDED +#define SAX_AttributesImpl_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/Attributes.h" +#include + + +namespace Poco { +namespace XML { + + +class XML_API AttributesImpl: public Attributes + /// This class provides a default implementation of the SAX2 Attributes interface, + /// with the addition of manipulators so that the list can be modified or reused. + /// + /// There are two typical uses of this class: + /// 1. to take a persistent snapshot of an Attributes object in a startElement event; or + /// 2. to construct or modify an Attributes object in a SAX2 driver or filter. +{ +public: + struct Attribute + { + XMLString localName; + XMLString namespaceURI; + XMLString qname; + XMLString value; + XMLString type; + bool specified; + }; + typedef std::vector AttributeVec; + typedef AttributeVec::const_iterator iterator; + + AttributesImpl(); + /// Creates the AttributesImpl. + + AttributesImpl(const Attributes& attributes); + /// Creates the AttributesImpl by copying another one. + + AttributesImpl(const AttributesImpl& attributes); + /// Creates the AttributesImpl by copying another one. + + ~AttributesImpl(); + /// Destroys the AttributesImpl. + + AttributesImpl& operator = (const AttributesImpl& attributes); + /// Assignment operator. + + int getIndex(const XMLString& name) const; + int getIndex(const XMLString& namespaceURI, const XMLString& localName) const; + int getLength() const; + const XMLString& getLocalName(int i) const; + const XMLString& getQName(int i) const; + const XMLString& getType(int i) const; + const XMLString& getType(const XMLString& qname) const; + const XMLString& getType(const XMLString& namespaceURI, const XMLString& localName) const; + const XMLString& getValue(int i) const; + const XMLString& getValue(const XMLString& qname) const; + const XMLString& getValue(const XMLString& namespaceURI, const XMLString& localName) const; + const XMLString& getURI(int i) const; + + bool isSpecified(int i) const; + /// Returns true unless the attribute value was provided by DTD defaulting. + /// Extension from Attributes2 interface. + + bool isSpecified(const XMLString& qname) const; + /// Returns true unless the attribute value was provided by DTD defaulting. + /// Extension from Attributes2 interface. + + bool isSpecified(const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns true unless the attribute value was provided by DTD defaulting. + /// Extension from Attributes2 interface. + + void setValue(int i, const XMLString& value); + /// Sets the value of an attribute. + + void setValue(const XMLString& qname, const XMLString& value); + /// Sets the value of an attribute. + + void setValue(const XMLString& namespaceURI, const XMLString& localName, const XMLString& value); + /// Sets the value of an attribute. + + void setAttributes(const Attributes& attributes); + /// Copies the attributes from another Attributes object. + + void setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value); + /// Sets an attribute. + + void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value); + /// Adds an attribute to the end of the list. + + void addAttribute(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value, bool specified); + /// Adds an attribute to the end of the list. + + void addAttribute(const XMLChar* namespaceURI, const XMLChar* localName, const XMLChar* qname, const XMLChar* type, const XMLChar* value, bool specified); + /// Adds an attribute to the end of the list. + + Attribute& addAttribute(); + /// Add an (empty) attribute to the end of the list. + /// For internal use only. + /// The returned Attribute element must be filled by the caller. + + void removeAttribute(int i); + /// Removes an attribute. + + void removeAttribute(const XMLString& qname); + /// Removes an attribute. + + void removeAttribute(const XMLString& namespaceURI, const XMLString& localName); + /// Removes an attribute. + + void clear(); + /// Removes all attributes. + + void reserve(std::size_t capacity); + /// Reserves capacity in the internal vector. + + void setLocalName(int i, const XMLString& localName); + /// Sets the local name of an attribute. + + void setQName(int i, const XMLString& qname); + /// Sets the qualified name of an attribute. + + void setType(int i, const XMLString& type); + /// Sets the type of an attribute. + + void setURI(int i, const XMLString& namespaceURI); + /// Sets the namespace URI of an attribute. + + iterator begin() const; + /// Iterator support. + + iterator end() const; + /// Iterator support. + +protected: + Attribute* find(const XMLString& qname) const; + Attribute* find(const XMLString& namespaceURI, const XMLString& localName) const; + +private: + AttributeVec _attributes; + Attribute _empty; +}; + + +// +// inlines +// +inline AttributesImpl::iterator AttributesImpl::begin() const +{ + return _attributes.begin(); +} + + +inline AttributesImpl::iterator AttributesImpl::end() const +{ + return _attributes.end(); +} + + +inline AttributesImpl::Attribute& AttributesImpl::addAttribute() +{ + _attributes.push_back(_empty); + return _attributes.back(); +} + + +inline int AttributesImpl::getLength() const +{ + return (int) _attributes.size(); +} + + +inline const XMLString& AttributesImpl::getLocalName(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].localName; +} + + +inline const XMLString& AttributesImpl::getQName(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].qname; +} + + +inline const XMLString& AttributesImpl::getType(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].type; +} + + +inline const XMLString& AttributesImpl::getType(const XMLString& qname) const +{ + Attribute* pAttr = find(qname); + if (pAttr) + return pAttr->type; + else + return _empty.type; +} + + +inline const XMLString& AttributesImpl::getType(const XMLString& namespaceURI, const XMLString& localName) const +{ + Attribute* pAttr = find(namespaceURI, localName); + if (pAttr) + return pAttr->type; + else + return _empty.type; +} + + +inline const XMLString& AttributesImpl::getValue(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].value; +} + + +inline const XMLString& AttributesImpl::getValue(const XMLString& qname) const +{ + Attribute* pAttr = find(qname); + if (pAttr) + return pAttr->value; + else + return _empty.value; +} + + +inline const XMLString& AttributesImpl::getValue(const XMLString& namespaceURI, const XMLString& localName) const +{ + Attribute* pAttr = find(namespaceURI, localName); + if (pAttr) + return pAttr->value; + else + return _empty.value; +} + + +inline const XMLString& AttributesImpl::getURI(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].namespaceURI; +} + + +inline bool AttributesImpl::isSpecified(int i) const +{ + poco_assert (i < _attributes.size()); + return _attributes[i].specified; +} + + +inline bool AttributesImpl::isSpecified(const XMLString& qname) const +{ + Attribute* pAttr = find(qname); + if (pAttr) + return pAttr->specified; + else + return false; +} + + +inline bool AttributesImpl::isSpecified(const XMLString& namespaceURI, const XMLString& localName) const +{ + Attribute* pAttr = find(namespaceURI, localName); + if (pAttr) + return pAttr->specified; + else + return false; +} + + +} } // namespace Poco::XML + + +#endif // SAX_AttributesImpl_INCLUDED diff --git a/XML/include/Poco/SAX/ContentHandler.h b/XML/include/Poco/SAX/ContentHandler.h index 51f925f07..bd8731a1c 100644 --- a/XML/include/Poco/SAX/ContentHandler.h +++ b/XML/include/Poco/SAX/ContentHandler.h @@ -1,262 +1,262 @@ -// -// ContentHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/ContentHandler.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX2 ContentHandler Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_ContentHandler_INCLUDED -#define SAX_ContentHandler_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class Locator; -class Attributes; - - -class XML_API ContentHandler - /// Receive notification of the logical content of a document. - /// - /// This is the main interface that most SAX applications implement: if the - /// application needs to be informed of basic parsing events, it implements - /// this interface and registers an instance with the SAX parser using the setContentHandler - /// method. The parser uses the instance to report basic document-related events - /// like the start and end of elements and character data. - /// - /// The order of events in this interface is very important, and mirrors the - /// order of information in the document itself. For example, all of an element's - /// content (character data, processing instructions, and/or subelements) will - /// appear, in order, between the startElement event and the corresponding endElement - /// event. - /// - /// This interface is similar to the now-deprecated SAX 1.0 DocumentHandler - /// interface, but it adds support for Namespaces and for reporting skipped - /// entities (in non-validating XML processors). - /// Receive notification of the logical content of a document. -{ -public: - virtual void setDocumentLocator(const Locator* loc) = 0; - /// Receive an object for locating the origin of SAX document events. - /// - /// SAX parsers are strongly encouraged (though not absolutely required) to - /// supply a locator: if it does so, it must supply the locator to the application - /// by invoking this method before invoking any of the other methods in the - /// ContentHandler interface. - /// - /// The locator allows the application to determine the end position of any - /// document-related event, even if the parser is not reporting an error. Typically, - /// the application will use this information for reporting its own errors (such - /// as character content that does not match an application's business rules). - /// The information returned by the locator is probably not sufficient for use - /// with a search engine. - /// - /// Note that the locator will return correct information only during the invocation - /// SAX event callbacks after startDocument returns and before endDocument is - /// called. The application should not attempt to use it at any other time. - - virtual void startDocument() = 0; - /// Receive notification of the beginning of a document. - /// - /// The SAX parser calls this function one time before calling all other - /// functions of this class (except SetDocumentLocator). - - virtual void endDocument() = 0; - /// Receive notification of the end of a document. - /// - /// The SAX parser will invoke this method only once, and it will be the last - /// method invoked during the parse. The parser shall not invoke this method - /// until it has either abandoned parsing (because of an unrecoverable error) - /// or reached the end of input. - - virtual void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) = 0; - /// Receive notification of the beginning of an element. - /// - /// The Parser will invoke this method at the beginning of every element in - /// the XML document; there will be a corresponding endElement event for every - /// startElement event (even when the element is empty). All of the element's - /// content will be reported, in order, before the corresponding endElement - /// event. - /// - /// This event allows up to three name components for each element: - /// 1. the Namespace URI; - /// 2. the local name; and - /// 3. the qualified (prefixed) name. - /// - /// Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces - /// and the http://xml.org/sax/features/namespace-prefixes properties: - /// * the Namespace URI and local name are required when the namespaces - /// property is true (the default), and are optional when the namespaces property - /// is false (if one is specified, both must be); - /// * the qualified name is required when the namespace-prefixes property - /// is true, and is optional when the namespace-prefixes property is false (the - /// default). - /// - /// Note that the attribute list provided will contain only attributes with - /// explicit values (specified or defaulted): #IMPLIED attributes will be omitted. - /// The attribute list will contain attributes used for Namespace declarations - /// (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes - /// property is true (it is false by default, and support for a true value is - /// optional). - /// - /// Like characters(), attribute values may have characters that need more than - /// one char value. - - virtual void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) = 0; - /// Receive notification of the end of an element. - /// - /// The SAX parser will invoke this method at the end of every element in the - /// XML document; there will be a corresponding startElement event for every - /// endElement event (even when the element is empty). - /// - /// For information on the names, see startElement. - - virtual void characters(const XMLChar ch[], int start, int length) = 0; - /// Receive notification of character data. - /// - /// The Parser will call this method to report each chunk of character data. - /// SAX parsers may return all contiguous character data in a single chunk, - /// or they may split it into several chunks; however, all of the characters - /// in any single event must come from the same external entity so that the - /// Locator provides useful information. - /// - /// The application must not attempt to read from the array outside of the specified - /// range. - /// - /// Individual characters may consist of more than one XMLChar value. There - /// are three important cases where this happens, because characters can't be - /// represented in just sixteen bits. In one case, characters are represented - /// in a Surrogate Pair, using two special Unicode values. Such characters are - /// in the so-called "Astral Planes", with a code point above U+FFFF. A second - /// case involves composite characters, such as a base character combining with - /// one or more accent characters. And most important, if XMLChar is a plain - /// char, characters are encoded in UTF-8. - /// - /// Your code should not assume that algorithms using char-at-a-time idioms - /// will be working in character units; in some cases they will split characters. - /// This is relevant wherever XML permits arbitrary characters, such as attribute - /// values, processing instruction data, and comments as well as in data reported - /// from this method. It's also generally relevant whenever C++ code manipulates - /// internationalized text; the issue isn't unique to XML. - /// - /// Note that some parsers will report whitespace in element content using the - /// ignorableWhitespace method rather than this one (validating parsers must - /// do so). - - virtual void ignorableWhitespace(const XMLChar ch[], int start, int length) = 0; - /// Receive notification of ignorable whitespace in element content. - /// - /// Validating Parsers must use this method to report each chunk of whitespace - /// in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating - /// parsers may also use this method if they are capable of parsing and using - /// content models. - /// - /// SAX parsers may return all contiguous whitespace in a single chunk, or they - /// may split it into several chunks; however, all of the characters in any - /// single event must come from the same external entity, so that the Locator - /// provides useful information. - /// - /// The application must not attempt to read from the array outside of the specified - /// range. - - virtual void processingInstruction(const XMLString& target, const XMLString& data) = 0; - /// Receive notification of a processing instruction. - /// - /// The Parser will invoke this method once for each processing instruction - /// found: note that processing instructions may occur before or after the main - /// document element. - /// - /// A SAX parser must never report an XML declaration (XML 1.0, section 2.8) - /// or a text declaration (XML 1.0, section 4.3.1) using this method. - /// - /// Like characters(), processing instruction data may have characters that - /// need more than one char value. - - virtual void startPrefixMapping(const XMLString& prefix, const XMLString& uri) = 0; - /// Begin the scope of a prefix-URI Namespace mapping. - /// - /// The information from this event is not necessary for normal Namespace processing: - /// the SAX XML reader will automatically replace prefixes for element and attribute - /// names when the http://xml.org/sax/features/namespaces feature is true (the - /// default). - /// - /// There are cases, however, when applications need to use prefixes in character - /// data or in attribute values, where they cannot safely be expanded automatically; - /// the start/endPrefixMapping event supplies the information to the application - /// to expand prefixes in those contexts itself, if necessary. - /// - /// Note that start/endPrefixMapping events are not guaranteed to be properly - /// nested relative to each other: all startPrefixMapping events will occur - /// immediately before the corresponding startElement event, and all endPrefixMapping - /// events will occur immediately after the corresponding endElement event, - /// but their order is not otherwise guaranteed. - /// - /// There should never be start/endPrefixMapping events for the "xml" prefix, - /// since it is predeclared and immutable. - - virtual void endPrefixMapping(const XMLString& prefix) = 0; - /// End the scope of a prefix-URI mapping. - /// - /// See startPrefixMapping for details. These events will always occur immediately - /// after the corresponding endElement event, but the order of endPrefixMapping - /// events is not otherwise guaranteed. - - virtual void skippedEntity(const XMLString& name) = 0; - /// Receive notification of a skipped entity. This is not called for entity - /// references within markup constructs such as element start tags or markup - /// declarations. (The XML recommendation requires reporting skipped external - /// entities. SAX also reports internal entity expansion/non-expansion, except - /// within markup constructs.) - /// - /// The Parser will invoke this method each time the entity is skipped. Non-validating - /// processors may skip entities if they have not seen the declarations (because, - /// for example, the entity was declared in an external DTD subset). All processors - /// may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities - /// and the http://xml.org/sax/features/external-parameter-entities properties. - -protected: - virtual ~ContentHandler(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_ContentHandler_INCLUDED +// +// ContentHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/ContentHandler.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX2 ContentHandler Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_ContentHandler_INCLUDED +#define SAX_ContentHandler_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class Locator; +class Attributes; + + +class XML_API ContentHandler + /// Receive notification of the logical content of a document. + /// + /// This is the main interface that most SAX applications implement: if the + /// application needs to be informed of basic parsing events, it implements + /// this interface and registers an instance with the SAX parser using the setContentHandler + /// method. The parser uses the instance to report basic document-related events + /// like the start and end of elements and character data. + /// + /// The order of events in this interface is very important, and mirrors the + /// order of information in the document itself. For example, all of an element's + /// content (character data, processing instructions, and/or subelements) will + /// appear, in order, between the startElement event and the corresponding endElement + /// event. + /// + /// This interface is similar to the now-deprecated SAX 1.0 DocumentHandler + /// interface, but it adds support for Namespaces and for reporting skipped + /// entities (in non-validating XML processors). + /// Receive notification of the logical content of a document. +{ +public: + virtual void setDocumentLocator(const Locator* loc) = 0; + /// Receive an object for locating the origin of SAX document events. + /// + /// SAX parsers are strongly encouraged (though not absolutely required) to + /// supply a locator: if it does so, it must supply the locator to the application + /// by invoking this method before invoking any of the other methods in the + /// ContentHandler interface. + /// + /// The locator allows the application to determine the end position of any + /// document-related event, even if the parser is not reporting an error. Typically, + /// the application will use this information for reporting its own errors (such + /// as character content that does not match an application's business rules). + /// The information returned by the locator is probably not sufficient for use + /// with a search engine. + /// + /// Note that the locator will return correct information only during the invocation + /// SAX event callbacks after startDocument returns and before endDocument is + /// called. The application should not attempt to use it at any other time. + + virtual void startDocument() = 0; + /// Receive notification of the beginning of a document. + /// + /// The SAX parser calls this function one time before calling all other + /// functions of this class (except SetDocumentLocator). + + virtual void endDocument() = 0; + /// Receive notification of the end of a document. + /// + /// The SAX parser will invoke this method only once, and it will be the last + /// method invoked during the parse. The parser shall not invoke this method + /// until it has either abandoned parsing (because of an unrecoverable error) + /// or reached the end of input. + + virtual void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) = 0; + /// Receive notification of the beginning of an element. + /// + /// The Parser will invoke this method at the beginning of every element in + /// the XML document; there will be a corresponding endElement event for every + /// startElement event (even when the element is empty). All of the element's + /// content will be reported, in order, before the corresponding endElement + /// event. + /// + /// This event allows up to three name components for each element: + /// 1. the Namespace URI; + /// 2. the local name; and + /// 3. the qualified (prefixed) name. + /// + /// Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces + /// and the http://xml.org/sax/features/namespace-prefixes properties: + /// * the Namespace URI and local name are required when the namespaces + /// property is true (the default), and are optional when the namespaces property + /// is false (if one is specified, both must be); + /// * the qualified name is required when the namespace-prefixes property + /// is true, and is optional when the namespace-prefixes property is false (the + /// default). + /// + /// Note that the attribute list provided will contain only attributes with + /// explicit values (specified or defaulted): #IMPLIED attributes will be omitted. + /// The attribute list will contain attributes used for Namespace declarations + /// (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes + /// property is true (it is false by default, and support for a true value is + /// optional). + /// + /// Like characters(), attribute values may have characters that need more than + /// one char value. + + virtual void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) = 0; + /// Receive notification of the end of an element. + /// + /// The SAX parser will invoke this method at the end of every element in the + /// XML document; there will be a corresponding startElement event for every + /// endElement event (even when the element is empty). + /// + /// For information on the names, see startElement. + + virtual void characters(const XMLChar ch[], int start, int length) = 0; + /// Receive notification of character data. + /// + /// The Parser will call this method to report each chunk of character data. + /// SAX parsers may return all contiguous character data in a single chunk, + /// or they may split it into several chunks; however, all of the characters + /// in any single event must come from the same external entity so that the + /// Locator provides useful information. + /// + /// The application must not attempt to read from the array outside of the specified + /// range. + /// + /// Individual characters may consist of more than one XMLChar value. There + /// are three important cases where this happens, because characters can't be + /// represented in just sixteen bits. In one case, characters are represented + /// in a Surrogate Pair, using two special Unicode values. Such characters are + /// in the so-called "Astral Planes", with a code point above U+FFFF. A second + /// case involves composite characters, such as a base character combining with + /// one or more accent characters. And most important, if XMLChar is a plain + /// char, characters are encoded in UTF-8. + /// + /// Your code should not assume that algorithms using char-at-a-time idioms + /// will be working in character units; in some cases they will split characters. + /// This is relevant wherever XML permits arbitrary characters, such as attribute + /// values, processing instruction data, and comments as well as in data reported + /// from this method. It's also generally relevant whenever C++ code manipulates + /// internationalized text; the issue isn't unique to XML. + /// + /// Note that some parsers will report whitespace in element content using the + /// ignorableWhitespace method rather than this one (validating parsers must + /// do so). + + virtual void ignorableWhitespace(const XMLChar ch[], int start, int length) = 0; + /// Receive notification of ignorable whitespace in element content. + /// + /// Validating Parsers must use this method to report each chunk of whitespace + /// in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating + /// parsers may also use this method if they are capable of parsing and using + /// content models. + /// + /// SAX parsers may return all contiguous whitespace in a single chunk, or they + /// may split it into several chunks; however, all of the characters in any + /// single event must come from the same external entity, so that the Locator + /// provides useful information. + /// + /// The application must not attempt to read from the array outside of the specified + /// range. + + virtual void processingInstruction(const XMLString& target, const XMLString& data) = 0; + /// Receive notification of a processing instruction. + /// + /// The Parser will invoke this method once for each processing instruction + /// found: note that processing instructions may occur before or after the main + /// document element. + /// + /// A SAX parser must never report an XML declaration (XML 1.0, section 2.8) + /// or a text declaration (XML 1.0, section 4.3.1) using this method. + /// + /// Like characters(), processing instruction data may have characters that + /// need more than one char value. + + virtual void startPrefixMapping(const XMLString& prefix, const XMLString& uri) = 0; + /// Begin the scope of a prefix-URI Namespace mapping. + /// + /// The information from this event is not necessary for normal Namespace processing: + /// the SAX XML reader will automatically replace prefixes for element and attribute + /// names when the http://xml.org/sax/features/namespaces feature is true (the + /// default). + /// + /// There are cases, however, when applications need to use prefixes in character + /// data or in attribute values, where they cannot safely be expanded automatically; + /// the start/endPrefixMapping event supplies the information to the application + /// to expand prefixes in those contexts itself, if necessary. + /// + /// Note that start/endPrefixMapping events are not guaranteed to be properly + /// nested relative to each other: all startPrefixMapping events will occur + /// immediately before the corresponding startElement event, and all endPrefixMapping + /// events will occur immediately after the corresponding endElement event, + /// but their order is not otherwise guaranteed. + /// + /// There should never be start/endPrefixMapping events for the "xml" prefix, + /// since it is predeclared and immutable. + + virtual void endPrefixMapping(const XMLString& prefix) = 0; + /// End the scope of a prefix-URI mapping. + /// + /// See startPrefixMapping for details. These events will always occur immediately + /// after the corresponding endElement event, but the order of endPrefixMapping + /// events is not otherwise guaranteed. + + virtual void skippedEntity(const XMLString& name) = 0; + /// Receive notification of a skipped entity. This is not called for entity + /// references within markup constructs such as element start tags or markup + /// declarations. (The XML recommendation requires reporting skipped external + /// entities. SAX also reports internal entity expansion/non-expansion, except + /// within markup constructs.) + /// + /// The Parser will invoke this method each time the entity is skipped. Non-validating + /// processors may skip entities if they have not seen the declarations (because, + /// for example, the entity was declared in an external DTD subset). All processors + /// may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities + /// and the http://xml.org/sax/features/external-parameter-entities properties. + +protected: + virtual ~ContentHandler(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_ContentHandler_INCLUDED diff --git a/XML/include/Poco/SAX/DTDHandler.h b/XML/include/Poco/SAX/DTDHandler.h index 5e3fdad38..962fcdbbf 100644 --- a/XML/include/Poco/SAX/DTDHandler.h +++ b/XML/include/Poco/SAX/DTDHandler.h @@ -1,108 +1,108 @@ -// -// DTDHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/DTDHandler.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX DTDHandler Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_DTDHandler_INCLUDED -#define SAX_DTDHandler_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API DTDHandler - /// If a SAX application needs information about notations and unparsed entities, - /// then the application implements this interface and registers an instance with the - /// SAX parser using the parser's setDTDHandler method. The parser uses the instance - /// to report notation and unparsed entity declarations to the application. - /// - /// Note that this interface includes only those DTD events that the XML recommendation - /// requires processors to report: notation and unparsed entity declarations. - /// - /// The SAX parser may report these events in any order, regardless of the order in - /// which the notations and unparsed entities were declared; however, all DTD events - /// must be reported after the document handler's startDocument event, and before the first - /// startElement event. (If the LexicalHandler is used, these events must also be reported before the endDTD event.) - /// - /// It is up to the application to store the information for future use (perhaps in a hash table or - /// object tree). If the application encounters attributes of type "NOTATION", "ENTITY", or "ENTITIES", - /// it can use the information that it obtained through this interface to find the entity and/or notation - /// corresponding with the attribute value. -{ -public: - virtual void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) = 0; - /// Receive notification of a notation declaration event. - /// - /// It is up to the application to record the notation for later reference, - /// if necessary; notations may appear as attribute values and in unparsed - /// entity declarations, and are sometime used with processing instruction - /// target names. - /// - /// At least one of publicId and systemId must be non-null. If a system identifier - /// is present, and it is a URL, the SAX parser must resolve it fully before passing - /// it to the application through this event. - /// - /// There is no guarantee that the notation declaration will be reported before any - /// unparsed entities that use it. - /// - /// Note that publicId and systemId maybe null, therefore we pass a pointer rather than a reference. - - virtual void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) = 0; - /// Receive notification of an unparsed entity declaration event. - /// - /// Note that the notation name corresponds to a notation reported by the - /// notationDecl event. It is up to the application to record the entity for - /// later reference, if necessary; unparsed entities may appear as attribute values. - /// - /// If the system identifier is a URL, the parser must resolve it fully before - /// passing it to the application. - /// - /// Note that publicId maybe null, therefore we pass a pointer rather than a reference. - -protected: - virtual ~DTDHandler(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_DTDHandler_INCLUDED +// +// DTDHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/DTDHandler.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX DTDHandler Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_DTDHandler_INCLUDED +#define SAX_DTDHandler_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API DTDHandler + /// If a SAX application needs information about notations and unparsed entities, + /// then the application implements this interface and registers an instance with the + /// SAX parser using the parser's setDTDHandler method. The parser uses the instance + /// to report notation and unparsed entity declarations to the application. + /// + /// Note that this interface includes only those DTD events that the XML recommendation + /// requires processors to report: notation and unparsed entity declarations. + /// + /// The SAX parser may report these events in any order, regardless of the order in + /// which the notations and unparsed entities were declared; however, all DTD events + /// must be reported after the document handler's startDocument event, and before the first + /// startElement event. (If the LexicalHandler is used, these events must also be reported before the endDTD event.) + /// + /// It is up to the application to store the information for future use (perhaps in a hash table or + /// object tree). If the application encounters attributes of type "NOTATION", "ENTITY", or "ENTITIES", + /// it can use the information that it obtained through this interface to find the entity and/or notation + /// corresponding with the attribute value. +{ +public: + virtual void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) = 0; + /// Receive notification of a notation declaration event. + /// + /// It is up to the application to record the notation for later reference, + /// if necessary; notations may appear as attribute values and in unparsed + /// entity declarations, and are sometime used with processing instruction + /// target names. + /// + /// At least one of publicId and systemId must be non-null. If a system identifier + /// is present, and it is a URL, the SAX parser must resolve it fully before passing + /// it to the application through this event. + /// + /// There is no guarantee that the notation declaration will be reported before any + /// unparsed entities that use it. + /// + /// Note that publicId and systemId maybe null, therefore we pass a pointer rather than a reference. + + virtual void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) = 0; + /// Receive notification of an unparsed entity declaration event. + /// + /// Note that the notation name corresponds to a notation reported by the + /// notationDecl event. It is up to the application to record the entity for + /// later reference, if necessary; unparsed entities may appear as attribute values. + /// + /// If the system identifier is a URL, the parser must resolve it fully before + /// passing it to the application. + /// + /// Note that publicId maybe null, therefore we pass a pointer rather than a reference. + +protected: + virtual ~DTDHandler(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_DTDHandler_INCLUDED diff --git a/XML/include/Poco/SAX/DeclHandler.h b/XML/include/Poco/SAX/DeclHandler.h index 2cfbf4baf..9760de8e5 100644 --- a/XML/include/Poco/SAX/DeclHandler.h +++ b/XML/include/Poco/SAX/DeclHandler.h @@ -1,113 +1,113 @@ -// -// DeclHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/DeclHandler.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX2-ext DeclHandler Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_DeclHandler_INCLUDED -#define SAX_DeclHandler_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API DeclHandler - /// This is an optional extension handler for SAX2 to provide information - /// about DTD declarations in an XML document. XML - /// readers are not required to support this handler, and this handler is - /// not included in the core SAX2 distribution. - /// - /// Note that data-related DTD declarations (unparsed entities and notations) - /// are already reported through the DTDHandler interface. - /// If you are using the declaration handler together with a lexical handler, - /// all of the events will occur between the startDTD and the endDTD events. - /// To set the DeclHandler for an XML reader, use the setProperty method - /// with the propertyId "http://xml.org/sax/properties/declaration-handler". - /// If the reader does not support declaration events, it will throw a - /// SAXNotRecognizedException or a SAXNotSupportedException when you attempt to - /// register the handler. -{ -public: - virtual void attributeDecl(const XMLString& eName, const XMLString& aName, const XMLString* valueDefault, const XMLString* value) = 0; - /// Report an attribute type declaration. - /// - /// Only the effective (first) declaration for an attribute will be reported. - /// The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", - /// "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group - /// with the separator "|" and all whitespace removed, or the word "NOTATION" - /// followed by a space followed by a parenthesized token group with all whitespace - /// removed. - /// - /// The value will be the value as reported to applications, appropriately normalized - /// and with entity and character references expanded. - - virtual void elementDecl(const XMLString& name, const XMLString& model) = 0; - /// Report an element type declaration. - /// - /// The content model will consist of the string "EMPTY", the string "ANY", or a - /// parenthesised group, optionally followed by an occurrence indicator. The model - /// will be normalized so that all parameter entities are fully resolved and all - /// whitespace is removed,and will include the enclosing parentheses. Other - /// normalization (such as removing redundant parentheses or simplifying occurrence - /// indicators) is at the discretion of the parser. - - virtual void externalEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId) = 0; - /// Report an external entity declaration. - /// - /// Only the effective (first) declaration for each entity will be reported. - /// - /// If the system identifier is a URL, the parser must resolve it fully before - /// passing it to the application. - - virtual void internalEntityDecl(const XMLString& name, const XMLString& value) = 0; - /// Report an internal entity declaration. - /// - /// Only the effective (first) declaration for each entity will be reported. All - /// parameter entities in the value will be expanded, but general entities will not. - -protected: - virtual ~DeclHandler(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_DeclHandler_INCLUDED +// +// DeclHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/DeclHandler.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX2-ext DeclHandler Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_DeclHandler_INCLUDED +#define SAX_DeclHandler_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API DeclHandler + /// This is an optional extension handler for SAX2 to provide information + /// about DTD declarations in an XML document. XML + /// readers are not required to support this handler, and this handler is + /// not included in the core SAX2 distribution. + /// + /// Note that data-related DTD declarations (unparsed entities and notations) + /// are already reported through the DTDHandler interface. + /// If you are using the declaration handler together with a lexical handler, + /// all of the events will occur between the startDTD and the endDTD events. + /// To set the DeclHandler for an XML reader, use the setProperty method + /// with the propertyId "http://xml.org/sax/properties/declaration-handler". + /// If the reader does not support declaration events, it will throw a + /// SAXNotRecognizedException or a SAXNotSupportedException when you attempt to + /// register the handler. +{ +public: + virtual void attributeDecl(const XMLString& eName, const XMLString& aName, const XMLString* valueDefault, const XMLString* value) = 0; + /// Report an attribute type declaration. + /// + /// Only the effective (first) declaration for an attribute will be reported. + /// The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", + /// "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group + /// with the separator "|" and all whitespace removed, or the word "NOTATION" + /// followed by a space followed by a parenthesized token group with all whitespace + /// removed. + /// + /// The value will be the value as reported to applications, appropriately normalized + /// and with entity and character references expanded. + + virtual void elementDecl(const XMLString& name, const XMLString& model) = 0; + /// Report an element type declaration. + /// + /// The content model will consist of the string "EMPTY", the string "ANY", or a + /// parenthesised group, optionally followed by an occurrence indicator. The model + /// will be normalized so that all parameter entities are fully resolved and all + /// whitespace is removed,and will include the enclosing parentheses. Other + /// normalization (such as removing redundant parentheses or simplifying occurrence + /// indicators) is at the discretion of the parser. + + virtual void externalEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId) = 0; + /// Report an external entity declaration. + /// + /// Only the effective (first) declaration for each entity will be reported. + /// + /// If the system identifier is a URL, the parser must resolve it fully before + /// passing it to the application. + + virtual void internalEntityDecl(const XMLString& name, const XMLString& value) = 0; + /// Report an internal entity declaration. + /// + /// Only the effective (first) declaration for each entity will be reported. All + /// parameter entities in the value will be expanded, but general entities will not. + +protected: + virtual ~DeclHandler(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_DeclHandler_INCLUDED diff --git a/XML/include/Poco/SAX/DefaultHandler.h b/XML/include/Poco/SAX/DefaultHandler.h index 4e334cba7..e73982b1d 100644 --- a/XML/include/Poco/SAX/DefaultHandler.h +++ b/XML/include/Poco/SAX/DefaultHandler.h @@ -1,105 +1,105 @@ -// -// DefaultHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/DefaultHandler.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX-2 DefaultHandler class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_DefaultHandler_INCLUDED -#define SAX_DefaultHandler_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/EntityResolver.h" -#include "Poco/SAX/DTDHandler.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/ErrorHandler.h" - - -namespace Poco { -namespace XML { - - -class XML_API DefaultHandler: public EntityResolver, public DTDHandler, public ContentHandler, public ErrorHandler - /// Default base class for SAX2 event handlers. - /// This class is available as a convenience base class for SAX2 applications: - /// it provides default implementations for all of the - /// callbacks in the four core SAX2 handler classes: - /// * EntityResolver - /// * DTDHandler - /// * ContentHandler - /// * ErrorHandler - /// Application writers can extend this class when they need to implement only - /// part of an interface; parser writers can instantiate this - /// class to provide default handlers when the application has not supplied its own. -{ -public: - DefaultHandler(); - /// Creates the DefaultHandler. - - ~DefaultHandler(); - /// Destroys the DefaultHandler. - - // EntityResolver - InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); - void releaseInputSource(InputSource* pSource); - - // DTDHandler - void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); - void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); - - // ContentHandler - void setDocumentLocator(const Locator* loc); - void startDocument(); - void endDocument(); - void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes); - void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); - void characters(const XMLChar ch[], int start, int length); - void ignorableWhitespace(const XMLChar ch[], int start, int length); - void processingInstruction(const XMLString& target, const XMLString& data); - void startPrefixMapping(const XMLString& prefix, const XMLString& uri); - void endPrefixMapping(const XMLString& prefix); - void skippedEntity(const XMLString& name); - - // ErrorHandler - void warning(const SAXException& exc); - void error(const SAXException& exc); - void fatalError(const SAXException& exc); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_DefaultHandler_INCLUDED +// +// DefaultHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/DefaultHandler.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX-2 DefaultHandler class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_DefaultHandler_INCLUDED +#define SAX_DefaultHandler_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/EntityResolver.h" +#include "Poco/SAX/DTDHandler.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/ErrorHandler.h" + + +namespace Poco { +namespace XML { + + +class XML_API DefaultHandler: public EntityResolver, public DTDHandler, public ContentHandler, public ErrorHandler + /// Default base class for SAX2 event handlers. + /// This class is available as a convenience base class for SAX2 applications: + /// it provides default implementations for all of the + /// callbacks in the four core SAX2 handler classes: + /// * EntityResolver + /// * DTDHandler + /// * ContentHandler + /// * ErrorHandler + /// Application writers can extend this class when they need to implement only + /// part of an interface; parser writers can instantiate this + /// class to provide default handlers when the application has not supplied its own. +{ +public: + DefaultHandler(); + /// Creates the DefaultHandler. + + ~DefaultHandler(); + /// Destroys the DefaultHandler. + + // EntityResolver + InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); + void releaseInputSource(InputSource* pSource); + + // DTDHandler + void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); + void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); + + // ContentHandler + void setDocumentLocator(const Locator* loc); + void startDocument(); + void endDocument(); + void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes); + void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); + void characters(const XMLChar ch[], int start, int length); + void ignorableWhitespace(const XMLChar ch[], int start, int length); + void processingInstruction(const XMLString& target, const XMLString& data); + void startPrefixMapping(const XMLString& prefix, const XMLString& uri); + void endPrefixMapping(const XMLString& prefix); + void skippedEntity(const XMLString& name); + + // ErrorHandler + void warning(const SAXException& exc); + void error(const SAXException& exc); + void fatalError(const SAXException& exc); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_DefaultHandler_INCLUDED diff --git a/XML/include/Poco/SAX/EntityResolver.h b/XML/include/Poco/SAX/EntityResolver.h index 76fa71761..088f0de29 100644 --- a/XML/include/Poco/SAX/EntityResolver.h +++ b/XML/include/Poco/SAX/EntityResolver.h @@ -1,108 +1,108 @@ -// -// EntityResolver.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/EntityResolver.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX EntityResolver Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_EntityResolver_INCLUDED -#define SAX_EntityResolver_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class InputSource; - - -class XML_API EntityResolver - /// If a SAX application needs to implement customized handling for external entities, - /// it must implement this interface and register an instance with the SAX driver using - /// the setEntityResolver method. - /// - /// The XML reader will then allow the application to intercept any external entities - /// (including the external DTD subset and external parameter entities, if any) before - /// including them. - /// - /// Many SAX applications will not need to implement this interface, but it will be - /// especially useful for applications that build XML documents from databases or other - /// specialised input sources, or for applications that use URI types other than URLs. - /// - /// The application can also use this interface to redirect system identifiers to local - /// URIs or to look up replacements in a catalog (possibly by using the public identifier). -{ -public: - virtual InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) = 0; - /// Allow the application to resolve external entities. - /// - /// The parser will call this method before opening any external entity except the - /// top-level document entity. Such entities include the external DTD subset and - /// external parameter entities referenced within the DTD (in either case, only - /// if the parser reads external parameter entities), and external general entities - /// referenced within the document element (if the parser reads external general entities). - /// The application may request that the parser locate the entity itself, that it use an - /// alternative URI, or that it use data provided by the application (as a character or - /// byte input stream). - /// - /// Application writers can use this method to redirect external system identifiers to - /// secure and/or local URIs, to look up public identifiers in a catalogue, or to read an - /// entity from a database or other input source (including, for example, a dialog box). - /// Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve - /// resources. However, SAX specifies how to interpret any InputSource returned by this method, - /// and that if none is returned, then the system ID will be dereferenced as a URL. - /// - /// If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to - /// the application. - /// - /// Note that publicId maybe null, therefore we pass a pointer rather than a reference. - - virtual void releaseInputSource(InputSource* pSource) = 0; - /// This is a non-standard extension to SAX! - /// Called by the parser when the input source returned by ResolveEntity is - /// no longer needed. Should free any resources used by the input source. - -protected: - virtual ~EntityResolver(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_EntityResolver_INCLUDED +// +// EntityResolver.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/EntityResolver.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX EntityResolver Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_EntityResolver_INCLUDED +#define SAX_EntityResolver_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class InputSource; + + +class XML_API EntityResolver + /// If a SAX application needs to implement customized handling for external entities, + /// it must implement this interface and register an instance with the SAX driver using + /// the setEntityResolver method. + /// + /// The XML reader will then allow the application to intercept any external entities + /// (including the external DTD subset and external parameter entities, if any) before + /// including them. + /// + /// Many SAX applications will not need to implement this interface, but it will be + /// especially useful for applications that build XML documents from databases or other + /// specialised input sources, or for applications that use URI types other than URLs. + /// + /// The application can also use this interface to redirect system identifiers to local + /// URIs or to look up replacements in a catalog (possibly by using the public identifier). +{ +public: + virtual InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) = 0; + /// Allow the application to resolve external entities. + /// + /// The parser will call this method before opening any external entity except the + /// top-level document entity. Such entities include the external DTD subset and + /// external parameter entities referenced within the DTD (in either case, only + /// if the parser reads external parameter entities), and external general entities + /// referenced within the document element (if the parser reads external general entities). + /// The application may request that the parser locate the entity itself, that it use an + /// alternative URI, or that it use data provided by the application (as a character or + /// byte input stream). + /// + /// Application writers can use this method to redirect external system identifiers to + /// secure and/or local URIs, to look up public identifiers in a catalogue, or to read an + /// entity from a database or other input source (including, for example, a dialog box). + /// Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve + /// resources. However, SAX specifies how to interpret any InputSource returned by this method, + /// and that if none is returned, then the system ID will be dereferenced as a URL. + /// + /// If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to + /// the application. + /// + /// Note that publicId maybe null, therefore we pass a pointer rather than a reference. + + virtual void releaseInputSource(InputSource* pSource) = 0; + /// This is a non-standard extension to SAX! + /// Called by the parser when the input source returned by ResolveEntity is + /// no longer needed. Should free any resources used by the input source. + +protected: + virtual ~EntityResolver(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_EntityResolver_INCLUDED diff --git a/XML/include/Poco/SAX/EntityResolverImpl.h b/XML/include/Poco/SAX/EntityResolverImpl.h index 6387f0afe..2ab4c88e8 100644 --- a/XML/include/Poco/SAX/EntityResolverImpl.h +++ b/XML/include/Poco/SAX/EntityResolverImpl.h @@ -1,100 +1,100 @@ -// -// EntityResolverImpl.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/EntityResolverImpl.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// An implementation of EntityResolver. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_EntityResolverImpl_INCLUDED -#define SAX_EntityResolverImpl_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/SAX/EntityResolver.h" -#include "Poco/URIStreamOpener.h" - - -namespace Poco { -namespace XML { - - -class XML_API EntityResolverImpl: public EntityResolver - /// A default implementation of the EntityResolver interface. - /// - /// The system ID is first interpreted as an URI and the - /// URIStreamOpener is used to create and open an istream - /// for an InputSource. - /// - /// If the system ID is not a valid URI, it is - /// interpreted as a filesystem path and a Poco::FileInputStream - /// is opened for it. -{ -public: - EntityResolverImpl(); - /// Creates an EntityResolverImpl that uses the default - /// URIStreamOpener. - - EntityResolverImpl(const Poco::URIStreamOpener& opener); - /// Creates an EntityResolverImpl that uses the given - /// URIStreamOpener. - - ~EntityResolverImpl(); - /// Destroys the EntityResolverImpl. - - InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); - /// Tries to use the URIStreamOpener to create and open an istream - /// for the given systemId, which is interpreted as an URI. - /// - /// If the systemId is not a valid URI, it is interpreted as - /// a local filesystem path and a Poco::FileInputStream is opened for it. - - void releaseInputSource(InputSource* pSource); - /// Deletes the InputSource's stream. - -protected: - std::istream* resolveSystemId(const XMLString& systemId); - -private: - EntityResolverImpl(const EntityResolverImpl&); - EntityResolverImpl& operator = (const EntityResolverImpl&); - - const Poco::URIStreamOpener& _opener; -}; - - -} } // namespace Poco::XML - - -#endif // SAX_EntityResolverImpl_INCLUDED +// +// EntityResolverImpl.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/EntityResolverImpl.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// An implementation of EntityResolver. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_EntityResolverImpl_INCLUDED +#define SAX_EntityResolverImpl_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/SAX/EntityResolver.h" +#include "Poco/URIStreamOpener.h" + + +namespace Poco { +namespace XML { + + +class XML_API EntityResolverImpl: public EntityResolver + /// A default implementation of the EntityResolver interface. + /// + /// The system ID is first interpreted as an URI and the + /// URIStreamOpener is used to create and open an istream + /// for an InputSource. + /// + /// If the system ID is not a valid URI, it is + /// interpreted as a filesystem path and a Poco::FileInputStream + /// is opened for it. +{ +public: + EntityResolverImpl(); + /// Creates an EntityResolverImpl that uses the default + /// URIStreamOpener. + + EntityResolverImpl(const Poco::URIStreamOpener& opener); + /// Creates an EntityResolverImpl that uses the given + /// URIStreamOpener. + + ~EntityResolverImpl(); + /// Destroys the EntityResolverImpl. + + InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); + /// Tries to use the URIStreamOpener to create and open an istream + /// for the given systemId, which is interpreted as an URI. + /// + /// If the systemId is not a valid URI, it is interpreted as + /// a local filesystem path and a Poco::FileInputStream is opened for it. + + void releaseInputSource(InputSource* pSource); + /// Deletes the InputSource's stream. + +protected: + std::istream* resolveSystemId(const XMLString& systemId); + +private: + EntityResolverImpl(const EntityResolverImpl&); + EntityResolverImpl& operator = (const EntityResolverImpl&); + + const Poco::URIStreamOpener& _opener; +}; + + +} } // namespace Poco::XML + + +#endif // SAX_EntityResolverImpl_INCLUDED diff --git a/XML/include/Poco/SAX/ErrorHandler.h b/XML/include/Poco/SAX/ErrorHandler.h index 0c4029f69..059625c0b 100644 --- a/XML/include/Poco/SAX/ErrorHandler.h +++ b/XML/include/Poco/SAX/ErrorHandler.h @@ -1,114 +1,114 @@ -// -// ErrorHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/ErrorHandler.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX ErrorHandler Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_ErrorHandler_INCLUDED -#define SAX_ErrorHandler_INCLUDED - - -#include "Poco/XML/XML.h" - - -namespace Poco { -namespace XML { - - -class SAXException; - - -class XML_API ErrorHandler - /// If a SAX application needs to implement customized error handling, it must - /// implement this interface and then register an instance with the XML reader - /// using the setErrorHandler method. The parser will then report all errors and - /// warnings through this interface. - /// - /// WARNING: If an application does not register an ErrorHandler, XML parsing errors - /// will go unreported, except that SAXParseExceptions will be thrown for fatal errors. - /// In order to detect validity errors, an ErrorHandler that does something with error() - /// calls must be registered. - /// - /// For XML processing errors, a SAX driver must use this interface in preference to - /// throwing an exception: it is up to the application to decide whether to throw an - /// exception for different types of errors and warnings. Note, however, that there is no - /// requirement that the parser continue to report additional errors after a call to - /// fatalError. In other words, a SAX driver class may throw an exception after reporting - /// any fatalError. Also parsers may throw appropriate exceptions for non-XML errors. For - /// example, XMLReader::parse() would throw an IOException for errors accessing entities or - /// the document. -{ -public: - virtual void warning(const SAXException& exc) = 0; - /// Receive notification of a warning. - /// - /// SAX parsers will use this method to report conditions that are not errors or fatal - /// errors as defined by the XML recommendation. The default behaviour is to take no action. - /// - /// The SAX parser must continue to provide normal parsing events after invoking this method: - /// it should still be possible for the application to process the document through to the end. - /// - /// Filters may use this method to report other, non-XML warnings as well. - - virtual void error(const SAXException& exc) = 0; - /// Receive notification of a recoverable error. - /// - /// This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 - /// Recommendation. For example, a validating parser would use this callback to report - /// the violation of a validity constraint. The default behaviour is to take no action. - /// - /// The SAX parser must continue to provide normal parsing events after invoking this - /// method: it should still be possible for the application to process the document through - /// to the end. If the application cannot do so, then the parser should report a fatal error - /// even if the XML recommendation does not require it to do so. - /// - /// Filters may use this method to report other, non-XML errors as well. - - virtual void fatalError(const SAXException& exc) = 0; - /// Receive notification of a non-recoverable error. - /// The application must assume that the document is unusable after the parser has - /// invoked this method, and should continue (if at all) only for the sake of collecting - /// additional error messages: in fact, SAX parsers are free to stop reporting any other - /// events once this method has been invoked. - -protected: - virtual ~ErrorHandler(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_ErrorHandler_INCLUDED +// +// ErrorHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/ErrorHandler.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX ErrorHandler Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_ErrorHandler_INCLUDED +#define SAX_ErrorHandler_INCLUDED + + +#include "Poco/XML/XML.h" + + +namespace Poco { +namespace XML { + + +class SAXException; + + +class XML_API ErrorHandler + /// If a SAX application needs to implement customized error handling, it must + /// implement this interface and then register an instance with the XML reader + /// using the setErrorHandler method. The parser will then report all errors and + /// warnings through this interface. + /// + /// WARNING: If an application does not register an ErrorHandler, XML parsing errors + /// will go unreported, except that SAXParseExceptions will be thrown for fatal errors. + /// In order to detect validity errors, an ErrorHandler that does something with error() + /// calls must be registered. + /// + /// For XML processing errors, a SAX driver must use this interface in preference to + /// throwing an exception: it is up to the application to decide whether to throw an + /// exception for different types of errors and warnings. Note, however, that there is no + /// requirement that the parser continue to report additional errors after a call to + /// fatalError. In other words, a SAX driver class may throw an exception after reporting + /// any fatalError. Also parsers may throw appropriate exceptions for non-XML errors. For + /// example, XMLReader::parse() would throw an IOException for errors accessing entities or + /// the document. +{ +public: + virtual void warning(const SAXException& exc) = 0; + /// Receive notification of a warning. + /// + /// SAX parsers will use this method to report conditions that are not errors or fatal + /// errors as defined by the XML recommendation. The default behaviour is to take no action. + /// + /// The SAX parser must continue to provide normal parsing events after invoking this method: + /// it should still be possible for the application to process the document through to the end. + /// + /// Filters may use this method to report other, non-XML warnings as well. + + virtual void error(const SAXException& exc) = 0; + /// Receive notification of a recoverable error. + /// + /// This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 + /// Recommendation. For example, a validating parser would use this callback to report + /// the violation of a validity constraint. The default behaviour is to take no action. + /// + /// The SAX parser must continue to provide normal parsing events after invoking this + /// method: it should still be possible for the application to process the document through + /// to the end. If the application cannot do so, then the parser should report a fatal error + /// even if the XML recommendation does not require it to do so. + /// + /// Filters may use this method to report other, non-XML errors as well. + + virtual void fatalError(const SAXException& exc) = 0; + /// Receive notification of a non-recoverable error. + /// The application must assume that the document is unusable after the parser has + /// invoked this method, and should continue (if at all) only for the sake of collecting + /// additional error messages: in fact, SAX parsers are free to stop reporting any other + /// events once this method has been invoked. + +protected: + virtual ~ErrorHandler(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_ErrorHandler_INCLUDED diff --git a/XML/include/Poco/SAX/InputSource.h b/XML/include/Poco/SAX/InputSource.h index 8c584805c..f9b4b7744 100644 --- a/XML/include/Poco/SAX/InputSource.h +++ b/XML/include/Poco/SAX/InputSource.h @@ -1,191 +1,191 @@ -// -// InputSource.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/InputSource.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX InputSource - A single input source for an XML entity. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_InputSource_INCLUDED -#define SAX_InputSource_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/XMLStream.h" - - -namespace Poco { -namespace XML { - - -class XML_API InputSource - /// This class allows a SAX application to encapsulate information about an input - /// source in a single object, which may include a public identifier, a system - /// identifier, a byte stream (possibly with a specified encoding), and/or a character - /// stream. - /// - /// There are two places that the application can deliver an input source to the - /// parser: as the argument to the Parser.parse method, or as the return value of the - /// EntityResolver::resolveEntity() method. - /// - /// The SAX parser will use the InputSource object to determine how to read XML input. - /// If there is a character stream available, the parser will read that stream directly, - /// disregarding any text encoding declaration found in that stream. If there is no character - /// stream, but there is a byte stream, the parser will use that byte stream, using the - /// encoding specified in the InputSource or else (if no encoding is specified) autodetecting - /// the character encoding using an algorithm such as the one in the XML specification. - /// If neither a character stream nor a byte stream is available, the parser will attempt - /// to open a URI connection to the resource identified by the system identifier. - /// - /// An InputSource object belongs to the application: the SAX parser shall never modify it in - /// any way (it may modify a copy if necessary). However, standard processing of both byte and - /// character streams is to close them on as part of end-of-parse cleanup, so applications should - /// not attempt to re-use such streams after they have been handed to a parser. -{ -public: - InputSource(); - /// Zero-argument default constructor. - - InputSource(const XMLString& systemId); - /// Creates a new input source with a system identifier. - /// Applications may use setPublicId to include a public identifier as well, - /// or setEncoding to specify the character encoding, if known. - /// - /// If the system identifier is a URL, it must be fully resolved (it may not - /// be a relative URL). - - InputSource(XMLByteInputStream& istr); - /// Creates a new input source with a byte stream. - /// - /// Application writers should use setSystemId() to provide a base for resolving - /// relative URIs, may use setPublicId to include a public identifier, and may use - /// setEncoding to specify the object's character encoding. - - ~InputSource(); - /// Destroys the InputSource. - - void setPublicId(const XMLString& publicId); - /// Set the public identifier for this input source. - /// - /// The public identifier is always optional: if the application writer includes one, - /// it will be provided as part of the location information. - - void setSystemId(const XMLString& systemId); - /// Set the system identifier for this input source. - /// - /// The system identifier is optional if there is a byte stream or a character stream, - /// but it is still useful to provide one, since the application can use it to resolve - /// relative URIs and can include it in error messages and warnings (the parser will - /// attempt to open a connection to the URI only if there is no byte stream or character - /// stream specified). - /// - /// If the application knows the character encoding of the object pointed to by the system - /// identifier, it can register the encoding using the setEncoding method. - /// - /// If the system identifier is a URL, it must be fully resolved (it may not be a relative URL). - - const XMLString& getPublicId() const; - /// Get the public identifier for this input source. - - const XMLString& getSystemId() const; - /// Get the system identifier for this input source. - - void setByteStream(XMLByteInputStream& istr); - /// Set the byte stream for this input source. - /// The SAX parser will ignore this if there is also a character stream specified, but it - /// will use a byte stream in preference to opening a URI connection itself. - - XMLByteInputStream* getByteStream() const; - /// Get the byte stream for this input source. - - void setCharacterStream(XMLCharInputStream& istr); - /// Set the character stream for this input source. - - XMLCharInputStream* getCharacterStream() const; - /// Get the character stream for this input source. - - void setEncoding(const XMLString& encoding); - /// Set the character encoding, if known. - /// The encoding must be a string acceptable for an XML encoding declaration - /// (see section 4.3.3 of the XML 1.0 recommendation). - - const XMLString& getEncoding() const; - /// Get the character encoding for a byte stream or URI. - -private: - XMLString _publicId; - XMLString _systemId; - XMLString _encoding; - XMLByteInputStream* _bistr; - XMLCharInputStream* _cistr; -}; - - -// -// inlines -// -inline const XMLString& InputSource::getPublicId() const -{ - return _publicId; -} - - -inline const XMLString& InputSource::getSystemId() const -{ - return _systemId; -} - - -inline const XMLString& InputSource::getEncoding() const -{ - return _encoding; -} - - -inline XMLByteInputStream* InputSource::getByteStream() const -{ - return _bistr; -} - - -inline XMLCharInputStream* InputSource::getCharacterStream() const -{ - return _cistr; -} - - -} } // namespace Poco::XML - - -#endif // SAX_InputSource_INCLUDED +// +// InputSource.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/InputSource.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX InputSource - A single input source for an XML entity. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_InputSource_INCLUDED +#define SAX_InputSource_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/XMLStream.h" + + +namespace Poco { +namespace XML { + + +class XML_API InputSource + /// This class allows a SAX application to encapsulate information about an input + /// source in a single object, which may include a public identifier, a system + /// identifier, a byte stream (possibly with a specified encoding), and/or a character + /// stream. + /// + /// There are two places that the application can deliver an input source to the + /// parser: as the argument to the Parser.parse method, or as the return value of the + /// EntityResolver::resolveEntity() method. + /// + /// The SAX parser will use the InputSource object to determine how to read XML input. + /// If there is a character stream available, the parser will read that stream directly, + /// disregarding any text encoding declaration found in that stream. If there is no character + /// stream, but there is a byte stream, the parser will use that byte stream, using the + /// encoding specified in the InputSource or else (if no encoding is specified) autodetecting + /// the character encoding using an algorithm such as the one in the XML specification. + /// If neither a character stream nor a byte stream is available, the parser will attempt + /// to open a URI connection to the resource identified by the system identifier. + /// + /// An InputSource object belongs to the application: the SAX parser shall never modify it in + /// any way (it may modify a copy if necessary). However, standard processing of both byte and + /// character streams is to close them on as part of end-of-parse cleanup, so applications should + /// not attempt to re-use such streams after they have been handed to a parser. +{ +public: + InputSource(); + /// Zero-argument default constructor. + + InputSource(const XMLString& systemId); + /// Creates a new input source with a system identifier. + /// Applications may use setPublicId to include a public identifier as well, + /// or setEncoding to specify the character encoding, if known. + /// + /// If the system identifier is a URL, it must be fully resolved (it may not + /// be a relative URL). + + InputSource(XMLByteInputStream& istr); + /// Creates a new input source with a byte stream. + /// + /// Application writers should use setSystemId() to provide a base for resolving + /// relative URIs, may use setPublicId to include a public identifier, and may use + /// setEncoding to specify the object's character encoding. + + ~InputSource(); + /// Destroys the InputSource. + + void setPublicId(const XMLString& publicId); + /// Set the public identifier for this input source. + /// + /// The public identifier is always optional: if the application writer includes one, + /// it will be provided as part of the location information. + + void setSystemId(const XMLString& systemId); + /// Set the system identifier for this input source. + /// + /// The system identifier is optional if there is a byte stream or a character stream, + /// but it is still useful to provide one, since the application can use it to resolve + /// relative URIs and can include it in error messages and warnings (the parser will + /// attempt to open a connection to the URI only if there is no byte stream or character + /// stream specified). + /// + /// If the application knows the character encoding of the object pointed to by the system + /// identifier, it can register the encoding using the setEncoding method. + /// + /// If the system identifier is a URL, it must be fully resolved (it may not be a relative URL). + + const XMLString& getPublicId() const; + /// Get the public identifier for this input source. + + const XMLString& getSystemId() const; + /// Get the system identifier for this input source. + + void setByteStream(XMLByteInputStream& istr); + /// Set the byte stream for this input source. + /// The SAX parser will ignore this if there is also a character stream specified, but it + /// will use a byte stream in preference to opening a URI connection itself. + + XMLByteInputStream* getByteStream() const; + /// Get the byte stream for this input source. + + void setCharacterStream(XMLCharInputStream& istr); + /// Set the character stream for this input source. + + XMLCharInputStream* getCharacterStream() const; + /// Get the character stream for this input source. + + void setEncoding(const XMLString& encoding); + /// Set the character encoding, if known. + /// The encoding must be a string acceptable for an XML encoding declaration + /// (see section 4.3.3 of the XML 1.0 recommendation). + + const XMLString& getEncoding() const; + /// Get the character encoding for a byte stream or URI. + +private: + XMLString _publicId; + XMLString _systemId; + XMLString _encoding; + XMLByteInputStream* _bistr; + XMLCharInputStream* _cistr; +}; + + +// +// inlines +// +inline const XMLString& InputSource::getPublicId() const +{ + return _publicId; +} + + +inline const XMLString& InputSource::getSystemId() const +{ + return _systemId; +} + + +inline const XMLString& InputSource::getEncoding() const +{ + return _encoding; +} + + +inline XMLByteInputStream* InputSource::getByteStream() const +{ + return _bistr; +} + + +inline XMLCharInputStream* InputSource::getCharacterStream() const +{ + return _cistr; +} + + +} } // namespace Poco::XML + + +#endif // SAX_InputSource_INCLUDED diff --git a/XML/include/Poco/SAX/LexicalHandler.h b/XML/include/Poco/SAX/LexicalHandler.h index 14976ecc0..6459c91c9 100644 --- a/XML/include/Poco/SAX/LexicalHandler.h +++ b/XML/include/Poco/SAX/LexicalHandler.h @@ -1,147 +1,147 @@ -// -// LexicalHandler.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/LexicalHandler.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX2-ext LexicalHandler Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_LexicalHandler_INCLUDED -#define SAX_LexicalHandler_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API LexicalHandler - /// This is an optional extension handler for SAX2 to provide lexical information - /// about an XML document, such as comments and CDATA section boundaries. - /// XML readers are not required to recognize this handler, and it is not part of - /// core-only SAX2 distributions. - /// - /// The events in the lexical handler apply to the entire document, not just to the - /// document element, and all lexical handler events must appear between the content - /// handler's startDocument and endDocument events. - /// - /// To set the LexicalHandler for an XML reader, use the setProperty method with the - /// property name http://xml.org/sax/properties/lexical-handler and an object implementing - /// this interface (or null) as the value. If the reader does not report lexical events, - /// it will throw a SAXNotRecognizedException when you attempt to register the handler. -{ -public: - virtual void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) = 0; - /// Report the start of DTD declarations, if any. - /// - /// This method is intended to report the beginning of the DOCTYPE declaration; - /// if the document has no DOCTYPE declaration, this method will not be invoked. - /// - /// All declarations reported through DTDHandler or DeclHandler events must appear - /// between the startDTD and endDTD events. Declarations are assumed to belong to - /// the internal DTD subset unless they appear between startEntity and endEntity - /// events. Comments and processing instructions from the DTD should also be reported - /// between the startDTD and endDTD events, in their original order of (logical) occurrence; - /// they are not required to appear in their correct locations relative to DTDHandler or - /// DeclHandler events, however. - /// - /// Note that the start/endDTD events will appear within the start/endDocument events from - /// ContentHandler and before the first startElement event. - - virtual void endDTD() = 0; - /// Report the end of DTD declarations. - /// - /// This method is intended to report the end of the DOCTYPE declaration; if the document - /// has no DOCTYPE declaration, this method will not be invoked. - - virtual void startEntity(const XMLString& name) = 0; - /// Report the beginning of some internal and external XML entities. - /// - /// The reporting of parameter entities (including the external DTD subset) is optional, - /// and SAX2 drivers that report LexicalHandler events may not implement it; you can use the - /// http://xml.org/sax/features/lexical-handler/parameter-entities feature to query or control - /// the reporting of parameter entities. - /// - /// General entities are reported with their regular names, parameter entities have '%' - /// prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]". - /// - /// When a SAX2 driver is providing these events, all other events must be properly nested - /// within start/end entity events. There is no additional requirement that events from - /// DeclHandler or DTDHandler be properly ordered. - /// - /// Note that skipped entities will be reported through the skippedEntity event, which is part of - /// the ContentHandler interface. - /// - /// Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under - /// any circumstances: - /// - /// * general entities within attribute values - /// * parameter entities within declarations - /// - /// These will be silently expanded, with no indication of where the original entity boundaries were. - /// - /// Note also that the boundaries of character references (which are not really entities anyway) are not reported. - /// - /// All start/endEntity events must be properly nested. - - virtual void endEntity(const XMLString& name) = 0; - /// Report the end of an entity. - - virtual void startCDATA() = 0; - /// Report the start of a CDATA section. - /// - /// The contents of the CDATA section will be reported through the regular characters event; - /// this event is intended only to report the boundary. - - virtual void endCDATA() = 0; - /// Report the end of a CDATA section. - - virtual void comment(const XMLChar ch[], int start, int length) = 0; - /// Report an XML comment anywhere in the document. - /// - /// This callback will be used for comments inside or outside the document element, - /// including comments in the external DTD subset (if read). Comments in the DTD must - /// be properly nested inside start/endDTD and start/endEntity events (if used). - -protected: - virtual ~LexicalHandler(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_LexicalHandler_INCLUDED +// +// LexicalHandler.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/LexicalHandler.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX2-ext LexicalHandler Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_LexicalHandler_INCLUDED +#define SAX_LexicalHandler_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API LexicalHandler + /// This is an optional extension handler for SAX2 to provide lexical information + /// about an XML document, such as comments and CDATA section boundaries. + /// XML readers are not required to recognize this handler, and it is not part of + /// core-only SAX2 distributions. + /// + /// The events in the lexical handler apply to the entire document, not just to the + /// document element, and all lexical handler events must appear between the content + /// handler's startDocument and endDocument events. + /// + /// To set the LexicalHandler for an XML reader, use the setProperty method with the + /// property name http://xml.org/sax/properties/lexical-handler and an object implementing + /// this interface (or null) as the value. If the reader does not report lexical events, + /// it will throw a SAXNotRecognizedException when you attempt to register the handler. +{ +public: + virtual void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) = 0; + /// Report the start of DTD declarations, if any. + /// + /// This method is intended to report the beginning of the DOCTYPE declaration; + /// if the document has no DOCTYPE declaration, this method will not be invoked. + /// + /// All declarations reported through DTDHandler or DeclHandler events must appear + /// between the startDTD and endDTD events. Declarations are assumed to belong to + /// the internal DTD subset unless they appear between startEntity and endEntity + /// events. Comments and processing instructions from the DTD should also be reported + /// between the startDTD and endDTD events, in their original order of (logical) occurrence; + /// they are not required to appear in their correct locations relative to DTDHandler or + /// DeclHandler events, however. + /// + /// Note that the start/endDTD events will appear within the start/endDocument events from + /// ContentHandler and before the first startElement event. + + virtual void endDTD() = 0; + /// Report the end of DTD declarations. + /// + /// This method is intended to report the end of the DOCTYPE declaration; if the document + /// has no DOCTYPE declaration, this method will not be invoked. + + virtual void startEntity(const XMLString& name) = 0; + /// Report the beginning of some internal and external XML entities. + /// + /// The reporting of parameter entities (including the external DTD subset) is optional, + /// and SAX2 drivers that report LexicalHandler events may not implement it; you can use the + /// http://xml.org/sax/features/lexical-handler/parameter-entities feature to query or control + /// the reporting of parameter entities. + /// + /// General entities are reported with their regular names, parameter entities have '%' + /// prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]". + /// + /// When a SAX2 driver is providing these events, all other events must be properly nested + /// within start/end entity events. There is no additional requirement that events from + /// DeclHandler or DTDHandler be properly ordered. + /// + /// Note that skipped entities will be reported through the skippedEntity event, which is part of + /// the ContentHandler interface. + /// + /// Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under + /// any circumstances: + /// + /// * general entities within attribute values + /// * parameter entities within declarations + /// + /// These will be silently expanded, with no indication of where the original entity boundaries were. + /// + /// Note also that the boundaries of character references (which are not really entities anyway) are not reported. + /// + /// All start/endEntity events must be properly nested. + + virtual void endEntity(const XMLString& name) = 0; + /// Report the end of an entity. + + virtual void startCDATA() = 0; + /// Report the start of a CDATA section. + /// + /// The contents of the CDATA section will be reported through the regular characters event; + /// this event is intended only to report the boundary. + + virtual void endCDATA() = 0; + /// Report the end of a CDATA section. + + virtual void comment(const XMLChar ch[], int start, int length) = 0; + /// Report an XML comment anywhere in the document. + /// + /// This callback will be used for comments inside or outside the document element, + /// including comments in the external DTD subset (if read). Comments in the DTD must + /// be properly nested inside start/endDTD and start/endEntity events (if used). + +protected: + virtual ~LexicalHandler(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_LexicalHandler_INCLUDED diff --git a/XML/include/Poco/SAX/Locator.h b/XML/include/Poco/SAX/Locator.h index ba6117d1b..a72e9c3b9 100644 --- a/XML/include/Poco/SAX/Locator.h +++ b/XML/include/Poco/SAX/Locator.h @@ -1,125 +1,125 @@ -// -// Locator.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/Locator.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX Locator Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_Locator_INCLUDED -#define SAX_Locator_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Locator - /// Interface for associating a SAX event with a document location. - /// - /// If a SAX parser provides location information to the SAX application, it does so by - /// implementing this interface and then passing an instance to the application using the - /// content handler's setDocumentLocator method. The application can use the object to obtain - /// the location of any other SAX event in the XML source document. - /// - /// Note that the results returned by the object will be valid only during the scope of each - /// callback method: the application will receive unpredictable results if it attempts to use - /// the locator at any other time, or after parsing completes. - /// - /// SAX parsers are not required to supply a locator, but they are very strongly encouraged to - /// do so. If the parser supplies a locator, it must do so before reporting any other document - /// events. If no locator has been set by the time the application receives the startDocument event, - /// the application should assume that a locator is not available. -{ -public: - virtual XMLString getPublicId() const = 0; - /// Return the public identifier for the current document event. - /// - /// The return value is the public identifier of the document entity or of the external - /// parsed entity in which the markup triggering the event appears. - - virtual XMLString getSystemId() const = 0; - /// Return the system identifier for the current document event. - /// - /// The return value is the system identifier of the document entity or of the external - /// parsed entity in which the markup triggering the event appears. - /// - /// If the system identifier is a URL, the parser must resolve it fully before passing - /// it to the application. For example, a file name must always be provided as a - /// file:... URL, and other kinds of relative URI are also resolved against their bases. - - virtual int getLineNumber() const = 0; - /// Return the line number where the current document event ends. - /// Lines are delimited by line ends, which are defined in the XML specification. - /// - /// Warning: The return value from the method is intended only as an approximation for - /// the sake of diagnostics; it is not intended to provide sufficient information to - /// edit the character content of the original XML document. In some cases, these "line" - /// numbers match what would be displayed as columns, and in others they may not match the - /// source text due to internal entity expansion. - /// - /// The return value is an approximation of the line number in the document entity or external - /// parsed entity where the markup triggering the event appears. - /// - /// If possible, the SAX driver should provide the line position of the first character after - /// the text associated with the document event. The first line is line 1. - - virtual int getColumnNumber() const = 0; - /// Return the column number where the current document event ends. - /// This is one-based number of characters since the last line end. - /// - /// Warning: The return value from the method is intended only as an approximation - /// for the sake of diagnostics; it is not intended to provide sufficient information - /// to edit the character content of the original XML document. For example, when lines - /// contain combining character sequences, wide characters, surrogate pairs, or bi-directional - /// text, the value may not correspond to the column in a text editor's display. - /// - /// The return value is an approximation of the column number in the document entity or external - /// parsed entity where the markup triggering the event appears. - /// - /// If possible, the SAX driver should provide the line position of the first character after - /// the text associated with the document event. The first column in each line is column 1. - -protected: - virtual ~Locator(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_Locator_INCLUDED +// +// Locator.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/Locator.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX Locator Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_Locator_INCLUDED +#define SAX_Locator_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Locator + /// Interface for associating a SAX event with a document location. + /// + /// If a SAX parser provides location information to the SAX application, it does so by + /// implementing this interface and then passing an instance to the application using the + /// content handler's setDocumentLocator method. The application can use the object to obtain + /// the location of any other SAX event in the XML source document. + /// + /// Note that the results returned by the object will be valid only during the scope of each + /// callback method: the application will receive unpredictable results if it attempts to use + /// the locator at any other time, or after parsing completes. + /// + /// SAX parsers are not required to supply a locator, but they are very strongly encouraged to + /// do so. If the parser supplies a locator, it must do so before reporting any other document + /// events. If no locator has been set by the time the application receives the startDocument event, + /// the application should assume that a locator is not available. +{ +public: + virtual XMLString getPublicId() const = 0; + /// Return the public identifier for the current document event. + /// + /// The return value is the public identifier of the document entity or of the external + /// parsed entity in which the markup triggering the event appears. + + virtual XMLString getSystemId() const = 0; + /// Return the system identifier for the current document event. + /// + /// The return value is the system identifier of the document entity or of the external + /// parsed entity in which the markup triggering the event appears. + /// + /// If the system identifier is a URL, the parser must resolve it fully before passing + /// it to the application. For example, a file name must always be provided as a + /// file:... URL, and other kinds of relative URI are also resolved against their bases. + + virtual int getLineNumber() const = 0; + /// Return the line number where the current document event ends. + /// Lines are delimited by line ends, which are defined in the XML specification. + /// + /// Warning: The return value from the method is intended only as an approximation for + /// the sake of diagnostics; it is not intended to provide sufficient information to + /// edit the character content of the original XML document. In some cases, these "line" + /// numbers match what would be displayed as columns, and in others they may not match the + /// source text due to internal entity expansion. + /// + /// The return value is an approximation of the line number in the document entity or external + /// parsed entity where the markup triggering the event appears. + /// + /// If possible, the SAX driver should provide the line position of the first character after + /// the text associated with the document event. The first line is line 1. + + virtual int getColumnNumber() const = 0; + /// Return the column number where the current document event ends. + /// This is one-based number of characters since the last line end. + /// + /// Warning: The return value from the method is intended only as an approximation + /// for the sake of diagnostics; it is not intended to provide sufficient information + /// to edit the character content of the original XML document. For example, when lines + /// contain combining character sequences, wide characters, surrogate pairs, or bi-directional + /// text, the value may not correspond to the column in a text editor's display. + /// + /// The return value is an approximation of the column number in the document entity or external + /// parsed entity where the markup triggering the event appears. + /// + /// If possible, the SAX driver should provide the line position of the first character after + /// the text associated with the document event. The first column in each line is column 1. + +protected: + virtual ~Locator(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_Locator_INCLUDED diff --git a/XML/include/Poco/SAX/LocatorImpl.h b/XML/include/Poco/SAX/LocatorImpl.h index 5e9206b4b..87b8f2763 100644 --- a/XML/include/Poco/SAX/LocatorImpl.h +++ b/XML/include/Poco/SAX/LocatorImpl.h @@ -1,110 +1,110 @@ -// -// LocatorImpl.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/LocatorImpl.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// An implementation of the SAX Locator interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_LocatorImpl_INCLUDED -#define SAX_LocatorImpl_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/Locator.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API LocatorImpl: public Locator - /// Provide an optional convenience implementation of Locator. -{ -public: - LocatorImpl(); - /// Zero-argument constructor. - /// - /// This will not normally be useful, since the main purpose of this class is - /// to make a snapshot of an existing Locator. - - LocatorImpl(const Locator& loc); - /// Copy constructor. - /// - /// Create a persistent copy of the current state of a locator. When the original - /// locator changes, this copy will still keep the original values (and it can be - /// used outside the scope of DocumentHandler methods). - - ~LocatorImpl(); - /// Destroys the Locator. - - LocatorImpl& operator = (const Locator& loc); - /// Assignment operator. - - XMLString getPublicId() const; - /// Return the saved public identifier. - - XMLString getSystemId() const; - /// Return the saved system identifier. - - int getLineNumber() const; - /// Return the saved line number (1-based). - - int getColumnNumber() const; - /// Return the saved column number (1-based). - - void setPublicId(const XMLString& publicId); - /// Set the public identifier for this locator. - - void setSystemId(const XMLString& systemId); - /// Set the system identifier for this locator. - - void setLineNumber(int lineNumber); - /// Set the line number for this locator (1-based). - - void setColumnNumber(int columnNumber); - /// Set the column number for this locator (1-based). - -private: - XMLString _publicId; - XMLString _systemId; - int _lineNumber; - int _columnNumber; -}; - - -} } // namespace Poco::XML - - -#endif // SAX_LocatorImpl_INCLUDED +// +// LocatorImpl.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/LocatorImpl.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// An implementation of the SAX Locator interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_LocatorImpl_INCLUDED +#define SAX_LocatorImpl_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/Locator.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API LocatorImpl: public Locator + /// Provide an optional convenience implementation of Locator. +{ +public: + LocatorImpl(); + /// Zero-argument constructor. + /// + /// This will not normally be useful, since the main purpose of this class is + /// to make a snapshot of an existing Locator. + + LocatorImpl(const Locator& loc); + /// Copy constructor. + /// + /// Create a persistent copy of the current state of a locator. When the original + /// locator changes, this copy will still keep the original values (and it can be + /// used outside the scope of DocumentHandler methods). + + ~LocatorImpl(); + /// Destroys the Locator. + + LocatorImpl& operator = (const Locator& loc); + /// Assignment operator. + + XMLString getPublicId() const; + /// Return the saved public identifier. + + XMLString getSystemId() const; + /// Return the saved system identifier. + + int getLineNumber() const; + /// Return the saved line number (1-based). + + int getColumnNumber() const; + /// Return the saved column number (1-based). + + void setPublicId(const XMLString& publicId); + /// Set the public identifier for this locator. + + void setSystemId(const XMLString& systemId); + /// Set the system identifier for this locator. + + void setLineNumber(int lineNumber); + /// Set the line number for this locator (1-based). + + void setColumnNumber(int columnNumber); + /// Set the column number for this locator (1-based). + +private: + XMLString _publicId; + XMLString _systemId; + int _lineNumber; + int _columnNumber; +}; + + +} } // namespace Poco::XML + + +#endif // SAX_LocatorImpl_INCLUDED diff --git a/XML/include/Poco/SAX/NamespaceSupport.h b/XML/include/Poco/SAX/NamespaceSupport.h index 300cda2a5..4470ba5a9 100644 --- a/XML/include/Poco/SAX/NamespaceSupport.h +++ b/XML/include/Poco/SAX/NamespaceSupport.h @@ -1,217 +1,217 @@ -// -// NamespaceSupport.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/NamespaceSupport.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Namespace support for SAX2. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_NamespaceSupport_INCLUDED -#define SAX_NamespaceSupport_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include -#include -#include - - -namespace Poco { -namespace XML { - - -class XML_API NamespaceSupport - /// Encapsulate Namespace logic for use by SAX drivers. - /// This class encapsulates the logic of Namespace processing: - /// it tracks the declarations currently in force for each context and - /// automatically processes qualified XML 1.0 names into their Namespace - /// parts; it can also be used in reverse for generating - /// XML 1.0 from Namespaces. - /// Namespace support objects are reusable, but the reset method - /// must be invoked between each session. -{ -public: - typedef std::set PrefixSet; - - NamespaceSupport(); - /// Creates a NamespaceSupport object. - - ~NamespaceSupport(); - /// Destroys a NamespaceSupport object. - - bool declarePrefix(const XMLString& prefix, const XMLString& namespaceURI); - /// Declare a Namespace prefix. All prefixes must be declared before they are - /// referenced. For example, a SAX driver (parser) would scan an element's attributes - /// in two passes: first for namespace declarations, then a second pass using - /// processName() to interpret prefixes against (potentially redefined) prefixes. - /// - /// This method declares a prefix in the current Namespace context; the prefix - /// will remain in force until this context is popped, unless it is shadowed - /// in a descendant context. - /// - /// To declare the default element Namespace, use the empty string as the prefix. - /// - /// Note that you must not declare a prefix after you've pushed and popped another - /// Namespace context, or treated the declarations phase as complete by processing - /// a prefixed name. - /// - /// Returns true if the prefix was legal, false otherwise. - - bool undeclarePrefix(const XMLString& prefix); - /// Remove the given namespace prefix. - - void getDeclaredPrefixes(PrefixSet& prefixes) const; - /// Return an enumeration of all prefixes declared in this context. - /// - /// The empty (default) prefix will be included in this enumeration; note that - /// this behaviour differs from that of getPrefix(java.lang.String) and getPrefixes(). - - const XMLString& getPrefix(const XMLString& namespaceURI) const; - /// Return one of the prefixes mapped to a Namespace URI. - /// - /// If more than one prefix is currently mapped to the same URI, this method - /// will make an arbitrary selection; if you want all of the prefixes, use the - /// getPrefixes() method instead. - - bool isMapped(const XMLString& namespaceURI) const; - /// Returns true if the given namespaceURI has been mapped to a prefix, - /// false otherwise. - - void getPrefixes(PrefixSet& prefixes) const; - /// Return an enumeration of all prefixes whose declarations are active in the - /// current context. This includes declarations from parent contexts that have - /// not been overridden. - /// - /// Note: if there is a default prefix, it will not be returned in this enumeration; - /// check for the default prefix using the getURI with an argument of "". - - void getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const; - /// Return an enumeration of all prefixes for a given URI whose declarations - /// are active in the current context. This includes declarations from parent - /// contexts that have not been overridden. - /// - /// This method returns prefixes mapped to a specific Namespace URI. The xml: - /// prefix will be included. If you want only one prefix that's mapped to the - /// Namespace URI, and you don't care which one you get, use the getPrefix() method - /// instead. - /// - /// Note: the empty (default) prefix is never included in this enumeration; - /// to check for the presence of a default Namespace, use the getURI() method - /// with an argument of "". - - const XMLString& getURI(const XMLString& prefix) const; - /// Look up a prefix and get the currently-mapped Namespace URI. - /// - /// This method looks up the prefix in the current context. Use the empty string - /// ("") for the default Namespace. - - void pushContext(); - /// Start a new Namespace context. The new context will automatically inherit - /// the declarations of its parent context, but it will also keep track of which - /// declarations were made within this context. - /// - /// Event callback code should start a new context once per element. This means - /// being ready to call this in either of two places. For elements that don't - /// include namespace declarations, the ContentHandler::startElement() callback - /// is the right place. For elements with such a declaration, it'd done in the - /// first ContentHandler::startPrefixMapping() callback. A boolean flag can be - /// used to track whether a context has been started yet. When either of those - /// methods is called, it checks the flag to see if a new context needs to be - /// started. If so, it starts the context and sets the flag. After - /// ContentHandler::startElement() does that, it always clears the flag. - /// - /// Normally, SAX drivers would push a new context at the beginning of each - /// XML element. Then they perform a first pass over the attributes to process - /// all namespace declarations, making ContentHandler::startPrefixMapping() callbacks. - /// Then a second pass is made, to determine the namespace-qualified names for - /// all attributes and for the element name. Finally all the information for - /// the ContentHandler::startElement() callback is available, so it can then - /// be made. - /// - /// The Namespace support object always starts with a base context already in - /// force: in this context, only the "xml" prefix is declared. - - void popContext(); - /// Revert to the previous Namespace context. - /// - /// Normally, you should pop the context at the end of each XML element. After - /// popping the context, all Namespace prefix mappings that were previously - /// in force are restored. - /// - /// You must not attempt to declare additional Namespace prefixes after popping - /// a context, unless you push another context first. - - bool processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const; - /// Process a raw XML 1.0 name. - /// This method processes a raw XML 1.0 name in the current context - /// by removing the prefix and looking it up among the - /// prefixes currently declared. The result will be returned in - /// namespaceURI and localName. - /// If the raw name has a prefix that has not been declared, then the return - /// value will be false, otherwise true. - /// - /// Note that attribute names are processed differently than element names: - /// an unprefixed element name will received the - /// default Namespace (if any), while an unprefixed element name will not. - - void reset(); - /// Reset this Namespace support object for reuse. - /// - /// It is necessary to invoke this method before reusing the Namespace support - /// object for a new session. If namespace declaration URIs are to be supported, - /// that flag must also be set to a non-default value. - /// Reset this Namespace support object for reuse. - - static const XMLString XML_NAMESPACE; - static const XMLString XML_NAMESPACE_PREFIX; - static const XMLString XMLNS_NAMESPACE; - static const XMLString XMLNS_NAMESPACE_PREFIX; - -private: - NamespaceSupport(const NamespaceSupport&); - NamespaceSupport& operator = (const NamespaceSupport&); - - typedef std::map Context; - typedef std::vector ContextVec; - - ContextVec _contexts; - - static const XMLString EMPTY_STRING; -}; - - -} } // namespace Poco::XML - - -#endif // SAX_NamespaceSupport_INCLUDED +// +// NamespaceSupport.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/NamespaceSupport.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Namespace support for SAX2. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_NamespaceSupport_INCLUDED +#define SAX_NamespaceSupport_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include +#include +#include + + +namespace Poco { +namespace XML { + + +class XML_API NamespaceSupport + /// Encapsulate Namespace logic for use by SAX drivers. + /// This class encapsulates the logic of Namespace processing: + /// it tracks the declarations currently in force for each context and + /// automatically processes qualified XML 1.0 names into their Namespace + /// parts; it can also be used in reverse for generating + /// XML 1.0 from Namespaces. + /// Namespace support objects are reusable, but the reset method + /// must be invoked between each session. +{ +public: + typedef std::set PrefixSet; + + NamespaceSupport(); + /// Creates a NamespaceSupport object. + + ~NamespaceSupport(); + /// Destroys a NamespaceSupport object. + + bool declarePrefix(const XMLString& prefix, const XMLString& namespaceURI); + /// Declare a Namespace prefix. All prefixes must be declared before they are + /// referenced. For example, a SAX driver (parser) would scan an element's attributes + /// in two passes: first for namespace declarations, then a second pass using + /// processName() to interpret prefixes against (potentially redefined) prefixes. + /// + /// This method declares a prefix in the current Namespace context; the prefix + /// will remain in force until this context is popped, unless it is shadowed + /// in a descendant context. + /// + /// To declare the default element Namespace, use the empty string as the prefix. + /// + /// Note that you must not declare a prefix after you've pushed and popped another + /// Namespace context, or treated the declarations phase as complete by processing + /// a prefixed name. + /// + /// Returns true if the prefix was legal, false otherwise. + + bool undeclarePrefix(const XMLString& prefix); + /// Remove the given namespace prefix. + + void getDeclaredPrefixes(PrefixSet& prefixes) const; + /// Return an enumeration of all prefixes declared in this context. + /// + /// The empty (default) prefix will be included in this enumeration; note that + /// this behaviour differs from that of getPrefix(java.lang.String) and getPrefixes(). + + const XMLString& getPrefix(const XMLString& namespaceURI) const; + /// Return one of the prefixes mapped to a Namespace URI. + /// + /// If more than one prefix is currently mapped to the same URI, this method + /// will make an arbitrary selection; if you want all of the prefixes, use the + /// getPrefixes() method instead. + + bool isMapped(const XMLString& namespaceURI) const; + /// Returns true if the given namespaceURI has been mapped to a prefix, + /// false otherwise. + + void getPrefixes(PrefixSet& prefixes) const; + /// Return an enumeration of all prefixes whose declarations are active in the + /// current context. This includes declarations from parent contexts that have + /// not been overridden. + /// + /// Note: if there is a default prefix, it will not be returned in this enumeration; + /// check for the default prefix using the getURI with an argument of "". + + void getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const; + /// Return an enumeration of all prefixes for a given URI whose declarations + /// are active in the current context. This includes declarations from parent + /// contexts that have not been overridden. + /// + /// This method returns prefixes mapped to a specific Namespace URI. The xml: + /// prefix will be included. If you want only one prefix that's mapped to the + /// Namespace URI, and you don't care which one you get, use the getPrefix() method + /// instead. + /// + /// Note: the empty (default) prefix is never included in this enumeration; + /// to check for the presence of a default Namespace, use the getURI() method + /// with an argument of "". + + const XMLString& getURI(const XMLString& prefix) const; + /// Look up a prefix and get the currently-mapped Namespace URI. + /// + /// This method looks up the prefix in the current context. Use the empty string + /// ("") for the default Namespace. + + void pushContext(); + /// Start a new Namespace context. The new context will automatically inherit + /// the declarations of its parent context, but it will also keep track of which + /// declarations were made within this context. + /// + /// Event callback code should start a new context once per element. This means + /// being ready to call this in either of two places. For elements that don't + /// include namespace declarations, the ContentHandler::startElement() callback + /// is the right place. For elements with such a declaration, it'd done in the + /// first ContentHandler::startPrefixMapping() callback. A boolean flag can be + /// used to track whether a context has been started yet. When either of those + /// methods is called, it checks the flag to see if a new context needs to be + /// started. If so, it starts the context and sets the flag. After + /// ContentHandler::startElement() does that, it always clears the flag. + /// + /// Normally, SAX drivers would push a new context at the beginning of each + /// XML element. Then they perform a first pass over the attributes to process + /// all namespace declarations, making ContentHandler::startPrefixMapping() callbacks. + /// Then a second pass is made, to determine the namespace-qualified names for + /// all attributes and for the element name. Finally all the information for + /// the ContentHandler::startElement() callback is available, so it can then + /// be made. + /// + /// The Namespace support object always starts with a base context already in + /// force: in this context, only the "xml" prefix is declared. + + void popContext(); + /// Revert to the previous Namespace context. + /// + /// Normally, you should pop the context at the end of each XML element. After + /// popping the context, all Namespace prefix mappings that were previously + /// in force are restored. + /// + /// You must not attempt to declare additional Namespace prefixes after popping + /// a context, unless you push another context first. + + bool processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const; + /// Process a raw XML 1.0 name. + /// This method processes a raw XML 1.0 name in the current context + /// by removing the prefix and looking it up among the + /// prefixes currently declared. The result will be returned in + /// namespaceURI and localName. + /// If the raw name has a prefix that has not been declared, then the return + /// value will be false, otherwise true. + /// + /// Note that attribute names are processed differently than element names: + /// an unprefixed element name will received the + /// default Namespace (if any), while an unprefixed element name will not. + + void reset(); + /// Reset this Namespace support object for reuse. + /// + /// It is necessary to invoke this method before reusing the Namespace support + /// object for a new session. If namespace declaration URIs are to be supported, + /// that flag must also be set to a non-default value. + /// Reset this Namespace support object for reuse. + + static const XMLString XML_NAMESPACE; + static const XMLString XML_NAMESPACE_PREFIX; + static const XMLString XMLNS_NAMESPACE; + static const XMLString XMLNS_NAMESPACE_PREFIX; + +private: + NamespaceSupport(const NamespaceSupport&); + NamespaceSupport& operator = (const NamespaceSupport&); + + typedef std::map Context; + typedef std::vector ContextVec; + + ContextVec _contexts; + + static const XMLString EMPTY_STRING; +}; + + +} } // namespace Poco::XML + + +#endif // SAX_NamespaceSupport_INCLUDED diff --git a/XML/include/Poco/SAX/SAXException.h b/XML/include/Poco/SAX/SAXException.h index a27e353c0..093bf73f8 100644 --- a/XML/include/Poco/SAX/SAXException.h +++ b/XML/include/Poco/SAX/SAXException.h @@ -1,198 +1,198 @@ -// -// SAXException.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/SAXException.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX exception classes. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_SAXException_INCLUDED -#define SAX_SAXException_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLException.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -POCO_DECLARE_EXCEPTION(XML_API, SAXException, XMLException) - /// The base class for all SAX-related exceptions like SAXParseException, - /// SAXNotRecognizedException or SAXNotSupportedException. - /// - /// This class can contain basic error or warning information from either the XML parser - /// or the application: a parser writer or application writer can subclass it to provide - /// additional functionality. SAX handlers may throw this exception or any exception subclassed - /// from it. - /// - /// If the application needs to pass through other types of exceptions, it must wrap those exceptions - /// in a SAXException or an exception derived from a SAXException. - /// - /// If the parser or application needs to include information about a specific location in an XML - /// document, it should use the SAXParseException subclass. - - -POCO_DECLARE_EXCEPTION(XML_API, SAXNotRecognizedException, SAXException) - /// Exception class for an unrecognized identifier. - /// - /// An XMLReader will throw this exception when it finds an unrecognized feature or property - /// identifier; SAX applications and extensions may use this class for other, similar purposes. - - -POCO_DECLARE_EXCEPTION(XML_API, SAXNotSupportedException, SAXException) - /// Exception class for an unsupported operation. - /// - /// An XMLReader will throw this exception when it recognizes a feature or property identifier, - /// but cannot perform the requested operation (setting a state or value). Other SAX2 applications - /// and extensions may use this class for similar purposes. - - -class Locator; - - -class XML_API SAXParseException: public SAXException - /// Encapsulate an XML parse error or warning. - /// - /// This exception may include information for locating the error in the original XML document, - /// as if it came from a Locator object. Note that although the application will receive a - /// SAXParseException as the argument to the handlers in the ErrorHandler interface, the application - /// is not actually required to throw the exception; instead, it can simply read the information in it - /// and take a different action. - /// - /// Since this exception is a subclass of SAXException, it inherits the ability to wrap another exception. -{ -public: - SAXParseException(const std::string& msg, const Locator& loc); - /// Create a new SAXParseException from a message and a Locator. - - SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc); - /// Wrap an existing exception in a SAXParseException. - - SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); - /// Create a new SAXParseException with an embedded exception. - /// - /// This constructor is most useful for parser writers. - /// All parameters except the message are as if they were provided by a Locator. - /// For example, if the system identifier is a URL (including relative filename), - /// the caller must resolve it fully before creating the exception. - - SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc); - /// Create a new SAXParseException. - /// - /// This constructor is most useful for parser writers. - /// All parameters except the message are as if they were provided by a Locator. - /// For example, if the system identifier is a URL (including relative filename), - /// the caller must resolve it fully before creating the exception. - - SAXParseException(const SAXParseException& exc); - /// Creates a new SAXParseException from another one. - - ~SAXParseException() throw(); - /// Destroy the exception. - - SAXParseException& operator = (const SAXParseException& exc); - /// Assignment operator. - - const char* name() const throw(); - /// Returns a static string describing the exception. - - const char* className() const throw(); - /// Returns the name of the exception class. - - Poco::Exception* clone() const; - /// Creates an exact copy of the exception. - - void rethrow() const; - /// (Re)Throws the exception. - - const XMLString& getPublicId() const; - /// Get the public identifier of the entity where the exception occurred. - - const XMLString& getSystemId() const; - /// Get the system identifier of the entity where the exception occurred. - - int getLineNumber() const; - /// The line number of the end of the text where the exception occurred. - /// The first line is line 1. - - int getColumnNumber() const; - /// The column number of the end of the text where the exception occurred. - /// The first column in a line is position 1. - -protected: - static std::string buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); - -private: - SAXParseException(); - - XMLString _publicId; - XMLString _systemId; - int _lineNumber; - int _columnNumber; -}; - - -// -// inlines -// -inline const XMLString& SAXParseException::getPublicId() const -{ - return _publicId; -} - - -inline const XMLString& SAXParseException::getSystemId() const -{ - return _systemId; -} - - -inline int SAXParseException::getLineNumber() const -{ - return _lineNumber; -} - - -inline int SAXParseException::getColumnNumber() const -{ - return _columnNumber; -} - - -} } // namespace Poco::XML - - -#endif // SAX_SAXException_INCLUDED +// +// SAXException.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/SAXException.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX exception classes. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_SAXException_INCLUDED +#define SAX_SAXException_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLException.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +POCO_DECLARE_EXCEPTION(XML_API, SAXException, XMLException) + /// The base class for all SAX-related exceptions like SAXParseException, + /// SAXNotRecognizedException or SAXNotSupportedException. + /// + /// This class can contain basic error or warning information from either the XML parser + /// or the application: a parser writer or application writer can subclass it to provide + /// additional functionality. SAX handlers may throw this exception or any exception subclassed + /// from it. + /// + /// If the application needs to pass through other types of exceptions, it must wrap those exceptions + /// in a SAXException or an exception derived from a SAXException. + /// + /// If the parser or application needs to include information about a specific location in an XML + /// document, it should use the SAXParseException subclass. + + +POCO_DECLARE_EXCEPTION(XML_API, SAXNotRecognizedException, SAXException) + /// Exception class for an unrecognized identifier. + /// + /// An XMLReader will throw this exception when it finds an unrecognized feature or property + /// identifier; SAX applications and extensions may use this class for other, similar purposes. + + +POCO_DECLARE_EXCEPTION(XML_API, SAXNotSupportedException, SAXException) + /// Exception class for an unsupported operation. + /// + /// An XMLReader will throw this exception when it recognizes a feature or property identifier, + /// but cannot perform the requested operation (setting a state or value). Other SAX2 applications + /// and extensions may use this class for similar purposes. + + +class Locator; + + +class XML_API SAXParseException: public SAXException + /// Encapsulate an XML parse error or warning. + /// + /// This exception may include information for locating the error in the original XML document, + /// as if it came from a Locator object. Note that although the application will receive a + /// SAXParseException as the argument to the handlers in the ErrorHandler interface, the application + /// is not actually required to throw the exception; instead, it can simply read the information in it + /// and take a different action. + /// + /// Since this exception is a subclass of SAXException, it inherits the ability to wrap another exception. +{ +public: + SAXParseException(const std::string& msg, const Locator& loc); + /// Create a new SAXParseException from a message and a Locator. + + SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc); + /// Wrap an existing exception in a SAXParseException. + + SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); + /// Create a new SAXParseException with an embedded exception. + /// + /// This constructor is most useful for parser writers. + /// All parameters except the message are as if they were provided by a Locator. + /// For example, if the system identifier is a URL (including relative filename), + /// the caller must resolve it fully before creating the exception. + + SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc); + /// Create a new SAXParseException. + /// + /// This constructor is most useful for parser writers. + /// All parameters except the message are as if they were provided by a Locator. + /// For example, if the system identifier is a URL (including relative filename), + /// the caller must resolve it fully before creating the exception. + + SAXParseException(const SAXParseException& exc); + /// Creates a new SAXParseException from another one. + + ~SAXParseException() throw(); + /// Destroy the exception. + + SAXParseException& operator = (const SAXParseException& exc); + /// Assignment operator. + + const char* name() const throw(); + /// Returns a static string describing the exception. + + const char* className() const throw(); + /// Returns the name of the exception class. + + Poco::Exception* clone() const; + /// Creates an exact copy of the exception. + + void rethrow() const; + /// (Re)Throws the exception. + + const XMLString& getPublicId() const; + /// Get the public identifier of the entity where the exception occurred. + + const XMLString& getSystemId() const; + /// Get the system identifier of the entity where the exception occurred. + + int getLineNumber() const; + /// The line number of the end of the text where the exception occurred. + /// The first line is line 1. + + int getColumnNumber() const; + /// The column number of the end of the text where the exception occurred. + /// The first column in a line is position 1. + +protected: + static std::string buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber); + +private: + SAXParseException(); + + XMLString _publicId; + XMLString _systemId; + int _lineNumber; + int _columnNumber; +}; + + +// +// inlines +// +inline const XMLString& SAXParseException::getPublicId() const +{ + return _publicId; +} + + +inline const XMLString& SAXParseException::getSystemId() const +{ + return _systemId; +} + + +inline int SAXParseException::getLineNumber() const +{ + return _lineNumber; +} + + +inline int SAXParseException::getColumnNumber() const +{ + return _columnNumber; +} + + +} } // namespace Poco::XML + + +#endif // SAX_SAXException_INCLUDED diff --git a/XML/include/Poco/SAX/SAXParser.h b/XML/include/Poco/SAX/SAXParser.h index 6dba4fe95..58f0fe882 100644 --- a/XML/include/Poco/SAX/SAXParser.h +++ b/XML/include/Poco/SAX/SAXParser.h @@ -1,119 +1,119 @@ -// -// SAXParser.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/SAXParser.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Implementation of the XMLReader interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_SAXParser_INCLUDED -#define SAX_SAXParser_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/XMLReader.h" -#include "Poco/XML/ParserEngine.h" - - -namespace Poco { -namespace XML { - - -class XML_API SAXParser: public XMLReader - /// This class provides a SAX2 (Simple API for XML) interface to expat, - /// the XML parser toolkit. - /// The following SAX2 features and properties are supported: - /// * http://xml.org/sax/features/external-general-entities - /// * http://xml.org/sax/features/external-parameter-entities - /// * http://xml.org/sax/features/namespaces - /// * http://xml.org/sax/features/namespace-prefixes - /// * http://xml.org/sax/properties/lexical-handler - /// * http://xml.org/sax/properties/declaration-handler -{ -public: - SAXParser(); - /// Creates an SAXParser. - - SAXParser(const XMLString& encoding); - /// Creates an SAXParser with the given encoding. - - ~SAXParser(); - /// Destroys the SAXParser. - - void setEncoding(const XMLString& encoding); - /// Sets the encoding used by the parser if no - /// encoding is specified in the XML document. - - const XMLString& getEncoding() const; - /// Returns the name of the encoding used by - /// the parser if no encoding is specified in - /// the XML document. - - void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); - /// Adds an encoding to the parser. Does not take ownership of the pointer! - - /// XMLReader - void setEntityResolver(EntityResolver* pResolver); - EntityResolver* getEntityResolver() const; - void setDTDHandler(DTDHandler* pDTDHandler); - DTDHandler* getDTDHandler() const; - void setContentHandler(ContentHandler* pContentHandler); - ContentHandler* getContentHandler() const; - void setErrorHandler(ErrorHandler* pErrorHandler); - ErrorHandler* getErrorHandler() const; - void setFeature(const XMLString& featureId, bool state); - bool getFeature(const XMLString& featureId) const; - void setProperty(const XMLString& propertyId, const XMLString& value); - void setProperty(const XMLString& propertyId, void* value); - void* getProperty(const XMLString& propertyId) const; - void parse(InputSource* pSource); - void parse(const XMLString& systemId); - void parseMemoryNP(const char* xml, std::size_t size); - - /// Extensions - void parseString(const std::string& xml); - -protected: - void setupParse(); - -private: - ParserEngine _engine; - bool _namespaces; - bool _namespacePrefixes; -}; - - -} } // namespace Poco::XML - - -#endif // SAX_SAXParser_INCLUDED +// +// SAXParser.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/SAXParser.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Implementation of the XMLReader interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_SAXParser_INCLUDED +#define SAX_SAXParser_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/XMLReader.h" +#include "Poco/XML/ParserEngine.h" + + +namespace Poco { +namespace XML { + + +class XML_API SAXParser: public XMLReader + /// This class provides a SAX2 (Simple API for XML) interface to expat, + /// the XML parser toolkit. + /// The following SAX2 features and properties are supported: + /// * http://xml.org/sax/features/external-general-entities + /// * http://xml.org/sax/features/external-parameter-entities + /// * http://xml.org/sax/features/namespaces + /// * http://xml.org/sax/features/namespace-prefixes + /// * http://xml.org/sax/properties/lexical-handler + /// * http://xml.org/sax/properties/declaration-handler +{ +public: + SAXParser(); + /// Creates an SAXParser. + + SAXParser(const XMLString& encoding); + /// Creates an SAXParser with the given encoding. + + ~SAXParser(); + /// Destroys the SAXParser. + + void setEncoding(const XMLString& encoding); + /// Sets the encoding used by the parser if no + /// encoding is specified in the XML document. + + const XMLString& getEncoding() const; + /// Returns the name of the encoding used by + /// the parser if no encoding is specified in + /// the XML document. + + void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); + /// Adds an encoding to the parser. Does not take ownership of the pointer! + + /// XMLReader + void setEntityResolver(EntityResolver* pResolver); + EntityResolver* getEntityResolver() const; + void setDTDHandler(DTDHandler* pDTDHandler); + DTDHandler* getDTDHandler() const; + void setContentHandler(ContentHandler* pContentHandler); + ContentHandler* getContentHandler() const; + void setErrorHandler(ErrorHandler* pErrorHandler); + ErrorHandler* getErrorHandler() const; + void setFeature(const XMLString& featureId, bool state); + bool getFeature(const XMLString& featureId) const; + void setProperty(const XMLString& propertyId, const XMLString& value); + void setProperty(const XMLString& propertyId, void* value); + void* getProperty(const XMLString& propertyId) const; + void parse(InputSource* pSource); + void parse(const XMLString& systemId); + void parseMemoryNP(const char* xml, std::size_t size); + + /// Extensions + void parseString(const std::string& xml); + +protected: + void setupParse(); + +private: + ParserEngine _engine; + bool _namespaces; + bool _namespacePrefixes; +}; + + +} } // namespace Poco::XML + + +#endif // SAX_SAXParser_INCLUDED diff --git a/XML/include/Poco/SAX/WhitespaceFilter.h b/XML/include/Poco/SAX/WhitespaceFilter.h index dc9b13f4a..3b58bf88b 100644 --- a/XML/include/Poco/SAX/WhitespaceFilter.h +++ b/XML/include/Poco/SAX/WhitespaceFilter.h @@ -1,103 +1,103 @@ -// -// WhitespaceFilter.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/WhitespaceFilter.h#1 $ -// -// Library: XML -// Package: SAX -// Module: WhitespaceFilter -// -// Definition of the WhitespaceFilter class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_WhitespaceFilter_INCLUDED -#define SAX_WhitespaceFilter_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/XMLFilterImpl.h" -#include "Poco/SAX/LexicalHandler.h" - - -namespace Poco { -namespace XML { - - -class XML_API WhitespaceFilter: public XMLFilterImpl, public LexicalHandler - /// This implementation of the SAX2 XMLFilter interface - /// filters all whitespace-only character data element - /// content. -{ -public: - WhitespaceFilter(); - /// Creates the WhitespaceFilter, with no parent. - - WhitespaceFilter(XMLReader* pReader); - /// Creates the WhitespaceFilter with the specified parent. - - ~WhitespaceFilter(); - /// Destroys the WhitespaceFilter. - - // XMLReader - void setProperty(const XMLString& propertyId, const XMLString& value); - void setProperty(const XMLString& propertyId, void* value); - void* getProperty(const XMLString& propertyId) const; - - // ContentHandler - void startDocument(); - void endDocument(); - void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList); - void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); - void characters(const XMLChar ch[], int start, int length); - void ignorableWhitespace(const XMLChar ch[], int start, int length); - void processingInstruction(const XMLString& target, const XMLString& data); - - // LexicalHandler - void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); - void endDTD(); - void startEntity(const XMLString& name); - void endEntity(const XMLString& name); - void startCDATA(); - void endCDATA(); - void comment(const XMLChar ch[], int start, int length); - -protected: - void setupParse(); - -private: - LexicalHandler* _pLexicalHandler; - XMLString _data; - bool _filter; -}; - - -} } // namespace Poco::XML - - -#endif // SAX_WhitespaceFilter_INCLUDED +// +// WhitespaceFilter.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/WhitespaceFilter.h#1 $ +// +// Library: XML +// Package: SAX +// Module: WhitespaceFilter +// +// Definition of the WhitespaceFilter class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_WhitespaceFilter_INCLUDED +#define SAX_WhitespaceFilter_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/XMLFilterImpl.h" +#include "Poco/SAX/LexicalHandler.h" + + +namespace Poco { +namespace XML { + + +class XML_API WhitespaceFilter: public XMLFilterImpl, public LexicalHandler + /// This implementation of the SAX2 XMLFilter interface + /// filters all whitespace-only character data element + /// content. +{ +public: + WhitespaceFilter(); + /// Creates the WhitespaceFilter, with no parent. + + WhitespaceFilter(XMLReader* pReader); + /// Creates the WhitespaceFilter with the specified parent. + + ~WhitespaceFilter(); + /// Destroys the WhitespaceFilter. + + // XMLReader + void setProperty(const XMLString& propertyId, const XMLString& value); + void setProperty(const XMLString& propertyId, void* value); + void* getProperty(const XMLString& propertyId) const; + + // ContentHandler + void startDocument(); + void endDocument(); + void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList); + void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); + void characters(const XMLChar ch[], int start, int length); + void ignorableWhitespace(const XMLChar ch[], int start, int length); + void processingInstruction(const XMLString& target, const XMLString& data); + + // LexicalHandler + void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); + void endDTD(); + void startEntity(const XMLString& name); + void endEntity(const XMLString& name); + void startCDATA(); + void endCDATA(); + void comment(const XMLChar ch[], int start, int length); + +protected: + void setupParse(); + +private: + LexicalHandler* _pLexicalHandler; + XMLString _data; + bool _filter; +}; + + +} } // namespace Poco::XML + + +#endif // SAX_WhitespaceFilter_INCLUDED diff --git a/XML/include/Poco/SAX/XMLFilter.h b/XML/include/Poco/SAX/XMLFilter.h index 893324d8c..9a37e88f1 100644 --- a/XML/include/Poco/SAX/XMLFilter.h +++ b/XML/include/Poco/SAX/XMLFilter.h @@ -1,83 +1,83 @@ -// -// XMLFilter.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/XMLFilter.h#1 $ -// -// Library: XML -// Package: SAX -// Module: SAXFilters -// -// SAX2 XMLFilter Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_XMLFilter_INCLUDED -#define SAX_XMLFilter_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/XMLReader.h" - - -namespace Poco { -namespace XML { - - -class XML_API XMLFilter: public XMLReader - /// Interface for an XML filter. - /// - /// An XML filter is like an XML reader, except that it obtains its events from another XML reader - /// rather than a primary source like an XML document or database. Filters can modify a stream of - /// events as they pass on to the final application. - /// - /// The XMLFilterImpl helper class provides a convenient base for creating SAX2 filters, by passing on - /// all EntityResolver, DTDHandler, ContentHandler and ErrorHandler events automatically. -{ -public: - virtual XMLReader* getParent() const = 0; - /// Set the parent reader. - /// - /// This method allows the application to link the filter to a parent reader (which may be another - /// filter). The argument may not be null. - - virtual void setParent(XMLReader* pParent) = 0; - /// Get the parent reader. - /// - /// This method allows the application to query the parent reader (which may be another filter). - /// It is generally a bad idea to perform any operations on the parent reader directly: they should - /// all pass through this filter. - -protected: - virtual ~XMLFilter(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_XMLFilter_INCLUDED +// +// XMLFilter.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/XMLFilter.h#1 $ +// +// Library: XML +// Package: SAX +// Module: SAXFilters +// +// SAX2 XMLFilter Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_XMLFilter_INCLUDED +#define SAX_XMLFilter_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/XMLReader.h" + + +namespace Poco { +namespace XML { + + +class XML_API XMLFilter: public XMLReader + /// Interface for an XML filter. + /// + /// An XML filter is like an XML reader, except that it obtains its events from another XML reader + /// rather than a primary source like an XML document or database. Filters can modify a stream of + /// events as they pass on to the final application. + /// + /// The XMLFilterImpl helper class provides a convenient base for creating SAX2 filters, by passing on + /// all EntityResolver, DTDHandler, ContentHandler and ErrorHandler events automatically. +{ +public: + virtual XMLReader* getParent() const = 0; + /// Set the parent reader. + /// + /// This method allows the application to link the filter to a parent reader (which may be another + /// filter). The argument may not be null. + + virtual void setParent(XMLReader* pParent) = 0; + /// Get the parent reader. + /// + /// This method allows the application to query the parent reader (which may be another filter). + /// It is generally a bad idea to perform any operations on the parent reader directly: they should + /// all pass through this filter. + +protected: + virtual ~XMLFilter(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_XMLFilter_INCLUDED diff --git a/XML/include/Poco/SAX/XMLFilterImpl.h b/XML/include/Poco/SAX/XMLFilterImpl.h index 6be663ac9..d7886609d 100644 --- a/XML/include/Poco/SAX/XMLFilterImpl.h +++ b/XML/include/Poco/SAX/XMLFilterImpl.h @@ -1,154 +1,154 @@ -// -// XMLFilterImpl.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/XMLFilterImpl.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAXFilters -// -// SAX2 XMLFilterImpl class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_XMLFilterImpl_INCLUDED -#define SAX_XMLFilterImpl_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/XMLFilter.h" -#include "Poco/SAX/EntityResolver.h" -#include "Poco/SAX/DTDHandler.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/ErrorHandler.h" - - -namespace Poco { -namespace XML { - - -class XML_API XMLFilterImpl: public XMLFilter, public EntityResolver, public DTDHandler, public ContentHandler, public ErrorHandler - /// Base class for deriving an XML filter. - /// - /// This class is designed to sit between an XMLReader and the client application's event - /// handlers. By default, it does nothing but pass requests up to the reader and events on to - /// the handlers unmodified, but subclasses can override specific methods to modify the event - /// stream or the configuration requests as they pass through. -{ -public: - XMLFilterImpl(); - /// Construct an empty XML filter, with no parent. - /// - /// This filter will have no parent: you must assign a parent before you start a parse or do any - /// configuration with setFeature or setProperty, unless you use this as a pure event consumer rather - /// than as an XMLReader. - - XMLFilterImpl(XMLReader* pParent); - /// Construct an XML filter with the specified parent. - - ~XMLFilterImpl(); - /// Destroys the XMLFilterImpl. - - // XMLFilter - XMLReader* getParent() const; - void setParent(XMLReader* pParent); - - // XMLReader - void setEntityResolver(EntityResolver* pResolver); - EntityResolver* getEntityResolver() const; - void setDTDHandler(DTDHandler* pDTDHandler); - DTDHandler* getDTDHandler() const; - void setContentHandler(ContentHandler* pContentHandler); - ContentHandler* getContentHandler() const; - void setErrorHandler(ErrorHandler* pErrorHandler); - ErrorHandler* getErrorHandler() const; - void setFeature(const XMLString& featureId, bool state); - bool getFeature(const XMLString& featureId) const; - void setProperty(const XMLString& propertyId, const XMLString& value); - void setProperty(const XMLString& propertyId, void* value); - void* getProperty(const XMLString& propertyId) const; - void parse(InputSource* pSource); - void parse(const XMLString& systemId); - void parseMemoryNP(const char* xml, std::size_t size); - - // EntityResolver - InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); - void releaseInputSource(InputSource* pSource); - - // DTDHandler - void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); - void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); - - // ContentHandler - void setDocumentLocator(const Locator* loc); - void startDocument(); - void endDocument(); - void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList); - void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); - void characters(const XMLChar ch[], int start, int length); - void ignorableWhitespace(const XMLChar ch[], int start, int length); - void processingInstruction(const XMLString& target, const XMLString& data); - void startPrefixMapping(const XMLString& prefix, const XMLString& uri); - void endPrefixMapping(const XMLString& prefix); - void skippedEntity(const XMLString& prefix); - void warning(const SAXException& e); - void error(const SAXException& e); - void fatalError(const SAXException& e); - -protected: - XMLReader* parent() const; - /// Return a pointer to the parent reader. - /// Subclasses can use this method instead of - /// getParent() for better performance - this method - /// is non-virtual and implemented as inline. - - virtual void setupParse(); - /// Setup the event handlers in the parent reader. - -private: - XMLReader* _pParent; - EntityResolver* _pEntityResolver; - DTDHandler* _pDTDHandler; - ContentHandler* _pContentHandler; - ErrorHandler* _pErrorHandler; -}; - - -// -// inlines -// -inline XMLReader* XMLFilterImpl::parent() const -{ - return _pParent; -} - - -} } // namespace Poco::XML - - -#endif // SAX_XMLFilterImpl_INCLUDED +// +// XMLFilterImpl.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/XMLFilterImpl.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAXFilters +// +// SAX2 XMLFilterImpl class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_XMLFilterImpl_INCLUDED +#define SAX_XMLFilterImpl_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/XMLFilter.h" +#include "Poco/SAX/EntityResolver.h" +#include "Poco/SAX/DTDHandler.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/ErrorHandler.h" + + +namespace Poco { +namespace XML { + + +class XML_API XMLFilterImpl: public XMLFilter, public EntityResolver, public DTDHandler, public ContentHandler, public ErrorHandler + /// Base class for deriving an XML filter. + /// + /// This class is designed to sit between an XMLReader and the client application's event + /// handlers. By default, it does nothing but pass requests up to the reader and events on to + /// the handlers unmodified, but subclasses can override specific methods to modify the event + /// stream or the configuration requests as they pass through. +{ +public: + XMLFilterImpl(); + /// Construct an empty XML filter, with no parent. + /// + /// This filter will have no parent: you must assign a parent before you start a parse or do any + /// configuration with setFeature or setProperty, unless you use this as a pure event consumer rather + /// than as an XMLReader. + + XMLFilterImpl(XMLReader* pParent); + /// Construct an XML filter with the specified parent. + + ~XMLFilterImpl(); + /// Destroys the XMLFilterImpl. + + // XMLFilter + XMLReader* getParent() const; + void setParent(XMLReader* pParent); + + // XMLReader + void setEntityResolver(EntityResolver* pResolver); + EntityResolver* getEntityResolver() const; + void setDTDHandler(DTDHandler* pDTDHandler); + DTDHandler* getDTDHandler() const; + void setContentHandler(ContentHandler* pContentHandler); + ContentHandler* getContentHandler() const; + void setErrorHandler(ErrorHandler* pErrorHandler); + ErrorHandler* getErrorHandler() const; + void setFeature(const XMLString& featureId, bool state); + bool getFeature(const XMLString& featureId) const; + void setProperty(const XMLString& propertyId, const XMLString& value); + void setProperty(const XMLString& propertyId, void* value); + void* getProperty(const XMLString& propertyId) const; + void parse(InputSource* pSource); + void parse(const XMLString& systemId); + void parseMemoryNP(const char* xml, std::size_t size); + + // EntityResolver + InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId); + void releaseInputSource(InputSource* pSource); + + // DTDHandler + void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); + void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); + + // ContentHandler + void setDocumentLocator(const Locator* loc); + void startDocument(); + void endDocument(); + void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList); + void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname); + void characters(const XMLChar ch[], int start, int length); + void ignorableWhitespace(const XMLChar ch[], int start, int length); + void processingInstruction(const XMLString& target, const XMLString& data); + void startPrefixMapping(const XMLString& prefix, const XMLString& uri); + void endPrefixMapping(const XMLString& prefix); + void skippedEntity(const XMLString& prefix); + void warning(const SAXException& e); + void error(const SAXException& e); + void fatalError(const SAXException& e); + +protected: + XMLReader* parent() const; + /// Return a pointer to the parent reader. + /// Subclasses can use this method instead of + /// getParent() for better performance - this method + /// is non-virtual and implemented as inline. + + virtual void setupParse(); + /// Setup the event handlers in the parent reader. + +private: + XMLReader* _pParent; + EntityResolver* _pEntityResolver; + DTDHandler* _pDTDHandler; + ContentHandler* _pContentHandler; + ErrorHandler* _pErrorHandler; +}; + + +// +// inlines +// +inline XMLReader* XMLFilterImpl::parent() const +{ + return _pParent; +} + + +} } // namespace Poco::XML + + +#endif // SAX_XMLFilterImpl_INCLUDED diff --git a/XML/include/Poco/SAX/XMLReader.h b/XML/include/Poco/SAX/XMLReader.h index 7792b968f..e598f6cda 100644 --- a/XML/include/Poco/SAX/XMLReader.h +++ b/XML/include/Poco/SAX/XMLReader.h @@ -1,227 +1,227 @@ -// -// XMLReader.h -// -// $Id: //poco/1.3/XML/include/Poco/SAX/XMLReader.h#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// SAX2 XMLReader Interface. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAX_XMLReader_INCLUDED -#define SAX_XMLReader_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class EntityResolver; -class DTDHandler; -class ContentHandler; -class ErrorHandler; -class InputSource; -class LexicalHandler; -class NamespaceHandler; - - -class XML_API XMLReader - /// Interface for reading an XML document using callbacks. - /// XMLReader is the interface that an XML parser's SAX2 driver must - /// implement. This interface allows an application to set and - /// query features and properties in the parser, to register event handlers - /// for document processing, and to initiate a document parse. - /// All SAX interfaces are assumed to be synchronous: the parse methods must not - /// return until parsing is complete, and readers - /// must wait for an event-handler callback to return before reporting the next event. -{ -public: - virtual void setEntityResolver(EntityResolver* pResolver) = 0; - /// Allow an application to register an entity resolver. - /// - /// If the application does not register an entity resolver, the - /// XMLReader will perform its own default resolution. - /// - /// Applications may register a new or different resolver in the middle of a - /// parse, and the SAX parser must begin using the new resolver immediately. - - virtual EntityResolver* getEntityResolver() const = 0; - /// Return the current entity resolver. - - virtual void setDTDHandler(DTDHandler* pDTDHandler) = 0; - /// Allow an application to register a DTD event handler. - /// - /// If the application does not register a DTD handler, all DTD events reported by - /// the SAX parser will be silently ignored. - /// - /// Applications may register a new or different handler in the middle of a parse, - /// and the SAX parser must begin using the new handler immediately. - - virtual DTDHandler* getDTDHandler() const = 0; - /// Return the current DTD handler. - - virtual void setContentHandler(ContentHandler* pContentHandler) = 0; - /// Allow an application to register a content event handler. - /// - /// If the application does not register a content handler, all content events - /// reported by the SAX parser will be silently ignored. - /// - /// Applications may register a new or different handler in the middle of a parse, - /// and the SAX parser must begin using the new handler immediately. - - virtual ContentHandler* getContentHandler() const = 0; - /// Return the current content handler. - - virtual void setErrorHandler(ErrorHandler* pErrorHandler) = 0; - /// Allow an application to register an error event handler. - /// - /// If the application does not register an error handler, all error events reported by - /// the SAX parser will be silently ignored; however, normal processing may not continue. - /// It is highly recommended that all SAX applications implement an error handler to avoid - /// unexpected bugs. - /// - /// Applications may register a new or different handler in the middle of a parse, and the - /// SAX parser must begin using the new handler immediately. - - virtual ErrorHandler* getErrorHandler() const = 0; - /// Return the current error handler. - - virtual void setFeature(const XMLString& featureId, bool state) = 0; - /// Set the state of a feature. - /// - /// The feature name is any fully-qualified URI. It is possible for an XMLReader to - /// expose a feature value but to be unable to change the current value. Some feature - /// values may be immutable or mutable only in specific contexts, such as before, during, - /// or after a parse. - /// - /// All XMLReaders are required to support setting http://xml.org/sax/features/namespaces - /// to true and http://xml.org/sax/features/namespace-prefixes to false. - - virtual bool getFeature(const XMLString& featureId) const = 0; - /// Look up the value of a feature. - /// - /// The feature name is any fully-qualified URI. It is possible for an XMLReader - /// to recognize a feature name but temporarily be unable to return its value. - /// Some feature values may be available only in specific contexts, such as before, - /// during, or after a parse. Also, some feature values may not be programmatically - /// accessible. (In the case of an adapter for SAX1 Parser, there is no - /// implementation-independent way to expose whether the underlying parser is performing - /// validation, expanding external entities, and so forth.) - /// - /// All XMLReaders are required to recognize the - /// http://xml.org/sax/features/namespaces and the - /// http://xml.org/sax/features/namespace-prefixes feature names. - /// Implementors are free (and encouraged) to invent their own features, - /// using names built on their own URIs. - - virtual void setProperty(const XMLString& propertyId, const XMLString& value) = 0; - /// Set the value of a property. - /// - /// The property name is any fully-qualified URI. It is possible for an XMLReader - /// to recognize a property name but to be unable to change the current value. - /// Some property values may be immutable or mutable only in specific contexts, - /// such as before, during, or after a parse. - /// - /// XMLReaders are not required to recognize setting any specific property names, though a - /// core set is defined by SAX2. - /// - /// This method is also the standard mechanism for setting extended handlers. - - virtual void setProperty(const XMLString& propertyId, void* value) = 0; - /// Set the value of a property. - /// See also setProperty(const XMLString&, const XMLString&). - - virtual void* getProperty(const XMLString& propertyId) const = 0; - /// Look up the value of a property. - /// String values are returned as XMLChar* - /// The property name is any fully-qualified URI. It is possible for an XMLReader to - /// recognize a property name but temporarily be unable to return its value. Some property - /// values may be available only in specific contexts, such as before, during, or after a parse. - /// - /// XMLReaders are not required to recognize any specific property names, though an initial - /// core set is documented for SAX2. - /// - /// Implementors are free (and encouraged) to invent their own properties, using names - /// built on their own URIs. - - virtual void parse(InputSource* pSource) = 0; - /// Parse an XML document. - /// - /// The application can use this method to instruct the XML reader to begin parsing an - /// XML document from any valid input source (a character stream, a byte stream, or a URI). - /// - /// Applications may not invoke this method while a parse is in progress (they should create - /// a new XMLReader instead for each nested XML document). Once a parse is complete, an - /// application may reuse the same XMLReader object, possibly with a different input source. - /// Configuration of the XMLReader object (such as handler bindings and values established for - /// feature flags and properties) is unchanged by completion of a parse, unless the definition of that - /// aspect of the configuration explicitly specifies other behavior. (For example, feature flags or - /// properties exposing characteristics of the document being parsed.) - /// - /// During the parse, the XMLReader will provide information about the XML document through the registered - /// event handlers. - /// - /// This method is synchronous: it will not return until parsing has ended. If a client application - /// wants to terminate parsing early, it should throw an exception. - - virtual void parse(const XMLString& systemId) = 0; - /// Parse an XML document from a system identifier. - /// See also parse(InputSource*). - - virtual void parseMemoryNP(const char* xml, std::size_t size) = 0; - /// Parse an XML document from memory. - /// See also parse(InputSource*). - - // SAX Features - static const XMLString FEATURE_VALIDATION; - static const XMLString FEATURE_NAMESPACES; - static const XMLString FEATURE_NAMESPACE_PREFIXES; - static const XMLString FEATURE_EXTERNAL_GENERAL_ENTITIES; - static const XMLString FEATURE_EXTERNAL_PARAMETER_ENTITIES; - static const XMLString FEATURE_STRING_INTERNING; - - // SAX Properties - static const XMLString PROPERTY_DECLARATION_HANDLER; - static const XMLString PROPERTY_LEXICAL_HANDLER; - -protected: - virtual ~XMLReader(); -}; - - -} } // namespace Poco::XML - - -#endif // SAX_XMLReader_INCLUDED +// +// XMLReader.h +// +// $Id: //poco/1.3/XML/include/Poco/SAX/XMLReader.h#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// SAX2 XMLReader Interface. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAX_XMLReader_INCLUDED +#define SAX_XMLReader_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class EntityResolver; +class DTDHandler; +class ContentHandler; +class ErrorHandler; +class InputSource; +class LexicalHandler; +class NamespaceHandler; + + +class XML_API XMLReader + /// Interface for reading an XML document using callbacks. + /// XMLReader is the interface that an XML parser's SAX2 driver must + /// implement. This interface allows an application to set and + /// query features and properties in the parser, to register event handlers + /// for document processing, and to initiate a document parse. + /// All SAX interfaces are assumed to be synchronous: the parse methods must not + /// return until parsing is complete, and readers + /// must wait for an event-handler callback to return before reporting the next event. +{ +public: + virtual void setEntityResolver(EntityResolver* pResolver) = 0; + /// Allow an application to register an entity resolver. + /// + /// If the application does not register an entity resolver, the + /// XMLReader will perform its own default resolution. + /// + /// Applications may register a new or different resolver in the middle of a + /// parse, and the SAX parser must begin using the new resolver immediately. + + virtual EntityResolver* getEntityResolver() const = 0; + /// Return the current entity resolver. + + virtual void setDTDHandler(DTDHandler* pDTDHandler) = 0; + /// Allow an application to register a DTD event handler. + /// + /// If the application does not register a DTD handler, all DTD events reported by + /// the SAX parser will be silently ignored. + /// + /// Applications may register a new or different handler in the middle of a parse, + /// and the SAX parser must begin using the new handler immediately. + + virtual DTDHandler* getDTDHandler() const = 0; + /// Return the current DTD handler. + + virtual void setContentHandler(ContentHandler* pContentHandler) = 0; + /// Allow an application to register a content event handler. + /// + /// If the application does not register a content handler, all content events + /// reported by the SAX parser will be silently ignored. + /// + /// Applications may register a new or different handler in the middle of a parse, + /// and the SAX parser must begin using the new handler immediately. + + virtual ContentHandler* getContentHandler() const = 0; + /// Return the current content handler. + + virtual void setErrorHandler(ErrorHandler* pErrorHandler) = 0; + /// Allow an application to register an error event handler. + /// + /// If the application does not register an error handler, all error events reported by + /// the SAX parser will be silently ignored; however, normal processing may not continue. + /// It is highly recommended that all SAX applications implement an error handler to avoid + /// unexpected bugs. + /// + /// Applications may register a new or different handler in the middle of a parse, and the + /// SAX parser must begin using the new handler immediately. + + virtual ErrorHandler* getErrorHandler() const = 0; + /// Return the current error handler. + + virtual void setFeature(const XMLString& featureId, bool state) = 0; + /// Set the state of a feature. + /// + /// The feature name is any fully-qualified URI. It is possible for an XMLReader to + /// expose a feature value but to be unable to change the current value. Some feature + /// values may be immutable or mutable only in specific contexts, such as before, during, + /// or after a parse. + /// + /// All XMLReaders are required to support setting http://xml.org/sax/features/namespaces + /// to true and http://xml.org/sax/features/namespace-prefixes to false. + + virtual bool getFeature(const XMLString& featureId) const = 0; + /// Look up the value of a feature. + /// + /// The feature name is any fully-qualified URI. It is possible for an XMLReader + /// to recognize a feature name but temporarily be unable to return its value. + /// Some feature values may be available only in specific contexts, such as before, + /// during, or after a parse. Also, some feature values may not be programmatically + /// accessible. (In the case of an adapter for SAX1 Parser, there is no + /// implementation-independent way to expose whether the underlying parser is performing + /// validation, expanding external entities, and so forth.) + /// + /// All XMLReaders are required to recognize the + /// http://xml.org/sax/features/namespaces and the + /// http://xml.org/sax/features/namespace-prefixes feature names. + /// Implementors are free (and encouraged) to invent their own features, + /// using names built on their own URIs. + + virtual void setProperty(const XMLString& propertyId, const XMLString& value) = 0; + /// Set the value of a property. + /// + /// The property name is any fully-qualified URI. It is possible for an XMLReader + /// to recognize a property name but to be unable to change the current value. + /// Some property values may be immutable or mutable only in specific contexts, + /// such as before, during, or after a parse. + /// + /// XMLReaders are not required to recognize setting any specific property names, though a + /// core set is defined by SAX2. + /// + /// This method is also the standard mechanism for setting extended handlers. + + virtual void setProperty(const XMLString& propertyId, void* value) = 0; + /// Set the value of a property. + /// See also setProperty(const XMLString&, const XMLString&). + + virtual void* getProperty(const XMLString& propertyId) const = 0; + /// Look up the value of a property. + /// String values are returned as XMLChar* + /// The property name is any fully-qualified URI. It is possible for an XMLReader to + /// recognize a property name but temporarily be unable to return its value. Some property + /// values may be available only in specific contexts, such as before, during, or after a parse. + /// + /// XMLReaders are not required to recognize any specific property names, though an initial + /// core set is documented for SAX2. + /// + /// Implementors are free (and encouraged) to invent their own properties, using names + /// built on their own URIs. + + virtual void parse(InputSource* pSource) = 0; + /// Parse an XML document. + /// + /// The application can use this method to instruct the XML reader to begin parsing an + /// XML document from any valid input source (a character stream, a byte stream, or a URI). + /// + /// Applications may not invoke this method while a parse is in progress (they should create + /// a new XMLReader instead for each nested XML document). Once a parse is complete, an + /// application may reuse the same XMLReader object, possibly with a different input source. + /// Configuration of the XMLReader object (such as handler bindings and values established for + /// feature flags and properties) is unchanged by completion of a parse, unless the definition of that + /// aspect of the configuration explicitly specifies other behavior. (For example, feature flags or + /// properties exposing characteristics of the document being parsed.) + /// + /// During the parse, the XMLReader will provide information about the XML document through the registered + /// event handlers. + /// + /// This method is synchronous: it will not return until parsing has ended. If a client application + /// wants to terminate parsing early, it should throw an exception. + + virtual void parse(const XMLString& systemId) = 0; + /// Parse an XML document from a system identifier. + /// See also parse(InputSource*). + + virtual void parseMemoryNP(const char* xml, std::size_t size) = 0; + /// Parse an XML document from memory. + /// See also parse(InputSource*). + + // SAX Features + static const XMLString FEATURE_VALIDATION; + static const XMLString FEATURE_NAMESPACES; + static const XMLString FEATURE_NAMESPACE_PREFIXES; + static const XMLString FEATURE_EXTERNAL_GENERAL_ENTITIES; + static const XMLString FEATURE_EXTERNAL_PARAMETER_ENTITIES; + static const XMLString FEATURE_STRING_INTERNING; + + // SAX Properties + static const XMLString PROPERTY_DECLARATION_HANDLER; + static const XMLString PROPERTY_LEXICAL_HANDLER; + +protected: + virtual ~XMLReader(); +}; + + +} } // namespace Poco::XML + + +#endif // SAX_XMLReader_INCLUDED diff --git a/XML/include/Poco/XML/Name.h b/XML/include/Poco/XML/Name.h index 6aa431f38..42ba994d4 100644 --- a/XML/include/Poco/XML/Name.h +++ b/XML/include/Poco/XML/Name.h @@ -1,160 +1,160 @@ -// -// Name.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/Name.h#1 $ -// -// Library: XML -// Package: XML -// Module: Name -// -// Definition of the Name class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_Name_INCLUDED -#define XML_Name_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" - - -namespace Poco { -namespace XML { - - -class XML_API Name - /// An XML element or attribute name, consisting of a - /// qualified name, a namespace URI and a local name. -{ -public: - Name(); - /// Creates an empty Name. - - Name(const XMLString& qname); - /// Creates a Name from a qualified name only. - - Name(const XMLString& qname, const XMLString& namespaceURI); - /// Creates a Name from a qualified name and a namespace URI. - /// The local name is extracted from the qualified name. - - Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); - /// Creates a Name from a qualified name, a namespace URI and a local name. - - Name(const Name& name); - /// Copy constructor. - - ~Name(); - /// Destroys the name. - - Name& operator = (const Name& name); - /// Assignment operator. - - void swap(Name& name); - /// Swaps the name with another one. - - void assign(const XMLString& qname); - /// Assigns a new value to the name. - - void assign(const XMLString& qname, const XMLString& namespaceURI); - /// Assigns new values to the name. - /// The local name is extracted from the qualified name. - - void assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); - /// Assigns new values to the name. - - bool equals(const Name& name) const; - /// Returns true if both names are equal. - - bool equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns true if all the name's components are equal to the given ones. - - bool equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; - /// Returns true if either the qnames are identical or the namespaceURIs and the localNames are identical. - - const XMLString& qname() const; - /// Returns the qualified name. - - const XMLString& namespaceURI() const; - /// Returns the namespace URI. - - const XMLString& localName() const; - /// Returns the local name. - - XMLString prefix() const; - /// Returns the namespace prefix. - - static void split(const XMLString& qname, XMLString& prefix, XMLString& localName); - /// Splits the given qualified name into its prefix and localName parts. - - static XMLString localName(const XMLString& qname); - /// Returns the local name part of the given qualified name. - - static XMLString prefix(const XMLString& qname); - /// Returns the prefix part of the given qualified name. - - static const XMLString EMPTY_NAME; - -private: - XMLString _qname; - XMLString _namespaceURI; - XMLString _localName; -}; - - -// -// inlines -// -inline const XMLString& Name::qname() const -{ - return _qname; -} - - -inline const XMLString& Name::namespaceURI() const -{ - return _namespaceURI; -} - - -inline const XMLString& Name::localName() const -{ - return _localName; -} - - -inline void swap(Name& n1, Name& n2) -{ - n1.swap(n2); -} - - -} } // namespace Poco::XML - - -#endif // XML_Name_INCLUDED +// +// Name.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/Name.h#1 $ +// +// Library: XML +// Package: XML +// Module: Name +// +// Definition of the Name class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_Name_INCLUDED +#define XML_Name_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" + + +namespace Poco { +namespace XML { + + +class XML_API Name + /// An XML element or attribute name, consisting of a + /// qualified name, a namespace URI and a local name. +{ +public: + Name(); + /// Creates an empty Name. + + Name(const XMLString& qname); + /// Creates a Name from a qualified name only. + + Name(const XMLString& qname, const XMLString& namespaceURI); + /// Creates a Name from a qualified name and a namespace URI. + /// The local name is extracted from the qualified name. + + Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); + /// Creates a Name from a qualified name, a namespace URI and a local name. + + Name(const Name& name); + /// Copy constructor. + + ~Name(); + /// Destroys the name. + + Name& operator = (const Name& name); + /// Assignment operator. + + void swap(Name& name); + /// Swaps the name with another one. + + void assign(const XMLString& qname); + /// Assigns a new value to the name. + + void assign(const XMLString& qname, const XMLString& namespaceURI); + /// Assigns new values to the name. + /// The local name is extracted from the qualified name. + + void assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); + /// Assigns new values to the name. + + bool equals(const Name& name) const; + /// Returns true if both names are equal. + + bool equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns true if all the name's components are equal to the given ones. + + bool equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; + /// Returns true if either the qnames are identical or the namespaceURIs and the localNames are identical. + + const XMLString& qname() const; + /// Returns the qualified name. + + const XMLString& namespaceURI() const; + /// Returns the namespace URI. + + const XMLString& localName() const; + /// Returns the local name. + + XMLString prefix() const; + /// Returns the namespace prefix. + + static void split(const XMLString& qname, XMLString& prefix, XMLString& localName); + /// Splits the given qualified name into its prefix and localName parts. + + static XMLString localName(const XMLString& qname); + /// Returns the local name part of the given qualified name. + + static XMLString prefix(const XMLString& qname); + /// Returns the prefix part of the given qualified name. + + static const XMLString EMPTY_NAME; + +private: + XMLString _qname; + XMLString _namespaceURI; + XMLString _localName; +}; + + +// +// inlines +// +inline const XMLString& Name::qname() const +{ + return _qname; +} + + +inline const XMLString& Name::namespaceURI() const +{ + return _namespaceURI; +} + + +inline const XMLString& Name::localName() const +{ + return _localName; +} + + +inline void swap(Name& n1, Name& n2) +{ + n1.swap(n2); +} + + +} } // namespace Poco::XML + + +#endif // XML_Name_INCLUDED diff --git a/XML/include/Poco/XML/NamePool.h b/XML/include/Poco/XML/NamePool.h index 0502511de..8dc61aec7 100644 --- a/XML/include/Poco/XML/NamePool.h +++ b/XML/include/Poco/XML/NamePool.h @@ -1,96 +1,96 @@ -// -// NamePool.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/NamePool.h#1 $ -// -// Library: XML -// Package: XML -// Module: NamePool -// -// Definition of the NamePool class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_NamePool_INCLUDED -#define XML_NamePool_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/Name.h" - - -namespace Poco { -namespace XML { - - -class NamePoolItem; - - -class XML_API NamePool - /// A hashtable that stores XML names consisting of an URI, a - /// local name and a qualified name. -{ -public: - NamePool(unsigned long size = 251); - /// Creates a name pool with room for up to size strings. - - const Name& insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); - /// Returns a const reference to an Name for the given names. - /// Creates the Name if it does not already exist. - /// Throws a PoolOverflowException if the name pool is full. - - const Name& insert(const Name& name); - /// Returns a const reference to an Name for the given name. - /// Creates the Name if it does not already exist. - /// Throws a PoolOverflowException if the name pool is full. - - void duplicate(); - /// Increments the reference count. - - void release(); - /// Decrements the reference count and deletes the object if the reference count reaches zero. - -protected: - unsigned long hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); - ~NamePool(); - -private: - NamePool(const NamePool&); - NamePool& operator = (const NamePool&); - - NamePoolItem* _pItems; - unsigned long _size; - int _rc; -}; - - -} } // namespace Poco::XML - - -#endif // XML_NamePool_INCLUDED +// +// NamePool.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/NamePool.h#1 $ +// +// Library: XML +// Package: XML +// Module: NamePool +// +// Definition of the NamePool class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_NamePool_INCLUDED +#define XML_NamePool_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/Name.h" + + +namespace Poco { +namespace XML { + + +class NamePoolItem; + + +class XML_API NamePool + /// A hashtable that stores XML names consisting of an URI, a + /// local name and a qualified name. +{ +public: + NamePool(unsigned long size = 251); + /// Creates a name pool with room for up to size strings. + + const Name& insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); + /// Returns a const reference to an Name for the given names. + /// Creates the Name if it does not already exist. + /// Throws a PoolOverflowException if the name pool is full. + + const Name& insert(const Name& name); + /// Returns a const reference to an Name for the given name. + /// Creates the Name if it does not already exist. + /// Throws a PoolOverflowException if the name pool is full. + + void duplicate(); + /// Increments the reference count. + + void release(); + /// Decrements the reference count and deletes the object if the reference count reaches zero. + +protected: + unsigned long hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); + ~NamePool(); + +private: + NamePool(const NamePool&); + NamePool& operator = (const NamePool&); + + NamePoolItem* _pItems; + unsigned long _size; + int _rc; +}; + + +} } // namespace Poco::XML + + +#endif // XML_NamePool_INCLUDED diff --git a/XML/include/Poco/XML/NamespaceStrategy.h b/XML/include/Poco/XML/NamespaceStrategy.h index 44692a05d..fcd5facb0 100644 --- a/XML/include/Poco/XML/NamespaceStrategy.h +++ b/XML/include/Poco/XML/NamespaceStrategy.h @@ -1,137 +1,137 @@ -// -// NamespaceStrategy.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/NamespaceStrategy.h#2 $ -// -// Library: XML -// Package: XML -// Module: NamespaceStrategy -// -// Definition of the NamespaceStrategy class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_NamespaceStrategy_INCLUDED -#define XML_NamespaceStrategy_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/XMLString.h" -#include "Poco/SAX/NamespaceSupport.h" -#include "Poco/SAX/AttributesImpl.h" - - -namespace Poco { -namespace XML { - - -class ContentHandler; - - -class XML_API NamespaceStrategy - /// This class is used by ParserEngine to handle the - /// startElement, endElement, startPrefixMapping and - /// endPrefixMapping events. -{ -public: - virtual ~NamespaceStrategy(); - - virtual void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler) = 0; - /// Translate the arguments as delivered by Expat and - /// call the startElement() method of the ContentHandler. - - virtual void endElement(const XMLChar* name, ContentHandler* pContentHandler) = 0; - /// Translate the arguments as delivered by Expat and - /// call the endElement() method of the ContentHandler. - -protected: - static void splitName(const XMLChar* qname, XMLString& uri, XMLString& localName); - static void splitName(const XMLChar* qname, XMLString& uri, XMLString& localName, XMLString& prefix); - - static const XMLString NOTHING; -}; - - -class XML_API NoNamespacesStrategy: public NamespaceStrategy - /// The NamespaceStrategy implementation used if no namespaces - /// processing is requested. -{ -public: - NoNamespacesStrategy(); - ~NoNamespacesStrategy(); - - void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); - void endElement(const XMLChar* name, ContentHandler* pContentHandler); - -private: - XMLString _name; - AttributesImpl _attrs; -}; - - -class XML_API NoNamespacePrefixesStrategy: public NamespaceStrategy - /// The NamespaceStrategy implementation used if namespaces - /// processing is requested, but prefixes are not reported. -{ -public: - NoNamespacePrefixesStrategy(); - ~NoNamespacePrefixesStrategy(); - - void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); - void endElement(const XMLChar* name, ContentHandler* pContentHandler); - -private: - XMLString _uri; - XMLString _local; - AttributesImpl _attrs; -}; - - -class XML_API NamespacePrefixesStrategy: public NamespaceStrategy - /// The NamespaceStrategy implementation used if namespaces - /// processing is requested and prefixes are reported. -{ -public: - NamespacePrefixesStrategy(); - ~NamespacePrefixesStrategy(); - - void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); - void endElement(const XMLChar* name, ContentHandler* pContentHandler); - -private: - XMLString _uri; - XMLString _local; - XMLString _qname; - AttributesImpl _attrs; -}; - - -} } // namespace Poco::XML - - -#endif // XML_NamespaceStrategy_INCLUDED +// +// NamespaceStrategy.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/NamespaceStrategy.h#2 $ +// +// Library: XML +// Package: XML +// Module: NamespaceStrategy +// +// Definition of the NamespaceStrategy class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_NamespaceStrategy_INCLUDED +#define XML_NamespaceStrategy_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/XMLString.h" +#include "Poco/SAX/NamespaceSupport.h" +#include "Poco/SAX/AttributesImpl.h" + + +namespace Poco { +namespace XML { + + +class ContentHandler; + + +class XML_API NamespaceStrategy + /// This class is used by ParserEngine to handle the + /// startElement, endElement, startPrefixMapping and + /// endPrefixMapping events. +{ +public: + virtual ~NamespaceStrategy(); + + virtual void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler) = 0; + /// Translate the arguments as delivered by Expat and + /// call the startElement() method of the ContentHandler. + + virtual void endElement(const XMLChar* name, ContentHandler* pContentHandler) = 0; + /// Translate the arguments as delivered by Expat and + /// call the endElement() method of the ContentHandler. + +protected: + static void splitName(const XMLChar* qname, XMLString& uri, XMLString& localName); + static void splitName(const XMLChar* qname, XMLString& uri, XMLString& localName, XMLString& prefix); + + static const XMLString NOTHING; +}; + + +class XML_API NoNamespacesStrategy: public NamespaceStrategy + /// The NamespaceStrategy implementation used if no namespaces + /// processing is requested. +{ +public: + NoNamespacesStrategy(); + ~NoNamespacesStrategy(); + + void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); + void endElement(const XMLChar* name, ContentHandler* pContentHandler); + +private: + XMLString _name; + AttributesImpl _attrs; +}; + + +class XML_API NoNamespacePrefixesStrategy: public NamespaceStrategy + /// The NamespaceStrategy implementation used if namespaces + /// processing is requested, but prefixes are not reported. +{ +public: + NoNamespacePrefixesStrategy(); + ~NoNamespacePrefixesStrategy(); + + void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); + void endElement(const XMLChar* name, ContentHandler* pContentHandler); + +private: + XMLString _uri; + XMLString _local; + AttributesImpl _attrs; +}; + + +class XML_API NamespacePrefixesStrategy: public NamespaceStrategy + /// The NamespaceStrategy implementation used if namespaces + /// processing is requested and prefixes are reported. +{ +public: + NamespacePrefixesStrategy(); + ~NamespacePrefixesStrategy(); + + void startElement(const XMLChar* name, const XMLChar** atts, int specifiedCount, ContentHandler* pContentHandler); + void endElement(const XMLChar* name, ContentHandler* pContentHandler); + +private: + XMLString _uri; + XMLString _local; + XMLString _qname; + AttributesImpl _attrs; +}; + + +} } // namespace Poco::XML + + +#endif // XML_NamespaceStrategy_INCLUDED diff --git a/XML/include/Poco/XML/ParserEngine.h b/XML/include/Poco/XML/ParserEngine.h index d49914ba5..f21ac6dae 100644 --- a/XML/include/Poco/XML/ParserEngine.h +++ b/XML/include/Poco/XML/ParserEngine.h @@ -1,343 +1,343 @@ -// -// ParserEngine.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/ParserEngine.h#2 $ -// -// Library: XML -// Package: XML -// Module: ParserEngine -// -// Definition of the ParseEngine class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - - -#ifndef XML_ParserEngine_INCLUDED -#define XML_ParserEngine_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/XML/expat.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/XMLStream.h" -#include "Poco/SAX/Locator.h" -#include "Poco/TextEncoding.h" -#include -#include - - -namespace Poco { -namespace XML { - - -class InputSource; -class EntityResolver; -class DTDHandler; -class DeclHandler; -class ContentHandler; -class LexicalHandler; -class ErrorHandler; -class NamespaceStrategy; -class ContextLocator; - - -class XML_API ParserEngine: public Locator - /// This class provides an object-oriented, stream-based, - /// low-level interface to the XML Parser Toolkit (expat). - /// It is strongly recommended, that you use the - /// SAX parser classes (which are based on this - /// class) instead of this class, since they provide - /// a standardized, higher-level interface to the parser. -{ -public: - ParserEngine(); - /// Creates the parser engine. - - ParserEngine(const XMLString& encoding); - /// Creates the parser engine and passes the encoding - /// to the underlying parser. - - ~ParserEngine(); - /// Destroys the parser. - - void setEncoding(const XMLString& encoding); - /// Sets the encoding used by expat. The encoding must be - /// set before parsing begins, otherwise it will be ignored. - - const XMLString& getEncoding() const; - /// Returns the encoding used by expat. - - void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); - /// Adds an encoding to the parser. - - void setNamespaceStrategy(NamespaceStrategy* pStrategy); - /// Sets the NamespaceStrategy used by the parser. - /// The parser takes ownership of the strategy object - /// and deletes it when it's no longer needed. - /// The default is NoNamespacesStrategy. - - NamespaceStrategy* getNamespaceStrategy() const; - /// Returns the NamespaceStrategy currently in use. - - void setExpandInternalEntities(bool flag = true); - /// Enables/disables expansion of internal entities (enabled by - /// default). If entity expansion is disabled, internal entities - /// are reported via the default handler. - /// Must be set before parsing begins, otherwise it will be - /// ignored. - - bool getExpandInternalEntities() const; - /// Returns true if internal entities will be expanded automatically, - /// which is the default. - - void setExternalGeneralEntities(bool flag = true); - /// Enable or disable processing of external general entities. - - bool getExternalGeneralEntities() const; - /// Returns true if external general entities will be processed; false otherwise. - - void setExternalParameterEntities(bool flag = true); - /// Enable or disable processing of external parameter entities. - - bool getExternalParameterEntities() const; - /// Returns true if external parameter entities will be processed; false otherwise. - - void setEntityResolver(EntityResolver* pResolver); - /// Allow an application to register an entity resolver. - - EntityResolver* getEntityResolver() const; - /// Return the current entity resolver. - - void setDTDHandler(DTDHandler* pDTDHandler); - /// Allow an application to register a DTD event handler. - - DTDHandler* getDTDHandler() const; - /// Return the current DTD handler. - - void setDeclHandler(DeclHandler* pDeclHandler); - /// Allow an application to register a DTD declarations event handler. - - DeclHandler* getDeclHandler() const; - /// Return the current DTD declarations handler. - - void setContentHandler(ContentHandler* pContentHandler); - /// Allow an application to register a content event handler. - - ContentHandler* getContentHandler() const; - /// Return the current content handler. - - void setLexicalHandler(LexicalHandler* pLexicalHandler); - /// Allow an application to register a lexical event handler. - - LexicalHandler* getLexicalHandler() const; - /// Return the current lexical handler. - - void setErrorHandler(ErrorHandler* pErrorHandler); - /// Allow an application to register an error event handler. - - ErrorHandler* getErrorHandler() const; - /// Return the current error handler. - - void parse(InputSource* pInputSource); - /// Parse an XML document from the given InputSource. - - void parse(const char* pBuffer, std::size_t size); - /// Parses an XML document from the given buffer. - - // Locator - XMLString getPublicId() const; - /// Return the public identifier for the current document event. - - XMLString getSystemId() const; - /// Return the system identifier for the current document event. - - int getLineNumber() const; - /// Return the line number where the current document event ends. - - int getColumnNumber() const; - /// Return the column number where the current document event ends. - -protected: - void init(); - /// initializes expat - - void parseByteInputStream(XMLByteInputStream& istr); - /// Parses an entity from the given stream. - - void parseCharInputStream(XMLCharInputStream& istr); - /// Parses an entity from the given stream. - - void handleError(int errorNo); - /// Throws an XMLException with a message corresponding - /// to the given Expat error code. - - void parseExternal(XML_Parser extParser, InputSource* pInputSource); - /// Parse an XML document from the given InputSource. - - void parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr); - /// Parses an external entity from the given stream, with a separate parser. - - void parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr); - /// Parses an external entity from the given stream, with a separate parser. - - void pushContext(XML_Parser parser, InputSource* pInputSource); - /// Pushes a new entry to the context stack. - - void popContext(); - /// Pops the top-most entry from the context stack. - - void resetContext(); - /// Resets and clears the context stack. - - const Locator& locator() const; - /// Returns a locator denoting the current parse location. - - // expat handler procedures - static void handleStartElement(void* userData, const XML_Char* name, const XML_Char** atts); - static void handleEndElement(void* userData, const XML_Char* name); - static void handleCharacterData(void* userData, const XML_Char* s, int len); - static void handleProcessingInstruction(void* userData, const XML_Char* target, const XML_Char* data); - static void handleDefault(void* userData, const XML_Char* s, int len); - static void handleUnparsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId, const XML_Char* notationName); - static void handleNotationDecl(void* userData, const XML_Char* notationName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); - static int handleExternalEntityRef(XML_Parser parser, const XML_Char* openEntityNames, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); - static int handleUnknownEncoding(void* encodingHandlerData, const XML_Char* name, XML_Encoding* info); - static void handleComment(void* userData, const XML_Char* data); - static void handleStartCdataSection(void* userData); - static void handleEndCdataSection(void* userData); - static void handleStartNamespaceDecl(void* userData, const XML_Char* prefix, const XML_Char* uri); - static void handleEndNamespaceDecl(void* userData, const XML_Char* prefix); - static void handleStartDoctypeDecl(void* userData, const XML_Char* doctypeName, const XML_Char *systemId, const XML_Char* publicId, int hasInternalSubset); - static void handleEndDoctypeDecl(void* userData); - static void handleEntityDecl(void *userData, const XML_Char *entityName, int isParamEntity, const XML_Char *value, int valueLength, - const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName); - static void handleExternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); - static void handleInternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* replacementText, int replacementTextLength); - static void handleSkippedEntity(void* userData, const XML_Char* entityName, int isParameterEntity); - - // encoding support - static int convert(void *data, const char *s); - -private: - typedef std::map EncodingMap; - typedef std::vector ContextStack; - - XML_Parser _parser; - char* _pBuffer; - bool _encodingSpecified; - XMLString _encoding; - bool _expandInternalEntities; - bool _externalGeneralEntities; - bool _externalParameterEntities; - NamespaceStrategy* _pNamespaceStrategy; - EncodingMap _encodings; - ContextStack _context; - - EntityResolver* _pEntityResolver; - DTDHandler* _pDTDHandler; - DeclHandler* _pDeclHandler; - ContentHandler* _pContentHandler; - LexicalHandler* _pLexicalHandler; - ErrorHandler* _pErrorHandler; - - static const int PARSE_BUFFER_SIZE; - static const XMLString EMPTY_STRING; -}; - - -// -// inlines -// -inline const XMLString& ParserEngine::getEncoding() const -{ - return _encoding; -} - - -inline NamespaceStrategy* ParserEngine::getNamespaceStrategy() const -{ - return _pNamespaceStrategy; -} - - -inline bool ParserEngine::getExpandInternalEntities() const -{ - return _expandInternalEntities; -} - - -inline bool ParserEngine::getExternalGeneralEntities() const -{ - return _externalGeneralEntities; -} - - -inline bool ParserEngine::getExternalParameterEntities() const -{ - return _externalParameterEntities; -} - - -inline EntityResolver* ParserEngine::getEntityResolver() const -{ - return _pEntityResolver; -} - - -inline DTDHandler* ParserEngine::getDTDHandler() const -{ - return _pDTDHandler; -} - - -inline DeclHandler* ParserEngine::getDeclHandler() const -{ - return _pDeclHandler; -} - - -inline ContentHandler* ParserEngine::getContentHandler() const -{ - return _pContentHandler; -} - - -inline LexicalHandler* ParserEngine::getLexicalHandler() const -{ - return _pLexicalHandler; -} - - -inline ErrorHandler* ParserEngine::getErrorHandler() const -{ - return _pErrorHandler; -} - - -} } // namespace Poco::XML - - -#endif // XML_ParserEngine_INCLUDED +// +// ParserEngine.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/ParserEngine.h#2 $ +// +// Library: XML +// Package: XML +// Module: ParserEngine +// +// Definition of the ParseEngine class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + + +#ifndef XML_ParserEngine_INCLUDED +#define XML_ParserEngine_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/XML/expat.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/XMLStream.h" +#include "Poco/SAX/Locator.h" +#include "Poco/TextEncoding.h" +#include +#include + + +namespace Poco { +namespace XML { + + +class InputSource; +class EntityResolver; +class DTDHandler; +class DeclHandler; +class ContentHandler; +class LexicalHandler; +class ErrorHandler; +class NamespaceStrategy; +class ContextLocator; + + +class XML_API ParserEngine: public Locator + /// This class provides an object-oriented, stream-based, + /// low-level interface to the XML Parser Toolkit (expat). + /// It is strongly recommended, that you use the + /// SAX parser classes (which are based on this + /// class) instead of this class, since they provide + /// a standardized, higher-level interface to the parser. +{ +public: + ParserEngine(); + /// Creates the parser engine. + + ParserEngine(const XMLString& encoding); + /// Creates the parser engine and passes the encoding + /// to the underlying parser. + + ~ParserEngine(); + /// Destroys the parser. + + void setEncoding(const XMLString& encoding); + /// Sets the encoding used by expat. The encoding must be + /// set before parsing begins, otherwise it will be ignored. + + const XMLString& getEncoding() const; + /// Returns the encoding used by expat. + + void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding); + /// Adds an encoding to the parser. + + void setNamespaceStrategy(NamespaceStrategy* pStrategy); + /// Sets the NamespaceStrategy used by the parser. + /// The parser takes ownership of the strategy object + /// and deletes it when it's no longer needed. + /// The default is NoNamespacesStrategy. + + NamespaceStrategy* getNamespaceStrategy() const; + /// Returns the NamespaceStrategy currently in use. + + void setExpandInternalEntities(bool flag = true); + /// Enables/disables expansion of internal entities (enabled by + /// default). If entity expansion is disabled, internal entities + /// are reported via the default handler. + /// Must be set before parsing begins, otherwise it will be + /// ignored. + + bool getExpandInternalEntities() const; + /// Returns true if internal entities will be expanded automatically, + /// which is the default. + + void setExternalGeneralEntities(bool flag = true); + /// Enable or disable processing of external general entities. + + bool getExternalGeneralEntities() const; + /// Returns true if external general entities will be processed; false otherwise. + + void setExternalParameterEntities(bool flag = true); + /// Enable or disable processing of external parameter entities. + + bool getExternalParameterEntities() const; + /// Returns true if external parameter entities will be processed; false otherwise. + + void setEntityResolver(EntityResolver* pResolver); + /// Allow an application to register an entity resolver. + + EntityResolver* getEntityResolver() const; + /// Return the current entity resolver. + + void setDTDHandler(DTDHandler* pDTDHandler); + /// Allow an application to register a DTD event handler. + + DTDHandler* getDTDHandler() const; + /// Return the current DTD handler. + + void setDeclHandler(DeclHandler* pDeclHandler); + /// Allow an application to register a DTD declarations event handler. + + DeclHandler* getDeclHandler() const; + /// Return the current DTD declarations handler. + + void setContentHandler(ContentHandler* pContentHandler); + /// Allow an application to register a content event handler. + + ContentHandler* getContentHandler() const; + /// Return the current content handler. + + void setLexicalHandler(LexicalHandler* pLexicalHandler); + /// Allow an application to register a lexical event handler. + + LexicalHandler* getLexicalHandler() const; + /// Return the current lexical handler. + + void setErrorHandler(ErrorHandler* pErrorHandler); + /// Allow an application to register an error event handler. + + ErrorHandler* getErrorHandler() const; + /// Return the current error handler. + + void parse(InputSource* pInputSource); + /// Parse an XML document from the given InputSource. + + void parse(const char* pBuffer, std::size_t size); + /// Parses an XML document from the given buffer. + + // Locator + XMLString getPublicId() const; + /// Return the public identifier for the current document event. + + XMLString getSystemId() const; + /// Return the system identifier for the current document event. + + int getLineNumber() const; + /// Return the line number where the current document event ends. + + int getColumnNumber() const; + /// Return the column number where the current document event ends. + +protected: + void init(); + /// initializes expat + + void parseByteInputStream(XMLByteInputStream& istr); + /// Parses an entity from the given stream. + + void parseCharInputStream(XMLCharInputStream& istr); + /// Parses an entity from the given stream. + + void handleError(int errorNo); + /// Throws an XMLException with a message corresponding + /// to the given Expat error code. + + void parseExternal(XML_Parser extParser, InputSource* pInputSource); + /// Parse an XML document from the given InputSource. + + void parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr); + /// Parses an external entity from the given stream, with a separate parser. + + void parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr); + /// Parses an external entity from the given stream, with a separate parser. + + void pushContext(XML_Parser parser, InputSource* pInputSource); + /// Pushes a new entry to the context stack. + + void popContext(); + /// Pops the top-most entry from the context stack. + + void resetContext(); + /// Resets and clears the context stack. + + const Locator& locator() const; + /// Returns a locator denoting the current parse location. + + // expat handler procedures + static void handleStartElement(void* userData, const XML_Char* name, const XML_Char** atts); + static void handleEndElement(void* userData, const XML_Char* name); + static void handleCharacterData(void* userData, const XML_Char* s, int len); + static void handleProcessingInstruction(void* userData, const XML_Char* target, const XML_Char* data); + static void handleDefault(void* userData, const XML_Char* s, int len); + static void handleUnparsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId, const XML_Char* notationName); + static void handleNotationDecl(void* userData, const XML_Char* notationName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); + static int handleExternalEntityRef(XML_Parser parser, const XML_Char* openEntityNames, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); + static int handleUnknownEncoding(void* encodingHandlerData, const XML_Char* name, XML_Encoding* info); + static void handleComment(void* userData, const XML_Char* data); + static void handleStartCdataSection(void* userData); + static void handleEndCdataSection(void* userData); + static void handleStartNamespaceDecl(void* userData, const XML_Char* prefix, const XML_Char* uri); + static void handleEndNamespaceDecl(void* userData, const XML_Char* prefix); + static void handleStartDoctypeDecl(void* userData, const XML_Char* doctypeName, const XML_Char *systemId, const XML_Char* publicId, int hasInternalSubset); + static void handleEndDoctypeDecl(void* userData); + static void handleEntityDecl(void *userData, const XML_Char *entityName, int isParamEntity, const XML_Char *value, int valueLength, + const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName); + static void handleExternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* base, const XML_Char* systemId, const XML_Char* publicId); + static void handleInternalParsedEntityDecl(void* userData, const XML_Char* entityName, const XML_Char* replacementText, int replacementTextLength); + static void handleSkippedEntity(void* userData, const XML_Char* entityName, int isParameterEntity); + + // encoding support + static int convert(void *data, const char *s); + +private: + typedef std::map EncodingMap; + typedef std::vector ContextStack; + + XML_Parser _parser; + char* _pBuffer; + bool _encodingSpecified; + XMLString _encoding; + bool _expandInternalEntities; + bool _externalGeneralEntities; + bool _externalParameterEntities; + NamespaceStrategy* _pNamespaceStrategy; + EncodingMap _encodings; + ContextStack _context; + + EntityResolver* _pEntityResolver; + DTDHandler* _pDTDHandler; + DeclHandler* _pDeclHandler; + ContentHandler* _pContentHandler; + LexicalHandler* _pLexicalHandler; + ErrorHandler* _pErrorHandler; + + static const int PARSE_BUFFER_SIZE; + static const XMLString EMPTY_STRING; +}; + + +// +// inlines +// +inline const XMLString& ParserEngine::getEncoding() const +{ + return _encoding; +} + + +inline NamespaceStrategy* ParserEngine::getNamespaceStrategy() const +{ + return _pNamespaceStrategy; +} + + +inline bool ParserEngine::getExpandInternalEntities() const +{ + return _expandInternalEntities; +} + + +inline bool ParserEngine::getExternalGeneralEntities() const +{ + return _externalGeneralEntities; +} + + +inline bool ParserEngine::getExternalParameterEntities() const +{ + return _externalParameterEntities; +} + + +inline EntityResolver* ParserEngine::getEntityResolver() const +{ + return _pEntityResolver; +} + + +inline DTDHandler* ParserEngine::getDTDHandler() const +{ + return _pDTDHandler; +} + + +inline DeclHandler* ParserEngine::getDeclHandler() const +{ + return _pDeclHandler; +} + + +inline ContentHandler* ParserEngine::getContentHandler() const +{ + return _pContentHandler; +} + + +inline LexicalHandler* ParserEngine::getLexicalHandler() const +{ + return _pLexicalHandler; +} + + +inline ErrorHandler* ParserEngine::getErrorHandler() const +{ + return _pErrorHandler; +} + + +} } // namespace Poco::XML + + +#endif // XML_ParserEngine_INCLUDED diff --git a/XML/include/Poco/XML/XML.h b/XML/include/Poco/XML/XML.h index e289a1a43..27c0b7683 100644 --- a/XML/include/Poco/XML/XML.h +++ b/XML/include/Poco/XML/XML.h @@ -1,92 +1,92 @@ -// -// XML.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/XML.h#2 $ -// -// Library: XML -// Package: XML -// Module: XML -// -// Basic definitions for the Poco XML library. -// This file must be the first file included by every other XML -// header file. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_XML_INCLUDED -#define XML_XML_INCLUDED - - -#include "Poco/Foundation.h" - - -// -// The following block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the XML_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// XML_API functions as being imported from a DLL, wheras this DLL sees symbols -// defined with this macro as being exported. -// -#if defined(_WIN32) && defined(POCO_DLL) - #if defined(XML_EXPORTS) - #define XML_API __declspec(dllexport) - #else - #define XML_API __declspec(dllimport) - #endif -#endif - - -#if !defined(XML_API) - #define XML_API -#endif - - -// -// Automatically link XML library. -// -#if defined(_MSC_VER) - #if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(XML_EXPORTS) - #if defined(POCO_DLL) - #if defined(_DEBUG) - #pragma comment(lib, "PocoXMLd.lib") - #else - #pragma comment(lib, "PocoXML.lib") - #endif - #else - #if defined(_DEBUG) - #pragma comment(lib, "PocoXMLmtd.lib") - #else - #pragma comment(lib, "PocoXMLmt.lib") - #endif - #endif - #endif -#endif - - -#endif // XML_XML_INCLUDED +// +// XML.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/XML.h#2 $ +// +// Library: XML +// Package: XML +// Module: XML +// +// Basic definitions for the Poco XML library. +// This file must be the first file included by every other XML +// header file. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_XML_INCLUDED +#define XML_XML_INCLUDED + + +#include "Poco/Foundation.h" + + +// +// The following block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the XML_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// XML_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +// +#if defined(_WIN32) && defined(POCO_DLL) + #if defined(XML_EXPORTS) + #define XML_API __declspec(dllexport) + #else + #define XML_API __declspec(dllimport) + #endif +#endif + + +#if !defined(XML_API) + #define XML_API +#endif + + +// +// Automatically link XML library. +// +#if defined(_MSC_VER) + #if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(XML_EXPORTS) + #if defined(POCO_DLL) + #if defined(_DEBUG) + #pragma comment(lib, "PocoXMLd.lib") + #else + #pragma comment(lib, "PocoXML.lib") + #endif + #else + #if defined(_DEBUG) + #pragma comment(lib, "PocoXMLmtd.lib") + #else + #pragma comment(lib, "PocoXMLmt.lib") + #endif + #endif + #endif +#endif + + +#endif // XML_XML_INCLUDED diff --git a/XML/include/Poco/XML/XMLException.h b/XML/include/Poco/XML/XMLException.h index a3081024b..94ae32b9f 100644 --- a/XML/include/Poco/XML/XMLException.h +++ b/XML/include/Poco/XML/XMLException.h @@ -1,59 +1,59 @@ -// -// XMLException.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/XMLException.h#1 $ -// -// Library: XML -// Package: XML -// Module: XMLException -// -// Definition of the XMLException class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_XMLException_INCLUDED -#define XML_XMLException_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/Exception.h" - - -namespace Poco { -namespace XML { - - -POCO_DECLARE_EXCEPTION(XML_API, XMLException, Poco::RuntimeException) - /// The base class for all XML-related exceptions like SAXException - /// and DOMException. - - -} } // namespace Poco::XML - - -#endif // XML_XMLException_INCLUDED +// +// XMLException.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/XMLException.h#1 $ +// +// Library: XML +// Package: XML +// Module: XMLException +// +// Definition of the XMLException class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_XMLException_INCLUDED +#define XML_XMLException_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/Exception.h" + + +namespace Poco { +namespace XML { + + +POCO_DECLARE_EXCEPTION(XML_API, XMLException, Poco::RuntimeException) + /// The base class for all XML-related exceptions like SAXException + /// and DOMException. + + +} } // namespace Poco::XML + + +#endif // XML_XMLException_INCLUDED diff --git a/XML/include/Poco/XML/XMLStream.h b/XML/include/Poco/XML/XMLStream.h index 3b543bd17..789728787 100644 --- a/XML/include/Poco/XML/XMLStream.h +++ b/XML/include/Poco/XML/XMLStream.h @@ -1,93 +1,93 @@ -// -// XMLStream.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/XMLStream.h#1 $ -// -// Library: XML -// Package: XML -// Module: XMLStream -// -// Definition of the XMLByteInputStream and XMLCharInputStream classes. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_XMLStream_INCLUDED -#define XML_XMLStream_INCLUDED - - -#include "Poco/XML/XML.h" -#include -#include - - -namespace Poco { -namespace XML { - - -// The byte input stream is always a narrow stream. -typedef std::istream XMLByteInputStream; -typedef std::ostream XMLByteOutputStream; - - -// -// The XML parser uses the stream classes provided by the C++ -// standard library (based on the basic_stream<> template). -// In Unicode mode, a wide stream is used. -// To turn on Unicode mode, #define XML_UNICODE and -// XML_UNICODE_WCHAR_T when compiling the library. -// -// XML_UNICODE XML_UNICODE_WCHAR_T XMLCharInputStream XMLCharOutputStream -// ------------------------------------------------------------------------- -// N N std::istream std::ostream -// N Y std::wistream std::wostream -// Y Y std::wistream std::wostream -// Y N -// -#if defined(XML_UNICODE_WCHAR_T) - - // Unicode - use wide streams - typedef std::wistream XMLCharInputStream; - typedef std::wostream XMLCharOutputStream; - -#elif defined(XML_UNICODE) - - // not supported - leave XMLString undefined - -#else - - // Characters are UTF-8 encoded - typedef std::istream XMLCharInputStream; - typedef std::ostream XMLCharOutputStream; - -#endif - - -} } // namespace Poco::XML - - -#endif // XML_XMLStream_INCLUDED +// +// XMLStream.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/XMLStream.h#1 $ +// +// Library: XML +// Package: XML +// Module: XMLStream +// +// Definition of the XMLByteInputStream and XMLCharInputStream classes. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_XMLStream_INCLUDED +#define XML_XMLStream_INCLUDED + + +#include "Poco/XML/XML.h" +#include +#include + + +namespace Poco { +namespace XML { + + +// The byte input stream is always a narrow stream. +typedef std::istream XMLByteInputStream; +typedef std::ostream XMLByteOutputStream; + + +// +// The XML parser uses the stream classes provided by the C++ +// standard library (based on the basic_stream<> template). +// In Unicode mode, a wide stream is used. +// To turn on Unicode mode, #define XML_UNICODE and +// XML_UNICODE_WCHAR_T when compiling the library. +// +// XML_UNICODE XML_UNICODE_WCHAR_T XMLCharInputStream XMLCharOutputStream +// ------------------------------------------------------------------------- +// N N std::istream std::ostream +// N Y std::wistream std::wostream +// Y Y std::wistream std::wostream +// Y N +// +#if defined(XML_UNICODE_WCHAR_T) + + // Unicode - use wide streams + typedef std::wistream XMLCharInputStream; + typedef std::wostream XMLCharOutputStream; + +#elif defined(XML_UNICODE) + + // not supported - leave XMLString undefined + +#else + + // Characters are UTF-8 encoded + typedef std::istream XMLCharInputStream; + typedef std::ostream XMLCharOutputStream; + +#endif + + +} } // namespace Poco::XML + + +#endif // XML_XMLStream_INCLUDED diff --git a/XML/include/Poco/XML/XMLWriter.h b/XML/include/Poco/XML/XMLWriter.h index 7f5a4dff8..3846824b7 100644 --- a/XML/include/Poco/XML/XMLWriter.h +++ b/XML/include/Poco/XML/XMLWriter.h @@ -1,331 +1,331 @@ -// -// XMLWriter.h -// -// $Id: //poco/1.3/XML/include/Poco/XML/XMLWriter.h#1 $ -// -// Library: XML -// Package: XML -// Module: XMLWriter -// -// Definition of the XMLWriter class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XML_XMLWriter_INCLUDED -#define XML_XMLWriter_INCLUDED - - -#include "Poco/XML/XML.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/LexicalHandler.h" -#include "Poco/SAX/DTDHandler.h" -#include "Poco/SAX/NamespaceSupport.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/XMLStream.h" -#include "Poco/XML/Name.h" -#include "Poco/TextEncoding.h" -#include "Poco/StreamConverter.h" -#include -#include - - -namespace Poco { -namespace XML { - - -class Locator; - - -class XML_API XMLWriter: public ContentHandler, public LexicalHandler, public DTDHandler - /// This class serializes SAX2 ContentHandler, LexicalHandler and - /// DTDHandler events back into a stream. - /// - /// Various consistency checks are performed on the written data - /// (i.e. there must be exactly one root element and every startElement() - /// must have a matching endElement()). - /// - /// The XMLWriter supports optional pretty-printing of the serialized XML. - /// Note, however, that pretty-printing XML data alters the - /// information set of the document being written, since in - /// XML all whitespace is potentially relevant to an application. - /// - /// The writer contains extensive support for XML Namespaces, so that a client - /// application does not have to keep track of prefixes and supply xmlns attributes. - /// - /// If the client does not provide namespace prefixes (either by specifying them - /// as part of the qualified name given to startElement(), or by calling - /// startPrefixMapping()), the XMLWriter automatically generates namespace - /// prefixes in the form ns1, ns2, etc. -{ -public: - enum Options - { - CANONICAL = 0x00, /// do not write an XML declaration - WRITE_XML_DECLARATION = 0x01, /// write an XML declaration - PRETTY_PRINT = 0x02 /// pretty-print XML markup - }; - - XMLWriter(XMLByteOutputStream& str, int options); - /// Creates the XMLWriter and sets the specified options. - /// - /// The resulting stream will be UTF-8 encoded. - - XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding& textEncoding); - /// Creates the XMLWriter and sets the specified options. - /// - /// The encoding is reflected in the XML declaration. - /// The caller is responsible for that the given encodingName matches with - /// the given textEncoding. - - XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding* pTextEncoding); - /// Creates the XMLWriter and sets the specified options. - /// - /// The encoding is reflected in the XML declaration. - /// The caller is responsible for that the given encodingName matches with - /// the given textEncoding. - /// If pTextEncoding is null, the given encodingName is ignored and the - /// default UTF-8 encoding is used. - - ~XMLWriter(); - /// Destroys the XMLWriter. - - void setNewLine(const std::string& newLineCharacters); - /// Sets the line ending for the resulting XML file. - /// - /// Possible values are: - /// * NEWLINE_DEFAULT (whatever is appropriate for the current platform) - /// * NEWLINE_CRLF (Windows), - /// * NEWLINE_LF (Unix), - /// * NEWLINE_CR (Macintosh) - - const std::string& getNewLine() const; - /// Returns the line ending currently in use. - - // ContentHandler - void setDocumentLocator(const Locator* loc); - /// Currently unused. - - void startDocument(); - /// Writes a generic XML declaration to the stream. - /// If a document type has been set (see SetDocumentType), - /// a DOCTYPE declaration is also written. - - void endDocument(); - /// Checks that all elements are closed and prints a final newline. - - void startFragment(); - /// Use this instead of StartDocument() if you want to write - /// a fragment rather than a document (no XML declaration and - /// more than one "root" element allowed). - - void endFragment(); - /// Checks that all elements are closed and prints a final newline. - - void startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); - /// Writes an XML start element tag. - /// - /// Namespaces are handled as follows. - /// 1. If a qname, but no namespaceURI and localName are given, the qname is taken as element name. - /// 2. If a namespaceURI and a localName, but no qname is given, and the given namespaceURI has been - /// declared earlier, the namespace prefix for the given namespaceURI together with the localName - /// is taken as element name. If the namespace has not been declared, a prefix in the form - /// "ns1", "ns2", etc. is generated and the namespace is declared with the generated prefix. - /// 3. If all three are given, and the namespace given in namespaceURI has not been declared, it is declared now. - /// Otherwise, see 2. - - void startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); - /// Writes an XML start element tag with no attributes. - /// See the other startElement() method for more information. - - void endElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); - /// Writes an XML end element tag. - /// - /// Throws an exception if the name of doesn't match the - /// one of the most recent startElement(). - - void emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); - /// Writes an empty XML element tag (). - - void emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); - /// Writes an empty XML element tag with the given attributes (). - - void characters(const XMLChar ch[], int start, int length); - /// Writes XML character data. Quotes, ampersand's, less-than and - /// greater-than signs are escaped, unless a CDATA section - /// has been opened by calling startCDATA(). - /// - /// The characters must be encoded in UTF-8 (if XMLChar is char) or - /// UTF-16 (if XMLChar is wchar_t). - - void characters(const XMLString& str); - /// Writes XML character data. Quotes, ampersand's, less-than and - /// greater-than signs are escaped, unless a CDATA section - /// has been opened by calling startCDATA(). - /// - /// The characters must be encoded in UTF-8 (if XMLChar is char) or - /// UTF-16 (if XMLChar is wchar_t). - - void rawCharacters(const XMLString& str); - /// Writes the characters in the given string as they are. - /// The caller is responsible for escaping characters as - /// necessary to produce valid XML. - /// - /// The characters must be encoded in UTF-8 (if XMLChar is char) or - /// UTF-16 (if XMLChar is wchar_t). - - void ignorableWhitespace(const XMLChar ch[], int start, int length); - /// Writes whitespace characters by simply passing them to - /// characters(). - - void processingInstruction(const XMLString& target, const XMLString& data); - /// Writes a processing instruction. - - void startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI); - /// Begin the scope of a prefix-URI Namespace mapping. - /// A namespace declaration is written with the next element. - - void endPrefixMapping(const XMLString& prefix); - /// End the scope of a prefix-URI mapping. - - void skippedEntity(const XMLString& name); - /// Does nothing. - - void dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& data, - const XMLString& attr1 = XMLString(), const XMLString& value1 = XMLString(), - const XMLString& attr2 = XMLString(), const XMLString& value2 = XMLString(), - const XMLString& attr3 = XMLString(), const XMLString& value3 = XMLString()); - /// Writes a data element in the form data. - - // LexicalHandler - void startCDATA(); - /// Writes the string that ends a CDATA section. - - void comment(const XMLChar ch[], int start, int length); - /// Writes a comment. - - void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); - /// Writes a DTD declaration. - - void endDTD(); - /// Writes the closing characters of a DTD declaration. - - void startEntity(const XMLString& name); - /// Does nothing. - - void endEntity(const XMLString& name); - /// Does nothing. - - // DTDHandler - void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); - void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); - - static const std::string NEWLINE_DEFAULT; - static const std::string NEWLINE_CR; - static const std::string NEWLINE_CRLF; - static const std::string NEWLINE_LF; - -protected: - typedef std::map AttributeMap; - - void writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); - void writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); - void writeMarkup(const std::string& str) const; - void writeXML(const XMLString& str) const; - void writeXML(XMLChar ch) const; - void writeNewLine() const; - void writeIndent() const; - void writeName(const XMLString& prefix, const XMLString& localName); - void writeXMLDeclaration(); - void closeStartTag(); - void declareAttributeNamespaces(const Attributes& attributes); - void addNamespaceAttributes(AttributeMap& attributeMap); - void addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI); - void writeAttributes(const AttributeMap& attributeMap); - void prettyPrint() const; - XMLString newPrefix(); - static std::string nameToString(const XMLString& localName, const XMLString& qname); - -private: - struct Namespace - { - Namespace(const XMLString& thePrefix, const XMLString& theNamespaceURI): - prefix(thePrefix), - namespaceURI(theNamespaceURI) - { - } - - XMLString prefix; - XMLString namespaceURI; - }; - typedef std::vector ElementStack; - - Poco::OutputStreamConverter* _pTextConverter; - Poco::TextEncoding* _pInEncoding; - Poco::TextEncoding* _pOutEncoding; - int _options; - std::string _encoding; - std::string _newLine; - int _depth; - int _elementCount; - bool _inFragment; - bool _inCDATA; - bool _inDTD; - bool _inInternalDTD; - bool _contentWritten; - bool _unclosedStartTag; - ElementStack _elementStack; - NamespaceSupport _namespaces; - int _prefix; - - static const std::string MARKUP_QUOTENC; - static const std::string MARKUP_APOSENC; - static const std::string MARKUP_AMPENC; - static const std::string MARKUP_LTENC; - static const std::string MARKUP_GTENC; - static const std::string MARKUP_LT; - static const std::string MARKUP_GT; - static const std::string MARKUP_SLASHGT; - static const std::string MARKUP_LTSLASH; - static const std::string MARKUP_COLON; - static const std::string MARKUP_EQQUOT; - static const std::string MARKUP_QUOT; - static const std::string MARKUP_SPACE; - static const std::string MARKUP_TAB; - static const std::string MARKUP_BEGIN_CDATA; - static const std::string MARKUP_END_CDATA; -}; - - -} } // namespace Poco::XML - - -#endif // XML_XMLWriter_INCLUDED +// +// XMLWriter.h +// +// $Id: //poco/1.3/XML/include/Poco/XML/XMLWriter.h#1 $ +// +// Library: XML +// Package: XML +// Module: XMLWriter +// +// Definition of the XMLWriter class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XML_XMLWriter_INCLUDED +#define XML_XMLWriter_INCLUDED + + +#include "Poco/XML/XML.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/LexicalHandler.h" +#include "Poco/SAX/DTDHandler.h" +#include "Poco/SAX/NamespaceSupport.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/XMLStream.h" +#include "Poco/XML/Name.h" +#include "Poco/TextEncoding.h" +#include "Poco/StreamConverter.h" +#include +#include + + +namespace Poco { +namespace XML { + + +class Locator; + + +class XML_API XMLWriter: public ContentHandler, public LexicalHandler, public DTDHandler + /// This class serializes SAX2 ContentHandler, LexicalHandler and + /// DTDHandler events back into a stream. + /// + /// Various consistency checks are performed on the written data + /// (i.e. there must be exactly one root element and every startElement() + /// must have a matching endElement()). + /// + /// The XMLWriter supports optional pretty-printing of the serialized XML. + /// Note, however, that pretty-printing XML data alters the + /// information set of the document being written, since in + /// XML all whitespace is potentially relevant to an application. + /// + /// The writer contains extensive support for XML Namespaces, so that a client + /// application does not have to keep track of prefixes and supply xmlns attributes. + /// + /// If the client does not provide namespace prefixes (either by specifying them + /// as part of the qualified name given to startElement(), or by calling + /// startPrefixMapping()), the XMLWriter automatically generates namespace + /// prefixes in the form ns1, ns2, etc. +{ +public: + enum Options + { + CANONICAL = 0x00, /// do not write an XML declaration + WRITE_XML_DECLARATION = 0x01, /// write an XML declaration + PRETTY_PRINT = 0x02 /// pretty-print XML markup + }; + + XMLWriter(XMLByteOutputStream& str, int options); + /// Creates the XMLWriter and sets the specified options. + /// + /// The resulting stream will be UTF-8 encoded. + + XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding& textEncoding); + /// Creates the XMLWriter and sets the specified options. + /// + /// The encoding is reflected in the XML declaration. + /// The caller is responsible for that the given encodingName matches with + /// the given textEncoding. + + XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding* pTextEncoding); + /// Creates the XMLWriter and sets the specified options. + /// + /// The encoding is reflected in the XML declaration. + /// The caller is responsible for that the given encodingName matches with + /// the given textEncoding. + /// If pTextEncoding is null, the given encodingName is ignored and the + /// default UTF-8 encoding is used. + + ~XMLWriter(); + /// Destroys the XMLWriter. + + void setNewLine(const std::string& newLineCharacters); + /// Sets the line ending for the resulting XML file. + /// + /// Possible values are: + /// * NEWLINE_DEFAULT (whatever is appropriate for the current platform) + /// * NEWLINE_CRLF (Windows), + /// * NEWLINE_LF (Unix), + /// * NEWLINE_CR (Macintosh) + + const std::string& getNewLine() const; + /// Returns the line ending currently in use. + + // ContentHandler + void setDocumentLocator(const Locator* loc); + /// Currently unused. + + void startDocument(); + /// Writes a generic XML declaration to the stream. + /// If a document type has been set (see SetDocumentType), + /// a DOCTYPE declaration is also written. + + void endDocument(); + /// Checks that all elements are closed and prints a final newline. + + void startFragment(); + /// Use this instead of StartDocument() if you want to write + /// a fragment rather than a document (no XML declaration and + /// more than one "root" element allowed). + + void endFragment(); + /// Checks that all elements are closed and prints a final newline. + + void startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); + /// Writes an XML start element tag. + /// + /// Namespaces are handled as follows. + /// 1. If a qname, but no namespaceURI and localName are given, the qname is taken as element name. + /// 2. If a namespaceURI and a localName, but no qname is given, and the given namespaceURI has been + /// declared earlier, the namespace prefix for the given namespaceURI together with the localName + /// is taken as element name. If the namespace has not been declared, a prefix in the form + /// "ns1", "ns2", etc. is generated and the namespace is declared with the generated prefix. + /// 3. If all three are given, and the namespace given in namespaceURI has not been declared, it is declared now. + /// Otherwise, see 2. + + void startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); + /// Writes an XML start element tag with no attributes. + /// See the other startElement() method for more information. + + void endElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); + /// Writes an XML end element tag. + /// + /// Throws an exception if the name of doesn't match the + /// one of the most recent startElement(). + + void emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); + /// Writes an empty XML element tag (). + + void emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); + /// Writes an empty XML element tag with the given attributes (). + + void characters(const XMLChar ch[], int start, int length); + /// Writes XML character data. Quotes, ampersand's, less-than and + /// greater-than signs are escaped, unless a CDATA section + /// has been opened by calling startCDATA(). + /// + /// The characters must be encoded in UTF-8 (if XMLChar is char) or + /// UTF-16 (if XMLChar is wchar_t). + + void characters(const XMLString& str); + /// Writes XML character data. Quotes, ampersand's, less-than and + /// greater-than signs are escaped, unless a CDATA section + /// has been opened by calling startCDATA(). + /// + /// The characters must be encoded in UTF-8 (if XMLChar is char) or + /// UTF-16 (if XMLChar is wchar_t). + + void rawCharacters(const XMLString& str); + /// Writes the characters in the given string as they are. + /// The caller is responsible for escaping characters as + /// necessary to produce valid XML. + /// + /// The characters must be encoded in UTF-8 (if XMLChar is char) or + /// UTF-16 (if XMLChar is wchar_t). + + void ignorableWhitespace(const XMLChar ch[], int start, int length); + /// Writes whitespace characters by simply passing them to + /// characters(). + + void processingInstruction(const XMLString& target, const XMLString& data); + /// Writes a processing instruction. + + void startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI); + /// Begin the scope of a prefix-URI Namespace mapping. + /// A namespace declaration is written with the next element. + + void endPrefixMapping(const XMLString& prefix); + /// End the scope of a prefix-URI mapping. + + void skippedEntity(const XMLString& name); + /// Does nothing. + + void dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& data, + const XMLString& attr1 = XMLString(), const XMLString& value1 = XMLString(), + const XMLString& attr2 = XMLString(), const XMLString& value2 = XMLString(), + const XMLString& attr3 = XMLString(), const XMLString& value3 = XMLString()); + /// Writes a data element in the form data. + + // LexicalHandler + void startCDATA(); + /// Writes the string that ends a CDATA section. + + void comment(const XMLChar ch[], int start, int length); + /// Writes a comment. + + void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId); + /// Writes a DTD declaration. + + void endDTD(); + /// Writes the closing characters of a DTD declaration. + + void startEntity(const XMLString& name); + /// Does nothing. + + void endEntity(const XMLString& name); + /// Does nothing. + + // DTDHandler + void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId); + void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName); + + static const std::string NEWLINE_DEFAULT; + static const std::string NEWLINE_CR; + static const std::string NEWLINE_CRLF; + static const std::string NEWLINE_LF; + +protected: + typedef std::map AttributeMap; + + void writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes); + void writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname); + void writeMarkup(const std::string& str) const; + void writeXML(const XMLString& str) const; + void writeXML(XMLChar ch) const; + void writeNewLine() const; + void writeIndent() const; + void writeName(const XMLString& prefix, const XMLString& localName); + void writeXMLDeclaration(); + void closeStartTag(); + void declareAttributeNamespaces(const Attributes& attributes); + void addNamespaceAttributes(AttributeMap& attributeMap); + void addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI); + void writeAttributes(const AttributeMap& attributeMap); + void prettyPrint() const; + XMLString newPrefix(); + static std::string nameToString(const XMLString& localName, const XMLString& qname); + +private: + struct Namespace + { + Namespace(const XMLString& thePrefix, const XMLString& theNamespaceURI): + prefix(thePrefix), + namespaceURI(theNamespaceURI) + { + } + + XMLString prefix; + XMLString namespaceURI; + }; + typedef std::vector ElementStack; + + Poco::OutputStreamConverter* _pTextConverter; + Poco::TextEncoding* _pInEncoding; + Poco::TextEncoding* _pOutEncoding; + int _options; + std::string _encoding; + std::string _newLine; + int _depth; + int _elementCount; + bool _inFragment; + bool _inCDATA; + bool _inDTD; + bool _inInternalDTD; + bool _contentWritten; + bool _unclosedStartTag; + ElementStack _elementStack; + NamespaceSupport _namespaces; + int _prefix; + + static const std::string MARKUP_QUOTENC; + static const std::string MARKUP_APOSENC; + static const std::string MARKUP_AMPENC; + static const std::string MARKUP_LTENC; + static const std::string MARKUP_GTENC; + static const std::string MARKUP_LT; + static const std::string MARKUP_GT; + static const std::string MARKUP_SLASHGT; + static const std::string MARKUP_LTSLASH; + static const std::string MARKUP_COLON; + static const std::string MARKUP_EQQUOT; + static const std::string MARKUP_QUOT; + static const std::string MARKUP_SPACE; + static const std::string MARKUP_TAB; + static const std::string MARKUP_BEGIN_CDATA; + static const std::string MARKUP_END_CDATA; +}; + + +} } // namespace Poco::XML + + +#endif // XML_XMLWriter_INCLUDED diff --git a/XML/include/Poco/XML/expat.h b/XML/include/Poco/XML/expat.h index 6c2b6ff57..20a8278f7 100644 --- a/XML/include/Poco/XML/expat.h +++ b/XML/include/Poco/XML/expat.h @@ -1,1014 +1,1014 @@ -/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#ifndef Expat_INCLUDED -#define Expat_INCLUDED 1 - -#ifdef __VMS -/* 0 1 2 3 0 1 2 3 - 1234567890123456789012345678901 1234567890123456789012345678901 */ -#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler -#define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler -#define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler -#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg -#endif - -#include -#include "expat_external.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct XML_ParserStruct; -typedef struct XML_ParserStruct *XML_Parser; - -/* Should this be defined using stdbool.h when C99 is available? */ -typedef unsigned char XML_Bool; -#define XML_TRUE ((XML_Bool) 1) -#define XML_FALSE ((XML_Bool) 0) - -/* The XML_Status enum gives the possible return values for several - API functions. The preprocessor #defines are included so this - stanza can be added to code that still needs to support older - versions of Expat 1.95.x: - - #ifndef XML_STATUS_OK - #define XML_STATUS_OK 1 - #define XML_STATUS_ERROR 0 - #endif - - Otherwise, the #define hackery is quite ugly and would have been - dropped. -*/ -enum XML_Status { - XML_STATUS_ERROR = 0, -#define XML_STATUS_ERROR XML_STATUS_ERROR - XML_STATUS_OK = 1, -#define XML_STATUS_OK XML_STATUS_OK - XML_STATUS_SUSPENDED = 2 -#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED -}; - -enum XML_Error { - XML_ERROR_NONE, - XML_ERROR_NO_MEMORY, - XML_ERROR_SYNTAX, - XML_ERROR_NO_ELEMENTS, - XML_ERROR_INVALID_TOKEN, - XML_ERROR_UNCLOSED_TOKEN, - XML_ERROR_PARTIAL_CHAR, - XML_ERROR_TAG_MISMATCH, - XML_ERROR_DUPLICATE_ATTRIBUTE, - XML_ERROR_JUNK_AFTER_DOC_ELEMENT, - XML_ERROR_PARAM_ENTITY_REF, - XML_ERROR_UNDEFINED_ENTITY, - XML_ERROR_RECURSIVE_ENTITY_REF, - XML_ERROR_ASYNC_ENTITY, - XML_ERROR_BAD_CHAR_REF, - XML_ERROR_BINARY_ENTITY_REF, - XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, - XML_ERROR_MISPLACED_XML_PI, - XML_ERROR_UNKNOWN_ENCODING, - XML_ERROR_INCORRECT_ENCODING, - XML_ERROR_UNCLOSED_CDATA_SECTION, - XML_ERROR_EXTERNAL_ENTITY_HANDLING, - XML_ERROR_NOT_STANDALONE, - XML_ERROR_UNEXPECTED_STATE, - XML_ERROR_ENTITY_DECLARED_IN_PE, - XML_ERROR_FEATURE_REQUIRES_XML_DTD, - XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, - /* Added in 1.95.7. */ - XML_ERROR_UNBOUND_PREFIX, - /* Added in 1.95.8. */ - XML_ERROR_UNDECLARING_PREFIX, - XML_ERROR_INCOMPLETE_PE, - XML_ERROR_XML_DECL, - XML_ERROR_TEXT_DECL, - XML_ERROR_PUBLICID, - XML_ERROR_SUSPENDED, - XML_ERROR_NOT_SUSPENDED, - XML_ERROR_ABORTED, - XML_ERROR_FINISHED, - XML_ERROR_SUSPEND_PE, - /* Added in 2.0. */ - XML_ERROR_RESERVED_PREFIX_XML, - XML_ERROR_RESERVED_PREFIX_XMLNS, - XML_ERROR_RESERVED_NAMESPACE_URI -}; - -enum XML_Content_Type { - XML_CTYPE_EMPTY = 1, - XML_CTYPE_ANY, - XML_CTYPE_MIXED, - XML_CTYPE_NAME, - XML_CTYPE_CHOICE, - XML_CTYPE_SEQ -}; - -enum XML_Content_Quant { - XML_CQUANT_NONE, - XML_CQUANT_OPT, - XML_CQUANT_REP, - XML_CQUANT_PLUS -}; - -/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be - XML_CQUANT_NONE, and the other fields will be zero or NULL. - If type == XML_CTYPE_MIXED, then quant will be NONE or REP and - numchildren will contain number of elements that may be mixed in - and children point to an array of XML_Content cells that will be - all of XML_CTYPE_NAME type with no quantification. - - If type == XML_CTYPE_NAME, then the name points to the name, and - the numchildren field will be zero and children will be NULL. The - quant fields indicates any quantifiers placed on the name. - - CHOICE and SEQ will have name NULL, the number of children in - numchildren and children will point, recursively, to an array - of XML_Content cells. - - The EMPTY, ANY, and MIXED types will only occur at top level. -*/ - -typedef struct XML_cp XML_Content; - -struct XML_cp { - enum XML_Content_Type type; - enum XML_Content_Quant quant; - XML_Char * name; - unsigned int numchildren; - XML_Content * children; -}; - - -/* This is called for an element declaration. See above for - description of the model argument. It's the caller's responsibility - to free model when finished with it. -*/ -typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, - const XML_Char *name, - XML_Content *model); - -XMLPARSEAPI(void) -XML_SetElementDeclHandler(XML_Parser parser, - XML_ElementDeclHandler eldecl); - -/* The Attlist declaration handler is called for *each* attribute. So - a single Attlist declaration with multiple attributes declared will - generate multiple calls to this handler. The "default" parameter - may be NULL in the case of the "#IMPLIED" or "#REQUIRED" - keyword. The "isrequired" parameter will be true and the default - value will be NULL in the case of "#REQUIRED". If "isrequired" is - true and default is non-NULL, then this is a "#FIXED" default. -*/ -typedef void (XMLCALL *XML_AttlistDeclHandler) ( - void *userData, - const XML_Char *elname, - const XML_Char *attname, - const XML_Char *att_type, - const XML_Char *dflt, - int isrequired); - -XMLPARSEAPI(void) -XML_SetAttlistDeclHandler(XML_Parser parser, - XML_AttlistDeclHandler attdecl); - -/* The XML declaration handler is called for *both* XML declarations - and text declarations. The way to distinguish is that the version - parameter will be NULL for text declarations. The encoding - parameter may be NULL for XML declarations. The standalone - parameter will be -1, 0, or 1 indicating respectively that there - was no standalone parameter in the declaration, that it was given - as no, or that it was given as yes. -*/ -typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, - const XML_Char *version, - const XML_Char *encoding, - int standalone); - -XMLPARSEAPI(void) -XML_SetXmlDeclHandler(XML_Parser parser, - XML_XmlDeclHandler xmldecl); - - -typedef struct { - void *(*malloc_fcn)(size_t size); - void *(*realloc_fcn)(void *ptr, size_t size); - void (*free_fcn)(void *ptr); -} XML_Memory_Handling_Suite; - -/* Constructs a new parser; encoding is the encoding specified by the - external protocol or NULL if there is none specified. -*/ -XMLPARSEAPI(XML_Parser) -XML_ParserCreate(const XML_Char *encoding); - -/* Constructs a new parser and namespace processor. Element type - names and attribute names that belong to a namespace will be - expanded; unprefixed attribute names are never expanded; unprefixed - element type names are expanded only if there is a default - namespace. The expanded name is the concatenation of the namespace - URI, the namespace separator character, and the local part of the - name. If the namespace separator is '\0' then the namespace URI - and the local part will be concatenated without any separator. - It is a programming error to use the separator '\0' with namespace - triplets (see XML_SetReturnNSTriplet). -*/ -XMLPARSEAPI(XML_Parser) -XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); - - -/* Constructs a new parser using the memory management suite referred to - by memsuite. If memsuite is NULL, then use the standard library memory - suite. If namespaceSeparator is non-NULL it creates a parser with - namespace processing as described above. The character pointed at - will serve as the namespace separator. - - All further memory operations used for the created parser will come from - the given suite. -*/ -XMLPARSEAPI(XML_Parser) -XML_ParserCreate_MM(const XML_Char *encoding, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *namespaceSeparator); - -/* Prepare a parser object to be re-used. This is particularly - valuable when memory allocation overhead is disproportionatly high, - such as when a large number of small documnents need to be parsed. - All handlers are cleared from the parser, except for the - unknownEncodingHandler. The parser's external state is re-initialized - except for the values of ns and ns_triplets. - - Added in Expat 1.95.3. -*/ -XMLPARSEAPI(XML_Bool) -XML_ParserReset(XML_Parser parser, const XML_Char *encoding); - -/* atts is array of name/value pairs, terminated by 0; - names and values are 0 terminated. -*/ -typedef void (XMLCALL *XML_StartElementHandler) (void *userData, - const XML_Char *name, - const XML_Char **atts); - -typedef void (XMLCALL *XML_EndElementHandler) (void *userData, - const XML_Char *name); - - -/* s is not 0 terminated. */ -typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, - const XML_Char *s, - int len); - -/* target and data are 0 terminated */ -typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( - void *userData, - const XML_Char *target, - const XML_Char *data); - -/* data is 0 terminated */ -typedef void (XMLCALL *XML_CommentHandler) (void *userData, - const XML_Char *data); - -typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); -typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); - -/* This is called for any characters in the XML document for which - there is no applicable handler. This includes both characters that - are part of markup which is of a kind that is not reported - (comments, markup declarations), or characters that are part of a - construct which could be reported but for which no handler has been - supplied. The characters are passed exactly as they were in the XML - document except that they will be encoded in UTF-8 or UTF-16. - Line boundaries are not normalized. Note that a byte order mark - character is not passed to the default handler. There are no - guarantees about how characters are divided between calls to the - default handler: for example, a comment might be split between - multiple calls. -*/ -typedef void (XMLCALL *XML_DefaultHandler) (void *userData, - const XML_Char *s, - int len); - -/* This is called for the start of the DOCTYPE declaration, before - any DTD or internal subset is parsed. -*/ -typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( - void *userData, - const XML_Char *doctypeName, - const XML_Char *sysid, - const XML_Char *pubid, - int has_internal_subset); - -/* This is called for the start of the DOCTYPE declaration when the - closing > is encountered, but after processing any external - subset. -*/ -typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); - -/* This is called for entity declarations. The is_parameter_entity - argument will be non-zero if the entity is a parameter entity, zero - otherwise. - - For internal entities (), value will - be non-NULL and systemId, publicID, and notationName will be NULL. - The value string is NOT nul-terminated; the length is provided in - the value_length argument. Since it is legal to have zero-length - values, do not use this argument to test for internal entities. - - For external entities, value will be NULL and systemId will be - non-NULL. The publicId argument will be NULL unless a public - identifier was provided. The notationName argument will have a - non-NULL value only for unparsed entity declarations. - - Note that is_parameter_entity can't be changed to XML_Bool, since - that would break binary compatibility. -*/ -typedef void (XMLCALL *XML_EntityDeclHandler) ( - void *userData, - const XML_Char *entityName, - int is_parameter_entity, - const XML_Char *value, - int value_length, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName); - -XMLPARSEAPI(void) -XML_SetEntityDeclHandler(XML_Parser parser, - XML_EntityDeclHandler handler); - -/* OBSOLETE -- OBSOLETE -- OBSOLETE - This handler has been superceded by the EntityDeclHandler above. - It is provided here for backward compatibility. - - This is called for a declaration of an unparsed (NDATA) entity. - The base argument is whatever was set by XML_SetBase. The - entityName, systemId and notationName arguments will never be - NULL. The other arguments may be. -*/ -typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( - void *userData, - const XML_Char *entityName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName); - -/* This is called for a declaration of notation. The base argument is - whatever was set by XML_SetBase. The notationName will never be - NULL. The other arguments can be. -*/ -typedef void (XMLCALL *XML_NotationDeclHandler) ( - void *userData, - const XML_Char *notationName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); - -/* When namespace processing is enabled, these are called once for - each namespace declaration. The call to the start and end element - handlers occur between the calls to the start and end namespace - declaration handlers. For an xmlns attribute, prefix will be - NULL. For an xmlns="" attribute, uri will be NULL. -*/ -typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( - void *userData, - const XML_Char *prefix, - const XML_Char *uri); - -typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( - void *userData, - const XML_Char *prefix); - -/* This is called if the document is not standalone, that is, it has an - external subset or a reference to a parameter entity, but does not - have standalone="yes". If this handler returns XML_STATUS_ERROR, - then processing will not continue, and the parser will return a - XML_ERROR_NOT_STANDALONE error. - If parameter entity parsing is enabled, then in addition to the - conditions above this handler will only be called if the referenced - entity was actually read. -*/ -typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); - -/* This is called for a reference to an external parsed general - entity. The referenced entity is not automatically parsed. The - application can parse it immediately or later using - XML_ExternalEntityParserCreate. - - The parser argument is the parser parsing the entity containing the - reference; it can be passed as the parser argument to - XML_ExternalEntityParserCreate. The systemId argument is the - system identifier as specified in the entity declaration; it will - not be NULL. - - The base argument is the system identifier that should be used as - the base for resolving systemId if systemId was relative; this is - set by XML_SetBase; it may be NULL. - - The publicId argument is the public identifier as specified in the - entity declaration, or NULL if none was specified; the whitespace - in the public identifier will have been normalized as required by - the XML spec. - - The context argument specifies the parsing context in the format - expected by the context argument to XML_ExternalEntityParserCreate; - context is valid only until the handler returns, so if the - referenced entity is to be parsed later, it must be copied. - context is NULL only when the entity is a parameter entity. - - The handler should return XML_STATUS_ERROR if processing should not - continue because of a fatal error in the handling of the external - entity. In this case the calling parser will return an - XML_ERROR_EXTERNAL_ENTITY_HANDLING error. - - Note that unlike other handlers the first argument is the parser, - not userData. -*/ -typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( - XML_Parser parser, - const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); - -/* This is called in two situations: - 1) An entity reference is encountered for which no declaration - has been read *and* this is not an error. - 2) An internal entity reference is read, but not expanded, because - XML_SetDefaultHandler has been called. - Note: skipped parameter entities in declarations and skipped general - entities in attribute values cannot be reported, because - the event would be out of sync with the reporting of the - declarations or attribute values -*/ -typedef void (XMLCALL *XML_SkippedEntityHandler) ( - void *userData, - const XML_Char *entityName, - int is_parameter_entity); - -/* This structure is filled in by the XML_UnknownEncodingHandler to - provide information to the parser about encodings that are unknown - to the parser. - - The map[b] member gives information about byte sequences whose - first byte is b. - - If map[b] is c where c is >= 0, then b by itself encodes the - Unicode scalar value c. - - If map[b] is -1, then the byte sequence is malformed. - - If map[b] is -n, where n >= 2, then b is the first byte of an - n-byte sequence that encodes a single Unicode scalar value. - - The data member will be passed as the first argument to the convert - function. - - The convert function is used to convert multibyte sequences; s will - point to a n-byte sequence where map[(unsigned char)*s] == -n. The - convert function must return the Unicode scalar value represented - by this byte sequence or -1 if the byte sequence is malformed. - - The convert function may be NULL if the encoding is a single-byte - encoding, that is if map[b] >= -1 for all bytes b. - - When the parser is finished with the encoding, then if release is - not NULL, it will call release passing it the data member; once - release has been called, the convert function will not be called - again. - - Expat places certain restrictions on the encodings that are supported - using this mechanism. - - 1. Every ASCII character that can appear in a well-formed XML document, - other than the characters - - $@\^`{}~ - - must be represented by a single byte, and that byte must be the - same byte that represents that character in ASCII. - - 2. No character may require more than 4 bytes to encode. - - 3. All characters encoded must have Unicode scalar values <= - 0xFFFF, (i.e., characters that would be encoded by surrogates in - UTF-16 are not allowed). Note that this restriction doesn't - apply to the built-in support for UTF-8 and UTF-16. - - 4. No Unicode character may be encoded by more than one distinct - sequence of bytes. -*/ -typedef struct { - int map[256]; - void *data; - int (XMLCALL *convert)(void *data, const char *s); - void (XMLCALL *release)(void *data); -} XML_Encoding; - -/* This is called for an encoding that is unknown to the parser. - - The encodingHandlerData argument is that which was passed as the - second argument to XML_SetUnknownEncodingHandler. - - The name argument gives the name of the encoding as specified in - the encoding declaration. - - If the callback can provide information about the encoding, it must - fill in the XML_Encoding structure, and return XML_STATUS_OK. - Otherwise it must return XML_STATUS_ERROR. - - If info does not describe a suitable encoding, then the parser will - return an XML_UNKNOWN_ENCODING error. -*/ -typedef int (XMLCALL *XML_UnknownEncodingHandler) ( - void *encodingHandlerData, - const XML_Char *name, - XML_Encoding *info); - -XMLPARSEAPI(void) -XML_SetElementHandler(XML_Parser parser, - XML_StartElementHandler start, - XML_EndElementHandler end); - -XMLPARSEAPI(void) -XML_SetStartElementHandler(XML_Parser parser, - XML_StartElementHandler handler); - -XMLPARSEAPI(void) -XML_SetEndElementHandler(XML_Parser parser, - XML_EndElementHandler handler); - -XMLPARSEAPI(void) -XML_SetCharacterDataHandler(XML_Parser parser, - XML_CharacterDataHandler handler); - -XMLPARSEAPI(void) -XML_SetProcessingInstructionHandler(XML_Parser parser, - XML_ProcessingInstructionHandler handler); -XMLPARSEAPI(void) -XML_SetCommentHandler(XML_Parser parser, - XML_CommentHandler handler); - -XMLPARSEAPI(void) -XML_SetCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start, - XML_EndCdataSectionHandler end); - -XMLPARSEAPI(void) -XML_SetStartCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start); - -XMLPARSEAPI(void) -XML_SetEndCdataSectionHandler(XML_Parser parser, - XML_EndCdataSectionHandler end); - -/* This sets the default handler and also inhibits expansion of - internal entities. These entity references will be passed to the - default handler, or to the skipped entity handler, if one is set. -*/ -XMLPARSEAPI(void) -XML_SetDefaultHandler(XML_Parser parser, - XML_DefaultHandler handler); - -/* This sets the default handler but does not inhibit expansion of - internal entities. The entity reference will not be passed to the - default handler. -*/ -XMLPARSEAPI(void) -XML_SetDefaultHandlerExpand(XML_Parser parser, - XML_DefaultHandler handler); - -XMLPARSEAPI(void) -XML_SetDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start, - XML_EndDoctypeDeclHandler end); - -XMLPARSEAPI(void) -XML_SetStartDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start); - -XMLPARSEAPI(void) -XML_SetEndDoctypeDeclHandler(XML_Parser parser, - XML_EndDoctypeDeclHandler end); - -XMLPARSEAPI(void) -XML_SetUnparsedEntityDeclHandler(XML_Parser parser, - XML_UnparsedEntityDeclHandler handler); - -XMLPARSEAPI(void) -XML_SetNotationDeclHandler(XML_Parser parser, - XML_NotationDeclHandler handler); - -XMLPARSEAPI(void) -XML_SetNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start, - XML_EndNamespaceDeclHandler end); - -XMLPARSEAPI(void) -XML_SetStartNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start); - -XMLPARSEAPI(void) -XML_SetEndNamespaceDeclHandler(XML_Parser parser, - XML_EndNamespaceDeclHandler end); - -XMLPARSEAPI(void) -XML_SetNotStandaloneHandler(XML_Parser parser, - XML_NotStandaloneHandler handler); - -XMLPARSEAPI(void) -XML_SetExternalEntityRefHandler(XML_Parser parser, - XML_ExternalEntityRefHandler handler); - -/* If a non-NULL value for arg is specified here, then it will be - passed as the first argument to the external entity ref handler - instead of the parser object. -*/ -XMLPARSEAPI(void) -XML_SetExternalEntityRefHandlerArg(XML_Parser parser, - void *arg); - -XMLPARSEAPI(void) -XML_SetSkippedEntityHandler(XML_Parser parser, - XML_SkippedEntityHandler handler); - -XMLPARSEAPI(void) -XML_SetUnknownEncodingHandler(XML_Parser parser, - XML_UnknownEncodingHandler handler, - void *encodingHandlerData); - -/* This can be called within a handler for a start element, end - element, processing instruction or character data. It causes the - corresponding markup to be passed to the default handler. -*/ -XMLPARSEAPI(void) -XML_DefaultCurrent(XML_Parser parser); - -/* If do_nst is non-zero, and namespace processing is in effect, and - a name has a prefix (i.e. an explicit namespace qualifier) then - that name is returned as a triplet in a single string separated by - the separator character specified when the parser was created: URI - + sep + local_name + sep + prefix. - - If do_nst is zero, then namespace information is returned in the - default manner (URI + sep + local_name) whether or not the name - has a prefix. - - Note: Calling XML_SetReturnNSTriplet after XML_Parse or - XML_ParseBuffer has no effect. -*/ - -XMLPARSEAPI(void) -XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); - -/* This value is passed as the userData argument to callbacks. */ -XMLPARSEAPI(void) -XML_SetUserData(XML_Parser parser, void *userData); - -/* Returns the last value set by XML_SetUserData or NULL. */ -#define XML_GetUserData(parser) (*(void **)(parser)) - -/* This is equivalent to supplying an encoding argument to - XML_ParserCreate. On success XML_SetEncoding returns non-zero, - zero otherwise. - Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer - has no effect and returns XML_STATUS_ERROR. -*/ -XMLPARSEAPI(enum XML_Status) -XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); - -/* If this function is called, then the parser will be passed as the - first argument to callbacks instead of userData. The userData will - still be accessible using XML_GetUserData. -*/ -XMLPARSEAPI(void) -XML_UseParserAsHandlerArg(XML_Parser parser); - -/* If useDTD == XML_TRUE is passed to this function, then the parser - will assume that there is an external subset, even if none is - specified in the document. In such a case the parser will call the - externalEntityRefHandler with a value of NULL for the systemId - argument (the publicId and context arguments will be NULL as well). - Note: For the purpose of checking WFC: Entity Declared, passing - useDTD == XML_TRUE will make the parser behave as if the document - had a DTD with an external subset. - Note: If this function is called, then this must be done before - the first call to XML_Parse or XML_ParseBuffer, since it will - have no effect after that. Returns - XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. - Note: If the document does not have a DOCTYPE declaration at all, - then startDoctypeDeclHandler and endDoctypeDeclHandler will not - be called, despite an external subset being parsed. - Note: If XML_DTD is not defined when Expat is compiled, returns - XML_ERROR_FEATURE_REQUIRES_XML_DTD. -*/ -XMLPARSEAPI(enum XML_Error) -XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); - - -/* Sets the base to be used for resolving relative URIs in system - identifiers in declarations. Resolving relative identifiers is - left to the application: this value will be passed through as the - base argument to the XML_ExternalEntityRefHandler, - XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base - argument will be copied. Returns XML_STATUS_ERROR if out of memory, - XML_STATUS_OK otherwise. -*/ -XMLPARSEAPI(enum XML_Status) -XML_SetBase(XML_Parser parser, const XML_Char *base); - -XMLPARSEAPI(const XML_Char *) -XML_GetBase(XML_Parser parser); - -/* Returns the number of the attribute/value pairs passed in last call - to the XML_StartElementHandler that were specified in the start-tag - rather than defaulted. Each attribute/value pair counts as 2; thus - this correspondds to an index into the atts array passed to the - XML_StartElementHandler. -*/ -XMLPARSEAPI(int) -XML_GetSpecifiedAttributeCount(XML_Parser parser); - -/* Returns the index of the ID attribute passed in the last call to - XML_StartElementHandler, or -1 if there is no ID attribute. Each - attribute/value pair counts as 2; thus this correspondds to an - index into the atts array passed to the XML_StartElementHandler. -*/ -XMLPARSEAPI(int) -XML_GetIdAttributeIndex(XML_Parser parser); - -/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is - detected. The last call to XML_Parse must have isFinal true; len - may be zero for this call (or any other). - - Though the return values for these functions has always been - described as a Boolean value, the implementation, at least for the - 1.95.x series, has always returned exactly one of the XML_Status - values. -*/ -XMLPARSEAPI(enum XML_Status) -XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); - -XMLPARSEAPI(void *) -XML_GetBuffer(XML_Parser parser, int len); - -XMLPARSEAPI(enum XML_Status) -XML_ParseBuffer(XML_Parser parser, int len, int isFinal); - -/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. - Must be called from within a call-back handler, except when aborting - (resumable = 0) an already suspended parser. Some call-backs may - still follow because they would otherwise get lost. Examples: - - endElementHandler() for empty elements when stopped in - startElementHandler(), - - endNameSpaceDeclHandler() when stopped in endElementHandler(), - and possibly others. - - Can be called from most handlers, including DTD related call-backs, - except when parsing an external parameter entity and resumable != 0. - Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. - Possible error codes: - - XML_ERROR_SUSPENDED: when suspending an already suspended parser. - - XML_ERROR_FINISHED: when the parser has already finished. - - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. - - When resumable != 0 (true) then parsing is suspended, that is, - XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. - Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() - return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. - - *Note*: - This will be applied to the current parser instance only, that is, if - there is a parent parser then it will continue parsing when the - externalEntityRefHandler() returns. It is up to the implementation of - the externalEntityRefHandler() to call XML_StopParser() on the parent - parser (recursively), if one wants to stop parsing altogether. - - When suspended, parsing can be resumed by calling XML_ResumeParser(). -*/ -XMLPARSEAPI(enum XML_Status) -XML_StopParser(XML_Parser parser, XML_Bool resumable); - -/* Resumes parsing after it has been suspended with XML_StopParser(). - Must not be called from within a handler call-back. Returns same - status codes as XML_Parse() or XML_ParseBuffer(). - Additional error code XML_ERROR_NOT_SUSPENDED possible. - - *Note*: - This must be called on the most deeply nested child parser instance - first, and on its parent parser only after the child parser has finished, - to be applied recursively until the document entity's parser is restarted. - That is, the parent parser will not resume by itself and it is up to the - application to call XML_ResumeParser() on it at the appropriate moment. -*/ -XMLPARSEAPI(enum XML_Status) -XML_ResumeParser(XML_Parser parser); - -enum XML_Parsing { - XML_INITIALIZED, - XML_PARSING, - XML_FINISHED, - XML_SUSPENDED -}; - -typedef struct { - enum XML_Parsing parsing; - XML_Bool finalBuffer; -} XML_ParsingStatus; - -/* Returns status of parser with respect to being initialized, parsing, - finished, or suspended and processing the final buffer. - XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, - XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED -*/ -XMLPARSEAPI(void) -XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); - -/* Creates an XML_Parser object that can parse an external general - entity; context is a '\0'-terminated string specifying the parse - context; encoding is a '\0'-terminated string giving the name of - the externally specified encoding, or NULL if there is no - externally specified encoding. The context string consists of a - sequence of tokens separated by formfeeds (\f); a token consisting - of a name specifies that the general entity of the name is open; a - token of the form prefix=uri specifies the namespace for a - particular prefix; a token of the form =uri specifies the default - namespace. This can be called at any point after the first call to - an ExternalEntityRefHandler so longer as the parser has not yet - been freed. The new parser is completely independent and may - safely be used in a separate thread. The handlers and userData are - initialized from the parser argument. Returns NULL if out of memory. - Otherwise returns a new XML_Parser object. -*/ -XMLPARSEAPI(XML_Parser) -XML_ExternalEntityParserCreate(XML_Parser parser, - const XML_Char *context, - const XML_Char *encoding); - -enum XML_ParamEntityParsing { - XML_PARAM_ENTITY_PARSING_NEVER, - XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, - XML_PARAM_ENTITY_PARSING_ALWAYS -}; - -/* Controls parsing of parameter entities (including the external DTD - subset). If parsing of parameter entities is enabled, then - references to external parameter entities (including the external - DTD subset) will be passed to the handler set with - XML_SetExternalEntityRefHandler. The context passed will be 0. - - Unlike external general entities, external parameter entities can - only be parsed synchronously. If the external parameter entity is - to be parsed, it must be parsed during the call to the external - entity ref handler: the complete sequence of - XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and - XML_ParserFree calls must be made during this call. After - XML_ExternalEntityParserCreate has been called to create the parser - for the external parameter entity (context must be 0 for this - call), it is illegal to make any calls on the old parser until - XML_ParserFree has been called on the newly created parser. - If the library has been compiled without support for parameter - entity parsing (ie without XML_DTD being defined), then - XML_SetParamEntityParsing will return 0 if parsing of parameter - entities is requested; otherwise it will return non-zero. - Note: If XML_SetParamEntityParsing is called after XML_Parse or - XML_ParseBuffer, then it has no effect and will always return 0. -*/ -XMLPARSEAPI(int) -XML_SetParamEntityParsing(XML_Parser parser, - enum XML_ParamEntityParsing parsing); - -/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then - XML_GetErrorCode returns information about the error. -*/ -XMLPARSEAPI(enum XML_Error) -XML_GetErrorCode(XML_Parser parser); - -/* These functions return information about the current parse - location. They may be called from any callback called to report - some parse event; in this case the location is the location of the - first of the sequence of characters that generated the event. When - called from callbacks generated by declarations in the document - prologue, the location identified isn't as neatly defined, but will - be within the relevant markup. When called outside of the callback - functions, the position indicated will be just past the last parse - event (regardless of whether there was an associated callback). - - They may also be called after returning from a call to XML_Parse - or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then - the location is the location of the character at which the error - was detected; otherwise the location is the location of the last - parse event, as described above. -*/ -XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); -XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); -XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); - -/* Return the number of bytes in the current event. - Returns 0 if the event is in an internal entity. -*/ -XMLPARSEAPI(int) -XML_GetCurrentByteCount(XML_Parser parser); - -/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets - the integer pointed to by offset to the offset within this buffer - of the current parse position, and sets the integer pointed to by size - to the size of this buffer (the number of input bytes). Otherwise - returns a NULL pointer. Also returns a NULL pointer if a parse isn't - active. - - NOTE: The character pointer returned should not be used outside - the handler that makes the call. -*/ -XMLPARSEAPI(const char *) -XML_GetInputContext(XML_Parser parser, - int *offset, - int *size); - -/* For backwards compatibility with previous versions. */ -#define XML_GetErrorLineNumber XML_GetCurrentLineNumber -#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber -#define XML_GetErrorByteIndex XML_GetCurrentByteIndex - -/* Frees the content model passed to the element declaration handler */ -XMLPARSEAPI(void) -XML_FreeContentModel(XML_Parser parser, XML_Content *model); - -/* Exposing the memory handling functions used in Expat */ -XMLPARSEAPI(void *) -XML_MemMalloc(XML_Parser parser, size_t size); - -XMLPARSEAPI(void *) -XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); - -XMLPARSEAPI(void) -XML_MemFree(XML_Parser parser, void *ptr); - -/* Frees memory used by the parser. */ -XMLPARSEAPI(void) -XML_ParserFree(XML_Parser parser); - -/* Returns a string describing the error. */ -XMLPARSEAPI(const XML_LChar *) -XML_ErrorString(enum XML_Error code); - -/* Return a string containing the version number of this expat */ -XMLPARSEAPI(const XML_LChar *) -XML_ExpatVersion(void); - -typedef struct { - int major; - int minor; - int micro; -} XML_Expat_Version; - -/* Return an XML_Expat_Version structure containing numeric version - number information for this version of expat. -*/ -XMLPARSEAPI(XML_Expat_Version) -XML_ExpatVersionInfo(void); - -/* Added in Expat 1.95.5. */ -enum XML_FeatureEnum { - XML_FEATURE_END = 0, - XML_FEATURE_UNICODE, - XML_FEATURE_UNICODE_WCHAR_T, - XML_FEATURE_DTD, - XML_FEATURE_CONTEXT_BYTES, - XML_FEATURE_MIN_SIZE, - XML_FEATURE_SIZEOF_XML_CHAR, - XML_FEATURE_SIZEOF_XML_LCHAR, - XML_FEATURE_NS, - XML_FEATURE_LARGE_SIZE - /* Additional features must be added to the end of this enum. */ -}; - -typedef struct { - enum XML_FeatureEnum feature; - const XML_LChar *name; - long int value; -} XML_Feature; - -XMLPARSEAPI(const XML_Feature *) -XML_GetFeatureList(void); - - -/* Expat follows the GNU/Linux convention of odd number minor version for - beta/development releases and even number minor version for stable - releases. Micro is bumped with each release, and set to 0 with each - change to major or minor version. -*/ -#define XML_MAJOR_VERSION 2 -#define XML_MINOR_VERSION 0 -#define XML_MICRO_VERSION 1 - -#ifdef __cplusplus -} -#endif - -#endif /* not Expat_INCLUDED */ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_INCLUDED +#define Expat_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler +#define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler +#define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler +#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg +#endif + +#include +#include "expat_external.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct XML_ParserStruct; +typedef struct XML_ParserStruct *XML_Parser; + +/* Should this be defined using stdbool.h when C99 is available? */ +typedef unsigned char XML_Bool; +#define XML_TRUE ((XML_Bool) 1) +#define XML_FALSE ((XML_Bool) 0) + +/* The XML_Status enum gives the possible return values for several + API functions. The preprocessor #defines are included so this + stanza can be added to code that still needs to support older + versions of Expat 1.95.x: + + #ifndef XML_STATUS_OK + #define XML_STATUS_OK 1 + #define XML_STATUS_ERROR 0 + #endif + + Otherwise, the #define hackery is quite ugly and would have been + dropped. +*/ +enum XML_Status { + XML_STATUS_ERROR = 0, +#define XML_STATUS_ERROR XML_STATUS_ERROR + XML_STATUS_OK = 1, +#define XML_STATUS_OK XML_STATUS_OK + XML_STATUS_SUSPENDED = 2 +#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED +}; + +enum XML_Error { + XML_ERROR_NONE, + XML_ERROR_NO_MEMORY, + XML_ERROR_SYNTAX, + XML_ERROR_NO_ELEMENTS, + XML_ERROR_INVALID_TOKEN, + XML_ERROR_UNCLOSED_TOKEN, + XML_ERROR_PARTIAL_CHAR, + XML_ERROR_TAG_MISMATCH, + XML_ERROR_DUPLICATE_ATTRIBUTE, + XML_ERROR_JUNK_AFTER_DOC_ELEMENT, + XML_ERROR_PARAM_ENTITY_REF, + XML_ERROR_UNDEFINED_ENTITY, + XML_ERROR_RECURSIVE_ENTITY_REF, + XML_ERROR_ASYNC_ENTITY, + XML_ERROR_BAD_CHAR_REF, + XML_ERROR_BINARY_ENTITY_REF, + XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, + XML_ERROR_MISPLACED_XML_PI, + XML_ERROR_UNKNOWN_ENCODING, + XML_ERROR_INCORRECT_ENCODING, + XML_ERROR_UNCLOSED_CDATA_SECTION, + XML_ERROR_EXTERNAL_ENTITY_HANDLING, + XML_ERROR_NOT_STANDALONE, + XML_ERROR_UNEXPECTED_STATE, + XML_ERROR_ENTITY_DECLARED_IN_PE, + XML_ERROR_FEATURE_REQUIRES_XML_DTD, + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, + /* Added in 1.95.7. */ + XML_ERROR_UNBOUND_PREFIX, + /* Added in 1.95.8. */ + XML_ERROR_UNDECLARING_PREFIX, + XML_ERROR_INCOMPLETE_PE, + XML_ERROR_XML_DECL, + XML_ERROR_TEXT_DECL, + XML_ERROR_PUBLICID, + XML_ERROR_SUSPENDED, + XML_ERROR_NOT_SUSPENDED, + XML_ERROR_ABORTED, + XML_ERROR_FINISHED, + XML_ERROR_SUSPEND_PE, + /* Added in 2.0. */ + XML_ERROR_RESERVED_PREFIX_XML, + XML_ERROR_RESERVED_PREFIX_XMLNS, + XML_ERROR_RESERVED_NAMESPACE_URI +}; + +enum XML_Content_Type { + XML_CTYPE_EMPTY = 1, + XML_CTYPE_ANY, + XML_CTYPE_MIXED, + XML_CTYPE_NAME, + XML_CTYPE_CHOICE, + XML_CTYPE_SEQ +}; + +enum XML_Content_Quant { + XML_CQUANT_NONE, + XML_CQUANT_OPT, + XML_CQUANT_REP, + XML_CQUANT_PLUS +}; + +/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be + XML_CQUANT_NONE, and the other fields will be zero or NULL. + If type == XML_CTYPE_MIXED, then quant will be NONE or REP and + numchildren will contain number of elements that may be mixed in + and children point to an array of XML_Content cells that will be + all of XML_CTYPE_NAME type with no quantification. + + If type == XML_CTYPE_NAME, then the name points to the name, and + the numchildren field will be zero and children will be NULL. The + quant fields indicates any quantifiers placed on the name. + + CHOICE and SEQ will have name NULL, the number of children in + numchildren and children will point, recursively, to an array + of XML_Content cells. + + The EMPTY, ANY, and MIXED types will only occur at top level. +*/ + +typedef struct XML_cp XML_Content; + +struct XML_cp { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + XML_Char * name; + unsigned int numchildren; + XML_Content * children; +}; + + +/* This is called for an element declaration. See above for + description of the model argument. It's the caller's responsibility + to free model when finished with it. +*/ +typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, + const XML_Char *name, + XML_Content *model); + +XMLPARSEAPI(void) +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl); + +/* The Attlist declaration handler is called for *each* attribute. So + a single Attlist declaration with multiple attributes declared will + generate multiple calls to this handler. The "default" parameter + may be NULL in the case of the "#IMPLIED" or "#REQUIRED" + keyword. The "isrequired" parameter will be true and the default + value will be NULL in the case of "#REQUIRED". If "isrequired" is + true and default is non-NULL, then this is a "#FIXED" default. +*/ +typedef void (XMLCALL *XML_AttlistDeclHandler) ( + void *userData, + const XML_Char *elname, + const XML_Char *attname, + const XML_Char *att_type, + const XML_Char *dflt, + int isrequired); + +XMLPARSEAPI(void) +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl); + +/* The XML declaration handler is called for *both* XML declarations + and text declarations. The way to distinguish is that the version + parameter will be NULL for text declarations. The encoding + parameter may be NULL for XML declarations. The standalone + parameter will be -1, 0, or 1 indicating respectively that there + was no standalone parameter in the declaration, that it was given + as no, or that it was given as yes. +*/ +typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); + +XMLPARSEAPI(void) +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler xmldecl); + + +typedef struct { + void *(*malloc_fcn)(size_t size); + void *(*realloc_fcn)(void *ptr, size_t size); + void (*free_fcn)(void *ptr); +} XML_Memory_Handling_Suite; + +/* Constructs a new parser; encoding is the encoding specified by the + external protocol or NULL if there is none specified. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate(const XML_Char *encoding); + +/* Constructs a new parser and namespace processor. Element type + names and attribute names that belong to a namespace will be + expanded; unprefixed attribute names are never expanded; unprefixed + element type names are expanded only if there is a default + namespace. The expanded name is the concatenation of the namespace + URI, the namespace separator character, and the local part of the + name. If the namespace separator is '\0' then the namespace URI + and the local part will be concatenated without any separator. + It is a programming error to use the separator '\0' with namespace + triplets (see XML_SetReturnNSTriplet). +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); + + +/* Constructs a new parser using the memory management suite referred to + by memsuite. If memsuite is NULL, then use the standard library memory + suite. If namespaceSeparator is non-NULL it creates a parser with + namespace processing as described above. The character pointed at + will serve as the namespace separator. + + All further memory operations used for the created parser will come from + the given suite. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate_MM(const XML_Char *encoding, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); + +/* Prepare a parser object to be re-used. This is particularly + valuable when memory allocation overhead is disproportionatly high, + such as when a large number of small documnents need to be parsed. + All handlers are cleared from the parser, except for the + unknownEncodingHandler. The parser's external state is re-initialized + except for the values of ns and ns_triplets. + + Added in Expat 1.95.3. +*/ +XMLPARSEAPI(XML_Bool) +XML_ParserReset(XML_Parser parser, const XML_Char *encoding); + +/* atts is array of name/value pairs, terminated by 0; + names and values are 0 terminated. +*/ +typedef void (XMLCALL *XML_StartElementHandler) (void *userData, + const XML_Char *name, + const XML_Char **atts); + +typedef void (XMLCALL *XML_EndElementHandler) (void *userData, + const XML_Char *name); + + +/* s is not 0 terminated. */ +typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, + const XML_Char *s, + int len); + +/* target and data are 0 terminated */ +typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( + void *userData, + const XML_Char *target, + const XML_Char *data); + +/* data is 0 terminated */ +typedef void (XMLCALL *XML_CommentHandler) (void *userData, + const XML_Char *data); + +typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); +typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); + +/* This is called for any characters in the XML document for which + there is no applicable handler. This includes both characters that + are part of markup which is of a kind that is not reported + (comments, markup declarations), or characters that are part of a + construct which could be reported but for which no handler has been + supplied. The characters are passed exactly as they were in the XML + document except that they will be encoded in UTF-8 or UTF-16. + Line boundaries are not normalized. Note that a byte order mark + character is not passed to the default handler. There are no + guarantees about how characters are divided between calls to the + default handler: for example, a comment might be split between + multiple calls. +*/ +typedef void (XMLCALL *XML_DefaultHandler) (void *userData, + const XML_Char *s, + int len); + +/* This is called for the start of the DOCTYPE declaration, before + any DTD or internal subset is parsed. +*/ +typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( + void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); + +/* This is called for the start of the DOCTYPE declaration when the + closing > is encountered, but after processing any external + subset. +*/ +typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); + +/* This is called for entity declarations. The is_parameter_entity + argument will be non-zero if the entity is a parameter entity, zero + otherwise. + + For internal entities (), value will + be non-NULL and systemId, publicID, and notationName will be NULL. + The value string is NOT nul-terminated; the length is provided in + the value_length argument. Since it is legal to have zero-length + values, do not use this argument to test for internal entities. + + For external entities, value will be NULL and systemId will be + non-NULL. The publicId argument will be NULL unless a public + identifier was provided. The notationName argument will have a + non-NULL value only for unparsed entity declarations. + + Note that is_parameter_entity can't be changed to XML_Bool, since + that would break binary compatibility. +*/ +typedef void (XMLCALL *XML_EntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity, + const XML_Char *value, + int value_length, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +XMLPARSEAPI(void) +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler); + +/* OBSOLETE -- OBSOLETE -- OBSOLETE + This handler has been superceded by the EntityDeclHandler above. + It is provided here for backward compatibility. + + This is called for a declaration of an unparsed (NDATA) entity. + The base argument is whatever was set by XML_SetBase. The + entityName, systemId and notationName arguments will never be + NULL. The other arguments may be. +*/ +typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +/* This is called for a declaration of notation. The base argument is + whatever was set by XML_SetBase. The notationName will never be + NULL. The other arguments can be. +*/ +typedef void (XMLCALL *XML_NotationDeclHandler) ( + void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* When namespace processing is enabled, these are called once for + each namespace declaration. The call to the start and end element + handlers occur between the calls to the start and end namespace + declaration handlers. For an xmlns attribute, prefix will be + NULL. For an xmlns="" attribute, uri will be NULL. +*/ +typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix); + +/* This is called if the document is not standalone, that is, it has an + external subset or a reference to a parameter entity, but does not + have standalone="yes". If this handler returns XML_STATUS_ERROR, + then processing will not continue, and the parser will return a + XML_ERROR_NOT_STANDALONE error. + If parameter entity parsing is enabled, then in addition to the + conditions above this handler will only be called if the referenced + entity was actually read. +*/ +typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); + +/* This is called for a reference to an external parsed general + entity. The referenced entity is not automatically parsed. The + application can parse it immediately or later using + XML_ExternalEntityParserCreate. + + The parser argument is the parser parsing the entity containing the + reference; it can be passed as the parser argument to + XML_ExternalEntityParserCreate. The systemId argument is the + system identifier as specified in the entity declaration; it will + not be NULL. + + The base argument is the system identifier that should be used as + the base for resolving systemId if systemId was relative; this is + set by XML_SetBase; it may be NULL. + + The publicId argument is the public identifier as specified in the + entity declaration, or NULL if none was specified; the whitespace + in the public identifier will have been normalized as required by + the XML spec. + + The context argument specifies the parsing context in the format + expected by the context argument to XML_ExternalEntityParserCreate; + context is valid only until the handler returns, so if the + referenced entity is to be parsed later, it must be copied. + context is NULL only when the entity is a parameter entity. + + The handler should return XML_STATUS_ERROR if processing should not + continue because of a fatal error in the handling of the external + entity. In this case the calling parser will return an + XML_ERROR_EXTERNAL_ENTITY_HANDLING error. + + Note that unlike other handlers the first argument is the parser, + not userData. +*/ +typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( + XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* This is called in two situations: + 1) An entity reference is encountered for which no declaration + has been read *and* this is not an error. + 2) An internal entity reference is read, but not expanded, because + XML_SetDefaultHandler has been called. + Note: skipped parameter entities in declarations and skipped general + entities in attribute values cannot be reported, because + the event would be out of sync with the reporting of the + declarations or attribute values +*/ +typedef void (XMLCALL *XML_SkippedEntityHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +/* This structure is filled in by the XML_UnknownEncodingHandler to + provide information to the parser about encodings that are unknown + to the parser. + + The map[b] member gives information about byte sequences whose + first byte is b. + + If map[b] is c where c is >= 0, then b by itself encodes the + Unicode scalar value c. + + If map[b] is -1, then the byte sequence is malformed. + + If map[b] is -n, where n >= 2, then b is the first byte of an + n-byte sequence that encodes a single Unicode scalar value. + + The data member will be passed as the first argument to the convert + function. + + The convert function is used to convert multibyte sequences; s will + point to a n-byte sequence where map[(unsigned char)*s] == -n. The + convert function must return the Unicode scalar value represented + by this byte sequence or -1 if the byte sequence is malformed. + + The convert function may be NULL if the encoding is a single-byte + encoding, that is if map[b] >= -1 for all bytes b. + + When the parser is finished with the encoding, then if release is + not NULL, it will call release passing it the data member; once + release has been called, the convert function will not be called + again. + + Expat places certain restrictions on the encodings that are supported + using this mechanism. + + 1. Every ASCII character that can appear in a well-formed XML document, + other than the characters + + $@\^`{}~ + + must be represented by a single byte, and that byte must be the + same byte that represents that character in ASCII. + + 2. No character may require more than 4 bytes to encode. + + 3. All characters encoded must have Unicode scalar values <= + 0xFFFF, (i.e., characters that would be encoded by surrogates in + UTF-16 are not allowed). Note that this restriction doesn't + apply to the built-in support for UTF-8 and UTF-16. + + 4. No Unicode character may be encoded by more than one distinct + sequence of bytes. +*/ +typedef struct { + int map[256]; + void *data; + int (XMLCALL *convert)(void *data, const char *s); + void (XMLCALL *release)(void *data); +} XML_Encoding; + +/* This is called for an encoding that is unknown to the parser. + + The encodingHandlerData argument is that which was passed as the + second argument to XML_SetUnknownEncodingHandler. + + The name argument gives the name of the encoding as specified in + the encoding declaration. + + If the callback can provide information about the encoding, it must + fill in the XML_Encoding structure, and return XML_STATUS_OK. + Otherwise it must return XML_STATUS_ERROR. + + If info does not describe a suitable encoding, then the parser will + return an XML_UNKNOWN_ENCODING error. +*/ +typedef int (XMLCALL *XML_UnknownEncodingHandler) ( + void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); + +XMLPARSEAPI(void) +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end); + +XMLPARSEAPI(void) +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler handler); + +XMLPARSEAPI(void) +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler handler); + +XMLPARSEAPI(void) +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler); + +XMLPARSEAPI(void) +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler); +XMLPARSEAPI(void) +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler); + +XMLPARSEAPI(void) +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end); + +XMLPARSEAPI(void) +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start); + +XMLPARSEAPI(void) +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end); + +/* This sets the default handler and also inhibits expansion of + internal entities. These entity references will be passed to the + default handler, or to the skipped entity handler, if one is set. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler); + +/* This sets the default handler but does not inhibit expansion of + internal entities. The entity reference will not be passed to the + default handler. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler); + +XMLPARSEAPI(void) +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler); + +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler); + +/* If a non-NULL value for arg is specified here, then it will be + passed as the first argument to the external entity ref handler + instead of the parser object. +*/ +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, + void *arg); + +XMLPARSEAPI(void) +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler); + +XMLPARSEAPI(void) +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *encodingHandlerData); + +/* This can be called within a handler for a start element, end + element, processing instruction or character data. It causes the + corresponding markup to be passed to the default handler. +*/ +XMLPARSEAPI(void) +XML_DefaultCurrent(XML_Parser parser); + +/* If do_nst is non-zero, and namespace processing is in effect, and + a name has a prefix (i.e. an explicit namespace qualifier) then + that name is returned as a triplet in a single string separated by + the separator character specified when the parser was created: URI + + sep + local_name + sep + prefix. + + If do_nst is zero, then namespace information is returned in the + default manner (URI + sep + local_name) whether or not the name + has a prefix. + + Note: Calling XML_SetReturnNSTriplet after XML_Parse or + XML_ParseBuffer has no effect. +*/ + +XMLPARSEAPI(void) +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); + +/* This value is passed as the userData argument to callbacks. */ +XMLPARSEAPI(void) +XML_SetUserData(XML_Parser parser, void *userData); + +/* Returns the last value set by XML_SetUserData or NULL. */ +#define XML_GetUserData(parser) (*(void **)(parser)) + +/* This is equivalent to supplying an encoding argument to + XML_ParserCreate. On success XML_SetEncoding returns non-zero, + zero otherwise. + Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer + has no effect and returns XML_STATUS_ERROR. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); + +/* If this function is called, then the parser will be passed as the + first argument to callbacks instead of userData. The userData will + still be accessible using XML_GetUserData. +*/ +XMLPARSEAPI(void) +XML_UseParserAsHandlerArg(XML_Parser parser); + +/* If useDTD == XML_TRUE is passed to this function, then the parser + will assume that there is an external subset, even if none is + specified in the document. In such a case the parser will call the + externalEntityRefHandler with a value of NULL for the systemId + argument (the publicId and context arguments will be NULL as well). + Note: For the purpose of checking WFC: Entity Declared, passing + useDTD == XML_TRUE will make the parser behave as if the document + had a DTD with an external subset. + Note: If this function is called, then this must be done before + the first call to XML_Parse or XML_ParseBuffer, since it will + have no effect after that. Returns + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. + Note: If the document does not have a DOCTYPE declaration at all, + then startDoctypeDeclHandler and endDoctypeDeclHandler will not + be called, despite an external subset being parsed. + Note: If XML_DTD is not defined when Expat is compiled, returns + XML_ERROR_FEATURE_REQUIRES_XML_DTD. +*/ +XMLPARSEAPI(enum XML_Error) +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); + + +/* Sets the base to be used for resolving relative URIs in system + identifiers in declarations. Resolving relative identifiers is + left to the application: this value will be passed through as the + base argument to the XML_ExternalEntityRefHandler, + XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base + argument will be copied. Returns XML_STATUS_ERROR if out of memory, + XML_STATUS_OK otherwise. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetBase(XML_Parser parser, const XML_Char *base); + +XMLPARSEAPI(const XML_Char *) +XML_GetBase(XML_Parser parser); + +/* Returns the number of the attribute/value pairs passed in last call + to the XML_StartElementHandler that were specified in the start-tag + rather than defaulted. Each attribute/value pair counts as 2; thus + this correspondds to an index into the atts array passed to the + XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetSpecifiedAttributeCount(XML_Parser parser); + +/* Returns the index of the ID attribute passed in the last call to + XML_StartElementHandler, or -1 if there is no ID attribute. Each + attribute/value pair counts as 2; thus this correspondds to an + index into the atts array passed to the XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetIdAttributeIndex(XML_Parser parser); + +/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is + detected. The last call to XML_Parse must have isFinal true; len + may be zero for this call (or any other). + + Though the return values for these functions has always been + described as a Boolean value, the implementation, at least for the + 1.95.x series, has always returned exactly one of the XML_Status + values. +*/ +XMLPARSEAPI(enum XML_Status) +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); + +XMLPARSEAPI(void *) +XML_GetBuffer(XML_Parser parser, int len); + +XMLPARSEAPI(enum XML_Status) +XML_ParseBuffer(XML_Parser parser, int len, int isFinal); + +/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. + Must be called from within a call-back handler, except when aborting + (resumable = 0) an already suspended parser. Some call-backs may + still follow because they would otherwise get lost. Examples: + - endElementHandler() for empty elements when stopped in + startElementHandler(), + - endNameSpaceDeclHandler() when stopped in endElementHandler(), + and possibly others. + + Can be called from most handlers, including DTD related call-backs, + except when parsing an external parameter entity and resumable != 0. + Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. + Possible error codes: + - XML_ERROR_SUSPENDED: when suspending an already suspended parser. + - XML_ERROR_FINISHED: when the parser has already finished. + - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. + + When resumable != 0 (true) then parsing is suspended, that is, + XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. + Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() + return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. + + *Note*: + This will be applied to the current parser instance only, that is, if + there is a parent parser then it will continue parsing when the + externalEntityRefHandler() returns. It is up to the implementation of + the externalEntityRefHandler() to call XML_StopParser() on the parent + parser (recursively), if one wants to stop parsing altogether. + + When suspended, parsing can be resumed by calling XML_ResumeParser(). +*/ +XMLPARSEAPI(enum XML_Status) +XML_StopParser(XML_Parser parser, XML_Bool resumable); + +/* Resumes parsing after it has been suspended with XML_StopParser(). + Must not be called from within a handler call-back. Returns same + status codes as XML_Parse() or XML_ParseBuffer(). + Additional error code XML_ERROR_NOT_SUSPENDED possible. + + *Note*: + This must be called on the most deeply nested child parser instance + first, and on its parent parser only after the child parser has finished, + to be applied recursively until the document entity's parser is restarted. + That is, the parent parser will not resume by itself and it is up to the + application to call XML_ResumeParser() on it at the appropriate moment. +*/ +XMLPARSEAPI(enum XML_Status) +XML_ResumeParser(XML_Parser parser); + +enum XML_Parsing { + XML_INITIALIZED, + XML_PARSING, + XML_FINISHED, + XML_SUSPENDED +}; + +typedef struct { + enum XML_Parsing parsing; + XML_Bool finalBuffer; +} XML_ParsingStatus; + +/* Returns status of parser with respect to being initialized, parsing, + finished, or suspended and processing the final buffer. + XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, + XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED +*/ +XMLPARSEAPI(void) +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); + +/* Creates an XML_Parser object that can parse an external general + entity; context is a '\0'-terminated string specifying the parse + context; encoding is a '\0'-terminated string giving the name of + the externally specified encoding, or NULL if there is no + externally specified encoding. The context string consists of a + sequence of tokens separated by formfeeds (\f); a token consisting + of a name specifies that the general entity of the name is open; a + token of the form prefix=uri specifies the namespace for a + particular prefix; a token of the form =uri specifies the default + namespace. This can be called at any point after the first call to + an ExternalEntityRefHandler so longer as the parser has not yet + been freed. The new parser is completely independent and may + safely be used in a separate thread. The handlers and userData are + initialized from the parser argument. Returns NULL if out of memory. + Otherwise returns a new XML_Parser object. +*/ +XMLPARSEAPI(XML_Parser) +XML_ExternalEntityParserCreate(XML_Parser parser, + const XML_Char *context, + const XML_Char *encoding); + +enum XML_ParamEntityParsing { + XML_PARAM_ENTITY_PARSING_NEVER, + XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, + XML_PARAM_ENTITY_PARSING_ALWAYS +}; + +/* Controls parsing of parameter entities (including the external DTD + subset). If parsing of parameter entities is enabled, then + references to external parameter entities (including the external + DTD subset) will be passed to the handler set with + XML_SetExternalEntityRefHandler. The context passed will be 0. + + Unlike external general entities, external parameter entities can + only be parsed synchronously. If the external parameter entity is + to be parsed, it must be parsed during the call to the external + entity ref handler: the complete sequence of + XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and + XML_ParserFree calls must be made during this call. After + XML_ExternalEntityParserCreate has been called to create the parser + for the external parameter entity (context must be 0 for this + call), it is illegal to make any calls on the old parser until + XML_ParserFree has been called on the newly created parser. + If the library has been compiled without support for parameter + entity parsing (ie without XML_DTD being defined), then + XML_SetParamEntityParsing will return 0 if parsing of parameter + entities is requested; otherwise it will return non-zero. + Note: If XML_SetParamEntityParsing is called after XML_Parse or + XML_ParseBuffer, then it has no effect and will always return 0. +*/ +XMLPARSEAPI(int) +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing parsing); + +/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then + XML_GetErrorCode returns information about the error. +*/ +XMLPARSEAPI(enum XML_Error) +XML_GetErrorCode(XML_Parser parser); + +/* These functions return information about the current parse + location. They may be called from any callback called to report + some parse event; in this case the location is the location of the + first of the sequence of characters that generated the event. When + called from callbacks generated by declarations in the document + prologue, the location identified isn't as neatly defined, but will + be within the relevant markup. When called outside of the callback + functions, the position indicated will be just past the last parse + event (regardless of whether there was an associated callback). + + They may also be called after returning from a call to XML_Parse + or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then + the location is the location of the character at which the error + was detected; otherwise the location is the location of the last + parse event, as described above. +*/ +XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); +XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); +XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); + +/* Return the number of bytes in the current event. + Returns 0 if the event is in an internal entity. +*/ +XMLPARSEAPI(int) +XML_GetCurrentByteCount(XML_Parser parser); + +/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets + the integer pointed to by offset to the offset within this buffer + of the current parse position, and sets the integer pointed to by size + to the size of this buffer (the number of input bytes). Otherwise + returns a NULL pointer. Also returns a NULL pointer if a parse isn't + active. + + NOTE: The character pointer returned should not be used outside + the handler that makes the call. +*/ +XMLPARSEAPI(const char *) +XML_GetInputContext(XML_Parser parser, + int *offset, + int *size); + +/* For backwards compatibility with previous versions. */ +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex + +/* Frees the content model passed to the element declaration handler */ +XMLPARSEAPI(void) +XML_FreeContentModel(XML_Parser parser, XML_Content *model); + +/* Exposing the memory handling functions used in Expat */ +XMLPARSEAPI(void *) +XML_MemMalloc(XML_Parser parser, size_t size); + +XMLPARSEAPI(void *) +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); + +XMLPARSEAPI(void) +XML_MemFree(XML_Parser parser, void *ptr); + +/* Frees memory used by the parser. */ +XMLPARSEAPI(void) +XML_ParserFree(XML_Parser parser); + +/* Returns a string describing the error. */ +XMLPARSEAPI(const XML_LChar *) +XML_ErrorString(enum XML_Error code); + +/* Return a string containing the version number of this expat */ +XMLPARSEAPI(const XML_LChar *) +XML_ExpatVersion(void); + +typedef struct { + int major; + int minor; + int micro; +} XML_Expat_Version; + +/* Return an XML_Expat_Version structure containing numeric version + number information for this version of expat. +*/ +XMLPARSEAPI(XML_Expat_Version) +XML_ExpatVersionInfo(void); + +/* Added in Expat 1.95.5. */ +enum XML_FeatureEnum { + XML_FEATURE_END = 0, + XML_FEATURE_UNICODE, + XML_FEATURE_UNICODE_WCHAR_T, + XML_FEATURE_DTD, + XML_FEATURE_CONTEXT_BYTES, + XML_FEATURE_MIN_SIZE, + XML_FEATURE_SIZEOF_XML_CHAR, + XML_FEATURE_SIZEOF_XML_LCHAR, + XML_FEATURE_NS, + XML_FEATURE_LARGE_SIZE + /* Additional features must be added to the end of this enum. */ +}; + +typedef struct { + enum XML_FeatureEnum feature; + const XML_LChar *name; + long int value; +} XML_Feature; + +XMLPARSEAPI(const XML_Feature *) +XML_GetFeatureList(void); + + +/* Expat follows the GNU/Linux convention of odd number minor version for + beta/development releases and even number minor version for stable + releases. Micro is bumped with each release, and set to 0 with each + change to major or minor version. +*/ +#define XML_MAJOR_VERSION 2 +#define XML_MINOR_VERSION 0 +#define XML_MICRO_VERSION 1 + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_INCLUDED */ diff --git a/XML/include/Poco/XML/expat_external.h b/XML/include/Poco/XML/expat_external.h index bb83a995c..2c03284ea 100644 --- a/XML/include/Poco/XML/expat_external.h +++ b/XML/include/Poco/XML/expat_external.h @@ -1,115 +1,115 @@ -/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#ifndef Expat_External_INCLUDED -#define Expat_External_INCLUDED 1 - -/* External API definitions */ - -#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) -#define XML_USE_MSC_EXTENSIONS 1 -#endif - -/* Expat tries very hard to make the API boundary very specifically - defined. There are two macros defined to control this boundary; - each of these can be defined before including this header to - achieve some different behavior, but doing so it not recommended or - tested frequently. - - XMLCALL - The calling convention to use for all calls across the - "library boundary." This will default to cdecl, and - try really hard to tell the compiler that's what we - want. - - XMLIMPORT - Whatever magic is needed to note that a function is - to be imported from a dynamically loaded library - (.dll, .so, or .sl, depending on your platform). - - The XMLCALL macro was added in Expat 1.95.7. The only one which is - expected to be directly useful in client code is XMLCALL. - - Note that on at least some Unix versions, the Expat library must be - compiled with the cdecl calling convention as the default since - system headers may assume the cdecl convention. -*/ -#ifndef XMLCALL -#if defined(_MSC_VER) -#define XMLCALL __cdecl -#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER) -#define XMLCALL __attribute__((cdecl)) -#else -/* For any platform which uses this definition and supports more than - one calling convention, we need to extend this definition to - declare the convention used on that platform, if it's possible to - do so. - - If this is the case for your platform, please file a bug report - with information on how to identify your platform via the C - pre-processor and how to specify the same calling convention as the - platform's malloc() implementation. -*/ -#define XMLCALL -#endif -#endif /* not defined XMLCALL */ - - -#if !defined(XML_STATIC) && !defined(XMLIMPORT) -#ifndef XML_BUILDING_EXPAT -/* using Expat from an application */ - -#ifdef XML_USE_MSC_EXTENSIONS -#define XMLIMPORT __declspec(dllimport) -#endif - -#endif -#endif /* not defined XML_STATIC */ - - -/* If we didn't define it above, define it away: */ -#ifndef XMLIMPORT -#define XMLIMPORT -#endif - - -#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef XML_UNICODE_WCHAR_T -#define XML_UNICODE -#endif - -#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ -#ifdef XML_UNICODE_WCHAR_T -typedef wchar_t XML_Char; -typedef wchar_t XML_LChar; -#else -typedef unsigned short XML_Char; -typedef char XML_LChar; -#endif /* XML_UNICODE_WCHAR_T */ -#else /* Information is UTF-8 encoded. */ -typedef char XML_Char; -typedef char XML_LChar; -#endif /* XML_UNICODE */ - -#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ -#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 -typedef __int64 XML_Index; -typedef unsigned __int64 XML_Size; -#else -typedef long long XML_Index; -typedef unsigned long long XML_Size; -#endif -#else -typedef long XML_Index; -typedef unsigned long XML_Size; -#endif /* XML_LARGE_SIZE */ - -#ifdef __cplusplus -} -#endif - -#endif /* not Expat_External_INCLUDED */ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_External_INCLUDED +#define Expat_External_INCLUDED 1 + +/* External API definitions */ + +#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) +#define XML_USE_MSC_EXTENSIONS 1 +#endif + +/* Expat tries very hard to make the API boundary very specifically + defined. There are two macros defined to control this boundary; + each of these can be defined before including this header to + achieve some different behavior, but doing so it not recommended or + tested frequently. + + XMLCALL - The calling convention to use for all calls across the + "library boundary." This will default to cdecl, and + try really hard to tell the compiler that's what we + want. + + XMLIMPORT - Whatever magic is needed to note that a function is + to be imported from a dynamically loaded library + (.dll, .so, or .sl, depending on your platform). + + The XMLCALL macro was added in Expat 1.95.7. The only one which is + expected to be directly useful in client code is XMLCALL. + + Note that on at least some Unix versions, the Expat library must be + compiled with the cdecl calling convention as the default since + system headers may assume the cdecl convention. +*/ +#ifndef XMLCALL +#if defined(_MSC_VER) +#define XMLCALL __cdecl +#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER) +#define XMLCALL __attribute__((cdecl)) +#else +/* For any platform which uses this definition and supports more than + one calling convention, we need to extend this definition to + declare the convention used on that platform, if it's possible to + do so. + + If this is the case for your platform, please file a bug report + with information on how to identify your platform via the C + pre-processor and how to specify the same calling convention as the + platform's malloc() implementation. +*/ +#define XMLCALL +#endif +#endif /* not defined XMLCALL */ + + +#if !defined(XML_STATIC) && !defined(XMLIMPORT) +#ifndef XML_BUILDING_EXPAT +/* using Expat from an application */ + +#ifdef XML_USE_MSC_EXTENSIONS +#define XMLIMPORT __declspec(dllimport) +#endif + +#endif +#endif /* not defined XML_STATIC */ + + +/* If we didn't define it above, define it away: */ +#ifndef XMLIMPORT +#define XMLIMPORT +#endif + + +#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef XML_UNICODE_WCHAR_T +#define XML_UNICODE +#endif + +#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ +#ifdef XML_UNICODE_WCHAR_T +typedef wchar_t XML_Char; +typedef wchar_t XML_LChar; +#else +typedef unsigned short XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE_WCHAR_T */ +#else /* Information is UTF-8 encoded. */ +typedef char XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE */ + +#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ +#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 +typedef __int64 XML_Index; +typedef unsigned __int64 XML_Size; +#else +typedef long long XML_Index; +typedef unsigned long long XML_Size; +#endif +#else +typedef long XML_Index; +typedef unsigned long XML_Size; +#endif /* XML_LARGE_SIZE */ + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_External_INCLUDED */ diff --git a/XML/samples/DOMParser/DOMParser.vmsbuild b/XML/samples/DOMParser/DOMParser.vmsbuild index 174fa57ad..f0277bcf2 100644 --- a/XML/samples/DOMParser/DOMParser.vmsbuild +++ b/XML/samples/DOMParser/DOMParser.vmsbuild @@ -1,8 +1,8 @@ -# -# sample.vmsbuild -# -# $Id: //poco/1.3/XML/samples/DOMParser/DOMParser.vmsbuild#1 $ -# -EXE=DOMParser -DOMParser - +# +# sample.vmsbuild +# +# $Id: //poco/1.3/XML/samples/DOMParser/DOMParser.vmsbuild#1 $ +# +EXE=DOMParser +DOMParser + diff --git a/XML/samples/DOMParser/DOMParser_vs71.vcproj b/XML/samples/DOMParser/DOMParser_vs71.vcproj index b3bba8ca8..8338395f6 100644 --- a/XML/samples/DOMParser/DOMParser_vs71.vcproj +++ b/XML/samples/DOMParser/DOMParser_vs71.vcproj @@ -1,149 +1,149 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/DOMParser/DOMParser_vs80.vcproj b/XML/samples/DOMParser/DOMParser_vs80.vcproj index f5ebbdfc9..7eea1c85f 100644 --- a/XML/samples/DOMParser/DOMParser_vs80.vcproj +++ b/XML/samples/DOMParser/DOMParser_vs80.vcproj @@ -1,213 +1,213 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/DOMParser/src/DOMParser.cpp b/XML/samples/DOMParser/src/DOMParser.cpp index 936d5ab20..42ac34571 100644 --- a/XML/samples/DOMParser/src/DOMParser.cpp +++ b/XML/samples/DOMParser/src/DOMParser.cpp @@ -1,81 +1,81 @@ -// -// DOMParser.cpp -// -// $Id: //poco/1.3/XML/samples/DOMParser/src/DOMParser.cpp#2 $ -// -// This sample demonstrates the DOMParser, AutoPtr and -// NodeIterator classes. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMParser.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/NodeIterator.h" -#include "Poco/DOM/NodeFilter.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/Exception.h" -#include - - -using Poco::XML::DOMParser; -using Poco::XML::InputSource; -using Poco::XML::Document; -using Poco::XML::NodeIterator; -using Poco::XML::NodeFilter; -using Poco::XML::Node; -using Poco::XML::AutoPtr; -using Poco::Exception; - - -int main(int argc, char** argv) -{ - // Parse an XML document from standard input - // and use a NodeIterator to print out all nodes. - - InputSource src(std::cin); - try - { - DOMParser parser; - AutoPtr pDoc = parser.parse(&src); - - NodeIterator it(pDoc, NodeFilter::SHOW_ALL); - Node* pNode = it.nextNode(); - while (pNode) - { - std::cout << pNode->nodeName() << ":" << pNode->nodeValue() << std::endl; - pNode = it.nextNode(); - } - } - catch (Exception& exc) - { - std::cerr << exc.displayText() << std::endl; - } - - return 0; -} +// +// DOMParser.cpp +// +// $Id: //poco/1.3/XML/samples/DOMParser/src/DOMParser.cpp#2 $ +// +// This sample demonstrates the DOMParser, AutoPtr and +// NodeIterator classes. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMParser.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/NodeIterator.h" +#include "Poco/DOM/NodeFilter.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/Exception.h" +#include + + +using Poco::XML::DOMParser; +using Poco::XML::InputSource; +using Poco::XML::Document; +using Poco::XML::NodeIterator; +using Poco::XML::NodeFilter; +using Poco::XML::Node; +using Poco::XML::AutoPtr; +using Poco::Exception; + + +int main(int argc, char** argv) +{ + // Parse an XML document from standard input + // and use a NodeIterator to print out all nodes. + + InputSource src(std::cin); + try + { + DOMParser parser; + AutoPtr pDoc = parser.parse(&src); + + NodeIterator it(pDoc, NodeFilter::SHOW_ALL); + Node* pNode = it.nextNode(); + while (pNode) + { + std::cout << pNode->nodeName() << ":" << pNode->nodeValue() << std::endl; + pNode = it.nextNode(); + } + } + catch (Exception& exc) + { + std::cerr << exc.displayText() << std::endl; + } + + return 0; +} diff --git a/XML/samples/DOMWriter/DOMWriter.vmsbuild b/XML/samples/DOMWriter/DOMWriter.vmsbuild index cdb5597ea..2eade9e1f 100644 --- a/XML/samples/DOMWriter/DOMWriter.vmsbuild +++ b/XML/samples/DOMWriter/DOMWriter.vmsbuild @@ -1,8 +1,8 @@ -# -# sample.vmsbuild -# -# $Id: //poco/1.3/XML/samples/DOMWriter/DOMWriter.vmsbuild#1 $ -# -EXE=DOMWriter -DOMWriter - +# +# sample.vmsbuild +# +# $Id: //poco/1.3/XML/samples/DOMWriter/DOMWriter.vmsbuild#1 $ +# +EXE=DOMWriter +DOMWriter + diff --git a/XML/samples/DOMWriter/DOMWriter_vs71.vcproj b/XML/samples/DOMWriter/DOMWriter_vs71.vcproj index 0bbd050d4..fdbf68a3b 100644 --- a/XML/samples/DOMWriter/DOMWriter_vs71.vcproj +++ b/XML/samples/DOMWriter/DOMWriter_vs71.vcproj @@ -1,149 +1,149 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/DOMWriter/DOMWriter_vs80.vcproj b/XML/samples/DOMWriter/DOMWriter_vs80.vcproj index a8afe3bf9..c3a0d46af 100644 --- a/XML/samples/DOMWriter/DOMWriter_vs80.vcproj +++ b/XML/samples/DOMWriter/DOMWriter_vs80.vcproj @@ -1,213 +1,213 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/DOMWriter/src/DOMWriter.cpp b/XML/samples/DOMWriter/src/DOMWriter.cpp index ae21106a8..afa2ab63c 100644 --- a/XML/samples/DOMWriter/src/DOMWriter.cpp +++ b/XML/samples/DOMWriter/src/DOMWriter.cpp @@ -1,78 +1,78 @@ -// -// DOMWriter.cpp -// -// $Id: //poco/1.3/XML/samples/DOMWriter/src/DOMWriter.cpp#1 $ -// -// This sample demonstrates the DOMWriter class and how to -// build DOM documents in memory. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/DOM/DOMWriter.h" -#include "Poco/XML/XMLWriter.h" -#include - - -using Poco::XML::Document; -using Poco::XML::Element; -using Poco::XML::Text; -using Poco::XML::AutoPtr; -using Poco::XML::DOMWriter; -using Poco::XML::XMLWriter; - - -int main(int argc, char** argv) -{ - // build a DOM document and write it to standard output. - - AutoPtr pDoc = new Document; - - AutoPtr pRoot = pDoc->createElement("root"); - pDoc->appendChild(pRoot); - - AutoPtr pChild1 = pDoc->createElement("child1"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - pChild1->appendChild(pText1); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - pChild2->appendChild(pText2); - pRoot->appendChild(pChild2); - - DOMWriter writer; - writer.setNewLine("\n"); - writer.setOptions(XMLWriter::PRETTY_PRINT); - writer.writeNode(std::cout, pDoc); - - return 0; -} +// +// DOMWriter.cpp +// +// $Id: //poco/1.3/XML/samples/DOMWriter/src/DOMWriter.cpp#1 $ +// +// This sample demonstrates the DOMWriter class and how to +// build DOM documents in memory. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/DOM/DOMWriter.h" +#include "Poco/XML/XMLWriter.h" +#include + + +using Poco::XML::Document; +using Poco::XML::Element; +using Poco::XML::Text; +using Poco::XML::AutoPtr; +using Poco::XML::DOMWriter; +using Poco::XML::XMLWriter; + + +int main(int argc, char** argv) +{ + // build a DOM document and write it to standard output. + + AutoPtr pDoc = new Document; + + AutoPtr pRoot = pDoc->createElement("root"); + pDoc->appendChild(pRoot); + + AutoPtr pChild1 = pDoc->createElement("child1"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + pChild1->appendChild(pText1); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + pChild2->appendChild(pText2); + pRoot->appendChild(pChild2); + + DOMWriter writer; + writer.setNewLine("\n"); + writer.setOptions(XMLWriter::PRETTY_PRINT); + writer.writeNode(std::cout, pDoc); + + return 0; +} diff --git a/XML/samples/PrettyPrint/PrettyPrint.vmsbuild b/XML/samples/PrettyPrint/PrettyPrint.vmsbuild index 7eb590a50..c49a884d7 100644 --- a/XML/samples/PrettyPrint/PrettyPrint.vmsbuild +++ b/XML/samples/PrettyPrint/PrettyPrint.vmsbuild @@ -1,8 +1,8 @@ -# -# sample.vmsbuild -# -# $Id: //poco/1.3/XML/samples/PrettyPrint/PrettyPrint.vmsbuild#1 $ -# -EXE=PrettyPrint -PrettyPrint - +# +# sample.vmsbuild +# +# $Id: //poco/1.3/XML/samples/PrettyPrint/PrettyPrint.vmsbuild#1 $ +# +EXE=PrettyPrint +PrettyPrint + diff --git a/XML/samples/PrettyPrint/PrettyPrint_vs71.vcproj b/XML/samples/PrettyPrint/PrettyPrint_vs71.vcproj index 235938563..439411748 100644 --- a/XML/samples/PrettyPrint/PrettyPrint_vs71.vcproj +++ b/XML/samples/PrettyPrint/PrettyPrint_vs71.vcproj @@ -1,149 +1,149 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/PrettyPrint/PrettyPrint_vs80.vcproj b/XML/samples/PrettyPrint/PrettyPrint_vs80.vcproj index 5d376067c..660487985 100644 --- a/XML/samples/PrettyPrint/PrettyPrint_vs80.vcproj +++ b/XML/samples/PrettyPrint/PrettyPrint_vs80.vcproj @@ -1,213 +1,213 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/PrettyPrint/src/PrettyPrint.cpp b/XML/samples/PrettyPrint/src/PrettyPrint.cpp index 12c7b02d7..fc0bd3789 100644 --- a/XML/samples/PrettyPrint/src/PrettyPrint.cpp +++ b/XML/samples/PrettyPrint/src/PrettyPrint.cpp @@ -1,78 +1,78 @@ -// -// PrettyPrint.cpp -// -// $Id: //poco/1.3/XML/samples/PrettyPrint/src/PrettyPrint.cpp#1 $ -// -// This sample demonstrates the SAXParser, WhitespaceFilter, -// InputSource and XMLWriter classes. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/SAXParser.h" -#include "Poco/SAX/WhitespaceFilter.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/XML/XMLWriter.h" -#include "Poco/Exception.h" -#include - - -using Poco::XML::SAXParser; -using Poco::XML::XMLReader; -using Poco::XML::WhitespaceFilter; -using Poco::XML::InputSource; -using Poco::XML::XMLWriter; -using Poco::Exception; - - -int main(int argc, char** argv) -{ - // read XML from standard input and pretty-print it to standard output - - SAXParser parser; - WhitespaceFilter filter(&parser); - - XMLWriter writer(std::cout, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine(XMLWriter::NEWLINE_LF); - - filter.setContentHandler(&writer); - filter.setDTDHandler(&writer); - filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - - try - { - InputSource source(std::cin); - filter.parse(&source); - } - catch (Exception& exc) - { - std::cerr << exc.displayText() << std::endl; - return 1; - } - - return 0; -} +// +// PrettyPrint.cpp +// +// $Id: //poco/1.3/XML/samples/PrettyPrint/src/PrettyPrint.cpp#1 $ +// +// This sample demonstrates the SAXParser, WhitespaceFilter, +// InputSource and XMLWriter classes. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/SAXParser.h" +#include "Poco/SAX/WhitespaceFilter.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/XML/XMLWriter.h" +#include "Poco/Exception.h" +#include + + +using Poco::XML::SAXParser; +using Poco::XML::XMLReader; +using Poco::XML::WhitespaceFilter; +using Poco::XML::InputSource; +using Poco::XML::XMLWriter; +using Poco::Exception; + + +int main(int argc, char** argv) +{ + // read XML from standard input and pretty-print it to standard output + + SAXParser parser; + WhitespaceFilter filter(&parser); + + XMLWriter writer(std::cout, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine(XMLWriter::NEWLINE_LF); + + filter.setContentHandler(&writer); + filter.setDTDHandler(&writer); + filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + + try + { + InputSource source(std::cin); + filter.parse(&source); + } + catch (Exception& exc) + { + std::cerr << exc.displayText() << std::endl; + return 1; + } + + return 0; +} diff --git a/XML/samples/SAXParser/SAXParser.vmsbuild b/XML/samples/SAXParser/SAXParser.vmsbuild index c630e5159..a7ae48fdb 100644 --- a/XML/samples/SAXParser/SAXParser.vmsbuild +++ b/XML/samples/SAXParser/SAXParser.vmsbuild @@ -1,8 +1,8 @@ -# -# sample.vmsbuild -# -# $Id: //poco/1.3/XML/samples/SAXParser/SAXParser.vmsbuild#1 $ -# -EXE=SAXParser -SAXParser - +# +# sample.vmsbuild +# +# $Id: //poco/1.3/XML/samples/SAXParser/SAXParser.vmsbuild#1 $ +# +EXE=SAXParser +SAXParser + diff --git a/XML/samples/SAXParser/SAXParser_vs71.vcproj b/XML/samples/SAXParser/SAXParser_vs71.vcproj index 12c0c95e9..c71d1539c 100644 --- a/XML/samples/SAXParser/SAXParser_vs71.vcproj +++ b/XML/samples/SAXParser/SAXParser_vs71.vcproj @@ -1,149 +1,149 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/SAXParser/SAXParser_vs80.vcproj b/XML/samples/SAXParser/SAXParser_vs80.vcproj index a661be2a1..0129b7744 100644 --- a/XML/samples/SAXParser/SAXParser_vs80.vcproj +++ b/XML/samples/SAXParser/SAXParser_vs80.vcproj @@ -1,213 +1,213 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/samples/SAXParser/src/SAXParser.cpp b/XML/samples/SAXParser/src/SAXParser.cpp index f09e0be7a..e4844c990 100644 --- a/XML/samples/SAXParser/src/SAXParser.cpp +++ b/XML/samples/SAXParser/src/SAXParser.cpp @@ -1,215 +1,215 @@ -// -// SAXParser.cpp -// -// $Id: //poco/1.3/XML/samples/SAXParser/src/SAXParser.cpp#1 $ -// -// This sample demonstrates the SAXParser class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/SAXParser.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/LexicalHandler.h" -#include "Poco/SAX/Attributes.h" -#include "Poco/SAX/Locator.h" -#include "Poco/Exception.h" -#include - - -using Poco::XML::SAXParser; -using Poco::XML::XMLReader; -using Poco::XML::XMLString; -using Poco::XML::XMLChar; -using Poco::XML::ContentHandler; -using Poco::XML::LexicalHandler; -using Poco::XML::Attributes; -using Poco::XML::Locator; - - -class MyHandler: public ContentHandler, public LexicalHandler -{ -public: - MyHandler(): - _pLocator(0) - { - } - - // ContentHandler - void setDocumentLocator(const Locator* loc) - { - _pLocator = loc; - } - - void startDocument() - { - where("startDocument"); - } - - void endDocument() - { - where("endDocument"); - } - - void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) - { - where("startElement"); - std::cout << "uri: " << uri << std::endl - << "localName: " << localName << std::endl - << "qname: " << qname << std::endl; - std::cout << "Attributes: " << std::endl; - for (int i = 0; i < attributes.getLength(); ++i) - { - std::cout << attributes.getLocalName(i) << "=" << attributes.getValue(i) << std::endl; - } - } - - void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) - { - where("endElement"); - } - - void characters(const XMLChar ch[], int start, int length) - { - where("characters"); - std::cout << std::string(ch + start, length) << std::endl; - } - - void ignorableWhitespace(const XMLChar ch[], int start, int length) - { - where("ignorableWhitespace"); - } - - void processingInstruction(const XMLString& target, const XMLString& data) - { - where("processingInstruction"); - std::cout << "target=" << target << ", data=" << data << std::endl; - } - - void startPrefixMapping(const XMLString& prefix, const XMLString& uri) - { - where("startPrefixMapping"); - std::cout << "prefix=" << prefix << " uri=" << uri << std::endl; - } - - void endPrefixMapping(const XMLString& prefix) - { - where("endPrefixMapping"); - std::cout << "prefix=" << prefix << std::endl; - } - - void skippedEntity(const XMLString& name) - { - where("skippedEntity"); - std::cout << "name=" << name << std::endl; - } - - // LexicalHandler - void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) - { - where("startDTD"); - } - - void endDTD() - { - where("endDTD"); - } - - void startEntity(const XMLString& name) - { - where("startEntity"); - } - - void endEntity(const XMLString& name) - { - where("endEntity"); - } - - void startCDATA() - { - where("startCDATA"); - } - - void endCDATA() - { - where("endCDATA"); - } - - void comment(const XMLChar ch[], int start, int length) - { - where("comment"); - } - -protected: - void where(const std::string& meth) - { - std::cout << "*** " << meth; - if (_pLocator) - { - std::cout << " in " - << _pLocator->getSystemId() - << ", line " << _pLocator->getLineNumber() - << ", col " << _pLocator->getColumnNumber() - << std::endl; - } - } - -private: - const Locator* _pLocator; -}; - - -int main(int argc, char** argv) -{ - // parse an XML document and print the generated SAX events - - if (argc < 2) - { - std::cout << "usage: " << argv[0] << ": " << std::endl; - return 1; - } - - MyHandler handler; - - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); - parser.setContentHandler(&handler); - parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&handler)); - - try - { - parser.parse(argv[1]); - } - catch (Poco::Exception& e) - { - std::cerr << e.displayText() << std::endl; - return 2; - } - - return 0; -} +// +// SAXParser.cpp +// +// $Id: //poco/1.3/XML/samples/SAXParser/src/SAXParser.cpp#1 $ +// +// This sample demonstrates the SAXParser class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/SAXParser.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/LexicalHandler.h" +#include "Poco/SAX/Attributes.h" +#include "Poco/SAX/Locator.h" +#include "Poco/Exception.h" +#include + + +using Poco::XML::SAXParser; +using Poco::XML::XMLReader; +using Poco::XML::XMLString; +using Poco::XML::XMLChar; +using Poco::XML::ContentHandler; +using Poco::XML::LexicalHandler; +using Poco::XML::Attributes; +using Poco::XML::Locator; + + +class MyHandler: public ContentHandler, public LexicalHandler +{ +public: + MyHandler(): + _pLocator(0) + { + } + + // ContentHandler + void setDocumentLocator(const Locator* loc) + { + _pLocator = loc; + } + + void startDocument() + { + where("startDocument"); + } + + void endDocument() + { + where("endDocument"); + } + + void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) + { + where("startElement"); + std::cout << "uri: " << uri << std::endl + << "localName: " << localName << std::endl + << "qname: " << qname << std::endl; + std::cout << "Attributes: " << std::endl; + for (int i = 0; i < attributes.getLength(); ++i) + { + std::cout << attributes.getLocalName(i) << "=" << attributes.getValue(i) << std::endl; + } + } + + void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) + { + where("endElement"); + } + + void characters(const XMLChar ch[], int start, int length) + { + where("characters"); + std::cout << std::string(ch + start, length) << std::endl; + } + + void ignorableWhitespace(const XMLChar ch[], int start, int length) + { + where("ignorableWhitespace"); + } + + void processingInstruction(const XMLString& target, const XMLString& data) + { + where("processingInstruction"); + std::cout << "target=" << target << ", data=" << data << std::endl; + } + + void startPrefixMapping(const XMLString& prefix, const XMLString& uri) + { + where("startPrefixMapping"); + std::cout << "prefix=" << prefix << " uri=" << uri << std::endl; + } + + void endPrefixMapping(const XMLString& prefix) + { + where("endPrefixMapping"); + std::cout << "prefix=" << prefix << std::endl; + } + + void skippedEntity(const XMLString& name) + { + where("skippedEntity"); + std::cout << "name=" << name << std::endl; + } + + // LexicalHandler + void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) + { + where("startDTD"); + } + + void endDTD() + { + where("endDTD"); + } + + void startEntity(const XMLString& name) + { + where("startEntity"); + } + + void endEntity(const XMLString& name) + { + where("endEntity"); + } + + void startCDATA() + { + where("startCDATA"); + } + + void endCDATA() + { + where("endCDATA"); + } + + void comment(const XMLChar ch[], int start, int length) + { + where("comment"); + } + +protected: + void where(const std::string& meth) + { + std::cout << "*** " << meth; + if (_pLocator) + { + std::cout << " in " + << _pLocator->getSystemId() + << ", line " << _pLocator->getLineNumber() + << ", col " << _pLocator->getColumnNumber() + << std::endl; + } + } + +private: + const Locator* _pLocator; +}; + + +int main(int argc, char** argv) +{ + // parse an XML document and print the generated SAX events + + if (argc < 2) + { + std::cout << "usage: " << argv[0] << ": " << std::endl; + return 1; + } + + MyHandler handler; + + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); + parser.setContentHandler(&handler); + parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&handler)); + + try + { + parser.parse(argv[1]); + } + catch (Poco::Exception& e) + { + std::cerr << e.displayText() << std::endl; + return 2; + } + + return 0; +} diff --git a/XML/samples/data/sample.xml b/XML/samples/data/sample.xml index 4a439bfab..7f36aecf1 100644 --- a/XML/samples/data/sample.xml +++ b/XML/samples/data/sample.xml @@ -1,22 +1,22 @@ - - - - - - - - - - A XHTML Example - - -

XHTML Example

-

This is a XHTML example page.

- Example Picture - is inside a CDATA section. - ]]> - - + + + + + + + + + + A XHTML Example + + +

XHTML Example

+

This is a XHTML example page.

+ Example Picture + is inside a CDATA section. + ]]> + + diff --git a/XML/samples/samples_vs71.sln b/XML/samples/samples_vs71.sln index 7aa0209e7..56c47afd7 100644 --- a/XML/samples/samples_vs71.sln +++ b/XML/samples/samples_vs71.sln @@ -1,45 +1,45 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAXParser", "SAXParser\SAXParser_vs71.vcproj", "{7E4D1B8E-B4FE-432A-92C9-352C98B646B4}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrettyPrint", "PrettyPrint\PrettyPrint_vs71.vcproj", "{5A6FC255-BE1D-4E09-A680-A67FF16E832F}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMParser", "DOMParser\DOMParser_vs71.vcproj", "{383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMWriter", "DOMWriter\DOMWriter_vs71.vcproj", "{68F63799-6BCA-4058-89AC-DAC545C6AB0F}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - debug_shared = debug_shared - release_shared = release_shared - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared.ActiveCfg = debug_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared.Build.0 = debug_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared.ActiveCfg = release_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared.Build.0 = release_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared.ActiveCfg = debug_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared.Build.0 = debug_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared.ActiveCfg = release_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared.Build.0 = release_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared.ActiveCfg = debug_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared.Build.0 = debug_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared.ActiveCfg = release_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared.Build.0 = release_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared.ActiveCfg = debug_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared.Build.0 = debug_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared.ActiveCfg = release_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared.Build.0 = release_shared|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAXParser", "SAXParser\SAXParser_vs71.vcproj", "{7E4D1B8E-B4FE-432A-92C9-352C98B646B4}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrettyPrint", "PrettyPrint\PrettyPrint_vs71.vcproj", "{5A6FC255-BE1D-4E09-A680-A67FF16E832F}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMParser", "DOMParser\DOMParser_vs71.vcproj", "{383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMWriter", "DOMWriter\DOMWriter_vs71.vcproj", "{68F63799-6BCA-4058-89AC-DAC545C6AB0F}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + debug_shared = debug_shared + release_shared = release_shared + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared.ActiveCfg = debug_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared.Build.0 = debug_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared.ActiveCfg = release_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared.Build.0 = release_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared.ActiveCfg = debug_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared.Build.0 = debug_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared.ActiveCfg = release_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared.Build.0 = release_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared.ActiveCfg = debug_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared.Build.0 = debug_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared.ActiveCfg = release_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared.Build.0 = release_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared.ActiveCfg = debug_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared.Build.0 = debug_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared.ActiveCfg = release_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared.Build.0 = release_shared|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/XML/samples/samples_vs80.sln b/XML/samples/samples_vs80.sln index 1ea76ab59..8d0b78593 100644 --- a/XML/samples/samples_vs80.sln +++ b/XML/samples/samples_vs80.sln @@ -1,37 +1,37 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAXParser", "SAXParser\SAXParser_vs80.vcproj", "{7E4D1B8E-B4FE-432A-92C9-352C98B646B4}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrettyPrint", "PrettyPrint\PrettyPrint_vs80.vcproj", "{5A6FC255-BE1D-4E09-A680-A67FF16E832F}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMParser", "DOMParser\DOMParser_vs80.vcproj", "{383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMWriter", "DOMWriter\DOMWriter_vs80.vcproj", "{68F63799-6BCA-4058-89AC-DAC545C6AB0F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - debug_shared|Win32 = debug_shared|Win32 - release_shared|Win32 = release_shared|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared|Win32.Build.0 = release_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared|Win32.Build.0 = release_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared|Win32.Build.0 = release_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared|Win32.Build.0 = debug_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared|Win32.ActiveCfg = release_shared|Win32 - {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared|Win32.Build.0 = release_shared|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SAXParser", "SAXParser\SAXParser_vs80.vcproj", "{7E4D1B8E-B4FE-432A-92C9-352C98B646B4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrettyPrint", "PrettyPrint\PrettyPrint_vs80.vcproj", "{5A6FC255-BE1D-4E09-A680-A67FF16E832F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMParser", "DOMParser\DOMParser_vs80.vcproj", "{383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DOMWriter", "DOMWriter\DOMWriter_vs80.vcproj", "{68F63799-6BCA-4058-89AC-DAC545C6AB0F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + debug_shared|Win32 = debug_shared|Win32 + release_shared|Win32 = release_shared|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {7E4D1B8E-B4FE-432A-92C9-352C98B646B4}.release_shared|Win32.Build.0 = release_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {5A6FC255-BE1D-4E09-A680-A67FF16E832F}.release_shared|Win32.Build.0 = release_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {383DAD0B-41DF-4130-B3E3-C9A6B19E9F3A}.release_shared|Win32.Build.0 = release_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {68F63799-6BCA-4058-89AC-DAC545C6AB0F}.release_shared|Win32.Build.0 = release_shared|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/XML/src/AbstractContainerNode.cpp b/XML/src/AbstractContainerNode.cpp index 3407b610c..00960304b 100644 --- a/XML/src/AbstractContainerNode.cpp +++ b/XML/src/AbstractContainerNode.cpp @@ -1,325 +1,325 @@ -// -// AbstractContainerNode.cpp -// -// $Id: //poco/1.3/XML/src/AbstractContainerNode.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/AbstractContainerNode.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument): - AbstractNode(pOwnerDocument), - _pFirstChild(0) -{ -} - - -AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument, const AbstractContainerNode& node): - AbstractNode(pOwnerDocument, node), - _pFirstChild(0) -{ -} - - -AbstractContainerNode::~AbstractContainerNode() -{ - AbstractNode* pChild = static_cast(_pFirstChild); - while (pChild) - { - AbstractNode* pDelNode = pChild; - pChild = pChild->_pNext; - pDelNode->_pNext = 0; - pDelNode->_pParent = 0; - pDelNode->release(); - } -} - - -Node* AbstractContainerNode::firstChild() const -{ - return _pFirstChild; -} - - -Node* AbstractContainerNode::lastChild() const -{ - AbstractNode* pChild = _pFirstChild; - if (pChild) - { - while (pChild->_pNext) pChild = pChild->_pNext; - return pChild; - } - return 0; -} - - -Node* AbstractContainerNode::insertBefore(Node* newChild, Node* refChild) -{ - poco_check_ptr (newChild); - - if (static_cast(newChild)->_pOwner != _pOwner && static_cast(newChild)->_pOwner != this) - throw DOMException(DOMException::WRONG_DOCUMENT_ERR); - if (refChild && static_cast(refChild)->_pParent != this) - throw DOMException(DOMException::NOT_FOUND_ERR); - if (newChild == refChild) - return newChild; - if (this == newChild) - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - - AbstractNode* pFirst = 0; - AbstractNode* pLast = 0; - if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) - { - AbstractContainerNode* pFrag = static_cast(newChild); - pFirst = pFrag->_pFirstChild; - pLast = pFirst; - if (pFirst) - { - while (pLast->_pNext) - { - pLast->_pParent = this; - pLast = pLast->_pNext; - } - pLast->_pParent = this; - } - pFrag->_pFirstChild = 0; - } - else - { - newChild->duplicate(); - AbstractContainerNode* pParent = static_cast(newChild)->_pParent; - if (pParent) pParent->removeChild(newChild); - pFirst = static_cast(newChild); - pLast = pFirst; - pFirst->_pParent = this; - } - if (_pFirstChild && pFirst) - { - AbstractNode* pCur = _pFirstChild; - if (pCur == refChild) - { - pLast->_pNext = _pFirstChild; - _pFirstChild = pFirst; - } - else - { - while (pCur && pCur->_pNext != refChild) pCur = pCur->_pNext; - if (pCur) - { - pLast->_pNext = pCur->_pNext; - pCur->_pNext = pFirst; - } - else throw DOMException(DOMException::NOT_FOUND_ERR); - } - } - else _pFirstChild = pFirst; - - if (events()) - { - while (pFirst && pFirst != pLast->_pNext) - { - pFirst->dispatchNodeInserted(); - pFirst->dispatchNodeInsertedIntoDocument(); - pFirst = pFirst->_pNext; - } - dispatchSubtreeModified(); - } - return newChild; -} - - -Node* AbstractContainerNode::replaceChild(Node* newChild, Node* oldChild) -{ - poco_check_ptr (newChild); - poco_check_ptr (oldChild); - - if (static_cast(newChild)->_pOwner != _pOwner && static_cast(newChild)->_pOwner != this) - throw DOMException(DOMException::WRONG_DOCUMENT_ERR); - if (static_cast(oldChild)->_pParent != this) - throw DOMException(DOMException::NOT_FOUND_ERR); - if (newChild == oldChild) - return newChild; - if (this == newChild) - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - - bool doEvents = events(); - if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) - { - insertBefore(newChild, oldChild); - removeChild(oldChild); - } - else - { - AbstractContainerNode* pParent = static_cast(newChild)->_pParent; - if (pParent) pParent->removeChild(newChild); - - if (oldChild == _pFirstChild) - { - if (doEvents) - { - _pFirstChild->dispatchNodeRemoved(); - _pFirstChild->dispatchNodeRemovedFromDocument(); - } - static_cast(newChild)->_pNext = static_cast(oldChild)->_pNext; - static_cast(newChild)->_pParent = this; - _pFirstChild->_pNext = 0; - _pFirstChild->_pParent = 0; - _pFirstChild = static_cast(newChild); - if (doEvents) - { - static_cast(newChild)->dispatchNodeInserted(); - static_cast(newChild)->dispatchNodeInsertedIntoDocument(); - } - } - else - { - AbstractNode* pCur = _pFirstChild; - while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext; - if (pCur) - { - poco_assert_dbg (pCur->_pNext == oldChild); - - if (doEvents) - { - static_cast(oldChild)->dispatchNodeRemoved(); - static_cast(oldChild)->dispatchNodeRemovedFromDocument(); - } - static_cast(newChild)->_pNext = static_cast(oldChild)->_pNext; - static_cast(newChild)->_pParent = this; - static_cast(oldChild)->_pNext = 0; - static_cast(oldChild)->_pParent = 0; - pCur->_pNext = static_cast(newChild); - if (doEvents) - { - static_cast(newChild)->dispatchNodeInserted(); - static_cast(newChild)->dispatchNodeInsertedIntoDocument(); - } - } - else throw DOMException(DOMException::NOT_FOUND_ERR); - } - newChild->duplicate(); - oldChild->autoRelease(); - } - if (doEvents) dispatchSubtreeModified(); - return oldChild; -} - - -Node* AbstractContainerNode::removeChild(Node* oldChild) -{ - poco_check_ptr (oldChild); - - bool doEvents = events(); - if (oldChild == _pFirstChild) - { - if (doEvents) - { - static_cast(oldChild)->dispatchNodeRemoved(); - static_cast(oldChild)->dispatchNodeRemovedFromDocument(); - } - _pFirstChild = _pFirstChild->_pNext; - static_cast(oldChild)->_pNext = 0; - static_cast(oldChild)->_pParent = 0; - } - else - { - AbstractNode* pCur = _pFirstChild; - while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext; - if (pCur) - { - if (doEvents) - { - static_cast(oldChild)->dispatchNodeRemoved(); - static_cast(oldChild)->dispatchNodeRemovedFromDocument(); - } - pCur->_pNext = pCur->_pNext->_pNext; - static_cast(oldChild)->_pNext = 0; - static_cast(oldChild)->_pParent = 0; - } - else throw DOMException(DOMException::NOT_FOUND_ERR); - } - oldChild->autoRelease(); - if (doEvents) dispatchSubtreeModified(); - return oldChild; -} - - -Node* AbstractContainerNode::appendChild(Node* newChild) -{ - return insertBefore(newChild, 0); -} - - -void AbstractContainerNode::dispatchNodeRemovedFromDocument() -{ - AbstractNode::dispatchNodeRemovedFromDocument(); - Node* pChild = firstChild(); - while (pChild) - { - static_cast(pChild)->dispatchNodeRemovedFromDocument(); - pChild = pChild->nextSibling(); - } -} - - -void AbstractContainerNode::dispatchNodeInsertedIntoDocument() -{ - AbstractNode::dispatchNodeInsertedIntoDocument(); - Node* pChild = firstChild(); - while (pChild) - { - static_cast(pChild)->dispatchNodeInsertedIntoDocument(); - pChild = pChild->nextSibling(); - } -} - - -bool AbstractContainerNode::hasChildNodes() const -{ - return _pFirstChild != 0; -} - - -bool AbstractContainerNode::hasAttributes() const -{ - return false; -} - - -} } // namespace Poco::XML +// +// AbstractContainerNode.cpp +// +// $Id: //poco/1.3/XML/src/AbstractContainerNode.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/AbstractContainerNode.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument): + AbstractNode(pOwnerDocument), + _pFirstChild(0) +{ +} + + +AbstractContainerNode::AbstractContainerNode(Document* pOwnerDocument, const AbstractContainerNode& node): + AbstractNode(pOwnerDocument, node), + _pFirstChild(0) +{ +} + + +AbstractContainerNode::~AbstractContainerNode() +{ + AbstractNode* pChild = static_cast(_pFirstChild); + while (pChild) + { + AbstractNode* pDelNode = pChild; + pChild = pChild->_pNext; + pDelNode->_pNext = 0; + pDelNode->_pParent = 0; + pDelNode->release(); + } +} + + +Node* AbstractContainerNode::firstChild() const +{ + return _pFirstChild; +} + + +Node* AbstractContainerNode::lastChild() const +{ + AbstractNode* pChild = _pFirstChild; + if (pChild) + { + while (pChild->_pNext) pChild = pChild->_pNext; + return pChild; + } + return 0; +} + + +Node* AbstractContainerNode::insertBefore(Node* newChild, Node* refChild) +{ + poco_check_ptr (newChild); + + if (static_cast(newChild)->_pOwner != _pOwner && static_cast(newChild)->_pOwner != this) + throw DOMException(DOMException::WRONG_DOCUMENT_ERR); + if (refChild && static_cast(refChild)->_pParent != this) + throw DOMException(DOMException::NOT_FOUND_ERR); + if (newChild == refChild) + return newChild; + if (this == newChild) + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + + AbstractNode* pFirst = 0; + AbstractNode* pLast = 0; + if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) + { + AbstractContainerNode* pFrag = static_cast(newChild); + pFirst = pFrag->_pFirstChild; + pLast = pFirst; + if (pFirst) + { + while (pLast->_pNext) + { + pLast->_pParent = this; + pLast = pLast->_pNext; + } + pLast->_pParent = this; + } + pFrag->_pFirstChild = 0; + } + else + { + newChild->duplicate(); + AbstractContainerNode* pParent = static_cast(newChild)->_pParent; + if (pParent) pParent->removeChild(newChild); + pFirst = static_cast(newChild); + pLast = pFirst; + pFirst->_pParent = this; + } + if (_pFirstChild && pFirst) + { + AbstractNode* pCur = _pFirstChild; + if (pCur == refChild) + { + pLast->_pNext = _pFirstChild; + _pFirstChild = pFirst; + } + else + { + while (pCur && pCur->_pNext != refChild) pCur = pCur->_pNext; + if (pCur) + { + pLast->_pNext = pCur->_pNext; + pCur->_pNext = pFirst; + } + else throw DOMException(DOMException::NOT_FOUND_ERR); + } + } + else _pFirstChild = pFirst; + + if (events()) + { + while (pFirst && pFirst != pLast->_pNext) + { + pFirst->dispatchNodeInserted(); + pFirst->dispatchNodeInsertedIntoDocument(); + pFirst = pFirst->_pNext; + } + dispatchSubtreeModified(); + } + return newChild; +} + + +Node* AbstractContainerNode::replaceChild(Node* newChild, Node* oldChild) +{ + poco_check_ptr (newChild); + poco_check_ptr (oldChild); + + if (static_cast(newChild)->_pOwner != _pOwner && static_cast(newChild)->_pOwner != this) + throw DOMException(DOMException::WRONG_DOCUMENT_ERR); + if (static_cast(oldChild)->_pParent != this) + throw DOMException(DOMException::NOT_FOUND_ERR); + if (newChild == oldChild) + return newChild; + if (this == newChild) + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + + bool doEvents = events(); + if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) + { + insertBefore(newChild, oldChild); + removeChild(oldChild); + } + else + { + AbstractContainerNode* pParent = static_cast(newChild)->_pParent; + if (pParent) pParent->removeChild(newChild); + + if (oldChild == _pFirstChild) + { + if (doEvents) + { + _pFirstChild->dispatchNodeRemoved(); + _pFirstChild->dispatchNodeRemovedFromDocument(); + } + static_cast(newChild)->_pNext = static_cast(oldChild)->_pNext; + static_cast(newChild)->_pParent = this; + _pFirstChild->_pNext = 0; + _pFirstChild->_pParent = 0; + _pFirstChild = static_cast(newChild); + if (doEvents) + { + static_cast(newChild)->dispatchNodeInserted(); + static_cast(newChild)->dispatchNodeInsertedIntoDocument(); + } + } + else + { + AbstractNode* pCur = _pFirstChild; + while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext; + if (pCur) + { + poco_assert_dbg (pCur->_pNext == oldChild); + + if (doEvents) + { + static_cast(oldChild)->dispatchNodeRemoved(); + static_cast(oldChild)->dispatchNodeRemovedFromDocument(); + } + static_cast(newChild)->_pNext = static_cast(oldChild)->_pNext; + static_cast(newChild)->_pParent = this; + static_cast(oldChild)->_pNext = 0; + static_cast(oldChild)->_pParent = 0; + pCur->_pNext = static_cast(newChild); + if (doEvents) + { + static_cast(newChild)->dispatchNodeInserted(); + static_cast(newChild)->dispatchNodeInsertedIntoDocument(); + } + } + else throw DOMException(DOMException::NOT_FOUND_ERR); + } + newChild->duplicate(); + oldChild->autoRelease(); + } + if (doEvents) dispatchSubtreeModified(); + return oldChild; +} + + +Node* AbstractContainerNode::removeChild(Node* oldChild) +{ + poco_check_ptr (oldChild); + + bool doEvents = events(); + if (oldChild == _pFirstChild) + { + if (doEvents) + { + static_cast(oldChild)->dispatchNodeRemoved(); + static_cast(oldChild)->dispatchNodeRemovedFromDocument(); + } + _pFirstChild = _pFirstChild->_pNext; + static_cast(oldChild)->_pNext = 0; + static_cast(oldChild)->_pParent = 0; + } + else + { + AbstractNode* pCur = _pFirstChild; + while (pCur && pCur->_pNext != oldChild) pCur = pCur->_pNext; + if (pCur) + { + if (doEvents) + { + static_cast(oldChild)->dispatchNodeRemoved(); + static_cast(oldChild)->dispatchNodeRemovedFromDocument(); + } + pCur->_pNext = pCur->_pNext->_pNext; + static_cast(oldChild)->_pNext = 0; + static_cast(oldChild)->_pParent = 0; + } + else throw DOMException(DOMException::NOT_FOUND_ERR); + } + oldChild->autoRelease(); + if (doEvents) dispatchSubtreeModified(); + return oldChild; +} + + +Node* AbstractContainerNode::appendChild(Node* newChild) +{ + return insertBefore(newChild, 0); +} + + +void AbstractContainerNode::dispatchNodeRemovedFromDocument() +{ + AbstractNode::dispatchNodeRemovedFromDocument(); + Node* pChild = firstChild(); + while (pChild) + { + static_cast(pChild)->dispatchNodeRemovedFromDocument(); + pChild = pChild->nextSibling(); + } +} + + +void AbstractContainerNode::dispatchNodeInsertedIntoDocument() +{ + AbstractNode::dispatchNodeInsertedIntoDocument(); + Node* pChild = firstChild(); + while (pChild) + { + static_cast(pChild)->dispatchNodeInsertedIntoDocument(); + pChild = pChild->nextSibling(); + } +} + + +bool AbstractContainerNode::hasChildNodes() const +{ + return _pFirstChild != 0; +} + + +bool AbstractContainerNode::hasAttributes() const +{ + return false; +} + + +} } // namespace Poco::XML diff --git a/XML/src/AbstractNode.cpp b/XML/src/AbstractNode.cpp index 479a9bc4b..dde4ae59e 100644 --- a/XML/src/AbstractNode.cpp +++ b/XML/src/AbstractNode.cpp @@ -1,377 +1,377 @@ -// -// AbstractNode.cpp -// -// $Id: //poco/1.3/XML/src/AbstractNode.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/AbstractNode.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/ChildNodesList.h" -#include "Poco/DOM/EventDispatcher.h" -#include "Poco/DOM/DOMException.h" -#include "Poco/DOM/EventException.h" -#include "Poco/DOM/DOMImplementation.h" -#include "Poco/DOM/Attr.h" -#include "Poco/XML/Name.h" -#include "Poco/DOM/AutoPtr.h" - - -namespace Poco { -namespace XML { - - -const XMLString AbstractNode::NODE_NAME = toXMLString("#node"); -const XMLString AbstractNode::EMPTY_STRING; - - -AbstractNode::AbstractNode(Document* pOwnerDocument): - _pParent(0), - _pNext(0), - _pOwner(pOwnerDocument), - _pEventDispatcher(0) -{ -} - - -AbstractNode::AbstractNode(Document* pOwnerDocument, const AbstractNode& node): - _pParent(0), - _pNext(0), - _pOwner(pOwnerDocument), - _pEventDispatcher(0) -{ -} - - -AbstractNode::~AbstractNode() -{ - delete _pEventDispatcher; - if (_pNext) _pNext->release(); -} - - -void AbstractNode::autoRelease() -{ - _pOwner->autoReleasePool().add(this); -} - - -const XMLString& AbstractNode::nodeName() const -{ - return NODE_NAME; -} - - -const XMLString& AbstractNode::getNodeValue() const -{ - return EMPTY_STRING; -} - - -void AbstractNode::setNodeValue(const XMLString& value) -{ - throw DOMException(DOMException::NO_DATA_ALLOWED_ERR); -} - - -Node* AbstractNode::parentNode() const -{ - return _pParent; -} - - -NodeList* AbstractNode::childNodes() const -{ - return new ChildNodesList(this); -} - - -Node* AbstractNode::firstChild() const -{ - return 0; -} - - -Node* AbstractNode::lastChild() const -{ - return 0; -} - - -Node* AbstractNode::previousSibling() const -{ - if (_pParent) - { - AbstractNode* pSibling = _pParent->_pFirstChild; - while (pSibling) - { - if (pSibling->_pNext == this) return pSibling; - pSibling = pSibling->_pNext; - } - } - return 0; -} - - -Node* AbstractNode::nextSibling() const -{ - return _pNext; -} - - -NamedNodeMap* AbstractNode::attributes() const -{ - return 0; -} - - -Document* AbstractNode::ownerDocument() const -{ - return _pOwner; -} - - -Node* AbstractNode::insertBefore(Node* newChild, Node* refChild) -{ - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); -} - - -Node* AbstractNode::replaceChild(Node* newChild, Node* oldChild) -{ - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); -} - - -Node* AbstractNode::removeChild(Node* oldChild) -{ - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); -} - - -Node* AbstractNode::appendChild(Node* newChild) -{ - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); -} - - -bool AbstractNode::hasChildNodes() const -{ - return false; -} - - -Node* AbstractNode::cloneNode(bool deep) const -{ - return copyNode(deep, _pOwner); -} - - -void AbstractNode::normalize() -{ -} - - -bool AbstractNode::isSupported(const XMLString& feature, const XMLString& version) const -{ - return DOMImplementation::instance().hasFeature(feature, version); -} - - -const XMLString& AbstractNode::namespaceURI() const -{ - return EMPTY_STRING; -} - - -XMLString AbstractNode::prefix() const -{ - return EMPTY_STRING; -} - - -const XMLString& AbstractNode::localName() const -{ - return EMPTY_STRING; -} - - -bool AbstractNode::hasAttributes() const -{ - return false; -} - - -XMLString AbstractNode::innerText() const -{ - return EMPTY_STRING; -} - - -void AbstractNode::addEventListener(const XMLString& type, EventListener* listener, bool useCapture) -{ - if (_pEventDispatcher) - _pEventDispatcher->removeEventListener(type, listener, useCapture); - else - _pEventDispatcher = new EventDispatcher; - - _pEventDispatcher->addEventListener(type, listener, useCapture); -} - - -void AbstractNode::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) -{ - if (_pEventDispatcher) - _pEventDispatcher->removeEventListener(type, listener, useCapture); -} - - -bool AbstractNode::dispatchEvent(Event* evt) -{ - if (eventsSuspended()) return true; - - if (evt->type().empty()) throw EventException(EventException::UNSPECIFIED_EVENT_TYPE_ERR); - - evt->setTarget(this); - evt->setCurrentPhase(Event::CAPTURING_PHASE); - - if (_pParent) _pParent->captureEvent(evt); - - if (_pEventDispatcher && !evt->isStopped()) - { - evt->setCurrentPhase(Event::AT_TARGET); - evt->setCurrentTarget(this); - _pEventDispatcher->dispatchEvent(evt); - } - if (!evt->isStopped() && evt->bubbles() && _pParent) - { - evt->setCurrentPhase(Event::BUBBLING_PHASE); - _pParent->bubbleEvent(evt); - } - - return evt->isCanceled(); -} - - -void AbstractNode::captureEvent(Event* evt) -{ - if (_pParent) - _pParent->captureEvent(evt); - - if (_pEventDispatcher && !evt->isStopped()) - { - evt->setCurrentTarget(this); - _pEventDispatcher->captureEvent(evt); - } -} - - -void AbstractNode::bubbleEvent(Event* evt) -{ - evt->setCurrentTarget(this); - if (_pEventDispatcher) - { - _pEventDispatcher->bubbleEvent(evt); - } - if (_pParent && !evt->isStopped()) - _pParent->bubbleEvent(evt); -} - - -void AbstractNode::dispatchSubtreeModified() -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMSubtreeModified, this, true, false, 0); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchNodeInserted() -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInserted, this, true, false, parentNode()); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchNodeRemoved() -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemoved, this, true, false, parentNode()); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchNodeRemovedFromDocument() -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemovedFromDocument, this, false, false, 0); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchNodeInsertedIntoDocument() -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInsertedIntoDocument, this, false, false, 0); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue) -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMAttrModified, this, true, false, pAttr, prevValue, newValue, pAttr->name(), changeType); - dispatchEvent(pEvent.get()); -} - - -void AbstractNode::dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue) -{ - AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMCharacterDataModified, this, true, false, 0, prevValue, newValue, EMPTY_STRING, MutationEvent::MODIFICATION); - dispatchEvent(pEvent.get()); -} - - -bool AbstractNode::events() const -{ - return _pOwner->events(); -} - - -bool AbstractNode::eventsSuspended() const -{ - return _pOwner->eventsSuspended(); -} - - -void AbstractNode::setOwnerDocument(Document* pOwnerDocument) -{ - _pOwner = pOwnerDocument; -} - - -} } // namespace Poco::XML +// +// AbstractNode.cpp +// +// $Id: //poco/1.3/XML/src/AbstractNode.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/AbstractNode.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/ChildNodesList.h" +#include "Poco/DOM/EventDispatcher.h" +#include "Poco/DOM/DOMException.h" +#include "Poco/DOM/EventException.h" +#include "Poco/DOM/DOMImplementation.h" +#include "Poco/DOM/Attr.h" +#include "Poco/XML/Name.h" +#include "Poco/DOM/AutoPtr.h" + + +namespace Poco { +namespace XML { + + +const XMLString AbstractNode::NODE_NAME = toXMLString("#node"); +const XMLString AbstractNode::EMPTY_STRING; + + +AbstractNode::AbstractNode(Document* pOwnerDocument): + _pParent(0), + _pNext(0), + _pOwner(pOwnerDocument), + _pEventDispatcher(0) +{ +} + + +AbstractNode::AbstractNode(Document* pOwnerDocument, const AbstractNode& node): + _pParent(0), + _pNext(0), + _pOwner(pOwnerDocument), + _pEventDispatcher(0) +{ +} + + +AbstractNode::~AbstractNode() +{ + delete _pEventDispatcher; + if (_pNext) _pNext->release(); +} + + +void AbstractNode::autoRelease() +{ + _pOwner->autoReleasePool().add(this); +} + + +const XMLString& AbstractNode::nodeName() const +{ + return NODE_NAME; +} + + +const XMLString& AbstractNode::getNodeValue() const +{ + return EMPTY_STRING; +} + + +void AbstractNode::setNodeValue(const XMLString& value) +{ + throw DOMException(DOMException::NO_DATA_ALLOWED_ERR); +} + + +Node* AbstractNode::parentNode() const +{ + return _pParent; +} + + +NodeList* AbstractNode::childNodes() const +{ + return new ChildNodesList(this); +} + + +Node* AbstractNode::firstChild() const +{ + return 0; +} + + +Node* AbstractNode::lastChild() const +{ + return 0; +} + + +Node* AbstractNode::previousSibling() const +{ + if (_pParent) + { + AbstractNode* pSibling = _pParent->_pFirstChild; + while (pSibling) + { + if (pSibling->_pNext == this) return pSibling; + pSibling = pSibling->_pNext; + } + } + return 0; +} + + +Node* AbstractNode::nextSibling() const +{ + return _pNext; +} + + +NamedNodeMap* AbstractNode::attributes() const +{ + return 0; +} + + +Document* AbstractNode::ownerDocument() const +{ + return _pOwner; +} + + +Node* AbstractNode::insertBefore(Node* newChild, Node* refChild) +{ + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); +} + + +Node* AbstractNode::replaceChild(Node* newChild, Node* oldChild) +{ + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); +} + + +Node* AbstractNode::removeChild(Node* oldChild) +{ + throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); +} + + +Node* AbstractNode::appendChild(Node* newChild) +{ + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); +} + + +bool AbstractNode::hasChildNodes() const +{ + return false; +} + + +Node* AbstractNode::cloneNode(bool deep) const +{ + return copyNode(deep, _pOwner); +} + + +void AbstractNode::normalize() +{ +} + + +bool AbstractNode::isSupported(const XMLString& feature, const XMLString& version) const +{ + return DOMImplementation::instance().hasFeature(feature, version); +} + + +const XMLString& AbstractNode::namespaceURI() const +{ + return EMPTY_STRING; +} + + +XMLString AbstractNode::prefix() const +{ + return EMPTY_STRING; +} + + +const XMLString& AbstractNode::localName() const +{ + return EMPTY_STRING; +} + + +bool AbstractNode::hasAttributes() const +{ + return false; +} + + +XMLString AbstractNode::innerText() const +{ + return EMPTY_STRING; +} + + +void AbstractNode::addEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + if (_pEventDispatcher) + _pEventDispatcher->removeEventListener(type, listener, useCapture); + else + _pEventDispatcher = new EventDispatcher; + + _pEventDispatcher->addEventListener(type, listener, useCapture); +} + + +void AbstractNode::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + if (_pEventDispatcher) + _pEventDispatcher->removeEventListener(type, listener, useCapture); +} + + +bool AbstractNode::dispatchEvent(Event* evt) +{ + if (eventsSuspended()) return true; + + if (evt->type().empty()) throw EventException(EventException::UNSPECIFIED_EVENT_TYPE_ERR); + + evt->setTarget(this); + evt->setCurrentPhase(Event::CAPTURING_PHASE); + + if (_pParent) _pParent->captureEvent(evt); + + if (_pEventDispatcher && !evt->isStopped()) + { + evt->setCurrentPhase(Event::AT_TARGET); + evt->setCurrentTarget(this); + _pEventDispatcher->dispatchEvent(evt); + } + if (!evt->isStopped() && evt->bubbles() && _pParent) + { + evt->setCurrentPhase(Event::BUBBLING_PHASE); + _pParent->bubbleEvent(evt); + } + + return evt->isCanceled(); +} + + +void AbstractNode::captureEvent(Event* evt) +{ + if (_pParent) + _pParent->captureEvent(evt); + + if (_pEventDispatcher && !evt->isStopped()) + { + evt->setCurrentTarget(this); + _pEventDispatcher->captureEvent(evt); + } +} + + +void AbstractNode::bubbleEvent(Event* evt) +{ + evt->setCurrentTarget(this); + if (_pEventDispatcher) + { + _pEventDispatcher->bubbleEvent(evt); + } + if (_pParent && !evt->isStopped()) + _pParent->bubbleEvent(evt); +} + + +void AbstractNode::dispatchSubtreeModified() +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMSubtreeModified, this, true, false, 0); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchNodeInserted() +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInserted, this, true, false, parentNode()); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchNodeRemoved() +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemoved, this, true, false, parentNode()); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchNodeRemovedFromDocument() +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeRemovedFromDocument, this, false, false, 0); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchNodeInsertedIntoDocument() +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMNodeInsertedIntoDocument, this, false, false, 0); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchAttrModified(Attr* pAttr, MutationEvent::AttrChangeType changeType, const XMLString& prevValue, const XMLString& newValue) +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMAttrModified, this, true, false, pAttr, prevValue, newValue, pAttr->name(), changeType); + dispatchEvent(pEvent.get()); +} + + +void AbstractNode::dispatchCharacterDataModified(const XMLString& prevValue, const XMLString& newValue) +{ + AutoPtr pEvent = new MutationEvent(_pOwner, MutationEvent::DOMCharacterDataModified, this, true, false, 0, prevValue, newValue, EMPTY_STRING, MutationEvent::MODIFICATION); + dispatchEvent(pEvent.get()); +} + + +bool AbstractNode::events() const +{ + return _pOwner->events(); +} + + +bool AbstractNode::eventsSuspended() const +{ + return _pOwner->eventsSuspended(); +} + + +void AbstractNode::setOwnerDocument(Document* pOwnerDocument) +{ + _pOwner = pOwnerDocument; +} + + +} } // namespace Poco::XML diff --git a/XML/src/Attr.cpp b/XML/src/Attr.cpp index 45eafb264..bb679aeb3 100644 --- a/XML/src/Attr.cpp +++ b/XML/src/Attr.cpp @@ -1,155 +1,155 @@ -// -// Attr.cpp -// -// $Id: //poco/1.3/XML/src/Attr.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Document.h" -#include "Poco/XML/NamePool.h" - - -namespace Poco { -namespace XML { - - -Attr::Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified): - AbstractNode(pOwnerDocument), - _name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)), - _value(value), - _specified(specified) -{ -} - - -Attr::Attr(Document* pOwnerDocument, const Attr& attr): - AbstractNode(pOwnerDocument, attr), - _name(pOwnerDocument->namePool().insert(attr._name)), - _value(attr._value), - _specified(attr._specified) -{ -} - - -Attr::~Attr() -{ -} - - -void Attr::setValue(const XMLString& value) -{ - XMLString oldValue = _value; - _value = value; - _specified = true; - if (_pParent && !_pOwner->eventsSuspended()) - _pParent->dispatchAttrModified(this, MutationEvent::MODIFICATION, oldValue, value); -} - - -Node* Attr::parentNode() const -{ - return 0; -} - - -Node* Attr::previousSibling() const -{ - if (_pParent) - { - Attr* pSibling = static_cast(_pParent)->_pFirstAttr; - while (pSibling) - { - if (pSibling->_pNext == const_cast(this)) return pSibling; - pSibling = static_cast(pSibling->_pNext); - } - return pSibling; - } - return 0; -} - - -const XMLString& Attr::nodeName() const -{ - return _name.qname(); -} - - -const XMLString& Attr::getNodeValue() const -{ - return _value; -} - - -void Attr::setNodeValue(const XMLString& value) -{ - setValue(value); -} - - -unsigned short Attr::nodeType() const -{ - return ATTRIBUTE_NODE; -} - - -const XMLString& Attr::namespaceURI() const -{ - return _name.namespaceURI(); -} - - -XMLString Attr::prefix() const -{ - return _name.prefix(); -} - - -const XMLString& Attr::localName() const -{ - return _name.localName(); -} - - -XMLString Attr::innerText() const -{ - return nodeValue(); -} - - -Node* Attr::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new Attr(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// Attr.cpp +// +// $Id: //poco/1.3/XML/src/Attr.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Document.h" +#include "Poco/XML/NamePool.h" + + +namespace Poco { +namespace XML { + + +Attr::Attr(Document* pOwnerDocument, Element* pOwnerElement, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& value, bool specified): + AbstractNode(pOwnerDocument), + _name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)), + _value(value), + _specified(specified) +{ +} + + +Attr::Attr(Document* pOwnerDocument, const Attr& attr): + AbstractNode(pOwnerDocument, attr), + _name(pOwnerDocument->namePool().insert(attr._name)), + _value(attr._value), + _specified(attr._specified) +{ +} + + +Attr::~Attr() +{ +} + + +void Attr::setValue(const XMLString& value) +{ + XMLString oldValue = _value; + _value = value; + _specified = true; + if (_pParent && !_pOwner->eventsSuspended()) + _pParent->dispatchAttrModified(this, MutationEvent::MODIFICATION, oldValue, value); +} + + +Node* Attr::parentNode() const +{ + return 0; +} + + +Node* Attr::previousSibling() const +{ + if (_pParent) + { + Attr* pSibling = static_cast(_pParent)->_pFirstAttr; + while (pSibling) + { + if (pSibling->_pNext == const_cast(this)) return pSibling; + pSibling = static_cast(pSibling->_pNext); + } + return pSibling; + } + return 0; +} + + +const XMLString& Attr::nodeName() const +{ + return _name.qname(); +} + + +const XMLString& Attr::getNodeValue() const +{ + return _value; +} + + +void Attr::setNodeValue(const XMLString& value) +{ + setValue(value); +} + + +unsigned short Attr::nodeType() const +{ + return ATTRIBUTE_NODE; +} + + +const XMLString& Attr::namespaceURI() const +{ + return _name.namespaceURI(); +} + + +XMLString Attr::prefix() const +{ + return _name.prefix(); +} + + +const XMLString& Attr::localName() const +{ + return _name.localName(); +} + + +XMLString Attr::innerText() const +{ + return nodeValue(); +} + + +Node* Attr::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new Attr(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/AttrMap.cpp b/XML/src/AttrMap.cpp index 10171092f..0ce4b4848 100644 --- a/XML/src/AttrMap.cpp +++ b/XML/src/AttrMap.cpp @@ -1,145 +1,145 @@ -// -// AttrMap.cpp -// -// $Id: //poco/1.3/XML/src/AttrMap.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/AttrMap.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -AttrMap::AttrMap(Element* pElement): - _pElement(pElement) -{ - poco_check_ptr (pElement); - - _pElement->duplicate(); -} - - -AttrMap::~AttrMap() -{ - _pElement->release(); -} - - -Node* AttrMap::getNamedItem(const XMLString& name) const -{ - return _pElement->getAttributeNode(name); -} - - -Node* AttrMap::setNamedItem(Node* arg) -{ - poco_check_ptr (arg); - - if (arg->nodeType() != Node::ATTRIBUTE_NODE) - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - - return _pElement->setAttributeNode(static_cast(arg)); -} - - -Node* AttrMap::removeNamedItem(const XMLString& name) -{ - Attr* pAttr = _pElement->getAttributeNode(name); - if (pAttr) - return _pElement->removeAttributeNode(pAttr); - else - return 0; -} - - -Node* AttrMap::item(unsigned long index) const -{ - AbstractNode* pAttr = _pElement->_pFirstAttr; - while (index-- > 0 && pAttr) pAttr = static_cast(pAttr->nextSibling()); - return pAttr; -} - - -unsigned long AttrMap::length() const -{ - unsigned long result = 0; - AbstractNode* pAttr = _pElement->_pFirstAttr; - while (pAttr) - { - pAttr = static_cast(pAttr->nextSibling()); - ++result; - } - return result; -} - - -Node* AttrMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - return _pElement->getAttributeNodeNS(namespaceURI, localName); -} - - -Node* AttrMap::setNamedItemNS(Node* arg) -{ - poco_check_ptr (arg); - - if (arg->nodeType() != Node::ATTRIBUTE_NODE) - throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - - return _pElement->setAttributeNodeNS(static_cast(arg)); -} - - -Node* AttrMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) -{ - Attr* pAttr = _pElement->getAttributeNodeNS(namespaceURI, localName); - if (pAttr) - return _pElement->removeAttributeNode(pAttr); - else - return 0; -} - - -void AttrMap::autoRelease() -{ - _pElement->ownerDocument()->autoReleasePool().add(this); -} - - -} } // namespace Poco::XML - +// +// AttrMap.cpp +// +// $Id: //poco/1.3/XML/src/AttrMap.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/AttrMap.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +AttrMap::AttrMap(Element* pElement): + _pElement(pElement) +{ + poco_check_ptr (pElement); + + _pElement->duplicate(); +} + + +AttrMap::~AttrMap() +{ + _pElement->release(); +} + + +Node* AttrMap::getNamedItem(const XMLString& name) const +{ + return _pElement->getAttributeNode(name); +} + + +Node* AttrMap::setNamedItem(Node* arg) +{ + poco_check_ptr (arg); + + if (arg->nodeType() != Node::ATTRIBUTE_NODE) + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + + return _pElement->setAttributeNode(static_cast(arg)); +} + + +Node* AttrMap::removeNamedItem(const XMLString& name) +{ + Attr* pAttr = _pElement->getAttributeNode(name); + if (pAttr) + return _pElement->removeAttributeNode(pAttr); + else + return 0; +} + + +Node* AttrMap::item(unsigned long index) const +{ + AbstractNode* pAttr = _pElement->_pFirstAttr; + while (index-- > 0 && pAttr) pAttr = static_cast(pAttr->nextSibling()); + return pAttr; +} + + +unsigned long AttrMap::length() const +{ + unsigned long result = 0; + AbstractNode* pAttr = _pElement->_pFirstAttr; + while (pAttr) + { + pAttr = static_cast(pAttr->nextSibling()); + ++result; + } + return result; +} + + +Node* AttrMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + return _pElement->getAttributeNodeNS(namespaceURI, localName); +} + + +Node* AttrMap::setNamedItemNS(Node* arg) +{ + poco_check_ptr (arg); + + if (arg->nodeType() != Node::ATTRIBUTE_NODE) + throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + + return _pElement->setAttributeNodeNS(static_cast(arg)); +} + + +Node* AttrMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) +{ + Attr* pAttr = _pElement->getAttributeNodeNS(namespaceURI, localName); + if (pAttr) + return _pElement->removeAttributeNode(pAttr); + else + return 0; +} + + +void AttrMap::autoRelease() +{ + _pElement->ownerDocument()->autoReleasePool().add(this); +} + + +} } // namespace Poco::XML + diff --git a/XML/src/Attributes.cpp b/XML/src/Attributes.cpp index 05f54c1fb..f6475d4cb 100644 --- a/XML/src/Attributes.cpp +++ b/XML/src/Attributes.cpp @@ -1,49 +1,49 @@ -// -// Attributes.cpp -// -// $Id: //poco/1.3/XML/src/Attributes.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/Attributes.h" - - -namespace Poco { -namespace XML { - - -Attributes::~Attributes() -{ -} - - -} } // namespace Poco::XML +// +// Attributes.cpp +// +// $Id: //poco/1.3/XML/src/Attributes.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/Attributes.h" + + +namespace Poco { +namespace XML { + + +Attributes::~Attributes() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/CDATASection.cpp b/XML/src/CDATASection.cpp index 8314ea2dc..2b307e1de 100644 --- a/XML/src/CDATASection.cpp +++ b/XML/src/CDATASection.cpp @@ -1,96 +1,96 @@ -// -// CDATASection.cpp -// -// $Id: //poco/1.3/XML/src/CDATASection.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/CDATASection.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -const XMLString CDATASection::NODE_NAME = toXMLString("#cdata-section"); - - -CDATASection::CDATASection(Document* pOwnerDocument, const XMLString& data): - Text(pOwnerDocument, data) -{ -} - - -CDATASection::CDATASection(Document* pOwnerDocument, const CDATASection& sec): - Text(pOwnerDocument, sec) -{ -} - - -CDATASection::~CDATASection() -{ -} - - -Text* CDATASection::splitText(unsigned long offset) -{ - Node* pParent = parentNode(); - if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - int n = length() - offset; - Text* pNew = ownerDocument()->createCDATASection(substringData(offset, n)); - deleteData(offset, n); - pParent->insertBefore(pNew, nextSibling())->release(); - return pNew; -} - - -const XMLString& CDATASection::nodeName() const -{ - return NODE_NAME; -} - - -unsigned short CDATASection::nodeType() const -{ - return Node::CDATA_SECTION_NODE; -} - - -Node* CDATASection::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new CDATASection(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// CDATASection.cpp +// +// $Id: //poco/1.3/XML/src/CDATASection.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/CDATASection.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +const XMLString CDATASection::NODE_NAME = toXMLString("#cdata-section"); + + +CDATASection::CDATASection(Document* pOwnerDocument, const XMLString& data): + Text(pOwnerDocument, data) +{ +} + + +CDATASection::CDATASection(Document* pOwnerDocument, const CDATASection& sec): + Text(pOwnerDocument, sec) +{ +} + + +CDATASection::~CDATASection() +{ +} + + +Text* CDATASection::splitText(unsigned long offset) +{ + Node* pParent = parentNode(); + if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + int n = length() - offset; + Text* pNew = ownerDocument()->createCDATASection(substringData(offset, n)); + deleteData(offset, n); + pParent->insertBefore(pNew, nextSibling())->release(); + return pNew; +} + + +const XMLString& CDATASection::nodeName() const +{ + return NODE_NAME; +} + + +unsigned short CDATASection::nodeType() const +{ + return Node::CDATA_SECTION_NODE; +} + + +Node* CDATASection::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new CDATASection(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/CharacterData.cpp b/XML/src/CharacterData.cpp index c65e9f8c9..a8a3f4caa 100644 --- a/XML/src/CharacterData.cpp +++ b/XML/src/CharacterData.cpp @@ -1,141 +1,141 @@ -// -// CharacterData.cpp -// -// $Id: //poco/1.3/XML/src/CharacterData.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/CharacterData.h" -#include "Poco/DOM/DOMException.h" -#include "Poco/String.h" - - -namespace Poco { -namespace XML { - - -CharacterData::CharacterData(Document* pOwnerDocument, const XMLString& data): - AbstractNode(pOwnerDocument), - _data(data) -{ -} - - -CharacterData::CharacterData(Document* pOwnerDocument, const CharacterData& data): - AbstractNode(pOwnerDocument, data), - _data(data._data) -{ -} - - -CharacterData::~CharacterData() -{ -} - - -void CharacterData::setData(const XMLString& data) -{ - XMLString oldData = getData(); - _data = data; - if (events()) dispatchCharacterDataModified(oldData, _data); -} - - -XMLString CharacterData::substringData(unsigned long offset, unsigned long count) const -{ - if (offset >= _data.length()) - throw DOMException(DOMException::INDEX_SIZE_ERR); - - return _data.substr(offset, count); -} - - -void CharacterData::appendData(const XMLString& arg) -{ - XMLString oldData = _data; - _data.append(arg); - if (events()) dispatchCharacterDataModified(oldData, _data); -} - - -void CharacterData::insertData(unsigned long offset, const XMLString& arg) -{ - if (offset > _data.length()) - throw DOMException(DOMException::INDEX_SIZE_ERR); - - XMLString oldData = _data; - _data.insert(offset, arg); - if (events()) dispatchCharacterDataModified(oldData, _data); -} - - -void CharacterData::deleteData(unsigned long offset, unsigned long count) -{ - if (offset >= _data.length()) - throw DOMException(DOMException::INDEX_SIZE_ERR); - - XMLString oldData = _data; - _data.replace(offset, count, EMPTY_STRING); - if (events()) dispatchCharacterDataModified(oldData, _data); -} - - -void CharacterData::replaceData(unsigned long offset, unsigned long count, const XMLString& arg) -{ - if (offset >= _data.length()) - throw DOMException(DOMException::INDEX_SIZE_ERR); - - XMLString oldData = _data; - _data.replace(offset, count, arg); - if (events()) dispatchCharacterDataModified(oldData, _data); -} - - -const XMLString& CharacterData::getNodeValue() const -{ - return _data; -} - - -void CharacterData::setNodeValue(const XMLString& value) -{ - setData(value); -} - - -XMLString CharacterData::trimmedData() const -{ - return Poco::trim(_data); -} - - -} } // namespace Poco::XML +// +// CharacterData.cpp +// +// $Id: //poco/1.3/XML/src/CharacterData.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/CharacterData.h" +#include "Poco/DOM/DOMException.h" +#include "Poco/String.h" + + +namespace Poco { +namespace XML { + + +CharacterData::CharacterData(Document* pOwnerDocument, const XMLString& data): + AbstractNode(pOwnerDocument), + _data(data) +{ +} + + +CharacterData::CharacterData(Document* pOwnerDocument, const CharacterData& data): + AbstractNode(pOwnerDocument, data), + _data(data._data) +{ +} + + +CharacterData::~CharacterData() +{ +} + + +void CharacterData::setData(const XMLString& data) +{ + XMLString oldData = getData(); + _data = data; + if (events()) dispatchCharacterDataModified(oldData, _data); +} + + +XMLString CharacterData::substringData(unsigned long offset, unsigned long count) const +{ + if (offset >= _data.length()) + throw DOMException(DOMException::INDEX_SIZE_ERR); + + return _data.substr(offset, count); +} + + +void CharacterData::appendData(const XMLString& arg) +{ + XMLString oldData = _data; + _data.append(arg); + if (events()) dispatchCharacterDataModified(oldData, _data); +} + + +void CharacterData::insertData(unsigned long offset, const XMLString& arg) +{ + if (offset > _data.length()) + throw DOMException(DOMException::INDEX_SIZE_ERR); + + XMLString oldData = _data; + _data.insert(offset, arg); + if (events()) dispatchCharacterDataModified(oldData, _data); +} + + +void CharacterData::deleteData(unsigned long offset, unsigned long count) +{ + if (offset >= _data.length()) + throw DOMException(DOMException::INDEX_SIZE_ERR); + + XMLString oldData = _data; + _data.replace(offset, count, EMPTY_STRING); + if (events()) dispatchCharacterDataModified(oldData, _data); +} + + +void CharacterData::replaceData(unsigned long offset, unsigned long count, const XMLString& arg) +{ + if (offset >= _data.length()) + throw DOMException(DOMException::INDEX_SIZE_ERR); + + XMLString oldData = _data; + _data.replace(offset, count, arg); + if (events()) dispatchCharacterDataModified(oldData, _data); +} + + +const XMLString& CharacterData::getNodeValue() const +{ + return _data; +} + + +void CharacterData::setNodeValue(const XMLString& value) +{ + setData(value); +} + + +XMLString CharacterData::trimmedData() const +{ + return Poco::trim(_data); +} + + +} } // namespace Poco::XML diff --git a/XML/src/ChildNodesList.cpp b/XML/src/ChildNodesList.cpp index dc280416f..44eea4df3 100644 --- a/XML/src/ChildNodesList.cpp +++ b/XML/src/ChildNodesList.cpp @@ -1,92 +1,92 @@ -// -// ChildNodesList.cpp -// -// $Id: //poco/1.3/XML/src/ChildNodesList.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/ChildNodesList.h" -#include "Poco/DOM/Node.h" -#include "Poco/DOM/Document.h" - - -namespace Poco { -namespace XML { - - -ChildNodesList::ChildNodesList(const Node* pParent): - _pParent(pParent) -{ - poco_check_ptr (pParent); - - _pParent->duplicate(); -} - - -ChildNodesList::~ChildNodesList() -{ - _pParent->release(); -} - - -Node* ChildNodesList::item(unsigned long index) const -{ - unsigned long n = 0; - Node* pCur = _pParent->firstChild(); - while (pCur && n++ < index) - { - pCur = pCur->nextSibling(); - } - return pCur; -} - - -unsigned long ChildNodesList::length() const -{ - unsigned long n = 0; - Node* pCur = _pParent->firstChild(); - while (pCur) - { - ++n; - pCur = pCur->nextSibling(); - } - return n; -} - - -void ChildNodesList::autoRelease() -{ - _pParent->ownerDocument()->autoReleasePool().add(this); -} - - -} } // namespace Poco::XML +// +// ChildNodesList.cpp +// +// $Id: //poco/1.3/XML/src/ChildNodesList.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/ChildNodesList.h" +#include "Poco/DOM/Node.h" +#include "Poco/DOM/Document.h" + + +namespace Poco { +namespace XML { + + +ChildNodesList::ChildNodesList(const Node* pParent): + _pParent(pParent) +{ + poco_check_ptr (pParent); + + _pParent->duplicate(); +} + + +ChildNodesList::~ChildNodesList() +{ + _pParent->release(); +} + + +Node* ChildNodesList::item(unsigned long index) const +{ + unsigned long n = 0; + Node* pCur = _pParent->firstChild(); + while (pCur && n++ < index) + { + pCur = pCur->nextSibling(); + } + return pCur; +} + + +unsigned long ChildNodesList::length() const +{ + unsigned long n = 0; + Node* pCur = _pParent->firstChild(); + while (pCur) + { + ++n; + pCur = pCur->nextSibling(); + } + return n; +} + + +void ChildNodesList::autoRelease() +{ + _pParent->ownerDocument()->autoReleasePool().add(this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/Comment.cpp b/XML/src/Comment.cpp index acb926abd..458cf0cbc 100644 --- a/XML/src/Comment.cpp +++ b/XML/src/Comment.cpp @@ -1,82 +1,82 @@ -// -// Comment.cpp -// -// $Id: //poco/1.3/XML/src/Comment.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Comment.h" - - -namespace Poco { -namespace XML { - - -const XMLString Comment::NODE_NAME = toXMLString("#comment"); - - -Comment::Comment(Document* pOwnerDocument, const XMLString& data): - CharacterData(pOwnerDocument, data) -{ -} - - -Comment::Comment(Document* pOwnerDocument, const Comment& comment): - CharacterData(pOwnerDocument, comment) -{ -} - - -Comment::~Comment() -{ -} - - -const XMLString& Comment::nodeName() const -{ - return NODE_NAME; -} - - -unsigned short Comment::nodeType() const -{ - return Node::COMMENT_NODE; -} - - -Node* Comment::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new Comment(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// Comment.cpp +// +// $Id: //poco/1.3/XML/src/Comment.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Comment.h" + + +namespace Poco { +namespace XML { + + +const XMLString Comment::NODE_NAME = toXMLString("#comment"); + + +Comment::Comment(Document* pOwnerDocument, const XMLString& data): + CharacterData(pOwnerDocument, data) +{ +} + + +Comment::Comment(Document* pOwnerDocument, const Comment& comment): + CharacterData(pOwnerDocument, comment) +{ +} + + +Comment::~Comment() +{ +} + + +const XMLString& Comment::nodeName() const +{ + return NODE_NAME; +} + + +unsigned short Comment::nodeType() const +{ + return Node::COMMENT_NODE; +} + + +Node* Comment::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new Comment(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/ContentHandler.cpp b/XML/src/ContentHandler.cpp index 636d31c76..979d0ecb7 100644 --- a/XML/src/ContentHandler.cpp +++ b/XML/src/ContentHandler.cpp @@ -1,49 +1,49 @@ -// -// ContentHandler.cpp -// -// $Id: //poco/1.3/XML/src/ContentHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/ContentHandler.h" - - -namespace Poco { -namespace XML { - - -ContentHandler::~ContentHandler() -{ -} - - -} } // namespace Poco::XML +// +// ContentHandler.cpp +// +// $Id: //poco/1.3/XML/src/ContentHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/ContentHandler.h" + + +namespace Poco { +namespace XML { + + +ContentHandler::~ContentHandler() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMBuilder.cpp b/XML/src/DOMBuilder.cpp index 76ce9531e..e61ea5529 100644 --- a/XML/src/DOMBuilder.cpp +++ b/XML/src/DOMBuilder.cpp @@ -1,334 +1,334 @@ -// -// DOMBuilder.cpp -// -// $Id: //poco/1.3/XML/src/DOMBuilder.cpp#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMBuilder -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMBuilder.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/CharacterData.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/Comment.h" -#include "Poco/DOM/CDATASection.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Entity.h" -#include "Poco/DOM/EntityReference.h" -#include "Poco/DOM/Notation.h" -#include "Poco/DOM/ProcessingInstruction.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/SAX/XMLReader.h" -#include "Poco/SAX/AttributesImpl.h" - - -namespace Poco { -namespace XML { - - -const XMLString DOMBuilder::EMPTY_STRING; - - -DOMBuilder::DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool): - _xmlReader(xmlReader), - _pNamePool(pNamePool), - _pDocument(0), - _pParent(0), - _pPrevious(0), - _inCDATA(false), - _namespaces(true) -{ - _xmlReader.setContentHandler(this); - _xmlReader.setDTDHandler(this); - _xmlReader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(this)); - - if (_pNamePool) _pNamePool->duplicate(); -} - - -DOMBuilder::~DOMBuilder() -{ - if (_pNamePool) _pNamePool->release(); -} - - -Document* DOMBuilder::parse(const XMLString& uri) -{ - setupParse(); - _pDocument->suspendEvents(); - try - { - _xmlReader.parse(uri); - } - catch (...) - { - _pDocument->release(); - _pDocument = 0; - _pParent = 0; - _pPrevious = 0; - throw; - } - _pDocument->resumeEvents(); - _pDocument->collectGarbage(); - return _pDocument; -} - - -Document* DOMBuilder::parse(InputSource* pInputSource) -{ - setupParse(); - _pDocument->suspendEvents(); - try - { - _xmlReader.parse(pInputSource); - } - catch (...) - { - _pDocument->release(); - _pDocument = 0; - _pParent = 0; - _pPrevious = 0; - throw; - } - _pDocument->resumeEvents(); - _pDocument->collectGarbage(); - return _pDocument; -} - - -Document* DOMBuilder::parseMemoryNP(const char* xml, std::size_t size) -{ - setupParse(); - _pDocument->suspendEvents(); - try - { - _xmlReader.parseMemoryNP(xml, size); - } - catch (...) - { - _pDocument->release(); - _pDocument = 0; - _pParent = 0; - _pPrevious = 0; - throw; - } - _pDocument->resumeEvents(); - _pDocument->collectGarbage(); - return _pDocument; -} - - -void DOMBuilder::setupParse() -{ - _pDocument = new Document(_pNamePool); - _pParent = _pDocument; - _pPrevious = 0; - _inCDATA = false; - _namespaces = _xmlReader.getFeature(XMLReader::FEATURE_NAMESPACES); -} - - -inline void DOMBuilder::appendNode(AbstractNode* pNode) -{ - if (_pPrevious && _pPrevious != _pParent) - { - _pPrevious->_pNext = pNode; - pNode->_pParent = _pParent; - pNode->duplicate(); - } - else _pParent->appendChild(pNode); - _pPrevious = pNode; -} - - -void DOMBuilder::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) -{ - DocumentType* pDoctype = _pDocument->getDoctype(); - if (pDoctype) - { - AutoPtr pNotation = _pDocument->createNotation(name, (publicId ? *publicId : EMPTY_STRING), (systemId ? *systemId : EMPTY_STRING)); - pDoctype->appendChild(pNotation); - } -} - - -void DOMBuilder::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) -{ - DocumentType* pDoctype = _pDocument->getDoctype(); - if (pDoctype) - { - AutoPtr pEntity = _pDocument->createEntity(name, publicId ? *publicId : EMPTY_STRING, systemId, notationName); - pDoctype->appendChild(pEntity); - } -} - - -void DOMBuilder::setDocumentLocator(const Locator* loc) -{ -} - - -void DOMBuilder::startDocument() -{ -} - - -void DOMBuilder::endDocument() -{ -} - - -void DOMBuilder::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) -{ - AutoPtr pElem = _namespaces ? _pDocument->createElementNS(uri, qname.empty() ? localName : qname) : _pDocument->createElement(qname); - - const AttributesImpl& attrs = dynamic_cast(attributes); - Attr* pPrevAttr = 0; - for (AttributesImpl::iterator it = attrs.begin(); it != attrs.end(); ++it) - { - AutoPtr pAttr = new Attr(_pDocument, 0, it->namespaceURI, it->localName, it->qname, it->value, it->specified); - pPrevAttr = pElem->addAttributeNodeNP(pPrevAttr, pAttr); - } - appendNode(pElem); - _pParent = pElem; -} - - -void DOMBuilder::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) -{ - _pPrevious = _pParent; - _pParent = static_cast(_pParent->parentNode()); -} - - -void DOMBuilder::characters(const XMLChar ch[], int start, int length) -{ - if (_inCDATA) - { - if (_pPrevious && _pPrevious->nodeType() == Node::CDATA_SECTION_NODE) - { - static_cast(_pPrevious)->appendData(XMLString(ch + start, length)); - } - else - { - AutoPtr pCDATA = _pDocument->createCDATASection(XMLString(ch + start, length)); - appendNode(pCDATA); - } - } - else - { - if (_pPrevious && _pPrevious->nodeType() == Node::TEXT_NODE) - { - static_cast(_pPrevious)->appendData(XMLString(ch + start, length)); - } - else - { - AutoPtr pText = _pDocument->createTextNode(XMLString(ch + start, length)); - appendNode(pText); - } - } -} - - -void DOMBuilder::ignorableWhitespace(const XMLChar ch[], int start, int length) -{ - characters(ch, start, length); -} - - -void DOMBuilder::processingInstruction(const XMLString& target, const XMLString& data) -{ - AutoPtr pPI = _pDocument->createProcessingInstruction(target, data); - appendNode(pPI); -} - - -void DOMBuilder::startPrefixMapping(const XMLString& prefix, const XMLString& uri) -{ -} - - -void DOMBuilder::endPrefixMapping(const XMLString& prefix) -{ -} - - -void DOMBuilder::skippedEntity(const XMLString& name) -{ - AutoPtr pER = _pDocument->createEntityReference(name); - appendNode(pER); -} - - -void DOMBuilder::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) -{ - AutoPtr pDoctype = new DocumentType(_pDocument, name, publicId, systemId); - _pDocument->setDoctype(pDoctype); -} - - -void DOMBuilder::endDTD() -{ -} - - -void DOMBuilder::startEntity(const XMLString& name) -{ -} - - -void DOMBuilder::endEntity(const XMLString& name) -{ -} - - -void DOMBuilder::startCDATA() -{ - _inCDATA = true; -} - - -void DOMBuilder::endCDATA() -{ - _inCDATA = false; -} - - -void DOMBuilder::comment(const XMLChar ch[], int start, int length) -{ - AutoPtr pComment = _pDocument->createComment(XMLString(ch + start, length)); - appendNode(pComment); -} - - -} } // namespace Poco::XML +// +// DOMBuilder.cpp +// +// $Id: //poco/1.3/XML/src/DOMBuilder.cpp#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMBuilder +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMBuilder.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/CharacterData.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/Comment.h" +#include "Poco/DOM/CDATASection.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Entity.h" +#include "Poco/DOM/EntityReference.h" +#include "Poco/DOM/Notation.h" +#include "Poco/DOM/ProcessingInstruction.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/SAX/XMLReader.h" +#include "Poco/SAX/AttributesImpl.h" + + +namespace Poco { +namespace XML { + + +const XMLString DOMBuilder::EMPTY_STRING; + + +DOMBuilder::DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool): + _xmlReader(xmlReader), + _pNamePool(pNamePool), + _pDocument(0), + _pParent(0), + _pPrevious(0), + _inCDATA(false), + _namespaces(true) +{ + _xmlReader.setContentHandler(this); + _xmlReader.setDTDHandler(this); + _xmlReader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(this)); + + if (_pNamePool) _pNamePool->duplicate(); +} + + +DOMBuilder::~DOMBuilder() +{ + if (_pNamePool) _pNamePool->release(); +} + + +Document* DOMBuilder::parse(const XMLString& uri) +{ + setupParse(); + _pDocument->suspendEvents(); + try + { + _xmlReader.parse(uri); + } + catch (...) + { + _pDocument->release(); + _pDocument = 0; + _pParent = 0; + _pPrevious = 0; + throw; + } + _pDocument->resumeEvents(); + _pDocument->collectGarbage(); + return _pDocument; +} + + +Document* DOMBuilder::parse(InputSource* pInputSource) +{ + setupParse(); + _pDocument->suspendEvents(); + try + { + _xmlReader.parse(pInputSource); + } + catch (...) + { + _pDocument->release(); + _pDocument = 0; + _pParent = 0; + _pPrevious = 0; + throw; + } + _pDocument->resumeEvents(); + _pDocument->collectGarbage(); + return _pDocument; +} + + +Document* DOMBuilder::parseMemoryNP(const char* xml, std::size_t size) +{ + setupParse(); + _pDocument->suspendEvents(); + try + { + _xmlReader.parseMemoryNP(xml, size); + } + catch (...) + { + _pDocument->release(); + _pDocument = 0; + _pParent = 0; + _pPrevious = 0; + throw; + } + _pDocument->resumeEvents(); + _pDocument->collectGarbage(); + return _pDocument; +} + + +void DOMBuilder::setupParse() +{ + _pDocument = new Document(_pNamePool); + _pParent = _pDocument; + _pPrevious = 0; + _inCDATA = false; + _namespaces = _xmlReader.getFeature(XMLReader::FEATURE_NAMESPACES); +} + + +inline void DOMBuilder::appendNode(AbstractNode* pNode) +{ + if (_pPrevious && _pPrevious != _pParent) + { + _pPrevious->_pNext = pNode; + pNode->_pParent = _pParent; + pNode->duplicate(); + } + else _pParent->appendChild(pNode); + _pPrevious = pNode; +} + + +void DOMBuilder::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) +{ + DocumentType* pDoctype = _pDocument->getDoctype(); + if (pDoctype) + { + AutoPtr pNotation = _pDocument->createNotation(name, (publicId ? *publicId : EMPTY_STRING), (systemId ? *systemId : EMPTY_STRING)); + pDoctype->appendChild(pNotation); + } +} + + +void DOMBuilder::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) +{ + DocumentType* pDoctype = _pDocument->getDoctype(); + if (pDoctype) + { + AutoPtr pEntity = _pDocument->createEntity(name, publicId ? *publicId : EMPTY_STRING, systemId, notationName); + pDoctype->appendChild(pEntity); + } +} + + +void DOMBuilder::setDocumentLocator(const Locator* loc) +{ +} + + +void DOMBuilder::startDocument() +{ +} + + +void DOMBuilder::endDocument() +{ +} + + +void DOMBuilder::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) +{ + AutoPtr pElem = _namespaces ? _pDocument->createElementNS(uri, qname.empty() ? localName : qname) : _pDocument->createElement(qname); + + const AttributesImpl& attrs = dynamic_cast(attributes); + Attr* pPrevAttr = 0; + for (AttributesImpl::iterator it = attrs.begin(); it != attrs.end(); ++it) + { + AutoPtr pAttr = new Attr(_pDocument, 0, it->namespaceURI, it->localName, it->qname, it->value, it->specified); + pPrevAttr = pElem->addAttributeNodeNP(pPrevAttr, pAttr); + } + appendNode(pElem); + _pParent = pElem; +} + + +void DOMBuilder::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) +{ + _pPrevious = _pParent; + _pParent = static_cast(_pParent->parentNode()); +} + + +void DOMBuilder::characters(const XMLChar ch[], int start, int length) +{ + if (_inCDATA) + { + if (_pPrevious && _pPrevious->nodeType() == Node::CDATA_SECTION_NODE) + { + static_cast(_pPrevious)->appendData(XMLString(ch + start, length)); + } + else + { + AutoPtr pCDATA = _pDocument->createCDATASection(XMLString(ch + start, length)); + appendNode(pCDATA); + } + } + else + { + if (_pPrevious && _pPrevious->nodeType() == Node::TEXT_NODE) + { + static_cast(_pPrevious)->appendData(XMLString(ch + start, length)); + } + else + { + AutoPtr pText = _pDocument->createTextNode(XMLString(ch + start, length)); + appendNode(pText); + } + } +} + + +void DOMBuilder::ignorableWhitespace(const XMLChar ch[], int start, int length) +{ + characters(ch, start, length); +} + + +void DOMBuilder::processingInstruction(const XMLString& target, const XMLString& data) +{ + AutoPtr pPI = _pDocument->createProcessingInstruction(target, data); + appendNode(pPI); +} + + +void DOMBuilder::startPrefixMapping(const XMLString& prefix, const XMLString& uri) +{ +} + + +void DOMBuilder::endPrefixMapping(const XMLString& prefix) +{ +} + + +void DOMBuilder::skippedEntity(const XMLString& name) +{ + AutoPtr pER = _pDocument->createEntityReference(name); + appendNode(pER); +} + + +void DOMBuilder::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) +{ + AutoPtr pDoctype = new DocumentType(_pDocument, name, publicId, systemId); + _pDocument->setDoctype(pDoctype); +} + + +void DOMBuilder::endDTD() +{ +} + + +void DOMBuilder::startEntity(const XMLString& name) +{ +} + + +void DOMBuilder::endEntity(const XMLString& name) +{ +} + + +void DOMBuilder::startCDATA() +{ + _inCDATA = true; +} + + +void DOMBuilder::endCDATA() +{ + _inCDATA = false; +} + + +void DOMBuilder::comment(const XMLChar ch[], int start, int length) +{ + AutoPtr pComment = _pDocument->createComment(XMLString(ch + start, length)); + appendNode(pComment); +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMException.cpp b/XML/src/DOMException.cpp index f0715ac45..09eed4309 100644 --- a/XML/src/DOMException.cpp +++ b/XML/src/DOMException.cpp @@ -1,129 +1,129 @@ -// -// DOMException.cpp -// -// $Id: //poco/1.3/XML/src/DOMException.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMException.h" -#include - - -namespace Poco { -namespace XML { - - -const std::string DOMException::MESSAGES[_NUMBER_OF_MESSAGES] = -{ - "Invalid DOM exception code", - "Index or size is negative or greater than allowed value", - "The specified range of text does not fit into a DOMString", - "A node is inserted somewhere it doesn't belong", - "A node is used in a different document than the one that created it", - "An invalid character is specified", - "Data is specified for a node which does not support data", - "An attempt is made to modify an object where modifications are not allowed", - "An attempt was made to reference a node in a context where it does not exist", - "The implementation does not support the type of object requested", - "An attempt is made to add an attribute that is already in use elsewhere", - "A parameter or an operation is not supported by the underlying object", - "An invalid or illegal string is specified", - "An attempt is made to modify the type of the underlying object", - "An attempt is made to create or change an object in a way which is incorrect with regard to namespaces", - "An attempt is made to use an object that is not, or is no longer, usable" -}; - - -DOMException::DOMException(unsigned short code): - XMLException(message(code)), - _code(code) -{ -} - - -DOMException::DOMException(const DOMException& exc): - XMLException(exc), - _code(exc._code) -{ -} - - -DOMException::~DOMException() throw() -{ -} - - -DOMException& DOMException::operator = (const DOMException& exc) -{ - if (&exc != this) - { - XMLException::operator = (exc); - _code = exc._code; - } - return *this; -} - - -const char* DOMException::name() const throw() -{ - return "DOMException"; -} - - -const char* DOMException::className() const throw() -{ - return typeid(*this).name(); -} - - -Poco::Exception* DOMException::clone() const -{ - return new DOMException(*this); -} - - -void DOMException::rethrow() const -{ - throw *this; -} - - -const std::string& DOMException::message(unsigned short code) -{ - if (code >= 1 && code < _NUMBER_OF_MESSAGES) - return MESSAGES[code]; - else - return MESSAGES[0]; -} - - -} } // namespace Poco::XML +// +// DOMException.cpp +// +// $Id: //poco/1.3/XML/src/DOMException.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMException.h" +#include + + +namespace Poco { +namespace XML { + + +const std::string DOMException::MESSAGES[_NUMBER_OF_MESSAGES] = +{ + "Invalid DOM exception code", + "Index or size is negative or greater than allowed value", + "The specified range of text does not fit into a DOMString", + "A node is inserted somewhere it doesn't belong", + "A node is used in a different document than the one that created it", + "An invalid character is specified", + "Data is specified for a node which does not support data", + "An attempt is made to modify an object where modifications are not allowed", + "An attempt was made to reference a node in a context where it does not exist", + "The implementation does not support the type of object requested", + "An attempt is made to add an attribute that is already in use elsewhere", + "A parameter or an operation is not supported by the underlying object", + "An invalid or illegal string is specified", + "An attempt is made to modify the type of the underlying object", + "An attempt is made to create or change an object in a way which is incorrect with regard to namespaces", + "An attempt is made to use an object that is not, or is no longer, usable" +}; + + +DOMException::DOMException(unsigned short code): + XMLException(message(code)), + _code(code) +{ +} + + +DOMException::DOMException(const DOMException& exc): + XMLException(exc), + _code(exc._code) +{ +} + + +DOMException::~DOMException() throw() +{ +} + + +DOMException& DOMException::operator = (const DOMException& exc) +{ + if (&exc != this) + { + XMLException::operator = (exc); + _code = exc._code; + } + return *this; +} + + +const char* DOMException::name() const throw() +{ + return "DOMException"; +} + + +const char* DOMException::className() const throw() +{ + return typeid(*this).name(); +} + + +Poco::Exception* DOMException::clone() const +{ + return new DOMException(*this); +} + + +void DOMException::rethrow() const +{ + throw *this; +} + + +const std::string& DOMException::message(unsigned short code) +{ + if (code >= 1 && code < _NUMBER_OF_MESSAGES) + return MESSAGES[code]; + else + return MESSAGES[0]; +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMImplementation.cpp b/XML/src/DOMImplementation.cpp index fd16fd565..e57c3a5dd 100644 --- a/XML/src/DOMImplementation.cpp +++ b/XML/src/DOMImplementation.cpp @@ -1,103 +1,103 @@ -// -// DOMImplementation.cpp -// -// $Id: //poco/1.3/XML/src/DOMImplementation.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMImplementation.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/String.h" -#include "Poco/SingletonHolder.h" - - -namespace Poco { -namespace XML { - - -const XMLString DOMImplementation::FEATURE_XML = toXMLString("xml"); -const XMLString DOMImplementation::FEATURE_CORE = toXMLString("core"); -const XMLString DOMImplementation::FEATURE_EVENTS = toXMLString("events"); -const XMLString DOMImplementation::FEATURE_MUTATIONEVENTS = toXMLString("mutationevents"); -const XMLString DOMImplementation::FEATURE_TRAVERSAL = toXMLString("traversal"); -const XMLString DOMImplementation::VERSION_1_0 = toXMLString("1.0"); -const XMLString DOMImplementation::VERSION_2_0 = toXMLString("2.0"); - - -DOMImplementation::DOMImplementation() -{ -} - - -DOMImplementation::~DOMImplementation() -{ -} - - -bool DOMImplementation::hasFeature(const XMLString& feature, const XMLString& version) const -{ - XMLString lcFeature = Poco::toLower(feature); - return lcFeature == FEATURE_XML && version == VERSION_1_0 || - lcFeature == FEATURE_CORE && version == VERSION_2_0 || - lcFeature == FEATURE_EVENTS && version == VERSION_2_0 || - lcFeature == FEATURE_MUTATIONEVENTS && version == VERSION_2_0 || - lcFeature == FEATURE_TRAVERSAL && version == VERSION_2_0; -} - - -DocumentType* DOMImplementation::createDocumentType(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const -{ - return new DocumentType(0, name, publicId, systemId); -} - - -Document* DOMImplementation::createDocument(const XMLString& namespaceURI, const XMLString& qualifiedName, DocumentType* doctype) const -{ - Document* pDoc = new Document(doctype); - if (namespaceURI.empty()) - pDoc->appendChild(pDoc->createElement(qualifiedName))->release(); - else - pDoc->appendChild(pDoc->createElementNS(namespaceURI, qualifiedName))->release(); - return pDoc; -} - - -const DOMImplementation& DOMImplementation::instance() -{ - static Poco::SingletonHolder sh; - return *sh.get(); -} - - -} } // namespace Poco::XML +// +// DOMImplementation.cpp +// +// $Id: //poco/1.3/XML/src/DOMImplementation.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMImplementation.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/String.h" +#include "Poco/SingletonHolder.h" + + +namespace Poco { +namespace XML { + + +const XMLString DOMImplementation::FEATURE_XML = toXMLString("xml"); +const XMLString DOMImplementation::FEATURE_CORE = toXMLString("core"); +const XMLString DOMImplementation::FEATURE_EVENTS = toXMLString("events"); +const XMLString DOMImplementation::FEATURE_MUTATIONEVENTS = toXMLString("mutationevents"); +const XMLString DOMImplementation::FEATURE_TRAVERSAL = toXMLString("traversal"); +const XMLString DOMImplementation::VERSION_1_0 = toXMLString("1.0"); +const XMLString DOMImplementation::VERSION_2_0 = toXMLString("2.0"); + + +DOMImplementation::DOMImplementation() +{ +} + + +DOMImplementation::~DOMImplementation() +{ +} + + +bool DOMImplementation::hasFeature(const XMLString& feature, const XMLString& version) const +{ + XMLString lcFeature = Poco::toLower(feature); + return lcFeature == FEATURE_XML && version == VERSION_1_0 || + lcFeature == FEATURE_CORE && version == VERSION_2_0 || + lcFeature == FEATURE_EVENTS && version == VERSION_2_0 || + lcFeature == FEATURE_MUTATIONEVENTS && version == VERSION_2_0 || + lcFeature == FEATURE_TRAVERSAL && version == VERSION_2_0; +} + + +DocumentType* DOMImplementation::createDocumentType(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const +{ + return new DocumentType(0, name, publicId, systemId); +} + + +Document* DOMImplementation::createDocument(const XMLString& namespaceURI, const XMLString& qualifiedName, DocumentType* doctype) const +{ + Document* pDoc = new Document(doctype); + if (namespaceURI.empty()) + pDoc->appendChild(pDoc->createElement(qualifiedName))->release(); + else + pDoc->appendChild(pDoc->createElementNS(namespaceURI, qualifiedName))->release(); + return pDoc; +} + + +const DOMImplementation& DOMImplementation::instance() +{ + static Poco::SingletonHolder sh; + return *sh.get(); +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMObject.cpp b/XML/src/DOMObject.cpp index 768efb9a7..a3c47c985 100644 --- a/XML/src/DOMObject.cpp +++ b/XML/src/DOMObject.cpp @@ -1,54 +1,54 @@ -// -// DOMObject.cpp -// -// $Id: //poco/1.3/XML/src/DOMObject.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMObject.h" - - -namespace Poco { -namespace XML { - - -DOMObject::DOMObject(): _rc(1) -{ -} - - -DOMObject::~DOMObject() -{ -} - - -} } // namespace Poco::XML +// +// DOMObject.cpp +// +// $Id: //poco/1.3/XML/src/DOMObject.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMObject.h" + + +namespace Poco { +namespace XML { + + +DOMObject::DOMObject(): _rc(1) +{ +} + + +DOMObject::~DOMObject() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMParser.cpp b/XML/src/DOMParser.cpp index 9cff10cb0..6efe48d1c 100644 --- a/XML/src/DOMParser.cpp +++ b/XML/src/DOMParser.cpp @@ -1,170 +1,170 @@ -// -// DOMParser.cpp -// -// $Id: //poco/1.3/XML/src/DOMParser.cpp#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMParser -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMParser.h" -#include "Poco/DOM/DOMBuilder.h" -#include "Poco/SAX/WhitespaceFilter.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/XML/NamePool.h" -#include - - -namespace Poco { -namespace XML { - - -const XMLString DOMParser::FEATURE_WHITESPACE = toXMLString("http://www.appinf.com/features/no-whitespace-in-element-content"); - - -DOMParser::DOMParser(NamePool* pNamePool): - _pNamePool(pNamePool), - _whitespace(true) -{ - if (_pNamePool) _pNamePool->duplicate(); - _saxParser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - _saxParser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); -} - - -DOMParser::~DOMParser() -{ - if (_pNamePool) _pNamePool->release(); -} - - -void DOMParser::setEncoding(const XMLString& encoding) -{ - _saxParser.setEncoding(encoding); -} - - -const XMLString& DOMParser::getEncoding() const -{ - return _saxParser.getEncoding(); -} - - -void DOMParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding) -{ - _saxParser.addEncoding(name, pEncoding); -} - - -void DOMParser::setFeature(const XMLString& name, bool state) -{ - if (name == FEATURE_WHITESPACE) - _whitespace = state; - else - _saxParser.setFeature(name, state); -} - - -bool DOMParser::getFeature(const XMLString& name) const -{ - if (name == FEATURE_WHITESPACE) - return _whitespace; - else - return _saxParser.getFeature(name); -} - - -Document* DOMParser::parse(const XMLString& uri) -{ - if (_whitespace) - { - DOMBuilder builder(_saxParser, _pNamePool); - return builder.parse(uri); - } - else - { - WhitespaceFilter filter(&_saxParser); - DOMBuilder builder(filter, _pNamePool); - return builder.parse(uri); - } -} - - -Document* DOMParser::parse(InputSource* pInputSource) -{ - if (_whitespace) - { - DOMBuilder builder(_saxParser, _pNamePool); - return builder.parse(pInputSource); - } - else - { - WhitespaceFilter filter(&_saxParser); - DOMBuilder builder(filter, _pNamePool); - return builder.parse(pInputSource); - } -} - - -Document* DOMParser::parseString(const std::string& xml) -{ - return parseMemory(xml.data(), xml.size()); -} - - -Document* DOMParser::parseMemory(const char* xml, std::size_t size) -{ - if (_whitespace) - { - DOMBuilder builder(_saxParser, _pNamePool); - return builder.parseMemoryNP(xml, size); - } - else - { - WhitespaceFilter filter(&_saxParser); - DOMBuilder builder(filter, _pNamePool); - return builder.parseMemoryNP(xml, size); - } -} - - -EntityResolver* DOMParser::getEntityResolver() const -{ - return _saxParser.getEntityResolver(); -} - - -void DOMParser::setEntityResolver(EntityResolver* pEntityResolver) -{ - _saxParser.setEntityResolver(pEntityResolver); -} - - -} } // namespace Poco::XML +// +// DOMParser.cpp +// +// $Id: //poco/1.3/XML/src/DOMParser.cpp#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMParser +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMParser.h" +#include "Poco/DOM/DOMBuilder.h" +#include "Poco/SAX/WhitespaceFilter.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/XML/NamePool.h" +#include + + +namespace Poco { +namespace XML { + + +const XMLString DOMParser::FEATURE_WHITESPACE = toXMLString("http://www.appinf.com/features/no-whitespace-in-element-content"); + + +DOMParser::DOMParser(NamePool* pNamePool): + _pNamePool(pNamePool), + _whitespace(true) +{ + if (_pNamePool) _pNamePool->duplicate(); + _saxParser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + _saxParser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); +} + + +DOMParser::~DOMParser() +{ + if (_pNamePool) _pNamePool->release(); +} + + +void DOMParser::setEncoding(const XMLString& encoding) +{ + _saxParser.setEncoding(encoding); +} + + +const XMLString& DOMParser::getEncoding() const +{ + return _saxParser.getEncoding(); +} + + +void DOMParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding) +{ + _saxParser.addEncoding(name, pEncoding); +} + + +void DOMParser::setFeature(const XMLString& name, bool state) +{ + if (name == FEATURE_WHITESPACE) + _whitespace = state; + else + _saxParser.setFeature(name, state); +} + + +bool DOMParser::getFeature(const XMLString& name) const +{ + if (name == FEATURE_WHITESPACE) + return _whitespace; + else + return _saxParser.getFeature(name); +} + + +Document* DOMParser::parse(const XMLString& uri) +{ + if (_whitespace) + { + DOMBuilder builder(_saxParser, _pNamePool); + return builder.parse(uri); + } + else + { + WhitespaceFilter filter(&_saxParser); + DOMBuilder builder(filter, _pNamePool); + return builder.parse(uri); + } +} + + +Document* DOMParser::parse(InputSource* pInputSource) +{ + if (_whitespace) + { + DOMBuilder builder(_saxParser, _pNamePool); + return builder.parse(pInputSource); + } + else + { + WhitespaceFilter filter(&_saxParser); + DOMBuilder builder(filter, _pNamePool); + return builder.parse(pInputSource); + } +} + + +Document* DOMParser::parseString(const std::string& xml) +{ + return parseMemory(xml.data(), xml.size()); +} + + +Document* DOMParser::parseMemory(const char* xml, std::size_t size) +{ + if (_whitespace) + { + DOMBuilder builder(_saxParser, _pNamePool); + return builder.parseMemoryNP(xml, size); + } + else + { + WhitespaceFilter filter(&_saxParser); + DOMBuilder builder(filter, _pNamePool); + return builder.parseMemoryNP(xml, size); + } +} + + +EntityResolver* DOMParser::getEntityResolver() const +{ + return _saxParser.getEntityResolver(); +} + + +void DOMParser::setEntityResolver(EntityResolver* pEntityResolver) +{ + _saxParser.setEntityResolver(pEntityResolver); +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMSerializer.cpp b/XML/src/DOMSerializer.cpp index 364f28df4..bf53d6645 100644 --- a/XML/src/DOMSerializer.cpp +++ b/XML/src/DOMSerializer.cpp @@ -1,345 +1,345 @@ -// -// DOMSerializer.cpp -// -// $Id: //poco/1.3/XML/src/DOMSerializer.cpp#2 $ -// -// Library: XML -// Package: DOM -// Module: DOMSerializer -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DOMSerializer.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/DocumentFragment.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/CDATASection.h" -#include "Poco/DOM/Comment.h" -#include "Poco/DOM/ProcessingInstruction.h" -#include "Poco/DOM/Entity.h" -#include "Poco/DOM/Notation.h" -#include "Poco/DOM/NamedNodeMap.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/SAX/EntityResolver.h" -#include "Poco/SAX/DTDHandler.h" -#include "Poco/SAX/ContentHandler.h" -#include "Poco/SAX/LexicalHandler.h" -#include "Poco/SAX/AttributesImpl.h" -#include "Poco/SAX/ErrorHandler.h" -#include "Poco/SAX/SAXException.h" - - -namespace Poco { -namespace XML { - - -const XMLString DOMSerializer::CDATA = toXMLString("CDATA"); - - -DOMSerializer::DOMSerializer(): - _pEntityResolver(0), - _pDTDHandler(0), - _pContentHandler(0), - _pErrorHandler(0), - _pDeclHandler(0), - _pLexicalHandler(0) -{ -} - - -DOMSerializer::~DOMSerializer() -{ -} - - -void DOMSerializer::setEntityResolver(EntityResolver* pEntityResolver) -{ - _pEntityResolver = pEntityResolver; -} - - -EntityResolver* DOMSerializer::getEntityResolver() const -{ - return _pEntityResolver; -} - - -void DOMSerializer::setDTDHandler(DTDHandler* pDTDHandler) -{ - _pDTDHandler = pDTDHandler; -} - - -DTDHandler* DOMSerializer::getDTDHandler() const -{ - return _pDTDHandler; -} - - -void DOMSerializer::setContentHandler(ContentHandler* pContentHandler) -{ - _pContentHandler = pContentHandler; -} - - -ContentHandler* DOMSerializer::getContentHandler() const -{ - return _pContentHandler; -} - - -void DOMSerializer::setErrorHandler(ErrorHandler* pErrorHandler) -{ - _pErrorHandler = pErrorHandler; -} - - -ErrorHandler* DOMSerializer::getErrorHandler() const -{ - return _pErrorHandler; -} - - -void DOMSerializer::setFeature(const XMLString& featureId, bool state) -{ - if (featureId == XMLReader::FEATURE_NAMESPACES) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES)); - else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES)); - else - throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -bool DOMSerializer::getFeature(const XMLString& featureId) const -{ - if (featureId == XMLReader::FEATURE_NAMESPACES) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES)); - else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES)); - else - throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -void DOMSerializer::setProperty(const XMLString& propertyId, const XMLString& value) -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); - else - throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void DOMSerializer::setProperty(const XMLString& propertyId, void* value) -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) - _pDeclHandler = reinterpret_cast(value); - else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - _pLexicalHandler = reinterpret_cast(value); - else throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void* DOMSerializer::getProperty(const XMLString& propertyId) const -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) - return _pDeclHandler; - else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - return _pLexicalHandler; - else throw SAXNotSupportedException(fromXMLString(propertyId)); -} - - -void DOMSerializer::serialize(const Node* pNode) -{ - poco_check_ptr (pNode); - - handleNode(pNode); -} - - -void DOMSerializer::parse(InputSource* pSource) -{ - throw XMLException("The DOMSerializer cannot parse an InputSource"); -} - - -void DOMSerializer::parse(const XMLString& systemId) -{ - throw XMLException("The DOMSerializer cannot parse from a system identifier"); -} - - -void DOMSerializer::parseMemoryNP(const char* xml, std::size_t size) -{ - throw XMLException("The DOMSerializer cannot parse from memory"); -} - - -void DOMSerializer::iterate(const Node* pNode) const -{ - while (pNode) - { - handleNode(pNode); - pNode = pNode->nextSibling(); - } -} - - -void DOMSerializer::handleNode(const Node* pNode) const -{ - switch (pNode->nodeType()) - { - case Node::ELEMENT_NODE: - handleElement(static_cast(pNode)); - break; - case Node::TEXT_NODE: - handleCharacterData(static_cast(pNode)); - break; - case Node::CDATA_SECTION_NODE: - handleCDATASection(static_cast(pNode)); - break; - case Node::ENTITY_NODE: - handleEntity(static_cast(pNode)); - break; - case Node::PROCESSING_INSTRUCTION_NODE: - handlePI(static_cast(pNode)); - break; - case Node::COMMENT_NODE: - handleComment(static_cast(pNode)); - break; - case Node::DOCUMENT_NODE: - handleDocument(static_cast(pNode)); - break; - case Node::DOCUMENT_TYPE_NODE: - handleDocumentType(static_cast(pNode)); - break; - case Node::DOCUMENT_FRAGMENT_NODE: - handleFragment(static_cast(pNode)); - break; - case Node::NOTATION_NODE: - handleNotation(static_cast(pNode)); - break; - } -} - - -void DOMSerializer::handleElement(const Element* pElement) const -{ - if (_pContentHandler) - { - AutoPtr pAttrs = pElement->attributes(); - AttributesImpl saxAttrs; - for (unsigned long i = 0; i < pAttrs->length(); ++i) - { - Attr* pAttr = static_cast(pAttrs->item(i)); - saxAttrs.addAttribute(pAttr->namespaceURI(), pAttr->localName(), pAttr->nodeName(), CDATA, pAttr->value(), pAttr->specified()); - } - _pContentHandler->startElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName(), saxAttrs); - } - iterate(pElement->firstChild()); - if (_pContentHandler) - _pContentHandler->endElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName()); -} - - -void DOMSerializer::handleCharacterData(const Text* pText) const -{ - if (_pContentHandler) - { - const XMLString& data = pText->data(); - _pContentHandler->characters(data.c_str(), 0, (int) data.length()); - } -} - - -void DOMSerializer::handleComment(const Comment* pComment) const -{ - if (_pLexicalHandler) - { - const XMLString& data = pComment->data(); - _pLexicalHandler->comment(data.c_str(), 0, (int) data.length()); - } -} - - -void DOMSerializer::handlePI(const ProcessingInstruction* pPI) const -{ - if (_pContentHandler) _pContentHandler->processingInstruction(pPI->target(), pPI->data()); -} - - -void DOMSerializer::handleCDATASection(const CDATASection* pCDATA) const -{ - if (_pLexicalHandler) _pLexicalHandler->startCDATA(); - handleCharacterData(pCDATA); - if (_pLexicalHandler) _pLexicalHandler->endCDATA(); -} - - -void DOMSerializer::handleDocument(const Document* pDocument) const -{ - if (_pContentHandler) _pContentHandler->startDocument(); - const DocumentType* pDoctype = pDocument->doctype(); - if (pDoctype) handleDocumentType(pDoctype); - iterate(pDocument->firstChild()); - if (_pContentHandler) _pContentHandler->endDocument(); -} - - -void DOMSerializer::handleDocumentType(const DocumentType* pDocumentType) const -{ - if (_pLexicalHandler) _pLexicalHandler->startDTD(pDocumentType->name(), pDocumentType->publicId(), pDocumentType->systemId()); - iterate(pDocumentType->firstChild()); - if (_pLexicalHandler) _pLexicalHandler->endDTD(); -} - - -void DOMSerializer::handleFragment(const DocumentFragment* pFragment) const -{ - iterate(pFragment->firstChild()); -} - - -void DOMSerializer::handleNotation(const Notation* pNotation) const -{ - if (_pDTDHandler) _pDTDHandler->notationDecl(pNotation->nodeName(), &pNotation->publicId(), &pNotation->systemId()); -} - - -void DOMSerializer::handleEntity(const Entity* pEntity) const -{ - if (_pDTDHandler) _pDTDHandler->unparsedEntityDecl(pEntity->nodeName(), &pEntity->publicId(), pEntity->systemId(), pEntity->notationName()); -} - - -} } // namespace Poco::XML +// +// DOMSerializer.cpp +// +// $Id: //poco/1.3/XML/src/DOMSerializer.cpp#2 $ +// +// Library: XML +// Package: DOM +// Module: DOMSerializer +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DOMSerializer.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/DocumentFragment.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/CDATASection.h" +#include "Poco/DOM/Comment.h" +#include "Poco/DOM/ProcessingInstruction.h" +#include "Poco/DOM/Entity.h" +#include "Poco/DOM/Notation.h" +#include "Poco/DOM/NamedNodeMap.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/SAX/EntityResolver.h" +#include "Poco/SAX/DTDHandler.h" +#include "Poco/SAX/ContentHandler.h" +#include "Poco/SAX/LexicalHandler.h" +#include "Poco/SAX/AttributesImpl.h" +#include "Poco/SAX/ErrorHandler.h" +#include "Poco/SAX/SAXException.h" + + +namespace Poco { +namespace XML { + + +const XMLString DOMSerializer::CDATA = toXMLString("CDATA"); + + +DOMSerializer::DOMSerializer(): + _pEntityResolver(0), + _pDTDHandler(0), + _pContentHandler(0), + _pErrorHandler(0), + _pDeclHandler(0), + _pLexicalHandler(0) +{ +} + + +DOMSerializer::~DOMSerializer() +{ +} + + +void DOMSerializer::setEntityResolver(EntityResolver* pEntityResolver) +{ + _pEntityResolver = pEntityResolver; +} + + +EntityResolver* DOMSerializer::getEntityResolver() const +{ + return _pEntityResolver; +} + + +void DOMSerializer::setDTDHandler(DTDHandler* pDTDHandler) +{ + _pDTDHandler = pDTDHandler; +} + + +DTDHandler* DOMSerializer::getDTDHandler() const +{ + return _pDTDHandler; +} + + +void DOMSerializer::setContentHandler(ContentHandler* pContentHandler) +{ + _pContentHandler = pContentHandler; +} + + +ContentHandler* DOMSerializer::getContentHandler() const +{ + return _pContentHandler; +} + + +void DOMSerializer::setErrorHandler(ErrorHandler* pErrorHandler) +{ + _pErrorHandler = pErrorHandler; +} + + +ErrorHandler* DOMSerializer::getErrorHandler() const +{ + return _pErrorHandler; +} + + +void DOMSerializer::setFeature(const XMLString& featureId, bool state) +{ + if (featureId == XMLReader::FEATURE_NAMESPACES) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES)); + else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES)); + else + throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +bool DOMSerializer::getFeature(const XMLString& featureId) const +{ + if (featureId == XMLReader::FEATURE_NAMESPACES) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACES)); + else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_NAMESPACE_PREFIXES)); + else + throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +void DOMSerializer::setProperty(const XMLString& propertyId, const XMLString& value) +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); + else + throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void DOMSerializer::setProperty(const XMLString& propertyId, void* value) +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) + _pDeclHandler = reinterpret_cast(value); + else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + _pLexicalHandler = reinterpret_cast(value); + else throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void* DOMSerializer::getProperty(const XMLString& propertyId) const +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) + return _pDeclHandler; + else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + return _pLexicalHandler; + else throw SAXNotSupportedException(fromXMLString(propertyId)); +} + + +void DOMSerializer::serialize(const Node* pNode) +{ + poco_check_ptr (pNode); + + handleNode(pNode); +} + + +void DOMSerializer::parse(InputSource* pSource) +{ + throw XMLException("The DOMSerializer cannot parse an InputSource"); +} + + +void DOMSerializer::parse(const XMLString& systemId) +{ + throw XMLException("The DOMSerializer cannot parse from a system identifier"); +} + + +void DOMSerializer::parseMemoryNP(const char* xml, std::size_t size) +{ + throw XMLException("The DOMSerializer cannot parse from memory"); +} + + +void DOMSerializer::iterate(const Node* pNode) const +{ + while (pNode) + { + handleNode(pNode); + pNode = pNode->nextSibling(); + } +} + + +void DOMSerializer::handleNode(const Node* pNode) const +{ + switch (pNode->nodeType()) + { + case Node::ELEMENT_NODE: + handleElement(static_cast(pNode)); + break; + case Node::TEXT_NODE: + handleCharacterData(static_cast(pNode)); + break; + case Node::CDATA_SECTION_NODE: + handleCDATASection(static_cast(pNode)); + break; + case Node::ENTITY_NODE: + handleEntity(static_cast(pNode)); + break; + case Node::PROCESSING_INSTRUCTION_NODE: + handlePI(static_cast(pNode)); + break; + case Node::COMMENT_NODE: + handleComment(static_cast(pNode)); + break; + case Node::DOCUMENT_NODE: + handleDocument(static_cast(pNode)); + break; + case Node::DOCUMENT_TYPE_NODE: + handleDocumentType(static_cast(pNode)); + break; + case Node::DOCUMENT_FRAGMENT_NODE: + handleFragment(static_cast(pNode)); + break; + case Node::NOTATION_NODE: + handleNotation(static_cast(pNode)); + break; + } +} + + +void DOMSerializer::handleElement(const Element* pElement) const +{ + if (_pContentHandler) + { + AutoPtr pAttrs = pElement->attributes(); + AttributesImpl saxAttrs; + for (unsigned long i = 0; i < pAttrs->length(); ++i) + { + Attr* pAttr = static_cast(pAttrs->item(i)); + saxAttrs.addAttribute(pAttr->namespaceURI(), pAttr->localName(), pAttr->nodeName(), CDATA, pAttr->value(), pAttr->specified()); + } + _pContentHandler->startElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName(), saxAttrs); + } + iterate(pElement->firstChild()); + if (_pContentHandler) + _pContentHandler->endElement(pElement->namespaceURI(), pElement->localName(), pElement->tagName()); +} + + +void DOMSerializer::handleCharacterData(const Text* pText) const +{ + if (_pContentHandler) + { + const XMLString& data = pText->data(); + _pContentHandler->characters(data.c_str(), 0, (int) data.length()); + } +} + + +void DOMSerializer::handleComment(const Comment* pComment) const +{ + if (_pLexicalHandler) + { + const XMLString& data = pComment->data(); + _pLexicalHandler->comment(data.c_str(), 0, (int) data.length()); + } +} + + +void DOMSerializer::handlePI(const ProcessingInstruction* pPI) const +{ + if (_pContentHandler) _pContentHandler->processingInstruction(pPI->target(), pPI->data()); +} + + +void DOMSerializer::handleCDATASection(const CDATASection* pCDATA) const +{ + if (_pLexicalHandler) _pLexicalHandler->startCDATA(); + handleCharacterData(pCDATA); + if (_pLexicalHandler) _pLexicalHandler->endCDATA(); +} + + +void DOMSerializer::handleDocument(const Document* pDocument) const +{ + if (_pContentHandler) _pContentHandler->startDocument(); + const DocumentType* pDoctype = pDocument->doctype(); + if (pDoctype) handleDocumentType(pDoctype); + iterate(pDocument->firstChild()); + if (_pContentHandler) _pContentHandler->endDocument(); +} + + +void DOMSerializer::handleDocumentType(const DocumentType* pDocumentType) const +{ + if (_pLexicalHandler) _pLexicalHandler->startDTD(pDocumentType->name(), pDocumentType->publicId(), pDocumentType->systemId()); + iterate(pDocumentType->firstChild()); + if (_pLexicalHandler) _pLexicalHandler->endDTD(); +} + + +void DOMSerializer::handleFragment(const DocumentFragment* pFragment) const +{ + iterate(pFragment->firstChild()); +} + + +void DOMSerializer::handleNotation(const Notation* pNotation) const +{ + if (_pDTDHandler) _pDTDHandler->notationDecl(pNotation->nodeName(), &pNotation->publicId(), &pNotation->systemId()); +} + + +void DOMSerializer::handleEntity(const Entity* pEntity) const +{ + if (_pDTDHandler) _pDTDHandler->unparsedEntityDecl(pEntity->nodeName(), &pEntity->publicId(), pEntity->systemId(), pEntity->notationName()); +} + + +} } // namespace Poco::XML diff --git a/XML/src/DOMWriter.cpp b/XML/src/DOMWriter.cpp index fc62c2291..5e9796f2c 100644 --- a/XML/src/DOMWriter.cpp +++ b/XML/src/DOMWriter.cpp @@ -1,116 +1,116 @@ -// -// DOMWriter.cpp -// -// $Id: //poco/1.3/XML/src/DOMWriter.cpp#3 $ -// -// Library: XML -// Package: DOM -// Module: DOMWriter -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - - -#include "Poco/DOM/DOMWriter.h" -#include "Poco/XML/XMLWriter.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DocumentFragment.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/DOMException.h" -#include "Poco/DOM/DOMSerializer.h" -#include "Poco/SAX/LexicalHandler.h" -#include "Poco/XML/XMLException.h" -#include "Poco/Path.h" -#include "Poco/FileStream.h" - - -namespace Poco { -namespace XML { - - -DOMWriter::DOMWriter(): - _pTextEncoding(0), - _options(0) -{ -} - - -DOMWriter::~DOMWriter() -{ -} - - -void DOMWriter::setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding) -{ - _encodingName = encodingName; - _pTextEncoding = &textEncoding; -} - - -void DOMWriter::setOptions(int options) -{ - _options = options; -} - - -void DOMWriter::setNewLine(const std::string& newLine) -{ - _newLine = newLine; -} - - -void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode) -{ - poco_check_ptr (pNode); - - bool isFragment = pNode->nodeType() != Node::DOCUMENT_NODE; - - XMLWriter writer(ostr, _options, _encodingName, _pTextEncoding); - writer.setNewLine(_newLine); - - DOMSerializer serializer; - serializer.setContentHandler(&writer); - serializer.setDTDHandler(&writer); - serializer.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - if (isFragment) writer.startFragment(); - serializer.serialize(pNode); - if (isFragment) writer.endFragment(); -} - - -void DOMWriter::writeNode(const std::string& systemId, const Node* pNode) -{ - Poco::FileOutputStream ostr(systemId); - if (ostr.good()) - writeNode(ostr, pNode); - else - throw Poco::CreateFileException(systemId); -} - - -} } // namespace Poco::XML - +// +// DOMWriter.cpp +// +// $Id: //poco/1.3/XML/src/DOMWriter.cpp#3 $ +// +// Library: XML +// Package: DOM +// Module: DOMWriter +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + + +#include "Poco/DOM/DOMWriter.h" +#include "Poco/XML/XMLWriter.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DocumentFragment.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/DOMException.h" +#include "Poco/DOM/DOMSerializer.h" +#include "Poco/SAX/LexicalHandler.h" +#include "Poco/XML/XMLException.h" +#include "Poco/Path.h" +#include "Poco/FileStream.h" + + +namespace Poco { +namespace XML { + + +DOMWriter::DOMWriter(): + _pTextEncoding(0), + _options(0) +{ +} + + +DOMWriter::~DOMWriter() +{ +} + + +void DOMWriter::setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding) +{ + _encodingName = encodingName; + _pTextEncoding = &textEncoding; +} + + +void DOMWriter::setOptions(int options) +{ + _options = options; +} + + +void DOMWriter::setNewLine(const std::string& newLine) +{ + _newLine = newLine; +} + + +void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode) +{ + poco_check_ptr (pNode); + + bool isFragment = pNode->nodeType() != Node::DOCUMENT_NODE; + + XMLWriter writer(ostr, _options, _encodingName, _pTextEncoding); + writer.setNewLine(_newLine); + + DOMSerializer serializer; + serializer.setContentHandler(&writer); + serializer.setDTDHandler(&writer); + serializer.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + if (isFragment) writer.startFragment(); + serializer.serialize(pNode); + if (isFragment) writer.endFragment(); +} + + +void DOMWriter::writeNode(const std::string& systemId, const Node* pNode) +{ + Poco::FileOutputStream ostr(systemId); + if (ostr.good()) + writeNode(ostr, pNode); + else + throw Poco::CreateFileException(systemId); +} + + +} } // namespace Poco::XML + diff --git a/XML/src/DTDHandler.cpp b/XML/src/DTDHandler.cpp index 25556c7ee..9bcb73621 100644 --- a/XML/src/DTDHandler.cpp +++ b/XML/src/DTDHandler.cpp @@ -1,49 +1,49 @@ -// -// DTDHandler.cpp -// -// $Id: //poco/1.3/XML/src/DTDHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/DTDHandler.h" - - -namespace Poco { -namespace XML { - - -DTDHandler::~DTDHandler() -{ -} - - -} } // namespace Poco::XML +// +// DTDHandler.cpp +// +// $Id: //poco/1.3/XML/src/DTDHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/DTDHandler.h" + + +namespace Poco { +namespace XML { + + +DTDHandler::~DTDHandler() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/DTDMap.cpp b/XML/src/DTDMap.cpp index a0619fb87..70d9d208d 100644 --- a/XML/src/DTDMap.cpp +++ b/XML/src/DTDMap.cpp @@ -1,139 +1,139 @@ -// -// DTDMap.cpp -// -// $Id: //poco/1.3/XML/src/DTDMap.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DTDMap.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -DTDMap::DTDMap(const DocumentType* pDocumentType, unsigned short type): - _pDocumentType(pDocumentType), - _type(type) -{ - poco_check_ptr (pDocumentType->ownerDocument()); -} - - -DTDMap::~DTDMap() -{ -} - - -Node* DTDMap::getNamedItem(const XMLString& name) const -{ - Node* pCur = _pDocumentType->firstChild(); - while (pCur) - { - if (pCur->nodeType() == _type && pCur->nodeName() == name) - return pCur; - pCur = pCur->nextSibling(); - } - return pCur; -} - - -Node* DTDMap::setNamedItem(Node* arg) -{ - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); -} - - -Node* DTDMap::removeNamedItem(const XMLString& name) -{ - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); -} - - -Node* DTDMap::item(unsigned long index) const -{ - unsigned long n = 0; - Node* pCur = _pDocumentType->firstChild(); - while (pCur) - { - if (pCur->nodeType() == _type) - { - if (n == index) return pCur; - ++n; - } - pCur = pCur->nextSibling(); - } - return pCur; -} - - -unsigned long DTDMap::length() const -{ - unsigned long n = 0; - Node* pCur = _pDocumentType->firstChild(); - while (pCur) - { - if (pCur->nodeType() == _type) ++n; - pCur = pCur->nextSibling(); - } - return n; -} - - -Node* DTDMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - return 0; -} - - -Node* DTDMap::setNamedItemNS(Node* arg) -{ - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); -} - - -Node* DTDMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) -{ - throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); -} - - -void DTDMap::autoRelease() -{ - _pDocumentType->ownerDocument()->autoReleasePool().add(this); -} - - -} } // namespace Poco::XML +// +// DTDMap.cpp +// +// $Id: //poco/1.3/XML/src/DTDMap.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DTDMap.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +DTDMap::DTDMap(const DocumentType* pDocumentType, unsigned short type): + _pDocumentType(pDocumentType), + _type(type) +{ + poco_check_ptr (pDocumentType->ownerDocument()); +} + + +DTDMap::~DTDMap() +{ +} + + +Node* DTDMap::getNamedItem(const XMLString& name) const +{ + Node* pCur = _pDocumentType->firstChild(); + while (pCur) + { + if (pCur->nodeType() == _type && pCur->nodeName() == name) + return pCur; + pCur = pCur->nextSibling(); + } + return pCur; +} + + +Node* DTDMap::setNamedItem(Node* arg) +{ + throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); +} + + +Node* DTDMap::removeNamedItem(const XMLString& name) +{ + throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); +} + + +Node* DTDMap::item(unsigned long index) const +{ + unsigned long n = 0; + Node* pCur = _pDocumentType->firstChild(); + while (pCur) + { + if (pCur->nodeType() == _type) + { + if (n == index) return pCur; + ++n; + } + pCur = pCur->nextSibling(); + } + return pCur; +} + + +unsigned long DTDMap::length() const +{ + unsigned long n = 0; + Node* pCur = _pDocumentType->firstChild(); + while (pCur) + { + if (pCur->nodeType() == _type) ++n; + pCur = pCur->nextSibling(); + } + return n; +} + + +Node* DTDMap::getNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + return 0; +} + + +Node* DTDMap::setNamedItemNS(Node* arg) +{ + throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); +} + + +Node* DTDMap::removeNamedItemNS(const XMLString& namespaceURI, const XMLString& localName) +{ + throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); +} + + +void DTDMap::autoRelease() +{ + _pDocumentType->ownerDocument()->autoReleasePool().add(this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/DeclHandler.cpp b/XML/src/DeclHandler.cpp index edd9fe36a..7fa42d926 100644 --- a/XML/src/DeclHandler.cpp +++ b/XML/src/DeclHandler.cpp @@ -1,49 +1,49 @@ -// -// DeclHandler.cpp -// -// $Id: //poco/1.3/XML/src/DeclHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/DeclHandler.h" - - -namespace Poco { -namespace XML { - - -DeclHandler::~DeclHandler() -{ -} - - -} } // namespace Poco::XML +// +// DeclHandler.cpp +// +// $Id: //poco/1.3/XML/src/DeclHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/DeclHandler.h" + + +namespace Poco { +namespace XML { + + +DeclHandler::~DeclHandler() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/DefaultHandler.cpp b/XML/src/DefaultHandler.cpp index fb7889a62..c66eb3f37 100644 --- a/XML/src/DefaultHandler.cpp +++ b/XML/src/DefaultHandler.cpp @@ -1,145 +1,145 @@ -// -// DefaultHandler.cpp -// -// $Id: //poco/1.3/XML/src/DefaultHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/DefaultHandler.h" - - -namespace Poco { -namespace XML { - - -DefaultHandler::DefaultHandler() -{ -} - - -DefaultHandler::~DefaultHandler() -{ -} - - -InputSource* DefaultHandler::resolveEntity(const XMLString* publicId, const XMLString& systemId) -{ - return 0; -} - - -void DefaultHandler::releaseInputSource(InputSource* pSource) -{ -} - - -void DefaultHandler::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) -{ -} - - -void DefaultHandler::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) -{ -} - - -void DefaultHandler::setDocumentLocator(const Locator* loc) -{ -} - - -void DefaultHandler::startDocument() -{ -} - - -void DefaultHandler::endDocument() -{ -} - - -void DefaultHandler::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) -{ -} - - -void DefaultHandler::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) -{ -} - - -void DefaultHandler::characters(const XMLChar ch[], int start, int length) -{ -} - - -void DefaultHandler::ignorableWhitespace(const XMLChar ch[], int start, int length) -{ -} - - -void DefaultHandler::processingInstruction(const XMLString& target, const XMLString& data) -{ -} - - -void DefaultHandler::startPrefixMapping(const XMLString& prefix, const XMLString& uri) -{ -} - - -void DefaultHandler::endPrefixMapping(const XMLString& prefix) -{ -} - - -void DefaultHandler::skippedEntity(const XMLString& name) -{ -} - - -void DefaultHandler::warning(const SAXException& exc) -{ -} - - -void DefaultHandler::error(const SAXException& exc) -{ -} - - -void DefaultHandler::fatalError(const SAXException& exc) -{ -} - - -} } // namespace Poco::XML +// +// DefaultHandler.cpp +// +// $Id: //poco/1.3/XML/src/DefaultHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/DefaultHandler.h" + + +namespace Poco { +namespace XML { + + +DefaultHandler::DefaultHandler() +{ +} + + +DefaultHandler::~DefaultHandler() +{ +} + + +InputSource* DefaultHandler::resolveEntity(const XMLString* publicId, const XMLString& systemId) +{ + return 0; +} + + +void DefaultHandler::releaseInputSource(InputSource* pSource) +{ +} + + +void DefaultHandler::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) +{ +} + + +void DefaultHandler::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) +{ +} + + +void DefaultHandler::setDocumentLocator(const Locator* loc) +{ +} + + +void DefaultHandler::startDocument() +{ +} + + +void DefaultHandler::endDocument() +{ +} + + +void DefaultHandler::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes) +{ +} + + +void DefaultHandler::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) +{ +} + + +void DefaultHandler::characters(const XMLChar ch[], int start, int length) +{ +} + + +void DefaultHandler::ignorableWhitespace(const XMLChar ch[], int start, int length) +{ +} + + +void DefaultHandler::processingInstruction(const XMLString& target, const XMLString& data) +{ +} + + +void DefaultHandler::startPrefixMapping(const XMLString& prefix, const XMLString& uri) +{ +} + + +void DefaultHandler::endPrefixMapping(const XMLString& prefix) +{ +} + + +void DefaultHandler::skippedEntity(const XMLString& name) +{ +} + + +void DefaultHandler::warning(const SAXException& exc) +{ +} + + +void DefaultHandler::error(const SAXException& exc) +{ +} + + +void DefaultHandler::fatalError(const SAXException& exc) +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/Document.cpp b/XML/src/Document.cpp index ff2bdd968..c32764521 100644 --- a/XML/src/Document.cpp +++ b/XML/src/Document.cpp @@ -1,325 +1,325 @@ -// -// Document.cpp -// -// $Id: //poco/1.3/XML/src/Document.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/DOMImplementation.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/DocumentFragment.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/Comment.h" -#include "Poco/DOM/CDATASection.h" -#include "Poco/DOM/ProcessingInstruction.h" -#include "Poco/DOM/EntityReference.h" -#include "Poco/DOM/DOMException.h" -#include "Poco/DOM/ElementsByTagNameList.h" -#include "Poco/DOM/Entity.h" -#include "Poco/DOM/Notation.h" -#include "Poco/XML/Name.h" -#include "Poco/XML/NamePool.h" - - -namespace Poco { -namespace XML { - - -const XMLString Document::NODE_NAME = toXMLString("#document"); - - -Document::Document(NamePool* pNamePool): - AbstractContainerNode(0), - _pDocumentType(0), - _eventSuspendLevel(0) -{ - if (pNamePool) - { - _pNamePool = pNamePool; - _pNamePool->duplicate(); - } - else - { - _pNamePool = new NamePool; - } -} - - -Document::Document(DocumentType* pDocumentType, NamePool* pNamePool): - AbstractContainerNode(0), - _pDocumentType(pDocumentType), - _eventSuspendLevel(0) -{ - if (pNamePool) - { - _pNamePool = pNamePool; - _pNamePool->duplicate(); - } - else - { - _pNamePool = new NamePool; - } - if (_pDocumentType) - { - _pDocumentType->duplicate(); - _pDocumentType->setOwnerDocument(this); - } -} - - -Document::~Document() -{ - if (_pDocumentType) _pDocumentType->release(); - _pNamePool->release(); -} - - -bool Document::dispatchEvent(Event* evt) -{ - return _eventSuspendLevel > 0 || AbstractContainerNode::dispatchEvent(evt); -} - - -void Document::collectGarbage() -{ - _autoReleasePool.release(); -} - - -void Document::suspendEvents() -{ - ++_eventSuspendLevel; -} - - -void Document::resumeEvents() -{ - poco_assert_dbg (_eventSuspendLevel > 0); - - --_eventSuspendLevel; -} - - -const DOMImplementation& Document::implementation() const -{ - return DOMImplementation::instance(); -} - - -Element* Document::documentElement() const -{ - // Skip non-element nodes before the document element - Node* pCur = firstChild(); - while (pCur) - { - if (dynamic_cast(pCur)) - return static_cast(pCur); - pCur = pCur->nextSibling(); - } - return 0; -} - - -Element* Document::createElement(const XMLString& tagName) const -{ - return new Element(const_cast(this), EMPTY_STRING, EMPTY_STRING, tagName); -} - - -DocumentFragment* Document::createDocumentFragment() const -{ - return new DocumentFragment(const_cast(this)); -} - - -Text* Document::createTextNode(const XMLString& data) const -{ - return new Text(const_cast(this), data); -} - - -Comment* Document::createComment(const XMLString& data) const -{ - return new Comment(const_cast(this), data); -} - - -CDATASection* Document::createCDATASection(const XMLString& data) const -{ - return new CDATASection(const_cast(this), data); -} - - -ProcessingInstruction* Document::createProcessingInstruction(const XMLString& target, const XMLString& data) const -{ - return new ProcessingInstruction(const_cast(this), target, data); -} - - -Attr* Document::createAttribute(const XMLString& name) const -{ - return new Attr(const_cast(this), 0, EMPTY_STRING, EMPTY_STRING, name, EMPTY_STRING); -} - - -EntityReference* Document::createEntityReference(const XMLString& name) const -{ - return new EntityReference(const_cast(this), name); -} - - -NodeList* Document::getElementsByTagName(const XMLString& name) const -{ - return new ElementsByTagNameList(const_cast(this), name); -} - - -const XMLString& Document::nodeName() const -{ - return NODE_NAME; -} - - -unsigned short Document::nodeType() const -{ - return Node::DOCUMENT_NODE; -} - - -Node* Document::importNode(Node* importedNode, bool deep) -{ - return static_cast(importedNode)->copyNode(deep, this); -} - - -Element* Document::createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const -{ - return new Element(const_cast(this), namespaceURI, Name::localName(qualifiedName), qualifiedName); -} - - -Attr* Document::createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const -{ - return new Attr(const_cast(this), 0, namespaceURI, Name::localName(qualifiedName), qualifiedName, EMPTY_STRING); -} - - -NodeList* Document::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - return new ElementsByTagNameListNS(const_cast(this), namespaceURI, localName); -} - - -Element* Document::getElementById(const XMLString& elementId) const -{ - return 0; -} - - -Event* Document::createEvent(const XMLString& eventType) const -{ - if (eventType == MutationEvent::DOMSubtreeModified || - eventType == MutationEvent::DOMNodeInserted || - eventType == MutationEvent::DOMNodeRemoved || - eventType == MutationEvent::DOMNodeRemovedFromDocument || - eventType == MutationEvent::DOMNodeInsertedIntoDocument || - eventType == MutationEvent::DOMAttrModified || - eventType == MutationEvent::DOMCharacterDataModified) - { - return new MutationEvent(const_cast(this), eventType); - } - throw DOMException(DOMException::NOT_SUPPORTED_ERR); -} - - -Node* Document::copyNode(bool deep, Document* pOwnerDocument) const -{ - throw DOMException(DOMException::NOT_SUPPORTED_ERR); -} - - -void Document::setDoctype(DocumentType* pDoctype) -{ - if (_pDocumentType) _pDocumentType->release(); - _pDocumentType = pDoctype; - if (_pDocumentType) - { - _pDocumentType->duplicate(); - _pDocumentType->setOwnerDocument(this); - } -} - - -bool Document::eventsSuspended() const -{ - return _eventSuspendLevel > 0; -} - - -bool Document::events() const -{ - return _eventSuspendLevel == 0; -} - - -Entity* Document::createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const -{ - return new Entity(const_cast(this), name, publicId, systemId, notationName); -} - - -Notation* Document::createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const -{ - return new Notation(const_cast(this), name, publicId, systemId); -} - - -Element* Document::getElementById(const XMLString& elementId, const XMLString& idAttribute) const -{ - Element* pElem = documentElement(); - if (pElem) pElem = pElem->getElementById(elementId, idAttribute); - return pElem; -} - - -Element* Document::getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const -{ - Element* pElem = documentElement(); - if (pElem) pElem = pElem->getElementByIdNS(elementId, idAttributeURI, idAttributeLocalName); - return pElem; -} - - -} } // namespace Poco::XML +// +// Document.cpp +// +// $Id: //poco/1.3/XML/src/Document.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/DOMImplementation.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/DocumentFragment.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/Comment.h" +#include "Poco/DOM/CDATASection.h" +#include "Poco/DOM/ProcessingInstruction.h" +#include "Poco/DOM/EntityReference.h" +#include "Poco/DOM/DOMException.h" +#include "Poco/DOM/ElementsByTagNameList.h" +#include "Poco/DOM/Entity.h" +#include "Poco/DOM/Notation.h" +#include "Poco/XML/Name.h" +#include "Poco/XML/NamePool.h" + + +namespace Poco { +namespace XML { + + +const XMLString Document::NODE_NAME = toXMLString("#document"); + + +Document::Document(NamePool* pNamePool): + AbstractContainerNode(0), + _pDocumentType(0), + _eventSuspendLevel(0) +{ + if (pNamePool) + { + _pNamePool = pNamePool; + _pNamePool->duplicate(); + } + else + { + _pNamePool = new NamePool; + } +} + + +Document::Document(DocumentType* pDocumentType, NamePool* pNamePool): + AbstractContainerNode(0), + _pDocumentType(pDocumentType), + _eventSuspendLevel(0) +{ + if (pNamePool) + { + _pNamePool = pNamePool; + _pNamePool->duplicate(); + } + else + { + _pNamePool = new NamePool; + } + if (_pDocumentType) + { + _pDocumentType->duplicate(); + _pDocumentType->setOwnerDocument(this); + } +} + + +Document::~Document() +{ + if (_pDocumentType) _pDocumentType->release(); + _pNamePool->release(); +} + + +bool Document::dispatchEvent(Event* evt) +{ + return _eventSuspendLevel > 0 || AbstractContainerNode::dispatchEvent(evt); +} + + +void Document::collectGarbage() +{ + _autoReleasePool.release(); +} + + +void Document::suspendEvents() +{ + ++_eventSuspendLevel; +} + + +void Document::resumeEvents() +{ + poco_assert_dbg (_eventSuspendLevel > 0); + + --_eventSuspendLevel; +} + + +const DOMImplementation& Document::implementation() const +{ + return DOMImplementation::instance(); +} + + +Element* Document::documentElement() const +{ + // Skip non-element nodes before the document element + Node* pCur = firstChild(); + while (pCur) + { + if (dynamic_cast(pCur)) + return static_cast(pCur); + pCur = pCur->nextSibling(); + } + return 0; +} + + +Element* Document::createElement(const XMLString& tagName) const +{ + return new Element(const_cast(this), EMPTY_STRING, EMPTY_STRING, tagName); +} + + +DocumentFragment* Document::createDocumentFragment() const +{ + return new DocumentFragment(const_cast(this)); +} + + +Text* Document::createTextNode(const XMLString& data) const +{ + return new Text(const_cast(this), data); +} + + +Comment* Document::createComment(const XMLString& data) const +{ + return new Comment(const_cast(this), data); +} + + +CDATASection* Document::createCDATASection(const XMLString& data) const +{ + return new CDATASection(const_cast(this), data); +} + + +ProcessingInstruction* Document::createProcessingInstruction(const XMLString& target, const XMLString& data) const +{ + return new ProcessingInstruction(const_cast(this), target, data); +} + + +Attr* Document::createAttribute(const XMLString& name) const +{ + return new Attr(const_cast(this), 0, EMPTY_STRING, EMPTY_STRING, name, EMPTY_STRING); +} + + +EntityReference* Document::createEntityReference(const XMLString& name) const +{ + return new EntityReference(const_cast(this), name); +} + + +NodeList* Document::getElementsByTagName(const XMLString& name) const +{ + return new ElementsByTagNameList(const_cast(this), name); +} + + +const XMLString& Document::nodeName() const +{ + return NODE_NAME; +} + + +unsigned short Document::nodeType() const +{ + return Node::DOCUMENT_NODE; +} + + +Node* Document::importNode(Node* importedNode, bool deep) +{ + return static_cast(importedNode)->copyNode(deep, this); +} + + +Element* Document::createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const +{ + return new Element(const_cast(this), namespaceURI, Name::localName(qualifiedName), qualifiedName); +} + + +Attr* Document::createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const +{ + return new Attr(const_cast(this), 0, namespaceURI, Name::localName(qualifiedName), qualifiedName, EMPTY_STRING); +} + + +NodeList* Document::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + return new ElementsByTagNameListNS(const_cast(this), namespaceURI, localName); +} + + +Element* Document::getElementById(const XMLString& elementId) const +{ + return 0; +} + + +Event* Document::createEvent(const XMLString& eventType) const +{ + if (eventType == MutationEvent::DOMSubtreeModified || + eventType == MutationEvent::DOMNodeInserted || + eventType == MutationEvent::DOMNodeRemoved || + eventType == MutationEvent::DOMNodeRemovedFromDocument || + eventType == MutationEvent::DOMNodeInsertedIntoDocument || + eventType == MutationEvent::DOMAttrModified || + eventType == MutationEvent::DOMCharacterDataModified) + { + return new MutationEvent(const_cast(this), eventType); + } + throw DOMException(DOMException::NOT_SUPPORTED_ERR); +} + + +Node* Document::copyNode(bool deep, Document* pOwnerDocument) const +{ + throw DOMException(DOMException::NOT_SUPPORTED_ERR); +} + + +void Document::setDoctype(DocumentType* pDoctype) +{ + if (_pDocumentType) _pDocumentType->release(); + _pDocumentType = pDoctype; + if (_pDocumentType) + { + _pDocumentType->duplicate(); + _pDocumentType->setOwnerDocument(this); + } +} + + +bool Document::eventsSuspended() const +{ + return _eventSuspendLevel > 0; +} + + +bool Document::events() const +{ + return _eventSuspendLevel == 0; +} + + +Entity* Document::createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const +{ + return new Entity(const_cast(this), name, publicId, systemId, notationName); +} + + +Notation* Document::createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const +{ + return new Notation(const_cast(this), name, publicId, systemId); +} + + +Element* Document::getElementById(const XMLString& elementId, const XMLString& idAttribute) const +{ + Element* pElem = documentElement(); + if (pElem) pElem = pElem->getElementById(elementId, idAttribute); + return pElem; +} + + +Element* Document::getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const +{ + Element* pElem = documentElement(); + if (pElem) pElem = pElem->getElementByIdNS(elementId, idAttributeURI, idAttributeLocalName); + return pElem; +} + + +} } // namespace Poco::XML diff --git a/XML/src/DocumentEvent.cpp b/XML/src/DocumentEvent.cpp index d52418a12..1d159c49c 100644 --- a/XML/src/DocumentEvent.cpp +++ b/XML/src/DocumentEvent.cpp @@ -1,49 +1,49 @@ -// -// DocumentEvent.cpp -// -// $Id: //poco/1.3/XML/src/DocumentEvent.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DocumentEvent.h" - - -namespace Poco { -namespace XML { - - -DocumentEvent::~DocumentEvent() -{ -} - - -} } // namespace Poco::XML +// +// DocumentEvent.cpp +// +// $Id: //poco/1.3/XML/src/DocumentEvent.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DocumentEvent.h" + + +namespace Poco { +namespace XML { + + +DocumentEvent::~DocumentEvent() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/DocumentFragment.cpp b/XML/src/DocumentFragment.cpp index 854d66120..d969e21ad 100644 --- a/XML/src/DocumentFragment.cpp +++ b/XML/src/DocumentFragment.cpp @@ -1,92 +1,92 @@ -// -// DocumentFragment.cpp -// -// $Id: //poco/1.3/XML/src/DocumentFragment.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DocumentFragment.h" - - -namespace Poco { -namespace XML { - - -const XMLString DocumentFragment::NODE_NAME = toXMLString("#document-fragment"); - - -DocumentFragment::DocumentFragment(Document* pOwnerDocument): - AbstractContainerNode(pOwnerDocument) -{ -} - - -DocumentFragment::DocumentFragment( Document* pOwnerDocument, const DocumentFragment& fragment): - AbstractContainerNode(pOwnerDocument, fragment) -{ -} - - -DocumentFragment::~DocumentFragment() -{ -} - - -const XMLString& DocumentFragment::nodeName() const -{ - return NODE_NAME; -} - - -unsigned short DocumentFragment::nodeType() const -{ - return Node::DOCUMENT_FRAGMENT_NODE; -} - - -Node* DocumentFragment::copyNode(bool deep, Document* pOwnerDocument) const -{ - DocumentFragment* pClone = new DocumentFragment(pOwnerDocument, *this); - if (deep) - { - Node* pCur = firstChild(); - while (pCur) - { - pClone->appendChild(static_cast(pCur)->copyNode(deep, pOwnerDocument))->release(); - pCur = pCur->nextSibling(); - } - } - return pClone; -} - - -} } // namespace Poco::XML +// +// DocumentFragment.cpp +// +// $Id: //poco/1.3/XML/src/DocumentFragment.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DocumentFragment.h" + + +namespace Poco { +namespace XML { + + +const XMLString DocumentFragment::NODE_NAME = toXMLString("#document-fragment"); + + +DocumentFragment::DocumentFragment(Document* pOwnerDocument): + AbstractContainerNode(pOwnerDocument) +{ +} + + +DocumentFragment::DocumentFragment( Document* pOwnerDocument, const DocumentFragment& fragment): + AbstractContainerNode(pOwnerDocument, fragment) +{ +} + + +DocumentFragment::~DocumentFragment() +{ +} + + +const XMLString& DocumentFragment::nodeName() const +{ + return NODE_NAME; +} + + +unsigned short DocumentFragment::nodeType() const +{ + return Node::DOCUMENT_FRAGMENT_NODE; +} + + +Node* DocumentFragment::copyNode(bool deep, Document* pOwnerDocument) const +{ + DocumentFragment* pClone = new DocumentFragment(pOwnerDocument, *this); + if (deep) + { + Node* pCur = firstChild(); + while (pCur) + { + pClone->appendChild(static_cast(pCur)->copyNode(deep, pOwnerDocument))->release(); + pCur = pCur->nextSibling(); + } + } + return pClone; +} + + +} } // namespace Poco::XML diff --git a/XML/src/DocumentType.cpp b/XML/src/DocumentType.cpp index fa43eedaa..7424b46a7 100644 --- a/XML/src/DocumentType.cpp +++ b/XML/src/DocumentType.cpp @@ -1,106 +1,106 @@ -// -// DocumentType.cpp -// -// $Id: //poco/1.3/XML/src/DocumentType.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DTDMap.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -DocumentType::DocumentType(Document* pOwner, const XMLString& name, const XMLString& publicId, const XMLString& systemId): - AbstractContainerNode(pOwner), - _name(name), - _publicId(publicId), - _systemId(systemId) -{ -} - - -DocumentType::DocumentType(Document* pOwner, const DocumentType& doctype): - AbstractContainerNode(pOwner, doctype), - _name(doctype._name), - _publicId(doctype._publicId), - _systemId(doctype._systemId) -{ -} - - -DocumentType::~DocumentType() -{ -} - - -NamedNodeMap* DocumentType::entities() const -{ - return new DTDMap(this, Node::ENTITY_NODE); -} - - -NamedNodeMap* DocumentType::notations() const -{ - return new DTDMap(this, Node::NOTATION_NODE); -} - - -const XMLString& DocumentType::nodeName() const -{ - return _name; -} - - -unsigned short DocumentType::nodeType() const -{ - return Node::DOCUMENT_TYPE_NODE; -} - - -const XMLString& DocumentType::internalSubset() const -{ - return EMPTY_STRING; -} - - -Node* DocumentType::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new DocumentType(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// DocumentType.cpp +// +// $Id: //poco/1.3/XML/src/DocumentType.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DTDMap.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +DocumentType::DocumentType(Document* pOwner, const XMLString& name, const XMLString& publicId, const XMLString& systemId): + AbstractContainerNode(pOwner), + _name(name), + _publicId(publicId), + _systemId(systemId) +{ +} + + +DocumentType::DocumentType(Document* pOwner, const DocumentType& doctype): + AbstractContainerNode(pOwner, doctype), + _name(doctype._name), + _publicId(doctype._publicId), + _systemId(doctype._systemId) +{ +} + + +DocumentType::~DocumentType() +{ +} + + +NamedNodeMap* DocumentType::entities() const +{ + return new DTDMap(this, Node::ENTITY_NODE); +} + + +NamedNodeMap* DocumentType::notations() const +{ + return new DTDMap(this, Node::NOTATION_NODE); +} + + +const XMLString& DocumentType::nodeName() const +{ + return _name; +} + + +unsigned short DocumentType::nodeType() const +{ + return Node::DOCUMENT_TYPE_NODE; +} + + +const XMLString& DocumentType::internalSubset() const +{ + return EMPTY_STRING; +} + + +Node* DocumentType::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new DocumentType(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/Element.cpp b/XML/src/Element.cpp index 403bfcca8..893dad00a 100644 --- a/XML/src/Element.cpp +++ b/XML/src/Element.cpp @@ -1,466 +1,466 @@ -// -// Element.cpp -// -// $Id: //poco/1.3/XML/src/Element.cpp#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/DOMException.h" -#include "Poco/DOM/ElementsByTagNameList.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/AttrMap.h" - - -namespace Poco { -namespace XML { - - -Element::Element(Document* pOwnerDocument, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname): - AbstractContainerNode(pOwnerDocument), - _name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)), - _pFirstAttr(0) -{ -} - - -Element::Element(Document* pOwnerDocument, const Element& element): - AbstractContainerNode(pOwnerDocument, element), - _name(pOwnerDocument->namePool().insert(element._name)), - _pFirstAttr(0) -{ - Attr* pAttr = element._pFirstAttr; - while (pAttr) - { - Attr* pClonedAttr = static_cast(pAttr->copyNode(false, pOwnerDocument)); - setAttributeNode(pClonedAttr); - pClonedAttr->release(); - pAttr = static_cast(pAttr->_pNext); - } -} - - -Element::~Element() -{ - if (_pFirstAttr) _pFirstAttr->release(); -} - - -const XMLString& Element::getAttribute(const XMLString& name) const -{ - Attr* pAttr = getAttributeNode(name); - if (pAttr) - return pAttr->getValue(); - else - return EMPTY_STRING; -} - - -void Element::setAttribute(const XMLString& name, const XMLString& value) -{ - Attr* pAttr = getAttributeNode(name); - if (pAttr) - { - pAttr->setValue(value); - } - else - { - pAttr = ownerDocument()->createAttribute(name); - pAttr->setValue(value); - setAttributeNode(pAttr); - pAttr->release(); - } -} - - -void Element::removeAttribute(const XMLString& name) -{ - Attr* pAttr = getAttributeNode(name); - if (pAttr) removeAttributeNode(pAttr); -} - - -Attr* Element::getAttributeNode(const XMLString& name) const -{ - Attr* pAttr = _pFirstAttr; - while (pAttr && pAttr->_name.qname() != name) pAttr = static_cast(pAttr->_pNext); - return pAttr; -} - - -Attr* Element::setAttributeNode(Attr* newAttr) -{ - poco_check_ptr (newAttr); - - if (newAttr->ownerDocument() != ownerDocument()) - throw DOMException(DOMException::WRONG_DOCUMENT_ERR); - if (newAttr->ownerElement()) - throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); - - Attr* oldAttr = getAttributeNode(newAttr->name()); - if (oldAttr) removeAttributeNode(oldAttr); - - Attr* pCur = _pFirstAttr; - if (pCur) - { - while (pCur->_pNext) pCur = static_cast(pCur->_pNext); - pCur->_pNext = newAttr; - } - else _pFirstAttr = newAttr; - newAttr->duplicate(); - newAttr->_pParent = this; - if (_pOwner->events()) - dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue()); - - return oldAttr; -} - - -Attr* Element::removeAttributeNode(Attr* oldAttr) -{ - poco_check_ptr (oldAttr); - - if (_pOwner->events()) - dispatchAttrModified(oldAttr, MutationEvent::REMOVAL, oldAttr->getValue(), EMPTY_STRING); - - if (oldAttr != _pFirstAttr) - { - Attr* pCur = _pFirstAttr; - while (pCur->_pNext != oldAttr) pCur = static_cast(pCur->_pNext); - if (pCur) - { - pCur->_pNext = static_cast(pCur->_pNext->_pNext); - } - else throw DOMException(DOMException::NOT_FOUND_ERR); - } - else _pFirstAttr = static_cast(_pFirstAttr->_pNext); - oldAttr->_pNext = 0; - oldAttr->_pParent = 0; - oldAttr->autoRelease(); - - return oldAttr; -} - - -Attr* Element::addAttributeNodeNP(Attr* oldAttr, Attr* newAttr) -{ - newAttr->_pParent = this; - if (oldAttr) - { - oldAttr->_pNext = newAttr; - } - else if (_pFirstAttr) - { - newAttr->_pNext = _pFirstAttr; - _pFirstAttr = newAttr; - } - else - { - _pFirstAttr = newAttr; - } - newAttr->duplicate(); - return newAttr; -} - - -NodeList* Element::getElementsByTagName(const XMLString& name) const -{ - return new ElementsByTagNameList(this, name); -} - - -NodeList* Element::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - return new ElementsByTagNameListNS(this, namespaceURI, localName); -} - - -void Element::normalize() -{ - Node* pCur = firstChild(); - while (pCur) - { - if (pCur->nodeType() == Node::ELEMENT_NODE) - { - pCur->normalize(); - } - else if (pCur->nodeType() == Node::TEXT_NODE) - { - Node* pNext = pCur->nextSibling(); - while (pNext && pNext->nodeType() == Node::TEXT_NODE) - { - static_cast(pCur)->appendData(pNext->nodeValue()); - removeChild(pNext); - pNext = pCur->nextSibling(); - } - } - pCur = pCur->nextSibling(); - } -} - - -const XMLString& Element::nodeName() const -{ - return tagName(); -} - - -NamedNodeMap* Element::attributes() const -{ - return new AttrMap(const_cast(this)); -} - - -unsigned short Element::nodeType() const -{ - return Node::ELEMENT_NODE; -} - - -const XMLString& Element::getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - Attr* pAttr = getAttributeNodeNS(namespaceURI, localName); - if (pAttr) - return pAttr->getValue(); - else - return EMPTY_STRING; -} - - -void Element::setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value) -{ - Attr* pAttr = getAttributeNodeNS(namespaceURI, qualifiedName); - if (pAttr) - { - pAttr->setValue(value); - } - else - { - pAttr = _pOwner->createAttributeNS(namespaceURI, qualifiedName); - pAttr->setValue(value); - setAttributeNodeNS(pAttr); - pAttr->release(); - } -} - - -void Element::removeAttributeNS(const XMLString& namespaceURI, const XMLString& localName) -{ - Attr* pAttr = getAttributeNodeNS(namespaceURI, localName); - if (pAttr) removeAttributeNode(pAttr); -} - - -Attr* Element::getAttributeNodeNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - Attr* pAttr = _pFirstAttr; - while (pAttr && (pAttr->_name.namespaceURI() != namespaceURI || pAttr->_name.localName() != localName)) pAttr = static_cast(pAttr->_pNext); - return pAttr; -} - - -Attr* Element::setAttributeNodeNS(Attr* newAttr) -{ - poco_check_ptr (newAttr); - - if (newAttr->ownerDocument() != ownerDocument()) - throw DOMException(DOMException::WRONG_DOCUMENT_ERR); - if (newAttr->ownerElement()) - throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); - - Attr* oldAttr = getAttributeNodeNS(newAttr->namespaceURI(), newAttr->localName()); - if (oldAttr) removeAttributeNode(oldAttr); - - Attr* pCur = _pFirstAttr; - if (pCur) - { - while (pCur->_pNext) pCur = static_cast(pCur->_pNext); - pCur->_pNext = newAttr; - } - else _pFirstAttr = newAttr; - newAttr->_pParent = this; - newAttr->duplicate(); - if (_pOwner->events()) - dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue()); - - return oldAttr; -} - - -bool Element::hasAttribute(const XMLString& name) const -{ - return getAttributeNode(name) != 0; -} - - -bool Element::hasAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - return getAttributeNodeNS(namespaceURI, localName) != 0; -} - - -const XMLString& Element::namespaceURI() const -{ - return _name.namespaceURI(); -} - - -XMLString Element::prefix() const -{ - return _name.prefix(); -} - - -const XMLString& Element::localName() const -{ - return _name.localName(); -} - - -bool Element::hasAttributes() const -{ - return _pFirstAttr != 0; -} - - -XMLString Element::innerText() const -{ - XMLString result; - Node* pChild = firstChild(); - while (pChild) - { - result.append(pChild->innerText()); - pChild = pChild->nextSibling(); - } - return result; -} - - -Element* Element::getChildElement(const XMLString& name) const -{ - Node* pNode = firstChild(); - while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->nodeName() == name)) - pNode = pNode->nextSibling(); - return static_cast(pNode); -} - - -Element* Element::getChildElementNS(const XMLString& namespaceURI, const XMLString& localName) const -{ - Node* pNode = firstChild(); - while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->namespaceURI() == namespaceURI && pNode->localName() == localName)) - pNode = pNode->nextSibling(); - return static_cast(pNode); -} - - -void Element::dispatchNodeRemovedFromDocument() -{ - AbstractContainerNode::dispatchNodeRemovedFromDocument(); - Attr* pAttr = _pFirstAttr; - while (pAttr) - { - pAttr->dispatchNodeRemovedFromDocument(); - pAttr = static_cast(pAttr->_pNext); - } -} - - -void Element::dispatchNodeInsertedIntoDocument() -{ - AbstractContainerNode::dispatchNodeInsertedIntoDocument(); - Attr* pAttr = _pFirstAttr; - while (pAttr) - { - pAttr->dispatchNodeInsertedIntoDocument(); - pAttr = static_cast(pAttr->_pNext); - } -} - - -Node* Element::copyNode(bool deep, Document* pOwnerDocument) const -{ - Element* pClone = new Element(pOwnerDocument, *this); - if (deep) - { - Node* pNode = firstChild(); - while (pNode) - { - pClone->appendChild(static_cast(pNode)->copyNode(true, pOwnerDocument))->release(); - pNode = pNode->nextSibling(); - } - } - return pClone; -} - - -Element* Element::getElementById(const XMLString& elementId, const XMLString& idAttribute) const -{ - if (getAttribute(idAttribute) == elementId) - return const_cast(this); - - Node* pNode = firstChild(); - while (pNode) - { - if (pNode->nodeType() == Node::ELEMENT_NODE) - { - Element* pResult = static_cast(pNode)->getElementById(elementId, idAttribute); - if (pResult) return pResult; - } - pNode = pNode->nextSibling(); - } - return 0; -} - - -Element* Element::getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const -{ - if (getAttributeNS(idAttributeURI, idAttributeLocalName) == elementId) - return const_cast(this); - - Node* pNode = firstChild(); - while (pNode) - { - if (pNode->nodeType() == Node::ELEMENT_NODE) - { - Element* pResult = static_cast(pNode)->getElementByIdNS(elementId, idAttributeURI, idAttributeLocalName); - if (pResult) return pResult; - } - pNode = pNode->nextSibling(); - } - return 0; -} - - -} } // namespace Poco::XML +// +// Element.cpp +// +// $Id: //poco/1.3/XML/src/Element.cpp#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/DOMException.h" +#include "Poco/DOM/ElementsByTagNameList.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/AttrMap.h" + + +namespace Poco { +namespace XML { + + +Element::Element(Document* pOwnerDocument, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname): + AbstractContainerNode(pOwnerDocument), + _name(pOwnerDocument->namePool().insert(qname, namespaceURI, localName)), + _pFirstAttr(0) +{ +} + + +Element::Element(Document* pOwnerDocument, const Element& element): + AbstractContainerNode(pOwnerDocument, element), + _name(pOwnerDocument->namePool().insert(element._name)), + _pFirstAttr(0) +{ + Attr* pAttr = element._pFirstAttr; + while (pAttr) + { + Attr* pClonedAttr = static_cast(pAttr->copyNode(false, pOwnerDocument)); + setAttributeNode(pClonedAttr); + pClonedAttr->release(); + pAttr = static_cast(pAttr->_pNext); + } +} + + +Element::~Element() +{ + if (_pFirstAttr) _pFirstAttr->release(); +} + + +const XMLString& Element::getAttribute(const XMLString& name) const +{ + Attr* pAttr = getAttributeNode(name); + if (pAttr) + return pAttr->getValue(); + else + return EMPTY_STRING; +} + + +void Element::setAttribute(const XMLString& name, const XMLString& value) +{ + Attr* pAttr = getAttributeNode(name); + if (pAttr) + { + pAttr->setValue(value); + } + else + { + pAttr = ownerDocument()->createAttribute(name); + pAttr->setValue(value); + setAttributeNode(pAttr); + pAttr->release(); + } +} + + +void Element::removeAttribute(const XMLString& name) +{ + Attr* pAttr = getAttributeNode(name); + if (pAttr) removeAttributeNode(pAttr); +} + + +Attr* Element::getAttributeNode(const XMLString& name) const +{ + Attr* pAttr = _pFirstAttr; + while (pAttr && pAttr->_name.qname() != name) pAttr = static_cast(pAttr->_pNext); + return pAttr; +} + + +Attr* Element::setAttributeNode(Attr* newAttr) +{ + poco_check_ptr (newAttr); + + if (newAttr->ownerDocument() != ownerDocument()) + throw DOMException(DOMException::WRONG_DOCUMENT_ERR); + if (newAttr->ownerElement()) + throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); + + Attr* oldAttr = getAttributeNode(newAttr->name()); + if (oldAttr) removeAttributeNode(oldAttr); + + Attr* pCur = _pFirstAttr; + if (pCur) + { + while (pCur->_pNext) pCur = static_cast(pCur->_pNext); + pCur->_pNext = newAttr; + } + else _pFirstAttr = newAttr; + newAttr->duplicate(); + newAttr->_pParent = this; + if (_pOwner->events()) + dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue()); + + return oldAttr; +} + + +Attr* Element::removeAttributeNode(Attr* oldAttr) +{ + poco_check_ptr (oldAttr); + + if (_pOwner->events()) + dispatchAttrModified(oldAttr, MutationEvent::REMOVAL, oldAttr->getValue(), EMPTY_STRING); + + if (oldAttr != _pFirstAttr) + { + Attr* pCur = _pFirstAttr; + while (pCur->_pNext != oldAttr) pCur = static_cast(pCur->_pNext); + if (pCur) + { + pCur->_pNext = static_cast(pCur->_pNext->_pNext); + } + else throw DOMException(DOMException::NOT_FOUND_ERR); + } + else _pFirstAttr = static_cast(_pFirstAttr->_pNext); + oldAttr->_pNext = 0; + oldAttr->_pParent = 0; + oldAttr->autoRelease(); + + return oldAttr; +} + + +Attr* Element::addAttributeNodeNP(Attr* oldAttr, Attr* newAttr) +{ + newAttr->_pParent = this; + if (oldAttr) + { + oldAttr->_pNext = newAttr; + } + else if (_pFirstAttr) + { + newAttr->_pNext = _pFirstAttr; + _pFirstAttr = newAttr; + } + else + { + _pFirstAttr = newAttr; + } + newAttr->duplicate(); + return newAttr; +} + + +NodeList* Element::getElementsByTagName(const XMLString& name) const +{ + return new ElementsByTagNameList(this, name); +} + + +NodeList* Element::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + return new ElementsByTagNameListNS(this, namespaceURI, localName); +} + + +void Element::normalize() +{ + Node* pCur = firstChild(); + while (pCur) + { + if (pCur->nodeType() == Node::ELEMENT_NODE) + { + pCur->normalize(); + } + else if (pCur->nodeType() == Node::TEXT_NODE) + { + Node* pNext = pCur->nextSibling(); + while (pNext && pNext->nodeType() == Node::TEXT_NODE) + { + static_cast(pCur)->appendData(pNext->nodeValue()); + removeChild(pNext); + pNext = pCur->nextSibling(); + } + } + pCur = pCur->nextSibling(); + } +} + + +const XMLString& Element::nodeName() const +{ + return tagName(); +} + + +NamedNodeMap* Element::attributes() const +{ + return new AttrMap(const_cast(this)); +} + + +unsigned short Element::nodeType() const +{ + return Node::ELEMENT_NODE; +} + + +const XMLString& Element::getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + Attr* pAttr = getAttributeNodeNS(namespaceURI, localName); + if (pAttr) + return pAttr->getValue(); + else + return EMPTY_STRING; +} + + +void Element::setAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName, const XMLString& value) +{ + Attr* pAttr = getAttributeNodeNS(namespaceURI, qualifiedName); + if (pAttr) + { + pAttr->setValue(value); + } + else + { + pAttr = _pOwner->createAttributeNS(namespaceURI, qualifiedName); + pAttr->setValue(value); + setAttributeNodeNS(pAttr); + pAttr->release(); + } +} + + +void Element::removeAttributeNS(const XMLString& namespaceURI, const XMLString& localName) +{ + Attr* pAttr = getAttributeNodeNS(namespaceURI, localName); + if (pAttr) removeAttributeNode(pAttr); +} + + +Attr* Element::getAttributeNodeNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + Attr* pAttr = _pFirstAttr; + while (pAttr && (pAttr->_name.namespaceURI() != namespaceURI || pAttr->_name.localName() != localName)) pAttr = static_cast(pAttr->_pNext); + return pAttr; +} + + +Attr* Element::setAttributeNodeNS(Attr* newAttr) +{ + poco_check_ptr (newAttr); + + if (newAttr->ownerDocument() != ownerDocument()) + throw DOMException(DOMException::WRONG_DOCUMENT_ERR); + if (newAttr->ownerElement()) + throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); + + Attr* oldAttr = getAttributeNodeNS(newAttr->namespaceURI(), newAttr->localName()); + if (oldAttr) removeAttributeNode(oldAttr); + + Attr* pCur = _pFirstAttr; + if (pCur) + { + while (pCur->_pNext) pCur = static_cast(pCur->_pNext); + pCur->_pNext = newAttr; + } + else _pFirstAttr = newAttr; + newAttr->_pParent = this; + newAttr->duplicate(); + if (_pOwner->events()) + dispatchAttrModified(newAttr, MutationEvent::ADDITION, EMPTY_STRING, newAttr->getValue()); + + return oldAttr; +} + + +bool Element::hasAttribute(const XMLString& name) const +{ + return getAttributeNode(name) != 0; +} + + +bool Element::hasAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + return getAttributeNodeNS(namespaceURI, localName) != 0; +} + + +const XMLString& Element::namespaceURI() const +{ + return _name.namespaceURI(); +} + + +XMLString Element::prefix() const +{ + return _name.prefix(); +} + + +const XMLString& Element::localName() const +{ + return _name.localName(); +} + + +bool Element::hasAttributes() const +{ + return _pFirstAttr != 0; +} + + +XMLString Element::innerText() const +{ + XMLString result; + Node* pChild = firstChild(); + while (pChild) + { + result.append(pChild->innerText()); + pChild = pChild->nextSibling(); + } + return result; +} + + +Element* Element::getChildElement(const XMLString& name) const +{ + Node* pNode = firstChild(); + while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->nodeName() == name)) + pNode = pNode->nextSibling(); + return static_cast(pNode); +} + + +Element* Element::getChildElementNS(const XMLString& namespaceURI, const XMLString& localName) const +{ + Node* pNode = firstChild(); + while (pNode && !(pNode->nodeType() == Node::ELEMENT_NODE && pNode->namespaceURI() == namespaceURI && pNode->localName() == localName)) + pNode = pNode->nextSibling(); + return static_cast(pNode); +} + + +void Element::dispatchNodeRemovedFromDocument() +{ + AbstractContainerNode::dispatchNodeRemovedFromDocument(); + Attr* pAttr = _pFirstAttr; + while (pAttr) + { + pAttr->dispatchNodeRemovedFromDocument(); + pAttr = static_cast(pAttr->_pNext); + } +} + + +void Element::dispatchNodeInsertedIntoDocument() +{ + AbstractContainerNode::dispatchNodeInsertedIntoDocument(); + Attr* pAttr = _pFirstAttr; + while (pAttr) + { + pAttr->dispatchNodeInsertedIntoDocument(); + pAttr = static_cast(pAttr->_pNext); + } +} + + +Node* Element::copyNode(bool deep, Document* pOwnerDocument) const +{ + Element* pClone = new Element(pOwnerDocument, *this); + if (deep) + { + Node* pNode = firstChild(); + while (pNode) + { + pClone->appendChild(static_cast(pNode)->copyNode(true, pOwnerDocument))->release(); + pNode = pNode->nextSibling(); + } + } + return pClone; +} + + +Element* Element::getElementById(const XMLString& elementId, const XMLString& idAttribute) const +{ + if (getAttribute(idAttribute) == elementId) + return const_cast(this); + + Node* pNode = firstChild(); + while (pNode) + { + if (pNode->nodeType() == Node::ELEMENT_NODE) + { + Element* pResult = static_cast(pNode)->getElementById(elementId, idAttribute); + if (pResult) return pResult; + } + pNode = pNode->nextSibling(); + } + return 0; +} + + +Element* Element::getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const +{ + if (getAttributeNS(idAttributeURI, idAttributeLocalName) == elementId) + return const_cast(this); + + Node* pNode = firstChild(); + while (pNode) + { + if (pNode->nodeType() == Node::ELEMENT_NODE) + { + Element* pResult = static_cast(pNode)->getElementByIdNS(elementId, idAttributeURI, idAttributeLocalName); + if (pResult) return pResult; + } + pNode = pNode->nextSibling(); + } + return 0; +} + + +} } // namespace Poco::XML diff --git a/XML/src/ElementsByTagNameList.cpp b/XML/src/ElementsByTagNameList.cpp index 55880b527..de7b7341f 100644 --- a/XML/src/ElementsByTagNameList.cpp +++ b/XML/src/ElementsByTagNameList.cpp @@ -1,171 +1,171 @@ -// -// ElementsByTagNameList.cpp -// -// $Id: //poco/1.3/XML/src/ElementsByTagNameList.cpp#2 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/ElementsByTagNameList.h" -#include "Poco/DOM/Node.h" -#include "Poco/DOM/Document.h" -#include - - -namespace Poco { -namespace XML { - - -ElementsByTagNameList::ElementsByTagNameList(const Node* pParent, const XMLString& name): - _pParent(pParent), - _name(name), - _count(0) -{ - poco_check_ptr (pParent); - - _pParent->duplicate(); -} - - -ElementsByTagNameList::~ElementsByTagNameList() -{ - _pParent->release(); -} - - -Node* ElementsByTagNameList::item(unsigned long index) const -{ - _count = 0; - return find(_pParent, index); -} - - -unsigned long ElementsByTagNameList::length() const -{ - _count = 0; - find(_pParent, ULONG_MAX); - return _count; -} - - -Node* ElementsByTagNameList::find(const Node* pParent, unsigned long index) const -{ - static const XMLString asterisk = toXMLString("*"); - - if (!pParent) return 0; - - // preorder search - Node* pCur = pParent->firstChild(); - while (pCur) - { - if (pCur->nodeType() == Node::ELEMENT_NODE && (_name == asterisk || pCur->nodeName() == _name)) - { - if (_count == index) return pCur; - _count++; - } - Node* pNode = find(pCur, index); - if (pNode) return pNode; - pCur = pCur->nextSibling(); - } - return pCur; -} - - -void ElementsByTagNameList::autoRelease() -{ - _pParent->ownerDocument()->autoReleasePool().add(this); -} - - -ElementsByTagNameListNS::ElementsByTagNameListNS(const Node* pParent, const XMLString& namespaceURI, const XMLString& localName): - _pParent(pParent), - _localName(localName), - _namespaceURI(namespaceURI), - _count(0) -{ - poco_check_ptr (pParent); - - _pParent->duplicate(); -} - - - -ElementsByTagNameListNS::~ElementsByTagNameListNS() -{ - _pParent->release(); -} - - -Node* ElementsByTagNameListNS::item(unsigned long index) const -{ - _count = 0; - return find(_pParent, index); -} - - -unsigned long ElementsByTagNameListNS::length() const -{ - _count = 0; - find(_pParent, ULONG_MAX); - return _count; -} - - -Node* ElementsByTagNameListNS::find(const Node* pParent, unsigned long index) const -{ - static const XMLString asterisk = toXMLString("*"); - - if (!pParent) return 0; - - // preorder search - Node* pCur = pParent->firstChild(); - while (pCur) - { - if (pCur->nodeType() == Node::ELEMENT_NODE && (_localName == asterisk || pCur->localName() == _localName) && (_namespaceURI == asterisk || pCur->namespaceURI() == _namespaceURI)) - { - if (_count == index) return pCur; - _count++; - } - Node* pNode = find(pCur, index); - if (pNode) return pNode; - pCur = pCur->nextSibling(); - } - return pCur; -} - - -void ElementsByTagNameListNS::autoRelease() -{ - _pParent->ownerDocument()->autoReleasePool().add(this); -} - - -} } // namespace Poco::XML +// +// ElementsByTagNameList.cpp +// +// $Id: //poco/1.3/XML/src/ElementsByTagNameList.cpp#2 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/ElementsByTagNameList.h" +#include "Poco/DOM/Node.h" +#include "Poco/DOM/Document.h" +#include + + +namespace Poco { +namespace XML { + + +ElementsByTagNameList::ElementsByTagNameList(const Node* pParent, const XMLString& name): + _pParent(pParent), + _name(name), + _count(0) +{ + poco_check_ptr (pParent); + + _pParent->duplicate(); +} + + +ElementsByTagNameList::~ElementsByTagNameList() +{ + _pParent->release(); +} + + +Node* ElementsByTagNameList::item(unsigned long index) const +{ + _count = 0; + return find(_pParent, index); +} + + +unsigned long ElementsByTagNameList::length() const +{ + _count = 0; + find(_pParent, ULONG_MAX); + return _count; +} + + +Node* ElementsByTagNameList::find(const Node* pParent, unsigned long index) const +{ + static const XMLString asterisk = toXMLString("*"); + + if (!pParent) return 0; + + // preorder search + Node* pCur = pParent->firstChild(); + while (pCur) + { + if (pCur->nodeType() == Node::ELEMENT_NODE && (_name == asterisk || pCur->nodeName() == _name)) + { + if (_count == index) return pCur; + _count++; + } + Node* pNode = find(pCur, index); + if (pNode) return pNode; + pCur = pCur->nextSibling(); + } + return pCur; +} + + +void ElementsByTagNameList::autoRelease() +{ + _pParent->ownerDocument()->autoReleasePool().add(this); +} + + +ElementsByTagNameListNS::ElementsByTagNameListNS(const Node* pParent, const XMLString& namespaceURI, const XMLString& localName): + _pParent(pParent), + _localName(localName), + _namespaceURI(namespaceURI), + _count(0) +{ + poco_check_ptr (pParent); + + _pParent->duplicate(); +} + + + +ElementsByTagNameListNS::~ElementsByTagNameListNS() +{ + _pParent->release(); +} + + +Node* ElementsByTagNameListNS::item(unsigned long index) const +{ + _count = 0; + return find(_pParent, index); +} + + +unsigned long ElementsByTagNameListNS::length() const +{ + _count = 0; + find(_pParent, ULONG_MAX); + return _count; +} + + +Node* ElementsByTagNameListNS::find(const Node* pParent, unsigned long index) const +{ + static const XMLString asterisk = toXMLString("*"); + + if (!pParent) return 0; + + // preorder search + Node* pCur = pParent->firstChild(); + while (pCur) + { + if (pCur->nodeType() == Node::ELEMENT_NODE && (_localName == asterisk || pCur->localName() == _localName) && (_namespaceURI == asterisk || pCur->namespaceURI() == _namespaceURI)) + { + if (_count == index) return pCur; + _count++; + } + Node* pNode = find(pCur, index); + if (pNode) return pNode; + pCur = pCur->nextSibling(); + } + return pCur; +} + + +void ElementsByTagNameListNS::autoRelease() +{ + _pParent->ownerDocument()->autoReleasePool().add(this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/Entity.cpp b/XML/src/Entity.cpp index 73c361b6e..fcac858ff 100644 --- a/XML/src/Entity.cpp +++ b/XML/src/Entity.cpp @@ -1,90 +1,90 @@ -// -// Entity.cpp -// -// $Id: //poco/1.3/XML/src/Entity.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Entity.h" - - -namespace Poco { -namespace XML { - - -const XMLString Entity::NODE_NAME = toXMLString("#entity"); - - -Entity::Entity(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName): - AbstractContainerNode(pOwnerDocument), - _name(name), - _publicId(publicId), - _systemId(systemId), - _notationName(notationName) -{ -} - - -Entity::Entity(Document* pOwnerDocument, const Entity& entity): - AbstractContainerNode(pOwnerDocument, entity), - _name(entity._name), - _publicId(entity._publicId), - _systemId(entity._systemId), - _notationName(entity._notationName) -{ -} - - -Entity::~Entity() -{ -} - - -const XMLString& Entity::nodeName() const -{ - return _name; -} - - -unsigned short Entity::nodeType() const -{ - return Node::ENTITY_NODE; -} - - -Node* Entity::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new Entity(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// Entity.cpp +// +// $Id: //poco/1.3/XML/src/Entity.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Entity.h" + + +namespace Poco { +namespace XML { + + +const XMLString Entity::NODE_NAME = toXMLString("#entity"); + + +Entity::Entity(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName): + AbstractContainerNode(pOwnerDocument), + _name(name), + _publicId(publicId), + _systemId(systemId), + _notationName(notationName) +{ +} + + +Entity::Entity(Document* pOwnerDocument, const Entity& entity): + AbstractContainerNode(pOwnerDocument, entity), + _name(entity._name), + _publicId(entity._publicId), + _systemId(entity._systemId), + _notationName(entity._notationName) +{ +} + + +Entity::~Entity() +{ +} + + +const XMLString& Entity::nodeName() const +{ + return _name; +} + + +unsigned short Entity::nodeType() const +{ + return Node::ENTITY_NODE; +} + + +Node* Entity::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new Entity(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/EntityReference.cpp b/XML/src/EntityReference.cpp index 6bf298f5a..8917dc27b 100644 --- a/XML/src/EntityReference.cpp +++ b/XML/src/EntityReference.cpp @@ -1,81 +1,81 @@ -// -// EntityReference.cpp -// -// $Id: //poco/1.3/XML/src/EntityReference.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/EntityReference.h" - - -namespace Poco { -namespace XML { - - -EntityReference::EntityReference(Document* pOwnerDocument, const XMLString& name): - AbstractNode(pOwnerDocument), - _name(name) -{ -} - - -EntityReference::EntityReference(Document* pOwnerDocument, const EntityReference& ref): - AbstractNode(pOwnerDocument, ref), - _name(ref._name) -{ -} - - -EntityReference::~EntityReference() -{ -} - - -const XMLString& EntityReference::nodeName() const -{ - return _name; -} - - -unsigned short EntityReference::nodeType() const -{ - return Node::ENTITY_REFERENCE_NODE; -} - - -Node* EntityReference::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new EntityReference(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// EntityReference.cpp +// +// $Id: //poco/1.3/XML/src/EntityReference.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/EntityReference.h" + + +namespace Poco { +namespace XML { + + +EntityReference::EntityReference(Document* pOwnerDocument, const XMLString& name): + AbstractNode(pOwnerDocument), + _name(name) +{ +} + + +EntityReference::EntityReference(Document* pOwnerDocument, const EntityReference& ref): + AbstractNode(pOwnerDocument, ref), + _name(ref._name) +{ +} + + +EntityReference::~EntityReference() +{ +} + + +const XMLString& EntityReference::nodeName() const +{ + return _name; +} + + +unsigned short EntityReference::nodeType() const +{ + return Node::ENTITY_REFERENCE_NODE; +} + + +Node* EntityReference::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new EntityReference(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/EntityResolver.cpp b/XML/src/EntityResolver.cpp index 973693552..a630994f4 100644 --- a/XML/src/EntityResolver.cpp +++ b/XML/src/EntityResolver.cpp @@ -1,49 +1,49 @@ -// -// EntityResolver.cpp -// -// $Id: //poco/1.3/XML/src/EntityResolver.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/EntityResolver.h" - - -namespace Poco { -namespace XML { - - -EntityResolver::~EntityResolver() -{ -} - - -} } // namespace Poco::XML +// +// EntityResolver.cpp +// +// $Id: //poco/1.3/XML/src/EntityResolver.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/EntityResolver.h" + + +namespace Poco { +namespace XML { + + +EntityResolver::~EntityResolver() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/EntityResolverImpl.cpp b/XML/src/EntityResolverImpl.cpp index 1fd6b6f35..ad424aef0 100644 --- a/XML/src/EntityResolverImpl.cpp +++ b/XML/src/EntityResolverImpl.cpp @@ -1,100 +1,100 @@ -// -// EntityResolverImpl.cpp -// -// $Id: //poco/1.3/XML/src/EntityResolverImpl.cpp#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/EntityResolverImpl.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/XML/XMLString.h" -#include "Poco/URI.h" -#include "Poco/Path.h" -#include "Poco/Exception.h" - - -using Poco::URIStreamOpener; -using Poco::URI; -using Poco::Path; -using Poco::Exception; -using Poco::IOException; -using Poco::OpenFileException; - - -namespace Poco { -namespace XML { - - -EntityResolverImpl::EntityResolverImpl(): - _opener(URIStreamOpener::defaultOpener()) -{ -} - - -EntityResolverImpl::EntityResolverImpl(const URIStreamOpener& opener): - _opener(opener) -{ -} - - -EntityResolverImpl::~EntityResolverImpl() -{ -} - - -InputSource* EntityResolverImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) -{ - std::istream* pIstr = resolveSystemId(systemId); - InputSource* pInputSource = new InputSource(systemId); - if (publicId) pInputSource->setPublicId(*publicId); - pInputSource->setByteStream(*pIstr); - return pInputSource; -} - - -void EntityResolverImpl::releaseInputSource(InputSource* pSource) -{ - poco_check_ptr (pSource); - - delete pSource->getByteStream(); - delete pSource; -} - - -std::istream* EntityResolverImpl::resolveSystemId(const XMLString& systemId) -{ - std::string sid = fromXMLString(systemId); - return _opener.open(sid); -} - - -} } // namespace Poco::XML +// +// EntityResolverImpl.cpp +// +// $Id: //poco/1.3/XML/src/EntityResolverImpl.cpp#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/EntityResolverImpl.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/XML/XMLString.h" +#include "Poco/URI.h" +#include "Poco/Path.h" +#include "Poco/Exception.h" + + +using Poco::URIStreamOpener; +using Poco::URI; +using Poco::Path; +using Poco::Exception; +using Poco::IOException; +using Poco::OpenFileException; + + +namespace Poco { +namespace XML { + + +EntityResolverImpl::EntityResolverImpl(): + _opener(URIStreamOpener::defaultOpener()) +{ +} + + +EntityResolverImpl::EntityResolverImpl(const URIStreamOpener& opener): + _opener(opener) +{ +} + + +EntityResolverImpl::~EntityResolverImpl() +{ +} + + +InputSource* EntityResolverImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) +{ + std::istream* pIstr = resolveSystemId(systemId); + InputSource* pInputSource = new InputSource(systemId); + if (publicId) pInputSource->setPublicId(*publicId); + pInputSource->setByteStream(*pIstr); + return pInputSource; +} + + +void EntityResolverImpl::releaseInputSource(InputSource* pSource) +{ + poco_check_ptr (pSource); + + delete pSource->getByteStream(); + delete pSource; +} + + +std::istream* EntityResolverImpl::resolveSystemId(const XMLString& systemId) +{ + std::string sid = fromXMLString(systemId); + return _opener.open(sid); +} + + +} } // namespace Poco::XML diff --git a/XML/src/ErrorHandler.cpp b/XML/src/ErrorHandler.cpp index 92bede355..8b5d96641 100644 --- a/XML/src/ErrorHandler.cpp +++ b/XML/src/ErrorHandler.cpp @@ -1,49 +1,49 @@ -// -// ErrorHandler.cpp -// -// $Id: //poco/1.3/XML/src/ErrorHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/ErrorHandler.h" - - -namespace Poco { -namespace XML { - - -ErrorHandler::~ErrorHandler() -{ -} - - -} } // namespace Poco::XML +// +// ErrorHandler.cpp +// +// $Id: //poco/1.3/XML/src/ErrorHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/ErrorHandler.h" + + +namespace Poco { +namespace XML { + + +ErrorHandler::~ErrorHandler() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/Event.cpp b/XML/src/Event.cpp index 3fcf5b05a..a36b8c5b0 100644 --- a/XML/src/Event.cpp +++ b/XML/src/Event.cpp @@ -1,124 +1,124 @@ -// -// Event.cpp -// -// $Id: //poco/1.3/XML/src/Event.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Event.h" -#include "Poco/DOM/Document.h" - - -namespace Poco { -namespace XML { - - -Event::Event(Document* pOwnerDocument, const XMLString& type): - _pOwner(pOwnerDocument), - _type(type), - _pTarget(0), - _pCurrentTarget(0), - _currentPhase(CAPTURING_PHASE), - _bubbles(true), - _cancelable(true), - _canceled(false), - _stopped(false) -{ -} - - -Event::Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable): - _pOwner(pOwnerDocument), - _type(type), - _pTarget(pTarget), - _pCurrentTarget(0), - _currentPhase(CAPTURING_PHASE), - _bubbles(canBubble), - _cancelable(isCancelable), - _canceled(false), - _stopped(false) -{ -} - - -Event::~Event() -{ -} - - -void Event::stopPropagation() -{ - _stopped = true; -} - - -void Event::preventDefault() -{ - _canceled = true; -} - - -void Event::initEvent(const XMLString& eventType, bool canBubble, bool isCancelable) -{ - _type = eventType; - _bubbles = canBubble; - _cancelable = isCancelable; - _canceled = false; - _stopped = false; -} - - -void Event::setTarget(EventTarget* pTarget) -{ - _pTarget = pTarget; -} - - -void Event::setCurrentPhase(PhaseType phase) -{ - _currentPhase = phase; -} - - -void Event::setCurrentTarget(EventTarget* pTarget) -{ - _pCurrentTarget = pTarget; -} - - -void Event::autoRelease() -{ - _pOwner->autoReleasePool().add(this); -} - - -} } // namespace Poco::XML +// +// Event.cpp +// +// $Id: //poco/1.3/XML/src/Event.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Event.h" +#include "Poco/DOM/Document.h" + + +namespace Poco { +namespace XML { + + +Event::Event(Document* pOwnerDocument, const XMLString& type): + _pOwner(pOwnerDocument), + _type(type), + _pTarget(0), + _pCurrentTarget(0), + _currentPhase(CAPTURING_PHASE), + _bubbles(true), + _cancelable(true), + _canceled(false), + _stopped(false) +{ +} + + +Event::Event(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool isCancelable): + _pOwner(pOwnerDocument), + _type(type), + _pTarget(pTarget), + _pCurrentTarget(0), + _currentPhase(CAPTURING_PHASE), + _bubbles(canBubble), + _cancelable(isCancelable), + _canceled(false), + _stopped(false) +{ +} + + +Event::~Event() +{ +} + + +void Event::stopPropagation() +{ + _stopped = true; +} + + +void Event::preventDefault() +{ + _canceled = true; +} + + +void Event::initEvent(const XMLString& eventType, bool canBubble, bool isCancelable) +{ + _type = eventType; + _bubbles = canBubble; + _cancelable = isCancelable; + _canceled = false; + _stopped = false; +} + + +void Event::setTarget(EventTarget* pTarget) +{ + _pTarget = pTarget; +} + + +void Event::setCurrentPhase(PhaseType phase) +{ + _currentPhase = phase; +} + + +void Event::setCurrentTarget(EventTarget* pTarget) +{ + _pCurrentTarget = pTarget; +} + + +void Event::autoRelease() +{ + _pOwner->autoReleasePool().add(this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/EventDispatcher.cpp b/XML/src/EventDispatcher.cpp index 6d61c230c..7cdf116e3 100644 --- a/XML/src/EventDispatcher.cpp +++ b/XML/src/EventDispatcher.cpp @@ -1,168 +1,168 @@ -// -// EventDispatcher.cpp -// -// $Id: //poco/1.3/XML/src/EventDispatcher.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/EventDispatcher.h" -#include "Poco/DOM/Event.h" -#include "Poco/DOM/EventListener.h" - - -namespace -{ - class DispatchGuard - { - public: - DispatchGuard(int& count): - _count(count) - { - ++_count; - } - - ~DispatchGuard() - { - --_count; - } - - private: - int& _count; - }; -} - - -namespace Poco { -namespace XML { - - -EventDispatcher::EventDispatcher(): - _inDispatch(0) -{ -} - - -EventDispatcher::~EventDispatcher() -{ -} - - -void EventDispatcher::addEventListener(const XMLString& type, EventListener* listener, bool useCapture) -{ - EventListenerItem item; - item.type = type; - item.pListener = listener; - item.useCapture = useCapture; - _listeners.push_front(item); -} - - -void EventDispatcher::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) -{ - EventListenerList::iterator it = _listeners.begin(); - while (it != _listeners.end()) - { - if (it->type == type && it->pListener == listener && it->useCapture == useCapture) - { - it->pListener = 0; - } - if (!_inDispatch && !it->pListener) - { - EventListenerList::iterator del = it++; - _listeners.erase(del); - } - else ++it; - } -} - - -void EventDispatcher::dispatchEvent(Event* evt) -{ - DispatchGuard guard(_inDispatch); - EventListenerList::iterator it = _listeners.begin(); - while (it != _listeners.end()) - { - if (it->pListener && it->type == evt->type()) - { - it->pListener->handleEvent(evt); - } - if (!it->pListener) - { - EventListenerList::iterator del = it++; - _listeners.erase(del); - } - else ++it; - } -} - - -void EventDispatcher::captureEvent(Event* evt) -{ - DispatchGuard guard(_inDispatch); - EventListenerList::iterator it = _listeners.begin(); - while (it != _listeners.end()) - { - if (it->pListener && it->useCapture && it->type == evt->type()) - { - it->pListener->handleEvent(evt); - } - if (!it->pListener) - { - EventListenerList::iterator del = it++; - _listeners.erase(del); - } - else ++it; - } -} - - -void EventDispatcher::bubbleEvent(Event* evt) -{ - DispatchGuard guard(_inDispatch); - EventListenerList::iterator it = _listeners.begin(); - while (it != _listeners.end()) - { - if (it->pListener && !it->useCapture && it->type == evt->type()) - { - it->pListener->handleEvent(evt); - } - if (!it->pListener) - { - EventListenerList::iterator del = it++; - _listeners.erase(del); - } - else ++it; - } -} - - -} } // namespace Poco::XML +// +// EventDispatcher.cpp +// +// $Id: //poco/1.3/XML/src/EventDispatcher.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/EventDispatcher.h" +#include "Poco/DOM/Event.h" +#include "Poco/DOM/EventListener.h" + + +namespace +{ + class DispatchGuard + { + public: + DispatchGuard(int& count): + _count(count) + { + ++_count; + } + + ~DispatchGuard() + { + --_count; + } + + private: + int& _count; + }; +} + + +namespace Poco { +namespace XML { + + +EventDispatcher::EventDispatcher(): + _inDispatch(0) +{ +} + + +EventDispatcher::~EventDispatcher() +{ +} + + +void EventDispatcher::addEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + EventListenerItem item; + item.type = type; + item.pListener = listener; + item.useCapture = useCapture; + _listeners.push_front(item); +} + + +void EventDispatcher::removeEventListener(const XMLString& type, EventListener* listener, bool useCapture) +{ + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->type == type && it->pListener == listener && it->useCapture == useCapture) + { + it->pListener = 0; + } + if (!_inDispatch && !it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::dispatchEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::captureEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && it->useCapture && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +void EventDispatcher::bubbleEvent(Event* evt) +{ + DispatchGuard guard(_inDispatch); + EventListenerList::iterator it = _listeners.begin(); + while (it != _listeners.end()) + { + if (it->pListener && !it->useCapture && it->type == evt->type()) + { + it->pListener->handleEvent(evt); + } + if (!it->pListener) + { + EventListenerList::iterator del = it++; + _listeners.erase(del); + } + else ++it; + } +} + + +} } // namespace Poco::XML diff --git a/XML/src/EventException.cpp b/XML/src/EventException.cpp index 3072ef057..1e02fe88b 100644 --- a/XML/src/EventException.cpp +++ b/XML/src/EventException.cpp @@ -1,87 +1,87 @@ -// -// EventException.cpp -// -// $Id: //poco/1.3/XML/src/EventException.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/EventException.h" -#include - - -namespace Poco { -namespace XML { - - -EventException::EventException(int code): - XMLException("Unspecified event type") -{ -} - - -EventException::EventException(const EventException& exc): - XMLException(exc) -{ -} - - -EventException::~EventException() throw() -{ -} - - -EventException& EventException::operator = (const EventException& exc) -{ - XMLException::operator = (exc); - return *this; -} - - -const char* EventException::name() const throw() -{ - return "EventException"; -} - - -const char* EventException::className() const throw() -{ - return typeid(*this).name(); -} - - -Poco::Exception* EventException::clone() const -{ - return new EventException(*this); -} - - -} } // namespace Poco::XML +// +// EventException.cpp +// +// $Id: //poco/1.3/XML/src/EventException.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/EventException.h" +#include + + +namespace Poco { +namespace XML { + + +EventException::EventException(int code): + XMLException("Unspecified event type") +{ +} + + +EventException::EventException(const EventException& exc): + XMLException(exc) +{ +} + + +EventException::~EventException() throw() +{ +} + + +EventException& EventException::operator = (const EventException& exc) +{ + XMLException::operator = (exc); + return *this; +} + + +const char* EventException::name() const throw() +{ + return "EventException"; +} + + +const char* EventException::className() const throw() +{ + return typeid(*this).name(); +} + + +Poco::Exception* EventException::clone() const +{ + return new EventException(*this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/EventListener.cpp b/XML/src/EventListener.cpp index e63d3e42f..13e7deb5e 100644 --- a/XML/src/EventListener.cpp +++ b/XML/src/EventListener.cpp @@ -1,49 +1,49 @@ -// -// EventListener.cpp -// -// $Id: //poco/1.3/XML/src/EventListener.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/EventListener.h" - - -namespace Poco { -namespace XML { - - -EventListener::~EventListener() -{ -} - - -} } // namespace Poco::XML +// +// EventListener.cpp +// +// $Id: //poco/1.3/XML/src/EventListener.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/EventListener.h" + + +namespace Poco { +namespace XML { + + +EventListener::~EventListener() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/EventTarget.cpp b/XML/src/EventTarget.cpp index e62cd8aef..7011f87fe 100644 --- a/XML/src/EventTarget.cpp +++ b/XML/src/EventTarget.cpp @@ -1,49 +1,49 @@ -// -// EventTarget.cpp -// -// $Id: //poco/1.3/XML/src/EventTarget.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/EventTarget.h" - - -namespace Poco { -namespace XML { - - -EventTarget::~EventTarget() -{ -} - - -} } // namespace Poco::XML +// +// EventTarget.cpp +// +// $Id: //poco/1.3/XML/src/EventTarget.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/EventTarget.h" + + +namespace Poco { +namespace XML { + + +EventTarget::~EventTarget() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/InputSource.cpp b/XML/src/InputSource.cpp index 390350247..351187a17 100644 --- a/XML/src/InputSource.cpp +++ b/XML/src/InputSource.cpp @@ -1,102 +1,102 @@ -// -// InputSource.cpp -// -// $Id: //poco/1.3/XML/src/InputSource.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/InputSource.h" - - -namespace Poco { -namespace XML { - - -InputSource::InputSource(): - _bistr(0), - _cistr(0) -{ -} - - -InputSource::InputSource(const XMLString& systemId): - _systemId(systemId), - _bistr(0), - _cistr(0) -{ -} - - -InputSource::InputSource(XMLByteInputStream& bistr): - _bistr(&bistr), - _cistr(0) -{ -} - - -InputSource::~InputSource() -{ -} - - -void InputSource::setPublicId(const XMLString& publicId) -{ - _publicId = publicId; -} - - -void InputSource::setSystemId(const XMLString& systemId) -{ - _systemId = systemId; -} - - -void InputSource::setEncoding(const XMLString& encoding) -{ - _encoding = encoding; -} - - -void InputSource::setByteStream(XMLByteInputStream& bistr) -{ - _bistr = &bistr; -} - - -void InputSource::setCharacterStream(XMLCharInputStream& cistr) -{ - _cistr = &cistr; -} - - -} } // namespace Poco::XML - +// +// InputSource.cpp +// +// $Id: //poco/1.3/XML/src/InputSource.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/InputSource.h" + + +namespace Poco { +namespace XML { + + +InputSource::InputSource(): + _bistr(0), + _cistr(0) +{ +} + + +InputSource::InputSource(const XMLString& systemId): + _systemId(systemId), + _bistr(0), + _cistr(0) +{ +} + + +InputSource::InputSource(XMLByteInputStream& bistr): + _bistr(&bistr), + _cistr(0) +{ +} + + +InputSource::~InputSource() +{ +} + + +void InputSource::setPublicId(const XMLString& publicId) +{ + _publicId = publicId; +} + + +void InputSource::setSystemId(const XMLString& systemId) +{ + _systemId = systemId; +} + + +void InputSource::setEncoding(const XMLString& encoding) +{ + _encoding = encoding; +} + + +void InputSource::setByteStream(XMLByteInputStream& bistr) +{ + _bistr = &bistr; +} + + +void InputSource::setCharacterStream(XMLCharInputStream& cistr) +{ + _cistr = &cistr; +} + + +} } // namespace Poco::XML + diff --git a/XML/src/LexicalHandler.cpp b/XML/src/LexicalHandler.cpp index 24deffed2..7b9f63b4c 100644 --- a/XML/src/LexicalHandler.cpp +++ b/XML/src/LexicalHandler.cpp @@ -1,49 +1,49 @@ -// -// LexicalHandler.cpp -// -// $Id: //poco/1.3/XML/src/LexicalHandler.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/LexicalHandler.h" - - -namespace Poco { -namespace XML { - - -LexicalHandler::~LexicalHandler() -{ -} - - -} } // namespace Poco::XML +// +// LexicalHandler.cpp +// +// $Id: //poco/1.3/XML/src/LexicalHandler.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/LexicalHandler.h" + + +namespace Poco { +namespace XML { + + +LexicalHandler::~LexicalHandler() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/Locator.cpp b/XML/src/Locator.cpp index 0d03d0fb4..28a5af3be 100644 --- a/XML/src/Locator.cpp +++ b/XML/src/Locator.cpp @@ -1,49 +1,49 @@ -// -// Locator.cpp -// -// $Id: //poco/1.3/XML/src/Locator.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/Locator.h" - - -namespace Poco { -namespace XML { - - -Locator::~Locator() -{ -} - - -} } // namespace Poco::XML +// +// Locator.cpp +// +// $Id: //poco/1.3/XML/src/Locator.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/Locator.h" + + +namespace Poco { +namespace XML { + + +Locator::~Locator() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/LocatorImpl.cpp b/XML/src/LocatorImpl.cpp index a77764766..431dec18f 100644 --- a/XML/src/LocatorImpl.cpp +++ b/XML/src/LocatorImpl.cpp @@ -1,126 +1,126 @@ -// -// LocatorImpl.cpp -// -// $Id: //poco/1.3/XML/src/LocatorImpl.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/LocatorImpl.h" - - -namespace Poco { -namespace XML { - - -LocatorImpl::LocatorImpl() -{ - _lineNumber = 0; - _columnNumber = 0; -} - - -LocatorImpl::LocatorImpl(const Locator& loc) -{ - _publicId = loc.getPublicId(); - _systemId = loc.getSystemId(); - _lineNumber = loc.getLineNumber(); - _columnNumber = loc.getColumnNumber(); -} - - -LocatorImpl::~LocatorImpl() -{ -} - - -LocatorImpl& LocatorImpl::operator = (const Locator& loc) -{ - if (&loc != this) - { - _publicId = loc.getPublicId(); - _systemId = loc.getSystemId(); - _lineNumber = loc.getLineNumber(); - _columnNumber = loc.getColumnNumber(); - } - return *this; -} - - -XMLString LocatorImpl::getPublicId() const -{ - return _publicId; -} - - -XMLString LocatorImpl::getSystemId() const -{ - return _systemId; -} - - -int LocatorImpl::getLineNumber() const -{ - return _lineNumber; -} - - -int LocatorImpl::getColumnNumber() const -{ - return _columnNumber; -} - - -void LocatorImpl::setPublicId(const XMLString& publicId) -{ - _publicId = publicId; -} - - -void LocatorImpl::setSystemId(const XMLString& systemId) -{ - _systemId = systemId; -} - - -void LocatorImpl::setLineNumber(int lineNumber) -{ - _lineNumber = lineNumber; -} - - -void LocatorImpl::setColumnNumber(int columnNumber) -{ - _columnNumber = columnNumber; -} - - -} } // namespace Poco::XML +// +// LocatorImpl.cpp +// +// $Id: //poco/1.3/XML/src/LocatorImpl.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/LocatorImpl.h" + + +namespace Poco { +namespace XML { + + +LocatorImpl::LocatorImpl() +{ + _lineNumber = 0; + _columnNumber = 0; +} + + +LocatorImpl::LocatorImpl(const Locator& loc) +{ + _publicId = loc.getPublicId(); + _systemId = loc.getSystemId(); + _lineNumber = loc.getLineNumber(); + _columnNumber = loc.getColumnNumber(); +} + + +LocatorImpl::~LocatorImpl() +{ +} + + +LocatorImpl& LocatorImpl::operator = (const Locator& loc) +{ + if (&loc != this) + { + _publicId = loc.getPublicId(); + _systemId = loc.getSystemId(); + _lineNumber = loc.getLineNumber(); + _columnNumber = loc.getColumnNumber(); + } + return *this; +} + + +XMLString LocatorImpl::getPublicId() const +{ + return _publicId; +} + + +XMLString LocatorImpl::getSystemId() const +{ + return _systemId; +} + + +int LocatorImpl::getLineNumber() const +{ + return _lineNumber; +} + + +int LocatorImpl::getColumnNumber() const +{ + return _columnNumber; +} + + +void LocatorImpl::setPublicId(const XMLString& publicId) +{ + _publicId = publicId; +} + + +void LocatorImpl::setSystemId(const XMLString& systemId) +{ + _systemId = systemId; +} + + +void LocatorImpl::setLineNumber(int lineNumber) +{ + _lineNumber = lineNumber; +} + + +void LocatorImpl::setColumnNumber(int columnNumber) +{ + _columnNumber = columnNumber; +} + + +} } // namespace Poco::XML diff --git a/XML/src/MutationEvent.cpp b/XML/src/MutationEvent.cpp index c08b94b91..675223b54 100644 --- a/XML/src/MutationEvent.cpp +++ b/XML/src/MutationEvent.cpp @@ -1,98 +1,98 @@ -// -// MutationEvent.cpp -// -// $Id: //poco/1.3/XML/src/MutationEvent.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOMEvents -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/MutationEvent.h" - - -namespace Poco { -namespace XML { - - -const XMLString MutationEvent::DOMSubtreeModified = toXMLString("DOMSubtreeModified"); -const XMLString MutationEvent::DOMNodeInserted = toXMLString("DOMNodeInserted"); -const XMLString MutationEvent::DOMNodeRemoved = toXMLString("DOMNodeRemoved"); -const XMLString MutationEvent::DOMNodeRemovedFromDocument = toXMLString("DOMNodeRemovedFromDocument"); -const XMLString MutationEvent::DOMNodeInsertedIntoDocument = toXMLString("DOMNodeInsertedIntoDocument"); -const XMLString MutationEvent::DOMAttrModified = toXMLString("DOMAttrModified"); -const XMLString MutationEvent::DOMCharacterDataModified = toXMLString("DOMCharacterDataModified"); - - -MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type): - Event(pOwnerDocument, type, 0, true, false), - _change(MODIFICATION), - _pRelatedNode(0) -{ -} - - -MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode): - Event(pOwnerDocument, type, pTarget, canBubble, cancelable), - _change(MODIFICATION), - _pRelatedNode(relatedNode) -{ -} - - -MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode, - const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change): - Event(pOwnerDocument, type, pTarget, canBubble, cancelable), - _prevValue(prevValue), - _newValue(newValue), - _attrName(attrName), - _change(change), - _pRelatedNode(relatedNode) -{ -} - - -MutationEvent::~MutationEvent() -{ -} - - -void MutationEvent::initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode, - const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change) -{ - initEvent(type, canBubble, cancelable); - _pRelatedNode = relatedNode; - _prevValue = prevValue; - _newValue = newValue; - _attrName = attrName; - _change = change; -} - - -} } // namespace Poco::XML +// +// MutationEvent.cpp +// +// $Id: //poco/1.3/XML/src/MutationEvent.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOMEvents +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/MutationEvent.h" + + +namespace Poco { +namespace XML { + + +const XMLString MutationEvent::DOMSubtreeModified = toXMLString("DOMSubtreeModified"); +const XMLString MutationEvent::DOMNodeInserted = toXMLString("DOMNodeInserted"); +const XMLString MutationEvent::DOMNodeRemoved = toXMLString("DOMNodeRemoved"); +const XMLString MutationEvent::DOMNodeRemovedFromDocument = toXMLString("DOMNodeRemovedFromDocument"); +const XMLString MutationEvent::DOMNodeInsertedIntoDocument = toXMLString("DOMNodeInsertedIntoDocument"); +const XMLString MutationEvent::DOMAttrModified = toXMLString("DOMAttrModified"); +const XMLString MutationEvent::DOMCharacterDataModified = toXMLString("DOMCharacterDataModified"); + + +MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type): + Event(pOwnerDocument, type, 0, true, false), + _change(MODIFICATION), + _pRelatedNode(0) +{ +} + + +MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode): + Event(pOwnerDocument, type, pTarget, canBubble, cancelable), + _change(MODIFICATION), + _pRelatedNode(relatedNode) +{ +} + + +MutationEvent::MutationEvent(Document* pOwnerDocument, const XMLString& type, EventTarget* pTarget, bool canBubble, bool cancelable, Node* relatedNode, + const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change): + Event(pOwnerDocument, type, pTarget, canBubble, cancelable), + _prevValue(prevValue), + _newValue(newValue), + _attrName(attrName), + _change(change), + _pRelatedNode(relatedNode) +{ +} + + +MutationEvent::~MutationEvent() +{ +} + + +void MutationEvent::initMutationEvent(const XMLString& type, bool canBubble, bool cancelable, Node* relatedNode, + const XMLString& prevValue, const XMLString& newValue, const XMLString& attrName, AttrChangeType change) +{ + initEvent(type, canBubble, cancelable); + _pRelatedNode = relatedNode; + _prevValue = prevValue; + _newValue = newValue; + _attrName = attrName; + _change = change; +} + + +} } // namespace Poco::XML diff --git a/XML/src/Name.cpp b/XML/src/Name.cpp index 638cf24ac..2ec606651 100644 --- a/XML/src/Name.cpp +++ b/XML/src/Name.cpp @@ -1,192 +1,192 @@ -// -// Name.cpp -// -// $Id: //poco/1.3/XML/src/Name.cpp#1 $ -// -// Library: XML -// Package: XML -// Module: Name -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/XML/Name.h" -#include - - -namespace Poco { -namespace XML { - - -const XMLString Name::EMPTY_NAME; - - -Name::Name() -{ -} - - -Name::Name(const XMLString& qname): - _qname(qname) -{ -} - - -Name::Name(const XMLString& qname, const XMLString& namespaceURI): - _qname(qname), - _namespaceURI(namespaceURI), - _localName(localName(qname)) -{ -} - - -Name::Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName): - _qname(qname), - _namespaceURI(namespaceURI), - _localName(localName) -{ -} - - -Name::Name(const Name& name): - _qname(name._qname), - _namespaceURI(name._namespaceURI), - _localName(name._localName) -{ -} - - -Name::~Name() -{ -} - - -Name& Name::operator = (const Name& name) -{ - if (this != &name) - { - _qname = name._qname; - _namespaceURI = name._namespaceURI; - _localName = name._localName; - } - return *this; -} - - -void Name::swap(Name& name) -{ - std::swap(_qname, name._qname); - std::swap(_namespaceURI, name._namespaceURI); - std::swap(_localName, name._localName); -} - - -void Name::assign(const XMLString& qname) -{ - _qname = qname; - _namespaceURI.clear(); - _localName.clear(); -} - - -void Name::assign(const XMLString& qname, const XMLString& namespaceURI) -{ - _qname = qname; - _namespaceURI = namespaceURI; - _localName = localName(qname); -} - - -void Name::assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) -{ - _qname = qname; - _namespaceURI = namespaceURI; - _localName = localName; -} - - -bool Name::equals(const Name& name) const -{ - return name._namespaceURI == _namespaceURI && name._localName == _localName && name._qname == _qname; -} - - -bool Name::equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const -{ - return _namespaceURI == namespaceURI && _localName == localName && _qname == qname; -} - - -bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const -{ - return _qname == qname && !qname.empty() || _namespaceURI == namespaceURI && _localName == localName && !_localName.empty(); -} - - -XMLString Name::prefix() const -{ - return prefix(_qname); -} - - -void Name::split(const XMLString& qname, XMLString& prefix, XMLString& localName) -{ - XMLString::size_type pos = qname.find(':'); - if (pos != XMLString::npos) - { - prefix.assign(qname, 0, pos); - localName.assign(qname, pos + 1, qname.size() - pos - 1); - } - else - { - prefix.clear(); - localName.assign(qname); - } -} - - -XMLString Name::localName(const XMLString& qname) -{ - XMLString::size_type pos = qname.find(':'); - if (pos != XMLString::npos) - return XMLString(qname, pos + 1, qname.size() - pos - 1); - else - return qname; -} - - -XMLString Name::prefix(const XMLString& qname) -{ - XMLString::size_type pos = qname.find(':'); - if (pos != XMLString::npos) - return XMLString(qname, 0, pos); - else - return EMPTY_NAME; -} - - -} } // namespace Poco::XML +// +// Name.cpp +// +// $Id: //poco/1.3/XML/src/Name.cpp#1 $ +// +// Library: XML +// Package: XML +// Module: Name +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/XML/Name.h" +#include + + +namespace Poco { +namespace XML { + + +const XMLString Name::EMPTY_NAME; + + +Name::Name() +{ +} + + +Name::Name(const XMLString& qname): + _qname(qname) +{ +} + + +Name::Name(const XMLString& qname, const XMLString& namespaceURI): + _qname(qname), + _namespaceURI(namespaceURI), + _localName(localName(qname)) +{ +} + + +Name::Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName): + _qname(qname), + _namespaceURI(namespaceURI), + _localName(localName) +{ +} + + +Name::Name(const Name& name): + _qname(name._qname), + _namespaceURI(name._namespaceURI), + _localName(name._localName) +{ +} + + +Name::~Name() +{ +} + + +Name& Name::operator = (const Name& name) +{ + if (this != &name) + { + _qname = name._qname; + _namespaceURI = name._namespaceURI; + _localName = name._localName; + } + return *this; +} + + +void Name::swap(Name& name) +{ + std::swap(_qname, name._qname); + std::swap(_namespaceURI, name._namespaceURI); + std::swap(_localName, name._localName); +} + + +void Name::assign(const XMLString& qname) +{ + _qname = qname; + _namespaceURI.clear(); + _localName.clear(); +} + + +void Name::assign(const XMLString& qname, const XMLString& namespaceURI) +{ + _qname = qname; + _namespaceURI = namespaceURI; + _localName = localName(qname); +} + + +void Name::assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) +{ + _qname = qname; + _namespaceURI = namespaceURI; + _localName = localName; +} + + +bool Name::equals(const Name& name) const +{ + return name._namespaceURI == _namespaceURI && name._localName == _localName && name._qname == _qname; +} + + +bool Name::equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const +{ + return _namespaceURI == namespaceURI && _localName == localName && _qname == qname; +} + + +bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const +{ + return _qname == qname && !qname.empty() || _namespaceURI == namespaceURI && _localName == localName && !_localName.empty(); +} + + +XMLString Name::prefix() const +{ + return prefix(_qname); +} + + +void Name::split(const XMLString& qname, XMLString& prefix, XMLString& localName) +{ + XMLString::size_type pos = qname.find(':'); + if (pos != XMLString::npos) + { + prefix.assign(qname, 0, pos); + localName.assign(qname, pos + 1, qname.size() - pos - 1); + } + else + { + prefix.clear(); + localName.assign(qname); + } +} + + +XMLString Name::localName(const XMLString& qname) +{ + XMLString::size_type pos = qname.find(':'); + if (pos != XMLString::npos) + return XMLString(qname, pos + 1, qname.size() - pos - 1); + else + return qname; +} + + +XMLString Name::prefix(const XMLString& qname) +{ + XMLString::size_type pos = qname.find(':'); + if (pos != XMLString::npos) + return XMLString(qname, 0, pos); + else + return EMPTY_NAME; +} + + +} } // namespace Poco::XML diff --git a/XML/src/NamePool.cpp b/XML/src/NamePool.cpp index 90288a89f..cb78fb593 100644 --- a/XML/src/NamePool.cpp +++ b/XML/src/NamePool.cpp @@ -1,148 +1,148 @@ -// -// NamePool.cpp -// -// $Id: //poco/1.3/XML/src/NamePool.cpp#1 $ -// -// Library: XML -// Package: XML -// Module: NamePool -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/XML/NamePool.h" -#include "Poco/Exception.h" - - -namespace Poco { -namespace XML { - - -class NamePoolItem -{ -public: - NamePoolItem(): _used(false) - { - } - - ~NamePoolItem() - { - } - - bool set(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) - { - if (!_used) - { - _name.assign(qname, namespaceURI, localName); - _used = true; - return true; - } - else return _name.equals(qname, namespaceURI, localName); - } - - const Name& get() const - { - return _name; - } - - bool used() const - { - return _used; - } - -private: - Name _name; - bool _used; -}; - - -NamePool::NamePool(unsigned long size): - _size(size), - _rc(1) -{ - poco_assert (size > 1); - - _pItems = new NamePoolItem[size]; -} - - -NamePool::~NamePool() -{ - delete [] _pItems; -} - - -void NamePool::duplicate() -{ - ++_rc; -} - - -void NamePool::release() -{ - if (--_rc == 0) - delete this; -} - - -const Name& NamePool::insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) -{ - unsigned long i = 0; - unsigned long n = hash(qname, namespaceURI, localName) % _size; - - while (!_pItems[n].set(qname, namespaceURI, localName) && i++ < _size) - n = (n + 1) % _size; - - if (i > _size) throw Poco::PoolOverflowException("XML name pool"); - - return _pItems[n].get(); -} - - -const Name& NamePool::insert(const Name& name) -{ - return insert(name.qname(), name.namespaceURI(), name.localName()); -} - - -unsigned long NamePool::hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) -{ - unsigned long h = 0; - XMLString::const_iterator it = qname.begin(); - XMLString::const_iterator end = qname.end(); - while (it != end) h = (h << 5) + h + (unsigned long) *it++; - it = namespaceURI.begin(); - end = namespaceURI.end(); - while (it != end) h = (h << 5) + h + (unsigned long) *it++; - it = localName.begin(); - end = localName.end(); - while (it != end) h = (h << 5) + h + (unsigned long) *it++; - return h; -} - - -} } // namespace Poco::XML +// +// NamePool.cpp +// +// $Id: //poco/1.3/XML/src/NamePool.cpp#1 $ +// +// Library: XML +// Package: XML +// Module: NamePool +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/XML/NamePool.h" +#include "Poco/Exception.h" + + +namespace Poco { +namespace XML { + + +class NamePoolItem +{ +public: + NamePoolItem(): _used(false) + { + } + + ~NamePoolItem() + { + } + + bool set(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) + { + if (!_used) + { + _name.assign(qname, namespaceURI, localName); + _used = true; + return true; + } + else return _name.equals(qname, namespaceURI, localName); + } + + const Name& get() const + { + return _name; + } + + bool used() const + { + return _used; + } + +private: + Name _name; + bool _used; +}; + + +NamePool::NamePool(unsigned long size): + _size(size), + _rc(1) +{ + poco_assert (size > 1); + + _pItems = new NamePoolItem[size]; +} + + +NamePool::~NamePool() +{ + delete [] _pItems; +} + + +void NamePool::duplicate() +{ + ++_rc; +} + + +void NamePool::release() +{ + if (--_rc == 0) + delete this; +} + + +const Name& NamePool::insert(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) +{ + unsigned long i = 0; + unsigned long n = hash(qname, namespaceURI, localName) % _size; + + while (!_pItems[n].set(qname, namespaceURI, localName) && i++ < _size) + n = (n + 1) % _size; + + if (i > _size) throw Poco::PoolOverflowException("XML name pool"); + + return _pItems[n].get(); +} + + +const Name& NamePool::insert(const Name& name) +{ + return insert(name.qname(), name.namespaceURI(), name.localName()); +} + + +unsigned long NamePool::hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) +{ + unsigned long h = 0; + XMLString::const_iterator it = qname.begin(); + XMLString::const_iterator end = qname.end(); + while (it != end) h = (h << 5) + h + (unsigned long) *it++; + it = namespaceURI.begin(); + end = namespaceURI.end(); + while (it != end) h = (h << 5) + h + (unsigned long) *it++; + it = localName.begin(); + end = localName.end(); + while (it != end) h = (h << 5) + h + (unsigned long) *it++; + return h; +} + + +} } // namespace Poco::XML diff --git a/XML/src/NamedNodeMap.cpp b/XML/src/NamedNodeMap.cpp index 362c2aee3..a16b1700e 100644 --- a/XML/src/NamedNodeMap.cpp +++ b/XML/src/NamedNodeMap.cpp @@ -1,49 +1,49 @@ -// -// NamedNodeMap.cpp -// -// $Id: //poco/1.3/XML/src/NamedNodeMap.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/NamedNodeMap.h" - - -namespace Poco { -namespace XML { - - -NamedNodeMap::~NamedNodeMap() -{ -} - - -} } // namespace Poco::XML +// +// NamedNodeMap.cpp +// +// $Id: //poco/1.3/XML/src/NamedNodeMap.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/NamedNodeMap.h" + + +namespace Poco { +namespace XML { + + +NamedNodeMap::~NamedNodeMap() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/NamespaceSupport.cpp b/XML/src/NamespaceSupport.cpp index c26b41ed9..b62a64d2f 100644 --- a/XML/src/NamespaceSupport.cpp +++ b/XML/src/NamespaceSupport.cpp @@ -1,209 +1,209 @@ -// -// NamespaceSupport.cpp -// -// $Id: //poco/1.3/XML/src/NamespaceSupport.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/NamespaceSupport.h" -#include "Poco/XML/Name.h" - - -namespace Poco { -namespace XML { - - -const XMLString NamespaceSupport::EMPTY_STRING; -const XMLString NamespaceSupport::XML_NAMESPACE = toXMLString("http://www.w3.org/XML/1998/namespace"); -const XMLString NamespaceSupport::XML_NAMESPACE_PREFIX = toXMLString("xml"); -const XMLString NamespaceSupport::XMLNS_NAMESPACE = toXMLString("http://www.w3.org/xmlns/2000/"); -const XMLString NamespaceSupport::XMLNS_NAMESPACE_PREFIX = toXMLString("xmlns"); - - -NamespaceSupport::NamespaceSupport() -{ - reset(); -} - - -NamespaceSupport::~NamespaceSupport() -{ -} - - -bool NamespaceSupport::declarePrefix(const XMLString& prefix, const XMLString& namespaceURI) -{ - poco_assert (_contexts.size() > 0); - - Context& ctx = _contexts.back(); - if (ctx.find(prefix) == ctx.end()) - { - ctx.insert(Context::value_type(prefix, namespaceURI)); - return true; - } - else return false; -} - - -bool NamespaceSupport::undeclarePrefix(const XMLString& prefix) -{ - for (ContextVec::reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - Context::iterator it = rit->find(prefix); - if (it != rit->end()) - { - rit->erase(it); - return true; - } - } - return false; -} - - -void NamespaceSupport::getDeclaredPrefixes(PrefixSet& prefixes) const -{ - prefixes.clear(); - const Context& ctx = _contexts.back(); - for (Context::const_iterator it = ctx.begin(); it != ctx.end(); ++it) - prefixes.insert(it->first); -} - - -const XMLString& NamespaceSupport::getPrefix(const XMLString& namespaceURI) const -{ - for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) - { - if (it->second == namespaceURI) - return it->first; - } - } - return EMPTY_STRING; -} - - -bool NamespaceSupport::isMapped(const XMLString& namespaceURI) const -{ - for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) - { - if (it->second == namespaceURI) - return true; - } - } - return false; -} - - -void NamespaceSupport::getPrefixes(PrefixSet& prefixes) const -{ - prefixes.clear(); - for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) - { - const XMLString& prefix = it->first; - if (!prefix.empty() && prefixes.find(prefix) == prefixes.end()) - prefixes.insert(it->first); - } - } -} - - -void NamespaceSupport::getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const -{ - prefixes.clear(); - for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) - { - const XMLString& prefix = it->first; - if (it->second == namespaceURI && !prefix.empty() && prefixes.find(prefix) == prefixes.end()) - prefixes.insert(it->first); - } - } -} - - -const XMLString& NamespaceSupport::getURI(const XMLString& prefix) const -{ - for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) - { - Context::const_iterator it = rit->find(prefix); - if (it != rit->end()) - return it->second; - } - return EMPTY_STRING; -} - - -void NamespaceSupport::pushContext() -{ - _contexts.push_back(Context()); -} - - -void NamespaceSupport::popContext() -{ - _contexts.pop_back(); -} - - -bool NamespaceSupport::processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const -{ - XMLString prefix; - Name::split(qname, prefix, localName); - if (prefix.empty() && isAttribute) - { - namespaceURI.clear(); - return true; - } - else - { - namespaceURI = getURI(prefix); - return !namespaceURI.empty() || prefix.empty(); - } -} - - -void NamespaceSupport::reset() -{ - _contexts.clear(); - pushContext(); - declarePrefix(XML_NAMESPACE_PREFIX, XML_NAMESPACE); - declarePrefix(XMLNS_NAMESPACE_PREFIX, XMLNS_NAMESPACE); -} - - -} } // namespace Poco::XML +// +// NamespaceSupport.cpp +// +// $Id: //poco/1.3/XML/src/NamespaceSupport.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/NamespaceSupport.h" +#include "Poco/XML/Name.h" + + +namespace Poco { +namespace XML { + + +const XMLString NamespaceSupport::EMPTY_STRING; +const XMLString NamespaceSupport::XML_NAMESPACE = toXMLString("http://www.w3.org/XML/1998/namespace"); +const XMLString NamespaceSupport::XML_NAMESPACE_PREFIX = toXMLString("xml"); +const XMLString NamespaceSupport::XMLNS_NAMESPACE = toXMLString("http://www.w3.org/xmlns/2000/"); +const XMLString NamespaceSupport::XMLNS_NAMESPACE_PREFIX = toXMLString("xmlns"); + + +NamespaceSupport::NamespaceSupport() +{ + reset(); +} + + +NamespaceSupport::~NamespaceSupport() +{ +} + + +bool NamespaceSupport::declarePrefix(const XMLString& prefix, const XMLString& namespaceURI) +{ + poco_assert (_contexts.size() > 0); + + Context& ctx = _contexts.back(); + if (ctx.find(prefix) == ctx.end()) + { + ctx.insert(Context::value_type(prefix, namespaceURI)); + return true; + } + else return false; +} + + +bool NamespaceSupport::undeclarePrefix(const XMLString& prefix) +{ + for (ContextVec::reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + Context::iterator it = rit->find(prefix); + if (it != rit->end()) + { + rit->erase(it); + return true; + } + } + return false; +} + + +void NamespaceSupport::getDeclaredPrefixes(PrefixSet& prefixes) const +{ + prefixes.clear(); + const Context& ctx = _contexts.back(); + for (Context::const_iterator it = ctx.begin(); it != ctx.end(); ++it) + prefixes.insert(it->first); +} + + +const XMLString& NamespaceSupport::getPrefix(const XMLString& namespaceURI) const +{ + for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) + { + if (it->second == namespaceURI) + return it->first; + } + } + return EMPTY_STRING; +} + + +bool NamespaceSupport::isMapped(const XMLString& namespaceURI) const +{ + for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) + { + if (it->second == namespaceURI) + return true; + } + } + return false; +} + + +void NamespaceSupport::getPrefixes(PrefixSet& prefixes) const +{ + prefixes.clear(); + for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) + { + const XMLString& prefix = it->first; + if (!prefix.empty() && prefixes.find(prefix) == prefixes.end()) + prefixes.insert(it->first); + } + } +} + + +void NamespaceSupport::getPrefixes(const XMLString& namespaceURI, PrefixSet& prefixes) const +{ + prefixes.clear(); + for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + for (Context::const_iterator it = rit->begin(); it != rit->end(); ++it) + { + const XMLString& prefix = it->first; + if (it->second == namespaceURI && !prefix.empty() && prefixes.find(prefix) == prefixes.end()) + prefixes.insert(it->first); + } + } +} + + +const XMLString& NamespaceSupport::getURI(const XMLString& prefix) const +{ + for (ContextVec::const_reverse_iterator rit = _contexts.rbegin(); rit != _contexts.rend(); ++rit) + { + Context::const_iterator it = rit->find(prefix); + if (it != rit->end()) + return it->second; + } + return EMPTY_STRING; +} + + +void NamespaceSupport::pushContext() +{ + _contexts.push_back(Context()); +} + + +void NamespaceSupport::popContext() +{ + _contexts.pop_back(); +} + + +bool NamespaceSupport::processName(const XMLString& qname, XMLString& namespaceURI, XMLString& localName, bool isAttribute) const +{ + XMLString prefix; + Name::split(qname, prefix, localName); + if (prefix.empty() && isAttribute) + { + namespaceURI.clear(); + return true; + } + else + { + namespaceURI = getURI(prefix); + return !namespaceURI.empty() || prefix.empty(); + } +} + + +void NamespaceSupport::reset() +{ + _contexts.clear(); + pushContext(); + declarePrefix(XML_NAMESPACE_PREFIX, XML_NAMESPACE); + declarePrefix(XMLNS_NAMESPACE_PREFIX, XMLNS_NAMESPACE); +} + + +} } // namespace Poco::XML diff --git a/XML/src/Node.cpp b/XML/src/Node.cpp index 79125724a..d1f134551 100644 --- a/XML/src/Node.cpp +++ b/XML/src/Node.cpp @@ -1,49 +1,49 @@ -// -// Node.cpp -// -// $Id: //poco/1.3/XML/src/Node.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Node.h" - - -namespace Poco { -namespace XML { - - -Node::~Node() -{ -} - - -} } // namespace Poco::XML +// +// Node.cpp +// +// $Id: //poco/1.3/XML/src/Node.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Node.h" + + +namespace Poco { +namespace XML { + + +Node::~Node() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/NodeAppender.cpp b/XML/src/NodeAppender.cpp index 89c39a2cd..8a4daf1a2 100644 --- a/XML/src/NodeAppender.cpp +++ b/XML/src/NodeAppender.cpp @@ -1,104 +1,104 @@ -// -// NodeAppender.cpp -// -// $Id: //poco/1.3/XML/src/NodeAppender.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeAppender -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/NodeAppender.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -NodeAppender::NodeAppender(Element* parent): - _pParent(parent), - _pLast(0) -{ - poco_check_ptr (parent); - - _pLast = static_cast(_pParent->lastChild()); -} - - -NodeAppender::~NodeAppender() -{ -} - - -void NodeAppender::appendChild(Node* newChild) -{ - poco_check_ptr (newChild); - poco_assert (_pLast == 0 || _pLast->_pNext == 0); - - if (static_cast(newChild)->_pOwner != _pParent->_pOwner) - throw DOMException(DOMException::WRONG_DOCUMENT_ERR); - - if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) - { - AbstractContainerNode* pFrag = static_cast(newChild); - AbstractNode* pChild = pFrag->_pFirstChild; - if (pChild) - { - if (_pLast) - _pLast->_pNext = pChild; - else - _pParent->_pFirstChild = pChild; - while (pChild) - { - _pLast = pChild; - pChild->_pParent = _pParent; - pChild = pChild->_pNext; - } - pFrag->_pFirstChild = 0; - } - } - else - { - AbstractNode* pAN = static_cast(newChild); - pAN->duplicate(); - if (pAN->_pParent) - pAN->_pParent->removeChild(pAN); - pAN->_pParent = _pParent; - if (_pLast) - _pLast->_pNext = pAN; - else - _pParent->_pFirstChild = pAN; - _pLast = pAN; - } -} - - -} } // namespace Poco::XML +// +// NodeAppender.cpp +// +// $Id: //poco/1.3/XML/src/NodeAppender.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeAppender +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/NodeAppender.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +NodeAppender::NodeAppender(Element* parent): + _pParent(parent), + _pLast(0) +{ + poco_check_ptr (parent); + + _pLast = static_cast(_pParent->lastChild()); +} + + +NodeAppender::~NodeAppender() +{ +} + + +void NodeAppender::appendChild(Node* newChild) +{ + poco_check_ptr (newChild); + poco_assert (_pLast == 0 || _pLast->_pNext == 0); + + if (static_cast(newChild)->_pOwner != _pParent->_pOwner) + throw DOMException(DOMException::WRONG_DOCUMENT_ERR); + + if (newChild->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) + { + AbstractContainerNode* pFrag = static_cast(newChild); + AbstractNode* pChild = pFrag->_pFirstChild; + if (pChild) + { + if (_pLast) + _pLast->_pNext = pChild; + else + _pParent->_pFirstChild = pChild; + while (pChild) + { + _pLast = pChild; + pChild->_pParent = _pParent; + pChild = pChild->_pNext; + } + pFrag->_pFirstChild = 0; + } + } + else + { + AbstractNode* pAN = static_cast(newChild); + pAN->duplicate(); + if (pAN->_pParent) + pAN->_pParent->removeChild(pAN); + pAN->_pParent = _pParent; + if (_pLast) + _pLast->_pNext = pAN; + else + _pParent->_pFirstChild = pAN; + _pLast = pAN; + } +} + + +} } // namespace Poco::XML diff --git a/XML/src/NodeFilter.cpp b/XML/src/NodeFilter.cpp index 14dc5d287..0ea210849 100644 --- a/XML/src/NodeFilter.cpp +++ b/XML/src/NodeFilter.cpp @@ -1,49 +1,49 @@ -// -// NodeFilter.cpp -// -// $Id: //poco/1.3/XML/src/NodeFilter.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeFilter -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/NodeFilter.h" - - -namespace Poco { -namespace XML { - - -NodeFilter::~NodeFilter() -{ -} - - -} } // namespace Poco::XML +// +// NodeFilter.cpp +// +// $Id: //poco/1.3/XML/src/NodeFilter.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeFilter +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/NodeFilter.h" + + +namespace Poco { +namespace XML { + + +NodeFilter::~NodeFilter() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/NodeIterator.cpp b/XML/src/NodeIterator.cpp index 0f3ccb2f4..0e1ae0751 100644 --- a/XML/src/NodeIterator.cpp +++ b/XML/src/NodeIterator.cpp @@ -1,198 +1,198 @@ -// -// NodeIterator.cpp -// -// $Id: //poco/1.3/XML/src/NodeIterator.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: NodeIterator -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/NodeIterator.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/DOM/NodeFilter.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -NodeIterator::NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter): - _pRoot(root), - _whatToShow(whatToShow), - _pFilter(pFilter), - _pCurrent(0) -{ -} - - -NodeIterator::NodeIterator(const NodeIterator& iterator): - _pRoot(iterator._pRoot), - _whatToShow(iterator._whatToShow), - _pFilter(iterator._pFilter), - _pCurrent(iterator._pCurrent) -{ -} - - -NodeIterator& NodeIterator::operator = (const NodeIterator& iterator) -{ - if (&iterator != this) - { - _pRoot = iterator._pRoot; - _whatToShow = iterator._whatToShow; - _pFilter = iterator._pFilter; - _pCurrent = iterator._pCurrent; - } - return *this; -} - - -NodeIterator::~NodeIterator() -{ -} - - -Node* NodeIterator::nextNode() -{ - if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); - - if (_pCurrent) - _pCurrent = next(); - else - _pCurrent = _pRoot; - while (_pCurrent && !accept(_pCurrent)) - _pCurrent = next(); - return _pCurrent; -} - - -Node* NodeIterator::previousNode() -{ - if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); - - if (_pCurrent) - _pCurrent = previous(); - else - _pCurrent = last(); - while (_pCurrent && !accept(_pCurrent)) - _pCurrent = previous(); - return _pCurrent; -} - - -void NodeIterator::detach() -{ - _pRoot = 0; - _pCurrent = 0; -} - - -bool NodeIterator::accept(Node* pNode) const -{ - bool accept = false; - switch (pNode->nodeType()) - { - case Node::ELEMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; - case Node::ATTRIBUTE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; - case Node::TEXT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; - case Node::CDATA_SECTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; - case Node::ENTITY_REFERENCE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; - case Node::ENTITY_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; - case Node::PROCESSING_INSTRUCTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; - case Node::COMMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; - case Node::DOCUMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; - case Node::DOCUMENT_TYPE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; - case Node::DOCUMENT_FRAGMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; - case Node::NOTATION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; - } - if (accept && _pFilter) - accept = _pFilter->acceptNode(pNode) == NodeFilter::FILTER_ACCEPT; - return accept; -} - - -Node* NodeIterator::next() const -{ - Node* pNext = _pCurrent->firstChild(); - if (pNext) return pNext; - pNext = _pCurrent; - while (pNext && pNext != _pRoot) - { - Node* pSibling = pNext->nextSibling(); - if (pSibling) return pSibling; - pNext = pNext->parentNode(); - } - return 0; -} - - -Node* NodeIterator::previous() const -{ - if (_pCurrent == _pRoot) return 0; - Node* pPrev = _pCurrent->previousSibling(); - while (pPrev) - { - Node* pLastChild = pPrev->lastChild(); - if (pLastChild) - pPrev = pLastChild; - else - return pPrev; - } - return _pCurrent->parentNode(); -} - - -Node* NodeIterator::last() -{ - _pCurrent = _pRoot; - Node* pLast = 0; - while (_pCurrent) - { - pLast = _pCurrent; - _pCurrent = next(); - } - return pLast; -} - - -} } // namespace Poco::XML +// +// NodeIterator.cpp +// +// $Id: //poco/1.3/XML/src/NodeIterator.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: NodeIterator +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/NodeIterator.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/DOM/NodeFilter.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +NodeIterator::NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter): + _pRoot(root), + _whatToShow(whatToShow), + _pFilter(pFilter), + _pCurrent(0) +{ +} + + +NodeIterator::NodeIterator(const NodeIterator& iterator): + _pRoot(iterator._pRoot), + _whatToShow(iterator._whatToShow), + _pFilter(iterator._pFilter), + _pCurrent(iterator._pCurrent) +{ +} + + +NodeIterator& NodeIterator::operator = (const NodeIterator& iterator) +{ + if (&iterator != this) + { + _pRoot = iterator._pRoot; + _whatToShow = iterator._whatToShow; + _pFilter = iterator._pFilter; + _pCurrent = iterator._pCurrent; + } + return *this; +} + + +NodeIterator::~NodeIterator() +{ +} + + +Node* NodeIterator::nextNode() +{ + if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); + + if (_pCurrent) + _pCurrent = next(); + else + _pCurrent = _pRoot; + while (_pCurrent && !accept(_pCurrent)) + _pCurrent = next(); + return _pCurrent; +} + + +Node* NodeIterator::previousNode() +{ + if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); + + if (_pCurrent) + _pCurrent = previous(); + else + _pCurrent = last(); + while (_pCurrent && !accept(_pCurrent)) + _pCurrent = previous(); + return _pCurrent; +} + + +void NodeIterator::detach() +{ + _pRoot = 0; + _pCurrent = 0; +} + + +bool NodeIterator::accept(Node* pNode) const +{ + bool accept = false; + switch (pNode->nodeType()) + { + case Node::ELEMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; + case Node::ATTRIBUTE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; + case Node::TEXT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; + case Node::CDATA_SECTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; + case Node::ENTITY_REFERENCE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; + case Node::ENTITY_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; + case Node::PROCESSING_INSTRUCTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; + case Node::COMMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; + case Node::DOCUMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; + case Node::DOCUMENT_TYPE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; + case Node::DOCUMENT_FRAGMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; + case Node::NOTATION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; + } + if (accept && _pFilter) + accept = _pFilter->acceptNode(pNode) == NodeFilter::FILTER_ACCEPT; + return accept; +} + + +Node* NodeIterator::next() const +{ + Node* pNext = _pCurrent->firstChild(); + if (pNext) return pNext; + pNext = _pCurrent; + while (pNext && pNext != _pRoot) + { + Node* pSibling = pNext->nextSibling(); + if (pSibling) return pSibling; + pNext = pNext->parentNode(); + } + return 0; +} + + +Node* NodeIterator::previous() const +{ + if (_pCurrent == _pRoot) return 0; + Node* pPrev = _pCurrent->previousSibling(); + while (pPrev) + { + Node* pLastChild = pPrev->lastChild(); + if (pLastChild) + pPrev = pLastChild; + else + return pPrev; + } + return _pCurrent->parentNode(); +} + + +Node* NodeIterator::last() +{ + _pCurrent = _pRoot; + Node* pLast = 0; + while (_pCurrent) + { + pLast = _pCurrent; + _pCurrent = next(); + } + return pLast; +} + + +} } // namespace Poco::XML diff --git a/XML/src/NodeList.cpp b/XML/src/NodeList.cpp index a55cc5187..d4ef071fb 100644 --- a/XML/src/NodeList.cpp +++ b/XML/src/NodeList.cpp @@ -1,49 +1,49 @@ -// -// NodeList.cpp -// -// $Id: //poco/1.3/XML/src/NodeList.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/NodeList.h" - - -namespace Poco { -namespace XML { - - -NodeList::~NodeList() -{ -} - - -} } // namespace Poco::XML +// +// NodeList.cpp +// +// $Id: //poco/1.3/XML/src/NodeList.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/NodeList.h" + + +namespace Poco { +namespace XML { + + +NodeList::~NodeList() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/Notation.cpp b/XML/src/Notation.cpp index 453270964..4b08a0558 100644 --- a/XML/src/Notation.cpp +++ b/XML/src/Notation.cpp @@ -1,85 +1,85 @@ -// -// Notation.cpp -// -// $Id: //poco/1.3/XML/src/Notation.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Notation.h" - - -namespace Poco { -namespace XML { - - -Notation::Notation(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId): - AbstractNode(pOwnerDocument), - _name(name), - _publicId(publicId), - _systemId(systemId) -{ -} - - -Notation::Notation(Document* pOwnerDocument, const Notation& notation): - AbstractNode(pOwnerDocument, notation), - _name(notation._name), - _publicId(notation._publicId), - _systemId(notation._systemId) -{ -} - - -Notation::~Notation() -{ -} - - -const XMLString& Notation::nodeName() const -{ - return _name; -} - - -unsigned short Notation::nodeType() const -{ - return Node::NOTATION_NODE; -} - - -Node* Notation::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new Notation(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// Notation.cpp +// +// $Id: //poco/1.3/XML/src/Notation.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Notation.h" + + +namespace Poco { +namespace XML { + + +Notation::Notation(Document* pOwnerDocument, const XMLString& name, const XMLString& publicId, const XMLString& systemId): + AbstractNode(pOwnerDocument), + _name(name), + _publicId(publicId), + _systemId(systemId) +{ +} + + +Notation::Notation(Document* pOwnerDocument, const Notation& notation): + AbstractNode(pOwnerDocument, notation), + _name(notation._name), + _publicId(notation._publicId), + _systemId(notation._systemId) +{ +} + + +Notation::~Notation() +{ +} + + +const XMLString& Notation::nodeName() const +{ + return _name; +} + + +unsigned short Notation::nodeType() const +{ + return Node::NOTATION_NODE; +} + + +Node* Notation::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new Notation(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/ProcessingInstruction.cpp b/XML/src/ProcessingInstruction.cpp index d14952f12..0c45e43fb 100644 --- a/XML/src/ProcessingInstruction.cpp +++ b/XML/src/ProcessingInstruction.cpp @@ -1,101 +1,101 @@ -// -// ProcessingInstruction.cpp -// -// $Id: //poco/1.3/XML/src/ProcessingInstruction.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/ProcessingInstruction.h" - - -namespace Poco { -namespace XML { - - -ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const XMLString& target, const XMLString& data): - AbstractNode(pOwnerDocument), - _target(target), - _data(data) -{ -} - - -ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const ProcessingInstruction& processingInstruction): - AbstractNode(pOwnerDocument, processingInstruction), - _target(processingInstruction._target), - _data(processingInstruction._data) -{ -} - - -ProcessingInstruction::~ProcessingInstruction() -{ -} - - -void ProcessingInstruction::setData(const XMLString& data) -{ - _data = data; -} - - -const XMLString& ProcessingInstruction::nodeName() const -{ - return _target; -} - - -const XMLString& ProcessingInstruction::getNodeValue() const -{ - return _data; -} - - -void ProcessingInstruction::setNodeValue(const XMLString& data) -{ - setData(data); -} - - -unsigned short ProcessingInstruction::nodeType() const -{ - return Node::PROCESSING_INSTRUCTION_NODE; -} - - -Node* ProcessingInstruction::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new ProcessingInstruction(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// ProcessingInstruction.cpp +// +// $Id: //poco/1.3/XML/src/ProcessingInstruction.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/ProcessingInstruction.h" + + +namespace Poco { +namespace XML { + + +ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const XMLString& target, const XMLString& data): + AbstractNode(pOwnerDocument), + _target(target), + _data(data) +{ +} + + +ProcessingInstruction::ProcessingInstruction(Document* pOwnerDocument, const ProcessingInstruction& processingInstruction): + AbstractNode(pOwnerDocument, processingInstruction), + _target(processingInstruction._target), + _data(processingInstruction._data) +{ +} + + +ProcessingInstruction::~ProcessingInstruction() +{ +} + + +void ProcessingInstruction::setData(const XMLString& data) +{ + _data = data; +} + + +const XMLString& ProcessingInstruction::nodeName() const +{ + return _target; +} + + +const XMLString& ProcessingInstruction::getNodeValue() const +{ + return _data; +} + + +void ProcessingInstruction::setNodeValue(const XMLString& data) +{ + setData(data); +} + + +unsigned short ProcessingInstruction::nodeType() const +{ + return Node::PROCESSING_INSTRUCTION_NODE; +} + + +Node* ProcessingInstruction::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new ProcessingInstruction(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/SAXException.cpp b/XML/src/SAXException.cpp index f4797b80c..9a9821c9c 100644 --- a/XML/src/SAXException.cpp +++ b/XML/src/SAXException.cpp @@ -1,160 +1,160 @@ -// -// SAXException.cpp -// -// $Id: //poco/1.3/XML/src/SAXException.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/SAXException.h" -#include "Poco/SAX/Locator.h" -#include -#include - - -namespace Poco { -namespace XML { - - -POCO_IMPLEMENT_EXCEPTION(SAXException, XMLException, "SAX Exception") -POCO_IMPLEMENT_EXCEPTION(SAXNotRecognizedException, SAXException, "Unrecognized SAX feature or property identifier") -POCO_IMPLEMENT_EXCEPTION(SAXNotSupportedException, SAXException, "Unsupported SAX feature or property identifier") - - -SAXParseException::SAXParseException(const std::string& msg, const Locator& loc): - SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber())), - _publicId(loc.getPublicId()), - _systemId(loc.getSystemId()), - _lineNumber(loc.getLineNumber()), - _columnNumber(loc.getColumnNumber()) -{ -} - - -SAXParseException::SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc): - SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()), exc), - _publicId(loc.getPublicId()), - _systemId(loc.getSystemId()), - _lineNumber(loc.getLineNumber()), - _columnNumber(loc.getColumnNumber()) -{ -} - - -SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber): - SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber)), - _publicId(publicId), - _systemId(systemId), - _lineNumber(lineNumber), - _columnNumber(columnNumber) -{ -} - - -SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc): - SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber), exc), - _publicId(publicId), - _systemId(systemId), - _lineNumber(lineNumber), - _columnNumber(columnNumber) -{ -} - - -SAXParseException::SAXParseException(const SAXParseException& exc): - SAXException(exc), - _publicId(exc._publicId), - _systemId(exc._systemId), - _lineNumber(exc._lineNumber), - _columnNumber(exc._columnNumber) -{ -} - - -SAXParseException::~SAXParseException() throw() -{ -} - - -SAXParseException& SAXParseException::operator = (const SAXParseException& exc) -{ - if (&exc != this) - { - SAXException::operator = (exc); - _publicId = exc._publicId; - _systemId = exc._systemId; - _lineNumber = exc._lineNumber; - _columnNumber = exc._columnNumber; - } - return *this; -} - - -const char* SAXParseException::name() const throw() -{ - return "SAXParseException"; -} - - -const char* SAXParseException::className() const throw() -{ - return typeid(*this).name(); -} - - -Poco::Exception* SAXParseException::clone() const -{ - return new SAXParseException(*this); -} - - -void SAXParseException::rethrow() const -{ - throw *this; -} - - -std::string SAXParseException::buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber) -{ - std::ostringstream result; - if (!msg.empty()) result << msg << " "; - result << "in "; - if (!systemId.empty()) - result << "'" << fromXMLString(systemId) << "', "; - else if (!publicId.empty()) - result << "'" << fromXMLString(publicId) << "', "; - if (lineNumber > 0) - result << "line " << lineNumber << " column " << columnNumber; - return result.str(); -} - - -} } // namespace Poco::XML +// +// SAXException.cpp +// +// $Id: //poco/1.3/XML/src/SAXException.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/SAXException.h" +#include "Poco/SAX/Locator.h" +#include +#include + + +namespace Poco { +namespace XML { + + +POCO_IMPLEMENT_EXCEPTION(SAXException, XMLException, "SAX Exception") +POCO_IMPLEMENT_EXCEPTION(SAXNotRecognizedException, SAXException, "Unrecognized SAX feature or property identifier") +POCO_IMPLEMENT_EXCEPTION(SAXNotSupportedException, SAXException, "Unsupported SAX feature or property identifier") + + +SAXParseException::SAXParseException(const std::string& msg, const Locator& loc): + SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber())), + _publicId(loc.getPublicId()), + _systemId(loc.getSystemId()), + _lineNumber(loc.getLineNumber()), + _columnNumber(loc.getColumnNumber()) +{ +} + + +SAXParseException::SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc): + SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()), exc), + _publicId(loc.getPublicId()), + _systemId(loc.getSystemId()), + _lineNumber(loc.getLineNumber()), + _columnNumber(loc.getColumnNumber()) +{ +} + + +SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber): + SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber)), + _publicId(publicId), + _systemId(systemId), + _lineNumber(lineNumber), + _columnNumber(columnNumber) +{ +} + + +SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc): + SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber), exc), + _publicId(publicId), + _systemId(systemId), + _lineNumber(lineNumber), + _columnNumber(columnNumber) +{ +} + + +SAXParseException::SAXParseException(const SAXParseException& exc): + SAXException(exc), + _publicId(exc._publicId), + _systemId(exc._systemId), + _lineNumber(exc._lineNumber), + _columnNumber(exc._columnNumber) +{ +} + + +SAXParseException::~SAXParseException() throw() +{ +} + + +SAXParseException& SAXParseException::operator = (const SAXParseException& exc) +{ + if (&exc != this) + { + SAXException::operator = (exc); + _publicId = exc._publicId; + _systemId = exc._systemId; + _lineNumber = exc._lineNumber; + _columnNumber = exc._columnNumber; + } + return *this; +} + + +const char* SAXParseException::name() const throw() +{ + return "SAXParseException"; +} + + +const char* SAXParseException::className() const throw() +{ + return typeid(*this).name(); +} + + +Poco::Exception* SAXParseException::clone() const +{ + return new SAXParseException(*this); +} + + +void SAXParseException::rethrow() const +{ + throw *this; +} + + +std::string SAXParseException::buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber) +{ + std::ostringstream result; + if (!msg.empty()) result << msg << " "; + result << "in "; + if (!systemId.empty()) + result << "'" << fromXMLString(systemId) << "', "; + else if (!publicId.empty()) + result << "'" << fromXMLString(publicId) << "', "; + if (lineNumber > 0) + result << "line " << lineNumber << " column " << columnNumber; + return result.str(); +} + + +} } // namespace Poco::XML diff --git a/XML/src/SAXParser.cpp b/XML/src/SAXParser.cpp index 7c6e92958..9796c48f5 100644 --- a/XML/src/SAXParser.cpp +++ b/XML/src/SAXParser.cpp @@ -1,253 +1,253 @@ -// -// SAXParser.cpp -// -// $Id: //poco/1.3/XML/src/SAXParser.cpp#2 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/SAXParser.h" -#include "Poco/SAX/SAXException.h" -#include "Poco/SAX/EntityResolverImpl.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/XML/NamespaceStrategy.h" -#include - - -namespace Poco { -namespace XML { - - -SAXParser::SAXParser(): - _namespaces(true), - _namespacePrefixes(false) -{ -} - - -SAXParser::SAXParser(const XMLString& encoding): - _engine(encoding), - _namespaces(true), - _namespacePrefixes(false) -{ -} - - -SAXParser::~SAXParser() -{ -} - - -void SAXParser::setEncoding(const XMLString& encoding) -{ - _engine.setEncoding(encoding); -} - - -const XMLString& SAXParser::getEncoding() const -{ - return _engine.getEncoding(); -} - - -void SAXParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding) -{ - _engine.addEncoding(name, pEncoding); -} - - -void SAXParser::setEntityResolver(EntityResolver* pResolver) -{ - _engine.setEntityResolver(pResolver); -} - - -EntityResolver* SAXParser::getEntityResolver() const -{ - return _engine.getEntityResolver(); -} - - -void SAXParser::setDTDHandler(DTDHandler* pDTDHandler) -{ - _engine.setDTDHandler(pDTDHandler); -} - - -DTDHandler* SAXParser::getDTDHandler() const -{ - return _engine.getDTDHandler(); -} - - -void SAXParser::setContentHandler(ContentHandler* pContentHandler) -{ - _engine.setContentHandler(pContentHandler); -} - - -ContentHandler* SAXParser::getContentHandler() const -{ - return _engine.getContentHandler(); -} - - -void SAXParser::setErrorHandler(ErrorHandler* pErrorHandler) -{ - _engine.setErrorHandler(pErrorHandler); -} - - -ErrorHandler* SAXParser::getErrorHandler() const -{ - return _engine.getErrorHandler(); -} - - -void SAXParser::setFeature(const XMLString& featureId, bool state) -{ - if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION)); - else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES) - _engine.setExternalGeneralEntities(state); - else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES) - _engine.setExternalParameterEntities(state); - else if (featureId == XMLReader::FEATURE_NAMESPACES) - _namespaces = state; - else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) - _namespacePrefixes = state; - else throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -bool SAXParser::getFeature(const XMLString& featureId) const -{ - if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING) - throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION)); - else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES) - return _engine.getExternalGeneralEntities(); - else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES) - return _engine.getExternalParameterEntities(); - else if (featureId == XMLReader::FEATURE_NAMESPACES) - return _namespaces; - else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) - return _namespacePrefixes; - else throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -void SAXParser::setProperty(const XMLString& propertyId, const XMLString& value) -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); - else - throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void SAXParser::setProperty(const XMLString& propertyId, void* value) -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) - _engine.setDeclHandler(reinterpret_cast(value)); - else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - _engine.setLexicalHandler(reinterpret_cast(value)); - else throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void* SAXParser::getProperty(const XMLString& propertyId) const -{ - if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) - return _engine.getDeclHandler(); - else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - return _engine.getLexicalHandler(); - else throw SAXNotSupportedException(fromXMLString(propertyId)); -} - - -void SAXParser::parse(InputSource* pInputSource) -{ - if (pInputSource->getByteStream() || pInputSource->getCharacterStream()) - { - setupParse(); - _engine.parse(pInputSource); - } - else parse(pInputSource->getSystemId()); -} - - -void SAXParser::parse(const XMLString& systemId) -{ - setupParse(); - EntityResolverImpl entityResolver; - InputSource* pInputSource = entityResolver.resolveEntity(0, systemId); - if (pInputSource) - { - try - { - _engine.parse(pInputSource); - } - catch (...) - { - entityResolver.releaseInputSource(pInputSource); - throw; - } - entityResolver.releaseInputSource(pInputSource); - } - else throw XMLException("Cannot resolve system identifier", fromXMLString(systemId)); -} - - -void SAXParser::parseString(const std::string& xml) -{ - parseMemoryNP(xml.data(), xml.size()); -} - - -void SAXParser::parseMemoryNP(const char* xml, std::size_t size) -{ - setupParse(); - _engine.parse(xml, size); -} - - -void SAXParser::setupParse() -{ - if (_namespaces && !_namespacePrefixes) - _engine.setNamespaceStrategy(new NoNamespacePrefixesStrategy); - else if (_namespaces && _namespacePrefixes) - _engine.setNamespaceStrategy(new NamespacePrefixesStrategy); - else - _engine.setNamespaceStrategy(new NoNamespacesStrategy); -} - - -} } // namespace Poco::XML +// +// SAXParser.cpp +// +// $Id: //poco/1.3/XML/src/SAXParser.cpp#2 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/SAXParser.h" +#include "Poco/SAX/SAXException.h" +#include "Poco/SAX/EntityResolverImpl.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/XML/NamespaceStrategy.h" +#include + + +namespace Poco { +namespace XML { + + +SAXParser::SAXParser(): + _namespaces(true), + _namespacePrefixes(false) +{ +} + + +SAXParser::SAXParser(const XMLString& encoding): + _engine(encoding), + _namespaces(true), + _namespacePrefixes(false) +{ +} + + +SAXParser::~SAXParser() +{ +} + + +void SAXParser::setEncoding(const XMLString& encoding) +{ + _engine.setEncoding(encoding); +} + + +const XMLString& SAXParser::getEncoding() const +{ + return _engine.getEncoding(); +} + + +void SAXParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding) +{ + _engine.addEncoding(name, pEncoding); +} + + +void SAXParser::setEntityResolver(EntityResolver* pResolver) +{ + _engine.setEntityResolver(pResolver); +} + + +EntityResolver* SAXParser::getEntityResolver() const +{ + return _engine.getEntityResolver(); +} + + +void SAXParser::setDTDHandler(DTDHandler* pDTDHandler) +{ + _engine.setDTDHandler(pDTDHandler); +} + + +DTDHandler* SAXParser::getDTDHandler() const +{ + return _engine.getDTDHandler(); +} + + +void SAXParser::setContentHandler(ContentHandler* pContentHandler) +{ + _engine.setContentHandler(pContentHandler); +} + + +ContentHandler* SAXParser::getContentHandler() const +{ + return _engine.getContentHandler(); +} + + +void SAXParser::setErrorHandler(ErrorHandler* pErrorHandler) +{ + _engine.setErrorHandler(pErrorHandler); +} + + +ErrorHandler* SAXParser::getErrorHandler() const +{ + return _engine.getErrorHandler(); +} + + +void SAXParser::setFeature(const XMLString& featureId, bool state) +{ + if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION)); + else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES) + _engine.setExternalGeneralEntities(state); + else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES) + _engine.setExternalParameterEntities(state); + else if (featureId == XMLReader::FEATURE_NAMESPACES) + _namespaces = state; + else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) + _namespacePrefixes = state; + else throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +bool SAXParser::getFeature(const XMLString& featureId) const +{ + if (featureId == XMLReader::FEATURE_VALIDATION || featureId == XMLReader::FEATURE_STRING_INTERNING) + throw SAXNotSupportedException(fromXMLString(XMLReader::FEATURE_VALIDATION)); + else if (featureId == XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES) + return _engine.getExternalGeneralEntities(); + else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES) + return _engine.getExternalParameterEntities(); + else if (featureId == XMLReader::FEATURE_NAMESPACES) + return _namespaces; + else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES) + return _namespacePrefixes; + else throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +void SAXParser::setProperty(const XMLString& propertyId, const XMLString& value) +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER || propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); + else + throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void SAXParser::setProperty(const XMLString& propertyId, void* value) +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) + _engine.setDeclHandler(reinterpret_cast(value)); + else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + _engine.setLexicalHandler(reinterpret_cast(value)); + else throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void* SAXParser::getProperty(const XMLString& propertyId) const +{ + if (propertyId == XMLReader::PROPERTY_DECLARATION_HANDLER) + return _engine.getDeclHandler(); + else if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + return _engine.getLexicalHandler(); + else throw SAXNotSupportedException(fromXMLString(propertyId)); +} + + +void SAXParser::parse(InputSource* pInputSource) +{ + if (pInputSource->getByteStream() || pInputSource->getCharacterStream()) + { + setupParse(); + _engine.parse(pInputSource); + } + else parse(pInputSource->getSystemId()); +} + + +void SAXParser::parse(const XMLString& systemId) +{ + setupParse(); + EntityResolverImpl entityResolver; + InputSource* pInputSource = entityResolver.resolveEntity(0, systemId); + if (pInputSource) + { + try + { + _engine.parse(pInputSource); + } + catch (...) + { + entityResolver.releaseInputSource(pInputSource); + throw; + } + entityResolver.releaseInputSource(pInputSource); + } + else throw XMLException("Cannot resolve system identifier", fromXMLString(systemId)); +} + + +void SAXParser::parseString(const std::string& xml) +{ + parseMemoryNP(xml.data(), xml.size()); +} + + +void SAXParser::parseMemoryNP(const char* xml, std::size_t size) +{ + setupParse(); + _engine.parse(xml, size); +} + + +void SAXParser::setupParse() +{ + if (_namespaces && !_namespacePrefixes) + _engine.setNamespaceStrategy(new NoNamespacePrefixesStrategy); + else if (_namespaces && _namespacePrefixes) + _engine.setNamespaceStrategy(new NamespacePrefixesStrategy); + else + _engine.setNamespaceStrategy(new NoNamespacesStrategy); +} + + +} } // namespace Poco::XML diff --git a/XML/src/Text.cpp b/XML/src/Text.cpp index 340ebd415..615cac221 100644 --- a/XML/src/Text.cpp +++ b/XML/src/Text.cpp @@ -1,102 +1,102 @@ -// -// Text.cpp -// -// $Id: //poco/1.3/XML/src/Text.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: DOM -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/Text.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -const XMLString Text::NODE_NAME = toXMLString("#text"); - - -Text::Text(Document* pOwnerDocument, const XMLString& data): - CharacterData(pOwnerDocument, data) -{ -} - - -Text::Text(Document* pOwnerDocument, const Text& text): - CharacterData(pOwnerDocument, text) -{ -} - - -Text::~Text() -{ -} - - -Text* Text::splitText(unsigned long offset) -{ - Node* pParent = parentNode(); - if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); - int n = length() - offset; - Text* pNew = ownerDocument()->createTextNode(substringData(offset, n)); - deleteData(offset, n); - pParent->insertBefore(pNew, nextSibling())->release(); - return pNew; -} - - -const XMLString& Text::nodeName() const -{ - return NODE_NAME; -} - - -unsigned short Text::nodeType() const -{ - return Node::TEXT_NODE; -} - - -XMLString Text::innerText() const -{ - return nodeValue(); -} - - -Node* Text::copyNode(bool deep, Document* pOwnerDocument) const -{ - return new Text(pOwnerDocument, *this); -} - - -} } // namespace Poco::XML +// +// Text.cpp +// +// $Id: //poco/1.3/XML/src/Text.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: DOM +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/Text.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +const XMLString Text::NODE_NAME = toXMLString("#text"); + + +Text::Text(Document* pOwnerDocument, const XMLString& data): + CharacterData(pOwnerDocument, data) +{ +} + + +Text::Text(Document* pOwnerDocument, const Text& text): + CharacterData(pOwnerDocument, text) +{ +} + + +Text::~Text() +{ +} + + +Text* Text::splitText(unsigned long offset) +{ + Node* pParent = parentNode(); + if (!pParent) throw DOMException(DOMException::HIERARCHY_REQUEST_ERR); + int n = length() - offset; + Text* pNew = ownerDocument()->createTextNode(substringData(offset, n)); + deleteData(offset, n); + pParent->insertBefore(pNew, nextSibling())->release(); + return pNew; +} + + +const XMLString& Text::nodeName() const +{ + return NODE_NAME; +} + + +unsigned short Text::nodeType() const +{ + return Node::TEXT_NODE; +} + + +XMLString Text::innerText() const +{ + return nodeValue(); +} + + +Node* Text::copyNode(bool deep, Document* pOwnerDocument) const +{ + return new Text(pOwnerDocument, *this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/TreeWalker.cpp b/XML/src/TreeWalker.cpp index 1d934acd3..a6f432cfc 100644 --- a/XML/src/TreeWalker.cpp +++ b/XML/src/TreeWalker.cpp @@ -1,249 +1,249 @@ -// -// TreeWalker.cpp -// -// $Id: //poco/1.3/XML/src/TreeWalker.cpp#1 $ -// -// Library: XML -// Package: DOM -// Module: TreeWalker -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/DOM/TreeWalker.h" -#include "Poco/DOM/Node.h" -#include "Poco/DOM/NodeFilter.h" - - -namespace Poco { -namespace XML { - - -TreeWalker::TreeWalker(Node* root, unsigned long whatToShow, NodeFilter* pFilter): - _pRoot(root), - _whatToShow(whatToShow), - _pFilter(pFilter), - _pCurrent(root) -{ -} - - -TreeWalker::TreeWalker(const TreeWalker& walker): - _pRoot(walker._pRoot), - _whatToShow(walker._whatToShow), - _pFilter(walker._pFilter), - _pCurrent(walker._pCurrent) -{ -} - - -TreeWalker& TreeWalker::operator = (const TreeWalker& walker) -{ - if (&walker != this) - { - _pRoot = walker._pRoot; - _whatToShow = walker._whatToShow; - _pFilter = walker._pFilter; - _pCurrent = walker._pCurrent; - } - return *this; -} - - -TreeWalker::~TreeWalker() -{ -} - - -void TreeWalker::setCurrentNode(Node* pNode) -{ - _pCurrent = pNode; -} - - -Node* TreeWalker::parentNode() -{ - if (!_pCurrent || _pCurrent == _pRoot) return 0; - - Node* pParent = _pCurrent->parentNode(); - while (pParent && pParent != _pRoot && accept(pParent) != NodeFilter::FILTER_ACCEPT) - pParent = pParent->parentNode(); - if (pParent && accept(pParent) == NodeFilter::FILTER_ACCEPT) - _pCurrent = pParent; - else - pParent = 0; - return pParent; -} - - -Node* TreeWalker::firstChild() -{ - if (!_pCurrent) return 0; - - Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->firstChild() : 0; - while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) - pNode = pNode->nextSibling(); - if (pNode) - _pCurrent = pNode; - return pNode; -} - - -Node* TreeWalker::lastChild() -{ - if (!_pCurrent) return 0; - - Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->lastChild() : 0; - while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) - pNode = pNode->previousSibling(); - if (pNode) - _pCurrent = pNode; - return pNode; -} - - -Node* TreeWalker::previousSibling() -{ - if (!_pCurrent) return 0; - - Node* pNode = _pCurrent->previousSibling(); - while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) - pNode = pNode->previousSibling(); - if (pNode) - _pCurrent = pNode; - return pNode; -} - - -Node* TreeWalker::nextSibling() -{ - if (!_pCurrent) return 0; - - Node* pNode = _pCurrent->nextSibling(); - while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) - pNode = pNode->nextSibling(); - if (pNode) - _pCurrent = pNode; - return pNode; -} - - -Node* TreeWalker::previousNode() -{ - if (!_pCurrent) return 0; - - Node* pPrev = previous(_pCurrent); - while (pPrev && accept(pPrev) != NodeFilter::FILTER_ACCEPT) - pPrev = previous(pPrev); - if (pPrev) - _pCurrent = pPrev; - return pPrev; -} - - -Node* TreeWalker::nextNode() -{ - if (!_pCurrent) return 0; - - Node* pNext = next(_pCurrent); - while (pNext && accept(pNext) != NodeFilter::FILTER_ACCEPT) - pNext = next(pNext); - if (pNext) - _pCurrent = pNext; - return pNext; -} - - -int TreeWalker::accept(Node* pNode) const -{ - bool accept = false; - switch (pNode->nodeType()) - { - case Node::ELEMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; - case Node::ATTRIBUTE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; - case Node::TEXT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; - case Node::CDATA_SECTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; - case Node::ENTITY_REFERENCE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; - case Node::ENTITY_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; - case Node::PROCESSING_INSTRUCTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; - case Node::COMMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; - case Node::DOCUMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; - case Node::DOCUMENT_TYPE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; - case Node::DOCUMENT_FRAGMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; - case Node::NOTATION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; - } - if (accept && _pFilter) - return _pFilter->acceptNode(pNode); - else - return accept ? NodeFilter::FILTER_ACCEPT : NodeFilter::FILTER_REJECT; -} - - -Node* TreeWalker::next(Node* pNode) const -{ - Node* pNext = accept(pNode) != NodeFilter::FILTER_REJECT ? pNode->firstChild() : 0; - if (pNext) return pNext; - pNext = pNode; - while (pNext && pNext != _pRoot) - { - Node* pSibling = pNext->nextSibling(); - if (pSibling) return pSibling; - pNext = pNext->parentNode(); - } - return 0; -} - - -Node* TreeWalker::previous(Node* pNode) const -{ - if (pNode == _pRoot) return 0; - Node* pPrev = pNode->previousSibling(); - while (pPrev) - { - Node* pLastChild = accept(pPrev) != NodeFilter::FILTER_REJECT ? pPrev->lastChild() : 0; - if (pLastChild) - pPrev = pLastChild; - else - return pPrev; - } - return pNode->parentNode(); -} - - -} } // namespace Poco::XML +// +// TreeWalker.cpp +// +// $Id: //poco/1.3/XML/src/TreeWalker.cpp#1 $ +// +// Library: XML +// Package: DOM +// Module: TreeWalker +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/DOM/TreeWalker.h" +#include "Poco/DOM/Node.h" +#include "Poco/DOM/NodeFilter.h" + + +namespace Poco { +namespace XML { + + +TreeWalker::TreeWalker(Node* root, unsigned long whatToShow, NodeFilter* pFilter): + _pRoot(root), + _whatToShow(whatToShow), + _pFilter(pFilter), + _pCurrent(root) +{ +} + + +TreeWalker::TreeWalker(const TreeWalker& walker): + _pRoot(walker._pRoot), + _whatToShow(walker._whatToShow), + _pFilter(walker._pFilter), + _pCurrent(walker._pCurrent) +{ +} + + +TreeWalker& TreeWalker::operator = (const TreeWalker& walker) +{ + if (&walker != this) + { + _pRoot = walker._pRoot; + _whatToShow = walker._whatToShow; + _pFilter = walker._pFilter; + _pCurrent = walker._pCurrent; + } + return *this; +} + + +TreeWalker::~TreeWalker() +{ +} + + +void TreeWalker::setCurrentNode(Node* pNode) +{ + _pCurrent = pNode; +} + + +Node* TreeWalker::parentNode() +{ + if (!_pCurrent || _pCurrent == _pRoot) return 0; + + Node* pParent = _pCurrent->parentNode(); + while (pParent && pParent != _pRoot && accept(pParent) != NodeFilter::FILTER_ACCEPT) + pParent = pParent->parentNode(); + if (pParent && accept(pParent) == NodeFilter::FILTER_ACCEPT) + _pCurrent = pParent; + else + pParent = 0; + return pParent; +} + + +Node* TreeWalker::firstChild() +{ + if (!_pCurrent) return 0; + + Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->firstChild() : 0; + while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) + pNode = pNode->nextSibling(); + if (pNode) + _pCurrent = pNode; + return pNode; +} + + +Node* TreeWalker::lastChild() +{ + if (!_pCurrent) return 0; + + Node* pNode = accept(_pCurrent) != NodeFilter::FILTER_REJECT ? _pCurrent->lastChild() : 0; + while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) + pNode = pNode->previousSibling(); + if (pNode) + _pCurrent = pNode; + return pNode; +} + + +Node* TreeWalker::previousSibling() +{ + if (!_pCurrent) return 0; + + Node* pNode = _pCurrent->previousSibling(); + while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) + pNode = pNode->previousSibling(); + if (pNode) + _pCurrent = pNode; + return pNode; +} + + +Node* TreeWalker::nextSibling() +{ + if (!_pCurrent) return 0; + + Node* pNode = _pCurrent->nextSibling(); + while (pNode && accept(pNode) != NodeFilter::FILTER_ACCEPT) + pNode = pNode->nextSibling(); + if (pNode) + _pCurrent = pNode; + return pNode; +} + + +Node* TreeWalker::previousNode() +{ + if (!_pCurrent) return 0; + + Node* pPrev = previous(_pCurrent); + while (pPrev && accept(pPrev) != NodeFilter::FILTER_ACCEPT) + pPrev = previous(pPrev); + if (pPrev) + _pCurrent = pPrev; + return pPrev; +} + + +Node* TreeWalker::nextNode() +{ + if (!_pCurrent) return 0; + + Node* pNext = next(_pCurrent); + while (pNext && accept(pNext) != NodeFilter::FILTER_ACCEPT) + pNext = next(pNext); + if (pNext) + _pCurrent = pNext; + return pNext; +} + + +int TreeWalker::accept(Node* pNode) const +{ + bool accept = false; + switch (pNode->nodeType()) + { + case Node::ELEMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; + case Node::ATTRIBUTE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; + case Node::TEXT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; + case Node::CDATA_SECTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; + case Node::ENTITY_REFERENCE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; + case Node::ENTITY_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; + case Node::PROCESSING_INSTRUCTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; + case Node::COMMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; + case Node::DOCUMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; + case Node::DOCUMENT_TYPE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; + case Node::DOCUMENT_FRAGMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; + case Node::NOTATION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; + } + if (accept && _pFilter) + return _pFilter->acceptNode(pNode); + else + return accept ? NodeFilter::FILTER_ACCEPT : NodeFilter::FILTER_REJECT; +} + + +Node* TreeWalker::next(Node* pNode) const +{ + Node* pNext = accept(pNode) != NodeFilter::FILTER_REJECT ? pNode->firstChild() : 0; + if (pNext) return pNext; + pNext = pNode; + while (pNext && pNext != _pRoot) + { + Node* pSibling = pNext->nextSibling(); + if (pSibling) return pSibling; + pNext = pNext->parentNode(); + } + return 0; +} + + +Node* TreeWalker::previous(Node* pNode) const +{ + if (pNode == _pRoot) return 0; + Node* pPrev = pNode->previousSibling(); + while (pPrev) + { + Node* pLastChild = accept(pPrev) != NodeFilter::FILTER_REJECT ? pPrev->lastChild() : 0; + if (pLastChild) + pPrev = pLastChild; + else + return pPrev; + } + return pNode->parentNode(); +} + + +} } // namespace Poco::XML diff --git a/XML/src/WhitespaceFilter.cpp b/XML/src/WhitespaceFilter.cpp index 13afb91dd..77c4595a6 100644 --- a/XML/src/WhitespaceFilter.cpp +++ b/XML/src/WhitespaceFilter.cpp @@ -1,234 +1,234 @@ -// -// WhitespaceFilter.cpp -// -// $Id: //poco/1.3/XML/src/WhitespaceFilter.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: WhitespaceFilter -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/WhitespaceFilter.h" -#include "Poco/SAX/SAXException.h" - - -namespace Poco { -namespace XML { - - -WhitespaceFilter::WhitespaceFilter(): - _pLexicalHandler(0), - _filter(true) -{ -} - - -WhitespaceFilter::WhitespaceFilter(XMLReader* pReader): - XMLFilterImpl(pReader), - _pLexicalHandler(0), - _filter(true) -{ -} - - -WhitespaceFilter::~WhitespaceFilter() -{ -} - - -void WhitespaceFilter::setProperty(const XMLString& propertyId, const XMLString& value) -{ - if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); - else - XMLFilterImpl::setProperty(propertyId, value); - -} - - -void WhitespaceFilter::setProperty(const XMLString& propertyId, void* value) -{ - if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - _pLexicalHandler = reinterpret_cast(value); - else - XMLFilterImpl::setProperty(propertyId, value); -} - - -void* WhitespaceFilter::getProperty(const XMLString& propertyId) const -{ - if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) - return _pLexicalHandler; - else - return XMLFilterImpl::getProperty(propertyId); -} - - -void WhitespaceFilter::startDocument() -{ - XMLFilterImpl::startDocument(); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::endDocument() -{ - XMLFilterImpl::endDocument(); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) -{ - XMLFilterImpl::startElement(uri, localName, qname, attrList); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) -{ - XMLFilterImpl::endElement(uri, localName, qname); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::characters(const XMLChar ch[], int start, int length) -{ - if (_filter) - { - bool ws = true; - const XMLChar* it = ch + start; - const XMLChar* end = ch + start + length; - _data.append(it, end); - while (it != end) - { - if (*it != '\r' && *it != '\n' && *it != '\t' && *it != ' ') - { - ws = false; - break; - } - ++it; - } - if (!ws) - { - XMLFilterImpl::characters(_data.data(), 0, (int) _data.length()); - _filter = false; - _data.clear(); - } - } - else XMLFilterImpl::characters(ch, start, length); -} - - -void WhitespaceFilter::ignorableWhitespace(const XMLChar ch[], int start, int length) -{ - // the handler name already says that this data can be ignored -} - - -void WhitespaceFilter::processingInstruction(const XMLString& target, const XMLString& data) -{ - XMLFilterImpl::processingInstruction(target, data); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) -{ - if (_pLexicalHandler) - _pLexicalHandler->startDTD(name, publicId, systemId); -} - - -void WhitespaceFilter::endDTD() -{ - if (_pLexicalHandler) - _pLexicalHandler->endDTD(); -} - - -void WhitespaceFilter::startEntity(const XMLString& name) -{ - if (_pLexicalHandler) - _pLexicalHandler->startEntity(name); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::endEntity(const XMLString& name) -{ - if (_pLexicalHandler) - _pLexicalHandler->endEntity(name); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::startCDATA() -{ - if (_pLexicalHandler) - _pLexicalHandler->startCDATA(); - _filter = false; - _data.clear(); -} - - -void WhitespaceFilter::endCDATA() -{ - if (_pLexicalHandler) - _pLexicalHandler->endCDATA(); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::comment(const XMLChar ch[], int start, int length) -{ - if (_pLexicalHandler) - _pLexicalHandler->comment(ch, start, length); - _filter = true; - _data.clear(); -} - - -void WhitespaceFilter::setupParse() -{ - XMLFilterImpl::setupParse(); - - parent()->setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(this)); -} - - -} } // namespace Poco::XML +// +// WhitespaceFilter.cpp +// +// $Id: //poco/1.3/XML/src/WhitespaceFilter.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: WhitespaceFilter +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/WhitespaceFilter.h" +#include "Poco/SAX/SAXException.h" + + +namespace Poco { +namespace XML { + + +WhitespaceFilter::WhitespaceFilter(): + _pLexicalHandler(0), + _filter(true) +{ +} + + +WhitespaceFilter::WhitespaceFilter(XMLReader* pReader): + XMLFilterImpl(pReader), + _pLexicalHandler(0), + _filter(true) +{ +} + + +WhitespaceFilter::~WhitespaceFilter() +{ +} + + +void WhitespaceFilter::setProperty(const XMLString& propertyId, const XMLString& value) +{ + if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + throw SAXNotSupportedException(std::string("property does not take a string value: ") + fromXMLString(propertyId)); + else + XMLFilterImpl::setProperty(propertyId, value); + +} + + +void WhitespaceFilter::setProperty(const XMLString& propertyId, void* value) +{ + if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + _pLexicalHandler = reinterpret_cast(value); + else + XMLFilterImpl::setProperty(propertyId, value); +} + + +void* WhitespaceFilter::getProperty(const XMLString& propertyId) const +{ + if (propertyId == XMLReader::PROPERTY_LEXICAL_HANDLER) + return _pLexicalHandler; + else + return XMLFilterImpl::getProperty(propertyId); +} + + +void WhitespaceFilter::startDocument() +{ + XMLFilterImpl::startDocument(); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::endDocument() +{ + XMLFilterImpl::endDocument(); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) +{ + XMLFilterImpl::startElement(uri, localName, qname, attrList); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) +{ + XMLFilterImpl::endElement(uri, localName, qname); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::characters(const XMLChar ch[], int start, int length) +{ + if (_filter) + { + bool ws = true; + const XMLChar* it = ch + start; + const XMLChar* end = ch + start + length; + _data.append(it, end); + while (it != end) + { + if (*it != '\r' && *it != '\n' && *it != '\t' && *it != ' ') + { + ws = false; + break; + } + ++it; + } + if (!ws) + { + XMLFilterImpl::characters(_data.data(), 0, (int) _data.length()); + _filter = false; + _data.clear(); + } + } + else XMLFilterImpl::characters(ch, start, length); +} + + +void WhitespaceFilter::ignorableWhitespace(const XMLChar ch[], int start, int length) +{ + // the handler name already says that this data can be ignored +} + + +void WhitespaceFilter::processingInstruction(const XMLString& target, const XMLString& data) +{ + XMLFilterImpl::processingInstruction(target, data); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) +{ + if (_pLexicalHandler) + _pLexicalHandler->startDTD(name, publicId, systemId); +} + + +void WhitespaceFilter::endDTD() +{ + if (_pLexicalHandler) + _pLexicalHandler->endDTD(); +} + + +void WhitespaceFilter::startEntity(const XMLString& name) +{ + if (_pLexicalHandler) + _pLexicalHandler->startEntity(name); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::endEntity(const XMLString& name) +{ + if (_pLexicalHandler) + _pLexicalHandler->endEntity(name); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::startCDATA() +{ + if (_pLexicalHandler) + _pLexicalHandler->startCDATA(); + _filter = false; + _data.clear(); +} + + +void WhitespaceFilter::endCDATA() +{ + if (_pLexicalHandler) + _pLexicalHandler->endCDATA(); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::comment(const XMLChar ch[], int start, int length) +{ + if (_pLexicalHandler) + _pLexicalHandler->comment(ch, start, length); + _filter = true; + _data.clear(); +} + + +void WhitespaceFilter::setupParse() +{ + XMLFilterImpl::setupParse(); + + parent()->setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(this)); +} + + +} } // namespace Poco::XML diff --git a/XML/src/XMLException.cpp b/XML/src/XMLException.cpp index c94f616ab..7629fc340 100644 --- a/XML/src/XMLException.cpp +++ b/XML/src/XMLException.cpp @@ -1,51 +1,51 @@ -// -// XMLException.cpp -// -// $Id: //poco/1.3/XML/src/XMLException.cpp#1 $ -// -// Library: XML -// Package: XML -// Module: XMLException -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/XML/XMLException.h" -#include - - -using Poco::RuntimeException; - - -namespace Poco { -namespace XML { - - -POCO_IMPLEMENT_EXCEPTION(XMLException, RuntimeException, "XML Exception") - - -} } // namespace Poco::XML +// +// XMLException.cpp +// +// $Id: //poco/1.3/XML/src/XMLException.cpp#1 $ +// +// Library: XML +// Package: XML +// Module: XMLException +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/XML/XMLException.h" +#include + + +using Poco::RuntimeException; + + +namespace Poco { +namespace XML { + + +POCO_IMPLEMENT_EXCEPTION(XMLException, RuntimeException, "XML Exception") + + +} } // namespace Poco::XML diff --git a/XML/src/XMLFilter.cpp b/XML/src/XMLFilter.cpp index 54ce030db..762ea4f28 100644 --- a/XML/src/XMLFilter.cpp +++ b/XML/src/XMLFilter.cpp @@ -1,49 +1,49 @@ -// -// XMLFilter.cpp -// -// $Id: //poco/1.3/XML/src/XMLFilter.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAXFilters -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/XMLFilter.h" - - -namespace Poco { -namespace XML { - - -XMLFilter::~XMLFilter() -{ -} - - -} } // namespace Poco::XML +// +// XMLFilter.cpp +// +// $Id: //poco/1.3/XML/src/XMLFilter.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAXFilters +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/XMLFilter.h" + + +namespace Poco { +namespace XML { + + +XMLFilter::~XMLFilter() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/XMLFilterImpl.cpp b/XML/src/XMLFilterImpl.cpp index 900b57e81..b38111f26 100644 --- a/XML/src/XMLFilterImpl.cpp +++ b/XML/src/XMLFilterImpl.cpp @@ -1,335 +1,335 @@ -// -// XMLFilterImpl.cpp -// -// $Id: //poco/1.3/XML/src/XMLFilterImpl.cpp#2 $ -// -// Library: XML -// Package: SAX -// Module: SAXFilters -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/XMLFilterImpl.h" -#include "Poco/SAX/SAXException.h" - - -namespace Poco { -namespace XML { - - -XMLFilterImpl::XMLFilterImpl(): - _pParent(0), - _pEntityResolver(0), - _pDTDHandler(0), - _pContentHandler(0), - _pErrorHandler(0) -{ -} - - -XMLFilterImpl::XMLFilterImpl(XMLReader* pParent): - _pParent(pParent), - _pEntityResolver(0), - _pDTDHandler(0), - _pContentHandler(0), - _pErrorHandler(0) -{ -} - - -XMLFilterImpl::~XMLFilterImpl() -{ -} - - -XMLReader* XMLFilterImpl::getParent() const -{ - return _pParent; -} - - -void XMLFilterImpl::setParent(XMLReader* pParent) -{ - _pParent = pParent; -} - - -void XMLFilterImpl::setEntityResolver(EntityResolver* pResolver) -{ - _pEntityResolver = pResolver; -} - - -EntityResolver* XMLFilterImpl::getEntityResolver() const -{ - return _pEntityResolver; -} - - -void XMLFilterImpl::setDTDHandler(DTDHandler* pDTDHandler) -{ - _pDTDHandler = pDTDHandler; -} - - -DTDHandler* XMLFilterImpl::getDTDHandler() const -{ - return _pDTDHandler; -} - - -void XMLFilterImpl::setContentHandler(ContentHandler* pContentHandler) -{ - _pContentHandler = pContentHandler; -} - - -ContentHandler* XMLFilterImpl::getContentHandler() const -{ - return _pContentHandler; -} - - -void XMLFilterImpl::setErrorHandler(ErrorHandler* pErrorHandler) -{ - _pErrorHandler = pErrorHandler; -} - - -ErrorHandler* XMLFilterImpl::getErrorHandler() const -{ - return _pErrorHandler; -} - - -void XMLFilterImpl::setFeature(const XMLString& featureId, bool state) -{ - if (_pParent) - _pParent->setFeature(featureId, state); - else - throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -bool XMLFilterImpl::getFeature(const XMLString& featureId) const -{ - if (_pParent) - return _pParent->getFeature(featureId); - else - throw SAXNotRecognizedException(fromXMLString(featureId)); -} - - -void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& value) -{ - if (_pParent) - _pParent->setProperty(propertyId, value); - else - throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value) -{ - if (_pParent) - _pParent->setProperty(propertyId, value); - else - throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void* XMLFilterImpl::getProperty(const XMLString& propertyId) const -{ - if (_pParent) - return _pParent->getProperty(propertyId); - else - throw SAXNotRecognizedException(fromXMLString(propertyId)); -} - - -void XMLFilterImpl::parse(InputSource* pSource) -{ - setupParse(); - _pParent->parse(pSource); -} - - -void XMLFilterImpl::parse(const XMLString& systemId) -{ - setupParse(); - _pParent->parse(systemId); -} - - -void XMLFilterImpl::parseMemoryNP(const char* xml, std::size_t size) -{ - setupParse(); - _pParent->parseMemoryNP(xml, size); -} - - -InputSource* XMLFilterImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) -{ - if (_pEntityResolver) - return _pEntityResolver->resolveEntity(publicId, systemId); - else - return 0; -} - - -void XMLFilterImpl::releaseInputSource(InputSource* pSource) -{ - if (_pEntityResolver) - _pEntityResolver->releaseInputSource(pSource); -} - - -void XMLFilterImpl::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) -{ - if (_pDTDHandler) - _pDTDHandler->notationDecl(name, publicId, systemId); -} - - -void XMLFilterImpl::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) -{ - if (_pDTDHandler) - _pDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName); -} - - -void XMLFilterImpl::setDocumentLocator(const Locator* loc) -{ - if (_pContentHandler) - _pContentHandler->setDocumentLocator(loc); -} - - -void XMLFilterImpl::startDocument() -{ - if (_pContentHandler) - _pContentHandler->startDocument(); -} - - -void XMLFilterImpl::endDocument() -{ - if (_pContentHandler) - _pContentHandler->endDocument(); -} - - -void XMLFilterImpl::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) -{ - if (_pContentHandler) - _pContentHandler->startElement(uri, localName, qname, attrList); -} - - -void XMLFilterImpl::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) -{ - if (_pContentHandler) - _pContentHandler->endElement(uri, localName, qname); -} - - -void XMLFilterImpl::characters(const XMLChar ch[], int start, int length) -{ - if (_pContentHandler) - _pContentHandler->characters(ch, start, length); -} - - -void XMLFilterImpl::ignorableWhitespace(const XMLChar ch[], int start, int length) -{ - if (_pContentHandler) - _pContentHandler->ignorableWhitespace(ch, start, length); -} - - -void XMLFilterImpl::processingInstruction(const XMLString& target, const XMLString& data) -{ - if (_pContentHandler) - _pContentHandler->processingInstruction(target, data); -} - - -void XMLFilterImpl::startPrefixMapping(const XMLString& prefix, const XMLString& uri) -{ - if (_pContentHandler) - _pContentHandler->startPrefixMapping(prefix, uri); -} - - -void XMLFilterImpl::endPrefixMapping(const XMLString& prefix) -{ - if (_pContentHandler) - _pContentHandler->endPrefixMapping(prefix); -} - - -void XMLFilterImpl::skippedEntity(const XMLString& prefix) -{ - if (_pContentHandler) - _pContentHandler->skippedEntity(prefix); -} - - -void XMLFilterImpl::warning(const SAXException& e) -{ - if (_pErrorHandler) - _pErrorHandler->warning(e); -} - - -void XMLFilterImpl::error(const SAXException& e) -{ - if (_pErrorHandler) - _pErrorHandler->error(e); -} - - -void XMLFilterImpl::fatalError(const SAXException& e) -{ - if (_pErrorHandler) - _pErrorHandler->fatalError(e); -} - - -void XMLFilterImpl::setupParse() -{ - poco_check_ptr (_pParent); - - _pParent->setEntityResolver(this); - _pParent->setDTDHandler(this); - _pParent->setContentHandler(this); - _pParent->setErrorHandler(this); -} - - -} } // namespace Poco::XML +// +// XMLFilterImpl.cpp +// +// $Id: //poco/1.3/XML/src/XMLFilterImpl.cpp#2 $ +// +// Library: XML +// Package: SAX +// Module: SAXFilters +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/XMLFilterImpl.h" +#include "Poco/SAX/SAXException.h" + + +namespace Poco { +namespace XML { + + +XMLFilterImpl::XMLFilterImpl(): + _pParent(0), + _pEntityResolver(0), + _pDTDHandler(0), + _pContentHandler(0), + _pErrorHandler(0) +{ +} + + +XMLFilterImpl::XMLFilterImpl(XMLReader* pParent): + _pParent(pParent), + _pEntityResolver(0), + _pDTDHandler(0), + _pContentHandler(0), + _pErrorHandler(0) +{ +} + + +XMLFilterImpl::~XMLFilterImpl() +{ +} + + +XMLReader* XMLFilterImpl::getParent() const +{ + return _pParent; +} + + +void XMLFilterImpl::setParent(XMLReader* pParent) +{ + _pParent = pParent; +} + + +void XMLFilterImpl::setEntityResolver(EntityResolver* pResolver) +{ + _pEntityResolver = pResolver; +} + + +EntityResolver* XMLFilterImpl::getEntityResolver() const +{ + return _pEntityResolver; +} + + +void XMLFilterImpl::setDTDHandler(DTDHandler* pDTDHandler) +{ + _pDTDHandler = pDTDHandler; +} + + +DTDHandler* XMLFilterImpl::getDTDHandler() const +{ + return _pDTDHandler; +} + + +void XMLFilterImpl::setContentHandler(ContentHandler* pContentHandler) +{ + _pContentHandler = pContentHandler; +} + + +ContentHandler* XMLFilterImpl::getContentHandler() const +{ + return _pContentHandler; +} + + +void XMLFilterImpl::setErrorHandler(ErrorHandler* pErrorHandler) +{ + _pErrorHandler = pErrorHandler; +} + + +ErrorHandler* XMLFilterImpl::getErrorHandler() const +{ + return _pErrorHandler; +} + + +void XMLFilterImpl::setFeature(const XMLString& featureId, bool state) +{ + if (_pParent) + _pParent->setFeature(featureId, state); + else + throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +bool XMLFilterImpl::getFeature(const XMLString& featureId) const +{ + if (_pParent) + return _pParent->getFeature(featureId); + else + throw SAXNotRecognizedException(fromXMLString(featureId)); +} + + +void XMLFilterImpl::setProperty(const XMLString& propertyId, const XMLString& value) +{ + if (_pParent) + _pParent->setProperty(propertyId, value); + else + throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void XMLFilterImpl::setProperty(const XMLString& propertyId, void* value) +{ + if (_pParent) + _pParent->setProperty(propertyId, value); + else + throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void* XMLFilterImpl::getProperty(const XMLString& propertyId) const +{ + if (_pParent) + return _pParent->getProperty(propertyId); + else + throw SAXNotRecognizedException(fromXMLString(propertyId)); +} + + +void XMLFilterImpl::parse(InputSource* pSource) +{ + setupParse(); + _pParent->parse(pSource); +} + + +void XMLFilterImpl::parse(const XMLString& systemId) +{ + setupParse(); + _pParent->parse(systemId); +} + + +void XMLFilterImpl::parseMemoryNP(const char* xml, std::size_t size) +{ + setupParse(); + _pParent->parseMemoryNP(xml, size); +} + + +InputSource* XMLFilterImpl::resolveEntity(const XMLString* publicId, const XMLString& systemId) +{ + if (_pEntityResolver) + return _pEntityResolver->resolveEntity(publicId, systemId); + else + return 0; +} + + +void XMLFilterImpl::releaseInputSource(InputSource* pSource) +{ + if (_pEntityResolver) + _pEntityResolver->releaseInputSource(pSource); +} + + +void XMLFilterImpl::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) +{ + if (_pDTDHandler) + _pDTDHandler->notationDecl(name, publicId, systemId); +} + + +void XMLFilterImpl::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) +{ + if (_pDTDHandler) + _pDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName); +} + + +void XMLFilterImpl::setDocumentLocator(const Locator* loc) +{ + if (_pContentHandler) + _pContentHandler->setDocumentLocator(loc); +} + + +void XMLFilterImpl::startDocument() +{ + if (_pContentHandler) + _pContentHandler->startDocument(); +} + + +void XMLFilterImpl::endDocument() +{ + if (_pContentHandler) + _pContentHandler->endDocument(); +} + + +void XMLFilterImpl::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attrList) +{ + if (_pContentHandler) + _pContentHandler->startElement(uri, localName, qname, attrList); +} + + +void XMLFilterImpl::endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname) +{ + if (_pContentHandler) + _pContentHandler->endElement(uri, localName, qname); +} + + +void XMLFilterImpl::characters(const XMLChar ch[], int start, int length) +{ + if (_pContentHandler) + _pContentHandler->characters(ch, start, length); +} + + +void XMLFilterImpl::ignorableWhitespace(const XMLChar ch[], int start, int length) +{ + if (_pContentHandler) + _pContentHandler->ignorableWhitespace(ch, start, length); +} + + +void XMLFilterImpl::processingInstruction(const XMLString& target, const XMLString& data) +{ + if (_pContentHandler) + _pContentHandler->processingInstruction(target, data); +} + + +void XMLFilterImpl::startPrefixMapping(const XMLString& prefix, const XMLString& uri) +{ + if (_pContentHandler) + _pContentHandler->startPrefixMapping(prefix, uri); +} + + +void XMLFilterImpl::endPrefixMapping(const XMLString& prefix) +{ + if (_pContentHandler) + _pContentHandler->endPrefixMapping(prefix); +} + + +void XMLFilterImpl::skippedEntity(const XMLString& prefix) +{ + if (_pContentHandler) + _pContentHandler->skippedEntity(prefix); +} + + +void XMLFilterImpl::warning(const SAXException& e) +{ + if (_pErrorHandler) + _pErrorHandler->warning(e); +} + + +void XMLFilterImpl::error(const SAXException& e) +{ + if (_pErrorHandler) + _pErrorHandler->error(e); +} + + +void XMLFilterImpl::fatalError(const SAXException& e) +{ + if (_pErrorHandler) + _pErrorHandler->fatalError(e); +} + + +void XMLFilterImpl::setupParse() +{ + poco_check_ptr (_pParent); + + _pParent->setEntityResolver(this); + _pParent->setDTDHandler(this); + _pParent->setContentHandler(this); + _pParent->setErrorHandler(this); +} + + +} } // namespace Poco::XML diff --git a/XML/src/XMLReader.cpp b/XML/src/XMLReader.cpp index 8a472c119..c70a72ef5 100644 --- a/XML/src/XMLReader.cpp +++ b/XML/src/XMLReader.cpp @@ -1,59 +1,59 @@ -// -// XMLReader.cpp -// -// $Id: //poco/1.3/XML/src/XMLReader.cpp#1 $ -// -// Library: XML -// Package: SAX -// Module: SAX -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/SAX/XMLReader.h" - - -namespace Poco { -namespace XML { - - -const XMLString XMLReader::FEATURE_VALIDATION = toXMLString("http://xml.org/sax/features/validation"); -const XMLString XMLReader::FEATURE_NAMESPACES = toXMLString("http://xml.org/sax/features/namespaces"); -const XMLString XMLReader::FEATURE_NAMESPACE_PREFIXES = toXMLString("http://xml.org/sax/features/namespace-prefixes"); -const XMLString XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES = toXMLString("http://xml.org/sax/features/external-general-entities"); -const XMLString XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES = toXMLString("http://xml.org/sax/features/external-parameter-entities"); -const XMLString XMLReader::FEATURE_STRING_INTERNING = toXMLString("http://xml.org/sax/features/string-interning"); -const XMLString XMLReader::PROPERTY_DECLARATION_HANDLER = toXMLString("http://xml.org/sax/properties/declaration-handler"); -const XMLString XMLReader::PROPERTY_LEXICAL_HANDLER = toXMLString("http://xml.org/sax/properties/lexical-handler"); - - -XMLReader::~XMLReader() -{ -} - - -} } // namespace Poco::XML +// +// XMLReader.cpp +// +// $Id: //poco/1.3/XML/src/XMLReader.cpp#1 $ +// +// Library: XML +// Package: SAX +// Module: SAX +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/SAX/XMLReader.h" + + +namespace Poco { +namespace XML { + + +const XMLString XMLReader::FEATURE_VALIDATION = toXMLString("http://xml.org/sax/features/validation"); +const XMLString XMLReader::FEATURE_NAMESPACES = toXMLString("http://xml.org/sax/features/namespaces"); +const XMLString XMLReader::FEATURE_NAMESPACE_PREFIXES = toXMLString("http://xml.org/sax/features/namespace-prefixes"); +const XMLString XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES = toXMLString("http://xml.org/sax/features/external-general-entities"); +const XMLString XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES = toXMLString("http://xml.org/sax/features/external-parameter-entities"); +const XMLString XMLReader::FEATURE_STRING_INTERNING = toXMLString("http://xml.org/sax/features/string-interning"); +const XMLString XMLReader::PROPERTY_DECLARATION_HANDLER = toXMLString("http://xml.org/sax/properties/declaration-handler"); +const XMLString XMLReader::PROPERTY_LEXICAL_HANDLER = toXMLString("http://xml.org/sax/properties/lexical-handler"); + + +XMLReader::~XMLReader() +{ +} + + +} } // namespace Poco::XML diff --git a/XML/src/XMLString.cpp b/XML/src/XMLString.cpp index 7b90618c8..1ede83fe8 100644 --- a/XML/src/XMLString.cpp +++ b/XML/src/XMLString.cpp @@ -1,86 +1,86 @@ -// -// XMLString.cpp -// -// $Id: //poco/1.3/XML/src/XMLString.cpp#1 $ -// -// Library: XML -// Package: XML -// Module: XMLString -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/XML/XMLString.h" - - -#if defined(XML_UNICODE_WCHAR_T) -#include -#endif - - -namespace Poco { -namespace XML { - - -#if defined(XML_UNICODE_WCHAR_T) - - -std::string fromXMLString(const XMLString& str) -{ - std::string result; - result.reserve(str.size()); - - for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it) - { - char c; - wctomb(&c, *it); - result += c; - } - return result; -} - - -XMLString toXMLString(const std::string& str) -{ - XMLString result; - result.reserve(str.size()); - - for (std::string::const_iterator it = str.begin(); it != str.end();) - { - wchar_t c; - int n = mbtowc(&c, &*it, MB_CUR_MAX); - result += c; - it += (n > 0 ? n : 1); - } - return result; -} - - -#endif // XML_UNICODE_WCHAR_T - - -} } // namespace Poco::XML +// +// XMLString.cpp +// +// $Id: //poco/1.3/XML/src/XMLString.cpp#1 $ +// +// Library: XML +// Package: XML +// Module: XMLString +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/XML/XMLString.h" + + +#if defined(XML_UNICODE_WCHAR_T) +#include +#endif + + +namespace Poco { +namespace XML { + + +#if defined(XML_UNICODE_WCHAR_T) + + +std::string fromXMLString(const XMLString& str) +{ + std::string result; + result.reserve(str.size()); + + for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it) + { + char c; + wctomb(&c, *it); + result += c; + } + return result; +} + + +XMLString toXMLString(const std::string& str) +{ + XMLString result; + result.reserve(str.size()); + + for (std::string::const_iterator it = str.begin(); it != str.end();) + { + wchar_t c; + int n = mbtowc(&c, &*it, MB_CUR_MAX); + result += c; + it += (n > 0 ? n : 1); + } + return result; +} + + +#endif // XML_UNICODE_WCHAR_T + + +} } // namespace Poco::XML diff --git a/XML/src/XMLWriter.cpp b/XML/src/XMLWriter.cpp index 827f7f7fe..0d2f351cb 100644 --- a/XML/src/XMLWriter.cpp +++ b/XML/src/XMLWriter.cpp @@ -1,816 +1,816 @@ -// -// XMLWriter.cpp -// -// $Id: //poco/1.3/XML/src/XMLWriter.cpp#2 $ -// -// Library: XML -// Package: XML -// Module: XMLWriter -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "Poco/XML/XMLWriter.h" -#include "Poco/XML/XMLString.h" -#include "Poco/XML/XMLException.h" -#include "Poco/SAX/AttributesImpl.h" -#include "Poco/UTF8Encoding.h" -#include "Poco/UTF16Encoding.h" -#include - - -namespace Poco { -namespace XML { - - -const std::string XMLWriter::NEWLINE_DEFAULT; -const std::string XMLWriter::NEWLINE_CR = "\r"; -const std::string XMLWriter::NEWLINE_CRLF = "\r\n"; -const std::string XMLWriter::NEWLINE_LF = "\n"; -const std::string XMLWriter::MARKUP_QUOTENC = """; -const std::string XMLWriter::MARKUP_APOSENC = "'"; -const std::string XMLWriter::MARKUP_AMPENC = "&"; -const std::string XMLWriter::MARKUP_LTENC = "<"; -const std::string XMLWriter::MARKUP_GTENC = ">"; -const std::string XMLWriter::MARKUP_LT = "<"; -const std::string XMLWriter::MARKUP_GT = ">"; -const std::string XMLWriter::MARKUP_SLASHGT = "/>"; -const std::string XMLWriter::MARKUP_LTSLASH = ""; - - -#if defined(XML_UNICODE_WCHAR_T) - #define NATIVE_ENCODING Poco::UTF16Encoding -#else - #define NATIVE_ENCODING Poco::UTF8Encoding -#endif - - -XMLWriter::XMLWriter(XMLByteOutputStream& str, int options): - _pTextConverter(0), - _pInEncoding(new NATIVE_ENCODING), - _pOutEncoding(new Poco::UTF8Encoding), - _options(options), - _encoding("UTF-8"), - _depth(-1), - _elementCount(0), - _inFragment(false), - _inCDATA(false), - _inDTD(false), - _inInternalDTD(false), - _contentWritten(false), - _unclosedStartTag(false), - _prefix(0) -{ - _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding); - setNewLine(NEWLINE_DEFAULT); -} - - -XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding& textEncoding): - _pTextConverter(0), - _pInEncoding(new NATIVE_ENCODING), - _pOutEncoding(0), - _options(options), - _encoding(encodingName), - _depth(-1), - _elementCount(0), - _inFragment(false), - _inCDATA(false), - _inDTD(false), - _inInternalDTD(false), - _contentWritten(false), - _unclosedStartTag(false), - _prefix(0) -{ - _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, textEncoding); - setNewLine(NEWLINE_DEFAULT); -} - - -XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding* pTextEncoding): - _pTextConverter(0), - _pInEncoding(new NATIVE_ENCODING), - _pOutEncoding(0), - _options(options), - _encoding(encodingName), - _depth(-1), - _elementCount(0), - _inFragment(false), - _inCDATA(false), - _inDTD(false), - _inInternalDTD(false), - _contentWritten(false), - _unclosedStartTag(false), - _prefix(0) -{ - if (pTextEncoding) - { - _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *pTextEncoding); - } - else - { - _encoding = "UTF-8"; - _pOutEncoding = new Poco::UTF8Encoding; - _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding); - } - setNewLine(NEWLINE_DEFAULT); -} - - -XMLWriter::~XMLWriter() -{ - delete _pTextConverter; - delete _pInEncoding; - delete _pOutEncoding; -} - - -void XMLWriter::setDocumentLocator(const Locator* loc) -{ -} - - -void XMLWriter::setNewLine(const std::string& newLineCharacters) -{ - if (newLineCharacters.empty()) - { -#if defined(_WIN32) - _newLine = NEWLINE_CRLF; -#else - _newLine = NEWLINE_LF; -#endif - } - else _newLine = newLineCharacters; -} - - -const std::string& XMLWriter::getNewLine() const -{ - return _newLine; -} - - -void XMLWriter::startDocument() -{ - if (_depth != -1) - throw XMLException("Cannot start a document in another document"); - - _inFragment = false; - _depth = 0; - _elementCount = 0; - _inDTD = false; - _inInternalDTD = false; - _prefix = 0; - - if (_options & WRITE_XML_DECLARATION) - writeXMLDeclaration(); - - _contentWritten = true; - _namespaces.reset(); - _namespaces.pushContext(); -} - - -void XMLWriter::endDocument() -{ - if (_depth > 0) - throw XMLException("Not well-formed (at least one tag has no matching end tag)"); - if (_elementCount == 0) - throw XMLException("No document element"); - - poco_assert_dbg (!_unclosedStartTag); - - _elementCount = 0; - _depth = -1; -} - - -void XMLWriter::startFragment() -{ - if (_depth != -1) - throw XMLException("Cannot start a fragment in another fragment or document"); - - _inFragment = true; - _depth = 0; - _elementCount = 0; - _prefix = 0; - - _contentWritten = true; - _namespaces.reset(); - _namespaces.pushContext(); -} - - -void XMLWriter::endFragment() -{ - if (_depth > 1) - throw XMLException("Not well-formed (at least one tag has no matching end tag)"); - - _inFragment = false; - _elementCount = 0; - _depth = -1; -} - - -void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) -{ - static const AttributesImpl attributes; - startElement(namespaceURI, localName, qname, attributes); -} - - -void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) -{ - if (_depth == 0 && !_inFragment && _elementCount > 1) - throw XMLException("Not well-formed. Second root element found", nameToString(localName, qname)); - - if (_unclosedStartTag) closeStartTag(); - prettyPrint(); - writeStartElement(namespaceURI, localName, qname, attributes); - _elementStack.push_back(Name(qname, namespaceURI, localName)); - _contentWritten = false; - ++_depth; -} - - -void XMLWriter::endElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) -{ - if (_depth < 1) - throw XMLException("No unclosed tag"); - - if (!_elementStack.back().equalsWeakly(qname, namespaceURI, localName)) - throw XMLException("End tag does not match start tag", nameToString(localName, qname)); - - _elementStack.pop_back(); - --_depth; - if (!_unclosedStartTag) prettyPrint(); - writeEndElement(namespaceURI, localName, qname); - _contentWritten = false; - if (_depth == 0) - writeNewLine(); -} - - -void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) -{ - static const AttributesImpl attributes; - emptyElement(namespaceURI, localName, qname, attributes); -} - - -void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) -{ - if (_depth == 0 && _elementCount > 1) - throw XMLException("Not well-formed. Second root element found."); - - if (_unclosedStartTag) closeStartTag(); - prettyPrint(); - writeStartElement(namespaceURI, localName, qname, attributes); - _contentWritten = false; - writeMarkup("/"); - closeStartTag(); -} - - -void XMLWriter::characters(const XMLChar ch[], int start, int length) -{ - if (length == 0) return; - - if (_unclosedStartTag) closeStartTag(); - _contentWritten = _contentWritten || length > 0; - if (_inCDATA) - { - while (length-- > 0) writeXML(ch[start++]); - } - else - { - while (length-- > 0) - { - XMLChar c = ch[start++]; - switch (c) - { - case '"': writeMarkup(MARKUP_QUOTENC); break; - case '\'': writeMarkup(MARKUP_APOSENC); break; - case '&': writeMarkup(MARKUP_AMPENC); break; - case '<': writeMarkup(MARKUP_LTENC); break; - case '>': writeMarkup(MARKUP_GTENC); break; - default: - if (c >= 0 && c < 32) - { - if (c == '\t' || c == '\r' || c == '\n') - writeXML(c); - else - throw XMLException("Invalid character token."); - } - else writeXML(c); - } - } - } -} - - -void XMLWriter::characters(const XMLString& str) -{ - characters(str.data(), 0, (int) str.length()); -} - - -void XMLWriter::rawCharacters(const XMLString& str) -{ - if (_unclosedStartTag) closeStartTag(); - _contentWritten = _contentWritten || !str.empty(); - writeXML(str); -} - - -void XMLWriter::ignorableWhitespace(const XMLChar ch[], int start, int length) -{ - characters(ch, start, length); -} - - -void XMLWriter::processingInstruction(const XMLString& target, const XMLString& data) -{ - if (_unclosedStartTag) closeStartTag(); - prettyPrint(); - writeMarkup(""); - if (_depth == 0) - writeNewLine(); -} - - -void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, - const XMLString& data, - const XMLString& attr1, const XMLString& value1, - const XMLString& attr2, const XMLString& value2, - const XMLString& attr3, const XMLString& value3) -{ - static const XMLString CDATA = toXMLString("CDATA"); - - AttributesImpl attributes; - if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1); - if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2); - if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3); - if (data.empty()) - { - emptyElement(namespaceURI, localName, qname, attributes); - } - else - { - startElement(namespaceURI, localName, qname, attributes); - characters(data); - endElement(namespaceURI, localName, qname); - } -} - - -void XMLWriter::startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI) -{ - if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX) - _namespaces.declarePrefix(prefix, namespaceURI); -} - - -void XMLWriter::endPrefixMapping(const XMLString& prefix) -{ - if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX) - _namespaces.undeclarePrefix(prefix); -} - - -void XMLWriter::skippedEntity(const XMLString& name) -{ -} - - -void XMLWriter::startCDATA() -{ - if (_inCDATA) throw XMLException("Cannot nest CDATA sections"); - if (_unclosedStartTag) closeStartTag(); - _inCDATA = true; - writeMarkup(MARKUP_BEGIN_CDATA); -} - - -void XMLWriter::endCDATA() -{ - poco_assert (_inCDATA); - _inCDATA = false; - writeMarkup(MARKUP_END_CDATA); -} - - -void XMLWriter::comment(const XMLChar ch[], int start, int length) -{ - if (_unclosedStartTag) closeStartTag(); - prettyPrint(); - writeMarkup(""); - _contentWritten = false; -} - - -void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) -{ - writeMarkup(""); - writeNewLine(); - _inDTD = false; -} - - -void XMLWriter::startEntity(const XMLString& name) -{ -} - - -void XMLWriter::endEntity(const XMLString& name) -{ -} - - -void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) -{ - if (!_inDTD) throw XMLException("Notation declaration not within DTD"); - if (!_inInternalDTD) - { - writeMarkup(" ["); - _inInternalDTD = true; - } - if (_options & PRETTY_PRINT) - { - writeNewLine(); - writeMarkup(MARKUP_TAB); - } - writeMarkup("empty()) - { - writeMarkup(" SYSTEM \""); - writeXML(*systemId); - writeMarkup("\""); - } - if (publicId && !publicId->empty()) - { - writeMarkup(" PUBLIC \""); - writeXML(*publicId); - writeMarkup("\""); - } - writeMarkup(">"); -} - - -void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) -{ - if (!_inDTD) throw XMLException("Entity declaration not within DTD"); - if (!_inInternalDTD) - { - writeMarkup(" ["); - _inInternalDTD = true; - } - if (_options & PRETTY_PRINT) - { - writeNewLine(); - writeMarkup(MARKUP_TAB); - } - writeMarkup("empty()) - { - writeMarkup(" PUBLIC \""); - writeXML(*publicId); - writeMarkup("\""); - } - if (!notationName.empty()) - { - writeMarkup(" NDATA "); - writeXML(notationName); - } - writeMarkup(">"); -} - - -void XMLWriter::prettyPrint() const -{ - if ((_options & PRETTY_PRINT) && !_contentWritten) - { - writeNewLine(); - writeIndent(); - } -} - - -void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) -{ - ++_elementCount; - writeMarkup(MARKUP_LT); - if (!localName.empty() && (qname.empty() || localName == qname)) - { - XMLString prefix; - if (!namespaceURI.empty() && !_namespaces.isMapped(namespaceURI)) - { - prefix = newPrefix(); - _namespaces.declarePrefix(prefix, namespaceURI); - } - else prefix = _namespaces.getPrefix(namespaceURI); - writeName(prefix, localName); - } - else if (namespaceURI.empty() && localName.empty() && !qname.empty()) - { - writeXML(qname); - } - else if (!localName.empty() && !qname.empty()) - { - XMLString local; - XMLString prefix; - Name::split(qname, prefix, local); - if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI); - const XMLString& uri = _namespaces.getURI(prefix); - if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty()) - { - _namespaces.declarePrefix(prefix, namespaceURI); - } - writeName(prefix, localName); - } - else throw XMLException("Tag mismatch", nameToString(localName, qname)); - - declareAttributeNamespaces(attributes); - AttributeMap attributeMap; - addNamespaceAttributes(attributeMap); - addAttributes(attributeMap, attributes, namespaceURI); - writeAttributes(attributeMap); - _unclosedStartTag = true; - _namespaces.pushContext(); -} - - -void XMLWriter::writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) -{ - if (_unclosedStartTag) - { - writeMarkup(MARKUP_SLASHGT); - _unclosedStartTag = false; - } - else - { - writeMarkup(MARKUP_LTSLASH); - if (!localName.empty()) - { - XMLString prefix = _namespaces.getPrefix(namespaceURI); - writeName(prefix, localName); - } - else - { - writeXML(qname); - } - writeMarkup(MARKUP_GT); - } - _namespaces.popContext(); -} - - -void XMLWriter::closeStartTag() -{ - _unclosedStartTag = false; - writeMarkup(MARKUP_GT); -} - - -void XMLWriter::declareAttributeNamespaces(const Attributes& attributes) -{ - for (int i = 0; i < attributes.getLength(); i++) - { - XMLString namespaceURI = attributes.getURI(i); - XMLString localName = attributes.getLocalName(i); - XMLString qname = attributes.getQName(i); - if (!localName.empty()) - { - XMLString prefix; - XMLString splitLocalName; - Name::split(qname, prefix, splitLocalName); - if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI); - if (prefix.empty() && !namespaceURI.empty() && !_namespaces.isMapped(namespaceURI)) - { - prefix = newPrefix(); - _namespaces.declarePrefix(prefix, namespaceURI); - } - - - const XMLString& uri = _namespaces.getURI(prefix); - if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty()) - { - _namespaces.declarePrefix(prefix, namespaceURI); - } - } - } -} - - -void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap) -{ - NamespaceSupport::PrefixSet prefixes; - _namespaces.getDeclaredPrefixes(prefixes); - for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it) - { - XMLString prefix = *it; - XMLString uri = _namespaces.getURI(prefix); - XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX; - - if (!prefix.empty()) - { - qname.append(toXMLString(MARKUP_COLON)); - qname.append(prefix); - } - attributeMap[qname] = uri; - } -} - - -void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI) -{ - for (int i = 0; i < attributes.getLength(); i++) - { - XMLString namespaceURI = attributes.getURI(i); - XMLString localName = attributes.getLocalName(i); - XMLString qname = attributes.getQName(i); - if (!localName.empty()) - { - XMLString prefix; - if (namespaceURI != elementNamespaceURI) - prefix = _namespaces.getPrefix(namespaceURI); - if (!prefix.empty()) - { - qname = prefix; - qname.append(toXMLString(MARKUP_COLON)); - } - else qname.clear(); - qname.append(localName); - } - attributeMap[qname] = attributes.getValue(i); - } -} - - -void XMLWriter::writeAttributes(const AttributeMap& attributeMap) -{ - for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it) - { - writeMarkup(MARKUP_SPACE); - writeXML(it->first); - writeMarkup(MARKUP_EQQUOT); - characters(it->second); - writeMarkup(MARKUP_QUOT); - } -} - - -void XMLWriter::writeMarkup(const std::string& str) const -{ - _pTextConverter->write(str.data(), (int) str.size()); -} - - -void XMLWriter::writeXML(const XMLString& str) const -{ - _pTextConverter->write((const char*) str.data(), (int) str.size()*sizeof(XMLChar)); -} - - -void XMLWriter::writeXML(XMLChar ch) const -{ - _pTextConverter->write((const char*) &ch, sizeof(ch)); -} - - -void XMLWriter::writeName(const XMLString& prefix, const XMLString& localName) -{ - if (prefix.empty()) - { - writeXML(localName); - } - else - { - writeXML(prefix); - writeMarkup(MARKUP_COLON); - writeXML(localName); - } -} - - -void XMLWriter::writeNewLine() const -{ - if (_options & PRETTY_PRINT) - writeMarkup(_newLine); -} - - -void XMLWriter::writeIndent() const -{ - for (int i = 0; i < _depth; ++i) - writeMarkup(MARKUP_TAB); -} - - -void XMLWriter::writeXMLDeclaration() -{ - writeMarkup(""); - writeNewLine(); -} - - -std::string XMLWriter::nameToString(const XMLString& localName, const XMLString& qname) -{ - if (qname.empty()) - return fromXMLString(localName); - else - return fromXMLString(qname); -} - - -XMLString XMLWriter::newPrefix() -{ - std::ostringstream str; - str << "ns" << ++_prefix; - return toXMLString(str.str()); -} - - -} } // namespace Poco::XML +// +// XMLWriter.cpp +// +// $Id: //poco/1.3/XML/src/XMLWriter.cpp#2 $ +// +// Library: XML +// Package: XML +// Module: XMLWriter +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "Poco/XML/XMLWriter.h" +#include "Poco/XML/XMLString.h" +#include "Poco/XML/XMLException.h" +#include "Poco/SAX/AttributesImpl.h" +#include "Poco/UTF8Encoding.h" +#include "Poco/UTF16Encoding.h" +#include + + +namespace Poco { +namespace XML { + + +const std::string XMLWriter::NEWLINE_DEFAULT; +const std::string XMLWriter::NEWLINE_CR = "\r"; +const std::string XMLWriter::NEWLINE_CRLF = "\r\n"; +const std::string XMLWriter::NEWLINE_LF = "\n"; +const std::string XMLWriter::MARKUP_QUOTENC = """; +const std::string XMLWriter::MARKUP_APOSENC = "'"; +const std::string XMLWriter::MARKUP_AMPENC = "&"; +const std::string XMLWriter::MARKUP_LTENC = "<"; +const std::string XMLWriter::MARKUP_GTENC = ">"; +const std::string XMLWriter::MARKUP_LT = "<"; +const std::string XMLWriter::MARKUP_GT = ">"; +const std::string XMLWriter::MARKUP_SLASHGT = "/>"; +const std::string XMLWriter::MARKUP_LTSLASH = ""; + + +#if defined(XML_UNICODE_WCHAR_T) + #define NATIVE_ENCODING Poco::UTF16Encoding +#else + #define NATIVE_ENCODING Poco::UTF8Encoding +#endif + + +XMLWriter::XMLWriter(XMLByteOutputStream& str, int options): + _pTextConverter(0), + _pInEncoding(new NATIVE_ENCODING), + _pOutEncoding(new Poco::UTF8Encoding), + _options(options), + _encoding("UTF-8"), + _depth(-1), + _elementCount(0), + _inFragment(false), + _inCDATA(false), + _inDTD(false), + _inInternalDTD(false), + _contentWritten(false), + _unclosedStartTag(false), + _prefix(0) +{ + _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding); + setNewLine(NEWLINE_DEFAULT); +} + + +XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding& textEncoding): + _pTextConverter(0), + _pInEncoding(new NATIVE_ENCODING), + _pOutEncoding(0), + _options(options), + _encoding(encodingName), + _depth(-1), + _elementCount(0), + _inFragment(false), + _inCDATA(false), + _inDTD(false), + _inInternalDTD(false), + _contentWritten(false), + _unclosedStartTag(false), + _prefix(0) +{ + _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, textEncoding); + setNewLine(NEWLINE_DEFAULT); +} + + +XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& encodingName, Poco::TextEncoding* pTextEncoding): + _pTextConverter(0), + _pInEncoding(new NATIVE_ENCODING), + _pOutEncoding(0), + _options(options), + _encoding(encodingName), + _depth(-1), + _elementCount(0), + _inFragment(false), + _inCDATA(false), + _inDTD(false), + _inInternalDTD(false), + _contentWritten(false), + _unclosedStartTag(false), + _prefix(0) +{ + if (pTextEncoding) + { + _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *pTextEncoding); + } + else + { + _encoding = "UTF-8"; + _pOutEncoding = new Poco::UTF8Encoding; + _pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding); + } + setNewLine(NEWLINE_DEFAULT); +} + + +XMLWriter::~XMLWriter() +{ + delete _pTextConverter; + delete _pInEncoding; + delete _pOutEncoding; +} + + +void XMLWriter::setDocumentLocator(const Locator* loc) +{ +} + + +void XMLWriter::setNewLine(const std::string& newLineCharacters) +{ + if (newLineCharacters.empty()) + { +#if defined(_WIN32) + _newLine = NEWLINE_CRLF; +#else + _newLine = NEWLINE_LF; +#endif + } + else _newLine = newLineCharacters; +} + + +const std::string& XMLWriter::getNewLine() const +{ + return _newLine; +} + + +void XMLWriter::startDocument() +{ + if (_depth != -1) + throw XMLException("Cannot start a document in another document"); + + _inFragment = false; + _depth = 0; + _elementCount = 0; + _inDTD = false; + _inInternalDTD = false; + _prefix = 0; + + if (_options & WRITE_XML_DECLARATION) + writeXMLDeclaration(); + + _contentWritten = true; + _namespaces.reset(); + _namespaces.pushContext(); +} + + +void XMLWriter::endDocument() +{ + if (_depth > 0) + throw XMLException("Not well-formed (at least one tag has no matching end tag)"); + if (_elementCount == 0) + throw XMLException("No document element"); + + poco_assert_dbg (!_unclosedStartTag); + + _elementCount = 0; + _depth = -1; +} + + +void XMLWriter::startFragment() +{ + if (_depth != -1) + throw XMLException("Cannot start a fragment in another fragment or document"); + + _inFragment = true; + _depth = 0; + _elementCount = 0; + _prefix = 0; + + _contentWritten = true; + _namespaces.reset(); + _namespaces.pushContext(); +} + + +void XMLWriter::endFragment() +{ + if (_depth > 1) + throw XMLException("Not well-formed (at least one tag has no matching end tag)"); + + _inFragment = false; + _elementCount = 0; + _depth = -1; +} + + +void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) +{ + static const AttributesImpl attributes; + startElement(namespaceURI, localName, qname, attributes); +} + + +void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) +{ + if (_depth == 0 && !_inFragment && _elementCount > 1) + throw XMLException("Not well-formed. Second root element found", nameToString(localName, qname)); + + if (_unclosedStartTag) closeStartTag(); + prettyPrint(); + writeStartElement(namespaceURI, localName, qname, attributes); + _elementStack.push_back(Name(qname, namespaceURI, localName)); + _contentWritten = false; + ++_depth; +} + + +void XMLWriter::endElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) +{ + if (_depth < 1) + throw XMLException("No unclosed tag"); + + if (!_elementStack.back().equalsWeakly(qname, namespaceURI, localName)) + throw XMLException("End tag does not match start tag", nameToString(localName, qname)); + + _elementStack.pop_back(); + --_depth; + if (!_unclosedStartTag) prettyPrint(); + writeEndElement(namespaceURI, localName, qname); + _contentWritten = false; + if (_depth == 0) + writeNewLine(); +} + + +void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) +{ + static const AttributesImpl attributes; + emptyElement(namespaceURI, localName, qname, attributes); +} + + +void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) +{ + if (_depth == 0 && _elementCount > 1) + throw XMLException("Not well-formed. Second root element found."); + + if (_unclosedStartTag) closeStartTag(); + prettyPrint(); + writeStartElement(namespaceURI, localName, qname, attributes); + _contentWritten = false; + writeMarkup("/"); + closeStartTag(); +} + + +void XMLWriter::characters(const XMLChar ch[], int start, int length) +{ + if (length == 0) return; + + if (_unclosedStartTag) closeStartTag(); + _contentWritten = _contentWritten || length > 0; + if (_inCDATA) + { + while (length-- > 0) writeXML(ch[start++]); + } + else + { + while (length-- > 0) + { + XMLChar c = ch[start++]; + switch (c) + { + case '"': writeMarkup(MARKUP_QUOTENC); break; + case '\'': writeMarkup(MARKUP_APOSENC); break; + case '&': writeMarkup(MARKUP_AMPENC); break; + case '<': writeMarkup(MARKUP_LTENC); break; + case '>': writeMarkup(MARKUP_GTENC); break; + default: + if (c >= 0 && c < 32) + { + if (c == '\t' || c == '\r' || c == '\n') + writeXML(c); + else + throw XMLException("Invalid character token."); + } + else writeXML(c); + } + } + } +} + + +void XMLWriter::characters(const XMLString& str) +{ + characters(str.data(), 0, (int) str.length()); +} + + +void XMLWriter::rawCharacters(const XMLString& str) +{ + if (_unclosedStartTag) closeStartTag(); + _contentWritten = _contentWritten || !str.empty(); + writeXML(str); +} + + +void XMLWriter::ignorableWhitespace(const XMLChar ch[], int start, int length) +{ + characters(ch, start, length); +} + + +void XMLWriter::processingInstruction(const XMLString& target, const XMLString& data) +{ + if (_unclosedStartTag) closeStartTag(); + prettyPrint(); + writeMarkup(""); + if (_depth == 0) + writeNewLine(); +} + + +void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, + const XMLString& data, + const XMLString& attr1, const XMLString& value1, + const XMLString& attr2, const XMLString& value2, + const XMLString& attr3, const XMLString& value3) +{ + static const XMLString CDATA = toXMLString("CDATA"); + + AttributesImpl attributes; + if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1); + if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2); + if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3); + if (data.empty()) + { + emptyElement(namespaceURI, localName, qname, attributes); + } + else + { + startElement(namespaceURI, localName, qname, attributes); + characters(data); + endElement(namespaceURI, localName, qname); + } +} + + +void XMLWriter::startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI) +{ + if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX) + _namespaces.declarePrefix(prefix, namespaceURI); +} + + +void XMLWriter::endPrefixMapping(const XMLString& prefix) +{ + if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX) + _namespaces.undeclarePrefix(prefix); +} + + +void XMLWriter::skippedEntity(const XMLString& name) +{ +} + + +void XMLWriter::startCDATA() +{ + if (_inCDATA) throw XMLException("Cannot nest CDATA sections"); + if (_unclosedStartTag) closeStartTag(); + _inCDATA = true; + writeMarkup(MARKUP_BEGIN_CDATA); +} + + +void XMLWriter::endCDATA() +{ + poco_assert (_inCDATA); + _inCDATA = false; + writeMarkup(MARKUP_END_CDATA); +} + + +void XMLWriter::comment(const XMLChar ch[], int start, int length) +{ + if (_unclosedStartTag) closeStartTag(); + prettyPrint(); + writeMarkup(""); + _contentWritten = false; +} + + +void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) +{ + writeMarkup(""); + writeNewLine(); + _inDTD = false; +} + + +void XMLWriter::startEntity(const XMLString& name) +{ +} + + +void XMLWriter::endEntity(const XMLString& name) +{ +} + + +void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId) +{ + if (!_inDTD) throw XMLException("Notation declaration not within DTD"); + if (!_inInternalDTD) + { + writeMarkup(" ["); + _inInternalDTD = true; + } + if (_options & PRETTY_PRINT) + { + writeNewLine(); + writeMarkup(MARKUP_TAB); + } + writeMarkup("empty()) + { + writeMarkup(" SYSTEM \""); + writeXML(*systemId); + writeMarkup("\""); + } + if (publicId && !publicId->empty()) + { + writeMarkup(" PUBLIC \""); + writeXML(*publicId); + writeMarkup("\""); + } + writeMarkup(">"); +} + + +void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName) +{ + if (!_inDTD) throw XMLException("Entity declaration not within DTD"); + if (!_inInternalDTD) + { + writeMarkup(" ["); + _inInternalDTD = true; + } + if (_options & PRETTY_PRINT) + { + writeNewLine(); + writeMarkup(MARKUP_TAB); + } + writeMarkup("empty()) + { + writeMarkup(" PUBLIC \""); + writeXML(*publicId); + writeMarkup("\""); + } + if (!notationName.empty()) + { + writeMarkup(" NDATA "); + writeXML(notationName); + } + writeMarkup(">"); +} + + +void XMLWriter::prettyPrint() const +{ + if ((_options & PRETTY_PRINT) && !_contentWritten) + { + writeNewLine(); + writeIndent(); + } +} + + +void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes) +{ + ++_elementCount; + writeMarkup(MARKUP_LT); + if (!localName.empty() && (qname.empty() || localName == qname)) + { + XMLString prefix; + if (!namespaceURI.empty() && !_namespaces.isMapped(namespaceURI)) + { + prefix = newPrefix(); + _namespaces.declarePrefix(prefix, namespaceURI); + } + else prefix = _namespaces.getPrefix(namespaceURI); + writeName(prefix, localName); + } + else if (namespaceURI.empty() && localName.empty() && !qname.empty()) + { + writeXML(qname); + } + else if (!localName.empty() && !qname.empty()) + { + XMLString local; + XMLString prefix; + Name::split(qname, prefix, local); + if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI); + const XMLString& uri = _namespaces.getURI(prefix); + if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty()) + { + _namespaces.declarePrefix(prefix, namespaceURI); + } + writeName(prefix, localName); + } + else throw XMLException("Tag mismatch", nameToString(localName, qname)); + + declareAttributeNamespaces(attributes); + AttributeMap attributeMap; + addNamespaceAttributes(attributeMap); + addAttributes(attributeMap, attributes, namespaceURI); + writeAttributes(attributeMap); + _unclosedStartTag = true; + _namespaces.pushContext(); +} + + +void XMLWriter::writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname) +{ + if (_unclosedStartTag) + { + writeMarkup(MARKUP_SLASHGT); + _unclosedStartTag = false; + } + else + { + writeMarkup(MARKUP_LTSLASH); + if (!localName.empty()) + { + XMLString prefix = _namespaces.getPrefix(namespaceURI); + writeName(prefix, localName); + } + else + { + writeXML(qname); + } + writeMarkup(MARKUP_GT); + } + _namespaces.popContext(); +} + + +void XMLWriter::closeStartTag() +{ + _unclosedStartTag = false; + writeMarkup(MARKUP_GT); +} + + +void XMLWriter::declareAttributeNamespaces(const Attributes& attributes) +{ + for (int i = 0; i < attributes.getLength(); i++) + { + XMLString namespaceURI = attributes.getURI(i); + XMLString localName = attributes.getLocalName(i); + XMLString qname = attributes.getQName(i); + if (!localName.empty()) + { + XMLString prefix; + XMLString splitLocalName; + Name::split(qname, prefix, splitLocalName); + if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI); + if (prefix.empty() && !namespaceURI.empty() && !_namespaces.isMapped(namespaceURI)) + { + prefix = newPrefix(); + _namespaces.declarePrefix(prefix, namespaceURI); + } + + + const XMLString& uri = _namespaces.getURI(prefix); + if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty()) + { + _namespaces.declarePrefix(prefix, namespaceURI); + } + } + } +} + + +void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap) +{ + NamespaceSupport::PrefixSet prefixes; + _namespaces.getDeclaredPrefixes(prefixes); + for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it) + { + XMLString prefix = *it; + XMLString uri = _namespaces.getURI(prefix); + XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX; + + if (!prefix.empty()) + { + qname.append(toXMLString(MARKUP_COLON)); + qname.append(prefix); + } + attributeMap[qname] = uri; + } +} + + +void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI) +{ + for (int i = 0; i < attributes.getLength(); i++) + { + XMLString namespaceURI = attributes.getURI(i); + XMLString localName = attributes.getLocalName(i); + XMLString qname = attributes.getQName(i); + if (!localName.empty()) + { + XMLString prefix; + if (namespaceURI != elementNamespaceURI) + prefix = _namespaces.getPrefix(namespaceURI); + if (!prefix.empty()) + { + qname = prefix; + qname.append(toXMLString(MARKUP_COLON)); + } + else qname.clear(); + qname.append(localName); + } + attributeMap[qname] = attributes.getValue(i); + } +} + + +void XMLWriter::writeAttributes(const AttributeMap& attributeMap) +{ + for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it) + { + writeMarkup(MARKUP_SPACE); + writeXML(it->first); + writeMarkup(MARKUP_EQQUOT); + characters(it->second); + writeMarkup(MARKUP_QUOT); + } +} + + +void XMLWriter::writeMarkup(const std::string& str) const +{ + _pTextConverter->write(str.data(), (int) str.size()); +} + + +void XMLWriter::writeXML(const XMLString& str) const +{ + _pTextConverter->write((const char*) str.data(), (int) str.size()*sizeof(XMLChar)); +} + + +void XMLWriter::writeXML(XMLChar ch) const +{ + _pTextConverter->write((const char*) &ch, sizeof(ch)); +} + + +void XMLWriter::writeName(const XMLString& prefix, const XMLString& localName) +{ + if (prefix.empty()) + { + writeXML(localName); + } + else + { + writeXML(prefix); + writeMarkup(MARKUP_COLON); + writeXML(localName); + } +} + + +void XMLWriter::writeNewLine() const +{ + if (_options & PRETTY_PRINT) + writeMarkup(_newLine); +} + + +void XMLWriter::writeIndent() const +{ + for (int i = 0; i < _depth; ++i) + writeMarkup(MARKUP_TAB); +} + + +void XMLWriter::writeXMLDeclaration() +{ + writeMarkup(""); + writeNewLine(); +} + + +std::string XMLWriter::nameToString(const XMLString& localName, const XMLString& qname) +{ + if (qname.empty()) + return fromXMLString(localName); + else + return fromXMLString(qname); +} + + +XMLString XMLWriter::newPrefix() +{ + std::ostringstream str; + str << "ns" << ++_prefix; + return toXMLString(str.str()); +} + + +} } // namespace Poco::XML diff --git a/XML/src/ascii.h b/XML/src/ascii.h index 73b2712dd..d10530b09 100644 --- a/XML/src/ascii.h +++ b/XML/src/ascii.h @@ -1,92 +1,92 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#define ASCII_A 0x41 -#define ASCII_B 0x42 -#define ASCII_C 0x43 -#define ASCII_D 0x44 -#define ASCII_E 0x45 -#define ASCII_F 0x46 -#define ASCII_G 0x47 -#define ASCII_H 0x48 -#define ASCII_I 0x49 -#define ASCII_J 0x4A -#define ASCII_K 0x4B -#define ASCII_L 0x4C -#define ASCII_M 0x4D -#define ASCII_N 0x4E -#define ASCII_O 0x4F -#define ASCII_P 0x50 -#define ASCII_Q 0x51 -#define ASCII_R 0x52 -#define ASCII_S 0x53 -#define ASCII_T 0x54 -#define ASCII_U 0x55 -#define ASCII_V 0x56 -#define ASCII_W 0x57 -#define ASCII_X 0x58 -#define ASCII_Y 0x59 -#define ASCII_Z 0x5A - -#define ASCII_a 0x61 -#define ASCII_b 0x62 -#define ASCII_c 0x63 -#define ASCII_d 0x64 -#define ASCII_e 0x65 -#define ASCII_f 0x66 -#define ASCII_g 0x67 -#define ASCII_h 0x68 -#define ASCII_i 0x69 -#define ASCII_j 0x6A -#define ASCII_k 0x6B -#define ASCII_l 0x6C -#define ASCII_m 0x6D -#define ASCII_n 0x6E -#define ASCII_o 0x6F -#define ASCII_p 0x70 -#define ASCII_q 0x71 -#define ASCII_r 0x72 -#define ASCII_s 0x73 -#define ASCII_t 0x74 -#define ASCII_u 0x75 -#define ASCII_v 0x76 -#define ASCII_w 0x77 -#define ASCII_x 0x78 -#define ASCII_y 0x79 -#define ASCII_z 0x7A - -#define ASCII_0 0x30 -#define ASCII_1 0x31 -#define ASCII_2 0x32 -#define ASCII_3 0x33 -#define ASCII_4 0x34 -#define ASCII_5 0x35 -#define ASCII_6 0x36 -#define ASCII_7 0x37 -#define ASCII_8 0x38 -#define ASCII_9 0x39 - -#define ASCII_TAB 0x09 -#define ASCII_SPACE 0x20 -#define ASCII_EXCL 0x21 -#define ASCII_QUOT 0x22 -#define ASCII_AMP 0x26 -#define ASCII_APOS 0x27 -#define ASCII_MINUS 0x2D -#define ASCII_PERIOD 0x2E -#define ASCII_COLON 0x3A -#define ASCII_SEMI 0x3B -#define ASCII_LT 0x3C -#define ASCII_EQUALS 0x3D -#define ASCII_GT 0x3E -#define ASCII_LSQB 0x5B -#define ASCII_RSQB 0x5D -#define ASCII_UNDERSCORE 0x5F -#define ASCII_LPAREN 0x28 -#define ASCII_RPAREN 0x29 -#define ASCII_FF 0x0C -#define ASCII_SLASH 0x2F -#define ASCII_HASH 0x23 -#define ASCII_PIPE 0x7C -#define ASCII_COMMA 0x2C +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#define ASCII_A 0x41 +#define ASCII_B 0x42 +#define ASCII_C 0x43 +#define ASCII_D 0x44 +#define ASCII_E 0x45 +#define ASCII_F 0x46 +#define ASCII_G 0x47 +#define ASCII_H 0x48 +#define ASCII_I 0x49 +#define ASCII_J 0x4A +#define ASCII_K 0x4B +#define ASCII_L 0x4C +#define ASCII_M 0x4D +#define ASCII_N 0x4E +#define ASCII_O 0x4F +#define ASCII_P 0x50 +#define ASCII_Q 0x51 +#define ASCII_R 0x52 +#define ASCII_S 0x53 +#define ASCII_T 0x54 +#define ASCII_U 0x55 +#define ASCII_V 0x56 +#define ASCII_W 0x57 +#define ASCII_X 0x58 +#define ASCII_Y 0x59 +#define ASCII_Z 0x5A + +#define ASCII_a 0x61 +#define ASCII_b 0x62 +#define ASCII_c 0x63 +#define ASCII_d 0x64 +#define ASCII_e 0x65 +#define ASCII_f 0x66 +#define ASCII_g 0x67 +#define ASCII_h 0x68 +#define ASCII_i 0x69 +#define ASCII_j 0x6A +#define ASCII_k 0x6B +#define ASCII_l 0x6C +#define ASCII_m 0x6D +#define ASCII_n 0x6E +#define ASCII_o 0x6F +#define ASCII_p 0x70 +#define ASCII_q 0x71 +#define ASCII_r 0x72 +#define ASCII_s 0x73 +#define ASCII_t 0x74 +#define ASCII_u 0x75 +#define ASCII_v 0x76 +#define ASCII_w 0x77 +#define ASCII_x 0x78 +#define ASCII_y 0x79 +#define ASCII_z 0x7A + +#define ASCII_0 0x30 +#define ASCII_1 0x31 +#define ASCII_2 0x32 +#define ASCII_3 0x33 +#define ASCII_4 0x34 +#define ASCII_5 0x35 +#define ASCII_6 0x36 +#define ASCII_7 0x37 +#define ASCII_8 0x38 +#define ASCII_9 0x39 + +#define ASCII_TAB 0x09 +#define ASCII_SPACE 0x20 +#define ASCII_EXCL 0x21 +#define ASCII_QUOT 0x22 +#define ASCII_AMP 0x26 +#define ASCII_APOS 0x27 +#define ASCII_MINUS 0x2D +#define ASCII_PERIOD 0x2E +#define ASCII_COLON 0x3A +#define ASCII_SEMI 0x3B +#define ASCII_LT 0x3C +#define ASCII_EQUALS 0x3D +#define ASCII_GT 0x3E +#define ASCII_LSQB 0x5B +#define ASCII_RSQB 0x5D +#define ASCII_UNDERSCORE 0x5F +#define ASCII_LPAREN 0x28 +#define ASCII_RPAREN 0x29 +#define ASCII_FF 0x0C +#define ASCII_SLASH 0x2F +#define ASCII_HASH 0x23 +#define ASCII_PIPE 0x7C +#define ASCII_COMMA 0x2C diff --git a/XML/src/asciitab.h b/XML/src/asciitab.h index 2ef65c79b..79a15c28c 100644 --- a/XML/src/asciitab.h +++ b/XML/src/asciitab.h @@ -1,36 +1,36 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, -/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, -/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, -/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, -/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, -/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, -/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, -/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, -/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, -/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, -/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/XML/src/expat_config.h b/XML/src/expat_config.h index 7d5e4aaf5..c649e91fb 100644 --- a/XML/src/expat_config.h +++ b/XML/src/expat_config.h @@ -1,59 +1,59 @@ -// -// expat_config.h -// -// $Id: //poco/1.3/XML/src/expat_config.h#1 $ -// -// Poco XML specific configuration for expat. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef EXPAT_CONFIG_H -#define EXPAT_CONFIG_H - - -#include "Poco/Platform.h" - - -#include -#include - - -#define XML_CONTEXT_BYTES 1024 - - -#if defined POCO_ARCH_LITTLE_ENDIAN -#define BYTEORDER 1234 -#else -#define BYTEORDER 4321 -#endif - - -#define HAVE_MEMMOVE - - -#endif /* EXPAT_CONFIG_H */ +// +// expat_config.h +// +// $Id: //poco/1.3/XML/src/expat_config.h#1 $ +// +// Poco XML specific configuration for expat. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef EXPAT_CONFIG_H +#define EXPAT_CONFIG_H + + +#include "Poco/Platform.h" + + +#include +#include + + +#define XML_CONTEXT_BYTES 1024 + + +#if defined POCO_ARCH_LITTLE_ENDIAN +#define BYTEORDER 1234 +#else +#define BYTEORDER 4321 +#endif + + +#define HAVE_MEMMOVE + + +#endif /* EXPAT_CONFIG_H */ diff --git a/XML/src/iasciitab.h b/XML/src/iasciitab.h index 980686f14..24a1d5ccc 100644 --- a/XML/src/iasciitab.h +++ b/XML/src/iasciitab.h @@ -1,37 +1,37 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */ -/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, -/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, -/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, -/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, -/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, -/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, -/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, -/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, -/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, -/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, -/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */ +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/XML/src/internal.h b/XML/src/internal.h index 3da3b789c..dd5454831 100644 --- a/XML/src/internal.h +++ b/XML/src/internal.h @@ -1,73 +1,73 @@ -/* internal.h - - Internal definitions used by Expat. This is not needed to compile - client code. - - The following calling convention macros are defined for frequently - called functions: - - FASTCALL - Used for those internal functions that have a simple - body and a low number of arguments and local variables. - - PTRCALL - Used for functions called though function pointers. - - PTRFASTCALL - Like PTRCALL, but for low number of arguments. - - inline - Used for selected internal functions for which inlining - may improve performance on some platforms. - - Note: Use of these macros is based on judgement, not hard rules, - and therefore subject to change. -*/ - -#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__) -/* We'll use this version by default only where we know it helps. - - regparm() generates warnings on Solaris boxes. See SF bug #692878. - - Instability reported with egcs on a RedHat Linux 7.3. - Let's comment out: - #define FASTCALL __attribute__((stdcall, regparm(3))) - and let's try this: -*/ -#define FASTCALL __attribute__((regparm(3))) -#define PTRFASTCALL __attribute__((regparm(3))) -#endif - -/* Using __fastcall seems to have an unexpected negative effect under - MS VC++, especially for function pointers, so we won't use it for - now on that platform. It may be reconsidered for a future release - if it can be made more effective. - Likely reason: __fastcall on Windows is like stdcall, therefore - the compiler cannot perform stack optimizations for call clusters. -*/ - -/* Make sure all of these are defined if they aren't already. */ - -#ifndef FASTCALL -#define FASTCALL -#endif - -#ifndef PTRCALL -#define PTRCALL -#endif - -#ifndef PTRFASTCALL -#define PTRFASTCALL -#endif - -#ifndef XML_MIN_SIZE -#if !defined(__cplusplus) && !defined(inline) -#ifdef __GNUC__ -#define inline __inline -#endif /* __GNUC__ */ -#endif -#endif /* XML_MIN_SIZE */ - -#ifdef __cplusplus -#define inline inline -#else -#ifndef inline -#define inline -#endif -#endif +/* internal.h + + Internal definitions used by Expat. This is not needed to compile + client code. + + The following calling convention macros are defined for frequently + called functions: + + FASTCALL - Used for those internal functions that have a simple + body and a low number of arguments and local variables. + + PTRCALL - Used for functions called though function pointers. + + PTRFASTCALL - Like PTRCALL, but for low number of arguments. + + inline - Used for selected internal functions for which inlining + may improve performance on some platforms. + + Note: Use of these macros is based on judgement, not hard rules, + and therefore subject to change. +*/ + +#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__) +/* We'll use this version by default only where we know it helps. + + regparm() generates warnings on Solaris boxes. See SF bug #692878. + + Instability reported with egcs on a RedHat Linux 7.3. + Let's comment out: + #define FASTCALL __attribute__((stdcall, regparm(3))) + and let's try this: +*/ +#define FASTCALL __attribute__((regparm(3))) +#define PTRFASTCALL __attribute__((regparm(3))) +#endif + +/* Using __fastcall seems to have an unexpected negative effect under + MS VC++, especially for function pointers, so we won't use it for + now on that platform. It may be reconsidered for a future release + if it can be made more effective. + Likely reason: __fastcall on Windows is like stdcall, therefore + the compiler cannot perform stack optimizations for call clusters. +*/ + +/* Make sure all of these are defined if they aren't already. */ + +#ifndef FASTCALL +#define FASTCALL +#endif + +#ifndef PTRCALL +#define PTRCALL +#endif + +#ifndef PTRFASTCALL +#define PTRFASTCALL +#endif + +#ifndef XML_MIN_SIZE +#if !defined(__cplusplus) && !defined(inline) +#ifdef __GNUC__ +#define inline __inline +#endif /* __GNUC__ */ +#endif +#endif /* XML_MIN_SIZE */ + +#ifdef __cplusplus +#define inline inline +#else +#ifndef inline +#define inline +#endif +#endif diff --git a/XML/src/latin1tab.h b/XML/src/latin1tab.h index 0c5b1ca0c..53c25d76b 100644 --- a/XML/src/latin1tab.h +++ b/XML/src/latin1tab.h @@ -1,36 +1,36 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, -/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, -/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, -/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, +/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, diff --git a/XML/src/nametab.h b/XML/src/nametab.h index adea34c56..b05e62c77 100644 --- a/XML/src/nametab.h +++ b/XML/src/nametab.h @@ -1,150 +1,150 @@ -static const unsigned namingBitmap[] = { -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE, -0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, -0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF, -0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, -0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, -0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, -0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, -0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, -0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, -0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000, -0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, -0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, -0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003, -0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, -0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, -0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003, -0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, -0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, -0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003, -0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000, -0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, -0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, -0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB, -0x40000000, 0xF580C900, 0x00000007, 0x02010800, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, -0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, -0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, -0x00000000, 0x00004C40, 0x00000000, 0x00000000, -0x00000007, 0x00000000, 0x00000000, 0x00000000, -0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, -0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF, -0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, -0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, -0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, -0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, -0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, -0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, -0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, -0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, -0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, -0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, -0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, -0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF, -0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, -0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, -0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, -0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, -0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, -0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, -0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, -0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, -0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, -0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000, -0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, -0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, -0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, -0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF, -}; -static const unsigned char nmstrtPages[] = { -0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, -0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, -0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, -0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; -static const unsigned char namePages[] = { -0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, -0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, -0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, -0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; +static const unsigned namingBitmap[] = { +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, +0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000, +0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, +0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, +0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003, +0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, +0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, +0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003, +0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, +0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, +0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003, +0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000, +0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, +0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, +0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB, +0x40000000, 0xF580C900, 0x00000007, 0x02010800, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, +0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, +0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, +0x00000000, 0x00004C40, 0x00000000, 0x00000000, +0x00000007, 0x00000000, 0x00000000, 0x00000000, +0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, +0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF, +0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, +0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, +0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, +0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF, +0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, +0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, +0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, +0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, +0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, +0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, +0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, +0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000, +0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, +0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, +0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, +0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF, +}; +static const unsigned char nmstrtPages[] = { +0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, +0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static const unsigned char namePages[] = { +0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, +0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/XML/src/utf8tab.h b/XML/src/utf8tab.h index 341960131..7bb3e7760 100644 --- a/XML/src/utf8tab.h +++ b/XML/src/utf8tab.h @@ -1,37 +1,37 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - - -/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, -/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + + +/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, +/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, diff --git a/XML/src/xmlparse.cpp b/XML/src/xmlparse.cpp index 8eb0d800f..da100284b 100644 --- a/XML/src/xmlparse.cpp +++ b/XML/src/xmlparse.cpp @@ -1,6287 +1,6287 @@ -/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#include -#include /* memset(), memcpy() */ -#include - -#define XML_BUILDING_EXPAT 1 - -#ifdef COMPILED_FROM_DSP -#include "winconfig.h" -#elif defined(MACOS_CLASSIC) -#include "macconfig.h" -#elif defined(__amigaos4__) -#include "amigaconfig.h" -#elif defined(__WATCOMC__) -#include "watcomconfig.h" -#elif defined(HAVE_EXPAT_CONFIG_H) -#include "expat_config.h" -#endif /* ndef COMPILED_FROM_DSP */ - -#include "ascii.h" -#include "Poco/XML/expat.h" - -#ifdef XML_UNICODE -#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX -#define XmlConvert XmlUtf16Convert -#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding -#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS -#define XmlEncode XmlUtf16Encode -/* Using pointer subtraction to convert to integer type. */ -#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) -typedef unsigned short ICHAR; -#else -#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX -#define XmlConvert XmlUtf8Convert -#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding -#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS -#define XmlEncode XmlUtf8Encode -#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) -typedef char ICHAR; -#endif - - -#ifndef XML_NS - -#define XmlInitEncodingNS XmlInitEncoding -#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding -#undef XmlGetInternalEncodingNS -#define XmlGetInternalEncodingNS XmlGetInternalEncoding -#define XmlParseXmlDeclNS XmlParseXmlDecl - -#endif - -#ifdef XML_UNICODE - -#ifdef XML_UNICODE_WCHAR_T -#define XML_T(x) (const wchar_t)x -#define XML_L(x) L ## x -#else -#define XML_T(x) (const unsigned short)x -#define XML_L(x) x -#endif - -#else - -#define XML_T(x) x -#define XML_L(x) x - -#endif - -/* Round up n to be a multiple of sz, where sz is a power of 2. */ -#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) - -/* Handle the case where memmove() doesn't exist. */ -#ifndef HAVE_MEMMOVE -#ifdef HAVE_BCOPY -#define memmove(d,s,l) bcopy((s),(d),(l)) -#else -#error memmove does not exist on this platform, nor is a substitute available -#endif /* HAVE_BCOPY */ -#endif /* HAVE_MEMMOVE */ - -#include "internal.h" -#include "xmltok.h" -#include "xmlrole.h" - -typedef const XML_Char *KEY; - -typedef struct { - KEY name; -} NAMED; - -typedef struct { - NAMED **v; - unsigned char power; - size_t size; - size_t used; - const XML_Memory_Handling_Suite *mem; -} HASH_TABLE; - -/* Basic character hash algorithm, taken from Python's string hash: - h = h * 1000003 ^ character, the constant being a prime number. - -*/ -#ifdef XML_UNICODE -#define CHAR_HASH(h, c) \ - (((h) * 0xF4243) ^ (unsigned short)(c)) -#else -#define CHAR_HASH(h, c) \ - (((h) * 0xF4243) ^ (unsigned char)(c)) -#endif - -/* For probing (after a collision) we need a step size relative prime - to the hash table size, which is a power of 2. We use double-hashing, - since we can calculate a second hash value cheaply by taking those bits - of the first hash value that were discarded (masked out) when the table - index was calculated: index = hash & mask, where mask = table->size - 1. - We limit the maximum step size to table->size / 4 (mask >> 2) and make - it odd, since odd numbers are always relative prime to a power of 2. -*/ -#define SECOND_HASH(hash, mask, power) \ - ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) -#define PROBE_STEP(hash, mask, power) \ - ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) - -typedef struct { - NAMED **p; - NAMED **end; -} HASH_TABLE_ITER; - -#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ -#define INIT_DATA_BUF_SIZE 1024 -#define INIT_ATTS_SIZE 16 -#define INIT_ATTS_VERSION 0xFFFFFFFF -#define INIT_BLOCK_SIZE 1024 -#define INIT_BUFFER_SIZE 1024 - -#define EXPAND_SPARE 24 - -typedef struct binding { - struct prefix *prefix; - struct binding *nextTagBinding; - struct binding *prevPrefixBinding; - const struct attribute_id *attId; - XML_Char *uri; - int uriLen; - int uriAlloc; -} BINDING; - -typedef struct prefix { - const XML_Char *name; - BINDING *binding; -} PREFIX; - -typedef struct { - const XML_Char *str; - const XML_Char *localPart; - const XML_Char *prefix; - int strLen; - int uriLen; - int prefixLen; -} TAG_NAME; - -/* TAG represents an open element. - The name of the element is stored in both the document and API - encodings. The memory buffer 'buf' is a separately-allocated - memory area which stores the name. During the XML_Parse()/ - XMLParseBuffer() when the element is open, the memory for the 'raw' - version of the name (in the document encoding) is shared with the - document buffer. If the element is open across calls to - XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to - contain the 'raw' name as well. - - A parser re-uses these structures, maintaining a list of allocated - TAG objects in a free list. -*/ -typedef struct tag { - struct tag *parent; /* parent of this element */ - const char *rawName; /* tagName in the original encoding */ - int rawNameLength; - TAG_NAME name; /* tagName in the API encoding */ - char *buf; /* buffer for name components */ - char *bufEnd; /* end of the buffer */ - BINDING *bindings; -} TAG; - -typedef struct { - const XML_Char *name; - const XML_Char *textPtr; - int textLen; /* length in XML_Chars */ - int processed; /* # of processed bytes - when suspended */ - const XML_Char *systemId; - const XML_Char *base; - const XML_Char *publicId; - const XML_Char *notation; - XML_Bool open; - XML_Bool is_param; - XML_Bool is_internal; /* true if declared in internal subset outside PE */ -} ENTITY; - -typedef struct { - enum XML_Content_Type type; - enum XML_Content_Quant quant; - const XML_Char * name; - int firstchild; - int lastchild; - int childcnt; - int nextsib; -} CONTENT_SCAFFOLD; - -#define INIT_SCAFFOLD_ELEMENTS 32 - -typedef struct block { - struct block *next; - int size; - XML_Char s[1]; -} BLOCK; - -typedef struct { - BLOCK *blocks; - BLOCK *freeBlocks; - const XML_Char *end; - XML_Char *ptr; - XML_Char *start; - const XML_Memory_Handling_Suite *mem; -} STRING_POOL; - -/* The XML_Char before the name is used to determine whether - an attribute has been specified. */ -typedef struct attribute_id { - XML_Char *name; - PREFIX *prefix; - XML_Bool maybeTokenized; - XML_Bool xmlns; -} ATTRIBUTE_ID; - -typedef struct { - const ATTRIBUTE_ID *id; - XML_Bool isCdata; - const XML_Char *value; -} DEFAULT_ATTRIBUTE; - -typedef struct { - unsigned long version; - unsigned long hash; - const XML_Char *uriName; -} NS_ATT; - -typedef struct { - const XML_Char *name; - PREFIX *prefix; - const ATTRIBUTE_ID *idAtt; - int nDefaultAtts; - int allocDefaultAtts; - DEFAULT_ATTRIBUTE *defaultAtts; -} ELEMENT_TYPE; - -typedef struct { - HASH_TABLE generalEntities; - HASH_TABLE elementTypes; - HASH_TABLE attributeIds; - HASH_TABLE prefixes; - STRING_POOL pool; - STRING_POOL entityValuePool; - /* false once a parameter entity reference has been skipped */ - XML_Bool keepProcessing; - /* true once an internal or external PE reference has been encountered; - this includes the reference to an external subset */ - XML_Bool hasParamEntityRefs; - XML_Bool standalone; -#ifdef XML_DTD - /* indicates if external PE has been read */ - XML_Bool paramEntityRead; - HASH_TABLE paramEntities; -#endif /* XML_DTD */ - PREFIX defaultPrefix; - /* === scaffolding for building content model === */ - XML_Bool in_eldecl; - CONTENT_SCAFFOLD *scaffold; - unsigned contentStringLen; - unsigned scaffSize; - unsigned scaffCount; - int scaffLevel; - int *scaffIndex; -} DTD; - -typedef struct open_internal_entity { - const char *internalEventPtr; - const char *internalEventEndPtr; - struct open_internal_entity *next; - ENTITY *entity; - int startTagLevel; - XML_Bool betweenDecl; /* WFC: PE Between Declarations */ -} OPEN_INTERNAL_ENTITY; - -typedef enum XML_Error PTRCALL Processor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr); - -static Processor prologProcessor; -static Processor prologInitProcessor; -static Processor contentProcessor; -static Processor cdataSectionProcessor; -#ifdef XML_DTD -static Processor ignoreSectionProcessor; -static Processor externalParEntProcessor; -static Processor externalParEntInitProcessor; -static Processor entityValueProcessor; -static Processor entityValueInitProcessor; -#endif /* XML_DTD */ -static Processor epilogProcessor; -static Processor errorProcessor; -static Processor externalEntityInitProcessor; -static Processor externalEntityInitProcessor2; -static Processor externalEntityInitProcessor3; -static Processor externalEntityContentProcessor; -static Processor internalEntityProcessor; - -static enum XML_Error -handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); -static enum XML_Error -processXmlDecl(XML_Parser parser, int isGeneralTextEntity, - const char *s, const char *next); -static enum XML_Error -initializeEncoding(XML_Parser parser); -static enum XML_Error -doProlog(XML_Parser parser, const ENCODING *enc, const char *s, - const char *end, int tok, const char *next, const char **nextPtr, - XML_Bool haveMore); -static enum XML_Error -processInternalEntity(XML_Parser parser, ENTITY *entity, - XML_Bool betweenDecl); -static enum XML_Error -doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, - const char *start, const char *end, const char **endPtr, - XML_Bool haveMore); -static enum XML_Error -doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, - const char *end, const char **nextPtr, XML_Bool haveMore); -#ifdef XML_DTD -static enum XML_Error -doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, - const char *end, const char **nextPtr, XML_Bool haveMore); -#endif /* XML_DTD */ - -static enum XML_Error -storeAtts(XML_Parser parser, const ENCODING *, const char *s, - TAG_NAME *tagNamePtr, BINDING **bindingsPtr); -static enum XML_Error -addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, - const XML_Char *uri, BINDING **bindingsPtr); -static int -defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, - XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); -static enum XML_Error -storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, - const char *, const char *, STRING_POOL *); -static enum XML_Error -appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, - const char *, const char *, STRING_POOL *); -static ATTRIBUTE_ID * -getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static int -setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); -static enum XML_Error -storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static int -reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end); -static int -reportComment(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static void -reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); - -static const XML_Char * getContext(XML_Parser parser); -static XML_Bool -setContext(XML_Parser parser, const XML_Char *context); - -static void FASTCALL normalizePublicId(XML_Char *s); - -static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); -/* do not call if parentParser != NULL */ -static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); -static void -dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); -static int -dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); -static int -copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); - -static NAMED * -lookup(HASH_TABLE *table, KEY name, size_t createSize); -static void FASTCALL -hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); -static void FASTCALL hashTableClear(HASH_TABLE *); -static void FASTCALL hashTableDestroy(HASH_TABLE *); -static void FASTCALL -hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); -static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); - -static void FASTCALL -poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); -static void FASTCALL poolClear(STRING_POOL *); -static void FASTCALL poolDestroy(STRING_POOL *); -static XML_Char * -poolAppend(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end); -static XML_Char * -poolStoreString(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end); -static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); -static const XML_Char * FASTCALL -poolCopyString(STRING_POOL *pool, const XML_Char *s); -static const XML_Char * -poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); -static const XML_Char * FASTCALL -poolAppendString(STRING_POOL *pool, const XML_Char *s); - -static int FASTCALL nextScaffoldPart(XML_Parser parser); -static XML_Content * build_model(XML_Parser parser); -static ELEMENT_TYPE * -getElementType(XML_Parser parser, const ENCODING *enc, - const char *ptr, const char *end); - -static XML_Parser -parserCreate(const XML_Char *encodingName, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep, - DTD *dtd); -static void -parserInit(XML_Parser parser, const XML_Char *encodingName); - -#define poolStart(pool) ((pool)->start) -#define poolEnd(pool) ((pool)->ptr) -#define poolLength(pool) ((pool)->ptr - (pool)->start) -#define poolChop(pool) ((void)--(pool->ptr)) -#define poolLastChar(pool) (((pool)->ptr)[-1]) -#define poolDiscard(pool) ((pool)->ptr = (pool)->start) -#define poolFinish(pool) ((pool)->start = (pool)->ptr) -#define poolAppendChar(pool, c) \ - (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ - ? 0 \ - : ((*((pool)->ptr)++ = c), 1)) - -struct XML_ParserStruct { - /* The first member must be userData so that the XML_GetUserData - macro works. */ - void *m_userData; - void *m_handlerArg; - char *m_buffer; - const XML_Memory_Handling_Suite m_mem; - /* first character to be parsed */ - const char *m_bufferPtr; - /* past last character to be parsed */ - char *m_bufferEnd; - /* allocated end of buffer */ - const char *m_bufferLim; - XML_Index m_parseEndByteIndex; - const char *m_parseEndPtr; - XML_Char *m_dataBuf; - XML_Char *m_dataBufEnd; - XML_StartElementHandler m_startElementHandler; - XML_EndElementHandler m_endElementHandler; - XML_CharacterDataHandler m_characterDataHandler; - XML_ProcessingInstructionHandler m_processingInstructionHandler; - XML_CommentHandler m_commentHandler; - XML_StartCdataSectionHandler m_startCdataSectionHandler; - XML_EndCdataSectionHandler m_endCdataSectionHandler; - XML_DefaultHandler m_defaultHandler; - XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; - XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; - XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; - XML_NotationDeclHandler m_notationDeclHandler; - XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; - XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; - XML_NotStandaloneHandler m_notStandaloneHandler; - XML_ExternalEntityRefHandler m_externalEntityRefHandler; - XML_Parser m_externalEntityRefHandlerArg; - XML_SkippedEntityHandler m_skippedEntityHandler; - XML_UnknownEncodingHandler m_unknownEncodingHandler; - XML_ElementDeclHandler m_elementDeclHandler; - XML_AttlistDeclHandler m_attlistDeclHandler; - XML_EntityDeclHandler m_entityDeclHandler; - XML_XmlDeclHandler m_xmlDeclHandler; - const ENCODING *m_encoding; - INIT_ENCODING m_initEncoding; - const ENCODING *m_internalEncoding; - const XML_Char *m_protocolEncodingName; - XML_Bool m_ns; - XML_Bool m_ns_triplets; - void *m_unknownEncodingMem; - void *m_unknownEncodingData; - void *m_unknownEncodingHandlerData; - void (XMLCALL *m_unknownEncodingRelease)(void *); - PROLOG_STATE m_prologState; - Processor *m_processor; - enum XML_Error m_errorCode; - const char *m_eventPtr; - const char *m_eventEndPtr; - const char *m_positionPtr; - OPEN_INTERNAL_ENTITY *m_openInternalEntities; - OPEN_INTERNAL_ENTITY *m_freeInternalEntities; - XML_Bool m_defaultExpandInternalEntities; - int m_tagLevel; - ENTITY *m_declEntity; - const XML_Char *m_doctypeName; - const XML_Char *m_doctypeSysid; - const XML_Char *m_doctypePubid; - const XML_Char *m_declAttributeType; - const XML_Char *m_declNotationName; - const XML_Char *m_declNotationPublicId; - ELEMENT_TYPE *m_declElementType; - ATTRIBUTE_ID *m_declAttributeId; - XML_Bool m_declAttributeIsCdata; - XML_Bool m_declAttributeIsId; - DTD *m_dtd; - const XML_Char *m_curBase; - TAG *m_tagStack; - TAG *m_freeTagList; - BINDING *m_inheritedBindings; - BINDING *m_freeBindingList; - int m_attsSize; - int m_nSpecifiedAtts; - int m_idAttIndex; - ATTRIBUTE *m_atts; - NS_ATT *m_nsAtts; - unsigned long m_nsAttsVersion; - unsigned char m_nsAttsPower; - POSITION m_position; - STRING_POOL m_tempPool; - STRING_POOL m_temp2Pool; - char *m_groupConnector; - unsigned int m_groupSize; - XML_Char m_namespaceSeparator; - XML_Parser m_parentParser; - XML_ParsingStatus m_parsingStatus; -#ifdef XML_DTD - XML_Bool m_isParamEntity; - XML_Bool m_useForeignDTD; - enum XML_ParamEntityParsing m_paramEntityParsing; -#endif -}; - -#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) -#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) -#define FREE(p) (parser->m_mem.free_fcn((p))) - -#define userData (parser->m_userData) -#define handlerArg (parser->m_handlerArg) -#define startElementHandler (parser->m_startElementHandler) -#define endElementHandler (parser->m_endElementHandler) -#define characterDataHandler (parser->m_characterDataHandler) -#define processingInstructionHandler \ - (parser->m_processingInstructionHandler) -#define commentHandler (parser->m_commentHandler) -#define startCdataSectionHandler \ - (parser->m_startCdataSectionHandler) -#define endCdataSectionHandler (parser->m_endCdataSectionHandler) -#define defaultHandler (parser->m_defaultHandler) -#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler) -#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler) -#define unparsedEntityDeclHandler \ - (parser->m_unparsedEntityDeclHandler) -#define notationDeclHandler (parser->m_notationDeclHandler) -#define startNamespaceDeclHandler \ - (parser->m_startNamespaceDeclHandler) -#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler) -#define notStandaloneHandler (parser->m_notStandaloneHandler) -#define externalEntityRefHandler \ - (parser->m_externalEntityRefHandler) -#define externalEntityRefHandlerArg \ - (parser->m_externalEntityRefHandlerArg) -#define internalEntityRefHandler \ - (parser->m_internalEntityRefHandler) -#define skippedEntityHandler (parser->m_skippedEntityHandler) -#define unknownEncodingHandler (parser->m_unknownEncodingHandler) -#define elementDeclHandler (parser->m_elementDeclHandler) -#define attlistDeclHandler (parser->m_attlistDeclHandler) -#define entityDeclHandler (parser->m_entityDeclHandler) -#define xmlDeclHandler (parser->m_xmlDeclHandler) -#define encoding (parser->m_encoding) -#define initEncoding (parser->m_initEncoding) -#define internalEncoding (parser->m_internalEncoding) -#define unknownEncodingMem (parser->m_unknownEncodingMem) -#define unknownEncodingData (parser->m_unknownEncodingData) -#define unknownEncodingHandlerData \ - (parser->m_unknownEncodingHandlerData) -#define unknownEncodingRelease (parser->m_unknownEncodingRelease) -#define protocolEncodingName (parser->m_protocolEncodingName) -#define ns (parser->m_ns) -#define ns_triplets (parser->m_ns_triplets) -#define prologState (parser->m_prologState) -#define processor (parser->m_processor) -#define errorCode (parser->m_errorCode) -#define eventPtr (parser->m_eventPtr) -#define eventEndPtr (parser->m_eventEndPtr) -#define positionPtr (parser->m_positionPtr) -#define position (parser->m_position) -#define openInternalEntities (parser->m_openInternalEntities) -#define freeInternalEntities (parser->m_freeInternalEntities) -#define defaultExpandInternalEntities \ - (parser->m_defaultExpandInternalEntities) -#define tagLevel (parser->m_tagLevel) -#define buffer (parser->m_buffer) -#define bufferPtr (parser->m_bufferPtr) -#define bufferEnd (parser->m_bufferEnd) -#define parseEndByteIndex (parser->m_parseEndByteIndex) -#define parseEndPtr (parser->m_parseEndPtr) -#define bufferLim (parser->m_bufferLim) -#define dataBuf (parser->m_dataBuf) -#define dataBufEnd (parser->m_dataBufEnd) -#define _dtd (parser->m_dtd) -#define curBase (parser->m_curBase) -#define declEntity (parser->m_declEntity) -#define doctypeName (parser->m_doctypeName) -#define doctypeSysid (parser->m_doctypeSysid) -#define doctypePubid (parser->m_doctypePubid) -#define declAttributeType (parser->m_declAttributeType) -#define declNotationName (parser->m_declNotationName) -#define declNotationPublicId (parser->m_declNotationPublicId) -#define declElementType (parser->m_declElementType) -#define declAttributeId (parser->m_declAttributeId) -#define declAttributeIsCdata (parser->m_declAttributeIsCdata) -#define declAttributeIsId (parser->m_declAttributeIsId) -#define freeTagList (parser->m_freeTagList) -#define freeBindingList (parser->m_freeBindingList) -#define inheritedBindings (parser->m_inheritedBindings) -#define tagStack (parser->m_tagStack) -#define atts (parser->m_atts) -#define attsSize (parser->m_attsSize) -#define nSpecifiedAtts (parser->m_nSpecifiedAtts) -#define idAttIndex (parser->m_idAttIndex) -#define nsAtts (parser->m_nsAtts) -#define nsAttsVersion (parser->m_nsAttsVersion) -#define nsAttsPower (parser->m_nsAttsPower) -#define tempPool (parser->m_tempPool) -#define temp2Pool (parser->m_temp2Pool) -#define groupConnector (parser->m_groupConnector) -#define groupSize (parser->m_groupSize) -#define namespaceSeparator (parser->m_namespaceSeparator) -#define parentParser (parser->m_parentParser) -#define ps_parsing (parser->m_parsingStatus.parsing) -#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) -#ifdef XML_DTD -#define isParamEntity (parser->m_isParamEntity) -#define useForeignDTD (parser->m_useForeignDTD) -#define paramEntityParsing (parser->m_paramEntityParsing) -#endif /* XML_DTD */ - -XML_Parser XMLCALL -XML_ParserCreate(const XML_Char *encodingName) -{ - return XML_ParserCreate_MM(encodingName, NULL, NULL); -} - -XML_Parser XMLCALL -XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) -{ - XML_Char tmp[2]; - *tmp = nsSep; - return XML_ParserCreate_MM(encodingName, NULL, tmp); -} - -static const XML_Char implicitContext[] = { - ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, - ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, - ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, - ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, - ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, - ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' -}; - -XML_Parser XMLCALL -XML_ParserCreate_MM(const XML_Char *encodingName, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep) -{ - XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL); - if (parser != NULL && ns) { - /* implicit context only set for root parser, since child - parsers (i.e. external entity parsers) will inherit it - */ - if (!setContext(parser, implicitContext)) { - XML_ParserFree(parser); - return NULL; - } - } - return parser; -} - -static XML_Parser -parserCreate(const XML_Char *encodingName, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep, - DTD *dtd) -{ - XML_Parser parser; - - if (memsuite) { - XML_Memory_Handling_Suite *mtemp; - parser = (XML_Parser) - memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); - if (parser != NULL) { - mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); - mtemp->malloc_fcn = memsuite->malloc_fcn; - mtemp->realloc_fcn = memsuite->realloc_fcn; - mtemp->free_fcn = memsuite->free_fcn; - } - } - else { - XML_Memory_Handling_Suite *mtemp; - parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); - if (parser != NULL) { - mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); - mtemp->malloc_fcn = malloc; - mtemp->realloc_fcn = realloc; - mtemp->free_fcn = free; - } - } - - if (!parser) - return parser; - - buffer = NULL; - bufferLim = NULL; - - attsSize = INIT_ATTS_SIZE; - atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); - if (atts == NULL) { - FREE(parser); - return NULL; - } - dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); - if (dataBuf == NULL) { - FREE(atts); - FREE(parser); - return NULL; - } - dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; - - if (dtd) - _dtd = dtd; - else { - _dtd = dtdCreate(&parser->m_mem); - if (_dtd == NULL) { - FREE(dataBuf); - FREE(atts); - FREE(parser); - return NULL; - } - } - - freeBindingList = NULL; - freeTagList = NULL; - freeInternalEntities = NULL; - - groupSize = 0; - groupConnector = NULL; - - unknownEncodingHandler = NULL; - unknownEncodingHandlerData = NULL; - - namespaceSeparator = ASCII_EXCL; - ns = XML_FALSE; - ns_triplets = XML_FALSE; - - nsAtts = NULL; - nsAttsVersion = 0; - nsAttsPower = 0; - - poolInit(&tempPool, &(parser->m_mem)); - poolInit(&temp2Pool, &(parser->m_mem)); - parserInit(parser, encodingName); - - if (encodingName && !protocolEncodingName) { - XML_ParserFree(parser); - return NULL; - } - - if (nameSep) { - ns = XML_TRUE; - internalEncoding = XmlGetInternalEncodingNS(); - namespaceSeparator = *nameSep; - } - else { - internalEncoding = XmlGetInternalEncoding(); - } - - return parser; -} - -static void -parserInit(XML_Parser parser, const XML_Char *encodingName) -{ - processor = prologInitProcessor; - XmlPrologStateInit(&prologState); - protocolEncodingName = (encodingName != NULL - ? poolCopyString(&tempPool, encodingName) - : NULL); - curBase = NULL; - XmlInitEncoding(&initEncoding, &encoding, 0); - userData = NULL; - handlerArg = NULL; - startElementHandler = NULL; - endElementHandler = NULL; - characterDataHandler = NULL; - processingInstructionHandler = NULL; - commentHandler = NULL; - startCdataSectionHandler = NULL; - endCdataSectionHandler = NULL; - defaultHandler = NULL; - startDoctypeDeclHandler = NULL; - endDoctypeDeclHandler = NULL; - unparsedEntityDeclHandler = NULL; - notationDeclHandler = NULL; - startNamespaceDeclHandler = NULL; - endNamespaceDeclHandler = NULL; - notStandaloneHandler = NULL; - externalEntityRefHandler = NULL; - externalEntityRefHandlerArg = parser; - skippedEntityHandler = NULL; - elementDeclHandler = NULL; - attlistDeclHandler = NULL; - entityDeclHandler = NULL; - xmlDeclHandler = NULL; - bufferPtr = buffer; - bufferEnd = buffer; - parseEndByteIndex = 0; - parseEndPtr = NULL; - declElementType = NULL; - declAttributeId = NULL; - declEntity = NULL; - doctypeName = NULL; - doctypeSysid = NULL; - doctypePubid = NULL; - declAttributeType = NULL; - declNotationName = NULL; - declNotationPublicId = NULL; - declAttributeIsCdata = XML_FALSE; - declAttributeIsId = XML_FALSE; - memset(&position, 0, sizeof(POSITION)); - errorCode = XML_ERROR_NONE; - eventPtr = NULL; - eventEndPtr = NULL; - positionPtr = NULL; - openInternalEntities = NULL; - defaultExpandInternalEntities = XML_TRUE; - tagLevel = 0; - tagStack = NULL; - inheritedBindings = NULL; - nSpecifiedAtts = 0; - unknownEncodingMem = NULL; - unknownEncodingRelease = NULL; - unknownEncodingData = NULL; - parentParser = NULL; - ps_parsing = XML_INITIALIZED; -#ifdef XML_DTD - isParamEntity = XML_FALSE; - useForeignDTD = XML_FALSE; - paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; -#endif -} - -/* moves list of bindings to freeBindingList */ -static void FASTCALL -moveToFreeBindingList(XML_Parser parser, BINDING *bindings) -{ - while (bindings) { - BINDING *b = bindings; - bindings = bindings->nextTagBinding; - b->nextTagBinding = freeBindingList; - freeBindingList = b; - } -} - -XML_Bool XMLCALL -XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) -{ - TAG *tStk; - OPEN_INTERNAL_ENTITY *openEntityList; - if (parentParser) - return XML_FALSE; - /* move tagStack to freeTagList */ - tStk = tagStack; - while (tStk) { - TAG *tag = tStk; - tStk = tStk->parent; - tag->parent = freeTagList; - moveToFreeBindingList(parser, tag->bindings); - tag->bindings = NULL; - freeTagList = tag; - } - /* move openInternalEntities to freeInternalEntities */ - openEntityList = openInternalEntities; - while (openEntityList) { - OPEN_INTERNAL_ENTITY *openEntity = openEntityList; - openEntityList = openEntity->next; - openEntity->next = freeInternalEntities; - freeInternalEntities = openEntity; - } - moveToFreeBindingList(parser, inheritedBindings); - FREE(unknownEncodingMem); - if (unknownEncodingRelease) - unknownEncodingRelease(unknownEncodingData); - poolClear(&tempPool); - poolClear(&temp2Pool); - parserInit(parser, encodingName); - dtdReset(_dtd, &parser->m_mem); - return setContext(parser, implicitContext); -} - -enum XML_Status XMLCALL -XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) -{ - /* Block after XML_Parse()/XML_ParseBuffer() has been called. - XXX There's no way for the caller to determine which of the - XXX possible error cases caused the XML_STATUS_ERROR return. - */ - if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) - return XML_STATUS_ERROR; - if (encodingName == NULL) - protocolEncodingName = NULL; - else { - protocolEncodingName = poolCopyString(&tempPool, encodingName); - if (!protocolEncodingName) - return XML_STATUS_ERROR; - } - return XML_STATUS_OK; -} - -XML_Parser XMLCALL -XML_ExternalEntityParserCreate(XML_Parser oldParser, - const XML_Char *context, - const XML_Char *encodingName) -{ - XML_Parser parser = oldParser; - DTD *newDtd = NULL; - DTD *oldDtd = _dtd; - XML_StartElementHandler oldStartElementHandler = startElementHandler; - XML_EndElementHandler oldEndElementHandler = endElementHandler; - XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; - XML_ProcessingInstructionHandler oldProcessingInstructionHandler - = processingInstructionHandler; - XML_CommentHandler oldCommentHandler = commentHandler; - XML_StartCdataSectionHandler oldStartCdataSectionHandler - = startCdataSectionHandler; - XML_EndCdataSectionHandler oldEndCdataSectionHandler - = endCdataSectionHandler; - XML_DefaultHandler oldDefaultHandler = defaultHandler; - XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler - = unparsedEntityDeclHandler; - XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler; - XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler - = startNamespaceDeclHandler; - XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler - = endNamespaceDeclHandler; - XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler; - XML_ExternalEntityRefHandler oldExternalEntityRefHandler - = externalEntityRefHandler; - XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler; - XML_UnknownEncodingHandler oldUnknownEncodingHandler - = unknownEncodingHandler; - XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler; - XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; - XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; - XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; - ELEMENT_TYPE * oldDeclElementType = declElementType; - - void *oldUserData = userData; - void *oldHandlerArg = handlerArg; - XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; - XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; -#ifdef XML_DTD - enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; - int oldInEntityValue = prologState.inEntityValue; -#endif - XML_Bool oldns_triplets = ns_triplets; - -#ifdef XML_DTD - if (!context) - newDtd = oldDtd; -#endif /* XML_DTD */ - - /* Note that the magical uses of the pre-processor to make field - access look more like C++ require that `parser' be overwritten - here. This makes this function more painful to follow than it - would be otherwise. - */ - if (ns) { - XML_Char tmp[2]; - *tmp = namespaceSeparator; - parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); - } - else { - parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); - } - - if (!parser) - return NULL; - - startElementHandler = oldStartElementHandler; - endElementHandler = oldEndElementHandler; - characterDataHandler = oldCharacterDataHandler; - processingInstructionHandler = oldProcessingInstructionHandler; - commentHandler = oldCommentHandler; - startCdataSectionHandler = oldStartCdataSectionHandler; - endCdataSectionHandler = oldEndCdataSectionHandler; - defaultHandler = oldDefaultHandler; - unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler; - notationDeclHandler = oldNotationDeclHandler; - startNamespaceDeclHandler = oldStartNamespaceDeclHandler; - endNamespaceDeclHandler = oldEndNamespaceDeclHandler; - notStandaloneHandler = oldNotStandaloneHandler; - externalEntityRefHandler = oldExternalEntityRefHandler; - skippedEntityHandler = oldSkippedEntityHandler; - unknownEncodingHandler = oldUnknownEncodingHandler; - elementDeclHandler = oldElementDeclHandler; - attlistDeclHandler = oldAttlistDeclHandler; - entityDeclHandler = oldEntityDeclHandler; - xmlDeclHandler = oldXmlDeclHandler; - declElementType = oldDeclElementType; - userData = oldUserData; - if (oldUserData == oldHandlerArg) - handlerArg = userData; - else - handlerArg = parser; - if (oldExternalEntityRefHandlerArg != oldParser) - externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; - defaultExpandInternalEntities = oldDefaultExpandInternalEntities; - ns_triplets = oldns_triplets; - parentParser = oldParser; -#ifdef XML_DTD - paramEntityParsing = oldParamEntityParsing; - prologState.inEntityValue = oldInEntityValue; - if (context) { -#endif /* XML_DTD */ - if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) - || !setContext(parser, context)) { - XML_ParserFree(parser); - return NULL; - } - processor = externalEntityInitProcessor; -#ifdef XML_DTD - } - else { - /* The DTD instance referenced by _dtd is shared between the document's - root parser and external PE parsers, therefore one does not need to - call setContext. In addition, one also *must* not call setContext, - because this would overwrite existing prefix->binding pointers in - _dtd with ones that get destroyed with the external PE parser. - This would leave those prefixes with dangling pointers. - */ - isParamEntity = XML_TRUE; - XmlPrologStateInitExternalEntity(&prologState); - processor = externalParEntInitProcessor; - } -#endif /* XML_DTD */ - return parser; -} - -static void FASTCALL -destroyBindings(BINDING *bindings, XML_Parser parser) -{ - for (;;) { - BINDING *b = bindings; - if (!b) - break; - bindings = b->nextTagBinding; - FREE(b->uri); - FREE(b); - } -} - -void XMLCALL -XML_ParserFree(XML_Parser parser) -{ - TAG *tagList; - OPEN_INTERNAL_ENTITY *entityList; - if (parser == NULL) - return; - /* free tagStack and freeTagList */ - tagList = tagStack; - for (;;) { - TAG *p; - if (tagList == NULL) { - if (freeTagList == NULL) - break; - tagList = freeTagList; - freeTagList = NULL; - } - p = tagList; - tagList = tagList->parent; - FREE(p->buf); - destroyBindings(p->bindings, parser); - FREE(p); - } - /* free openInternalEntities and freeInternalEntities */ - entityList = openInternalEntities; - for (;;) { - OPEN_INTERNAL_ENTITY *openEntity; - if (entityList == NULL) { - if (freeInternalEntities == NULL) - break; - entityList = freeInternalEntities; - freeInternalEntities = NULL; - } - openEntity = entityList; - entityList = entityList->next; - FREE(openEntity); - } - - destroyBindings(freeBindingList, parser); - destroyBindings(inheritedBindings, parser); - poolDestroy(&tempPool); - poolDestroy(&temp2Pool); -#ifdef XML_DTD - /* external parameter entity parsers share the DTD structure - parser->m_dtd with the root parser, so we must not destroy it - */ - if (!isParamEntity && _dtd) -#else - if (_dtd) -#endif /* XML_DTD */ - dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); - FREE((void *)atts); - FREE(groupConnector); - FREE(buffer); - FREE(dataBuf); - FREE(nsAtts); - FREE(unknownEncodingMem); - if (unknownEncodingRelease) - unknownEncodingRelease(unknownEncodingData); - FREE(parser); -} - -void XMLCALL -XML_UseParserAsHandlerArg(XML_Parser parser) -{ - handlerArg = parser; -} - -enum XML_Error XMLCALL -XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) -{ -#ifdef XML_DTD - /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) - return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; - useForeignDTD = useDTD; - return XML_ERROR_NONE; -#else - return XML_ERROR_FEATURE_REQUIRES_XML_DTD; -#endif -} - -void XMLCALL -XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) -{ - /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) - return; - ns_triplets = do_nst ? XML_TRUE : XML_FALSE; -} - -void XMLCALL -XML_SetUserData(XML_Parser parser, void *p) -{ - if (handlerArg == userData) - handlerArg = userData = p; - else - userData = p; -} - -enum XML_Status XMLCALL -XML_SetBase(XML_Parser parser, const XML_Char *p) -{ - if (p) { - p = poolCopyString(&_dtd->pool, p); - if (!p) - return XML_STATUS_ERROR; - curBase = p; - } - else - curBase = NULL; - return XML_STATUS_OK; -} - -const XML_Char * XMLCALL -XML_GetBase(XML_Parser parser) -{ - return curBase; -} - -int XMLCALL -XML_GetSpecifiedAttributeCount(XML_Parser parser) -{ - return nSpecifiedAtts; -} - -int XMLCALL -XML_GetIdAttributeIndex(XML_Parser parser) -{ - return idAttIndex; -} - -void XMLCALL -XML_SetElementHandler(XML_Parser parser, - XML_StartElementHandler start, - XML_EndElementHandler end) -{ - startElementHandler = start; - endElementHandler = end; -} - -void XMLCALL -XML_SetStartElementHandler(XML_Parser parser, - XML_StartElementHandler start) { - startElementHandler = start; -} - -void XMLCALL -XML_SetEndElementHandler(XML_Parser parser, - XML_EndElementHandler end) { - endElementHandler = end; -} - -void XMLCALL -XML_SetCharacterDataHandler(XML_Parser parser, - XML_CharacterDataHandler handler) -{ - characterDataHandler = handler; -} - -void XMLCALL -XML_SetProcessingInstructionHandler(XML_Parser parser, - XML_ProcessingInstructionHandler handler) -{ - processingInstructionHandler = handler; -} - -void XMLCALL -XML_SetCommentHandler(XML_Parser parser, - XML_CommentHandler handler) -{ - commentHandler = handler; -} - -void XMLCALL -XML_SetCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start, - XML_EndCdataSectionHandler end) -{ - startCdataSectionHandler = start; - endCdataSectionHandler = end; -} - -void XMLCALL -XML_SetStartCdataSectionHandler(XML_Parser parser, - XML_StartCdataSectionHandler start) { - startCdataSectionHandler = start; -} - -void XMLCALL -XML_SetEndCdataSectionHandler(XML_Parser parser, - XML_EndCdataSectionHandler end) { - endCdataSectionHandler = end; -} - -void XMLCALL -XML_SetDefaultHandler(XML_Parser parser, - XML_DefaultHandler handler) -{ - defaultHandler = handler; - defaultExpandInternalEntities = XML_FALSE; -} - -void XMLCALL -XML_SetDefaultHandlerExpand(XML_Parser parser, - XML_DefaultHandler handler) -{ - defaultHandler = handler; - defaultExpandInternalEntities = XML_TRUE; -} - -void XMLCALL -XML_SetDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start, - XML_EndDoctypeDeclHandler end) -{ - startDoctypeDeclHandler = start; - endDoctypeDeclHandler = end; -} - -void XMLCALL -XML_SetStartDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start) { - startDoctypeDeclHandler = start; -} - -void XMLCALL -XML_SetEndDoctypeDeclHandler(XML_Parser parser, - XML_EndDoctypeDeclHandler end) { - endDoctypeDeclHandler = end; -} - -void XMLCALL -XML_SetUnparsedEntityDeclHandler(XML_Parser parser, - XML_UnparsedEntityDeclHandler handler) -{ - unparsedEntityDeclHandler = handler; -} - -void XMLCALL -XML_SetNotationDeclHandler(XML_Parser parser, - XML_NotationDeclHandler handler) -{ - notationDeclHandler = handler; -} - -void XMLCALL -XML_SetNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start, - XML_EndNamespaceDeclHandler end) -{ - startNamespaceDeclHandler = start; - endNamespaceDeclHandler = end; -} - -void XMLCALL -XML_SetStartNamespaceDeclHandler(XML_Parser parser, - XML_StartNamespaceDeclHandler start) { - startNamespaceDeclHandler = start; -} - -void XMLCALL -XML_SetEndNamespaceDeclHandler(XML_Parser parser, - XML_EndNamespaceDeclHandler end) { - endNamespaceDeclHandler = end; -} - -void XMLCALL -XML_SetNotStandaloneHandler(XML_Parser parser, - XML_NotStandaloneHandler handler) -{ - notStandaloneHandler = handler; -} - -void XMLCALL -XML_SetExternalEntityRefHandler(XML_Parser parser, - XML_ExternalEntityRefHandler handler) -{ - externalEntityRefHandler = handler; -} - -void XMLCALL -XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) -{ - if (arg) - externalEntityRefHandlerArg = (XML_Parser)arg; - else - externalEntityRefHandlerArg = parser; -} - -void XMLCALL -XML_SetSkippedEntityHandler(XML_Parser parser, - XML_SkippedEntityHandler handler) -{ - skippedEntityHandler = handler; -} - -void XMLCALL -XML_SetUnknownEncodingHandler(XML_Parser parser, - XML_UnknownEncodingHandler handler, - void *data) -{ - unknownEncodingHandler = handler; - unknownEncodingHandlerData = data; -} - -void XMLCALL -XML_SetElementDeclHandler(XML_Parser parser, - XML_ElementDeclHandler eldecl) -{ - elementDeclHandler = eldecl; -} - -void XMLCALL -XML_SetAttlistDeclHandler(XML_Parser parser, - XML_AttlistDeclHandler attdecl) -{ - attlistDeclHandler = attdecl; -} - -void XMLCALL -XML_SetEntityDeclHandler(XML_Parser parser, - XML_EntityDeclHandler handler) -{ - entityDeclHandler = handler; -} - -void XMLCALL -XML_SetXmlDeclHandler(XML_Parser parser, - XML_XmlDeclHandler handler) { - xmlDeclHandler = handler; -} - -int XMLCALL -XML_SetParamEntityParsing(XML_Parser parser, - enum XML_ParamEntityParsing peParsing) -{ - /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) - return 0; -#ifdef XML_DTD - paramEntityParsing = peParsing; - return 1; -#else - return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; -#endif -} - -enum XML_Status XMLCALL -XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) -{ - switch (ps_parsing) { - case XML_SUSPENDED: - errorCode = XML_ERROR_SUSPENDED; - return XML_STATUS_ERROR; - case XML_FINISHED: - errorCode = XML_ERROR_FINISHED; - return XML_STATUS_ERROR; - default: - ps_parsing = XML_PARSING; - } - - if (len == 0) { - ps_finalBuffer = (XML_Bool)isFinal; - if (!isFinal) - return XML_STATUS_OK; - positionPtr = bufferPtr; - parseEndPtr = bufferEnd; - - /* If data are left over from last buffer, and we now know that these - data are the final chunk of input, then we have to check them again - to detect errors based on that fact. - */ - errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); - - if (errorCode == XML_ERROR_NONE) { - switch (ps_parsing) { - case XML_SUSPENDED: - XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); - positionPtr = bufferPtr; - return XML_STATUS_SUSPENDED; - case XML_INITIALIZED: - case XML_PARSING: - ps_parsing = XML_FINISHED; - /* fall through */ - default: - return XML_STATUS_OK; - } - } - eventEndPtr = eventPtr; - processor = errorProcessor; - return XML_STATUS_ERROR; - } -#ifndef XML_CONTEXT_BYTES - else if (bufferPtr == bufferEnd) { - const char *end; - int nLeftOver; - enum XML_Error result; - parseEndByteIndex += len; - positionPtr = s; - ps_finalBuffer = (XML_Bool)isFinal; - - errorCode = processor(parser, s, parseEndPtr = s + len, &end); - - if (errorCode != XML_ERROR_NONE) { - eventEndPtr = eventPtr; - processor = errorProcessor; - return XML_STATUS_ERROR; - } - else { - switch (ps_parsing) { - case XML_SUSPENDED: - result = XML_STATUS_SUSPENDED; - break; - case XML_INITIALIZED: - case XML_PARSING: - result = XML_STATUS_OK; - if (isFinal) { - ps_parsing = XML_FINISHED; - return result; - } - } - } - - XmlUpdatePosition(encoding, positionPtr, end, &position); - nLeftOver = s + len - end; - if (nLeftOver) { - if (buffer == NULL || nLeftOver > bufferLim - buffer) { - /* FIXME avoid integer overflow */ - char *temp; - temp = (buffer == NULL - ? (char *)MALLOC(len * 2) - : (char *)REALLOC(buffer, len * 2)); - if (temp == NULL) { - errorCode = XML_ERROR_NO_MEMORY; - return XML_STATUS_ERROR; - } - buffer = temp; - if (!buffer) { - errorCode = XML_ERROR_NO_MEMORY; - eventPtr = eventEndPtr = NULL; - processor = errorProcessor; - return XML_STATUS_ERROR; - } - bufferLim = buffer + len * 2; - } - memcpy(buffer, end, nLeftOver); - } - bufferPtr = buffer; - bufferEnd = buffer + nLeftOver; - positionPtr = bufferPtr; - parseEndPtr = bufferEnd; - eventPtr = bufferPtr; - eventEndPtr = bufferPtr; - return result; - } -#endif /* not defined XML_CONTEXT_BYTES */ - else { - void *buff = XML_GetBuffer(parser, len); - if (buff == NULL) - return XML_STATUS_ERROR; - else { - memcpy(buff, s, len); - return XML_ParseBuffer(parser, len, isFinal); - } - } -} - -enum XML_Status XMLCALL -XML_ParseBuffer(XML_Parser parser, int len, int isFinal) -{ - const char *start; - enum XML_Status result = XML_STATUS_OK; - - switch (ps_parsing) { - case XML_SUSPENDED: - errorCode = XML_ERROR_SUSPENDED; - return XML_STATUS_ERROR; - case XML_FINISHED: - errorCode = XML_ERROR_FINISHED; - return XML_STATUS_ERROR; - default: - ps_parsing = XML_PARSING; - } - - start = bufferPtr; - positionPtr = start; - bufferEnd += len; - parseEndPtr = bufferEnd; - parseEndByteIndex += len; - ps_finalBuffer = (XML_Bool)isFinal; - - errorCode = processor(parser, start, parseEndPtr, &bufferPtr); - - if (errorCode != XML_ERROR_NONE) { - eventEndPtr = eventPtr; - processor = errorProcessor; - return XML_STATUS_ERROR; - } - else { - switch (ps_parsing) { - case XML_SUSPENDED: - result = XML_STATUS_SUSPENDED; - break; - case XML_INITIALIZED: - case XML_PARSING: - if (isFinal) { - ps_parsing = XML_FINISHED; - return result; - } - default: ; /* should not happen */ - } - } - - XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); - positionPtr = bufferPtr; - return result; -} - -void * XMLCALL -XML_GetBuffer(XML_Parser parser, int len) -{ - switch (ps_parsing) { - case XML_SUSPENDED: - errorCode = XML_ERROR_SUSPENDED; - return NULL; - case XML_FINISHED: - errorCode = XML_ERROR_FINISHED; - return NULL; - default: ; - } - - if (len > bufferLim - bufferEnd) { - /* FIXME avoid integer overflow */ - int neededSize = len + (int)(bufferEnd - bufferPtr); -#ifdef XML_CONTEXT_BYTES - int keep = (int)(bufferPtr - buffer); - - if (keep > XML_CONTEXT_BYTES) - keep = XML_CONTEXT_BYTES; - neededSize += keep; -#endif /* defined XML_CONTEXT_BYTES */ - if (neededSize <= bufferLim - buffer) { -#ifdef XML_CONTEXT_BYTES - if (keep < bufferPtr - buffer) { - int offset = (int)(bufferPtr - buffer) - keep; - memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); - bufferEnd -= offset; - bufferPtr -= offset; - } -#else - memmove(buffer, bufferPtr, bufferEnd - bufferPtr); - bufferEnd = buffer + (bufferEnd - bufferPtr); - bufferPtr = buffer; -#endif /* not defined XML_CONTEXT_BYTES */ - } - else { - char *newBuf; - int bufferSize = (int)(bufferLim - bufferPtr); - if (bufferSize == 0) - bufferSize = INIT_BUFFER_SIZE; - do { - bufferSize *= 2; - } while (bufferSize < neededSize); - newBuf = (char *)MALLOC(bufferSize); - if (newBuf == 0) { - errorCode = XML_ERROR_NO_MEMORY; - return NULL; - } - bufferLim = newBuf + bufferSize; -#ifdef XML_CONTEXT_BYTES - if (bufferPtr) { - int keep = (int)(bufferPtr - buffer); - if (keep > XML_CONTEXT_BYTES) - keep = XML_CONTEXT_BYTES; - memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); - FREE(buffer); - buffer = newBuf; - bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; - bufferPtr = buffer + keep; - } - else { - bufferEnd = newBuf + (bufferEnd - bufferPtr); - bufferPtr = buffer = newBuf; - } -#else - if (bufferPtr) { - memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); - FREE(buffer); - } - bufferEnd = newBuf + (bufferEnd - bufferPtr); - bufferPtr = buffer = newBuf; -#endif /* not defined XML_CONTEXT_BYTES */ - } - } - return bufferEnd; -} - -enum XML_Status XMLCALL -XML_StopParser(XML_Parser parser, XML_Bool resumable) -{ - switch (ps_parsing) { - case XML_SUSPENDED: - if (resumable) { - errorCode = XML_ERROR_SUSPENDED; - return XML_STATUS_ERROR; - } - ps_parsing = XML_FINISHED; - break; - case XML_FINISHED: - errorCode = XML_ERROR_FINISHED; - return XML_STATUS_ERROR; - default: - if (resumable) { -#ifdef XML_DTD - if (isParamEntity) { - errorCode = XML_ERROR_SUSPEND_PE; - return XML_STATUS_ERROR; - } -#endif - ps_parsing = XML_SUSPENDED; - } - else - ps_parsing = XML_FINISHED; - } - return XML_STATUS_OK; -} - -enum XML_Status XMLCALL -XML_ResumeParser(XML_Parser parser) -{ - enum XML_Status result = XML_STATUS_OK; - - if (ps_parsing != XML_SUSPENDED) { - errorCode = XML_ERROR_NOT_SUSPENDED; - return XML_STATUS_ERROR; - } - ps_parsing = XML_PARSING; - - errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); - - if (errorCode != XML_ERROR_NONE) { - eventEndPtr = eventPtr; - processor = errorProcessor; - return XML_STATUS_ERROR; - } - else { - switch (ps_parsing) { - case XML_SUSPENDED: - result = XML_STATUS_SUSPENDED; - break; - case XML_INITIALIZED: - case XML_PARSING: - if (ps_finalBuffer) { - ps_parsing = XML_FINISHED; - return result; - } - default: ; - } - } - - XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); - positionPtr = bufferPtr; - return result; -} - -void XMLCALL -XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) -{ - assert(status != NULL); - *status = parser->m_parsingStatus; -} - -enum XML_Error XMLCALL -XML_GetErrorCode(XML_Parser parser) -{ - return errorCode; -} - -XML_Index XMLCALL -XML_GetCurrentByteIndex(XML_Parser parser) -{ - if (eventPtr) - return parseEndByteIndex - (parseEndPtr - eventPtr); - return -1; -} - -int XMLCALL -XML_GetCurrentByteCount(XML_Parser parser) -{ - if (eventEndPtr && eventPtr) - return (int)(eventEndPtr - eventPtr); - return 0; -} - -const char * XMLCALL -XML_GetInputContext(XML_Parser parser, int *offset, int *size) -{ -#ifdef XML_CONTEXT_BYTES - if (eventPtr && buffer) { - *offset = (int)(eventPtr - buffer); - *size = (int)(bufferEnd - buffer); - return buffer; - } -#endif /* defined XML_CONTEXT_BYTES */ - return (char *) 0; -} - -XML_Size XMLCALL -XML_GetCurrentLineNumber(XML_Parser parser) -{ - if (eventPtr && eventPtr >= positionPtr) { - XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); - positionPtr = eventPtr; - } - return position.lineNumber + 1; -} - -XML_Size XMLCALL -XML_GetCurrentColumnNumber(XML_Parser parser) -{ - if (eventPtr && eventPtr >= positionPtr) { - XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); - positionPtr = eventPtr; - } - return position.columnNumber; -} - -void XMLCALL -XML_FreeContentModel(XML_Parser parser, XML_Content *model) -{ - FREE(model); -} - -void * XMLCALL -XML_MemMalloc(XML_Parser parser, size_t size) -{ - return MALLOC(size); -} - -void * XMLCALL -XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) -{ - return REALLOC(ptr, size); -} - -void XMLCALL -XML_MemFree(XML_Parser parser, void *ptr) -{ - FREE(ptr); -} - -void XMLCALL -XML_DefaultCurrent(XML_Parser parser) -{ - if (defaultHandler) { - if (openInternalEntities) - reportDefault(parser, - internalEncoding, - openInternalEntities->internalEventPtr, - openInternalEntities->internalEventEndPtr); - else - reportDefault(parser, encoding, eventPtr, eventEndPtr); - } -} - -const XML_LChar * XMLCALL -XML_ErrorString(enum XML_Error code) -{ - static const XML_LChar* const message[] = { - 0, - XML_L("out of memory"), - XML_L("syntax error"), - XML_L("no element found"), - XML_L("not well-formed (invalid token)"), - XML_L("unclosed token"), - XML_L("partial character"), - XML_L("mismatched tag"), - XML_L("duplicate attribute"), - XML_L("junk after document element"), - XML_L("illegal parameter entity reference"), - XML_L("undefined entity"), - XML_L("recursive entity reference"), - XML_L("asynchronous entity"), - XML_L("reference to invalid character number"), - XML_L("reference to binary entity"), - XML_L("reference to external entity in attribute"), - XML_L("XML or text declaration not at start of entity"), - XML_L("unknown encoding"), - XML_L("encoding specified in XML declaration is incorrect"), - XML_L("unclosed CDATA section"), - XML_L("error in processing external entity reference"), - XML_L("document is not standalone"), - XML_L("unexpected parser state - please send a bug report"), - XML_L("entity declared in parameter entity"), - XML_L("requested feature requires XML_DTD support in Expat"), - XML_L("cannot change setting once parsing has begun"), - XML_L("unbound prefix"), - XML_L("must not undeclare prefix"), - XML_L("incomplete markup in parameter entity"), - XML_L("XML declaration not well-formed"), - XML_L("text declaration not well-formed"), - XML_L("illegal character(s) in public id"), - XML_L("parser suspended"), - XML_L("parser not suspended"), - XML_L("parsing aborted"), - XML_L("parsing finished"), - XML_L("cannot suspend in external parameter entity"), - XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), - XML_L("reserved prefix (xmlns) must not be declared or undeclared"), - XML_L("prefix must not be bound to one of the reserved namespace names") - }; - if (code > 0 && code < sizeof(message)/sizeof(message[0])) - return message[code]; - return NULL; -} - -const XML_LChar * XMLCALL -XML_ExpatVersion(void) { - - /* V1 is used to string-ize the version number. However, it would - string-ize the actual version macro *names* unless we get them - substituted before being passed to V1. CPP is defined to expand - a macro, then rescan for more expansions. Thus, we use V2 to expand - the version macros, then CPP will expand the resulting V1() macro - with the correct numerals. */ - /* ### I'm assuming cpp is portable in this respect... */ - -#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) -#define V2(a,b,c) XML_L("expat_")V1(a,b,c) - - return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); - -#undef V1 -#undef V2 -} - -XML_Expat_Version XMLCALL -XML_ExpatVersionInfo(void) -{ - XML_Expat_Version version; - - version.major = XML_MAJOR_VERSION; - version.minor = XML_MINOR_VERSION; - version.micro = XML_MICRO_VERSION; - - return version; -} - -const XML_Feature * XMLCALL -XML_GetFeatureList(void) -{ - static const XML_Feature features[] = { - {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), - sizeof(XML_Char)}, - {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), - sizeof(XML_LChar)}, -#ifdef XML_UNICODE - {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, -#endif -#ifdef XML_UNICODE_WCHAR_T - {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, -#endif -#ifdef XML_DTD - {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, -#endif -#ifdef XML_CONTEXT_BYTES - {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), - XML_CONTEXT_BYTES}, -#endif -#ifdef XML_MIN_SIZE - {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, -#endif -#ifdef XML_NS - {XML_FEATURE_NS, XML_L("XML_NS"), 0}, -#endif -#ifdef XML_LARGE_SIZE - {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, -#endif - {XML_FEATURE_END, NULL, 0} - }; - - return features; -} - -/* Initially tag->rawName always points into the parse buffer; - for those TAG instances opened while the current parse buffer was - processed, and not yet closed, we need to store tag->rawName in a more - permanent location, since the parse buffer is about to be discarded. -*/ -static XML_Bool -storeRawNames(XML_Parser parser) -{ - TAG *tag = tagStack; - while (tag) { - int bufSize; - int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); - char *rawNameBuf = tag->buf + nameLen; - /* Stop if already stored. Since tagStack is a stack, we can stop - at the first entry that has already been copied; everything - below it in the stack is already been accounted for in a - previous call to this function. - */ - if (tag->rawName == rawNameBuf) - break; - /* For re-use purposes we need to ensure that the - size of tag->buf is a multiple of sizeof(XML_Char). - */ - bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); - if (bufSize > tag->bufEnd - tag->buf) { - char *temp = (char *)REALLOC(tag->buf, bufSize); - if (temp == NULL) - return XML_FALSE; - /* if tag->name.str points to tag->buf (only when namespace - processing is off) then we have to update it - */ - if (tag->name.str == (XML_Char *)tag->buf) - tag->name.str = (XML_Char *)temp; - /* if tag->name.localPart is set (when namespace processing is on) - then update it as well, since it will always point into tag->buf - */ - if (tag->name.localPart) - tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - - (XML_Char *)tag->buf); - tag->buf = temp; - tag->bufEnd = temp + bufSize; - rawNameBuf = temp + nameLen; - } - memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); - tag->rawName = rawNameBuf; - tag = tag->parent; - } - return XML_TRUE; -} - -static enum XML_Error PTRCALL -contentProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doContent(parser, 0, encoding, start, end, - endPtr, (XML_Bool)!ps_finalBuffer); - if (result == XML_ERROR_NONE) { - if (!storeRawNames(parser)) - return XML_ERROR_NO_MEMORY; - } - return result; -} - -static enum XML_Error PTRCALL -externalEntityInitProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = initializeEncoding(parser); - if (result != XML_ERROR_NONE) - return result; - processor = externalEntityInitProcessor2; - return externalEntityInitProcessor2(parser, start, end, endPtr); -} - -static enum XML_Error PTRCALL -externalEntityInitProcessor2(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - const char *next = start; /* XmlContentTok doesn't always set the last arg */ - int tok = XmlContentTok(encoding, start, end, &next); - switch (tok) { - case XML_TOK_BOM: - /* If we are at the end of the buffer, this would cause the next stage, - i.e. externalEntityInitProcessor3, to pass control directly to - doContent (by detecting XML_TOK_NONE) without processing any xml text - declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. - */ - if (next == end && !ps_finalBuffer) { - *endPtr = next; - return XML_ERROR_NONE; - } - start = next; - break; - case XML_TOK_PARTIAL: - if (!ps_finalBuffer) { - *endPtr = start; - return XML_ERROR_NONE; - } - eventPtr = start; - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (!ps_finalBuffer) { - *endPtr = start; - return XML_ERROR_NONE; - } - eventPtr = start; - return XML_ERROR_PARTIAL_CHAR; - } - processor = externalEntityInitProcessor3; - return externalEntityInitProcessor3(parser, start, end, endPtr); -} - -static enum XML_Error PTRCALL -externalEntityInitProcessor3(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - int tok; - const char *next = start; /* XmlContentTok doesn't always set the last arg */ - eventPtr = start; - tok = XmlContentTok(encoding, start, end, &next); - eventEndPtr = next; - - switch (tok) { - case XML_TOK_XML_DECL: - { - enum XML_Error result; - result = processXmlDecl(parser, 1, start, next); - if (result != XML_ERROR_NONE) - return result; - switch (ps_parsing) { - case XML_SUSPENDED: - *endPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: - start = next; - } - } - break; - case XML_TOK_PARTIAL: - if (!ps_finalBuffer) { - *endPtr = start; - return XML_ERROR_NONE; - } - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (!ps_finalBuffer) { - *endPtr = start; - return XML_ERROR_NONE; - } - return XML_ERROR_PARTIAL_CHAR; - } - processor = externalEntityContentProcessor; - tagLevel = 1; - return externalEntityContentProcessor(parser, start, end, endPtr); -} - -static enum XML_Error PTRCALL -externalEntityContentProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doContent(parser, 1, encoding, start, end, - endPtr, (XML_Bool)!ps_finalBuffer); - if (result == XML_ERROR_NONE) { - if (!storeRawNames(parser)) - return XML_ERROR_NO_MEMORY; - } - return result; -} - -static enum XML_Error -doContent(XML_Parser parser, - int startTagLevel, - const ENCODING *enc, - const char *s, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ - /* save one level of indirection */ - DTD * const dtd = _dtd; - - const char **eventPP; - const char **eventEndPP; - if (enc == encoding) { - eventPP = &eventPtr; - eventEndPP = &eventEndPtr; - } - else { - eventPP = &(openInternalEntities->internalEventPtr); - eventEndPP = &(openInternalEntities->internalEventEndPtr); - } - *eventPP = s; - - for (;;) { - const char *next = s; /* XmlContentTok doesn't always set the last arg */ - int tok = XmlContentTok(enc, s, end, &next); - *eventEndPP = next; - switch (tok) { - case XML_TOK_TRAILING_CR: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - *eventEndPP = end; - if (characterDataHandler) { - XML_Char c = 0xA; - characterDataHandler(handlerArg, &c, 1); - } - else if (defaultHandler) - reportDefault(parser, enc, s, end); - /* We are at the end of the final buffer, should we check for - XML_SUSPENDED, XML_FINISHED? - */ - if (startTagLevel == 0) - return XML_ERROR_NO_ELEMENTS; - if (tagLevel != startTagLevel) - return XML_ERROR_ASYNC_ENTITY; - *nextPtr = end; - return XML_ERROR_NONE; - case XML_TOK_NONE: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - if (startTagLevel > 0) { - if (tagLevel != startTagLevel) - return XML_ERROR_ASYNC_ENTITY; - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_NO_ELEMENTS; - case XML_TOK_INVALID: - *eventPP = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_ENTITY_REF: - { - const XML_Char *name; - ENTITY *entity; - XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (ch) { - if (characterDataHandler) - characterDataHandler(handlerArg, &ch, 1); - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - name = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) - return XML_ERROR_NO_MEMORY; - entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); - poolDiscard(&dtd->pool); - /* First, determine if a check for an existing declaration is needed; - if yes, check that the entity exists, and that it is internal, - otherwise call the skipped entity or default handler. - */ - if (!dtd->hasParamEntityRefs || dtd->standalone) { - if (!entity) - return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) - return XML_ERROR_ENTITY_DECLARED_IN_PE; - } - else if (!entity) { - if (skippedEntityHandler) - skippedEntityHandler(handlerArg, name, 0); - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - if (entity->open) - return XML_ERROR_RECURSIVE_ENTITY_REF; - if (entity->notation) - return XML_ERROR_BINARY_ENTITY_REF; - if (entity->textPtr) { - enum XML_Error result; - if (!defaultExpandInternalEntities) { - if (skippedEntityHandler) - skippedEntityHandler(handlerArg, entity->name, 0); - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - result = processInternalEntity(parser, entity, XML_FALSE); - if (result != XML_ERROR_NONE) - return result; - } - else if (externalEntityRefHandler) { - const XML_Char *context; - entity->open = XML_TRUE; - context = getContext(parser); - entity->open = XML_FALSE; - if (!context) - return XML_ERROR_NO_MEMORY; - if (!externalEntityRefHandler(externalEntityRefHandlerArg, - context, - entity->base, - entity->systemId, - entity->publicId)) - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - poolDiscard(&tempPool); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - case XML_TOK_START_TAG_NO_ATTS: - /* fall through */ - case XML_TOK_START_TAG_WITH_ATTS: - { - TAG *tag; - enum XML_Error result; - XML_Char *toPtr; - if (freeTagList) { - tag = freeTagList; - freeTagList = freeTagList->parent; - } - else { - tag = (TAG *)MALLOC(sizeof(TAG)); - if (!tag) - return XML_ERROR_NO_MEMORY; - tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); - if (!tag->buf) { - FREE(tag); - return XML_ERROR_NO_MEMORY; - } - tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; - } - tag->bindings = NULL; - tag->parent = tagStack; - tagStack = tag; - tag->name.localPart = NULL; - tag->name.prefix = NULL; - tag->rawName = s + enc->minBytesPerChar; - tag->rawNameLength = XmlNameLength(enc, tag->rawName); - ++tagLevel; - { - const char *rawNameEnd = tag->rawName + tag->rawNameLength; - const char *fromPtr = tag->rawName; - toPtr = (XML_Char *)tag->buf; - for (;;) { - int bufSize; - int convLen; - XmlConvert(enc, - &fromPtr, rawNameEnd, - (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); - convLen = (int)(toPtr - (XML_Char *)tag->buf); - if (fromPtr == rawNameEnd) { - tag->name.strLen = convLen; - break; - } - bufSize = (int)(tag->bufEnd - tag->buf) << 1; - { - char *temp = (char *)REALLOC(tag->buf, bufSize); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - tag->buf = temp; - tag->bufEnd = temp + bufSize; - toPtr = (XML_Char *)temp + convLen; - } - } - } - tag->name.str = (XML_Char *)tag->buf; - *toPtr = XML_T('\0'); - result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); - if (result) - return result; - if (startElementHandler) - startElementHandler(handlerArg, tag->name.str, - (const XML_Char **)atts); - else if (defaultHandler) - reportDefault(parser, enc, s, next); - poolClear(&tempPool); - break; - } - case XML_TOK_EMPTY_ELEMENT_NO_ATTS: - /* fall through */ - case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: - { - const char *rawName = s + enc->minBytesPerChar; - enum XML_Error result; - BINDING *bindings = NULL; - XML_Bool noElmHandlers = XML_TRUE; - TAG_NAME name; - name.str = poolStoreString(&tempPool, enc, rawName, - rawName + XmlNameLength(enc, rawName)); - if (!name.str) - return XML_ERROR_NO_MEMORY; - poolFinish(&tempPool); - result = storeAtts(parser, enc, s, &name, &bindings); - if (result) - return result; - poolFinish(&tempPool); - if (startElementHandler) { - startElementHandler(handlerArg, name.str, (const XML_Char **)atts); - noElmHandlers = XML_FALSE; - } - if (endElementHandler) { - if (startElementHandler) - *eventPP = *eventEndPP; - endElementHandler(handlerArg, name.str); - noElmHandlers = XML_FALSE; - } - if (noElmHandlers && defaultHandler) - reportDefault(parser, enc, s, next); - poolClear(&tempPool); - while (bindings) { - BINDING *b = bindings; - if (endNamespaceDeclHandler) - endNamespaceDeclHandler(handlerArg, b->prefix->name); - bindings = bindings->nextTagBinding; - b->nextTagBinding = freeBindingList; - freeBindingList = b; - b->prefix->binding = b->prevPrefixBinding; - } - } - if (tagLevel == 0) - return epilogProcessor(parser, next, end, nextPtr); - break; - case XML_TOK_END_TAG: - if (tagLevel == startTagLevel) - return XML_ERROR_ASYNC_ENTITY; - else { - int len; - const char *rawName; - TAG *tag = tagStack; - tagStack = tag->parent; - tag->parent = freeTagList; - freeTagList = tag; - rawName = s + enc->minBytesPerChar*2; - len = XmlNameLength(enc, rawName); - if (len != tag->rawNameLength - || memcmp(tag->rawName, rawName, len) != 0) { - *eventPP = rawName; - return XML_ERROR_TAG_MISMATCH; - } - --tagLevel; - if (endElementHandler) { - const XML_Char *localPart; - const XML_Char *prefix; - XML_Char *uri; - localPart = tag->name.localPart; - if (ns && localPart) { - /* localPart and prefix may have been overwritten in - tag->name.str, since this points to the binding->uri - buffer which gets re-used; so we have to add them again - */ - uri = (XML_Char *)tag->name.str + tag->name.uriLen; - /* don't need to check for space - already done in storeAtts() */ - while (*localPart) *uri++ = *localPart++; - prefix = (XML_Char *)tag->name.prefix; - if (ns_triplets && prefix) { - *uri++ = namespaceSeparator; - while (*prefix) *uri++ = *prefix++; - } - *uri = XML_T('\0'); - } - endElementHandler(handlerArg, tag->name.str); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - while (tag->bindings) { - BINDING *b = tag->bindings; - if (endNamespaceDeclHandler) - endNamespaceDeclHandler(handlerArg, b->prefix->name); - tag->bindings = tag->bindings->nextTagBinding; - b->nextTagBinding = freeBindingList; - freeBindingList = b; - b->prefix->binding = b->prevPrefixBinding; - } - if (tagLevel == 0) - return epilogProcessor(parser, next, end, nextPtr); - } - break; - case XML_TOK_CHAR_REF: - { - int n = XmlCharRefNumber(enc, s); - if (n < 0) - return XML_ERROR_BAD_CHAR_REF; - if (characterDataHandler) { - XML_Char buf[XML_ENCODE_MAX]; - characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - } - break; - case XML_TOK_XML_DECL: - return XML_ERROR_MISPLACED_XML_PI; - case XML_TOK_DATA_NEWLINE: - if (characterDataHandler) { - XML_Char c = 0xA; - characterDataHandler(handlerArg, &c, 1); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - case XML_TOK_CDATA_SECT_OPEN: - { - enum XML_Error result; - if (startCdataSectionHandler) - startCdataSectionHandler(handlerArg); -#if 0 - /* Suppose you doing a transformation on a document that involves - changing only the character data. You set up a defaultHandler - and a characterDataHandler. The defaultHandler simply copies - characters through. The characterDataHandler does the - transformation and writes the characters out escaping them as - necessary. This case will fail to work if we leave out the - following two lines (because & and < inside CDATA sections will - be incorrectly escaped). - - However, now we have a start/endCdataSectionHandler, so it seems - easier to let the user deal with this. - */ - else if (characterDataHandler) - characterDataHandler(handlerArg, dataBuf, 0); -#endif - else if (defaultHandler) - reportDefault(parser, enc, s, next); - result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); - if (result != XML_ERROR_NONE) - return result; - else if (!next) { - processor = cdataSectionProcessor; - return result; - } - } - break; - case XML_TOK_TRAILING_RSQB: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - if (characterDataHandler) { - if (MUST_CONVERT(enc, s)) { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); - characterDataHandler(handlerArg, dataBuf, - (int)(dataPtr - (ICHAR *)dataBuf)); - } - else - characterDataHandler(handlerArg, - (XML_Char *)s, - (int)((XML_Char *)end - (XML_Char *)s)); - } - else if (defaultHandler) - reportDefault(parser, enc, s, end); - /* We are at the end of the final buffer, should we check for - XML_SUSPENDED, XML_FINISHED? - */ - if (startTagLevel == 0) { - *eventPP = end; - return XML_ERROR_NO_ELEMENTS; - } - if (tagLevel != startTagLevel) { - *eventPP = end; - return XML_ERROR_ASYNC_ENTITY; - } - *nextPtr = end; - return XML_ERROR_NONE; - case XML_TOK_DATA_CHARS: - { - XML_CharacterDataHandler charDataHandler = characterDataHandler; - if (charDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); - *eventEndPP = s; - charDataHandler(handlerArg, dataBuf, - (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) - break; - *eventPP = s; - } - } - else - charDataHandler(handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - } - break; - case XML_TOK_PI: - if (!reportProcessingInstruction(parser, enc, s, next)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_COMMENT: - if (!reportComment(parser, enc, s, next)) - return XML_ERROR_NO_MEMORY; - break; - default: - if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - *eventPP = s = next; - switch (ps_parsing) { - case XML_SUSPENDED: - *nextPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: ; - } - } - /* not reached */ -} - -/* Precondition: all arguments must be non-NULL; - Purpose: - - normalize attributes - - check attributes for well-formedness - - generate namespace aware attribute names (URI, prefix) - - build list of attributes for startElementHandler - - default attributes - - process namespace declarations (check and report them) - - generate namespace aware element name (URI, prefix) -*/ -static enum XML_Error -storeAtts(XML_Parser parser, const ENCODING *enc, - const char *attStr, TAG_NAME *tagNamePtr, - BINDING **bindingsPtr) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - ELEMENT_TYPE *elementType; - int nDefaultAtts; - const XML_Char **appAtts; /* the attribute list for the application */ - int attIndex = 0; - int prefixLen; - int i; - int n; - XML_Char *uri; - int nPrefixes = 0; - BINDING *binding; - const XML_Char *localPart; - - /* lookup the element type name */ - elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); - if (!elementType) { - const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); - if (!name) - return XML_ERROR_NO_MEMORY; - elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, - sizeof(ELEMENT_TYPE)); - if (!elementType) - return XML_ERROR_NO_MEMORY; - if (ns && !setElementTypePrefix(parser, elementType)) - return XML_ERROR_NO_MEMORY; - } - nDefaultAtts = elementType->nDefaultAtts; - - /* get the attributes from the tokenizer */ - n = XmlGetAttributes(enc, attStr, attsSize, atts); - if (n + nDefaultAtts > attsSize) { - int oldAttsSize = attsSize; - ATTRIBUTE *temp; - attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; - temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - atts = temp; - if (n > oldAttsSize) - XmlGetAttributes(enc, attStr, n, atts); - } - - appAtts = (const XML_Char **)atts; - for (i = 0; i < n; i++) { - /* add the name and value to the attribute list */ - ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, - atts[i].name - + XmlNameLength(enc, atts[i].name)); - if (!attId) - return XML_ERROR_NO_MEMORY; - /* Detect duplicate attributes by their QNames. This does not work when - namespace processing is turned on and different prefixes for the same - namespace are used. For this case we have a check further down. - */ - if ((attId->name)[-1]) { - if (enc == encoding) - eventPtr = atts[i].name; - return XML_ERROR_DUPLICATE_ATTRIBUTE; - } - (attId->name)[-1] = 1; - appAtts[attIndex++] = attId->name; - if (!atts[i].normalized) { - enum XML_Error result; - XML_Bool isCdata = XML_TRUE; - - /* figure out whether declared as other than CDATA */ - if (attId->maybeTokenized) { - int j; - for (j = 0; j < nDefaultAtts; j++) { - if (attId == elementType->defaultAtts[j].id) { - isCdata = elementType->defaultAtts[j].isCdata; - break; - } - } - } - - /* normalize the attribute value */ - result = storeAttributeValue(parser, enc, isCdata, - atts[i].valuePtr, atts[i].valueEnd, - &tempPool); - if (result) - return result; - appAtts[attIndex] = poolStart(&tempPool); - poolFinish(&tempPool); - } - else { - /* the value did not need normalizing */ - appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, - atts[i].valueEnd); - if (appAtts[attIndex] == 0) - return XML_ERROR_NO_MEMORY; - poolFinish(&tempPool); - } - /* handle prefixed attribute names */ - if (attId->prefix) { - if (attId->xmlns) { - /* deal with namespace declarations here */ - enum XML_Error result = addBinding(parser, attId->prefix, attId, - appAtts[attIndex], bindingsPtr); - if (result) - return result; - --attIndex; - } - else { - /* deal with other prefixed names later */ - attIndex++; - nPrefixes++; - (attId->name)[-1] = 2; - } - } - else - attIndex++; - } - - /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ - nSpecifiedAtts = attIndex; - if (elementType->idAtt && (elementType->idAtt->name)[-1]) { - for (i = 0; i < attIndex; i += 2) - if (appAtts[i] == elementType->idAtt->name) { - idAttIndex = i; - break; - } - } - else - idAttIndex = -1; - - /* do attribute defaulting */ - for (i = 0; i < nDefaultAtts; i++) { - const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; - if (!(da->id->name)[-1] && da->value) { - if (da->id->prefix) { - if (da->id->xmlns) { - enum XML_Error result = addBinding(parser, da->id->prefix, da->id, - da->value, bindingsPtr); - if (result) - return result; - } - else { - (da->id->name)[-1] = 2; - nPrefixes++; - appAtts[attIndex++] = da->id->name; - appAtts[attIndex++] = da->value; - } - } - else { - (da->id->name)[-1] = 1; - appAtts[attIndex++] = da->id->name; - appAtts[attIndex++] = da->value; - } - } - } - appAtts[attIndex] = 0; - - /* expand prefixed attribute names, check for duplicates, - and clear flags that say whether attributes were specified */ - i = 0; - if (nPrefixes) { - int j; /* hash table index */ - unsigned long version = nsAttsVersion; - int nsAttsSize = (int)1 << nsAttsPower; - /* size of hash table must be at least 2 * (# of prefixed attributes) */ - if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ - NS_ATT *temp; - /* hash table size must also be a power of 2 and >= 8 */ - while (nPrefixes >> nsAttsPower++); - if (nsAttsPower < 3) - nsAttsPower = 3; - nsAttsSize = (int)1 << nsAttsPower; - temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); - if (!temp) - return XML_ERROR_NO_MEMORY; - nsAtts = temp; - version = 0; /* force re-initialization of nsAtts hash table */ - } - /* using a version flag saves us from initializing nsAtts every time */ - if (!version) { /* initialize version flags when version wraps around */ - version = INIT_ATTS_VERSION; - for (j = nsAttsSize; j != 0; ) - nsAtts[--j].version = version; - } - nsAttsVersion = --version; - - /* expand prefixed names and check for duplicates */ - for (; i < attIndex; i += 2) { - const XML_Char *s = appAtts[i]; - if (s[-1] == 2) { /* prefixed */ - ATTRIBUTE_ID *id; - const BINDING *b; - unsigned long uriHash = 0; - ((XML_Char *)s)[-1] = 0; /* clear flag */ - id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); - b = id->prefix->binding; - if (!b) - return XML_ERROR_UNBOUND_PREFIX; - - /* as we expand the name we also calculate its hash value */ - for (j = 0; j < b->uriLen; j++) { - const XML_Char c = b->uri[j]; - if (!poolAppendChar(&tempPool, c)) - return XML_ERROR_NO_MEMORY; - uriHash = CHAR_HASH(uriHash, c); - } - while (*s++ != XML_T(ASCII_COLON)) - ; - do { /* copies null terminator */ - const XML_Char c = *s; - if (!poolAppendChar(&tempPool, *s)) - return XML_ERROR_NO_MEMORY; - uriHash = CHAR_HASH(uriHash, c); - } while (*s++); - - { /* Check hash table for duplicate of expanded name (uriName). - Derived from code in lookup(HASH_TABLE *table, ...). - */ - unsigned char step = 0; - unsigned long mask = nsAttsSize - 1; - j = uriHash & mask; /* index into hash table */ - while (nsAtts[j].version == version) { - /* for speed we compare stored hash values first */ - if (uriHash == nsAtts[j].hash) { - const XML_Char *s1 = poolStart(&tempPool); - const XML_Char *s2 = nsAtts[j].uriName; - /* s1 is null terminated, but not s2 */ - for (; *s1 == *s2 && *s1 != 0; s1++, s2++); - if (*s1 == 0) - return XML_ERROR_DUPLICATE_ATTRIBUTE; - } - if (!step) - step = PROBE_STEP(uriHash, mask, nsAttsPower); - j < step ? (j += nsAttsSize - step) : (j -= step); - } - } - - if (ns_triplets) { /* append namespace separator and prefix */ - tempPool.ptr[-1] = namespaceSeparator; - s = b->prefix->name; - do { - if (!poolAppendChar(&tempPool, *s)) - return XML_ERROR_NO_MEMORY; - } while (*s++); - } - - /* store expanded name in attribute list */ - s = poolStart(&tempPool); - poolFinish(&tempPool); - appAtts[i] = s; - - /* fill empty slot with new version, uriName and hash value */ - nsAtts[j].version = version; - nsAtts[j].hash = uriHash; - nsAtts[j].uriName = s; - - if (!--nPrefixes) { - i += 2; - break; - } - } - else /* not prefixed */ - ((XML_Char *)s)[-1] = 0; /* clear flag */ - } - } - /* clear flags for the remaining attributes */ - for (; i < attIndex; i += 2) - ((XML_Char *)(appAtts[i]))[-1] = 0; - for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) - binding->attId->name[-1] = 0; - - if (!ns) - return XML_ERROR_NONE; - - /* expand the element type name */ - if (elementType->prefix) { - binding = elementType->prefix->binding; - if (!binding) - return XML_ERROR_UNBOUND_PREFIX; - localPart = tagNamePtr->str; - while (*localPart++ != XML_T(ASCII_COLON)) - ; - } - else if (dtd->defaultPrefix.binding) { - binding = dtd->defaultPrefix.binding; - localPart = tagNamePtr->str; - } - else - return XML_ERROR_NONE; - prefixLen = 0; - if (ns_triplets && binding->prefix->name) { - for (; binding->prefix->name[prefixLen++];) - ; /* prefixLen includes null terminator */ - } - tagNamePtr->localPart = localPart; - tagNamePtr->uriLen = binding->uriLen; - tagNamePtr->prefix = binding->prefix->name; - tagNamePtr->prefixLen = prefixLen; - for (i = 0; localPart[i++];) - ; /* i includes null terminator */ - n = i + binding->uriLen + prefixLen; - if (n > binding->uriAlloc) { - TAG *p; - uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); - if (!uri) - return XML_ERROR_NO_MEMORY; - binding->uriAlloc = n + EXPAND_SPARE; - memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); - for (p = tagStack; p; p = p->parent) - if (p->name.str == binding->uri) - p->name.str = uri; - FREE(binding->uri); - binding->uri = uri; - } - /* if namespaceSeparator != '\0' then uri includes it already */ - uri = binding->uri + binding->uriLen; - memcpy(uri, localPart, i * sizeof(XML_Char)); - /* we always have a namespace separator between localPart and prefix */ - if (prefixLen) { - uri += i - 1; - *uri = namespaceSeparator; /* replace null terminator */ - memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); - } - tagNamePtr->str = binding->uri; - return XML_ERROR_NONE; -} - -/* addBinding() overwrites the value of prefix->binding without checking. - Therefore one must keep track of the old value outside of addBinding(). -*/ -static enum XML_Error -addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, - const XML_Char *uri, BINDING **bindingsPtr) -{ - static const XML_Char xmlNamespace[] = { - ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, - ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, - ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, - ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, - ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, - ASCII_e, '\0' - }; - static const int xmlLen = - (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; - static const XML_Char xmlnsNamespace[] = { - ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, - ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, - ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, - ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, - ASCII_SLASH, '\0' - }; - static const int xmlnsLen = - (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; - - XML_Bool mustBeXML = XML_FALSE; - XML_Bool isXML = XML_TRUE; - XML_Bool isXMLNS = XML_TRUE; - - BINDING *b; - int len; - - /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ - if (*uri == XML_T('\0') && prefix->name) - return XML_ERROR_UNDECLARING_PREFIX; - - if (prefix->name - && prefix->name[0] == XML_T(ASCII_x) - && prefix->name[1] == XML_T(ASCII_m) - && prefix->name[2] == XML_T(ASCII_l)) { - - /* Not allowed to bind xmlns */ - if (prefix->name[3] == XML_T(ASCII_n) - && prefix->name[4] == XML_T(ASCII_s) - && prefix->name[5] == XML_T('\0')) - return XML_ERROR_RESERVED_PREFIX_XMLNS; - - if (prefix->name[3] == XML_T('\0')) - mustBeXML = XML_TRUE; - } - - for (len = 0; uri[len]; len++) { - if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) - isXML = XML_FALSE; - - if (!mustBeXML && isXMLNS - && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) - isXMLNS = XML_FALSE; - } - isXML = isXML && len == xmlLen; - isXMLNS = isXMLNS && len == xmlnsLen; - - if (mustBeXML != isXML) - return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML - : XML_ERROR_RESERVED_NAMESPACE_URI; - - if (isXMLNS) - return XML_ERROR_RESERVED_NAMESPACE_URI; - - if (namespaceSeparator) - len++; - if (freeBindingList) { - b = freeBindingList; - if (len > b->uriAlloc) { - XML_Char *temp = (XML_Char *)REALLOC(b->uri, - sizeof(XML_Char) * (len + EXPAND_SPARE)); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - b->uri = temp; - b->uriAlloc = len + EXPAND_SPARE; - } - freeBindingList = b->nextTagBinding; - } - else { - b = (BINDING *)MALLOC(sizeof(BINDING)); - if (!b) - return XML_ERROR_NO_MEMORY; - b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); - if (!b->uri) { - FREE(b); - return XML_ERROR_NO_MEMORY; - } - b->uriAlloc = len + EXPAND_SPARE; - } - b->uriLen = len; - memcpy(b->uri, uri, len * sizeof(XML_Char)); - if (namespaceSeparator) - b->uri[len - 1] = namespaceSeparator; - b->prefix = prefix; - b->attId = attId; - b->prevPrefixBinding = prefix->binding; - /* NULL binding when default namespace undeclared */ - if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) - prefix->binding = NULL; - else - prefix->binding = b; - b->nextTagBinding = *bindingsPtr; - *bindingsPtr = b; - /* if attId == NULL then we are not starting a namespace scope */ - if (attId && startNamespaceDeclHandler) - startNamespaceDeclHandler(handlerArg, prefix->name, - prefix->binding ? uri : 0); - return XML_ERROR_NONE; -} - -/* The idea here is to avoid using stack for each CDATA section when - the whole file is parsed with one call. -*/ -static enum XML_Error PTRCALL -cdataSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doCdataSection(parser, encoding, &start, end, - endPtr, (XML_Bool)!ps_finalBuffer); - if (result != XML_ERROR_NONE) - return result; - if (start) { - if (parentParser) { /* we are parsing an external entity */ - processor = externalEntityContentProcessor; - return externalEntityContentProcessor(parser, start, end, endPtr); - } - else { - processor = contentProcessor; - return contentProcessor(parser, start, end, endPtr); - } - } - return result; -} - -/* startPtr gets set to non-null if the section is closed, and to null if - the section is not yet closed. -*/ -static enum XML_Error -doCdataSection(XML_Parser parser, - const ENCODING *enc, - const char **startPtr, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ - const char *s = *startPtr; - const char **eventPP; - const char **eventEndPP; - if (enc == encoding) { - eventPP = &eventPtr; - *eventPP = s; - eventEndPP = &eventEndPtr; - } - else { - eventPP = &(openInternalEntities->internalEventPtr); - eventEndPP = &(openInternalEntities->internalEventEndPtr); - } - *eventPP = s; - *startPtr = NULL; - - for (;;) { - const char *next; - int tok = XmlCdataSectionTok(enc, s, end, &next); - *eventEndPP = next; - switch (tok) { - case XML_TOK_CDATA_SECT_CLOSE: - if (endCdataSectionHandler) - endCdataSectionHandler(handlerArg); -#if 0 - /* see comment under XML_TOK_CDATA_SECT_OPEN */ - else if (characterDataHandler) - characterDataHandler(handlerArg, dataBuf, 0); -#endif - else if (defaultHandler) - reportDefault(parser, enc, s, next); - *startPtr = next; - *nextPtr = next; - if (ps_parsing == XML_FINISHED) - return XML_ERROR_ABORTED; - else - return XML_ERROR_NONE; - case XML_TOK_DATA_NEWLINE: - if (characterDataHandler) { - XML_Char c = 0xA; - characterDataHandler(handlerArg, &c, 1); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - break; - case XML_TOK_DATA_CHARS: - { - XML_CharacterDataHandler charDataHandler = characterDataHandler; - if (charDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); - *eventEndPP = next; - charDataHandler(handlerArg, dataBuf, - (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) - break; - *eventPP = s; - } - } - else - charDataHandler(handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); - } - else if (defaultHandler) - reportDefault(parser, enc, s, next); - } - break; - case XML_TOK_INVALID: - *eventPP = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_PARTIAL: - case XML_TOK_NONE: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_UNCLOSED_CDATA_SECTION; - default: - *eventPP = next; - return XML_ERROR_UNEXPECTED_STATE; - } - - *eventPP = s = next; - switch (ps_parsing) { - case XML_SUSPENDED: - *nextPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: ; - } - } - /* not reached */ -} - -#ifdef XML_DTD - -/* The idea here is to avoid using stack for each IGNORE section when - the whole file is parsed with one call. -*/ -static enum XML_Error PTRCALL -ignoreSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, - endPtr, (XML_Bool)!ps_finalBuffer); - if (result != XML_ERROR_NONE) - return result; - if (start) { - processor = prologProcessor; - return prologProcessor(parser, start, end, endPtr); - } - return result; -} - -/* startPtr gets set to non-null is the section is closed, and to null - if the section is not yet closed. -*/ -static enum XML_Error -doIgnoreSection(XML_Parser parser, - const ENCODING *enc, - const char **startPtr, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ - const char *next; - int tok; - const char *s = *startPtr; - const char **eventPP; - const char **eventEndPP; - if (enc == encoding) { - eventPP = &eventPtr; - *eventPP = s; - eventEndPP = &eventEndPtr; - } - else { - eventPP = &(openInternalEntities->internalEventPtr); - eventEndPP = &(openInternalEntities->internalEventEndPtr); - } - *eventPP = s; - *startPtr = NULL; - tok = XmlIgnoreSectionTok(enc, s, end, &next); - *eventEndPP = next; - switch (tok) { - case XML_TOK_IGNORE_SECT: - if (defaultHandler) - reportDefault(parser, enc, s, next); - *startPtr = next; - *nextPtr = next; - if (ps_parsing == XML_FINISHED) - return XML_ERROR_ABORTED; - else - return XML_ERROR_NONE; - case XML_TOK_INVALID: - *eventPP = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_PARTIAL: - case XML_TOK_NONE: - if (haveMore) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ - default: - *eventPP = next; - return XML_ERROR_UNEXPECTED_STATE; - } - /* not reached */ -} - -#endif /* XML_DTD */ - -static enum XML_Error -initializeEncoding(XML_Parser parser) -{ - const char *s; -#ifdef XML_UNICODE - char encodingBuf[128]; - if (!protocolEncodingName) - s = NULL; - else { - int i; - for (i = 0; protocolEncodingName[i]; i++) { - if (i == sizeof(encodingBuf) - 1 - || (protocolEncodingName[i] & ~0x7f) != 0) { - encodingBuf[0] = '\0'; - break; - } - encodingBuf[i] = (char)protocolEncodingName[i]; - } - encodingBuf[i] = '\0'; - s = encodingBuf; - } -#else - s = protocolEncodingName; -#endif - if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) - return XML_ERROR_NONE; - return handleUnknownEncoding(parser, protocolEncodingName); -} - -static enum XML_Error -processXmlDecl(XML_Parser parser, int isGeneralTextEntity, - const char *s, const char *next) -{ - const char *encodingName = NULL; - const XML_Char *storedEncName = NULL; - const ENCODING *newEncoding = NULL; - const char *version = NULL; - const char *versionend; - const XML_Char *storedversion = NULL; - int standalone = -1; - if (!(ns - ? XmlParseXmlDeclNS - : XmlParseXmlDecl)(isGeneralTextEntity, - encoding, - s, - next, - &eventPtr, - &version, - &versionend, - &encodingName, - &newEncoding, - &standalone)) { - if (isGeneralTextEntity) - return XML_ERROR_TEXT_DECL; - else - return XML_ERROR_XML_DECL; - } - if (!isGeneralTextEntity && standalone == 1) { - _dtd->standalone = XML_TRUE; -#ifdef XML_DTD - if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) - paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; -#endif /* XML_DTD */ - } - if (xmlDeclHandler) { - if (encodingName != NULL) { - storedEncName = poolStoreString(&temp2Pool, - encoding, - encodingName, - encodingName - + XmlNameLength(encoding, encodingName)); - if (!storedEncName) - return XML_ERROR_NO_MEMORY; - poolFinish(&temp2Pool); - } - if (version) { - storedversion = poolStoreString(&temp2Pool, - encoding, - version, - versionend - encoding->minBytesPerChar); - if (!storedversion) - return XML_ERROR_NO_MEMORY; - } - xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); - } - else if (defaultHandler) - reportDefault(parser, encoding, s, next); - if (protocolEncodingName == NULL) { - if (newEncoding) { - if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) { - eventPtr = encodingName; - return XML_ERROR_INCORRECT_ENCODING; - } - encoding = newEncoding; - } - else if (encodingName) { - enum XML_Error result; - if (!storedEncName) { - storedEncName = poolStoreString( - &temp2Pool, encoding, encodingName, - encodingName + XmlNameLength(encoding, encodingName)); - if (!storedEncName) - return XML_ERROR_NO_MEMORY; - } - result = handleUnknownEncoding(parser, storedEncName); - poolClear(&temp2Pool); - if (result == XML_ERROR_UNKNOWN_ENCODING) - eventPtr = encodingName; - return result; - } - } - - if (storedEncName || storedversion) - poolClear(&temp2Pool); - - return XML_ERROR_NONE; -} - -static enum XML_Error -handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) -{ - if (unknownEncodingHandler) { - XML_Encoding info; - int i; - for (i = 0; i < 256; i++) - info.map[i] = -1; - info.convert = NULL; - info.data = NULL; - info.release = NULL; - if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, - &info)) { - ENCODING *enc; - unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding()); - if (!unknownEncodingMem) { - if (info.release) - info.release(info.data); - return XML_ERROR_NO_MEMORY; - } - enc = (ns - ? XmlInitUnknownEncodingNS - : XmlInitUnknownEncoding)(unknownEncodingMem, - info.map, - info.convert, - info.data); - if (enc) { - unknownEncodingData = info.data; - unknownEncodingRelease = info.release; - encoding = enc; - return XML_ERROR_NONE; - } - } - if (info.release != NULL) - info.release(info.data); - } - return XML_ERROR_UNKNOWN_ENCODING; -} - -static enum XML_Error PTRCALL -prologInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - enum XML_Error result = initializeEncoding(parser); - if (result != XML_ERROR_NONE) - return result; - processor = prologProcessor; - return prologProcessor(parser, s, end, nextPtr); -} - -#ifdef XML_DTD - -static enum XML_Error PTRCALL -externalParEntInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - enum XML_Error result = initializeEncoding(parser); - if (result != XML_ERROR_NONE) - return result; - - /* we know now that XML_Parse(Buffer) has been called, - so we consider the external parameter entity read */ - _dtd->paramEntityRead = XML_TRUE; - - if (prologState.inEntityValue) { - processor = entityValueInitProcessor; - return entityValueInitProcessor(parser, s, end, nextPtr); - } - else { - processor = externalParEntProcessor; - return externalParEntProcessor(parser, s, end, nextPtr); - } -} - -static enum XML_Error PTRCALL -entityValueInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - int tok; - const char *start = s; - const char *next = start; - eventPtr = start; - - for (;;) { - tok = XmlPrologTok(encoding, start, end, &next); - eventEndPtr = next; - if (tok <= 0) { - if (!ps_finalBuffer && tok != XML_TOK_INVALID) { - *nextPtr = s; - return XML_ERROR_NONE; - } - switch (tok) { - case XML_TOK_INVALID: - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ - default: - break; - } - /* found end of entity value - can store it now */ - return storeEntityValue(parser, encoding, s, end); - } - else if (tok == XML_TOK_XML_DECL) { - enum XML_Error result; - result = processXmlDecl(parser, 0, start, next); - if (result != XML_ERROR_NONE) - return result; - switch (ps_parsing) { - case XML_SUSPENDED: - *nextPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: - *nextPtr = next; - } - /* stop scanning for text declaration - we found one */ - processor = entityValueProcessor; - return entityValueProcessor(parser, next, end, nextPtr); - } - /* If we are at the end of the buffer, this would cause XmlPrologTok to - return XML_TOK_NONE on the next call, which would then cause the - function to exit with *nextPtr set to s - that is what we want for other - tokens, but not for the BOM - we would rather like to skip it; - then, when this routine is entered the next time, XmlPrologTok will - return XML_TOK_INVALID, since the BOM is still in the buffer - */ - else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { - *nextPtr = next; - return XML_ERROR_NONE; - } - start = next; - eventPtr = start; - } -} - -static enum XML_Error PTRCALL -externalParEntProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - const char *next = s; - int tok; - - tok = XmlPrologTok(encoding, s, end, &next); - if (tok <= 0) { - if (!ps_finalBuffer && tok != XML_TOK_INVALID) { - *nextPtr = s; - return XML_ERROR_NONE; - } - switch (tok) { - case XML_TOK_INVALID: - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ - default: - break; - } - } - /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. - However, when parsing an external subset, doProlog will not accept a BOM - as valid, and report a syntax error, so we have to skip the BOM - */ - else if (tok == XML_TOK_BOM) { - s = next; - tok = XmlPrologTok(encoding, s, end, &next); - } - - processor = prologProcessor; - return doProlog(parser, encoding, s, end, tok, next, - nextPtr, (XML_Bool)!ps_finalBuffer); -} - -static enum XML_Error PTRCALL -entityValueProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - const char *start = s; - const char *next = s; - const ENCODING *enc = encoding; - int tok; - - for (;;) { - tok = XmlPrologTok(enc, start, end, &next); - if (tok <= 0) { - if (!ps_finalBuffer && tok != XML_TOK_INVALID) { - *nextPtr = s; - return XML_ERROR_NONE; - } - switch (tok) { - case XML_TOK_INVALID: - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ - default: - break; - } - /* found end of entity value - can store it now */ - return storeEntityValue(parser, enc, s, end); - } - start = next; - } -} - -#endif /* XML_DTD */ - -static enum XML_Error PTRCALL -prologProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - const char *next = s; - int tok = XmlPrologTok(encoding, s, end, &next); - return doProlog(parser, encoding, s, end, tok, next, - nextPtr, (XML_Bool)!ps_finalBuffer); -} - -static enum XML_Error -doProlog(XML_Parser parser, - const ENCODING *enc, - const char *s, - const char *end, - int tok, - const char *next, - const char **nextPtr, - XML_Bool haveMore) -{ -#ifdef XML_DTD - static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; -#endif /* XML_DTD */ - static const XML_Char atypeCDATA[] = - { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; - static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; - static const XML_Char atypeIDREF[] = - { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; - static const XML_Char atypeIDREFS[] = - { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; - static const XML_Char atypeENTITY[] = - { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; - static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, - ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; - static const XML_Char atypeNMTOKEN[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; - static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, - ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; - static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, - ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; - static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; - static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; - - /* save one level of indirection */ - DTD * const dtd = _dtd; - - const char **eventPP; - const char **eventEndPP; - enum XML_Content_Quant quant; - - if (enc == encoding) { - eventPP = &eventPtr; - eventEndPP = &eventEndPtr; - } - else { - eventPP = &(openInternalEntities->internalEventPtr); - eventEndPP = &(openInternalEntities->internalEventEndPtr); - } - - for (;;) { - int role; - XML_Bool handleDefault = XML_TRUE; - *eventPP = s; - *eventEndPP = next; - if (tok <= 0) { - if (haveMore && tok != XML_TOK_INVALID) { - *nextPtr = s; - return XML_ERROR_NONE; - } - switch (tok) { - case XML_TOK_INVALID: - *eventPP = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: -#ifdef XML_DTD - /* for internal PE NOT referenced between declarations */ - if (enc != encoding && !openInternalEntities->betweenDecl) { - *nextPtr = s; - return XML_ERROR_NONE; - } - /* WFC: PE Between Declarations - must check that PE contains - complete markup, not only for external PEs, but also for - internal PEs if the reference occurs between declarations. - */ - if (isParamEntity || enc != encoding) { - if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) - == XML_ROLE_ERROR) - return XML_ERROR_INCOMPLETE_PE; - *nextPtr = s; - return XML_ERROR_NONE; - } -#endif /* XML_DTD */ - return XML_ERROR_NO_ELEMENTS; - default: - tok = -tok; - next = end; - break; - } - } - role = XmlTokenRole(&prologState, tok, s, next, enc); - switch (role) { - case XML_ROLE_XML_DECL: - { - enum XML_Error result = processXmlDecl(parser, 0, s, next); - if (result != XML_ERROR_NONE) - return result; - enc = encoding; - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_DOCTYPE_NAME: - if (startDoctypeDeclHandler) { - doctypeName = poolStoreString(&tempPool, enc, s, next); - if (!doctypeName) - return XML_ERROR_NO_MEMORY; - poolFinish(&tempPool); - doctypePubid = NULL; - handleDefault = XML_FALSE; - } - doctypeSysid = NULL; /* always initialize to NULL */ - break; - case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: - if (startDoctypeDeclHandler) { - startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid, - doctypePubid, 1); - doctypeName = NULL; - poolClear(&tempPool); - handleDefault = XML_FALSE; - } - break; -#ifdef XML_DTD - case XML_ROLE_TEXT_DECL: - { - enum XML_Error result = processXmlDecl(parser, 1, s, next); - if (result != XML_ERROR_NONE) - return result; - enc = encoding; - handleDefault = XML_FALSE; - } - break; -#endif /* XML_DTD */ - case XML_ROLE_DOCTYPE_PUBLIC_ID: -#ifdef XML_DTD - useForeignDTD = XML_FALSE; - declEntity = (ENTITY *)lookup(&dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!declEntity) - return XML_ERROR_NO_MEMORY; -#endif /* XML_DTD */ - dtd->hasParamEntityRefs = XML_TRUE; - if (startDoctypeDeclHandler) { - if (!XmlIsPublicId(enc, s, next, eventPP)) - return XML_ERROR_PUBLICID; - doctypePubid = poolStoreString(&tempPool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!doctypePubid) - return XML_ERROR_NO_MEMORY; - normalizePublicId((XML_Char *)doctypePubid); - poolFinish(&tempPool); - handleDefault = XML_FALSE; - goto alreadyChecked; - } - /* fall through */ - case XML_ROLE_ENTITY_PUBLIC_ID: - if (!XmlIsPublicId(enc, s, next, eventPP)) - return XML_ERROR_PUBLICID; - alreadyChecked: - if (dtd->keepProcessing && declEntity) { - XML_Char *tem = poolStoreString(&dtd->pool, - enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!tem) - return XML_ERROR_NO_MEMORY; - normalizePublicId(tem); - declEntity->publicId = tem; - poolFinish(&dtd->pool); - if (entityDeclHandler) - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_DOCTYPE_CLOSE: - if (doctypeName) { - startDoctypeDeclHandler(handlerArg, doctypeName, - doctypeSysid, doctypePubid, 0); - poolClear(&tempPool); - handleDefault = XML_FALSE; - } - /* doctypeSysid will be non-NULL in the case of a previous - XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler - was not set, indicating an external subset - */ -#ifdef XML_DTD - if (doctypeSysid || useForeignDTD) { - XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; - dtd->hasParamEntityRefs = XML_TRUE; - if (paramEntityParsing && externalEntityRefHandler) { - ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!entity) - return XML_ERROR_NO_MEMORY; - if (useForeignDTD) - entity->base = curBase; - dtd->paramEntityRead = XML_FALSE; - if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - if (dtd->paramEntityRead) { - if (!dtd->standalone && - notStandaloneHandler && - !notStandaloneHandler(handlerArg)) - return XML_ERROR_NOT_STANDALONE; - } - /* if we didn't read the foreign DTD then this means that there - is no external subset and we must reset dtd->hasParamEntityRefs - */ - else if (!doctypeSysid) - dtd->hasParamEntityRefs = hadParamEntityRefs; - /* end of DTD - no need to update dtd->keepProcessing */ - } - useForeignDTD = XML_FALSE; - } -#endif /* XML_DTD */ - if (endDoctypeDeclHandler) { - endDoctypeDeclHandler(handlerArg); - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_INSTANCE_START: -#ifdef XML_DTD - /* if there is no DOCTYPE declaration then now is the - last chance to read the foreign DTD - */ - if (useForeignDTD) { - XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; - dtd->hasParamEntityRefs = XML_TRUE; - if (paramEntityParsing && externalEntityRefHandler) { - ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!entity) - return XML_ERROR_NO_MEMORY; - entity->base = curBase; - dtd->paramEntityRead = XML_FALSE; - if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - if (dtd->paramEntityRead) { - if (!dtd->standalone && - notStandaloneHandler && - !notStandaloneHandler(handlerArg)) - return XML_ERROR_NOT_STANDALONE; - } - /* if we didn't read the foreign DTD then this means that there - is no external subset and we must reset dtd->hasParamEntityRefs - */ - else - dtd->hasParamEntityRefs = hadParamEntityRefs; - /* end of DTD - no need to update dtd->keepProcessing */ - } - } -#endif /* XML_DTD */ - processor = contentProcessor; - return contentProcessor(parser, s, end, nextPtr); - case XML_ROLE_ATTLIST_ELEMENT_NAME: - declElementType = getElementType(parser, enc, s, next); - if (!declElementType) - return XML_ERROR_NO_MEMORY; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_NAME: - declAttributeId = getAttributeId(parser, enc, s, next); - if (!declAttributeId) - return XML_ERROR_NO_MEMORY; - declAttributeIsCdata = XML_FALSE; - declAttributeType = NULL; - declAttributeIsId = XML_FALSE; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_CDATA: - declAttributeIsCdata = XML_TRUE; - declAttributeType = atypeCDATA; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_ID: - declAttributeIsId = XML_TRUE; - declAttributeType = atypeID; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_IDREF: - declAttributeType = atypeIDREF; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_IDREFS: - declAttributeType = atypeIDREFS; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_ENTITY: - declAttributeType = atypeENTITY; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES: - declAttributeType = atypeENTITIES; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: - declAttributeType = atypeNMTOKEN; - goto checkAttListDeclHandler; - case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: - declAttributeType = atypeNMTOKENS; - checkAttListDeclHandler: - if (dtd->keepProcessing && attlistDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_ATTRIBUTE_ENUM_VALUE: - case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: - if (dtd->keepProcessing && attlistDeclHandler) { - const XML_Char *prefix; - if (declAttributeType) { - prefix = enumValueSep; - } - else { - prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE - ? notationPrefix - : enumValueStart); - } - if (!poolAppendString(&tempPool, prefix)) - return XML_ERROR_NO_MEMORY; - if (!poolAppend(&tempPool, enc, s, next)) - return XML_ERROR_NO_MEMORY; - declAttributeType = tempPool.start; - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: - case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: - if (dtd->keepProcessing) { - if (!defineAttribute(declElementType, declAttributeId, - declAttributeIsCdata, declAttributeIsId, - 0, parser)) - return XML_ERROR_NO_MEMORY; - if (attlistDeclHandler && declAttributeType) { - if (*declAttributeType == XML_T(ASCII_LPAREN) - || (*declAttributeType == XML_T(ASCII_N) - && declAttributeType[1] == XML_T(ASCII_O))) { - /* Enumerated or Notation type */ - if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) - || !poolAppendChar(&tempPool, XML_T('\0'))) - return XML_ERROR_NO_MEMORY; - declAttributeType = tempPool.start; - poolFinish(&tempPool); - } - *eventEndPP = s; - attlistDeclHandler(handlerArg, declElementType->name, - declAttributeId->name, declAttributeType, - 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); - poolClear(&tempPool); - handleDefault = XML_FALSE; - } - } - break; - case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: - case XML_ROLE_FIXED_ATTRIBUTE_VALUE: - if (dtd->keepProcessing) { - const XML_Char *attVal; - enum XML_Error result = - storeAttributeValue(parser, enc, declAttributeIsCdata, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar, - &dtd->pool); - if (result) - return result; - attVal = poolStart(&dtd->pool); - poolFinish(&dtd->pool); - /* ID attributes aren't allowed to have a default */ - if (!defineAttribute(declElementType, declAttributeId, - declAttributeIsCdata, XML_FALSE, attVal, parser)) - return XML_ERROR_NO_MEMORY; - if (attlistDeclHandler && declAttributeType) { - if (*declAttributeType == XML_T(ASCII_LPAREN) - || (*declAttributeType == XML_T(ASCII_N) - && declAttributeType[1] == XML_T(ASCII_O))) { - /* Enumerated or Notation type */ - if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) - || !poolAppendChar(&tempPool, XML_T('\0'))) - return XML_ERROR_NO_MEMORY; - declAttributeType = tempPool.start; - poolFinish(&tempPool); - } - *eventEndPP = s; - attlistDeclHandler(handlerArg, declElementType->name, - declAttributeId->name, declAttributeType, - attVal, - role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); - poolClear(&tempPool); - handleDefault = XML_FALSE; - } - } - break; - case XML_ROLE_ENTITY_VALUE: - if (dtd->keepProcessing) { - enum XML_Error result = storeEntityValue(parser, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (declEntity) { - declEntity->textPtr = poolStart(&dtd->entityValuePool); - declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); - poolFinish(&dtd->entityValuePool); - if (entityDeclHandler) { - *eventEndPP = s; - entityDeclHandler(handlerArg, - declEntity->name, - declEntity->is_param, - declEntity->textPtr, - declEntity->textLen, - curBase, 0, 0, 0); - handleDefault = XML_FALSE; - } - } - else - poolDiscard(&dtd->entityValuePool); - if (result != XML_ERROR_NONE) - return result; - } - break; - case XML_ROLE_DOCTYPE_SYSTEM_ID: -#ifdef XML_DTD - useForeignDTD = XML_FALSE; -#endif /* XML_DTD */ - dtd->hasParamEntityRefs = XML_TRUE; - if (startDoctypeDeclHandler) { - doctypeSysid = poolStoreString(&tempPool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (doctypeSysid == NULL) - return XML_ERROR_NO_MEMORY; - poolFinish(&tempPool); - handleDefault = XML_FALSE; - } -#ifdef XML_DTD - else - /* use externalSubsetName to make doctypeSysid non-NULL - for the case where no startDoctypeDeclHandler is set */ - doctypeSysid = externalSubsetName; -#endif /* XML_DTD */ - if (!dtd->standalone -#ifdef XML_DTD - && !paramEntityParsing -#endif /* XML_DTD */ - && notStandaloneHandler - && !notStandaloneHandler(handlerArg)) - return XML_ERROR_NOT_STANDALONE; -#ifndef XML_DTD - break; -#else /* XML_DTD */ - if (!declEntity) { - declEntity = (ENTITY *)lookup(&dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!declEntity) - return XML_ERROR_NO_MEMORY; - declEntity->publicId = NULL; - } - /* fall through */ -#endif /* XML_DTD */ - case XML_ROLE_ENTITY_SYSTEM_ID: - if (dtd->keepProcessing && declEntity) { - declEntity->systemId = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!declEntity->systemId) - return XML_ERROR_NO_MEMORY; - declEntity->base = curBase; - poolFinish(&dtd->pool); - if (entityDeclHandler) - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_ENTITY_COMPLETE: - if (dtd->keepProcessing && declEntity && entityDeclHandler) { - *eventEndPP = s; - entityDeclHandler(handlerArg, - declEntity->name, - declEntity->is_param, - 0,0, - declEntity->base, - declEntity->systemId, - declEntity->publicId, - 0); - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_ENTITY_NOTATION_NAME: - if (dtd->keepProcessing && declEntity) { - declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); - if (!declEntity->notation) - return XML_ERROR_NO_MEMORY; - poolFinish(&dtd->pool); - if (unparsedEntityDeclHandler) { - *eventEndPP = s; - unparsedEntityDeclHandler(handlerArg, - declEntity->name, - declEntity->base, - declEntity->systemId, - declEntity->publicId, - declEntity->notation); - handleDefault = XML_FALSE; - } - else if (entityDeclHandler) { - *eventEndPP = s; - entityDeclHandler(handlerArg, - declEntity->name, - 0,0,0, - declEntity->base, - declEntity->systemId, - declEntity->publicId, - declEntity->notation); - handleDefault = XML_FALSE; - } - } - break; - case XML_ROLE_GENERAL_ENTITY_NAME: - { - if (XmlPredefinedEntityName(enc, s, next)) { - declEntity = NULL; - break; - } - if (dtd->keepProcessing) { - const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); - if (!name) - return XML_ERROR_NO_MEMORY; - declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, - sizeof(ENTITY)); - if (!declEntity) - return XML_ERROR_NO_MEMORY; - if (declEntity->name != name) { - poolDiscard(&dtd->pool); - declEntity = NULL; - } - else { - poolFinish(&dtd->pool); - declEntity->publicId = NULL; - declEntity->is_param = XML_FALSE; - /* if we have a parent parser or are reading an internal parameter - entity, then the entity declaration is not considered "internal" - */ - declEntity->is_internal = !(parentParser || openInternalEntities); - if (entityDeclHandler) - handleDefault = XML_FALSE; - } - } - else { - poolDiscard(&dtd->pool); - declEntity = NULL; - } - } - break; - case XML_ROLE_PARAM_ENTITY_NAME: -#ifdef XML_DTD - if (dtd->keepProcessing) { - const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); - if (!name) - return XML_ERROR_NO_MEMORY; - declEntity = (ENTITY *)lookup(&dtd->paramEntities, - name, sizeof(ENTITY)); - if (!declEntity) - return XML_ERROR_NO_MEMORY; - if (declEntity->name != name) { - poolDiscard(&dtd->pool); - declEntity = NULL; - } - else { - poolFinish(&dtd->pool); - declEntity->publicId = NULL; - declEntity->is_param = XML_TRUE; - /* if we have a parent parser or are reading an internal parameter - entity, then the entity declaration is not considered "internal" - */ - declEntity->is_internal = !(parentParser || openInternalEntities); - if (entityDeclHandler) - handleDefault = XML_FALSE; - } - } - else { - poolDiscard(&dtd->pool); - declEntity = NULL; - } -#else /* not XML_DTD */ - declEntity = NULL; -#endif /* XML_DTD */ - break; - case XML_ROLE_NOTATION_NAME: - declNotationPublicId = NULL; - declNotationName = NULL; - if (notationDeclHandler) { - declNotationName = poolStoreString(&tempPool, enc, s, next); - if (!declNotationName) - return XML_ERROR_NO_MEMORY; - poolFinish(&tempPool); - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_NOTATION_PUBLIC_ID: - if (!XmlIsPublicId(enc, s, next, eventPP)) - return XML_ERROR_PUBLICID; - if (declNotationName) { /* means notationDeclHandler != NULL */ - XML_Char *tem = poolStoreString(&tempPool, - enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!tem) - return XML_ERROR_NO_MEMORY; - normalizePublicId(tem); - declNotationPublicId = tem; - poolFinish(&tempPool); - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_NOTATION_SYSTEM_ID: - if (declNotationName && notationDeclHandler) { - const XML_Char *systemId - = poolStoreString(&tempPool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!systemId) - return XML_ERROR_NO_MEMORY; - *eventEndPP = s; - notationDeclHandler(handlerArg, - declNotationName, - curBase, - systemId, - declNotationPublicId); - handleDefault = XML_FALSE; - } - poolClear(&tempPool); - break; - case XML_ROLE_NOTATION_NO_SYSTEM_ID: - if (declNotationPublicId && notationDeclHandler) { - *eventEndPP = s; - notationDeclHandler(handlerArg, - declNotationName, - curBase, - 0, - declNotationPublicId); - handleDefault = XML_FALSE; - } - poolClear(&tempPool); - break; - case XML_ROLE_ERROR: - switch (tok) { - case XML_TOK_PARAM_ENTITY_REF: - /* PE references in internal subset are - not allowed within declarations. */ - return XML_ERROR_PARAM_ENTITY_REF; - case XML_TOK_XML_DECL: - return XML_ERROR_MISPLACED_XML_PI; - default: - return XML_ERROR_SYNTAX; - } -#ifdef XML_DTD - case XML_ROLE_IGNORE_SECT: - { - enum XML_Error result; - if (defaultHandler) - reportDefault(parser, enc, s, next); - handleDefault = XML_FALSE; - result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); - if (result != XML_ERROR_NONE) - return result; - else if (!next) { - processor = ignoreSectionProcessor; - return result; - } - } - break; -#endif /* XML_DTD */ - case XML_ROLE_GROUP_OPEN: - if (prologState.level >= groupSize) { - if (groupSize) { - char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - groupConnector = temp; - if (dtd->scaffIndex) { - int *temp = (int *)REALLOC(dtd->scaffIndex, - groupSize * sizeof(int)); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - dtd->scaffIndex = temp; - } - } - else { - groupConnector = (char *)MALLOC(groupSize = 32); - if (!groupConnector) - return XML_ERROR_NO_MEMORY; - } - } - groupConnector[prologState.level] = 0; - if (dtd->in_eldecl) { - int myindex = nextScaffoldPart(parser); - if (myindex < 0) - return XML_ERROR_NO_MEMORY; - dtd->scaffIndex[dtd->scaffLevel] = myindex; - dtd->scaffLevel++; - dtd->scaffold[myindex].type = XML_CTYPE_SEQ; - if (elementDeclHandler) - handleDefault = XML_FALSE; - } - break; - case XML_ROLE_GROUP_SEQUENCE: - if (groupConnector[prologState.level] == ASCII_PIPE) - return XML_ERROR_SYNTAX; - groupConnector[prologState.level] = ASCII_COMMA; - if (dtd->in_eldecl && elementDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_GROUP_CHOICE: - if (groupConnector[prologState.level] == ASCII_COMMA) - return XML_ERROR_SYNTAX; - if (dtd->in_eldecl - && !groupConnector[prologState.level] - && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type - != XML_CTYPE_MIXED) - ) { - dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type - = XML_CTYPE_CHOICE; - if (elementDeclHandler) - handleDefault = XML_FALSE; - } - groupConnector[prologState.level] = ASCII_PIPE; - break; - case XML_ROLE_PARAM_ENTITY_REF: -#ifdef XML_DTD - case XML_ROLE_INNER_PARAM_ENTITY_REF: - dtd->hasParamEntityRefs = XML_TRUE; - if (!paramEntityParsing) - dtd->keepProcessing = dtd->standalone; - else { - const XML_Char *name; - ENTITY *entity; - name = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) - return XML_ERROR_NO_MEMORY; - entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); - poolDiscard(&dtd->pool); - /* first, determine if a check for an existing declaration is needed; - if yes, check that the entity exists, and that it is internal, - otherwise call the skipped entity handler - */ - if (prologState.documentEntity && - (dtd->standalone - ? !openInternalEntities - : !dtd->hasParamEntityRefs)) { - if (!entity) - return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) - return XML_ERROR_ENTITY_DECLARED_IN_PE; - } - else if (!entity) { - dtd->keepProcessing = dtd->standalone; - /* cannot report skipped entities in declarations */ - if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { - skippedEntityHandler(handlerArg, name, 1); - handleDefault = XML_FALSE; - } - break; - } - if (entity->open) - return XML_ERROR_RECURSIVE_ENTITY_REF; - if (entity->textPtr) { - enum XML_Error result; - XML_Bool betweenDecl = - (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); - result = processInternalEntity(parser, entity, betweenDecl); - if (result != XML_ERROR_NONE) - return result; - handleDefault = XML_FALSE; - break; - } - if (externalEntityRefHandler) { - dtd->paramEntityRead = XML_FALSE; - entity->open = XML_TRUE; - if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) { - entity->open = XML_FALSE; - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - entity->open = XML_FALSE; - handleDefault = XML_FALSE; - if (!dtd->paramEntityRead) { - dtd->keepProcessing = dtd->standalone; - break; - } - } - else { - dtd->keepProcessing = dtd->standalone; - break; - } - } -#endif /* XML_DTD */ - if (!dtd->standalone && - notStandaloneHandler && - !notStandaloneHandler(handlerArg)) - return XML_ERROR_NOT_STANDALONE; - break; - - /* Element declaration stuff */ - - case XML_ROLE_ELEMENT_NAME: - if (elementDeclHandler) { - declElementType = getElementType(parser, enc, s, next); - if (!declElementType) - return XML_ERROR_NO_MEMORY; - dtd->scaffLevel = 0; - dtd->scaffCount = 0; - dtd->in_eldecl = XML_TRUE; - handleDefault = XML_FALSE; - } - break; - - case XML_ROLE_CONTENT_ANY: - case XML_ROLE_CONTENT_EMPTY: - if (dtd->in_eldecl) { - if (elementDeclHandler) { - XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); - if (!content) - return XML_ERROR_NO_MEMORY; - content->quant = XML_CQUANT_NONE; - content->name = NULL; - content->numchildren = 0; - content->children = NULL; - content->type = ((role == XML_ROLE_CONTENT_ANY) ? - XML_CTYPE_ANY : - XML_CTYPE_EMPTY); - *eventEndPP = s; - elementDeclHandler(handlerArg, declElementType->name, content); - handleDefault = XML_FALSE; - } - dtd->in_eldecl = XML_FALSE; - } - break; - - case XML_ROLE_CONTENT_PCDATA: - if (dtd->in_eldecl) { - dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type - = XML_CTYPE_MIXED; - if (elementDeclHandler) - handleDefault = XML_FALSE; - } - break; - - case XML_ROLE_CONTENT_ELEMENT: - quant = XML_CQUANT_NONE; - goto elementContent; - case XML_ROLE_CONTENT_ELEMENT_OPT: - quant = XML_CQUANT_OPT; - goto elementContent; - case XML_ROLE_CONTENT_ELEMENT_REP: - quant = XML_CQUANT_REP; - goto elementContent; - case XML_ROLE_CONTENT_ELEMENT_PLUS: - quant = XML_CQUANT_PLUS; - elementContent: - if (dtd->in_eldecl) { - ELEMENT_TYPE *el; - const XML_Char *name; - int nameLen; - const char *nxt = (quant == XML_CQUANT_NONE - ? next - : next - enc->minBytesPerChar); - int myindex = nextScaffoldPart(parser); - if (myindex < 0) - return XML_ERROR_NO_MEMORY; - dtd->scaffold[myindex].type = XML_CTYPE_NAME; - dtd->scaffold[myindex].quant = quant; - el = getElementType(parser, enc, s, nxt); - if (!el) - return XML_ERROR_NO_MEMORY; - name = el->name; - dtd->scaffold[myindex].name = name; - nameLen = 0; - for (; name[nameLen++]; ); - dtd->contentStringLen += nameLen; - if (elementDeclHandler) - handleDefault = XML_FALSE; - } - break; - - case XML_ROLE_GROUP_CLOSE: - quant = XML_CQUANT_NONE; - goto closeGroup; - case XML_ROLE_GROUP_CLOSE_OPT: - quant = XML_CQUANT_OPT; - goto closeGroup; - case XML_ROLE_GROUP_CLOSE_REP: - quant = XML_CQUANT_REP; - goto closeGroup; - case XML_ROLE_GROUP_CLOSE_PLUS: - quant = XML_CQUANT_PLUS; - closeGroup: - if (dtd->in_eldecl) { - if (elementDeclHandler) - handleDefault = XML_FALSE; - dtd->scaffLevel--; - dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; - if (dtd->scaffLevel == 0) { - if (!handleDefault) { - XML_Content *model = build_model(parser); - if (!model) - return XML_ERROR_NO_MEMORY; - *eventEndPP = s; - elementDeclHandler(handlerArg, declElementType->name, model); - } - dtd->in_eldecl = XML_FALSE; - dtd->contentStringLen = 0; - } - } - break; - /* End element declaration stuff */ - - case XML_ROLE_PI: - if (!reportProcessingInstruction(parser, enc, s, next)) - return XML_ERROR_NO_MEMORY; - handleDefault = XML_FALSE; - break; - case XML_ROLE_COMMENT: - if (!reportComment(parser, enc, s, next)) - return XML_ERROR_NO_MEMORY; - handleDefault = XML_FALSE; - break; - case XML_ROLE_NONE: - switch (tok) { - case XML_TOK_BOM: - handleDefault = XML_FALSE; - break; - } - break; - case XML_ROLE_DOCTYPE_NONE: - if (startDoctypeDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_ENTITY_NONE: - if (dtd->keepProcessing && entityDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_NOTATION_NONE: - if (notationDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_ATTLIST_NONE: - if (dtd->keepProcessing && attlistDeclHandler) - handleDefault = XML_FALSE; - break; - case XML_ROLE_ELEMENT_NONE: - if (elementDeclHandler) - handleDefault = XML_FALSE; - break; - } /* end of big switch */ - - if (handleDefault && defaultHandler) - reportDefault(parser, enc, s, next); - - switch (ps_parsing) { - case XML_SUSPENDED: - *nextPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: - s = next; - tok = XmlPrologTok(enc, s, end, &next); - } - } - /* not reached */ -} - -static enum XML_Error PTRCALL -epilogProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - processor = epilogProcessor; - eventPtr = s; - for (;;) { - const char *next = NULL; - int tok = XmlPrologTok(encoding, s, end, &next); - eventEndPtr = next; - switch (tok) { - /* report partial linebreak - it might be the last token */ - case -XML_TOK_PROLOG_S: - if (defaultHandler) { - reportDefault(parser, encoding, s, next); - if (ps_parsing == XML_FINISHED) - return XML_ERROR_ABORTED; - } - *nextPtr = next; - return XML_ERROR_NONE; - case XML_TOK_NONE: - *nextPtr = s; - return XML_ERROR_NONE; - case XML_TOK_PROLOG_S: - if (defaultHandler) - reportDefault(parser, encoding, s, next); - break; - case XML_TOK_PI: - if (!reportProcessingInstruction(parser, encoding, s, next)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_COMMENT: - if (!reportComment(parser, encoding, s, next)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_INVALID: - eventPtr = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - if (!ps_finalBuffer) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_UNCLOSED_TOKEN; - case XML_TOK_PARTIAL_CHAR: - if (!ps_finalBuffer) { - *nextPtr = s; - return XML_ERROR_NONE; - } - return XML_ERROR_PARTIAL_CHAR; - default: - return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; - } - eventPtr = s = next; - switch (ps_parsing) { - case XML_SUSPENDED: - *nextPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: ; - } - } -} - -static enum XML_Error -processInternalEntity(XML_Parser parser, ENTITY *entity, - XML_Bool betweenDecl) -{ - const char *textStart, *textEnd; - const char *next; - enum XML_Error result; - OPEN_INTERNAL_ENTITY *openEntity; - - if (freeInternalEntities) { - openEntity = freeInternalEntities; - freeInternalEntities = openEntity->next; - } - else { - openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); - if (!openEntity) - return XML_ERROR_NO_MEMORY; - } - entity->open = XML_TRUE; - entity->processed = 0; - openEntity->next = openInternalEntities; - openInternalEntities = openEntity; - openEntity->entity = entity; - openEntity->startTagLevel = tagLevel; - openEntity->betweenDecl = betweenDecl; - openEntity->internalEventPtr = NULL; - openEntity->internalEventEndPtr = NULL; - textStart = (char *)entity->textPtr; - textEnd = (char *)(entity->textPtr + entity->textLen); - -#ifdef XML_DTD - if (entity->is_param) { - int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); - result = doProlog(parser, internalEncoding, textStart, textEnd, tok, - next, &next, XML_FALSE); - } - else -#endif /* XML_DTD */ - result = doContent(parser, tagLevel, internalEncoding, textStart, - textEnd, &next, XML_FALSE); - - if (result == XML_ERROR_NONE) { - if (textEnd != next && ps_parsing == XML_SUSPENDED) { - entity->processed = (int)(next - textStart); - processor = internalEntityProcessor; - } - else { - entity->open = XML_FALSE; - openInternalEntities = openEntity->next; - /* put openEntity back in list of free instances */ - openEntity->next = freeInternalEntities; - freeInternalEntities = openEntity; - } - } - return result; -} - -static enum XML_Error PTRCALL -internalEntityProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - ENTITY *entity; - const char *textStart, *textEnd; - const char *next; - enum XML_Error result; - OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; - if (!openEntity) - return XML_ERROR_UNEXPECTED_STATE; - - entity = openEntity->entity; - textStart = ((char *)entity->textPtr) + entity->processed; - textEnd = (char *)(entity->textPtr + entity->textLen); - -#ifdef XML_DTD - if (entity->is_param) { - int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); - result = doProlog(parser, internalEncoding, textStart, textEnd, tok, - next, &next, XML_FALSE); - } - else -#endif /* XML_DTD */ - result = doContent(parser, openEntity->startTagLevel, internalEncoding, - textStart, textEnd, &next, XML_FALSE); - - if (result != XML_ERROR_NONE) - return result; - else if (textEnd != next && ps_parsing == XML_SUSPENDED) { - entity->processed = (int)(next - (char *)entity->textPtr); - return result; - } - else { - entity->open = XML_FALSE; - openInternalEntities = openEntity->next; - /* put openEntity back in list of free instances */ - openEntity->next = freeInternalEntities; - freeInternalEntities = openEntity; - } - -#ifdef XML_DTD - if (entity->is_param) { - int tok; - processor = prologProcessor; - tok = XmlPrologTok(encoding, s, end, &next); - return doProlog(parser, encoding, s, end, tok, next, nextPtr, - (XML_Bool)!ps_finalBuffer); - } - else -#endif /* XML_DTD */ - { - processor = contentProcessor; - /* see externalEntityContentProcessor vs contentProcessor */ - return doContent(parser, parentParser ? 1 : 0, encoding, s, end, - nextPtr, (XML_Bool)!ps_finalBuffer); - } -} - -static enum XML_Error PTRCALL -errorProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - return errorCode; -} - -static enum XML_Error -storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, - STRING_POOL *pool) -{ - enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, - end, pool); - if (result) - return result; - if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) - poolChop(pool); - if (!poolAppendChar(pool, XML_T('\0'))) - return XML_ERROR_NO_MEMORY; - return XML_ERROR_NONE; -} - -static enum XML_Error -appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, - STRING_POOL *pool) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - for (;;) { - const char *next; - int tok = XmlAttributeValueTok(enc, ptr, end, &next); - switch (tok) { - case XML_TOK_NONE: - return XML_ERROR_NONE; - case XML_TOK_INVALID: - if (enc == encoding) - eventPtr = next; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_PARTIAL: - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_INVALID_TOKEN; - case XML_TOK_CHAR_REF: - { - XML_Char buf[XML_ENCODE_MAX]; - int i; - int n = XmlCharRefNumber(enc, ptr); - if (n < 0) { - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_BAD_CHAR_REF; - } - if (!isCdata - && n == 0x20 /* space */ - && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) - break; - n = XmlEncode(n, (ICHAR *)buf); - if (!n) { - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_BAD_CHAR_REF; - } - for (i = 0; i < n; i++) { - if (!poolAppendChar(pool, buf[i])) - return XML_ERROR_NO_MEMORY; - } - } - break; - case XML_TOK_DATA_CHARS: - if (!poolAppend(pool, enc, ptr, next)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_TRAILING_CR: - next = ptr + enc->minBytesPerChar; - /* fall through */ - case XML_TOK_ATTRIBUTE_VALUE_S: - case XML_TOK_DATA_NEWLINE: - if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) - break; - if (!poolAppendChar(pool, 0x20)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_ENTITY_REF: - { - const XML_Char *name; - ENTITY *entity; - char checkEntityDecl; - XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, - ptr + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (ch) { - if (!poolAppendChar(pool, ch)) - return XML_ERROR_NO_MEMORY; - break; - } - name = poolStoreString(&temp2Pool, enc, - ptr + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) - return XML_ERROR_NO_MEMORY; - entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); - poolDiscard(&temp2Pool); - /* First, determine if a check for an existing declaration is needed; - if yes, check that the entity exists, and that it is internal. - */ - if (pool == &dtd->pool) /* are we called from prolog? */ - checkEntityDecl = -#ifdef XML_DTD - prologState.documentEntity && -#endif /* XML_DTD */ - (dtd->standalone - ? !openInternalEntities - : !dtd->hasParamEntityRefs); - else /* if (pool == &tempPool): we are called from content */ - checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; - if (checkEntityDecl) { - if (!entity) - return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) - return XML_ERROR_ENTITY_DECLARED_IN_PE; - } - else if (!entity) { - /* Cannot report skipped entity here - see comments on - skippedEntityHandler. - if (skippedEntityHandler) - skippedEntityHandler(handlerArg, name, 0); - */ - /* Cannot call the default handler because this would be - out of sync with the call to the startElementHandler. - if ((pool == &tempPool) && defaultHandler) - reportDefault(parser, enc, ptr, next); - */ - break; - } - if (entity->open) { - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_RECURSIVE_ENTITY_REF; - } - if (entity->notation) { - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_BINARY_ENTITY_REF; - } - if (!entity->textPtr) { - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; - } - else { - enum XML_Error result; - const XML_Char *textEnd = entity->textPtr + entity->textLen; - entity->open = XML_TRUE; - result = appendAttributeValue(parser, internalEncoding, isCdata, - (char *)entity->textPtr, - (char *)textEnd, pool); - entity->open = XML_FALSE; - if (result) - return result; - } - } - break; - default: - if (enc == encoding) - eventPtr = ptr; - return XML_ERROR_UNEXPECTED_STATE; - } - ptr = next; - } - /* not reached */ -} - -static enum XML_Error -storeEntityValue(XML_Parser parser, - const ENCODING *enc, - const char *entityTextPtr, - const char *entityTextEnd) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - STRING_POOL *pool = &(dtd->entityValuePool); - enum XML_Error result = XML_ERROR_NONE; -#ifdef XML_DTD - int oldInEntityValue = prologState.inEntityValue; - prologState.inEntityValue = 1; -#endif /* XML_DTD */ - /* never return Null for the value argument in EntityDeclHandler, - since this would indicate an external entity; therefore we - have to make sure that entityValuePool.start is not null */ - if (!pool->blocks) { - if (!poolGrow(pool)) - return XML_ERROR_NO_MEMORY; - } - - for (;;) { - const char *next; - int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); - switch (tok) { - case XML_TOK_PARAM_ENTITY_REF: -#ifdef XML_DTD - if (isParamEntity || enc != encoding) { - const XML_Char *name; - ENTITY *entity; - name = poolStoreString(&tempPool, enc, - entityTextPtr + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) { - result = XML_ERROR_NO_MEMORY; - goto endEntityValue; - } - entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); - poolDiscard(&tempPool); - if (!entity) { - /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ - /* cannot report skipped entity here - see comments on - skippedEntityHandler - if (skippedEntityHandler) - skippedEntityHandler(handlerArg, name, 0); - */ - dtd->keepProcessing = dtd->standalone; - goto endEntityValue; - } - if (entity->open) { - if (enc == encoding) - eventPtr = entityTextPtr; - result = XML_ERROR_RECURSIVE_ENTITY_REF; - goto endEntityValue; - } - if (entity->systemId) { - if (externalEntityRefHandler) { - dtd->paramEntityRead = XML_FALSE; - entity->open = XML_TRUE; - if (!externalEntityRefHandler(externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) { - entity->open = XML_FALSE; - result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; - goto endEntityValue; - } - entity->open = XML_FALSE; - if (!dtd->paramEntityRead) - dtd->keepProcessing = dtd->standalone; - } - else - dtd->keepProcessing = dtd->standalone; - } - else { - entity->open = XML_TRUE; - result = storeEntityValue(parser, - internalEncoding, - (char *)entity->textPtr, - (char *)(entity->textPtr - + entity->textLen)); - entity->open = XML_FALSE; - if (result) - goto endEntityValue; - } - break; - } -#endif /* XML_DTD */ - /* In the internal subset, PE references are not legal - within markup declarations, e.g entity values in this case. */ - eventPtr = entityTextPtr; - result = XML_ERROR_PARAM_ENTITY_REF; - goto endEntityValue; - case XML_TOK_NONE: - result = XML_ERROR_NONE; - goto endEntityValue; - case XML_TOK_ENTITY_REF: - case XML_TOK_DATA_CHARS: - if (!poolAppend(pool, enc, entityTextPtr, next)) { - result = XML_ERROR_NO_MEMORY; - goto endEntityValue; - } - break; - case XML_TOK_TRAILING_CR: - next = entityTextPtr + enc->minBytesPerChar; - /* fall through */ - case XML_TOK_DATA_NEWLINE: - if (pool->end == pool->ptr && !poolGrow(pool)) { - result = XML_ERROR_NO_MEMORY; - goto endEntityValue; - } - *(pool->ptr)++ = 0xA; - break; - case XML_TOK_CHAR_REF: - { - XML_Char buf[XML_ENCODE_MAX]; - int i; - int n = XmlCharRefNumber(enc, entityTextPtr); - if (n < 0) { - if (enc == encoding) - eventPtr = entityTextPtr; - result = XML_ERROR_BAD_CHAR_REF; - goto endEntityValue; - } - n = XmlEncode(n, (ICHAR *)buf); - if (!n) { - if (enc == encoding) - eventPtr = entityTextPtr; - result = XML_ERROR_BAD_CHAR_REF; - goto endEntityValue; - } - for (i = 0; i < n; i++) { - if (pool->end == pool->ptr && !poolGrow(pool)) { - result = XML_ERROR_NO_MEMORY; - goto endEntityValue; - } - *(pool->ptr)++ = buf[i]; - } - } - break; - case XML_TOK_PARTIAL: - if (enc == encoding) - eventPtr = entityTextPtr; - result = XML_ERROR_INVALID_TOKEN; - goto endEntityValue; - case XML_TOK_INVALID: - if (enc == encoding) - eventPtr = next; - result = XML_ERROR_INVALID_TOKEN; - goto endEntityValue; - default: - if (enc == encoding) - eventPtr = entityTextPtr; - result = XML_ERROR_UNEXPECTED_STATE; - goto endEntityValue; - } - entityTextPtr = next; - } -endEntityValue: -#ifdef XML_DTD - prologState.inEntityValue = oldInEntityValue; -#endif /* XML_DTD */ - return result; -} - -static void FASTCALL -normalizeLines(XML_Char *s) -{ - XML_Char *p; - for (;; s++) { - if (*s == XML_T('\0')) - return; - if (*s == 0xD) - break; - } - p = s; - do { - if (*s == 0xD) { - *p++ = 0xA; - if (*++s == 0xA) - s++; - } - else - *p++ = *s++; - } while (*s); - *p = XML_T('\0'); -} - -static int -reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ - const XML_Char *target; - XML_Char *data; - const char *tem; - if (!processingInstructionHandler) { - if (defaultHandler) - reportDefault(parser, enc, start, end); - return 1; - } - start += enc->minBytesPerChar * 2; - tem = start + XmlNameLength(enc, start); - target = poolStoreString(&tempPool, enc, start, tem); - if (!target) - return 0; - poolFinish(&tempPool); - data = poolStoreString(&tempPool, enc, - XmlSkipS(enc, tem), - end - enc->minBytesPerChar*2); - if (!data) - return 0; - normalizeLines(data); - processingInstructionHandler(handlerArg, target, data); - poolClear(&tempPool); - return 1; -} - -static int -reportComment(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ - XML_Char *data; - if (!commentHandler) { - if (defaultHandler) - reportDefault(parser, enc, start, end); - return 1; - } - data = poolStoreString(&tempPool, - enc, - start + enc->minBytesPerChar * 4, - end - enc->minBytesPerChar * 3); - if (!data) - return 0; - normalizeLines(data); - commentHandler(handlerArg, data); - poolClear(&tempPool); - return 1; -} - -static void -reportDefault(XML_Parser parser, const ENCODING *enc, - const char *s, const char *end) -{ - if (MUST_CONVERT(enc, s)) { - const char **eventPP; - const char **eventEndPP; - if (enc == encoding) { - eventPP = &eventPtr; - eventEndPP = &eventEndPtr; - } - else { - eventPP = &(openInternalEntities->internalEventPtr); - eventEndPP = &(openInternalEntities->internalEventEndPtr); - } - do { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); - *eventEndPP = s; - defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); - *eventPP = s; - } while (s != end); - } - else - defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); -} - - -static int -defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, - XML_Bool isId, const XML_Char *value, XML_Parser parser) -{ - DEFAULT_ATTRIBUTE *att; - if (value || isId) { - /* The handling of default attributes gets messed up if we have - a default which duplicates a non-default. */ - int i; - for (i = 0; i < type->nDefaultAtts; i++) - if (attId == type->defaultAtts[i].id) - return 1; - if (isId && !type->idAtt && !attId->xmlns) - type->idAtt = attId; - } - if (type->nDefaultAtts == type->allocDefaultAtts) { - if (type->allocDefaultAtts == 0) { - type->allocDefaultAtts = 8; - type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts - * sizeof(DEFAULT_ATTRIBUTE)); - if (!type->defaultAtts) - return 0; - } - else { - DEFAULT_ATTRIBUTE *temp; - int count = type->allocDefaultAtts * 2; - temp = (DEFAULT_ATTRIBUTE *) - REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); - if (temp == NULL) - return 0; - type->allocDefaultAtts = count; - type->defaultAtts = temp; - } - } - att = type->defaultAtts + type->nDefaultAtts; - att->id = attId; - att->value = value; - att->isCdata = isCdata; - if (!isCdata) - attId->maybeTokenized = XML_TRUE; - type->nDefaultAtts += 1; - return 1; -} - -static int -setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - const XML_Char *name; - for (name = elementType->name; *name; name++) { - if (*name == XML_T(ASCII_COLON)) { - PREFIX *prefix; - const XML_Char *s; - for (s = elementType->name; s != name; s++) { - if (!poolAppendChar(&dtd->pool, *s)) - return 0; - } - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) - return 0; - prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), - sizeof(PREFIX)); - if (!prefix) - return 0; - if (prefix->name == poolStart(&dtd->pool)) - poolFinish(&dtd->pool); - else - poolDiscard(&dtd->pool); - elementType->prefix = prefix; - - } - } - return 1; -} - -static ATTRIBUTE_ID * -getAttributeId(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - ATTRIBUTE_ID *id; - const XML_Char *name; - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) - return NULL; - name = poolStoreString(&dtd->pool, enc, start, end); - if (!name) - return NULL; - /* skip quotation mark - its storage will be re-used (like in name[-1]) */ - ++name; - id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); - if (!id) - return NULL; - if (id->name != name) - poolDiscard(&dtd->pool); - else { - poolFinish(&dtd->pool); - if (!ns) - ; - else if (name[0] == XML_T(ASCII_x) - && name[1] == XML_T(ASCII_m) - && name[2] == XML_T(ASCII_l) - && name[3] == XML_T(ASCII_n) - && name[4] == XML_T(ASCII_s) - && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { - if (name[5] == XML_T('\0')) - id->prefix = &dtd->defaultPrefix; - else - id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); - id->xmlns = XML_TRUE; - } - else { - int i; - for (i = 0; name[i]; i++) { - /* attributes without prefix are *not* in the default namespace */ - if (name[i] == XML_T(ASCII_COLON)) { - int j; - for (j = 0; j < i; j++) { - if (!poolAppendChar(&dtd->pool, name[j])) - return NULL; - } - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) - return NULL; - id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), - sizeof(PREFIX)); - if (id->prefix->name == poolStart(&dtd->pool)) - poolFinish(&dtd->pool); - else - poolDiscard(&dtd->pool); - break; - } - } - } - } - return id; -} - -#define CONTEXT_SEP XML_T(ASCII_FF) - -static const XML_Char * -getContext(XML_Parser parser) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - HASH_TABLE_ITER iter; - XML_Bool needSep = XML_FALSE; - - if (dtd->defaultPrefix.binding) { - int i; - int len; - if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) - return NULL; - len = dtd->defaultPrefix.binding->uriLen; - if (namespaceSeparator) - len--; - for (i = 0; i < len; i++) - if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) - return NULL; - needSep = XML_TRUE; - } - - hashTableIterInit(&iter, &(dtd->prefixes)); - for (;;) { - int i; - int len; - const XML_Char *s; - PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); - if (!prefix) - break; - if (!prefix->binding) - continue; - if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) - return NULL; - for (s = prefix->name; *s; s++) - if (!poolAppendChar(&tempPool, *s)) - return NULL; - if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) - return NULL; - len = prefix->binding->uriLen; - if (namespaceSeparator) - len--; - for (i = 0; i < len; i++) - if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) - return NULL; - needSep = XML_TRUE; - } - - - hashTableIterInit(&iter, &(dtd->generalEntities)); - for (;;) { - const XML_Char *s; - ENTITY *e = (ENTITY *)hashTableIterNext(&iter); - if (!e) - break; - if (!e->open) - continue; - if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) - return NULL; - for (s = e->name; *s; s++) - if (!poolAppendChar(&tempPool, *s)) - return 0; - needSep = XML_TRUE; - } - - if (!poolAppendChar(&tempPool, XML_T('\0'))) - return NULL; - return tempPool.start; -} - -static XML_Bool -setContext(XML_Parser parser, const XML_Char *context) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - const XML_Char *s = context; - - while (*context != XML_T('\0')) { - if (*s == CONTEXT_SEP || *s == XML_T('\0')) { - ENTITY *e; - if (!poolAppendChar(&tempPool, XML_T('\0'))) - return XML_FALSE; - e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); - if (e) - e->open = XML_TRUE; - if (*s != XML_T('\0')) - s++; - context = s; - poolDiscard(&tempPool); - } - else if (*s == XML_T(ASCII_EQUALS)) { - PREFIX *prefix; - if (poolLength(&tempPool) == 0) - prefix = &dtd->defaultPrefix; - else { - if (!poolAppendChar(&tempPool, XML_T('\0'))) - return XML_FALSE; - prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), - sizeof(PREFIX)); - if (!prefix) - return XML_FALSE; - if (prefix->name == poolStart(&tempPool)) { - prefix->name = poolCopyString(&dtd->pool, prefix->name); - if (!prefix->name) - return XML_FALSE; - } - poolDiscard(&tempPool); - } - for (context = s + 1; - *context != CONTEXT_SEP && *context != XML_T('\0'); - context++) - if (!poolAppendChar(&tempPool, *context)) - return XML_FALSE; - if (!poolAppendChar(&tempPool, XML_T('\0'))) - return XML_FALSE; - if (addBinding(parser, prefix, NULL, poolStart(&tempPool), - &inheritedBindings) != XML_ERROR_NONE) - return XML_FALSE; - poolDiscard(&tempPool); - if (*context != XML_T('\0')) - ++context; - s = context; - } - else { - if (!poolAppendChar(&tempPool, *s)) - return XML_FALSE; - s++; - } - } - return XML_TRUE; -} - -static void FASTCALL -normalizePublicId(XML_Char *publicId) -{ - XML_Char *p = publicId; - XML_Char *s; - for (s = publicId; *s; s++) { - switch (*s) { - case 0x20: - case 0xD: - case 0xA: - if (p != publicId && p[-1] != 0x20) - *p++ = 0x20; - break; - default: - *p++ = *s; - } - } - if (p != publicId && p[-1] == 0x20) - --p; - *p = XML_T('\0'); -} - -static DTD * -dtdCreate(const XML_Memory_Handling_Suite *ms) -{ - DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); - if (p == NULL) - return p; - poolInit(&(p->pool), ms); - poolInit(&(p->entityValuePool), ms); - hashTableInit(&(p->generalEntities), ms); - hashTableInit(&(p->elementTypes), ms); - hashTableInit(&(p->attributeIds), ms); - hashTableInit(&(p->prefixes), ms); -#ifdef XML_DTD - p->paramEntityRead = XML_FALSE; - hashTableInit(&(p->paramEntities), ms); -#endif /* XML_DTD */ - p->defaultPrefix.name = NULL; - p->defaultPrefix.binding = NULL; - - p->in_eldecl = XML_FALSE; - p->scaffIndex = NULL; - p->scaffold = NULL; - p->scaffLevel = 0; - p->scaffSize = 0; - p->scaffCount = 0; - p->contentStringLen = 0; - - p->keepProcessing = XML_TRUE; - p->hasParamEntityRefs = XML_FALSE; - p->standalone = XML_FALSE; - return p; -} - -static void -dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) -{ - HASH_TABLE_ITER iter; - hashTableIterInit(&iter, &(p->elementTypes)); - for (;;) { - ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!e) - break; - if (e->allocDefaultAtts != 0) - ms->free_fcn(e->defaultAtts); - } - hashTableClear(&(p->generalEntities)); -#ifdef XML_DTD - p->paramEntityRead = XML_FALSE; - hashTableClear(&(p->paramEntities)); -#endif /* XML_DTD */ - hashTableClear(&(p->elementTypes)); - hashTableClear(&(p->attributeIds)); - hashTableClear(&(p->prefixes)); - poolClear(&(p->pool)); - poolClear(&(p->entityValuePool)); - p->defaultPrefix.name = NULL; - p->defaultPrefix.binding = NULL; - - p->in_eldecl = XML_FALSE; - - ms->free_fcn(p->scaffIndex); - p->scaffIndex = NULL; - ms->free_fcn(p->scaffold); - p->scaffold = NULL; - - p->scaffLevel = 0; - p->scaffSize = 0; - p->scaffCount = 0; - p->contentStringLen = 0; - - p->keepProcessing = XML_TRUE; - p->hasParamEntityRefs = XML_FALSE; - p->standalone = XML_FALSE; -} - -static void -dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) -{ - HASH_TABLE_ITER iter; - hashTableIterInit(&iter, &(p->elementTypes)); - for (;;) { - ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!e) - break; - if (e->allocDefaultAtts != 0) - ms->free_fcn(e->defaultAtts); - } - hashTableDestroy(&(p->generalEntities)); -#ifdef XML_DTD - hashTableDestroy(&(p->paramEntities)); -#endif /* XML_DTD */ - hashTableDestroy(&(p->elementTypes)); - hashTableDestroy(&(p->attributeIds)); - hashTableDestroy(&(p->prefixes)); - poolDestroy(&(p->pool)); - poolDestroy(&(p->entityValuePool)); - if (isDocEntity) { - ms->free_fcn(p->scaffIndex); - ms->free_fcn(p->scaffold); - } - ms->free_fcn(p); -} - -/* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. - The new DTD has already been initialized. -*/ -static int -dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) -{ - HASH_TABLE_ITER iter; - - /* Copy the prefix table. */ - - hashTableIterInit(&iter, &(oldDtd->prefixes)); - for (;;) { - const XML_Char *name; - const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); - if (!oldP) - break; - name = poolCopyString(&(newDtd->pool), oldP->name); - if (!name) - return 0; - if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX))) - return 0; - } - - hashTableIterInit(&iter, &(oldDtd->attributeIds)); - - /* Copy the attribute id table. */ - - for (;;) { - ATTRIBUTE_ID *newA; - const XML_Char *name; - const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); - - if (!oldA) - break; - /* Remember to allocate the scratch byte before the name. */ - if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) - return 0; - name = poolCopyString(&(newDtd->pool), oldA->name); - if (!name) - return 0; - ++name; - newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, - sizeof(ATTRIBUTE_ID)); - if (!newA) - return 0; - newA->maybeTokenized = oldA->maybeTokenized; - if (oldA->prefix) { - newA->xmlns = oldA->xmlns; - if (oldA->prefix == &oldDtd->defaultPrefix) - newA->prefix = &newDtd->defaultPrefix; - else - newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), - oldA->prefix->name, 0); - } - } - - /* Copy the element type table. */ - - hashTableIterInit(&iter, &(oldDtd->elementTypes)); - - for (;;) { - int i; - ELEMENT_TYPE *newE; - const XML_Char *name; - const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!oldE) - break; - name = poolCopyString(&(newDtd->pool), oldE->name); - if (!name) - return 0; - newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, - sizeof(ELEMENT_TYPE)); - if (!newE) - return 0; - if (oldE->nDefaultAtts) { - newE->defaultAtts = (DEFAULT_ATTRIBUTE *) - ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); - if (!newE->defaultAtts) { - ms->free_fcn(newE); - return 0; - } - } - if (oldE->idAtt) - newE->idAtt = (ATTRIBUTE_ID *) - lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); - newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; - if (oldE->prefix) - newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), - oldE->prefix->name, 0); - for (i = 0; i < newE->nDefaultAtts; i++) { - newE->defaultAtts[i].id = (ATTRIBUTE_ID *) - lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); - newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; - if (oldE->defaultAtts[i].value) { - newE->defaultAtts[i].value - = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); - if (!newE->defaultAtts[i].value) - return 0; - } - else - newE->defaultAtts[i].value = NULL; - } - } - - /* Copy the entity tables. */ - if (!copyEntityTable(&(newDtd->generalEntities), - &(newDtd->pool), - &(oldDtd->generalEntities))) - return 0; - -#ifdef XML_DTD - if (!copyEntityTable(&(newDtd->paramEntities), - &(newDtd->pool), - &(oldDtd->paramEntities))) - return 0; - newDtd->paramEntityRead = oldDtd->paramEntityRead; -#endif /* XML_DTD */ - - newDtd->keepProcessing = oldDtd->keepProcessing; - newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; - newDtd->standalone = oldDtd->standalone; - - /* Don't want deep copying for scaffolding */ - newDtd->in_eldecl = oldDtd->in_eldecl; - newDtd->scaffold = oldDtd->scaffold; - newDtd->contentStringLen = oldDtd->contentStringLen; - newDtd->scaffSize = oldDtd->scaffSize; - newDtd->scaffLevel = oldDtd->scaffLevel; - newDtd->scaffIndex = oldDtd->scaffIndex; - - return 1; -} /* End dtdCopy */ - -static int -copyEntityTable(HASH_TABLE *newTable, - STRING_POOL *newPool, - const HASH_TABLE *oldTable) -{ - HASH_TABLE_ITER iter; - const XML_Char *cachedOldBase = NULL; - const XML_Char *cachedNewBase = NULL; - - hashTableIterInit(&iter, oldTable); - - for (;;) { - ENTITY *newE; - const XML_Char *name; - const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); - if (!oldE) - break; - name = poolCopyString(newPool, oldE->name); - if (!name) - return 0; - newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY)); - if (!newE) - return 0; - if (oldE->systemId) { - const XML_Char *tem = poolCopyString(newPool, oldE->systemId); - if (!tem) - return 0; - newE->systemId = tem; - if (oldE->base) { - if (oldE->base == cachedOldBase) - newE->base = cachedNewBase; - else { - cachedOldBase = oldE->base; - tem = poolCopyString(newPool, cachedOldBase); - if (!tem) - return 0; - cachedNewBase = newE->base = tem; - } - } - if (oldE->publicId) { - tem = poolCopyString(newPool, oldE->publicId); - if (!tem) - return 0; - newE->publicId = tem; - } - } - else { - const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, - oldE->textLen); - if (!tem) - return 0; - newE->textPtr = tem; - newE->textLen = oldE->textLen; - } - if (oldE->notation) { - const XML_Char *tem = poolCopyString(newPool, oldE->notation); - if (!tem) - return 0; - newE->notation = tem; - } - newE->is_param = oldE->is_param; - newE->is_internal = oldE->is_internal; - } - return 1; -} - -#define INIT_POWER 6 - -static XML_Bool FASTCALL -keyeq(KEY s1, KEY s2) -{ - for (; *s1 == *s2; s1++, s2++) - if (*s1 == 0) - return XML_TRUE; - return XML_FALSE; -} - -static unsigned long FASTCALL -hash(KEY s) -{ - unsigned long h = 0; - while (*s) - h = CHAR_HASH(h, *s++); - return h; -} - -static NAMED * -lookup(HASH_TABLE *table, KEY name, size_t createSize) -{ - size_t i; - if (table->size == 0) { - size_t tsize; - if (!createSize) - return NULL; - table->power = INIT_POWER; - /* table->size is a power of 2 */ - table->size = (size_t)1 << INIT_POWER; - tsize = table->size * sizeof(NAMED *); - table->v = (NAMED **)table->mem->malloc_fcn(tsize); - if (!table->v) { - table->size = 0; - return NULL; - } - memset(table->v, 0, tsize); - i = hash(name) & ((unsigned long)table->size - 1); - } - else { - unsigned long h = hash(name); - unsigned long mask = (unsigned long)table->size - 1; - unsigned char step = 0; - i = h & mask; - while (table->v[i]) { - if (keyeq(name, table->v[i]->name)) - return table->v[i]; - if (!step) - step = PROBE_STEP(h, mask, table->power); - i < step ? (i += table->size - step) : (i -= step); - } - if (!createSize) - return NULL; - - /* check for overflow (table is half full) */ - if (table->used >> (table->power - 1)) { - unsigned char newPower = table->power + 1; - size_t newSize = (size_t)1 << newPower; - unsigned long newMask = (unsigned long)newSize - 1; - size_t tsize = newSize * sizeof(NAMED *); - NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); - if (!newV) - return NULL; - memset(newV, 0, tsize); - for (i = 0; i < table->size; i++) - if (table->v[i]) { - unsigned long newHash = hash(table->v[i]->name); - size_t j = newHash & newMask; - step = 0; - while (newV[j]) { - if (!step) - step = PROBE_STEP(newHash, newMask, newPower); - j < step ? (j += newSize - step) : (j -= step); - } - newV[j] = table->v[i]; - } - table->mem->free_fcn(table->v); - table->v = newV; - table->power = newPower; - table->size = newSize; - i = h & newMask; - step = 0; - while (table->v[i]) { - if (!step) - step = PROBE_STEP(h, newMask, newPower); - i < step ? (i += newSize - step) : (i -= step); - } - } - } - table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); - if (!table->v[i]) - return NULL; - memset(table->v[i], 0, createSize); - table->v[i]->name = name; - (table->used)++; - return table->v[i]; -} - -static void FASTCALL -hashTableClear(HASH_TABLE *table) -{ - size_t i; - for (i = 0; i < table->size; i++) { - table->mem->free_fcn(table->v[i]); - table->v[i] = NULL; - } - table->used = 0; -} - -static void FASTCALL -hashTableDestroy(HASH_TABLE *table) -{ - size_t i; - for (i = 0; i < table->size; i++) - table->mem->free_fcn(table->v[i]); - table->mem->free_fcn(table->v); -} - -static void FASTCALL -hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) -{ - p->power = 0; - p->size = 0; - p->used = 0; - p->v = NULL; - p->mem = ms; -} - -static void FASTCALL -hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) -{ - iter->p = table->v; - iter->end = iter->p + table->size; -} - -static NAMED * FASTCALL -hashTableIterNext(HASH_TABLE_ITER *iter) -{ - while (iter->p != iter->end) { - NAMED *tem = *(iter->p)++; - if (tem) - return tem; - } - return NULL; -} - -static void FASTCALL -poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) -{ - pool->blocks = NULL; - pool->freeBlocks = NULL; - pool->start = NULL; - pool->ptr = NULL; - pool->end = NULL; - pool->mem = ms; -} - -static void FASTCALL -poolClear(STRING_POOL *pool) -{ - if (!pool->freeBlocks) - pool->freeBlocks = pool->blocks; - else { - BLOCK *p = pool->blocks; - while (p) { - BLOCK *tem = p->next; - p->next = pool->freeBlocks; - pool->freeBlocks = p; - p = tem; - } - } - pool->blocks = NULL; - pool->start = NULL; - pool->ptr = NULL; - pool->end = NULL; -} - -static void FASTCALL -poolDestroy(STRING_POOL *pool) -{ - BLOCK *p = pool->blocks; - while (p) { - BLOCK *tem = p->next; - pool->mem->free_fcn(p); - p = tem; - } - p = pool->freeBlocks; - while (p) { - BLOCK *tem = p->next; - pool->mem->free_fcn(p); - p = tem; - } -} - -static XML_Char * -poolAppend(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end) -{ - if (!pool->ptr && !poolGrow(pool)) - return NULL; - for (;;) { - XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); - if (ptr == end) - break; - if (!poolGrow(pool)) - return NULL; - } - return pool->start; -} - -static const XML_Char * FASTCALL -poolCopyString(STRING_POOL *pool, const XML_Char *s) -{ - do { - if (!poolAppendChar(pool, *s)) - return NULL; - } while (*s++); - s = pool->start; - poolFinish(pool); - return s; -} - -static const XML_Char * -poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) -{ - if (!pool->ptr && !poolGrow(pool)) - return NULL; - for (; n > 0; --n, s++) { - if (!poolAppendChar(pool, *s)) - return NULL; - } - s = pool->start; - poolFinish(pool); - return s; -} - -static const XML_Char * FASTCALL -poolAppendString(STRING_POOL *pool, const XML_Char *s) -{ - while (*s) { - if (!poolAppendChar(pool, *s)) - return NULL; - s++; - } - return pool->start; -} - -static XML_Char * -poolStoreString(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end) -{ - if (!poolAppend(pool, enc, ptr, end)) - return NULL; - if (pool->ptr == pool->end && !poolGrow(pool)) - return NULL; - *(pool->ptr)++ = 0; - return pool->start; -} - -static XML_Bool FASTCALL -poolGrow(STRING_POOL *pool) -{ - if (pool->freeBlocks) { - if (pool->start == 0) { - pool->blocks = pool->freeBlocks; - pool->freeBlocks = pool->freeBlocks->next; - pool->blocks->next = NULL; - pool->start = pool->blocks->s; - pool->end = pool->start + pool->blocks->size; - pool->ptr = pool->start; - return XML_TRUE; - } - if (pool->end - pool->start < pool->freeBlocks->size) { - BLOCK *tem = pool->freeBlocks->next; - pool->freeBlocks->next = pool->blocks; - pool->blocks = pool->freeBlocks; - pool->freeBlocks = tem; - memcpy(pool->blocks->s, pool->start, - (pool->end - pool->start) * sizeof(XML_Char)); - pool->ptr = pool->blocks->s + (pool->ptr - pool->start); - pool->start = pool->blocks->s; - pool->end = pool->start + pool->blocks->size; - return XML_TRUE; - } - } - if (pool->blocks && pool->start == pool->blocks->s) { - int blockSize = (int)(pool->end - pool->start)*2; - pool->blocks = (BLOCK *) - pool->mem->realloc_fcn(pool->blocks, - (offsetof(BLOCK, s) - + blockSize * sizeof(XML_Char))); - if (pool->blocks == NULL) - return XML_FALSE; - pool->blocks->size = blockSize; - pool->ptr = pool->blocks->s + (pool->ptr - pool->start); - pool->start = pool->blocks->s; - pool->end = pool->start + blockSize; - } - else { - BLOCK *tem; - int blockSize = (int)(pool->end - pool->start); - if (blockSize < INIT_BLOCK_SIZE) - blockSize = INIT_BLOCK_SIZE; - else - blockSize *= 2; - tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) - + blockSize * sizeof(XML_Char)); - if (!tem) - return XML_FALSE; - tem->size = blockSize; - tem->next = pool->blocks; - pool->blocks = tem; - if (pool->ptr != pool->start) - memcpy(tem->s, pool->start, - (pool->ptr - pool->start) * sizeof(XML_Char)); - pool->ptr = tem->s + (pool->ptr - pool->start); - pool->start = tem->s; - pool->end = tem->s + blockSize; - } - return XML_TRUE; -} - -static int FASTCALL -nextScaffoldPart(XML_Parser parser) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - CONTENT_SCAFFOLD * me; - int next; - - if (!dtd->scaffIndex) { - dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); - if (!dtd->scaffIndex) - return -1; - dtd->scaffIndex[0] = 0; - } - - if (dtd->scaffCount >= dtd->scaffSize) { - CONTENT_SCAFFOLD *temp; - if (dtd->scaffold) { - temp = (CONTENT_SCAFFOLD *) - REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); - if (temp == NULL) - return -1; - dtd->scaffSize *= 2; - } - else { - temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS - * sizeof(CONTENT_SCAFFOLD)); - if (temp == NULL) - return -1; - dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; - } - dtd->scaffold = temp; - } - next = dtd->scaffCount++; - me = &dtd->scaffold[next]; - if (dtd->scaffLevel) { - CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; - if (parent->lastchild) { - dtd->scaffold[parent->lastchild].nextsib = next; - } - if (!parent->childcnt) - parent->firstchild = next; - parent->lastchild = next; - parent->childcnt++; - } - me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; - return next; -} - -static void -build_node(XML_Parser parser, - int src_node, - XML_Content *dest, - XML_Content **contpos, - XML_Char **strpos) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - dest->type = dtd->scaffold[src_node].type; - dest->quant = dtd->scaffold[src_node].quant; - if (dest->type == XML_CTYPE_NAME) { - const XML_Char *src; - dest->name = *strpos; - src = dtd->scaffold[src_node].name; - for (;;) { - *(*strpos)++ = *src; - if (!*src) - break; - src++; - } - dest->numchildren = 0; - dest->children = NULL; - } - else { - unsigned int i; - int cn; - dest->numchildren = dtd->scaffold[src_node].childcnt; - dest->children = *contpos; - *contpos += dest->numchildren; - for (i = 0, cn = dtd->scaffold[src_node].firstchild; - i < dest->numchildren; - i++, cn = dtd->scaffold[cn].nextsib) { - build_node(parser, cn, &(dest->children[i]), contpos, strpos); - } - dest->name = NULL; - } -} - -static XML_Content * -build_model (XML_Parser parser) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - XML_Content *ret; - XML_Content *cpos; - XML_Char * str; - int allocsize = (dtd->scaffCount * sizeof(XML_Content) - + (dtd->contentStringLen * sizeof(XML_Char))); - - ret = (XML_Content *)MALLOC(allocsize); - if (!ret) - return NULL; - - str = (XML_Char *) (&ret[dtd->scaffCount]); - cpos = &ret[1]; - - build_node(parser, 0, ret, &cpos, &str); - return ret; -} - -static ELEMENT_TYPE * -getElementType(XML_Parser parser, - const ENCODING *enc, - const char *ptr, - const char *end) -{ - DTD * const dtd = _dtd; /* save one level of indirection */ - const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); - ELEMENT_TYPE *ret; - - if (!name) - return NULL; - ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); - if (!ret) - return NULL; - if (ret->name != name) - poolDiscard(&dtd->pool); - else { - poolFinish(&dtd->pool); - if (!setElementTypePrefix(parser, ret)) - return NULL; - } - return ret; -} +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include +#include /* memset(), memcpy() */ +#include + +#define XML_BUILDING_EXPAT 1 + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos4__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#elif defined(HAVE_EXPAT_CONFIG_H) +#include "expat_config.h" +#endif /* ndef COMPILED_FROM_DSP */ + +#include "ascii.h" +#include "Poco/XML/expat.h" + +#ifdef XML_UNICODE +#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX +#define XmlConvert XmlUtf16Convert +#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS +#define XmlEncode XmlUtf16Encode +/* Using pointer subtraction to convert to integer type. */ +#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) +typedef unsigned short ICHAR; +#else +#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX +#define XmlConvert XmlUtf8Convert +#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS +#define XmlEncode XmlUtf8Encode +#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) +typedef char ICHAR; +#endif + + +#ifndef XML_NS + +#define XmlInitEncodingNS XmlInitEncoding +#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding +#undef XmlGetInternalEncodingNS +#define XmlGetInternalEncodingNS XmlGetInternalEncoding +#define XmlParseXmlDeclNS XmlParseXmlDecl + +#endif + +#ifdef XML_UNICODE + +#ifdef XML_UNICODE_WCHAR_T +#define XML_T(x) (const wchar_t)x +#define XML_L(x) L ## x +#else +#define XML_T(x) (const unsigned short)x +#define XML_L(x) x +#endif + +#else + +#define XML_T(x) x +#define XML_L(x) x + +#endif + +/* Round up n to be a multiple of sz, where sz is a power of 2. */ +#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) + +/* Handle the case where memmove() doesn't exist. */ +#ifndef HAVE_MEMMOVE +#ifdef HAVE_BCOPY +#define memmove(d,s,l) bcopy((s),(d),(l)) +#else +#error memmove does not exist on this platform, nor is a substitute available +#endif /* HAVE_BCOPY */ +#endif /* HAVE_MEMMOVE */ + +#include "internal.h" +#include "xmltok.h" +#include "xmlrole.h" + +typedef const XML_Char *KEY; + +typedef struct { + KEY name; +} NAMED; + +typedef struct { + NAMED **v; + unsigned char power; + size_t size; + size_t used; + const XML_Memory_Handling_Suite *mem; +} HASH_TABLE; + +/* Basic character hash algorithm, taken from Python's string hash: + h = h * 1000003 ^ character, the constant being a prime number. + +*/ +#ifdef XML_UNICODE +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned short)(c)) +#else +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned char)(c)) +#endif + +/* For probing (after a collision) we need a step size relative prime + to the hash table size, which is a power of 2. We use double-hashing, + since we can calculate a second hash value cheaply by taking those bits + of the first hash value that were discarded (masked out) when the table + index was calculated: index = hash & mask, where mask = table->size - 1. + We limit the maximum step size to table->size / 4 (mask >> 2) and make + it odd, since odd numbers are always relative prime to a power of 2. +*/ +#define SECOND_HASH(hash, mask, power) \ + ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) +#define PROBE_STEP(hash, mask, power) \ + ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) + +typedef struct { + NAMED **p; + NAMED **end; +} HASH_TABLE_ITER; + +#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ +#define INIT_DATA_BUF_SIZE 1024 +#define INIT_ATTS_SIZE 16 +#define INIT_ATTS_VERSION 0xFFFFFFFF +#define INIT_BLOCK_SIZE 1024 +#define INIT_BUFFER_SIZE 1024 + +#define EXPAND_SPARE 24 + +typedef struct binding { + struct prefix *prefix; + struct binding *nextTagBinding; + struct binding *prevPrefixBinding; + const struct attribute_id *attId; + XML_Char *uri; + int uriLen; + int uriAlloc; +} BINDING; + +typedef struct prefix { + const XML_Char *name; + BINDING *binding; +} PREFIX; + +typedef struct { + const XML_Char *str; + const XML_Char *localPart; + const XML_Char *prefix; + int strLen; + int uriLen; + int prefixLen; +} TAG_NAME; + +/* TAG represents an open element. + The name of the element is stored in both the document and API + encodings. The memory buffer 'buf' is a separately-allocated + memory area which stores the name. During the XML_Parse()/ + XMLParseBuffer() when the element is open, the memory for the 'raw' + version of the name (in the document encoding) is shared with the + document buffer. If the element is open across calls to + XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to + contain the 'raw' name as well. + + A parser re-uses these structures, maintaining a list of allocated + TAG objects in a free list. +*/ +typedef struct tag { + struct tag *parent; /* parent of this element */ + const char *rawName; /* tagName in the original encoding */ + int rawNameLength; + TAG_NAME name; /* tagName in the API encoding */ + char *buf; /* buffer for name components */ + char *bufEnd; /* end of the buffer */ + BINDING *bindings; +} TAG; + +typedef struct { + const XML_Char *name; + const XML_Char *textPtr; + int textLen; /* length in XML_Chars */ + int processed; /* # of processed bytes - when suspended */ + const XML_Char *systemId; + const XML_Char *base; + const XML_Char *publicId; + const XML_Char *notation; + XML_Bool open; + XML_Bool is_param; + XML_Bool is_internal; /* true if declared in internal subset outside PE */ +} ENTITY; + +typedef struct { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + const XML_Char * name; + int firstchild; + int lastchild; + int childcnt; + int nextsib; +} CONTENT_SCAFFOLD; + +#define INIT_SCAFFOLD_ELEMENTS 32 + +typedef struct block { + struct block *next; + int size; + XML_Char s[1]; +} BLOCK; + +typedef struct { + BLOCK *blocks; + BLOCK *freeBlocks; + const XML_Char *end; + XML_Char *ptr; + XML_Char *start; + const XML_Memory_Handling_Suite *mem; +} STRING_POOL; + +/* The XML_Char before the name is used to determine whether + an attribute has been specified. */ +typedef struct attribute_id { + XML_Char *name; + PREFIX *prefix; + XML_Bool maybeTokenized; + XML_Bool xmlns; +} ATTRIBUTE_ID; + +typedef struct { + const ATTRIBUTE_ID *id; + XML_Bool isCdata; + const XML_Char *value; +} DEFAULT_ATTRIBUTE; + +typedef struct { + unsigned long version; + unsigned long hash; + const XML_Char *uriName; +} NS_ATT; + +typedef struct { + const XML_Char *name; + PREFIX *prefix; + const ATTRIBUTE_ID *idAtt; + int nDefaultAtts; + int allocDefaultAtts; + DEFAULT_ATTRIBUTE *defaultAtts; +} ELEMENT_TYPE; + +typedef struct { + HASH_TABLE generalEntities; + HASH_TABLE elementTypes; + HASH_TABLE attributeIds; + HASH_TABLE prefixes; + STRING_POOL pool; + STRING_POOL entityValuePool; + /* false once a parameter entity reference has been skipped */ + XML_Bool keepProcessing; + /* true once an internal or external PE reference has been encountered; + this includes the reference to an external subset */ + XML_Bool hasParamEntityRefs; + XML_Bool standalone; +#ifdef XML_DTD + /* indicates if external PE has been read */ + XML_Bool paramEntityRead; + HASH_TABLE paramEntities; +#endif /* XML_DTD */ + PREFIX defaultPrefix; + /* === scaffolding for building content model === */ + XML_Bool in_eldecl; + CONTENT_SCAFFOLD *scaffold; + unsigned contentStringLen; + unsigned scaffSize; + unsigned scaffCount; + int scaffLevel; + int *scaffIndex; +} DTD; + +typedef struct open_internal_entity { + const char *internalEventPtr; + const char *internalEventEndPtr; + struct open_internal_entity *next; + ENTITY *entity; + int startTagLevel; + XML_Bool betweenDecl; /* WFC: PE Between Declarations */ +} OPEN_INTERNAL_ENTITY; + +typedef enum XML_Error PTRCALL Processor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr); + +static Processor prologProcessor; +static Processor prologInitProcessor; +static Processor contentProcessor; +static Processor cdataSectionProcessor; +#ifdef XML_DTD +static Processor ignoreSectionProcessor; +static Processor externalParEntProcessor; +static Processor externalParEntInitProcessor; +static Processor entityValueProcessor; +static Processor entityValueInitProcessor; +#endif /* XML_DTD */ +static Processor epilogProcessor; +static Processor errorProcessor; +static Processor externalEntityInitProcessor; +static Processor externalEntityInitProcessor2; +static Processor externalEntityInitProcessor3; +static Processor externalEntityContentProcessor; +static Processor internalEntityProcessor; + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next); +static enum XML_Error +initializeEncoding(XML_Parser parser); +static enum XML_Error +doProlog(XML_Parser parser, const ENCODING *enc, const char *s, + const char *end, int tok, const char *next, const char **nextPtr, + XML_Bool haveMore); +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl); +static enum XML_Error +doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, + const char *start, const char *end, const char **endPtr, + XML_Bool haveMore); +static enum XML_Error +doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#ifdef XML_DTD +static enum XML_Error +doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#endif /* XML_DTD */ + +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *, const char *s, + TAG_NAME *tagNamePtr, BINDING **bindingsPtr); +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr); +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, + XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); +static enum XML_Error +storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int +reportComment(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static void +reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); + +static const XML_Char * getContext(XML_Parser parser); +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context); + +static void FASTCALL normalizePublicId(XML_Char *s); + +static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); +/* do not call if parentParser != NULL */ +static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); +static int +dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); +static int +copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); + +static NAMED * +lookup(HASH_TABLE *table, KEY name, size_t createSize); +static void FASTCALL +hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL hashTableClear(HASH_TABLE *); +static void FASTCALL hashTableDestroy(HASH_TABLE *); +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); +static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); + +static void FASTCALL +poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL poolClear(STRING_POOL *); +static void FASTCALL poolDestroy(STRING_POOL *); +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s); +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s); + +static int FASTCALL nextScaffoldPart(XML_Parser parser); +static XML_Content * build_model(XML_Parser parser); +static ELEMENT_TYPE * +getElementType(XML_Parser parser, const ENCODING *enc, + const char *ptr, const char *end); + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd); +static void +parserInit(XML_Parser parser, const XML_Char *encodingName); + +#define poolStart(pool) ((pool)->start) +#define poolEnd(pool) ((pool)->ptr) +#define poolLength(pool) ((pool)->ptr - (pool)->start) +#define poolChop(pool) ((void)--(pool->ptr)) +#define poolLastChar(pool) (((pool)->ptr)[-1]) +#define poolDiscard(pool) ((pool)->ptr = (pool)->start) +#define poolFinish(pool) ((pool)->start = (pool)->ptr) +#define poolAppendChar(pool, c) \ + (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ + ? 0 \ + : ((*((pool)->ptr)++ = c), 1)) + +struct XML_ParserStruct { + /* The first member must be userData so that the XML_GetUserData + macro works. */ + void *m_userData; + void *m_handlerArg; + char *m_buffer; + const XML_Memory_Handling_Suite m_mem; + /* first character to be parsed */ + const char *m_bufferPtr; + /* past last character to be parsed */ + char *m_bufferEnd; + /* allocated end of buffer */ + const char *m_bufferLim; + XML_Index m_parseEndByteIndex; + const char *m_parseEndPtr; + XML_Char *m_dataBuf; + XML_Char *m_dataBufEnd; + XML_StartElementHandler m_startElementHandler; + XML_EndElementHandler m_endElementHandler; + XML_CharacterDataHandler m_characterDataHandler; + XML_ProcessingInstructionHandler m_processingInstructionHandler; + XML_CommentHandler m_commentHandler; + XML_StartCdataSectionHandler m_startCdataSectionHandler; + XML_EndCdataSectionHandler m_endCdataSectionHandler; + XML_DefaultHandler m_defaultHandler; + XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; + XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; + XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; + XML_NotationDeclHandler m_notationDeclHandler; + XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; + XML_NotStandaloneHandler m_notStandaloneHandler; + XML_ExternalEntityRefHandler m_externalEntityRefHandler; + XML_Parser m_externalEntityRefHandlerArg; + XML_SkippedEntityHandler m_skippedEntityHandler; + XML_UnknownEncodingHandler m_unknownEncodingHandler; + XML_ElementDeclHandler m_elementDeclHandler; + XML_AttlistDeclHandler m_attlistDeclHandler; + XML_EntityDeclHandler m_entityDeclHandler; + XML_XmlDeclHandler m_xmlDeclHandler; + const ENCODING *m_encoding; + INIT_ENCODING m_initEncoding; + const ENCODING *m_internalEncoding; + const XML_Char *m_protocolEncodingName; + XML_Bool m_ns; + XML_Bool m_ns_triplets; + void *m_unknownEncodingMem; + void *m_unknownEncodingData; + void *m_unknownEncodingHandlerData; + void (XMLCALL *m_unknownEncodingRelease)(void *); + PROLOG_STATE m_prologState; + Processor *m_processor; + enum XML_Error m_errorCode; + const char *m_eventPtr; + const char *m_eventEndPtr; + const char *m_positionPtr; + OPEN_INTERNAL_ENTITY *m_openInternalEntities; + OPEN_INTERNAL_ENTITY *m_freeInternalEntities; + XML_Bool m_defaultExpandInternalEntities; + int m_tagLevel; + ENTITY *m_declEntity; + const XML_Char *m_doctypeName; + const XML_Char *m_doctypeSysid; + const XML_Char *m_doctypePubid; + const XML_Char *m_declAttributeType; + const XML_Char *m_declNotationName; + const XML_Char *m_declNotationPublicId; + ELEMENT_TYPE *m_declElementType; + ATTRIBUTE_ID *m_declAttributeId; + XML_Bool m_declAttributeIsCdata; + XML_Bool m_declAttributeIsId; + DTD *m_dtd; + const XML_Char *m_curBase; + TAG *m_tagStack; + TAG *m_freeTagList; + BINDING *m_inheritedBindings; + BINDING *m_freeBindingList; + int m_attsSize; + int m_nSpecifiedAtts; + int m_idAttIndex; + ATTRIBUTE *m_atts; + NS_ATT *m_nsAtts; + unsigned long m_nsAttsVersion; + unsigned char m_nsAttsPower; + POSITION m_position; + STRING_POOL m_tempPool; + STRING_POOL m_temp2Pool; + char *m_groupConnector; + unsigned int m_groupSize; + XML_Char m_namespaceSeparator; + XML_Parser m_parentParser; + XML_ParsingStatus m_parsingStatus; +#ifdef XML_DTD + XML_Bool m_isParamEntity; + XML_Bool m_useForeignDTD; + enum XML_ParamEntityParsing m_paramEntityParsing; +#endif +}; + +#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) +#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) +#define FREE(p) (parser->m_mem.free_fcn((p))) + +#define userData (parser->m_userData) +#define handlerArg (parser->m_handlerArg) +#define startElementHandler (parser->m_startElementHandler) +#define endElementHandler (parser->m_endElementHandler) +#define characterDataHandler (parser->m_characterDataHandler) +#define processingInstructionHandler \ + (parser->m_processingInstructionHandler) +#define commentHandler (parser->m_commentHandler) +#define startCdataSectionHandler \ + (parser->m_startCdataSectionHandler) +#define endCdataSectionHandler (parser->m_endCdataSectionHandler) +#define defaultHandler (parser->m_defaultHandler) +#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler) +#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler) +#define unparsedEntityDeclHandler \ + (parser->m_unparsedEntityDeclHandler) +#define notationDeclHandler (parser->m_notationDeclHandler) +#define startNamespaceDeclHandler \ + (parser->m_startNamespaceDeclHandler) +#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler) +#define notStandaloneHandler (parser->m_notStandaloneHandler) +#define externalEntityRefHandler \ + (parser->m_externalEntityRefHandler) +#define externalEntityRefHandlerArg \ + (parser->m_externalEntityRefHandlerArg) +#define internalEntityRefHandler \ + (parser->m_internalEntityRefHandler) +#define skippedEntityHandler (parser->m_skippedEntityHandler) +#define unknownEncodingHandler (parser->m_unknownEncodingHandler) +#define elementDeclHandler (parser->m_elementDeclHandler) +#define attlistDeclHandler (parser->m_attlistDeclHandler) +#define entityDeclHandler (parser->m_entityDeclHandler) +#define xmlDeclHandler (parser->m_xmlDeclHandler) +#define encoding (parser->m_encoding) +#define initEncoding (parser->m_initEncoding) +#define internalEncoding (parser->m_internalEncoding) +#define unknownEncodingMem (parser->m_unknownEncodingMem) +#define unknownEncodingData (parser->m_unknownEncodingData) +#define unknownEncodingHandlerData \ + (parser->m_unknownEncodingHandlerData) +#define unknownEncodingRelease (parser->m_unknownEncodingRelease) +#define protocolEncodingName (parser->m_protocolEncodingName) +#define ns (parser->m_ns) +#define ns_triplets (parser->m_ns_triplets) +#define prologState (parser->m_prologState) +#define processor (parser->m_processor) +#define errorCode (parser->m_errorCode) +#define eventPtr (parser->m_eventPtr) +#define eventEndPtr (parser->m_eventEndPtr) +#define positionPtr (parser->m_positionPtr) +#define position (parser->m_position) +#define openInternalEntities (parser->m_openInternalEntities) +#define freeInternalEntities (parser->m_freeInternalEntities) +#define defaultExpandInternalEntities \ + (parser->m_defaultExpandInternalEntities) +#define tagLevel (parser->m_tagLevel) +#define buffer (parser->m_buffer) +#define bufferPtr (parser->m_bufferPtr) +#define bufferEnd (parser->m_bufferEnd) +#define parseEndByteIndex (parser->m_parseEndByteIndex) +#define parseEndPtr (parser->m_parseEndPtr) +#define bufferLim (parser->m_bufferLim) +#define dataBuf (parser->m_dataBuf) +#define dataBufEnd (parser->m_dataBufEnd) +#define _dtd (parser->m_dtd) +#define curBase (parser->m_curBase) +#define declEntity (parser->m_declEntity) +#define doctypeName (parser->m_doctypeName) +#define doctypeSysid (parser->m_doctypeSysid) +#define doctypePubid (parser->m_doctypePubid) +#define declAttributeType (parser->m_declAttributeType) +#define declNotationName (parser->m_declNotationName) +#define declNotationPublicId (parser->m_declNotationPublicId) +#define declElementType (parser->m_declElementType) +#define declAttributeId (parser->m_declAttributeId) +#define declAttributeIsCdata (parser->m_declAttributeIsCdata) +#define declAttributeIsId (parser->m_declAttributeIsId) +#define freeTagList (parser->m_freeTagList) +#define freeBindingList (parser->m_freeBindingList) +#define inheritedBindings (parser->m_inheritedBindings) +#define tagStack (parser->m_tagStack) +#define atts (parser->m_atts) +#define attsSize (parser->m_attsSize) +#define nSpecifiedAtts (parser->m_nSpecifiedAtts) +#define idAttIndex (parser->m_idAttIndex) +#define nsAtts (parser->m_nsAtts) +#define nsAttsVersion (parser->m_nsAttsVersion) +#define nsAttsPower (parser->m_nsAttsPower) +#define tempPool (parser->m_tempPool) +#define temp2Pool (parser->m_temp2Pool) +#define groupConnector (parser->m_groupConnector) +#define groupSize (parser->m_groupSize) +#define namespaceSeparator (parser->m_namespaceSeparator) +#define parentParser (parser->m_parentParser) +#define ps_parsing (parser->m_parsingStatus.parsing) +#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) +#ifdef XML_DTD +#define isParamEntity (parser->m_isParamEntity) +#define useForeignDTD (parser->m_useForeignDTD) +#define paramEntityParsing (parser->m_paramEntityParsing) +#endif /* XML_DTD */ + +XML_Parser XMLCALL +XML_ParserCreate(const XML_Char *encodingName) +{ + return XML_ParserCreate_MM(encodingName, NULL, NULL); +} + +XML_Parser XMLCALL +XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) +{ + XML_Char tmp[2]; + *tmp = nsSep; + return XML_ParserCreate_MM(encodingName, NULL, tmp); +} + +static const XML_Char implicitContext[] = { + ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, + ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, + ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, + ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, + ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, + ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' +}; + +XML_Parser XMLCALL +XML_ParserCreate_MM(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep) +{ + XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL); + if (parser != NULL && ns) { + /* implicit context only set for root parser, since child + parsers (i.e. external entity parsers) will inherit it + */ + if (!setContext(parser, implicitContext)) { + XML_ParserFree(parser); + return NULL; + } + } + return parser; +} + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd) +{ + XML_Parser parser; + + if (memsuite) { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser) + memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = memsuite->malloc_fcn; + mtemp->realloc_fcn = memsuite->realloc_fcn; + mtemp->free_fcn = memsuite->free_fcn; + } + } + else { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = malloc; + mtemp->realloc_fcn = realloc; + mtemp->free_fcn = free; + } + } + + if (!parser) + return parser; + + buffer = NULL; + bufferLim = NULL; + + attsSize = INIT_ATTS_SIZE; + atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); + if (atts == NULL) { + FREE(parser); + return NULL; + } + dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); + if (dataBuf == NULL) { + FREE(atts); + FREE(parser); + return NULL; + } + dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; + + if (dtd) + _dtd = dtd; + else { + _dtd = dtdCreate(&parser->m_mem); + if (_dtd == NULL) { + FREE(dataBuf); + FREE(atts); + FREE(parser); + return NULL; + } + } + + freeBindingList = NULL; + freeTagList = NULL; + freeInternalEntities = NULL; + + groupSize = 0; + groupConnector = NULL; + + unknownEncodingHandler = NULL; + unknownEncodingHandlerData = NULL; + + namespaceSeparator = ASCII_EXCL; + ns = XML_FALSE; + ns_triplets = XML_FALSE; + + nsAtts = NULL; + nsAttsVersion = 0; + nsAttsPower = 0; + + poolInit(&tempPool, &(parser->m_mem)); + poolInit(&temp2Pool, &(parser->m_mem)); + parserInit(parser, encodingName); + + if (encodingName && !protocolEncodingName) { + XML_ParserFree(parser); + return NULL; + } + + if (nameSep) { + ns = XML_TRUE; + internalEncoding = XmlGetInternalEncodingNS(); + namespaceSeparator = *nameSep; + } + else { + internalEncoding = XmlGetInternalEncoding(); + } + + return parser; +} + +static void +parserInit(XML_Parser parser, const XML_Char *encodingName) +{ + processor = prologInitProcessor; + XmlPrologStateInit(&prologState); + protocolEncodingName = (encodingName != NULL + ? poolCopyString(&tempPool, encodingName) + : NULL); + curBase = NULL; + XmlInitEncoding(&initEncoding, &encoding, 0); + userData = NULL; + handlerArg = NULL; + startElementHandler = NULL; + endElementHandler = NULL; + characterDataHandler = NULL; + processingInstructionHandler = NULL; + commentHandler = NULL; + startCdataSectionHandler = NULL; + endCdataSectionHandler = NULL; + defaultHandler = NULL; + startDoctypeDeclHandler = NULL; + endDoctypeDeclHandler = NULL; + unparsedEntityDeclHandler = NULL; + notationDeclHandler = NULL; + startNamespaceDeclHandler = NULL; + endNamespaceDeclHandler = NULL; + notStandaloneHandler = NULL; + externalEntityRefHandler = NULL; + externalEntityRefHandlerArg = parser; + skippedEntityHandler = NULL; + elementDeclHandler = NULL; + attlistDeclHandler = NULL; + entityDeclHandler = NULL; + xmlDeclHandler = NULL; + bufferPtr = buffer; + bufferEnd = buffer; + parseEndByteIndex = 0; + parseEndPtr = NULL; + declElementType = NULL; + declAttributeId = NULL; + declEntity = NULL; + doctypeName = NULL; + doctypeSysid = NULL; + doctypePubid = NULL; + declAttributeType = NULL; + declNotationName = NULL; + declNotationPublicId = NULL; + declAttributeIsCdata = XML_FALSE; + declAttributeIsId = XML_FALSE; + memset(&position, 0, sizeof(POSITION)); + errorCode = XML_ERROR_NONE; + eventPtr = NULL; + eventEndPtr = NULL; + positionPtr = NULL; + openInternalEntities = NULL; + defaultExpandInternalEntities = XML_TRUE; + tagLevel = 0; + tagStack = NULL; + inheritedBindings = NULL; + nSpecifiedAtts = 0; + unknownEncodingMem = NULL; + unknownEncodingRelease = NULL; + unknownEncodingData = NULL; + parentParser = NULL; + ps_parsing = XML_INITIALIZED; +#ifdef XML_DTD + isParamEntity = XML_FALSE; + useForeignDTD = XML_FALSE; + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif +} + +/* moves list of bindings to freeBindingList */ +static void FASTCALL +moveToFreeBindingList(XML_Parser parser, BINDING *bindings) +{ + while (bindings) { + BINDING *b = bindings; + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + } +} + +XML_Bool XMLCALL +XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) +{ + TAG *tStk; + OPEN_INTERNAL_ENTITY *openEntityList; + if (parentParser) + return XML_FALSE; + /* move tagStack to freeTagList */ + tStk = tagStack; + while (tStk) { + TAG *tag = tStk; + tStk = tStk->parent; + tag->parent = freeTagList; + moveToFreeBindingList(parser, tag->bindings); + tag->bindings = NULL; + freeTagList = tag; + } + /* move openInternalEntities to freeInternalEntities */ + openEntityList = openInternalEntities; + while (openEntityList) { + OPEN_INTERNAL_ENTITY *openEntity = openEntityList; + openEntityList = openEntity->next; + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + moveToFreeBindingList(parser, inheritedBindings); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + poolClear(&tempPool); + poolClear(&temp2Pool); + parserInit(parser, encodingName); + dtdReset(_dtd, &parser->m_mem); + return setContext(parser, implicitContext); +} + +enum XML_Status XMLCALL +XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + /* Block after XML_Parse()/XML_ParseBuffer() has been called. + XXX There's no way for the caller to determine which of the + XXX possible error cases caused the XML_STATUS_ERROR return. + */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_STATUS_ERROR; + if (encodingName == NULL) + protocolEncodingName = NULL; + else { + protocolEncodingName = poolCopyString(&tempPool, encodingName); + if (!protocolEncodingName) + return XML_STATUS_ERROR; + } + return XML_STATUS_OK; +} + +XML_Parser XMLCALL +XML_ExternalEntityParserCreate(XML_Parser oldParser, + const XML_Char *context, + const XML_Char *encodingName) +{ + XML_Parser parser = oldParser; + DTD *newDtd = NULL; + DTD *oldDtd = _dtd; + XML_StartElementHandler oldStartElementHandler = startElementHandler; + XML_EndElementHandler oldEndElementHandler = endElementHandler; + XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; + XML_ProcessingInstructionHandler oldProcessingInstructionHandler + = processingInstructionHandler; + XML_CommentHandler oldCommentHandler = commentHandler; + XML_StartCdataSectionHandler oldStartCdataSectionHandler + = startCdataSectionHandler; + XML_EndCdataSectionHandler oldEndCdataSectionHandler + = endCdataSectionHandler; + XML_DefaultHandler oldDefaultHandler = defaultHandler; + XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler + = unparsedEntityDeclHandler; + XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler; + XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler + = startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler + = endNamespaceDeclHandler; + XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler; + XML_ExternalEntityRefHandler oldExternalEntityRefHandler + = externalEntityRefHandler; + XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler; + XML_UnknownEncodingHandler oldUnknownEncodingHandler + = unknownEncodingHandler; + XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler; + XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; + XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; + XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; + ELEMENT_TYPE * oldDeclElementType = declElementType; + + void *oldUserData = userData; + void *oldHandlerArg = handlerArg; + XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; + XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; +#ifdef XML_DTD + enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; + int oldInEntityValue = prologState.inEntityValue; +#endif + XML_Bool oldns_triplets = ns_triplets; + +#ifdef XML_DTD + if (!context) + newDtd = oldDtd; +#endif /* XML_DTD */ + + /* Note that the magical uses of the pre-processor to make field + access look more like C++ require that `parser' be overwritten + here. This makes this function more painful to follow than it + would be otherwise. + */ + if (ns) { + XML_Char tmp[2]; + *tmp = namespaceSeparator; + parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); + } + else { + parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); + } + + if (!parser) + return NULL; + + startElementHandler = oldStartElementHandler; + endElementHandler = oldEndElementHandler; + characterDataHandler = oldCharacterDataHandler; + processingInstructionHandler = oldProcessingInstructionHandler; + commentHandler = oldCommentHandler; + startCdataSectionHandler = oldStartCdataSectionHandler; + endCdataSectionHandler = oldEndCdataSectionHandler; + defaultHandler = oldDefaultHandler; + unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler; + notationDeclHandler = oldNotationDeclHandler; + startNamespaceDeclHandler = oldStartNamespaceDeclHandler; + endNamespaceDeclHandler = oldEndNamespaceDeclHandler; + notStandaloneHandler = oldNotStandaloneHandler; + externalEntityRefHandler = oldExternalEntityRefHandler; + skippedEntityHandler = oldSkippedEntityHandler; + unknownEncodingHandler = oldUnknownEncodingHandler; + elementDeclHandler = oldElementDeclHandler; + attlistDeclHandler = oldAttlistDeclHandler; + entityDeclHandler = oldEntityDeclHandler; + xmlDeclHandler = oldXmlDeclHandler; + declElementType = oldDeclElementType; + userData = oldUserData; + if (oldUserData == oldHandlerArg) + handlerArg = userData; + else + handlerArg = parser; + if (oldExternalEntityRefHandlerArg != oldParser) + externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; + defaultExpandInternalEntities = oldDefaultExpandInternalEntities; + ns_triplets = oldns_triplets; + parentParser = oldParser; +#ifdef XML_DTD + paramEntityParsing = oldParamEntityParsing; + prologState.inEntityValue = oldInEntityValue; + if (context) { +#endif /* XML_DTD */ + if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) + || !setContext(parser, context)) { + XML_ParserFree(parser); + return NULL; + } + processor = externalEntityInitProcessor; +#ifdef XML_DTD + } + else { + /* The DTD instance referenced by _dtd is shared between the document's + root parser and external PE parsers, therefore one does not need to + call setContext. In addition, one also *must* not call setContext, + because this would overwrite existing prefix->binding pointers in + _dtd with ones that get destroyed with the external PE parser. + This would leave those prefixes with dangling pointers. + */ + isParamEntity = XML_TRUE; + XmlPrologStateInitExternalEntity(&prologState); + processor = externalParEntInitProcessor; + } +#endif /* XML_DTD */ + return parser; +} + +static void FASTCALL +destroyBindings(BINDING *bindings, XML_Parser parser) +{ + for (;;) { + BINDING *b = bindings; + if (!b) + break; + bindings = b->nextTagBinding; + FREE(b->uri); + FREE(b); + } +} + +void XMLCALL +XML_ParserFree(XML_Parser parser) +{ + TAG *tagList; + OPEN_INTERNAL_ENTITY *entityList; + if (parser == NULL) + return; + /* free tagStack and freeTagList */ + tagList = tagStack; + for (;;) { + TAG *p; + if (tagList == NULL) { + if (freeTagList == NULL) + break; + tagList = freeTagList; + freeTagList = NULL; + } + p = tagList; + tagList = tagList->parent; + FREE(p->buf); + destroyBindings(p->bindings, parser); + FREE(p); + } + /* free openInternalEntities and freeInternalEntities */ + entityList = openInternalEntities; + for (;;) { + OPEN_INTERNAL_ENTITY *openEntity; + if (entityList == NULL) { + if (freeInternalEntities == NULL) + break; + entityList = freeInternalEntities; + freeInternalEntities = NULL; + } + openEntity = entityList; + entityList = entityList->next; + FREE(openEntity); + } + + destroyBindings(freeBindingList, parser); + destroyBindings(inheritedBindings, parser); + poolDestroy(&tempPool); + poolDestroy(&temp2Pool); +#ifdef XML_DTD + /* external parameter entity parsers share the DTD structure + parser->m_dtd with the root parser, so we must not destroy it + */ + if (!isParamEntity && _dtd) +#else + if (_dtd) +#endif /* XML_DTD */ + dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); + FREE((void *)atts); + FREE(groupConnector); + FREE(buffer); + FREE(dataBuf); + FREE(nsAtts); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + FREE(parser); +} + +void XMLCALL +XML_UseParserAsHandlerArg(XML_Parser parser) +{ + handlerArg = parser; +} + +enum XML_Error XMLCALL +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) +{ +#ifdef XML_DTD + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; + useForeignDTD = useDTD; + return XML_ERROR_NONE; +#else + return XML_ERROR_FEATURE_REQUIRES_XML_DTD; +#endif +} + +void XMLCALL +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return; + ns_triplets = do_nst ? XML_TRUE : XML_FALSE; +} + +void XMLCALL +XML_SetUserData(XML_Parser parser, void *p) +{ + if (handlerArg == userData) + handlerArg = userData = p; + else + userData = p; +} + +enum XML_Status XMLCALL +XML_SetBase(XML_Parser parser, const XML_Char *p) +{ + if (p) { + p = poolCopyString(&_dtd->pool, p); + if (!p) + return XML_STATUS_ERROR; + curBase = p; + } + else + curBase = NULL; + return XML_STATUS_OK; +} + +const XML_Char * XMLCALL +XML_GetBase(XML_Parser parser) +{ + return curBase; +} + +int XMLCALL +XML_GetSpecifiedAttributeCount(XML_Parser parser) +{ + return nSpecifiedAtts; +} + +int XMLCALL +XML_GetIdAttributeIndex(XML_Parser parser) +{ + return idAttIndex; +} + +void XMLCALL +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end) +{ + startElementHandler = start; + endElementHandler = end; +} + +void XMLCALL +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler start) { + startElementHandler = start; +} + +void XMLCALL +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler end) { + endElementHandler = end; +} + +void XMLCALL +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler) +{ + characterDataHandler = handler; +} + +void XMLCALL +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler) +{ + processingInstructionHandler = handler; +} + +void XMLCALL +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler) +{ + commentHandler = handler; +} + +void XMLCALL +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end) +{ + startCdataSectionHandler = start; + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start) { + startCdataSectionHandler = start; +} + +void XMLCALL +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end) { + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_FALSE; +} + +void XMLCALL +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_TRUE; +} + +void XMLCALL +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end) +{ + startDoctypeDeclHandler = start; + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start) { + startDoctypeDeclHandler = start; +} + +void XMLCALL +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end) { + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler) +{ + unparsedEntityDeclHandler = handler; +} + +void XMLCALL +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler) +{ + notationDeclHandler = handler; +} + +void XMLCALL +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end) +{ + startNamespaceDeclHandler = start; + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start) { + startNamespaceDeclHandler = start; +} + +void XMLCALL +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end) { + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler) +{ + notStandaloneHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler) +{ + externalEntityRefHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) +{ + if (arg) + externalEntityRefHandlerArg = (XML_Parser)arg; + else + externalEntityRefHandlerArg = parser; +} + +void XMLCALL +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler) +{ + skippedEntityHandler = handler; +} + +void XMLCALL +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *data) +{ + unknownEncodingHandler = handler; + unknownEncodingHandlerData = data; +} + +void XMLCALL +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl) +{ + elementDeclHandler = eldecl; +} + +void XMLCALL +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl) +{ + attlistDeclHandler = attdecl; +} + +void XMLCALL +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler) +{ + entityDeclHandler = handler; +} + +void XMLCALL +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler handler) { + xmlDeclHandler = handler; +} + +int XMLCALL +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing peParsing) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return 0; +#ifdef XML_DTD + paramEntityParsing = peParsing; + return 1; +#else + return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; +#endif +} + +enum XML_Status XMLCALL +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + ps_parsing = XML_PARSING; + } + + if (len == 0) { + ps_finalBuffer = (XML_Bool)isFinal; + if (!isFinal) + return XML_STATUS_OK; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + + /* If data are left over from last buffer, and we now know that these + data are the final chunk of input, then we have to check them again + to detect errors based on that fact. + */ + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode == XML_ERROR_NONE) { + switch (ps_parsing) { + case XML_SUSPENDED: + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return XML_STATUS_SUSPENDED; + case XML_INITIALIZED: + case XML_PARSING: + ps_parsing = XML_FINISHED; + /* fall through */ + default: + return XML_STATUS_OK; + } + } + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } +#ifndef XML_CONTEXT_BYTES + else if (bufferPtr == bufferEnd) { + const char *end; + int nLeftOver; + enum XML_Error result; + parseEndByteIndex += len; + positionPtr = s; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, s, parseEndPtr = s + len, &end); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + result = XML_STATUS_OK; + if (isFinal) { + ps_parsing = XML_FINISHED; + return result; + } + } + } + + XmlUpdatePosition(encoding, positionPtr, end, &position); + nLeftOver = s + len - end; + if (nLeftOver) { + if (buffer == NULL || nLeftOver > bufferLim - buffer) { + /* FIXME avoid integer overflow */ + char *temp; + temp = (buffer == NULL + ? (char *)MALLOC(len * 2) + : (char *)REALLOC(buffer, len * 2)); + if (temp == NULL) { + errorCode = XML_ERROR_NO_MEMORY; + return XML_STATUS_ERROR; + } + buffer = temp; + if (!buffer) { + errorCode = XML_ERROR_NO_MEMORY; + eventPtr = eventEndPtr = NULL; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + bufferLim = buffer + len * 2; + } + memcpy(buffer, end, nLeftOver); + } + bufferPtr = buffer; + bufferEnd = buffer + nLeftOver; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + eventPtr = bufferPtr; + eventEndPtr = bufferPtr; + return result; + } +#endif /* not defined XML_CONTEXT_BYTES */ + else { + void *buff = XML_GetBuffer(parser, len); + if (buff == NULL) + return XML_STATUS_ERROR; + else { + memcpy(buff, s, len); + return XML_ParseBuffer(parser, len, isFinal); + } + } +} + +enum XML_Status XMLCALL +XML_ParseBuffer(XML_Parser parser, int len, int isFinal) +{ + const char *start; + enum XML_Status result = XML_STATUS_OK; + + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + ps_parsing = XML_PARSING; + } + + start = bufferPtr; + positionPtr = start; + bufferEnd += len; + parseEndPtr = bufferEnd; + parseEndByteIndex += len; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, start, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (isFinal) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; /* should not happen */ + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void * XMLCALL +XML_GetBuffer(XML_Parser parser, int len) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return NULL; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return NULL; + default: ; + } + + if (len > bufferLim - bufferEnd) { + /* FIXME avoid integer overflow */ + int neededSize = len + (int)(bufferEnd - bufferPtr); +#ifdef XML_CONTEXT_BYTES + int keep = (int)(bufferPtr - buffer); + + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + neededSize += keep; +#endif /* defined XML_CONTEXT_BYTES */ + if (neededSize <= bufferLim - buffer) { +#ifdef XML_CONTEXT_BYTES + if (keep < bufferPtr - buffer) { + int offset = (int)(bufferPtr - buffer) - keep; + memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); + bufferEnd -= offset; + bufferPtr -= offset; + } +#else + memmove(buffer, bufferPtr, bufferEnd - bufferPtr); + bufferEnd = buffer + (bufferEnd - bufferPtr); + bufferPtr = buffer; +#endif /* not defined XML_CONTEXT_BYTES */ + } + else { + char *newBuf; + int bufferSize = (int)(bufferLim - bufferPtr); + if (bufferSize == 0) + bufferSize = INIT_BUFFER_SIZE; + do { + bufferSize *= 2; + } while (bufferSize < neededSize); + newBuf = (char *)MALLOC(bufferSize); + if (newBuf == 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } + bufferLim = newBuf + bufferSize; +#ifdef XML_CONTEXT_BYTES + if (bufferPtr) { + int keep = (int)(bufferPtr - buffer); + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); + FREE(buffer); + buffer = newBuf; + bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; + bufferPtr = buffer + keep; + } + else { + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; + } +#else + if (bufferPtr) { + memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); + FREE(buffer); + } + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; +#endif /* not defined XML_CONTEXT_BYTES */ + } + } + return bufferEnd; +} + +enum XML_Status XMLCALL +XML_StopParser(XML_Parser parser, XML_Bool resumable) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + if (resumable) { + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_FINISHED; + break; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + if (resumable) { +#ifdef XML_DTD + if (isParamEntity) { + errorCode = XML_ERROR_SUSPEND_PE; + return XML_STATUS_ERROR; + } +#endif + ps_parsing = XML_SUSPENDED; + } + else + ps_parsing = XML_FINISHED; + } + return XML_STATUS_OK; +} + +enum XML_Status XMLCALL +XML_ResumeParser(XML_Parser parser) +{ + enum XML_Status result = XML_STATUS_OK; + + if (ps_parsing != XML_SUSPENDED) { + errorCode = XML_ERROR_NOT_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_PARSING; + + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (ps_finalBuffer) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void XMLCALL +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) +{ + assert(status != NULL); + *status = parser->m_parsingStatus; +} + +enum XML_Error XMLCALL +XML_GetErrorCode(XML_Parser parser) +{ + return errorCode; +} + +XML_Index XMLCALL +XML_GetCurrentByteIndex(XML_Parser parser) +{ + if (eventPtr) + return parseEndByteIndex - (parseEndPtr - eventPtr); + return -1; +} + +int XMLCALL +XML_GetCurrentByteCount(XML_Parser parser) +{ + if (eventEndPtr && eventPtr) + return (int)(eventEndPtr - eventPtr); + return 0; +} + +const char * XMLCALL +XML_GetInputContext(XML_Parser parser, int *offset, int *size) +{ +#ifdef XML_CONTEXT_BYTES + if (eventPtr && buffer) { + *offset = (int)(eventPtr - buffer); + *size = (int)(bufferEnd - buffer); + return buffer; + } +#endif /* defined XML_CONTEXT_BYTES */ + return (char *) 0; +} + +XML_Size XMLCALL +XML_GetCurrentLineNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.lineNumber + 1; +} + +XML_Size XMLCALL +XML_GetCurrentColumnNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.columnNumber; +} + +void XMLCALL +XML_FreeContentModel(XML_Parser parser, XML_Content *model) +{ + FREE(model); +} + +void * XMLCALL +XML_MemMalloc(XML_Parser parser, size_t size) +{ + return MALLOC(size); +} + +void * XMLCALL +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) +{ + return REALLOC(ptr, size); +} + +void XMLCALL +XML_MemFree(XML_Parser parser, void *ptr) +{ + FREE(ptr); +} + +void XMLCALL +XML_DefaultCurrent(XML_Parser parser) +{ + if (defaultHandler) { + if (openInternalEntities) + reportDefault(parser, + internalEncoding, + openInternalEntities->internalEventPtr, + openInternalEntities->internalEventEndPtr); + else + reportDefault(parser, encoding, eventPtr, eventEndPtr); + } +} + +const XML_LChar * XMLCALL +XML_ErrorString(enum XML_Error code) +{ + static const XML_LChar* const message[] = { + 0, + XML_L("out of memory"), + XML_L("syntax error"), + XML_L("no element found"), + XML_L("not well-formed (invalid token)"), + XML_L("unclosed token"), + XML_L("partial character"), + XML_L("mismatched tag"), + XML_L("duplicate attribute"), + XML_L("junk after document element"), + XML_L("illegal parameter entity reference"), + XML_L("undefined entity"), + XML_L("recursive entity reference"), + XML_L("asynchronous entity"), + XML_L("reference to invalid character number"), + XML_L("reference to binary entity"), + XML_L("reference to external entity in attribute"), + XML_L("XML or text declaration not at start of entity"), + XML_L("unknown encoding"), + XML_L("encoding specified in XML declaration is incorrect"), + XML_L("unclosed CDATA section"), + XML_L("error in processing external entity reference"), + XML_L("document is not standalone"), + XML_L("unexpected parser state - please send a bug report"), + XML_L("entity declared in parameter entity"), + XML_L("requested feature requires XML_DTD support in Expat"), + XML_L("cannot change setting once parsing has begun"), + XML_L("unbound prefix"), + XML_L("must not undeclare prefix"), + XML_L("incomplete markup in parameter entity"), + XML_L("XML declaration not well-formed"), + XML_L("text declaration not well-formed"), + XML_L("illegal character(s) in public id"), + XML_L("parser suspended"), + XML_L("parser not suspended"), + XML_L("parsing aborted"), + XML_L("parsing finished"), + XML_L("cannot suspend in external parameter entity"), + XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), + XML_L("reserved prefix (xmlns) must not be declared or undeclared"), + XML_L("prefix must not be bound to one of the reserved namespace names") + }; + if (code > 0 && code < sizeof(message)/sizeof(message[0])) + return message[code]; + return NULL; +} + +const XML_LChar * XMLCALL +XML_ExpatVersion(void) { + + /* V1 is used to string-ize the version number. However, it would + string-ize the actual version macro *names* unless we get them + substituted before being passed to V1. CPP is defined to expand + a macro, then rescan for more expansions. Thus, we use V2 to expand + the version macros, then CPP will expand the resulting V1() macro + with the correct numerals. */ + /* ### I'm assuming cpp is portable in this respect... */ + +#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) +#define V2(a,b,c) XML_L("expat_")V1(a,b,c) + + return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); + +#undef V1 +#undef V2 +} + +XML_Expat_Version XMLCALL +XML_ExpatVersionInfo(void) +{ + XML_Expat_Version version; + + version.major = XML_MAJOR_VERSION; + version.minor = XML_MINOR_VERSION; + version.micro = XML_MICRO_VERSION; + + return version; +} + +const XML_Feature * XMLCALL +XML_GetFeatureList(void) +{ + static const XML_Feature features[] = { + {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), + sizeof(XML_Char)}, + {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), + sizeof(XML_LChar)}, +#ifdef XML_UNICODE + {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, +#endif +#ifdef XML_UNICODE_WCHAR_T + {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, +#endif +#ifdef XML_DTD + {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, +#endif +#ifdef XML_CONTEXT_BYTES + {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), + XML_CONTEXT_BYTES}, +#endif +#ifdef XML_MIN_SIZE + {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, +#endif +#ifdef XML_NS + {XML_FEATURE_NS, XML_L("XML_NS"), 0}, +#endif +#ifdef XML_LARGE_SIZE + {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, +#endif + {XML_FEATURE_END, NULL, 0} + }; + + return features; +} + +/* Initially tag->rawName always points into the parse buffer; + for those TAG instances opened while the current parse buffer was + processed, and not yet closed, we need to store tag->rawName in a more + permanent location, since the parse buffer is about to be discarded. +*/ +static XML_Bool +storeRawNames(XML_Parser parser) +{ + TAG *tag = tagStack; + while (tag) { + int bufSize; + int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); + char *rawNameBuf = tag->buf + nameLen; + /* Stop if already stored. Since tagStack is a stack, we can stop + at the first entry that has already been copied; everything + below it in the stack is already been accounted for in a + previous call to this function. + */ + if (tag->rawName == rawNameBuf) + break; + /* For re-use purposes we need to ensure that the + size of tag->buf is a multiple of sizeof(XML_Char). + */ + bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); + if (bufSize > tag->bufEnd - tag->buf) { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_FALSE; + /* if tag->name.str points to tag->buf (only when namespace + processing is off) then we have to update it + */ + if (tag->name.str == (XML_Char *)tag->buf) + tag->name.str = (XML_Char *)temp; + /* if tag->name.localPart is set (when namespace processing is on) + then update it as well, since it will always point into tag->buf + */ + if (tag->name.localPart) + tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - + (XML_Char *)tag->buf); + tag->buf = temp; + tag->bufEnd = temp + bufSize; + rawNameBuf = temp + nameLen; + } + memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); + tag->rawName = rawNameBuf; + tag = tag->parent; + } + return XML_TRUE; +} + +static enum XML_Error PTRCALL +contentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 0, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = externalEntityInitProcessor2; + return externalEntityInitProcessor2(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor2(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(encoding, start, end, &next); + switch (tok) { + case XML_TOK_BOM: + /* If we are at the end of the buffer, this would cause the next stage, + i.e. externalEntityInitProcessor3, to pass control directly to + doContent (by detecting XML_TOK_NONE) without processing any xml text + declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. + */ + if (next == end && !ps_finalBuffer) { + *endPtr = next; + return XML_ERROR_NONE; + } + start = next; + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityInitProcessor3; + return externalEntityInitProcessor3(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor3(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + int tok; + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + eventPtr = start; + tok = XmlContentTok(encoding, start, end, &next); + eventEndPtr = next; + + switch (tok) { + case XML_TOK_XML_DECL: + { + enum XML_Error result; + result = processXmlDecl(parser, 1, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *endPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + start = next; + } + } + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityContentProcessor; + tagLevel = 1; + return externalEntityContentProcessor(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityContentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 1, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error +doContent(XML_Parser parser, + int startTagLevel, + const ENCODING *enc, + const char *s, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + + for (;;) { + const char *next = s; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_TRAILING_CR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + *eventEndPP = end; + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) + return XML_ERROR_NO_ELEMENTS; + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (startTagLevel > 0) { + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_NO_ELEMENTS; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (characterDataHandler) + characterDataHandler(handlerArg, &ch, 1); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); + poolDiscard(&dtd->pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity or default handler. + */ + if (!dtd->hasParamEntityRefs || dtd->standalone) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->notation) + return XML_ERROR_BINARY_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + if (!defaultExpandInternalEntities) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, entity->name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + result = processInternalEntity(parser, entity, XML_FALSE); + if (result != XML_ERROR_NONE) + return result; + } + else if (externalEntityRefHandler) { + const XML_Char *context; + entity->open = XML_TRUE; + context = getContext(parser); + entity->open = XML_FALSE; + if (!context) + return XML_ERROR_NO_MEMORY; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + context, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + poolDiscard(&tempPool); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + case XML_TOK_START_TAG_NO_ATTS: + /* fall through */ + case XML_TOK_START_TAG_WITH_ATTS: + { + TAG *tag; + enum XML_Error result; + XML_Char *toPtr; + if (freeTagList) { + tag = freeTagList; + freeTagList = freeTagList->parent; + } + else { + tag = (TAG *)MALLOC(sizeof(TAG)); + if (!tag) + return XML_ERROR_NO_MEMORY; + tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); + if (!tag->buf) { + FREE(tag); + return XML_ERROR_NO_MEMORY; + } + tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; + } + tag->bindings = NULL; + tag->parent = tagStack; + tagStack = tag; + tag->name.localPart = NULL; + tag->name.prefix = NULL; + tag->rawName = s + enc->minBytesPerChar; + tag->rawNameLength = XmlNameLength(enc, tag->rawName); + ++tagLevel; + { + const char *rawNameEnd = tag->rawName + tag->rawNameLength; + const char *fromPtr = tag->rawName; + toPtr = (XML_Char *)tag->buf; + for (;;) { + int bufSize; + int convLen; + XmlConvert(enc, + &fromPtr, rawNameEnd, + (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); + convLen = (int)(toPtr - (XML_Char *)tag->buf); + if (fromPtr == rawNameEnd) { + tag->name.strLen = convLen; + break; + } + bufSize = (int)(tag->bufEnd - tag->buf) << 1; + { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + tag->buf = temp; + tag->bufEnd = temp + bufSize; + toPtr = (XML_Char *)temp + convLen; + } + } + } + tag->name.str = (XML_Char *)tag->buf; + *toPtr = XML_T('\0'); + result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); + if (result) + return result; + if (startElementHandler) + startElementHandler(handlerArg, tag->name.str, + (const XML_Char **)atts); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + break; + } + case XML_TOK_EMPTY_ELEMENT_NO_ATTS: + /* fall through */ + case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: + { + const char *rawName = s + enc->minBytesPerChar; + enum XML_Error result; + BINDING *bindings = NULL; + XML_Bool noElmHandlers = XML_TRUE; + TAG_NAME name; + name.str = poolStoreString(&tempPool, enc, rawName, + rawName + XmlNameLength(enc, rawName)); + if (!name.str) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + result = storeAtts(parser, enc, s, &name, &bindings); + if (result) + return result; + poolFinish(&tempPool); + if (startElementHandler) { + startElementHandler(handlerArg, name.str, (const XML_Char **)atts); + noElmHandlers = XML_FALSE; + } + if (endElementHandler) { + if (startElementHandler) + *eventPP = *eventEndPP; + endElementHandler(handlerArg, name.str); + noElmHandlers = XML_FALSE; + } + if (noElmHandlers && defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + while (bindings) { + BINDING *b = bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + break; + case XML_TOK_END_TAG: + if (tagLevel == startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + else { + int len; + const char *rawName; + TAG *tag = tagStack; + tagStack = tag->parent; + tag->parent = freeTagList; + freeTagList = tag; + rawName = s + enc->minBytesPerChar*2; + len = XmlNameLength(enc, rawName); + if (len != tag->rawNameLength + || memcmp(tag->rawName, rawName, len) != 0) { + *eventPP = rawName; + return XML_ERROR_TAG_MISMATCH; + } + --tagLevel; + if (endElementHandler) { + const XML_Char *localPart; + const XML_Char *prefix; + XML_Char *uri; + localPart = tag->name.localPart; + if (ns && localPart) { + /* localPart and prefix may have been overwritten in + tag->name.str, since this points to the binding->uri + buffer which gets re-used; so we have to add them again + */ + uri = (XML_Char *)tag->name.str + tag->name.uriLen; + /* don't need to check for space - already done in storeAtts() */ + while (*localPart) *uri++ = *localPart++; + prefix = (XML_Char *)tag->name.prefix; + if (ns_triplets && prefix) { + *uri++ = namespaceSeparator; + while (*prefix) *uri++ = *prefix++; + } + *uri = XML_T('\0'); + } + endElementHandler(handlerArg, tag->name.str); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + while (tag->bindings) { + BINDING *b = tag->bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + tag->bindings = tag->bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + } + break; + case XML_TOK_CHAR_REF: + { + int n = XmlCharRefNumber(enc, s); + if (n < 0) + return XML_ERROR_BAD_CHAR_REF; + if (characterDataHandler) { + XML_Char buf[XML_ENCODE_MAX]; + characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_CDATA_SECT_OPEN: + { + enum XML_Error result; + if (startCdataSectionHandler) + startCdataSectionHandler(handlerArg); +#if 0 + /* Suppose you doing a transformation on a document that involves + changing only the character data. You set up a defaultHandler + and a characterDataHandler. The defaultHandler simply copies + characters through. The characterDataHandler does the + transformation and writes the characters out escaping them as + necessary. This case will fail to work if we leave out the + following two lines (because & and < inside CDATA sections will + be incorrectly escaped). + + However, now we have a start/endCdataSectionHandler, so it seems + easier to let the user deal with this. + */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = cdataSectionProcessor; + return result; + } + } + break; + case XML_TOK_TRAILING_RSQB: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (characterDataHandler) { + if (MUST_CONVERT(enc, s)) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + characterDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + } + else + characterDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)end - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) { + *eventPP = end; + return XML_ERROR_NO_ELEMENTS; + } + if (tagLevel != startTagLevel) { + *eventPP = end; + return XML_ERROR_ASYNC_ENTITY; + } + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_DATA_CHARS: + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + default: + if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +/* Precondition: all arguments must be non-NULL; + Purpose: + - normalize attributes + - check attributes for well-formedness + - generate namespace aware attribute names (URI, prefix) + - build list of attributes for startElementHandler + - default attributes + - process namespace declarations (check and report them) + - generate namespace aware element name (URI, prefix) +*/ +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *enc, + const char *attStr, TAG_NAME *tagNamePtr, + BINDING **bindingsPtr) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ELEMENT_TYPE *elementType; + int nDefaultAtts; + const XML_Char **appAtts; /* the attribute list for the application */ + int attIndex = 0; + int prefixLen; + int i; + int n; + XML_Char *uri; + int nPrefixes = 0; + BINDING *binding; + const XML_Char *localPart; + + /* lookup the element type name */ + elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); + if (!elementType) { + const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); + if (!name) + return XML_ERROR_NO_MEMORY; + elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, + sizeof(ELEMENT_TYPE)); + if (!elementType) + return XML_ERROR_NO_MEMORY; + if (ns && !setElementTypePrefix(parser, elementType)) + return XML_ERROR_NO_MEMORY; + } + nDefaultAtts = elementType->nDefaultAtts; + + /* get the attributes from the tokenizer */ + n = XmlGetAttributes(enc, attStr, attsSize, atts); + if (n + nDefaultAtts > attsSize) { + int oldAttsSize = attsSize; + ATTRIBUTE *temp; + attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; + temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + atts = temp; + if (n > oldAttsSize) + XmlGetAttributes(enc, attStr, n, atts); + } + + appAtts = (const XML_Char **)atts; + for (i = 0; i < n; i++) { + /* add the name and value to the attribute list */ + ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, + atts[i].name + + XmlNameLength(enc, atts[i].name)); + if (!attId) + return XML_ERROR_NO_MEMORY; + /* Detect duplicate attributes by their QNames. This does not work when + namespace processing is turned on and different prefixes for the same + namespace are used. For this case we have a check further down. + */ + if ((attId->name)[-1]) { + if (enc == encoding) + eventPtr = atts[i].name; + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + (attId->name)[-1] = 1; + appAtts[attIndex++] = attId->name; + if (!atts[i].normalized) { + enum XML_Error result; + XML_Bool isCdata = XML_TRUE; + + /* figure out whether declared as other than CDATA */ + if (attId->maybeTokenized) { + int j; + for (j = 0; j < nDefaultAtts; j++) { + if (attId == elementType->defaultAtts[j].id) { + isCdata = elementType->defaultAtts[j].isCdata; + break; + } + } + } + + /* normalize the attribute value */ + result = storeAttributeValue(parser, enc, isCdata, + atts[i].valuePtr, atts[i].valueEnd, + &tempPool); + if (result) + return result; + appAtts[attIndex] = poolStart(&tempPool); + poolFinish(&tempPool); + } + else { + /* the value did not need normalizing */ + appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, + atts[i].valueEnd); + if (appAtts[attIndex] == 0) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + } + /* handle prefixed attribute names */ + if (attId->prefix) { + if (attId->xmlns) { + /* deal with namespace declarations here */ + enum XML_Error result = addBinding(parser, attId->prefix, attId, + appAtts[attIndex], bindingsPtr); + if (result) + return result; + --attIndex; + } + else { + /* deal with other prefixed names later */ + attIndex++; + nPrefixes++; + (attId->name)[-1] = 2; + } + } + else + attIndex++; + } + + /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ + nSpecifiedAtts = attIndex; + if (elementType->idAtt && (elementType->idAtt->name)[-1]) { + for (i = 0; i < attIndex; i += 2) + if (appAtts[i] == elementType->idAtt->name) { + idAttIndex = i; + break; + } + } + else + idAttIndex = -1; + + /* do attribute defaulting */ + for (i = 0; i < nDefaultAtts; i++) { + const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; + if (!(da->id->name)[-1] && da->value) { + if (da->id->prefix) { + if (da->id->xmlns) { + enum XML_Error result = addBinding(parser, da->id->prefix, da->id, + da->value, bindingsPtr); + if (result) + return result; + } + else { + (da->id->name)[-1] = 2; + nPrefixes++; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + else { + (da->id->name)[-1] = 1; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + } + appAtts[attIndex] = 0; + + /* expand prefixed attribute names, check for duplicates, + and clear flags that say whether attributes were specified */ + i = 0; + if (nPrefixes) { + int j; /* hash table index */ + unsigned long version = nsAttsVersion; + int nsAttsSize = (int)1 << nsAttsPower; + /* size of hash table must be at least 2 * (# of prefixed attributes) */ + if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ + NS_ATT *temp; + /* hash table size must also be a power of 2 and >= 8 */ + while (nPrefixes >> nsAttsPower++); + if (nsAttsPower < 3) + nsAttsPower = 3; + nsAttsSize = (int)1 << nsAttsPower; + temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); + if (!temp) + return XML_ERROR_NO_MEMORY; + nsAtts = temp; + version = 0; /* force re-initialization of nsAtts hash table */ + } + /* using a version flag saves us from initializing nsAtts every time */ + if (!version) { /* initialize version flags when version wraps around */ + version = INIT_ATTS_VERSION; + for (j = nsAttsSize; j != 0; ) + nsAtts[--j].version = version; + } + nsAttsVersion = --version; + + /* expand prefixed names and check for duplicates */ + for (; i < attIndex; i += 2) { + const XML_Char *s = appAtts[i]; + if (s[-1] == 2) { /* prefixed */ + ATTRIBUTE_ID *id; + const BINDING *b; + unsigned long uriHash = 0; + ((XML_Char *)s)[-1] = 0; /* clear flag */ + id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); + b = id->prefix->binding; + if (!b) + return XML_ERROR_UNBOUND_PREFIX; + + /* as we expand the name we also calculate its hash value */ + for (j = 0; j < b->uriLen; j++) { + const XML_Char c = b->uri[j]; + if (!poolAppendChar(&tempPool, c)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } + while (*s++ != XML_T(ASCII_COLON)) + ; + do { /* copies null terminator */ + const XML_Char c = *s; + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } while (*s++); + + { /* Check hash table for duplicate of expanded name (uriName). + Derived from code in lookup(HASH_TABLE *table, ...). + */ + unsigned char step = 0; + unsigned long mask = nsAttsSize - 1; + j = uriHash & mask; /* index into hash table */ + while (nsAtts[j].version == version) { + /* for speed we compare stored hash values first */ + if (uriHash == nsAtts[j].hash) { + const XML_Char *s1 = poolStart(&tempPool); + const XML_Char *s2 = nsAtts[j].uriName; + /* s1 is null terminated, but not s2 */ + for (; *s1 == *s2 && *s1 != 0; s1++, s2++); + if (*s1 == 0) + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + if (!step) + step = PROBE_STEP(uriHash, mask, nsAttsPower); + j < step ? (j += nsAttsSize - step) : (j -= step); + } + } + + if (ns_triplets) { /* append namespace separator and prefix */ + tempPool.ptr[-1] = namespaceSeparator; + s = b->prefix->name; + do { + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + } while (*s++); + } + + /* store expanded name in attribute list */ + s = poolStart(&tempPool); + poolFinish(&tempPool); + appAtts[i] = s; + + /* fill empty slot with new version, uriName and hash value */ + nsAtts[j].version = version; + nsAtts[j].hash = uriHash; + nsAtts[j].uriName = s; + + if (!--nPrefixes) { + i += 2; + break; + } + } + else /* not prefixed */ + ((XML_Char *)s)[-1] = 0; /* clear flag */ + } + } + /* clear flags for the remaining attributes */ + for (; i < attIndex; i += 2) + ((XML_Char *)(appAtts[i]))[-1] = 0; + for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) + binding->attId->name[-1] = 0; + + if (!ns) + return XML_ERROR_NONE; + + /* expand the element type name */ + if (elementType->prefix) { + binding = elementType->prefix->binding; + if (!binding) + return XML_ERROR_UNBOUND_PREFIX; + localPart = tagNamePtr->str; + while (*localPart++ != XML_T(ASCII_COLON)) + ; + } + else if (dtd->defaultPrefix.binding) { + binding = dtd->defaultPrefix.binding; + localPart = tagNamePtr->str; + } + else + return XML_ERROR_NONE; + prefixLen = 0; + if (ns_triplets && binding->prefix->name) { + for (; binding->prefix->name[prefixLen++];) + ; /* prefixLen includes null terminator */ + } + tagNamePtr->localPart = localPart; + tagNamePtr->uriLen = binding->uriLen; + tagNamePtr->prefix = binding->prefix->name; + tagNamePtr->prefixLen = prefixLen; + for (i = 0; localPart[i++];) + ; /* i includes null terminator */ + n = i + binding->uriLen + prefixLen; + if (n > binding->uriAlloc) { + TAG *p; + uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); + if (!uri) + return XML_ERROR_NO_MEMORY; + binding->uriAlloc = n + EXPAND_SPARE; + memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); + for (p = tagStack; p; p = p->parent) + if (p->name.str == binding->uri) + p->name.str = uri; + FREE(binding->uri); + binding->uri = uri; + } + /* if namespaceSeparator != '\0' then uri includes it already */ + uri = binding->uri + binding->uriLen; + memcpy(uri, localPart, i * sizeof(XML_Char)); + /* we always have a namespace separator between localPart and prefix */ + if (prefixLen) { + uri += i - 1; + *uri = namespaceSeparator; /* replace null terminator */ + memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); + } + tagNamePtr->str = binding->uri; + return XML_ERROR_NONE; +} + +/* addBinding() overwrites the value of prefix->binding without checking. + Therefore one must keep track of the old value outside of addBinding(). +*/ +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr) +{ + static const XML_Char xmlNamespace[] = { + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, + ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, + ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, + ASCII_e, '\0' + }; + static const int xmlLen = + (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; + static const XML_Char xmlnsNamespace[] = { + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, + ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, + ASCII_SLASH, '\0' + }; + static const int xmlnsLen = + (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; + + XML_Bool mustBeXML = XML_FALSE; + XML_Bool isXML = XML_TRUE; + XML_Bool isXMLNS = XML_TRUE; + + BINDING *b; + int len; + + /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ + if (*uri == XML_T('\0') && prefix->name) + return XML_ERROR_UNDECLARING_PREFIX; + + if (prefix->name + && prefix->name[0] == XML_T(ASCII_x) + && prefix->name[1] == XML_T(ASCII_m) + && prefix->name[2] == XML_T(ASCII_l)) { + + /* Not allowed to bind xmlns */ + if (prefix->name[3] == XML_T(ASCII_n) + && prefix->name[4] == XML_T(ASCII_s) + && prefix->name[5] == XML_T('\0')) + return XML_ERROR_RESERVED_PREFIX_XMLNS; + + if (prefix->name[3] == XML_T('\0')) + mustBeXML = XML_TRUE; + } + + for (len = 0; uri[len]; len++) { + if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) + isXML = XML_FALSE; + + if (!mustBeXML && isXMLNS + && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) + isXMLNS = XML_FALSE; + } + isXML = isXML && len == xmlLen; + isXMLNS = isXMLNS && len == xmlnsLen; + + if (mustBeXML != isXML) + return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML + : XML_ERROR_RESERVED_NAMESPACE_URI; + + if (isXMLNS) + return XML_ERROR_RESERVED_NAMESPACE_URI; + + if (namespaceSeparator) + len++; + if (freeBindingList) { + b = freeBindingList; + if (len > b->uriAlloc) { + XML_Char *temp = (XML_Char *)REALLOC(b->uri, + sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + b->uri = temp; + b->uriAlloc = len + EXPAND_SPARE; + } + freeBindingList = b->nextTagBinding; + } + else { + b = (BINDING *)MALLOC(sizeof(BINDING)); + if (!b) + return XML_ERROR_NO_MEMORY; + b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (!b->uri) { + FREE(b); + return XML_ERROR_NO_MEMORY; + } + b->uriAlloc = len + EXPAND_SPARE; + } + b->uriLen = len; + memcpy(b->uri, uri, len * sizeof(XML_Char)); + if (namespaceSeparator) + b->uri[len - 1] = namespaceSeparator; + b->prefix = prefix; + b->attId = attId; + b->prevPrefixBinding = prefix->binding; + /* NULL binding when default namespace undeclared */ + if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) + prefix->binding = NULL; + else + prefix->binding = b; + b->nextTagBinding = *bindingsPtr; + *bindingsPtr = b; + /* if attId == NULL then we are not starting a namespace scope */ + if (attId && startNamespaceDeclHandler) + startNamespaceDeclHandler(handlerArg, prefix->name, + prefix->binding ? uri : 0); + return XML_ERROR_NONE; +} + +/* The idea here is to avoid using stack for each CDATA section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +cdataSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doCdataSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + if (parentParser) { /* we are parsing an external entity */ + processor = externalEntityContentProcessor; + return externalEntityContentProcessor(parser, start, end, endPtr); + } + else { + processor = contentProcessor; + return contentProcessor(parser, start, end, endPtr); + } + } + return result; +} + +/* startPtr gets set to non-null if the section is closed, and to null if + the section is not yet closed. +*/ +static enum XML_Error +doCdataSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + + for (;;) { + const char *next; + int tok = XmlCdataSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_CDATA_SECT_CLOSE: + if (endCdataSectionHandler) + endCdataSectionHandler(handlerArg); +#if 0 + /* see comment under XML_TOK_CDATA_SECT_OPEN */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_DATA_CHARS: + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = next; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_CDATA_SECTION; + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +#ifdef XML_DTD + +/* The idea here is to avoid using stack for each IGNORE section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +ignoreSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + processor = prologProcessor; + return prologProcessor(parser, start, end, endPtr); + } + return result; +} + +/* startPtr gets set to non-null is the section is closed, and to null + if the section is not yet closed. +*/ +static enum XML_Error +doIgnoreSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *next; + int tok; + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + tok = XmlIgnoreSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_IGNORE_SECT: + if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + /* not reached */ +} + +#endif /* XML_DTD */ + +static enum XML_Error +initializeEncoding(XML_Parser parser) +{ + const char *s; +#ifdef XML_UNICODE + char encodingBuf[128]; + if (!protocolEncodingName) + s = NULL; + else { + int i; + for (i = 0; protocolEncodingName[i]; i++) { + if (i == sizeof(encodingBuf) - 1 + || (protocolEncodingName[i] & ~0x7f) != 0) { + encodingBuf[0] = '\0'; + break; + } + encodingBuf[i] = (char)protocolEncodingName[i]; + } + encodingBuf[i] = '\0'; + s = encodingBuf; + } +#else + s = protocolEncodingName; +#endif + if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) + return XML_ERROR_NONE; + return handleUnknownEncoding(parser, protocolEncodingName); +} + +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next) +{ + const char *encodingName = NULL; + const XML_Char *storedEncName = NULL; + const ENCODING *newEncoding = NULL; + const char *version = NULL; + const char *versionend; + const XML_Char *storedversion = NULL; + int standalone = -1; + if (!(ns + ? XmlParseXmlDeclNS + : XmlParseXmlDecl)(isGeneralTextEntity, + encoding, + s, + next, + &eventPtr, + &version, + &versionend, + &encodingName, + &newEncoding, + &standalone)) { + if (isGeneralTextEntity) + return XML_ERROR_TEXT_DECL; + else + return XML_ERROR_XML_DECL; + } + if (!isGeneralTextEntity && standalone == 1) { + _dtd->standalone = XML_TRUE; +#ifdef XML_DTD + if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif /* XML_DTD */ + } + if (xmlDeclHandler) { + if (encodingName != NULL) { + storedEncName = poolStoreString(&temp2Pool, + encoding, + encodingName, + encodingName + + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + poolFinish(&temp2Pool); + } + if (version) { + storedversion = poolStoreString(&temp2Pool, + encoding, + version, + versionend - encoding->minBytesPerChar); + if (!storedversion) + return XML_ERROR_NO_MEMORY; + } + xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); + } + else if (defaultHandler) + reportDefault(parser, encoding, s, next); + if (protocolEncodingName == NULL) { + if (newEncoding) { + if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) { + eventPtr = encodingName; + return XML_ERROR_INCORRECT_ENCODING; + } + encoding = newEncoding; + } + else if (encodingName) { + enum XML_Error result; + if (!storedEncName) { + storedEncName = poolStoreString( + &temp2Pool, encoding, encodingName, + encodingName + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + } + result = handleUnknownEncoding(parser, storedEncName); + poolClear(&temp2Pool); + if (result == XML_ERROR_UNKNOWN_ENCODING) + eventPtr = encodingName; + return result; + } + } + + if (storedEncName || storedversion) + poolClear(&temp2Pool); + + return XML_ERROR_NONE; +} + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + if (unknownEncodingHandler) { + XML_Encoding info; + int i; + for (i = 0; i < 256; i++) + info.map[i] = -1; + info.convert = NULL; + info.data = NULL; + info.release = NULL; + if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, + &info)) { + ENCODING *enc; + unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding()); + if (!unknownEncodingMem) { + if (info.release) + info.release(info.data); + return XML_ERROR_NO_MEMORY; + } + enc = (ns + ? XmlInitUnknownEncodingNS + : XmlInitUnknownEncoding)(unknownEncodingMem, + info.map, + info.convert, + info.data); + if (enc) { + unknownEncodingData = info.data; + unknownEncodingRelease = info.release; + encoding = enc; + return XML_ERROR_NONE; + } + } + if (info.release != NULL) + info.release(info.data); + } + return XML_ERROR_UNKNOWN_ENCODING; +} + +static enum XML_Error PTRCALL +prologInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = prologProcessor; + return prologProcessor(parser, s, end, nextPtr); +} + +#ifdef XML_DTD + +static enum XML_Error PTRCALL +externalParEntInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + + /* we know now that XML_Parse(Buffer) has been called, + so we consider the external parameter entity read */ + _dtd->paramEntityRead = XML_TRUE; + + if (prologState.inEntityValue) { + processor = entityValueInitProcessor; + return entityValueInitProcessor(parser, s, end, nextPtr); + } + else { + processor = externalParEntProcessor; + return externalParEntProcessor(parser, s, end, nextPtr); + } +} + +static enum XML_Error PTRCALL +entityValueInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + int tok; + const char *start = s; + const char *next = start; + eventPtr = start; + + for (;;) { + tok = XmlPrologTok(encoding, start, end, &next); + eventEndPtr = next; + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, encoding, s, end); + } + else if (tok == XML_TOK_XML_DECL) { + enum XML_Error result; + result = processXmlDecl(parser, 0, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + *nextPtr = next; + } + /* stop scanning for text declaration - we found one */ + processor = entityValueProcessor; + return entityValueProcessor(parser, next, end, nextPtr); + } + /* If we are at the end of the buffer, this would cause XmlPrologTok to + return XML_TOK_NONE on the next call, which would then cause the + function to exit with *nextPtr set to s - that is what we want for other + tokens, but not for the BOM - we would rather like to skip it; + then, when this routine is entered the next time, XmlPrologTok will + return XML_TOK_INVALID, since the BOM is still in the buffer + */ + else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { + *nextPtr = next; + return XML_ERROR_NONE; + } + start = next; + eventPtr = start; + } +} + +static enum XML_Error PTRCALL +externalParEntProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok; + + tok = XmlPrologTok(encoding, s, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + } + /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. + However, when parsing an external subset, doProlog will not accept a BOM + as valid, and report a syntax error, so we have to skip the BOM + */ + else if (tok == XML_TOK_BOM) { + s = next; + tok = XmlPrologTok(encoding, s, end, &next); + } + + processor = prologProcessor; + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error PTRCALL +entityValueProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *start = s; + const char *next = s; + const ENCODING *enc = encoding; + int tok; + + for (;;) { + tok = XmlPrologTok(enc, start, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, enc, s, end); + } + start = next; + } +} + +#endif /* XML_DTD */ + +static enum XML_Error PTRCALL +prologProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error +doProlog(XML_Parser parser, + const ENCODING *enc, + const char *s, + const char *end, + int tok, + const char *next, + const char **nextPtr, + XML_Bool haveMore) +{ +#ifdef XML_DTD + static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; +#endif /* XML_DTD */ + static const XML_Char atypeCDATA[] = + { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; + static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; + static const XML_Char atypeIDREF[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; + static const XML_Char atypeIDREFS[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; + static const XML_Char atypeENTITY[] = + { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; + static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, + ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; + static const XML_Char atypeNMTOKEN[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; + static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, + ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; + static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, + ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; + static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; + static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; + + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + enum XML_Content_Quant quant; + + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + + for (;;) { + int role; + XML_Bool handleDefault = XML_TRUE; + *eventPP = s; + *eventEndPP = next; + if (tok <= 0) { + if (haveMore && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: +#ifdef XML_DTD + /* for internal PE NOT referenced between declarations */ + if (enc != encoding && !openInternalEntities->betweenDecl) { + *nextPtr = s; + return XML_ERROR_NONE; + } + /* WFC: PE Between Declarations - must check that PE contains + complete markup, not only for external PEs, but also for + internal PEs if the reference occurs between declarations. + */ + if (isParamEntity || enc != encoding) { + if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) + == XML_ROLE_ERROR) + return XML_ERROR_INCOMPLETE_PE; + *nextPtr = s; + return XML_ERROR_NONE; + } +#endif /* XML_DTD */ + return XML_ERROR_NO_ELEMENTS; + default: + tok = -tok; + next = end; + break; + } + } + role = XmlTokenRole(&prologState, tok, s, next, enc); + switch (role) { + case XML_ROLE_XML_DECL: + { + enum XML_Error result = processXmlDecl(parser, 0, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_NAME: + if (startDoctypeDeclHandler) { + doctypeName = poolStoreString(&tempPool, enc, s, next); + if (!doctypeName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + doctypePubid = NULL; + handleDefault = XML_FALSE; + } + doctypeSysid = NULL; /* always initialize to NULL */ + break; + case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: + if (startDoctypeDeclHandler) { + startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid, + doctypePubid, 1); + doctypeName = NULL; + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + break; +#ifdef XML_DTD + case XML_ROLE_TEXT_DECL: + { + enum XML_Error result = processXmlDecl(parser, 1, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; +#endif /* XML_DTD */ + case XML_ROLE_DOCTYPE_PUBLIC_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + doctypePubid = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!doctypePubid) + return XML_ERROR_NO_MEMORY; + normalizePublicId((XML_Char *)doctypePubid); + poolFinish(&tempPool); + handleDefault = XML_FALSE; + goto alreadyChecked; + } + /* fall through */ + case XML_ROLE_ENTITY_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + alreadyChecked: + if (dtd->keepProcessing && declEntity) { + XML_Char *tem = poolStoreString(&dtd->pool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declEntity->publicId = tem; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_CLOSE: + if (doctypeName) { + startDoctypeDeclHandler(handlerArg, doctypeName, + doctypeSysid, doctypePubid, 0); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + /* doctypeSysid will be non-NULL in the case of a previous + XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler + was not set, indicating an external subset + */ +#ifdef XML_DTD + if (doctypeSysid || useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + if (useForeignDTD) + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else if (!doctypeSysid) + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + useForeignDTD = XML_FALSE; + } +#endif /* XML_DTD */ + if (endDoctypeDeclHandler) { + endDoctypeDeclHandler(handlerArg); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_INSTANCE_START: +#ifdef XML_DTD + /* if there is no DOCTYPE declaration then now is the + last chance to read the foreign DTD + */ + if (useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + } +#endif /* XML_DTD */ + processor = contentProcessor; + return contentProcessor(parser, s, end, nextPtr); + case XML_ROLE_ATTLIST_ELEMENT_NAME: + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_NAME: + declAttributeId = getAttributeId(parser, enc, s, next); + if (!declAttributeId) + return XML_ERROR_NO_MEMORY; + declAttributeIsCdata = XML_FALSE; + declAttributeType = NULL; + declAttributeIsId = XML_FALSE; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_CDATA: + declAttributeIsCdata = XML_TRUE; + declAttributeType = atypeCDATA; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ID: + declAttributeIsId = XML_TRUE; + declAttributeType = atypeID; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREF: + declAttributeType = atypeIDREF; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREFS: + declAttributeType = atypeIDREFS; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITY: + declAttributeType = atypeENTITY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES: + declAttributeType = atypeENTITIES; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: + declAttributeType = atypeNMTOKEN; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: + declAttributeType = atypeNMTOKENS; + checkAttListDeclHandler: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTRIBUTE_ENUM_VALUE: + case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: + if (dtd->keepProcessing && attlistDeclHandler) { + const XML_Char *prefix; + if (declAttributeType) { + prefix = enumValueSep; + } + else { + prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE + ? notationPrefix + : enumValueStart); + } + if (!poolAppendString(&tempPool, prefix)) + return XML_ERROR_NO_MEMORY; + if (!poolAppend(&tempPool, enc, s, next)) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: + case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, declAttributeIsId, + 0, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: + case XML_ROLE_FIXED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + const XML_Char *attVal; + enum XML_Error result = + storeAttributeValue(parser, enc, declAttributeIsCdata, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar, + &dtd->pool); + if (result) + return result; + attVal = poolStart(&dtd->pool); + poolFinish(&dtd->pool); + /* ID attributes aren't allowed to have a default */ + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, XML_FALSE, attVal, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + attVal, + role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_ENTITY_VALUE: + if (dtd->keepProcessing) { + enum XML_Error result = storeEntityValue(parser, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (declEntity) { + declEntity->textPtr = poolStart(&dtd->entityValuePool); + declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); + poolFinish(&dtd->entityValuePool); + if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + declEntity->textPtr, + declEntity->textLen, + curBase, 0, 0, 0); + handleDefault = XML_FALSE; + } + } + else + poolDiscard(&dtd->entityValuePool); + if (result != XML_ERROR_NONE) + return result; + } + break; + case XML_ROLE_DOCTYPE_SYSTEM_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + doctypeSysid = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (doctypeSysid == NULL) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } +#ifdef XML_DTD + else + /* use externalSubsetName to make doctypeSysid non-NULL + for the case where no startDoctypeDeclHandler is set */ + doctypeSysid = externalSubsetName; +#endif /* XML_DTD */ + if (!dtd->standalone +#ifdef XML_DTD + && !paramEntityParsing +#endif /* XML_DTD */ + && notStandaloneHandler + && !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; +#ifndef XML_DTD + break; +#else /* XML_DTD */ + if (!declEntity) { + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + declEntity->publicId = NULL; + } + /* fall through */ +#endif /* XML_DTD */ + case XML_ROLE_ENTITY_SYSTEM_ID: + if (dtd->keepProcessing && declEntity) { + declEntity->systemId = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!declEntity->systemId) + return XML_ERROR_NO_MEMORY; + declEntity->base = curBase; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_COMPLETE: + if (dtd->keepProcessing && declEntity && entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + 0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + 0); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_NOTATION_NAME: + if (dtd->keepProcessing && declEntity) { + declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); + if (!declEntity->notation) + return XML_ERROR_NO_MEMORY; + poolFinish(&dtd->pool); + if (unparsedEntityDeclHandler) { + *eventEndPP = s; + unparsedEntityDeclHandler(handlerArg, + declEntity->name, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + else if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + 0,0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_GENERAL_ENTITY_NAME: + { + if (XmlPredefinedEntityName(enc, s, next)) { + declEntity = NULL; + break; + } + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_FALSE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + } + break; + case XML_ROLE_PARAM_ENTITY_NAME: +#ifdef XML_DTD + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + name, sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_TRUE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } +#else /* not XML_DTD */ + declEntity = NULL; +#endif /* XML_DTD */ + break; + case XML_ROLE_NOTATION_NAME: + declNotationPublicId = NULL; + declNotationName = NULL; + if (notationDeclHandler) { + declNotationName = poolStoreString(&tempPool, enc, s, next); + if (!declNotationName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + if (declNotationName) { /* means notationDeclHandler != NULL */ + XML_Char *tem = poolStoreString(&tempPool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declNotationPublicId = tem; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_SYSTEM_ID: + if (declNotationName && notationDeclHandler) { + const XML_Char *systemId + = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!systemId) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + systemId, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_NOTATION_NO_SYSTEM_ID: + if (declNotationPublicId && notationDeclHandler) { + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + 0, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_ERROR: + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: + /* PE references in internal subset are + not allowed within declarations. */ + return XML_ERROR_PARAM_ENTITY_REF; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + default: + return XML_ERROR_SYNTAX; + } +#ifdef XML_DTD + case XML_ROLE_IGNORE_SECT: + { + enum XML_Error result; + if (defaultHandler) + reportDefault(parser, enc, s, next); + handleDefault = XML_FALSE; + result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = ignoreSectionProcessor; + return result; + } + } + break; +#endif /* XML_DTD */ + case XML_ROLE_GROUP_OPEN: + if (prologState.level >= groupSize) { + if (groupSize) { + char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + groupConnector = temp; + if (dtd->scaffIndex) { + int *temp = (int *)REALLOC(dtd->scaffIndex, + groupSize * sizeof(int)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex = temp; + } + } + else { + groupConnector = (char *)MALLOC(groupSize = 32); + if (!groupConnector) + return XML_ERROR_NO_MEMORY; + } + } + groupConnector[prologState.level] = 0; + if (dtd->in_eldecl) { + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex[dtd->scaffLevel] = myindex; + dtd->scaffLevel++; + dtd->scaffold[myindex].type = XML_CTYPE_SEQ; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_GROUP_SEQUENCE: + if (groupConnector[prologState.level] == ASCII_PIPE) + return XML_ERROR_SYNTAX; + groupConnector[prologState.level] = ASCII_COMMA; + if (dtd->in_eldecl && elementDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_GROUP_CHOICE: + if (groupConnector[prologState.level] == ASCII_COMMA) + return XML_ERROR_SYNTAX; + if (dtd->in_eldecl + && !groupConnector[prologState.level] + && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + != XML_CTYPE_MIXED) + ) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_CHOICE; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + groupConnector[prologState.level] = ASCII_PIPE; + break; + case XML_ROLE_PARAM_ENTITY_REF: +#ifdef XML_DTD + case XML_ROLE_INNER_PARAM_ENTITY_REF: + dtd->hasParamEntityRefs = XML_TRUE; + if (!paramEntityParsing) + dtd->keepProcessing = dtd->standalone; + else { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); + poolDiscard(&dtd->pool); + /* first, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity handler + */ + if (prologState.documentEntity && + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs)) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + dtd->keepProcessing = dtd->standalone; + /* cannot report skipped entities in declarations */ + if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { + skippedEntityHandler(handlerArg, name, 1); + handleDefault = XML_FALSE; + } + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + XML_Bool betweenDecl = + (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); + result = processInternalEntity(parser, entity, betweenDecl); + if (result != XML_ERROR_NONE) + return result; + handleDefault = XML_FALSE; + break; + } + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + } + entity->open = XML_FALSE; + handleDefault = XML_FALSE; + if (!dtd->paramEntityRead) { + dtd->keepProcessing = dtd->standalone; + break; + } + } + else { + dtd->keepProcessing = dtd->standalone; + break; + } + } +#endif /* XML_DTD */ + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + break; + + /* Element declaration stuff */ + + case XML_ROLE_ELEMENT_NAME: + if (elementDeclHandler) { + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + dtd->scaffLevel = 0; + dtd->scaffCount = 0; + dtd->in_eldecl = XML_TRUE; + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ANY: + case XML_ROLE_CONTENT_EMPTY: + if (dtd->in_eldecl) { + if (elementDeclHandler) { + XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); + if (!content) + return XML_ERROR_NO_MEMORY; + content->quant = XML_CQUANT_NONE; + content->name = NULL; + content->numchildren = 0; + content->children = NULL; + content->type = ((role == XML_ROLE_CONTENT_ANY) ? + XML_CTYPE_ANY : + XML_CTYPE_EMPTY); + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, content); + handleDefault = XML_FALSE; + } + dtd->in_eldecl = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_PCDATA: + if (dtd->in_eldecl) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_MIXED; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ELEMENT: + quant = XML_CQUANT_NONE; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_OPT: + quant = XML_CQUANT_OPT; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_REP: + quant = XML_CQUANT_REP; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_PLUS: + quant = XML_CQUANT_PLUS; + elementContent: + if (dtd->in_eldecl) { + ELEMENT_TYPE *el; + const XML_Char *name; + int nameLen; + const char *nxt = (quant == XML_CQUANT_NONE + ? next + : next - enc->minBytesPerChar); + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffold[myindex].type = XML_CTYPE_NAME; + dtd->scaffold[myindex].quant = quant; + el = getElementType(parser, enc, s, nxt); + if (!el) + return XML_ERROR_NO_MEMORY; + name = el->name; + dtd->scaffold[myindex].name = name; + nameLen = 0; + for (; name[nameLen++]; ); + dtd->contentStringLen += nameLen; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_GROUP_CLOSE: + quant = XML_CQUANT_NONE; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_OPT: + quant = XML_CQUANT_OPT; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_REP: + quant = XML_CQUANT_REP; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_PLUS: + quant = XML_CQUANT_PLUS; + closeGroup: + if (dtd->in_eldecl) { + if (elementDeclHandler) + handleDefault = XML_FALSE; + dtd->scaffLevel--; + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; + if (dtd->scaffLevel == 0) { + if (!handleDefault) { + XML_Content *model = build_model(parser); + if (!model) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, model); + } + dtd->in_eldecl = XML_FALSE; + dtd->contentStringLen = 0; + } + } + break; + /* End element declaration stuff */ + + case XML_ROLE_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_NONE: + switch (tok) { + case XML_TOK_BOM: + handleDefault = XML_FALSE; + break; + } + break; + case XML_ROLE_DOCTYPE_NONE: + if (startDoctypeDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ENTITY_NONE: + if (dtd->keepProcessing && entityDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_NOTATION_NONE: + if (notationDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTLIST_NONE: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ELEMENT_NONE: + if (elementDeclHandler) + handleDefault = XML_FALSE; + break; + } /* end of big switch */ + + if (handleDefault && defaultHandler) + reportDefault(parser, enc, s, next); + + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + s = next; + tok = XmlPrologTok(enc, s, end, &next); + } + } + /* not reached */ +} + +static enum XML_Error PTRCALL +epilogProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + processor = epilogProcessor; + eventPtr = s; + for (;;) { + const char *next = NULL; + int tok = XmlPrologTok(encoding, s, end, &next); + eventEndPtr = next; + switch (tok) { + /* report partial linebreak - it might be the last token */ + case -XML_TOK_PROLOG_S: + if (defaultHandler) { + reportDefault(parser, encoding, s, next); + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + } + *nextPtr = next; + return XML_ERROR_NONE; + case XML_TOK_NONE: + *nextPtr = s; + return XML_ERROR_NONE; + case XML_TOK_PROLOG_S: + if (defaultHandler) + reportDefault(parser, encoding, s, next); + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_INVALID: + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + default: + return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; + } + eventPtr = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } +} + +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl) +{ + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity; + + if (freeInternalEntities) { + openEntity = freeInternalEntities; + freeInternalEntities = openEntity->next; + } + else { + openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); + if (!openEntity) + return XML_ERROR_NO_MEMORY; + } + entity->open = XML_TRUE; + entity->processed = 0; + openEntity->next = openInternalEntities; + openInternalEntities = openEntity; + openEntity->entity = entity; + openEntity->startTagLevel = tagLevel; + openEntity->betweenDecl = betweenDecl; + openEntity->internalEventPtr = NULL; + openEntity->internalEventEndPtr = NULL; + textStart = (char *)entity->textPtr; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, tagLevel, internalEncoding, textStart, + textEnd, &next, XML_FALSE); + + if (result == XML_ERROR_NONE) { + if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - textStart); + processor = internalEntityProcessor; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + } + return result; +} + +static enum XML_Error PTRCALL +internalEntityProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + ENTITY *entity; + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; + if (!openEntity) + return XML_ERROR_UNEXPECTED_STATE; + + entity = openEntity->entity; + textStart = ((char *)entity->textPtr) + entity->processed; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, openEntity->startTagLevel, internalEncoding, + textStart, textEnd, &next, XML_FALSE); + + if (result != XML_ERROR_NONE) + return result; + else if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - (char *)entity->textPtr); + return result; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + +#ifdef XML_DTD + if (entity->is_param) { + int tok; + processor = prologProcessor; + tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, nextPtr, + (XML_Bool)!ps_finalBuffer); + } + else +#endif /* XML_DTD */ + { + processor = contentProcessor; + /* see externalEntityContentProcessor vs contentProcessor */ + return doContent(parser, parentParser ? 1 : 0, encoding, s, end, + nextPtr, (XML_Bool)!ps_finalBuffer); + } +} + +static enum XML_Error PTRCALL +errorProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + return errorCode; +} + +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, + end, pool); + if (result) + return result; + if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) + poolChop(pool); + if (!poolAppendChar(pool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + return XML_ERROR_NONE; +} + +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + for (;;) { + const char *next; + int tok = XmlAttributeValueTok(enc, ptr, end, &next); + switch (tok) { + case XML_TOK_NONE: + return XML_ERROR_NONE; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, ptr); + if (n < 0) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + if (!isCdata + && n == 0x20 /* space */ + && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + for (i = 0; i < n; i++) { + if (!poolAppendChar(pool, buf[i])) + return XML_ERROR_NO_MEMORY; + } + } + break; + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, ptr, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_TRAILING_CR: + next = ptr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_ATTRIBUTE_VALUE_S: + case XML_TOK_DATA_NEWLINE: + if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + if (!poolAppendChar(pool, 0x20)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + char checkEntityDecl; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (!poolAppendChar(pool, ch)) + return XML_ERROR_NO_MEMORY; + break; + } + name = poolStoreString(&temp2Pool, enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); + poolDiscard(&temp2Pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal. + */ + if (pool == &dtd->pool) /* are we called from prolog? */ + checkEntityDecl = +#ifdef XML_DTD + prologState.documentEntity && +#endif /* XML_DTD */ + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs); + else /* if (pool == &tempPool): we are called from content */ + checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; + if (checkEntityDecl) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + /* Cannot report skipped entity here - see comments on + skippedEntityHandler. + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + /* Cannot call the default handler because this would be + out of sync with the call to the startElementHandler. + if ((pool == &tempPool) && defaultHandler) + reportDefault(parser, enc, ptr, next); + */ + break; + } + if (entity->open) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_RECURSIVE_ENTITY_REF; + } + if (entity->notation) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BINARY_ENTITY_REF; + } + if (!entity->textPtr) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; + } + else { + enum XML_Error result; + const XML_Char *textEnd = entity->textPtr + entity->textLen; + entity->open = XML_TRUE; + result = appendAttributeValue(parser, internalEncoding, isCdata, + (char *)entity->textPtr, + (char *)textEnd, pool); + entity->open = XML_FALSE; + if (result) + return result; + } + } + break; + default: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_UNEXPECTED_STATE; + } + ptr = next; + } + /* not reached */ +} + +static enum XML_Error +storeEntityValue(XML_Parser parser, + const ENCODING *enc, + const char *entityTextPtr, + const char *entityTextEnd) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + STRING_POOL *pool = &(dtd->entityValuePool); + enum XML_Error result = XML_ERROR_NONE; +#ifdef XML_DTD + int oldInEntityValue = prologState.inEntityValue; + prologState.inEntityValue = 1; +#endif /* XML_DTD */ + /* never return Null for the value argument in EntityDeclHandler, + since this would indicate an external entity; therefore we + have to make sure that entityValuePool.start is not null */ + if (!pool->blocks) { + if (!poolGrow(pool)) + return XML_ERROR_NO_MEMORY; + } + + for (;;) { + const char *next; + int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: +#ifdef XML_DTD + if (isParamEntity || enc != encoding) { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&tempPool, enc, + entityTextPtr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); + poolDiscard(&tempPool); + if (!entity) { + /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ + /* cannot report skipped entity here - see comments on + skippedEntityHandler + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + dtd->keepProcessing = dtd->standalone; + goto endEntityValue; + } + if (entity->open) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_RECURSIVE_ENTITY_REF; + goto endEntityValue; + } + if (entity->systemId) { + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; + goto endEntityValue; + } + entity->open = XML_FALSE; + if (!dtd->paramEntityRead) + dtd->keepProcessing = dtd->standalone; + } + else + dtd->keepProcessing = dtd->standalone; + } + else { + entity->open = XML_TRUE; + result = storeEntityValue(parser, + internalEncoding, + (char *)entity->textPtr, + (char *)(entity->textPtr + + entity->textLen)); + entity->open = XML_FALSE; + if (result) + goto endEntityValue; + } + break; + } +#endif /* XML_DTD */ + /* In the internal subset, PE references are not legal + within markup declarations, e.g entity values in this case. */ + eventPtr = entityTextPtr; + result = XML_ERROR_PARAM_ENTITY_REF; + goto endEntityValue; + case XML_TOK_NONE: + result = XML_ERROR_NONE; + goto endEntityValue; + case XML_TOK_ENTITY_REF: + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, entityTextPtr, next)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + break; + case XML_TOK_TRAILING_CR: + next = entityTextPtr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_DATA_NEWLINE: + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = 0xA; + break; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, entityTextPtr); + if (n < 0) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + for (i = 0; i < n; i++) { + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = buf[i]; + } + } + break; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + default: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_UNEXPECTED_STATE; + goto endEntityValue; + } + entityTextPtr = next; + } +endEntityValue: +#ifdef XML_DTD + prologState.inEntityValue = oldInEntityValue; +#endif /* XML_DTD */ + return result; +} + +static void FASTCALL +normalizeLines(XML_Char *s) +{ + XML_Char *p; + for (;; s++) { + if (*s == XML_T('\0')) + return; + if (*s == 0xD) + break; + } + p = s; + do { + if (*s == 0xD) { + *p++ = 0xA; + if (*++s == 0xA) + s++; + } + else + *p++ = *s++; + } while (*s); + *p = XML_T('\0'); +} + +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + const XML_Char *target; + XML_Char *data; + const char *tem; + if (!processingInstructionHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + start += enc->minBytesPerChar * 2; + tem = start + XmlNameLength(enc, start); + target = poolStoreString(&tempPool, enc, start, tem); + if (!target) + return 0; + poolFinish(&tempPool); + data = poolStoreString(&tempPool, enc, + XmlSkipS(enc, tem), + end - enc->minBytesPerChar*2); + if (!data) + return 0; + normalizeLines(data); + processingInstructionHandler(handlerArg, target, data); + poolClear(&tempPool); + return 1; +} + +static int +reportComment(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + XML_Char *data; + if (!commentHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + data = poolStoreString(&tempPool, + enc, + start + enc->minBytesPerChar * 4, + end - enc->minBytesPerChar * 3); + if (!data) + return 0; + normalizeLines(data); + commentHandler(handlerArg, data); + poolClear(&tempPool); + return 1; +} + +static void +reportDefault(XML_Parser parser, const ENCODING *enc, + const char *s, const char *end) +{ + if (MUST_CONVERT(enc, s)) { + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + do { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); + *eventPP = s; + } while (s != end); + } + else + defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); +} + + +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, + XML_Bool isId, const XML_Char *value, XML_Parser parser) +{ + DEFAULT_ATTRIBUTE *att; + if (value || isId) { + /* The handling of default attributes gets messed up if we have + a default which duplicates a non-default. */ + int i; + for (i = 0; i < type->nDefaultAtts; i++) + if (attId == type->defaultAtts[i].id) + return 1; + if (isId && !type->idAtt && !attId->xmlns) + type->idAtt = attId; + } + if (type->nDefaultAtts == type->allocDefaultAtts) { + if (type->allocDefaultAtts == 0) { + type->allocDefaultAtts = 8; + type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts + * sizeof(DEFAULT_ATTRIBUTE)); + if (!type->defaultAtts) + return 0; + } + else { + DEFAULT_ATTRIBUTE *temp; + int count = type->allocDefaultAtts * 2; + temp = (DEFAULT_ATTRIBUTE *) + REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); + if (temp == NULL) + return 0; + type->allocDefaultAtts = count; + type->defaultAtts = temp; + } + } + att = type->defaultAtts + type->nDefaultAtts; + att->id = attId; + att->value = value; + att->isCdata = isCdata; + if (!isCdata) + attId->maybeTokenized = XML_TRUE; + type->nDefaultAtts += 1; + return 1; +} + +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name; + for (name = elementType->name; *name; name++) { + if (*name == XML_T(ASCII_COLON)) { + PREFIX *prefix; + const XML_Char *s; + for (s = elementType->name; s != name; s++) { + if (!poolAppendChar(&dtd->pool, *s)) + return 0; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return 0; + prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (!prefix) + return 0; + if (prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + elementType->prefix = prefix; + + } + } + return 1; +} + +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ATTRIBUTE_ID *id; + const XML_Char *name; + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + name = poolStoreString(&dtd->pool, enc, start, end); + if (!name) + return NULL; + /* skip quotation mark - its storage will be re-used (like in name[-1]) */ + ++name; + id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); + if (!id) + return NULL; + if (id->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!ns) + ; + else if (name[0] == XML_T(ASCII_x) + && name[1] == XML_T(ASCII_m) + && name[2] == XML_T(ASCII_l) + && name[3] == XML_T(ASCII_n) + && name[4] == XML_T(ASCII_s) + && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { + if (name[5] == XML_T('\0')) + id->prefix = &dtd->defaultPrefix; + else + id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); + id->xmlns = XML_TRUE; + } + else { + int i; + for (i = 0; name[i]; i++) { + /* attributes without prefix are *not* in the default namespace */ + if (name[i] == XML_T(ASCII_COLON)) { + int j; + for (j = 0; j < i; j++) { + if (!poolAppendChar(&dtd->pool, name[j])) + return NULL; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (id->prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + break; + } + } + } + } + return id; +} + +#define CONTEXT_SEP XML_T(ASCII_FF) + +static const XML_Char * +getContext(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + HASH_TABLE_ITER iter; + XML_Bool needSep = XML_FALSE; + + if (dtd->defaultPrefix.binding) { + int i; + int len; + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) + return NULL; + len = dtd->defaultPrefix.binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + hashTableIterInit(&iter, &(dtd->prefixes)); + for (;;) { + int i; + int len; + const XML_Char *s; + PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); + if (!prefix) + break; + if (!prefix->binding) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = prefix->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return NULL; + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) + return NULL; + len = prefix->binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + + hashTableIterInit(&iter, &(dtd->generalEntities)); + for (;;) { + const XML_Char *s; + ENTITY *e = (ENTITY *)hashTableIterNext(&iter); + if (!e) + break; + if (!e->open) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = e->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return 0; + needSep = XML_TRUE; + } + + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return NULL; + return tempPool.start; +} + +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *s = context; + + while (*context != XML_T('\0')) { + if (*s == CONTEXT_SEP || *s == XML_T('\0')) { + ENTITY *e; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); + if (e) + e->open = XML_TRUE; + if (*s != XML_T('\0')) + s++; + context = s; + poolDiscard(&tempPool); + } + else if (*s == XML_T(ASCII_EQUALS)) { + PREFIX *prefix; + if (poolLength(&tempPool) == 0) + prefix = &dtd->defaultPrefix; + else { + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), + sizeof(PREFIX)); + if (!prefix) + return XML_FALSE; + if (prefix->name == poolStart(&tempPool)) { + prefix->name = poolCopyString(&dtd->pool, prefix->name); + if (!prefix->name) + return XML_FALSE; + } + poolDiscard(&tempPool); + } + for (context = s + 1; + *context != CONTEXT_SEP && *context != XML_T('\0'); + context++) + if (!poolAppendChar(&tempPool, *context)) + return XML_FALSE; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + if (addBinding(parser, prefix, NULL, poolStart(&tempPool), + &inheritedBindings) != XML_ERROR_NONE) + return XML_FALSE; + poolDiscard(&tempPool); + if (*context != XML_T('\0')) + ++context; + s = context; + } + else { + if (!poolAppendChar(&tempPool, *s)) + return XML_FALSE; + s++; + } + } + return XML_TRUE; +} + +static void FASTCALL +normalizePublicId(XML_Char *publicId) +{ + XML_Char *p = publicId; + XML_Char *s; + for (s = publicId; *s; s++) { + switch (*s) { + case 0x20: + case 0xD: + case 0xA: + if (p != publicId && p[-1] != 0x20) + *p++ = 0x20; + break; + default: + *p++ = *s; + } + } + if (p != publicId && p[-1] == 0x20) + --p; + *p = XML_T('\0'); +} + +static DTD * +dtdCreate(const XML_Memory_Handling_Suite *ms) +{ + DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); + if (p == NULL) + return p; + poolInit(&(p->pool), ms); + poolInit(&(p->entityValuePool), ms); + hashTableInit(&(p->generalEntities), ms); + hashTableInit(&(p->elementTypes), ms); + hashTableInit(&(p->attributeIds), ms); + hashTableInit(&(p->prefixes), ms); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableInit(&(p->paramEntities), ms); +#endif /* XML_DTD */ + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + p->scaffIndex = NULL; + p->scaffold = NULL; + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; + return p; +} + +static void +dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableClear(&(p->generalEntities)); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableClear(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableClear(&(p->elementTypes)); + hashTableClear(&(p->attributeIds)); + hashTableClear(&(p->prefixes)); + poolClear(&(p->pool)); + poolClear(&(p->entityValuePool)); + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + + ms->free_fcn(p->scaffIndex); + p->scaffIndex = NULL; + ms->free_fcn(p->scaffold); + p->scaffold = NULL; + + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; +} + +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableDestroy(&(p->generalEntities)); +#ifdef XML_DTD + hashTableDestroy(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableDestroy(&(p->elementTypes)); + hashTableDestroy(&(p->attributeIds)); + hashTableDestroy(&(p->prefixes)); + poolDestroy(&(p->pool)); + poolDestroy(&(p->entityValuePool)); + if (isDocEntity) { + ms->free_fcn(p->scaffIndex); + ms->free_fcn(p->scaffold); + } + ms->free_fcn(p); +} + +/* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. + The new DTD has already been initialized. +*/ +static int +dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + + /* Copy the prefix table. */ + + hashTableIterInit(&iter, &(oldDtd->prefixes)); + for (;;) { + const XML_Char *name; + const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); + if (!oldP) + break; + name = poolCopyString(&(newDtd->pool), oldP->name); + if (!name) + return 0; + if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX))) + return 0; + } + + hashTableIterInit(&iter, &(oldDtd->attributeIds)); + + /* Copy the attribute id table. */ + + for (;;) { + ATTRIBUTE_ID *newA; + const XML_Char *name; + const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); + + if (!oldA) + break; + /* Remember to allocate the scratch byte before the name. */ + if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) + return 0; + name = poolCopyString(&(newDtd->pool), oldA->name); + if (!name) + return 0; + ++name; + newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, + sizeof(ATTRIBUTE_ID)); + if (!newA) + return 0; + newA->maybeTokenized = oldA->maybeTokenized; + if (oldA->prefix) { + newA->xmlns = oldA->xmlns; + if (oldA->prefix == &oldDtd->defaultPrefix) + newA->prefix = &newDtd->defaultPrefix; + else + newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), + oldA->prefix->name, 0); + } + } + + /* Copy the element type table. */ + + hashTableIterInit(&iter, &(oldDtd->elementTypes)); + + for (;;) { + int i; + ELEMENT_TYPE *newE; + const XML_Char *name; + const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(&(newDtd->pool), oldE->name); + if (!name) + return 0; + newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, + sizeof(ELEMENT_TYPE)); + if (!newE) + return 0; + if (oldE->nDefaultAtts) { + newE->defaultAtts = (DEFAULT_ATTRIBUTE *) + ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + if (!newE->defaultAtts) { + ms->free_fcn(newE); + return 0; + } + } + if (oldE->idAtt) + newE->idAtt = (ATTRIBUTE_ID *) + lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); + newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; + if (oldE->prefix) + newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), + oldE->prefix->name, 0); + for (i = 0; i < newE->nDefaultAtts; i++) { + newE->defaultAtts[i].id = (ATTRIBUTE_ID *) + lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); + newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; + if (oldE->defaultAtts[i].value) { + newE->defaultAtts[i].value + = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); + if (!newE->defaultAtts[i].value) + return 0; + } + else + newE->defaultAtts[i].value = NULL; + } + } + + /* Copy the entity tables. */ + if (!copyEntityTable(&(newDtd->generalEntities), + &(newDtd->pool), + &(oldDtd->generalEntities))) + return 0; + +#ifdef XML_DTD + if (!copyEntityTable(&(newDtd->paramEntities), + &(newDtd->pool), + &(oldDtd->paramEntities))) + return 0; + newDtd->paramEntityRead = oldDtd->paramEntityRead; +#endif /* XML_DTD */ + + newDtd->keepProcessing = oldDtd->keepProcessing; + newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; + newDtd->standalone = oldDtd->standalone; + + /* Don't want deep copying for scaffolding */ + newDtd->in_eldecl = oldDtd->in_eldecl; + newDtd->scaffold = oldDtd->scaffold; + newDtd->contentStringLen = oldDtd->contentStringLen; + newDtd->scaffSize = oldDtd->scaffSize; + newDtd->scaffLevel = oldDtd->scaffLevel; + newDtd->scaffIndex = oldDtd->scaffIndex; + + return 1; +} /* End dtdCopy */ + +static int +copyEntityTable(HASH_TABLE *newTable, + STRING_POOL *newPool, + const HASH_TABLE *oldTable) +{ + HASH_TABLE_ITER iter; + const XML_Char *cachedOldBase = NULL; + const XML_Char *cachedNewBase = NULL; + + hashTableIterInit(&iter, oldTable); + + for (;;) { + ENTITY *newE; + const XML_Char *name; + const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(newPool, oldE->name); + if (!name) + return 0; + newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY)); + if (!newE) + return 0; + if (oldE->systemId) { + const XML_Char *tem = poolCopyString(newPool, oldE->systemId); + if (!tem) + return 0; + newE->systemId = tem; + if (oldE->base) { + if (oldE->base == cachedOldBase) + newE->base = cachedNewBase; + else { + cachedOldBase = oldE->base; + tem = poolCopyString(newPool, cachedOldBase); + if (!tem) + return 0; + cachedNewBase = newE->base = tem; + } + } + if (oldE->publicId) { + tem = poolCopyString(newPool, oldE->publicId); + if (!tem) + return 0; + newE->publicId = tem; + } + } + else { + const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, + oldE->textLen); + if (!tem) + return 0; + newE->textPtr = tem; + newE->textLen = oldE->textLen; + } + if (oldE->notation) { + const XML_Char *tem = poolCopyString(newPool, oldE->notation); + if (!tem) + return 0; + newE->notation = tem; + } + newE->is_param = oldE->is_param; + newE->is_internal = oldE->is_internal; + } + return 1; +} + +#define INIT_POWER 6 + +static XML_Bool FASTCALL +keyeq(KEY s1, KEY s2) +{ + for (; *s1 == *s2; s1++, s2++) + if (*s1 == 0) + return XML_TRUE; + return XML_FALSE; +} + +static unsigned long FASTCALL +hash(KEY s) +{ + unsigned long h = 0; + while (*s) + h = CHAR_HASH(h, *s++); + return h; +} + +static NAMED * +lookup(HASH_TABLE *table, KEY name, size_t createSize) +{ + size_t i; + if (table->size == 0) { + size_t tsize; + if (!createSize) + return NULL; + table->power = INIT_POWER; + /* table->size is a power of 2 */ + table->size = (size_t)1 << INIT_POWER; + tsize = table->size * sizeof(NAMED *); + table->v = (NAMED **)table->mem->malloc_fcn(tsize); + if (!table->v) { + table->size = 0; + return NULL; + } + memset(table->v, 0, tsize); + i = hash(name) & ((unsigned long)table->size - 1); + } + else { + unsigned long h = hash(name); + unsigned long mask = (unsigned long)table->size - 1; + unsigned char step = 0; + i = h & mask; + while (table->v[i]) { + if (keyeq(name, table->v[i]->name)) + return table->v[i]; + if (!step) + step = PROBE_STEP(h, mask, table->power); + i < step ? (i += table->size - step) : (i -= step); + } + if (!createSize) + return NULL; + + /* check for overflow (table is half full) */ + if (table->used >> (table->power - 1)) { + unsigned char newPower = table->power + 1; + size_t newSize = (size_t)1 << newPower; + unsigned long newMask = (unsigned long)newSize - 1; + size_t tsize = newSize * sizeof(NAMED *); + NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); + if (!newV) + return NULL; + memset(newV, 0, tsize); + for (i = 0; i < table->size; i++) + if (table->v[i]) { + unsigned long newHash = hash(table->v[i]->name); + size_t j = newHash & newMask; + step = 0; + while (newV[j]) { + if (!step) + step = PROBE_STEP(newHash, newMask, newPower); + j < step ? (j += newSize - step) : (j -= step); + } + newV[j] = table->v[i]; + } + table->mem->free_fcn(table->v); + table->v = newV; + table->power = newPower; + table->size = newSize; + i = h & newMask; + step = 0; + while (table->v[i]) { + if (!step) + step = PROBE_STEP(h, newMask, newPower); + i < step ? (i += newSize - step) : (i -= step); + } + } + } + table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); + if (!table->v[i]) + return NULL; + memset(table->v[i], 0, createSize); + table->v[i]->name = name; + (table->used)++; + return table->v[i]; +} + +static void FASTCALL +hashTableClear(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) { + table->mem->free_fcn(table->v[i]); + table->v[i] = NULL; + } + table->used = 0; +} + +static void FASTCALL +hashTableDestroy(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) + table->mem->free_fcn(table->v[i]); + table->mem->free_fcn(table->v); +} + +static void FASTCALL +hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) +{ + p->power = 0; + p->size = 0; + p->used = 0; + p->v = NULL; + p->mem = ms; +} + +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) +{ + iter->p = table->v; + iter->end = iter->p + table->size; +} + +static NAMED * FASTCALL +hashTableIterNext(HASH_TABLE_ITER *iter) +{ + while (iter->p != iter->end) { + NAMED *tem = *(iter->p)++; + if (tem) + return tem; + } + return NULL; +} + +static void FASTCALL +poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) +{ + pool->blocks = NULL; + pool->freeBlocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; + pool->mem = ms; +} + +static void FASTCALL +poolClear(STRING_POOL *pool) +{ + if (!pool->freeBlocks) + pool->freeBlocks = pool->blocks; + else { + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + p->next = pool->freeBlocks; + pool->freeBlocks = p; + p = tem; + } + } + pool->blocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; +} + +static void FASTCALL +poolDestroy(STRING_POOL *pool) +{ + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } + p = pool->freeBlocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } +} + +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (;;) { + XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + if (ptr == end) + break; + if (!poolGrow(pool)) + return NULL; + } + return pool->start; +} + +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s) +{ + do { + if (!poolAppendChar(pool, *s)) + return NULL; + } while (*s++); + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (; n > 0; --n, s++) { + if (!poolAppendChar(pool, *s)) + return NULL; + } + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s) +{ + while (*s) { + if (!poolAppendChar(pool, *s)) + return NULL; + s++; + } + return pool->start; +} + +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!poolAppend(pool, enc, ptr, end)) + return NULL; + if (pool->ptr == pool->end && !poolGrow(pool)) + return NULL; + *(pool->ptr)++ = 0; + return pool->start; +} + +static XML_Bool FASTCALL +poolGrow(STRING_POOL *pool) +{ + if (pool->freeBlocks) { + if (pool->start == 0) { + pool->blocks = pool->freeBlocks; + pool->freeBlocks = pool->freeBlocks->next; + pool->blocks->next = NULL; + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + pool->ptr = pool->start; + return XML_TRUE; + } + if (pool->end - pool->start < pool->freeBlocks->size) { + BLOCK *tem = pool->freeBlocks->next; + pool->freeBlocks->next = pool->blocks; + pool->blocks = pool->freeBlocks; + pool->freeBlocks = tem; + memcpy(pool->blocks->s, pool->start, + (pool->end - pool->start) * sizeof(XML_Char)); + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + return XML_TRUE; + } + } + if (pool->blocks && pool->start == pool->blocks->s) { + int blockSize = (int)(pool->end - pool->start)*2; + pool->blocks = (BLOCK *) + pool->mem->realloc_fcn(pool->blocks, + (offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char))); + if (pool->blocks == NULL) + return XML_FALSE; + pool->blocks->size = blockSize; + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + blockSize; + } + else { + BLOCK *tem; + int blockSize = (int)(pool->end - pool->start); + if (blockSize < INIT_BLOCK_SIZE) + blockSize = INIT_BLOCK_SIZE; + else + blockSize *= 2; + tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char)); + if (!tem) + return XML_FALSE; + tem->size = blockSize; + tem->next = pool->blocks; + pool->blocks = tem; + if (pool->ptr != pool->start) + memcpy(tem->s, pool->start, + (pool->ptr - pool->start) * sizeof(XML_Char)); + pool->ptr = tem->s + (pool->ptr - pool->start); + pool->start = tem->s; + pool->end = tem->s + blockSize; + } + return XML_TRUE; +} + +static int FASTCALL +nextScaffoldPart(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + CONTENT_SCAFFOLD * me; + int next; + + if (!dtd->scaffIndex) { + dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); + if (!dtd->scaffIndex) + return -1; + dtd->scaffIndex[0] = 0; + } + + if (dtd->scaffCount >= dtd->scaffSize) { + CONTENT_SCAFFOLD *temp; + if (dtd->scaffold) { + temp = (CONTENT_SCAFFOLD *) + REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize *= 2; + } + else { + temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS + * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; + } + dtd->scaffold = temp; + } + next = dtd->scaffCount++; + me = &dtd->scaffold[next]; + if (dtd->scaffLevel) { + CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; + if (parent->lastchild) { + dtd->scaffold[parent->lastchild].nextsib = next; + } + if (!parent->childcnt) + parent->firstchild = next; + parent->lastchild = next; + parent->childcnt++; + } + me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; + return next; +} + +static void +build_node(XML_Parser parser, + int src_node, + XML_Content *dest, + XML_Content **contpos, + XML_Char **strpos) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + dest->type = dtd->scaffold[src_node].type; + dest->quant = dtd->scaffold[src_node].quant; + if (dest->type == XML_CTYPE_NAME) { + const XML_Char *src; + dest->name = *strpos; + src = dtd->scaffold[src_node].name; + for (;;) { + *(*strpos)++ = *src; + if (!*src) + break; + src++; + } + dest->numchildren = 0; + dest->children = NULL; + } + else { + unsigned int i; + int cn; + dest->numchildren = dtd->scaffold[src_node].childcnt; + dest->children = *contpos; + *contpos += dest->numchildren; + for (i = 0, cn = dtd->scaffold[src_node].firstchild; + i < dest->numchildren; + i++, cn = dtd->scaffold[cn].nextsib) { + build_node(parser, cn, &(dest->children[i]), contpos, strpos); + } + dest->name = NULL; + } +} + +static XML_Content * +build_model (XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + XML_Content *ret; + XML_Content *cpos; + XML_Char * str; + int allocsize = (dtd->scaffCount * sizeof(XML_Content) + + (dtd->contentStringLen * sizeof(XML_Char))); + + ret = (XML_Content *)MALLOC(allocsize); + if (!ret) + return NULL; + + str = (XML_Char *) (&ret[dtd->scaffCount]); + cpos = &ret[1]; + + build_node(parser, 0, ret, &cpos, &str); + return ret; +} + +static ELEMENT_TYPE * +getElementType(XML_Parser parser, + const ENCODING *enc, + const char *ptr, + const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); + ELEMENT_TYPE *ret; + + if (!name) + return NULL; + ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); + if (!ret) + return NULL; + if (ret->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!setElementTypePrefix(parser, ret)) + return NULL; + } + return ret; +} diff --git a/XML/src/xmlrole.c b/XML/src/xmlrole.c index 1e5ddc41c..f41ca8fce 100644 --- a/XML/src/xmlrole.c +++ b/XML/src/xmlrole.c @@ -1,1336 +1,1336 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#include - -#ifdef COMPILED_FROM_DSP -#include "winconfig.h" -#elif defined(MACOS_CLASSIC) -#include "macconfig.h" -#elif defined(__amigaos4__) -#include "amigaconfig.h" -#elif defined(__WATCOMC__) -#include "watcomconfig.h" -#else -#ifdef HAVE_EXPAT_CONFIG_H -#include "expat_config.h" -#endif -#endif /* ndef COMPILED_FROM_DSP */ - -#include "Poco/XML/expat_external.h" -#include "internal.h" -#include "xmlrole.h" -#include "ascii.h" - -/* Doesn't check: - - that ,| are not mixed in a model group - content of literals - -*/ - -static const char KW_ANY[] = { - ASCII_A, ASCII_N, ASCII_Y, '\0' }; -static const char KW_ATTLIST[] = { - ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; -static const char KW_CDATA[] = { - ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_DOCTYPE[] = { - ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; -static const char KW_ELEMENT[] = { - ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; -static const char KW_EMPTY[] = { - ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; -static const char KW_ENTITIES[] = { - ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, - '\0' }; -static const char KW_ENTITY[] = { - ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; -static const char KW_FIXED[] = { - ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; -static const char KW_ID[] = { - ASCII_I, ASCII_D, '\0' }; -static const char KW_IDREF[] = { - ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; -static const char KW_IDREFS[] = { - ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; -#ifdef XML_DTD -static const char KW_IGNORE[] = { - ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; -#endif -static const char KW_IMPLIED[] = { - ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; -#ifdef XML_DTD -static const char KW_INCLUDE[] = { - ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; -#endif -static const char KW_NDATA[] = { - ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_NMTOKEN[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; -static const char KW_NMTOKENS[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, - '\0' }; -static const char KW_NOTATION[] = - { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, - '\0' }; -static const char KW_PCDATA[] = { - ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_PUBLIC[] = { - ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; -static const char KW_REQUIRED[] = { - ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, - '\0' }; -static const char KW_SYSTEM[] = { - ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; - -#ifndef MIN_BYTES_PER_CHAR -#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) -#endif - -#ifdef XML_DTD -#define setTopLevel(state) \ - ((state)->handler = ((state)->documentEntity \ - ? internalSubset \ - : externalSubset1)) -#else /* not XML_DTD */ -#define setTopLevel(state) ((state)->handler = internalSubset) -#endif /* not XML_DTD */ - -typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc); - -static PROLOG_HANDLER - prolog0, prolog1, prolog2, - doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, - internalSubset, - entity0, entity1, entity2, entity3, entity4, entity5, entity6, - entity7, entity8, entity9, entity10, - notation0, notation1, notation2, notation3, notation4, - attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, - attlist7, attlist8, attlist9, - element0, element1, element2, element3, element4, element5, element6, - element7, -#ifdef XML_DTD - externalSubset0, externalSubset1, - condSect0, condSect1, condSect2, -#endif /* XML_DTD */ - declClose, - error; - -static int FASTCALL common(PROLOG_STATE *state, int tok); - -static int PTRCALL -prolog0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - state->handler = prolog1; - return XML_ROLE_NONE; - case XML_TOK_XML_DECL: - state->handler = prolog1; - return XML_ROLE_XML_DECL; - case XML_TOK_PI: - state->handler = prolog1; - return XML_ROLE_PI; - case XML_TOK_COMMENT: - state->handler = prolog1; - return XML_ROLE_COMMENT; - case XML_TOK_BOM: - return XML_ROLE_NONE; - case XML_TOK_DECL_OPEN: - if (!XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_DOCTYPE)) - break; - state->handler = doctype0; - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_INSTANCE_START: - state->handler = error; - return XML_ROLE_INSTANCE_START; - } - return common(state, tok); -} - -static int PTRCALL -prolog1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_PI: - return XML_ROLE_PI; - case XML_TOK_COMMENT: - return XML_ROLE_COMMENT; - case XML_TOK_BOM: - return XML_ROLE_NONE; - case XML_TOK_DECL_OPEN: - if (!XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_DOCTYPE)) - break; - state->handler = doctype0; - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_INSTANCE_START: - state->handler = error; - return XML_ROLE_INSTANCE_START; - } - return common(state, tok); -} - -static int PTRCALL -prolog2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_PI: - return XML_ROLE_PI; - case XML_TOK_COMMENT: - return XML_ROLE_COMMENT; - case XML_TOK_INSTANCE_START: - state->handler = error; - return XML_ROLE_INSTANCE_START; - } - return common(state, tok); -} - -static int PTRCALL -doctype0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = doctype1; - return XML_ROLE_DOCTYPE_NAME; - } - return common(state, tok); -} - -static int PTRCALL -doctype1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_OPEN_BRACKET: - state->handler = internalSubset; - return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; - case XML_TOK_DECL_CLOSE: - state->handler = prolog2; - return XML_ROLE_DOCTYPE_CLOSE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { - state->handler = doctype3; - return XML_ROLE_DOCTYPE_NONE; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { - state->handler = doctype2; - return XML_ROLE_DOCTYPE_NONE; - } - break; - } - return common(state, tok); -} - -static int PTRCALL -doctype2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_LITERAL: - state->handler = doctype3; - return XML_ROLE_DOCTYPE_PUBLIC_ID; - } - return common(state, tok); -} - -static int PTRCALL -doctype3(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_LITERAL: - state->handler = doctype4; - return XML_ROLE_DOCTYPE_SYSTEM_ID; - } - return common(state, tok); -} - -static int PTRCALL -doctype4(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_OPEN_BRACKET: - state->handler = internalSubset; - return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; - case XML_TOK_DECL_CLOSE: - state->handler = prolog2; - return XML_ROLE_DOCTYPE_CLOSE; - } - return common(state, tok); -} - -static int PTRCALL -doctype5(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_DECL_CLOSE: - state->handler = prolog2; - return XML_ROLE_DOCTYPE_CLOSE; - } - return common(state, tok); -} - -static int PTRCALL -internalSubset(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_DECL_OPEN: - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_ENTITY)) { - state->handler = entity0; - return XML_ROLE_ENTITY_NONE; - } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_ATTLIST)) { - state->handler = attlist0; - return XML_ROLE_ATTLIST_NONE; - } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_ELEMENT)) { - state->handler = element0; - return XML_ROLE_ELEMENT_NONE; - } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_NOTATION)) { - state->handler = notation0; - return XML_ROLE_NOTATION_NONE; - } - break; - case XML_TOK_PI: - return XML_ROLE_PI; - case XML_TOK_COMMENT: - return XML_ROLE_COMMENT; - case XML_TOK_PARAM_ENTITY_REF: - return XML_ROLE_PARAM_ENTITY_REF; - case XML_TOK_CLOSE_BRACKET: - state->handler = doctype5; - return XML_ROLE_DOCTYPE_NONE; - case XML_TOK_NONE: - return XML_ROLE_NONE; - } - return common(state, tok); -} - -#ifdef XML_DTD - -static int PTRCALL -externalSubset0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - state->handler = externalSubset1; - if (tok == XML_TOK_XML_DECL) - return XML_ROLE_TEXT_DECL; - return externalSubset1(state, tok, ptr, end, enc); -} - -static int PTRCALL -externalSubset1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_COND_SECT_OPEN: - state->handler = condSect0; - return XML_ROLE_NONE; - case XML_TOK_COND_SECT_CLOSE: - if (state->includeLevel == 0) - break; - state->includeLevel -= 1; - return XML_ROLE_NONE; - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_CLOSE_BRACKET: - break; - case XML_TOK_NONE: - if (state->includeLevel) - break; - return XML_ROLE_NONE; - default: - return internalSubset(state, tok, ptr, end, enc); - } - return common(state, tok); -} - -#endif /* XML_DTD */ - -static int PTRCALL -entity0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_PERCENT: - state->handler = entity1; - return XML_ROLE_ENTITY_NONE; - case XML_TOK_NAME: - state->handler = entity2; - return XML_ROLE_GENERAL_ENTITY_NAME; - } - return common(state, tok); -} - -static int PTRCALL -entity1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_NAME: - state->handler = entity7; - return XML_ROLE_PARAM_ENTITY_NAME; - } - return common(state, tok); -} - -static int PTRCALL -entity2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { - state->handler = entity4; - return XML_ROLE_ENTITY_NONE; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { - state->handler = entity3; - return XML_ROLE_ENTITY_NONE; - } - break; - case XML_TOK_LITERAL: - state->handler = declClose; - state->role_none = XML_ROLE_ENTITY_NONE; - return XML_ROLE_ENTITY_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -entity3(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_LITERAL: - state->handler = entity4; - return XML_ROLE_ENTITY_PUBLIC_ID; - } - return common(state, tok); -} - -static int PTRCALL -entity4(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_LITERAL: - state->handler = entity5; - return XML_ROLE_ENTITY_SYSTEM_ID; - } - return common(state, tok); -} - -static int PTRCALL -entity5(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_DECL_CLOSE: - setTopLevel(state); - return XML_ROLE_ENTITY_COMPLETE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) { - state->handler = entity6; - return XML_ROLE_ENTITY_NONE; - } - break; - } - return common(state, tok); -} - -static int PTRCALL -entity6(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_NAME: - state->handler = declClose; - state->role_none = XML_ROLE_ENTITY_NONE; - return XML_ROLE_ENTITY_NOTATION_NAME; - } - return common(state, tok); -} - -static int PTRCALL -entity7(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { - state->handler = entity9; - return XML_ROLE_ENTITY_NONE; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { - state->handler = entity8; - return XML_ROLE_ENTITY_NONE; - } - break; - case XML_TOK_LITERAL: - state->handler = declClose; - state->role_none = XML_ROLE_ENTITY_NONE; - return XML_ROLE_ENTITY_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -entity8(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_LITERAL: - state->handler = entity9; - return XML_ROLE_ENTITY_PUBLIC_ID; - } - return common(state, tok); -} - -static int PTRCALL -entity9(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_LITERAL: - state->handler = entity10; - return XML_ROLE_ENTITY_SYSTEM_ID; - } - return common(state, tok); -} - -static int PTRCALL -entity10(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ENTITY_NONE; - case XML_TOK_DECL_CLOSE: - setTopLevel(state); - return XML_ROLE_ENTITY_COMPLETE; - } - return common(state, tok); -} - -static int PTRCALL -notation0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NOTATION_NONE; - case XML_TOK_NAME: - state->handler = notation1; - return XML_ROLE_NOTATION_NAME; - } - return common(state, tok); -} - -static int PTRCALL -notation1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NOTATION_NONE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { - state->handler = notation3; - return XML_ROLE_NOTATION_NONE; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { - state->handler = notation2; - return XML_ROLE_NOTATION_NONE; - } - break; - } - return common(state, tok); -} - -static int PTRCALL -notation2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NOTATION_NONE; - case XML_TOK_LITERAL: - state->handler = notation4; - return XML_ROLE_NOTATION_PUBLIC_ID; - } - return common(state, tok); -} - -static int PTRCALL -notation3(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NOTATION_NONE; - case XML_TOK_LITERAL: - state->handler = declClose; - state->role_none = XML_ROLE_NOTATION_NONE; - return XML_ROLE_NOTATION_SYSTEM_ID; - } - return common(state, tok); -} - -static int PTRCALL -notation4(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NOTATION_NONE; - case XML_TOK_LITERAL: - state->handler = declClose; - state->role_none = XML_ROLE_NOTATION_NONE; - return XML_ROLE_NOTATION_SYSTEM_ID; - case XML_TOK_DECL_CLOSE: - setTopLevel(state); - return XML_ROLE_NOTATION_NO_SYSTEM_ID; - } - return common(state, tok); -} - -static int PTRCALL -attlist0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = attlist1; - return XML_ROLE_ATTLIST_ELEMENT_NAME; - } - return common(state, tok); -} - -static int PTRCALL -attlist1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_DECL_CLOSE: - setTopLevel(state); - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = attlist2; - return XML_ROLE_ATTRIBUTE_NAME; - } - return common(state, tok); -} - -static int PTRCALL -attlist2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NAME: - { - static const char * const types[] = { - KW_CDATA, - KW_ID, - KW_IDREF, - KW_IDREFS, - KW_ENTITY, - KW_ENTITIES, - KW_NMTOKEN, - KW_NMTOKENS, - }; - int i; - for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) - if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { - state->handler = attlist8; - return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; - } - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { - state->handler = attlist5; - return XML_ROLE_ATTLIST_NONE; - } - break; - case XML_TOK_OPEN_PAREN: - state->handler = attlist3; - return XML_ROLE_ATTLIST_NONE; - } - return common(state, tok); -} - -static int PTRCALL -attlist3(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NMTOKEN: - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = attlist4; - return XML_ROLE_ATTRIBUTE_ENUM_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -attlist4(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_CLOSE_PAREN: - state->handler = attlist8; - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_OR: - state->handler = attlist3; - return XML_ROLE_ATTLIST_NONE; - } - return common(state, tok); -} - -static int PTRCALL -attlist5(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_OPEN_PAREN: - state->handler = attlist6; - return XML_ROLE_ATTLIST_NONE; - } - return common(state, tok); -} - -static int PTRCALL -attlist6(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NAME: - state->handler = attlist7; - return XML_ROLE_ATTRIBUTE_NOTATION_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -attlist7(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_CLOSE_PAREN: - state->handler = attlist8; - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_OR: - state->handler = attlist6; - return XML_ROLE_ATTLIST_NONE; - } - return common(state, tok); -} - -/* default value */ -static int PTRCALL -attlist8(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_POUND_NAME: - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, - KW_IMPLIED)) { - state->handler = attlist1; - return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; - } - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, - KW_REQUIRED)) { - state->handler = attlist1; - return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; - } - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, - KW_FIXED)) { - state->handler = attlist9; - return XML_ROLE_ATTLIST_NONE; - } - break; - case XML_TOK_LITERAL: - state->handler = attlist1; - return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -attlist9(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ATTLIST_NONE; - case XML_TOK_LITERAL: - state->handler = attlist1; - return XML_ROLE_FIXED_ATTRIBUTE_VALUE; - } - return common(state, tok); -} - -static int PTRCALL -element0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = element1; - return XML_ROLE_ELEMENT_NAME; - } - return common(state, tok); -} - -static int PTRCALL -element1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - return XML_ROLE_CONTENT_EMPTY; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - return XML_ROLE_CONTENT_ANY; - } - break; - case XML_TOK_OPEN_PAREN: - state->handler = element2; - state->level = 1; - return XML_ROLE_GROUP_OPEN; - } - return common(state, tok); -} - -static int PTRCALL -element2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_POUND_NAME: - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, - KW_PCDATA)) { - state->handler = element3; - return XML_ROLE_CONTENT_PCDATA; - } - break; - case XML_TOK_OPEN_PAREN: - state->level = 2; - state->handler = element6; - return XML_ROLE_GROUP_OPEN; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT; - case XML_TOK_NAME_QUESTION: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_OPT; - case XML_TOK_NAME_ASTERISK: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_REP; - case XML_TOK_NAME_PLUS: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_PLUS; - } - return common(state, tok); -} - -static int PTRCALL -element3(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_CLOSE_PAREN: - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - return XML_ROLE_GROUP_CLOSE; - case XML_TOK_CLOSE_PAREN_ASTERISK: - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - return XML_ROLE_GROUP_CLOSE_REP; - case XML_TOK_OR: - state->handler = element4; - return XML_ROLE_ELEMENT_NONE; - } - return common(state, tok); -} - -static int PTRCALL -element4(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = element5; - return XML_ROLE_CONTENT_ELEMENT; - } - return common(state, tok); -} - -static int PTRCALL -element5(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_CLOSE_PAREN_ASTERISK: - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - return XML_ROLE_GROUP_CLOSE_REP; - case XML_TOK_OR: - state->handler = element4; - return XML_ROLE_ELEMENT_NONE; - } - return common(state, tok); -} - -static int PTRCALL -element6(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_OPEN_PAREN: - state->level += 1; - return XML_ROLE_GROUP_OPEN; - case XML_TOK_NAME: - case XML_TOK_PREFIXED_NAME: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT; - case XML_TOK_NAME_QUESTION: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_OPT; - case XML_TOK_NAME_ASTERISK: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_REP; - case XML_TOK_NAME_PLUS: - state->handler = element7; - return XML_ROLE_CONTENT_ELEMENT_PLUS; - } - return common(state, tok); -} - -static int PTRCALL -element7(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_ELEMENT_NONE; - case XML_TOK_CLOSE_PAREN: - state->level -= 1; - if (state->level == 0) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - } - return XML_ROLE_GROUP_CLOSE; - case XML_TOK_CLOSE_PAREN_ASTERISK: - state->level -= 1; - if (state->level == 0) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - } - return XML_ROLE_GROUP_CLOSE_REP; - case XML_TOK_CLOSE_PAREN_QUESTION: - state->level -= 1; - if (state->level == 0) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - } - return XML_ROLE_GROUP_CLOSE_OPT; - case XML_TOK_CLOSE_PAREN_PLUS: - state->level -= 1; - if (state->level == 0) { - state->handler = declClose; - state->role_none = XML_ROLE_ELEMENT_NONE; - } - return XML_ROLE_GROUP_CLOSE_PLUS; - case XML_TOK_COMMA: - state->handler = element6; - return XML_ROLE_GROUP_SEQUENCE; - case XML_TOK_OR: - state->handler = element6; - return XML_ROLE_GROUP_CHOICE; - } - return common(state, tok); -} - -#ifdef XML_DTD - -static int PTRCALL -condSect0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_NAME: - if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { - state->handler = condSect1; - return XML_ROLE_NONE; - } - if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) { - state->handler = condSect2; - return XML_ROLE_NONE; - } - break; - } - return common(state, tok); -} - -static int PTRCALL -condSect1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_OPEN_BRACKET: - state->handler = externalSubset1; - state->includeLevel += 1; - return XML_ROLE_NONE; - } - return common(state, tok); -} - -static int PTRCALL -condSect2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return XML_ROLE_NONE; - case XML_TOK_OPEN_BRACKET: - state->handler = externalSubset1; - return XML_ROLE_IGNORE_SECT; - } - return common(state, tok); -} - -#endif /* XML_DTD */ - -static int PTRCALL -declClose(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - switch (tok) { - case XML_TOK_PROLOG_S: - return state->role_none; - case XML_TOK_DECL_CLOSE: - setTopLevel(state); - return state->role_none; - } - return common(state, tok); -} - -static int PTRCALL -error(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ - return XML_ROLE_NONE; -} - -static int FASTCALL -common(PROLOG_STATE *state, int tok) -{ -#ifdef XML_DTD - if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) - return XML_ROLE_INNER_PARAM_ENTITY_REF; -#endif - state->handler = error; - return XML_ROLE_ERROR; -} - -void -XmlPrologStateInit(PROLOG_STATE *state) -{ - state->handler = prolog0; -#ifdef XML_DTD - state->documentEntity = 1; - state->includeLevel = 0; - state->inEntityValue = 0; -#endif /* XML_DTD */ -} - -#ifdef XML_DTD - -void -XmlPrologStateInitExternalEntity(PROLOG_STATE *state) -{ - state->handler = externalSubset0; - state->documentEntity = 0; - state->includeLevel = 0; -} - -#endif /* XML_DTD */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos4__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#else +#ifdef HAVE_EXPAT_CONFIG_H +#include "expat_config.h" +#endif +#endif /* ndef COMPILED_FROM_DSP */ + +#include "Poco/XML/expat_external.h" +#include "internal.h" +#include "xmlrole.h" +#include "ascii.h" + +/* Doesn't check: + + that ,| are not mixed in a model group + content of literals + +*/ + +static const char KW_ANY[] = { + ASCII_A, ASCII_N, ASCII_Y, '\0' }; +static const char KW_ATTLIST[] = { + ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; +static const char KW_CDATA[] = { + ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_DOCTYPE[] = { + ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; +static const char KW_ELEMENT[] = { + ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; +static const char KW_EMPTY[] = { + ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; +static const char KW_ENTITIES[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, + '\0' }; +static const char KW_ENTITY[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; +static const char KW_FIXED[] = { + ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; +static const char KW_ID[] = { + ASCII_I, ASCII_D, '\0' }; +static const char KW_IDREF[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; +static const char KW_IDREFS[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; +#ifdef XML_DTD +static const char KW_IGNORE[] = { + ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; +#endif +static const char KW_IMPLIED[] = { + ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; +#ifdef XML_DTD +static const char KW_INCLUDE[] = { + ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; +#endif +static const char KW_NDATA[] = { + ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_NMTOKEN[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; +static const char KW_NMTOKENS[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, + '\0' }; +static const char KW_NOTATION[] = + { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, + '\0' }; +static const char KW_PCDATA[] = { + ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_PUBLIC[] = { + ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; +static const char KW_REQUIRED[] = { + ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, + '\0' }; +static const char KW_SYSTEM[] = { + ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; + +#ifndef MIN_BYTES_PER_CHAR +#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) +#endif + +#ifdef XML_DTD +#define setTopLevel(state) \ + ((state)->handler = ((state)->documentEntity \ + ? internalSubset \ + : externalSubset1)) +#else /* not XML_DTD */ +#define setTopLevel(state) ((state)->handler = internalSubset) +#endif /* not XML_DTD */ + +typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + +static PROLOG_HANDLER + prolog0, prolog1, prolog2, + doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, + internalSubset, + entity0, entity1, entity2, entity3, entity4, entity5, entity6, + entity7, entity8, entity9, entity10, + notation0, notation1, notation2, notation3, notation4, + attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, + attlist7, attlist8, attlist9, + element0, element1, element2, element3, element4, element5, element6, + element7, +#ifdef XML_DTD + externalSubset0, externalSubset1, + condSect0, condSect1, condSect2, +#endif /* XML_DTD */ + declClose, + error; + +static int FASTCALL common(PROLOG_STATE *state, int tok); + +static int PTRCALL +prolog0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + state->handler = prolog1; + return XML_ROLE_NONE; + case XML_TOK_XML_DECL: + state->handler = prolog1; + return XML_ROLE_XML_DECL; + case XML_TOK_PI: + state->handler = prolog1; + return XML_ROLE_PI; + case XML_TOK_COMMENT: + state->handler = prolog1; + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +doctype0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = doctype1; + return XML_ROLE_DOCTYPE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +doctype1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = doctype3; + return XML_ROLE_DOCTYPE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = doctype2; + return XML_ROLE_DOCTYPE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +doctype2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype3; + return XML_ROLE_DOCTYPE_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype4; + return XML_ROLE_DOCTYPE_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +doctype5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +internalSubset(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ENTITY)) { + state->handler = entity0; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ATTLIST)) { + state->handler = attlist0; + return XML_ROLE_ATTLIST_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ELEMENT)) { + state->handler = element0; + return XML_ROLE_ELEMENT_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_NOTATION)) { + state->handler = notation0; + return XML_ROLE_NOTATION_NONE; + } + break; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_PARAM_ENTITY_REF: + return XML_ROLE_PARAM_ENTITY_REF; + case XML_TOK_CLOSE_BRACKET: + state->handler = doctype5; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NONE: + return XML_ROLE_NONE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +externalSubset0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + state->handler = externalSubset1; + if (tok == XML_TOK_XML_DECL) + return XML_ROLE_TEXT_DECL; + return externalSubset1(state, tok, ptr, end, enc); +} + +static int PTRCALL +externalSubset1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_COND_SECT_OPEN: + state->handler = condSect0; + return XML_ROLE_NONE; + case XML_TOK_COND_SECT_CLOSE: + if (state->includeLevel == 0) + break; + state->includeLevel -= 1; + return XML_ROLE_NONE; + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_CLOSE_BRACKET: + break; + case XML_TOK_NONE: + if (state->includeLevel) + break; + return XML_ROLE_NONE; + default: + return internalSubset(state, tok, ptr, end, enc); + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +entity0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_PERCENT: + state->handler = entity1; + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity2; + return XML_ROLE_GENERAL_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity7; + return XML_ROLE_PARAM_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity4; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity3; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity4; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity5; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) { + state->handler = entity6; + return XML_ROLE_ENTITY_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +entity6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity9; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity8; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity9; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity10; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity10(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + } + return common(state, tok); +} + +static int PTRCALL +notation0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + state->handler = notation1; + return XML_ROLE_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +notation1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = notation3; + return XML_ROLE_NOTATION_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = notation2; + return XML_ROLE_NOTATION_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +notation2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = notation4; + return XML_ROLE_NOTATION_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_NOTATION_NO_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +attlist0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist1; + return XML_ROLE_ATTLIST_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist2; + return XML_ROLE_ATTRIBUTE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + { + static const char * const types[] = { + KW_CDATA, + KW_ID, + KW_IDREF, + KW_IDREFS, + KW_ENTITY, + KW_ENTITIES, + KW_NMTOKEN, + KW_NMTOKENS, + }; + int i; + for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) + if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { + state->handler = attlist8; + return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; + } + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { + state->handler = attlist5; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NMTOKEN: + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist4; + return XML_ROLE_ATTRIBUTE_ENUM_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OPEN_PAREN: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + state->handler = attlist7; + return XML_ROLE_ATTRIBUTE_NOTATION_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +/* default value */ +static int PTRCALL +attlist8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_IMPLIED)) { + state->handler = attlist1; + return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_REQUIRED)) { + state->handler = attlist1; + return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_FIXED)) { + state->handler = attlist9; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_FIXED_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +element0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element1; + return XML_ROLE_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +element1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_EMPTY; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_ANY; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = element2; + state->level = 1; + return XML_ROLE_GROUP_OPEN; + } + return common(state, tok); +} + +static int PTRCALL +element2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_PCDATA)) { + state->handler = element3; + return XML_ROLE_CONTENT_PCDATA; + } + break; + case XML_TOK_OPEN_PAREN: + state->level = 2; + state->handler = element6; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element5; + return XML_ROLE_CONTENT_ELEMENT; + } + return common(state, tok); +} + +static int PTRCALL +element5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_OPEN_PAREN: + state->level += 1; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_CLOSE_PAREN_QUESTION: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_OPT; + case XML_TOK_CLOSE_PAREN_PLUS: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_PLUS; + case XML_TOK_COMMA: + state->handler = element6; + return XML_ROLE_GROUP_SEQUENCE; + case XML_TOK_OR: + state->handler = element6; + return XML_ROLE_GROUP_CHOICE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +condSect0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { + state->handler = condSect1; + return XML_ROLE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) { + state->handler = condSect2; + return XML_ROLE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +condSect1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + state->includeLevel += 1; + return XML_ROLE_NONE; + } + return common(state, tok); +} + +static int PTRCALL +condSect2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + return XML_ROLE_IGNORE_SECT; + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +declClose(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return state->role_none; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return state->role_none; + } + return common(state, tok); +} + +static int PTRCALL +error(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + return XML_ROLE_NONE; +} + +static int FASTCALL +common(PROLOG_STATE *state, int tok) +{ +#ifdef XML_DTD + if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) + return XML_ROLE_INNER_PARAM_ENTITY_REF; +#endif + state->handler = error; + return XML_ROLE_ERROR; +} + +void +XmlPrologStateInit(PROLOG_STATE *state) +{ + state->handler = prolog0; +#ifdef XML_DTD + state->documentEntity = 1; + state->includeLevel = 0; + state->inEntityValue = 0; +#endif /* XML_DTD */ +} + +#ifdef XML_DTD + +void +XmlPrologStateInitExternalEntity(PROLOG_STATE *state) +{ + state->handler = externalSubset0; + state->documentEntity = 0; + state->includeLevel = 0; +} + +#endif /* XML_DTD */ diff --git a/XML/src/xmlrole.h b/XML/src/xmlrole.h index 25be6b02e..4dd9f06f9 100644 --- a/XML/src/xmlrole.h +++ b/XML/src/xmlrole.h @@ -1,114 +1,114 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#ifndef XmlRole_INCLUDED -#define XmlRole_INCLUDED 1 - -#ifdef __VMS -/* 0 1 2 3 0 1 2 3 - 1234567890123456789012345678901 1234567890123456789012345678901 */ -#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt -#endif - -#include "xmltok.h" - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - XML_ROLE_ERROR = -1, - XML_ROLE_NONE = 0, - XML_ROLE_XML_DECL, - XML_ROLE_INSTANCE_START, - XML_ROLE_DOCTYPE_NONE, - XML_ROLE_DOCTYPE_NAME, - XML_ROLE_DOCTYPE_SYSTEM_ID, - XML_ROLE_DOCTYPE_PUBLIC_ID, - XML_ROLE_DOCTYPE_INTERNAL_SUBSET, - XML_ROLE_DOCTYPE_CLOSE, - XML_ROLE_GENERAL_ENTITY_NAME, - XML_ROLE_PARAM_ENTITY_NAME, - XML_ROLE_ENTITY_NONE, - XML_ROLE_ENTITY_VALUE, - XML_ROLE_ENTITY_SYSTEM_ID, - XML_ROLE_ENTITY_PUBLIC_ID, - XML_ROLE_ENTITY_COMPLETE, - XML_ROLE_ENTITY_NOTATION_NAME, - XML_ROLE_NOTATION_NONE, - XML_ROLE_NOTATION_NAME, - XML_ROLE_NOTATION_SYSTEM_ID, - XML_ROLE_NOTATION_NO_SYSTEM_ID, - XML_ROLE_NOTATION_PUBLIC_ID, - XML_ROLE_ATTRIBUTE_NAME, - XML_ROLE_ATTRIBUTE_TYPE_CDATA, - XML_ROLE_ATTRIBUTE_TYPE_ID, - XML_ROLE_ATTRIBUTE_TYPE_IDREF, - XML_ROLE_ATTRIBUTE_TYPE_IDREFS, - XML_ROLE_ATTRIBUTE_TYPE_ENTITY, - XML_ROLE_ATTRIBUTE_TYPE_ENTITIES, - XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN, - XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS, - XML_ROLE_ATTRIBUTE_ENUM_VALUE, - XML_ROLE_ATTRIBUTE_NOTATION_VALUE, - XML_ROLE_ATTLIST_NONE, - XML_ROLE_ATTLIST_ELEMENT_NAME, - XML_ROLE_IMPLIED_ATTRIBUTE_VALUE, - XML_ROLE_REQUIRED_ATTRIBUTE_VALUE, - XML_ROLE_DEFAULT_ATTRIBUTE_VALUE, - XML_ROLE_FIXED_ATTRIBUTE_VALUE, - XML_ROLE_ELEMENT_NONE, - XML_ROLE_ELEMENT_NAME, - XML_ROLE_CONTENT_ANY, - XML_ROLE_CONTENT_EMPTY, - XML_ROLE_CONTENT_PCDATA, - XML_ROLE_GROUP_OPEN, - XML_ROLE_GROUP_CLOSE, - XML_ROLE_GROUP_CLOSE_REP, - XML_ROLE_GROUP_CLOSE_OPT, - XML_ROLE_GROUP_CLOSE_PLUS, - XML_ROLE_GROUP_CHOICE, - XML_ROLE_GROUP_SEQUENCE, - XML_ROLE_CONTENT_ELEMENT, - XML_ROLE_CONTENT_ELEMENT_REP, - XML_ROLE_CONTENT_ELEMENT_OPT, - XML_ROLE_CONTENT_ELEMENT_PLUS, - XML_ROLE_PI, - XML_ROLE_COMMENT, -#ifdef XML_DTD - XML_ROLE_TEXT_DECL, - XML_ROLE_IGNORE_SECT, - XML_ROLE_INNER_PARAM_ENTITY_REF, -#endif /* XML_DTD */ - XML_ROLE_PARAM_ENTITY_REF -}; - -typedef struct prolog_state { - int (PTRCALL *handler) (struct prolog_state *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc); - unsigned level; - int role_none; -#ifdef XML_DTD - unsigned includeLevel; - int documentEntity; - int inEntityValue; -#endif /* XML_DTD */ -} PROLOG_STATE; - -void XmlPrologStateInit(PROLOG_STATE *); -#ifdef XML_DTD -void XmlPrologStateInitExternalEntity(PROLOG_STATE *); -#endif /* XML_DTD */ - -#define XmlTokenRole(state, tok, ptr, end, enc) \ - (((state)->handler)(state, tok, ptr, end, enc)) - -#ifdef __cplusplus -} -#endif - -#endif /* not XmlRole_INCLUDED */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlRole_INCLUDED +#define XmlRole_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt +#endif + +#include "xmltok.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + XML_ROLE_ERROR = -1, + XML_ROLE_NONE = 0, + XML_ROLE_XML_DECL, + XML_ROLE_INSTANCE_START, + XML_ROLE_DOCTYPE_NONE, + XML_ROLE_DOCTYPE_NAME, + XML_ROLE_DOCTYPE_SYSTEM_ID, + XML_ROLE_DOCTYPE_PUBLIC_ID, + XML_ROLE_DOCTYPE_INTERNAL_SUBSET, + XML_ROLE_DOCTYPE_CLOSE, + XML_ROLE_GENERAL_ENTITY_NAME, + XML_ROLE_PARAM_ENTITY_NAME, + XML_ROLE_ENTITY_NONE, + XML_ROLE_ENTITY_VALUE, + XML_ROLE_ENTITY_SYSTEM_ID, + XML_ROLE_ENTITY_PUBLIC_ID, + XML_ROLE_ENTITY_COMPLETE, + XML_ROLE_ENTITY_NOTATION_NAME, + XML_ROLE_NOTATION_NONE, + XML_ROLE_NOTATION_NAME, + XML_ROLE_NOTATION_SYSTEM_ID, + XML_ROLE_NOTATION_NO_SYSTEM_ID, + XML_ROLE_NOTATION_PUBLIC_ID, + XML_ROLE_ATTRIBUTE_NAME, + XML_ROLE_ATTRIBUTE_TYPE_CDATA, + XML_ROLE_ATTRIBUTE_TYPE_ID, + XML_ROLE_ATTRIBUTE_TYPE_IDREF, + XML_ROLE_ATTRIBUTE_TYPE_IDREFS, + XML_ROLE_ATTRIBUTE_TYPE_ENTITY, + XML_ROLE_ATTRIBUTE_TYPE_ENTITIES, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS, + XML_ROLE_ATTRIBUTE_ENUM_VALUE, + XML_ROLE_ATTRIBUTE_NOTATION_VALUE, + XML_ROLE_ATTLIST_NONE, + XML_ROLE_ATTLIST_ELEMENT_NAME, + XML_ROLE_IMPLIED_ATTRIBUTE_VALUE, + XML_ROLE_REQUIRED_ATTRIBUTE_VALUE, + XML_ROLE_DEFAULT_ATTRIBUTE_VALUE, + XML_ROLE_FIXED_ATTRIBUTE_VALUE, + XML_ROLE_ELEMENT_NONE, + XML_ROLE_ELEMENT_NAME, + XML_ROLE_CONTENT_ANY, + XML_ROLE_CONTENT_EMPTY, + XML_ROLE_CONTENT_PCDATA, + XML_ROLE_GROUP_OPEN, + XML_ROLE_GROUP_CLOSE, + XML_ROLE_GROUP_CLOSE_REP, + XML_ROLE_GROUP_CLOSE_OPT, + XML_ROLE_GROUP_CLOSE_PLUS, + XML_ROLE_GROUP_CHOICE, + XML_ROLE_GROUP_SEQUENCE, + XML_ROLE_CONTENT_ELEMENT, + XML_ROLE_CONTENT_ELEMENT_REP, + XML_ROLE_CONTENT_ELEMENT_OPT, + XML_ROLE_CONTENT_ELEMENT_PLUS, + XML_ROLE_PI, + XML_ROLE_COMMENT, +#ifdef XML_DTD + XML_ROLE_TEXT_DECL, + XML_ROLE_IGNORE_SECT, + XML_ROLE_INNER_PARAM_ENTITY_REF, +#endif /* XML_DTD */ + XML_ROLE_PARAM_ENTITY_REF +}; + +typedef struct prolog_state { + int (PTRCALL *handler) (struct prolog_state *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + unsigned level; + int role_none; +#ifdef XML_DTD + unsigned includeLevel; + int documentEntity; + int inEntityValue; +#endif /* XML_DTD */ +} PROLOG_STATE; + +void XmlPrologStateInit(PROLOG_STATE *); +#ifdef XML_DTD +void XmlPrologStateInitExternalEntity(PROLOG_STATE *); +#endif /* XML_DTD */ + +#define XmlTokenRole(state, tok, ptr, end, enc) \ + (((state)->handler)(state, tok, ptr, end, enc)) + +#ifdef __cplusplus +} +#endif + +#endif /* not XmlRole_INCLUDED */ diff --git a/XML/src/xmltok.c b/XML/src/xmltok.c index debc7162d..44d130903 100644 --- a/XML/src/xmltok.c +++ b/XML/src/xmltok.c @@ -1,1651 +1,1651 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#include - -#ifdef COMPILED_FROM_DSP -#include "winconfig.h" -#elif defined(MACOS_CLASSIC) -#include "macconfig.h" -#elif defined(__amigaos4__) -#include "amigaconfig.h" -#elif defined(__WATCOMC__) -#include "watcomconfig.h" -#else -#ifdef HAVE_EXPAT_CONFIG_H -#include "expat_config.h" -#endif -#endif /* ndef COMPILED_FROM_DSP */ - -#include "Poco/XML/expat_external.h" -#include "internal.h" -#include "xmltok.h" -#include "nametab.h" - -#ifdef XML_DTD -#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) -#else -#define IGNORE_SECTION_TOK_VTABLE /* as nothing */ -#endif - -#define VTABLE1 \ - { PREFIX(prologTok), PREFIX(contentTok), \ - PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \ - { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \ - PREFIX(sameName), \ - PREFIX(nameMatchesAscii), \ - PREFIX(nameLength), \ - PREFIX(skipS), \ - PREFIX(getAtts), \ - PREFIX(charRefNumber), \ - PREFIX(predefinedEntityName), \ - PREFIX(updatePosition), \ - PREFIX(isPublicId) - -#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) - -#define UCS2_GET_NAMING(pages, hi, lo) \ - (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F))) - -/* A 2 byte UTF-8 representation splits the characters 11 bits between - the bottom 5 and 6 bits of the bytes. We need 8 bits to index into - pages, 3 bits to add to that index and 5 bits to generate the mask. -*/ -#define UTF8_GET_NAMING2(pages, byte) \ - (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ - + ((((byte)[0]) & 3) << 1) \ - + ((((byte)[1]) >> 5) & 1)] \ - & (1 << (((byte)[1]) & 0x1F))) - -/* A 3 byte UTF-8 representation splits the characters 16 bits between - the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index - into pages, 3 bits to add to that index and 5 bits to generate the - mask. -*/ -#define UTF8_GET_NAMING3(pages, byte) \ - (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \ - + ((((byte)[1]) >> 2) & 0xF)] \ - << 3) \ - + ((((byte)[1]) & 3) << 1) \ - + ((((byte)[2]) >> 5) & 1)] \ - & (1 << (((byte)[2]) & 0x1F))) - -#define UTF8_GET_NAMING(pages, p, n) \ - ((n) == 2 \ - ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ - : ((n) == 3 \ - ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \ - : 0)) - -/* Detection of invalid UTF-8 sequences is based on Table 3.1B - of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ - with the additional restriction of not allowing the Unicode - code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). - Implementation details: - (A & 0x80) == 0 means A < 0x80 - and - (A & 0xC0) == 0xC0 means A > 0xBF -*/ - -#define UTF8_INVALID2(p) \ - ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0) - -#define UTF8_INVALID3(p) \ - (((p)[2] & 0x80) == 0 \ - || \ - ((*p) == 0xEF && (p)[1] == 0xBF \ - ? \ - (p)[2] > 0xBD \ - : \ - ((p)[2] & 0xC0) == 0xC0) \ - || \ - ((*p) == 0xE0 \ - ? \ - (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ - : \ - ((p)[1] & 0x80) == 0 \ - || \ - ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) - -#define UTF8_INVALID4(p) \ - (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \ - || \ - ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \ - || \ - ((*p) == 0xF0 \ - ? \ - (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ - : \ - ((p)[1] & 0x80) == 0 \ - || \ - ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) - -static int PTRFASTCALL -isNever(const ENCODING *enc, const char *p) -{ - return 0; -} - -static int PTRFASTCALL -utf8_isName2(const ENCODING *enc, const char *p) -{ - return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); -} - -static int PTRFASTCALL -utf8_isName3(const ENCODING *enc, const char *p) -{ - return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); -} - -#define utf8_isName4 isNever - -static int PTRFASTCALL -utf8_isNmstrt2(const ENCODING *enc, const char *p) -{ - return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); -} - -static int PTRFASTCALL -utf8_isNmstrt3(const ENCODING *enc, const char *p) -{ - return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); -} - -#define utf8_isNmstrt4 isNever - -static int PTRFASTCALL -utf8_isInvalid2(const ENCODING *enc, const char *p) -{ - return UTF8_INVALID2((const unsigned char *)p); -} - -static int PTRFASTCALL -utf8_isInvalid3(const ENCODING *enc, const char *p) -{ - return UTF8_INVALID3((const unsigned char *)p); -} - -static int PTRFASTCALL -utf8_isInvalid4(const ENCODING *enc, const char *p) -{ - return UTF8_INVALID4((const unsigned char *)p); -} - -struct normal_encoding { - ENCODING enc; - unsigned char type[256]; -#ifdef XML_MIN_SIZE - int (PTRFASTCALL *byteType)(const ENCODING *, const char *); - int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); - int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); - int (PTRCALL *charMatches)(const ENCODING *, const char *, int); -#endif /* XML_MIN_SIZE */ - int (PTRFASTCALL *isName2)(const ENCODING *, const char *); - int (PTRFASTCALL *isName3)(const ENCODING *, const char *); - int (PTRFASTCALL *isName4)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); -}; - -#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc)) - -#ifdef XML_MIN_SIZE - -#define STANDARD_VTABLE(E) \ - E ## byteType, \ - E ## isNameMin, \ - E ## isNmstrtMin, \ - E ## byteToAscii, \ - E ## charMatches, - -#else - -#define STANDARD_VTABLE(E) /* as nothing */ - -#endif - -#define NORMAL_VTABLE(E) \ - E ## isName2, \ - E ## isName3, \ - E ## isName4, \ - E ## isNmstrt2, \ - E ## isNmstrt3, \ - E ## isNmstrt4, \ - E ## isInvalid2, \ - E ## isInvalid3, \ - E ## isInvalid4 - -static int FASTCALL checkCharRefNumber(int); - -#include "xmltok_impl.h" -#include "ascii.h" - -#ifdef XML_MIN_SIZE -#define sb_isNameMin isNever -#define sb_isNmstrtMin isNever -#endif - -#ifdef XML_MIN_SIZE -#define MINBPC(enc) ((enc)->minBytesPerChar) -#else -/* minimum bytes per character */ -#define MINBPC(enc) 1 -#endif - -#define SB_BYTE_TYPE(enc, p) \ - (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) - -#ifdef XML_MIN_SIZE -static int PTRFASTCALL -sb_byteType(const ENCODING *enc, const char *p) -{ - return SB_BYTE_TYPE(enc, p); -} -#define BYTE_TYPE(enc, p) \ - (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) -#else -#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) -#endif - -#ifdef XML_MIN_SIZE -#define BYTE_TO_ASCII(enc, p) \ - (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) -static int PTRFASTCALL -sb_byteToAscii(const ENCODING *enc, const char *p) -{ - return *p; -} -#else -#define BYTE_TO_ASCII(enc, p) (*(p)) -#endif - -#define IS_NAME_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p)) -#define IS_NMSTRT_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p)) -#define IS_INVALID_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p)) - -#ifdef XML_MIN_SIZE -#define IS_NAME_CHAR_MINBPC(enc, p) \ - (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) \ - (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) -#else -#define IS_NAME_CHAR_MINBPC(enc, p) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) -#endif - -#ifdef XML_MIN_SIZE -#define CHAR_MATCHES(enc, p, c) \ - (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) -static int PTRCALL -sb_charMatches(const ENCODING *enc, const char *p, int c) -{ - return *p == c; -} -#else -/* c is an ASCII character */ -#define CHAR_MATCHES(enc, p, c) (*(p) == c) -#endif - -#define PREFIX(ident) normal_ ## ident -#define XML_TOK_IMPL_C -#include "xmltok_impl.c" -#undef XML_TOK_IMPL_C - -#undef MINBPC -#undef BYTE_TYPE -#undef BYTE_TO_ASCII -#undef CHAR_MATCHES -#undef IS_NAME_CHAR -#undef IS_NAME_CHAR_MINBPC -#undef IS_NMSTRT_CHAR -#undef IS_NMSTRT_CHAR_MINBPC -#undef IS_INVALID_CHAR - -enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ - UTF8_cval1 = 0x00, - UTF8_cval2 = 0xc0, - UTF8_cval3 = 0xe0, - UTF8_cval4 = 0xf0 -}; - -static void PTRCALL -utf8_toUtf8(const ENCODING *enc, - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ - char *to; - const char *from; - if (fromLim - *fromP > toLim - *toP) { - /* Avoid copying partial characters. */ - for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--) - if (((unsigned char)fromLim[-1] & 0xc0) != 0x80) - break; - } - for (to = *toP, from = *fromP; from != fromLim; from++, to++) - *to = *from; - *fromP = from; - *toP = to; -} - -static void PTRCALL -utf8_toUtf16(const ENCODING *enc, - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ - unsigned short *to = *toP; - const char *from = *fromP; - while (from != fromLim && to != toLim) { - switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { - case BT_LEAD2: - *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); - from += 2; - break; - case BT_LEAD3: - *to++ = (unsigned short)(((from[0] & 0xf) << 12) - | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); - from += 3; - break; - case BT_LEAD4: - { - unsigned long n; - if (to + 1 == toLim) - goto after; - n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) - | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); - n -= 0x10000; - to[0] = (unsigned short)((n >> 10) | 0xD800); - to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); - to += 2; - from += 4; - } - break; - default: - *to++ = *from++; - break; - } - } -after: - *fromP = from; - *toP = to; -} - -#ifdef XML_NS -static const struct normal_encoding utf8_encoding_ns = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#include "asciitab.h" -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; -#endif - -static const struct normal_encoding utf8_encoding = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -#ifdef XML_NS - -static const struct normal_encoding internal_utf8_encoding_ns = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#include "iasciitab.h" -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -#endif - -static const struct normal_encoding internal_utf8_encoding = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -static void PTRCALL -latin1_toUtf8(const ENCODING *enc, - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ - for (;;) { - unsigned char c; - if (*fromP == fromLim) - break; - c = (unsigned char)**fromP; - if (c & 0x80) { - if (toLim - *toP < 2) - break; - *(*toP)++ = (char)((c >> 6) | UTF8_cval2); - *(*toP)++ = (char)((c & 0x3f) | 0x80); - (*fromP)++; - } - else { - if (*toP == toLim) - break; - *(*toP)++ = *(*fromP)++; - } - } -} - -static void PTRCALL -latin1_toUtf16(const ENCODING *enc, - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ - while (*fromP != fromLim && *toP != toLim) - *(*toP)++ = (unsigned char)*(*fromP)++; -} - -#ifdef XML_NS - -static const struct normal_encoding latin1_encoding_ns = { - { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(sb_) -}; - -#endif - -static const struct normal_encoding latin1_encoding = { - { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(sb_) -}; - -static void PTRCALL -ascii_toUtf8(const ENCODING *enc, - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ - while (*fromP != fromLim && *toP != toLim) - *(*toP)++ = *(*fromP)++; -} - -#ifdef XML_NS - -static const struct normal_encoding ascii_encoding_ns = { - { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, - { -#include "asciitab.h" -/* BT_NONXML == 0 */ - }, - STANDARD_VTABLE(sb_) -}; - -#endif - -static const struct normal_encoding ascii_encoding = { - { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -/* BT_NONXML == 0 */ - }, - STANDARD_VTABLE(sb_) -}; - -static int PTRFASTCALL -unicode_byte_type(char hi, char lo) -{ - switch ((unsigned char)hi) { - case 0xD8: case 0xD9: case 0xDA: case 0xDB: - return BT_LEAD4; - case 0xDC: case 0xDD: case 0xDE: case 0xDF: - return BT_TRAIL; - case 0xFF: - switch ((unsigned char)lo) { - case 0xFF: - case 0xFE: - return BT_NONXML; - } - break; - } - return BT_NONASCII; -} - -#define DEFINE_UTF16_TO_UTF8(E) \ -static void PTRCALL \ -E ## toUtf8(const ENCODING *enc, \ - const char **fromP, const char *fromLim, \ - char **toP, const char *toLim) \ -{ \ - const char *from; \ - for (from = *fromP; from != fromLim; from += 2) { \ - int plane; \ - unsigned char lo2; \ - unsigned char lo = GET_LO(from); \ - unsigned char hi = GET_HI(from); \ - switch (hi) { \ - case 0: \ - if (lo < 0x80) { \ - if (*toP == toLim) { \ - *fromP = from; \ - return; \ - } \ - *(*toP)++ = lo; \ - break; \ - } \ - /* fall through */ \ - case 0x1: case 0x2: case 0x3: \ - case 0x4: case 0x5: case 0x6: case 0x7: \ - if (toLim - *toP < 2) { \ - *fromP = from; \ - return; \ - } \ - *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ - *(*toP)++ = ((lo & 0x3f) | 0x80); \ - break; \ - default: \ - if (toLim - *toP < 3) { \ - *fromP = from; \ - return; \ - } \ - /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ - *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ - *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ - *(*toP)++ = ((lo & 0x3f) | 0x80); \ - break; \ - case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ - if (toLim - *toP < 4) { \ - *fromP = from; \ - return; \ - } \ - plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ - *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ - *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ - from += 2; \ - lo2 = GET_LO(from); \ - *(*toP)++ = (((lo & 0x3) << 4) \ - | ((GET_HI(from) & 0x3) << 2) \ - | (lo2 >> 6) \ - | 0x80); \ - *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ - break; \ - } \ - } \ - *fromP = from; \ -} - -#define DEFINE_UTF16_TO_UTF16(E) \ -static void PTRCALL \ -E ## toUtf16(const ENCODING *enc, \ - const char **fromP, const char *fromLim, \ - unsigned short **toP, const unsigned short *toLim) \ -{ \ - /* Avoid copying first half only of surrogate */ \ - if (fromLim - *fromP > ((toLim - *toP) << 1) \ - && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \ - fromLim -= 2; \ - for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \ - *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ -} - -#define SET2(ptr, ch) \ - (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8))) -#define GET_LO(ptr) ((unsigned char)(ptr)[0]) -#define GET_HI(ptr) ((unsigned char)(ptr)[1]) - -DEFINE_UTF16_TO_UTF8(little2_) -DEFINE_UTF16_TO_UTF16(little2_) - -#undef SET2 -#undef GET_LO -#undef GET_HI - -#define SET2(ptr, ch) \ - (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF))) -#define GET_LO(ptr) ((unsigned char)(ptr)[1]) -#define GET_HI(ptr) ((unsigned char)(ptr)[0]) - -DEFINE_UTF16_TO_UTF8(big2_) -DEFINE_UTF16_TO_UTF16(big2_) - -#undef SET2 -#undef GET_LO -#undef GET_HI - -#define LITTLE2_BYTE_TYPE(enc, p) \ - ((p)[1] == 0 \ - ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ - : unicode_byte_type((p)[1], (p)[0])) -#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1) -#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c) -#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \ - UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) -#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ - UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0]) - -#ifdef XML_MIN_SIZE - -static int PTRFASTCALL -little2_byteType(const ENCODING *enc, const char *p) -{ - return LITTLE2_BYTE_TYPE(enc, p); -} - -static int PTRFASTCALL -little2_byteToAscii(const ENCODING *enc, const char *p) -{ - return LITTLE2_BYTE_TO_ASCII(enc, p); -} - -static int PTRCALL -little2_charMatches(const ENCODING *enc, const char *p, int c) -{ - return LITTLE2_CHAR_MATCHES(enc, p, c); -} - -static int PTRFASTCALL -little2_isNameMin(const ENCODING *enc, const char *p) -{ - return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p); -} - -static int PTRFASTCALL -little2_isNmstrtMin(const ENCODING *enc, const char *p) -{ - return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p); -} - -#undef VTABLE -#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 - -#else /* not XML_MIN_SIZE */ - -#undef PREFIX -#define PREFIX(ident) little2_ ## ident -#define MINBPC(enc) 2 -/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ -#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) -#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p) -#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c) -#define IS_NAME_CHAR(enc, p, n) 0 -#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) -#define IS_NMSTRT_CHAR(enc, p, n) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) - -#define XML_TOK_IMPL_C -#include "xmltok_impl.c" -#undef XML_TOK_IMPL_C - -#undef MINBPC -#undef BYTE_TYPE -#undef BYTE_TO_ASCII -#undef CHAR_MATCHES -#undef IS_NAME_CHAR -#undef IS_NAME_CHAR_MINBPC -#undef IS_NMSTRT_CHAR -#undef IS_NMSTRT_CHAR_MINBPC -#undef IS_INVALID_CHAR - -#endif /* not XML_MIN_SIZE */ - -#ifdef XML_NS - -static const struct normal_encoding little2_encoding_ns = { - { VTABLE, 2, 0, -#if BYTEORDER == 1234 - 1 -#else - 0 -#endif - }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) -}; - -#endif - -static const struct normal_encoding little2_encoding = { - { VTABLE, 2, 0, -#if BYTEORDER == 1234 - 1 -#else - 0 -#endif - }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) -}; - -#if BYTEORDER != 4321 - -#ifdef XML_NS - -static const struct normal_encoding internal_little2_encoding_ns = { - { VTABLE, 2, 0, 1 }, - { -#include "iasciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) -}; - -#endif - -static const struct normal_encoding internal_little2_encoding = { - { VTABLE, 2, 0, 1 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) -}; - -#endif - - -#define BIG2_BYTE_TYPE(enc, p) \ - ((p)[0] == 0 \ - ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ - : unicode_byte_type((p)[0], (p)[1])) -#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1) -#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c) -#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \ - UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) -#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ - UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1]) - -#ifdef XML_MIN_SIZE - -static int PTRFASTCALL -big2_byteType(const ENCODING *enc, const char *p) -{ - return BIG2_BYTE_TYPE(enc, p); -} - -static int PTRFASTCALL -big2_byteToAscii(const ENCODING *enc, const char *p) -{ - return BIG2_BYTE_TO_ASCII(enc, p); -} - -static int PTRCALL -big2_charMatches(const ENCODING *enc, const char *p, int c) -{ - return BIG2_CHAR_MATCHES(enc, p, c); -} - -static int PTRFASTCALL -big2_isNameMin(const ENCODING *enc, const char *p) -{ - return BIG2_IS_NAME_CHAR_MINBPC(enc, p); -} - -static int PTRFASTCALL -big2_isNmstrtMin(const ENCODING *enc, const char *p) -{ - return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p); -} - -#undef VTABLE -#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 - -#else /* not XML_MIN_SIZE */ - -#undef PREFIX -#define PREFIX(ident) big2_ ## ident -#define MINBPC(enc) 2 -/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ -#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) -#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p) -#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c) -#define IS_NAME_CHAR(enc, p, n) 0 -#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p) -#define IS_NMSTRT_CHAR(enc, p, n) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) - -#define XML_TOK_IMPL_C -#include "xmltok_impl.c" -#undef XML_TOK_IMPL_C - -#undef MINBPC -#undef BYTE_TYPE -#undef BYTE_TO_ASCII -#undef CHAR_MATCHES -#undef IS_NAME_CHAR -#undef IS_NAME_CHAR_MINBPC -#undef IS_NMSTRT_CHAR -#undef IS_NMSTRT_CHAR_MINBPC -#undef IS_INVALID_CHAR - -#endif /* not XML_MIN_SIZE */ - -#ifdef XML_NS - -static const struct normal_encoding big2_encoding_ns = { - { VTABLE, 2, 0, -#if BYTEORDER == 4321 - 1 -#else - 0 -#endif - }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) -}; - -#endif - -static const struct normal_encoding big2_encoding = { - { VTABLE, 2, 0, -#if BYTEORDER == 4321 - 1 -#else - 0 -#endif - }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) -}; - -#if BYTEORDER != 1234 - -#ifdef XML_NS - -static const struct normal_encoding internal_big2_encoding_ns = { - { VTABLE, 2, 0, 1 }, - { -#include "iasciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) -}; - -#endif - -static const struct normal_encoding internal_big2_encoding = { - { VTABLE, 2, 0, 1 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) -}; - -#endif - -#undef PREFIX - -static int FASTCALL -streqci(const char *s1, const char *s2) -{ - for (;;) { - char c1 = *s1++; - char c2 = *s2++; - if (ASCII_a <= c1 && c1 <= ASCII_z) - c1 += ASCII_A - ASCII_a; - if (ASCII_a <= c2 && c2 <= ASCII_z) - c2 += ASCII_A - ASCII_a; - if (c1 != c2) - return 0; - if (!c1) - break; - } - return 1; -} - -static void PTRCALL -initUpdatePosition(const ENCODING *enc, const char *ptr, - const char *end, POSITION *pos) -{ - normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); -} - -static int -toAscii(const ENCODING *enc, const char *ptr, const char *end) -{ - char buf[1]; - char *p = buf; - XmlUtf8Convert(enc, &ptr, end, &p, p + 1); - if (p == buf) - return -1; - else - return buf[0]; -} - -static int FASTCALL -isSpace(int c) -{ - switch (c) { - case 0x20: - case 0xD: - case 0xA: - case 0x9: - return 1; - } - return 0; -} - -/* Return 1 if there's just optional white space or there's an S - followed by name=val. -*/ -static int -parsePseudoAttribute(const ENCODING *enc, - const char *ptr, - const char *end, - const char **namePtr, - const char **nameEndPtr, - const char **valPtr, - const char **nextTokPtr) -{ - int c; - char open; - if (ptr == end) { - *namePtr = NULL; - return 1; - } - if (!isSpace(toAscii(enc, ptr, end))) { - *nextTokPtr = ptr; - return 0; - } - do { - ptr += enc->minBytesPerChar; - } while (isSpace(toAscii(enc, ptr, end))); - if (ptr == end) { - *namePtr = NULL; - return 1; - } - *namePtr = ptr; - for (;;) { - c = toAscii(enc, ptr, end); - if (c == -1) { - *nextTokPtr = ptr; - return 0; - } - if (c == ASCII_EQUALS) { - *nameEndPtr = ptr; - break; - } - if (isSpace(c)) { - *nameEndPtr = ptr; - do { - ptr += enc->minBytesPerChar; - } while (isSpace(c = toAscii(enc, ptr, end))); - if (c != ASCII_EQUALS) { - *nextTokPtr = ptr; - return 0; - } - break; - } - ptr += enc->minBytesPerChar; - } - if (ptr == *namePtr) { - *nextTokPtr = ptr; - return 0; - } - ptr += enc->minBytesPerChar; - c = toAscii(enc, ptr, end); - while (isSpace(c)) { - ptr += enc->minBytesPerChar; - c = toAscii(enc, ptr, end); - } - if (c != ASCII_QUOT && c != ASCII_APOS) { - *nextTokPtr = ptr; - return 0; - } - open = (char)c; - ptr += enc->minBytesPerChar; - *valPtr = ptr; - for (;; ptr += enc->minBytesPerChar) { - c = toAscii(enc, ptr, end); - if (c == open) - break; - if (!(ASCII_a <= c && c <= ASCII_z) - && !(ASCII_A <= c && c <= ASCII_Z) - && !(ASCII_0 <= c && c <= ASCII_9) - && c != ASCII_PERIOD - && c != ASCII_MINUS - && c != ASCII_UNDERSCORE) { - *nextTokPtr = ptr; - return 0; - } - } - *nextTokPtr = ptr + enc->minBytesPerChar; - return 1; -} - -static const char KW_version[] = { - ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0' -}; - -static const char KW_encoding[] = { - ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0' -}; - -static const char KW_standalone[] = { - ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, - ASCII_n, ASCII_e, '\0' -}; - -static const char KW_yes[] = { - ASCII_y, ASCII_e, ASCII_s, '\0' -}; - -static const char KW_no[] = { - ASCII_n, ASCII_o, '\0' -}; - -static int -doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, - const char *, - const char *), - int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingName, - const ENCODING **encoding, - int *standalone) -{ - const char *val = NULL; - const char *name = NULL; - const char *nameEnd = NULL; - ptr += 5 * enc->minBytesPerChar; - end -= 2 * enc->minBytesPerChar; - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) - || !name) { - *badPtr = ptr; - return 0; - } - if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { - if (!isGeneralTextEntity) { - *badPtr = name; - return 0; - } - } - else { - if (versionPtr) - *versionPtr = val; - if (versionEndPtr) - *versionEndPtr = ptr; - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { - *badPtr = ptr; - return 0; - } - if (!name) { - if (isGeneralTextEntity) { - /* a TextDecl must have an EncodingDecl */ - *badPtr = ptr; - return 0; - } - return 1; - } - } - if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) { - int c = toAscii(enc, val, end); - if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) { - *badPtr = val; - return 0; - } - if (encodingName) - *encodingName = val; - if (encoding) - *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar); - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { - *badPtr = ptr; - return 0; - } - if (!name) - return 1; - } - if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) - || isGeneralTextEntity) { - *badPtr = name; - return 0; - } - if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) { - if (standalone) - *standalone = 1; - } - else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { - if (standalone) - *standalone = 0; - } - else { - *badPtr = val; - return 0; - } - while (isSpace(toAscii(enc, ptr, end))) - ptr += enc->minBytesPerChar; - if (ptr != end) { - *badPtr = ptr; - return 0; - } - return 1; -} - -static int FASTCALL -checkCharRefNumber(int result) -{ - switch (result >> 8) { - case 0xD8: case 0xD9: case 0xDA: case 0xDB: - case 0xDC: case 0xDD: case 0xDE: case 0xDF: - return -1; - case 0: - if (latin1_encoding.type[result] == BT_NONXML) - return -1; - break; - case 0xFF: - if (result == 0xFFFE || result == 0xFFFF) - return -1; - break; - } - return result; -} - -int FASTCALL -XmlUtf8Encode(int c, char *buf) -{ - enum { - /* minN is minimum legal resulting value for N byte sequence */ - min2 = 0x80, - min3 = 0x800, - min4 = 0x10000 - }; - - if (c < 0) - return 0; - if (c < min2) { - buf[0] = (char)(c | UTF8_cval1); - return 1; - } - if (c < min3) { - buf[0] = (char)((c >> 6) | UTF8_cval2); - buf[1] = (char)((c & 0x3f) | 0x80); - return 2; - } - if (c < min4) { - buf[0] = (char)((c >> 12) | UTF8_cval3); - buf[1] = (char)(((c >> 6) & 0x3f) | 0x80); - buf[2] = (char)((c & 0x3f) | 0x80); - return 3; - } - if (c < 0x110000) { - buf[0] = (char)((c >> 18) | UTF8_cval4); - buf[1] = (char)(((c >> 12) & 0x3f) | 0x80); - buf[2] = (char)(((c >> 6) & 0x3f) | 0x80); - buf[3] = (char)((c & 0x3f) | 0x80); - return 4; - } - return 0; -} - -int FASTCALL -XmlUtf16Encode(int charNum, unsigned short *buf) -{ - if (charNum < 0) - return 0; - if (charNum < 0x10000) { - buf[0] = (unsigned short)charNum; - return 1; - } - if (charNum < 0x110000) { - charNum -= 0x10000; - buf[0] = (unsigned short)((charNum >> 10) + 0xD800); - buf[1] = (unsigned short)((charNum & 0x3FF) + 0xDC00); - return 2; - } - return 0; -} - -struct unknown_encoding { - struct normal_encoding normal; - CONVERTER convert; - void *userData; - unsigned short utf16[256]; - char utf8[256][4]; -}; - -#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc)) - -int -XmlSizeOfUnknownEncoding(void) -{ - return sizeof(struct unknown_encoding); -} - -static int PTRFASTCALL -unknown_isName(const ENCODING *enc, const char *p) -{ - const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - int c = uenc->convert(uenc->userData, p); - if (c & ~0xFFFF) - return 0; - return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); -} - -static int PTRFASTCALL -unknown_isNmstrt(const ENCODING *enc, const char *p) -{ - const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - int c = uenc->convert(uenc->userData, p); - if (c & ~0xFFFF) - return 0; - return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); -} - -static int PTRFASTCALL -unknown_isInvalid(const ENCODING *enc, const char *p) -{ - const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - int c = uenc->convert(uenc->userData, p); - return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; -} - -static void PTRCALL -unknown_toUtf8(const ENCODING *enc, - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ - const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - char buf[XML_UTF8_ENCODE_MAX]; - for (;;) { - const char *utf8; - int n; - if (*fromP == fromLim) - break; - utf8 = uenc->utf8[(unsigned char)**fromP]; - n = *utf8++; - if (n == 0) { - int c = uenc->convert(uenc->userData, *fromP); - n = XmlUtf8Encode(c, buf); - if (n > toLim - *toP) - break; - utf8 = buf; - *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] - - (BT_LEAD2 - 2)); - } - else { - if (n > toLim - *toP) - break; - (*fromP)++; - } - do { - *(*toP)++ = *utf8++; - } while (--n != 0); - } -} - -static void PTRCALL -unknown_toUtf16(const ENCODING *enc, - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ - const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); - while (*fromP != fromLim && *toP != toLim) { - unsigned short c = uenc->utf16[(unsigned char)**fromP]; - if (c == 0) { - c = (unsigned short) - uenc->convert(uenc->userData, *fromP); - *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] - - (BT_LEAD2 - 2)); - } - else - (*fromP)++; - *(*toP)++ = c; - } -} - -ENCODING * -XmlInitUnknownEncoding(void *mem, - int *table, - CONVERTER convert, - void *userData) -{ - int i; - struct unknown_encoding *e = (struct unknown_encoding *)mem; - for (i = 0; i < (int)sizeof(struct normal_encoding); i++) - ((char *)mem)[i] = ((char *)&latin1_encoding)[i]; - for (i = 0; i < 128; i++) - if (latin1_encoding.type[i] != BT_OTHER - && latin1_encoding.type[i] != BT_NONXML - && table[i] != i) - return 0; - for (i = 0; i < 256; i++) { - int c = table[i]; - if (c == -1) { - e->normal.type[i] = BT_MALFORM; - /* This shouldn't really get used. */ - e->utf16[i] = 0xFFFF; - e->utf8[i][0] = 1; - e->utf8[i][1] = 0; - } - else if (c < 0) { - if (c < -4) - return 0; - e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2)); - e->utf8[i][0] = 0; - e->utf16[i] = 0; - } - else if (c < 0x80) { - if (latin1_encoding.type[c] != BT_OTHER - && latin1_encoding.type[c] != BT_NONXML - && c != i) - return 0; - e->normal.type[i] = latin1_encoding.type[c]; - e->utf8[i][0] = 1; - e->utf8[i][1] = (char)c; - e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c); - } - else if (checkCharRefNumber(c) < 0) { - e->normal.type[i] = BT_NONXML; - /* This shouldn't really get used. */ - e->utf16[i] = 0xFFFF; - e->utf8[i][0] = 1; - e->utf8[i][1] = 0; - } - else { - if (c > 0xFFFF) - return 0; - if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff)) - e->normal.type[i] = BT_NMSTRT; - else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff)) - e->normal.type[i] = BT_NAME; - else - e->normal.type[i] = BT_OTHER; - e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1); - e->utf16[i] = (unsigned short)c; - } - } - e->userData = userData; - e->convert = convert; - if (convert) { - e->normal.isName2 = unknown_isName; - e->normal.isName3 = unknown_isName; - e->normal.isName4 = unknown_isName; - e->normal.isNmstrt2 = unknown_isNmstrt; - e->normal.isNmstrt3 = unknown_isNmstrt; - e->normal.isNmstrt4 = unknown_isNmstrt; - e->normal.isInvalid2 = unknown_isInvalid; - e->normal.isInvalid3 = unknown_isInvalid; - e->normal.isInvalid4 = unknown_isInvalid; - } - e->normal.enc.utf8Convert = unknown_toUtf8; - e->normal.enc.utf16Convert = unknown_toUtf16; - return &(e->normal.enc); -} - -/* If this enumeration is changed, getEncodingIndex and encodings -must also be changed. */ -enum { - UNKNOWN_ENC = -1, - ISO_8859_1_ENC = 0, - US_ASCII_ENC, - UTF_8_ENC, - UTF_16_ENC, - UTF_16BE_ENC, - UTF_16LE_ENC, - /* must match encodingNames up to here */ - NO_ENC -}; - -static const char KW_ISO_8859_1[] = { - ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, - ASCII_MINUS, ASCII_1, '\0' -}; -static const char KW_US_ASCII[] = { - ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, - '\0' -}; -static const char KW_UTF_8[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0' -}; -static const char KW_UTF_16[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0' -}; -static const char KW_UTF_16BE[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, - '\0' -}; -static const char KW_UTF_16LE[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, - '\0' -}; - -static int FASTCALL -getEncodingIndex(const char *name) -{ - static const char * const encodingNames[] = { - KW_ISO_8859_1, - KW_US_ASCII, - KW_UTF_8, - KW_UTF_16, - KW_UTF_16BE, - KW_UTF_16LE, - }; - int i; - if (name == NULL) - return NO_ENC; - for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++) - if (streqci(name, encodingNames[i])) - return i; - return UNKNOWN_ENC; -} - -/* For binary compatibility, we store the index of the encoding - specified at initialization in the isUtf16 member. -*/ - -#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16) -#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i) - -/* This is what detects the encoding. encodingTable maps from - encoding indices to encodings; INIT_ENC_INDEX(enc) is the index of - the external (protocol) specified encoding; state is - XML_CONTENT_STATE if we're parsing an external text entity, and - XML_PROLOG_STATE otherwise. -*/ - - -static int -initScan(const ENCODING * const *encodingTable, - const INIT_ENCODING *enc, - int state, - const char *ptr, - const char *end, - const char **nextTokPtr) -{ - const ENCODING **encPtr; - - if (ptr == end) - return XML_TOK_NONE; - encPtr = enc->encPtr; - if (ptr + 1 == end) { - /* only a single byte available for auto-detection */ -#ifndef XML_DTD /* FIXME */ - /* a well-formed document entity must have more than one byte */ - if (state != XML_CONTENT_STATE) - return XML_TOK_PARTIAL; -#endif - /* so we're parsing an external text entity... */ - /* if UTF-16 was externally specified, then we need at least 2 bytes */ - switch (INIT_ENC_INDEX(enc)) { - case UTF_16_ENC: - case UTF_16LE_ENC: - case UTF_16BE_ENC: - return XML_TOK_PARTIAL; - } - switch ((unsigned char)*ptr) { - case 0xFE: - case 0xFF: - case 0xEF: /* possibly first byte of UTF-8 BOM */ - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) - break; - /* fall through */ - case 0x00: - case 0x3C: - return XML_TOK_PARTIAL; - } - } - else { - switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) { - case 0xFEFF: - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) - break; - *nextTokPtr = ptr + 2; - *encPtr = encodingTable[UTF_16BE_ENC]; - return XML_TOK_BOM; - /* 00 3C is handled in the default case */ - case 0x3C00: - if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC - || INIT_ENC_INDEX(enc) == UTF_16_ENC) - && state == XML_CONTENT_STATE) - break; - *encPtr = encodingTable[UTF_16LE_ENC]; - return XmlTok(*encPtr, state, ptr, end, nextTokPtr); - case 0xFFFE: - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) - break; - *nextTokPtr = ptr + 2; - *encPtr = encodingTable[UTF_16LE_ENC]; - return XML_TOK_BOM; - case 0xEFBB: - /* Maybe a UTF-8 BOM (EF BB BF) */ - /* If there's an explicitly specified (external) encoding - of ISO-8859-1 or some flavour of UTF-16 - and this is an external text entity, - don't look for the BOM, - because it might be a legal data. - */ - if (state == XML_CONTENT_STATE) { - int e = INIT_ENC_INDEX(enc); - if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC - || e == UTF_16LE_ENC || e == UTF_16_ENC) - break; - } - if (ptr + 2 == end) - return XML_TOK_PARTIAL; - if ((unsigned char)ptr[2] == 0xBF) { - *nextTokPtr = ptr + 3; - *encPtr = encodingTable[UTF_8_ENC]; - return XML_TOK_BOM; - } - break; - default: - if (ptr[0] == '\0') { - /* 0 isn't a legal data character. Furthermore a document - entity can only start with ASCII characters. So the only - way this can fail to be big-endian UTF-16 if it it's an - external parsed general entity that's labelled as - UTF-16LE. - */ - if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC) - break; - *encPtr = encodingTable[UTF_16BE_ENC]; - return XmlTok(*encPtr, state, ptr, end, nextTokPtr); - } - else if (ptr[1] == '\0') { - /* We could recover here in the case: - - parsing an external entity - - second byte is 0 - - no externally specified encoding - - no encoding declaration - by assuming UTF-16LE. But we don't, because this would mean when - presented just with a single byte, we couldn't reliably determine - whether we needed further bytes. - */ - if (state == XML_CONTENT_STATE) - break; - *encPtr = encodingTable[UTF_16LE_ENC]; - return XmlTok(*encPtr, state, ptr, end, nextTokPtr); - } - break; - } - } - *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; - return XmlTok(*encPtr, state, ptr, end, nextTokPtr); -} - - -#define NS(x) x -#define ns(x) x -#define XML_TOK_NS_C -#include "xmltok_ns.c" -#undef XML_TOK_NS_C -#undef NS -#undef ns - -#ifdef XML_NS - -#define NS(x) x ## NS -#define ns(x) x ## _ns - -#define XML_TOK_NS_C -#include "xmltok_ns.c" -#undef XML_TOK_NS_C - -#undef NS -#undef ns - -ENCODING * -XmlInitUnknownEncodingNS(void *mem, - int *table, - CONVERTER convert, - void *userData) -{ - ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData); - if (enc) - ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON; - return enc; -} - -#endif /* XML_NS */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include + +#ifdef COMPILED_FROM_DSP +#include "winconfig.h" +#elif defined(MACOS_CLASSIC) +#include "macconfig.h" +#elif defined(__amigaos4__) +#include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" +#else +#ifdef HAVE_EXPAT_CONFIG_H +#include "expat_config.h" +#endif +#endif /* ndef COMPILED_FROM_DSP */ + +#include "Poco/XML/expat_external.h" +#include "internal.h" +#include "xmltok.h" +#include "nametab.h" + +#ifdef XML_DTD +#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) +#else +#define IGNORE_SECTION_TOK_VTABLE /* as nothing */ +#endif + +#define VTABLE1 \ + { PREFIX(prologTok), PREFIX(contentTok), \ + PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \ + { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \ + PREFIX(sameName), \ + PREFIX(nameMatchesAscii), \ + PREFIX(nameLength), \ + PREFIX(skipS), \ + PREFIX(getAtts), \ + PREFIX(charRefNumber), \ + PREFIX(predefinedEntityName), \ + PREFIX(updatePosition), \ + PREFIX(isPublicId) + +#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) + +#define UCS2_GET_NAMING(pages, hi, lo) \ + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F))) + +/* A 2 byte UTF-8 representation splits the characters 11 bits between + the bottom 5 and 6 bits of the bytes. We need 8 bits to index into + pages, 3 bits to add to that index and 5 bits to generate the mask. +*/ +#define UTF8_GET_NAMING2(pages, byte) \ + (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ + + ((((byte)[0]) & 3) << 1) \ + + ((((byte)[1]) >> 5) & 1)] \ + & (1 << (((byte)[1]) & 0x1F))) + +/* A 3 byte UTF-8 representation splits the characters 16 bits between + the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index + into pages, 3 bits to add to that index and 5 bits to generate the + mask. +*/ +#define UTF8_GET_NAMING3(pages, byte) \ + (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \ + + ((((byte)[1]) >> 2) & 0xF)] \ + << 3) \ + + ((((byte)[1]) & 3) << 1) \ + + ((((byte)[2]) >> 5) & 1)] \ + & (1 << (((byte)[2]) & 0x1F))) + +#define UTF8_GET_NAMING(pages, p, n) \ + ((n) == 2 \ + ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ + : ((n) == 3 \ + ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \ + : 0)) + +/* Detection of invalid UTF-8 sequences is based on Table 3.1B + of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ + with the additional restriction of not allowing the Unicode + code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). + Implementation details: + (A & 0x80) == 0 means A < 0x80 + and + (A & 0xC0) == 0xC0 means A > 0xBF +*/ + +#define UTF8_INVALID2(p) \ + ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0) + +#define UTF8_INVALID3(p) \ + (((p)[2] & 0x80) == 0 \ + || \ + ((*p) == 0xEF && (p)[1] == 0xBF \ + ? \ + (p)[2] > 0xBD \ + : \ + ((p)[2] & 0xC0) == 0xC0) \ + || \ + ((*p) == 0xE0 \ + ? \ + (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) + +#define UTF8_INVALID4(p) \ + (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \ + || \ + ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \ + || \ + ((*p) == 0xF0 \ + ? \ + (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) + +static int PTRFASTCALL +isNever(const ENCODING *enc, const char *p) +{ + return 0; +} + +static int PTRFASTCALL +utf8_isName2(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isName3(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); +} + +#define utf8_isName4 isNever + +static int PTRFASTCALL +utf8_isNmstrt2(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isNmstrt3(const ENCODING *enc, const char *p) +{ + return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); +} + +#define utf8_isNmstrt4 isNever + +static int PTRFASTCALL +utf8_isInvalid2(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID2((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid3(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID3((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid4(const ENCODING *enc, const char *p) +{ + return UTF8_INVALID4((const unsigned char *)p); +} + +struct normal_encoding { + ENCODING enc; + unsigned char type[256]; +#ifdef XML_MIN_SIZE + int (PTRFASTCALL *byteType)(const ENCODING *, const char *); + int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); + int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); + int (PTRCALL *charMatches)(const ENCODING *, const char *, int); +#endif /* XML_MIN_SIZE */ + int (PTRFASTCALL *isName2)(const ENCODING *, const char *); + int (PTRFASTCALL *isName3)(const ENCODING *, const char *); + int (PTRFASTCALL *isName4)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); +}; + +#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc)) + +#ifdef XML_MIN_SIZE + +#define STANDARD_VTABLE(E) \ + E ## byteType, \ + E ## isNameMin, \ + E ## isNmstrtMin, \ + E ## byteToAscii, \ + E ## charMatches, + +#else + +#define STANDARD_VTABLE(E) /* as nothing */ + +#endif + +#define NORMAL_VTABLE(E) \ + E ## isName2, \ + E ## isName3, \ + E ## isName4, \ + E ## isNmstrt2, \ + E ## isNmstrt3, \ + E ## isNmstrt4, \ + E ## isInvalid2, \ + E ## isInvalid3, \ + E ## isInvalid4 + +static int FASTCALL checkCharRefNumber(int); + +#include "xmltok_impl.h" +#include "ascii.h" + +#ifdef XML_MIN_SIZE +#define sb_isNameMin isNever +#define sb_isNmstrtMin isNever +#endif + +#ifdef XML_MIN_SIZE +#define MINBPC(enc) ((enc)->minBytesPerChar) +#else +/* minimum bytes per character */ +#define MINBPC(enc) 1 +#endif + +#define SB_BYTE_TYPE(enc, p) \ + (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) + +#ifdef XML_MIN_SIZE +static int PTRFASTCALL +sb_byteType(const ENCODING *enc, const char *p) +{ + return SB_BYTE_TYPE(enc, p); +} +#define BYTE_TYPE(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) +#else +#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) +#endif + +#ifdef XML_MIN_SIZE +#define BYTE_TO_ASCII(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) +static int PTRFASTCALL +sb_byteToAscii(const ENCODING *enc, const char *p) +{ + return *p; +} +#else +#define BYTE_TO_ASCII(enc, p) (*(p)) +#endif + +#define IS_NAME_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p)) +#define IS_NMSTRT_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p)) +#define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p)) + +#ifdef XML_MIN_SIZE +#define IS_NAME_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) +#else +#define IS_NAME_CHAR_MINBPC(enc, p) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) +#endif + +#ifdef XML_MIN_SIZE +#define CHAR_MATCHES(enc, p, c) \ + (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) +static int PTRCALL +sb_charMatches(const ENCODING *enc, const char *p, int c) +{ + return *p == c; +} +#else +/* c is an ASCII character */ +#define CHAR_MATCHES(enc, p, c) (*(p) == c) +#endif + +#define PREFIX(ident) normal_ ## ident +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ + UTF8_cval1 = 0x00, + UTF8_cval2 = 0xc0, + UTF8_cval3 = 0xe0, + UTF8_cval4 = 0xf0 +}; + +static void PTRCALL +utf8_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + char *to; + const char *from; + if (fromLim - *fromP > toLim - *toP) { + /* Avoid copying partial characters. */ + for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--) + if (((unsigned char)fromLim[-1] & 0xc0) != 0x80) + break; + } + for (to = *toP, from = *fromP; from != fromLim; from++, to++) + *to = *from; + *fromP = from; + *toP = to; +} + +static void PTRCALL +utf8_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + unsigned short *to = *toP; + const char *from = *fromP; + while (from != fromLim && to != toLim) { + switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { + case BT_LEAD2: + *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); + from += 2; + break; + case BT_LEAD3: + *to++ = (unsigned short)(((from[0] & 0xf) << 12) + | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); + from += 3; + break; + case BT_LEAD4: + { + unsigned long n; + if (to + 1 == toLim) + goto after; + n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) + | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); + n -= 0x10000; + to[0] = (unsigned short)((n >> 10) | 0xD800); + to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); + to += 2; + from += 4; + } + break; + default: + *to++ = *from++; + break; + } + } +after: + *fromP = from; + *toP = to; +} + +#ifdef XML_NS +static const struct normal_encoding utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; +#endif + +static const struct normal_encoding utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#ifdef XML_NS + +static const struct normal_encoding internal_utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "iasciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#endif + +static const struct normal_encoding internal_utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +static void PTRCALL +latin1_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + for (;;) { + unsigned char c; + if (*fromP == fromLim) + break; + c = (unsigned char)**fromP; + if (c & 0x80) { + if (toLim - *toP < 2) + break; + *(*toP)++ = (char)((c >> 6) | UTF8_cval2); + *(*toP)++ = (char)((c & 0x3f) | 0x80); + (*fromP)++; + } + else { + if (*toP == toLim) + break; + *(*toP)++ = *(*fromP)++; + } + } +} + +static void PTRCALL +latin1_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = (unsigned char)*(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding latin1_encoding_ns = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) +}; + +#endif + +static const struct normal_encoding latin1_encoding = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) +}; + +static void PTRCALL +ascii_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = *(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding ascii_encoding_ns = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) +}; + +#endif + +static const struct normal_encoding ascii_encoding = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) +}; + +static int PTRFASTCALL +unicode_byte_type(char hi, char lo) +{ + switch ((unsigned char)hi) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + return BT_LEAD4; + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return BT_TRAIL; + case 0xFF: + switch ((unsigned char)lo) { + case 0xFF: + case 0xFE: + return BT_NONXML; + } + break; + } + return BT_NONASCII; +} + +#define DEFINE_UTF16_TO_UTF8(E) \ +static void PTRCALL \ +E ## toUtf8(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + char **toP, const char *toLim) \ +{ \ + const char *from; \ + for (from = *fromP; from != fromLim; from += 2) { \ + int plane; \ + unsigned char lo2; \ + unsigned char lo = GET_LO(from); \ + unsigned char hi = GET_HI(from); \ + switch (hi) { \ + case 0: \ + if (lo < 0x80) { \ + if (*toP == toLim) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = lo; \ + break; \ + } \ + /* fall through */ \ + case 0x1: case 0x2: case 0x3: \ + case 0x4: case 0x5: case 0x6: case 0x7: \ + if (toLim - *toP < 2) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + default: \ + if (toLim - *toP < 3) { \ + *fromP = from; \ + return; \ + } \ + /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ + *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ + *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ + if (toLim - *toP < 4) { \ + *fromP = from; \ + return; \ + } \ + plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ + *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ + *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ + from += 2; \ + lo2 = GET_LO(from); \ + *(*toP)++ = (((lo & 0x3) << 4) \ + | ((GET_HI(from) & 0x3) << 2) \ + | (lo2 >> 6) \ + | 0x80); \ + *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ + break; \ + } \ + } \ + *fromP = from; \ +} + +#define DEFINE_UTF16_TO_UTF16(E) \ +static void PTRCALL \ +E ## toUtf16(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + unsigned short **toP, const unsigned short *toLim) \ +{ \ + /* Avoid copying first half only of surrogate */ \ + if (fromLim - *fromP > ((toLim - *toP) << 1) \ + && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \ + fromLim -= 2; \ + for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \ + *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ +} + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8))) +#define GET_LO(ptr) ((unsigned char)(ptr)[0]) +#define GET_HI(ptr) ((unsigned char)(ptr)[1]) + +DEFINE_UTF16_TO_UTF8(little2_) +DEFINE_UTF16_TO_UTF16(little2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF))) +#define GET_LO(ptr) ((unsigned char)(ptr)[1]) +#define GET_HI(ptr) ((unsigned char)(ptr)[0]) + +DEFINE_UTF16_TO_UTF8(big2_) +DEFINE_UTF16_TO_UTF16(big2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define LITTLE2_BYTE_TYPE(enc, p) \ + ((p)[1] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ + : unicode_byte_type((p)[1], (p)[0])) +#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1) +#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c) +#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) +#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +little2_byteType(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +little2_byteToAscii(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +little2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return LITTLE2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +little2_isNameMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +little2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) little2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding little2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + +static const struct normal_encoding little2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#if BYTEORDER != 4321 + +#ifdef XML_NS + +static const struct normal_encoding internal_little2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + +static const struct normal_encoding internal_little2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) +}; + +#endif + + +#define BIG2_BYTE_TYPE(enc, p) \ + ((p)[0] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ + : unicode_byte_type((p)[0], (p)[1])) +#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1) +#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c) +#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) +#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +big2_byteType(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +big2_byteToAscii(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +big2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return BIG2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +big2_isNameMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +big2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) big2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#define XML_TOK_IMPL_C +#include "xmltok_impl.c" +#undef XML_TOK_IMPL_C + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding big2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +static const struct normal_encoding big2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#if BYTEORDER != 1234 + +#ifdef XML_NS + +static const struct normal_encoding internal_big2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +static const struct normal_encoding internal_big2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) +}; + +#endif + +#undef PREFIX + +static int FASTCALL +streqci(const char *s1, const char *s2) +{ + for (;;) { + char c1 = *s1++; + char c2 = *s2++; + if (ASCII_a <= c1 && c1 <= ASCII_z) + c1 += ASCII_A - ASCII_a; + if (ASCII_a <= c2 && c2 <= ASCII_z) + c2 += ASCII_A - ASCII_a; + if (c1 != c2) + return 0; + if (!c1) + break; + } + return 1; +} + +static void PTRCALL +initUpdatePosition(const ENCODING *enc, const char *ptr, + const char *end, POSITION *pos) +{ + normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); +} + +static int +toAscii(const ENCODING *enc, const char *ptr, const char *end) +{ + char buf[1]; + char *p = buf; + XmlUtf8Convert(enc, &ptr, end, &p, p + 1); + if (p == buf) + return -1; + else + return buf[0]; +} + +static int FASTCALL +isSpace(int c) +{ + switch (c) { + case 0x20: + case 0xD: + case 0xA: + case 0x9: + return 1; + } + return 0; +} + +/* Return 1 if there's just optional white space or there's an S + followed by name=val. +*/ +static int +parsePseudoAttribute(const ENCODING *enc, + const char *ptr, + const char *end, + const char **namePtr, + const char **nameEndPtr, + const char **valPtr, + const char **nextTokPtr) +{ + int c; + char open; + if (ptr == end) { + *namePtr = NULL; + return 1; + } + if (!isSpace(toAscii(enc, ptr, end))) { + *nextTokPtr = ptr; + return 0; + } + do { + ptr += enc->minBytesPerChar; + } while (isSpace(toAscii(enc, ptr, end))); + if (ptr == end) { + *namePtr = NULL; + return 1; + } + *namePtr = ptr; + for (;;) { + c = toAscii(enc, ptr, end); + if (c == -1) { + *nextTokPtr = ptr; + return 0; + } + if (c == ASCII_EQUALS) { + *nameEndPtr = ptr; + break; + } + if (isSpace(c)) { + *nameEndPtr = ptr; + do { + ptr += enc->minBytesPerChar; + } while (isSpace(c = toAscii(enc, ptr, end))); + if (c != ASCII_EQUALS) { + *nextTokPtr = ptr; + return 0; + } + break; + } + ptr += enc->minBytesPerChar; + } + if (ptr == *namePtr) { + *nextTokPtr = ptr; + return 0; + } + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + while (isSpace(c)) { + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + } + if (c != ASCII_QUOT && c != ASCII_APOS) { + *nextTokPtr = ptr; + return 0; + } + open = (char)c; + ptr += enc->minBytesPerChar; + *valPtr = ptr; + for (;; ptr += enc->minBytesPerChar) { + c = toAscii(enc, ptr, end); + if (c == open) + break; + if (!(ASCII_a <= c && c <= ASCII_z) + && !(ASCII_A <= c && c <= ASCII_Z) + && !(ASCII_0 <= c && c <= ASCII_9) + && c != ASCII_PERIOD + && c != ASCII_MINUS + && c != ASCII_UNDERSCORE) { + *nextTokPtr = ptr; + return 0; + } + } + *nextTokPtr = ptr + enc->minBytesPerChar; + return 1; +} + +static const char KW_version[] = { + ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0' +}; + +static const char KW_encoding[] = { + ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0' +}; + +static const char KW_standalone[] = { + ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, + ASCII_n, ASCII_e, '\0' +}; + +static const char KW_yes[] = { + ASCII_y, ASCII_e, ASCII_s, '\0' +}; + +static const char KW_no[] = { + ASCII_n, ASCII_o, '\0' +}; + +static int +doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, + const char *, + const char *), + int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + const char *val = NULL; + const char *name = NULL; + const char *nameEnd = NULL; + ptr += 5 * enc->minBytesPerChar; + end -= 2 * enc->minBytesPerChar; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) + || !name) { + *badPtr = ptr; + return 0; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { + if (!isGeneralTextEntity) { + *badPtr = name; + return 0; + } + } + else { + if (versionPtr) + *versionPtr = val; + if (versionEndPtr) + *versionEndPtr = ptr; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) { + if (isGeneralTextEntity) { + /* a TextDecl must have an EncodingDecl */ + *badPtr = ptr; + return 0; + } + return 1; + } + } + if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) { + int c = toAscii(enc, val, end); + if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) { + *badPtr = val; + return 0; + } + if (encodingName) + *encodingName = val; + if (encoding) + *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar); + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) + return 1; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) + || isGeneralTextEntity) { + *badPtr = name; + return 0; + } + if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) { + if (standalone) + *standalone = 1; + } + else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { + if (standalone) + *standalone = 0; + } + else { + *badPtr = val; + return 0; + } + while (isSpace(toAscii(enc, ptr, end))) + ptr += enc->minBytesPerChar; + if (ptr != end) { + *badPtr = ptr; + return 0; + } + return 1; +} + +static int FASTCALL +checkCharRefNumber(int result) +{ + switch (result >> 8) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return -1; + case 0: + if (latin1_encoding.type[result] == BT_NONXML) + return -1; + break; + case 0xFF: + if (result == 0xFFFE || result == 0xFFFF) + return -1; + break; + } + return result; +} + +int FASTCALL +XmlUtf8Encode(int c, char *buf) +{ + enum { + /* minN is minimum legal resulting value for N byte sequence */ + min2 = 0x80, + min3 = 0x800, + min4 = 0x10000 + }; + + if (c < 0) + return 0; + if (c < min2) { + buf[0] = (char)(c | UTF8_cval1); + return 1; + } + if (c < min3) { + buf[0] = (char)((c >> 6) | UTF8_cval2); + buf[1] = (char)((c & 0x3f) | 0x80); + return 2; + } + if (c < min4) { + buf[0] = (char)((c >> 12) | UTF8_cval3); + buf[1] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[2] = (char)((c & 0x3f) | 0x80); + return 3; + } + if (c < 0x110000) { + buf[0] = (char)((c >> 18) | UTF8_cval4); + buf[1] = (char)(((c >> 12) & 0x3f) | 0x80); + buf[2] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[3] = (char)((c & 0x3f) | 0x80); + return 4; + } + return 0; +} + +int FASTCALL +XmlUtf16Encode(int charNum, unsigned short *buf) +{ + if (charNum < 0) + return 0; + if (charNum < 0x10000) { + buf[0] = (unsigned short)charNum; + return 1; + } + if (charNum < 0x110000) { + charNum -= 0x10000; + buf[0] = (unsigned short)((charNum >> 10) + 0xD800); + buf[1] = (unsigned short)((charNum & 0x3FF) + 0xDC00); + return 2; + } + return 0; +} + +struct unknown_encoding { + struct normal_encoding normal; + CONVERTER convert; + void *userData; + unsigned short utf16[256]; + char utf8[256][4]; +}; + +#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc)) + +int +XmlSizeOfUnknownEncoding(void) +{ + return sizeof(struct unknown_encoding); +} + +static int PTRFASTCALL +unknown_isName(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isNmstrt(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isInvalid(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; +} + +static void PTRCALL +unknown_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + char buf[XML_UTF8_ENCODE_MAX]; + for (;;) { + const char *utf8; + int n; + if (*fromP == fromLim) + break; + utf8 = uenc->utf8[(unsigned char)**fromP]; + n = *utf8++; + if (n == 0) { + int c = uenc->convert(uenc->userData, *fromP); + n = XmlUtf8Encode(c, buf); + if (n > toLim - *toP) + break; + utf8 = buf; + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else { + if (n > toLim - *toP) + break; + (*fromP)++; + } + do { + *(*toP)++ = *utf8++; + } while (--n != 0); + } +} + +static void PTRCALL +unknown_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + while (*fromP != fromLim && *toP != toLim) { + unsigned short c = uenc->utf16[(unsigned char)**fromP]; + if (c == 0) { + c = (unsigned short) + uenc->convert(uenc->userData, *fromP); + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else + (*fromP)++; + *(*toP)++ = c; + } +} + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + int i; + struct unknown_encoding *e = (struct unknown_encoding *)mem; + for (i = 0; i < (int)sizeof(struct normal_encoding); i++) + ((char *)mem)[i] = ((char *)&latin1_encoding)[i]; + for (i = 0; i < 128; i++) + if (latin1_encoding.type[i] != BT_OTHER + && latin1_encoding.type[i] != BT_NONXML + && table[i] != i) + return 0; + for (i = 0; i < 256; i++) { + int c = table[i]; + if (c == -1) { + e->normal.type[i] = BT_MALFORM; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else if (c < 0) { + if (c < -4) + return 0; + e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2)); + e->utf8[i][0] = 0; + e->utf16[i] = 0; + } + else if (c < 0x80) { + if (latin1_encoding.type[c] != BT_OTHER + && latin1_encoding.type[c] != BT_NONXML + && c != i) + return 0; + e->normal.type[i] = latin1_encoding.type[c]; + e->utf8[i][0] = 1; + e->utf8[i][1] = (char)c; + e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c); + } + else if (checkCharRefNumber(c) < 0) { + e->normal.type[i] = BT_NONXML; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else { + if (c > 0xFFFF) + return 0; + if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NMSTRT; + else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NAME; + else + e->normal.type[i] = BT_OTHER; + e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1); + e->utf16[i] = (unsigned short)c; + } + } + e->userData = userData; + e->convert = convert; + if (convert) { + e->normal.isName2 = unknown_isName; + e->normal.isName3 = unknown_isName; + e->normal.isName4 = unknown_isName; + e->normal.isNmstrt2 = unknown_isNmstrt; + e->normal.isNmstrt3 = unknown_isNmstrt; + e->normal.isNmstrt4 = unknown_isNmstrt; + e->normal.isInvalid2 = unknown_isInvalid; + e->normal.isInvalid3 = unknown_isInvalid; + e->normal.isInvalid4 = unknown_isInvalid; + } + e->normal.enc.utf8Convert = unknown_toUtf8; + e->normal.enc.utf16Convert = unknown_toUtf16; + return &(e->normal.enc); +} + +/* If this enumeration is changed, getEncodingIndex and encodings +must also be changed. */ +enum { + UNKNOWN_ENC = -1, + ISO_8859_1_ENC = 0, + US_ASCII_ENC, + UTF_8_ENC, + UTF_16_ENC, + UTF_16BE_ENC, + UTF_16LE_ENC, + /* must match encodingNames up to here */ + NO_ENC +}; + +static const char KW_ISO_8859_1[] = { + ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, + ASCII_MINUS, ASCII_1, '\0' +}; +static const char KW_US_ASCII[] = { + ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, + '\0' +}; +static const char KW_UTF_8[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0' +}; +static const char KW_UTF_16[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0' +}; +static const char KW_UTF_16BE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, + '\0' +}; +static const char KW_UTF_16LE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, + '\0' +}; + +static int FASTCALL +getEncodingIndex(const char *name) +{ + static const char * const encodingNames[] = { + KW_ISO_8859_1, + KW_US_ASCII, + KW_UTF_8, + KW_UTF_16, + KW_UTF_16BE, + KW_UTF_16LE, + }; + int i; + if (name == NULL) + return NO_ENC; + for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++) + if (streqci(name, encodingNames[i])) + return i; + return UNKNOWN_ENC; +} + +/* For binary compatibility, we store the index of the encoding + specified at initialization in the isUtf16 member. +*/ + +#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16) +#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i) + +/* This is what detects the encoding. encodingTable maps from + encoding indices to encodings; INIT_ENC_INDEX(enc) is the index of + the external (protocol) specified encoding; state is + XML_CONTENT_STATE if we're parsing an external text entity, and + XML_PROLOG_STATE otherwise. +*/ + + +static int +initScan(const ENCODING * const *encodingTable, + const INIT_ENCODING *enc, + int state, + const char *ptr, + const char *end, + const char **nextTokPtr) +{ + const ENCODING **encPtr; + + if (ptr == end) + return XML_TOK_NONE; + encPtr = enc->encPtr; + if (ptr + 1 == end) { + /* only a single byte available for auto-detection */ +#ifndef XML_DTD /* FIXME */ + /* a well-formed document entity must have more than one byte */ + if (state != XML_CONTENT_STATE) + return XML_TOK_PARTIAL; +#endif + /* so we're parsing an external text entity... */ + /* if UTF-16 was externally specified, then we need at least 2 bytes */ + switch (INIT_ENC_INDEX(enc)) { + case UTF_16_ENC: + case UTF_16LE_ENC: + case UTF_16BE_ENC: + return XML_TOK_PARTIAL; + } + switch ((unsigned char)*ptr) { + case 0xFE: + case 0xFF: + case 0xEF: /* possibly first byte of UTF-8 BOM */ + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + /* fall through */ + case 0x00: + case 0x3C: + return XML_TOK_PARTIAL; + } + } + else { + switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) { + case 0xFEFF: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XML_TOK_BOM; + /* 00 3C is handled in the default case */ + case 0x3C00: + if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC + || INIT_ENC_INDEX(enc) == UTF_16_ENC) + && state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + case 0xFFFE: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XML_TOK_BOM; + case 0xEFBB: + /* Maybe a UTF-8 BOM (EF BB BF) */ + /* If there's an explicitly specified (external) encoding + of ISO-8859-1 or some flavour of UTF-16 + and this is an external text entity, + don't look for the BOM, + because it might be a legal data. + */ + if (state == XML_CONTENT_STATE) { + int e = INIT_ENC_INDEX(enc); + if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC + || e == UTF_16LE_ENC || e == UTF_16_ENC) + break; + } + if (ptr + 2 == end) + return XML_TOK_PARTIAL; + if ((unsigned char)ptr[2] == 0xBF) { + *nextTokPtr = ptr + 3; + *encPtr = encodingTable[UTF_8_ENC]; + return XML_TOK_BOM; + } + break; + default: + if (ptr[0] == '\0') { + /* 0 isn't a legal data character. Furthermore a document + entity can only start with ASCII characters. So the only + way this can fail to be big-endian UTF-16 if it it's an + external parsed general entity that's labelled as + UTF-16LE. + */ + if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC) + break; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + else if (ptr[1] == '\0') { + /* We could recover here in the case: + - parsing an external entity + - second byte is 0 + - no externally specified encoding + - no encoding declaration + by assuming UTF-16LE. But we don't, because this would mean when + presented just with a single byte, we couldn't reliably determine + whether we needed further bytes. + */ + if (state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + break; + } + } + *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); +} + + +#define NS(x) x +#define ns(x) x +#define XML_TOK_NS_C +#include "xmltok_ns.c" +#undef XML_TOK_NS_C +#undef NS +#undef ns + +#ifdef XML_NS + +#define NS(x) x ## NS +#define ns(x) x ## _ns + +#define XML_TOK_NS_C +#include "xmltok_ns.c" +#undef XML_TOK_NS_C + +#undef NS +#undef ns + +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData); + if (enc) + ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON; + return enc; +} + +#endif /* XML_NS */ diff --git a/XML/src/xmltok.h b/XML/src/xmltok.h index 497611f8b..ca867aa6b 100644 --- a/XML/src/xmltok.h +++ b/XML/src/xmltok.h @@ -1,316 +1,316 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -#ifndef XmlTok_INCLUDED -#define XmlTok_INCLUDED 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* The following token may be returned by XmlContentTok */ -#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be - start of illegal ]]> sequence */ -/* The following tokens may be returned by both XmlPrologTok and - XmlContentTok. -*/ -#define XML_TOK_NONE -4 /* The string to be scanned is empty */ -#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; - might be part of CRLF sequence */ -#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ -#define XML_TOK_PARTIAL -1 /* only part of a token */ -#define XML_TOK_INVALID 0 - -/* The following tokens are returned by XmlContentTok; some are also - returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. -*/ -#define XML_TOK_START_TAG_WITH_ATTS 1 -#define XML_TOK_START_TAG_NO_ATTS 2 -#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag */ -#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 -#define XML_TOK_END_TAG 5 -#define XML_TOK_DATA_CHARS 6 -#define XML_TOK_DATA_NEWLINE 7 -#define XML_TOK_CDATA_SECT_OPEN 8 -#define XML_TOK_ENTITY_REF 9 -#define XML_TOK_CHAR_REF 10 /* numeric character reference */ - -/* The following tokens may be returned by both XmlPrologTok and - XmlContentTok. -*/ -#define XML_TOK_PI 11 /* processing instruction */ -#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ -#define XML_TOK_COMMENT 13 -#define XML_TOK_BOM 14 /* Byte order mark */ - -/* The following tokens are returned only by XmlPrologTok */ -#define XML_TOK_PROLOG_S 15 -#define XML_TOK_DECL_OPEN 16 /* */ -#define XML_TOK_NAME 18 -#define XML_TOK_NMTOKEN 19 -#define XML_TOK_POUND_NAME 20 /* #name */ -#define XML_TOK_OR 21 /* | */ -#define XML_TOK_PERCENT 22 -#define XML_TOK_OPEN_PAREN 23 -#define XML_TOK_CLOSE_PAREN 24 -#define XML_TOK_OPEN_BRACKET 25 -#define XML_TOK_CLOSE_BRACKET 26 -#define XML_TOK_LITERAL 27 -#define XML_TOK_PARAM_ENTITY_REF 28 -#define XML_TOK_INSTANCE_START 29 - -/* The following occur only in element type declarations */ -#define XML_TOK_NAME_QUESTION 30 /* name? */ -#define XML_TOK_NAME_ASTERISK 31 /* name* */ -#define XML_TOK_NAME_PLUS 32 /* name+ */ -#define XML_TOK_COND_SECT_OPEN 33 /* */ -#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ -#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ -#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ -#define XML_TOK_COMMA 38 - -/* The following token is returned only by XmlAttributeValueTok */ -#define XML_TOK_ATTRIBUTE_VALUE_S 39 - -/* The following token is returned only by XmlCdataSectionTok */ -#define XML_TOK_CDATA_SECT_CLOSE 40 - -/* With namespace processing this is returned by XmlPrologTok for a - name with a colon. -*/ -#define XML_TOK_PREFIXED_NAME 41 - -#ifdef XML_DTD -#define XML_TOK_IGNORE_SECT 42 -#endif /* XML_DTD */ - -#ifdef XML_DTD -#define XML_N_STATES 4 -#else /* not XML_DTD */ -#define XML_N_STATES 3 -#endif /* not XML_DTD */ - -#define XML_PROLOG_STATE 0 -#define XML_CONTENT_STATE 1 -#define XML_CDATA_SECTION_STATE 2 -#ifdef XML_DTD -#define XML_IGNORE_SECTION_STATE 3 -#endif /* XML_DTD */ - -#define XML_N_LITERAL_TYPES 2 -#define XML_ATTRIBUTE_VALUE_LITERAL 0 -#define XML_ENTITY_VALUE_LITERAL 1 - -/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ -#define XML_UTF8_ENCODE_MAX 4 -/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ -#define XML_UTF16_ENCODE_MAX 2 - -typedef struct position { - /* first line and first column are 0 not 1 */ - XML_Size lineNumber; - XML_Size columnNumber; -} POSITION; - -typedef struct { - const char *name; - const char *valuePtr; - const char *valueEnd; - char normalized; -} ATTRIBUTE; - -struct encoding; -typedef struct encoding ENCODING; - -typedef int (PTRCALL *SCANNER)(const ENCODING *, - const char *, - const char *, - const char **); - -struct encoding { - SCANNER scanners[XML_N_STATES]; - SCANNER literalScanners[XML_N_LITERAL_TYPES]; - int (PTRCALL *sameName)(const ENCODING *, - const char *, - const char *); - int (PTRCALL *nameMatchesAscii)(const ENCODING *, - const char *, - const char *, - const char *); - int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); - const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); - int (PTRCALL *getAtts)(const ENCODING *enc, - const char *ptr, - int attsMax, - ATTRIBUTE *atts); - int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); - int (PTRCALL *predefinedEntityName)(const ENCODING *, - const char *, - const char *); - void (PTRCALL *updatePosition)(const ENCODING *, - const char *ptr, - const char *end, - POSITION *); - int (PTRCALL *isPublicId)(const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr); - void (PTRCALL *utf8Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, - char **toP, - const char *toLim); - void (PTRCALL *utf16Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, - unsigned short **toP, - const unsigned short *toLim); - int minBytesPerChar; - char isUtf8; - char isUtf16; -}; - -/* Scan the string starting at ptr until the end of the next complete - token, but do not scan past eptr. Return an integer giving the - type of token. - - Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. - - Return XML_TOK_PARTIAL when the string does not contain a complete - token; nextTokPtr will not be set. - - Return XML_TOK_INVALID when the string does not start a valid - token; nextTokPtr will be set to point to the character which made - the token invalid. - - Otherwise the string starts with a valid token; nextTokPtr will be - set to point to the character following the end of that token. - - Each data character counts as a single token, but adjacent data - characters may be returned together. Similarly for characters in - the prolog outside literals, comments and processing instructions. -*/ - - -#define XmlTok(enc, state, ptr, end, nextTokPtr) \ - (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) - -#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) - -#define XmlContentTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) - -#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) - -#ifdef XML_DTD - -#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) - -#endif /* XML_DTD */ - -/* This is used for performing a 2nd-level tokenization on the content - of a literal that has already been returned by XmlTok. -*/ -#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ - (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) - -#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ - XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) - -#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ - XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) - -#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) - -#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ - (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) - -#define XmlNameLength(enc, ptr) \ - (((enc)->nameLength)(enc, ptr)) - -#define XmlSkipS(enc, ptr) \ - (((enc)->skipS)(enc, ptr)) - -#define XmlGetAttributes(enc, ptr, attsMax, atts) \ - (((enc)->getAtts)(enc, ptr, attsMax, atts)) - -#define XmlCharRefNumber(enc, ptr) \ - (((enc)->charRefNumber)(enc, ptr)) - -#define XmlPredefinedEntityName(enc, ptr, end) \ - (((enc)->predefinedEntityName)(enc, ptr, end)) - -#define XmlUpdatePosition(enc, ptr, end, pos) \ - (((enc)->updatePosition)(enc, ptr, end, pos)) - -#define XmlIsPublicId(enc, ptr, end, badPtr) \ - (((enc)->isPublicId)(enc, ptr, end, badPtr)) - -#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ - (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) - -#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ - (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) - -typedef struct { - ENCODING initEnc; - const ENCODING **encPtr; -} INIT_ENCODING; - -int XmlParseXmlDecl(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingNamePtr, - const ENCODING **namedEncodingPtr, - int *standalonePtr); - -int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); -const ENCODING *XmlGetUtf8InternalEncoding(void); -const ENCODING *XmlGetUtf16InternalEncoding(void); -int FASTCALL XmlUtf8Encode(int charNumber, char *buf); -int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); -int XmlSizeOfUnknownEncoding(void); - - -typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); - -ENCODING * -XmlInitUnknownEncoding(void *mem, - int *table, - CONVERTER convert, - void *userData); - -int XmlParseXmlDeclNS(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingNamePtr, - const ENCODING **namedEncodingPtr, - int *standalonePtr); - -int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); -const ENCODING *XmlGetUtf8InternalEncodingNS(void); -const ENCODING *XmlGetUtf16InternalEncodingNS(void); -ENCODING * -XmlInitUnknownEncodingNS(void *mem, - int *table, - CONVERTER convert, - void *userData); -#ifdef __cplusplus -} -#endif - -#endif /* not XmlTok_INCLUDED */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlTok_INCLUDED +#define XmlTok_INCLUDED 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* The following token may be returned by XmlContentTok */ +#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be + start of illegal ]]> sequence */ +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_NONE -4 /* The string to be scanned is empty */ +#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; + might be part of CRLF sequence */ +#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ +#define XML_TOK_PARTIAL -1 /* only part of a token */ +#define XML_TOK_INVALID 0 + +/* The following tokens are returned by XmlContentTok; some are also + returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. +*/ +#define XML_TOK_START_TAG_WITH_ATTS 1 +#define XML_TOK_START_TAG_NO_ATTS 2 +#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag */ +#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 +#define XML_TOK_END_TAG 5 +#define XML_TOK_DATA_CHARS 6 +#define XML_TOK_DATA_NEWLINE 7 +#define XML_TOK_CDATA_SECT_OPEN 8 +#define XML_TOK_ENTITY_REF 9 +#define XML_TOK_CHAR_REF 10 /* numeric character reference */ + +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_PI 11 /* processing instruction */ +#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ +#define XML_TOK_COMMENT 13 +#define XML_TOK_BOM 14 /* Byte order mark */ + +/* The following tokens are returned only by XmlPrologTok */ +#define XML_TOK_PROLOG_S 15 +#define XML_TOK_DECL_OPEN 16 /* */ +#define XML_TOK_NAME 18 +#define XML_TOK_NMTOKEN 19 +#define XML_TOK_POUND_NAME 20 /* #name */ +#define XML_TOK_OR 21 /* | */ +#define XML_TOK_PERCENT 22 +#define XML_TOK_OPEN_PAREN 23 +#define XML_TOK_CLOSE_PAREN 24 +#define XML_TOK_OPEN_BRACKET 25 +#define XML_TOK_CLOSE_BRACKET 26 +#define XML_TOK_LITERAL 27 +#define XML_TOK_PARAM_ENTITY_REF 28 +#define XML_TOK_INSTANCE_START 29 + +/* The following occur only in element type declarations */ +#define XML_TOK_NAME_QUESTION 30 /* name? */ +#define XML_TOK_NAME_ASTERISK 31 /* name* */ +#define XML_TOK_NAME_PLUS 32 /* name+ */ +#define XML_TOK_COND_SECT_OPEN 33 /* */ +#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ +#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ +#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ +#define XML_TOK_COMMA 38 + +/* The following token is returned only by XmlAttributeValueTok */ +#define XML_TOK_ATTRIBUTE_VALUE_S 39 + +/* The following token is returned only by XmlCdataSectionTok */ +#define XML_TOK_CDATA_SECT_CLOSE 40 + +/* With namespace processing this is returned by XmlPrologTok for a + name with a colon. +*/ +#define XML_TOK_PREFIXED_NAME 41 + +#ifdef XML_DTD +#define XML_TOK_IGNORE_SECT 42 +#endif /* XML_DTD */ + +#ifdef XML_DTD +#define XML_N_STATES 4 +#else /* not XML_DTD */ +#define XML_N_STATES 3 +#endif /* not XML_DTD */ + +#define XML_PROLOG_STATE 0 +#define XML_CONTENT_STATE 1 +#define XML_CDATA_SECTION_STATE 2 +#ifdef XML_DTD +#define XML_IGNORE_SECTION_STATE 3 +#endif /* XML_DTD */ + +#define XML_N_LITERAL_TYPES 2 +#define XML_ATTRIBUTE_VALUE_LITERAL 0 +#define XML_ENTITY_VALUE_LITERAL 1 + +/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ +#define XML_UTF8_ENCODE_MAX 4 +/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ +#define XML_UTF16_ENCODE_MAX 2 + +typedef struct position { + /* first line and first column are 0 not 1 */ + XML_Size lineNumber; + XML_Size columnNumber; +} POSITION; + +typedef struct { + const char *name; + const char *valuePtr; + const char *valueEnd; + char normalized; +} ATTRIBUTE; + +struct encoding; +typedef struct encoding ENCODING; + +typedef int (PTRCALL *SCANNER)(const ENCODING *, + const char *, + const char *, + const char **); + +struct encoding { + SCANNER scanners[XML_N_STATES]; + SCANNER literalScanners[XML_N_LITERAL_TYPES]; + int (PTRCALL *sameName)(const ENCODING *, + const char *, + const char *); + int (PTRCALL *nameMatchesAscii)(const ENCODING *, + const char *, + const char *, + const char *); + int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); + const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); + int (PTRCALL *getAtts)(const ENCODING *enc, + const char *ptr, + int attsMax, + ATTRIBUTE *atts); + int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); + int (PTRCALL *predefinedEntityName)(const ENCODING *, + const char *, + const char *); + void (PTRCALL *updatePosition)(const ENCODING *, + const char *ptr, + const char *end, + POSITION *); + int (PTRCALL *isPublicId)(const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr); + void (PTRCALL *utf8Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + char **toP, + const char *toLim); + void (PTRCALL *utf16Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + unsigned short **toP, + const unsigned short *toLim); + int minBytesPerChar; + char isUtf8; + char isUtf16; +}; + +/* Scan the string starting at ptr until the end of the next complete + token, but do not scan past eptr. Return an integer giving the + type of token. + + Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. + + Return XML_TOK_PARTIAL when the string does not contain a complete + token; nextTokPtr will not be set. + + Return XML_TOK_INVALID when the string does not start a valid + token; nextTokPtr will be set to point to the character which made + the token invalid. + + Otherwise the string starts with a valid token; nextTokPtr will be + set to point to the character following the end of that token. + + Each data character counts as a single token, but adjacent data + characters may be returned together. Similarly for characters in + the prolog outside literals, comments and processing instructions. +*/ + + +#define XmlTok(enc, state, ptr, end, nextTokPtr) \ + (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) + +#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) + +#define XmlContentTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) + +#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) + +#ifdef XML_DTD + +#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) + +#endif /* XML_DTD */ + +/* This is used for performing a 2nd-level tokenization on the content + of a literal that has already been returned by XmlTok. +*/ +#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ + (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) + +#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) + +#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ + (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) + +#define XmlNameLength(enc, ptr) \ + (((enc)->nameLength)(enc, ptr)) + +#define XmlSkipS(enc, ptr) \ + (((enc)->skipS)(enc, ptr)) + +#define XmlGetAttributes(enc, ptr, attsMax, atts) \ + (((enc)->getAtts)(enc, ptr, attsMax, atts)) + +#define XmlCharRefNumber(enc, ptr) \ + (((enc)->charRefNumber)(enc, ptr)) + +#define XmlPredefinedEntityName(enc, ptr, end) \ + (((enc)->predefinedEntityName)(enc, ptr, end)) + +#define XmlUpdatePosition(enc, ptr, end, pos) \ + (((enc)->updatePosition)(enc, ptr, end, pos)) + +#define XmlIsPublicId(enc, ptr, end, badPtr) \ + (((enc)->isPublicId)(enc, ptr, end, badPtr)) + +#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) + +#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) + +typedef struct { + ENCODING initEnc; + const ENCODING **encPtr; +} INIT_ENCODING; + +int XmlParseXmlDecl(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncoding(void); +const ENCODING *XmlGetUtf16InternalEncoding(void); +int FASTCALL XmlUtf8Encode(int charNumber, char *buf); +int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); +int XmlSizeOfUnknownEncoding(void); + + +typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData); + +int XmlParseXmlDeclNS(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncodingNS(void); +const ENCODING *XmlGetUtf16InternalEncodingNS(void); +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData); +#ifdef __cplusplus +} +#endif + +#endif /* not XmlTok_INCLUDED */ diff --git a/XML/src/xmltok_impl.c b/XML/src/xmltok_impl.c index baae3b426..126881925 100644 --- a/XML/src/xmltok_impl.c +++ b/XML/src/xmltok_impl.c @@ -1,1783 +1,1783 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -/* This file is included! */ -#ifdef XML_TOK_IMPL_C - -#ifndef IS_INVALID_CHAR -#define IS_INVALID_CHAR(enc, ptr, n) (0) -#endif - -#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (IS_INVALID_CHAR(enc, ptr, n)) { \ - *(nextTokPtr) = (ptr); \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define INVALID_CASES(ptr, nextTokPtr) \ - INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ - INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ - INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ - case BT_NONXML: \ - case BT_MALFORM: \ - case BT_TRAIL: \ - *(nextTokPtr) = (ptr); \ - return XML_TOK_INVALID; - -#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (!IS_NAME_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ - case BT_NONASCII: \ - if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - case BT_NMSTRT: \ - case BT_HEX: \ - case BT_DIGIT: \ - case BT_NAME: \ - case BT_MINUS: \ - ptr += MINBPC(enc); \ - break; \ - CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ - CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ - CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) - -#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ - case BT_NONASCII: \ - if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - case BT_NMSTRT: \ - case BT_HEX: \ - ptr += MINBPC(enc); \ - break; \ - CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ - CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ - CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) - -#ifndef PREFIX -#define PREFIX(ident) ident -#endif - -/* ptr points to character following " */ - switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { - case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - /* fall through */ - case BT_S: case BT_CR: case BT_LF: - *nextTokPtr = ptr; - return XML_TOK_DECL_OPEN; - case BT_NMSTRT: - case BT_HEX: - ptr += MINBPC(enc); - break; - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - } - return XML_TOK_PARTIAL; -} - -static int PTRCALL -PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, - const char *end, int *tokPtr) -{ - int upper = 0; - *tokPtr = XML_TOK_PI; - if (end - ptr != MINBPC(enc)*3) - return 1; - switch (BYTE_TO_ASCII(enc, ptr)) { - case ASCII_x: - break; - case ASCII_X: - upper = 1; - break; - default: - return 1; - } - ptr += MINBPC(enc); - switch (BYTE_TO_ASCII(enc, ptr)) { - case ASCII_m: - break; - case ASCII_M: - upper = 1; - break; - default: - return 1; - } - ptr += MINBPC(enc); - switch (BYTE_TO_ASCII(enc, ptr)) { - case ASCII_l: - break; - case ASCII_L: - upper = 1; - break; - default: - return 1; - } - if (upper) - return 0; - *tokPtr = XML_TOK_XML_DECL; - return 1; -} - -/* ptr points to character following " 1) { - size_t n = end - ptr; - if (n & (MINBPC(enc) - 1)) { - n &= ~(MINBPC(enc) - 1); - if (n == 0) - return XML_TOK_PARTIAL; - end = ptr + n; - } - } - switch (BYTE_TYPE(enc, ptr)) { - case BT_RSQB: - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; - if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) - break; - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; - if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { - ptr -= MINBPC(enc); - break; - } - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_CDATA_SECT_CLOSE; - case BT_CR: - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; - if (BYTE_TYPE(enc, ptr) == BT_LF) - ptr += MINBPC(enc); - *nextTokPtr = ptr; - return XML_TOK_DATA_NEWLINE; - case BT_LF: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_DATA_NEWLINE; - INVALID_CASES(ptr, nextTokPtr) - default: - ptr += MINBPC(enc); - break; - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_DATA_CHARS; \ - } \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_NONXML: - case BT_MALFORM: - case BT_TRAIL: - case BT_CR: - case BT_LF: - case BT_RSQB: - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - default: - ptr += MINBPC(enc); - break; - } - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; -} - -/* ptr points to character following " 1) { - size_t n = end - ptr; - if (n & (MINBPC(enc) - 1)) { - n &= ~(MINBPC(enc) - 1); - if (n == 0) - return XML_TOK_PARTIAL; - end = ptr + n; - } - } - switch (BYTE_TYPE(enc, ptr)) { - case BT_LT: - return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_AMP: - return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_CR: - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_TRAILING_CR; - if (BYTE_TYPE(enc, ptr) == BT_LF) - ptr += MINBPC(enc); - *nextTokPtr = ptr; - return XML_TOK_DATA_NEWLINE; - case BT_LF: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_DATA_NEWLINE; - case BT_RSQB: - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_TRAILING_RSQB; - if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) - break; - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_TRAILING_RSQB; - if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { - ptr -= MINBPC(enc); - break; - } - *nextTokPtr = ptr; - return XML_TOK_INVALID; - INVALID_CASES(ptr, nextTokPtr) - default: - ptr += MINBPC(enc); - break; - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_DATA_CHARS; \ - } \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_RSQB: - if (ptr + MINBPC(enc) != end) { - if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { - ptr += MINBPC(enc); - break; - } - if (ptr + 2*MINBPC(enc) != end) { - if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { - ptr += MINBPC(enc); - break; - } - *nextTokPtr = ptr + 2*MINBPC(enc); - return XML_TOK_INVALID; - } - } - /* fall through */ - case BT_AMP: - case BT_LT: - case BT_NONXML: - case BT_MALFORM: - case BT_TRAIL: - case BT_CR: - case BT_LF: - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - default: - ptr += MINBPC(enc); - break; - } - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; -} - -/* ptr points to character following "%" */ - -static int PTRCALL -PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - if (ptr == end) - return -XML_TOK_PERCENT; - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) - case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: - *nextTokPtr = ptr; - return XML_TOK_PERCENT; - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - case BT_SEMI: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_PARAM_ENTITY_REF; - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - } - return XML_TOK_PARTIAL; -} - -static int PTRCALL -PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - if (ptr == end) - return XML_TOK_PARTIAL; - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - case BT_CR: case BT_LF: case BT_S: - case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: - *nextTokPtr = ptr; - return XML_TOK_POUND_NAME; - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - } - return -XML_TOK_POUND_NAME; -} - -static int PTRCALL -PREFIX(scanLit)(int open, const ENCODING *enc, - const char *ptr, const char *end, - const char **nextTokPtr) -{ - while (ptr != end) { - int t = BYTE_TYPE(enc, ptr); - switch (t) { - INVALID_CASES(ptr, nextTokPtr) - case BT_QUOT: - case BT_APOS: - ptr += MINBPC(enc); - if (t != open) - break; - if (ptr == end) - return -XML_TOK_LITERAL; - *nextTokPtr = ptr; - switch (BYTE_TYPE(enc, ptr)) { - case BT_S: case BT_CR: case BT_LF: - case BT_GT: case BT_PERCNT: case BT_LSQB: - return XML_TOK_LITERAL; - default: - return XML_TOK_INVALID; - } - default: - ptr += MINBPC(enc); - break; - } - } - return XML_TOK_PARTIAL; -} - -static int PTRCALL -PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - int tok; - if (ptr == end) - return XML_TOK_NONE; - if (MINBPC(enc) > 1) { - size_t n = end - ptr; - if (n & (MINBPC(enc) - 1)) { - n &= ~(MINBPC(enc) - 1); - if (n == 0) - return XML_TOK_PARTIAL; - end = ptr + n; - } - } - switch (BYTE_TYPE(enc, ptr)) { - case BT_QUOT: - return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_APOS: - return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_LT: - { - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_PARTIAL; - switch (BYTE_TYPE(enc, ptr)) { - case BT_EXCL: - return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_QUEST: - return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_NMSTRT: - case BT_HEX: - case BT_NONASCII: - case BT_LEAD2: - case BT_LEAD3: - case BT_LEAD4: - *nextTokPtr = ptr - MINBPC(enc); - return XML_TOK_INSTANCE_START; - } - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - case BT_CR: - if (ptr + MINBPC(enc) == end) { - *nextTokPtr = end; - /* indicate that this might be part of a CR/LF pair */ - return -XML_TOK_PROLOG_S; - } - /* fall through */ - case BT_S: case BT_LF: - for (;;) { - ptr += MINBPC(enc); - if (ptr == end) - break; - switch (BYTE_TYPE(enc, ptr)) { - case BT_S: case BT_LF: - break; - case BT_CR: - /* don't split CR/LF pair */ - if (ptr + MINBPC(enc) != end) - break; - /* fall through */ - default: - *nextTokPtr = ptr; - return XML_TOK_PROLOG_S; - } - } - *nextTokPtr = ptr; - return XML_TOK_PROLOG_S; - case BT_PERCNT: - return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_COMMA: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_COMMA; - case BT_LSQB: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_OPEN_BRACKET; - case BT_RSQB: - ptr += MINBPC(enc); - if (ptr == end) - return -XML_TOK_CLOSE_BRACKET; - if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { - if (ptr + MINBPC(enc) == end) - return XML_TOK_PARTIAL; - if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { - *nextTokPtr = ptr + 2*MINBPC(enc); - return XML_TOK_COND_SECT_CLOSE; - } - } - *nextTokPtr = ptr; - return XML_TOK_CLOSE_BRACKET; - case BT_LPAR: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_OPEN_PAREN; - case BT_RPAR: - ptr += MINBPC(enc); - if (ptr == end) - return -XML_TOK_CLOSE_PAREN; - switch (BYTE_TYPE(enc, ptr)) { - case BT_AST: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_CLOSE_PAREN_ASTERISK; - case BT_QUEST: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_CLOSE_PAREN_QUESTION; - case BT_PLUS: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_CLOSE_PAREN_PLUS; - case BT_CR: case BT_LF: case BT_S: - case BT_GT: case BT_COMMA: case BT_VERBAR: - case BT_RPAR: - *nextTokPtr = ptr; - return XML_TOK_CLOSE_PAREN; - } - *nextTokPtr = ptr; - return XML_TOK_INVALID; - case BT_VERBAR: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_OR; - case BT_GT: - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_DECL_CLOSE; - case BT_NUM: - return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ - ptr += n; \ - tok = XML_TOK_NAME; \ - break; \ - } \ - if (IS_NAME_CHAR(enc, ptr, n)) { \ - ptr += n; \ - tok = XML_TOK_NMTOKEN; \ - break; \ - } \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_NMSTRT: - case BT_HEX: - tok = XML_TOK_NAME; - ptr += MINBPC(enc); - break; - case BT_DIGIT: - case BT_NAME: - case BT_MINUS: -#ifdef XML_NS - case BT_COLON: -#endif - tok = XML_TOK_NMTOKEN; - ptr += MINBPC(enc); - break; - case BT_NONASCII: - if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { - ptr += MINBPC(enc); - tok = XML_TOK_NAME; - break; - } - if (IS_NAME_CHAR_MINBPC(enc, ptr)) { - ptr += MINBPC(enc); - tok = XML_TOK_NMTOKEN; - break; - } - /* fall through */ - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - case BT_GT: case BT_RPAR: case BT_COMMA: - case BT_VERBAR: case BT_LSQB: case BT_PERCNT: - case BT_S: case BT_CR: case BT_LF: - *nextTokPtr = ptr; - return tok; -#ifdef XML_NS - case BT_COLON: - ptr += MINBPC(enc); - switch (tok) { - case XML_TOK_NAME: - if (ptr == end) - return XML_TOK_PARTIAL; - tok = XML_TOK_PREFIXED_NAME; - switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - default: - tok = XML_TOK_NMTOKEN; - break; - } - break; - case XML_TOK_PREFIXED_NAME: - tok = XML_TOK_NMTOKEN; - break; - } - break; -#endif - case BT_PLUS: - if (tok == XML_TOK_NMTOKEN) { - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_NAME_PLUS; - case BT_AST: - if (tok == XML_TOK_NMTOKEN) { - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_NAME_ASTERISK; - case BT_QUEST: - if (tok == XML_TOK_NMTOKEN) { - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_NAME_QUESTION; - default: - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } - } - return -tok; -} - -static int PTRCALL -PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ - const char *start; - if (ptr == end) - return XML_TOK_NONE; - start = ptr; - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_AMP: - if (ptr == start) - return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_LT: - /* this is for inside entity references */ - *nextTokPtr = ptr; - return XML_TOK_INVALID; - case BT_LF: - if (ptr == start) { - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_DATA_NEWLINE; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_CR: - if (ptr == start) { - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_TRAILING_CR; - if (BYTE_TYPE(enc, ptr) == BT_LF) - ptr += MINBPC(enc); - *nextTokPtr = ptr; - return XML_TOK_DATA_NEWLINE; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_S: - if (ptr == start) { - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_ATTRIBUTE_VALUE_S; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - default: - ptr += MINBPC(enc); - break; - } - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; -} - -static int PTRCALL -PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ - const char *start; - if (ptr == end) - return XML_TOK_NONE; - start = ptr; - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_AMP: - if (ptr == start) - return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_PERCNT: - if (ptr == start) { - int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), - end, nextTokPtr); - return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_LF: - if (ptr == start) { - *nextTokPtr = ptr + MINBPC(enc); - return XML_TOK_DATA_NEWLINE; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - case BT_CR: - if (ptr == start) { - ptr += MINBPC(enc); - if (ptr == end) - return XML_TOK_TRAILING_CR; - if (BYTE_TYPE(enc, ptr) == BT_LF) - ptr += MINBPC(enc); - *nextTokPtr = ptr; - return XML_TOK_DATA_NEWLINE; - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; - default: - ptr += MINBPC(enc); - break; - } - } - *nextTokPtr = ptr; - return XML_TOK_DATA_CHARS; -} - -#ifdef XML_DTD - -static int PTRCALL -PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ - int level = 0; - if (MINBPC(enc) > 1) { - size_t n = end - ptr; - if (n & (MINBPC(enc) - 1)) { - n &= ~(MINBPC(enc) - 1); - end = ptr + n; - } - } - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { - INVALID_CASES(ptr, nextTokPtr) - case BT_LT: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; - if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; - if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { - ++level; - ptr += MINBPC(enc); - } - } - break; - case BT_RSQB: - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; - if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { - if ((ptr += MINBPC(enc)) == end) - return XML_TOK_PARTIAL; - if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { - ptr += MINBPC(enc); - if (level == 0) { - *nextTokPtr = ptr; - return XML_TOK_IGNORE_SECT; - } - --level; - } - } - break; - default: - ptr += MINBPC(enc); - break; - } - } - return XML_TOK_PARTIAL; -} - -#endif /* XML_DTD */ - -static int PTRCALL -PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, - const char **badPtr) -{ - ptr += MINBPC(enc); - end -= MINBPC(enc); - for (; ptr != end; ptr += MINBPC(enc)) { - switch (BYTE_TYPE(enc, ptr)) { - case BT_DIGIT: - case BT_HEX: - case BT_MINUS: - case BT_APOS: - case BT_LPAR: - case BT_RPAR: - case BT_PLUS: - case BT_COMMA: - case BT_SOL: - case BT_EQUALS: - case BT_QUEST: - case BT_CR: - case BT_LF: - case BT_SEMI: - case BT_EXCL: - case BT_AST: - case BT_PERCNT: - case BT_NUM: -#ifdef XML_NS - case BT_COLON: -#endif - break; - case BT_S: - if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { - *badPtr = ptr; - return 0; - } - break; - case BT_NAME: - case BT_NMSTRT: - if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) - break; - default: - switch (BYTE_TO_ASCII(enc, ptr)) { - case 0x24: /* $ */ - case 0x40: /* @ */ - break; - default: - *badPtr = ptr; - return 0; - } - break; - } - } - return 1; -} - -/* This must only be called for a well-formed start-tag or empty - element tag. Returns the number of attributes. Pointers to the - first attsMax attributes are stored in atts. -*/ - -static int PTRCALL -PREFIX(getAtts)(const ENCODING *enc, const char *ptr, - int attsMax, ATTRIBUTE *atts) -{ - enum { other, inName, inValue } state = inName; - int nAtts = 0; - int open = 0; /* defined when state == inValue; - initialization just to shut up compilers */ - - for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { - switch (BYTE_TYPE(enc, ptr)) { -#define START_NAME \ - if (state == other) { \ - if (nAtts < attsMax) { \ - atts[nAtts].name = ptr; \ - atts[nAtts].normalized = 1; \ - } \ - state = inName; \ - } -#define LEAD_CASE(n) \ - case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_NONASCII: - case BT_NMSTRT: - case BT_HEX: - START_NAME - break; -#undef START_NAME - case BT_QUOT: - if (state != inValue) { - if (nAtts < attsMax) - atts[nAtts].valuePtr = ptr + MINBPC(enc); - state = inValue; - open = BT_QUOT; - } - else if (open == BT_QUOT) { - state = other; - if (nAtts < attsMax) - atts[nAtts].valueEnd = ptr; - nAtts++; - } - break; - case BT_APOS: - if (state != inValue) { - if (nAtts < attsMax) - atts[nAtts].valuePtr = ptr + MINBPC(enc); - state = inValue; - open = BT_APOS; - } - else if (open == BT_APOS) { - state = other; - if (nAtts < attsMax) - atts[nAtts].valueEnd = ptr; - nAtts++; - } - break; - case BT_AMP: - if (nAtts < attsMax) - atts[nAtts].normalized = 0; - break; - case BT_S: - if (state == inName) - state = other; - else if (state == inValue - && nAtts < attsMax - && atts[nAtts].normalized - && (ptr == atts[nAtts].valuePtr - || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE - || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE - || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) - atts[nAtts].normalized = 0; - break; - case BT_CR: case BT_LF: - /* This case ensures that the first attribute name is counted - Apart from that we could just change state on the quote. */ - if (state == inName) - state = other; - else if (state == inValue && nAtts < attsMax) - atts[nAtts].normalized = 0; - break; - case BT_GT: - case BT_SOL: - if (state != inValue) - return nAtts; - break; - default: - break; - } - } - /* not reached */ -} - -static int PTRFASTCALL -PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) -{ - int result = 0; - /* skip &# */ - ptr += 2*MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_x)) { - for (ptr += MINBPC(enc); - !CHAR_MATCHES(enc, ptr, ASCII_SEMI); - ptr += MINBPC(enc)) { - int c = BYTE_TO_ASCII(enc, ptr); - switch (c) { - case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: - case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: - result <<= 4; - result |= (c - ASCII_0); - break; - case ASCII_A: case ASCII_B: case ASCII_C: - case ASCII_D: case ASCII_E: case ASCII_F: - result <<= 4; - result += 10 + (c - ASCII_A); - break; - case ASCII_a: case ASCII_b: case ASCII_c: - case ASCII_d: case ASCII_e: case ASCII_f: - result <<= 4; - result += 10 + (c - ASCII_a); - break; - } - if (result >= 0x110000) - return -1; - } - } - else { - for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { - int c = BYTE_TO_ASCII(enc, ptr); - result *= 10; - result += (c - ASCII_0); - if (result >= 0x110000) - return -1; - } - } - return checkCharRefNumber(result); -} - -static int PTRCALL -PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, - const char *end) -{ - switch ((end - ptr)/MINBPC(enc)) { - case 2: - if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { - switch (BYTE_TO_ASCII(enc, ptr)) { - case ASCII_l: - return ASCII_LT; - case ASCII_g: - return ASCII_GT; - } - } - break; - case 3: - if (CHAR_MATCHES(enc, ptr, ASCII_a)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_m)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_p)) - return ASCII_AMP; - } - } - break; - case 4: - switch (BYTE_TO_ASCII(enc, ptr)) { - case ASCII_q: - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_u)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_o)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_t)) - return ASCII_QUOT; - } - } - break; - case ASCII_a: - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_p)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_o)) { - ptr += MINBPC(enc); - if (CHAR_MATCHES(enc, ptr, ASCII_s)) - return ASCII_APOS; - } - } - break; - } - } - return 0; -} - -static int PTRCALL -PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) -{ - for (;;) { - switch (BYTE_TYPE(enc, ptr1)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (*ptr1++ != *ptr2++) \ - return 0; - LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2) -#undef LEAD_CASE - /* fall through */ - if (*ptr1++ != *ptr2++) - return 0; - break; - case BT_NONASCII: - case BT_NMSTRT: -#ifdef XML_NS - case BT_COLON: -#endif - case BT_HEX: - case BT_DIGIT: - case BT_NAME: - case BT_MINUS: - if (*ptr2++ != *ptr1++) - return 0; - if (MINBPC(enc) > 1) { - if (*ptr2++ != *ptr1++) - return 0; - if (MINBPC(enc) > 2) { - if (*ptr2++ != *ptr1++) - return 0; - if (MINBPC(enc) > 3) { - if (*ptr2++ != *ptr1++) - return 0; - } - } - } - break; - default: - if (MINBPC(enc) == 1 && *ptr1 == *ptr2) - return 1; - switch (BYTE_TYPE(enc, ptr2)) { - case BT_LEAD2: - case BT_LEAD3: - case BT_LEAD4: - case BT_NONASCII: - case BT_NMSTRT: -#ifdef XML_NS - case BT_COLON: -#endif - case BT_HEX: - case BT_DIGIT: - case BT_NAME: - case BT_MINUS: - return 0; - default: - return 1; - } - } - } - /* not reached */ -} - -static int PTRCALL -PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, - const char *end1, const char *ptr2) -{ - for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { - if (ptr1 == end1) - return 0; - if (!CHAR_MATCHES(enc, ptr1, *ptr2)) - return 0; - } - return ptr1 == end1; -} - -static int PTRFASTCALL -PREFIX(nameLength)(const ENCODING *enc, const char *ptr) -{ - const char *start = ptr; - for (;;) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_NONASCII: - case BT_NMSTRT: -#ifdef XML_NS - case BT_COLON: -#endif - case BT_HEX: - case BT_DIGIT: - case BT_NAME: - case BT_MINUS: - ptr += MINBPC(enc); - break; - default: - return (int)(ptr - start); - } - } -} - -static const char * PTRFASTCALL -PREFIX(skipS)(const ENCODING *enc, const char *ptr) -{ - for (;;) { - switch (BYTE_TYPE(enc, ptr)) { - case BT_LF: - case BT_CR: - case BT_S: - ptr += MINBPC(enc); - break; - default: - return ptr; - } - } -} - -static void PTRCALL -PREFIX(updatePosition)(const ENCODING *enc, - const char *ptr, - const char *end, - POSITION *pos) -{ - while (ptr != end) { - switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE - case BT_LF: - pos->columnNumber = (XML_Size)-1; - pos->lineNumber++; - ptr += MINBPC(enc); - break; - case BT_CR: - pos->lineNumber++; - ptr += MINBPC(enc); - if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) - ptr += MINBPC(enc); - pos->columnNumber = (XML_Size)-1; - break; - default: - ptr += MINBPC(enc); - break; - } - pos->columnNumber++; - } -} - -#undef DO_LEAD_CASE -#undef MULTIBYTE_CASES -#undef INVALID_CASES -#undef CHECK_NAME_CASE -#undef CHECK_NAME_CASES -#undef CHECK_NMSTRT_CASE -#undef CHECK_NMSTRT_CASES - -#endif /* XML_TOK_IMPL_C */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* This file is included! */ +#ifdef XML_TOK_IMPL_C + +#ifndef IS_INVALID_CHAR +#define IS_INVALID_CHAR(enc, ptr, n) (0) +#endif + +#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_INVALID_CHAR(enc, ptr, n)) { \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define INVALID_CASES(ptr, nextTokPtr) \ + INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ + case BT_NONXML: \ + case BT_MALFORM: \ + case BT_TRAIL: \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; + +#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NAME_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + case BT_DIGIT: \ + case BT_NAME: \ + case BT_MINUS: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) + +#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) + +#ifndef PREFIX +#define PREFIX(ident) ident +#endif + +/* ptr points to character following " */ + switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { + case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + /* fall through */ + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DECL_OPEN; + case BT_NMSTRT: + case BT_HEX: + ptr += MINBPC(enc); + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, + const char *end, int *tokPtr) +{ + int upper = 0; + *tokPtr = XML_TOK_PI; + if (end - ptr != MINBPC(enc)*3) + return 1; + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_x: + break; + case ASCII_X: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_m: + break; + case ASCII_M: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + break; + case ASCII_L: + upper = 1; + break; + default: + return 1; + } + if (upper) + return 0; + *tokPtr = XML_TOK_XML_DECL; + return 1; +} + +/* ptr points to character following " 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CDATA_SECT_CLOSE; + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + case BT_RSQB: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following " 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_LT: + return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_AMP: + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_RSQB: + if (ptr + MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { + ptr += MINBPC(enc); + break; + } + if (ptr + 2*MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { + ptr += MINBPC(enc); + break; + } + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_INVALID; + } + } + /* fall through */ + case BT_AMP: + case BT_LT: + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following "%" */ + +static int PTRCALL +PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return -XML_TOK_PERCENT; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_PERCENT; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_PARAM_ENTITY_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_CR: case BT_LF: case BT_S: + case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: + *nextTokPtr = ptr; + return XML_TOK_POUND_NAME; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -XML_TOK_POUND_NAME; +} + +static int PTRCALL +PREFIX(scanLit)(int open, const ENCODING *enc, + const char *ptr, const char *end, + const char **nextTokPtr) +{ + while (ptr != end) { + int t = BYTE_TYPE(enc, ptr); + switch (t) { + INVALID_CASES(ptr, nextTokPtr) + case BT_QUOT: + case BT_APOS: + ptr += MINBPC(enc); + if (t != open) + break; + if (ptr == end) + return -XML_TOK_LITERAL; + *nextTokPtr = ptr; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_CR: case BT_LF: + case BT_GT: case BT_PERCNT: case BT_LSQB: + return XML_TOK_LITERAL; + default: + return XML_TOK_INVALID; + } + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + int tok; + if (ptr == end) + return XML_TOK_NONE; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_QUOT: + return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_APOS: + return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_LT: + { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_EXCL: + return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_QUEST: + return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_NMSTRT: + case BT_HEX: + case BT_NONASCII: + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + *nextTokPtr = ptr - MINBPC(enc); + return XML_TOK_INSTANCE_START; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + case BT_CR: + if (ptr + MINBPC(enc) == end) { + *nextTokPtr = end; + /* indicate that this might be part of a CR/LF pair */ + return -XML_TOK_PROLOG_S; + } + /* fall through */ + case BT_S: case BT_LF: + for (;;) { + ptr += MINBPC(enc); + if (ptr == end) + break; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_LF: + break; + case BT_CR: + /* don't split CR/LF pair */ + if (ptr + MINBPC(enc) != end) + break; + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + } + } + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + case BT_PERCNT: + return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_COMMA: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_COMMA; + case BT_LSQB: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_BRACKET; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_BRACKET; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if (ptr + MINBPC(enc) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_COND_SECT_CLOSE; + } + } + *nextTokPtr = ptr; + return XML_TOK_CLOSE_BRACKET; + case BT_LPAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_PAREN; + case BT_RPAR: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_PAREN; + switch (BYTE_TYPE(enc, ptr)) { + case BT_AST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_ASTERISK; + case BT_QUEST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_QUESTION; + case BT_PLUS: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_PLUS; + case BT_CR: case BT_LF: case BT_S: + case BT_GT: case BT_COMMA: case BT_VERBAR: + case BT_RPAR: + *nextTokPtr = ptr; + return XML_TOK_CLOSE_PAREN; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_VERBAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OR; + case BT_GT: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DECL_CLOSE; + case BT_NUM: + return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NAME; \ + break; \ + } \ + if (IS_NAME_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NMTOKEN; \ + break; \ + } \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NMSTRT: + case BT_HEX: + tok = XML_TOK_NAME; + ptr += MINBPC(enc); + break; + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: +#ifdef XML_NS + case BT_COLON: +#endif + tok = XML_TOK_NMTOKEN; + ptr += MINBPC(enc); + break; + case BT_NONASCII: + if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NAME; + break; + } + if (IS_NAME_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NMTOKEN; + break; + } + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_GT: case BT_RPAR: case BT_COMMA: + case BT_VERBAR: case BT_LSQB: case BT_PERCNT: + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return tok; +#ifdef XML_NS + case BT_COLON: + ptr += MINBPC(enc); + switch (tok) { + case XML_TOK_NAME: + if (ptr == end) + return XML_TOK_PARTIAL; + tok = XML_TOK_PREFIXED_NAME; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + default: + tok = XML_TOK_NMTOKEN; + break; + } + break; + case XML_TOK_PREFIXED_NAME: + tok = XML_TOK_NMTOKEN; + break; + } + break; +#endif + case BT_PLUS: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_PLUS; + case BT_AST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_ASTERISK; + case BT_QUEST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_QUESTION; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -tok; +} + +static int PTRCALL +PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LT: + /* this is for inside entity references */ + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_S: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_ATTRIBUTE_VALUE_S; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +static int PTRCALL +PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_PERCNT: + if (ptr == start) { + int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), + end, nextTokPtr); + return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +#ifdef XML_DTD + +static int PTRCALL +PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + int level = 0; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + end = ptr + n; + } + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + INVALID_CASES(ptr, nextTokPtr) + case BT_LT: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { + ++level; + ptr += MINBPC(enc); + } + } + break; + case BT_RSQB: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr += MINBPC(enc); + if (level == 0) { + *nextTokPtr = ptr; + return XML_TOK_IGNORE_SECT; + } + --level; + } + } + break; + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +#endif /* XML_DTD */ + +static int PTRCALL +PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, + const char **badPtr) +{ + ptr += MINBPC(enc); + end -= MINBPC(enc); + for (; ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + case BT_HEX: + case BT_MINUS: + case BT_APOS: + case BT_LPAR: + case BT_RPAR: + case BT_PLUS: + case BT_COMMA: + case BT_SOL: + case BT_EQUALS: + case BT_QUEST: + case BT_CR: + case BT_LF: + case BT_SEMI: + case BT_EXCL: + case BT_AST: + case BT_PERCNT: + case BT_NUM: +#ifdef XML_NS + case BT_COLON: +#endif + break; + case BT_S: + if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { + *badPtr = ptr; + return 0; + } + break; + case BT_NAME: + case BT_NMSTRT: + if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) + break; + default: + switch (BYTE_TO_ASCII(enc, ptr)) { + case 0x24: /* $ */ + case 0x40: /* @ */ + break; + default: + *badPtr = ptr; + return 0; + } + break; + } + } + return 1; +} + +/* This must only be called for a well-formed start-tag or empty + element tag. Returns the number of attributes. Pointers to the + first attsMax attributes are stored in atts. +*/ + +static int PTRCALL +PREFIX(getAtts)(const ENCODING *enc, const char *ptr, + int attsMax, ATTRIBUTE *atts) +{ + enum { other, inName, inValue } state = inName; + int nAtts = 0; + int open = 0; /* defined when state == inValue; + initialization just to shut up compilers */ + + for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { +#define START_NAME \ + if (state == other) { \ + if (nAtts < attsMax) { \ + atts[nAtts].name = ptr; \ + atts[nAtts].normalized = 1; \ + } \ + state = inName; \ + } +#define LEAD_CASE(n) \ + case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: + case BT_HEX: + START_NAME + break; +#undef START_NAME + case BT_QUOT: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_QUOT; + } + else if (open == BT_QUOT) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_APOS: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_APOS; + } + else if (open == BT_APOS) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_AMP: + if (nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_S: + if (state == inName) + state = other; + else if (state == inValue + && nAtts < attsMax + && atts[nAtts].normalized + && (ptr == atts[nAtts].valuePtr + || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE + || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE + || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) + atts[nAtts].normalized = 0; + break; + case BT_CR: case BT_LF: + /* This case ensures that the first attribute name is counted + Apart from that we could just change state on the quote. */ + if (state == inName) + state = other; + else if (state == inValue && nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_GT: + case BT_SOL: + if (state != inValue) + return nAtts; + break; + default: + break; + } + } + /* not reached */ +} + +static int PTRFASTCALL +PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) +{ + int result = 0; + /* skip &# */ + ptr += 2*MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_x)) { + for (ptr += MINBPC(enc); + !CHAR_MATCHES(enc, ptr, ASCII_SEMI); + ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + switch (c) { + case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: + case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: + result <<= 4; + result |= (c - ASCII_0); + break; + case ASCII_A: case ASCII_B: case ASCII_C: + case ASCII_D: case ASCII_E: case ASCII_F: + result <<= 4; + result += 10 + (c - ASCII_A); + break; + case ASCII_a: case ASCII_b: case ASCII_c: + case ASCII_d: case ASCII_e: case ASCII_f: + result <<= 4; + result += 10 + (c - ASCII_a); + break; + } + if (result >= 0x110000) + return -1; + } + } + else { + for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + result *= 10; + result += (c - ASCII_0); + if (result >= 0x110000) + return -1; + } + } + return checkCharRefNumber(result); +} + +static int PTRCALL +PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, + const char *end) +{ + switch ((end - ptr)/MINBPC(enc)) { + case 2: + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + return ASCII_LT; + case ASCII_g: + return ASCII_GT; + } + } + break; + case 3: + if (CHAR_MATCHES(enc, ptr, ASCII_a)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_m)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) + return ASCII_AMP; + } + } + break; + case 4: + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_q: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_u)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_t)) + return ASCII_QUOT; + } + } + break; + case ASCII_a: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_s)) + return ASCII_APOS; + } + } + break; + } + } + return 0; +} + +static int PTRCALL +PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr1)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (*ptr1++ != *ptr2++) \ + return 0; + LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2) +#undef LEAD_CASE + /* fall through */ + if (*ptr1++ != *ptr2++) + return 0; + break; + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 1) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 2) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 3) { + if (*ptr2++ != *ptr1++) + return 0; + } + } + } + break; + default: + if (MINBPC(enc) == 1 && *ptr1 == *ptr2) + return 1; + switch (BYTE_TYPE(enc, ptr2)) { + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + return 0; + default: + return 1; + } + } + } + /* not reached */ +} + +static int PTRCALL +PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, + const char *end1, const char *ptr2) +{ + for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { + if (ptr1 == end1) + return 0; + if (!CHAR_MATCHES(enc, ptr1, *ptr2)) + return 0; + } + return ptr1 == end1; +} + +static int PTRFASTCALL +PREFIX(nameLength)(const ENCODING *enc, const char *ptr) +{ + const char *start = ptr; + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + ptr += MINBPC(enc); + break; + default: + return (int)(ptr - start); + } + } +} + +static const char * PTRFASTCALL +PREFIX(skipS)(const ENCODING *enc, const char *ptr) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_LF: + case BT_CR: + case BT_S: + ptr += MINBPC(enc); + break; + default: + return ptr; + } + } +} + +static void PTRCALL +PREFIX(updatePosition)(const ENCODING *enc, + const char *ptr, + const char *end, + POSITION *pos) +{ + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_LF: + pos->columnNumber = (XML_Size)-1; + pos->lineNumber++; + ptr += MINBPC(enc); + break; + case BT_CR: + pos->lineNumber++; + ptr += MINBPC(enc); + if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + pos->columnNumber = (XML_Size)-1; + break; + default: + ptr += MINBPC(enc); + break; + } + pos->columnNumber++; + } +} + +#undef DO_LEAD_CASE +#undef MULTIBYTE_CASES +#undef INVALID_CASES +#undef CHECK_NAME_CASE +#undef CHECK_NAME_CASES +#undef CHECK_NMSTRT_CASE +#undef CHECK_NMSTRT_CASES + +#endif /* XML_TOK_IMPL_C */ diff --git a/XML/src/xmltok_impl.h b/XML/src/xmltok_impl.h index 94c7db617..da0ea60a6 100644 --- a/XML/src/xmltok_impl.h +++ b/XML/src/xmltok_impl.h @@ -1,46 +1,46 @@ -/* -Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd -See the file COPYING for copying permission. -*/ - -enum { - BT_NONXML, - BT_MALFORM, - BT_LT, - BT_AMP, - BT_RSQB, - BT_LEAD2, - BT_LEAD3, - BT_LEAD4, - BT_TRAIL, - BT_CR, - BT_LF, - BT_GT, - BT_QUOT, - BT_APOS, - BT_EQUALS, - BT_QUEST, - BT_EXCL, - BT_SOL, - BT_SEMI, - BT_NUM, - BT_LSQB, - BT_S, - BT_NMSTRT, - BT_COLON, - BT_HEX, - BT_DIGIT, - BT_NAME, - BT_MINUS, - BT_OTHER, /* known not to be a name or name start character */ - BT_NONASCII, /* might be a name or name start character */ - BT_PERCNT, - BT_LPAR, - BT_RPAR, - BT_AST, - BT_PLUS, - BT_COMMA, - BT_VERBAR -}; - -#include +/* +Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd +See the file COPYING for copying permission. +*/ + +enum { + BT_NONXML, + BT_MALFORM, + BT_LT, + BT_AMP, + BT_RSQB, + BT_LEAD2, + BT_LEAD3, + BT_LEAD4, + BT_TRAIL, + BT_CR, + BT_LF, + BT_GT, + BT_QUOT, + BT_APOS, + BT_EQUALS, + BT_QUEST, + BT_EXCL, + BT_SOL, + BT_SEMI, + BT_NUM, + BT_LSQB, + BT_S, + BT_NMSTRT, + BT_COLON, + BT_HEX, + BT_DIGIT, + BT_NAME, + BT_MINUS, + BT_OTHER, /* known not to be a name or name start character */ + BT_NONASCII, /* might be a name or name start character */ + BT_PERCNT, + BT_LPAR, + BT_RPAR, + BT_AST, + BT_PLUS, + BT_COMMA, + BT_VERBAR +}; + +#include diff --git a/XML/src/xmltok_ns.c b/XML/src/xmltok_ns.c index 6f4425616..c3b88fdf4 100644 --- a/XML/src/xmltok_ns.c +++ b/XML/src/xmltok_ns.c @@ -1,115 +1,115 @@ -/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd - See the file COPYING for copying permission. -*/ - -/* This file is included! */ -#ifdef XML_TOK_NS_C - -const ENCODING * -NS(XmlGetUtf8InternalEncoding)(void) -{ - return &ns(internal_utf8_encoding).enc; -} - -const ENCODING * -NS(XmlGetUtf16InternalEncoding)(void) -{ -#if BYTEORDER == 1234 - return &ns(internal_little2_encoding).enc; -#elif BYTEORDER == 4321 - return &ns(internal_big2_encoding).enc; -#else - const short n = 1; - return (*(const char *)&n - ? &ns(internal_little2_encoding).enc - : &ns(internal_big2_encoding).enc); -#endif -} - -static const ENCODING * const NS(encodings)[] = { - &ns(latin1_encoding).enc, - &ns(ascii_encoding).enc, - &ns(utf8_encoding).enc, - &ns(big2_encoding).enc, - &ns(big2_encoding).enc, - &ns(little2_encoding).enc, - &ns(utf8_encoding).enc /* NO_ENC */ -}; - -static int PTRCALL -NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - return initScan(NS(encodings), (const INIT_ENCODING *)enc, - XML_PROLOG_STATE, ptr, end, nextTokPtr); -} - -static int PTRCALL -NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - return initScan(NS(encodings), (const INIT_ENCODING *)enc, - XML_CONTENT_STATE, ptr, end, nextTokPtr); -} - -int -NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, - const char *name) -{ - int i = getEncodingIndex(name); - if (i == UNKNOWN_ENC) - return 0; - SET_INIT_ENC_INDEX(p, i); - p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); - p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); - p->initEnc.updatePosition = initUpdatePosition; - p->encPtr = encPtr; - *encPtr = &(p->initEnc); - return 1; -} - -static const ENCODING * -NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) -{ -#define ENCODING_MAX 128 - char buf[ENCODING_MAX]; - char *p = buf; - int i; - XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); - if (ptr != end) - return 0; - *p = 0; - if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) - return enc; - i = getEncodingIndex(buf); - if (i == UNKNOWN_ENC) - return 0; - return NS(encodings)[i]; -} - -int -NS(XmlParseXmlDecl)(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingName, - const ENCODING **encoding, - int *standalone) -{ - return doParseXmlDecl(NS(findEncoding), - isGeneralTextEntity, - enc, - ptr, - end, - badPtr, - versionPtr, - versionEndPtr, - encodingName, - encoding, - standalone); -} - -#endif /* XML_TOK_NS_C */ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* This file is included! */ +#ifdef XML_TOK_NS_C + +const ENCODING * +NS(XmlGetUtf8InternalEncoding)(void) +{ + return &ns(internal_utf8_encoding).enc; +} + +const ENCODING * +NS(XmlGetUtf16InternalEncoding)(void) +{ +#if BYTEORDER == 1234 + return &ns(internal_little2_encoding).enc; +#elif BYTEORDER == 4321 + return &ns(internal_big2_encoding).enc; +#else + const short n = 1; + return (*(const char *)&n + ? &ns(internal_little2_encoding).enc + : &ns(internal_big2_encoding).enc); +#endif +} + +static const ENCODING * const NS(encodings)[] = { + &ns(latin1_encoding).enc, + &ns(ascii_encoding).enc, + &ns(utf8_encoding).enc, + &ns(big2_encoding).enc, + &ns(big2_encoding).enc, + &ns(little2_encoding).enc, + &ns(utf8_encoding).enc /* NO_ENC */ +}; + +static int PTRCALL +NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_PROLOG_STATE, ptr, end, nextTokPtr); +} + +static int PTRCALL +NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_CONTENT_STATE, ptr, end, nextTokPtr); +} + +int +NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, + const char *name) +{ + int i = getEncodingIndex(name); + if (i == UNKNOWN_ENC) + return 0; + SET_INIT_ENC_INDEX(p, i); + p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); + p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); + p->initEnc.updatePosition = initUpdatePosition; + p->encPtr = encPtr; + *encPtr = &(p->initEnc); + return 1; +} + +static const ENCODING * +NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) +{ +#define ENCODING_MAX 128 + char buf[ENCODING_MAX]; + char *p = buf; + int i; + XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); + if (ptr != end) + return 0; + *p = 0; + if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) + return enc; + i = getEncodingIndex(buf); + if (i == UNKNOWN_ENC) + return 0; + return NS(encodings)[i]; +} + +int +NS(XmlParseXmlDecl)(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + return doParseXmlDecl(NS(findEncoding), + isGeneralTextEntity, + enc, + ptr, + end, + badPtr, + versionPtr, + versionEndPtr, + encodingName, + encoding, + standalone); +} + +#endif /* XML_TOK_NS_C */ diff --git a/XML/testsuite/TestSuite.vmsbuild b/XML/testsuite/TestSuite.vmsbuild index d7c295162..cceda5068 100644 --- a/XML/testsuite/TestSuite.vmsbuild +++ b/XML/testsuite/TestSuite.vmsbuild @@ -1,26 +1,26 @@ -# -# TestSuite.vmsbuild -# -# $Id: //poco/1.3/XML/testsuite/TestSuite.vmsbuild#1 $ -# -EXE=TestRunner -AttributesImplTest -ChildNodesTest -DOMTestSuite -DocumentTest -DocumentTypeTest -Driver -ElementTest -EventTest -NamePoolTest -NameTest -NamespaceSupportTest -NodeIteratorTest -NodeTest -ParserWriterTest -SAXParserTest -SAXTestSuite -TextTest -TreeWalkerTest -XMLTestSuite -XMLWriterTest +# +# TestSuite.vmsbuild +# +# $Id: //poco/1.3/XML/testsuite/TestSuite.vmsbuild#1 $ +# +EXE=TestRunner +AttributesImplTest +ChildNodesTest +DOMTestSuite +DocumentTest +DocumentTypeTest +Driver +ElementTest +EventTest +NamePoolTest +NameTest +NamespaceSupportTest +NodeIteratorTest +NodeTest +ParserWriterTest +SAXParserTest +SAXTestSuite +TextTest +TreeWalkerTest +XMLTestSuite +XMLWriterTest diff --git a/XML/testsuite/TestSuite_vs71.vcproj b/XML/testsuite/TestSuite_vs71.vcproj index 2fc5b0796..378dc2502 100644 --- a/XML/testsuite/TestSuite_vs71.vcproj +++ b/XML/testsuite/TestSuite_vs71.vcproj @@ -1,435 +1,435 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/testsuite/TestSuite_vs80.vcproj b/XML/testsuite/TestSuite_vs80.vcproj index a34f16cc1..72859bcbe 100644 --- a/XML/testsuite/TestSuite_vs80.vcproj +++ b/XML/testsuite/TestSuite_vs80.vcproj @@ -1,598 +1,598 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XML/testsuite/src/AttributesImplTest.cpp b/XML/testsuite/src/AttributesImplTest.cpp index ba4a3dfd7..44636d777 100644 --- a/XML/testsuite/src/AttributesImplTest.cpp +++ b/XML/testsuite/src/AttributesImplTest.cpp @@ -1,266 +1,266 @@ -// -// AttributesImplTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/AttributesImplTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "AttributesImplTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/SAX/AttributesImpl.h" - - -using Poco::XML::AttributesImpl; - - -AttributesImplTest::AttributesImplTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -AttributesImplTest::~AttributesImplTest() -{ -} - - -void AttributesImplTest::testNoNamespaces() -{ - AttributesImpl attrs; - - assert (attrs.getLength() == 0); - assert (attrs.getIndex("foo") == -1); - assert (attrs.getValue("foo").empty()); - - attrs.addAttribute("", "", "a1", "CDATA", "v1"); - assert (attrs.getLength() == 1); - assert (attrs.getIndex("a1") == 0); - assert (attrs.getQName(0) == "a1"); - assert (attrs.getType(0) == "CDATA"); - assert (attrs.getValue(0) == "v1"); - assert (attrs.isSpecified(0)); - - assert (attrs.getType("a1") == "CDATA"); - assert (attrs.getValue("a1") == "v1"); - - attrs.addAttribute("", "", "a2", "CDATA", "v2"); - assert (attrs.getLength() == 2); - assert (attrs.getIndex("a2") == 1); - assert (attrs.getQName(1) == "a2"); - assert (attrs.getType(1) == "CDATA"); - assert (attrs.getValue(1) == "v2"); - assert (attrs.isSpecified(1)); - - assert (attrs.getType("a2") == "CDATA"); - assert (attrs.getValue("a2") == "v2"); - - attrs.addAttribute("", "", "a3", "CDATA", "v3"); - assert (attrs.getLength() == 3); - assert (attrs.getIndex("a3") == 2); - assert (attrs.getValue("a3") == "v3"); - - attrs.removeAttribute(0); - assert (attrs.getLength() == 2); - assert (attrs.getIndex("a1") == -1); - assert (attrs.getIndex("a2") == 0); - assert (attrs.getIndex("a3") == 1); - assert (attrs.getQName(0) == "a2"); - assert (attrs.getQName(1) == "a3"); - - attrs.removeAttribute("a3"); - assert (attrs.getLength() == 1); - assert (attrs.getIndex("a1") == -1); - assert (attrs.getIndex("a2") == 0); - assert (attrs.getIndex("a3") == -1); - assert (attrs.getQName(0) == "a2"); -} - - -void AttributesImplTest::testNamespaces() -{ - AttributesImpl attrs; - - assert (attrs.getLength() == 0); - assert (attrs.getIndex("urn:ns", "foo") == -1); - assert (attrs.getValue("urn:ns", "foo").empty()); - - attrs.addAttribute("urn:ns", "a1", "p:a1", "CDATA", "v1"); - assert (attrs.getLength() == 1); - assert (attrs.getIndex("urn:ns", "a1") == 0); - assert (attrs.getQName(0) == "p:a1"); - assert (attrs.getLocalName(0) == "a1"); - assert (attrs.getURI(0) == "urn:ns"); - assert (attrs.getType(0) == "CDATA"); - assert (attrs.getValue(0) == "v1"); - assert (attrs.isSpecified(0)); - - assert (attrs.getType("urn:ns", "a1") == "CDATA"); - assert (attrs.getValue("urn:ns", "a1") == "v1"); - - attrs.addAttribute("urn:ns", "a2", "p:a2", "CDATA", "v2"); - assert (attrs.getLength() == 2); - assert (attrs.getIndex("urn:ns", "a2") == 1); - assert (attrs.getQName(1) == "p:a2"); - assert (attrs.getLocalName(1) == "a2"); - assert (attrs.getURI(1) == "urn:ns"); - assert (attrs.getType(1) == "CDATA"); - assert (attrs.getValue(1) == "v2"); - assert (attrs.isSpecified(1)); - - assert (attrs.getType("urn:ns", "a2") == "CDATA"); - assert (attrs.getValue("urn:ns", "a2") == "v2"); - - assert (attrs.getIndex("urn:ns2", "a2") == -1); - - attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3"); - assert (attrs.getLength() == 3); - assert (attrs.getIndex("urn:ns2", "a3") == 2); - assert (attrs.getValue("urn:ns2", "a3") == "v3"); - - attrs.removeAttribute(0); - assert (attrs.getLength() == 2); - assert (attrs.getIndex("urn:ns", "a1") == -1); - assert (attrs.getIndex("urn:ns", "a2") == 0); - assert (attrs.getIndex("urn:ns2", "a3") == 1); - assert (attrs.getQName(0) == "p:a2"); - assert (attrs.getLocalName(0) == "a2"); - assert (attrs.getURI(0) == "urn:ns"); - assert (attrs.getQName(1) == "q:a3"); - assert (attrs.getLocalName(1) == "a3"); - assert (attrs.getURI(1) == "urn:ns2"); - - attrs.removeAttribute("urn:ns", "a3"); - assert (attrs.getLength() == 2); - - attrs.removeAttribute("urn:ns2", "a3"); - assert (attrs.getLength() == 1); - assert (attrs.getIndex("urn:ns", "a1") == -1); - assert (attrs.getIndex("urn:ns", "a2") == 0); - assert (attrs.getIndex("urn:ns2", "a3") == -1); - assert (attrs.getQName(0) == "p:a2"); -} - - -void AttributesImplTest::testAccessors() -{ - AttributesImpl attrs; - attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1"); - attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2", false); - attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3", true); - - assert (attrs.getQName(0) == "p:a1"); - assert (attrs.getQName(1) == "p:a2"); - assert (attrs.getQName(2) == "q:a3"); - - assert (attrs.getLocalName(0) == "a1"); - assert (attrs.getLocalName(1) == "a2"); - assert (attrs.getLocalName(2) == "a3"); - - assert (attrs.getURI(0) == "urn:ns1"); - assert (attrs.getURI(1) == "urn:ns1"); - assert (attrs.getURI(2) == "urn:ns2"); - - assert (attrs.getValue(0) == "v1"); - assert (attrs.getValue(1) == "v2"); - assert (attrs.getValue(2) == "v3"); - - assert (attrs.isSpecified(0)); - assert (!attrs.isSpecified(1)); - assert (attrs.isSpecified(2)); - - attrs.setType(0, "NMTOKEN"); - assert (attrs.getType(0) == "NMTOKEN"); - assert (attrs.getType("urn:ns1", "a1") == "NMTOKEN"); - - attrs.setValue(1, "v2 v2"); - assert (attrs.getValue(1) == "v2 v2"); - assert (attrs.getValue("urn:ns1", "a2") == "v2 v2"); - assert (attrs.isSpecified(1)); - - attrs.setLocalName(2, "A3"); - assert (attrs.getLocalName(2) == "A3"); - attrs.setQName(2, "p:A3"); - assert (attrs.getQName(2) == "p:A3"); - attrs.setURI(2, "urn:ns1"); - assert (attrs.getURI(2) == "urn:ns1"); - - assert (attrs.getValue("urn:ns1", "A3") == "v3"); -} - - -void AttributesImplTest::testCopy() -{ - AttributesImpl attrs; - attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1"); - attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2"); - attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3"); - - AttributesImpl attrs2; - attrs2.setAttributes(attrs); - - assert (attrs2.getLength() == 3); - - assert (attrs2.getQName(0) == "p:a1"); - assert (attrs2.getQName(1) == "p:a2"); - assert (attrs2.getQName(2) == "q:a3"); - - assert (attrs2.getLocalName(0) == "a1"); - assert (attrs2.getLocalName(1) == "a2"); - assert (attrs2.getLocalName(2) == "a3"); - - assert (attrs2.getURI(0) == "urn:ns1"); - assert (attrs2.getURI(1) == "urn:ns1"); - assert (attrs2.getURI(2) == "urn:ns2"); - - assert (attrs2.getValue(0) == "v1"); - assert (attrs2.getValue(1) == "v2"); - assert (attrs2.getValue(2) == "v3"); -} - - -void AttributesImplTest::setUp() -{ -} - - -void AttributesImplTest::tearDown() -{ -} - - -CppUnit::Test* AttributesImplTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesImplTest"); - - CppUnit_addTest(pSuite, AttributesImplTest, testNoNamespaces); - CppUnit_addTest(pSuite, AttributesImplTest, testNamespaces); - CppUnit_addTest(pSuite, AttributesImplTest, testAccessors); - CppUnit_addTest(pSuite, AttributesImplTest, testCopy); - - return pSuite; -} +// +// AttributesImplTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/AttributesImplTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "AttributesImplTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/SAX/AttributesImpl.h" + + +using Poco::XML::AttributesImpl; + + +AttributesImplTest::AttributesImplTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +AttributesImplTest::~AttributesImplTest() +{ +} + + +void AttributesImplTest::testNoNamespaces() +{ + AttributesImpl attrs; + + assert (attrs.getLength() == 0); + assert (attrs.getIndex("foo") == -1); + assert (attrs.getValue("foo").empty()); + + attrs.addAttribute("", "", "a1", "CDATA", "v1"); + assert (attrs.getLength() == 1); + assert (attrs.getIndex("a1") == 0); + assert (attrs.getQName(0) == "a1"); + assert (attrs.getType(0) == "CDATA"); + assert (attrs.getValue(0) == "v1"); + assert (attrs.isSpecified(0)); + + assert (attrs.getType("a1") == "CDATA"); + assert (attrs.getValue("a1") == "v1"); + + attrs.addAttribute("", "", "a2", "CDATA", "v2"); + assert (attrs.getLength() == 2); + assert (attrs.getIndex("a2") == 1); + assert (attrs.getQName(1) == "a2"); + assert (attrs.getType(1) == "CDATA"); + assert (attrs.getValue(1) == "v2"); + assert (attrs.isSpecified(1)); + + assert (attrs.getType("a2") == "CDATA"); + assert (attrs.getValue("a2") == "v2"); + + attrs.addAttribute("", "", "a3", "CDATA", "v3"); + assert (attrs.getLength() == 3); + assert (attrs.getIndex("a3") == 2); + assert (attrs.getValue("a3") == "v3"); + + attrs.removeAttribute(0); + assert (attrs.getLength() == 2); + assert (attrs.getIndex("a1") == -1); + assert (attrs.getIndex("a2") == 0); + assert (attrs.getIndex("a3") == 1); + assert (attrs.getQName(0) == "a2"); + assert (attrs.getQName(1) == "a3"); + + attrs.removeAttribute("a3"); + assert (attrs.getLength() == 1); + assert (attrs.getIndex("a1") == -1); + assert (attrs.getIndex("a2") == 0); + assert (attrs.getIndex("a3") == -1); + assert (attrs.getQName(0) == "a2"); +} + + +void AttributesImplTest::testNamespaces() +{ + AttributesImpl attrs; + + assert (attrs.getLength() == 0); + assert (attrs.getIndex("urn:ns", "foo") == -1); + assert (attrs.getValue("urn:ns", "foo").empty()); + + attrs.addAttribute("urn:ns", "a1", "p:a1", "CDATA", "v1"); + assert (attrs.getLength() == 1); + assert (attrs.getIndex("urn:ns", "a1") == 0); + assert (attrs.getQName(0) == "p:a1"); + assert (attrs.getLocalName(0) == "a1"); + assert (attrs.getURI(0) == "urn:ns"); + assert (attrs.getType(0) == "CDATA"); + assert (attrs.getValue(0) == "v1"); + assert (attrs.isSpecified(0)); + + assert (attrs.getType("urn:ns", "a1") == "CDATA"); + assert (attrs.getValue("urn:ns", "a1") == "v1"); + + attrs.addAttribute("urn:ns", "a2", "p:a2", "CDATA", "v2"); + assert (attrs.getLength() == 2); + assert (attrs.getIndex("urn:ns", "a2") == 1); + assert (attrs.getQName(1) == "p:a2"); + assert (attrs.getLocalName(1) == "a2"); + assert (attrs.getURI(1) == "urn:ns"); + assert (attrs.getType(1) == "CDATA"); + assert (attrs.getValue(1) == "v2"); + assert (attrs.isSpecified(1)); + + assert (attrs.getType("urn:ns", "a2") == "CDATA"); + assert (attrs.getValue("urn:ns", "a2") == "v2"); + + assert (attrs.getIndex("urn:ns2", "a2") == -1); + + attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3"); + assert (attrs.getLength() == 3); + assert (attrs.getIndex("urn:ns2", "a3") == 2); + assert (attrs.getValue("urn:ns2", "a3") == "v3"); + + attrs.removeAttribute(0); + assert (attrs.getLength() == 2); + assert (attrs.getIndex("urn:ns", "a1") == -1); + assert (attrs.getIndex("urn:ns", "a2") == 0); + assert (attrs.getIndex("urn:ns2", "a3") == 1); + assert (attrs.getQName(0) == "p:a2"); + assert (attrs.getLocalName(0) == "a2"); + assert (attrs.getURI(0) == "urn:ns"); + assert (attrs.getQName(1) == "q:a3"); + assert (attrs.getLocalName(1) == "a3"); + assert (attrs.getURI(1) == "urn:ns2"); + + attrs.removeAttribute("urn:ns", "a3"); + assert (attrs.getLength() == 2); + + attrs.removeAttribute("urn:ns2", "a3"); + assert (attrs.getLength() == 1); + assert (attrs.getIndex("urn:ns", "a1") == -1); + assert (attrs.getIndex("urn:ns", "a2") == 0); + assert (attrs.getIndex("urn:ns2", "a3") == -1); + assert (attrs.getQName(0) == "p:a2"); +} + + +void AttributesImplTest::testAccessors() +{ + AttributesImpl attrs; + attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1"); + attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2", false); + attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3", true); + + assert (attrs.getQName(0) == "p:a1"); + assert (attrs.getQName(1) == "p:a2"); + assert (attrs.getQName(2) == "q:a3"); + + assert (attrs.getLocalName(0) == "a1"); + assert (attrs.getLocalName(1) == "a2"); + assert (attrs.getLocalName(2) == "a3"); + + assert (attrs.getURI(0) == "urn:ns1"); + assert (attrs.getURI(1) == "urn:ns1"); + assert (attrs.getURI(2) == "urn:ns2"); + + assert (attrs.getValue(0) == "v1"); + assert (attrs.getValue(1) == "v2"); + assert (attrs.getValue(2) == "v3"); + + assert (attrs.isSpecified(0)); + assert (!attrs.isSpecified(1)); + assert (attrs.isSpecified(2)); + + attrs.setType(0, "NMTOKEN"); + assert (attrs.getType(0) == "NMTOKEN"); + assert (attrs.getType("urn:ns1", "a1") == "NMTOKEN"); + + attrs.setValue(1, "v2 v2"); + assert (attrs.getValue(1) == "v2 v2"); + assert (attrs.getValue("urn:ns1", "a2") == "v2 v2"); + assert (attrs.isSpecified(1)); + + attrs.setLocalName(2, "A3"); + assert (attrs.getLocalName(2) == "A3"); + attrs.setQName(2, "p:A3"); + assert (attrs.getQName(2) == "p:A3"); + attrs.setURI(2, "urn:ns1"); + assert (attrs.getURI(2) == "urn:ns1"); + + assert (attrs.getValue("urn:ns1", "A3") == "v3"); +} + + +void AttributesImplTest::testCopy() +{ + AttributesImpl attrs; + attrs.addAttribute("urn:ns1", "a1", "p:a1", "CDATA", "v1"); + attrs.addAttribute("urn:ns1", "a2", "p:a2", "CDATA", "v2"); + attrs.addAttribute("urn:ns2", "a3", "q:a3", "CDATA", "v3"); + + AttributesImpl attrs2; + attrs2.setAttributes(attrs); + + assert (attrs2.getLength() == 3); + + assert (attrs2.getQName(0) == "p:a1"); + assert (attrs2.getQName(1) == "p:a2"); + assert (attrs2.getQName(2) == "q:a3"); + + assert (attrs2.getLocalName(0) == "a1"); + assert (attrs2.getLocalName(1) == "a2"); + assert (attrs2.getLocalName(2) == "a3"); + + assert (attrs2.getURI(0) == "urn:ns1"); + assert (attrs2.getURI(1) == "urn:ns1"); + assert (attrs2.getURI(2) == "urn:ns2"); + + assert (attrs2.getValue(0) == "v1"); + assert (attrs2.getValue(1) == "v2"); + assert (attrs2.getValue(2) == "v3"); +} + + +void AttributesImplTest::setUp() +{ +} + + +void AttributesImplTest::tearDown() +{ +} + + +CppUnit::Test* AttributesImplTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesImplTest"); + + CppUnit_addTest(pSuite, AttributesImplTest, testNoNamespaces); + CppUnit_addTest(pSuite, AttributesImplTest, testNamespaces); + CppUnit_addTest(pSuite, AttributesImplTest, testAccessors); + CppUnit_addTest(pSuite, AttributesImplTest, testCopy); + + return pSuite; +} diff --git a/XML/testsuite/src/AttributesImplTest.h b/XML/testsuite/src/AttributesImplTest.h index da1d81664..056b2e115 100644 --- a/XML/testsuite/src/AttributesImplTest.h +++ b/XML/testsuite/src/AttributesImplTest.h @@ -1,63 +1,63 @@ -// -// AttributesImplTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/AttributesImplTest.h#1 $ -// -// Definition of the AttributesImplTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef AttributesImplTest_INCLUDED -#define AttributesImplTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class AttributesImplTest: public CppUnit::TestCase -{ -public: - AttributesImplTest(const std::string& name); - ~AttributesImplTest(); - - void testNoNamespaces(); - void testNamespaces(); - void testAccessors(); - void testCopy(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // AttributesImplTest_INCLUDED +// +// AttributesImplTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/AttributesImplTest.h#1 $ +// +// Definition of the AttributesImplTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef AttributesImplTest_INCLUDED +#define AttributesImplTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class AttributesImplTest: public CppUnit::TestCase +{ +public: + AttributesImplTest(const std::string& name); + ~AttributesImplTest(); + + void testNoNamespaces(); + void testNamespaces(); + void testAccessors(); + void testCopy(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // AttributesImplTest_INCLUDED diff --git a/XML/testsuite/src/ChildNodesTest.cpp b/XML/testsuite/src/ChildNodesTest.cpp index b73aad590..0fcb8ec16 100644 --- a/XML/testsuite/src/ChildNodesTest.cpp +++ b/XML/testsuite/src/ChildNodesTest.cpp @@ -1,124 +1,124 @@ -// -// ChildNodesTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/ChildNodesTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "ChildNodesTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/NodeList.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::NodeList; -using Poco::XML::Node; -using Poco::XML::AutoPtr; - - -ChildNodesTest::ChildNodesTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -ChildNodesTest::~ChildNodesTest() -{ -} - - -void ChildNodesTest::testChildNodes() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - assert (!pRoot->hasChildNodes()); - AutoPtr pNL = pRoot->childNodes(); - assert (pNL->length() == 0); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - assert (pRoot->hasChildNodes()); - - assert (pNL->length() == 1); - assert (pNL->item(0) == pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - assert (pNL->length() == 2); - assert (pNL->item(0) == pChild1); - assert (pNL->item(1) == pChild2); - - AutoPtr pChild0 = pDoc->createElement("child0"); - pRoot->insertBefore(pChild0, pChild1); - - assert (pNL->length() == 3); - assert (pNL->item(0) == pChild0); - assert (pNL->item(1) == pChild1); - assert (pNL->item(2) == pChild2); - - pRoot->removeChild(pChild1); - assert (pNL->length() == 2); - assert (pNL->item(0) == pChild0); - assert (pNL->item(1) == pChild2); - - pRoot->removeChild(pChild0); - assert (pNL->length() == 1); - assert (pNL->item(0) == pChild2); - - pRoot->removeChild(pChild2); - assert (pNL->length() == 0); - assert (pNL->item(0) == 0); - - assert (!pRoot->hasChildNodes()); -} - - -void ChildNodesTest::setUp() -{ -} - - -void ChildNodesTest::tearDown() -{ -} - - -CppUnit::Test* ChildNodesTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ChildNodesTest"); - - CppUnit_addTest(pSuite, ChildNodesTest, testChildNodes); - - return pSuite; -} +// +// ChildNodesTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/ChildNodesTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "ChildNodesTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/NodeList.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::NodeList; +using Poco::XML::Node; +using Poco::XML::AutoPtr; + + +ChildNodesTest::ChildNodesTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +ChildNodesTest::~ChildNodesTest() +{ +} + + +void ChildNodesTest::testChildNodes() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + assert (!pRoot->hasChildNodes()); + AutoPtr pNL = pRoot->childNodes(); + assert (pNL->length() == 0); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + assert (pRoot->hasChildNodes()); + + assert (pNL->length() == 1); + assert (pNL->item(0) == pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + assert (pNL->length() == 2); + assert (pNL->item(0) == pChild1); + assert (pNL->item(1) == pChild2); + + AutoPtr pChild0 = pDoc->createElement("child0"); + pRoot->insertBefore(pChild0, pChild1); + + assert (pNL->length() == 3); + assert (pNL->item(0) == pChild0); + assert (pNL->item(1) == pChild1); + assert (pNL->item(2) == pChild2); + + pRoot->removeChild(pChild1); + assert (pNL->length() == 2); + assert (pNL->item(0) == pChild0); + assert (pNL->item(1) == pChild2); + + pRoot->removeChild(pChild0); + assert (pNL->length() == 1); + assert (pNL->item(0) == pChild2); + + pRoot->removeChild(pChild2); + assert (pNL->length() == 0); + assert (pNL->item(0) == 0); + + assert (!pRoot->hasChildNodes()); +} + + +void ChildNodesTest::setUp() +{ +} + + +void ChildNodesTest::tearDown() +{ +} + + +CppUnit::Test* ChildNodesTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ChildNodesTest"); + + CppUnit_addTest(pSuite, ChildNodesTest, testChildNodes); + + return pSuite; +} diff --git a/XML/testsuite/src/ChildNodesTest.h b/XML/testsuite/src/ChildNodesTest.h index d0d8e64d5..b183f2839 100644 --- a/XML/testsuite/src/ChildNodesTest.h +++ b/XML/testsuite/src/ChildNodesTest.h @@ -1,60 +1,60 @@ -// -// ChildNodesTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/ChildNodesTest.h#1 $ -// -// Definition of the ChildNodesTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef ChildNodesTest_INCLUDED -#define ChildNodesTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class ChildNodesTest: public CppUnit::TestCase -{ -public: - ChildNodesTest(const std::string& name); - ~ChildNodesTest(); - - void testChildNodes(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // ChildNodesTest_INCLUDED +// +// ChildNodesTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/ChildNodesTest.h#1 $ +// +// Definition of the ChildNodesTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef ChildNodesTest_INCLUDED +#define ChildNodesTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class ChildNodesTest: public CppUnit::TestCase +{ +public: + ChildNodesTest(const std::string& name); + ~ChildNodesTest(); + + void testChildNodes(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // ChildNodesTest_INCLUDED diff --git a/XML/testsuite/src/DOMTestSuite.cpp b/XML/testsuite/src/DOMTestSuite.cpp index 6fec58a15..0b4144201 100644 --- a/XML/testsuite/src/DOMTestSuite.cpp +++ b/XML/testsuite/src/DOMTestSuite.cpp @@ -1,64 +1,64 @@ -// -// DOMTestSuite.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/DOMTestSuite.cpp#2 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "DOMTestSuite.h" -#include "NodeTest.h" -#include "ChildNodesTest.h" -#include "ElementTest.h" -#include "TextTest.h" -#include "DocumentTest.h" -#include "DocumentTypeTest.h" -#include "EventTest.h" -#include "NodeIteratorTest.h" -#include "TreeWalkerTest.h" -#include "ParserWriterTest.h" -#include "NodeAppenderTest.h" - - -CppUnit::Test* DOMTestSuite::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DOMTestSuite"); - - pSuite->addTest(NodeTest::suite()); - pSuite->addTest(ChildNodesTest::suite()); - pSuite->addTest(ElementTest::suite()); - pSuite->addTest(TextTest::suite()); - pSuite->addTest(DocumentTest::suite()); - pSuite->addTest(DocumentTypeTest::suite()); - pSuite->addTest(EventTest::suite()); - pSuite->addTest(NodeIteratorTest::suite()); - pSuite->addTest(TreeWalkerTest::suite()); - pSuite->addTest(ParserWriterTest::suite()); - pSuite->addTest(NodeAppenderTest::suite()); - - return pSuite; -} +// +// DOMTestSuite.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/DOMTestSuite.cpp#2 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "DOMTestSuite.h" +#include "NodeTest.h" +#include "ChildNodesTest.h" +#include "ElementTest.h" +#include "TextTest.h" +#include "DocumentTest.h" +#include "DocumentTypeTest.h" +#include "EventTest.h" +#include "NodeIteratorTest.h" +#include "TreeWalkerTest.h" +#include "ParserWriterTest.h" +#include "NodeAppenderTest.h" + + +CppUnit::Test* DOMTestSuite::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DOMTestSuite"); + + pSuite->addTest(NodeTest::suite()); + pSuite->addTest(ChildNodesTest::suite()); + pSuite->addTest(ElementTest::suite()); + pSuite->addTest(TextTest::suite()); + pSuite->addTest(DocumentTest::suite()); + pSuite->addTest(DocumentTypeTest::suite()); + pSuite->addTest(EventTest::suite()); + pSuite->addTest(NodeIteratorTest::suite()); + pSuite->addTest(TreeWalkerTest::suite()); + pSuite->addTest(ParserWriterTest::suite()); + pSuite->addTest(NodeAppenderTest::suite()); + + return pSuite; +} diff --git a/XML/testsuite/src/DOMTestSuite.h b/XML/testsuite/src/DOMTestSuite.h index f9698186e..c87bd26fc 100644 --- a/XML/testsuite/src/DOMTestSuite.h +++ b/XML/testsuite/src/DOMTestSuite.h @@ -1,49 +1,49 @@ -// -// DOMTestSuite.h -// -// $Id: //poco/1.3/XML/testsuite/src/DOMTestSuite.h#1 $ -// -// Definition of the DOMTestSuite class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DOMTestSuite_INCLUDED -#define DOMTestSuite_INCLUDED - - -#include "CppUnit/TestSuite.h" - - -class DOMTestSuite -{ -public: - static CppUnit::Test* suite(); -}; - - -#endif // DOMTestSuite_INCLUDED +// +// DOMTestSuite.h +// +// $Id: //poco/1.3/XML/testsuite/src/DOMTestSuite.h#1 $ +// +// Definition of the DOMTestSuite class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DOMTestSuite_INCLUDED +#define DOMTestSuite_INCLUDED + + +#include "CppUnit/TestSuite.h" + + +class DOMTestSuite +{ +public: + static CppUnit::Test* suite(); +}; + + +#endif // DOMTestSuite_INCLUDED diff --git a/XML/testsuite/src/DocumentTest.cpp b/XML/testsuite/src/DocumentTest.cpp index bedc1309c..7e026e34c 100644 --- a/XML/testsuite/src/DocumentTest.cpp +++ b/XML/testsuite/src/DocumentTest.cpp @@ -1,310 +1,310 @@ -// -// DocumentTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/DocumentTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "DocumentTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/NodeList.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/DOM/DOMException.h" - - -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::Text; -using Poco::XML::Node; -using Poco::XML::NodeList; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; -using Poco::XML::DOMException; - - -DocumentTest::DocumentTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -DocumentTest::~DocumentTest() -{ -} - - -void DocumentTest::testDocumentElement() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - assert (pDoc->documentElement() == 0); - pDoc->appendChild(pRoot); - assert (pDoc->documentElement() == pRoot); - - AutoPtr pText = pDoc->createTextNode(" "); - pDoc->insertBefore(pText, pRoot); - assert (pDoc->documentElement() == pRoot); - -} - - -void DocumentTest::testImport() -{ - AutoPtr pDoc1 = new Document; - AutoPtr pRoot1 = pDoc1->createElement("root"); - - AutoPtr pDoc2 = new Document; - - try - { - pDoc2->appendChild(pRoot1); - fail("wrong document - must throw exception"); - } - catch (DOMException&) - { - } - - AutoPtr pRoot2 = static_cast(pDoc2->importNode(pRoot1, false)); - assert (pRoot2->ownerDocument() == pDoc2); - assert (pRoot1->ownerDocument() == pDoc1); - - pDoc2->appendChild(pRoot2); -} - - -void DocumentTest::testImportDeep() -{ - AutoPtr pDoc1 = new Document; - AutoPtr pRoot1 = pDoc1->createElement("root"); - AutoPtr pElem1 = pDoc1->createElement("elem"); - AutoPtr pText1 = pDoc1->createTextNode("text"); - - pElem1->appendChild(pText1); - pRoot1->appendChild(pElem1); - - pRoot1->setAttribute("a1", "v1"); - pRoot1->setAttribute("a2", "v2"); - - AutoPtr pDoc2 = new Document; - - try - { - pDoc2->appendChild(pRoot1); - fail("wrong document - must throw exception"); - } - catch (DOMException&) - { - } - - AutoPtr pRoot2 = static_cast(pDoc2->importNode(pRoot1, true)); - assert (pRoot2->ownerDocument() == pDoc2); - assert (pRoot2->firstChild()->ownerDocument() == pDoc2); - assert (pRoot2->firstChild()->firstChild()->ownerDocument() == pDoc2); - assert (pRoot1->ownerDocument() == pDoc1); - assert (pRoot1->firstChild()->ownerDocument() == pDoc1); - assert (pRoot1->firstChild()->firstChild()->ownerDocument() == pDoc1); - - pDoc2->appendChild(pRoot2); -} - - -void DocumentTest::testElementsByTagName() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - pDoc->appendChild(pRoot); - AutoPtr pNL1 = pDoc->getElementsByTagName("*"); - AutoPtr pNL2 = pDoc->getElementsByTagName("elem"); - - assert (pNL1->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL2->length() == 0); - - AutoPtr pElem1 = pDoc->createElement("elem"); - pRoot->appendChild(pElem1); - - assert (pNL1->length() == 2); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL1->item(1) == pElem1); - assert (pNL2->item(0) == pElem1); - - AutoPtr pElem2 = pDoc->createElement("Elem"); - pRoot->appendChild(pElem2); - - assert (pNL1->length() == 3); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL1->item(1) == pElem1); - assert (pNL1->item(2) == pElem2); - assert (pNL2->item(0) == pElem1); -} - - -void DocumentTest::testElementsByTagNameNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); - pDoc->appendChild(pRoot); - AutoPtr pNL1 = pDoc->getElementsByTagNameNS("*", "*"); - AutoPtr pNL2 = pDoc->getElementsByTagNameNS("*", "elem"); - - assert (pNL1->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL2->length() == 0); - - AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); - pRoot->appendChild(pElem1); - - assert (pNL1->length() == 2); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL1->item(1) == pElem1); - assert (pNL2->item(0) == pElem1); - - AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "Elem"); - pRoot->appendChild(pElem2); - - assert (pNL1->length() == 3); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pRoot); - assert (pNL1->item(1) == pElem1); - assert (pNL1->item(2) == pElem2); - assert (pNL2->item(0) == pElem1); -} - - -void DocumentTest::testElementById() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - pRoot->setAttribute("id", "0"); - AutoPtr pElem1 = pDoc->createElement("elem"); - pElem1->setAttribute("id", "1"); - AutoPtr pText1 = pDoc->createTextNode("text"); - AutoPtr pElem2 = pDoc->createElement("elem"); - pElem2->setAttribute("id", "2"); - AutoPtr pElem3 = pDoc->createElement("elem"); - pElem3->setAttribute("id", "3"); - - pElem1->appendChild(pText1); - pElem1->appendChild(pElem2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem3); - pDoc->appendChild(pRoot); - - Element* pFound = pDoc->getElementById("0", "id"); - assert (pFound == pRoot); - - pFound = pDoc->getElementById("1", "id"); - assert (pFound == pElem1); - - pFound = pDoc->getElementById("2", "id"); - assert (pFound == pElem2); - - pFound = pDoc->getElementById("3", "id"); - assert (pFound == pElem3); - - pFound = pDoc->getElementById("4", "id"); - assert (pFound == 0); - - pFound = pDoc->getElementById("0", "ID"); - assert (pFound == 0); -} - - -void DocumentTest::testElementByIdNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); - pRoot->setAttributeNS("urn:ns1", "id", "0"); - AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); - pElem1->setAttributeNS("urn:ns1", "id", "1"); - AutoPtr pText1 = pDoc->createTextNode("text"); - AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "elem"); - pElem2->setAttributeNS("urn:ns1", "id", "2"); - AutoPtr pElem3 = pDoc->createElementNS("urn:ns1", "elem"); - pElem3->setAttributeNS("urn:ns1", "id", "3"); - - pElem1->appendChild(pText1); - pElem1->appendChild(pElem2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem3); - pDoc->appendChild(pRoot); - - Element* pFound = pDoc->getElementByIdNS("0", "urn:ns1", "id"); - assert (pFound == pRoot); - - pFound = pDoc->getElementByIdNS("1", "urn:ns1", "id"); - assert (pFound == pElem1); - - pFound = pDoc->getElementByIdNS("2", "urn:ns1", "id"); - assert (pFound == pElem2); - - pFound = pDoc->getElementByIdNS("3", "urn:ns1", "id"); - assert (pFound == pElem3); - - pFound = pDoc->getElementByIdNS("4", "urn:ns1", "id"); - assert (pFound == 0); - - pFound = pDoc->getElementByIdNS("0", "urn:ns1", "ID"); - assert (pFound == 0); - - pFound = pDoc->getElementByIdNS("0", "urn:ns2", "id"); - assert (pFound == 0); -} - - -void DocumentTest::setUp() -{ -} - - -void DocumentTest::tearDown() -{ -} - - -CppUnit::Test* DocumentTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTest"); - - CppUnit_addTest(pSuite, DocumentTest, testDocumentElement); - CppUnit_addTest(pSuite, DocumentTest, testImport); - CppUnit_addTest(pSuite, DocumentTest, testImportDeep); - CppUnit_addTest(pSuite, DocumentTest, testElementsByTagName); - CppUnit_addTest(pSuite, DocumentTest, testElementsByTagNameNS); - CppUnit_addTest(pSuite, DocumentTest, testElementById); - CppUnit_addTest(pSuite, DocumentTest, testElementByIdNS); - - return pSuite; -} +// +// DocumentTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/DocumentTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "DocumentTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/NodeList.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/DOM/DOMException.h" + + +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::Text; +using Poco::XML::Node; +using Poco::XML::NodeList; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; +using Poco::XML::DOMException; + + +DocumentTest::DocumentTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +DocumentTest::~DocumentTest() +{ +} + + +void DocumentTest::testDocumentElement() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + assert (pDoc->documentElement() == 0); + pDoc->appendChild(pRoot); + assert (pDoc->documentElement() == pRoot); + + AutoPtr pText = pDoc->createTextNode(" "); + pDoc->insertBefore(pText, pRoot); + assert (pDoc->documentElement() == pRoot); + +} + + +void DocumentTest::testImport() +{ + AutoPtr pDoc1 = new Document; + AutoPtr pRoot1 = pDoc1->createElement("root"); + + AutoPtr pDoc2 = new Document; + + try + { + pDoc2->appendChild(pRoot1); + fail("wrong document - must throw exception"); + } + catch (DOMException&) + { + } + + AutoPtr pRoot2 = static_cast(pDoc2->importNode(pRoot1, false)); + assert (pRoot2->ownerDocument() == pDoc2); + assert (pRoot1->ownerDocument() == pDoc1); + + pDoc2->appendChild(pRoot2); +} + + +void DocumentTest::testImportDeep() +{ + AutoPtr pDoc1 = new Document; + AutoPtr pRoot1 = pDoc1->createElement("root"); + AutoPtr pElem1 = pDoc1->createElement("elem"); + AutoPtr pText1 = pDoc1->createTextNode("text"); + + pElem1->appendChild(pText1); + pRoot1->appendChild(pElem1); + + pRoot1->setAttribute("a1", "v1"); + pRoot1->setAttribute("a2", "v2"); + + AutoPtr pDoc2 = new Document; + + try + { + pDoc2->appendChild(pRoot1); + fail("wrong document - must throw exception"); + } + catch (DOMException&) + { + } + + AutoPtr pRoot2 = static_cast(pDoc2->importNode(pRoot1, true)); + assert (pRoot2->ownerDocument() == pDoc2); + assert (pRoot2->firstChild()->ownerDocument() == pDoc2); + assert (pRoot2->firstChild()->firstChild()->ownerDocument() == pDoc2); + assert (pRoot1->ownerDocument() == pDoc1); + assert (pRoot1->firstChild()->ownerDocument() == pDoc1); + assert (pRoot1->firstChild()->firstChild()->ownerDocument() == pDoc1); + + pDoc2->appendChild(pRoot2); +} + + +void DocumentTest::testElementsByTagName() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + pDoc->appendChild(pRoot); + AutoPtr pNL1 = pDoc->getElementsByTagName("*"); + AutoPtr pNL2 = pDoc->getElementsByTagName("elem"); + + assert (pNL1->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL2->length() == 0); + + AutoPtr pElem1 = pDoc->createElement("elem"); + pRoot->appendChild(pElem1); + + assert (pNL1->length() == 2); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL1->item(1) == pElem1); + assert (pNL2->item(0) == pElem1); + + AutoPtr pElem2 = pDoc->createElement("Elem"); + pRoot->appendChild(pElem2); + + assert (pNL1->length() == 3); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL1->item(1) == pElem1); + assert (pNL1->item(2) == pElem2); + assert (pNL2->item(0) == pElem1); +} + + +void DocumentTest::testElementsByTagNameNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); + pDoc->appendChild(pRoot); + AutoPtr pNL1 = pDoc->getElementsByTagNameNS("*", "*"); + AutoPtr pNL2 = pDoc->getElementsByTagNameNS("*", "elem"); + + assert (pNL1->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL2->length() == 0); + + AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); + pRoot->appendChild(pElem1); + + assert (pNL1->length() == 2); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL1->item(1) == pElem1); + assert (pNL2->item(0) == pElem1); + + AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "Elem"); + pRoot->appendChild(pElem2); + + assert (pNL1->length() == 3); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pRoot); + assert (pNL1->item(1) == pElem1); + assert (pNL1->item(2) == pElem2); + assert (pNL2->item(0) == pElem1); +} + + +void DocumentTest::testElementById() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + pRoot->setAttribute("id", "0"); + AutoPtr pElem1 = pDoc->createElement("elem"); + pElem1->setAttribute("id", "1"); + AutoPtr pText1 = pDoc->createTextNode("text"); + AutoPtr pElem2 = pDoc->createElement("elem"); + pElem2->setAttribute("id", "2"); + AutoPtr pElem3 = pDoc->createElement("elem"); + pElem3->setAttribute("id", "3"); + + pElem1->appendChild(pText1); + pElem1->appendChild(pElem2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem3); + pDoc->appendChild(pRoot); + + Element* pFound = pDoc->getElementById("0", "id"); + assert (pFound == pRoot); + + pFound = pDoc->getElementById("1", "id"); + assert (pFound == pElem1); + + pFound = pDoc->getElementById("2", "id"); + assert (pFound == pElem2); + + pFound = pDoc->getElementById("3", "id"); + assert (pFound == pElem3); + + pFound = pDoc->getElementById("4", "id"); + assert (pFound == 0); + + pFound = pDoc->getElementById("0", "ID"); + assert (pFound == 0); +} + + +void DocumentTest::testElementByIdNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); + pRoot->setAttributeNS("urn:ns1", "id", "0"); + AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); + pElem1->setAttributeNS("urn:ns1", "id", "1"); + AutoPtr pText1 = pDoc->createTextNode("text"); + AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "elem"); + pElem2->setAttributeNS("urn:ns1", "id", "2"); + AutoPtr pElem3 = pDoc->createElementNS("urn:ns1", "elem"); + pElem3->setAttributeNS("urn:ns1", "id", "3"); + + pElem1->appendChild(pText1); + pElem1->appendChild(pElem2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem3); + pDoc->appendChild(pRoot); + + Element* pFound = pDoc->getElementByIdNS("0", "urn:ns1", "id"); + assert (pFound == pRoot); + + pFound = pDoc->getElementByIdNS("1", "urn:ns1", "id"); + assert (pFound == pElem1); + + pFound = pDoc->getElementByIdNS("2", "urn:ns1", "id"); + assert (pFound == pElem2); + + pFound = pDoc->getElementByIdNS("3", "urn:ns1", "id"); + assert (pFound == pElem3); + + pFound = pDoc->getElementByIdNS("4", "urn:ns1", "id"); + assert (pFound == 0); + + pFound = pDoc->getElementByIdNS("0", "urn:ns1", "ID"); + assert (pFound == 0); + + pFound = pDoc->getElementByIdNS("0", "urn:ns2", "id"); + assert (pFound == 0); +} + + +void DocumentTest::setUp() +{ +} + + +void DocumentTest::tearDown() +{ +} + + +CppUnit::Test* DocumentTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTest"); + + CppUnit_addTest(pSuite, DocumentTest, testDocumentElement); + CppUnit_addTest(pSuite, DocumentTest, testImport); + CppUnit_addTest(pSuite, DocumentTest, testImportDeep); + CppUnit_addTest(pSuite, DocumentTest, testElementsByTagName); + CppUnit_addTest(pSuite, DocumentTest, testElementsByTagNameNS); + CppUnit_addTest(pSuite, DocumentTest, testElementById); + CppUnit_addTest(pSuite, DocumentTest, testElementByIdNS); + + return pSuite; +} diff --git a/XML/testsuite/src/DocumentTest.h b/XML/testsuite/src/DocumentTest.h index 7956608b1..9a3d35fe4 100644 --- a/XML/testsuite/src/DocumentTest.h +++ b/XML/testsuite/src/DocumentTest.h @@ -1,66 +1,66 @@ -// -// DocumentTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/DocumentTest.h#1 $ -// -// Definition of the DocumentTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DocumentTest_INCLUDED -#define DocumentTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class DocumentTest: public CppUnit::TestCase -{ -public: - DocumentTest(const std::string& name); - ~DocumentTest(); - - void testDocumentElement(); - void testImport(); - void testImportDeep(); - void testElementsByTagName(); - void testElementsByTagNameNS(); - void testElementById(); - void testElementByIdNS(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // DocumentTest_INCLUDED +// +// DocumentTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/DocumentTest.h#1 $ +// +// Definition of the DocumentTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DocumentTest_INCLUDED +#define DocumentTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class DocumentTest: public CppUnit::TestCase +{ +public: + DocumentTest(const std::string& name); + ~DocumentTest(); + + void testDocumentElement(); + void testImport(); + void testImportDeep(); + void testElementsByTagName(); + void testElementsByTagNameNS(); + void testElementById(); + void testElementByIdNS(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // DocumentTest_INCLUDED diff --git a/XML/testsuite/src/DocumentTypeTest.cpp b/XML/testsuite/src/DocumentTypeTest.cpp index 14cc7c583..473afb817 100644 --- a/XML/testsuite/src/DocumentTypeTest.cpp +++ b/XML/testsuite/src/DocumentTypeTest.cpp @@ -1,130 +1,130 @@ -// -// DocumentTypeTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/DocumentTypeTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "DocumentTypeTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/DocumentType.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Notation.h" -#include "Poco/DOM/Entity.h" -#include "Poco/DOM/DOMImplementation.h" -#include "Poco/DOM/NamedNodeMap.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::DocumentType; -using Poco::XML::Document; -using Poco::XML::Entity; -using Poco::XML::Notation; -using Poco::XML::DOMImplementation; -using Poco::XML::NamedNodeMap; -using Poco::XML::AutoPtr; - - -DocumentTypeTest::DocumentTypeTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -DocumentTypeTest::~DocumentTypeTest() -{ -} - - -void DocumentTypeTest::testDocumentType() -{ - AutoPtr pDoctype = DOMImplementation::instance().createDocumentType("test", "public", "system"); - - assert (pDoctype->ownerDocument() == 0); - assert (pDoctype->name() == "test"); - assert (pDoctype->publicId() == "public"); - assert (pDoctype->systemId() == "system"); - - AutoPtr pDoc = new Document(pDoctype); - assert (pDoc->doctype() == pDoctype); - assert (pDoctype->ownerDocument() == pDoc); - - AutoPtr pEntities = pDoctype->entities(); - AutoPtr pNotations = pDoctype->notations(); - - assert (pEntities->length() == 0); - assert (pNotations->length() == 0); - - AutoPtr pEntity1 = pDoc->createEntity("entity1", "public1", "system1", ""); - pDoctype->appendChild(pEntity1); - - assert (pEntities->length() == 1); - assert (pNotations->length() == 0); - assert (pEntities->item(0) == pEntity1); - assert (pEntities->getNamedItem("entity1") == pEntity1); - - AutoPtr pEntity2 = pDoc->createEntity("entity2", "public2", "system2", ""); - pDoctype->appendChild(pEntity2); - assert (pEntities->length() == 2); - assert (pNotations->length() == 0); - assert (pEntities->item(0) == pEntity1); - assert (pEntities->item(1) == pEntity2); - assert (pEntities->getNamedItem("entity1") == pEntity1); - assert (pEntities->getNamedItem("entity2") == pEntity2); - - AutoPtr pNotation = pDoc->createNotation("notation", "public", "system"); - pDoctype->appendChild(pNotation); - assert (pEntities->length() == 2); - assert (pNotations->length() == 1); - assert (pEntities->item(0) == pEntity1); - assert (pEntities->item(1) == pEntity2); - assert (pNotations->item(0) == pNotation); - assert (pEntities->getNamedItem("entity1") == pEntity1); - assert (pEntities->getNamedItem("entity2") == pEntity2); - assert (pNotations->getNamedItem("notation") == pNotation); -} - - -void DocumentTypeTest::setUp() -{ -} - - -void DocumentTypeTest::tearDown() -{ -} - - -CppUnit::Test* DocumentTypeTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTypeTest"); - - CppUnit_addTest(pSuite, DocumentTypeTest, testDocumentType); - - return pSuite; -} +// +// DocumentTypeTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/DocumentTypeTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "DocumentTypeTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/DocumentType.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Notation.h" +#include "Poco/DOM/Entity.h" +#include "Poco/DOM/DOMImplementation.h" +#include "Poco/DOM/NamedNodeMap.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::DocumentType; +using Poco::XML::Document; +using Poco::XML::Entity; +using Poco::XML::Notation; +using Poco::XML::DOMImplementation; +using Poco::XML::NamedNodeMap; +using Poco::XML::AutoPtr; + + +DocumentTypeTest::DocumentTypeTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +DocumentTypeTest::~DocumentTypeTest() +{ +} + + +void DocumentTypeTest::testDocumentType() +{ + AutoPtr pDoctype = DOMImplementation::instance().createDocumentType("test", "public", "system"); + + assert (pDoctype->ownerDocument() == 0); + assert (pDoctype->name() == "test"); + assert (pDoctype->publicId() == "public"); + assert (pDoctype->systemId() == "system"); + + AutoPtr pDoc = new Document(pDoctype); + assert (pDoc->doctype() == pDoctype); + assert (pDoctype->ownerDocument() == pDoc); + + AutoPtr pEntities = pDoctype->entities(); + AutoPtr pNotations = pDoctype->notations(); + + assert (pEntities->length() == 0); + assert (pNotations->length() == 0); + + AutoPtr pEntity1 = pDoc->createEntity("entity1", "public1", "system1", ""); + pDoctype->appendChild(pEntity1); + + assert (pEntities->length() == 1); + assert (pNotations->length() == 0); + assert (pEntities->item(0) == pEntity1); + assert (pEntities->getNamedItem("entity1") == pEntity1); + + AutoPtr pEntity2 = pDoc->createEntity("entity2", "public2", "system2", ""); + pDoctype->appendChild(pEntity2); + assert (pEntities->length() == 2); + assert (pNotations->length() == 0); + assert (pEntities->item(0) == pEntity1); + assert (pEntities->item(1) == pEntity2); + assert (pEntities->getNamedItem("entity1") == pEntity1); + assert (pEntities->getNamedItem("entity2") == pEntity2); + + AutoPtr pNotation = pDoc->createNotation("notation", "public", "system"); + pDoctype->appendChild(pNotation); + assert (pEntities->length() == 2); + assert (pNotations->length() == 1); + assert (pEntities->item(0) == pEntity1); + assert (pEntities->item(1) == pEntity2); + assert (pNotations->item(0) == pNotation); + assert (pEntities->getNamedItem("entity1") == pEntity1); + assert (pEntities->getNamedItem("entity2") == pEntity2); + assert (pNotations->getNamedItem("notation") == pNotation); +} + + +void DocumentTypeTest::setUp() +{ +} + + +void DocumentTypeTest::tearDown() +{ +} + + +CppUnit::Test* DocumentTypeTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DocumentTypeTest"); + + CppUnit_addTest(pSuite, DocumentTypeTest, testDocumentType); + + return pSuite; +} diff --git a/XML/testsuite/src/DocumentTypeTest.h b/XML/testsuite/src/DocumentTypeTest.h index 9ac5c92b1..198846d28 100644 --- a/XML/testsuite/src/DocumentTypeTest.h +++ b/XML/testsuite/src/DocumentTypeTest.h @@ -1,60 +1,60 @@ -// -// DocumentTypeTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/DocumentTypeTest.h#1 $ -// -// Definition of the DocumentTypeTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef DocumentTypeTest_INCLUDED -#define DocumentTypeTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class DocumentTypeTest: public CppUnit::TestCase -{ -public: - DocumentTypeTest(const std::string& name); - ~DocumentTypeTest(); - - void testDocumentType(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // DocumentTypeTest_INCLUDED +// +// DocumentTypeTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/DocumentTypeTest.h#1 $ +// +// Definition of the DocumentTypeTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef DocumentTypeTest_INCLUDED +#define DocumentTypeTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class DocumentTypeTest: public CppUnit::TestCase +{ +public: + DocumentTypeTest(const std::string& name); + ~DocumentTypeTest(); + + void testDocumentType(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // DocumentTypeTest_INCLUDED diff --git a/XML/testsuite/src/Driver.cpp b/XML/testsuite/src/Driver.cpp index d9385be03..a59dbda5a 100644 --- a/XML/testsuite/src/Driver.cpp +++ b/XML/testsuite/src/Driver.cpp @@ -1,39 +1,39 @@ -// -// Driver.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/Driver.cpp#1 $ -// -// Console-based test driver for Poco XML. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "CppUnit/TestRunner.h" -#include "XMLTestSuite.h" - - -CppUnitMain(XMLTestSuite) +// +// Driver.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/Driver.cpp#1 $ +// +// Console-based test driver for Poco XML. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "CppUnit/TestRunner.h" +#include "XMLTestSuite.h" + + +CppUnitMain(XMLTestSuite) diff --git a/XML/testsuite/src/ElementTest.cpp b/XML/testsuite/src/ElementTest.cpp index a046be4a7..cd030c5cd 100644 --- a/XML/testsuite/src/ElementTest.cpp +++ b/XML/testsuite/src/ElementTest.cpp @@ -1,658 +1,658 @@ -// -// ElementTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/ElementTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "ElementTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/NamedNodeMap.h" -#include "Poco/DOM/NodeList.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::Attr; -using Poco::XML::Text; -using Poco::XML::Node; -using Poco::XML::NamedNodeMap; -using Poco::XML::NodeList; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -ElementTest::ElementTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -ElementTest::~ElementTest() -{ -} - - -void ElementTest::testAttributes() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElement("elem"); - - assert (!pElem->hasAttributes()); - - pElem->setAttribute("a1", "v1"); - assert (pElem->hasAttributes()); - - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "v1"); - - Attr* pAttr1 = pElem->getAttributeNode("a1"); - assert (pAttr1 != 0); - assert (pAttr1->name() == "a1"); - assert (pAttr1->nodeName() == "a1"); - assert (pAttr1->value() == "v1"); - assert (pAttr1->nodeValue() == "v1"); - assert (pAttr1->ownerElement() == pElem); - assert (pAttr1->ownerDocument() == pDoc); - assert (pAttr1->innerText() == "v1"); - - assert (pAttr1->previousSibling() == 0); - assert (pAttr1->nextSibling() == 0); - - pAttr1->setValue("V1"); - assert (pElem->getAttribute("a1") == "V1"); - - pElem->setAttribute("a2", "v2"); - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "V1"); - assert (pElem->hasAttribute("a2")); - assert (pElem->getAttribute("a2") == "v2"); - - Attr* pAttr2 = pElem->getAttributeNode("a2"); - assert (pAttr2 != 0); - assert (pAttr2->name() == "a2"); - assert (pAttr2->value() == "v2"); - assert (pAttr2->ownerElement() == pElem); - - assert (pAttr1->previousSibling() == 0); - assert (pAttr1->nextSibling() == pAttr2); - assert (pAttr2->previousSibling() == pAttr1); - assert (pAttr2->nextSibling() == 0); - - Attr* pAttr3 = pElem->getAttributeNode("a3"); - assert (pAttr3 == 0); - - pAttr3 = pDoc->createAttribute("a3"); - pAttr3->setValue("v3"); - pElem->setAttributeNode(pAttr3); - pAttr3->release(); - - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "V1"); - assert (pElem->hasAttribute("a2")); - assert (pElem->getAttribute("a2") == "v2"); - assert (pElem->hasAttribute("a3")); - assert (pElem->getAttribute("a3") == "v3"); - - assert (pAttr1->previousSibling() == 0); - assert (pAttr1->nextSibling() == pAttr2); - assert (pAttr2->previousSibling() == pAttr1); - assert (pAttr2->nextSibling() == pAttr3); - assert (pAttr3->previousSibling() == pAttr2); - assert (pAttr3->nextSibling() == 0); - - pAttr2 = pDoc->createAttribute("a2"); - pAttr2->setValue("V2"); - pElem->setAttributeNode(pAttr2); - pAttr2->release(); - - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "V1"); - assert (pElem->hasAttribute("a2")); - assert (pElem->getAttribute("a2") == "V2"); - assert (pElem->hasAttribute("a3")); - assert (pElem->getAttribute("a3") == "v3"); - - pAttr1 = pDoc->createAttribute("a1"); - pAttr1->setValue("v1"); - pElem->setAttributeNode(pAttr1); - pAttr1->release(); - - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "v1"); - assert (pElem->hasAttribute("a2")); - assert (pElem->getAttribute("a2") == "V2"); - assert (pElem->hasAttribute("a3")); - assert (pElem->getAttribute("a3") == "v3"); - - pAttr3 = pDoc->createAttribute("a3"); - pAttr3->setValue("V3"); - pElem->setAttributeNode(pAttr3); - pAttr3->release(); - - assert (pElem->hasAttribute("a1")); - assert (pElem->getAttribute("a1") == "v1"); - assert (pElem->hasAttribute("a2")); - assert (pElem->getAttribute("a2") == "V2"); - assert (pElem->hasAttribute("a3")); - assert (pElem->getAttribute("a3") == "V3"); - - pElem->removeAttributeNode(pAttr3); - assert (!pElem->hasAttribute("a3")); - - pElem->removeAttribute("a1"); - assert (!pElem->hasAttribute("a1")); - - pElem->removeAttribute("a2"); - assert (!pElem->hasAttribute("a2")); - - assert (!pElem->hasAttributes()); -} - - -void ElementTest::testAttributesNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElementNS("urn:ns1", "p:elem"); - - assert (pElem->namespaceURI() == "urn:ns1"); - assert (pElem->prefix() == "p"); - assert (pElem->tagName() == "p:elem"); - assert (pElem->localName() == "elem"); - - assert (!pElem->hasAttributes()); - - pElem->setAttributeNS("urn:ns1", "a1", "v1"); - assert (pElem->hasAttributes()); - - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); - - Attr* pAttr1 = pElem->getAttributeNodeNS("urn:ns1", "a1"); - assert (pAttr1 != 0); - assert (pAttr1->name() == "a1"); - assert (pAttr1->namespaceURI() == "urn:ns1"); - assert (pAttr1->prefix().empty()); - assert (pAttr1->localName() == "a1"); - assert (pAttr1->nodeName() == "a1"); - assert (pAttr1->value() == "v1"); - assert (pAttr1->nodeValue() == "v1"); - assert (pAttr1->ownerElement() == pElem); - - pAttr1->setValue("V1"); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); - - pElem->setAttributeNS("urn:ns1", "a2", "v2"); - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); - assert (pElem->hasAttributeNS("urn:ns1", "a2")); - assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2"); - - Attr* pAttr2 = pElem->getAttributeNodeNS("urn:ns1", "a2"); - assert (pAttr2 != 0); - assert (pAttr2->name() == "a2"); - assert (pAttr2->namespaceURI() == "urn:ns1"); - assert (pAttr2->prefix().empty()); - assert (pAttr2->localName() == "a2"); - assert (pAttr2->value() == "v2"); - assert (pAttr2->ownerElement() == pElem); - - Attr* pAttr3 = pElem->getAttributeNodeNS("urn:ns2", "p:a3"); - assert (pAttr3 == 0); - - pAttr3 = pDoc->createAttributeNS("urn:ns2", "p:a3"); - pAttr3->setValue("v3"); - pElem->setAttributeNodeNS(pAttr3); - pAttr3->release(); - - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); - assert (pElem->hasAttributeNS("urn:ns1", "a2")); - assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2"); - assert (pElem->hasAttributeNS("urn:ns2", "a3")); - assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); - - pAttr2 = pDoc->createAttributeNS("urn:ns1", "a2"); - pAttr2->setValue("V2"); - pElem->setAttributeNodeNS(pAttr2); - pAttr2->release(); - - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); - assert (pElem->hasAttributeNS("urn:ns1", "a2")); - assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); - assert (pElem->hasAttributeNS("urn:ns2", "a3")); - assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); - - pAttr1 = pDoc->createAttributeNS("urn:ns1", "a1"); - pAttr1->setValue("v1"); - pElem->setAttributeNodeNS(pAttr1); - pAttr1->release(); - - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); - assert (pElem->hasAttributeNS("urn:ns1", "a2")); - assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); - assert (pElem->hasAttributeNS("urn:ns2", "a3")); - assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); - - pAttr3 = pDoc->createAttributeNS("urn:ns2", "q:a3"); - pAttr3->setValue("V3"); - pElem->setAttributeNodeNS(pAttr3); - pAttr3->release(); - - assert (pElem->hasAttributeNS("urn:ns1", "a1")); - assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); - assert (pElem->hasAttributeNS("urn:ns1", "a2")); - assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); - assert (pElem->hasAttributeNS("urn:ns2", "a3")); - assert (pElem->getAttributeNS("urn:ns2", "a3") == "V3"); - - pElem->removeAttributeNode(pAttr3); - assert (!pElem->hasAttributeNS("urn:ns2", "a3")); - - pElem->removeAttributeNS("urn:ns1", "a1"); - assert (!pElem->hasAttributeNS("urn:ns1", "a1")); - - pElem->removeAttributeNS("urn:ns1", "a2"); - assert (!pElem->hasAttributeNS("urn:ns1", "a2")); - - assert (!pElem->hasAttributes()); -} - - -void ElementTest::testAttrMap() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElement("elem"); - - AutoPtr pNNM = pElem->attributes(); - assert (pNNM->length() == 0); - - pElem->setAttribute("a1", "v1"); - assert (pNNM->length() == 1); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); - - pElem->setAttribute("a2", "v2"); - assert (pNNM->length() == 2); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); - assert (pNNM->item(1)->nodeName() == "a2"); - assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); - - Attr* pAttr = pDoc->createAttribute("a3"); - pNNM->setNamedItem(pAttr); - pAttr->release(); - - assert (pNNM->length() == 3); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); - assert (pNNM->item(1)->nodeName() == "a2"); - assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); - assert (pNNM->item(2)->nodeName() == "a3"); - assert (pNNM->getNamedItem("a3")->nodeName() == "a3"); - - pNNM->removeNamedItem("a2"); - assert (pNNM->length() == 2); - assert (!pElem->hasAttribute("a2")); - - pNNM->removeNamedItem("a3"); - assert (pNNM->length() == 1); - assert (!pElem->hasAttribute("a3")); - - pElem->removeAttribute("a1"); - assert (pNNM->length() == 0); -} - - -void ElementTest::testAttrMapNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElementNS("urn:ns1", "elem"); - - AutoPtr pNNM = pElem->attributes(); - assert (pNNM->length() == 0); - - pElem->setAttributeNS("urn:ns1", "a1", "v1"); - assert (pNNM->length() == 1); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1"); - - pElem->setAttributeNS("urn:ns1", "a2", "v2"); - assert (pNNM->length() == 2); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); - assert (pNNM->item(1)->nodeName() == "a2"); - assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); - - Attr* pAttr = pDoc->createAttributeNS("urn:ns2", "a3"); - pNNM->setNamedItem(pAttr); - pAttr->release(); - - assert (pNNM->length() == 3); - assert (pNNM->item(0)->nodeName() == "a1"); - assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1"); - assert (pNNM->item(1)->nodeName() == "a2"); - assert (pNNM->getNamedItemNS("urn:ns1", "a2")->nodeName() == "a2"); - assert (pNNM->item(2)->nodeName() == "a3"); - assert (pNNM->getNamedItemNS("urn:ns2", "a3")->nodeName() == "a3"); - - pNNM->removeNamedItemNS("urn:ns1", "a2"); - assert (pNNM->length() == 2); - assert (!pElem->hasAttributeNS("urn:ns1", "a2")); - - pNNM->removeNamedItemNS("urn:ns2", "a3"); - assert (pNNM->length() == 1); - assert (!pElem->hasAttributeNS("urn:ns2", "a3")); - - pElem->removeAttributeNS("urn:ns1", "a1"); - assert (pNNM->length() == 0); -} - - -void ElementTest::testElementsByTagName() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pNL1 = pRoot->getElementsByTagName("*"); - AutoPtr pNL2 = pRoot->getElementsByTagName("elem"); - - assert (pNL1->length() == 0); - assert (pNL2->length() == 0); - - AutoPtr pElem1 = pDoc->createElement("elem"); - pRoot->appendChild(pElem1); - - assert (pNL1->length() == 1); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pElem1); - assert (pNL2->item(0) == pElem1); - - AutoPtr pElem2 = pDoc->createElement("Elem"); - pRoot->appendChild(pElem2); - - assert (pNL1->length() == 2); - assert (pNL2->length() == 1); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem2); - assert (pNL2->item(0) == pElem1); - - AutoPtr pElem3 = pDoc->createElement("elem"); - pRoot->appendChild(pElem3); - - assert (pNL1->length() == 3); - assert (pNL2->length() == 2); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem2); - assert (pNL1->item(2) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem3); - - AutoPtr pElem11 = pDoc->createElement("elem"); - pElem1->appendChild(pElem11); - - assert (pNL1->length() == 4); - assert (pNL2->length() == 3); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem2); - assert (pNL1->item(3) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem3); - - AutoPtr pElem12 = pDoc->createElement("Elem"); - pElem1->appendChild(pElem12); - - assert (pNL1->length() == 5); - assert (pNL2->length() == 3); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem12); - assert (pNL1->item(3) == pElem2); - assert (pNL1->item(4) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem3); - - AutoPtr pElem21 = pDoc->createElement("elem"); - pElem2->appendChild(pElem21); - - assert (pNL1->length() == 6); - assert (pNL2->length() == 4); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem12); - assert (pNL1->item(3) == pElem2); - assert (pNL1->item(4) == pElem21); - assert (pNL1->item(5) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem21); - assert (pNL2->item(3) == pElem3); -} - - -void ElementTest::testElementsByTagNameNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); - AutoPtr pNL1 = pRoot->getElementsByTagNameNS("*", "*"); - AutoPtr pNL2 = pRoot->getElementsByTagNameNS("*", "elem"); - AutoPtr pNL3 = pRoot->getElementsByTagNameNS("urn:ns1", "elem"); - - assert (pNL1->length() == 0); - assert (pNL2->length() == 0); - - AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); - pRoot->appendChild(pElem1); - - assert (pNL1->length() == 1); - assert (pNL2->length() == 1); - assert (pNL3->length() == 1); - assert (pNL1->item(0) == pElem1); - assert (pNL2->item(0) == pElem1); - assert (pNL3->item(0) == pElem1); - - AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "Elem"); - pRoot->appendChild(pElem2); - - assert (pNL1->length() == 2); - assert (pNL2->length() == 1); - assert (pNL3->length() == 1); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem2); - assert (pNL2->item(0) == pElem1); - assert (pNL3->item(0) == pElem1); - - AutoPtr pElem3 = pDoc->createElementNS("urn:ns2", "elem"); - pRoot->appendChild(pElem3); - - assert (pNL1->length() == 3); - assert (pNL2->length() == 2); - assert (pNL3->length() == 1); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem2); - assert (pNL1->item(2) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem3); - assert (pNL3->item(0) == pElem1); - - AutoPtr pElem11 = pDoc->createElementNS("urn:ns1", "elem"); - pElem1->appendChild(pElem11); - - assert (pNL1->length() == 4); - assert (pNL2->length() == 3); - assert (pNL3->length() == 2); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem2); - assert (pNL1->item(3) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem3); - assert (pNL3->item(0) == pElem1); - assert (pNL3->item(1) == pElem11); - - AutoPtr pElem12 = pDoc->createElementNS("urn:ns1", "Elem"); - pElem1->appendChild(pElem12); - - assert (pNL1->length() == 5); - assert (pNL2->length() == 3); - assert (pNL3->length() == 2); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem12); - assert (pNL1->item(3) == pElem2); - assert (pNL1->item(4) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem3); - assert (pNL3->item(0) == pElem1); - assert (pNL3->item(1) == pElem11); - - AutoPtr pElem21 = pDoc->createElementNS("urn:ns1", "elem"); - pElem2->appendChild(pElem21); - - assert (pNL1->length() == 6); - assert (pNL2->length() == 4); - assert (pNL3->length() == 3); - assert (pNL1->item(0) == pElem1); - assert (pNL1->item(1) == pElem11); - assert (pNL1->item(2) == pElem12); - assert (pNL1->item(3) == pElem2); - assert (pNL1->item(4) == pElem21); - assert (pNL1->item(5) == pElem3); - assert (pNL2->item(0) == pElem1); - assert (pNL2->item(1) == pElem11); - assert (pNL2->item(2) == pElem21); - assert (pNL2->item(3) == pElem3); - assert (pNL3->item(0) == pElem1); - assert (pNL3->item(1) == pElem11); - assert (pNL3->item(2) == pElem21); -} - - -void ElementTest::testInnerText() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pElem1 = pDoc->createElement("elem1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - AutoPtr pText3 = pDoc->createTextNode("text3"); - - pElem1->appendChild(pText2); - pRoot->appendChild(pText1); - pRoot->appendChild(pElem1); - pRoot->appendChild(pText3); - - XMLString innerText = pRoot->innerText(); - assert (innerText == "text1text2text3"); -} - - -void ElementTest::testChildElement() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem1"); - AutoPtr pElem2 = pDoc->createElement("elem2"); - AutoPtr pElem3 = pDoc->createElement("elem3"); - AutoPtr pElem4 = pDoc->createElement("elem3"); - - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pRoot->appendChild(pElem3); - pRoot->appendChild(pElem4); - - assert (pRoot->getChildElement("elem1") == pElem1); - assert (pRoot->getChildElement("elem2") == pElem2); - assert (pRoot->getChildElement("elem3") == pElem3); - assert (pRoot->getChildElement("elem4") == 0); - - assert (pElem1->getChildElement("elem11") == 0); -} - - -void ElementTest::testChildElementNS() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElementNS("urn:ns", "root"); - AutoPtr pElem1 = pDoc->createElementNS("urn:ns", "elem1"); - AutoPtr pElem2 = pDoc->createElementNS("urn:ns", "elem2"); - AutoPtr pElem3 = pDoc->createElementNS("urn:ns", "elem3"); - AutoPtr pElem4 = pDoc->createElementNS("urn:ns", "elem3"); - - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pRoot->appendChild(pElem3); - pRoot->appendChild(pElem4); - - assert (pRoot->getChildElementNS("urn:ns", "elem1") == pElem1); - assert (pRoot->getChildElementNS("urn:ns", "elem2") == pElem2); - assert (pRoot->getChildElementNS("urn:ns", "elem3") == pElem3); - assert (pRoot->getChildElementNS("urn:ns", "elem4") == 0); - assert (pRoot->getChildElementNS("urn:NS", "elem1") == 0); - - assert (pElem1->getChildElementNS("urn:ns", "elem11") == 0); -} - - -void ElementTest::setUp() -{ -} - - -void ElementTest::tearDown() -{ -} - - -CppUnit::Test* ElementTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ElementTest"); - - CppUnit_addTest(pSuite, ElementTest, testAttributes); - CppUnit_addTest(pSuite, ElementTest, testAttributesNS); - CppUnit_addTest(pSuite, ElementTest, testAttrMap); - CppUnit_addTest(pSuite, ElementTest, testAttrMapNS); - CppUnit_addTest(pSuite, ElementTest, testElementsByTagName); - CppUnit_addTest(pSuite, ElementTest, testElementsByTagNameNS); - CppUnit_addTest(pSuite, ElementTest, testInnerText); - CppUnit_addTest(pSuite, ElementTest, testChildElement); - CppUnit_addTest(pSuite, ElementTest, testChildElementNS); - - return pSuite; -} +// +// ElementTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/ElementTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "ElementTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/NamedNodeMap.h" +#include "Poco/DOM/NodeList.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::Attr; +using Poco::XML::Text; +using Poco::XML::Node; +using Poco::XML::NamedNodeMap; +using Poco::XML::NodeList; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +ElementTest::ElementTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +ElementTest::~ElementTest() +{ +} + + +void ElementTest::testAttributes() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElement("elem"); + + assert (!pElem->hasAttributes()); + + pElem->setAttribute("a1", "v1"); + assert (pElem->hasAttributes()); + + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "v1"); + + Attr* pAttr1 = pElem->getAttributeNode("a1"); + assert (pAttr1 != 0); + assert (pAttr1->name() == "a1"); + assert (pAttr1->nodeName() == "a1"); + assert (pAttr1->value() == "v1"); + assert (pAttr1->nodeValue() == "v1"); + assert (pAttr1->ownerElement() == pElem); + assert (pAttr1->ownerDocument() == pDoc); + assert (pAttr1->innerText() == "v1"); + + assert (pAttr1->previousSibling() == 0); + assert (pAttr1->nextSibling() == 0); + + pAttr1->setValue("V1"); + assert (pElem->getAttribute("a1") == "V1"); + + pElem->setAttribute("a2", "v2"); + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "V1"); + assert (pElem->hasAttribute("a2")); + assert (pElem->getAttribute("a2") == "v2"); + + Attr* pAttr2 = pElem->getAttributeNode("a2"); + assert (pAttr2 != 0); + assert (pAttr2->name() == "a2"); + assert (pAttr2->value() == "v2"); + assert (pAttr2->ownerElement() == pElem); + + assert (pAttr1->previousSibling() == 0); + assert (pAttr1->nextSibling() == pAttr2); + assert (pAttr2->previousSibling() == pAttr1); + assert (pAttr2->nextSibling() == 0); + + Attr* pAttr3 = pElem->getAttributeNode("a3"); + assert (pAttr3 == 0); + + pAttr3 = pDoc->createAttribute("a3"); + pAttr3->setValue("v3"); + pElem->setAttributeNode(pAttr3); + pAttr3->release(); + + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "V1"); + assert (pElem->hasAttribute("a2")); + assert (pElem->getAttribute("a2") == "v2"); + assert (pElem->hasAttribute("a3")); + assert (pElem->getAttribute("a3") == "v3"); + + assert (pAttr1->previousSibling() == 0); + assert (pAttr1->nextSibling() == pAttr2); + assert (pAttr2->previousSibling() == pAttr1); + assert (pAttr2->nextSibling() == pAttr3); + assert (pAttr3->previousSibling() == pAttr2); + assert (pAttr3->nextSibling() == 0); + + pAttr2 = pDoc->createAttribute("a2"); + pAttr2->setValue("V2"); + pElem->setAttributeNode(pAttr2); + pAttr2->release(); + + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "V1"); + assert (pElem->hasAttribute("a2")); + assert (pElem->getAttribute("a2") == "V2"); + assert (pElem->hasAttribute("a3")); + assert (pElem->getAttribute("a3") == "v3"); + + pAttr1 = pDoc->createAttribute("a1"); + pAttr1->setValue("v1"); + pElem->setAttributeNode(pAttr1); + pAttr1->release(); + + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "v1"); + assert (pElem->hasAttribute("a2")); + assert (pElem->getAttribute("a2") == "V2"); + assert (pElem->hasAttribute("a3")); + assert (pElem->getAttribute("a3") == "v3"); + + pAttr3 = pDoc->createAttribute("a3"); + pAttr3->setValue("V3"); + pElem->setAttributeNode(pAttr3); + pAttr3->release(); + + assert (pElem->hasAttribute("a1")); + assert (pElem->getAttribute("a1") == "v1"); + assert (pElem->hasAttribute("a2")); + assert (pElem->getAttribute("a2") == "V2"); + assert (pElem->hasAttribute("a3")); + assert (pElem->getAttribute("a3") == "V3"); + + pElem->removeAttributeNode(pAttr3); + assert (!pElem->hasAttribute("a3")); + + pElem->removeAttribute("a1"); + assert (!pElem->hasAttribute("a1")); + + pElem->removeAttribute("a2"); + assert (!pElem->hasAttribute("a2")); + + assert (!pElem->hasAttributes()); +} + + +void ElementTest::testAttributesNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElementNS("urn:ns1", "p:elem"); + + assert (pElem->namespaceURI() == "urn:ns1"); + assert (pElem->prefix() == "p"); + assert (pElem->tagName() == "p:elem"); + assert (pElem->localName() == "elem"); + + assert (!pElem->hasAttributes()); + + pElem->setAttributeNS("urn:ns1", "a1", "v1"); + assert (pElem->hasAttributes()); + + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); + + Attr* pAttr1 = pElem->getAttributeNodeNS("urn:ns1", "a1"); + assert (pAttr1 != 0); + assert (pAttr1->name() == "a1"); + assert (pAttr1->namespaceURI() == "urn:ns1"); + assert (pAttr1->prefix().empty()); + assert (pAttr1->localName() == "a1"); + assert (pAttr1->nodeName() == "a1"); + assert (pAttr1->value() == "v1"); + assert (pAttr1->nodeValue() == "v1"); + assert (pAttr1->ownerElement() == pElem); + + pAttr1->setValue("V1"); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); + + pElem->setAttributeNS("urn:ns1", "a2", "v2"); + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); + assert (pElem->hasAttributeNS("urn:ns1", "a2")); + assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2"); + + Attr* pAttr2 = pElem->getAttributeNodeNS("urn:ns1", "a2"); + assert (pAttr2 != 0); + assert (pAttr2->name() == "a2"); + assert (pAttr2->namespaceURI() == "urn:ns1"); + assert (pAttr2->prefix().empty()); + assert (pAttr2->localName() == "a2"); + assert (pAttr2->value() == "v2"); + assert (pAttr2->ownerElement() == pElem); + + Attr* pAttr3 = pElem->getAttributeNodeNS("urn:ns2", "p:a3"); + assert (pAttr3 == 0); + + pAttr3 = pDoc->createAttributeNS("urn:ns2", "p:a3"); + pAttr3->setValue("v3"); + pElem->setAttributeNodeNS(pAttr3); + pAttr3->release(); + + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); + assert (pElem->hasAttributeNS("urn:ns1", "a2")); + assert (pElem->getAttributeNS("urn:ns1", "a2") == "v2"); + assert (pElem->hasAttributeNS("urn:ns2", "a3")); + assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); + + pAttr2 = pDoc->createAttributeNS("urn:ns1", "a2"); + pAttr2->setValue("V2"); + pElem->setAttributeNodeNS(pAttr2); + pAttr2->release(); + + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "V1"); + assert (pElem->hasAttributeNS("urn:ns1", "a2")); + assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); + assert (pElem->hasAttributeNS("urn:ns2", "a3")); + assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); + + pAttr1 = pDoc->createAttributeNS("urn:ns1", "a1"); + pAttr1->setValue("v1"); + pElem->setAttributeNodeNS(pAttr1); + pAttr1->release(); + + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); + assert (pElem->hasAttributeNS("urn:ns1", "a2")); + assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); + assert (pElem->hasAttributeNS("urn:ns2", "a3")); + assert (pElem->getAttributeNS("urn:ns2", "a3") == "v3"); + + pAttr3 = pDoc->createAttributeNS("urn:ns2", "q:a3"); + pAttr3->setValue("V3"); + pElem->setAttributeNodeNS(pAttr3); + pAttr3->release(); + + assert (pElem->hasAttributeNS("urn:ns1", "a1")); + assert (pElem->getAttributeNS("urn:ns1", "a1") == "v1"); + assert (pElem->hasAttributeNS("urn:ns1", "a2")); + assert (pElem->getAttributeNS("urn:ns1", "a2") == "V2"); + assert (pElem->hasAttributeNS("urn:ns2", "a3")); + assert (pElem->getAttributeNS("urn:ns2", "a3") == "V3"); + + pElem->removeAttributeNode(pAttr3); + assert (!pElem->hasAttributeNS("urn:ns2", "a3")); + + pElem->removeAttributeNS("urn:ns1", "a1"); + assert (!pElem->hasAttributeNS("urn:ns1", "a1")); + + pElem->removeAttributeNS("urn:ns1", "a2"); + assert (!pElem->hasAttributeNS("urn:ns1", "a2")); + + assert (!pElem->hasAttributes()); +} + + +void ElementTest::testAttrMap() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElement("elem"); + + AutoPtr pNNM = pElem->attributes(); + assert (pNNM->length() == 0); + + pElem->setAttribute("a1", "v1"); + assert (pNNM->length() == 1); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); + + pElem->setAttribute("a2", "v2"); + assert (pNNM->length() == 2); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); + assert (pNNM->item(1)->nodeName() == "a2"); + assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); + + Attr* pAttr = pDoc->createAttribute("a3"); + pNNM->setNamedItem(pAttr); + pAttr->release(); + + assert (pNNM->length() == 3); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); + assert (pNNM->item(1)->nodeName() == "a2"); + assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); + assert (pNNM->item(2)->nodeName() == "a3"); + assert (pNNM->getNamedItem("a3")->nodeName() == "a3"); + + pNNM->removeNamedItem("a2"); + assert (pNNM->length() == 2); + assert (!pElem->hasAttribute("a2")); + + pNNM->removeNamedItem("a3"); + assert (pNNM->length() == 1); + assert (!pElem->hasAttribute("a3")); + + pElem->removeAttribute("a1"); + assert (pNNM->length() == 0); +} + + +void ElementTest::testAttrMapNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElementNS("urn:ns1", "elem"); + + AutoPtr pNNM = pElem->attributes(); + assert (pNNM->length() == 0); + + pElem->setAttributeNS("urn:ns1", "a1", "v1"); + assert (pNNM->length() == 1); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1"); + + pElem->setAttributeNS("urn:ns1", "a2", "v2"); + assert (pNNM->length() == 2); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItem("a1")->nodeName() == "a1"); + assert (pNNM->item(1)->nodeName() == "a2"); + assert (pNNM->getNamedItem("a2")->nodeName() == "a2"); + + Attr* pAttr = pDoc->createAttributeNS("urn:ns2", "a3"); + pNNM->setNamedItem(pAttr); + pAttr->release(); + + assert (pNNM->length() == 3); + assert (pNNM->item(0)->nodeName() == "a1"); + assert (pNNM->getNamedItemNS("urn:ns1", "a1")->nodeName() == "a1"); + assert (pNNM->item(1)->nodeName() == "a2"); + assert (pNNM->getNamedItemNS("urn:ns1", "a2")->nodeName() == "a2"); + assert (pNNM->item(2)->nodeName() == "a3"); + assert (pNNM->getNamedItemNS("urn:ns2", "a3")->nodeName() == "a3"); + + pNNM->removeNamedItemNS("urn:ns1", "a2"); + assert (pNNM->length() == 2); + assert (!pElem->hasAttributeNS("urn:ns1", "a2")); + + pNNM->removeNamedItemNS("urn:ns2", "a3"); + assert (pNNM->length() == 1); + assert (!pElem->hasAttributeNS("urn:ns2", "a3")); + + pElem->removeAttributeNS("urn:ns1", "a1"); + assert (pNNM->length() == 0); +} + + +void ElementTest::testElementsByTagName() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pNL1 = pRoot->getElementsByTagName("*"); + AutoPtr pNL2 = pRoot->getElementsByTagName("elem"); + + assert (pNL1->length() == 0); + assert (pNL2->length() == 0); + + AutoPtr pElem1 = pDoc->createElement("elem"); + pRoot->appendChild(pElem1); + + assert (pNL1->length() == 1); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pElem1); + assert (pNL2->item(0) == pElem1); + + AutoPtr pElem2 = pDoc->createElement("Elem"); + pRoot->appendChild(pElem2); + + assert (pNL1->length() == 2); + assert (pNL2->length() == 1); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem2); + assert (pNL2->item(0) == pElem1); + + AutoPtr pElem3 = pDoc->createElement("elem"); + pRoot->appendChild(pElem3); + + assert (pNL1->length() == 3); + assert (pNL2->length() == 2); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem2); + assert (pNL1->item(2) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem3); + + AutoPtr pElem11 = pDoc->createElement("elem"); + pElem1->appendChild(pElem11); + + assert (pNL1->length() == 4); + assert (pNL2->length() == 3); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem2); + assert (pNL1->item(3) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem3); + + AutoPtr pElem12 = pDoc->createElement("Elem"); + pElem1->appendChild(pElem12); + + assert (pNL1->length() == 5); + assert (pNL2->length() == 3); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem12); + assert (pNL1->item(3) == pElem2); + assert (pNL1->item(4) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem3); + + AutoPtr pElem21 = pDoc->createElement("elem"); + pElem2->appendChild(pElem21); + + assert (pNL1->length() == 6); + assert (pNL2->length() == 4); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem12); + assert (pNL1->item(3) == pElem2); + assert (pNL1->item(4) == pElem21); + assert (pNL1->item(5) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem21); + assert (pNL2->item(3) == pElem3); +} + + +void ElementTest::testElementsByTagNameNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElementNS("urn:ns1", "root"); + AutoPtr pNL1 = pRoot->getElementsByTagNameNS("*", "*"); + AutoPtr pNL2 = pRoot->getElementsByTagNameNS("*", "elem"); + AutoPtr pNL3 = pRoot->getElementsByTagNameNS("urn:ns1", "elem"); + + assert (pNL1->length() == 0); + assert (pNL2->length() == 0); + + AutoPtr pElem1 = pDoc->createElementNS("urn:ns1", "elem"); + pRoot->appendChild(pElem1); + + assert (pNL1->length() == 1); + assert (pNL2->length() == 1); + assert (pNL3->length() == 1); + assert (pNL1->item(0) == pElem1); + assert (pNL2->item(0) == pElem1); + assert (pNL3->item(0) == pElem1); + + AutoPtr pElem2 = pDoc->createElementNS("urn:ns1", "Elem"); + pRoot->appendChild(pElem2); + + assert (pNL1->length() == 2); + assert (pNL2->length() == 1); + assert (pNL3->length() == 1); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem2); + assert (pNL2->item(0) == pElem1); + assert (pNL3->item(0) == pElem1); + + AutoPtr pElem3 = pDoc->createElementNS("urn:ns2", "elem"); + pRoot->appendChild(pElem3); + + assert (pNL1->length() == 3); + assert (pNL2->length() == 2); + assert (pNL3->length() == 1); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem2); + assert (pNL1->item(2) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem3); + assert (pNL3->item(0) == pElem1); + + AutoPtr pElem11 = pDoc->createElementNS("urn:ns1", "elem"); + pElem1->appendChild(pElem11); + + assert (pNL1->length() == 4); + assert (pNL2->length() == 3); + assert (pNL3->length() == 2); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem2); + assert (pNL1->item(3) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem3); + assert (pNL3->item(0) == pElem1); + assert (pNL3->item(1) == pElem11); + + AutoPtr pElem12 = pDoc->createElementNS("urn:ns1", "Elem"); + pElem1->appendChild(pElem12); + + assert (pNL1->length() == 5); + assert (pNL2->length() == 3); + assert (pNL3->length() == 2); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem12); + assert (pNL1->item(3) == pElem2); + assert (pNL1->item(4) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem3); + assert (pNL3->item(0) == pElem1); + assert (pNL3->item(1) == pElem11); + + AutoPtr pElem21 = pDoc->createElementNS("urn:ns1", "elem"); + pElem2->appendChild(pElem21); + + assert (pNL1->length() == 6); + assert (pNL2->length() == 4); + assert (pNL3->length() == 3); + assert (pNL1->item(0) == pElem1); + assert (pNL1->item(1) == pElem11); + assert (pNL1->item(2) == pElem12); + assert (pNL1->item(3) == pElem2); + assert (pNL1->item(4) == pElem21); + assert (pNL1->item(5) == pElem3); + assert (pNL2->item(0) == pElem1); + assert (pNL2->item(1) == pElem11); + assert (pNL2->item(2) == pElem21); + assert (pNL2->item(3) == pElem3); + assert (pNL3->item(0) == pElem1); + assert (pNL3->item(1) == pElem11); + assert (pNL3->item(2) == pElem21); +} + + +void ElementTest::testInnerText() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pElem1 = pDoc->createElement("elem1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + AutoPtr pText3 = pDoc->createTextNode("text3"); + + pElem1->appendChild(pText2); + pRoot->appendChild(pText1); + pRoot->appendChild(pElem1); + pRoot->appendChild(pText3); + + XMLString innerText = pRoot->innerText(); + assert (innerText == "text1text2text3"); +} + + +void ElementTest::testChildElement() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem1"); + AutoPtr pElem2 = pDoc->createElement("elem2"); + AutoPtr pElem3 = pDoc->createElement("elem3"); + AutoPtr pElem4 = pDoc->createElement("elem3"); + + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pRoot->appendChild(pElem3); + pRoot->appendChild(pElem4); + + assert (pRoot->getChildElement("elem1") == pElem1); + assert (pRoot->getChildElement("elem2") == pElem2); + assert (pRoot->getChildElement("elem3") == pElem3); + assert (pRoot->getChildElement("elem4") == 0); + + assert (pElem1->getChildElement("elem11") == 0); +} + + +void ElementTest::testChildElementNS() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElementNS("urn:ns", "root"); + AutoPtr pElem1 = pDoc->createElementNS("urn:ns", "elem1"); + AutoPtr pElem2 = pDoc->createElementNS("urn:ns", "elem2"); + AutoPtr pElem3 = pDoc->createElementNS("urn:ns", "elem3"); + AutoPtr pElem4 = pDoc->createElementNS("urn:ns", "elem3"); + + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pRoot->appendChild(pElem3); + pRoot->appendChild(pElem4); + + assert (pRoot->getChildElementNS("urn:ns", "elem1") == pElem1); + assert (pRoot->getChildElementNS("urn:ns", "elem2") == pElem2); + assert (pRoot->getChildElementNS("urn:ns", "elem3") == pElem3); + assert (pRoot->getChildElementNS("urn:ns", "elem4") == 0); + assert (pRoot->getChildElementNS("urn:NS", "elem1") == 0); + + assert (pElem1->getChildElementNS("urn:ns", "elem11") == 0); +} + + +void ElementTest::setUp() +{ +} + + +void ElementTest::tearDown() +{ +} + + +CppUnit::Test* ElementTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ElementTest"); + + CppUnit_addTest(pSuite, ElementTest, testAttributes); + CppUnit_addTest(pSuite, ElementTest, testAttributesNS); + CppUnit_addTest(pSuite, ElementTest, testAttrMap); + CppUnit_addTest(pSuite, ElementTest, testAttrMapNS); + CppUnit_addTest(pSuite, ElementTest, testElementsByTagName); + CppUnit_addTest(pSuite, ElementTest, testElementsByTagNameNS); + CppUnit_addTest(pSuite, ElementTest, testInnerText); + CppUnit_addTest(pSuite, ElementTest, testChildElement); + CppUnit_addTest(pSuite, ElementTest, testChildElementNS); + + return pSuite; +} diff --git a/XML/testsuite/src/ElementTest.h b/XML/testsuite/src/ElementTest.h index 53f9f3406..bcb1f6b60 100644 --- a/XML/testsuite/src/ElementTest.h +++ b/XML/testsuite/src/ElementTest.h @@ -1,68 +1,68 @@ -// -// ElementTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/ElementTest.h#1 $ -// -// Definition of the ElementTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef ElementTest_INCLUDED -#define ElementTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class ElementTest: public CppUnit::TestCase -{ -public: - ElementTest(const std::string& name); - ~ElementTest(); - - void testAttributes(); - void testAttributesNS(); - void testAttrMap(); - void testAttrMapNS(); - void testElementsByTagName(); - void testElementsByTagNameNS(); - void testInnerText(); - void testChildElement(); - void testChildElementNS(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // ElementTest_INCLUDED +// +// ElementTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/ElementTest.h#1 $ +// +// Definition of the ElementTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef ElementTest_INCLUDED +#define ElementTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class ElementTest: public CppUnit::TestCase +{ +public: + ElementTest(const std::string& name); + ~ElementTest(); + + void testAttributes(); + void testAttributesNS(); + void testAttrMap(); + void testAttrMapNS(); + void testElementsByTagName(); + void testElementsByTagNameNS(); + void testInnerText(); + void testChildElement(); + void testChildElementNS(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // ElementTest_INCLUDED diff --git a/XML/testsuite/src/EventTest.cpp b/XML/testsuite/src/EventTest.cpp index 1004cc9de..d54e8e19d 100644 --- a/XML/testsuite/src/EventTest.cpp +++ b/XML/testsuite/src/EventTest.cpp @@ -1,593 +1,593 @@ -// -// EventTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/EventTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "EventTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Event.h" -#include "Poco/DOM/MutationEvent.h" -#include "Poco/DOM/EventListener.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Attr.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::Event; -using Poco::XML::MutationEvent; -using Poco::XML::EventListener; -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::Attr; -using Poco::XML::Text; -using Poco::XML::Node; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -class TestEventListener: public EventListener -{ -public: - TestEventListener(const XMLString& name, bool cancel = false, bool readd = false, bool capture = false): - _name(name), - _cancel(cancel), - _readd(readd), - _capture(capture) - { - } - - void handleEvent(Event* evt) - { - XMLString type = evt->type(); - XMLString phase; - switch (evt->eventPhase()) - { - case Event::CAPTURING_PHASE: - phase = "CAPTURING_PHASE"; break; - case Event::AT_TARGET: - phase = "AT_TARGET"; break; - case Event::BUBBLING_PHASE: - phase = "BUBBLING_PHASE"; break; - } - Node* pTarget = static_cast(evt->target()); - Node* pCurrentTarget = static_cast(evt->currentTarget()); - - _log.append(_name); - _log.append(":"); - _log.append(type); - _log.append(":"); - _log.append(phase); - _log.append(":"); - _log.append(pTarget->nodeName()); - _log.append(":"); - _log.append(pCurrentTarget->nodeName()); - _log.append(":"); - _log.append(evt->bubbles() ? "B" : "-"); - _log.append(":"); - _log.append(evt->cancelable() ? "C" : "-"); - - MutationEvent* pME = dynamic_cast(evt); - if (pME) - { - XMLString attrChange; - switch (pME->attrChange()) - { - case MutationEvent::MODIFICATION: - attrChange = "MODIFICATION"; break; - case MutationEvent::ADDITION: - attrChange = "ADDITION"; break; - case MutationEvent::REMOVAL: - attrChange = "REMOVAL"; break; - } - XMLString relatedNode; - Node* pRelatedNode = pME->relatedNode(); - if (pRelatedNode) relatedNode = pRelatedNode->nodeName(); - - _log.append(":"); - _log.append(attrChange); - _log.append(":"); - _log.append(relatedNode); - _log.append(":"); - _log.append(pME->attrName()); - _log.append(":"); - _log.append(pME->prevValue()); - _log.append(":"); - _log.append(pME->newValue()); - } - _log.append("\n"); - - if (_cancel) evt->stopPropagation(); - if (_readd) - pCurrentTarget->addEventListener(type, this, _capture); - } - - static const XMLString& log() - { - return _log; - } - - static void reset() - { - _log.clear(); - } - -private: - XMLString _name; - bool _cancel; - bool _readd; - bool _capture; - static XMLString _log; -}; - - -XMLString TestEventListener::_log; - - -EventTest::EventTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -EventTest::~EventTest() -{ -} - - -void EventTest::testInsert() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap"); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); - - pDoc->appendChild(pRoot); - - const XMLString& log = TestEventListener::log(); - - assert (log == - "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - ); - - TestEventListener::reset(); - - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - - assert (log == - "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" - "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" - ); -} - - -void EventTest::testInsertSubtree() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap"); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); - - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - - TestEventListener::reset(); - - pDoc->appendChild(pRoot); - - const XMLString& log = TestEventListener::log(); - assert (log == - "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - ); -} - - -void EventTest::testRemove() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap"); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true); - - pDoc->appendChild(pRoot); - - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - - TestEventListener::reset(); - - pRoot->removeChild(pText); - - const XMLString& log = TestEventListener::log(); - assert (log == - "docCap:DOMNodeRemoved:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "rootCap:DOMNodeRemoved:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "root:DOMNodeRemoved:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "doc:DOMNodeRemoved:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" - "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" - ); -} - - -void EventTest::testRemoveSubtree() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap"); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true); - - pDoc->appendChild(pRoot); - - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - - TestEventListener::reset(); - - pDoc->removeChild(pRoot); - - const XMLString& log = TestEventListener::log(); - assert (log == - "docCap:DOMNodeRemoved:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "rootCap:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "root:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "doc:DOMNodeRemoved:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "root:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - ); -} - - -void EventTest::testCharacterData() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - pDoc->appendChild(pRoot); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap"); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - TestEventListener textListener("text"); - TestEventListener textCapListener("textCap"); - - pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true); - pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true); - pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false); - pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true); - - TestEventListener::reset(); - - pText->setData("modified"); - - const XMLString& log = TestEventListener::log(); - assert (log == - "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n" - "rootCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n" - "textCap:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n" - "text:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n" - "root:DOMCharacterDataModified:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n" - "doc:DOMCharacterDataModified:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n" - ); -} - - -void EventTest::testCancel() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - pDoc->appendChild(pRoot); - - TestEventListener docListener("doc"); - TestEventListener docCapListener("docCap", true); - TestEventListener rootListener("root"); - TestEventListener rootCapListener("rootCap"); - TestEventListener textListener("text"); - TestEventListener textCapListener("textCap"); - - pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true); - pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true); - pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false); - pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true); - - TestEventListener::reset(); - - pText->setData("modified"); - - const XMLString& log = TestEventListener::log(); - assert (log == "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"); -} - - -void EventTest::testAttributes() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener rootListener("root"); - pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false); - - pRoot->setAttribute("a1", "v1"); - - const XMLString& log = TestEventListener::log(); - assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a1:a1::v1\n"); - - TestEventListener::reset(); - pRoot->setAttribute("a1", "V1"); - assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:MODIFICATION:a1:a1:v1:V1\n"); - - TestEventListener::reset(); - pRoot->setAttribute("a2", "v2"); - assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a2:a2::v2\n"); - - TestEventListener::reset(); - pRoot->removeAttribute("a1"); - assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:REMOVAL:a1:a1:V1:\n"); -} - - -void EventTest::testAddRemoveInEvent() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - TestEventListener docListener("doc", false, true, false); - TestEventListener docCapListener("docCap", false, true, true); - TestEventListener rootListener("root", false, true, false); - TestEventListener rootCapListener("rootCap", false, true, true); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); - - pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); - pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); - - pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); - pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); - - pDoc->appendChild(pRoot); - - const XMLString& log = TestEventListener::log(); - assert (log == - "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" - "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" - ); - - TestEventListener::reset(); - - AutoPtr pText = pDoc->createTextNode("text"); - pRoot->appendChild(pText); - - assert (log == - "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" - "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" - "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" - "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" - "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" - "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" - "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" - ); -} - - -void EventTest::testSuspended() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - pDoc->suspendEvents(); - - TestEventListener rootListener("root"); - pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false); - - pRoot->setAttribute("a1", "v1"); - - const XMLString& log = TestEventListener::log(); - assert (log.empty()); - - TestEventListener::reset(); - pRoot->setAttribute("a1", "V1"); - assert (log.empty()); - - TestEventListener::reset(); - pRoot->setAttribute("a2", "v2"); - assert (log.empty()); - - TestEventListener::reset(); - pRoot->removeAttribute("a1"); - assert (log.empty()); -} - - -void EventTest::setUp() -{ - TestEventListener::reset(); -} - - -void EventTest::tearDown() -{ -} - - -CppUnit::Test* EventTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("EventTest"); - - CppUnit_addTest(pSuite, EventTest, testInsert); - CppUnit_addTest(pSuite, EventTest, testInsertSubtree); - CppUnit_addTest(pSuite, EventTest, testRemove); - CppUnit_addTest(pSuite, EventTest, testRemoveSubtree); - CppUnit_addTest(pSuite, EventTest, testCharacterData); - CppUnit_addTest(pSuite, EventTest, testCancel); - CppUnit_addTest(pSuite, EventTest, testAttributes); - CppUnit_addTest(pSuite, EventTest, testAddRemoveInEvent); - CppUnit_addTest(pSuite, EventTest, testSuspended); - - return pSuite; -} +// +// EventTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/EventTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "EventTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Event.h" +#include "Poco/DOM/MutationEvent.h" +#include "Poco/DOM/EventListener.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Attr.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::Event; +using Poco::XML::MutationEvent; +using Poco::XML::EventListener; +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::Attr; +using Poco::XML::Text; +using Poco::XML::Node; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +class TestEventListener: public EventListener +{ +public: + TestEventListener(const XMLString& name, bool cancel = false, bool readd = false, bool capture = false): + _name(name), + _cancel(cancel), + _readd(readd), + _capture(capture) + { + } + + void handleEvent(Event* evt) + { + XMLString type = evt->type(); + XMLString phase; + switch (evt->eventPhase()) + { + case Event::CAPTURING_PHASE: + phase = "CAPTURING_PHASE"; break; + case Event::AT_TARGET: + phase = "AT_TARGET"; break; + case Event::BUBBLING_PHASE: + phase = "BUBBLING_PHASE"; break; + } + Node* pTarget = static_cast(evt->target()); + Node* pCurrentTarget = static_cast(evt->currentTarget()); + + _log.append(_name); + _log.append(":"); + _log.append(type); + _log.append(":"); + _log.append(phase); + _log.append(":"); + _log.append(pTarget->nodeName()); + _log.append(":"); + _log.append(pCurrentTarget->nodeName()); + _log.append(":"); + _log.append(evt->bubbles() ? "B" : "-"); + _log.append(":"); + _log.append(evt->cancelable() ? "C" : "-"); + + MutationEvent* pME = dynamic_cast(evt); + if (pME) + { + XMLString attrChange; + switch (pME->attrChange()) + { + case MutationEvent::MODIFICATION: + attrChange = "MODIFICATION"; break; + case MutationEvent::ADDITION: + attrChange = "ADDITION"; break; + case MutationEvent::REMOVAL: + attrChange = "REMOVAL"; break; + } + XMLString relatedNode; + Node* pRelatedNode = pME->relatedNode(); + if (pRelatedNode) relatedNode = pRelatedNode->nodeName(); + + _log.append(":"); + _log.append(attrChange); + _log.append(":"); + _log.append(relatedNode); + _log.append(":"); + _log.append(pME->attrName()); + _log.append(":"); + _log.append(pME->prevValue()); + _log.append(":"); + _log.append(pME->newValue()); + } + _log.append("\n"); + + if (_cancel) evt->stopPropagation(); + if (_readd) + pCurrentTarget->addEventListener(type, this, _capture); + } + + static const XMLString& log() + { + return _log; + } + + static void reset() + { + _log.clear(); + } + +private: + XMLString _name; + bool _cancel; + bool _readd; + bool _capture; + static XMLString _log; +}; + + +XMLString TestEventListener::_log; + + +EventTest::EventTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +EventTest::~EventTest() +{ +} + + +void EventTest::testInsert() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap"); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); + + pDoc->appendChild(pRoot); + + const XMLString& log = TestEventListener::log(); + + assert (log == + "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + ); + + TestEventListener::reset(); + + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + + assert (log == + "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" + "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" + ); +} + + +void EventTest::testInsertSubtree() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap"); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); + + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + + TestEventListener::reset(); + + pDoc->appendChild(pRoot); + + const XMLString& log = TestEventListener::log(); + assert (log == + "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + ); +} + + +void EventTest::testRemove() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap"); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true); + + pDoc->appendChild(pRoot); + + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + + TestEventListener::reset(); + + pRoot->removeChild(pText); + + const XMLString& log = TestEventListener::log(); + assert (log == + "docCap:DOMNodeRemoved:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "rootCap:DOMNodeRemoved:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "root:DOMNodeRemoved:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "doc:DOMNodeRemoved:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" + "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" + ); +} + + +void EventTest::testRemoveSubtree() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap"); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docListener, false); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeRemoved, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &docCapListener, true); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootListener, false); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeRemoved, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeRemovedFromDocument, &rootCapListener, true); + + pDoc->appendChild(pRoot); + + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + + TestEventListener::reset(); + + pDoc->removeChild(pRoot); + + const XMLString& log = TestEventListener::log(); + assert (log == + "docCap:DOMNodeRemoved:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "rootCap:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "root:DOMNodeRemoved:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "doc:DOMNodeRemoved:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "root:DOMNodeRemovedFromDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "docCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeRemovedFromDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + ); +} + + +void EventTest::testCharacterData() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + pDoc->appendChild(pRoot); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap"); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + TestEventListener textListener("text"); + TestEventListener textCapListener("textCap"); + + pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true); + pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true); + pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false); + pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true); + + TestEventListener::reset(); + + pText->setData("modified"); + + const XMLString& log = TestEventListener::log(); + assert (log == + "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n" + "rootCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n" + "textCap:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n" + "text:DOMCharacterDataModified:AT_TARGET:#text:#text:B:-:MODIFICATION:::text:modified\n" + "root:DOMCharacterDataModified:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:::text:modified\n" + "doc:DOMCharacterDataModified:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n" + ); +} + + +void EventTest::testCancel() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + pDoc->appendChild(pRoot); + + TestEventListener docListener("doc"); + TestEventListener docCapListener("docCap", true); + TestEventListener rootListener("root"); + TestEventListener rootCapListener("rootCap"); + TestEventListener textListener("text"); + TestEventListener textCapListener("textCap"); + + pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMCharacterDataModified, &docCapListener, true); + pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMCharacterDataModified, &rootCapListener, true); + pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textListener, false); + pText->addEventListener(MutationEvent::DOMCharacterDataModified, &textCapListener, true); + + TestEventListener::reset(); + + pText->setData("modified"); + + const XMLString& log = TestEventListener::log(); + assert (log == "docCap:DOMCharacterDataModified:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:::text:modified\n"); +} + + +void EventTest::testAttributes() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener rootListener("root"); + pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false); + + pRoot->setAttribute("a1", "v1"); + + const XMLString& log = TestEventListener::log(); + assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a1:a1::v1\n"); + + TestEventListener::reset(); + pRoot->setAttribute("a1", "V1"); + assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:MODIFICATION:a1:a1:v1:V1\n"); + + TestEventListener::reset(); + pRoot->setAttribute("a2", "v2"); + assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:ADDITION:a2:a2::v2\n"); + + TestEventListener::reset(); + pRoot->removeAttribute("a1"); + assert (log == "root:DOMAttrModified:AT_TARGET:root:root:B:-:REMOVAL:a1:a1:V1:\n"); +} + + +void EventTest::testAddRemoveInEvent() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + TestEventListener docListener("doc", false, true, false); + TestEventListener docCapListener("docCap", false, true, true); + TestEventListener rootListener("root", false, true, false); + TestEventListener rootCapListener("rootCap", false, true, true); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docListener, false); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docListener, false); + + pDoc->addEventListener(MutationEvent::DOMSubtreeModified, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInserted, &docCapListener, true); + pDoc->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &docCapListener, true); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootListener, false); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootListener, false); + + pRoot->addEventListener(MutationEvent::DOMSubtreeModified, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInserted, &rootCapListener, true); + pRoot->addEventListener(MutationEvent::DOMNodeInsertedIntoDocument, &rootCapListener, true); + + pDoc->appendChild(pRoot); + + const XMLString& log = TestEventListener::log(); + assert (log == + "docCap:DOMNodeInserted:CAPTURING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "rootCap:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "root:DOMNodeInserted:AT_TARGET:root:root:B:-:MODIFICATION:#document:::\n" + "doc:DOMNodeInserted:BUBBLING_PHASE:root:#document:B:-:MODIFICATION:#document:::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:root:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "root:DOMNodeInsertedIntoDocument:AT_TARGET:root:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:AT_TARGET:#document:#document:B:-:MODIFICATION::::\n" + ); + + TestEventListener::reset(); + + AutoPtr pText = pDoc->createTextNode("text"); + pRoot->appendChild(pText); + + assert (log == + "docCap:DOMNodeInserted:CAPTURING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "rootCap:DOMNodeInserted:CAPTURING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "root:DOMNodeInserted:BUBBLING_PHASE:#text:root:B:-:MODIFICATION:root:::\n" + "doc:DOMNodeInserted:BUBBLING_PHASE:#text:#document:B:-:MODIFICATION:root:::\n" + "docCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:#document:-:-:MODIFICATION::::\n" + "rootCap:DOMNodeInsertedIntoDocument:CAPTURING_PHASE:#text:root:-:-:MODIFICATION::::\n" + "docCap:DOMSubtreeModified:CAPTURING_PHASE:root:#document:B:-:MODIFICATION::::\n" + "rootCap:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "root:DOMSubtreeModified:AT_TARGET:root:root:B:-:MODIFICATION::::\n" + "doc:DOMSubtreeModified:BUBBLING_PHASE:root:#document:B:-:MODIFICATION::::\n" + ); +} + + +void EventTest::testSuspended() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + pDoc->suspendEvents(); + + TestEventListener rootListener("root"); + pRoot->addEventListener(MutationEvent::DOMAttrModified, &rootListener, false); + + pRoot->setAttribute("a1", "v1"); + + const XMLString& log = TestEventListener::log(); + assert (log.empty()); + + TestEventListener::reset(); + pRoot->setAttribute("a1", "V1"); + assert (log.empty()); + + TestEventListener::reset(); + pRoot->setAttribute("a2", "v2"); + assert (log.empty()); + + TestEventListener::reset(); + pRoot->removeAttribute("a1"); + assert (log.empty()); +} + + +void EventTest::setUp() +{ + TestEventListener::reset(); +} + + +void EventTest::tearDown() +{ +} + + +CppUnit::Test* EventTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("EventTest"); + + CppUnit_addTest(pSuite, EventTest, testInsert); + CppUnit_addTest(pSuite, EventTest, testInsertSubtree); + CppUnit_addTest(pSuite, EventTest, testRemove); + CppUnit_addTest(pSuite, EventTest, testRemoveSubtree); + CppUnit_addTest(pSuite, EventTest, testCharacterData); + CppUnit_addTest(pSuite, EventTest, testCancel); + CppUnit_addTest(pSuite, EventTest, testAttributes); + CppUnit_addTest(pSuite, EventTest, testAddRemoveInEvent); + CppUnit_addTest(pSuite, EventTest, testSuspended); + + return pSuite; +} diff --git a/XML/testsuite/src/EventTest.h b/XML/testsuite/src/EventTest.h index a894be655..cf751990d 100644 --- a/XML/testsuite/src/EventTest.h +++ b/XML/testsuite/src/EventTest.h @@ -1,68 +1,68 @@ -// -// EventTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/EventTest.h#1 $ -// -// Definition of the EventTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef EventTest_INCLUDED -#define EventTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class EventTest: public CppUnit::TestCase -{ -public: - EventTest(const std::string& name); - ~EventTest(); - - void testInsert(); - void testInsertSubtree(); - void testRemove(); - void testRemoveSubtree(); - void testCharacterData(); - void testCancel(); - void testAttributes(); - void testAddRemoveInEvent(); - void testSuspended(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // EventTest_INCLUDED +// +// EventTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/EventTest.h#1 $ +// +// Definition of the EventTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef EventTest_INCLUDED +#define EventTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class EventTest: public CppUnit::TestCase +{ +public: + EventTest(const std::string& name); + ~EventTest(); + + void testInsert(); + void testInsertSubtree(); + void testRemove(); + void testRemoveSubtree(); + void testCharacterData(); + void testCancel(); + void testAttributes(); + void testAddRemoveInEvent(); + void testSuspended(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // EventTest_INCLUDED diff --git a/XML/testsuite/src/NamePoolTest.cpp b/XML/testsuite/src/NamePoolTest.cpp index 2c69c2670..032dafab2 100644 --- a/XML/testsuite/src/NamePoolTest.cpp +++ b/XML/testsuite/src/NamePoolTest.cpp @@ -1,94 +1,94 @@ -// -// NamePoolTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NamePoolTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NamePoolTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/XML/NamePool.h" -#include "Poco/XML/Name.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::NamePool; -using Poco::XML::Name; -using Poco::XML::AutoPtr; - - -NamePoolTest::NamePoolTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NamePoolTest::~NamePoolTest() -{ -} - - -void NamePoolTest::testNamePool() -{ - AutoPtr pool = new NamePool; - const Name* pName = 0; - Name name("pre:local", "http://www.appinf.com"); - - pName = &pool->insert(name); - const Name* pName2 = &pool->insert("pre:local", "http://www.appinf.com", "local"); - assert (pName == pName2); - - pName2 = &pool->insert("pre:local2", "http://www.appinf.com", "local2"); - assert (pName2 != pName); - - pName2 = &pool->insert(name); - assert (pName2 == pName); - - pName2 = &pool->insert(*pName); - assert (pName2 == pName); -} - - -void NamePoolTest::setUp() -{ -} - - -void NamePoolTest::tearDown() -{ -} - - -CppUnit::Test* NamePoolTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamePoolTest"); - - CppUnit_addTest(pSuite, NamePoolTest, testNamePool); - - return pSuite; -} +// +// NamePoolTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NamePoolTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NamePoolTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/XML/NamePool.h" +#include "Poco/XML/Name.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::NamePool; +using Poco::XML::Name; +using Poco::XML::AutoPtr; + + +NamePoolTest::NamePoolTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NamePoolTest::~NamePoolTest() +{ +} + + +void NamePoolTest::testNamePool() +{ + AutoPtr pool = new NamePool; + const Name* pName = 0; + Name name("pre:local", "http://www.appinf.com"); + + pName = &pool->insert(name); + const Name* pName2 = &pool->insert("pre:local", "http://www.appinf.com", "local"); + assert (pName == pName2); + + pName2 = &pool->insert("pre:local2", "http://www.appinf.com", "local2"); + assert (pName2 != pName); + + pName2 = &pool->insert(name); + assert (pName2 == pName); + + pName2 = &pool->insert(*pName); + assert (pName2 == pName); +} + + +void NamePoolTest::setUp() +{ +} + + +void NamePoolTest::tearDown() +{ +} + + +CppUnit::Test* NamePoolTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamePoolTest"); + + CppUnit_addTest(pSuite, NamePoolTest, testNamePool); + + return pSuite; +} diff --git a/XML/testsuite/src/NamePoolTest.h b/XML/testsuite/src/NamePoolTest.h index 45ee6dd8f..7b342dcf0 100644 --- a/XML/testsuite/src/NamePoolTest.h +++ b/XML/testsuite/src/NamePoolTest.h @@ -1,60 +1,60 @@ -// -// NamePoolTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NamePoolTest.h#1 $ -// -// Definition of the NamePoolTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NamePoolTest_INCLUDED -#define NamePoolTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NamePoolTest: public CppUnit::TestCase -{ -public: - NamePoolTest(const std::string& name); - ~NamePoolTest(); - - void testNamePool(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NamePoolTest_INCLUDED +// +// NamePoolTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NamePoolTest.h#1 $ +// +// Definition of the NamePoolTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NamePoolTest_INCLUDED +#define NamePoolTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NamePoolTest: public CppUnit::TestCase +{ +public: + NamePoolTest(const std::string& name); + ~NamePoolTest(); + + void testNamePool(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NamePoolTest_INCLUDED diff --git a/XML/testsuite/src/NameTest.cpp b/XML/testsuite/src/NameTest.cpp index 81ba60803..60ef072ad 100644 --- a/XML/testsuite/src/NameTest.cpp +++ b/XML/testsuite/src/NameTest.cpp @@ -1,193 +1,193 @@ -// -// NameTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NameTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NameTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/XML/Name.h" - - -using Poco::XML::Name; - - -NameTest::NameTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NameTest::~NameTest() -{ -} - - -void NameTest::testSplit() -{ - std::string qname = "name"; - std::string prefix; - std::string local; - Name::split(qname, prefix, local); - assert (prefix.empty()); - assert (local == "name"); - - qname = "p:l"; - Name::split(qname, prefix, local); - assert (prefix == "p"); - assert (local == "l"); - - qname = "pre:local"; - Name::split(qname, prefix, local); - assert (prefix == "pre"); - assert (local == "local"); -} - - -void NameTest::testLocalName() -{ - std::string qname = "name"; - std::string local = Name::localName(qname); - assert (local == "name"); - qname = "p:l"; - local = Name::localName(qname); - assert (local == "l"); - qname = "pre:local"; - local = Name::localName(qname); - assert (local == "local"); -} - - -void NameTest::testPrefix() -{ - std::string qname = "name"; - std::string prefix = Name::prefix(qname); - assert (prefix.empty()); - qname = "p:l"; - prefix = Name::prefix(qname); - assert (prefix == "p"); - qname = "pre:local"; - prefix = Name::prefix(qname); - assert (prefix == "pre"); -} - - -void NameTest::testName() -{ - std::string qname = "name"; - Name name(qname); - assert (name.qname() == "name"); - assert (name.prefix().empty()); - assert (name.namespaceURI().empty()); - assert (name.localName().empty()); - - qname.clear(); - name.assign(qname, "http://www.appinf.com/", "local"); - assert (name.qname().empty()); - assert (name.prefix().empty()); - assert (name.namespaceURI() == "http://www.appinf.com/"); - assert (name.localName() == "local"); - - Name name2("pre:local", "http://www.appinf.com/"); - assert (name2.qname() == "pre:local"); - assert (name2.prefix() == "pre"); - assert (name2.namespaceURI() == "http://www.appinf.com/"); - assert (name2.localName() == "local"); - - name2.assign("PRE:Local", "http://www.appinf.com/"); - assert (name2.qname() == "PRE:Local"); - assert (name2.prefix() == "PRE"); - assert (name2.namespaceURI() == "http://www.appinf.com/"); - assert (name2.localName() == "Local"); -} - - -void NameTest::testCompare() -{ - Name n1("pre:local"); - Name n2(n1); - Name n3("pre:local2"); - - assert (n1.equals(n2)); - assert (!n1.equals(n3)); - - n1.assign("pre:local", "http://www.appinf.com", "local"); - n2.assign("pre:local", "http://www.appinf.com", "local"); - n3.assign("pre:local2", "http://www.appinf.com", "local2"); - - assert (n1.equals(n2)); - assert (!n1.equals(n3)); - - assert (n1.equals("pre:local", "http://www.appinf.com", "local")); - assert (!n1.equals("pre:local", "", "")); - assert (n1.equalsWeakly("pre:local", "", "")); - assert (!n1.equalsWeakly("pre:local2", "", "")); - assert (!n1.equals("", "http://www.appinf.com", "local")); - assert (n1.equalsWeakly("", "http://www.appinf.com", "local")); - assert (!n1.equalsWeakly("", "http://www.appinf.com", "local2")); -} - - -void NameTest::testSwap() -{ - Name n1("ns:name1", "http://www.appinf.com"); - Name n2("ns:name2", "http://www.foobar.com"); - n1.swap(n2); - assert (n1.qname() == "ns:name2"); - assert (n1.namespaceURI() == "http://www.foobar.com"); - assert (n1.localName() == "name2"); - assert (n2.qname() == "ns:name1"); - assert (n2.namespaceURI() == "http://www.appinf.com"); - assert (n2.localName() == "name1"); -} - - -void NameTest::setUp() -{ -} - - -void NameTest::tearDown() -{ -} - - -CppUnit::Test* NameTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameTest"); - - CppUnit_addTest(pSuite, NameTest, testSplit); - CppUnit_addTest(pSuite, NameTest, testLocalName); - CppUnit_addTest(pSuite, NameTest, testPrefix); - CppUnit_addTest(pSuite, NameTest, testName); - CppUnit_addTest(pSuite, NameTest, testCompare); - CppUnit_addTest(pSuite, NameTest, testSwap); - - return pSuite; -} +// +// NameTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NameTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NameTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/XML/Name.h" + + +using Poco::XML::Name; + + +NameTest::NameTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NameTest::~NameTest() +{ +} + + +void NameTest::testSplit() +{ + std::string qname = "name"; + std::string prefix; + std::string local; + Name::split(qname, prefix, local); + assert (prefix.empty()); + assert (local == "name"); + + qname = "p:l"; + Name::split(qname, prefix, local); + assert (prefix == "p"); + assert (local == "l"); + + qname = "pre:local"; + Name::split(qname, prefix, local); + assert (prefix == "pre"); + assert (local == "local"); +} + + +void NameTest::testLocalName() +{ + std::string qname = "name"; + std::string local = Name::localName(qname); + assert (local == "name"); + qname = "p:l"; + local = Name::localName(qname); + assert (local == "l"); + qname = "pre:local"; + local = Name::localName(qname); + assert (local == "local"); +} + + +void NameTest::testPrefix() +{ + std::string qname = "name"; + std::string prefix = Name::prefix(qname); + assert (prefix.empty()); + qname = "p:l"; + prefix = Name::prefix(qname); + assert (prefix == "p"); + qname = "pre:local"; + prefix = Name::prefix(qname); + assert (prefix == "pre"); +} + + +void NameTest::testName() +{ + std::string qname = "name"; + Name name(qname); + assert (name.qname() == "name"); + assert (name.prefix().empty()); + assert (name.namespaceURI().empty()); + assert (name.localName().empty()); + + qname.clear(); + name.assign(qname, "http://www.appinf.com/", "local"); + assert (name.qname().empty()); + assert (name.prefix().empty()); + assert (name.namespaceURI() == "http://www.appinf.com/"); + assert (name.localName() == "local"); + + Name name2("pre:local", "http://www.appinf.com/"); + assert (name2.qname() == "pre:local"); + assert (name2.prefix() == "pre"); + assert (name2.namespaceURI() == "http://www.appinf.com/"); + assert (name2.localName() == "local"); + + name2.assign("PRE:Local", "http://www.appinf.com/"); + assert (name2.qname() == "PRE:Local"); + assert (name2.prefix() == "PRE"); + assert (name2.namespaceURI() == "http://www.appinf.com/"); + assert (name2.localName() == "Local"); +} + + +void NameTest::testCompare() +{ + Name n1("pre:local"); + Name n2(n1); + Name n3("pre:local2"); + + assert (n1.equals(n2)); + assert (!n1.equals(n3)); + + n1.assign("pre:local", "http://www.appinf.com", "local"); + n2.assign("pre:local", "http://www.appinf.com", "local"); + n3.assign("pre:local2", "http://www.appinf.com", "local2"); + + assert (n1.equals(n2)); + assert (!n1.equals(n3)); + + assert (n1.equals("pre:local", "http://www.appinf.com", "local")); + assert (!n1.equals("pre:local", "", "")); + assert (n1.equalsWeakly("pre:local", "", "")); + assert (!n1.equalsWeakly("pre:local2", "", "")); + assert (!n1.equals("", "http://www.appinf.com", "local")); + assert (n1.equalsWeakly("", "http://www.appinf.com", "local")); + assert (!n1.equalsWeakly("", "http://www.appinf.com", "local2")); +} + + +void NameTest::testSwap() +{ + Name n1("ns:name1", "http://www.appinf.com"); + Name n2("ns:name2", "http://www.foobar.com"); + n1.swap(n2); + assert (n1.qname() == "ns:name2"); + assert (n1.namespaceURI() == "http://www.foobar.com"); + assert (n1.localName() == "name2"); + assert (n2.qname() == "ns:name1"); + assert (n2.namespaceURI() == "http://www.appinf.com"); + assert (n2.localName() == "name1"); +} + + +void NameTest::setUp() +{ +} + + +void NameTest::tearDown() +{ +} + + +CppUnit::Test* NameTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameTest"); + + CppUnit_addTest(pSuite, NameTest, testSplit); + CppUnit_addTest(pSuite, NameTest, testLocalName); + CppUnit_addTest(pSuite, NameTest, testPrefix); + CppUnit_addTest(pSuite, NameTest, testName); + CppUnit_addTest(pSuite, NameTest, testCompare); + CppUnit_addTest(pSuite, NameTest, testSwap); + + return pSuite; +} diff --git a/XML/testsuite/src/NameTest.h b/XML/testsuite/src/NameTest.h index 8f02276ba..81a0b3829 100644 --- a/XML/testsuite/src/NameTest.h +++ b/XML/testsuite/src/NameTest.h @@ -1,65 +1,65 @@ -// -// NameTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NameTest.h#1 $ -// -// Definition of the NameTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NameTest_INCLUDED -#define NameTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NameTest: public CppUnit::TestCase -{ -public: - NameTest(const std::string& name); - ~NameTest(); - - void testSplit(); - void testLocalName(); - void testPrefix(); - void testName(); - void testCompare(); - void testSwap(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NameTest_INCLUDED +// +// NameTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NameTest.h#1 $ +// +// Definition of the NameTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NameTest_INCLUDED +#define NameTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NameTest: public CppUnit::TestCase +{ +public: + NameTest(const std::string& name); + ~NameTest(); + + void testSplit(); + void testLocalName(); + void testPrefix(); + void testName(); + void testCompare(); + void testSwap(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NameTest_INCLUDED diff --git a/XML/testsuite/src/NamespaceSupportTest.cpp b/XML/testsuite/src/NamespaceSupportTest.cpp index 2349f40f9..8d4531bde 100644 --- a/XML/testsuite/src/NamespaceSupportTest.cpp +++ b/XML/testsuite/src/NamespaceSupportTest.cpp @@ -1,212 +1,212 @@ -// -// NamespaceSupportTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NamespaceSupportTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NamespaceSupportTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/SAX/NamespaceSupport.h" - - -using Poco::XML::NamespaceSupport; - - -NamespaceSupportTest::NamespaceSupportTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NamespaceSupportTest::~NamespaceSupportTest() -{ -} - - -void NamespaceSupportTest::testNamespaceSupport() -{ - NamespaceSupport ns; - NamespaceSupport::PrefixSet prefixes; - ns.getDeclaredPrefixes(prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("xml") != prefixes.end()); - assert (prefixes.find("xmlns") != prefixes.end()); - - ns.getPrefixes(prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("xml") != prefixes.end()); - assert (prefixes.find("xmlns") != prefixes.end()); - - ns.pushContext(); - ns.declarePrefix("ns1", "urn:ns1"); - ns.declarePrefix("ns2", "urn:ns2"); - - ns.getDeclaredPrefixes(prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("ns1") != prefixes.end()); - assert (prefixes.find("ns2") != prefixes.end()); - - ns.pushContext(); - ns.declarePrefix("ns3", "urn:ns3"); - - ns.getDeclaredPrefixes(prefixes); - assert (prefixes.size() == 1); - assert (prefixes.find("ns3") != prefixes.end()); - - ns.getPrefixes(prefixes); - assert (prefixes.size() == 5); - assert (prefixes.find("xml") != prefixes.end()); - assert (prefixes.find("xmlns") != prefixes.end()); - assert (prefixes.find("ns1") != prefixes.end()); - assert (prefixes.find("ns2") != prefixes.end()); - assert (prefixes.find("ns3") != prefixes.end()); - - ns.popContext(); - ns.getDeclaredPrefixes(prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("ns1") != prefixes.end()); - assert (prefixes.find("ns2") != prefixes.end()); - - assert (ns.isMapped("urn:ns1")); - assert (ns.isMapped("urn:ns2")); - assert (ns.isMapped("http://www.w3.org/XML/1998/namespace")); - assert (!ns.isMapped("urn:ns3")); - - ns.getPrefixes("urn:ns2", prefixes); - assert (prefixes.size() == 1); - assert (prefixes.find("ns2") != prefixes.end()); - - ns.pushContext(); - ns.declarePrefix("", "urn:ns3"); - ns.declarePrefix("NS2", "urn:ns2"); - - ns.getPrefixes("urn:ns2", prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("ns2") != prefixes.end()); - assert (prefixes.find("NS2") != prefixes.end()); - - ns.getPrefixes(prefixes); - assert (prefixes.size() == 5); - assert (prefixes.find("xml") != prefixes.end()); - assert (prefixes.find("xmlns") != prefixes.end()); - assert (prefixes.find("ns1") != prefixes.end()); - assert (prefixes.find("ns2") != prefixes.end()); - assert (prefixes.find("NS2") != prefixes.end()); - - ns.getDeclaredPrefixes(prefixes); - assert (prefixes.size() == 2); - assert (prefixes.find("") != prefixes.end()); - assert (prefixes.find("NS2") != prefixes.end()); - - assert (ns.getPrefix("urn:ns3") == ""); - assert (ns.getPrefix("urn:ns2") == "NS2"); - assert (ns.getPrefix("urn:ns4") == ""); - - assert (ns.isMapped("urn:ns3")); - assert (ns.isMapped("urn:ns2")); - assert (!ns.isMapped("urn:ns4")); - - assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace"); - assert (ns.getURI("ns1") == "urn:ns1"); - assert (ns.getURI("") == "urn:ns3"); - assert (ns.getURI("NS2") == "urn:ns2"); - - std::string localName; - std::string namespaceURI; - bool declared = ns.processName("elem", namespaceURI, localName, false); - assert (declared); - assert (localName == "elem"); - assert (namespaceURI == "urn:ns3"); - - declared = ns.processName("NS2:elem", namespaceURI, localName, false); - assert (declared); - assert (localName == "elem"); - assert (namespaceURI == "urn:ns2"); - - declared = ns.processName("ns3:elem", namespaceURI, localName, false); - assert (!declared); - assert (localName == "elem"); - assert (namespaceURI == ""); - - declared = ns.processName("ns2:attr", namespaceURI, localName, true); - assert (declared); - assert (localName == "attr"); - assert (namespaceURI == "urn:ns2"); - - declared = ns.processName("attr", namespaceURI, localName, true); - assert (declared); - assert (localName == "attr"); - assert (namespaceURI == ""); - - declared = ns.processName("ns3:attr", namespaceURI, localName, true); - assert (!declared); - assert (localName == "attr"); - assert (namespaceURI == ""); - - ns.popContext(); - assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace"); - assert (ns.getURI("ns1") == "urn:ns1"); - assert (ns.getURI("") == ""); - assert (ns.getURI("NS2") == ""); - - declared = ns.processName("elem", namespaceURI, localName, false); - assert (declared); - assert (localName == "elem"); - assert (namespaceURI == ""); - - declared = ns.processName("ns2:elem", namespaceURI, localName, false); - assert (declared); - assert (localName == "elem"); - assert (namespaceURI == "urn:ns2"); - - declared = ns.processName("ns3:elem", namespaceURI, localName, false); - assert (!declared); - assert (localName == "elem"); - assert (namespaceURI == ""); -} - - -void NamespaceSupportTest::setUp() -{ -} - - -void NamespaceSupportTest::tearDown() -{ -} - - -CppUnit::Test* NamespaceSupportTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamespaceSupportTest"); - - CppUnit_addTest(pSuite, NamespaceSupportTest, testNamespaceSupport); - - return pSuite; -} +// +// NamespaceSupportTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NamespaceSupportTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NamespaceSupportTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/SAX/NamespaceSupport.h" + + +using Poco::XML::NamespaceSupport; + + +NamespaceSupportTest::NamespaceSupportTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NamespaceSupportTest::~NamespaceSupportTest() +{ +} + + +void NamespaceSupportTest::testNamespaceSupport() +{ + NamespaceSupport ns; + NamespaceSupport::PrefixSet prefixes; + ns.getDeclaredPrefixes(prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("xml") != prefixes.end()); + assert (prefixes.find("xmlns") != prefixes.end()); + + ns.getPrefixes(prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("xml") != prefixes.end()); + assert (prefixes.find("xmlns") != prefixes.end()); + + ns.pushContext(); + ns.declarePrefix("ns1", "urn:ns1"); + ns.declarePrefix("ns2", "urn:ns2"); + + ns.getDeclaredPrefixes(prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("ns1") != prefixes.end()); + assert (prefixes.find("ns2") != prefixes.end()); + + ns.pushContext(); + ns.declarePrefix("ns3", "urn:ns3"); + + ns.getDeclaredPrefixes(prefixes); + assert (prefixes.size() == 1); + assert (prefixes.find("ns3") != prefixes.end()); + + ns.getPrefixes(prefixes); + assert (prefixes.size() == 5); + assert (prefixes.find("xml") != prefixes.end()); + assert (prefixes.find("xmlns") != prefixes.end()); + assert (prefixes.find("ns1") != prefixes.end()); + assert (prefixes.find("ns2") != prefixes.end()); + assert (prefixes.find("ns3") != prefixes.end()); + + ns.popContext(); + ns.getDeclaredPrefixes(prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("ns1") != prefixes.end()); + assert (prefixes.find("ns2") != prefixes.end()); + + assert (ns.isMapped("urn:ns1")); + assert (ns.isMapped("urn:ns2")); + assert (ns.isMapped("http://www.w3.org/XML/1998/namespace")); + assert (!ns.isMapped("urn:ns3")); + + ns.getPrefixes("urn:ns2", prefixes); + assert (prefixes.size() == 1); + assert (prefixes.find("ns2") != prefixes.end()); + + ns.pushContext(); + ns.declarePrefix("", "urn:ns3"); + ns.declarePrefix("NS2", "urn:ns2"); + + ns.getPrefixes("urn:ns2", prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("ns2") != prefixes.end()); + assert (prefixes.find("NS2") != prefixes.end()); + + ns.getPrefixes(prefixes); + assert (prefixes.size() == 5); + assert (prefixes.find("xml") != prefixes.end()); + assert (prefixes.find("xmlns") != prefixes.end()); + assert (prefixes.find("ns1") != prefixes.end()); + assert (prefixes.find("ns2") != prefixes.end()); + assert (prefixes.find("NS2") != prefixes.end()); + + ns.getDeclaredPrefixes(prefixes); + assert (prefixes.size() == 2); + assert (prefixes.find("") != prefixes.end()); + assert (prefixes.find("NS2") != prefixes.end()); + + assert (ns.getPrefix("urn:ns3") == ""); + assert (ns.getPrefix("urn:ns2") == "NS2"); + assert (ns.getPrefix("urn:ns4") == ""); + + assert (ns.isMapped("urn:ns3")); + assert (ns.isMapped("urn:ns2")); + assert (!ns.isMapped("urn:ns4")); + + assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace"); + assert (ns.getURI("ns1") == "urn:ns1"); + assert (ns.getURI("") == "urn:ns3"); + assert (ns.getURI("NS2") == "urn:ns2"); + + std::string localName; + std::string namespaceURI; + bool declared = ns.processName("elem", namespaceURI, localName, false); + assert (declared); + assert (localName == "elem"); + assert (namespaceURI == "urn:ns3"); + + declared = ns.processName("NS2:elem", namespaceURI, localName, false); + assert (declared); + assert (localName == "elem"); + assert (namespaceURI == "urn:ns2"); + + declared = ns.processName("ns3:elem", namespaceURI, localName, false); + assert (!declared); + assert (localName == "elem"); + assert (namespaceURI == ""); + + declared = ns.processName("ns2:attr", namespaceURI, localName, true); + assert (declared); + assert (localName == "attr"); + assert (namespaceURI == "urn:ns2"); + + declared = ns.processName("attr", namespaceURI, localName, true); + assert (declared); + assert (localName == "attr"); + assert (namespaceURI == ""); + + declared = ns.processName("ns3:attr", namespaceURI, localName, true); + assert (!declared); + assert (localName == "attr"); + assert (namespaceURI == ""); + + ns.popContext(); + assert (ns.getURI("xml") == "http://www.w3.org/XML/1998/namespace"); + assert (ns.getURI("ns1") == "urn:ns1"); + assert (ns.getURI("") == ""); + assert (ns.getURI("NS2") == ""); + + declared = ns.processName("elem", namespaceURI, localName, false); + assert (declared); + assert (localName == "elem"); + assert (namespaceURI == ""); + + declared = ns.processName("ns2:elem", namespaceURI, localName, false); + assert (declared); + assert (localName == "elem"); + assert (namespaceURI == "urn:ns2"); + + declared = ns.processName("ns3:elem", namespaceURI, localName, false); + assert (!declared); + assert (localName == "elem"); + assert (namespaceURI == ""); +} + + +void NamespaceSupportTest::setUp() +{ +} + + +void NamespaceSupportTest::tearDown() +{ +} + + +CppUnit::Test* NamespaceSupportTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NamespaceSupportTest"); + + CppUnit_addTest(pSuite, NamespaceSupportTest, testNamespaceSupport); + + return pSuite; +} diff --git a/XML/testsuite/src/NamespaceSupportTest.h b/XML/testsuite/src/NamespaceSupportTest.h index 0f570b32c..12038761b 100644 --- a/XML/testsuite/src/NamespaceSupportTest.h +++ b/XML/testsuite/src/NamespaceSupportTest.h @@ -1,60 +1,60 @@ -// -// NamespaceSupportTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NamespaceSupportTest.h#1 $ -// -// Definition of the NamespaceSupportTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NamespaceSupportTest_INCLUDED -#define NamespaceSupportTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NamespaceSupportTest: public CppUnit::TestCase -{ -public: - NamespaceSupportTest(const std::string& name); - ~NamespaceSupportTest(); - - void testNamespaceSupport(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NamespaceSupportTest_INCLUDED +// +// NamespaceSupportTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NamespaceSupportTest.h#1 $ +// +// Definition of the NamespaceSupportTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NamespaceSupportTest_INCLUDED +#define NamespaceSupportTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NamespaceSupportTest: public CppUnit::TestCase +{ +public: + NamespaceSupportTest(const std::string& name); + ~NamespaceSupportTest(); + + void testNamespaceSupport(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NamespaceSupportTest_INCLUDED diff --git a/XML/testsuite/src/NodeAppenderTest.cpp b/XML/testsuite/src/NodeAppenderTest.cpp index 93f71348b..3f31c4334 100644 --- a/XML/testsuite/src/NodeAppenderTest.cpp +++ b/XML/testsuite/src/NodeAppenderTest.cpp @@ -1,162 +1,162 @@ -// -// NodeAppenderTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NodeAppenderTest.cpp#1 $ -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NodeAppenderTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/NodeAppender.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/DocumentFragment.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::NodeAppender; -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::DocumentFragment; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -NodeAppenderTest::NodeAppenderTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NodeAppenderTest::~NodeAppenderTest() -{ -} - - -void NodeAppenderTest::testAppendNode() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - pDoc->appendChild(pRoot); - - NodeAppender appender(pRoot); - - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pElem3 = pDoc->createElement("elem"); - - appender.appendChild(pElem1); - appender.appendChild(pElem2); - appender.appendChild(pElem3); - - assert (pRoot->firstChild() == pElem1); - assert (pRoot->lastChild() == pElem3); - - assert (pElem1->nextSibling() == pElem2); - assert (pElem2->nextSibling() == pElem3); - assert (pElem3->nextSibling() == 0); - - assert (pElem1->previousSibling() == 0); - assert (pElem2->previousSibling() == pElem1); - assert (pElem3->previousSibling() == pElem2); - - assert (pElem1->parentNode() == pRoot); - assert (pElem2->parentNode() == pRoot); - assert (pElem3->parentNode() == pRoot); -} - - -void NodeAppenderTest::testAppendNodeList() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - pDoc->appendChild(pRoot); - - NodeAppender appender(pRoot); - - AutoPtr pFrag1 = pDoc->createDocumentFragment(); - AutoPtr pFrag2 = pDoc->createDocumentFragment(); - AutoPtr pFrag3 = pDoc->createDocumentFragment(); - - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pElem3 = pDoc->createElement("elem"); - AutoPtr pElem4 = pDoc->createElement("elem"); - - pFrag2->appendChild(pElem1); - pFrag2->appendChild(pElem2); - pFrag2->appendChild(pElem3); - - pFrag3->appendChild(pElem4); - - appender.appendChild(pFrag1); - assert (pRoot->firstChild() == 0); - - appender.appendChild(pFrag2); - assert (pRoot->firstChild() == pElem1); - assert (pRoot->lastChild() == pElem3); - - assert (pElem1->nextSibling() == pElem2); - assert (pElem2->nextSibling() == pElem3); - assert (pElem3->nextSibling() == 0); - - assert (pElem1->previousSibling() == 0); - assert (pElem2->previousSibling() == pElem1); - assert (pElem3->previousSibling() == pElem2); - - assert (pElem1->parentNode() == pRoot); - assert (pElem2->parentNode() == pRoot); - assert (pElem3->parentNode() == pRoot); - - appender.appendChild(pFrag3); - assert (pRoot->lastChild() == pElem4); - assert (pElem4->parentNode() == pRoot); - assert (pElem3->nextSibling() == pElem4); - assert (pElem4->previousSibling() == pElem3); -} - - -void NodeAppenderTest::setUp() -{ -} - - -void NodeAppenderTest::tearDown() -{ -} - - -CppUnit::Test* NodeAppenderTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeAppenderTest"); - - CppUnit_addTest(pSuite, NodeAppenderTest, testAppendNode); - CppUnit_addTest(pSuite, NodeAppenderTest, testAppendNodeList); - - return pSuite; -} +// +// NodeAppenderTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NodeAppenderTest.cpp#1 $ +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NodeAppenderTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/NodeAppender.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/DocumentFragment.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::NodeAppender; +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::DocumentFragment; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +NodeAppenderTest::NodeAppenderTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NodeAppenderTest::~NodeAppenderTest() +{ +} + + +void NodeAppenderTest::testAppendNode() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + pDoc->appendChild(pRoot); + + NodeAppender appender(pRoot); + + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pElem3 = pDoc->createElement("elem"); + + appender.appendChild(pElem1); + appender.appendChild(pElem2); + appender.appendChild(pElem3); + + assert (pRoot->firstChild() == pElem1); + assert (pRoot->lastChild() == pElem3); + + assert (pElem1->nextSibling() == pElem2); + assert (pElem2->nextSibling() == pElem3); + assert (pElem3->nextSibling() == 0); + + assert (pElem1->previousSibling() == 0); + assert (pElem2->previousSibling() == pElem1); + assert (pElem3->previousSibling() == pElem2); + + assert (pElem1->parentNode() == pRoot); + assert (pElem2->parentNode() == pRoot); + assert (pElem3->parentNode() == pRoot); +} + + +void NodeAppenderTest::testAppendNodeList() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + pDoc->appendChild(pRoot); + + NodeAppender appender(pRoot); + + AutoPtr pFrag1 = pDoc->createDocumentFragment(); + AutoPtr pFrag2 = pDoc->createDocumentFragment(); + AutoPtr pFrag3 = pDoc->createDocumentFragment(); + + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pElem3 = pDoc->createElement("elem"); + AutoPtr pElem4 = pDoc->createElement("elem"); + + pFrag2->appendChild(pElem1); + pFrag2->appendChild(pElem2); + pFrag2->appendChild(pElem3); + + pFrag3->appendChild(pElem4); + + appender.appendChild(pFrag1); + assert (pRoot->firstChild() == 0); + + appender.appendChild(pFrag2); + assert (pRoot->firstChild() == pElem1); + assert (pRoot->lastChild() == pElem3); + + assert (pElem1->nextSibling() == pElem2); + assert (pElem2->nextSibling() == pElem3); + assert (pElem3->nextSibling() == 0); + + assert (pElem1->previousSibling() == 0); + assert (pElem2->previousSibling() == pElem1); + assert (pElem3->previousSibling() == pElem2); + + assert (pElem1->parentNode() == pRoot); + assert (pElem2->parentNode() == pRoot); + assert (pElem3->parentNode() == pRoot); + + appender.appendChild(pFrag3); + assert (pRoot->lastChild() == pElem4); + assert (pElem4->parentNode() == pRoot); + assert (pElem3->nextSibling() == pElem4); + assert (pElem4->previousSibling() == pElem3); +} + + +void NodeAppenderTest::setUp() +{ +} + + +void NodeAppenderTest::tearDown() +{ +} + + +CppUnit::Test* NodeAppenderTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeAppenderTest"); + + CppUnit_addTest(pSuite, NodeAppenderTest, testAppendNode); + CppUnit_addTest(pSuite, NodeAppenderTest, testAppendNodeList); + + return pSuite; +} diff --git a/XML/testsuite/src/NodeAppenderTest.h b/XML/testsuite/src/NodeAppenderTest.h index ce652c24e..41747e016 100644 --- a/XML/testsuite/src/NodeAppenderTest.h +++ b/XML/testsuite/src/NodeAppenderTest.h @@ -1,61 +1,61 @@ -// -// NodeAppenderTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NodeAppenderTest.h#1 $ -// -// Definition of the NodeAppenderTest class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NodeAppenderTest_INCLUDED -#define NodeAppenderTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NodeAppenderTest: public CppUnit::TestCase -{ -public: - NodeAppenderTest(const std::string& name); - ~NodeAppenderTest(); - - void testAppendNode(); - void testAppendNodeList(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NodeAppenderTest_INCLUDED +// +// NodeAppenderTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NodeAppenderTest.h#1 $ +// +// Definition of the NodeAppenderTest class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NodeAppenderTest_INCLUDED +#define NodeAppenderTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NodeAppenderTest: public CppUnit::TestCase +{ +public: + NodeAppenderTest(const std::string& name); + ~NodeAppenderTest(); + + void testAppendNode(); + void testAppendNodeList(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NodeAppenderTest_INCLUDED diff --git a/XML/testsuite/src/NodeIteratorTest.cpp b/XML/testsuite/src/NodeIteratorTest.cpp index 103834511..7ff80154b 100644 --- a/XML/testsuite/src/NodeIteratorTest.cpp +++ b/XML/testsuite/src/NodeIteratorTest.cpp @@ -1,210 +1,210 @@ -// -// NodeIteratorTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NodeIteratorTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NodeIteratorTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/NodeIterator.h" -#include "Poco/DOM/NodeFilter.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::NodeIterator; -using Poco::XML::NodeFilter; -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::Text; -using Poco::XML::Node; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -namespace -{ - class TestNodeFilter: public NodeFilter - { - short acceptNode(Node* node) - { - if (node->innerText() == "text1") - return NodeFilter::FILTER_ACCEPT; - else - return NodeFilter::FILTER_REJECT; - } - }; -} - - -NodeIteratorTest::NodeIteratorTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NodeIteratorTest::~NodeIteratorTest() -{ -} - - -void NodeIteratorTest::testShowAll() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - NodeIterator it(pRoot, NodeFilter::SHOW_ALL); - - assert (it.nextNode() == pRoot); - assert (it.nextNode() == pElem1); - assert (it.nextNode() == pText1); - assert (it.nextNode() == pElem2); - assert (it.nextNode() == pText2); - assert (it.nextNode() == 0); - - assert (it.previousNode() == pText2); - assert (it.previousNode() == pElem2); - assert (it.previousNode() == pText1); - assert (it.previousNode() == pElem1); - assert (it.previousNode() == pRoot); - assert (it.previousNode() == 0); -} - - -void NodeIteratorTest::testShowElements() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT); - - assert (it.nextNode() == pRoot); - assert (it.nextNode() == pElem1); - assert (it.nextNode() == pElem2); - assert (it.nextNode() == 0); - - assert (it.previousNode() == pElem2); - assert (it.previousNode() == pElem1); - assert (it.previousNode() == pRoot); - assert (it.previousNode() == 0); -} - - -void NodeIteratorTest::testFilter() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - TestNodeFilter filter; - NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT, &filter); - - assert (it.nextNode() == pElem1); - assert (it.nextNode() == 0); - - assert (it.previousNode() == pElem1); - assert (it.previousNode() == 0); -} - - -void NodeIteratorTest::testShowNothing() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - NodeIterator it(pRoot, 0); - - assert (it.nextNode() == 0); - - assert (it.previousNode() == 0); -} - - -void NodeIteratorTest::setUp() -{ -} - - -void NodeIteratorTest::tearDown() -{ -} - - -CppUnit::Test* NodeIteratorTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeIteratorTest"); - - CppUnit_addTest(pSuite, NodeIteratorTest, testShowAll); - CppUnit_addTest(pSuite, NodeIteratorTest, testShowElements); - CppUnit_addTest(pSuite, NodeIteratorTest, testFilter); - CppUnit_addTest(pSuite, NodeIteratorTest, testShowNothing); - - return pSuite; -} +// +// NodeIteratorTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NodeIteratorTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NodeIteratorTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/NodeIterator.h" +#include "Poco/DOM/NodeFilter.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::NodeIterator; +using Poco::XML::NodeFilter; +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::Text; +using Poco::XML::Node; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +namespace +{ + class TestNodeFilter: public NodeFilter + { + short acceptNode(Node* node) + { + if (node->innerText() == "text1") + return NodeFilter::FILTER_ACCEPT; + else + return NodeFilter::FILTER_REJECT; + } + }; +} + + +NodeIteratorTest::NodeIteratorTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NodeIteratorTest::~NodeIteratorTest() +{ +} + + +void NodeIteratorTest::testShowAll() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + NodeIterator it(pRoot, NodeFilter::SHOW_ALL); + + assert (it.nextNode() == pRoot); + assert (it.nextNode() == pElem1); + assert (it.nextNode() == pText1); + assert (it.nextNode() == pElem2); + assert (it.nextNode() == pText2); + assert (it.nextNode() == 0); + + assert (it.previousNode() == pText2); + assert (it.previousNode() == pElem2); + assert (it.previousNode() == pText1); + assert (it.previousNode() == pElem1); + assert (it.previousNode() == pRoot); + assert (it.previousNode() == 0); +} + + +void NodeIteratorTest::testShowElements() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT); + + assert (it.nextNode() == pRoot); + assert (it.nextNode() == pElem1); + assert (it.nextNode() == pElem2); + assert (it.nextNode() == 0); + + assert (it.previousNode() == pElem2); + assert (it.previousNode() == pElem1); + assert (it.previousNode() == pRoot); + assert (it.previousNode() == 0); +} + + +void NodeIteratorTest::testFilter() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + TestNodeFilter filter; + NodeIterator it(pRoot, NodeFilter::SHOW_ELEMENT, &filter); + + assert (it.nextNode() == pElem1); + assert (it.nextNode() == 0); + + assert (it.previousNode() == pElem1); + assert (it.previousNode() == 0); +} + + +void NodeIteratorTest::testShowNothing() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + NodeIterator it(pRoot, 0); + + assert (it.nextNode() == 0); + + assert (it.previousNode() == 0); +} + + +void NodeIteratorTest::setUp() +{ +} + + +void NodeIteratorTest::tearDown() +{ +} + + +CppUnit::Test* NodeIteratorTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeIteratorTest"); + + CppUnit_addTest(pSuite, NodeIteratorTest, testShowAll); + CppUnit_addTest(pSuite, NodeIteratorTest, testShowElements); + CppUnit_addTest(pSuite, NodeIteratorTest, testFilter); + CppUnit_addTest(pSuite, NodeIteratorTest, testShowNothing); + + return pSuite; +} diff --git a/XML/testsuite/src/NodeIteratorTest.h b/XML/testsuite/src/NodeIteratorTest.h index a9f921758..056bb4dd8 100644 --- a/XML/testsuite/src/NodeIteratorTest.h +++ b/XML/testsuite/src/NodeIteratorTest.h @@ -1,63 +1,63 @@ -// -// NodeIteratorTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NodeIteratorTest.h#1 $ -// -// Definition of the NodeIteratorTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NodeIteratorTest_INCLUDED -#define NodeIteratorTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NodeIteratorTest: public CppUnit::TestCase -{ -public: - NodeIteratorTest(const std::string& name); - ~NodeIteratorTest(); - - void testShowAll(); - void testShowElements(); - void testFilter(); - void testShowNothing(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NodeIteratorTest_INCLUDED +// +// NodeIteratorTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NodeIteratorTest.h#1 $ +// +// Definition of the NodeIteratorTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NodeIteratorTest_INCLUDED +#define NodeIteratorTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NodeIteratorTest: public CppUnit::TestCase +{ +public: + NodeIteratorTest(const std::string& name); + ~NodeIteratorTest(); + + void testShowAll(); + void testShowElements(); + void testFilter(); + void testShowNothing(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NodeIteratorTest_INCLUDED diff --git a/XML/testsuite/src/NodeTest.cpp b/XML/testsuite/src/NodeTest.cpp index 72330c0fa..29bef4454 100644 --- a/XML/testsuite/src/NodeTest.cpp +++ b/XML/testsuite/src/NodeTest.cpp @@ -1,1126 +1,1126 @@ -// -// NodeTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/NodeTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "NodeTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/DocumentFragment.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::DocumentFragment; -using Poco::XML::Node; -using Poco::XML::AutoPtr; - - -NodeTest::NodeTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -NodeTest::~NodeTest() -{ -} - - -void NodeTest::testInsert() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - assert (!pRoot->hasChildNodes()); - assert (pRoot->firstChild() == 0); - assert (pRoot->lastChild() == 0); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->insertBefore(pChild1, 0); - assert (pRoot->hasChildNodes()); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild1); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->insertBefore(pChild3, 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild0 = pDoc->createElement("child0"); - pRoot->insertBefore(pChild0, pChild1); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild3); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->insertBefore(pChild2, pChild3); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild3); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); -} - - -void NodeTest::testAppend() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild1); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild2); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); -} - - -void NodeTest::testRemove() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - - AutoPtr pChild4 = pDoc->createElement("child4"); - pRoot->appendChild(pChild4); - - pRoot->removeChild(pChild2); - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == 0); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - pRoot->removeChild(pChild4); - assert (pChild4->previousSibling() == 0); - assert (pChild4->nextSibling() == 0); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == 0); - - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - pRoot->removeChild(pChild1); - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - - assert (pRoot->firstChild() == pChild3); - assert (pRoot->lastChild() == pChild3); - - pRoot->removeChild(pChild3); - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == 0); - assert (pRoot->firstChild() == 0); - assert (pRoot->lastChild() == 0); -} - - -void NodeTest::testReplace() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - - AutoPtr pChild4 = pDoc->createElement("child4"); - pRoot->appendChild(pChild4); - - AutoPtr pChild11 = pDoc->createElement("child11"); - pRoot->replaceChild(pChild11, pChild1); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild11); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild22 = pDoc->createElement("child22"); - pRoot->replaceChild(pChild22, pChild2); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild22); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild33 = pDoc->createElement("child33"); - pRoot->replaceChild(pChild33, pChild3); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild22); - assert (pChild33->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild33); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild44 = pDoc->createElement("child44"); - pRoot->replaceChild(pChild44, pChild4); - - assert (pChild4->previousSibling() == 0); - assert (pChild4->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild44); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild22); - assert (pChild33->nextSibling() == pChild44); - assert (pChild44->previousSibling() == pChild33); - assert (pChild44->nextSibling() == 0); -} - - -void NodeTest::testInsertFragment1() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - assert (!pRoot->hasChildNodes()); - assert (pRoot->firstChild() == 0); - assert (pRoot->lastChild() == 0); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pFrag->appendChild(pChild1); - pRoot->insertBefore(pFrag, 0); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild1); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pFrag->appendChild(pChild3); - pRoot->insertBefore(pFrag, 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild0 = pDoc->createElement("child0"); - pFrag->appendChild(pChild0); - pRoot->insertBefore(pFrag, pChild1); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild3); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild1); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pFrag->appendChild(pChild2); - pRoot->insertBefore(pFrag, pChild3); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild3); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); -} - - -void NodeTest::testInsertFragment2() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - assert (!pRoot->hasChildNodes()); - assert (pRoot->firstChild() == 0); - assert (pRoot->lastChild() == 0); - - AutoPtr pChild2 = pDoc->createElement("child2"); - AutoPtr pChild3 = pDoc->createElement("child3"); - pFrag->appendChild(pChild2); - pFrag->appendChild(pChild3); - pRoot->insertBefore(pFrag, 0); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild2); - assert (pRoot->lastChild() == pChild3); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild6 = pDoc->createElement("child6"); - AutoPtr pChild7 = pDoc->createElement("child7"); - pFrag->appendChild(pChild6); - pFrag->appendChild(pChild7); - pRoot->insertBefore(pFrag, 0); - assert (pRoot->firstChild() == pChild2); - assert (pRoot->lastChild() == pChild7); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild3); - assert (pChild6->nextSibling() == pChild7); - assert (pChild7->previousSibling() == pChild6); - assert (pChild7->nextSibling() == 0); - - AutoPtr pChild0 = pDoc->createElement("child0"); - AutoPtr pChild1 = pDoc->createElement("child1"); - pFrag->appendChild(pChild0); - pFrag->appendChild(pChild1); - pRoot->insertBefore(pFrag, pChild2); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild7); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild3); - assert (pChild6->nextSibling() == pChild7); - assert (pChild7->previousSibling() == pChild6); - assert (pChild7->nextSibling() == 0); - - AutoPtr pChild4 = pDoc->createElement("child4"); - AutoPtr pChild5 = pDoc->createElement("child5"); - pFrag->appendChild(pChild4); - pFrag->appendChild(pChild5); - pRoot->insertBefore(pFrag, pChild6); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild7); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild5); - assert (pChild6->nextSibling() == pChild7); - assert (pChild7->previousSibling() == pChild6); - assert (pChild7->nextSibling() == 0); -} - - -void NodeTest::testInsertFragment3() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - assert (!pRoot->hasChildNodes()); - assert (pRoot->firstChild() == 0); - assert (pRoot->lastChild() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - AutoPtr pChild4 = pDoc->createElement("child4"); - AutoPtr pChild5 = pDoc->createElement("child5"); - pFrag->appendChild(pChild3); - pFrag->appendChild(pChild4); - pFrag->appendChild(pChild5); - pRoot->insertBefore(pFrag, 0); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild3); - assert (pRoot->lastChild() == pChild5); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == 0); - - AutoPtr pChild9 = pDoc->createElement("child9"); - AutoPtr pChild10 = pDoc->createElement("child10"); - AutoPtr pChild11 = pDoc->createElement("child11"); - pFrag->appendChild(pChild9); - pFrag->appendChild(pChild10); - pFrag->appendChild(pChild11); - pRoot->insertBefore(pFrag, 0); - assert (pRoot->firstChild() == pChild3); - assert (pRoot->lastChild() == pChild11); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild9); - assert (pChild9->previousSibling() == pChild5); - assert (pChild9->nextSibling() == pChild10); - assert (pChild10->previousSibling() == pChild9); - assert (pChild10->nextSibling() == pChild11); - assert (pChild11->previousSibling() == pChild10); - assert (pChild11->nextSibling() == 0); - - AutoPtr pChild0 = pDoc->createElement("child0"); - AutoPtr pChild1 = pDoc->createElement("child1"); - AutoPtr pChild2 = pDoc->createElement("child2"); - pFrag->appendChild(pChild0); - pFrag->appendChild(pChild1); - pFrag->appendChild(pChild2); - pRoot->insertBefore(pFrag, pChild3); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild11); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild9); - assert (pChild9->previousSibling() == pChild5); - assert (pChild9->nextSibling() == pChild10); - assert (pChild10->previousSibling() == pChild9); - assert (pChild10->nextSibling() == pChild11); - assert (pChild11->previousSibling() == pChild10); - assert (pChild11->nextSibling() == 0); - - AutoPtr pChild6 = pDoc->createElement("child6"); - AutoPtr pChild7 = pDoc->createElement("child7"); - AutoPtr pChild8 = pDoc->createElement("child8"); - pFrag->appendChild(pChild6); - pFrag->appendChild(pChild7); - pFrag->appendChild(pChild8); - pRoot->insertBefore(pFrag, pChild9); - assert (pRoot->firstChild() == pChild0); - assert (pRoot->lastChild() == pChild11); - - assert (pChild0->previousSibling() == 0); - assert (pChild0->nextSibling() == pChild1); - assert (pChild1->previousSibling() == pChild0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild5); - assert (pChild6->nextSibling() == pChild7); - assert (pChild7->previousSibling() == pChild6); - assert (pChild7->nextSibling() == pChild8); - assert (pChild8->previousSibling() == pChild7); - assert (pChild8->nextSibling() == pChild9); - assert (pChild9->previousSibling() == pChild8); - assert (pChild9->nextSibling() == pChild10); - assert (pChild10->previousSibling() == pChild9); - assert (pChild10->nextSibling() == pChild11); - assert (pChild11->previousSibling() == pChild10); - assert (pChild11->nextSibling() == 0); -} - - -void NodeTest::testAppendFragment1() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pFrag->appendChild(pChild1); - pRoot->appendChild(pFrag); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild1); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pFrag->appendChild(pChild2); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild2); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pFrag->appendChild(pChild3); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); -} - - -void NodeTest::testAppendFragment2() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - AutoPtr pChild2 = pDoc->createElement("child2"); - pFrag->appendChild(pChild1); - pFrag->appendChild(pChild2); - pRoot->appendChild(pFrag); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild2); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == 0); - - AutoPtr pChild3 = pDoc->createElement("child3"); - AutoPtr pChild4 = pDoc->createElement("child4"); - pFrag->appendChild(pChild3); - pFrag->appendChild(pChild4); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild4); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild5 = pDoc->createElement("child5"); - AutoPtr pChild6 = pDoc->createElement("child6"); - pFrag->appendChild(pChild5); - pFrag->appendChild(pChild6); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild6); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild5); - assert (pChild6->nextSibling() == 0); -} - - -void NodeTest::testAppendFragment3() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - AutoPtr pChild2 = pDoc->createElement("child2"); - AutoPtr pChild3 = pDoc->createElement("child3"); - pFrag->appendChild(pChild1); - pFrag->appendChild(pChild2); - pFrag->appendChild(pChild3); - pRoot->appendChild(pFrag); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild3); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == 0); - - AutoPtr pChild4 = pDoc->createElement("child4"); - AutoPtr pChild5 = pDoc->createElement("child5"); - AutoPtr pChild6 = pDoc->createElement("child6"); - pFrag->appendChild(pChild4); - pFrag->appendChild(pChild5); - pFrag->appendChild(pChild6); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild6); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild5); - assert (pChild6->nextSibling() == 0); - - AutoPtr pChild7 = pDoc->createElement("child7"); - AutoPtr pChild8 = pDoc->createElement("child8"); - AutoPtr pChild9 = pDoc->createElement("child9"); - pFrag->appendChild(pChild7); - pFrag->appendChild(pChild8); - pFrag->appendChild(pChild9); - pRoot->appendChild(pFrag); - assert (pRoot->firstChild() == pChild1); - assert (pRoot->lastChild() == pChild9); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild1); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == pChild5); - assert (pChild5->previousSibling() == pChild4); - assert (pChild5->nextSibling() == pChild6); - assert (pChild6->previousSibling() == pChild5); - assert (pChild6->nextSibling() == pChild7); - assert (pChild7->previousSibling() == pChild6); - assert (pChild7->nextSibling() == pChild8); - assert (pChild8->previousSibling() == pChild7); - assert (pChild8->nextSibling() == pChild9); - assert (pChild9->previousSibling() == pChild8); - assert (pChild9->nextSibling() == 0); -} - - -void NodeTest::testReplaceFragment1() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - - AutoPtr pChild4 = pDoc->createElement("child4"); - pRoot->appendChild(pChild4); - - AutoPtr pChild11 = pDoc->createElement("child11"); - pFrag->appendChild(pChild11); - pRoot->replaceChild(pFrag, pChild1); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild11); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild22 = pDoc->createElement("child22"); - pFrag->appendChild(pChild22); - pRoot->replaceChild(pFrag, pChild2); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild22); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild33 = pDoc->createElement("child33"); - pFrag->appendChild(pChild33); - pRoot->replaceChild(pFrag, pChild3); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild22); - assert (pChild33->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild33); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild44 = pDoc->createElement("child44"); - pFrag->appendChild(pChild44); - pRoot->replaceChild(pFrag, pChild4); - - assert (pChild4->previousSibling() == 0); - assert (pChild4->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild44); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild11); - assert (pChild22->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild22); - assert (pChild33->nextSibling() == pChild44); - assert (pChild44->previousSibling() == pChild33); - assert (pChild44->nextSibling() == 0); -} - - -void NodeTest::testReplaceFragment2() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - - AutoPtr pChild4 = pDoc->createElement("child4"); - pRoot->appendChild(pChild4); - - AutoPtr pChild11 = pDoc->createElement("child11"); - AutoPtr pChild12 = pDoc->createElement("child12"); - pFrag->appendChild(pChild11); - pFrag->appendChild(pChild12); - pRoot->replaceChild(pFrag, pChild1); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild12); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild21 = pDoc->createElement("child21"); - AutoPtr pChild22 = pDoc->createElement("child22"); - pFrag->appendChild(pChild21); - pFrag->appendChild(pChild22); - pRoot->replaceChild(pFrag, pChild2); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild12); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild22); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild31 = pDoc->createElement("child31"); - AutoPtr pChild32 = pDoc->createElement("child32"); - pFrag->appendChild(pChild31); - pFrag->appendChild(pChild32); - pRoot->replaceChild(pFrag, pChild3); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild12); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild31); - assert (pChild31->previousSibling() == pChild22); - assert (pChild31->nextSibling() == pChild32); - assert (pChild32->previousSibling() == pChild31); - assert (pChild32->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild32); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild41 = pDoc->createElement("child41"); - AutoPtr pChild42 = pDoc->createElement("child42"); - pFrag->appendChild(pChild41); - pFrag->appendChild(pChild42); - pRoot->replaceChild(pFrag, pChild4); - - assert (pChild4->previousSibling() == 0); - assert (pChild4->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild42); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild12); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild31); - assert (pChild31->previousSibling() == pChild22); - assert (pChild31->nextSibling() == pChild32); - assert (pChild32->previousSibling() == pChild31); - assert (pChild32->nextSibling() == pChild41); - assert (pChild41->previousSibling() == pChild32); - assert (pChild41->nextSibling() == pChild42); - assert (pChild42->previousSibling() == pChild41); - assert (pChild42->nextSibling() == 0); -} - - -void NodeTest::testReplaceFragment3() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pFrag = pDoc->createDocumentFragment(); - - AutoPtr pChild1 = pDoc->createElement("child1"); - pRoot->appendChild(pChild1); - - AutoPtr pChild2 = pDoc->createElement("child2"); - pRoot->appendChild(pChild2); - - AutoPtr pChild3 = pDoc->createElement("child3"); - pRoot->appendChild(pChild3); - - AutoPtr pChild4 = pDoc->createElement("child4"); - pRoot->appendChild(pChild4); - - AutoPtr pChild11 = pDoc->createElement("child11"); - AutoPtr pChild12 = pDoc->createElement("child12"); - AutoPtr pChild13 = pDoc->createElement("child13"); - pFrag->appendChild(pChild11); - pFrag->appendChild(pChild12); - pFrag->appendChild(pChild13); - pRoot->replaceChild(pFrag, pChild1); - assert (pFrag->firstChild() == 0); - assert (pFrag->lastChild() == 0); - - assert (pChild1->previousSibling() == 0); - assert (pChild1->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild13); - assert (pChild13->previousSibling() == pChild12); - assert (pChild13->nextSibling() == pChild2); - assert (pChild2->previousSibling() == pChild13); - assert (pChild2->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild2); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild21 = pDoc->createElement("child21"); - AutoPtr pChild22 = pDoc->createElement("child22"); - AutoPtr pChild23 = pDoc->createElement("child23"); - pFrag->appendChild(pChild21); - pFrag->appendChild(pChild22); - pFrag->appendChild(pChild23); - pRoot->replaceChild(pFrag, pChild2); - - assert (pChild2->previousSibling() == 0); - assert (pChild2->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild13); - assert (pChild13->previousSibling() == pChild12); - assert (pChild13->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild13); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild23); - assert (pChild23->previousSibling() == pChild22); - assert (pChild23->nextSibling() == pChild3); - assert (pChild3->previousSibling() == pChild23); - assert (pChild3->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild3); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild31 = pDoc->createElement("child31"); - AutoPtr pChild32 = pDoc->createElement("child32"); - AutoPtr pChild33 = pDoc->createElement("child33"); - pFrag->appendChild(pChild31); - pFrag->appendChild(pChild32); - pFrag->appendChild(pChild33); - pRoot->replaceChild(pFrag, pChild3); - - assert (pChild3->previousSibling() == 0); - assert (pChild3->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild4); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild13); - assert (pChild13->previousSibling() == pChild12); - assert (pChild13->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild13); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild23); - assert (pChild23->previousSibling() == pChild22); - assert (pChild23->nextSibling() == pChild31); - assert (pChild31->previousSibling() == pChild23); - assert (pChild31->nextSibling() == pChild32); - assert (pChild32->previousSibling() == pChild31); - assert (pChild32->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild32); - assert (pChild33->nextSibling() == pChild4); - assert (pChild4->previousSibling() == pChild33); - assert (pChild4->nextSibling() == 0); - - AutoPtr pChild41 = pDoc->createElement("child41"); - AutoPtr pChild42 = pDoc->createElement("child42"); - AutoPtr pChild43 = pDoc->createElement("child43"); - pFrag->appendChild(pChild41); - pFrag->appendChild(pChild42); - pFrag->appendChild(pChild43); - pRoot->replaceChild(pFrag, pChild4); - - assert (pChild4->previousSibling() == 0); - assert (pChild4->nextSibling() == 0); - assert (pRoot->firstChild() == pChild11); - assert (pRoot->lastChild() == pChild43); - assert (pChild11->previousSibling() == 0); - assert (pChild11->nextSibling() == pChild12); - assert (pChild12->previousSibling() == pChild11); - assert (pChild12->nextSibling() == pChild13); - assert (pChild13->previousSibling() == pChild12); - assert (pChild13->nextSibling() == pChild21); - assert (pChild21->previousSibling() == pChild13); - assert (pChild21->nextSibling() == pChild22); - assert (pChild22->previousSibling() == pChild21); - assert (pChild22->nextSibling() == pChild23); - assert (pChild23->previousSibling() == pChild22); - assert (pChild23->nextSibling() == pChild31); - assert (pChild31->previousSibling() == pChild23); - assert (pChild31->nextSibling() == pChild32); - assert (pChild32->previousSibling() == pChild31); - assert (pChild32->nextSibling() == pChild33); - assert (pChild33->previousSibling() == pChild32); - assert (pChild33->nextSibling() == pChild41); - assert (pChild41->previousSibling() == pChild33); - assert (pChild41->nextSibling() == pChild42); - assert (pChild42->previousSibling() == pChild41); - assert (pChild42->nextSibling() == pChild43); - assert (pChild43->previousSibling() == pChild42); - assert (pChild43->nextSibling() == 0); -} - - -void NodeTest::setUp() -{ -} - - -void NodeTest::tearDown() -{ -} - - -CppUnit::Test* NodeTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeTest"); - - CppUnit_addTest(pSuite, NodeTest, testInsert); - CppUnit_addTest(pSuite, NodeTest, testAppend); - CppUnit_addTest(pSuite, NodeTest, testRemove); - CppUnit_addTest(pSuite, NodeTest, testReplace); - CppUnit_addTest(pSuite, NodeTest, testInsertFragment1); - CppUnit_addTest(pSuite, NodeTest, testInsertFragment2); - CppUnit_addTest(pSuite, NodeTest, testInsertFragment3); - CppUnit_addTest(pSuite, NodeTest, testAppendFragment1); - CppUnit_addTest(pSuite, NodeTest, testAppendFragment2); - CppUnit_addTest(pSuite, NodeTest, testAppendFragment3); - CppUnit_addTest(pSuite, NodeTest, testReplaceFragment1); - CppUnit_addTest(pSuite, NodeTest, testReplaceFragment2); - CppUnit_addTest(pSuite, NodeTest, testReplaceFragment3); - - return pSuite; -} +// +// NodeTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/NodeTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "NodeTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/DocumentFragment.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::DocumentFragment; +using Poco::XML::Node; +using Poco::XML::AutoPtr; + + +NodeTest::NodeTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +NodeTest::~NodeTest() +{ +} + + +void NodeTest::testInsert() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + assert (!pRoot->hasChildNodes()); + assert (pRoot->firstChild() == 0); + assert (pRoot->lastChild() == 0); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->insertBefore(pChild1, 0); + assert (pRoot->hasChildNodes()); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild1); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->insertBefore(pChild3, 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild0 = pDoc->createElement("child0"); + pRoot->insertBefore(pChild0, pChild1); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild3); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->insertBefore(pChild2, pChild3); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild3); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); +} + + +void NodeTest::testAppend() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild1); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild2); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); +} + + +void NodeTest::testRemove() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + + AutoPtr pChild4 = pDoc->createElement("child4"); + pRoot->appendChild(pChild4); + + pRoot->removeChild(pChild2); + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == 0); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + pRoot->removeChild(pChild4); + assert (pChild4->previousSibling() == 0); + assert (pChild4->nextSibling() == 0); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == 0); + + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + pRoot->removeChild(pChild1); + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + + assert (pRoot->firstChild() == pChild3); + assert (pRoot->lastChild() == pChild3); + + pRoot->removeChild(pChild3); + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == 0); + assert (pRoot->firstChild() == 0); + assert (pRoot->lastChild() == 0); +} + + +void NodeTest::testReplace() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + + AutoPtr pChild4 = pDoc->createElement("child4"); + pRoot->appendChild(pChild4); + + AutoPtr pChild11 = pDoc->createElement("child11"); + pRoot->replaceChild(pChild11, pChild1); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild11); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild22 = pDoc->createElement("child22"); + pRoot->replaceChild(pChild22, pChild2); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild22); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild33 = pDoc->createElement("child33"); + pRoot->replaceChild(pChild33, pChild3); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild22); + assert (pChild33->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild33); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild44 = pDoc->createElement("child44"); + pRoot->replaceChild(pChild44, pChild4); + + assert (pChild4->previousSibling() == 0); + assert (pChild4->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild44); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild22); + assert (pChild33->nextSibling() == pChild44); + assert (pChild44->previousSibling() == pChild33); + assert (pChild44->nextSibling() == 0); +} + + +void NodeTest::testInsertFragment1() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + assert (!pRoot->hasChildNodes()); + assert (pRoot->firstChild() == 0); + assert (pRoot->lastChild() == 0); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pFrag->appendChild(pChild1); + pRoot->insertBefore(pFrag, 0); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild1); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pFrag->appendChild(pChild3); + pRoot->insertBefore(pFrag, 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild0 = pDoc->createElement("child0"); + pFrag->appendChild(pChild0); + pRoot->insertBefore(pFrag, pChild1); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild3); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild1); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pFrag->appendChild(pChild2); + pRoot->insertBefore(pFrag, pChild3); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild3); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); +} + + +void NodeTest::testInsertFragment2() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + assert (!pRoot->hasChildNodes()); + assert (pRoot->firstChild() == 0); + assert (pRoot->lastChild() == 0); + + AutoPtr pChild2 = pDoc->createElement("child2"); + AutoPtr pChild3 = pDoc->createElement("child3"); + pFrag->appendChild(pChild2); + pFrag->appendChild(pChild3); + pRoot->insertBefore(pFrag, 0); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild2); + assert (pRoot->lastChild() == pChild3); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild6 = pDoc->createElement("child6"); + AutoPtr pChild7 = pDoc->createElement("child7"); + pFrag->appendChild(pChild6); + pFrag->appendChild(pChild7); + pRoot->insertBefore(pFrag, 0); + assert (pRoot->firstChild() == pChild2); + assert (pRoot->lastChild() == pChild7); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild3); + assert (pChild6->nextSibling() == pChild7); + assert (pChild7->previousSibling() == pChild6); + assert (pChild7->nextSibling() == 0); + + AutoPtr pChild0 = pDoc->createElement("child0"); + AutoPtr pChild1 = pDoc->createElement("child1"); + pFrag->appendChild(pChild0); + pFrag->appendChild(pChild1); + pRoot->insertBefore(pFrag, pChild2); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild7); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild3); + assert (pChild6->nextSibling() == pChild7); + assert (pChild7->previousSibling() == pChild6); + assert (pChild7->nextSibling() == 0); + + AutoPtr pChild4 = pDoc->createElement("child4"); + AutoPtr pChild5 = pDoc->createElement("child5"); + pFrag->appendChild(pChild4); + pFrag->appendChild(pChild5); + pRoot->insertBefore(pFrag, pChild6); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild7); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild5); + assert (pChild6->nextSibling() == pChild7); + assert (pChild7->previousSibling() == pChild6); + assert (pChild7->nextSibling() == 0); +} + + +void NodeTest::testInsertFragment3() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + assert (!pRoot->hasChildNodes()); + assert (pRoot->firstChild() == 0); + assert (pRoot->lastChild() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + AutoPtr pChild4 = pDoc->createElement("child4"); + AutoPtr pChild5 = pDoc->createElement("child5"); + pFrag->appendChild(pChild3); + pFrag->appendChild(pChild4); + pFrag->appendChild(pChild5); + pRoot->insertBefore(pFrag, 0); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild3); + assert (pRoot->lastChild() == pChild5); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == 0); + + AutoPtr pChild9 = pDoc->createElement("child9"); + AutoPtr pChild10 = pDoc->createElement("child10"); + AutoPtr pChild11 = pDoc->createElement("child11"); + pFrag->appendChild(pChild9); + pFrag->appendChild(pChild10); + pFrag->appendChild(pChild11); + pRoot->insertBefore(pFrag, 0); + assert (pRoot->firstChild() == pChild3); + assert (pRoot->lastChild() == pChild11); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild9); + assert (pChild9->previousSibling() == pChild5); + assert (pChild9->nextSibling() == pChild10); + assert (pChild10->previousSibling() == pChild9); + assert (pChild10->nextSibling() == pChild11); + assert (pChild11->previousSibling() == pChild10); + assert (pChild11->nextSibling() == 0); + + AutoPtr pChild0 = pDoc->createElement("child0"); + AutoPtr pChild1 = pDoc->createElement("child1"); + AutoPtr pChild2 = pDoc->createElement("child2"); + pFrag->appendChild(pChild0); + pFrag->appendChild(pChild1); + pFrag->appendChild(pChild2); + pRoot->insertBefore(pFrag, pChild3); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild11); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild9); + assert (pChild9->previousSibling() == pChild5); + assert (pChild9->nextSibling() == pChild10); + assert (pChild10->previousSibling() == pChild9); + assert (pChild10->nextSibling() == pChild11); + assert (pChild11->previousSibling() == pChild10); + assert (pChild11->nextSibling() == 0); + + AutoPtr pChild6 = pDoc->createElement("child6"); + AutoPtr pChild7 = pDoc->createElement("child7"); + AutoPtr pChild8 = pDoc->createElement("child8"); + pFrag->appendChild(pChild6); + pFrag->appendChild(pChild7); + pFrag->appendChild(pChild8); + pRoot->insertBefore(pFrag, pChild9); + assert (pRoot->firstChild() == pChild0); + assert (pRoot->lastChild() == pChild11); + + assert (pChild0->previousSibling() == 0); + assert (pChild0->nextSibling() == pChild1); + assert (pChild1->previousSibling() == pChild0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild5); + assert (pChild6->nextSibling() == pChild7); + assert (pChild7->previousSibling() == pChild6); + assert (pChild7->nextSibling() == pChild8); + assert (pChild8->previousSibling() == pChild7); + assert (pChild8->nextSibling() == pChild9); + assert (pChild9->previousSibling() == pChild8); + assert (pChild9->nextSibling() == pChild10); + assert (pChild10->previousSibling() == pChild9); + assert (pChild10->nextSibling() == pChild11); + assert (pChild11->previousSibling() == pChild10); + assert (pChild11->nextSibling() == 0); +} + + +void NodeTest::testAppendFragment1() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pFrag->appendChild(pChild1); + pRoot->appendChild(pFrag); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild1); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pFrag->appendChild(pChild2); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild2); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pFrag->appendChild(pChild3); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); +} + + +void NodeTest::testAppendFragment2() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + AutoPtr pChild2 = pDoc->createElement("child2"); + pFrag->appendChild(pChild1); + pFrag->appendChild(pChild2); + pRoot->appendChild(pFrag); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild2); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == 0); + + AutoPtr pChild3 = pDoc->createElement("child3"); + AutoPtr pChild4 = pDoc->createElement("child4"); + pFrag->appendChild(pChild3); + pFrag->appendChild(pChild4); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild4); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild5 = pDoc->createElement("child5"); + AutoPtr pChild6 = pDoc->createElement("child6"); + pFrag->appendChild(pChild5); + pFrag->appendChild(pChild6); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild6); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild5); + assert (pChild6->nextSibling() == 0); +} + + +void NodeTest::testAppendFragment3() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + AutoPtr pChild2 = pDoc->createElement("child2"); + AutoPtr pChild3 = pDoc->createElement("child3"); + pFrag->appendChild(pChild1); + pFrag->appendChild(pChild2); + pFrag->appendChild(pChild3); + pRoot->appendChild(pFrag); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild3); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == 0); + + AutoPtr pChild4 = pDoc->createElement("child4"); + AutoPtr pChild5 = pDoc->createElement("child5"); + AutoPtr pChild6 = pDoc->createElement("child6"); + pFrag->appendChild(pChild4); + pFrag->appendChild(pChild5); + pFrag->appendChild(pChild6); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild6); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild5); + assert (pChild6->nextSibling() == 0); + + AutoPtr pChild7 = pDoc->createElement("child7"); + AutoPtr pChild8 = pDoc->createElement("child8"); + AutoPtr pChild9 = pDoc->createElement("child9"); + pFrag->appendChild(pChild7); + pFrag->appendChild(pChild8); + pFrag->appendChild(pChild9); + pRoot->appendChild(pFrag); + assert (pRoot->firstChild() == pChild1); + assert (pRoot->lastChild() == pChild9); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild1); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == pChild5); + assert (pChild5->previousSibling() == pChild4); + assert (pChild5->nextSibling() == pChild6); + assert (pChild6->previousSibling() == pChild5); + assert (pChild6->nextSibling() == pChild7); + assert (pChild7->previousSibling() == pChild6); + assert (pChild7->nextSibling() == pChild8); + assert (pChild8->previousSibling() == pChild7); + assert (pChild8->nextSibling() == pChild9); + assert (pChild9->previousSibling() == pChild8); + assert (pChild9->nextSibling() == 0); +} + + +void NodeTest::testReplaceFragment1() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + + AutoPtr pChild4 = pDoc->createElement("child4"); + pRoot->appendChild(pChild4); + + AutoPtr pChild11 = pDoc->createElement("child11"); + pFrag->appendChild(pChild11); + pRoot->replaceChild(pFrag, pChild1); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild11); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild22 = pDoc->createElement("child22"); + pFrag->appendChild(pChild22); + pRoot->replaceChild(pFrag, pChild2); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild22); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild33 = pDoc->createElement("child33"); + pFrag->appendChild(pChild33); + pRoot->replaceChild(pFrag, pChild3); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild22); + assert (pChild33->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild33); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild44 = pDoc->createElement("child44"); + pFrag->appendChild(pChild44); + pRoot->replaceChild(pFrag, pChild4); + + assert (pChild4->previousSibling() == 0); + assert (pChild4->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild44); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild11); + assert (pChild22->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild22); + assert (pChild33->nextSibling() == pChild44); + assert (pChild44->previousSibling() == pChild33); + assert (pChild44->nextSibling() == 0); +} + + +void NodeTest::testReplaceFragment2() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + + AutoPtr pChild4 = pDoc->createElement("child4"); + pRoot->appendChild(pChild4); + + AutoPtr pChild11 = pDoc->createElement("child11"); + AutoPtr pChild12 = pDoc->createElement("child12"); + pFrag->appendChild(pChild11); + pFrag->appendChild(pChild12); + pRoot->replaceChild(pFrag, pChild1); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild12); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild21 = pDoc->createElement("child21"); + AutoPtr pChild22 = pDoc->createElement("child22"); + pFrag->appendChild(pChild21); + pFrag->appendChild(pChild22); + pRoot->replaceChild(pFrag, pChild2); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild12); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild22); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild31 = pDoc->createElement("child31"); + AutoPtr pChild32 = pDoc->createElement("child32"); + pFrag->appendChild(pChild31); + pFrag->appendChild(pChild32); + pRoot->replaceChild(pFrag, pChild3); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild12); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild31); + assert (pChild31->previousSibling() == pChild22); + assert (pChild31->nextSibling() == pChild32); + assert (pChild32->previousSibling() == pChild31); + assert (pChild32->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild32); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild41 = pDoc->createElement("child41"); + AutoPtr pChild42 = pDoc->createElement("child42"); + pFrag->appendChild(pChild41); + pFrag->appendChild(pChild42); + pRoot->replaceChild(pFrag, pChild4); + + assert (pChild4->previousSibling() == 0); + assert (pChild4->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild42); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild12); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild31); + assert (pChild31->previousSibling() == pChild22); + assert (pChild31->nextSibling() == pChild32); + assert (pChild32->previousSibling() == pChild31); + assert (pChild32->nextSibling() == pChild41); + assert (pChild41->previousSibling() == pChild32); + assert (pChild41->nextSibling() == pChild42); + assert (pChild42->previousSibling() == pChild41); + assert (pChild42->nextSibling() == 0); +} + + +void NodeTest::testReplaceFragment3() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pFrag = pDoc->createDocumentFragment(); + + AutoPtr pChild1 = pDoc->createElement("child1"); + pRoot->appendChild(pChild1); + + AutoPtr pChild2 = pDoc->createElement("child2"); + pRoot->appendChild(pChild2); + + AutoPtr pChild3 = pDoc->createElement("child3"); + pRoot->appendChild(pChild3); + + AutoPtr pChild4 = pDoc->createElement("child4"); + pRoot->appendChild(pChild4); + + AutoPtr pChild11 = pDoc->createElement("child11"); + AutoPtr pChild12 = pDoc->createElement("child12"); + AutoPtr pChild13 = pDoc->createElement("child13"); + pFrag->appendChild(pChild11); + pFrag->appendChild(pChild12); + pFrag->appendChild(pChild13); + pRoot->replaceChild(pFrag, pChild1); + assert (pFrag->firstChild() == 0); + assert (pFrag->lastChild() == 0); + + assert (pChild1->previousSibling() == 0); + assert (pChild1->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild13); + assert (pChild13->previousSibling() == pChild12); + assert (pChild13->nextSibling() == pChild2); + assert (pChild2->previousSibling() == pChild13); + assert (pChild2->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild2); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild21 = pDoc->createElement("child21"); + AutoPtr pChild22 = pDoc->createElement("child22"); + AutoPtr pChild23 = pDoc->createElement("child23"); + pFrag->appendChild(pChild21); + pFrag->appendChild(pChild22); + pFrag->appendChild(pChild23); + pRoot->replaceChild(pFrag, pChild2); + + assert (pChild2->previousSibling() == 0); + assert (pChild2->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild13); + assert (pChild13->previousSibling() == pChild12); + assert (pChild13->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild13); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild23); + assert (pChild23->previousSibling() == pChild22); + assert (pChild23->nextSibling() == pChild3); + assert (pChild3->previousSibling() == pChild23); + assert (pChild3->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild3); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild31 = pDoc->createElement("child31"); + AutoPtr pChild32 = pDoc->createElement("child32"); + AutoPtr pChild33 = pDoc->createElement("child33"); + pFrag->appendChild(pChild31); + pFrag->appendChild(pChild32); + pFrag->appendChild(pChild33); + pRoot->replaceChild(pFrag, pChild3); + + assert (pChild3->previousSibling() == 0); + assert (pChild3->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild4); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild13); + assert (pChild13->previousSibling() == pChild12); + assert (pChild13->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild13); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild23); + assert (pChild23->previousSibling() == pChild22); + assert (pChild23->nextSibling() == pChild31); + assert (pChild31->previousSibling() == pChild23); + assert (pChild31->nextSibling() == pChild32); + assert (pChild32->previousSibling() == pChild31); + assert (pChild32->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild32); + assert (pChild33->nextSibling() == pChild4); + assert (pChild4->previousSibling() == pChild33); + assert (pChild4->nextSibling() == 0); + + AutoPtr pChild41 = pDoc->createElement("child41"); + AutoPtr pChild42 = pDoc->createElement("child42"); + AutoPtr pChild43 = pDoc->createElement("child43"); + pFrag->appendChild(pChild41); + pFrag->appendChild(pChild42); + pFrag->appendChild(pChild43); + pRoot->replaceChild(pFrag, pChild4); + + assert (pChild4->previousSibling() == 0); + assert (pChild4->nextSibling() == 0); + assert (pRoot->firstChild() == pChild11); + assert (pRoot->lastChild() == pChild43); + assert (pChild11->previousSibling() == 0); + assert (pChild11->nextSibling() == pChild12); + assert (pChild12->previousSibling() == pChild11); + assert (pChild12->nextSibling() == pChild13); + assert (pChild13->previousSibling() == pChild12); + assert (pChild13->nextSibling() == pChild21); + assert (pChild21->previousSibling() == pChild13); + assert (pChild21->nextSibling() == pChild22); + assert (pChild22->previousSibling() == pChild21); + assert (pChild22->nextSibling() == pChild23); + assert (pChild23->previousSibling() == pChild22); + assert (pChild23->nextSibling() == pChild31); + assert (pChild31->previousSibling() == pChild23); + assert (pChild31->nextSibling() == pChild32); + assert (pChild32->previousSibling() == pChild31); + assert (pChild32->nextSibling() == pChild33); + assert (pChild33->previousSibling() == pChild32); + assert (pChild33->nextSibling() == pChild41); + assert (pChild41->previousSibling() == pChild33); + assert (pChild41->nextSibling() == pChild42); + assert (pChild42->previousSibling() == pChild41); + assert (pChild42->nextSibling() == pChild43); + assert (pChild43->previousSibling() == pChild42); + assert (pChild43->nextSibling() == 0); +} + + +void NodeTest::setUp() +{ +} + + +void NodeTest::tearDown() +{ +} + + +CppUnit::Test* NodeTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NodeTest"); + + CppUnit_addTest(pSuite, NodeTest, testInsert); + CppUnit_addTest(pSuite, NodeTest, testAppend); + CppUnit_addTest(pSuite, NodeTest, testRemove); + CppUnit_addTest(pSuite, NodeTest, testReplace); + CppUnit_addTest(pSuite, NodeTest, testInsertFragment1); + CppUnit_addTest(pSuite, NodeTest, testInsertFragment2); + CppUnit_addTest(pSuite, NodeTest, testInsertFragment3); + CppUnit_addTest(pSuite, NodeTest, testAppendFragment1); + CppUnit_addTest(pSuite, NodeTest, testAppendFragment2); + CppUnit_addTest(pSuite, NodeTest, testAppendFragment3); + CppUnit_addTest(pSuite, NodeTest, testReplaceFragment1); + CppUnit_addTest(pSuite, NodeTest, testReplaceFragment2); + CppUnit_addTest(pSuite, NodeTest, testReplaceFragment3); + + return pSuite; +} diff --git a/XML/testsuite/src/NodeTest.h b/XML/testsuite/src/NodeTest.h index 45e14c67c..f0d6f8bf9 100644 --- a/XML/testsuite/src/NodeTest.h +++ b/XML/testsuite/src/NodeTest.h @@ -1,72 +1,72 @@ -// -// NodeTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/NodeTest.h#1 $ -// -// Definition of the NodeTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef NodeTest_INCLUDED -#define NodeTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class NodeTest: public CppUnit::TestCase -{ -public: - NodeTest(const std::string& name); - ~NodeTest(); - - void testInsert(); - void testAppend(); - void testRemove(); - void testReplace(); - void testInsertFragment1(); - void testInsertFragment2(); - void testInsertFragment3(); - void testAppendFragment1(); - void testAppendFragment2(); - void testAppendFragment3(); - void testReplaceFragment1(); - void testReplaceFragment2(); - void testReplaceFragment3(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // NodeTest_INCLUDED +// +// NodeTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/NodeTest.h#1 $ +// +// Definition of the NodeTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef NodeTest_INCLUDED +#define NodeTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class NodeTest: public CppUnit::TestCase +{ +public: + NodeTest(const std::string& name); + ~NodeTest(); + + void testInsert(); + void testAppend(); + void testRemove(); + void testReplace(); + void testInsertFragment1(); + void testInsertFragment2(); + void testInsertFragment3(); + void testAppendFragment1(); + void testAppendFragment2(); + void testAppendFragment3(); + void testReplaceFragment1(); + void testReplaceFragment2(); + void testReplaceFragment3(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // NodeTest_INCLUDED diff --git a/XML/testsuite/src/ParserWriterTest.cpp b/XML/testsuite/src/ParserWriterTest.cpp index 2b83f44c2..5a406af9d 100644 --- a/XML/testsuite/src/ParserWriterTest.cpp +++ b/XML/testsuite/src/ParserWriterTest.cpp @@ -1,321 +1,321 @@ -// -// ParserWriterTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/ParserWriterTest.cpp#2 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "ParserWriterTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/DOMParser.h" -#include "Poco/DOM/DOMWriter.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/AutoPtr.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/XML/XMLWriter.h" -#include - - -using Poco::XML::DOMParser; -using Poco::XML::DOMWriter; -using Poco::XML::XMLReader; -using Poco::XML::XMLWriter; -using Poco::XML::Document; -using Poco::XML::AutoPtr; -using Poco::XML::InputSource; - - -ParserWriterTest::ParserWriterTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -ParserWriterTest::~ParserWriterTest() -{ -} - - -void ParserWriterTest::testParseWriteXHTML() -{ - std::ostringstream ostr; - - DOMParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); - DOMWriter writer; - AutoPtr pDoc = parser.parseString(XHTML); - writer.writeNode(ostr, pDoc); - - std::string xml = ostr.str(); - assert (xml == XHTML); -} - - -void ParserWriterTest::testParseWriteXHTML2() -{ - std::ostringstream ostr; - - DOMParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); - DOMWriter writer; - AutoPtr pDoc = parser.parseString(XHTML2); - writer.writeNode(ostr, pDoc); - - std::string xml = ostr.str(); - assert (xml == XHTML2); -} - - -void ParserWriterTest::testParseWriteWSDL() -{ - std::istringstream istr(WSDL); - std::ostringstream ostr; - - DOMParser parser; - parser.setFeature(DOMParser::FEATURE_WHITESPACE, false); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); - DOMWriter writer; - writer.setOptions(XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine(XMLWriter::NEWLINE_LF); - InputSource source(istr); - AutoPtr pDoc = parser.parse(&source); - writer.writeNode(ostr, pDoc); - - std::string xml = ostr.str(); - assert (xml == WSDL); -} - - -void ParserWriterTest::setUp() -{ -} - - -void ParserWriterTest::tearDown() -{ -} - - -CppUnit::Test* ParserWriterTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ParserWriterTest"); - - CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML); - CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML2); - CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL); - - return pSuite; -} - - -const std::string ParserWriterTest::XHTML = - "" - "\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\tA XHTML Example\n" - "\t\n" - "\t\n" - "\t\tXHTML Example\n" - "\t\tThis is a XHTML example page.\n" - "\t\t\n" - "\t\tis inside a CDATA section.\n" - "\t\t]]>\n" - "\t\n" - ""; - - -const std::string ParserWriterTest::XHTML2 = - "" - "\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\tA XHTML Example\n" - "\t\n" - "\t\n" - "\t\tXHTML Example\n" - "\t\tThis is a XHTML example page.\n" - "\t\t\n" - "\t\tis inside a CDATA section.\n" - "\t\t]]>\n" - "\t\n" - ""; - - -const std::string ParserWriterTest::WSDL = - "\n" - "\n" - "\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\n" - "\t\n" - "\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\n" - "\n"; +// +// ParserWriterTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/ParserWriterTest.cpp#2 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "ParserWriterTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/DOMParser.h" +#include "Poco/DOM/DOMWriter.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/AutoPtr.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/XML/XMLWriter.h" +#include + + +using Poco::XML::DOMParser; +using Poco::XML::DOMWriter; +using Poco::XML::XMLReader; +using Poco::XML::XMLWriter; +using Poco::XML::Document; +using Poco::XML::AutoPtr; +using Poco::XML::InputSource; + + +ParserWriterTest::ParserWriterTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +ParserWriterTest::~ParserWriterTest() +{ +} + + +void ParserWriterTest::testParseWriteXHTML() +{ + std::ostringstream ostr; + + DOMParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); + DOMWriter writer; + AutoPtr pDoc = parser.parseString(XHTML); + writer.writeNode(ostr, pDoc); + + std::string xml = ostr.str(); + assert (xml == XHTML); +} + + +void ParserWriterTest::testParseWriteXHTML2() +{ + std::ostringstream ostr; + + DOMParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); + DOMWriter writer; + AutoPtr pDoc = parser.parseString(XHTML2); + writer.writeNode(ostr, pDoc); + + std::string xml = ostr.str(); + assert (xml == XHTML2); +} + + +void ParserWriterTest::testParseWriteWSDL() +{ + std::istringstream istr(WSDL); + std::ostringstream ostr; + + DOMParser parser; + parser.setFeature(DOMParser::FEATURE_WHITESPACE, false); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); + DOMWriter writer; + writer.setOptions(XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine(XMLWriter::NEWLINE_LF); + InputSource source(istr); + AutoPtr pDoc = parser.parse(&source); + writer.writeNode(ostr, pDoc); + + std::string xml = ostr.str(); + assert (xml == WSDL); +} + + +void ParserWriterTest::setUp() +{ +} + + +void ParserWriterTest::tearDown() +{ +} + + +CppUnit::Test* ParserWriterTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ParserWriterTest"); + + CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML); + CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteXHTML2); + CppUnit_addTest(pSuite, ParserWriterTest, testParseWriteWSDL); + + return pSuite; +} + + +const std::string ParserWriterTest::XHTML = + "" + "\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\tA XHTML Example\n" + "\t\n" + "\t\n" + "\t\tXHTML Example\n" + "\t\tThis is a XHTML example page.\n" + "\t\t\n" + "\t\tis inside a CDATA section.\n" + "\t\t]]>\n" + "\t\n" + ""; + + +const std::string ParserWriterTest::XHTML2 = + "" + "\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\tA XHTML Example\n" + "\t\n" + "\t\n" + "\t\tXHTML Example\n" + "\t\tThis is a XHTML example page.\n" + "\t\t\n" + "\t\tis inside a CDATA section.\n" + "\t\t]]>\n" + "\t\n" + ""; + + +const std::string ParserWriterTest::WSDL = + "\n" + "\n" + "\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + "\t\n" + "\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + "\n"; diff --git a/XML/testsuite/src/ParserWriterTest.h b/XML/testsuite/src/ParserWriterTest.h index 4aef1ca0c..036bced96 100644 --- a/XML/testsuite/src/ParserWriterTest.h +++ b/XML/testsuite/src/ParserWriterTest.h @@ -1,65 +1,65 @@ -// -// ParserWriterTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/ParserWriterTest.h#1 $ -// -// Definition of the ParserWriterTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef ParserWriterTest_INCLUDED -#define ParserWriterTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class ParserWriterTest: public CppUnit::TestCase -{ -public: - ParserWriterTest(const std::string& name); - ~ParserWriterTest(); - - void testParseWriteXHTML(); - void testParseWriteXHTML2(); - void testParseWriteWSDL(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: - static const std::string XHTML; - static const std::string XHTML2; - static const std::string WSDL; -}; - - -#endif // ParserWriterTest_INCLUDED +// +// ParserWriterTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/ParserWriterTest.h#1 $ +// +// Definition of the ParserWriterTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef ParserWriterTest_INCLUDED +#define ParserWriterTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class ParserWriterTest: public CppUnit::TestCase +{ +public: + ParserWriterTest(const std::string& name); + ~ParserWriterTest(); + + void testParseWriteXHTML(); + void testParseWriteXHTML2(); + void testParseWriteWSDL(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: + static const std::string XHTML; + static const std::string XHTML2; + static const std::string WSDL; +}; + + +#endif // ParserWriterTest_INCLUDED diff --git a/XML/testsuite/src/SAXParserTest.cpp b/XML/testsuite/src/SAXParserTest.cpp index 2471213d0..f07cfa8ae 100644 --- a/XML/testsuite/src/SAXParserTest.cpp +++ b/XML/testsuite/src/SAXParserTest.cpp @@ -1,1036 +1,1036 @@ -// -// SAXParserTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/SAXParserTest.cpp#3 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "SAXParserTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/SAX/SAXParser.h" -#include "Poco/SAX/InputSource.h" -#include "Poco/SAX/EntityResolver.h" -#include "Poco/SAX/SAXException.h" -#include "Poco/SAX/WhitespaceFilter.h" -#include "Poco/XML/XMLWriter.h" -#include "Poco/Latin9Encoding.h" -#include "Poco/FileStream.h" -#include - - -using Poco::XML::SAXParser; -using Poco::XML::XMLWriter; -using Poco::XML::XMLReader; -using Poco::XML::InputSource; -using Poco::XML::EntityResolver; -using Poco::XML::XMLString; -using Poco::XML::SAXParseException; -using Poco::XML::WhitespaceFilter; - - -class TestEntityResolver: public EntityResolver -{ -public: - InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) - { - if (systemId == "include.xml") - { - std::istringstream* istr = new std::istringstream(SAXParserTest::INCLUDE); - InputSource* pIS = new InputSource(*istr); - pIS->setSystemId(systemId); - return pIS; - } - else if (systemId == "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent") - { - std::istringstream* istr = new std::istringstream(SAXParserTest::XHTML_LATIN1_ENTITIES); - InputSource* pIS = new InputSource(*istr); - pIS->setSystemId(systemId); - return pIS; - } - return 0; - } - - void releaseInputSource(InputSource* pSource) - { - delete pSource->getByteStream(); - delete pSource; - } -}; - - -SAXParserTest::SAXParserTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -SAXParserTest::~SAXParserTest() -{ -} - - -void SAXParserTest::testSimple1() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, SIMPLE1); - assert (xml == ""); -} - - -void SAXParserTest::testSimple2() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, SIMPLE2); - assert (xml == ""); -} - - -void SAXParserTest::testAttributes() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, ATTRIBUTES); - assert (xml == ATTRIBUTES); -} - - -void SAXParserTest::testCDATA() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, CDATA); - assert (xml == CDATA); -} - - -void SAXParserTest::testComment() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, COMMENT); - assert (xml == COMMENT); -} - - -void SAXParserTest::testPI() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, PROCESSING_INSTRUCTION); - assert (xml == PROCESSING_INSTRUCTION); -} - - -void SAXParserTest::testDTD() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, DTD); - assert (xml == ""); -} - - -void SAXParserTest::testInternalEntity() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, INTERNAL_ENTITY); - assert (xml == "\n\tApplied Informatics\n"); -} - - -void SAXParserTest::testNotation() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, NOTATION); - assert (xml == "" - "]>" - ""); -} - - -void SAXParserTest::testExternalUnparsed() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, EXTERNAL_UNPARSED); - assert (xml == "" - "]>" - ""); -} - - -void SAXParserTest::testExternalParsed() -{ - SAXParser parser; - TestEntityResolver resolver; - parser.setEntityResolver(&resolver); - parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true); - std::string xml = parse(parser, XMLWriter::CANONICAL, EXTERNAL_PARSED); - assert (xml == "\n\t\n\tAn external entity.\n\n\n"); -} - - -void SAXParserTest::testDefaultNamespace() -{ - SAXParser parser; - std::string xml = parse(parser, XMLWriter::CANONICAL, DEFAULT_NAMESPACE); - assert (xml == DEFAULT_NAMESPACE); -} - - -void SAXParserTest::testNamespaces() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); - std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); - assert (xml == NAMESPACES); -} - - -void SAXParserTest::testNamespacesNoPrefixes() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); - std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); - assert (xml == NAMESPACES); -} - - -void SAXParserTest::testNoNamespaces() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); - std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); - assert (xml == NAMESPACES); -} - - -void SAXParserTest::testUndeclaredNamespace() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); - try - { - std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); - fail("undeclared namespace - must throw exception"); - } - catch (SAXParseException&) - { - } -} - - -void SAXParserTest::testUndeclaredNamespaceNoPrefixes() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); - parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); - try - { - std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); - fail("undeclared namespace - must throw exception"); - } - catch (SAXParseException&) - { - } -} - - -void SAXParserTest::testUndeclaredNoNamespace() -{ - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); - std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); - assert (xml == UNDECLARED_NAMESPACE); -} - - -void SAXParserTest::testRSS() -{ - SAXParser parser; - WhitespaceFilter filter(&parser); - TestEntityResolver resolver; - filter.setEntityResolver(&resolver); - parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true); - parser.setFeature(XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES, true); - - std::istringstream istr(RSS); - Poco::FileOutputStream ostr("rss.xml"); - XMLWriter writer(ostr, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - filter.setContentHandler(&writer); - filter.setDTDHandler(&writer); - filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - InputSource source(istr); - filter.parse(&source); -} - - -void SAXParserTest::testEncoding() -{ - SAXParser parser; - Poco::Latin9Encoding encoding; - parser.addEncoding("ISO-8859-15", &encoding); - - std::istringstream istr(ENCODING); - std::ostringstream ostr; - XMLWriter writer(ostr, XMLWriter::WRITE_XML_DECLARATION, "ISO-8859-15", encoding); - parser.setContentHandler(&writer); - parser.setDTDHandler(&writer); - parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - InputSource source(istr); - parser.parse(&source); - - std::string xml = ostr.str(); - assert (xml == ENCODING); -} - - -void SAXParserTest::testCharacters() -{ - static const XMLString xml(" TEXT & AMPERSAND "); - SAXParser parser; - parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); - std::string result = parse(parser, XMLWriter::CANONICAL, xml); - assert (result == xml); -} - - -void SAXParserTest::testParseMemory() -{ - SAXParser parser; - std::string xml = parseMemory(parser, XMLWriter::CANONICAL, ATTRIBUTES); - assert (xml == ATTRIBUTES); -} - - -void SAXParserTest::setUp() -{ -} - - -void SAXParserTest::tearDown() -{ -} - - -std::string SAXParserTest::parse(XMLReader& reader, int options, const std::string& data) -{ - std::istringstream istr(data); - std::ostringstream ostr; - XMLWriter writer(ostr, options); - reader.setContentHandler(&writer); - reader.setDTDHandler(&writer); - reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - InputSource source(istr); - reader.parse(&source); - return ostr.str(); -} - - -std::string SAXParserTest::parseMemory(XMLReader& reader, int options, const std::string& data) -{ - std::istringstream istr(data); - std::ostringstream ostr; - XMLWriter writer(ostr, options); - reader.setContentHandler(&writer); - reader.setDTDHandler(&writer); - reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); - reader.parseMemoryNP(data.data(), data.size()); - return ostr.str(); -} - - -CppUnit::Test* SAXParserTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXParserTest"); - - CppUnit_addTest(pSuite, SAXParserTest, testSimple1); - CppUnit_addTest(pSuite, SAXParserTest, testSimple2); - CppUnit_addTest(pSuite, SAXParserTest, testAttributes); - CppUnit_addTest(pSuite, SAXParserTest, testCDATA); - CppUnit_addTest(pSuite, SAXParserTest, testComment); - CppUnit_addTest(pSuite, SAXParserTest, testPI); - CppUnit_addTest(pSuite, SAXParserTest, testDTD); - CppUnit_addTest(pSuite, SAXParserTest, testInternalEntity); - CppUnit_addTest(pSuite, SAXParserTest, testNotation); - CppUnit_addTest(pSuite, SAXParserTest, testExternalUnparsed); - CppUnit_addTest(pSuite, SAXParserTest, testExternalParsed); - CppUnit_addTest(pSuite, SAXParserTest, testDefaultNamespace); - CppUnit_addTest(pSuite, SAXParserTest, testNamespaces); - CppUnit_addTest(pSuite, SAXParserTest, testNamespacesNoPrefixes); - CppUnit_addTest(pSuite, SAXParserTest, testNoNamespaces); - CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespace); - CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespaceNoPrefixes); - CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace); - CppUnit_addTest(pSuite, SAXParserTest, testRSS); - CppUnit_addTest(pSuite, SAXParserTest, testEncoding); - CppUnit_addTest(pSuite, SAXParserTest, testParseMemory); - CppUnit_addTest(pSuite, SAXParserTest, testCharacters); - - return pSuite; -} - - -const std::string SAXParserTest::SIMPLE1 = - "\n"; - - -const std::string SAXParserTest::SIMPLE2 = - "\n" - "\n"; - - -const std::string SAXParserTest::ATTRIBUTES = - "\n" - "\t\n" - ""; - - -const std::string SAXParserTest::CDATA = - "\n" - "is inside a CDATA section.\n" - "]]>\n" - ""; - - -const std::string SAXParserTest::COMMENT = - "" - "\n" - "\t\n" - "\t\n" - ""; - - -const std::string SAXParserTest::PROCESSING_INSTRUCTION = - "\n" - "\t\n" - "\t\t\n" - "\t\ttest\n" - "\t\n" - "\t\n" - "\t\t

this is a test

\n" - "\t\n" - ""; - - -const std::string SAXParserTest::DTD = - "\n" - "\n" - ""; - - -const std::string SAXParserTest::INTERNAL_ENTITY = - "\n" - "]>\n" - "\n" - "\t&appinf;\n" - ""; - - -const std::string SAXParserTest::NOTATION = - "\n" - "\n" - "\t\n" - "]>\n" - ""; - - -const std::string SAXParserTest::EXTERNAL_UNPARSED = - "\n" - "\n" - "\t\n" - "]>\n" - ""; - - -const std::string SAXParserTest::EXTERNAL_PARSED = - "\n" - "\n" - "]>\n" - "\n" - "\t&include;\n" - "\n"; - - -const std::string SAXParserTest::INCLUDE = - "\n" - "\tAn external entity.\n" - "\n"; - - -const std::string SAXParserTest::DEFAULT_NAMESPACE = - "\n" - "\tdata\n" - ""; - - -const std::string SAXParserTest::NAMESPACES = - "\n" - "\tdata\n" - "\t\n" - "\t\tmore data\n" - "\t\n" - ""; - - -const std::string SAXParserTest::UNDECLARED_NAMESPACE = - "\n" - "\tdata\n" - "\t\n" - "\t\tmore data\n" - "\t\n" - "\t\n" - ""; - - -const std::string SAXParserTest::XHTML_LATIN1_ENTITIES = - "\n" - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n"; - -const std::string SAXParserTest::RSS = - "\n" - "\n" - "\n" - "%HTMLlat1;\n" - "]>\n" - "\n" - " \n" - "\n" - " \n" - " XML.com \n" - " http://www.xml.com/\n" - " XML.com features a rich mix of information and services for the XML community.\n" - " hourly\n" - " 2\n" - " 2000-01-01T12:00+00:00\n" - "\n" - " \n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n" - " \n" - "\n" - " \n" - " Meerkat Powered!\n" - " http://meerkat.oreillynet.com/icons/meerkat-powered.jpg\n" - " http://meerkat.oreillynet.com\n" - " \n" - "\n" - " \n" - " Features: Top 10 XForms Engines\n" - " http://www.xml.com/pub/a/2005/02/09/xforms.html\n" - " \n" - " Micah Dubinko, one of the gurus of XForms, offers a rundown on the state of XForms engines for 2005.\n" - " \n" - " XML.com\n" - " Micah Dubinko\n" - " Web, Applications\n" - " O'Reilly Media, Inc.\n" - " 2005-02-09\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Comparing CSS and XSL: A Reply from Norm Walsh\n" - " http://www.xml.com/pub/a/2005/02/09/cssorxsl.html\n" - " \n" - " Norm Walsh responds to a recent article about CSS and XSL, explaining how and when and why you'd want to use XSLFO or CSS or XSLT.\n" - " \n" - " XML.com\n" - " Norman Walsh\n" - " Style\n" - " O'Reilly Media, Inc.\n" - " 2005-02-09\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Very Dynamic Web Interfaces\n" - " http://www.xml.com/pub/a/2005/02/09/xml-http-request.html\n" - " \n" - " Drew McLellan explains how to use XMLHTTPRequest and Javascript to create web applications with very dynamic, smooth interfaces.\n" - " \n" - " XML.com\n" - " Drew McLellan\n" - " Web Development, Instruction\n" - " O'Reilly Media, Inc.\n" - " 2005-02-09\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Transforming XML: The XPath 2.0 Data Model\n" - " http://www.xml.com/pub/a/2005/02/02/xpath2.html\n" - " \n" - " Bob DuCharme, in his latest Transforming XML column, examines the XPath 2.0, hence the XSLT 2.0, data model.\n" - " \n" - " XML.com\n" - " Bob DuCharme\n" - " Style, Style\n" - " O'Reilly Media, Inc.\n" - " 2005-02-02\n" - " Transforming XML\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " XML Tourist: The Silent Soundtrack\n" - " http://www.xml.com/pub/a/2005/02/02/silent.html\n" - " \n" - " In this installation of XML Tourist, John E. Simpson presents an overview of the types of sound-to-text captioning available. Pinpointing closed captioning as the most suitable for use with computerized multimedia, he then explains how XML-based solutions address synchronization issues.\n" - " \n" - " XML.com\n" - " John E. Simpson\n" - " Graphics, Vertical Industries\n" - " O'Reilly Media, Inc.\n" - " 2005-02-02\n" - " XML Tourist\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Transforming XML: The XML 2.0 Data Model\n" - " http://www.xml.com/pub/a/2005/02/02/xpath2.html\n" - " \n" - " Bob DuCharme, in his latest Transforming XML column, examines the XPath 2.0, hence the XSLT 2.0, data model.\n" - " \n" - " XML.com\n" - " Bob DuCharme\n" - " Style, Style\n" - " O'Reilly Media, Inc.\n" - " 2005-02-02\n" - " Transforming XML\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: An Introduction to TMAPI\n" - " http://www.xml.com/pub/a/2005/02/02/tmapi.html\n" - " \n" - " TMAPI, a Java Topic Map API, is the standard way to interact with XML Topic Maps programmatically from Java. This article provides a tutorial for TMAPI. \n" - " \n" - " XML.com\n" - " Robert Barta, Oliver Leimig\n" - " Metadata, Metadata\n" - " O'Reilly Media, Inc.\n" - " 2005-02-02\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Formal Taxonomies for the U.S. Government\n" - " http://www.xml.com/pub/a/2005/01/26/formtax.html\n" - " \n" - " Mike Daconta, Metadata Program Manager at the Department of Homeland Security, introduces the notion of a formal taxonomy in the context of the Federal Enteriprise Architecture's Data Reference Model.\n" - " \n" - " XML.com\n" - " Michael Daconta\n" - " Metadata, Metadata\n" - " O'Reilly Media, Inc.\n" - " 2005-01-26\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Hacking Open Office\n" - " http://www.xml.com/pub/a/2005/01/26/hacking-ooo.html\n" - " \n" - " Peter Sefton shows us how to use XML tools to hack Open Office file formats.\n" - " \n" - " XML.com\n" - " Peter Sefton\n" - " Programming, Tools, Publishing\n" - " O'Reilly Media, Inc.\n" - " 2005-01-26\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: SIMILE: Practical Metadata for the Semantic Web\n" - " http://www.xml.com/pub/a/2005/01/26/simile.html\n" - " \n" - " Digital libraries and generic metadata form part of the background assumptions and forward-looking goals of the Semantic Web. SIMILE is an interesting project aimed at realizing some of those goals.\n" - " \n" - " XML.com\n" - " Stephen Garland, Ryan Lee, Stefano Mazzocchi\n" - " Semantic Web, Metadata\n" - " O'Reilly Media, Inc.\n" - " 2005-01-26\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Python and XML: Introducing the Amara XML Toolkit\n" - " http://www.xml.com/pub/a/2005/01/19/amara.html\n" - " \n" - " Uche Ogbuji introduces Amara, his new collection of XML tools for Python.\n" - " \n" - " XML.com\n" - " Uche Ogbuji\n" - " Programming, Programming\n" - " O'Reilly Media, Inc.\n" - " 2005-01-19\n" - " Python and XML\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Printing XML: Why CSS Is Better than XSL\n" - " http://www.xml.com/pub/a/2005/01/19/print.html\n" - " \n" - " One of the old school debates among XML developers is &quot;CSS versus XSLT.&quot; H&aring;kun Wium Lie and Michael Day revive that debate with a shot across XSL's bow.\n" - " \n" - " XML.com\n" - " Michael Day, H&aring;kon Wium Lie\n" - " Style, Publishing\n" - " O'Reilly Media, Inc.\n" - " 2005-01-19\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Reviewing the Architecture of the World Wide Web\n" - " http://www.xml.com/pub/a/2005/01/19/review.html\n" - " \n" - " Harry Halpin reviews the final published edition of the W3C TAG's Architecture of the World Wide Web document.\n" - " \n" - " XML.com\n" - " Harry Halpin\n" - " Web, Perspectives\n" - " O'Reilly Media, Inc.\n" - " 2005-01-19\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: SAML 2: The Building Blocks of Federated Identity\n" - " http://www.xml.com/pub/a/2005/01/12/saml2.html\n" - " \n" - " Paul Madsen reports on the developments in web services security, including a new major release of SAML, which provides the basis for building federated identity.\n" - " \n" - " XML.com\n" - " Paul Madsen\n" - " Web Services, Specifications\n" - " O'Reilly Media, Inc.\n" - " 2005-01-12\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - " \n" - " Features: Introducing Comega\n" - " http://www.xml.com/pub/a/2005/01/12/comega.html\n" - " \n" - " Dare Obasanjo explains some of the ways in which C&omega;--a new language from Microsoft Research--makes XML processing easier and more natural.\n" - " \n" - " XML.com\n" - " Dare Obasanjo\n" - " Programming, Instruction\n" - " O'Reilly Media, Inc.\n" - " 2005-01-12\n" - " Features\n" - " text/html\n" - " en-us\n" - " Copyright 2005, O'Reilly Media, Inc.\n" - " \n" - "\n" - "\n" - " \n" - " Search\n" - " Search Meerkat...\n" - " s\n" - " http://meerkat.oreillynet.com/\n" - " \n" - "\n" - "\n"; - - -const std::string SAXParserTest::ENCODING = - "" - "\244"; +// +// SAXParserTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/SAXParserTest.cpp#3 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "SAXParserTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/SAX/SAXParser.h" +#include "Poco/SAX/InputSource.h" +#include "Poco/SAX/EntityResolver.h" +#include "Poco/SAX/SAXException.h" +#include "Poco/SAX/WhitespaceFilter.h" +#include "Poco/XML/XMLWriter.h" +#include "Poco/Latin9Encoding.h" +#include "Poco/FileStream.h" +#include + + +using Poco::XML::SAXParser; +using Poco::XML::XMLWriter; +using Poco::XML::XMLReader; +using Poco::XML::InputSource; +using Poco::XML::EntityResolver; +using Poco::XML::XMLString; +using Poco::XML::SAXParseException; +using Poco::XML::WhitespaceFilter; + + +class TestEntityResolver: public EntityResolver +{ +public: + InputSource* resolveEntity(const XMLString* publicId, const XMLString& systemId) + { + if (systemId == "include.xml") + { + std::istringstream* istr = new std::istringstream(SAXParserTest::INCLUDE); + InputSource* pIS = new InputSource(*istr); + pIS->setSystemId(systemId); + return pIS; + } + else if (systemId == "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent") + { + std::istringstream* istr = new std::istringstream(SAXParserTest::XHTML_LATIN1_ENTITIES); + InputSource* pIS = new InputSource(*istr); + pIS->setSystemId(systemId); + return pIS; + } + return 0; + } + + void releaseInputSource(InputSource* pSource) + { + delete pSource->getByteStream(); + delete pSource; + } +}; + + +SAXParserTest::SAXParserTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +SAXParserTest::~SAXParserTest() +{ +} + + +void SAXParserTest::testSimple1() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, SIMPLE1); + assert (xml == ""); +} + + +void SAXParserTest::testSimple2() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, SIMPLE2); + assert (xml == ""); +} + + +void SAXParserTest::testAttributes() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, ATTRIBUTES); + assert (xml == ATTRIBUTES); +} + + +void SAXParserTest::testCDATA() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, CDATA); + assert (xml == CDATA); +} + + +void SAXParserTest::testComment() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, COMMENT); + assert (xml == COMMENT); +} + + +void SAXParserTest::testPI() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, PROCESSING_INSTRUCTION); + assert (xml == PROCESSING_INSTRUCTION); +} + + +void SAXParserTest::testDTD() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, DTD); + assert (xml == ""); +} + + +void SAXParserTest::testInternalEntity() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, INTERNAL_ENTITY); + assert (xml == "\n\tApplied Informatics\n"); +} + + +void SAXParserTest::testNotation() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, NOTATION); + assert (xml == "" + "]>" + ""); +} + + +void SAXParserTest::testExternalUnparsed() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, EXTERNAL_UNPARSED); + assert (xml == "" + "]>" + ""); +} + + +void SAXParserTest::testExternalParsed() +{ + SAXParser parser; + TestEntityResolver resolver; + parser.setEntityResolver(&resolver); + parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true); + std::string xml = parse(parser, XMLWriter::CANONICAL, EXTERNAL_PARSED); + assert (xml == "\n\t\n\tAn external entity.\n\n\n"); +} + + +void SAXParserTest::testDefaultNamespace() +{ + SAXParser parser; + std::string xml = parse(parser, XMLWriter::CANONICAL, DEFAULT_NAMESPACE); + assert (xml == DEFAULT_NAMESPACE); +} + + +void SAXParserTest::testNamespaces() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); + std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); + assert (xml == NAMESPACES); +} + + +void SAXParserTest::testNamespacesNoPrefixes() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); + std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); + assert (xml == NAMESPACES); +} + + +void SAXParserTest::testNoNamespaces() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); + std::string xml = parse(parser, XMLWriter::CANONICAL, NAMESPACES); + assert (xml == NAMESPACES); +} + + +void SAXParserTest::testUndeclaredNamespace() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true); + try + { + std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); + fail("undeclared namespace - must throw exception"); + } + catch (SAXParseException&) + { + } +} + + +void SAXParserTest::testUndeclaredNamespaceNoPrefixes() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, true); + parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false); + try + { + std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); + fail("undeclared namespace - must throw exception"); + } + catch (SAXParseException&) + { + } +} + + +void SAXParserTest::testUndeclaredNoNamespace() +{ + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); + std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE); + assert (xml == UNDECLARED_NAMESPACE); +} + + +void SAXParserTest::testRSS() +{ + SAXParser parser; + WhitespaceFilter filter(&parser); + TestEntityResolver resolver; + filter.setEntityResolver(&resolver); + parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true); + parser.setFeature(XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES, true); + + std::istringstream istr(RSS); + Poco::FileOutputStream ostr("rss.xml"); + XMLWriter writer(ostr, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + filter.setContentHandler(&writer); + filter.setDTDHandler(&writer); + filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + InputSource source(istr); + filter.parse(&source); +} + + +void SAXParserTest::testEncoding() +{ + SAXParser parser; + Poco::Latin9Encoding encoding; + parser.addEncoding("ISO-8859-15", &encoding); + + std::istringstream istr(ENCODING); + std::ostringstream ostr; + XMLWriter writer(ostr, XMLWriter::WRITE_XML_DECLARATION, "ISO-8859-15", encoding); + parser.setContentHandler(&writer); + parser.setDTDHandler(&writer); + parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + InputSource source(istr); + parser.parse(&source); + + std::string xml = ostr.str(); + assert (xml == ENCODING); +} + + +void SAXParserTest::testCharacters() +{ + static const XMLString xml(" TEXT & AMPERSAND "); + SAXParser parser; + parser.setFeature(XMLReader::FEATURE_NAMESPACES, false); + std::string result = parse(parser, XMLWriter::CANONICAL, xml); + assert (result == xml); +} + + +void SAXParserTest::testParseMemory() +{ + SAXParser parser; + std::string xml = parseMemory(parser, XMLWriter::CANONICAL, ATTRIBUTES); + assert (xml == ATTRIBUTES); +} + + +void SAXParserTest::setUp() +{ +} + + +void SAXParserTest::tearDown() +{ +} + + +std::string SAXParserTest::parse(XMLReader& reader, int options, const std::string& data) +{ + std::istringstream istr(data); + std::ostringstream ostr; + XMLWriter writer(ostr, options); + reader.setContentHandler(&writer); + reader.setDTDHandler(&writer); + reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + InputSource source(istr); + reader.parse(&source); + return ostr.str(); +} + + +std::string SAXParserTest::parseMemory(XMLReader& reader, int options, const std::string& data) +{ + std::istringstream istr(data); + std::ostringstream ostr; + XMLWriter writer(ostr, options); + reader.setContentHandler(&writer); + reader.setDTDHandler(&writer); + reader.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast(&writer)); + reader.parseMemoryNP(data.data(), data.size()); + return ostr.str(); +} + + +CppUnit::Test* SAXParserTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXParserTest"); + + CppUnit_addTest(pSuite, SAXParserTest, testSimple1); + CppUnit_addTest(pSuite, SAXParserTest, testSimple2); + CppUnit_addTest(pSuite, SAXParserTest, testAttributes); + CppUnit_addTest(pSuite, SAXParserTest, testCDATA); + CppUnit_addTest(pSuite, SAXParserTest, testComment); + CppUnit_addTest(pSuite, SAXParserTest, testPI); + CppUnit_addTest(pSuite, SAXParserTest, testDTD); + CppUnit_addTest(pSuite, SAXParserTest, testInternalEntity); + CppUnit_addTest(pSuite, SAXParserTest, testNotation); + CppUnit_addTest(pSuite, SAXParserTest, testExternalUnparsed); + CppUnit_addTest(pSuite, SAXParserTest, testExternalParsed); + CppUnit_addTest(pSuite, SAXParserTest, testDefaultNamespace); + CppUnit_addTest(pSuite, SAXParserTest, testNamespaces); + CppUnit_addTest(pSuite, SAXParserTest, testNamespacesNoPrefixes); + CppUnit_addTest(pSuite, SAXParserTest, testNoNamespaces); + CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespace); + CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNamespaceNoPrefixes); + CppUnit_addTest(pSuite, SAXParserTest, testUndeclaredNoNamespace); + CppUnit_addTest(pSuite, SAXParserTest, testRSS); + CppUnit_addTest(pSuite, SAXParserTest, testEncoding); + CppUnit_addTest(pSuite, SAXParserTest, testParseMemory); + CppUnit_addTest(pSuite, SAXParserTest, testCharacters); + + return pSuite; +} + + +const std::string SAXParserTest::SIMPLE1 = + "\n"; + + +const std::string SAXParserTest::SIMPLE2 = + "\n" + "\n"; + + +const std::string SAXParserTest::ATTRIBUTES = + "\n" + "\t\n" + ""; + + +const std::string SAXParserTest::CDATA = + "\n" + "is inside a CDATA section.\n" + "]]>\n" + ""; + + +const std::string SAXParserTest::COMMENT = + "" + "\n" + "\t\n" + "\t\n" + ""; + + +const std::string SAXParserTest::PROCESSING_INSTRUCTION = + "\n" + "\t\n" + "\t\t\n" + "\t\ttest\n" + "\t\n" + "\t\n" + "\t\t

this is a test

\n" + "\t\n" + ""; + + +const std::string SAXParserTest::DTD = + "\n" + "\n" + ""; + + +const std::string SAXParserTest::INTERNAL_ENTITY = + "\n" + "]>\n" + "\n" + "\t&appinf;\n" + ""; + + +const std::string SAXParserTest::NOTATION = + "\n" + "\n" + "\t\n" + "]>\n" + ""; + + +const std::string SAXParserTest::EXTERNAL_UNPARSED = + "\n" + "\n" + "\t\n" + "]>\n" + ""; + + +const std::string SAXParserTest::EXTERNAL_PARSED = + "\n" + "\n" + "]>\n" + "\n" + "\t&include;\n" + "\n"; + + +const std::string SAXParserTest::INCLUDE = + "\n" + "\tAn external entity.\n" + "\n"; + + +const std::string SAXParserTest::DEFAULT_NAMESPACE = + "\n" + "\tdata\n" + ""; + + +const std::string SAXParserTest::NAMESPACES = + "\n" + "\tdata\n" + "\t\n" + "\t\tmore data\n" + "\t\n" + ""; + + +const std::string SAXParserTest::UNDECLARED_NAMESPACE = + "\n" + "\tdata\n" + "\t\n" + "\t\tmore data\n" + "\t\n" + "\t\n" + ""; + + +const std::string SAXParserTest::XHTML_LATIN1_ENTITIES = + "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n"; + +const std::string SAXParserTest::RSS = + "\n" + "\n" + "\n" + "%HTMLlat1;\n" + "]>\n" + "\n" + " \n" + "\n" + " \n" + " XML.com \n" + " http://www.xml.com/\n" + " XML.com features a rich mix of information and services for the XML community.\n" + " hourly\n" + " 2\n" + " 2000-01-01T12:00+00:00\n" + "\n" + " \n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + " \n" + "\n" + " \n" + " Meerkat Powered!\n" + " http://meerkat.oreillynet.com/icons/meerkat-powered.jpg\n" + " http://meerkat.oreillynet.com\n" + " \n" + "\n" + " \n" + " Features: Top 10 XForms Engines\n" + " http://www.xml.com/pub/a/2005/02/09/xforms.html\n" + " \n" + " Micah Dubinko, one of the gurus of XForms, offers a rundown on the state of XForms engines for 2005.\n" + " \n" + " XML.com\n" + " Micah Dubinko\n" + " Web, Applications\n" + " O'Reilly Media, Inc.\n" + " 2005-02-09\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Comparing CSS and XSL: A Reply from Norm Walsh\n" + " http://www.xml.com/pub/a/2005/02/09/cssorxsl.html\n" + " \n" + " Norm Walsh responds to a recent article about CSS and XSL, explaining how and when and why you'd want to use XSLFO or CSS or XSLT.\n" + " \n" + " XML.com\n" + " Norman Walsh\n" + " Style\n" + " O'Reilly Media, Inc.\n" + " 2005-02-09\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Very Dynamic Web Interfaces\n" + " http://www.xml.com/pub/a/2005/02/09/xml-http-request.html\n" + " \n" + " Drew McLellan explains how to use XMLHTTPRequest and Javascript to create web applications with very dynamic, smooth interfaces.\n" + " \n" + " XML.com\n" + " Drew McLellan\n" + " Web Development, Instruction\n" + " O'Reilly Media, Inc.\n" + " 2005-02-09\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Transforming XML: The XPath 2.0 Data Model\n" + " http://www.xml.com/pub/a/2005/02/02/xpath2.html\n" + " \n" + " Bob DuCharme, in his latest Transforming XML column, examines the XPath 2.0, hence the XSLT 2.0, data model.\n" + " \n" + " XML.com\n" + " Bob DuCharme\n" + " Style, Style\n" + " O'Reilly Media, Inc.\n" + " 2005-02-02\n" + " Transforming XML\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " XML Tourist: The Silent Soundtrack\n" + " http://www.xml.com/pub/a/2005/02/02/silent.html\n" + " \n" + " In this installation of XML Tourist, John E. Simpson presents an overview of the types of sound-to-text captioning available. Pinpointing closed captioning as the most suitable for use with computerized multimedia, he then explains how XML-based solutions address synchronization issues.\n" + " \n" + " XML.com\n" + " John E. Simpson\n" + " Graphics, Vertical Industries\n" + " O'Reilly Media, Inc.\n" + " 2005-02-02\n" + " XML Tourist\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Transforming XML: The XML 2.0 Data Model\n" + " http://www.xml.com/pub/a/2005/02/02/xpath2.html\n" + " \n" + " Bob DuCharme, in his latest Transforming XML column, examines the XPath 2.0, hence the XSLT 2.0, data model.\n" + " \n" + " XML.com\n" + " Bob DuCharme\n" + " Style, Style\n" + " O'Reilly Media, Inc.\n" + " 2005-02-02\n" + " Transforming XML\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: An Introduction to TMAPI\n" + " http://www.xml.com/pub/a/2005/02/02/tmapi.html\n" + " \n" + " TMAPI, a Java Topic Map API, is the standard way to interact with XML Topic Maps programmatically from Java. This article provides a tutorial for TMAPI. \n" + " \n" + " XML.com\n" + " Robert Barta, Oliver Leimig\n" + " Metadata, Metadata\n" + " O'Reilly Media, Inc.\n" + " 2005-02-02\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Formal Taxonomies for the U.S. Government\n" + " http://www.xml.com/pub/a/2005/01/26/formtax.html\n" + " \n" + " Mike Daconta, Metadata Program Manager at the Department of Homeland Security, introduces the notion of a formal taxonomy in the context of the Federal Enteriprise Architecture's Data Reference Model.\n" + " \n" + " XML.com\n" + " Michael Daconta\n" + " Metadata, Metadata\n" + " O'Reilly Media, Inc.\n" + " 2005-01-26\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Hacking Open Office\n" + " http://www.xml.com/pub/a/2005/01/26/hacking-ooo.html\n" + " \n" + " Peter Sefton shows us how to use XML tools to hack Open Office file formats.\n" + " \n" + " XML.com\n" + " Peter Sefton\n" + " Programming, Tools, Publishing\n" + " O'Reilly Media, Inc.\n" + " 2005-01-26\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: SIMILE: Practical Metadata for the Semantic Web\n" + " http://www.xml.com/pub/a/2005/01/26/simile.html\n" + " \n" + " Digital libraries and generic metadata form part of the background assumptions and forward-looking goals of the Semantic Web. SIMILE is an interesting project aimed at realizing some of those goals.\n" + " \n" + " XML.com\n" + " Stephen Garland, Ryan Lee, Stefano Mazzocchi\n" + " Semantic Web, Metadata\n" + " O'Reilly Media, Inc.\n" + " 2005-01-26\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Python and XML: Introducing the Amara XML Toolkit\n" + " http://www.xml.com/pub/a/2005/01/19/amara.html\n" + " \n" + " Uche Ogbuji introduces Amara, his new collection of XML tools for Python.\n" + " \n" + " XML.com\n" + " Uche Ogbuji\n" + " Programming, Programming\n" + " O'Reilly Media, Inc.\n" + " 2005-01-19\n" + " Python and XML\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Printing XML: Why CSS Is Better than XSL\n" + " http://www.xml.com/pub/a/2005/01/19/print.html\n" + " \n" + " One of the old school debates among XML developers is &quot;CSS versus XSLT.&quot; H&aring;kun Wium Lie and Michael Day revive that debate with a shot across XSL's bow.\n" + " \n" + " XML.com\n" + " Michael Day, H&aring;kon Wium Lie\n" + " Style, Publishing\n" + " O'Reilly Media, Inc.\n" + " 2005-01-19\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Reviewing the Architecture of the World Wide Web\n" + " http://www.xml.com/pub/a/2005/01/19/review.html\n" + " \n" + " Harry Halpin reviews the final published edition of the W3C TAG's Architecture of the World Wide Web document.\n" + " \n" + " XML.com\n" + " Harry Halpin\n" + " Web, Perspectives\n" + " O'Reilly Media, Inc.\n" + " 2005-01-19\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: SAML 2: The Building Blocks of Federated Identity\n" + " http://www.xml.com/pub/a/2005/01/12/saml2.html\n" + " \n" + " Paul Madsen reports on the developments in web services security, including a new major release of SAML, which provides the basis for building federated identity.\n" + " \n" + " XML.com\n" + " Paul Madsen\n" + " Web Services, Specifications\n" + " O'Reilly Media, Inc.\n" + " 2005-01-12\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + " \n" + " Features: Introducing Comega\n" + " http://www.xml.com/pub/a/2005/01/12/comega.html\n" + " \n" + " Dare Obasanjo explains some of the ways in which C&omega;--a new language from Microsoft Research--makes XML processing easier and more natural.\n" + " \n" + " XML.com\n" + " Dare Obasanjo\n" + " Programming, Instruction\n" + " O'Reilly Media, Inc.\n" + " 2005-01-12\n" + " Features\n" + " text/html\n" + " en-us\n" + " Copyright 2005, O'Reilly Media, Inc.\n" + " \n" + "\n" + "\n" + " \n" + " Search\n" + " Search Meerkat...\n" + " s\n" + " http://meerkat.oreillynet.com/\n" + " \n" + "\n" + "\n"; + + +const std::string SAXParserTest::ENCODING = + "" + "\244"; diff --git a/XML/testsuite/src/SAXParserTest.h b/XML/testsuite/src/SAXParserTest.h index c9574631b..a95feec3d 100644 --- a/XML/testsuite/src/SAXParserTest.h +++ b/XML/testsuite/src/SAXParserTest.h @@ -1,102 +1,102 @@ -// -// SAXParserTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/SAXParserTest.h#2 $ -// -// Definition of the SAXParserTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAXParserTest_INCLUDED -#define SAXParserTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" -#include "Poco/SAX/XMLReader.h" - - -class SAXParserTest: public CppUnit::TestCase -{ -public: - SAXParserTest(const std::string& name); - ~SAXParserTest(); - - void testSimple1(); - void testSimple2(); - void testAttributes(); - void testCDATA(); - void testComment(); - void testPI(); - void testDTD(); - void testInternalEntity(); - void testNotation(); - void testExternalUnparsed(); - void testExternalParsed(); - void testDefaultNamespace(); - void testNamespaces(); - void testNamespacesNoPrefixes(); - void testNoNamespaces(); - void testUndeclaredNamespace(); - void testUndeclaredNamespaceNoPrefixes(); - void testUndeclaredNoNamespace(); - void testRSS(); - void testEncoding(); - void testParseMemory(); - void testCharacters(); - - void setUp(); - void tearDown(); - - std::string parse(Poco::XML::XMLReader& reader, int options, const std::string& data); - std::string parseMemory(Poco::XML::XMLReader& reader, int options, const std::string& data); - - static CppUnit::Test* suite(); - - static const std::string SIMPLE1; - static const std::string SIMPLE2; - static const std::string ATTRIBUTES; - static const std::string CDATA; - static const std::string COMMENT; - static const std::string PROCESSING_INSTRUCTION; - static const std::string DTD; - static const std::string INTERNAL_ENTITY; - static const std::string NOTATION; - static const std::string EXTERNAL_UNPARSED; - static const std::string EXTERNAL_PARSED; - static const std::string INCLUDE; - static const std::string DEFAULT_NAMESPACE; - static const std::string NAMESPACES; - static const std::string UNDECLARED_NAMESPACE; - static const std::string XHTML_LATIN1_ENTITIES; - static const std::string RSS; - static const std::string ENCODING; -}; - - -#endif // SAXParserTest_INCLUDED +// +// SAXParserTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/SAXParserTest.h#2 $ +// +// Definition of the SAXParserTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAXParserTest_INCLUDED +#define SAXParserTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" +#include "Poco/SAX/XMLReader.h" + + +class SAXParserTest: public CppUnit::TestCase +{ +public: + SAXParserTest(const std::string& name); + ~SAXParserTest(); + + void testSimple1(); + void testSimple2(); + void testAttributes(); + void testCDATA(); + void testComment(); + void testPI(); + void testDTD(); + void testInternalEntity(); + void testNotation(); + void testExternalUnparsed(); + void testExternalParsed(); + void testDefaultNamespace(); + void testNamespaces(); + void testNamespacesNoPrefixes(); + void testNoNamespaces(); + void testUndeclaredNamespace(); + void testUndeclaredNamespaceNoPrefixes(); + void testUndeclaredNoNamespace(); + void testRSS(); + void testEncoding(); + void testParseMemory(); + void testCharacters(); + + void setUp(); + void tearDown(); + + std::string parse(Poco::XML::XMLReader& reader, int options, const std::string& data); + std::string parseMemory(Poco::XML::XMLReader& reader, int options, const std::string& data); + + static CppUnit::Test* suite(); + + static const std::string SIMPLE1; + static const std::string SIMPLE2; + static const std::string ATTRIBUTES; + static const std::string CDATA; + static const std::string COMMENT; + static const std::string PROCESSING_INSTRUCTION; + static const std::string DTD; + static const std::string INTERNAL_ENTITY; + static const std::string NOTATION; + static const std::string EXTERNAL_UNPARSED; + static const std::string EXTERNAL_PARSED; + static const std::string INCLUDE; + static const std::string DEFAULT_NAMESPACE; + static const std::string NAMESPACES; + static const std::string UNDECLARED_NAMESPACE; + static const std::string XHTML_LATIN1_ENTITIES; + static const std::string RSS; + static const std::string ENCODING; +}; + + +#endif // SAXParserTest_INCLUDED diff --git a/XML/testsuite/src/SAXTestSuite.cpp b/XML/testsuite/src/SAXTestSuite.cpp index b45a5f8dc..76edc5526 100644 --- a/XML/testsuite/src/SAXTestSuite.cpp +++ b/XML/testsuite/src/SAXTestSuite.cpp @@ -1,48 +1,48 @@ -// -// SAXTestSuite.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/SAXTestSuite.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "SAXTestSuite.h" -#include "AttributesImplTest.h" -#include "NamespaceSupportTest.h" -#include "SAXParserTest.h" - - -CppUnit::Test* SAXTestSuite::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXTestSuite"); - - pSuite->addTest(AttributesImplTest::suite()); - pSuite->addTest(NamespaceSupportTest::suite()); - pSuite->addTest(SAXParserTest::suite()); - - return pSuite; -} +// +// SAXTestSuite.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/SAXTestSuite.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "SAXTestSuite.h" +#include "AttributesImplTest.h" +#include "NamespaceSupportTest.h" +#include "SAXParserTest.h" + + +CppUnit::Test* SAXTestSuite::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SAXTestSuite"); + + pSuite->addTest(AttributesImplTest::suite()); + pSuite->addTest(NamespaceSupportTest::suite()); + pSuite->addTest(SAXParserTest::suite()); + + return pSuite; +} diff --git a/XML/testsuite/src/SAXTestSuite.h b/XML/testsuite/src/SAXTestSuite.h index b664192d4..d228a37a6 100644 --- a/XML/testsuite/src/SAXTestSuite.h +++ b/XML/testsuite/src/SAXTestSuite.h @@ -1,49 +1,49 @@ -// -// SAXTestSuite.h -// -// $Id: //poco/1.3/XML/testsuite/src/SAXTestSuite.h#1 $ -// -// Definition of the SAXTestSuite class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef SAXTestSuite_INCLUDED -#define SAXTestSuite_INCLUDED - - -#include "CppUnit/TestSuite.h" - - -class SAXTestSuite -{ -public: - static CppUnit::Test* suite(); -}; - - -#endif // SAXTestSuite_INCLUDED +// +// SAXTestSuite.h +// +// $Id: //poco/1.3/XML/testsuite/src/SAXTestSuite.h#1 $ +// +// Definition of the SAXTestSuite class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef SAXTestSuite_INCLUDED +#define SAXTestSuite_INCLUDED + + +#include "CppUnit/TestSuite.h" + + +class SAXTestSuite +{ +public: + static CppUnit::Test* suite(); +}; + + +#endif // SAXTestSuite_INCLUDED diff --git a/XML/testsuite/src/TextTest.cpp b/XML/testsuite/src/TextTest.cpp index 85e196c3b..eb950aafc 100644 --- a/XML/testsuite/src/TextTest.cpp +++ b/XML/testsuite/src/TextTest.cpp @@ -1,189 +1,189 @@ -// -// TextTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/TextTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "TextTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/CDATASection.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::Text; -using Poco::XML::CDATASection; -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -TextTest::TextTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -TextTest::~TextTest() -{ -} - - -void TextTest::testLength() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode(""); - assert (pText1->length() == 0); - AutoPtr pText2 = pDoc->createTextNode("foo bar"); - assert (pText2->length() == 7); -} - - -void TextTest::testSubstring() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode("foo bar"); - XMLString str = pText1->substringData(0, 3); - assert (str == "foo"); - str = pText1->substringData(4, 3); - assert (str == "bar"); - str = pText1->substringData(3, 0); - assert (str == ""); -} - - -void TextTest::testAppend() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode("foo"); - pText1->appendData("bar"); - assert (pText1->data() == "foobar"); -} - - -void TextTest::testInsert() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode("bar"); - pText1->insertData(0, "foo"); - assert (pText1->data() == "foobar"); - pText1->insertData(pText1->length(), "!"); - assert (pText1->data() == "foobar!"); - pText1->insertData(3, " "); - assert (pText1->data() == "foo bar!"); -} - - -void TextTest::testDelete() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode("foo bar"); - pText1->deleteData(3, 1); - assert (pText1->data() == "foobar"); - pText1->deleteData(0, 3); - assert (pText1->data() == "bar"); - pText1->deleteData(1, 0); - assert (pText1->data() == "bar"); - pText1->deleteData(0, pText1->length()); - assert (pText1->data() == ""); -} - - -void TextTest::testReplace() -{ - AutoPtr pDoc = new Document; - AutoPtr pText1 = pDoc->createTextNode("foo bar"); - pText1->replaceData(0, 3, "FOO"); - assert (pText1->data() == "FOO bar"); - pText1->replaceData(4, 3, "BAR!!!"); - assert (pText1->data() == "FOO BAR!!!"); - pText1->replaceData(3, 1, "-"); - assert (pText1->data() == "FOO-BAR!!!"); - pText1->replaceData(3, 1, "---"); - assert (pText1->data() == "FOO---BAR!!!"); - pText1->replaceData(3, 3, " "); - assert (pText1->data() == "FOO BAR!!!"); - pText1->replaceData(0, pText1->length(), "foo bar"); - assert (pText1->data() == "foo bar"); -} - - -void TextTest::testSplit() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createCDATASection("foobar"); - pElem->appendChild(pText1); - pText1->splitText(3); - assert (pElem->firstChild()->nodeValue() == "foo"); - assert (pElem->lastChild()->nodeValue() == "bar"); -} - - -void TextTest::testSplitCDATA() -{ - AutoPtr pDoc = new Document; - AutoPtr pElem = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("foobar"); - pElem->appendChild(pText1); - pText1->splitText(3); - assert (pElem->firstChild()->nodeValue() == "foo"); - assert (pElem->lastChild()->nodeValue() == "bar"); - -} - - -void TextTest::setUp() -{ -} - - -void TextTest::tearDown() -{ -} - - -CppUnit::Test* TextTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextTest"); - - CppUnit_addTest(pSuite, TextTest, testLength); - CppUnit_addTest(pSuite, TextTest, testSubstring); - CppUnit_addTest(pSuite, TextTest, testAppend); - CppUnit_addTest(pSuite, TextTest, testInsert); - CppUnit_addTest(pSuite, TextTest, testDelete); - CppUnit_addTest(pSuite, TextTest, testReplace); - CppUnit_addTest(pSuite, TextTest, testSplit); - CppUnit_addTest(pSuite, TextTest, testSplitCDATA); - - return pSuite; -} +// +// TextTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/TextTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "TextTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/CDATASection.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::Text; +using Poco::XML::CDATASection; +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +TextTest::TextTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +TextTest::~TextTest() +{ +} + + +void TextTest::testLength() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode(""); + assert (pText1->length() == 0); + AutoPtr pText2 = pDoc->createTextNode("foo bar"); + assert (pText2->length() == 7); +} + + +void TextTest::testSubstring() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode("foo bar"); + XMLString str = pText1->substringData(0, 3); + assert (str == "foo"); + str = pText1->substringData(4, 3); + assert (str == "bar"); + str = pText1->substringData(3, 0); + assert (str == ""); +} + + +void TextTest::testAppend() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode("foo"); + pText1->appendData("bar"); + assert (pText1->data() == "foobar"); +} + + +void TextTest::testInsert() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode("bar"); + pText1->insertData(0, "foo"); + assert (pText1->data() == "foobar"); + pText1->insertData(pText1->length(), "!"); + assert (pText1->data() == "foobar!"); + pText1->insertData(3, " "); + assert (pText1->data() == "foo bar!"); +} + + +void TextTest::testDelete() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode("foo bar"); + pText1->deleteData(3, 1); + assert (pText1->data() == "foobar"); + pText1->deleteData(0, 3); + assert (pText1->data() == "bar"); + pText1->deleteData(1, 0); + assert (pText1->data() == "bar"); + pText1->deleteData(0, pText1->length()); + assert (pText1->data() == ""); +} + + +void TextTest::testReplace() +{ + AutoPtr pDoc = new Document; + AutoPtr pText1 = pDoc->createTextNode("foo bar"); + pText1->replaceData(0, 3, "FOO"); + assert (pText1->data() == "FOO bar"); + pText1->replaceData(4, 3, "BAR!!!"); + assert (pText1->data() == "FOO BAR!!!"); + pText1->replaceData(3, 1, "-"); + assert (pText1->data() == "FOO-BAR!!!"); + pText1->replaceData(3, 1, "---"); + assert (pText1->data() == "FOO---BAR!!!"); + pText1->replaceData(3, 3, " "); + assert (pText1->data() == "FOO BAR!!!"); + pText1->replaceData(0, pText1->length(), "foo bar"); + assert (pText1->data() == "foo bar"); +} + + +void TextTest::testSplit() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createCDATASection("foobar"); + pElem->appendChild(pText1); + pText1->splitText(3); + assert (pElem->firstChild()->nodeValue() == "foo"); + assert (pElem->lastChild()->nodeValue() == "bar"); +} + + +void TextTest::testSplitCDATA() +{ + AutoPtr pDoc = new Document; + AutoPtr pElem = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("foobar"); + pElem->appendChild(pText1); + pText1->splitText(3); + assert (pElem->firstChild()->nodeValue() == "foo"); + assert (pElem->lastChild()->nodeValue() == "bar"); + +} + + +void TextTest::setUp() +{ +} + + +void TextTest::tearDown() +{ +} + + +CppUnit::Test* TextTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextTest"); + + CppUnit_addTest(pSuite, TextTest, testLength); + CppUnit_addTest(pSuite, TextTest, testSubstring); + CppUnit_addTest(pSuite, TextTest, testAppend); + CppUnit_addTest(pSuite, TextTest, testInsert); + CppUnit_addTest(pSuite, TextTest, testDelete); + CppUnit_addTest(pSuite, TextTest, testReplace); + CppUnit_addTest(pSuite, TextTest, testSplit); + CppUnit_addTest(pSuite, TextTest, testSplitCDATA); + + return pSuite; +} diff --git a/XML/testsuite/src/TextTest.h b/XML/testsuite/src/TextTest.h index 420a3fc5b..c9e20f270 100644 --- a/XML/testsuite/src/TextTest.h +++ b/XML/testsuite/src/TextTest.h @@ -1,67 +1,67 @@ -// -// TextTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/TextTest.h#1 $ -// -// Definition of the TextTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef TextTest_INCLUDED -#define TextTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class TextTest: public CppUnit::TestCase -{ -public: - TextTest(const std::string& name); - ~TextTest(); - - void testLength(); - void testSubstring(); - void testAppend(); - void testInsert(); - void testDelete(); - void testReplace(); - void testSplit(); - void testSplitCDATA(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // TextTest_INCLUDED +// +// TextTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/TextTest.h#1 $ +// +// Definition of the TextTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef TextTest_INCLUDED +#define TextTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class TextTest: public CppUnit::TestCase +{ +public: + TextTest(const std::string& name); + ~TextTest(); + + void testLength(); + void testSubstring(); + void testAppend(); + void testInsert(); + void testDelete(); + void testReplace(); + void testSplit(); + void testSplitCDATA(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // TextTest_INCLUDED diff --git a/XML/testsuite/src/TreeWalkerTest.cpp b/XML/testsuite/src/TreeWalkerTest.cpp index 1705a473e..5e2053596 100644 --- a/XML/testsuite/src/TreeWalkerTest.cpp +++ b/XML/testsuite/src/TreeWalkerTest.cpp @@ -1,329 +1,329 @@ -// -// TreeWalkerTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/TreeWalkerTest.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "TreeWalkerTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/DOM/TreeWalker.h" -#include "Poco/DOM/NodeFilter.h" -#include "Poco/DOM/Document.h" -#include "Poco/DOM/Element.h" -#include "Poco/DOM/Text.h" -#include "Poco/DOM/AutoPtr.h" - - -using Poco::XML::TreeWalker; -using Poco::XML::NodeFilter; -using Poco::XML::Element; -using Poco::XML::Document; -using Poco::XML::Text; -using Poco::XML::Node; -using Poco::XML::AutoPtr; -using Poco::XML::XMLString; - - -namespace -{ - class RejectNodeFilter: public NodeFilter - { - short acceptNode(Node* node) - { - if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1" || node->nodeName() == "root") - return NodeFilter::FILTER_ACCEPT; - else - return NodeFilter::FILTER_REJECT; - } - }; - - class SkipNodeFilter: public NodeFilter - { - short acceptNode(Node* node) - { - if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1") - return NodeFilter::FILTER_ACCEPT; - else - return NodeFilter::FILTER_SKIP; - } - }; -} - - -TreeWalkerTest::TreeWalkerTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -TreeWalkerTest::~TreeWalkerTest() -{ -} - - -void TreeWalkerTest::testShowAll() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - TreeWalker it(pRoot, NodeFilter::SHOW_ALL); - - assert (it.currentNode() == pRoot); - assert (it.nextNode() == pElem1); - assert (it.nextNode() == pText1); - assert (it.nextNode() == pElem2); - assert (it.nextNode() == pText2); - assert (it.nextNode() == 0); - - assert (it.currentNode() == pText2); - assert (it.previousNode() == pElem2); - assert (it.previousNode() == pText1); - assert (it.previousNode() == pElem1); - assert (it.previousNode() == pRoot); - assert (it.previousNode() == 0); - - assert (it.currentNode() == pRoot); - assert (it.parentNode() == 0); - assert (it.currentNode() == pRoot); - assert (it.firstChild() == pElem1); - assert (it.parentNode() == pRoot); - assert (it.lastChild() == pElem2); - assert (it.previousSibling() == pElem1); - assert (it.previousSibling() == 0); - assert (it.currentNode() == pElem1); - assert (it.nextSibling() == pElem2); - assert (it.nextSibling() == 0); - assert (it.currentNode() == pElem2); - assert (it.firstChild() == pText2); - assert (it.nextSibling() == 0); - assert (it.previousSibling() == 0); - assert (it.parentNode() == pElem2); - assert (it.lastChild() == pText2); -} - - -void TreeWalkerTest::testShowElements() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - TreeWalker it(pRoot, NodeFilter::SHOW_ELEMENT); - - assert (it.currentNode() == pRoot); - assert (it.nextNode() == pElem1); - assert (it.nextNode() == pElem2); - assert (it.nextNode() == 0); - - assert (it.currentNode() == pElem2); - assert (it.previousNode() == pElem1); - assert (it.previousNode() == pRoot); - assert (it.previousNode() == 0); - - assert (it.currentNode() == pRoot); - assert (it.parentNode() == 0); - assert (it.currentNode() == pRoot); - assert (it.firstChild() == pElem1); - assert (it.parentNode() == pRoot); - assert (it.lastChild() == pElem2); - assert (it.firstChild() == 0); - assert (it.currentNode() == pElem2); - assert (it.lastChild() == 0); - assert (it.currentNode() == pElem2); - assert (it.previousSibling() == pElem1); - assert (it.firstChild() == 0); - assert (it.lastChild() == 0); - assert (it.parentNode() == pRoot); -} - - -void TreeWalkerTest::testFilter() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - SkipNodeFilter skipFilter; - TreeWalker it1(pRoot, NodeFilter::SHOW_ELEMENT, &skipFilter); - - assert (it1.nextNode() == pElem1); - assert (it1.nextNode() == 0); - - assert (it1.currentNode() == pElem1); - assert (it1.previousNode() == 0); - - assert (it1.parentNode() == 0); - assert (it1.firstChild() == 0); - assert (it1.lastChild() == 0); - assert (it1.nextSibling() == 0); - assert (it1.previousSibling() == 0); - - TreeWalker it2(pRoot, NodeFilter::SHOW_ALL, &skipFilter); - - assert (it2.nextNode() == pElem1); - assert (it2.nextNode() == pText1); - assert (it2.nextNode() == pText2); - assert (it2.nextNode() == 0); - - assert (it2.currentNode() == pText2); - assert (it2.previousNode() == pText1); - assert (it2.previousNode() == pElem1); - assert (it2.previousNode() == 0); - - assert (it2.currentNode() == pElem1); - assert (it2.parentNode() == 0); - assert (it2.nextSibling() == 0); - assert (it2.previousSibling() == 0); - assert (it2.firstChild() == pText1); - assert (it2.nextSibling() == 0); - assert (it2.previousSibling() == 0); - assert (it2.parentNode() == pElem1); - - RejectNodeFilter rejectFilter; - TreeWalker it3(pRoot, NodeFilter::SHOW_ELEMENT, &rejectFilter); - - assert (it3.nextNode() == pElem1); - assert (it3.nextNode() == 0); - - assert (it3.currentNode() == pElem1); - assert (it3.previousNode() == pRoot); - assert (it3.previousNode() == 0); - - assert (it3.currentNode() == pRoot); - assert (it3.parentNode() == 0); - assert (it3.firstChild() == pElem1); - assert (it3.nextSibling() == 0); - assert (it3.previousSibling() == 0); - assert (it3.parentNode() == pRoot); - assert (it3.lastChild() == pElem1); - - TreeWalker it4(pRoot, NodeFilter::SHOW_ALL, &rejectFilter); - - assert (it4.nextNode() == pElem1); - assert (it4.nextNode() == pText1); - assert (it4.nextNode() == 0); - - assert (it4.currentNode() == pText1); - assert (it4.previousNode() == pElem1); - assert (it4.previousNode() == pRoot); - assert (it4.previousNode() == 0); - - assert (it4.currentNode() == pRoot); - assert (it4.parentNode() == 0); - assert (it4.firstChild() == pElem1); - assert (it4.firstChild() == pText1); - assert (it4.nextSibling() == 0); - assert (it4.previousSibling() == 0); - assert (it4.parentNode() == pElem1); - assert (it4.lastChild() == pText1); - assert (it4.parentNode() == pElem1); - assert (it4.nextSibling() == 0); - assert (it4.previousSibling() == 0); - assert (it4.parentNode() == pRoot); -} - - -void TreeWalkerTest::testShowNothing() -{ - AutoPtr pDoc = new Document; - AutoPtr pRoot = pDoc->createElement("root"); - AutoPtr pElem1 = pDoc->createElement("elem"); - AutoPtr pElem2 = pDoc->createElement("elem"); - AutoPtr pText1 = pDoc->createTextNode("text1"); - AutoPtr pText2 = pDoc->createTextNode("text2"); - - pElem1->appendChild(pText1); - pElem2->appendChild(pText2); - pRoot->appendChild(pElem1); - pRoot->appendChild(pElem2); - pDoc->appendChild(pRoot); - - TreeWalker it(pRoot, 0); - - assert (it.nextNode() == 0); - - assert (it.previousNode() == 0); - - assert (it.currentNode() == pRoot); - assert (it.firstChild() == 0); - assert (it.lastChild() == 0); - assert (it.nextSibling() == 0); - assert (it.previousSibling() == 0); -} - - -void TreeWalkerTest::setUp() -{ -} - - -void TreeWalkerTest::tearDown() -{ -} - - -CppUnit::Test* TreeWalkerTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TreeWalkerTest"); - - CppUnit_addTest(pSuite, TreeWalkerTest, testShowAll); - CppUnit_addTest(pSuite, TreeWalkerTest, testShowElements); - CppUnit_addTest(pSuite, TreeWalkerTest, testFilter); - CppUnit_addTest(pSuite, TreeWalkerTest, testShowNothing); - - return pSuite; -} +// +// TreeWalkerTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/TreeWalkerTest.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "TreeWalkerTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/DOM/TreeWalker.h" +#include "Poco/DOM/NodeFilter.h" +#include "Poco/DOM/Document.h" +#include "Poco/DOM/Element.h" +#include "Poco/DOM/Text.h" +#include "Poco/DOM/AutoPtr.h" + + +using Poco::XML::TreeWalker; +using Poco::XML::NodeFilter; +using Poco::XML::Element; +using Poco::XML::Document; +using Poco::XML::Text; +using Poco::XML::Node; +using Poco::XML::AutoPtr; +using Poco::XML::XMLString; + + +namespace +{ + class RejectNodeFilter: public NodeFilter + { + short acceptNode(Node* node) + { + if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1" || node->nodeName() == "root") + return NodeFilter::FILTER_ACCEPT; + else + return NodeFilter::FILTER_REJECT; + } + }; + + class SkipNodeFilter: public NodeFilter + { + short acceptNode(Node* node) + { + if (node->nodeType() != Node::ELEMENT_NODE || node->innerText() == "text1") + return NodeFilter::FILTER_ACCEPT; + else + return NodeFilter::FILTER_SKIP; + } + }; +} + + +TreeWalkerTest::TreeWalkerTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +TreeWalkerTest::~TreeWalkerTest() +{ +} + + +void TreeWalkerTest::testShowAll() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + TreeWalker it(pRoot, NodeFilter::SHOW_ALL); + + assert (it.currentNode() == pRoot); + assert (it.nextNode() == pElem1); + assert (it.nextNode() == pText1); + assert (it.nextNode() == pElem2); + assert (it.nextNode() == pText2); + assert (it.nextNode() == 0); + + assert (it.currentNode() == pText2); + assert (it.previousNode() == pElem2); + assert (it.previousNode() == pText1); + assert (it.previousNode() == pElem1); + assert (it.previousNode() == pRoot); + assert (it.previousNode() == 0); + + assert (it.currentNode() == pRoot); + assert (it.parentNode() == 0); + assert (it.currentNode() == pRoot); + assert (it.firstChild() == pElem1); + assert (it.parentNode() == pRoot); + assert (it.lastChild() == pElem2); + assert (it.previousSibling() == pElem1); + assert (it.previousSibling() == 0); + assert (it.currentNode() == pElem1); + assert (it.nextSibling() == pElem2); + assert (it.nextSibling() == 0); + assert (it.currentNode() == pElem2); + assert (it.firstChild() == pText2); + assert (it.nextSibling() == 0); + assert (it.previousSibling() == 0); + assert (it.parentNode() == pElem2); + assert (it.lastChild() == pText2); +} + + +void TreeWalkerTest::testShowElements() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + TreeWalker it(pRoot, NodeFilter::SHOW_ELEMENT); + + assert (it.currentNode() == pRoot); + assert (it.nextNode() == pElem1); + assert (it.nextNode() == pElem2); + assert (it.nextNode() == 0); + + assert (it.currentNode() == pElem2); + assert (it.previousNode() == pElem1); + assert (it.previousNode() == pRoot); + assert (it.previousNode() == 0); + + assert (it.currentNode() == pRoot); + assert (it.parentNode() == 0); + assert (it.currentNode() == pRoot); + assert (it.firstChild() == pElem1); + assert (it.parentNode() == pRoot); + assert (it.lastChild() == pElem2); + assert (it.firstChild() == 0); + assert (it.currentNode() == pElem2); + assert (it.lastChild() == 0); + assert (it.currentNode() == pElem2); + assert (it.previousSibling() == pElem1); + assert (it.firstChild() == 0); + assert (it.lastChild() == 0); + assert (it.parentNode() == pRoot); +} + + +void TreeWalkerTest::testFilter() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + SkipNodeFilter skipFilter; + TreeWalker it1(pRoot, NodeFilter::SHOW_ELEMENT, &skipFilter); + + assert (it1.nextNode() == pElem1); + assert (it1.nextNode() == 0); + + assert (it1.currentNode() == pElem1); + assert (it1.previousNode() == 0); + + assert (it1.parentNode() == 0); + assert (it1.firstChild() == 0); + assert (it1.lastChild() == 0); + assert (it1.nextSibling() == 0); + assert (it1.previousSibling() == 0); + + TreeWalker it2(pRoot, NodeFilter::SHOW_ALL, &skipFilter); + + assert (it2.nextNode() == pElem1); + assert (it2.nextNode() == pText1); + assert (it2.nextNode() == pText2); + assert (it2.nextNode() == 0); + + assert (it2.currentNode() == pText2); + assert (it2.previousNode() == pText1); + assert (it2.previousNode() == pElem1); + assert (it2.previousNode() == 0); + + assert (it2.currentNode() == pElem1); + assert (it2.parentNode() == 0); + assert (it2.nextSibling() == 0); + assert (it2.previousSibling() == 0); + assert (it2.firstChild() == pText1); + assert (it2.nextSibling() == 0); + assert (it2.previousSibling() == 0); + assert (it2.parentNode() == pElem1); + + RejectNodeFilter rejectFilter; + TreeWalker it3(pRoot, NodeFilter::SHOW_ELEMENT, &rejectFilter); + + assert (it3.nextNode() == pElem1); + assert (it3.nextNode() == 0); + + assert (it3.currentNode() == pElem1); + assert (it3.previousNode() == pRoot); + assert (it3.previousNode() == 0); + + assert (it3.currentNode() == pRoot); + assert (it3.parentNode() == 0); + assert (it3.firstChild() == pElem1); + assert (it3.nextSibling() == 0); + assert (it3.previousSibling() == 0); + assert (it3.parentNode() == pRoot); + assert (it3.lastChild() == pElem1); + + TreeWalker it4(pRoot, NodeFilter::SHOW_ALL, &rejectFilter); + + assert (it4.nextNode() == pElem1); + assert (it4.nextNode() == pText1); + assert (it4.nextNode() == 0); + + assert (it4.currentNode() == pText1); + assert (it4.previousNode() == pElem1); + assert (it4.previousNode() == pRoot); + assert (it4.previousNode() == 0); + + assert (it4.currentNode() == pRoot); + assert (it4.parentNode() == 0); + assert (it4.firstChild() == pElem1); + assert (it4.firstChild() == pText1); + assert (it4.nextSibling() == 0); + assert (it4.previousSibling() == 0); + assert (it4.parentNode() == pElem1); + assert (it4.lastChild() == pText1); + assert (it4.parentNode() == pElem1); + assert (it4.nextSibling() == 0); + assert (it4.previousSibling() == 0); + assert (it4.parentNode() == pRoot); +} + + +void TreeWalkerTest::testShowNothing() +{ + AutoPtr pDoc = new Document; + AutoPtr pRoot = pDoc->createElement("root"); + AutoPtr pElem1 = pDoc->createElement("elem"); + AutoPtr pElem2 = pDoc->createElement("elem"); + AutoPtr pText1 = pDoc->createTextNode("text1"); + AutoPtr pText2 = pDoc->createTextNode("text2"); + + pElem1->appendChild(pText1); + pElem2->appendChild(pText2); + pRoot->appendChild(pElem1); + pRoot->appendChild(pElem2); + pDoc->appendChild(pRoot); + + TreeWalker it(pRoot, 0); + + assert (it.nextNode() == 0); + + assert (it.previousNode() == 0); + + assert (it.currentNode() == pRoot); + assert (it.firstChild() == 0); + assert (it.lastChild() == 0); + assert (it.nextSibling() == 0); + assert (it.previousSibling() == 0); +} + + +void TreeWalkerTest::setUp() +{ +} + + +void TreeWalkerTest::tearDown() +{ +} + + +CppUnit::Test* TreeWalkerTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TreeWalkerTest"); + + CppUnit_addTest(pSuite, TreeWalkerTest, testShowAll); + CppUnit_addTest(pSuite, TreeWalkerTest, testShowElements); + CppUnit_addTest(pSuite, TreeWalkerTest, testFilter); + CppUnit_addTest(pSuite, TreeWalkerTest, testShowNothing); + + return pSuite; +} diff --git a/XML/testsuite/src/TreeWalkerTest.h b/XML/testsuite/src/TreeWalkerTest.h index bbe782b43..13b48015f 100644 --- a/XML/testsuite/src/TreeWalkerTest.h +++ b/XML/testsuite/src/TreeWalkerTest.h @@ -1,63 +1,63 @@ -// -// TreeWalkerTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/TreeWalkerTest.h#1 $ -// -// Definition of the TreeWalkerTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef TreeWalkerTest_INCLUDED -#define TreeWalkerTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class TreeWalkerTest: public CppUnit::TestCase -{ -public: - TreeWalkerTest(const std::string& name); - ~TreeWalkerTest(); - - void testShowAll(); - void testShowElements(); - void testFilter(); - void testShowNothing(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // TreeWalkerTest_INCLUDED +// +// TreeWalkerTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/TreeWalkerTest.h#1 $ +// +// Definition of the TreeWalkerTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef TreeWalkerTest_INCLUDED +#define TreeWalkerTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class TreeWalkerTest: public CppUnit::TestCase +{ +public: + TreeWalkerTest(const std::string& name); + ~TreeWalkerTest(); + + void testShowAll(); + void testShowElements(); + void testFilter(); + void testShowNothing(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // TreeWalkerTest_INCLUDED diff --git a/XML/testsuite/src/WinDriver.cpp b/XML/testsuite/src/WinDriver.cpp index c275a6322..b9a9dd036 100644 --- a/XML/testsuite/src/WinDriver.cpp +++ b/XML/testsuite/src/WinDriver.cpp @@ -1,50 +1,50 @@ -// -// WinDriver.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/WinDriver.cpp#1 $ -// -// Windows test driver for Poco XML. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "WinTestRunner/WinTestRunner.h" -#include "XMLTestSuite.h" - - -class TestDriver: public CppUnit::WinTestRunnerApp -{ - void TestMain() - { - CppUnit::WinTestRunner runner; - runner.addTest(XMLTestSuite::suite()); - runner.run(); - } -}; - - -TestDriver theDriver; +// +// WinDriver.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/WinDriver.cpp#1 $ +// +// Windows test driver for Poco XML. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "WinTestRunner/WinTestRunner.h" +#include "XMLTestSuite.h" + + +class TestDriver: public CppUnit::WinTestRunnerApp +{ + void TestMain() + { + CppUnit::WinTestRunner runner; + runner.addTest(XMLTestSuite::suite()); + runner.run(); + } +}; + + +TestDriver theDriver; diff --git a/XML/testsuite/src/XMLTestSuite.cpp b/XML/testsuite/src/XMLTestSuite.cpp index d8249ff75..859575a41 100644 --- a/XML/testsuite/src/XMLTestSuite.cpp +++ b/XML/testsuite/src/XMLTestSuite.cpp @@ -1,52 +1,52 @@ -// -// XMLTestSuite.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/XMLTestSuite.cpp#1 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "XMLTestSuite.h" -#include "NameTest.h" -#include "NamePoolTest.h" -#include "XMLWriterTest.h" -#include "SAXTestSuite.h" -#include "DOMTestSuite.h" - - -CppUnit::Test* XMLTestSuite::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLTestSuite"); - - pSuite->addTest(NameTest::suite()); - pSuite->addTest(NamePoolTest::suite()); - pSuite->addTest(XMLWriterTest::suite()); - pSuite->addTest(SAXTestSuite::suite()); - pSuite->addTest(DOMTestSuite::suite()); - - return pSuite; -} +// +// XMLTestSuite.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/XMLTestSuite.cpp#1 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "XMLTestSuite.h" +#include "NameTest.h" +#include "NamePoolTest.h" +#include "XMLWriterTest.h" +#include "SAXTestSuite.h" +#include "DOMTestSuite.h" + + +CppUnit::Test* XMLTestSuite::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLTestSuite"); + + pSuite->addTest(NameTest::suite()); + pSuite->addTest(NamePoolTest::suite()); + pSuite->addTest(XMLWriterTest::suite()); + pSuite->addTest(SAXTestSuite::suite()); + pSuite->addTest(DOMTestSuite::suite()); + + return pSuite; +} diff --git a/XML/testsuite/src/XMLTestSuite.h b/XML/testsuite/src/XMLTestSuite.h index 28e995615..b22bf656d 100644 --- a/XML/testsuite/src/XMLTestSuite.h +++ b/XML/testsuite/src/XMLTestSuite.h @@ -1,49 +1,49 @@ -// -// XMLTestSuite.h -// -// $Id: //poco/1.3/XML/testsuite/src/XMLTestSuite.h#1 $ -// -// Definition of the XMLTestSuite class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XMLTestSuite_INCLUDED -#define XMLTestSuite_INCLUDED - - -#include "CppUnit/TestSuite.h" - - -class XMLTestSuite -{ -public: - static CppUnit::Test* suite(); -}; - - -#endif // XMLTestSuite_INCLUDED +// +// XMLTestSuite.h +// +// $Id: //poco/1.3/XML/testsuite/src/XMLTestSuite.h#1 $ +// +// Definition of the XMLTestSuite class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XMLTestSuite_INCLUDED +#define XMLTestSuite_INCLUDED + + +#include "CppUnit/TestSuite.h" + + +class XMLTestSuite +{ +public: + static CppUnit::Test* suite(); +}; + + +#endif // XMLTestSuite_INCLUDED diff --git a/XML/testsuite/src/XMLWriterTest.cpp b/XML/testsuite/src/XMLWriterTest.cpp index 9b3516c9b..e7a2b3bc2 100644 --- a/XML/testsuite/src/XMLWriterTest.cpp +++ b/XML/testsuite/src/XMLWriterTest.cpp @@ -1,603 +1,603 @@ -// -// XMLWriterTest.cpp -// -// $Id: //poco/1.3/XML/testsuite/src/XMLWriterTest.cpp#3 $ -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#include "XMLWriterTest.h" -#include "CppUnit/TestCaller.h" -#include "CppUnit/TestSuite.h" -#include "Poco/XML/XMLWriter.h" -#include "Poco/SAX/AttributesImpl.h" -#include "Poco/Exception.h" -#include - - -using Poco::XML::XMLWriter; -using Poco::XML::AttributesImpl; - - -XMLWriterTest::XMLWriterTest(const std::string& name): CppUnit::TestCase(name) -{ -} - - -XMLWriterTest::~XMLWriterTest() -{ -} - - -void XMLWriterTest::testTrivial() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testTrivialDecl() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION); - writer.startDocument(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testTrivialDeclPretty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n\n"); -} - - -void XMLWriterTest::testTrivialFragment() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startFragment(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endFragment(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testTrivialFragmentPretty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startFragment(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endFragment(); - std::string xml = str.str(); - assert (xml == "\n"); -} - - -void XMLWriterTest::testDTDPretty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startDTD("test", "", "http://www.appinf.com/DTDs/test"); - writer.endDTD(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n" - "\n" - "\n"); -} - - -void XMLWriterTest::testDTD() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startDTD("test", "", "http://www.appinf.com/DTDs/test"); - writer.endDTD(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "" - "" - ""); -} - - -void XMLWriterTest::testDTDNotation() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startDTD("test", "", ""); - std::string systemId("quicktime"); - writer.notationDecl("mov", 0, &systemId); - std::string publicId("-//W3C//NOTATION XML 1.0//EN"); - writer.notationDecl("xml", &publicId, 0); - writer.endDTD(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n" - "\n" - "\t\n" - "]>\n" - "\n"); -} - - -void XMLWriterTest::testDTDEntity() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startDTD("test", "", ""); - std::string systemId("quicktime"); - writer.notationDecl("mov", 0, &systemId); - std::string publicId("-//W3C//NOTATION XML 1.0//EN"); - writer.unparsedEntityDecl("movie", 0, "movie.mov", "mov"); - writer.endDTD(); - writer.startElement("", "", "foo"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n" - "\n" - "\t\n" - "]>\n" - "\n"); -} - - -void XMLWriterTest::testAttributes() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - AttributesImpl attrs; - attrs.addAttribute("", "", "a1", "CDATA", "v1"); - attrs.addAttribute("", "", "a2", "CDATA", "v2"); - writer.startElement("", "", "el", attrs); - writer.endElement("", "", "el"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testData() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "data"); -} - - -void XMLWriterTest::testEmptyData() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testDataPretty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n\tdata\n\n"); -} - - -void XMLWriterTest::testEmptyDataPretty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n\t\n\n"); -} - - -void XMLWriterTest::testComment() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.comment("a comment", 0, 9); - writer.startElement("", "", "r"); - writer.comment("", 0, 17); - writer.dataElement("", "", "d", "data"); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n\n\t\n\tdata\n\n"); -} - - -void XMLWriterTest::testPI() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); - writer.setNewLine("\n"); - writer.startDocument(); - writer.processingInstruction("target", "a processing instruction"); - writer.startElement("", "", "r"); - writer.processingInstruction("target", "another processing instruction"); - writer.dataElement("", "", "d", "data"); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "\n\n\t\n\tdata\n\n"); -} - - -void XMLWriterTest::testCharacters() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.characters("some \"chars\" that be & escaped"); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "some "chars" that <must> be & escaped"); -} - - -void XMLWriterTest::testEmptyCharacters() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.characters(""); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testCDATA() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.startCDATA(); - writer.characters("some \"chars\" that be & escaped"); - writer.endCDATA(); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == " be & escaped]]>"); -} - - -void XMLWriterTest::testRawCharacters() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "r"); - writer.startCDATA(); - writer.rawCharacters("some \"chars\" that be & escaped"); - writer.endCDATA(); - writer.endElement("", "", "r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == " be & escaped]]>"); -} - - -void XMLWriterTest::testDefaultNamespace() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startPrefixMapping("", "urn:ns"); - writer.startElement("", "", "r"); - writer.characters("data"); - writer.endElement("", "", "r"); - writer.endPrefixMapping(""); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "data"); -} - - -void XMLWriterTest::testQNamespaces() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("urn:ns", "r", "p:r"); - writer.characters("data"); - writer.endElement("urn:ns", "r", "p:r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "data"); -} - - -void XMLWriterTest::testQNamespacesNested() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("urn:ns", "r", "p:r"); - writer.startElement("urn:ns", "e", "p:e"); - writer.endElement("urn:ns", "e", "p:e"); - writer.endElement("urn:ns", "r", "p:r"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testNamespaces() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("urn:ns", "r", ""); - writer.characters("data"); - writer.endElement("urn:ns", "r", ""); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "data"); -} - -void XMLWriterTest::testAttributeNamespaces() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - Poco::XML::AttributesImpl attrs; - attrs.addAttribute("urn:other", "myattr", "", "", "attrValue"); - attrs.addAttribute("urn:ns", "myattr2", "", "", "attrValue2"); - writer.startDocument(); - writer.startElement("urn:ns", "r", "", attrs); - writer.characters("data"); - writer.endElement("urn:ns", "r", ""); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == "data"); -} - - -void XMLWriterTest::testNamespacesNested() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("urn:ns1", "r", ""); - writer.startElement("urn:ns1", "e", ""); - writer.endElement("urn:ns1", "e", ""); - writer.startElement("urn:ns2", "f", ""); - writer.endElement("urn:ns2", "f", ""); - writer.endElement("urn:ns1", "r", ""); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testExplicitNamespaces() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startPrefixMapping("p1", "urn:ns1"); - writer.startPrefixMapping("p2", "urn:ns2"); - writer.startElement("urn:ns1", "r", ""); - writer.startElement("urn:ns2", "e", ""); - writer.endElement("urn:ns2", "e", ""); - writer.startPrefixMapping("p3", "urn:ns3"); - writer.startElement("urn:ns2", "e", ""); - writer.startElement("urn:ns3", "f", ""); - writer.endElement("urn:ns3", "f", ""); - writer.endElement("urn:ns2", "e", ""); - writer.endElement("urn:ns1", "r", ""); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::testWellformed() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "foo"); - try - { - writer.endElement("", "", "bar"); - fail("not wellformed - must throw exception"); - } - catch (Poco::Exception&) - { - } -} - - -void XMLWriterTest::testWellformedNested() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "foo"); - writer.startElement("", "", "bar"); - try - { - writer.endElement("", "", "foo"); - fail("not wellformed - must throw exception"); - } - catch (Poco::Exception&) - { - } -} - - -void XMLWriterTest::testWellformedNamespace() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("urn:ns1", "foo", ""); - writer.startElement("urn:ns2", "bar", ""); - try - { - writer.endElement("urn:ns1", "bar", ""); - fail("not wellformed - must throw exception"); - } - catch (Poco::Exception&) - { - } -} - - -void XMLWriterTest::testEmpty() -{ - std::ostringstream str; - XMLWriter writer(str, XMLWriter::CANONICAL); - writer.startDocument(); - writer.startElement("", "", "foo"); - writer.startElement("", "", "bar"); - writer.emptyElement("", "", "empty"); - writer.endElement("", "", "bar"); - writer.endElement("", "", "foo"); - writer.endDocument(); - std::string xml = str.str(); - assert (xml == ""); -} - - -void XMLWriterTest::setUp() -{ -} - - -void XMLWriterTest::tearDown() -{ -} - - -CppUnit::Test* XMLWriterTest::suite() -{ - CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest"); - - CppUnit_addTest(pSuite, XMLWriterTest, testTrivial); - CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl); - CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty); - CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment); - CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty); - CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty); - CppUnit_addTest(pSuite, XMLWriterTest, testDTD); - CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation); - CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity); - CppUnit_addTest(pSuite, XMLWriterTest, testAttributes); - CppUnit_addTest(pSuite, XMLWriterTest, testData); - CppUnit_addTest(pSuite, XMLWriterTest, testEmptyData); - CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty); - CppUnit_addTest(pSuite, XMLWriterTest, testEmptyDataPretty); - CppUnit_addTest(pSuite, XMLWriterTest, testComment); - CppUnit_addTest(pSuite, XMLWriterTest, testPI); - CppUnit_addTest(pSuite, XMLWriterTest, testCharacters); - CppUnit_addTest(pSuite, XMLWriterTest, testEmptyCharacters); - CppUnit_addTest(pSuite, XMLWriterTest, testCDATA); - CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters); - CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace); - CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces); - CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested); - CppUnit_addTest(pSuite, XMLWriterTest, testNamespaces); - CppUnit_addTest(pSuite, XMLWriterTest, testAttributeNamespaces); - CppUnit_addTest(pSuite, XMLWriterTest, testNamespacesNested); - CppUnit_addTest(pSuite, XMLWriterTest, testExplicitNamespaces); - CppUnit_addTest(pSuite, XMLWriterTest, testWellformed); - CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNested); - CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNamespace); - CppUnit_addTest(pSuite, XMLWriterTest, testEmpty); - - return pSuite; -} +// +// XMLWriterTest.cpp +// +// $Id: //poco/1.3/XML/testsuite/src/XMLWriterTest.cpp#3 $ +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#include "XMLWriterTest.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" +#include "Poco/XML/XMLWriter.h" +#include "Poco/SAX/AttributesImpl.h" +#include "Poco/Exception.h" +#include + + +using Poco::XML::XMLWriter; +using Poco::XML::AttributesImpl; + + +XMLWriterTest::XMLWriterTest(const std::string& name): CppUnit::TestCase(name) +{ +} + + +XMLWriterTest::~XMLWriterTest() +{ +} + + +void XMLWriterTest::testTrivial() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testTrivialDecl() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION); + writer.startDocument(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testTrivialDeclPretty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n\n"); +} + + +void XMLWriterTest::testTrivialFragment() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startFragment(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endFragment(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testTrivialFragmentPretty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startFragment(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endFragment(); + std::string xml = str.str(); + assert (xml == "\n"); +} + + +void XMLWriterTest::testDTDPretty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startDTD("test", "", "http://www.appinf.com/DTDs/test"); + writer.endDTD(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n" + "\n" + "\n"); +} + + +void XMLWriterTest::testDTD() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startDTD("test", "", "http://www.appinf.com/DTDs/test"); + writer.endDTD(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "" + "" + ""); +} + + +void XMLWriterTest::testDTDNotation() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startDTD("test", "", ""); + std::string systemId("quicktime"); + writer.notationDecl("mov", 0, &systemId); + std::string publicId("-//W3C//NOTATION XML 1.0//EN"); + writer.notationDecl("xml", &publicId, 0); + writer.endDTD(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n" + "\n" + "\t\n" + "]>\n" + "\n"); +} + + +void XMLWriterTest::testDTDEntity() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::WRITE_XML_DECLARATION | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startDTD("test", "", ""); + std::string systemId("quicktime"); + writer.notationDecl("mov", 0, &systemId); + std::string publicId("-//W3C//NOTATION XML 1.0//EN"); + writer.unparsedEntityDecl("movie", 0, "movie.mov", "mov"); + writer.endDTD(); + writer.startElement("", "", "foo"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n" + "\n" + "\t\n" + "]>\n" + "\n"); +} + + +void XMLWriterTest::testAttributes() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + AttributesImpl attrs; + attrs.addAttribute("", "", "a1", "CDATA", "v1"); + attrs.addAttribute("", "", "a2", "CDATA", "v2"); + writer.startElement("", "", "el", attrs); + writer.endElement("", "", "el"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testData() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "data"); +} + + +void XMLWriterTest::testEmptyData() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testDataPretty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.dataElement("", "", "d", "data", "a1", "v1", "a2", "v2", "a3", "v3"); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n\tdata\n\n"); +} + + +void XMLWriterTest::testEmptyDataPretty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.dataElement("", "", "d", "", "a1", "v1", "a2", "v2", "a3", "v3"); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n\t\n\n"); +} + + +void XMLWriterTest::testComment() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.comment("a comment", 0, 9); + writer.startElement("", "", "r"); + writer.comment("", 0, 17); + writer.dataElement("", "", "d", "data"); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n\n\t\n\tdata\n\n"); +} + + +void XMLWriterTest::testPI() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT); + writer.setNewLine("\n"); + writer.startDocument(); + writer.processingInstruction("target", "a processing instruction"); + writer.startElement("", "", "r"); + writer.processingInstruction("target", "another processing instruction"); + writer.dataElement("", "", "d", "data"); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "\n\n\t\n\tdata\n\n"); +} + + +void XMLWriterTest::testCharacters() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.characters("some \"chars\" that be & escaped"); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "some "chars" that <must> be & escaped"); +} + + +void XMLWriterTest::testEmptyCharacters() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.characters(""); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testCDATA() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.startCDATA(); + writer.characters("some \"chars\" that be & escaped"); + writer.endCDATA(); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == " be & escaped]]>"); +} + + +void XMLWriterTest::testRawCharacters() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "r"); + writer.startCDATA(); + writer.rawCharacters("some \"chars\" that be & escaped"); + writer.endCDATA(); + writer.endElement("", "", "r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == " be & escaped]]>"); +} + + +void XMLWriterTest::testDefaultNamespace() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startPrefixMapping("", "urn:ns"); + writer.startElement("", "", "r"); + writer.characters("data"); + writer.endElement("", "", "r"); + writer.endPrefixMapping(""); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "data"); +} + + +void XMLWriterTest::testQNamespaces() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("urn:ns", "r", "p:r"); + writer.characters("data"); + writer.endElement("urn:ns", "r", "p:r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "data"); +} + + +void XMLWriterTest::testQNamespacesNested() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("urn:ns", "r", "p:r"); + writer.startElement("urn:ns", "e", "p:e"); + writer.endElement("urn:ns", "e", "p:e"); + writer.endElement("urn:ns", "r", "p:r"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testNamespaces() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("urn:ns", "r", ""); + writer.characters("data"); + writer.endElement("urn:ns", "r", ""); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "data"); +} + +void XMLWriterTest::testAttributeNamespaces() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + Poco::XML::AttributesImpl attrs; + attrs.addAttribute("urn:other", "myattr", "", "", "attrValue"); + attrs.addAttribute("urn:ns", "myattr2", "", "", "attrValue2"); + writer.startDocument(); + writer.startElement("urn:ns", "r", "", attrs); + writer.characters("data"); + writer.endElement("urn:ns", "r", ""); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == "data"); +} + + +void XMLWriterTest::testNamespacesNested() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("urn:ns1", "r", ""); + writer.startElement("urn:ns1", "e", ""); + writer.endElement("urn:ns1", "e", ""); + writer.startElement("urn:ns2", "f", ""); + writer.endElement("urn:ns2", "f", ""); + writer.endElement("urn:ns1", "r", ""); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testExplicitNamespaces() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startPrefixMapping("p1", "urn:ns1"); + writer.startPrefixMapping("p2", "urn:ns2"); + writer.startElement("urn:ns1", "r", ""); + writer.startElement("urn:ns2", "e", ""); + writer.endElement("urn:ns2", "e", ""); + writer.startPrefixMapping("p3", "urn:ns3"); + writer.startElement("urn:ns2", "e", ""); + writer.startElement("urn:ns3", "f", ""); + writer.endElement("urn:ns3", "f", ""); + writer.endElement("urn:ns2", "e", ""); + writer.endElement("urn:ns1", "r", ""); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::testWellformed() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "foo"); + try + { + writer.endElement("", "", "bar"); + fail("not wellformed - must throw exception"); + } + catch (Poco::Exception&) + { + } +} + + +void XMLWriterTest::testWellformedNested() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "foo"); + writer.startElement("", "", "bar"); + try + { + writer.endElement("", "", "foo"); + fail("not wellformed - must throw exception"); + } + catch (Poco::Exception&) + { + } +} + + +void XMLWriterTest::testWellformedNamespace() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("urn:ns1", "foo", ""); + writer.startElement("urn:ns2", "bar", ""); + try + { + writer.endElement("urn:ns1", "bar", ""); + fail("not wellformed - must throw exception"); + } + catch (Poco::Exception&) + { + } +} + + +void XMLWriterTest::testEmpty() +{ + std::ostringstream str; + XMLWriter writer(str, XMLWriter::CANONICAL); + writer.startDocument(); + writer.startElement("", "", "foo"); + writer.startElement("", "", "bar"); + writer.emptyElement("", "", "empty"); + writer.endElement("", "", "bar"); + writer.endElement("", "", "foo"); + writer.endDocument(); + std::string xml = str.str(); + assert (xml == ""); +} + + +void XMLWriterTest::setUp() +{ +} + + +void XMLWriterTest::tearDown() +{ +} + + +CppUnit::Test* XMLWriterTest::suite() +{ + CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("XMLWriterTest"); + + CppUnit_addTest(pSuite, XMLWriterTest, testTrivial); + CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDecl); + CppUnit_addTest(pSuite, XMLWriterTest, testTrivialDeclPretty); + CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragment); + CppUnit_addTest(pSuite, XMLWriterTest, testTrivialFragmentPretty); + CppUnit_addTest(pSuite, XMLWriterTest, testDTDPretty); + CppUnit_addTest(pSuite, XMLWriterTest, testDTD); + CppUnit_addTest(pSuite, XMLWriterTest, testDTDNotation); + CppUnit_addTest(pSuite, XMLWriterTest, testDTDEntity); + CppUnit_addTest(pSuite, XMLWriterTest, testAttributes); + CppUnit_addTest(pSuite, XMLWriterTest, testData); + CppUnit_addTest(pSuite, XMLWriterTest, testEmptyData); + CppUnit_addTest(pSuite, XMLWriterTest, testDataPretty); + CppUnit_addTest(pSuite, XMLWriterTest, testEmptyDataPretty); + CppUnit_addTest(pSuite, XMLWriterTest, testComment); + CppUnit_addTest(pSuite, XMLWriterTest, testPI); + CppUnit_addTest(pSuite, XMLWriterTest, testCharacters); + CppUnit_addTest(pSuite, XMLWriterTest, testEmptyCharacters); + CppUnit_addTest(pSuite, XMLWriterTest, testCDATA); + CppUnit_addTest(pSuite, XMLWriterTest, testRawCharacters); + CppUnit_addTest(pSuite, XMLWriterTest, testDefaultNamespace); + CppUnit_addTest(pSuite, XMLWriterTest, testQNamespaces); + CppUnit_addTest(pSuite, XMLWriterTest, testQNamespacesNested); + CppUnit_addTest(pSuite, XMLWriterTest, testNamespaces); + CppUnit_addTest(pSuite, XMLWriterTest, testAttributeNamespaces); + CppUnit_addTest(pSuite, XMLWriterTest, testNamespacesNested); + CppUnit_addTest(pSuite, XMLWriterTest, testExplicitNamespaces); + CppUnit_addTest(pSuite, XMLWriterTest, testWellformed); + CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNested); + CppUnit_addTest(pSuite, XMLWriterTest, testWellformedNamespace); + CppUnit_addTest(pSuite, XMLWriterTest, testEmpty); + + return pSuite; +} diff --git a/XML/testsuite/src/XMLWriterTest.h b/XML/testsuite/src/XMLWriterTest.h index 41b01ff00..84f242092 100644 --- a/XML/testsuite/src/XMLWriterTest.h +++ b/XML/testsuite/src/XMLWriterTest.h @@ -1,90 +1,90 @@ -// -// XMLWriterTest.h -// -// $Id: //poco/1.3/XML/testsuite/src/XMLWriterTest.h#3 $ -// -// Definition of the XMLWriterTest class. -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Permission is hereby granted, free of charge, to any person or organization -// obtaining a copy of the software and accompanying documentation covered by -// this license (the "Software") to use, reproduce, display, distribute, -// execute, and transmit the Software, and to prepare derivative works of the -// Software, and to permit third-parties to whom the Software is furnished to -// do so, all subject to the following: -// -// The copyright notices in the Software and this entire statement, including -// the above license grant, this restriction and the following disclaimer, -// must be included in all copies of the Software, in whole or in part, and -// all derivative works of the Software, unless such copies or derivative -// works are solely in the form of machine-executable object code generated by -// a source language processor. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// - - -#ifndef XMLWriterTest_INCLUDED -#define XMLWriterTest_INCLUDED - - -#include "Poco/XML/XML.h" -#include "CppUnit/TestCase.h" - - -class XMLWriterTest: public CppUnit::TestCase -{ -public: - XMLWriterTest(const std::string& name); - ~XMLWriterTest(); - - void testTrivial(); - void testTrivialDecl(); - void testTrivialDeclPretty(); - void testTrivialFragment(); - void testTrivialFragmentPretty(); - void testDTDPretty(); - void testDTD(); - void testDTDNotation(); - void testDTDEntity(); - void testAttributes(); - void testData(); - void testEmptyData(); - void testDataPretty(); - void testEmptyDataPretty(); - void testComment(); - void testPI(); - void testCharacters(); - void testEmptyCharacters(); - void testCDATA(); - void testRawCharacters(); - void testDefaultNamespace(); - void testQNamespaces(); - void testQNamespacesNested(); - void testNamespaces(); - void testNamespacesNested(); - void testExplicitNamespaces(); - void testWellformed(); - void testWellformedNested(); - void testWellformedNamespace(); - void testAttributeNamespaces(); - void testEmpty(); - - void setUp(); - void tearDown(); - - static CppUnit::Test* suite(); - -private: -}; - - -#endif // XMLWriterTest_INCLUDED +// +// XMLWriterTest.h +// +// $Id: //poco/1.3/XML/testsuite/src/XMLWriterTest.h#3 $ +// +// Definition of the XMLWriterTest class. +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Permission is hereby granted, free of charge, to any person or organization +// obtaining a copy of the software and accompanying documentation covered by +// this license (the "Software") to use, reproduce, display, distribute, +// execute, and transmit the Software, and to prepare derivative works of the +// Software, and to permit third-parties to whom the Software is furnished to +// do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including +// the above license grant, this restriction and the following disclaimer, +// must be included in all copies of the Software, in whole or in part, and +// all derivative works of the Software, unless such copies or derivative +// works are solely in the form of machine-executable object code generated by +// a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + + +#ifndef XMLWriterTest_INCLUDED +#define XMLWriterTest_INCLUDED + + +#include "Poco/XML/XML.h" +#include "CppUnit/TestCase.h" + + +class XMLWriterTest: public CppUnit::TestCase +{ +public: + XMLWriterTest(const std::string& name); + ~XMLWriterTest(); + + void testTrivial(); + void testTrivialDecl(); + void testTrivialDeclPretty(); + void testTrivialFragment(); + void testTrivialFragmentPretty(); + void testDTDPretty(); + void testDTD(); + void testDTDNotation(); + void testDTDEntity(); + void testAttributes(); + void testData(); + void testEmptyData(); + void testDataPretty(); + void testEmptyDataPretty(); + void testComment(); + void testPI(); + void testCharacters(); + void testEmptyCharacters(); + void testCDATA(); + void testRawCharacters(); + void testDefaultNamespace(); + void testQNamespaces(); + void testQNamespacesNested(); + void testNamespaces(); + void testNamespacesNested(); + void testExplicitNamespaces(); + void testWellformed(); + void testWellformedNested(); + void testWellformedNamespace(); + void testAttributeNamespaces(); + void testEmpty(); + + void setUp(); + void tearDown(); + + static CppUnit::Test* suite(); + +private: +}; + + +#endif // XMLWriterTest_INCLUDED