Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.37 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.38 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.37 Thu Jun 21 09:01:13 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Tue Jul 29 07:59:52 2008 @@ -23,16 +23,90 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.37 $ + * @version $Revision: 1.38 $ * - * Last update: $Date: 2007-06-21 09:01:13 $ - * by : $Author: sletellier $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; -import static org.codelutin.jrst.ReStructuredText.*; import static org.codelutin.i18n.I18n._; +import static org.codelutin.jrst.ReStructuredText.ADDRESS; +import static org.codelutin.jrst.ReStructuredText.ADMONITION; +import static org.codelutin.jrst.ReStructuredText.ATTRIBUTION; +import static org.codelutin.jrst.ReStructuredText.AUTHOR; +import static org.codelutin.jrst.ReStructuredText.AUTHORS; +import static org.codelutin.jrst.ReStructuredText.BLOCK_QUOTE; +import static org.codelutin.jrst.ReStructuredText.BULLET_LIST; +import static org.codelutin.jrst.ReStructuredText.COLSPEC; +import static org.codelutin.jrst.ReStructuredText.COMMENT; +import static org.codelutin.jrst.ReStructuredText.CONTACT; +import static org.codelutin.jrst.ReStructuredText.COPYRIGHT; +import static org.codelutin.jrst.ReStructuredText.DATE; +import static org.codelutin.jrst.ReStructuredText.DECORATION; +import static org.codelutin.jrst.ReStructuredText.DEFINITION; +import static org.codelutin.jrst.ReStructuredText.DEFINITION_LIST; +import static org.codelutin.jrst.ReStructuredText.DEFINITION_LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.DESCRIPTION; +import static org.codelutin.jrst.ReStructuredText.DOCINFO; +import static org.codelutin.jrst.ReStructuredText.DOCTEST_BLOCK; +import static org.codelutin.jrst.ReStructuredText.DOCUMENT; +import static org.codelutin.jrst.ReStructuredText.EMPHASIS; +import static org.codelutin.jrst.ReStructuredText.ENTRY; +import static org.codelutin.jrst.ReStructuredText.ENUMERATED_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD; +import static org.codelutin.jrst.ReStructuredText.FIELD_BODY; +import static org.codelutin.jrst.ReStructuredText.FIELD_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD_NAME; +import static org.codelutin.jrst.ReStructuredText.FOOTER; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.FOOTNOTE_SYMBOL; +import static org.codelutin.jrst.ReStructuredText.HEADER; +import static org.codelutin.jrst.ReStructuredText.IMAGE; +import static org.codelutin.jrst.ReStructuredText.LINE; +import static org.codelutin.jrst.ReStructuredText.LINE_BLOCK; +import static org.codelutin.jrst.ReStructuredText.LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.LITERAL; +import static org.codelutin.jrst.ReStructuredText.LITERAL_BLOCK; +import static org.codelutin.jrst.ReStructuredText.OPTION; +import static org.codelutin.jrst.ReStructuredText.OPTION_ARGUMENT; +import static org.codelutin.jrst.ReStructuredText.OPTION_GROUP; +import static org.codelutin.jrst.ReStructuredText.OPTION_LIST; +import static org.codelutin.jrst.ReStructuredText.OPTION_LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.OPTION_STRING; +import static org.codelutin.jrst.ReStructuredText.ORGANIZATION; +import static org.codelutin.jrst.ReStructuredText.PARAGRAPH; +import static org.codelutin.jrst.ReStructuredText.REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_ANONYMOUS_HYPERLINK_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_EMAIL; +import static org.codelutin.jrst.ReStructuredText.REGEX_EMPHASIS; +import static org.codelutin.jrst.ReStructuredText.REGEX_FOOTNOTE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_HYPERLINK_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_INLINE_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_LITERAL; +import static org.codelutin.jrst.ReStructuredText.REGEX_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REGEX_STRONG; +import static org.codelutin.jrst.ReStructuredText.REGEX_SUBSTITUTION_REFERENCE; +import static org.codelutin.jrst.ReStructuredText.REVISION; +import static org.codelutin.jrst.ReStructuredText.ROW; +import static org.codelutin.jrst.ReStructuredText.SECTION; +import static org.codelutin.jrst.ReStructuredText.SIDEBAR; +import static org.codelutin.jrst.ReStructuredText.STATUS; +import static org.codelutin.jrst.ReStructuredText.STRONG; +import static org.codelutin.jrst.ReStructuredText.SUBSTITUTION_DEFINITION; +import static org.codelutin.jrst.ReStructuredText.SUBTITLE; +import static org.codelutin.jrst.ReStructuredText.TABLE; +import static org.codelutin.jrst.ReStructuredText.TARGET; +import static org.codelutin.jrst.ReStructuredText.TBODY; +import static org.codelutin.jrst.ReStructuredText.TERM; +import static org.codelutin.jrst.ReStructuredText.TGROUP; +import static org.codelutin.jrst.ReStructuredText.THEAD; +import static org.codelutin.jrst.ReStructuredText.TITLE; +import static org.codelutin.jrst.ReStructuredText.TOPIC; +import static org.codelutin.jrst.ReStructuredText.TRANSITION; +import static org.codelutin.jrst.ReStructuredText.VERSION; import java.io.BufferedReader; import java.io.File; @@ -49,11 +123,11 @@ import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -//import org.codelutin.jrst.directive.CalcDirective; import org.codelutin.jrst.directive.ContentDirective; import org.codelutin.jrst.directive.DateDirective; import org.codelutin.jrst.directive.ImageDirective; @@ -311,7 +385,7 @@ defaultDirectives.put(DATE, new DateDirective()); defaultDirectives.put("time", new DateDirective()); defaultDirectives.put("contents", new ContentDirective()); - //defaultDirectives.put("calc", new CalcDirective()); + // defaultDirectives.put("calc", new CalcDirective()); defaultDirectives.put("sectnum", new SectnumDirective()); // TODO put here all other directive } @@ -330,8 +404,7 @@ } /** - * @param defaultDirectives - * the defaultDirectives to set + * @param defaultDirectives the defaultDirectives to set */ public static void addDefaultDirectives(String name, JRSTDirective directive) { JRSTReader.defaultDirectives.put(name, directive); @@ -345,8 +418,7 @@ } /** - * @param JRSTDirective - * the defaultDirectives to set + * @param JRSTDirective the defaultDirectives to set */ public void addDirectives(String name, JRSTDirective directive) { directives.put(name, directive); @@ -483,8 +555,7 @@ } /** - * @param LinkedList - * title, String num + * @param LinkedList title, String num * @return Element */ private Element composeLineContent(LinkedList title, String num) { @@ -951,7 +1022,7 @@ *
      * ..
      *   So this block is not "lost",
-     *   despite its indentation. 
+     *   despite its indentation.
      * 
* * @param item @@ -966,6 +1037,7 @@ *
      * __ http://truc.html
      * 
+ * * @param item * @return Element */ @@ -977,9 +1049,8 @@ } /** - *
+     * 
+     * 
      * @param item
      * @return Element
      */
@@ -997,6 +1068,7 @@
      * 
      * .. [#] This is a footnote
      * 
+ * * @param item * @return Element * @throws Exception @@ -1103,9 +1175,10 @@ /** *
-     * -a command-line option "a" -1 file, --one=file, --two file Multiple
+     * -a command-line option "a" -1 file, --one=file, --two file Multiple
      * options with arguments.
      * 
+ * * @param lexer * @return Element * @throws Exception @@ -1149,8 +1222,7 @@ * Body. *
* - * @param Element - * item + * @param Element item * @return Element * @throws Exception */ @@ -1501,7 +1573,8 @@ morecols++; // tmpCell = cells.get(c + morecols); // cellEnd = - // Integer.parseInt(tmpCell.attributeValue(JRSTLexer.CELL_INDEX_END)); + // Integer.parseInt(tmpCell.attributeValue(JRSTLexer. + // CELL_INDEX_END)); } if (morecols > 0) { entry @@ -1523,7 +1596,8 @@ } /** - *

* items begin with "-", "+", or "*" + *

+ * items begin with "-", "+", or "*" *

* *
@@ -1673,6 +1747,7 @@
      *    - debut 
      *    - de list
      * 
+ * * @param lexer * @return Element * @throws Exception @@ -1795,12 +1870,9 @@ } /** - * @param Element - * e1 - * @param Element - * e2 - * @param String - * ... attnames + * @param Element e1 + * @param Element e2 + * @param String ... attnames * @return boolean */ private boolean hasSameAttribute(Element e1, Element e2, String... attnames) { @@ -1817,10 +1889,8 @@ } /** - * @param Element - * from - * @param Element - * to + * @param Element from + * @param Element to * @throws DocumentException */ private void copyLevel(Element from, Element to) throws DocumentException { @@ -1832,10 +1902,8 @@ } /** - * @param String - * name - * @param Element - * e + * @param String name + * @param Element e * @return boolean * @throws DocumentException */ @@ -1845,14 +1913,10 @@ } /** - * @param String - * name - * @param Element - * e - * @param boolean - * throwError - * @param boolean - * eof + * @param String name + * @param Element e + * @param boolean throwError + * @param boolean eof * @return boolean * @throws DocumentException */ @@ -1867,10 +1931,8 @@ } /** - * @param String - * name - * @param Element - * e + * @param String name + * @param Element e * @return boolean */ private boolean itemNotEquals(String name, Element e) { @@ -1887,11 +1949,13 @@ return reader.read(r); } + /** *

- * Initialises les variables d'environements - * par ex, les hyperlinks peuvent etre referencer dans tous le document + * Initialises les variables d'environements par ex, les hyperlinks peuvent + * etre referencer dans tous le document *

+ * * @param idMax * @param symbolMax * @param symbolMaxRef @@ -1922,8 +1986,7 @@ /** * Parse text in element and replace text with parse result * - * @param Element - * e + * @param Element e * @throws DocumentException */ private void inline(Element e) throws DocumentException { Index: jrst2/src/java/org/codelutin/jrst/AdvancedReader.java diff -u jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.3 jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.4 --- jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.3 Tue Apr 24 14:28:59 2007 +++ jrst2/src/java/org/codelutin/jrst/AdvancedReader.java Tue Jul 29 07:59:52 2008 @@ -23,10 +23,10 @@ * Created: 27 oct. 06 00:24:57 * * @author poussin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2007-04-24 14:28:59 $ - * by : $Author: sletellier $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; @@ -41,38 +41,38 @@ import org.apache.commons.collections.primitives.ArrayCharList; import org.apache.commons.collections.primitives.CharList; - /** * Le principe est d'avoir dans cette classe le moyen de lire, et de retourner * la ou on etait avant la lecture (mark et reset de {@link BufferedReader}). *

* Mais il faut aussi pouvoir dire qu'en fin de compte on ne souhaite pas lire - * les caracteres que l'on vient de lire ({@link #unread(int)} a peu pres egal - * a {@link PushbackReader}) + * les caracteres que l'on vient de lire ({@link #unread(int)} a peu pres egal a + * {@link PushbackReader}) *

* Le pointer nextChar pointe toujours sur le prochain caractere qui sera lu *

- * Lorsque l'on appelle la method {@link #mark()} on vide aussi le buffer pour + * Lorsque l'on appelle la method {@link #mark()} on vide aussi le buffer pour * liberer de la place, car on a plus le moyen de retourner avant le mark que * l'on vient de positionner. *

- * On contraire du mark de {@link BufferedReader} ou {@link LineNumberReader} - * il n'y a pas a specifier le nombre de caractere a garder au maximum, seul la + * On contraire du mark de {@link BufferedReader} ou {@link LineNumberReader} il + * n'y a pas a specifier le nombre de caractere a garder au maximum, seul la * memoire nous limite. Du coup si l'on utilise cette classe sans mark, au final * on aura dans le buffer tout le contenu du reader, il faut donc utiliser mark - * avec cette classe + * avec cette classe + * + * buffer * - * buffer *

  * #########################
- * 0     ^       ^
+ * 0     ˆ       ˆ
  *       |       |
  *       |       + nextChar
  *       + markChar
  * 
- * + * * @author poussin - * + * */ public class AdvancedReader { @@ -80,20 +80,20 @@ protected static final String TAB = " "; /** nombre de caractere lu au minimum sur le vrai reader */ protected static final int READ_AHEAD = 80; - + protected Reader in = null; protected CharList buffer = null; - + protected int charNumber = 0; protected int charNumberMark = 0; protected int lineNumber = 0; protected int lineNumberMark = 0; - + protected int nextChar = 0; protected int markChar = 0; - + protected int readInMark = 0; - + /** * */ @@ -106,70 +106,70 @@ markChar = nextChar; charNumberMark = charNumber; lineNumberMark = lineNumber; - + free(markChar); } - + public void reset() throws IOException { nextChar = markChar; charNumber = charNumberMark; - lineNumber = lineNumberMark; - + lineNumber = lineNumberMark; + } - + public int readSinceMark() { return nextChar - markChar; } - + /** * @return the charNumber */ public int getCharNumber() { return this.charNumber; } - + /** * @return the lineNumber */ public int getLineNumber() { return this.lineNumber; } - - + /** * remove number of char in buffer * * @param number * @return the real number of char removed from the head of buffer - * @throws IOException + * @throws IOException */ private int free(int number) throws IOException { -// fill(number); + // fill(number); int result = Math.min(buffer.size(), number); buffer.subList(0, result).clear(); - + nextChar -= result; - markChar -= result; - + markChar -= result; + return result; } /** * ensure that have number char available and not allready read + * * @param number - * @throws IOException + * @throws IOException */ private void fill(int number) throws IOException { int needed = nextChar + number - buffer.size(); if (needed > 0) { - char [] cbuf = new char[needed + READ_AHEAD]; + char[] cbuf = new char[needed + READ_AHEAD]; int read = in.read(cbuf); - for (int i=0; i result = new ArrayList(); - + String tmp = ""; - for (int i=count; tmp!=null && i!=0; i--) { + for (int i = count; tmp != null && i != 0; i--) { tmp = readLine(); if (tmp != null) { result.add(tmp); } } - return result.toArray(new String [result.size()]); + return result.toArray(new String[result.size()]); } /** - * lit les lignes jusqu'a la premiere ligne blanche (non retournée) + * lit les lignes jusqu'a la premiere ligne blanche (non retournée) + * * @return * @throws IOException */ - public String [] readUntilBlank() throws IOException { - String [] result = readUntil("\\s*"); + public String[] readUntilBlank() throws IOException { + String[] result = readUntil("\\s*"); return result; } - - /** + + /** * lit les lignes jusqu'a la ligne qui correspond pas au pattern, cette * ligne n'est pas mise dans le resultat retourne + * * @param pattern * @return - * @throws IOException + * @throws IOException */ - public String [] readUntil(String pattern) throws IOException { + public String[] readUntil(String pattern) throws IOException { ArrayList result = new ArrayList(); String tmp = readLine(); while (tmp != null && !tmp.matches(pattern)) { @@ -335,9 +343,9 @@ if (tmp != null) { unread(tmp.length() + 1); // +1 for '\n' not in line } - return result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } - + /** * lit les lignes tant que les lignes correspondent au pattern * @@ -345,7 +353,7 @@ * @return * @throws IOException */ - public String [] readWhile(String pattern) throws IOException { + public String[] readWhile(String pattern) throws IOException { ArrayList result = new ArrayList(); String tmp = readLine(); while (tmp != null && tmp.matches(pattern)) { @@ -355,9 +363,7 @@ if (tmp != null) { unread(tmp.length() + 1); // +1 for '\n' not in line } - return result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } - -} - +} Index: jrst2/src/java/org/codelutin/jrst/DocumentHandler.java diff -u jrst2/src/java/org/codelutin/jrst/DocumentHandler.java:1.1.1.1 jrst2/src/java/org/codelutin/jrst/DocumentHandler.java:1.2 --- jrst2/src/java/org/codelutin/jrst/DocumentHandler.java:1.1.1.1 Mon Oct 30 19:34:05 2006 +++ jrst2/src/java/org/codelutin/jrst/DocumentHandler.java Tue Jul 29 07:59:52 2008 @@ -23,10 +23,10 @@ * Created: 30 oct. 06 10:22:52 * * @author poussin - * @version $Revision: 1.1.1.1 $ + * @version $Revision: 1.2 $ * - * Last update: $Date: 2006-10-30 19:34:05 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; @@ -35,20 +35,21 @@ import org.dom4j.Element; import org.dom4j.Text; - /** * @author poussin - * + * */ public interface DocumentHandler { public void startDocument(Document doc); + public void endDocument(Document doc); + public void startElement(Element e); + public void endElement(Element e); - public void text(Text t); - -} + public void text(Text t); +} Index: jrst2/src/java/org/codelutin/jrst/DocumentWalker.java diff -u jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.2 jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.3 --- jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.2 Thu May 10 10:18:41 2007 +++ jrst2/src/java/org/codelutin/jrst/DocumentWalker.java Tue Jul 29 07:59:52 2008 @@ -23,10 +23,10 @@ * Created: 30 oct. 06 10:28:10 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2007-05-10 10:18:41 $ - * by : $Author: sletellier $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; @@ -40,10 +40,9 @@ import org.dom4j.Node; import org.dom4j.Text; - /** * @author poussin - * + * */ public class DocumentWalker { @@ -51,6 +50,7 @@ static private Log log = LogFactory.getLog(DocumentWalker.class); protected DocumentHandler handler = null; + /** * */ @@ -64,25 +64,24 @@ walk(elem); handler.endDocument(doc); } - + @SuppressWarnings("unchecked") public void walk(Element elem) { handler.startElement(elem); - for (Node node : (List)elem.content()) { + for (Node node : (List) elem.content()) { switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - walk((Element)node); - break; - case Node.TEXT_NODE: - handler.text((Text)node); - break; - default: - log.warn("Not supported element type: " + node.getNodeTypeName()); - break; + case Node.ELEMENT_NODE: + walk((Element) node); + break; + case Node.TEXT_NODE: + handler.text((Text) node); + break; + default: + log.warn("Not supported element type: " + + node.getNodeTypeName()); + break; } } handler.endElement(elem); } } - - Index: jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.6 jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.7 --- jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.6 Thu May 10 10:18:41 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java Tue Jul 29 07:59:52 2008 @@ -23,15 +23,44 @@ * Created: 30 oct. 06 00:14:18 * * @author poussin - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Last update: $Date: 2007-05-10 10:18:41 $ - * by : $Author: sletellier $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; -import static org.codelutin.jrst.ReStructuredText.*; +import static org.codelutin.jrst.ReStructuredText.ADDRESS; +import static org.codelutin.jrst.ReStructuredText.AUTHOR; +import static org.codelutin.jrst.ReStructuredText.AUTHORS; +import static org.codelutin.jrst.ReStructuredText.BULLET_LIST; +import static org.codelutin.jrst.ReStructuredText.CLASSIFIER; +import static org.codelutin.jrst.ReStructuredText.CONTACT; +import static org.codelutin.jrst.ReStructuredText.COPYRIGHT; +import static org.codelutin.jrst.ReStructuredText.DATE; +import static org.codelutin.jrst.ReStructuredText.DEFINITION; +import static org.codelutin.jrst.ReStructuredText.DEFINITION_LIST; +import static org.codelutin.jrst.ReStructuredText.DOCINFO; +import static org.codelutin.jrst.ReStructuredText.EMPHASIS; +import static org.codelutin.jrst.ReStructuredText.ENUMERATED_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD_BODY; +import static org.codelutin.jrst.ReStructuredText.FIELD_LIST; +import static org.codelutin.jrst.ReStructuredText.FIELD_NAME; +import static org.codelutin.jrst.ReStructuredText.LIST_ITEM; +import static org.codelutin.jrst.ReStructuredText.LITERAL; +import static org.codelutin.jrst.ReStructuredText.LITERAL_BLOCK; +import static org.codelutin.jrst.ReStructuredText.ORGANIZATION; +import static org.codelutin.jrst.ReStructuredText.PARAGRAPH; +import static org.codelutin.jrst.ReStructuredText.REVISION; +import static org.codelutin.jrst.ReStructuredText.SECTION; +import static org.codelutin.jrst.ReStructuredText.STATUS; +import static org.codelutin.jrst.ReStructuredText.STRONG; +import static org.codelutin.jrst.ReStructuredText.TABLE; +import static org.codelutin.jrst.ReStructuredText.TITLE; +import static org.codelutin.jrst.ReStructuredText.TITLE_CHAR; +import static org.codelutin.jrst.ReStructuredText.TRANSITION; +import static org.codelutin.jrst.ReStructuredText.VERSION; import java.io.File; import java.io.IOException; @@ -62,14 +91,13 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; - /** - * Cette classe contient plusieurs methode pour generer, soit en utilisant - * une feuille de style {@link #generate(Document, URL, Writer)}, soit un + * Cette classe contient plusieurs methode pour generer, soit en utilisant une + * feuille de style {@link #generate(Document, URL, Writer)}, soit un * {@link ContentHandler} avec {@link #generate(Document, ContentHandler)}, soit - * {@link DocumentHandler} avec {@link #generate(Document, ContentHandler)} - * ou bien regenerer du RST avec {@link #generate(Document)} dans les deux - * dernier cas il faut passer un {@link Writer} en paremetre du constructeur. + * {@link DocumentHandler} avec {@link #generate(Document, ContentHandler)} ou + * bien regenerer du RST avec {@link #generate(Document)} dans les deux dernier + * cas il faut passer un {@link Writer} en paremetre du constructeur. *

* On peut aussi transformer le {@link Document} en un autre {@link Document} * avec {@link #transform(Document, URL)} @@ -79,39 +107,39 @@ public class JRSTGenerator implements DocumentHandler { static boolean DEBUG = true; - + static private Log log = LogFactory.getLog(JRSTGenerator.class); - + protected Writer out = null; protected int sectionLevel = 0; protected int indent = 0; - + protected String listType = "bullet|enumerated|..."; - protected int enumStart = 1; - + protected int enumStart = 1; + protected URIResolver uriResolver = null; - + public JRSTGenerator() { } - + public JRSTGenerator(Writer out) { this.out = out; } - + /** * @return the uriResolver */ public URIResolver getUriResolver() { return this.uriResolver; } - + /** * @param uriResolver the uriResolver to set */ public void setUriResolver(URIResolver uriResolver) { this.uriResolver = uriResolver; } - + /** * Generate using this class as handler, this generate RST text to out * passed in constructor @@ -123,12 +151,13 @@ public void generate(Document doc) throws IOException { generate(doc, this); } - - public void generate(Document doc, DocumentHandler handler) throws IOException { + + public void generate(Document doc, DocumentHandler handler) + throws IOException { DocumentWalker walker = new DocumentWalker(handler); walker.walk(doc); } - + /** * Generate using handler passed in argument * @@ -137,7 +166,8 @@ * @throws IOException * @throws TransformerException */ - public void generate(Document doc, ContentHandler handler) throws IOException, TransformerException { + public void generate(Document doc, ContentHandler handler) + throws IOException, TransformerException { // load the transformer using JAXP TransformerFactory factory = TransformerFactory.newInstance(); if (uriResolver != null) { @@ -146,11 +176,11 @@ Transformer transformer = factory.newTransformer(); // now lets style the given document - DocumentSource source = new DocumentSource( doc ); + DocumentSource source = new DocumentSource(doc); SAXResult result = new SAXResult(handler); - transformer.transform( source, result ); + transformer.transform(source, result); } - + /** * Used writer passed in construction class * @@ -159,10 +189,11 @@ * @throws IOException * @throws TransformerException */ - public void generate(Document doc, URL stylesheet) throws IOException, TransformerException { + public void generate(Document doc, URL stylesheet) throws IOException, + TransformerException { generate(doc, stylesheet, out); } - + /** * Generate out from document using stylesheet * @@ -172,7 +203,8 @@ * @throws IOException * @throws TransformerException */ - public void generate(Document doc, URL stylesheet, Writer out) throws IOException, TransformerException { + public void generate(Document doc, URL stylesheet, Writer out) + throws IOException, TransformerException { // load the transformer using JAXP TransformerFactory factory = TransformerFactory.newInstance(); if (uriResolver != null) { @@ -180,18 +212,17 @@ } else { factory.setURIResolver(new DocumentResolver(stylesheet)); } - Transformer transformer = factory.newTransformer( - new StreamSource( stylesheet.openStream() ) - ); + Transformer transformer = factory.newTransformer(new StreamSource( + stylesheet.openStream())); // now lets style the given document - DocumentSource source = new DocumentSource( doc ); + DocumentSource source = new DocumentSource(doc); StreamResult result = new StreamResult(out); - transformer.transform( source, result ); + transformer.transform(source, result); out.flush(); } - + /** * Transform doc in another XML document * @@ -201,7 +232,8 @@ * @throws TransformerException * @throws IOException */ - public Document transform(Document doc, URL stylesheet, String ... args) throws TransformerException, IOException { + public Document transform(Document doc, URL stylesheet, String... args) + throws TransformerException, IOException { // load the transformer using JAXP TransformerFactory factory = TransformerFactory.newInstance(); if (uriResolver != null) { @@ -209,33 +241,35 @@ } else { factory.setURIResolver(new DocumentResolver(stylesheet)); } - Transformer transformer = factory.newTransformer( - new StreamSource( stylesheet.openStream() ) - ); + Transformer transformer = factory.newTransformer(new StreamSource( + stylesheet.openStream())); // DEBUG To see where is the probleme with the dtd locator :( -// transformer.setErrorListener(new ErrorListener() { -// public void error(TransformerException exception) throws TransformerException { -// exception.printStackTrace(); -// } -// public void fatalError(TransformerException exception) throws TransformerException { -// exception.printStackTrace(); -// } -// public void warning(TransformerException exception) throws TransformerException { -// exception.printStackTrace(); -// } -// -// }); - + // transformer.setErrorListener(new ErrorListener() { + // public void error(TransformerException exception) throws + // TransformerException { + // exception.printStackTrace(); + // } + // public void fatalError(TransformerException exception) throws + // TransformerException { + // exception.printStackTrace(); + // } + // public void warning(TransformerException exception) throws + // TransformerException { + // exception.printStackTrace(); + // } + // + // }); + // TODO -// for (int i=0; i()"; public static final String QUOTED_CHAR = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; - public static final String BULLET_CHAR = "*" + "+" + "-" + "\u2022" + "\u2023" + "\u2043"; - public static final String DOCINFO_ITEM = - "author|authors|organization|address|contact|version|revision|status|date|copyright"; - public static final String FOOTNOTE_SYMBOL = "\u002A"+"\u2020"+"\u2021"+"\u00A7"+"\u00B6"+"\u0023"+"\u2660"+"\u2665"+"\u2666"+"\u2663"; - // public static final String ADMONITION = "admonition|caution|danger|error|hint|important|note|tip|warning"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + public static final String BULLET_CHAR = "*" + "+" + "-" + "\u2022" + + "\u2023" + "\u2043"; + public static final String DOCINFO_ITEM = "author|authors|organization|address|contact|version|revision|status|date|copyright"; + public static final String FOOTNOTE_SYMBOL = "\u002A" + "\u2020" + "\u2021" + + "\u00A7" + "\u00B6" + "\u0023" + "\u2660" + "\u2665" + "\u2666" + + "\u2663"; + // public static final String ADMONITION = + // "admonition|caution|danger|error|hint|important|note|tip|warning"; + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Root Element - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String DOCUMENT = "document"; - - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Title Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String TITLE = "title"; public static final String SUBTITLE = "subtitle"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Bibliographic Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String DOCINFO = "docinfo"; -// public static final String INFO = "info"; + // public static final String INFO = "info"; public static final String AUTHOR = "author"; public static final String AUTHORS = "authors"; public static final String ORGANIZATION = "organization"; @@ -74,27 +76,27 @@ public static final String VERSION = "version"; public static final String REVISION = "revision"; public static final String STATUS = "status"; - public static final String DATE = "date"; + public static final String DATE = "date"; public static final String COPYRIGHT = "copyright"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Decoration Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String DECORATION = "decoration"; public static final String HEADER = "header"; public static final String FOOTER = "footer"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Structural Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String SECTION = "section"; public static final String TOPIC = "topic"; public static final String SIDEBAR = "sidebar"; public static final String TRANSITION = "transition"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Body Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String PARAGRAPH = "paragraph"; public static final String COMPOUND = "compound"; public static final String CONTAINER = "container"; @@ -147,7 +149,7 @@ public static final String LEGEND = "legend"; public static final String SYSTEM_MESSAGE = "system_message"; public static final String RAW = "raw"; - + // table public static final String TABLE = "table"; public static final String TGROUP = "tgroup"; @@ -157,9 +159,9 @@ public static final String ROW = "row"; public static final String ENTRY = "entry"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Inline Elements - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final String EMPHASIS = "emphasis"; public static final String STRONG = "strong"; public static final String LITERAL = "literal"; @@ -176,19 +178,27 @@ public static final String PROBLEMATIC = "problematic"; public static final String GENERATED = "generated"; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Inline Elements Regex - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - public static final Pattern REGEX_EMPHASIS = Pattern.compile("\\*([^*(\\]_.+\\[)].+?)\\*"); - public static final Pattern REGEX_STRONG = Pattern.compile("\\*\\*(.+?)\\*\\*"); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + public static final Pattern REGEX_EMPHASIS = Pattern + .compile("\\*([^*(\\]_.+\\[)].+?)\\*"); + public static final Pattern REGEX_STRONG = Pattern + .compile("\\*\\*(.+?)\\*\\*"); public static final Pattern REGEX_LITERAL = Pattern.compile("``([^`]+)``"); - public static final Pattern REGEX_REFERENCE = Pattern.compile("(http://[-/%#[\\&&&[^(>)]]\\._\\w]+\\w+)((\\W|&|$)+)"); - public static final Pattern REGEX_INLINE_REFERENCE = Pattern.compile("`(.+) \\<\\;(http://[-/%#&\\._\\w]+)(\\>\\;)`"); - public static final Pattern REGEX_EMAIL = Pattern.compile("(^|[^_\\w])([-\\._\\w]+@[-\\._\\w]+)([^-\\._\\w]|$)"); - public static final Pattern REGEX_FOOTNOTE_REFERENCE = Pattern.compile("\\[(#|[0-9]|\\*)\\w*\\]_"); - //"\\[([0-9]+?|#)\\]"); - public static final Pattern REGEX_CITATION_REFERENCE = Pattern.compile("\\[([^\\]]+?)\\]"); - public static final Pattern REGEX_SUBSTITUTION_REFERENCE = Pattern.compile("\\|([^|]+?)\\|"); + public static final Pattern REGEX_REFERENCE = Pattern + .compile("(http://[-/%#[\\&&&[^(>)]]\\._\\w]+\\w+)((\\W|&|$)+)"); + public static final Pattern REGEX_INLINE_REFERENCE = Pattern + .compile("`(.+) \\<\\;(http://[-/%#&\\._\\w]+)(\\>\\;)`"); + public static final Pattern REGEX_EMAIL = Pattern + .compile("(^|[^_\\w])([-\\._\\w]+@[-\\._\\w]+)([^-\\._\\w]|$)"); + public static final Pattern REGEX_FOOTNOTE_REFERENCE = Pattern + .compile("\\[(#|[0-9]|\\*)\\w*\\]_"); + // "\\[([0-9]+?|#)\\]"); + public static final Pattern REGEX_CITATION_REFERENCE = Pattern + .compile("\\[([^\\]]+?)\\]"); + public static final Pattern REGEX_SUBSTITUTION_REFERENCE = Pattern + .compile("\\|([^|]+?)\\|"); public static final Pattern REGEX_ABBREVIATION = Pattern.compile("(.*?)"); public static final Pattern REGEX_ACRONYM = Pattern.compile("(.*?)"); public static final Pattern REGEX_SUPERSCRIPT = Pattern.compile("(.*?)"); @@ -197,9 +207,9 @@ public static final Pattern REGEX_PROBLEMATIC = Pattern.compile("(.*?)"); public static final Pattern REGEX_GENERATED = Pattern.compile("(.*?)"); // `truc truc`_ - public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^_<>]+\\`_(\\W|$))|(('|`)[^_<`(')>]+('|`)_(\\W|$))|([\\S]+[^\\s<>\\.`]+_(\\W|$))"); + public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern + .compile("(\\`[^_<>]+\\`_(\\W|$))|(('|`)[^_<`(')>]+('|`)_(\\W|$))|([\\S]+[^\\s<>\\.`]+_(\\W|$))"); // `trux truc`__ - public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`\\]\\[]+\\`__)|(\\w+[^()`\\s<>]+__)"); + public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern + .compile("(\\`[^<>`\\]\\[]+\\`__)|(\\w+[^()`\\s<>]+__)"); } - - Index: jrst2/src/java/org/codelutin/jrst/JRST.java diff -u jrst2/src/java/org/codelutin/jrst/JRST.java:1.16 jrst2/src/java/org/codelutin/jrst/JRST.java:1.17 --- jrst2/src/java/org/codelutin/jrst/JRST.java:1.16 Mon Mar 3 15:21:18 2008 +++ jrst2/src/java/org/codelutin/jrst/JRST.java Tue Jul 29 07:59:52 2008 @@ -23,10 +23,10 @@ * Created: 3 nov. 06 20:56:00 * * @author poussin - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * - * Last update: $Date: 2008-03-03 15:21:18 $ - * by : $Author: glandais $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; @@ -34,11 +34,9 @@ import java.awt.GraphicsEnvironment; import java.io.BufferedOutputStream; import java.io.BufferedReader; -import java.io.Console; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -51,37 +49,40 @@ import java.util.Map; import java.util.ResourceBundle; - import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; +import org.apache.fop.apps.MimeConstants; +import org.codelutin.i18n.I18n; import org.codelutin.util.FileCompletion; import org.codelutin.util.FileUtil; +import org.codelutin.util.Resource; import org.codelutin.util.StringUtil; import org.dom4j.Document; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; + import uk.co.flamingpenguin.jewel.cli.Cli; import uk.co.flamingpenguin.jewel.cli.CliFactory; import uk.co.flamingpenguin.jewel.cli.CommandLineInterface; import uk.co.flamingpenguin.jewel.cli.Option; import uk.co.flamingpenguin.jewel.cli.Unparsed; -import org.codelutin.i18n.I18n; - -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.FopFactory; -import org.apache.fop.apps.Fop; -import org.apache.fop.apps.MimeConstants; /** - * FIXME: 'JRST --help' doesn't work, but 'JRST --help toto' work :( - * FIXME: 'JRST -c' doesn't work, but 'JRST -c toto' + * FIXME: 'JRST --help' doesn't work, but 'JRST --help toto' work :( FIXME: + * 'JRST -c' doesn't work, but 'JRST -c toto' + * * @author poussin */ @CommandLineInterface(application = "JRST") @@ -100,8 +101,10 @@ static final private String rst2xdoc = "/xsl/rst2xdoc.xsl"; static final private String rst2docbook = "/xsl/dn2dbk.xsl"; - //static final private String walshDir = "/home/letellier/docbook5-xsl-1.72.0/"; - static final private String walshDir = "/docbook-xsl-nwalsh"; + // static final private String walshDir = + // "/home/letellier/docbook5-xsl-1.72.0/"; + //static final private String walshDir = "/docbook-xsl-nwalsh"; + static final private String walshDir = ""; // static final private String docbook2odfDir = "/docbook2odf-0.211"; static final private String docbook2xhtml = walshDir + "/xhtml/docbook.xsl"; @@ -136,10 +139,12 @@ // static final public String TYPE_ODT = "odt"; static final public String TYPE_FO = "fo"; - + static final public String TYPE_PDF = "pdf"; - /** key, Out type; value: chain of XSL file to provide wanted file for output */ + /** + * key, Out type; value: chain of XSL file to provide wanted file for output + */ static private Map stylesheets = null; static { @@ -153,16 +158,18 @@ stylesheets.put(TYPE_RST, rst2rst); // stylesheets.put(TYPE_ODT, rst2docbook+","+docbook2odf); stylesheets.put(TYPE_FO, rst2docbook + "," + docbook2fo); - stylesheets.put(TYPE_PDF, rst2docbook + "," + docbook2fo); + stylesheets.put(TYPE_PDF, rst2docbook + "," + docbook2fo); } static public void main(String[] args) throws Exception { if (args.length == 0) args = askOption(); - if (args==null){System.exit(0);} - + if (args == null) { + System.exit(0); + } + JRSTOption option = CliFactory.parseArguments(JRSTOption.class, args); - + if (option.isHelp()) { Cli cli = CliFactory.createCli(JRSTOption.class); System.out.println(cli.getHelpMessage()); @@ -183,48 +190,55 @@ .isForce() ? Overwrite.ALLTIME : Overwrite.NEVER); } - private static String[] askOption() throws SecurityException, NoSuchMethodException, IOException{ + private static String[] askOption() throws SecurityException, + NoSuchMethodException, IOException { String[] result = null; - try{ - GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + try { + GraphicsEnvironment ge = GraphicsEnvironment + .getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); - boolean done=false; - if (!(gs==null)){ - if (gs.length>0){ - result=askOptionGraph(); - done=true; + boolean done = false; + if (!(gs == null)) { + if (gs.length > 0) { + result = askOptionGraph(); + done = true; } } if (!done) - result=askOptionText(); - }catch(java.awt.HeadlessException e){ - result=askOptionText(); + result = askOptionText(); + } catch (java.awt.HeadlessException e) { + result = askOptionText(); } - + return result; } -/** - * interface graphique - * @return - * @throws SecurityException - * @throws NoSuchMethodException - */ - private static String[] askOptionGraph() throws SecurityException, NoSuchMethodException { - Method m =JRSTOption.class.getMethod("getOutType", null); + + /** + * interface graphique + * + * @return + * @throws SecurityException + * @throws NoSuchMethodException + */ + private static String[] askOptionGraph() throws SecurityException, + NoSuchMethodException { + Method m = JRSTOption.class.getMethod("getOutType", null); Option a = m.getAnnotation(Option.class); JRSTInterface graph = new JRSTInterface(a.pattern()); - - //String[] result=graph.askOption(); + + // String[] result=graph.askOption(); return graph.getCmd(); } -/** - * Interface textuel - * @return String[] - * @throws IOException - */ + + /** + * Interface textuel + * + * @return String[] + * @throws IOException + */ private static String[] askOptionText() throws IOException { - //language + // language if (Locale.getDefault().getLanguage() == "fr") I18n.init("fr", "FR"); else @@ -236,7 +250,7 @@ String cheminRST = ""; while (!done) { System.out.println(bundle.getString("rstFile?")); - cheminRST = lireFile(false,false); + cheminRST = lireFile(false, false); if (cheminRST.length() == 0) System.exit(0); File fileRST = new File(cheminRST); @@ -261,33 +275,35 @@ done = false; while (!done) { System.out.println(bundle.getString("xslFile?")); - String cheminXSLtmp = lireFile(false,true); + String cheminXSLtmp = lireFile(false, true); File fileRST = new File(cheminXSLtmp); - if (cheminXSLtmp.equals("")){ - if (cheminXSL.length()!=0) - cheminXSL=cheminXSL.substring(0,cheminXSL.length()-1); - done=true; - } - else{ + if (cheminXSLtmp.equals("")) { + if (cheminXSL.length() != 0) + cheminXSL = cheminXSL.substring(0, + cheminXSL.length() - 1); + done = true; + } else { if (!fileRST.exists()) { System.out.println(bundle.getString("dontExist")); - } else{ - cheminXSL+=cheminXSLtmp; + } else { + cheminXSL += cheminXSLtmp; String other = ""; do { System.out.println(bundle.getString("other?")); other = lire(); } while (!other.matches("y|n|o")); if (other.equals("y") || other.equals("o")) - cheminXSL+=","; + cheminXSL += ","; else if (other.equals("n")) done = true; } } - + } - if (cheminXSL.length() == 0 || !type.matches("xhtml|docbook|xml|html|xdoc|rst|pdf|odt|rtf")) + if (cheminXSL.length() == 0 + || !type + .matches("xhtml|docbook|xml|html|xdoc|rst|pdf|odt|rtf")) type = "xml"; } boolean ecraser = false; @@ -295,7 +311,7 @@ String cheminSortie = ""; while (!done) { System.out.println(bundle.getString("outputFile?")); - cheminSortie = lireFile(true,true); + cheminSortie = lireFile(true, true); File fileRST = new File(cheminSortie); if (fileRST.exists()) { @@ -322,11 +338,13 @@ cmd += " " + cheminRST + " "; return cmd.split(" "); } + /** * lit une ligne + * * @return String - */ - public static String lire(){ + */ + public static String lire() { String ligne_lue = null; try { @@ -339,20 +357,24 @@ return ligne_lue; } - public static String lireFile(boolean enreg, boolean exit) throws IOException{ - String line=""; - FileCompletion fc = new FileCompletion(enreg,exit); + + public static String lireFile(boolean enreg, boolean exit) + throws IOException { + String line = ""; + FileCompletion fc = new FileCompletion(enreg, exit); if (fc.consoleAvailable()) - line=fc.read(); - if (line==null) - line=""; + line = fc.read(); + if (line == null) + line = ""; return line; } - public static void generate(String xslListOrOutType, File fileIn, File fileOut, Overwrite overwrite) throws Exception { - generate(xslListOrOutType, fileIn, "ISO-8859-15", fileOut, "ISO-8859-15", overwrite); + public static void generate(String xslListOrOutType, File fileIn, + File fileOut, Overwrite overwrite) throws Exception { + generate(xslListOrOutType, fileIn, "ISO-8859-15", fileOut, + "ISO-8859-15", overwrite); } - + /** * * @param xslListOrOutType @@ -362,13 +384,17 @@ * @throws Exception */ - public static void generate(String xslListOrOutType, File fileIn, String inputEncoding, File fileOut, String outputEncoding, Overwrite overwrite) throws Exception { + public static void generate(String xslListOrOutType, File fileIn, + String inputEncoding, File fileOut, String outputEncoding, + Overwrite overwrite) throws Exception { if (fileOut != null && fileOut.exists() && (overwrite == Overwrite.NEVER || (overwrite == Overwrite.IFNEWER && FileUtil .isNewer(fileIn, fileOut)))) { - //System.err.println("Don't generate file " + fileOut + ", because already exists"); - log.info("Don't generate file " + fileOut + ", because already exists"); + // System.err.println("Don't generate file " + fileOut + + // ", because already exists"); + log.info("Don't generate file " + fileOut + + ", because already exists"); } else { // search xsl file list to apply String xslList = stylesheets.get(xslListOrOutType); @@ -376,14 +402,12 @@ xslList = xslListOrOutType; } - - // parse rst file URL url = fileIn.toURL(); Reader in = new InputStreamReader(url.openStream(), inputEncoding); JRSTReader jrst = new JRSTReader(); Document doc = jrst.read(in); - + // apply xsl on rst xml document JRSTGenerator gen = new JRSTGenerator(); String[] xsls = StringUtil.split(xslList, ","); @@ -401,71 +425,79 @@ } doc = gen.transform(doc, stylesheet); } - - boolean pdf=false; - //generation PDF - if (xslListOrOutType!=null){ - if (xslListOrOutType.equals("pdf")){ - pdf=true; + + boolean pdf = false; + // generation PDF + if (xslListOrOutType != null) { + if (xslListOrOutType.equals("pdf")) { + pdf = true; FopFactory fopFactory = FopFactory.newInstance(); - //OutputStream outPDF = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf"))); - + // OutputStream outPDF = new BufferedOutputStream(new + // FileOutputStream(new File("C:/Temp/myfile.pdf"))); + OutputStream outPDF = null; if (fileOut != null) { fileOut.getAbsoluteFile().getParentFile().mkdirs(); - outPDF = new BufferedOutputStream(new FileOutputStream(fileOut)); + outPDF = new BufferedOutputStream(new FileOutputStream( + fileOut)); } else { outPDF = new BufferedOutputStream(System.out); } - + FOUserAgent userAgent = fopFactory.newFOUserAgent(); - - //Step 3: Construct fop with desired output format - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, outPDF); - + + // Step 3: Construct fop with desired output format + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, + userAgent, outPDF); + // Step 4: Setup JAXP using identity transformer - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); // identity transformer - - // Step 5: Setup input and output for XSLT transformation + TransformerFactory factory = TransformerFactory + .newInstance(); + Transformer transformer = factory.newTransformer(); // identity + // transformer + + // Step 5: Setup input and output for XSLT transformation // Setup input stream Source src = new StreamSource(new StringReader(doc.asXML())); - - // Resulting SAX events (the generated FO) must be piped through to FOP + + // Resulting SAX events (the generated FO) must be piped + // through to FOP Result res = new SAXResult(fop.getDefaultHandler()); - + // Step 6: Start XSLT transformation and FOP processing transformer.transform(src, res); - - + if (fileOut != null) { outPDF.close(); } } } - if(!pdf){ - // prepare the output flux + if (!pdf) { + // prepare the output flux XMLWriter out = null; if (fileOut != null) { fileOut.getAbsoluteFile().getParentFile().mkdirs(); - out = new XMLWriter(FileUtil.getWriter(fileOut, outputEncoding), new OutputFormat( - " ", true,outputEncoding)); + out = new XMLWriter(FileUtil.getWriter(fileOut, + outputEncoding), new OutputFormat(" ", true, + outputEncoding)); } else { - out = new XMLWriter(System.out, new OutputFormat(" ", true, outputEncoding)); + out = new XMLWriter(System.out, new OutputFormat(" ", + true, outputEncoding)); } // write generated document out.write(doc); - + if (fileOut != null) { out.close(); } } } } -/** - * Les options - */ + + /** + * Les options + */ public static interface JRSTOption { @Option(description = "display this help and exit") @@ -476,7 +508,7 @@ @Option(shortName = "c", description = "Console mode") public boolean isConsole(); - + @Option(shortName = "x", description = "XSL file list to apply, comma separated") public String getXslFile(); Index: jrst2/src/java/org/codelutin/jrst/JRSTDirective.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTDirective.java:1.1 jrst2/src/java/org/codelutin/jrst/JRSTDirective.java:1.2 --- jrst2/src/java/org/codelutin/jrst/JRSTDirective.java:1.1 Mon Nov 6 15:08:46 2006 +++ jrst2/src/java/org/codelutin/jrst/JRSTDirective.java Tue Jul 29 07:59:52 2008 @@ -23,10 +23,10 @@ * Created: 4 nov. 06 12:49:39 * * @author poussin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Last update: $Date: 2006-11-06 15:08:46 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2008-07-29 07:59:52 $ + * by : $Author: chatellier $ */ package org.codelutin.jrst; @@ -34,22 +34,18 @@ import org.dom4j.Element; import org.dom4j.Node; - /** * @author poussin - * + * */ public interface JRSTDirective { /** - * parse directive block element and return element to put in final - * XML + * parse directive block element and return element to put in final XML * * @param e * @return */ public Node parse(Element e); } - - Index: jrst2/src/java/org/codelutin/jrst/JRSTInterface.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTInterface.java:1.2 jrst2/src/java/org/codelutin/jrst/JRSTInterface.java:1.3 --- jrst2/src/java/org/codelutin/jrst/JRSTInterface.java:1.2 Fri Jun 22 13:34:44 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTInterface.java Tue Jul 29 07:59:52 2008 @@ -31,7 +31,7 @@ import org.codelutin.i18n.I18n; import org.codelutin.util.Resource; -public class JRSTInterface extends JDialog{ +public class JRSTInterface extends JDialog { private JPanel savePanel = null; private JPanel formatPanel = null; @@ -45,7 +45,7 @@ private JComboBox formatList = null; private JButton boutonAnnuler = null; - + private JButton boutonConvertir = null; private JPanel panelPrincipal = null; @@ -53,8 +53,8 @@ private JPanel boutonPanel = null; private JButton boutonSaveLocation = null; - - private JLabel errorLbl=null; + + private JLabel errorLbl = null; private JButton boutonOpenLocation = null; @@ -79,7 +79,7 @@ private LinkedList ListXslBouton = null; private LinkedList ListXslBoutonLocation = null; - private boolean ecrase=false; + private boolean ecrase = false; private String[] commande = null; private ImageIcon open = Resource.getIcon("icone/open.png"); @@ -88,10 +88,11 @@ private ResourceBundle bundle = null; private LinkedList composantsXSL = null; + /** * le parametre initialise les options disponibles - * @param String - * o + * + * @param String o */ public JRSTInterface(String o) { // language @@ -99,24 +100,26 @@ I18n.init("fr", "FR"); else I18n.init("en", "US"); - bundle = ResourceBundle.getBundle("org.codelutin.i18n.I18nBundleBridge"); - this.setFormats(o); - this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - this.setTitle("JRST"); - this.setLayout(new BorderLayout()); - this.add(getPanelPrincipal(), BorderLayout.CENTER); - Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - this.setModal(true); // pour que JRST attende que cette fenetre soit ferme - this.pack(); - this.setResizable(false); - this.setLocation(dim.width/2 - this.getWidth()/2, dim.height/2 - this.getHeight()/2); // Centrer - this.setVisible(true); + bundle = ResourceBundle + .getBundle("org.codelutin.i18n.I18nBundleBridge"); + this.setFormats(o); + this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + this.setTitle("JRST"); + this.setLayout(new BorderLayout()); + this.add(getPanelPrincipal(), BorderLayout.CENTER); + Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); + this.setModal(true); // pour que JRST attende que cette fenetre soit + // ferme + this.pack(); + this.setResizable(false); + this.setLocation(dim.width / 2 - this.getWidth() / 2, dim.height / 2 + - this.getHeight() / 2); // Centrer + this.setVisible(true); } - private JPanel getPanelPrincipal() { if (panelPrincipal == null) { - + panelPrincipal = new JPanel(); panelPrincipal.setLayout(new BoxLayout(panelPrincipal, BoxLayout.Y_AXIS)); @@ -130,9 +133,10 @@ } return panelPrincipal; } - private JLabel getErrorLabel(){ - if (errorLbl==null){ - errorLbl=new JLabel(""); + + private JLabel getErrorLabel() { + if (errorLbl == null) { + errorLbl = new JLabel(""); } return errorLbl; } @@ -197,7 +201,7 @@ } private LinkedList getListAddXslPanel() { - if (ListAddXslPanel.size()==0) { + if (ListAddXslPanel.size() == 0) { ListAddXslPanel.add(ajoutXSL()); getFormatList().setEnabled(getFormat().isSelected()); @@ -214,14 +218,14 @@ b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); - if (b.getIcon()==more) - + if (b.getIcon() == more) + ajout(); else supprimerXslLigne((JButton) e.getSource()); } }); - + composantsXSL.add(b); ListXslBouton.add(b); JTextField t = new JTextField(); @@ -433,8 +437,6 @@ return openText; } - - private JButton getBoutonOpenLocation() { if (boutonOpenLocation == null) { boutonOpenLocation = new JButton(open); @@ -464,68 +466,66 @@ fc.showSaveDialog(this); File file = fc.getSelectedFile(); if (file != null) { - if (file.exists()){ + if (file.exists()) { int choix = askEcraser(); - if (choix == JOptionPane.YES_OPTION){ + if (choix == JOptionPane.YES_OPTION) { ecrase = true; getSaveText().setText(file.getAbsolutePath()); - } - else if (choix == JOptionPane.NO_OPTION) + } else if (choix == JOptionPane.NO_OPTION) openSaveLocation(); - } - else + } else getSaveText().setText(file.getAbsolutePath()); } } - public int askEcraser(){ - int choix = JOptionPane.showConfirmDialog(this,bundle.getObject("overwriteGraph?")); - + + public int askEcraser() { + int choix = JOptionPane.showConfirmDialog(this, bundle + .getObject("overwriteGraph?")); + return choix; } + public void setFormats(String formats) { listFormats = formats.split("\\|"); } - private void annuler() { System.exit(0); } - - + private void convert() { - boolean exit=false; - if (getOpenText().getText().equals("")){ + boolean exit = false; + if (getOpenText().getText().equals("")) { getErrorLabel().setText(bundle.getString("openEmpty?")); getErrorLabel().setForeground(Color.RED); this.pack(); - } - else{ - if (!ecrase){ + } else { + if (!ecrase) { File file = new File(getSaveText().getText()); if (file != null) { - if (file.exists()){ + if (file.exists()) { int choix = askEcraser(); if (choix == JOptionPane.YES_OPTION) ecrase = true; else if (choix == JOptionPane.NO_OPTION) - exit=true; - } + exit = true; + } } } - if (!exit){ + if (!exit) { String cmd = ""; if (ecrase) cmd += "--force "; if (getFormat().isSelected()) cmd += "-t " + getFormatList().getSelectedItem(); - else{ + else { cmd += "-x "; - for (JTextField t : ListXslText){ + for (JTextField t : ListXslText) { if (!t.getText().equals("")) - cmd+=t.getText()+","; + cmd += t.getText() + ","; } - cmd=cmd.substring(0,cmd.length()-1); + cmd = cmd.substring(0, cmd.length() - 1); } if (getSaveText().getText().length() > 0) cmd += " -o " + getSaveText().getText(); @@ -535,7 +535,8 @@ } } } - public String[] getCmd(){ + + public String[] getCmd() { return commande; } Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.33 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.34 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.33 Thu Nov 29 10:18:10 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Tue Jul 29 07:59:52 2008 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.33 $ + * @version $Revision: 1.34 $ * - * Last update: $Date: 2007-11-29 10:18:10 $ + * Last update: $Date: 2008-07-29 07:59:52 $ * by : $Author: chatellier $ */ @@ -38,6 +38,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dom4j.DocumentHelper; @@ -199,7 +200,9 @@ private AdvancedReader in = null; - /** length of the last element returned (number of char need to this element) */ + /** + * length of the last element returned (number of char need to this element) + */ private int elementLength = 0; public JRSTLexer(Reader reader) { @@ -255,8 +258,7 @@ * Read block text, block text have same indentation and is continu (no * blank line) * - * @param minLeftMargin - * min left blank needed to accept to read block + * @param minLeftMargin min left blank needed to accept to read block * @return String[] * @throws IOException */ @@ -277,8 +279,7 @@ /** * All lines are joined and left and right spaces are removed during join * - * @param String[] - * lines + * @param String[] lines * @return String */ private String joinBlock(String[] lines) { @@ -290,12 +291,9 @@ * All lines are joined whith the String joinSep and left and right spaces * are removed if trim * - * @param String[] - * lines - * @param String - * joinSep - * @param Boolean - * trim + * @param String[] lines + * @param String joinSep + * @param Boolean trim * @return String */ private String joinBlock(String[] lines, String joinSep, boolean trim) { @@ -383,6 +381,7 @@ *

      * .. __: http://www.python.org
      * 
+ * * @return Element * @throws IOException */ @@ -560,7 +559,7 @@ result = DocumentHelper.createElement("remove").addAttribute( "level", "" + level(line)); } - + } endPeek(); return result; @@ -607,30 +606,28 @@ * read options * *
-     * Ex :     -a            command-line option "a"
+     * Ex :     -a            command-line option "a"
      *          -1 file, --one=file, --two file
      *                     Multiple options with arguments.
-     *
      * Schéma :  ________________________________
      *           v          |                    |
-     *        -{1,2}\w+ ->|','                   |
-     *                    |'='-----|-> \w+ --->|','
+     *        -{1,2}\w+ ->|','                   |
+     *                    |'='-----|-> \w+ --->|','
      *                    |' '-----|           |' '---+
-     *                    |"  " -----> \w+ ---> end   |
-     *                      ^                         |
+     *                    |"  " -----> \w+ ---> end   |
+     *                      ˆ                         |
      *                      |_________________________|
-     *
      * Légende :   
      * 
-     *          -{1,2} --> 1 or 2 tirets
-     *          \w+ -----> word characters one or more times
+     *          -{1,2} --> 1 or 2 tirets
+     *          \w+ -----> word characters one or more times
      * 
* * @return Element * @throws IOException */ public Element peekOption() throws IOException { - + beginPeek(); Element result = null; String line = in.readLine(); @@ -1497,21 +1494,16 @@ // result.addText(line); } else if (line.matches("^\\s*(=+ +)+=+\\s*$")) { // Les donnees de la table peuvent depasser de celle-ci - /* - ===== ===== ====== - Inputs Output - ------------ ------ - A B A or B - ===== ===== ====== - False False Second column of row 1. - True False Second column of row 2. - - True 2 - Second column of row 3. - - - Second item in bullet - list (row 3, column 2). - ============ ====== - */ + /* + * ===== ===== ====== Inputs Output ------------ ------ A B A or + * B ===== ===== ====== False False Second column of row 1. True + * False Second column of row 2. + * + * True 2 - Second column of row 3. + * + * - Second item in bullet list (row 3, column 2). ============ + * ====== + */ result = DocumentHelper.createElement(TABLE); line = line.trim(); @@ -1519,7 +1511,8 @@ // = Pattern pBordersTiret = Pattern.compile("^\\s*(-+ +)+-+\\s*$"); // Separation // - - Pattern pBorders = Pattern.compile("^\\s*([=-]+ +)+[=-]+\\s*$"); // = ou + Pattern pBorders = Pattern.compile("^\\s*([=-]+ +)+[=-]+\\s*$"); // = + // ou // - String[] table = in.readUntilBlank(); // Recuperation de la // table @@ -1553,34 +1546,20 @@ // Traitement du tbl /* - ===== ===== ====== - Inputs Output - ------------ ------ - A B A or B - ===== ===== ====== - False False Second column of row 1. - True False Second column of row 2. - - True 2 - Second column of row 3. - - - Second item in bullet - list (row 3, column 2). - ============ ====== - devient l'equivalent : - ===== ===== ====== - Inputs Output - ------------ ------ - A B A or B - ===== ===== ====== - False False Second column of row 1. - ----- ----- ------ - True False Second column of row 2. - ----- ----- ------ - True 2 - Second column of row 3. - - Second item in bullet - list (row 3, column 2). - ============ ====== - */ + * ===== ===== ====== Inputs Output ------------ ------ A B A or + * B ===== ===== ====== False False Second column of row 1. True + * False Second column of row 2. + * + * True 2 - Second column of row 3. + * + * - Second item in bullet list (row 3, column 2). ============ + * ====== devient l'equivalent : ===== ===== ====== Inputs + * Output ------------ ------ A B A or B ===== ===== ====== + * False False Second column of row 1. ----- ----- ------ True + * False Second column of row 2. ----- ----- ------ True 2 - + * Second column of row 3. - Second item in bullet list (row 3, + * column 2). ============ ====== + */ String lineRef = line.replace('=', '-'); Matcher matcher2; List tableTmp = new LinkedList(); @@ -1847,24 +1826,21 @@ /** * read enumarted list * - * can be: - *
  • 1, 2, 3, ... - *
  • a, b, c, ... - *
  • A, B, C, ... - *
  • i, ii, iii, iv, ... - *
  • I, II, III, IV, ... + * can be:
  • 1, 2, 3, ...
  • a, b, c, ...
  • A, B, C, ...
  • i, ii, + * iii, iv, ...
  • I, II, III, IV, ... * * or # for auto-numbered * *
    -     * 1. next line
    -     * 1) next line
    -     * (1) first line
    +     * 
    +     * 1. next line 1) next line (1) first line
    +     * 
          * 
    * * @return <enumerated_list level="[int]" start="[number]" * prefix="[char]" suffix="[char]" - * enumtype="[(arabic|loweralpha|upperalpha|lowerroman|upperroman]">[text]</enumerated_list> + * enumtype="[(arabic|loweralpha|upperalpha|lowerroman|upperroman]"> + * ;[text]</enumerated_list> * @throws IOException */ public Element peekEnumeratedList() throws IOException { @@ -1929,16 +1905,17 @@ * simple: * *
    -     * Le titre
    -     * ========
    +     * 
    +     * Le titre ========
    +     * 
          * 
    * * double: * *
    -     * ============
    -     *   le titre
    -     * ============
    +     * 
    +     * ============ le titre ============
    +     * 
          * 
    * * @return <title level="[int]" type="[simple|double]" char="[underline @@ -2007,7 +1984,7 @@ int i = line.indexOf(':'); result.addAttribute("id", line.substring(matcher.end(), i) .replaceAll("\\W", "-").toLowerCase()); - result.addAttribute("level", ""+level(line)); + result.addAttribute("level", "" + level(line)); } } } @@ -2051,10 +2028,11 @@ // line = null if link is non well formed // .. _Unifying types and classes in Python: // miss uri - if(line==null) { + if (line == null) { line = ""; } - result.getLast().addAttribute("refuri",line.trim()); + result.getLast().addAttribute("refuri", + line.trim()); } else result.getLast().addAttribute("refuri", line.substring(i + 2, line.length())); @@ -2224,8 +2202,7 @@ /** * Read block text, block text have same indentation * - * @param minLeftMargin - * min left blank needed to accept to read block + * @param minLeftMargin min left blank needed to accept to read block * @return String * @throws IOException */ @@ -2306,8 +2283,7 @@ } /** - * @param String - * line + * @param String line * @return int * @throws IOException */