From doxia-commitssimpsonnathan@example.org Mon Jul 03 23:32:50 2006 Return-Path: <doxia-commitssimpsonnathan@example.org> Delivered-To: simpsonnathan@example.org Received: (qmail 8260 invoked from network); 3 Jul 2006 23:32:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 3 Jul 2006 23:32:50 -0000 Received: (qmail 70986 invoked by uid 500); 3 Jul 2006 23:32:50 -0000 Delivered-To: simpsonnathan@example.org Received: (qmail 70958 invoked by uid 500); 3 Jul 2006 23:32:49 -0000 Mailing-List: contact simpsonnathan@example.org; run by ezmlm Precedence: bulk List-Help: <mailto:simpsonnathan@example.org> List-Unsubscribe: <mailto:simpsonnathan@example.org> List-Post: <mailto:simpsonnathan@example.org> List-Id: <doxia-commits.maven.apache.org> Reply-To: simpsonnathan@example.org Delivered-To: mailing list simpsonnathan@example.org Received: (qmail 70949 invoked by uid 99); 3 Jul 2006 23:32:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:32:49 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:32:49 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3BA1D1A983A; Mon, 3 Jul 2006 16:32:29 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418874 - in /maven/doxia/trunk: doxia-doc-renderer/ doxia-site-renderer/ Date: Mon, 03 Jul 2006 23:32:28 -0000 To: simpsonnathan@example.org From: simpsonnathan@example.org X-Mailer: svnmailer-1.0.8 Message-Id: <simpsonnathan@example.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trygvis Date: Mon Jul 3 16:32:28 2006 New Revision: 418874 URL: http://svn.apache.org/viewvc?rev=418874&view=rev Log: o Setting svn:ignore. Modified: maven/doxia/trunk/doxia-doc-renderer/ (props changed) maven/doxia/trunk/doxia-site-renderer/ (props changed) Propchange: maven/doxia/trunk/doxia-doc-renderer/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Mon Jul 3 16:32:28 2006 @@ -0,0 +1,8 @@ +target +*~ +*.log +.classpath +.project +*.ipr +*.iws +*.iml Propchange: maven/doxia/trunk/doxia-site-renderer/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Mon Jul 3 16:32:28 2006 @@ -1,2 +1,8 @@ target +*~ +*.log +.classpath +.project +*.ipr +*.iws *.iml From doxia-commitssimpsonnathan@example.org Mon Jul 03 23:33:34 2006 Return-Path: <doxia-commitssimpsonnathan@example.org> Delivered-To: simpsonnathan@example.org Received: (qmail 8489 invoked from network); 3 Jul 2006 23:33:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 3 Jul 2006 23:33:34 -0000 Received: (qmail 72308 invoked by uid 500); 3 Jul 2006 23:33:33 -0000 Delivered-To: simpsonnathan@example.org Received: (qmail 72290 invoked by uid 500); 3 Jul 2006 23:33:33 -0000 Mailing-List: contact simpsonnathan@example.org; run by ezmlm Precedence: bulk List-Help: <mailto:simpsonnathan@example.org> List-Unsubscribe: <mailto:simpsonnathan@example.org> List-Post: <mailto:simpsonnathan@example.org> List-Id: <doxia-commits.maven.apache.org> Reply-To: simpsonnathan@example.org Delivered-To: mailing list simpsonnathan@example.org Received: (qmail 72270 invoked by uid 99); 3 Jul 2006 23:33:33 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:33:33 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:33:32 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CC6F41A983A; Mon, 3 Jul 2006 16:33:11 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418875 - in /maven/doxia/trunk/doxia-core/src/main: java/org/apache/maven/doxia/module/latex/ resources/org/ resources/org/apache/ resources/org/apache/maven/ resources/org/apache/maven/doxia/ resources/org/apache/maven/doxia/module/ resou... Date: Mon, 03 Jul 2006 23:33:11 -0000 To: simpsonnathan@example.org From: simpsonnathan@example.org X-Mailer: svnmailer-1.0.8 Message-Id: <simpsonnathan@example.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trygvis Date: Mon Jul 3 16:33:10 2006 New Revision: 418875 URL: http://svn.apache.org/viewvc?rev=418875&view=rev Log: o Cleaning up LaTeX sink. Should be usable by the book system now. Added: maven/doxia/trunk/doxia-core/src/main/resources/org/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_preamble.tex maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_sink_commands.tex Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java?rev=418875&r1=418874&r2=418875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java (original) +++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java Mon Jul 3 16:33:10 2006 @@ -19,19 +19,29 @@ import org.apache.maven.doxia.module.apt.AptParser; import org.apache.maven.doxia.sink.SinkAdapter; import org.apache.maven.doxia.util.LineBreaker; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; import java.io.Writer; +import java.io.IOException; +import java.io.InputStream; -/** - * @componentx - */ public class LatexSink extends SinkAdapter { private static final String EOL = System.getProperty( "line.separator" ); + /** + * Flag that indicates if the document to be written is only a fragment. + * + * This implies that <code>\\begin{document}</code>, <code>\\ptitle{..}</code> will not be output. + */ + private boolean fragmentDocument; + private LineBreaker out; + private String sinkCommands; + private String preamble; private boolean titleFlag; @@ -52,29 +62,58 @@ private int cellCount; - // ----------------------------------------------------------------------- + private boolean isTitle; + + private String title; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- public LatexSink( Writer out ) + throws IOException { - this( out, defaultPreamble ); + this( out, IOUtil.toString( getDefaultSinkCommands() ), IOUtil.toString( getDefaultPreamble() ) ); } - public LatexSink( Writer out, String preamble ) + public LatexSink( Writer out, String sinkCommands, String preamble ) { this.out = new LineBreaker( out ); - setPreamble( preamble ); + this.sinkCommands = sinkCommands; + this.preamble = preamble; } - public void setPreamble( String preamble ) + public LatexSink( Writer out, String sinkCommands, String preamble, boolean fragmentDocument ) { + this.out = new LineBreaker( out ); + this.sinkCommands = sinkCommands; this.preamble = preamble; + this.fragmentDocument = fragmentDocument; + } + + // ---------------------------------------------------------------------- + // Overridables + // ---------------------------------------------------------------------- + + protected String getDocumentStart() + { + return "\\documentclass[a4paper]{article}"; + } + + protected String getDocumentBegin() + { + return "\\begin{document}"; } - public String getPreamble() + protected String getDocumentEnd() { - return preamble; + return "\\end{document}" + EOL; } + // ---------------------------------------------------------------------- + // Sink Implementation + // ---------------------------------------------------------------------- + public void head() { titleFlag = false; @@ -87,13 +126,21 @@ cellJustif = null; cellCount = 0; - markup( preamble ); - markup( "\\begin{document}" + EOL + EOL ); + if ( !fragmentDocument ) + { + markup( sinkCommands ); + + markup( preamble ); + + markup( getDocumentStart() ); + + markup( getDocumentBegin() ); + } } public void body() { - if ( titleFlag ) + if ( !fragmentDocument && titleFlag ) { titleFlag = false; markup( "\\pmaketitle" + EOL + EOL ); @@ -102,35 +149,138 @@ public void body_() { - markup( "\\end{document}" + EOL + EOL ); + if ( !fragmentDocument ) + { + markup( getDocumentEnd() ); + } + out.flush(); } - public void section1() + // ---------------------------------------------------------------------- + // Section Title 1 + // ---------------------------------------------------------------------- + + public void sectionTitle1() { - markup( "\\psectioni{" ); + isTitle = true; } - public void section2() + public void sectionTitle1_() { - markup( "\\psectionii{" ); + isTitle = false; } - public void section3() + public void section1_() { - markup( "\\psectioniii{" ); + if ( StringUtils.isNotEmpty( title ) ) + { + markup( "\\psectioni{" + title + "}" ); + + title = null; + } } - public void section4() + // ---------------------------------------------------------------------- + // Section Title 2 + // ---------------------------------------------------------------------- + + public void sectionTitle2() + { + isTitle = true; + } + + public void sectionTitle2_() + { + isTitle = false; + } + + public void section2_() + { + if ( StringUtils.isNotEmpty( title ) ) + { + markup( "\\psectionii{" + title + "}" ); + + title = null; + } + } + + // ---------------------------------------------------------------------- + // Section Title 3 + // ---------------------------------------------------------------------- + + public void sectionTitle3() + { + isTitle = true; + } + + public void sectionTitle3_() { - markup( "\\psectioniv{" ); + isTitle = false; } - public void section5() + public void section3_() { - markup( "\\psectionv{" ); + if ( StringUtils.isNotEmpty( title ) ) + { + markup( "\\psectioniii{" + title + "}" ); + + title = null; + } } + // ---------------------------------------------------------------------- + // Section Title 4 + // ---------------------------------------------------------------------- + + public void sectionTitle4() + { + isTitle = true; + } + + public void sectionTitle4_() + { + isTitle = false; + } + + public void section4_() + { + if ( StringUtils.isNotEmpty( title ) ) + { + markup( "\\psectioniv{" + title + "}" ); + + title = null; + } + } + + // ---------------------------------------------------------------------- + // Section Title 5 + // ---------------------------------------------------------------------- + + public void sectionTitle5() + { + isTitle = true; + } + + public void sectionTitle5_() + { + isTitle = false; + } + + public void section5_() + { + if ( StringUtils.isNotEmpty( title ) ) + { + markup( "\\psectionv{" + title + "}" ); + + title = null; + } + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + public void list() { markup( "\\begin{plist}" + EOL + EOL ); @@ -297,33 +447,51 @@ public void title() { - titleFlag = true; - markup( "\\ptitle{" ); + if ( !fragmentDocument ) + { + titleFlag = true; + markup( "\\ptitle{" ); + } } public void title_() { - markup( "}" + EOL ); + if ( !fragmentDocument ) + { + markup( "}" + EOL ); + } } public void author() { - markup( "\\pauthor{" ); + if ( !fragmentDocument ) + { + markup( "\\pauthor{" ); + } } public void author_() { - markup( "}" + EOL ); + if ( !fragmentDocument ) + { + markup( "}" + EOL ); + } } public void date() { - markup( "\\pdate{" ); + if ( !fragmentDocument ) + { + markup( "\\pdate{" ); + } } public void date_() { - markup( "}" + EOL ); + if ( !fragmentDocument ) + { + markup( "}" + EOL ); + } } public void sectionTitle_() @@ -505,7 +673,11 @@ public void text( String text ) { - if ( verbatimFlag ) + if ( isTitle ) + { + title = text; + } + else if ( verbatimFlag ) { verbatimContent( text ); } @@ -519,7 +691,10 @@ protected void markup( String text ) { - out.write( text, /*preserveSpace*/ true ); + if ( text != null ) + { + out.write( text, /*preserveSpace*/ true ); + } } protected void content( String text ) @@ -547,7 +722,7 @@ case '-': case '<': case '>': - buffer.append( "\\symbol{" + ( (int) c ) + "}" ); + buffer.append( "\\symbol{" ).append( (int) c ).append( "}" ); break; case '~': buffer.append( "\\textasciitilde " ); @@ -590,59 +765,9 @@ return buffer.toString(); } - // ----------------------------------------------------------------------- - - private static final String defaultPreamble = "\\newcommand{\\ptitle}[1]{\\title{#1}}" + EOL + - "\\newcommand{\\pauthor}[1]{\\author{#1}}" + EOL + - "\\newcommand{\\pdate}[1]{\\date{#1}}" + EOL + - "\\newcommand{\\pmaketitle}{\\maketitle}" + EOL + - "\\newcommand{\\psectioni}[1]{\\section{#1}}" + EOL + - "\\newcommand{\\psectionii}[1]{\\subsection{#1}}" + EOL + - "\\newcommand{\\psectioniii}[1]{\\subsubsection{#1}}" + EOL + - "\\newcommand{\\psectioniv}[1]{\\paragraph{#1}}" + EOL + - "\\newcommand{\\psectionv}[1]{\\subparagraph{#1}}" + EOL + - "\\newenvironment{plist}{\\begin{itemize}}{\\end{itemize}}" + EOL + - "\\newenvironment{pnumberedlist}{\\begin{enumerate}}{\\end{enumerate}}" + EOL + - "\\newcommand{\\pdef}[1]{\\textbf{#1}\\hfill}" + EOL + - "\\newenvironment{pdefinitionlist}" + EOL + - "{\\begin{list}{}{\\settowidth{\\labelwidth}{\\textbf{999.}}" + EOL + - " \\setlength{\\leftmargin}{\\labelwidth}" + EOL + - " \\addtolength{\\leftmargin}{\\labelsep}" + EOL + - " \\renewcommand{\\makelabel}{\\pdef}}}" + EOL + "{\\end{list}}" + EOL + - "\\newenvironment{pfigure}{\\begin{center}}{\\end{center}}" + EOL + - "\\newcommand{\\pfiguregraphics}[1]{\\includegraphics{#1.eps}}" + EOL + - "\\newcommand{\\pfigurecaption}[1]{\\\\ \\vspace{\\pparskipamount}" + EOL + - " \\textit{#1}}" + EOL + - "\\newenvironment{ptable}{\\begin{center}}{\\end{center}}" + EOL + - "\\newenvironment{ptablerows}[1]{\\begin{tabular}{#1}}{\\end{tabular}}" + EOL + - "\\newenvironment{pcell}[1]{\\begin{tabular}[t]{#1}}{\\end{tabular}}" + EOL + - "\\newcommand{\\ptablecaption}[1]{\\\\ \\vspace{\\pparskipamount}" + EOL + - " \\textit{#1}}" + EOL + - "\\newenvironment{pverbatim}{\\begin{small}}{\\end{small}}" + EOL + "\\newsavebox{\\pbox}" + EOL + - "\\newenvironment{pverbatimbox}" + EOL + "{\\begin{lrbox}{\\pbox}\\begin{minipage}{\\linewidth}\\begin{small}}" + EOL + - "{\\end{small}\\end{minipage}\\end{lrbox}\\fbox{\\usebox{\\pbox}}}" + EOL + - "\\newcommand{\\phorizontalrule}{\\begin{center}" + EOL + - " \\rule[0.5ex]{\\linewidth}{1pt}" + EOL + - " \\end{center}}" + EOL + - "\\newcommand{\\panchor}[1]{\\textcolor{panchorcolor}{#1}}" + EOL + - "\\newcommand{\\plink}[1]{\\textcolor{plinkcolor}{#1}}" + EOL + "\\newcommand{\\pitalic}[1]{\\textit{#1}}" + EOL + - "\\newcommand{\\pbold}[1]{\\textbf{#1}}" + EOL + - "\\newcommand{\\pmonospaced}[1]{\\texttt{\\small #1}}" + EOL + EOL + - "\\documentclass[a4paper]{article}" + EOL + "\\usepackage{a4wide}" + EOL + - "\\usepackage{color}" + EOL + - "\\usepackage{graphics}" + EOL + - "\\usepackage{times}" + EOL + - "\\usepackage[latin1]{inputenc}" + EOL + - "\\usepackage[T1]{fontenc}" + EOL + EOL + - "\\pagestyle{plain}" + EOL + EOL + - "\\definecolor{plinkcolor}{rgb}{0,0,0.54}" + EOL + - "\\definecolor{panchorcolor}{rgb}{0.54,0,0}" + EOL + EOL + - "\\newlength{\\pparskipamount}" + EOL + - "\\setlength{\\pparskipamount}{1ex}" + EOL + - "\\setlength{\\parindent}{0pt}" + EOL + - "\\setlength{\\parskip}{\\pparskipamount}" + EOL + EOL; - - // ----------------------------------------------------------------------- + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- public void flush() { @@ -652,5 +777,21 @@ public void close() { out.close(); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public static InputStream getDefaultSinkCommands() + throws IOException + { + return LatexSink.class.getResource( "default_sink_commands.tex" ).openStream(); + } + + public static InputStream getDefaultPreamble() + throws IOException + { + return LatexSink.class.getResource( "default_preamble.tex" ).openStream(); } } Added: maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_preamble.tex URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_preamble.tex?rev=418875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_preamble.tex (added) +++ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_preamble.tex Mon Jul 3 16:33:10 2006 @@ -0,0 +1,13 @@ +\usepackage{a4wide} +\usepackage{color} +\usepackage{graphics} +\usepackage{times} +\usepackage[latin1]{inputenc} +%%\usepackage[T1]{fontenc} +\pagestyle{plain} +\definecolor{plinkcolor}{rgb}{0,0,0.54} +\definecolor{panchorcolor}{rgb}{0.54,0,0} +\newlength{\pparskipamount} +\setlength{\pparskipamount}{1ex} +\setlength{\parindent}{0pt} +\setlength{\parskip}{\pparskipamount} Added: maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_sink_commands.tex URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_sink_commands.tex?rev=418875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_sink_commands.tex (added) +++ maven/doxia/trunk/doxia-core/src/main/resources/org/apache/maven/doxia/module/latex/default_sink_commands.tex Mon Jul 3 16:33:10 2006 @@ -0,0 +1,36 @@ +\newcommand{\ptitle}[1]{\title{#1}} +\newcommand{\pauthor}[1]{\author{#1}} +\newcommand{\pdate}[1]{\date{#1}} +\newcommand{\pmaketitle}{\maketitle} +\newcommand{\psectioni}[1]{\section{#1}} +\newcommand{\psectionii}[1]{\subsection{#1}} +\newcommand{\psectioniii}[1]{\subsubsection{#1}} +\newcommand{\psectioniv}[1]{\paragraph{#1}} +\newcommand{\psectionv}[1]{\subparagraph{#1}} +\newenvironment{plist}{\begin{itemize}}{\end{itemize}} +\newenvironment{pnumberedlist}{\begin{enumerate}}{\end{enumerate}} +\newcommand{\pdef}[1]{\textbf{#1}\hfill} +\newenvironment{pdefinitionlist} +{\begin{list}{}{\settowidth{\labelwidth}{\textbf{999.}} + \setlength{\leftmargin}{\labelwidth} + \addtolength{\leftmargin}{\labelsep} + \renewcommand{\makelabel}{\pdef}}} {\end{list}} +\newenvironment{pfigure}{\begin{center}}{\end{center}} +\newcommand{\pfiguregraphics}[1]{\includegraphics{#1.eps}} +\newcommand{\pfigurecaption}[1]{\\ \vspace{\pparskipamount} + \textit{#1}} +\newenvironment{ptable}{\begin{center}}{\end{center}} +\newenvironment{ptablerows}[1]{\begin{tabular}{#1}}{\end{tabular}} +\newenvironment{pcell}[1]{\begin{tabular}[t]{#1}}{\end{tabular}} +\newcommand{\ptablecaption}[1]{\\ \vspace{\pparskipamount} + \textit{#1}} +\newenvironment{pverbatim}{\begin{small}}{\end{small}} \newsavebox{\pbox} +\newenvironment{pverbatimbox} {\begin{lrbox}{\pbox}\begin{minipage}{\linewidth}\begin{small}} +{\end{small}\end{minipage}\end{lrbox}\fbox{\usebox{\pbox}}} +\newcommand{\phorizontalrule}{\begin{center} + \rule[0.5ex]{\linewidth}{1pt} + \end{center}} +\newcommand{\panchor}[1]{\textcolor{panchorcolor}{#1}} +\newcommand{\plink}[1]{\textcolor{plinkcolor}{#1}} \newcommand{\pitalic}[1]{\textit{#1}} +\newcommand{\pbold}[1]{\textbf{#1}} +\newcommand{\pmonospaced}[1]{\texttt{\small #1}} From doxia-commitssimpsonnathan@example.org Mon Jul 03 23:34:45 2006 Return-Path: <doxia-commitssimpsonnathan@example.org> Delivered-To: simpsonnathan@example.org Received: (qmail 8713 invoked from network); 3 Jul 2006 23:34:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 3 Jul 2006 23:34:45 -0000 Received: (qmail 72655 invoked by uid 500); 3 Jul 2006 23:34:45 -0000 Delivered-To: simpsonnathan@example.org Received: (qmail 72631 invoked by uid 500); 3 Jul 2006 23:34:44 -0000 Mailing-List: contact simpsonnathan@example.org; run by ezmlm Precedence: bulk List-Help: <mailto:simpsonnathan@example.org> List-Unsubscribe: <mailto:simpsonnathan@example.org> List-Post: <mailto:simpsonnathan@example.org> List-Id: <doxia-commits.maven.apache.org> Reply-To: simpsonnathan@example.org Delivered-To: mailing list simpsonnathan@example.org Received: (qmail 72622 invoked by uid 99); 3 Jul 2006 23:34:44 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:34:44 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:34:43 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id D726D1A983A; Mon, 3 Jul 2006 16:34:23 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418876 - in /maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/doxia/ src/main/java/org/apache/m... Date: Mon, 03 Jul 2006 23:34:23 -0000 To: simpsonnathan@example.org From: simpsonnathan@example.org X-Mailer: svnmailer-1.0.8 Message-Id: <simpsonnathan@example.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trygvis Date: Mon Jul 3 16:34:22 2006 New Revision: 418876 URL: http://svn.apache.org/viewvc?rev=418876&view=rev Log: o Adding a Maven plugin to render Doxia Books. Added: maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/ (with props) maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/Book.java maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java Propchange: maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Mon Jul 3 16:34:22 2006 @@ -0,0 +1,8 @@ +target +*~ +*.log +.classpath +.project +*.ipr +*.iws +*.iml Added: maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml?rev=418876&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml Mon Jul 3 16:34:22 2006 @@ -0,0 +1,24 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia</artifactId> + <version>1.0-alpha-9-SNAPSHOT</version> + </parent> + <artifactId>doxia-maven-plugin</artifactId> + <version>1.0-alpha-1-SNAPSHOT</version> + <packaging>maven-plugin</packaging> + <name>Doxia Maven Plugin</name> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>doxia-book</artifactId> + <version>1.0-alpha-1-SNAPSHOT</version> + </dependency> + </dependencies> +</project> Added: maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/Book.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/Book.java?rev=418876&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/Book.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/Book.java Mon Jul 3 16:34:22 2006 @@ -0,0 +1,45 @@ +package org.apache.maven.doxia.plugin; + +import java.util.List; + +/** + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class Book +{ + private String descriptor; + + private List formats; + + private String directory; + + private List includes; + + private List excludes; + + public String getDescriptor() + { + return descriptor; + } + + public List getFormats() + { + return formats; + } + + public String getDirectory() + { + return directory; + } + + public List getIncludes() + { + return includes; + } + + public List getExcludes() + { + return excludes; + } +} Added: maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java?rev=418876&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java Mon Jul 3 16:34:22 2006 @@ -0,0 +1,191 @@ +package org.apache.maven.doxia.plugin; + +import org.apache.maven.doxia.book.BookDoxia; +import org.apache.maven.doxia.book.BookDoxiaException; +import org.apache.maven.doxia.book.InvalidBookDescriptorException; +import org.apache.maven.doxia.book.services.validation.ValidationResult; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +/** + * @goal render-books + * + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class DoxiaRenderBooksMojo + extends AbstractMojo +{ + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + /** + * @parameter + */ + private List books; + + /** + * @parameter expression="${basedir}" + */ + private File basedir; + + /** + * @parameter expression="${project.reporting.outputDirectory}" + */ + private File outputDirectory; + + /** + * @component + */ + private BookDoxia bookDoxia; + + private static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public void execute() + throws MojoExecutionException, MojoFailureException + { + for ( Iterator it = books.iterator(); it.hasNext(); ) + { + Book book = (Book) it.next(); + + // ---------------------------------------------------------------------- + // Validate + // ---------------------------------------------------------------------- + + if ( StringUtils.isEmpty( book.getDirectory() ) ) + { + throw new MojoFailureException( "Invalid configuration: The book is required to have a descriptor set." ); + } + + if ( StringUtils.isEmpty( book.getDirectory() ) ) + { + throw new MojoFailureException( "Invalid configuration: The book is required to have a directory set." ); + } + + if ( book.getFormats() == null || book.getFormats().size() == 0 ) + { + throw new MojoFailureException( "Invalid configuration: The book is required to have at least one format set." ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + File descriptor = new File( basedir, book.getDescriptor() ); + + String includes = ""; + + if ( book.getIncludes() != null ) + { + for ( Iterator j = book.getIncludes().iterator(); j.hasNext(); ) + { + String include = (String) j.next(); + + includes += include + ","; + } + } + else + { + includes = "**/*"; + } + + String excludes = ""; + + if ( book.getExcludes() != null ) + { + for ( Iterator j = book.getExcludes().iterator(); j.hasNext(); ) + { + String exclude = (String) j.next(); + + excludes += exclude + ","; + } + } + + // ---------------------------------------------------------------------- + // Find all the files to pass to the renderer. + // ---------------------------------------------------------------------- + + getLog().debug( "Locating files to include in the book:" ); + getLog().debug( "Basedir: " + basedir ); + getLog().debug( "Includes: " + includes ); + getLog().debug( "Excludes: " + excludes ); + + List files; + + try + { + files = FileUtils.getFiles( new File( basedir, book.getDirectory() ), includes, excludes ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error while looking for input files. " + + "Basedir=" + basedir.getAbsolutePath() + ", " + + "includes=" + includes + ", " + + "excludes=" + excludes, e ); + } + + for ( Iterator j = book.getFormats().iterator(); j.hasNext(); ) + { + String format = (String) j.next(); + + try + { + bookDoxia.renderBook( descriptor, format, files, new File( outputDirectory, format ) ); + } + catch ( InvalidBookDescriptorException e ) + { + throw new MojoFailureException( "Invalid book descriptor: " + LINE_SEPARATOR + + formatResult( e.getValidationResult() ) ); + } + catch ( BookDoxiaException e ) + { + throw new MojoExecutionException( "Error while generating book in format '" + format + "'.", e ); + } + } + } + } + + private String formatResult( ValidationResult result ) + { + StringBuffer buffer = new StringBuffer(); + + if ( result.getErrors().size() > 0 ) + { + buffer.append( "Validation errors:" ); + + for ( Iterator it = result.getErrors().iterator(); it.hasNext(); ) + { + String error = (String) it.next(); + + buffer.append( LINE_SEPARATOR ).append( " " ).append( error ); + } + } + + if ( result.getWarnings().size() > 0 ) + { + buffer.append( "Validation warnings:" ); + + for ( Iterator it = result.getWarnings().iterator(); it.hasNext(); ) + { + String error = (String) it.next(); + + buffer.append( LINE_SEPARATOR ).append( " " ).append( error ); + } + } + + return buffer.toString(); + } +} From doxia-commitssimpsonnathan@example.org Mon Jul 03 23:35:16 2006 Return-Path: <doxia-commitssimpsonnathan@example.org> Delivered-To: simpsonnathan@example.org Received: (qmail 8806 invoked from network); 3 Jul 2006 23:35:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 3 Jul 2006 23:35:16 -0000 Received: (qmail 72836 invoked by uid 500); 3 Jul 2006 23:35:16 -0000 Delivered-To: simpsonnathan@example.org Received: (qmail 72813 invoked by uid 500); 3 Jul 2006 23:35:16 -0000 Mailing-List: contact simpsonnathan@example.org; run by ezmlm Precedence: bulk List-Help: <mailto:simpsonnathan@example.org> List-Unsubscribe: <mailto:simpsonnathan@example.org> List-Post: <mailto:simpsonnathan@example.org> List-Id: <doxia-commits.maven.apache.org> Reply-To: simpsonnathan@example.org Delivered-To: mailing list simpsonnathan@example.org Received: (qmail 72802 invoked by uid 99); 3 Jul 2006 23:35:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:35:16 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2006 16:35:14 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 5607B1A983E; Mon, 3 Jul 2006 16:34:54 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418877 - in /maven/doxia/trunk/doxia-sandbox/doxia-book/src/main: java/org/apache/maven/doxia/book/services/renderer/ java/org/apache/maven/doxia/book/services/renderer/latex/ java/org/apache/maven/doxia/book/services/validation/ modello/ Date: Mon, 03 Jul 2006 23:34:53 -0000 To: simpsonnathan@example.org From: simpsonnathan@example.org X-Mailer: svnmailer-1.0.8 Message-Id: <simpsonnathan@example.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trygvis Date: Mon Jul 3 16:34:53 2006 New Revision: 418877 URL: http://svn.apache.org/viewvc?rev=418877&view=rev Log: o More work done. Adding LaTeX book sink. Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/LatexBookSink.java Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/validation/DefaultBookValidator.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/modello/book.mdo Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java?rev=418877&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java Mon Jul 3 16:34:53 2006 @@ -0,0 +1,198 @@ +package org.apache.maven.doxia.book.services.renderer; + +import org.apache.maven.doxia.book.BookDoxiaException; +import org.apache.maven.doxia.book.services.renderer.latex.LatexBookSink; +import org.apache.maven.doxia.book.context.BookContext; +import org.apache.maven.doxia.book.model.Book; +import org.apache.maven.doxia.book.model.Chapter; +import org.apache.maven.doxia.book.model.Section; +import org.apache.maven.doxia.module.latex.LatexSink; +import org.apache.maven.doxia.parser.manager.ParserNotFoundException; +import org.apache.maven.doxia.parser.ParseException; +import org.apache.maven.doxia.Doxia; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.IOUtil; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.FileReader; +import java.io.FileNotFoundException; +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +/** + * @plexus.component role-hint="latex" + * + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class LatexBookRenderer + implements BookRenderer +{ + /** + * @plexus.requirement + */ + private Doxia doxia; + + // ---------------------------------------------------------------------- + // BookRenderer Implementatino + // ---------------------------------------------------------------------- + + public void renderBook( BookContext context ) + throws BookDoxiaException + { + Book book = context.getBook(); + + if ( !context.getOutputDirectory().exists() ) + { + if ( !context.getOutputDirectory().mkdirs() ) + { + throw new BookDoxiaException( + "Could not make directory: " + context.getOutputDirectory().getAbsolutePath() + "." ); + } + } + + File bookFile = new File( context.getOutputDirectory(), book.getId() + ".tex" ); + + FileWriter fileWriter = null; + + try + { + fileWriter = new FileWriter( bookFile ); + + PrintWriter writer = new PrintWriter( fileWriter ); + + writeBook( book, context, writer ); + } + catch ( IOException e ) + { + throw new BookDoxiaException( "Error while opening file.", e ); + } + finally + { + IOUtil.close( fileWriter ); + } + } + + // ---------------------------------------------------------------------- + // Private + // ---------------------------------------------------------------------- + + private static class SectionInfo + { + private String id; + + private String title; + } + + private void writeBook( Book book, BookContext context, PrintWriter writer ) + throws IOException, BookDoxiaException + { + // ---------------------------------------------------------------------- + // Process all the section documents and collect their names + // ---------------------------------------------------------------------- + + Map sectionInfos = new HashMap(); + + for ( Iterator it = book.getChapters().iterator(); it.hasNext(); ) + { + Chapter chapter = (Chapter) it.next(); + + for ( Iterator j = chapter.getSections().iterator(); j.hasNext(); ) + { + Section section = (Section) j.next(); + + SectionInfo info = writeSection( section, context ); + + sectionInfos.put( info.id, info ); + } + } + + // ---------------------------------------------------------------------- + // Write the main .tex file + // ---------------------------------------------------------------------- + + writer.println( "\\documentclass{book}" ); + writer.println( "\\title{" + book.getTitle() + "}"); + + if ( StringUtils.isNotEmpty( book.getAuthor() ) ) + { + writer.println( "\\author{" + book.getAuthor() + "}" ); + } + + if ( StringUtils.isNotEmpty( book.getDate() ) ) + { + writer.println( "\\author{" + book.getDate() + "}" ); + } + + writer.print( IOUtil.toString( LatexSink.getDefaultSinkCommands() ) ); + writer.print( IOUtil.toString( LatexSink.getDefaultPreamble() ) ); + writer.println( "\\begin{document}"); + writer.println( "\\maketitle"); + writer.println( "\\tableofcontents"); +// writer.println( "\\listoffigures"); + + for ( Iterator it = book.getChapters().iterator(); it.hasNext(); ) + { + Chapter chapter = (Chapter) it.next(); + + writer.println( "\\chapter{" + chapter.getTitle() + "}" ); + + for ( Iterator j = chapter.getSections().iterator(); j.hasNext(); ) + { + Section section = (Section) j.next(); + + SectionInfo info = (SectionInfo) sectionInfos.get( section.getId() ); + + writer.println( "\\input{" + info.id + "}"); + } + } + + writer.println( "\\end{document}"); + } + + private SectionInfo writeSection( Section section, BookContext context ) + throws IOException, BookDoxiaException + { + File file = new File( context.getOutputDirectory(), (section.getId() + ".tex") ); + + FileWriter writer = new FileWriter( file ); + + LatexBookSink sink = new LatexBookSink( writer ); + + BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() ); + + if ( bookFile == null ) + { + throw new BookDoxiaException( "No document that matches section with id=" + section.getId() + "." ); + } + + try + { + doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink ); + } + catch ( ParserNotFoundException e ) + { + throw new BookDoxiaException( "Parser not found: " + bookFile.getParserId() + ".", e ); + } + catch ( ParseException e ) + { + throw new BookDoxiaException( "Error while parsing document: " + bookFile.getFile().getAbsolutePath() + ".", e ); + } + catch ( FileNotFoundException e ) + { + throw new BookDoxiaException( "Could not find document: " + bookFile.getFile().getAbsolutePath() + ".", e ); + } + + SectionInfo info = new SectionInfo(); + info.id = section.getId(); + info.title = sink.getTitle(); + + return info; + } +} Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/LatexBookSink.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/LatexBookSink.java?rev=418877&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/LatexBookSink.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/latex/LatexBookSink.java Mon Jul 3 16:34:53 2006 @@ -0,0 +1,70 @@ +package org.apache.maven.doxia.book.services.renderer.latex; + +import org.apache.maven.doxia.module.latex.LatexSink; + +import java.io.Writer; +import java.io.IOException; + +/** + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class LatexBookSink + extends LatexSink +{ + private String text; + + private String title; + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public LatexBookSink( Writer out ) + throws IOException + { + super( out, null, null, true ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + protected String getDocumentStart() + { + return ""; +// return "\\documentclass{book}"; + } + + protected String getDocumentBegin() + { + return null; + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public void text( String text ) + { + this.text = text; + + super.text( text ); + } + + public void title_() + { + super.title_(); + + this.title = text; + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public String getTitle() + { + return title; + } +} Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/validation/DefaultBookValidator.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/validation/DefaultBookValidator.java?rev=418877&r1=418876&r2=418877&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/validation/DefaultBookValidator.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/validation/DefaultBookValidator.java Mon Jul 3 16:34:53 2006 @@ -43,6 +43,8 @@ Chapter chapter = (Chapter) it.next(); validateChapter( result, chapter ); + + // TODO: Validate the chapter id } } @@ -62,9 +64,14 @@ return; } + if ( StringUtils.isEmpty( chapter.getTitle() ) ) + { + result.getErrors().add( "Missing title. Chapter id: " + chapter.getId() ); + } + if ( chapter.getSections().size() == 0 ) { - result.getErrors().add( "Each chapter has to contain at least one section. Chapter id: " + chapter.getId() ); + result.getErrors().add( "Chapter doesn't have any sections. Chapter id: " + chapter.getId() ); } } } Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/modello/book.mdo URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/modello/book.mdo?rev=418877&r1=418876&r2=418877&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/modello/book.mdo (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/modello/book.mdo Mon Jul 3 16:34:53 2006 @@ -23,7 +23,17 @@ <identifier>true</identifier> </field> <field> - <name>name</name> + <name>title</name> + <version>1.0.0</version> + <type>String</type> + </field> + <field> + <name>author</name> + <version>1.0.0</version> + <type>String</type> + </field> + <field> + <name>date</name> <version>1.0.0</version> <type>String</type> </field> From doxia-commitssimpsonnathan@example.org Tue Jul 11 14:44:18 2006 Return-Path: <doxia-commitssimpsonnathan@example.org> Delivered-To: simpsonnathan@example.org Received: (qmail 82403 invoked from network); 11 Jul 2006 14:44:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 11 Jul 2006 14:44:16 -0000 Received: (qmail 75164 invoked by uid 500); 11 Jul 2006 14:44:06 -0000 Delivered-To: simpsonnathan@example.org Received: (qmail 74827 invoked by uid 500); 11 Jul 2006 14:44:04 -0000 Mailing-List: contact simpsonnathan@example.org; run by ezmlm Precedence: bulk List-Help: <mailto:simpsonnathan@example.org> List-Unsubscribe: <mailto:simpsonnathan@example.org> List-Post: <mailto:simpsonnathan@example.org> List-Id: <doxia-commits.maven.apache.org> Reply-To: simpsonnathan@example.org Delivered-To: mailing list simpsonnathan@example.org Received: (qmail 74748 invoked by uid 99); 11 Jul 2006 14:44:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jul 2006 07:44:03 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jul 2006 07:44:00 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B76191A981A; Tue, 11 Jul 2006 07:43:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r420875 - in /maven/doxia/trunk: ./ doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/ doxia-sandbox/ doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/ doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxi... Date: Tue, 11 Jul 2006 14:43:36 -0000 To: simpsonnathan@example.org From: simpsonnathan@example.org X-Mailer: svnmailer-1.0.8 Message-Id: <simpsonnathan@example.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trygvis Date: Tue Jul 11 07:43:35 2006 New Revision: 420875 URL: http://svn.apache.org/viewvc?rev=420875&view=rev Log: o Adding a Xdoc sink so it's possible to include the content directly in a generated site. o Changed the Doxia book Maven plugin to use the target/generated-site directory for output as default. o Implementing the Indexing service. This should be changed in the future to just be a step in a pre-processing step of all the documents before rendering them. o Fixing the Xdoc so that it would write out the <xxxsection> start elements. Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookIndex.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java - copied, changed from r420511, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/TOCEntry.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/BookIo.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/DefaultBookIo.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/context/ maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/context/IndexEntryTest.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/ maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/ maven/doxia/trunk/doxia-sandbox/pom.xml Removed: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/TOCEntry.java Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java maven/doxia/trunk/doxia-sandbox/ (props changed) maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/DefaultBookDoxia.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookContext.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/DefaultBookIndexer.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/BookRendererTest.java maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/resources/book-1/section-1.apt maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/resources/book-1/section-2.apt maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/resources/book-1/section-3.apt maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/resources/book-1/section-4.apt maven/doxia/trunk/doxia-sandbox/doxia-editor/pom.xml maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/pom.xml maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java maven/doxia/trunk/pom.xml Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=420875&r1=420874&r2=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java (original) +++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java Tue Jul 11 07:43:35 2006 @@ -29,18 +29,17 @@ * * @author <a href="mailto:simpsonnathan@example.org">James Taylor</a> * @version $Id:XdocSink.java 348605 2005-11-24 12:02:44 +1100 (Thu, 24 Nov 2005) brett $ - * @componentx */ public class XdocSink extends SinkAdapter { - private static final String EOL = System.getProperty( "line.separator" ); + protected static final String EOL = System.getProperty( "line.separator" ); - private LineBreaker out; + protected LineBreaker out; - private StringBuffer buffer = new StringBuffer(); + protected StringBuffer buffer = new StringBuffer(); - private boolean headFlag; + protected boolean headFlag; private int itemFlag; @@ -141,57 +140,72 @@ public void section1() { - section = "section"; + markup( "<section name=\"" ); } - public void section2() + public void sectionTitle1_() { - section = "subsection"; + markup( "\">" ); } - public void section3() + public void section1_() { - section = "subsection"; + markup( "</section>" ); } - public void section4() + public void section2() { - section = "subsection"; + markup( "<subsection name=\"" ); } - public void section5() + public void sectionTitle2_() { - section = "subsection"; + sectionTitle1_(); } - public void sectionTitle() + public void section2_() { - markup( "<" + section + " name=\"" ); + markup( "</subsection>" ); } - public void sectionTitle_() + public void section3() { - markup( "\">" ); + markup( "<subsection name=\"" ); } - public void section1_() + public void sectionTitle3_() { - markup( "</section>" ); + sectionTitle1_(); } - public void section2_() + public void section3_() { markup( "</subsection>" ); } - public void section3_() + public void section4() { - markup( "</subsection>" ); + markup( "<subsection name=\"" ); + } + + public void sectionTitle4_() + { + sectionTitle1_(); } public void section4_() { markup( "</subsection>" ); + } + + public void section5() + { + markup( "<subsection name=\"" ); + } + + public void sectionTitle5_() + { + sectionTitle1_(); } public void section5_() Propchange: maven/doxia/trunk/doxia-sandbox/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Tue Jul 11 07:43:35 2006 @@ -0,0 +1,8 @@ +target +*~ +*.log +.classpath +.project +*.ipr +*.iws +*.iml Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/DefaultBookDoxia.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/DefaultBookDoxia.java?rev=420875&r1=420874&r2=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/DefaultBookDoxia.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/DefaultBookDoxia.java Tue Jul 11 07:43:35 2006 @@ -1,26 +1,18 @@ package org.apache.maven.doxia.book; import org.apache.maven.doxia.book.context.BookContext; -import org.apache.maven.doxia.book.context.TOCEntry; +import org.apache.maven.doxia.book.context.IndexEntry; import org.apache.maven.doxia.book.model.Book; -import org.apache.maven.doxia.book.model.io.xpp3.BookXpp3Reader; import org.apache.maven.doxia.book.services.indexer.BookIndexer; +import org.apache.maven.doxia.book.services.io.BookIo; import org.apache.maven.doxia.book.services.renderer.BookRenderer; import org.apache.maven.doxia.book.services.validation.BookValidator; import org.apache.maven.doxia.book.services.validation.ValidationResult; -import org.apache.maven.doxia.site.module.SiteModule; -import org.apache.maven.doxia.site.module.manager.SiteModuleManager; import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.TreeMap; /** * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> @@ -34,6 +26,11 @@ /** * @plexus.requirement */ + private BookIo bookIo; + + /** + * @plexus.requirement + */ private BookValidator bookValidator; /** @@ -46,11 +43,6 @@ */ private Map bookRenderers; - /** - * @plexus.requirement - */ - private SiteModuleManager siteModuleManager; - // ---------------------------------------------------------------------- // BookDoxia Implementation // ---------------------------------------------------------------------- @@ -58,20 +50,7 @@ public void renderBook( File bookDescriptor, String bookRendererId, List files, File outputDirectory ) throws BookDoxiaException { - Book book; - - try - { - book = new BookXpp3Reader().read( new FileReader( bookDescriptor ), true ); - } - catch ( IOException e ) - { - throw new BookDoxiaException( "Error while reading book descriptor.", e ); - } - catch ( XmlPullParserException e ) - { - throw new BookDoxiaException( "Error while reading book descriptor.", e ); - } + Book book = bookIo.readBook( bookDescriptor ); // ---------------------------------------------------------------------- // @@ -94,52 +73,11 @@ context.setOutputDirectory( outputDirectory ); - context.setRootTOCEntry( new TOCEntry() ); - - // ---------------------------------------------------------------------- + // ----------------------------------------------------------------------- // - // ---------------------------------------------------------------------- - - Collection siteModules = siteModuleManager.getSiteModules(); - - for ( Iterator it = siteModules.iterator(); it.hasNext(); ) - { - SiteModule siteModule = (SiteModule) it.next(); - - String extension = siteModule.getExtension(); - - for ( Iterator j = files.iterator(); j.hasNext(); ) - { - File file = (File) j.next(); - - String name = file.getName(); - - if ( name.endsWith( extension ) ) - { - name = name.substring( 0, name.length() - siteModule.getExtension().length() - 1 ); - - BookContext.BookFile bookFile = new BookContext.BookFile( file, siteModule.getParserId() ); + // ----------------------------------------------------------------------- - context.getFiles().put( name, bookFile ); - } - } - } - - if ( getLogger().isDebugEnabled() ) - { - getLogger().debug( "Dumping document <-> id mapping:" ); - - Map map = new TreeMap( context.getFiles() ); - - for ( Iterator it = map.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry entry = (Map.Entry) it.next(); - - BookContext.BookFile file = (BookContext.BookFile) entry.getValue(); - - getLogger().debug( " " + entry.getKey() + "=" + file.getFile() + ", parser: " + file.getParserId() ); - } - } + bookIo.loadFiles( context, files ); // ---------------------------------------------------------------------- // Generate indexes Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookContext.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookContext.java?rev=420875&r1=420874&r2=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookContext.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookContext.java Tue Jul 11 07:43:35 2006 @@ -2,7 +2,6 @@ import org.apache.maven.doxia.book.model.Book; -import java.util.List; import java.util.Map; import java.util.HashMap; import java.io.File; @@ -19,7 +18,7 @@ private File outputDirectory; - private TOCEntry rootTOCEntry; + private BookIndex index; // ---------------------------------------------------------------------- // @@ -87,13 +86,13 @@ this.outputDirectory = outputDirectory; } - public TOCEntry getRootTOCEntry() + public BookIndex getIndex() { - return rootTOCEntry; + return index; } - public void setRootTOCEntry( TOCEntry rootTOCEntry ) + public void setIndex( BookIndex index ) { - this.rootTOCEntry = rootTOCEntry; + this.index = index; } } Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookIndex.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookIndex.java?rev=420875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookIndex.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/BookIndex.java Tue Jul 11 07:43:35 2006 @@ -0,0 +1,14 @@ +package org.apache.maven.doxia.book.context; + +/** + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class BookIndex + extends IndexEntry +{ + public BookIndex() + { + super( "book" ); + } +} Copied: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java (from r420511, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/TOCEntry.java) URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java?p2=maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java&p1=maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/TOCEntry.java&r1=420511&r2=420875&rev=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/TOCEntry.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/context/IndexEntry.java Tue Jul 11 07:43:35 2006 @@ -1,28 +1,59 @@ package org.apache.maven.doxia.book.context; +import org.codehaus.plexus.util.StringUtils; + import java.util.List; import java.util.ArrayList; +import java.util.Iterator; +import java.util.Collections; /** * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> * @version $Id$ */ -public class TOCEntry +public class IndexEntry { - private String sectionId; + private IndexEntry parent; + + private String id; private String title; - private List childEntries; + private List childEntries = new ArrayList(); + + private static final String EOL = System.getProperty( "line.separator" ); - public String getSectionId() + public IndexEntry( String id ) { - return sectionId; + this.id = id; } - public void setSectionId( String sectionId ) + public IndexEntry( IndexEntry parent, String id ) { - this.sectionId = sectionId; + if ( parent == null ) + { + throw new NullPointerException( "parent cannot be null." ); + } + + if ( id == null ) + { + throw new NullPointerException( "parent cannot be null." ); + } + + this.parent = parent; + this.id = id; + + parent.childEntries.add( this ); + } + + public IndexEntry getParent() + { + return parent; + } + + public String getId() + { + return id; } public String getTitle() @@ -37,16 +68,128 @@ public List getChildEntries() { + return Collections.unmodifiableList( childEntries ); + } + + public void setChildEntries( List childEntries ) + { if ( childEntries == null ) { childEntries = new ArrayList(); } - return childEntries; + this.childEntries = childEntries; } - public void setChildEntries( List childEntries ) + // ----------------------------------------------------------------------- + // Utils + // ----------------------------------------------------------------------- + + public IndexEntry getNextEntry() { - this.childEntries = childEntries; + if ( parent == null ) + { + return null; + } + + List entries = parent.getChildEntries(); + + int index = entries.indexOf( this ); + + if ( index + 1 >= entries.size() ) + { + return null; + } + + return (IndexEntry) entries.get( index + 1 ); + } + + public IndexEntry getPrevEntry() + { + if ( parent == null ) + { + return null; + } + + List entries = parent.getChildEntries(); + + int index = entries.indexOf( this ); + + if ( index == 0 ) + { + return null; + } + + return (IndexEntry) entries.get( index - 1 ); + } + + public IndexEntry getFirstEntry() + { + List entries = getChildEntries(); + + if ( entries.size() == 0 ) + { + return null; + } + else + { + return (IndexEntry) entries.get( 0 ); + } + } + + public IndexEntry getRootEntry() + { + List entries = getChildEntries(); + + if ( entries.size() == 0 ) + { + return null; + } + else if ( entries.size() > 1 ) + { + throw new RuntimeException( "This index has more than one root entry" ); + } + else + { + return (IndexEntry) entries.get( 0 ); + } + } + + // ----------------------------------------------------------------------- + // Object Overrides + // ----------------------------------------------------------------------- + + public String toString() + { + return toString( 0 ); + } + + public String toString( int depth ) + { + StringBuffer message = new StringBuffer(); + + message.append( "Id: " ).append( id ); + + if ( StringUtils.isNotEmpty( title ) ) + { + message.append( ", title: " ).append( title ); + } + + message.append( EOL ); + + String indent = ""; + + for( int i = 0; i < depth; i++ ) { + indent += " "; + } + + for ( Iterator it = getChildEntries().iterator(); it.hasNext(); ) + { + IndexEntry entry = (IndexEntry) it.next(); + + message.append( indent ).append( entry.toString( depth + 1 ) ); + } + + return message.toString(); } } Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java?rev=420875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java Tue Jul 11 07:43:35 2006 @@ -0,0 +1,98 @@ +package org.apache.maven.doxia.book.services.indexer; + +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.apache.maven.doxia.book.services.io.BookIo; +import org.apache.maven.doxia.book.model.Book; +import org.apache.maven.doxia.book.context.BookContext; +import org.apache.maven.doxia.book.context.IndexEntry; + +/** + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class BookIndexerTest + extends PlexusTestCase +{ + public void testBasic() + throws Exception + { + BookIo io = (BookIo) lookup( BookIo.ROLE ); + + BookIndexer indexer = (BookIndexer) lookup( BookIndexer.ROLE ); + + Book book = io.readBook( getTestFile( "src/test/resources/book-1.xml" ) ); + + BookContext context = new BookContext(); + + io.loadFiles( context, FileUtils.getFiles( getTestFile( "src/test/resources/book-1" ), "*.apt", "" ) ); + + indexer.indexBook( book, context ); + + IndexEntry root = context.getIndex(); + + assertNotNull( root ); + + assertEquals( 2, root.getChildEntries().size() ); + + IndexEntry c1 = assertIndexEntry( root, 0, "Chapter 1", "chapter-1", 2 ); + + // ----------------------------------------------------------------------- + // Section 1 + // ----------------------------------------------------------------------- + + IndexEntry s1 = assertIndexEntry( c1, 0, "Section 1", "section-1", 5 ); + + IndexEntry ss1 = assertIndexEntry( s1, 0, "Subsection 1", "subsection_1", 1 ); + + assertIndexEntry( ss1, 0, "Subsubsection 1", "subsubsection_1", 0 ); + + assertIndexEntry( s1, 1, "Subsection 2", "subsection_2", 0 ); + + assertIndexEntry( s1, 2, "Subsection 3", "subsection_3", 0 ); + + assertIndexEntry( s1, 3, "Subsection 4", "subsection_4", 0 ); + + // ----------------------------------------------------------------------- + // Section 2 + // ----------------------------------------------------------------------- + + IndexEntry s2 = assertIndexEntry( c1, 1, "Section 2", "section-2", 1 ); + + assertIndexEntry( s2, 0, "Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC", + "section_1.10.32_of_\"de_finibus_bonorum_et_malorum\",_written_by_cicero_in_45_bc", 0 ); + + // ----------------------------------------------------------------------- + // Chapter 2 + // ----------------------------------------------------------------------- + + IndexEntry c2 = assertIndexEntry( root, 1, "Chapter 2", "chapter-2", 2 ); + + IndexEntry s3 = assertIndexEntry( c2, 0, "Section 3", "section-3", 1 ); + + assertIndexEntry( s3, 0, "1914 translation by H. Rackham", "1914_translation_by_h._rackham", 0 ); + + IndexEntry s4 = assertIndexEntry( c2, 1, "Section 4", "section-4", 1 ); + + assertIndexEntry( s4, 0, "Section 1.10.33 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC", + "section_1.10.33_of_\"de_finibus_bonorum_et_malorum\",_written_by_cicero_in_45_bc", 0 ); + } + + private IndexEntry assertIndexEntry( IndexEntry parent, int childIndex, String title, String id, int childCount ) + { + assertTrue( "parent: " + parent.getId() + ", " + + "required count: " + childCount + ", " + + "actual count: " + parent.getChildEntries().size(), + childIndex < parent.getChildEntries().size() ); + + IndexEntry indexEntry = (IndexEntry) parent.getChildEntries().get( childIndex ); + + assertEquals( title, indexEntry.getTitle() ); + + assertEquals( id, indexEntry.getId() ); + + assertEquals( childCount, indexEntry.getChildEntries().size() ); + + return indexEntry; + } +} Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java?rev=420875&r1=420874&r2=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java Tue Jul 11 07:43:35 2006 @@ -1,11 +1,10 @@ package org.apache.maven.doxia.book.services.indexer; import org.apache.maven.doxia.sink.SinkAdapter; -import org.apache.maven.doxia.book.context.BookContext; -import org.apache.maven.doxia.book.context.TOCEntry; -import org.apache.maven.doxia.book.BookDoxiaException; +import org.apache.maven.doxia.book.context.IndexEntry; import java.util.List; +import java.util.Stack; /** * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> @@ -22,6 +21,7 @@ private final static int TYPE_DEFINED_TERM = 6; private final static int TYPE_FIGURE = 7; private final static int TYPE_TABLE = 8; + private final static int TITLE = 9; private int type; @@ -29,91 +29,149 @@ // // ---------------------------------------------------------------------- - private BookContext bookContext; + private String title; - public BookIndexingSink( BookContext bookContext ) + private Stack stack = new Stack(); + + public BookIndexingSink( IndexEntry sectionEntry ) + { + stack.push( sectionEntry ); + } + + public String getTitle() { - this.bookContext = bookContext; + return title; } // ---------------------------------------------------------------------- // Sink Overrides // ---------------------------------------------------------------------- - public void sectionTitle1_() + public void title() + { + super.title(); + + type = TITLE; + } + + public void sectionTitle1() { type = TYPE_SECTION_1; } - public void sectionTitle2_() + public void section1_() + { + pop(); + } + + public void sectionTitle2() { type = TYPE_SECTION_2; } - public void sectionTitle3_() + public void section2_() + { + pop(); + } + + public void sectionTitle3() { type = TYPE_SECTION_3; } - public void sectionTitle4_() + public void section3_() { - type = TYPE_SECTION_4; + pop(); } - public void sectionTitle5_() + public void sectionTitle4() { - type = TYPE_SECTION_5; + type = TYPE_SECTION_4; } - public void definedTerm_() + public void section4_() { - type = TYPE_DEFINED_TERM; + pop(); } - public void figureCaption_() + public void sectionTitle5() { - type = TYPE_FIGURE; + type = TYPE_SECTION_5; } - public void tableCaption_() + public void section5_() { - type = TYPE_TABLE; + pop(); } +// public void definedTerm() +// { +// type = TYPE_DEFINED_TERM; +// } +// +// public void figureCaption() +// { +// type = TYPE_FIGURE; +// } +// +// public void tableCaption() +// { +// type = TYPE_TABLE; +// } + public void text( String text ) { - if ( bookContext == null ) - { - throw new RuntimeException( new BookDoxiaException( "The book context has to be set first." ) ); - } - - TOCEntry entry = new TOCEntry(); - entry.setTitle( text ); + IndexEntry entry; switch( type ) { - case TYPE_SECTION_1: addSection( 0, entry ); break; - case TYPE_SECTION_2: addSection( 1, entry ); break; - case TYPE_SECTION_3: addSection( 2, entry ); break; - case TYPE_SECTION_4: addSection( 3, entry ); break; - case TYPE_SECTION_5: addSection( 4, entry ); break; + case TITLE: + this.title = text; + break; + case TYPE_SECTION_1: + case TYPE_SECTION_2: + case TYPE_SECTION_3: + case TYPE_SECTION_4: + case TYPE_SECTION_5: + // ----------------------------------------------------------------------- + // Sanitize the id. The most important step is to remove any blanks + // ----------------------------------------------------------------------- + + String id = text.toLowerCase().replace( ' ', '_' ); + + // ----------------------------------------------------------------------- + // + // ----------------------------------------------------------------------- + + entry = new IndexEntry( peek(), id ); + + entry.setTitle( text ); + + push( entry ); + break; + // Dunno how to handle these yet case TYPE_DEFINED_TERM: case TYPE_FIGURE: case TYPE_TABLE: } + + type = 0; } - private void addSection( int depth, TOCEntry entry ) + public void push( IndexEntry entry ) { - TOCEntry parent = bookContext.getRootTOCEntry(); - - for ( int i = 0; i < depth; i++ ) - { - List entries = parent.getChildEntries(); +// System.out.println( "push: " + entry.getId() ); + stack.push( entry ); + } - parent = (TOCEntry) entries.get( entries.size() - 1 ); - } + public void pop() + { +// System.out.println( "pop: " + peek().getId() ); + stack.pop(); + } - parent.getChildEntries().add( entry ); + public IndexEntry peek() + { + return (IndexEntry) stack.peek(); } } Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/DefaultBookIndexer.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/DefaultBookIndexer.java?rev=420875&r1=420874&r2=420875&view=diff ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/DefaultBookIndexer.java (original) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/DefaultBookIndexer.java Tue Jul 11 07:43:35 2006 @@ -1,6 +1,8 @@ package org.apache.maven.doxia.book.services.indexer; import org.apache.maven.doxia.book.context.BookContext; +import org.apache.maven.doxia.book.context.IndexEntry; +import org.apache.maven.doxia.book.context.BookIndex; import org.apache.maven.doxia.book.model.Book; import org.apache.maven.doxia.book.model.Chapter; import org.apache.maven.doxia.book.model.Section; @@ -36,32 +38,38 @@ public void indexBook( Book book, BookContext bookContext ) throws BookDoxiaException { - BookIndexingSink sink = new BookIndexingSink( bookContext ); + BookIndex index = new BookIndex(); for ( Iterator it = book.getChapters().iterator(); it.hasNext(); ) { Chapter chapter = (Chapter) it.next(); - indexChapter( bookContext, chapter, sink ); + indexChapter( bookContext, index, chapter ); } + + bookContext.setIndex( index ); } // ---------------------------------------------------------------------- // Private // ---------------------------------------------------------------------- - private void indexChapter( BookContext bookContext, Chapter chapter, BookIndexingSink sink ) + private void indexChapter( BookContext context, IndexEntry bookEntry, Chapter chapter ) throws BookDoxiaException { + IndexEntry chapterEntry = new IndexEntry( bookEntry, chapter.getId( ) ); + + chapterEntry.setTitle( chapter.getTitle() ); + for ( Iterator it = chapter.getSections().iterator(); it.hasNext(); ) { Section section = (Section) it.next(); - indexSection( bookContext, section, sink ); + indexSection( context, chapterEntry, section ); } } - private void indexSection( BookContext bookContext, Section section, BookIndexingSink sink ) + private void indexSection( BookContext bookContext, IndexEntry chapterEntry, Section section ) throws BookDoxiaException { BookContext.BookFile bookFile = (BookContext.BookFile) bookContext.getFiles().get( section.getId() ); @@ -75,6 +83,10 @@ // // ---------------------------------------------------------------------- + IndexEntry sectionEntry = new IndexEntry( chapterEntry, section.getId() ); + + BookIndexingSink sink = new BookIndexingSink( sectionEntry ); + try { doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink ); @@ -91,5 +103,7 @@ { throw new BookDoxiaException( "Could not find document: " + bookFile.getFile().getAbsolutePath() + ".", e ); } + + sectionEntry.setTitle( sink.getTitle() ); } } Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/BookIo.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/BookIo.java?rev=420875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/BookIo.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/BookIo.java Tue Jul 11 07:43:35 2006 @@ -0,0 +1,22 @@ +package org.apache.maven.doxia.book.services.io; + +import org.apache.maven.doxia.book.model.Book; +import org.apache.maven.doxia.book.BookDoxiaException; +import org.apache.maven.doxia.book.context.BookContext; + +import java.io.File; +import java.util.List; + +/** + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public interface BookIo +{ + String ROLE = BookIo.class.getName(); + + Book readBook( File bookDescriptor ) + throws BookDoxiaException; + + void loadFiles( BookContext context, List files ); +} Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/DefaultBookIo.java URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/DefaultBookIo.java?rev=420875&view=auto ============================================================================== --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/DefaultBookIo.java (added) +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/io/DefaultBookIo.java Tue Jul 11 07:43:35 2006 @@ -0,0 +1,104 @@ +package org.apache.maven.doxia.book.services.io; + +import org.apache.maven.doxia.book.model.io.xpp3.BookXpp3Reader; +import org.apache.maven.doxia.book.model.Book; +import org.apache.maven.doxia.book.BookDoxiaException; +import org.apache.maven.doxia.book.context.BookContext; +import org.apache.maven.doxia.site.module.SiteModule; +import org.apache.maven.doxia.site.module.manager.SiteModuleManager; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +import java.io.FileReader; +import java.io.IOException; +import java.io.File; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; +import java.util.List; + +/** + * @plexus.component + * + * @author <a href="mailto:simpsonnathan@example.org">Trygve Laugst&oslash;l</a> + * @version $Id$ + */ +public class DefaultBookIo + extends AbstractLogEnabled + implements BookIo +{ + /** + * @plexus.requirement + */ + private SiteModuleManager siteModuleManager; + + // ----------------------------------------------------------------------- + // DefaultBookIo Implementation + // ----------------------------------------------------------------------- + + public Book readBook( File bookDescriptor ) + throws BookDoxiaException + { + try + { + return new BookXpp3Reader().read( new FileReader( bookDescriptor ), true ); + } + catch ( IOException e ) + { + throw new BookDoxiaException( "Error while reading book descriptor.", e ); + } + catch ( XmlPullParserException e ) + { + throw new BookDoxiaException( "Error while reading book descriptor.", e ); + } + } + + public void loadFiles( BookContext context, List files ) + { + // ---------------------------------------------------------------------- + // Find all the files, map the file names to ids + // ---------------------------------------------------------------------- + + Collection siteModules = siteModuleManager.getSiteModules(); + + for ( Iterator it = siteModules.iterator(); it.hasNext(); ) + { + SiteModule siteModule = (SiteModule) it.next(); + + String extension = siteModule.getExtension(); + + for ( Iterator j = files.iterator(); j.hasNext(); ) + { + File file = (File) j.next(); + + String name = file.getName(); + + if ( name.endsWith( extension ) ) + { + name = name.substring( 0, name.length() - siteModule.getExtension().length() - 1 ); + + BookContext.BookFile
{'source': 'Apache Software Foundation Public Mail Archives'}