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.lang.reflect.Method;
23
24 import net.sourceforge.jeuclid.elements.generic.JEuclidDOMImplementation;
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.w3c.dom.DOMImplementation;
30
31
32
33
34
35
36 public final class BatikDetector implements ConverterDetector {
37
38
39
40 private static final Log LOGGER = LogFactory.getLog(BatikDetector.class);
41
42
43
44
45 public BatikDetector() {
46
47 }
48
49 private static DOMImplementation findSVGDOMImplementation() {
50 DOMImplementation impl;
51 try {
52 final Class<?> svgdomimpl = ClassLoaderSupport.getInstance()
53 .loadClass(
54 "org.apache.batik.dom.svg.SVGDOMImplementation");
55 final Method getDOMimpl = svgdomimpl.getMethod(
56 "getDOMImplementation", new Class<?>[] {});
57 impl = (DOMImplementation) getDOMimpl.invoke(null,
58 (Object[]) null);
59
60
61
62 } catch (final RuntimeException e) {
63
64 impl = null;
65 } catch (final LinkageError e) {
66 impl = null;
67 } catch (final ClassNotFoundException e) {
68 impl = null;
69 } catch (final NoSuchMethodException e) {
70 impl = null;
71 } catch (final IllegalAccessException e) {
72 impl = null;
73 } catch (final InvocationTargetException e) {
74 impl = null;
75 }
76 if (impl == null) {
77 impl = JEuclidDOMImplementation.getInstance();
78 }
79 return impl;
80 }
81
82
83
84
85
86
87
88 public void detectConversionPlugins(final ConverterRegistry registry) {
89 try {
90 ClassLoaderSupport.getInstance().loadClass(
91 "org.apache.batik.svggen.SVGGraphics2D");
92 BatikDetector.LOGGER.debug("Batik detected!");
93 registry
94 .registerMimeTypeAndSuffix(
95 net.sourceforge.jeuclid.converter.Converter.TYPE_SVG,
96 net.sourceforge.jeuclid.converter.Converter.EXTENSION_SVG,
97 true);
98 final DOMImplementation impl = BatikDetector
99 .findSVGDOMImplementation();
100 if (impl != null) {
101 registry.registerConverter(
102 net.sourceforge.jeuclid.converter.Converter.TYPE_SVG,
103 new BatikConverter(impl), true);
104 }
105 } catch (final ClassNotFoundException e) {
106 BatikDetector.LOGGER.debug("Batik is not in classpath!");
107 }
108 }
109
110 }