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,11 +510,9 @@ 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);
@@ -524,20 +522,22 @@ public abstract class OfficeDocument
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
.getElementsByTagName(TAG_OFFICE_FONT_DECLS);
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);
} }
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES); nodeList = newDoc
.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
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);
@@ -555,7 +555,8 @@ public abstract class OfficeDocument
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
.getElementsByTagName(TAG_OFFICE_FONT_DECLS);
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);
@@ -568,14 +569,16 @@ public abstract class OfficeDocument
} }
// 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
.getElementsByTagName(TAG_OFFICE_AUTOMATIC_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:master-styles in styles DOM // FIX (HJ): Include office:master-styles in styles DOM
nodeList= newDoc.getElementsByTagName(TAG_OFFICE_MASTER_STYLES); nodeList = newDoc
.getElementsByTagName(TAG_OFFICE_MASTER_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);
@@ -587,7 +590,8 @@ public abstract class OfficeDocument
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 */
@@ -599,9 +603,7 @@ public abstract class OfficeDocument
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

@@ -109,36 +109,56 @@ public final class DocumentSerializerImpl
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
.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder(); 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(); Element rootElement = newDoc.getDocumentElement();
rootElement.setAttribute("xmlns:office","http://openoffice.org/2000/office"); rootElement.setAttribute("xmlns:office",
rootElement.setAttribute("xmlns:style","http://openoffice.org/2000/style" ); "http://openoffice.org/2000/office");
rootElement.setAttribute("xmlns:text","http://openoffice.org/2000/text"); rootElement.setAttribute("xmlns:style",
rootElement.setAttribute("xmlns:table","http://openoffice.org/2000/table"); "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:draw",
rootElement.setAttribute("xmlns:fo","http://www.w3.org/1999/XSL/Format" ); "http://openoffice.org/2000/drawing");
rootElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink" ); rootElement.setAttribute("xmlns:fo",
rootElement.setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/" ); "http://www.w3.org/1999/XSL/Format");
rootElement.setAttribute("xmlns:meta","http://openoffice.org/2000/meta" ); rootElement.setAttribute("xmlns:xlink",
rootElement.setAttribute("xmlns:number","http://openoffice.org/2000/datastyle" ); "http://www.w3.org/1999/xlink");
rootElement.setAttribute("xmlns:svg","http://www.w3.org/2000/svg" ); rootElement.setAttribute("xmlns:dc",
rootElement.setAttribute("xmlns:chart","http://openoffice.org/2000/chart" ); "http://purl.org/dc/elements/1.1/");
rootElement.setAttribute("xmlns:dr3d","http://openoffice.org/2000/dr3d" ); rootElement.setAttribute("xmlns:meta",
rootElement.setAttribute("xmlns:math","http://www.w3.org/1998/Math/MathML" ); "http://openoffice.org/2000/meta");
rootElement.setAttribute("xmlns:form","http://openoffice.org/2000/form" ); rootElement.setAttribute("xmlns:number",
rootElement.setAttribute("xmlns:script","http://openoffice.org/2000/script" ); "http://openoffice.org/2000/datastyle");
rootElement.setAttribute("xmlns:config","http://openoffice.org/2001/config" ); 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:class", "text");
rootElement.setAttribute("office:version", "1.0"); rootElement.setAttribute("office:version", "1.0");
NodeList nodeList; NodeList nodeList;
Node tmpNode; Node tmpNode;
Node rootNode = rootElement; Node rootNode = rootElement;
@@ -148,14 +168,16 @@ public final class DocumentSerializerImpl
tmpNode = newDoc.importNode(nodeList.item(0), true); tmpNode = newDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
} if (styleDoc !=null){ }
if (styleDoc != null) {
nodeList = styleDoc.getElementsByTagName(TAG_OFFICE_STYLES); nodeList = styleDoc.getElementsByTagName(TAG_OFFICE_STYLES);
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); rootNode.appendChild(tmpNode);
} }
}if (domDoc !=null){ }
nodeList= domDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES); nodeList = domDoc
.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES);
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); rootNode.appendChild(tmpNode);
@@ -165,22 +187,24 @@ public final class DocumentSerializerImpl
tmpNode = newDoc.importNode(nodeList.item(0), true); tmpNode = newDoc.importNode(nodeList.item(0), true);
rootNode.appendChild(tmpNode); rootNode.appendChild(tmpNode);
} }
}
domDoc = newDoc; domDoc = newDoc;
} catch (Exception e) { } catch (Exception e) {
System.out.println("\nAn Exception occurred with Xslt Serializer"+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
.createDeviceDocument(docName,
new ByteArrayInputStream(baos.toByteArray()));
cd.addDocument(resultDomDoc); cd.addDocument(resultDomDoc);
return cd; return cd;
} }