Java cleanup - remove unnecessary null checks

Change-Id: I72a847b1180e9aeb8dec18bcaedee7286eee7754
This commit is contained in:
Noel Grandin
2012-08-21 09:07:44 +02:00
committed by Stephan Bergmann
parent 0439c5189a
commit 4e2c95c786
7 changed files with 204 additions and 189 deletions

View File

@@ -253,10 +253,8 @@ public class List extends DescendantManager implements javax.accessibility.Acces
XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext();
if (xAccessibleContext != null) { if (xAccessibleContext != null) {
javax.accessibility.AccessibleContext ac = new AccessibleListItem(xAccessibleContext); javax.accessibility.AccessibleContext ac = new AccessibleListItem(xAccessibleContext);
if (ac != null) {
ac.setAccessibleParent(List.this); ac.setAccessibleParent(List.this);
accessibleContext = ac; accessibleContext = ac;
}
AccessibleStateAdapter.setComponentState(this, xAccessibleContext.getAccessibleStateSet()); AccessibleStateAdapter.setComponentState(this, xAccessibleContext.getAccessibleStateSet());
} }
} catch (com.sun.star.uno.RuntimeException e) { } catch (com.sun.star.uno.RuntimeException e) {

View File

@@ -479,11 +479,9 @@ public class Table extends DescendantManager implements javax.accessibility.Acce
XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext();
if (xAccessibleContext != null) { if (xAccessibleContext != null) {
javax.accessibility.AccessibleContext ac = new AccessibleTableCell(xAccessibleContext); javax.accessibility.AccessibleContext ac = new AccessibleTableCell(xAccessibleContext);
if (ac != null) {
ac.setAccessibleParent(Table.this); ac.setAccessibleParent(Table.this);
accessibleContext = ac; accessibleContext = ac;
} }
}
} catch (com.sun.star.uno.RuntimeException e) { } catch (com.sun.star.uno.RuntimeException e) {
} }
} }

View File

@@ -491,11 +491,9 @@ public class Tree extends DescendantManager implements javax.accessibility.Acces
XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext(); XAccessibleContext xAccessibleContext = unoAccessible.getAccessibleContext();
if (xAccessibleContext != null) { if (xAccessibleContext != null) {
javax.accessibility.AccessibleContext ac = new AccessibleTreeItem(xAccessibleContext); javax.accessibility.AccessibleContext ac = new AccessibleTreeItem(xAccessibleContext);
if (ac != null) {
ac.setAccessibleParent(Tree.this); ac.setAccessibleParent(Tree.this);
accessibleContext = ac; accessibleContext = ac;
} }
}
} catch (com.sun.star.uno.RuntimeException e) { } catch (com.sun.star.uno.RuntimeException e) {
} }
} }

View File

@@ -350,14 +350,12 @@ final class InstallationFinder {
"reading which command output failed: " + e ); "reading which command output failed: " + e );
return null; return null;
} finally { } finally {
if ( br != null ) {
try { try {
br.close(); br.close();
} catch ( IOException e ) { } catch ( IOException e ) {
// closing standard input stream failed, ignore // closing standard input stream failed, ignore
} }
} }
}
try { try {
// wait until the which process has terminated // wait until the which process has terminated

View File

@@ -127,9 +127,7 @@ class WseHeader extends Wse {
e.printStackTrace(); e.printStackTrace();
} }
if (bs != null) {
return bs.toByteArray(); return bs.toByteArray();
} else return null;
} }
} }

View File

@@ -510,98 +510,100 @@ public abstract class OfficeDocument
throw new OfficeDocumentException(ex); throw new OfficeDocumentException(ex);
} }
if (isZip) if (isZip) {
{
read(is); read(is);
} } else {
else{ try {
try{
Reader r = secondHack(is); Reader r = secondHack(is);
InputSource ins = new InputSource(r); InputSource ins = new InputSource(r);
org.w3c.dom.Document newDoc = builder.parse(ins); org.w3c.dom.Document newDoc = builder.parse(ins);
Element rootElement=newDoc.getDocumentElement(); Element rootElement = newDoc.getDocumentElement();
NodeList nodeList; NodeList nodeList;
Node tmpNode; Node tmpNode;
Node rootNode = rootElement; Node rootNode = rootElement;
if (newDoc !=null){
/*content*/ /* content */
contentDoc = createDOM(TAG_OFFICE_DOCUMENT_CONTENT); contentDoc = createDOM(TAG_OFFICE_DOCUMENT_CONTENT);
rootElement=contentDoc.getDocumentElement(); rootElement = contentDoc.getDocumentElement();
rootNode = rootElement; rootNode = rootElement;
// FIX (HJ): Include office:font-decls in content DOM // FIX (HJ): Include office:font-decls in content DOM
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_FONT_DECLS); nodeList = newDoc
if (nodeList.getLength()>0){ .getElementsByTagName(TAG_OFFICE_FONT_DECLS);
tmpNode = contentDoc.importNode(nodeList.item(0),true); if (nodeList.getLength() > 0) {
tmpNode = contentDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES); nodeList = newDoc
if (nodeList.getLength()>0){ .getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
tmpNode = contentDoc.importNode(nodeList.item(0),true); if (nodeList.getLength() > 0) {
tmpNode = contentDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_BODY); nodeList = newDoc.getElementsByTagName(TAG_OFFICE_BODY);
if (nodeList.getLength()>0){ if (nodeList.getLength() > 0) {
tmpNode = contentDoc.importNode(nodeList.item(0),true); tmpNode = contentDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
/*Styles*/ /* Styles */
styleDoc = createDOM(TAG_OFFICE_DOCUMENT_STYLES); styleDoc = createDOM(TAG_OFFICE_DOCUMENT_STYLES);
rootElement=styleDoc.getDocumentElement(); rootElement = styleDoc.getDocumentElement();
rootNode = rootElement; rootNode = rootElement;
// FIX (HJ): Include office:font-decls in styles DOM // FIX (HJ): Include office:font-decls in styles DOM
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_FONT_DECLS); nodeList = newDoc
if (nodeList.getLength()>0){ .getElementsByTagName(TAG_OFFICE_FONT_DECLS);
tmpNode = styleDoc.importNode(nodeList.item(0),true); if (nodeList.getLength() > 0) {
tmpNode = styleDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_STYLES); nodeList = newDoc.getElementsByTagName(TAG_OFFICE_STYLES);
if (nodeList.getLength()>0){ if (nodeList.getLength() > 0) {
tmpNode = styleDoc.importNode(nodeList.item(0),true); tmpNode = styleDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
// FIX (HJ): Include office:automatic-styles in styles DOM // FIX (HJ): Include office:automatic-styles in styles DOM
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES); nodeList = newDoc
if (nodeList.getLength()>0){ .getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
tmpNode = styleDoc.importNode(nodeList.item(0),true); if (nodeList.getLength() > 0) {
tmpNode = styleDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
// FIX (HJ): Include office:master-styles in styles DOM // FIX (HJ): Include office:master-styles in styles DOM
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_MASTER_STYLES); nodeList = newDoc
if (nodeList.getLength()>0){ .getElementsByTagName(TAG_OFFICE_MASTER_STYLES);
tmpNode = styleDoc.importNode(nodeList.item(0),true); if (nodeList.getLength() > 0) {
tmpNode = styleDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
/*Settings*/ /* Settings */
settingsDoc = createDOM(TAG_OFFICE_DOCUMENT_SETTINGS); settingsDoc = createDOM(TAG_OFFICE_DOCUMENT_SETTINGS);
rootElement=settingsDoc.getDocumentElement(); rootElement = settingsDoc.getDocumentElement();
rootNode = rootElement; rootNode = rootElement;
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_SETTINGS); nodeList = newDoc.getElementsByTagName(TAG_OFFICE_SETTINGS);
if (nodeList.getLength()>0){ if (nodeList.getLength() > 0) {
tmpNode = settingsDoc.importNode(nodeList.item(0),true); tmpNode = settingsDoc
.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
/*Meta*/ /* Meta */
metaDoc = createDOM(TAG_OFFICE_DOCUMENT_META); metaDoc = createDOM(TAG_OFFICE_DOCUMENT_META);
rootElement=metaDoc.getDocumentElement(); rootElement = metaDoc.getDocumentElement();
rootNode = rootElement; rootNode = rootElement;
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_META); nodeList = newDoc.getElementsByTagName(TAG_OFFICE_META);
if (nodeList.getLength()>0){ if (nodeList.getLength() > 0) {
tmpNode = metaDoc.importNode(nodeList.item(0),true); tmpNode = metaDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
} } catch (SAXException ex) {
}
catch (SAXException ex) {
throw new OfficeDocumentException(ex); throw new OfficeDocumentException(ex);
} }
} }
@@ -609,7 +611,6 @@ public abstract class OfficeDocument
} }
/** /**
* Parse given <code>byte</code> array into a DOM * Parse given <code>byte</code> array into a DOM
* <code>Document</code> object using the * <code>Document</code> object using the

View File

@@ -104,84 +104,108 @@ public final class DocumentSerializerImpl
org.w3c.dom.Document domDoc = sxwDoc.getContentDOM(); org.w3c.dom.Document domDoc = sxwDoc.getContentDOM();
org.w3c.dom.Document metaDoc = sxwDoc.getMetaDOM(); org.w3c.dom.Document metaDoc = sxwDoc.getMetaDOM();
org.w3c.dom.Document styleDoc = sxwDoc.getStyleDOM(); org.w3c.dom.Document styleDoc = sxwDoc.getStyleDOM();
ByteArrayOutputStream baos= new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
ConvertData cd = new ConvertData(); ConvertData cd = new ConvertData();
Node offnode = domDoc.getDocumentElement(); Node offnode = domDoc.getDocumentElement();
if (!(offnode.getNodeName()).equals("office:document")){ if (!(offnode.getNodeName()).equals("office:document")) {
try{ try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory builderFactory = DocumentBuilderFactory
DocumentBuilder builder= builderFactory.newDocumentBuilder(); .newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation domImpl = builder.getDOMImplementation(); DOMImplementation domImpl = builder.getDOMImplementation();
DocumentType docType =domImpl.createDocumentType("office:document","-//OpenOffice.org//DTD OfficeDocument 1.0//EN",null); DocumentType docType = domImpl.createDocumentType(
org.w3c.dom.Document newDoc = domImpl.createDocument("http://openoffice.org/2000/office","office:document",docType); "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");
Element rootElement=newDoc.getDocumentElement(); rootElement.setAttribute("xmlns:draw",
rootElement.setAttribute("xmlns:office","http://openoffice.org/2000/office"); "http://openoffice.org/2000/drawing");
rootElement.setAttribute("xmlns:style","http://openoffice.org/2000/style" ); rootElement.setAttribute("xmlns:fo",
rootElement.setAttribute("xmlns:text","http://openoffice.org/2000/text"); "http://www.w3.org/1999/XSL/Format");
rootElement.setAttribute("xmlns:table","http://openoffice.org/2000/table"); rootElement.setAttribute("xmlns:xlink",
"http://www.w3.org/1999/xlink");
rootElement.setAttribute("xmlns:draw","http://openoffice.org/2000/drawing"); rootElement.setAttribute("xmlns:dc",
rootElement.setAttribute("xmlns:fo","http://www.w3.org/1999/XSL/Format" ); "http://purl.org/dc/elements/1.1/");
rootElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink" ); rootElement.setAttribute("xmlns:meta",
rootElement.setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/" ); "http://openoffice.org/2000/meta");
rootElement.setAttribute("xmlns:meta","http://openoffice.org/2000/meta" ); rootElement.setAttribute("xmlns:number",
rootElement.setAttribute("xmlns:number","http://openoffice.org/2000/datastyle" ); "http://openoffice.org/2000/datastyle");
rootElement.setAttribute("xmlns:svg","http://www.w3.org/2000/svg" ); rootElement.setAttribute("xmlns:svg",
rootElement.setAttribute("xmlns:chart","http://openoffice.org/2000/chart" ); "http://www.w3.org/2000/svg");
rootElement.setAttribute("xmlns:dr3d","http://openoffice.org/2000/dr3d" ); rootElement.setAttribute("xmlns:chart",
rootElement.setAttribute("xmlns:math","http://www.w3.org/1998/Math/MathML" ); "http://openoffice.org/2000/chart");
rootElement.setAttribute("xmlns:form","http://openoffice.org/2000/form" ); rootElement.setAttribute("xmlns:dr3d",
rootElement.setAttribute("xmlns:script","http://openoffice.org/2000/script" ); "http://openoffice.org/2000/dr3d");
rootElement.setAttribute("xmlns:config","http://openoffice.org/2001/config" ); rootElement.setAttribute("xmlns:math",
rootElement.setAttribute("office:class","text" ); "http://www.w3.org/1998/Math/MathML");
rootElement.setAttribute("office:version","1.0"); 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; NodeList nodeList;
Node tmpNode; Node tmpNode;
Node rootNode = rootElement; Node rootNode = rootElement;
if (metaDoc !=null){ if (metaDoc != null) {
nodeList= metaDoc.getElementsByTagName(TAG_OFFICE_META); nodeList = metaDoc.getElementsByTagName(TAG_OFFICE_META);
if (nodeList.getLength()>0){ if (nodeList.getLength() > 0) {
tmpNode = newDoc.importNode(nodeList.item(0),true); 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); rootNode.appendChild(tmpNode);
} }
} }
domDoc=newDoc; if (styleDoc != null) {
}catch(Exception e){ nodeList = styleDoc.getElementsByTagName(TAG_OFFICE_STYLES);
System.out.println("\nAn Exception occurred with Xslt Serializer"+e); 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{ try {
baos=transform(domDoc); baos = transform(domDoc);
} } catch (Exception e) {
catch (Exception e){
System.out.println("\n Error with Xslt\n"); System.out.println("\n Error with Xslt\n");
} }
DOMDocument resultDomDoc=(DOMDocument)pluginFactory.createDeviceDocument(docName,new ByteArrayInputStream(baos.toByteArray())); DOMDocument resultDomDoc = (DOMDocument) pluginFactory
cd.addDocument (resultDomDoc); .createDeviceDocument(docName,
new ByteArrayInputStream(baos.toByteArray()));
cd.addDocument(resultDomDoc);
return cd; return cd;
} }