Skip to content

Commit

Permalink
+ fj-doc-mod-fop Fixed legacy compatibility of FopConfigClassLoader see
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Nov 24, 2022
1 parent f1c4c70 commit b51a31e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolver;
import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolverWrapper;
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoader;
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
Expand Down Expand Up @@ -127,7 +126,7 @@ public void configure(Element tag) throws ConfigException {
// legacy class loader mode
if ( StringUtils.isEmpty( fopConfigMode ) && StringUtils.isNotEmpty( fopConfigClassloaderPath ) && StringUtils.isNotEmpty( fontBaseClassloaderPath ) ) {
fopConfigMode = ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY;
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 );
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 );
}
if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER.equalsIgnoreCase( fopConfigMode ) ) {
try {
Expand All @@ -138,8 +137,7 @@ public void configure(Element tag) throws ConfigException {
throw new ConfigException( PdfFopTypeHandler.class.getSimpleName()+" configuration error : "+e, e );
}
} else if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY.equalsIgnoreCase( fopConfigMode ) ) {
ClassLoaderResourceResolver customResourceResolver = new ClassLoaderResourceResolver( fontBaseClassloaderPath );
FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, customResourceResolver);
FopConfigClassLoader fopConfigClassLoader = new FopConfigClassLoader(fopConfigClassloaderPath, fontBaseClassloaderPath);
this.fopConfig = fopConfigClassLoader;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
@Deprecated
public class ClassLoaderResourceResolver implements ResourceResolver, Serializable {

public static final String MIN_VERSION_NEW_CLASSLOADER_MODE = "[0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)";

private static final Logger logger = LoggerFactory.getLogger( ClassLoaderResourceResolver.class );

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

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

@Override
public Resource getResource(URI uri) throws IOException {
try {
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), MIN_VERSION_NEW_CLASSLOADER_MODE );
logger.warn( "{} is deprecated it is suggested to switch to fop-config-mode='classloader', see: {}", this.getClass().getName(), FopConfigClassLoader.MIN_VERSION_NEW_CLASSLOADER_MODE );
String path = this.defaultFontPath+uri.getPath().substring( uri.getPath().lastIndexOf( "/")+1 );
InputStream inputStream = ClassHelper.loadFromDefaultClassLoader( path );
return new Resource(inputStream);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
package org.fugerit.java.doc.mod.fop.config;

import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;

import org.apache.fop.apps.EnvironmentalProfileFactory;
import org.apache.fop.apps.FopConfParser;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.xmlgraphics.io.ResourceResolver;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.doc.mod.fop.FopConfig;

public class FopConfigClassLoader implements FopConfig, Serializable {
/*
* Left only for compatibility with versions previous of 0.5.2
*/
@Deprecated
public class FopConfigClassLoader extends FopConfigClassLoaderWrapper {

/**
*
*/
private static final long serialVersionUID = 188843074194800812L;

private String fopConfigPath;

public String getFopConfigPath() {
return fopConfigPath;
}

private ResourceResolver customResourceResolver;

public ResourceResolver getCustomResourceResolver() {
return customResourceResolver;
}
public static final String MIN_VERSION_NEW_CLASSLOADER_MODE = "[0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)";

/**
* Provided only for compatibility
Expand All @@ -41,28 +23,7 @@ public ResourceResolver getCustomResourceResolver() {
*/
@Deprecated
public FopConfigClassLoader(String fopConfigPath, String defaultFontPath) {
this( fopConfigPath, new ClassLoaderResourceResolver( defaultFontPath ) );
}

public FopConfigClassLoader(String fopConfigPath) {
this( fopConfigPath, new ClassLoaderResourceResolverWrapper() );
}

public FopConfigClassLoader(String fopConfigPath, ResourceResolver customResourceResolver) {
super();
this.fopConfigPath = fopConfigPath;
this.customResourceResolver = customResourceResolver;
}

@Override
public FopFactory newFactory() throws Exception {
FopFactory fopFactory = null;
try ( InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() ) ) {
FopConfParser confParser = new FopConfParser( fopConfigStream, EnvironmentalProfileFactory.createRestrictedIO(new URI("."), this.customResourceResolver) );
FopFactoryBuilder confBuilder = confParser.getFopFactoryBuilder();
fopFactory = confBuilder.build();
}
return fopFactory;
super( fopConfigPath, new ClassLoaderResourceResolver( defaultFontPath ) );
}

}

0 comments on commit b51a31e

Please sign in to comment.