| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package net.sourceforge.jeuclid.converter; |
| 20 | |
|
| 21 | |
import java.lang.reflect.InvocationTargetException; |
| 22 | |
import java.util.HashMap; |
| 23 | |
import java.util.Map; |
| 24 | |
|
| 25 | |
import net.sourceforge.jeuclid.elements.support.ClassLoaderSupport; |
| 26 | |
|
| 27 | |
import org.apache.commons.logging.Log; |
| 28 | |
import org.apache.commons.logging.LogFactory; |
| 29 | |
import org.freehep.util.export.ExportFileType; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public final class FreeHepInternalDetector { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | 209 | private static final Log LOGGER = LogFactory |
| 43 | |
.getLog(FreeHepInternalDetector.class); |
| 44 | |
|
| 45 | 209 | private static final Map<String, String> PLUGINS_CLASSES = new HashMap<String, String>(); |
| 46 | |
|
| 47 | 0 | private FreeHepInternalDetector() { |
| 48 | |
|
| 49 | 0 | } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public static void actuallyDetectConversionPlugins( |
| 58 | |
final ConverterRegistry registry) { |
| 59 | |
|
| 60 | 209 | for (final Map.Entry<String, String> e : FreeHepInternalDetector.PLUGINS_CLASSES |
| 61 | |
.entrySet()) { |
| 62 | |
|
| 63 | |
try { |
| 64 | 1254 | final Class<?> infoClass = ClassLoaderSupport.getInstance() |
| 65 | |
.loadClass(e.getKey()); |
| 66 | 1254 | final ExportFileType fileType = (ExportFileType) infoClass |
| 67 | |
.getConstructor().newInstance(); |
| 68 | |
|
| 69 | 1254 | final Class<?> graphicsClass = ClassLoaderSupport.getInstance() |
| 70 | |
.loadClass(e.getValue()); |
| 71 | 1254 | FreeHepInternalDetector.actuallyRegister(registry, fileType, |
| 72 | |
graphicsClass); |
| 73 | 0 | } catch (final NoSuchMethodException ex) { |
| 74 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 75 | 0 | } catch (final ClassNotFoundException ex) { |
| 76 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 77 | 0 | } catch (final IllegalArgumentException ex) { |
| 78 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 79 | 0 | } catch (final SecurityException ex) { |
| 80 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 81 | 0 | } catch (final InstantiationException ex) { |
| 82 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 83 | 0 | } catch (final IllegalAccessException ex) { |
| 84 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 85 | 0 | } catch (final InvocationTargetException ex) { |
| 86 | 0 | FreeHepInternalDetector.LOGGER.debug(ex); |
| 87 | 2508 | } |
| 88 | |
} |
| 89 | 209 | } |
| 90 | |
|
| 91 | |
private static void actuallyRegister(final ConverterRegistry registry, |
| 92 | |
final ExportFileType fileType, final Class<?> graphicsClass) |
| 93 | |
throws NoSuchMethodException { |
| 94 | 1254 | final ConverterPlugin freeHepConverter = new FreeHepConverter( |
| 95 | |
graphicsClass); |
| 96 | 2717 | for (final String mimeType : fileType.getMIMETypes()) { |
| 97 | 3135 | for (final String suffix : fileType.getExtensions()) { |
| 98 | 1672 | registry.registerMimeTypeAndSuffix(mimeType, suffix, false); |
| 99 | |
} |
| 100 | 1463 | registry.registerConverter(mimeType, freeHepConverter, false); |
| 101 | |
} |
| 102 | 1254 | } |
| 103 | |
|
| 104 | |
static { |
| 105 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 106 | |
"org.freehep.graphicsio.emf.EMFExportFileType", |
| 107 | |
"org.freehep.graphicsio.emf.EMFGraphics2D"); |
| 108 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 109 | |
"org.freehep.graphicsio.gif.GIFExportFileType", |
| 110 | |
"org.freehep.graphicsio.gif.GIFGraphics2D"); |
| 111 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 112 | |
"org.freehep.graphicsio.pdf.PDFExportFileType", |
| 113 | |
"org.freehep.graphicsio.pdf.PDFGraphics2D"); |
| 114 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 115 | |
"org.freehep.graphicsio.ps.PSExportFileType", |
| 116 | |
"org.freehep.graphicsio.ps.PSGraphics2D"); |
| 117 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 118 | |
"org.freehep.graphicsio.svg.SVGExportFileType", |
| 119 | |
"org.freehep.graphicsio.svg.SVGGraphics2D"); |
| 120 | 209 | FreeHepInternalDetector.PLUGINS_CLASSES.put( |
| 121 | |
"org.freehep.graphicsio.swf.SWFExportFileType", |
| 122 | |
"org.freehep.graphicsio.swf.SWFGraphics2D"); |
| 123 | 209 | } |
| 124 | |
} |