1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include "transform.h"
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include "transformation_facade.h"
#include "support/xerces_string_guard.h"
namespace {
using InputXSLT::XercesStringGuard;
xercesc::DOMDocument* constructDocument(
const InputXSLT::FilesystemContext&,
const boost::filesystem::path& transformationPath,
const boost::filesystem::path& targetPath
) {
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
nullptr,
*XercesStringGuard<XMLCh>("content"),
nullptr
)
);
xercesc::DOMNode* const rootNode(
domDocument->getDocumentElement()
);
InputXSLT::TransformationFacade transformation(
transformationPath.string()
);
const int result = transformation.generate(
targetPath.string()
);
if ( result == 0 ) {
xercesc::DOMElement* const resultNode(
domDocument->createElement(*XercesStringGuard<XMLCh>("result"))
);
resultNode->setAttribute(
*XercesStringGuard<XMLCh>("name"),
*XercesStringGuard<XMLCh>(targetPath.string())
);
rootNode->appendChild(resultNode);
} else {
xercesc::DOMElement* const resultNode(
domDocument->createElement(*XercesStringGuard<XMLCh>("error"))
);
rootNode->appendChild(resultNode);
}
return domDocument;
}
}
namespace InputXSLT {
FunctionTransform::FunctionTransform():
document_cache_(std::make_shared<DomDocumentCache>()) { }
xalan::XObjectPtr FunctionTransform::execute(
xalan::XPathExecutionContext& executionContext,
xalan::XalanNode*,
const xalan::XObjectPtr argument1,
const xalan::XObjectPtr argument2,
const xalan::Locator* locator
) const {
const FilesystemContext fsContext(locator);
xalan::XalanDocument* const domDocument(
this->document_cache_->create(
constructDocument(
fsContext,
fsContext.resolve(argument1->str()),
fsContext.resolve(argument2->str())
)
)
);
xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
executionContext
);
nodeList->addNodes(
*domDocument->getDocumentElement()->getChildNodes()
);
return executionContext.getXObjectFactory().createNodeSet(nodeList);
}
FunctionTransform* FunctionTransform::clone(
xalan::MemoryManager& manager) const {
return xalan::XalanCopyConstruct(
manager,
*this
);
}
const xalan::XalanDOMString& FunctionTransform::getError(
xalan::XalanDOMString& result) const {
result.assign("The function expects two arguments of type string.");
return result;
}
}
|