11package org .fugerit .java .doc .base .config ;
22
33import java .io .Serializable ;
4+ import java .nio .charset .Charset ;
45
56import org .fugerit .java .core .cfg .ConfigException ;
67import org .fugerit .java .core .cfg .helpers .XMLConfigurableObject ;
8+ import org .fugerit .java .core .lang .helpers .StringUtils ;
79import org .fugerit .java .doc .base .helper .DefaultMimeHelper ;
810import org .w3c .dom .Element ;
11+ import org .w3c .dom .NodeList ;
912
1013public 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}
0 commit comments