Skip to content

Commit b6fbe80

Browse files
committed
[freemarker] new fullProcess() by handler id method
[base] new findHandlerRequired() method
1 parent 29d82bd commit b6fbe80

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
- [base] new findHandlerRequired() method
15+
- [freemarker] new fullProcess() by handler id method
1416
- [freemarker] added load-bundled-functions property
1517
- [freemarker] Changed latest freemarker constant to 2.3.33
1618
- [playground-quarkus] quarkus-version set to 3.13.2

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.fugerit.java.core.cfg.ConfigException;
1111
import org.fugerit.java.core.cfg.ConfigRuntimeException;
12+
import org.fugerit.java.core.lang.helpers.StringUtils;
1213
import org.fugerit.java.core.util.ObjectUtils;
1314
import org.fugerit.java.core.util.collection.ListMapStringKey;
1415
import org.fugerit.java.doc.base.config.DocInput;
@@ -117,7 +118,23 @@ public void registerHandlerAndId( String id, DocTypeHandler handler, boolean all
117118
public void registerHandler( DocTypeHandler handler ) throws Exception {
118119
this.registerHandler( handler, DEFAULT_REGISTER_FOR_TYPE, DEFAULT_ERROR_ON_DUPLICATE );
119120
}
120-
121+
122+
/**
123+
* Handler lookup by id, throws a ConfigRuntimeException if not found.
124+
*
125+
* @param handlerId the id of the handler
126+
* @return the handler
127+
* throws ConfigRuntimeException if the handler is not found
128+
*/
129+
public DocTypeHandler findHandlerRequired( String handlerId ) {
130+
DocTypeHandler handler = this.findHandler( handlerId );
131+
if ( handler == null ) {
132+
throw new ConfigRuntimeException( String.format( "No handler found for id %s, available handler ids are : %s", handlerId, StringUtils.concat( ", ", this.mapHandlers.keySet() ) ) );
133+
} else {
134+
return handler;
135+
}
136+
}
137+
121138
public void handle( DocInput docInput, DocOutput docOutput ) throws Exception {
122139
String type = docInput.getType();
123140
DocTypeHandler handler = this.mapHandlers.get( type );

fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/facade/TestDocHandlerFacade.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public void testDocFacade() throws Exception {
6262
DocHandlerFactory.register( new FactoryCatalog() );
6363
Assert.assertFalse( facade.listHandlersForType( SimpleMarkdownBasicTypeHandler.HANDLER.getType() ).isEmpty() );
6464
facade.logHandlersInfo();
65+
// handler not found
66+
Assert.assertThrows( ConfigRuntimeException.class, () -> facade.findHandlerRequired( "not-found" ) );
6567
}
6668

6769
@Test

fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Set;
77

88
import org.fugerit.java.core.cfg.xml.ListMapConfig;
9+
import org.fugerit.java.core.function.SafeFunction;
910
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
1011
import org.fugerit.java.core.util.filterchain.MiniFilterMap;
1112
import org.fugerit.java.core.xml.sax.SAXParseResult;
@@ -52,7 +53,11 @@ protected void setDefaultChain( DefaultChainProvider defaultChain ) {
5253
protected DefaultChainProvider getDefaultChain() {
5354
return this.defaultChain;
5455
}
55-
56+
57+
public DocProcessData fullProcess( String chainId, DocProcessContext context, String handlerId, DocOutput docOutput ) {
58+
return SafeFunction.get( () -> this.fullProcess( chainId, context, this.facade.findHandlerRequired( handlerId ), docOutput ) );
59+
}
60+
5661
public DocProcessData fullProcess( String chainId, DocProcessContext context, DocTypeHandler handler, DocOutput docOutput ) throws Exception {
5762
DocProcessData data = new DocProcessData();
5863
this.process(chainId, context, data);

fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ public void testNewSimpleConfigVersion() {
135135
public void testProcess() {
136136
SafeFunction.apply( () -> {
137137
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-003", "/fj_doc_test/template/" );
138+
config.getFacade().registerHandler( FreeMarkerHtmlTypeHandlerUTF8.HANDLER );
138139
// test full process
139140
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
140141
DocProcessData data = config.fullProcess( "test_02" ,
141-
DocProcessContext.newContext(), FreeMarkerHtmlTypeHandlerUTF8.HANDLER, DocOutput.newOutput(baos) );
142+
DocProcessContext.newContext(), DocConfig.TYPE_HTML, DocOutput.newOutput(baos) );
142143
Assert.assertNotEquals( 0 , data.getCurrentXmlData().length() );
143144
}
144145
// test process 1

0 commit comments

Comments
 (0)