maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r709685 - in /maven/doxia/doxia-tools/trunk/doxia-converter/src: main/java/org/apache/maven/doxia/ main/java/org/apache/maven/doxia/cli/ site/apt/ test/java/org/apache/maven/doxia/
Date Sat, 01 Nov 2008 12:24:35 GMT
Author: vsiveton
Date: Sat Nov  1 05:24:35 2008
New Revision: 709685

URL: http://svn.apache.org/viewvc?rev=709685&view=rev
Log:
o added a format flag to format the XML generated files
o updated documentation

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/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=709685&r1=709684&r2=709685&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
Sat Nov  1 05:24:35 2008
@@ -60,4 +60,13 @@
      */
     void convert( InputReaderWrapper input, OutputWriterWrapper output )
         throws UnsupportedFormatException, ConverterException;
+
+    /**
+     * Make the generated files human readable.
+     * <br/>
+     * <b>Note</b>: actually, only XML based outputs could be formatted.
+     *
+     * @param formatOutput <code>true</code> to format the generated files, <code>false</code>
otherwise.
+     */
+    void setFormatOutput( boolean formatOutput );
 }

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=709685&r1=709684&r2=709685&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
Sat Nov  1 05:24:35 2008
@@ -19,6 +19,7 @@
 package org.apache.maven.doxia;
 
 import java.io.BufferedInputStream;
+import java.io.CharArrayWriter;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -116,6 +117,9 @@
     public static final String[] SUPPORTED_TO_FORMAT =
         { APT_SINK, CONFLUENCE_SINK, DOCBOOK_SINK, FO_SINK, ITEXT_SINK, LATEX_SINK, RTF_SINK,
TWIKI_SINK, XDOC_SINK, XHTML_SINK };
 
+    /** Flag to format the generated files, actually only for XML based sinks. */
+    private boolean formatOutput;
+
     /** Plexus container */
     private PlexusContainer plexus;
 
@@ -280,6 +284,12 @@
         }
     }
 
+    /** {@inheritDoc} */
+    public void setFormatOutput( boolean formatOutput )
+    {
+        this.formatOutput = formatOutput;
+    }
+
     // ----------------------------------------------------------------------
     // Private methods
     // ----------------------------------------------------------------------
@@ -403,6 +413,37 @@
         }
 
         parse( parser, inputFormat, reader, sink, writer );
+
+        if ( formatOutput && ( output.getFormat().equals( DOCBOOK_SINK ) || output.getFormat().equals(
FO_SINK )
+            || output.getFormat().equals( ITEXT_SINK ) || output.getFormat().equals( XDOC_SINK
)
+            || output.getFormat().equals( XHTML_SINK ) ) )
+        {
+            // format all xml files excluding docbook which is buggy
+            // TODO Add doc book format
+            if ( output.getFormat().equals( DOCBOOK_SINK ) || inputFormat.equals( DOCBOOK_PARSER
) )
+            {
+                return;
+            }
+            Reader r = null;
+            Writer w = null;
+            try
+            {
+                r = ReaderFactory.newXmlReader( outputFile );
+                CharArrayWriter caw = new CharArrayWriter();
+                XmlUtil.prettyFormat( r, caw );
+                w = WriterFactory.newXmlWriter( outputFile );
+                w.write( caw.toString() );
+            }
+            catch ( IOException e )
+            {
+                throw new ConverterException( "IOException: " + e.getMessage(), e );
+            }
+            finally
+            {
+                IOUtil.close( r );
+                IOUtil.close( w );
+            }
+        }
     }
 
     /**

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=709685&r1=709684&r2=709685&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
Sat Nov  1 05:24:35 2008
@@ -62,6 +62,9 @@
     /** inEncoding String */
     static final String INENCODING = "inEncoding";
 
+    /** f character */
+    static final char FORMAT = 'f';
+
     /** X character */
     static final char DEBUG = 'X';
 
@@ -91,6 +94,10 @@
                                                           "Input file encoding. "
                                                               + "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." )
+                           .create( FORMAT ) );
 
         options.addOption( OptionBuilder.withLongOpt( "debug" )
                                         .withDescription( "Produce execution debug output."
).create( DEBUG ) );

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=709685&r1=709684&r2=709685&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
Sat Nov  1 05:24:35 2008
@@ -161,6 +161,9 @@
             return 1;
         }
 
+        boolean format = commandLine.hasOption( CLIManager.FORMAT );
+        converter.setFormatOutput( format );
+
         try
         {
             converter.convert( input, output );

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=709685&r1=709684&r2=709685&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 Sat Nov  1 05:24:35
2008
@@ -39,16 +39,19 @@
              <arg> -to
 
 Options:
- -e,--errors                           Produce execution error messages
- -from <arg>                           From format
- -h,--help                             Display help information
- -in,--input <arg>                     Input file or directory
- -inEncoding,--inputEncoding <arg>     Input file encoding. If not
-                                       specified, autodetect the input encoding.
- -out,--output <arg>                   Output file or directory
- -to <arg>                             To format
- -v,--version                          Display version information
- -X,--debug                            Produce execution debug output
+ -e,--errors                         Produce execution error messages.
+ -f,--format                         Format the output (actually only xml
+                                     based outputs) to be human readable.
+ -from <arg>                         From format. If not specified, try to
+                                     autodetect it.
+ -h,--help                           Display help information.
+ -in,--input <arg>                   Input file or directory.
+ -inEncoding,--inputEncoding <arg>   Input file encoding. If not
+                                     specified, try to autodetect it.
+ -out,--output <arg>                 Output file or directory.
+ -to <arg>                           To format.
+ -v,--version                        Display version information.
+ -X,--debug                          Produce execution debug output.
 
 Supported Formats:
 from: apt, confluence, docbook, fml, twiki, xdoc, xhtml or autodetect

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=709685&r1=709684&r2=709685&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
Sat Nov  1 05:24:35 2008
@@ -44,7 +44,9 @@
 public class ConverterTest
     extends PlexusTestCase
 {
-    Converter converter;
+    private Converter converter;
+
+    private boolean formatOutput;
 
     /** {@inheritDoc} */
     protected void setUp()
@@ -53,6 +55,8 @@
         super.setUp();
 
         converter = new DefaultConverter();
+
+        formatOutput = Boolean.valueOf( System.getProperty( "format", "false" ) ).booleanValue();
     }
 
     /** {@inheritDoc} */
@@ -99,6 +103,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out, "Doxia.htm.apt" ).exists() );
         assertTrue( new File( out, "Doxia.htm.apt" ).length() != 0 );
@@ -125,6 +130,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -151,6 +157,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -163,6 +170,7 @@
         input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
         output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -187,6 +195,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -199,6 +208,7 @@
         input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
         output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
     }
 
@@ -221,6 +231,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -234,6 +245,7 @@
         // input = InputFileWrapper.valueOf( in, from, converter.getInputFormats() );
         // output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
         //
+        // converter.setFormatOutput( formatOutput );
         // converter.convert( input, output );
         // assertTrue( new File( out ).exists() );
     }
@@ -257,6 +269,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -271,6 +284,7 @@
             input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
             output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             assertFalse( true );
@@ -300,6 +314,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -312,6 +327,7 @@
         input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
         output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
     }
 
@@ -334,6 +350,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -346,6 +363,7 @@
         input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
         output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -370,6 +388,7 @@
         OutputFileWrapper output =
             OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -382,6 +401,7 @@
         input = InputFileWrapper.valueOf( in, from, ReaderFactory.UTF_8, converter.getInputFormats()
);
         output = OutputFileWrapper.valueOf( out, to, converter.getOutputFormats() );
 
+        converter.setFormatOutput( formatOutput );
         converter.convert( input, output );
         assertTrue( new File( out ).exists() );
         assertTrue( new File( out ).length() != 0 );
@@ -416,6 +436,7 @@
                 InputReaderWrapper.valueOf( new FileReader( inFile ), from, converter.getInputFormats()
);
             OutputWriterWrapper output = OutputWriterWrapper.valueOf( writer, to, converter.getOutputFormats()
);
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             IOUtil.copy( writer.toString(), fw );
@@ -459,6 +480,7 @@
             OutputWriterWrapper output =
                 OutputWriterWrapper.valueOf( new FileWriter( outFile ), to, converter.getOutputFormats()
);
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             IOUtil.copy( writer.toString(), fw );
@@ -502,6 +524,7 @@
             OutputFileWrapper output =
                 OutputFileWrapper.valueOf( outFile.getAbsolutePath(), to, converter.getOutputFormats()
);
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             IOUtil.copy( writer.toString(), fw );
@@ -534,6 +557,7 @@
             OutputFileWrapper output =
                 OutputFileWrapper.valueOf( outFile.getAbsolutePath(), to, converter.getOutputFormats()
);
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             IOUtil.copy( writer.toString(), fw );
@@ -564,6 +588,7 @@
             OutputFileWrapper output =
                 OutputFileWrapper.valueOf( outFile.getAbsolutePath(), to, converter.getOutputFormats()
);
 
+            converter.setFormatOutput( formatOutput );
             converter.convert( input, output );
 
             assertFalse( true );



Mime
View raw message