Index: jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.5 jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.6 --- jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java:1.5 Fri Nov 10 14:21:11 2006 +++ jrst2/src/java/org/codelutin/jrst/JRSTGenerator.java Thu May 10 10:18:41 2007 @@ -23,10 +23,10 @@ * Created: 30 oct. 06 00:14:18 * * @author poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Last update: $Date: 2006/11/10 14:21:11 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2007/05/10 10:18:41 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -328,6 +328,7 @@ * @param e * @return */ + @SuppressWarnings("unchecked") protected int inlineLength(Element e) { int result = 0; LinkedList elems = new LinkedList(); Index: jrst2/src/java/org/codelutin/jrst/DocumentWalker.java diff -u jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.1.1.1 jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.2 --- jrst2/src/java/org/codelutin/jrst/DocumentWalker.java:1.1.1.1 Mon Oct 30 19:34:05 2006 +++ jrst2/src/java/org/codelutin/jrst/DocumentWalker.java Thu May 10 10:18:41 2007 @@ -23,10 +23,10 @@ * Created: 30 oct. 06 10:28:10 * * @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: 2007/05/10 10:18:41 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -65,6 +65,7 @@ handler.endDocument(doc); } + @SuppressWarnings("unchecked") public void walk(Element elem) { handler.startElement(elem); for (Node node : (List)elem.content()) { Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.19 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.20 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.19 Wed May 9 12:12:19 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Thu May 10 10:18:41 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * - * Last update: $Date: 2007/05/09 12:12:19 $ + * Last update: $Date: 2007/05/10 10:18:41 $ * by : $Author: sletellier $ */ @@ -43,11 +43,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.ContentDirective; import org.codelutin.jrst.directive.DateDirective; import org.codelutin.jrst.directive.ImageDirective; import org.codelutin.util.StringUtil; @@ -301,12 +301,14 @@ private LinkedList eFootnotes = new LinkedList(); private LinkedList eTarget = new LinkedList(); private LinkedList eTargetAnonymous = new LinkedList(); + private LinkedList eTitle = new LinkedList(); static { defaultDirectives = new HashMap(); defaultDirectives.put(IMAGE, new ImageDirective()); defaultDirectives.put(DATE, new DateDirective()); defaultDirectives.put("time", new DateDirective()); + defaultDirectives.put("contents", new ContentDirective()); // TODO put here all other directive } @@ -357,7 +359,6 @@ JRSTLexer lexer = new JRSTLexer(reader); try { Element root = composeDocument(lexer); - Document result = DocumentHelper.createDocument(); result.setRootElement(root); @@ -365,6 +366,13 @@ root.accept(new VisitorSupport() { public void visit(Element e) { e.addAttribute("level", null); + String type = e.attributeValue("type"); + if (type!=null){ + if (type.equals("contents")){ + composeContents(e); + e.addAttribute("type",null); + } + } if ("true".equalsIgnoreCase(e.attributeValue("inline"))) { e.addAttribute("inline", null); try { @@ -377,15 +385,99 @@ } } }); - - return result; } catch (Exception eee) { log.error(_("JRST parsing error line {0} char {1}:\n{2}", lexer.getLineNumber(), lexer.getCharNumber(), lexer.readNotBlanckLine())); throw eee; } } + private void composeContents(Element e) { + Element result = DocumentHelper.createElement(TOPIC); + String option = e.getText(); + 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()); + } + int levelInit = Integer.parseInt(eTitle.getFirst().attributeValue("level")); + LinkedList title = new LinkedList(); + for (Element el : eTitle){ + int level = Integer.parseInt(el.attributeValue("level")); + level=level-levelInit; + el.addAttribute("level", ""+level); + if (depth==-1) + title.add(el); + else{ + if (depth>level-levelInit) + title.add(el); + } + } + e.addAttribute("class", "contents"); + String titleValue= e.attributeValue("value"); + e.addAttribute("value", null); + String value = titleValue.trim().toLowerCase(); + + if (value.matches("\\s*")){ + value="contents"; + titleValue="Contents"; + } + e.addAttribute("id", value); + e.addAttribute("name",value); + result.addElement("title").setText(titleValue); + result.add(composeLineContent(title)); + e.appendContent(result); + } + private Element composeLineContent(LinkedList title) { + Element result = DocumentHelper.createElement(BULLET_LIST); + while (!title.isEmpty()){ + boolean done=false; + Element e = title.getFirst(); + Element item = null; + title.removeFirst(); + int level = Integer.parseInt(e.attributeValue("level")); + LinkedList child = new LinkedList(); + while (level==0 && !done){ + item = result.addElement(LIST_ITEM); + Element para = item.addElement(PARAGRAPH); + Element reference = para.addElement(REFERENCE); + String text=e.getText(); + reference.addAttribute("id", e.attributeValue("refid")); + reference.addAttribute("refid", text.replaceAll("\\W+", " ").trim().toLowerCase().replaceAll("\\W+", "-")); + reference.addAttribute("inline","true"); + reference.setText(text.trim()); + if (!title.isEmpty()){ + e = title.getFirst(); + title.removeFirst(); + level = Integer.parseInt(e.attributeValue("level")); + } + else + done=true; + } + while (level>0 && !done){ + e.addAttribute("level", ""+(level-1)); + child.add(e); + if (!title.isEmpty()){ + e = title.getFirst(); + title.removeFirst(); + level = Integer.parseInt(e.attributeValue("level")); + } + else + done=true; + } + if (child!=null){ + if (item!=null) + item.add(composeLineContent(child)); // Appel recursif + else + result.add(composeLineContent(child)); // Appel recursif + } + } + return result; + } /** * @param lexer * @return Element @@ -501,7 +593,6 @@ result.add(section); item = lexer.peekTitle(); } - return result; } /** @@ -675,6 +766,7 @@ * @throws Exception */ // TODO bug caractere speciaux : auto-symbols + @SuppressWarnings("unchecked") private Element[] composeFootnote(Element item) throws Exception { Element[] result=null; if (itemEquals("footnotes", item) ) { @@ -785,7 +877,8 @@ * @throws Exception * @throws DocumentException */ - private Element composeOptionList(JRSTLexer lexer) throws DocumentException, Exception{ + @SuppressWarnings("unchecked") + private Element composeOptionList(JRSTLexer lexer) throws DocumentException, Exception{ Element item = lexer.peekOption(); Element result = DocumentHelper.createElement(OPTION_LIST); while (itemEquals(OPTION_LIST, item) ) { @@ -844,7 +937,8 @@ * @throws Exception */ - private Element composeLineBlock(JRSTLexer lexer, Element item) 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); @@ -975,6 +1069,7 @@ * @param Element item * @return Element */ + @SuppressWarnings("unchecked") private Element composeTable(Element item) throws Exception { Element result = DocumentHelper.createElement(TABLE); @@ -1213,8 +1308,11 @@ Element title = result.addElement(TITLE); copyLevel(item, result); copyLevel(item, title); - - title.addAttribute("inline", "true").setText(item.getText()); + title.addAttribute("refid", "id"+(++idMax)); + title.addAttribute("inline", "true").setText(item.getText().trim()); + 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 Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.18 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.19 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.18 Wed May 9 12:12:19 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Thu May 10 10:18:41 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.18 $ + * @version $Revision: 1.19 $ * - * Last update: $Date: 2007/05/09 12:12:19 $ + * Last update: $Date: 2007/05/10 10:18:41 $ * by : $Author: sletellier $ */ @@ -34,13 +34,10 @@ import java.io.IOException; import java.io.Reader; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.locks.ReadWriteLock; 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; @@ -1057,6 +1054,7 @@ * @return Element * @throws IOException */ + @SuppressWarnings("unchecked") public Element peekTable() throws IOException { beginPeek(); @@ -1874,13 +1872,7 @@ } return txt; } - private String[] readBlockWithBlank(int level) throws IOException{ - - String [] lines = in.readWhile("(^ {"+level+"}.*)|(\\s*)"); - - return lines; - } - /** + /** * Lit les premieres ligne non vide et les retourne, rien n'est modifier par rapport * aux positions dans le fichier. Util pour afficher a l'utilisateur les lignes * qui ont produit une erreur Index: jrst2/src/java/org/codelutin/jrst/JRST.java diff -u jrst2/src/java/org/codelutin/jrst/JRST.java:1.5 jrst2/src/java/org/codelutin/jrst/JRST.java:1.6 --- jrst2/src/java/org/codelutin/jrst/JRST.java:1.5 Thu May 3 16:37:08 2007 +++ jrst2/src/java/org/codelutin/jrst/JRST.java Thu May 10 10:18:41 2007 @@ -23,9 +23,9 @@ * Created: 3 nov. 06 20:56:00 * * @author poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Last update: $Date: 2007/05/03 16:37:08 $ + * Last update: $Date: 2007/05/10 10:18:41 $ * by : $Author: sletellier $ */ @@ -34,25 +34,18 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; -import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.HashMap; import java.util.Map; - -import javax.xml.transform.TransformerException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.util.FileUtil; import org.codelutin.util.StringUtil; import org.dom4j.Document; -import org.dom4j.DocumentException; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; - -import uk.co.flamingpenguin.jewel.cli.ArgumentValidationException; import uk.co.flamingpenguin.jewel.cli.Cli; import uk.co.flamingpenguin.jewel.cli.CliFactory; import uk.co.flamingpenguin.jewel.cli.CommandLineInterface;