Skip to content

Commit b51a31e

Browse files
committed
+ fj-doc-mod-fop Fixed legacy compatibility of FopConfigClassLoader see
[0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)ù
1 parent f1c4c70 commit b51a31e

File tree

3 files changed

+11
-54
lines changed

3 files changed

+11
-54
lines changed

fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/PdfFopTypeHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.fugerit.java.doc.base.config.DocInput;
2525
import org.fugerit.java.doc.base.config.DocOutput;
2626
import org.fugerit.java.doc.base.config.DocTypeHandler;
27-
import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolver;
2827
import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolverWrapper;
2928
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoader;
3029
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
@@ -127,7 +126,7 @@ public void configure(Element tag) throws ConfigException {
127126
// legacy class loader mode
128127
if ( StringUtils.isEmpty( fopConfigMode ) && StringUtils.isNotEmpty( fopConfigClassloaderPath ) && StringUtils.isNotEmpty( fontBaseClassloaderPath ) ) {
129128
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 );
129+
logger.warn( "Activated legacy ClassLoader mode. It is strongly recomended to update te configuration {} -> {}", ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY, FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE );
131130
}
132131
if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER.equalsIgnoreCase( fopConfigMode ) ) {
133132
try {
@@ -138,8 +137,7 @@ public void configure(Element tag) throws ConfigException {
138137
throw new ConfigException( PdfFopTypeHandler.class.getSimpleName()+" configuration error : "+e, e );
139138
}
140139
} else if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY.equalsIgnoreCase( fopConfigMode ) ) {
141-
ClassLoaderResourceResolver customResourceResolver = new ClassLoaderResourceResolver( fontBaseClassloaderPath );
142-
FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, customResourceResolver);
140+
FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, fontBaseClassloaderPath);
143141
this.fopConfig = fopConfigClassLoader;
144142
}
145143
}

fj-doc-mod-fop/src/main/java/org/fugerit/java/doc/mod/fop/config/ClassLoaderResourceResolver.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
@Deprecated
2626
public class ClassLoaderResourceResolver implements ResourceResolver, Serializable {
2727

28-
public static final String MIN_VERSION_NEW_CLASSLOADER_MODE = "[0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)";
29-
3028
private static final Logger logger = LoggerFactory.getLogger( ClassLoaderResourceResolver.class );
3129

3230
private String defaultFontPath;
@@ -51,14 +49,14 @@ public ClassLoaderResourceResolver(String defaultFontPath) {
5149

5250
@Override
5351
public OutputStream getOutputStream(URI uri) throws IOException {
54-
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), MIN_VERSION_NEW_CLASSLOADER_MODE );
52+
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE );
5553
return Thread.currentThread().getContextClassLoader().getResource(uri.toString()).openConnection().getOutputStream();
5654
}
5755

5856
@Override
5957
public Resource getResource(URI uri) throws IOException {
6058
try {
61-
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), MIN_VERSION_NEW_CLASSLOADER_MODE );
59+
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE );
6260
String path = this.defaultFontPath+uri.getPath().substring( uri.getPath().lastIndexOf( "/")+1 );
6361
InputStream inputStream = ClassHelper.loadFromDefaultClassLoader( path );
6462
return new Resource(inputStream);
Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
package org.fugerit.java.doc.mod.fop.config;
22

3-
import java.io.InputStream;
4-
import java.io.Serializable;
5-
import java.net.URI;
6-
7-
import org.apache.fop.apps.EnvironmentalProfileFactory;
8-
import org.apache.fop.apps.FopConfParser;
9-
import org.apache.fop.apps.FopFactory;
10-
import org.apache.fop.apps.FopFactoryBuilder;
11-
import org.apache.xmlgraphics.io.ResourceResolver;
12-
import org.fugerit.java.core.lang.helpers.ClassHelper;
13-
import org.fugerit.java.doc.mod.fop.FopConfig;
14-
15-
public class FopConfigClassLoader implements FopConfig, Serializable {
3+
/*
4+
* Left only for compatibility with versions previous of 0.5.2
5+
*/
6+
@Deprecated
7+
public class FopConfigClassLoader extends FopConfigClassLoaderWrapper {
168

179
/**
1810
*
1911
*/
2012
private static final long serialVersionUID = 188843074194800812L;
2113

22-
private String fopConfigPath;
23-
24-
public String getFopConfigPath() {
25-
return fopConfigPath;
26-
}
27-
28-
private ResourceResolver customResourceResolver;
29-
30-
public ResourceResolver getCustomResourceResolver() {
31-
return customResourceResolver;
32-
}
14+
public static final String MIN_VERSION_NEW_CLASSLOADER_MODE = "[0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)";
3315

3416
/**
3517
* Provided only for compatibility
@@ -41,28 +23,7 @@ public ResourceResolver getCustomResourceResolver() {
4123
*/
4224
@Deprecated
4325
public FopConfigClassLoader(String fopConfigPath, String defaultFontPath) {
44-
this( fopConfigPath, new ClassLoaderResourceResolver( defaultFontPath ) );
45-
}
46-
47-
public FopConfigClassLoader(String fopConfigPath) {
48-
this( fopConfigPath, new ClassLoaderResourceResolverWrapper() );
49-
}
50-
51-
public FopConfigClassLoader(String fopConfigPath, ResourceResolver customResourceResolver) {
52-
super();
53-
this.fopConfigPath = fopConfigPath;
54-
this.customResourceResolver = customResourceResolver;
55-
}
56-
57-
@Override
58-
public FopFactory newFactory() throws Exception {
59-
FopFactory fopFactory = null;
60-
try ( InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() ) ) {
61-
FopConfParser confParser = new FopConfParser( fopConfigStream, EnvironmentalProfileFactory.createRestrictedIO(new URI("."), this.customResourceResolver) );
62-
FopFactoryBuilder confBuilder = confParser.getFopFactoryBuilder();
63-
fopFactory = confBuilder.build();
64-
}
65-
return fopFactory;
26+
super( fopConfigPath, new ClassLoaderResourceResolver( defaultFontPath ) );
6627
}
6728

6829
}

0 commit comments

Comments
 (0)