Author: vsiveton
Date: Tue Jul 25 12:33:51 2006
New Revision: 425493
URL: http://svn.apache.org/viewvc?rev=425493&view=rev
Log:
o Replaced ITextBookRenderer by PDF and RTF renderers. <format>itext</format>
is deprecated in favor of <format>pdf</format>
o Corrected a toString() bug.
Added:
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/PdfBookRenderer.java
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/RtfBookRenderer.java
Removed:
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/ITextBookRenderer.java
Modified:
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-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java?rev=425493&view=auto
==============================================================================
---
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
(added)
+++
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
Tue Jul 25 12:33:51 2006
@@ -0,0 +1,293 @@
+package org.apache.maven.doxia.book.services.renderer;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.doxia.Doxia;
+import org.apache.maven.doxia.book.BookDoxiaException;
+import org.apache.maven.doxia.book.context.BookContext;
+import org.apache.maven.doxia.book.model.BookModel;
+import org.apache.maven.doxia.book.model.Chapter;
+import org.apache.maven.doxia.book.model.Section;
+import org.apache.maven.doxia.editor.io.PipelineSink;
+import org.apache.maven.doxia.module.itext.ITextSink;
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
+import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+
+/**
+ * Base class for <code>iText</code> renderer.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Trygve Laugstøl</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
+ * @version $Id$
+ */
+public abstract class AbstractITextBookRenderer
+ extends AbstractLogEnabled
+ implements BookRenderer
+{
+ /**
+ * @plexus.requirement
+ */
+ private Doxia doxia;
+
+ // ----------------------------------------------------------------------
+ // BookRenderer Implementation
+ // ----------------------------------------------------------------------
+
+ public void renderBook( BookContext context )
+ throws BookDoxiaException
+ {
+ BookModel 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() +
".xml" );
+
+ FileWriter fileWriter;
+
+ try
+ {
+ fileWriter = new FileWriter( bookFile );
+ }
+ catch ( IOException e )
+ {
+ throw new BookDoxiaException( "Error while opening file.", e );
+ }
+
+ //
----------------------------------------------------------------------
+ // Create the XML File
+ //
----------------------------------------------------------------------
+
+ PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( fileWriter,
"UTF-8", null );
+ writer.startElement( "itext" );
+ writer.addAttribute( "creationdate",
DateFormat.getDateTimeInstance().format( new Date() ) );
+ writer.addAttribute( "producer", "Doxia iText" );
+
+ // writer.startElement( "paragraph" );
+ // writer.addAttribute( "leading", "18.0" );
+ // writer.addAttribute( "font", "unknown" );
+ // writer.addAttribute( "align", "Default" );
+ // writer.writeText( "Please visit my" + System.getProperty(
"line.separator" ) );
+ //
+ // writer.startElement( "anchor" );
+ // writer.addAttribute( "leading", "18.0" );
+ // writer.addAttribute( "font", "Helvetica" );
+ // writer.addAttribute( "size", "12.0" );
+ // writer.addAttribute( "fontstyle", "normal, underline" );
+ // writer.addAttribute( "red", "0" );
+ // writer.addAttribute( "green", "0" );
+ // writer.addAttribute( "blue", "255" );
+ // writer.addAttribute( "name", "top" );
+ // writer.addAttribute( "reference",
"http://www.lowagie.com/iText/" );
+ //
+ // writer.startElement( "chunk" );
+ // writer.addAttribute( "font", "Helvetica" );
+ // writer.addAttribute( "size", "12.0" );
+ // writer.addAttribute( "fontstyle", "normal, underline" );
+ // writer.addAttribute( "red", "0" );
+ // writer.addAttribute( "green", "0" );
+ // writer.addAttribute( "blue", "255" );
+ // writer.writeText( "website (external reference)" );
+ // writer.endElement();
+ //
+ // writer.endElement(); // anchor
+ //
+ // writer.endElement(); // paragraph
+
+ // TODO: Write out TOC
+
+ for ( Iterator it = book.getChapters().iterator(); it.hasNext(); )
+ {
+ Chapter chapter = (Chapter) it.next();
+
+ renderChapter( writer, chapter, context );
+ }
+
+ writer.endElement(); // itext
+
+ try
+ {
+ fileWriter.close();
+ }
+ catch ( IOException e )
+ {
+ throw new BookDoxiaException( "Error while closing file.", e );
+ }
+
+ //
----------------------------------------------------------------------
+ // Render the XML to PDF
+ //
----------------------------------------------------------------------
+ File outputFile = new File( context.getOutputDirectory(), book.getId()
+ "." + getOutputExtension() );
+ try
+ {
+ renderXML( bookFile, outputFile );
+ }
+ catch ( IOException e )
+ {
+ throw new BookDoxiaException( "Error while rendering file", e );
+ }
+ }
+
+ /**
+ * Get the output extension supported
+ *
+ * @return the ouput extension supported
+ */
+ public abstract String getOutputExtension();
+
+ /**
+ * Generate an ouput file with the iText framework
+ *
+ * @param iTextFile
+ * @param iTextOutput
+ * @throws IOException if any
+ */
+ public abstract void renderXML( File iTextFile, File iTextOutput )
+ throws IOException;
+
+ // ----------------------------------------------------------------------
+ // Private
+ // ----------------------------------------------------------------------
+
+ private void renderChapter( PrettyPrintXMLWriter writer, Chapter chapter,
BookContext context )
+ throws BookDoxiaException
+ {
+ writer.startElement( "chapter" );
+ writer.addAttribute( "numberdepth", "1" );
+ writer.addAttribute( "depth", "1" );
+ writer.addAttribute( "indent", "1" );
+
+ startTitle( writer, "36.0", "Helvetica", "24.0", "normal", "255", "0",
"0" );
+ chunk( writer, chapter.getTitle(), "Helvetica", "24.0", "normal",
"255", "0", "0" );
+ writer.endElement(); // title
+
+ // writer.startElement( "sectioncontent" );
+ for ( Iterator it = chapter.getSections().iterator(); it.hasNext(); )
+ {
+ Section section = (Section) it.next();
+
+ renderSection( writer, section, context );
+ }
+ // writer.endElement(); // sectioncontent
+
+ writer.endElement(); // chapter
+ }
+
+ private void renderSection( PrettyPrintXMLWriter writer, Section section,
BookContext context )
+ throws BookDoxiaException
+ {
+ // writer.startElement( "section" );
+
+ //
----------------------------------------------------------------------
+ //
+ //
----------------------------------------------------------------------
+
+ 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() + "." );
+ }
+
+ //
----------------------------------------------------------------------
+ //
+ //
----------------------------------------------------------------------
+
+ Sink itextSink = new ITextSink( writer );
+
+ List pipeline = new ArrayList();
+ // pipeline.add( DebugSink.newInstance() );
+ pipeline.add( itextSink );
+ Sink sink = PipelineSink.newInstance( pipeline );
+
+ 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 );
+ }
+
+ // writer.endElement(); // section
+ }
+
+ private void startTitle( PrettyPrintXMLWriter writer, String leading,
String font, String size, String fontstyle,
+ String red, String green, String blue )
+ {
+ writer.startElement( "title" );
+ writer.addAttribute( "leading", leading );
+ writer.addAttribute( "font", font );
+ writer.addAttribute( "size", size );
+ writer.addAttribute( "fontstyle", fontstyle );
+ writer.addAttribute( "red", red );
+ writer.addAttribute( "green", green );
+ writer.addAttribute( "blue", blue );
+ }
+
+ private void chunk( PrettyPrintXMLWriter writer, String title, String
font, String size, String fontstyle,
+ String red, String green, String blue )
+ {
+ writer.startElement( "chunk" );
+ writer.addAttribute( "font", font );
+ writer.addAttribute( "size", size );
+ writer.addAttribute( "fontstyle", fontstyle );
+ writer.addAttribute( "red", red );
+ writer.addAttribute( "green", green );
+ writer.addAttribute( "blue", blue );
+ if ( StringUtils.isNotEmpty( title ) )
+ {
+ writer.writeText( title );
+ }
+ else
+ {
+ writer.writeText( "<Missing title>" );
+ }
+ writer.endElement(); // chunk
+ }
+}
Added:
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/PdfBookRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/PdfBookRenderer.java?rev=425493&view=auto
==============================================================================
---
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/PdfBookRenderer.java
(added)
+++
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/PdfBookRenderer.java
Tue Jul 25 12:33:51 2006
@@ -0,0 +1,53 @@
+package org.apache.maven.doxia.book.services.renderer;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.maven.doxia.module.itext.ITextUtil;
+
+/**
+ * PDF book renderer with the <code>iText</code> framework.
+ *
+ * @plexus.component role-hint="pdf"
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class PdfBookRenderer
+ extends AbstractITextBookRenderer
+{
+ /**
+ * @see
org.apache.maven.doxia.book.services.renderer.AbstractITextBookRenderer#getOutputExtension()
+ */
+ public String getOutputExtension()
+ {
+ return "pdf";
+ }
+
+ /**
+ * @see
org.apache.maven.doxia.book.services.renderer.AbstractITextBookRenderer#renderXML(java.io.File,
java.io.File)
+ */
+ public void renderXML( File iTextFile, File iTextOutput )
+ throws IOException
+ {
+ ITextUtil.writePdf( new FileInputStream( iTextFile ), new
FileOutputStream( iTextOutput ) );
+ }
+}
Added:
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/RtfBookRenderer.java
URL:
http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/RtfBookRenderer.java?rev=425493&view=auto
==============================================================================
---
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/RtfBookRenderer.java
(added)
+++
maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/RtfBookRenderer.java
Tue Jul 25 12:33:51 2006
@@ -0,0 +1,53 @@
+package org.apache.maven.doxia.book.services.renderer;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.maven.doxia.module.itext.ITextUtil;
+
+/**
+ * RTF book renderer with the <code>iText</code> framework.
+ *
+ * @plexus.component role-hint="rtf"
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class RtfBookRenderer
+ extends AbstractITextBookRenderer
+{
+ /**
+ * @see
org.apache.maven.doxia.book.services.renderer.AbstractITextBookRenderer#getOutputExtension()
+ */
+ public String getOutputExtension()
+ {
+ return "rtf";
+ }
+
+ /**
+ * @see
org.apache.maven.doxia.book.services.renderer.AbstractITextBookRenderer#renderXML(java.io.File,
java.io.File)
+ */
+ public void renderXML( File iTextFile, File iTextOutput )
+ throws IOException
+ {
+ ITextUtil.writeRtf( new FileInputStream( iTextFile ), new
FileOutputStream( iTextOutput ) );
+ }
+}
Modified:
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=425493&r1=425492&r2=425493&view=diff
==============================================================================
---
maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java
(original)
+++
maven/doxia/trunk/doxia-sandbox/doxia-maven-plugin/src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java
Tue Jul 25 12:33:51 2006
@@ -92,17 +92,20 @@
if ( StringUtils.isEmpty( book.getDescriptor() ) )
{
- throw new MojoFailureException( "Invalid configuration: The
book is required to have a descriptor set." );
+ 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." );
+ 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." );
+ throw new MojoFailureException( "Invalid configuration: "
+ + "The book is required to have at least one format set."
);
}
//
----------------------------------------------------------------------
@@ -159,10 +162,8 @@
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Error while looking for
input files. " +
- "Basedir=" + basedir.getAbsolutePath() + ", " +
- "includes=" + includes + ", " +
- "excludes=" + excludes, e );
+ throw new MojoExecutionException( "Error while looking for
input files. " + "Basedir="
+ + basedir.getAbsolutePath() + ", " + "includes=" +
includes + ", " + "excludes=" + excludes, e );
}
//
-----------------------------------------------------------------------
@@ -177,8 +178,8 @@
}
catch ( InvalidBookDescriptorException e )
{
- throw new MojoFailureException( "Invalid book descriptor: " +
LINE_SEPARATOR +
- formatResult( e.getValidationResult() ) );
+ throw new MojoFailureException( "Invalid book descriptor: " +
LINE_SEPARATOR
+ + formatResult( e.getValidationResult() ) );
}
catch ( BookDoxiaException e )
{
@@ -202,7 +203,9 @@
}
catch ( BookDoxiaException e )
{
- throw new MojoExecutionException( "Error while generating
book in format '" + format + "'.", e );
+ throw new MojoExecutionException(
+ "Error while generating
book in format '" + format.getId() + "'.",
+ e );
}
}
}