r667 - branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst
Author: jpages Date: 2012-05-16 15:47:36 +0200 (Wed, 16 May 2012) New Revision: 667 Url: http://nuiton.org/repositories/revision/jrst/667 Log: Cr?\195?\169ation de nouvelles constantes pour certaines cha?\195?\174nes de carat?\195?\168res. Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java Modified: branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java =================================================================== --- branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-05-16 13:22:28 UTC (rev 666) +++ branches/jrst-docutils-jython/jrst/src/main/java/org/nuiton/jrst/JRST.java 2012-05-16 13:47:36 UTC (rev 667) @@ -76,12 +76,18 @@ public static final String UTF_8 = "UTF-8"; - public static final String DOCUTILS_LAUNCHER = "/__run__.py"; + public static final String DOCUTILS_LAUNCHER = "__run__.py"; public static final String IMPORT_SCRIPT = "import __run__"; public static final String WINDOWS_NAME = "win"; + public static final String OS_NAME = "os.name"; + + public static final String BANG = "!"; + + public static final String FILE_PREFIX = "file:"; + public enum Overwrite { NEVER, IFNEWER, ALLTIME } @@ -455,11 +461,11 @@ and it will become : /home/user/.m2/repository/org/nuiton/jrst/docutils/1.6-SNAPSHOT/docutils-1.6-SNAPSHOT.jar/ */ - URL resource = JRST.class.getResource(DOCUTILS_LAUNCHER); + URL resource = JRST.class.getResource("/" + DOCUTILS_LAUNCHER); String docutilsPath = resource.getPath() - .replaceAll("__run__.py", ""); - docutilsPath = docutilsPath.replaceAll("!", ""); - docutilsPath = docutilsPath.replaceAll("file:", ""); + .replaceAll(DOCUTILS_LAUNCHER, ""); + docutilsPath = docutilsPath.replaceAll(BANG, ""); + docutilsPath = docutilsPath.replaceAll(FILE_PREFIX, ""); // Import of the main script to use docutils ( __run__ ) PythonInterpreter interp = new PythonInterpreter(); @@ -468,17 +474,17 @@ // If the OS is windows, escapes the backslashs in the filepath String filePath = in.getAbsolutePath(); - String property = System.getProperty("os.name").toLowerCase(); + String property = System.getProperty(OS_NAME).toLowerCase(); if (property.contains(WINDOWS_NAME)) { filePath = filePath.replaceAll("\\\\", "\\\\\\\\"); } + // Sets an output stream in the python interpreter and executes the code + interp.setOut(out); + // Execution of the docutils script to transform rst to xml String commandExec = String.format("__run__.exec_docutils('%s', '%s', '%s')", docutilsPath, outputType, filePath); - - // Sets an output stream in the python interpreter and executes the code - interp.setOut(out); interp.exec(commandExec); // Cleans the python interpreter to avoid problems if they are multiple execution of this method @@ -490,7 +496,7 @@ try { doc = DocumentHelper.parseText(xmlString); } catch (DocumentException e) { - log.error("Erreur lors de la lecture du xml", e); + log.error("Error during the creation of the document", e); } return doc;
participants (1)
-
jpages@users.nuiton.org