From 4197ed9e822a5dd2207c493ba90e1abb74cb590e Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 2 Nov 2005 20:12:13 +0000 Subject: [PATCH] Removing old files which have been copies in CVS to content/xslt, see bug 304494 --- content/xsl/.cvsignore | 1 - content/xsl/Makefile.in | 49 - content/xsl/public/.cvsignore | 1 - content/xsl/public/Makefile.in | 59 - content/xsl/public/nsIDocumentTransformer.h | 83 - content/xsl/public/nsIXSLTException.idl | 53 - content/xsl/public/nsIXSLTProcessor.idl | 134 - .../xsl/public/nsIXSLTProcessorObsolete.idl | 57 - content/xsl/tests/book.css | 2 - content/xsl/tests/book.xml | 5 - content/xsl/tests/book.xsl | 18 - extensions/transformiix/.cvsignore | 1 - extensions/transformiix/Makefile.in | 51 - extensions/transformiix/build/.cvsignore | 1 - extensions/transformiix/build/Makefile.in | 94 - .../build/XSLTProcessorModule.cpp | 324 -- .../transformiix/build/transformiix.jst | 30 - .../transformiix/build/transformiix.pkg | 12 - extensions/transformiix/docs/changes.txt | 260 -- .../docs/compiled-stylesheets.html | 254 -- .../transformiix/docs/compiled-templates.html | 273 -- .../transformiix/docs/contributors.html | 376 --- .../docs/optimized-stylesheets.html | 199 -- .../transformiix/docs/optimized-xpath.html | 523 --- extensions/transformiix/docs/readme.html | 172 - extensions/transformiix/resources/Makefile.in | 45 - .../resources/XSLTMark/XSLTMark-static.js | 77 - .../resources/XSLTMark/XSLTMark-test.js | 79 - .../resources/XSLTMark/XSLTMark-view.js | 208 -- .../resources/XSLTMark/XSLTMark.css | 41 - .../resources/XSLTMark/XSLTMark.xul | 85 - .../transformiix/resources/buster/DiffDOM.js | 136 - .../transformiix/resources/buster/DumpDOM.js | 85 - .../transformiix/resources/buster/Makefile.in | 45 - .../transformiix/resources/buster/ReadMe | 22 - .../resources/buster/buster-files.js | 115 - .../resources/buster/buster-handlers.js | 71 - .../resources/buster/buster-statics.js | 121 - .../resources/buster/buster-test.js | 390 --- .../resources/buster/buster-view.js | 227 -- .../transformiix/resources/buster/buster.css | 53 - .../transformiix/resources/buster/buster.xul | 227 -- .../resources/buster/contents.rdf | 28 - .../resources/buster/helper/generate-rdf.pl | 95 - .../transformiix/resources/buster/install.js | 17 - .../transformiix/resources/buster/jar.mn | 17 - .../resources/buster/result-inspector.xul | 70 - .../resources/buster/result-view.css | 16 - .../resources/buster/result-view.js | 139 - .../resources/buster/result-view.xul | 79 - .../resources/buster/xslt-qa-overlay.js | 44 - .../resources/buster/xslt-qa-overlay.xul | 45 - extensions/transformiix/source/.cvsignore | 1 - extensions/transformiix/source/Makefile.in | 51 - .../transformiix/source/base/.cvsignore | 1 - .../transformiix/source/base/Double.cpp | 353 -- .../transformiix/source/base/ErrorObserver.h | 114 - extensions/transformiix/source/base/List.cpp | 426 --- extensions/transformiix/source/base/List.h | 224 -- .../transformiix/source/base/Makefile.in | 86 - .../source/base/SimpleErrorObserver.cpp | 80 - extensions/transformiix/source/base/TxLog.h | 67 - .../transformiix/source/base/txAtoms.cpp | 102 - extensions/transformiix/source/base/txAtoms.h | 105 - extensions/transformiix/source/base/txCore.h | 110 - extensions/transformiix/source/base/txError.h | 138 - .../source/base/txExpandedNameMap.cpp | 203 -- .../source/base/txExpandedNameMap.h | 137 - .../source/base/txNamespaceMap.cpp | 127 - .../transformiix/source/base/txNamespaceMap.h | 76 - extensions/transformiix/source/base/txStack.h | 152 - .../source/base/txStringUtils.cpp | 153 - .../transformiix/source/base/txStringUtils.h | 82 - .../transformiix/source/base/txTokenizer.h | 90 - .../transformiix/source/base/txURIUtils.cpp | 352 -- .../transformiix/source/base/txURIUtils.h | 115 - .../source/examples/functions.html | 1352 -------- .../source/examples/functions.xml | 12 - .../source/examples/functions.xsl | 1212 ------- .../source/examples/identity-result.xml | 8 - .../transformiix/source/examples/identity.xml | 9 - .../transformiix/source/examples/identity.xsl | 59 - .../source/examples/include-helper.xsl | 53 - .../transformiix/source/examples/include.html | 12 - .../transformiix/source/examples/include.xml | 6 - .../transformiix/source/examples/include.xsl | 64 - .../transformiix/source/examples/sort.html | 55 - .../transformiix/source/examples/sort.xml | 14 - .../transformiix/source/examples/sort.xsl | 60 - .../transformiix/source/examples/test.html | 746 ----- .../transformiix/source/examples/test.xml | 13 - .../transformiix/source/examples/test.xsl | 859 ----- .../source/examples/view-source.xsl | 105 - .../transformiix/source/lib/Makefile.in | 74 - .../transformiix/source/main/.cvsignore | 1 - .../transformiix/source/main/Makefile.in | 79 - .../transformiix/source/main/testXalan.cpp | 424 --- .../transformiix/source/main/transformiix.cpp | 209 -- .../transformiix/source/main/txTestExpr.cpp | 145 - .../source/main/txXSLTMarkDriver.cpp | 131 - extensions/transformiix/source/xml/.cvsignore | 1 - .../transformiix/source/xml/Makefile.in | 75 - .../transformiix/source/xml/XMLUtils.cpp | 251 -- extensions/transformiix/source/xml/XMLUtils.h | 213 -- .../transformiix/source/xml/dom/.cvsignore | 1 - .../transformiix/source/xml/dom/Makefile.in | 49 - extensions/transformiix/source/xml/dom/dom.h | 45 - .../source/xml/dom/standalone/.cvsignore | 1 - .../source/xml/dom/standalone/Attr.cpp | 117 - .../source/xml/dom/standalone/Document.cpp | 177 - .../source/xml/dom/standalone/Element.cpp | 208 -- .../source/xml/dom/standalone/Makefile.in | 66 - .../xml/dom/standalone/NodeDefinition.cpp | 378 --- .../dom/standalone/ProcessingInstruction.cpp | 80 - .../source/xml/dom/standalone/dom.h | 473 --- .../transformiix/source/xml/parser/.cvsignore | 1 - .../source/xml/parser/Makefile.in | 80 - .../source/xml/parser/txXMLParser.cpp | 460 --- .../source/xml/parser/txXMLParser.h | 72 - .../transformiix/source/xpath/.cvsignore | 1 - .../source/xpath/AdditiveExpr.cpp | 106 - .../source/xpath/AttributeValueTemplate.cpp | 115 - .../transformiix/source/xpath/BooleanExpr.cpp | 107 - .../source/xpath/BooleanFunctionCall.cpp | 185 - .../source/xpath/BooleanResult.cpp | 83 - extensions/transformiix/source/xpath/Expr.h | 743 ---- .../transformiix/source/xpath/ExprLexer.cpp | 398 --- .../transformiix/source/xpath/ExprLexer.h | 257 -- .../transformiix/source/xpath/ExprParser.cpp | 1094 ------ .../transformiix/source/xpath/ExprParser.h | 137 - .../transformiix/source/xpath/ExprResult.h | 156 - .../transformiix/source/xpath/FilterExpr.cpp | 98 - .../source/xpath/FunctionCall.cpp | 200 -- .../transformiix/source/xpath/FunctionLib.h | 180 - .../source/xpath/LocationStep.cpp | 328 -- .../transformiix/source/xpath/Makefile.in | 127 - .../source/xpath/MultiplicativeExpr.cpp | 139 - .../source/xpath/NodeSetFunctionCall.cpp | 279 -- .../source/xpath/NumberFunctionCall.cpp | 195 -- .../source/xpath/NumberResult.cpp | 88 - .../transformiix/source/xpath/PathExpr.cpp | 244 -- .../source/xpath/PredicateList.cpp | 138 - .../source/xpath/RelationalExpr.cpp | 237 -- .../transformiix/source/xpath/RootExpr.cpp | 77 - .../source/xpath/StringFunctionCall.cpp | 417 --- .../source/xpath/StringResult.cpp | 87 - .../transformiix/source/xpath/UnaryExpr.cpp | 81 - .../transformiix/source/xpath/UnionExpr.cpp | 143 - .../source/xpath/VariableRefExpr.cpp | 101 - .../source/xpath/XFormsFunctionCall.cpp | 604 ---- .../source/xpath/XFormsFunctions.h | 84 - .../source/xpath/nsIXFormsUtilityService.h | 164 - .../source/xpath/nsIXFormsXPathEvaluator.h | 99 - .../source/xpath/nsXFormsXPathEvaluator.cpp | 274 -- .../source/xpath/nsXFormsXPathEvaluator.h | 101 - .../source/xpath/nsXPath1Scheme.cpp | 238 -- .../source/xpath/nsXPath1Scheme.h | 59 - .../source/xpath/nsXPathEvaluator.cpp | 213 -- .../source/xpath/nsXPathEvaluator.h | 114 - .../source/xpath/nsXPathException.cpp | 111 - .../source/xpath/nsXPathException.h | 68 - .../source/xpath/nsXPathExpression.cpp | 225 -- .../source/xpath/nsXPathExpression.h | 109 - .../source/xpath/nsXPathNSResolver.cpp | 78 - .../source/xpath/nsXPathNSResolver.h | 66 - .../source/xpath/nsXPathNamespace.cpp | 210 -- .../source/xpath/nsXPathNamespace.h | 70 - .../source/xpath/nsXPathResult.cpp | 373 --- .../transformiix/source/xpath/nsXPathResult.h | 138 - .../transformiix/source/xpath/txErrorExpr.cpp | 66 - .../source/xpath/txForwardContext.cpp | 94 - .../source/xpath/txForwardContext.h | 67 - .../source/xpath/txIXPathContext.h | 169 - .../source/xpath/txLiteralExpr.cpp | 89 - .../source/xpath/txMozillaXPathTreeWalker.cpp | 968 ------ .../transformiix/source/xpath/txNameTest.cpp | 117 - .../transformiix/source/xpath/txNodeSet.cpp | 626 ---- .../transformiix/source/xpath/txNodeSet.h | 241 -- .../source/xpath/txNodeSetContext.cpp | 93 - .../source/xpath/txNodeSetContext.h | 82 - .../source/xpath/txNodeTypeTest.cpp | 124 - .../source/xpath/txResultRecycler.cpp | 301 -- .../source/xpath/txResultRecycler.h | 111 - .../source/xpath/txSingleNodeContext.h | 114 - .../xpath/txStandaloneXPathTreeWalker.cpp | 417 --- .../source/xpath/txXPathAtomList.h | 110 - .../transformiix/source/xpath/txXPathNode.h | 155 - .../source/xpath/txXPathTreeWalker.h | 348 -- .../transformiix/source/xslt/.cvsignore | 1 - .../transformiix/source/xslt/Makefile.in | 122 - .../source/xslt/functions/.cvsignore | 1 - .../xslt/functions/CurrentFunctionCall.cpp | 49 - .../xslt/functions/DocumentFunctionCall.cpp | 188 -- .../xslt/functions/ElementAvailableFnCall.cpp | 141 - .../functions/FunctionAvailableFnCall.cpp | 140 - .../xslt/functions/GenerateIdFunctionCall.cpp | 116 - .../source/xslt/functions/Makefile.in | 81 - .../functions/SystemPropertyFunctionCall.cpp | 120 - .../source/xslt/functions/XSLTFunctions.h | 258 -- .../functions/txFormatNumberFunctionCall.cpp | 449 --- .../source/xslt/functions/txKey.h | 227 -- .../xslt/functions/txKeyFunctionCall.cpp | 459 --- .../source/xslt/txBufferingHandler.cpp | 416 --- .../source/xslt/txBufferingHandler.h | 79 - .../source/xslt/txExecutionState.cpp | 597 ---- .../source/xslt/txExecutionState.h | 187 -- .../transformiix/source/xslt/txHTMLAtomList.h | 97 - .../transformiix/source/xslt/txHTMLOutput.cpp | 369 -- .../transformiix/source/xslt/txHTMLOutput.h | 74 - .../source/xslt/txInstructions.cpp | 1052 ------ .../transformiix/source/xslt/txInstructions.h | 424 --- .../xslt/txMozillaStylesheetCompiler.cpp | 829 ----- .../source/xslt/txMozillaTextOutput.cpp | 336 -- .../source/xslt/txMozillaTextOutput.h | 74 - .../source/xslt/txMozillaXMLOutput.cpp | 981 ------ .../source/xslt/txMozillaXMLOutput.h | 154 - .../source/xslt/txMozillaXSLTProcessor.cpp | 1276 ------- .../source/xslt/txMozillaXSLTProcessor.h | 185 - .../source/xslt/txOutputFormat.cpp | 164 - .../transformiix/source/xslt/txOutputFormat.h | 106 - .../source/xslt/txPatternParser.cpp | 358 -- .../source/xslt/txPatternParser.h | 67 - .../transformiix/source/xslt/txRtfHandler.cpp | 119 - .../transformiix/source/xslt/txRtfHandler.h | 72 - .../xslt/txStandaloneStylesheetCompiler.cpp | 381 --- .../xslt/txStandaloneStylesheetCompiler.h | 56 - .../source/xslt/txStandaloneXSLTProcessor.cpp | 378 --- .../source/xslt/txStandaloneXSLTProcessor.h | 165 - .../transformiix/source/xslt/txStylesheet.cpp | 668 ---- .../transformiix/source/xslt/txStylesheet.h | 248 -- .../xslt/txStylesheetCompileHandlers.cpp | 2983 ----------------- .../source/xslt/txStylesheetCompileHandlers.h | 89 - .../source/xslt/txStylesheetCompiler.cpp | 999 ------ .../source/xslt/txStylesheetCompiler.h | 259 -- .../source/xslt/txTextHandler.cpp | 92 - .../transformiix/source/xslt/txTextHandler.h | 60 - .../transformiix/source/xslt/txTextOutput.cpp | 87 - .../transformiix/source/xslt/txTextOutput.h | 57 - .../source/xslt/txToplevelItems.cpp | 85 - .../source/xslt/txToplevelItems.h | 163 - .../source/xslt/txUnknownHandler.cpp | 138 - .../source/xslt/txUnknownHandler.h | 71 - .../transformiix/source/xslt/txVariableMap.h | 106 - .../source/xslt/txXMLEventHandler.h | 202 -- .../transformiix/source/xslt/txXMLOutput.cpp | 346 -- .../transformiix/source/xslt/txXMLOutput.h | 126 - .../transformiix/source/xslt/txXSLTAtomList.h | 151 - .../transformiix/source/xslt/txXSLTNumber.cpp | 759 ----- .../transformiix/source/xslt/txXSLTNumber.h | 106 - .../source/xslt/txXSLTNumberCounters.cpp | 246 -- .../source/xslt/txXSLTPatterns.cpp | 606 ---- .../transformiix/source/xslt/txXSLTPatterns.h | 233 -- .../source/xslt/txXSLTProcessor.cpp | 103 - .../source/xslt/txXSLTProcessor.h | 61 - .../transformiix/source/xslt/util/.cvsignore | 1 - .../transformiix/source/xslt/util/Makefile.in | 75 - .../source/xslt/util/txNodeSorter.cpp | 306 -- .../source/xslt/util/txNodeSorter.h | 92 - .../xslt/util/txXPathResultComparator.cpp | 290 -- .../xslt/util/txXPathResultComparator.h | 135 - 260 files changed, 52926 deletions(-) delete mode 100644 content/xsl/.cvsignore delete mode 100755 content/xsl/Makefile.in delete mode 100644 content/xsl/public/.cvsignore delete mode 100644 content/xsl/public/Makefile.in delete mode 100644 content/xsl/public/nsIDocumentTransformer.h delete mode 100644 content/xsl/public/nsIXSLTException.idl delete mode 100644 content/xsl/public/nsIXSLTProcessor.idl delete mode 100644 content/xsl/public/nsIXSLTProcessorObsolete.idl delete mode 100644 content/xsl/tests/book.css delete mode 100644 content/xsl/tests/book.xml delete mode 100644 content/xsl/tests/book.xsl delete mode 100644 extensions/transformiix/.cvsignore delete mode 100644 extensions/transformiix/Makefile.in delete mode 100644 extensions/transformiix/build/.cvsignore delete mode 100644 extensions/transformiix/build/Makefile.in delete mode 100755 extensions/transformiix/build/XSLTProcessorModule.cpp delete mode 100644 extensions/transformiix/build/transformiix.jst delete mode 100644 extensions/transformiix/build/transformiix.pkg delete mode 100755 extensions/transformiix/docs/changes.txt delete mode 100644 extensions/transformiix/docs/compiled-stylesheets.html delete mode 100644 extensions/transformiix/docs/compiled-templates.html delete mode 100644 extensions/transformiix/docs/contributors.html delete mode 100644 extensions/transformiix/docs/optimized-stylesheets.html delete mode 100644 extensions/transformiix/docs/optimized-xpath.html delete mode 100644 extensions/transformiix/docs/readme.html delete mode 100644 extensions/transformiix/resources/Makefile.in delete mode 100644 extensions/transformiix/resources/XSLTMark/XSLTMark-static.js delete mode 100644 extensions/transformiix/resources/XSLTMark/XSLTMark-test.js delete mode 100644 extensions/transformiix/resources/XSLTMark/XSLTMark-view.js delete mode 100644 extensions/transformiix/resources/XSLTMark/XSLTMark.css delete mode 100644 extensions/transformiix/resources/XSLTMark/XSLTMark.xul delete mode 100644 extensions/transformiix/resources/buster/DiffDOM.js delete mode 100644 extensions/transformiix/resources/buster/DumpDOM.js delete mode 100644 extensions/transformiix/resources/buster/Makefile.in delete mode 100644 extensions/transformiix/resources/buster/ReadMe delete mode 100644 extensions/transformiix/resources/buster/buster-files.js delete mode 100644 extensions/transformiix/resources/buster/buster-handlers.js delete mode 100644 extensions/transformiix/resources/buster/buster-statics.js delete mode 100644 extensions/transformiix/resources/buster/buster-test.js delete mode 100644 extensions/transformiix/resources/buster/buster-view.js delete mode 100644 extensions/transformiix/resources/buster/buster.css delete mode 100644 extensions/transformiix/resources/buster/buster.xul delete mode 100644 extensions/transformiix/resources/buster/contents.rdf delete mode 100644 extensions/transformiix/resources/buster/helper/generate-rdf.pl delete mode 100644 extensions/transformiix/resources/buster/install.js delete mode 100644 extensions/transformiix/resources/buster/jar.mn delete mode 100644 extensions/transformiix/resources/buster/result-inspector.xul delete mode 100644 extensions/transformiix/resources/buster/result-view.css delete mode 100644 extensions/transformiix/resources/buster/result-view.js delete mode 100644 extensions/transformiix/resources/buster/result-view.xul delete mode 100644 extensions/transformiix/resources/buster/xslt-qa-overlay.js delete mode 100644 extensions/transformiix/resources/buster/xslt-qa-overlay.xul delete mode 100644 extensions/transformiix/source/.cvsignore delete mode 100644 extensions/transformiix/source/Makefile.in delete mode 100644 extensions/transformiix/source/base/.cvsignore delete mode 100644 extensions/transformiix/source/base/Double.cpp delete mode 100644 extensions/transformiix/source/base/ErrorObserver.h delete mode 100644 extensions/transformiix/source/base/List.cpp delete mode 100644 extensions/transformiix/source/base/List.h delete mode 100644 extensions/transformiix/source/base/Makefile.in delete mode 100644 extensions/transformiix/source/base/SimpleErrorObserver.cpp delete mode 100644 extensions/transformiix/source/base/TxLog.h delete mode 100644 extensions/transformiix/source/base/txAtoms.cpp delete mode 100644 extensions/transformiix/source/base/txAtoms.h delete mode 100644 extensions/transformiix/source/base/txCore.h delete mode 100644 extensions/transformiix/source/base/txError.h delete mode 100644 extensions/transformiix/source/base/txExpandedNameMap.cpp delete mode 100644 extensions/transformiix/source/base/txExpandedNameMap.h delete mode 100644 extensions/transformiix/source/base/txNamespaceMap.cpp delete mode 100644 extensions/transformiix/source/base/txNamespaceMap.h delete mode 100644 extensions/transformiix/source/base/txStack.h delete mode 100644 extensions/transformiix/source/base/txStringUtils.cpp delete mode 100644 extensions/transformiix/source/base/txStringUtils.h delete mode 100644 extensions/transformiix/source/base/txTokenizer.h delete mode 100644 extensions/transformiix/source/base/txURIUtils.cpp delete mode 100644 extensions/transformiix/source/base/txURIUtils.h delete mode 100644 extensions/transformiix/source/examples/functions.html delete mode 100644 extensions/transformiix/source/examples/functions.xml delete mode 100644 extensions/transformiix/source/examples/functions.xsl delete mode 100644 extensions/transformiix/source/examples/identity-result.xml delete mode 100644 extensions/transformiix/source/examples/identity.xml delete mode 100644 extensions/transformiix/source/examples/identity.xsl delete mode 100644 extensions/transformiix/source/examples/include-helper.xsl delete mode 100644 extensions/transformiix/source/examples/include.html delete mode 100644 extensions/transformiix/source/examples/include.xml delete mode 100644 extensions/transformiix/source/examples/include.xsl delete mode 100644 extensions/transformiix/source/examples/sort.html delete mode 100644 extensions/transformiix/source/examples/sort.xml delete mode 100644 extensions/transformiix/source/examples/sort.xsl delete mode 100644 extensions/transformiix/source/examples/test.html delete mode 100644 extensions/transformiix/source/examples/test.xml delete mode 100644 extensions/transformiix/source/examples/test.xsl delete mode 100644 extensions/transformiix/source/examples/view-source.xsl delete mode 100644 extensions/transformiix/source/lib/Makefile.in delete mode 100644 extensions/transformiix/source/main/.cvsignore delete mode 100644 extensions/transformiix/source/main/Makefile.in delete mode 100644 extensions/transformiix/source/main/testXalan.cpp delete mode 100644 extensions/transformiix/source/main/transformiix.cpp delete mode 100644 extensions/transformiix/source/main/txTestExpr.cpp delete mode 100644 extensions/transformiix/source/main/txXSLTMarkDriver.cpp delete mode 100644 extensions/transformiix/source/xml/.cvsignore delete mode 100644 extensions/transformiix/source/xml/Makefile.in delete mode 100644 extensions/transformiix/source/xml/XMLUtils.cpp delete mode 100644 extensions/transformiix/source/xml/XMLUtils.h delete mode 100644 extensions/transformiix/source/xml/dom/.cvsignore delete mode 100644 extensions/transformiix/source/xml/dom/Makefile.in delete mode 100644 extensions/transformiix/source/xml/dom/dom.h delete mode 100644 extensions/transformiix/source/xml/dom/standalone/.cvsignore delete mode 100644 extensions/transformiix/source/xml/dom/standalone/Attr.cpp delete mode 100644 extensions/transformiix/source/xml/dom/standalone/Document.cpp delete mode 100644 extensions/transformiix/source/xml/dom/standalone/Element.cpp delete mode 100644 extensions/transformiix/source/xml/dom/standalone/Makefile.in delete mode 100644 extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp delete mode 100644 extensions/transformiix/source/xml/dom/standalone/ProcessingInstruction.cpp delete mode 100644 extensions/transformiix/source/xml/dom/standalone/dom.h delete mode 100644 extensions/transformiix/source/xml/parser/.cvsignore delete mode 100644 extensions/transformiix/source/xml/parser/Makefile.in delete mode 100644 extensions/transformiix/source/xml/parser/txXMLParser.cpp delete mode 100644 extensions/transformiix/source/xml/parser/txXMLParser.h delete mode 100644 extensions/transformiix/source/xpath/.cvsignore delete mode 100644 extensions/transformiix/source/xpath/AdditiveExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/AttributeValueTemplate.cpp delete mode 100644 extensions/transformiix/source/xpath/BooleanExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/BooleanFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/BooleanResult.cpp delete mode 100644 extensions/transformiix/source/xpath/Expr.h delete mode 100644 extensions/transformiix/source/xpath/ExprLexer.cpp delete mode 100644 extensions/transformiix/source/xpath/ExprLexer.h delete mode 100644 extensions/transformiix/source/xpath/ExprParser.cpp delete mode 100644 extensions/transformiix/source/xpath/ExprParser.h delete mode 100644 extensions/transformiix/source/xpath/ExprResult.h delete mode 100644 extensions/transformiix/source/xpath/FilterExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/FunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/FunctionLib.h delete mode 100644 extensions/transformiix/source/xpath/LocationStep.cpp delete mode 100644 extensions/transformiix/source/xpath/Makefile.in delete mode 100644 extensions/transformiix/source/xpath/MultiplicativeExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/NumberFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/NumberResult.cpp delete mode 100644 extensions/transformiix/source/xpath/PathExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/PredicateList.cpp delete mode 100644 extensions/transformiix/source/xpath/RelationalExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/RootExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/StringFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/StringResult.cpp delete mode 100644 extensions/transformiix/source/xpath/UnaryExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/UnionExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/VariableRefExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/XFormsFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xpath/XFormsFunctions.h delete mode 100644 extensions/transformiix/source/xpath/nsIXFormsUtilityService.h delete mode 100644 extensions/transformiix/source/xpath/nsIXFormsXPathEvaluator.h delete mode 100644 extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.h delete mode 100755 extensions/transformiix/source/xpath/nsXPath1Scheme.cpp delete mode 100755 extensions/transformiix/source/xpath/nsXPath1Scheme.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathEvaluator.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathEvaluator.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathException.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathException.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathExpression.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathExpression.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathNSResolver.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathNSResolver.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathNamespace.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathNamespace.h delete mode 100644 extensions/transformiix/source/xpath/nsXPathResult.cpp delete mode 100644 extensions/transformiix/source/xpath/nsXPathResult.h delete mode 100755 extensions/transformiix/source/xpath/txErrorExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/txForwardContext.cpp delete mode 100644 extensions/transformiix/source/xpath/txForwardContext.h delete mode 100644 extensions/transformiix/source/xpath/txIXPathContext.h delete mode 100644 extensions/transformiix/source/xpath/txLiteralExpr.cpp delete mode 100644 extensions/transformiix/source/xpath/txMozillaXPathTreeWalker.cpp delete mode 100644 extensions/transformiix/source/xpath/txNameTest.cpp delete mode 100644 extensions/transformiix/source/xpath/txNodeSet.cpp delete mode 100644 extensions/transformiix/source/xpath/txNodeSet.h delete mode 100644 extensions/transformiix/source/xpath/txNodeSetContext.cpp delete mode 100644 extensions/transformiix/source/xpath/txNodeSetContext.h delete mode 100644 extensions/transformiix/source/xpath/txNodeTypeTest.cpp delete mode 100644 extensions/transformiix/source/xpath/txResultRecycler.cpp delete mode 100644 extensions/transformiix/source/xpath/txResultRecycler.h delete mode 100644 extensions/transformiix/source/xpath/txSingleNodeContext.h delete mode 100644 extensions/transformiix/source/xpath/txStandaloneXPathTreeWalker.cpp delete mode 100644 extensions/transformiix/source/xpath/txXPathAtomList.h delete mode 100644 extensions/transformiix/source/xpath/txXPathNode.h delete mode 100644 extensions/transformiix/source/xpath/txXPathTreeWalker.h delete mode 100644 extensions/transformiix/source/xslt/.cvsignore delete mode 100644 extensions/transformiix/source/xslt/Makefile.in delete mode 100644 extensions/transformiix/source/xslt/functions/.cvsignore delete mode 100644 extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/DocumentFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/ElementAvailableFnCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/FunctionAvailableFnCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/GenerateIdFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/Makefile.in delete mode 100644 extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/XSLTFunctions.h delete mode 100644 extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/functions/txKey.h delete mode 100644 extensions/transformiix/source/xslt/functions/txKeyFunctionCall.cpp delete mode 100644 extensions/transformiix/source/xslt/txBufferingHandler.cpp delete mode 100644 extensions/transformiix/source/xslt/txBufferingHandler.h delete mode 100644 extensions/transformiix/source/xslt/txExecutionState.cpp delete mode 100644 extensions/transformiix/source/xslt/txExecutionState.h delete mode 100644 extensions/transformiix/source/xslt/txHTMLAtomList.h delete mode 100644 extensions/transformiix/source/xslt/txHTMLOutput.cpp delete mode 100644 extensions/transformiix/source/xslt/txHTMLOutput.h delete mode 100644 extensions/transformiix/source/xslt/txInstructions.cpp delete mode 100644 extensions/transformiix/source/xslt/txInstructions.h delete mode 100644 extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp delete mode 100644 extensions/transformiix/source/xslt/txMozillaTextOutput.cpp delete mode 100644 extensions/transformiix/source/xslt/txMozillaTextOutput.h delete mode 100644 extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp delete mode 100644 extensions/transformiix/source/xslt/txMozillaXMLOutput.h delete mode 100644 extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp delete mode 100644 extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h delete mode 100644 extensions/transformiix/source/xslt/txOutputFormat.cpp delete mode 100644 extensions/transformiix/source/xslt/txOutputFormat.h delete mode 100644 extensions/transformiix/source/xslt/txPatternParser.cpp delete mode 100644 extensions/transformiix/source/xslt/txPatternParser.h delete mode 100644 extensions/transformiix/source/xslt/txRtfHandler.cpp delete mode 100644 extensions/transformiix/source/xslt/txRtfHandler.h delete mode 100644 extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.cpp delete mode 100644 extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.h delete mode 100644 extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.cpp delete mode 100644 extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.h delete mode 100644 extensions/transformiix/source/xslt/txStylesheet.cpp delete mode 100644 extensions/transformiix/source/xslt/txStylesheet.h delete mode 100644 extensions/transformiix/source/xslt/txStylesheetCompileHandlers.cpp delete mode 100644 extensions/transformiix/source/xslt/txStylesheetCompileHandlers.h delete mode 100644 extensions/transformiix/source/xslt/txStylesheetCompiler.cpp delete mode 100644 extensions/transformiix/source/xslt/txStylesheetCompiler.h delete mode 100644 extensions/transformiix/source/xslt/txTextHandler.cpp delete mode 100644 extensions/transformiix/source/xslt/txTextHandler.h delete mode 100644 extensions/transformiix/source/xslt/txTextOutput.cpp delete mode 100644 extensions/transformiix/source/xslt/txTextOutput.h delete mode 100644 extensions/transformiix/source/xslt/txToplevelItems.cpp delete mode 100644 extensions/transformiix/source/xslt/txToplevelItems.h delete mode 100644 extensions/transformiix/source/xslt/txUnknownHandler.cpp delete mode 100644 extensions/transformiix/source/xslt/txUnknownHandler.h delete mode 100644 extensions/transformiix/source/xslt/txVariableMap.h delete mode 100644 extensions/transformiix/source/xslt/txXMLEventHandler.h delete mode 100644 extensions/transformiix/source/xslt/txXMLOutput.cpp delete mode 100644 extensions/transformiix/source/xslt/txXMLOutput.h delete mode 100644 extensions/transformiix/source/xslt/txXSLTAtomList.h delete mode 100644 extensions/transformiix/source/xslt/txXSLTNumber.cpp delete mode 100644 extensions/transformiix/source/xslt/txXSLTNumber.h delete mode 100644 extensions/transformiix/source/xslt/txXSLTNumberCounters.cpp delete mode 100644 extensions/transformiix/source/xslt/txXSLTPatterns.cpp delete mode 100644 extensions/transformiix/source/xslt/txXSLTPatterns.h delete mode 100644 extensions/transformiix/source/xslt/txXSLTProcessor.cpp delete mode 100644 extensions/transformiix/source/xslt/txXSLTProcessor.h delete mode 100644 extensions/transformiix/source/xslt/util/.cvsignore delete mode 100644 extensions/transformiix/source/xslt/util/Makefile.in delete mode 100644 extensions/transformiix/source/xslt/util/txNodeSorter.cpp delete mode 100644 extensions/transformiix/source/xslt/util/txNodeSorter.h delete mode 100644 extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp delete mode 100644 extensions/transformiix/source/xslt/util/txXPathResultComparator.h diff --git a/content/xsl/.cvsignore b/content/xsl/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/content/xsl/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/content/xsl/Makefile.in b/content/xsl/Makefile.in deleted file mode 100755 index 8b7c0fe5e541..000000000000 --- a/content/xsl/Makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org Code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -DIRS = public - -include $(topsrcdir)/config/config.mk - -include $(topsrcdir)/config/rules.mk diff --git a/content/xsl/public/.cvsignore b/content/xsl/public/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/content/xsl/public/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/content/xsl/public/Makefile.in b/content/xsl/public/Makefile.in deleted file mode 100644 index 3dbb06df01b0..000000000000 --- a/content/xsl/public/Makefile.in +++ /dev/null @@ -1,59 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 2002 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Peter Van der Beken (original author) -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = content -XPIDL_MODULE = content_xslt - -EXPORTS = \ - nsIDocumentTransformer.h \ - $(NULL) - -XPIDLSRCS = \ - nsIXSLTException.idl \ - nsIXSLTProcessor.idl \ - nsIXSLTProcessorObsolete.idl \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - diff --git a/content/xsl/public/nsIDocumentTransformer.h b/content/xsl/public/nsIDocumentTransformer.h deleted file mode 100644 index fd6646741dcc..000000000000 --- a/content/xsl/public/nsIDocumentTransformer.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking (Original author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIDocumentTransformer_h__ -#define nsIDocumentTransformer_h__ - -#include "nsISupports.h" - -class nsIDOMDocument; -class nsIDOMNode; -class nsILoadGroup; -class nsIURI; -class nsIPrincipal; - -#define NS_ITRANSFORMOBSERVER_IID \ - {0xcce88481, 0x6eb3, 0x11d6, \ - { 0xa7, 0xf2, 0x8d, 0x82, 0xcd, 0x2a, 0xf3, 0x7c }} - -class nsITransformObserver : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITRANSFORMOBSERVER_IID) - - NS_IMETHOD OnDocumentCreated(nsIDOMDocument *aResultDocument) = 0; - - NS_IMETHOD OnTransformDone(nsresult aResult, - nsIDOMDocument *aResultDocument) = 0; - -}; - -#define NS_IDOCUMENTTRANSFORMER_IID \ - {0x43e5a6c6, 0xa53c, 0x4f97, \ - { 0x91, 0x79, 0x47, 0xf2, 0x46, 0xec, 0xd9, 0xd6 }} - -class nsIDocumentTransformer : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENTTRANSFORMER_IID) - - NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver) = 0; - NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup, - nsIPrincipal* aCallerPrincipal) = 0; - NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource) = 0; - NS_IMETHOD CancelLoads() = 0; -}; - -#endif //nsIDocumentTransformer_h__ diff --git a/content/xsl/public/nsIXSLTException.idl b/content/xsl/public/nsIXSLTException.idl deleted file mode 100644 index 0c291d1ad8f7..000000000000 --- a/content/xsl/public/nsIXSLTException.idl +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT Processor. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht, - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIException.idl" -#include "domstubs.idl" - -[scriptable, uuid(e06dfaea-92d5-47f7-a800-c5f5404d8771)] -interface nsIXSLTException : nsIException { - /** - * The node in the stylesheet that triggered the exception. - */ - readonly attribute nsIDOMNode styleNode; - - /** - * The context node, may be null - */ - readonly attribute nsIDOMNode sourceNode; -}; diff --git a/content/xsl/public/nsIXSLTProcessor.idl b/content/xsl/public/nsIXSLTProcessor.idl deleted file mode 100644 index a2f41c3e1969..000000000000 --- a/content/xsl/public/nsIXSLTProcessor.idl +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT Processor. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht, - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" -#include "domstubs.idl" - -interface nsIVariant; - -[scriptable, uuid(4a91aeb3-4100-43ee-a21e-9866268757c5)] -interface nsIXSLTProcessor : nsISupports -{ - /** - * Import the stylesheet into this XSLTProcessor for transformations. - * - * @param style The root-node of a XSLT stylesheet. This can be either - * a document node or an element node. If a document node - * then the document can contain either a XSLT stylesheet - * or a LRE stylesheet. - * If the argument is an element node it must be the - * xsl:stylesheet (or xsl:transform) element of an XSLT - * stylesheet. - * - * @exception nsIXSLTException - */ - void importStylesheet(in nsIDOMNode style); - - /** - * Transforms the node source applying the stylesheet given by - * the importStylesheet() function. The owner document of the output node - * owns the returned document fragment. - * - * @param source The node to be transformed - * @param output This document is used to generate the output - * @return DocumentFragment The result of the transformation - * - * @exception nsIXSLTException - */ - nsIDOMDocumentFragment transformToFragment(in nsIDOMNode source, - in nsIDOMDocument output); - - /** - * Transforms the node source applying the stylesheet given by the - * importStylesheet() function. - * - * @param source The node to be transformed - * @return Document The result of the transformation - * - * @exception nsIXSLTException - */ - nsIDOMDocument transformToDocument(in nsIDOMNode source); - - /** - * Sets a parameter to be used in subsequent transformations with this - * nsIXSLTProcessor. If the parameter doesn't exist in the stylesheet the - * parameter will be ignored. - * - * @param namespaceURI The namespaceURI of the XSLT parameter - * @param localName The local name of the XSLT parameter - * @param value The new value of the XSLT parameter - * - * @exception NS_ERROR_ILLEGAL_VALUE The datatype of value is - * not supported - */ - void setParameter(in DOMString namespaceURI, - in DOMString localName, - in nsIVariant value); - - /** - * Gets a parameter if previously set by setParameter. Returns null - * otherwise. - * - * @param namespaceURI The namespaceURI of the XSLT parameter - * @param localName The local name of the XSLT parameter - * @return nsIVariant The value of the XSLT parameter - */ - nsIVariant getParameter(in DOMString namespaceURI, - in DOMString localName); - /** - * Removes a parameter, if set. This will make the processor use the - * default-value for the parameter as specified in the stylesheet. - * - * @param namespaceURI The namespaceURI of the XSLT parameter - * @param localName The local name of the XSLT parameter - */ - void removeParameter(in DOMString namespaceURI, - in DOMString localName); - - /** - * Removes all set parameters from this nsIXSLTProcessor. This will make - * the processor use the default-value for all parameters as specified in - * the stylesheet. - */ - void clearParameters(); - - /** - * Remove all parameters and stylesheets from this nsIXSLTProcessor. - */ - void reset(); -}; diff --git a/content/xsl/public/nsIXSLTProcessorObsolete.idl b/content/xsl/public/nsIXSLTProcessorObsolete.idl deleted file mode 100644 index 4ff46ae6f1b4..000000000000 --- a/content/xsl/public/nsIXSLTProcessorObsolete.idl +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Nisheeth Ranjan (original author) - * Peter Van der Beken - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" - -interface nsIDOMNode; -interface nsIDOMDocument; - -/** - * DEPRECATED! Don't use this interface! Use nsIXSLTProcessor instead!! - */ - -[scriptable, uuid(3fbff728-2d20-11d3-aef3-00108300ff91)] -interface nsIXSLTProcessorObsolete : nsISupports -{ - void transformDocument(in nsIDOMNode aSourceDOM, - in nsIDOMNode aStyleDOM, - in nsIDOMDocument aOutputDOC, - in nsISupports aObserver); -}; diff --git a/content/xsl/tests/book.css b/content/xsl/tests/book.css deleted file mode 100644 index 58f9d2eb5e4c..000000000000 --- a/content/xsl/tests/book.css +++ /dev/null @@ -1,2 +0,0 @@ -title {font-weight: bold;} -author {font-style: italic;} diff --git a/content/xsl/tests/book.xml b/content/xsl/tests/book.xml deleted file mode 100644 index 64dd71ce00ac..000000000000 --- a/content/xsl/tests/book.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - -Nisheeth's Document - \ No newline at end of file diff --git a/content/xsl/tests/book.xsl b/content/xsl/tests/book.xsl deleted file mode 100644 index 855535d803fb..000000000000 --- a/content/xsl/tests/book.xsl +++ /dev/null @@ -1,18 +0,0 @@ - - - - - A Document - - - - - - - - -

- -

-
-
\ No newline at end of file diff --git a/extensions/transformiix/.cvsignore b/extensions/transformiix/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/Makefile.in b/extensions/transformiix/Makefile.in deleted file mode 100644 index e5cb7d8f0d6d..000000000000 --- a/extensions/transformiix/Makefile.in +++ /dev/null @@ -1,51 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -DIRS = source -ifndef TX_EXE -DIRS += build resources -endif - -include $(topsrcdir)/config/rules.mk diff --git a/extensions/transformiix/build/.cvsignore b/extensions/transformiix/build/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/build/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/build/Makefile.in b/extensions/transformiix/build/Makefile.in deleted file mode 100644 index e949a5b62ef8..000000000000 --- a/extensions/transformiix/build/Makefile.in +++ /dev/null @@ -1,94 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = transformiix -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = TransformiixModule -ifneq ($(OS_ARCH),WINNT) -SHORT_LIBNAME = t8iix -endif -MOZILLA_INTERNAL_API = 1 - -PACKAGE_FILE = transformiix.pkg - -REQUIRES = xpcom \ - string \ - dom \ - content \ - layout \ - widget \ - necko \ - js \ - xpconnect \ - caps \ - htmlparser \ - $(NULL) - - -CPPSRCS = XSLTProcessorModule.cpp - -SHARED_LIBRARY_LIBS = \ - $(DIST)/lib/$(LIB_PREFIX)txbase_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxml_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxmlparser_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxpath_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxslt_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxsltfunctions_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxsltutil_s.$(LIB_SUFFIX) \ - $(NULL) - -EXTRA_DSO_LDOPTS += \ - $(MOZ_UNICHARUTIL_LIBS) \ - $(MOZ_COMPONENT_LIBS) \ - $(MOZ_JS_LIBS) \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir)/../source/xslt -I$(srcdir)/../source/base \ - -I$(srcdir)/../source/xml -I$(srcdir)/../source/xml/parser \ - -I$(srcdir)/../source/xpath -I$(srcdir)/../source/xslt/util \ - -I$(srcdir)/../source/xslt/functions diff --git a/extensions/transformiix/build/XSLTProcessorModule.cpp b/extensions/transformiix/build/XSLTProcessorModule.cpp deleted file mode 100755 index 2107f38c1147..000000000000 --- a/extensions/transformiix/build/XSLTProcessorModule.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Peter Van der Beken. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsICategoryManager.h" -#include "nsIDOMClassInfo.h" -#include "nsIDOMNSXPathExpression.h" -#include "nsIDOMXPathExpression.h" -#include "nsIDOMXPathNSResolver.h" -#include "nsIDOMXPathResult.h" -#include "nsIErrorService.h" -#include "nsIExceptionService.h" -#include "nsIGenericFactory.h" -#include "nsIParserService.h" -#include "nsIScriptNameSpaceManager.h" -#include "nsIServiceManager.h" -#include "nsXPathEvaluator.h" -#include "nsXPathException.h" -#include "nsXPIDLString.h" -#include "txAtoms.h" -#include "txMozillaXSLTProcessor.h" -#include "TxLog.h" -#include "nsCRT.h" -#include "nsIScriptSecurityManager.h" -#include "txURIUtils.h" -#include "txXSLTProcessor.h" -#include "nsXPath1Scheme.h" - -#ifndef DISABLE_XFORMS_HOOKS -#include "nsXFormsXPathEvaluator.h" -#endif - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPath1SchemeProcessor) - -/* 1c1a3c01-14f6-11d6-a7f2-ea502af815dc */ -#define TRANSFORMIIX_DOMCI_EXTENSION_CID \ -{ 0x1c1a3c01, 0x14f6, 0x11d6, {0xa7, 0xf2, 0xea, 0x50, 0x2a, 0xf8, 0x15, 0xdc} } - -/* {0C351177-0159-4500-86B0-A219DFDE4258} */ -#define TRANSFORMIIX_XPATH1_SCHEME_CID \ -{ 0xc351177, 0x159, 0x4500, { 0x86, 0xb0, 0xa2, 0x19, 0xdf, 0xde, 0x42, 0x58 } } - -#define TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID \ -"@mozilla.org/transformiix-domci-extender;1" - -NS_DOMCI_EXTENSION(Transformiix) - static NS_DEFINE_CID(kXSLTProcessorCID, TRANSFORMIIX_XSLT_PROCESSOR_CID); - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XSLTProcessor) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIXSLTProcessor) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIXSLTProcessorObsolete) // XXX DEPRECATED - NS_DOMCI_EXTENSION_ENTRY_END(XSLTProcessor, nsIXSLTProcessor, PR_TRUE, - &kXSLTProcessorCID) - - static NS_DEFINE_CID(kXPathEvaluatorCID, TRANSFORMIIX_XPATH_EVALUATOR_CID); - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathEvaluator) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathEvaluator) - NS_DOMCI_EXTENSION_ENTRY_END(XPathEvaluator, nsIDOMXPathEvaluator, PR_TRUE, - &kXPathEvaluatorCID) - - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathException) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathException) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIException) - NS_DOMCI_EXTENSION_ENTRY_END(XPathException, nsIDOMXPathException, PR_TRUE, - nsnull) - - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathExpression) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathExpression) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMNSXPathExpression) - NS_DOMCI_EXTENSION_ENTRY_END(XPathExpression, nsIDOMXPathExpression, - PR_TRUE, nsnull) - - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathNSResolver) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathNSResolver) - NS_DOMCI_EXTENSION_ENTRY_END(XPathNSResolver, nsIDOMXPathNSResolver, - PR_TRUE, nsnull) - - NS_DOMCI_EXTENSION_ENTRY_BEGIN(XPathResult) - NS_DOMCI_EXTENSION_ENTRY_INTERFACE(nsIDOMXPathResult) - NS_DOMCI_EXTENSION_ENTRY_END(XPathResult, nsIDOMXPathResult, PR_TRUE, - nsnull) -NS_DOMCI_EXTENSION_END - -// Factory Constructor -NS_GENERIC_FACTORY_CONSTRUCTOR(txMozillaXSLTProcessor) -NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(nsXPathEvaluator, Init) -#ifndef DISABLE_XFORMS_HOOKS -NS_GENERIC_FACTORY_CONSTRUCTOR(nsXFormsXPathEvaluator) -#endif - -NS_DECL_DOM_CLASSINFO(XSLTProcessor) -NS_DECL_DOM_CLASSINFO(XPathEvaluator) -NS_DECL_DOM_CLASSINFO(XPathException) -NS_DECL_DOM_CLASSINFO(XPathExpression) -NS_DECL_DOM_CLASSINFO(XPathNSResolver) -NS_DECL_DOM_CLASSINFO(XPathResult) - -static NS_METHOD -RegisterTransformiix(nsIComponentManager *aCompMgr, - nsIFile *aPath, - const char *registryLocation, - const char *componentType, - const nsModuleComponentInfo *info) -{ - nsresult rv = NS_OK; - - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - - if (NS_FAILED(rv)) - return rv; - - nsXPIDLCString previous; - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XSLTProcessor", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XPathEvaluator", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XPathException", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XPathExpression", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XPathNSResolver", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_CLASS, - "XPathResult", - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - char* iidString = NS_GET_IID(nsIXSLTProcessorObsolete).ToString(); - if (!iidString) - return NS_ERROR_OUT_OF_MEMORY; - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_INTERFACE, - "nsIXSLTProcessorObsolete", - iidString, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - nsCRT::free(iidString); - NS_ENSURE_SUCCESS(rv, rv); - - iidString = NS_GET_IID(nsIXSLTProcessor).ToString(); - if (!iidString) - return NS_ERROR_OUT_OF_MEMORY; - rv = catman->AddCategoryEntry(JAVASCRIPT_DOM_INTERFACE, - "nsIXSLTProcessor", - iidString, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - nsCRT::free(iidString); - - return rv; -} - -static PRBool gInitialized = PR_FALSE; -static nsIExceptionProvider *gXPathExceptionProvider = 0; -nsINameSpaceManager *gTxNameSpaceManager = 0; -nsIParserService *gTxParserService = 0; - -// Perform our one-time intialization for this module -PR_STATIC_CALLBACK(nsresult) -Initialize(nsIModule* aSelf) -{ - NS_PRECONDITION(!gInitialized, "module already initialized"); - if (gInitialized) - return NS_OK; - - gInitialized = PR_TRUE; - - gXPathExceptionProvider = new nsXPathExceptionProvider(); - if (!gXPathExceptionProvider) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(gXPathExceptionProvider); - nsCOMPtr xs = - do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID); - if (xs) - xs->RegisterExceptionProvider(gXPathExceptionProvider, - NS_ERROR_MODULE_DOM_XPATH); - - if (!txXSLTProcessor::init()) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsresult rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, - &gTxSecurityManager); - if (NS_FAILED(rv)) { - gTxSecurityManager = nsnull; - return rv; - } - - rv = CallGetService(NS_NAMESPACEMANAGER_CONTRACTID, &gTxNameSpaceManager); - if (NS_FAILED(rv)) { - gTxNameSpaceManager = nsnull; - return rv; - } - - rv = CallGetService("@mozilla.org/parser/parser-service;1", - &gTxParserService); - if (NS_FAILED(rv)) { - gTxParserService = nsnull; - return rv; - } - - nsCOMPtr errorService = - do_GetService(NS_ERRORSERVICE_CONTRACTID); - if (errorService) { - errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_XSLT, - XSLT_MSGS_URL); - } - - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -PR_STATIC_CALLBACK(void) -Shutdown(nsIModule* aSelf) -{ - NS_PRECONDITION(gInitialized, "module not initialized"); - if (!gInitialized) - return; - - gInitialized = PR_FALSE; - if (gXPathExceptionProvider) { - nsCOMPtr xs = - do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID); - if (xs) - xs->UnregisterExceptionProvider(gXPathExceptionProvider, - NS_ERROR_MODULE_DOM_XPATH); - NS_RELEASE(gXPathExceptionProvider); - } - - NS_IF_RELEASE(NS_CLASSINFO_NAME(XSLTProcessor)); - NS_IF_RELEASE(NS_CLASSINFO_NAME(XPathEvaluator)); - NS_IF_RELEASE(NS_CLASSINFO_NAME(XPathException)); - NS_IF_RELEASE(NS_CLASSINFO_NAME(XPathExpression)); - NS_IF_RELEASE(NS_CLASSINFO_NAME(XPathNSResolver)); - NS_IF_RELEASE(NS_CLASSINFO_NAME(XPathResult)); - - txXSLTProcessor::shutdown(); - - NS_IF_RELEASE(gTxSecurityManager); - NS_IF_RELEASE(gTxNameSpaceManager); - NS_IF_RELEASE(gTxParserService); -} - -// Component Table -static const nsModuleComponentInfo gComponents[] = { - { "XSLTProcessor", - TRANSFORMIIX_XSLT_PROCESSOR_CID, - TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID, - txMozillaXSLTProcessorConstructor, - RegisterTransformiix }, - { "XPathEvaluator", - TRANSFORMIIX_XPATH_EVALUATOR_CID, - NS_XPATH_EVALUATOR_CONTRACTID, - nsXPathEvaluatorConstructor }, -#ifndef DISABLE_XFORMS_HOOKS - { "XFormsXPathEvaluator", - TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_CID, - NS_XFORMS_XPATH_EVALUATOR_CONTRACTID, - nsXFormsXPathEvaluatorConstructor }, -#endif - { "Transformiix DOMCI Extender", - TRANSFORMIIX_DOMCI_EXTENSION_CID, - TRANSFORMIIX_DOMCI_EXTENSION_CONTRACTID, - NS_DOMCI_EXTENSION_CONSTRUCTOR(Transformiix) }, - { "XPath1 XPointer Scheme Processor", - TRANSFORMIIX_XPATH1_SCHEME_CID, - NS_XPOINTER_SCHEME_PROCESSOR_BASE "xpath1", - nsXPath1SchemeProcessorConstructor } -}; - -NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(TransformiixModule, gComponents, - Initialize, Shutdown) diff --git a/extensions/transformiix/build/transformiix.jst b/extensions/transformiix/build/transformiix.jst deleted file mode 100644 index a17ac1595080..000000000000 --- a/extensions/transformiix/build/transformiix.jst +++ /dev/null @@ -1,30 +0,0 @@ -var err = initInstall("Transformiix", "Transformiix", $Version$); -logComment("initInstall: " + err); - -var fProgram = getFolder("Program"); -logComment("fProgram: " + fProgram); - -if (verifyDiskSpace(fProgram, $SpaceRequired$)) -{ - err = addDirectory("Transformiix", - $Version$, - "bin", - fProgram, - "", - true ); - - logComment("addDirectory() returned: " + err); - - if (err==SUCCESS) - { - err = performInstall(); - logComment("performInstall() returned: " + err); - } - else - { - cancelInstall(err); - logComment("cancelInstall() due to error: " + err); - } -} -else - cancelInstall(INSUFFICIENT_DISK_SPACE); diff --git a/extensions/transformiix/build/transformiix.pkg b/extensions/transformiix/build/transformiix.pkg deleted file mode 100644 index cd9fcae8999f..000000000000 --- a/extensions/transformiix/build/transformiix.pkg +++ /dev/null @@ -1,12 +0,0 @@ -# right now this only packages the mozilla component -# we can think about standalone too - -# xxxbsmedberg: should this move to the GRE? -# currently transformiix is not part of the default firebird -# build, but that can be controlled by --enable-extensions -[xpfe-browser browser] -#if SHARED_LIBRARY -dist/bin/components/@SHARED_LIBRARY@ -#else -!staticcomp @LIBRARY@ @MODULE_NAME@ -#endif diff --git a/extensions/transformiix/docs/changes.txt b/extensions/transformiix/docs/changes.txt deleted file mode 100755 index 423aba9676d6..000000000000 --- a/extensions/transformiix/docs/changes.txt +++ /dev/null @@ -1,260 +0,0 @@ -***** BEGIN LICENSE BLOCK ***** -Version: MPL 1.1/GPL 2.0/LGPL 2.1 - -The contents of this file are subject to the Mozilla Public License Version -1.1 (the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at -http://www.mozilla.org/MPL/ - -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -for the specific language governing rights and limitations under the -License. - -The Original Code is TransforMiiX. - -The Initial Developer of the Original Code is -The MITRE Corporation, Keith Visco, et al. -Portions created by the Initial Developer are Copyright (C) 1999-2000 -the Initial Developer. All Rights Reserved. - -Contributor(s): - -Alternatively, the contents of this file may be used under the terms of -either the GNU General Public License Version 2 or later (the "GPL"), or -the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -in which case the provisions of the GPL or the LGPL are applicable instead -of those above. If you wish to allow use of your version of this file only -under the terms of either the GPL or the LGPL, and not to allow others to -use your version of this file under the terms of the MPL, indicate your -decision by deleting the provisions above and replace them with the notice -and other provisions required by the GPL or the LGPL. If you do not delete -the provisions above, a recipient may use your version of this file under -the terms of any one of the MPL, the GPL or the LGPL. - -***** END LICENSE BLOCK ***** - -Note: The changes listed here mainly reflect the core XSLT processor and - the standalone version. - -Build 20000906 - --- Fixed UTF8 bug - - reported by Steve Tinney (stinney@sas.upenn.edu) - --- Updated Expat for standalone version - -Build 20000725 - --- Windows Makefiles are up to date to create Mozilla module - - thanx to Arthur Barrett and Justin Smith - -Build 20000722 - --- Fixed leading + trailing whitspace when printing comments - - reported by Jeff Bailey - --- Fixed bug in ExprLexer caused by a previous patch - - The prevToken was being set to NULL, in cases when - it shouldn't have been - - discovered when looking for an error reported by - Bernhard Zwischenbrugger - -Build 20000618 - --- Added changes from Olivier Gerardin for improved - handling of template parameters - -Build 20000523 - --- Added fix from Marc Schefer regarding OR expressions - - If the left hand expression was false...the right - hand expression was not evaluated (which should - only happen if the expression is an AND expr). - --- Added support for document() function - - implemented by Olivier Gerardin - - The second argument to the function is not yet supported - --- Added support for lang() function - - implemented by Marina Mechtcherikova - --- Fixed bug with doing xsl:copy-of on a document node. - - reported by Olivier Gerardin - - -Build 20000420 - --- Fixed document base issue with transfromiix.cpp (Nathan) - - When an XSLT stylesheet is specified on the command line - the document base was still defaulting to the XML document, - instead of the stylesheet - --- Fixed bug in namespace-uri() function [NodeSetFunctionCall.cpp] - Marina - - If an expression was passed as an argument to the function, - which evaluated to an empty NodeSet, the context node was being - used, which is incorrect. We now just return an empty string. - --- Fixed bug in PathExpr::matches (Marina) - - expressions such as "foo//bar" would not always match - properly if more than one node existed in the final - set of "matching context nodes" (so basically if foo - was not the root element). - - -Build 20000419 - --- Added the generate-id function --- Added XPath Extension Function support - -Build 20000413 - --- Added some bug fixes from Marina - -- fixed parsing of multiple predicates - -- added support to handle attribute-set recursion - -- added appropriate calls to handle use-attribute-sets on xsl:copy - -Build 20000412 - --- Fixed the following Axes names in Names.cpp so that - the are compatible with the XSLT 1.0 recommendation (Marina) - -- FOLLOWING_SIBLING_AXIS - removed the trailing s - -- PRECEDING_SIBLING_AXIS - removed the trailing s - --- Added support for xsl:sort (kvisco) - -- simple sorting is working...documentation to follow --- Added StringComparator and DefaultStringComparator - -- we need some more comparators for I18N support --- Did some directory structure changes - - source/xsl is now source/xslt - - source/xsl/expr is now source/xpath --- Changed xslt/XSLProcessor.* to XSLTProcessor.* - --- Incorporated some changes from Olivier Gerardin for the Expat parser - -Build 20000331 - --- Fixed a memory leak with translate() function (kvisco) - -- StringFunctionCall.cpp --- Updated the necessary source files to support the changes to - the String class (kvisco) --- Overloaded String::toCharArray to automatically create the - character array (tomk) --- Changed String::toChar to String::toCharArray (tomk) - - -Build 20000327 --- Fixed "dot" bug in CNAME parsing (ExprLexer.cpp) reported by Nathan Pride - -Build 20000326 --- Added Peter Van der Beken's changes to net/URIUtils for integration - within Mozilla - --- Added Marina Mechtcheriakova's changes to xml/parser/XMLParser.cpp to fix - a Unicode bug in ::startElement. Instead of improperly casting char* - as DOM_CHAR*, the proper String constructor, String(char*) is used - -Build 20000322 --- Added Unicode bug fix from Lidong - -Build 20000318 --- Added Olivier's implementation of the XPath Number functions --- Added missing prototype to TxString.h (Peter Van der Beken) - -Build 20000222 --- Added Attribute parent mapping since DOM 1.0 doesn't support it --- Added default sorting of NodeSet by DocumentOrder - -- yes this is a hint that xsl:sort is will be available soon - -Build 20000218 --- Fixed bug reported by Thiery Le Bouil, xsl:param was getting - processed, and then treated as a literal element - -Build 20000217 - --- Changed StringList#iterator to return a pointer instead of a reference --- Added patches from Eric Du for FreeBSD, sorry for the delay in committing these - -Build 20000216 - --- Fixed bug with using wildcards directly after the parent operator, such as "/*" --- Fixed bug with PredicateList#isEmpty which was returning the opposite of the - expected value. - -- this also caused default priorities to be incorrectly calculated. - -Build 19991110 --- fixed bug with PathExpr and LocationStep with respect - to the ::match method - -- problem reported by Oblix --- Added support for xsl:include (only file URLs will work) --- fixed the built-in xsl:apply-templates rule to handle text nodes --- moved code base to Linux platform for default development environment - -Build 19990818 --- Added very simple support for xsl:number --- Added support for xsl:with-param --- Added more XPath support - -- added operator precedence - -- added and, or, <,<=,>=,> - - -Build 19990816 --- Changed focus from 19990709 to 19990813 XSLT Working Draft --- Made some changes for Borland C compatibility - -- submitted by Stefan Heesch --- added xsl:copy-of --- fixed a bug with DOM Element, to allow DocumentFragments as children - -Build 19990813 --- added new example: identity.xml/xsl which tests: - -- xsl:copy, node() --- added comment(), pi(), and node() - -- XMLParser still needs to handle reading in XML comments --- added xsl:copy --- added xsl:processing-instruction --- added xsl:comment - -Build 19990812 --- Created base/Double.cpp (primitives.h) - -- Based off some code submitted by Larry Fitzpatrick, changed Name from - FloatPort to Double, I wanted to add more Double related methods - -- changed the NaN() method to just a static double - -- All expr classes now use Double::isNaN() and Double::NaN - -- I added Double::isInfinite, Double::POSITIVE_INFINITY and - Double::NEGATIVE_INFINITY --- Added base/Integer.cpp back into Makefile - -- added Integer::toString(int,String); - -- changed implementation --- Moved code to convert from Strings to doubles and from doubles to Strings - into the Double class --- removed testdom.cpp from xml/dom --- Added more changes from Larry Fitzpatrick and Michele Lee for - porting issues - -- added appropriate return values for: - -- xml/dom/Element.cpp - -- xml/dom/NodeDefinition.cpp - -- base/StringList.cpp - -- xsl/expr/PredicateList.cpp --- Added remaining String Function Calls - -- substring(), substring-after(), substring-before(), translate(), - string-length() - - -Build 19990810 --- Added most of the Whitespace handling --- Added ErrorObserver interface - -- ErrorObserver is now used throughout most of the code --- Added SimpleErrorObserver implementation of ErrorObserver --- Moved main() method from XSLProcessor.cpp to tranformiix.cpp --- Added the following XPath functions: - -- local-part(), name(), namespace() - -- see functions.xml/functions.xsl for available functions - -Build 19990806 --- Incoporated Changes From Larry Fitzpatrick --- Added more XPath functions - -- last(), count(), string(), contains(), starts-with(), concat() - -- see functions.xml/functions.xsl for available functions --- Added xsl:text support - - diff --git a/extensions/transformiix/docs/compiled-stylesheets.html b/extensions/transformiix/docs/compiled-stylesheets.html deleted file mode 100644 index 79ca327c95e4..000000000000 --- a/extensions/transformiix/docs/compiled-stylesheets.html +++ /dev/null @@ -1,254 +0,0 @@ - - - Compiled Stylesheets - - - - -

Compiled Stylesheets

- -

Overview

-

- There are 5 main entities: Stylesheet-loaders, stylesheet-compiler, - stylesheet, execution-state and processor. The normal usecase is: -

    -
  1. Set up a stylesheet-loader to read a resource. -
  2. Let it feed events to the stylesheet-compiler. -
  3. The compiler creates a stylesheet. -
  4. Init an execution-state with stylesheet, initial node, global - parameters and an outputhandler factory. -
  5. Start the processor. -
-

- -

Main classes

-

txStylesheet

-

Description:

-

- This class represents a compiled stylesheet. If the stylesheet - contains imported and/or included stylesheets they are all compiled - into a single txStylesheet-object. -

- -

- The stylesheet contains functions for getting the different top-level - entities that exist in a stylesheet, such as attribute-sets, templates - and global variables. The txStylesheet owns all objects - in the stylesheet, including the instructions in templates and - variables. -

- -

- A single txStylesheet-object can be used for multiple - transformations, even running concurrently. Once a stylesheet is - compiled it is never changed, nor does it carry any state. -

- -

Typical functions:

-
-txInstruction* findTemplate(Node* aNode,
-                            const txExpandedName& aMode,
-                            txIMatchContext* aContext,
-                            ImportFrame* aImportedBy,
-                            ImportFrame** aImportFrame);
-txDecimalFormat* getDecimalFormat(const txExpandedName& aName);
-txInstruction* getAttributeSet(const txExpandedName& aName);
-txOutputFormat* getOutputFormat();
-
- -

txStylesheetCompiler

-

Description:

-

- This class gets "events" from a stylesheet loader and creates a - compiled stylesheet. The class calls back through a callback interface - to the stylesheet-loader to load included and imported stylesheets. -

- -

- The output from the txStylesheetCompiler is a - ready-to-use txStylesheet object. -

- -

- To load included and imported stylesheets the - txStylesheetCompiler calls the loader through a - txIIncludeLoaderCallback interface suppling the url to - load, and the txStylesheetCompiler-object that the loader - should use to notify its events to. There is a separate - txStylesheetCompiler-object for each sub-stylesheet, - however only the initial txStylesheetCompiler will create - a txStylesheet-object. -

- -

- Do we want to refcount txIIncludeLoaderCallback? It might otherwise - be hairy to deal with loads being cancled or failing. -

- -

Typical functions:

-
-nsresult startElement(PRInt32 aNamespaceID, txAtom* aLocalName,
-                      txAtom* aPrefix, txStylesheetAttr* aAttributes,
-                      PRInt32 aAttrCount);
-nsresult endElement();
-nsresult characters(const String& aStr);
-nsresult doneLoading();
-void cancel(nsresult aError);
-
- -

txHandlerTable

-

Description:

-

- To process the elements and textnodes in the stylesheet the - txStylesheetCompiler calls different - stylesheet-compile-handlers. Which handler to call is decided by two - things: -

    -
  1. The "mode" of the compiler, i.e. is it processing a top-level - element? Is it processing the contents of a template? Is it - processing the children of a xsl:attribute-set element? -
  2. The name and namespace of the element. (Of course, this doesn't - apply to textnodes). -
- The handlers are global static C-style functions. The handlers - processes the elements and textnodes in the stylesheet and - creates instructions and toplevel-items. -

- -

- To find which handler to call the compiler uses - txHandlerTable-objects. The txHandlerTable - contains a list of these stylesheet-compile-handlers keyed on - element-name. It also contains a handler for text and a handler for - LRE-elements. -

- -

- There are different txHandlerTable-objects for different - "modes" of the compiler. There is one for handling top-level elements, - one for handling template-parameters, one for handling the contents of - a xsl:attribte-set element, one for handling the contents of - unsupported extension-elements etc. The - txStylesheetCompiler always has a current - txHandlerTable which is used to find the handler to call. -

- -

- The txHandlerTables are initialized from static structs. - This is to avoid having large pieces of code containing very similar - code. -

- -

Typical functions:

-
-nsresult init(txHandlerTableData* aTableData);
-txElementHandler* find(PRInt32 aNamespaceID, txAtom* aLocalName);
-
- -

txStylesheetCompilerState

-

- Do we want to rename this txStylesheetCompilerInternal? -

-

Description:

-

- This class manages the internal state of the - txStylesheetCompiler. The reason that this is a separate - class is so that the txStylesheetCompiler can keep a clean - interface towards the stylesheet-loaders. -

- -

- The txStylesheetCompilerState-class is used both by the - txStylesheetCompiler-class and by the - stylesheet-compile-handlers. -

- -

- The class has three main purposes: -

    -
  • - Keep track of the current context. Such as: -
      -
    • Namespace mappings. -
    • Base-URI. -
    • Extension-element namespaces. -
    • Whitespace preservation mode. -
    -
  • -
  • - Store the state that the stylesheet-compile-handlers need. For - example the current xsl:for-each loop to add xsl:sort-elements to. -
  • -
  • - Keep track of the current txHandlerTable, so that the - right stylesheet-compile-handler is called for elements and text. -
  • -
-

- -

- This is the class that implements txIParseContext during - all stylesheet-compilation. -

- -

Typical functions:

-
-nsresult pushHandlerTable(txHandlerTable* aTable);
-nsresult parsePattern(const String& aPattern, txPattern** aResult);
-nsresult parseExpr(const String& aExpr, Expr** aResult);
-nsresult addToplevelItem(txToplevelItem* aItem);
-nsresult openInstructionContainer(txInstructionContainer* aContainer);
-nsresult addInstruction(txInstruction* aInstruction);
-
- -

txExecutionState

-

Description:

-

- This class manages all state during the execution of a stylesheet. - This includes -

    -
  • The current txIEvalContext. -
  • The next txInstruction to be executed. -
  • Variables that are in scope. -
  • Values of global variables and keys. -
  • Current result-handler. -
  • Stylesheet being executed. -
-

- -

- The txExecutionState also acts as a general-purpose stack - that instructions can use to communicate between each other. The class - is the owner of this data and will delete it as appropriate if the - execution aborts. -

- -

Typical functions:

-
-nsresult pushEvalContext(txIEvalContext* aContext);
-txIEvalContext* popEvalContext();
-nsresult pushString(const nsAString& aStr);
-void popString(nsAString& aStr);
-txInstruction* getNextInstruction();
-nsresult runTemplate(txInstruction* aInstruction);
-void gotoInstruction(txInstruction* aNext);
-
- -

txXSLTProcessor

-

Description:

-

- This is a fully static class that contains the main loop for executing - a stylsheet. -

- -

Typical functions:

-
-nsresult execute(txExecutionState& aEs);
-
- - - diff --git a/extensions/transformiix/docs/compiled-templates.html b/extensions/transformiix/docs/compiled-templates.html deleted file mode 100644 index 0214a97b6ac4..000000000000 --- a/extensions/transformiix/docs/compiled-templates.html +++ /dev/null @@ -1,273 +0,0 @@ - - - - XSLT Templates and Compiling - - - - -

XSLT Templates and Compiling

-

This document describes compiling of XSLT stylesheets and the - evaluation of the result.

- -

Objectives:

-
    -
  • Speed
  • -
  • Better support for AVTs
  • -
  • Interruptability of processing
  • -
  • exclude and alias namespaces
  • -
-

Concepts:

-
-
-
LRE namespaces
-
All namespace aliases are merged wit import precedence - into an array of all namespace ids, which is used to map the - LRE namespace in the source to the LRE namespace in the - result. Non-aliased namespaces just have their namespace id - in that array.
-
-
- -

Compilation:

-

The XSLT specification describes XSLT in terms of the XPath - datamodel, something pretty close to a DOM. So we talk about the - input in terms of DOM elements.

-
The DOM nodes in a stylesheet get compiled into either -
    -
  • nothing :-) (stuff like xsl:output),
  • -
  • xslTopElements or
  • -
  • xslInstructions.
  • -
- The xslInstructions fall into classes, -
    -
  1. simple instructions,
  2. -
  3. utilities (no-op, variable-pop, push-handler),
  4. -
  5. branching instructions,
  6. -
  7. instructions changing the result handler and
  8. -
  9. instructions calling into different - xslTopElements.
  10. -
-
-

How do instructions work?

-
The general pattern used to create output from a set of - instructions is -
while (instruction) {
-  rv = instruction.do(args);
-  if (NS_FAILED(rv)) {
-    //cleanup
-    return rv;
-  }
-  instruction = instruction.mNext;
-}
- This says pretty much all about simple and utility instructions. -
-

Branching instructions

-
see xsl:choose. The trailing single - no-op helps in rejoining the paths, as that no-op can be created - before the paths and thus easily appended to each end of the - paths.
-

Instructions that change the output handler

-
These instructions (attribute, comment, pi creating text - handlers, variable possibly creating a rtf handler) get created - by inserting a push-handler-instruction into the workflow for - the start of the element and the XSLT instruction at the - end. The handler instruction should keep a non-owning reference - to the push-handler-instruction to get the result and restore - the previous handler.
- -

xsl:apply-imports

-
no idea
- -

xsl:apply-templates

-
-
-
members:
-
-
-
select
node-set-expression
-
mode
qname
-
sorts
list of xsl:sort elements
-
params
list of xsl:with-param elements
-
-
-
do()
-
set up the params, if any, evaluate the select, create a - evalContext and push it on the evalContextStack. push the next - instruction to the instruction return stack. trigger the new - context (how do we do this?).
-
-
- -

xsl:attribute

-
-
-
members:
-
-
-
name
AVT with QName value
-
namespace
AVT with uri value
-
-
-
do()
-
the start tag pushes a textValueHandler, the end tag pops - the value handler and calls the outputhandler::attribute
-
-
- -

xsl:attribute-set (tle)

-
attribute sets are merged, - we should pay attention that multiple stylesheet compilers - don't mix their content. Order of attributes is relevant, IMHO. -
-
members:
-
-
-
name
qname
-
use-attribute-sets
list of qnames
-
-
-
do()
-
merging and stuff needed in the global stylesheet object, - (NOT part of import frame).
-
-
- -

xsl:call-template

-
-
-
members:
-
-
-
name
qname
-
with-params
list of xsl:with-params
-
-
-
do()
-
push the next instruction onto the instruction return - stack, lookup the template and set the instruction pointer - to the called template. Setup the params, if there are. This - does not change the evalContextStack. -
Can we cache this? What happens if a - added stylesheet between two transforms changes which - stylesheet this qname resolves to?
-
-
- -

xsl:choose

-
- This is a branching instruction with one exit point and several - conditional entry points (xsl:when) and one default - (xsl:otherwise). The conditional entry points start with a - conditionalGotoInstrunction, which jumps to the next entry point - if they don't succeed. Each of them ends with a gotoInstruction - that jumps to the end of the xsl:choose (for simplicity in the - compilation phase, this might be a noopInstruction). The - xsl:otherwise is just the instructions list of the - xsl:otherwise, linked to the ending noopInstruction. Note that - this construct a single instruction list for the complete - xsl:choose, as the mNext of the final gotos is the next entry - point. This mNext is only used for iterations, though. -
- -

xsl:comment

-
-
-
do()
-
startElement pushes a textHandler, endElement takes the - value and calls ::comment() in the output handler
-
-
- -

xsl:copy

-
-
-
members:
-
-
do()
-
xsl:copy has a use-attribute-sets attribute, - TODO
-
-
- -

xsl:copy-of

-
-
-
members:
-
-
-
select
-
an expression to be added to the result tree
-
-
-
do()
-
the value of the result is added to the result tree. If - the result is a RTF, the RTF is just fed into the output - handler, if the result is not a nodeset, it is converted - into a string and ::characters is called on the output - handler. For nodesets, the result is a list of source nodes - which have to be interpreted, for example thru the - stylesheet compiler. This has be xslt-blind, that is, xslt - elements in the source must be treated as LRE elements and - copied into the result, instead of generating XSLT - instructions. is this all?
-
-
- -

xsl:decimal-format (tle)

-
xsl:decimal-format is stored in the global - stylesheet object, import precedence does not apply.
- -

xsl:element

-
-
-
members:
-
-
-
name
AVT with QName - value
-
namespace
AVT with URI value
-
-
-
do()
-
xsl:element has attribute-sets, todo. Other than that, this just - generates an element. Note that the attributes of this - element have to be discarded, if the name AVT does not - evaluate to a QName.
-
-
- -

xsl:fallback

-
do we care?
- -

-
-
-
members:
-
-
do()
-
-
-
- - diff --git a/extensions/transformiix/docs/contributors.html b/extensions/transformiix/docs/contributors.html deleted file mode 100644 index 45d66e41bf05..000000000000 --- a/extensions/transformiix/docs/contributors.html +++ /dev/null @@ -1,376 +0,0 @@ - - -Transformiix (TM) Contributors - - - - - - - - - - - - -
- TransforMiiX - TM -

- -
-
-

- Much of the original TransforMiiX code was ported - from XSL:P, - an open source XSLT processor. Thanks to all the contributors of - that project. TransforMiiX is now a whole new beast...thanks to all - of the hard work of those listed below. -

-

-Core Developers

-The following people have contributed substantial time and -effort to the development. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameContributionCompany
- Visco, Keith - - Software design, and most of the XSLT implementation and - base classes implementation. - - Exoffice Technologies -

- Formerly with The MITRE Corporation. -

- Kneeland, Tom - - Software design, DOM Implementation. Handled the initial - Mozilla integration and wrapper classes, - String and String wrapper classes. - - The MITRE Corporation -
- Van der Beken, Peter - - Leading the Transformiix/Mozilla integration, - and Macintosh porting issues. Without Peter...we'd be doomed! :-) - -
-
- Hecht, Axel (AKA - Pike) - - Build issues...configure, Make, etc. Solaris porting issues. - All nasty comments on regarding make files should now be directed to Pike! - -
-
-

-

-

-Additional Developers

-The following people have contributed to the development. -
(appearing in alphabetical order) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameContributionCompany
- Barrett, Arthur - - Working on Windows makefiles. - -
-
- Brown, William Lewis - - Working with Marina on XSLT 1.0 conformity issues. - -
-
- Du, Eric - - FreeBSD floating point porting issues - -
-
- Fitzpatrick, Larry - - Larry was the first contributor to the project. He sent - a number of C++ porting issues with Visual C++, - and has influenced some of the early design. - - OpenText -
- Gerardin, Olivier - - Implemented the XPath Number functions, the document() - function, as well as some other changes/improvements. - - (see changes.txt for more info) - - - DigitalWave -
- Guarino, Bobbi - - Solaris porting issues - - Wavo Corporation -
- Heesch, Stefan - - C++ porting issues with Borland C - -
-
- Kuan, Joseph - - Sent changes for getting TransforMiiX to build on HPUX, SUNOS and AIX. - I still need to add these into the CVS. - - Hewlett-Packard -
- Lee, Michele - - C++ porting issues, bug reports - - Oblix -
- Lidong - - Some Unicode bug fixes - - Leyou.com -
- Mechtcheriakova, Marina - - Contributed a number of bug fixes, as well as handling - some conformity issues. - -
-
- Miller, Bob - - A number of bug fixes, C++ porting issues - - Oblix -
- Otte, Andreas - - Helping Axel with build issues...configure, make files, etc. - -
-
- Pride, Nathan - - Solaris porting issues, some general bug fixes - - Wavo Corporation -
- Smith, Justin - - Working on Windows Makefiles. - -
-
- -

Testing/Feedback (Suggestions/Bug Reports)

-The following people have used TransforMiiX and provided feedback that has been -beneficial to the development. -
(appearing in alphabetical order) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameCompany
Bailey, Jeff
Brown, William Lewis
Le Bouil, ThierryLucent Technologies, Inc.
Schefer, Marc
Tinney, SteveUniversity of Pennsylvania
Wang, Jiwei
- - Zwischenbrugger, Bernhard -
- - - -


- -The MITRE Corporation, Keith Visco (C) Copyright 1999-2000, All rights reserved
-Email:kvisco@ziplink.net -
- -
- - diff --git a/extensions/transformiix/docs/optimized-stylesheets.html b/extensions/transformiix/docs/optimized-stylesheets.html deleted file mode 100644 index 7fa07b8ce1c8..000000000000 --- a/extensions/transformiix/docs/optimized-stylesheets.html +++ /dev/null @@ -1,199 +0,0 @@ - - - Optimizing Stylesheets - - - - -

Optimizing Stylesheets

- -

Overview

-

- This document outlines optimizations that we can perform on - stylesheets after a stylesheet is compiled, but before it is executed. -

- - -

Create AVTs out of xsl:attributes

-

- People often write stylesheets like -

-<LRE>
-  <xsl:attribute name="foo">
-    text here
-    <xsl:value-of select="@bar"/>
-  </xsl:attribute>
-
- This could be optimized into an AVT like -
-<LRE foo="text here{@foo}">
-
- This can be done both in templates and in attribute-sets -

- - -

Investigate how RTFs are being used

-

- When only the string-value or double-value of an RTF is being used it - is unneccesary to create an entire RTF. Instead we could set up a - string-handler and use the resulting string. -

- -

- Once we have a node-set() function we could also have a special - handler that creates that resulting nodeset rather then - whatever-we-create-once-we-have-real-RTFs. That handler would be set - up when we can determain that a RTF is used only as argument to the - node-set() function. -

- -

- In cases where an RTF is used as parameter in a call to another - template we could do further analysis to see how that parameter is - used in that template. Either by first analyzing how all template - parameters are used in all templates, or by recursivly searching - the called template when we find that a RTF is used as an argument. -

- -

- We will still need a catch-all RTF implementation that is used when - we can't determin how a variable is used, or when it is used in - multiple different ways. -

- - -

Inline/calculate constant variables

-

- Variables that does not have a value that depends on the source - document can be inlined into the stylesheet. The value of these - variables could also be calculated before the transformation is - started. -

- -

- This can be combined with the previous optimization of RTFs so that - stylesheets like -

-<xsl:variable name="v">_</xsl:variable>
-...
-<xsl:value-of select="concat(@id, $v, foo)"/>
-
- is executed like -
-<xsl:value-of select="concat(@id, '_', foo)"/>
-
-

- -

- This can be done for both global and local variables. -

- - -

Resolve cross-references

-

- Cross-references to named templates, attribute-sets and template-modes - can be resolved before the stylesheet is executed. That way we don't - have to search for the template/attribute-set with a certain name, or - the group of templates for a certain mode. -

- -

- Note that for apply-imports we won't always know at compile-time which - mode to seach for templates in. -

- - -

Resolve variables by index rather then expanded name

-

- Rather then seaching for variables with a certain name at runtime - we could remove names for variables/parameters entierly and put all - variables in an array (possibly a separate array for global variables) - and then let variable-references in expressions just point to an index - in that array. -

- - -

Calculate and use constant AVTs

-

- A lot of instruction-elements uses AVTs that often are constants in - stylesheets, such as the data-type parameter to xsl:sort. For xsl:sort - we could pre-create a finished nodesorter if all AVTs in all - xsl:sort-elements are constant. -

- -

- Another example is xsl:element and xsl:attribute where we could use - LRE-instructions if the AVTs are constant. For xsl:number we could - create prepare the list of txFormattedCounters. -

- - -

Reuse parameter-map if exact same parameters are used

-

- If a template calls another template and uses the exact same - parameters we can reuse the same parameter-map. -

-<xsl:template name="hsbc_html_body">
-  <xsl:param name="appName"/>
-  <xsl:param name="title"/>
-  <body>
-    <xsl:call-template name="hsbc_form">
-      <xsl:with-param name="appName" select="$appName"/>
-      <xsl:with-param name="title" select="$title"/>
-    </xsl:call-template>
-  </body>
-</xsl:template>
-
-

- -

- We have to watch out for default parameter-values as well as - parameters being specified by the caller of this template but not used - by this template. I.e. if the parameter "hello" is specified when - calling the above template. -

- -

- All this might make this optimization useless. -

- -

Combind consecutive LRE items into a txResultBuffer

-

- When a template contains several consecutive "LRE instructions" such - as LRE-elements, LRE-attributes and textnodes we can replace their - instructions with a special instruction that contains a - txResultBuffer. This buffer would then be flushed when - the instruction is executed. This can of course not be done for - LRE-attributes that contains AVTs. Even PI and comment-instructions - can be included in this buffer if their contents is strictly literal. -

- -

- The result is that a template like -

-<xsl:template match="/">
-  <html>
-    <body bgcolor="green">
-      Here goes pagecontent
-      <xsl:apply-templates />
-    </body>
-  </html>
-</xsl:template>
-
- Would result in the first txResultBuffer to contain the - following transactions: eStartElementTransaction, - eStartElementTransaction, eAttributeTransaction, eCharacterTransaction. -

- -

- There is probably a lower limit to when it's worth the effort to - replace the normal instructions with the buffer-instruction. A single - "LRE instruction" is probobably better kept as a normal instruction. -

- - - diff --git a/extensions/transformiix/docs/optimized-xpath.html b/extensions/transformiix/docs/optimized-xpath.html deleted file mode 100644 index 5885e789ae52..000000000000 --- a/extensions/transformiix/docs/optimized-xpath.html +++ /dev/null @@ -1,523 +0,0 @@ - - - Optimizing XPath - - - - -

Optimizing XPath

- -

Overview

-

- This document outlines optimizations that we can perform to execute - xpath-expressions faster. -

- -

Stage 1, DONE

- -

Summary

-

- Speed up retrieval of orderInfo objects by storing them in resp. - node instead of in a hash. -

- -

Details

-

- We currently spend a GREAT deal of time looking through a - DOMHelper::orders hash looking for the orderInfo object for a - specific node. If we moved the ownership and retrieval of these - orderInfo objects to the Node class instead we will probably save - a lot of time. I.E. instead of calling - myDOMHelper->getDocumentOrder(node) you call - node->getDocumentOrder() which then returns the - orderInfo object. -

- -

- It would also be nice if we at the same time fixed some bugs wrt the - orderInfo objects and the function that sorts nodes using them. -

- -

- Bugs filed at this are 88964 and 94471 -

- - - -

Stage 2, DONE

- - -

Summary

-

- Speed up document-order sorting by having the XPath engine always - return document-ordered nodesets. -

- -

Details

-

- Currently the nodesets returned from the XPath engine are totally - unordered (or rather, have undefined order) which forces the XSLT - code to sort the nodesets. This is quite expensive since it requires - us to generate orderInfo objects for every node. Considering that - many XPath classes actually returns nodesets that are already - ordered in document order (or reversed document order) this seems a - bit unnecessary. -

- -

- However we still need to handle the classes that don't by default - return document-ordered nodesets. A good example of this is the id() - function. For example "id('foo bar')" produces two nodes which the - id-function has no idea how they relate in terms of document order. - Another example is "foo | bar", where the UnionExpr object gets two - nodesets (ordered in document order since all XPath classes should - now return ordered nodesets) and need to merge them into a single - ordered nodeset. -

- -

Stage 3, DONE

- -

Summary

-

- Refcount ExprResults to reduce the number of objects - created during evaluation. -

- -

Details

-

- Right now every subexpression creates a new object during evaluation. - If we refcounted objects we would be often be able to reuse the same - objects across multiple evaluations. We should also keep global - result-objects for true and false, that way expressions that return - bool-values would never have to create any objects. -

- -

- This does however require that the returned objects arn't modified - since they might be used elsewhere. This is not a big problem in the - current code where we pretty much only modify nodesets in a couple - of places. -

- -

- To be able to reuse objects across subexpressions we chould have an - ExprResult::ensureModifyable-function. This would - return the same object if the refcount is 1, and create a new object - to return otherwise. This is especially usefull for nodesets which - would be mostly used by a single object at a time. But it could be - just as usefull for other types, though then we might need a - ExprResult::ensureModifyableOfType(ExprResult::ResultType)-function - that only returned itself if it has a refcount of 1 and is of the - requsted type. -

- -

Stage 4

- -

Summary

-

- Speed up evaluation of XPath expressions by using specialized - classes for common optimizable expressions. -

- -

Details

-

- Some common expressions are possible to execute faster if we have - classes that are specialized for them. For example the expression - "@foo" can be evaluated by simply calling |context->getAttributeNode - ("foo")|, instead we now walk all attributes of the context node and - filter each node using a AttributeExpr. Below is a list of - expressions that I can think of that are optimizable, but there are - probably more. -

- -

- One thing that we IMHO should keep in mind is to only put effort on - optimising expressions that are actually used in realworld - stylesheets. For example "foo | foo", "foo | bar[0]" and - "foo[position()]" can all be optimised to "foo", but since noone - should be so stupid as to write such an expression we shouldn't - spend time or codesize on that. Of course we should return the - correct result according to spec for those expressions, we just - shouldn't bother with evaluating them fast. -

- - -

- Apart from finding expression that we can evaluate more cleverly - there is also the problem of how and where do we create these - optimised objects instead of the unoptimised, general ones we create - now. And what are these optimised classes, should they be normal - Expr classes or should they be something else? We could also add - "optional" methods to Expr which have default implementations in - Expr, for example a ::isContextSensitive() which returns MB_TRUE - unless overridden. However we probably can't answer all this until - we know which expressions we want to optimised and how we want to - optimise them. -

- -

- These expressions can be optimised: -

- -

Use case 1

-

Class:

- Steps along the attribute axis which doesn't contain wildcards -

Example:

- @foo -

What we do today:

- Walk through the attributes NamedNodeMap and filter each node using a - NameTest. -

What we could do:

- Call getAttributeNode (or actually getAttributeNodeNS) on the - contextnode and return a nodeset containing just the returned node, or - an empty nodeset if NULL is returned. -

- -

Use case 2

-

Class:

- Union expressions where each expression consists of a LocationStep and - all LocationSteps have the same axis. None of the LocationSteps have any - predicates (well, this could be relaxed a bit) -

Example:

- foo | bar | baz -

What we do today:

- Evaluate each LocationStep separately and thus walk the same path through - the document each time. During the walking the NodeTest is applied to - filter out the correct nodes. The resulting nodesets are then merged and - thus we generate orderInfo objects for most nodes. -

What we could do:

- Have just one LocationStep object which contains a NodeTest that is a - "UnionNodeTest" which contains a list of NodeTests. The UnionNodeTest - then tests each NodeTest until it finds one that returns true. If none - do then false is returned. - This results in just one walk along the axis and no need to generate any - orderInfo objects. -

- -

Use case 3

-

Class:

- Steps where the predicates isn't context-node-list sensitive. -

Example:

- foo[@bar] -

What we do today:

- Build a nodeset of all nodes that match 'foo' and then filter the - nodeset through the predicate and thus do some node shuffling. -

What we could do:

- Create a "PredicatedNodeTest" that contains a NodeTest and a list of - predicates. The PredicatedNodeTest returns true if both the NodeTest - returns true and all predicats evaluate to true. Then let the - LocationStep have that PredicateNodeTest as NodeTest and no predicates. - This will save us the predicate filtering and thus some node shuffling. - (Note how this combines nicely with the previous optimisation...) - (Actually this can be done even if some predicates are context-list - sensitive, but only up until the first that isn't.) -

- -

Use case 4

-

Class:

- PathExprs that only contains steps that from the child:: and attribute:: - axes. -

Example:

- foo/bar/baz -

What we do today:

- For each step we evaluate the step once for every node in a nodeset - (for example for the second step the nodeset is the list of all "foo" - children) and then merge the resulting nodesets while making sure that - we keep the nodes in document order (and thus generate orderInfo - objects). -

What we could do:

- The same thing except that we don't merge the resulting nodeset, but - rather just concatenate them. We always know that the resulting nodesets - are after each other in node order. -

- -

Use case 5

-

Class:

- List of predicates where some predicate are not context-list sensitive -

Example:

- foo[position() > 3][@bar][.//baz][position() > size() div 2][.//@fud] -

What we do today:

- Apply each predicate separately requiring us to shuffle nodes five times - in the above example. -

What we could do:

- Merge all predicates that are not node context-list sensitive into the - previous predicate. The above predicate list could be merged into the - following predicate list - foo[(position() > 3) and (@bar) and (.//baz)][(position() > size() div 2) and (.//@fud)] - Which only requires two node-shuffles -

- -

Use case 6

-

Class:

- Predicates that are only context-list-position sensitive and not - context-list-size sensitive -

Example:

- foo[position() > 5][position() mod 2] -

What we do today:

- Build the entire list of nodes that matches "foo" and then apply the - predicates -

What we could do:

- Apply the predicates during the initial build of the first nodeset. We - would have to keep track of how many nodes has passed each and somehow - override the code that calculates the context-list-position. -

- -

Use case 7

-

Class:

- Predicates that are constants -

Example:

- foo[5] -

What we do today:

- Perform the appropriate walk and build the entire nodeset. Then apply - the predicate. -

What we could do:

- There are three types of constant results; 1) Numerical values 2) - Results with a true boolean-value 3) Results with a false boolean value. - In the case of 1) we should only step up until the n:th node (5 in above - example) and then stop. For 2) we should completely ignore the predicate - and for 3) we should return an empty nodeset without doing any walking. - In some cases we can't at parsetime decide if a constant expression will - return a numerical or not, for example for "foo[$pos]", so the decision - of 1) 2) or 3) would have to be made at evaltime. However we should be - able to decide if it's a constant or not at parsetime. - Note that while evaluating a LocationStep [//foo] can be considered - constant. -

- -

Use case 8

-

Class:

- PathExprs that contains '//' followed by an unpredicated child-step. -

Example:

- .//bar -

What we do today:

- We walk the entire subtree below the contextnode and at every node we - evaluate the 'bar'-expression which walks all the children of the - contextnode. This means that we'll walk the entire subtree twice. -

What we could do:

- Change the expression into "./descendant::bar". This means that we'll - only walk the tree once. This can only be done if there are no - predicates since the context-node-list will be different for - predicates in the new expression. - Note that this combines nicely with the "Steps where the predicates - isn't context-node-list sensitive" optimization. -

- -

Use case 9

-

Class:

- PathExprs where the first step is '.' -

Example:

- ./* -

What we do today:

- Evaluate the step "." which always returns the same node and then - evaluate the rest of the PathExpr. -

What we could do:

- Remove the '.'-step and simply evaluate the other steps. In the example - we could even remove the entire PathExpr-object and replace it with a - single Step-object. -

- -

Use case 10

-

Class:

- Steps along the attribute axis which doesn't contain wildcards and - we only care about the boolean value. -

Example:

- foo[@bar], @foo or @bar -

What we do today:

- Evaluate the step and create a nodeset. Then get the bool-value of - the nodeset by checking if the nodeset contain any nodes. -

What we could do:

- Simply check if the current element has an attribute of the - requested name and return a bool-result. -

- -

Use case 11

-

Class:

- Unpredicated steps where we only care about the boolean value. -

Example:

- foo[processing-instruction()] -

What we do today:

- Evaluate the step and create a nodeset. Then get the bool-value of - the nodeset by checking if the nodeset contain any nodes. -

What we could do:

- Walk along the axis until we find a node that matches the nodetest. - If one is found we can stop the walking and return a true - bool-result immediatly, otherwise a false bool-result is returned. - It might not be worth implementing all axes unless we can reuse - code from the normal Step-code. This could also be applied to - PathExprs by getting the boolvalue of the last step. -

- -

Use case 12

-

Class:

- Unpredicated steps where we only care about the string-value. -

Example:

- starts-with(processing-instruction(), 'hello') -

What we do today:

- Evaluate the step and create a nodeset. Then get the string-value of - the nodeset by getting the stringvalue of the first node. -

What we could do:

- Walk along the axis until we find a node that matches the nodetest. - If one is found we can stop the walking and return a string-result - containing the value of that node. Otherwise an empty string-result - can be returned.
- This can also be done when we only care about the number-value.
- This could be combined with the "Unpredicated steps where we only - care about the boolean value" optimization by instead of returning - a bool-value or string-value return a nodeset containing just the - found node. If that is done this optimization could be applied to - PathExprs. -

- -

Use case 13

-

Class:

- Expressions where the value of an attribute is compared to - a literal. -

Example:

- @bar = 'value' -

What we do today:

- Evaluate the attribute-step and then compare the resulting nodeset - to the value. -

What we could do:

- Get the attribute-value for the element and compare that directly - to the value. In the above example we would just call - getAttr('bar', kNameSpaceID_None) and compare the - resulting string with 'value'. -

- -

Use case 14

-

Class:

- PathExprs where the last step has a predicate that is not - context-nodeset dependent and that contains a part that is not - context-node dependent. -

Example:

- foo/*[@bar = current()/@bar] -

What we do today:

-

What we could do:

- First evaluate "foo/*" and "current()/@bar". Then replace - "current()/@bar" with a literal (and possibly optimize) and filter - all nodes in the nodeset from "foo/*". -

- -

Use case 15

-

Class:

- local-name() or namespace-uri() compared to a literal -

Example:

- local-name() = 'foo' -

What we do today:

- evaluate the local-name function and compare the string-result to - the string-result of the literal. -

What we could do:

- Atomize the literal (or get the namespaceID in case of - namespace-uri()) and then compare that to the atom-name of the - contextnode. This is primarily usefull when combined with the - previous class. -

- -

Use case 16

-

Class:

- Comparisons where one side is a nodeset and the other is not a - bool-value. -

Example:

- //myElem = @baz -

What we do today:

- Evaluate both sides and then compare them according to the spec. -

What we could do:

- First of all we should start by evaluating the nodeset-side, if the - result is an empty nodeset false can be returned immediatly. - Otherwise we evaluate as normal. When both sides are nodesets we - should examine them and try to figure out which is faster to - evaluate. That expression should be evaluated first (probably - by making it the left-hand-side expression). -

- -

Use case 17

-

Class:

- Comparisons where one side is a PathExpr and the other is a - bool-value. -

Example:

- baz = ($foo > $bar) -

What we do today:

- Evaluate both sides and then compare them. -

What we could do:

- Apply the "Steps where we only care about the boolean - value"-optimization on the PathExpr-side and then evaluate as usual. -

- -

Use case 18

-

Class:

- Subexpressions that will be evaluated more then once where the only - change is in context it doesn't depend on -

Example:

- foo[@bar = sum($var/@bar)] -

What we do today:

- Reevaluate the subexpression every time we need it and every time - get the same result. -

What we could do:

- We should save the result from the first evaluation and just bring - it back the following time we need it. This can be done by - inserting an extra expression between the subexpression and its - parent, this expression would then first go look in a cache - available through the nsIEvalContext, if the value - isn't available there the original expression is evaluated and its - result is saved in the cache. The cache can be keyed on an integer - which is stored in the inserted 'cache-expression'.
- The cache itself could be created by another expression that is - inserted at the top of the expression. This way that expression - works as a boundry-point for the cache and can in theory be - inserted anywhere in an expression if needed. -

- -

Stage 5

- -

Summary

-

- Detect when we can concatenate nodesets instead of merge them in - PathExpr. -

- -

Details

-

- Why can we for expressions like "foo/bar/baz" concatenate the resulting - nodesets without having to check nodeorder? Because at every step two - statements are true: -

    -
  1. We iterate a nodeset where no node is an ancestor of another
  2. -
  3. The LocationStep only returns nodes that are members of the subtree - below the context-node
  4. -
-

- -

- For example; While evaluating the second step in "foo/bar/baz" we - iterate a nodelist containing all "foo" children of the original - contextnode, i.e. none can be an ancestor of another. And the - LocationStep "bar" only returns children of the contextnode. -

- -

- So, it would be nice if we can detect when this occurs as often as - possible. For example the expression "id(foo)/bar/baz" fulfils those - requirements if the nodeset returned from contains doesn't contain any - ancestors of other nodes in the nodeset, which probably often is the - case in real-world stylesheets. -

- -

- We should perform this check on every step to be able to take advantage - of it as often as possible. For example the in expression - "id(@boss)/ancestor::team/members" we can't use this optimisation at the - second step since the ancestor axis returns nodes that are not members - of the contextnodes subtree. However we will probably be able to use the - optimisation at the third step since if iterated nodeset contains only - one node (and thus can't contain ancestors of it's members). -

- - diff --git a/extensions/transformiix/docs/readme.html b/extensions/transformiix/docs/readme.html deleted file mode 100644 index 4cbc8f66c1a3..000000000000 --- a/extensions/transformiix/docs/readme.html +++ /dev/null @@ -1,172 +0,0 @@ - - -TransforMiiX(tm) - - - - - - - - - - - - - -
- MITRE - - TransforMiiX - TM -

- - -
-
-

-TransforMiiX is an XSLT processor which is -not yet complete, but supports a good portion of the -XSLT 1.0 recommendation. - -

-TransforMiiX was designed to be a "standalone" -XSLT processor. This means you can call the processor from the command line, -or via the XSLProcessor API. The only thing TransforMiiX requires is an XML parser, -and the currently supported parser is -Expat written by James Clark. -

-

-There is currently an effort undergoing to integrate -TransforMiiX with Mozilla. This effort -is not yet complete and therefor the XSLT processor cannot yet be used -within the Mozilla browser. Integration is nearing completion, however. -

-

-


-

-Running TransforMiiX from the command line -

-The command line syntax is pretty straight forward: -

-example: transfrmx -i my.xml -s my.xsl -o my.out -

-This will process the XML source file called "my.xml" using the "my.xsl" XSLT stylesheet, -and the result will be placed in "my.out". - -The "-s" flag is not required if the XSLT stylesheet is specified inside the XML source -document using the "xml-stylesheet" PI (processing instruction). -

-The stylesheet PI, should appear below the XML declaration -("<?xml version="1.0"?>"). -

-example: - - - - -
-
-
-<?xml version="1.0"?>
-<?xml-stylesheet href="my.xsl" type="text/xsl"?>
-<document>
-   ...
-</document>
-    
-
- -

-The command line program is in "source/main/transformiix.cpp" and is simply -a wrapper for "source/xsl/XSLProcessor.cpp" which is the TransforMiiX API. -

-

-Feel free to run the examples in the "source/examples" directory, they are a -good example of what has been implemented so far in TransforMiiX. -

- -


-

-What is the current status of TransforMiiX? -

-You can check the current status by looking three main files: -

-

-


-

-What can I do to help finish the implementation of - TransforMiiX? -

-There are a number of things that can be done: -

-Development -

    -
  1. Check out the source code, build it. -
  2. Use it. -
  3. Familiarize yourself with the code. -
  4. Look at the the "to-do" or "known issues" list and choose something -that you would like to work on. -
  5. If it's a large task, notify us that you are working on a task or issue, or -would like to contribute to the existing effort of a specific task. -
    -If it's a simple change you may contact us first to make sure -you are not duplicating effort, or feel free to just make the changes. -
  6. If you have CVS commit status, commit your code, -otherwise submit your code to be integrated to us. -
    - - -Please do a "cvs update" to make sure you have the latest changes, and that -your changes work with any code changes that might have occured during -your development. - - -
- -Bug Reporting -
    -
  1. Check out the source code, build it. -
  2. Use it. -
  3. Submit any bugs to the - -mailing list [netscape.public.mozilla.layout.xslt] - or directly to us. -
- -Documentation -
    -
  1. Check out the source code, build it. -
  2. Use it. -
  3. Find something that's not documented - pretty easy to do at this point. -
  4. Document #3. -
  5. If you have commit status, commit your documentation, otherwise -submit your documentation directly to us. -
-

- -Miscellaneous (but important)
- -- I just wouldn't be myself if I didn't add these! -- Keith :-) -

    -
  1. Get me a date with Claudia Schiffer or Kelly Hu. -
  2. Get me some coffee! -
-

- - - -


- -The MITRE Corporation, Keith Visco (C) Copyright 1999, All rights reserved
-Email: Keith Visco, -Tom Kneeland -
- -
- - diff --git a/extensions/transformiix/resources/Makefile.in b/extensions/transformiix/resources/Makefile.in deleted file mode 100644 index 3bdeaf8a408f..000000000000 --- a/extensions/transformiix/resources/Makefile.in +++ /dev/null @@ -1,45 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2002 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -include $(topsrcdir)/config/rules.mk diff --git a/extensions/transformiix/resources/XSLTMark/XSLTMark-static.js b/extensions/transformiix/resources/XSLTMark/XSLTMark-static.js deleted file mode 100644 index e6a43cae6cbb..000000000000 --- a/extensions/transformiix/resources/XSLTMark/XSLTMark-static.js +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const enablePrivilege = netscape.security.PrivilegeManager.enablePrivilege; -const IOSERVICE_CTRID = "@mozilla.org/network/io-service;1"; -const nsIIOService = Components.interfaces.nsIIOService; -const SIS_CTRID = "@mozilla.org/scriptableinputstream;1"; -const nsISIS = Components.interfaces.nsIScriptableInputStream; -const nsIFilePicker = Components.interfaces.nsIFilePicker; -const STDURL_CTRID = "@mozilla.org/network/standard-url;1"; -const nsIURI = Components.interfaces.nsIURI; - -var gStop = false; - -function loadFile(aUriSpec) -{ - enablePrivilege('UniversalXPConnect'); - var serv = Components.classes[IOSERVICE_CTRID]. - getService(nsIIOService); - if (!serv) { - throw Components.results.ERR_FAILURE; - } - var chan = serv.newChannel(aUriSpec, null, null); - var instream = - Components.classes[SIS_CTRID].createInstance(nsISIS); - instream.init(chan.open()); - - return instream.read(instream.available()); -} - -function dump20(aVal) -{ - const pads = ' '; - if (typeof(aVal)=='string') - out = aVal; - else if (typeof(aVal)=='number') - out = Number(aVal).toFixed(2); - else - out = new String(aVal); - dump(pads.substring(0, 20 - out.length)); - dump(out); -} diff --git a/extensions/transformiix/resources/XSLTMark/XSLTMark-test.js b/extensions/transformiix/resources/XSLTMark/XSLTMark-test.js deleted file mode 100644 index 47eb058e7099..000000000000 --- a/extensions/transformiix/resources/XSLTMark/XSLTMark-test.js +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var gParser = new DOMParser; -var gProc = new XSLTProcessor; -var gTimeout; - -function Test(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) -{ - this.mTitle = aTitle; - this.mObserver = aObserver; - this.mTotal = aNumber; - this.mDone = 0; - var xmlcontent = loadFile(aSourceURL); - var xslcontent = loadFile(aStyleURL); - this.mSource = gParser.parseFromString(xmlcontent, 'application/xml'); - this.mStyle = gParser.parseFromString(xslcontent, 'application/xml'); -} - -function runTest(aTitle, aSourceURL, aStyleURL, aNumber, aObserver) -{ - test = new Test(aTitle, aSourceURL, aStyleURL, aNumber, - aObserver); - gTimeout = setTimeout(onNextTransform, 100, test, 0); -} - -function onNextTransform(aTest, aNumber) -{ - res = document.implementation.createDocument('', '', null); - var startTime = Date.now(); - gProc.transformDocument(aTest.mSource, aTest.mStyle, res, null); - var endTime = Date.now(); - aNumber++; - var progress = aNumber / aTest.mTotal * 100; - if (aTest.mObserver) { - aTest.mObserver.progress(aTest.mTitle, endTime - startTime, - progress); - } - if (aNumber < aTest.mTotal) { - gTimeout = setTimeout(onNextTransform, 100, aTest, aNumber); - } else if (aTest.mObserver) { - aTest.mObserver.done(aTest.mTitle); - } -} diff --git a/extensions/transformiix/resources/XSLTMark/XSLTMark-view.js b/extensions/transformiix/resources/XSLTMark/XSLTMark-view.js deleted file mode 100644 index 00096efea347..000000000000 --- a/extensions/transformiix/resources/XSLTMark/XSLTMark-view.js +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var view = -{ - configUrl: null, - testArray: null, - mCurrent: null, - - browseForConfig: function() - { - enablePrivilege('UniversalXPConnect'); - var fp = Components.classes["@mozilla.org/filepicker;1"]. - createInstance(nsIFilePicker); - fp.init(window,'XSLTMark Description File',nsIFilePicker.modeOpen); - fp.appendFilter('*.conf', '*.conf'); - fp.appendFilters(nsIFilePicker.filterAll); - var res = fp.show(); - - if (res == nsIFilePicker.returnOK) { - this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); - this.configUrl.spec = fp.fileURL.spec; - document.getElementById('config').setAttribute('value', this.configUrl.spec); - } - this.parseConfig(); - return true; - }, - - parseConfig: function() - { - this.testArray = new Array(); - var test; - if (!this.configUrl) { - return; - } - - var content = loadFile(this.configUrl.spec); - - var lines = content.split("\n"); - var line, res; - var head = /^\[(.+)\]$/; - var instruct = /^(.+)=(.+)$/; - while (lines.length) { - line = lines.shift(); - if (head.test(line)) { - test = new Object; - res = head.exec(line); - test['title'] = res[1]; - this.testArray.push(test); - } - else if (line == '') { - test = undefined; - } - else { - res = instruct.exec(line); - test[res[1]] = res[2]; - } - } - }, - - onLoad: function() - { - this.mCurrentStatus = document.getElementById('currentStatus'); - this.mCurrentProgress = document.getElementById('currentProgress'); - this.mTotalProgress = document.getElementById('totalProgress'); - this.mOutput = document.getElementById('transformOutput'); - this.mDetailOutput = - document.getElementById('transformDetailedOutput'); - this.mDetail = true; - }, - - progress: function(aTitle, aTime, aProgress) - { - // dump20(aTitle); - // dump20(aTime); - // dump20(aProgress); - this.mCurrentProgress.value = aProgress; - this.displayDetailTime(aTime); - this.mTimes.push(aTime); - // dump("\n"); - }, - - done: function(aTitle) - { - // dump(aTitle + " is finished.\n"); - this.mCurrent++; - this.mCurrentProgress.value = 0; - this.displayTotalTime(); - if (this.mCurrent >= this.testArray.length) { - this.mTotalProgress.value = 0; - this.mCurrentStatus.value = "done"; - return; - } - this.mTotalProgress.value = this.mCurrent*100/this.testArray.length; - var test = this.testArray[this.mCurrent]; - enablePrivilege('UniversalXPConnect'); - this.displayTest(test.title); - runTest(test.title, this.configUrl.resolve(test.input), - this.configUrl.resolve(test.stylesheet), - test.iterations, this); - }, - - onStop: function() - { - clearTimeout(gTimeout); - this.mCurrentProgress.value = 0; - this.mTotalProgress.value = 0; - this.mCurrentStatus.value = "stopped"; - }, - - displayTest: function(aTitle) - { - this.mTimes = new Array; - aTitle += "\t"; - this.mCurrentStatus.value = aTitle; - this.mOutput.value += aTitle; - if (this.mDetail) { - this.mDetailOutput.value += aTitle; - } - }, - - displayDetailTime: function(aTime) - { - if (this.mDetail) { - this.mDetailOutput.value += aTime + " ms\t"; - } - }, - - displayTotalTime: function() - { - var sum = 0; - for (k = 0; k < this.mTimes.length; k++) { - sum += this.mTimes[k]; - } - var mean = sum / this.mTimes.length; - this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t"; - var variance = 0; - for (k = 0; k < this.mTimes.length; k++) { - var n = this.mTimes[k] - mean; - variance += n*n; - } - variance = Math.sqrt(variance/this.mTimes.length); - this.mOutput.value += Number(variance).toFixed(2)+"\n"; - if (this.mDetail) { - this.mDetailOutput.value += "\n"; - } - }, - - runBenchmark: function() - { - enablePrivilege('UniversalXPConnect'); - if (!this.testArray) { - if (!this.configUrl) { - this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); - this.configUrl.spec = document.getElementById('config').value; - } - this.parseConfig(); - } - - this.mCurrent = 0; - var test = this.testArray[this.mCurrent]; - this.mOutput.value = ''; - if (this.mDetail) { - this.mDetailOutput.value = ''; - } - this.displayTest(test.title); - runTest(test.title, this.configUrl.resolve(test.input), - this.configUrl.resolve(test.stylesheet), - test.iterations, this); - return true; - } -} - diff --git a/extensions/transformiix/resources/XSLTMark/XSLTMark.css b/extensions/transformiix/resources/XSLTMark/XSLTMark.css deleted file mode 100644 index 80eb616fe13a..000000000000 --- a/extensions/transformiix/resources/XSLTMark/XSLTMark.css +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -textbox.out { - white-space: pre; -} diff --git a/extensions/transformiix/resources/XSLTMark/XSLTMark.xul b/extensions/transformiix/resources/XSLTMark/XSLTMark.xul deleted file mode 100644 index fdb2a5a2a55c..000000000000 --- a/extensions/transformiix/resources/XSLTMark/XSLTMark.xul +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - -
- - Mozilla XSLT - -
- TransforMiiX Test Cases -
-

This document serves to test basic XSL expressions.

-

- Testing xsl:variable and xsl:copy-of -
- Test:<xsl:copy-of select="$product-name"/>
- Desired Result:TransforMiiX
- Result:TransforMiiX

-

- Testing xsl:if -
- Test:<xsl:if test="x | y | z">true</xsl:if>
- Desired Result:true
- Result:true

-

- Testing xsl:if -
- Test:<xsl:if test="true()">true</xsl:if>
- Desired Result:true
- Result:true

-

- Testing xsl:if -
- Test:<xsl:if test="'a'='b'">a equals b</xsl:if>
- <xsl:if test="'a'!='b'">a does not equal b</xsl:if>
- Desired Result:a does not equal to b
- Result:a does not equal b

-

- Testing xsl:if -
- Test:<xsl:if test="2+1-3">2+1-3 is true</xsl:if>
-  <xsl:if test="not(2+1-3)">not(2+1-3) is true</xsl:if>
- Desired Result:not(2+1-3) is true
- Result:not(2+1-3) is true

-

- Testing xsl:choose -
- Test:see source
- Desired Result:true
- Result:true

-

- Testing parent and ancestor ops -
- Test:see source
- Desired Result:true
- Result:true
-

-

- Testing basic xsl:apply-templates -
- Test:<xsl:apply-templates/>
- Desired Result:element x, element y, element z
- Result: - - ,element x - ,element y - ,element z - - -

-

- Testing basic xsl:apply-templates with mode -
- Test:<xsl:apply-templates mode="mode-test"/>
- Desired Result:x, y, z
- Result:, x, y, z

-

- Testing predicates -
- Test:see source
- Desired Result: - z -
- Result: - z -

-

- Testing predicates -
- Test:see source
- Desired Result: -
- Result: -

-

- Named Template/Call Template -

- Test:<xsl:call-template name="named-template-test"/>
- Desired Result:named template processed with default value!
- Result:named template processed with default value!

-

- Test:- passing arguments to named templates (see xsl source)
- Desired Result:named template processed with passed value!
- Result:named template processed with passed value!

-

-

- Attribute Value Templates and variables -
- Test: -

    <xsl:variable name="color">red</xsl:variable>
    <FONT COLOR="{$color}">Red Text</FONT>
- Desired Result: - Red Text -
- Result: - Red Text -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Axis Identifiers (these should work, I need more test cases though) -
- Test: - <xsl:if test="descendant::z">true</xsl:if>
-
- Desired Result: - - true -
-
- Result: - - true -
- Test: - <xsl:if test="not(descendant-or-self::no-element)">true</xsl:if>
-
- Desired Result: - - true -
-
- Result: - - true -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Creating Elements with xsl:element and xsl:attribute -
- Test: - <xsl:element name="FONT">
<xsl:attribute name="COLOR">blue</xsl:attribute>
Passed
</xsl:element>
- Desired Result: - - Passed -
-
- Result: - - Passed -
- Using Attribute Sets -
- Test: - <FONT xsl:use-attribute-sets="style1">
Passed
</FONT>
- Desired Result: - - Passed -
-
- Result: - - Passed -
- Test: - <xsl:element name="FONT" use-attribute-sets="style1 style2">
Passed
</xsl:element>
- Desired Result: - - Passed -
-
- Result: - - Passed -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Numbering (only simple numbering currently implemented) -
- Test: - <xsl:number value="4"/>
-
- Desired Result: - - 4 -
-
- Result: - - 4 -
- Test: - see source
-
- Desired Result: - - 1. x
1. y
1. z
-
-
- Result: - - 1. x
1. y
1. z
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Additive Expressions -
- Test: - <xsl:value-of select="70+4"/>
-
- Desired Result: - - 74 -
-
- Result: - - 74 -
- Test: - <xsl:value-of select="-70+4"/>
-
- Desired Result: - - -66 -
-
- Result: - - -66 -
- Test: - <xsl:value-of select="1900+70+8-4"/>
-
- Desired Result: - - 1974 -
-
- Result: - - 1974 -
- Test: - <xsl:value-of select="(4+5)-(9+9)"/>
-
- Desired Result: - - -9 -
-
- Result: - - -9 -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Multiplicative Expressions -
- Test: - <xsl:value-of select="7*4"/>
-
- Desired Result: - - 28 -
-
- Result: - - 28 -
- Test: - <xsl:value-of select="7mod4"/>
-
- Desired Result: - - 3 -
-
- Result: - - 3 -
- Test: - <xsl:value-of select="7div4"/>
-
- Desired Result: - - 1.75 -
-
- Result: - - 1.75 -
- Test: - <xsl:value-of select="7div0"/>
-
- Desired Result: - - Infinity -
-
- Result: - - Infinity -
- Test: - <xsl:value-of select="0 div 0"/>
-
- Desired Result: - - NaN -
-
- Result: - - NaN -
- Test: - <xsl:variable name="x" select="7*3"/>
<xsl:variable name="y" select="3"/>
<xsl:value-of select="$x div $y"/>
-
- Desired Result: - - 7 -
-
- Result: - - 7
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Precedence tests -
- Test: - <xsl:value-of select="2 mod 2 = 0"/>
-
- Desired Result: - - true -
-
- Result: - - true -
- Test: - <xsl:value-of select="5 mod 2<5 and 2*6>= 12"/>
-
- Desired Result: - - true -
-
- Result: - - true -
- Test: - <xsl:value-of select="5 mod 2<5 and 2*6>12"/>
-
- Desired Result: - - false -
-
- Result: - - false -
- Test: - <xsl:value-of select="4+5*3"/>
-
- Desired Result: - - 19 -
-
- Result: - - 19 -
- Test: - <xsl:value-of select="4+5*3+(6-4)*7"/>
-
- Desired Result: - - 33 -
-
- Result: - - 33 -
- - - - - - - - - - - - - - - - -
- Automatic Result Type Conversion -
- Test: - <xsl:value-of select="'747' + 8"/>
-
- Desired Result: - - 755 -
-
- Result: - - 755 -
- - diff --git a/extensions/transformiix/source/examples/test.xml b/extensions/transformiix/source/examples/test.xml deleted file mode 100644 index 12e53e278a30..000000000000 --- a/extensions/transformiix/source/examples/test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - x - y - z - - - def - - diff --git a/extensions/transformiix/source/examples/test.xsl b/extensions/transformiix/source/examples/test.xsl deleted file mode 100644 index 4b3b07a988d2..000000000000 --- a/extensions/transformiix/source/examples/test.xsl +++ /dev/null @@ -1,859 +0,0 @@ - - - - - - - - - - - - - blue - +0 - - - - red - +0 - - - - - - this is a test processing instruction - - TransforMiiX Test cases, written by Keith Visco. - - - - - - - named template processed with - ! - -
- - Error, undeclared parameters should be ignored! - -
-
- - - - - - - - - - TransforMiiX - - - - - - TransforMiiX Test Cases - - - -
- - Mozilla XSLT - -
- TransforMiiX Test Cases -
-

- This document serves to test basic XSL expressions. -

- -

- Testing xsl:variable and xsl:copy-of
- Test: <xsl:copy-of select="$product-name"/>
- Desired Result:TransforMiiX
- Result: -

- -

- Testing xsl:if
- Test: <xsl:if test="x | y | z">true</xsl:if>
- Desired Result: true
- Result: true -

- - -

- Testing xsl:if
- Test: <xsl:if test="true()">true</xsl:if>
- Desired Result: true
- Result: true -

- - -

- Testing xsl:if
- Test: <xsl:if test="'a'='b'">a equals b</xsl:if>
- <xsl:if test="'a'!='b'">a does not equal b</xsl:if> -
- Desired Result: a does not equal to b
- Result: - a equals b
- a does not equal b -

- - -

- Testing xsl:if
- Test: <xsl:if test="2+1-3"> 2+1-3 is true</xsl:if>
-  <xsl:if test="not(2+1-3)"> not(2+1-3) is true</xsl:if>
- Desired Result:not(2+1-3) is true
- Result: - 2+1-3 is true - not(2+1-3) is true -

- - -

- Testing xsl:choose
- Test:see source
- Desired Result: true
- Result: - - error - a - true - error - b - false - -

- -

- Testing parent and ancestor ops
- Test:see source
- Desired Result: true
- Result:true
- -

- - -

- Testing basic xsl:apply-templates
- Test:<xsl:apply-templates/>
- Desired Result:element x, element y, element z
- Result: -

- - -

- Testing basic xsl:apply-templates with mode
- Test:<xsl:apply-templates mode="mode-test"/>
- Desired Result:x, y, z
- Result: -

- -

- Testing predicates
- Test:see source
- Desired Result: z
- Result: - - - -

- -

- Testing predicates
- Test:see source
- Desired Result:
- Result: - - - -

- -

- Named Template/Call Template -

- Test:<xsl:call-template name="named-template-test"/>
- Desired Result:named template processed with default value!
- Result: -

-

- Test: - passing arguments to named templates (see xsl source)
- Desired Result:named template processed with passed value!
- Result: - - - - -

-

- -

- Attribute Value Templates and variables
- Test: -

    - <xsl:variable name="color">red</xsl:variable>
    - <FONT COLOR="{$color}">Red Text</FONT> -
- Desired Result: - Red Text
- Result: - red - Red Text -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Axis Identifiers (these should work, I need more test cases though) -
Test: - <xsl:if test="descendant::z">true</xsl:if>
-
Desired Result: - true
-
Result: - - true - -
Test: - <xsl:if test="not(descendant-or-self::no-element)">true</xsl:if>
-
Desired Result: - true
-
Result: - - true - -
Test: - <xsl:value-of select="count(x/attribute::*)"/>
-
Desired Result: - 1
-
Result: - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Creating Elements with xsl:element and xsl:attribute -
Test: - <xsl:element name="FONT">
- <xsl:attribute name="COLOR">blue</xsl:attribute>
- Passed
- </xsl:element> -
Desired Result: - Passed
-
Result: - - blue - Passed - -
Using Attribute Sets
Test: - <FONT xsl:use-attribute-sets="style1">
- Passed
- </FONT> -
Desired Result: - Passed
-
Result: - - Passed - -
Test: - <xsl:element name="FONT" use-attribute-sets="style1 style2">
- Passed
- </xsl:element> -
Desired Result: - Passed
-
Result: - - Passed - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Numbering (only simple numbering currently implemented) -
Test: - <xsl:number value="4"/>
-
Desired Result: - 4
-
Result: - -
Test: - see source
-
Desired Result: - - 1. x
1. y
1. z -

-
Result: - - - - .
-
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Additive Expressions -
Test: - <xsl:value-of select="70+4"/>
-
Desired Result: - 74
-
Result: - - - -
Test: - <xsl:value-of select="-70+4"/>
-
Desired Result: - -66
-
Result: - - - -
Test: - <xsl:value-of select="1900+70+8-4"/>
-
Desired Result: - 1974
-
Result: - - - -
Test: - <xsl:value-of select="(4+5)-(9+9)"/>
-
Desired Result: - -9
-
Result: - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Multiplicative Expressions -
Test: - <xsl:value-of select="7*4"/>
-
Desired Result: - 28
-
Result: - - - -
Test: - <xsl:value-of select="7mod 4"/>
-
Desired Result: - 3
-
Result: - - - -
Test: - <xsl:value-of select="7div 4"/>
-
Desired Result: - 1.75
-
Result: - - - -
Test: - <xsl:value-of select="7div 0"/>
-
Desired Result: - Infinity
-
Result: - - - -
Test: - <xsl:value-of select="0 div 0"/>
-
Desired Result: - NaN
-
Result: - - - -
Test: - <xsl:variable name="x" select="7*3"/>
- <xsl:variable name="y" select="3"/>
- <xsl:value-of select="$x div $y"/>
-
Desired Result: - 7
-
Result: - - - - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Precedence tests -
Test: - <xsl:value-of select="2 mod 2 = 0"/>
-
Desired Result: - true
-
Result: - - - -
Test: - <xsl:value-of select="5 mod 2 < 5 and 2*6 >= 12"/>
-
Desired Result: - true
-
Result: - - - -
Test: - <xsl:value-of select="5 mod 2 < 5 and 2*6>12"/>
-
Desired Result: - false
-
Result: - - - -
Test: - <xsl:value-of select="4+5*3"/>
-
Desired Result: - 19
-
Result: - - - -
Test: - <xsl:value-of select="4+5*3+(6-4)*7"/>
-
Desired Result: - 33
-
Result: - - - -
- - - - - - - - - - - - - - - - - - - -
- Automatic Result Type Conversion -
Test: - <xsl:value-of select="'747' + 8"/>
-
Desired Result: - 755
-
Result: - - - -
- - -
- - - - element - , - - - - - , - - - - element (z): - - -
- diff --git a/extensions/transformiix/source/examples/view-source.xsl b/extensions/transformiix/source/examples/view-source.xsl deleted file mode 100644 index 56fe55f57deb..000000000000 --- a/extensions/transformiix/source/examples/view-source.xsl +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - -]> - - - - - - - - View Source: - - - - - <?xml version="1.0"?>
-
- - - -
- - - - <!----> - - - - - - - < - > - - -
- - - - - - </ - - > -
-
- - - -   - ="" - - - - - <? ?>
-
- - -
- diff --git a/extensions/transformiix/source/lib/Makefile.in b/extensions/transformiix/source/lib/Makefile.in deleted file mode 100644 index 3af7d8cc15f1..000000000000 --- a/extensions/transformiix/source/lib/Makefile.in +++ /dev/null @@ -1,74 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -LIBRARY_NAME = tx -FORCE_STATIC_LIB = 1 -CPP_PROG_LINK = 1 -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - expat \ - $(NULL) - -SHARED_LIBRARY_LIBS = \ - $(DIST)/lib/$(LIB_PREFIX)txbase_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxml_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxmldom_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxmlparser_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxpath_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxslt_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxsltfunctions_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)txxsltutil_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)expat_s.$(LIB_SUFFIX) \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir)/../xslt -I$(srcdir)/../base -I$(srcdir)/../net \ - -I$(srcdir)/../xml -I$(srcdir)/../xml/dom \ - -I$(srcdir)/../xml/parser \ - -I$(srcdir)/../xpath -I$(srcdir)/../xslt/util \ - -I$(srcdir)/../xslt/functions $(MARK_INC) -DEFINES += -DXML_DTD -DXML_UNICODE diff --git a/extensions/transformiix/source/main/.cvsignore b/extensions/transformiix/source/main/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/main/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/main/Makefile.in b/extensions/transformiix/source/main/Makefile.in deleted file mode 100644 index 14c40655b86d..000000000000 --- a/extensions/transformiix/source/main/Makefile.in +++ /dev/null @@ -1,79 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOZILLA_INTERNAL_API = 1 -SIMPLE_PROGRAMS = transformiix$(BIN_SUFFIX) testXalan$(BIN_SUFFIX) \ - txTestExpr$(BIN_SUFFIX) -ifdef MARK_INC -SIMPLE_PROGRAMS += txXSLTMarkDriver$(BIN_SUFFIX) -endif - -REQUIRES = string \ - xpcom \ - expat \ - jprof \ - $(NULL) - -CPP_PROG_LINK = 1 - -EXTRA_DEPS = \ - $(DIST)/lib/$(LIB_PREFIX)tx.$(LIB_SUFFIX) \ - $(NULL) - -EXTRA_LIBS = \ - $(DIST)/lib/$(LIB_PREFIX)tx.$(LIB_SUFFIX) \ - $(MOZ_COMPONENT_LIBS) \ - $(NULL) - -ifdef MOZ_JPROF -LIBS += -ljprof -endif - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir)/../xslt -I$(srcdir)/../base -I$(srcdir)/../net \ - -I$(srcdir)/../xml -I$(srcdir)/../xml/dom \ - -I$(srcdir)/../xml/parser \ - -I$(srcdir)/../xpath -I$(srcdir)/../xslt/util \ - -I$(srcdir)/../xslt/functions $(MARK_INC) diff --git a/extensions/transformiix/source/main/testXalan.cpp b/extensions/transformiix/source/main/testXalan.cpp deleted file mode 100644 index f1ca1e2fb770..000000000000 --- a/extensions/transformiix/source/main/testXalan.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStandaloneXSLTProcessor.h" -#include "nsXPCOM.h" -#include -#include "nsDoubleHashtable.h" -#include "nsIComponentManager.h" -#include "nsILocalFile.h" -#include "nsISimpleEnumerator.h" -#include "nsString.h" -#include "nsVoidArray.h" -#include "prenv.h" -#include "prsystem.h" -#include "nsDirectoryServiceUtils.h" -#include "nsDirectoryServiceDefs.h" - -#ifdef NS_TRACE_MALLOC -#include "nsTraceMalloc.h" -#endif -#ifdef MOZ_JPROF -#include "jprof.h" -#endif - -/** - * Prints the command line help screen to the console - */ -void printHelp() -{ - cerr << "testXalan [-o output-file] [category]*" << endl << endl; - cerr << "Options:"; - cerr << endl << endl; - cerr << "\t-o specify output file (default: write to stdout)"; - cerr << endl << endl; - cerr << "\t Specify XALAN_DIR in your environement." << endl; - cerr << endl; -} - -/** - * Helper class to report success and failure to RDF - */ -class txRDFOut -{ -public: - explicit txRDFOut(ostream* aOut) - : mOut(aOut), mSuccess(0), mFail(0), mParent(nsnull) - { - } - explicit txRDFOut(const nsACString& aName, txRDFOut* aParent) - : mName(aName), mOut(aParent->mOut), mSuccess(0), mFail(0), - mParent(aParent) - { - } - ~txRDFOut() - { - *mOut << " \n" << - " " << - mSuccess << - "\n" << - " " << - mFail << - "\n" << - " " << endl; - } - - void feed(const nsACString& aTest, PRBool aSuccess) - { - *mOut << " \n"; - } - - void succeeded() - { - if (mParent) - mParent->succeeded(); - ++mSuccess; - } - void failed() - { - if (mParent) - mParent->failed(); - ++mFail; - } -private: - nsCAutoString mName; - ostream* mOut; - PRUint32 mSuccess, mFail; - txRDFOut* mParent; -}; - -static void -readToString(istream& aIstream, nsACString& aString) -{ - static char buffer[1024]; - int read = 0; - do { - aIstream.read(buffer, 1024); - read = aIstream.gcount(); - aString.Append(Substring(buffer, buffer + read)); - } while (!aIstream.eof()); -} - -/** - * Get the XALAN_DIR environment variable and return a nsIFile for - * the conf and the conf-gold subdirectory. Create a TEMP file, too. - * Return an error if either does not exist. - */ -static nsresult -setupXalan(const char* aPath, nsIFile** aConf, nsIFile** aConfGold, - nsIFile** aTemp) -{ - nsresult rv; - nsCOMPtr conf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, - &rv)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr tmpFile; - rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)); - NS_ENSURE_SUCCESS(rv, rv); - tmpFile->Append(NS_LITERAL_STRING("xalan.out")); - rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); - rv = conf->InitWithNativePath(nsDependentCString(aPath)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr gold; - rv = conf->Clone(getter_AddRefs(gold)); - NS_ENSURE_SUCCESS(rv, rv); - rv = conf->Append(NS_LITERAL_STRING("conf")); - NS_ENSURE_SUCCESS(rv, rv); - PRBool isDir; - rv = conf->IsDirectory(&isDir); - if (NS_FAILED(rv) || !isDir) { - return NS_ERROR_FILE_NOT_DIRECTORY; - } - rv = gold->Append(NS_LITERAL_STRING("conf-gold")); - NS_ENSURE_SUCCESS(rv, rv); - rv = gold->IsDirectory(&isDir); - if (NS_FAILED(rv) || !isDir || !conf || !gold) { - return NS_ERROR_FILE_NOT_DIRECTORY; - } - // got conf and conf-gold subdirectories - *aConf = conf; - NS_ADDREF(*aConf); - *aConfGold = gold; - NS_ADDREF(*aConfGold); - *aTemp = tmpFile; - NS_ADDREF(*aTemp); - return NS_OK; -} - -/** - * Run a category of Xalan tests - */ -void runCategory(nsIFile* aConfCat, nsIFile* aGoldCat, nsIFile* aRefTmp, - txRDFOut* aOut) -{ - nsresult rv; - //clone the nsIFiles, so that we can return easily - nsCOMPtr conf, gold; - aConfCat->Clone(getter_AddRefs(conf)); - aGoldCat->Clone(getter_AddRefs(gold)); - nsCAutoString catName, refTmp; - conf->GetNativeLeafName(catName); - aRefTmp->GetNativePath(refTmp); - txRDFOut results(catName, aOut); - nsCOMPtr tests; - rv = conf->GetDirectoryEntries(getter_AddRefs(tests)); - if (NS_FAILED(rv)) - return; - PRBool hasMore, isFile; - nsCAutoString leaf; - NS_NAMED_LITERAL_CSTRING(xsl, ".xsl"); - while (NS_SUCCEEDED(tests->HasMoreElements(&hasMore)) && hasMore) { - nsCOMPtr test; - tests->GetNext(getter_AddRefs(test)); - test->GetNativeLeafName(leaf); - if (xsl.Equals(Substring(leaf, leaf.Length()-4, 4))) { - // we have a stylesheet, let's look for source and reference - nsAFlatCString::char_iterator start, ext; - leaf.BeginWriting(start); - leaf.EndWriting(ext); - ext -= 2; - // overwrite extension with .xml - *ext = 'm'; // this one was easy - nsCOMPtr source; - conf->Clone(getter_AddRefs(source)); - rv = source->AppendNative(leaf); - if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(source->IsFile(&isFile)) && - isFile) { - nsCOMPtr reference; - gold->Clone(getter_AddRefs(reference)); - // overwrite extension with .out - --ext; - nsCharTraits::copy(ext, "out", 3); - rv = reference->AppendNative(leaf); - if (NS_SUCCEEDED(rv) && - NS_SUCCEEDED(reference->IsFile(&isFile)) && - isFile) { - nsCAutoString src, style, refPath; - test->GetNativePath(style); - source->GetNativePath(src); - reference->GetNativePath(refPath); - if (PR_GetDirectorySeparator() =='\\') { - src.ReplaceChar('\\','/'); - style.ReplaceChar('\\','/'); - refPath.ReplaceChar('\\','/'); - } - SimpleErrorObserver obs; - txStandaloneXSLTProcessor proc; - fstream result(refTmp.get(), - ios::in | ios::out | ios::trunc); - rv = proc.transform(src, style, result, obs); - PRBool success = PR_FALSE; - if (NS_SUCCEEDED(rv)) { - result.flush(); - PRInt64 resultSize, refSize; - aRefTmp->GetFileSize(&resultSize); - reference->GetFileSize(&refSize); - result.seekg(0); - int toread = (int)resultSize; - nsCString resContent, refContent; - resContent.SetCapacity(toread); - readToString(result, resContent); - result.close(); - ifstream refStream(refPath.get()); - toread = (int)refSize; - refContent.SetCapacity(toread); - readToString(refStream, refContent); - refStream.close(); - success = resContent.Equals(refContent); - } - ext--; - results.feed(Substring(start, ext), success); - } - } - } - } -} -/** - * The Xalan testcases app - */ -int main(int argc, char** argv) -{ -#ifdef NS_TRACE_MALLOC - NS_TraceMallocStartupArgs(argc, argv); -#endif -#ifdef MOZ_JPROF - setupProfilingStuff(); -#endif - char* xalan = PR_GetEnv("XALAN_DIR"); - if (!xalan) { - printHelp(); - return 1; - } - nsresult rv; - rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr conf, gold, resFile; - rv = setupXalan(xalan, getter_AddRefs(conf), getter_AddRefs(gold), - getter_AddRefs(resFile)); - if (NS_FAILED(rv)) { - NS_ShutdownXPCOM(nsnull); - printHelp(); - return -1; - } - - //-- handle output stream - ostream* resultOutput = &cout; - ofstream resultFileStream; - - int argn = 1; - // skip -- gnu style options - while (argn < argc) { - nsDependentCString opt(argv[argn]); - if (!Substring(opt, 0, 2).EqualsLiteral("--")) { - break; - } - ++argn; - } - if (argn < argc) { - nsDependentCString opt(argv[argn]); - if (Substring(opt, 0, 2).EqualsLiteral("-o")) { - if (opt.Length() > 2) { - const nsAFlatCString& fname = - PromiseFlatCString(Substring(opt, 2, opt.Length()-2)); - resultFileStream.open(fname.get(), ios::out); - } - else { - ++argn; - if (argn < argc) { - resultFileStream.open(argv[argn], ios::out); - } - } - if (!resultFileStream) { - cerr << "error opening output file" << endl; - PRBool exists; - if (NS_SUCCEEDED(resFile->Exists(&exists)) && exists) - resFile->Remove(PR_FALSE); - NS_ShutdownXPCOM(nsnull); - return -1; - } - ++argn; - resultOutput = &resultFileStream; - } - } - - if (!txXSLTProcessor::init()) { - PRBool exists; - if (NS_SUCCEEDED(resFile->Exists(&exists)) && exists) - resFile->Remove(PR_FALSE); - NS_ShutdownXPCOM(nsnull); - return 1; - } - - *resultOutput << "\n" << - "" << endl; - - txRDFOut* rdfOut = new txRDFOut(resultOutput); - nsCOMPtr tempFile; - if (argn < argc) { - // categories are specified - while (argn < argc) { - nsDependentCString cat(argv[argn++]); - rv = conf->AppendNative(cat); - if (NS_SUCCEEDED(rv)) { - rv = gold->AppendNative(cat); - if (NS_SUCCEEDED(rv)) { - runCategory(conf, gold, resFile, rdfOut); - rv = gold->GetParent(getter_AddRefs(tempFile)); - NS_ASSERTION(NS_SUCCEEDED(rv), "can't go back?"); - gold = tempFile; - } - rv = conf->GetParent(getter_AddRefs(tempFile)); - NS_ASSERTION(NS_SUCCEEDED(rv), "can't go back?"); - conf = tempFile; - } - } - } - else { - // no category specified, do everything - nsCOMPtr cats; - rv = conf->GetDirectoryEntries(getter_AddRefs(cats)); - PRBool hasMore, isDir; - nsCAutoString leaf; - while (NS_SUCCEEDED(cats->HasMoreElements(&hasMore)) && hasMore) { - nsCOMPtr cat; - cats->GetNext(getter_AddRefs(cat)); - rv = cat->IsDirectory(&isDir); - if (NS_SUCCEEDED(rv) && isDir) { - rv = cat->GetNativeLeafName(leaf); - if (NS_SUCCEEDED(rv) && - !leaf.EqualsLiteral("CVS")) { - rv = gold->AppendNative(leaf); - if (NS_SUCCEEDED(rv)) { - runCategory(cat, gold, resFile, rdfOut); - rv = gold->GetParent(getter_AddRefs(tempFile)); - gold = tempFile; - } - } - } - } - } - delete rdfOut; - rdfOut = nsnull; - *resultOutput << "" << endl; - PRBool exists; - if (NS_SUCCEEDED(resFile->Exists(&exists)) && exists) - resFile->Remove(PR_FALSE); - resultFileStream.close(); - txXSLTProcessor::shutdown(); - rv = NS_ShutdownXPCOM(nsnull); -#ifdef NS_TRACE_MALLOC - NS_TraceMallocShutdown(); -#endif - NS_ENSURE_SUCCESS(rv, rv); - return 0; -} diff --git a/extensions/transformiix/source/main/transformiix.cpp b/extensions/transformiix/source/main/transformiix.cpp deleted file mode 100644 index 8f45a647bf56..000000000000 --- a/extensions/transformiix/source/main/transformiix.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStandaloneXSLTProcessor.h" -#include "nsXPCOM.h" -#include -#include "nsDoubleHashtable.h" -#include "nsVoidArray.h" -#ifdef MOZ_JPROF -#include "jprof.h" -#endif - -/** - * Prints the command line help screen to the console - */ -void printHelp() -{ - cerr << "transfrmx [-h] [-i xml-file] [-s xslt-file] [-o output-file]" << endl << endl; - cerr << "Options:"; - cerr << endl << endl; - cerr << "\t-i specify XML file to process" << endl; - cerr << "\t-s specify XSLT file to use for processing (default: use stylesheet" << endl - << "\t\tspecified in XML file)" << endl; - cerr << "\t-o specify output file (default: write to stdout)" << endl; - cerr << "\t-h this help screen" << endl; - cerr << endl; - cerr << "You may use '-' in place of the output-file to explicitly specify" << endl; - cerr << "standard output." << endl; - cerr << endl; -} - -/** - * Prints the command line usage information to the console - */ -void printUsage() -{ - cerr << "transfrmx [-h] [-i xml-file] [-s xslt-file] [-o output-file]" << endl << endl; - cerr << "For more infomation use the -h flag" << endl; -} - -class txOptionEntry : public PLDHashCStringEntry -{ -public: - txOptionEntry(const void* aKey) : PLDHashCStringEntry(aKey) - { - } - ~txOptionEntry() - { - } - nsCStringArray mValues; -}; - -DECL_DHASH_WRAPPER(txOptions, txOptionEntry, nsACString&) -DHASH_WRAPPER(txOptions, txOptionEntry, nsACString&) - -/** - * Parses the command line - */ -void parseCommandLine(int argc, char** argv, txOptions& aOptions) -{ - nsCAutoString flag; - - for (int i = 1; i < argc; ++i) { - nsDependentCString arg(argv[i]); - if (*argv[i] == '-' && arg.Length() > 1) { - // clean up previous flag - if (!flag.IsEmpty()) { - aOptions.AddEntry(flag); - flag.Truncate(); - } - - // get next flag - flag = Substring(arg, 1, arg.Length() - 1); - } - else { - txOptionEntry* option = aOptions.AddEntry(flag); - if (option) { - option->mValues.AppendCString(nsCString(arg)); - } - flag.Truncate(); - } - } - - if (!flag.IsEmpty()) { - aOptions.AddEntry(flag); - } -} - -/** - * The TransforMiiX command line interface - */ -int main(int argc, char** argv) -{ - using namespace std; - nsresult rv; -#ifdef MOZ_JPROF - setupProfilingStuff(); -#endif - rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - if (!txXSLTProcessor::init()) - return 1; - - txOptions options; - if (NS_FAILED(options.Init(4))) { - return 1; - } - parseCommandLine(argc, argv, options); - - if (!options.GetEntry(NS_LITERAL_CSTRING("q"))) { - NS_NAMED_LITERAL_CSTRING(copyright, "(C) 1999 The MITRE Corporation, Keith Visco, and contributors"); - cerr << "TransforMiiX "; - cerr << MOZILLA_VERSION << endl; - cerr << copyright.get() << endl; - //-- print banner line - PRUint32 fillSize = copyright.Length() + 1; - PRUint32 counter; - for (counter = 0; counter < fillSize; ++counter) - cerr << '-'; - cerr << endl << endl; - } - - if (options.GetEntry(NS_LITERAL_CSTRING("h"))) { - printHelp(); - return 0; - } - - //-- handle output stream - ostream* resultOutput = &cout; - ofstream resultFileStream; - - txOptionEntry* option = options.GetEntry(NS_LITERAL_CSTRING("o")); - if (option && - option->mValues.Count() > 0 && - !option->mValues[0]->EqualsLiteral("-")) { - resultFileStream.open(option->mValues[0]->get(), ios::out); - if (!resultFileStream) { - cerr << "error opening output file: "; - cerr << option->mValues[0]->get() << endl; - return -1; - } - resultOutput = &resultFileStream; - } - - option = options.GetEntry(NS_LITERAL_CSTRING("i")); - if (!option || option->mValues.Count() == 0) { - cerr << "you must specify at least a source XML path" << endl; - printUsage(); - return -1; - } - - SimpleErrorObserver obs; - txStandaloneXSLTProcessor proc; - - txOptionEntry* styleOption = options.GetEntry(NS_LITERAL_CSTRING("s")); - if (!styleOption || styleOption->mValues.Count() == 0) { - rv = proc.transform(*option->mValues[0], *resultOutput, obs); - } - else { - // XXX TODO: Handle multiple stylesheets - rv = proc.transform(*option->mValues[0], *styleOption->mValues[0], - *resultOutput, obs); - } - - if (NS_FAILED(rv)) { - cerr << "transformation failed with " << hex << rv << endl; - } - - resultFileStream.close(); - txXSLTProcessor::shutdown(); - rv = NS_ShutdownXPCOM(nsnull); - NS_ENSURE_SUCCESS(rv, rv); - return 0; -} diff --git a/extensions/transformiix/source/main/txTestExpr.cpp b/extensions/transformiix/source/main/txTestExpr.cpp deleted file mode 100644 index 946c442a964f..000000000000 --- a/extensions/transformiix/source/main/txTestExpr.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPCOM.h" -#include "txStandaloneXSLTProcessor.h" -#include "nsString.h" -#include "ExprParser.h" -#include "txIXPathContext.h" - -/** - * A ExprParser test exe - */ - -static const char* kTokens[] = {"(", "concat", "(", "foo", ",", "'", "bar", - "'",")", "//", ".", "[", "preceding-sibling", - "::", "bar", "]", "/", "*", "[", "23", "]", - "|", "node", "(", ")", ")", "<", "3"}; -static const PRUint8 kCount = sizeof(kTokens)/sizeof(char*); - -class ParseContextImpl : public txIParseContext -{ -public: - nsresult - resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID) - { - return NS_ERROR_FAILURE; - } - nsresult - resolveFunctionCall(nsIAtom* aName, PRInt32 aID, FunctionCall*& aFunction) - { - return NS_ERROR_XPATH_UNKNOWN_FUNCTION; - } - PRBool - caseInsensitiveNameTests() - { - return PR_FALSE; - } - void - SetErrorOffset(PRUint32 aOffset) - { - mOff = aOffset; - } - PRUint32 mOff; -}; - -static void doTest(const nsASingleFragmentString& aExpr) -{ - ParseContextImpl ct; - nsAutoPtr expression; - cout << NS_LossyConvertUTF16toASCII(aExpr).get() << endl; - ct.mOff = 0; - nsresult rv = txExprParser::createExpr(aExpr, &ct, - getter_Transfers(expression)); - - cout << "createExpr returned " << ios::hex << rv << ios::dec; - cout << " at " << ct.mOff << endl; - if (NS_FAILED(rv)) { - NS_LossyConvertUTF16toASCII cstring(aExpr); - cout << NS_LossyConvertUTF16toASCII(StringHead(aExpr, ct.mOff)).get(); - cout << " ^ "; - cout << NS_LossyConvertUTF16toASCII(StringTail(aExpr, aExpr.Length()-ct.mOff)).get(); - cout << endl << endl; - } -#ifdef TX_TO_STRING - else { - nsAutoString expr; - expression->toString(expr); - cout << "parsed expression: "; - cout << NS_LossyConvertUTF16toASCII(expr).get() << endl << endl; - } -#endif -} - -int main(int argc, char** argv) -{ - using namespace std; - nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - if (!txXSLTProcessor::init()) - return 1; - - nsAutoString exprOrig, expr; - nsStringArray exprHead, exprTail; - PRUint8 i, dropStart, dropEnd; - exprHead.AppendString(NS_ConvertASCIItoUTF16(kTokens[0])); - exprTail.AppendString(NS_ConvertASCIItoUTF16(kTokens[kCount - 1])); - for (i = 2; i < kCount; ++i) { - exprHead.AppendString(*exprHead[i - 2] + - NS_ConvertASCIItoUTF16(kTokens[i - 1])); - exprTail.AppendString(NS_ConvertASCIItoUTF16(kTokens[kCount - i]) + - *exprTail[i - 2]); - } - exprOrig = NS_ConvertASCIItoUTF16(kTokens[0]) + *exprTail[kCount - 2]; - cout << NS_LossyConvertUTF16toASCII(exprOrig).get() << endl << endl; - for (dropStart = 0; dropStart < kCount - 2; ++dropStart) { - doTest(*exprTail[kCount - 2 - dropStart]); - for (dropEnd = kCount - 3 - dropStart; dropEnd > 0; --dropEnd) { - expr = *exprHead[dropStart] + *exprTail[dropEnd]; - doTest(expr); - } - doTest(*exprHead[dropStart]); - } - doTest(*exprHead[kCount - 2]); - - txXSLTProcessor::shutdown(); - rv = NS_ShutdownXPCOM(nsnull); - NS_ENSURE_SUCCESS(rv, rv); - return 0; -} diff --git a/extensions/transformiix/source/main/txXSLTMarkDriver.cpp b/extensions/transformiix/source/main/txXSLTMarkDriver.cpp deleted file mode 100644 index e679cfc346e2..000000000000 --- a/extensions/transformiix/source/main/txXSLTMarkDriver.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Driver for running XSLTMark on standalone - * - * See http://www.datapower.com/XSLTMark/ - */ - -#include "txStandaloneStylesheetCompiler.h" -#include "txStandaloneXSLTProcessor.h" -#include "nsXPCOM.h" -#include "xmExternalDriver.hpp" -#ifdef MOZ_JPROF -#include "jprof.h" -#endif - -class txDriverProcessor : public txStandaloneXSLTProcessor, - public xmExternalDriver -{ -public: - txDriverProcessor() : mXML(0), mOut(0) - { - } - - int loadStylesheet (char * filename) - { - txParsedURL url; - url.init(NS_ConvertASCIItoUCS2(filename)); - nsresult rv = - TX_CompileStylesheetPath(url, getter_AddRefs(mStylesheet)); - return NS_SUCCEEDED(rv) ? 0 : 1; - } - int setInputDocument (char * filename) - { - delete mXML; - mXML = parsePath(nsDependentCString(filename), mObserver); - return mXML ? 0 : 1; - } - int openOutput (char * outputFilename) - { - mOut = new ofstream(outputFilename); - return mXML ? 0 : 1; - } - int runTransform () - { - if (!mXML || !mStylesheet || !mOut) - return 1; - nsresult rv = transform(*mXML, mStylesheet, *mOut, mObserver); - return NS_FAILED(rv); - } - int closeOutput () - { - if (mOut) - mOut->close(); - delete mOut; - mOut = 0; - return 0; - } - int terminate() - { - delete mXML; - mXML = 0; - if (mOut && mOut->is_open()) - mOut->close(); - delete mOut; - mOut = 0; - mStylesheet = 0; - return 0; - } - ~txDriverProcessor() - { - delete mXML; - delete mOut; - } -private: - txXPathNode *mXML; - nsRefPtr mStylesheet; - SimpleErrorObserver mObserver; - ofstream* mOut; -}; - -int main (int argc, char ** argv) -{ - txDriverProcessor driver; -#ifdef MOZ_JPROF - setupProfilingStuff(); -#endif - NS_InitXPCOM2(nsnull, nsnull, nsnull); - if (!txDriverProcessor::init()) - return 1; - driver.main (argc, argv); - txDriverProcessor::shutdown(); - NS_ShutdownXPCOM(nsnull); - return 0; -} diff --git a/extensions/transformiix/source/xml/.cvsignore b/extensions/transformiix/source/xml/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xml/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xml/Makefile.in b/extensions/transformiix/source/xml/Makefile.in deleted file mode 100644 index 71dbe0966a85..000000000000 --- a/extensions/transformiix/source/xml/Makefile.in +++ /dev/null @@ -1,75 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxml_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += dom \ - content \ - layout \ - widget \ - unicharutil \ - necko \ - htmlparser \ - $(NULL) -endif - -DIRS = dom parser - -CPPSRCS = XMLUtils.cpp - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir)/../base -I$(srcdir)/dom -I$(srcdir)/../xpath \ - -I$(srcdir)/../xslt diff --git a/extensions/transformiix/source/xml/XMLUtils.cpp b/extensions/transformiix/source/xml/XMLUtils.cpp deleted file mode 100644 index 23572ea9b67e..000000000000 --- a/extensions/transformiix/source/xml/XMLUtils.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * Lidong - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * XML utility classes - */ - -#include "XMLUtils.h" -#include "nsString.h" -#include "nsReadableUtils.h" -#include "txAtoms.h" -#include "txStringUtils.h" -#include "txNamespaceMap.h" -#include "txXPathTreeWalker.h" - -nsresult -txExpandedName::init(const nsAString& aQName, txNamespaceMap* aResolver, - MBool aUseDefault) -{ - const nsAFlatString& qName = PromiseFlatString(aQName); - const PRUnichar* colon; - PRBool valid = XMLUtils::isValidQName(qName, &colon); - if (!valid) { - return NS_ERROR_FAILURE; - } - - if (colon) { - nsCOMPtr prefix = do_GetAtom(Substring(qName.get(), colon)); - PRInt32 namespaceID = aResolver->lookupNamespace(prefix); - if (namespaceID == kNameSpaceID_Unknown) - return NS_ERROR_FAILURE; - mNamespaceID = namespaceID; - - const PRUnichar *end; - qName.EndReading(end); - mLocalName = do_GetAtom(Substring(colon + 1, end)); - } - else { - mNamespaceID = aUseDefault ? aResolver->lookupNamespace(nsnull) : - kNameSpaceID_None; - mLocalName = do_GetAtom(aQName); - } - return NS_OK; -} - - //------------------------------/ - //- Implementation of XMLUtils -/ -//------------------------------/ - -// static -nsresult -XMLUtils::splitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix, - nsIAtom **aLocalName, PRInt32* aNameSpaceID) -{ - /** - * Expat can send the following: - * localName - * namespaceURIlocalName - * namespaceURIlocalNameprefix - */ - - const PRUnichar *uriEnd = nsnull; - const PRUnichar *nameEnd = nsnull; - const PRUnichar *pos; - for (pos = aExpatName; *pos; ++pos) { - if (*pos == kExpatSeparatorChar) { - if (uriEnd) { - nameEnd = pos; - } - else { - uriEnd = pos; - } - } - } - - const PRUnichar *nameStart; - if (uriEnd) { - *aNameSpaceID = - txNamespaceManager::getNamespaceID(nsDependentSubstring(aExpatName, - uriEnd)); - if (*aNameSpaceID == kNameSpaceID_Unknown) { - return NS_ERROR_FAILURE; - } - - nameStart = (uriEnd + 1); - if (nameEnd) { - const PRUnichar *prefixStart = nameEnd + 1; - *aPrefix = NS_NewAtom(NS_ConvertUTF16toUTF8(prefixStart, - pos - prefixStart)); - if (!*aPrefix) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - else { - nameEnd = pos; - *aPrefix = nsnull; - } - } - else { - *aNameSpaceID = kNameSpaceID_None; - nameStart = aExpatName; - nameEnd = pos; - *aPrefix = nsnull; - } - - *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart, - nameEnd - nameStart)); - - return *aLocalName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -nsresult -XMLUtils::splitQName(const nsAString& aName, nsIAtom** aPrefix, - nsIAtom** aLocalName) -{ - const nsAFlatString& qName = PromiseFlatString(aName); - const PRUnichar* colon; - PRBool valid = XMLUtils::isValidQName(qName, &colon); - if (!valid) { - return NS_ERROR_FAILURE; - } - - if (colon) { - const PRUnichar *end; - qName.EndReading(end); - - *aPrefix = NS_NewAtom(Substring(qName.get(), colon)); - *aLocalName = NS_NewAtom(Substring(colon + 1, end)); - } - else { - *aPrefix = nsnull; - *aLocalName = NS_NewAtom(aName); - } - - return NS_OK; -} - -const nsDependentSubstring XMLUtils::getLocalPart(const nsAString& src) -{ - // Anything after ':' is the local part of the name - PRInt32 idx = src.FindChar(':'); - if (idx == kNotFound) { - return Substring(src, 0, src.Length()); - } - - NS_ASSERTION(idx > 0, "This QName looks invalid."); - return Substring(src, idx + 1, src.Length() - (idx + 1)); -} - -/** - * Returns true if the given string has only whitespace characters - */ -PRBool XMLUtils::isWhitespace(const nsAFlatString& aText) -{ - nsAFlatString::const_char_iterator start, end; - aText.BeginReading(start); - aText.EndReading(end); - for ( ; start != end; ++start) { - if (!isWhitespace(*start)) { - return PR_FALSE; - } - } - return PR_TRUE; -} - -/** - * Normalizes the value of a XML processing instruction -**/ -void XMLUtils::normalizePIValue(nsAString& piValue) -{ - nsAutoString origValue(piValue); - PRUint32 origLength = origValue.Length(); - PRUint32 conversionLoop = 0; - PRUnichar prevCh = 0; - piValue.Truncate(); - - while (conversionLoop < origLength) { - PRUnichar ch = origValue.CharAt(conversionLoop); - switch (ch) { - case '>': - { - if (prevCh == '?') { - piValue.Append(PRUnichar(' ')); - } - break; - } - default: - { - break; - } - } - piValue.Append(ch); - prevCh = ch; - ++conversionLoop; - } -} - -//static -MBool XMLUtils::getXMLSpacePreserve(const txXPathNode& aNode) -{ - nsAutoString value; - txXPathTreeWalker walker(aNode); - do { - if (walker.getAttr(txXMLAtoms::space, kNameSpaceID_XML, value)) { - if (TX_StringEqualsAtom(value, txXMLAtoms::preserve)) { - return PR_TRUE; - } - if (TX_StringEqualsAtom(value, txXMLAtoms::_default)) { - return PR_FALSE; - } - } - } while (walker.moveToParent()); - - return PR_FALSE; -} diff --git a/extensions/transformiix/source/xml/XMLUtils.h b/extensions/transformiix/source/xml/XMLUtils.h deleted file mode 100644 index 90f8b392ca60..000000000000 --- a/extensions/transformiix/source/xml/XMLUtils.h +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * An XML Utility class -**/ - -#ifndef MITRE_XMLUTILS_H -#define MITRE_XMLUTILS_H - -#include "txCore.h" -#include "nsCOMPtr.h" -#include "nsDependentSubstring.h" -#include "nsIAtom.h" -#include "txXPathNode.h" - -#ifndef TX_EXE -#include "nsIParserService.h" -#endif - -#define kExpatSeparatorChar 0xFFFF - -class nsIAtom; -class txNamespaceMap; - -class txExpandedName { -public: - txExpandedName() : mNamespaceID(kNameSpaceID_None) - { - } - - txExpandedName(PRInt32 aNsID, - nsIAtom* aLocalName) : mNamespaceID(aNsID), - mLocalName(aLocalName) - { - } - - txExpandedName(const txExpandedName& aOther) : - mNamespaceID(aOther.mNamespaceID), - mLocalName(aOther.mLocalName) - { - } - - ~txExpandedName() - { - } - - nsresult init(const nsAString& aQName, txNamespaceMap* aResolver, - MBool aUseDefault); - - void reset() - { - mNamespaceID = kNameSpaceID_None; - mLocalName = nsnull; - } - - PRBool isNull() - { - return mNamespaceID == kNameSpaceID_None && !mLocalName; - } - - txExpandedName& operator = (const txExpandedName& rhs) - { - mNamespaceID = rhs.mNamespaceID; - mLocalName = rhs.mLocalName; - return *this; - } - - MBool operator == (const txExpandedName& rhs) const - { - return ((mLocalName == rhs.mLocalName) && - (mNamespaceID == rhs.mNamespaceID)); - } - - MBool operator != (const txExpandedName& rhs) const - { - return ((mLocalName != rhs.mLocalName) || - (mNamespaceID != rhs.mNamespaceID)); - } - - PRInt32 mNamespaceID; - nsCOMPtr mLocalName; -}; - -#ifdef TX_EXE -extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end, - int ns_aware, const char** colon); -extern "C" int MOZ_XMLIsLetter(const char* ptr); -extern "C" int MOZ_XMLIsNCNameChar(const char* ptr); -#else -extern nsIParserService *gTxParserService; -#endif - -class XMLUtils { - -public: - static nsresult splitExpatName(const PRUnichar *aExpatName, - nsIAtom **aPrefix, nsIAtom **aLocalName, - PRInt32* aNameSpaceID); - static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix, - nsIAtom** aLocalName); - static const nsDependentSubstring getLocalPart(const nsAString& src); - - /* - * Returns true if the given character is whitespace. - */ - static MBool isWhitespace(const PRUnichar& aChar) - { - return (aChar <= ' ' && - (aChar == ' ' || aChar == '\r' || - aChar == '\n'|| aChar == '\t')); - } - - /** - * Returns true if the given string has only whitespace characters - */ - static PRBool isWhitespace(const nsAFlatString& aText); - - /** - * Normalizes the value of a XML processingInstruction - **/ - static void normalizePIValue(nsAString& attValue); - - /** - * Returns true if the given string is a valid XML QName - */ - static PRBool isValidQName(const nsAFlatString& aQName, - const PRUnichar** aColon) - { -#ifdef TX_EXE - const PRUnichar* end; - aQName.EndReading(end); - - const char *colonPtr; - int result = MOZ_XMLCheckQName(NS_REINTERPRET_CAST(const char*, - aQName.get()), - NS_REINTERPRET_CAST(const char*, - end), - PR_TRUE, &colonPtr); - *aColon = NS_REINTERPRET_CAST(const PRUnichar*, colonPtr); - return result == 0; -#else - return NS_SUCCEEDED(gTxParserService->CheckQName(aQName, PR_TRUE, aColon)); -#endif - } - - /** - * Returns true if the given character represents an Alpha letter - */ - static PRBool isLetter(PRUnichar aChar) - { -#ifdef TX_EXE - return MOZ_XMLIsLetter(NS_REINTERPRET_CAST(const char*, &aChar)); -#else - return gTxParserService->IsXMLLetter(aChar); -#endif - } - - /** - * Returns true if the given character is an allowable NCName character - */ - static PRBool isNCNameChar(PRUnichar aChar) - { -#ifdef TX_EXE - return MOZ_XMLIsNCNameChar(NS_REINTERPRET_CAST(const char*, &aChar)); -#else - return gTxParserService->IsXMLNCNameChar(aChar); -#endif - } - - /* - * Walks up the document tree and returns true if the closest xml:space - * attribute is "preserve" - */ - static MBool getXMLSpacePreserve(const txXPathNode& aNode); -}; - -#endif diff --git a/extensions/transformiix/source/xml/dom/.cvsignore b/extensions/transformiix/source/xml/dom/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xml/dom/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xml/dom/Makefile.in b/extensions/transformiix/source/xml/dom/Makefile.in deleted file mode 100644 index c286c708c938..000000000000 --- a/extensions/transformiix/source/xml/dom/Makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -ifdef TX_EXE -DIRS = standalone -endif - -include $(topsrcdir)/config/rules.mk diff --git a/extensions/transformiix/source/xml/dom/dom.h b/extensions/transformiix/source/xml/dom/dom.h deleted file mode 100644 index 1102652a34f0..000000000000 --- a/extensions/transformiix/source/xml/dom/dom.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_DOM_WRAPPER__ -#define __TX_DOM_WRAPPER__ - -#ifdef TX_EXE -#include "standalone/dom.h" -#endif - -#endif diff --git a/extensions/transformiix/source/xml/dom/standalone/.cvsignore b/extensions/transformiix/source/xml/dom/standalone/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xml/dom/standalone/Attr.cpp b/extensions/transformiix/source/xml/dom/standalone/Attr.cpp deleted file mode 100644 index 577157b4c74f..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/Attr.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// Implementation of the Attr class -// - -#include "dom.h" -#include "txAtoms.h" -#include "XMLUtils.h" - -Attr::Attr(nsIAtom *aPrefix, nsIAtom *aLocalName, PRInt32 aNamespaceID, - Element *aOwnerElement, const nsAString &aValue) : - NodeDefinition(Node::ATTRIBUTE_NODE, aLocalName, aValue, - aOwnerElement->getOwnerDocument()), - mPrefix(aPrefix), - mNamespaceID(aNamespaceID), - mOwnerElement(aOwnerElement) -{ -} - -Attr::~Attr() -{ -} - -// -//Not implemented anymore, return null as an error. -// -Node* Attr::appendChild(Node* newChild) -{ - NS_ASSERTION(0, "not implemented"); - return nsnull; -} - -nsresult -Attr::getNodeName(nsAString& aName) const -{ - if (mPrefix) { - mPrefix->ToString(aName); - aName.Append(PRUnichar(':')); - } - else { - aName.Truncate(); - } - - const char* ASCIIAtom; - mLocalName->GetUTF8String(&ASCIIAtom); - AppendUTF8toUTF16(ASCIIAtom, aName); - - return NS_OK; -} - -// -//Return the attributes local (unprefixed) name atom. -// -MBool Attr::getLocalName(nsIAtom** aLocalName) -{ - if (!aLocalName) - return MB_FALSE; - *aLocalName = mLocalName; - NS_ADDREF(*aLocalName); - return MB_TRUE; -} - -// -//Return the namespace the attribute belongs to. If the attribute doesn't -//have a prefix it doesn't belong to any namespace per the namespace spec, -//and is handled in the constructor. -// -PRInt32 Attr::getNamespaceID() -{ - return mNamespaceID; -} - -// -//Return the attributes owning element -// -Node* Attr::getXPathParent() -{ - return mOwnerElement; -} diff --git a/extensions/transformiix/source/xml/dom/standalone/Document.cpp b/extensions/transformiix/source/xml/dom/standalone/Document.cpp deleted file mode 100644 index 5867b20cdfb3..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/Document.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// Implementation of the Document class -// -// Modification History: -// Who When What -// TK 03/29/99 Created -// LF 08/06/1999 Removed Default argument initializer from -// Document() constructor -// LF 08/06/1999 fixed typo: defalut to default -// - -#include "dom.h" -#include "txAtoms.h" - -// -//Construct a Document. Currently no parameters are required, but the the -//node constructor is called to identify the node type. -// -Document::Document() : - NodeDefinition(Node::DOCUMENT_NODE, txXMLAtoms::document, EmptyString(), - nsnull), - documentElement(nsnull) -{ - mIDMap.Init(0); -} - -// -//Return the one and only element for this document -// -Element* Document::getDocumentElement() -{ - return documentElement; -} - -Element* -Document::createElementNS(nsIAtom *aPrefix, nsIAtom *aLocalName, - PRInt32 aNamespaceID) -{ - return new Element(aPrefix, aLocalName, aNamespaceID, this); -} - -// -//Construct a text node with the given data -// -Node* Document::createTextNode(const nsAString& theData) -{ - return new NodeDefinition(Node::TEXT_NODE, txXMLAtoms::text, theData, this); -} - -// -//Construct a comment node with the given data -// -Node* Document::createComment(const nsAString& theData) -{ - return new NodeDefinition(Node::COMMENT_NODE, txXMLAtoms::comment, theData, - this); -} - -// -//Construct a ProcessingInstruction node with the given targe and data. -// -ProcessingInstruction* - Document::createProcessingInstruction(nsIAtom *aTarget, - const nsAString& data) -{ - return new ProcessingInstruction(aTarget, data, this); -} - -// -//Return an Element by ID, introduced by DOM2 -// -DHASH_WRAPPER(txIDMap, txIDEntry, nsAString&) - -Element* Document::getElementById(const nsAString& aID) -{ - txIDEntry* entry = mIDMap.GetEntry(aID); - if (entry) - return entry->mElement; - return nsnull; -} - -/** - * private setter for element ID - */ -PRBool -Document::setElementID(const nsAString& aID, Element* aElement) -{ - txIDEntry* id = mIDMap.AddEntry(aID); - // make sure IDs are unique - if (id->mElement) { - return PR_FALSE; - } - id->mElement = aElement; - id->mElement->setIDValue(aID); - return PR_TRUE; -} - -Node* Document::appendChild(Node* newChild) -{ - unsigned short nodeType = newChild->getNodeType(); - - // Convert to a NodeDefinition Pointer - NodeDefinition* pNewChild = (NodeDefinition*)newChild; - - if (pNewChild->parentNode == this) - { - pNewChild = implRemoveChild(pNewChild); - if (nodeType == Node::ELEMENT_NODE) - documentElement = nsnull; - } - - switch (nodeType) - { - case Node::PROCESSING_INSTRUCTION_NODE : - case Node::COMMENT_NODE : - case Node::DOCUMENT_TYPE_NODE : - return implAppendChild(pNewChild); - - case Node::ELEMENT_NODE : - if (!documentElement) - { - Node* returnVal = implAppendChild(pNewChild); - documentElement = (Element*)pNewChild; - return returnVal; - } - - default: - break; - } - - return nsnull; -} - -nsresult Document::getBaseURI(nsAString& aURI) -{ - aURI = documentBaseURI; - return NS_OK; -} diff --git a/extensions/transformiix/source/xml/dom/standalone/Element.cpp b/extensions/transformiix/source/xml/dom/standalone/Element.cpp deleted file mode 100644 index 27f56a29f2c7..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/Element.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// Implementation of the Element class -// - -#include "dom.h" -#include "txAtoms.h" -#include "XMLUtils.h" - -Element::Element(nsIAtom *aPrefix, nsIAtom *aLocalName, PRInt32 aNamespaceID, - Document* aOwner) : - NodeDefinition(Node::ELEMENT_NODE, aLocalName, EmptyString(), aOwner), - mPrefix(aPrefix), - mNamespaceID(aNamespaceID) -{ -} - -// -// This element is being destroyed, so destroy all attributes stored -// in the mAttributes NamedNodeMap. -// -Element::~Element() -{ -} - -Node* Element::appendChild(Node* newChild) -{ - switch (newChild->getNodeType()) - { - case Node::ELEMENT_NODE : - case Node::TEXT_NODE : - case Node::COMMENT_NODE : - case Node::PROCESSING_INSTRUCTION_NODE : - { - // Remove the "newChild" if it is already a child of this node - NodeDefinition* pNewChild = (NodeDefinition*)newChild; - if (pNewChild->getParentNode() == this) - pNewChild = implRemoveChild(pNewChild); - - return implAppendChild(pNewChild); - } - - default: - break; - } - - return nsnull; -} - -nsresult -Element::getNodeName(nsAString& aName) const -{ - if (mPrefix) { - mPrefix->ToString(aName); - aName.Append(PRUnichar(':')); - } - else { - aName.Truncate(); - } - - const char* ASCIIAtom; - mLocalName->GetUTF8String(&ASCIIAtom); - AppendUTF8toUTF16(ASCIIAtom, aName); - - return NS_OK; -} - -// -//Return the elements local (unprefixed) name. -// -MBool Element::getLocalName(nsIAtom** aLocalName) -{ - if (!aLocalName) - return MB_FALSE; - *aLocalName = mLocalName; - NS_ADDREF(*aLocalName); - return MB_TRUE; -} - -// -//Return the namespace the elements belongs to. -// -PRInt32 Element::getNamespaceID() -{ - return mNamespaceID; -} - -nsresult -Element::appendAttributeNS(nsIAtom *aPrefix, nsIAtom *aLocalName, - PRInt32 aNamespaceID, const nsAString& aValue) -{ - nsAutoPtr newAttribute; - newAttribute = new Attr(aPrefix, aLocalName, aNamespaceID, this, aValue); - if (!newAttribute) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (mFirstAttribute) { - Attr *lastAttribute = mFirstAttribute; - while (lastAttribute->mNextAttribute) { - lastAttribute = lastAttribute->mNextAttribute; - } - lastAttribute->mNextAttribute = newAttribute; - } - else { - mFirstAttribute = newAttribute; - } - - return NS_OK; -} - -// -// Return true if the attribute specified by localname and nsID -// exists, and sets aValue to the value of the attribute. -// Return false, if the attribute does not exist. -// -MBool Element::getAttr(nsIAtom* aLocalName, PRInt32 aNSID, - nsAString& aValue) -{ - aValue.Truncate(); - Attr *attribute = mFirstAttribute; - while (attribute) { - if (attribute->equals(aLocalName, aNSID)) { - attribute->getNodeValue(aValue); - - return PR_TRUE; - } - - attribute = attribute->mNextAttribute; - } - - return PR_FALSE; -} - -// -// Return true if the attribute specified by localname and nsID -// exists. Return false otherwise. -// -MBool Element::hasAttr(nsIAtom* aLocalName, PRInt32 aNSID) -{ - Attr *attribute = mFirstAttribute; - while (attribute) { - if (attribute->equals(aLocalName, aNSID)) { - return PR_TRUE; - } - - attribute = attribute->mNextAttribute; - } - - return PR_FALSE; -} - -/** - * ID accessors. Getter used for id() patterns, private setter for parser - */ -PRBool -Element::getIDValue(nsAString& aValue) -{ - if (mIDValue.IsEmpty()) { - return PR_FALSE; - } - aValue = mIDValue; - return PR_TRUE; -} - -void -Element::setIDValue(const nsAString& aValue) -{ - mIDValue = aValue; -} diff --git a/extensions/transformiix/source/xml/dom/standalone/Makefile.in b/extensions/transformiix/source/xml/dom/standalone/Makefile.in deleted file mode 100644 index 4de7682472ff..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/Makefile.in +++ /dev/null @@ -1,66 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxmldom_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -CPPSRCS = Attr.cpp \ - Document.cpp \ - Element.cpp \ - NodeDefinition.cpp \ - ProcessingInstruction.cpp - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir) -I$(srcdir)/../.. -I$(srcdir)/../../../base \ - -I$(srcdir)/../../../xpath -I$(srcdir)/../../../xslt diff --git a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp b/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp deleted file mode 100644 index f63da7939bb1..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// Implementation of the NodeDefinition Class -// -// Modification History: -// Who When What -// TK 03/29/99 Created -// - -#include "dom.h" -#include "nsVoidArray.h" -#include "txURIUtils.h" -#include "txAtoms.h" -#include - -NodeDefinition::NodeDefinition(NodeType type, nsIAtom *aLocalName, - const nsAString& value, Document* owner) : - mLocalName(aLocalName), - nodeValue(value), - nodeType(type), - parentNode(nsnull), - previousSibling(nsnull), - nextSibling(nsnull), - ownerDocument(owner), - length(0), - firstChild(nsnull), - lastChild(nsnull), - mOrderInfo(nsnull) -{ -} - -// -// This node is being destroyed, so loop through and destroy all the children. -// -NodeDefinition::~NodeDefinition() -{ - NodeDefinition* pCurrent = firstChild; - NodeDefinition* pDestroyer; - - while (pCurrent) - { - pDestroyer = pCurrent; - pCurrent = pCurrent->nextSibling; - delete pDestroyer; - } - - delete mOrderInfo; -} - -nsresult NodeDefinition::getNodeName(nsAString& aName) const -{ - mLocalName->ToString(aName); - return NS_OK; -} - -nsresult NodeDefinition::getNodeValue(nsAString& aValue) -{ - aValue = nodeValue; - return NS_OK; -} - -unsigned short NodeDefinition::getNodeType() const -{ - return nodeType; -} - -Node* NodeDefinition::getParentNode() const -{ - return parentNode; -} - -Node* NodeDefinition::getFirstChild() const -{ - return firstChild; -} - -Node* NodeDefinition::getLastChild() const -{ - return lastChild; -} - -Node* NodeDefinition::getPreviousSibling() const -{ - return previousSibling; -} - -Node* NodeDefinition::getNextSibling() const -{ - return nextSibling; -} - -Document* NodeDefinition::getOwnerDocument() const -{ - return ownerDocument; -} - -Node* NodeDefinition::appendChild(Node* newChild) -{ - return nsnull; -} - -NodeDefinition* NodeDefinition::implAppendChild(NodeDefinition* newChild) -{ - // The new child should not be a child of any other node - if (!newChild->previousSibling && !newChild->nextSibling && - !newChild->parentNode) - { - newChild->previousSibling = lastChild; - - if (lastChild) - lastChild->nextSibling = newChild; - - lastChild = newChild; - - newChild->parentNode = this; - - if (!newChild->previousSibling) - firstChild = newChild; - - ++length; - - return newChild; - } - - return nsnull; -} - -NodeDefinition* NodeDefinition::implRemoveChild(NodeDefinition* oldChild) -{ - if (oldChild != firstChild) - oldChild->previousSibling->nextSibling = oldChild->nextSibling; - else - firstChild = oldChild->nextSibling; - - if (oldChild != lastChild) - oldChild->nextSibling->previousSibling = oldChild->previousSibling; - else - lastChild = oldChild->previousSibling; - - oldChild->nextSibling = nsnull; - oldChild->previousSibling = nsnull; - oldChild->parentNode = nsnull; - - --length; - - return oldChild; -} - -MBool NodeDefinition::hasChildNodes() const -{ - if (firstChild) - return MB_TRUE; - else - return MB_FALSE; -} - -MBool NodeDefinition::getLocalName(nsIAtom** aLocalName) -{ - if (!aLocalName) - return MB_FALSE; - *aLocalName = 0; - return MB_TRUE; -} - -nsresult NodeDefinition::getNamespaceURI(nsAString& aNSURI) -{ - return txStandaloneNamespaceManager::getNamespaceURI(getNamespaceID(), - aNSURI); -} - -PRInt32 NodeDefinition::getNamespaceID() -{ - return kNameSpaceID_None; -} - -Node* NodeDefinition::getXPathParent() -{ - return parentNode; -} - -// -// Returns the base URI of the node. Acccounts for xml:base -// attributes. -// -// @return base URI for the node -// -nsresult NodeDefinition::getBaseURI(nsAString& aURI) -{ - Node* node = this; - nsStringArray baseUrls; - nsAutoString url; - - while (node) { - switch (node->getNodeType()) { - case Node::ELEMENT_NODE : - if (((Element*)node)->getAttr(txXMLAtoms::base, kNameSpaceID_XML, - url)) - baseUrls.AppendString(url); - break; - - case Node::DOCUMENT_NODE : - node->getBaseURI(url); - baseUrls.AppendString(url); - break; - - default: - break; - } - node = node->getXPathParent(); - } - - PRInt32 count = baseUrls.Count(); - if (count) { - baseUrls.StringAt(--count, aURI); - - while (count > 0) { - nsAutoString dest; - URIUtils::resolveHref(*baseUrls[--count], aURI, dest); - aURI = dest; - } - } - - return NS_OK; -} // getBaseURI - -/* - * Compares document position of this node relative to another node - */ -PRInt32 NodeDefinition::compareDocumentPosition(Node* aOther) -{ - OrderInfo* myOrder = getOrderInfo(); - OrderInfo* otherOrder = ((NodeDefinition*)aOther)->getOrderInfo(); - if (!myOrder || !otherOrder) - return -1; - - if (myOrder->mRoot == otherOrder->mRoot) { - int c = 0; - while (c < myOrder->mSize && c < otherOrder->mSize) { - if (myOrder->mOrder[c] < otherOrder->mOrder[c]) - return -1; - if (myOrder->mOrder[c] > otherOrder->mOrder[c]) - return 1; - ++c; - } - if (c < myOrder->mSize) - return 1; - if (c < otherOrder->mSize) - return -1; - return 0; - } - - if (myOrder->mRoot < otherOrder->mRoot) - return -1; - - return 1; -} - -/* - * Get order information for node - */ -NodeDefinition::OrderInfo* NodeDefinition::getOrderInfo() -{ - if (mOrderInfo) - return mOrderInfo; - - mOrderInfo = new OrderInfo; - if (!mOrderInfo) - return 0; - - Node* parent = getXPathParent(); - if (!parent) { - mOrderInfo->mOrder = 0; - mOrderInfo->mSize = 0; - mOrderInfo->mRoot = this; - return mOrderInfo; - } - - OrderInfo* parentOrder = ((NodeDefinition*)parent)->getOrderInfo(); - mOrderInfo->mSize = parentOrder->mSize + 1; - mOrderInfo->mRoot = parentOrder->mRoot; - mOrderInfo->mOrder = new PRUint32[mOrderInfo->mSize]; - if (!mOrderInfo->mOrder) { - delete mOrderInfo; - mOrderInfo = 0; - return 0; - } - memcpy(mOrderInfo->mOrder, - parentOrder->mOrder, - parentOrder->mSize * sizeof(PRUint32*)); - - // Get childnumber of this node - int lastElem = parentOrder->mSize; - switch (getNodeType()) { - case Node::ATTRIBUTE_NODE: - { - NS_ASSERTION(parent->getNodeType() == Node::ELEMENT_NODE, - "parent to attribute is not an element"); - - Element* elem = (Element*)parent; - Attr *attribute = elem->getFirstAttribute(); - PRUint32 i = 0; - while (attribute) { - if (attribute == this) { - mOrderInfo->mOrder[lastElem] = i + kTxAttrIndexOffset; - return mOrderInfo; - } - attribute = attribute->getNextAttribute(); - ++i; - } - break; - } - // XXX Namespace: need to take care of namespace nodes here - default: - { - PRUint32 i = 0; - Node * child = parent->getFirstChild(); - while (child) { - if (child == this) { - mOrderInfo->mOrder[lastElem] = i + kTxChildIndexOffset; - return mOrderInfo; - } - ++i; - child = child->getNextSibling(); - } - break; - } - } - - NS_ASSERTION(0, "unable to get childnumber"); - mOrderInfo->mOrder[lastElem] = 0; - return mOrderInfo; -} - -/* - * OrderInfo destructor - */ -NodeDefinition::OrderInfo::~OrderInfo() -{ - delete [] mOrder; -} diff --git a/extensions/transformiix/source/xml/dom/standalone/ProcessingInstruction.cpp b/extensions/transformiix/source/xml/dom/standalone/ProcessingInstruction.cpp deleted file mode 100644 index 958005c19218..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/ProcessingInstruction.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// Implementation of the ProcessingInstruction class -// -// Modification History: -// Who When What -// TK 03/29/99 Created -// - -#include "dom.h" -#include "nsIAtom.h" - -// -//Construct a text object with the specified document owner and data -// -ProcessingInstruction::ProcessingInstruction(nsIAtom *theTarget, - const nsAString& theData, - Document* owner) : - NodeDefinition(Node::PROCESSING_INSTRUCTION_NODE, theTarget, theData, owner) -{ -} - -// -//Release the mLocalName -// -ProcessingInstruction::~ProcessingInstruction() -{ -} - -// -//ProcessingInstruction nodes can not have any children, so just return null -//from all child manipulation functions. -// - -MBool ProcessingInstruction::getLocalName(nsIAtom** aLocalName) -{ - if (!aLocalName) - return MB_FALSE; - *aLocalName = mLocalName; - NS_ADDREF(*aLocalName); - return MB_TRUE; -} diff --git a/extensions/transformiix/source/xml/dom/standalone/dom.h b/extensions/transformiix/source/xml/dom/standalone/dom.h deleted file mode 100644 index 84d046240f1e..000000000000 --- a/extensions/transformiix/source/xml/dom/standalone/dom.h +++ /dev/null @@ -1,473 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Tom Kneeland (3/29/99) -// -// Implementation of the Document Object Model Level 1 Core -// -// Modification History: -// Who When What -// TK 03/29/99 Created -// LF 08/06/1999 Changed static const short NodeType to enum -// Added "friend NamedNodeMap"; to NodeListDefinition -// - -#ifndef MITRE_DOM -#define MITRE_DOM - -#ifdef __BORLANDC__ -#include -#endif - -#include "List.h" -#include "nsIAtom.h" -#include "nsDoubleHashtable.h" -#include "nsString.h" -#include "nsVoidArray.h" -#include "txCore.h" -#include "nsAutoPtr.h" - -#define kTxNsNodeIndexOffset 0x00000000; -#define kTxAttrIndexOffset 0x40000000; -#define kTxChildIndexOffset 0x80000000; - -class NamedNodeMap; -class Document; -class Element; -class Attr; -class ProcessingInstruction; - -#define kNameSpaceID_Unknown -1 -#define kNameSpaceID_None 0 -// not really a namespace, but it needs to play the game -#define kNameSpaceID_XMLNS 1 -#define kNameSpaceID_XML 2 -// kNameSpaceID_XSLT is 6 for module, see nsINameSpaceManager.h -#define kNameSpaceID_XSLT 3 - -// -// Abstract Class defining the interface for a Node. See NodeDefinition below -// for the actual implementation of the WC3 node. -// -class Node : public TxObject -{ - public: - //Node type constants - //-- LF - changed to enum - enum NodeType { - ELEMENT_NODE = 1, - ATTRIBUTE_NODE, - TEXT_NODE, - CDATA_SECTION_NODE, - ENTITY_REFERENCE_NODE, - ENTITY_NODE, - PROCESSING_INSTRUCTION_NODE, - COMMENT_NODE, - DOCUMENT_NODE, - DOCUMENT_TYPE_NODE, - DOCUMENT_FRAGMENT_NODE, - NOTATION_NODE - }; - - virtual ~Node() {} - - //Read functions - virtual nsresult getNodeName(nsAString& aName) const = 0; - virtual nsresult getNodeValue(nsAString& aValue) = 0; - virtual unsigned short getNodeType() const = 0; - virtual Node* getParentNode() const = 0; - virtual Node* getFirstChild() const = 0; - virtual Node* getLastChild() const = 0; - virtual Node* getPreviousSibling() const = 0; - virtual Node* getNextSibling() const = 0; - virtual Document* getOwnerDocument() const = 0; - - //Node manipulation functions - virtual Node* appendChild(Node* newChild) = 0; - - virtual MBool hasChildNodes() const = 0; - - //From DOM3 26-Jan-2001 WD - virtual nsresult getBaseURI(nsAString& aURI) = 0; - - //Introduced in DOM2 - virtual nsresult getNamespaceURI(nsAString& aNSURI) = 0; - - //txXPathNode functions - virtual MBool getLocalName(nsIAtom** aLocalName) = 0; - virtual PRInt32 getNamespaceID() = 0; - virtual Node* getXPathParent() = 0; - virtual PRInt32 compareDocumentPosition(Node* aOther) = 0; -}; - -// -// Definition and Implementation of Node and NodeList functionality. This is -// the central class, from which all other DOM classes (objects) are derrived. -// Users of this DOM should work strictly with the Node interface and NodeList -// interface (see above for those definitions) -// -class NodeDefinition : public Node -{ - public: - virtual ~NodeDefinition(); //Destructor, delete all children of node - - //Read functions - virtual nsresult getNodeName(nsAString& aName) const; - nsresult getNodeValue(nsAString& aValue); - unsigned short getNodeType() const; - Node* getParentNode() const; - Node* getFirstChild() const; - Node* getLastChild() const; - Node* getPreviousSibling() const; - Node* getNextSibling() const; - Document* getOwnerDocument() const; - - //Child node manipulation functions - virtual Node* appendChild(Node* newChild); - - MBool hasChildNodes() const; - - //From DOM3 26-Jan-2001 WD - virtual nsresult getBaseURI(nsAString& aURI); - - //Introduced in DOM2 - nsresult getNamespaceURI(nsAString& aNSURI); - - //txXPathNode functions - virtual MBool getLocalName(nsIAtom** aLocalName); - virtual PRInt32 getNamespaceID(); - virtual Node* getXPathParent(); - virtual PRInt32 compareDocumentPosition(Node* aOther); - - //Only to be used from XMLParser - void appendData(const PRUnichar* aData, int aLength) - { - nodeValue.Append(aData, aLength); - }; - - protected: - friend class Document; - friend class txXPathTreeWalker; - friend class txXPathNodeUtils; - NodeDefinition(NodeType type, nsIAtom *aLocalName, - const nsAString& value, Document* owner); - - //Name, value, and attributes for this node. Available to derrived - //classes, since those derrived classes have a better idea how to use them, - //than the generic node does. - nsCOMPtr mLocalName; - nsString nodeValue; - - NodeDefinition* implAppendChild(NodeDefinition* newChild); - NodeDefinition* implRemoveChild(NodeDefinition* oldChild); - - private: - //Type of node this is - NodeType nodeType; - - //Data members for linking this Node to its parent and siblings - NodeDefinition* parentNode; - NodeDefinition* previousSibling; - NodeDefinition* nextSibling; - - //Pointer to the node's document - Document* ownerDocument; - - PRUint32 length; - - //Data members for maintaining a list of child nodes - NodeDefinition* firstChild; - NodeDefinition* lastChild; - - // Struct to hold document order information - struct OrderInfo { - ~OrderInfo(); - PRUint32* mOrder; - PRInt32 mSize; - Node* mRoot; - }; - - // OrderInfo object for comparing document order - OrderInfo* mOrderInfo; - - // Helperfunction for compareDocumentOrder - OrderInfo* getOrderInfo(); -}; - -// -//Definition and Implementation of a Document. -// - -/** - * nsDoubleHashtable definitions for IDs - * - * It may be possible to share the key value with the element, - * but that may leave entries without keys, as the entries - * are constructed from the key value and the setting of mElement - * happens late. As pldhash.h ain't clear on this, we store the - * key by inheriting from PLDHashStringEntry. - */ -class txIDEntry : public PLDHashStringEntry -{ -public: - txIDEntry(const void* aKey) : PLDHashStringEntry(aKey), mElement(nsnull) - { - } - ~txIDEntry() - { - } - Element* mElement; -}; -DECL_DHASH_WRAPPER(txIDMap, txIDEntry, nsAString&) - -class Document : public NodeDefinition -{ - public: - Document(); - - Element* getDocumentElement(); - - //Factory functions for various node types - Node* createComment(const nsAString& aData); - ProcessingInstruction* createProcessingInstruction(nsIAtom *aTarget, - const nsAString& aData); - Node* createTextNode(const nsAString& theData); - - Element* createElementNS(nsIAtom *aPrefix, nsIAtom *aLocalName, - PRInt32 aNamespaceID); - Element* getElementById(const nsAString& aID); - - // Node manipulation functions - Node* appendChild(Node* newChild); - - //Override to return documentBaseURI - nsresult getBaseURI(nsAString& aURI); - - private: - PRBool setElementID(const nsAString& aID, Element* aElement); - - Element* documentElement; - - // This class is friend to be able to set the documentBaseURI - // and IDs. - friend class txXMLParser; - txIDMap mIDMap; - nsString documentBaseURI; -}; - -// -//Definition and Implementation of an Element -// -class Element : public NodeDefinition -{ - public: - virtual ~Element(); - - NamedNodeMap* getAttributes(); - - nsresult appendAttributeNS(nsIAtom *aPrefix, nsIAtom *aLocalName, - PRInt32 aNamespaceID, const nsAString& aValue); - - // Node manipulation functions - Node* appendChild(Node* newChild); - - //txXPathNode functions override - nsresult getNodeName(nsAString& aName) const; - MBool getLocalName(nsIAtom** aLocalName); - PRInt32 getNamespaceID(); - MBool getAttr(nsIAtom* aLocalName, PRInt32 aNSID, nsAString& aValue); - MBool hasAttr(nsIAtom* aLocalName, PRInt32 aNSID); - - // ID getter - PRBool getIDValue(nsAString& aValue); - - Attr *getFirstAttribute() - { - return mFirstAttribute; - } - - private: - friend class Document; - void setIDValue(const nsAString& aValue); - - Element(nsIAtom *aPrefix, nsIAtom *aLocalName, PRInt32 aNamespaceID, - Document* aOwner); - - nsAutoPtr mFirstAttribute; - nsString mIDValue; - nsCOMPtr mPrefix; - PRInt32 mNamespaceID; -}; - -// -//Definition and Implementation of a Attr -// NOTE: For the time bing use just the default functionality found in the -// NodeDefinition class -// -class Attr : public NodeDefinition -{ - public: - virtual ~Attr(); - - // Node manipulation functions - Node* appendChild(Node* newChild); - - //txXPathNode functions override - nsresult getNodeName(nsAString& aName) const; - MBool getLocalName(nsIAtom** aLocalName); - PRInt32 getNamespaceID(); - Node* getXPathParent(); - PRBool equals(nsIAtom *aLocalName, PRInt32 aNamespaceID) - { - return mLocalName == aLocalName && aNamespaceID == mNamespaceID; - } - Attr *getNextAttribute() - { - return mNextAttribute; - } - - private: - friend class Element; - - Attr(nsIAtom *aPrefix, nsIAtom *aLocalName, PRInt32 aNamespaceID, - Element *aOwnerElement, const nsAString &aValue); - - nsCOMPtr mPrefix; - PRInt32 mNamespaceID; - Element *mOwnerElement; - nsAutoPtr mNextAttribute; -}; - -// -//Definition and Implemention of a ProcessingInstruction node. Most -//functionality is inherrited from NodeDefinition. -// The Target of a processing instruction is stored in the nodeName datamember -// inherrited from NodeDefinition. -// The Data of a processing instruction is stored in the nodeValue datamember -// inherrited from NodeDefinition -// -class ProcessingInstruction : public NodeDefinition -{ - public: - ~ProcessingInstruction(); - - //txXPathNode functions override - MBool getLocalName(nsIAtom** aLocalName); - - private: - friend class Document; - ProcessingInstruction(nsIAtom *theTarget, const nsAString& theData, - Document* owner); -}; - -class txStandaloneNamespaceManager -{ -public: - static PRInt32 getNamespaceID(const nsAString& aURI) - { - if (!mNamespaces && !init()) - return kNameSpaceID_Unknown; - - PRInt32 id = mNamespaces->IndexOf(aURI); - if (id != -1) { - return id + 1; - } - - if (!mNamespaces->AppendString(aURI)) { - NS_ASSERTION(0, "Out of memory, namespaces are getting lost"); - return kNameSpaceID_Unknown; - } - - return mNamespaces->Count(); - } - - static nsresult getNamespaceURI(const PRInt32 aID, nsAString& aNSURI) - { - // empty namespace, and errors - aNSURI.Truncate(); - if (aID <= 0 || (!mNamespaces && !init()) || - aID > mNamespaces->Count()) { - return NS_OK; - } - - aNSURI = *mNamespaces->StringAt(aID - 1); - return NS_OK; - } - - static MBool init() - { - NS_ASSERTION(!mNamespaces, - "called without matching shutdown()"); - if (mNamespaces) - return MB_TRUE; - mNamespaces = new nsStringArray(); - if (!mNamespaces) - return MB_FALSE; - /* - * Hardwiring some Namespace IDs. - * no Namespace is 0 - * xmlns prefix is 1, mapped to http://www.w3.org/2000/xmlns/ - * xml prefix is 2, mapped to http://www.w3.org/XML/1998/namespace - */ - if (!mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/2000/xmlns/")) || - !mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/XML/1998/namespace")) || - !mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/1999/XSL/Transform"))) { - delete mNamespaces; - mNamespaces = 0; - return MB_FALSE; - } - - return MB_TRUE; - } - - static void shutdown() - { - NS_ASSERTION(mNamespaces, "called without matching init()"); - if (!mNamespaces) - return; - delete mNamespaces; - mNamespaces = nsnull; - } - -private: - static nsStringArray* mNamespaces; -}; - -#define TX_IMPL_DOM_STATICS \ - nsStringArray* txStandaloneNamespaceManager::mNamespaces = 0 - -#endif diff --git a/extensions/transformiix/source/xml/parser/.cvsignore b/extensions/transformiix/source/xml/parser/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xml/parser/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xml/parser/Makefile.in b/extensions/transformiix/source/xml/parser/Makefile.in deleted file mode 100644 index 29589f011852..000000000000 --- a/extensions/transformiix/source/xml/parser/Makefile.in +++ /dev/null @@ -1,80 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxmlparser_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += necko \ - dom \ - content \ - layout \ - widget \ - js \ - xpconnect \ - caps \ - unicharutil \ - $(NULL) -else -REQUIRES += expat \ - $(NULL) -endif - -CPPSRCS = txXMLParser.cpp - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -DEFINES += -DXML_DTD -DXML_UNICODE - -INCLUDES += -I$(srcdir)/.. -I$(srcdir)/../../base -I$(srcdir)/../dom \ - -I$(srcdir)/../../xpath diff --git a/extensions/transformiix/source/xml/parser/txXMLParser.cpp b/extensions/transformiix/source/xml/parser/txXMLParser.cpp deleted file mode 100644 index 4bface5f3e9f..000000000000 --- a/extensions/transformiix/source/xml/parser/txXMLParser.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Tom Kneeland (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXMLParser.h" -#include "txURIUtils.h" -#include "txXPathTreeWalker.h" - -#ifndef TX_EXE -#include "nsIDocument.h" -#include "nsIDOMDocument.h" -#include "nsISyncLoadDOMService.h" -#include "nsNetUtil.h" -#else -#include "expat_config.h" -#include "expat.h" -#include "XMLUtils.h" -#endif - -#ifdef TX_EXE -/** - * Implementation of an In-Memory DOM based XML parser. The actual XML - * parsing is provided by EXPAT. - */ -class txXMLParser -{ - public: - nsresult parse(istream& aInputStream, const nsAString& aUri, - txXPathNode** aResultDoc); - const nsAString& getErrorString(); - - /** - * Expat handlers - */ - int StartElement(const XML_Char *aName, const XML_Char **aAtts); - int EndElement(const XML_Char* aName); - void CharacterData(const XML_Char* aChars, int aLength); - void Comment(const XML_Char* aChars); - int ProcessingInstruction(const XML_Char *aTarget, const XML_Char *aData); - int ExternalEntityRef(const XML_Char *aContext, const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId); - - protected: - void createErrorString(); - nsString mErrorString; - Document* mDocument; - Node* mCurrentNode; - XML_Parser mExpatParser; -}; -#endif - -nsresult -txParseDocumentFromURI(const nsAString& aHref, const nsAString& aReferrer, - const txXPathNode& aLoader, nsAString& aErrMsg, - txXPathNode** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; -#ifndef TX_EXE - nsCOMPtr documentURI; - nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref); - NS_ENSURE_SUCCESS(rv, rv); - - nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader); - - nsCOMPtr loadGroup = loaderDocument->GetDocumentLoadGroup(); - nsIURI *loaderUri = loaderDocument->GetDocumentURI(); - NS_ENSURE_TRUE(loaderUri, NS_ERROR_FAILURE); - - nsCOMPtr channel; - rv = NS_NewChannel(getter_AddRefs(channel), documentURI, nsnull, - loadGroup); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr http = do_QueryInterface(channel); - if (http) { - nsCOMPtr refUri; - NS_NewURI(getter_AddRefs(refUri), aReferrer); - if (refUri) { - http->SetReferrer(refUri); - } - http->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), - NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"), - PR_FALSE); - - - } - - nsCOMPtr loader = - do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - // Raw pointer, we want the resulting txXPathNode to hold a reference to - // the document. - nsIDOMDocument* theDocument = nsnull; - rv = loader->LoadDocumentAsXML(channel, loaderUri, &theDocument); - - PRBool succeeded = NS_SUCCEEDED(rv) && theDocument; - if (succeeded && http) { - PRBool httpSucceeded; - rv = http->GetRequestSucceeded(&httpSucceeded); - succeeded = NS_SUCCEEDED(rv) && httpSucceeded; - } - - if (!succeeded) { - aErrMsg.Append(NS_LITERAL_STRING("Document load of ") + - aHref + NS_LITERAL_STRING(" failed.")); - return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE; - } - - *aResult = txXPathNativeNode::createXPathNode(theDocument); - if (!*aResult) { - NS_RELEASE(theDocument); - return NS_ERROR_FAILURE; - } - - return NS_OK; -#else - istream* xslInput = URIUtils::getInputStream(aHref, aErrMsg); - if (!xslInput) { - return NS_ERROR_FAILURE; - } - return txParseFromStream(*xslInput, aHref, aErrMsg, aResult); -#endif -} - -#ifdef TX_EXE -nsresult -txParseFromStream(istream& aInputStream, const nsAString& aUri, - nsAString& aErrorString, txXPathNode** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - txXMLParser parser; - nsresult rv = parser.parse(aInputStream, aUri, aResult); - aErrorString = parser.getErrorString(); - return rv; -} - -/** - * expat C stub handlers - */ - -// shortcut macro for redirection into txXMLParser method calls -#define TX_XMLPARSER(_userData) NS_STATIC_CAST(txXMLParser*, _userData) -#define TX_ENSURE_DATA(_userData) \ - PR_BEGIN_MACRO \ - if (!aUserData) { \ - NS_WARNING("no userData in comment handler"); \ - return; \ - } \ - PR_END_MACRO - -PR_STATIC_CALLBACK(void) -startElement(void *aUserData, const XML_Char *aName, const XML_Char **aAtts) -{ - TX_ENSURE_DATA(aUserData); - TX_XMLPARSER(aUserData)->StartElement(aName, aAtts); -} - -PR_STATIC_CALLBACK(void) -endElement(void *aUserData, const XML_Char* aName) -{ - TX_ENSURE_DATA(aUserData); - TX_XMLPARSER(aUserData)->EndElement(aName); -} - -PR_STATIC_CALLBACK(void) -charData(void* aUserData, const XML_Char* aChars, int aLength) -{ - TX_ENSURE_DATA(aUserData); - TX_XMLPARSER(aUserData)->CharacterData(aChars, aLength); -} - -PR_STATIC_CALLBACK(void) -commentHandler(void* aUserData, const XML_Char* aChars) -{ - TX_ENSURE_DATA(aUserData); - TX_XMLPARSER(aUserData)->Comment(aChars); -} - -PR_STATIC_CALLBACK(void) -piHandler(void *aUserData, const XML_Char *aTarget, const XML_Char *aData) -{ - TX_ENSURE_DATA(aUserData); - TX_XMLPARSER(aUserData)->ProcessingInstruction(aTarget, aData); -} - -PR_STATIC_CALLBACK(int) -externalEntityRefHandler(XML_Parser aParser, - const XML_Char *aContext, - const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId) -{ - // aParser is aUserData is the txXMLParser, - // we set that in txXMLParser::parse - NS_ENSURE_TRUE(aParser, XML_ERROR_NONE); - return ((txXMLParser*)aParser)->ExternalEntityRef(aContext, aBase, - aSystemId, aPublicId); -} - - -/** - * Parses the given input stream and returns a DOM Document. - * A NULL pointer will be returned if errors occurred - */ -nsresult -txXMLParser::parse(istream& aInputStream, const nsAString& aUri, - txXPathNode** aResultDoc) -{ - mErrorString.Truncate(); - *aResultDoc = nsnull; - if (!aInputStream) { - mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered."); - return NS_ERROR_FAILURE; - } - - static const XML_Memory_Handling_Suite memsuite = { - (void *(*)(size_t))PR_Malloc, - (void *(*)(void *, size_t))PR_Realloc, - PR_Free - }; - static const PRUnichar expatSeparator = kExpatSeparatorChar; - mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator); - if (!mExpatParser) { - return NS_ERROR_OUT_OF_MEMORY; - } - mDocument = new Document(); - if (!mDocument) { - XML_ParserFree(mExpatParser); - return NS_ERROR_OUT_OF_MEMORY; - } - mDocument->documentBaseURI = aUri; - mCurrentNode = mDocument; - - XML_SetReturnNSTriplet(mExpatParser, XML_TRUE); - XML_SetUserData(mExpatParser, this); - XML_SetElementHandler(mExpatParser, startElement, endElement); - XML_SetCharacterDataHandler(mExpatParser, charData); - XML_SetProcessingInstructionHandler(mExpatParser, piHandler); - XML_SetCommentHandler(mExpatParser, commentHandler); -#ifdef XML_DTD - XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS); -#endif - XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler); - XML_SetExternalEntityRefHandlerArg(mExpatParser, this); - XML_SetBase(mExpatParser, - (const XML_Char*)(PromiseFlatString(aUri).get())); - - const int bufferSize = 1024; - char buf[bufferSize]; - PRBool done; - do { - aInputStream.read(buf, bufferSize); - done = aInputStream.eof(); - - if (!XML_Parse(mExpatParser, buf, aInputStream.gcount(), done)) { - createErrorString(); - done = MB_TRUE; - delete mDocument; - mDocument = nsnull; - } - } while (!done); - aInputStream.clear(); - - // clean up - XML_ParserFree(mExpatParser); - // ownership to the caller - *aResultDoc = txXPathNativeNode::createXPathNode(mDocument); - mDocument = nsnull; - return *aResultDoc ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -const nsAString& -txXMLParser::getErrorString() -{ - return mErrorString; -} - - -int -txXMLParser::StartElement(const XML_Char *aName, const XML_Char **aAtts) -{ - nsCOMPtr prefix, localName; - PRInt32 nsID; - XMLUtils::splitExpatName(aName, getter_AddRefs(prefix), - getter_AddRefs(localName), &nsID); - Element* newElement = mDocument->createElementNS(prefix, localName, nsID); - if (!newElement) { - return XML_ERROR_NO_MEMORY; - } - - const XML_Char** theAtts = aAtts; - while (*theAtts) { - XMLUtils::splitExpatName(*theAtts++, getter_AddRefs(prefix), - getter_AddRefs(localName), &nsID); - nsDependentString attValue(*theAtts++); - nsresult rv = newElement->appendAttributeNS(prefix, localName, nsID, - attValue); - if (NS_FAILED(rv)) { - return XML_ERROR_NO_MEMORY; - } - } - - int idx; - if ((idx = XML_GetIdAttributeIndex(mExpatParser)) > -1) { - nsDependentString idName((const PRUnichar*)*(aAtts + idx)); - nsDependentString idValue((const PRUnichar*)*(aAtts + idx + 1)); - // make sure IDs are unique - if (!idValue.IsEmpty()) { - mDocument->setElementID(idValue, newElement); - } - } - mCurrentNode->appendChild(newElement); - mCurrentNode = newElement; - - return XML_ERROR_NONE; -} - -int -txXMLParser::EndElement(const XML_Char* aName) -{ - if (mCurrentNode->getParentNode()) { - mCurrentNode = mCurrentNode->getParentNode(); - } - return XML_ERROR_NONE; -} - -void -txXMLParser::CharacterData(const XML_Char* aChars, int aLength) -{ - Node* prevSib = mCurrentNode->getLastChild(); - const PRUnichar* pChars = NS_STATIC_CAST(const PRUnichar*, aChars); - if (prevSib && prevSib->getNodeType() == Node::TEXT_NODE) { - NS_STATIC_CAST(NodeDefinition*, prevSib)->appendData(pChars, aLength); - } - else { - // aChars is not null-terminated so we use Substring here. - Node* node = mDocument->createTextNode(Substring(pChars, - pChars + aLength)); - mCurrentNode->appendChild(node); - } -} - -void -txXMLParser::Comment(const XML_Char* aChars) -{ - Node* node = mDocument->createComment( - nsDependentString(NS_STATIC_CAST(const PRUnichar*, aChars))); - mCurrentNode->appendChild(node); -} - -int -txXMLParser::ProcessingInstruction(const XML_Char *aTarget, - const XML_Char *aData) -{ - nsCOMPtr target = do_GetAtom(aTarget); - nsDependentString data((const PRUnichar*)aData); - Node* node = mDocument->createProcessingInstruction(target, data); - mCurrentNode->appendChild(node); - - return XML_ERROR_NONE; -} - -int -txXMLParser::ExternalEntityRef(const XML_Char *aContext, - const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId) -{ - if (aPublicId) { - // not supported, this is "http://some.site.net/foo.dtd" stuff - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - nsAutoString absUrl; - URIUtils::resolveHref(nsDependentString((PRUnichar*)aSystemId), - nsDependentString((PRUnichar*)aBase), absUrl); - istream* extInput = URIUtils::getInputStream(absUrl, mErrorString); - if (!extInput) { - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - XML_Parser parent = mExpatParser; - mExpatParser = - XML_ExternalEntityParserCreate(mExpatParser, aContext, nsnull); - if (!mExpatParser) { - mExpatParser = parent; - delete extInput; - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - XML_SetBase(mExpatParser, absUrl.get()); - - const int bufSize = 1024; - char buffer[bufSize]; - int result; - PRBool done; - do { - extInput->read(buffer, bufSize); - done = extInput->eof(); - if (!(result = - XML_Parse(mExpatParser, buffer, extInput->gcount(), done))) { - createErrorString(); - mErrorString.Append(PRUnichar('\n')); - done = MB_TRUE; - } - } while (!done); - - delete extInput; - XML_ParserFree(mExpatParser); - - mExpatParser = parent; - - return result; -} - -void -txXMLParser::createErrorString() -{ - XML_Error errCode = XML_GetErrorCode(mExpatParser); - mErrorString.AppendWithConversion(XML_ErrorString(errCode)); - mErrorString.AppendLiteral(" at line "); - mErrorString.AppendInt(XML_GetCurrentLineNumber(mExpatParser)); - mErrorString.AppendLiteral(" in "); - mErrorString.Append((const PRUnichar*)XML_GetBase(mExpatParser)); -} -#endif diff --git a/extensions/transformiix/source/xml/parser/txXMLParser.h b/extensions/transformiix/source/xml/parser/txXMLParser.h deleted file mode 100644 index 272d6111f3eb..000000000000 --- a/extensions/transformiix/source/xml/parser/txXMLParser.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Tom Kneeland (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef MITRE_XMLPARSER_H -#define MITRE_XMLPARSER_H - -#include "txCore.h" - -#ifdef TX_EXE -#include -#endif - -class txXPathNode; - -/** - * API to load XML files into DOM datastructures. - * Parsing is either done by expat, or by expat via the syncloaderservice - */ - -/** - * Parse a document from the aHref location, with referrer URI on behalf - * of the document aLoader. - */ -extern "C" nsresult -txParseDocumentFromURI(const nsAString& aHref, const nsAString& aReferrer, - const txXPathNode& aLoader, nsAString& aErrMsg, - txXPathNode** aResult); - -#ifdef TX_EXE -/** - * Parse a document from the given stream - */ -extern "C" nsresult -txParseFromStream(istream& aInputStream, const nsAString& aUri, - nsAString& aErrorString, txXPathNode** aResult); -#endif -#endif diff --git a/extensions/transformiix/source/xpath/.cvsignore b/extensions/transformiix/source/xpath/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xpath/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xpath/AdditiveExpr.cpp b/extensions/transformiix/source/xpath/AdditiveExpr.cpp deleted file mode 100644 index acf5b01d732c..000000000000 --- a/extensions/transformiix/source/xpath/AdditiveExpr.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Represents a AdditiveExpr, an binary expression that - * performs an additive operation between it's lvalue and rvalue: - * + : addition - * - : subtraction -**/ - -#include "Expr.h" -#include "ExprResult.h" -#include "txIXPathContext.h" - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -AdditiveExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = rightExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - double rightDbl = exprRes->numberValue(); - - rv = leftExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - double leftDbl = exprRes->numberValue(); - - double result = 0; - switch ( op ) { - case SUBTRACTION: - result = leftDbl - rightDbl; - break; - default: - result = leftDbl + rightDbl; - break; - } - - return aContext->recycler()->getNumberResult(result, aResult); -} //-- evaluate - -#ifdef TX_TO_STRING -void -AdditiveExpr::toString(nsAString& str) -{ - if ( leftExpr ) leftExpr->toString(str); - else str.AppendLiteral("null"); - - switch ( op ) { - case SUBTRACTION: - str.AppendLiteral(" - "); - break; - default: - str.AppendLiteral(" + "); - break; - } - if ( rightExpr ) rightExpr->toString(str); - else str.AppendLiteral("null"); - -} -#endif - diff --git a/extensions/transformiix/source/xpath/AttributeValueTemplate.cpp b/extensions/transformiix/source/xpath/AttributeValueTemplate.cpp deleted file mode 100644 index 8234baf8ab2e..000000000000 --- a/extensions/transformiix/source/xpath/AttributeValueTemplate.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * AttributeValueTemplate -**/ - -#include "Expr.h" -#include "ExprResult.h" -#include "txIXPathContext.h" - -/** - * Create a new AttributeValueTemplate -**/ -AttributeValueTemplate::AttributeValueTemplate() {} - -/** - * Default destructor -**/ -AttributeValueTemplate::~AttributeValueTemplate() { - txListIterator iter(&expressions); - while (iter.hasNext()) { - delete (Expr*)iter.next(); - } -} //-- ~AttributeValueTemplate - -/** - * Adds the given Expr to this AttributeValueTemplate -**/ -void AttributeValueTemplate::addExpr(Expr* expr) { - if (expr) expressions.add(expr); -} //-- addExpr - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -AttributeValueTemplate::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - - txListIterator iter(&expressions); - nsRefPtr strRes; - nsresult rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes)); - NS_ENSURE_SUCCESS(rv, rv); - - while (iter.hasNext()) { - Expr* expr = (Expr*)iter.next(); - nsRefPtr exprResult; - nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - exprResult->stringValue(strRes->mValue); - } - - *aResult = strRes; - - NS_ADDREF(*aResult); - - return NS_OK; -} //-- evaluate - -#ifdef TX_TO_STRING -void -AttributeValueTemplate::toString(nsAString& str) -{ - txListIterator iter(&expressions); - while (iter.hasNext()) { - str.Append(PRUnichar('{')); - Expr* expr = (Expr*)iter.next(); - expr->toString(str); - str.Append(PRUnichar('}')); - } -} -#endif diff --git a/extensions/transformiix/source/xpath/BooleanExpr.cpp b/extensions/transformiix/source/xpath/BooleanExpr.cpp deleted file mode 100644 index 841250bcb7c4..000000000000 --- a/extensions/transformiix/source/xpath/BooleanExpr.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -/** - * Represents a BooleanExpr, a binary expression that - * performs a boolean operation between it's lvalue and rvalue. -**/ - -#include "Expr.h" -#include "ExprResult.h" -#include "txIXPathContext.h" - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -BooleanExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = leftExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool lval = exprRes->booleanValue(); - - // check for early decision - if (op == OR && lval) { - aContext->recycler()->getBoolResult(PR_TRUE, aResult); - - return NS_OK; - } - if (op == AND && !lval) { - aContext->recycler()->getBoolResult(PR_FALSE, aResult); - - return NS_OK; - } - - rv = rightExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - // just use rval, since we already checked lval - aContext->recycler()->getBoolResult(exprRes->booleanValue(), aResult); - - return NS_OK; -} //-- evaluate - -#ifdef TX_TO_STRING -void -BooleanExpr::toString(nsAString& str) -{ - if ( leftExpr ) leftExpr->toString(str); - else str.AppendLiteral("null"); - - switch ( op ) { - case OR: - str.AppendLiteral(" or "); - break; - default: - str.AppendLiteral(" and "); - break; - } - if ( rightExpr ) rightExpr->toString(str); - else str.AppendLiteral("null"); - -} -#endif diff --git a/extensions/transformiix/source/xpath/BooleanFunctionCall.cpp b/extensions/transformiix/source/xpath/BooleanFunctionCall.cpp deleted file mode 100644 index 855261202cf7..000000000000 --- a/extensions/transformiix/source/xpath/BooleanFunctionCall.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "ExprResult.h" -#include "FunctionLib.h" -#include "nsReadableUtils.h" -#include "txAtoms.h" -#include "txError.h" -#include "txIXPathContext.h" -#include "txStringUtils.h" -#include "txXPathTreeWalker.h" - -/** - * Creates a default BooleanFunctionCall, which always evaluates to False -**/ -BooleanFunctionCall::BooleanFunctionCall(BooleanFunctions aType) - : mType(aType) -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -BooleanFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - txListIterator iter(¶ms); - switch (mType) { - case TX_BOOLEAN: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - aContext->recycler()->getBoolResult( - evaluateToBoolean((Expr*)iter.next(), aContext), aResult); - - return NS_OK; - } - case TX_LANG: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - txXPathTreeWalker walker(aContext->getContextNode()); - - nsAutoString lang; - PRBool found; - do { - found = walker.getAttr(txXMLAtoms::lang, kNameSpaceID_XML, - lang); - } while (!found && walker.moveToParent()); - - if (!found) { - aContext->recycler()->getBoolResult(PR_FALSE, aResult); - - return NS_OK; - } - - nsAutoString arg; - evaluateToString((Expr*)iter.next(), aContext, arg); - PRBool result = arg.Equals(Substring(lang, 0, arg.Length()), - txCaseInsensitiveStringComparator()) && - (lang.Length() == arg.Length() || - lang.CharAt(arg.Length()) == '-'); - - aContext->recycler()->getBoolResult(result, aResult); - - return NS_OK; - } - case TX_NOT: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - aContext->recycler()->getBoolResult( - !evaluateToBoolean((Expr*)iter.next(), aContext), aResult); - - return NS_OK; - } - case TX_TRUE: - { - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - aContext->recycler()->getBoolResult(PR_TRUE, aResult); - - return NS_OK; - } - case TX_FALSE: - { - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - aContext->recycler()->getBoolResult(PR_FALSE, aResult); - - return NS_OK; - } - } - - aContext->receiveError(NS_LITERAL_STRING("Internal error"), - NS_ERROR_UNEXPECTED); - return NS_ERROR_UNEXPECTED; -} - -#ifdef TX_TO_STRING -nsresult -BooleanFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - switch (mType) { - case TX_BOOLEAN: - { - *aAtom = txXPathAtoms::boolean; - break; - } - case TX_LANG: - { - *aAtom = txXPathAtoms::lang; - break; - } - case TX_NOT: - { - *aAtom = txXPathAtoms::_not; - break; - } - case TX_TRUE: - { - *aAtom = txXPathAtoms::_true; - break; - } - case TX_FALSE: - { - *aAtom = txXPathAtoms::_false; - break; - } - default: - { - *aAtom = 0; - return NS_ERROR_FAILURE; - } - } - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xpath/BooleanResult.cpp b/extensions/transformiix/source/xpath/BooleanResult.cpp deleted file mode 100644 index c61df5d73dbd..000000000000 --- a/extensions/transformiix/source/xpath/BooleanResult.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * Boolean Expression result -*/ - -#include "ExprResult.h" - -/** - * Creates a new BooleanResult with the value of the given MBool parameter - * @param boolean the MBool to use for initialization of this BooleanResult's value -**/ -BooleanResult::BooleanResult(PRBool boolean) - : txAExprResult(nsnull) -{ - this->value = boolean; -} //-- BooleanResult - -/* - * Virtual Methods from ExprResult -*/ - -short BooleanResult::getResultType() { - return txAExprResult::BOOLEAN; -} //-- getResultType - -void BooleanResult::stringValue(nsAString& str) { - if ( value ) str.AppendLiteral("true"); - else str.AppendLiteral("false"); -} //-- toString - -nsAString* -BooleanResult::stringValuePointer() -{ - // In theory we could set strings containing "true" and "false" somewhere, - // but most stylesheets never get the stringvalue of a bool so that won't - // really buy us anything. - return nsnull; -} - -MBool BooleanResult::booleanValue() { - return this->value; -} //-- toBoolean - -double BooleanResult::numberValue() { - return ( value ) ? 1.0 : 0.0; -} //-- toNumber diff --git a/extensions/transformiix/source/xpath/Expr.h b/extensions/transformiix/source/xpath/Expr.h deleted file mode 100644 index 76b3a2540d75..000000000000 --- a/extensions/transformiix/source/xpath/Expr.h +++ /dev/null @@ -1,743 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * Larry Fitzpatick, OpenText - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_EXPR_H -#define TRANSFRMX_EXPR_H - -#include "List.h" -#include "nsAutoPtr.h" -#include "txCore.h" -#include "nsString.h" - -#ifdef DEBUG -#define TX_TO_STRING -#endif - -/* - XPath class definitions. - Much of this code was ported from XSL:P. -*/ - -class nsIAtom; -class txAExprResult; -class txIParseContext; -class txIMatchContext; -class txIEvalContext; -class txNodeSet; -class txXPathNode; - -/** - * A Base Class for all XSL Expressions -**/ -class Expr : public TxObject { - -public: - - /** - * Virtual destructor, important for subclasses - **/ - virtual ~Expr() - { - } - - /** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - **/ - virtual nsresult evaluate(txIEvalContext* aContext, - txAExprResult** aResult) = 0; - -#ifdef TX_TO_STRING - /** - * Returns the String representation of this Expr. - * @param dest the String to use when creating the String - * representation. The String representation will be appended to - * any data in the destination String, to allow cascading calls to - * other #toString() methods for Expressions. - * @return the String representation of this Expr. - **/ - virtual void toString(nsAString& str) = 0; -#endif -}; //-- Expr - -#define TX_DECL_EVALUATE \ - nsresult evaluate(txIEvalContext* aContext, txAExprResult** aResult) - -#ifndef TX_TO_STRING -#define TX_DECL_EXPR TX_DECL_EVALUATE -#define TX_DECL_FUNCTION TX_DECL_EVALUATE -#else -#define TX_DECL_EXPR \ - TX_DECL_EVALUATE; \ - void toString(nsAString& aDest) - -#define TX_DECL_FUNCTION \ - TX_DECL_EVALUATE; \ - nsresult getNameAtom(nsIAtom** aAtom) -#endif - -/** - * This class represents a FunctionCall as defined by the XPath 1.0 - * Recommendation. -**/ -class FunctionCall : public Expr { - -public: - virtual ~FunctionCall(); - - /** - * Adds the given parameter to this FunctionCall's parameter list. - * The ownership of the given Expr is passed over to the FunctionCall, - * even on failure. - * @param aExpr the Expr to add to this FunctionCall's parameter list - * @return nsresult indicating out of memory - */ - nsresult addParam(Expr* aExpr); - - /** - * Check if the number of parameters falls within a range. - * - * @param aParamCountMin minimum number of required parameters. - * @param aParamCountMax maximum number of parameters. If aParamCountMax - * is negative the maximum number is not checked. - * @return boolean representing whether the number of parameters falls - * within the expected range or not. - * - * XXX txIEvalContext should be txIParseContest, bug 143291 - */ - virtual PRBool requireParams(PRInt32 aParamCountMin, - PRInt32 aParamCountMax, - txIEvalContext* aContext); - -#ifdef TX_TO_STRING - void toString(nsAString& aDest); -#endif - -protected: - - txList params; - - FunctionCall(); - - /* - * Evaluates the given Expression and converts its result to a String. - * The value is appended to the given destination String - */ - void evaluateToString(Expr* aExpr, txIEvalContext* aContext, - nsAString& aDest); - - /* - * Evaluates the given Expression and converts its result to a number. - */ - double evaluateToNumber(Expr* aExpr, txIEvalContext* aContext); - - /* - * Evaluates the given Expression and converts its result to a boolean. - */ - MBool evaluateToBoolean(Expr* aExpr, txIEvalContext* aContext); - - /* - * Evaluates the given Expression and converts its result to a NodeSet. - * If the result is not a NodeSet an error is returned. - */ - nsresult evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext, - txNodeSet** aResult); - -#ifdef TX_TO_STRING - /* - * Returns the name of the function as an atom. - */ - virtual nsresult getNameAtom(nsIAtom** aAtom) = 0; -#endif -}; //-- FunctionCall - - -/** - * Represents an AttributeValueTemplate -**/ -class AttributeValueTemplate: public Expr { - -public: - - AttributeValueTemplate(); - - virtual ~AttributeValueTemplate(); - - /** - * Adds the given Expr to this AttributeValueTemplate - **/ - void addExpr(Expr* expr); - - TX_DECL_EXPR; - -private: - List expressions; -}; - - -/* - * This class represents a NodeTest as defined by the XPath spec - */ -class txNodeTest -{ -public: - virtual ~txNodeTest() {} - /* - * Virtual methods - * pretty much a txPattern, but not supposed to be used - * standalone. The NodeTest node() is different to the - * Pattern "node()" (document node isn't matched) - */ - virtual PRBool matches(const txXPathNode& aNode, - txIMatchContext* aContext) = 0; - virtual double getDefaultPriority() = 0; - -#ifdef TX_TO_STRING - virtual void toString(nsAString& aDest) = 0; -#endif -}; - -#define TX_DECL_NODE_TEST_BASE \ - PRBool matches(const txXPathNode& aNode, txIMatchContext* aContext); \ - double getDefaultPriority() - -#ifndef TX_TO_STRING -#define TX_DECL_NODE_TEST TX_DECL_NODE_TEST_BASE -#else -#define TX_DECL_NODE_TEST \ - TX_DECL_NODE_TEST_BASE; \ - void toString(nsAString& aDest) -#endif - -/* - * This class represents a NameTest as defined by the XPath spec - */ -class txNameTest : public txNodeTest -{ -public: - /* - * Creates a new txNameTest with the given type and the given - * principal node type - */ - txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID, - PRUint16 aNodeType); - - ~txNameTest(); - - TX_DECL_NODE_TEST; - -private: - nsCOMPtr mPrefix; - nsCOMPtr mLocalName; - PRInt32 mNamespace; - PRUint16 mNodeType; -}; - -/* - * This class represents a NodeType as defined by the XPath spec - */ -class txNodeTypeTest : public txNodeTest -{ -public: - enum NodeType { - COMMENT_TYPE, - TEXT_TYPE, - PI_TYPE, - NODE_TYPE - }; - - /* - * Creates a new txNodeTypeTest of the given type - */ - txNodeTypeTest(NodeType aNodeType); - - ~txNodeTypeTest(); - - /* - * Sets the name of the node to match. Only availible for pi nodes - */ - void setNodeName(const nsAString& aName); - - TX_DECL_NODE_TEST; - -private: - NodeType mNodeType; - nsCOMPtr mNodeName; -}; - -/** - * Represents an ordered list of Predicates, - * for use with Step and Filter Expressions -**/ -class PredicateList { - -public: - - /** - * Creates a new PredicateList - **/ - PredicateList(); - /** - * Destructor, will delete all Expressions in the list, so remove - * any you may need - **/ - virtual ~PredicateList(); - - /** - * Adds the given Expr to the list. - * The ownership of the given Expr is passed over the PredicateList, - * even on failure. - * @param aExpr the Expr to add to the list - * @return nsresult indicating out of memory - */ - nsresult add(Expr* aExpr); - - nsresult evaluatePredicates(txNodeSet* aNodes, txIMatchContext* aContext); - - /** - * returns true if this predicate list is empty - **/ - MBool isEmpty(); - -#ifdef TX_TO_STRING - /** - * Returns the String representation of this PredicateList. - * @param dest the String to use when creating the String - * representation. The String representation will be appended to - * any data in the destination String, to allow cascading calls to - * other #toString() methods for Expressions. - * @return the String representation of this PredicateList. - **/ - virtual void toString(nsAString& dest); -#endif - -protected: - //-- list of predicates - List predicates; -}; //-- PredicateList - -class LocationStep : public PredicateList, - public Expr -{ -public: - enum LocationStepType { - ANCESTOR_AXIS = 0, - ANCESTOR_OR_SELF_AXIS, - ATTRIBUTE_AXIS, - CHILD_AXIS, - DESCENDANT_AXIS, - DESCENDANT_OR_SELF_AXIS, - FOLLOWING_AXIS, - FOLLOWING_SIBLING_AXIS, - NAMESPACE_AXIS, - PARENT_AXIS, - PRECEDING_AXIS, - PRECEDING_SIBLING_AXIS, - SELF_AXIS - }; - - /** - * Creates a new LocationStep using the given NodeExpr and Axis Identifier - * @param nodeExpr the NodeExpr to use when matching Nodes - * @param axisIdentifier the Axis Identifier in which to search for nodes - **/ - LocationStep(nsAutoPtr& aNodeTest, - LocationStepType aAxisIdentifier) - : mNodeTest(aNodeTest), - mAxisIdentifier(aAxisIdentifier) - { - } - - TX_DECL_EXPR; - -private: - void fromDescendants(const txXPathNode& aNode, txIMatchContext* aCs, - txNodeSet* aNodes); - void fromDescendantsRev(const txXPathNode& aNode, txIMatchContext* aCs, - txNodeSet* aNodes); - - nsAutoPtr mNodeTest; - LocationStepType mAxisIdentifier; -}; - -class FilterExpr : public PredicateList, public Expr { - -public: - - /** - * Creates a new FilterExpr using the given Expr - * @param expr the Expr to use for evaluation - */ - FilterExpr(nsAutoPtr& aExpr) - : expr(aExpr) - { - } - - TX_DECL_EXPR; - -private: - nsAutoPtr expr; - -}; //-- FilterExpr - - -class txLiteralExpr : public Expr { -public: - txLiteralExpr(double aDbl); - txLiteralExpr(const nsAString& aStr); - - TX_DECL_EXPR; - -private: - nsRefPtr mValue; -}; - -/** - * Represents an AdditiveExpr, a binary expression that - * performs an additive operation between it's lvalue and rvalue: - * + : add - * - : subtract -**/ -class AdditiveExpr : public Expr { - -public: - - //-- AdditiveExpr Types - //-- LF, changed from static const short to enum - enum _AdditiveExprType { ADDITION = 1, SUBTRACTION }; - - AdditiveExpr(nsAutoPtr& aLeftExpr, nsAutoPtr& aRightExpr, - short aOp) - : op(aOp), - leftExpr(aLeftExpr), - rightExpr(aRightExpr) - { - } - - TX_DECL_EXPR; - -private: - short op; - nsAutoPtr leftExpr, rightExpr; -}; //-- AdditiveExpr - -/** - * Represents an UnaryExpr. Returns the negative value of it's expr. -**/ -class UnaryExpr : public Expr { - -public: - - UnaryExpr(nsAutoPtr& aExpr) - : expr(aExpr) - { - } - - TX_DECL_EXPR; - -private: - nsAutoPtr expr; -}; //-- UnaryExpr - -/** - * Represents a BooleanExpr, a binary expression that - * performs a boolean operation between it's lvalue and rvalue. -**/ -class BooleanExpr : public Expr { - -public: - - //-- BooleanExpr Types - enum _BooleanExprType { AND = 1, OR }; - - BooleanExpr(nsAutoPtr& aLeftExpr, nsAutoPtr& aRightExpr, - short aOp) - : op(aOp), - leftExpr(aLeftExpr), - rightExpr(aRightExpr) - { - } - - TX_DECL_EXPR; - -private: - short op; - nsAutoPtr leftExpr, rightExpr; -}; //-- BooleanExpr - -/** - * Represents a MultiplicativeExpr, a binary expression that - * performs a multiplicative operation between it's lvalue and rvalue: - * * : multiply - * mod : modulus - * div : divide - * -**/ -class MultiplicativeExpr : public Expr { - -public: - - //-- MultiplicativeExpr Types - //-- LF, changed from static const short to enum - enum _MultiplicativeExprType { DIVIDE = 1, MULTIPLY, MODULUS }; - - MultiplicativeExpr(nsAutoPtr& aLeftExpr, - nsAutoPtr& aRightExpr, - short aOp) - : op(aOp), - leftExpr(aLeftExpr), - rightExpr(aRightExpr) - { - } - - TX_DECL_EXPR; - -private: - short op; - nsAutoPtr leftExpr, rightExpr; -}; //-- MultiplicativeExpr - -/** - * Represents a RelationalExpr, an expression that compares it's lvalue - * to it's rvalue using: - * = : equal to - * < : less than - * > : greater than - * <= : less than or equal to - * >= : greater than or equal to - * -**/ -class RelationalExpr : public Expr { - -public: - enum RelationalExprType { - EQUAL, - NOT_EQUAL, - LESS_THAN, - GREATER_THAN, - LESS_OR_EQUAL, - GREATER_OR_EQUAL - }; - - RelationalExpr(nsAutoPtr& aLeftExpr, nsAutoPtr& aRightExpr, - RelationalExprType aOp) - : mLeftExpr(aLeftExpr), - mRightExpr(aRightExpr), - mOp(aOp) - { - } - - - TX_DECL_EXPR; - -private: - PRBool compareResults(txIEvalContext* aContext, txAExprResult* aLeft, - txAExprResult* aRight); - - nsAutoPtr mLeftExpr; - nsAutoPtr mRightExpr; - RelationalExprType mOp; -}; - -/** - * VariableRefExpr - * Represents a variable reference ($refname) -**/ -class VariableRefExpr : public Expr { - -public: - - VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID); - ~VariableRefExpr(); - - TX_DECL_EXPR; - -private: - nsCOMPtr mPrefix; - nsCOMPtr mLocalName; - PRInt32 mNamespace; -}; - -/** - * Represents a PathExpr -**/ -class PathExpr : public Expr { - -public: - - //-- Path Operators - //-- RELATIVE_OP is the default - //-- LF, changed from static const short to enum - enum PathOperator { RELATIVE_OP, DESCENDANT_OP }; - - /** - * Creates a new PathExpr - **/ - PathExpr(); - - /** - * Destructor, will delete all Expressions - **/ - virtual ~PathExpr(); - - /** - * Adds the Expr to this PathExpr - * The ownership of the given Expr is passed over the PathExpr, - * even on failure. - * @param aExpr the Expr to add to this PathExpr - * @return nsresult indicating out of memory - */ - nsresult addExpr(Expr* aExpr, PathOperator pathOp); - - TX_DECL_EXPR; - -private: - class PathExprItem { - public: - PathExprItem(Expr* aExpr, PathOperator aOp) - : expr(aExpr), - pathOp(aOp) - {} - nsAutoPtr expr; - PathOperator pathOp; - }; - - List expressions; - - /* - * Selects from the descendants of the context node - * all nodes that match the Expr - */ - nsresult evalDescendants(Expr* aStep, const txXPathNode& aNode, - txIMatchContext* aContext, - txNodeSet* resNodes); -}; - -/** - * This class represents a RootExpr, which only matches the Document node -**/ -class RootExpr : public Expr { -public: - /** - * Creates a new RootExpr - */ - RootExpr() -#ifdef TX_TO_STRING - : mSerialize(PR_TRUE) -#endif - { - } - - TX_DECL_EXPR; - -#ifdef TX_TO_STRING -public: - void setSerialize(PRBool aSerialize) - { - mSerialize = aSerialize; - } - -private: - // When a RootExpr is used in a PathExpr it shouldn't be serialized - PRBool mSerialize; -#endif -}; //-- RootExpr - -/** - * Represents a UnionExpr -**/ -class UnionExpr : public Expr { - -public: - - /** - * Creates a new UnionExpr - **/ - UnionExpr(); - - /** - * Destructor, will delete all Path Expressions - **/ - virtual ~UnionExpr(); - - /** - * Adds the PathExpr to this UnionExpr - * The ownership of the given Expr is passed over the UnionExpr, - * even on failure. - * @param aExpr the Expr to add to this UnionExpr - * @return nsresult indicating out of memory - */ - nsresult addExpr(Expr* aExpr); - - TX_DECL_EXPR; - -private: - - List expressions; - -}; //-- UnionExpr - -/** - * Expression that failed to parse - */ -class txErrorExpr : public Expr -{ -public: -#ifdef TX_TO_STRING - txErrorExpr(const nsAString& aStr) - : mStr(aStr) - { - } -#endif - - TX_DECL_EXPR; - -#ifdef TX_TO_STRING -private: - nsString mStr; -#endif -}; - -#endif - - diff --git a/extensions/transformiix/source/xpath/ExprLexer.cpp b/extensions/transformiix/source/xpath/ExprLexer.cpp deleted file mode 100644 index ccb5584a105a..000000000000 --- a/extensions/transformiix/source/xpath/ExprLexer.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Lexical analyzer for XPath expressions - */ - -#include "ExprLexer.h" -#include "txAtoms.h" -#include "nsString.h" -#include "txError.h" -#include "XMLUtils.h" - -/** - * Creates a new ExprLexer - */ -txExprLexer::txExprLexer() - : mCurrentItem(nsnull), - mFirstItem(nsnull), - mLastItem(nsnull), - mTokenCount(0) -{ -} - -/** - * Destroys this instance of an txExprLexer - */ -txExprLexer::~txExprLexer() -{ - //-- delete tokens - Token* tok = mFirstItem; - while (tok) { - Token* temp = tok->mNext; - delete tok; - tok = temp; - } - mCurrentItem = nsnull; -} - -Token* -txExprLexer::nextToken() -{ - NS_ASSERTION(mCurrentItem, "nextToken called beyoned the end"); - Token* token = mCurrentItem; - mCurrentItem = mCurrentItem->mNext; - return token; -} - -void -txExprLexer::pushBack() -{ - mCurrentItem = mCurrentItem ? mCurrentItem->mPrevious : mLastItem; -} - -void -txExprLexer::addToken(Token* aToken) -{ - if (mLastItem) { - aToken->mPrevious = mLastItem; - mLastItem->mNext = aToken; - } - if (!mFirstItem) { - mFirstItem = aToken; - mCurrentItem = aToken; - } - mLastItem = aToken; - ++mTokenCount; -} - -/** - * Returns true if the following Token should be an operator. - * This is a helper for the first bullet of [XPath 3.7] - * Lexical Structure - */ -PRBool -txExprLexer::nextIsOperatorToken(Token* aToken) -{ - if (!aToken || aToken->mType == Token::NULL_TOKEN) { - return PR_FALSE; - } - /* This relies on the tokens having the right order in ExprLexer.h */ - return aToken->mType < Token::COMMA || - aToken->mType > Token::UNION_OP; - -} - -/** - * Parses the given string into a sequence of Tokens - */ -nsresult -txExprLexer::parse(const nsASingleFragmentString& aPattern) -{ - iterator start, end; - start = aPattern.BeginReading(mPosition); - aPattern.EndReading(end); - - //-- initialize previous token, this will automatically get - //-- deleted when it goes out of scope - Token nullToken(nsnull, nsnull, Token::NULL_TOKEN); - - Token::Type defType; - Token* newToken = nsnull; - Token* prevToken = &nullToken; - PRBool isToken; - - while (mPosition < end) { - - defType = Token::CNAME; - isToken = PR_TRUE; - - if (*mPosition == DOLLAR_SIGN) { - if (++mPosition == end || !XMLUtils::isLetter(*mPosition)) { - return NS_ERROR_XPATH_INVALID_VAR_NAME; - } - defType = Token::VAR_REFERENCE; - } - // just reuse the QName parsing, which will use defType - // the token to construct - - if (XMLUtils::isLetter(*mPosition)) { - // NCName, can get QName or OperatorName; - // FunctionName, NodeName, and AxisSpecifier may want whitespace, - // and are dealt with below - start = mPosition; - while (++mPosition < end && XMLUtils::isNCNameChar(*mPosition)) { - /* just go */ - } - if (mPosition < end && *mPosition == COLON) { - // try QName or wildcard, might need to step back for axis - if (++mPosition == end) { - return NS_ERROR_XPATH_UNEXPECTED_END; - } - if (XMLUtils::isLetter(*mPosition)) { - while (++mPosition < end && XMLUtils::isNCNameChar(*mPosition)) { - /* just go */ - } - } - else if (*mPosition == '*' && defType != Token::VAR_REFERENCE) { - // eat wildcard for NameTest, bail for var ref at COLON - ++mPosition; - } - else { - --mPosition; // step back - } - } - if (nextIsOperatorToken(prevToken)) { - NS_ConvertUTF16toUTF8 opUTF8(Substring(start, mPosition)); - if (txXPathAtoms::_and->EqualsUTF8(opUTF8)) { - defType = Token::AND_OP; - } - else if (txXPathAtoms::_or->EqualsUTF8(opUTF8)) { - defType = Token::OR_OP; - } - else if (txXPathAtoms::mod->EqualsUTF8(opUTF8)) { - defType = Token::MODULUS_OP; - } - else if (txXPathAtoms::div->EqualsUTF8(opUTF8)) { - defType = Token::DIVIDE_OP; - } - else { - // XXX QUESTION: spec is not too precise - // badops is sure an error, but is bad:ops, too? We say yes! - return NS_ERROR_XPATH_OPERATOR_EXPECTED; - } - } - newToken = new Token(start, mPosition, defType); - } - else if (isXPathDigit(*mPosition)) { - start = mPosition; - while (++mPosition < end && isXPathDigit(*mPosition)) { - /* just go */ - } - if (mPosition < end && *mPosition == '.') { - while (++mPosition < end && isXPathDigit(*mPosition)) { - /* just go */ - } - } - newToken = new Token(start, mPosition, Token::NUMBER); - } - else { - switch (*mPosition) { - //-- ignore whitespace - case SPACE: - case TX_TAB: - case TX_CR: - case TX_LF: - ++mPosition; - isToken = PR_FALSE; - break; - case S_QUOTE : - case D_QUOTE : - start = mPosition; - while (++mPosition < end && *mPosition != *start) { - // eat literal - } - if (mPosition == end) { - mPosition = start; - return NS_ERROR_XPATH_UNCLOSED_LITERAL; - } - newToken = new Token(start + 1, mPosition, Token::LITERAL); - ++mPosition; - break; - case PERIOD: - // period can be .., .(DIGITS)+ or ., check next - if (++mPosition == end) { - newToken = new Token(mPosition - 1, Token::SELF_NODE); - } - else if (isXPathDigit(*mPosition)) { - start = mPosition - 1; - while (++mPosition < end && isXPathDigit(*mPosition)) { - /* just go */ - } - newToken = new Token(start, mPosition, Token::NUMBER); - } - else if (*mPosition == PERIOD) { - ++mPosition; - newToken = new Token(mPosition - 2, mPosition, Token::PARENT_NODE); - } - else { - newToken = new Token(mPosition - 1, Token::SELF_NODE); - } - break; - case COLON: // QNames are dealt above, must be axis ident - if (++mPosition >= end || *mPosition != COLON || - prevToken->mType != Token::CNAME) { - return NS_ERROR_XPATH_BAD_COLON; - } - prevToken->mType = Token::AXIS_IDENTIFIER; - ++mPosition; - isToken = PR_FALSE; - break; - case FORWARD_SLASH : - if (++mPosition < end && *mPosition == FORWARD_SLASH) { - ++mPosition; - newToken = new Token(mPosition - 2, mPosition, Token::ANCESTOR_OP); - } - else { - newToken = new Token(mPosition - 1, Token::PARENT_OP); - } - break; - case BANG : // can only be != - if (++mPosition < end && *mPosition == EQUAL) { - ++mPosition; - newToken = new Token(mPosition - 2, mPosition, Token::NOT_EQUAL_OP); - break; - } - // Error ! is not not() - return NS_ERROR_XPATH_BAD_BANG; - case EQUAL: - newToken = new Token(mPosition, Token::EQUAL_OP); - ++mPosition; - break; - case L_ANGLE: - if (++mPosition == end) { - return NS_ERROR_XPATH_UNEXPECTED_END; - } - if (*mPosition == EQUAL) { - ++mPosition; - newToken = new Token(mPosition - 2, mPosition, - Token::LESS_OR_EQUAL_OP); - } - else { - newToken = new Token(mPosition - 1, Token::LESS_THAN_OP); - } - break; - case R_ANGLE: - if (++mPosition == end) { - return NS_ERROR_XPATH_UNEXPECTED_END; - } - if (*mPosition == EQUAL) { - ++mPosition; - newToken = new Token(mPosition - 2, mPosition, - Token::GREATER_OR_EQUAL_OP); - } - else { - newToken = new Token(mPosition - 1, Token::GREATER_THAN_OP); - } - break; - case HYPHEN : - newToken = new Token(mPosition, Token::SUBTRACTION_OP); - ++mPosition; - break; - case ASTERIX: - if (nextIsOperatorToken(prevToken)) { - newToken = new Token(mPosition, Token::MULTIPLY_OP); - } - else { - newToken = new Token(mPosition, Token::CNAME); - } - ++mPosition; - break; - case L_PAREN: - if (prevToken->mType == Token::CNAME) { - NS_ConvertUTF16toUTF8 utf8Value(prevToken->Value()); - if (txXPathAtoms::comment->EqualsUTF8(utf8Value)) { - prevToken->mType = Token::COMMENT; - } - else if (txXPathAtoms::node->EqualsUTF8(utf8Value)) { - prevToken->mType = Token::NODE; - } - else if (txXPathAtoms::processingInstruction->EqualsUTF8(utf8Value)) { - prevToken->mType = Token::PROC_INST; - } - else if (txXPathAtoms::text->EqualsUTF8(utf8Value)) { - prevToken->mType = Token::TEXT; - } - else { - prevToken->mType = Token::FUNCTION_NAME; - } - } - newToken = new Token(mPosition, Token::L_PAREN); - ++mPosition; - break; - case R_PAREN: - newToken = new Token(mPosition, Token::R_PAREN); - ++mPosition; - break; - case L_BRACKET: - newToken = new Token(mPosition, Token::L_BRACKET); - ++mPosition; - break; - case R_BRACKET: - newToken = new Token(mPosition, Token::R_BRACKET); - ++mPosition; - break; - case COMMA: - newToken = new Token(mPosition, Token::COMMA); - ++mPosition; - break; - case AT_SIGN : - newToken = new Token(mPosition, Token::AT_SIGN); - ++mPosition; - break; - case PLUS: - newToken = new Token(mPosition, Token::ADDITION_OP); - ++mPosition; - break; - case VERT_BAR: - newToken = new Token(mPosition, Token::UNION_OP); - ++mPosition; - break; - default: - // Error, don't grok character :-( - return NS_ERROR_XPATH_ILLEGAL_CHAR; - } - } - if (isToken) { - NS_ENSURE_TRUE(newToken, NS_ERROR_OUT_OF_MEMORY); - NS_ENSURE_TRUE(newToken != mLastItem, NS_ERROR_FAILURE); - prevToken = newToken; - addToken(newToken); - } - } - - // add a endToken to the list - newToken = new Token(end, end, Token::END); - if (!newToken) { - return NS_ERROR_OUT_OF_MEMORY; - } - addToken(newToken); - - return NS_OK; -} diff --git a/extensions/transformiix/source/xpath/ExprLexer.h b/extensions/transformiix/source/xpath/ExprLexer.h deleted file mode 100644 index 4748a8c13f56..000000000000 --- a/extensions/transformiix/source/xpath/ExprLexer.h +++ /dev/null @@ -1,257 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#ifndef MITREXSL_EXPRLEXER_H -#define MITREXSL_EXPRLEXER_H - -#include "txCore.h" -#include "nsString.h" - -/** - * A Token class for the ExprLexer. - * - * This class was ported from XSL:P, an open source Java based - * XSLT processor, written by yours truly. - */ -class Token -{ -public: - - /** - * Token types - */ - enum Type { - //-- Trivial Tokens - NULL_TOKEN = 1, - LITERAL, - NUMBER, - CNAME, - FUNCTION_NAME, - VAR_REFERENCE, - PARENT_NODE, - SELF_NODE, - R_PAREN, - R_BRACKET, // 10 - /** - * start of tokens for 3.7, bullet 1 - * ExprLexer::nextIsOperatorToken bails if the tokens aren't - * consecutive. - */ - COMMA, - AT_SIGN, - L_PAREN, - L_BRACKET, - AXIS_IDENTIFIER, - - /** - * operators - */ - //-- boolean ops - AND_OP, // 16 - OR_OP, - - //-- relational - EQUAL_OP, // 18 - NOT_EQUAL_OP, - LESS_THAN_OP, - GREATER_THAN_OP, - LESS_OR_EQUAL_OP, - GREATER_OR_EQUAL_OP, - //-- additive operators - ADDITION_OP, // 24 - SUBTRACTION_OP, - //-- multiplicative - DIVIDE_OP , // 26 - MULTIPLY_OP, - MODULUS_OP, - //-- path operators - PARENT_OP, // 29 - ANCESTOR_OP, - UNION_OP, - /** - * end of tokens for 3.7, bullet 1 -/ - */ - //-- node type tokens - COMMENT, // 32 - NODE, - PROC_INST, - TEXT, - - //-- Special endtoken - END // 36 - }; - - - /** - * Constructors - */ - typedef nsASingleFragmentString::const_char_iterator iterator; - - Token(iterator aStart, iterator aEnd, Type aType) - : mStart(aStart), - mEnd(aEnd), - mType(aType), - mNext(nsnull), - mPrevious(nsnull) - { - } - Token(iterator aChar, Type aType) - : mStart(aChar), - mEnd(aChar + 1), - mType(aType), - mNext(nsnull), - mPrevious(nsnull) - { - } - - const nsDependentSubstring Value() - { - return Substring(mStart, mEnd); - } - - iterator mStart, mEnd; - Type mType; - Token* mNext; - // XXX mPrevious needed for pushBack(), do we pushBack more than once? - Token* mPrevious; -}; - -/** - * A class for splitting an "Expr" String into tokens and - * performing basic Lexical Analysis. - * - * This class was ported from XSL:P, an open source Java based XSL processor - */ - -class txExprLexer -{ -public: - - txExprLexer(); - ~txExprLexer(); - - /** - * Parse the given string. - * returns an error result if lexing failed. - * The given string must outlive the use of the lexer, as the - * generated Tokens point to Substrings of it. - * mPosition points to the offending location in case of an error. - */ - nsresult parse(const nsASingleFragmentString& aPattern); - - typedef nsASingleFragmentString::const_char_iterator iterator; - iterator mPosition; - - /** - * Functions for iterating over the TokenList - */ - - Token* nextToken(); - Token* peek() - { - return mCurrentItem; - } - void pushBack(); - PRBool hasMoreTokens() - { - return (mCurrentItem->mType != Token::END); - } - - /** - * Trivial Tokens - */ - //-- LF, changed to enum - enum _TrivialTokens { - D_QUOTE = '\"', - S_QUOTE = '\'', - L_PAREN = '(', - R_PAREN = ')', - L_BRACKET = '[', - R_BRACKET = ']', - L_ANGLE = '<', - R_ANGLE = '>', - COMMA = ',', - PERIOD = '.', - ASTERIX = '*', - FORWARD_SLASH = '/', - EQUAL = '=', - BANG = '!', - VERT_BAR = '|', - AT_SIGN = '@', - DOLLAR_SIGN = '$', - PLUS = '+', - HYPHEN = '-', - COLON = ':', - //-- whitespace tokens - SPACE = ' ', - TX_TAB = '\t', - TX_CR = '\n', - TX_LF = '\r' - }; - -private: - - Token* mCurrentItem; - Token* mFirstItem; - Token* mLastItem; - - int mTokenCount; - - void addToken(Token* aToken); - - /** - * Returns true if the following Token should be an operator. - * This is a helper for the first bullet of [XPath 3.7] - * Lexical Structure - */ - PRBool nextIsOperatorToken(Token* aToken); - - /** - * Returns true if the given character represents a numeric letter (digit) - * Implemented in ExprLexerChars.cpp - */ - static PRBool isXPathDigit(PRUnichar ch) - { - return (ch >= '0' && ch <= '9'); - } -}; - -#endif - diff --git a/extensions/transformiix/source/xpath/ExprParser.cpp b/extensions/transformiix/source/xpath/ExprParser.cpp deleted file mode 100644 index dfb681e71b2e..000000000000 --- a/extensions/transformiix/source/xpath/ExprParser.cpp +++ /dev/null @@ -1,1094 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * ExprParser - * This class is used to parse XSL Expressions - * @see ExprLexer -**/ - -#include "ExprParser.h" -#include "ExprLexer.h" -#include "FunctionLib.h" -#include "txStack.h" -#include "txAtoms.h" -#include "txError.h" -#include "txIXPathContext.h" -#include "txStringUtils.h" -#include "txXPathNode.h" - -/** - * Creates an Attribute Value Template using the given value - * This should move to XSLProcessor class -**/ -AttributeValueTemplate* txExprParser::createAttributeValueTemplate - (const nsAFlatString& attValue, txIParseContext* aContext) -{ - AttributeValueTemplate* avt = new AttributeValueTemplate(); - if (!avt) { - // XXX ErrorReport: out of memory - return 0; - } - - if (attValue.IsEmpty()) - return avt; - - PRUint32 size = attValue.Length(); - PRUint32 cc = 0; - PRUnichar nextCh; - PRUnichar ch; - nsAutoString buffer; - MBool inExpr = MB_FALSE; - MBool inLiteral = MB_FALSE; - PRUnichar endLiteral = 0; - - nextCh = attValue.CharAt(cc); - while (cc++ < size) { - ch = nextCh; - nextCh = cc != size ? attValue.CharAt(cc) : 0; - - // if in literal just add ch to buffer - if (inLiteral && (ch != endLiteral)) { - buffer.Append(ch); - continue; - } - switch ( ch ) { - case '\'' : - case '"' : - buffer.Append(ch); - if (inLiteral) - inLiteral = MB_FALSE; - else if (inExpr) { - inLiteral = MB_TRUE; - endLiteral = ch; - } - break; - case '{' : - if (!inExpr) { - // Ignore case where we find two { - if (nextCh == ch) { - buffer.Append(ch); //-- append '{' - cc++; - nextCh = cc != size ? attValue.CharAt(cc) : 0; - } - else { - if (!buffer.IsEmpty()) { - Expr* strExpr = new txLiteralExpr(buffer); - if (!strExpr) { - // XXX ErrorReport: out of memory - delete avt; - return 0; - } - avt->addExpr(strExpr); - } - buffer.Truncate(); - inExpr = MB_TRUE; - } - } - else - buffer.Append(ch); //-- simply append '{' - break; - case '}': - if (inExpr) { - inExpr = MB_FALSE; - txExprLexer lexer; - nsresult rv = lexer.parse(buffer); - if (NS_FAILED(rv)) { - delete avt; - return 0; - } - Expr* expr; - rv = createExpr(lexer, aContext, &expr); - if (NS_FAILED(rv)) { - delete avt; - return 0; - } - avt->addExpr(expr); - buffer.Truncate(); - } - else if (nextCh == ch) { - buffer.Append(ch); - cc++; - nextCh = cc != size ? attValue.CharAt(cc) : 0; - } - else { - //XXX ErrorReport: unmatched '}' found - delete avt; - return 0; - } - break; - default: - buffer.Append(ch); - break; - } - } - - if (inExpr) { - //XXX ErrorReport: ending '}' missing - delete avt; - return 0; - } - - if (!buffer.IsEmpty()) { - Expr* strExpr = new txLiteralExpr(buffer); - if (!strExpr) { - // XXX ErrorReport: out of memory - delete avt; - return 0; - } - avt->addExpr(strExpr); - } - - return avt; - -} - -nsresult -txExprParser::createExpr(const nsASingleFragmentString& aExpression, - txIParseContext* aContext, Expr** aExpr) -{ - NS_ENSURE_ARG_POINTER(aExpr); - *aExpr = nsnull; - txExprLexer lexer; - nsresult rv = lexer.parse(aExpression); - if (NS_FAILED(rv)) { - nsASingleFragmentString::const_char_iterator start; - aExpression.BeginReading(start); - aContext->SetErrorOffset(lexer.mPosition - start); - return rv; - } - rv = createExpr(lexer, aContext, aExpr); - if (NS_SUCCEEDED(rv) && lexer.peek()->mType != Token::END) { - delete *aExpr; - *aExpr = nsnull; - rv = NS_ERROR_XPATH_BINARY_EXPECTED; - } - if (NS_FAILED(rv)) { - nsASingleFragmentString::const_char_iterator start; - aExpression.BeginReading(start); - aContext->SetErrorOffset(lexer.peek()->mStart - start); - } - return rv; -} - -/** - * Private Methods - */ - -/** - * Creates a binary Expr for the given operator - */ -nsresult -txExprParser::createBinaryExpr(nsAutoPtr& left, nsAutoPtr& right, - Token* op, Expr** aResult) -{ - NS_ASSERTION(op, "internal error"); - *aResult = nsnull; - - Expr* expr = nsnull; - switch (op->mType) { - //-- additive ops - case Token::ADDITION_OP : - expr = new AdditiveExpr(left, right, AdditiveExpr::ADDITION); - break; - case Token::SUBTRACTION_OP: - expr = new AdditiveExpr(left, right, AdditiveExpr::SUBTRACTION); - break; - - //-- case boolean ops - case Token::AND_OP: - expr = new BooleanExpr(left, right, BooleanExpr::AND); - break; - case Token::OR_OP: - expr = new BooleanExpr(left, right, BooleanExpr::OR); - break; - - //-- equality ops - case Token::EQUAL_OP : - expr = new RelationalExpr(left, right, RelationalExpr::EQUAL); - break; - case Token::NOT_EQUAL_OP : - expr = new RelationalExpr(left, right, RelationalExpr::NOT_EQUAL); - break; - - //-- relational ops - case Token::LESS_THAN_OP: - expr = new RelationalExpr(left, right, RelationalExpr::LESS_THAN); - break; - case Token::GREATER_THAN_OP: - expr = new RelationalExpr(left, right, - RelationalExpr::GREATER_THAN); - break; - case Token::LESS_OR_EQUAL_OP: - expr = new RelationalExpr(left, right, - RelationalExpr::LESS_OR_EQUAL); - break; - case Token::GREATER_OR_EQUAL_OP: - expr = new RelationalExpr(left, right, - RelationalExpr::GREATER_OR_EQUAL); - break; - - //-- multiplicative ops - case Token::DIVIDE_OP : - expr = new MultiplicativeExpr(left, right, - MultiplicativeExpr::DIVIDE); - break; - case Token::MODULUS_OP : - expr = new MultiplicativeExpr(left, right, - MultiplicativeExpr::MODULUS); - break; - case Token::MULTIPLY_OP : - expr = new MultiplicativeExpr(left, right, - MultiplicativeExpr::MULTIPLY); - break; - default: - NS_NOTREACHED("operator tokens should be already checked"); - return NS_ERROR_UNEXPECTED; - } - NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY); - - *aResult = expr; - return NS_OK; -} - - -nsresult -txExprParser::createExpr(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult) -{ - *aResult = nsnull; - - nsresult rv = NS_OK; - MBool done = MB_FALSE; - - nsAutoPtr expr; - - txStack exprs; - txStack ops; - - while (!done) { - - MBool unary = MB_FALSE; - while (lexer.peek()->mType == Token::SUBTRACTION_OP) { - unary = !unary; - lexer.nextToken(); - } - - rv = createUnionExpr(lexer, aContext, getter_Transfers(expr)); - if (NS_FAILED(rv)) { - break; - } - - if (unary) { - Expr* uExpr = new UnaryExpr(expr); - if (!uExpr) { - rv = NS_ERROR_OUT_OF_MEMORY; - break; - } - expr = uExpr; - } - - Token* tok = lexer.nextToken(); - switch (tok->mType) { - case Token::ADDITION_OP: - case Token::DIVIDE_OP: - //-- boolean ops - case Token::AND_OP : - case Token::OR_OP : - //-- equality ops - case Token::EQUAL_OP: - case Token::NOT_EQUAL_OP: - //-- relational ops - case Token::LESS_THAN_OP: - case Token::GREATER_THAN_OP: - case Token::LESS_OR_EQUAL_OP: - case Token::GREATER_OR_EQUAL_OP: - //-- multiplicative ops - case Token::MODULUS_OP: - case Token::MULTIPLY_OP: - case Token::SUBTRACTION_OP: - { - while (!exprs.isEmpty() && precedence(tok) - <= precedence(NS_STATIC_CAST(Token*, ops.peek()))) { - // can't use expr as result due to order of evaluation - nsAutoPtr left(NS_STATIC_CAST(Expr*, exprs.pop())); - nsAutoPtr right(expr); - rv = createBinaryExpr(left, right, - NS_STATIC_CAST(Token*, ops.pop()), - getter_Transfers(expr)); - if (NS_FAILED(rv)) { - break; - } - } - exprs.push(expr.forget()); - ops.push(tok); - break; - } - default: - lexer.pushBack(); - done = MB_TRUE; - break; - } - } - - while (NS_SUCCEEDED(rv) && !exprs.isEmpty()) { - nsAutoPtr left(NS_STATIC_CAST(Expr*, exprs.pop())); - nsAutoPtr right(expr); - rv = createBinaryExpr(left, right, NS_STATIC_CAST(Token*, ops.pop()), - getter_Transfers(expr)); - } - // clean up on error - while (!exprs.isEmpty()) { - delete NS_STATIC_CAST(Expr*, exprs.pop()); - } - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = expr.forget(); - return NS_OK; -} - -nsresult -txExprParser::createFilter(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult) -{ - *aResult = nsnull; - - nsresult rv = NS_OK; - Token* tok = lexer.nextToken(); - - nsAutoPtr expr; - switch (tok->mType) { - case Token::FUNCTION_NAME : - lexer.pushBack(); - rv = createFunctionCall(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - break; - case Token::VAR_REFERENCE : - { - nsCOMPtr prefix, lName; - PRInt32 nspace; - nsresult rv = resolveQName(tok->Value(), getter_AddRefs(prefix), - aContext, getter_AddRefs(lName), - nspace); - NS_ENSURE_SUCCESS(rv, rv); - expr = new VariableRefExpr(prefix, lName, nspace); - NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY); - } - break; - case Token::L_PAREN: - rv = createExpr(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - if (lexer.nextToken()->mType != Token::R_PAREN) { - lexer.pushBack(); - return NS_ERROR_XPATH_PAREN_EXPECTED; - } - break; - case Token::LITERAL : - expr = new txLiteralExpr(tok->Value()); - NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY); - break; - case Token::NUMBER: - { - expr = new txLiteralExpr(Double::toDouble(tok->Value())); - NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY); - break; - } - default: - NS_NOTREACHED("internal error, this is not a filter token"); - lexer.pushBack(); - return NS_ERROR_UNEXPECTED; - } - - if (lexer.peek()->mType == Token::L_BRACKET) { - nsAutoPtr filterExpr(new FilterExpr(expr)); - NS_ENSURE_TRUE(filterExpr, NS_ERROR_OUT_OF_MEMORY); - - //-- handle predicates - rv = parsePredicates(filterExpr, lexer, aContext); - NS_ENSURE_SUCCESS(rv, rv); - expr = filterExpr.forget(); - } - - *aResult = expr.forget(); - return NS_OK; -} - -nsresult -txExprParser::createFunctionCall(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult) -{ - *aResult = nsnull; - - nsAutoPtr fnCall; - - Token* tok = lexer.nextToken(); - NS_ASSERTION(tok->mType == Token::FUNCTION_NAME, "FunctionCall expected"); - - //-- compare function names - nsCOMPtr prefix, lName; - PRInt32 namespaceID; - nsresult rv = resolveQName(tok->Value(), getter_AddRefs(prefix), aContext, - getter_AddRefs(lName), namespaceID); - NS_ENSURE_SUCCESS(rv, rv); - - if (namespaceID == kNameSpaceID_None) { - PRBool isOutOfMem = PR_TRUE; - if (lName == txXPathAtoms::boolean) { - fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_BOOLEAN); - } - else if (lName == txXPathAtoms::concat) { - fnCall = new StringFunctionCall(StringFunctionCall::CONCAT); - } - else if (lName == txXPathAtoms::contains) { - fnCall = new StringFunctionCall(StringFunctionCall::CONTAINS); - } - else if (lName == txXPathAtoms::count) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::COUNT); - } - else if (lName == txXPathAtoms::_false) { - fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_FALSE); - } - else if (lName == txXPathAtoms::id) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::ID); - } - else if (lName == txXPathAtoms::lang) { - fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_LANG); - } - else if (lName == txXPathAtoms::last) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LAST); - } - else if (lName == txXPathAtoms::localName) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LOCAL_NAME); - } - else if (lName == txXPathAtoms::name) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAME); - } - else if (lName == txXPathAtoms::namespaceUri) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAMESPACE_URI); - } - else if (lName == txXPathAtoms::normalizeSpace) { - fnCall = new StringFunctionCall(StringFunctionCall::NORMALIZE_SPACE); - } - else if (lName == txXPathAtoms::_not) { - fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_NOT); - } - else if (lName == txXPathAtoms::position) { - fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::POSITION); - } - else if (lName == txXPathAtoms::startsWith) { - fnCall = new StringFunctionCall(StringFunctionCall::STARTS_WITH); - } - else if (lName == txXPathAtoms::string) { - fnCall = new StringFunctionCall(StringFunctionCall::STRING); - } - else if (lName == txXPathAtoms::stringLength) { - fnCall = new StringFunctionCall(StringFunctionCall::STRING_LENGTH); - } - else if (lName == txXPathAtoms::substring) { - fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING); - } - else if (lName == txXPathAtoms::substringAfter) { - fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_AFTER); - } - else if (lName == txXPathAtoms::substringBefore) { - fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_BEFORE); - } - else if (lName == txXPathAtoms::sum) { - fnCall = new NumberFunctionCall(NumberFunctionCall::SUM); - } - else if (lName == txXPathAtoms::translate) { - fnCall = new StringFunctionCall(StringFunctionCall::TRANSLATE); - } - else if (lName == txXPathAtoms::_true) { - fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_TRUE); - } - else if (lName == txXPathAtoms::number) { - fnCall = new NumberFunctionCall(NumberFunctionCall::NUMBER); - } - else if (lName == txXPathAtoms::round) { - fnCall = new NumberFunctionCall(NumberFunctionCall::ROUND); - } - else if (lName == txXPathAtoms::ceiling) { - fnCall = new NumberFunctionCall(NumberFunctionCall::CEILING); - } - else if (lName == txXPathAtoms::floor) { - fnCall = new NumberFunctionCall(NumberFunctionCall::FLOOR); - } - else { - // didn't find functioncall here, fnCall should be null - isOutOfMem = PR_FALSE; - } - if (!fnCall && isOutOfMem) { - NS_ERROR("XPath FunctionLib failed on out-of-memory"); - return NS_ERROR_OUT_OF_MEMORY; - } - } - // check extension functions and xslt - if (!fnCall) { - rv = aContext->resolveFunctionCall(lName, namespaceID, - *getter_Transfers(fnCall)); - - if (rv == NS_ERROR_NOT_IMPLEMENTED) { - // this should just happen for unparsed-entity-uri() - NS_ASSERTION(!fnCall, "Now is it implemented or not?"); - rv = parseParameters(0, lexer, aContext); - NS_ENSURE_SUCCESS(rv, rv); - *aResult = new txLiteralExpr(tok->Value() + - NS_LITERAL_STRING(" not implemented.")); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; - } - - if (NS_FAILED(rv)) { - NS_ERROR("Creation of FunctionCall failed"); - return rv; - } - } - - //-- handle parametes - rv = parseParameters(fnCall, lexer, aContext); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = fnCall.forget(); - return NS_OK; -} - -nsresult -txExprParser::createLocationStep(txExprLexer& lexer, txIParseContext* aContext, - Expr** aExpr) -{ - *aExpr = nsnull; - - //-- child axis is default - LocationStep::LocationStepType axisIdentifier = LocationStep::CHILD_AXIS; - nsAutoPtr nodeTest; - - //-- get Axis Identifier or AbbreviatedStep, if present - Token* tok = lexer.peek(); - switch (tok->mType) { - case Token::AXIS_IDENTIFIER: - { - //-- eat token - lexer.nextToken(); - nsCOMPtr axis = do_GetAtom(tok->Value()); - if (axis == txXPathAtoms::ancestor) { - axisIdentifier = LocationStep::ANCESTOR_AXIS; - } - else if (axis == txXPathAtoms::ancestorOrSelf) { - axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS; - } - else if (axis == txXPathAtoms::attribute) { - axisIdentifier = LocationStep::ATTRIBUTE_AXIS; - } - else if (axis == txXPathAtoms::child) { - axisIdentifier = LocationStep::CHILD_AXIS; - } - else if (axis == txXPathAtoms::descendant) { - axisIdentifier = LocationStep::DESCENDANT_AXIS; - } - else if (axis == txXPathAtoms::descendantOrSelf) { - axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS; - } - else if (axis == txXPathAtoms::following) { - axisIdentifier = LocationStep::FOLLOWING_AXIS; - } - else if (axis == txXPathAtoms::followingSibling) { - axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS; - } - else if (axis == txXPathAtoms::_namespace) { - axisIdentifier = LocationStep::NAMESPACE_AXIS; - } - else if (axis == txXPathAtoms::parent) { - axisIdentifier = LocationStep::PARENT_AXIS; - } - else if (axis == txXPathAtoms::preceding) { - axisIdentifier = LocationStep::PRECEDING_AXIS; - } - else if (axis == txXPathAtoms::precedingSibling) { - axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS; - } - else if (axis == txXPathAtoms::self) { - axisIdentifier = LocationStep::SELF_AXIS; - } - else { - return NS_ERROR_XPATH_INVALID_AXIS; - } - break; - } - case Token::AT_SIGN: - //-- eat token - lexer.nextToken(); - axisIdentifier = LocationStep::ATTRIBUTE_AXIS; - break; - case Token::PARENT_NODE : - //-- eat token - lexer.nextToken(); - axisIdentifier = LocationStep::PARENT_AXIS; - nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE); - NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); - break; - case Token::SELF_NODE : - //-- eat token - lexer.nextToken(); - axisIdentifier = LocationStep::SELF_AXIS; - nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE); - NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); - break; - default: - break; - } - - //-- get NodeTest unless an AbbreviatedStep was found - nsresult rv = NS_OK; - if (!nodeTest) { - tok = lexer.nextToken(); - - switch (tok->mType) { - case Token::CNAME : - { - // resolve QName - nsCOMPtr prefix, lName; - PRInt32 nspace; - rv = resolveQName(tok->Value(), getter_AddRefs(prefix), - aContext, getter_AddRefs(lName), - nspace, PR_TRUE); - NS_ENSURE_SUCCESS(rv, rv); - switch (axisIdentifier) { - case LocationStep::ATTRIBUTE_AXIS: - nodeTest = new txNameTest(prefix, lName, nspace, - txXPathNodeType::ATTRIBUTE_NODE); - break; - default: - nodeTest = new txNameTest(prefix, lName, nspace, - txXPathNodeType::ELEMENT_NODE); - break; - } - NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); - } - break; - default: - lexer.pushBack(); - rv = createNodeTypeTest(lexer, getter_Transfers(nodeTest)); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - nsAutoPtr lstep(new LocationStep(nodeTest, axisIdentifier)); - NS_ENSURE_TRUE(lstep, NS_ERROR_OUT_OF_MEMORY); - - //-- handle predicates - rv = parsePredicates(lstep, lexer, aContext); - NS_ENSURE_SUCCESS(rv, rv); - - *aExpr = lstep.forget(); - return NS_OK; -} - -/** - * This method only handles comment(), text(), processing-instructing() - * and node() - */ -nsresult -txExprParser::createNodeTypeTest(txExprLexer& lexer, txNodeTest** aTest) -{ - *aTest = 0; - nsAutoPtr nodeTest; - - Token* nodeTok = lexer.nextToken(); - - switch (nodeTok->mType) { - case Token::COMMENT: - nodeTest = new txNodeTypeTest(txNodeTypeTest::COMMENT_TYPE); - break; - case Token::NODE : - nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE); - break; - case Token::PROC_INST : - nodeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE); - break; - case Token::TEXT : - nodeTest = new txNodeTypeTest(txNodeTypeTest::TEXT_TYPE); - break; - default: - lexer.pushBack(); - return NS_ERROR_XPATH_NO_NODE_TYPE_TEST; - } - NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); - - if (lexer.nextToken()->mType != Token::L_PAREN) { - lexer.pushBack(); - NS_NOTREACHED("txExprLexer doesn't generate nodetypetest without("); - return NS_ERROR_UNEXPECTED; - } - if (nodeTok->mType == Token::PROC_INST && - lexer.peek()->mType == Token::LITERAL) { - Token* tok = lexer.nextToken(); - nodeTest->setNodeName(tok->Value()); - } - if (lexer.nextToken()->mType != Token::R_PAREN) { - lexer.pushBack(); - return NS_ERROR_XPATH_PAREN_EXPECTED; - } - - *aTest = nodeTest.forget(); - return NS_OK; -} - -/** - * Creates a PathExpr using the given txExprLexer - * @param lexer the txExprLexer for retrieving Tokens - */ -nsresult -txExprParser::createPathExpr(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult) -{ - *aResult = nsnull; - - nsAutoPtr expr; - - Token* tok = lexer.peek(); - - // is this a root expression? - if (tok->mType == Token::PARENT_OP) { - lexer.nextToken(); - if (!isLocationStepToken(lexer.peek())) { - *aResult = new RootExpr(); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; - } - lexer.pushBack(); - } - - // parse first step (possibly a FilterExpr) - nsresult rv = NS_OK; - if (tok->mType != Token::PARENT_OP && - tok->mType != Token::ANCESTOR_OP) { - if (isFilterExprToken(tok)) { - rv = createFilter(lexer, aContext, getter_Transfers(expr)); - } - else { - rv = createLocationStep(lexer, aContext, getter_Transfers(expr)); - } - NS_ENSURE_SUCCESS(rv, rv); - - // is this a singlestep path expression? - tok = lexer.peek(); - if (tok->mType != Token::PARENT_OP && - tok->mType != Token::ANCESTOR_OP) { - *aResult = expr.forget(); - return NS_OK; - } - } - else { - expr = new RootExpr(); - NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY); - -#ifdef TX_TO_STRING - NS_STATIC_CAST(RootExpr*, expr.get())->setSerialize(PR_FALSE); -#endif - } - - // We have a PathExpr containing several steps - nsAutoPtr pathExpr(new PathExpr()); - NS_ENSURE_TRUE(pathExpr, NS_ERROR_OUT_OF_MEMORY); - - rv = pathExpr->addExpr(expr.forget(), PathExpr::RELATIVE_OP); - NS_ENSURE_SUCCESS(rv, rv); - - // this is ugly - while (1) { - PathExpr::PathOperator pathOp; - tok = lexer.nextToken(); - switch (tok->mType) { - case Token::ANCESTOR_OP : - pathOp = PathExpr::DESCENDANT_OP; - break; - case Token::PARENT_OP : - pathOp = PathExpr::RELATIVE_OP; - break; - default: - lexer.pushBack(); - *aResult = pathExpr.forget(); - return NS_OK; - } - - rv = createLocationStep(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = pathExpr->addExpr(expr.forget(), pathOp); - NS_ENSURE_SUCCESS(rv, rv); - } - NS_NOTREACHED("internal xpath parser error"); - return NS_ERROR_UNEXPECTED; -} - -/** - * Creates a PathExpr using the given txExprLexer - * @param lexer the txExprLexer for retrieving Tokens - */ -nsresult -txExprParser::createUnionExpr(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult) -{ - *aResult = nsnull; - - nsAutoPtr expr; - nsresult rv = createPathExpr(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - if (lexer.peek()->mType != Token::UNION_OP) { - *aResult = expr.forget(); - return NS_OK; - } - - nsAutoPtr unionExpr(new UnionExpr()); - NS_ENSURE_TRUE(unionExpr, NS_ERROR_OUT_OF_MEMORY); - - rv = unionExpr->addExpr(expr.forget()); - NS_ENSURE_SUCCESS(rv, rv); - - while (lexer.peek()->mType == Token::UNION_OP) { - lexer.nextToken(); //-- eat token - - rv = createPathExpr(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = unionExpr->addExpr(expr.forget()); - NS_ENSURE_SUCCESS(rv, rv); - } - - *aResult = unionExpr.forget(); - return NS_OK; -} - -PRBool -txExprParser::isFilterExprToken(Token* aToken) -{ - switch (aToken->mType) { - case Token::LITERAL: - case Token::NUMBER: - case Token::FUNCTION_NAME: - case Token::VAR_REFERENCE: - case Token::L_PAREN: // grouping expr - return PR_TRUE; - default: - return PR_FALSE; - } -} - -PRBool -txExprParser::isLocationStepToken(Token* aToken) -{ - switch (aToken->mType) { - case Token::AXIS_IDENTIFIER : - case Token::AT_SIGN : - case Token::PARENT_NODE : - case Token::SELF_NODE : - return PR_TRUE; - default: - return isNodeTypeToken(aToken); - } -} - -PRBool -txExprParser::isNodeTypeToken(Token* aToken) -{ - switch (aToken->mType) { - case Token::CNAME: - case Token::COMMENT: - case Token::NODE : - case Token::PROC_INST : - case Token::TEXT : - return PR_TRUE; - default: - return PR_FALSE; - } -} - -/** - * Using the given lexer, parses the tokens if they represent a predicate list - * If an error occurs a non-zero String pointer will be returned containing the - * error message. - * @param predicateList, the PredicateList to add predicate expressions to - * @param lexer the txExprLexer to use for parsing tokens - * @return 0 if successful, or a String pointer to the error message - */ -nsresult -txExprParser::parsePredicates(PredicateList* aPredicateList, - txExprLexer& lexer, txIParseContext* aContext) -{ - nsAutoPtr expr; - nsresult rv = NS_OK; - while (lexer.peek()->mType == Token::L_BRACKET) { - //-- eat Token - lexer.nextToken(); - - rv = createExpr(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aPredicateList->add(expr.forget()); - NS_ENSURE_SUCCESS(rv, rv); - - if (lexer.nextToken()->mType != Token::R_BRACKET) { - lexer.pushBack(); - return NS_ERROR_XPATH_BRACKET_EXPECTED; - } - } - return NS_OK; -} - - -/** - * Using the given lexer, parses the tokens if they represent a parameter list - * If an error occurs a non-zero String pointer will be returned containing the - * error message. - * @param list, the List to add parameter expressions to - * @param lexer the txExprLexer to use for parsing tokens - * @return NS_OK if successful, or another rv otherwise - */ -nsresult -txExprParser::parseParameters(FunctionCall* aFnCall, txExprLexer& lexer, - txIParseContext* aContext) -{ - if (lexer.nextToken()->mType != Token::L_PAREN) { - lexer.pushBack(); - NS_NOTREACHED("txExprLexer doesn't generate functions without("); - return NS_ERROR_UNEXPECTED; - } - - if (lexer.peek()->mType == Token::R_PAREN) { - lexer.nextToken(); - return NS_OK; - } - - nsAutoPtr expr; - nsresult rv = NS_OK; - while (1) { - rv = createExpr(lexer, aContext, getter_Transfers(expr)); - NS_ENSURE_SUCCESS(rv, rv); - - if (aFnCall) { - rv = aFnCall->addParam(expr.forget()); - NS_ENSURE_SUCCESS(rv, rv); - } - - switch (lexer.nextToken()->mType) { - case Token::R_PAREN : - return NS_OK; - case Token::COMMA: //-- param separator - break; - default: - lexer.pushBack(); - return NS_ERROR_XPATH_PAREN_EXPECTED; - } - } - - NS_NOTREACHED("internal xpath parser error"); - return NS_ERROR_UNEXPECTED; -} - -short -txExprParser::precedence(Token* aToken) -{ - switch (aToken->mType) { - case Token::OR_OP: - return 1; - case Token::AND_OP: - return 2; - //-- equality - case Token::EQUAL_OP: - case Token::NOT_EQUAL_OP: - return 3; - //-- relational - case Token::LESS_THAN_OP: - case Token::GREATER_THAN_OP: - case Token::LESS_OR_EQUAL_OP: - case Token::GREATER_OR_EQUAL_OP: - return 4; - //-- additive operators - case Token::ADDITION_OP: - case Token::SUBTRACTION_OP: - return 5; - //-- multiplicative - case Token::DIVIDE_OP: - case Token::MULTIPLY_OP: - case Token::MODULUS_OP: - return 6; - default: - break; - } - return 0; -} - -nsresult -txExprParser::resolveQName(const nsAString& aQName, - nsIAtom** aPrefix, txIParseContext* aContext, - nsIAtom** aLocalName, PRInt32& aNamespace, - PRBool aIsNameTest) -{ - aNamespace = kNameSpaceID_None; - PRInt32 idx = aQName.FindChar(':'); - if (idx > 0) { - *aPrefix = NS_NewAtom(Substring(aQName, 0, (PRUint32)idx)); - if (!*aPrefix) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aLocalName = NS_NewAtom(Substring(aQName, (PRUint32)idx + 1, - aQName.Length() - (idx + 1))); - if (!*aLocalName) { - NS_RELEASE(*aPrefix); - return NS_ERROR_OUT_OF_MEMORY; - } - return aContext->resolveNamespacePrefix(*aPrefix, aNamespace); - } - // the lexer dealt with idx == 0 - *aPrefix = 0; - if (aIsNameTest && aContext->caseInsensitiveNameTests()) { - nsAutoString lcname; - TX_ToLowerCase(aQName, lcname); - *aLocalName = NS_NewAtom(lcname); - } - else { - *aLocalName = NS_NewAtom(aQName); - } - if (!*aLocalName) { - return NS_ERROR_OUT_OF_MEMORY; - } - return NS_OK; -} diff --git a/extensions/transformiix/source/xpath/ExprParser.h b/extensions/transformiix/source/xpath/ExprParser.h deleted file mode 100644 index bf0a7e846d6f..000000000000 --- a/extensions/transformiix/source/xpath/ExprParser.h +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * ExprParser - * This class is used to parse XSL Expressions - * @see ExprLexer -**/ - -#ifndef MITREXSL_EXPRPARSER_H -#define MITREXSL_EXPRPARSER_H - -#include "txCore.h" -#include "nsAutoPtr.h" -#include "nsString.h" - -class AttributeValueTemplate; -class Expr; -class txExprLexer; -class FunctionCall; -class LocationStep; -class nsIAtom; -class PredicateList; -class Token; -class txIParseContext; -class txNodeTest; -class txNodeTypeTest; - -class txExprParser -{ -public: - - static nsresult createExpr(const nsASingleFragmentString& aExpression, - txIParseContext* aContext, Expr** aExpr); - - /** - * Creates an Attribute Value Template using the given value - */ - static AttributeValueTemplate* createAttributeValueTemplate - (const nsAFlatString& attValue, txIParseContext* aContext); - - -protected: - /** - * Using nsAutoPtr& to optimize passing the ownership to the - * created binary expression objects. - */ - static nsresult createBinaryExpr(nsAutoPtr& left, - nsAutoPtr& right, Token* op, - Expr** aResult); - static nsresult createExpr(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult); - static nsresult createFilter(txExprLexer& lexer, txIParseContext* aContext, - Expr** aResult); - static nsresult createFunctionCall(txExprLexer& lexer, - txIParseContext* aContext, - Expr** aResult); - static nsresult createLocationStep(txExprLexer& lexer, - txIParseContext* aContext, - Expr** aResult); - static nsresult createNodeTypeTest(txExprLexer& lexer, - txNodeTest** aResult); - static nsresult createPathExpr(txExprLexer& lexer, - txIParseContext* aContext, - Expr** aResult); - static nsresult createUnionExpr(txExprLexer& lexer, - txIParseContext* aContext, - Expr** aResult); - - static PRBool isFilterExprToken(Token* aToken); - static PRBool isLocationStepToken(Token* aToken); - static PRBool isNodeTypeToken(Token* aToken); - - static short precedence(Token* aToken); - - /** - * Resolve a QName, given the mContext parse context. - * Returns prefix and localName as well as namespace ID - */ - static nsresult resolveQName(const nsAString& aQName, nsIAtom** aPrefix, - txIParseContext* aContext, - nsIAtom** aLocalName, PRInt32& aNamespace, - PRBool aIsNameTest = MB_FALSE); - - /** - * Using the given lexer, parses the tokens if they represent a - * predicate list - * If an error occurs a non-zero String pointer will be returned - * containing the error message. - * @param predicateList, the PredicateList to add predicate expressions to - * @param lexer the ExprLexer to use for parsing tokens - * @return 0 if successful, or a String pointer to the error message - */ - static nsresult parsePredicates(PredicateList* aPredicateList, - txExprLexer& lexer, - txIParseContext* aContext); - static nsresult parseParameters(FunctionCall* aFnCall, txExprLexer& lexer, - txIParseContext* aContext); - -}; - -#endif diff --git a/extensions/transformiix/source/xpath/ExprResult.h b/extensions/transformiix/source/xpath/ExprResult.h deleted file mode 100644 index 82f1cbb40ad1..000000000000 --- a/extensions/transformiix/source/xpath/ExprResult.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * Larry Fitzpatrick, OpenText - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_EXPRRESULT_H -#define TRANSFRMX_EXPRRESULT_H - -#include "nsString.h" -#include "nsAutoPtr.h" -#include "txCore.h" -#include "txResultRecycler.h" - -/* - * ExprResult - * - * Classes Represented: - * BooleanResult, ExprResult, NumberResult, StringResult - * - * Note: for NodeSet, see NodeSet.h -*/ - -class txAExprResult : public TxObject -{ -public: - friend class txResultRecycler; - enum ResultType { - NODESET, - BOOLEAN, - NUMBER, - STRING, - RESULT_TREE_FRAGMENT - }; - - txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler) {} - virtual ~txAExprResult() {}; - - void AddRef() - { - ++mRefCnt; - } - - void Release(); // Implemented in txResultRecycler.cpp - - /** - * Returns the type of ExprResult represented - * @return the type of ExprResult represented - **/ - virtual short getResultType() = 0; - - /** - * Creates a String representation of this ExprResult - * @param str the destination string to append the String representation to. - **/ - virtual void stringValue(nsAString& str) = 0; - - /** - * Returns a pointer to the stringvalue if possible. Otherwise null is - * returned. - */ - virtual nsAString* stringValuePointer() = 0; - - /** - * Converts this ExprResult to a Boolean (MBool) value - * @return the Boolean value - **/ - virtual MBool booleanValue() = 0; - - /** - * Converts this ExprResult to a Number (double) value - * @return the Number value - **/ - virtual double numberValue() = 0; - -private: - nsAutoRefCnt mRefCnt; - nsRefPtr mRecycler; -}; - -#define TX_DECL_EXPRRESULT \ - virtual short getResultType(); \ - virtual void stringValue(nsAString& str); \ - virtual nsAString* stringValuePointer(); \ - virtual PRBool booleanValue(); \ - virtual double numberValue(); \ - - -class BooleanResult : public txAExprResult { - -public: - BooleanResult(MBool aValue); - - TX_DECL_EXPRRESULT - -private: - MBool value; -}; - -class NumberResult : public txAExprResult { - -public: - NumberResult(double aValue, txResultRecycler* aRecycler); - - TX_DECL_EXPRRESULT - - double value; - -}; - - -class StringResult : public txAExprResult { -public: - StringResult(txResultRecycler* aRecycler); - StringResult(const nsAString& aValue, txResultRecycler* aRecycler); - - TX_DECL_EXPRRESULT - - nsString mValue; -}; - -#endif - diff --git a/extensions/transformiix/source/xpath/FilterExpr.cpp b/extensions/transformiix/source/xpath/FilterExpr.cpp deleted file mode 100644 index 109057fc5fdb..000000000000 --- a/extensions/transformiix/source/xpath/FilterExpr.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * Bob Miller - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txNodeSet.h" -#include "txIXPathContext.h" - -//-- Implementation of FilterExpr --/ - - //-----------------------------/ - //- Virtual methods from Expr -/ -//-----------------------------/ - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ProcessorState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see Expr -**/ -nsresult -FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET, - NS_ERROR_XSLT_NODESET_EXPECTED); - - nsRefPtr nodes = - NS_STATIC_CAST(txNodeSet*, NS_STATIC_CAST(txAExprResult*, exprRes)); - // null out exprRes so that we can test for shared-ness - exprRes = nsnull; - - nsRefPtr nonShared; - rv = aContext->recycler()->getNonSharedNodeSet(nodes, - getter_AddRefs(nonShared)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = evaluatePredicates(nonShared, aContext); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = nonShared; - NS_ADDREF(*aResult); - - return NS_OK; -} //-- evaluate - -#ifdef TX_TO_STRING -void -FilterExpr::toString(nsAString& str) -{ - if ( expr ) expr->toString(str); - else str.AppendLiteral("null"); - PredicateList::toString(str); -} -#endif - diff --git a/extensions/transformiix/source/xpath/FunctionCall.cpp b/extensions/transformiix/source/xpath/FunctionCall.cpp deleted file mode 100644 index bf0cb92d1d6c..000000000000 --- a/extensions/transformiix/source/xpath/FunctionCall.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "FunctionLib.h" -#include "ExprResult.h" -#include "nsIAtom.h" -#include "txIXPathContext.h" -#include "txNodeSet.h" - -/** - * This class represents a FunctionCall as defined by the XSL Working Draft -**/ - -FunctionCall::FunctionCall() -{ -} - -/** - * Destructor -**/ -FunctionCall::~FunctionCall() -{ - txListIterator iter(¶ms); - while (iter.hasNext()) { - delete (Expr*)iter.next(); - } -} //-- ~FunctionCall - - //------------------/ - //- Public Methods -/ -//------------------/ - -/** - * Adds the given parameter to this FunctionCall's parameter list - * @param expr the Expr to add to this FunctionCall's parameter list - */ -nsresult -FunctionCall::addParam(Expr* aExpr) -{ - NS_ASSERTION(aExpr, "missing expression"); - nsresult rv = params.add(aExpr); - if (NS_FAILED(rv)) { - delete aExpr; - } - return rv; -} //-- addParam - -/* - * Evaluates the given Expression and converts its result to a String. - * The value is appended to the given destination String - */ -void FunctionCall::evaluateToString(Expr* aExpr, txIEvalContext* aContext, - nsAString& aDest) -{ - NS_ASSERTION(aExpr, "missing expression"); - nsRefPtr exprResult; - nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprResult)); - if (NS_FAILED(rv)) - return; - - exprResult->stringValue(aDest); -} - -/* - * Evaluates the given Expression and converts its result to a number. - */ -double FunctionCall::evaluateToNumber(Expr* aExpr, txIEvalContext* aContext) -{ - NS_ASSERTION(aExpr, "missing expression"); - nsRefPtr exprResult; - nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprResult)); - if (NS_FAILED(rv)) - return Double::NaN; - - return exprResult->numberValue(); -} - -/* - * Evaluates the given Expression and converts its result to a boolean. - */ -MBool FunctionCall::evaluateToBoolean(Expr* aExpr, txIEvalContext* aContext) -{ - NS_ASSERTION(aExpr, "missing expression"); - nsRefPtr exprResult; - nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprResult)); - if (NS_FAILED(rv)) - return PR_FALSE; - - return exprResult->booleanValue(); -} - -/* - * Evaluates the given Expression and converts its result to a NodeSet. - * If the result is not a NodeSet NULL is returned. - */ -nsresult -FunctionCall::evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext, - txNodeSet** aResult) -{ - NS_ASSERTION(aExpr, "Missing expression to evaluate"); - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (exprRes->getResultType() != txAExprResult::NODESET) { - aContext->receiveError(NS_LITERAL_STRING("NodeSet expected as argument"), NS_ERROR_XSLT_NODESET_EXPECTED); - return NS_ERROR_XSLT_NODESET_EXPECTED; - } - - *aResult = - NS_STATIC_CAST(txNodeSet*, NS_STATIC_CAST(txAExprResult*, exprRes)); - NS_ADDREF(*aResult); - - return NS_OK; -} - -PRBool FunctionCall::requireParams(PRInt32 aParamCountMin, - PRInt32 aParamCountMax, - txIEvalContext* aContext) -{ - PRInt32 argc = params.getLength(); - if (argc < aParamCountMin || - (aParamCountMax > -1 && argc > aParamCountMax)) { - nsAutoString err(NS_LITERAL_STRING("invalid number of parameters for function")); -#ifdef TX_TO_STRING - err.AppendLiteral(": "); - toString(err); -#endif - aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG); - - return PR_FALSE; - } - - return PR_TRUE; -} - -#ifdef TX_TO_STRING -void -FunctionCall::toString(nsAString& aDest) -{ - nsCOMPtr functionNameAtom; - nsAutoString functionName; - if (NS_FAILED(getNameAtom(getter_AddRefs(functionNameAtom))) || - NS_FAILED(functionNameAtom->ToString(functionName))) { - NS_ASSERTION(0, "Can't get function name."); - return; - } - - aDest.Append(functionName); - aDest.Append(PRUnichar('(')); - txListIterator iter(¶ms); - MBool addComma = MB_FALSE; - while (iter.hasNext()) { - if (addComma) { - aDest.Append(PRUnichar(',')); - } - addComma = MB_TRUE; - Expr* expr = (Expr*)iter.next(); - expr->toString(aDest); - } - aDest.Append(PRUnichar(')')); -} -#endif diff --git a/extensions/transformiix/source/xpath/FunctionLib.h b/extensions/transformiix/source/xpath/FunctionLib.h deleted file mode 100644 index b865b0ed5689..000000000000 --- a/extensions/transformiix/source/xpath/FunctionLib.h +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_FUNCTIONLIB_H -#define TRANSFRMX_FUNCTIONLIB_H - -#include "Expr.h" -#include "nsIAtom.h" - -/** - * The following are definitions for the XPath functions - * - *
- * Modifications:
- * 20000418: Keith Visco
- *   -- added ExtensionFunctionCall
- *
- * 19990805: Keith Visco
- *   - added NodeSetFunctionCall
- *   - moved position() function into NodeSetFunctionCall
- *   - removed PositionFunctionCall
- * 19990806: Larry Fitzpatrick
- *   - changed constant short declarations for BooleanFunctionCall
- *     with enumerations
- * 19990806: Keith Visco
- *   - added StringFunctionCall
- *   - stated using Larry's enum suggestion instead of using static const shorts,
- *     as you can see, I am a Java developer! ;-)
- * 
- */ - -/** - * Represents the Set of boolean functions -**/ -class BooleanFunctionCall : public FunctionCall { - -public: - - enum BooleanFunctions { - TX_BOOLEAN, // boolean() - TX_FALSE, // false() - TX_LANG, // lang() - TX_NOT, // not() - TX_TRUE // true() - }; - - /** - * Creates a BooleanFunctionCall of the given type - **/ - BooleanFunctionCall(BooleanFunctions aType); - - TX_DECL_FUNCTION; - -private: - BooleanFunctions mType; -}; //-- BooleanFunctionCall - -/* - * A representation of the XPath NodeSet funtions - */ -class NodeSetFunctionCall : public FunctionCall { - -public: - - enum NodeSetFunctions { - COUNT, // count() - ID, // id() - LAST, // last() - LOCAL_NAME, // local-name() - NAMESPACE_URI, // namespace-uri() - NAME, // name() - POSITION // position() - }; - - /* - * Creates a NodeSetFunctionCall of the given type - */ - NodeSetFunctionCall(NodeSetFunctions aType); - - TX_DECL_FUNCTION; - -private: - NodeSetFunctions mType; -}; - - -/** - * Represents the XPath String Function Calls -**/ -class StringFunctionCall : public FunctionCall { - -public: - - enum StringFunctions { - CONCAT, // concat() - CONTAINS, // contains() - NORMALIZE_SPACE, // normalize-space() - STARTS_WITH, // starts-with() - STRING, // string() - STRING_LENGTH, // string-length() - SUBSTRING, // substring() - SUBSTRING_AFTER, // substring-after() - SUBSTRING_BEFORE, // substring-before() - TRANSLATE // translate() - }; - - /** - * Creates a String function of the given type - **/ - StringFunctionCall(StringFunctions aType); - - TX_DECL_FUNCTION; - -private: - StringFunctions mType; -}; //-- StringFunctionCall - - -/* - * Represents the XPath Number Function Calls - */ -class NumberFunctionCall : public FunctionCall { - -public: - - enum NumberFunctions { - NUMBER, // number() - ROUND, // round() - FLOOR, // floor() - CEILING, // ceiling() - SUM // sum() - }; - - /* - * Creates a Number function of the given type - */ - NumberFunctionCall(NumberFunctions aType); - - TX_DECL_FUNCTION; - -private: - NumberFunctions mType; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/LocationStep.cpp b/extensions/transformiix/source/xpath/LocationStep.cpp deleted file mode 100644 index 2d0bd46958e4..000000000000 --- a/extensions/transformiix/source/xpath/LocationStep.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - Implementation of an XPath LocationStep -*/ - -#include "Expr.h" -#include "txIXPathContext.h" -#include "txNodeSet.h" - - //-----------------------------/ - //- Virtual methods from Expr -/ -//-----------------------------/ - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ProcessorState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see Expr -**/ -nsresult -LocationStep::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - NS_ASSERTION(aContext, "internal error"); - *aResult = nsnull; - - nsRefPtr nodes; - nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - txXPathTreeWalker walker(aContext->getContextNode()); - - switch (mAxisIdentifier) { - case ANCESTOR_AXIS: - { - if (!walker.moveToParent()) { - break; - } - // do not break here - } - case ANCESTOR_OR_SELF_AXIS: - { - nodes->setReverse(); - - do { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - } while (walker.moveToParent()); - - break; - } - case ATTRIBUTE_AXIS: - { - if (!walker.moveToFirstAttribute()) { - break; - } - - do { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - } while (walker.moveToNextAttribute()); - break; - } - case DESCENDANT_OR_SELF_AXIS: - { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - // do not break here - } - case DESCENDANT_AXIS: - { - fromDescendants(walker.getCurrentPosition(), aContext, nodes); - break; - } - case FOLLOWING_AXIS: - { - if (txXPathNodeUtils::isAttribute(walker.getCurrentPosition())) { - walker.moveToParent(); - fromDescendants(walker.getCurrentPosition(), aContext, nodes); - } - PRBool cont = PR_TRUE; - while (!walker.moveToNextSibling()) { - if (!walker.moveToParent()) { - cont = PR_FALSE; - break; - } - } - while (cont) { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - - fromDescendants(walker.getCurrentPosition(), aContext, nodes); - - while (!walker.moveToNextSibling()) { - if (!walker.moveToParent()) { - cont = PR_FALSE; - break; - } - } - } - break; - } - case FOLLOWING_SIBLING_AXIS: - { - while (walker.moveToNextSibling()) { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - } - break; - } - case NAMESPACE_AXIS: //-- not yet implemented -#if 0 - // XXX DEBUG OUTPUT - cout << "namespace axis not yet implemented"<matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - break; - } - case PRECEDING_AXIS: - { - nodes->setReverse(); - - PRBool cont = PR_TRUE; - while (!walker.moveToPreviousSibling()) { - if (!walker.moveToParent()) { - cont = PR_FALSE; - break; - } - } - while (cont) { - fromDescendantsRev(walker.getCurrentPosition(), aContext, nodes); - - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - - while (!walker.moveToPreviousSibling()) { - if (!walker.moveToParent()) { - cont = PR_FALSE; - break; - } - } - } - break; - } - case PRECEDING_SIBLING_AXIS: - { - nodes->setReverse(); - - while (walker.moveToPreviousSibling()) { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - } - break; - } - case SELF_AXIS: - { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - break; - } - default: // Children Axis - { - if (!walker.moveToFirstChild()) { - break; - } - - do { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - } while (walker.moveToNextSibling()); - break; - } - } - - // Apply predicates - if (!isEmpty()) { - rv = evaluatePredicates(nodes, aContext); - NS_ENSURE_SUCCESS(rv, rv); - } - - nodes->unsetReverse(); - - NS_ADDREF(*aResult = nodes); - - return NS_OK; -} - -void LocationStep::fromDescendants(const txXPathNode& aNode, - txIMatchContext* aCs, - txNodeSet* aNodes) -{ - txXPathTreeWalker walker(aNode); - if (!walker.moveToFirstChild()) { - return; - } - - do { - const txXPathNode& child = walker.getCurrentPosition(); - if (mNodeTest->matches(child, aCs)) { - aNodes->append(child); - } - fromDescendants(child, aCs, aNodes); - } while (walker.moveToNextSibling()); -} - -void LocationStep::fromDescendantsRev(const txXPathNode& aNode, - txIMatchContext* aCs, - txNodeSet* aNodes) -{ - txXPathTreeWalker walker(aNode); - if (!walker.moveToLastChild()) { - return; - } - - do { - const txXPathNode& child = walker.getCurrentPosition(); - fromDescendantsRev(child, aCs, aNodes); - - if (mNodeTest->matches(child, aCs)) { - aNodes->append(child); - } - - } while (walker.moveToPreviousSibling()); -} - -#ifdef TX_TO_STRING -void -LocationStep::toString(nsAString& str) -{ - switch (mAxisIdentifier) { - case ANCESTOR_AXIS : - str.AppendLiteral("ancestor::"); - break; - case ANCESTOR_OR_SELF_AXIS : - str.AppendLiteral("ancestor-or-self::"); - break; - case ATTRIBUTE_AXIS: - str.Append(PRUnichar('@')); - break; - case DESCENDANT_AXIS: - str.AppendLiteral("descendant::"); - break; - case DESCENDANT_OR_SELF_AXIS: - str.AppendLiteral("descendant-or-self::"); - break; - case FOLLOWING_AXIS : - str.AppendLiteral("following::"); - break; - case FOLLOWING_SIBLING_AXIS: - str.AppendLiteral("following-sibling::"); - break; - case NAMESPACE_AXIS: - str.AppendLiteral("namespace::"); - break; - case PARENT_AXIS : - str.AppendLiteral("parent::"); - break; - case PRECEDING_AXIS : - str.AppendLiteral("preceding::"); - break; - case PRECEDING_SIBLING_AXIS : - str.AppendLiteral("preceding-sibling::"); - break; - case SELF_AXIS : - str.AppendLiteral("self::"); - break; - default: - break; - } - NS_ASSERTION(mNodeTest, "mNodeTest is null, that's verboten"); - mNodeTest->toString(str); - - PredicateList::toString(str); -} -#endif diff --git a/extensions/transformiix/source/xpath/Makefile.in b/extensions/transformiix/source/xpath/Makefile.in deleted file mode 100644 index 691290980ad4..000000000000 --- a/extensions/transformiix/source/xpath/Makefile.in +++ /dev/null @@ -1,127 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxpath_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += dom \ - content \ - widget \ - xpconnect \ - js \ - unicharutil \ - layout \ - necko \ - htmlparser \ - $(NULL) -endif - -CPPSRCS = AdditiveExpr.cpp \ - AttributeValueTemplate.cpp \ - BooleanExpr.cpp \ - BooleanFunctionCall.cpp \ - BooleanResult.cpp \ - ExprLexer.cpp \ - ExprParser.cpp \ - FilterExpr.cpp \ - FunctionCall.cpp \ - LocationStep.cpp \ - MultiplicativeExpr.cpp \ - NodeSetFunctionCall.cpp \ - NumberFunctionCall.cpp \ - NumberResult.cpp \ - PathExpr.cpp \ - PredicateList.cpp \ - RelationalExpr.cpp \ - RootExpr.cpp \ - StringFunctionCall.cpp \ - StringResult.cpp \ - txErrorExpr.cpp \ - txLiteralExpr.cpp \ - txNameTest.cpp \ - txNodeSet.cpp \ - txNodeTypeTest.cpp \ - txForwardContext.cpp \ - txNodeSetContext.cpp \ - txResultRecycler.cpp \ - UnionExpr.cpp \ - UnaryExpr.cpp \ - VariableRefExpr.cpp -ifndef TX_EXE -CPPSRCS += nsXPathEvaluator.cpp \ - nsXPathException.cpp \ - nsXPathExpression.cpp \ - nsXPathNSResolver.cpp \ - nsXPathResult.cpp \ - nsXPath1Scheme.cpp \ - txMozillaXPathTreeWalker.cpp -else -CPPSRCS += txStandaloneXPathTreeWalker.cpp -endif - -ifndef TX_EXE -ifndef DISABLE_XFORMS_HOOKS -EXPORTS = nsIXFormsUtilityService.h \ - nsIXFormsXPathEvaluator.h - -CPPSRCS += nsXFormsXPathEvaluator.cpp \ - XFormsFunctionCall.cpp -endif -endif - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir) -I$(srcdir)/../base \ - -I$(srcdir)/../xml -I$(srcdir)/../xml/dom \ - -I$(srcdir)/../xslt diff --git a/extensions/transformiix/source/xpath/MultiplicativeExpr.cpp b/extensions/transformiix/source/xpath/MultiplicativeExpr.cpp deleted file mode 100644 index 570a89385d1d..000000000000 --- a/extensions/transformiix/source/xpath/MultiplicativeExpr.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Represents a MultiplicativeExpr, an binary expression that - * performs a multiplicative operation between it's lvalue and rvalue: - * * : multiply - * mod : modulus - * div : divide -**/ - -#include "Expr.h" -#include "ExprResult.h" -#include -#include "txIXPathContext.h" - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -MultiplicativeExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = rightExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - double rightDbl = exprRes->numberValue(); - - rv = leftExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - double leftDbl = exprRes->numberValue(); - double result = 0; - - switch ( op ) { - case DIVIDE: - if (rightDbl == 0) { -#if defined(XP_WIN) - /* XXX MSVC miscompiles such that (NaN == 0) */ - if (Double::isNaN(rightDbl)) - result = Double::NaN; - else -#endif - if (leftDbl == 0 || Double::isNaN(leftDbl)) - result = Double::NaN; - else if (Double::isNeg(leftDbl) ^ Double::isNeg(rightDbl)) - result = Double::NEGATIVE_INFINITY; - else - result = Double::POSITIVE_INFINITY; - } - else - result = leftDbl / rightDbl; - break; - case MODULUS: - if (rightDbl == 0) { - result = Double::NaN; - } - else { -#if defined(XP_WIN) - /* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */ - if (!Double::isInfinite(leftDbl) && Double::isInfinite(rightDbl)) - result = leftDbl; - else -#endif - result = fmod(leftDbl, rightDbl); - } - break; - default: - result = leftDbl * rightDbl; - break; - } - - return aContext->recycler()->getNumberResult(result, aResult); -} //-- evaluate - -#ifdef TX_TO_STRING -void -MultiplicativeExpr::toString(nsAString& str) -{ - if ( leftExpr ) leftExpr->toString(str); - else str.AppendLiteral("null"); - - switch ( op ) { - case DIVIDE: - str.AppendLiteral(" div "); - break; - case MODULUS: - str.AppendLiteral(" mod "); - break; - default: - str.AppendLiteral(" * "); - break; - } - if ( rightExpr ) rightExpr->toString(str); - else str.AppendLiteral("null"); - -} -#endif diff --git a/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp b/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp deleted file mode 100644 index a6788bb7672f..000000000000 --- a/extensions/transformiix/source/xpath/NodeSetFunctionCall.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * NodeSetFunctionCall - * A representation of the XPath NodeSet funtions - */ - -#include "FunctionLib.h" -#include "nsAutoPtr.h" -#include "txNodeSet.h" -#include "txAtoms.h" -#include "txIXPathContext.h" -#include "txTokenizer.h" - -/* - * Creates a NodeSetFunctionCall of the given type - */ -NodeSetFunctionCall::NodeSetFunctionCall(NodeSetFunctions aType) - : mType(aType) -{ -} - -/* - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - */ -nsresult -NodeSetFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - nsresult rv = NS_OK; - txListIterator iter(¶ms); - - switch (mType) { - case COUNT: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr nodes; - rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - return aContext->recycler()->getNumberResult(nodes->size(), - aResult); - } - case ID: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr exprResult; - rv = ((Expr*)iter.next())->evaluate(aContext, - getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr resultSet; - rv = aContext->recycler()->getNodeSet(getter_AddRefs(resultSet)); - NS_ENSURE_SUCCESS(rv, rv); - - txXPathTreeWalker walker(aContext->getContextNode()); - - if (exprResult->getResultType() == txAExprResult::NODESET) { - txNodeSet* nodes = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprResult)); - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - nsAutoString idList; - txXPathNodeUtils::appendNodeValue(nodes->get(i), idList); - txTokenizer tokenizer(idList); - while (tokenizer.hasMoreTokens()) { - if (walker.moveToElementById(tokenizer.nextToken())) { - resultSet->add(walker.getCurrentPosition()); - } - } - } - } - else { - nsAutoString idList; - exprResult->stringValue(idList); - txTokenizer tokenizer(idList); - while (tokenizer.hasMoreTokens()) { - if (walker.moveToElementById(tokenizer.nextToken())) { - resultSet->add(walker.getCurrentPosition()); - } - } - } - - *aResult = resultSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - case LAST: - { - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - return aContext->recycler()->getNumberResult(aContext->size(), - aResult); - } - case LOCAL_NAME: - case NAME: - case NAMESPACE_URI: - { - if (!requireParams(0, 1, aContext)) { - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - // Check for optional arg - nsRefPtr nodes; - if (iter.hasNext()) { - rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (nodes->isEmpty()) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - } - - const txXPathNode& node = nodes ? nodes->get(0) : - aContext->getContextNode(); - switch (mType) { - case LOCAL_NAME: - { - StringResult* strRes = nsnull; - rv = aContext->recycler()->getStringResult(&strRes); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = strRes; - txXPathNodeUtils::getLocalName(node, strRes->mValue); - - return NS_OK; - } - case NAMESPACE_URI: - { - StringResult* strRes = nsnull; - rv = aContext->recycler()->getStringResult(&strRes); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = strRes; - txXPathNodeUtils::getNamespaceURI(node, strRes->mValue); - - return NS_OK; - } - case NAME: - { - // XXX Namespace: namespaces have a name - if (txXPathNodeUtils::isAttribute(node) || - txXPathNodeUtils::isElement(node) || - txXPathNodeUtils::isProcessingInstruction(node)) { - StringResult* strRes = nsnull; - rv = aContext->recycler()->getStringResult(&strRes); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = strRes; - txXPathNodeUtils::getNodeName(node, strRes->mValue); - } - else { - aContext->recycler()->getEmptyStringResult(aResult); - } - - return NS_OK; - } - default: - { - break; - } - } - } - case POSITION: - { - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - return aContext->recycler()->getNumberResult(aContext->position(), - aResult); - } - } - - aContext->receiveError(NS_LITERAL_STRING("Internal error"), - NS_ERROR_UNEXPECTED); - return NS_ERROR_UNEXPECTED; -} - -#ifdef TX_TO_STRING -nsresult -NodeSetFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - switch (mType) { - case COUNT: - { - *aAtom = txXPathAtoms::count; - break; - } - case ID: - { - *aAtom = txXPathAtoms::id; - break; - } - case LAST: - { - *aAtom = txXPathAtoms::last; - break; - } - case LOCAL_NAME: - { - *aAtom = txXPathAtoms::localName; - break; - } - case NAME: - { - *aAtom = txXPathAtoms::name; - break; - } - case NAMESPACE_URI: - { - *aAtom = txXPathAtoms::namespaceUri; - break; - } - case POSITION: - { - *aAtom = txXPathAtoms::position; - break; - } - default: - { - *aAtom = 0; - return NS_ERROR_FAILURE; - } - } - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xpath/NumberFunctionCall.cpp b/extensions/transformiix/source/xpath/NumberFunctionCall.cpp deleted file mode 100644 index 2fdd011e40f2..000000000000 --- a/extensions/transformiix/source/xpath/NumberFunctionCall.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * NumberFunctionCall - * A representation of the XPath Number funtions - */ - -#include "FunctionLib.h" -#include -#include "txNodeSet.h" -#include "txAtoms.h" -#include "txIXPathContext.h" - -/* - * Creates a NumberFunctionCall of the given type - */ -NumberFunctionCall::NumberFunctionCall(NumberFunctions aType) - : mType(aType) -{ -} - -/* - * Evaluates this Expr based on the given context node and processor state - * @param context the context Node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - */ -nsresult -NumberFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - txListIterator iter(¶ms); - if (mType == NUMBER) { - if (!requireParams(0, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - else { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - switch (mType) { - case CEILING: - { - double dbl = evaluateToNumber((Expr*)iter.next(), aContext); - if (!Double::isNaN(dbl) && !Double::isInfinite(dbl)) { - if (Double::isNeg(dbl) && dbl > -1) { - dbl *= 0; - } - else { - dbl = ceil(dbl); - } - } - - return aContext->recycler()->getNumberResult(dbl, aResult); - } - case FLOOR: - { - double dbl = evaluateToNumber((Expr*)iter.next(), aContext); - if (!Double::isNaN(dbl) && - !Double::isInfinite(dbl) && - !(dbl == 0 && Double::isNeg(dbl))) { - dbl = floor(dbl); - } - - return aContext->recycler()->getNumberResult(dbl, aResult); - } - case ROUND: - { - double dbl = evaluateToNumber((Expr*)iter.next(), aContext); - if (!Double::isNaN(dbl) && !Double::isInfinite(dbl)) { - if (Double::isNeg(dbl) && dbl >= -0.5) { - dbl *= 0; - } - else { - dbl = floor(dbl + 0.5); - } - } - - return aContext->recycler()->getNumberResult(dbl, aResult); - } - case SUM: - { - nsRefPtr nodes; - nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - double res = 0; - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr); - res += Double::toDouble(resultStr); - } - return aContext->recycler()->getNumberResult(res, aResult); - } - case NUMBER: - { - double res; - if (iter.hasNext()) { - res = evaluateToNumber((Expr*)iter.next(), aContext); - } - else { - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(aContext->getContextNode(), - resultStr); - res = Double::toDouble(resultStr); - } - return aContext->recycler()->getNumberResult(res, aResult); - } - } - - aContext->receiveError(NS_LITERAL_STRING("Internal error"), - NS_ERROR_UNEXPECTED); - return NS_ERROR_UNEXPECTED; -} - -#ifdef TX_TO_STRING -nsresult -NumberFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - switch (mType) { - case NUMBER: - { - *aAtom = txXPathAtoms::number; - break; - } - case ROUND: - { - *aAtom = txXPathAtoms::round; - break; - } - case FLOOR: - { - *aAtom = txXPathAtoms::floor; - break; - } - case CEILING: - { - *aAtom = txXPathAtoms::ceiling; - break; - } - case SUM: - { - *aAtom = txXPathAtoms::sum; - break; - } - default: - { - *aAtom = 0; - return NS_ERROR_FAILURE; - } - } - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xpath/NumberResult.cpp b/extensions/transformiix/source/xpath/NumberResult.cpp deleted file mode 100644 index 52a722880817..000000000000 --- a/extensions/transformiix/source/xpath/NumberResult.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * NumberResult - * Represents the a number as the result of evaluating an Expr -**/ - -#include "ExprResult.h" - -/** - * Default Constructor -**/ - -/** - * Creates a new NumberResult with the value of the given double parameter - * @param dbl the double to use for initialization of this NumberResult's value -**/ -NumberResult::NumberResult(double aValue, txResultRecycler* aRecycler) - : txAExprResult(aRecycler), value(aValue) -{ -} //-- NumberResult - -/* - * Virtual Methods from ExprResult -*/ - -short NumberResult::getResultType() { - return txAExprResult::NUMBER; -} //-- getResultType - -void NumberResult::stringValue(nsAString& str) { - Double::toString(value, str); -} //-- stringValue - -nsAString* -NumberResult::stringValuePointer() -{ - return nsnull; -} - -MBool NumberResult::booleanValue() { - // OG+ - // As per the XPath spec, the boolean value of a number is true if and only if - // it is neither positive 0 nor negative 0 nor NaN - return (MBool)(value != 0.0 && !Double::isNaN(value)); - // OG- -} //-- booleanValue - -double NumberResult::numberValue() { - return this->value; -} //-- numberValue - diff --git a/extensions/transformiix/source/xpath/PathExpr.cpp b/extensions/transformiix/source/xpath/PathExpr.cpp deleted file mode 100644 index 16f23dfdf47b..000000000000 --- a/extensions/transformiix/source/xpath/PathExpr.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txNodeSet.h" -#include "txNodeSetContext.h" -#include "txSingleNodeContext.h" -#include "XMLUtils.h" - - //------------/ - //- PathExpr -/ -//------------/ - -/** - * Creates a new PathExpr -**/ -PathExpr::PathExpr() -{ - //-- do nothing -} - -/** - * Destructor, will delete all Expressions -**/ -PathExpr::~PathExpr() -{ - txListIterator iter(&expressions); - while (iter.hasNext()) { - delete NS_STATIC_CAST(PathExprItem*, iter.next()); - } -} //-- ~PathExpr - -/** - * Adds the Expr to this PathExpr - * @param expr the Expr to add to this PathExpr -**/ -nsresult -PathExpr::addExpr(Expr* aExpr, PathOperator pathOp) -{ - NS_ASSERTION(expressions.getLength() > 0 || pathOp == RELATIVE_OP, - "First step has to be relative in PathExpr"); - PathExprItem* pxi = new PathExprItem(aExpr, pathOp); - if (!pxi) { - delete aExpr; - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult rv = expressions.add(pxi); - if (NS_FAILED(rv)) { - delete pxi; - } - return rv; -} //-- addExpr - - //-----------------------------/ - //- Virtual methods from Expr -/ -//-----------------------------/ - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -PathExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr nodes; - nsresult rv = aContext->recycler()->getNodeSet(aContext->getContextNode(), - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - txListIterator iter(&expressions); - PathExprItem* pxi; - while ((pxi = (PathExprItem*)iter.next())) { - nsRefPtr tmpNodes; - txNodeSetContext eContext(nodes, aContext); - while (eContext.hasNext()) { - eContext.next(); - - nsRefPtr resNodes; - if (pxi->pathOp == DESCENDANT_OP) { - rv = aContext->recycler()->getNodeSet(getter_AddRefs(resNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = evalDescendants(pxi->expr, eContext.getContextNode(), - &eContext, resNodes); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - nsRefPtr res; - rv = pxi->expr->evaluate(&eContext, getter_AddRefs(res)); - NS_ENSURE_SUCCESS(rv, rv); - - if (res->getResultType() != txAExprResult::NODESET) { - //XXX ErrorReport: report nonnodeset error - return NS_ERROR_XSLT_NODESET_EXPECTED; - } - resNodes = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - res)); - } - - if (tmpNodes) { - if (!resNodes->isEmpty()) { - nsRefPtr oldSet; - oldSet.swap(tmpNodes); - rv = aContext->recycler()-> - getNonSharedNodeSet(oldSet, getter_AddRefs(tmpNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - oldSet.swap(resNodes); - rv = aContext->recycler()-> - getNonSharedNodeSet(oldSet, getter_AddRefs(resNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - tmpNodes->addAndTransfer(resNodes); - } - } - else { - tmpNodes = resNodes; - } - } - nodes = tmpNodes; - if (nodes->isEmpty()) { - break; - } - } - - *aResult = nodes; - NS_ADDREF(*aResult); - - return NS_OK; -} //-- evaluate - -/** - * Selects from the descendants of the context node - * all nodes that match the Expr -**/ -nsresult -PathExpr::evalDescendants(Expr* aStep, const txXPathNode& aNode, - txIMatchContext* aContext, txNodeSet* resNodes) -{ - txSingleNodeContext eContext(aNode, aContext); - nsRefPtr res; - nsresult rv = aStep->evaluate(&eContext, getter_AddRefs(res)); - NS_ENSURE_SUCCESS(rv, rv); - - if (res->getResultType() != txAExprResult::NODESET) { - //XXX ErrorReport: report nonnodeset error - return NS_ERROR_XSLT_NODESET_EXPECTED; - } - - txNodeSet* oldSet = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, res)); - nsRefPtr newSet; - rv = aContext->recycler()->getNonSharedNodeSet(oldSet, - getter_AddRefs(newSet)); - NS_ENSURE_SUCCESS(rv, rv); - - resNodes->addAndTransfer(newSet); - - MBool filterWS = aContext->isStripSpaceAllowed(aNode); - - txXPathTreeWalker walker(aNode); - if (!walker.moveToFirstChild()) { - return NS_OK; - } - - do { - const txXPathNode& node = walker.getCurrentPosition(); - if (!(filterWS && txXPathNodeUtils::isText(node) && - txXPathNodeUtils::isWhitespace(node))) { - rv = evalDescendants(aStep, node, aContext, resNodes); - NS_ENSURE_SUCCESS(rv, rv); - } - } while (walker.moveToNextSibling()); - - return NS_OK; -} //-- evalDescendants - -#ifdef TX_TO_STRING -void -PathExpr::toString(nsAString& dest) -{ - txListIterator iter(&expressions); - - PathExprItem* pxi = (PathExprItem*)iter.next(); - if (pxi) { - NS_ASSERTION(pxi->pathOp == RELATIVE_OP, - "First step should be relative"); - pxi->expr->toString(dest); - } - - while ((pxi = (PathExprItem*)iter.next())) { - switch (pxi->pathOp) { - case DESCENDANT_OP: - dest.AppendLiteral("//"); - break; - case RELATIVE_OP: - dest.Append(PRUnichar('/')); - break; - } - pxi->expr->toString(dest); - } -} -#endif diff --git a/extensions/transformiix/source/xpath/PredicateList.cpp b/extensions/transformiix/source/xpath/PredicateList.cpp deleted file mode 100644 index 9aeff275b925..000000000000 --- a/extensions/transformiix/source/xpath/PredicateList.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txNodeSet.h" -#include "txNodeSetContext.h" - -/* - * Represents an ordered list of Predicates, - * for use with Step and Filter Expressions - */ - -PredicateList::PredicateList() -{ -} // PredicateList - -/* - * Destructor, will delete all Expressions in the list - */ -PredicateList::~PredicateList() -{ - txListIterator iter(&predicates); - while (iter.hasNext()) { - delete (Expr*)iter.next(); - } -} // ~PredicateList - -/* - * Adds the given Expr to the list - * @param expr the Expr to add to the list - */ -nsresult -PredicateList::add(Expr* aExpr) -{ - NS_ASSERTION(aExpr, "missing expression"); - nsresult rv = predicates.add(aExpr); - if (NS_FAILED(rv)) { - delete aExpr; - } - return rv; -} // add - -nsresult -PredicateList::evaluatePredicates(txNodeSet* nodes, - txIMatchContext* aContext) -{ - NS_ASSERTION(nodes, "called evaluatePredicates with NULL NodeSet"); - nsresult rv = NS_OK; - - txListIterator iter(&predicates); - while (iter.hasNext() && !nodes->isEmpty()) { - Expr* expr = (Expr*)iter.next(); - txNodeSetContext predContext(nodes, aContext); - /* - * add nodes to newNodes that match the expression - * or, if the result is a number, add the node with the right - * position - */ - PRInt32 index = 0; - while (predContext.hasNext()) { - predContext.next(); - nsRefPtr exprResult; - rv = expr->evaluate(&predContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - // handle default, [position() == numberValue()] - if (exprResult->getResultType() == txAExprResult::NUMBER) { - if ((double)predContext.position() == exprResult->numberValue()) { - nodes->mark(index); - } - } - else if (exprResult->booleanValue()) { - nodes->mark(index); - } - ++index; - } - // sweep the non-marked nodes - nodes->sweep(); - } - - return NS_OK; -} - -/* - * returns true if this predicate list is empty - */ -MBool PredicateList::isEmpty() -{ - return (MBool)(predicates.getLength() == 0); -} // isEmpty - -#ifdef TX_TO_STRING -void PredicateList::toString(nsAString& dest) -{ - txListIterator iter(&predicates); - while (iter.hasNext()) { - Expr* expr = (Expr*) iter.next(); - dest.Append(PRUnichar('[')); - expr->toString(dest); - dest.Append(PRUnichar(']')); - } -} -#endif diff --git a/extensions/transformiix/source/xpath/RelationalExpr.cpp b/extensions/transformiix/source/xpath/RelationalExpr.cpp deleted file mode 100644 index e4fc1b96b331..000000000000 --- a/extensions/transformiix/source/xpath/RelationalExpr.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txNodeSet.h" -#include "txIXPathContext.h" - -/** - * Compares the two ExprResults based on XPath 1.0 Recommendation (section 3.4) - */ -PRBool -RelationalExpr::compareResults(txIEvalContext* aContext, txAExprResult* aLeft, - txAExprResult* aRight) -{ - short ltype = aLeft->getResultType(); - short rtype = aRight->getResultType(); - nsresult rv = NS_OK; - - // Handle case for just Left NodeSet or Both NodeSets - if (ltype == txAExprResult::NODESET) { - if (rtype == txAExprResult::BOOLEAN) { - BooleanResult leftBool(aLeft->booleanValue()); - return compareResults(aContext, &leftBool, aRight); - } - - txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aLeft); - nsRefPtr strResult; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strResult)); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 i; - for (i = 0; i < nodeSet->size(); ++i) { - strResult->mValue.Truncate(); - txXPathNodeUtils::appendNodeValue(nodeSet->get(i), - strResult->mValue); - if (compareResults(aContext, strResult, aRight)) { - return PR_TRUE; - } - } - - return PR_FALSE; - } - - // Handle case for Just Right NodeSet - if (rtype == txAExprResult::NODESET) { - if (ltype == txAExprResult::BOOLEAN) { - BooleanResult rightBool(aRight->booleanValue()); - return compareResults(aContext, aLeft, &rightBool); - } - - txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aRight); - nsRefPtr strResult; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strResult)); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 i; - for (i = 0; i < nodeSet->size(); ++i) { - strResult->mValue.Truncate(); - txXPathNodeUtils::appendNodeValue(nodeSet->get(i), - strResult->mValue); - if (compareResults(aContext, aLeft, strResult)) { - return PR_TRUE; - } - } - - return PR_FALSE; - } - - // Neither is a NodeSet - if (mOp == EQUAL || mOp == NOT_EQUAL) { - PRBool result; - nsAString *lString, *rString; - - // If either is a bool, compare as bools. - if (ltype == txAExprResult::BOOLEAN || - rtype == txAExprResult::BOOLEAN) { - result = aLeft->booleanValue() == aRight->booleanValue(); - } - - // If either is a number, compare as numbers. - else if (ltype == txAExprResult::NUMBER || - rtype == txAExprResult::NUMBER) { - double lval = aLeft->numberValue(); - double rval = aRight->numberValue(); -#if defined(XP_WIN) - if (Double::isNaN(lval) || Double::isNaN(rval)) - result = PR_FALSE; - else - result = lval == rval; -#else - result = lval == rval; -#endif - } - - // Otherwise compare as strings. Try to use the stringobject in - // StringResult if possible since that is a common case. - else if ((lString = aLeft->stringValuePointer())) { - if ((rString = aRight->stringValuePointer())) { - result = lString->Equals(*rString); - } - else { - nsAutoString rStr; - aRight->stringValue(rStr); - result = rStr.Equals(*lString); - } - } - else if ((rString = aRight->stringValuePointer())) { - nsAutoString lStr; - aLeft->stringValue(lStr); - result = rString->Equals(lStr); - } - else { - nsAutoString lStr, rStr; - aLeft->stringValue(lStr); - aRight->stringValue(rStr); - result = lStr.Equals(rStr); - } - - return mOp == EQUAL ? result : !result; - } - - double leftDbl = aLeft->numberValue(); - double rightDbl = aRight->numberValue(); -#if defined(XP_WIN) - if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl)) - return PR_FALSE; -#endif - - switch (mOp) { - case LESS_THAN: - { - return leftDbl < rightDbl; - } - case LESS_OR_EQUAL: - { - return leftDbl <= rightDbl; - } - case GREATER_THAN: - { - return leftDbl > rightDbl; - } - case GREATER_OR_EQUAL: - { - return leftDbl >= rightDbl; - } - default: - { - NS_NOTREACHED("We should have caught all cases"); - } - } - - return PR_FALSE; -} - -nsresult -RelationalExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - nsRefPtr lResult; - nsresult rv = mLeftExpr->evaluate(aContext, getter_AddRefs(lResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr rResult; - rv = mRightExpr->evaluate(aContext, getter_AddRefs(rResult)); - NS_ENSURE_SUCCESS(rv, rv); - - aContext->recycler()-> - getBoolResult(compareResults(aContext, lResult, rResult), aResult); - - return NS_OK; -} - -#ifdef TX_TO_STRING -void -RelationalExpr::toString(nsAString& str) -{ - mLeftExpr->toString(str); - - switch (mOp) { - case NOT_EQUAL: - str.AppendLiteral("!="); - break; - case LESS_THAN: - str.Append(PRUnichar('<')); - break; - case LESS_OR_EQUAL: - str.AppendLiteral("<="); - break; - case GREATER_THAN : - str.Append(PRUnichar('>')); - break; - case GREATER_OR_EQUAL: - str.AppendLiteral(">="); - break; - default: - str.Append(PRUnichar('=')); - break; - } - - mRightExpr->toString(str); -} -#endif diff --git a/extensions/transformiix/source/xpath/RootExpr.cpp b/extensions/transformiix/source/xpath/RootExpr.cpp deleted file mode 100644 index a62f000e2141..000000000000 --- a/extensions/transformiix/source/xpath/RootExpr.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txNodeSet.h" -#include "txIXPathContext.h" - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -RootExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - const txXPathNode& context = aContext->getContextNode(); - nsAutoPtr document(txXPathNodeUtils::getDocument(context)); - if (!document) { - nsRefPtr nodes; - aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); - if (!nodes) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult = nodes); - - return NS_OK; - } - - return aContext->recycler()->getNodeSet(*document, aResult); -} //-- evaluate - -#ifdef TX_TO_STRING -void -RootExpr::toString(nsAString& dest) -{ - if (mSerialize) - dest.Append(PRUnichar('/')); -} -#endif diff --git a/extensions/transformiix/source/xpath/StringFunctionCall.cpp b/extensions/transformiix/source/xpath/StringFunctionCall.cpp deleted file mode 100644 index f9b66d2b8301..000000000000 --- a/extensions/transformiix/source/xpath/StringFunctionCall.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * StringFunctionCall - * A representation of the XPath String funtions -**/ - -#include "ExprResult.h" -#include "FunctionLib.h" -#include "txAtoms.h" -#include "txError.h" -#include "txIXPathContext.h" -#include "XMLUtils.h" -#include "txXPathTreeWalker.h" -#include -#include "nsReadableUtils.h" - -/** - * Creates a StringFunctionCall of the given type -**/ -StringFunctionCall::StringFunctionCall(StringFunctions aType) : mType(aType) -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -StringFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsresult rv = NS_OK; - txListIterator iter(¶ms); - switch (mType) { - case CONCAT: - { - if (!requireParams(2, -1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr strRes; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes)); - NS_ENSURE_SUCCESS(rv, rv); - - while (iter.hasNext()) { - evaluateToString((Expr*)iter.next(), aContext, strRes->mValue); - } - *aResult = strRes; - NS_ADDREF(*aResult); - - return NS_OK; - } - case CONTAINS: - { - if (!requireParams(2, 2, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString arg1, arg2; - Expr* arg1Expr = (Expr*)iter.next(); - evaluateToString((Expr*)iter.next(), aContext, arg2); - if (arg2.IsEmpty()) { - aContext->recycler()->getBoolResult(PR_TRUE, aResult); - } - else { - evaluateToString(arg1Expr, aContext, arg1); - aContext->recycler()->getBoolResult(arg1.Find(arg2) >= 0, - aResult); - } - - return NS_OK; - } - case NORMALIZE_SPACE: - { - if (!requireParams(0, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString resultStr; - if (iter.hasNext()) - evaluateToString((Expr*)iter.next(), aContext, resultStr); - else - txXPathNodeUtils::appendNodeValue(aContext->getContextNode(), - resultStr); - - nsRefPtr strRes; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes)); - NS_ENSURE_SUCCESS(rv, rv); - - MBool addSpace = MB_FALSE; - MBool first = MB_TRUE; - strRes->mValue.SetCapacity(resultStr.Length()); - PRUnichar c; - PRUint32 src; - for (src = 0; src < resultStr.Length(); src++) { - c = resultStr.CharAt(src); - if (XMLUtils::isWhitespace(c)) { - addSpace = MB_TRUE; - } - else { - if (addSpace && !first) - strRes->mValue.Append(PRUnichar(' ')); - - strRes->mValue.Append(c); - addSpace = MB_FALSE; - first = MB_FALSE; - } - } - *aResult = strRes; - NS_ADDREF(*aResult); - - return NS_OK; - } - case STARTS_WITH: - { - if (!requireParams(2, 2, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString arg1, arg2; - Expr* arg1Expr = (Expr*)iter.next(); - evaluateToString((Expr*)iter.next(), aContext, arg2); - if (arg2.IsEmpty()) { - aContext->recycler()->getBoolResult(PR_TRUE, aResult); - } - else { - evaluateToString(arg1Expr, aContext, arg1); - aContext->recycler()->getBoolResult( - StringBeginsWith(arg1, arg2), aResult); - } - - return NS_OK; - } - case STRING_LENGTH: - { - if (!requireParams(0, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString resultStr; - if (iter.hasNext()) - evaluateToString((Expr*)iter.next(), aContext, resultStr); - else - txXPathNodeUtils::appendNodeValue(aContext->getContextNode(), - resultStr); - rv = aContext->recycler()->getNumberResult(resultStr.Length(), - aResult); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; - } - case SUBSTRING: - { - if (!requireParams(2, 3, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString src; - double start, end; - evaluateToString((Expr*)iter.next(), aContext, src); - start = evaluateToNumber((Expr*)iter.next(), aContext); - - // check for NaN or +/-Inf - if (Double::isNaN(start) || - Double::isInfinite(start) || - start >= src.Length() + 0.5) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - start = floor(start + 0.5) - 1; - if (iter.hasNext()) { - end = start + evaluateToNumber((Expr*)iter.next(), - aContext); - if (Double::isNaN(end) || end < 0) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - if (end > src.Length()) - end = src.Length(); - else - end = floor(end + 0.5); - } - else { - end = src.Length(); - } - - if (start < 0) - start = 0; - - if (start > end) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - return aContext->recycler()->getStringResult( - Substring(src, (PRUint32)start, (PRUint32)(end - start)), - aResult); - } - case SUBSTRING_AFTER: - { - if (!requireParams(2, 2, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString arg1, arg2; - evaluateToString((Expr*)iter.next(), aContext, arg1); - evaluateToString((Expr*)iter.next(), aContext, arg2); - if (arg2.IsEmpty()) { - return aContext->recycler()->getStringResult(arg1, aResult); - } - - PRInt32 idx = arg1.Find(arg2); - if (idx == kNotFound) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - PRUint32 len = arg2.Length(); - return aContext->recycler()->getStringResult( - Substring(arg1, idx + len, arg1.Length() - (idx + len)), - aResult); - } - case SUBSTRING_BEFORE: - { - if (!requireParams(2, 2, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString arg1, arg2; - Expr* arg1Expr = (Expr*)iter.next(); - evaluateToString((Expr*)iter.next(), aContext, arg2); - if (arg2.IsEmpty()) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - evaluateToString(arg1Expr, aContext, arg1); - - PRInt32 idx = arg1.Find(arg2); - if (idx == kNotFound) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - return aContext->recycler()-> - getStringResult(Substring(arg1, 0, idx), aResult); - } - case TRANSLATE: - { - if (!requireParams(3, 3, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString src; - evaluateToString((Expr*)iter.next(), aContext, src); - if (src.IsEmpty()) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - nsRefPtr strRes; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes)); - NS_ENSURE_SUCCESS(rv, rv); - - strRes->mValue.SetCapacity(src.Length()); - nsAutoString oldChars, newChars; - evaluateToString((Expr*)iter.next(), aContext, oldChars); - evaluateToString((Expr*)iter.next(), aContext, newChars); - PRUint32 i; - PRInt32 newCharsLength = (PRInt32)newChars.Length(); - for (i = 0; i < src.Length(); i++) { - PRInt32 idx = oldChars.FindChar(src.CharAt(i)); - if (idx != kNotFound) { - if (idx < newCharsLength) - strRes->mValue.Append(newChars.CharAt((PRUint32)idx)); - } - else { - strRes->mValue.Append(src.CharAt(i)); - } - } - *aResult = strRes; - NS_ADDREF(*aResult); - - return NS_OK; - } - case STRING: - { - if (!requireParams(0, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr strRes; - rv = aContext->recycler()->getStringResult(getter_AddRefs(strRes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (iter.hasNext()) - evaluateToString((Expr*)iter.next(), aContext, strRes->mValue); - else - txXPathNodeUtils::appendNodeValue(aContext->getContextNode(), - strRes->mValue); - *aResult = strRes; - NS_ADDREF(*aResult); - - return NS_OK; - } - } - - aContext->receiveError(NS_LITERAL_STRING("Internal error"), - NS_ERROR_UNEXPECTED); - return NS_ERROR_UNEXPECTED; -} - -#ifdef TX_TO_STRING -nsresult -StringFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - switch (mType) { - case CONCAT: - { - *aAtom = txXPathAtoms::concat; - break; - } - case CONTAINS: - { - *aAtom = txXPathAtoms::contains; - break; - } - case NORMALIZE_SPACE: - { - *aAtom = txXPathAtoms::normalizeSpace; - break; - } - case STARTS_WITH: - { - *aAtom = txXPathAtoms::startsWith; - break; - } - case STRING: - { - *aAtom = txXPathAtoms::string; - break; - } - case STRING_LENGTH: - { - *aAtom = txXPathAtoms::stringLength; - break; - } - case SUBSTRING: - { - *aAtom = txXPathAtoms::substring; - break; - } - case SUBSTRING_AFTER: - { - *aAtom = txXPathAtoms::substringAfter; - break; - } - case SUBSTRING_BEFORE: - { - *aAtom = txXPathAtoms::substringBefore; - break; - } - case TRANSLATE: - { - *aAtom = txXPathAtoms::translate; - break; - } - default: - { - *aAtom = 0; - return NS_ERROR_FAILURE; - } - } - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xpath/StringResult.cpp b/extensions/transformiix/source/xpath/StringResult.cpp deleted file mode 100644 index a220e17c7495..000000000000 --- a/extensions/transformiix/source/xpath/StringResult.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * StringResult - * Represents a String as a Result of evaluating an Expr -**/ -#include "ExprResult.h" - -/** - * Default Constructor -**/ -StringResult::StringResult(txResultRecycler* aRecycler) - : txAExprResult(aRecycler) -{ -} - -/** - * Creates a new StringResult with the value of the given String parameter - * @param str the String to use for initialization of this StringResult's value -**/ -StringResult::StringResult(const nsAString& aValue, txResultRecycler* aRecycler) - : txAExprResult(aRecycler), mValue(aValue) -{ -} - -/* - * Virtual Methods from ExprResult -*/ - -short StringResult::getResultType() { - return txAExprResult::STRING; -} //-- getResultType - -void StringResult::stringValue(nsAString& str) { - str.Append(mValue); -} //-- stringValue - -nsAString* -StringResult::stringValuePointer() -{ - return &mValue; -} - -MBool StringResult::booleanValue() { - return !mValue.IsEmpty(); -} //-- booleanValue - -double StringResult::numberValue() { - return Double::toDouble(mValue); -} //-- numberValue - diff --git a/extensions/transformiix/source/xpath/UnaryExpr.cpp b/extensions/transformiix/source/xpath/UnaryExpr.cpp deleted file mode 100644 index 563af4926ca1..000000000000 --- a/extensions/transformiix/source/xpath/UnaryExpr.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "ExprResult.h" -#include "txIXPathContext.h" - -/* - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation. - * @return the result of the evaluation. - */ -nsresult -UnaryExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsRefPtr exprRes; - nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - double value = exprRes->numberValue(); -#ifdef HPUX - /* - * Negation of a zero doesn't produce a negative - * zero on HPUX. Perform the operation by multiplying with - * -1. - */ - return aContext->recycler()->getNumberResult(-1 * value, aResult); -#else - return aContext->recycler()->getNumberResult(-value, aResult); -#endif -} - -#ifdef TX_TO_STRING -void -UnaryExpr::toString(nsAString& str) -{ - if (!expr) - return; - str.Append(PRUnichar('-')); - expr->toString(str); -} -#endif diff --git a/extensions/transformiix/source/xpath/UnionExpr.cpp b/extensions/transformiix/source/xpath/UnionExpr.cpp deleted file mode 100644 index 7029e1a0c5f4..000000000000 --- a/extensions/transformiix/source/xpath/UnionExpr.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "txIXPathContext.h" -#include "txNodeSet.h" - - //-------------/ - //- UnionExpr -/ -//-------------/ - - -/** - * Creates a new UnionExpr -**/ -UnionExpr::UnionExpr() { - //-- do nothing -} - -/** - * Destructor, will delete all Path Expressions -**/ -UnionExpr::~UnionExpr() { - txListIterator iter(&expressions); - while (iter.hasNext()) { - delete (Expr*)iter.next(); - } -} //-- ~UnionExpr - -/** - * Adds the Expr to this UnionExpr - * @param expr the Expr to add to this UnionExpr -**/ -nsresult -UnionExpr::addExpr(Expr* aExpr) -{ - nsresult rv = expressions.add(aExpr); - if (NS_FAILED(rv)) { - delete aExpr; - } - return rv; -} //-- addExpr - - //-----------------------------/ - //- Virtual methods from Expr -/ -//-----------------------------/ - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - nsRefPtr nodes; - nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - txListIterator iter(&expressions); - while (iter.hasNext()) { - Expr* expr = (Expr*)iter.next(); - nsRefPtr exprResult; - rv = expr->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - if (exprResult->getResultType() != txAExprResult::NODESET) { - //XXX ErrorReport: report nonnodeset error - return NS_ERROR_XSLT_NODESET_EXPECTED; - } - - nsRefPtr resultSet, ownedSet; - resultSet = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, exprResult)); - exprResult = nsnull; - rv = aContext->recycler()-> - getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = nodes->addAndTransfer(ownedSet); - NS_ENSURE_SUCCESS(rv, rv); - } - - *aResult = nodes; - NS_ADDREF(*aResult); - - return NS_OK; -} //-- evaluate - -#ifdef TX_TO_STRING -void -UnionExpr::toString(nsAString& dest) -{ - txListIterator iter(&expressions); - - short count = 0; - while (iter.hasNext()) { - //-- set operator - if (count > 0) - dest.AppendLiteral(" | "); - ((Expr*)iter.next())->toString(dest); - ++count; - } -} -#endif diff --git a/extensions/transformiix/source/xpath/VariableRefExpr.cpp b/extensions/transformiix/source/xpath/VariableRefExpr.cpp deleted file mode 100644 index 8da7da341320..000000000000 --- a/extensions/transformiix/source/xpath/VariableRefExpr.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "nsIAtom.h" -#include "txNodeSet.h" -#include "txAtoms.h" -#include "txIXPathContext.h" - - //-------------------/ - //- VariableRefExpr -/ -//-------------------/ - -/** - * Creates a VariableRefExpr with the given variable name -**/ -VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, - PRInt32 aNSID) - : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID) -{ - NS_ASSERTION(mLocalName, "VariableRefExpr without local name?"); - if (mPrefix == txXMLAtoms::_empty) - mPrefix = 0; -} - -/* - * Release the local name atom - */ -VariableRefExpr::~VariableRefExpr() -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation -**/ -nsresult -VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult); - if (NS_FAILED(rv)) { - // XXX report error, undefined variable - return rv; - } - return NS_OK; -} - -#ifdef TX_TO_STRING -void -VariableRefExpr::toString(nsAString& aDest) -{ - aDest.Append(PRUnichar('$')); - if (mPrefix) { - nsAutoString prefix; - mPrefix->ToString(prefix); - aDest.Append(prefix); - aDest.Append(PRUnichar(':')); - } - nsAutoString lname; - mLocalName->ToString(lname); - aDest.Append(lname); -} -#endif diff --git a/extensions/transformiix/source/xpath/XFormsFunctionCall.cpp b/extensions/transformiix/source/xpath/XFormsFunctionCall.cpp deleted file mode 100644 index 7fe1d53fc589..000000000000 --- a/extensions/transformiix/source/xpath/XFormsFunctionCall.cpp +++ /dev/null @@ -1,604 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * XFormsFunctionCall - * A representation of the XPath NodeSet funtions - */ - -#include "FunctionLib.h" -#include "nsAutoPtr.h" -#include "txNodeSet.h" -#include "txAtoms.h" -#include "txIXPathContext.h" -#include "txTokenizer.h" -#include "XFormsFunctions.h" -#include -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentEvent.h" -#include "nsIDOMEvent.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMElement.h" -#include "nsIXFormsUtilityService.h" -#include "nsServiceManagerUtils.h" // needed for do_GetService? -#include "prprf.h" - -/* - * Creates a XFormsFunctionCall of the given type - */ -XFormsFunctionCall::XFormsFunctionCall(XFormsFunctions aType, nsIDOMNode *aResolverNode) - : mType(aType) - , mResolverNode(aResolverNode) -{ -} - -/* - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - */ -nsresult -XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - nsresult rv = NS_OK; - txListIterator iter(¶ms); - - switch (mType) { - case AVG: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr nodes; - nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - double res = 0; - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr); - res += Double::toDouble(resultStr); - } - - if (i > 0) { - res = (res/i); - } - else { - res = Double::NaN; - } - return aContext->recycler()->getNumberResult(res, aResult); - } - case BOOLEANFROMSTRING: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - PRInt32 retvalue = -1; - nsAutoString booleanValue; - evaluateToString((Expr*)iter.next(), aContext, booleanValue); - - aContext->recycler()->getBoolResult( - booleanValue.EqualsLiteral("1") || - booleanValue.LowerCaseEqualsLiteral("true"), - aResult); - - return NS_OK; - } - case COUNTNONEMPTY: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr nodes; - nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - double res = 0, test = 0; - PRInt32 i, count=0; - for (i = 0; i < nodes->size(); ++i) { - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr); - if (!resultStr.IsEmpty()) { - count++; - } - } - - return aContext->recycler()->getNumberResult(count, aResult); - } - case DAYSFROMDATE: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString date; - evaluateToString((Expr*)iter.next(), aContext, date); - - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 result = 0; - double res = Double::NaN; - nsresult rv = xformsService->GetDaysFromDateTime(date, &result); - if (NS_SUCCEEDED(rv)) { - res = result; - } - else if (rv != NS_ERROR_ILLEGAL_VALUE) { - // if we failed for a reason other than the parameter value, pass that - // up the chain - return rv; - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - case IF: - { - if (!requireParams(3, 3, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - PRBool test; - nsAutoString valueToReturn; - test = evaluateToBoolean((Expr*)iter.next(), aContext); - - // grab 'true' value to return - Expr *getvalue = (Expr*)iter.next(); - - if (!test) { - // grab 'false' value to return - getvalue = (Expr*)iter.next(); - } - evaluateToString(getvalue, aContext, valueToReturn); - - return aContext->recycler()->getStringResult(valueToReturn, aResult); - } - case INDEX: - { - // Given an element's id as the parameter, need to query the element and - // make sure that it is a xforms:repeat node. Given that, must query - // its index. - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString indexId; - evaluateToString((Expr*)iter.next(), aContext, indexId); - - // here document is the XForms document - nsCOMPtr document; - rv = mResolverNode->GetOwnerDocument(getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(document, NS_ERROR_NULL_POINTER); - - // indexId should be the id of a nsIXFormsRepeatElement - nsCOMPtr repeatEle; - rv = document->GetElementById(indexId, getter_AddRefs(repeatEle)); - NS_ENSURE_SUCCESS(rv, rv); - - // now get the index value from the xforms:repeat. Need to use the - // service to do this work so that we don't have dependencies in - // transformiix on XForms. - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - PRUint32 index; - rv = xformsService->GetRepeatIndex(repeatEle, &index); - NS_ENSURE_SUCCESS(rv, rv); - - return aContext->recycler()->getNumberResult(index, aResult); - - } - case INSTANCE: - { - nsresult rv; - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr resultSet; - rv = aContext->recycler()->getNodeSet(getter_AddRefs(resultSet)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString instanceId; - evaluateToString((Expr*)iter.next(), aContext, instanceId); - - // here document is the XForms document - nsCOMPtr document; - rv = mResolverNode->GetOwnerDocument(getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(document, NS_ERROR_NULL_POINTER); - - nsCOMPtr instEle; - rv = document->GetElementById(instanceId, getter_AddRefs(instEle)); - - PRBool foundInstance = PR_FALSE; - nsAutoString localname, namespaceURI; - if (instEle) { - instEle->GetLocalName(localname); - instEle->GetNamespaceURI(namespaceURI); - if (localname.EqualsLiteral("instance") && - namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) { - foundInstance = PR_TRUE; - } - } - - if (!foundInstance) { - // We didn't find an instance element with the given id. Return the - // empty result set. - *aResult = resultSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - - // Make sure that this element is contained in the same - // model as the context node of the expression as per - // the XForms 1.0 spec. - - // first step is to get the contextNode passed in to - // the evaluation - - nsCOMPtr xfContextNode; - rv = txXPathNativeNode::getNode(aContext->getContextNode(), - getter_AddRefs(xfContextNode)); - NS_ENSURE_SUCCESS(rv, rv); - - // now see if the node we found (instEle) and the - // context node for the evaluation (xfContextNode) link - // back to the same model. - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr instNode, modelInstance; - instNode = do_QueryInterface(instEle); - rv = xformsService->GetModelFromNode(instNode, - getter_AddRefs(modelInstance)); - - NS_ENSURE_SUCCESS(rv, rv); - - PRBool modelContainsNode = PR_FALSE; - rv = xformsService->IsNodeAssocWithModel(xfContextNode, - modelInstance, - &modelContainsNode); - NS_ENSURE_SUCCESS(rv, rv); - - if (modelContainsNode) { - // ok, we've found an instance node with the proper id - // that fulfills the requirement of being from the - // same model as the context node. Now we need to - // return a 'node-set containing just the root - // element node of the referenced instance data'. - // Wonderful. - - nsCOMPtr instanceRoot; - rv = xformsService->GetInstanceDocumentRoot( - instanceId, - modelInstance, - getter_AddRefs(instanceRoot)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(instanceRoot, NS_ERROR_NULL_POINTER); - - nsAutoPtr txNode(txXPathNativeNode::createXPathNode(instanceRoot)); - if (txNode) { - resultSet->add(*txNode); - } - } - - - // XXX where we need to do the work - // if (walker.moveToElementById(instanceId)) { - // resultSet->add(walker.getCurrentPosition()); - // } - - *aResult = resultSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - case MAX: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr nodes; - nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - double res = Double::NaN; - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - double test; - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr); - test = Double::toDouble(resultStr); - if (Double::isNaN(test)) { - res = Double::NaN; - break; - } - if (test > res || i == 0) { - res = test; - } - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - case MIN: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsRefPtr nodes; - nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - double res = Double::NaN; - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - double test; - nsAutoString resultStr; - txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr); - test = Double::toDouble(resultStr); - if (Double::isNaN(test)) { - res = Double::NaN; - break; - } - if ((test < res) || (i==0)) { - res = test; - } - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - case MONTHS: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString duration; - evaluateToString((Expr*)iter.next(), aContext, duration); - - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 result = 0; - double res = Double::NaN; - nsresult rv = xformsService->GetMonths(duration, &result); - if (NS_SUCCEEDED(rv)) { - res = result; - } - else if (rv != NS_ERROR_ILLEGAL_VALUE) { - // if we failed for a reason other than the parameter value, pass that - // up the chain - return rv; - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - case NOW: - { - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - PRExplodedTime time; - char ctime[60]; - - PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &time); - int gmtoffsethour = time.tm_params.tp_gmt_offset < 0 ? - -1*time.tm_params.tp_gmt_offset / 3600 : - time.tm_params.tp_gmt_offset / 3600; - int remainder = time.tm_params.tp_gmt_offset%3600; - int gmtoffsetminute = remainder ? remainder/60 : 00; - - char zone_location[40]; - const int zoneBufSize = sizeof(zone_location); - PR_snprintf(zone_location, zoneBufSize, "%c%02d:%02d\0", - time.tm_params.tp_gmt_offset < 0 ? '-' : '+', - gmtoffsethour, gmtoffsetminute); - - PR_FormatTime(ctime, sizeof(ctime), "%Y-%m-%dT%H:%M:%S\0", &time); - nsString sTime = NS_ConvertASCIItoUTF16(ctime) + NS_ConvertASCIItoUTF16(zone_location); - - return aContext->recycler()->getStringResult(sTime, aResult); - } - case PROPERTY: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString property; - evaluateToString((Expr*)iter.next(), aContext, property); - - // This function can handle "version" and "conformance-level" - // which is all that the XForms 1.0 spec is worried about - if (property.Equals(NS_LITERAL_STRING("version"))) - property.Assign(NS_LITERAL_STRING("1.0")); - else if (property.Equals(NS_LITERAL_STRING("conformance-level"))) - property.Assign(NS_LITERAL_STRING("basic")); - - return aContext->recycler()->getStringResult(property, aResult); - } - case SECONDS: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString duration; - evaluateToString((Expr*)iter.next(), aContext, duration); - - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - double res; - nsresult rv = xformsService->GetSeconds(duration, &res); - if (NS_FAILED(rv)) { - if (rv != NS_ERROR_ILLEGAL_VALUE) { - // if we failed for a reason other than the parameter value, pass that - // up the chain - return rv; - } - res = Double::NaN; - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - case SECONDSFROMDATETIME: - { - if (!requireParams(1, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsAutoString dateTime; - evaluateToString((Expr*)iter.next(), aContext, dateTime); - - nsCOMPtrxformsService = - do_GetService("@mozilla.org/xforms-utility-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - double res; - nsresult rv = xformsService->GetSecondsFromDateTime(dateTime, &res); - if (NS_FAILED(rv)) { - if (rv != NS_ERROR_ILLEGAL_VALUE) { - // if we failed for a reason other than the parameter value, pass that - // up the chain - return rv; - } - res = Double::NaN; - } - - return aContext->recycler()->getNumberResult(res, aResult); - } - } /* switch() */ - - aContext->receiveError(NS_LITERAL_STRING("Internal error"), - NS_ERROR_UNEXPECTED); - return NS_ERROR_UNEXPECTED; -} - -#ifdef TX_TO_STRING -nsresult -XFormsFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - switch (mType) { - case AVG: - { - *aAtom = txXPathAtoms::avg; - break; - } - case BOOLEANFROMSTRING: - { - *aAtom = txXPathAtoms::booleanFromString; - break; - } - case COUNTNONEMPTY: - { - *aAtom = txXPathAtoms::countNonEmpty; - break; - } - case DAYSFROMDATE: - { - *aAtom = txXPathAtoms::daysFromDate; - break; - } - case IF: - { - *aAtom = txXPathAtoms::ifFunc; - break; - } - case INDEX: - { - *aAtom = txXPathAtoms::index; - break; - } - case INSTANCE: - { - *aAtom = txXPathAtoms::instance; - break; - } - case MAX: - { - *aAtom = txXPathAtoms::max; - break; - } - case MIN: - { - *aAtom = txXPathAtoms::min; - break; - } - case MONTHS: - { - *aAtom = txXPathAtoms::months; - break; - } - case NOW: - { - *aAtom = txXPathAtoms::now; - break; - } - case PROPERTY: - { - *aAtom = txXPathAtoms::property; - break; - } - case SECONDS: - { - *aAtom = txXPathAtoms::seconds; - break; - } - case SECONDSFROMDATETIME: - { - *aAtom = txXPathAtoms::secondsFromDateTime; - break; - } - default: - { - *aAtom = 0; - return NS_ERROR_FAILURE; - } - } - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xpath/XFormsFunctions.h b/extensions/transformiix/source/xpath/XFormsFunctions.h deleted file mode 100644 index 6c05a910c009..000000000000 --- a/extensions/transformiix/source/xpath/XFormsFunctions.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_XFORMS_FUNCTIONS_H -#define TRANSFRMX_XFORMS_FUNCTIONS_H - -#include "Expr.h" -#include "nsIDOMNode.h" - -#define NS_NAMESPACE_XFORMS "http://www.w3.org/2002/xforms" -#define NS_NAMESPACE_SCHEMA "http://www.w3.org/1999/XMLSchema" - -/* - * Represents the XPath XForms Function Calls - */ -class XFormsFunctionCall : public FunctionCall { - -public: - - enum XFormsFunctions { - AVG, // avg() - BOOLEANFROMSTRING, // boolean-from-string() - COUNTNONEMPTY, // count-non-empty() - DAYSFROMDATE, // days-from-date() - IF, // if() - INDEX, // index() - INSTANCE, // instance() - MAX, // max() - MIN, // min() - MONTHS, // months() - NOW, // now() - PROPERTY, // property() - SECONDS, // seconds() - SECONDSFROMDATETIME // seconds-from-dateTime() - }; - - /* - * Creates a Number function of the given type - */ - XFormsFunctionCall(XFormsFunctions aType, nsIDOMNode *resolverNode=nsnull); - - TX_DECL_FUNCTION; - -private: - XFormsFunctions mType; - nsCOMPtr mResolverNode; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsIXFormsUtilityService.h b/extensions/transformiix/source/xpath/nsIXFormsUtilityService.h deleted file mode 100644 index a827b8be6e1e..000000000000 --- a/extensions/transformiix/source/xpath/nsIXFormsUtilityService.h +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIXFormsUtilityService_h -#define nsIXFormsUtilityService_h - - -#include "nsISupports.h" - -/* For IDL files that don't want to include root IDL files. */ -#ifndef NS_NO_VTABLE -#define NS_NO_VTABLE -#endif -class nsIDOMNode; /* forward declaration */ - -class nsIXFormsModelElement; /* forward declaration */ - - -/* starting interface: nsIXFormsUtilityService */ -#define NS_IXFORMSUTILITYSERVICE_IID_STR "4a744a59-8771-4065-959d-b8de3dad81da" - -#define NS_IXFORMSUTILITYSERVICE_IID \ - {0x4a744a59, 0x8771, 0x4065, \ - { 0x95, 0x9d, 0xb8, 0xde, 0x3d, 0xad, 0x81, 0xda }} - -#define NS_XFORMS_UTILITY_CONTRACTID "@mozilla.org/xforms-utility-service;1" - -/* Use this macro when declaring classes that implement this interface. */ -#define NS_DECL_NSIXFORMSUTILITYSERVICE \ - NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval); \ - NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval); \ - NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval); \ - NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval); \ - NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex); \ - NS_IMETHOD GetMonths(const nsAString & aValue, PRInt32 *aMonths); \ - NS_IMETHOD GetSeconds(const nsAString & aValue, double *aSeconds); \ - NS_IMETHOD GetSecondsFromDateTime(const nsAString & aValue, double *aSeconds); \ - NS_IMETHOD GetDaysFromDateTime(const nsAString & aValue, PRInt32 *aDays); - -/** - * Private interface implemented by the nsXFormsUtilityService in XForms extension. - * Defining it here to prevent XPath requiring XForms extension. - */ -class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports { - public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXFORMSUTILITYSERVICE_IID) - - /** - * Function to get the corresponding model element from a xforms node or - * a xforms instance data node. - */ - /* nsIDOMNode getModelFromNode (in nsIDOMNode node); */ - NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval) = 0; - - /** - * Function to see if the given node is associated with the given model. - * Right now this function is only called by XPath in the case of the - * instance() function. - * The provided node can be an instance node from an instance - * document and thus be associated to the model in that way (model elements - * contain instance elements). Otherwise the node will be an XForms element - * that was used as the context node of the XPath expression (i.e the - * XForms control has an attribute that contains an XPath expression). - * Form controls are associated with model elements either explicitly through - * single-node binding or implicitly (if model cannot by calculated, it - * will use the first model element encountered in the document). The model - * can also be inherited from a containing element like xforms:group or - * xforms:repeat. - */ - /* PRBool isNodeAssocWithModel (in nsIDOMNode aNode, in nsIDOMNode aModel); */ - NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval) = 0; - - /** - * Function to get the instance document root for the instance element with - * the given id. The instance element must be associated with the given - * model. - */ - /* nsIDOMNode getInstanceDocumentRoot (in DOMString aID, in nsIDOMNode aModelNode); */ - NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval) = 0; - - /** - * Function to ensure that aValue is of the schema type aType. Will basically - * be a forwarder to the nsISchemaValidator function of the same name. - */ - /* boolean validateString (in AString aValue, in AString aType, in AString aNamespace); */ - NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval) = 0; - - /** - * Function to retrieve the index from the given repeat element. - */ - /* unsigned long getRepeatIndex (in nsIDOMNode aRepeat); */ - NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex) = 0; - - /** - * Function to retrieve the number of months represented by the - * xsd:duration provided in aValue - */ - /* long getMonths (in DOMString aValue); */ - NS_IMETHOD GetMonths(const nsAString & aValue, PRInt32 *aMonths) = 0; - - /** - * Function to retrieve the number of seconds represented by the - * xsd:duration provided in aValue - */ - /* AString getSeconds (in DOMString aValue); */ - NS_IMETHOD GetSeconds(const nsAString & aValue, double *aSeconds) = 0; - - /** - * Function to retrieve the number of seconds represented by the - * xsd:dateTime provided in aValue - */ - /* AString getSecondsFromDateTime (in DOMString aValue); */ - NS_IMETHOD GetSecondsFromDateTime(const nsAString & aValue, - double *aSeconds) = 0; - - /** - * Function to retrieve the number of days represented by the - * xsd:dateTime provided in aValue - */ - /* AString getDaysFromDateTime (in DOMString aValue); */ - NS_IMETHOD GetDaysFromDateTime(const nsAString & aValue, - PRInt32 * aDays) = 0; -}; - -#define NS_ERROR_XFORMS_CALCUATION_EXCEPTION \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3001) - -#endif /* nsIXFormsUtilityService_h */ diff --git a/extensions/transformiix/source/xpath/nsIXFormsXPathEvaluator.h b/extensions/transformiix/source/xpath/nsIXFormsXPathEvaluator.h deleted file mode 100644 index d6163bd6c886..000000000000 --- a/extensions/transformiix/source/xpath/nsIXFormsXPathEvaluator.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIXFormsXPathEvaluator_h -#define nsIXFormsXPathEvaluator_h - - -#include "nsISupports.h" - -/* For IDL files that don't want to include root IDL files. */ -#ifndef NS_NO_VTABLE -#define NS_NO_VTABLE -#endif -class nsIDOMNode; /* forward declaration */ -class nsIDOMNSXPathExpression; /* forward declaration */ - -/* starting interface: nsIXFormsXPathEvaluator */ -#define NS_XFORMS_XPATH_EVALUATOR_CONTRACTID "@mozilla.org/dom/xforms-xpath-evaluator;1" -/* 4cdd884f-f949-4d82-bb78-b8edd9f1420c */ -#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_CID \ -{ 0x4cdd884f, 0xf949, 0x4d82, \ - {0xbb, 0x78, 0xb8, 0xed, 0xd9, 0xf1, 0x42, 0x0c} } - -/* 61e5a446-73f7-432e-a2d6-d94d4a51aed8 */ -#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID \ -{ 0x61e5a446, 0x73f7, 0x432e, \ - {0xa2, 0xd6, 0xd9, 0x4d, 0x4a, 0x51, 0xae, 0xd8} } - -/* Use this macro when declaring classes that implement this interface. */ -#define NS_DECL_NSIXFORMXPATHEVALUATOR \ - NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode, nsIDOMNSXPathExpression **aResult); \ - NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, PRUint32 aContextPosition, PRUint32 aContextSize, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult); - -/** - * Private interface implemented by the nsXFormsXPathEvaluator in Transformiix - * and will move to the XForms extension when XPath is made extensible. We - * are using this interface instead of nsIDOMXPathEvaluator since we can - * don't really need all of that overhead. For example, this interface uses - * a resolver node from the xforms document rather than forcing XForms to - * create a namespace resolver node prior to creating the expression or - * running an evaluation. - */ -class NS_NO_VTABLE nsIXFormsXPathEvaluator : public nsISupports { - public: - - NS_DEFINE_STATIC_IID_ACCESSOR(TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID) - - /** - * Function to create a nsIDOMNSXPathExpression from the provided expression - * string. aResolverNode is the xforms node that the expression is - * associated with. - */ - NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode, nsIDOMNSXPathExpression **aResult) = 0; - - /** - * Function to evaluate the given expression. aResolverNode is the xforms - * node that the expression is associated with. The other parameters are as - * required by DOM's XPathEvaluator. - */ - NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, PRUint32 aContextPosition, PRUint32 aContextSize, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult) = 0; - -}; - -#endif /* nsIXFormsXPathEvaluator_h */ diff --git a/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.cpp b/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.cpp deleted file mode 100644 index 915bfaf6801f..000000000000 --- a/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXFormsXPathEvaluator.h" -#include "nsCOMPtr.h" -#include "nsIAtom.h" -#include "nsIDOMClassInfo.h" -#include "nsXPathException.h" -#include "nsXPathExpression.h" -#include "nsXPathNSResolver.h" -#include "nsXPathResult.h" -#include "nsContentCID.h" -#include "Expr.h" -#include "ExprParser.h" -#include "nsDOMError.h" -#include "txURIUtils.h" -#include "nsIDocument.h" -#include "nsIDOMDocument.h" -#include "nsDOMString.h" -#include "nsINameSpaceManager.h" -#include "txError.h" -#include "txAtoms.h" -#include "XFormsFunctions.h" -#include "nsIDOM3Node.h" - -extern nsINameSpaceManager* gTxNameSpaceManager; - -NS_IMPL_ADDREF(nsXFormsXPathEvaluator) -NS_IMPL_RELEASE(nsXFormsXPathEvaluator) -NS_INTERFACE_MAP_BEGIN(nsXFormsXPathEvaluator) - NS_INTERFACE_MAP_ENTRY(nsIXFormsXPathEvaluator) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXFormsXPathEvaluator) -NS_INTERFACE_MAP_END - -nsXFormsXPathEvaluator::nsXFormsXPathEvaluator() -{ -} - -nsXFormsXPathEvaluator::~nsXFormsXPathEvaluator() -{ -} - -NS_IMETHODIMP -nsXFormsXPathEvaluator::CreateExpression(const nsAString & aExpression, - nsIDOMNode *aResolverNode, - nsIDOMNSXPathExpression **aResult) -{ - nsresult rv = NS_OK; - if (!mRecycler) { - nsRefPtr recycler = new txResultRecycler; - NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY); - - rv = recycler->init(); - NS_ENSURE_SUCCESS(rv, rv); - - mRecycler = recycler; - } - - XFormsParseContextImpl pContext(aResolverNode); - - nsAutoPtr expression; - rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext, - getter_Transfers(expression)); - if (NS_FAILED(rv)) { - if (rv == NS_ERROR_DOM_NAMESPACE_ERR) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - return NS_ERROR_DOM_INVALID_EXPRESSION_ERR; - } - - *aResult = new nsXPathExpression(expression, mRecycler); - if (!*aResult) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsXFormsXPathEvaluator::Evaluate(const nsAString & aExpression, - nsIDOMNode *aContextNode, - PRUint32 aPosition, - PRUint32 aSize, - nsIDOMNode *aResolverNode, - PRUint16 aType, - nsISupports *aInResult, - nsISupports **aResult) -{ - // XXX Need to check document of aContextNode if created by - // QI'ing a document. - - nsCOMPtr expression; - nsresult rv = CreateExpression(aExpression, aResolverNode, - getter_AddRefs(expression)); - NS_ENSURE_SUCCESS(rv, rv); - - return expression->EvaluateWithContext(aContextNode, aPosition, aSize, - aType, aInResult, aResult); -} - - -/* - * Implementation of txIParseContext private to nsXFormsXPathEvaluator - * XFormsParseContextImpl bases on a nsIDOMXPathNSResolver - */ - -nsresult nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveNamespacePrefix - (nsIAtom* aPrefix, PRInt32& aID) -{ - aID = kNameSpaceID_Unknown; - - if (!mResolverNode) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - nsAutoString prefix; - if (aPrefix) { - aPrefix->ToString(prefix); - } - - nsVoidableString ns; - nsresult rv; - // begin - taken directly from nsXPathNSResolver::LookupNamespaceURI - if (prefix.EqualsLiteral("xml")) { - ns.AssignLiteral("http://www.w3.org/XML/1998/namespace"); - rv = NS_OK; - } - else { - nsCOMPtr dom3Node = do_QueryInterface(mResolverNode); - NS_ASSERTION(dom3Node, "Need a node to resolve namespaces."); - if( dom3Node ) { - rv = dom3Node->LookupNamespaceURI(prefix, ns); - } - else { - SetDOMStringToNull(ns); - rv = NS_OK; - } - } - // end - taken directly from nsXPathNSResolver::LookupNamespaceURI - NS_ENSURE_SUCCESS(rv, rv); - - if (DOMStringIsNull(ns)) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - if (ns.IsEmpty()) { - aID = kNameSpaceID_None; - return NS_OK; - } - - // get the namespaceID for the URI - return gTxNameSpaceManager->RegisterNameSpace(ns, aID); -} - -nsresult -nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveFunctionCall( - nsIAtom* aName, - PRInt32 aNamespaceID, - FunctionCall*& aFnCall) -{ - if (aNamespaceID == kNameSpaceID_None) { - PRBool isOutOfMem = PR_TRUE; - - if (aName == txXPathAtoms::avg) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::AVG); - } - else if (aName == txXPathAtoms::booleanFromString) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::BOOLEANFROMSTRING); - } - else if (aName == txXPathAtoms::countNonEmpty) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::COUNTNONEMPTY); - } - else if (aName == txXPathAtoms::daysFromDate) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::DAYSFROMDATE); - } - else if (aName == txXPathAtoms::ifFunc) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::IF); - } - else if (aName == txXPathAtoms::index) { - NS_ENSURE_TRUE(mResolverNode, NS_ERROR_FAILURE); - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::INDEX, - mResolverNode); - } - else if (aName == txXPathAtoms::instance) { - NS_ENSURE_TRUE(mResolverNode, NS_ERROR_FAILURE); - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::INSTANCE, - mResolverNode); - } - else if (aName == txXPathAtoms::max) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MAX); - } - else if (aName == txXPathAtoms::min) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MIN); - } - else if (aName == txXPathAtoms::months) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::MONTHS); - } - else if (aName == txXPathAtoms::now) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::NOW); - } - else if (aName == txXPathAtoms::property) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::PROPERTY); - } - else if (aName == txXPathAtoms::seconds) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::SECONDS); - } - else if (aName == txXPathAtoms::secondsFromDateTime) { - aFnCall = new XFormsFunctionCall(XFormsFunctionCall::SECONDSFROMDATETIME); - } - else { - // didn't find functioncall here, aFnCall should be null - isOutOfMem = PR_FALSE; - } - - if (aFnCall) - { - return NS_OK; - } - else if (isOutOfMem) { - NS_ERROR("XPath FunctionLib failed on out-of-memory"); - return NS_ERROR_OUT_OF_MEMORY; - } - } - return NS_ERROR_XPATH_UNKNOWN_FUNCTION; -} - -PRBool nsXFormsXPathEvaluator::XFormsParseContextImpl::caseInsensitiveNameTests() -{ - // This will always be false since this handles XForms, which is XML-based, - // so case sensitive. - return PR_FALSE; -} - -void -nsXFormsXPathEvaluator::XFormsParseContextImpl::SetErrorOffset(PRUint32 aOffset) -{ -} diff --git a/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.h b/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.h deleted file mode 100644 index 04375ef822af..000000000000 --- a/extensions/transformiix/source/xpath/nsXFormsXPathEvaluator.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla XForms support. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Aaron Reed - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXFormsXPathEvaluator_h__ -#define nsXFormsXPathEvaluator_h__ - -#include "nsIXFormsXPathEvaluator.h" -#include "txIXPathContext.h" -#include "nsIXPathEvaluatorInternal.h" -#include "nsIWeakReference.h" -#include "nsAutoPtr.h" -#include "txResultRecycler.h" - - -class nsIDOMDocument; -class nsIDOMXPathExpression; - -/** - * A class for evaluating an XPath expression string - */ -class nsXFormsXPathEvaluator : public nsIXFormsXPathEvaluator -{ -public: - nsXFormsXPathEvaluator(); - virtual ~nsXFormsXPathEvaluator(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIXFormsXPathEvaluator interface - NS_DECL_NSIXFORMXPATHEVALUATOR - -private: - // txIParseContext implementation - class XFormsParseContextImpl : public txIParseContext - { - public: - XFormsParseContextImpl(nsIDOMNode* aResolverNode) - : mResolverNode(aResolverNode), mLastError(NS_OK) - { - } - - ~XFormsParseContextImpl() - { - } - - nsresult getError() - { - return mLastError; - } - - nsresult resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID); - nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID, - FunctionCall*& aFunction); - PRBool caseInsensitiveNameTests(); - void SetErrorOffset(PRUint32 aOffset); - - private: - nsIDOMNode* mResolverNode; - nsresult mLastError; - }; - - nsRefPtr mRecycler; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPath1Scheme.cpp b/extensions/transformiix/source/xpath/nsXPath1Scheme.cpp deleted file mode 100755 index 30f450d0ba99..000000000000 --- a/extensions/transformiix/source/xpath/nsXPath1Scheme.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Heikki Toivonen (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * This file implements the xpath1 XPointer scheme, and the xmlns scheme - * as well but only for xpath1. - * - * http://www.simonstl.com/ietf/draft-stlaurent-xpath-frag-00.html - */ - -#include "nsXPath1Scheme.h" -#include "nsXPathEvaluator.h" -#include "nsXPathException.h" -#include "nsDOMError.h" -#include "nsXPathResult.h" -#include "nsIDOMNode.h" -#include "nsIDOMDocument.h" -#include "nsIDOMXPathNSResolver.h" -#include "nsIDOMRange.h" -#include "nsDOMString.h" -#include "nsIModifyableXPointer.h" -#include "nsAutoPtr.h" -#include "nsString.h" - -#include "nsContentCID.h" -static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); - -/** - * nsXPath1SchemeNSResolver - * - * This will effectively give us xmlns scheme support. - */ -class nsXPath1SchemeNSResolver : public nsIDOMXPathNSResolver -{ -public: - nsXPath1SchemeNSResolver(nsIXPointerSchemeContext *aContext) - : mContext(aContext) - { - } - - virtual ~nsXPath1SchemeNSResolver() - { - } - - NS_DECL_ISUPPORTS - NS_DECL_NSIDOMXPATHNSRESOLVER - -private: - nsCOMPtr mContext; -}; - -NS_IMPL_ISUPPORTS1(nsXPath1SchemeNSResolver, nsIDOMXPathNSResolver) - -//DOMString lookupNamespaceURI(in DOMString prefix); -NS_IMETHODIMP -nsXPath1SchemeNSResolver::LookupNamespaceURI(const nsAString &aPrefix, - nsAString &aURI) -{ - aURI.Truncate(); - - // This method will be called each time the XPath engine encounters - // a prefix. - - // We could cache the extracted prefix + URI pairs in a hash table, - // and do a lookup from that first. But typical XPointers only have - // a few scheme + data pairs (and only some of those will be xmlns - // schemes), and typical XPath expressions only have a few prefixes - // as well, so we'll see if we can manage without... - - if (!mContext) { - return NS_OK; - } - - NS_NAMED_LITERAL_STRING(xmlns, "xmlns"); - - PRUint32 count; - mContext->GetCount(&count); - PRUint32 i; - for (i = 0; i < count; ++i) { - nsAutoString scheme, data; - mContext->GetSchemeData(i, scheme, data); - if (scheme.Equals(xmlns)) { - PRInt32 sep = data.FindChar('='); - if (sep > 0 && aPrefix.Equals(Substring(data, 0, sep))) { - aURI.Assign(Substring(data, sep + 1, data.Length() - sep - 1)); - return NS_OK; - } - } - } - - SetDOMStringToNull(aURI); - - return NS_OK; -} - -// nsXPath1SchemeProcessor -nsXPath1SchemeProcessor::nsXPath1SchemeProcessor() -{ -} - -nsXPath1SchemeProcessor::~nsXPath1SchemeProcessor() -{ -} - -NS_IMPL_ISUPPORTS1(nsXPath1SchemeProcessor, nsIXPointerSchemeProcessor) - -/** - * Evaluate. - * - * @param aDocument The document in which to resolve the XPointer. - * @param aContext The XPointer context in which to process aData. - * @param aData The data in the scheme that needs to be resolved. - * @return The result of the evaluation. - */ -NS_IMETHODIMP -nsXPath1SchemeProcessor::Evaluate(nsIDOMDocument *aDocument, - nsIXPointerSchemeContext *aContext, - const nsAString &aData, - nsIXPointerResult **aResult) -{ - NS_ENSURE_ARG_POINTER(aDocument); - NS_ENSURE_ARG_POINTER(aContext); - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - - // Resolve expression - nsCOMPtr nsresolver(new nsXPath1SchemeNSResolver(aContext)); - if (!nsresolver) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsRefPtr e(new nsXPathEvaluator(nsnull)); - if (!e) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsresult rv = e->Init(); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr result; - rv = e->Evaluate(aData, - aDocument, - nsresolver, - nsIDOMXPathResult::ORDERED_NODE_ITERATOR_TYPE, - nsnull, - getter_AddRefs(result)); - if (NS_FAILED(rv)) { - if ((rv == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) || - (rv == NS_ERROR_DOM_NAMESPACE_ERR) || - (rv == NS_ERROR_DOM_TYPE_ERR)) { - // These errors are benign, change them to NS_OK so that - // we will not terminate the processor. - rv = NS_OK; - } - return rv; - } - - // Create return result - // XXX perf: just store the XPathResult and resolve as XPointerResult on demand - nsCOMPtr xpointerResult( - do_CreateInstance("@mozilla.org/xmlextras/xpointerresult;1", &rv)); - if (NS_FAILED(rv)) { - return rv; - } - - nsCOMPtr privatePointerResult(do_QueryInterface(xpointerResult)); - if (!privatePointerResult) { - return NS_ERROR_FAILURE; - } - - nsCOMPtr node; - rv = result->IterateNext(getter_AddRefs(node)); - if (NS_FAILED(rv)) { - return rv; - } - - // Fill in return result - while (node) { - nsCOMPtr range(do_CreateInstance(kRangeCID, &rv)); - if (NS_FAILED(rv)) - break; - - rv = range->SelectNode(node); - if (NS_FAILED(rv)) - break; - - rv = privatePointerResult->AppendRange(range); - if (NS_FAILED(rv)) - break; - - rv = result->IterateNext(getter_AddRefs(node)); - if (NS_FAILED(rv)) - break; - } - - PRUint32 count; - xpointerResult->GetLength(&count); - if (NS_SUCCEEDED(rv) && (count > 0)) { - *aResult = xpointerResult; - NS_ADDREF(*aResult); - } - - return rv; -} diff --git a/extensions/transformiix/source/xpath/nsXPath1Scheme.h b/extensions/transformiix/source/xpath/nsXPath1Scheme.h deleted file mode 100755 index 4b4308fda270..000000000000 --- a/extensions/transformiix/source/xpath/nsXPath1Scheme.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Heikki Toivonen (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * This file implements the xpath1 XPointer scheme. - */ - -#ifndef __nsXPath1Scheme_h__ -#define __nsXPath1Scheme_h__ - -#include "nsIXPointer.h" - -class nsXPath1SchemeProcessor : public nsIXPointerSchemeProcessor -{ -public: - nsXPath1SchemeProcessor(); - virtual ~nsXPath1SchemeProcessor(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIXPOINTERSCHEMEPROCESSOR -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp b/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp deleted file mode 100644 index 71012a592214..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathEvaluator.h" -#include "nsCOMPtr.h" -#include "nsIAtom.h" -#include "nsIDOMClassInfo.h" -#include "nsXPathException.h" -#include "nsXPathExpression.h" -#include "nsXPathNSResolver.h" -#include "nsXPathResult.h" -#include "nsContentCID.h" -#include "Expr.h" -#include "ExprParser.h" -#include "nsDOMError.h" -#include "txURIUtils.h" -#include "nsIDocument.h" -#include "nsIDOMDocument.h" -#include "nsDOMString.h" -#include "nsINameSpaceManager.h" -#include "txError.h" - -extern nsINameSpaceManager* gTxNameSpaceManager; - -NS_IMPL_AGGREGATED(nsXPathEvaluator) -NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsXPathEvaluator) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator) - NS_INTERFACE_MAP_ENTRY(nsIXPathEvaluatorInternal) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathEvaluator) -NS_INTERFACE_MAP_END - -nsXPathEvaluator::nsXPathEvaluator(nsISupports *aOuter) -{ - NS_INIT_AGGREGATED(aOuter); -} - -nsresult -nsXPathEvaluator::Init() -{ - nsCOMPtr document = do_QueryInterface(fOuter); - - return document ? SetDocument(document) : NS_OK; -} - -NS_IMETHODIMP -nsXPathEvaluator::CreateExpression(const nsAString & aExpression, - nsIDOMXPathNSResolver *aResolver, - nsIDOMXPathExpression **aResult) -{ - nsresult rv = NS_OK; - if (!mRecycler) { - nsRefPtr recycler = new txResultRecycler; - NS_ENSURE_TRUE(recycler, NS_ERROR_OUT_OF_MEMORY); - - rv = recycler->init(); - NS_ENSURE_SUCCESS(rv, rv); - - mRecycler = recycler; - } - - nsCOMPtr doc = do_QueryReferent(mDocument); - ParseContextImpl pContext(aResolver, !doc || doc->IsCaseSensitive()); - nsAutoPtr expression; - rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext, - getter_Transfers(expression)); - if (NS_FAILED(rv)) { - if (rv == NS_ERROR_DOM_NAMESPACE_ERR) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - return NS_ERROR_DOM_INVALID_EXPRESSION_ERR; - } - - *aResult = new nsXPathExpression(expression, mRecycler); - if (!*aResult) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsXPathEvaluator::CreateNSResolver(nsIDOMNode *aNodeResolver, - nsIDOMXPathNSResolver **aResult) -{ - NS_ENSURE_ARG(aNodeResolver); - if (!URIUtils::CanCallerAccess(aNodeResolver)) - return NS_ERROR_DOM_SECURITY_ERR; - - *aResult = new nsXPathNSResolver(aNodeResolver); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsXPathEvaluator::Evaluate(const nsAString & aExpression, - nsIDOMNode *aContextNode, - nsIDOMXPathNSResolver *aResolver, - PRUint16 aType, - nsISupports *aInResult, - nsISupports **aResult) -{ - // XXX Need to check document of aContextNode if created by - // QI'ing a document. - - nsCOMPtr expression; - nsresult rv = CreateExpression(aExpression, aResolver, - getter_AddRefs(expression)); - NS_ENSURE_SUCCESS(rv, rv); - - return expression->Evaluate(aContextNode, aType, aInResult, aResult); -} - - -NS_IMETHODIMP -nsXPathEvaluator::SetDocument(nsIDOMDocument* aDocument) -{ - mDocument = do_GetWeakReference(aDocument); - return NS_OK; -} - -/* - * Implementation of txIParseContext private to nsXPathEvaluator - * ParseContextImpl bases on a nsIDOMXPathNSResolver - */ - -nsresult nsXPathEvaluator::ParseContextImpl::resolveNamespacePrefix - (nsIAtom* aPrefix, PRInt32& aID) -{ - aID = kNameSpaceID_Unknown; - - if (!mResolver) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - nsAutoString prefix; - if (aPrefix) { - aPrefix->ToString(prefix); - } - - nsVoidableString ns; - nsresult rv = mResolver->LookupNamespaceURI(prefix, ns); - NS_ENSURE_SUCCESS(rv, rv); - - if (DOMStringIsNull(ns)) { - return NS_ERROR_DOM_NAMESPACE_ERR; - } - - if (ns.IsEmpty()) { - aID = kNameSpaceID_None; - - return NS_OK; - } - - // get the namespaceID for the URI - return gTxNameSpaceManager->RegisterNameSpace(ns, aID); -} - -nsresult -nsXPathEvaluator::ParseContextImpl::resolveFunctionCall(nsIAtom* aName, - PRInt32 aID, - FunctionCall*& aFn) -{ - return NS_ERROR_XPATH_UNKNOWN_FUNCTION; -} - -PRBool nsXPathEvaluator::ParseContextImpl::caseInsensitiveNameTests() -{ - return !mIsCaseSensitive; -} - -void -nsXPathEvaluator::ParseContextImpl::SetErrorOffset(PRUint32 aOffset) -{ -} diff --git a/extensions/transformiix/source/xpath/nsXPathEvaluator.h b/extensions/transformiix/source/xpath/nsXPathEvaluator.h deleted file mode 100644 index 9655ae39ddef..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathEvaluator.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathEvaluator_h__ -#define nsXPathEvaluator_h__ - -#include "nsIDOMXPathEvaluator.h" -#include "txIXPathContext.h" -#include "nsIXPathEvaluatorInternal.h" -#include "nsIWeakReference.h" -#include "nsAutoPtr.h" -#include "txResultRecycler.h" -#include "nsAgg.h" - -/** - * A class for evaluating an XPath expression string - */ -class nsXPathEvaluator : public nsIDOMXPathEvaluator, - public nsIXPathEvaluatorInternal -{ -public: - nsXPathEvaluator(nsISupports *aOuter); - virtual ~nsXPathEvaluator() - { - } - - nsresult Init(); - - // nsISupports interface (support aggregation) - NS_DECL_AGGREGATED - - // nsIDOMXPathEvaluator interface - NS_DECL_NSIDOMXPATHEVALUATOR - - // nsIXPathEvaluatorInternal interface - NS_IMETHOD SetDocument(nsIDOMDocument* aDocument); - -private: - // txIParseContext implementation - class ParseContextImpl : public txIParseContext - { - public: - ParseContextImpl(nsIDOMXPathNSResolver* aResolver, - PRBool aIsCaseSensitive) - : mResolver(aResolver), mLastError(NS_OK), - mIsCaseSensitive(aIsCaseSensitive) - { - } - - ~ParseContextImpl() - { - } - - nsresult getError() - { - return mLastError; - } - - nsresult resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID); - nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID, - FunctionCall*& aFunction); - PRBool caseInsensitiveNameTests(); - void SetErrorOffset(PRUint32 aOffset); - - private: - nsIDOMXPathNSResolver* mResolver; - nsresult mLastError; - PRBool mIsCaseSensitive; - }; - - nsWeakPtr mDocument; - nsRefPtr mRecycler; -}; - -/* d0a75e02-b5e7-11d5-a7f2-df109fb8a1fc */ -#define TRANSFORMIIX_XPATH_EVALUATOR_CID \ -{ 0xd0a75e02, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } } - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathException.cpp b/extensions/transformiix/source/xpath/nsXPathException.cpp deleted file mode 100644 index e7a732ff2e10..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathException.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathException.h" -#include "nsCRT.h" -#include "nsIDOMClassInfo.h" -#include "nsIBaseDOMException.h" -#include "prprf.h" - -static const char kInvalidExpressionErrName[] = "NS_ERROR_DOM_INVALID_EXPRESSION_ERR"; -static const char kInvalidExpressionErrMessage[] = NS_ERROR_DOM_INVALID_EXPRESSION_MSG; -static const char kTypeErrName[] = "NS_ERROR_DOM_TYPE_ERR"; -static const char kTypeErrMessage[] = NS_ERROR_DOM_TYPE_MSG; - -static void -TXResultToNameAndMessage(nsresult aNSResult, - const char** aName, - const char** aMessage) -{ - if (aNSResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) { - *aName = kInvalidExpressionErrName; - *aMessage = kInvalidExpressionErrMessage; - } - else if (aNSResult == NS_ERROR_DOM_TYPE_ERR) { - *aName = kTypeErrName; - *aMessage = kTypeErrMessage; - } - else { - NS_WARNING("Huh, someone is throwing non-XPath DOM errors using the XPath DOM module!"); - *aName = nsnull; - *aMessage = nsnull; - } - - return; -} - - -IMPL_DOM_EXCEPTION_HEAD(nsXPathException, nsIDOMXPathException) - NS_DECL_NSIDOMXPATHEXCEPTION -IMPL_DOM_EXCEPTION_TAIL(nsXPathException, nsIDOMXPathException, XPathException, - NS_ERROR_MODULE_DOM_XPATH, TXResultToNameAndMessage) - -NS_IMETHODIMP -nsXPathException::GetCode(PRUint16* aCode) -{ - NS_ENSURE_ARG_POINTER(aCode); - nsresult result; - mBase->GetResult(&result); - *aCode = NS_ERROR_GET_CODE(result); - - return NS_OK; -} - - -NS_IMPL_ISUPPORTS1(nsXPathExceptionProvider, nsIExceptionProvider) - -nsXPathExceptionProvider::nsXPathExceptionProvider() -{ -} - -nsXPathExceptionProvider::~nsXPathExceptionProvider() -{ -} - -NS_IMETHODIMP -nsXPathExceptionProvider::GetException(nsresult aNSResult, - nsIException *aDefaultException, - nsIException **aException) -{ - NS_ENSURE_ARG_POINTER(aException); - - NS_NewXPathException(aNSResult, aDefaultException, aException); - NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; -} diff --git a/extensions/transformiix/source/xpath/nsXPathException.h b/extensions/transformiix/source/xpath/nsXPathException.h deleted file mode 100644 index 48df489e00e2..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathException.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathException_h__ -#define nsXPathException_h__ - -#include "nsCOMPtr.h" -#include "nsIDOMXPathException.h" -#include "nsIException.h" -#include "nsIExceptionService.h" - -/* DOM error codes from http://www.w3.org/TR/DOM-Level-3-XPath */ - -#define NS_ERROR_DOM_INVALID_EXPRESSION_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_XPATH, 51) -#define NS_ERROR_DOM_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_XPATH, 52) - -#define NS_ERROR_DOM_INVALID_EXPRESSION_MSG "The expression is not a legal expression." -#define NS_ERROR_DOM_TYPE_MSG "The expression cannot be converted to return the specified type." - -class nsXPathExceptionProvider : public nsIExceptionProvider -{ -public: - nsXPathExceptionProvider(); - virtual ~nsXPathExceptionProvider(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIExceptionProvider interface - NS_DECL_NSIEXCEPTIONPROVIDER -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathExpression.cpp b/extensions/transformiix/source/xpath/nsXPathExpression.cpp deleted file mode 100644 index 16454e6f4e93..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathExpression.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathExpression.h" -#include "Expr.h" -#include "ExprResult.h" -#include "nsDOMError.h" -#include "nsIDOMCharacterData.h" -#include "nsIDOMClassInfo.h" -#include "nsIDOMDocument.h" -#include "nsIDOMXPathNamespace.h" -#include "nsXPathResult.h" -#include "nsDOMError.h" -#include "txURIUtils.h" -#include "txXPathTreeWalker.h" - -NS_IMPL_ADDREF(nsXPathExpression) -NS_IMPL_RELEASE(nsXPathExpression) -NS_INTERFACE_MAP_BEGIN(nsXPathExpression) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathExpression) - NS_INTERFACE_MAP_ENTRY(nsIDOMNSXPathExpression) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathExpression) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathExpression) -NS_INTERFACE_MAP_END - -nsXPathExpression::nsXPathExpression(nsAutoPtr& aExpression, - txResultRecycler* aRecycler) - : mExpression(aExpression), - mRecycler(aRecycler) -{ -} - -nsXPathExpression::~nsXPathExpression() -{ -} - -NS_IMETHODIMP -nsXPathExpression::Evaluate(nsIDOMNode *aContextNode, - PRUint16 aType, - nsISupports *aInResult, - nsISupports **aResult) -{ - return EvaluateWithContext(aContextNode, 1, 1, aType, aInResult, aResult); -} - -NS_IMETHODIMP -nsXPathExpression::EvaluateWithContext(nsIDOMNode *aContextNode, - PRUint32 aContextPosition, - PRUint32 aContextSize, - PRUint16 aType, - nsISupports *aInResult, - nsISupports **aResult) -{ - NS_ENSURE_ARG(aContextNode); - - if (aContextPosition > aContextSize) - return NS_ERROR_FAILURE; - - if (!URIUtils::CanCallerAccess(aContextNode)) - return NS_ERROR_DOM_SECURITY_ERR; - - nsresult rv; - PRUint16 nodeType; - rv = aContextNode->GetNodeType(&nodeType); - NS_ENSURE_SUCCESS(rv, rv); - - if (nodeType == nsIDOMNode::TEXT_NODE || - nodeType == nsIDOMNode::CDATA_SECTION_NODE) { - nsCOMPtr textNode = do_QueryInterface(aContextNode); - NS_ENSURE_TRUE(textNode, NS_ERROR_FAILURE); - - if (textNode) { - PRUint32 textLength; - textNode->GetLength(&textLength); - if (textLength == 0) - return NS_ERROR_DOM_NOT_SUPPORTED_ERR; - } - - // XXX Need to get logical XPath text node for CDATASection - // and Text nodes. - } - else if (nodeType != nsIDOMNode::DOCUMENT_NODE && - nodeType != nsIDOMNode::ELEMENT_NODE && - nodeType != nsIDOMNode::ATTRIBUTE_NODE && - nodeType != nsIDOMNode::COMMENT_NODE && - nodeType != nsIDOMNode::PROCESSING_INSTRUCTION_NODE && - nodeType != nsIDOMXPathNamespace::XPATH_NAMESPACE_NODE) { - return NS_ERROR_DOM_NOT_SUPPORTED_ERR; - } - - NS_ENSURE_ARG(aResult); - *aResult = nsnull; - - nsAutoPtr contextNode(txXPathNativeNode::createXPathNode(aContextNode)); - if (!contextNode) { - return NS_ERROR_OUT_OF_MEMORY; - } - - EvalContextImpl eContext(*contextNode, aContextPosition, aContextSize, - mRecycler); - nsRefPtr exprResult; - rv = mExpression->evaluate(&eContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - PRUint16 resultType = aType; - if (aType == nsIDOMXPathResult::ANY_TYPE) { - short exprResultType = exprResult->getResultType(); - switch (exprResultType) { - case txAExprResult::NUMBER: - resultType = nsIDOMXPathResult::NUMBER_TYPE; - break; - case txAExprResult::STRING: - resultType = nsIDOMXPathResult::STRING_TYPE; - break; - case txAExprResult::BOOLEAN: - resultType = nsIDOMXPathResult::BOOLEAN_TYPE; - break; - case txAExprResult::NODESET: - resultType = nsIDOMXPathResult::UNORDERED_NODE_ITERATOR_TYPE; - break; - case txAExprResult::RESULT_TREE_FRAGMENT: - NS_ERROR("Can't return a tree fragment!"); - return NS_ERROR_FAILURE; - } - } - - // We need a result object and it must be our implementation. - nsCOMPtr xpathResult = do_QueryInterface(aInResult); - if (!xpathResult) { - // Either no aInResult or not one of ours. - xpathResult = new nsXPathResult(); - NS_ENSURE_TRUE(xpathResult, NS_ERROR_OUT_OF_MEMORY); - } - rv = xpathResult->SetExprResult(exprResult, resultType); - NS_ENSURE_SUCCESS(rv, rv); - - return CallQueryInterface(xpathResult, aResult); -} - -/* - * Implementation of the txIEvalContext private to nsXPathExpression - * EvalContextImpl bases on only one context node and no variables - */ - -nsresult -nsXPathExpression::EvalContextImpl::getVariable(PRInt32 aNamespace, - nsIAtom* aLName, - txAExprResult*& aResult) -{ - aResult = 0; - return NS_ERROR_INVALID_ARG; -} - -MBool nsXPathExpression::EvalContextImpl::isStripSpaceAllowed(const txXPathNode& aNode) -{ - return MB_FALSE; -} - -void* nsXPathExpression::EvalContextImpl::getPrivateContext() -{ - // we don't have a private context here. - return nsnull; -} - -txResultRecycler* nsXPathExpression::EvalContextImpl::recycler() -{ - return mRecycler; -} - -void nsXPathExpression::EvalContextImpl::receiveError(const nsAString& aMsg, - nsresult aRes) -{ - mLastError = aRes; - // forward aMsg to console service? -} - -const txXPathNode& nsXPathExpression::EvalContextImpl::getContextNode() -{ - return mContextNode; -} - -PRUint32 nsXPathExpression::EvalContextImpl::size() -{ - return mContextSize; -} - -PRUint32 nsXPathExpression::EvalContextImpl::position() -{ - return mContextPosition; -} diff --git a/extensions/transformiix/source/xpath/nsXPathExpression.h b/extensions/transformiix/source/xpath/nsXPathExpression.h deleted file mode 100644 index 8284b7d97598..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathExpression.h +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathExpression_h__ -#define nsXPathExpression_h__ - -#include "nsIDOMXPathExpression.h" -#include "nsIDOMNSXPathExpression.h" -#include "txIXPathContext.h" -#include "txResultRecycler.h" -#include "nsAutoPtr.h" - -class Expr; -class txXPathNode; - -/** - * A class for evaluating an XPath expression string - */ -class nsXPathExpression : public nsIDOMXPathExpression, - public nsIDOMNSXPathExpression -{ -public: - nsXPathExpression(nsAutoPtr& aExpression, - txResultRecycler* aRecycler); - virtual ~nsXPathExpression(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIDOMXPathExpression interface - NS_DECL_NSIDOMXPATHEXPRESSION - - // nsIDOMNSXPathExpression interface - NS_DECL_NSIDOMNSXPATHEXPRESSION - -private: - nsAutoPtr mExpression; - nsRefPtr mRecycler; - - class EvalContextImpl : public txIEvalContext - { - public: - EvalContextImpl(const txXPathNode& aContextNode, - PRUint32 aContextPosition, PRUint32 aContextSize, - txResultRecycler* aRecycler) - : mContextNode(aContextNode), - mContextPosition(aContextPosition), - mContextSize(aContextSize), - mLastError(NS_OK), - mRecycler(aRecycler) - { - } - - ~EvalContextImpl() - { - } - - nsresult getError() - { - return mLastError; - } - - TX_DECL_EVAL_CONTEXT; - - private: - const txXPathNode& mContextNode; - PRUint32 mContextPosition; - PRUint32 mContextSize; - nsresult mLastError; - nsRefPtr mRecycler; - }; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathNSResolver.cpp b/extensions/transformiix/source/xpath/nsXPathNSResolver.cpp deleted file mode 100644 index a38f583e0a4f..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathNSResolver.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathNSResolver.h" -#include "nsIDOMClassInfo.h" -#include "nsDOMString.h" - -NS_IMPL_ADDREF(nsXPathNSResolver) -NS_IMPL_RELEASE(nsXPathNSResolver) -NS_INTERFACE_MAP_BEGIN(nsXPathNSResolver) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathNSResolver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathNSResolver) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathNSResolver) -NS_INTERFACE_MAP_END - -nsXPathNSResolver::nsXPathNSResolver(nsIDOMNode* aNode) -{ - mNode = do_QueryInterface(aNode); - NS_ASSERTION(mNode, "Need a node to resolve namespaces."); -} - -nsXPathNSResolver::~nsXPathNSResolver() -{ -} - -NS_IMETHODIMP -nsXPathNSResolver::LookupNamespaceURI(const nsAString & aPrefix, - nsAString & aResult) -{ - if (aPrefix.EqualsLiteral("xml")) { - aResult.AssignLiteral("http://www.w3.org/XML/1998/namespace"); - - return NS_OK; - } - - if (!mNode) { - SetDOMStringToNull(aResult); - - return NS_OK; - } - - return mNode->LookupNamespaceURI(aPrefix, aResult); -} diff --git a/extensions/transformiix/source/xpath/nsXPathNSResolver.h b/extensions/transformiix/source/xpath/nsXPathNSResolver.h deleted file mode 100644 index 5453fb562246..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathNSResolver.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathNSResolver_h__ -#define nsXPathNSResolver_h__ - -#include "nsIDOMXPathNSResolver.h" -#include "nsIDOMNode.h" -#include "nsIDOM3Node.h" -#include "nsCOMPtr.h" - -/** - * A class for evaluating an XPath expression string - */ -class nsXPathNSResolver : public nsIDOMXPathNSResolver -{ -public: - nsXPathNSResolver(nsIDOMNode* aNode); - virtual ~nsXPathNSResolver(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIDOMXPathNSResolver interface - NS_DECL_NSIDOMXPATHNSRESOLVER - -private: - nsCOMPtr mNode; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathNamespace.cpp b/extensions/transformiix/source/xpath/nsXPathNamespace.cpp deleted file mode 100644 index 54af8e3a5f60..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathNamespace.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathNamespace.h" -#include "nsIDOMClassInfo.h" - -NS_IMPL_ADDREF(nsXPathNamespace) -NS_IMPL_RELEASE(nsXPathNamespace) -NS_INTERFACE_MAP_BEGIN(nsXPathNamespace) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathNamespace) - NS_INTERFACE_MAP_ENTRY(nsIDOMNode) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathNamespace) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathNamespace) -NS_INTERFACE_MAP_END - -nsXPathNamespace::nsXPathNamespace() -{ -} - -nsXPathNamespace::~nsXPathNamespace() -{ -} - -/* readonly attribute DOMString nodeName; */ -NS_IMETHODIMP nsXPathNamespace::GetNodeName(nsAString & aNodeName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute DOMString nodeValue; */ -NS_IMETHODIMP nsXPathNamespace::GetNodeValue(nsAString & aNodeValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP nsXPathNamespace::SetNodeValue(const nsAString & aNodeValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute unsigned short nodeType; */ -NS_IMETHODIMP nsXPathNamespace::GetNodeType(PRUint16 *aNodeType) -{ - *aNodeType = XPATH_NAMESPACE_NODE; - return NS_OK; -} - -/* readonly attribute nsIDOMNode parentNode; */ -NS_IMETHODIMP nsXPathNamespace::GetParentNode(nsIDOMNode * *aParentNode) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNodeList childNodes; */ -NS_IMETHODIMP nsXPathNamespace::GetChildNodes(nsIDOMNodeList * *aChildNodes) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNode firstChild; */ -NS_IMETHODIMP nsXPathNamespace::GetFirstChild(nsIDOMNode * *aFirstChild) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNode lastChild; */ -NS_IMETHODIMP nsXPathNamespace::GetLastChild(nsIDOMNode * *aLastChild) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNode previousSibling; */ -NS_IMETHODIMP nsXPathNamespace::GetPreviousSibling(nsIDOMNode * *aPreviousSibling) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNode nextSibling; */ -NS_IMETHODIMP nsXPathNamespace::GetNextSibling(nsIDOMNode * *aNextSibling) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMNamedNodeMap attributes; */ -NS_IMETHODIMP nsXPathNamespace::GetAttributes(nsIDOMNamedNodeMap * *aAttributes) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMDocument ownerDocument; */ -NS_IMETHODIMP nsXPathNamespace::GetOwnerDocument(nsIDOMDocument * *aOwnerDocument) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* nsIDOMNode insertBefore (in nsIDOMNode newChild, in nsIDOMNode refChild) raises (DOMException); */ -NS_IMETHODIMP nsXPathNamespace::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild, nsIDOMNode **aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* nsIDOMNode replaceChild (in nsIDOMNode newChild, in nsIDOMNode oldChild) raises (DOMException); */ -NS_IMETHODIMP nsXPathNamespace::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild, nsIDOMNode **aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* nsIDOMNode removeChild (in nsIDOMNode oldChild) raises (DOMException); */ -NS_IMETHODIMP nsXPathNamespace::RemoveChild(nsIDOMNode *oldChild, nsIDOMNode **aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* nsIDOMNode appendChild (in nsIDOMNode newChild) raises (DOMException); */ -NS_IMETHODIMP nsXPathNamespace::AppendChild(nsIDOMNode *newChild, nsIDOMNode **aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean hasChildNodes (); */ -NS_IMETHODIMP nsXPathNamespace::HasChildNodes(PRBool *aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* nsIDOMNode cloneNode (in boolean deep); */ -NS_IMETHODIMP nsXPathNamespace::CloneNode(PRBool deep, nsIDOMNode **aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void normalize (); */ -NS_IMETHODIMP nsXPathNamespace::Normalize() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean isSupported (in DOMString feature, in DOMString version); */ -NS_IMETHODIMP nsXPathNamespace::IsSupported(const nsAString & feature, const nsAString & version, PRBool *aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute DOMString namespaceURI; */ -NS_IMETHODIMP nsXPathNamespace::GetNamespaceURI(nsAString & aNamespaceURI) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute DOMString prefix; */ -NS_IMETHODIMP nsXPathNamespace::GetPrefix(nsAString & aPrefix) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP nsXPathNamespace::SetPrefix(const nsAString & aPrefix) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute DOMString localName; */ -NS_IMETHODIMP nsXPathNamespace::GetLocalName(nsAString & aLocalName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean hasAttributes (); */ -NS_IMETHODIMP nsXPathNamespace::HasAttributes(PRBool *aResult) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute nsIDOMElement ownerElement; */ -NS_IMETHODIMP nsXPathNamespace::GetOwnerElement(nsIDOMElement * *aOwnerElement) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/extensions/transformiix/source/xpath/nsXPathNamespace.h b/extensions/transformiix/source/xpath/nsXPathNamespace.h deleted file mode 100644 index 5e0052b759fb..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathNamespace.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathNamespace_h__ -#define nsXPathNamespace_h__ - -#include "nsIDOMXPathNamespace.h" - -/* d0a75e07-b5e7-11d5-a7f2-df109fb8a1fc */ -#define TRANSFORMIIX_XPATH_NAMESPACE_CID \ -{ 0xd0a75e07, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } } - -#define TRANSFORMIIX_XPATH_NAMESPACE_CONTRACTID \ -"@mozilla.org/transformiix/xpath-namespace;1" - -/** - * A class for representing XPath namespace nodes in the DOM. - */ -class nsXPathNamespace : public nsIDOMXPathNamespace -{ -public: - nsXPathNamespace(); - virtual ~nsXPathNamespace(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIDOMNode interface - NS_DECL_NSIDOMNODE - - // nsIDOMXPathNamespace interface - NS_DECL_NSIDOMXPATHNAMESPACE -}; - -#endif diff --git a/extensions/transformiix/source/xpath/nsXPathResult.cpp b/extensions/transformiix/source/xpath/nsXPathResult.cpp deleted file mode 100644 index 2d3971c8c2be..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathResult.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXPathResult.h" -#include "ExprResult.h" -#include "txNodeSet.h" -#include "nsDOMError.h" -#include "nsIContent.h" -#include "nsIDOMClassInfo.h" -#include "nsIDOMNode.h" -#include "nsXPathException.h" -#include "nsIDOMDocument.h" -#include "nsDOMString.h" - -nsXPathResult::nsXPathResult() : mDocument(nsnull), - mCurrentPos(0), - mResultType(ANY_TYPE), - mInvalidIteratorState(PR_TRUE) -{ -} - -nsXPathResult::~nsXPathResult() -{ - if (mDocument) { - mDocument->RemoveObserver(this); - } -} - -NS_IMPL_ADDREF(nsXPathResult) -NS_IMPL_RELEASE(nsXPathResult) -NS_INTERFACE_MAP_BEGIN(nsXPathResult) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathResult) - NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) - NS_INTERFACE_MAP_ENTRY(nsIXPathResult) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXPathResult) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathResult) -NS_INTERFACE_MAP_END - -NS_IMETHODIMP -nsXPathResult::GetResultType(PRUint16 *aResultType) -{ - *aResultType = mResultType; - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetNumberValue(double *aNumberValue) -{ - if (mResultType != NUMBER_TYPE) { - return NS_ERROR_DOM_TYPE_ERR; - } - - *aNumberValue = mResult.get()->numberValue(); - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetStringValue(nsAString &aStringValue) -{ - if (mResultType != STRING_TYPE) { - return NS_ERROR_DOM_TYPE_ERR; - } - - mResult.get()->stringValue(aStringValue); - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetBooleanValue(PRBool *aBooleanValue) -{ - if (mResultType != BOOLEAN_TYPE) { - return NS_ERROR_DOM_TYPE_ERR; - } - - *aBooleanValue = mResult.get()->booleanValue(); - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetSingleNodeValue(nsIDOMNode **aSingleNodeValue) -{ - if (!isNode()) { - return NS_ERROR_DOM_TYPE_ERR; - } - - txNodeSet *nodeSet = NS_STATIC_CAST(txNodeSet*, mResult.get()); - if (nodeSet->size() > 0) { - return txXPathNativeNode::getNode(nodeSet->get(0), aSingleNodeValue); - } - - *aSingleNodeValue = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetInvalidIteratorState(PRBool *aInvalidIteratorState) -{ - *aInvalidIteratorState = isIterator() && mInvalidIteratorState; - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::GetSnapshotLength(PRUint32 *aSnapshotLength) -{ - if (!isSnapshot()) { - return NS_ERROR_DOM_TYPE_ERR; - } - - txNodeSet *nodeSet = NS_STATIC_CAST(txNodeSet*, mResult.get()); - *aSnapshotLength = (PRUint32)nodeSet->size(); - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::IterateNext(nsIDOMNode **aResult) -{ - if (!isIterator()) { - return NS_ERROR_DOM_TYPE_ERR; - } - - if (mDocument) { - mDocument->FlushPendingNotifications(Flush_Content); - } - - if (mInvalidIteratorState) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - txNodeSet *nodeSet = NS_STATIC_CAST(txNodeSet*, mResult.get()); - if (mCurrentPos < (PRUint32)nodeSet->size()) { - return txXPathNativeNode::getNode(nodeSet->get(mCurrentPos++), - aResult); - } - - *aResult = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsXPathResult::SnapshotItem(PRUint32 aIndex, nsIDOMNode **aResult) -{ - if (!isSnapshot()) { - return NS_ERROR_DOM_TYPE_ERR; - } - - txNodeSet *nodeSet = NS_STATIC_CAST(txNodeSet*, mResult.get()); - if (aIndex < (PRUint32)nodeSet->size()) { - return txXPathNativeNode::getNode(nodeSet->get(aIndex), aResult); - } - - *aResult = nsnull; - - return NS_OK; -} - -NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(nsXPathResult) -NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsXPathResult) -NS_IMPL_NSIDOCUMENTOBSERVER_REFLOW_STUB(nsXPathResult) -NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(nsXPathResult) -NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(nsXPathResult) - -void -nsXPathResult::CharacterDataChanged(nsIDocument* aDocument, - nsIContent *aContent, - PRBool aAppend) -{ - Invalidate(); -} - -void -nsXPathResult::AttributeChanged(nsIDocument* aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType) -{ - Invalidate(); -} - -void -nsXPathResult::ContentAppended(nsIDocument* aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ - Invalidate(); -} - -void -nsXPathResult::ContentInserted(nsIDocument* aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - Invalidate(); -} - -void -nsXPathResult::ContentRemoved(nsIDocument* aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - Invalidate(); -} - -nsresult -nsXPathResult::SetExprResult(txAExprResult* aExprResult, PRUint16 aResultType) -{ - if (mDocument) { - mDocument->RemoveObserver(this); - mDocument = nsnull; - } - - mResultType = aResultType; - mResult.set(aExprResult); - - if (!isIterator()) { - return NS_OK; - } - - mInvalidIteratorState = PR_FALSE; - - txNodeSet* nodeSet = NS_STATIC_CAST(txNodeSet*, aExprResult); - nsCOMPtr node; - if (nodeSet->size() > 0) { - nsresult rv = txXPathNativeNode::getNode(nodeSet->get(0), - getter_AddRefs(node)); - NS_ENSURE_SUCCESS(rv, rv); - - // If we support the document() function in DOM-XPath we need to - // observe all documents that we have resultnodes in. - nsCOMPtr document; - node->GetOwnerDocument(getter_AddRefs(document)); - if (document) { - mDocument = do_QueryInterface(document); - } - else { - mDocument = do_QueryInterface(node); - } - - NS_ASSERTION(mDocument, "We need a document!"); - if (mDocument) { - mDocument->AddObserver(this); - } - } - - return NS_OK; -} - -void -nsXPathResult::Invalidate() -{ - if (mDocument) { - mDocument->RemoveObserver(this); - mDocument = nsnull; - } - mInvalidIteratorState = PR_TRUE; -} - -nsresult -nsXPathResult::GetExprResult(txAExprResult** aExprResult) -{ - if (isIterator() && mInvalidIteratorState) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - *aExprResult = mResult.get(); - if (!*aExprResult) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - NS_ADDREF(*aExprResult); - - return NS_OK; -} - -nsresult -nsXPathResult::Clone(nsIXPathResult **aResult) -{ - *aResult = nsnull; - - if (isIterator() && mInvalidIteratorState) { - return NS_ERROR_DOM_INVALID_STATE_ERR; - } - - nsCOMPtr result = new nsXPathResult(); - if (!result) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsresult rv = result->SetExprResult(mResult.get(), mResultType); - NS_ENSURE_SUCCESS(rv, rv); - - result.swap(*aResult); - - return NS_OK; -} - -void -txResultHolder::set(txAExprResult *aResult) -{ - releaseNodeSet(); - - // XXX This will keep the recycler alive, should we clear it? - mResult = aResult; - - if (mResult && mResult->getResultType() == txAExprResult::NODESET) { - txNodeSet *nodeSet = - NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, mResult)); - PRInt32 i, count = nodeSet->size(); - for (i = 0; i < count; ++i) { - txXPathNativeNode::addRef(nodeSet->get(i)); - } - } -} - -void -txResultHolder::releaseNodeSet() -{ - if (mResult && mResult->getResultType() == txAExprResult::NODESET) { - txNodeSet *nodeSet = - NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, mResult)); - PRInt32 i, count = nodeSet->size(); - for (i = 0; i < count; ++i) { - txXPathNativeNode::release(nodeSet->get(i)); - } - } -} diff --git a/extensions/transformiix/source/xpath/nsXPathResult.h b/extensions/transformiix/source/xpath/nsXPathResult.h deleted file mode 100644 index ca58e6566a24..000000000000 --- a/extensions/transformiix/source/xpath/nsXPathResult.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXPathResult_h__ -#define nsXPathResult_h__ - -#include "ExprResult.h" -#include "nsIDOMXPathResult.h" -#include "nsIDocument.h" -#include "nsIDocumentObserver.h" -#include "nsCOMPtr.h" -#include "nsCOMArray.h" - -// {15b9b301-2012-11d6-a7f2-e6d0a678995c} -#define NS_IXPATHRESULT_IID \ -{ 0x15b9b301, 0x2012, 0x11d6, {0xa7, 0xf2, 0xe6, 0xd0, 0xa6, 0x78, 0x99, 0x5c }}; - -class nsIXPathResult : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPATHRESULT_IID) - virtual nsresult SetExprResult(txAExprResult *aExprResult, - PRUint16 aResultType) = 0; - virtual nsresult GetExprResult(txAExprResult **aExprResult) = 0; - virtual nsresult Clone(nsIXPathResult **aResult) = 0; -}; - -/** - * Helper class to keep Mozilla node objects alive as long as the nodeset is - * alive. - */ -class txResultHolder -{ -public: - ~txResultHolder() - { - releaseNodeSet(); - } - - txAExprResult *get() - { - return mResult; - } - void set(txAExprResult *aResult); - -private: - void releaseNodeSet(); - - nsRefPtr mResult; -}; - -/** - * A class for evaluating an XPath expression string - */ -class nsXPathResult : public nsIDOMXPathResult, - public nsIDocumentObserver, - public nsIXPathResult -{ -public: - nsXPathResult(); - virtual ~nsXPathResult(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIDOMXPathResult interface - NS_DECL_NSIDOMXPATHRESULT - - // nsIDocumentObserver interface - NS_DECL_NSIDOCUMENTOBSERVER - - // nsIXPathResult interface - nsresult SetExprResult(txAExprResult *aExprResult, PRUint16 aResultType); - nsresult GetExprResult(txAExprResult **aExprResult); - nsresult Clone(nsIXPathResult **aResult); - -private: - PRBool isSnapshot() const - { - return mResultType == UNORDERED_NODE_SNAPSHOT_TYPE || - mResultType == ORDERED_NODE_SNAPSHOT_TYPE; - } - PRBool isIterator() const - { - return mResultType == UNORDERED_NODE_ITERATOR_TYPE || - mResultType == ORDERED_NODE_ITERATOR_TYPE; - } - PRBool isNode() const - { - return mResultType == FIRST_ORDERED_NODE_TYPE || - mResultType == ANY_UNORDERED_NODE_TYPE; - } - - void Invalidate(); - - txResultHolder mResult; - nsCOMPtr mDocument; - PRUint32 mCurrentPos; - PRUint16 mResultType; - PRPackedBool mInvalidIteratorState; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/txErrorExpr.cpp b/extensions/transformiix/source/xpath/txErrorExpr.cpp deleted file mode 100755 index b506a578dd60..000000000000 --- a/extensions/transformiix/source/xpath/txErrorExpr.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2005 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txError.h" -#include "Expr.h" -#include "nsString.h" -#include "txIXPathContext.h" - -nsresult -txErrorExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - nsAutoString err(NS_LITERAL_STRING("Invalid expression evaluated")); -#ifdef TX_TO_STRING - err.AppendLiteral(": "); - toString(err); -#endif - aContext->receiveError(err, - NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED); - - return NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED; -} - -#ifdef TX_TO_STRING -void -txErrorExpr::toString(nsAString& aStr) -{ - aStr.Append(mStr); -} -#endif diff --git a/extensions/transformiix/source/xpath/txForwardContext.cpp b/extensions/transformiix/source/xpath/txForwardContext.cpp deleted file mode 100644 index 9b2d94f75735..000000000000 --- a/extensions/transformiix/source/xpath/txForwardContext.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txForwardContext.h" -#include "txNodeSet.h" - -const txXPathNode& txForwardContext::getContextNode() -{ - return mContextNode; -} - -PRUint32 txForwardContext::size() -{ - return (PRUint32)mContextSet->size(); -} - -PRUint32 txForwardContext::position() -{ - PRInt32 pos = mContextSet->indexOf(mContextNode); - NS_ASSERTION(pos >= 0, "Context is not member of context node list."); - return (PRUint32)(pos + 1); -} - -nsresult txForwardContext::getVariable(PRInt32 aNamespace, nsIAtom* aLName, - txAExprResult*& aResult) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getVariable(aNamespace, aLName, aResult); -} - -MBool txForwardContext::isStripSpaceAllowed(const txXPathNode& aNode) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->isStripSpaceAllowed(aNode); -} - -void* txForwardContext::getPrivateContext() -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getPrivateContext(); -} - -txResultRecycler* txForwardContext::recycler() -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->recycler(); -} - -void txForwardContext::receiveError(const nsAString& aMsg, nsresult aRes) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); -#ifdef DEBUG - nsAutoString error(NS_LITERAL_STRING("forwarded error: ")); - error.Append(aMsg); - mInner->receiveError(error, aRes); -#else - mInner->receiveError(aMsg, aRes); -#endif -} diff --git a/extensions/transformiix/source/xpath/txForwardContext.h b/extensions/transformiix/source/xpath/txForwardContext.h deleted file mode 100644 index f092a7a22277..000000000000 --- a/extensions/transformiix/source/xpath/txForwardContext.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_XPATH_CONTEXT -#define __TX_XPATH_CONTEXT - -#include "txIXPathContext.h" -#include "nsAutoPtr.h" -#include "txNodeSet.h" - -class txForwardContext : public txIEvalContext -{ -public: - txForwardContext(txIMatchContext* aContext, - const txXPathNode& aContextNode, - txNodeSet* aContextNodeSet) - : mInner(aContext), - mContextNode(aContextNode), - mContextSet(aContextNodeSet) - {} - ~txForwardContext() - {} - - TX_DECL_EVAL_CONTEXT; - -private: - txIMatchContext* mInner; - const txXPathNode& mContextNode; - nsRefPtr mContextSet; -}; - -#endif // __TX_XPATH_CONTEXT diff --git a/extensions/transformiix/source/xpath/txIXPathContext.h b/extensions/transformiix/source/xpath/txIXPathContext.h deleted file mode 100644 index 86ac85e581c3..000000000000 --- a/extensions/transformiix/source/xpath/txIXPathContext.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_I_XPATH_CONTEXT -#define __TX_I_XPATH_CONTEXT - -#include "txCore.h" - -class FunctionCall; -class nsIAtom; -class txAExprResult; -class txResultRecycler; -class txXPathNode; - -/* - * txIParseContext - * - * This interface describes the context needed to create - * XPath Expressions and XSLT Patters. - * (not completely though. key() requires the ProcessorState, which is - * not part of this interface.) - */ - -class txIParseContext -{ -public: - virtual ~txIParseContext() - { - } - - /* - * Return a namespaceID for a given prefix. - */ - virtual nsresult resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID) = 0; - - /* - * Create a FunctionCall, needed for extension function calls and - * XSLT. XPath function calls are resolved by the Parser. - */ - virtual nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID, - FunctionCall*& aFunction) = 0; - - /** - * Should nametests parsed in this context be case-sensitive - */ - virtual PRBool caseInsensitiveNameTests() = 0; - - /* - * Callback to be used by the Parser if errors are detected. - */ - virtual void SetErrorOffset(PRUint32 aOffset) = 0; -}; - -/* - * txIMatchContext - * - * Interface used for matching XSLT Patters. - * This is the part of txIEvalContext (see below), that is independent - * of the context node when evaluating a XPath expression, too. - * When evaluating a XPath expression, |txIMatchContext|s are used - * to transport the information from Step to Step. - */ -class txIMatchContext -{ -public: - virtual ~txIMatchContext() - { - } - - /* - * Return the ExprResult associated with the variable with the - * given namespace and local name. - */ - virtual nsresult getVariable(PRInt32 aNamespace, nsIAtom* aLName, - txAExprResult*& aResult) = 0; - - /* - * Is whitespace stripping allowed for the given node? - * See http://www.w3.org/TR/xslt#strip - */ - virtual MBool isStripSpaceAllowed(const txXPathNode& aNode) = 0; - - /** - * Returns a pointer to the private context - */ - virtual void* getPrivateContext() = 0; - - virtual txResultRecycler* recycler() = 0; - - /* - * Callback to be used by the expression/pattern if errors are detected. - */ - virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0; -}; - -#define TX_DECL_MATCH_CONTEXT \ - nsresult getVariable(PRInt32 aNamespace, nsIAtom* aLName, \ - txAExprResult*& aResult); \ - MBool isStripSpaceAllowed(const txXPathNode& aNode); \ - void* getPrivateContext(); \ - txResultRecycler* recycler(); \ - void receiveError(const nsAString& aMsg, nsresult aRes) - -class txIEvalContext : public txIMatchContext -{ -public: - virtual ~txIEvalContext() - { - } - - /* - * Get the context node. - */ - virtual const txXPathNode& getContextNode() = 0; - - /* - * Get the size of the context node set. - */ - virtual PRUint32 size() = 0; - - /* - * Get the position of the context node in the context node set, - * starting with 1. - */ - virtual PRUint32 position() = 0; -}; - -#define TX_DECL_EVAL_CONTEXT \ - TX_DECL_MATCH_CONTEXT; \ - const txXPathNode& getContextNode(); \ - PRUint32 size(); \ - PRUint32 position() - -#endif // __TX_I_XPATH_CONTEXT diff --git a/extensions/transformiix/source/xpath/txLiteralExpr.cpp b/extensions/transformiix/source/xpath/txLiteralExpr.cpp deleted file mode 100644 index 7a608bd0428b..000000000000 --- a/extensions/transformiix/source/xpath/txLiteralExpr.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * IBM Corporation - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "ExprResult.h" - -txLiteralExpr::txLiteralExpr(double aDbl) - : mValue(new NumberResult(aDbl, nsnull)) -{ -} - -txLiteralExpr::txLiteralExpr(const nsAString& aStr) - : mValue(new StringResult(aStr, nsnull)) -{ -} - -nsresult -txLiteralExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - NS_ENSURE_TRUE(mValue, NS_ERROR_OUT_OF_MEMORY); - - *aResult = mValue; - NS_ADDREF(*aResult); - - return NS_OK; -} - -#ifdef TX_TO_STRING -void -txLiteralExpr::toString(nsAString& aStr) -{ - switch (mValue->getResultType()) { - case txAExprResult::NUMBER: - { - Double::toString(mValue->numberValue(), aStr); - return; - } - case txAExprResult::STRING: - { - StringResult* strRes = - NS_STATIC_CAST(StringResult*, NS_STATIC_CAST(txAExprResult*, - mValue)); - PRUnichar ch = '\''; - if (strRes->mValue.FindChar(ch) != kNotFound) { - ch = '\"'; - } - aStr.Append(ch); - aStr.Append(strRes->mValue); - aStr.Append(ch); - return; - } - } -} -#endif diff --git a/extensions/transformiix/source/xpath/txMozillaXPathTreeWalker.cpp b/extensions/transformiix/source/xpath/txMozillaXPathTreeWalker.cpp deleted file mode 100644 index 112741e5d8b6..000000000000 --- a/extensions/transformiix/source/xpath/txMozillaXPathTreeWalker.cpp +++ /dev/null @@ -1,968 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXPathTreeWalker.h" -#include "nsIAtom.h" -#include "nsIAttribute.h" -#include "nsIDOM3Node.h" -#include "nsIDOMAttr.h" -#include "nsIDOMDocument.h" -#include "nsIDOMNode.h" -#include "nsIDOMElement.h" -#include "nsIDOMProcessingInstruction.h" -#include "nsINodeInfo.h" -#include "nsITextContent.h" -#include "nsPrintfCString.h" -#include "nsReadableUtils.h" -#include "nsString.h" -#include "nsTextFragment.h" -#include "XMLUtils.h" -#include "TxLog.h" -#include "nsUnicharUtils.h" - -const PRUint32 kUnknownIndex = PRUint32(-1); - -txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther) - : mPosition(aOther.mPosition), - mCurrentIndex(aOther.mCurrentIndex) -{ -} - -txXPathTreeWalker::txXPathTreeWalker(const txXPathNode& aNode) - : mPosition(aNode), - mCurrentIndex(kUnknownIndex) -{ -} - -txXPathTreeWalker::~txXPathTreeWalker() -{ -} - -PRBool -txXPathTreeWalker::moveToElementById(const nsAString& aID) -{ - nsCOMPtr document; - if (mPosition.isDocument()) { - document = do_QueryInterface(mPosition.mDocument); - } - else { - document = do_QueryInterface(mPosition.mContent->GetDocument()); - } - - if (!document) { - return PR_FALSE; - } - - nsCOMPtr element; - document->GetElementById(aID, getter_AddRefs(element)); - if (!element) { - return PR_FALSE; - } - - nsCOMPtr content = do_QueryInterface(element); - NS_ENSURE_TRUE(content, PR_FALSE); - - mPosition.mIndex = txXPathNode::eContent; - mPosition.mContent = content; - mCurrentIndex = kUnknownIndex; - mDescendants.Clear(); - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToFirstAttribute() -{ - if (!mPosition.isContent()) { - return PR_FALSE; - } - - return moveToValidAttribute(0); -} - -PRBool -txXPathTreeWalker::moveToNextAttribute() -{ - // XXX an assertion should be enough here with the current code - if (!mPosition.isAttribute()) { - return PR_FALSE; - } - - return moveToValidAttribute(mPosition.mIndex + 1); -} - -PRBool -txXPathTreeWalker::moveToValidAttribute(PRUint32 aStartIndex) -{ - NS_ASSERTION(!mPosition.isDocument(), "documents doesn't have attrs"); - - PRUint32 total = mPosition.mContent->GetAttrCount(); - if (aStartIndex >= total) { - return PR_FALSE; - } - - PRInt32 namespaceID; - nsCOMPtr name, prefix; - - PRUint32 index; - for (index = aStartIndex; index < total; ++index) { - mPosition.mContent->GetAttrNameAt(index, &namespaceID, - getter_AddRefs(name), - getter_AddRefs(prefix)); - - // We need to ignore XMLNS attributes. - if (namespaceID != kNameSpaceID_XMLNS) { - mPosition.mIndex = index; - - return PR_TRUE; - } - } - return PR_FALSE; -} - -PRBool -txXPathTreeWalker::moveToFirstChild() -{ - if (mPosition.isAttribute()) { - return PR_FALSE; - } - - if (mPosition.isDocument()) { - nsIContent* child = mPosition.mDocument->GetChildAt(0); - if (!child) { - return PR_FALSE; - } - mPosition.mIndex = txXPathNode::eContent; - mPosition.mContent = child; - - NS_ASSERTION(mCurrentIndex == kUnknownIndex && !mDescendants.Count(), - "we shouldn't have any position info at the document"); - mCurrentIndex = 0; - - return PR_TRUE; - } - - nsIContent* child = mPosition.mContent->GetChildAt(0); - if (!child) { - return PR_FALSE; - } - mPosition.mContent = child; - - NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(), - "Index should be known if parents index are"); - if (mCurrentIndex != kUnknownIndex && - !mDescendants.AppendValue(mCurrentIndex)) { - mDescendants.Clear(); - } - mCurrentIndex = 0; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToLastChild() -{ - if (mPosition.isAttribute()) { - return PR_FALSE; - } - - if (mPosition.isDocument()) { - PRUint32 total = mPosition.mDocument->GetChildCount(); - if (!total) { - return PR_FALSE; - } - - mPosition.mIndex = txXPathNode::eContent; - mPosition.mContent = mPosition.mDocument->GetChildAt(total - 1); - NS_ASSERTION(mCurrentIndex == kUnknownIndex && !mDescendants.Count(), - "we shouldn't have any position info at the document"); - mCurrentIndex = total - 1; - - return PR_TRUE; - } - - PRUint32 total = mPosition.mContent->GetChildCount(); - if (!total) { - return PR_FALSE; - } - mPosition.mContent = mPosition.mContent->GetChildAt(total - 1); - - NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(), - "Index should be known if parents index are"); - if (mCurrentIndex != kUnknownIndex && - !mDescendants.AppendValue(mCurrentIndex)) { - mDescendants.Clear(); - } - mCurrentIndex = total - 1; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToNextSibling() -{ - if (!mPosition.isContent()) { - return PR_FALSE; - } - - return moveToSibling(1); -} - -PRBool -txXPathTreeWalker::moveToPreviousSibling() -{ - if (!mPosition.isContent()) { - return PR_FALSE; - } - - return moveToSibling(-1); -} - -PRBool -txXPathTreeWalker::moveToParent() -{ - if (mPosition.isDocument()) { - return PR_FALSE; - } - - if (mPosition.isAttribute()) { - mPosition.mIndex = txXPathNode::eContent; - - return PR_TRUE; - } - - nsIContent *parent = mPosition.mContent->GetParent(); - if (parent) { - mPosition.mContent = parent; - PRInt32 count = mDescendants.Count(); - if (count) { - mCurrentIndex = mDescendants.ValueAt(--count); - mDescendants.RemoveValueAt(count); - } - else { - mCurrentIndex = kUnknownIndex; - } - - return PR_TRUE; - } - - nsIDocument* document = mPosition.mContent->GetDocument(); - if (!document) { - return PR_FALSE; - } - - mPosition.mIndex = txXPathNode::eDocument; - mPosition.mDocument = document; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToSibling(PRInt32 aDir) -{ - NS_ASSERTION(mPosition.isContent(), - "moveToSibling should only be called for content"); - - nsIDocument* document; - nsIContent* parent = mPosition.mContent->GetParent(); - if (!parent) { - document = mPosition.mContent->GetDocument(); - if (!document) { - return PR_FALSE; - } - } - if (mCurrentIndex == kUnknownIndex) { - mCurrentIndex = parent ? parent->IndexOf(mPosition.mContent) - : document->IndexOf(mPosition.mContent); - } - - // if mCurrentIndex is 0 we rely on GetChildAt returning null for an - // index of PRUint32(-1). - PRUint32 newIndex = mCurrentIndex + aDir; - nsIContent* newChild = parent ? parent->GetChildAt(newIndex) : - document->GetChildAt(newIndex); - if (!newChild) { - return PR_FALSE; - } - - mPosition.mContent = newChild; - mCurrentIndex = newIndex; - - return PR_TRUE; -} - -txXPathNode::txXPathNode(const txXPathNode& aNode) : mIndex(aNode.mIndex) -{ - // Hopefully it's ok to access mContent through mDocument. - mDocument = aNode.mDocument; -} - -PRBool -txXPathNode::operator==(const txXPathNode& aNode) const -{ - if (mIndex != aNode.mIndex) { - return PR_FALSE; - } - - // Hopefully it's ok to access mContent through mDocument. - return (mDocument == aNode.mDocument); -} - -/* static */ -PRBool -txXPathNodeUtils::getAttr(const txXPathNode& aNode, nsIAtom* aLocalName, - PRInt32 aNSID, nsAString& aValue) -{ - if (aNode.isDocument() || aNode.isAttribute()) { - return PR_FALSE; - } - - return aNode.mContent->GetAttr(aNSID, aLocalName, aValue); -} - -/* static */ -already_AddRefed -txXPathNodeUtils::getLocalName(const txXPathNode& aNode) -{ - if (aNode.isDocument()) { - return nsnull; - } - - if (aNode.isContent()) { - if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { - nsIAtom* localName = aNode.mContent->Tag(); - NS_ADDREF(localName); - - return localName; - } - - if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) { - nsCOMPtr node = do_QueryInterface(aNode.mContent); - nsAutoString target; - node->GetNodeName(target); - - return NS_NewAtom(target); - } - - return nsnull; - } - - nsIAtom* localName; - nsCOMPtr prefix; - PRInt32 namespaceID; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, &localName, - getter_AddRefs(prefix)); - - return localName; -} - -/* static */ -void -txXPathNodeUtils::getLocalName(const txXPathNode& aNode, nsAString& aLocalName) -{ - if (aNode.isDocument()) { - aLocalName.Truncate(); - - return; - } - - if (aNode.isContent()) { - if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { - nsINodeInfo* nodeInfo = aNode.mContent->NodeInfo(); - nodeInfo->GetLocalName(aLocalName); - - // Check for html - if (nodeInfo->NamespaceEquals(kNameSpaceID_None) && - aNode.mContent->IsContentOfType(nsIContent::eHTML)) { - ToUpperCase(aLocalName); - } - - return; - } - - if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) { - // PIs don't have a nodeinfo but do have a name - nsCOMPtr node = do_QueryInterface(aNode.mContent); - node->GetNodeName(aLocalName); - - return; - } - - aLocalName.Truncate(); - - return; - } - - nsCOMPtr prefix, localName; - PRInt32 namespaceID; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, - getter_AddRefs(localName), - getter_AddRefs(prefix)); - localName->ToString(aLocalName); - - // Check for html - if (aNode.mContent->NodeInfo()->NamespaceEquals(kNameSpaceID_None) && - aNode.mContent->IsContentOfType(nsIContent::eHTML)) { - ToUpperCase(aLocalName); - } -} - -/* static */ -void -txXPathNodeUtils::getNodeName(const txXPathNode& aNode, nsAString& aName) -{ - if (aNode.isDocument()) { - aName.Truncate(); - - return; - } - - if (aNode.isContent()) { - if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { - nsINodeInfo* nodeInfo = aNode.mContent->NodeInfo(); - nodeInfo->GetQualifiedName(aName); - - // Check for html - if (nodeInfo->NamespaceEquals(kNameSpaceID_None) && - aNode.mContent->IsContentOfType(nsIContent::eHTML)) { - ToUpperCase(aName); - } - - return; - } - - if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) { - // PIs don't have a nodeinfo but do have a name - nsCOMPtr node = do_QueryInterface(aNode.mContent); - node->GetNodeName(aName); - - return; - } - - aName.Truncate(); - - return; - } - - nsCOMPtr name, prefix; - PRInt32 namespaceID; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, - getter_AddRefs(name), - getter_AddRefs(prefix)); - - - if (prefix) { - prefix->ToString(aName); - aName.Append(PRUnichar(':')); - } - else { - aName.Truncate(); - } - - const char* attrName; - name->GetUTF8String(&attrName); - AppendUTF8toUTF16(attrName, aName); - - // Check for html - if (aNode.mContent->NodeInfo()->NamespaceEquals(kNameSpaceID_None) && - aNode.mContent->IsContentOfType(nsIContent::eHTML)) { - ToUpperCase(aName); - } -} - -/* static */ -PRInt32 -txXPathNodeUtils::getNamespaceID(const txXPathNode& aNode) -{ - if (aNode.isDocument()) { - return kNameSpaceID_None; - } - - if (aNode.isContent()) { - return aNode.mContent->GetNameSpaceID(); - } - - nsCOMPtr name, prefix; - PRInt32 namespaceID; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, - getter_AddRefs(name), - getter_AddRefs(prefix)); - return namespaceID; -} - -/* static */ -void -txXPathNodeUtils::getNamespaceURI(const txXPathNode& aNode, nsAString& aURI) -{ - gTxNameSpaceManager->GetNameSpaceURI(getNamespaceID(aNode), aURI); -} - -/* static */ -PRUint16 -txXPathNodeUtils::getNodeType(const txXPathNode& aNode) -{ - if (aNode.isDocument()) { - return txXPathNodeType::DOCUMENT_NODE; - } - - if (aNode.isContent()) { - PRUint16 type; - nsCOMPtr node = do_QueryInterface(aNode.mContent); - node->GetNodeType(&type); - - return type; - } - - return txXPathNodeType::ATTRIBUTE_NODE; -} - -static void appendTextContent(nsIContent* aElement, nsAString& aResult) -{ - nsIContent* content = aElement->GetChildAt(0); - PRUint32 i = 0; - while (content) { - if (content->IsContentOfType(nsIContent::eELEMENT)) { - appendTextContent(content, aResult); - } - else if (content->IsContentOfType(nsIContent::eTEXT)) { - nsCOMPtr textContent = do_QueryInterface(content); - textContent->AppendTextTo(aResult); - } - content = aElement->GetChildAt(++i); - } -} - -/* static */ -void -txXPathNodeUtils::appendNodeValue(const txXPathNode& aNode, nsAString& aResult) -{ - if (aNode.isAttribute()) { - nsCOMPtr name, prefix; - PRInt32 namespaceID; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, - getter_AddRefs(name), - getter_AddRefs(prefix)); - - nsAutoString result; - aNode.mContent->GetAttr(namespaceID, name, result); - aResult.Append(result); - - return; - } - - if (aNode.isDocument()) { - nsIContent* content = aNode.mDocument->GetRootContent(); - if (content) { - appendTextContent(content, aResult); - } - - return; - } - - if (aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { - appendTextContent(aNode.mContent, aResult); - - return; - } - - if (aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION)) { - nsCOMPtr node = do_QueryInterface(aNode.mContent); - - nsAutoString result; - node->GetNodeValue(result); - aResult.Append(result); - - return; - } - - nsCOMPtr textContent = do_QueryInterface(aNode.mContent); - if (!textContent) { - NS_ERROR("Unexpected nodetype."); - - return; - } - - textContent->AppendTextTo(aResult); -} - -/* static */ -PRBool -txXPathNodeUtils::isWhitespace(const txXPathNode& aNode) -{ - NS_ASSERTION(aNode.isContent(), "Wrong type!"); - - nsCOMPtr textCont = do_QueryInterface(aNode.mContent); - if (!textCont) { - return PR_TRUE; - } - return textCont->IsOnlyWhitespace(); -} - -/* static */ -txXPathNode* -txXPathNodeUtils::getDocument(const txXPathNode& aNode) -{ - if (aNode.isDocument()) { - return new txXPathNode(aNode); - } - - nsIDocument* document = aNode.mContent->GetDocument(); - return document ? new txXPathNode(document) : nsnull; -} - -/* static */ -txXPathNode* -txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) -{ - if (aNode.isDocument()) { - return new txXPathNode(aNode); - } - - nsIDocument* document = aNode.mContent->GetOwnerDoc(); - - return document ? new txXPathNode(document) : nsnull; -} - -#ifndef HAVE_64BIT_OS -#define kFmtSize 13 -#define kFmtSizeAttr 24 -const char gPrintfFmt[] = "id0x%08p"; -const char gPrintfFmtAttr[] = "id0x%08p-%010i"; -#else -#define kFmtSize 21 -#define kFmtSizeAttr 32 -const char gPrintfFmt[] = "id0x%016p"; -const char gPrintfFmtAttr[] = "id0x%016p-%010i"; -#endif - -/* static */ -nsresult -txXPathNodeUtils::getXSLTId(const txXPathNode& aNode, - nsAString& aResult) -{ - if (aNode.isDocument()) { - CopyASCIItoUTF16(nsPrintfCString(kFmtSize, gPrintfFmt, - aNode.mDocument), aResult); - - return NS_OK; - } - - if (aNode.isContent()) { - CopyASCIItoUTF16(nsPrintfCString(kFmtSize, gPrintfFmt, aNode.mContent), - aResult); - - return NS_OK; - } - - CopyASCIItoUTF16(nsPrintfCString(kFmtSizeAttr, gPrintfFmtAttr, aNode.mContent, - aNode.mIndex), aResult); - - return NS_OK; -} - -/* static */ -void -txXPathNodeUtils::getBaseURI(const txXPathNode& aNode, nsAString& aURI) -{ - nsCOMPtr node; - if (aNode.isDocument()) { - node = do_QueryInterface(aNode.mDocument); - } - else { - node = do_QueryInterface(aNode.mContent); - } - - if (node) { - node->GetBaseURI(aURI); - } - else { - aURI.Truncate(); - } -} - -/* static */ -PRIntn -txXPathNodeUtils::comparePosition(const txXPathNode& aNode, - const txXPathNode& aOtherNode) -{ - // First check for equal nodes or attribute-nodes on the same element. - if (aNode.mContent == aOtherNode.mContent) { - if (aNode.mIndex == aOtherNode.mIndex) { - return 0; - } - - if (aNode.isContent() || (!aOtherNode.isContent() && - aNode.mIndex < aOtherNode.mIndex)) { - return -1; - } - - return 1; - } - - // Get document for both nodes. - nsIDocument* document = aNode.isDocument() ? - aNode.mDocument : - aNode.mContent->GetDocument(); - - nsIDocument* otherDocument = aOtherNode.isDocument() ? - aOtherNode.mDocument : - aOtherNode.mContent->GetDocument(); - - // If the nodes have different ownerdocuments, compare the document - // pointers. - if (document && otherDocument && document != otherDocument) { - return document > otherDocument ? 1 : -1; - } - - // Every node comes after its ownerdocument. - if (aNode.isDocument()) { - return -1; - } - - if (aOtherNode.isDocument()) { - return 1; - } - - // Get parents up the tree. - nsAutoVoidArray parents, otherParents; - nsIContent* content = aNode.mContent; - nsIContent* otherContent = aOtherNode.mContent; - nsIContent* parent, *otherParent; - PRInt32 index, otherIndex; - while (content && otherContent) { - parent = content->GetParent(); - otherParent = otherContent->GetParent(); - - // Hopefully this is a common case. - if (parent == otherParent) { - if (parent) { - index = (PRUint32)parent->IndexOf(content); - otherIndex = (PRUint32)parent->IndexOf(otherContent); - } - else { - if (!document) { - if (!otherDocument) { - // Neither aNode nor aOtherNode are not in a document, - // compare their top ancestors. - return content > otherContent ? 1 : -1; - } - - // aNode is not in the tree, compare its top ancestor with - // aOtherNode's document. - return (void*)content > (void*)otherDocument ? 1 : -1; - } - else if (!otherDocument) { - // aOtherNode is not in a document, compare its top - // ancestor with aNode's document. - return (void*)document > (void*)otherContent ? 1 : -1; - } - - // Both nodes are in the same document. - index = (PRUint32)document->IndexOf(content); - otherIndex = (PRUint32)document->IndexOf(otherContent); - } - - return index < otherIndex ? -1 : 1; - } - - parents.AppendElement(content); - otherParents.AppendElement(otherContent); - content = parent; - otherContent = otherParent; - } - - while (content) { - parents.AppendElement(content); - content = content->GetParent(); - } - while (otherContent) { - otherParents.AppendElement(otherContent); - otherContent = otherContent->GetParent(); - } - - if (!document) { - if (!otherDocument) { - // Neither aNode nor aOtherNode are not in a document, compare - // their top ancestors. - return parents.ElementAt(parents.Count() - 1) > - otherParents.ElementAt(otherParents.Count() - 1) ? 1 : -1; - } - - // aNode is not in the tree, compare its top ancestor with aOtherNode's - // document. - return parents.ElementAt(parents.Count() - 1) > otherDocument ? 1 : -1; - } - else if (!otherDocument) { - // aOtherNode is not in a document, compare its top - // ancestor with aNode's document. - return document > - otherParents.ElementAt(otherParents.Count() - 1) ? 1 : -1; - } - - // Walk back down along the parent-chains until we find where they split. - PRInt32 total = parents.Count() - 1; - PRInt32 otherTotal = otherParents.Count() - 1; - NS_ASSERTION(total != otherTotal, "Can't have same number of parents"); - - PRInt32 lastIndex = PR_MIN(total, otherTotal); - PRInt32 i; - parent = nsnull; - for (i = 0; i <= lastIndex; ++i) { - content = NS_STATIC_CAST(nsIContent*, parents.ElementAt(total - i)); - otherContent = NS_STATIC_CAST(nsIContent*, - otherParents.ElementAt(otherTotal - i)); - if (content != otherContent) { - if (parent) { - index = (PRUint32)parent->IndexOf(content); - otherIndex = (PRUint32)parent->IndexOf(otherContent); - } - else { - index = (PRUint32)document->IndexOf(content); - otherIndex = (PRUint32)document->IndexOf(otherContent); - } - NS_ASSERTION(index != otherIndex && index >= 0 && otherIndex >= 0, - "invalid index in compareTreePosition"); - return index < otherIndex ? -1 : 1; - } - - parent = content; - } - - // One node is a descendant of the other. The one with the shortest - // parent-chain is first in the document. - return total < otherTotal ? -1 : 1; -} - -/* static */ -txXPathNode* -txXPathNativeNode::createXPathNode(nsIDOMNode* aNode) -{ - PRUint16 nodeType; - aNode->GetNodeType(&nodeType); - - if (nodeType == nsIDOMNode::ATTRIBUTE_NODE) { - nsCOMPtr attr = do_QueryInterface(aNode); - NS_ASSERTION(attr, "doesn't implement nsIAttribute"); - - nsINodeInfo *nodeInfo = attr->NodeInfo(); - nsIContent *parent = attr->GetContent(); - if (!parent) { - return nsnull; - } - - nsCOMPtr attName, attPrefix; - PRInt32 attNS; - - PRUint32 i, total = parent->GetAttrCount(); - for (i = 0; i < total; ++i) { - parent->GetAttrNameAt(i, &attNS, getter_AddRefs(attName), - getter_AddRefs(attPrefix)); - if (nodeInfo->Equals(attName, attNS)) { - return new txXPathNode(parent, i); - } - } - - NS_ERROR("Couldn't find the attribute in its parent!"); - - return nsnull; - } - - if (nodeType == nsIDOMNode::DOCUMENT_NODE) { - nsCOMPtr document = do_QueryInterface(aNode); - return new txXPathNode(document); - } - - nsCOMPtr content = do_QueryInterface(aNode); - return new txXPathNode(content); -} - -/* static */ -txXPathNode* -txXPathNativeNode::createXPathNode(nsIDOMDocument* aDocument) -{ - nsCOMPtr document = do_QueryInterface(aDocument); - return new txXPathNode(document); -} - -/* static */ -nsresult -txXPathNativeNode::getNode(const txXPathNode& aNode, nsIDOMNode** aResult) -{ - if (aNode.isDocument()) { - return CallQueryInterface(aNode.mDocument, aResult); - } - - if (aNode.isContent()) { - return CallQueryInterface(aNode.mContent, aResult); - } - - PRInt32 namespaceID; - nsCOMPtr name, prefix; - aNode.mContent->GetAttrNameAt(aNode.mIndex, &namespaceID, - getter_AddRefs(name), - getter_AddRefs(prefix)); - - nsAutoString namespaceURI, localname; - gTxNameSpaceManager->GetNameSpaceURI(namespaceID, namespaceURI); - name->ToString(localname); - - nsCOMPtr element = do_QueryInterface(aNode.mContent); - nsCOMPtr attr; - element->GetAttributeNodeNS(namespaceURI, localname, - getter_AddRefs(attr)); - - return CallQueryInterface(attr, aResult); -} - -/* static */ -nsIContent* -txXPathNativeNode::getContent(const txXPathNode& aNode) -{ - NS_ASSERTION(aNode.isContent(), - "Only call getContent on nsIContent wrappers!"); - return aNode.mContent; -} - -/* static */ -nsIDocument* -txXPathNativeNode::getDocument(const txXPathNode& aNode) -{ - NS_ASSERTION(aNode.isDocument(), - "Only call getDocument on nsIDocument wrappers!"); - return aNode.mDocument; -} diff --git a/extensions/transformiix/source/xpath/txNameTest.cpp b/extensions/transformiix/source/xpath/txNameTest.cpp deleted file mode 100644 index 297f4d2f6a8f..000000000000 --- a/extensions/transformiix/source/xpath/txNameTest.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "nsIAtom.h" -#include "txAtoms.h" -#include "txXPathTreeWalker.h" -#include "txIXPathContext.h" - -txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID, - PRUint16 aNodeType) - :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID), - mNodeType(aNodeType) -{ - if (aPrefix == txXMLAtoms::_empty) - mPrefix = 0; - NS_ASSERTION(aLocalName, "txNameTest without a local name?"); - NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE || - aNodeType == txXPathNodeType::ELEMENT_NODE || - aNodeType == txXPathNodeType::ATTRIBUTE_NODE, - "Go fix txNameTest::matches"); -} - -txNameTest::~txNameTest() -{ -} - -PRBool txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - if ((mNodeType == txXPathNodeType::ELEMENT_NODE && - !txXPathNodeUtils::isElement(aNode)) || - (mNodeType == txXPathNodeType::ATTRIBUTE_NODE && - !txXPathNodeUtils::isAttribute(aNode)) || - (mNodeType == txXPathNodeType::DOCUMENT_NODE && - !txXPathNodeUtils::isRoot(aNode))) { - return PR_FALSE; - } - - // Totally wild? - if (mLocalName == txXPathAtoms::_asterix && !mPrefix) - return MB_TRUE; - - // Compare namespaces - if (txXPathNodeUtils::getNamespaceID(aNode) != mNamespace) - return MB_FALSE; - - // Name wild? - if (mLocalName == txXPathAtoms::_asterix) - return MB_TRUE; - - // Compare local-names - return txXPathNodeUtils::localNameEquals(aNode, mLocalName); -} - -/* - * Returns the default priority of this txNodeTest - */ -double txNameTest::getDefaultPriority() -{ - if (mLocalName == txXPathAtoms::_asterix) { - if (!mPrefix) - return -0.5; - return -0.25; - } - return 0; -} - -#ifdef TX_TO_STRING -void -txNameTest::toString(nsAString& aDest) -{ - if (mPrefix) { - nsAutoString prefix; - mPrefix->ToString(prefix); - aDest.Append(prefix); - aDest.Append(PRUnichar(':')); - } - nsAutoString localName; - mLocalName->ToString(localName); - aDest.Append(localName); -} -#endif diff --git a/extensions/transformiix/source/xpath/txNodeSet.cpp b/extensions/transformiix/source/xpath/txNodeSet.cpp deleted file mode 100644 index e7b56de46397..000000000000 --- a/extensions/transformiix/source/xpath/txNodeSet.cpp +++ /dev/null @@ -1,626 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txNodeSet.h" -#include "TxLog.h" -#include "nsMemory.h" - -/** - * Implementation of an XPath nodeset - */ - -static const PRInt32 kTxNodeSetMinSize = 4; -static const PRInt32 kTxNodeSetGrowFactor = 2; - -#define kForward 1 -#define kReversed -1 - -txNodeSet::txNodeSet(txResultRecycler* aRecycler) - : txAExprResult(aRecycler), - mStart(nsnull), - mEnd(nsnull), - mStartBuffer(nsnull), - mEndBuffer(nsnull), - mDirection(kForward), - mMarks(nsnull) -{ -} - -txNodeSet::txNodeSet(const txXPathNode& aNode, txResultRecycler* aRecycler) - : txAExprResult(aRecycler), - mStart(nsnull), - mEnd(nsnull), - mStartBuffer(nsnull), - mEndBuffer(nsnull), - mDirection(kForward), - mMarks(nsnull) -{ - if (!ensureGrowSize(1)) { - return; - } - - new(mStart) txXPathNode(aNode); - ++mEnd; -} - -txNodeSet::txNodeSet(const txNodeSet& aSource, txResultRecycler* aRecycler) - : txAExprResult(aRecycler), - mStart(nsnull), - mEnd(nsnull), - mStartBuffer(nsnull), - mEndBuffer(nsnull), - mDirection(kForward), - mMarks(nsnull) -{ - append(aSource); -} - -txNodeSet::~txNodeSet() -{ - delete [] mMarks; - - if (mStartBuffer) { - while (mStart < mEnd) { - mStart->~txXPathNode(); - ++mStart; - } - - nsMemory::Free(mStartBuffer); - } -} - -nsresult txNodeSet::add(const txXPathNode& aNode) -{ - NS_ASSERTION(mDirection == kForward, - "only append(aNode) is supported on reversed nodesets"); - - if (isEmpty()) { - return append(aNode); - } - - PRBool dupe; - txXPathNode* pos = findPosition(aNode, mStart, mEnd, dupe); - - if (dupe) { - return NS_OK; - } - - // save pos, ensureGrowSize messes with the pointers - PRInt32 moveSize = mEnd - pos; - PRInt32 offset = pos - mStart; - if (!ensureGrowSize(1)) { - return NS_ERROR_OUT_OF_MEMORY; - } - // set pos to where it was - pos = mStart + offset; - - if (moveSize > 0) { - memmove(pos + 1, pos, moveSize * sizeof(txXPathNode)); - } - - new(pos) txXPathNode(aNode); - ++mEnd; - - return NS_OK; -} - -nsresult txNodeSet::add(const txNodeSet& aNodes) -{ - return add(aNodes, copyElements); -} - -nsresult txNodeSet::addAndTransfer(txNodeSet* aNodes) -{ - // failure is out-of-memory, transfer didn't happen - nsresult rv = add(*aNodes, transferElements); - NS_ENSURE_SUCCESS(rv, rv); - -#ifdef TX_DONT_RECYCLE_BUFFER - if (aNodes->mStartBuffer) { - nsMemory::Free(aNodes->mStartBuffer); - aNodes->mStartBuffer = aNodes->mEndBuffer = nsnull; - } -#endif - aNodes->mStart = aNodes->mEnd = aNodes->mStartBuffer; - - return NS_OK; -} - -/** - * add(aNodeSet, aTransferOp) - * - * The code is optimized to make a minimum number of calls to - * Node::compareDocumentPosition. The idea is this: - * We have the two nodesets (number indicate "document position") - * - * 1 3 7 <- source 1 - * 2 3 6 8 9 <- source 2 - * _ _ _ _ _ _ _ _ <- result - * - * - * When merging these nodesets into the result, the nodes are transfered - * in chunks to the end of the buffer so that each chunk does not contain - * a node from the other nodeset, in document order. - * - * We select the last non-transfered node in the first nodeset and find - * where in the other nodeset it would be inserted. In this case we would - * take the 7 from the first nodeset and find the position between the - * 6 and 8 in the second. We then take the nodes after the insert-position - * and transfer them to the end of the resulting nodeset. Which in this case - * means that we first transfered the 8 and 9 nodes, giving us the following: - * - * 1 3 7 <- source 1 - * 2 3 6 <- source 2 - * _ _ _ _ _ _ 8 9 <- result - * - * The corresponding procedure is done for the second nodeset, that is - * the insertion position of the 6 in the first nodeset is found, which - * is between the 3 and the 7. The 7 is memmoved (as it stays within - * the same nodeset) to the result buffer. - * - * As the result buffer is filled from the end, it is safe to share the - * buffer between this nodeset and the result. - * - * This is repeated until both of the nodesets are empty. - * - * If we find a duplicate node when searching for where insertposition we - * check for sequences of duplicate nodes, which can be optimized. - * - */ -nsresult txNodeSet::add(const txNodeSet& aNodes, transferOp aTransfer) -{ - NS_ASSERTION(mDirection == kForward, - "only append(aNode) is supported on reversed nodesets"); - - if (aNodes.isEmpty()) { - return NS_OK; - } - - if (!ensureGrowSize(aNodes.size())) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // This is probably a rather common case, so lets try to shortcut. - if (mStart == mEnd || - txXPathNodeUtils::comparePosition(mEnd[-1], *aNodes.mStart) < 0) { - aTransfer(mEnd, aNodes.mStart, aNodes.mEnd); - mEnd += aNodes.size(); - - return NS_OK; - } - - // Last element in this nodeset - txXPathNode* thisPos = mEnd; - - // Last element of the other nodeset - txXPathNode* otherPos = aNodes.mEnd; - - // Pointer to the insertion point in this nodeset - txXPathNode* insertPos = mEndBuffer; - - PRBool dupe; - txXPathNode* pos; - PRInt32 count; - while (thisPos > mStart || otherPos > aNodes.mStart) { - // Find where the last remaining node of this nodeset would - // be inserted in the other nodeset. - if (thisPos > mStart) { - pos = findPosition(thisPos[-1], aNodes.mStart, otherPos, dupe); - - if (dupe) { - --thisPos; // this is already added - // check dupe sequence - while (thisPos > mStart && pos > aNodes.mStart && - thisPos[-1] == pos[-1]) { - --thisPos; - --pos; - } - } - } - else { - pos = aNodes.mStart; - } - - // Transfer the otherNodes after the insertion point to the result - count = otherPos - pos; - if (count > 0) { - insertPos -= count; - aTransfer(insertPos, pos, otherPos); - otherPos -= count; - } - - // Find where the last remaining node of the otherNodeset would - // be inserted in this nodeset. - if (otherPos > aNodes.mStart) { - pos = findPosition(otherPos[-1], mStart, thisPos, dupe); - - if (dupe) { - --otherPos; // this is already added - // check dupe sequence - while (otherPos > aNodes.mStart && pos > mStart && - otherPos[-1] == pos[-1]) { - --otherPos; - --pos; - } - } - } - else { - pos = mStart; - } - - // Move the nodes from this nodeset after the insertion point - // to the result - count = thisPos - pos; - if (count > 0) { - insertPos -= count; - memmove(insertPos, pos, count * sizeof(txXPathNode)); - thisPos -= count; - } - } - mStart = insertPos; - mEnd = mEndBuffer; - - return NS_OK; -} - -/** - * Append API - * These functions should be used with care. - * They are intended to be used when the caller assures that the resulting - * nodeset remains in document order. - * Abuse will break document order, and cause errors in the result. - * These functions are significantly faster than the add API, as no - * order info operations will be performed. - */ - -nsresult -txNodeSet::append(const txXPathNode& aNode) -{ - if (!ensureGrowSize(1)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (mDirection == kForward) { - new(mEnd) txXPathNode(aNode); - ++mEnd; - - return NS_OK; - } - - new(--mStart) txXPathNode(aNode); - - return NS_OK; -} - -nsresult -txNodeSet::append(const txNodeSet& aNodes) -{ - NS_ASSERTION(mDirection == kForward, - "only append(aNode) is supported on reversed nodesets"); - - if (aNodes.isEmpty()) { - return NS_OK; - } - - PRInt32 appended = aNodes.size(); - if (!ensureGrowSize(appended)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - copyElements(mEnd, aNodes.mStart, aNodes.mEnd); - mEnd += appended; - - return NS_OK; -} - -nsresult -txNodeSet::mark(PRInt32 aIndex) -{ - NS_ASSERTION(aIndex >= 0 && mStart && mEnd - mStart > aIndex, - "index out of bounds"); - if (!mMarks) { - PRInt32 length = size(); - mMarks = new PRPackedBool[length]; - NS_ENSURE_TRUE(mMarks, NS_ERROR_OUT_OF_MEMORY); - memset(mMarks, 0, length * sizeof(PRPackedBool)); - } - if (mDirection == kForward) { - mMarks[aIndex] = PR_TRUE; - } - else { - mMarks[size() - aIndex - 1] = PR_TRUE; - } - - return NS_OK; -} - -nsresult -txNodeSet::sweep() -{ - if (!mMarks) { - // sweep everything - clear(); - } - - PRInt32 chunk, pos = 0; - PRInt32 length = size(); - txXPathNode* insertion = mStartBuffer; - - while (pos < length) { - while (pos < length && !mMarks[pos]) { - // delete unmarked - mStart[pos].~txXPathNode(); - ++pos; - } - // find chunk to move - chunk = 0; - while (pos < length && mMarks[pos]) { - ++pos; - ++chunk; - } - // move chunk - if (chunk > 0) { - memmove(insertion, mStart + pos - chunk, - chunk * sizeof(txXPathNode)); - insertion += chunk; - } - } - mStart = mStartBuffer; - mEnd = insertion; - delete [] mMarks; - mMarks = nsnull; - - return NS_OK; -} - -void -txNodeSet::clear() -{ - while (mStart < mEnd) { - mStart->~txXPathNode(); - ++mStart; - } -#ifdef TX_DONT_RECYCLE_BUFFER - if (mStartBuffer) { - nsMemory::Free(mStartBuffer); - mStartBuffer = mEndBuffer = nsnull; - } -#endif - mStart = mEnd = mStartBuffer; - delete [] mMarks; - mMarks = nsnull; - mDirection = kForward; -} - -PRInt32 -txNodeSet::indexOf(const txXPathNode& aNode) const -{ - NS_ASSERTION(mDirection == kForward, - "only append(aNode) is supported on reversed nodesets"); - - if (!mStart || mStart == mEnd) { - return -1; - } - - PRInt32 counter = 0; - txXPathNode* pos = mStart; - for (; pos < mEnd; ++counter, ++pos) { - if (*pos == aNode) { - return counter; - } - } - - return -1; -} - -const txXPathNode& -txNodeSet::get(PRInt32 aIndex) const -{ - if (mDirection == kForward) { - return mStart[aIndex]; - } - - return mEnd[-aIndex - 1]; -} - -short -txNodeSet::getResultType() -{ - return txAExprResult::NODESET; -} - -PRBool -txNodeSet::booleanValue() -{ - return !isEmpty(); -} -double -txNodeSet::numberValue() -{ - nsAutoString str; - stringValue(str); - - return Double::toDouble(str); -} - -void -txNodeSet::stringValue(nsAString& aStr) -{ - NS_ASSERTION(mDirection == kForward, - "only append(aNode) is supported on reversed nodesets"); - if (isEmpty()) { - return; - } - txXPathNodeUtils::appendNodeValue(get(0), aStr); -} - -nsAString* -txNodeSet::stringValuePointer() -{ - return nsnull; -} - -PRBool txNodeSet::ensureGrowSize(PRInt32 aSize) -{ - // check if there is enough place in the buffer as is - if (mDirection == kForward && aSize <= mEndBuffer - mEnd) { - return PR_TRUE; - } - - if (mDirection == kReversed && aSize <= mStart - mStartBuffer) { - return PR_TRUE; - } - - // check if we just have to align mStart to have enough space - PRInt32 oldSize = mEnd - mStart; - PRInt32 oldLength = mEndBuffer - mStartBuffer; - PRInt32 ensureSize = oldSize + aSize; - if (ensureSize <= oldLength) { - // just move the buffer - txXPathNode* dest = mStartBuffer; - if (mDirection == kReversed) { - dest = mEndBuffer - oldSize; - } - memmove(dest, mStart, oldSize * sizeof(txXPathNode)); - mStart = dest; - mEnd = dest + oldSize; - - return PR_TRUE; - } - - // This isn't 100% safe. But until someone manages to make a 1gig nodeset - // it should be ok. - PRInt32 newLength = PR_MAX(oldLength, kTxNodeSetMinSize); - - while (newLength < ensureSize) { - newLength *= kTxNodeSetGrowFactor; - } - - txXPathNode* newArr = NS_STATIC_CAST(txXPathNode*, - nsMemory::Alloc(newLength * - sizeof(txXPathNode))); - if (!newArr) { - return PR_FALSE; - } - - txXPathNode* dest = newArr; - if (mDirection == kReversed) { - dest += newLength - oldSize; - } - - if (oldSize > 0) { - memcpy(dest, mStart, oldSize * sizeof(txXPathNode)); - } - - if (mStartBuffer) { -#ifdef DEBUG - memset(mStartBuffer, 0, - (mEndBuffer - mStartBuffer) * sizeof(txXPathNode)); -#endif - nsMemory::Free(mStartBuffer); - } - - mStartBuffer = newArr; - mEndBuffer = mStartBuffer + newLength; - mStart = dest; - mEnd = dest + oldSize; - - return PR_TRUE; -} - -txXPathNode* -txNodeSet::findPosition(const txXPathNode& aNode, txXPathNode* aFirst, - txXPathNode* aLast, PRBool& aDupe) const -{ - aDupe = PR_FALSE; - if (aLast - aFirst <= 2) { - // If we search 2 nodes or less there is no point in further divides - txXPathNode* pos = aFirst; - for (; pos < aLast; ++pos) { - PRIntn cmp = txXPathNodeUtils::comparePosition(aNode, *pos); - if (cmp < 0) { - return pos; - } - - if (cmp == 0) { - aDupe = PR_TRUE; - - return pos; - } - } - return pos; - } - - // (cannot add two pointers) - txXPathNode* midpos = aFirst + (aLast - aFirst) / 2; - PRIntn cmp = txXPathNodeUtils::comparePosition(aNode, *midpos); - if (cmp == 0) { - aDupe = PR_TRUE; - - return midpos; - } - - if (cmp > 0) { - return findPosition(aNode, midpos + 1, aLast, aDupe); - } - - // midpos excluded as end of range - - return findPosition(aNode, aFirst, midpos, aDupe); -} - -/* static */ -void -txNodeSet::copyElements(txXPathNode* aDest, - const txXPathNode* aStart, const txXPathNode* aEnd) -{ - const txXPathNode* pos = aStart; - while (pos < aEnd) { - new(aDest) txXPathNode(*pos); - ++aDest; - ++pos; - } -} - -/* static */ -void -txNodeSet::transferElements(txXPathNode* aDest, - const txXPathNode* aStart, const txXPathNode* aEnd) -{ - memcpy(aDest, aStart, (aEnd - aStart) * sizeof(txXPathNode)); -} diff --git a/extensions/transformiix/source/xpath/txNodeSet.h b/extensions/transformiix/source/xpath/txNodeSet.h deleted file mode 100644 index 43d6ac4182cd..000000000000 --- a/extensions/transformiix/source/xpath/txNodeSet.h +++ /dev/null @@ -1,241 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Implementation of an XPath NodeSet - */ - -#ifndef txNodeSet_h__ -#define txNodeSet_h__ - -#include "ExprResult.h" -#include "nsVoidArray.h" -#include "txError.h" -#include "txXPathTreeWalker.h" - -class txNodeSet : public txAExprResult -{ -public: - /** - * Creates a new empty NodeSet - */ - txNodeSet(txResultRecycler* aRecycler); - - /** - * Creates a new NodeSet with one node. - */ - txNodeSet(const txXPathNode& aNode, txResultRecycler* aRecycler); - - /** - * Creates a new txNodeSet, copying the node references from the source - * NodeSet. - */ - txNodeSet(const txNodeSet& aSource, txResultRecycler* aRecycler); - - /** - * Destructor for txNodeSet, deletes the nodes. - */ - virtual ~txNodeSet(); - - /** - * Adds the specified txXPathNode to this NodeSet if it is not already - * in this NodeSet. The node is inserted according to document order. - * - * @param aNode the txXPathNode to add to the NodeSet - * @return errorcode. - */ - nsresult add(const txXPathNode& aNode); - - /** - * Adds the nodes in specified NodeSet to this NodeSet. The resulting - * NodeSet is sorted in document order and does not contain any duplicate - * nodes. - * - * @param aNodes the NodeSet to add, must be in document order. - * @return errorcode. - */ - nsresult add(const txNodeSet& aNodes); - nsresult addAndTransfer(txNodeSet* aNodes); - - /** - * Append API - * These functions should be used with care. - * They are intended to be used when the caller assures that the resulting - * NodeSet remains in document order. - * Abuse will break document order, and cause errors in the result. - * These functions are significantly faster than the add API, as no - * order info operations will be performed. - */ - - /** - * Appends the specified Node to the end of this NodeSet - * @param aNode the Node to append to the NodeSet - * @return errorcode. - */ - nsresult append(const txXPathNode& aNode); - - /** - * Appends the nodes in the specified NodeSet to the end of this NodeSet - * @param aNodes the NodeSet to append to the NodeSet - * @return errorcode. - */ - nsresult append(const txNodeSet& aNodes); - - /** - * API to implement reverse axes in LocationStep. - * - * Before adding nodes to the nodeset for a reversed axis, call - * setReverse(). This will make the append(aNode) and get() methods treat - * the nodeset as required. Do only call append(aNode), get(), mark() - * and sweep() while the nodeset is reversed. - * Afterwards, call unsetReverse(). The nodes are stored in document - * order internally. - */ - void setReverse() - { - mDirection = -1; - } - void unsetReverse() - { - mDirection = 1; - } - - /** - * API to implement predicates in PredicateExpr - * - * mark(aIndex) marks the specified member of the nodeset. - * sweep() clears all members of the nodeset that haven't been - * marked before and clear the mMarks array. - */ - nsresult mark(PRInt32 aIndex); - nsresult sweep(); - - /** - * Removes all nodes from this nodeset - */ - void clear(); - - /** - * Returns the index of the specified Node, - * or -1 if the Node is not contained in the NodeSet - * @param aNode the Node to get the index for - * @return index of specified node or -1 if the node does not exist - */ - PRInt32 indexOf(const txXPathNode& aNode) const; - - /** - * Returns true if the specified Node is contained in the set. - * @param aNode the Node to search for - * @return true if specified Node is contained in the NodeSet - */ - PRBool contains(const txXPathNode& aNode) const - { - return indexOf(aNode) >= 0; - } - - /** - * Returns the Node at the specified node in this NodeSet. - * @param aIndex the node of the Node to return - * @return Node at specified node - */ - const txXPathNode& get(PRInt32 aIndex) const; - - /** - * Returns true if there are no Nodes in the NodeSet. - * @return true if there are no Nodes in the NodeSet. - */ - PRBool isEmpty() const - { - return mStart ? mStart == mEnd : PR_TRUE; - } - - /** - * Returns the number of elements in the NodeSet - * @return the number of elements in the NodeSet - */ - PRInt32 size() const - { - return mStart ? mEnd - mStart : 0; - } - - TX_DECL_EXPRRESULT - -private: - static void toString(const txNodeSet& aNodes, nsAString& aResult); - - /** - * Ensure that this nodeset can take another aSize nodes. - * - * Changes mStart and mEnd as well as mBufferStart and mBufferEnd. - */ - PRBool ensureGrowSize(PRInt32 aSize); - - /** - * Finds position in the buffer where a node should be inserted - * to keep the nodeset in document order. Searches the positions - * aFirst-aLast, including aFirst, but not aLast. - * @param aNode Node to find insert position for. - * @param aFirst First item of the search range, included. - * @param aLast Last item of the search range, excluded. - * @param aDupe out-param. Will be set to true if the node already - * exists in the NodeSet, false if it should be - * inserted. - * @return pointer where to insert the node. The node should be inserted - * before the given node. This value is always set, even if aNode - * already exists in the NodeSet - */ - txXPathNode* findPosition(const txXPathNode& aNode, - txXPathNode* aFirst, - txXPathNode* aLast, PRBool& aDupe) const; - - static void copyElements(txXPathNode* aDest, const txXPathNode* aStart, - const txXPathNode* aEnd); - static void transferElements(txXPathNode* aDest, const txXPathNode* aStart, - const txXPathNode* aEnd); - - typedef void (*transferOp) (txXPathNode* aDest, const txXPathNode* aStart, - const txXPathNode* aEnd); - nsresult add(const txNodeSet& aNodes, transferOp aTransfer); - - txXPathNode *mStart, *mEnd, *mStartBuffer, *mEndBuffer; - PRInt32 mDirection; - // used for mark() and sweep() in predicates - PRPackedBool* mMarks; -}; - -#endif diff --git a/extensions/transformiix/source/xpath/txNodeSetContext.cpp b/extensions/transformiix/source/xpath/txNodeSetContext.cpp deleted file mode 100644 index 0217703c23dd..000000000000 --- a/extensions/transformiix/source/xpath/txNodeSetContext.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txNodeSetContext.h" -#include "txNodeSet.h" - -const txXPathNode& txNodeSetContext::getContextNode() -{ - return mContextSet->get(mPosition - 1); -} - -PRUint32 txNodeSetContext::size() -{ - return (PRUint32)mContextSet->size(); -} - -PRUint32 txNodeSetContext::position() -{ - NS_ASSERTION(mPosition, "Should have called next() at least once"); - return mPosition; -} - -nsresult txNodeSetContext::getVariable(PRInt32 aNamespace, nsIAtom* aLName, - txAExprResult*& aResult) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getVariable(aNamespace, aLName, aResult); -} - -MBool txNodeSetContext::isStripSpaceAllowed(const txXPathNode& aNode) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->isStripSpaceAllowed(aNode); -} - -void* txNodeSetContext::getPrivateContext() -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getPrivateContext(); -} - -txResultRecycler* txNodeSetContext::recycler() -{ - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->recycler(); -} - -void txNodeSetContext::receiveError(const nsAString& aMsg, nsresult aRes) -{ - NS_ASSERTION(mInner, "mInner is null!!!"); -#ifdef DEBUG - nsAutoString error(NS_LITERAL_STRING("forwarded error: ")); - error.Append(aMsg); - mInner->receiveError(error, aRes); -#else - mInner->receiveError(aMsg, aRes); -#endif -} diff --git a/extensions/transformiix/source/xpath/txNodeSetContext.h b/extensions/transformiix/source/xpath/txNodeSetContext.h deleted file mode 100644 index 393cb6da194c..000000000000 --- a/extensions/transformiix/source/xpath/txNodeSetContext.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_XPATH_SET_CONTEXT -#define __TX_XPATH_SET_CONTEXT - -#include "txIXPathContext.h" -#include "txNodeSet.h" -#include "nsAutoPtr.h" - -class txNodeSetContext : public txIEvalContext -{ -public: - txNodeSetContext(txNodeSet* aContextNodeSet, txIMatchContext* aContext) - : mContextSet(aContextNodeSet), mPosition(0), mInner(aContext) - { - } - virtual ~txNodeSetContext() - { - } - - // Iteration over the given NodeSet - MBool hasNext() - { - return mPosition < size(); - } - void next() - { - NS_ASSERTION(mPosition < size(), "Out of bounds."); - mPosition++; - } - void setPosition(PRUint32 aPosition) - { - NS_ASSERTION(aPosition > 0 && - aPosition <= size(), "Out of bounds."); - mPosition = aPosition; - } - - TX_DECL_EVAL_CONTEXT; - -protected: - nsRefPtr mContextSet; - PRUint32 mPosition; - txIMatchContext* mInner; -}; - -#endif // __TX_XPATH_SET_CONTEXT diff --git a/extensions/transformiix/source/xpath/txNodeTypeTest.cpp b/extensions/transformiix/source/xpath/txNodeTypeTest.cpp deleted file mode 100644 index 2a8738cb1351..000000000000 --- a/extensions/transformiix/source/xpath/txNodeTypeTest.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "Expr.h" -#include "nsIAtom.h" -#include "txIXPathContext.h" -#include "txXPathTreeWalker.h" - -/* - * Creates a new txNodeTypeTest of the given type - */ -txNodeTypeTest::txNodeTypeTest(NodeType aNodeType) - : mNodeType(aNodeType) -{ -} - -txNodeTypeTest::~txNodeTypeTest() -{ -} - -void txNodeTypeTest::setNodeName(const nsAString& aName) -{ - mNodeName = do_GetAtom(aName); -} - -PRBool txNodeTypeTest::matches(const txXPathNode& aNode, - txIMatchContext* aContext) -{ - switch (mNodeType) { - case COMMENT_TYPE: - { - return txXPathNodeUtils::isComment(aNode); - } - case TEXT_TYPE: - { - return txXPathNodeUtils::isText(aNode) && - !aContext->isStripSpaceAllowed(aNode); - } - case PI_TYPE: - { - return txXPathNodeUtils::isProcessingInstruction(aNode) && - (!mNodeName || - txXPathNodeUtils::localNameEquals(aNode, mNodeName)); - } - case NODE_TYPE: - { - return !txXPathNodeUtils::isText(aNode) || - !aContext->isStripSpaceAllowed(aNode); - } - } - return PR_TRUE; -} - -/* - * Returns the default priority of this txNodeTest - */ -double txNodeTypeTest::getDefaultPriority() -{ - return mNodeName ? 0 : -0.5; -} - -#ifdef TX_TO_STRING -void -txNodeTypeTest::toString(nsAString& aDest) -{ - switch (mNodeType) { - case COMMENT_TYPE: - aDest.Append(NS_LITERAL_STRING("comment()")); - break; - case TEXT_TYPE: - aDest.Append(NS_LITERAL_STRING("text()")); - break; - case PI_TYPE: - aDest.AppendLiteral("processing-instruction("); - if (mNodeName) { - nsAutoString str; - mNodeName->ToString(str); - aDest.Append(PRUnichar('\'')); - aDest.Append(str); - aDest.Append(PRUnichar('\'')); - } - aDest.Append(PRUnichar(')')); - break; - case NODE_TYPE: - aDest.Append(NS_LITERAL_STRING("node()")); - break; - } -} -#endif diff --git a/extensions/transformiix/source/xpath/txResultRecycler.cpp b/extensions/transformiix/source/xpath/txResultRecycler.cpp deleted file mode 100644 index fb608e745f8c..000000000000 --- a/extensions/transformiix/source/xpath/txResultRecycler.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * IBM Corporation - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txResultRecycler.h" -#include "ExprResult.h" -#include "txNodeSet.h" - -txResultRecycler::txResultRecycler() - : mEmptyStringResult(nsnull), - mTrueResult(nsnull), - mFalseResult(nsnull) -{ -} - -txResultRecycler::~txResultRecycler() -{ - txStackIterator stringIter(&mStringResults); - while (stringIter.hasNext()) { - delete NS_STATIC_CAST(StringResult*, stringIter.next()); - } - txStackIterator nodesetIter(&mNodeSetResults); - while (nodesetIter.hasNext()) { - delete NS_STATIC_CAST(txNodeSet*, nodesetIter.next()); - } - txStackIterator numberIter(&mNumberResults); - while (numberIter.hasNext()) { - delete NS_STATIC_CAST(NumberResult*, numberIter.next()); - } - - NS_IF_RELEASE(mEmptyStringResult); - NS_IF_RELEASE(mTrueResult); - NS_IF_RELEASE(mFalseResult); -} - - -nsresult -txResultRecycler::init() -{ - NS_ASSERTION(!mEmptyStringResult && !mTrueResult && !mFalseResult, - "Already inited"); - mEmptyStringResult = new StringResult(nsnull); - NS_ENSURE_TRUE(mEmptyStringResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(mEmptyStringResult); - - mTrueResult = new BooleanResult(PR_TRUE); - NS_ENSURE_TRUE(mTrueResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(mTrueResult); - - mFalseResult = new BooleanResult(PR_FALSE); - NS_ENSURE_TRUE(mFalseResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(mFalseResult); - - return NS_OK; -} - - -void -txResultRecycler::recycle(txAExprResult* aResult) -{ - NS_ASSERTION(aResult->mRefCnt == 0, "In-use txAExprResult recycled"); - nsRefPtr kungFuDeathGrip; - aResult->mRecycler.swap(kungFuDeathGrip); - - nsresult rv = NS_OK; - switch (aResult->getResultType()) { - case txAExprResult::STRING: - { - rv = mStringResults.push(NS_STATIC_CAST(StringResult*, aResult)); - if (NS_FAILED(rv)) { - delete aResult; - } - return; - } - case txAExprResult::NODESET: - { - rv = mNodeSetResults.push(NS_STATIC_CAST(txNodeSet*, aResult)); - if (NS_FAILED(rv)) { - delete aResult; - } - return; - } - case txAExprResult::NUMBER: - { - rv = mNumberResults.push(NS_STATIC_CAST(NumberResult*, aResult)); - if (NS_FAILED(rv)) { - delete aResult; - } - return; - } - default: - { - delete aResult; - } - } -} - -nsresult -txResultRecycler::getStringResult(StringResult** aResult) -{ - if (mStringResults.isEmpty()) { - *aResult = new StringResult(this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - *aResult = NS_STATIC_CAST(StringResult*, mStringResults.pop()); - (*aResult)->mValue.Truncate(); - (*aResult)->mRecycler = this; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -txResultRecycler::getStringResult(const nsAString& aValue, - txAExprResult** aResult) -{ - if (mStringResults.isEmpty()) { - *aResult = new StringResult(aValue, this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - StringResult* strRes = - NS_STATIC_CAST(StringResult*, mStringResults.pop()); - strRes->mValue = aValue; - strRes->mRecycler = this; - *aResult = strRes; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -void -txResultRecycler::getEmptyStringResult(txAExprResult** aResult) -{ - *aResult = mEmptyStringResult; - NS_ADDREF(*aResult); -} - -nsresult -txResultRecycler::getNodeSet(txNodeSet** aResult) -{ - if (mNodeSetResults.isEmpty()) { - *aResult = new txNodeSet(this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop()); - (*aResult)->clear(); - (*aResult)->mRecycler = this; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -txResultRecycler::getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult) -{ - if (mNodeSetResults.isEmpty()) { - *aResult = new txNodeSet(*aNodeSet, this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop()); - (*aResult)->clear(); - (*aResult)->append(*aNodeSet); - (*aResult)->mRecycler = this; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -txResultRecycler::getNodeSet(const txXPathNode& aNode, txAExprResult** aResult) -{ - if (mNodeSetResults.isEmpty()) { - *aResult = new txNodeSet(aNode, this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - txNodeSet* nodes = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop()); - nodes->clear(); - nodes->append(aNode); - nodes->mRecycler = this; - *aResult = nodes; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -txResultRecycler::getNodeSet(const txXPathNode& aNode, txNodeSet** aResult) -{ - if (mNodeSetResults.isEmpty()) { - *aResult = new txNodeSet(aNode, this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop()); - (*aResult)->clear(); - (*aResult)->append(aNode); - (*aResult)->mRecycler = this; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -nsresult -txResultRecycler::getNumberResult(double aValue, txAExprResult** aResult) -{ - if (mNumberResults.isEmpty()) { - *aResult = new NumberResult(aValue, this); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - } - else { - NumberResult* numRes = - NS_STATIC_CAST(NumberResult*, mNumberResults.pop()); - numRes->value = aValue; - numRes->mRecycler = this; - *aResult = numRes; - } - NS_ADDREF(*aResult); - - return NS_OK; -} - -void -txResultRecycler::getBoolResult(PRBool aValue, txAExprResult** aResult) -{ - *aResult = aValue ? mTrueResult : mFalseResult; - NS_ADDREF(*aResult); -} - -nsresult -txResultRecycler::getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult) -{ - if (aNodeSet->mRefCnt > 1) { - return getNodeSet(aNodeSet, aResult); - } - - *aResult = aNodeSet; - NS_ADDREF(*aResult); - - return NS_OK; -} - -void -txAExprResult::Release() -{ - if (--mRefCnt == 0) { - if (mRecycler) { - mRecycler->recycle(this); - } - else { - delete this; - } - } -} diff --git a/extensions/transformiix/source/xpath/txResultRecycler.h b/extensions/transformiix/source/xpath/txResultRecycler.h deleted file mode 100644 index 7d452e5c26e1..000000000000 --- a/extensions/transformiix/source/xpath/txResultRecycler.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * IBM Corporation - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txResultRecycler_h__ -#define txResultRecycler_h__ - -#include "nsCOMPtr.h" -#include "txStack.h" - -class txAExprResult; -class StringResult; -class txNodeSet; -class txXPathNode; -class NumberResult; -class BooleanResult; - -class txResultRecycler -{ -public: - txResultRecycler(); - ~txResultRecycler(); - nsresult init(); - - void AddRef() - { - ++mRefCnt; - } - void Release() - { - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - } - } - - /** - * Returns an txAExprResult to this recycler for reuse. - * @param aResult result to recycle - */ - void recycle(txAExprResult* aResult); - - /** - * Functions to return results that will be fully used by the caller. - * Returns nsnull on out-of-memory and an inited result otherwise. - */ - nsresult getStringResult(StringResult** aResult); - nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult); - nsresult getNodeSet(txNodeSet** aResult); - nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); - nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult); - nsresult getNodeSet(const txXPathNode& aNode, txNodeSet** aResult); - nsresult getNumberResult(double aValue, txAExprResult** aResult); - - /** - * Functions to return a txAExprResult that is shared across several - * clients and must not be modified. Never returns nsnull. - */ - void getEmptyStringResult(txAExprResult** aResult); - void getBoolResult(PRBool aValue, txAExprResult** aResult); - - /** - * Functions that return non-shared resultsobjects - */ - nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); - -private: - nsAutoRefCnt mRefCnt; - txStack mStringResults; - txStack mNodeSetResults; - txStack mNumberResults; - StringResult* mEmptyStringResult; - BooleanResult* mTrueResult; - BooleanResult* mFalseResult; -}; - -#endif //txResultRecycler_h__ diff --git a/extensions/transformiix/source/xpath/txSingleNodeContext.h b/extensions/transformiix/source/xpath/txSingleNodeContext.h deleted file mode 100644 index 02310b866bd2..000000000000 --- a/extensions/transformiix/source/xpath/txSingleNodeContext.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_XPATH_SINGLENODE_CONTEXT -#define __TX_XPATH_SINGLENODE_CONTEXT - -#include "txIXPathContext.h" - -class txSingleNodeContext : public txIEvalContext -{ -public: - txSingleNodeContext(const txXPathNode& aContextNode, - txIMatchContext* aContext) - : mNode(aContextNode), - mInner(aContext) - { - NS_ASSERTION(aContext, "txIMatchContext must be given"); - } - ~txSingleNodeContext() - {} - - nsresult getVariable(PRInt32 aNamespace, nsIAtom* aLName, - txAExprResult*& aResult) - { - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getVariable(aNamespace, aLName, aResult); - } - - MBool isStripSpaceAllowed(const txXPathNode& aNode) - { - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->isStripSpaceAllowed(aNode); - } - - void* getPrivateContext() - { - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->getPrivateContext(); - } - - txResultRecycler* recycler() - { - NS_ASSERTION(mInner, "mInner is null!!!"); - return mInner->recycler(); - } - - void receiveError(const nsAString& aMsg, nsresult aRes) - { - NS_ASSERTION(mInner, "mInner is null!!!"); -#ifdef DEBUG - nsAutoString error(NS_LITERAL_STRING("forwarded error: ")); - error.Append(aMsg); - mInner->receiveError(error, aRes); -#else - mInner->receiveError(aMsg, aRes); -#endif - } - - const txXPathNode& getContextNode() - { - return mNode; - } - - PRUint32 size() - { - return 1; - } - - PRUint32 position() - { - return 1; - } - -private: - const txXPathNode& mNode; - txIMatchContext* mInner; -}; - -#endif // __TX_XPATH_SINGLENODE_CONTEXT diff --git a/extensions/transformiix/source/xpath/txStandaloneXPathTreeWalker.cpp b/extensions/transformiix/source/xpath/txStandaloneXPathTreeWalker.cpp deleted file mode 100644 index 291c173a5e85..000000000000 --- a/extensions/transformiix/source/xpath/txStandaloneXPathTreeWalker.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXPathTreeWalker.h" -#include "nsPrintfCString.h" -#include "nsReadableUtils.h" -#include "nsString.h" -#include "XMLUtils.h" - -txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther) - : mPosition(aOther.mPosition) -{ -} - -txXPathTreeWalker::txXPathTreeWalker(const txXPathNode& aNode) - : mPosition(aNode) -{ -} - -txXPathTreeWalker::~txXPathTreeWalker() -{ -} - -#define INNER mPosition.mInner - -PRBool -txXPathTreeWalker::moveToElementById(const nsAString& aID) -{ - Document* document; - if (INNER->nodeType == Node::DOCUMENT_NODE) { - document = NS_STATIC_CAST(Document*, INNER); - } - else { - document = INNER->ownerDocument; - } - - Element* element = - document->getElementById(aID); - if (!element) { - return PR_FALSE; - } - - INNER = element; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToFirstAttribute() -{ - if (INNER->nodeType != Node::ELEMENT_NODE) { - return PR_FALSE; - } - - Element* element = NS_STATIC_CAST(Element*, INNER); - Attr *attribute = element->getFirstAttribute(); - while (attribute) { - if (attribute->getNamespaceID() != kNameSpaceID_XMLNS) { - INNER = attribute; - - return PR_TRUE; - } - - attribute = attribute->getNextAttribute(); - } - - return PR_FALSE; -} - -PRBool -txXPathTreeWalker::moveToNextAttribute() -{ - // XXX an assertion should be enough here with the current code - if (INNER->nodeType != Node::ATTRIBUTE_NODE) { - return PR_FALSE; - } - - Element* element = NS_STATIC_CAST(Element*, INNER->getXPathParent()); - Attr *attribute = element->getFirstAttribute(); - while (attribute != INNER) { - attribute = attribute->getNextAttribute(); - } - NS_ASSERTION(attribute, "Attr not attribute of it's owner?"); - - attribute = attribute->getNextAttribute(); - - while (attribute) { - if (attribute->getNamespaceID() != kNameSpaceID_XMLNS) { - INNER = attribute; - - return PR_TRUE; - } - - attribute = attribute->getNextAttribute(); - } - - return PR_FALSE; -} - -PRBool -txXPathTreeWalker::moveToFirstChild() -{ - if (!INNER->firstChild) { - return PR_FALSE; - } - - INNER = INNER->firstChild; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToLastChild() -{ - if (!INNER->lastChild) { - return PR_FALSE; - } - - INNER = INNER->lastChild; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToNextSibling() -{ - if (!INNER->nextSibling) { - return PR_FALSE; - } - - INNER = INNER->nextSibling; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToPreviousSibling() -{ - if (!INNER->previousSibling) { - return PR_FALSE; - } - - INNER = INNER->previousSibling; - - return PR_TRUE; -} - -PRBool -txXPathTreeWalker::moveToParent() -{ - if (INNER->nodeType == Node::ATTRIBUTE_NODE) { - INNER = NS_STATIC_CAST(NodeDefinition*, INNER->getXPathParent()); - return PR_TRUE; - } - - if (INNER->nodeType == Node::DOCUMENT_NODE) { - return PR_FALSE; - } - - NS_ASSERTION(INNER->parentNode, "orphaned node shouldn't happen"); - - INNER = INNER->parentNode; - - return PR_TRUE; -} - -txXPathNode::txXPathNode(const txXPathNode& aNode) - : mInner(aNode.mInner) -{ -} - -PRBool -txXPathNode::operator==(const txXPathNode& aNode) const -{ - return (mInner == aNode.mInner); -} - -/* static */ -PRBool -txXPathNodeUtils::getAttr(const txXPathNode& aNode, nsIAtom* aLocalName, - PRInt32 aNSID, nsAString& aValue) -{ - if (aNode.mInner->getNodeType() != Node::ELEMENT_NODE) { - return PR_FALSE; - } - - Element* elem = NS_STATIC_CAST(Element*, aNode.mInner); - return elem->getAttr(aLocalName, aNSID, aValue); -} - -/* static */ -already_AddRefed -txXPathNodeUtils::getLocalName(const txXPathNode& aNode) -{ - nsIAtom* localName; - return aNode.mInner->getLocalName(&localName) ? localName : nsnull; -} - -/* static */ -void -txXPathNodeUtils::getLocalName(const txXPathNode& aNode, nsAString& aLocalName) -{ - nsCOMPtr localName; - PRBool hasName = aNode.mInner->getLocalName(getter_AddRefs(localName)); - if (hasName && localName) { - localName->ToString(aLocalName); - } -} - -/* static */ -void -txXPathNodeUtils::getNodeName(const txXPathNode& aNode, nsAString& aName) -{ - aNode.mInner->getNodeName(aName); -} - -/* static */ -PRInt32 -txXPathNodeUtils::getNamespaceID(const txXPathNode& aNode) -{ - return aNode.mInner->getNamespaceID(); -} - -/* static */ -void -txXPathNodeUtils::getNamespaceURI(const txXPathNode& aNode, nsAString& aURI) -{ - aNode.mInner->getNamespaceURI(aURI); -} - -/* static */ -PRUint16 -txXPathNodeUtils::getNodeType(const txXPathNode& aNode) -{ - return aNode.mInner->getNodeType(); -} - -/* static */ -void -txXPathNodeUtils::appendNodeValueHelper(NodeDefinition* aNode, - nsAString& aResult) -{ - - NodeDefinition* child = NS_STATIC_CAST(NodeDefinition*, - aNode->getFirstChild()); - while (child) { - switch (child->getNodeType()) { - case Node::TEXT_NODE: - { - aResult.Append(child->nodeValue); - } - case Node::ELEMENT_NODE: - { - appendNodeValueHelper(child, aResult); - } - } - child = NS_STATIC_CAST(NodeDefinition*, child->getNextSibling()); - } -} - -/* static */ -void -txXPathNodeUtils::appendNodeValue(const txXPathNode& aNode, nsAString& aResult) -{ - unsigned short type = aNode.mInner->getNodeType(); - if (type == Node::ATTRIBUTE_NODE || - type == Node::COMMENT_NODE || - type == Node::PROCESSING_INSTRUCTION_NODE || - type == Node::TEXT_NODE) { - aResult.Append(aNode.mInner->nodeValue); - - return; - } - - NS_ASSERTION(type == Node::ELEMENT_NODE || type == Node::DOCUMENT_NODE, - "Element or Document expected"); - - appendNodeValueHelper(aNode.mInner, aResult); -} - -/* static */ -PRBool -txXPathNodeUtils::isWhitespace(const txXPathNode& aNode) -{ - NS_ASSERTION(aNode.mInner->nodeType == Node::TEXT_NODE, "Wrong type!"); - - return XMLUtils::isWhitespace(aNode.mInner->nodeValue); -} - -/* static */ -txXPathNode* -txXPathNodeUtils::getDocument(const txXPathNode& aNode) -{ - if (aNode.mInner->nodeType == Node::DOCUMENT_NODE) { - return new txXPathNode(aNode); - } - - return new txXPathNode(aNode.mInner->ownerDocument); -} - -/* static */ -txXPathNode* -txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) -{ - return getDocument(aNode); -} - -#ifndef HAVE_64BIT_OS -#define kFmtSize 13 -const char gPrintfFmt[] = "id0x%08p"; -#else -#define kFmtSize 21 -const char gPrintfFmt[] = "id0x%016p"; -#endif - -/* static */ -nsresult -txXPathNodeUtils::getXSLTId(const txXPathNode& aNode, - nsAString& aResult) -{ - CopyASCIItoUCS2(nsPrintfCString(kFmtSize, gPrintfFmt, aNode.mInner), - aResult); - - return NS_OK; -} - -/* static */ -void -txXPathNodeUtils::getBaseURI(const txXPathNode& aNode, nsAString& aURI) -{ - aNode.mInner->getBaseURI(aURI); -} - -/* static */ -PRIntn -txXPathNodeUtils::comparePosition(const txXPathNode& aNode, - const txXPathNode& aOtherNode) -{ - // First check for equal nodes. - if (aNode == aOtherNode) { - return 0; - } - return aNode.mInner->compareDocumentPosition(aOtherNode.mInner); -} - -/* static */ -txXPathNode* -txXPathNativeNode::createXPathNode(Node* aNode) -{ - if (aNode != nsnull) { - return new txXPathNode(NS_STATIC_CAST(NodeDefinition*, aNode)); - } - return nsnull; -} - -/* static */ -nsresult -txXPathNativeNode::getElement(const txXPathNode& aNode, Element** aResult) -{ - if (aNode.mInner->getNodeType() != Node::ELEMENT_NODE) { - return NS_ERROR_FAILURE; - } - - *aResult = NS_STATIC_CAST(Element*, aNode.mInner); - - return NS_OK; - -} - -/* static */ -nsresult -txXPathNativeNode::getDocument(const txXPathNode& aNode, Document** aResult) -{ - if (aNode.mInner->getNodeType() != Node::DOCUMENT_NODE) { - return NS_ERROR_FAILURE; - } - - *aResult = NS_STATIC_CAST(Document*, aNode.mInner); - - return NS_OK; -} diff --git a/extensions/transformiix/source/xpath/txXPathAtomList.h b/extensions/transformiix/source/xpath/txXPathAtomList.h deleted file mode 100644 index 3b76c640db47..000000000000 --- a/extensions/transformiix/source/xpath/txXPathAtomList.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// OUTPUT_CLASS=txXPathAtoms -// MACRO_NAME=TX_ATOM - -TX_ATOM(_and, "and") -TX_ATOM(_asterix, "*") -TX_ATOM(boolean, "boolean") -TX_ATOM(ceiling, "ceiling") -TX_ATOM(comment, "comment") -TX_ATOM(concat, "concat") -TX_ATOM(contains, "contains") -TX_ATOM(count, "count") -TX_ATOM(div, "div") -TX_ATOM(_false, "false") -TX_ATOM(floor, "floor") -TX_ATOM(id, "id") -TX_ATOM(lang, "lang") -TX_ATOM(last, "last") -TX_ATOM(localName, "local-name") -TX_ATOM(mod, "mod") -TX_ATOM(name, "name") -TX_ATOM(namespaceUri, "namespace-uri") -TX_ATOM(node, "node") -TX_ATOM(normalizeSpace, "normalize-space") -TX_ATOM(_not, "not") -TX_ATOM(number, "number") -TX_ATOM(_or, "or") -TX_ATOM(position, "position") -TX_ATOM(processingInstruction, "processing-instruction") -TX_ATOM(round, "round") -TX_ATOM(startsWith, "starts-with") -TX_ATOM(string, "string") -TX_ATOM(stringLength, "string-length") -TX_ATOM(substring, "substring") -TX_ATOM(substringAfter, "substring-after") -TX_ATOM(substringBefore, "substring-before") -TX_ATOM(sum, "sum") -TX_ATOM(text, "text") -TX_ATOM(translate, "translate") -TX_ATOM(_true, "true") - -// XPath Axes -TX_ATOM(ancestor, "ancestor") -TX_ATOM(ancestorOrSelf, "ancestor-or-self") -TX_ATOM(attribute, "attribute") -TX_ATOM(child, "child") -TX_ATOM(descendant, "descendant") -TX_ATOM(descendantOrSelf, "descendant-or-self") -TX_ATOM(following, "following") -TX_ATOM(followingSibling, "following-sibling") -TX_ATOM(_namespace, "namespace") -TX_ATOM(parent, "parent") -TX_ATOM(preceding, "preceding") -TX_ATOM(precedingSibling, "preceding-sibling") -TX_ATOM(self, "self") - -#ifndef DISABLE_XFORMS_HOOKS -// XForms XPath Extensions -TX_ATOM(avg, "avg") -TX_ATOM(booleanFromString, "boolean-from-string") -TX_ATOM(countNonEmpty, "count-non-empty") -TX_ATOM(daysFromDate, "days-from-date") -TX_ATOM(ifFunc, "if") -TX_ATOM(index, "index") -TX_ATOM(instance, "instance") -TX_ATOM(min, "min") -TX_ATOM(max, "max") -TX_ATOM(months, "months") -TX_ATOM(now, "now") -TX_ATOM(property, "property") -TX_ATOM(seconds, "seconds") -TX_ATOM(secondsFromDateTime, "seconds-from-dateTime") -#endif diff --git a/extensions/transformiix/source/xpath/txXPathNode.h b/extensions/transformiix/source/xpath/txXPathNode.h deleted file mode 100644 index cbc7e2141026..000000000000 --- a/extensions/transformiix/source/xpath/txXPathNode.h +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txXPathNode_h__ -#define txXPathNode_h__ - -#ifdef TX_EXE -#include "dom.h" -#else -#include "nsAutoPtr.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIDOMNode.h" -#include "nsINameSpaceManager.h" - -extern nsINameSpaceManager* gTxNameSpaceManager; -#endif - -#ifdef TX_EXE -typedef Node txXPathNodeType; -#else -typedef nsIDOMNode txXPathNodeType; -#endif - -class txXPathNode -{ -public: - PRBool operator==(const txXPathNode& aNode) const; - PRBool operator!=(const txXPathNode& aNode) const - { - return !(*this == aNode); - } - -private: - friend class txNodeSet; - friend class txXPathNativeNode; - friend class txXPathNodeUtils; - friend class txXPathTreeWalker; - -#ifdef TX_EXE - txXPathNode(NodeDefinition* aNode) : mInner(aNode) - { - } - txXPathNode(const txXPathNode& aNode); - - NodeDefinition* mInner; -#else - txXPathNode(nsIDocument* aDocument) : mDocument(aDocument), - mIndex(eDocument) - { - } - txXPathNode(nsIContent* aContent, PRUint32 aIndex = eContent) - : mContent(aContent), - mIndex(aIndex) - { - } - txXPathNode(const txXPathNode& aNode); - - PRBool isDocument() const - { - return mIndex == eDocument; - }; - PRBool isContent() const - { - return mIndex == eContent; - }; - PRBool isAttribute() const - { - return mIndex != eDocument && mIndex != eContent; - }; - - enum PositionType - { - eDocument = (PRUint32)-2, - eContent = (PRUint32)-1 - }; - union { - nsIDocument* mDocument; // eDocument - nsIContent* mContent; // eContent, eAttribute - }; - PRUint32 mIndex; -#endif -}; - -class txNamespaceManager -{ -public: - static PRInt32 getNamespaceID(const nsAString& aNamespaceURI); - static nsresult getNamespaceURI(const PRInt32 aID, nsAString& aResult); -}; - -/* static */ -inline PRInt32 -txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI) -{ -#ifdef TX_EXE - return txStandaloneNamespaceManager::getNamespaceID(aNamespaceURI); -#else - NS_ASSERTION(gTxNameSpaceManager, "No namespace manager"); - - PRInt32 namespaceID = kNameSpaceID_Unknown; - gTxNameSpaceManager->RegisterNameSpace(aNamespaceURI, namespaceID); - return namespaceID; -#endif -} - -/* static */ -inline nsresult -txNamespaceManager::getNamespaceURI(const PRInt32 aID, nsAString& aResult) -{ -#ifdef TX_EXE - return txStandaloneNamespaceManager::getNamespaceURI(aID, aResult); -#else - NS_ASSERTION(gTxNameSpaceManager, "No namespace manager"); - - return gTxNameSpaceManager->GetNameSpaceURI(aID, aResult); -#endif -} - -#endif /* txXPathNode_h__ */ diff --git a/extensions/transformiix/source/xpath/txXPathTreeWalker.h b/extensions/transformiix/source/xpath/txXPathTreeWalker.h deleted file mode 100644 index 63c8e4d24cff..000000000000 --- a/extensions/transformiix/source/xpath/txXPathTreeWalker.h +++ /dev/null @@ -1,348 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txXPathTreeWalker_h__ -#define txXPathTreeWalker_h__ - -#include "txCore.h" -#include "txXPathNode.h" - -class nsIAtom; - -#ifndef TX_EXE -#include "nsINodeInfo.h" -#include "nsVoidArray.h" - -class txUint32Array : public nsVoidArray -{ -public: - PRBool AppendValue(PRUint32 aValue) - { - return InsertElementAt(NS_INT32_TO_PTR(aValue), Count()); - } - PRBool RemoveValueAt(PRUint32 aIndex) - { - return RemoveElementsAt(aIndex, 1); - } - PRInt32 ValueAt(PRUint32 aIndex) const - { - return NS_PTR_TO_INT32(ElementAt(aIndex)); - } -}; - -class nsIDOMDocument; -#endif - -class txXPathTreeWalker -{ -public: - txXPathTreeWalker(const txXPathTreeWalker& aOther); - explicit txXPathTreeWalker(const txXPathNode& aNode); - ~txXPathTreeWalker(); - - PRBool getAttr(nsIAtom* aLocalName, PRInt32 aNSID, nsAString& aValue) const; - PRInt32 getNamespaceID() const; - PRUint16 getNodeType() const; - void appendNodeValue(nsAString& aResult) const; - void getNodeName(nsAString& aName) const; - - void moveTo(const txXPathTreeWalker& aWalker); - - PRBool moveToParent(); - PRBool moveToElementById(const nsAString& aID); - PRBool moveToFirstAttribute(); - PRBool moveToNextAttribute(); - PRBool moveToFirstChild(); - PRBool moveToLastChild(); - PRBool moveToNextSibling(); - PRBool moveToPreviousSibling(); - - PRBool isOnNode(const txXPathNode& aNode) const; - - const txXPathNode& getCurrentPosition() const; - -private: - txXPathNode mPosition; - -#ifndef TX_EXE - PRBool moveToValidAttribute(PRUint32 aStartIndex); - PRBool moveToSibling(PRInt32 aDir); - - PRUint32 mCurrentIndex; - txUint32Array mDescendants; -#endif -}; - -class txXPathNodeUtils -{ -public: - static PRBool getAttr(const txXPathNode& aNode, nsIAtom* aLocalName, - PRInt32 aNSID, nsAString& aValue); - static already_AddRefed getLocalName(const txXPathNode& aNode); - static void getLocalName(const txXPathNode& aNode, nsAString& aLocalName); - static void getNodeName(const txXPathNode& aNode, - nsAString& aName); - static PRInt32 getNamespaceID(const txXPathNode& aNode); - static void getNamespaceURI(const txXPathNode& aNode, nsAString& aURI); - static PRUint16 getNodeType(const txXPathNode& aNode); - static void appendNodeValue(const txXPathNode& aNode, nsAString& aResult); - static PRBool isWhitespace(const txXPathNode& aNode); - static txXPathNode* getDocument(const txXPathNode& aNode); - static txXPathNode* getOwnerDocument(const txXPathNode& aNode); - static PRInt32 getUniqueIdentifier(const txXPathNode& aNode); - static nsresult getXSLTId(const txXPathNode& aNode, nsAString& aResult); - static void release(txXPathNode* aNode); - static void getBaseURI(const txXPathNode& aNode, nsAString& aURI); - static PRIntn comparePosition(const txXPathNode& aNode, - const txXPathNode& aOtherNode); - static PRBool localNameEquals(const txXPathNode& aNode, - nsIAtom* aLocalName); - static PRBool isRoot(const txXPathNode& aNode); - static PRBool isElement(const txXPathNode& aNode); - static PRBool isAttribute(const txXPathNode& aNode); - static PRBool isProcessingInstruction(const txXPathNode& aNode); - static PRBool isComment(const txXPathNode& aNode); - static PRBool isText(const txXPathNode& aNode); - -#ifdef TX_EXE -private: - static void appendNodeValueHelper(NodeDefinition* aNode, nsAString& aResult); -#endif -}; - -#ifdef TX_EXE -class txXPathNativeNode -{ -public: - static txXPathNode* createXPathNode(Node* aNode); - static nsresult getElement(const txXPathNode& aNode, Element** aResult); - static nsresult getDocument(const txXPathNode& aNode, Document** aResult); -}; -#else -class txXPathNativeNode -{ -public: - static txXPathNode* createXPathNode(nsIDOMNode* aNode); - static txXPathNode* createXPathNode(nsIDOMDocument* aDocument); - static nsresult getNode(const txXPathNode& aNode, nsIDOMNode** aResult); - static nsIContent* getContent(const txXPathNode& aNode); - static nsIDocument* getDocument(const txXPathNode& aNode); - static void addRef(const txXPathNode& aNode) - { - // Hopefully it's ok to access mContent through mDocument. - NS_ADDREF(aNode.mDocument); - } - static void release(const txXPathNode& aNode) - { - // Hopefully it's ok to access mContent through mDocument. - nsISupports *node = aNode.mDocument; - NS_RELEASE(node); - } -}; - -#endif - -inline const txXPathNode& -txXPathTreeWalker::getCurrentPosition() const -{ - return mPosition; -} - -inline PRBool -txXPathTreeWalker::getAttr(nsIAtom* aLocalName, PRInt32 aNSID, - nsAString& aValue) const -{ - return txXPathNodeUtils::getAttr(mPosition, aLocalName, aNSID, aValue); -} - -inline PRInt32 -txXPathTreeWalker::getNamespaceID() const -{ - return txXPathNodeUtils::getNamespaceID(mPosition); -} - -inline void -txXPathTreeWalker::appendNodeValue(nsAString& aResult) const -{ - txXPathNodeUtils::appendNodeValue(mPosition, aResult); -} - -inline void -txXPathTreeWalker::getNodeName(nsAString& aName) const -{ - txXPathNodeUtils::getNodeName(mPosition, aName); -} - -inline void -txXPathTreeWalker::moveTo(const txXPathTreeWalker& aWalker) -{ -#ifdef TX_EXE - mPosition.mInner = aWalker.mPosition.mInner; -#else - mPosition.mIndex = aWalker.mPosition.mIndex; - // Hopefully it's ok to access mContent through mDocument. - mPosition.mDocument = aWalker.mPosition.mDocument; - mCurrentIndex = aWalker.mCurrentIndex; - mDescendants.Clear(); -#endif -} - -inline PRBool -txXPathTreeWalker::isOnNode(const txXPathNode& aNode) const -{ - return (mPosition == aNode); -} - -/* static */ -inline PRInt32 -txXPathNodeUtils::getUniqueIdentifier(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return NS_PTR_TO_INT32(aNode.mInner); -#else - NS_PRECONDITION(aNode.mIndex == txXPathNode::eDocument, - "Only implemented for documents."); - return NS_PTR_TO_INT32(aNode.mDocument); -#endif -} - -/* static */ -inline void -txXPathNodeUtils::release(txXPathNode* aNode) -{ -#ifdef TX_EXE - delete aNode->mInner; -#else - NS_RELEASE(aNode->mDocument); -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::localNameEquals(const txXPathNode& aNode, - nsIAtom* aLocalName) -{ -#ifdef TX_EXE - nsCOMPtr localName; - aNode.mInner->getLocalName(getter_AddRefs(localName)); - - return localName == aLocalName; -#else - if (aNode.isContent() && - aNode.mContent->IsContentOfType(nsIContent::eELEMENT)) { - return aNode.mContent->NodeInfo()->Equals(aLocalName); - } - - nsCOMPtr localName = txXPathNodeUtils::getLocalName(aNode); - - return localName == aLocalName; -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::isRoot(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::DOCUMENT_NODE; -#else - return aNode.isDocument(); -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::isElement(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::ELEMENT_NODE; -#else - return aNode.isContent() && - aNode.mContent->IsContentOfType(nsIContent::eELEMENT); -#endif -} - - -/* static */ -inline PRBool -txXPathNodeUtils::isAttribute(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::ATTRIBUTE_NODE; -#else - return aNode.isAttribute(); -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::isProcessingInstruction(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE; -#else - return aNode.isContent() && - aNode.mContent->IsContentOfType(nsIContent::ePROCESSING_INSTRUCTION); -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::isComment(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::COMMENT_NODE; -#else - return aNode.isContent() && - aNode.mContent->IsContentOfType(nsIContent::eCOMMENT); -#endif -} - -/* static */ -inline PRBool -txXPathNodeUtils::isText(const txXPathNode& aNode) -{ -#ifdef TX_EXE - return aNode.mInner->getNodeType() == Node::TEXT_NODE; -#else - return aNode.isContent() && - aNode.mContent->IsContentOfType(nsIContent::eTEXT); -#endif -} - -#endif /* txXPathTreeWalker_h__ */ diff --git a/extensions/transformiix/source/xslt/.cvsignore b/extensions/transformiix/source/xslt/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xslt/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xslt/Makefile.in b/extensions/transformiix/source/xslt/Makefile.in deleted file mode 100644 index 677cff56db49..000000000000 --- a/extensions/transformiix/source/xslt/Makefile.in +++ /dev/null @@ -1,122 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -DIRS = functions util - -MODULE = transformiix -LIBRARY_NAME = txxslt_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += dom \ - content \ - widget \ - necko \ - unicharutil \ - xpconnect \ - js \ - htmlparser \ - webshell \ - docshell \ - layout \ - uconv \ - caps \ - windowwatcher \ - mimetype \ - intl \ - htmlparser \ - $(NULL) -else -REQUIRES += expat \ - $(NULL) -endif - -CPPSRCS = \ - txBufferingHandler.cpp \ - txExecutionState.cpp \ - txInstructions.cpp \ - txOutputFormat.cpp \ - txRtfHandler.cpp \ - txStylesheet.cpp \ - txStylesheetCompileHandlers.cpp \ - txStylesheetCompiler.cpp \ - txTextHandler.cpp \ - txToplevelItems.cpp \ - txXSLTNumber.cpp \ - txXSLTNumberCounters.cpp \ - txXSLTPatterns.cpp \ - txXSLTProcessor.cpp \ - txPatternParser.cpp \ - txUnknownHandler.cpp - -ifdef TX_EXE -CPPSRCS += txHTMLOutput.cpp \ - txStandaloneXSLTProcessor.cpp \ - txStandaloneStylesheetCompiler.cpp \ - txTextOutput.cpp \ - txXMLOutput.cpp -else -CPPSRCS += txMozillaStylesheetCompiler.cpp \ - txMozillaTextOutput.cpp \ - txMozillaXMLOutput.cpp \ - txMozillaXSLTProcessor.cpp -endif - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir) -I$(srcdir)/../base \ - -I$(srcdir)/../xml -I$(srcdir)/../xml/dom \ - -I$(srcdir)/../xml/parser \ - -I$(srcdir)/../xpath -I$(srcdir)/util -I$(srcdir)/functions -ifdef TX_EXE -DEFINES += -DXML_DTD -DXML_UNICODE -endif diff --git a/extensions/transformiix/source/xslt/functions/.cvsignore b/extensions/transformiix/source/xslt/functions/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xslt/functions/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp deleted file mode 100644 index ae6778a0bc61..000000000000 --- a/extensions/transformiix/source/xslt/functions/CurrentFunctionCall.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "txAtoms.h" -#include "XSLTFunctions.h" -#include "txExecutionState.h" - -/* - Implementation of XSLT 1.0 extension function: current -*/ - -/** - * Creates a new current function call -**/ -CurrentFunctionCall::CurrentFunctionCall() -{ -} - -/* - * Evaluates this Expr - * - * @return NodeSet containing the context node used for the complete - * Expr or Pattern. - */ -nsresult -CurrentFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - *aResult = nsnull; - - if (!requireParams(0, 0, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - txExecutionState* es = - NS_STATIC_CAST(txExecutionState*, aContext->getPrivateContext()); - if (!es) { - NS_ASSERTION(0, - "called xslt extension function \"current\" with wrong context"); - return NS_ERROR_UNEXPECTED; - } - return aContext->recycler()->getNodeSet( - es->getEvalContext()->getContextNode(), aResult); -} - -#ifdef TX_TO_STRING -nsresult -CurrentFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::current; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/DocumentFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/DocumentFunctionCall.cpp deleted file mode 100644 index 673214d84fbd..000000000000 --- a/extensions/transformiix/source/xslt/functions/DocumentFunctionCall.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * The MITRE Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Olivier Gerardin (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * DocumentFunctionCall - * A representation of the XSLT additional function: document() - */ - -#include "txAtoms.h" -#include "txIXPathContext.h" -#include "XSLTFunctions.h" -#include "txExecutionState.h" -#include "txURIUtils.h" - -/* - * Creates a new DocumentFunctionCall. - */ -DocumentFunctionCall::DocumentFunctionCall(const nsAString& aBaseURI) - : mBaseURI(aBaseURI) -{ -} - -static void -retrieveNode(txExecutionState* aExecutionState, const nsAString& aUri, - const nsAString& aBaseUri, txNodeSet* aNodeSet) -{ - nsAutoString absUrl; - URIUtils::resolveHref(aUri, aBaseUri, absUrl); - - PRInt32 hash = absUrl.RFindChar(PRUnichar('#')); - PRUint32 urlEnd, fragStart, fragEnd; - if (hash == kNotFound) { - urlEnd = absUrl.Length(); - fragStart = 0; - fragEnd = 0; - } - else { - urlEnd = hash; - fragStart = hash + 1; - fragEnd = absUrl.Length(); - } - - nsDependentSubstring docUrl(absUrl, 0, urlEnd); - nsDependentSubstring frag(absUrl, fragStart, fragEnd); - - const txXPathNode* loadNode = aExecutionState->retrieveDocument(docUrl); - if (loadNode) { - if (frag.IsEmpty()) { - aNodeSet->add(*loadNode); - } - else { - txXPathTreeWalker walker(*loadNode); - if (walker.moveToElementById(frag)) { - aNodeSet->add(walker.getCurrentPosition()); - } - } - } -} - -/* - * Evaluates this Expr based on the given context node and processor state - * NOTE: the implementation is incomplete since it does not make use of the - * second argument (base URI) - * @param context the context node for evaluation of this Expr - * @return the result of the evaluation - */ -nsresult -DocumentFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - txExecutionState* es = - NS_STATIC_CAST(txExecutionState*, aContext->getPrivateContext()); - - nsRefPtr nodeSet; - nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodeSet)); - NS_ENSURE_SUCCESS(rv, rv); - - // document(object, node-set?) - if (!requireParams(1, 2, aContext)) { - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - txListIterator iter(¶ms); - Expr* param1 = (Expr*)iter.next(); - nsRefPtr exprResult1; - rv = param1->evaluate(aContext, getter_AddRefs(exprResult1)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString baseURI; - MBool baseURISet = MB_FALSE; - - if (iter.hasNext()) { - // We have 2 arguments, get baseURI from the first node - // in the resulting nodeset - nsRefPtr nodeSet2; - rv = evaluateToNodeSet(NS_STATIC_CAST(Expr*, iter.next()), - aContext, getter_AddRefs(nodeSet2)); - NS_ENSURE_SUCCESS(rv, rv); - - // Make this true, even if nodeSet2 is empty. For relative URLs, - // we'll fail to load the document with an empty base URI, and for - // absolute URLs, the base URI doesn't matter - baseURISet = MB_TRUE; - - if (!nodeSet2->isEmpty()) { - txXPathNodeUtils::getBaseURI(nodeSet2->get(0), baseURI); - } - } - - if (exprResult1->getResultType() == txAExprResult::NODESET) { - // The first argument is a NodeSet, iterate on its nodes - txNodeSet* nodeSet1 = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprResult1)); - PRInt32 i; - for (i = 0; i < nodeSet1->size(); ++i) { - const txXPathNode& node = nodeSet1->get(i); - nsAutoString uriStr; - txXPathNodeUtils::appendNodeValue(node, uriStr); - if (!baseURISet) { - // if the second argument wasn't specified, use - // the baseUri of node itself - txXPathNodeUtils::getBaseURI(node, baseURI); - } - retrieveNode(es, uriStr, baseURI, nodeSet); - } - - NS_ADDREF(*aResult = nodeSet); - - return NS_OK; - } - - // The first argument is not a NodeSet - nsAutoString uriStr; - exprResult1->stringValue(uriStr); - const nsAString* base = baseURISet ? &baseURI : &mBaseURI; - retrieveNode(es, uriStr, *base, nodeSet); - - NS_ADDREF(*aResult = nodeSet); - - return NS_OK; -} - -#ifdef TX_TO_STRING -nsresult -DocumentFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::document; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/ElementAvailableFnCall.cpp b/extensions/transformiix/source/xslt/functions/ElementAvailableFnCall.cpp deleted file mode 100644 index c27d70330222..000000000000 --- a/extensions/transformiix/source/xslt/functions/ElementAvailableFnCall.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txIXPathContext.h" -#include "txAtoms.h" -#include "txError.h" -#include "XMLUtils.h" -#include "XSLTFunctions.h" -#include "ExprResult.h" -#include "txNamespaceMap.h" - -/* - Implementation of XSLT 1.0 extension function: element-available -*/ - -/** - * Creates a new element-available function call - * aNode is the Element in the stylesheet containing the - * Expr and is used for namespaceID resolution -**/ -ElementAvailableFunctionCall::ElementAvailableFunctionCall(txNamespaceMap* aMappings) - : mMappings(aMappings) -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param cs the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see FunctionCall.h -**/ -nsresult -ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - if (!requireParams(1, 1, aContext)) { - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - txListIterator iter(¶ms); - Expr* param = (Expr*) iter.next(); - - nsRefPtr exprResult; - nsresult rv = param->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString property; - exprResult->stringValue(property); - txExpandedName qname; - rv = qname.init(property, mMappings, MB_TRUE); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool val = qname.mNamespaceID == kNameSpaceID_XSLT && - (qname.mLocalName == txXSLTAtoms::applyImports || - qname.mLocalName == txXSLTAtoms::applyTemplates || - qname.mLocalName == txXSLTAtoms::attribute || - qname.mLocalName == txXSLTAtoms::attributeSet || - qname.mLocalName == txXSLTAtoms::callTemplate || - qname.mLocalName == txXSLTAtoms::choose || - qname.mLocalName == txXSLTAtoms::comment || - qname.mLocalName == txXSLTAtoms::copy || - qname.mLocalName == txXSLTAtoms::copyOf || - qname.mLocalName == txXSLTAtoms::decimalFormat || - qname.mLocalName == txXSLTAtoms::element || - qname.mLocalName == txXSLTAtoms::fallback || - qname.mLocalName == txXSLTAtoms::forEach || - qname.mLocalName == txXSLTAtoms::_if || - qname.mLocalName == txXSLTAtoms::import || - qname.mLocalName == txXSLTAtoms::include || - qname.mLocalName == txXSLTAtoms::key || - qname.mLocalName == txXSLTAtoms::message || - //qname.mLocalName == txXSLTAtoms::namespaceAlias || - qname.mLocalName == txXSLTAtoms::number || - qname.mLocalName == txXSLTAtoms::otherwise || - qname.mLocalName == txXSLTAtoms::output || - qname.mLocalName == txXSLTAtoms::param || - qname.mLocalName == txXSLTAtoms::preserveSpace || - qname.mLocalName == txXSLTAtoms::processingInstruction || - qname.mLocalName == txXSLTAtoms::sort || - qname.mLocalName == txXSLTAtoms::stripSpace || - qname.mLocalName == txXSLTAtoms::stylesheet || - qname.mLocalName == txXSLTAtoms::_template || - qname.mLocalName == txXSLTAtoms::text || - qname.mLocalName == txXSLTAtoms::transform || - qname.mLocalName == txXSLTAtoms::valueOf || - qname.mLocalName == txXSLTAtoms::variable || - qname.mLocalName == txXSLTAtoms::when || - qname.mLocalName == txXSLTAtoms::withParam); - - aContext->recycler()->getBoolResult(val, aResult); - - return NS_OK; -} - -#ifdef TX_TO_STRING -nsresult -ElementAvailableFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::elementAvailable; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/FunctionAvailableFnCall.cpp b/extensions/transformiix/source/xslt/functions/FunctionAvailableFnCall.cpp deleted file mode 100644 index 2187c461b083..000000000000 --- a/extensions/transformiix/source/xslt/functions/FunctionAvailableFnCall.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txIXPathContext.h" -#include "ExprResult.h" -#include "txAtoms.h" -#include "txError.h" -#include "XMLUtils.h" -#include "XSLTFunctions.h" -#include "txNamespaceMap.h" - -/* - Implementation of XSLT 1.0 extension function: function-available -*/ - -/** - * Creates a new function-available function call -**/ -FunctionAvailableFunctionCall::FunctionAvailableFunctionCall(txNamespaceMap* aMappings) - : mMappings(aMappings) -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param cs the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see FunctionCall.h -**/ -nsresult -FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - if (!requireParams(1, 1, aContext)) { - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - txListIterator iter(¶ms); - Expr* param = (Expr*)iter.next(); - nsRefPtr exprResult; - nsresult rv = param->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString property; - exprResult->stringValue(property); - txExpandedName qname; - rv = qname.init(property, mMappings, MB_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool val = qname.mNamespaceID == kNameSpaceID_None && - (qname.mLocalName == txXPathAtoms::boolean || - qname.mLocalName == txXPathAtoms::ceiling || - qname.mLocalName == txXPathAtoms::concat || - qname.mLocalName == txXPathAtoms::contains || - qname.mLocalName == txXPathAtoms::count || - qname.mLocalName == txXPathAtoms::_false || - qname.mLocalName == txXPathAtoms::floor || - qname.mLocalName == txXPathAtoms::id || - qname.mLocalName == txXPathAtoms::lang || - qname.mLocalName == txXPathAtoms::last || - qname.mLocalName == txXPathAtoms::localName || - qname.mLocalName == txXPathAtoms::name || - qname.mLocalName == txXPathAtoms::namespaceUri || - qname.mLocalName == txXPathAtoms::normalizeSpace || - qname.mLocalName == txXPathAtoms::_not || - qname.mLocalName == txXPathAtoms::number || - qname.mLocalName == txXPathAtoms::position || - qname.mLocalName == txXPathAtoms::round || - qname.mLocalName == txXPathAtoms::startsWith || - qname.mLocalName == txXPathAtoms::string || - qname.mLocalName == txXPathAtoms::stringLength || - qname.mLocalName == txXPathAtoms::substring || - qname.mLocalName == txXPathAtoms::substringAfter || - qname.mLocalName == txXPathAtoms::substringBefore || - qname.mLocalName == txXPathAtoms::sum || - qname.mLocalName == txXPathAtoms::translate || - qname.mLocalName == txXPathAtoms::_true || - qname.mLocalName == txXSLTAtoms::current || - qname.mLocalName == txXSLTAtoms::document || - qname.mLocalName == txXSLTAtoms::elementAvailable || - qname.mLocalName == txXSLTAtoms::formatNumber || - qname.mLocalName == txXSLTAtoms::functionAvailable || - qname.mLocalName == txXSLTAtoms::generateId || - qname.mLocalName == txXSLTAtoms::key || - //qname.mLocalName == txXSLTAtoms::unparsedEntityUri || - qname.mLocalName == txXSLTAtoms::systemProperty); - - aContext->recycler()->getBoolResult(val, aResult); - - return NS_OK; - -} - -#ifdef TX_TO_STRING -nsresult -FunctionAvailableFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::functionAvailable; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/GenerateIdFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/GenerateIdFunctionCall.cpp deleted file mode 100644 index d2dac47182f4..000000000000 --- a/extensions/transformiix/source/xslt/functions/GenerateIdFunctionCall.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Keith Visco. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "ExprResult.h" -#include "txAtoms.h" -#include "txIXPathContext.h" -#include "txNodeSet.h" -#include "XSLTFunctions.h" - -/* - Implementation of XSLT 1.0 extension function: generate-id -*/ - -/** - * Creates a new generate-id function call -**/ -GenerateIdFunctionCall::GenerateIdFunctionCall() -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param ps the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see FunctionCall.h -**/ -nsresult -GenerateIdFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - if (!requireParams(0, 1, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - nsresult rv = NS_OK; - if (params.getLength() != 1) { - StringResult* strRes; - rv = aContext->recycler()->getStringResult(&strRes); - NS_ENSURE_SUCCESS(rv, rv); - - txXPathNodeUtils::getXSLTId(aContext->getContextNode(), - strRes->mValue); - - *aResult = strRes; - - return NS_OK; - } - - txListIterator iter(¶ms); - nsRefPtr nodes; - rv = evaluateToNodeSet(NS_STATIC_CAST(Expr*, iter.next()), aContext, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (nodes->isEmpty()) { - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - } - - StringResult* strRes; - rv = aContext->recycler()->getStringResult(&strRes); - NS_ENSURE_SUCCESS(rv, rv); - - txXPathNodeUtils::getXSLTId(nodes->get(0), strRes->mValue); - - *aResult = strRes; - - return NS_OK; -} - -#ifdef TX_TO_STRING -nsresult -GenerateIdFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::generateId; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/Makefile.in b/extensions/transformiix/source/xslt/functions/Makefile.in deleted file mode 100644 index 9a0fd8053ae4..000000000000 --- a/extensions/transformiix/source/xslt/functions/Makefile.in +++ /dev/null @@ -1,81 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxsltfunctions_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += dom \ - content \ - layout \ - widget \ - unicharutil \ - necko \ - htmlparser \ - $(NULL) -endif - -CPPSRCS = CurrentFunctionCall.cpp \ - DocumentFunctionCall.cpp \ - ElementAvailableFnCall.cpp \ - FunctionAvailableFnCall.cpp \ - GenerateIdFunctionCall.cpp \ - SystemPropertyFunctionCall.cpp \ - txFormatNumberFunctionCall.cpp \ - txKeyFunctionCall.cpp - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir)/../../base -I$(srcdir)/../../xpath \ - -I$(srcdir)/../../xml/dom -I$(srcdir)/../../xml -I$(srcdir) \ - -I$(srcdir)/../../xml/parser -I$(srcdir)/.. -I$(srcdir)/../util diff --git a/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp deleted file mode 100644 index 2542f9b0d707..000000000000 --- a/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txIXPathContext.h" -#include "txAtoms.h" -#include "txError.h" -#include "XMLUtils.h" -#include "XSLTFunctions.h" -#include "ExprResult.h" -#include "txNamespaceMap.h" - -/* - Implementation of XSLT 1.0 extension function: system-property -*/ - -/** - * Creates a new system-property function call - * aNode is the Element in the stylesheet containing the - * Expr and is used for namespaceID resolution -**/ -SystemPropertyFunctionCall::SystemPropertyFunctionCall(txNamespaceMap* aMappings) - : mMappings(aMappings) -{ -} - -/** - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param cs the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - * @see FunctionCall.h -**/ -nsresult -SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - - if (!requireParams(1, 1, aContext)) { - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - } - - txListIterator iter(¶ms); - Expr* param = (Expr*)iter.next(); - nsRefPtr exprResult; - nsresult rv = param->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString property; - exprResult->stringValue(property); - txExpandedName qname; - rv = qname.init(property, mMappings, MB_TRUE); - NS_ENSURE_SUCCESS(rv, rv); - - if (qname.mNamespaceID == kNameSpaceID_XSLT) { - if (qname.mLocalName == txXSLTAtoms::version) { - return aContext->recycler()->getNumberResult(1.0, aResult); - } - if (qname.mLocalName == txXSLTAtoms::vendor) { - return aContext->recycler()->getStringResult( - NS_LITERAL_STRING("Transformiix"), aResult); - } - if (qname.mLocalName == txXSLTAtoms::vendorUrl) { - return aContext->recycler()->getStringResult( - NS_LITERAL_STRING("http://www.mozilla.org/projects/xslt/"), - aResult); - } - } - aContext->recycler()->getEmptyStringResult(aResult); - - return NS_OK; - -} - -#ifdef TX_TO_STRING -nsresult -SystemPropertyFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::systemProperty; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif diff --git a/extensions/transformiix/source/xslt/functions/XSLTFunctions.h b/extensions/transformiix/source/xslt/functions/XSLTFunctions.h deleted file mode 100644 index 0e6f0f3583a5..000000000000 --- a/extensions/transformiix/source/xslt/functions/XSLTFunctions.h +++ /dev/null @@ -1,258 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Keith Visco. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_XSLT_FUNCTIONS_H -#define TRANSFRMX_XSLT_FUNCTIONS_H - -#include "Expr.h" -#include "XMLUtils.h" -#include "nsAutoPtr.h" - -class txPattern; -class txStylesheet; -class txKeyValueHashKey; -class txExecutionState; -class txNamespaceMap; - -/** - * The definition for the XSLT document() function -**/ -class DocumentFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new document() function call - **/ - DocumentFunctionCall(const nsAString& aBaseURI); - - TX_DECL_FUNCTION; - -private: - nsString mBaseURI; -}; - -/* - * The definition for the XSLT key() function - */ -class txKeyFunctionCall : public FunctionCall { - -public: - - /* - * Creates a new key() function call - */ - txKeyFunctionCall(txNamespaceMap* aMappings); - - TX_DECL_FUNCTION; - -private: - nsRefPtr mMappings; -}; - -/** - * The definition for the XSLT format-number() function -**/ -class txFormatNumberFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new format-number() function call - **/ - txFormatNumberFunctionCall(txStylesheet* aStylesheet, txNamespaceMap* aMappings); - - TX_DECL_FUNCTION; - -private: - static const PRUnichar FORMAT_QUOTE; - - enum FormatParseState { - Prefix, - IntDigit, - IntZero, - FracZero, - FracDigit, - Suffix, - Finished - }; - - txStylesheet* mStylesheet; - nsRefPtr mMappings; -}; - -/** - * DecimalFormat - * A representation of the XSLT element - */ -class txDecimalFormat : public TxObject { - -public: - /* - * Creates a new decimal format and initilizes all properties with - * default values - */ - txDecimalFormat(); - MBool isEqual(txDecimalFormat* other); - - PRUnichar mDecimalSeparator; - PRUnichar mGroupingSeparator; - nsString mInfinity; - PRUnichar mMinusSign; - nsString mNaN; - PRUnichar mPercent; - PRUnichar mPerMille; - PRUnichar mZeroDigit; - PRUnichar mDigit; - PRUnichar mPatternSeparator; -}; - -/** - * The definition for the XSLT current() function -**/ -class CurrentFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new current() function call - **/ - CurrentFunctionCall(); - - TX_DECL_FUNCTION; -}; - -/** - * The definition for the XSLT unparsed-entity-uri() function -**/ -class UnparsedEntityUriFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new unparsed-entity-uri() function call - **/ - UnparsedEntityUriFunctionCall(); - - TX_DECL_FUNCTION; - -private: -}; - -/** - * The definition for the XSLT generate-id() function -**/ -class GenerateIdFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new generate-id() function call - **/ - GenerateIdFunctionCall(); - - TX_DECL_FUNCTION; -}; - -/** - * The definition for the XSLT system-property() function -**/ -class SystemPropertyFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new system-property() function call - * aNode is the Element in the stylesheet containing the - * Expr and is used for namespaceID resolution - **/ - SystemPropertyFunctionCall(txNamespaceMap* aMappings); - - TX_DECL_FUNCTION; - -private: - /* - * resolve namespaceIDs with this node - */ - nsRefPtr mMappings; -}; - -/** - * The definition for the XSLT element-available() function -**/ -class ElementAvailableFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new element-available() function call - * aNode is the Element in the stylesheet containing the - * Expr and is used for namespaceID resolution - **/ - ElementAvailableFunctionCall(txNamespaceMap* aMappings); - - TX_DECL_FUNCTION; - -private: - /* - * resolve namespaceIDs with this node - */ - nsRefPtr mMappings; -}; - -/** - * The definition for the XSLT function-available() function -**/ -class FunctionAvailableFunctionCall : public FunctionCall { - -public: - - /** - * Creates a new function-available() function call - **/ - FunctionAvailableFunctionCall(txNamespaceMap* aMappings); - - TX_DECL_FUNCTION; - -private: - /* - * resolve namespaceIDs with this node - */ - nsRefPtr mMappings; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp deleted file mode 100644 index 83d12c65e64d..000000000000 --- a/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "XSLTFunctions.h" -#include "txAtoms.h" -#include "txIXPathContext.h" -#include "txStylesheet.h" -#include -#include "ExprResult.h" -#include "txNamespaceMap.h" - -#include "prdtoa.h" - -#define INVALID_PARAM_VALUE \ - NS_LITERAL_STRING("invalid parameter value for function") - -const PRUnichar txFormatNumberFunctionCall::FORMAT_QUOTE = '\''; - -/* - * FormatNumberFunctionCall - * A representation of the XSLT additional function: format-number() - */ - -/* - * Creates a new format-number function call - */ -txFormatNumberFunctionCall::txFormatNumberFunctionCall(txStylesheet* aStylesheet, - txNamespaceMap* aMappings) - : mStylesheet(aStylesheet), - mMappings(aMappings) -{ -} - -/* - * Evaluates this Expr based on the given context node and processor state - * @param context the context node for evaluation of this Expr - * @param cs the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - */ -nsresult -txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - nsresult rv = NS_OK; - *aResult = nsnull; - if (!requireParams(2, 3, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - // Get number and format - txListIterator iter(¶ms); - - double value; - nsAutoString formatStr; - txExpandedName formatName; - - value = evaluateToNumber((Expr*)iter.next(), aContext); - evaluateToString((Expr*)iter.next(), aContext, formatStr); - if (iter.hasNext()) { - nsAutoString formatQName; - evaluateToString((Expr*)iter.next(), aContext, formatQName); - rv = formatName.init(formatQName, mMappings, MB_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - } - - txDecimalFormat* format = mStylesheet->getDecimalFormat(formatName); - if (!format) { - nsAutoString err(NS_LITERAL_STRING("unknown decimal format")); -#ifdef TX_TO_STRING - err.AppendLiteral(" for: "); - toString(err); -#endif - aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG); - return NS_ERROR_XPATH_INVALID_ARG; - } - - // Special cases - if (Double::isNaN(value)) { - return aContext->recycler()->getStringResult(format->mNaN, aResult); - } - - if (value == Double::POSITIVE_INFINITY) { - return aContext->recycler()->getStringResult(format->mInfinity, - aResult); - } - - if (value == Double::NEGATIVE_INFINITY) { - nsAutoString res; - res.Append(format->mMinusSign); - res.Append(format->mInfinity); - return aContext->recycler()->getStringResult(res, aResult); - } - - // Value is a normal finite number - nsAutoString prefix; - nsAutoString suffix; - int minIntegerSize=0; - int minFractionSize=0; - int maxFractionSize=0; - int multiplier=1; - int groupSize=-1; - - PRUint32 pos = 0; - PRUint32 formatLen = formatStr.Length(); - MBool inQuote; - - // Get right subexpression - inQuote = MB_FALSE; - if (Double::isNeg(value)) { - while (pos < formatLen && - (inQuote || - formatStr.CharAt(pos) != format->mPatternSeparator)) { - if (formatStr.CharAt(pos) == FORMAT_QUOTE) - inQuote = !inQuote; - pos++; - } - - if (pos == formatLen) { - pos = 0; - prefix.Append(format->mMinusSign); - } - else - pos++; - } - - // Parse the format string - FormatParseState pState = Prefix; - inQuote = MB_FALSE; - - PRUnichar c = 0; - while (pos < formatLen && pState != Finished) { - c=formatStr.CharAt(pos++); - - switch (pState) { - - case Prefix: - case Suffix: - if (!inQuote) { - if (c == format->mPercent) { - if (multiplier == 1) - multiplier = 100; - else { - nsAutoString err(INVALID_PARAM_VALUE); -#ifdef TX_TO_STRING - err.AppendLiteral(": "); - toString(err); -#endif - aContext->receiveError(err, - NS_ERROR_XPATH_INVALID_ARG); - return NS_ERROR_XPATH_INVALID_ARG; - } - } - else if (c == format->mPerMille) { - if (multiplier == 1) - multiplier = 1000; - else { - nsAutoString err(INVALID_PARAM_VALUE); -#ifdef TX_TO_STRING - err.AppendLiteral(": "); - toString(err); -#endif - aContext->receiveError(err, - NS_ERROR_XPATH_INVALID_ARG); - return NS_ERROR_XPATH_INVALID_ARG; - } - } - else if (c == format->mDecimalSeparator || - c == format->mGroupingSeparator || - c == format->mZeroDigit || - c == format->mDigit || - c == format->mPatternSeparator) { - pState = pState == Prefix ? IntDigit : Finished; - pos--; - break; - } - } - - if (c == FORMAT_QUOTE) - inQuote = !inQuote; - else if (pState == Prefix) - prefix.Append(c); - else - suffix.Append(c); - break; - - case IntDigit: - if (c == format->mGroupingSeparator) - groupSize=0; - else if (c == format->mDigit) { - if (groupSize >= 0) - groupSize++; - } - else { - pState = IntZero; - pos--; - } - break; - - case IntZero: - if (c == format->mGroupingSeparator) - groupSize = 0; - else if (c == format->mZeroDigit) { - if (groupSize >= 0) - groupSize++; - minIntegerSize++; - } - else if (c == format->mDecimalSeparator) { - pState = FracZero; - } - else { - pState = Suffix; - pos--; - } - break; - - case FracZero: - if (c == format->mZeroDigit) { - maxFractionSize++; - minFractionSize++; - } - else { - pState = FracDigit; - pos--; - } - break; - - case FracDigit: - if (c == format->mDigit) - maxFractionSize++; - else { - pState = Suffix; - pos--; - } - break; - - case Finished: - break; - } - } - - // Did we manage to parse the entire formatstring and was it valid - if ((c != format->mPatternSeparator && pos < formatLen) || - inQuote || - groupSize == 0) { - nsAutoString err(INVALID_PARAM_VALUE); -#ifdef TX_TO_STRING - err.AppendLiteral(": "); - toString(err); -#endif - aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG); - return NS_ERROR_XPATH_INVALID_ARG; - } - - - /* - * FINALLY we're done with the parsing - * now build the result string - */ - - value = fabs(value) * multiplier; - - // Prefix - nsAutoString res(prefix); - - int bufsize; - if (value > 1) - bufsize = (int)log10(value) + 30; - else - bufsize = 1 + 30; - - char* buf = new char[bufsize]; - NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY); - - PRIntn bufIntDigits, sign; - char* endp; - PR_dtoa(value, 0, 0, &bufIntDigits, &sign, &endp, buf, bufsize-1); - - int buflen = endp - buf; - int intDigits; - intDigits = bufIntDigits > minIntegerSize ? bufIntDigits : minIntegerSize; - - if (groupSize < 0) - groupSize = intDigits + 10; //to simplify grouping - - // XXX We shouldn't use SetLength. - res.SetLength(res.Length() + - intDigits + // integer digits - 1 + // decimal separator - maxFractionSize + // fractions - (intDigits-1)/groupSize); // group separators - - PRInt32 i = bufIntDigits + maxFractionSize - 1; - MBool carry = (i+1 < buflen) && (buf[i+1] >= '5'); - MBool hasFraction = MB_FALSE; - - PRUint32 resPos = res.Length()-1; - - // Fractions - for (; i >= bufIntDigits; --i) { - int digit; - if (i >= buflen || i < 0) { - digit = 0; - } - else { - digit = buf[i] - '0'; - } - - if (carry) { - digit = (digit + 1) % 10; - carry = digit == 0; - } - - if (hasFraction || digit != 0 || i < bufIntDigits+minFractionSize) { - hasFraction = MB_TRUE; - res.SetCharAt((PRUnichar)(digit + format->mZeroDigit), - resPos--); - } - else { - res.Truncate(resPos--); - } - } - - // Decimal separator - if (hasFraction) { - res.SetCharAt(format->mDecimalSeparator, resPos--); - } - else { - res.Truncate(resPos--); - } - - // Integer digits - for (i = 0; i < intDigits; ++i) { - int digit; - if (bufIntDigits-i-1 >= buflen || bufIntDigits-i-1 < 0) { - digit = 0; - } - else { - digit = buf[bufIntDigits-i-1] - '0'; - } - - if (carry) { - digit = (digit + 1) % 10; - carry = digit == 0; - } - - if (i != 0 && i%groupSize == 0) { - res.SetCharAt(format->mGroupingSeparator, resPos--); - } - - res.SetCharAt((PRUnichar)(digit + format->mZeroDigit), resPos--); - } - - if (carry) { - if (i%groupSize == 0) { - res.Insert(format->mGroupingSeparator, resPos + 1); - } - res.Insert((PRUnichar)(1 + format->mZeroDigit), resPos + 1); - } - - if (!hasFraction && !intDigits && !carry) { - // If we havn't added any characters we add a '0' - // This can only happen for formats like '##.##' - res.Append(format->mZeroDigit); - } - - delete [] buf; - - // Build suffix - res.Append(suffix); - - return aContext->recycler()->getStringResult(res, aResult); -} //-- evaluate - -#ifdef TX_TO_STRING -nsresult -txFormatNumberFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::formatNumber; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif - -/* - * txDecimalFormat - * A representation of the XSLT element - */ - -txDecimalFormat::txDecimalFormat() : mInfinity(NS_LITERAL_STRING("Infinity")), - mNaN(NS_LITERAL_STRING("NaN")) -{ - mDecimalSeparator = '.'; - mGroupingSeparator = ','; - mMinusSign = '-'; - mPercent = '%'; - mPerMille = 0x2030; - mZeroDigit = '0'; - mDigit = '#'; - mPatternSeparator = ';'; -} - -MBool txDecimalFormat::isEqual(txDecimalFormat* other) -{ - return mDecimalSeparator == other->mDecimalSeparator && - mGroupingSeparator == other->mGroupingSeparator && - mInfinity.Equals(other->mInfinity) && - mMinusSign == other->mMinusSign && - mNaN.Equals(other->mNaN) && - mPercent == other->mPercent && - mPerMille == other->mPerMille && - mZeroDigit == other->mZeroDigit && - mDigit == other->mDigit && - mPatternSeparator == other->mPatternSeparator; -} diff --git a/extensions/transformiix/source/xslt/functions/txKey.h b/extensions/transformiix/source/xslt/functions/txKey.h deleted file mode 100644 index 340cf5a46472..000000000000 --- a/extensions/transformiix/source/xslt/functions/txKey.h +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txKey_h__ -#define txKey_h__ - -#include "nsDoubleHashtable.h" -#include "txNodeSet.h" -#include "List.h" -#include "txXSLTPatterns.h" -#include "XMLUtils.h" - -class txPattern; -class Expr; -class txExecutionState; - -class txKeyValueHashKey -{ -public: - txKeyValueHashKey(const txExpandedName& aKeyName, - PRInt32 aDocumentIdentifier, - const nsAString& aKeyValue) - : mKeyName(aKeyName), - mKeyValue(aKeyValue), - mDocumentIdentifier(aDocumentIdentifier) - { - } - - txExpandedName mKeyName; - nsString mKeyValue; - PRInt32 mDocumentIdentifier; -}; - -struct txKeyValueHashEntry : public PLDHashEntryHdr -{ - txKeyValueHashEntry(const void* aKey) - : mKey(*NS_STATIC_CAST(const txKeyValueHashKey*, aKey)), - mNodeSet(new txNodeSet(nsnull)) - { - } - - // @see nsDoubleHashtable.h - const void* GetKey(); - PRBool MatchEntry(const void* aKey) const; - static PLDHashNumber HashKey(const void* aKey); - - txKeyValueHashKey mKey; - nsRefPtr mNodeSet; -}; - -DECL_DHASH_WRAPPER(txKeyValueHash, txKeyValueHashEntry, txKeyValueHashKey&) - -class txIndexedKeyHashKey -{ -public: - txIndexedKeyHashKey(txExpandedName aKeyName, - PRInt32 aDocumentIdentifier) - : mKeyName(aKeyName), - mDocumentIdentifier(aDocumentIdentifier) - { - } - - txExpandedName mKeyName; - PRInt32 mDocumentIdentifier; -}; - -struct txIndexedKeyHashEntry : public PLDHashEntryHdr -{ - txIndexedKeyHashEntry(const void* aKey) - : mKey(*NS_STATIC_CAST(const txIndexedKeyHashKey*, aKey)), - mIndexed(PR_FALSE) - { - } - - // @see nsDoubleHashtable.h - const void* GetKey(); - PRBool MatchEntry(const void* aKey) const; - static PLDHashNumber HashKey(const void* aKey); - - txIndexedKeyHashKey mKey; - PRBool mIndexed; -}; - -DECL_DHASH_WRAPPER(txIndexedKeyHash, txIndexedKeyHashEntry, - txIndexedKeyHashKey&) - -/** - * Class holding all s of a particular expanded name in the - * stylesheet. - */ -class txXSLKey : public TxObject { - -public: - txXSLKey(const txExpandedName& aName) : mName(aName) - { - } - ~txXSLKey(); - - /** - * Adds a match/use pair. - * @param aMatch match-pattern - * @param aUse use-expression - * @return PR_FALSE if an error occured, PR_TRUE otherwise - */ - PRBool addKey(nsAutoPtr aMatch, nsAutoPtr aUse); - - /** - * Indexes a document and adds it to the hash of key values - * @param aDocument Document to index and add - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ - nsresult indexDocument(const txXPathNode& aDocument, - txKeyValueHash& aKeyValueHash, - txExecutionState& aEs); - -private: - /** - * Recursively searches a node, its attributes and its subtree for - * nodes matching any of the keys match-patterns. - * @param aNode Node to search - * @param aKey Key to use when adding into the hash - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ - nsresult indexTree(const txXPathNode& aNode, txKeyValueHashKey& aKey, - txKeyValueHash& aKeyValueHash, txExecutionState& aEs); - - /** - * Tests one node if it matches any of the keys match-patterns. If - * the node matches its values are added to the index. - * @param aNode Node to test - * @param aKey Key to use when adding into the hash - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ - nsresult testNode(const txXPathNode& aNode, txKeyValueHashKey& aKey, - txKeyValueHash& aKeyValueHash, txExecutionState& aEs); - - /** - * represents one match/use pair - */ - struct Key { - nsAutoPtr matchPattern; - nsAutoPtr useExpr; - }; - - /** - * List of all match/use pairs. The items as |Key|s - */ - List mKeys; - - /** - * Name of this key - */ - txExpandedName mName; -}; - - -class txKeyHash -{ -public: - txKeyHash(const txExpandedNameMap& aKeys) - : mKeys(aKeys) - { - } - - nsresult init(); - - nsresult getKeyNodes(const txExpandedName& aKeyName, - const txXPathNode& aDocument, - const nsAString& aKeyValue, - PRBool aIndexIfNotFound, - txExecutionState& aEs, - txNodeSet** aResult); - -private: - // Hash of all indexed key-values - txKeyValueHash mKeyValues; - - // Hash showing which keys+documents has been indexed - txIndexedKeyHash mIndexedKeys; - - // Map of txXSLKeys - const txExpandedNameMap& mKeys; - - // Empty nodeset returned if no key is found - nsRefPtr mEmptyNodeSet; -}; - - -#endif //txKey_h__ diff --git a/extensions/transformiix/source/xslt/functions/txKeyFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/txKeyFunctionCall.cpp deleted file mode 100644 index 2a0b114535d0..000000000000 --- a/extensions/transformiix/source/xslt/functions/txKeyFunctionCall.cpp +++ /dev/null @@ -1,459 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txExecutionState.h" -#include "txAtoms.h" -#include "txSingleNodeContext.h" -#include "XSLTFunctions.h" -#include "nsReadableUtils.h" -#include "txKey.h" -#include "txXSLTPatterns.h" -#include "txNamespaceMap.h" - -/* - * txKeyFunctionCall - * A representation of the XSLT additional function: key() - */ - -/* - * Creates a new key function call - */ -txKeyFunctionCall::txKeyFunctionCall(txNamespaceMap* aMappings) - : mMappings(aMappings) -{ -} - -/* - * Evaluates a key() xslt-function call. First argument is name of key - * to use, second argument is value to look up. - * @param aContext the context node for evaluation of this Expr - * @param aCs the ContextState containing the stack information needed - * for evaluation - * @return the result of the evaluation - */ -nsresult -txKeyFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult) -{ - if (!aContext || !requireParams(2, 2, aContext)) - return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT; - - txExecutionState* es = - NS_STATIC_CAST(txExecutionState*, aContext->getPrivateContext()); - - txListIterator iter(¶ms); - nsAutoString keyQName; - evaluateToString((Expr*)iter.next(), aContext, keyQName); - - txExpandedName keyName; - nsresult rv = keyName.init(keyQName, mMappings, PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr exprResult; - rv = ((Expr*)iter.next())->evaluate(aContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr contextDoc(txXPathNodeUtils::getOwnerDocument(aContext->getContextNode())); - NS_ENSURE_TRUE(contextDoc, NS_ERROR_FAILURE); - - nsRefPtr res; - txNodeSet* nodeSet; - if (exprResult->getResultType() == txAExprResult::NODESET && - (nodeSet = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprResult)))->size() > 1) { - rv = aContext->recycler()->getNodeSet(getter_AddRefs(res)); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 i; - for (i = 0; i < nodeSet->size(); ++i) { - nsAutoString val; - txXPathNodeUtils::appendNodeValue(nodeSet->get(i), val); - - nsRefPtr nodes; - rv = es->getKeyNodes(keyName, *contextDoc, val, i == 0, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - res->add(*nodes); - } - } - else { - nsAutoString val; - exprResult->stringValue(val); - rv = es->getKeyNodes(keyName, *contextDoc, val, PR_TRUE, - getter_AddRefs(res)); - NS_ENSURE_SUCCESS(rv, rv); - } - - *aResult = res; - NS_ADDREF(*aResult); - - return NS_OK; -} - -#ifdef TX_TO_STRING -nsresult -txKeyFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - *aAtom = txXSLTAtoms::key; - NS_ADDREF(*aAtom); - return NS_OK; -} -#endif - -/** - * Hash functions - */ - -DHASH_WRAPPER(txKeyValueHash, txKeyValueHashEntry, txKeyValueHashKey&) -DHASH_WRAPPER(txIndexedKeyHash, txIndexedKeyHashEntry, txIndexedKeyHashKey&) - -const void* -txKeyValueHashEntry::GetKey() -{ - return &mKey; -} - -PRBool -txKeyValueHashEntry::MatchEntry(const void* aKey) const -{ - const txKeyValueHashKey* key = - NS_STATIC_CAST(const txKeyValueHashKey*, aKey); - - return mKey.mKeyName == key->mKeyName && - mKey.mDocumentIdentifier == key->mDocumentIdentifier && - mKey.mKeyValue.Equals(key->mKeyValue); -} - -PLDHashNumber -txKeyValueHashEntry::HashKey(const void* aKey) -{ - const txKeyValueHashKey* key = - NS_STATIC_CAST(const txKeyValueHashKey*, aKey); - - return key->mKeyName.mNamespaceID ^ - NS_PTR_TO_INT32(key->mKeyName.mLocalName.get()) ^ - key->mDocumentIdentifier ^ - HashString(key->mKeyValue); -} - -const void* -txIndexedKeyHashEntry::GetKey() -{ - return &mKey; -} - -PRBool -txIndexedKeyHashEntry::MatchEntry(const void* aKey) const -{ - const txIndexedKeyHashKey* key = - NS_STATIC_CAST(const txIndexedKeyHashKey*, aKey); - - return mKey.mKeyName == key->mKeyName && - mKey.mDocumentIdentifier == key->mDocumentIdentifier; -} - -PLDHashNumber -txIndexedKeyHashEntry::HashKey(const void* aKey) -{ - const txIndexedKeyHashKey* key = - NS_STATIC_CAST(const txIndexedKeyHashKey*, aKey); - - return key->mKeyName.mNamespaceID ^ - NS_PTR_TO_INT32(key->mKeyName.mLocalName.get()) ^ - key->mDocumentIdentifier; -} - -/* - * Class managing XSLT-keys - */ - -nsresult -txKeyHash::getKeyNodes(const txExpandedName& aKeyName, - const txXPathNode& aDocument, - const nsAString& aKeyValue, - PRBool aIndexIfNotFound, - txExecutionState& aEs, - txNodeSet** aResult) -{ - NS_ENSURE_TRUE(mKeyValues.mHashTable.ops && mIndexedKeys.mHashTable.ops, - NS_ERROR_OUT_OF_MEMORY); - - *aResult = nsnull; - - PRInt32 identifier = txXPathNodeUtils::getUniqueIdentifier(aDocument); - - txKeyValueHashKey valueKey(aKeyName, identifier, aKeyValue); - txKeyValueHashEntry* valueEntry = mKeyValues.GetEntry(valueKey); - if (valueEntry) { - *aResult = valueEntry->mNodeSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - - // We didn't find a value. This could either mean that that key has no - // nodes with that value or that the key hasn't been indexed using this - // document. - - if (!aIndexIfNotFound) { - // If aIndexIfNotFound is set then the caller knows this key is - // indexed, so don't bother investigating. - *aResult = mEmptyNodeSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - - txIndexedKeyHashKey indexKey(aKeyName, identifier); - txIndexedKeyHashEntry* indexEntry = mIndexedKeys.AddEntry(indexKey); - NS_ENSURE_TRUE(indexEntry, NS_ERROR_OUT_OF_MEMORY); - - if (indexEntry->mIndexed) { - // The key was indexed and apparently didn't contain this value so - // return the empty nodeset. - *aResult = mEmptyNodeSet; - NS_ADDREF(*aResult); - - return NS_OK; - } - - // The key needs to be indexed. - txXSLKey* xslKey = (txXSLKey*)mKeys.get(aKeyName); - if (!xslKey) { - // The key didn't exist, so bail. - return NS_ERROR_INVALID_ARG; - } - - nsresult rv = xslKey->indexDocument(aDocument, mKeyValues, aEs); - NS_ENSURE_SUCCESS(rv, rv); - - indexEntry->mIndexed = PR_TRUE; - - // Now that the key is indexed we can get its value. - valueEntry = mKeyValues.GetEntry(valueKey); - if (valueEntry) { - *aResult = valueEntry->mNodeSet; - NS_ADDREF(*aResult); - } - else { - *aResult = mEmptyNodeSet; - NS_ADDREF(*aResult); - } - - return NS_OK; -} - -nsresult -txKeyHash::init() -{ - nsresult rv = mKeyValues.Init(8); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mIndexedKeys.Init(1); - NS_ENSURE_SUCCESS(rv, rv); - - mEmptyNodeSet = new txNodeSet(nsnull); - NS_ENSURE_TRUE(mEmptyNodeSet, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; -} - -/** - * Class holding all s of a particular expanded name in the - * stylesheet. - */ -txXSLKey::~txXSLKey() -{ - txListIterator iter(&mKeys); - Key* key; - while ((key = (Key*)iter.next())) { - delete key; - } -} - -/** - * Adds a match/use pair. - * @param aMatch match-pattern - * @param aUse use-expression - * @return PR_FALSE if an error occured, PR_TRUE otherwise - */ -PRBool txXSLKey::addKey(nsAutoPtr aMatch, nsAutoPtr aUse) -{ - if (!aMatch || !aUse) - return PR_FALSE; - - nsAutoPtr key(new Key); - if (!key) - return PR_FALSE; - - key->matchPattern = aMatch; - key->useExpr = aUse; - nsresult rv = mKeys.add(key); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - key.forget(); - - return PR_TRUE; -} - -/** - * Indexes a document and adds it to the hash of key values - * @param aDocument Document to index and add - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ -nsresult txXSLKey::indexDocument(const txXPathNode& aDocument, - txKeyValueHash& aKeyValueHash, - txExecutionState& aEs) -{ - txKeyValueHashKey key(mName, - txXPathNodeUtils::getUniqueIdentifier(aDocument), - EmptyString()); - return indexTree(aDocument, key, aKeyValueHash, aEs); -} - -/** - * Recursively searches a node, its attributes and its subtree for - * nodes matching any of the keys match-patterns. - * @param aNode Node to search - * @param aKey Key to use when adding into the hash - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ -nsresult txXSLKey::indexTree(const txXPathNode& aNode, - txKeyValueHashKey& aKey, - txKeyValueHash& aKeyValueHash, - txExecutionState& aEs) -{ - nsresult rv = testNode(aNode, aKey, aKeyValueHash, aEs); - NS_ENSURE_SUCCESS(rv, rv); - - // check if the node's attributes match - txXPathTreeWalker walker(aNode); - if (walker.moveToFirstAttribute()) { - do { - rv = testNode(walker.getCurrentPosition(), aKey, aKeyValueHash, - aEs); - NS_ENSURE_SUCCESS(rv, rv); - } while (walker.moveToNextAttribute()); - walker.moveToParent(); - } - - // check if the node's descendants match - if (walker.moveToFirstChild()) { - do { - rv = indexTree(walker.getCurrentPosition(), aKey, aKeyValueHash, - aEs); - NS_ENSURE_SUCCESS(rv, rv); - } while (walker.moveToNextSibling()); - } - - return NS_OK; -} - -/** - * Tests one node if it matches any of the keys match-patterns. If - * the node matches its values are added to the index. - * @param aNode Node to test - * @param aKey Key to use when adding into the hash - * @param aKeyValueHash Hash to add values to - * @param aEs txExecutionState to use for XPath evaluation - */ -nsresult txXSLKey::testNode(const txXPathNode& aNode, - txKeyValueHashKey& aKey, - txKeyValueHash& aKeyValueHash, - txExecutionState& aEs) -{ - nsAutoString val; - txListIterator iter(&mKeys); - while (iter.hasNext()) - { - Key* key = (Key*)iter.next(); - if (key->matchPattern->matches(aNode, &aEs)) { - txSingleNodeContext evalContext(aNode, &aEs); - nsresult rv = aEs.pushEvalContext(&evalContext); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr exprResult; - rv = key->useExpr->evaluate(&evalContext, - getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, rv); - - aEs.popEvalContext(); - - if (exprResult->getResultType() == txAExprResult::NODESET) { - txNodeSet* res = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprResult)); - PRInt32 i; - for (i = 0; i < res->size(); ++i) { - val.Truncate(); - txXPathNodeUtils::appendNodeValue(res->get(i), val); - - aKey.mKeyValue.Assign(val); - txKeyValueHashEntry* entry = aKeyValueHash.AddEntry(aKey); - NS_ENSURE_TRUE(entry && entry->mNodeSet, - NS_ERROR_OUT_OF_MEMORY); - - if (entry->mNodeSet->isEmpty() || - entry->mNodeSet->get(entry->mNodeSet->size() - 1) != - aNode) { - entry->mNodeSet->append(aNode); - } - } - } - else { - exprResult->stringValue(val); - - aKey.mKeyValue.Assign(val); - txKeyValueHashEntry* entry = aKeyValueHash.AddEntry(aKey); - NS_ENSURE_TRUE(entry && entry->mNodeSet, - NS_ERROR_OUT_OF_MEMORY); - - if (entry->mNodeSet->isEmpty() || - entry->mNodeSet->get(entry->mNodeSet->size() - 1) != - aNode) { - entry->mNodeSet->append(aNode); - } - } - } - } - - return NS_OK; -} diff --git a/extensions/transformiix/source/xslt/txBufferingHandler.cpp b/extensions/transformiix/source/xslt/txBufferingHandler.cpp deleted file mode 100644 index ba4339b3f19a..000000000000 --- a/extensions/transformiix/source/xslt/txBufferingHandler.cpp +++ /dev/null @@ -1,416 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txBufferingHandler.h" - -class txOutputTransaction -{ -public: - enum txTransactionType { - eAttributeTransaction, - eCharacterTransaction, - eCharacterNoOETransaction, - eCommentTransaction, - eEndDocumentTransaction, - eEndElementTransaction, - ePITransaction, - eStartDocumentTransaction, - eStartElementTransaction - }; - txOutputTransaction(txTransactionType aType) - : mType(aType) - { - } - virtual ~txOutputTransaction() - { - } - txTransactionType mType; -}; - -class txCharacterTransaction : public txOutputTransaction -{ -public: - txCharacterTransaction(txTransactionType aType, PRUint32 aLength) - : txOutputTransaction(aType), - mLength(aLength) - { - } - PRUint32 mLength; -}; - -class txCommentTransaction : public txOutputTransaction -{ -public: - txCommentTransaction(const nsAString& aValue) - : txOutputTransaction(eCommentTransaction), - mValue(aValue) - { - } - nsString mValue; -}; - -class txPITransaction : public txOutputTransaction -{ -public: - txPITransaction(const nsAString& aTarget, const nsAString& aData) - : txOutputTransaction(ePITransaction), - mTarget(aTarget), - mData(aData) - { - } - nsString mTarget; - nsString mData; -}; - -class txElementTransaction : public txOutputTransaction -{ -public: - txElementTransaction(txTransactionType aType, const nsAString& aName, - PRInt32 aNsID) - : txOutputTransaction(aType), - mName(aName), - mNsID(aNsID) - { - } - nsString mName; - PRInt32 mNsID; -}; - -class txAttributeTransaction : public txOutputTransaction -{ -public: - txAttributeTransaction(const nsAString& aName, PRInt32 aNsID, - const nsAString& aValue) - : txOutputTransaction(eAttributeTransaction), - mName(aName), - mNsID(aNsID), - mValue(aValue) - { - } - nsString mName; - PRInt32 mNsID; - nsString mValue; -}; - -txBufferingHandler::txBufferingHandler() : mCanAddAttribute(PR_FALSE) -{ - mBuffer = new txResultBuffer(); -} - -txBufferingHandler::~txBufferingHandler() -{ -} - -void -txBufferingHandler::attribute(const nsAString& aName, const PRInt32 aNsID, - const nsAString& aValue) -{ - if (!mBuffer) { - return; - } - - if (!mCanAddAttribute) { - // XXX ErrorReport: Can't add attributes without element - return; - } - - txOutputTransaction* transaction = - new txAttributeTransaction(aName, aNsID, aValue); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::characters(const nsAString& aData, PRBool aDOE) -{ - if (!mBuffer) { - return; - } - - mCanAddAttribute = PR_FALSE; - - txOutputTransaction::txTransactionType type = - aDOE ? txOutputTransaction::eCharacterNoOETransaction - : txOutputTransaction::eCharacterTransaction; - - txOutputTransaction* transaction = mBuffer->getLastTransaction(); - if (transaction && transaction->mType == type) { - mBuffer->mStringValue.Append(aData); - NS_STATIC_CAST(txCharacterTransaction*, transaction)->mLength += - aData.Length(); - return; - } - - transaction = new txCharacterTransaction(type, aData.Length()); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - - mBuffer->mStringValue.Append(aData); - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::comment(const nsAString& aData) -{ - if (!mBuffer) { - return; - } - - mCanAddAttribute = PR_FALSE; - - txOutputTransaction* transaction = new txCommentTransaction(aData); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::endDocument(nsresult aResult) -{ - if (!mBuffer) { - return; - } - - txOutputTransaction* transaction = - new txOutputTransaction(txOutputTransaction::eEndDocumentTransaction); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::endElement(const nsAString& aName, const PRInt32 aNsID) -{ - if (!mBuffer) { - return; - } - - mCanAddAttribute = PR_FALSE; - - txOutputTransaction* transaction = - new txElementTransaction(txOutputTransaction::eEndElementTransaction, - aName, aNsID); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ - if (!mBuffer) { - return; - } - - mCanAddAttribute = PR_FALSE; - - txOutputTransaction* transaction = - new txPITransaction(aTarget, aData); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void txBufferingHandler::startDocument() -{ - if (!mBuffer) { - return; - } - - txOutputTransaction* transaction = - new txOutputTransaction(txOutputTransaction::eStartDocumentTransaction); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -void -txBufferingHandler::startElement(const nsAString& aName, const PRInt32 aNsID) -{ - if (!mBuffer) { - return; - } - - mCanAddAttribute = PR_TRUE; - - txOutputTransaction* transaction = - new txElementTransaction(txOutputTransaction::eStartElementTransaction, - aName, aNsID); - if (!transaction) { - NS_ASSERTION(0, "Out of memory!"); - return; - } - mBuffer->addTransaction(transaction); -} - -PR_STATIC_CALLBACK(PRBool) -deleteTransaction(void* aElement, void *aData) -{ - delete NS_STATIC_CAST(txOutputTransaction*, aElement); - return PR_TRUE; -} - -txResultBuffer::~txResultBuffer() -{ - mTransactions.EnumerateForwards(deleteTransaction, nsnull); -} - -nsresult -txResultBuffer::addTransaction(txOutputTransaction* aTransaction) -{ - if (!mTransactions.AppendElement(aTransaction)) { - return NS_ERROR_OUT_OF_MEMORY; - } - return NS_OK; -} - -struct Holder -{ - txAXMLEventHandler* mHandler; - nsAFlatString::const_char_iterator mIter; -}; - -PR_STATIC_CALLBACK(PRBool) -flushTransaction(void* aElement, void *aData) -{ - txAXMLEventHandler* handler = NS_STATIC_CAST(Holder*, aData)->mHandler; - txOutputTransaction* transaction = - NS_STATIC_CAST(txOutputTransaction*, aElement); - - switch (transaction->mType) { - case txOutputTransaction::eAttributeTransaction: - { - txAttributeTransaction* attrTransaction = - NS_STATIC_CAST(txAttributeTransaction*, aElement); - handler->attribute(attrTransaction->mName, - attrTransaction->mNsID, - attrTransaction->mValue); - break; - } - case txOutputTransaction::eCharacterTransaction: - case txOutputTransaction::eCharacterNoOETransaction: - { - txCharacterTransaction* charTransaction = - NS_STATIC_CAST(txCharacterTransaction*, aElement); - nsAFlatString::const_char_iterator& start = - NS_STATIC_CAST(Holder*, aData)->mIter; - nsAFlatString::const_char_iterator end = - start + charTransaction->mLength; - handler->characters(Substring(start, end), - transaction->mType == - txOutputTransaction::eCharacterNoOETransaction); - start = end; - break; - } - case txOutputTransaction::eCommentTransaction: - { - txCommentTransaction* commentTransaction = - NS_STATIC_CAST(txCommentTransaction*, aElement); - handler->comment(commentTransaction->mValue); - break; - } - case txOutputTransaction::eEndElementTransaction: - { - txElementTransaction* elementTransaction = - NS_STATIC_CAST(txElementTransaction*, aElement); - handler->endElement(elementTransaction->mName, - elementTransaction->mNsID); - break; - } - case txOutputTransaction::ePITransaction: - { - txPITransaction* piTransaction = - NS_STATIC_CAST(txPITransaction*, aElement); - handler->processingInstruction(piTransaction->mTarget, - piTransaction->mData); - break; - } - case txOutputTransaction::eStartDocumentTransaction: - { - handler->startDocument(); - break; - } - case txOutputTransaction::eStartElementTransaction: - { - txElementTransaction* elementTransaction = - NS_STATIC_CAST(txElementTransaction*, aElement); - handler->startElement(elementTransaction->mName, - elementTransaction->mNsID); - break; - } - } - - return PR_TRUE; -} - -nsresult -txResultBuffer::flushToHandler(txAXMLEventHandler* aHandler) -{ - Holder data; - data.mHandler = aHandler; - mStringValue.BeginReading(data.mIter); - mTransactions.EnumerateForwards(flushTransaction, &data); - return NS_OK; -} - -txOutputTransaction* -txResultBuffer::getLastTransaction() -{ - PRInt32 last = mTransactions.Count() - 1; - if (last < 0) { - return nsnull; - } - return NS_STATIC_CAST(txOutputTransaction*, mTransactions[last]); -} diff --git a/extensions/transformiix/source/xslt/txBufferingHandler.h b/extensions/transformiix/source/xslt/txBufferingHandler.h deleted file mode 100644 index b7e407f4fd5a..000000000000 --- a/extensions/transformiix/source/xslt/txBufferingHandler.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txBufferingHandler_h__ -#define txBufferingHandler_h__ - -#include "txXMLEventHandler.h" -#include "nsString.h" -#include "nsVoidArray.h" -#include "nsAutoPtr.h" - -class txOutputTransaction; -class txCharacterTransaction; - -class txResultBuffer -{ -public: - ~txResultBuffer(); - - nsresult addTransaction(txOutputTransaction* aTransaction); - nsresult flushToHandler(txAXMLEventHandler* aHandler); - txOutputTransaction* getLastTransaction(); - - nsString mStringValue; - -private: - nsVoidArray mTransactions; -}; - -class txBufferingHandler : public txAXMLEventHandler -{ -public: - txBufferingHandler(); - ~txBufferingHandler(); - - TX_DECL_TXAXMLEVENTHANDLER - -protected: - nsAutoPtr mBuffer; - PRPackedBool mCanAddAttribute; -}; - -#endif /* txBufferingHandler_h__ */ diff --git a/extensions/transformiix/source/xslt/txExecutionState.cpp b/extensions/transformiix/source/xslt/txExecutionState.cpp deleted file mode 100644 index b8f5d62c17e1..000000000000 --- a/extensions/transformiix/source/xslt/txExecutionState.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txExecutionState.h" -#include "txSingleNodeContext.h" -#include "txInstructions.h" -#include "txStylesheet.h" -#include "txVariableMap.h" -#include "txRtfHandler.h" -#include "txXSLTProcessor.h" -#include "TxLog.h" -#include "txURIUtils.h" -#include "txXMLParser.h" - -const PRInt32 txExecutionState::kMaxRecursionDepth = 20000; - -nsresult txLoadedDocumentsHash::init(txXPathNode* aSourceDocument) -{ - nsresult rv = Init(8); - NS_ENSURE_SUCCESS(rv, rv); - - mSourceDocument = aSourceDocument; - - nsAutoString baseURI; - txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI); - - txLoadedDocumentEntry* entry = PutEntry(baseURI); - if (!entry) { - return NS_ERROR_FAILURE; - } - - entry->mDocument = mSourceDocument; - - return NS_OK; -} - -txLoadedDocumentsHash::~txLoadedDocumentsHash() -{ - if (!IsInitialized()) { - return; - } - - nsAutoString baseURI; - txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI); - - txLoadedDocumentEntry* entry = GetEntry(baseURI); - if (entry) { - delete entry->mDocument.forget(); - } -} - -txExecutionState::txExecutionState(txStylesheet* aStylesheet) - : mStylesheet(aStylesheet), - mNextInstruction(nsnull), - mLocalVariables(nsnull), - mRecursionDepth(0), - mTemplateRules(nsnull), - mTemplateRulesBufferSize(0), - mTemplateRuleCount(0), - mEvalContext(nsnull), - mInitialEvalContext(nsnull), -// mRTFDocument(nsnull), - mGlobalParams(nsnull), - mKeyHash(aStylesheet->getKeyMap()) -{ -} - -txExecutionState::~txExecutionState() -{ - delete mResultHandler; - delete mLocalVariables; - delete mEvalContext; -// delete mRTFDocument; - - PRInt32 i; - for (i = 0; i < mTemplateRuleCount; ++i) { - NS_IF_RELEASE(mTemplateRules[i].mModeLocalName); - } - delete [] mTemplateRules; - - txStackIterator varsIter(&mLocalVarsStack); - while (varsIter.hasNext()) { - delete (txVariableMap*)varsIter.next(); - } - - txStackIterator contextIter(&mEvalContextStack); - while (contextIter.hasNext()) { - txIEvalContext* context = (txIEvalContext*)contextIter.next(); - if (context != mInitialEvalContext) { - delete context; - } - } - - txStackIterator handlerIter(&mResultHandlerStack); - while (handlerIter.hasNext()) { - delete (txAXMLEventHandler*)handlerIter.next(); - } - - txStackIterator paramIter(&mParamStack); - while (paramIter.hasNext()) { - delete (txExpandedNameMap*)paramIter.next(); - } -} - -nsresult -txExecutionState::init(const txXPathNode& aNode, - txExpandedNameMap* aGlobalParams) -{ - nsresult rv = NS_OK; - - mGlobalParams = aGlobalParams; - - // Set up initial context - mEvalContext = new txSingleNodeContext(aNode, this); - NS_ENSURE_TRUE(mEvalContext, NS_ERROR_OUT_OF_MEMORY); - - mInitialEvalContext = mEvalContext; - - // Set up output and result-handler - txAXMLEventHandler* handler = 0; - rv = mOutputHandlerFactory-> - createHandlerWith(mStylesheet->getOutputFormat(), &handler); - NS_ENSURE_SUCCESS(rv, rv); - - mOutputHandler = handler; - mResultHandler = handler; - mOutputHandler->startDocument(); - - // Set up loaded-documents-hash - nsAutoPtr document(txXPathNodeUtils::getOwnerDocument(aNode)); - NS_ENSURE_TRUE(document, NS_ERROR_FAILURE); - - rv = mLoadedDocuments.init(document); - NS_ENSURE_SUCCESS(rv, rv); - - // loaded-documents-hash owns this now - document.forget(); - - // Init members - rv = mKeyHash.init(); - NS_ENSURE_SUCCESS(rv, rv); - - mRecycler = new txResultRecycler; - NS_ENSURE_TRUE(mRecycler, NS_ERROR_OUT_OF_MEMORY); - - rv = mRecycler->init(); - NS_ENSURE_SUCCESS(rv, rv); - - // The actual value here doesn't really matter since noone should use this - // value. But lets put something errorlike in just in case - mGlobalVarPlaceholderValue = new StringResult(NS_LITERAL_STRING("Error"), nsnull); - NS_ENSURE_TRUE(mGlobalVarPlaceholderValue, NS_ERROR_OUT_OF_MEMORY); - - // Initiate first instruction. This has to be done last since findTemplate - // might use us. - txStylesheet::ImportFrame* frame = 0; - txExpandedName nullName; - txInstruction* templ = mStylesheet->findTemplate(aNode, nullName, - this, nsnull, &frame); - rv = pushTemplateRule(frame, nullName, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - return runTemplate(templ); -} - -nsresult -txExecutionState::end(nsresult aResult) -{ - popTemplateRule(); - mOutputHandler->endDocument(aResult); - - return NS_OK; -} - - - -nsresult -txExecutionState::getVariable(PRInt32 aNamespace, nsIAtom* aLName, - txAExprResult*& aResult) -{ - nsresult rv = NS_OK; - txExpandedName name(aNamespace, aLName); - - // look for a local variable - if (mLocalVariables) { - mLocalVariables->getVariable(name, &aResult); - if (aResult) { - return NS_OK; - } - } - - // look for an evaluated global variable - mGlobalVariableValues.getVariable(name, &aResult); - if (aResult) { - if (aResult == mGlobalVarPlaceholderValue) { - // XXX ErrorReport: cyclic variable-value - NS_RELEASE(aResult); - return NS_ERROR_XSLT_BAD_RECURSION; - } - return NS_OK; - } - - // Is there perchance a global variable not evaluated yet? - txStylesheet::GlobalVariable* var = mStylesheet->getGlobalVariable(name); - if (!var) { - // XXX ErrorReport: variable doesn't exist in this scope - return NS_ERROR_FAILURE; - } - - NS_ASSERTION(var->mExpr && !var->mFirstInstruction || - !var->mExpr && var->mFirstInstruction, - "global variable should have either instruction or expression"); - - // Is this a stylesheet parameter that has a value? - if (var->mIsParam && mGlobalParams) { - txIGlobalParameter* param = - (txIGlobalParameter*)mGlobalParams->get(name); - if (param) { - rv = param->getValue(&aResult); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mGlobalVariableValues.bindVariable(name, aResult); - if (NS_FAILED(rv)) { - NS_RELEASE(aResult); - return rv; - } - - return NS_OK; - } - } - - // Insert a placeholdervalue to protect against recursion - rv = mGlobalVariableValues.bindVariable(name, mGlobalVarPlaceholderValue); - NS_ENSURE_SUCCESS(rv, rv); - - // evaluate the global variable - pushEvalContext(mInitialEvalContext); - if (var->mExpr) { - txVariableMap* oldVars = mLocalVariables; - mLocalVariables = nsnull; - rv = var->mExpr->evaluate(getEvalContext(), &aResult); - NS_ENSURE_SUCCESS(rv, rv); - - mLocalVariables = oldVars; - } - else { - nsAutoPtr rtfHandler(new txRtfHandler); - NS_ENSURE_TRUE(rtfHandler, NS_ERROR_OUT_OF_MEMORY); - - rv = pushResultHandler(rtfHandler); - NS_ENSURE_SUCCESS(rv, rv); - - rtfHandler.forget(); - - txInstruction* prevInstr = mNextInstruction; - // set return to nsnull to stop execution - mNextInstruction = nsnull; - rv = runTemplate(var->mFirstInstruction); - NS_ENSURE_SUCCESS(rv, rv); - - rv = pushTemplateRule(nsnull, txExpandedName(), nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - rv = txXSLTProcessor::execute(*this); - NS_ENSURE_SUCCESS(rv, rv); - - popTemplateRule(); - - mNextInstruction = prevInstr; - rtfHandler = (txRtfHandler*)popResultHandler(); - rv = rtfHandler->getAsRTF(&aResult); - NS_ENSURE_SUCCESS(rv, rv); - } - popEvalContext(); - - // Remove the placeholder and insert the calculated value - mGlobalVariableValues.removeVariable(name); - rv = mGlobalVariableValues.bindVariable(name, aResult); - if (NS_FAILED(rv)) { - NS_RELEASE(aResult); - - return rv; - } - - return NS_OK; -} - -PRBool -txExecutionState::isStripSpaceAllowed(const txXPathNode& aNode) -{ - return mStylesheet->isStripSpaceAllowed(aNode, this); -} - -void* -txExecutionState::getPrivateContext() -{ - return this; -} - -txResultRecycler* -txExecutionState::recycler() -{ - return mRecycler; -} - -void -txExecutionState::receiveError(const nsAString& aMsg, nsresult aRes) -{ - // XXX implement me -} - -nsresult -txExecutionState::pushEvalContext(txIEvalContext* aContext) -{ - nsresult rv = mEvalContextStack.push(mEvalContext); - NS_ENSURE_SUCCESS(rv, rv); - - mEvalContext = aContext; - - return NS_OK; -} - -txIEvalContext* -txExecutionState::popEvalContext() -{ - txIEvalContext* prev = mEvalContext; - mEvalContext = (txIEvalContext*)mEvalContextStack.pop(); - - return prev; -} - -nsresult -txExecutionState::pushString(const nsAString& aStr) -{ - if (!mStringStack.AppendString(aStr)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -void -txExecutionState::popString(nsAString& aStr) -{ - PRInt32 count = mStringStack.Count() - 1; - NS_ASSERTION(count >= 0, "stack is empty"); - mStringStack.StringAt(count, aStr); - mStringStack.RemoveStringAt(count); -} - -nsresult -txExecutionState::pushInt(PRInt32 aInt) -{ - return mIntStack.push(NS_INT32_TO_PTR(aInt)); -} - -PRInt32 -txExecutionState::popInt() -{ - return NS_PTR_TO_INT32(mIntStack.pop()); -} - -nsresult -txExecutionState::pushResultHandler(txAXMLEventHandler* aHandler) -{ - nsresult rv = mResultHandlerStack.push(mResultHandler); - NS_ENSURE_SUCCESS(rv, rv); - - mResultHandler = aHandler; - - return NS_OK; -} - -txAXMLEventHandler* -txExecutionState::popResultHandler() -{ - txAXMLEventHandler* oldHandler = mResultHandler; - mResultHandler = (txAXMLEventHandler*)mResultHandlerStack.pop(); - - return oldHandler; -} - -nsresult -txExecutionState::pushTemplateRule(txStylesheet::ImportFrame* aFrame, - const txExpandedName& aMode, - txVariableMap* aParams) -{ - if (mTemplateRuleCount == mTemplateRulesBufferSize) { - PRInt32 newSize = - mTemplateRulesBufferSize ? mTemplateRulesBufferSize * 2 : 10; - TemplateRule* newRules = new TemplateRule[newSize]; - NS_ENSURE_TRUE(newRules, NS_ERROR_OUT_OF_MEMORY); - - memcpy(newRules, mTemplateRules, - mTemplateRuleCount * sizeof(TemplateRule)); - delete [] mTemplateRules; - mTemplateRules = newRules; - mTemplateRulesBufferSize = newSize; - } - - mTemplateRules[mTemplateRuleCount].mFrame = aFrame; - mTemplateRules[mTemplateRuleCount].mModeNsId = aMode.mNamespaceID; - mTemplateRules[mTemplateRuleCount].mModeLocalName = aMode.mLocalName; - mTemplateRules[mTemplateRuleCount].mParams = aParams; - NS_IF_ADDREF(mTemplateRules[mTemplateRuleCount].mModeLocalName); - ++mTemplateRuleCount; - - return NS_OK; -} - -void -txExecutionState::popTemplateRule() -{ - // decrement outside of RELEASE, that would decrement twice - --mTemplateRuleCount; - NS_IF_RELEASE(mTemplateRules[mTemplateRuleCount].mModeLocalName); -} - -txIEvalContext* -txExecutionState::getEvalContext() -{ - return mEvalContext; -} - -const txXPathNode* -txExecutionState::retrieveDocument(const nsAString& aUri) -{ - NS_ASSERTION(aUri.FindChar(PRUnichar('#')) == kNotFound, - "Remove the fragment."); - - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("Retrieve Document %s", NS_LossyConvertUCS2toASCII(aUri).get())); - - // try to get already loaded document - txLoadedDocumentEntry *entry = mLoadedDocuments.PutEntry(aUri); - if (!entry) { - return nsnull; - } - - if (!entry->mDocument) { - // open URI - nsAutoString errMsg, refUri; - // XXX we should get the referrer from the actual node - // triggering the load, but this will do for the time being - txXPathNodeUtils::getBaseURI(*mLoadedDocuments.mSourceDocument, refUri); - nsresult rv; - rv = txParseDocumentFromURI(aUri, refUri, - *mLoadedDocuments.mSourceDocument, errMsg, - getter_Transfers(entry->mDocument)); - - if (NS_FAILED(rv) || !entry->mDocument) { - mLoadedDocuments.RawRemoveEntry(entry); - receiveError(NS_LITERAL_STRING("Couldn't load document '") + - aUri + NS_LITERAL_STRING("': ") + errMsg, rv); - - return nsnull; - } - } - - return entry->mDocument; -} - -nsresult -txExecutionState::getKeyNodes(const txExpandedName& aKeyName, - const txXPathNode& aDocument, - const nsAString& aKeyValue, - PRBool aIndexIfNotFound, - txNodeSet** aResult) -{ - return mKeyHash.getKeyNodes(aKeyName, aDocument, aKeyValue, - aIndexIfNotFound, *this, aResult); -} - -txExecutionState::TemplateRule* -txExecutionState::getCurrentTemplateRule() -{ - return mTemplateRules + mTemplateRuleCount - 1; -} - -txInstruction* -txExecutionState::getNextInstruction() -{ - txInstruction* instr = mNextInstruction; - if (instr) { - mNextInstruction = instr->mNext; - } - - return instr; -} - -nsresult -txExecutionState::runTemplate(txInstruction* aTemplate) -{ - NS_ENSURE_TRUE(++mRecursionDepth < kMaxRecursionDepth, - NS_ERROR_XSLT_BAD_RECURSION); - - nsresult rv = mLocalVarsStack.push(mLocalVariables); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mReturnStack.push(mNextInstruction); - NS_ENSURE_SUCCESS(rv, rv); - - mLocalVariables = nsnull; - mNextInstruction = aTemplate; - - return NS_OK; -} - -void -txExecutionState::gotoInstruction(txInstruction* aNext) -{ - mNextInstruction = aNext; -} - -void -txExecutionState::returnFromTemplate() -{ - --mRecursionDepth; - NS_ASSERTION(!mReturnStack.isEmpty() && !mLocalVarsStack.isEmpty(), - "return or variable stack is empty"); - delete mLocalVariables; - mNextInstruction = (txInstruction*)mReturnStack.pop(); - mLocalVariables = (txVariableMap*)mLocalVarsStack.pop(); -} - -nsresult -txExecutionState::bindVariable(const txExpandedName& aName, - txAExprResult* aValue) -{ - if (!mLocalVariables) { - mLocalVariables = new txVariableMap; - NS_ENSURE_TRUE(mLocalVariables, NS_ERROR_OUT_OF_MEMORY); - } - return mLocalVariables->bindVariable(aName, aValue); -} - -void -txExecutionState::removeVariable(const txExpandedName& aName) -{ - mLocalVariables->removeVariable(aName); -} - -nsresult -txExecutionState::pushParamMap(txVariableMap* aParams) -{ - nsresult rv = mParamStack.push(mTemplateParams); - NS_ENSURE_SUCCESS(rv, rv); - - mTemplateParams.forget(); - mTemplateParams = aParams; - - return NS_OK; -} - -txVariableMap* -txExecutionState::popParamMap() -{ - txVariableMap* oldParams = mTemplateParams.forget(); - mTemplateParams = (txVariableMap*)mParamStack.pop(); - - return oldParams; -} diff --git a/extensions/transformiix/source/xslt/txExecutionState.h b/extensions/transformiix/source/xslt/txExecutionState.h deleted file mode 100644 index abe7d6d10d21..000000000000 --- a/extensions/transformiix/source/xslt/txExecutionState.h +++ /dev/null @@ -1,187 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXEXECUTIONSTATE_H -#define TRANSFRMX_TXEXECUTIONSTATE_H - -#include "txCore.h" -#include "txStack.h" -#include "XMLUtils.h" -#include "nsVoidArray.h" -#include "txIXPathContext.h" -#include "txVariableMap.h" -#include "nsTHashtable.h" -#include "nsHashKeys.h" -#include "txKey.h" -#include "txStylesheet.h" - -class txAOutputHandlerFactory; -class txAXMLEventHandler; -class txInstruction; -class txIOutputHandlerFactory; -class txExpandedNameMap; - -class txLoadedDocumentEntry : public nsStringHashKey -{ -public: - txLoadedDocumentEntry(KeyTypePointer aStr) : nsStringHashKey(aStr) - { - } - txLoadedDocumentEntry(const txLoadedDocumentEntry& aToCopy) - : nsStringHashKey(aToCopy) - { - NS_ERROR("We're horked."); - } - ~txLoadedDocumentEntry() - { - if (mDocument) { - txXPathNodeUtils::release(mDocument); - } - } - - nsAutoPtr mDocument; -}; - -class txLoadedDocumentsHash : public nsTHashtable -{ -public: - ~txLoadedDocumentsHash(); - nsresult init(txXPathNode* aSourceDocument); - -private: - friend class txExecutionState; - txXPathNode* mSourceDocument; -}; - - -class txExecutionState : public txIMatchContext -{ -public: - txExecutionState(txStylesheet* aStylesheet); - ~txExecutionState(); - nsresult init(const txXPathNode& aNode, txExpandedNameMap* aGlobalParams); - nsresult end(nsresult aResult); - - TX_DECL_MATCH_CONTEXT; - - /** - * Struct holding information about a current template rule - */ - struct TemplateRule { - txStylesheet::ImportFrame* mFrame; - PRInt32 mModeNsId; - nsIAtom* mModeLocalName; - txVariableMap* mParams; - }; - - // Stack functions - nsresult pushEvalContext(txIEvalContext* aContext); - txIEvalContext* popEvalContext(); - nsresult pushString(const nsAString& aStr); - void popString(nsAString& aStr); - nsresult pushInt(PRInt32 aInt); - PRInt32 popInt(); - nsresult pushResultHandler(txAXMLEventHandler* aHandler); - txAXMLEventHandler* popResultHandler(); - nsresult pushTemplateRule(txStylesheet::ImportFrame* aFrame, - const txExpandedName& aMode, - txVariableMap* aParams); - void popTemplateRule(); - nsresult pushParamMap(txVariableMap* aParams); - txVariableMap* popParamMap(); - - // state-getting functions - txIEvalContext* getEvalContext(); - txExpandedNameMap* getParamMap(); - const txXPathNode* retrieveDocument(const nsAString& aUri); - nsresult getKeyNodes(const txExpandedName& aKeyName, - const txXPathNode& aDocument, - const nsAString& aKeyValue, PRBool aIndexIfNotFound, - txNodeSet** aResult); - TemplateRule* getCurrentTemplateRule(); - - // state-modification functions - txInstruction* getNextInstruction(); - nsresult runTemplate(txInstruction* aInstruction); - nsresult runTemplate(txInstruction* aInstruction, - txInstruction* aReturnTo); - void gotoInstruction(txInstruction* aNext); - void returnFromTemplate(); - nsresult bindVariable(const txExpandedName& aName, - txAExprResult* aValue); - void removeVariable(const txExpandedName& aName); - - txAXMLEventHandler* mOutputHandler; - txAXMLEventHandler* mResultHandler; - txAOutputHandlerFactory* mOutputHandlerFactory; - - nsAutoPtr mTemplateParams; - - nsRefPtr mStylesheet; - -private: - txStack mReturnStack; - txStack mLocalVarsStack; - txStack mEvalContextStack; - txStack mIntStack; - txStack mResultHandlerStack; - txStack mParamStack; - nsStringArray mStringStack; - txInstruction* mNextInstruction; - txVariableMap* mLocalVariables; - txVariableMap mGlobalVariableValues; - nsRefPtr mGlobalVarPlaceholderValue; - PRInt32 mRecursionDepth; - - TemplateRule* mTemplateRules; - PRInt32 mTemplateRulesBufferSize; - PRInt32 mTemplateRuleCount; - - txIEvalContext* mEvalContext; - txIEvalContext* mInitialEvalContext; - //Document* mRTFDocument; - txExpandedNameMap* mGlobalParams; - - txLoadedDocumentsHash mLoadedDocuments; - txKeyHash mKeyHash; - nsRefPtr mRecycler; - - static const PRInt32 kMaxRecursionDepth; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txHTMLAtomList.h b/extensions/transformiix/source/xslt/txHTMLAtomList.h deleted file mode 100644 index a786381557b2..000000000000 --- a/extensions/transformiix/source/xslt/txHTMLAtomList.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// OUTPUT_CLASS=txHTMLAtoms -// MACRO_NAME=TX_ATOM - -TX_ATOM(area, "area") -TX_ATOM(base, "base") -TX_ATOM(basefont, "basefont") -TX_ATOM(br, "br") -TX_ATOM(button, "button") -TX_ATOM(checked, "checked") -TX_ATOM(col, "col") -TX_ATOM(compact, "compact") -TX_ATOM(content, "content") -TX_ATOM(declare, "declare") -TX_ATOM(defer, "defer") -TX_ATOM(dir, "dir") -TX_ATOM(disabled, "disabled") -TX_ATOM(dl, "dl") -TX_ATOM(frame, "frame") -TX_ATOM(headerDefaultStyle, "default-style") -TX_ATOM(head, "head") -TX_ATOM(hr, "hr") -TX_ATOM(href, "href") -TX_ATOM(httpEquiv, "http-equiv") -TX_ATOM(img, "img") -TX_ATOM(input, "input") -TX_ATOM(isindex, "isindex") -TX_ATOM(ismap, "ismap") -TX_ATOM(li, "li") -TX_ATOM(link, "link") -TX_ATOM(media, "media") -TX_ATOM(menu, "menu") -TX_ATOM(meta, "meta") -TX_ATOM(multiple, "multiple") -TX_ATOM(noresize, "noresize") -TX_ATOM(noshade, "noshade") -TX_ATOM(nowrap, "nowrap") -TX_ATOM(object, "object") -TX_ATOM(ol, "ol") -TX_ATOM(optgroup, "optgroup") -TX_ATOM(option, "option") -TX_ATOM(p, "p") -TX_ATOM(param, "param") -TX_ATOM(readonly, "readonly") -TX_ATOM(refresh, "refresh") -TX_ATOM(script, "script") -TX_ATOM(select, "select") -TX_ATOM(selected, "selected") -TX_ATOM(src, "src") -TX_ATOM(style, "style") -TX_ATOM(table, "table") -TX_ATOM(target, "target") -TX_ATOM(tbody, "tbody") -TX_ATOM(td, "td") -TX_ATOM(textarea, "textarea") -TX_ATOM(th, "th") -TX_ATOM(title, "title") -TX_ATOM(tr, "tr") -TX_ATOM(type, "type") -TX_ATOM(ul, "ul") diff --git a/extensions/transformiix/source/xslt/txHTMLOutput.cpp b/extensions/transformiix/source/xslt/txHTMLOutput.cpp deleted file mode 100644 index f2396256bf2e..000000000000 --- a/extensions/transformiix/source/xslt/txHTMLOutput.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txHTMLOutput.h" -#include "nsCOMArray.h" -#include "nsStaticNameTable.h" -#include "txAtoms.h" -#include "txOutputFormat.h" -#include "txStringUtils.h" -#include "XMLUtils.h" - -#define EMPTY_ELEMENTS_COUNT 13 -const char* const kHTMLEmptyTags[] = -{ - "area", - "base", - "basefont", - "br", - "col", - "frame", - "hr", - "img", - "input", - "isindex", - "link", - "meta", - "param" -}; - -#define SHORTHAND_ATTR_COUNT 12 -const char* const kHTMLEmptyAttributes[] = -{ - "checked", - "compact", - "declare", - "defer", - "disabled", - "ismap", - "multiple", - "noresize", - "noshade", - "nowrap", - "readonly", - "selected" -}; - -struct txEmptyAttributesMaps -{ - typedef nsCOMArray EmptyAttrBag; - EmptyAttrBag mMaps[SHORTHAND_ATTR_COUNT]; -}; - -static PRInt32 gTableRefCount; -static nsStaticCaseInsensitiveNameTable* gHTMLEmptyTagsTable; -static nsStaticCaseInsensitiveNameTable* gHTMLEmptyAttributesTable; -static txEmptyAttributesMaps* gHTMLEmptyAttributesMaps; - -/* static */ -nsresult -txHTMLOutput::init() -{ - if (0 == gTableRefCount++) { - NS_ASSERTION(!gHTMLEmptyTagsTable, "pre existing array!"); - gHTMLEmptyTagsTable = new nsStaticCaseInsensitiveNameTable(); - if (!gHTMLEmptyTagsTable) { - return NS_ERROR_OUT_OF_MEMORY; - } - - gHTMLEmptyTagsTable->Init(kHTMLEmptyTags, EMPTY_ELEMENTS_COUNT); - - NS_ASSERTION(!gHTMLEmptyAttributesTable, "pre existing array!"); - gHTMLEmptyAttributesTable = new nsStaticCaseInsensitiveNameTable(); - if (!gHTMLEmptyAttributesTable) { - return NS_ERROR_OUT_OF_MEMORY; - } - - gHTMLEmptyAttributesTable->Init(kHTMLEmptyAttributes, - SHORTHAND_ATTR_COUNT); - - NS_ASSERTION(!gHTMLEmptyAttributesMaps, "pre existing map!"); - gHTMLEmptyAttributesMaps = new txEmptyAttributesMaps(); - if (!gHTMLEmptyAttributesMaps) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // checked - gHTMLEmptyAttributesMaps->mMaps[0].AppendObject(txHTMLAtoms::input); - - // compact - gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dir); - gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dl); - gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::menu); - gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ol); - gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ul); - - // declare - gHTMLEmptyAttributesMaps->mMaps[2].AppendObject(txHTMLAtoms::object); - - // defer - gHTMLEmptyAttributesMaps->mMaps[3].AppendObject(txHTMLAtoms::script); - - // disabled - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::button); - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::input); - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::optgroup); - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::option); - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::select); - gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::textarea); - - // ismap - gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::img); - gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::input); - - // multiple - gHTMLEmptyAttributesMaps->mMaps[6].AppendObject(txHTMLAtoms::select); - - // noresize - gHTMLEmptyAttributesMaps->mMaps[7].AppendObject(txHTMLAtoms::frame); - - // noshade - gHTMLEmptyAttributesMaps->mMaps[8].AppendObject(txHTMLAtoms::hr); - - // nowrap - gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::td); - gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::th); - - // readonly - gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::input); - gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::textarea); - - // selected - gHTMLEmptyAttributesMaps->mMaps[11].AppendObject(txHTMLAtoms::option); - } - - return NS_OK; -} - -/* static */ -void -txHTMLOutput::shutdown() -{ - if (0 == --gTableRefCount) { - if (gHTMLEmptyTagsTable) { - delete gHTMLEmptyTagsTable; - gHTMLEmptyTagsTable = nsnull; - } - if (gHTMLEmptyAttributesTable) { - delete gHTMLEmptyAttributesTable; - gHTMLEmptyAttributesTable = nsnull; - } - if (gHTMLEmptyAttributesMaps) { - delete gHTMLEmptyAttributesMaps; - gHTMLEmptyAttributesMaps = nsnull; - } - } -} - -txHTMLOutput::txHTMLOutput(txOutputFormat* aFormat, ostream* aOut) - : txXMLOutput(aFormat, aOut) -{ - mUseEmptyElementShorthand = PR_FALSE; -} - -txHTMLOutput::~txHTMLOutput() -{ -} - -void txHTMLOutput::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ - if (!mStartTagOpen) - // XXX Signal this? (can't add attributes after element closed) - return; - - MBool shortHand = MB_FALSE; - if (aNsID == kNameSpaceID_None) { - const nsAString& localPart = XMLUtils::getLocalPart(aName); - shortHand = isShorthandAttribute(localPart); - if (shortHand && - localPart.Equals(aValue, txCaseInsensitiveStringComparator())) { - txListIterator iter(&mAttributes); - txOutAttr* setAtt = 0; - nsCOMPtr localName = do_GetAtom(localPart); - txExpandedName att(aNsID, localName); - while ((setAtt = (txOutAttr*)iter.next())) { - if (setAtt->mName == att) { - setAtt->mShorthand = MB_TRUE; - break; - } - } - if (!setAtt) { - setAtt = new txOutAttr(aNsID, localName, EmptyString()); - setAtt->mShorthand = MB_TRUE; - mAttributes.add(setAtt); - } - } - } - if (!shortHand) - txXMLOutput::attribute(aName, aNsID, aValue); -} - -void txHTMLOutput::characters(const nsAString& aData, PRBool aDOE) -{ - if (aDOE) { - closeStartTag(MB_FALSE); - printUTF8Chars(aData); - - return; - } - - // Special-case script and style - if (!mCurrentElements.isEmpty()) { - txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek(); - if (currentElement->mNamespaceID == kNameSpaceID_None && - (currentElement->mLocalName == txHTMLAtoms::script || - currentElement->mLocalName == txHTMLAtoms::style)) { - closeStartTag(MB_FALSE); - printUTF8Chars(aData); - return; - } - } - txXMLOutput::characters(aData, aDOE); -} - -void txHTMLOutput::endElement(const nsAString& aName, - const PRInt32 aNsID) -{ - const nsAString& localPart = XMLUtils::getLocalPart(aName); - if ((aNsID == kNameSpaceID_None) && isShorthandElement(localPart) && - mStartTagOpen) { - MBool newLine = (mOutputFormat.mIndent == eTrue) && - mAfterEndTag; - closeStartTag(MB_FALSE); - if (newLine) - *mOut << endl; - if (mOutputFormat.mIndent == eTrue) - mIndentLevel -= DEFAULT_INDENT; - mAfterEndTag = MB_TRUE; - } - else { - txXMLOutput::endElement(aName, aNsID); - } - delete (txExpandedName*)mCurrentElements.pop(); -} - -void txHTMLOutput::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ - closeStartTag(MB_FALSE); - if (mOutputFormat.mIndent == eTrue) { - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - *mOut << PI_START; - printUTF8Chars(aTarget); - *mOut << SPACE; - printUTF8Chars(aData); - *mOut << R_ANGLE_BRACKET; - if (mOutputFormat.mIndent == eTrue) - *mOut << endl; -} - -void txHTMLOutput::startDocument() -{ - // XXX Should be using mOutputFormat.getVersion - *mOut << DOCTYPE_START << "html " << PUBLIC; - *mOut << " \"-//W3C//DTD HTML 4.0 Transitional//EN\""; - *mOut << " \"http://www.w3.org/TR/REC-html40/loose.dtd\""; - *mOut << DOCTYPE_END << endl; -} - -void txHTMLOutput::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ - txXMLOutput::startElement(aName, aNsID); - - nsCOMPtr localAtom; - if (aNsID == kNameSpaceID_None) { - nsAutoString localName; - TX_ToLowerCase(aName, localName); - localAtom = do_GetAtom(localName); - } - else { - localAtom = do_GetAtom(aName); - } - NS_ASSERTION(localAtom, "Can't get atom"); - txExpandedName* currentElement = new txExpandedName(aNsID, localAtom); - NS_ASSERTION(currentElement, "Can't create currentElement"); - if (currentElement) - mCurrentElements.push(currentElement); -} - -void txHTMLOutput::closeStartTag(MBool aUseEmptyElementShorthand) -{ - txExpandedName* currentElement = mCurrentElements.isEmpty() ? - nsnull : (txExpandedName*)mCurrentElements.peek(); - if (mStartTagOpen && currentElement && - (currentElement->mNamespaceID == kNameSpaceID_None) && - (currentElement->mLocalName == txHTMLAtoms::head)) { - txXMLOutput::closeStartTag(MB_FALSE); - if (mOutputFormat.mIndent == eTrue) { - *mOut << endl; - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - *mOut << LT << "meta http-equiv=" << QUOTE << "Content-Type" << QUOTE; - *mOut << " content=" << QUOTE; - printUTF8Chars(mOutputFormat.mMediaType); - *mOut << "; charset="; - printUTF8Chars(mOutputFormat.mEncoding); - *mOut << QUOTE << GT; - } - else { - txXMLOutput::closeStartTag(aUseEmptyElementShorthand); - } -} - -MBool txHTMLOutput::isShorthandElement(const nsAString& aLocalName) -{ - return (gHTMLEmptyTagsTable->Lookup(aLocalName) != - nsStaticCaseInsensitiveNameTable::NOT_FOUND); -} - -MBool txHTMLOutput::isShorthandAttribute(const nsAString& aLocalName) -{ - PRInt32 index = gHTMLEmptyTagsTable->Lookup(aLocalName); - if (index == nsStaticCaseInsensitiveNameTable::NOT_FOUND) { - return PR_FALSE; - } - - txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek(); - return (gHTMLEmptyAttributesMaps->mMaps[index].IndexOf(currentElement->mLocalName) > -1); -} diff --git a/extensions/transformiix/source/xslt/txHTMLOutput.h b/extensions/transformiix/source/xslt/txHTMLOutput.h deleted file mode 100644 index 82c5773ad948..000000000000 --- a/extensions/transformiix/source/xslt/txHTMLOutput.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_HTML_OUTPUT_H -#define TRANSFRMX_HTML_OUTPUT_H - -#include "txXMLOutput.h" - -class txHTMLOutput : public txXMLOutput -{ -public: - txHTMLOutput(txOutputFormat* aFormat, ostream* aOut); - ~txHTMLOutput(); - - /** - * Init/release table with shorthands. - */ - static nsresult init(); - static void shutdown(); - - void attribute(const nsAString& aName, const PRInt32 aNsID, - const nsAString& aValue); - void characters(const nsAString& aData, PRBool aDOE); - void endElement(const nsAString& aName, const PRInt32 aNsID); - void processingInstruction(const nsAString& aTarget, - const nsAString& aData); - void startDocument(); - void startElement(const nsAString& aName, const PRInt32 aNsID); - TX_DECL_TXAOUTPUTXMLEVENTHANDLER - -private: - void closeStartTag(MBool aUseEmptyElementShorthand); - MBool isShorthandElement(const nsAString& aName); - MBool isShorthandAttribute(const nsAString& aLocalName); - - txStack mCurrentElements; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txInstructions.cpp b/extensions/transformiix/source/xslt/txInstructions.cpp deleted file mode 100644 index 2412f0f31476..000000000000 --- a/extensions/transformiix/source/xslt/txInstructions.cpp +++ /dev/null @@ -1,1052 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txInstructions.h" -#include "txError.h" -#include "Expr.h" -#include "ExprResult.h" -#include "txStylesheet.h" -#include "txNodeSetContext.h" -#include "txTextHandler.h" -#include "nsIConsoleService.h" -#include "nsServiceManagerUtils.h" -#include "txStringUtils.h" -#include "txAtoms.h" -#include "txRtfHandler.h" -#include "txNodeSorter.h" -#include "txXSLTNumber.h" -#include "txExecutionState.h" - -nsresult -txApplyDefaultElementTemplate::execute(txExecutionState& aEs) -{ - txExecutionState::TemplateRule* rule = aEs.getCurrentTemplateRule(); - txExpandedName mode(rule->mModeNsId, rule->mModeLocalName); - txStylesheet::ImportFrame* frame = 0; - txInstruction* templ = - aEs.mStylesheet->findTemplate(aEs.getEvalContext()->getContextNode(), - mode, &aEs, nsnull, &frame); - - nsresult rv = aEs.pushTemplateRule(frame, mode, aEs.mTemplateParams); - NS_ENSURE_SUCCESS(rv, rv); - - return aEs.runTemplate(templ); -} - -nsresult -txApplyImportsEnd::execute(txExecutionState& aEs) -{ - aEs.popTemplateRule(); - aEs.popParamMap(); - - return NS_OK; -} - -nsresult -txApplyImportsStart::execute(txExecutionState& aEs) -{ - txExecutionState::TemplateRule* rule = aEs.getCurrentTemplateRule(); - // The frame is set to null when there is no current template rule, or - // when the current template rule is a default template. However this - // instruction isn't used in default templates. - if (!rule->mFrame) { - // XXX ErrorReport: apply-imports instantiated without a current rule - return NS_ERROR_XSLT_EXECUTION_FAILURE; - } - - nsresult rv = aEs.pushParamMap(rule->mParams); - NS_ENSURE_SUCCESS(rv, rv); - - txStylesheet::ImportFrame* frame = 0; - txExpandedName mode(rule->mModeNsId, rule->mModeLocalName); - txInstruction* templ = - aEs.mStylesheet->findTemplate(aEs.getEvalContext()->getContextNode(), - mode, &aEs, rule->mFrame, &frame); - - rv = aEs.pushTemplateRule(frame, mode, rule->mParams); - NS_ENSURE_SUCCESS(rv, rv); - - return aEs.runTemplate(templ); -} - -txApplyTemplates::txApplyTemplates(const txExpandedName& aMode) - : mMode(aMode) -{ -} - -nsresult -txApplyTemplates::execute(txExecutionState& aEs) -{ - txStylesheet::ImportFrame* frame = 0; - txInstruction* templ = - aEs.mStylesheet->findTemplate(aEs.getEvalContext()->getContextNode(), - mMode, &aEs, nsnull, &frame); - - nsresult rv = aEs.pushTemplateRule(frame, mMode, aEs.mTemplateParams); - NS_ENSURE_SUCCESS(rv, rv); - - return aEs.runTemplate(templ); -} - -txAttribute::txAttribute(nsAutoPtr aName, nsAutoPtr aNamespace, - txNamespaceMap* aMappings) - : mName(aName), - mNamespace(aNamespace), - mMappings(aMappings) -{ -} - -nsresult -txAttribute::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mName->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString name; - exprRes->stringValue(name); - - const PRUnichar* colon; - if (!XMLUtils::isValidQName(name, &colon) || - TX_StringEqualsAtom(name, txXMLAtoms::xmlns)) { - // truncate name to indicate failure - name.Truncate(); - } - - nsCOMPtr prefix; - if (colon) { - prefix = do_GetAtom(Substring(name.get(), colon)); - } - - PRInt32 nsId = kNameSpaceID_None; - if (!name.IsEmpty()) { - if (mNamespace) { - rv = mNamespace->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString nspace; - exprRes->stringValue(nspace); - - if (!nspace.IsEmpty()) { - nsId = txNamespaceManager::getNamespaceID(nspace); - NS_ENSURE_FALSE(nsId == kNameSpaceID_Unknown, - NS_ERROR_FAILURE); - } - } - else if (prefix) { - nsId = mMappings->lookupNamespace(prefix); - if (nsId == kNameSpaceID_Unknown) { - // tunkate name to indicate failure - name.Truncate(); - } - } - } - - if (prefix == txXMLAtoms::xmlns) { - // Cut xmlns: (6 characters) - name.Cut(0, 6); - } - - nsAutoPtr handler( - NS_STATIC_CAST(txTextHandler*, aEs.popResultHandler())); - if (!name.IsEmpty()) { - // add attribute if everything was ok - aEs.mResultHandler->attribute(name, nsId, handler->mValue); - } - - return NS_OK; -} - -txCallTemplate::txCallTemplate(const txExpandedName& aName) - : mName(aName) -{ -} - -nsresult -txCallTemplate::execute(txExecutionState& aEs) -{ - txInstruction* instr = aEs.mStylesheet->getNamedTemplate(mName); - NS_ENSURE_TRUE(instr, NS_ERROR_XSLT_EXECUTION_FAILURE); - - nsresult rv = aEs.runTemplate(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -txCheckParam::txCheckParam(const txExpandedName& aName) - : mName(aName), mBailTarget(nsnull) -{ -} - -nsresult -txCheckParam::execute(txExecutionState& aEs) -{ - nsresult rv = NS_OK; - if (aEs.mTemplateParams) { - nsRefPtr exprRes; - aEs.mTemplateParams->getVariable(mName, getter_AddRefs(exprRes)); - if (exprRes) { - rv = aEs.bindVariable(mName, exprRes); - NS_ENSURE_SUCCESS(rv, rv); - - aEs.gotoInstruction(mBailTarget); - } - } - - return NS_OK; -} - -txConditionalGoto::txConditionalGoto(nsAutoPtr aCondition, - txInstruction* aTarget) - : mCondition(aCondition), - mTarget(aTarget) -{ -} - -nsresult -txConditionalGoto::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mCondition->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (!exprRes->booleanValue()) { - aEs.gotoInstruction(mTarget); - } - - return NS_OK; -} - -nsresult -txComment::execute(txExecutionState& aEs) -{ - nsAutoPtr handler( - NS_STATIC_CAST(txTextHandler*, aEs.popResultHandler())); - PRUint32 length = handler->mValue.Length(); - PRInt32 pos = 0; - while ((pos = handler->mValue.FindChar('-', (PRUint32)pos)) != kNotFound) { - ++pos; - if ((PRUint32)pos == length || handler->mValue.CharAt(pos) == '-') { - handler->mValue.Insert(PRUnichar(' '), pos++); - ++length; - } - } - - aEs.mResultHandler->comment(handler->mValue); - - return NS_OK; -} - -nsresult -txCopyBase::copyNode(const txXPathNode& aNode, txExecutionState& aEs) -{ - switch (txXPathNodeUtils::getNodeType(aNode)) { - case txXPathNodeType::ATTRIBUTE_NODE: - { - nsAutoString nodeName, nodeValue; - txXPathNodeUtils::getNodeName(aNode, nodeName); - txXPathNodeUtils::appendNodeValue(aNode, nodeValue); - aEs.mResultHandler->attribute(nodeName, - txXPathNodeUtils::getNamespaceID(aNode), - nodeValue); - break; - } - case txXPathNodeType::COMMENT_NODE: - { - nsAutoString nodeValue; - txXPathNodeUtils::appendNodeValue(aNode, nodeValue); - aEs.mResultHandler->comment(nodeValue); - break; - } - case txXPathNodeType::DOCUMENT_NODE: - case txXPathNodeType::DOCUMENT_FRAGMENT_NODE: - { - // Copy children - txXPathTreeWalker walker(aNode); - PRBool hasChild = walker.moveToFirstChild(); - while (hasChild) { - copyNode(walker.getCurrentPosition(), aEs); - hasChild = walker.moveToNextSibling(); - } - break; - } - case txXPathNodeType::ELEMENT_NODE: - { - nsAutoString name; - txXPathNodeUtils::getNodeName(aNode, name); - PRInt32 nsID = txXPathNodeUtils::getNamespaceID(aNode); - aEs.mResultHandler->startElement(name, nsID); - - // Copy attributes - txXPathTreeWalker walker(aNode); - if (walker.moveToFirstAttribute()) { - do { - nsAutoString nodeName, nodeValue; - walker.getNodeName(nodeName); - walker.appendNodeValue(nodeValue); - aEs.mResultHandler->attribute(nodeName, - walker.getNamespaceID(), - nodeValue); - } while (walker.moveToNextAttribute()); - walker.moveToParent(); - } - - // Copy children - PRBool hasChild = walker.moveToFirstChild(); - while (hasChild) { - copyNode(walker.getCurrentPosition(), aEs); - hasChild = walker.moveToNextSibling(); - } - - aEs.mResultHandler->endElement(name, nsID); - break; - } - case txXPathNodeType::PROCESSING_INSTRUCTION_NODE: - { - nsAutoString target, data; - txXPathNodeUtils::getNodeName(aNode, target); - txXPathNodeUtils::appendNodeValue(aNode, data); - aEs.mResultHandler->processingInstruction(target, data); - break; - } - case txXPathNodeType::TEXT_NODE: - case txXPathNodeType::CDATA_SECTION_NODE: - { - nsAutoString nodeValue; - txXPathNodeUtils::appendNodeValue(aNode, nodeValue); - aEs.mResultHandler->characters(nodeValue, PR_FALSE); - break; - } - } - - return NS_OK; -} - -txCopy::txCopy() - : mBailTarget(nsnull) -{ -} - -nsresult -txCopy::execute(txExecutionState& aEs) -{ - nsresult rv = NS_OK; - const txXPathNode& node = aEs.getEvalContext()->getContextNode(); - - switch (txXPathNodeUtils::getNodeType(node)) { - case txXPathNodeType::DOCUMENT_NODE: - { - const nsAFlatString& empty = EmptyString(); - - // "close" current element to ensure that no attributes are added - aEs.mResultHandler->characters(empty, PR_FALSE); - - rv = aEs.pushString(empty); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aEs.pushInt(kNameSpaceID_None); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - case txXPathNodeType::ELEMENT_NODE: - { - nsAutoString nodeName; - txXPathNodeUtils::getNodeName(node, nodeName); - PRInt32 nsID = txXPathNodeUtils::getNamespaceID(node); - - aEs.mResultHandler->startElement(nodeName, nsID); - // XXX copy namespace nodes once we have them - - rv = aEs.pushString(nodeName); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aEs.pushInt(nsID); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - default: - { - rv = copyNode(node, aEs); - NS_ENSURE_SUCCESS(rv, rv); - - aEs.gotoInstruction(mBailTarget); - } - } - - return NS_OK; -} - -txCopyOf::txCopyOf(nsAutoPtr aSelect) - : mSelect(aSelect) -{ -} - -nsresult -txCopyOf::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mSelect->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - switch (exprRes->getResultType()) { - case txAExprResult::NODESET: - { - txNodeSet* nodes = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprRes)); - PRInt32 i; - for (i = 0; i < nodes->size(); ++i) { - rv = copyNode(nodes->get(i), aEs); - NS_ENSURE_SUCCESS(rv, rv); - } - break; - } - case txAExprResult::RESULT_TREE_FRAGMENT: - { - txResultTreeFragment* rtf = - NS_STATIC_CAST(txResultTreeFragment*, - NS_STATIC_CAST(txAExprResult*, exprRes)); - rv = rtf->flushToHandler(aEs.mResultHandler); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - default: - { - nsAutoString value; - exprRes->stringValue(value); - if (!value.IsEmpty()) { - aEs.mResultHandler->characters(value, PR_FALSE); - } - break; - } - } - - return NS_OK; -} - -nsresult -txEndElement::execute(txExecutionState& aEs) -{ - PRInt32 namespaceID = aEs.popInt(); - nsAutoString nodeName; - aEs.popString(nodeName); - - - // For xsl:elements with a bad name we push an empty name - if (!nodeName.IsEmpty()) { - aEs.mResultHandler->endElement(nodeName, namespaceID); - } - - return NS_OK; -} - -nsresult -txErrorInstruction::execute(txExecutionState& aEs) -{ - // XXX ErrorReport: unknown instruction executed - return NS_ERROR_XSLT_EXECUTION_FAILURE; -} - -txGoTo::txGoTo(txInstruction* aTarget) - : mTarget(aTarget) -{ -} - -nsresult -txGoTo::execute(txExecutionState& aEs) -{ - aEs.gotoInstruction(mTarget); - - return NS_OK; -} - -txInsertAttrSet::txInsertAttrSet(const txExpandedName& aName) - : mName(aName) -{ -} - -nsresult -txInsertAttrSet::execute(txExecutionState& aEs) -{ - txInstruction* instr = aEs.mStylesheet->getAttributeSet(mName); - NS_ENSURE_TRUE(instr, NS_ERROR_XSLT_EXECUTION_FAILURE); - - nsresult rv = aEs.runTemplate(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -txLoopNodeSet::txLoopNodeSet(txInstruction* aTarget) - : mTarget(aTarget) -{ -} - -nsresult -txLoopNodeSet::execute(txExecutionState& aEs) -{ - aEs.popTemplateRule(); - txNodeSetContext* context = - NS_STATIC_CAST(txNodeSetContext*, aEs.getEvalContext()); - if (!context->hasNext()) { - delete aEs.popEvalContext(); - - return NS_OK; - } - - context->next(); - aEs.gotoInstruction(mTarget); - - return NS_OK; -} - -txLREAttribute::txLREAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix, nsAutoPtr aValue) - : mNamespaceID(aNamespaceID), - mLocalName(aLocalName), - mPrefix(aPrefix), - mValue(aValue) -{ -} - -nsresult -txLREAttribute::execute(txExecutionState& aEs) -{ - // We should atomize the resulthandler - nsAutoString nodeName; - if (mPrefix) { - mPrefix->ToString(nodeName); - nsAutoString localName; - nodeName.Append(PRUnichar(':')); - mLocalName->ToString(localName); - nodeName.Append(localName); - } - else { - mLocalName->ToString(nodeName); - } - - nsRefPtr exprRes; - nsresult rv = mValue->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAString* value = exprRes->stringValuePointer(); - if (value) { - aEs.mResultHandler->attribute(nodeName, mNamespaceID, *value); - } - else { - nsAutoString valueStr; - exprRes->stringValue(valueStr); - aEs.mResultHandler->attribute(nodeName, mNamespaceID, valueStr); - } - - return NS_OK; -} - -txMessage::txMessage(PRBool aTerminate) - : mTerminate(aTerminate) -{ -} - -nsresult -txMessage::execute(txExecutionState& aEs) -{ - nsAutoPtr handler( - NS_STATIC_CAST(txTextHandler*, aEs.popResultHandler())); - - nsCOMPtr consoleSvc = - do_GetService("@mozilla.org/consoleservice;1"); - if (consoleSvc) { - nsAutoString logString(NS_LITERAL_STRING("xsl:message - ")); - logString.Append(handler->mValue); - consoleSvc->LogStringMessage(logString.get()); - } - - return mTerminate ? NS_ERROR_XSLT_ABORTED : NS_OK; -} - -txNumber::txNumber(txXSLTNumber::LevelType aLevel, nsAutoPtr aCount, - nsAutoPtr aFrom, nsAutoPtr aValue, - nsAutoPtr aFormat, nsAutoPtr aGroupingSeparator, - nsAutoPtr aGroupingSize) - : mLevel(aLevel), mCount(aCount), mFrom(aFrom), mValue(aValue), - mFormat(aFormat), mGroupingSeparator(aGroupingSeparator), - mGroupingSize(aGroupingSize) -{ -} - -nsresult -txNumber::execute(txExecutionState& aEs) -{ - nsAutoString res; - nsresult rv = - txXSLTNumber::createNumber(mValue, mCount, mFrom, mLevel, mGroupingSize, - mGroupingSeparator, mFormat, - aEs.getEvalContext(), res); - NS_ENSURE_SUCCESS(rv, rv); - - aEs.mResultHandler->characters(res, PR_FALSE); - - return NS_OK; -} - -nsresult -txPopParams::execute(txExecutionState& aEs) -{ - delete aEs.popParamMap(); - - return NS_OK; -} - -txProcessingInstruction::txProcessingInstruction(nsAutoPtr aName) - : mName(aName) -{ -} - -nsresult -txProcessingInstruction::execute(txExecutionState& aEs) -{ - nsAutoPtr handler( - NS_STATIC_CAST(txTextHandler*, aEs.popResultHandler())); - XMLUtils::normalizePIValue(handler->mValue); - - nsRefPtr exprRes; - nsresult rv = mName->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString name; - exprRes->stringValue(name); - - // Check name validity (must be valid NCName and a PITarget) - // XXX Need to check for NCName and PITarget - const PRUnichar* colon; - if (!XMLUtils::isValidQName(name, &colon)) { - // XXX ErrorReport: bad PI-target - return NS_ERROR_FAILURE; - } - - aEs.mResultHandler->processingInstruction(name, handler->mValue); - - return NS_OK; -} - -txPushNewContext::txPushNewContext(nsAutoPtr aSelect) - : mSelect(aSelect), mBailTarget(nsnull) -{ -} - -txPushNewContext::~txPushNewContext() -{ - PRInt32 i; - for (i = 0; i < mSortKeys.Count(); ++i) - { - delete NS_STATIC_CAST(SortKey*, mSortKeys[i]); - } -} - -nsresult -txPushNewContext::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mSelect->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - if (exprRes->getResultType() != txAExprResult::NODESET) { - // XXX ErrorReport: nodeset expected - return NS_ERROR_XSLT_NODESET_EXPECTED; - } - - txNodeSet* nodes = NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, - exprRes)); - - if (nodes->isEmpty()) { - aEs.gotoInstruction(mBailTarget); - - return NS_OK; - } - - txNodeSorter sorter; - PRInt32 i, count = mSortKeys.Count(); - for (i = 0; i < count; ++i) { - SortKey* sort = NS_STATIC_CAST(SortKey*, mSortKeys[i]); - rv = sorter.addSortElement(sort->mSelectExpr, sort->mLangExpr, - sort->mDataTypeExpr, sort->mOrderExpr, - sort->mCaseOrderExpr, - aEs.getEvalContext()); - NS_ENSURE_SUCCESS(rv, rv); - } - nsRefPtr sortedNodes; - rv = sorter.sortNodeSet(nodes, &aEs, getter_AddRefs(sortedNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - txNodeSetContext* context = new txNodeSetContext(sortedNodes, &aEs); - NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY); - - context->next(); - - rv = aEs.pushEvalContext(context); - if (NS_FAILED(rv)) { - delete context; - return rv; - } - - return NS_OK; -} - -nsresult -txPushNewContext::addSort(nsAutoPtr aSelectExpr, - nsAutoPtr aLangExpr, - nsAutoPtr aDataTypeExpr, - nsAutoPtr aOrderExpr, - nsAutoPtr aCaseOrderExpr) -{ - SortKey* sort = new SortKey(aSelectExpr, aLangExpr, aDataTypeExpr, - aOrderExpr, aCaseOrderExpr); - NS_ENSURE_TRUE(sort, NS_ERROR_OUT_OF_MEMORY); - - if (!mSortKeys.AppendElement(sort)) { - delete sort; - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -txPushNewContext::SortKey::SortKey(nsAutoPtr aSelectExpr, - nsAutoPtr aLangExpr, - nsAutoPtr aDataTypeExpr, - nsAutoPtr aOrderExpr, - nsAutoPtr aCaseOrderExpr) - : mSelectExpr(aSelectExpr), mLangExpr(aLangExpr), - mDataTypeExpr(aDataTypeExpr), mOrderExpr(aOrderExpr), - mCaseOrderExpr(aCaseOrderExpr) -{ -} - -nsresult -txPushNullTemplateRule::execute(txExecutionState& aEs) -{ - return aEs.pushTemplateRule(nsnull, txExpandedName(), nsnull); -} - -nsresult -txPushParams::execute(txExecutionState& aEs) -{ - return aEs.pushParamMap(nsnull); -} - -nsresult -txPushRTFHandler::execute(txExecutionState& aEs) -{ - txAXMLEventHandler* handler = new txRtfHandler; - NS_ENSURE_TRUE(handler, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aEs.pushResultHandler(handler); - if (NS_FAILED(rv)) { - delete handler; - return rv; - } - - return NS_OK; -} - -txPushStringHandler::txPushStringHandler(PRBool aOnlyText) - : mOnlyText(aOnlyText) -{ -} - -nsresult -txPushStringHandler::execute(txExecutionState& aEs) -{ - txAXMLEventHandler* handler = new txTextHandler(mOnlyText); - NS_ENSURE_TRUE(handler, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aEs.pushResultHandler(handler); - if (NS_FAILED(rv)) { - delete handler; - return rv; - } - - return NS_OK; -} - -txRemoveVariable::txRemoveVariable(const txExpandedName& aName) - : mName(aName) -{ -} - -nsresult -txRemoveVariable::execute(txExecutionState& aEs) -{ - aEs.removeVariable(mName); - - return NS_OK; -} - -nsresult -txReturn::execute(txExecutionState& aEs) -{ - NS_ASSERTION(!mNext, "instructions exist after txReturn"); - aEs.returnFromTemplate(); - - return NS_OK; -} - -txSetParam::txSetParam(const txExpandedName& aName, nsAutoPtr aValue) - : mName(aName), mValue(aValue) -{ -} - -nsresult -txSetParam::execute(txExecutionState& aEs) -{ - nsresult rv = NS_OK; - if (!aEs.mTemplateParams) { - aEs.mTemplateParams = new txVariableMap; - NS_ENSURE_TRUE(aEs.mTemplateParams, NS_ERROR_OUT_OF_MEMORY); - } - - nsRefPtr exprRes; - if (mValue) { - rv = mValue->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - nsAutoPtr rtfHandler( - NS_STATIC_CAST(txRtfHandler*, aEs.popResultHandler())); - rv = rtfHandler->getAsRTF(getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = aEs.mTemplateParams->bindVariable(mName, exprRes); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -txSetVariable::txSetVariable(const txExpandedName& aName, - nsAutoPtr aValue) - : mName(aName), mValue(aValue) -{ -} - -nsresult -txSetVariable::execute(txExecutionState& aEs) -{ - nsresult rv = NS_OK; - nsRefPtr exprRes; - if (mValue) { - rv = mValue->evaluate(aEs.getEvalContext(), getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - nsAutoPtr rtfHandler( - NS_STATIC_CAST(txRtfHandler*, aEs.popResultHandler())); - rv = rtfHandler->getAsRTF(getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - } - - return aEs.bindVariable(mName, exprRes); -} - -txStartElement::txStartElement(nsAutoPtr aName, - nsAutoPtr aNamespace, - txNamespaceMap* aMappings) - : mName(aName), - mNamespace(aNamespace), - mMappings(aMappings) -{ -} - -nsresult -txStartElement::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mName->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString name; - exprRes->stringValue(name); - - const PRUnichar* colon; - if (!XMLUtils::isValidQName(name, &colon)) { - // tunkate name to indicate failure - name.Truncate(); - } - - PRInt32 nsId = kNameSpaceID_None; - if (!name.IsEmpty()) { - if (mNamespace) { - rv = mNamespace->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString nspace; - exprRes->stringValue(nspace); - - if (!nspace.IsEmpty()) { - nsId = txNamespaceManager::getNamespaceID(nspace); - NS_ENSURE_FALSE(nsId == kNameSpaceID_Unknown, - NS_ERROR_FAILURE); - } - } - else { - nsCOMPtr prefix; - if (colon) { - prefix = do_GetAtom(Substring(name.get(), colon)); - } - nsId = mMappings->lookupNamespace(prefix); - if (nsId == kNameSpaceID_Unknown) { - // truncate name to indicate failure - name.Truncate(); - } - } - } - - if (!name.IsEmpty()) { - // add element if everything was ok - aEs.mResultHandler->startElement(name, nsId); - } - else { - // we call characters with an empty string to "close" any element to - // make sure that no attributes are added - aEs.mResultHandler->characters(EmptyString(), PR_FALSE); - } - - rv = aEs.pushString(name); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aEs.pushInt(nsId); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - - -txStartLREElement::txStartLREElement(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix) - : mNamespaceID(aNamespaceID), - mLocalName(aLocalName), - mPrefix(aPrefix) -{ -} - -nsresult -txStartLREElement::execute(txExecutionState& aEs) -{ - // We should atomize the resulthandler - nsAutoString nodeName; - if (mPrefix) { - mPrefix->ToString(nodeName); - nsAutoString localName; - nodeName.Append(PRUnichar(':')); - mLocalName->ToString(localName); - nodeName.Append(localName); - } - else { - mLocalName->ToString(nodeName); - } - - aEs.mResultHandler->startElement(nodeName, mNamespaceID); - - nsresult rv = aEs.pushString(nodeName); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aEs.pushInt(mNamespaceID); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -txText::txText(const nsAString& aStr, PRBool aDOE) - : mStr(aStr), - mDOE(aDOE) -{ -} - -nsresult -txText::execute(txExecutionState& aEs) -{ - aEs.mResultHandler->characters(mStr, mDOE); - return NS_OK; -} - -txValueOf::txValueOf(nsAutoPtr aExpr, PRBool aDOE) - : mExpr(aExpr), - mDOE(aDOE) -{ -} - -nsresult -txValueOf::execute(txExecutionState& aEs) -{ - nsRefPtr exprRes; - nsresult rv = mExpr->evaluate(aEs.getEvalContext(), - getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAString* value = exprRes->stringValuePointer(); - if (value) { - if (!value->IsEmpty()) { - aEs.mResultHandler->characters(*value, mDOE); - } - } - else { - nsAutoString valueStr; - exprRes->stringValue(valueStr); - if (!valueStr.IsEmpty()) { - aEs.mResultHandler->characters(valueStr, mDOE); - } - } - - return NS_OK; -} diff --git a/extensions/transformiix/source/xslt/txInstructions.h b/extensions/transformiix/source/xslt/txInstructions.h deleted file mode 100644 index a82f7dcb250b..000000000000 --- a/extensions/transformiix/source/xslt/txInstructions.h +++ /dev/null @@ -1,424 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXINSTRUCTIONS_H -#define TRANSFRMX_TXINSTRUCTIONS_H - -#include "nsCOMPtr.h" -#include "txCore.h" -#include "nsString.h" -#include "XMLUtils.h" -#include "txNamespaceMap.h" -#include "nsAutoPtr.h" -#include "txXSLTNumber.h" - -class nsIAtom; -class txExecutionState; - -class txInstruction : public TxObject -{ -public: - txInstruction() : mNext(0) - { - } - - virtual ~txInstruction() - { - delete mNext; - } - - virtual nsresult execute(txExecutionState& aEs) = 0; - - txInstruction* mNext; -}; - -#define TX_DECL_TXINSTRUCTION \ - virtual nsresult execute(txExecutionState& aEs); - - -class txApplyDefaultElementTemplate : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txApplyImportsEnd : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txApplyImportsStart : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txApplyTemplates : public txInstruction -{ -public: - txApplyTemplates(const txExpandedName& aMode); - - TX_DECL_TXINSTRUCTION - - txExpandedName mMode; -}; - -class txAttribute : public txInstruction -{ -public: - txAttribute(nsAutoPtr aName, nsAutoPtr aNamespace, - txNamespaceMap* aMappings); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mName; - nsAutoPtr mNamespace; - nsRefPtr mMappings; -}; - -class txCallTemplate : public txInstruction -{ -public: - txCallTemplate(const txExpandedName& aName); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; -}; - -class txCheckParam : public txInstruction -{ -public: - txCheckParam(const txExpandedName& aName); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; - txInstruction* mBailTarget; -}; - -class txConditionalGoto : public txInstruction -{ -public: - txConditionalGoto(nsAutoPtr aCondition, txInstruction* aTarget); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mCondition; - txInstruction* mTarget; -}; - -class txComment : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txCopyBase : public txInstruction -{ -protected: - nsresult copyNode(const txXPathNode& aNode, txExecutionState& aEs); -}; - -class txCopy : public txCopyBase -{ -public: - txCopy(); - - TX_DECL_TXINSTRUCTION - - txInstruction* mBailTarget; -}; - -class txCopyOf : public txCopyBase -{ -public: - txCopyOf(nsAutoPtr aSelect); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mSelect; -}; - -class txEndElement : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txErrorInstruction : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txGoTo : public txInstruction -{ -public: - txGoTo(txInstruction* aTarget); - - TX_DECL_TXINSTRUCTION - - txInstruction* mTarget; -}; - -class txInsertAttrSet : public txInstruction -{ -public: - txInsertAttrSet(const txExpandedName& aName); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; -}; - -class txLoopNodeSet : public txInstruction -{ -public: - txLoopNodeSet(txInstruction* aTarget); - - TX_DECL_TXINSTRUCTION - - txInstruction* mTarget; -}; - -class txLREAttribute : public txInstruction -{ -public: - txLREAttribute(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix, nsAutoPtr aValue); - - TX_DECL_TXINSTRUCTION - - PRInt32 mNamespaceID; - nsCOMPtr mLocalName; - nsCOMPtr mPrefix; - nsAutoPtr mValue; -}; - -class txMessage : public txInstruction -{ -public: - txMessage(PRBool aTerminate); - - TX_DECL_TXINSTRUCTION - - PRBool mTerminate; -}; - -class txNumber : public txInstruction -{ -public: - txNumber(txXSLTNumber::LevelType aLevel, nsAutoPtr aCount, - nsAutoPtr aFrom, nsAutoPtr aValue, - nsAutoPtr aFormat, nsAutoPtr aGroupingSeparator, - nsAutoPtr aGroupingSize); - - TX_DECL_TXINSTRUCTION - - txXSLTNumber::LevelType mLevel; - nsAutoPtr mCount; - nsAutoPtr mFrom; - nsAutoPtr mValue; - nsAutoPtr mFormat; - nsAutoPtr mGroupingSeparator; - nsAutoPtr mGroupingSize; -}; - -class txPopParams : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txProcessingInstruction : public txInstruction -{ -public: - txProcessingInstruction(nsAutoPtr aName); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mName; -}; - -class txPushNewContext : public txInstruction -{ -public: - txPushNewContext(nsAutoPtr aSelect); - ~txPushNewContext(); - - TX_DECL_TXINSTRUCTION - - - nsresult addSort(nsAutoPtr aSelectExpr, nsAutoPtr aLangExpr, - nsAutoPtr aDataTypeExpr, nsAutoPtr aOrderExpr, - nsAutoPtr aCaseOrderExpr); - - struct SortKey { - SortKey(nsAutoPtr aSelectExpr, nsAutoPtr aLangExpr, - nsAutoPtr aDataTypeExpr, nsAutoPtr aOrderExpr, - nsAutoPtr aCaseOrderExpr); - - nsAutoPtr mSelectExpr; - nsAutoPtr mLangExpr; - nsAutoPtr mDataTypeExpr; - nsAutoPtr mOrderExpr; - nsAutoPtr mCaseOrderExpr; - }; - - nsVoidArray mSortKeys; - nsAutoPtr mSelect; - txInstruction* mBailTarget; -}; - -class txPushNullTemplateRule : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txPushParams : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txPushRTFHandler : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txPushStringHandler : public txInstruction -{ -public: - txPushStringHandler(PRBool aOnlyText); - - TX_DECL_TXINSTRUCTION - - PRBool mOnlyText; -}; - -class txRemoveVariable : public txInstruction -{ -public: - txRemoveVariable(const txExpandedName& aName); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; -}; - -class txReturn : public txInstruction -{ -public: - TX_DECL_TXINSTRUCTION -}; - -class txSetParam : public txInstruction -{ -public: - txSetParam(const txExpandedName& aName, nsAutoPtr aValue); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; - nsAutoPtr mValue; -}; - -class txSetVariable : public txInstruction -{ -public: - txSetVariable(const txExpandedName& aName, nsAutoPtr aValue); - - TX_DECL_TXINSTRUCTION - - txExpandedName mName; - nsAutoPtr mValue; -}; - -class txStartElement : public txInstruction -{ -public: - txStartElement(nsAutoPtr aName, nsAutoPtr aNamespace, - txNamespaceMap* aMappings); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mName; - nsAutoPtr mNamespace; - nsRefPtr mMappings; -}; - -class txStartLREElement : public txInstruction -{ -public: - txStartLREElement(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix); - - TX_DECL_TXINSTRUCTION - - PRInt32 mNamespaceID; - nsCOMPtr mLocalName; - nsCOMPtr mPrefix; -}; - -class txText : public txInstruction -{ -public: - txText(const nsAString& aStr, PRBool aDOE); - - TX_DECL_TXINSTRUCTION - - nsString mStr; - PRBool mDOE; -}; - -class txValueOf : public txInstruction -{ -public: - txValueOf(nsAutoPtr aExpr, PRBool aDOE); - - TX_DECL_TXINSTRUCTION - - nsAutoPtr mExpr; - PRBool mDOE; -}; - -#endif //TRANSFRMX_TXINSTRUCTIONS_H diff --git a/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp b/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp deleted file mode 100644 index 8b931cabe4c6..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaStylesheetCompiler.cpp +++ /dev/null @@ -1,829 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCOMArray.h" -#include "nsIAuthPrompt.h" -#include "nsICharsetAlias.h" -#include "nsIDOMNode.h" -#include "nsIDOMDocument.h" -#include "nsIDocument.h" -#include "nsIExpatSink.h" -#include "nsIChannelEventSink.h" -#include "nsIInterfaceRequestor.h" -#include "nsILoadGroup.h" -#include "nsINameSpaceManager.h" -#include "nsINodeInfo.h" -#include "nsIParser.h" -#include "nsIRequestObserver.h" -#include "nsIScriptSecurityManager.h" -#include "nsContentPolicyUtils.h" -#include "nsIStreamConverterService.h" -#include "nsISyncLoadDOMService.h" -#include "nsIURI.h" -#include "nsIPrincipal.h" -#include "nsIWindowWatcher.h" -#include "nsIXMLContentSink.h" -#include "nsMimeTypes.h" -#include "nsNetUtil.h" -#include "nsParserCIID.h" -#include "txAtoms.h" -#include "TxLog.h" -#include "txMozillaXSLTProcessor.h" -#include "txStylesheetCompiler.h" -#include "XMLUtils.h" - -static const char kLoadAsData[] = "loadAsData"; -static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); - -static void -getSpec(nsIChannel* aChannel, nsAString& aSpec) -{ - if (!aChannel) { - return; - } - - nsCOMPtr uri; - aChannel->GetOriginalURI(getter_AddRefs(uri)); - if (!uri) { - return; - } - - nsCAutoString spec; - uri->GetSpec(spec); - AppendUTF8toUTF16(spec, aSpec); -} - -class txStylesheetSink : public nsIXMLContentSink, - public nsIExpatSink, - public nsIStreamListener, - public nsIChannelEventSink, - public nsIInterfaceRequestor -{ -public: - txStylesheetSink(txStylesheetCompiler* aCompiler, nsIParser* aParser); - virtual ~txStylesheetSink(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIEXPATSINK - NS_DECL_NSISTREAMLISTENER - NS_DECL_NSIREQUESTOBSERVER - NS_DECL_NSICHANNELEVENTSINK - NS_DECL_NSIINTERFACEREQUESTOR - - // nsIContentSink - NS_IMETHOD WillBuildModel(void) { return NS_OK; } - NS_IMETHOD DidBuildModel(); - NS_IMETHOD WillInterrupt(void) { return NS_OK; } - NS_IMETHOD WillResume(void) { return NS_OK; } - NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; } - virtual void FlushPendingNotifications(mozFlushType aType) { } - NS_IMETHOD SetDocumentCharset(nsACString& aCharset) { return NS_OK; } - virtual nsISupports *GetTarget() { return nsnull; } - -private: - nsRefPtr mCompiler; - nsCOMPtr mListener; - PRPackedBool mCheckedForXML; - -protected: - // This exists soly to supress a warning from nsDerivedSafe - txStylesheetSink(); -}; - -txStylesheetSink::txStylesheetSink(txStylesheetCompiler* aCompiler, - nsIParser* aParser) - : mCompiler(aCompiler), - mCheckedForXML(PR_FALSE) -{ - mListener = do_QueryInterface(aParser); -} - -txStylesheetSink::~txStylesheetSink() -{ -} - -NS_IMPL_ISUPPORTS7(txStylesheetSink, - nsIXMLContentSink, - nsIContentSink, - nsIExpatSink, - nsIStreamListener, - nsIRequestObserver, - nsIChannelEventSink, - nsIInterfaceRequestor) - -NS_IMETHODIMP -txStylesheetSink::HandleStartElement(const PRUnichar *aName, - const PRUnichar **aAtts, - PRUint32 aAttsCount, - PRInt32 aIndex, - PRUint32 aLineNumber) -{ - NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount"); - - nsresult rv = - mCompiler->startElement(aName, aAtts, aAttsCount / 2, aIndex); - if (NS_FAILED(rv)) { - mCompiler->cancel(rv); - - return rv; - } - - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleEndElement(const PRUnichar *aName) -{ - nsresult rv = mCompiler->endElement(); - if (NS_FAILED(rv)) { - mCompiler->cancel(rv); - - return rv; - } - - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleComment(const PRUnichar *aName) -{ - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleCDataSection(const PRUnichar *aData, - PRUint32 aLength) -{ - return HandleCharacterData(aData, aLength); -} - -NS_IMETHODIMP -txStylesheetSink::HandleDoctypeDecl(const nsAString & aSubset, - const nsAString & aName, - const nsAString & aSystemId, - const nsAString & aPublicId, - nsISupports *aCatalogData) -{ - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleCharacterData(const PRUnichar *aData, - PRUint32 aLength) -{ - nsresult rv = mCompiler->characters(Substring(aData, aData + aLength)); - if (NS_FAILED(rv)) { - mCompiler->cancel(rv); - return rv; - } - - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleProcessingInstruction(const PRUnichar *aTarget, - const PRUnichar *aData) -{ - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::HandleXMLDeclaration(const PRUnichar *aVersion, - const PRUnichar *aEncoding, - PRInt32 aStandalone) -{ - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::ReportError(const PRUnichar *aErrorText, - const PRUnichar *aSourceText) -{ - mCompiler->cancel(NS_ERROR_FAILURE, aErrorText, aSourceText); - - return NS_OK; -} - -NS_IMETHODIMP -txStylesheetSink::DidBuildModel() -{ - return mCompiler->doneLoading(); -} - -NS_IMETHODIMP -txStylesheetSink::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, - nsIInputStream *aInputStream, - PRUint32 aOffset, PRUint32 aCount) -{ - if (!mCheckedForXML) { - nsCOMPtr parser = do_QueryInterface(aContext); - nsCOMPtr dtd; - parser->GetDTD(getter_AddRefs(dtd)); - if (dtd) { - mCheckedForXML = PR_TRUE; - if (!(dtd->GetType() & NS_IPARSER_FLAG_XML)) { - nsCOMPtr channel = do_QueryInterface(aRequest); - nsAutoString spec; - getSpec(channel, spec); - mCompiler->cancel(NS_ERROR_XSLT_WRONG_MIME_TYPE, nsnull, - spec.get()); - - return NS_ERROR_XSLT_WRONG_MIME_TYPE; - } - } - } - - return mListener->OnDataAvailable(aRequest, aContext, aInputStream, - aOffset, aCount); -} - -NS_IMETHODIMP -txStylesheetSink::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) -{ - nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8")); - PRInt32 charsetSource = kCharsetFromDocTypeDefault; - - nsCOMPtr channel = do_QueryInterface(aRequest); - - // check channel's charset... - nsCAutoString charsetVal; - nsresult rv = channel->GetContentCharset(charsetVal); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr calias = - do_GetService(NS_CHARSETALIAS_CONTRACTID); - - if (calias) { - nsCAutoString preferred; - rv = calias->GetPreferred(charsetVal, - preferred); - if (NS_SUCCEEDED(rv)) { - charset = preferred; - charsetSource = kCharsetFromChannel; - } - } - } - - nsCOMPtr parser = do_QueryInterface(aContext); - parser->SetDocumentCharset(charset, charsetSource); - - nsCAutoString contentType; - channel->GetContentType(contentType); - - // Time to sniff! Note: this should go away once file channels do - // sniffing themselves. - nsCOMPtr uri; - channel->GetURI(getter_AddRefs(uri)); - PRBool sniff; - if (NS_SUCCEEDED(uri->SchemeIs("file", &sniff)) && sniff && - contentType.Equals(UNKNOWN_CONTENT_TYPE)) { - nsCOMPtr serv = - do_GetService("@mozilla.org/streamConverters;1", &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr converter; - rv = serv->AsyncConvertData(UNKNOWN_CONTENT_TYPE, - "*/*", - mListener, - aContext, - getter_AddRefs(converter)); - if (NS_SUCCEEDED(rv)) { - mListener = converter; - } - } - } - - return mListener->OnStartRequest(aRequest, aContext); -} - -NS_IMETHODIMP -txStylesheetSink::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext, - nsresult aStatusCode) -{ - PRBool success = PR_TRUE; - - nsCOMPtr httpChannel = do_QueryInterface(aRequest); - if (httpChannel) { - httpChannel->GetRequestSucceeded(&success); - } - - nsresult result = aStatusCode; - if (!success) { - // XXX We sometimes want to use aStatusCode here, but the parser resets - // it to NS_ERROR_NOINTERFACE because we don't implement - // nsIHTMLContentSink. - result = NS_ERROR_XSLT_NETWORK_ERROR; - } - else if (!mCheckedForXML) { - nsCOMPtr parser = do_QueryInterface(aContext); - nsCOMPtr dtd; - parser->GetDTD(getter_AddRefs(dtd)); - if (dtd && !(dtd->GetType() & NS_IPARSER_FLAG_XML)) { - result = NS_ERROR_XSLT_WRONG_MIME_TYPE; - } - } - - if (NS_FAILED(result)) { - nsCOMPtr channel = do_QueryInterface(aRequest); - nsAutoString spec; - getSpec(channel, spec); - mCompiler->cancel(result, nsnull, spec.get()); - } - - nsresult rv = mListener->OnStopRequest(aRequest, aContext, aStatusCode); - mListener = nsnull; - return rv; -} - -NS_IMETHODIMP -txStylesheetSink::OnChannelRedirect(nsIChannel *aOldChannel, - nsIChannel *aNewChannel, - PRUint32 aFlags) -{ - NS_PRECONDITION(aNewChannel, "Redirect without a channel?"); - - nsresult rv; - nsCOMPtr secMan = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr oldURI; - rv = aOldChannel->GetURI(getter_AddRefs(oldURI)); // The original URI - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr newURI; - rv = aNewChannel->GetURI(getter_AddRefs(newURI)); // The new URI - NS_ENSURE_SUCCESS(rv, rv); - - return secMan->CheckSameOriginURI(oldURI, newURI); -} - -NS_IMETHODIMP -txStylesheetSink::GetInterface(const nsIID& aIID, void** aResult) -{ - if (aIID.Equals(NS_GET_IID(nsIAuthPrompt))) { - NS_ENSURE_ARG(aResult); - *aResult = nsnull; - - nsresult rv; - nsCOMPtr wwatcher = - do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr prompt; - rv = wwatcher->GetNewAuthPrompter(nsnull, getter_AddRefs(prompt)); - NS_ENSURE_SUCCESS(rv, rv); - - nsIAuthPrompt* rawPtr = nsnull; - prompt.swap(rawPtr); - *aResult = rawPtr; - - return NS_OK; - } - - return QueryInterface(aIID, aResult); -} - -static nsresult -CheckLoadURI(nsIURI *aUri, nsIURI *aReferrerUri, - nsIPrincipal *aReferrerPrincipal, nsISupports *aContext) -{ - // First do a security check. - nsresult rv; - nsCOMPtr securityManager = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - if (aReferrerPrincipal) { - rv = securityManager-> - CheckLoadURIWithPrincipal(aReferrerPrincipal, aUri, - nsIScriptSecurityManager::STANDARD); - } - else { - rv = securityManager->CheckLoadURI(aReferrerUri, aUri, - nsIScriptSecurityManager::STANDARD); - } - NS_ENSURE_SUCCESS(rv, NS_ERROR_XSLT_LOAD_BLOCKED_ERROR); - - rv = securityManager->CheckSameOriginURI(aReferrerUri, aUri); - NS_ENSURE_SUCCESS(rv, NS_ERROR_XSLT_LOAD_BLOCKED_ERROR); - - // Then do a content policy check. - PRInt16 decision = nsIContentPolicy::ACCEPT; - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET, - aUri, aReferrerUri, aContext, - NS_LITERAL_CSTRING("application/xml"), nsnull, - &decision); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_CP_REJECTED(decision) ? NS_ERROR_XSLT_LOAD_BLOCKED_ERROR : NS_OK; -} - -class txCompileObserver : public txACompileObserver -{ -public: - txCompileObserver(txMozillaXSLTProcessor* aProcessor, - nsILoadGroup* aLoadGroup); - virtual ~txCompileObserver(); - - TX_DECL_ACOMPILEOBSERVER; - - nsresult startLoad(nsIURI* aUri, txStylesheetCompiler* aCompiler, - nsIURI* aReferrerURI); - -protected: - nsAutoRefCnt mRefCnt; - -private: - nsRefPtr mProcessor; - nsCOMPtr mLoadGroup; - -protected: - // This exists soly to supress a warning from nsDerivedSafe - txCompileObserver(); -}; - -txCompileObserver::txCompileObserver(txMozillaXSLTProcessor* aProcessor, - nsILoadGroup* aLoadGroup) - : mProcessor(aProcessor), - mLoadGroup(aLoadGroup) -{ -} - -txCompileObserver::~txCompileObserver() -{ -} - -nsrefcnt -txCompileObserver::AddRef() -{ - return ++mRefCnt; -} - -nsrefcnt -txCompileObserver::Release() -{ - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - return 0; - } - return mRefCnt; -} - -nsresult -txCompileObserver::loadURI(const nsAString& aUri, - const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler) -{ - nsCOMPtr uri; - nsresult rv = NS_NewURI(getter_AddRefs(uri), aUri); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr referrerUri; - rv = NS_NewURI(getter_AddRefs(referrerUri), aReferrerUri); - NS_ENSURE_SUCCESS(rv, rv); - - // Do security check. - rv = CheckLoadURI(uri, referrerUri, nsnull, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - return startLoad(uri, aCompiler, referrerUri); -} - -void -txCompileObserver::onDoneCompiling(txStylesheetCompiler* aCompiler, - nsresult aResult, - const PRUnichar *aErrorText, - const PRUnichar *aParam) -{ - if (NS_SUCCEEDED(aResult)) { - mProcessor->setStylesheet(aCompiler->getStylesheet()); - } - else { - mProcessor->reportError(aResult, aErrorText, aParam); - } -} - -nsresult -txCompileObserver::startLoad(nsIURI* aUri, txStylesheetCompiler* aCompiler, - nsIURI* aReferrerURI) -{ - nsCOMPtr channel; - nsresult rv = NS_NewChannel(getter_AddRefs(channel), aUri); - NS_ENSURE_SUCCESS(rv, rv); - - channel->SetLoadGroup(mLoadGroup); - - channel->SetContentType(NS_LITERAL_CSTRING("text/xml")); - - nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) { - httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), - NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"), - PR_FALSE); - - if (aReferrerURI) { - httpChannel->SetReferrer(aReferrerURI); - } - } - - nsCOMPtr parser = do_CreateInstance(kCParserCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr sink = new txStylesheetSink(aCompiler, parser); - NS_ENSURE_TRUE(sink, NS_ERROR_OUT_OF_MEMORY); - - channel->SetNotificationCallbacks(sink); - - parser->SetCommand(kLoadAsData); - parser->SetContentSink(sink); - parser->Parse(aUri); - - return channel->AsyncOpen(sink, parser); -} - -nsresult -TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor, - nsILoadGroup* aLoadGroup, nsIPrincipal* aCallerPrincipal) -{ - nsCAutoString spec; - aUri->GetSpec(spec); - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, ("TX_LoadSheet: %s\n", spec.get())); - - nsCOMPtr referrerURI; - aCallerPrincipal->GetURI(getter_AddRefs(referrerURI)); - NS_ASSERTION(referrerURI, "Caller principal must have a URI!"); - - // Pass source document as the context - nsresult rv = CheckLoadURI(aUri, referrerURI, aCallerPrincipal, - aProcessor->GetSourceContentModel()); - NS_ENSURE_SUCCESS(rv, rv); - - nsRefPtr observer = - new txCompileObserver(aProcessor, aLoadGroup); - NS_ENSURE_TRUE(observer, NS_ERROR_OUT_OF_MEMORY); - - nsRefPtr compiler = - new txStylesheetCompiler(NS_ConvertUTF8toUTF16(spec), observer); - NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY); - - return observer->startLoad(aUri, compiler, referrerURI); -} - -/** - * handling DOM->txStylesheet - * Observer needs to do synchronous loads. - */ -static nsresult -handleNode(nsIDOMNode* aNode, txStylesheetCompiler* aCompiler) -{ - nsresult rv = NS_OK; - PRUint16 nodetype; - aNode->GetNodeType(&nodetype); - switch (nodetype) { - case nsIDOMNode::ELEMENT_NODE: - { - nsCOMPtr element = do_QueryInterface(aNode); - - PRUint32 attsCount = element->GetAttrCount(); - nsAutoArrayPtr atts; - if (attsCount > 0) { - atts = new txStylesheetAttr[attsCount]; - NS_ENSURE_TRUE(atts, NS_ERROR_OUT_OF_MEMORY); - - PRUint32 counter; - for (counter = 0; counter < attsCount; ++counter) { - txStylesheetAttr& att = atts[counter]; - element->GetAttrNameAt(counter, &att.mNamespaceID, - getter_AddRefs(att.mLocalName), - getter_AddRefs(att.mPrefix)); - element->GetAttr(att.mNamespaceID, att.mLocalName, att.mValue); - } - } - - nsINodeInfo *ni = element->NodeInfo(); - - rv = aCompiler->startElement(ni->NamespaceID(), - ni->NameAtom(), - ni->GetPrefixAtom(), atts, - attsCount); - NS_ENSURE_SUCCESS(rv, rv); - - // explicitly destroy the attrs here since we no longer need it - atts = nsnull; - - PRUint32 childCount = element->GetChildCount(); - if (childCount > 0) { - PRUint32 counter = 0; - nsIContent *child; - while ((child = element->GetChildAt(counter++))) { - nsCOMPtr childNode = do_QueryInterface(child); - rv = handleNode(childNode, aCompiler); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - rv = aCompiler->endElement(); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - case nsIDOMNode::CDATA_SECTION_NODE: - case nsIDOMNode::TEXT_NODE: - { - nsAutoString chars; - aNode->GetNodeValue(chars); - rv = aCompiler->characters(chars); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - case nsIDOMNode::DOCUMENT_NODE: - { - nsCOMPtr document = do_QueryInterface(aNode); - - PRUint32 counter = 0; - nsIContent *child; - while ((child = document->GetChildAt(counter++))) { - nsCOMPtr childNode = do_QueryInterface(child); - rv = handleNode(childNode, aCompiler); - NS_ENSURE_SUCCESS(rv, rv); - } - break; - } - } - return NS_OK; -} - -class txSyncCompileObserver : public txACompileObserver -{ -public: - txSyncCompileObserver(); - virtual ~txSyncCompileObserver(); - - TX_DECL_ACOMPILEOBSERVER; - -protected: - nsAutoRefCnt mRefCnt; - -private: - nsCOMPtr mLoadService; -}; - -txSyncCompileObserver::txSyncCompileObserver() -{ -} - -txSyncCompileObserver::~txSyncCompileObserver() -{ -} - -nsrefcnt -txSyncCompileObserver::AddRef() -{ - return ++mRefCnt; -} - -nsrefcnt -txSyncCompileObserver::Release() -{ - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - return 0; - } - return mRefCnt; -} - -nsresult -txSyncCompileObserver::loadURI(const nsAString& aUri, - const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler) -{ - nsCOMPtr uri; - nsresult rv = NS_NewURI(getter_AddRefs(uri), aUri); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr referrerUri; - rv = NS_NewURI(getter_AddRefs(referrerUri), aReferrerUri); - NS_ENSURE_SUCCESS(rv, rv); - - rv = CheckLoadURI(uri, referrerUri, nsnull, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - if (!mLoadService) { - mLoadService = - do_GetService("@mozilla.org/content/syncload-dom-service;1"); - NS_ENSURE_TRUE(mLoadService, NS_ERROR_OUT_OF_MEMORY); - } - - nsCOMPtr channel; - rv = NS_NewChannel(getter_AddRefs(channel), uri); - NS_ENSURE_SUCCESS(rv, rv); - - // This is probably called by js, a loadGroup for the channel doesn't - // make sense. - - channel->SetContentType(NS_LITERAL_CSTRING("text/xml")); - - nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) { - httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), - NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"), - PR_FALSE); - - httpChannel->SetReferrer(referrerUri); - } - - nsCOMPtr document; - rv = mLoadService->LoadDocument(channel, referrerUri, - getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv); - rv = handleNode(document, aCompiler); - if (NS_FAILED(rv)) { - nsCAutoString spec; - uri->GetSpec(spec); - aCompiler->cancel(rv, nsnull, NS_ConvertUTF8toUTF16(spec).get()); - return rv; - } - - rv = aCompiler->doneLoading(); - return rv; -} - -void txSyncCompileObserver::onDoneCompiling(txStylesheetCompiler* aCompiler, - nsresult aResult, - const PRUnichar *aErrorText, - const PRUnichar *aParam) -{ -} - -nsresult -TX_CompileStylesheet(nsIDOMNode* aNode, txStylesheet** aStylesheet) -{ - nsCOMPtr document; - aNode->GetOwnerDocument(getter_AddRefs(document)); - if (!document) { - document = do_QueryInterface(aNode); - } - - nsCOMPtr doc = do_QueryInterface(document); - nsIURI *uri = doc->GetBaseURI(); - nsCAutoString baseURI; - uri->GetSpec(baseURI); - - nsRefPtr obs = new txSyncCompileObserver(); - NS_ENSURE_TRUE(obs, NS_ERROR_OUT_OF_MEMORY); - NS_ConvertUTF8toUTF16 base(baseURI); - nsRefPtr compiler = - new txStylesheetCompiler(base, obs); - NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = handleNode(aNode, compiler); - if (NS_FAILED(rv)) { - compiler->cancel(rv); - return rv; - } - - rv = compiler->doneLoading(); - NS_ENSURE_SUCCESS(rv, rv); - - *aStylesheet = compiler->getStylesheet(); - NS_ADDREF(*aStylesheet); - - return NS_OK; -} diff --git a/extensions/transformiix/source/xslt/txMozillaTextOutput.cpp b/extensions/transformiix/source/xslt/txMozillaTextOutput.cpp deleted file mode 100644 index ad081e691bd1..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaTextOutput.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txMozillaTextOutput.h" -#include "nsContentCID.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentFragment.h" -#include "nsIDOMElement.h" -#include "nsIDOMHTMLElement.h" -#include "nsIDOMText.h" -#include "nsIDocumentTransformer.h" -#include "nsNetUtil.h" -#include "nsIDOMNSDocument.h" -#include "nsIParser.h" -#include "nsICharsetAlias.h" - -static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); - -txMozillaTextOutput::txMozillaTextOutput(nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument, - nsITransformObserver* aObserver) -{ - mObserver = do_GetWeakReference(aObserver); - createResultDocument(aSourceDocument, aResultDocument); -} - -txMozillaTextOutput::txMozillaTextOutput(nsIDOMDocumentFragment* aDest) -{ - nsCOMPtr doc; - aDest->GetOwnerDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc, "unable to get ownerdocument"); - nsCOMPtr textNode; - nsresult rv = doc->CreateTextNode(EmptyString(), - getter_AddRefs(textNode)); - if (NS_FAILED(rv)) { - return; - } - nsCOMPtr dummy; - rv = aDest->AppendChild(textNode, getter_AddRefs(dummy)); - if (NS_FAILED(rv)) { - return; - } - - mTextNode = textNode; - return; -} - -txMozillaTextOutput::~txMozillaTextOutput() -{ -} - -void txMozillaTextOutput::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ -} - -void txMozillaTextOutput::characters(const nsAString& aData, PRBool aDOE) -{ - if (mTextNode) - mTextNode->AppendData(aData); -} - -void txMozillaTextOutput::comment(const nsAString& aData) -{ -} - -void txMozillaTextOutput::endDocument(nsresult aResult) -{ - if (NS_SUCCEEDED(aResult)) { - nsCOMPtr observer = do_QueryReferent(mObserver); - if (observer) { - observer->OnTransformDone(aResult, mDocument); - } - } -} - -void txMozillaTextOutput::endElement(const nsAString& aName, - const PRInt32 aNsID) -{ -} - -void txMozillaTextOutput::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ -} - -void txMozillaTextOutput::startDocument() -{ -} - -void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument) -{ - nsresult rv = NS_OK; - - /* - * Create an XHTML document to hold the text. - * - * - * - * - *
 * The text comes here * 
- * - * - * - * Except if we are transforming into a non-displayed document we create - * the following DOM - * - * * The text comes here * - */ - - nsCOMPtr doc; - if (!aResultDocument) { - // Create the document - doc = do_CreateInstance(kXMLDocumentCID, &rv); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create document"); - mDocument = do_QueryInterface(doc); - } - else { - mDocument = aResultDocument; - doc = do_QueryInterface(aResultDocument); - NS_ASSERTION(doc, "Couldn't QI to nsIDocument"); - } - - if (!doc) { - return; - } - - NS_ASSERTION(mDocument, "Need document"); - - nsCOMPtr nsDoc = do_QueryInterface(mDocument); - if (nsDoc) { - nsDoc->SetTitle(EmptyString()); - } - - // Reset and set up document - nsCOMPtr channel; - nsCOMPtr sourceDoc = do_QueryInterface(aSourceDocument); - nsCOMPtr loadGroup = sourceDoc->GetDocumentLoadGroup(); - nsCOMPtr serv = do_GetService(NS_IOSERVICE_CONTRACTID); - if (serv) { - // Create a temporary channel to get nsIDocument->Reset to - // do the right thing. We want the output document to get - // much of the input document's characteristics. - serv->NewChannelFromURI(sourceDoc->GetDocumentURI(), - getter_AddRefs(channel)); - } - doc->Reset(channel, loadGroup); - doc->SetBaseURI(sourceDoc->GetBaseURI()); - - // Set the charset - if (!mOutputFormat.mEncoding.IsEmpty()) { - NS_LossyConvertUTF16toASCII charset(mOutputFormat.mEncoding); - nsCAutoString canonicalCharset; - nsCOMPtr calias = - do_GetService("@mozilla.org/intl/charsetalias;1"); - - if (calias && - NS_SUCCEEDED(calias->GetPreferred(charset, canonicalCharset))) { - doc->SetDocumentCharacterSet(canonicalCharset); - doc->SetDocumentCharacterSetSource(kCharsetFromOtherComponent); - } - } - else { - doc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet()); - doc->SetDocumentCharacterSetSource( - sourceDoc->GetDocumentCharacterSetSource()); - } - - // Notify the contentsink that the document is created - nsCOMPtr observer = do_QueryReferent(mObserver); - if (observer) { - observer->OnDocumentCreated(mDocument); - } - - // Create the content - - // When transforming into a non-displayed document (i.e. when there is no - // observer) we only create a transformiix:result root element. - // Don't do this when called through nsIXSLTProcessorObsolete (i.e. when - // aResultDocument is set) for compability reasons - nsCOMPtr textContainer; - if (!aResultDocument && !observer) { - nsCOMPtr docElement; - mDocument->CreateElementNS(NS_LITERAL_STRING(kTXNameSpaceURI), - NS_LITERAL_STRING(kTXWrapper), - getter_AddRefs(docElement)); - NS_ASSERTION(docElement, "Failed to create wrapper element"); - if (!docElement) { - return; - } - - rv = mDocument->AppendChild(docElement, getter_AddRefs(textContainer)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the wrapper element"); - if (NS_FAILED(rv)) { - return; - } - } - else { - nsCOMPtr element, docElement; - nsCOMPtr parent, pre; - - NS_NAMED_LITERAL_STRING(XHTML_NSURI, "http://www.w3.org/1999/xhtml"); - - mDocument->CreateElementNS(XHTML_NSURI, - NS_LITERAL_STRING("html"), - getter_AddRefs(docElement)); - nsCOMPtr rootContent = do_QueryInterface(docElement); - NS_ASSERTION(rootContent, "Need root element"); - if (!rootContent) { - return; - } - - // XXXbz what to do on failure here? - rv = doc->SetRootContent(rootContent); - if (NS_FAILED(rv)) { - NS_ERROR("Failed to set root content"); - return; - } - - - mDocument->CreateElementNS(XHTML_NSURI, - NS_LITERAL_STRING("head"), - getter_AddRefs(element)); - NS_ASSERTION(element, "Failed to create head element"); - if (!element) { - return; - } - - rv = docElement->AppendChild(element, getter_AddRefs(parent)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the head element"); - if (NS_FAILED(rv)) { - return; - } - - mDocument->CreateElementNS(XHTML_NSURI, - NS_LITERAL_STRING("body"), - getter_AddRefs(element)); - NS_ASSERTION(element, "Failed to create body element"); - if (!element) { - return; - } - - rv = docElement->AppendChild(element, getter_AddRefs(parent)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the body element"); - if (NS_FAILED(rv)) { - return; - } - - mDocument->CreateElementNS(XHTML_NSURI, - NS_LITERAL_STRING("pre"), - getter_AddRefs(element)); - NS_ASSERTION(element, "Failed to create pre element"); - if (!element) { - return; - } - - rv = parent->AppendChild(element, getter_AddRefs(pre)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the pre element"); - if (NS_FAILED(rv)) { - return; - } - - nsCOMPtr htmlElement = do_QueryInterface(pre); - htmlElement->SetId(NS_LITERAL_STRING("transformiixResult")); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the id"); - - textContainer = pre; - } - - nsCOMPtr textNode; - mDocument->CreateTextNode(EmptyString(), - getter_AddRefs(textNode)); - NS_ASSERTION(textNode, "Failed to create the text node"); - if (!textNode) { - return; - } - - nsCOMPtr dummy; - rv = textContainer->AppendChild(textNode, getter_AddRefs(dummy)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the text node"); - if (NS_FAILED(rv)) { - return; - } - - mTextNode = textNode; -} - -void txMozillaTextOutput::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ -} - -void txMozillaTextOutput::getOutputDocument(nsIDOMDocument** aDocument) -{ - *aDocument = mDocument; - NS_IF_ADDREF(*aDocument); -} diff --git a/extensions/transformiix/source/xslt/txMozillaTextOutput.h b/extensions/transformiix/source/xslt/txMozillaTextOutput.h deleted file mode 100644 index 67dd2f39a7ce..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaTextOutput.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_MOZILLA_TEXT_OUTPUT_H -#define TRANSFRMX_MOZILLA_TEXT_OUTPUT_H - -#include "txXMLEventHandler.h" -#include "nsCOMPtr.h" -#include "nsWeakPtr.h" -#include "txOutputFormat.h" - -class nsIDOMCharacterData; -class nsIDOMDocument; -class nsIDOMDocumentFragment; -class nsITransformObserver; - -class txMozillaTextOutput : public txAOutputXMLEventHandler -{ -public: - txMozillaTextOutput(nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument, - nsITransformObserver* aObserver); - txMozillaTextOutput(nsIDOMDocumentFragment* aDest); - virtual ~txMozillaTextOutput(); - - TX_DECL_TXAXMLEVENTHANDLER - TX_DECL_TXAOUTPUTXMLEVENTHANDLER - -private: - void createResultDocument(nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument); - - nsCOMPtr mTextNode; - nsWeakPtr mObserver; - nsCOMPtr mDocument; - txOutputFormat mOutputFormat; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp b/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp deleted file mode 100644 index 9028ee693d41..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp +++ /dev/null @@ -1,981 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txMozillaXMLOutput.h" - -#include "nsIDocument.h" -#include "nsIDocShell.h" -#include "nsIScriptLoader.h" -#include "nsIDOMDocument.h" -#include "nsIDOMComment.h" -#include "nsIDOMDocumentType.h" -#include "nsIDOMDOMImplementation.h" -#include "nsIDOMNodeList.h" -#include "nsIDOMProcessingInstruction.h" -#include "nsIDOMText.h" -#include "nsIDOMHTMLTableSectionElem.h" -#include "nsIScriptElement.h" -#include "nsIDOMNSDocument.h" -#include "nsIParser.h" -#include "nsIRefreshURI.h" -#include "nsIScriptGlobalObject.h" -#include "nsITextContent.h" -#include "nsIXMLContent.h" -#include "nsContentCID.h" -#include "nsNetUtil.h" -#include "nsUnicharUtils.h" -#include "txAtoms.h" -#include "TxLog.h" -#include "nsIConsoleService.h" -#include "nsIDOMDocumentFragment.h" -#include "nsINameSpaceManager.h" -#include "nsICSSStyleSheet.h" -#include "txStringUtils.h" -#include "txURIUtils.h" -#include "nsIHTMLDocument.h" -#include "nsIStyleSheetLinkingElement.h" -#include "nsIDocumentTransformer.h" -#include "nsICSSLoader.h" -#include "nsICharsetAlias.h" -#include "nsIHTMLContentSink.h" - -extern nsINameSpaceManager* gTxNameSpaceManager; - -static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); -static NS_DEFINE_CID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID); - -#define kXHTMLNameSpaceURI "http://www.w3.org/1999/xhtml" - -#define TX_ENSURE_CURRENTNODE \ - NS_ASSERTION(mCurrentNode, "mCurrentNode is NULL"); \ - if (!mCurrentNode) \ - return - -txMozillaXMLOutput::txMozillaXMLOutput(const nsAString& aRootName, - PRInt32 aRootNsID, - txOutputFormat* aFormat, - nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument, - nsITransformObserver* aObserver) - : mTreeDepth(0), - mBadChildLevel(0), - mTableState(NORMAL), - mDontAddCurrent(PR_FALSE), - mHaveTitleElement(PR_FALSE), - mHaveBaseElement(PR_FALSE), - mCreatingNewDocument(PR_TRUE) -{ - if (aObserver) { - mNotifier = new txTransformNotifier(); - if (mNotifier) { - mNotifier->Init(aObserver); - } - } - - mOutputFormat.merge(*aFormat); - mOutputFormat.setFromDefaults(); - - createResultDocument(aRootName, aRootNsID, aSourceDocument, aResultDocument); -} - -txMozillaXMLOutput::txMozillaXMLOutput(txOutputFormat* aFormat, - nsIDOMDocumentFragment* aFragment) - : mBadChildLevel(0), - mTableState(NORMAL), - mDontAddCurrent(PR_FALSE), - mHaveTitleElement(PR_FALSE), - mHaveBaseElement(PR_FALSE), - mCreatingNewDocument(PR_FALSE) -{ - mOutputFormat.merge(*aFormat); - mOutputFormat.setFromDefaults(); - - aFragment->GetOwnerDocument(getter_AddRefs(mDocument)); - - nsCOMPtr doc = do_QueryInterface(mDocument); - mDocumentIsHTML = doc && !doc->IsCaseSensitive(); - - mCurrentNode = aFragment; -} - -txMozillaXMLOutput::~txMozillaXMLOutput() -{ -} - -void txMozillaXMLOutput::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ - if (!mParentNode) - // XXX Signal this? (can't add attributes after element closed) - return; - - if (mBadChildLevel) { - return; - } - - nsCOMPtr element = do_QueryInterface(mCurrentNode); - NS_ASSERTION(element, "No element to add the attribute to."); - if (!element) - // XXX Signal this? (no element to add attributes to) - return; - - if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) { - // Outputting HTML as XHTML, lowercase attribute names - nsAutoString lowerName; - TX_ToLowerCase(aName, lowerName); - element->SetAttributeNS(EmptyString(), lowerName, - aValue); - } - else { - nsAutoString nsURI; - gTxNameSpaceManager->GetNameSpaceURI(aNsID, nsURI); - element->SetAttributeNS(nsURI, aName, aValue); - } -} - -void txMozillaXMLOutput::characters(const nsAString& aData, PRBool aDOE) -{ - closePrevious(eCloseElement); - - if (mBadChildLevel) { - return; - } - - mText.Append(aData); -} - -void txMozillaXMLOutput::comment(const nsAString& aData) -{ - closePrevious(eCloseElement | eFlushText); - - if (mBadChildLevel) { - return; - } - - TX_ENSURE_CURRENTNODE; - - nsCOMPtr comment; - nsresult rv = mDocument->CreateComment(aData, - getter_AddRefs(comment)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create comment"); - nsCOMPtr resultNode; - rv = mCurrentNode->AppendChild(comment, getter_AddRefs(resultNode)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append comment"); -} - -void txMozillaXMLOutput::endDocument(nsresult aResult) -{ - closePrevious(eCloseElement | eFlushText); - // This should really be handled by nsIDocument::Reset - if (mCreatingNewDocument && !mHaveTitleElement) { - nsCOMPtr domDoc = do_QueryInterface(mDocument); - if (domDoc) { - domDoc->SetTitle(EmptyString()); - } - } - - if (!mRefreshString.IsEmpty()) { - nsCOMPtr doc = do_QueryInterface(mDocument); - nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); - if (sgo) { - nsCOMPtr refURI = - do_QueryInterface(sgo->GetDocShell()); - if (refURI) { - refURI->SetupRefreshURIFromHeader(doc->GetBaseURI(), - mRefreshString); - } - } - } - - if (mNotifier) { - mNotifier->OnTransformEnd(aResult); - } -} - -void txMozillaXMLOutput::endElement(const nsAString& aName, const PRInt32 aNsID) -{ - TX_ENSURE_CURRENTNODE; - - if (mBadChildLevel) { - --mBadChildLevel; - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("endElement, mBadChildLevel = %d\n", mBadChildLevel)); - return; - } - - --mTreeDepth; - -#ifdef DEBUG - if (mTableState != ADDED_TBODY) { - nsAutoString nodeName; - mCurrentNode->GetNodeName(nodeName); - NS_ASSERTION(nodeName.Equals(aName, - nsCaseInsensitiveStringComparator()), - "Unbalanced startElement and endElement calls!"); - } - else { - nsCOMPtr parent; - mCurrentNode->GetParentNode(getter_AddRefs(parent)); - nsAutoString nodeName; - parent->GetNodeName(nodeName); - NS_ASSERTION(nodeName.Equals(aName, - nsCaseInsensitiveStringComparator()), - "Unbalanced startElement and endElement calls!"); - } -#endif - - closePrevious(eCloseElement | eFlushText); - - // Handle html-elements - if ((mOutputFormat.mMethod == eHTMLOutput && aNsID == kNameSpaceID_None) || - aNsID == kNameSpaceID_XHTML) { - nsCOMPtr element = do_QueryInterface(mCurrentNode); - NS_ASSERTION(element, "endElement'ing non-element"); - endHTMLElement(element); - } - - // Handle svg script elements - if (aNsID == kNameSpaceID_SVG && txHTMLAtoms::script->Equals(aName)) { - // Add this script element to the array of loading script elements. - nsCOMPtr scriptElement = - do_QueryInterface(mCurrentNode); - NS_ASSERTION(scriptElement, "Need script element"); - mNotifier->AddScriptElement(scriptElement); - } - - if (mCreatingNewDocument) { - // Handle all sorts of stylesheets - nsCOMPtr ssle = - do_QueryInterface(mCurrentNode); - if (ssle) { - ssle->SetEnableUpdates(PR_TRUE); - if (ssle->UpdateStyleSheet(nsnull, mNotifier) == - NS_ERROR_HTMLPARSER_BLOCK) { - nsCOMPtr stylesheet; - ssle->GetStyleSheet(*getter_AddRefs(stylesheet)); - if (mNotifier) { - mNotifier->AddStyleSheet(stylesheet); - } - } - } - } - - // Add the element to the tree if it wasn't added before and take one step - // up the tree - // we can't use GetParentNode to check if mCurrentNode is the - // "non-added node" since that does strange things when we've called - // BindToTree manually - if (mCurrentNode == mNonAddedNode) { - nsCOMPtr document = do_QueryInterface(mNonAddedParent); - if (document && !mRootContent) { - mRootContent = do_QueryInterface(mCurrentNode); - // XXXbz what to do on failure here? - document->SetRootContent(mRootContent); - } - else { - nsCOMPtr resultNode; - mNonAddedParent->AppendChild(mCurrentNode, - getter_AddRefs(resultNode)); - } - mCurrentNode = mNonAddedParent; - mNonAddedParent = nsnull; - mNonAddedNode = nsnull; - } - else { - nsCOMPtr parent; - mCurrentNode->GetParentNode(getter_AddRefs(parent)); - mCurrentNode = parent; - } - - mTableState = - NS_STATIC_CAST(TableState, NS_PTR_TO_INT32(mTableStateStack.pop())); -} - -void txMozillaXMLOutput::getOutputDocument(nsIDOMDocument** aDocument) -{ - *aDocument = mDocument; - NS_IF_ADDREF(*aDocument); -} - -void txMozillaXMLOutput::processingInstruction(const nsAString& aTarget, const nsAString& aData) -{ - if (mOutputFormat.mMethod == eHTMLOutput) - return; - - closePrevious(eCloseElement | eFlushText); - - TX_ENSURE_CURRENTNODE; - - nsCOMPtr pi; - nsresult rv = mDocument->CreateProcessingInstruction(aTarget, aData, - getter_AddRefs(pi)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create processing instruction"); - if (NS_FAILED(rv)) - return; - - nsCOMPtr ssle; - if (mCreatingNewDocument) { - ssle = do_QueryInterface(pi); - if (ssle) { - ssle->InitStyleLinkElement(nsnull, PR_FALSE); - ssle->SetEnableUpdates(PR_FALSE); - } - } - - nsCOMPtr resultNode; - rv = mCurrentNode->AppendChild(pi, getter_AddRefs(resultNode)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append processing instruction"); - if (NS_FAILED(rv)) - return; - - if (ssle) { - ssle->SetEnableUpdates(PR_TRUE); - rv = ssle->UpdateStyleSheet(nsnull, mNotifier); - if (rv == NS_ERROR_HTMLPARSER_BLOCK) { - nsCOMPtr stylesheet; - ssle->GetStyleSheet(*getter_AddRefs(stylesheet)); - if (mNotifier) { - mNotifier->AddStyleSheet(stylesheet); - } - } - } -} - -void txMozillaXMLOutput::startDocument() -{ - if (mNotifier) { - mNotifier->OnTransformStart(); - } -} - -void txMozillaXMLOutput::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ - TX_ENSURE_CURRENTNODE; - - if (mBadChildLevel) { - ++mBadChildLevel; - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); - return; - } - - closePrevious(eCloseElement | eFlushText); - - if (mBadChildLevel || mTreeDepth == MAX_REFLOW_DEPTH) { - // eCloseElement couldn't add the parent so we fail as well or we've - // reached the limit of the depth of the tree that we allow. - ++mBadChildLevel; - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("startElement, mBadChildLevel = %d\n", mBadChildLevel)); - return; - } - - ++mTreeDepth; - - nsresult rv = mTableStateStack.push(NS_INT32_TO_PTR(mTableState)); - if (NS_FAILED(rv)) { - return; - } - mTableState = NORMAL; - - nsCOMPtr element; - mDontAddCurrent = PR_FALSE; - - if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) { - if (mDocumentIsHTML) { - rv = mDocument->CreateElement(aName, - getter_AddRefs(element)); - } - else { - nsAutoString lcname; - ToLowerCase(aName, lcname); - rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), - lcname, - getter_AddRefs(element)); - } - if (NS_FAILED(rv)) { - return; - } - - startHTMLElement(element, PR_FALSE); - } - else { - nsAutoString nsURI; - gTxNameSpaceManager->GetNameSpaceURI(aNsID, nsURI); - rv = mDocument->CreateElementNS(nsURI, aName, - getter_AddRefs(element)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create element"); - if (NS_FAILED(rv)) { - return; - } - - if (aNsID == kNameSpaceID_XHTML) { - startHTMLElement(element, PR_TRUE); - } else if (aNsID == kNameSpaceID_SVG && - txHTMLAtoms::script->Equals(aName)) { - mDontAddCurrent = PR_TRUE; - } - } - - if (mCreatingNewDocument) { - // Handle all sorts of stylesheets - nsCOMPtr ssle = - do_QueryInterface(element); - if (ssle) { - ssle->InitStyleLinkElement(nsnull, PR_FALSE); - ssle->SetEnableUpdates(PR_FALSE); - } - } - mParentNode = mCurrentNode; - mCurrentNode = do_QueryInterface(element); -} - -void txMozillaXMLOutput::closePrevious(PRInt8 aAction) -{ - TX_ENSURE_CURRENTNODE; - - nsresult rv; - if ((aAction & eCloseElement) && mParentNode) { - nsCOMPtr document = do_QueryInterface(mParentNode); - nsCOMPtr currentElement = do_QueryInterface(mCurrentNode); - - if (document && currentElement && mRootContent) { - // We already have a document element, but the XSLT spec allows this. - // As a workaround, create a wrapper object and use that as the - // document element. - nsCOMPtr wrapper; - - rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kTXNameSpaceURI), - NS_LITERAL_STRING(kTXWrapper), - getter_AddRefs(wrapper)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create wrapper element"); - - nsCOMPtr child, resultNode; - PRUint32 i, j, childCount = document->GetChildCount(); - for (i = 0, j = 0; i < childCount; ++i) { - nsCOMPtr childContent = document->GetChildAt(j); - if (childContent == mRootContent) { - document->SetRootContent(nsnull); - } - child = do_QueryInterface(childContent); - PRUint16 nodeType; - child->GetNodeType(&nodeType); - switch (nodeType) { - case nsIDOMNode::ELEMENT_NODE: - case nsIDOMNode::TEXT_NODE: - case nsIDOMNode::CDATA_SECTION_NODE: - case nsIDOMNode::ENTITY_REFERENCE_NODE: - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: - case nsIDOMNode::COMMENT_NODE: - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: - { - rv = wrapper->AppendChild(child, - getter_AddRefs(resultNode)); - if (NS_FAILED(rv)) { - // XXX Need to notify about this! - ++j; - } - } - default: - { - ++j; - } - } - } - - mParentNode = wrapper; - mRootContent = do_QueryInterface(wrapper); - // XXXbz what to do on failure here? - document->SetRootContent(mRootContent); - } - - if (mDontAddCurrent && !mNonAddedParent) { - mNonAddedParent = mParentNode; - mNonAddedNode = mCurrentNode; - } - else { - if (document && currentElement && !mRootContent) { - mRootContent = do_QueryInterface(mCurrentNode); - // XXXbz what to do on failure here? - document->SetRootContent(mRootContent); - } - else { - nsCOMPtr resultNode; - - rv = mParentNode->AppendChild(mCurrentNode, getter_AddRefs(resultNode)); - if (NS_FAILED(rv)) { - mBadChildLevel = 1; - mCurrentNode = mParentNode; - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("closePrevious, mBadChildLevel = %d\n", - mBadChildLevel)); - // warning to the console - nsCOMPtr consoleSvc = - do_GetService("@mozilla.org/consoleservice;1", &rv); - if (consoleSvc) { - consoleSvc->LogStringMessage( - NS_LITERAL_STRING("failed to create XSLT content").get()); - } - } - } - } - mParentNode = nsnull; - } - else if ((aAction & eFlushText) && !mText.IsEmpty()) { - nsCOMPtr text; - rv = mDocument->CreateTextNode(mText, getter_AddRefs(text)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create text node"); - - nsCOMPtr resultNode; - rv = mCurrentNode->AppendChild(text, getter_AddRefs(resultNode)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append text node"); - - mText.Truncate(); - } -} - -void txMozillaXMLOutput::startHTMLElement(nsIDOMElement* aElement, PRBool aXHTML) -{ - nsresult rv = NS_OK; - nsCOMPtr content = do_QueryInterface(aElement); - nsIAtom *atom = content->Tag(); - - mDontAddCurrent = (atom == txHTMLAtoms::script); - - if ((atom != txHTMLAtoms::tr || aXHTML) && - NS_PTR_TO_INT32(mTableStateStack.peek()) == ADDED_TBODY) { - nsCOMPtr parent; - mCurrentNode->GetParentNode(getter_AddRefs(parent)); - mCurrentNode.swap(parent); - mTableStateStack.pop(); - } - - if (atom == txHTMLAtoms::table && !aXHTML) { - mTableState = TABLE; - } - else if (atom == txHTMLAtoms::tr && !aXHTML && - NS_PTR_TO_INT32(mTableStateStack.peek()) == TABLE) { - nsCOMPtr elem; - rv = createHTMLElement(NS_LITERAL_STRING("tbody"), - getter_AddRefs(elem)); - if (NS_FAILED(rv)) { - return; - } - nsCOMPtr dummy; - rv = mCurrentNode->AppendChild(elem, getter_AddRefs(dummy)); - if (NS_FAILED(rv)) { - return; - } - rv = mTableStateStack.push(NS_INT32_TO_PTR(ADDED_TBODY)); - if (NS_FAILED(rv)) { - return; - } - mCurrentNode = elem; - } - else if (atom == txHTMLAtoms::head && - mOutputFormat.mMethod == eHTMLOutput) { - // Insert META tag, according to spec, 16.2, like - // - nsCOMPtr meta; - rv = createHTMLElement(NS_LITERAL_STRING("meta"), - getter_AddRefs(meta)); - if (NS_FAILED(rv)) { - return; - } - rv = meta->SetAttribute(NS_LITERAL_STRING("http-equiv"), - NS_LITERAL_STRING("Content-Type")); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't set http-equiv on meta"); - nsAutoString metacontent; - metacontent.Append(mOutputFormat.mMediaType); - metacontent.AppendLiteral("; charset="); - metacontent.Append(mOutputFormat.mEncoding); - rv = meta->SetAttribute(NS_LITERAL_STRING("content"), - metacontent); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't set content on meta"); - nsCOMPtr dummy; - rv = aElement->AppendChild(meta, getter_AddRefs(dummy)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append meta"); - } -} - -void txMozillaXMLOutput::endHTMLElement(nsIDOMElement* aElement) -{ - nsresult rv; - nsCOMPtr content = do_QueryInterface(aElement); - NS_ASSERTION(content, "Can't QI to nsIContent"); - - nsIAtom *atom = content->Tag(); - - if (mTableState == ADDED_TBODY) { - NS_ASSERTION(atom == txHTMLAtoms::tbody, - "Element flagged as added tbody isn't a tbody"); - nsCOMPtr parent; - mCurrentNode->GetParentNode(getter_AddRefs(parent)); - mCurrentNode = parent; - mTableState = NS_STATIC_CAST(TableState, - NS_PTR_TO_INT32(mTableStateStack.pop())); - - return; - } - - // Load scripts - if (mNotifier && atom == txHTMLAtoms::script) { - // Add this script element to the array of loading script elements. - nsCOMPtr scriptElement = - do_QueryInterface(mCurrentNode); - NS_ASSERTION(scriptElement, "Need script element"); - mNotifier->AddScriptElement(scriptElement); - } - // Set document title - else if (mCreatingNewDocument && - atom == txHTMLAtoms::title && !mHaveTitleElement) { - // The first title wins - mHaveTitleElement = PR_TRUE; - nsCOMPtr domDoc = do_QueryInterface(mDocument); - nsCOMPtr textNode; - aElement->GetFirstChild(getter_AddRefs(textNode)); - if (domDoc && textNode) { - nsAutoString text; - textNode->GetNodeValue(text); - text.CompressWhitespace(); - domDoc->SetTitle(text); - } - } - else if (mCreatingNewDocument && atom == txHTMLAtoms::base && - !mHaveBaseElement) { - // The first base wins - mHaveBaseElement = PR_TRUE; - - nsCOMPtr doc = do_QueryInterface(mDocument); - NS_ASSERTION(doc, "document doesn't implement nsIDocument"); - nsAutoString value; - content->GetAttr(kNameSpaceID_None, txHTMLAtoms::target, value); - doc->SetBaseTarget(value); - - content->GetAttr(kNameSpaceID_None, txHTMLAtoms::href, value); - nsCOMPtr baseURI; - rv = NS_NewURI(getter_AddRefs(baseURI), value, nsnull); - if (NS_FAILED(rv)) - return; - doc->SetBaseURI(baseURI); // The document checks if it is legal to set this base - } - else if (mCreatingNewDocument && atom == txHTMLAtoms::meta) { - // handle HTTP-EQUIV data - nsAutoString httpEquiv; - content->GetAttr(kNameSpaceID_None, txHTMLAtoms::httpEquiv, httpEquiv); - if (httpEquiv.IsEmpty()) - return; - - nsAutoString value; - content->GetAttr(kNameSpaceID_None, txHTMLAtoms::content, value); - if (value.IsEmpty()) - return; - - TX_ToLowerCase(httpEquiv); - nsCOMPtr header = do_GetAtom(httpEquiv); - processHTTPEquiv(header, value); - } -} - -void txMozillaXMLOutput::processHTTPEquiv(nsIAtom* aHeader, const nsAString& aValue) -{ - // For now we only handle "refresh". There's a longer list in - // HTMLContentSink::ProcessHeaderData - if (aHeader == txHTMLAtoms::refresh) - CopyUCS2toASCII(aValue, mRefreshString); -} - -nsresult -txMozillaXMLOutput::createResultDocument(const nsAString& aName, PRInt32 aNsID, - nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument) -{ - nsresult rv; - - nsCOMPtr doc; - if (!aResultDocument) { - // Create the document - if (mOutputFormat.mMethod == eHTMLOutput) { - doc = do_CreateInstance(kHTMLDocumentCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - mDocumentIsHTML = PR_TRUE; - } - else { - // We should check the root name/namespace here and create the - // appropriate document - doc = do_CreateInstance(kXMLDocumentCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - mDocumentIsHTML = PR_FALSE; - } - mDocument = do_QueryInterface(doc); - } - else { - mDocument = aResultDocument; - doc = do_QueryInterface(aResultDocument); - - nsCOMPtr doc = do_QueryInterface(aResultDocument); - mDocumentIsHTML = doc && !doc->IsCaseSensitive(); - } - - mCurrentNode = mDocument; - - // Reset and set up the document - URIUtils::ResetWithSource(doc, aSourceDocument); - - // Set the charset - if (!mOutputFormat.mEncoding.IsEmpty()) { - NS_LossyConvertUTF16toASCII charset(mOutputFormat.mEncoding); - nsCAutoString canonicalCharset; - nsCOMPtr calias = - do_GetService("@mozilla.org/intl/charsetalias;1"); - - if (calias && - NS_SUCCEEDED(calias->GetPreferred(charset, canonicalCharset))) { - doc->SetDocumentCharacterSet(canonicalCharset); - doc->SetDocumentCharacterSetSource(kCharsetFromOtherComponent); - } - } - - // Set the mime-type - if (!mOutputFormat.mMediaType.IsEmpty()) { - doc->SetContentType(mOutputFormat.mMediaType); - } - else if (mOutputFormat.mMethod == eHTMLOutput) { - doc->SetContentType(NS_LITERAL_STRING("text/html")); - } - else { - doc->SetContentType(NS_LITERAL_STRING("application/xml")); - } - - // Set up script loader of the result document. - nsIScriptLoader *loader = doc->GetScriptLoader(); - if (loader) { - if (mNotifier) { - loader->AddObserver(mNotifier); - } - else { - // Don't load scripts, we can't notify the caller when they're loaded. - loader->SetEnabled(PR_FALSE); - } - } - - if (mNotifier) { - mNotifier->SetOutputDocument(mDocument); - } - - // Do this after calling OnDocumentCreated to ensure that the - // PresShell/PresContext has been hooked up and get notified. - nsCOMPtr htmlDoc = do_QueryInterface(doc); - if (htmlDoc) { - htmlDoc->SetCompatibilityMode(eCompatibility_FullStandards); - } - - // Add a doc-type if requested - if (!mOutputFormat.mSystemId.IsEmpty()) { - nsCOMPtr implementation; - rv = aSourceDocument->GetImplementation(getter_AddRefs(implementation)); - NS_ENSURE_SUCCESS(rv, rv); - nsAutoString qName; - if (mOutputFormat.mMethod == eHTMLOutput) { - qName.AssignLiteral("html"); - } - else { - qName.Assign(aName); - } - nsCOMPtr documentType; - rv = implementation->CreateDocumentType(qName, - mOutputFormat.mPublicId, - mOutputFormat.mSystemId, - getter_AddRefs(documentType)); - NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create doctype"); - nsCOMPtr tmp; - mDocument->AppendChild(documentType, getter_AddRefs(tmp)); - } - - return NS_OK; -} - -nsresult -txMozillaXMLOutput::createHTMLElement(const nsAString& aName, - nsIDOMElement** aResult) -{ - if (mDocumentIsHTML) { - return mDocument->CreateElement(aName, aResult); - } - - return mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), - aName, aResult); -} - -txTransformNotifier::txTransformNotifier() - : mInTransform(PR_FALSE) - -{ -} - -txTransformNotifier::~txTransformNotifier() -{ -} - -NS_IMPL_ISUPPORTS2(txTransformNotifier, - nsIScriptLoaderObserver, - nsICSSLoaderObserver) - -NS_IMETHODIMP -txTransformNotifier::ScriptAvailable(nsresult aResult, - nsIScriptElement *aElement, - PRBool aIsInline, - PRBool aWasPending, - nsIURI *aURI, - PRInt32 aLineNo, - const nsAString& aScript) -{ - if (NS_FAILED(aResult) && - mScriptElements.RemoveObject(aElement)) { - SignalTransformEnd(); - } - - return NS_OK; -} - -NS_IMETHODIMP -txTransformNotifier::ScriptEvaluated(nsresult aResult, - nsIScriptElement *aElement, - PRBool aIsInline, - PRBool aWasPending) -{ - if (mScriptElements.RemoveObject(aElement)) { - SignalTransformEnd(); - } - - return NS_OK; -} - -NS_IMETHODIMP -txTransformNotifier::StyleSheetLoaded(nsICSSStyleSheet* aSheet, - PRBool aWasAlternate, - nsresult aStatus) -{ - // Check that the stylesheet was in the mStylesheets array, if not it is an - // alternate and we don't want to call SignalTransformEnd since we don't - // wait on alternates before calling OnTransformDone and so the load of the - // alternate could finish after we called OnTransformDone already. - // See http://bugzilla.mozilla.org/show_bug.cgi?id=215465. - if (mStylesheets.RemoveObject(aSheet)) { - SignalTransformEnd(); - } - - return NS_OK; -} - -void -txTransformNotifier::Init(nsITransformObserver* aObserver) -{ - mObserver = aObserver; -} - -void -txTransformNotifier::AddScriptElement(nsIScriptElement* aElement) -{ - mScriptElements.AppendObject(aElement); -} - -void -txTransformNotifier::AddStyleSheet(nsIStyleSheet* aStyleSheet) -{ - mStylesheets.AppendObject(aStyleSheet); -} - -void -txTransformNotifier::OnTransformEnd(nsresult aResult) -{ - mInTransform = PR_FALSE; - SignalTransformEnd(aResult); -} - -void -txTransformNotifier::OnTransformStart() -{ - mInTransform = PR_TRUE; -} - -void -txTransformNotifier::SetOutputDocument(nsIDOMDocument* aDocument) -{ - mDocument = aDocument; - - // Notify the contentsink that the document is created - mObserver->OnDocumentCreated(mDocument); -} - -void -txTransformNotifier::SignalTransformEnd(nsresult aResult) -{ - if (mInTransform || (NS_SUCCEEDED(aResult) && - mScriptElements.Count() > 0 || mStylesheets.Count() > 0)) { - return; - } - - mStylesheets.Clear(); - mScriptElements.Clear(); - - // Make sure that we don't get deleted while this function is executed and - // we remove ourselfs from the scriptloader - nsCOMPtr kungFuDeathGrip(this); - - nsCOMPtr doc = do_QueryInterface(mDocument); - if (doc) { - nsIScriptLoader *scriptLoader = doc->GetScriptLoader(); - if (scriptLoader) { - scriptLoader->RemoveObserver(this); - // XXX Maybe we want to cancel script loads if NS_FAILED(rv)? - } - - if (NS_FAILED(aResult)) { - doc->CSSLoader()->Stop(); - } - } - - if (NS_SUCCEEDED(aResult)) { - mObserver->OnTransformDone(aResult, mDocument); - } -} diff --git a/extensions/transformiix/source/xslt/txMozillaXMLOutput.h b/extensions/transformiix/source/xslt/txMozillaXMLOutput.h deleted file mode 100644 index 621403450c85..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaXMLOutput.h +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_MOZILLA_XML_OUTPUT_H -#define TRANSFRMX_MOZILLA_XML_OUTPUT_H - -#include "txXMLEventHandler.h" -#include "nsAutoPtr.h" -#include "nsIScriptLoaderObserver.h" -#include "txOutputFormat.h" -#include "nsCOMArray.h" -#include "nsICSSLoaderObserver.h" -#include "txStack.h" - -class nsIContent; -class nsIDOMDocument; -class nsIAtom; -class nsIDOMDocumentFragment; -class nsIDOMElement; -class nsIStyleSheet; -class nsIDOMNode; -class nsITransformObserver; - -class txTransformNotifier : public nsIScriptLoaderObserver, - public nsICSSLoaderObserver -{ -public: - txTransformNotifier(); - virtual ~txTransformNotifier(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCRIPTLOADEROBSERVER - - // nsICSSLoaderObserver - NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, - PRBool aWasAlternate, - nsresult aStatus); - - void Init(nsITransformObserver* aObserver); - void AddScriptElement(nsIScriptElement* aElement); - void AddStyleSheet(nsIStyleSheet* aStyleSheet); - void OnTransformEnd(nsresult aResult = NS_OK); - void OnTransformStart(); - void SetOutputDocument(nsIDOMDocument* aDocument); - -private: - void SignalTransformEnd(nsresult aResult = NS_OK); - - nsCOMPtr mDocument; - nsCOMPtr mObserver; - nsCOMArray mScriptElements; - nsCOMArray mStylesheets; - PRPackedBool mInTransform; -}; - -class txMozillaXMLOutput : public txAOutputXMLEventHandler -{ -public: - txMozillaXMLOutput(const nsAString& aRootName, - PRInt32 aRootNsID, - txOutputFormat* aFormat, - nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument, - nsITransformObserver* aObserver); - txMozillaXMLOutput(txOutputFormat* aFormat, - nsIDOMDocumentFragment* aFragment); - virtual ~txMozillaXMLOutput(); - - TX_DECL_TXAXMLEVENTHANDLER - TX_DECL_TXAOUTPUTXMLEVENTHANDLER - -private: - void closePrevious(PRInt8 aAction); - void startHTMLElement(nsIDOMElement* aElement, PRBool aXHTML); - void endHTMLElement(nsIDOMElement* aElement); - void processHTTPEquiv(nsIAtom* aHeader, const nsAString& aValue); - nsresult createResultDocument(const nsAString& aName, PRInt32 aNsID, - nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument); - nsresult createHTMLElement(const nsAString& aName, - nsIDOMElement** aResult); - - nsCOMPtr mDocument; - nsCOMPtr mCurrentNode; - nsCOMPtr mParentNode; - nsCOMPtr mRootContent; - - nsCOMPtr mNonAddedParent; - nsCOMPtr mNonAddedNode; - - nsRefPtr mNotifier; - - PRUint32 mTreeDepth, mBadChildLevel; - nsCString mRefreshString; - - txStack mTableStateStack; - enum TableState { - NORMAL, // An element needing no special treatment - TABLE, // A HTML table element - ADDED_TBODY // An inserted tbody not coming from the stylesheet - }; - TableState mTableState; - - nsAutoString mText; - - txOutputFormat mOutputFormat; - - PRPackedBool mDontAddCurrent; - - PRPackedBool mHaveTitleElement; - PRPackedBool mHaveBaseElement; - - PRPackedBool mDocumentIsHTML; - PRPackedBool mCreatingNewDocument; - - enum txAction { eCloseElement = 1, eFlushText = 2 }; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp deleted file mode 100644 index 778262620a7b..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp +++ /dev/null @@ -1,1276 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txMozillaXSLTProcessor.h" -#include "nsContentCID.h" -#include "nsDOMError.h" -#include "nsIChannel.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsIDOMText.h" -#include "nsIDocument.h" -#include "nsIDOMClassInfo.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentFragment.h" -#include "nsIDOMNodeList.h" -#include "nsIIOService.h" -#include "nsILoadGroup.h" -#include "nsIScriptLoader.h" -#include "nsIStringBundle.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsXPathResult.h" -#include "txExecutionState.h" -#include "txMozillaTextOutput.h" -#include "txMozillaXMLOutput.h" -#include "txURIUtils.h" -#include "XMLUtils.h" -#include "txUnknownHandler.h" -#include "txXSLTProcessor.h" -#include "nsIPrincipal.h" -#include "jsapi.h" -#include "nsIEventQueueService.h" - -static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); - -/** - * Output Handler Factories - */ -class txToDocHandlerFactory : public txAOutputHandlerFactory -{ -public: - txToDocHandlerFactory(txExecutionState* aEs, - nsIDOMDocument* aSourceDocument, - nsIDOMDocument* aResultDocument, - nsITransformObserver* aObserver) - : mEs(aEs), mSourceDocument(aSourceDocument), - mResultDocument(aResultDocument), mObserver(aObserver) - { - } - - virtual ~txToDocHandlerFactory() - { - } - - TX_DECL_TXAOUTPUTHANDLERFACTORY - -private: - txExecutionState* mEs; - nsCOMPtr mSourceDocument; - nsCOMPtr mResultDocument; - nsCOMPtr mObserver; -}; - -class txToFragmentHandlerFactory : public txAOutputHandlerFactory -{ -public: - txToFragmentHandlerFactory(nsIDOMDocumentFragment* aFragment) - : mFragment(aFragment) - { - } - - virtual ~txToFragmentHandlerFactory() - { - } - - TX_DECL_TXAOUTPUTHANDLERFACTORY - -private: - nsCOMPtr mFragment; -}; - -nsresult -txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - txAXMLEventHandler** aHandler) -{ - *aHandler = nsnull; - switch (aFormat->mMethod) { - case eMethodNotSet: - case eXMLOutput: - { - *aHandler = new txUnknownHandler(mEs); - break; - } - - case eHTMLOutput: - { - *aHandler = new txMozillaXMLOutput(EmptyString(), - kNameSpaceID_None, - aFormat, mSourceDocument, - mResultDocument, mObserver); - break; - } - - case eTextOutput: - { - *aHandler = new txMozillaTextOutput(mSourceDocument, - mResultDocument, - mObserver); - break; - } - } - NS_ENSURE_TRUE(*aHandler, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; -} - -nsresult -txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - const nsAString& aName, - PRInt32 aNsID, - txAXMLEventHandler** aHandler) -{ - *aHandler = nsnull; - switch (aFormat->mMethod) { - case eMethodNotSet: - { - NS_ERROR("How can method not be known when root element is?"); - return NS_ERROR_UNEXPECTED; - } - - case eXMLOutput: - case eHTMLOutput: - { - *aHandler = new txMozillaXMLOutput(aName, aNsID, aFormat, - mSourceDocument, - mResultDocument, - mObserver); - break; - } - - case eTextOutput: - { - *aHandler = new txMozillaTextOutput(mSourceDocument, - mResultDocument, - mObserver); - break; - } - } - NS_ENSURE_TRUE(*aHandler, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; -} - -nsresult -txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - txAXMLEventHandler** aHandler) -{ - *aHandler = nsnull; - switch (aFormat->mMethod) { - case eMethodNotSet: - { - txOutputFormat format; - format.merge(*aFormat); - nsCOMPtr domdoc; - mFragment->GetOwnerDocument(getter_AddRefs(domdoc)); - NS_ASSERTION(domdoc, "unable to get ownerdocument"); - nsCOMPtr doc = do_QueryInterface(domdoc); - - if (!doc || doc->IsCaseSensitive()) { - format.mMethod = eXMLOutput; - } else { - format.mMethod = eHTMLOutput; - } - - *aHandler = new txMozillaXMLOutput(&format, mFragment); - break; - } - - case eXMLOutput: - case eHTMLOutput: - { - *aHandler = new txMozillaXMLOutput(aFormat, mFragment); - break; - } - - case eTextOutput: - { - *aHandler = new txMozillaTextOutput(mFragment); - break; - } - } - NS_ENSURE_TRUE(*aHandler, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; -} - -nsresult -txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - const nsAString& aName, - PRInt32 aNsID, - txAXMLEventHandler** aHandler) -{ - *aHandler = nsnull; - NS_ASSERTION(aFormat->mMethod != eMethodNotSet, - "How can method not be known when root element is?"); - NS_ENSURE_TRUE(aFormat->mMethod != eMethodNotSet, NS_ERROR_UNEXPECTED); - return createHandlerWith(aFormat, aHandler); -} - -/** - * txMozillaXSLTProcessor - */ - -NS_IMPL_ADDREF(txMozillaXSLTProcessor) -NS_IMPL_RELEASE(txMozillaXSLTProcessor) -NS_INTERFACE_MAP_BEGIN(txMozillaXSLTProcessor) - NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessor) - NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessorObsolete) - NS_INTERFACE_MAP_ENTRY(nsIDocumentTransformer) - NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXSLTProcessor) - NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XSLTProcessor) -NS_INTERFACE_MAP_END - -txMozillaXSLTProcessor::txMozillaXSLTProcessor() : mStylesheetDocument(nsnull), - mTransformResult(NS_OK), - mCompileResult(NS_OK), - mVariables(PR_TRUE) -{ -} - -txMozillaXSLTProcessor::~txMozillaXSLTProcessor() -{ - if (mStylesheetDocument) { - mStylesheetDocument->RemoveObserver(this); - } -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM, - nsIDOMNode* aStyleDOM, - nsIDOMDocument* aOutputDoc, - nsISupports* aObserver) -{ - NS_ENSURE_ARG(aSourceDOM); - NS_ENSURE_ARG(aStyleDOM); - NS_ENSURE_ARG(aOutputDoc); - NS_ENSURE_FALSE(aObserver, NS_ERROR_NOT_IMPLEMENTED); - - if (!URIUtils::CanCallerAccess(aSourceDOM) || - !URIUtils::CanCallerAccess(aStyleDOM) || - !URIUtils::CanCallerAccess(aOutputDoc)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - PRUint16 type = 0; - aStyleDOM->GetNodeType(&type); - NS_ENSURE_TRUE(type == nsIDOMNode::ELEMENT_NODE || - type == nsIDOMNode::DOCUMENT_NODE, - NS_ERROR_INVALID_ARG); - - nsresult rv = TX_CompileStylesheet(aStyleDOM, getter_AddRefs(mStylesheet)); - NS_ENSURE_SUCCESS(rv, rv); - - mSource = aSourceDOM; - - return TransformToDoc(aOutputDoc, nsnull); -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::SetTransformObserver(nsITransformObserver* aObserver) -{ - mObserver = aObserver; - return NS_OK; -} - -nsresult -txMozillaXSLTProcessor::SetSourceContentModel(nsIDOMNode* aSourceDOM) -{ - mSource = aSourceDOM; - - if (NS_FAILED(mTransformResult)) { - notifyError(); - return NS_OK; - } - - if (mStylesheet) { - return DoTransform(); - } - - return NS_OK; -} - -PR_BEGIN_EXTERN_C -void* PR_CALLBACK -HandleTransformBlockerEvent(PLEvent *aEvent) -{ - txMozillaXSLTProcessor *processor = - NS_STATIC_CAST(txMozillaXSLTProcessor*, aEvent->owner); - processor->TransformToDoc(nsnull, nsnull); - - return nsnull; -} - -void PR_CALLBACK -DestroyTransformBlockerEvent(PLEvent *aEvent) -{ - txMozillaXSLTProcessor *processor = - NS_STATIC_CAST(txMozillaXSLTProcessor*, aEvent->owner); - nsCOMPtr document = - do_QueryInterface(processor->GetSourceContentModel()); - document->UnblockOnload(PR_TRUE); - - NS_RELEASE(processor); - delete aEvent; -} -PR_END_EXTERN_C - -nsresult -txMozillaXSLTProcessor::DoTransform() -{ - NS_ENSURE_TRUE(mSource, NS_ERROR_UNEXPECTED); - NS_ENSURE_TRUE(mStylesheet, NS_ERROR_UNEXPECTED); - NS_ASSERTION(mObserver, "no observer"); - - nsresult rv; - nsCOMPtr document = do_QueryInterface(mSource, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr service = - do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr eventQ; - rv = service->GetSpecialEventQueue(nsIEventQueueService::UI_THREAD_EVENT_QUEUE, - getter_AddRefs(eventQ)); - NS_ENSURE_SUCCESS(rv, rv); - - PLEvent* event = new PLEvent(); - if (!event) { - return NS_ERROR_OUT_OF_MEMORY; - } - - PL_InitEvent(event, this, HandleTransformBlockerEvent, - DestroyTransformBlockerEvent); - - document->BlockOnload(); - - // After this point, event destruction will release |this| (in - // DestroyTransformBlockerEvent) - NS_ADDREF_THIS(); - - rv = eventQ->PostEvent(event); - if (NS_FAILED(rv)) { - // XXX Maybe we should just display the source document in this case? - // Also, set up context information, see bug 204655. - reportError(rv, nsnull, nsnull); - PL_DestroyEvent(event); - } - - return rv; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::ImportStylesheet(nsIDOMNode *aStyle) -{ - NS_ENSURE_TRUE(aStyle, NS_ERROR_NULL_POINTER); - - // We don't support importing multiple stylesheets yet. - NS_ENSURE_TRUE(!mStylesheetDocument && !mStylesheet, - NS_ERROR_NOT_IMPLEMENTED); - - if (!URIUtils::CanCallerAccess(aStyle)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - PRUint16 type = 0; - aStyle->GetNodeType(&type); - NS_ENSURE_TRUE(type == nsIDOMNode::ELEMENT_NODE || - type == nsIDOMNode::DOCUMENT_NODE, - NS_ERROR_INVALID_ARG); - - nsresult rv = TX_CompileStylesheet(aStyle, getter_AddRefs(mStylesheet)); - // XXX set up exception context, bug 204658 - NS_ENSURE_SUCCESS(rv, rv); - - if (type == nsIDOMNode::ELEMENT_NODE) { - nsCOMPtr domDoc; - aStyle->GetOwnerDocument(getter_AddRefs(domDoc)); - NS_ENSURE_TRUE(domDoc, NS_ERROR_UNEXPECTED); - - nsCOMPtr styleDoc = do_QueryInterface(domDoc); - mStylesheetDocument = styleDoc; - mEmbeddedStylesheetRoot = do_QueryInterface(aStyle); - } - else { - nsCOMPtr styleDoc = do_QueryInterface(aStyle); - mStylesheetDocument = styleDoc; - } - - mStylesheetDocument->AddObserver(this); - - return NS_OK; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::TransformToDocument(nsIDOMNode *aSource, - nsIDOMDocument **aResult) -{ - NS_ENSURE_ARG(aSource); - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_SUCCESS(mCompileResult, mCompileResult); - - if (!URIUtils::CanCallerAccess(aSource)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - nsresult rv = ensureStylesheet(); - NS_ENSURE_SUCCESS(rv, rv); - - mSource = aSource; - - return TransformToDoc(nsnull, aResult); -} - -nsresult -txMozillaXSLTProcessor::TransformToDoc(nsIDOMDocument *aOutputDoc, - nsIDOMDocument **aResult) -{ - nsAutoPtr sourceNode(txXPathNativeNode::createXPathNode(mSource)); - if (!sourceNode) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsCOMPtr sourceDOMDocument; - mSource->GetOwnerDocument(getter_AddRefs(sourceDOMDocument)); - if (!sourceDOMDocument) { - sourceDOMDocument = do_QueryInterface(mSource); - } - - txExecutionState es(mStylesheet); - - // XXX Need to add error observers - - txToDocHandlerFactory handlerFactory(&es, sourceDOMDocument, aOutputDoc, - mObserver); - es.mOutputHandlerFactory = &handlerFactory; - - es.init(*sourceNode, &mVariables); - - // Process root of XML source document - nsresult rv = txXSLTProcessor::execute(es); - es.end(rv); - if (NS_SUCCEEDED(rv)) { - if (aResult) { - txAOutputXMLEventHandler* handler = - NS_STATIC_CAST(txAOutputXMLEventHandler*, es.mOutputHandler); - handler->getOutputDocument(aResult); - } - } - else if (mObserver) { - // XXX set up context information, bug 204655 - reportError(rv, nsnull, nsnull); - } - - return rv; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::TransformToFragment(nsIDOMNode *aSource, - nsIDOMDocument *aOutput, - nsIDOMDocumentFragment **aResult) -{ - NS_ENSURE_ARG(aSource); - NS_ENSURE_ARG(aOutput); - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_SUCCESS(mCompileResult, mCompileResult); - - if (!URIUtils::CanCallerAccess(aSource) || - !URIUtils::CanCallerAccess(aOutput)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - nsresult rv = ensureStylesheet(); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr sourceNode(txXPathNativeNode::createXPathNode(aSource)); - if (!sourceNode) { - return NS_ERROR_OUT_OF_MEMORY; - } - - txExecutionState es(mStylesheet); - - // XXX Need to add error observers - - rv = aOutput->CreateDocumentFragment(aResult); - NS_ENSURE_SUCCESS(rv, rv); - txToFragmentHandlerFactory handlerFactory(*aResult); - es.mOutputHandlerFactory = &handlerFactory; - - es.init(*sourceNode, &mVariables); - - // Process root of XML source document - rv = txXSLTProcessor::execute(es); - // XXX setup exception context, bug 204658 - es.end(rv); - - return rv; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::SetParameter(const nsAString & aNamespaceURI, - const nsAString & aLocalName, - nsIVariant *aValue) -{ - NS_ENSURE_ARG(aValue); - - nsCOMPtr value = aValue; - - PRUint16 dataType; - value->GetDataType(&dataType); - switch (dataType) { - // Number - case nsIDataType::VTYPE_INT8: - case nsIDataType::VTYPE_INT16: - case nsIDataType::VTYPE_INT32: - case nsIDataType::VTYPE_INT64: - case nsIDataType::VTYPE_UINT8: - case nsIDataType::VTYPE_UINT16: - case nsIDataType::VTYPE_UINT32: - case nsIDataType::VTYPE_UINT64: - case nsIDataType::VTYPE_FLOAT: - case nsIDataType::VTYPE_DOUBLE: - - // Boolean - case nsIDataType::VTYPE_BOOL: - - // String - case nsIDataType::VTYPE_CHAR: - case nsIDataType::VTYPE_WCHAR: - case nsIDataType::VTYPE_DOMSTRING: - case nsIDataType::VTYPE_CHAR_STR: - case nsIDataType::VTYPE_WCHAR_STR: - case nsIDataType::VTYPE_STRING_SIZE_IS: - case nsIDataType::VTYPE_WSTRING_SIZE_IS: - case nsIDataType::VTYPE_UTF8STRING: - case nsIDataType::VTYPE_CSTRING: - case nsIDataType::VTYPE_ASTRING: - { - break; - } - - // Nodeset - case nsIDataType::VTYPE_INTERFACE: - case nsIDataType::VTYPE_INTERFACE_IS: - { - nsCOMPtr supports; - nsresult rv = value->GetAsISupports(getter_AddRefs(supports)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr node = do_QueryInterface(supports); - if (node) { - if (!URIUtils::CanCallerAccess(node)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - - break; - } - - nsCOMPtr xpathResult = do_QueryInterface(supports); - if (xpathResult) { - nsRefPtr result; - nsresult rv = xpathResult->GetExprResult(getter_AddRefs(result)); - NS_ENSURE_SUCCESS(rv, rv); - - if (result->getResultType() == txAExprResult::NODESET) { - txNodeSet *nodeSet = - NS_STATIC_CAST(txNodeSet*, - NS_STATIC_CAST(txAExprResult*, result)); - - nsCOMPtr node; - PRInt32 i, count = nodeSet->size(); - for (i = 0; i < count; ++i) { - rv = txXPathNativeNode::getNode(nodeSet->get(i), - getter_AddRefs(node)); - NS_ENSURE_SUCCESS(rv, rv); - - if (!URIUtils::CanCallerAccess(node)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - } - } - - // Clone the nsXPathResult so that mutations don't affect this - // variable. - nsCOMPtr clone; - rv = xpathResult->Clone(getter_AddRefs(clone)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr variant = - do_CreateInstance("@mozilla.org/variant;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - rv = variant->SetAsISupports(clone); - NS_ENSURE_SUCCESS(rv, rv); - - value = variant; - - break; - } - - nsCOMPtr nodeList = do_QueryInterface(supports); - if (nodeList) { - PRUint32 length; - nodeList->GetLength(&length); - - nsCOMPtr node; - PRUint32 i; - for (i = 0; i < length; ++i) { - nodeList->Item(i, getter_AddRefs(node)); - - if (!URIUtils::CanCallerAccess(node)) { - return NS_ERROR_DOM_SECURITY_ERR; - } - } - - break; - } - - // Random JS Objects will be converted to a string. - nsCOMPtr holder = - do_QueryInterface(supports); - if (holder) { - break; - } - - // We don't know how to handle this type of param. - return NS_ERROR_ILLEGAL_VALUE; - } - - case nsIDataType::VTYPE_ARRAY: - { - PRUint16 type; - nsIID iid; - PRUint32 count; - void* array; - nsresult rv = value->GetAsArray(&type, &iid, &count, &array); - NS_ENSURE_SUCCESS(rv, rv); - - if (type != nsIDataType::VTYPE_INTERFACE && - type != nsIDataType::VTYPE_INTERFACE_IS) { - nsMemory::Free(array); - - // We only support arrays of DOM nodes. - return NS_ERROR_ILLEGAL_VALUE; - } - - nsISupports** values = NS_STATIC_CAST(nsISupports**, array); - - PRUint32 i; - for (i = 0; i < count; ++i) { - nsISupports *supports = values[i]; - nsCOMPtr node = do_QueryInterface(supports); - - if (node) { - rv = URIUtils::CanCallerAccess(node) ? NS_OK : - NS_ERROR_DOM_SECURITY_ERR; - } - else { - // We only support arrays of DOM nodes. - rv = NS_ERROR_ILLEGAL_VALUE; - } - - if (NS_FAILED(rv)) { - while (i < count) { - NS_RELEASE(values[i++]); - } - nsMemory::Free(array); - - return rv; - } - - NS_RELEASE(supports); - } - - nsMemory::Free(array); - - break; - } - - default: - { - return NS_ERROR_FAILURE; - } - } - - PRInt32 nsId = kNameSpaceID_Unknown; - nsresult rv = gTxNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsId); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr localName = do_GetAtom(aLocalName); - txExpandedName varName(nsId, localName); - - txVariable* var = (txVariable*)mVariables.get(varName); - if (var) { - var->setValue(value); - return NS_OK; - } - - var = new txVariable(value); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - return mVariables.add(varName, var); -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::GetParameter(const nsAString& aNamespaceURI, - const nsAString& aLocalName, - nsIVariant **aResult) -{ - PRInt32 nsId = kNameSpaceID_Unknown; - nsresult rv = gTxNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsId); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr localName = do_GetAtom(aLocalName); - txExpandedName varName(nsId, localName); - - txVariable* var = (txVariable*)mVariables.get(varName); - if (var) { - return var->getValue(aResult); - } - return NS_OK; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::RemoveParameter(const nsAString& aNamespaceURI, - const nsAString& aLocalName) -{ - PRInt32 nsId = kNameSpaceID_Unknown; - nsresult rv = gTxNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsId); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr localName = do_GetAtom(aLocalName); - txExpandedName varName(nsId, localName); - - mVariables.remove(varName); - return NS_OK; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::ClearParameters() -{ - mVariables.clear(); - - return NS_OK; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::Reset() -{ - if (mStylesheetDocument) { - mStylesheetDocument->RemoveObserver(this); - } - mStylesheet = nsnull; - mStylesheetDocument = nsnull; - mEmbeddedStylesheetRoot = nsnull; - mCompileResult = NS_OK; - mVariables.clear(); - - return NS_OK; -} - -NS_IMETHODIMP -txMozillaXSLTProcessor::LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup, - nsIPrincipal* aCallerPrincipal) -{ - nsresult rv = TX_LoadSheet(aUri, this, aLoadGroup, aCallerPrincipal); - if (NS_FAILED(rv) && mObserver) { - // This is most likely a network or security error, just - // use the uri as context. - nsCAutoString spec; - if (aUri) { - aUri->GetSpec(spec); - CopyUTF8toUTF16(spec, mSourceText); - } - reportError(rv, nsnull, nsnull); - } - return rv; -} - -nsresult -txMozillaXSLTProcessor::setStylesheet(txStylesheet* aStylesheet) -{ - mStylesheet = aStylesheet; - if (mSource) { - return DoTransform(); - } - return NS_OK; -} - -void -txMozillaXSLTProcessor::reportError(nsresult aResult, - const PRUnichar *aErrorText, - const PRUnichar *aSourceText) -{ - if (!mObserver) { - return; - } - - mTransformResult = aResult; - - if (aErrorText) { - mErrorText.Assign(aErrorText); - } - else { - nsCOMPtr sbs = - do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if (sbs) { - nsXPIDLString errorText; - sbs->FormatStatusMessage(aResult, EmptyString().get(), - getter_Copies(errorText)); - - nsXPIDLString errorMessage; - nsCOMPtr bundle; - sbs->CreateBundle(XSLT_MSGS_URL, getter_AddRefs(bundle)); - - if (bundle) { - const PRUnichar* error[] = { errorText.get() }; - if (mStylesheet) { - bundle->FormatStringFromName(NS_LITERAL_STRING("TransformError").get(), - error, 1, - getter_Copies(errorMessage)); - } - else { - bundle->FormatStringFromName(NS_LITERAL_STRING("LoadingError").get(), - error, 1, - getter_Copies(errorMessage)); - } - } - mErrorText.Assign(errorMessage); - } - } - - if (aSourceText) { - mSourceText.Assign(aSourceText); - } - - if (mSource) { - notifyError(); - } -} - -void -txMozillaXSLTProcessor::notifyError() -{ - nsresult rv; - nsCOMPtr errorDocument = do_CreateInstance(kXMLDocumentCID, - &rv); - if (NS_FAILED(rv)) { - return; - } - - // Set up the document - nsCOMPtr document = do_QueryInterface(errorDocument); - if (!document) { - return; - } - URIUtils::ResetWithSource(document, mSource); - - NS_NAMED_LITERAL_STRING(ns, "http://www.mozilla.org/newlayout/xml/parsererror.xml"); - - nsCOMPtr element; - rv = errorDocument->CreateElementNS(ns, NS_LITERAL_STRING("parsererror"), - getter_AddRefs(element)); - if (NS_FAILED(rv)) { - return; - } - - nsCOMPtr rootContent = do_QueryInterface(element); - if (!rootContent) { - return; - } - - rv = document->SetRootContent(rootContent); - if (NS_FAILED(rv)) { - return; - } - - nsCOMPtr text; - rv = errorDocument->CreateTextNode(mErrorText, getter_AddRefs(text)); - if (NS_FAILED(rv)) { - return; - } - - nsCOMPtr resultNode; - rv = element->AppendChild(text, getter_AddRefs(resultNode)); - if (NS_FAILED(rv)) { - return; - } - - if (!mSourceText.IsEmpty()) { - nsCOMPtr sourceElement; - rv = errorDocument->CreateElementNS(ns, - NS_LITERAL_STRING("sourcetext"), - getter_AddRefs(sourceElement)); - if (NS_FAILED(rv)) { - return; - } - - rv = element->AppendChild(sourceElement, getter_AddRefs(resultNode)); - if (NS_FAILED(rv)) { - return; - } - - rv = errorDocument->CreateTextNode(mSourceText, getter_AddRefs(text)); - if (NS_FAILED(rv)) { - return; - } - - rv = sourceElement->AppendChild(text, getter_AddRefs(resultNode)); - if (NS_FAILED(rv)) { - return; - } - } - - mObserver->OnTransformDone(mTransformResult, errorDocument); -} - -nsresult -txMozillaXSLTProcessor::ensureStylesheet() -{ - if (mStylesheet) { - return NS_OK; - } - - NS_ENSURE_TRUE(mStylesheetDocument, NS_ERROR_NOT_INITIALIZED); - - nsCOMPtr style = do_QueryInterface(mEmbeddedStylesheetRoot); - if (!style) { - style = do_QueryInterface(mStylesheetDocument); - } - return TX_CompileStylesheet(style, getter_AddRefs(mStylesheet)); -} - -NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(txMozillaXSLTProcessor) -NS_IMPL_NSIDOCUMENTOBSERVER_REFLOW_STUB(txMozillaXSLTProcessor) -NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(txMozillaXSLTProcessor) -NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(txMozillaXSLTProcessor) - -void -txMozillaXSLTProcessor::BeginUpdate(nsIDocument* aDocument, - nsUpdateType aUpdateType) -{ -} - -void -txMozillaXSLTProcessor::EndUpdate(nsIDocument* aDocument, - nsUpdateType aUpdateType) -{ -} - -void -txMozillaXSLTProcessor::DocumentWillBeDestroyed(nsIDocument* aDocument) -{ - if (NS_FAILED(mCompileResult)) { - return; - } - - mCompileResult = ensureStylesheet(); - mStylesheetDocument = nsnull; - mEmbeddedStylesheetRoot = nsnull; - - // This might not be neccesary, but just in case some element ends up - // causing a notification as the document goes away we don't want to - // invalidate the stylesheet. - aDocument->RemoveObserver(this); -} - -void -txMozillaXSLTProcessor::CharacterDataChanged(nsIDocument* aDocument, - nsIContent *aContent, - PRBool aAppend) -{ - mStylesheet = nsnull; -} - -void -txMozillaXSLTProcessor::AttributeChanged(nsIDocument* aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType) -{ - mStylesheet = nsnull; -} - -void -txMozillaXSLTProcessor::ContentAppended(nsIDocument* aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ - mStylesheet = nsnull; -} - -void -txMozillaXSLTProcessor::ContentInserted(nsIDocument* aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - mStylesheet = nsnull; -} - -void -txMozillaXSLTProcessor::ContentRemoved(nsIDocument* aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - mStylesheet = nsnull; -} - -/* static*/ -nsresult -txVariable::Convert(nsIVariant *aValue, txAExprResult** aResult) -{ - *aResult = nsnull; - - PRUint16 dataType; - aValue->GetDataType(&dataType); - switch (dataType) { - // Number - case nsIDataType::VTYPE_INT8: - case nsIDataType::VTYPE_INT16: - case nsIDataType::VTYPE_INT32: - case nsIDataType::VTYPE_INT64: - case nsIDataType::VTYPE_UINT8: - case nsIDataType::VTYPE_UINT16: - case nsIDataType::VTYPE_UINT32: - case nsIDataType::VTYPE_UINT64: - case nsIDataType::VTYPE_FLOAT: - case nsIDataType::VTYPE_DOUBLE: - { - double value; - nsresult rv = aValue->GetAsDouble(&value); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = new NumberResult(value, nsnull); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - - return NS_OK; - } - - // Boolean - case nsIDataType::VTYPE_BOOL: - { - PRBool value; - nsresult rv = aValue->GetAsBool(&value); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = new BooleanResult(value); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - - return NS_OK; - } - - // String - case nsIDataType::VTYPE_CHAR: - case nsIDataType::VTYPE_WCHAR: - case nsIDataType::VTYPE_DOMSTRING: - case nsIDataType::VTYPE_CHAR_STR: - case nsIDataType::VTYPE_WCHAR_STR: - case nsIDataType::VTYPE_STRING_SIZE_IS: - case nsIDataType::VTYPE_WSTRING_SIZE_IS: - case nsIDataType::VTYPE_UTF8STRING: - case nsIDataType::VTYPE_CSTRING: - case nsIDataType::VTYPE_ASTRING: - { - nsAutoString value; - nsresult rv = aValue->GetAsAString(value); - NS_ENSURE_SUCCESS(rv, rv); - - *aResult = new StringResult(value, nsnull); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - - return NS_OK; - } - - // Nodeset - case nsIDataType::VTYPE_INTERFACE: - case nsIDataType::VTYPE_INTERFACE_IS: - { - nsCOMPtr supports; - nsresult rv = aValue->GetAsISupports(getter_AddRefs(supports)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr node = do_QueryInterface(supports); - if (node) { - nsAutoPtr xpathNode(txXPathNativeNode::createXPathNode(node)); - if (!xpathNode) { - return NS_ERROR_FAILURE; - } - - *aResult = new txNodeSet(*xpathNode, nsnull); - if (!*aResult) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult); - - return NS_OK; - } - - nsCOMPtr xpathResult = do_QueryInterface(supports); - if (xpathResult) { - return xpathResult->GetExprResult(aResult); - } - - nsCOMPtr nodeList = do_QueryInterface(supports); - if (nodeList) { - nsRefPtr nodeSet = new txNodeSet(nsnull); - if (!nodeSet) { - return NS_ERROR_OUT_OF_MEMORY; - } - - PRUint32 length; - nodeList->GetLength(&length); - - nsCOMPtr node; - PRUint32 i; - for (i = 0; i < length; ++i) { - nodeList->Item(i, getter_AddRefs(node)); - - nsAutoPtr xpathNode( - txXPathNativeNode::createXPathNode(node)); - if (!xpathNode) { - return NS_ERROR_FAILURE; - } - - nodeSet->add(*xpathNode); - } - - NS_ADDREF(*aResult = nodeSet); - - return NS_OK; - } - - // Convert random JS Objects to a string. - nsCOMPtr holder = - do_QueryInterface(supports); - if (holder) { - nsCOMPtr xpc = - do_GetService(nsIXPConnect::GetCID(), &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr cc; - rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); - NS_ENSURE_SUCCESS(rv, rv); - - JSContext* cx; - rv = cc->GetJSContext(&cx); - NS_ENSURE_SUCCESS(rv, rv); - - JSObject *jsobj; - rv = holder->GetJSObject(&jsobj); - NS_ENSURE_SUCCESS(rv, rv); - - JSString *str = JS_ValueToString(cx, OBJECT_TO_JSVAL(jsobj)); - NS_ENSURE_TRUE(str, NS_ERROR_FAILURE); - - const PRUnichar *strChars = - NS_REINTERPRET_CAST(const PRUnichar*, - ::JS_GetStringChars(str)); - nsDependentString value(strChars, ::JS_GetStringLength(str)); - - *aResult = new StringResult(value, nsnull); - if (!*aResult) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aResult); - - return NS_OK; - } - - break; - } - - case nsIDataType::VTYPE_ARRAY: - { - PRUint16 type; - nsIID iid; - PRUint32 count; - void* array; - nsresult rv = aValue->GetAsArray(&type, &iid, &count, &array); - NS_ENSURE_SUCCESS(rv, rv); - - NS_ASSERTION(type == nsIDataType::VTYPE_INTERFACE || - type == nsIDataType::VTYPE_INTERFACE_IS, - "Huh, we checked this in SetParameter?"); - - nsISupports** values = NS_STATIC_CAST(nsISupports**, array); - - nsRefPtr nodeSet = new txNodeSet(nsnull); - if (!nodeSet) { - NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, values); - - return NS_ERROR_OUT_OF_MEMORY; - } - - PRUint32 i; - for (i = 0; i < count; ++i) { - nsISupports *supports = values[i]; - nsCOMPtr node = do_QueryInterface(supports); - NS_ASSERTION(node, "Huh, we checked this in SetParameter?"); - - nsAutoPtr xpathNode( - txXPathNativeNode::createXPathNode(node)); - if (!xpathNode) { - while (i < count) { - NS_RELEASE(values[i++]); - } - nsMemory::Free(array); - - return NS_ERROR_FAILURE; - } - - nodeSet->add(*xpathNode); - - NS_RELEASE(supports); - } - - nsMemory::Free(array); - - NS_ADDREF(*aResult = nodeSet); - - return NS_OK; - } - } - - return NS_ERROR_ILLEGAL_VALUE; -} diff --git a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h deleted file mode 100644 index 4c1f3e309db1..000000000000 --- a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXMOZILLAXSLTPROCESSOR_H -#define TRANSFRMX_TXMOZILLAXSLTPROCESSOR_H - -#include "ExprResult.h" -#include "nsIDocumentTransformer.h" -#include "nsIVariant.h" -#include "nsIXSLTProcessor.h" -#include "nsVoidArray.h" -#include "nsWeakPtr.h" -#include "txExpandedNameMap.h" -#include "txXMLEventHandler.h" -#include "nsIXSLTProcessorObsolete.h" -#include "txXSLTProcessor.h" -#include "nsVoidArray.h" -#include "nsAutoPtr.h" -#include "nsIDocumentObserver.h" - -class nsIURI; -class nsIXMLContentSink; -class nsIDOMNode; -class nsIPrincipal; - -/* bacd8ad0-552f-11d3-a9f7-000064657374 */ -#define TRANSFORMIIX_XSLT_PROCESSOR_CID \ -{ 0xbacd8ad0, 0x552f, 0x11d3, {0xa9, 0xf7, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} } - -#define TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID \ -"@mozilla.org/document-transformer;1?type=xslt" - -#define XSLT_MSGS_URL "chrome://global/locale/xslt/xslt.properties" - -class txVariable : public txIGlobalParameter -{ -public: - txVariable(nsIVariant *aValue) : mValue(aValue), - mTxValue(nsnull) - { - } - nsresult getValue(txAExprResult** aValue) - { - NS_ASSERTION(mValue, "variablevalue is null"); - - if (!mTxValue) { - nsresult rv = Convert(mValue, getter_AddRefs(mTxValue)); - NS_ENSURE_SUCCESS(rv, rv); - } - - *aValue = mTxValue; - NS_ADDREF(*aValue); - - return NS_OK; - } - nsresult getValue(nsIVariant** aValue) - { - *aValue = mValue; - NS_ADDREF(*aValue); - return NS_OK; - } - void setValue(nsIVariant* aValue) - { - NS_ASSERTION(aValue, "setting variablevalue to null"); - mValue = aValue; - mTxValue = nsnull; - } - -private: - static nsresult Convert(nsIVariant *aValue, txAExprResult** aResult); - - nsCOMPtr mValue; - nsRefPtr mTxValue; -}; - -/** - * txMozillaXSLTProcessor is a front-end to the XSLT Processor. - */ -class txMozillaXSLTProcessor : public nsIXSLTProcessor, - public nsIXSLTProcessorObsolete, - public nsIDocumentTransformer, - public nsIDocumentObserver -{ -public: - /** - * Creates a new txMozillaXSLTProcessor - */ - txMozillaXSLTProcessor(); - - /** - * Default destructor for txMozillaXSLTProcessor - */ - virtual ~txMozillaXSLTProcessor(); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIXSLTProcessor interface - NS_DECL_NSIXSLTPROCESSOR - - // nsIXSLTProcessorObsolete interface - NS_DECL_NSIXSLTPROCESSOROBSOLETE - - // nsIDocumentTransformer interface - NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver); - NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup, - nsIPrincipal* aCallerPrincipal); - NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource); - NS_IMETHOD CancelLoads() {return NS_OK;}; - - // nsIDocumentObserver interface - NS_DECL_NSIDOCUMENTOBSERVER - - nsresult setStylesheet(txStylesheet* aStylesheet); - void reportError(nsresult aResult, const PRUnichar *aErrorText, - const PRUnichar *aSourceText); - - nsIDOMNode *GetSourceContentModel() - { - return mSource; - } - - nsresult TransformToDoc(nsIDOMDocument *aOutputDoc, - nsIDOMDocument **aResult); - -private: - nsresult DoTransform(); - void notifyError(); - nsresult ensureStylesheet(); - - nsRefPtr mStylesheet; - nsIDocument* mStylesheetDocument; // weak - nsCOMPtr mEmbeddedStylesheetRoot; - - nsCOMPtr mSource; - nsresult mTransformResult; - nsresult mCompileResult; - nsString mErrorText, mSourceText; - nsCOMPtr mObserver; - txExpandedNameMap mVariables; -}; - -extern nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor, - nsILoadGroup* aLoadGroup, - nsIPrincipal* aCallerPrincipal); - -extern nsresult TX_CompileStylesheet(nsIDOMNode* aNode, - txStylesheet** aStylesheet); - -#endif diff --git a/extensions/transformiix/source/xslt/txOutputFormat.cpp b/extensions/transformiix/source/xslt/txOutputFormat.cpp deleted file mode 100644 index afedacf6bb57..000000000000 --- a/extensions/transformiix/source/xslt/txOutputFormat.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txOutputFormat.h" -#include "XMLUtils.h" - -txOutputFormat::txOutputFormat() : mMethod(eMethodNotSet), - mOmitXMLDeclaration(eNotSet), - mStandalone(eNotSet), - mIndent(eNotSet) -{ -} - -txOutputFormat::~txOutputFormat() -{ - txListIterator iter(&mCDATASectionElements); - while (iter.hasNext()) - delete (txExpandedName*)iter.next(); -} - -void txOutputFormat::reset() -{ - mMethod = eMethodNotSet; - mVersion.Truncate(); - if (mEncoding.IsEmpty()) - mOmitXMLDeclaration = eNotSet; - mStandalone = eNotSet; - mPublicId.Truncate(); - mSystemId.Truncate(); - txListIterator iter(&mCDATASectionElements); - while (iter.hasNext()) - delete (txExpandedName*)iter.next(); - mIndent = eNotSet; - mMediaType.Truncate(); -} - -void txOutputFormat::merge(txOutputFormat& aOutputFormat) -{ - if (mMethod == eMethodNotSet) - mMethod = aOutputFormat.mMethod; - - if (mVersion.IsEmpty()) - mVersion = aOutputFormat.mVersion; - - if (mEncoding.IsEmpty()) - mEncoding = aOutputFormat.mEncoding; - - if (mOmitXMLDeclaration == eNotSet) - mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration; - - if (mStandalone == eNotSet) - mStandalone = aOutputFormat.mStandalone; - - if (mPublicId.IsEmpty()) - mPublicId = aOutputFormat.mPublicId; - - if (mSystemId.IsEmpty()) - mSystemId = aOutputFormat.mSystemId; - - txListIterator iter(&aOutputFormat.mCDATASectionElements); - txExpandedName* qName; - while ((qName = (txExpandedName*)iter.next())) { - mCDATASectionElements.add(qName); - // XXX We need txList.clear() - iter.remove(); - } - - if (mIndent == eNotSet) - mIndent = aOutputFormat.mIndent; - - if (mMediaType.IsEmpty()) - mMediaType = aOutputFormat.mMediaType; -} - -void txOutputFormat::setFromDefaults() -{ - switch (mMethod) { - case eMethodNotSet: - { - mMethod = eXMLOutput; - // Fall through - } - case eXMLOutput: - { - if (mVersion.IsEmpty()) - mVersion.AppendLiteral("1.0"); - - if (mEncoding.IsEmpty()) - mEncoding.AppendLiteral("UTF-8"); - - if (mOmitXMLDeclaration == eNotSet) - mOmitXMLDeclaration = eFalse; - - if (mIndent == eNotSet) - mIndent = eFalse; - - if (mMediaType.IsEmpty()) - mMediaType.AppendLiteral("text/xml"); - - break; - } - case eHTMLOutput: - { - if (mVersion.IsEmpty()) - mVersion.AppendLiteral("4.0"); - - if (mEncoding.IsEmpty()) - mEncoding.AppendLiteral("UTF-8"); - - if (mIndent == eNotSet) - mIndent = eTrue; - - if (mMediaType.IsEmpty()) - mMediaType.AppendLiteral("text/html"); - - break; - } - case eTextOutput: - { - if (mEncoding.IsEmpty()) - mEncoding.AppendLiteral("UTF-8"); - - if (mMediaType.IsEmpty()) - mMediaType.AppendLiteral("text/plain"); - - break; - } - } -} diff --git a/extensions/transformiix/source/xslt/txOutputFormat.h b/extensions/transformiix/source/xslt/txOutputFormat.h deleted file mode 100644 index 4d6f35c5340b..000000000000 --- a/extensions/transformiix/source/xslt/txOutputFormat.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_OUTPUTFORMAT_H -#define TRANSFRMX_OUTPUTFORMAT_H - -#include "List.h" -#include "nsString.h" - -enum txOutputMethod { - eMethodNotSet, - eXMLOutput, - eHTMLOutput, - eTextOutput -}; - -enum txThreeState { - eNotSet, - eFalse, - eTrue -}; - -class txOutputFormat { -public: - txOutputFormat(); - ~txOutputFormat(); - - // "Unset" all values - void reset(); - - // Merges in the values of aOutputFormat, members that already - // have a value in this txOutputFormat will not be changed. - void merge(txOutputFormat& aOutputFormat); - - // Sets members that have no value to their default value. - void setFromDefaults(); - - // The XSLT output method, which can be "xml", "html", or "text" - txOutputMethod mMethod; - - // The xml version number that should be used when serializing - // xml documents - nsString mVersion; - - // The XML character encoding that should be used when serializing - // xml documents - nsString mEncoding; - - // Signals if we should output an XML declaration - txThreeState mOmitXMLDeclaration; - - // Signals if we should output a standalone document declaration - txThreeState mStandalone; - - // The public Id for creating a DOCTYPE - nsString mPublicId; - - // The System Id for creating a DOCTYPE - nsString mSystemId; - - // The elements whose text node children should be output as CDATA - txList mCDATASectionElements; - - // Signals if output should be indented - txThreeState mIndent; - - // The media type of the output - nsString mMediaType; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txPatternParser.cpp b/extensions/transformiix/source/xslt/txPatternParser.cpp deleted file mode 100644 index fd465d05aa8d..000000000000 --- a/extensions/transformiix/source/xslt/txPatternParser.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txPatternParser.h" -#include "ExprLexer.h" -#include "txAtoms.h" -#include "txError.h" -#include "txStringUtils.h" -#include "txXSLTPatterns.h" -#include "txIXPathContext.h" - -txPattern* txPatternParser::createPattern(const nsAFlatString& aPattern, - txIParseContext* aContext) -{ - txPattern* pattern = 0; - txExprLexer lexer; - nsresult rv = lexer.parse(aPattern); - if (NS_FAILED(rv)) { - // XXX error report parsing error - return 0; - } - rv = createUnionPattern(lexer, aContext, pattern); - if (NS_FAILED(rv)) { - // XXX error report parsing error - return 0; - } - return pattern; -} - -nsresult txPatternParser::createUnionPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern) -{ - nsresult rv = NS_OK; - txPattern* locPath = 0; - - rv = createLocPathPattern(aLexer, aContext, locPath); - if (NS_FAILED(rv)) - return rv; - - Token::Type type = aLexer.peek()->mType; - if (type == Token::END) { - aPattern = locPath; - return NS_OK; - } - - if (type != Token::UNION_OP) { - delete locPath; - return NS_ERROR_XPATH_PARSE_FAILURE; - } - - txUnionPattern* unionPattern = new txUnionPattern(); - if (!unionPattern) { - delete locPath; - return NS_ERROR_OUT_OF_MEMORY; - } - rv = unionPattern->addPattern(locPath); -#if 0 // XXX addPattern can't fail yet, it doesn't check for mem - if (NS_FAILED(rv)) { - delete unionPattern; - delete locPath; - return rv; - } -#endif - - aLexer.nextToken(); - do { - rv = createLocPathPattern(aLexer, aContext, locPath); - if (NS_FAILED(rv)) { - delete unionPattern; - return rv; - } - rv = unionPattern->addPattern(locPath); -#if 0 // XXX addPattern can't fail yet, it doesn't check for mem - if (NS_FAILED(rv)) { - delete unionPattern; - delete locPath; - return rv; - } -#endif - type = aLexer.nextToken()->mType; - } while (type == Token::UNION_OP); - - if (type != Token::END) { - delete unionPattern; - return NS_ERROR_XPATH_PARSE_FAILURE; - } - - aPattern = unionPattern; - return NS_OK; -} - -nsresult txPatternParser::createLocPathPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern) -{ - nsresult rv = NS_OK; - - MBool isChild = MB_TRUE; - MBool isAbsolute = MB_FALSE; - txPattern* stepPattern = 0; - txLocPathPattern* pathPattern = 0; - - Token::Type type = aLexer.peek()->mType; - switch (type) { - case Token::ANCESTOR_OP: - isChild = MB_FALSE; - isAbsolute = MB_TRUE; - aLexer.nextToken(); - break; - case Token::PARENT_OP: - aLexer.nextToken(); - isAbsolute = MB_TRUE; - if (aLexer.peek()->mType == Token::END || - aLexer.peek()->mType == Token::UNION_OP) { - aPattern = new txRootPattern(); - - return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY; - } - break; - case Token::FUNCTION_NAME: - // id(Literal) or key(Literal, Literal) - { - nsCOMPtr nameAtom = - do_GetAtom(aLexer.nextToken()->Value()); - if (nameAtom == txXPathAtoms::id) { - rv = createIdPattern(aLexer, stepPattern); - } - else if (nameAtom == txXSLTAtoms::key) { - rv = createKeyPattern(aLexer, aContext, stepPattern); - } - if (NS_FAILED(rv)) - return rv; - } - break; - default: - break; - } - if (!stepPattern) { - rv = createStepPattern(aLexer, aContext, stepPattern); - if (NS_FAILED(rv)) - return rv; - } - - type = aLexer.peek()->mType; - if (!isAbsolute && type != Token::PARENT_OP - && type != Token::ANCESTOR_OP) { - aPattern = stepPattern; - return NS_OK; - } - - pathPattern = new txLocPathPattern(); - if (!pathPattern) { - delete stepPattern; - return NS_ERROR_OUT_OF_MEMORY; - } - - if (isAbsolute) { - txRootPattern* root = new txRootPattern(); - if (!root) { - delete stepPattern; - delete pathPattern; - return NS_ERROR_OUT_OF_MEMORY; - } - -#ifdef TX_TO_STRING - root->setSerialize(PR_FALSE); -#endif - - rv = pathPattern->addStep(root, isChild); - if (NS_FAILED(rv)) { - delete stepPattern; - delete pathPattern; - delete root; - return NS_ERROR_OUT_OF_MEMORY; - } - } - - rv = pathPattern->addStep(stepPattern, isChild); - if (NS_FAILED(rv)) { - delete stepPattern; - delete pathPattern; - return NS_ERROR_OUT_OF_MEMORY; - } - stepPattern = 0; // stepPattern is part of pathPattern now - - while (type == Token::PARENT_OP || type == Token::ANCESTOR_OP) { - isChild = type == Token::PARENT_OP; - aLexer.nextToken(); - rv = createStepPattern(aLexer, aContext, stepPattern); - if (NS_FAILED(rv)) { - delete pathPattern; - return rv; - } - rv = pathPattern->addStep(stepPattern, isChild); - if (NS_FAILED(rv)) { - delete stepPattern; - delete pathPattern; - return NS_ERROR_OUT_OF_MEMORY; - } - stepPattern = 0; // stepPattern is part of pathPattern now - type = aLexer.peek()->mType; - } - aPattern = pathPattern; - return rv; -} - -nsresult txPatternParser::createIdPattern(txExprLexer& aLexer, - txPattern*& aPattern) -{ - // check for '(' Literal ')' - if (aLexer.nextToken()->mType != Token::L_PAREN && - aLexer.peek()->mType != Token::LITERAL) - return NS_ERROR_XPATH_PARSE_FAILURE; - const nsDependentSubstring& value = - aLexer.nextToken()->Value(); - if (aLexer.nextToken()->mType != Token::R_PAREN) - return NS_ERROR_XPATH_PARSE_FAILURE; - aPattern = new txIdPattern(value); - return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -nsresult txPatternParser::createKeyPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern) -{ - // check for '(' Literal, Literal ')' - if (aLexer.nextToken()->mType != Token::L_PAREN && - aLexer.peek()->mType != Token::LITERAL) - return NS_ERROR_XPATH_PARSE_FAILURE; - const nsDependentSubstring& key = - aLexer.nextToken()->Value(); - if (aLexer.nextToken()->mType != Token::COMMA && - aLexer.peek()->mType != Token::LITERAL) - return NS_ERROR_XPATH_PARSE_FAILURE; - const nsDependentSubstring& value = - aLexer.nextToken()->Value(); - if (aLexer.nextToken()->mType != Token::R_PAREN) - return NS_ERROR_XPATH_PARSE_FAILURE; - - const PRUnichar* colon; - if (!XMLUtils::isValidQName(PromiseFlatString(key), &colon)) - return NS_ERROR_XPATH_PARSE_FAILURE; - nsCOMPtr prefix, localName; - PRInt32 namespaceID; - nsresult rv = resolveQName(key, getter_AddRefs(prefix), aContext, - getter_AddRefs(localName), namespaceID); - if (NS_FAILED(rv)) - return rv; - - aPattern = new txKeyPattern(prefix, localName, namespaceID, value); - - return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -nsresult txPatternParser::createStepPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern) -{ - nsresult rv = NS_OK; - MBool isAttr = MB_FALSE; - Token* tok = aLexer.peek(); - if (tok->mType == Token::AXIS_IDENTIFIER) { - if (TX_StringEqualsAtom(tok->Value(), txXPathAtoms::attribute)) { - isAttr = MB_TRUE; - } - else if (!TX_StringEqualsAtom(tok->Value(), txXPathAtoms::child)) { - // all done already for CHILD_AXIS, for all others - // XXX report unexpected axis error - return NS_ERROR_XPATH_PARSE_FAILURE; - } - aLexer.nextToken(); - } - else if (tok->mType == Token::AT_SIGN) { - aLexer.nextToken(); - isAttr = MB_TRUE; - } - tok = aLexer.nextToken(); - - txNodeTest* nodeTest = 0; - if (tok->mType == Token::CNAME) { - // resolve QName - nsCOMPtr prefix, lName; - PRInt32 nspace; - rv = resolveQName(tok->Value(), getter_AddRefs(prefix), aContext, - getter_AddRefs(lName), nspace, PR_TRUE); - if (NS_FAILED(rv)) { - // XXX error report namespace resolve failed - return rv; - } - if (isAttr) { - nodeTest = new txNameTest(prefix, lName, nspace, - txXPathNodeType::ATTRIBUTE_NODE); - } - else { - nodeTest = new txNameTest(prefix, lName, nspace, - txXPathNodeType::ELEMENT_NODE); - } - if (!nodeTest) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - else { - aLexer.pushBack(); - rv = createNodeTypeTest(aLexer, &nodeTest); - NS_ENSURE_SUCCESS(rv, rv); - } - - txStepPattern* step = new txStepPattern(nodeTest, isAttr); - if (!step) { - delete nodeTest; - return NS_ERROR_OUT_OF_MEMORY; - } - nodeTest = 0; - rv = parsePredicates(step, aLexer, aContext); - if (NS_FAILED(rv)) { - delete step; - return rv; - } - - aPattern = step; - return NS_OK; -} diff --git a/extensions/transformiix/source/xslt/txPatternParser.h b/extensions/transformiix/source/xslt/txPatternParser.h deleted file mode 100644 index 75753b1871a6..000000000000 --- a/extensions/transformiix/source/xslt/txPatternParser.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TX_PATTERNPARSER_H -#define TX_PATTERNPARSER_H - -#include "txXSLTPatterns.h" -#include "ExprParser.h" - -class txPatternParser : public txExprParser -{ -public: - static txPattern* createPattern(const nsAFlatString& aPattern, - txIParseContext* aContext); -protected: - static nsresult createUnionPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern); - static nsresult createLocPathPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern); - static nsresult createIdPattern(txExprLexer& aLexer, - txPattern*& aPattern); - static nsresult createKeyPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern); - static nsresult createStepPattern(txExprLexer& aLexer, - txIParseContext* aContext, - txPattern*& aPattern); -}; - -#endif // TX_PATTERNPARSER_H diff --git a/extensions/transformiix/source/xslt/txRtfHandler.cpp b/extensions/transformiix/source/xslt/txRtfHandler.cpp deleted file mode 100644 index 8e43ca6a67b4..000000000000 --- a/extensions/transformiix/source/xslt/txRtfHandler.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txRtfHandler.h" - -txResultTreeFragment::txResultTreeFragment(nsAutoPtr& aBuffer) - : txAExprResult(nsnull), - mBuffer(aBuffer) -{ -} - -txResultTreeFragment::~txResultTreeFragment() -{ -} - -short txResultTreeFragment::getResultType() -{ - return RESULT_TREE_FRAGMENT; -} - -void txResultTreeFragment::stringValue(nsAString& aResult) -{ - if (!mBuffer) { - return; - } - - aResult.Append(mBuffer->mStringValue); -} - -nsAString* txResultTreeFragment::stringValuePointer() -{ - return mBuffer ? &mBuffer->mStringValue : nsnull; -} - -PRBool txResultTreeFragment::booleanValue() -{ - return PR_TRUE; -} - -double txResultTreeFragment::numberValue() -{ - if (!mBuffer) { - return 0; - } - - return Double::toDouble(mBuffer->mStringValue); -} - -nsresult txResultTreeFragment::flushToHandler(txAXMLEventHandler* aHandler) -{ - if (!mBuffer) { - return NS_ERROR_FAILURE; - } - - return mBuffer->flushToHandler(aHandler); -} - -txRtfHandler::txRtfHandler() -{ -} - -txRtfHandler::~txRtfHandler() -{ -} - -nsresult -txRtfHandler::getAsRTF(txAExprResult** aResult) -{ - *aResult = new txResultTreeFragment(mBuffer); - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - - return NS_OK; -} - -void txRtfHandler::endDocument(nsresult aResult) -{ -} - -void txRtfHandler::startDocument() -{ -} diff --git a/extensions/transformiix/source/xslt/txRtfHandler.h b/extensions/transformiix/source/xslt/txRtfHandler.h deleted file mode 100644 index 44a1bf3994ee..000000000000 --- a/extensions/transformiix/source/xslt/txRtfHandler.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txRtfHandler_h___ -#define txRtfHandler_h___ - -#include "txBufferingHandler.h" -#include "ExprResult.h" - -class txResultTreeFragment : public txAExprResult -{ -public: - txResultTreeFragment(nsAutoPtr& aBuffer); - ~txResultTreeFragment(); - - TX_DECL_EXPRRESULT - - nsresult flushToHandler(txAXMLEventHandler* aHandler); - -private: - nsAutoPtr mBuffer; -}; - -class txRtfHandler : public txBufferingHandler -{ -public: - txRtfHandler(); - virtual ~txRtfHandler(); - - nsresult getAsRTF(txAExprResult** aResult); - - void endDocument(nsresult aResult); - void startDocument(); -}; - -#endif /* txRtfHandler_h___ */ diff --git a/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.cpp b/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.cpp deleted file mode 100644 index b9d7a1c9f685..000000000000 --- a/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStandaloneStylesheetCompiler.h" -#include "TxLog.h" -#include "txStylesheetCompiler.h" -#include "txURIUtils.h" -#include "expat_config.h" -#include "expat.h" -#include "txXMLParser.h" - -/** - * Implementation of an In-Memory DOM based XML parser. The actual XML - * parsing is provided by EXPAT. - */ -class txDriver : public txACompileObserver -{ - public: - nsresult parse(istream& aInputStream, const nsAString& aUri); - const nsAString& getErrorString(); - - /** - * Expat handlers - */ - void StartElement(const XML_Char *aName, const XML_Char **aAtts); - void EndElement(const XML_Char* aName); - void CharacterData(const XML_Char* aChars, int aLength); - int ExternalEntityRef(const XML_Char *aContext, const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId); - - TX_DECL_ACOMPILEOBSERVER; - - nsRefPtr mCompiler; - protected: - void createErrorString(); - nsString mErrorString; - // keep track of the nsresult returned by the handlers, expat forgets them - nsresult mRV; - XML_Parser mExpatParser; - nsAutoRefCnt mRefCnt; -}; - -nsresult -TX_CompileStylesheetPath(const txParsedURL& aURL, txStylesheet** aResult) -{ - *aResult = nsnull; - nsAutoString errMsg, filePath; - - aURL.getFile(filePath); - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("TX_CompileStylesheetPath: %s\n", - NS_LossyConvertUCS2toASCII(filePath).get())); - istream* xslInput = URIUtils::getInputStream(filePath, errMsg); - if (!xslInput) { - return NS_ERROR_FAILURE; - } - nsRefPtr driver = new txDriver(); - if (!driver) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsAutoString spec = filePath; - if (!aURL.mRef.IsEmpty()) { - spec.Append(PRUnichar('#')); - spec.Append(aURL.mRef); - } - driver->mCompiler = new txStylesheetCompiler(spec, driver); - if (!driver->mCompiler) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsresult rv = driver->parse(*xslInput, filePath); - if (NS_FAILED(rv)) { - return rv; - }; - *aResult = driver->mCompiler->getStylesheet(); - NS_ADDREF(*aResult); - return NS_OK; -} - -/** - * expat C stub handlers - */ - -// shortcut macro for redirection into txDriver method calls -#define TX_DRIVER(_userData) NS_STATIC_CAST(txDriver*, _userData) - -PR_STATIC_CALLBACK(void) -startElement(void *aUserData, const XML_Char *aName, const XML_Char **aAtts) -{ - if (!aUserData) { - NS_WARNING("no userData in startElement handler"); - return; - } - TX_DRIVER(aUserData)->StartElement(aName, aAtts); -} - -PR_STATIC_CALLBACK(void) -endElement(void *aUserData, const XML_Char* aName) -{ - if (!aUserData) { - NS_WARNING("no userData in endElement handler"); - return; - } - TX_DRIVER(aUserData)->EndElement(aName); -} - -PR_STATIC_CALLBACK(void) -charData(void* aUserData, const XML_Char* aChars, int aLength) -{ - if (!aUserData) { - NS_WARNING("no userData in charData handler"); - return; - } - TX_DRIVER(aUserData)->CharacterData(aChars, aLength); -} - -PR_STATIC_CALLBACK(int) -externalEntityRefHandler(XML_Parser aParser, - const XML_Char *aContext, - const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId) -{ - // aParser is aUserData is the txDriver, - // we set that in txDriver::parse - NS_ENSURE_TRUE(aParser, XML_ERROR_NONE); - return ((txDriver*)aParser)->ExternalEntityRef(aContext, aBase, - aSystemId, aPublicId); -} - - -/** - * Parses the given input stream and returns a DOM Document. - * A NULL pointer will be returned if errors occurred - */ -nsresult -txDriver::parse(istream& aInputStream, const nsAString& aUri) -{ - mErrorString.Truncate(); - if (!aInputStream) { - mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered."); - return NS_ERROR_FAILURE; - } - - static const XML_Memory_Handling_Suite memsuite = { - (void *(*)(size_t))PR_Malloc, - (void *(*)(void *, size_t))PR_Realloc, - PR_Free - }; - static const PRUnichar expatSeparator = kExpatSeparatorChar; - mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator); - if (!mExpatParser) { - return NS_ERROR_OUT_OF_MEMORY; - } - - XML_SetReturnNSTriplet(mExpatParser, XML_TRUE); - XML_SetUserData(mExpatParser, this); - XML_SetElementHandler(mExpatParser, startElement, endElement); - XML_SetCharacterDataHandler(mExpatParser, charData); -#ifdef XML_DTD - XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS); -#endif - XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler); - XML_SetExternalEntityRefHandlerArg(mExpatParser, this); - XML_SetBase(mExpatParser, - (const XML_Char*)(PromiseFlatString(aUri).get())); - - const int bufferSize = 1024; - char buf[bufferSize]; - PRBool done; - int success; - mRV = NS_OK; - do { - aInputStream.read(buf, bufferSize); - done = aInputStream.eof(); - success = XML_Parse(mExpatParser, buf, aInputStream.gcount(), done); - // mRV is set in onDoneCompiling in case of an error - if (!success || NS_FAILED(mRV)) { - createErrorString(); - done = MB_TRUE; - } - } while (!done); - aInputStream.clear(); - - // clean up - XML_ParserFree(mExpatParser); - mCompiler->doneLoading(); - if (!success) { - return NS_ERROR_FAILURE; - } - return mRV; -} - -const nsAString& -txDriver::getErrorString() -{ - return mErrorString; -} - -void -txDriver::StartElement(const XML_Char *aName, const XML_Char **aAtts) -{ - PRInt32 attcount = 0; - const XML_Char** atts = aAtts; - while (*atts) { - ++atts; - ++attcount; - } - PRInt32 idOffset = XML_GetIdAttributeIndex(mExpatParser); - nsresult rv = - mCompiler->startElement(NS_STATIC_CAST(const PRUnichar*, aName), - NS_STATIC_CAST(const PRUnichar**, aAtts), - attcount/2, idOffset); - if (NS_FAILED(rv)) { - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("compile failed at %i with %x\n", - XML_GetCurrentLineNumber(mExpatParser), rv)); - mCompiler->cancel(rv); - } -} - -void -txDriver::EndElement(const XML_Char* aName) -{ - nsresult rv = mCompiler->endElement(); - if (NS_FAILED(rv)) { - mCompiler->cancel(rv); - } -} - -void -txDriver::CharacterData(const XML_Char* aChars, int aLength) -{ - const PRUnichar* pChars = NS_STATIC_CAST(const PRUnichar*, aChars); - // ignore rv, as this expat handler returns void - nsresult rv = mCompiler->characters(Substring(pChars, pChars + aLength)); - if (NS_FAILED(rv)) { - mCompiler->cancel(rv); - } -} - -int -txDriver::ExternalEntityRef(const XML_Char *aContext, const XML_Char *aBase, - const XML_Char *aSystemId, - const XML_Char *aPublicId) -{ - if (aPublicId) { - // not supported, this is "http://some.site.net/foo.dtd" stuff - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - nsAutoString absUrl; - URIUtils::resolveHref(nsDependentString((PRUnichar*)aSystemId), - nsDependentString((PRUnichar*)aBase), absUrl); - istream* extInput = URIUtils::getInputStream(absUrl, mErrorString); - if (!extInput) { - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - XML_Parser parent = mExpatParser; - mExpatParser = - XML_ExternalEntityParserCreate(mExpatParser, aContext, nsnull); - if (!mExpatParser) { - mExpatParser = parent; - delete extInput; - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - } - XML_SetBase(mExpatParser, absUrl.get()); - - const int bufSize = 1024; - char buffer[bufSize]; - int result; - PRBool done; - do { - extInput->read(buffer, bufSize); - done = extInput->eof(); - if (!(result = - XML_Parse(mExpatParser, buffer, extInput->gcount(), done))) { - createErrorString(); - mErrorString.Append(PRUnichar('\n')); - done = MB_TRUE; - } - } while (!done); - - delete extInput; - XML_ParserFree(mExpatParser); - - mExpatParser = parent; - - return result; -} - -void -txDriver::createErrorString() -{ - XML_Error errCode = XML_GetErrorCode(mExpatParser); - mErrorString.AppendWithConversion(XML_ErrorString(errCode)); - mErrorString.AppendLiteral(" at line "); - mErrorString.AppendInt(XML_GetCurrentLineNumber(mExpatParser)); - mErrorString.AppendLiteral(" in "); - mErrorString.Append((const PRUnichar*)XML_GetBase(mExpatParser)); -} - -/** - * txACompileObserver implementation - */ - -nsrefcnt -txDriver::AddRef() -{ - return ++mRefCnt; -} - -nsrefcnt -txDriver::Release() -{ - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - return 0; - } - return mRefCnt; -} - -void -txDriver::onDoneCompiling(txStylesheetCompiler* aCompiler, nsresult aResult, - const PRUnichar *aErrorText, const PRUnichar *aParam) -{ - // store the nsresult as expat forgets about it - mRV = aResult; -} - -nsresult -txDriver::loadURI(const nsAString& aUri, const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler) -{ - nsAutoString errMsg; - istream* xslInput = URIUtils::getInputStream(aUri, errMsg); - if (!xslInput) { - return NS_ERROR_FAILURE; - } - nsRefPtr driver = new txDriver(); - if (!driver) { - return NS_ERROR_OUT_OF_MEMORY; - } - driver->mCompiler = aCompiler; - return driver->parse(*xslInput, aUri); -} diff --git a/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.h b/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.h deleted file mode 100644 index d5c7bed06fad..000000000000 --- a/extensions/transformiix/source/xslt/txStandaloneStylesheetCompiler.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __TX_STANDALONE_STYLESHEET_COMPILER_H__ -#define __TX_STANDALONE_STYLESHEET_COMPILER_H__ - -#include "txStylesheet.h" -#include "txURIUtils.h" - -/** - * API to load XML files into compiled stylesheets. - * Parsing is done by expat. - */ - -/** - * Parse a stylesheet from the aPath. - */ -nsresult -TX_CompileStylesheetPath(const txParsedURL& aURL, txStylesheet** aResult); - -#endif // __TX_STANDALONE_STYLESHEET_COMPILER_H__ diff --git a/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.cpp b/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.cpp deleted file mode 100644 index fce4330673be..000000000000 --- a/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStandaloneXSLTProcessor.h" -#include "txStandaloneStylesheetCompiler.h" -#include "nsCRT.h" -#include "nsReadableUtils.h" -#include "txHTMLOutput.h" -#include "txTextOutput.h" -#include "txUnknownHandler.h" -#include "txURIUtils.h" -#include "txXMLParser.h" - -TX_IMPL_DOM_STATICS; - -/** - * Output Handler Factory - */ -class txStandaloneHandlerFactory : public txAOutputHandlerFactory -{ -public: - txStandaloneHandlerFactory(txExecutionState* aEs, - ostream* aStream) - : mEs(aEs), mStream(aStream) - { - } - - virtual ~txStandaloneHandlerFactory() - { - }; - - TX_DECL_TXAOUTPUTHANDLERFACTORY; - -private: - txExecutionState* mEs; - ostream* mStream; -}; - -nsresult -txStandaloneHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - txAOutputXMLEventHandler** aHandler) -{ - *aHandler = 0; - switch (aFormat->mMethod) { - case eXMLOutput: - *aHandler = new txXMLOutput(aFormat, mStream); - break; - - case eHTMLOutput: - *aHandler = new txHTMLOutput(aFormat, mStream); - break; - - case eTextOutput: - *aHandler = new txTextOutput(mStream); - break; - - case eMethodNotSet: - *aHandler = new txUnknownHandler(mEs); - break; - } - NS_ENSURE_TRUE(*aHandler, NS_ERROR_OUT_OF_MEMORY); - return NS_OK; -} - -nsresult -txStandaloneHandlerFactory::createHandlerWith(txOutputFormat* aFormat, - const nsAString& aName, - PRInt32 aNsID, - txAOutputXMLEventHandler** aHandler) -{ - *aHandler = 0; - NS_ASSERTION(aFormat->mMethod != eMethodNotSet, - "How can method not be known when root element is?"); - NS_ENSURE_TRUE(aFormat->mMethod != eMethodNotSet, NS_ERROR_UNEXPECTED); - return createHandlerWith(aFormat, aHandler); -} - - -/** - * txStandaloneXSLTProcessor - */ - -/** - * Transform a XML document given by path. - * The stylesheet is retrieved by a processing instruction, - * or an error is returned. - */ -nsresult -txStandaloneXSLTProcessor::transform(nsACString& aXMLPath, ostream& aOut, - ErrorObserver& aErr) -{ - txXPathNode* xmlDoc = parsePath(aXMLPath, aErr); - if (!xmlDoc) { - return NS_ERROR_FAILURE; - } - - // transform - nsresult rv = transform(*xmlDoc, aOut, aErr); - - delete xmlDoc; - - return rv; -} - -/** - * Transform a XML document given by path with the given - * stylesheet. - */ -nsresult -txStandaloneXSLTProcessor::transform(nsACString& aXMLPath, - nsACString& aXSLPath, ostream& aOut, - ErrorObserver& aErr) -{ - txXPathNode* xmlDoc = parsePath(aXMLPath, aErr); - if (!xmlDoc) { - return NS_ERROR_FAILURE; - } - txParsedURL path; - path.init(NS_ConvertASCIItoUCS2(aXSLPath)); - nsRefPtr style; - nsresult rv = TX_CompileStylesheetPath(path, getter_AddRefs(style)); - if (NS_FAILED(rv)) { - delete xmlDoc; - return rv; - } - // transform - rv = transform(*xmlDoc, style, aOut, aErr); - - delete xmlDoc; - - return rv; -} - -/** - * Transform a XML document. - * The stylesheet is retrieved by a processing instruction, - * or an error is returned. - */ -nsresult -txStandaloneXSLTProcessor::transform(txXPathNode& aXMLDoc, ostream& aOut, - ErrorObserver& aErr) -{ - Document* xmlDoc; - nsresult rv = txXPathNativeNode::getDocument(aXMLDoc, &xmlDoc); - NS_ENSURE_SUCCESS(rv, rv); - - // get stylesheet path - nsAutoString stylePath, basePath; - xmlDoc->getBaseURI(basePath); - getHrefFromStylesheetPI(*xmlDoc, stylePath); - txParsedURL base, ref, resolved; - base.init(basePath); - ref.init(stylePath); - base.resolve(ref, resolved); - - nsRefPtr style; - rv = TX_CompileStylesheetPath(resolved, getter_AddRefs(style)); - NS_ENSURE_SUCCESS(rv, rv); - - // transform - rv = transform(aXMLDoc, style, aOut, aErr); - - return rv; -} - -/** - * Processes the given XML Document using the given XSL document - * and prints the results to the given ostream argument - */ -nsresult -txStandaloneXSLTProcessor::transform(txXPathNode& aSource, - txStylesheet* aStylesheet, - ostream& aOut, ErrorObserver& aErr) -{ - // Create a new txEvalState - txExecutionState es(aStylesheet); - - // XXX todo es.addErrorObserver(aErr); - - txStandaloneHandlerFactory handlerFactory(&es, &aOut); - -#ifndef XP_WIN - bool sync = aOut.sync_with_stdio(false); -#endif - es.mOutputHandlerFactory = &handlerFactory; - - es.init(aSource, nsnull); - - // Process root of XML source document - nsresult rv = txXSLTProcessor::execute(es); - es.end(rv); - -#ifndef XP_WIN - aOut.sync_with_stdio(sync); -#endif - - return rv; -} - -/** - * Parses the XML Stylesheet PIs associated with the - * given XML document. If a stylesheet PIs is found with type="text/xsl", - * type="text/xml" or type="application/xml" the href pseudo attribute - * value will be appended to the given href argument. If multiple XSLT - * stylesheet PIs are found, the first one is used. - */ -void txStandaloneXSLTProcessor::getHrefFromStylesheetPI(Document& xmlDocument, - nsAString& href) -{ - Node* node = xmlDocument.getFirstChild(); - nsAutoString type; - nsAutoString tmpHref; - while (node) { - if (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE) { - nsAutoString target; - node->getNodeName(target); - if (target.EqualsLiteral("xml-stylesheet")) { - nsAutoString data; - node->getNodeValue(data); - type.Truncate(); - tmpHref.Truncate(); - parseStylesheetPI(data, type, tmpHref); - if (type.EqualsLiteral("text/xsl") || - type.EqualsLiteral("text/xml") || - type.EqualsLiteral("application/xml")) { - href = tmpHref; - return; - } - } - } - node = node->getNextSibling(); - } -} - -/** - * Parses the contents of data, and returns the type and href pseudo attributes - * (Based on code copied from nsParserUtils) - */ -#define SKIP_WHITESPACE(iter, end_iter) \ - while ((iter) != (end_iter) && nsCRT::IsAsciiSpace(*(iter))) { \ - ++(iter); \ - } \ - if ((iter) == (end_iter)) \ - break - -#define SKIP_ATTR_NAME(iter, end_iter) \ - while ((iter) != (end_iter) && !nsCRT::IsAsciiSpace(*(iter)) && \ - *(iter) != '=') { \ - ++(iter); \ - } \ - if ((iter) == (end_iter)) \ - break - -void txStandaloneXSLTProcessor::parseStylesheetPI(const nsAFlatString& aData, - nsAString& aType, - nsAString& aHref) -{ - nsAFlatString::const_char_iterator start, end; - aData.BeginReading(start); - aData.EndReading(end); - nsAFlatString::const_char_iterator iter; - PRInt8 found = 0; - - while (start != end) { - SKIP_WHITESPACE(start, end); - iter = start; - SKIP_ATTR_NAME(iter, end); - - // Remember the attr name. - const nsAString & attrName = Substring(start, iter); - - // Now check whether this is a valid name="value" pair. - start = iter; - SKIP_WHITESPACE(start, end); - if (*start != '=') { - // No '=', so this is not a name="value" pair. We don't know - // what it is, and we have no way to handle it. - break; - } - - // Have to skip the value. - ++start; - SKIP_WHITESPACE(start, end); - PRUnichar q = *start; - if (q != QUOTE && q != APOSTROPHE) { - // Not a valid quoted value, so bail. - break; - } - - ++start; // Point to the first char of the value. - iter = start; - while (iter != end && *iter != q) { - ++iter; - } - if (iter == end) { - // Oops, unterminated quoted string. - break; - } - - // At this point attrName holds the name of the "attribute" and - // the value is between start and iter. - if (attrName.EqualsLiteral("type")) { - aType = Substring(start, iter); - ++found; - } - else if (attrName.EqualsLiteral("href")) { - aHref = Substring(start, iter); - ++found; - } - - // Stop if we found both attributes - if (found == 2) { - break; - } - - // Resume scanning after the end of the attribute value. - start = iter; - ++start; // To move past the quote char. - } -} - -txXPathNode* -txStandaloneXSLTProcessor::parsePath(const nsACString& aPath, ErrorObserver& aErr) -{ - NS_ConvertASCIItoUCS2 path(aPath); - - ifstream xmlInput(PromiseFlatCString(aPath).get(), ios::in); - if (!xmlInput) { - aErr.receiveError(NS_LITERAL_STRING("Couldn't open ") + path); - return 0; - } - // parse source - txXPathNode* xmlDoc; - nsAutoString errors; - nsresult rv = txParseFromStream(xmlInput, path, errors, &xmlDoc); - xmlInput.close(); - if (NS_FAILED(rv) || !xmlDoc) { - aErr.receiveError(NS_LITERAL_STRING("Parsing error \"") + errors + - NS_LITERAL_STRING("\"")); - } - return xmlDoc; -} diff --git a/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.h b/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.h deleted file mode 100644 index e70baa7d941b..000000000000 --- a/extensions/transformiix/source/xslt/txStandaloneXSLTProcessor.h +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXSTANDALONEXSLTPROCESSOR_H -#define TRANSFRMX_TXSTANDALONEXSLTPROCESSOR_H - -#include "txStylesheet.h" -#include "txXSLTProcessor.h" -#include "ErrorObserver.h" - -#ifndef __BORLANDC__ -#include -#include -#endif - -class txStreamXMLEventHandler; - -/** - * txStandaloneXSLTProcessor - * - * Use of the standalone TransforMiiX API: - * - * The XSLT Processor need initialisation and shutdown - * by - * txStandaloneXSLTProcessor::Init(); - * and - * txStandaloneXSLTProcessor::Shutdown(); - * Be sure to always call these functions in pairs. - * - * The API to transform documents consists of entry points - * to transform either one or two documents. - * If you provide one document, the stylesheet location is - * computed from the processing instruction. If that cannot - * be found, an error is issued. - * - * The result is output to a stream. - * - * Documents can be provided either by path or by DOM Document. - * - * Stylesheet parameters - * XXX TODO - * - */ - -class txStandaloneXSLTProcessor : public txXSLTProcessor -{ -public: - /** - * Methods that print the result to a stream - */ - - /** - * Transform a XML document given by path. - * The stylesheet is retrieved by a processing instruction, - * or an error is returned. - * - * @param aXMLPath path to the source document - * @param aOut stream to which the result is feeded - * @param aErr error observer - * @result NS_OK if transformation was successful - */ - nsresult transform(nsACString& aXMLPath, ostream& aOut, - ErrorObserver& aErr); - - /** - * Transform a XML document given by path with the given - * stylesheet. - * - * @param aXMLPath path to the source document - * @param aXSLPath path to the style document - * @param aOut stream to which the result is feeded - * @param aErr error observer - * @result NS_OK if transformation was successful - */ - nsresult transform(nsACString& aXMLPath, nsACString& aXSLPath, - ostream& aOut, ErrorObserver& aErr); - - /** - * Transform a XML document. - * The stylesheet is retrieved by a processing instruction, - * or an error is returned. - * - * @param aXMLDoc source document - * @param aOut stream to which the result is feeded - * @param aErr error observer - * @result NS_OK if transformation was successful - */ - nsresult transform(txXPathNode& aXMLDoc, ostream& aOut, ErrorObserver& aErr); - - /** - * Transform a XML document with the given stylesheet. - * - * @param aXMLDoc source document - * @param aXSLNode style node - * @param aOut stream to which the result is feeded - * @param aErr error observer - * @result NS_OK if transformation was successful - */ - nsresult transform(txXPathNode& aXMLDoc, txStylesheet* aXSLNode, - ostream& aOut, ErrorObserver& aErr); - -protected: - /** - * Parses all XML Stylesheet PIs associated with the - * given XML document. If any stylesheet PIs are found with - * type="text/xsl" the href pseudo attribute value will be - * added to the given href argument. If multiple text/xsl stylesheet PIs - * are found, the one closest to the end of the document is used. - */ - static void getHrefFromStylesheetPI(Document& xmlDocument, nsAString& href); - - /** - * Parses the contents of data, returns the type and href pseudo attributes - */ - static void parseStylesheetPI(const nsAFlatString& data, - nsAString& type, - nsAString& href); - - /** - * Create a Document from a path. - * - * @param aPath path to the xml file - * @param aErr ErrorObserver - * @result Document XML Document, or null on error - */ - static txXPathNode* parsePath(const nsACString& aPath, ErrorObserver& aErr); -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txStylesheet.cpp b/extensions/transformiix/source/xslt/txStylesheet.cpp deleted file mode 100644 index 94401df7286d..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheet.cpp +++ /dev/null @@ -1,668 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStylesheet.h" -#include "Expr.h" -#include "txXSLTPatterns.h" -#include "txToplevelItems.h" -#include "txInstructions.h" -#include "XSLTFunctions.h" -#include "TxLog.h" -#include "txKey.h" - -txStylesheet::txStylesheet() - : mRootFrame(nsnull), - mNamedTemplates(PR_FALSE), - mDecimalFormats(PR_TRUE), - mAttributeSets(PR_FALSE), - mGlobalVariables(PR_TRUE), - mKeys(PR_TRUE) -{ -} - -nsresult -txStylesheet::init() -{ - mRootFrame = new ImportFrame; - NS_ENSURE_TRUE(mRootFrame, NS_ERROR_OUT_OF_MEMORY); - - // Create default templates - // element/root template - mContainerTemplate = new txPushParams; - NS_ENSURE_TRUE(mContainerTemplate, NS_ERROR_OUT_OF_MEMORY); - - nsAutoPtr nt(new txNodeTypeTest(txNodeTypeTest::NODE_TYPE)); - NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY); - - nsAutoPtr nodeExpr(new LocationStep(nt, LocationStep::CHILD_AXIS)); - NS_ENSURE_TRUE(nodeExpr, NS_ERROR_OUT_OF_MEMORY); - - txPushNewContext* pushContext = new txPushNewContext(nodeExpr); - mContainerTemplate->mNext = pushContext; - NS_ENSURE_TRUE(pushContext, NS_ERROR_OUT_OF_MEMORY); - - txApplyDefaultElementTemplate* applyTemplates = - new txApplyDefaultElementTemplate; - pushContext->mNext = applyTemplates; - NS_ENSURE_TRUE(applyTemplates, NS_ERROR_OUT_OF_MEMORY); - - txLoopNodeSet* loopNodeSet = new txLoopNodeSet(applyTemplates); - applyTemplates->mNext = loopNodeSet; - NS_ENSURE_TRUE(loopNodeSet, NS_ERROR_OUT_OF_MEMORY); - - txPopParams* popParams = new txPopParams; - pushContext->mBailTarget = loopNodeSet->mNext = popParams; - NS_ENSURE_TRUE(popParams, NS_ERROR_OUT_OF_MEMORY); - - popParams->mNext = new txReturn(); - NS_ENSURE_TRUE(popParams->mNext, NS_ERROR_OUT_OF_MEMORY); - - // attribute/textnode template - nt = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE); - NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY); - - nodeExpr = new LocationStep(nt, LocationStep::SELF_AXIS); - NS_ENSURE_TRUE(nodeExpr, NS_ERROR_OUT_OF_MEMORY); - - mCharactersTemplate = new txValueOf(nodeExpr, PR_FALSE); - NS_ENSURE_TRUE(mCharactersTemplate, NS_ERROR_OUT_OF_MEMORY); - - mCharactersTemplate->mNext = new txReturn(); - NS_ENSURE_TRUE(mCharactersTemplate->mNext, NS_ERROR_OUT_OF_MEMORY); - - // pi/comment/namespace template - mEmptyTemplate = new txReturn(); - NS_ENSURE_TRUE(mEmptyTemplate, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; -} - -txStylesheet::~txStylesheet() -{ - // Delete all ImportFrames - delete mRootFrame; - txListIterator frameIter(&mImportFrames); - while (frameIter.hasNext()) { - delete NS_STATIC_CAST(ImportFrame*, frameIter.next()); - } - - txListIterator instrIter(&mTemplateInstructions); - while (instrIter.hasNext()) { - delete NS_STATIC_CAST(txInstruction*, instrIter.next()); - } - - // We can't make the map own its values because then we wouldn't be able - // to merge attributesets of the same name - txExpandedNameMap::iterator attrSetIter(mAttributeSets); - while (attrSetIter.next()) { - delete attrSetIter.value(); - } -} - -txInstruction* -txStylesheet::findTemplate(const txXPathNode& aNode, - const txExpandedName& aMode, - txIMatchContext* aContext, - ImportFrame* aImportedBy, - ImportFrame** aImportFrame) -{ - NS_ASSERTION(aImportFrame, "missing ImportFrame pointer"); - - *aImportFrame = nsnull; - txInstruction* matchTemplate = nsnull; - ImportFrame* endFrame = nsnull; - txListIterator frameIter(&mImportFrames); - - if (aImportedBy) { - ImportFrame* curr = NS_STATIC_CAST(ImportFrame*, frameIter.next()); - while (curr != aImportedBy) { - curr = NS_STATIC_CAST(ImportFrame*, frameIter.next()); - } - endFrame = aImportedBy->mFirstNotImported; - } - -#ifdef PR_LOGGING - txPattern* match = 0; -#endif - - ImportFrame* frame; - while (!matchTemplate && - (frame = NS_STATIC_CAST(ImportFrame*, frameIter.next())) && - frame != endFrame) { - - // get templatelist for this mode - txList* templates = - NS_STATIC_CAST(txList*, frame->mMatchableTemplates.get(aMode)); - - if (templates) { - txListIterator templateIter(templates); - - // Find template with highest priority - MatchableTemplate* templ; - while (!matchTemplate && - (templ = - NS_STATIC_CAST(MatchableTemplate*, templateIter.next()))) { - if (templ->mMatch->matches(aNode, aContext)) { - matchTemplate = templ->mFirstInstruction; - *aImportFrame = frame; -#ifdef PR_LOGGING - match = templ->mMatch; -#endif - } - } - } - } - -#ifdef PR_LOGGING - nsAutoString mode, nodeName; - if (aMode.mLocalName) { - aMode.mLocalName->ToString(mode); - } - txXPathNodeUtils::getNodeName(aNode, nodeName); - if (matchTemplate) { - nsAutoString matchAttr; -#ifdef TX_TO_STRING - match->toString(matchAttr); -#endif - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("MatchTemplate, Pattern %s, Mode %s, Node %s\n", - NS_LossyConvertUCS2toASCII(matchAttr).get(), - NS_LossyConvertUCS2toASCII(mode).get(), - NS_LossyConvertUCS2toASCII(nodeName).get())); - } - else { - PR_LOG(txLog::xslt, PR_LOG_DEBUG, - ("No match, Node %s, Mode %s\n", - NS_LossyConvertUCS2toASCII(nodeName).get(), - NS_LossyConvertUCS2toASCII(mode).get())); - } -#endif - - if (!matchTemplate) { - if (txXPathNodeUtils::isElement(aNode) || - txXPathNodeUtils::isRoot(aNode)) { - matchTemplate = mContainerTemplate; - } - else if (txXPathNodeUtils::isAttribute(aNode) || - txXPathNodeUtils::isText(aNode)) { - matchTemplate = mCharactersTemplate; - } - else { - matchTemplate = mEmptyTemplate; - } - } - - return matchTemplate; -} - -txDecimalFormat* -txStylesheet::getDecimalFormat(const txExpandedName& aName) -{ - return NS_STATIC_CAST(txDecimalFormat*, mDecimalFormats.get(aName)); -} - -txInstruction* -txStylesheet::getAttributeSet(const txExpandedName& aName) -{ - return NS_STATIC_CAST(txInstruction*, mAttributeSets.get(aName)); -} - -txInstruction* -txStylesheet::getNamedTemplate(const txExpandedName& aName) -{ - return NS_STATIC_CAST(txInstruction*, mNamedTemplates.get(aName)); -} - -txOutputFormat* -txStylesheet::getOutputFormat() -{ - return &mOutputFormat; -} - -txStylesheet::GlobalVariable* -txStylesheet::getGlobalVariable(const txExpandedName& aName) -{ - return NS_STATIC_CAST(GlobalVariable*, mGlobalVariables.get(aName)); -} - -const txExpandedNameMap& -txStylesheet::getKeyMap() -{ - return mKeys; -} - -PRBool -txStylesheet::isStripSpaceAllowed(const txXPathNode& aNode, txIMatchContext* aContext) -{ - PRInt32 frameCount = mStripSpaceTests.Count(); - if (frameCount == 0) { - return PR_FALSE; - } - - txXPathTreeWalker walker(aNode); - - if (txXPathNodeUtils::isText(walker.getCurrentPosition()) && - (!txXPathNodeUtils::isWhitespace(aNode) || !walker.moveToParent())) { - return PR_FALSE; - } - - const txXPathNode& node = walker.getCurrentPosition(); - - if (!txXPathNodeUtils::isElement(node)) { - return PR_FALSE; - } - - // check Whitespace stipping handling list against given Node - PRInt32 i; - for (i = 0; i < frameCount; ++i) { - txStripSpaceTest* sst = - NS_STATIC_CAST(txStripSpaceTest*, mStripSpaceTests[i]); - if (sst->matches(node, aContext)) { - return sst->stripsSpace() && !XMLUtils::getXMLSpacePreserve(node); - } - } - - return PR_FALSE; -} - -nsresult -txStylesheet::doneCompiling() -{ - nsresult rv = NS_OK; - // Collect all importframes into a single ordered list - txListIterator frameIter(&mImportFrames); - rv = frameIter.addAfter(mRootFrame); - NS_ENSURE_SUCCESS(rv, rv); - - mRootFrame = nsnull; - frameIter.next(); - rv = addFrames(frameIter); - NS_ENSURE_SUCCESS(rv, rv); - - // Loop through importframes in decreasing-precedence-order and process - // all items - frameIter.reset(); - ImportFrame* frame; - while ((frame = NS_STATIC_CAST(ImportFrame*, frameIter.next()))) { - nsVoidArray frameStripSpaceTests; - - txListIterator itemIter(&frame->mToplevelItems); - itemIter.resetToEnd(); - txToplevelItem* item; - while ((item = NS_STATIC_CAST(txToplevelItem*, itemIter.previous()))) { - switch (item->getType()) { - case txToplevelItem::attributeSet: - { - rv = addAttributeSet(NS_STATIC_CAST(txAttributeSetItem*, - item)); - NS_ENSURE_SUCCESS(rv, rv); - break; - } - case txToplevelItem::dummy: - case txToplevelItem::import: - { - break; - } - case txToplevelItem::output: - { - mOutputFormat.merge(NS_STATIC_CAST(txOutputItem*, item)->mFormat); - break; - } - case txToplevelItem::stripSpace: - { - rv = addStripSpace(NS_STATIC_CAST(txStripSpaceItem*, item), - frameStripSpaceTests); - NS_ENSURE_SUCCESS(rv, rv); - break; - } - case txToplevelItem::templ: - { - rv = addTemplate(NS_STATIC_CAST(txTemplateItem*, item), - frame); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - case txToplevelItem::variable: - { - rv = addGlobalVariable(NS_STATIC_CAST(txVariableItem*, - item)); - NS_ENSURE_SUCCESS(rv, rv); - - break; - } - } - delete item; - itemIter.remove(); //remove() moves to the previous - itemIter.next(); - } - if (!mStripSpaceTests.AppendElements(frameStripSpaceTests)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - frameStripSpaceTests.Clear(); - } - - if (!mDecimalFormats.get(txExpandedName())) { - nsAutoPtr format(new txDecimalFormat); - NS_ENSURE_TRUE(format, NS_ERROR_OUT_OF_MEMORY); - - rv = mDecimalFormats.add(txExpandedName(), format); - NS_ENSURE_SUCCESS(rv, rv); - - format.forget(); - } - - return NS_OK; -} - -nsresult -txStylesheet::addTemplate(txTemplateItem* aTemplate, - ImportFrame* aImportFrame) -{ - NS_ASSERTION(aTemplate, "missing template"); - - txInstruction* instr = aTemplate->mFirstInstruction; - nsresult rv = mTemplateInstructions.add(instr); - NS_ENSURE_SUCCESS(rv, rv); - - // mTemplateInstructions now owns the instructions - aTemplate->mFirstInstruction.forget(); - - if (!aTemplate->mName.isNull()) { - rv = mNamedTemplates.add(aTemplate->mName, instr); - NS_ENSURE_TRUE(NS_SUCCEEDED(rv) || rv == NS_ERROR_XSLT_ALREADY_SET, - rv); - } - - if (!aTemplate->mMatch) { - // This is no error, see section 6 Named Templates - - return NS_OK; - } - - // get the txList for the right mode - txList* templates = - NS_STATIC_CAST(txList*, - aImportFrame->mMatchableTemplates.get(aTemplate->mMode)); - - if (!templates) { - nsAutoPtr newList(new txList); - NS_ENSURE_TRUE(newList, NS_ERROR_OUT_OF_MEMORY); - - rv = aImportFrame->mMatchableTemplates.add(aTemplate->mMode, newList); - NS_ENSURE_SUCCESS(rv, rv); - - templates = newList.forget(); - } - - // Add the simple patterns to the list of matchable templates, according - // to default priority - txList simpleMatches; - rv = aTemplate->mMatch->getSimplePatterns(simpleMatches); - if (simpleMatches.get(0) == aTemplate->mMatch) { - aTemplate->mMatch.forget(); - } - - txListIterator simples(&simpleMatches); - while (simples.hasNext()) { - // XXX if we fail in this loop, we leak the remaining simple patterns - nsAutoPtr simple(NS_STATIC_CAST(txPattern*, simples.next())); - double priority = aTemplate->mPrio; - if (Double::isNaN(priority)) { - priority = simple->getDefaultPriority(); - NS_ASSERTION(!Double::isNaN(priority), - "simple pattern without default priority"); - } - nsAutoPtr - nt(new MatchableTemplate(instr, simple, priority)); - NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY); - - txListIterator templ(templates); - while (templ.hasNext()) { - MatchableTemplate* mt = NS_STATIC_CAST(MatchableTemplate*, - templ.next()); - if (priority > mt->mPriority) { - rv = templ.addBefore(nt); - NS_ENSURE_SUCCESS(rv, rv); - - nt.forget(); - break; - } - } - if (nt) { - rv = templates->add(nt); - NS_ENSURE_SUCCESS(rv, rv); - - nt.forget(); - } - } - - return NS_OK; -} - -nsresult -txStylesheet::addFrames(txListIterator& aInsertIter) -{ - ImportFrame* frame = NS_STATIC_CAST(ImportFrame*, aInsertIter.current()); - nsresult rv = NS_OK; - txListIterator iter(&frame->mToplevelItems); - txToplevelItem* item; - while ((item = NS_STATIC_CAST(txToplevelItem*, iter.next()))) { - if (item->getType() == txToplevelItem::import) { - txImportItem* import = NS_STATIC_CAST(txImportItem*, item); - import->mFrame->mFirstNotImported = - NS_STATIC_CAST(ImportFrame*, aInsertIter.next()); - rv = aInsertIter.addBefore(import->mFrame); - NS_ENSURE_SUCCESS(rv, rv); - - import->mFrame.forget(); - aInsertIter.previous(); - rv = addFrames(aInsertIter); - NS_ENSURE_SUCCESS(rv, rv); - aInsertIter.previous(); - } - } - - return NS_OK; -} - -nsresult -txStylesheet::addStripSpace(txStripSpaceItem* aStripSpaceItem, - nsVoidArray& frameStripSpaceTests) -{ - PRInt32 testCount = aStripSpaceItem->mStripSpaceTests.Count(); - for (; testCount > 0; --testCount) { - txStripSpaceTest* sst = - NS_STATIC_CAST(txStripSpaceTest*, - aStripSpaceItem->mStripSpaceTests[testCount-1]); - double priority = sst->getDefaultPriority(); - PRInt32 i, frameCount = frameStripSpaceTests.Count(); - for (i = 0; i < frameCount; ++i) { - txStripSpaceTest* fsst = - NS_STATIC_CAST(txStripSpaceTest*, frameStripSpaceTests[i]); - if (fsst->getDefaultPriority() < priority) { - break; - } - } - if (!frameStripSpaceTests.InsertElementAt(sst, i)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - aStripSpaceItem->mStripSpaceTests.RemoveElementAt(testCount-1); - } - - return NS_OK; -} - -nsresult -txStylesheet::addAttributeSet(txAttributeSetItem* aAttributeSetItem) -{ - nsresult rv = NS_OK; - txInstruction* oldInstr = - NS_STATIC_CAST(txInstruction*, - mAttributeSets.get(aAttributeSetItem->mName)); - if (!oldInstr) { - rv = mAttributeSets.add(aAttributeSetItem->mName, - aAttributeSetItem->mFirstInstruction); - NS_ENSURE_SUCCESS(rv, rv); - - aAttributeSetItem->mFirstInstruction.forget(); - - return NS_OK; - } - - // We need to prepend the new instructions before the existing ones. - txInstruction* instr = aAttributeSetItem->mFirstInstruction; - txInstruction* lastNonReturn = nsnull; - while (instr->mNext) { - lastNonReturn = instr; - instr = instr->mNext; - } - - if (!lastNonReturn) { - // The new attributeset is empty, so lets just ignore it. - return NS_OK; - } - - rv = mAttributeSets.set(aAttributeSetItem->mName, - aAttributeSetItem->mFirstInstruction); - NS_ENSURE_SUCCESS(rv, rv); - - aAttributeSetItem->mFirstInstruction.forget(); - - delete lastNonReturn->mNext; // Delete the txReturn... - lastNonReturn->mNext = oldInstr; // ...and link up the old instructions. - - return NS_OK; -} - -nsresult -txStylesheet::addGlobalVariable(txVariableItem* aVariable) -{ - if (mGlobalVariables.get(aVariable->mName)) { - return NS_OK; - } - nsAutoPtr var( - new GlobalVariable(aVariable->mValue, aVariable->mFirstInstruction, - aVariable->mIsParam)); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = mGlobalVariables.add(aVariable->mName, var); - NS_ENSURE_SUCCESS(rv, rv); - - var.forget(); - - return NS_OK; - -} - -nsresult -txStylesheet::addKey(const txExpandedName& aName, - nsAutoPtr aMatch, nsAutoPtr aUse) -{ - nsresult rv = NS_OK; - - txXSLKey* xslKey = NS_STATIC_CAST(txXSLKey*, mKeys.get(aName)); - if (!xslKey) { - xslKey = new txXSLKey(aName); - NS_ENSURE_TRUE(xslKey, NS_ERROR_OUT_OF_MEMORY); - - rv = mKeys.add(aName, xslKey); - if (NS_FAILED(rv)) { - delete xslKey; - return rv; - } - } - if (!xslKey->addKey(aMatch, aUse)) { - return NS_ERROR_OUT_OF_MEMORY; - } - return NS_OK; -} - -nsresult -txStylesheet::addDecimalFormat(const txExpandedName& aName, - nsAutoPtr aFormat) -{ - txDecimalFormat* existing = - NS_STATIC_CAST(txDecimalFormat*, mDecimalFormats.get(aName)); - if (existing) { - NS_ENSURE_TRUE(existing->isEqual(aFormat), - NS_ERROR_XSLT_PARSE_FAILURE); - - return NS_OK; - } - - nsresult rv = mDecimalFormats.add(aName, aFormat); - NS_ENSURE_SUCCESS(rv, rv); - - aFormat.forget(); - - return NS_OK; -} - -txStylesheet::ImportFrame::ImportFrame() - : mMatchableTemplates(MB_TRUE), - mFirstNotImported(nsnull) -{ -} - -txStylesheet::ImportFrame::~ImportFrame() -{ - // Delete templates in mMatchableTemplates - txExpandedNameMap::iterator mapIter(mMatchableTemplates); - while (mapIter.next()) { - txListIterator templIter(NS_STATIC_CAST(txList*, mapIter.value())); - MatchableTemplate* templ; - while ((templ = NS_STATIC_CAST(MatchableTemplate*, templIter.next()))) { - delete templ; - } - } - - txListIterator tlIter(&mToplevelItems); - while (tlIter.hasNext()) { - delete NS_STATIC_CAST(txToplevelItem*, tlIter.next()); - } -} - -txStylesheet::GlobalVariable::GlobalVariable(nsAutoPtr aExpr, - nsAutoPtr aFirstInstruction, - PRBool aIsParam) - : mExpr(aExpr), mFirstInstruction(aFirstInstruction), mIsParam(aIsParam) -{ -} diff --git a/extensions/transformiix/source/xslt/txStylesheet.h b/extensions/transformiix/source/xslt/txStylesheet.h deleted file mode 100644 index b790cc09555c..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheet.h +++ /dev/null @@ -1,248 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TX_TXSTYLESHEET_H -#define TX_TXSTYLESHEET_H - -#include "txOutputFormat.h" -#include "txExpandedNameMap.h" -#include "List.h" -#include "txXSLTPatterns.h" -#include "XSLTFunctions.h" -#include "nsVoidArray.h" - -class txInstruction; -class txToplevelItem; -class txTemplateItem; -class txVariableItem; -class txStripSpaceItem; -class txAttributeSetItem; - -class txStylesheet -{ -public: - class ImportFrame; - class GlobalVariable; - friend class txStylesheetCompilerState; - // To be able to do some cleaning up in destructor - friend class ImportFrame; - - txStylesheet(); - ~txStylesheet(); - nsresult init(); - - nsrefcnt AddRef() - { - return ++mRefCnt; - } - nsrefcnt Release() - { - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - return 0; - } - return mRefCnt; - } - - txInstruction* findTemplate(const txXPathNode& aNode, - const txExpandedName& aMode, - txIMatchContext* aContext, - ImportFrame* aImportedBy, - ImportFrame** aImportFrame); - txDecimalFormat* getDecimalFormat(const txExpandedName& aName); - txInstruction* getAttributeSet(const txExpandedName& aName); - txInstruction* getNamedTemplate(const txExpandedName& aName); - txOutputFormat* getOutputFormat(); - GlobalVariable* getGlobalVariable(const txExpandedName& aName); - const txExpandedNameMap& getKeyMap(); - PRBool isStripSpaceAllowed(const txXPathNode& aNode, - txIMatchContext* aContext); - - /** - * Called by the stylesheet compiler once all stylesheets has been read. - */ - nsresult doneCompiling(); - - /** - * Add a key to the stylesheet - */ - nsresult addKey(const txExpandedName& aName, nsAutoPtr aMatch, - nsAutoPtr aUse); - - /** - * Add a decimal-format to the stylesheet - */ - nsresult addDecimalFormat(const txExpandedName& aName, - nsAutoPtr aFormat); - - /** - * Contain information that is import precedence dependant. - */ - class ImportFrame { - public: - ImportFrame(); - ~ImportFrame(); - - // List of toplevel items - txList mToplevelItems; - - // Map of template modes, each item in the map is a txList - // of templates - txExpandedNameMap mMatchableTemplates; - - // ImportFrame which is the first one *not* imported by this frame - ImportFrame* mFirstNotImported; - }; - - class GlobalVariable : public TxObject { - public: - GlobalVariable(nsAutoPtr aExpr, - nsAutoPtr aFirstInstruction, - PRBool aIsParam); - - nsAutoPtr mExpr; - nsAutoPtr mFirstInstruction; - PRBool mIsParam; - }; - -private: - class MatchableTemplate { - public: - MatchableTemplate(txInstruction* aFirstInstruction, - nsAutoPtr aPattern, - double aPriority) - : mFirstInstruction(aFirstInstruction), - mMatch(aPattern), - mPriority(aPriority) - { - } - txInstruction* mFirstInstruction; - nsAutoPtr mMatch; - double mPriority; - }; - - nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame); - nsresult addGlobalVariable(txVariableItem* aVariable); - nsresult addFrames(txListIterator& aInsertIter); - nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem, - nsVoidArray& frameStripSpaceTests); - nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem); - - // Refcount - nsAutoRefCnt mRefCnt; - - // List of ImportFrames - txList mImportFrames; - - // output format - txOutputFormat mOutputFormat; - - // List of first instructions of templates. This is the owner of all - // instructions used in templates - txList mTemplateInstructions; - - // Root importframe - ImportFrame* mRootFrame; - - // Named templates - txExpandedNameMap mNamedTemplates; - - // Map with all decimal-formats - txExpandedNameMap mDecimalFormats; - - // Map with all named attribute sets - txExpandedNameMap mAttributeSets; - - // Map with all global variables and parameters - txExpandedNameMap mGlobalVariables; - - // Map with all keys - txExpandedNameMap mKeys; - - // Array of all txStripSpaceTests, sorted in acending order - nsVoidArray mStripSpaceTests; - - // Default templates - nsAutoPtr mContainerTemplate; - nsAutoPtr mCharactersTemplate; - nsAutoPtr mEmptyTemplate; -}; - - -/** - * txStripSpaceTest holds both an txNameTest and a bool for use in - * whitespace stripping. - */ -class txStripSpaceTest { -public: - txStripSpaceTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID, - MBool stripSpace) - : mNameTest(aPrefix, aLocalName, aNSID, txXPathNodeType::ELEMENT_NODE), - mStrips(stripSpace) - { - } - - MBool matches(const txXPathNode& aNode, txIMatchContext* aContext) { - return mNameTest.matches(aNode, aContext); - } - - MBool stripsSpace() { - return mStrips; - } - - double getDefaultPriority() { - return mNameTest.getDefaultPriority(); - } - -protected: - txNameTest mNameTest; - MBool mStrips; -}; - -/** - * Value of a global parameter - */ -class txIGlobalParameter : public TxObject -{ -public: - virtual nsresult getValue(txAExprResult** aValue) = 0; -}; - - -#endif //TX_TXSTYLESHEET_H diff --git a/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.cpp b/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.cpp deleted file mode 100644 index 0b251ee84b48..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.cpp +++ /dev/null @@ -1,2983 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStylesheetCompiler.h" -#include "txStylesheetCompileHandlers.h" -#include "txTokenizer.h" -#include "txInstructions.h" -#include "txAtoms.h" -#include "txCore.h" -#include "txStringUtils.h" -#include "txStylesheet.h" -#include "txToplevelItems.h" -#include "txPatternParser.h" -#include "txNamespaceMap.h" -#include "txURIUtils.h" -#include "XSLTFunctions.h" - -txHandlerTable* gTxIgnoreHandler = 0; -txHandlerTable* gTxRootHandler = 0; -txHandlerTable* gTxEmbedHandler = 0; -txHandlerTable* gTxTopHandler = 0; -txHandlerTable* gTxTemplateHandler = 0; -txHandlerTable* gTxTextHandler = 0; -txHandlerTable* gTxApplyTemplatesHandler = 0; -txHandlerTable* gTxCallTemplateHandler = 0; -txHandlerTable* gTxVariableHandler = 0; -txHandlerTable* gTxForEachHandler = 0; -txHandlerTable* gTxTopVariableHandler = 0; -txHandlerTable* gTxChooseHandler = 0; -txHandlerTable* gTxParamHandler = 0; -txHandlerTable* gTxImportHandler = 0; -txHandlerTable* gTxAttributeSetHandler = 0; -txHandlerTable* gTxFallbackHandler = 0; - -nsresult -txFnStartLRE(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState); -nsresult -txFnEndLRE(txStylesheetCompilerState& aState); - - -#define TX_RETURN_IF_WHITESPACE(_str, _state) \ - do { \ - if (!_state.mElementContext->mPreserveWhitespace && \ - XMLUtils::isWhitespace(PromiseFlatString(_str))) { \ - return NS_OK; \ - } \ - } while(0) - - -nsresult -getStyleAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - PRInt32 aNamespace, - nsIAtom* aName, - PRBool aRequired, - txStylesheetAttr** aAttr) -{ - PRInt32 i; - for (i = 0; i < aAttrCount; ++i) { - txStylesheetAttr* attr = aAttributes + i; - if (attr->mNamespaceID == aNamespace && - attr->mLocalName == aName) { - *aAttr = attr; - - return NS_OK; - } - } - *aAttr = nsnull; - - if (aRequired) { - // XXX ErrorReport: missing required attribute - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - return NS_OK; -} - -nsresult -parseUseAttrSets(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - PRBool aInXSLTNS, - txStylesheetCompilerState& aState) -{ - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, - aInXSLTNS ? kNameSpaceID_XSLT - : kNameSpaceID_None, - txXSLTAtoms::useAttributeSets, PR_FALSE, - &attr); - if (!attr) { - return rv; - } - - txTokenizer tok(attr->mValue); - while (tok.hasMoreTokens()) { - txExpandedName name; - rv = name.init(tok.nextToken(), aState.mElementContext->mMappings, - PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(new txInsertAttrSet(name)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; -} - -nsresult -getQNameAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - txExpandedName& aExpName) -{ - aExpName.reset(); - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - rv = aExpName.init(attr->mValue, aState.mElementContext->mMappings, - PR_FALSE); - if (!aRequired && NS_FAILED(rv) && aState.fcp()) { - aExpName.reset(); - rv = NS_OK; - } - - return rv; -} - -nsresult -getExprAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - nsAutoPtr& aExpr) -{ - aExpr = nsnull; - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - rv = txExprParser::createExpr(attr->mValue, &aState, - getter_Transfers(aExpr)); - if (NS_FAILED(rv) && aState.fcp()) { - // use default value in fcp for not required exprs - if (aRequired) { - aExpr = new txErrorExpr( -#ifdef TX_TO_STRING - attr->mValue -#endif - ); - NS_ENSURE_TRUE(aExpr, NS_ERROR_OUT_OF_MEMORY); - } - else { - aExpr = nsnull; - } - return NS_OK; - } - - return rv; -} - -nsresult -getAVTAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - nsAutoPtr& aAVT) -{ - aAVT = nsnull; - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - aAVT = txExprParser::createAttributeValueTemplate(attr->mValue, &aState); - if (!aAVT) { - if (!aState.fcp()) { - // XXX ErrorReport: XPath parse failure - return NS_ERROR_XPATH_PARSE_FAILURE; - } - - if (aRequired) { - aAVT = new txErrorExpr( -#ifdef TX_TO_STRING - attr->mValue -#endif - ); - NS_ENSURE_TRUE(aAVT, NS_ERROR_OUT_OF_MEMORY); - } - } - - return NS_OK; -} - -nsresult -getPatternAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - nsAutoPtr& aPattern) -{ - aPattern = nsnull; - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - aPattern = txPatternParser::createPattern(attr->mValue, &aState); - if (!aPattern && (aRequired || !aState.fcp())) { - // XXX ErrorReport: XSLT-Pattern parse failure - return NS_ERROR_XPATH_PARSE_FAILURE; - } - - return NS_OK; -} - -nsresult -getNumberAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - double& aNumber) -{ - aNumber = Double::NaN; - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - aNumber = Double::toDouble(attr->mValue); - if (Double::isNaN(aNumber) && (aRequired || !aState.fcp())) { - // XXX ErrorReport: number parse failure - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - return NS_OK; -} - -nsresult -getAtomAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - nsIAtom** aAtom) -{ - *aAtom = nsnull; - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - *aAtom = NS_NewAtom(attr->mValue); - NS_ENSURE_TRUE(*aAtom, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; -} - -nsresult -getYesNoAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - txThreeState& aRes) -{ - aRes = eNotSet; - nsCOMPtr atom; - nsresult rv = getAtomAttr(aAttributes, aAttrCount, aName, aRequired, - aState, getter_AddRefs(atom)); - if (!atom) { - return rv; - } - - if (atom == txXSLTAtoms::yes) { - aRes = eTrue; - } - else if (atom == txXSLTAtoms::no) { - aRes = eFalse; - } - else if (aRequired || !aState.fcp()) { - // XXX ErrorReport: unknown values - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - return NS_OK; -} - -nsresult -getCharAttr(txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - nsIAtom* aName, - PRBool aRequired, - txStylesheetCompilerState& aState, - PRUnichar& aChar) -{ - // Don't reset aChar since it contains the default value - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - aName, aRequired, &attr); - if (!attr) { - return rv; - } - - if (attr->mValue.Length() == 1) { - aChar = attr->mValue.CharAt(0); - } - else if (aRequired || !aState.fcp()) { - // XXX ErrorReport: not a character - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - return NS_OK; -} - - -/** - * Ignore and error handlers - */ -nsresult -txFnTextIgnore(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - return NS_OK; -} - -nsresult -txFnTextError(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - TX_RETURN_IF_WHITESPACE(aStr, aState); - - return NS_ERROR_XSLT_PARSE_FAILURE; -} - -nsresult -txFnStartElementIgnore(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - return NS_OK; -} - -nsresult -txFnEndElementIgnore(txStylesheetCompilerState& aState) -{ - return NS_OK; -} - -nsresult -txFnStartElementSetIgnore(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndElementSetIgnore(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - return NS_OK; -} - -nsresult -txFnStartElementError(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - return NS_ERROR_XSLT_PARSE_FAILURE; -} - -nsresult -txFnEndElementError(txStylesheetCompilerState& aState) -{ - NS_ERROR("txFnEndElementError shouldn't be called"); - return NS_ERROR_XSLT_PARSE_FAILURE; -} - - -/** - * Root handlers - */ -nsresult -txFnStartStylesheet(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - txStylesheetAttr* attr; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::version, PR_TRUE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxImportHandler); -} - -nsresult -txFnEndStylesheet(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - return NS_OK; -} - -nsresult -txFnStartElementContinueTopLevel(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - aState.mHandlerTable = gTxTopHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -nsresult -txFnStartLREStylesheet(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - txStylesheetAttr* attr; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_XSLT, - txXSLTAtoms::version, PR_TRUE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - txExpandedName nullExpr; - double prio = Double::NaN; - - nsAutoPtr match(new txRootPattern()); - NS_ENSURE_TRUE(match, NS_ERROR_OUT_OF_MEMORY); - - nsAutoPtr templ(new txTemplateItem(match, nullExpr, - nullExpr, prio)); - NS_ENSURE_TRUE(templ, NS_ERROR_OUT_OF_MEMORY); - - aState.openInstructionContainer(templ); - rv = aState.addToplevelItem(templ); - NS_ENSURE_SUCCESS(rv, rv); - - templ.forget(); - - rv = aState.pushHandlerTable(gTxTemplateHandler); - NS_ENSURE_SUCCESS(rv, rv); - - return txFnStartLRE(aNamespaceID, aLocalName, aPrefix, aAttributes, - aAttrCount, aState); -} - -nsresult -txFnEndLREStylesheet(txStylesheetCompilerState& aState) -{ - nsresult rv = txFnEndLRE(aState); - NS_ENSURE_SUCCESS(rv, rv); - - aState.popHandlerTable(); - - nsAutoPtr instr(new txReturn()); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.closeInstructionContainer(); - - return NS_OK; -} - -nsresult -txFnStartEmbed(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - if (!aState.handleEmbeddedSheet()) { - return NS_OK; - } - if (aNamespaceID != kNameSpaceID_XSLT || - (aLocalName != txXSLTAtoms::stylesheet && - aLocalName != txXSLTAtoms::transform)) { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - return txFnStartStylesheet(aNamespaceID, aLocalName, aPrefix, - aAttributes, aAttrCount, aState); -} - -nsresult -txFnEndEmbed(txStylesheetCompilerState& aState) -{ - if (!aState.handleEmbeddedSheet()) { - return NS_OK; - } - nsresult rv = txFnEndStylesheet(aState); - aState.doneEmbedding(); - return rv; -} - - -/** - * Top handlers - */ -nsresult -txFnStartOtherTop(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - if (aNamespaceID == kNameSpaceID_None) { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndOtherTop(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - return NS_OK; -} - - -// xsl:attribute-set -nsresult -txFnStartAttributeSet(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr attrSet(new txAttributeSetItem(name)); - NS_ENSURE_TRUE(attrSet, NS_ERROR_OUT_OF_MEMORY); - - aState.openInstructionContainer(attrSet); - - rv = aState.addToplevelItem(attrSet); - NS_ENSURE_SUCCESS(rv, rv); - - attrSet.forget(); - - rv = parseUseAttrSets(aAttributes, aAttrCount, PR_FALSE, aState); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxAttributeSetHandler); -} - -nsresult -txFnEndAttributeSet(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - nsAutoPtr instr(new txReturn()); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.closeInstructionContainer(); - - return NS_OK; -} - - -// xsl:decimal-format -nsresult -txFnStartDecimalFormat(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_FALSE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr format(new txDecimalFormat); - NS_ENSURE_TRUE(format, NS_ERROR_OUT_OF_MEMORY); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::decimalSeparator, - PR_FALSE, aState, format->mDecimalSeparator); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::groupingSeparator, - PR_FALSE, aState, format->mGroupingSeparator); - NS_ENSURE_SUCCESS(rv, rv); - - txStylesheetAttr* attr = nsnull; - rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::infinity, PR_FALSE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - if (attr) { - format->mInfinity = attr->mValue; - } - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::minusSign, - PR_FALSE, aState, format->mMinusSign); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::NaN, PR_FALSE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - if (attr) { - format->mNaN = attr->mValue; - } - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::percent, - PR_FALSE, aState, format->mPercent); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::perMille, - PR_FALSE, aState, format->mPerMille); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::zeroDigit, - PR_FALSE, aState, format->mZeroDigit); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::digit, - PR_FALSE, aState, format->mDigit); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getCharAttr(aAttributes, aAttrCount, txXSLTAtoms::patternSeparator, - PR_FALSE, aState, format->mPatternSeparator); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.mStylesheet->addDecimalFormat(name, format); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndDecimalFormat(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:import -nsresult -txFnStartImport(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr import(new txImportItem); - NS_ENSURE_TRUE(import, NS_ERROR_OUT_OF_MEMORY); - - import->mFrame = new txStylesheet::ImportFrame; - NS_ENSURE_TRUE(import->mFrame, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addToplevelItem(import); - NS_ENSURE_SUCCESS(rv, rv); - - txImportItem* importPtr = import.forget(); - - txStylesheetAttr* attr = nsnull; - rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::href, PR_TRUE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString absUri; - URIUtils::resolveHref(attr->mValue, aState.mElementContext->mBaseURI, - absUri); - rv = aState.loadImportedStylesheet(absUri, importPtr->mFrame); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndImport(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:include -nsresult -txFnStartInclude(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::href, PR_TRUE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString absUri; - URIUtils::resolveHref(attr->mValue, aState.mElementContext->mBaseURI, - absUri); - rv = aState.loadIncludedStylesheet(absUri); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndInclude(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:key -nsresult -txFnStartKey(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr match; - rv = getPatternAttr(aAttributes, aAttrCount, txXSLTAtoms::match, PR_TRUE, - aState, match); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr use; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::use, PR_TRUE, - aState, use); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.mStylesheet->addKey(name, match, use); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndKey(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:output -nsresult -txFnStartOutput(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr item(new txOutputItem); - NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY); - - txExpandedName methodExpName; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::method, PR_FALSE, - aState, methodExpName); - NS_ENSURE_SUCCESS(rv, rv); - - if (!methodExpName.isNull()) { - if (methodExpName.mNamespaceID != kNameSpaceID_None) { - // The spec doesn't say what to do here so we'll just ignore the - // value. We could possibly warn. - } - else if (methodExpName.mLocalName == txXSLTAtoms::html) { - item->mFormat.mMethod = eHTMLOutput; - } - else if (methodExpName.mLocalName == txXSLTAtoms::text) { - item->mFormat.mMethod = eTextOutput; - } - else if (methodExpName.mLocalName == txXSLTAtoms::xml) { - item->mFormat.mMethod = eXMLOutput; - } - else { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - } - - txStylesheetAttr* attr = nsnull; - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::version, PR_FALSE, &attr); - if (attr) { - item->mFormat.mVersion = attr->mValue; - } - - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::encoding, PR_FALSE, &attr); - if (attr) { - item->mFormat.mEncoding = attr->mValue; - } - - rv = getYesNoAttr(aAttributes, aAttrCount, - txXSLTAtoms::omitXmlDeclaration, PR_FALSE, aState, - item->mFormat.mOmitXMLDeclaration); - NS_ENSURE_SUCCESS(rv, rv); - - rv = getYesNoAttr(aAttributes, aAttrCount, - txXSLTAtoms::standalone, PR_FALSE, aState, - item->mFormat.mStandalone); - NS_ENSURE_SUCCESS(rv, rv); - - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::doctypePublic, PR_FALSE, &attr); - if (attr) { - item->mFormat.mPublicId = attr->mValue; - } - - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::doctypeSystem, PR_FALSE, &attr); - if (attr) { - item->mFormat.mSystemId = attr->mValue; - } - - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::cdataSectionElements, PR_FALSE, &attr); - if (attr) { - txTokenizer tokens(attr->mValue); - while (tokens.hasMoreTokens()) { - txExpandedName* qname = new txExpandedName(); - NS_ENSURE_TRUE(qname, NS_ERROR_OUT_OF_MEMORY); - - rv = qname->init(tokens.nextToken(), - aState.mElementContext->mMappings, PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - rv = item->mFormat.mCDATASectionElements.add(qname); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - rv = getYesNoAttr(aAttributes, aAttrCount, - txXSLTAtoms::indent, PR_FALSE, aState, - item->mFormat.mIndent); - NS_ENSURE_SUCCESS(rv, rv); - - getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::mediaType, PR_FALSE, &attr); - if (attr) { - item->mFormat.mMediaType = attr->mValue; - } - - rv = aState.addToplevelItem(item); - NS_ENSURE_SUCCESS(rv, rv); - - item.forget(); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndOutput(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:strip-space/xsl:preserve-space -nsresult -txFnStartStripSpace(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - txStylesheetAttr* attr = nsnull; - nsresult rv = getStyleAttr(aAttributes, aAttrCount, kNameSpaceID_None, - txXSLTAtoms::elements, PR_TRUE, &attr); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool strip = aLocalName == txXSLTAtoms::stripSpace; - - nsAutoPtr stripItem(new txStripSpaceItem); - NS_ENSURE_TRUE(stripItem, NS_ERROR_OUT_OF_MEMORY); - - txTokenizer tokenizer(attr->mValue); - while (tokenizer.hasMoreTokens()) { - const nsASingleFragmentString& name = tokenizer.nextToken(); - PRInt32 ns = kNameSpaceID_None; - nsCOMPtr prefix, localName; - rv = XMLUtils::splitQName(name, getter_AddRefs(prefix), - getter_AddRefs(localName)); - if (NS_FAILED(rv)) { - // check for "*" or "prefix:*" - PRUint32 length = name.Length(); - const PRUnichar* c; - name.BeginReading(c); - if (length == 2 || c[length-1] != '*') { - // these can't work - return NS_ERROR_XSLT_PARSE_FAILURE; - } - if (length > 1) { - // Check for a valid prefix, that is, the returned prefix - // should be empty and the real prefix is returned in - // localName. - if (c[length-2] != ':') { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - rv = XMLUtils::splitQName(Substring(name, 0, length-2), - getter_AddRefs(prefix), - getter_AddRefs(localName)); - if (NS_FAILED(rv) || prefix) { - // bad chars or two ':' - return NS_ERROR_XSLT_PARSE_FAILURE; - } - prefix = localName; - } - localName = txXPathAtoms::_asterix; - } - if (prefix) { - ns = aState.mElementContext->mMappings->lookupNamespace(prefix); - NS_ENSURE_TRUE(ns != kNameSpaceID_Unknown, NS_ERROR_FAILURE); - } - nsAutoPtr sst(new txStripSpaceTest(prefix, localName, - ns, strip)); - NS_ENSURE_TRUE(sst, NS_ERROR_OUT_OF_MEMORY); - - rv = stripItem->addStripSpaceTest(sst); - NS_ENSURE_SUCCESS(rv, rv); - - sst.forget(); - } - - rv = aState.addToplevelItem(stripItem); - NS_ENSURE_SUCCESS(rv, rv); - - stripItem.forget(); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndStripSpace(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -// xsl:template -nsresult -txFnStartTemplate(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_FALSE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - txExpandedName mode; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::mode, PR_FALSE, - aState, mode); - NS_ENSURE_SUCCESS(rv, rv); - - double prio = Double::NaN; - rv = getNumberAttr(aAttributes, aAttrCount, txXSLTAtoms::priority, - PR_FALSE, aState, prio); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr match; - rv = getPatternAttr(aAttributes, aAttrCount, txXSLTAtoms::match, - name.isNull(), aState, match); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr templ(new txTemplateItem(match, name, mode, prio)); - NS_ENSURE_TRUE(templ, NS_ERROR_OUT_OF_MEMORY); - - aState.openInstructionContainer(templ); - rv = aState.addToplevelItem(templ); - NS_ENSURE_SUCCESS(rv, rv); - - templ.forget(); - - return aState.pushHandlerTable(gTxParamHandler); -} - -nsresult -txFnEndTemplate(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - nsAutoPtr instr(new txReturn()); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.closeInstructionContainer(); - - return NS_OK; -} - -// xsl:variable, xsl:param -nsresult -txFnStartTopVariable(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr var( - new txVariableItem(name, select, aLocalName == txXSLTAtoms::param)); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - aState.openInstructionContainer(var); - rv = aState.pushPtr(var); - NS_ENSURE_SUCCESS(rv, rv); - - if (var->mValue) { - // XXX should be gTxErrorHandler? - rv = aState.pushHandlerTable(gTxIgnoreHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - rv = aState.pushHandlerTable(gTxTopVariableHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = aState.addToplevelItem(var); - NS_ENSURE_SUCCESS(rv, rv); - - var.forget(); - - return NS_OK; -} - -nsresult -txFnEndTopVariable(txStylesheetCompilerState& aState) -{ - txHandlerTable* prev = aState.mHandlerTable; - aState.popHandlerTable(); - txVariableItem* var = NS_STATIC_CAST(txVariableItem*, aState.popPtr()); - - if (prev == gTxTopVariableHandler) { - // No children were found. - NS_ASSERTION(!var->mValue, - "There shouldn't be a select-expression here"); - var->mValue = new txLiteralExpr(EmptyString()); - NS_ENSURE_TRUE(var->mValue, NS_ERROR_OUT_OF_MEMORY); - } - else if (!var->mValue) { - // If we don't have a select-expression there mush be children. - nsAutoPtr instr(new txReturn()); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - } - - aState.closeInstructionContainer(); - - return NS_OK; -} - -nsresult -txFnStartElementStartTopVar(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -nsresult -txFnTextStartTopVar(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - TX_RETURN_IF_WHITESPACE(aStr, aState); - - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -/** - * Template Handlers - */ - -/* - LRE - - txStartLREElement - txInsertAttrSet one for each qname in xsl:use-attribute-sets - txLREAttribute one for each attribute - [children] - txEndElement -*/ -nsresult -txFnStartLRE(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr instr(new txStartLREElement(aNamespaceID, - aLocalName, aPrefix)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - rv = parseUseAttrSets(aAttributes, aAttrCount, PR_TRUE, aState); - NS_ENSURE_SUCCESS(rv, rv); - - txStylesheetAttr* attr = nsnull; - PRInt32 i; - for (i = 0; i < aAttrCount; ++i) { - attr = aAttributes + i; - - if (attr->mNamespaceID == kNameSpaceID_XSLT) { - continue; - } - - nsAutoPtr avt( - txExprParser::createAttributeValueTemplate(attr->mValue, &aState)); - NS_ENSURE_TRUE(avt, NS_ERROR_XPATH_PARSE_FAILURE); - - instr = new txLREAttribute(attr->mNamespaceID, attr->mLocalName, - attr->mPrefix, avt); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - } - - return NS_OK; -} - -nsresult -txFnEndLRE(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txEndElement); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - "LRE text" - - txText -*/ -nsresult -txFnText(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - TX_RETURN_IF_WHITESPACE(aStr, aState); - - nsAutoPtr instr(new txText(aStr, MB_FALSE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:apply-imports - - txApplyImportsStart - txApplyImportsEnd -*/ -nsresult -txFnStartApplyImports(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr instr(new txApplyImportsStart); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txApplyImportsEnd; - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndApplyImports(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -/* - xsl:apply-templates - - txPushParams - [params] - txPushNewContext -+ (holds s) - txApplyTemplate <-+ | - txLoopNodeSet -+ | - txPopParams <-+ -*/ -nsresult -txFnStartApplyTemplates(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr instr(new txPushParams); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txExpandedName mode; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::mode, PR_FALSE, - aState, mode); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txApplyTemplates(mode); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushObject(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr.forget(); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - if (!select) { - nsAutoPtr nt( - new txNodeTypeTest(txNodeTypeTest::NODE_TYPE)); - NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY); - - select = new LocationStep(nt, LocationStep::CHILD_AXIS); - NS_ENSURE_TRUE(select, NS_ERROR_OUT_OF_MEMORY); - } - - nsAutoPtr pushcontext(new txPushNewContext(select)); - NS_ENSURE_TRUE(pushcontext, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushSorter(pushcontext); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.pushObject(pushcontext); - NS_ENSURE_SUCCESS(rv, rv); - - pushcontext.forget(); - - return aState.pushHandlerTable(gTxApplyTemplatesHandler); -} - -nsresult -txFnEndApplyTemplates(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - txPushNewContext* pushcontext = - NS_STATIC_CAST(txPushNewContext*, aState.popObject()); - nsAutoPtr instr(pushcontext); // txPushNewContext - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.popSorter(); - - instr = NS_STATIC_CAST(txInstruction*, aState.popObject()); // txApplyTemplates - nsAutoPtr loop(new txLoopNodeSet(instr)); - NS_ENSURE_TRUE(loop, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr = loop.forget(); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txPopParams; - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - pushcontext->mBailTarget = instr; - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:attribute - - txPushStringHandler - [children] - txAttribute -*/ -nsresult -txFnStartAttribute(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr instr(new txPushStringHandler(PR_TRUE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr name; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr nspace; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::_namespace, PR_FALSE, - aState, nspace); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txAttribute(name, nspace, aState.mElementContext->mMappings); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushObject(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr.forget(); - - // We need to push the template-handler since the current might be - // the attributeset-handler - return aState.pushHandlerTable(gTxTemplateHandler); -} - -nsresult -txFnEndAttribute(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - nsAutoPtr instr(NS_STATIC_CAST(txInstruction*, - aState.popObject())); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:call-template - - txPushParams - [params] - txCallTemplate - txPopParams -*/ -nsresult -txFnStartCallTemplate(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr instr(new txPushParams); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txCallTemplate(name); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushObject(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr.forget(); - - return aState.pushHandlerTable(gTxCallTemplateHandler); -} - -nsresult -txFnEndCallTemplate(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - // txCallTemplate - nsAutoPtr instr(NS_STATIC_CAST(txInstruction*, - aState.popObject())); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txPopParams; - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:choose - - txCondotionalGoto --+ \ - [children] | | one for each xsl:when - txGoTo --+ | / - | | - txCondotionalGoto | <-+ --+ - [children] | | - txGoTo --+ | - | | - [children] | <-+ for the xsl:otherwise, if there is one - <-+ -*/ -nsresult -txFnStartChoose(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = aState.pushChooseGotoList(); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxChooseHandler); -} - -nsresult -txFnEndChoose(txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - aState.popHandlerTable(); - txListIterator iter(aState.mChooseGotoList); - txGoTo* gotoinstr; - while ((gotoinstr = NS_STATIC_CAST(txGoTo*, iter.next()))) { - rv = aState.addGotoTarget(&gotoinstr->mTarget); - NS_ENSURE_SUCCESS(rv, rv); - } - - aState.popChooseGotoList(); - - return NS_OK; -} - -/* - xsl:comment - - txPushStringHandler - [children] - txComment -*/ -nsresult -txFnStartComment(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txPushStringHandler(PR_TRUE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -txFnEndComment(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txComment); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:copy - - txCopy -+ - txInsertAttrSet | one for each qname in use-attribute-sets - [children] | - txEndElement | - <-+ -*/ -nsresult -txFnStartCopy(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr copy(new txCopy); - NS_ENSURE_TRUE(copy, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.pushPtr(copy); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(copy.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - rv = parseUseAttrSets(aAttributes, aAttrCount, PR_FALSE, aState); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -txFnEndCopy(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txEndElement); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txCopy* copy = NS_STATIC_CAST(txCopy*, aState.popPtr()); - rv = aState.addGotoTarget(©->mBailTarget); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:copy-of - - txCopyOf -*/ -nsresult -txFnStartCopyOf(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_TRUE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(new txCopyOf(select)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndCopyOf(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - return NS_OK; -} - -/* - xsl:element - - txStartElement - txInsertAttrSet one for each qname in use-attribute-sets - [children] - txEndElement -*/ -nsresult -txFnStartElement(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr name; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr nspace; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::_namespace, PR_FALSE, - aState, nspace); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr( - new txStartElement(name, nspace, aState.mElementContext->mMappings)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - rv = parseUseAttrSets(aAttributes, aAttrCount, PR_FALSE, aState); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -txFnEndElement(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txEndElement); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:fallback - - [children] -*/ -nsresult -txFnStartFallback(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - aState.mSearchingForFallback = PR_FALSE; - - return aState.pushHandlerTable(gTxTemplateHandler); -} - -nsresult -txFnEndFallback(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - NS_ASSERTION(!aState.mSearchingForFallback, - "bad nesting of unknown-instruction and fallback handlers"); - return NS_OK; -} - -/* - xsl:for-each - - txPushNewContext -+ (holds s) - txPushNullTemplateRule <-+ | - [children] | | - txLoopNodeSet -+ | - <-+ -*/ -nsresult -txFnStartForEach(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_TRUE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr pushcontext(new txPushNewContext(select)); - NS_ENSURE_TRUE(pushcontext, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushPtr(pushcontext); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.pushSorter(pushcontext); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(pushcontext.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txPushNullTemplateRule; - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushPtr(instr); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxForEachHandler); -} - -nsresult -txFnEndForEach(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - // This is a txPushNullTemplateRule - txInstruction* pnullrule = - NS_STATIC_CAST(txInstruction*, aState.popPtr()); - - nsAutoPtr instr(new txLoopNodeSet(pnullrule)); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.popSorter(); - txPushNewContext* pushcontext = - NS_STATIC_CAST(txPushNewContext*, aState.popPtr()); - aState.addGotoTarget(&pushcontext->mBailTarget); - - return NS_OK; -} - -nsresult -txFnStartElementContinueTemplate(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -nsresult -txFnTextContinueTemplate(const nsAString& aStr, - txStylesheetCompilerState& aState) -{ - TX_RETURN_IF_WHITESPACE(aStr, aState); - - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -/* - xsl:if - - txConditionalGoto -+ - [children] | - <-+ -*/ -nsresult -txFnStartIf(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr test; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::test, PR_TRUE, - aState, test); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr condGoto(new txConditionalGoto(test, nsnull)); - NS_ENSURE_TRUE(condGoto, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushPtr(condGoto); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(condGoto.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -txFnEndIf(txStylesheetCompilerState& aState) -{ - txConditionalGoto* condGoto = - NS_STATIC_CAST(txConditionalGoto*, aState.popPtr()); - return aState.addGotoTarget(&condGoto->mTarget); -} - -/* - xsl:message - - txPushStringHandler - [children] - txMessage -*/ -nsresult -txFnStartMessage(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txPushStringHandler(PR_FALSE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txThreeState term; - rv = getYesNoAttr(aAttributes, aAttrCount, txXSLTAtoms::terminate, - PR_FALSE, aState, term); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txMessage(term == eTrue); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushObject(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr.forget(); - - return NS_OK; -} - -nsresult -txFnEndMessage(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(NS_STATIC_CAST(txInstruction*, - aState.popObject())); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:number - - txNumber -*/ -nsresult -txFnStartNumber(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsCOMPtr levelAtom; - rv = getAtomAttr(aAttributes, aAttrCount, txXSLTAtoms::level, PR_FALSE, - aState, getter_AddRefs(levelAtom)); - NS_ENSURE_SUCCESS(rv, rv); - - txXSLTNumber::LevelType level = txXSLTNumber::eLevelSingle; - if (levelAtom == txXSLTAtoms::multiple) { - level = txXSLTNumber::eLevelMultiple; - } - else if (levelAtom == txXSLTAtoms::any) { - level = txXSLTNumber::eLevelAny; - } - else if (levelAtom && levelAtom != txXSLTAtoms::single && !aState.fcp()) { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - - nsAutoPtr count; - rv = getPatternAttr(aAttributes, aAttrCount, txXSLTAtoms::count, PR_FALSE, - aState, count); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr from; - rv = getPatternAttr(aAttributes, aAttrCount, txXSLTAtoms::from, PR_FALSE, - aState, from); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr value; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::value, PR_FALSE, - aState, value); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr format; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::format, PR_FALSE, - aState, format); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr groupingSeparator; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::groupingSeparator, - PR_FALSE, aState, groupingSeparator); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr groupingSize; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::groupingSize, - PR_FALSE, aState, groupingSize); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(new txNumber(level, count, from, value, - format,groupingSeparator, - groupingSize)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndNumber(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -/* - xsl:otherwise - - (see xsl:choose) -*/ -nsresult -txFnStartOtherwise(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - return aState.pushHandlerTable(gTxTemplateHandler); -} - -nsresult -txFnEndOtherwise(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - aState.mHandlerTable = gTxIgnoreHandler; // XXX should be gTxErrorHandler - - return NS_OK; -} - -/* - xsl:param - - txCheckParam --+ - txPushRTFHandler | --- (for RTF-parameters) - [children] | / - txSetVariable | - <-+ -*/ -nsresult -txFnStartParam(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr checkParam(new txCheckParam(name)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.pushPtr(checkParam); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(checkParam.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr var(new txSetVariable(name, select)); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - if (var->mValue) { - // XXX should be gTxErrorHandler? - rv = aState.pushHandlerTable(gTxIgnoreHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - rv = aState.pushHandlerTable(gTxVariableHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = aState.pushObject(var); - NS_ENSURE_SUCCESS(rv, rv); - - var.forget(); - - return NS_OK; -} - -nsresult -txFnEndParam(txStylesheetCompilerState& aState) -{ - nsAutoPtr var(NS_STATIC_CAST(txSetVariable*, - aState.popObject())); - txHandlerTable* prev = aState.mHandlerTable; - aState.popHandlerTable(); - - if (prev == gTxVariableHandler) { - // No children were found. - NS_ASSERTION(!var->mValue, - "There shouldn't be a select-expression here"); - var->mValue = new txLiteralExpr(EmptyString()); - NS_ENSURE_TRUE(var->mValue, NS_ERROR_OUT_OF_MEMORY); - } - - nsresult rv = aState.addVariable(var->mName); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(var.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txCheckParam* checkParam = NS_STATIC_CAST(txCheckParam*, aState.popPtr()); - aState.addGotoTarget(&checkParam->mBailTarget); - - return NS_OK; -} - -/* - xsl:processing-instruction - - txPushStringHandler - [children] - txProcessingInstruction -*/ -nsresult -txFnStartPI(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txPushStringHandler(PR_TRUE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr name; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - instr = new txProcessingInstruction(name); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushObject(instr); - NS_ENSURE_SUCCESS(rv, rv); - - instr.forget(); - - return NS_OK; -} - -nsresult -txFnEndPI(txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(NS_STATIC_CAST(txInstruction*, - aState.popObject())); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:sort - - (no instructions) -*/ -nsresult -txFnStartSort(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - if (!select) { - nsAutoPtr nt( - new txNodeTypeTest(txNodeTypeTest::NODE_TYPE)); - NS_ENSURE_TRUE(nt, NS_ERROR_OUT_OF_MEMORY); - - select = new LocationStep(nt, LocationStep::SELF_AXIS); - NS_ENSURE_TRUE(select, NS_ERROR_OUT_OF_MEMORY); - } - - nsAutoPtr lang; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::lang, PR_FALSE, - aState, lang); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr dataType; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::dataType, PR_FALSE, - aState, dataType); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr order; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::order, PR_FALSE, - aState, order); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr caseOrder; - rv = getAVTAttr(aAttributes, aAttrCount, txXSLTAtoms::caseOrder, PR_FALSE, - aState, caseOrder); - NS_ENSURE_SUCCESS(rv, rv); - - rv = aState.mSorter->addSort(select, lang, dataType, order, caseOrder); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndSort(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - return NS_OK; -} - -/* - xsl:text - - [children] (only txText) -*/ -nsresult -txFnStartText(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - NS_ASSERTION(!aState.mDOE, "nested d-o-e elements should not happen"); - - nsresult rv = NS_OK; - txThreeState doe; - rv = getYesNoAttr(aAttributes, aAttrCount, - txXSLTAtoms::disableOutputEscaping, PR_FALSE, aState, - doe); - NS_ENSURE_SUCCESS(rv, rv); - - aState.mDOE = doe == eTrue; - - return aState.pushHandlerTable(gTxTextHandler); -} - -nsresult -txFnEndText(txStylesheetCompilerState& aState) -{ - aState.mDOE = MB_FALSE; - aState.popHandlerTable(); - return NS_OK; -} - -nsresult -txFnTextText(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txText(aStr, aState.mDOE)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:value-of - - txValueOf -*/ -nsresult -txFnStartValueOf(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - txThreeState doe; - rv = getYesNoAttr(aAttributes, aAttrCount, - txXSLTAtoms::disableOutputEscaping, PR_FALSE, aState, - doe); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_TRUE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(new txValueOf(select, doe == eTrue)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxIgnoreHandler); -} - -nsresult -txFnEndValueOf(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - return NS_OK; -} - -/* - xsl:variable - - txPushRTFHandler --- (for RTF-parameters) - [children] / - txSetVariable -*/ -nsresult -txFnStartVariable(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr var(new txSetVariable(name, select)); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - if (var->mValue) { - // XXX should be gTxErrorHandler? - rv = aState.pushHandlerTable(gTxIgnoreHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - rv = aState.pushHandlerTable(gTxVariableHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = aState.pushObject(var); - NS_ENSURE_SUCCESS(rv, rv); - - var.forget(); - - return NS_OK; -} - -nsresult -txFnEndVariable(txStylesheetCompilerState& aState) -{ - nsAutoPtr var(NS_STATIC_CAST(txSetVariable*, - aState.popObject())); - - txHandlerTable* prev = aState.mHandlerTable; - aState.popHandlerTable(); - - if (prev == gTxVariableHandler) { - // No children were found. - NS_ASSERTION(!var->mValue, - "There shouldn't be a select-expression here"); - var->mValue = new txLiteralExpr(EmptyString()); - NS_ENSURE_TRUE(var->mValue, NS_ERROR_OUT_OF_MEMORY); - } - - nsresult rv = aState.addVariable(var->mName); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(var.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult -txFnStartElementStartRTF(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsAutoPtr instr(new txPushRTFHandler); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -nsresult -txFnTextStartRTF(const nsAString& aStr, txStylesheetCompilerState& aState) -{ - TX_RETURN_IF_WHITESPACE(aStr, aState); - - nsAutoPtr instr(new txPushRTFHandler); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - aState.mHandlerTable = gTxTemplateHandler; - - return NS_XSLT_GET_NEW_HANDLER; -} - -/* - xsl:when - - (see xsl:choose) -*/ -nsresult -txFnStartWhen(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - nsAutoPtr test; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::test, PR_TRUE, - aState, test); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr condGoto(new txConditionalGoto(test, nsnull)); - NS_ENSURE_TRUE(condGoto, NS_ERROR_OUT_OF_MEMORY); - - rv = aState.pushPtr(condGoto); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(condGoto.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return aState.pushHandlerTable(gTxTemplateHandler); -} - -nsresult -txFnEndWhen(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - nsAutoPtr gotoinstr(new txGoTo(nsnull)); - NS_ENSURE_TRUE(gotoinstr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.mChooseGotoList->add(gotoinstr); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr instr(gotoinstr.forget()); - rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - txConditionalGoto* condGoto = - NS_STATIC_CAST(txConditionalGoto*, aState.popPtr()); - rv = aState.addGotoTarget(&condGoto->mTarget); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - xsl:with-param - - txPushRTFHandler -- for RTF-parameters - [children] / - txSetParam -*/ -nsresult -txFnStartWithParam(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - nsresult rv = NS_OK; - - txExpandedName name; - rv = getQNameAttr(aAttributes, aAttrCount, txXSLTAtoms::name, PR_TRUE, - aState, name); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr select; - rv = getExprAttr(aAttributes, aAttrCount, txXSLTAtoms::select, PR_FALSE, - aState, select); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoPtr var(new txSetParam(name, select)); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - if (var->mValue) { - // XXX should be gTxErrorHandler? - rv = aState.pushHandlerTable(gTxIgnoreHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - rv = aState.pushHandlerTable(gTxVariableHandler); - NS_ENSURE_SUCCESS(rv, rv); - } - - rv = aState.pushObject(var); - NS_ENSURE_SUCCESS(rv, rv); - - var.forget(); - - return NS_OK; -} - -nsresult -txFnEndWithParam(txStylesheetCompilerState& aState) -{ - nsAutoPtr var(NS_STATIC_CAST(txSetParam*, aState.popObject())); - txHandlerTable* prev = aState.mHandlerTable; - aState.popHandlerTable(); - - if (prev == gTxVariableHandler) { - // No children were found. - NS_ASSERTION(!var->mValue, - "There shouldn't be a select-expression here"); - var->mValue = new txLiteralExpr(EmptyString()); - NS_ENSURE_TRUE(var->mValue, NS_ERROR_OUT_OF_MEMORY); - } - - nsAutoPtr instr(var.forget()); - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -/* - Unknown instruction - - [fallbacks] if one or more xsl:fallbacks are found - or - txErrorInstruction otherwise -*/ -nsresult -txFnStartUnknownInstruction(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState) -{ - NS_ASSERTION(!aState.mSearchingForFallback, - "bad nesting of unknown-instruction and fallback handlers"); - aState.mSearchingForFallback = PR_TRUE; - - return aState.pushHandlerTable(gTxFallbackHandler); -} - -nsresult -txFnEndUnknownInstruction(txStylesheetCompilerState& aState) -{ - aState.popHandlerTable(); - - if (aState.mSearchingForFallback) { - nsAutoPtr instr(new txErrorInstruction()); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = aState.addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - } - - aState.mSearchingForFallback = PR_FALSE; - - return NS_OK; -} - -/** - * Table Datas - */ - -struct txHandlerTableData { - txElementHandler mOtherHandler; - txElementHandler mLREHandler; - HandleTextFn mTextHandler; -}; - -const txHandlerTableData gTxIgnoreTableData = { - // Other - { 0, 0, txFnStartElementIgnore, txFnEndElementIgnore }, - // LRE - { 0, 0, txFnStartElementIgnore, txFnEndElementIgnore }, - // Text - txFnTextIgnore -}; - -const txElementHandler gTxRootElementHandlers[] = { - { kNameSpaceID_XSLT, "stylesheet", txFnStartStylesheet, txFnEndStylesheet }, - { kNameSpaceID_XSLT, "transform", txFnStartStylesheet, txFnEndStylesheet } -}; - -const txHandlerTableData gTxRootTableData = { - // Other - { 0, 0, txFnStartElementError, txFnEndElementError }, - // LRE - { 0, 0, txFnStartLREStylesheet, txFnEndLREStylesheet }, - // Text - txFnTextError -}; - -const txHandlerTableData gTxEmbedTableData = { - // Other - { 0, 0, txFnStartEmbed, txFnEndEmbed }, - // LRE - { 0, 0, txFnStartElementIgnore, txFnEndElementIgnore }, - // Text - txFnTextIgnore -}; - -const txElementHandler gTxTopElementHandlers[] = { - { kNameSpaceID_XSLT, "attribute-set", txFnStartAttributeSet, txFnEndAttributeSet }, - { kNameSpaceID_XSLT, "decimal-format", txFnStartDecimalFormat, txFnEndDecimalFormat }, - { kNameSpaceID_XSLT, "include", txFnStartInclude, txFnEndInclude }, - { kNameSpaceID_XSLT, "key", txFnStartKey, txFnEndKey }, - { kNameSpaceID_XSLT, "output", txFnStartOutput, txFnEndOutput }, - { kNameSpaceID_XSLT, "param", txFnStartTopVariable, txFnEndTopVariable }, - { kNameSpaceID_XSLT, "preserve-space", txFnStartStripSpace, txFnEndStripSpace }, - { kNameSpaceID_XSLT, "strip-space", txFnStartStripSpace, txFnEndStripSpace }, - { kNameSpaceID_XSLT, "template", txFnStartTemplate, txFnEndTemplate }, - { kNameSpaceID_XSLT, "variable", txFnStartTopVariable, txFnEndTopVariable } -}; - -const txHandlerTableData gTxTopTableData = { - // Other - { 0, 0, txFnStartOtherTop, txFnEndOtherTop }, - // LRE - { 0, 0, txFnStartOtherTop, txFnEndOtherTop }, - // Text - txFnTextIgnore -}; - -const txElementHandler gTxTemplateElementHandlers[] = { - { kNameSpaceID_XSLT, "apply-imports", txFnStartApplyImports, txFnEndApplyImports }, - { kNameSpaceID_XSLT, "apply-templates", txFnStartApplyTemplates, txFnEndApplyTemplates }, - { kNameSpaceID_XSLT, "attribute", txFnStartAttribute, txFnEndAttribute }, - { kNameSpaceID_XSLT, "call-template", txFnStartCallTemplate, txFnEndCallTemplate }, - { kNameSpaceID_XSLT, "choose", txFnStartChoose, txFnEndChoose }, - { kNameSpaceID_XSLT, "comment", txFnStartComment, txFnEndComment }, - { kNameSpaceID_XSLT, "copy", txFnStartCopy, txFnEndCopy }, - { kNameSpaceID_XSLT, "copy-of", txFnStartCopyOf, txFnEndCopyOf }, - { kNameSpaceID_XSLT, "element", txFnStartElement, txFnEndElement }, - { kNameSpaceID_XSLT, "fallback", txFnStartElementSetIgnore, txFnEndElementSetIgnore }, - { kNameSpaceID_XSLT, "for-each", txFnStartForEach, txFnEndForEach }, - { kNameSpaceID_XSLT, "if", txFnStartIf, txFnEndIf }, - { kNameSpaceID_XSLT, "message", txFnStartMessage, txFnEndMessage }, - { kNameSpaceID_XSLT, "number", txFnStartNumber, txFnEndNumber }, - { kNameSpaceID_XSLT, "processing-instruction", txFnStartPI, txFnEndPI }, - { kNameSpaceID_XSLT, "text", txFnStartText, txFnEndText }, - { kNameSpaceID_XSLT, "value-of", txFnStartValueOf, txFnEndValueOf }, - { kNameSpaceID_XSLT, "variable", txFnStartVariable, txFnEndVariable } -}; - -const txHandlerTableData gTxTemplateTableData = { - // Other - { 0, 0, txFnStartUnknownInstruction, txFnEndUnknownInstruction }, - // LRE - { 0, 0, txFnStartLRE, txFnEndLRE }, - // Text - txFnText -}; - -const txHandlerTableData gTxTextTableData = { - // Other - { 0, 0, txFnStartElementError, txFnEndElementError }, - // LRE - { 0, 0, txFnStartElementError, txFnEndElementError }, - // Text - txFnTextText -}; - -const txElementHandler gTxApplyTemplatesElementHandlers[] = { - { kNameSpaceID_XSLT, "sort", txFnStartSort, txFnEndSort }, - { kNameSpaceID_XSLT, "with-param", txFnStartWithParam, txFnEndWithParam } -}; - -const txHandlerTableData gTxApplyTemplatesTableData = { - // Other - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, // should this be error? - // LRE - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, - // Text - txFnTextIgnore -}; - -const txElementHandler gTxCallTemplateElementHandlers[] = { - { kNameSpaceID_XSLT, "with-param", txFnStartWithParam, txFnEndWithParam } -}; - -const txHandlerTableData gTxCallTemplateTableData = { - // Other - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, // should this be error? - // LRE - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, - // Text - txFnTextIgnore -}; - -const txHandlerTableData gTxVariableTableData = { - // Other - { 0, 0, txFnStartElementStartRTF, 0 }, - // LRE - { 0, 0, txFnStartElementStartRTF, 0 }, - // Text - txFnTextStartRTF -}; - -const txElementHandler gTxForEachElementHandlers[] = { - { kNameSpaceID_XSLT, "sort", txFnStartSort, txFnEndSort } -}; - -const txHandlerTableData gTxForEachTableData = { - // Other - { 0, 0, txFnStartElementContinueTemplate, 0 }, - // LRE - { 0, 0, txFnStartElementContinueTemplate, 0 }, - // Text - txFnTextContinueTemplate -}; - -const txHandlerTableData gTxTopVariableTableData = { - // Other - { 0, 0, txFnStartElementStartTopVar, 0 }, - // LRE - { 0, 0, txFnStartElementStartTopVar, 0 }, - // Text - txFnTextStartTopVar -}; - -const txElementHandler gTxChooseElementHandlers[] = { - { kNameSpaceID_XSLT, "otherwise", txFnStartOtherwise, txFnEndOtherwise }, - { kNameSpaceID_XSLT, "when", txFnStartWhen, txFnEndWhen } -}; - -const txHandlerTableData gTxChooseTableData = { - // Other - { 0, 0, txFnStartElementError, 0 }, - // LRE - { 0, 0, txFnStartElementError, 0 }, - // Text - txFnTextError -}; - -const txElementHandler gTxParamElementHandlers[] = { - { kNameSpaceID_XSLT, "param", txFnStartParam, txFnEndParam } -}; - -const txHandlerTableData gTxParamTableData = { - // Other - { 0, 0, txFnStartElementContinueTemplate, 0 }, - // LRE - { 0, 0, txFnStartElementContinueTemplate, 0 }, - // Text - txFnTextContinueTemplate -}; - -const txElementHandler gTxImportElementHandlers[] = { - { kNameSpaceID_XSLT, "import", txFnStartImport, txFnEndImport } -}; - -const txHandlerTableData gTxImportTableData = { - // Other - { 0, 0, txFnStartElementContinueTopLevel, 0 }, - // LRE - { 0, 0, txFnStartOtherTop, txFnEndOtherTop }, // XXX what should we do here? - // Text - txFnTextIgnore // XXX what should we do here? -}; - -const txElementHandler gTxAttributeSetElementHandlers[] = { - { kNameSpaceID_XSLT, "attribute", txFnStartAttribute, txFnEndAttribute } -}; - -const txHandlerTableData gTxAttributeSetTableData = { - // Other - { 0, 0, txFnStartElementError, 0 }, - // LRE - { 0, 0, txFnStartElementError, 0 }, - // Text - txFnTextError -}; - -const txElementHandler gTxFallbackElementHandlers[] = { - { kNameSpaceID_XSLT, "fallback", txFnStartFallback, txFnEndFallback } -}; - -const txHandlerTableData gTxFallbackTableData = { - // Other - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, - // LRE - { 0, 0, txFnStartElementSetIgnore, txFnEndElementSetIgnore }, - // Text - txFnTextIgnore -}; - - - -/** - * txHandlerTable - */ -txHandlerTable::txHandlerTable(const HandleTextFn aTextHandler, - const txElementHandler* aLREHandler, - const txElementHandler* aOtherHandler) - : mTextHandler(aTextHandler), - mLREHandler(aLREHandler), - mOtherHandler(aOtherHandler), - mHandlers(PR_FALSE) -{ -} - -nsresult -txHandlerTable::init(const txElementHandler* aHandlers, PRUint32 aCount) -{ - nsresult rv = NS_OK; - - PRUint32 i; - for (i = 0; i < aCount; ++i) { - nsCOMPtr nameAtom = do_GetAtom(aHandlers->mLocalName); - txExpandedName name(aHandlers->mNamespaceID, nameAtom); - // XXX this cast is a reinterpret_cast, which is sad - rv = mHandlers.add(name, (TxObject*)aHandlers); - NS_ENSURE_SUCCESS(rv, rv); - - ++aHandlers; - } - return NS_OK; -} - -const txElementHandler* -txHandlerTable::find(PRInt32 aNamespaceID, nsIAtom* aLocalName) -{ - txExpandedName name(aNamespaceID, aLocalName); - // XXX this cast is a reinterpret_cast, same sad story as in ::init - const txElementHandler* handler = - (const txElementHandler*)mHandlers.get(name); - if (!handler) { - handler = mOtherHandler; - } - return handler; -} - -#define INIT_HANDLER(_name) \ - gTx##_name##Handler = \ - new txHandlerTable(gTx##_name##TableData.mTextHandler, \ - &gTx##_name##TableData.mLREHandler, \ - &gTx##_name##TableData.mOtherHandler); \ - if (!gTx##_name##Handler) \ - return PR_FALSE - -#define INIT_HANDLER_WITH_ELEMENT_HANDLERS(_name) \ - INIT_HANDLER(_name); \ - \ - rv = gTx##_name##Handler->init(gTx##_name##ElementHandlers, \ - NS_ARRAY_LENGTH(gTx##_name##ElementHandlers)); \ - if (NS_FAILED(rv)) \ - return PR_FALSE - -#define SHUTDOWN_HANDLER(_name) \ - delete gTx##_name##Handler; \ - gTx##_name##Handler = nsnull - -// static -MBool -txHandlerTable::init() -{ - nsresult rv = NS_OK; - - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Root); - INIT_HANDLER(Embed); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Top); - INIT_HANDLER(Ignore); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Template); - INIT_HANDLER(Text); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(ApplyTemplates); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(CallTemplate); - INIT_HANDLER(Variable); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(ForEach); - INIT_HANDLER(TopVariable); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Choose); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Param); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Import); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(AttributeSet); - INIT_HANDLER_WITH_ELEMENT_HANDLERS(Fallback); - - return MB_TRUE; -} - -// static -void -txHandlerTable::shutdown() -{ - SHUTDOWN_HANDLER(Root); - SHUTDOWN_HANDLER(Top); - SHUTDOWN_HANDLER(Ignore); - SHUTDOWN_HANDLER(Template); - SHUTDOWN_HANDLER(Text); - SHUTDOWN_HANDLER(ApplyTemplates); - SHUTDOWN_HANDLER(CallTemplate); - SHUTDOWN_HANDLER(Variable); - SHUTDOWN_HANDLER(ForEach); - SHUTDOWN_HANDLER(TopVariable); - SHUTDOWN_HANDLER(Choose); - SHUTDOWN_HANDLER(Param); - SHUTDOWN_HANDLER(Import); - SHUTDOWN_HANDLER(AttributeSet); - SHUTDOWN_HANDLER(Fallback); -} diff --git a/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.h b/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.h deleted file mode 100644 index 131cd9201bef..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheetCompileHandlers.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXSTYLESHEETCOMPILEHANDLERS_H -#define TRANSFRMX_TXSTYLESHEETCOMPILEHANDLERS_H - -#include "txError.h" -#include "txNamespaceMap.h" -#include "txExpandedNameMap.h" - -struct txStylesheetAttr; -class txStylesheetCompilerState; - -typedef nsresult (*HandleStartFn) (PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - txStylesheetCompilerState& aState); -typedef nsresult (*HandleEndFn) (txStylesheetCompilerState& aState); -typedef nsresult (*HandleTextFn) (const nsAString& aStr, - txStylesheetCompilerState& aState); - -struct txElementHandler { - PRInt32 mNamespaceID; - char* mLocalName; - HandleStartFn mStartFunction; - HandleEndFn mEndFunction; -}; - -class txHandlerTable -{ -public: - txHandlerTable(const HandleTextFn aTextHandler, - const txElementHandler* aLREHandler, - const txElementHandler* aOtherHandler); - nsresult init(const txElementHandler* aHandlers, PRUint32 aCount); - const txElementHandler* find(PRInt32 aNamespaceID, nsIAtom* aLocalName); - - const HandleTextFn mTextHandler; - const txElementHandler* const mLREHandler; - - static MBool init(); - static void shutdown(); - -private: - const txElementHandler* const mOtherHandler; - txExpandedNameMap mHandlers; -}; - -extern txHandlerTable* gTxRootHandler; -extern txHandlerTable* gTxEmbedHandler; - -#endif //TRANSFRMX_TXSTYLESHEETCOMPILEHANDLERS_H diff --git a/extensions/transformiix/source/xslt/txStylesheetCompiler.cpp b/extensions/transformiix/source/xslt/txStylesheetCompiler.cpp deleted file mode 100644 index be9a049c38e3..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheetCompiler.cpp +++ /dev/null @@ -1,999 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txStylesheetCompiler.h" -#include "txStylesheetCompileHandlers.h" -#include "txAtoms.h" -#include "txURIUtils.h" -#include "txTokenizer.h" -#include "txStylesheet.h" -#include "txInstructions.h" -#include "txToplevelItems.h" -#include "ExprParser.h" -#include "TxLog.h" -#include "txPatternParser.h" -#include "txStringUtils.h" -#include "XSLTFunctions.h" - -txStylesheetCompiler::txStylesheetCompiler(const nsAString& aBaseURI, - txACompileObserver* aObserver) - : txStylesheetCompilerState(aObserver) -{ - mStatus = init(aBaseURI, nsnull, nsnull); -} - -txStylesheetCompiler::txStylesheetCompiler(const nsAString& aBaseURI, - txStylesheet* aStylesheet, - txListIterator* aInsertPosition, - txACompileObserver* aObserver) - : txStylesheetCompilerState(aObserver) -{ - mStatus = init(aBaseURI, aStylesheet, aInsertPosition); -} - -nsrefcnt -txStylesheetCompiler::AddRef() -{ - return ++mRefCnt; -} - -nsrefcnt -txStylesheetCompiler::Release() -{ - if (--mRefCnt == 0) { - mRefCnt = 1; //stabilize - delete this; - return 0; - } - return mRefCnt; -} - -nsresult -txStylesheetCompiler::startElement(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount) -{ - if (NS_FAILED(mStatus)) { - // ignore content after failure - // XXX reevaluate once expat stops on failure - return NS_OK; - } - - nsresult rv = flushCharacters(); - NS_ENSURE_SUCCESS(rv, rv); - - // look for new namespace mappings - PRBool hasOwnNamespaceMap = PR_FALSE; - PRInt32 i; - for (i = 0; i < aAttrCount; ++i) { - txStylesheetAttr* attr = aAttributes + i; - if (attr->mNamespaceID == kNameSpaceID_XMLNS) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - if (!hasOwnNamespaceMap) { - mElementContext->mMappings = - new txNamespaceMap(*mElementContext->mMappings); - NS_ENSURE_TRUE(mElementContext->mMappings, - NS_ERROR_OUT_OF_MEMORY); - hasOwnNamespaceMap = PR_TRUE; - } - - if (attr->mLocalName == txXMLAtoms::xmlns) { - mElementContext->mMappings->addNamespace(nsnull, attr->mValue); - } - else { - mElementContext->mMappings-> - addNamespace(attr->mLocalName, attr->mValue); - } - } - } - - return startElementInternal(aNamespaceID, aLocalName, aPrefix, - aAttributes, aAttrCount); -} - -nsresult -txStylesheetCompiler::startElement(const PRUnichar *aName, - const PRUnichar **aAttrs, - PRInt32 aAttrCount, PRInt32 aIDOffset) -{ - if (NS_FAILED(mStatus)) { - // ignore content after failure - // XXX reevaluate once expat stops on failure - return NS_OK; - } - - nsresult rv = flushCharacters(); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoArrayPtr atts; - if (aAttrCount > 0) { - atts = new txStylesheetAttr[aAttrCount]; - NS_ENSURE_TRUE(atts, NS_ERROR_OUT_OF_MEMORY); - } - - PRBool hasOwnNamespaceMap = PR_FALSE; - PRInt32 i; - for (i = 0; i < aAttrCount; ++i) { - rv = XMLUtils::splitExpatName(aAttrs[i * 2], - getter_AddRefs(atts[i].mPrefix), - getter_AddRefs(atts[i].mLocalName), - &atts[i].mNamespaceID); - NS_ENSURE_SUCCESS(rv, rv); - atts[i].mValue.Append(aAttrs[i * 2 + 1]); - - nsCOMPtr prefixToBind; - if (atts[i].mPrefix == txXMLAtoms::xmlns) { - prefixToBind = atts[i].mLocalName; - } - else if (atts[i].mNamespaceID == kNameSpaceID_XMLNS) { - prefixToBind = txXMLAtoms::_empty; - } - - if (prefixToBind) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - if (!hasOwnNamespaceMap) { - mElementContext->mMappings = - new txNamespaceMap(*mElementContext->mMappings); - NS_ENSURE_TRUE(mElementContext->mMappings, - NS_ERROR_OUT_OF_MEMORY); - hasOwnNamespaceMap = PR_TRUE; - } - - rv = mElementContext->mMappings-> - addNamespace(prefixToBind, atts[i].mValue); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - nsCOMPtr prefix, localname; - PRInt32 namespaceID; - rv = XMLUtils::splitExpatName(aName, getter_AddRefs(prefix), - getter_AddRefs(localname), &namespaceID); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 idOffset = aIDOffset; - if (idOffset > 0) { - idOffset /= 2; - } - return startElementInternal(namespaceID, localname, prefix, atts, - aAttrCount, idOffset); -} - -nsresult -txStylesheetCompiler::startElementInternal(PRInt32 aNamespaceID, - nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - PRInt32 aIDOffset) -{ - nsresult rv = NS_OK; - PRInt32 i; - for (i = mInScopeVariables.Count() - 1; i >= 0; --i) { - ++(NS_STATIC_CAST(txInScopeVariable*, mInScopeVariables[i]))->mLevel; - } - - // Update the elementcontext if we have special attributes - for (i = 0; i < aAttrCount; ++i) { - txStylesheetAttr* attr = aAttributes + i; - - // xml:space - if (attr->mNamespaceID == kNameSpaceID_XML && - attr->mLocalName == txXMLAtoms::space) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - if (TX_StringEqualsAtom(attr->mValue, txXMLAtoms::preserve)) { - mElementContext->mPreserveWhitespace = MB_TRUE; - } - else if (TX_StringEqualsAtom(attr->mValue, txXMLAtoms::_default)) { - mElementContext->mPreserveWhitespace = MB_FALSE; - } - else { - return NS_ERROR_XSLT_PARSE_FAILURE; - } - } - - // xml:base - if (attr->mNamespaceID == kNameSpaceID_XML && - attr->mLocalName == txXMLAtoms::base && - !attr->mValue.IsEmpty()) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString uri; - URIUtils::resolveHref(attr->mValue, mElementContext->mBaseURI, uri); - mElementContext->mBaseURI = uri; - } - - // extension-element-prefixes - if ((attr->mNamespaceID == kNameSpaceID_XSLT && - attr->mLocalName == txXSLTAtoms::extensionElementPrefixes && - aNamespaceID != kNameSpaceID_XSLT) || - (attr->mNamespaceID == kNameSpaceID_None && - attr->mLocalName == txXSLTAtoms::extensionElementPrefixes && - aNamespaceID == kNameSpaceID_XSLT && - (aLocalName == txXSLTAtoms::stylesheet || - aLocalName == txXSLTAtoms::transform))) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - txTokenizer tok(attr->mValue); - while (tok.hasMoreTokens()) { - PRInt32 namespaceID = mElementContext->mMappings-> - lookupNamespaceWithDefault(tok.nextToken()); - - if (namespaceID == kNameSpaceID_Unknown) - return NS_ERROR_XSLT_PARSE_FAILURE; - - if (!mElementContext->mInstructionNamespaces. - AppendElement(NS_INT32_TO_PTR(namespaceID))) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - } - - // version - if ((attr->mNamespaceID == kNameSpaceID_XSLT && - attr->mLocalName == txXSLTAtoms::version && - aNamespaceID != kNameSpaceID_XSLT) || - (attr->mNamespaceID == kNameSpaceID_None && - attr->mLocalName == txXSLTAtoms::version && - aNamespaceID == kNameSpaceID_XSLT && - (aLocalName == txXSLTAtoms::stylesheet || - aLocalName == txXSLTAtoms::transform))) { - rv = ensureNewElementContext(); - NS_ENSURE_SUCCESS(rv, rv); - - if (attr->mValue.EqualsLiteral("1.0")) { - mElementContext->mForwardsCompatibleParsing = MB_FALSE; - } - else { - mElementContext->mForwardsCompatibleParsing = MB_TRUE; - } - } - } - - // Find the right elementhandler and execute it - MBool isInstruction = MB_FALSE; - PRInt32 count = mElementContext->mInstructionNamespaces.Count(); - for (i = 0; i < count; ++i) { - if (NS_PTR_TO_INT32(mElementContext->mInstructionNamespaces[i]) == - aNamespaceID) { - isInstruction = MB_TRUE; - break; - } - } - - if (mEmbedStatus == eNeedEmbed) { - // handle embedded stylesheets - if (aIDOffset >= 0 && aAttributes[aIDOffset].mValue.Equals(mTarget)) { - // We found the right ID, signal to compile the - // embedded stylesheet. - mEmbedStatus = eInEmbed; - } - } - const txElementHandler* handler; - do { - handler = isInstruction ? - mHandlerTable->find(aNamespaceID, aLocalName) : - mHandlerTable->mLREHandler; - - rv = (handler->mStartFunction)(aNamespaceID, aLocalName, aPrefix, - aAttributes, aAttrCount, *this); - } while (rv == NS_XSLT_GET_NEW_HANDLER); - - NS_ENSURE_SUCCESS(rv, rv); - - rv = pushPtr(NS_CONST_CAST(txElementHandler*, handler)); - NS_ENSURE_SUCCESS(rv, rv); - - mElementContext->mDepth++; - - return NS_OK; -} - -nsresult -txStylesheetCompiler::endElement() -{ - if (NS_FAILED(mStatus)) { - // ignore content after failure - // XXX reevaluate once expat stops on failure - return NS_OK; - } - - nsresult rv = flushCharacters(); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 i; - for (i = mInScopeVariables.Count() - 1; i >= 0; --i) { - txInScopeVariable* var = - NS_STATIC_CAST(txInScopeVariable*, mInScopeVariables[i]); - if (!--(var->mLevel)) { - nsAutoPtr instr(new txRemoveVariable(var->mName)); - NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY); - - rv = addInstruction(instr); - NS_ENSURE_SUCCESS(rv, rv); - - mInScopeVariables.RemoveElementAt(i); - delete var; - } - } - - const txElementHandler* handler = - NS_CONST_CAST(const txElementHandler*, - NS_STATIC_CAST(txElementHandler*, popPtr())); - rv = (handler->mEndFunction)(*this); - NS_ENSURE_SUCCESS(rv, rv); - - if (!--mElementContext->mDepth) { - // this will delete the old object - mElementContext = NS_STATIC_CAST(txElementContext*, popObject()); - } - - return NS_OK; -} - -nsresult -txStylesheetCompiler::characters(const nsAString& aStr) -{ - if (NS_FAILED(mStatus)) { - // ignore content after failure - // XXX reevaluate once expat stops on failure - return NS_OK; - } - - mCharacters.Append(aStr); - - return NS_OK; -} - -nsresult -txStylesheetCompiler::doneLoading() -{ - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("Compiler::doneLoading: %s\n", - NS_LossyConvertUCS2toASCII(mURI).get())); - if (NS_FAILED(mStatus)) { - return mStatus; - } - - mDoneWithThisStylesheet = PR_TRUE; - - return maybeDoneCompiling(); -} - -void -txStylesheetCompiler::cancel(nsresult aError, const PRUnichar *aErrorText, - const PRUnichar *aParam) -{ - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("Compiler::cancel: %s, module: %d, code %d\n", - NS_LossyConvertUCS2toASCII(mURI).get(), - NS_ERROR_GET_MODULE(aError), - NS_ERROR_GET_CODE(aError))); - if (NS_SUCCEEDED(mStatus)) { - mStatus = aError; - } - - if (mObserver) { - mObserver->onDoneCompiling(this, mStatus, aErrorText, aParam); - // This will ensure that we don't call onDoneCompiling twice. Also - // ensures that we don't keep the observer alive longer then necessary. - mObserver = nsnull; - } -} - -txStylesheet* -txStylesheetCompiler::getStylesheet() -{ - return mStylesheet; -} - -nsresult -txStylesheetCompiler::loadURI(const nsAString& aUri, - const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler) -{ - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("Compiler::loadURI forwards %s thru %s\n", - NS_LossyConvertUCS2toASCII(aUri).get(), - NS_LossyConvertUCS2toASCII(mURI).get())); - if (mURI.Equals(aUri)) { - return NS_ERROR_XSLT_LOAD_RECURSION; - } - return mObserver ? mObserver->loadURI(aUri, aReferrerUri, aCompiler) : - NS_ERROR_FAILURE; -} - -void -txStylesheetCompiler::onDoneCompiling(txStylesheetCompiler* aCompiler, - nsresult aResult, - const PRUnichar *aErrorText, - const PRUnichar *aParam) -{ - if (NS_FAILED(aResult)) { - cancel(aResult, aErrorText, aParam); - return; - } - - mChildCompilerList.RemoveElement(aCompiler); - - maybeDoneCompiling(); -} - -nsresult -txStylesheetCompiler::flushCharacters() -{ - // Bail if we don't have any characters. The handler will detect - // ignoreable whitespace - if (mCharacters.IsEmpty()) { - return NS_OK; - } - - nsresult rv = NS_OK; - - do { - rv = (mHandlerTable->mTextHandler)(mCharacters, *this); - } while (rv == NS_XSLT_GET_NEW_HANDLER); - - NS_ENSURE_SUCCESS(rv, rv); - - mCharacters.Truncate(); - - return NS_OK; -} - -nsresult -txStylesheetCompiler::ensureNewElementContext() -{ - // Do we already have a new context? - if (!mElementContext->mDepth) { - return NS_OK; - } - - nsAutoPtr - context(new txElementContext(*mElementContext)); - NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = pushObject(mElementContext); - NS_ENSURE_SUCCESS(rv, rv); - - mElementContext.forget(); - mElementContext = context; - - return NS_OK; -} - -nsresult -txStylesheetCompiler::maybeDoneCompiling() -{ - if (!mDoneWithThisStylesheet || mChildCompilerList.Count()) { - return NS_OK; - } - - if (mIsTopCompiler) { - nsresult rv = mStylesheet->doneCompiling(); - if (NS_FAILED(rv)) { - cancel(rv); - return rv; - } - } - - if (mObserver) { - mObserver->onDoneCompiling(this, mStatus); - // This will ensure that we don't call onDoneCompiling twice. Also - // ensures that we don't keep the observer alive longer then necessary. - mObserver = nsnull; - } - - return NS_OK; -} - -/** - * txStylesheetCompilerState - */ - - -txStylesheetCompilerState::txStylesheetCompilerState(txACompileObserver* aObserver) - : mHandlerTable(nsnull), - mSorter(nsnull), - mDOE(PR_FALSE), - mSearchingForFallback(PR_FALSE), - mObserver(aObserver), - mEmbedStatus(eNoEmbed), - mDoneWithThisStylesheet(PR_FALSE), - mNextInstrPtr(nsnull), - mToplevelIterator(nsnull) -{ - // Embedded stylesheets have another handler, which is set in - // txStylesheetCompiler::init if the baseURI has a fragment identifier. - mHandlerTable = gTxRootHandler; - -} - -nsresult -txStylesheetCompilerState::init(const nsAString& aBaseURI, - txStylesheet* aStylesheet, - txListIterator* aInsertPosition) -{ - NS_ASSERTION(!aStylesheet || aInsertPosition, - "must provide insertposition if loading subsheet"); - mURI = aBaseURI; - // Check for fragment identifier of an embedded stylesheet. - PRInt32 fragment = aBaseURI.FindChar('#') + 1; - if (fragment > 0) { - PRInt32 fragmentLength = aBaseURI.Length() - fragment; - if (fragmentLength > 0) { - // This is really an embedded stylesheet, not just a - // "url#". We may want to unescape the fragment. - mTarget = Substring(aBaseURI, (PRUint32)fragment, - fragmentLength); - mEmbedStatus = eNeedEmbed; - mHandlerTable = gTxEmbedHandler; - } - } - nsresult rv = NS_OK; - if (aStylesheet) { - mStylesheet = aStylesheet; - mToplevelIterator = *aInsertPosition; - mIsTopCompiler = PR_FALSE; - } - else { - mStylesheet = new txStylesheet; - NS_ENSURE_TRUE(mStylesheet, NS_ERROR_OUT_OF_MEMORY); - - rv = mStylesheet->init(); - NS_ENSURE_SUCCESS(rv, rv); - - mToplevelIterator = - txListIterator(&mStylesheet->mRootFrame->mToplevelItems); - mToplevelIterator.next(); // go to the end of the list - mIsTopCompiler = PR_TRUE; - } - - mElementContext = new txElementContext(aBaseURI); - NS_ENSURE_TRUE(mElementContext && mElementContext->mMappings, - NS_ERROR_OUT_OF_MEMORY); - - // Push the "old" txElementContext - rv = pushObject(0); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - - -txStylesheetCompilerState::~txStylesheetCompilerState() -{ - while (!mObjectStack.isEmpty()) { - delete popObject(); - } - - PRInt32 i; - for (i = mInScopeVariables.Count() - 1; i >= 0; --i) { - delete NS_STATIC_CAST(txInScopeVariable*, mInScopeVariables[i]); - } -} - -nsresult -txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable) -{ - nsresult rv = pushPtr(mHandlerTable); - NS_ENSURE_SUCCESS(rv, rv); - - mHandlerTable = aTable; - - return NS_OK; -} - -void -txStylesheetCompilerState::popHandlerTable() -{ - mHandlerTable = NS_STATIC_CAST(txHandlerTable*, popPtr()); -} - -nsresult -txStylesheetCompilerState::pushSorter(txPushNewContext* aSorter) -{ - nsresult rv = pushPtr(mSorter); - NS_ENSURE_SUCCESS(rv, rv); - - mSorter = aSorter; - - return NS_OK; -} - -void -txStylesheetCompilerState::popSorter() -{ - mSorter = NS_STATIC_CAST(txPushNewContext*, popPtr()); -} - -nsresult -txStylesheetCompilerState::pushChooseGotoList() -{ - nsresult rv = pushObject(mChooseGotoList); - NS_ENSURE_SUCCESS(rv, rv); - - mChooseGotoList.forget(); - mChooseGotoList = new txList; - NS_ENSURE_TRUE(mChooseGotoList, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; -} - -void -txStylesheetCompilerState::popChooseGotoList() -{ - // this will delete the old value - mChooseGotoList = NS_STATIC_CAST(txList*, popObject()); -} - -nsresult -txStylesheetCompilerState::pushObject(TxObject* aObject) -{ - return mObjectStack.push(aObject); -} - -TxObject* -txStylesheetCompilerState::popObject() -{ - return NS_STATIC_CAST(TxObject*, mObjectStack.pop()); -} - -nsresult -txStylesheetCompilerState::pushPtr(void* aPtr) -{ -#ifdef TX_DEBUG_STACK - PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("pushPtr: %d\n", aPtr)); -#endif - return mOtherStack.push(aPtr); -} - -void* -txStylesheetCompilerState::popPtr() -{ - void* value = mOtherStack.pop(); -#ifdef TX_DEBUG_STACK - PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("popPtr: %d\n", value)); -#endif - return value; -} - -nsresult -txStylesheetCompilerState::addToplevelItem(txToplevelItem* aItem) -{ - return mToplevelIterator.addBefore(aItem); -} - -nsresult -txStylesheetCompilerState::openInstructionContainer(txInstructionContainer* aContainer) -{ - NS_PRECONDITION(!mNextInstrPtr, "can't nest instruction-containers"); - - mNextInstrPtr = aContainer->mFirstInstruction.StartAssignment(); - return NS_OK; -} - -void -txStylesheetCompilerState::closeInstructionContainer() -{ - NS_ASSERTION(mGotoTargetPointers.Count() == 0, - "GotoTargets still exists, did you forget to add txReturn?"); - mNextInstrPtr = 0; -} - -nsresult -txStylesheetCompilerState::addInstruction(nsAutoPtr aInstruction) -{ - NS_PRECONDITION(mNextInstrPtr, "adding instruction outside container"); - - txInstruction* newInstr = aInstruction; - - *mNextInstrPtr = aInstruction.forget(); - mNextInstrPtr = &newInstr->mNext; - - PRInt32 i, count = mGotoTargetPointers.Count(); - for (i = 0; i < count; ++i) { - *NS_STATIC_CAST(txInstruction**, mGotoTargetPointers[i]) = newInstr; - } - mGotoTargetPointers.Clear(); - - return NS_OK; -} - -nsresult -txStylesheetCompilerState::loadIncludedStylesheet(const nsAString& aURI) -{ - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("CompilerState::loadIncludedStylesheet: %s\n", - NS_LossyConvertUCS2toASCII(aURI).get())); - if (mURI.Equals(aURI)) { - return NS_ERROR_XSLT_LOAD_RECURSION; - } - NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED); - - nsAutoPtr item(new txDummyItem); - NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv = mToplevelIterator.addBefore(item); - NS_ENSURE_SUCCESS(rv, rv); - - item.forget(); - - // step back to the dummy-item - mToplevelIterator.previous(); - - txACompileObserver* observer = NS_STATIC_CAST(txStylesheetCompiler*, this); - - nsRefPtr compiler = - new txStylesheetCompiler(aURI, mStylesheet, &mToplevelIterator, - observer); - NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY); - - // step forward before calling the observer in case of syncronous loading - mToplevelIterator.next(); - - if (!mChildCompilerList.AppendElement(compiler)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = mObserver->loadURI(aURI, mURI, compiler); - if (NS_FAILED(rv)) { - mChildCompilerList.RemoveElement(compiler); - } - - return rv; -} - -nsresult -txStylesheetCompilerState::loadImportedStylesheet(const nsAString& aURI, - txStylesheet::ImportFrame* aFrame) -{ - PR_LOG(txLog::xslt, PR_LOG_ALWAYS, - ("CompilerState::loadImportedStylesheet: %s\n", - NS_LossyConvertUCS2toASCII(aURI).get())); - if (mURI.Equals(aURI)) { - return NS_ERROR_XSLT_LOAD_RECURSION; - } - NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED); - - txListIterator iter(&aFrame->mToplevelItems); - iter.next(); // go to the end of the list - - txACompileObserver* observer = NS_STATIC_CAST(txStylesheetCompiler*, this); - - nsRefPtr compiler = - new txStylesheetCompiler(aURI, mStylesheet, &iter, observer); - NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY); - - if (!mChildCompilerList.AppendElement(compiler)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsresult rv = mObserver->loadURI(aURI, mURI, compiler); - if (NS_FAILED(rv)) { - mChildCompilerList.RemoveElement(compiler); - } - - return rv; -} - -nsresult -txStylesheetCompilerState::addGotoTarget(txInstruction** aTargetPointer) -{ - if (!mGotoTargetPointers.AppendElement(aTargetPointer)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -nsresult -txStylesheetCompilerState::addVariable(const txExpandedName& aName) -{ - txInScopeVariable* var = new txInScopeVariable(aName); - NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY); - - if (!mInScopeVariables.AppendElement(var)) { - delete var; - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -nsresult -txStylesheetCompilerState::resolveNamespacePrefix(nsIAtom* aPrefix, - PRInt32& aID) -{ - NS_ASSERTION(aPrefix && aPrefix != txXMLAtoms::_empty, - "caller should handle default namespace ''"); - aID = mElementContext->mMappings->lookupNamespace(aPrefix); - return (aID != kNameSpaceID_Unknown) ? NS_OK : NS_ERROR_FAILURE; -} - -/** - * Error Function to be used for unknown extension functions. - * - */ -class txErrorFunctionCall : public FunctionCall -{ -public: - txErrorFunctionCall(nsIAtom* aName, const PRInt32 aID) - : mName(aName), - mID(aID) - { - } - - TX_DECL_FUNCTION; - -private: - nsCOMPtr mName; - PRInt32 mID; -}; - -nsresult -txErrorFunctionCall::evaluate(txIEvalContext* aContext, - txAExprResult** aResult) -{ - *aResult = nsnull; - - return NS_ERROR_XPATH_BAD_EXTENSION_FUNCTION; -} - -#ifdef TX_TO_STRING -nsresult -txErrorFunctionCall::getNameAtom(nsIAtom** aAtom) -{ - NS_IF_ADDREF(*aAtom = mName); - - return NS_OK; -} -#endif - -nsresult -txStylesheetCompilerState::resolveFunctionCall(nsIAtom* aName, PRInt32 aID, - FunctionCall*& aFunction) -{ - aFunction = nsnull; - - if (aID == kNameSpaceID_None) { - if (aName == txXSLTAtoms::document) { - aFunction = new DocumentFunctionCall(mElementContext->mBaseURI); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::key) { - aFunction = new txKeyFunctionCall(mElementContext->mMappings); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::formatNumber) { - aFunction = new txFormatNumberFunctionCall(mStylesheet, - mElementContext->mMappings); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::current) { - aFunction = new CurrentFunctionCall(); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::unparsedEntityUri) { - - return NS_ERROR_NOT_IMPLEMENTED; - } - if (aName == txXSLTAtoms::generateId) { - aFunction = new GenerateIdFunctionCall(); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::systemProperty) { - aFunction = new SystemPropertyFunctionCall(mElementContext->mMappings); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::elementAvailable) { - aFunction = - new ElementAvailableFunctionCall(mElementContext->mMappings); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (aName == txXSLTAtoms::functionAvailable) { - aFunction = - new FunctionAvailableFunctionCall(mElementContext->mMappings); - NS_ENSURE_TRUE(aFunction, NS_ERROR_OUT_OF_MEMORY); - - return NS_OK; - } - if (!fcp()) { - return NS_ERROR_XPATH_UNKNOWN_FUNCTION; - } - } - - aFunction = new txErrorFunctionCall(aName, aID); - - return aFunction ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -PRBool -txStylesheetCompilerState::caseInsensitiveNameTests() -{ - return PR_FALSE; -} - -void -txStylesheetCompilerState::SetErrorOffset(PRUint32 aOffset) -{ - // XXX implement me -} - -txElementContext::txElementContext(const nsAString& aBaseURI) - : mPreserveWhitespace(PR_FALSE), - mForwardsCompatibleParsing(PR_TRUE), - mBaseURI(aBaseURI), - mMappings(new txNamespaceMap), - mDepth(0) -{ - mInstructionNamespaces.AppendElement(NS_INT32_TO_PTR(kNameSpaceID_XSLT)); -} - -txElementContext::txElementContext(const txElementContext& aOther) - : mPreserveWhitespace(aOther.mPreserveWhitespace), - mForwardsCompatibleParsing(aOther.mForwardsCompatibleParsing), - mBaseURI(aOther.mBaseURI), - mMappings(aOther.mMappings), - mDepth(0) -{ - mInstructionNamespaces = aOther.mInstructionNamespaces; -} diff --git a/extensions/transformiix/source/xslt/txStylesheetCompiler.h b/extensions/transformiix/source/xslt/txStylesheetCompiler.h deleted file mode 100644 index c411095c7b45..000000000000 --- a/extensions/transformiix/source/xslt/txStylesheetCompiler.h +++ /dev/null @@ -1,259 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXSTYLESHEETCOMPILER_H -#define TRANSFRMX_TXSTYLESHEETCOMPILER_H - -#include "txStack.h" -#include "txXSLTPatterns.h" -#include "Expr.h" -#include "txIXPathContext.h" -#include "nsAutoPtr.h" -#include "txStylesheet.h" - -class txHandlerTable; -class txElementContext; -class txInstructionContainer; -class txInstruction; -class txNamespaceMap; -class txToplevelItem; -class txPushNewContext; -class txStylesheetCompiler; - -class txElementContext : public TxObject -{ -public: - txElementContext(const nsAString& aBaseURI); - txElementContext(const txElementContext& aOther); - - PRBool mPreserveWhitespace; - PRBool mForwardsCompatibleParsing; - nsString mBaseURI; - nsRefPtr mMappings; - nsVoidArray mInstructionNamespaces; - PRInt32 mDepth; -}; - -class txACompileObserver -{ -public: - virtual nsrefcnt AddRef() = 0; - virtual nsrefcnt Release() = 0; - - virtual nsresult loadURI(const nsAString& aUri, - const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler) = 0; - virtual void onDoneCompiling(txStylesheetCompiler* aCompiler, - nsresult aResult, - const PRUnichar *aErrorText = nsnull, - const PRUnichar *aParam = nsnull) = 0; -}; - -#define TX_DECL_ACOMPILEOBSERVER \ - nsrefcnt AddRef(); \ - nsrefcnt Release(); \ - nsresult loadURI(const nsAString& aUri, const nsAString& aReferrerUri, \ - txStylesheetCompiler* aCompiler); \ - void onDoneCompiling(txStylesheetCompiler* aCompiler, nsresult aResult, \ - const PRUnichar *aErrorText = nsnull, \ - const PRUnichar *aParam = nsnull) - -class txStylesheetCompilerState : public txIParseContext -{ -public: - txStylesheetCompilerState(txACompileObserver* aObserver); - ~txStylesheetCompilerState(); - - nsresult init(const nsAString& aBaseURI, txStylesheet* aStylesheet, - txListIterator* aInsertPosition); - - // Embedded stylesheets state - PRBool handleEmbeddedSheet() - { - return mEmbedStatus == eInEmbed; - } - void doneEmbedding() - { - mEmbedStatus = eHasEmbed; - } - - // Stack functions - nsresult pushHandlerTable(txHandlerTable* aTable); - void popHandlerTable(); - nsresult pushSorter(txPushNewContext* aSorter); - void popSorter(); - nsresult pushChooseGotoList(); - void popChooseGotoList(); - nsresult pushObject(TxObject* aObject); - TxObject* popObject(); - nsresult pushPtr(void* aPtr); - void* popPtr(); - - // stylesheet functions - nsresult addToplevelItem(txToplevelItem* aItem); - nsresult openInstructionContainer(txInstructionContainer* aContainer); - void closeInstructionContainer(); - nsresult addInstruction(nsAutoPtr aInstruction); - nsresult loadIncludedStylesheet(const nsAString& aURI); - nsresult loadImportedStylesheet(const nsAString& aURI, - txStylesheet::ImportFrame* aFrame); - - // misc - nsresult addGotoTarget(txInstruction** aTargetPointer); - nsresult addVariable(const txExpandedName& aName); - - // txIParseContext - nsresult resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID); - nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID, - FunctionCall*& aFunction); - PRBool caseInsensitiveNameTests(); - - /** - * Should the stylesheet be parsed in forwards compatible parsing mode. - */ - PRBool fcp() - { - return mElementContext->mForwardsCompatibleParsing; - } - - void SetErrorOffset(PRUint32 aOffset); - - - nsRefPtr mStylesheet; - txHandlerTable* mHandlerTable; - nsAutoPtr mElementContext; - txPushNewContext* mSorter; - nsAutoPtr mChooseGotoList; - PRPackedBool mDOE; - PRPackedBool mSearchingForFallback; - -protected: - nsRefPtr mObserver; - nsVoidArray mInScopeVariables; - nsVoidArray mChildCompilerList; - // embed info, target information is the ID - nsString mTarget; - enum - { - eNoEmbed, - eNeedEmbed, - eInEmbed, - eHasEmbed - } mEmbedStatus; - nsString mURI; - PRPackedBool mIsTopCompiler; - PRPackedBool mDoneWithThisStylesheet; - -private: - txStack mObjectStack; - txStack mOtherStack; - txInstruction** mNextInstrPtr; - txListIterator mToplevelIterator; - nsVoidArray mGotoTargetPointers; -}; - -struct txStylesheetAttr -{ - PRInt32 mNamespaceID; - nsCOMPtr mLocalName; - nsCOMPtr mPrefix; - nsString mValue; -}; - -class txStylesheetCompiler : private txStylesheetCompilerState, - public txACompileObserver -{ -public: - friend class txStylesheetCompilerState; - txStylesheetCompiler(const nsAString& aBaseURI, - txACompileObserver* aObserver); - txStylesheetCompiler(const nsAString& aBaseURI, - txStylesheet* aStylesheet, - txListIterator* aInsertPosition, - txACompileObserver* aObserver); - virtual nsrefcnt AddRef(); - virtual nsrefcnt Release(); - - nsresult startElement(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix, txStylesheetAttr* aAttributes, - PRInt32 aAttrCount); - nsresult startElement(const PRUnichar *aName, - const PRUnichar **aAtts, - PRInt32 aAttrCount, PRInt32 aIDOffset); - nsresult endElement(); - nsresult characters(const nsAString& aStr); - nsresult doneLoading(); - - void cancel(nsresult aError, const PRUnichar *aErrorText = nsnull, - const PRUnichar *aParam = nsnull); - - txStylesheet* getStylesheet(); - - // txACompileObserver - nsresult loadURI(const nsAString& aUri, const nsAString& aReferrerUri, - txStylesheetCompiler* aCompiler); - void onDoneCompiling(txStylesheetCompiler* aCompiler, nsresult aResult, - const PRUnichar *aErrorText = nsnull, - const PRUnichar *aParam = nsnull); - -private: - nsresult startElementInternal(PRInt32 aNamespaceID, nsIAtom* aLocalName, - nsIAtom* aPrefix, - txStylesheetAttr* aAttributes, - PRInt32 aAttrCount, - PRInt32 aIDOffset = -1); - - nsresult flushCharacters(); - nsresult ensureNewElementContext(); - nsresult maybeDoneCompiling(); - - nsAutoRefCnt mRefCnt; - nsString mCharacters; - nsresult mStatus; -}; - -class txInScopeVariable { -public: - txInScopeVariable(const txExpandedName& aName) : mName(aName), mLevel(1) - { - } - txExpandedName mName; - PRInt32 mLevel; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txTextHandler.cpp b/extensions/transformiix/source/xslt/txTextHandler.cpp deleted file mode 100644 index 2024d17dad91..000000000000 --- a/extensions/transformiix/source/xslt/txTextHandler.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txTextHandler.h" -#include "nsAString.h" - -txTextHandler::txTextHandler(MBool aOnlyText) : mLevel(0), - mOnlyText(aOnlyText) -{ -} - -txTextHandler::~txTextHandler() -{ -} - -void txTextHandler::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ -} - -void txTextHandler::characters(const nsAString& aData, PRBool aDOE) -{ - if (mLevel == 0) - mValue.Append(aData); -} - -void txTextHandler::comment(const nsAString& aData) -{ -} - -void txTextHandler::endDocument(nsresult aResult) -{ -} - -void txTextHandler::endElement(const nsAString& aName, - const PRInt32 aNsID) -{ - if (mOnlyText) - --mLevel; -} - -void txTextHandler::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ -} - -void txTextHandler::startDocument() -{ -} - -void txTextHandler::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ - if (mOnlyText) - ++mLevel; -} diff --git a/extensions/transformiix/source/xslt/txTextHandler.h b/extensions/transformiix/source/xslt/txTextHandler.h deleted file mode 100644 index 4ed87f891f76..000000000000 --- a/extensions/transformiix/source/xslt/txTextHandler.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TEXT_HANDLER_H -#define TRANSFRMX_TEXT_HANDLER_H - -#include "txXMLEventHandler.h" -#include "nsString.h" - -class txTextHandler : public txAXMLEventHandler -{ -public: - txTextHandler(MBool aOnlyText); - virtual ~txTextHandler(); - - TX_DECL_TXAXMLEVENTHANDLER - - nsString mValue; - -private: - PRUint32 mLevel; - MBool mOnlyText; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txTextOutput.cpp b/extensions/transformiix/source/xslt/txTextOutput.cpp deleted file mode 100644 index 543d016f6843..000000000000 --- a/extensions/transformiix/source/xslt/txTextOutput.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txTextOutput.h" -#include "nsString.h" - -txTextOutput::txTextOutput(ostream* aOut) - : mOut(aOut) -{ -} - -txTextOutput::~txTextOutput() -{ -} - -void txTextOutput::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ -} - -void txTextOutput::characters(const nsAString& aData, PRBool aDOE) -{ - *mOut << NS_ConvertUCS2toUTF8(aData).get(); -} - -void txTextOutput::comment(const nsAString& aData) -{ -} - -void txTextOutput::endDocument(nsresult aResult) -{ -} - -void txTextOutput::endElement(const nsAString& aName, - const PRInt32 aNsID) -{ -} - -void txTextOutput::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ -} - -void txTextOutput::startDocument() -{ -} - -void txTextOutput::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ -} diff --git a/extensions/transformiix/source/xslt/txTextOutput.h b/extensions/transformiix/source/xslt/txTextOutput.h deleted file mode 100644 index 66e73df3a05c..000000000000 --- a/extensions/transformiix/source/xslt/txTextOutput.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TEXT_OUTPUT_H -#define TRANSFRMX_TEXT_OUTPUT_H - -#include "txXMLEventHandler.h" - -class txTextOutput : public txAOutputXMLEventHandler -{ -public: - txTextOutput(ostream* aOut); - ~txTextOutput(); - - TX_DECL_TXAXMLEVENTHANDLER - TX_DECL_TXAOUTPUTXMLEVENTHANDLER - -private: - ostream* mOut; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txToplevelItems.cpp b/extensions/transformiix/source/xslt/txToplevelItems.cpp deleted file mode 100644 index ba27a7116c6d..000000000000 --- a/extensions/transformiix/source/xslt/txToplevelItems.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txToplevelItems.h" -#include "txStylesheet.h" -#include "txInstructions.h" -#include "txXSLTPatterns.h" - -TX_IMPL_GETTYPE(txAttributeSetItem, txToplevelItem::attributeSet) -TX_IMPL_GETTYPE(txImportItem, txToplevelItem::import) -TX_IMPL_GETTYPE(txOutputItem, txToplevelItem::output) -TX_IMPL_GETTYPE(txDummyItem, txToplevelItem::dummy) - -TX_IMPL_GETTYPE(txStripSpaceItem, txToplevelItem::stripSpace) - -txStripSpaceItem::~txStripSpaceItem() -{ - PRInt32 i, count = mStripSpaceTests.Count(); - for (i = 0; i < count; ++i) { - delete NS_STATIC_CAST(txStripSpaceTest*, mStripSpaceTests[i]); - } -} - -nsresult -txStripSpaceItem::addStripSpaceTest(txStripSpaceTest* aStripSpaceTest) -{ - if (!mStripSpaceTests.AppendElement(aStripSpaceTest)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - -TX_IMPL_GETTYPE(txTemplateItem, txToplevelItem::templ) - -txTemplateItem::txTemplateItem(nsAutoPtr aMatch, - const txExpandedName& aName, - const txExpandedName& aMode, double aPrio) - : mMatch(aMatch), mName(aName), mMode(aMode), mPrio(aPrio) -{ -} - -TX_IMPL_GETTYPE(txVariableItem, txToplevelItem::variable) - -txVariableItem::txVariableItem(const txExpandedName& aName, - nsAutoPtr aValue, - PRBool aIsParam) - : mName(aName), mValue(aValue), mIsParam(aIsParam) -{ -} diff --git a/extensions/transformiix/source/xslt/txToplevelItems.h b/extensions/transformiix/source/xslt/txToplevelItems.h deleted file mode 100644 index 8fedaac1cb33..000000000000 --- a/extensions/transformiix/source/xslt/txToplevelItems.h +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXTOPLEVELITEMS_H -#define TRANSFRMX_TXTOPLEVELITEMS_H - -#include "txError.h" -#include "txOutputFormat.h" -#include "XMLUtils.h" -#include "txStylesheet.h" -#include "txInstructions.h" - -class txPattern; -class Expr; - -class txToplevelItem -{ -public: - virtual ~txToplevelItem() - { - } - - enum type { - attributeSet, - dummy, - import, - //namespaceAlias, - output, - stripSpace, //also used for preserve-space - templ, - variable - }; - - virtual type getType() = 0; -}; - -#define TX_DECL_TOPLEVELITEM virtual type getType(); -#define TX_IMPL_GETTYPE(_class, _type) \ -txToplevelItem::type \ -_class::getType() { return _type;} - -class txInstructionContainer : public txToplevelItem -{ -public: - nsAutoPtr mFirstInstruction; -}; - -// xsl:attribute-set -class txAttributeSetItem : public txInstructionContainer -{ -public: - txAttributeSetItem(const txExpandedName aName) : mName(aName) - { - } - - TX_DECL_TOPLEVELITEM - - txExpandedName mName; -}; - -// xsl:import -class txImportItem : public txToplevelItem -{ -public: - TX_DECL_TOPLEVELITEM - - nsAutoPtr mFrame; -}; - -// xsl:output -class txOutputItem : public txToplevelItem -{ -public: - TX_DECL_TOPLEVELITEM - - txOutputFormat mFormat; -}; - -// insertionpoint for xsl:include -class txDummyItem : public txToplevelItem -{ -public: - TX_DECL_TOPLEVELITEM -}; - -// xsl:strip-space and xsl:preserve-space -class txStripSpaceItem : public txToplevelItem -{ -public: - virtual ~txStripSpaceItem(); - - TX_DECL_TOPLEVELITEM - - nsresult addStripSpaceTest(txStripSpaceTest* aStripSpaceTest); - - nsVoidArray mStripSpaceTests; -}; - -// xsl:template -class txTemplateItem : public txInstructionContainer -{ -public: - txTemplateItem(nsAutoPtr aMatch, const txExpandedName& aName, - const txExpandedName& aMode, double aPrio); - - TX_DECL_TOPLEVELITEM - - nsAutoPtr mMatch; - txExpandedName mName; - txExpandedName mMode; - double mPrio; -}; - -// xsl:variable at top level -class txVariableItem : public txInstructionContainer -{ -public: - txVariableItem(const txExpandedName& aName, nsAutoPtr aValue, - PRBool aIsParam); - - TX_DECL_TOPLEVELITEM - - txExpandedName mName; - nsAutoPtr mValue; - PRBool mIsParam; -}; - -#endif //TRANSFRMX_TXTOPLEVELITEMS_H diff --git a/extensions/transformiix/source/xslt/txUnknownHandler.cpp b/extensions/transformiix/source/xslt/txUnknownHandler.cpp deleted file mode 100644 index fa610c1fc2b2..000000000000 --- a/extensions/transformiix/source/xslt/txUnknownHandler.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txUnknownHandler.h" -#include "txExecutionState.h" -#include "txStringUtils.h" -#include "txStylesheet.h" - -txUnknownHandler::txUnknownHandler(txExecutionState* aEs) - : mEs(aEs) -{ -} - -txUnknownHandler::~txUnknownHandler() -{ -} - -void txUnknownHandler::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ - // If this is called then the stylesheet is trying to add an attribute - // without adding an element first. So we'll just ignore it. - // XXX ErrorReport: Signal this? -} - -void txUnknownHandler::endDocument(nsresult aResult) -{ - if (NS_FAILED(aResult)) { - return; - } - - // This is an unusual case, no output method has been set and we - // didn't create a document element. Switching to XML output mode - // anyway. - - // Make sure that mEs->mResultHandler == this is true, otherwise we'll - // leak mEs->mResultHandler in createHandlerAndFlush and we'll crash on - // the last line (delete this). - NS_ASSERTION(mEs->mResultHandler == this, - "We're leaking mEs->mResultHandler and are going to crash."); - - nsresult rv = createHandlerAndFlush(eXMLOutput, EmptyString(), - kNameSpaceID_None); - if (NS_FAILED(rv)) - return; - - mEs->mResultHandler->endDocument(aResult); - - delete this; -} - -void txUnknownHandler::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ - // Make sure that mEs->mResultHandler == this is true, otherwise we'll - // leak mEs->mResultHandler in createHandlerAndFlush and we may crash - // later on trying to delete this handler again. - NS_ASSERTION(mEs->mResultHandler == this, - "We're leaking mEs->mResultHandler."); - - nsresult rv = NS_OK; - txOutputFormat* format = mEs->mStylesheet->getOutputFormat(); - if (format->mMethod != eMethodNotSet) { - rv = createHandlerAndFlush(format->mMethod, aName, aNsID); - } - else if (aNsID == kNameSpaceID_None && - aName.Equals(NS_LITERAL_STRING("html"), - txCaseInsensitiveStringComparator())) { - rv = createHandlerAndFlush(eHTMLOutput, aName, aNsID); - } - else { - rv = createHandlerAndFlush(eXMLOutput, aName, aNsID); - } - if (NS_FAILED(rv)) - return; - - mEs->mResultHandler->startElement(aName, aNsID); - - delete this; -} - -nsresult txUnknownHandler::createHandlerAndFlush(txOutputMethod aMethod, - const nsAString& aName, - const PRInt32 aNsID) -{ - NS_ENSURE_TRUE(mBuffer, NS_ERROR_NOT_INITIALIZED); - - txOutputFormat format; - format.merge(*mEs->mStylesheet->getOutputFormat()); - format.mMethod = aMethod; - - txAXMLEventHandler *handler = nsnull; - nsresult rv = mEs->mOutputHandlerFactory->createHandlerWith(&format, aName, - aNsID, - &handler); - NS_ENSURE_SUCCESS(rv, rv); - - mEs->mOutputHandler = handler; - mEs->mResultHandler = handler; - - return mBuffer->flushToHandler(handler); -} diff --git a/extensions/transformiix/source/xslt/txUnknownHandler.h b/extensions/transformiix/source/xslt/txUnknownHandler.h deleted file mode 100644 index e300fe5629d7..000000000000 --- a/extensions/transformiix/source/xslt/txUnknownHandler.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef txUnknownHandler_h___ -#define txUnknownHandler_h___ - -#include "txBufferingHandler.h" -#include "txOutputFormat.h" - -class txExecutionState; - -class txUnknownHandler : public txBufferingHandler -{ -public: - txUnknownHandler(txExecutionState* aEs); - virtual ~txUnknownHandler(); - - void attribute(const nsAString& aName, const PRInt32 aNsID, - const nsAString& aValue); - void endDocument(nsresult aResult); - void startElement(const nsAString& aName, const PRInt32 aNsID); - -private: - nsresult createHandlerAndFlush(txOutputMethod aMethod, - const nsAString& aName, - const PRInt32 aNsID); - - /* - * XXX we shouldn't hold to the txExecutionState, as we're supposed - * to live without it. But as a standalone handler, we don't. - * The right fix may need a txOutputFormat here. - */ - txExecutionState* mEs; -}; - -#endif /* txUnknownHandler_h___ */ diff --git a/extensions/transformiix/source/xslt/txVariableMap.h b/extensions/transformiix/source/xslt/txVariableMap.h deleted file mode 100644 index 29964a80a1df..000000000000 --- a/extensions/transformiix/source/xslt/txVariableMap.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_VARIABLEMAP_H -#define TRANSFRMX_VARIABLEMAP_H - -#include "txError.h" -#include "XMLUtils.h" -#include "ExprResult.h" -#include "txExpandedNameMap.h" - -class txVariableMap { -public: - txVariableMap(); - ~txVariableMap(); - - nsresult bindVariable(const txExpandedName& aName, txAExprResult* aValue); - - void getVariable(const txExpandedName& aName, txAExprResult** aResult); - - void removeVariable(const txExpandedName& aName); - -private: - txExpandedNameMap mMap; -}; - - -inline -txVariableMap::txVariableMap() - : mMap(MB_FALSE) -{ -} - -inline -txVariableMap::~txVariableMap() -{ - txExpandedNameMap::iterator iter(mMap); - while (iter.next()) { - txAExprResult* res = NS_STATIC_CAST(txAExprResult*, iter.value()); - NS_RELEASE(res); - } -} - -inline nsresult -txVariableMap::bindVariable(const txExpandedName& aName, txAExprResult* aValue) -{ - NS_ASSERTION(aValue, "can't add null-variables to a txVariableMap"); - nsresult rv = mMap.add(aName, aValue); - if (NS_SUCCEEDED(rv)) { - NS_ADDREF(aValue); - } - return rv; -} - -inline void -txVariableMap::getVariable(const txExpandedName& aName, txAExprResult** aResult) -{ - *aResult = NS_STATIC_CAST(txAExprResult*, mMap.get(aName)); - if (*aResult) { - NS_ADDREF(*aResult); - } -} - -inline void -txVariableMap::removeVariable(const txExpandedName& aName) -{ - txAExprResult* var = NS_STATIC_CAST(txAExprResult*, mMap.remove(aName)); - NS_IF_RELEASE(var); -} - -#endif //TRANSFRMX_VARIABLEMAP_H diff --git a/extensions/transformiix/source/xslt/txXMLEventHandler.h b/extensions/transformiix/source/xslt/txXMLEventHandler.h deleted file mode 100644 index 0877ea4b704c..000000000000 --- a/extensions/transformiix/source/xslt/txXMLEventHandler.h +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Keith Visco. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Keith Visco - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_XML_EVENT_HANDLER_H -#define TRANSFRMX_XML_EVENT_HANDLER_H - -#include "txCore.h" - -class txOutputFormat; - -#ifdef TX_EXE -#include -#else -#define kTXNameSpaceURI "http://www.mozilla.org/TransforMiix" -#define kTXWrapper "transformiix:result" - -class nsIDOMDocument; -#endif - -/** - * An interface for handling XML documents, loosely modeled - * after Dave Megginson's SAX 1.0 API. - */ - -class txAXMLEventHandler -{ -public: - virtual ~txAXMLEventHandler() {}; - - /** - * Signals to receive the start of an attribute. - * - * @param aName the name of the attribute - * @param aNsID the namespace ID of the attribute - * @param aValue the value of the attribute - */ - virtual void attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) = 0; - - /** - * Signals to receive characters. - * - * @param aData the characters to receive - * @param aDOE disable output escaping for these characters - */ - virtual void characters(const nsAString& aData, PRBool aDOE) = 0; - - /** - * Signals to receive data that should be treated as a comment. - * - * @param data the comment data to receive - */ - virtual void comment(const nsAString& aData) = 0; - - /** - * Signals the end of a document. It is an error to call - * this method more than once. - */ - virtual void endDocument(nsresult aResult) = 0; - - /** - * Signals to receive the end of an element. - * - * @param aName the name of the element - * @param aNsID the namespace ID of the element - */ - virtual void endElement(const nsAString& aName, - const PRInt32 aNsID) = 0; - - /** - * Signals to receive a processing instruction. - * - * @param aTarget the target of the processing instruction - * @param aData the data of the processing instruction - */ - virtual void processingInstruction(const nsAString& aTarget, - const nsAString& aData) = 0; - - /** - * Signals the start of a document. - */ - virtual void startDocument() = 0; - - /** - * Signals to receive the start of an element. - * - * @param aName the name of the element - * @param aNsID the namespace ID of the element - */ - virtual void startElement(const nsAString& aName, - const PRInt32 aNsID) = 0; -}; - -#define TX_DECL_TXAXMLEVENTHANDLER \ - virtual void attribute(const nsAString& aName, const PRInt32 aNsID, \ - const nsAString& aValue); \ - virtual void characters(const nsAString& aData, PRBool aDOE); \ - virtual void comment(const nsAString& aData); \ - virtual void endDocument(nsresult aResult = NS_OK); \ - virtual void endElement(const nsAString& aName, const PRInt32 aNsID); \ - virtual void processingInstruction(const nsAString& aTarget, \ - const nsAString& aData); \ - virtual void startDocument(); \ - virtual void startElement(const nsAString& aName, const PRInt32 aNsID); - - -#ifdef TX_EXE -typedef txAXMLEventHandler txAOutputXMLEventHandler; -#define TX_DECL_TXAOUTPUTXMLEVENTHANDLER -#else -class txAOutputXMLEventHandler : public txAXMLEventHandler -{ -public: - /** - * Gets the Mozilla output document - * - * @param aDocument the Mozilla output document - */ - virtual void getOutputDocument(nsIDOMDocument** aDocument) = 0; -}; - -#define TX_DECL_TXAOUTPUTXMLEVENTHANDLER \ - virtual void getOutputDocument(nsIDOMDocument** aDocument); -#endif - -/** - * Interface used to create the appropriate outputhandler - */ -class txAOutputHandlerFactory -{ -public: - virtual ~txAOutputHandlerFactory() {}; - - /** - * Creates an outputhandler for the specified format. - * @param aFromat format to get handler for - * @param aHandler outparam. The created handler - */ - virtual nsresult - createHandlerWith(txOutputFormat* aFormat, - txAXMLEventHandler** aHandler) = 0; - - /** - * Creates an outputhandler for the specified format, with the specified - * name and namespace for the root element. - * @param aFromat format to get handler for - * @param aName name of the root element - * @param aNsID namespace-id of the root element - * @param aHandler outparam. The created handler - */ - virtual nsresult - createHandlerWith(txOutputFormat* aFormat, - const nsAString& aName, - PRInt32 aNsID, - txAXMLEventHandler** aHandler) = 0; -}; - -#define TX_DECL_TXAOUTPUTHANDLERFACTORY \ - nsresult createHandlerWith(txOutputFormat* aFormat, \ - txAXMLEventHandler** aHandler); \ - nsresult createHandlerWith(txOutputFormat* aFormat, \ - const nsAString& aName, \ - PRInt32 aNsID, \ - txAXMLEventHandler** aHandler); - -#endif diff --git a/extensions/transformiix/source/xslt/txXMLOutput.cpp b/extensions/transformiix/source/xslt/txXMLOutput.cpp deleted file mode 100644 index c4baf685ae6b..000000000000 --- a/extensions/transformiix/source/xslt/txXMLOutput.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXMLOutput.h" - -const int txXMLOutput::DEFAULT_INDENT = 2; - -txOutAttr::txOutAttr(PRInt32 aNsID, nsIAtom* aLocalName, - const nsAString& aValue) : - mName(aNsID, aLocalName), - mValue(aValue), - mShorthand(MB_FALSE) -{ -} - -txXMLOutput::txXMLOutput(txOutputFormat* aFormat, ostream* aOut) - : mOut(aOut), - mUseEmptyElementShorthand(MB_TRUE), - mHaveDocumentElement(MB_FALSE), - mStartTagOpen(MB_FALSE), - mAfterEndTag(MB_FALSE), - mInCDATASection(MB_FALSE), - mIndentLevel(0) -{ - mOutputFormat.merge(*aFormat); - mOutputFormat.setFromDefaults(); -} - -txXMLOutput::~txXMLOutput() -{ -} - -void txXMLOutput::attribute(const nsAString& aName, - const PRInt32 aNsID, - const nsAString& aValue) -{ - if (!mStartTagOpen) - // XXX Signal this? (can't add attributes after element closed) - return; - - txListIterator iter(&mAttributes); - nsCOMPtr localName = do_GetAtom(XMLUtils::getLocalPart(aName)); - txExpandedName att(aNsID, localName); - - txOutAttr* setAtt = 0; - while ((setAtt = (txOutAttr*)iter.next())) { - if (setAtt->mName == att) { - setAtt->mValue = aValue; - break; - } - } - if (!setAtt) { - setAtt = new txOutAttr(aNsID, localName, aValue); - mAttributes.add(setAtt); - } -} - -void txXMLOutput::characters(const nsAString& aData, PRBool aDOE) -{ - closeStartTag(MB_FALSE); - - if (aDOE) { - printUTF8Chars(aData); - - return; - } - - if (mInCDATASection) { - PRUint32 length = aData.Length(); - - *mOut << CDATA_START; - - if (length <= 3) { - printUTF8Chars(aData); - } - else { - PRUint32 j = 0; - nsAString::const_iterator iter; - aData.BeginReading(iter); - mBuffer[j++] = *(iter++); - mBuffer[j++] = *(iter++); - mBuffer[j++] = *(iter++); - - nsAString::const_iterator end; - aData.EndReading(end); - while (iter != end) { - mBuffer[j++] = *(iter++); - if (mBuffer[(j - 1) % 4] == ']' && - mBuffer[j % 4] == ']' && - mBuffer[(j + 1) % 4] == '>') { - *mOut << CDATA_END; - *mOut << CDATA_START; - } - j = j % 4; - printUTF8Char(mBuffer[j]); - } - - j = ++j % 4; - printUTF8Char(mBuffer[j]); - j = ++j % 4; - printUTF8Char(mBuffer[j]); - j = ++j % 4; - printUTF8Char(mBuffer[j]); - } - - *mOut << CDATA_END; - } - else { - printWithXMLEntities(aData); - } -} - -void txXMLOutput::comment(const nsAString& aData) -{ - closeStartTag(MB_FALSE); - - if (mOutputFormat.mIndent == eTrue) { - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - *mOut << COMMENT_START; - printUTF8Chars(aData); - *mOut << COMMENT_END; - if (mOutputFormat.mIndent == eTrue) - *mOut << endl; -} - -void txXMLOutput::endDocument(nsresult aResult) -{ -} - -void txXMLOutput::endElement(const nsAString& aName, - const PRInt32 aNsID) -{ - MBool newLine = (mOutputFormat.mIndent == eTrue) && mAfterEndTag; - MBool writeEndTag = !(mStartTagOpen && mUseEmptyElementShorthand); - closeStartTag(mUseEmptyElementShorthand); - if (newLine) - *mOut << endl; - if (mOutputFormat.mIndent == eTrue) - mIndentLevel -= DEFAULT_INDENT; - if (writeEndTag) { - if (newLine) { - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - *mOut << L_ANGLE_BRACKET << FORWARD_SLASH; - printUTF8Chars(aName); - *mOut << R_ANGLE_BRACKET; - } - if (mOutputFormat.mIndent == eTrue) - *mOut << endl; - mAfterEndTag = MB_TRUE; - mInCDATASection = (MBool)mCDATASections.pop(); -} - -void txXMLOutput::processingInstruction(const nsAString& aTarget, - const nsAString& aData) -{ - closeStartTag(MB_FALSE); - if (mOutputFormat.mIndent == eTrue) { - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - *mOut << PI_START; - printUTF8Chars(aTarget); - *mOut << SPACE; - printUTF8Chars(aData); - *mOut << PI_END; - if (mOutputFormat.mIndent == eTrue) - *mOut << endl; -} - -void txXMLOutput::startDocument() -{ - if (mOutputFormat.mMethod == eMethodNotSet) { - // XXX We should "cache" content until we have a - // document element - } - *mOut << PI_START << XML_DECL << DOUBLE_QUOTE; - *mOut << XML_VERSION; - *mOut << DOUBLE_QUOTE << " encoding=\"UTF-8\"" << PI_END << endl; -} - -void txXMLOutput::startElement(const nsAString& aName, - const PRInt32 aNsID) -{ - if (!mHaveDocumentElement) { - // XXX Output doc type and "cached" content - mHaveDocumentElement = MB_TRUE; - } - - MBool newLine = mStartTagOpen || mAfterEndTag; - closeStartTag(MB_FALSE); - - if (mOutputFormat.mIndent == eTrue) { - if (newLine) { - *mOut << endl; - for (PRUint32 i = 0; i < mIndentLevel; i++) - *mOut << ' '; - } - } - *mOut << L_ANGLE_BRACKET; - printUTF8Chars(aName); - mStartTagOpen = MB_TRUE; - if (mOutputFormat.mIndent == eTrue) - mIndentLevel += DEFAULT_INDENT; - - mCDATASections.push((void*)mInCDATASection); - mInCDATASection = MB_FALSE; - - nsCOMPtr localName = do_GetAtom(aName); - txExpandedName currentElement(aNsID, localName); - txListIterator iter(&(mOutputFormat.mCDATASectionElements)); - while (iter.hasNext()) { - if (currentElement == *(txExpandedName*)iter.next()) { - mInCDATASection = MB_TRUE; - break; - } - } -} - -void txXMLOutput::closeStartTag(MBool aUseEmptyElementShorthand) -{ - mAfterEndTag = aUseEmptyElementShorthand; - if (mStartTagOpen) { - txListIterator iter(&mAttributes); - txOutAttr* att; - while ((att = (txOutAttr*)iter.next())) { - *mOut << SPACE; - const char* attrVal; - att->mName.mLocalName->GetUTF8String(&attrVal); - *mOut << attrVal; - if (!att->mShorthand) { - *mOut << EQUALS << DOUBLE_QUOTE; - printWithXMLEntities(att->mValue, MB_TRUE); - *mOut << DOUBLE_QUOTE; - } - delete (txOutAttr*)iter.remove(); - } - - if (aUseEmptyElementShorthand) - *mOut << FORWARD_SLASH; - *mOut << R_ANGLE_BRACKET; - mStartTagOpen = MB_FALSE; - } -} - -void txXMLOutput::printUTF8Char(PRUnichar& ch) -{ - // PRUnichar is 16-bits so we only need to cover up to 0xFFFF - - // 0x0000-0x007F - if (ch < 128) { - *mOut << (char)ch; - } - // 0x0080-0x07FF - else if (ch < 2048) { - *mOut << (char) (192+(ch/64)); // 0xC0 + x/64 - *mOut << (char) (128+(ch%64)); // 0x80 + x%64 - } - // 0x800-0xFFFF - else { - *mOut << (char) (224+(ch/4096)); // 0xE0 + x/64^2 - *mOut << (char) (128+((ch/64)%64)); // 0x80 + (x/64)%64 - *mOut << (char) (128+(ch%64)); // 0x80 + x%64 - } -} - -void txXMLOutput::printUTF8Chars(const nsAString& aData) -{ - *mOut << NS_ConvertUCS2toUTF8(aData).get(); -} - -void txXMLOutput::printWithXMLEntities(const nsAString& aData, - MBool aAttribute) -{ - nsAString::const_iterator iter, end; - aData.EndReading(end); - - for (aData.BeginReading(iter); iter != end; ++iter) { - PRUnichar currChar = *iter; - switch (currChar) { - case AMPERSAND: - *mOut << AMP_ENTITY; - break; - case APOSTROPHE: - if (aAttribute) - *mOut << APOS_ENTITY; - else - printUTF8Char(currChar); - break; - case GT: - *mOut << GT_ENTITY; - break; - case LT: - *mOut << LT_ENTITY; - break; - case QUOTE: - if (aAttribute) - *mOut << QUOT_ENTITY; - else - printUTF8Char(currChar); - break; - default: - printUTF8Char(currChar); - break; - } - } - *mOut << flush; -} diff --git a/extensions/transformiix/source/xslt/txXMLOutput.h b/extensions/transformiix/source/xslt/txXMLOutput.h deleted file mode 100644 index 7a514c21237e..000000000000 --- a/extensions/transformiix/source/xslt/txXMLOutput.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_XML_OUTPUT_H -#define TRANSFRMX_XML_OUTPUT_H - -#include "txXMLEventHandler.h" -#include "List.h" -#include "txStack.h" -#include "txOutputFormat.h" -#include "XMLUtils.h" - -#define DASH '-' -#define TX_CR '\r' -#define TX_LF '\n' - -#define AMPERSAND '&' -#define APOSTROPHE '\'' -#define GT '>' -#define LT '<' -#define QUOTE '"' - -#define AMP_ENTITY "&" -#define APOS_ENTITY "'" -#define GT_ENTITY ">" -#define LT_ENTITY "<" -#define QUOT_ENTITY """ -#define HEX_ENTITY "&#" - -#define CDATA_END "]]>" -#define CDATA_START "" -#define DOCTYPE_START "" -#define DOUBLE_QUOTE "\"" -#define EQUALS "=" -#define FORWARD_SLASH "/" -#define L_ANGLE_BRACKET "<" -#define PI_START "" -#define PUBLIC "PUBLIC" -#define R_ANGLE_BRACKET ">" -#define SEMICOLON ";" -#define SPACE " " -#define SYSTEM "SYSTEM" -#define XML_DECL "xml version=" -#define XML_VERSION "1.0" - -class txOutAttr { -public: - txOutAttr(PRInt32 aNsID, nsIAtom* aLocalName, const nsAString& aValue); - txExpandedName mName; - nsString mValue; - MBool mShorthand; -}; - -class txXMLOutput : public txAOutputXMLEventHandler -{ -public: - txXMLOutput(txOutputFormat* aFormat, ostream* aOut); - virtual ~txXMLOutput(); - - static const int DEFAULT_INDENT; - - TX_DECL_TXAXMLEVENTHANDLER - TX_DECL_TXAOUTPUTXMLEVENTHANDLER - -protected: - virtual void closeStartTag(MBool aUseEmptyElementShorthand); - void printUTF8Char(PRUnichar& ch); - void printUTF8Chars(const nsAString& aData); - void printWithXMLEntities(const nsAString& aData, - MBool aAttribute = MB_FALSE); - - ostream* mOut; - txOutputFormat mOutputFormat; - MBool mUseEmptyElementShorthand; - MBool mHaveDocumentElement; - MBool mStartTagOpen; - MBool mAfterEndTag; - MBool mInCDATASection; - PRUint32 mIndentLevel; - txList mAttributes; - txStack mCDATASections; - -private: - PRUnichar mBuffer[4]; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/txXSLTAtomList.h b/extensions/transformiix/source/xslt/txXSLTAtomList.h deleted file mode 100644 index 9b0347726b5b..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTAtomList.h +++ /dev/null @@ -1,151 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// OUTPUT_CLASS=txXSLTAtoms -// MACRO_NAME=TX_ATOM - -// XSLT elements -TX_ATOM(applyImports, "apply-imports") -TX_ATOM(applyTemplates, "apply-templates") -TX_ATOM(attribute, "attribute") -TX_ATOM(attributeSet, "attribute-set") -TX_ATOM(callTemplate, "call-template") -TX_ATOM(choose, "choose") -TX_ATOM(comment, "comment") -TX_ATOM(copy, "copy") -TX_ATOM(copyOf, "copy-of") -TX_ATOM(decimalFormat, "decimal-format") -TX_ATOM(element, "element") -TX_ATOM(fallback, "fallback") -TX_ATOM(forEach, "for-each") -TX_ATOM(_if, "if") -TX_ATOM(import, "import") -TX_ATOM(include, "include") -TX_ATOM(key, "key") -TX_ATOM(message, "message") -TX_ATOM(namespaceAlias, "namespace-alias") -TX_ATOM(number, "number") -TX_ATOM(otherwise, "otherwise") -TX_ATOM(output, "output") -TX_ATOM(param, "param") -TX_ATOM(preserveSpace, "preserve-space") -TX_ATOM(processingInstruction, "processing-instruction") -TX_ATOM(sort, "sort") -TX_ATOM(stripSpace, "strip-space") -TX_ATOM(stylesheet, "stylesheet") -TX_ATOM(_template, "template") -TX_ATOM(text, "text") -TX_ATOM(transform, "transform") -TX_ATOM(valueOf, "value-of") -TX_ATOM(variable, "variable") -TX_ATOM(when, "when") -TX_ATOM(withParam, "with-param") - -// XSLT attributes -TX_ATOM(caseOrder, "case-order") -TX_ATOM(cdataSectionElements, "cdata-section-elements") -TX_ATOM(count, "count") -TX_ATOM(dataType, "data-type") -TX_ATOM(decimalSeparator, "decimal-separator") -TX_ATOM(digit, "digit") -TX_ATOM(disableOutputEscaping, "disable-output-escaping") -TX_ATOM(doctypePublic, "doctype-public") -TX_ATOM(doctypeSystem, "doctype-system") -TX_ATOM(elements, "elements") -TX_ATOM(encoding, "encoding") -TX_ATOM(extensionElementPrefixes, "extension-element-prefixes") -TX_ATOM(format, "format") -TX_ATOM(from, "from") -TX_ATOM(groupingSeparator, "grouping-separator") -TX_ATOM(groupingSize, "grouping-size") -TX_ATOM(href, "href") -TX_ATOM(indent, "indent") -TX_ATOM(infinity, "infinity") -TX_ATOM(lang, "lang") -TX_ATOM(level, "level") -TX_ATOM(match, "match") -TX_ATOM(method, "method") -TX_ATOM(mediaType, "media-type") -TX_ATOM(minusSign, "minus-sign") -TX_ATOM(mode, "mode") -TX_ATOM(name, "name") -TX_ATOM(_namespace, "namespace") -TX_ATOM(NaN, "NaN") -TX_ATOM(omitXmlDeclaration, "omit-xml-declaration") -TX_ATOM(order, "order") -TX_ATOM(patternSeparator, "pattern-separator") -TX_ATOM(perMille, "per-mille") -TX_ATOM(percent, "percent") -TX_ATOM(priority, "priority") -TX_ATOM(select, "select") -TX_ATOM(standalone, "standalone") -TX_ATOM(test, "test") -TX_ATOM(terminate, "terminate") -TX_ATOM(use, "use") -TX_ATOM(useAttributeSets, "use-attribute-sets") -TX_ATOM(value, "value") -TX_ATOM(version, "version") -TX_ATOM(zeroDigit, "zero-digit") - -// XSLT functions -TX_ATOM(current, "current") -TX_ATOM(document, "document") -TX_ATOM(elementAvailable, "element-available") -TX_ATOM(formatNumber, "format-number") -TX_ATOM(functionAvailable, "function-available") -TX_ATOM(generateId, "generate-id") -TX_ATOM(unparsedEntityUri, "unparsed-entity-uri") -TX_ATOM(systemProperty, "system-property") - -// XSLT properties -TX_ATOM(vendor, "vendor") -TX_ATOM(vendorUrl, "vendor-url") - -// XSLT attribute values -TX_ATOM(any, "any") -TX_ATOM(ascending, "ascending") -TX_ATOM(descending, "descending") -TX_ATOM(html, "html") -TX_ATOM(lowerFirst, "lower-first") -TX_ATOM(multiple, "multiple") -TX_ATOM(no, "no") -TX_ATOM(single, "single") -TX_ATOM(upperFirst, "upper-first") -TX_ATOM(xml, "xml") -TX_ATOM(yes, "yes") -TX_ATOM(_poundDefault, "#default") diff --git a/extensions/transformiix/source/xslt/txXSLTNumber.cpp b/extensions/transformiix/source/xslt/txXSLTNumber.cpp deleted file mode 100644 index e8bb5510d626..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTNumber.cpp +++ /dev/null @@ -1,759 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXSLTNumber.h" -#include "txAtoms.h" -#include "txCore.h" -#include -#include "Expr.h" -#include "ExprResult.h" -#include "txXSLTPatterns.h" -#include "txIXPathContext.h" -#include "txXPathTreeWalker.h" - -nsresult txXSLTNumber::createNumber(Expr* aValueExpr, txPattern* aCountPattern, - txPattern* aFromPattern, LevelType aLevel, - Expr* aGroupSize, Expr* aGroupSeparator, - Expr* aFormat, txIEvalContext* aContext, - nsAString& aResult) -{ - aResult.Truncate(); - nsresult rv = NS_OK; - - // Parse format - txList counters; - nsAutoString head, tail; - rv = getCounters(aGroupSize, aGroupSeparator, aFormat, aContext, counters, - head, tail); - NS_ENSURE_SUCCESS(rv, rv); - - // Create list of values to format - txList values; - nsAutoString valueString; - rv = getValueList(aValueExpr, aCountPattern, aFromPattern, aLevel, - aContext, values, valueString); - NS_ENSURE_SUCCESS(rv, rv); - - if (!valueString.IsEmpty()) { - aResult = valueString; - - return NS_OK; - } - - // Create resulting string - aResult = head; - MBool first = MB_TRUE; - txListIterator valueIter(&values); - txListIterator counterIter(&counters); - valueIter.resetToEnd(); - PRInt32 value; - txFormattedCounter* counter = 0; - while ((value = NS_PTR_TO_INT32(valueIter.previous()))) { - if (counterIter.hasNext()) { - counter = (txFormattedCounter*)counterIter.next(); - } - - if (!first) { - aResult.Append(counter->mSeparator); - } - - counter->appendNumber(value, aResult); - first = MB_FALSE; - } - - aResult.Append(tail); - - txListIterator iter(&counters); - while (iter.hasNext()) { - delete (txFormattedCounter*)iter.next(); - } - - return NS_OK; -} - -nsresult -txXSLTNumber::getValueList(Expr* aValueExpr, txPattern* aCountPattern, - txPattern* aFromPattern, LevelType aLevel, - txIEvalContext* aContext, txList& aValues, - nsAString& aValueString) -{ - aValueString.Truncate(); - nsresult rv = NS_OK; - - // If the value attribute exists then use that - if (aValueExpr) { - nsRefPtr result; - rv = aValueExpr->evaluate(aContext, getter_AddRefs(result)); - NS_ENSURE_SUCCESS(rv, rv); - - double value = result->numberValue(); - - if (Double::isInfinite(value) || Double::isNaN(value) || - value < 0.5) { - Double::toString(value, aValueString); - return NS_OK; - } - - aValues.add(NS_INT32_TO_PTR((PRInt32)floor(value + 0.5))); - return NS_OK; - } - - - // Otherwise use count/from/level - - txPattern* countPattern = aCountPattern; - MBool ownsCountPattern = MB_FALSE; - const txXPathNode& currNode = aContext->getContextNode(); - - // Parse count- and from-attributes - - if (!aCountPattern) { - ownsCountPattern = MB_TRUE; - txNodeTest* nodeTest = 0; - PRUint16 nodeType = txXPathNodeUtils::getNodeType(currNode); - switch (nodeType) { - case txXPathNodeType::ELEMENT_NODE: - { - nsCOMPtr localName = - txXPathNodeUtils::getLocalName(currNode); - PRInt32 namespaceID = txXPathNodeUtils::getNamespaceID(currNode); - nodeTest = new txNameTest(0, localName, namespaceID, - txXPathNodeType::ELEMENT_NODE); - break; - } - case txXPathNodeType::TEXT_NODE: - case txXPathNodeType::CDATA_SECTION_NODE: - { - nodeTest = new txNodeTypeTest(txNodeTypeTest::TEXT_TYPE); - break; - } - case txXPathNodeType::PROCESSING_INSTRUCTION_NODE: - { - txNodeTypeTest* typeTest; - typeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE); - if (typeTest) { - nsAutoString nodeName; - txXPathNodeUtils::getNodeName(currNode, nodeName); - typeTest->setNodeName(nodeName); - } - nodeTest = typeTest; - break; - } - case txXPathNodeType::COMMENT_NODE: - { - nodeTest = new txNodeTypeTest(txNodeTypeTest::COMMENT_TYPE); - break; - } - case txXPathNodeType::DOCUMENT_NODE: - case txXPathNodeType::ATTRIBUTE_NODE: - default: - { - // this won't match anything as we walk up the tree - // but it's what the spec says to do - nodeTest = new txNameTest(0, txXPathAtoms::_asterix, 0, - nodeType); - break; - } - } - NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY); - - countPattern = new txStepPattern(nodeTest, MB_FALSE); - if (!countPattern) { - // XXX error reporting - delete nodeTest; - return NS_ERROR_OUT_OF_MEMORY; - } - } - - - // Generate list of values depending on the value of the level-attribute - - // level = "single" - if (aLevel == eLevelSingle) { - txXPathTreeWalker walker(currNode); - do { - if (aFromPattern && !walker.isOnNode(currNode) && - aFromPattern->matches(walker.getCurrentPosition(), aContext)) { - break; - } - - if (countPattern->matches(walker.getCurrentPosition(), aContext)) { - aValues.add(NS_INT32_TO_PTR(getSiblingCount(walker, countPattern, - aContext))); - break; - } - - } while (walker.moveToParent()); - - // Spec says to only match ancestors that are decendants of the - // ancestor that matches the from-pattern, so keep going to make - // sure that there is an ancestor that does. - if (aFromPattern && aValues.getLength()) { - PRBool hasParent; - while ((hasParent = walker.moveToParent())) { - if (aFromPattern->matches(walker.getCurrentPosition(), aContext)) { - break; - } - } - - if (!hasParent) { - aValues.clear(); - } - } - } - // level = "multiple" - else if (aLevel == eLevelMultiple) { - // find all ancestor-or-selfs that matches count until... - txXPathTreeWalker walker(currNode); - MBool matchedFrom = MB_FALSE; - do { - if (aFromPattern && !walker.isOnNode(currNode) && - aFromPattern->matches(walker.getCurrentPosition(), aContext)) { - //... we find one that matches from - matchedFrom = MB_TRUE; - break; - } - - if (countPattern->matches(walker.getCurrentPosition(), aContext)) { - aValues.add(NS_INT32_TO_PTR(getSiblingCount(walker, countPattern, - aContext))); - } - } while (walker.moveToParent()); - - // Spec says to only match ancestors that are decendants of the - // ancestor that matches the from-pattern, so if none did then - // we shouldn't search anything - if (aFromPattern && !matchedFrom) { - aValues.clear(); - } - } - // level = "any" - else if (aLevel == eLevelAny) { - PRInt32 value = 0; - MBool matchedFrom = MB_FALSE; - - txXPathTreeWalker walker(currNode); - do { - if (aFromPattern && !walker.isOnNode(currNode) && - aFromPattern->matches(walker.getCurrentPosition(), aContext)) { - matchedFrom = MB_TRUE; - break; - } - - if (countPattern->matches(walker.getCurrentPosition(), aContext)) { - ++value; - } - - } while (getPrevInDocumentOrder(walker)); - - // Spec says to only count nodes that follows the first node that - // matches the from pattern. So so if none did then we shouldn't - // count any - if (aFromPattern && !matchedFrom) { - value = 0; - } - - if (value) { - aValues.add(NS_INT32_TO_PTR(value)); - } - } - - if (ownsCountPattern) { - delete countPattern; - } - - return NS_OK; -} - - -nsresult -txXSLTNumber::getCounters(Expr* aGroupSize, Expr* aGroupSeparator, - Expr* aFormat, txIEvalContext* aContext, - txList& aCounters, nsAString& aHead, - nsAString& aTail) -{ - aHead.Truncate(); - aTail.Truncate(); - - nsresult rv = NS_OK; - - nsAutoString groupSeparator; - PRInt32 groupSize = 0; - if (aGroupSize && aGroupSeparator) { - nsRefPtr exprRes; - rv = aGroupSize->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString sizeStr; - exprRes->stringValue(sizeStr); - - double size = Double::toDouble(sizeStr); - groupSize = (PRInt32)size; - if ((double)groupSize != size) { - groupSize = 0; - } - - rv = aGroupSeparator->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - exprRes->stringValue(groupSeparator); - } - - nsAutoString format; - if (aFormat) { - nsRefPtr formatRes; - rv = aFormat->evaluate(aContext, getter_AddRefs(formatRes)); - NS_ENSURE_SUCCESS(rv, rv); - - formatRes->stringValue(format); - } - PRUint32 formatLen = format.Length(); - PRUint32 formatPos = 0; - PRUnichar ch = 0; - - // start with header - while (formatPos < formatLen && - !isAlphaNumeric(ch = format.CharAt(formatPos))) { - aHead.Append(ch); - ++formatPos; - } - - // If there are no formatting tokens we need to create a default one. - if (formatPos == formatLen) { - txFormattedCounter* defaultCounter; - rv = txFormattedCounter::getCounterFor(NS_LITERAL_STRING("1"), groupSize, - groupSeparator, defaultCounter); - NS_ENSURE_SUCCESS(rv, rv); - - defaultCounter->mSeparator.AssignLiteral("."); - rv = aCounters.add(defaultCounter); - if (NS_FAILED(rv)) { - // XXX ErrorReport: out of memory - delete defaultCounter; - return rv; - } - - return NS_OK; - } - - while (formatPos < formatLen) { - nsAutoString sepToken; - // parse separator token - if (!aCounters.getLength()) { - // Set the first counters separator to default value so that if - // there is only one formatting token and we're formatting a - // value-list longer then one we use the default separator. This - // won't be used when formatting the first value anyway. - sepToken.AssignLiteral("."); - } - else { - while (formatPos < formatLen && - !isAlphaNumeric(ch = format.CharAt(formatPos))) { - sepToken.Append(ch); - ++formatPos; - } - } - - // if we're at the end of the string then the previous token was the tail - if (formatPos == formatLen) { - aTail = sepToken; - return NS_OK; - } - - // parse formatting token - nsAutoString numToken; - while (formatPos < formatLen && - isAlphaNumeric(ch = format.CharAt(formatPos))) { - numToken.Append(ch); - ++formatPos; - } - - txFormattedCounter* counter = 0; - rv = txFormattedCounter::getCounterFor(numToken, groupSize, - groupSeparator, counter); - if (NS_FAILED(rv)) { - txListIterator iter(&aCounters); - while (iter.hasNext()) { - delete (txFormattedCounter*)iter.next(); - } - aCounters.clear(); - return rv; - } - - // Add to list of counters - counter->mSeparator = sepToken; - rv = aCounters.add(counter); - if (NS_FAILED(rv)) { - // XXX ErrorReport: out of memory - txListIterator iter(&aCounters); - while (iter.hasNext()) { - delete (txFormattedCounter*)iter.next(); - } - aCounters.clear(); - return rv; - } - } - - return NS_OK; -} - -PRInt32 -txXSLTNumber::getSiblingCount(txXPathTreeWalker& aWalker, - txPattern* aCountPattern, - txIMatchContext* aContext) -{ - PRInt32 value = 1; - while (aWalker.moveToPreviousSibling()) { - if (aCountPattern->matches(aWalker.getCurrentPosition(), aContext)) { - ++value; - } - } - return value; -} - -PRBool -txXSLTNumber::getPrevInDocumentOrder(txXPathTreeWalker& aWalker) -{ - if (aWalker.moveToPreviousSibling()) { - while (aWalker.moveToLastChild()) { - // do nothing - } - return PR_TRUE; - } - return aWalker.moveToParent(); -} - -#define TX_CHAR_RANGE(ch, a, b) if (ch < a) return MB_FALSE; \ - if (ch <= b) return MB_TRUE -#define TX_MATCH_CHAR(ch, a) if (ch < a) return MB_FALSE; \ - if (ch == a) return MB_TRUE - -MBool txXSLTNumber::isAlphaNumeric(PRUnichar ch) -{ - TX_CHAR_RANGE(ch, 0x0030, 0x0039); - TX_CHAR_RANGE(ch, 0x0041, 0x005A); - TX_CHAR_RANGE(ch, 0x0061, 0x007A); - TX_MATCH_CHAR(ch, 0x00AA); - TX_CHAR_RANGE(ch, 0x00B2, 0x00B3); - TX_MATCH_CHAR(ch, 0x00B5); - TX_CHAR_RANGE(ch, 0x00B9, 0x00BA); - TX_CHAR_RANGE(ch, 0x00BC, 0x00BE); - TX_CHAR_RANGE(ch, 0x00C0, 0x00D6); - TX_CHAR_RANGE(ch, 0x00D8, 0x00F6); - TX_CHAR_RANGE(ch, 0x00F8, 0x021F); - TX_CHAR_RANGE(ch, 0x0222, 0x0233); - TX_CHAR_RANGE(ch, 0x0250, 0x02AD); - TX_CHAR_RANGE(ch, 0x02B0, 0x02B8); - TX_CHAR_RANGE(ch, 0x02BB, 0x02C1); - TX_CHAR_RANGE(ch, 0x02D0, 0x02D1); - TX_CHAR_RANGE(ch, 0x02E0, 0x02E4); - TX_MATCH_CHAR(ch, 0x02EE); - TX_MATCH_CHAR(ch, 0x037A); - TX_MATCH_CHAR(ch, 0x0386); - TX_CHAR_RANGE(ch, 0x0388, 0x038A); - TX_MATCH_CHAR(ch, 0x038C); - TX_CHAR_RANGE(ch, 0x038E, 0x03A1); - TX_CHAR_RANGE(ch, 0x03A3, 0x03CE); - TX_CHAR_RANGE(ch, 0x03D0, 0x03D7); - TX_CHAR_RANGE(ch, 0x03DA, 0x03F3); - TX_CHAR_RANGE(ch, 0x0400, 0x0481); - TX_CHAR_RANGE(ch, 0x048C, 0x04C4); - TX_CHAR_RANGE(ch, 0x04C7, 0x04C8); - TX_CHAR_RANGE(ch, 0x04CB, 0x04CC); - TX_CHAR_RANGE(ch, 0x04D0, 0x04F5); - TX_CHAR_RANGE(ch, 0x04F8, 0x04F9); - TX_CHAR_RANGE(ch, 0x0531, 0x0556); - TX_MATCH_CHAR(ch, 0x0559); - TX_CHAR_RANGE(ch, 0x0561, 0x0587); - TX_CHAR_RANGE(ch, 0x05D0, 0x05EA); - TX_CHAR_RANGE(ch, 0x05F0, 0x05F2); - TX_CHAR_RANGE(ch, 0x0621, 0x063A); - TX_CHAR_RANGE(ch, 0x0640, 0x064A); - TX_CHAR_RANGE(ch, 0x0660, 0x0669); - TX_CHAR_RANGE(ch, 0x0671, 0x06D3); - TX_MATCH_CHAR(ch, 0x06D5); - TX_CHAR_RANGE(ch, 0x06E5, 0x06E6); - TX_CHAR_RANGE(ch, 0x06F0, 0x06FC); - TX_MATCH_CHAR(ch, 0x0710); - TX_CHAR_RANGE(ch, 0x0712, 0x072C); - TX_CHAR_RANGE(ch, 0x0780, 0x07A5); - TX_CHAR_RANGE(ch, 0x0905, 0x0939); - TX_MATCH_CHAR(ch, 0x093D); - TX_MATCH_CHAR(ch, 0x0950); - TX_CHAR_RANGE(ch, 0x0958, 0x0961); - TX_CHAR_RANGE(ch, 0x0966, 0x096F); - TX_CHAR_RANGE(ch, 0x0985, 0x098C); - TX_CHAR_RANGE(ch, 0x098F, 0x0990); - TX_CHAR_RANGE(ch, 0x0993, 0x09A8); - TX_CHAR_RANGE(ch, 0x09AA, 0x09B0); - TX_MATCH_CHAR(ch, 0x09B2); - TX_CHAR_RANGE(ch, 0x09B6, 0x09B9); - TX_CHAR_RANGE(ch, 0x09DC, 0x09DD); - TX_CHAR_RANGE(ch, 0x09DF, 0x09E1); - TX_CHAR_RANGE(ch, 0x09E6, 0x09F1); - TX_CHAR_RANGE(ch, 0x09F4, 0x09F9); - TX_CHAR_RANGE(ch, 0x0A05, 0x0A0A); - TX_CHAR_RANGE(ch, 0x0A0F, 0x0A10); - TX_CHAR_RANGE(ch, 0x0A13, 0x0A28); - TX_CHAR_RANGE(ch, 0x0A2A, 0x0A30); - TX_CHAR_RANGE(ch, 0x0A32, 0x0A33); - TX_CHAR_RANGE(ch, 0x0A35, 0x0A36); - TX_CHAR_RANGE(ch, 0x0A38, 0x0A39); - TX_CHAR_RANGE(ch, 0x0A59, 0x0A5C); - TX_MATCH_CHAR(ch, 0x0A5E); - TX_CHAR_RANGE(ch, 0x0A66, 0x0A6F); - TX_CHAR_RANGE(ch, 0x0A72, 0x0A74); - TX_CHAR_RANGE(ch, 0x0A85, 0x0A8B); - TX_MATCH_CHAR(ch, 0x0A8D); - TX_CHAR_RANGE(ch, 0x0A8F, 0x0A91); - TX_CHAR_RANGE(ch, 0x0A93, 0x0AA8); - TX_CHAR_RANGE(ch, 0x0AAA, 0x0AB0); - TX_CHAR_RANGE(ch, 0x0AB2, 0x0AB3); - TX_CHAR_RANGE(ch, 0x0AB5, 0x0AB9); - TX_MATCH_CHAR(ch, 0x0ABD); - TX_MATCH_CHAR(ch, 0x0AD0); - TX_MATCH_CHAR(ch, 0x0AE0); - TX_CHAR_RANGE(ch, 0x0AE6, 0x0AEF); - TX_CHAR_RANGE(ch, 0x0B05, 0x0B0C); - TX_CHAR_RANGE(ch, 0x0B0F, 0x0B10); - TX_CHAR_RANGE(ch, 0x0B13, 0x0B28); - TX_CHAR_RANGE(ch, 0x0B2A, 0x0B30); - TX_CHAR_RANGE(ch, 0x0B32, 0x0B33); - TX_CHAR_RANGE(ch, 0x0B36, 0x0B39); - TX_MATCH_CHAR(ch, 0x0B3D); - TX_CHAR_RANGE(ch, 0x0B5C, 0x0B5D); - TX_CHAR_RANGE(ch, 0x0B5F, 0x0B61); - TX_CHAR_RANGE(ch, 0x0B66, 0x0B6F); - TX_CHAR_RANGE(ch, 0x0B85, 0x0B8A); - TX_CHAR_RANGE(ch, 0x0B8E, 0x0B90); - TX_CHAR_RANGE(ch, 0x0B92, 0x0B95); - TX_CHAR_RANGE(ch, 0x0B99, 0x0B9A); - TX_MATCH_CHAR(ch, 0x0B9C); - TX_CHAR_RANGE(ch, 0x0B9E, 0x0B9F); - TX_CHAR_RANGE(ch, 0x0BA3, 0x0BA4); - TX_CHAR_RANGE(ch, 0x0BA8, 0x0BAA); - TX_CHAR_RANGE(ch, 0x0BAE, 0x0BB5); - TX_CHAR_RANGE(ch, 0x0BB7, 0x0BB9); - TX_CHAR_RANGE(ch, 0x0BE7, 0x0BF2); - TX_CHAR_RANGE(ch, 0x0C05, 0x0C0C); - TX_CHAR_RANGE(ch, 0x0C0E, 0x0C10); - TX_CHAR_RANGE(ch, 0x0C12, 0x0C28); - TX_CHAR_RANGE(ch, 0x0C2A, 0x0C33); - TX_CHAR_RANGE(ch, 0x0C35, 0x0C39); - TX_CHAR_RANGE(ch, 0x0C60, 0x0C61); - TX_CHAR_RANGE(ch, 0x0C66, 0x0C6F); - TX_CHAR_RANGE(ch, 0x0C85, 0x0C8C); - TX_CHAR_RANGE(ch, 0x0C8E, 0x0C90); - TX_CHAR_RANGE(ch, 0x0C92, 0x0CA8); - TX_CHAR_RANGE(ch, 0x0CAA, 0x0CB3); - TX_CHAR_RANGE(ch, 0x0CB5, 0x0CB9); - TX_MATCH_CHAR(ch, 0x0CDE); - TX_CHAR_RANGE(ch, 0x0CE0, 0x0CE1); - TX_CHAR_RANGE(ch, 0x0CE6, 0x0CEF); - TX_CHAR_RANGE(ch, 0x0D05, 0x0D0C); - TX_CHAR_RANGE(ch, 0x0D0E, 0x0D10); - TX_CHAR_RANGE(ch, 0x0D12, 0x0D28); - TX_CHAR_RANGE(ch, 0x0D2A, 0x0D39); - TX_CHAR_RANGE(ch, 0x0D60, 0x0D61); - TX_CHAR_RANGE(ch, 0x0D66, 0x0D6F); - TX_CHAR_RANGE(ch, 0x0D85, 0x0D96); - TX_CHAR_RANGE(ch, 0x0D9A, 0x0DB1); - TX_CHAR_RANGE(ch, 0x0DB3, 0x0DBB); - TX_MATCH_CHAR(ch, 0x0DBD); - TX_CHAR_RANGE(ch, 0x0DC0, 0x0DC6); - TX_CHAR_RANGE(ch, 0x0E01, 0x0E30); - TX_CHAR_RANGE(ch, 0x0E32, 0x0E33); - TX_CHAR_RANGE(ch, 0x0E40, 0x0E46); - TX_CHAR_RANGE(ch, 0x0E50, 0x0E59); - TX_CHAR_RANGE(ch, 0x0E81, 0x0E82); - TX_MATCH_CHAR(ch, 0x0E84); - TX_CHAR_RANGE(ch, 0x0E87, 0x0E88); - TX_MATCH_CHAR(ch, 0x0E8A); - TX_MATCH_CHAR(ch, 0x0E8D); - TX_CHAR_RANGE(ch, 0x0E94, 0x0E97); - TX_CHAR_RANGE(ch, 0x0E99, 0x0E9F); - TX_CHAR_RANGE(ch, 0x0EA1, 0x0EA3); - TX_MATCH_CHAR(ch, 0x0EA5); - TX_MATCH_CHAR(ch, 0x0EA7); - TX_CHAR_RANGE(ch, 0x0EAA, 0x0EAB); - TX_CHAR_RANGE(ch, 0x0EAD, 0x0EB0); - TX_CHAR_RANGE(ch, 0x0EB2, 0x0EB3); - TX_MATCH_CHAR(ch, 0x0EBD); - TX_CHAR_RANGE(ch, 0x0EC0, 0x0EC4); - TX_MATCH_CHAR(ch, 0x0EC6); - TX_CHAR_RANGE(ch, 0x0ED0, 0x0ED9); - TX_CHAR_RANGE(ch, 0x0EDC, 0x0EDD); - TX_MATCH_CHAR(ch, 0x0F00); - TX_CHAR_RANGE(ch, 0x0F20, 0x0F33); - TX_CHAR_RANGE(ch, 0x0F40, 0x0F47); - TX_CHAR_RANGE(ch, 0x0F49, 0x0F6A); - TX_CHAR_RANGE(ch, 0x0F88, 0x0F8B); - TX_CHAR_RANGE(ch, 0x1000, 0x1021); - TX_CHAR_RANGE(ch, 0x1023, 0x1027); - TX_CHAR_RANGE(ch, 0x1029, 0x102A); - TX_CHAR_RANGE(ch, 0x1040, 0x1049); - TX_CHAR_RANGE(ch, 0x1050, 0x1055); - TX_CHAR_RANGE(ch, 0x10A0, 0x10C5); - TX_CHAR_RANGE(ch, 0x10D0, 0x10F6); - TX_CHAR_RANGE(ch, 0x1100, 0x1159); - TX_CHAR_RANGE(ch, 0x115F, 0x11A2); - TX_CHAR_RANGE(ch, 0x11A8, 0x11F9); - TX_CHAR_RANGE(ch, 0x1200, 0x1206); - TX_CHAR_RANGE(ch, 0x1208, 0x1246); - TX_MATCH_CHAR(ch, 0x1248); - TX_CHAR_RANGE(ch, 0x124A, 0x124D); - TX_CHAR_RANGE(ch, 0x1250, 0x1256); - TX_MATCH_CHAR(ch, 0x1258); - TX_CHAR_RANGE(ch, 0x125A, 0x125D); - TX_CHAR_RANGE(ch, 0x1260, 0x1286); - TX_MATCH_CHAR(ch, 0x1288); - TX_CHAR_RANGE(ch, 0x128A, 0x128D); - TX_CHAR_RANGE(ch, 0x1290, 0x12AE); - TX_MATCH_CHAR(ch, 0x12B0); - TX_CHAR_RANGE(ch, 0x12B2, 0x12B5); - TX_CHAR_RANGE(ch, 0x12B8, 0x12BE); - TX_MATCH_CHAR(ch, 0x12C0); - TX_CHAR_RANGE(ch, 0x12C2, 0x12C5); - TX_CHAR_RANGE(ch, 0x12C8, 0x12CE); - TX_CHAR_RANGE(ch, 0x12D0, 0x12D6); - TX_CHAR_RANGE(ch, 0x12D8, 0x12EE); - TX_CHAR_RANGE(ch, 0x12F0, 0x130E); - TX_MATCH_CHAR(ch, 0x1310); - TX_CHAR_RANGE(ch, 0x1312, 0x1315); - TX_CHAR_RANGE(ch, 0x1318, 0x131E); - TX_CHAR_RANGE(ch, 0x1320, 0x1346); - TX_CHAR_RANGE(ch, 0x1348, 0x135A); - TX_CHAR_RANGE(ch, 0x1369, 0x137C); - TX_CHAR_RANGE(ch, 0x13A0, 0x13F4); - TX_CHAR_RANGE(ch, 0x1401, 0x166C); - TX_CHAR_RANGE(ch, 0x166F, 0x1676); - TX_CHAR_RANGE(ch, 0x1681, 0x169A); - TX_CHAR_RANGE(ch, 0x16A0, 0x16EA); - TX_CHAR_RANGE(ch, 0x16EE, 0x16F0); - TX_CHAR_RANGE(ch, 0x1780, 0x17B3); - TX_CHAR_RANGE(ch, 0x17E0, 0x17E9); - TX_CHAR_RANGE(ch, 0x1810, 0x1819); - TX_CHAR_RANGE(ch, 0x1820, 0x1877); - TX_CHAR_RANGE(ch, 0x1880, 0x18A8); - TX_CHAR_RANGE(ch, 0x1E00, 0x1E9B); - TX_CHAR_RANGE(ch, 0x1EA0, 0x1EF9); - TX_CHAR_RANGE(ch, 0x1F00, 0x1F15); - TX_CHAR_RANGE(ch, 0x1F18, 0x1F1D); - TX_CHAR_RANGE(ch, 0x1F20, 0x1F45); - TX_CHAR_RANGE(ch, 0x1F48, 0x1F4D); - TX_CHAR_RANGE(ch, 0x1F50, 0x1F57); - TX_MATCH_CHAR(ch, 0x1F59); - TX_MATCH_CHAR(ch, 0x1F5B); - TX_MATCH_CHAR(ch, 0x1F5D); - TX_CHAR_RANGE(ch, 0x1F5F, 0x1F7D); - TX_CHAR_RANGE(ch, 0x1F80, 0x1FB4); - TX_CHAR_RANGE(ch, 0x1FB6, 0x1FBC); - TX_MATCH_CHAR(ch, 0x1FBE); - TX_CHAR_RANGE(ch, 0x1FC2, 0x1FC4); - TX_CHAR_RANGE(ch, 0x1FC6, 0x1FCC); - TX_CHAR_RANGE(ch, 0x1FD0, 0x1FD3); - TX_CHAR_RANGE(ch, 0x1FD6, 0x1FDB); - TX_CHAR_RANGE(ch, 0x1FE0, 0x1FEC); - TX_CHAR_RANGE(ch, 0x1FF2, 0x1FF4); - TX_CHAR_RANGE(ch, 0x1FF6, 0x1FFC); - TX_MATCH_CHAR(ch, 0x2070); - TX_CHAR_RANGE(ch, 0x2074, 0x2079); - TX_CHAR_RANGE(ch, 0x207F, 0x2089); - TX_MATCH_CHAR(ch, 0x2102); - TX_MATCH_CHAR(ch, 0x2107); - TX_CHAR_RANGE(ch, 0x210A, 0x2113); - TX_MATCH_CHAR(ch, 0x2115); - TX_CHAR_RANGE(ch, 0x2119, 0x211D); - TX_MATCH_CHAR(ch, 0x2124); - TX_MATCH_CHAR(ch, 0x2126); - TX_MATCH_CHAR(ch, 0x2128); - TX_CHAR_RANGE(ch, 0x212A, 0x212D); - TX_CHAR_RANGE(ch, 0x212F, 0x2131); - TX_CHAR_RANGE(ch, 0x2133, 0x2139); - TX_CHAR_RANGE(ch, 0x2153, 0x2183); - TX_CHAR_RANGE(ch, 0x2460, 0x249B); - TX_MATCH_CHAR(ch, 0x24EA); - TX_CHAR_RANGE(ch, 0x2776, 0x2793); - TX_CHAR_RANGE(ch, 0x3005, 0x3007); - TX_CHAR_RANGE(ch, 0x3021, 0x3029); - TX_CHAR_RANGE(ch, 0x3031, 0x3035); - TX_CHAR_RANGE(ch, 0x3038, 0x303A); - TX_CHAR_RANGE(ch, 0x3041, 0x3094); - TX_CHAR_RANGE(ch, 0x309D, 0x309E); - TX_CHAR_RANGE(ch, 0x30A1, 0x30FA); - TX_CHAR_RANGE(ch, 0x30FC, 0x30FE); - TX_CHAR_RANGE(ch, 0x3105, 0x312C); - TX_CHAR_RANGE(ch, 0x3131, 0x318E); - TX_CHAR_RANGE(ch, 0x3192, 0x3195); - TX_CHAR_RANGE(ch, 0x31A0, 0x31B7); - TX_CHAR_RANGE(ch, 0x3220, 0x3229); - TX_CHAR_RANGE(ch, 0x3280, 0x3289); - TX_MATCH_CHAR(ch, 0x3400); - TX_MATCH_CHAR(ch, 0x4DB5); - TX_MATCH_CHAR(ch, 0x4E00); - TX_MATCH_CHAR(ch, 0x9FA5); - TX_CHAR_RANGE(ch, 0xA000, 0xA48C); - TX_MATCH_CHAR(ch, 0xAC00); - TX_MATCH_CHAR(ch, 0xD7A3); - TX_CHAR_RANGE(ch, 0xF900, 0xFA2D); - TX_CHAR_RANGE(ch, 0xFB00, 0xFB06); - TX_CHAR_RANGE(ch, 0xFB13, 0xFB17); - TX_MATCH_CHAR(ch, 0xFB1D); - TX_CHAR_RANGE(ch, 0xFB1F, 0xFB28); - TX_CHAR_RANGE(ch, 0xFB2A, 0xFB36); - TX_CHAR_RANGE(ch, 0xFB38, 0xFB3C); - TX_MATCH_CHAR(ch, 0xFB3E); - TX_CHAR_RANGE(ch, 0xFB40, 0xFB41); - TX_CHAR_RANGE(ch, 0xFB43, 0xFB44); - TX_CHAR_RANGE(ch, 0xFB46, 0xFBB1); - TX_CHAR_RANGE(ch, 0xFBD3, 0xFD3D); - TX_CHAR_RANGE(ch, 0xFD50, 0xFD8F); - TX_CHAR_RANGE(ch, 0xFD92, 0xFDC7); - TX_CHAR_RANGE(ch, 0xFDF0, 0xFDFB); - TX_CHAR_RANGE(ch, 0xFE70, 0xFE72); - TX_MATCH_CHAR(ch, 0xFE74); - TX_CHAR_RANGE(ch, 0xFE76, 0xFEFC); - TX_CHAR_RANGE(ch, 0xFF10, 0xFF19); - TX_CHAR_RANGE(ch, 0xFF21, 0xFF3A); - TX_CHAR_RANGE(ch, 0xFF41, 0xFF5A); - TX_CHAR_RANGE(ch, 0xFF66, 0xFFBE); - TX_CHAR_RANGE(ch, 0xFFC2, 0xFFC7); - TX_CHAR_RANGE(ch, 0xFFCA, 0xFFCF); - TX_CHAR_RANGE(ch, 0xFFD2, 0xFFD7); - return MB_FALSE; -} diff --git a/extensions/transformiix/source/xslt/txXSLTNumber.h b/extensions/transformiix/source/xslt/txXSLTNumber.h deleted file mode 100644 index f7e249f63baa..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTNumber.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXXSLTNUMBER_H -#define TRANSFRMX_TXXSLTNUMBER_H - -#include "txError.h" -#include "List.h" -#include "nsString.h" - -class Expr; -class txPattern; -class txIEvalContext; -class txIMatchContext; -class txXPathTreeWalker; - -class txXSLTNumber { -public: - enum LevelType { - eLevelSingle, - eLevelMultiple, - eLevelAny - }; - - static nsresult createNumber(Expr* aValueExpr, txPattern* aCountPattern, - txPattern* aFromPattern, LevelType aLevel, - Expr* aGroupSize, Expr* aGroupSeparator, - Expr* aFormat, txIEvalContext* aContext, - nsAString& aResult); - -private: - static nsresult getValueList(Expr* aValueExpr, txPattern* aCountPattern, - txPattern* aFromPattern, LevelType aLevel, - txIEvalContext* aContext, txList& aValues, - nsAString& aValueString); - - static nsresult getCounters(Expr* aGroupSize, Expr* aGroupSeparator, - Expr* aFormat, txIEvalContext* aContext, - txList& aCounters, nsAString& aHead, - nsAString& aTail); - - /** - * getSiblingCount uses aWalker to walk the siblings of aWalker's current - * position. - * - */ - static PRInt32 getSiblingCount(txXPathTreeWalker& aWalker, - txPattern* aCountPattern, - txIMatchContext* aContext); - - static PRBool getPrevInDocumentOrder(txXPathTreeWalker& aWalker); - - static MBool isAlphaNumeric(PRUnichar ch); -}; - -class txFormattedCounter { -public: - virtual ~txFormattedCounter() - { - } - - virtual void appendNumber(PRInt32 aNumber, nsAString& aDest) = 0; - - static nsresult getCounterFor(const nsAFlatString& aToken, int aGroupSize, - const nsAString& aGroupSeparator, - txFormattedCounter*& aCounter); - - nsString mSeparator; -}; - -#endif //TRANSFRMX_TXXSLTNUMBER_H diff --git a/extensions/transformiix/source/xslt/txXSLTNumberCounters.cpp b/extensions/transformiix/source/xslt/txXSLTNumberCounters.cpp deleted file mode 100644 index eee53dbf2d34..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTNumberCounters.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXSLTNumber.h" -#include "nsReadableUtils.h" -#include "txCore.h" - -class txDecimalCounter : public txFormattedCounter { -public: - txDecimalCounter() : mMinLength(1), mGroupSize(50) - { - } - - txDecimalCounter(PRInt32 aMinLength, PRInt32 aGroupSize, - const nsAString& mGroupSeparator); - - virtual void appendNumber(PRInt32 aNumber, nsAString& aDest); - -private: - PRInt32 mMinLength; - PRInt32 mGroupSize; - nsString mGroupSeparator; -}; - -class txAlphaCounter : public txFormattedCounter { -public: - txAlphaCounter(PRUnichar aOffset) : mOffset(aOffset) - { - } - - virtual void appendNumber(PRInt32 aNumber, nsAString& aDest); - -private: - PRUnichar mOffset; -}; - -class txRomanCounter : public txFormattedCounter { -public: - txRomanCounter(MBool aUpper) : mTableOffset(aUpper ? 30 : 0) - { - } - - void appendNumber(PRInt32 aNumber, nsAString& aDest); - -private: - PRInt32 mTableOffset; -}; - - -nsresult -txFormattedCounter::getCounterFor(const nsAFlatString& aToken, - PRInt32 aGroupSize, - const nsAString& aGroupSeparator, - txFormattedCounter*& aCounter) -{ - PRInt32 length = aToken.Length(); - NS_ASSERTION(length, "getting counter for empty token"); - aCounter = 0; - - if (length == 1) { - PRUnichar ch = aToken.CharAt(0); - switch (ch) { - - case 'i': - case 'I': - aCounter = new txRomanCounter(ch == 'I'); - break; - - case 'a': - case 'A': - aCounter = new txAlphaCounter(ch); - break; - - case '1': - default: - // if we don't recognize the token then use "1" - aCounter = new txDecimalCounter(1, aGroupSize, - aGroupSeparator); - break; - } - return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY; - } - - // for now, the only multi-char token we support are decimals - PRInt32 i; - for (i = 0; i < length-1; ++i) { - if (aToken.CharAt(i) != '0') - break; - } - if (i == length-1 && aToken.CharAt(i) == '1') { - aCounter = new txDecimalCounter(length, aGroupSize, aGroupSeparator); - } - else { - // if we don't recognize the token then use '1' - aCounter = new txDecimalCounter(1, aGroupSize, aGroupSeparator); - } - - return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - - -txDecimalCounter::txDecimalCounter(PRInt32 aMinLength, PRInt32 aGroupSize, - const nsAString& aGroupSeparator) - : mMinLength(aMinLength), mGroupSize(aGroupSize), - mGroupSeparator(aGroupSeparator) -{ - if (mGroupSize <= 0) { - mGroupSize = aMinLength + 10; - } -} - -void txDecimalCounter::appendNumber(PRInt32 aNumber, nsAString& aDest) -{ - const PRInt32 bufsize = 10; //must be able to fit an PRInt32 - PRUnichar buf[bufsize]; - PRInt32 pos = bufsize; - while (aNumber > 0) { - PRInt32 ch = aNumber % 10; - aNumber /= 10; - buf[--pos] = ch + '0'; - } - - // in case we didn't get a long enough string - PRInt32 end = (bufsize > mMinLength) ? bufsize - mMinLength : 0; - while (pos > end) { - buf[--pos] = '0'; - } - - // in case we *still* didn't get a long enough string. - // this should be very rare since it only happens if mMinLength is bigger - // then the length of any PRInt32. - // pos will always be zero - PRInt32 extraPos = mMinLength; - while (extraPos > bufsize) { - aDest.Append(PRUnichar('0')); - --extraPos; - if (extraPos % mGroupSize == 0) { - aDest.Append(mGroupSeparator); - } - } - - // copy string to buffer - if (mGroupSize >= bufsize - pos) { - // no grouping will occur - aDest.Append(buf + pos, (PRUint32)(bufsize - pos)); - } - else { - // append chars up to first grouping separator - PRInt32 len = ((bufsize - pos - 1) % mGroupSize) + 1; - aDest.Append(buf + pos, len); - pos += len; - while (bufsize - pos > 0) { - aDest.Append(mGroupSeparator); - aDest.Append(buf + pos, mGroupSize); - pos += mGroupSize; - } - NS_ASSERTION(bufsize == pos, "error while grouping"); - } -} - - -void txAlphaCounter::appendNumber(PRInt32 aNumber, nsAString& aDest) -{ - PRUnichar buf[12]; - buf[11] = 0; - PRInt32 pos = 11; - while (aNumber > 0) { - --aNumber; - PRInt32 ch = aNumber % 26; - aNumber /= 26; - buf[--pos] = ch + mOffset; - } - - aDest.Append(buf + pos, (PRUint32)(11 - pos)); -} - - -const char* const kTxRomanNumbers[] = - {"", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm", - "", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc", - "", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", - "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", - "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", - "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; - -void txRomanCounter::appendNumber(PRInt32 aNumber, nsAString& aDest) -{ - // Numbers bigger then 3999 can't be done in roman - if (aNumber >= 4000) { - txDecimalCounter().appendNumber(aNumber, aDest); - return; - } - - while (aNumber >= 1000) { - aDest.Append(!mTableOffset ? PRUnichar('m') : PRUnichar('M')); - aNumber -= 1000; - } - - PRInt32 posValue; - - // Hundreds - posValue = aNumber / 100; - aNumber %= 100; - AppendASCIItoUTF16(kTxRomanNumbers[posValue + mTableOffset], aDest); - // Tens - posValue = aNumber / 10; - aNumber %= 10; - AppendASCIItoUTF16(kTxRomanNumbers[10 + posValue + mTableOffset], aDest); - // Ones - AppendASCIItoUTF16(kTxRomanNumbers[20 + aNumber + mTableOffset], aDest); -} diff --git a/extensions/transformiix/source/xslt/txXSLTPatterns.cpp b/extensions/transformiix/source/xslt/txXSLTPatterns.cpp deleted file mode 100644 index 518f8afbf4f2..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTPatterns.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsReadableUtils.h" -#include "txExecutionState.h" -#include "txXSLTPatterns.h" -#include "txNodeSetContext.h" -#include "txForwardContext.h" -#include "XMLUtils.h" -#include "XSLTFunctions.h" -#ifndef TX_EXE -#include "nsIContent.h" -#endif - -/* - * txPattern - * - * Base class of all patterns - * Implements only a default getSimplePatterns - */ -nsresult txPattern::getSimplePatterns(txList& aList) -{ - aList.add(this); - return NS_OK; -} - -txPattern::~txPattern() -{ -} - - -/* - * txUnionPattern - * - * This pattern is returned by the parser for "foo | bar" constructs. - * |xsl:template|s should use the simple patterns - */ - -/* - * Destructor, deletes all LocationPathPatterns - */ -txUnionPattern::~txUnionPattern() -{ - txListIterator iter(&mLocPathPatterns); - while (iter.hasNext()) { - delete (txPattern*)iter.next(); - } -} - -nsresult txUnionPattern::addPattern(txPattern* aPattern) -{ - if (!aPattern) - return NS_ERROR_NULL_POINTER; - mLocPathPatterns.add(aPattern); - return NS_OK; -} - -/* - * Returns the default priority of this Pattern. - * UnionPatterns don't like this. - * This should be called on the simple patterns. - */ -double txUnionPattern::getDefaultPriority() -{ - NS_ASSERTION(0, "Don't call getDefaultPriority on txUnionPattern"); - return Double::NaN; -} - -/* - * Determines whether this Pattern matches the given node within - * the given context - * This should be called on the simple patterns for xsl:template, - * but is fine for xsl:key and xsl:number - */ -MBool txUnionPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - txListIterator iter(&mLocPathPatterns); - while (iter.hasNext()) { - txPattern* p = (txPattern*)iter.next(); - if (p->matches(aNode, aContext)) { - return MB_TRUE; - } - } - return MB_FALSE; -} - -nsresult txUnionPattern::getSimplePatterns(txList& aList) -{ - txListIterator iter(&mLocPathPatterns); - while (iter.hasNext()) { - aList.add(iter.next()); - iter.remove(); - } - return NS_OK; -} - -#ifdef TX_TO_STRING -void -txUnionPattern::toString(nsAString& aDest) -{ -#ifdef DEBUG - aDest.AppendLiteral("txUnionPattern{"); -#endif - txListIterator iter(&mLocPathPatterns); - if (iter.hasNext()) - ((txPattern*)iter.next())->toString(aDest); - while (iter.hasNext()) { - aDest.AppendLiteral(" | "); - ((txPattern*)iter.next())->toString(aDest); - } -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif - - -/* - * LocationPathPattern - * - * a list of step patterns, can start with id or key - * (dealt with by the parser) - */ - -/* - * Destructor, deletes all PathPatterns - */ -txLocPathPattern::~txLocPathPattern() -{ - txListIterator iter(&mSteps); - while (iter.hasNext()) { - delete (Step*)iter.next(); - } -} - -nsresult txLocPathPattern::addStep(txPattern* aPattern, MBool isChild) -{ - if (!aPattern) - return NS_ERROR_NULL_POINTER; - Step* step = new Step(aPattern, isChild); - if (!step) - return NS_ERROR_OUT_OF_MEMORY; - mSteps.add(step); - return NS_OK; -} - -MBool txLocPathPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - NS_ASSERTION(mSteps.getLength(), "Internal error"); - - /* - * The idea is to split up a path into blocks separated by descendant - * operators. For example "foo/bar//baz/bop//ying/yang" is split up into - * three blocks. The "ying/yang" block is handled by the first while-loop - * and the "foo/bar" and "baz/bop" blocks are handled by the second - * while-loop. - * A block is considered matched when we find a list of ancestors that - * match the block. If there are more than one list of ancestors that - * match a block we only need to find the one furthermost down in the - * tree. - */ - - txListIterator iter(&mSteps); - iter.resetToEnd(); - - Step* step; - step = (Step*)iter.previous(); - if (!step->pattern->matches(aNode, aContext)) - return MB_FALSE; - - txXPathTreeWalker walker(aNode); - PRBool hasParent = walker.moveToParent(); - - while (step->isChild) { - step = (Step*)iter.previous(); - if (!step) - return MB_TRUE; // all steps matched - if (!hasParent || !step->pattern->matches(walker.getCurrentPosition(), aContext)) - return MB_FALSE; // no more ancestors or no match - - hasParent = walker.moveToParent(); - } - - // We have at least one // path separator - txXPathTreeWalker blockWalker(walker); - txListIterator blockIter(iter); - - while ((step = (Step*)iter.previous())) { - if (!hasParent) - return MB_FALSE; // There are more steps in the current block - // than ancestors of the tested node - - if (!step->pattern->matches(walker.getCurrentPosition(), aContext)) { - // Didn't match. We restart at beginning of block using a new - // start node - iter = blockIter; - hasParent = blockWalker.moveToParent(); - walker.moveTo(blockWalker); - } - else { - hasParent = walker.moveToParent(); - if (!step->isChild) { - // We've matched an entire block. Set new start iter and start node - blockIter = iter; - blockWalker.moveTo(walker); - } - } - } - - return MB_TRUE; -} // txLocPathPattern::matches - -double txLocPathPattern::getDefaultPriority() -{ - if (mSteps.getLength() > 1) { - return 0.5; - } - - return ((Step*)mSteps.get(0))->pattern->getDefaultPriority(); -} - -#ifdef TX_TO_STRING -void -txLocPathPattern::toString(nsAString& aDest) -{ - txListIterator iter(&mSteps); -#ifdef DEBUG - aDest.AppendLiteral("txLocPathPattern{"); -#endif - Step* step; - step = (Step*)iter.next(); - if (step) { - step->pattern->toString(aDest); - } - while ((step = (Step*)iter.next())) { - if (step->isChild) - aDest.Append(PRUnichar('/')); - else - aDest.AppendLiteral("//"); - step->pattern->toString(aDest); - } -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif - -/* - * txRootPattern - * - * a txPattern matching the document node, or '/' - */ - -txRootPattern::~txRootPattern() -{ -} - -MBool txRootPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - return txXPathNodeUtils::isRoot(aNode); -} - -double txRootPattern::getDefaultPriority() -{ - return 0.5; -} - -#ifdef TX_TO_STRING -void -txRootPattern::toString(nsAString& aDest) -{ -#ifdef DEBUG - aDest.AppendLiteral("txRootPattern{"); -#endif - if (mSerialize) - aDest.Append(PRUnichar('/')); -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif - -/* - * txIdPattern - * - * txIdPattern matches if the given node has a ID attribute with one - * of the space delimited values. - * This looks like the id() function, but may only have LITERALs as - * argument. - */ -txIdPattern::txIdPattern(const nsAString& aString) -{ - nsAString::const_iterator pos, begin, end; - aString.BeginReading(begin); - aString.EndReading(end); - pos = begin; - while (pos != end) { - while (pos != end && XMLUtils::isWhitespace(*pos)) - ++pos; - begin = pos; - while (pos != end && !XMLUtils::isWhitespace(*pos)) - ++pos; - // this can fail, XXX move to a Init(aString) method - mIds.AppendString(Substring(begin, pos)); - } -} - -txIdPattern::~txIdPattern() -{ -} - -MBool txIdPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - if (!txXPathNodeUtils::isElement(aNode)) { - return PR_FALSE; - } - - // Get a ID attribute, if there is - nsAutoString value; -#ifdef TX_EXE - Element* elem; - nsresult rv = txXPathNativeNode::getElement(aNode, &elem); - NS_ASSERTION(NS_SUCCEEDED(rv), "So why claim it's an element above?"); - if (!elem->getIDValue(value)) { - return PR_FALSE; - } -#else - nsIContent* content = txXPathNativeNode::getContent(aNode); - NS_ASSERTION(content, "a Element without nsIContent"); - if (!content) { - return MB_FALSE; - } - - nsIAtom* idAttr = content->GetIDAttributeName(); - if (!idAttr) { - return MB_FALSE; // no ID for this element defined, can't match - } - content->GetAttr(kNameSpaceID_None, idAttr, value); - if (value.IsEmpty()) { - return MB_FALSE; // no ID attribute given - } -#endif // TX_EXE - return mIds.IndexOf(value) > -1; -} - -double txIdPattern::getDefaultPriority() -{ - return 0.5; -} - -#ifdef TX_TO_STRING -void -txIdPattern::toString(nsAString& aDest) -{ -#ifdef DEBUG - aDest.AppendLiteral("txIdPattern{"); -#endif - aDest.AppendLiteral("id('"); - PRUint32 k, count = mIds.Count() - 1; - for (k = 0; k < count; ++k) { - aDest.Append(*mIds[k]); - aDest.Append(PRUnichar(' ')); - } - aDest.Append(*mIds[count]); - aDest.Append(NS_LITERAL_STRING("')")); -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif - -/* - * txKeyPattern - * - * txKeyPattern matches if the given node is in the evalation of - * the key() function - * This resembles the key() function, but may only have LITERALs as - * argument. - */ - -txKeyPattern::~txKeyPattern() -{ -} - -MBool txKeyPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - txExecutionState* es = (txExecutionState*)aContext->getPrivateContext(); - nsAutoPtr contextDoc(txXPathNodeUtils::getOwnerDocument(aNode)); - NS_ENSURE_TRUE(contextDoc, PR_FALSE); - - nsRefPtr nodes; - nsresult rv = es->getKeyNodes(mName, *contextDoc, mValue, PR_TRUE, - getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - return nodes->contains(aNode); -} - -double txKeyPattern::getDefaultPriority() -{ - return 0.5; -} - -#ifdef TX_TO_STRING -void -txKeyPattern::toString(nsAString& aDest) -{ -#ifdef DEBUG - aDest.AppendLiteral("txKeyPattern{"); -#endif - aDest.AppendLiteral("key('"); - nsAutoString tmp; - if (mPrefix) { - mPrefix->ToString(tmp); - aDest.Append(tmp); - aDest.Append(PRUnichar(':')); - } - mName.mLocalName->ToString(tmp); - aDest.Append(tmp); - aDest.AppendLiteral(", "); - aDest.Append(mValue); - aDest.Append(NS_LITERAL_STRING("')")); -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif - -/* - * txStepPattern - * - * a txPattern to hold the NodeTest and the Predicates of a StepPattern - */ - -txStepPattern::~txStepPattern() -{ - delete mNodeTest; -} - -MBool txStepPattern::matches(const txXPathNode& aNode, txIMatchContext* aContext) -{ - NS_ASSERTION(mNodeTest, "Internal error"); - - if (!mNodeTest->matches(aNode, aContext)) - return MB_FALSE; - - txXPathTreeWalker walker(aNode); - if ((!mIsAttr && - txXPathNodeUtils::isAttribute(walker.getCurrentPosition())) || - !walker.moveToParent()) { - return MB_FALSE; - } - if (isEmpty()) { - return MB_TRUE; - } - - /* - * Evaluate Predicates - * - * Copy all siblings/attributes matching mNodeTest to nodes - * Up to the last Predicate do - * Foreach node in nodes - * evaluate Predicate with node as context node - * if the result is a number, check the context position, - * otherwise convert to bool - * if result is true, copy node to newNodes - * if aNode is not member of newNodes, return MB_FALSE - * nodes = newNodes - * - * For the last Predicate, evaluate Predicate with aNode as - * context node, if the result is a number, check the position, - * otherwise return the result converted to boolean - */ - - // Create the context node set for evaluating the predicates - nsRefPtr nodes; - nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes)); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool hasNext = mIsAttr ? walker.moveToFirstAttribute() : - walker.moveToFirstChild(); - while (hasNext) { - if (mNodeTest->matches(walker.getCurrentPosition(), aContext)) { - nodes->append(walker.getCurrentPosition()); - } - hasNext = mIsAttr ? walker.moveToNextAttribute() : - walker.moveToNextSibling(); - } - - txListIterator iter(&predicates); - Expr* predicate = (Expr*)iter.next(); - nsRefPtr newNodes; - rv = aContext->recycler()->getNodeSet(getter_AddRefs(newNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - while (iter.hasNext()) { - newNodes->clear(); - MBool contextIsInPredicate = MB_FALSE; - txNodeSetContext predContext(nodes, aContext); - while (predContext.hasNext()) { - predContext.next(); - nsRefPtr exprResult; - rv = predicate->evaluate(&predContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - switch(exprResult->getResultType()) { - case txAExprResult::NUMBER: - // handle default, [position() == numberValue()] - if ((double)predContext.position() == - exprResult->numberValue()) { - const txXPathNode& tmp = predContext.getContextNode(); - if (tmp == aNode) - contextIsInPredicate = MB_TRUE; - newNodes->append(tmp); - } - break; - default: - if (exprResult->booleanValue()) { - const txXPathNode& tmp = predContext.getContextNode(); - if (tmp == aNode) - contextIsInPredicate = MB_TRUE; - newNodes->append(tmp); - } - break; - } - } - // Move new NodeSet to the current one - nodes->clear(); - nodes->append(*newNodes); - if (!contextIsInPredicate) { - return MB_FALSE; - } - predicate = (Expr*)iter.next(); - } - txForwardContext evalContext(aContext, aNode, nodes); - nsRefPtr exprResult; - rv = predicate->evaluate(&evalContext, getter_AddRefs(exprResult)); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - if (exprResult->getResultType() == txAExprResult::NUMBER) - // handle default, [position() == numberValue()] - return ((double)evalContext.position() == exprResult->numberValue()); - - return exprResult->booleanValue(); -} // matches - -double txStepPattern::getDefaultPriority() -{ - if (isEmpty()) - return mNodeTest->getDefaultPriority(); - return 0.5; -} - -#ifdef TX_TO_STRING -void -txStepPattern::toString(nsAString& aDest) -{ -#ifdef DEBUG - aDest.AppendLiteral("txStepPattern{"); -#endif - if (mIsAttr) - aDest.Append(PRUnichar('@')); - if (mNodeTest) - mNodeTest->toString(aDest); - - PredicateList::toString(aDest); -#ifdef DEBUG - aDest.Append(PRUnichar('}')); -#endif -} -#endif diff --git a/extensions/transformiix/source/xslt/txXSLTPatterns.h b/extensions/transformiix/source/xslt/txXSLTPatterns.h deleted file mode 100644 index 0a59a3de9ee9..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTPatterns.h +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Axel Hecht. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Axel Hecht - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TX_XSLT_PATTERNS_H -#define TX_XSLT_PATTERNS_H - -#include "Expr.h" -#include "XMLUtils.h" -#include "nsVoidArray.h" - -class ProcessorState; - -class txPattern : public TxObject -{ -public: - virtual ~txPattern(); - - /* - * Determines whether this Pattern matches the given node. - */ - virtual MBool matches(const txXPathNode& aNode, - txIMatchContext* aContext) = 0; - - /* - * Returns the default priority of this Pattern. - * - * Simple Patterns return the values as specified in XPath 5.5. - * Returns -Inf for union patterns, as it shouldn't be called on them. - */ - virtual double getDefaultPriority() = 0; - - /* - * Adds the simple Patterns to the List. - * For union patterns, add all sub patterns, - * all other (simple) patterns just add themselves. - * This cuts the ownership of the union pattern and it's - * simple patterns, leaving union patterns empty after a call - * to this function. - */ - virtual nsresult getSimplePatterns(txList &aList); - -#ifdef TX_TO_STRING - /* - * Returns the String representation of this Pattern. - * @param dest the String to use when creating the String - * representation. The String representation will be appended to - * any data in the destination String, to allow cascading calls to - * other #toString() methods for Patterns. - * @return the String representation of this Pattern. - */ - virtual void toString(nsAString& aDest) = 0; -#endif -}; - -#define TX_DECL_PATTERN_BASE \ - MBool matches(const txXPathNode& aNode, txIMatchContext* aContext); \ - double getDefaultPriority() - -#ifndef TX_TO_STRING -#define TX_DECL_PATTERN TX_DECL_PATTERN_BASE -#else -#define TX_DECL_PATTERN \ - TX_DECL_PATTERN_BASE; \ - void toString(nsAString& aDest) -#endif - -#define TX_DECL_PATTERN2 \ - TX_DECL_PATTERN; \ - nsresult getSimplePatterns(txList &aList) - - -class txUnionPattern : public txPattern -{ -public: - txUnionPattern() - { - } - - ~txUnionPattern(); - - nsresult addPattern(txPattern* aPattern); - - TX_DECL_PATTERN2; - -private: - txList mLocPathPatterns; -}; - -class txLocPathPattern : public txPattern -{ -public: - txLocPathPattern() - { - } - - ~txLocPathPattern(); - - nsresult addStep(txPattern* aPattern, MBool isChild); - - TX_DECL_PATTERN; - -private: - class Step { - public: - Step(txPattern* aPattern, MBool aIsChild) - : pattern(aPattern), isChild(aIsChild) - { - } - - ~Step() - { - delete pattern; - } - - txPattern* pattern; - MBool isChild; - }; - - txList mSteps; -}; - -class txRootPattern : public txPattern -{ -public: - txRootPattern() -#ifdef TX_TO_STRING - : mSerialize(PR_TRUE) -#endif - { - } - - ~txRootPattern(); - - TX_DECL_PATTERN; - -#ifdef TX_TO_STRING -public: - void setSerialize(PRBool aSerialize) - { - mSerialize = aSerialize; - } - -private: - // Don't serialize txRootPattern if it's used in a txLocPathPattern - PRBool mSerialize; -#endif -}; - -class txIdPattern : public txPattern -{ -public: - txIdPattern(const nsAString& aString); - - ~txIdPattern(); - - TX_DECL_PATTERN; - -private: - nsStringArray mIds; -}; - -class txKeyPattern : public txPattern -{ -public: - txKeyPattern(nsIAtom* aPrefix, nsIAtom* aLocalName, - PRInt32 aNSID, const nsAString& aValue) - : mName(aNSID, aLocalName), mPrefix(aPrefix), mValue(aValue) - { - } - - ~txKeyPattern(); - - TX_DECL_PATTERN; - -private: - txExpandedName mName; - nsIAtom* mPrefix; - nsString mValue; -}; - -class txStepPattern : public PredicateList, public txPattern -{ -public: - txStepPattern(txNodeTest* aNodeTest, MBool isAttr) - :mNodeTest(aNodeTest), mIsAttr(isAttr) - { - } - - ~txStepPattern(); - - TX_DECL_PATTERN; - -private: - txNodeTest* mNodeTest; - MBool mIsAttr; -}; - -#endif // TX_XSLT_PATTERNS_H diff --git a/extensions/transformiix/source/xslt/txXSLTProcessor.cpp b/extensions/transformiix/source/xslt/txXSLTProcessor.cpp deleted file mode 100644 index 3885a55d5d94..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTProcessor.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXSLTProcessor.h" -#include "txInstructions.h" -#include "txAtoms.h" -#include "TxLog.h" -#include "txStylesheetCompileHandlers.h" -#include "txExecutionState.h" -#include "ExprResult.h" -#ifdef TX_EXE -#include "txHTMLOutput.h" -#endif - -TX_LG_IMPL - -/* static */ -MBool -txXSLTProcessor::init() -{ - TX_LG_CREATE; - -#ifdef TX_EXE - if (!txStandaloneNamespaceManager::init()) - return MB_FALSE; - - if (NS_FAILED(txHTMLOutput::init())) { - return MB_FALSE; - } -#endif - - txXMLAtoms::init(); - txXPathAtoms::init(); - txXSLTAtoms::init(); - txHTMLAtoms::init(); - - if (!txHandlerTable::init()) - return MB_FALSE; - - return MB_TRUE; -} - -/* static */ -void -txXSLTProcessor::shutdown() -{ -#ifdef TX_EXE - txStandaloneNamespaceManager::shutdown(); - txHTMLOutput::shutdown(); -#endif - - txHandlerTable::shutdown(); -} - - -/* static */ -nsresult -txXSLTProcessor::execute(txExecutionState& aEs) -{ - nsresult rv = NS_OK; - txInstruction* instr; - while ((instr = aEs.getNextInstruction())) { - rv = instr->execute(aEs); - NS_ENSURE_SUCCESS(rv, rv); - } - - return NS_OK; -} diff --git a/extensions/transformiix/source/xslt/txXSLTProcessor.h b/extensions/transformiix/source/xslt/txXSLTProcessor.h deleted file mode 100644 index c96f3d7b6816..000000000000 --- a/extensions/transformiix/source/xslt/txXSLTProcessor.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_TXXSLTPROCESSOR_H -#define TRANSFRMX_TXXSLTPROCESSOR_H - -#include "txExecutionState.h" - -class txXSLTProcessor -{ -public: - /** - * Initialisation and shutdown routines. Initilizes and cleansup all - * dependant classes - */ - static MBool init(); - static void shutdown(); - - - static nsresult execute(txExecutionState& aEs); - - // once we want to have interuption we should probably have functions for - // running X number of steps or running until a condition is true. -}; - -#endif diff --git a/extensions/transformiix/source/xslt/util/.cvsignore b/extensions/transformiix/source/xslt/util/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/extensions/transformiix/source/xslt/util/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/extensions/transformiix/source/xslt/util/Makefile.in b/extensions/transformiix/source/xslt/util/Makefile.in deleted file mode 100644 index 5d99d001f7aa..000000000000 --- a/extensions/transformiix/source/xslt/util/Makefile.in +++ /dev/null @@ -1,75 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is TransforMiiX XSLT processor code. -# -# The Initial Developer of the Original Code is -# Axel Hecht. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Axel Hecht -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = transformiix -LIBRARY_NAME = txxsltutil_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = string \ - xpcom \ - $(NULL) - -ifndef TX_EXE -REQUIRES += dom \ - content \ - layout \ - widget \ - locale \ - unicharutil \ - necko \ - htmlparser \ - $(NULL) -endif - -CPPSRCS = txNodeSorter.cpp txXPathResultComparator.cpp - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -INCLUDES += -I$(srcdir) -I$(srcdir)/../../base -I$(srcdir)/../../xpath \ - -I$(srcdir)/../../xml -I$(srcdir)/../../xml/dom \ - -I$(srcdir)/.. -I$(srcdir)/../functions diff --git a/extensions/transformiix/source/xslt/util/txNodeSorter.cpp b/extensions/transformiix/source/xslt/util/txNodeSorter.cpp deleted file mode 100644 index be6b73886ea8..000000000000 --- a/extensions/transformiix/source/xslt/util/txNodeSorter.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txNodeSorter.h" -#include "txExecutionState.h" -#include "txXPathResultComparator.h" -#include "txAtoms.h" -#include "txNodeSetContext.h" -#include "ExprResult.h" -#include "Expr.h" -#include "txStringUtils.h" -#include "prmem.h" -#include "nsQuickSort.h" - -/* - * Sorts Nodes as specified by the W3C XSLT 1.0 Recommendation - */ - -txNodeSorter::txNodeSorter() : mNKeys(0) -{ -} - -txNodeSorter::~txNodeSorter() -{ - txListIterator iter(&mSortKeys); - while (iter.hasNext()) { - SortKey* key = (SortKey*)iter.next(); - delete key->mComparator; - delete key; - } -} - -nsresult -txNodeSorter::addSortElement(Expr* aSelectExpr, Expr* aLangExpr, - Expr* aDataTypeExpr, Expr* aOrderExpr, - Expr* aCaseOrderExpr, txIEvalContext* aContext) -{ - SortKey* key = new SortKey; - NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY); - nsresult rv = NS_OK; - - // Select - key->mExpr = aSelectExpr; - - // Order - MBool ascending = MB_TRUE; - if (aOrderExpr) { - nsRefPtr exprRes; - rv = aOrderExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString attrValue; - exprRes->stringValue(attrValue); - - if (TX_StringEqualsAtom(attrValue, txXSLTAtoms::descending)) { - ascending = MB_FALSE; - } - else if (!TX_StringEqualsAtom(attrValue, txXSLTAtoms::ascending)) { - delete key; - // XXX ErrorReport: unknown value for order attribute - return NS_ERROR_XSLT_BAD_VALUE; - } - } - - - // Create comparator depending on datatype - nsAutoString dataType; - if (aDataTypeExpr) { - nsRefPtr exprRes; - rv = aDataTypeExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - exprRes->stringValue(dataType); - } - - if (!aDataTypeExpr || TX_StringEqualsAtom(dataType, txXSLTAtoms::text)) { - // Text comparator - - // Language - nsAutoString lang; - if (aLangExpr) { - nsRefPtr exprRes; - rv = aLangExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - exprRes->stringValue(lang); - } - - // Case-order - MBool upperFirst = PR_FALSE; - if (aCaseOrderExpr) { - nsRefPtr exprRes; - rv = aCaseOrderExpr->evaluate(aContext, getter_AddRefs(exprRes)); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString attrValue; - exprRes->stringValue(attrValue); - - if (TX_StringEqualsAtom(attrValue, txXSLTAtoms::upperFirst)) { - upperFirst = PR_TRUE; - } - else if (!TX_StringEqualsAtom(attrValue, - txXSLTAtoms::lowerFirst)) { - delete key; - // XXX ErrorReport: unknown value for case-order attribute - return NS_ERROR_XSLT_BAD_VALUE; - } - } - - key->mComparator = new txResultStringComparator(ascending, - upperFirst, - lang); - NS_ENSURE_TRUE(key->mComparator, NS_ERROR_OUT_OF_MEMORY); - } - else if (TX_StringEqualsAtom(dataType, txXSLTAtoms::number)) { - // Number comparator - key->mComparator = new txResultNumberComparator(ascending); - NS_ENSURE_TRUE(key->mComparator, NS_ERROR_OUT_OF_MEMORY); - } - else { - // XXX ErrorReport: unknown data-type - delete key; - - return NS_ERROR_XSLT_BAD_VALUE; - } - - mSortKeys.add(key); - mNKeys++; - - return NS_OK; -} - -nsresult -txNodeSorter::sortNodeSet(txNodeSet* aNodes, txExecutionState* aEs, - txNodeSet** aResult) -{ - if (mNKeys == 0 || aNodes->isEmpty()) { - NS_ADDREF(*aResult = aNodes); - - return NS_OK; - } - - *aResult = nsnull; - - nsRefPtr sortedNodes; - nsresult rv = aEs->recycler()->getNodeSet(getter_AddRefs(sortedNodes)); - NS_ENSURE_SUCCESS(rv, rv); - - txNodeSetContext* evalContext = new txNodeSetContext(aNodes, aEs); - NS_ENSURE_TRUE(evalContext, NS_ERROR_OUT_OF_MEMORY); - - rv = aEs->pushEvalContext(evalContext); - NS_ENSURE_SUCCESS(rv, rv); - - // Create and set up memoryblock for sort-values and indexarray - PRUint32 len = NS_STATIC_CAST(PRUint32, aNodes->size()); - void* mem = PR_Malloc(len * (sizeof(PRUint32) + mNKeys * sizeof(TxObject*))); - NS_ENSURE_TRUE(mem, NS_ERROR_OUT_OF_MEMORY); - - PRUint32* indexes = NS_STATIC_CAST(PRUint32*, mem); - TxObject** sortValues = NS_REINTERPRET_CAST(TxObject**, indexes + len); - - PRUint32 i; - for (i = 0; i < len; ++i) { - indexes[i] = i; - } - memset(sortValues, 0, len * mNKeys * sizeof(TxObject*)); - - // Sort the indexarray - SortData sortData; - sortData.mNodeSorter = this; - sortData.mContext = evalContext; - sortData.mSortValues = sortValues; - sortData.mRv = NS_OK; - NS_QuickSort(indexes, len, sizeof(PRUint32), compareNodes, &sortData); - - // Delete these here so we don't have to deal with them at every possible - // failurepoint - PRUint32 numSortValues = len * mNKeys; - for (i = 0; i < numSortValues; ++i) { - delete sortValues[i]; - } - - if (NS_FAILED(sortData.mRv)) { - PR_Free(mem); - // The txExecutionState owns the evalcontext so no need to handle it - return sortData.mRv; - } - - // Insert nodes in sorted order in new nodeset - for (i = 0; i < len; ++i) { - rv = sortedNodes->append(aNodes->get(indexes[i])); - if (NS_FAILED(rv)) { - PR_Free(mem); - // The txExecutionState owns the evalcontext so no need to handle it - return rv; - } - } - - PR_Free(mem); - delete aEs->popEvalContext(); - - NS_ADDREF(*aResult = sortedNodes); - - return NS_OK; -} - -// static -int -txNodeSorter::compareNodes(const void* aIndexA, const void* aIndexB, - void* aSortData) -{ - SortData* sortData = NS_STATIC_CAST(SortData*, aSortData); - NS_ENSURE_SUCCESS(sortData->mRv, -1); - - txListIterator iter(&sortData->mNodeSorter->mSortKeys); - PRUint32 indexA = *NS_STATIC_CAST(const PRUint32*, aIndexA); - PRUint32 indexB = *NS_STATIC_CAST(const PRUint32*, aIndexB); - TxObject** sortValuesA = sortData->mSortValues + - indexA * sortData->mNodeSorter->mNKeys; - TxObject** sortValuesB = sortData->mSortValues + - indexB * sortData->mNodeSorter->mNKeys; - - int i; - // Step through each key until a difference is found - for (i = 0; i < sortData->mNodeSorter->mNKeys; ++i) { - SortKey* key = (SortKey*)iter.next(); - // Lazy create sort values - if (!sortValuesA[i] && - !calcSortValue(sortValuesA[i], key, sortData, indexA)) { - return -1; - } - if (!sortValuesB[i] && - !calcSortValue(sortValuesB[i], key, sortData, indexB)) { - return -1; - } - - // Compare node values - int compRes = key->mComparator->compareValues(sortValuesA[i], - sortValuesB[i]); - if (compRes != 0) - return compRes; - } - // All keys have the same value for these nodes - - return indexA - indexB; -} - -//static -PRBool -txNodeSorter::calcSortValue(TxObject*& aSortValue, SortKey* aKey, - SortData* aSortData, PRUint32 aNodeIndex) -{ - aSortData->mContext->setPosition(aNodeIndex + 1); // position is 1-based - nsRefPtr res; - nsresult rv = aKey->mExpr->evaluate(aSortData->mContext, - getter_AddRefs(res)); - if (NS_FAILED(rv)) { - aSortData->mRv = rv; - return PR_FALSE; - } - - aSortValue = aKey->mComparator->createSortableValue(res); - if (!aSortValue) { - aSortData->mRv = NS_ERROR_OUT_OF_MEMORY; - return PR_FALSE; - } - - return PR_TRUE; -} diff --git a/extensions/transformiix/source/xslt/util/txNodeSorter.h b/extensions/transformiix/source/xslt/util/txNodeSorter.h deleted file mode 100644 index 6b4eea796240..000000000000 --- a/extensions/transformiix/source/xslt/util/txNodeSorter.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_NODESORTER_H -#define TRANSFRMX_NODESORTER_H - -#include "txCore.h" -#include "List.h" - -class Expr; -class txExecutionState; -class txNodeSet; -class TxObject; -class txXPathResultComparator; -class txIEvalContext; -class txNodeSetContext; - -/* - * Sorts Nodes as specified by the W3C XSLT 1.0 Recommendation - */ - -class txNodeSorter -{ -public: - txNodeSorter(); - ~txNodeSorter(); - - nsresult addSortElement(Expr* aSelectExpr, Expr* aLangExpr, - Expr* aDataTypeExpr, Expr* aOrderExpr, - Expr* aCaseOrderExpr, txIEvalContext* aContext); - nsresult sortNodeSet(txNodeSet* aNodes, txExecutionState* aEs, - txNodeSet** aResult); - -private: - struct SortData - { - txNodeSorter* mNodeSorter; - txNodeSetContext* mContext; - TxObject** mSortValues; - nsresult mRv; - }; - struct SortKey - { - Expr* mExpr; - txXPathResultComparator* mComparator; - }; - - static int compareNodes(const void* aIndexA, const void* aIndexB, - void* aSortData); - static PRBool calcSortValue(TxObject*& aSortValue, SortKey* aKey, - SortData* aSortData, PRUint32 aNodeIndex); - txList mSortKeys; - int mNKeys; -}; - -#endif diff --git a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp b/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp deleted file mode 100644 index b4fcc3f61463..000000000000 --- a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "txXPathResultComparator.h" -#include "Expr.h" -#include "ExprResult.h" -#include "txCore.h" -#ifndef TX_EXE -#include "nsCollationCID.h" -#include "nsILocale.h" -#include "nsILocaleService.h" -#include "nsIServiceManager.h" -#include "nsLocaleCID.h" -#include "prmem.h" - -static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); -#else -#include "txStringUtils.h" -#endif - -#define kAscending (1<<0) -#define kUpperFirst (1<<1) - -txResultStringComparator::txResultStringComparator(MBool aAscending, - MBool aUpperFirst, - const nsAFlatString& aLanguage) -{ - mSorting = 0; - if (aAscending) - mSorting |= kAscending; - if (aUpperFirst) - mSorting |= kUpperFirst; -#ifndef TX_EXE - nsresult rv = init(aLanguage); - if (NS_FAILED(rv)) - NS_ERROR("Failed to initialize txResultStringComparator"); -#endif -} - -txResultStringComparator::~txResultStringComparator() -{ -} - -#ifndef TX_EXE -nsresult txResultStringComparator::init(const nsAFlatString& aLanguage) -{ - nsresult rv; - - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr locale; - if (!aLanguage.IsEmpty()) { - rv = localeService->NewLocale(aLanguage, - getter_AddRefs(locale)); - } - else { - rv = localeService->GetApplicationLocale(getter_AddRefs(locale)); - } - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr colFactory = - do_CreateInstance(kCollationFactoryCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation)); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} -#endif - -TxObject* txResultStringComparator::createSortableValue(txAExprResult* aExprRes) -{ - StringValue* val = new StringValue; - - if (!val) - return 0; - -#ifdef TX_EXE - aExprRes->stringValue(val->mStr); - // We don't support case-order on standalone - TX_ToLowerCase(val->mStr); -#else - if (!mCollation) - return 0; - - val->mCaseKey = new nsString; - if (!val->mCaseKey) { - delete val; - return 0; - } - - nsString& nsCaseKey = *(nsString *)val->mCaseKey; - aExprRes->stringValue(nsCaseKey); - if (nsCaseKey.IsEmpty()) { - return val; - } - nsresult rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, - nsCaseKey, - &val->mKey, - &val->mLength); - if (NS_FAILED(rv)) { - NS_ERROR("Failed to create raw sort key"); - delete val; - return 0; - } -#endif - return val; -} - -int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2) -{ - StringValue* strval1 = (StringValue*)aVal1; - StringValue* strval2 = (StringValue*)aVal2; -#ifdef TX_EXE - PRUint32 len1 = strval1->mStr.Length(); - PRUint32 len2 = strval2->mStr.Length(); - PRUint32 minLength = (len1 < len2) ? len1 : len2; - - PRUint32 c = 0; - while (c < minLength) { - PRUnichar ch1 = strval1->mStr.CharAt(c); - PRUnichar ch2 = strval2->mStr.CharAt(c); - if (ch1 < ch2) - return ((mSorting & kAscending) ? 1 : -1) * -1; - if (ch2 < ch1) - return ((mSorting & kAscending) ? 1 : -1) * 1; - c++; - } - - if (len1 == len2) - return 0; - - return ((mSorting & kAscending) ? 1 : -1) * ((len1 < len2) ? -1 : 1); -#else - if (!mCollation) - return -1; - - if (strval1->mLength == 0) { - if (strval2->mLength == 0) - return 0; - return ((mSorting & kAscending) ? -1 : 1); - } - - if (strval2->mLength == 0) - return ((mSorting & kAscending) ? 1 : -1); - - nsresult rv; - PRInt32 result = -1; - rv = mCollation->CompareRawSortKey(strval1->mKey, strval1->mLength, - strval2->mKey, strval2->mLength, - &result); - if (NS_FAILED(rv)) { - // XXX ErrorReport - return -1; - } - - if (result != 0) - return ((mSorting & kAscending) ? 1 : -1) * result; - - if ((strval1->mCaseLength == 0) && (strval1->mLength != 0)) { - nsString* caseString = (nsString *)strval1->mCaseKey; - rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseSensitive, - *caseString, - (PRUint8**)&strval1->mCaseKey, - &strval1->mCaseLength); - if (NS_FAILED(rv)) { - // XXX ErrorReport - strval1->mCaseKey = caseString; - strval1->mCaseLength = 0; - return -1; - } - delete caseString; - } - if ((strval2->mCaseLength == 0) && (strval2->mLength != 0)) { - nsString* caseString = (nsString *)strval2->mCaseKey; - rv = mCollation->AllocateRawSortKey(nsICollation::kCollationCaseSensitive, - *caseString, - (PRUint8**)&strval2->mCaseKey, - &strval2->mCaseLength); - if (NS_FAILED(rv)) { - // XXX ErrorReport - strval2->mCaseKey = caseString; - strval2->mCaseLength = 0; - return -1; - } - delete caseString; - } - rv = mCollation->CompareRawSortKey((PRUint8*)strval1->mCaseKey, strval1->mCaseLength, - (PRUint8*)strval2->mCaseKey, strval2->mCaseLength, - &result); - if (NS_FAILED(rv)) { - // XXX ErrorReport - return -1; - } - - return ((mSorting & kAscending) ? 1 : -1) * - ((mSorting & kUpperFirst) ? -1 : 1) * result; -#endif -} - -#ifndef TX_EXE -txResultStringComparator::StringValue::StringValue() : mKey(0), - mCaseKey(0), - mLength(0), - mCaseLength(0) -{ -} - -txResultStringComparator::StringValue::~StringValue() -{ - PR_Free(mKey); - if (mCaseLength > 0) - PR_Free((PRUint8*)mCaseKey); - else - delete (nsString*)mCaseKey; -} -#endif - -txResultNumberComparator::txResultNumberComparator(MBool aAscending) -{ - mAscending = aAscending ? 1 : -1; -} - -txResultNumberComparator::~txResultNumberComparator() -{ -} - -TxObject* txResultNumberComparator::createSortableValue(txAExprResult* aExprRes) -{ - NumberValue* numval = new NumberValue; - if (numval) - numval->mVal = aExprRes->numberValue(); - return numval; -} - -int txResultNumberComparator::compareValues(TxObject* aVal1, TxObject* aVal2) -{ - double dval1 = ((NumberValue*)aVal1)->mVal; - double dval2 = ((NumberValue*)aVal2)->mVal; - - if (Double::isNaN(dval1)) - return Double::isNaN(dval2) ? 0 : -mAscending; - - if (Double::isNaN(dval2)) - return mAscending; - - if (dval1 == dval2) - return 0; - - return (dval1 < dval2) ? -mAscending : mAscending; -} diff --git a/extensions/transformiix/source/xslt/util/txXPathResultComparator.h b/extensions/transformiix/source/xslt/util/txXPathResultComparator.h deleted file mode 100644 index 80a8f36b10df..000000000000 --- a/extensions/transformiix/source/xslt/util/txXPathResultComparator.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is TransforMiiX XSLT processor code. - * - * The Initial Developer of the Original Code is - * Jonas Sicking. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jonas Sicking - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TRANSFRMX_XPATHRESULTCOMPARATOR_H -#define TRANSFRMX_XPATHRESULTCOMPARATOR_H - -#include "txCore.h" -#ifndef TX_EXE -#include "nsCOMPtr.h" -#include "nsICollation.h" -#endif -#include "nsString.h" - -class txAExprResult; - -/* - * Result comparators - */ -class txXPathResultComparator -{ -public: - virtual ~txXPathResultComparator() - { - } - - /* - * Compares two XPath results. Returns -1 if val1 < val2, - * 1 if val1 > val2 and 0 if val1 == val2. - */ - virtual int compareValues(TxObject* val1, TxObject* val2) = 0; - - /* - * Create a sortable value. - */ - virtual TxObject* createSortableValue(txAExprResult* exprRes) = 0; -}; - -/* - * Compare results as stings (data-type="text") - */ -class txResultStringComparator : public txXPathResultComparator -{ -public: - txResultStringComparator(MBool aAscending, MBool aUpperFirst, - const nsAFlatString& aLanguage); - virtual ~txResultStringComparator(); - - int compareValues(TxObject* aVal1, TxObject* aVal2); - TxObject* createSortableValue(txAExprResult* aExprRes); -private: -#ifndef TX_EXE - nsCOMPtr mCollation; - nsresult init(const nsAFlatString& aLanguage); - nsresult createRawSortKey(const PRInt32 aStrength, - const nsString& aString, - PRUint8** aKey, - PRUint32* aLength); -#endif - int mSorting; - - class StringValue : public TxObject - { - public: -#ifdef TX_EXE - nsString mStr; -#else - StringValue(); - ~StringValue(); - - PRUint8* mKey; - void* mCaseKey; - PRUint32 mLength, mCaseLength; -#endif - }; -}; - -/* - * Compare results as numbers (data-type="number") - */ -class txResultNumberComparator : public txXPathResultComparator -{ -public: - txResultNumberComparator(MBool aAscending); - virtual ~txResultNumberComparator(); - - int compareValues(TxObject* aVal1, TxObject* aVal2); - TxObject* createSortableValue(txAExprResult* aExprRes); - -private: - int mAscending; - - class NumberValue : public TxObject - { - public: - double mVal; - }; -}; - -#endif