File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
src/main/java/io/github/fvarrui/javapackager/utils Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 11
11
import javax .xml .transform .stream .StreamResult ;
12
12
13
13
import org .w3c .dom .Document ;
14
+ import org .w3c .dom .DocumentType ;
14
15
import org .w3c .dom .Node ;
15
16
import org .w3c .dom .NodeList ;
16
17
@@ -29,13 +30,20 @@ public static final void prettify(File file) throws Exception {
29
30
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
30
31
DocumentBuilder builder = factory .newDocumentBuilder ();
31
32
Document document = builder .parse (file );
32
-
33
+
33
34
trimWhitespace (document );
34
35
35
36
Transformer transformer = TransformerFactory .newInstance ().newTransformer ();
36
37
transformer .setOutputProperty (OutputKeys .INDENT , "yes" );
38
+ transformer .setOutputProperty (OutputKeys .OMIT_XML_DECLARATION , "no" );
37
39
transformer .setOutputProperty (OutputKeys .ENCODING , "UTF-8" );
38
- transformer .setOutputProperty (OutputKeys .DOCTYPE_PUBLIC ,"yes" );
40
+
41
+ DocumentType doctype = document .getDoctype ();
42
+ if (doctype != null ) {
43
+ transformer .setOutputProperty (OutputKeys .DOCTYPE_PUBLIC , doctype .getPublicId ());
44
+ transformer .setOutputProperty (OutputKeys .DOCTYPE_SYSTEM , doctype .getSystemId ());
45
+ }
46
+
39
47
transformer .transform (new DOMSource (document ), new StreamResult (file ));
40
48
41
49
}
You can’t perform that action at this time.
0 commit comments