summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-10-10 23:20:14 +0200
committerDavid A. Madore <david+git@madore.org>2010-10-10 23:20:14 +0200
commita9d7361ee110a79e29d849a4c7876a2738c509fe (patch)
tree382e1f803d1a3b6440f7d1dbee421d7a96c7c656
parent3d574c5090212ad271e1878719b4704a0466d2c5 (diff)
downloaddamlengine-a9d7361ee110a79e29d849a4c7876a2738c509fe.tar.gz
damlengine-a9d7361ee110a79e29d849a4c7876a2738c509fe.tar.bz2
damlengine-a9d7361ee110a79e29d849a4c7876a2738c509fe.zip
Allow doctype overriding in unparser.
-rw-r--r--org/madore/damlengine/DamlEngine.java3
-rw-r--r--org/madore/damlengine/Unparser.java32
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("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
- 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("<!DOCTYPE "+doctype.getName()+externalId+">\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("<!DOCTYPE "+doctype.getName()+externalId+">\n");
+ } else
+ out.write("\n");
+ } else {
+ out.write("<!DOCTYPE "+forceDoctype+">\n");
+ }
cursor = doc.getDocumentElement();
dir = Dir.PUSHING;
while ( cursor != null ) {