19package org.openoffice.xmerge.converter.xml.xslt;
21import org.w3c.dom.NodeList;
22import org.w3c.dom.Node;
23import org.w3c.dom.Element;
26import java.io.IOException;
27import java.io.ByteArrayOutputStream;
28import java.io.ByteArrayInputStream;
39import javax.xml.transform.TransformerFactory;
40import javax.xml.transform.Transformer;
41import javax.xml.transform.stream.StreamSource;
42import javax.xml.transform.stream.StreamResult;
43import javax.xml.transform.dom.DOMSource;
44import javax.xml.transform.TransformerException;
45import javax.xml.transform.URIResolver;
46import javax.xml.transform.Source;
48import javax.xml.parsers.DocumentBuilder;
49import javax.xml.parsers.DocumentBuilderFactory;
92 org.w3c.dom.Document domDoc =
sxwDoc.getContentDOM();
93 org.w3c.dom.Document metaDoc =
sxwDoc.getMetaDOM();
94 org.w3c.dom.Document styleDoc =
sxwDoc.getStyleDOM();
95 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
97 Node offnode = domDoc.getDocumentElement();
98 if (!(offnode.getNodeName()).equals(
"office:document")) {
100 DocumentBuilderFactory builderFactory = DocumentBuilderFactory
102 DocumentBuilder builder = builderFactory.newDocumentBuilder();
103 DOMImplementation domImpl = builder.getDOMImplementation();
106 "-//OpenOffice.org//DTD OfficeDocument 1.0//EN",
null);
107 org.w3c.dom.Document newDoc = domImpl.createDocument(
108 "http://openoffice.org/2000/office",
"office:document",
111 Element rootElement = newDoc.getDocumentElement();
112 rootElement.setAttribute(
"xmlns:office",
113 "http://openoffice.org/2000/office");
114 rootElement.setAttribute(
"xmlns:style",
115 "http://openoffice.org/2000/style");
116 rootElement.setAttribute(
"xmlns:text",
117 "http://openoffice.org/2000/text");
118 rootElement.setAttribute(
"xmlns:table",
119 "http://openoffice.org/2000/table");
121 rootElement.setAttribute(
"xmlns:draw",
122 "http://openoffice.org/2000/drawing");
123 rootElement.setAttribute(
"xmlns:fo",
124 "http://www.w3.org/1999/XSL/Format");
125 rootElement.setAttribute(
"xmlns:xlink",
126 "http://www.w3.org/1999/xlink");
127 rootElement.setAttribute(
"xmlns:dc",
128 "http://purl.org/dc/elements/1.1/");
129 rootElement.setAttribute(
"xmlns:meta",
130 "http://openoffice.org/2000/meta");
131 rootElement.setAttribute(
"xmlns:number",
132 "http://openoffice.org/2000/datastyle");
133 rootElement.setAttribute(
"xmlns:svg",
134 "http://www.w3.org/2000/svg");
135 rootElement.setAttribute(
"xmlns:chart",
136 "http://openoffice.org/2000/chart");
137 rootElement.setAttribute(
"xmlns:dr3d",
138 "http://openoffice.org/2000/dr3d");
139 rootElement.setAttribute(
"xmlns:math",
140 "http://www.w3.org/1998/Math/MathML");
141 rootElement.setAttribute(
"xmlns:form",
142 "http://openoffice.org/2000/form");
143 rootElement.setAttribute(
"xmlns:script",
144 "http://openoffice.org/2000/script");
145 rootElement.setAttribute(
"xmlns:config",
146 "http://openoffice.org/2001/config");
147 rootElement.setAttribute(
"office:class",
"text");
148 rootElement.setAttribute(
"office:version",
"1.0");
152 Node rootNode = rootElement;
153 if (metaDoc !=
null) {
155 if (nodeList.getLength() > 0) {
156 tmpNode = newDoc.importNode(nodeList.item(0),
true);
157 rootNode.appendChild(tmpNode);
160 if (styleDoc !=
null) {
162 if (nodeList.getLength() > 0) {
163 tmpNode = newDoc.importNode(nodeList.item(0),
true);
164 rootNode.appendChild(tmpNode);
169 if (nodeList.getLength() > 0) {
170 tmpNode = newDoc.importNode(nodeList.item(0),
true);
171 rootNode.appendChild(tmpNode);
174 if (nodeList.getLength() > 0) {
175 tmpNode = newDoc.importNode(nodeList.item(0),
true);
176 rootNode.appendChild(tmpNode);
181 .println(
"\nAn Exception occurred with Xslt Serializer"
190 System.out.println(
"\n Error with Xslt\n");
194 .createDeviceDocument(docName,
195 new ByteArrayInputStream(baos.toByteArray()));
201 throws TransformerException {
203 if (href.equals(
"javax.xml.transform.dom.DOMSource") || href.length() == 0) {
209 StreamSource sheetFile =
new StreamSource(newhRef);
212 System.out.println(
"\nException in Xslt Resolver " + e);
231 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
234 DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
235 dFactory.setNamespaceAware(
true);
237 DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
240 teststr = teststr.substring(0, 6);
241 org.w3c.dom.Document xslDoc =
null;
242 if ((teststr.equals(
"http:/")) || (teststr.equals(
"file:/"))
243 || (teststr.equals(
"jar://"))) {
248 xslDoc = dBuilder.parse(
252 DOMSource xslDomSource =
new DOMSource(xslDoc);
253 DOMSource xmlDomSource =
new DOMSource(domDoc);
256 TransformerFactory tFactory = TransformerFactory.newInstance();
257 tFactory.setURIResolver(
this);
258 Transformer transformer = tFactory.newTransformer(xslDomSource);
260 transformer.transform(xmlDomSource,
new StreamResult(baos));
262 System.out.println(
"An error occurred in the transformation : " + e);
ConvertData is used as a container for passing Document objects in and out of the Convert class.
void addDocument(Document doc)
Adds a Document to the vector.
This Exception is thrown by convert algorithms.
ConverterInfo getConverterInfo()
Returns the ConvertInfo that corresponds to this plug-in.
An implementation of Document for StarOffice documents.
Xslt implementation of org.openoffice.xmerge.DocumentSerializer for the PluginFactoryImpl.
DocumentSerializerImpl(PluginFactoryImpl pf, Document doc)
Constructor.
ByteArrayOutputStream transform(org.w3c.dom.Document domDoc)
This method performs the xsl transformation on the supplied Document and returns a DOMResult object.
final GenericOfficeDocument sxwDoc
SXW Document object that this converter processes.
final PluginFactoryImpl pluginFactory
Source resolve(String href, String base)
ConvertData serialize()
Method to convert a Document with an xsl stylesheet.
This class is an implementation of OfficeDocument for the generic office format.
Xslt implementation of the PluginFactory.
Class for storing the information about a converter plug-in.
String getJarName()
Returns the jar file name.
String getXsltSerial()
Returns a String containing the Xslt stylesheet URL that is to be used by the Xslt Plug-in Serializer...
A DocumentSerializer represents a converter that converts a "Office" Document to a "Device" Document ...
A Document represents any Document to be converted and the resulting Document from any conversion.
This interface contains constants for StarOffice XML tags, attributes (StarCalc cell types,...
String TAG_OFFICE_META
Element tag for office:meta.
String TAG_OFFICE_BODY
Element tag for office:body.
String TAG_OFFICE_AUTOMATIC_STYLES
Element tag for office:automatic-styles.
String TAG_OFFICE_STYLES
Element tag for office:styles.
Provides classes for converting basic document types to/from a DOMDocument object,...
Document and PluginFactory implementations for XML based formats.
Provides an interface for plug-in registration.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...