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 1111import javax .xml .transform .stream .StreamResult ;
1212
1313import org .w3c .dom .Document ;
14+ import org .w3c .dom .DocumentType ;
1415import org .w3c .dom .Node ;
1516import org .w3c .dom .NodeList ;
1617
@@ -29,13 +30,20 @@ public static final void prettify(File file) throws Exception {
2930 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
3031 DocumentBuilder builder = factory .newDocumentBuilder ();
3132 Document document = builder .parse (file );
32-
33+
3334 trimWhitespace (document );
3435
3536 Transformer transformer = TransformerFactory .newInstance ().newTransformer ();
3637 transformer .setOutputProperty (OutputKeys .INDENT , "yes" );
38+ transformer .setOutputProperty (OutputKeys .OMIT_XML_DECLARATION , "no" );
3739 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+
3947 transformer .transform (new DOMSource (document ), new StreamResult (file ));
4048
4149 }
You can’t perform that action at this time.
0 commit comments