From a04e5ac0177ae30908046a99c68c3195137ad34b Mon Sep 17 00:00:00 2001 From: Mauritz Jeanson Date: Wed, 2 May 2012 17:57:07 +0000 Subject: [PATCH] Added fixes to ensure that generated XHTML markup for callouts is in the proper namespace. --- .../src/com/nwalsh/saxon/FormatCallout.java | 26 +++++++++++++------ .../nwalsh/saxon/FormatGraphicCallout.java | 17 ++++++++---- .../com/nwalsh/saxon/FormatTextCallout.java | 4 +-- .../nwalsh/saxon/FormatUnicodeCallout.java | 12 ++++++--- xsl-saxon/src/com/nwalsh/saxon/Verbatim.java | 14 +++++++--- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/xsl-saxon/src/com/nwalsh/saxon/FormatCallout.java b/xsl-saxon/src/com/nwalsh/saxon/FormatCallout.java index 2c4e34877..bdb4c5939 100644 --- a/xsl-saxon/src/com/nwalsh/saxon/FormatCallout.java +++ b/xsl-saxon/src/com/nwalsh/saxon/FormatCallout.java @@ -34,12 +34,15 @@ import com.nwalsh.saxon.Callout; public abstract class FormatCallout { protected static final String foURI = "http://www.w3.org/1999/XSL/Format"; protected static final String xhURI = "http://www.w3.org/1999/xhtml"; + protected String uri = ""; protected boolean foStylesheet = false; + protected boolean xhStylesheet = false; protected NamePool namePool = null; - public FormatCallout(NamePool nPool, boolean fo) { + public FormatCallout(NamePool nPool, boolean fo, boolean xhtml) { namePool = nPool; foStylesheet = fo; + xhStylesheet = xhtml; } public String areaLabel(Element area) { @@ -82,26 +85,33 @@ public abstract class FormatCallout { return id; } - public void startSpan(Emitter rtf, String id) throws TransformerException { - + if (!foStylesheet && namePool != null) { - int spanName = namePool.allocate("", "", "span"); + if(xhStylesheet) { + uri = xhURI; + } + + + int spanName = namePool.allocate("", uri, "span"); + AttributeCollection spanAttr = new AttributeCollection(namePool); int namespaces[] = new int[1]; - spanAttr.addAttribute("", "", "class", "CDATA", "co"); - spanAttr.addAttribute("", "", "id", "CDATA", id); + spanAttr.addAttribute("", uri, "class", "CDATA", "co"); + spanAttr.addAttribute("", uri, "id", "CDATA", id); rtf.startElement(spanName, spanAttr, namespaces, 0); } - } public void endSpan(Emitter rtf) throws TransformerException { if (!foStylesheet && namePool != null) { - int spanName = namePool.allocate("", "", "span"); + if (xhStylesheet) { + uri = xhURI; + } + int spanName = namePool.allocate("", uri, "span"); rtf.endElement(spanName); } } diff --git a/xsl-saxon/src/com/nwalsh/saxon/FormatGraphicCallout.java b/xsl-saxon/src/com/nwalsh/saxon/FormatGraphicCallout.java index eade59403..fde0409ce 100644 --- a/xsl-saxon/src/com/nwalsh/saxon/FormatGraphicCallout.java +++ b/xsl-saxon/src/com/nwalsh/saxon/FormatGraphicCallout.java @@ -37,8 +37,9 @@ public class FormatGraphicCallout extends FormatCallout { int graphicsMax = 0; String iconSize = ""; - public FormatGraphicCallout(NamePool nPool, String path, String ext, int max, String size, boolean fo) { - super(nPool, fo); + public FormatGraphicCallout(NamePool nPool, String path, String ext, int max, + String size, boolean fo, boolean xhtml) { + super(nPool, fo, xhtml); graphicsPath = path; graphicsExt = ext; graphicsMax = max; @@ -72,9 +73,15 @@ public class FormatGraphicCallout extends FormatCallout { imgAttr.addAttribute("", "", "content-width", "CDATA", iconSize); imgAttr.addAttribute("", "", "width", "CDATA", iconSize); - // HTML - } else { - imgName = namePool.allocate("", "", "img"); + // XHTML/HTML + } else { + if (xhStylesheet) { + imgName = namePool.allocate("", xhURI, "img"); + } + else { + imgName = namePool.allocate("", "", "img"); + } + imgAttr = new AttributeCollection(namePool); imgAttr.addAttribute("", "", "src", "CDATA", graphicsPath + num + graphicsExt); diff --git a/xsl-saxon/src/com/nwalsh/saxon/FormatTextCallout.java b/xsl-saxon/src/com/nwalsh/saxon/FormatTextCallout.java index 263c913b9..4de640585 100644 --- a/xsl-saxon/src/com/nwalsh/saxon/FormatTextCallout.java +++ b/xsl-saxon/src/com/nwalsh/saxon/FormatTextCallout.java @@ -27,8 +27,8 @@ import com.nwalsh.saxon.Callout; **/ public class FormatTextCallout extends FormatCallout { - public FormatTextCallout(NamePool nPool, boolean fo) { - super(nPool, fo); + public FormatTextCallout(NamePool nPool, boolean fo, boolean xhtml) { + super(nPool, fo, xhtml); } public void formatCallout(Emitter rtfEmitter, diff --git a/xsl-saxon/src/com/nwalsh/saxon/FormatUnicodeCallout.java b/xsl-saxon/src/com/nwalsh/saxon/FormatUnicodeCallout.java index 21b5599ee..90bf33c73 100644 --- a/xsl-saxon/src/com/nwalsh/saxon/FormatUnicodeCallout.java +++ b/xsl-saxon/src/com/nwalsh/saxon/FormatUnicodeCallout.java @@ -39,8 +39,9 @@ public class FormatUnicodeCallout extends FormatCallout { String font, int start, int max, - boolean fo) { - super(nPool, fo); + boolean fo, + boolean xhtml) { + super(nPool, fo, xhtml); unicodeFont = font; unicodeMax = max; unicodeStart = start; @@ -72,7 +73,12 @@ public class FormatUnicodeCallout extends FormatCallout { inAttr.addAttribute("", "", "id", "ID", id); } else { - inName = namePool.allocate("", "", "font"); + if (xhStylesheet) { + inName = namePool.allocate("", xhURI, "font"); + } else { + inName = namePool.allocate("", "", "font"); + } + inAttr = new AttributeCollection(namePool); inAttr.addAttribute("", "", "face", "CDATA", unicodeFont); inAttr.addAttribute("", "", "id", "ID", id); diff --git a/xsl-saxon/src/com/nwalsh/saxon/Verbatim.java b/xsl-saxon/src/com/nwalsh/saxon/Verbatim.java index f817645b8..33d7328ec 100644 --- a/xsl-saxon/src/com/nwalsh/saxon/Verbatim.java +++ b/xsl-saxon/src/com/nwalsh/saxon/Verbatim.java @@ -56,6 +56,8 @@ import com.nwalsh.saxon.CalloutEmitter; public class Verbatim { /** True if the stylesheet is producing formatting objects */ private static boolean foStylesheet = false; + /** True if the stylesheet is producing XHTML */ + private static boolean xhStylesheet = false; /** The modulus for line numbering (every 'modulus' line is numbered). */ private static int modulus = 0; /** The width (in characters) of line numbers (for padding). */ @@ -246,7 +248,7 @@ public class Verbatim { LineCountEmitter lcEmitter = new LineCountEmitter(); rtf.replay(lcEmitter); int numLines = lcEmitter.lineCount(); - + int listingModulus = numLines < modulus ? 1 : modulus; double log10numLines = Math.log(numLines) / Math.log(10); @@ -326,6 +328,7 @@ public class Verbatim { graphicsMax = 0; iconSize = "7pt"; foStylesheet = false; + xhStylesheet = false; calloutsSetup = true; Value variable = null; @@ -334,6 +337,7 @@ public class Verbatim { // Get the stylesheet type varString = getVariable(context, "stylesheet.result.type"); foStylesheet = (varString.equals("fo")); + xhStylesheet = (varString.equals("xhtml")); // Get the default column varString = getVariable(context, "callout.defaultcolumn"); @@ -382,7 +386,8 @@ public class Verbatim { graphicsExt, graphicsMax, iconSize, - foStylesheet); + foStylesheet, + xhStylesheet); } else if (useUnicode) { // Get the starting character varString = getVariable(context, "callout.unicode.start.character"); @@ -414,9 +419,10 @@ public class Verbatim { unicodeFont, unicodeStart, unicodeMax, - foStylesheet); + foStylesheet, + xhStylesheet); } else { - fCallout = new FormatTextCallout(namePool, foStylesheet); + fCallout = new FormatTextCallout(namePool, foStylesheet, xhStylesheet); } } -- 2.40.0