19package org.openoffice.xmerge.util.registry;
34 private static final ArrayList<ConverterInfo>
converterInfoList =
new ArrayList<ConverterInfo>();
49 if (ci.getDisplayName() ==
null) {
51 "Converter must have valid name.");
54 if (ci.getClassImpl() ==
null) {
56 "Converter must have valid class implementation specified.");
59 if (ci.getOfficeMime() ==
null) {
61 "Converter must have valid office mime specified.");
64 if (! ci.getDeviceMime().hasNext()) {
66 "Converter must have valid device mime specified.");
73 if (ci.getDisplayName().equals(converterInfo.getDisplayName())) {
75 "Converter with specified display name already exists.");
100 public static void addPlugIn(Iterator<ConverterInfo> jarEnum)
103 while (jarEnum.hasNext()) {
180 if (deviceMime ==
null ||
187 String toDeviceInfo = converterInfo.getOfficeMime();
188 Iterator<String> fromEnum = converterInfo.getDeviceMime();
191 while (fromEnum.hasNext()) {
192 String fromDeviceInfo = fromEnum.next();
193 if (deviceMime.trim().equals(fromDeviceInfo) &&
194 officeMime.trim().equals(toDeviceInfo)) {
195 return converterInfo;
217 if (deviceFromMime ==
null || deviceToMime ==
null) {
225 while (cifEnum.hasNext()) {
227 converterInfo[0] = cifEnum.next();
229 Iterator<String> fromEnum = converterInfo[0].
getDeviceMime();
233 while (fromEnum.hasNext()) {
234 String fromDeviceInfo = fromEnum.next();
236 if (deviceFromMime.trim().equals(fromDeviceInfo)) {
241 while (citEnum.hasNext()) {
243 converterInfo[1] = citEnum.next();
249 while (toEnum.hasNext()) {
250 String toDeviceInfo = toEnum.next();
251 if (deviceToMime.trim().equals(toDeviceInfo) &&
252 fromOfficeInfo.equals(toOfficeInfo)) {
255 return converterInfo;
265 static String readLine(BufferedReader br)
throws IOException{
266 String ret = br.readLine();
268 throw new IOException(
"short read");
279 public static void main(String args[]) {
282 boolean validate =
false;
283 InputStreamReader isr =
new InputStreamReader(
System.in);
284 BufferedReader br =
new BufferedReader(isr);
287 boolean exitFlag =
false;
290 System.out.println(
"\nMenu:");
291 System.out.println(
"(L)oad plug-ins from a jar file");
292 System.out.println(
"(D)isplay name unload");
293 System.out.println(
"(J)ar name unload");
294 System.out.println(
"(F)ind ConverterInfo");
295 System.out.println(
"(C)ind ConverterInfo chain");
296 System.out.println(
"(V)iew plug-ins");
297 System.out.println(
"(T)oggle Validation");
298 System.out.println(
"(Q)uit\n");
301 c = readLine(br).toUpperCase().trim().charAt(0);
303 System.out.println(
"Invalid entry");
304 System.out.println(
"Error msg: " + e.getMessage());
315 }
else if (c ==
'L') {
317 System.out.println(
"Enter path to jarfile: ");
319 String jarname = readLine(br).trim();
322 System.out.println(
"Cannot load plug-in ConverterFactory implementation.");
323 System.out.println(
"Error msg: " + e.getMessage());
325 System.out.println(
"Error adding data to registry");
326 System.out.println(
"Error msg: " + e.getMessage());
334 System.out.println(
"Error adding data to registry");
335 System.out.println(
"Error msg: " + e.getMessage());
340 }
else if (c ==
'T') {
342 System.out.println(
"Validation switched off");
345 System.out.println(
"Validation switched on");
348 }
else if (c ==
'D' || c ==
'J') {
351 System.out.println(
"Enter display name: ");
353 System.out.println(
"Enter path to jarfile: ");
367 System.out.println(
"Remove successful.");
369 System.out.println(
"Remove failed.");
373 System.out.println(
"Error removing value from registry");
374 System.out.println(
"Error msg: " + e.getMessage());
379 }
else if (c ==
'F' || c ==
'C') {
381 String findMimeOne =
null;
382 String findMimeTwo =
null;
385 System.out.println(
"Enter device mime: ");
387 System.out.println(
"Enter device from mime: ");
391 findMimeOne = readLine(br).trim();
393 System.out.println(
"Error adding data to registry");
394 System.out.println(
"Error msg: " + e.getMessage());
398 System.out.println(
"Enter office mime: ");
400 System.out.println(
"Enter device to mime: ");
404 findMimeTwo = readLine(br).trim();
406 System.out.println(
"Error adding data to registry");
407 System.out.println(
"Error msg: " + e.getMessage());
412 if (foundInfo !=
null) {
413 System.out.println(
" Found ConverterInfo");
416 System.out.println(
" Did not find ConverterInfo");
421 if (foundInfo !=
null && foundInfo[0] !=
null && foundInfo[1] !=
null ) {
422 System.out.println(
" Found ConverterInfo Chain");
423 System.out.println(
" DisplayName : " + foundInfo[0].getDisplayName());
424 System.out.println(
" DisplayName : " + foundInfo[1].getDisplayName());
426 System.out.println(
" Did not find ConverterInfo");
432 }
else if (c ==
'V') {
437 while (ciEnum.hasNext())
440 System.out.println(
" Displaying converter number " + ciCnt);
449 while (fromEnum.hasNext())
451 System.out.println(
" DeviceMime : (#" + feCnt +
") : " +
456 System.out.println(
" DeviceMime : None specified");
470 System.out.println(
"No converters registered");
473 System.out.println(
"Invalid input");
Manages the converter plug-ins that are currently active.
static ConverterInfo[] findConverterInfoChain(String deviceFromMime, String deviceToMime)
Returns an array of two ConverterInfo objects that can be chained to perform the specified mime type ...
static void addPlugIn(Iterator< ConverterInfo > jarEnum)
Adds a list of converter plug-ins to the registry.
static void main(String args[])
Main to let the user specify what plug-ins to register from jarfiles and to display the currently reg...
static boolean removeByName(String name)
Removes any ConverterInfo object from the registry that have the specified display name value.
static boolean removeByJar(String jar)
Removes any ConverterInfo object from the registry that have the specified jar name value.
static void addPlugIn(ConverterInfo ci)
Adds a converter plug-in to the registry.
static Iterator< ConverterInfo > getConverterInfoEnumeration()
Returns an Enumeration of registered ConverterInfo objects.
static ConverterInfo findConverterInfo(String deviceMime, String officeMime)
Returns the ConverterInfo object that supports the specified device/office mime type conversion.
static final ArrayList< ConverterInfo > converterInfoList
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.
String getVersion()
Returns the version.
boolean canSerialize()
Returns true if this plug-in has a serializer, false otherwise.
static boolean isValidOfficeType(String officeMime)
Returns true if the officeMime is a valid Office mime type.
String getDescription()
Returns the description.
boolean canMerge()
Returns true if this plug-in has a merger, false otherwise.
String getDisplayName()
Returns the display name.
String getVendor()
Returns the vendor name.
String getJarName()
Returns the jar file name.
String getOfficeMime()
Returns the office mime-type.
String getXsltDeserial()
Returns a String containing the xslt stylesheet URL that is to be used by the Xslt Plug-in Deserializ...
String getXsltSerial()
Returns a String containing the Xslt stylesheet URL that is to be used by the Xslt Plug-in Serializer...
boolean canDeserialize()
Returns true if this plug-in has a deserializer, false otherwise.
String getClassImpl()
Returns the implementation class name of PluginFactory.
Iterator< String > getDeviceMime()
Returns an Enumeration of String objects indicating the device mime-type.
This Exception is thrown by converter registry algorithms.