19package org.openoffice.xmerge.test;
22import java.io.FileInputStream;
23import java.io.FileOutputStream;
24import java.util.ArrayList;
25import java.util.Iterator;
54 private final ArrayList<String>
deviceFiles =
new ArrayList<String>();
58 "sxc",
"staroffice/sxc",
59 "sxw",
"staroffice/sxw"
67 public static void main(String args[]) {
70 String propFile =
"ConverterInfoList.properties";
74 while (jarFileEnum.hasNext()) {
75 String jarName = jarFileEnum.next();
81 System.out.println(
"\nCannot not load <" + jarName +
82 "> from the <" + propFile +
"> property file");
89 }
catch (IllegalArgumentException
ex) {
92 if (msg !=
null)
System.out.println(
"\n" + msg);
98 if (msg !=
null)
System.out.println(
"\n" + msg);
103 private static void close(FileOutputStream c) {
104 if (c ==
null)
return;
122 String processFile =
null;
124 if (myConvert ==
null) {
125 System.out.println(
"\nNo plug-in exists to convert from <" +
127 throw new IllegalArgumentException();
132 while (dfEnum.hasNext()) {
133 processFile = dfEnum.next();
138 System.out.println(processFile +
" does not exist!");
141 FileInputStream fis =
new FileInputStream(f);
145 throw new IllegalArgumentException(
"\nFile <" + processFile +
"> is not in <" +
154 System.out.println(
"\nThere was an error in the conversion");
155 convertExcept.printStackTrace();
158 if (dataOut !=
null ) {
162 while (docEnum.hasNext()) {
165 FileOutputStream fos =
null;
167 fos =
new FileOutputStream(fileName);
171 System.out.println(
"\nThere was a writing out file <" +
173 writeExcept.printStackTrace();
180 FileInputStream mergeIS =
new FileInputStream(
mergeFile);
186 merger.
merge(convertedFile);
189 FileOutputStream fos =
null;
198 System.out.println(
"\nThere was an error in the merge");
199 mergeExcept.printStackTrace();
209 System.out.println(
"\nUsage:");
210 System.out.println(
"\n java org.openoffice.xmerge.test.Driver <args>");
211 System.out.println(
"\n where <args> is as follows:");
212 System.out.println(
" -from <MIMETYPE> -to <MIMETYPE> [ -merge <OrigDoc ] <document>\n");
223 throws IllegalArgumentException {
225 if (
args.length == 0) {
226 throw new IllegalArgumentException();
229 for (
int i = 0;
i <
args.length;
i++) {
232 if (
"-to".equals(arg)) {
234 for (
int j = 0; j <
mimeTypes.length; j+=2) {
239 }
else if (
"-from".equals(arg)) {
241 for (
int j = 0; j <
mimeTypes.length; j+=2) {
246 }
else if (
"-merge".equals(arg)) {
250 IllegalArgumentException(
"Arg " +
i +
251 ": expected zip, got " +
261 ((
mergeFile !=
null) ?
" with merge " :
" "));
279 throws IllegalArgumentException {
281 if (
i+1 <
args.length)
284 IllegalArgumentException(
"Arg " +
i +
285 ": expected arg for " +
args[
i]);
295 private boolean isZip(String zipName) {
297 String str = zipName.toLowerCase();
298 return str.endsWith(
"sxw") || zipName.endsWith(
"sxc");
ConvertData is used as a container for passing Document objects in and out of the Convert class.
Iterator< Object > getDocumentEnumeration()
Gets an Enumeration to access the Vector of Document objects.
The Convert class manages a conversion from one mime-type to another.
void addInputStream(String name, InputStream is)
Adds an InputStream to be used as input by the Convert class.
Document getOfficeDocument(String name, InputStream is)
Returns the appropriate "Office" Document object for this plug-in.
DocumentMerger getDocumentMerger(Document origDoc)
Returns a DocumentMerger for the given Document.
ConvertData convert()
Convert the input specified in calls to the addInputStream method to the output format specified by t...
Factory that provides access to Convert objects, which are used to do a conversion.
Convert getConverter(String mimeTypeIn, String mimeTypeOut)
Returns the Convert object that converts the specified device/office mime type conversion.
Loads a properties file so that registry knows which plug-ins it needs to load.
Iterator< String > getJarFileEnum()
Returns an Iterator of String objects.
This class is a command-line driver for the converter framework.
void parseCommandLine(String args[])
Parse command-line arguments.
static void main(String args[])
Main.
String toMime
Command-line parameter.
void doConversion()
Gets a Convert object using the ConverterFactory and does the conversion using this object.
static void close(FileOutputStream c)
static void showUsage()
Display usage.
final ArrayList< String > deviceFiles
Command-line parameter.
String fromMime
Command-line parameter.
boolean isZip(String zipName)
Simple validation for Office ZIP files.
String extractArg(int i, String args[])
Extract the next argument from the array, while checking to see that the array size is not exceeded.
final String mimeTypes[]
Command-line parameter shortcuts.
String mergeFile
mergeFile name.
Manages the converter plug-ins that are currently active.
static void addPlugIn(ConverterInfo ci)
Adds a converter plug-in to the registry.
The ConverterInfoReader pulls a META-INF/converter.xml file out of a jar file and parses it,...
Iterator< ConverterInfo > getConverterInfoEnumeration()
Returns an Enumeration of ConverterInfo objects.
Class for storing the information about a converter plug-in.
A DocumentMerger can merge changes from a modified "Device" Document to the assigned original "Office...
void merge(Document modifiedDoc)
This method will find the changes that had happened in the modifiedDoc Document object given the desi...
A Document represents any Document to be converted and the resulting Document from any conversion.
void write(OutputStream os)
Writes out the Document content to the specified OutputStream.
String getFileName()
Returns the Document name with file extension.
Provides an interface for plug-in registration.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...