|
15 | 15 | import org.apache.fop.apps.Fop; |
16 | 16 | import org.apache.fop.apps.FopFactory; |
17 | 17 | import org.apache.fop.apps.MimeConstants; |
| 18 | +import org.apache.xmlgraphics.io.ResourceResolver; |
18 | 19 | import org.fugerit.java.core.cfg.ConfigException; |
| 20 | +import org.fugerit.java.core.lang.helpers.ClassHelper; |
19 | 21 | import org.fugerit.java.core.lang.helpers.StringUtils; |
20 | 22 | import org.fugerit.java.core.xml.dom.DOMUtils; |
21 | 23 | import org.fugerit.java.doc.base.config.DocConfig; |
22 | 24 | import org.fugerit.java.doc.base.config.DocInput; |
23 | 25 | import org.fugerit.java.doc.base.config.DocOutput; |
24 | 26 | import org.fugerit.java.doc.base.config.DocTypeHandler; |
| 27 | +import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolver; |
| 28 | +import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolverWrapper; |
25 | 29 | import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoader; |
| 30 | +import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper; |
26 | 31 | import org.w3c.dom.Element; |
27 | 32 | import org.w3c.dom.NodeList; |
28 | 33 |
|
29 | 34 | public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler { |
30 | 35 |
|
31 | 36 | public static final DocTypeHandler HANDLER = new PdfFopTypeHandler(); |
32 | 37 |
|
| 38 | + public static final String ATT_FOP_CONFIG_MODE = "fop-config-mode"; |
| 39 | + public static final String ATT_FOP_CONFIG_MODE_DEFAULT = "default"; |
| 40 | + public static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER = "classloader"; |
| 41 | + @Deprecated |
| 42 | + public static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY = "classloader-legacy"; |
| 43 | + |
33 | 44 | public static final String ATT_FOP_CONFIG_CLASSLOADER_PATH = "fop-config-classloader-path"; |
| 45 | + |
| 46 | + public static final String ATT_FOP_CONFIG_RESOLVER_TYPE = "fop-config-resover-type"; |
| 47 | + public static final String ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT = ClassLoaderResourceResolverWrapper.class.getName(); |
| 48 | + |
| 49 | + @Deprecated |
34 | 50 | public static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path"; |
35 | 51 |
|
36 | 52 | public static final boolean DEFAULT_ACCESSIBILITY = true; |
@@ -104,10 +120,26 @@ public void configure(Element tag) throws ConfigException { |
104 | 120 | if ( nl.getLength() > 0 ) { |
105 | 121 | Element config = (Element)nl.item( 0 ); |
106 | 122 | Properties props = DOMUtils.attributesToProperties( config ); |
| 123 | + String fopConfigMode = props.getProperty( ATT_FOP_CONFIG_MODE ); |
107 | 124 | String fopConfigClassloaderPath = props.getProperty( ATT_FOP_CONFIG_CLASSLOADER_PATH ); |
| 125 | + String fopConfigResoverType = props.getProperty( ATT_FOP_CONFIG_RESOLVER_TYPE, ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT ); |
108 | 126 | String fontBaseClassloaderPath = props.getProperty( ATT_FONT_BASE_CLASSLOADER_PATH ); |
109 | | - if ( StringUtils.isNotEmpty( fopConfigClassloaderPath ) && StringUtils.isNotEmpty( fontBaseClassloaderPath ) ) { |
110 | | - FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, fontBaseClassloaderPath); |
| 127 | + // legacy class loader mode |
| 128 | + if ( StringUtils.isEmpty( fopConfigMode ) && StringUtils.isNotEmpty( fopConfigClassloaderPath ) && StringUtils.isNotEmpty( fontBaseClassloaderPath ) ) { |
| 129 | + fopConfigMode = ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY; |
| 130 | + logger.warn( "Activated legacy ClassLoader mode. It is strongly recomended to update te configuration {} -> {}", ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY, ClassLoaderResourceResolver.MIN_VERSION_NEW_CLASSLOADER_MODE ); |
| 131 | + } |
| 132 | + if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER.equalsIgnoreCase( fopConfigMode ) ) { |
| 133 | + try { |
| 134 | + ResourceResolver customResourceResolver = (ResourceResolver) ClassHelper.newInstance( fopConfigResoverType ); |
| 135 | + FopConfigClassLoaderWrapper fopConfigClassLoaderWrapper = new FopConfigClassLoaderWrapper(fopConfigClassloaderPath, customResourceResolver); |
| 136 | + this.fopConfig = fopConfigClassLoaderWrapper; |
| 137 | + } catch (Exception e) { |
| 138 | + throw new ConfigException( PdfFopTypeHandler.class.getSimpleName()+" configuration error : "+e, e ); |
| 139 | + } |
| 140 | + } else if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY.equalsIgnoreCase( fopConfigMode ) ) { |
| 141 | + ClassLoaderResourceResolver customResourceResolver = new ClassLoaderResourceResolver( fontBaseClassloaderPath ); |
| 142 | + FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, customResourceResolver); |
111 | 143 | this.fopConfig = fopConfigClassLoader; |
112 | 144 | } |
113 | 145 | } |
|
0 commit comments