Skip to content

Commit 9e99d9f

Browse files
committed
Working examples
1 parent 5674545 commit 9e99d9f

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed

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

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

48-
<!-- example document chain -->
48+
<!-- example messageFormat chain -->
4949
<docChain id="message-format" parent="shared">
5050
<chainStep stepType="complex" map-atts="params" template-path="${chainId}.ftl"/>
5151
</docChain>
5252

53+
<!-- example template fail chain -->
54+
<docChain id="template-fail" parent="shared">
55+
<chainStep stepType="complex" map-atts="params" template-path="${chainId}.ftl"/>
56+
</docChain>
57+
5358
</freemarker-doc-process-config>

code-samples-fj-doc/src/main/resources/code-samples-fj-doc/template/message-format.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</metadata>
3030
<body>
3131
<para>${docTitle!defaultTitle}</para>
32-
<para>${messageFormat(params['prop1'], 'Elrond')}</para>
32+
<para>${messageFormat(params['prop1'], 'Galadriel')}</para>
3333
</body>
3434

3535
</doc>
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="Template fail test">
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>

code-samples-fj-doc/src/test/java/test/testorg/fugerit/java/codesamplesfjdoc/MessageFormatTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void test() throws IOException {
3030
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
3131
// creates the doc helper
3232
DocHelper docHelper = new DocHelper();
33-
// create custom data for the fremarker template 'document.ftl'
33+
// create custom data for the fremarker template 'message-format.ftl'
3434
Properties params = new Properties();
35-
params.setProperty( "prop1", "The king of Rivendell is {0}" );
35+
params.setProperty( "prop1", "The Queel of Lorien is {0}" );
3636
// handler id
3737
String handlerId = DocConfig.TYPE_MD;
3838
// output generation
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.io.ByteArrayOutputStream;
11+
import java.io.IOException;
12+
import java.nio.charset.StandardCharsets;
13+
import java.util.Properties;
14+
15+
/**
16+
* This is a basic example of Fugerit Venus Doc usage,
17+
* running this main the program will :
18+
* - creates data to be used in document model
19+
* - renders the 'document.ftl' template
20+
* - print the result in markdown format on the log
21+
*
22+
* For further documentation :
23+
* https://github.com/fugerit-org/fj-doc
24+
*/
25+
@Slf4j
26+
class TemplateFailTest {
27+
28+
@Test
29+
void test() throws IOException {
30+
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
31+
// creates the doc helper
32+
DocHelper docHelper = new DocHelper();
33+
// create custom data for the fremarker template 'template-fail.ftl'
34+
Properties params = new Properties();
35+
params.setProperty( "prop1", "The king of Rivendell is {0}" );
36+
// handler id
37+
String handlerId = DocConfig.TYPE_MD;
38+
// output generation
39+
docHelper.getDocProcessConfig().fullProcess( "template-fail", DocProcessContext.newContext( "params", params ), handlerId, baos );
40+
// print the output
41+
log.info( "html output : \n{}", new String( baos.toByteArray(), StandardCharsets.UTF_8 ) );
42+
Assertions.assertNotEquals( 0, baos.size() );
43+
}
44+
}
45+
46+
/*
47+
* Class used to wrap data to be rendered in the document template
48+
*/
49+
public static class People {
50+
51+
private String name;
52+
53+
private String surname;
54+
55+
private String title;
56+
57+
public People(String name, String surname, String title) {
58+
this.name = name;
59+
this.surname = surname;
60+
this.title = title;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
67+
public String getSurname() {
68+
return surname;
69+
}
70+
71+
public String getTitle() {
72+
return title;
73+
}
74+
}
75+
76+
}

0 commit comments

Comments
 (0)