Author: ltheussl
Date: Mon Sep 17 03:52:53 2007
New Revision: 576356
URL: http://svn.apache.org/viewvc?rev=576356&view=rev
Log:
Factor out abstract base class. Some code clean-up.
Added:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
(with props)
Modified:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/DefaultPdfRenderer.java
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/PdfRenderer.java
Added:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java?rev=576356&view=auto
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
(added)
+++
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
Mon Sep 17 03:52:53 2007
@@ -0,0 +1,177 @@
+package org.apache.maven.plugins.pdf;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.maven.plugin.AbstractMojo;
+
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.util.StringUtils;
+
+
+/**
+ * @author ltheussl
+ * @version $Id$
+ */
+public abstract class AbstractPdfMojo
+ extends AbstractMojo
+{
+ /**
+ * The locale by default for all default bundles
+ */
+ private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+ /**
+ * A comma separated list of locales supported by Maven. The first valid
token will be the default Locale
+ * for this instance of the Java Virtual Machine.
+ *
+ * @parameter expression="${locales}"
+ */
+ private String locales;
+
+ /**
+ * Internationalization.
+ *
+ * @component
+ */
+ protected I18N i18n;
+
+ /**
+ * Init the <code>localesList</code> variable.
+ * <p>If <code>locales</code> variable is available, the first valid token
will be the <code>defaultLocale</code>
+ * for this instance of the Java Virtual Machine.</p>
+ *
+ * @return a list of <code>Locale</code>
+ * @todo that's not specific to pdf, move it somewhere to make it
re-usable.
+ */
+ protected List initLocalesList()
+ {
+ List localesList = new ArrayList();
+ if ( locales != null )
+ {
+ String[] localesArray = StringUtils.split( locales, "," );
+
+ for ( int i = 0; i < localesArray.length; i++ )
+ {
+ Locale locale = codeToLocale( localesArray[i] );
+
+ if ( locale != null )
+ {
+ if ( !Arrays.asList( Locale.getAvailableLocales()
).contains( locale ) )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "The locale '" ).append( locale );
+ sb.append( "' is not available in this Java Virtual
Machine (" );
+ sb.append( System.getProperty( "java.version" )
).append( "from" );
+ sb.append( System.getProperty( "java.vendor" )
).append( ") - IGNORING" );
+
+ getLog().warn( sb.toString() );
+
+ continue;
+ }
+
+ // Default bundles are in English
+ if ( !locale.getLanguage().equals(
DEFAULT_LOCALE.getLanguage() ) )
+ {
+ if ( !i18n.getBundle( "site-plugin", locale
).getLocale().getLanguage().equals( locale
+ .getLanguage() ) )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "The locale '" ).append( locale
).append( "' (" );
+ sb.append( locale.getDisplayName( Locale.ENGLISH )
);
+ sb.append( ") is not supported IGNORING. " );
+
+ getLog().warn( sb.toString() );
+
+ continue;
+ }
+ }
+
+ localesList.add( locale );
+ }
+ }
+ }
+
+ if ( localesList.isEmpty() )
+ {
+ localesList = Collections.singletonList( DEFAULT_LOCALE );
+ }
+
+ return localesList;
+ }
+
+ /**
+ * Converts a locale code like "en", "en_US" or "en_US_win" to a
<code>java.util.Locale</code>
+ * object.
+ * <p>If localeCode = <code>default</code>, return the current value of
the default locale for this instance
+ * of the Java Virtual Machine.</p>
+ *
+ * @param localeCode the locale code string.
+ * @return a java.util.Locale object instancied or null if errors occurred
+ * @see <a
href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
+ * @todo that's not specific to pdf, move it somewhere to make it
re-usable.
+ */
+ private Locale codeToLocale( String localeCode )
+ {
+ if ( localeCode == null )
+ {
+ return null;
+ }
+
+ if ( "default".equalsIgnoreCase( localeCode ) )
+ {
+ return Locale.getDefault();
+ }
+
+ String language = "";
+ String country = "";
+ String variant = "";
+
+ StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
+ if ( tokenizer.countTokens() > 3 )
+ {
+ getLog().warn( "Invalid java.util.Locale format for '" +
localeCode + "' entry - IGNORING" );
+ return null;
+ }
+
+ if ( tokenizer.hasMoreTokens() )
+ {
+ language = tokenizer.nextToken();
+ if ( tokenizer.hasMoreTokens() )
+ {
+ country = tokenizer.nextToken();
+ if ( tokenizer.hasMoreTokens() )
+ {
+ variant = tokenizer.nextToken();
+ }
+ }
+ }
+
+ return new Locale( language, country, variant );
+ }
+}
Propchange:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=576356&r1=576355&r2=576356&view=diff
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
(original)
+++
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
Mon Sep 17 03:52:53 2007
@@ -21,24 +21,16 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.StringTokenizer;
import org.apache.maven.doxia.docrenderer.DocRenderer;
import org.apache.maven.doxia.docrenderer.DocRendererException;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.i18n.I18N;
-import org.codehaus.plexus.util.StringUtils;
-
/**
* @author ltheussl
@@ -47,14 +39,9 @@
* @goal pdf
*/
public class PdfMojo
- extends AbstractMojo
+ extends AbstractPdfMojo
{
/**
- * The locale by default for all default bundles
- */
- private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
-
- /**
* Directory containing source for apt, fml and xdoc docs.
*
* @parameter expression="${basedir}/src/site"
@@ -63,21 +50,6 @@
protected File siteDirectory;
/**
- * A comma separated list of locales supported by Maven. The first valid
token will be the default Locale
- * for this instance of the Java Virtual Machine.
- *
- * @parameter expression="${locales}"
- */
- private String locales;
-
- /**
- * Internationalization.
- *
- * @component
- */
- protected I18N i18n;
-
- /**
* Directory containing the generated project sites and report
distributions.
*
* @parameter alias="workingDirectory"
expression="${project.build.directory}/pdf"
@@ -116,7 +88,7 @@
{
Locale locale = (Locale) iterator.next();
- File outputDirectory = getOutputDirectory( locale,
defaultLocale );
+ File outputDir = getOutputDirectory( locale, defaultLocale );
// Generate static site
File siteDirectoryFile = siteDirectory;
@@ -126,7 +98,7 @@
siteDirectoryFile = new File( siteDirectory,
locale.getLanguage() );
}
- docRenderer.render( siteDirectoryFile, outputDirectory,
docDescriptor );
+ docRenderer.render( siteDirectoryFile, outputDir,
docDescriptor );
}
}
catch ( DocRendererException e )
@@ -156,119 +128,4 @@
return file;
}
- /**
- * Init the <code>localesList</code> variable.
- * <p>If <code>locales</code> variable is available, the first valid token
will be the <code>defaultLocale</code>
- * for this instance of the Java Virtual Machine.</p>
- *
- * @return a list of <code>Locale</code>
- * @todo that's not specific to pdf, move it somewhere to make it
re-usable.
- */
- protected List initLocalesList()
- {
- List localesList = new ArrayList();
- if ( locales != null )
- {
- String[] localesArray = StringUtils.split( locales, "," );
-
- for ( int i = 0; i < localesArray.length; i++ )
- {
- Locale locale = codeToLocale( localesArray[i] );
-
- if ( locale != null )
- {
- if ( !Arrays.asList( Locale.getAvailableLocales()
).contains( locale ) )
- {
- StringBuffer sb = new StringBuffer();
-
- sb.append( "The locale '" ).append( locale );
- sb.append( "' is not available in this Java Virtual
Machine (" );
- sb.append( System.getProperty( "java.version" )
).append( "from" );
- sb.append( System.getProperty( "java.vendor" )
).append( ") - IGNORING" );
-
- getLog().warn( sb.toString() );
-
- continue;
- }
-
- // Default bundles are in English
- if ( !locale.getLanguage().equals(
DEFAULT_LOCALE.getLanguage() ) )
- {
- if ( !i18n.getBundle( "site-plugin", locale
).getLocale().getLanguage().equals( locale
- .getLanguage() ) )
- {
- StringBuffer sb = new StringBuffer();
-
- sb.append( "The locale '" ).append( locale
).append( "' (" );
- sb.append( locale.getDisplayName( Locale.ENGLISH )
);
- sb.append( ") is not supported IGNORING. " );
-
- getLog().warn( sb.toString() );
-
- continue;
- }
- }
-
- localesList.add( locale );
- }
- }
- }
-
- if ( localesList.isEmpty() )
- {
- localesList = Collections.singletonList( DEFAULT_LOCALE );
- }
-
- return localesList;
- }
-
- /**
- * Converts a locale code like "en", "en_US" or "en_US_win" to a
<code>java.util.Locale</code>
- * object.
- * <p>If localeCode = <code>default</code>, return the current value of
the default locale for this instance
- * of the Java Virtual Machine.</p>
- *
- * @param localeCode the locale code string.
- * @return a java.util.Locale object instancied or null if errors occurred
- * @see <a
href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
- * @todo that's not specific to pdf, move it somewhere to make it
re-usable.
- */
- private Locale codeToLocale( String localeCode )
- {
- if ( localeCode == null )
- {
- return null;
- }
-
- if ( "default".equalsIgnoreCase( localeCode ) )
- {
- return Locale.getDefault();
- }
-
- String language = "";
- String country = "";
- String variant = "";
-
- StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
- if ( tokenizer.countTokens() > 3 )
- {
- getLog().warn( "Invalid java.util.Locale format for '" +
localeCode + "' entry - IGNORING" );
- return null;
- }
-
- if ( tokenizer.hasMoreTokens() )
- {
- language = tokenizer.nextToken();
- if ( tokenizer.hasMoreTokens() )
- {
- country = tokenizer.nextToken();
- if ( tokenizer.hasMoreTokens() )
- {
- variant = tokenizer.nextToken();
- }
- }
- }
-
- return new Locale( language, country, variant );
- }
}
Modified:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/DefaultPdfRenderer.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/DefaultPdfRenderer.java?rev=576356&r1=576355&r2=576356&view=diff
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/DefaultPdfRenderer.java
(original)
+++
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/DefaultPdfRenderer.java
Mon Sep 17 03:52:53 2007
@@ -20,18 +20,16 @@
*/
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
+import javax.xml.transform.TransformerException;
+
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;
@@ -75,7 +73,13 @@
}
/**
+ * Converts an FO file to a PDF file using FOP.
+ * @param foFile the FO file.
+ * @param pdfFile the target PDF file.
+ * @throws DocRendererException In case of a conversion problem.
+ * @see
org.apache.maven.doxia.module.fo.FoUtils#convertFO2PDF(File,File,String);
*/
+
public void generatePdf( File foFile, File pdfFile )
throws DocRendererException
{
@@ -85,8 +89,7 @@
{
FoUtils.convertFO2PDF( foFile, pdfFile, null );
}
- catch ( Exception e )
- // TransformerException
+ catch ( TransformerException e )
{
throw new DocRendererException( "Error creating PDF from " +
foFile + ": " + e.getMessage() );
}
@@ -135,11 +138,11 @@
{
String doc = (String) j.next();
- String fullPathDoc = new File( moduleBasedir, doc
).getPath();
+ String fullDocPath = new File( moduleBasedir, doc
).getPath();
sink.setDocumentName( doc );
- parse( fullPathDoc, module, sink );
+ parse( fullDocPath, module, sink );
}
}
}
@@ -265,28 +268,29 @@
/**
* Parse a source document into a FO sink.
*
- * @param fullPathDoc full path to the source document.
+ * @param fullDocPath full path to the source document.
* @param module the SiteModule that the source document belongs to
(determines the parser to use).
* @param sink the sink to receive the events.
- * @throws DocRendererException
- * @throws IOException
+ * @throws DocRendererException in case of a parsing error.
+ * @throws IOException if the source document cannot be opened.
*/
- private void parse( String fullPathDoc, SiteModule module, FoAggregateSink
sink )
+ private void parse( String fullDocPath, SiteModule module, FoAggregateSink
sink )
throws DocRendererException, IOException
{
try
{
- FileReader reader = new FileReader( fullPathDoc );
+ FileReader reader = new FileReader( fullDocPath );
doxia.parse( reader, module.getParserId(), sink );
}
catch ( ParserNotFoundException e )
{
- throw new DocRendererException( "Error getting a parser for " +
fullPathDoc + ": " + e.getMessage() );
+ throw new DocRendererException( "No parser '" +
module.getParserId()
+ + "' found for " + fullDocPath + ": " + e.getMessage()
);
}
catch ( ParseException e )
{
- // TODO: getLogger().error( "Error parsing " + fullPathDoc + ": "
+ e.getMessage(), e );
+ throw new DocRendererException( "Error parsing " + fullDocPath +
": " + e.getMessage(), e );
}
finally
{
Modified:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/PdfRenderer.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/PdfRenderer.java?rev=576356&r1=576355&r2=576356&view=diff
==============================================================================
---
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/PdfRenderer.java
(original)
+++
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/PdfRenderer.java
Mon Sep 17 03:52:53 2007
@@ -29,5 +29,6 @@
*/
public interface PdfRenderer extends DocRenderer
{
+ /** Plexus lookup role. */
String ROLE = PdfRenderer.class.getName();
}