Author: jvanzyl Date: Sun May 14 15:16:12 2006 New Revision: 406451 URL: http://svn.apache.org/viewcvs?rev=406451&view=rev Log: o adding vincent's document renderer
Added: maven/doxia/trunk/doxia-doc-renderer/ maven/doxia/trunk/doxia-doc-renderer/pom.xml (with props) maven/doxia/trunk/doxia-doc-renderer/src/ maven/doxia/trunk/doxia-doc-renderer/src/main/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java (with props) maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/ maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/document.mdo maven/doxia/trunk/doxia-doc-renderer/src/main/resources/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt (with props) maven/doxia/trunk/doxia-doc-renderer/src/test/ maven/doxia/trunk/doxia-doc-renderer/src/test/java/ maven/doxia/trunk/doxia-doc-renderer/src/test/resources/ Added: maven/doxia/trunk/doxia-doc-renderer/pom.xml URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/pom.xml?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/pom.xml (added) +++ maven/doxia/trunk/doxia-doc-renderer/pom.xml Sun May 14 15:16:12 2006 @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>doxia</artifactId> + <groupId>org.apache.maven.doxia</groupId> + <version>1.0-alpha-8-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>doxia-doc-renderer</artifactId> + <name>Doxia Document Renderer Component</name> + <version>1.0-SNAPSHOT</version> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.modello</groupId> + <artifactId>modello-maven-plugin</artifactId> + <version>1.0-alpha-8</version> + <executions> + <execution> + <goals> + <goal>xpp3-writer</goal> + <goal>java</goal> + <goal>xpp3-reader</goal> + <goal>xsd</goal> + </goals> + </execution> + </executions> + <configuration> + <version>1.0.0</version> + <model>src/main/mdo/document.mdo</model> + </configuration> + </plugin> + </plugins> + </build> + <developers> + <developer> + <id>vsiveton</id> + <name>Vincent Siveton</name> + <email>[EMAIL PROTECTED]</email> + <organization>Apache Software Foundation</organization> + <roles> + <role>Java Developer</role> + </roles> + <timezone>-5</timezone> + </developer> + </developers> + <dependencies> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-i18n</artifactId> + <version>1.0-beta-6</version> + </dependency> + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-module-itext</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <!-- plexus-container-default uses 1.0.4 --> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>1.2-SNAPSHOT</version> + </dependency> + </dependencies> +</project> \ No newline at end of file Propchange: maven/doxia/trunk/doxia-doc-renderer/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java Sun May 14 15:16:12 2006 @@ -0,0 +1,61 @@ +package org.apache.maven.doxia.docrenderer; + +/* + * Copyright 2004-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.IOException; + +/** + * Base renderer interface for the <code>document</code> + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + */ +public interface DocRenderer +{ + String ROLE = DocRenderer.class.getName(); + + /** + * Render all files from a site directory to an output directory + * + * @param siteDirectory the input directory contains files to be generated + * @param outputDirectory the output directory where files are generated + * @throws DocRendererException if any + * @throws IOException if any + */ + void render( File siteDirectory, File outputDirectory ) + throws DocRendererException, IOException; + + /** + * Render a document depending a context and a document descriptor + * + * @param siteDirectory the input directory contains files to be generated + * @param outputDirectory the output directory where file are generated + * @param documentDescriptor the document descriptor + * @throws DocRendererException if any + * @throws IOException if any + */ + void render( File siteDirectory, File outputDirectory, File documentDescriptor ) + throws DocRendererException, IOException; + + /** + * Get the output extension supported + * + * @return the ouput extension supported + */ + public String getOutputExtension(); +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java Sun May 14 15:16:12 2006 @@ -0,0 +1,48 @@ +package org.apache.maven.doxia.docrenderer; + +/* + * Copyright 2004-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. + */ + +/** + * A <code>document</code> renderer exception + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + */ +public class DocRendererException + extends Exception +{ + /** + * Default constructor + * + * @param message + */ + public DocRendererException( String message ) + { + super( message ); + } + + /** + * Other constructor + * + * @param message + * @param t + */ + public DocRendererException( String message, Throwable t ) + { + super( message, t ); + } +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/DocRendererException.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java Sun May 14 15:16:12 2006 @@ -0,0 +1,444 @@ +package org.apache.maven.doxia.docrenderer.itext; + +/* + * 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.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.maven.doxia.Doxia; +import org.apache.maven.doxia.docrenderer.DocRenderer; +import org.apache.maven.doxia.docrenderer.DocRendererException; +import org.apache.maven.doxia.docrenderer.document.DocumentModel; +import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem; +import org.apache.maven.doxia.docrenderer.document.io.xpp3.DocumentXpp3Reader; +import org.apache.maven.doxia.module.itext.ITextSink; +import org.apache.maven.doxia.module.itext.ITextUtil; +import org.apache.maven.doxia.parser.ParseException; +import org.apache.maven.doxia.parser.manager.ParserNotFoundException; +import org.apache.maven.doxia.site.module.SiteModule; +import org.apache.maven.doxia.site.module.manager.SiteModuleManager; +import org.apache.xml.utils.DefaultErrorHandler; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import com.lowagie.text.ElementTags; + +/** + * Abstract <code>document</code> render with the <code>iText</code> framework + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + */ +public abstract class AbstractITextRender + extends AbstractLogEnabled + implements DocRenderer +{ + private static String XSLT_RESOURCE = "org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt"; + + private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); + + private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); + + /** + * @plexus.requirement + */ + protected SiteModuleManager siteModuleManager; + + /** + * @plexus.requirement + */ + protected Doxia doxia; + + static + { + TRANSFORMER_FACTORY.setErrorListener( new DefaultErrorHandler() ); + } + + /** + * @see org.apache.maven.doxia.docrenderer.DocRenderer#render(java.io.File, java.io.File) + */ + public void render( File siteDirectory, File outputDirectory ) + throws DocRendererException, IOException + { + for ( Iterator i = siteModuleManager.getSiteModules().iterator(); i.hasNext(); ) + { + SiteModule module = (SiteModule) i.next(); + + File moduleBasedir = new File( siteDirectory, module.getSourceDirectory() ); + + if ( moduleBasedir.exists() ) + { + List docs = FileUtils.getFileNames( moduleBasedir, "**/*." + module.getExtension(), null, false ); + + for ( Iterator j = docs.iterator(); j.hasNext(); ) + { + String doc = (String) j.next(); + String fullPathDoc = new File( moduleBasedir, doc ).getPath(); + + String outputITextName = doc.substring( 0, doc.indexOf( "." ) + 1 ) + "xml"; + File outputITextFile = new File( outputDirectory, outputITextName ); + if ( !outputITextFile.getParentFile().exists() ) + { + outputITextFile.getParentFile().mkdirs(); + } + String iTextOutputName = doc.substring( 0, doc.indexOf( "." ) + 1 ) + getOutputExtension(); + File iTextOutputFile = new File( outputDirectory, iTextOutputName ); + if ( !iTextOutputFile.getParentFile().exists() ) + { + iTextOutputFile.getParentFile().mkdirs(); + } + + parse( fullPathDoc, module, outputITextFile ); + + generateOutput( outputITextFile, iTextOutputFile ); + } + } + } + } + + /** + * @see org.apache.maven.doxia.docrenderer.DocRenderer#render(java.io.File, java.io.File, java.io.File) + */ + public void render( File siteDirectory, File outputDirectory, File documentDescriptor ) + throws DocRendererException, IOException + { + if ( ( documentDescriptor == null ) || ( !documentDescriptor.exists() ) ) + { + getLogger().info( "No documentDescriptor is found. Generate all documents." ); + render( siteDirectory, outputDirectory ); + return; + } + + DocumentModel documentModel; + try + { + documentModel = new DocumentXpp3Reader().read( new FileReader( documentDescriptor ) ); + } + catch ( XmlPullParserException e ) + { + throw new DocRendererException( "Error parsing document descriptor", e ); + } + catch ( IOException e ) + { + throw new DocRendererException( "Error reading document descriptor", e ); + } + + if ( documentModel.getOutputName() == null ) + { + getLogger().info( "No outputName is defined in the document descriptor. Using 'generated_itext'" ); + documentModel.setOutputName( "generated_itext" ); + } + + if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) ) + { + getLogger().info( "No TOC is defined in the document descriptor. Merging all documents." ); + } + + List iTextFiles = new LinkedList(); + for ( Iterator i = siteModuleManager.getSiteModules().iterator(); i.hasNext(); ) + { + SiteModule module = (SiteModule) i.next(); + + File moduleBasedir = new File( siteDirectory, module.getSourceDirectory() ); + + if ( moduleBasedir.exists() ) + { + List docs = FileUtils.getFileNames( moduleBasedir, "**/*." + module.getExtension(), null, false ); + + for ( Iterator j = docs.iterator(); j.hasNext(); ) + { + String doc = (String) j.next(); + String fullPathDoc = new File( moduleBasedir, doc ).getPath(); + + String outputITextName = doc.substring( 0, doc.lastIndexOf( "." ) + 1 ) + "xml"; + File outputITextFile = new File( outputDirectory, outputITextName ); + + if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) ) + { + iTextFiles.add( outputITextFile ); + + if ( !outputITextFile.getParentFile().exists() ) + { + outputITextFile.getParentFile().mkdirs(); + } + + parse( fullPathDoc, module, outputITextFile ); + } + else + { + for ( Iterator k = documentModel.getToc().getItems().iterator(); k.hasNext(); ) + { + DocumentTOCItem tocItem = (DocumentTOCItem) k.next(); + + if ( tocItem.getRef() == null ) + { + getLogger().info( "No ref defined for an tocItem in the document descriptor." ); + continue; + } + + String outTmp = StringUtils.replace( outputITextFile.getAbsolutePath(), "\\", "/" ); + outTmp = outTmp.substring( 0, outTmp.lastIndexOf( "." ) ); + + String outRef = StringUtils.replace( tocItem.getRef(), "\\", "/" ); + if (outRef.lastIndexOf( "." )!= -1) + { + outRef = outRef.substring( 0, outRef.lastIndexOf( "." ) ); + } + else + { + outRef = outRef.substring( 0, outRef.length() ); + } + + if ( outTmp.indexOf( outRef ) != -1 ) + { + iTextFiles.add( outputITextFile ); + + if ( !outputITextFile.getParentFile().exists() ) + { + outputITextFile.getParentFile().mkdirs(); + } + + parse( fullPathDoc, module, outputITextFile ); + } + } + } + } + } + } + + File iTextFile = new File( outputDirectory, documentModel.getOutputName() + ".xml" ); + File iTextOutput = new File( outputDirectory, documentModel.getOutputName() + "." + getOutputExtension() ); + Document document = generateDocument( iTextFiles ); + transform( documentModel, document, iTextFile ); + generateOutput( iTextFile, iTextOutput ); + } + + /** + * Generate an ouput file with the iText framework + * + * @param iTextFile + * @param iTextOutput + * @throws DocRendererException if any + * @throws IOException if any + */ + public abstract void generateOutput( File iTextFile, File iTextOutput ) + throws DocRendererException, IOException; + + /** + * Parse a sink + * + * @param fullPathDoc + * @param module + * @param outputITextFile + * @throws DocRendererException + * @throws IOException + */ + private void parse( String fullPathDoc, SiteModule module, File outputITextFile ) + throws DocRendererException, IOException + { + ITextSink sink = new ITextSink( new FileWriter( outputITextFile ) ); + + sink.setClassLoader( new URLClassLoader( new URL[] { outputITextFile.getParentFile().toURL() } ) ); + try + { + FileReader reader = new FileReader( fullPathDoc ); + + doxia.parse( reader, module.getParserId(), sink ); + } + catch ( ParserNotFoundException e ) + { + throw new DocRendererException( "Error getting a parser for " + fullPathDoc + ": " + e.getMessage() ); + } + catch ( ParseException e ) + { + getLogger().error( "Error parsing " + fullPathDoc + ": " + e.getMessage(), e ); + } + finally + { + sink.flush(); + + sink.close(); + } + } + + /** + * Merge all iTextFiles to a single one + * + * @param iTextFiles + * @return a document + * @throws DocRendererException if any + * @throws IOException if any + */ + private Document generateDocument( List iTextFiles ) + throws DocRendererException, IOException + { + Document document; + try + { + document = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().newDocument(); + } + catch ( ParserConfigurationException e ) + { + throw new DocRendererException( "Error building document :" + e.getMessage() ); + } + document.appendChild( document.createElement( ElementTags.ITEXT ) ); // Used only to set a root + + for ( int i = 0; i < iTextFiles.size(); i++ ) + { + File iTextFile = (File) iTextFiles.get( i ); + + Document iTextDocument; + try + { + iTextDocument = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder().parse( iTextFile ); + } + catch ( SAXException e ) + { + throw new DocRendererException( "SAX Error : " + e.getMessage() ); + } + catch ( ParserConfigurationException e ) + { + throw new DocRendererException( "Error parsing configuration : " + e.getMessage() ); + } + + // Only one chapter per doc + Node chapter = iTextDocument.getElementsByTagName( ElementTags.CHAPTER ).item( 0 ); + try + { + document.getDocumentElement().appendChild( document.importNode( chapter, true ) ); + } + catch ( DOMException e ) + { + throw new DocRendererException( "Error appending chapter for " + iTextFile + " : " + e.getMessage() ); + } + } + + return document; + } + + /** + * Init the transformer object + * + * @return an instanced transformer object + * @throws DocRendererException if any + */ + private Transformer initTransformer() + throws DocRendererException + { + try + { + Transformer transformer = TRANSFORMER_FACTORY.newTransformer( new StreamSource( DefaultPdfRenderer.class + .getResourceAsStream( "/" + XSLT_RESOURCE ) ) ); + transformer.setErrorListener( TRANSFORMER_FACTORY.getErrorListener() ); + + transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "false" ); + transformer.setOutputProperty( OutputKeys.INDENT, "yes" ); + transformer.setOutputProperty( OutputKeys.METHOD, "xml" ); + transformer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" ); + + return transformer; + } + catch ( TransformerConfigurationException e ) + { + throw new DocRendererException( "Error configuring Transformer for " + XSLT_RESOURCE + ": " + + e.getMessage() ); + } + catch ( IllegalArgumentException e ) + { + throw new DocRendererException( "Error configuring Transformer for " + XSLT_RESOURCE + ": " + + e.getMessage() ); + } + } + + /** + * Add transformer parameters + * + * @param transformer + * @param documentModel + */ + private void addTransformerParameters( Transformer transformer, DocumentModel documentModel ) + { + transformer.setParameter( "title", documentModel.getMeta().getTitle() ); + transformer.setParameter( "author", documentModel.getMeta().getAuthor() ); + transformer.setParameter( "creationdate", new Date().toString() ); + transformer.setParameter( "subject", documentModel.getMeta().getSubject() ); + transformer.setParameter( "keywords", documentModel.getMeta().getKeywords() ); + transformer.setParameter( "producer", "Generated with Doxia by " + System.getProperty( "user.name" ) ); + if ( ITextUtil.isPageSizeSupported( documentModel.getMeta().getTitle() ) ) + { + transformer.setParameter( "pagesize", documentModel.getMeta().getPageSize() ); + } + else + { + transformer.setParameter( "pagesize", "A4" ); + } + + transformer.setParameter( "frontPageHeader", "" ); + transformer.setParameter( "frontPageTitle", documentModel.getMeta().getTitle() ); + transformer.setParameter( "frontPageFooter", "Generated date " + new Date().toString() ); + } + + /** + * Transform a document to an iTextFile + * + * @param documentModel + * @param document + * @param iTextFile + * @throws DocRendererException + */ + private void transform( DocumentModel documentModel, Document document, File iTextFile ) + throws DocRendererException + { + Transformer transformer = initTransformer(); + + addTransformerParameters( transformer, documentModel ); + + try + { + transformer.transform( new DOMSource( document ), new StreamResult( iTextFile ) ); + } + catch ( TransformerException e ) + { + throw new DocRendererException( "Error transformer Document from " + document + ": " + e.getMessage() ); + } + } +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/AbstractITextRender.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java Sun May 14 15:16:12 2006 @@ -0,0 +1,62 @@ +package org.apache.maven.doxia.docrenderer.itext; + +/* + * 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.docrenderer.DocRendererException; +import org.apache.maven.doxia.module.itext.ITextUtil; + +/** + * PDF render with the <code>iText</code> framework + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + * @plexus.component role="org.apache.maven.doxia.docrenderer.PdfRenderer" + */ +public class DefaultPdfRenderer + extends AbstractITextRender + implements PdfRenderer +{ + /** + * @see org.apache.maven.doxia.docrenderer.DocRenderer#getOutputExtension() + */ + public String getOutputExtension() + { + return "pdf"; + } + + /** + * @see org.apache.maven.doxia.docrenderer.itext.AbstractITextRender#generateOutput(java.io.File, java.io.File) + */ + public void generateOutput( File iTextFile, File iTextOutput ) + throws DocRendererException, IOException + { + getLogger().debug( "Writing : " + iTextOutput ); + try + { + ITextUtil.writePdf( new FileInputStream( iTextFile ), new FileOutputStream( iTextOutput ) ); + } + catch ( RuntimeException e ) + { + throw new DocRendererException( "Error writing PDF from " + iTextOutput + ": " + e.getMessage() ); + } + } +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultPdfRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java Sun May 14 15:16:12 2006 @@ -0,0 +1,62 @@ +package org.apache.maven.doxia.docrenderer.itext; + +/* + * 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.docrenderer.DocRendererException; +import org.apache.maven.doxia.module.itext.ITextUtil; + +/** + * RTF render with the <code>iText</code> framework + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + * @plexus.component role="org.apache.maven.doxia.docrenderer.RtfRenderer" + */ +public class DefaultRtfRenderer + extends AbstractITextRender + implements RtfRenderer +{ + /** + * @see org.apache.maven.doxia.docrenderer.DocRenderer#getOutputExtension() + */ + public String getOutputExtension() + { + return "rtf"; + } + + /** + * @see org.apache.maven.doxia.docrenderer.itext.AbstractITextRender#generateOutput(java.io.File, java.io.File) + */ + public void generateOutput( File iTextFile, File iTextOutput ) + throws DocRendererException, IOException + { + getLogger().debug( "Writing : " + iTextOutput ); + try + { + ITextUtil.writeRtf( new FileInputStream( iTextFile ), new FileOutputStream( iTextOutput ) ); + } + catch ( RuntimeException e ) + { + throw new DocRendererException( "Error writing RTF from " + iTextOutput + ": " + e.getMessage() ); + } + } +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/DefaultRtfRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java Sun May 14 15:16:12 2006 @@ -0,0 +1,30 @@ +package org.apache.maven.doxia.docrenderer.itext; + +/* + * Copyright 2004-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 org.apache.maven.doxia.docrenderer.DocRenderer; + +/** + * PDF renderer interface for the <code>iText</code> framework + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + */ +public interface PdfRenderer extends DocRenderer +{ + String ROLE = PdfRenderer.class.getName(); +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/PdfRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java Sun May 14 15:16:12 2006 @@ -0,0 +1,30 @@ +package org.apache.maven.doxia.docrenderer.itext; + +/* + * Copyright 2004-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 org.apache.maven.doxia.docrenderer.DocRenderer; + +/** + * RTF renderer interface for the <code>iText</code> framework + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a> + * @version $Id$ + */ +public interface RtfRenderer extends DocRenderer +{ + String ROLE = RtfRenderer.class.getName(); +} Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/itext/RtfRenderer.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/document.mdo URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/document.mdo?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/document.mdo (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/mdo/document.mdo Sun May 14 15:16:12 2006 @@ -0,0 +1,137 @@ +<?xml version="1.0"?> + +<model> + <id>document</id> + <name>Document</name> + <description><![CDATA[Model for Document in Doxia.]]></description> + <defaults> + <default> + <key>package</key> + <value>org.apache.maven.doxia.docrenderer.document</value> + </default> + </defaults> + <classes> + <class rootElement="true" xml.tagName="document"> + <name>DocumentModel</name> + <description>Describes the overall document model.</description> + <version>1.0.0</version> + <fields> + <field xml.attribute="true"> + <name>outputName</name> + <version>1.0.0</version> + <type>String</type> + <identifier>true</identifier> + </field> + <field> + <name>meta</name> + <description>The Meta information properties.</description> + <version>1.0.0</version> + <association> + <type>DocumentMeta</type> + </association> + <identifier>true</identifier> + </field> + <field> + <name>toc</name> + <description>The TOC information properties.</description> + <version>1.0.0</version> + <association> + <type>DocumentTOC</type> + </association> + <identifier>true</identifier> + </field> + </fields> + </class> + + <class> + <name>DocumentMeta</name> + <description>Element that contains some meta information about the document.</description> + <version>1.0.0</version> + <fields> + <field> + <name>title</name> + <version>1.0.0</version> + <description>Title of the document.</description> + <type>String</type> + <identifier>true</identifier> + </field> + <field> + <name>author</name> + <version>1.0.0</version> + <description>The author of the document.</description> + <type>String</type> + <identifier>true</identifier> + </field> + <field> + <name>subject</name> + <version>1.0.0</version> + <description>The subject of the document.</description> + <type>String</type> + <identifier>true</identifier> + </field> + <field> + <name>keywords</name> + <version>1.0.0</version> + <description>The keywords of the document</description> + <type>String</type> + <identifier>true</identifier> + </field> + <field> + <name>pageSize</name> + <version>1.0.0</version> + <description>The pagesize of the document</description> + <type>String</type> + <identifier>true</identifier> + </field> + </fields> + </class> + + <class> + <name>DocumentTOC</name> + <description>A Table Of Content for the document.</description> + <version>1.0.0</version> + <fields> + <field xml.attribute="true"> + <name>name</name> + <description>The name to use for the menu.</description> + <version>1.0.0</version> + <type>String</type> + <identifier>true</identifier> + </field> + <field xml.listStyle="flat"> + <name>items</name> + <description>TOC item.</description> + <version>1.0.0</version> + <association> + <type>DocumentTOCItem</type> + <multiplicity>*</multiplicity> + </association> + <identifier>true</identifier> + </field> + </fields> + </class> + + <class> + <name>DocumentTOCItem</name> + <description>A menu item.</description> + <version>1.0.0</version> + <fields> + <field xml.attribute="true"> + <name>name</name> + <description>The name to use for the toc.</description> + <version>1.0.0</version> + <type>String</type> + <identifier>true</identifier> + </field> + <field xml.attribute="true"> + <name>ref</name> + <description>The ref to use for the item.</description> + <version>1.0.0</version> + <type>String</type> + <identifier>true</identifier> + </field> + </fields> + </class> + </classes> +</model> + Added: maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt?rev=406451&view=auto ============================================================================== --- maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt (added) +++ maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt Sun May 14 15:16:12 2006 @@ -0,0 +1,181 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + /* + * 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. + */ +--> + +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <!-- MetaData Parameters --> + <xsl:param name="title" /> + <xsl:param name="author" /> + <xsl:param name="creationdate" /> + <xsl:param name="subject" /> + <xsl:param name="keywords" /> + <xsl:param name="producer" /> + <xsl:param name="pagesize" /> + + <!-- FrontPage Parameters --> + <xsl:param name="frontPageTitle" /> + <xsl:param name="frontPageFooter" /> + + <xsl:template match="/itext"> + <itext title="{$title}" author="{$author}" creationdate="{$creationdate}" + subject="{$subject}" keywords="{$keywords}" producer="{$producer}" + pagesize="{$pagesize}"> + <!-- Start Front page --> + <paragraph> + <chunk font="Helvetica" size="12.0" fontstyle="normal" + blue="0" green="0" red="0"> + <table columns="1" left="false" right="false" + top="false" bottom="false" align="Center" width="100%"> + <row> + <cell left="false" right="false" top="false" + bottom="false" horizontalalign="Left" verticalalign="middle"> + <image + url="http://maven.apache.org/images/apache-maven-project.png" + plainwidth="306.0" plainheight="27.867857" /> + </cell> + </row> + <row> + <cell left="false" right="false" top="false" + bottom="false" horizontalalign="Center" verticalalign="middle" + leading="330"> + <chunk font="Helvetica" size="24.0" + fontstyle="bold" blue="0" green="0" red="0"><xsl:value-of select="$frontPageTitle"/></chunk> + </cell> + </row> + <row> + <cell left="false" right="false" top="false" + bottom="false" horizontalalign="Left" verticalalign="middle" + leading="330"> + <chunk font="Helvetica" size="16.0" + fontstyle="bold" blue="0" green="0" red="0"><xsl:value-of select="$frontPageFooter"/></chunk> + </cell> + </row> + </table> + </chunk> + </paragraph> + <!-- End Front page --> + + <!-- Start TOC --> + <newpage /> + <paragraph align="Center"> + <chunk font="Helvetica" size="24" fontstyle="bold" blue="0" + green="0" red="0">Table Of Contents</chunk> + </paragraph> + <paragraph align="Left" leading="24.0"> + <newline /> + <xsl:apply-templates select="*" mode="toc" /> + </paragraph> + <!-- End TOC --> + + <xsl:apply-templates select="*" mode="body" /> + + </itext> + </xsl:template> + + <!-- Add TOC --> + <xsl:template match="chapter|section" mode="toc"> + <xsl:if test="./title/chunk != ''"> + <chunk font="Helvetica" size="16.0" fontstyle="normal" + blue="255" green="0" red="0" + localgoto="{generate-id(./title/chunk)}"> + <xsl:number level="multiple" format="1.1.1.1.1." + count="section|chapter" /> + <xsl:text> </xsl:text> + <xsl:value-of select="title/chunk" /> + </chunk> + </xsl:if> + <xsl:if test="./title/anchor != ''"> + <xsl:if test="./title/anchor/@name != ''"> + <chunk font="Helvetica" size="16.0" fontstyle="normal" + blue="255" green="0" red="0" localgoto="{./title/anchor/@name}"> + <xsl:number level="multiple" format="1.1.1.1.1." + count="section|chapter" /> + <xsl:text> </xsl:text> + <xsl:value-of select="title/anchor/chunk" /> + </chunk> + </xsl:if> + <xsl:if test="./title/anchor/@name = ''"> + <chunk font="Helvetica" size="16.0" fontstyle="normal" + blue="0" green="0" red="0"> + <xsl:number level="multiple" format="1.1.1.1.1." + count="section|chapter" /> + <xsl:text> </xsl:text> + <xsl:value-of select="title/anchor/chunk" /> + </chunk> + </xsl:if> + </xsl:if> + + <newline /> + <xsl:apply-templates select="child::*[name() = 'section']" + mode="toc" /> + </xsl:template> + + <xsl:template match="chapter/title/chunk|section/title/chunk" + mode="body"> + <xsl:copy> + <xsl:apply-templates select="@*" mode="body" /> + <xsl:attribute name="localdestination"> + <xsl:value-of select="generate-id(.)" /> + </xsl:attribute> + <xsl:apply-templates select="text()|*" mode="body" /> + </xsl:copy> + </xsl:template> + + <xsl:template + match="chapter/title/anchor/chunk|section/title/anchor/chunk" + mode="body"> + <xsl:copy> + <xsl:apply-templates select="@*" mode="body" /> + <xsl:apply-templates select="text()|*" mode="body" /> + </xsl:copy> + </xsl:template> + + <xsl:template match="*|text()|@*" mode="body"> + <xsl:copy> + <xsl:apply-templates select="*|text()|@*" mode="body" /> + </xsl:copy> + </xsl:template> + + <!-- Update depth and numberdepth --> + <xsl:template match="chapter" mode="body"> + <xsl:copy> + <xsl:apply-templates select="@*" mode="body" /> + <xsl:attribute name="depth">1</xsl:attribute> + <xsl:attribute name="numberdepth">1</xsl:attribute> + <xsl:apply-templates select="text()|*" mode="body" /> + </xsl:copy> + </xsl:template> + + <xsl:template match="section" mode="body"> + <xsl:copy> + <xsl:apply-templates select="@*" mode="body" /> + <xsl:variable name="depth.from.context" + select="count(ancestor::*)" /> + <xsl:attribute name="depth"> + <xsl:value-of select="$depth.from.context" /> + </xsl:attribute> + <xsl:attribute name="numberdepth"> + <xsl:value-of select="$depth.from.context" /> + </xsl:attribute> + <xsl:apply-templates select="text()|*" mode="body" /> + </xsl:copy> + </xsl:template> +</xsl:stylesheet> Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/itext/xslt/TOC.xslt ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"