2424import org .fugerit .java .core .lang .helpers .BooleanUtils ;
2525import org .fugerit .java .core .lang .helpers .ClassHelper ;
2626import org .fugerit .java .core .lang .helpers .StringUtils ;
27- import org .fugerit .java .core .xml .TransformerXML ;
2827import org .fugerit .java .core .xml .dom .DOMIO ;
2928import org .fugerit .java .core .xml .dom .DOMUtils ;
3029import org .fugerit .java .doc .base .config .DocCharsetProvider ;
4443public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler {
4544
4645 public static final DocTypeHandler HANDLER = new PdfFopTypeHandler ();
47-
46+
4847 public static final String ATT_FOP_CONFIG_MODE = "fop-config-mode" ;
4948 public static final String ATT_FOP_CONFIG_MODE_DEFAULT = "default" ;
5049 public static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER = "classloader" ;
5150 public static final String ATT_FOP_CONFIG_MODE_INLINE = "inline" ;
52-
51+
5352 private static final String ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY = "classloader-legacy" ; // removed as of v2.0.1
54-
53+
5554 public static final String ATT_FOP_CONFIG_CLASSLOADER_PATH = "fop-config-classloader-path" ;
56-
55+
5756 public static final String ATT_FOP_CONFIG_RESOLVER_TYPE = "fop-config-resover-type" ;
5857
5958 public static final String ATT_FOP_CONFIG_RESOLVER_TYPE_DEFAULT = FopConfigClassLoaderWrapper .DEFAULT_RESOURCE_RESOLVER .getClass ().getName ();
60-
59+
6160 public static final String ATT_PDF_A_MODE = "pdf-a-mode" ;
6261 public static final String ATT_PDF_A_MODE_PDF_A_1A = DocConfig .FORMAT_PDF_A_1A ;
6362 public static final String ATT_PDF_A_MODE_PDF_A_1B = DocConfig .FORMAT_PDF_A_1B ;
@@ -66,36 +65,36 @@ public class PdfFopTypeHandler extends FreeMarkerFopTypeHandler {
6665
6766 public static final String ATT_PDF_UA_MODE = "pdf-ua-mode" ;
6867 public static final String ATT_PDF_UA_MODE_PDF_UA_1 = DocConfig .FORMAT_PDF_UA_1 ;
69-
68+
7069 private static final String [] VALID_PDF_A = { ATT_PDF_A_MODE_PDF_A_1A , ATT_PDF_A_MODE_PDF_A_1B , ATT_PDF_A_MODE_PDF_A_2A };
7170 public static final List <String > VALID_PDF_A_MODES = Collections .unmodifiableList ( Arrays .asList ( VALID_PDF_A ) );
72-
71+
7372 private static final String [] VALID_PDF_UA = { ATT_PDF_UA_MODE_PDF_UA_1 };
7473 public static final List <String > VALID_PDF_UA_MODES = Collections .unmodifiableList ( Arrays .asList ( VALID_PDF_UA ) );
75-
74+
7675 private static final String ATT_FONT_BASE_CLASSLOADER_PATH = "font-base-classloader-path" ; // removed as of v2.0.1
77-
76+
7877 public static final boolean DEFAULT_ACCESSIBILITY = true ;
79-
78+
8079 public static final boolean DEFAULT_KEEP_EMPTY_TAGS = false ;
81-
80+
8281 public static final String ATT_FOP_SUPPRESS_EVENTS = "fop-suppress-events" ;
8382
8483 public static final String ATT_FOP_POOL_MIN = "fop-pool-min" ;
8584
8685 public static final String ATT_FOP_POOL_MAX = "fop-pool-max" ;
8786
8887 private static final String FOP_CONFIG_ROOT = "fop" ;
89-
88+
9089 /**
91- *
90+ *
9291 */
9392 private static final long serialVersionUID = -7394516771708L ;
9493
9594 @ Getter private boolean accessibility ;
96-
95+
9796 @ Getter private boolean keepEmptyTags ;
98-
97+
9998 private Serializable fopConfig ;
10099
101100 public FopConfig getFopConfig () {
@@ -107,9 +106,9 @@ public void setFopConfig(FopConfig fopConfig) {
107106 }
108107
109108 @ Getter @ Setter private String pdfAMode ;
110-
109+
111110 @ Getter @ Setter private String pdfUAMode ;
112-
111+
113112 @ Getter @ Setter private boolean suppressEvents ;
114113
115114 @ Getter @ Setter private transient int fopPoolMin ;
@@ -121,7 +120,7 @@ public void setFopConfig(FopConfig fopConfig) {
121120 private transient UnsafeSupplier <FopConfigWrap , ConfigException > fopWrapSupplier ;
122121
123122 private transient UnsafeConsumer <FopConfigWrap , ConfigException > fopWrapConsumer ;
124-
123+
125124 public PdfFopTypeHandler ( Charset charset , FopConfig fopConfig , boolean accessibility , boolean keepEmptyTags ) {
126125 super ( DocConfig .TYPE_PDF , charset );
127126 this .fopConfig = fopConfig ;
@@ -133,27 +132,27 @@ public PdfFopTypeHandler( Charset charset, FopConfig fopConfig, boolean accessib
133132 this .fopPoolMin = 0 ;
134133 this .fopPoolMax = 0 ;
135134 }
136-
135+
137136 public PdfFopTypeHandler ( Charset charset , FopConfig fopConfig ) {
138137 this ( charset , fopConfig , DEFAULT_ACCESSIBILITY , DEFAULT_KEEP_EMPTY_TAGS );
139138 }
140-
139+
141140 public PdfFopTypeHandler ( FopConfig fopConfig , boolean accessibility , boolean keepEmptyTags ) {
142141 this ( DocCharsetProvider .getDefaultProvider ().resolveCharset ( null ), fopConfig , accessibility , keepEmptyTags );
143142 }
144-
143+
145144 public PdfFopTypeHandler ( Charset charset , boolean accessibility , boolean keepEmptyTags ) {
146145 this ( charset , FopConfigDefault .DEFAULT , accessibility , keepEmptyTags );
147146 }
148-
147+
149148 public PdfFopTypeHandler ( Charset charset ) {
150149 this ( charset , DEFAULT_ACCESSIBILITY , DEFAULT_KEEP_EMPTY_TAGS );
151150 }
152-
151+
153152 public PdfFopTypeHandler ( boolean accessibility , boolean keepEmptyTags ) {
154153 this ( FopConfigDefault .DEFAULT , accessibility , keepEmptyTags );
155154 }
156-
155+
157156 public PdfFopTypeHandler () {
158157 this ( DEFAULT_ACCESSIBILITY , DEFAULT_KEEP_EMPTY_TAGS );
159158 }
@@ -190,7 +189,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
190189 StreamSource xmlSource = new StreamSource ( new InputStreamReader ( new ByteArrayInputStream ( buffer .toByteArray () ), this .getCharset () ) );
191190 FopConfigWrap fopWrap = this .fopWrapSupplier .get ();
192191 Fop fop = fopWrap .getFopFactory ().newFop (MimeConstants .MIME_PDF , fopWrap .getFoUserAgent (), docOutput .getOs ());
193- TransformerFactory factory = TransformerXML . newSafeTransformerFactory ();
192+ TransformerFactory factory = TransformerFactory . newInstance ();
194193 Transformer transformer = factory .newTransformer ();
195194 Result res = new SAXResult (fop .getDefaultHandler ());
196195 transformer .transform (xmlSource , res );
@@ -211,7 +210,7 @@ protected void handleConfigTag(Element config) throws ConfigException {
211210 log .info ( "pdf ua mode -> {} : {}" , ATT_PDF_UA_MODE , pdfUAModConfig );
212211 if ( VALID_PDF_UA_MODES .contains ( pdfUAModConfig ) ) {
213212 this .setPdfUAMode ( pdfUAModConfig );
214- this .setFormat ( pdfUAModConfig );
213+ this .setFormat ( pdfUAModConfig );
215214 } else {
216215 throw new ConfigException ( ATT_PDF_UA_MODE +" not valid : " +pdfUAModConfig +"( valid modes are : " +VALID_PDF_A_MODES +")" );
217216 }
@@ -222,7 +221,7 @@ protected void handleConfigTag(Element config) throws ConfigException {
222221 log .info ( "pdf a mode -> {} : {}" , ATT_PDF_A_MODE , pdfAModConfig );
223222 if ( VALID_PDF_A_MODES .contains ( pdfAModConfig ) ) {
224223 this .setPdfAMode ( pdfAModConfig );
225- this .setFormat ( pdfAModConfig );
224+ this .setFormat ( pdfAModConfig );
226225 } else {
227226 throw new ConfigException ( ATT_PDF_A_MODE +" not valid : " +pdfAModConfig +"( valid modes are : " +VALID_PDF_A_MODES +")" );
228227 }
@@ -251,7 +250,7 @@ private void setupPool( Properties props ) throws ConfigException {
251250 }
252251 if ( StringUtils .isNotEmpty ( props .getProperty ( ATT_FOP_POOL_MAX ) ) ) {
253252 this .setFopPoolMax ( Integer .parseInt ( props .getProperty ( ATT_FOP_POOL_MAX ) ) );
254- } else if ( this .getFopPoolMin () > 0 ) {
253+ } else if ( this .getFopPoolMin () > 0 ) {
255254 this .setFopPoolMax ( this .getFopPoolMin () );
256255 }
257256 }
@@ -261,7 +260,7 @@ private void setupFopConfigMode( String fopConfigMode, String fopConfigResoverTy
261260 ConfigException .apply ( () -> {
262261 ResourceResolver customResourceResolver = (ResourceResolver ) ClassHelper .newInstance ( fopConfigResoverType );
263262 FopConfigClassLoaderWrapper fopConfigClassLoaderWrapper = new FopConfigClassLoaderWrapper (fopConfigClassloaderPath , customResourceResolver );
264- this .fopConfig = fopConfigClassLoaderWrapper ;
263+ this .fopConfig = fopConfigClassLoaderWrapper ;
265264 } );
266265 } else if ( ATT_FOP_CONFIG_MODE_INLINE .equalsIgnoreCase ( fopConfigMode ) ) {
267266 ConfigException .apply ( () -> {
@@ -273,10 +272,10 @@ private void setupFopConfigMode( String fopConfigMode, String fopConfigResoverTy
273272 try ( ByteArrayOutputStream baos = new ByteArrayOutputStream () ) {
274273 DOMIO .writeDOM ( nl .item ( 0 ) , baos );
275274 fopConfigInlineData = baos .toByteArray ();
276- }
275+ }
277276 ResourceResolver customResourceResolver = (ResourceResolver ) ClassHelper .newInstance ( fopConfigResoverType );
278277 FopConfigClassLoaderWrapper fopConfigClassLoaderWrapper = new FopConfigClassLoaderWrapper (fopConfigInlineData , customResourceResolver );
279- this .fopConfig = fopConfigClassLoaderWrapper ;
278+ this .fopConfig = fopConfigClassLoaderWrapper ;
280279 } );
281280 } else if ( ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY .equalsIgnoreCase ( fopConfigMode ) ) {
282281 log .warn ( "Activated legacy ClassLoader mode. it is now deprecated : {}" , ATT_FOP_CONFIG_MODE_CLASS_LOADER_LEGACY );
0 commit comments