以下示例描述了 Doxia 转换器的基本用法。
# java -jar target/apache-doxia-1.2-jar-with-dependencies.jar -h
usage: doxia [options] -in <arg> [-from <arg>] [-inEncoding <arg>] -out
<arg> -to <arg> [-outEncoding <arg>]
Options:
-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.
-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.
Supported Formats:
from: apt, confluence, docbook, fml, twiki, xdoc, xhtml or autodetect
out: apt, docbook, fo, itext, latex, rtf, xdoc, xhtml
Supported Encoding:
UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE, Shift_JIS, ISO-2022-JP,
ISO-2022-CN, ISO-2022-KR, GB18030, EUC-JP, EUC-KR, Big5, ISO-8859-1,
ISO-8859-2, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, windows-1251,
windows-1256, KOI8-R, ISO-8859-9
注意:可以自动检测输入参数(即编码和格式)。
# java -jar target/apache-doxia-1.2-jar-with-dependencies.jar \
-in /path/to/xhtml.file \
-from xhtml \
-out /path/to/outputdir \
-to apt
注意:from参数可以为空。在这种情况下,Doxia 转换器会尝试从in文件参数中自动检测from输入。
String in = "...";
String from = "...";
String out = "...";
String to = "...";
Converter converter = new DefaultConverter();
try
{
InputFileWrapper input = InputFileWrapper.valueOf( in, from, "ISO-8859-1", converter.getInputFormats() );
OutputFileWrapper output = OutputFileWrapper.valueOf( out, to, "UTF-8", converter.getOutputFormats() );
converter.convert( input, output );
}
catch ( UnsupportedFormatException e )
{
e.printStackTrace();
}
catch ( ConverterException e )
{
e.printStackTrace();
}