diff options
Diffstat (limited to 'xmerge')
-rw-r--r-- | xmerge/source/bridge/java/XMergeBridge.java | 210 |
1 files changed, 102 insertions, 108 deletions
diff --git a/xmerge/source/bridge/java/XMergeBridge.java b/xmerge/source/bridge/java/XMergeBridge.java index 391232c90207..bbe3e2a05e56 100644 --- a/xmerge/source/bridge/java/XMergeBridge.java +++ b/xmerge/source/bridge/java/XMergeBridge.java @@ -375,136 +375,130 @@ public class XMergeBridge { XInputStreamToInputStreamAdapter xis =new XInputStreamToInputStreamAdapter(xml); XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(device); - try{ - ConverterInfoReader cir = new ConverterInfoReader(jarName,false); - ciEnum =cir.getConverterInfoEnumeration(); - } - catch (ParserConfigurationException pexc){ - System.out.println("Error:"+pexc); - } - catch ( org.xml.sax.SAXException pexc){ - System.out.println("Error:"+pexc); - } - catch(Exception e){ - System.out.println("Error:"+e); - } - ConverterInfoMgr. removeByJar(jarName); - if (convertFromOffice) - { - - try { - - //Check to see if jar contains a plugin Impl - - ConverterInfoMgr.addPlugIn(ciEnum); - ConverterFactory cf = new ConverterFactory(); - - Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false); - if (cv == null) { - System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> "); - } - else - { - cv.addInputStream(name,xis,false); - ConvertData dataOut = cv.convert(); + /* make sure newxos and xis get closed */ + try{ + try{ + ConverterInfoReader cir = new ConverterInfoReader(jarName,false); + ciEnum =cir.getConverterInfoEnumeration(); + } + catch (ParserConfigurationException pexc){ + System.out.println("Error:"+pexc); + } + catch ( org.xml.sax.SAXException pexc){ + System.out.println("Error:"+pexc); + } + catch(Exception e){ + System.out.println("Error:"+e); + } + ConverterInfoMgr. removeByJar(jarName); + if (convertFromOffice) + { - Iterator<Object> docEnum = dataOut.getDocumentEnumeration(); + try { - if (docEnum.hasNext()){ - Document docOut = (Document)docEnum.next(); - docOut.write(newxos); + //Check to see if jar contains a plugin Impl - newxos.flush(); - newxos.close(); + ConverterInfoMgr.addPlugIn(ciEnum); + ConverterFactory cf = new ConverterFactory(); - int i=1; - while (docEnum.hasNext() && sURL.startsWith("file:")) { + Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false); + if (cv == null) { + System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> "); - URI uri=new URI(sURL); - String newFileName= getPath(uri); + } + else + { + cv.addInputStream(name,xis,false); + ConvertData dataOut = cv.convert(); + + Iterator<Object> docEnum = dataOut.getDocumentEnumeration(); + + if (docEnum.hasNext()){ + Document docOut = (Document)docEnum.next(); + docOut.write(newxos); + + newxos.flush(); + newxos.close(); + newxos = null; + + int i=1; + while (docEnum.hasNext() && sURL.startsWith("file:")) { + + URI uri=new URI(sURL); + String newFileName= getPath(uri); + + File newFile; + if (newFileName.lastIndexOf(".")!=-1){ + newFile =new File(newFileName.substring(0,newFileName.lastIndexOf("."))+String.valueOf(i)+newFileName.substring(newFileName.lastIndexOf("."))); + } + else{ + newFile =new File(newFileName.concat(String.valueOf(i))); + } + + FileOutputStream fos = new FileOutputStream(newFile); + docOut = (Document)docEnum.next(); + docOut.write(fos); + fos.flush(); + fos.close(); + i++; - File newFile; - if (newFileName.lastIndexOf(".")!=-1){ - newFile =new File(newFileName.substring(0,newFileName.lastIndexOf("."))+String.valueOf(i)+newFileName.substring(newFileName.lastIndexOf("."))); } - else{ - newFile =new File(newFileName.concat(String.valueOf(i))); - } - - FileOutputStream fos = new FileOutputStream(newFile); - docOut = (Document)docEnum.next(); - docOut.write(fos); - fos.flush(); - fos.close(); - fos = null; - i++; } - } + ConverterInfoMgr.removeByJar(jarName); } - ConverterInfoMgr.removeByJar(jarName); - } - catch (Exception ex1) { - /* Satisfy coverity */ - newxos.flush(); - newxos.close(); - newxos = null; - xis.close(); - xis = null; - IOException ex2 = new IOException(); - ex2.initCause(ex1); - throw ex2; - } - } - else{ - - try { - //Check to see if jar contains a plugin Impl - ConverterInfoMgr.addPlugIn(ciEnum); - ConverterFactory cf = new ConverterFactory(); - Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),true); - if (cv == null) { - System.out.println("\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>"); + catch (Exception ex1) { + IOException ex2 = new IOException(); + ex2.initCause(ex1); + throw ex2; } - else - { + } + else{ + + try { + //Check to see if jar contains a plugin Impl + ConverterInfoMgr.addPlugIn(ciEnum); + ConverterFactory cf = new ConverterFactory(); + Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),true); + if (cv == null) { + System.out.println("\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>"); + } + else + { - cv.addInputStream(name,xis,false); - ConvertData dataIn = cv.convert(); - Iterator<Object> docEnum = dataIn.getDocumentEnumeration(); - while (docEnum.hasNext()) { - OfficeDocument docIn = (OfficeDocument)docEnum.next(); + cv.addInputStream(name,xis,false); + ConvertData dataIn = cv.convert(); + Iterator<Object> docEnum = dataIn.getDocumentEnumeration(); + while (docEnum.hasNext()) { + OfficeDocument docIn = (OfficeDocument)docEnum.next(); - docIn.write(newxos,false); + docIn.write(newxos,false); + } + newxos.close(); + newxos = null; } - newxos.close(); + ConverterInfoMgr.removeByJar(jarName); } - ConverterInfoMgr.removeByJar(jarName); - } - catch (StackOverflowError sOE){ - System.out.println("\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"); + catch (StackOverflowError sOE){ + System.out.println("\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"); + } + catch (Exception ex1) { + IOException ex2 = new IOException(); + ex2.initCause(ex1); + throw ex2; + } + } - catch (Exception ex1) { - /* Satisfy coverity */ + } + finally{ + if (newxos != null){ newxos.flush(); newxos.close(); - newxos = null; - xis.close(); - xis = null; - IOException ex2 = new IOException(); - ex2.initCause(ex1); - throw ex2; } - + xis.close(); } - /* Satisfy coverity */ - newxos.flush(); - newxos.close(); - newxos = null; - xis.close(); - xis = null; } private String getPath(URI uri){ |