Skip to content

Commit 7670ac7

Browse files
committed
[playground-quarkus] added kotlin input
1 parent 2273917 commit 7670ac7

File tree

9 files changed

+79
-5
lines changed

9 files changed

+79
-5
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- [playground-quarkus] added kotlin input <https://github.com/fugerit-org/fj-doc-ext-kotlin/>
13+
1014
### Changed
1115

1216
- fj-bom set to 1.6.5

fj-doc-playground-quarkus/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<exec-plugin.version>3.2.0</exec-plugin.version>
2525
<antrun-plugin.version>3.1.0</antrun-plugin.version>
2626
<fj-service-helper-bom-version>1.4.0</fj-service-helper-bom-version>
27+
<fj-doc-ext-kotlin-version>0.2.0</fj-doc-ext-kotlin-version>
2728
</properties>
2829
<dependencyManagement>
2930
<dependencies>
@@ -94,6 +95,11 @@
9495
<groupId>org.fugerit.java</groupId>
9596
<artifactId>emp-service-model</artifactId>
9697
</dependency>
98+
<dependency>
99+
<groupId>org.fugerit.java</groupId>
100+
<artifactId>fj-doc-ext-kotlin</artifactId>
101+
<version>${fj-doc-ext-kotlin-version}</version>
102+
</dependency>
97103
</dependencies>
98104
<build>
99105
<plugins>

fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/doc/GenerateFacade.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@
3434
import jakarta.enterprise.context.ApplicationScoped;
3535
import lombok.extern.slf4j.Slf4j;
3636

37+
import javax.script.ScriptEngine;
38+
import javax.script.ScriptEngineManager;
39+
3740
@Slf4j
3841
@ApplicationScoped
3942
public class GenerateFacade {
4043

4144

4245
private static final String FTL_DIRECTIVE = "<#ftl";
43-
46+
4447
private void doHandle( DocTypeHandler handler, String type, int sourceType, Reader reader, ByteArrayOutputStream baos ) {
4548
SafeFunction.apply( () -> {
4649
DocInput docInput = DocInput.newInput( type, reader , sourceType );
@@ -100,6 +103,18 @@ private void handleFtlx( DocTypeHandler handler, String type, int sourceType, Re
100103
configuration.clearTemplateCache();
101104
} );
102105
}
106+
107+
private void handleKts( DocTypeHandler handler, String type, Reader reader, ByteArrayOutputStream baos ) {
108+
SafeFunction.apply( () -> {
109+
ScriptEngineManager manager = new ScriptEngineManager();
110+
ScriptEngine engine = manager.getEngineByExtension( "kts" );
111+
Object obj = engine.eval( StreamIO.readString( reader ) );
112+
String xml = obj.toString();
113+
try ( StringReader xmlReader = new StringReader( xml) ) {
114+
this.doHandle(handler, type, DocFacadeSource.SOURCE_TYPE_XML, xmlReader, baos);
115+
}
116+
} );
117+
}
103118

104119
public byte[] generateHelper( GenerateInput input, DocTypeHandler handler) throws Exception {
105120
byte[] result = null;
@@ -116,6 +131,8 @@ public byte[] generateHelper( GenerateInput input, DocTypeHandler handler) throw
116131
log.info( "output format : {}", type );
117132
if ( InputFacade.FORMAT_FTLX.equalsIgnoreCase( input.getInputFormat() ) ) {
118133
this.handleFtlx(handler, type, sourceType, reader, baos, input.getFreemarkerJsonData());
134+
} else if ( InputFacade.FORMAT_KTS.equalsIgnoreCase( input.getInputFormat() ) ) {
135+
this.handleKts(handler, type, reader, baos);
119136
} else {
120137
this.doHandle(handler, type, sourceType, reader, baos);
121138
}
@@ -144,5 +161,4 @@ public DocParser findParser( BasicInput input ) {
144161
return DocFacadeSource.getInstance().getParserForSource( sourceType );
145162
}
146163

147-
148164
}

fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/facade/InputFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ private InputFacade() {}
1111
public static final String FORMAT_XML = "XML";
1212
public static final String FORMAT_JSON = "JSON";
1313
public static final String FORMAT_YAML = "YAML";
14+
15+
public static final String FORMAT_KTS = "KTS";
1416

1517
public static final String FORMAT_FTLX = "FTLX";
1618

17-
protected static final String[] FORMATS_A = { FORMAT_XML, FORMAT_JSON, FORMAT_YAML, FORMAT_FTLX };
19+
protected static final String[] FORMATS_A = { FORMAT_XML, FORMAT_JSON, FORMAT_YAML, FORMAT_FTLX, FORMAT_KTS };
1820

1921
public static final List<String> FORMAT_LIST = Collections.unmodifiableList( Arrays.asList( FORMATS_A ) );
2022

fj-doc-playground-quarkus/src/main/react/src/playground/DocXmlEditor.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AceEditor from "react-ace";
99
import MarkdownEditor from '@uiw/react-markdown-editor';
1010

1111
import "ace-builds/src-noconflict/mode-xml";
12+
import "ace-builds/src-noconflict/mode-kotlin";
1213
import "ace-builds/src-noconflict/mode-ftl";
1314
import "ace-builds/src-noconflict/mode-markdown";
1415
import "ace-builds/src-noconflict/theme-xcode";
@@ -152,7 +153,9 @@ class DocXmlEditor extends Component {
152153
let freemarkerJsonData = '';
153154
let editorInFormat = 'xml';
154155
if ( this.state.inputFormat != null ) {
155-
if ( this.state.inputFormat === 'FTLX' ) {
156+
if ( this.state.inputFormat === 'KTS' ) {
157+
editorInFormat = 'kotlin'
158+
} else if ( this.state.inputFormat === 'FTLX' ) {
156159
editorInFormat = 'ftl'
157160
freemarkerJsonData = <Fragment>
158161
<p style={{paddingTop: "20px"}}>Json properties will be available in FTL. each property as a freemarker variable.</p>
@@ -258,6 +261,7 @@ class DocXmlEditor extends Component {
258261
<MenuItem value='XML'>XML</MenuItem>
259262
<MenuItem value='JSON'>JSON</MenuItem>
260263
<MenuItem value='YAML'>YAML</MenuItem>
264+
<MenuItem value='KTS'>KTS</MenuItem>
261265
</Select>
262266
</FormControl>
263267
</Grid>

fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/GenerateRestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private void testWorker( String apiPath, String jsonPayloadPath ) {
3737

3838
@Test
3939
void testGenerateDocument() {
40-
int[] testId = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
40+
int[] testId = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
4141
for ( int k=0; k<testId.length; k++ ) {
4242
String current = String.valueOf( testId[k]<10 ? "0"+testId[k] : testId[k] );
4343
this.testWorker( "/generate/document", "generate/test_generate_input_"+current+".json" );
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"inputFormat": "XML",
3+
"outputFormat":"HTML",
4+
"docContent":"{\n\t\"docTitle\":\"My FreeMarker Template Sample Doc Title\",\n\t\"listPeople\": [\n\t\t{ \"name\":\"Luthien\", \"surname\":\"Tinuviel\", \"title\":\"Queen\" },\n\t\t{ \"name\":\"Thorin\", \"surname\":\"Oakshield\", \"title\":\"King\" }\n\t]\n}"
5+
}

fj-doc-sample/src/main/resources/sample_docs/doc_catalog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<doc id="full_document_yaml" type="yaml" path="playground/full-document.yaml" description="More complex YAML source document"/>
2424
<doc id="doc-01" type="xml" path="playground/doc_test_01.xml" description="Image loading (does not work in excel format)"/>
2525
<doc id="doc-02" type="xml" path="playground/full_doc_header_footer.xml" description="Document which contains most tags"/>
26+
<doc id="kts-01" type="kts" path="playground/sample-1.kts" description="Sample fugerit kotlin document"/>
2627
</catalog>
2728

2829
</doc-catalog>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import org.fugerit.java.doc.base.kotlin.dsl.dslDoc
2+
3+
dslDoc {
4+
meta {
5+
info( ( "DSL Kotlin Document From JUnit 2" ) ).name( "doc-title" )
6+
}
7+
body {
8+
para( "Concise paragraph" )
9+
.align( "center" )
10+
.style( "bold" )
11+
.whiteSpaceCollapse( true )
12+
.spaceLeft( 10 )
13+
.leading( 1 )
14+
.format( "{}" )
15+
para {
16+
setText("Verbose paragraph")
17+
align( "left" )
18+
style( "italic" )
19+
whiteSpaceCollapse( true )
20+
spaceAfter( 10 )
21+
foreColor( "#000000" )
22+
backColor( "#ffffff" )
23+
}
24+
phrase( "Inline phrase" ).style( "normal" ).size( 8 )
25+
table {
26+
row {
27+
cell { para( "col 1" ) }
28+
cell { para( "col 2" ) }
29+
}.header( true )
30+
row {
31+
cell { para( "data 1" ) }
32+
cell { para( "data 2" ) }
33+
}
34+
}.width( 100 ).columns( 2 ).colwidths( "50;50" )
35+
}
36+
}

0 commit comments

Comments
 (0)