Skip to content

Commit ce17a77

Browse files
authored
Merge pull request #18 from fugerit-org/feature/issue_17_charset
0.8.4 (2023-01-26)
2 parents 69251f2 + 1ea23e4 commit ce17a77

File tree

38 files changed

+356
-69
lines changed

38 files changed

+356
-69
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" : "27/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-27)
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
------------------

fj-doc-base-json/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.8.3</version>
10+
<version>0.8.4</version>
1111
</parent>
1212

1313
<name>fj-doc-base-json</name>

fj-doc-base-yaml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.8.3</version>
10+
<version>0.8.4</version>
1111
</parent>
1212

1313
<name>fj-doc-base-yaml</name>

fj-doc-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-doc</artifactId>
10-
<version>0.8.3</version>
10+
<version>0.8.4</version>
1111
</parent>
1212

1313
<name>fj-doc-base</name>
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
}

0 commit comments

Comments
 (0)