summaryrefslogtreecommitdiff
path: root/xmerge
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-08-21 09:07:44 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-08-28 16:15:43 +0200
commit4e2c95c786ecd5931e6fb7f2ceda5c203350f305 (patch)
treed95d9c8d3372b78250732d837ce6e433078acd0b /xmerge
parent0439c5189a81aa74e2e998b773cf7a4b1271c83f (diff)
Java cleanup - remove unnecessary null checks
Change-Id: I72a847b1180e9aeb8dec18bcaedee7286eee7754
Diffstat (limited to 'xmerge')
-rw-r--r--xmerge/source/wordsmith/java/org/openoffice/xmerge/converter/xml/sxw/wordsmith/WseHeader.java4
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java187
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java184
3 files changed, 199 insertions, 176 deletions
diff --git a/xmerge/source/wordsmith/java/org/openoffice/xmerge/converter/xml/sxw/wordsmith/WseHeader.java b/xmerge/source/wordsmith/java/org/openoffice/xmerge/converter/xml/sxw/wordsmith/WseHeader.java
index c620f2127f9e..cd4a125fed44 100644
--- a/xmerge/source/wordsmith/java/org/openoffice/xmerge/converter/xml/sxw/wordsmith/WseHeader.java
+++ b/xmerge/source/wordsmith/java/org/openoffice/xmerge/converter/xml/sxw/wordsmith/WseHeader.java
@@ -127,9 +127,7 @@ class WseHeader extends Wse {
e.printStackTrace();
}
- if (bs != null) {
- return bs.toByteArray();
- } else return null;
+ return bs.toByteArray();
}
}
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
index c1ab7f9b4fc2..d51dcfe34cb2 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
@@ -510,106 +510,107 @@ public abstract class OfficeDocument
throw new OfficeDocumentException(ex);
}
- if (isZip)
- {
+ if (isZip) {
read(is);
- }
- else{
- try{
- Reader r = secondHack(is);
- InputSource ins = new InputSource(r);
- org.w3c.dom.Document newDoc = builder.parse(ins);
- Element rootElement=newDoc.getDocumentElement();
-
- NodeList nodeList;
- Node tmpNode;
- Node rootNode = rootElement;
- if (newDoc !=null){
- /*content*/
- contentDoc = createDOM(TAG_OFFICE_DOCUMENT_CONTENT);
- rootElement=contentDoc.getDocumentElement();
- rootNode = rootElement;
-
- // FIX (HJ): Include office:font-decls in content DOM
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_FONT_DECLS);
- if (nodeList.getLength()>0){
- tmpNode = contentDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = contentDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_BODY);
- if (nodeList.getLength()>0){
- tmpNode = contentDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- /*Styles*/
- styleDoc = createDOM(TAG_OFFICE_DOCUMENT_STYLES);
- rootElement=styleDoc.getDocumentElement();
- rootNode = rootElement;
-
- // FIX (HJ): Include office:font-decls in styles DOM
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_FONT_DECLS);
- if (nodeList.getLength()>0){
- tmpNode = styleDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = styleDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- // FIX (HJ): Include office:automatic-styles in styles DOM
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = styleDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- // FIX (HJ): Include office:master-styles in styles DOM
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_MASTER_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = styleDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
-
- /*Settings*/
- settingsDoc = createDOM(TAG_OFFICE_DOCUMENT_SETTINGS);
- rootElement=settingsDoc.getDocumentElement();
- rootNode = rootElement;
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_SETTINGS);
- if (nodeList.getLength()>0){
- tmpNode = settingsDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
- /*Meta*/
- metaDoc = createDOM(TAG_OFFICE_DOCUMENT_META);
- rootElement=metaDoc.getDocumentElement();
- rootNode = rootElement;
- nodeList= newDoc.getElementsByTagName(TAG_OFFICE_META);
- if (nodeList.getLength()>0){
- tmpNode = metaDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
+ } else {
+ try {
+ Reader r = secondHack(is);
+ InputSource ins = new InputSource(r);
+ org.w3c.dom.Document newDoc = builder.parse(ins);
+ Element rootElement = newDoc.getDocumentElement();
+
+ NodeList nodeList;
+ Node tmpNode;
+ Node rootNode = rootElement;
+
+ /* content */
+ contentDoc = createDOM(TAG_OFFICE_DOCUMENT_CONTENT);
+ rootElement = contentDoc.getDocumentElement();
+ rootNode = rootElement;
+
+ // FIX (HJ): Include office:font-decls in content DOM
+ nodeList = newDoc
+ .getElementsByTagName(TAG_OFFICE_FONT_DECLS);
+ if (nodeList.getLength() > 0) {
+ tmpNode = contentDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
}
+
+ nodeList = newDoc
+ .getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = contentDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ nodeList = newDoc.getElementsByTagName(TAG_OFFICE_BODY);
+ if (nodeList.getLength() > 0) {
+ tmpNode = contentDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ /* Styles */
+ styleDoc = createDOM(TAG_OFFICE_DOCUMENT_STYLES);
+ rootElement = styleDoc.getDocumentElement();
+ rootNode = rootElement;
+
+ // FIX (HJ): Include office:font-decls in styles DOM
+ nodeList = newDoc
+ .getElementsByTagName(TAG_OFFICE_FONT_DECLS);
+ if (nodeList.getLength() > 0) {
+ tmpNode = styleDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ nodeList = newDoc.getElementsByTagName(TAG_OFFICE_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = styleDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ // FIX (HJ): Include office:automatic-styles in styles DOM
+ nodeList = newDoc
+ .getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = styleDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ // FIX (HJ): Include office:master-styles in styles DOM
+ nodeList = newDoc
+ .getElementsByTagName(TAG_OFFICE_MASTER_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = styleDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+
+ /* Settings */
+ settingsDoc = createDOM(TAG_OFFICE_DOCUMENT_SETTINGS);
+ rootElement = settingsDoc.getDocumentElement();
+ rootNode = rootElement;
+ nodeList = newDoc.getElementsByTagName(TAG_OFFICE_SETTINGS);
+ if (nodeList.getLength() > 0) {
+ tmpNode = settingsDoc
+ .importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ /* Meta */
+ metaDoc = createDOM(TAG_OFFICE_DOCUMENT_META);
+ rootElement = metaDoc.getDocumentElement();
+ rootNode = rootElement;
+ nodeList = newDoc.getElementsByTagName(TAG_OFFICE_META);
+ if (nodeList.getLength() > 0) {
+ tmpNode = metaDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ } catch (SAXException ex) {
+ throw new OfficeDocumentException(ex);
+ }
}
- catch (SAXException ex) {
- throw new OfficeDocumentException(ex);
- }
- }
}
-
/**
* Parse given <code>byte</code> array into a DOM
* <code>Document</code> object using the
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java
index 911e6a6599f5..a347280c300b 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java
@@ -100,89 +100,113 @@ public final class DocumentSerializerImpl
* @throws IOException If any I/O error occurs.
*/
public ConvertData serialize() throws ConvertException, IOException {
- String docName = sxwDoc.getName();
- org.w3c.dom.Document domDoc = sxwDoc.getContentDOM();
- org.w3c.dom.Document metaDoc = sxwDoc.getMetaDOM();
- org.w3c.dom.Document styleDoc = sxwDoc.getStyleDOM();
- ByteArrayOutputStream baos= new ByteArrayOutputStream();
- ConvertData cd = new ConvertData();
- Node offnode = domDoc.getDocumentElement();
- if (!(offnode.getNodeName()).equals("office:document")){
- try{
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder= builderFactory.newDocumentBuilder();
- DOMImplementation domImpl = builder.getDOMImplementation();
- DocumentType docType =domImpl.createDocumentType("office:document","-//OpenOffice.org//DTD OfficeDocument 1.0//EN",null);
- org.w3c.dom.Document newDoc = domImpl.createDocument("http://openoffice.org/2000/office","office:document",docType);
-
-
- Element rootElement=newDoc.getDocumentElement();
- rootElement.setAttribute("xmlns:office","http://openoffice.org/2000/office");
- rootElement.setAttribute("xmlns:style","http://openoffice.org/2000/style" );
- rootElement.setAttribute("xmlns:text","http://openoffice.org/2000/text");
- rootElement.setAttribute("xmlns:table","http://openoffice.org/2000/table");
-
- rootElement.setAttribute("xmlns:draw","http://openoffice.org/2000/drawing");
- rootElement.setAttribute("xmlns:fo","http://www.w3.org/1999/XSL/Format" );
- rootElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink" );
- rootElement.setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/" );
- rootElement.setAttribute("xmlns:meta","http://openoffice.org/2000/meta" );
- rootElement.setAttribute("xmlns:number","http://openoffice.org/2000/datastyle" );
- rootElement.setAttribute("xmlns:svg","http://www.w3.org/2000/svg" );
- rootElement.setAttribute("xmlns:chart","http://openoffice.org/2000/chart" );
- rootElement.setAttribute("xmlns:dr3d","http://openoffice.org/2000/dr3d" );
- rootElement.setAttribute("xmlns:math","http://www.w3.org/1998/Math/MathML" );
- rootElement.setAttribute("xmlns:form","http://openoffice.org/2000/form" );
- rootElement.setAttribute("xmlns:script","http://openoffice.org/2000/script" );
- rootElement.setAttribute("xmlns:config","http://openoffice.org/2001/config" );
- rootElement.setAttribute("office:class","text" );
- rootElement.setAttribute("office:version","1.0");
-
-
- NodeList nodeList;
- Node tmpNode;
- Node rootNode = rootElement;
- if (metaDoc !=null){
- nodeList= metaDoc.getElementsByTagName(TAG_OFFICE_META);
- if (nodeList.getLength()>0){
- tmpNode = newDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
- } if (styleDoc !=null){
- nodeList= styleDoc.getElementsByTagName(TAG_OFFICE_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = newDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
- }if (domDoc !=null){
- nodeList= domDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
- if (nodeList.getLength()>0){
- tmpNode = newDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
- nodeList= domDoc.getElementsByTagName(TAG_OFFICE_BODY);
- if (nodeList.getLength()>0){
- tmpNode = newDoc.importNode(nodeList.item(0),true);
- rootNode.appendChild(tmpNode);
- }
- }
- domDoc=newDoc;
- }catch(Exception e){
- System.out.println("\nAn Exception occurred with Xslt Serializer"+e);
- }
+ String docName = sxwDoc.getName();
+ org.w3c.dom.Document domDoc = sxwDoc.getContentDOM();
+ org.w3c.dom.Document metaDoc = sxwDoc.getMetaDOM();
+ org.w3c.dom.Document styleDoc = sxwDoc.getStyleDOM();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ConvertData cd = new ConvertData();
+ Node offnode = domDoc.getDocumentElement();
+ if (!(offnode.getNodeName()).equals("office:document")) {
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = builderFactory.newDocumentBuilder();
+ DOMImplementation domImpl = builder.getDOMImplementation();
+ DocumentType docType = domImpl.createDocumentType(
+ "office:document",
+ "-//OpenOffice.org//DTD OfficeDocument 1.0//EN", null);
+ org.w3c.dom.Document newDoc = domImpl.createDocument(
+ "http://openoffice.org/2000/office", "office:document",
+ docType);
+
+ Element rootElement = newDoc.getDocumentElement();
+ rootElement.setAttribute("xmlns:office",
+ "http://openoffice.org/2000/office");
+ rootElement.setAttribute("xmlns:style",
+ "http://openoffice.org/2000/style");
+ rootElement.setAttribute("xmlns:text",
+ "http://openoffice.org/2000/text");
+ rootElement.setAttribute("xmlns:table",
+ "http://openoffice.org/2000/table");
+
+ rootElement.setAttribute("xmlns:draw",
+ "http://openoffice.org/2000/drawing");
+ rootElement.setAttribute("xmlns:fo",
+ "http://www.w3.org/1999/XSL/Format");
+ rootElement.setAttribute("xmlns:xlink",
+ "http://www.w3.org/1999/xlink");
+ rootElement.setAttribute("xmlns:dc",
+ "http://purl.org/dc/elements/1.1/");
+ rootElement.setAttribute("xmlns:meta",
+ "http://openoffice.org/2000/meta");
+ rootElement.setAttribute("xmlns:number",
+ "http://openoffice.org/2000/datastyle");
+ rootElement.setAttribute("xmlns:svg",
+ "http://www.w3.org/2000/svg");
+ rootElement.setAttribute("xmlns:chart",
+ "http://openoffice.org/2000/chart");
+ rootElement.setAttribute("xmlns:dr3d",
+ "http://openoffice.org/2000/dr3d");
+ rootElement.setAttribute("xmlns:math",
+ "http://www.w3.org/1998/Math/MathML");
+ rootElement.setAttribute("xmlns:form",
+ "http://openoffice.org/2000/form");
+ rootElement.setAttribute("xmlns:script",
+ "http://openoffice.org/2000/script");
+ rootElement.setAttribute("xmlns:config",
+ "http://openoffice.org/2001/config");
+ rootElement.setAttribute("office:class", "text");
+ rootElement.setAttribute("office:version", "1.0");
+
+ NodeList nodeList;
+ Node tmpNode;
+ Node rootNode = rootElement;
+ if (metaDoc != null) {
+ nodeList = metaDoc.getElementsByTagName(TAG_OFFICE_META);
+ if (nodeList.getLength() > 0) {
+ tmpNode = newDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ }
+ if (styleDoc != null) {
+ nodeList = styleDoc.getElementsByTagName(TAG_OFFICE_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = newDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ }
+ nodeList = domDoc
+ .getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
+ if (nodeList.getLength() > 0) {
+ tmpNode = newDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ nodeList = domDoc.getElementsByTagName(TAG_OFFICE_BODY);
+ if (nodeList.getLength() > 0) {
+ tmpNode = newDoc.importNode(nodeList.item(0), true);
+ rootNode.appendChild(tmpNode);
+ }
+ domDoc = newDoc;
+ } catch (Exception e) {
+ System.out
+ .println("\nAn Exception occurred with Xslt Serializer"
+ + e);
+ }
- }
+ }
- try{
- baos=transform(domDoc);
- }
- catch (Exception e){
- System.out.println("\n Error with Xslt\n");
- }
+ try {
+ baos = transform(domDoc);
+ } catch (Exception e) {
+ System.out.println("\n Error with Xslt\n");
+ }
- DOMDocument resultDomDoc=(DOMDocument)pluginFactory.createDeviceDocument(docName,new ByteArrayInputStream(baos.toByteArray()));
- cd.addDocument (resultDomDoc);
- return cd;
+ DOMDocument resultDomDoc = (DOMDocument) pluginFactory
+ .createDeviceDocument(docName,
+ new ByteArrayInputStream(baos.toByteArray()));
+ cd.addDocument(resultDomDoc);
+ return cd;
}
public Source resolve(String href,String base)