Skip to content

Commit 8faf6cd

Browse files
committed
0.5.2 (2022-11-21)
+ fj-doc-sample semplified. (Reduced to only one test facade.) + Introduce new FopPrtTypeHandler config attribute 'fop-config-mode' (previous mode is deprecated) see [0.5.2](#7)
1 parent f323316 commit 8faf6cd

File tree

16 files changed

+257
-36
lines changed

16 files changed

+257
-36
lines changed

docgen/parameters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title" : "Venus (Fugerit Document Generation Framework)",
33
"name": "Venus",
4-
"version" : "0.5.1",
5-
"date" : "20/11/2022",
4+
"version" : "0.5.2",
5+
"date" : "21/11/2022",
66
"organization" : {
77
"name" : "Fugerit Org",
88
"url" : "https://www.fugerit.org"

docgen/release-notes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
0.5.2 (2022-11-??)
1+
0.5.2 (2022-11-21)
22
------------------
33
+ fj-doc-sample semplified. (Reduced to only one test facade.)
4+
+ Introduce new FopPrtTypeHandler config attribute 'fop-config-mode' (previous mode is deprecated) see [0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)
45

56
0.5.1 (2022-11-20)
67
------------------

fj-doc-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.5.1</version>
10+
<version>0.5.2</version>
1111
</parent>
1212

1313
<name>fj-doc-base</name>

fj-doc-freemarker/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.5.1</version>
10+
<version>0.5.2</version>
1111
</parent>
1212

1313
<name>fj-doc-freemarker</name>

fj-doc-mod-fop/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.5.1</version>
10+
<version>0.5.2</version>
1111
</parent>
1212

1313
<name>fj-doc-mod-fop</name>

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,38 @@
1515
import org.apache.fop.apps.Fop;
1616
import org.apache.fop.apps.FopFactory;
1717
import org.apache.fop.apps.MimeConstants;
18+
import org.apache.xmlgraphics.io.ResourceResolver;
1819
import org.fugerit.java.core.cfg.ConfigException;
20+
import org.fugerit.java.core.lang.helpers.ClassHelper;
1921
import org.fugerit.java.core.lang.helpers.StringUtils;
2022
import org.fugerit.java.core.xml.dom.DOMUtils;
2123
import org.fugerit.java.doc.base.config.DocConfig;
2224
import org.fugerit.java.doc.base.config.DocInput;
2325
import org.fugerit.java.doc.base.config.DocOutput;
2426
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;
2529
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoader;
30+
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
2631
import org.w3c.dom.Element;
2732
import org.w3c.dom.NodeList;
2833

2934
public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler {
3035

3136
public static final DocTypeHandler HANDLER = new PdfFopTypeHandler();
3237

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+
3344
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
3450
public static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path";
3551

3652
public static final boolean DEFAULT_ACCESSIBILITY = true;
@@ -104,10 +120,26 @@ public void configure(Element tag) throws ConfigException {
104120
if ( nl.getLength() > 0 ) {
105121
Element config = (Element)nl.item( 0 );
106122
Properties props = DOMUtils.attributesToProperties( config );
123+
String fopConfigMode = props.getProperty( ATT_FOP_CONFIG_MODE );
107124
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 );
108126
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);
111143
this.fopConfig = fopConfigClassLoader;
112144
}
113145
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,26 @@
99
import org.apache.xmlgraphics.io.Resource;
1010
import org.apache.xmlgraphics.io.ResourceResolver;
1111
import org.fugerit.java.core.lang.helpers.ClassHelper;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

15+
/**
16+
* This ResourceResolver try to load resources from class loader.
17+
*
18+
* Starting with version 0.5.2 it is deprecated. [0.5.2](https://github.com/fugerit-org/fj-doc/issues/7)
19+
*
20+
* @deprecated use {@link ClassLoaderResourceResolverWrapper} instead.
21+
*
22+
* @author fugerit
23+
*
24+
*/
25+
@Deprecated
1326
public class ClassLoaderResourceResolver implements ResourceResolver, Serializable {
1427

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

1734
public String getDefaultFontPath() {
@@ -34,12 +51,14 @@ public ClassLoaderResourceResolver(String defaultFontPath) {
3451

3552
@Override
3653
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 );
3755
return Thread.currentThread().getContextClassLoader().getResource(uri.toString()).openConnection().getOutputStream();
3856
}
3957

4058
@Override
4159
public Resource getResource(URI uri) throws IOException {
4260
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 );
4362
String path = this.defaultFontPath+uri.getPath().substring( uri.getPath().lastIndexOf( "/")+1 );
4463
InputStream inputStream = ClassHelper.loadFromDefaultClassLoader( path );
4564
return new Resource(inputStream);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.fugerit.java.doc.mod.fop.config;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.net.URI;
6+
7+
import org.apache.fop.apps.io.ResourceResolverFactory;
8+
import org.apache.xmlgraphics.io.Resource;
9+
import org.fugerit.java.core.lang.helpers.ClassHelper;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
/**
14+
* This class loader try to laod from class loader path starting with classpath://
15+
*
16+
* All other uri path are delegated to apache fop default ResourceResolver
17+
*
18+
* @author fugerit
19+
*
20+
*/
21+
public class ClassLoaderResourceResolverWrapper extends ResourceResolverWrapper {
22+
23+
private static final long serialVersionUID = -4400353184756089423L;
24+
25+
private static final Logger logger = LoggerFactory.getLogger( ClassLoaderResourceResolverWrapper.class );
26+
27+
public static final String CLASSPATH_SCHEMA = "classpath://";
28+
29+
public ClassLoaderResourceResolverWrapper() {
30+
super( ResourceResolverFactory.createDefaultResourceResolver() );
31+
}
32+
33+
@Override
34+
public OutputStream getOutputStream(URI uri) throws IOException {
35+
logger.debug( "getOutputStream() uri -> {}", uri );
36+
return Thread.currentThread().getContextClassLoader().getResource(uri.toString()).openConnection().getOutputStream();
37+
}
38+
39+
public boolean canHandle( String uri ) {
40+
return uri.startsWith( CLASSPATH_SCHEMA );
41+
}
42+
43+
@Override
44+
public Resource getResource(URI uri) throws IOException {
45+
try {
46+
String path = uri.toString();
47+
boolean canHandle = this.canHandle( path );
48+
logger.debug( "getResource() canHandle?:{}, uri:{}", canHandle, uri );
49+
if ( canHandle ) {
50+
path = path.substring( CLASSPATH_SCHEMA.length() ); ;
51+
return new Resource( ClassHelper.loadFromDefaultClassLoader( path ) );
52+
} else {
53+
return this.unwrap().getResource(uri);
54+
}
55+
} catch (Exception e) {
56+
throw new IOException( e );
57+
}
58+
}
59+
60+
}
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package org.fugerit.java.doc.mod.fop.config;
22

3-
import java.io.File;
43
import java.io.InputStream;
54
import java.io.Serializable;
5+
import java.net.URI;
66

7+
import org.apache.fop.apps.EnvironmentalProfileFactory;
8+
import org.apache.fop.apps.FopConfParser;
79
import org.apache.fop.apps.FopFactory;
810
import org.apache.fop.apps.FopFactoryBuilder;
9-
import org.apache.fop.apps.io.InternalResourceResolver;
10-
import org.apache.fop.apps.io.ResourceResolverFactory;
11-
import org.apache.fop.configuration.DefaultConfigurationBuilder;
1211
import org.apache.xmlgraphics.io.ResourceResolver;
1312
import org.fugerit.java.core.lang.helpers.ClassHelper;
1413
import org.fugerit.java.doc.mod.fop.FopConfig;
@@ -26,30 +25,27 @@ public String getFopConfigPath() {
2625
return fopConfigPath;
2726
}
2827

29-
private String defaultFontPath;
30-
31-
public String getDefaultFontPath() {
32-
return defaultFontPath;
28+
private ResourceResolver customResourceResolver;
29+
30+
public ResourceResolver getCustomResourceResolver() {
31+
return customResourceResolver;
3332
}
3433

35-
public FopConfigClassLoader(String fopConfigPath, String defaultFontPath) {
34+
public FopConfigClassLoader(String fopConfigPath, ResourceResolver customResourceResolver) {
3635
super();
3736
this.fopConfigPath = fopConfigPath;
38-
this.defaultFontPath = defaultFontPath;
37+
this.customResourceResolver = customResourceResolver;
3938
}
4039

4140
@Override
4241
public FopFactory newFactory() throws Exception {
43-
InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() );
44-
ResourceResolver customResourceResolver = new ClassLoaderResourceResolver( this.getDefaultFontPath() );
45-
FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI(), customResourceResolver);
46-
FopFactory factory = builder.setConfiguration(new DefaultConfigurationBuilder().build(fopConfigStream)).build();
47-
// fix for bug https://github.com/fugerit-org/fj-doc/issues/6 - start #6
48-
InternalResourceResolver irr = factory.getFontManager().getResourceResolver();
49-
factory.getFontManager().setResourceResolver( ResourceResolverFactory.createInternalResourceResolver( irr.getBaseURI(), customResourceResolver ) );
50-
// fix for bug https://github.com/fugerit-org/fj-doc/issues/6 - start #6
51-
fopConfigStream.close();
52-
return factory;
42+
FopFactory fopFactory = null;
43+
try ( InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() ) ) {
44+
FopConfParser confParser = new FopConfParser( fopConfigStream, EnvironmentalProfileFactory.createRestrictedIO(new URI("."), this.customResourceResolver) );
45+
FopFactoryBuilder confBuilder = confParser.getFopFactoryBuilder();
46+
fopFactory = confBuilder.build();
47+
}
48+
return fopFactory;
5349
}
5450

5551
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.fugerit.java.doc.mod.fop.config;
2+
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 FopConfigClassLoaderWrapper implements FopConfig, Serializable {
16+
17+
/**
18+
*
19+
*/
20+
private static final long serialVersionUID = 188843074194800812L;
21+
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+
}
33+
34+
public FopConfigClassLoaderWrapper(String fopConfigPath, ResourceResolver customResourceResolver) {
35+
super();
36+
this.fopConfigPath = fopConfigPath;
37+
this.customResourceResolver = customResourceResolver;
38+
}
39+
40+
@Override
41+
public FopFactory newFactory() throws Exception {
42+
FopFactory fopFactory = null;
43+
try ( InputStream fopConfigStream = ClassHelper.loadFromDefaultClassLoader( this.getFopConfigPath() ) ) {
44+
FopConfParser confParser = new FopConfParser( fopConfigStream, EnvironmentalProfileFactory.createRestrictedIO(new URI("."), this.customResourceResolver) );
45+
FopFactoryBuilder confBuilder = confParser.getFopFactoryBuilder();
46+
fopFactory = confBuilder.build();
47+
}
48+
return fopFactory;
49+
}
50+
51+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.fugerit.java.doc.mod.fop.config;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.io.Serializable;
6+
import java.net.URI;
7+
8+
import org.apache.xmlgraphics.io.Resource;
9+
import org.apache.xmlgraphics.io.ResourceResolver;
10+
11+
public class ResourceResolverWrapper implements ResourceResolver, Serializable {
12+
13+
private static final long serialVersionUID = 1188711703327821113L;
14+
15+
public ResourceResolverWrapper(ResourceResolver wrapped) {
16+
super();
17+
this.wrapped = wrapped;
18+
}
19+
20+
public ResourceResolverWrapper() {
21+
this.wrapped = null;
22+
}
23+
24+
private ResourceResolver wrapped;
25+
26+
public ResourceResolver unwrap() {
27+
return wrapped;
28+
}
29+
30+
public void wrap(ResourceResolver wrapped) {
31+
this.wrapped = wrapped;
32+
}
33+
34+
@Override
35+
public Resource getResource(URI uri) throws IOException {
36+
return this.wrapped.getResource(uri);
37+
}
38+
39+
@Override
40+
public OutputStream getOutputStream(URI uri) throws IOException {
41+
return this.wrapped.getOutputStream(uri);
42+
}
43+
44+
}

fj-doc-mod-poi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.5.1</version>
10+
<version>0.5.2</version>
1111
</parent>
1212

1313
<name>fj-doc-mod-poi</name>

fj-doc-sample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.5.1</version>
10+
<version>0.5.2</version>
1111
</parent>
1212

1313
<name>fj-doc-sample</name>

0 commit comments

Comments
 (0)