Base Framework
testsuite/xsltprocessor.cpp
/***************************************************************************
The Base Framework
A framework for developing platform independent applications
See COPYRIGHT.txt for details.
This framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the licensing terms refer to the file 'LICENSE'.
***************************************************************************/
#include <base/Application.h>
#include <base/string/FormatOutputStream.h>
#include <base/io/File.h>
#include <base/xml/Document.h>
#include <base/xml/Stylesheet.h>
#include <base/xml/Transformer.h>
#include <base/collection/Stack.h>
#include <base/collection/Array.h>
using namespace com::azure::dev::base;
class XSLTProcessorApplication : public Application {
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
XSLTProcessorApplication()
: Application("xsltprocessor")
{
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
Array<String> arguments = getArguments();
if (arguments.getSize() != 3) {
fout << getFormalName() << " source destination" << ENDL;
return; // stop
}
const String sourceName = arguments[0];
const String destinationName = arguments[1];
{
fout << "Reading XML file into buffer..." << ENDL;
File file(sourceName, File::READ, File::EXCLUSIVE);
buffer.setSize(file.getSize());
file.read(buffer.getElements(), file.getSize());
}
fout << "Reading document" << ENDL;
Document source = dom.createFromURI(sourceName);
source.save(sourceName + ".saved");
fout << "Reading stylesheet..." << ENDL;
Document xslDocument = dom.createFromURI(destinationName);
xslDocument.save(destinationName + ".saved");
Stylesheet stylesheet(xslDocument);
fout << "Stylesheet" << EOL
<< indent(2) << "output method: "
<< stylesheet.getOutputMethod() << EOL
<< indent(2) << "namespace: "
<< stylesheet.getNamespace() << EOL
<< indent(2) << "version: "
<< stylesheet.getVersion() << EOL
<< indent(2) << "encoding: "
<< stylesheet.getEncoding() << EOL
<< ENDL;
// fout << "Excluded prefixes: "
// << stylesheet.getExcludedPrefixes() << ENDL;
Transformer transformer;
transformer.setParameter(
MESSAGE("projectname"),
MESSAGE("Base framework")
);
transformer.setStylesheet(stylesheet);
fout << "Transforming document..." << ENDL;
Document result = transformer.transform(source);
fout << "Saving result document..." << ENDL;
transformer.save(arguments[2], result);
}
};
APPLICATION_STUB(XSLTProcessorApplication);
File::READ
@ READ
Definition: File.h:64
Stylesheet
Stylesheet.
Definition: Stylesheet.h:30
DOMImplementation::createFromURI
Document createFromURI(const String &systemId, Mode mode=VALIDATING, unsigned int flags=WARNINGS|PEDANTIC|DETECT_IDS|COMPLETE_ATTRIBUTE_LISTS)
Document::save
void save(const String &filename)
Allocator< uint8 >
Document
DOM document.
Definition: Document.h:47
Transformer::transform
Document transform(const Document &document)
File
File.
Definition: File.h:37
String
String.
Definition: String.h:102
Array::getSize
MemorySize getSize() const noexcept
Definition: Array.h:339
Allocator::getElements
TYPE * getElements() noexcept
Definition: Allocator.h:427
File::read
unsigned int read(uint8 *buffer, unsigned int size, bool nonblocking=false)
Application
Application.
Definition: Application.h:53
File::EXCLUSIVE
@ EXCLUSIVE
Definition: File.h:69
Allocator::setSize
void setSize(MemorySize size)
Definition: Allocator.h:668
Transformer::setStylesheet
void setStylesheet(Stylesheet stylesheet) noexcept
File::getSize
long long getSize() const
DOMImplementation
DOM implementation.
Definition: DOMImplementation.h:32
Transformer::save
void save(const String &filename, const Document &document)
Array< String >
Transformer::setParameter
void setParameter(const String &name, const String &value)
Transformer
XSLT transformer.
Definition: Transformer.h:40