r716 - in trunk/jrst: . src/main/java/org/nuiton/jrst/ui
Author: jpages Date: 2012-06-13 16:11:20 +0200 (Wed, 13 Jun 2012) New Revision: 716 Url: http://nuiton.org/repositories/revision/jrst/716 Log: Simplification du code pour nommer automatiquement le fichier de sortie (utilisation de guava) Modified: trunk/jrst/pom.xml trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java Modified: trunk/jrst/pom.xml =================================================================== --- trunk/jrst/pom.xml 2012-06-13 13:37:59 UTC (rev 715) +++ trunk/jrst/pom.xml 2012-06-13 14:11:20 UTC (rev 716) @@ -163,6 +163,12 @@ <artifactId>jython-standalone</artifactId> </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>12.0</version> + </dependency> + <!-- itext --> <dependency> <groupId>org.xhtmlrenderer</groupId> Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java 2012-06-13 13:37:59 UTC (rev 715) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTViewHandler.java 2012-06-13 14:11:20 UTC (rev 716) @@ -24,6 +24,7 @@ */ package org.nuiton.jrst.ui; +import com.google.common.io.Files; import java.awt.Color; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -107,7 +108,6 @@ } public void addXslLocation() { - JAXXInitialContext context = new JAXXInitialContext(); context.add(jrstView); JRSTCommandModel model = jrstView.getModel(); @@ -170,20 +170,17 @@ if (length > 0) { outputFile = model.getSaveLocationText(); } else { + // If the user didn't give the output file, we take the input file name with the right extension + // For example, nameExample.rst becomes nameExample.xml if (fileIn.isFile()) { - String name = fileIn.getName(); - String[] splitName = name.split("\\."); - outputFile = splitName[0]; - for (int i = 1; i < splitName.length - 2; i++ ) { - outputFile += splitName[i]; - } - outputFile += "."; - if (model.isFormatEnabled()) { - outputFile += xslListOrFormat; + outputFile = fileIn.getAbsolutePath(); + String ext = Files.getFileExtension(outputFile); + if (ext.isEmpty()) { + ext = xslListOrFormat; + outputFile = outputFile + "." + xslListOrFormat; } else { - outputFile += JRST.TYPE_XML; + outputFile = outputFile.replace("." + ext, "." + xslListOrFormat); } - outputFile = fileIn.getParent() + File.separator + outputFile; } } File fileOut = new File(outputFile);
participants (1)
-
jpages@users.nuiton.org