Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.22 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.23 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.22 Fri May 11 16:19:06 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Mon May 14 14:41:07 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.22 $ + * @version $Revision: 1.23 $ * - * Last update: $Date: 2007/05/11 16:19:06 $ + * Last update: $Date: 2007/05/14 14:41:07 $ * by : $Author: sletellier $ */ @@ -33,9 +33,16 @@ import static org.codelutin.jrst.ReStructuredText.*; import static org.codelutin.i18n.I18n._; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.net.URL; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -645,6 +652,10 @@ lexer.remove(); }else if (itemEquals("remove", item)) { lexer.remove(); + } else if (itemEquals("include", item)){ + lexer.remove(); + Element list = composeInclude(item); + parent.add(list); } else if (itemEquals(DOCTEST_BLOCK, item)) { lexer.remove(); Element list = composeDoctestBlock(item); @@ -748,6 +759,37 @@ } return parent; } + private Element composeInclude(Element item) throws Exception { + String option = item.attributeValue("option"); + String path = item.getText(); + Element result = null; + if (option.equals("literal")){ + result=DocumentHelper.createElement("LITERAL_BLOCK"); + FileReader reader = new FileReader(path); + BufferedReader bf = new BufferedReader(reader); + String line=""; + String lineTmp= bf.readLine(); + //bf.skip(line.length()); + while (lineTmp != null){ + line += '\n'+lineTmp; + lineTmp = bf.readLine(); + //bf.skip(line.length()); + } + result.setText(line); + } + else{ + File fileIn =new File(path); + URL url = fileIn.toURL(); + Reader in = new InputStreamReader(url.openStream()); + JRSTReader jrst = new JRSTReader(); + Document doc = jrst.read(in); + + result = doc.getRootElement(); + } + return result; + } + + private Element composeComment(Element item) { return item; Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.20 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.21 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.20 Thu May 10 16:13:49 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Mon May 14 14:41:07 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.20 $ + * @version $Revision: 1.21 $ * - * Last update: $Date: 2007/05/10 16:13:49 $ + * Last update: $Date: 2007/05/14 14:41:07 $ * by : $Author: sletellier $ */ @@ -342,6 +342,9 @@ public Element peekBodyElement() throws IOException { Element result = null; if (result == null) { + result = peekInclude(); + } + if (result == null) { result = peekComment(); } if (result == null) { @@ -440,8 +443,32 @@ * * * @return Element + * @throws IOException * @throws IOException */ + private Element peekInclude() throws IOException{ + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("^\\s*\\.\\.\\sinclude\\:\\:.+$")){ + result = DocumentHelper.createElement("include"); + result.addAttribute("level",""+level(line)); + String option = line.substring(line.indexOf("::")+2).trim(); + result.addAttribute("option", ""); + if (option.trim().equalsIgnoreCase("literal")){ + result.addAttribute("option", "literal"); + line = in.readLine(); + result.setText(line.trim()); + } + else + result.setText(option); + + } + } + endPeek(); + return result; + } public Element peekOption() throws IOException { /* -a command-line option "a"