Index: jrst2/src/java/org/codelutin/jrst/ReStructuredText.java
diff -u jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.11 jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.12
--- jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.11 Tue May 22 14:01:15 2007
+++ jrst2/src/java/org/codelutin/jrst/ReStructuredText.java Wed May 23 17:16:20 2007
@@ -23,9 +23,9 @@
* Created: 27 oct. 06 11:10:30
*
* @author poussin
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*
- * Last update: $Date: 2007/05/22 14:01:15 $
+ * Last update: $Date: 2007/05/23 17:16:20 $
* by : $Author: sletellier $
*/
@@ -164,7 +164,7 @@
public static final String STRONG = "strong";
public static final String LITERAL = "literal";
public static final String REFERENCE = "reference";
- public static final String FOOTNOTE_REFERENCE = "footnote_reference";
+ public static final String FOOTNOTE_REFERENCE = "footnote-reference";
public static final String CITATION_REFERENCE = "citation_reference";
public static final String SUBSTITUTION_REFERENCE = "substitution_reference";
public static final String TITLE_REFERENCE = "title_reference";
@@ -182,8 +182,8 @@
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]+)");
- public static final Pattern REGEX_INLINE_REFERENCE = Pattern.compile("`(.+) ?[(<)<](http://[-/%#&\\._\\w]+)[(>)>]`_");
+ 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]+?|#)\\]");
@@ -197,7 +197,7 @@
public static final Pattern REGEX_PROBLEMATIC = Pattern.compile("(.*?)");
public static final Pattern REGEX_GENERATED = Pattern.compile("(.*?)");
public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^_<>]+\\`_)|('[^_<>]+'_)|([\\S]+[^\\s<>\\.]+_)");
- public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`]+\\`__)|([^\\S]+[^\\s<>]+__)");
+ public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`]+\\`__)|([\\w]+[^`\\s<>]+__)");
}
Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java
diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.27 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.28
--- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.27 Tue May 22 14:01:15 2007
+++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Wed May 23 17:16:20 2007
@@ -23,9 +23,9 @@
* Created: 27 oct. 06 00:15:34
*
* @author poussin
- * @version $Revision: 1.27 $
+ * @version $Revision: 1.28 $
*
- * Last update: $Date: 2007/05/22 14:01:15 $
+ * Last update: $Date: 2007/05/23 17:16:20 $
* by : $Author: sletellier $
*/
@@ -66,116 +66,95 @@
import org.dom4j.Node;
import org.dom4j.VisitorSupport;
-
/*
- *
-
-+--------------------------------------------------------------------+
-| document [may begin with a title, subtitle, decoration, docinfo] |
-| +--------------------------------------+
-| | sections [each begins with a title] |
-+-----------------------------+-------------------------+------------+
-| [body elements:] | (sections) |
-| | - literal | - lists | | - hyperlink +------------+
-| | blocks | - tables | | targets |
-| para- | - doctest | - block | foot- | - sub. defs |
-| graphs | blocks | quotes | notes | - comments |
-+---------+-----------+----------+-------+--------------+
-| [text]+ | [text] | (body elements) | [text] |
-| (inline +-----------+------------------+--------------+
-| markup) |
-+---------+
-
+ *
+ * +--------------------------------------------------------------------+ |
+ * document [may begin with a title, subtitle, decoration, docinfo] | |
+ * +--------------------------------------+ | | sections [each begins with a
+ * title] |
+ * +-----------------------------+-------------------------+------------+ |
+ * [body elements:] | (sections) | | | - literal | - lists | | - hyperlink
+ * +------------+ | | blocks | - tables | | targets | | para- | - doctest | -
+ * block | foot- | - sub. defs | | graphs | blocks | quotes | notes | - comments |
+ * +---------+-----------+----------+-------+--------------+ | [text]+ | [text] |
+ * (body elements) | [text] | | (inline
+ * +-----------+------------------+--------------+ | markup) | +---------+
+ *
*
*
* Inline support: http://docutils.sourceforge.net/docs/user/rst/quickref.html
*
- * STRUCTURAL ELEMENTS: document, section, topic, sidebar
- * STRUCTURAL SUBELEMENTS: title, subtitle, decoration, docinfo, transition
- * docinfo: address, author, authors, contact, copyright, date, field,
- * organization, revision, status, version
- * decoration: footer, header
- * BODY ELEMENTS: admonition, attention, block_quote, bullet_list, caution,
- * citation, comment, compound, container, danger, definition_list,
- * doctest_block, enumerated_list, error, field_list, figure, footnote,
- * hint, image, important, line_block, literal_block, note, option_list,
- * paragraph, pending, raw, rubric, substitution_definition,
- * system_message, table, target, tip, warning
- * SIMPLE BODY ELEMENTS: comment, doctest_block, image, literal_block,
- * paragraph, pending, raw, rubric, substitution_definition, target
- * COMPOUND BODY ELEMENTS: admonition, attention, block_quote, bullet_list,
- * caution, citation, compound, container, danger, definition_list,
- * enumerated_list, error, field_list, figure, footnote, hint, important,
- * line_block, note, option_list, system_message, table, tip, warning
- * BODY SUBELEMENTS: attribution, caption, classifier, colspec, field_name,
- * label, line, option_argument, option_string, term
- * definition, definition_list_item, description, entry, field,
- * field_body, legend, list_item, option, option_group, option_list_item,
- * row, tbody, tgroup, thead
- * INLINE ELEMENTS: abbreviation, acronym, citation_reference, emphasis,
- * footnote_reference, generated, image, inline, literal, problematic,
- * reference, strong, subscript, substitution_reference, superscript,
- * target, title_reference, raw
- *
-
- DOCUMENT :: ( (title, subtitle?)?, decoration?, (docinfo, transition?)?,
- STRUCTURE.MODEL; )
- decoration :: (header?, footer?)
- header, footer, definition, description, attention, caution, danger, error,
- hint, important, note, tip, warning :: (BODY.ELEMENTS;)+
- transition :: EMPTY
- docinfo :: (BIBLIOGRAPHIC.ELEMENTS;)+
- BIBLIOGRAPHIC.ELEMENTS :: author | authors | organization | contact | address
- | version | revision | status | date | copyright | field
- authors :: ( (author)+ )
- field :: (field_name, field_body)
- field_body, list_item :: (BODY.ELEMENTS;)*
- STRUCTURE.MODEL :: ( ( (BODY.ELEMENTS; | topic | sidebar)+, transition? )*,
- ( (section), (transition?, (section) )* )? )
- BODY.ELEMENTS :: paragraph | compound | container | literal_block | doctest_block
- | line_block | block_quote | table | figure | image | footnote | citation
- | rubric | bullet_list | enumerated_list | definition_list | field_list
- | option_list | attention | caution | danger | error | hint | important
- | note | tip | warning | admonition | reference | target
- | substitution_definition | comment | pending | system_message | raw
- topic :: (title?, (BODY.ELEMENTS;)+)
- sidebar :: (title, subtitle?, (BODY.ELEMENTS; | topic)+)
- section :: (title, STRUCTURE.MODEL;)
- line_block :: (line | line_block)+
- block_quote:: ((BODY.ELEMENTS;)+, attribution?)
- bullet_list, enumerated_list :: (list_item +)
- definition_list :: (definition_list_item +)
- definition_list_item :: (term, classifier?, definition)
- field_list :: (field +)
- option_list :: (option_list_item +)
- option_list_item :: (option_string, option_argument *, description)
- option_string, option_argument :: (#PCDATA)
- admonition :: (title, (BODY.ELEMENTS;)+)
-
- title, subtitle, author, organization, contact, address, version, revision,
- status, date, copyright, field_name, paragraph, compound, container,
- literal_block, doctest_block, attribution, line, term, classifier :: TEXT.MODEL;
-
- TEXT.MODEL :: (#PCDATA | INLINE.ELEMENTS;)*
- INLINE.ELEMENTS :: emphasis | strong | literal | reference | footnote_reference
- | citation_reference | substitution_reference | title_reference | abbreviation
- | acronym | subscript | superscript | inline | problematic | generated
- | target | image | raw
- emphasis :: '*' #PCDATA '*'
- strong :: '**' #PCDATA '**'
- literal :: '``' #PCDATA '``'
- footnote_reference :: '[' ([0-9]+|#) ']'
- citation_reference :: '[' [a-zA-Z]+ ']'
-
-
-*/
+ * STRUCTURAL ELEMENTS: document, section, topic, sidebar STRUCTURAL
+ * SUBELEMENTS: title, subtitle, decoration, docinfo, transition docinfo:
+ * address, author, authors, contact, copyright, date, field, organization,
+ * revision, status, version decoration: footer, header BODY ELEMENTS:
+ * admonition, attention, block_quote, bullet_list, caution, citation, comment,
+ * compound, container, danger, definition_list, doctest_block, enumerated_list,
+ * error, field_list, figure, footnote, hint, image, important, line_block,
+ * literal_block, note, option_list, paragraph, pending, raw, rubric,
+ * substitution_definition, system_message, table, target, tip, warning
+ * SIMPLE BODY ELEMENTS: comment, doctest_block, image, literal_block,
+ * paragraph, pending, raw, rubric, substitution_definition, target
+ * COMPOUND BODY ELEMENTS: admonition, attention, block_quote, bullet_list,
+ * caution, citation, compound, container, danger, definition_list,
+ * enumerated_list, error, field_list, figure, footnote, hint, important,
+ * line_block, note, option_list, system_message, table, tip, warning BODY
+ * SUBELEMENTS: attribution, caption, classifier, colspec, field_name, label,
+ * line, option_argument, option_string, term definition, definition_list_item,
+ * description, entry, field, field_body, legend, list_item, option,
+ * option_group, option_list_item, row, tbody, tgroup, thead INLINE
+ * ELEMENTS: abbreviation, acronym, citation_reference, emphasis,
+ * footnote_reference, generated, image, inline, literal, problematic,
+ * reference, strong, subscript, substitution_reference, superscript, target,
+ * title_reference, raw
+ *
+ * DOCUMENT :: ( (title, subtitle?)?, decoration?, (docinfo,
+ * transition?)?, STRUCTURE.MODEL; ) decoration :: (header?, footer?) header,
+ * footer, definition, description, attention, caution, danger, error, hint,
+ * important, note, tip, warning :: (BODY.ELEMENTS;)+ transition :: EMPTY
+ * docinfo :: (BIBLIOGRAPHIC.ELEMENTS;)+ BIBLIOGRAPHIC.ELEMENTS :: author |
+ * authors | organization | contact | address | version | revision | status |
+ * date | copyright | field authors :: ( (author)+ ) field :: (field_name,
+ * field_body) field_body, list_item :: (BODY.ELEMENTS;)* STRUCTURE.MODEL :: ( (
+ * (BODY.ELEMENTS; | topic | sidebar)+, transition? )*, ( (section),
+ * (transition?, (section) )* )? ) BODY.ELEMENTS :: paragraph | compound |
+ * container | literal_block | doctest_block | line_block | block_quote | table |
+ * figure | image | footnote | citation | rubric | bullet_list | enumerated_list |
+ * definition_list | field_list | option_list | attention | caution | danger |
+ * error | hint | important | note | tip | warning | admonition | reference |
+ * target | substitution_definition | comment | pending | system_message | raw
+ * topic :: (title?, (BODY.ELEMENTS;)+) sidebar :: (title, subtitle?,
+ * (BODY.ELEMENTS; | topic)+) section :: (title, STRUCTURE.MODEL;) line_block ::
+ * (line | line_block)+ block_quote:: ((BODY.ELEMENTS;)+, attribution?)
+ * bullet_list, enumerated_list :: (list_item +) definition_list ::
+ * (definition_list_item +) definition_list_item :: (term, classifier?,
+ * definition) field_list :: (field +) option_list :: (option_list_item +)
+ * option_list_item :: (option_string, option_argument *, description)
+ * option_string, option_argument :: (#PCDATA) admonition :: (title,
+ * (BODY.ELEMENTS;)+)
+ *
+ * title, subtitle, author, organization, contact, address, version, revision,
+ * status, date, copyright, field_name, paragraph, compound, container,
+ * literal_block, doctest_block, attribution, line, term, classifier ::
+ * TEXT.MODEL;
+ *
+ * TEXT.MODEL :: (#PCDATA | INLINE.ELEMENTS;)* INLINE.ELEMENTS :: emphasis |
+ * strong | literal | reference | footnote_reference | citation_reference |
+ * substitution_reference | title_reference | abbreviation | acronym | subscript |
+ * superscript | inline | problematic | generated | target | image | raw
+ * emphasis :: '*' #PCDATA '*' strong :: '**' #PCDATA '**' literal :: '``'
+ * #PCDATA '``' footnote_reference :: '[' ([0-9]+|#) ']' citation_reference ::
+ * '[' [a-zA-Z]+ ']'
+ *
+ *
+ */
/**
- * * Le principe est d'utiliser les methodes peek* {@link JRSTLexer} pour prendre
- * l'element que l'on attend, si la methode retourne null ou un autre element
- * et bien c que ce n'est pas le bon choix, cela veut dire que l'element courant
- * est fini d'etre lu (plus de paragraphe dans la section par exemple) ou
- * qu'il y a une erreur dans le fichier en entre.
+ * * Le principe est d'utiliser les methodes peek* {@link JRSTLexer} pour
+ * prendre l'element que l'on attend, si la methode retourne null ou un autre
+ * element et bien c que ce n'est pas le bon choix, cela veut dire que l'element
+ * courant est fini d'etre lu (plus de paragraphe dans la section par exemple)
+ * ou qu'il y a une erreur dans le fichier en entre.
*
* On construit un arbre XML representant le RST au fur et a mesure, on peut
* ensuite appliquer une fueille de style ou autre chose avec
@@ -183,134 +162,147 @@
*
*
* Tous les elements ont un attribut level qui permet de savoir on il est dans
- * la hierarchie. Le Document a le level -1001, et les sections/titres
- * on pour level les valeurs 1000, -999, -998, ...
+ * la hierarchie. Le Document a le level -1001, et les sections/titres on pour
+ * level les valeurs 1000, -999, -998, ...
*
- * de cette facon les methods isUpperLevel et isSameLevel fonctionne pour
- * tous les elements de la meme facon
+ * de cette facon les methods isUpperLevel et isSameLevel fonctionne pour tous
+ * les elements de la meme facon
*
*
- * abbreviation
- * acronym
- * address (done)
- * admonition (done)
- * attention (done)
- * attribution
- * author (done)
- * authors (done)
- * block_quote (done)
- * bullet_list (done)
- * caption
- * caution (done)
- * citation
- * citation_reference
- * classifier (done)
- * colspec (done)
- * comment
- * compound
- * contact (done)
- * container
- * copyright (done)
- * danger (done)
- * date (done)
- * decoration
- * definition (done)
- * definition_list (done)
- * definition_list_item (done)
- * description (done)
- * docinfo (done)
- * doctest_block (done)
- * document (done)
- * emphasis (done)
- * entry (done)
- * enumerated_list (done)
- * error (done)
- * field (done)
- * field_body (done)
- * field_list (done)
- * field_name (done)
- * figure
- * footer
- * footnote (done)
- * footnote_reference (done)
- * generated
- * header (parcialy done)
- * hint (done)
- * image (done)
- * important (done)
- * inline
- * label
- * legend
- * line (done)
- * line_block (done)
- * list_item (done)
- * literal (done)
- * literal_block (done)
- * note (done)
- * option (done)
- * option_argument (done)
- * option_group (done)
- * option_list (done)
- * option_list_item (done)
- * option_string (done)
- * organization (done)
- * paragraph (done)
- * pending
- * problematic
- * raw
- * reference (partialy done)
- * revision (done)
- * row (done)
- * rubric
- * section (done)
- * sidebar (done)
- * status (done)
- * strong (done)
- * subscript
- * substitution_definition
- * substitution_reference
- * subtitle (done)
- * superscript
- * system_message
- * table (done)
- * target
- * tbody (done)
- * term (done)
- * tgroup (done)
- * thead (done)
- * tip (done)
- * title (done)
- * title_reference
- * topic (done)
- * transition (done)
- * version (done)
- * warning (done)
+ * abbreviation
+ * acronym
+ * address (done)
+ * admonition (done)
+ * attention (done)
+ * attribution
+ * author (done)
+ * authors (done)
+ * block_quote (done)
+ * bullet_list (done)
+ * caption
+ * caution (done)
+ * citation
+ * citation_reference
+ * classifier (done)
+ * colspec (done)
+ * comment
+ * compound
+ * contact (done)
+ * container
+ * copyright (done)
+ * danger (done)
+ * date (done)
+ * decoration
+ * definition (done)
+ * definition_list (done)
+ * definition_list_item (done)
+ * description (done)
+ * docinfo (done)
+ * doctest_block (done)
+ * document (done)
+ * emphasis (done)
+ * entry (done)
+ * enumerated_list (done)
+ * error (done)
+ * field (done)
+ * field_body (done)
+ * field_list (done)
+ * field_name (done)
+ * figure
+ * footer
+ * footnote (done)
+ * footnote_reference (done)
+ * generated
+ * header (parcialy done)
+ * hint (done)
+ * image (done)
+ * important (done)
+ * inline
+ * label
+ * legend
+ * line (done)
+ * line_block (done)
+ * list_item (done)
+ * literal (done)
+ * literal_block (done)
+ * note (done)
+ * option (done)
+ * option_argument (done)
+ * option_group (done)
+ * option_list (done)
+ * option_list_item (done)
+ * option_string (done)
+ * organization (done)
+ * paragraph (done)
+ * pending
+ * problematic
+ * raw
+ * reference (partialy done)
+ * revision (done)
+ * row (done)
+ * rubric
+ * section (done)
+ * sidebar (done)
+ * status (done)
+ * strong (done)
+ * subscript
+ * substitution_definition
+ * substitution_reference
+ * subtitle (done)
+ * superscript
+ * system_message
+ * table (done)
+ * target
+ * tbody (done)
+ * term (done)
+ * tgroup (done)
+ * thead (done)
+ * tip (done)
+ * title (done)
+ * title_reference
+ * topic (done)
+ * transition (done)
+ * version (done)
+ * warning (done)
*
*
* @author poussin, letellier
*/
public class JRSTReader {
-
-
+
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(JRSTReader.class);
boolean ERROR_MISSING_ITEM = false;
+
static int MAX_SECTION_DEPTH = -1000;
-
+
static protected Map defaultDirectives = null;
+
protected Map directives = new HashMap();
+
private static boolean sectnum = false;
+
+ private Element footer;
+
private static int idMax = 0;
+
private static int symbolMax = 0;
+
private static int symbolMaxRef = 0;
+
private static LinkedList lblFootnotes = new LinkedList();
+
private static LinkedList lblFootnotesRef = new LinkedList();
+
private static LinkedList eFootnotes = new LinkedList();
+
private static LinkedList eTarget = new LinkedList();
- private static LinkedList eTargetAnonymous = new LinkedList();
+
+ static LinkedList eTargetAnonymous = new LinkedList();
+
private static LinkedList eTitle = new LinkedList();
-
+
static {
defaultDirectives = new HashMap();
defaultDirectives.put(IMAGE, new ImageDirective());
@@ -320,37 +312,38 @@
defaultDirectives.put("sectnum", new SectnumDirective());
// TODO put here all other directive
}
-
+
/**
*
*/
public JRSTReader() {
}
-
/**
* @return the defaultDirectives
*/
public static JRSTDirective getDefaultDirective(String name) {
return defaultDirectives.get(name);
}
-
+
/**
- * @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);
}
-
+
/**
* @return the defaultDirectives
*/
public JRSTDirective getDirective(String name) {
return directives.get(name);
}
-
+
/**
- * @param defaultDirectives the defaultDirectives to set
+ * @param defaultDirectives
+ * the defaultDirectives to set
*/
public void addDirectives(String name, JRSTDirective directive) {
directives.put(name, directive);
@@ -359,14 +352,15 @@
/**
* On commence par decouper tout le document en Element, puis on construit
* l'article a partir de ces elements.
+ *
* @param reader
* @return
* @throws IOException
- * @throws DocumentException
+ * @throws DocumentException
*/
public Document read(Reader reader) throws Exception {
JRSTLexer lexer = new JRSTLexer(reader);
- try {
+ try {
Element root = composeDocument(lexer);
Document result = DocumentHelper.createDocument();
result.setRootElement(root);
@@ -375,11 +369,11 @@
public void visit(Element e) {
e.addAttribute("level", null);
String type = e.attributeValue("type");
-
- if (type!=null){
- if (type.equals("contents")){
+
+ if (type != null) {
+ if (type.equals("contents")) {
composeContents(e);
- e.addAttribute("type",null);
+ e.addAttribute("type", null);
}
}
if ("true".equalsIgnoreCase(e.attributeValue("inline"))) {
@@ -396,61 +390,68 @@
});
return result;
} catch (Exception eee) {
- log.error(_("JRST parsing error line {0} char {1}:\n{2}", lexer.getLineNumber(), lexer.getCharNumber(), lexer.readNotBlanckLine()));
+ log.error(_("JRST parsing error line {0} char {1}:\n{2}", lexer
+ .getLineNumber(), lexer.getCharNumber(), lexer
+ .readNotBlanckLine()));
throw eee;
}
}
+
/**
- * @param Element e
+ * @param Element
+ * e
*/
private void composeContents(Element e) {
-
- Element result = DocumentHelper.createElement(TOPIC);
+
+ Element result = DocumentHelper.createElement(TOPIC);
String option = e.getText();
- int depth=-1;
+ int depth = -1;
Pattern pattern = Pattern.compile("\\s*\\:depth\\:\\s*\\p{Digit}+");
Matcher matcher = pattern.matcher(option);
if (matcher.matches()) {
pattern = Pattern.compile("\\p{Digit}+");
matcher = pattern.matcher(matcher.group());
if (matcher.find())
- depth=Integer.parseInt(matcher.group());
+ depth = Integer.parseInt(matcher.group());
}
- int levelInit = Integer.parseInt(eTitle.getFirst().attributeValue("level"));
+ int levelInit = Integer.parseInt(eTitle.getFirst().attributeValue(
+ "level"));
LinkedList title = new LinkedList();
- for (int i=0;ilevel)
+ else {
+ if (depth > level)
title.add(el);
}
}
e.addAttribute("class", "contents");
- String titleValue= e.attributeValue("value");
+ String titleValue = e.attributeValue("value");
e.addAttribute("value", null);
String value = titleValue.trim().toLowerCase();
-
- if (value.matches("\\s*")){
- value="contents";
- titleValue="Contents";
+
+ if (value.matches("\\s*")) {
+ value = "contents";
+ titleValue = "Contents";
}
e.addAttribute("id", value);
- e.addAttribute("name",value);
+ e.addAttribute("name", value);
result.addElement("title").setText(titleValue);
result.add(composeLineContent(title, ""));
e.setText("");
e.appendContent(result);
}
+
/**
- * @param LinkedList title, String num
+ * @param LinkedList
+ * title, String num
* @return Element
*/
private Element composeLineContent(LinkedList title, String num) {
@@ -458,61 +459,66 @@
if (sectnum)
result.addAttribute("class", "auto-toc");
Element item = null;
- int cnt=0;
- while (!title.isEmpty()){
-
- boolean done=false;
+ int cnt = 0;
+ while (!title.isEmpty()) {
+
+ boolean done = false;
Element e = title.getFirst();
int level = Integer.parseInt(e.attributeValue("level"));
LinkedList child = new LinkedList();
-
- if (level==0 && !done){
+
+ if (level == 0 && !done) {
cnt++;
title.removeFirst();
item = result.addElement(LIST_ITEM);
Element para = item.addElement(PARAGRAPH);
Element reference = para.addElement(REFERENCE);
- String text=e.getText();
- String id= e.attributeValue("refid");
- reference.addAttribute("id",id);
- reference.addAttribute("refid", text.replaceAll("\\W+", " ").trim().toLowerCase().replaceAll("\\W+", "-"));
- reference.addAttribute("inline","true");
- if (sectnum){
- Element generated = reference.addElement("generated").addAttribute("class", "sectnum");
- generated.setText(num+cnt+" ");
- for (int i=0;i0 && !done);
- String numTmp="";
+ }
+ } while (!title.isEmpty() && level > 0 && !done);
+ String numTmp = "";
if (sectnum)
- numTmp=num+cnt+".";
- if (item!=null)
- item.add(composeLineContent(child,numTmp)); // Appel recursif
+ numTmp = num + cnt + ".";
+ if (item != null)
+ item.add(composeLineContent(child, numTmp)); // Appel
+ // recursif
else
- result.add(composeLineContent(child,numTmp)); // Appel recursif
+ result.add(composeLineContent(child, numTmp)); // Appel
+ // recursif
}
}
return result;
}
+
/**
* @param lexer
* @return Element
@@ -523,111 +529,160 @@
result.addAttribute("level", String.valueOf(MAX_SECTION_DEPTH - 1));
Element item = null;
-
+
// skip blank line
skipBlankLine(lexer);
-
+
// le header
item = lexer.peekHeader();
- if (itemEquals(HEADER, item)){
- Element decoration = result.addElement(DECORATION);
- Element header = decoration.addElement(HEADER);
- header.addAttribute("inline", "true").setText(item.getText());
+ if (itemEquals(HEADER, item)) {
+ Element decoration = result.addElement(DECORATION);
+ Element header = decoration.addElement(HEADER);
+ header.addAttribute("inline", "true").setText(item.getText());
+ }
+
+ item = lexer.peekFooter();
+ if (itemEquals(FOOTER, item)) {
+ footer = DocumentHelper.createElement(DECORATION);
+ Element header = footer.addElement(FOOTER);
+ header.addAttribute("inline", "true").setText(item.getText());
+ }
+
+ LinkedList listItem = lexer.peekTargetAnonymous();
+ if (listItem != null) {
+ for (Element e : listItem) {
+ Element anonym = result.addElement(TARGET);
+ anonym.addAttribute("anonymous", "1");
+ idMax++;
+ anonym.addAttribute("id", "id" + idMax);
+ anonym.addAttribute("refuri", e.attributeValue("refuri")
+ .replaceAll("`|_", "").trim());
+
+ eTargetAnonymous.add(anonym);
+
+ }
}
+
item = lexer.peekRemove();
if (itemEquals("remove", item))
- lexer.remove();
-
+ lexer.remove();
+
// le titre du doc
item = lexer.peekTitle();
if (itemEquals(TITLE, item)) {
lexer.remove();
Element title = result.addElement(TITLE);
String txt = item.getText();
- result.addAttribute("id", txt.replaceAll("[(\\W+)_]"," ").toLowerCase().trim().replaceAll("\\s+", "-"));
- result.addAttribute("name", txt.toLowerCase().replaceAll("[(\\W+)_&&[^\\:]]+", " ").trim());
+ result.addAttribute("id", txt.replaceAll("[(\\W+)_]", " ")
+ .toLowerCase().trim().replaceAll("\\s+", "-"));
+ result.addAttribute("name", txt.toLowerCase().replaceAll(
+ "[(\\W+)_&&[^\\:]]+", " ").trim());
copyLevel(item, title);
title.addAttribute("inline", "true").setText(txt.trim());
}
-
+
// skip blank line
skipBlankLine(lexer);
-
+
// le sous titre du doc
item = lexer.peekTitle();
if (itemEquals(TITLE, item)) {
lexer.remove();
Element subtitle = result.addElement(SUBTITLE);
String txt = item.getText();
- subtitle.addAttribute("id", txt.replaceAll("[(\\W+)_]"," ").toLowerCase().trim().replaceAll("\\s+", "-"));
- subtitle.addAttribute("name",txt.toLowerCase().replaceAll("[(\\W+)_]", " ").trim());
- copyLevel(item, subtitle);DocumentHelper.createElement("footnotes");
+ subtitle.addAttribute("id", txt.replaceAll("[(\\W+)_]", " ")
+ .toLowerCase().trim().replaceAll("\\s+", "-"));
+ subtitle.addAttribute("name", txt.toLowerCase().replaceAll(
+ "[(\\W+)_]", " ").trim());
+ copyLevel(item, subtitle);
+ DocumentHelper.createElement("footnotes");
subtitle.addAttribute("inline", "true").setText(txt.trim());
}
-
+
// skip blank line
- skipBlankLine(lexer);
-
+ skipBlankLine(lexer);
+
// les infos du doc
item = lexer.peekDocInfo();
-
+
Element documentinfo = null;
while (itemEquals(DOCINFO, item) || itemEquals(FIELD_LIST, item)) {
-
- if (documentinfo == null) {
+
+ if (documentinfo == null) {
documentinfo = result.addElement(DOCINFO);
}
- skipBlankLine(lexer);
+ skipBlankLine(lexer);
if (itemEquals(FIELD_LIST, item)) {
Element field = composeFieldItemList(lexer);
documentinfo.add(field);
} else {
if ("author".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(AUTHOR).addAttribute("inline", "true").setText(item.getText());
+ documentinfo.addElement(AUTHOR).addAttribute("inline",
+ "true").setText(item.getText());
} else if ("date".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(DATE).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("organization".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(ORGANIZATION).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("contact".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(CONTACT).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("address".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(ADDRESS).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("version".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(VERSION).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("revision".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(REVISION).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("status".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(STATUS).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("copyright".equalsIgnoreCase(item.attributeValue("type"))) {
- documentinfo.addElement(COPYRIGHT).addAttribute("inline", "true").setText(item.getText().trim());
- } else if ("authors".equalsIgnoreCase(item.attributeValue("type"))){
- Element authors = documentinfo.addElement(AUTHORS);
- int t=0;
- String line = item.getText();
- for (int i=0;i footnotes = (List)item.selectNodes(FOOTNOTE);
+ Element[] result = null;
+ if (itemEquals("footnotes", item)) {
+ List footnotes = (List) item
+ .selectNodes(FOOTNOTE);
result = new Element[footnotes.size()];
- int cnt=0;
- for (Element footnote : footnotes){
- result[cnt] = DocumentHelper.createElement(FOOTNOTE);
- Element efootnote = DocumentHelper.createElement(FOOTNOTE);
- int labelMax=0;
-
- for (int i = 0; i option = (List)item.selectNodes("option");
- for (Element e : option){
- Element eOption = optionGroup.addElement(OPTION);
- eOption.addElement(OPTION_STRING).setText(e.attributeValue(OPTION_STRING));
- if (e.attributeValue("delimiterExiste").equals("true")){
- eOption.addElement(OPTION_ARGUMENT).addAttribute("delimiter", e.attributeValue("delimiter")).setText(e.attributeValue(OPTION_ARGUMENT));
- }
+ List option = (List) item.selectNodes("option");
+ for (Element e : option) {
+ Element eOption = optionGroup.addElement(OPTION);
+ eOption.addElement(OPTION_STRING).setText(
+ e.attributeValue(OPTION_STRING));
+ if (e.attributeValue("delimiterExiste").equals("true")) {
+ eOption.addElement(OPTION_ARGUMENT).addAttribute(
+ "delimiter", e.attributeValue("delimiter"))
+ .setText(e.attributeValue(OPTION_ARGUMENT));
+ }
}
- optionListItem.addElement(DESCRIPTION).addAttribute("inline", "true").setText(item.getText());
+ optionListItem.addElement(DESCRIPTION).addAttribute("inline",
+ "true").setText(item.getText());
item = lexer.peekOption();
}
return result;
- }
- /**
- * @param Element item
- * @return Element
- * @throws Exception
- */
-
- private Element composeTopic(Element item) throws Exception {
- Element result = null;
- result=DocumentHelper.createElement(TOPIC);
- result.addElement(TITLE).addAttribute("inline", "true").setText(item.attributeValue(TITLE));
- result.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText());
- return result;
- }
- /**
- * @param Element item
- * @return Element
- * @throws Exception
- */
-
- private Element composeSidebar(Element item) throws Exception {
- Element result = null;
- result=DocumentHelper.createElement(SIDEBAR);
- result.addElement(TITLE).addAttribute("inline", "true").setText(item.attributeValue(TITLE));
- if (item.attributeValue("subExiste").equals("true"))
- result.addElement(SUBTITLE).addAttribute("inline", "true").setText(item.attributeValue(SUBTITLE));
- JRSTReader reader = new JRSTReader();
+ }
+
+ /**
+ * @param Element
+ * item
+ * @return Element
+ * @throws Exception
+ */
+
+ private Element composeTopic(Element item) throws Exception {
+ Element result = null;
+ result = DocumentHelper.createElement(TOPIC);
+ result.addElement(TITLE).addAttribute("inline", "true").setText(
+ item.attributeValue(TITLE));
+ result.addElement(PARAGRAPH).addAttribute("inline", "true").setText(
+ item.getText());
+ return result;
+ }
+
+ /**
+ * @param Element
+ * item
+ * @return Element
+ * @throws Exception
+ */
+
+ private Element composeSidebar(Element item) throws Exception {
+ Element result = null;
+ result = DocumentHelper.createElement(SIDEBAR);
+ result.addElement(TITLE).addAttribute("inline", "true").setText(
+ item.attributeValue(TITLE));
+ if (item.attributeValue("subExiste").equals("true"))
+ result.addElement(SUBTITLE).addAttribute("inline", "true").setText(
+ item.attributeValue(SUBTITLE));
+ JRSTReader reader = new JRSTReader();
String text = item.getText();
- Document doc = reader.read(new StringReader(text));
- result.appendContent(doc.getRootElement());
-
- return result;
- }
- /**
+ Document doc = reader.read(new StringReader(text));
+ result.appendContent(doc.getRootElement());
+
+ return result;
+ }
+
+ /**
* @param lexer
* @param item
* @return Element
- * @throws Exception
+ * @throws Exception
*/
- @SuppressWarnings("unchecked")
- private Element composeLineBlock(JRSTLexer lexer, Element item) throws Exception {
- Element result = null;
- result=DocumentHelper.createElement(LINE_BLOCK);
- List lines = (List)item.selectNodes(LINE);
- int[] levels=new int[lines.size()];
- int cnt=0;
- for (Element l : lines){
- levels[cnt]=Integer.parseInt(l.attributeValue("level"));
- cnt++;
- }
- cnt=0;
- boolean[] lineDone = new boolean [lines.size()];
- for (int i=0;i0){
- Element eLine = newItem.addElement("line");
- eLine.addAttribute("level", ""+(levels[i]-1));
- eLine.setText(lines.get(i).getText());
- lineDone[i]=true;
- }
- else
- done=true;
-
- }
- Element eLineBlock= result.addElement(LINE_BLOCK);
- // Appel recursif
- eLineBlock.appendContent(composeLineBlock(lexer,newItem));
- }
- }
- cnt++;
-
- }
- return result;
- }
- /**
- * @param Element item
- * @return Element
- */
- private Element composeDoctestBlock(Element item) {
- return item;
- }
- /**
- * @param Element item
- * @return Element
- * @throws Exception
- */
-
- private Element composeBlockQuote(Element item) throws Exception {
- Element result = null;
- result=DocumentHelper.createElement(BLOCK_QUOTE);
- JRSTReader reader = new JRSTReader();
+ @SuppressWarnings("unchecked")
+ private Element composeLineBlock(JRSTLexer lexer, Element item)
+ throws Exception {
+ Element result = null;
+ result = DocumentHelper.createElement(LINE_BLOCK);
+ List lines = (List) item.selectNodes(LINE);
+ int[] levels = new int[lines.size()];
+ int cnt = 0;
+ for (Element l : lines) {
+ levels[cnt] = Integer.parseInt(l.attributeValue("level"));
+ cnt++;
+ }
+ cnt = 0;
+ boolean[] lineDone = new boolean[lines.size()];
+ for (int i = 0; i < lineDone.length; i++)
+ lineDone[i] = false;
+ for (Element l : lines) {
+ if (levels[cnt] == 0)
+ result.addElement(LINE).addAttribute("inline", "true").setText(
+ l.getText());
+ else {
+ if (!lineDone[cnt]) {
+ Element newItem = DocumentHelper.createElement(LINE_BLOCK);
+ Boolean done = false;
+ for (int i = cnt; i < lines.size() && !done; i++) {
+ if (levels[i] > 0) {
+ Element eLine = newItem.addElement("line");
+ eLine.addAttribute("level", "" + (levels[i] - 1));
+ eLine.setText(lines.get(i).getText());
+ lineDone[i] = true;
+ } else
+ done = true;
+
+ }
+ Element eLineBlock = result.addElement(LINE_BLOCK);
+ // Appel recursif
+ eLineBlock.appendContent(composeLineBlock(lexer, newItem));
+ }
+ }
+ cnt++;
+
+ }
+ return result;
+ }
+
+ /**
+ * @param Element
+ * item
+ * @return Element
+ */
+ private Element composeDoctestBlock(Element item) {
+ return item;
+ }
+
+ /**
+ * @param Element
+ * item
+ * @return Element
+ * @throws Exception
+ */
+
+ private Element composeBlockQuote(Element item) throws Exception {
+ Element result = null;
+ result = DocumentHelper.createElement(BLOCK_QUOTE);
+ JRSTReader reader = new JRSTReader();
String text = item.getText();
- Document doc = reader.read(new StringReader(text));
- result.appendContent(doc.getRootElement());
+ Document doc = reader.read(new StringReader(text));
+ result.appendContent(doc.getRootElement());
String sAttribution = item.attributeValue(ATTRIBUTION);
- if (sAttribution != null){
- Element attribution = result.addElement(ATTRIBUTION);
- attribution.setText(sAttribution);
- attribution.addAttribute("inline","true");
- }
- return result;
- }
- /**
- * @param Element item
- * @return Element
- * @throws Exception
- */
- private Element composeAdmonition(Element item) throws Exception {
- Element result = null;
- if (item.attributeValue("type").equalsIgnoreCase(ADMONITION)){
- result=DocumentHelper.createElement(ADMONITION);
- String title = item.attributeValue(TITLE);
- String admonitionClass="admonition_"+title;
- admonitionClass=admonitionClass.toLowerCase().replaceAll("\\p{Punct}","");
- admonitionClass=admonitionClass.replace(' ', '-');
- admonitionClass=admonitionClass.replace('\n', '-');
- result.addAttribute("class", admonitionClass);
- result.addElement(TITLE).addAttribute("inline", "true").setText(title.trim());
- }
- else
- result=DocumentHelper.createElement(item.attributeValue("type").toLowerCase());
+ if (sAttribution != null) {
+ Element attribution = result.addElement(ATTRIBUTION);
+ attribution.setText(sAttribution);
+ attribution.addAttribute("inline", "true");
+ }
+ return result;
+ }
+
+ /**
+ * @param Element
+ * item
+ * @return Element
+ * @throws Exception
+ */
+ private Element composeAdmonition(Element item) throws Exception {
+ Element result = null;
+ if (item.attributeValue("type").equalsIgnoreCase(ADMONITION)) {
+ result = DocumentHelper.createElement(ADMONITION);
+ String title = item.attributeValue(TITLE);
+ String admonitionClass = "admonition_" + title;
+ admonitionClass = admonitionClass.toLowerCase().replaceAll(
+ "\\p{Punct}", "");
+ admonitionClass = admonitionClass.replace(' ', '-');
+ admonitionClass = admonitionClass.replace('\n', '-');
+ result.addAttribute("class", admonitionClass);
+ result.addElement(TITLE).addAttribute("inline", "true").setText(
+ title.trim());
+ } else
+ result = DocumentHelper.createElement(item.attributeValue("type")
+ .toLowerCase());
JRSTReader reader = new JRSTReader();
String text = item.getText();
Document doc = reader.read(new StringReader(text));
- result.appendContent(doc.getRootElement());
- return result;
- }
-
+ result.appendContent(doc.getRootElement());
+ return result;
+ }
- /**
+ /**
* @param item
* @return Node
*/
@@ -1127,7 +1195,7 @@
Node result = item;
String type = item.attributeValue(JRSTLexer.DIRECTIVE_TYPE);
if (type.equals("sectnum"))
- sectnum=true;
+ sectnum = true;
JRSTDirective directive = getDirective(type);
if (directive == null) {
directive = getDefaultDirective(type);
@@ -1140,104 +1208,128 @@
return result;
}
-
/**
- * @param Element item
+ * @param Element
+ * item
* @return Element
*/
private Element composeSubstitutionDefinition(Element item) {
Element result = item;
- Element child = (Element)item.selectSingleNode("*");
+ Element child = (Element) item.selectSingleNode("*");
Node newChild = composeDirective(child);
- result.remove(child); // remove old after composeDirective, because directive can be used this parent
+ result.remove(child); // remove old after composeDirective, because
+ // directive can be used this parent
result.add(newChild);
return result;
}
-
/**
- * @param Element item
- * @return Element
+ * @param Element
+ * item
+ * @return Element
*/
@SuppressWarnings("unchecked")
private Element composeTable(Element item) throws Exception {
-
+
Element result = DocumentHelper.createElement(TABLE);
-
- int tableWidth = Integer.parseInt(item.attributeValue(JRSTLexer.TABLE_WIDTH));
-
+
+ int tableWidth = Integer.parseInt(item
+ .attributeValue(JRSTLexer.TABLE_WIDTH));
+
TreeSet beginCellList = new TreeSet();
-
- for (Element cell : (List)item.selectNodes(JRSTLexer.ROW+"/"+JRSTLexer.CELL)) {
- Integer begin = Integer.valueOf(cell.attributeValue(JRSTLexer.CELL_INDEX_START));
+
+ for (Element cell : (List) item.selectNodes(JRSTLexer.ROW
+ + "/" + JRSTLexer.CELL)) {
+ Integer begin = Integer.valueOf(cell
+ .attributeValue(JRSTLexer.CELL_INDEX_START));
beginCellList.add(begin);
}
-
- int [] beginCell = new int[beginCellList.size() + 1]; // + 1 to put table width to simulate new cell
- int [] lengthCell = new int[beginCellList.size()];
+
+ int[] beginCell = new int[beginCellList.size() + 1]; // + 1 to put
+ // table width
+ // to simulate
+ // new cell
+ int[] lengthCell = new int[beginCellList.size()];
int cellNumber = 0;
for (int b : beginCellList) {
beginCell[cellNumber] = b;
if (cellNumber > 0) {
- lengthCell[cellNumber - 1] = beginCell[cellNumber] - beginCell[cellNumber - 1];
+ lengthCell[cellNumber - 1] = beginCell[cellNumber]
+ - beginCell[cellNumber - 1];
}
cellNumber++;
}
beginCell[cellNumber] = tableWidth;
- lengthCell[cellNumber - 1] = beginCell[cellNumber] - beginCell[cellNumber - 1];
-
-
- Element tgroup = result.addElement(TGROUP).addAttribute("cols", String.valueOf(cellNumber));
+ lengthCell[cellNumber - 1] = beginCell[cellNumber]
+ - beginCell[cellNumber - 1];
+
+ Element tgroup = result.addElement(TGROUP).addAttribute("cols",
+ String.valueOf(cellNumber));
for (int width : lengthCell) {
- tgroup.addElement(COLSPEC).addAttribute("colwidth", String.valueOf(width));
+ tgroup.addElement(COLSPEC).addAttribute("colwidth",
+ String.valueOf(width));
}
-
+
Element rowList = null;
if ("true".equals(item.attributeValue(JRSTLexer.TABLE_HEADER))) {
rowList = tgroup.addElement(THEAD);
} else {
rowList = tgroup.addElement(TBODY);
}
- List rows = (List)item.selectNodes(JRSTLexer.ROW);
- for (int r=0; r rows = (List) item.selectNodes(JRSTLexer.ROW);
+ for (int r = 0; r < rows.size(); r++) {
Element row = rowList.addElement(ROW);
- List cells = (List)rows.get(r).selectNodes(JRSTLexer.CELL);
- for (int c=0; c cells = (List) rows.get(r).selectNodes(
+ JRSTLexer.CELL);
+ for (int c = 0; c < cells.size(); c++) {
Element cell = cells.get(c);
- // si la cellule a ete utilisé pour un regroupement vertical on la passe
+ // si la cellule a ete utilisé pour un regroupement vertical on
+ // la passe
if (!"true".equals(cell.attributeValue("used"))) {
Element entry = row.addElement(ENTRY);
String text = "";
-
+
// on regroupe les cellules verticalement
int morerows = -1;
Element tmpCell = null;
- String cellStart = cell.attributeValue(JRSTLexer.CELL_INDEX_START);
+ String cellStart = cell
+ .attributeValue(JRSTLexer.CELL_INDEX_START);
do {
morerows++;
- tmpCell = (Element)rows.get(r + morerows).selectSingleNode(
- JRSTLexer.CELL+"[@"+JRSTLexer.CELL_INDEX_START+"="+cellStart+"]");
+ tmpCell = (Element) rows.get(r + morerows)
+ .selectSingleNode(
+ JRSTLexer.CELL + "[@"
+ + JRSTLexer.CELL_INDEX_START
+ + "=" + cellStart + "]");
text += tmpCell.getText();
// on marque la cellule comme utilisé
tmpCell.addAttribute("used", "true");
- } while (!"true".equals(tmpCell.attributeValue(JRSTLexer.CELL_END)));
-
+ } while (!"true".equals(tmpCell
+ .attributeValue(JRSTLexer.CELL_END)));
+
if (morerows > 0) {
- entry.addAttribute("morerows", String.valueOf(morerows));
+ entry
+ .addAttribute("morerows", String
+ .valueOf(morerows));
}
- // on compte le nombre de cellules regroupees horizontalement
+ // on compte le nombre de cellules regroupees
+ // horizontalement
int morecols = 0;
tmpCell = cells.get(c + morecols);
- int cellEnd = Integer.parseInt(tmpCell.attributeValue(JRSTLexer.CELL_INDEX_END));
+ int cellEnd = Integer.parseInt(tmpCell
+ .attributeValue(JRSTLexer.CELL_INDEX_END));
while (cellEnd + 1 != beginCell[c + morecols + 1]) {
morecols++;
-// tmpCell = cells.get(c + morecols);
-// cellEnd = Integer.parseInt(tmpCell.attributeValue(JRSTLexer.CELL_INDEX_END));
+ // tmpCell = cells.get(c + morecols);
+ // cellEnd =
+ // Integer.parseInt(tmpCell.attributeValue(JRSTLexer.CELL_INDEX_END));
}
if (morecols > 0) {
- entry.addAttribute("morecols", String.valueOf(morecols));
+ entry
+ .addAttribute("morecols", String
+ .valueOf(morecols));
}
// parse entry text in table
JRSTReader reader = new JRSTReader();
@@ -1245,39 +1337,43 @@
entry.appendContent(doc.getRootElement());
}
}
- if ("true".equals(rows.get(r).attributeValue(JRSTLexer.ROW_END_HEADER))) {
+ if ("true".equals(rows.get(r).attributeValue(
+ JRSTLexer.ROW_END_HEADER))) {
rowList = tgroup.addElement(TBODY);
}
}
-
+
return result;
}
+
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeBulletList(JRSTLexer lexer) throws Exception {
Element item = lexer.peekBulletList();
Element result = DocumentHelper.createElement(BULLET_LIST);
- copyLevel(item, result);
+ copyLevel(item, result);
result.addAttribute("bullet", item.attributeValue("bullet"));
- while (itemEquals(BULLET_LIST, item) && isSameLevel(item, result) &&
- hasSameAttribute(item, result, "bullet")) {
+ while (itemEquals(BULLET_LIST, item) && isSameLevel(item, result)
+ && hasSameAttribute(item, result, "bullet")) {
lexer.remove();
Element bullet = result.addElement(LIST_ITEM);
copyLevel(item, bullet);
- bullet.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText());
+ bullet.addElement(PARAGRAPH).addAttribute("inline", "true")
+ .setText(item.getText());
composeBody(lexer, bullet);
-
+
item = lexer.peekBulletList();
}
return result;
}
+
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeEnumeratedList(JRSTLexer lexer) throws Exception {
Element item = lexer.peekEnumeratedList();
@@ -1288,189 +1384,208 @@
result.addAttribute("start", item.attributeValue("start"));
result.addAttribute("prefix", item.attributeValue("prefix"));
result.addAttribute("suffix", item.attributeValue("suffix"));
- result.addAttribute("enumtype",enumType );
- while (itemEquals(ENUMERATED_LIST, item) && isSameLevel(item, result) &&
- hasSameAttribute(item, result, "prefix", "suffix") &&
- ("auto".equals(item.attributeValue("enumtype")) ||
- hasSameAttribute(item, result, "enumtype"))) {
+ result.addAttribute("enumtype", enumType);
+ while (itemEquals(ENUMERATED_LIST, item)
+ && isSameLevel(item, result)
+ && hasSameAttribute(item, result, "prefix", "suffix")
+ && ("auto".equals(item.attributeValue("enumtype")) || hasSameAttribute(
+ item, result, "enumtype"))) {
lexer.remove();
Element e = result.addElement(LIST_ITEM);
copyLevel(item, e);
- e.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText());
+ e.addElement(PARAGRAPH).addAttribute("inline", "true").setText(
+ item.getText());
composeBody(lexer, e);
-
+
item = lexer.peekEnumeratedList();
}
return result;
}
+
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeDefinitionList(JRSTLexer lexer) throws Exception {
Element item = lexer.peekBodyElement();
Element result = DocumentHelper.createElement(DEFINITION_LIST);
- copyLevel(item, result);
+ copyLevel(item, result);
while (itemEquals(DEFINITION_LIST, item) && isSameLevel(item, result)) {
lexer.remove();
Element def = result.addElement(DEFINITION_LIST_ITEM);
- copyLevel(item, def);
-
+ copyLevel(item, def);
+
Element term = def.addElement(TERM);
- copyLevel(item, term);
- term.addAttribute("inline", "true").setText(item.attributeValue("term"));
-
- String [] classifiers = StringUtil.split(item.attributeValue("classifiers"), " : ");
+ copyLevel(item, term);
+ term.addAttribute("inline", "true").setText(
+ item.attributeValue("term"));
+
+ String[] classifiers = StringUtil.split(item
+ .attributeValue("classifiers"), " : ");
for (String classifierText : classifiers) {
Element classifier = def.addElement("classifier");
copyLevel(item, classifier);
- classifier.addAttribute("inline", "true").setText(classifierText);
+ classifier.addAttribute("inline", "true").setText(
+ classifierText);
}
-
+
Element definition = def.addElement(DEFINITION);
- definition.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText());
- copyLevel(item, definition);
-
+ definition.addElement(PARAGRAPH).addAttribute("inline", "true")
+ .setText(item.getText());
+ copyLevel(item, definition);
+
composeBody(lexer, definition);
-
+
item = lexer.peekBodyElement();
}
return result;
}
+
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeFieldList(JRSTLexer lexer) throws Exception {
Element item = lexer.peekBodyElement();
Element result = DocumentHelper.createElement(FIELD_LIST);
- copyLevel(item, result);
+ copyLevel(item, result);
while (itemEquals(FIELD_LIST, item) && isSameLevel(item, result)) {
Element field = composeFieldItemList(lexer);
- result.add(field);
+ result.add(field);
item = lexer.peekBodyElement();
}
return result;
}
+
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeFieldItemList(JRSTLexer lexer) throws Exception {
Element item = lexer.peekFieldList();
if (itemEquals(FIELD_LIST, item)) {
lexer.remove();
Element field = DocumentHelper.createElement(FIELD);
- copyLevel(item, field);
+ copyLevel(item, field);
Element fieldName = field.addElement(FIELD_NAME);
- copyLevel(item, fieldName);
- fieldName.addAttribute("inline", "true").setText(item.attributeValue("name"));
+ copyLevel(item, fieldName);
+ fieldName.addAttribute("inline", "true").setText(
+ item.attributeValue("name"));
Element fieldBody = field.addElement(FIELD_BODY);
- fieldBody.addElement(PARAGRAPH).addAttribute("inline", "true").setText(item.getText());
- copyLevel(item, fieldBody);
+ fieldBody.addElement(PARAGRAPH).addAttribute("inline", "true")
+ .setText(item.getText());
+ copyLevel(item, fieldBody);
composeBody(lexer, fieldBody);
-
+
return field;
} else {
- throw new DocumentException("Waiting for " + FIELD_LIST + " and found " + item.getName());
+ throw new DocumentException("Waiting for " + FIELD_LIST
+ + " and found " + item.getName());
}
}
-
-
/**
* @param lexer
* @return Element
- * @throws Exception
+ * @throws Exception
*/
private Element composeSection(JRSTLexer lexer) throws Exception {
Element result = DocumentHelper.createElement(SECTION);
Element firstTitle = null;
-
+
Element item = null;
-
+
// le titre de la section
item = lexer.peekTitle();
if (itemEquals(TITLE, item, true, lexer.eof())) {
lexer.remove();
- firstTitle = item;
+ firstTitle = item;
Element title = result.addElement(TITLE);
copyLevel(item, result);
copyLevel(item, title);
title.addAttribute("inline", "true").setText(item.getText().trim());
- result.addAttribute("id", item.getText().replaceAll("\\W+", " ").trim().toLowerCase().replaceAll("\\W+", "-"));
+ result.addAttribute("id", item.getText().replaceAll("\\W+", " ")
+ .trim().toLowerCase().replaceAll("\\W+", "-"));
result.addAttribute("name", item.getText().toLowerCase().trim());
eTitle.add(title);
}
-
+
// le contenu de la section
item = lexer.peekTitle();
while (itemNotEquals(TITLE, item) && !lexer.eof()) {
- composeBody(lexer, result);
+ composeBody(lexer, result);
item = lexer.peekTitle();
}
-
+
// les sous sections
item = lexer.peekTitle();
- while (itemEquals(TITLE, item)
- && isUpperLevel(item, firstTitle)) {
+ while (itemEquals(TITLE, item) && isUpperLevel(item, firstTitle)) {
Element section = composeSection(lexer);
result.add(section);
item = lexer.peekTitle();
}
-
+
return result;
}
/**
- * Indique si la sous section est bien une sous section, c-a-d dire
- * que son level est superieur a celui de la section
+ * Indique si la sous section est bien une sous section, c-a-d dire que son
+ * level est superieur a celui de la section
*
* @param item
* @param firstTitle
* @return boolean
- * @throws DocumentException
+ * @throws DocumentException
*/
- private boolean isUpperLevel(Element subSection, Element section) throws DocumentException {
-// if (!(itemEquals(SECTION, subSection) && itemEquals(SECTION, section))
-// || itemEquals(DOCUMENT, section) || itemEquals(SECTION, section)) {
-// // all element is upper than Document or section
-// return true;
-// }
- int subSectionLevel = Integer.parseInt(subSection.attributeValue("level"));
+ private boolean isUpperLevel(Element subSection, Element section)
+ throws DocumentException {
+ // if (!(itemEquals(SECTION, subSection) && itemEquals(SECTION,
+ // section))
+ // || itemEquals(DOCUMENT, section) || itemEquals(SECTION, section)) {
+ // // all element is upper than Document or section
+ // return true;
+ // }
+ int subSectionLevel = Integer.parseInt(subSection
+ .attributeValue("level"));
int sectionLevel = Integer.parseInt(section.attributeValue("level"));
boolean result = subSectionLevel > sectionLevel;
return result;
}
-
+
/**
* Indique si les deux elements sont au meme niveau
*
* @param item
* @param firstTitle
* @return boolean
- * @throws DocumentException
+ * @throws DocumentException
*/
- private boolean isSameLevel(Element subSection, Element section) throws DocumentException {
-// if (itemEquals(DOCUMENT, section) || itemEquals(SECTION, section)) {
-// // all element is upper than Document or section
-// return false;
-// }
- int subSectionLevel = Integer.parseInt(subSection.attributeValue("level"));
+ private boolean isSameLevel(Element subSection, Element section)
+ throws DocumentException {
+ // if (itemEquals(DOCUMENT, section) || itemEquals(SECTION, section)) {
+ // // all element is upper than Document or section
+ // return false;
+ // }
+ int subSectionLevel = Integer.parseInt(subSection
+ .attributeValue("level"));
int sectionLevel = Integer.parseInt(section.attributeValue("level"));
boolean result = subSectionLevel == sectionLevel;
return result;
}
+
/**
- * @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) {
+ private boolean hasSameAttribute(Element e1, Element e2, String... attnames) {
boolean result = true;
for (String attname : attnames) {
String a1 = e1.attributeValue(attname);
@@ -1482,10 +1597,13 @@
}
return result;
}
+
/**
- * @param Element from
- * @param Element to
- * @throws DocumentException
+ * @param Element
+ * from
+ * @param Element
+ * to
+ * @throws DocumentException
*/
private void copyLevel(Element from, Element to) throws DocumentException {
String level = from.attributeValue("level");
@@ -1494,65 +1612,82 @@
}
to.addAttribute("level", level);
}
+
/**
- * @param String name
- * @param Element e
- * @return boolean
- * @throws DocumentException
+ * @param String
+ * name
+ * @param Element
+ * e
+ * @return boolean
+ * @throws DocumentException
*/
private boolean itemEquals(String name, Element e) throws DocumentException {
boolean result = itemEquals(name, e, false, false);
return result;
}
+
/**
- * @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
+ * @throws DocumentException
*/
- private boolean itemEquals(String name, Element e, boolean throwError, boolean eof) throws DocumentException {
+ private boolean itemEquals(String name, Element e, boolean throwError,
+ boolean eof) throws DocumentException {
boolean result = e != null && name.equals(e.getName());
if (ERROR_MISSING_ITEM && !result && throwError && !eof) {
- throw new DocumentException("Malformed document waiting " + name + " and found " + (e!=null?e.getName():"null"));
+ throw new DocumentException("Malformed document waiting " + name
+ + " and found " + (e != null ? e.getName() : "null"));
}
return result;
- }
+ }
+
/**
- * @param String name
- * @param Element e
- * @return boolean
+ * @param String
+ * name
+ * @param Element
+ * e
+ * @return boolean
*/
private boolean itemNotEquals(String name, Element e) {
boolean result = e == null || !name.equals(e.getName());
return result;
- }
-
+ }
+
/**
- * Parse text in element and replace text with parse result
- * @param Element e
+ * Parse text in element and replace text with parse result
+ *
+ * @param Element
+ * e
* @throws DocumentException
*/
private void inline(Element e) throws DocumentException {
String text = e.getText();
-
+
text = StringEscapeUtils.escapeXml(text);
// search all LITERAL and replace it with special mark
// this prevent substitution in literal, example **something** must not
// change in literal
Map temporaries = new HashMap();
-
+
Matcher matcher = REGEX_LITERAL.matcher(text);
int index = 0;
- while(matcher.find()) {
- int start = matcher.start();
+ while (matcher.find()) {
+ int start = matcher.start();
int end = matcher.end();
- String literal = "<"+LITERAL+">" + matcher.group(1) + ""+LITERAL+">";
- String key = "literal" + index++;
+ String literal = "<" + LITERAL + ">" + matcher.group(1) + ""
+ + LITERAL + ">";
+ String key = "literal" + index++;
temporaries.put(key, literal);
-
- text = text.substring(0, start) + "``" + key + "``" + text.substring(end);
+
+ text = text.substring(0, start) + "``" + key + "``"
+ + text.substring(end);
}
// search all REGEX_INLINE_REFERENCE and replace it with special mark
@@ -1560,223 +1695,231 @@
// mechanisme as literal for that
matcher = REGEX_INLINE_REFERENCE.matcher(text);
index = 0;
- while(matcher.find()) {
- int start = matcher.start();
+
+ while (matcher.find()) {
+ int start = matcher.start();
int end = matcher.end();
Element ref = DocumentHelper.createElement(REFERENCE);
ref.addAttribute("refuri", matcher.group(2));
ref.setText(matcher.group(1));
- String key = "inlineReference" + index++;
+ String key = "inlineReference" + index++;
temporaries.put(key, ref.asXML());
- text = text.substring(0, start) + "``" + key + "``" + text.substring(end);
+ text = text.substring(0, start) + "``" + key + "``"
+ + text.substring(end);
}
-
-
-
-
-
// do all substitution inline
- text = REGEX_EMAIL.matcher(text).replaceAll("$1<"+REFERENCE+" refuri='mailto:$2'>$2"+REFERENCE+">$3");
- text = REGEX_STRONG.matcher(text).replaceAll("<"+STRONG+">$1"+STRONG+">");
- text = REGEX_EMPHASIS.matcher(text).replaceAll("<"+EMPHASIS+">$1"+EMPHASIS+">");
- text = REGEX_REFERENCE.matcher(text).replaceAll("<"+REFERENCE+" refuri='$1'>$1"+REFERENCE+">$2");
+ text = REGEX_EMAIL.matcher(text).replaceAll(
+ "$1<" + REFERENCE + " refuri='mailto:$2'>$2" + REFERENCE
+ + ">$3");
+ text = REGEX_STRONG.matcher(text).replaceAll(
+ "<" + STRONG + ">$1" + STRONG + ">");
+ text = REGEX_EMPHASIS.matcher(text).replaceAll(
+ "<" + EMPHASIS + ">$1" + EMPHASIS + ">");
+ text = REGEX_REFERENCE.matcher(text).replaceAll(
+ "<" + REFERENCE + " refuri='$1'>$1" + REFERENCE + ">$2");
-
matcher = REGEX_FOOTNOTE_REFERENCE.matcher(text);
- while (matcher.find()){
- String txtDebut=text.substring(0,matcher.start());
- String txtFin=text.substring(matcher.end(),text.length());
+ while (matcher.find()) {
+ String txtDebut = text.substring(0, matcher.start());
+ String txtFin = text.substring(matcher.end(), text.length());
Element footnote = DocumentHelper.createElement(FOOTNOTE_REFERENCE);
String sFootnote = matcher.group();
boolean done = false;
- for (int i=0;i