[OFBiz] SVN: r7428 - trunk/applications/content/src/org/ofbiz/content/openoffice
byersa@svn.ofbiz.org
byersa at svn.ofbiz.org
Wed Apr 26 19:55:32 CDT 2006
Author: byersa
Date: 2006-04-26 19:55:18 -0500 (Wed, 26 Apr 2006)
New Revision: 7428
Modified:
trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java
trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeWorker.java
Log:
This fixes some problems with earlier OpenOffice code not working with Microsoft Windows and it had to deal with problems caused by the latest UNO libraries.
I used the jar files from version 2.0.2. I am not sure if they are different from the Windows download to the Linux. The jar that I am currently using a ridl, unoil, java_uno_accesbridge, java_uno, juh, jurt, jut. I am not sure all of those are required. Eclipse says that only ridl and unoil are needed, but I thought there might be some future or indirect need for the others.
I am doing this work on a Windows laptop with .5G of memory, so I cannot adequately test. Will have to do that later.
Modified: trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java 2006-04-27 00:02:37 UTC (rev 7427)
+++ trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeServices.java 2006-04-27 00:55:18 UTC (rev 7428)
@@ -27,6 +27,8 @@
import java.util.Map;
import java.util.Random;
import java.sql.Timestamp;
+import java.lang.Math;
+import java.net.MalformedURLException;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
@@ -69,7 +71,7 @@
//String uniqueSeqNum = delegator.getNextSeqId("OOTempDir");
Timestamp ts = UtilDateTime.nowTimestamp();
Random random = new Random(ts.getTime());
- String uniqueSeqNum = Long.toString(random.nextLong());
+ String uniqueSeqNum = Integer.toString(Math.abs(random.nextInt()));
String fileInName = "OOIN_" + uniqueSeqNum;
String fileOutName = "OOOUT_" + uniqueSeqNum;
File fileIn = null;
@@ -100,7 +102,8 @@
FileOutputStream fos = new FileOutputStream(fileIn);
fos.write(inByteArray);
fos.close();
- OpenOfficeWorker.convertOODocToFile(xmulticomponentfactory, "file://" + tempDir + fileInName, "file://" + tempDir + fileOutName, outputMimeType);
+ Debug.logInfo("fileIn:" + tempDir + fileInName, module);
+ OpenOfficeWorker.convertOODocToFile(xmulticomponentfactory, tempDir + fileInName, tempDir + fileOutName, outputMimeType);
fileOut = new File(tempDir + fileOutName);
FileInputStream fis = new FileInputStream(fileOut);
int c;
@@ -113,6 +116,9 @@
results.put("outByteWrapper", new ByteWrapper(baos.toByteArray()));
baos.close();
+ } catch (MalformedURLException e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.toString());
} catch (FileNotFoundException e) {
Debug.logError(e, "Error in OpenOffice operation: ", module);
return ServiceUtil.returnError(e.toString());
@@ -123,8 +129,8 @@
Debug.logError(e, "Error in OpenOffice operation: ", module);
return ServiceUtil.returnError(e.toString());
} finally {
- if (fileIn != null) fileIn.delete();
- if (fileOut != null) fileOut.delete();
+ //if (fileIn != null) fileIn.delete();
+ //if (fileOut != null) fileOut.delete();
}
return results;
}
Modified: trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeWorker.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeWorker.java 2006-04-27 00:02:37 UTC (rev 7427)
+++ trunk/applications/content/src/org/ofbiz/content/openoffice/OpenOfficeWorker.java 2006-04-27 00:55:18 UTC (rev 7428)
@@ -17,13 +17,12 @@
*/
package org.ofbiz.content.openoffice;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.FileNotFoundException;
-import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
-import java.util.Hashtable;
-import java.util.Properties;
-import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -43,6 +42,7 @@
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
+import com.sun.star.uri.ExternalUriReferenceTranslator;
/**
* OpenOfficeWorker Class
@@ -162,7 +162,7 @@
return filterNameList;
}
- public static void convertOODocToFile(XMultiComponentFactory xmulticomponentfactory, String stringUrl, String stringConvertedFile, String outputMimeType) throws FileNotFoundException, IOException, Exception {
+ public static void convertOODocToFile(XMultiComponentFactory xmulticomponentfactory, String fileInPath, String fileOutPath, String outputMimeType) throws FileNotFoundException, IOException, MalformedURLException, Exception {
// Converting the document to the favoured type
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xmulticomponentfactory);
@@ -188,16 +188,18 @@
// Setting the flag for hidding the open document
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Hidden";
- propertyvalue[ 0 ].Value = new Boolean(true);
+ propertyvalue[ 0 ].Value = new Boolean(false);
propertyvalue[ 1 ] = new PropertyValue();
propertyvalue[ 1 ].Name = "UpdateDocMode";
propertyvalue[ 1 ].Value = "1";
// Loading the wanted document
+ String stringUrl = convertToUrl(fileInPath, xcomponentcontext);
+ Debug.logInfo("stringUrl:" + stringUrl, module);
Object objectDocumentToStore = xcomponentloader.loadComponentFromURL(stringUrl, "_blank", 0, propertyvalue);
- // Getting an object that will offer a simple way to store a document to a URL.
+ // Getting an object that will offer a simple way to store a document to a URL.
XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore);
// Preparing properties for converting the document
@@ -218,11 +220,12 @@
propertyvalue[2].Name = "CompressionMode";
propertyvalue[2].Value = "1";
- Debug.logInfo("stringConvertedFile: "+stringConvertedFile, module);
// Storing and converting the document
//File newFile = new File(stringConvertedFile);
//newFile.createNewFile();
+ String stringConvertedFile = convertToUrl(fileOutPath, xcomponentcontext);
+ Debug.logInfo("stringConvertedFile: "+stringConvertedFile, module);
xstorable.storeToURL(stringConvertedFile, propertyvalue);
// Getting the method dispose() for closing the document
@@ -343,4 +346,14 @@
return extension;
}
+ public static String convertToUrl(String filePath, XComponentContext xComponentContext ) throws MalformedURLException {
+
+ String returnUrl = null;
+ File f = new File(filePath);
+ URL u = f.toURL();
+ returnUrl = ExternalUriReferenceTranslator.create(xComponentContext).translateToInternal(u.toExternalForm());
+
+ return returnUrl;
+ }
+
}
More information about the Svn
mailing list