Skip to content

Commit 8e3475c

Browse files
committed
Added messageFormat template
1 parent 5f299d2 commit 8e3475c

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

code-samples-fj-doc/src/main/resources/code-samples-fj-doc/fm-doc-process-config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@
4545
<chainStep stepType="complex" map-atts="listPeople" template-path="${chainId}.ftl"/>
4646
</docChain>
4747

48+
<!-- example document chain -->
49+
<docChain id="message-format" parent="shared">
50+
<chainStep stepType="complex" map-atts="params" template-path="${chainId}.ftl"/>
51+
</docChain>
52+
4853
</freemarker-doc-process-config>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >
6+
7+
<#--
8+
This is a Venus Fugerit Doc (https://github.com/fugerit-org/fj-doc) FreeMarker Template XML (ftl[x]).
9+
For consideration of Venus Fugerit Doc and Apache FreeMarker integration see :
10+
https://venusguides.fugerit.org/src/docs/common/doc_format_freemarker.html
11+
The result will be a :
12+
-->
13+
<!--
14+
This is a Venus Fugerit Doc (https://github.com/fugerit-org/fj-doc) XML Source Document.
15+
For documentation on how to write a valid Venus Doc XML Meta Model refer to :
16+
https://venusguides.fugerit.org/src/docs/common/doc_format_summary.html
17+
-->
18+
19+
<#assign defaultTitle="Message fun test template">
20+
21+
<metadata>
22+
<!-- Margin for document : left;right;top;bottom -->
23+
<info name="margins">10;10;10;30</info>
24+
<!-- documenta meta information -->
25+
<info name="doc-title">${docTitle!defaultTitle}</info>
26+
<info name="doc-subject">Template to show messageFun functionalities</info>
27+
<info name="doc-author">fugerit79</info>
28+
<info name="doc-language">en</info>
29+
</metadata>
30+
<body>
31+
<para>${docTitle!defaultTitle}</para>
32+
<para>${messageFormat(params['prop1'], 'Elrond')}</para>
33+
</body>
34+
35+
</doc>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package test.testorg.fugerit.java.codesamplesfjdoc;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.codesamplesfjdoc.DocHelper;
5+
import org.fugerit.java.doc.base.config.DocConfig;
6+
import org.fugerit.java.doc.base.process.DocProcessContext;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.Properties;
13+
14+
/**
15+
* This is a basic example of Fugerit Venus Doc usage,
16+
* running this main the program will :
17+
* - creates data to be used in document model
18+
* - renders the 'document.ftl' template
19+
* - print the result in markdown format on the log
20+
*
21+
* For further documentation :
22+
* https://github.com/fugerit-org/fj-doc
23+
*/
24+
@Slf4j
25+
class MessageFormatTest {
26+
27+
@Test
28+
void test() throws IOException {
29+
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
30+
// creates the doc helper
31+
DocHelper docHelper = new DocHelper();
32+
// create custom data for the fremarker template 'document.ftl'
33+
Properties params = new Properties();
34+
params.setProperty( "prop1", "The king of Rivendell is {0}" );
35+
// handler id
36+
String handlerId = DocConfig.TYPE_MD;
37+
// output generation
38+
docHelper.getDocProcessConfig().fullProcess( "message-format", DocProcessContext.newContext( "params", params ), handlerId, baos );
39+
// print the output
40+
log.info( "html output : \n{}", new String( baos.toByteArray(), StandardCharsets.UTF_8 ) );
41+
}
42+
}
43+
44+
/*
45+
* Class used to wrap data to be rendered in the document template
46+
*/
47+
public static class People {
48+
49+
private String name;
50+
51+
private String surname;
52+
53+
private String title;
54+
55+
public People(String name, String surname, String title) {
56+
this.name = name;
57+
this.surname = surname;
58+
this.title = title;
59+
}
60+
61+
public String getName() {
62+
return name;
63+
}
64+
65+
public String getSurname() {
66+
return surname;
67+
}
68+
69+
public String getTitle() {
70+
return title;
71+
}
72+
}
73+
74+
}

0 commit comments

Comments
 (0)