package fr.gouv.finances.dgfip.xemelios.batch.exports.postProcessors;
-import fr.gouv.finances.dgfip.xemelios.batch.PostProcessor;
-import fr.gouv.finances.dgfip.xemelios.export.ExportJob;
import java.io.File;
import java.lang.reflect.Method;
+
import org.apache.log4j.Logger;
+import fr.gouv.finances.dgfip.xemelios.batch.PostProcessor;
+import fr.gouv.finances.dgfip.xemelios.export.ExportJob;
+
/**
- *
+ *
* @author Christophe Marchand <christophe.marchand@axyus.com>
*/
public class ExcelRunner implements PostProcessor {
- private static final Logger logger = Logger.getLogger(ExcelRunner.class);
- private ExportJob job;
+ private static final Logger logger = Logger.getLogger(ExcelRunner.class);
+ private ExportJob job;
- public ExcelRunner() {
- super();
- }
+ public ExcelRunner() {
+ super();
+ }
- public void setConfigData(Object data) {
- job = (ExportJob)data;
- }
+ @Override
+ public void setConfigData(final Object data) {
+ this.job = (ExportJob) data;
+ }
- public void postProcess() throws Exception {
- if(job==null) return;
- File f = new File(job.getGeneratedFileName());
- if(!f.exists()) return;
- if(!f.getName().toUpperCase().endsWith(".XLS")) return;
+ @Override
+ public void postProcess() throws Exception {
+ if (this.job == null) {
+ return;
+ }
+ final File f = new File(this.job.getGeneratedFileName());
+ if (!f.exists()) {
+ return;
+ }
+ if (!f.getName().toUpperCase().endsWith(".XLS")) {
+ return;
+ }
- String osName = System.getProperty("os.name");
- String url = f.toURL().toExternalForm();
- try {
- if (osName.startsWith("Mac OS")) {
- // Mac OS X can handle file types itself (thank goodness!)
- Class fileMgr = Class.forName("com.apple.eio.FileManager");
- Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[] {String.class});
- openURL.invoke(null, new Object[] {url});
- } else if (osName.startsWith("Windows")) { // who knows what Windows does ...
- // il y a un bug avec Windows 2000, il faut que le fichier commence par file:// au lieu de file:/
- if("Windows 2000".equals(System.getProperty("os.name")) || "Windows 98".equals(System.getProperty("os.name"))) {
- if(url.startsWith("file:/") && !url.startsWith("file://"))
- url = "file://".concat(url.substring(6));
- }
- Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
- // we must synchronize this
- p.waitFor();
- } else {
- logger.error("This post processor - ExcelRunner - can only be used on Windows and MacOS. You are using "+osName);
- }
- } catch (Exception e) {
- logger.error(e);
- throw e;
- }
+ final String osName = System.getProperty("os.name");
+ String url = f.toURL().toExternalForm();
+ try {
+ if (osName.startsWith("Mac OS")) {
+ // Mac OS X can handle file types itself (thank goodness!)
+ final Class fileMgr = Class.forName("com.apple.eio.FileManager");
+ final Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
+ openURL.invoke(null, new Object[] { url });
+ } else if (osName.startsWith("Windows")) { // who knows what Windows does ...
+ // il y a un bug avec Windows 2000, il faut que le fichier commence par file:// au lieu de file:/
+ if ("Windows 2000".equals(System.getProperty("os.name")) || "Windows 98".equals(System.getProperty("os.name"))) {
+ if (url.startsWith("file:/") && !url.startsWith("file://")) {
+ url = "file://".concat(url.substring(6));
+ }
+ }
+ final Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
+ // we must synchronize this
+ p.waitFor();
+ } else {
+ logger.error("This post processor - ExcelRunner - can only be used on Windows and MacOS. You are using " + osName);
+ }
+ } catch (final Exception e) {
+ logger.error(e);
+ throw e;
+ }
- }
+ }
}