Skip to content

Commit 55a27d8

Browse files
committed
0.8.4 (2023-01-26)
+ [fj-doc-base - Enable charset selection for DocTypeHandlerXML](#17) Signed-off-by: Matteo Franci a.k.a. Fugerit <m@fugerit.org>
1 parent 69251f2 commit 55a27d8

22 files changed

+340
-53
lines changed

docgen/parameters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title" : "Venus (Fugerit Document Generation Framework)",
33
"name": "Venus",
4-
"version" : "0.8.3",
5-
"date" : "24/01/2023",
4+
"version" : "0.8.4",
5+
"date" : "26/01/2023",
66
"organization" : {
77
"name" : "Fugerit Org",
88
"url" : "https://www.fugerit.org"

docgen/release-notes.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
0.8.3 (2023-01-24)
1+
0.8.4 (2023-01-26)
22
------------------
3-
+ [fj-doc-mod-fop - need to create FopConfigClassLoaderWrapper with default ResourceResolver]([0.5.2](https://github.com/fugerit-org/fj-doc/issues/15))
3+
+ [fj-doc-base - Enable charset selection for DocTypeHandlerXML](https://github.com/fugerit-org/fj-doc/issues/17)
4+
5+
0.8.3 (2023-01-24)
6+
------------------
7+
+ [fj-doc-mod-fop - need to create FopConfigClassLoaderWrapper with default ResourceResolver](https://github.com/fugerit-org/fj-doc/issues/15)
48

59
0.8.2 (2023-01-22)
610
------------------
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.fugerit.java.doc.base.config;
2+
3+
import java.nio.charset.Charset;
4+
5+
import org.fugerit.java.core.util.ObjectUtils;
6+
7+
public abstract class DocCharsetProvider {
8+
9+
public abstract Charset resolveCharset( Charset charset );
10+
11+
public static final DocCharsetProvider DEFAULT = new DocCharsetProvider() {
12+
@Override
13+
public Charset resolveCharset(Charset charset) {
14+
return ObjectUtils.objectWithDefault( charset , Charset.defaultCharset() );
15+
}
16+
};
17+
18+
private static DocCharsetProvider defaultProvider = DEFAULT;
19+
20+
public static DocCharsetProvider getDefaultProvider() {
21+
return defaultProvider;
22+
}
23+
24+
public static void setDefaultProvider(DocCharsetProvider defaultProvider) {
25+
DocCharsetProvider.defaultProvider = defaultProvider;
26+
}
27+
28+
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.fugerit.java.doc.base.config;
22

3+
import java.nio.charset.Charset;
4+
35
import org.fugerit.java.core.util.collection.KeyString;
46

57
public interface DocTypeHandler extends KeyString {
@@ -10,6 +12,8 @@ public interface DocTypeHandler extends KeyString {
1012

1113
String getMime();
1214

15+
Charset getCharset();
16+
1317
void handle( DocInput docInput, DocOutput docOutput ) throws Exception;
1418

1519
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.fugerit.java.doc.base.config;
2+
3+
import org.fugerit.java.core.cfg.ConfigException;
4+
import org.w3c.dom.Element;
5+
6+
public class DocTypeHandlerDecorator extends DocTypeHandlerDefault {
7+
8+
private static final long serialVersionUID = 5531355008187717238L;
9+
10+
private DocTypeHandler handler;
11+
12+
public DocTypeHandlerDecorator( DocTypeHandler handler ) {
13+
super( handler.getType(), handler.getModule(), handler.getMime(), handler.getCharset() );
14+
this.handler = handler;
15+
}
16+
17+
public DocTypeHandler unwrap() {
18+
return handler;
19+
}
20+
21+
@Override
22+
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
23+
this.handler.handle(docInput, docOutput);
24+
}
25+
26+
@Override
27+
public void configure(Element tag) throws ConfigException {
28+
if ( this.handler instanceof DocTypeHandlerDefault ) {
29+
((DocTypeHandlerDefault)this.handler).configure(tag);
30+
}
31+
}
32+
33+
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerDefault.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.fugerit.java.doc.base.config;
22

33
import java.io.Serializable;
4+
import java.nio.charset.Charset;
45

56
import org.fugerit.java.core.cfg.ConfigException;
67
import org.fugerit.java.core.cfg.helpers.XMLConfigurableObject;
8+
import org.fugerit.java.core.lang.helpers.StringUtils;
79
import org.fugerit.java.doc.base.helper.DefaultMimeHelper;
810
import org.w3c.dom.Element;
11+
import org.w3c.dom.NodeList;
912

1013
public class DocTypeHandlerDefault extends XMLConfigurableObject implements DocTypeHandler, Serializable {
1114

@@ -14,12 +17,18 @@ public class DocTypeHandlerDefault extends XMLConfigurableObject implements DocT
1417
*/
1518
private static final long serialVersionUID = -5024985828785381015L;
1619

20+
public static final String TAG_NAME_CONFIG = "config";
21+
22+
public static final String ATT_NAME_CHARSET = "charset";
23+
1724
private String type;
1825

1926
private String module;
2027

2128
private String mime;
2229

30+
private Charset charset;
31+
2332
@Override
2433
public String getMime() {
2534
String res = this.mime;
@@ -44,16 +53,26 @@ public String getModule() {
4453
return module;
4554
}
4655

56+
@Override
57+
public Charset getCharset() {
58+
return charset;
59+
}
60+
4761
@Override
4862
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
4963

5064
}
51-
52-
public DocTypeHandlerDefault(String type, String module, String mime) {
65+
66+
public DocTypeHandlerDefault(String type, String module, String mime, Charset charset) {
5367
super();
5468
this.type = type;
5569
this.module = module;
5670
this.mime = mime;
71+
this.charset = DocCharsetProvider.getDefaultProvider().resolveCharset(charset);
72+
}
73+
74+
public DocTypeHandlerDefault(String type, String module, String mime) {
75+
this( type, module, mime, null );
5776
}
5877

5978
public DocTypeHandlerDefault(String type, String module ) {
@@ -64,8 +83,21 @@ public static final String createKey( String type, String mod ) {
6483
return type+"-"+mod;
6584
}
6685

86+
protected void handleConfigTag( Element config ) throws ConfigException {
87+
88+
}
89+
6790
@Override
6891
public void configure(Element tag) throws ConfigException {
92+
NodeList nl = tag.getElementsByTagName( TAG_NAME_CONFIG );
93+
if ( nl.getLength() > 0 ) {
94+
Element config = (Element)nl.item( 0 );
95+
String charsetAtt = config.getAttribute( ATT_NAME_CHARSET );
96+
if ( StringUtils.isNotEmpty( charsetAtt ) ) {
97+
this.charset = Charset.forName( charsetAtt );
98+
}
99+
this.handleConfigTag(config);
100+
}
69101
}
70102

71103
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/config/DocTypeHandlerXML.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.fugerit.java.doc.base.config;
22

33
import java.io.OutputStreamWriter;
4+
import java.nio.charset.Charset;
5+
import java.nio.charset.StandardCharsets;
46

57
import org.fugerit.java.core.io.StreamIO;
68

@@ -13,17 +15,23 @@ public class DocTypeHandlerXML extends DocTypeHandlerDefault {
1315

1416
public static final DocTypeHandler HANDLER = new DocTypeHandlerXML();
1517

18+
public static final DocTypeHandler HANDLER_UTF8 = new DocTypeHandlerXML( StandardCharsets.UTF_8 );
19+
1620
public static final String TYPE = DocConfig.TYPE_XML;
1721

1822
public static final String MODULE = "doc";
1923

24+
public DocTypeHandlerXML( Charset charset ) {
25+
super( TYPE, MODULE, null, charset );
26+
}
27+
2028
public DocTypeHandlerXML() {
2129
super( TYPE, MODULE );
2230
}
2331

2432
@Override
2533
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
26-
StreamIO.pipeCharCloseBoth( docInput.getReader() , new OutputStreamWriter( docOutput.getOs() ) );
34+
StreamIO.pipeCharCloseBoth( docInput.getReader() , new OutputStreamWriter( docOutput.getOs(), this.getCharset() ) );
2735
}
2836

2937
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.fugerit.java.doc.base.config;
2+
3+
public class DocTypeHandlerXMLUTF8 extends DocTypeHandlerDecorator {
4+
5+
private static final long serialVersionUID = -8512962187951518109L;
6+
7+
public static final DocTypeHandler HANDLER = new DocTypeHandlerXMLUTF8();
8+
9+
public DocTypeHandlerXMLUTF8() {
10+
super( DocTypeHandlerXML.HANDLER_UTF8 );
11+
}
12+
13+
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehandler/markdown/AbstractCustomMarkdownTypeHandler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.fugerit.java.doc.base.typehandler.markdown;
22

3+
import java.nio.charset.Charset;
4+
35
import org.fugerit.java.doc.base.config.DocConfig;
46
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
57

@@ -11,11 +13,19 @@ public abstract class AbstractCustomMarkdownTypeHandler extends DocTypeHandlerDe
1113

1214
public static final String MIME = "text/x-markdown";
1315

14-
public AbstractCustomMarkdownTypeHandler( boolean printComments ) {
15-
super(TYPE, MODULE, MIME);
16+
public AbstractCustomMarkdownTypeHandler( Charset charset, boolean printComments ) {
17+
super(TYPE, MODULE, MIME, charset);
1618
this.printComments = printComments;
1719
}
1820

21+
public AbstractCustomMarkdownTypeHandler( Charset charset ) {
22+
this( charset, MarkdownBasicDocFacade.DEFAULT_PRINT_COMMENTS );
23+
}
24+
25+
public AbstractCustomMarkdownTypeHandler( boolean printComments ) {
26+
this( null, printComments );
27+
}
28+
1929
public AbstractCustomMarkdownTypeHandler() {
2030
this( MarkdownBasicDocFacade.DEFAULT_PRINT_COMMENTS );
2131
}

fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehandler/markdown/SimpleMarkdownBasicTypeHandler.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.OutputStreamWriter;
44
import java.io.PrintWriter;
5+
import java.nio.charset.Charset;
6+
import java.nio.charset.StandardCharsets;
57

68
import org.fugerit.java.doc.base.config.DocInput;
79
import org.fugerit.java.doc.base.config.DocOutput;
@@ -24,6 +26,10 @@ public class SimpleMarkdownBasicTypeHandler extends AbstractCustomMarkdownTypeHa
2426

2527
public static final DocTypeHandler HANDLER_NOCOMMENTS = new SimpleMarkdownBasicTypeHandler( false );
2628

29+
public static final DocTypeHandler HANDLER_UTF8 = new SimpleMarkdownBasicTypeHandler( StandardCharsets.UTF_8 );
30+
31+
public static final DocTypeHandler HANDLER_NOCOMMENTS_UTF8 = new SimpleMarkdownBasicTypeHandler( StandardCharsets.UTF_8, false );
32+
2733
/**
2834
*
2935
*/
@@ -35,15 +41,21 @@ public SimpleMarkdownBasicTypeHandler() {
3541
super();
3642
}
3743

38-
39-
4044
public SimpleMarkdownBasicTypeHandler(boolean printComments) {
4145
super(printComments);
4246
}
4347

48+
public SimpleMarkdownBasicTypeHandler(Charset charset, boolean printComments) {
49+
super(charset, printComments);
50+
}
51+
52+
public SimpleMarkdownBasicTypeHandler(Charset charset) {
53+
super(charset);
54+
}
55+
4456
@Override
4557
public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
46-
PrintWriter writer = new PrintWriter( new OutputStreamWriter( docOutput.getOs() ) );
58+
PrintWriter writer = new PrintWriter( new OutputStreamWriter( docOutput.getOs(), this.getCharset() ) );
4759
DocBase docBase = docInput.getDoc();
4860
/*
4961
* The key for building a DocTypeHandler is to correctly renders

0 commit comments

Comments
 (0)