You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by vd...@apache.org on 2016/10/13 04:10:08 UTC

svn commit: r1764576 - in /openmeetings/application/branches/3.2.x/openmeetings-core: pom.xml src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java

Author: vdegtyarev
Date: Thu Oct 13 04:10:08 2016
New Revision: 1764576

URL: http://svn.apache.org/viewvc?rev=1764576&view=rev
Log:
OPENMEETINGS-1490 is fixed. Jodconverter is added to openmeetings project.

Modified:
    openmeetings/application/branches/3.2.x/openmeetings-core/pom.xml
    openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java

Modified: openmeetings/application/branches/3.2.x/openmeetings-core/pom.xml
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-core/pom.xml?rev=1764576&r1=1764575&r2=1764576&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-core/pom.xml (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-core/pom.xml Thu Oct 13 04:10:08 2016
@@ -93,6 +93,11 @@
 			<artifactId>javax.mail</artifactId>
 			<version>${mail.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>org.artofsolving.jodconverter</groupId>
+			<artifactId>jodconverter-core</artifactId>
+			<version>3.0.1-om</version>
+		</dependency>
 		<!-- Test dependencies -->
 		<dependency>
 			<groupId>org.red5</groupId>

Modified: openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java?rev=1764576&r1=1764575&r2=1764576&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/documents/GeneratePDF.java Thu Oct 13 04:10:08 2016
@@ -23,8 +23,6 @@ import static org.apache.openmeetings.ut
 import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
 
 import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
 
 import org.apache.openmeetings.core.converter.GenerateSWF;
 import org.apache.openmeetings.core.converter.GenerateThumbs;
@@ -32,7 +30,10 @@ import org.apache.openmeetings.db.dao.ba
 import org.apache.openmeetings.db.entity.file.FileExplorerItem;
 import org.apache.openmeetings.util.process.ConverterProcessResult;
 import org.apache.openmeetings.util.process.ConverterProcessResultList;
-import org.apache.openmeetings.util.process.ProcessHelper;
+import org.artofsolving.jodconverter.OfficeDocumentConverter;
+import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
+import org.artofsolving.jodconverter.office.OfficeException;
+import org.artofsolving.jodconverter.office.OfficeManager;
 import org.red5.logging.Red5LoggerFactory;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -73,51 +74,26 @@ public class GeneratePDF {
 	 */
 	public ConverterProcessResult doJodConvert(File in, File out) {
 		try {
-			String jodPath = configurationDao.getConfValue("jod.path", String.class, "./jod");
 			String officePath = configurationDao.getConfValue("office.path", String.class, "");
-
-			File jodFolder = new File(jodPath);
-			if (!jodFolder.exists() || !jodFolder.isDirectory()) {
-				return new ConverterProcessResult("doJodConvert", "Path to JOD Library folder does not exist", null);
-			}
-
-			ArrayList<String> argv = new ArrayList<String>();
-			argv.add("java");
-
-			if (officePath.trim().length() > 0) {
-				argv.add("-Doffice.home=" + officePath);
-			}
-			String jodConverterJar = "";
-
-			String[] list = jodFolder.list(new FilenameFilter() {
-				@Override
-				public boolean accept(File file1, String name) {
-					return name.endsWith(".jar");
-				}
-			});
-			if (list != null) {
-				for (String jar : list) {
-					argv.add("-cp");
-					if (jar.startsWith("jodconverter")) {
-						jodConverterJar = jar;
-					}
-					argv.add(new File(jodFolder, jar).getCanonicalPath());
-				}
-			}
-			if (jodConverterJar.length() == 0) {
-				throw new Exception("Could not find jodConverter JAR file in JOD folder");
+			DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
+			configuration.setOfficeHome(officePath);
+			OfficeManager officeManager = configuration.buildOfficeManager();
+			officeManager.start();
+			OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
+			try {
+				converter.convert(in, out);
+			} catch (OfficeException ex) {
+				log.error("doJodConvert", ex);
+				return new ConverterProcessResult("doJodConvert", ex.getMessage(), ex);
+			} finally {
+				officeManager.stop();
 			}
-
-			argv.add("-jar");
-			argv.add(new File(jodFolder, jodConverterJar).getCanonicalPath());
-			argv.add(in.getCanonicalPath());
-			argv.add(out.getCanonicalPath());
-
-			return ProcessHelper.executeScript("doJodConvert", argv.toArray(new String[argv.size()]));
-
 		} catch (Exception ex) {
 			log.error("doJodConvert", ex);
 			return new ConverterProcessResult("doJodConvert", ex.getMessage(), ex);
 		}
+		ConverterProcessResult result = new ConverterProcessResult("doJodConvert", "Document converted successfully", null);
+		result.setExitCode(0);
+		return result;
 	}
 }