From a9d7361ee110a79e29d849a4c7876a2738c509fe Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 10 Oct 2010 23:20:14 +0200 Subject: Allow doctype overriding in unparser. --- org/madore/damlengine/DamlEngine.java | 3 ++- org/madore/damlengine/Unparser.java | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java index 2cde6ec..c146587 100644 --- a/org/madore/damlengine/DamlEngine.java +++ b/org/madore/damlengine/DamlEngine.java @@ -56,7 +56,8 @@ public final class DamlEngine { doc.normalizeDocument(); Unparser unparser = new Unparser(doc, new OutputStreamWriter(System.out, - "UTF-8")); + "UTF-8"), + "html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); unparser.unparse(); } diff --git a/org/madore/damlengine/Unparser.java b/org/madore/damlengine/Unparser.java index 82ff9e1..0eeec00 100644 --- a/org/madore/damlengine/Unparser.java +++ b/org/madore/damlengine/Unparser.java @@ -11,10 +11,12 @@ public final class Unparser { private enum Dir { PUSHING, POPPING } private Dir dir; private final Writer out; + private final String forceDoctype; - public Unparser(Document doc, Writer out) { + public Unparser(Document doc, Writer out, String forceDoctype) { this.doc = doc; this.out = out; + this.forceDoctype = forceDoctype; } protected void enter() { @@ -126,18 +128,22 @@ public final class Unparser { public void unparse() throws IOException { out.write(""); - DocumentType doctype = doc.getDoctype(); - if ( doctype != null ) { - String externalId = ""; - if ( doctype.getPublicId() != null ) { - externalId = " PUBLIC \""+doctype.getPublicId()+"\" \"" - +doctype.getSystemId()+"\""; - } else if ( doctype.getSystemId() != null ) { - externalId = " SYSTEM \""+doctype.getSystemId()+"\""; - } - out.write("\n"); - } else - out.write("\n"); + if ( forceDoctype == null ) { + DocumentType doctype = doc.getDoctype(); + if ( doctype != null ) { + String externalId = ""; + if ( doctype.getPublicId() != null ) { + externalId = " PUBLIC \""+doctype.getPublicId()+"\" \"" + +doctype.getSystemId()+"\""; + } else if ( doctype.getSystemId() != null ) { + externalId = " SYSTEM \""+doctype.getSystemId()+"\""; + } + out.write("\n"); + } else + out.write("\n"); + } else { + out.write("\n"); + } cursor = doc.getDocumentElement(); dir = Dir.PUSHING; while ( cursor != null ) { -- cgit v1.2.3