Author: hboutemy
Date: Mon Nov 10 14:54:37 2008
New Revision: 712860
URL: http://svn.apache.org/viewvc?rev=712860&view=rev
Log:
DOXIA-185: add back output encoding support in doxia-converter
Added:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java
- copied, changed from r712715,
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputWriterWrapper.java
Removed:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputWriterWrapper.java
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/Converter.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/util/ConverterUtil.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java
maven/doxia/doxia-tools/trunk/doxia-converter/src/site/apt/usage.apt
maven/doxia/doxia-tools/trunk/doxia-converter/src/test/java/org/apache/maven/doxia/ConverterTest.java
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/Converter.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/Converter.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/Converter.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/Converter.java
Mon Nov 10 14:54:37 2008
@@ -23,7 +23,7 @@
import org.apache.maven.doxia.wrapper.InputFileWrapper;
import org.apache.maven.doxia.wrapper.InputReaderWrapper;
import org.apache.maven.doxia.wrapper.OutputFileWrapper;
-import org.apache.maven.doxia.wrapper.OutputWriterWrapper;
+import org.apache.maven.doxia.wrapper.OutputStreamWrapper;
/**
* Interface to convert a Doxia input wrapper to a Doxia output wrapper.
@@ -59,7 +59,7 @@
* @throws UnsupportedFormatException if any
* @throws ConverterException if any
*/
- void convert( InputReaderWrapper input, OutputWriterWrapper output )
+ void convert( InputReaderWrapper input, OutputStreamWrapper output )
throws UnsupportedFormatException, ConverterException;
/**
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
Mon Nov 10 14:54:37 2008
@@ -24,8 +24,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
@@ -41,11 +43,12 @@
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkFactory;
import org.apache.maven.doxia.util.ConverterUtil;
import org.apache.maven.doxia.wrapper.InputFileWrapper;
import org.apache.maven.doxia.wrapper.InputReaderWrapper;
import org.apache.maven.doxia.wrapper.OutputFileWrapper;
-import org.apache.maven.doxia.wrapper.OutputWriterWrapper;
+import org.apache.maven.doxia.wrapper.OutputStreamWrapper;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
@@ -223,7 +226,7 @@
}
/** [EMAIL PROTECTED] */
- public void convert( InputReaderWrapper input, OutputWriterWrapper output )
+ public void convert( InputReaderWrapper input, OutputStreamWrapper output )
throws UnsupportedFormatException, ConverterException
{
if ( input == null )
@@ -262,15 +265,25 @@
getLog().debug( "Parser used: " + parser.getClass().getName()
);
}
- Sink sink;
+ SinkFactory sinkFactory;
try
{
- sink = ConverterUtil.getSink( plexus, output.getFormat(),
output.getWriter(), SUPPORTED_TO_FORMAT );
+ sinkFactory = ConverterUtil.getSinkFactory( plexus,
output.getFormat(), SUPPORTED_TO_FORMAT );
}
catch ( ComponentLookupException e )
{
throw new ConverterException( "ComponentLookupException: " +
e.getMessage(), e );
}
+
+ Sink sink;
+ try
+ {
+ sink = sinkFactory.createSink( output.getOutputStream(),
output.getEncoding() );
+ }
+ catch ( IOException e )
+ {
+ throw new ConverterException( "IOException: " +
e.getMessage(), e );
+ }
sink.enableLogging( log );
if ( getLog().isDebugEnabled() )
@@ -278,7 +291,7 @@
getLog().debug( "Sink used: " + sink.getClass().getName() );
}
- parse( parser, input.getFormat(), input.getReader(), sink,
output.getWriter() );
+ parse( parser, input.getFormat(), input.getReader(), sink );
}
finally
{
@@ -388,25 +401,38 @@
throw new ConverterException( "IOException: " + e.getMessage(), e
);
}
- Writer writer;
+ SinkFactory sinkFactory;
try
{
- writer = WriterFactory.newWriter( outputFile, output.getEncoding()
);
+ sinkFactory = ConverterUtil.getSinkFactory( plexus,
output.getFormat(), SUPPORTED_TO_FORMAT );
}
- catch ( IOException e )
+ catch ( ComponentLookupException e )
{
- throw new ConverterException( "IOException: " + e.getMessage(), e
);
+ throw new ConverterException( "ComponentLookupException: " +
e.getMessage(), e );
}
Sink sink;
try
{
- sink = ConverterUtil.getSink( plexus, output.getFormat(), writer,
SUPPORTED_TO_FORMAT );
+ String outputEncoding;
+ if ( StringUtils.isEmpty( output.getEncoding() )
+ || output.getEncoding().equals(
OutputFileWrapper.AUTO_ENCODING ) )
+ {
+ outputEncoding = inputEncoding;
+ }
+ else
+ {
+ outputEncoding = output.getEncoding();
+ }
+
+ OutputStream out = new FileOutputStream( outputFile );
+ sink = sinkFactory.createSink( out, outputEncoding );
}
- catch ( ComponentLookupException e )
+ catch ( IOException e )
{
- throw new ConverterException( "ComponentLookupException: " +
e.getMessage(), e );
+ throw new ConverterException( "IOException: " + e.getMessage(), e
);
}
+
sink.enableLogging( log );
if ( getLog().isDebugEnabled() )
@@ -414,7 +440,7 @@
getLog().debug( "Sink used: " + sink.getClass().getName() );
}
- parse( parser, inputFormat, reader, sink, writer );
+ parse( parser, inputFormat, reader, sink );
if ( formatOutput && ( output.getFormat().equals( DOCBOOK_SINK ) ||
output.getFormat().equals( FO_SINK )
|| output.getFormat().equals( ITEXT_SINK ) ||
output.getFormat().equals( XDOC_SINK )
@@ -455,7 +481,7 @@
* @param writer not null
* @throws ConverterException if any
*/
- private void parse( Parser parser, String inputFormat, Reader reader, Sink
sink, Writer writer )
+ private void parse( Parser parser, String inputFormat, Reader reader, Sink
sink )
throws ConverterException
{
// add warnings
@@ -479,7 +505,6 @@
IOUtil.close( reader );
sink.flush();
sink.close();
- IOUtil.close( writer );
}
}
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/CLIManager.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/CLIManager.java
Mon Nov 10 14:54:37 2008
@@ -66,6 +66,9 @@
/** f character */
static final char FORMAT = 'f';
+ /** outEncoding String */
+ static final String OUTENCODING = "outEncoding";
+
/** X character */
static final char DEBUG = 'X';
@@ -95,9 +98,13 @@
+ "If not
specified, try to autodetect it." )
.hasArg().create( INENCODING ) );
OPTIONS.addOption( OptionBuilder.withLongOpt( "format" )
- .withDescription( "Format the output (actually only
xml based outputs) "
- + " to be human readable." )
+ .withDescription( "Format the output
(actually only xml based outputs) "
+ + " to be human
readable." )
.create( FORMAT ) );
+ OPTIONS.addOption( OptionBuilder.withLongOpt( "outputEncoding" )
+ .withDescription( "Output file
encoding. If not specified, use the "
+ + "input
encoding (or autodetected)." ).hasArg()
+ .create( OUTENCODING ) );
OPTIONS.addOption( OptionBuilder.withLongOpt( "debug" )
.withDescription( "Produce execution
debug output." ).create( DEBUG ) );
@@ -132,7 +139,7 @@
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "doxia [options] -in <arg> [-from <arg>]
[-inEncoding <arg>] -out <arg> "
- + "-to <arg>\n", "\nOptions:", OPTIONS,
getSupportedFormatAndEncoding() );
+ + "-to <arg> [-outEncoding <arg>]\n", "\nOptions:", OPTIONS,
getSupportedFormatAndEncoding() );
}
private static String getSupportedFormatAndEncoding()
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/cli/ConverterCli.java
Mon Nov 10 14:54:37 2008
@@ -139,6 +139,7 @@
output =
OutputFileWrapper.valueOf( commandLine.getOptionValue(
CLIManager.OUT ),
commandLine.getOptionValue(
CLIManager.TO ),
+ commandLine.getOptionValue(
CLIManager.OUTENCODING ),
converter.getOutputFormats() );
}
catch ( IllegalArgumentException e )
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/util/ConverterUtil.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/util/ConverterUtil.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/util/ConverterUtil.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/util/ConverterUtil.java
Mon Nov 10 14:54:37 2008
@@ -19,11 +19,10 @@
* under the License.
*/
-import java.io.Writer;
+import java.io.IOException;
import org.apache.maven.doxia.UnsupportedFormatException;
import org.apache.maven.doxia.parser.Parser;
-import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkFactory;
import org.codehaus.plexus.PlexusContainer;
import
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@@ -81,16 +80,14 @@
/**
* @param plexus not null
* @param format not null
- * @param writer not null writer to write the result. <b>Should</b> be an
UTF-8 Writer such as defines in
- * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}. You could use
<code>newWriter</code> methods from
- * [EMAIL PROTECTED] org.codehaus.plexus.util.WriterFactory}.
* @param supportedFormats not null
- * @return an instance of <code>Sink</code> depending on the given format.
+ * @return an instance of <code>SinkFactory</code> depending on the given
format.
* @throws ComponentLookupException if could not find the SinkFactory for
the given format.
* @throws UnsupportedFormatException if the found sink is not
instantiated.
+ * @throws IOException
* @throws IllegalArgumentException if any parameter is null
*/
- public static Sink getSink( PlexusContainer plexus, String format, Writer
writer, String[] supportedFormats )
+ public static SinkFactory getSinkFactory( PlexusContainer plexus, String
format, String[] supportedFormats )
throws ComponentLookupException, UnsupportedFormatException
{
if ( plexus == null )
@@ -120,12 +117,6 @@
throw new UnsupportedFormatException( format, supportedFormats );
}
- Sink sink = factory.createSink( writer );
- if ( sink == null )
- {
- throw new IllegalArgumentException( "Sink was not instanciated: "
+ format );
- }
-
- return sink;
+ return factory;
}
}
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputFileWrapper.java
Mon Nov 10 14:54:37 2008
@@ -41,14 +41,15 @@
*
* @param file not null
* @param format not null
+ * @param charsetName could be null
* @param supportedFormat not null.
* @throws IllegalArgumentException if any.
* @throws UnsupportedEncodingException if the encoding is unsupported.
*/
- private OutputFileWrapper( String absolutePath, String format, String[]
supportedFormat )
+ private OutputFileWrapper( String absolutePath, String format, String
charsetName, String[] supportedFormat )
throws UnsupportedEncodingException
{
- super( absolutePath, format, WriterFactory.UTF_8, supportedFormat );
+ super( absolutePath, format, charsetName, supportedFormat );
if ( getFormat().equalsIgnoreCase( AUTO_FORMAT ) )
{
@@ -60,27 +61,33 @@
* @param absolutePath not null
* @param format not null
* @param supportedFormat not null
- * @return a type safe output writer using UTF-8 as encoding such as
defines in
- * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}.
+ * @return a type safe output writer
* @throws IllegalArgumentException if any.
* @throws UnsupportedEncodingException if the encoding is unsupported.
*/
public static OutputFileWrapper valueOf( String absolutePath, String
format, String[] supportedFormat )
throws IllegalArgumentException, UnsupportedEncodingException
{
- if ( StringUtils.isEmpty( format ) )
- {
- throw new IllegalArgumentException( "output format is required" );
- }
- return new OutputFileWrapper( absolutePath, format, supportedFormat );
+ return valueOf( absolutePath, format, WriterFactory.UTF_8,
supportedFormat );
}
-
/**
- * @return always the encoding UTF-8 to be used for the file.
+ * @param absolutePath not null
+ * @param format not null
+ * @param charsetName could be null
+ * @param supportedFormat not null
+ * @return a type safe output writer
+ * @throws IllegalArgumentException if any.
+ * @throws UnsupportedEncodingException if the encoding is unsupported.
*/
- public String getEncoding()
+ public static OutputFileWrapper valueOf( String absolutePath, String
format, String charsetName,
+ String[] supportedFormat )
+ throws IllegalArgumentException, UnsupportedEncodingException
{
- return WriterFactory.UTF_8;
+ if ( StringUtils.isEmpty( format ) )
+ {
+ throw new IllegalArgumentException( "output format is required" );
+ }
+ return new OutputFileWrapper( absolutePath, format, charsetName,
supportedFormat );
}
}
Copied:
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java
(from r712715,
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputWriterWrapper.java)
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java?p2=maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java&p1=maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputWriterWrapper.java&r1=712715&r2=712860&rev=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputWriterWrapper.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/wrapper/OutputStreamWrapper.java
Mon Nov 10 14:54:37 2008
@@ -19,36 +19,36 @@
* under the License.
*/
+import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import org.codehaus.plexus.util.StringUtils;
/**
- * Wrapper for an output writer.
+ * Wrapper for an output stream.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Siveton</a>
* @version $Id$
*/
-public class OutputWriterWrapper
+public class OutputStreamWrapper
extends AbstractWrapper
{
/** serialVersionUID */
static final long serialVersionUID = 3329037527245430610L;
- private Writer writer;
+ private OutputStream out;
+
+ private String encoding;
/**
* Private constructor.
*
- * @param writer not null writer to write the result. <b>Should</b> be an
UTF-8 Writer such as defines in
- * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}. You could use
<code>newWriter</code> methods from
- * [EMAIL PROTECTED] org.codehaus.plexus.util.WriterFactory}.
* @param format not null
* @param supportedFormat not null
* @throws IllegalArgumentException if any.
*/
- private OutputWriterWrapper( Writer writer, String format, String[]
supportedFormat )
+ private OutputStreamWrapper( OutputStream out, String format, String
encoding, String[] supportedFormat )
{
super( format, supportedFormat );
@@ -57,32 +57,38 @@
throw new IllegalArgumentException( "output format is required" );
}
- this.writer = writer;
+ this.out = out;
+ this.encoding = encoding;
+ }
+
+ /**
+ * @return the output stream
+ */
+ public OutputStream getOutputStream()
+ {
+ return this.out;
}
/**
- * @return the writer. <b>Should</b> be an UTF-8 Writer such as defines in
- * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}.
+ * @return the encoding
*/
- public Writer getWriter()
+ public String getEncoding()
{
- return this.writer;
+ return encoding;
}
/**
- * @param writer not null writer to write the result. <b>Should</b> be an
UTF-8 Writer such as defines in
- * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}. You could use
<code>newWriter</code> methods from
- * [EMAIL PROTECTED] org.codehaus.plexus.util.WriterFactory}.
+ * @param out not null
* @param format not null
* @param supportedFormat not null
- * @return a type safe output writer
+ * @return a type safe output stream wrapper
* @throws IllegalArgumentException if any.
* @throws UnsupportedEncodingException if the encoding is unsupported.
*/
- public static OutputWriterWrapper valueOf( Writer writer, String format,
String[] supportedFormat )
+ public static OutputStreamWrapper valueOf( OutputStream out, String
format, String encoding, String[] supportedFormat )
throws IllegalArgumentException
{
- if ( writer == null )
+ if ( out == null )
{
throw new IllegalArgumentException( "output writer is required" );
}
@@ -91,6 +97,6 @@
throw new IllegalArgumentException( "output format is required" );
}
- return new OutputWriterWrapper( writer, format, supportedFormat );
+ return new OutputStreamWrapper( out, format, encoding, supportedFormat
);
}
}
Modified: maven/doxia/doxia-tools/trunk/doxia-converter/src/site/apt/usage.apt
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/site/apt/usage.apt?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-converter/src/site/apt/usage.apt
(original)
+++ maven/doxia/doxia-tools/trunk/doxia-converter/src/site/apt/usage.apt Mon
Nov 10 14:54:37 2008
@@ -36,7 +36,7 @@
# java -jar target/apache-doxia-1.0-SNAPSHOT-jar-with-dependencies.jar -h
usage: doxia [options] -in <arg> [-from <arg>] [-inEncoding <arg>] -out
- <arg> -to
+ <arg> -to <arg> [-outEncoding <arg>]
Options:
-e,--errors Produce execution error messages.
@@ -49,6 +49,8 @@
-inEncoding,--inputEncoding <arg> Input file encoding. If not
specified, try to autodetect it.
-out,--output <arg> Output file or directory.
+ -outEncoding,--outputEncoding <arg> Output file encoding. If not
+ specified, use the input encoding (or
detected).
-to <arg> To format.
-v,--version Display version information.
-X,--debug Produce execution debug output.
@@ -90,7 +92,7 @@
try
{
InputFileWrapper input = InputFileWrapper.valueOf( in, from, "ISO-8859-1",
converter.getInputFormats() );
- OutputFileWrapper output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ OutputFileWrapper output = OutputFileWrapper.valueOf( out, to, "UTF-8",
converter.getOutputFormats() );
converter.convert( input, output );
}
Modified:
maven/doxia/doxia-tools/trunk/doxia-converter/src/test/java/org/apache/maven/doxia/ConverterTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/test/java/org/apache/maven/doxia/ConverterTest.java?rev=712860&r1=712859&r2=712860&view=diff
==============================================================================
---
maven/doxia/doxia-tools/trunk/doxia-converter/src/test/java/org/apache/maven/doxia/ConverterTest.java
(original)
+++
maven/doxia/doxia-tools/trunk/doxia-converter/src/test/java/org/apache/maven/doxia/ConverterTest.java
Mon Nov 10 14:54:37 2008
@@ -19,9 +19,12 @@
* under the License.
*/
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.OutputStream;
import java.io.StringWriter;
import junitx.util.PrivateAccessor;
@@ -29,11 +32,12 @@
import org.apache.maven.doxia.wrapper.InputFileWrapper;
import org.apache.maven.doxia.wrapper.InputReaderWrapper;
import org.apache.maven.doxia.wrapper.OutputFileWrapper;
-import org.apache.maven.doxia.wrapper.OutputWriterWrapper;
+import org.apache.maven.doxia.wrapper.OutputStreamWrapper;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.WriterFactory;
/**
* Tests Doxia converter.
@@ -101,7 +105,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -128,7 +132,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -155,7 +159,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -168,7 +172,7 @@
to = "apt";
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -193,7 +197,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -206,7 +210,7 @@
to = "confluence";
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -229,7 +233,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -267,7 +271,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -282,7 +286,7 @@
try
{
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -312,7 +316,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -325,7 +329,7 @@
to = "twiki";
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
try
@@ -359,7 +363,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -372,7 +376,7 @@
to = "xdoc";
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -397,7 +401,7 @@
InputFileWrapper input =
InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
OutputFileWrapper output =
- OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
+ OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -410,7 +414,7 @@
to = "xhtml";
input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8,
converter.getInputFormats() );
- output = OutputFileWrapper.valueOf( out, to,
converter.getOutputFormats() );
+ output = OutputFileWrapper.valueOf( out, to, WriterFactory.UTF_8,
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
@@ -421,7 +425,7 @@
/**
* Input apt reader / output writer
*
- * @see Converter#convert(InputReaderWrapper, OutputWriterWrapper)
+ * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper)
* @throws Exception if any
*/
public void testAptWriterConverter()
@@ -436,25 +440,25 @@
File outFile = new File( out );
outFile.getParentFile().mkdirs();
- FileWriter fw = null;
+ OutputStream fo = null;
try
{
- fw = new FileWriter( outFile );
+ fo = new FileOutputStream( outFile );
- StringWriter writer = new StringWriter();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputReaderWrapper input =
InputReaderWrapper.valueOf( new FileReader( inFile ), from,
converter.getInputFormats() );
- OutputWriterWrapper output = OutputWriterWrapper.valueOf( writer,
to, converter.getOutputFormats() );
+ OutputStreamWrapper output = OutputStreamWrapper.valueOf(
outputStream, to, "UTF-8", converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
- IOUtil.copy( writer.toString(), fw );
+ IOUtil.copy( outputStream.toByteArray(), fo );
}
finally
{
- IOUtil.close( fw );
+ IOUtil.close( fo );
}
assertTrue( outFile.exists() );
@@ -464,7 +468,7 @@
/**
* Input confluence reader / output writer
*
- * @see Converter#convert(InputReaderWrapper, OutputWriterWrapper)
+ * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper)
* @throws Exception if any
*/
public void testConfluenceWriterConverter()
@@ -479,36 +483,36 @@
File outFile = new File( out );
outFile.getParentFile().mkdirs();
- FileWriter fw = null;
+ OutputStream fo = null;
try
{
- fw = new FileWriter( outFile );
+ fo = new FileOutputStream( outFile );
- StringWriter writer = new StringWriter();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputReaderWrapper input =
InputReaderWrapper.valueOf( new FileReader( inFile ), from,
converter.getInputFormats() );
- OutputWriterWrapper output =
- OutputWriterWrapper.valueOf( new FileWriter( outFile ), to,
converter.getOutputFormats() );
+ OutputStreamWrapper output =
+ OutputStreamWrapper.valueOf( outputStream, to, "UTF-8",
converter.getOutputFormats() );
converter.setFormatOutput( formatOutput );
converter.convert( input, output );
- IOUtil.copy( writer.toString(), fw );
-
- assertTrue( outFile.exists() );
- assertTrue( outFile.length() != 0 );
+ IOUtil.copy( outputStream.toByteArray(), fo );
}
finally
{
- IOUtil.close( fw );
+ IOUtil.close( fo );
}
+
+ assertTrue( outFile.exists() );
+ assertTrue( outFile.length() != 0 );
}
/**
* Input xdoc (autodetect) reader / output writer
*
- * @see Converter#convert(InputReaderWrapper, OutputWriterWrapper)
+ * @see Converter#convert(InputReaderWrapper, OutputStreamWrapper)
* @throws Exception if any
*/
public void testAutoDetectConverter()