Skip to content

Commit

Permalink
Review to full document generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Oct 22, 2023
1 parent a537344 commit b0168b5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public class FullDocumentFmFacade {
new MapEntry<>( "oln", "numbered ordered list")
);

public void generateFullDocument( OutputStream os, DocTypeHandler handler, List<UserData> listUsers ) throws DocException {
public void generateFullDocument( OutputStream os, DocTypeHandler handler, List<PeopleData> listPeople ) throws DocException {
// wraps any exception as a DocException
DocException.apply( () -> {
DocProcessContext context = DocProcessContext.newContext( "listUsers", listUsers );
context.setAttribute( "listTests" , LIST_TESTS );
DocProcessContext context = DocProcessContext.newContext( "listPeople", listPeople )
.withAtt( "docTitle" , "Full document sample demo" )
.withAtt( "listTests", LIST_TESTS);
SIMPLE_CONFIG.fullProcess( "full-document", context, handler, DocOutput.newOutput(os) );
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Getter;

@AllArgsConstructor
public class UserData {
public class PeopleData {

@Getter private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >

<#--
This is a Venus Fugerit Doc (https://github.com/fugerit-org/fj-doc) FreeMarker Template XML (ftl[x]).
For consideration of Venus Fugerit Doc and Apache FreeMarker integration see :
https://venusguides.fugerit.org/src/docs/common/doc_format_freemarker.html
The result will be a :
-->
<!--
This is a Venus Fugerit Doc (https://github.com/fugerit-org/fj-doc) XML Source Document.
For documentation on how to write a valid Venus Doc XML Meta Model refer to :
Expand All @@ -15,9 +21,16 @@
<!-- Margin for document : left;right;top;bottom -->
<info name="margins">10;10;10;30</info>
<!-- documenta meta information -->
<info name="doc-title">Full document sample</info>
<info name="doc-title">${docTitle}</info>
<info name="doc-author">fugerit79</info>
<info name="doc-language">en</info>
<!-- only apply to excep format -->
<info name="excel-table-id">data-table-1=sheet1,data-table-2=sheet2</info>
<!-- font must be loaded -->
<info name="default-font-name">TitilliumWeb</info>
<footer-ext>
<para align="right">${r"${currentPage}"} / ${r"${pageCount}"}</para>
</footer-ext>
<bookmark-tree>
<bookmark ref="top">Full document sample demo</bookmark>
<bookmark ref="sec_1">1. Sample tables</bookmark>
Expand All @@ -38,17 +51,17 @@

<h head-level="3" size="12">1.1 Sample table : no special characteristics</h>

<table colwidths="30;30;40" columns="3" width="100">
<table colwidths="30;30;40" columns="3" width="100" id="data-table-1">
<row header="true">
<cell align="center"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<#list listUsers as user>
<#list listPeople as current>
<row>
<cell><para>${user.name}</para></cell>
<cell><para>${user.surname}</para></cell>
<cell><para>${user.title}</para></cell>
<cell><para>${current.name}</para></cell>
<cell><para>${current.surname}</para></cell>
<cell><para>${current.title}</para></cell>
</row>
</#list>
</table>
Expand All @@ -57,17 +70,17 @@

<h head-level="3" size="12">1.2 Sample table : special characteristics</h>

<table colwidths="30;30;40" columns="3" width="100">
<table colwidths="30;30;40" columns="3" width="100" id="data-table-2">
<row header="true">
<cell align="center"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<#list listUsers as user>
<#list listPeople as current>
<row>
<cell><para>${user.name}</para></cell>
<cell><para>${user.surname}</para></cell>
<cell><para>${user.title}</para></cell>
<cell><para>${current.name}</para></cell>
<cell><para>${current.surname}</para></cell>
<cell><para>${current.title}</para></cell>
</row>
</#list>
</table>
Expand All @@ -80,13 +93,16 @@

<#-- iterate over list types -->
<#list listTests as listType>
<br/>
<h head-level="3" size="12">Sample list ${1+listType?index} : ${listType.value}</h>
<list list-type="${listType.key}">
<li><para>Marie Curie</para></li>
<li><para>Alan Turing</para></li>
</list>
</#list>

<page-break/>

</body>

</doc>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.fugerit.java.doc.base.config.DocTypeHandlerXMLUTF8;
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerEscapeUTF8;
import org.fugerit.java.doc.guides.fulldocument.fm.facade.FullDocumentFmFacade;
import org.fugerit.java.doc.guides.fulldocument.fm.facade.UserData;
import org.fugerit.java.doc.guides.fulldocument.fm.facade.PeopleData;
import org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandler;
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
import org.junit.Assert;
Expand All @@ -33,16 +33,16 @@ public class TestFullDocumentFmFacade {
@Test
public void testFullDocument() throws IOException, DocException {
// custom data to be added to the template via Apache FreeMarker
List<UserData> listUsers = Arrays.asList(
new UserData( "Marie" , "Curie", ">> Checmist"),
new UserData( "Alan" , "Turing", "<IT/> Specialist")
List<PeopleData> listPeole = Arrays.asList(
new PeopleData( "Marie" , "Curie", ">> Chemist"),
new PeopleData( "Alan" , "Turing", "<IT/> Specialist")
);
for ( DocTypeHandler handler : HANDLERS ) {
File outputFile = new File( "target", "full-document."+handler.getType() ); // output file
log.info( "outputFile : {}", outputFile );
try ( OutputStream os = new FileOutputStream( outputFile ) ) {
FullDocumentFmFacade facade = new FullDocumentFmFacade(); // the facade to generate the document
facade.generateFullDocument(os, handler, listUsers); // actual document generation
facade.generateFullDocument(os, handler, listPeole); // actual document generation
log.info( "Generated full documenti pdf file in path : {}", outputFile.getCanonicalPath() );
Assert.assertTrue( outputFile.exists() );
}
Expand Down

0 comments on commit b0168b5

Please sign in to comment.