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