Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- new built-in function stringToBase64

### Changed

- fj-doc-maven-plugin, init, flavour : quarkus-version set to 3.29.2 across all the modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Background : HelperDSL.TagWithText( "background" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Body : HelperDSL.TagWithText( "body" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Cell : HelperDSL.TagWithText( "cell" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Footer : HelperDSL.TagWithText( "footer" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class FooterExt : HelperDSL.TagWithText( "footer-ext" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Header : HelperDSL.TagWithText( "header" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class HeaderExt : HelperDSL.TagWithText( "header-ext" ) {
* Creates a new default Image instance.
* @return the new instance.
*/
fun image( init: Image.() -> Unit = {} ): Image {
return initTag(Image(), init);
fun image( text: String = "", init: Image.() -> Unit = {} ): Image {
return initTag(Image(text), init);
}
/**
* Creates a new default Phrase instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ package org.fugerit.java.doc.base.kotlin.dsl
*
* This class will provide function to handle all image attributes and kids
*/
class Image : HelperDSL.TagWithText( "image" ) {
class Image( text: String = "" ) : HelperDSL.TagWithText( "image" ) {

init { setText(text) }
/**
* Function to set text content for this element.
*/

fun setText( value: String ) { addKid( HelperDSL.TextElement( value ) ) }


/**
* Function handling url attribute of the Image with specific check on type.
Expand Down
1 change: 1 addition & 0 deletions fj-doc-base/src/main/docs/doc_xsd_config_ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ <h1 style="font-weight: bold;">Reference xsd documentation for Venus - Fugerit
<span >An image to include in the document (roughly comparable to a HTML 'image' element)</span>
</td>
<td id="cell_19_2" style=" width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
<span >mixed </span>
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The Apache Software Foundation (http://www.apache.org/).
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;

Expand Down Expand Up @@ -82,7 +83,9 @@ public static Collection<String> getAcceptedImageTypes() {
@Getter @Setter private String alt;

@Getter @Setter private int align;


@Getter @Setter private String content = "";

public String getResolvedBase64() {
return SafeFunction.get( () -> {
String res = this.getBase64();
Expand All @@ -94,7 +97,13 @@ public String getResolvedBase64() {
}

public String getResolvedText() {
return SafeFunction.get( () -> new String( resolveImage( this ) ) );
return SafeFunction.get( () -> {
if ( StringUtils.isEmpty( this.content ) ) {
return new String( resolveImage( this ) );
} else {
return this.content;
}
});
}

public String getResolvedType() {
Expand Down Expand Up @@ -134,6 +143,8 @@ public static byte[] resolveImage( DocImage img ) throws IOException {
data = Base64Helper.decodeBase64String( base64 );
} else if ( path != null ) {
data = byteResolverHelper( path );
} else if ( StringUtils.isNotEmpty( img.getContent() ) ) {
data = img.getContent().getBytes( StandardCharsets.UTF_8 );
} else {
throw new IOException( "Null path provided!" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public void handleText( String text ) {
} else if ( this.currentElement instanceof DocInfo ) {
DocInfo docInfo = (DocInfo)this.currentElement;
docInfo.getContent().append( text );
} else if ( this.currentElement instanceof DocImage ) {
DocImage docImage = (DocImage)this.currentElement;
docImage.setContent( docImage.getContent()+text );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,9 @@
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "getContent",
"parameterTypes" : [ ]
}, {
"name" : "getId",
"parameterTypes" : [ ]
Expand Down Expand Up @@ -1188,6 +1191,9 @@
}, {
"name" : "setBase64",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setContent",
"parameterTypes" : [ "java.lang.String" ]
}, {
"name" : "setId",
"parameterTypes" : [ "java.lang.String" ]
Expand Down
4 changes: 2 additions & 2 deletions fj-doc-base/src/main/resources/config/doc-2-1.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @project : fj-doc-base
* @creation : 2023-08-18
* @version : 2.1.0-rc.3 (2025-03-22)
* @version : 2.1.0-rc.4 (2025-11-19)
*
* XSD for fugerit doc configuration
*/
Expand Down Expand Up @@ -408,7 +408,7 @@
<xsd:documentation>An image to include in the document</xsd:documentation>
<xsd:documentation>(roughly comparable to a HTML 'image' element)</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexType mixed="true">
<xsd:attribute name='url' type='doc:urlType' use='optional'/>
<xsd:attribute name='type' type='doc:imageType' use='optional' />
<xsd:attribute name='scaling' type='doc:scalingType' use='optional' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
class TestDocImage extends HelperDocT {

@Test
void testElement1() {
void testElement1() throws IOException {
DocImage image = new DocImage();
image.setUrl( DocImage.TYPE_JPG );
Assertions.assertEquals( DocImage.TYPE_JPG, image.getResolvedType() );
Expand All @@ -22,6 +24,12 @@ void testElement1() {
image.setUrl( "cl://txt/test.txt" );
Assertions.assertEquals( "test text", image.getResolvedText() );
log.info( "accepted types : {}", DocImage.getAcceptedImageTypes() );
String altTest = "alt test";
image.setContent( altTest );
Assertions.assertEquals( altTest, image.getResolvedText() );
image.setUrl( null );
image.setBase64( null );
Assertions.assertEquals( altTest.length(), DocImage.resolveImage( image ).length );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<#if docImage.align = 2>
<#assign imageAlign="style='display: block; margin-left: auto; margin-right: auto;'"/>
</#if>
</#if>
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, ${docImage.resolvedBase64}" />
</#if>
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, <#if docImage.content?has_content>${docImage.content}<#else>${docImage.resolvedBase64}</#if>" />
</#macro>

<#macro handleList docList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<image scaling="100" url="cl://test/img_test_teal.jpg"/>
<br/>
<page-break/>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<doc
xmlns="http://javacoredoc.fugerit.org"
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-0.xsd" >
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >

<metadata>
<!-- Margin for document : left;right;top;bottom -->
Expand All @@ -29,7 +29,9 @@
<body>
<image scaling="100" url="cl://test/img_test_teal.jpg"/>
<phrase leading="3">My sample title</phrase>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<image type="svg" alt="blank square"><![CDATA[<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" width="10px" height="10px" viewBox="0 0 24 24"><path d="M21,2H3A1,1,0,0,0,2,3V21a1,1,0,0,0,1,1H21a1,1,0,0,0,1-1V3A1,1,0,0,0,21,2ZM20,20H4V4H20Z"/></svg>]]></image>

<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para fore-color="#ffffff" style="bold">Surname</para></cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public int process(DocProcessContext context, DocProcessData data) throws Except
map.put(CleanTextFun.DEFAULT_NAME, new CleanTextFun());
map.put(FormatLocalDateTimeFun.DEFAULT_NAME, new FormatLocalDateTimeFun());
map.put(Base64ToStringFun.DEFAULT_NAME, new Base64ToStringFun());
map.put(StringToBase64Fun.DEFAULT_NAME, new StringToBase64Fun());
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.fugerit.java.doc.freemarker.fun;

import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateScalarModel;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;

public class StringToBase64Fun implements TemplateMethodModelEx {

public static final String DEFAULT_NAME = "stringToBase64";

@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
FMFunHelper.checkParameterNumber( arguments, 1 );
String content = ((TemplateScalarModel)arguments.get( 0 )).getAsString();
return new SimpleScalar( Base64.getEncoder().encodeToString( content.getBytes( StandardCharsets.UTF_8 ) ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,42 @@
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.freemarker.fun.StringToBase64Fun",
"methods" : [ {
"name" : "<init>",
"parameterTypes" : [ ]
}, {
"name" : "equals",
"parameterTypes" : [ "java.lang.Object" ]
}, {
"name" : "exec",
"parameterTypes" : [ "java.util.List" ]
}, {
"name" : "getClass",
"parameterTypes" : [ ]
}, {
"name" : "hashCode",
"parameterTypes" : [ ]
}, {
"name" : "notify",
"parameterTypes" : [ ]
}, {
"name" : "notifyAll",
"parameterTypes" : [ ]
}, {
"name" : "toString",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ ]
}, {
"name" : "wait",
"parameterTypes" : [ "long" ]
}, {
"name" : "wait",
"parameterTypes" : [ "long", "int" ]
} ]
}, {
"name" : "org.fugerit.java.doc.freemarker.fun.TextWrapFun",
"methods" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<#assign imageAlign="style='display: block; margin-left: auto; margin-right: auto;'"/>
</#if>
</#if>
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, ${docImage.resolvedBase64}" />
<img <@handleId element=docImage/> ${imageAlign!''} <#if (docImage.alt)??> alt="${docImage.alt}" </#if> ${imageScaling} src="data:image/png;base64, <#if docImage.content?has_content>${docImage.content}<#else>${docImage.resolvedBase64}</#if>" />
</#if>
</#macro>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<function name="messageFormat" value="org.fugerit.java.doc.freemarker.fun.SimpleMessageFun"/>
<function name="sumLong" value="org.fugerit.java.doc.freemarker.fun.SimpleSumLongFun"/>
<function name="base64ToString" value="org.fugerit.java.doc.freemarker.fun.Base64ToStringFun"/>
<function name="stringToBase64" value="org.fugerit.java.doc.freemarker.fun.StringToBase64Fun"/>
</chainStep>
</docChain>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

<para style="bold">base64ToString ${base64ToString('VEVTVA==')}</para>

<para style="bold">stringToBase64 ${stringToBase64('TEST')}</para>

<image url="png" base64="${imageBase64CLFun()}" scaling="25"/>

<para style="bold">italic ${messageFormat()}</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ NOTE: When using *skipfm* no FreeMarker template syntax should be used in the te
| formats a LocalDate, LocalTime or LocalDateTime
| (1) - the date/time to format, (2) - the format pattern

| base64ToString
| org.fugerit.java.doc.freemarker.fun.&#8203;Base64ToStringFun
| converts a base64 to string
| (1) - base64 to convert to string

| stringToBase64
| org.fugerit.java.doc.freemarker.fun.&#8203;StringToBase64Fun
| converts a string to base64
| (1) - the string to convert

|========================================================================================================================================

NOTE: These functions can all be loaded at once with the config step attribute _load-bundled-functions="true"_.
Loading