Skip to content

Commit ff64322

Browse files
committed
Managing of unsafe DocTypeHandler for DocHandlerFactory #31
1 parent 1af982e commit ff64322

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

fj-doc-base/src/main/java/org/fugerit/java/doc/base/facade/DocHandlerFactory.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import java.util.Collection;
55
import java.util.HashMap;
66

7-
import org.fugerit.java.core.cfg.ConfigurableObject;
87
import org.fugerit.java.core.cfg.xml.FactoryCatalog;
98
import org.fugerit.java.core.cfg.xml.FactoryType;
9+
import org.fugerit.java.core.cfg.xml.FactoryTypeHelper;
1010
import org.fugerit.java.core.io.helper.StreamHelper;
11-
import org.fugerit.java.core.lang.helpers.ClassHelper;
1211
import org.fugerit.java.doc.base.config.DocTypeHandler;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1314

1415
public class DocHandlerFactory extends HashMap<String, DocHandlerFacade> {
1516

@@ -22,6 +23,10 @@ public class DocHandlerFactory extends HashMap<String, DocHandlerFacade> {
2223

2324
private String useCatalog;
2425

26+
private final static Logger logger = LoggerFactory.getLogger( DocHandlerFactory.class );
27+
28+
private static final FactoryTypeHelper<DocTypeHandler> HELPER = FactoryTypeHelper.newInstance( DocTypeHandler.class );
29+
2530
public static DocHandlerFacade register( String factoryCatalogPath ) throws Exception {
2631
return register( factoryCatalogPath, null );
2732
}
@@ -42,11 +47,12 @@ public static DocHandlerFacade register( Collection<FactoryType> col ) throws Ex
4247
if ( col != null ) {
4348
facade = new DocHandlerFacade();
4449
for ( FactoryType ft : col ) {
45-
DocTypeHandler handler = (DocTypeHandler) ClassHelper.newInstance( ft.getType() );
46-
if ( handler instanceof ConfigurableObject ) {
47-
((ConfigurableObject)handler).configure( ft.getElement());
50+
DocTypeHandler handler = HELPER.createHelper( ft );
51+
if ( handler != null ) {
52+
facade.registerHandler( handler );
53+
} else {
54+
logger.info( "skipped null handler for -> {}", ft );
4855
}
49-
facade.registerHandler( handler );
5056
}
5157
}
5258
return facade;

fj-doc-sample/src/main/resources/config/doc-handler-sample.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@
3131
<data id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8" />
3232
<data id="csv-opencsv" info="csv" type="org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler"/>
3333
</factory>
34+
35+
<factory id="unsafe-test">
36+
<data id="html-fm" info="html" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8" />
37+
<data id="html-fragment-fm" info="fhtml" type="org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8" />
38+
<data id="pdf-unsafe" info="pdf" type="org.fugerit.java.doc.pdf.UnsafeDocHandler" unsafe="true" unsafeMode="log-trace"/>
39+
</factory>
3440

3541
</doc-handler-config>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test.org.fugerit.java.doc.sample.config;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import org.fugerit.java.doc.base.facade.DocHandlerFactory;
6+
import org.junit.Test;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
public class TestDocHandlerFactory {
11+
12+
private final static Logger logger = LoggerFactory.getLogger( TestDocHandlerFactory.class );
13+
14+
@Test
15+
public void initDocFactoryTest() {
16+
try {
17+
String path = "cl://config/doc-handler-sample.xml";
18+
DocHandlerFactory factory = DocHandlerFactory.newInstance( path );
19+
logger.info( "factory {}", factory );
20+
} catch (Throwable t) {
21+
String message = "Error : "+t;
22+
logger.error( message, t );
23+
fail( message );
24+
}
25+
}
26+
27+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<maven.compiler.source>${java-version-compliance}</maven.compiler.source>
2525
<maven.compiler.target>${java-version-compliance}</maven.compiler.target>
2626
<!-- fj java versions -->
27-
<fj-version>0.8.12</fj-version>
27+
<fj-version>0.8.13</fj-version>
2828
<fj-doc-version>${project.version}</fj-doc-version>
2929
<jackson-version>2.14.2</jackson-version>
3030
</properties>

0 commit comments

Comments
 (0)