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 private static final Log LOGGER = LogFactory
43 .getLog(FreeHepInternalDetector.class);
44
45 private static final Map<String, String> PLUGINS_CLASSES = new HashMap<String, String>();
46
47 private FreeHepInternalDetector() {
48
49 }
50
51
52
53
54
55
56
57 public static void actuallyDetectConversionPlugins(
58 final ConverterRegistry registry) {
59
60 for (final Map.Entry<String, String> e : FreeHepInternalDetector.PLUGINS_CLASSES
61 .entrySet()) {
62
63 try {
64 final Class<?> infoClass = ClassLoaderSupport.getInstance()
65 .loadClass(e.getKey());
66 final ExportFileType fileType = (ExportFileType) infoClass
67 .getConstructor().newInstance();
68
69 final Class<?> graphicsClass = ClassLoaderSupport.getInstance()
70 .loadClass(e.getValue());
71 FreeHepInternalDetector.actuallyRegister(registry, fileType,
72 graphicsClass);
73 } catch (final NoSuchMethodException ex) {
74 FreeHepInternalDetector.LOGGER.debug(ex);
75 } catch (final ClassNotFoundException ex) {
76 FreeHepInternalDetector.LOGGER.debug(ex);
77 } catch (final IllegalArgumentException ex) {
78 FreeHepInternalDetector.LOGGER.debug(ex);
79 } catch (final SecurityException ex) {
80 FreeHepInternalDetector.LOGGER.debug(ex);
81 } catch (final InstantiationException ex) {
82 FreeHepInternalDetector.LOGGER.debug(ex);
83 } catch (final IllegalAccessException ex) {
84 FreeHepInternalDetector.LOGGER.debug(ex);
85 } catch (final InvocationTargetException ex) {
86 FreeHepInternalDetector.LOGGER.debug(ex);
87 }
88 }
89 }
90
91 private static void actuallyRegister(final ConverterRegistry registry,
92 final ExportFileType fileType, final Class<?> graphicsClass)
93 throws NoSuchMethodException {
94 final ConverterPlugin freeHepConverter = new FreeHepConverter(
95 graphicsClass);
96 for (final String mimeType : fileType.getMIMETypes()) {
97 for (final String suffix : fileType.getExtensions()) {
98 registry.registerMimeTypeAndSuffix(mimeType, suffix, false);
99 }
100 registry.registerConverter(mimeType, freeHepConverter, false);
101 }
102 }
103
104 static {
105 FreeHepInternalDetector.PLUGINS_CLASSES.put(
106 "org.freehep.graphicsio.emf.EMFExportFileType",
107 "org.freehep.graphicsio.emf.EMFGraphics2D");
108 FreeHepInternalDetector.PLUGINS_CLASSES.put(
109 "org.freehep.graphicsio.gif.GIFExportFileType",
110 "org.freehep.graphicsio.gif.GIFGraphics2D");
111 FreeHepInternalDetector.PLUGINS_CLASSES.put(
112 "org.freehep.graphicsio.pdf.PDFExportFileType",
113 "org.freehep.graphicsio.pdf.PDFGraphics2D");
114 FreeHepInternalDetector.PLUGINS_CLASSES.put(
115 "org.freehep.graphicsio.ps.PSExportFileType",
116 "org.freehep.graphicsio.ps.PSGraphics2D");
117 FreeHepInternalDetector.PLUGINS_CLASSES.put(
118 "org.freehep.graphicsio.svg.SVGExportFileType",
119 "org.freehep.graphicsio.svg.SVGGraphics2D");
120 FreeHepInternalDetector.PLUGINS_CLASSES.put(
121 "org.freehep.graphicsio.swf.SWFExportFileType",
122 "org.freehep.graphicsio.swf.SWFGraphics2D");
123 }
124 }