Index: jrst2/src/java/org/codelutin/jrst/JRST.java diff -u jrst2/src/java/org/codelutin/jrst/JRST.java:1.3 jrst2/src/java/org/codelutin/jrst/JRST.java:1.4 --- jrst2/src/java/org/codelutin/jrst/JRST.java:1.3 Fri Dec 29 17:59:33 2006 +++ jrst2/src/java/org/codelutin/jrst/JRST.java Thu Feb 8 11:48:15 2007 @@ -23,9 +23,9 @@ * Created: 3 nov. 06 20:56:00 * * @author poussin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2006/12/29 17:59:33 $ + * Last update: $Date: 2007/02/08 11:48:15 $ * by : $Author: bpoussin $ */ @@ -45,6 +45,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.codelutin.util.FileUtil; import org.codelutin.util.StringUtil; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -67,6 +68,12 @@ @CommandLineInterface(application="JRST") public class JRST { + public static enum Overwrite { + NEVER, + IFNEWER, + ALLTIME + } + /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(JRST.class); @@ -118,12 +125,14 @@ xslList = option.getOutType(); } - generate(xslList, option.getFile(), option.getOutFile(), option.isForce()); + generate(xslList, option.getFile(), option.getOutFile(), option.isForce()?Overwrite.ALLTIME:Overwrite.NEVER); } public static void generate(String xslListOrOutType, File fileIn, File fileOut, - boolean overwrite) throws Exception { - if (fileOut != null && fileOut.exists() && overwrite == false) { + Overwrite overwrite) throws Exception { + if (fileOut != null && fileOut.exists() && + (overwrite == Overwrite.NEVER || + (overwrite == Overwrite.IFNEWER && FileUtil.isNewer(fileIn, fileOut)))) { log.info("Don't generate file "+fileOut+", because already exists"); } else { // search xsl file list to apply Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.5 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.6 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.5 Mon Dec 18 15:57:28 2006 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Thu Feb 8 11:48:15 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Last update: $Date: 2006/12/18 15:57:28 $ + * Last update: $Date: 2007/02/08 11:48:15 $ * by : $Author: bpoussin $ */ @@ -270,6 +270,30 @@ } /** + * Lit les premieres ligne non vide et les retourne, rien n'est modifier par rapport + * aux positions dans le fichier. Util pour afficher a l'utilisateur les lignes + * qui ont produit une erreur + * + * @return + * @throws IOException + */ + public String readNotBlanckLine() throws IOException { + beginPeek(); + in.skipBlankLines(); + String line = joinBlock(in.readUntilBlank(), "\n", false); + endPeek(); + return line; + } + + public int getLineNumber() { + return in.getLineNumber(); + } + + public int getCharNumber() { + return in.getCharNumber(); + } + + /** * @return * @throws IOException */ @@ -788,11 +812,13 @@ .addAttribute("term", term) .addAttribute("classifiers", classifiers); - if (!in.eof()) { - String [] content = readBlock(level + 1); - String text = joinBlock(content); - result.addText(text); - } + // poussin 20070207 don't read block here because can't + // interpret it correctly in JRSTReader +// if (!in.eof()) { +// String [] content = readBlock(level + 1); +// String text = joinBlock(content); +// result.addText(text); +// } } } } Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.5 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.6 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.5 Mon Dec 18 15:57:28 2006 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Thu Feb 8 11:48:15 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Last update: $Date: 2006/12/18 15:57:28 $ + * Last update: $Date: 2007/02/08 11:48:15 $ * by : $Author: bpoussin $ */ @@ -33,6 +33,8 @@ import static org.codelutin.jrst.ReStructuredText.*; +import static org.codelutin.i18n.I18n._; + import java.io.IOException; import java.io.Reader; import java.io.StringReader; @@ -342,42 +344,45 @@ * @throws IOException * @throws DocumentException */ - public Document read(Reader reader) throws IOException, DocumentException { + public Document read(Reader reader) throws Exception { JRSTLexer lexer = new JRSTLexer(reader); - - Element root = composeDocument(lexer); - - Document result = DocumentHelper.createDocument(); - result.setRootElement(root); - - // remove all level attribute - root.accept(new VisitorSupport() { - public void visit(Element e) { - e.addAttribute("level", null); - if ("true".equalsIgnoreCase(e.attributeValue("inline"))) { - e.addAttribute("inline", null); - try { - inline(e); - } catch (DocumentException eee) { - if (log.isWarnEnabled()) { - log.warn("Can inline text for " + e, eee); + try { + Element root = composeDocument(lexer); + + Document result = DocumentHelper.createDocument(); + result.setRootElement(root); + + // remove all level attribute + root.accept(new VisitorSupport() { + public void visit(Element e) { + e.addAttribute("level", null); + if ("true".equalsIgnoreCase(e.attributeValue("inline"))) { + e.addAttribute("inline", null); + try { + inline(e); + } catch (DocumentException eee) { + if (log.isWarnEnabled()) { + log.warn("Can inline text for " + e, eee); + } } } } - } - }); - + }); + - return result; + return result; + } catch (Exception eee) { + log.error(_("JRST parsing error line {0} char {1}:\n{2}", lexer.getLineNumber(), lexer.getCharNumber(), lexer.readNotBlanckLine())); + throw eee; + } } /** * @param in * @param root - * @throws IOException - * @throws DocumentException + * @throws Exception */ - private Element composeDocument(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeDocument(JRSTLexer lexer) throws Exception { Element result = DocumentHelper.createElement(DOCUMENT); result.addAttribute("level", String.valueOf(MAX_SECTION_DEPTH - 1)); @@ -462,7 +467,7 @@ * @throws DocumentException * @throws IOException */ - private Element composeBody(JRSTLexer lexer, Element parent) throws DocumentException, IOException { + private Element composeBody(JRSTLexer lexer, Element parent) throws Exception { Element item = lexer.peekTitleOrBodyElement(); if (item == null && !lexer.eof()) { item = lexer.peekTitleOrBodyElement(); @@ -564,7 +569,7 @@ * @param item * @return */ - private Element composeTable(JRSTLexer lexer, Element item) throws IOException, DocumentException { + private Element composeTable(JRSTLexer lexer, Element item) throws Exception { Element result = DocumentHelper.createElement(TABLE); int tableWidth = Integer.parseInt(item.attributeValue(JRSTLexer.TABLE_WIDTH)); @@ -657,7 +662,7 @@ return result; } - private Element composeBulletList(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeBulletList(JRSTLexer lexer) throws Exception { Element item = lexer.peekBulletList(); Element result = DocumentHelper.createElement(BULLET_LIST); copyLevel(item, result); @@ -675,7 +680,7 @@ return result; } - private Element composeEnumeratedList(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeEnumeratedList(JRSTLexer lexer) throws Exception { Element item = lexer.peekEnumeratedList(); Element result = DocumentHelper.createElement(ENUMERATED_LIST); copyLevel(item, result); @@ -698,7 +703,7 @@ return result; } - private Element composeDefinitionList(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeDefinitionList(JRSTLexer lexer) throws Exception { Element item = lexer.peekBodyElement(); Element result = DocumentHelper.createElement(DEFINITION_LIST); copyLevel(item, result); @@ -718,18 +723,18 @@ classifier.addAttribute("inline", "true").setText(classifierText); } - Element defintion = def.addElement(DEFINITION); - defintion.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText()); - copyLevel(item, defintion); + Element definition = def.addElement(DEFINITION); + definition.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText()); + copyLevel(item, definition); - composeBody(lexer, defintion); + composeBody(lexer, definition); item = lexer.peekBodyElement(); } return result; } - private Element composeFieldList(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeFieldList(JRSTLexer lexer) throws Exception { Element item = lexer.peekBodyElement(); Element result = DocumentHelper.createElement(FIELD_LIST); copyLevel(item, result); @@ -741,7 +746,7 @@ return result; } - private Element composeFieldItemList(JRSTLexer lexer) throws IOException, DocumentException { + private Element composeFieldItemList(JRSTLexer lexer) throws Exception { Element item = lexer.peekFieldList(); if (itemEquals(FIELD_LIST, item)) { lexer.remove(); @@ -769,7 +774,7 @@ * @throws DocumentException * @throws IOException */ - private Element composeSection(JRSTLexer lexer) throws DocumentException, IOException { + private Element composeSection(JRSTLexer lexer) throws Exception { Element result = DocumentHelper.createElement(SECTION); Element firstTitle = null;