embed anchors at end of narrative for JSON & XML

This commit is contained in:
Grahame Grieve 2019-09-14 21:42:56 +10:00
parent 5fb54f8889
commit 024d6dc935
11 changed files with 53 additions and 4 deletions

View File

@ -486,6 +486,8 @@ public class JsonParser extends ParserBase {
if (element.hasValue())
primitiveValue(name, element);
name = "_"+name;
if (element.getType().equals("xhtml"))
json.anchor("end-xhtml");
}
if (element.hasChildren()) {
open(name, linkResolver == null ? null : linkResolver.resolveProperty(element.getProperty()));

View File

@ -501,8 +501,10 @@ public class XmlParser extends ParserBase {
String rawXhtml = element.getValue();
if (isCdaText(element.getProperty())) {
new CDANarrativeFormat().convert(xml, element.getXhtml());
} else
} else {
xml.escapedText(rawXhtml);
xml.anchor("end-xhtml");
}
} else if (isText(element.getProperty())) {
if (linkResolver != null)
xml.link(linkResolver.resolveProperty(element.getProperty()));

View File

@ -59,4 +59,5 @@ public interface JsonCreator {
// only used by an creator that actually produces xhtml
void link(String href);
void anchor(String string);
}

View File

@ -262,5 +262,10 @@ public class JsonCreatorCanonical implements JsonCreator {
// not used
}
@Override
public void anchor(String name) {
// not used
}
}

View File

@ -189,4 +189,10 @@ public class JsonCreatorDirect implements JsonCreator {
}
@Override
public void anchor(String name) {
// not used
}
}

View File

@ -106,4 +106,9 @@ public class JsonCreatorGson implements JsonCreator {
value(new BigDecimal(value));
}
@Override
public void anchor(String name) {
// not used
}
}

View File

@ -283,7 +283,7 @@ public class NPMPackageGenerator {
// also, for cache management on current builds, generate a little manifest
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(packageManifest);
TextFile.stringToFile(json, Utilities.changeFileExt(destFile, ".manifest.json"));
TextFile.stringToFile(json, Utilities.changeFileExt(destFile, ".manifest.json"), false);
}
public String filename() {

View File

@ -1363,13 +1363,29 @@ public class StructureMapUtilities {
vars.add(VariableMode.INPUT, getInputName(g, StructureMapInputMode.SOURCE, "source"), source);
if (target != null)
vars.add(VariableMode.OUTPUT, getInputName(g, StructureMapInputMode.TARGET, "target"), target);
else if (getInputName(g, StructureMapInputMode.TARGET, null) != null) {
String type = getInputType(g, StructureMapInputMode.TARGET);
throw new Error("not handled yet: creating a type of "+type);
}
executeGroup("", context, map, vars, g, true);
if (target instanceof Element)
((Element) target).sort();
}
private String getInputName(StructureMapGroupComponent g, StructureMapInputMode mode, String def) throws DefinitionException {
private String getInputType(StructureMapGroupComponent g, StructureMapInputMode mode) {
String type = null;
for (StructureMapGroupInputComponent inp : g.getInput()) {
if (inp.getMode() == mode)
if (type != null)
throw new DefinitionException("This engine does not support multiple source inputs");
else
type = inp.getType();
}
return type;
}
private String getInputName(StructureMapGroupComponent g, StructureMapInputMode mode, String def) throws DefinitionException {
String name = null;
for (StructureMapGroupInputComponent inp : g.getInput()) {
if (inp.getMode() == mode)

View File

@ -200,5 +200,12 @@ public class TextFile {
return streamToString(new ByteArrayInputStream(bs));
}
public static String bytesToString(byte[] bs, boolean removeBOM) throws IOException {
if (removeBOM)
return streamToString(new ByteArrayInputStream(bs)).replace("\uFEFF", "");
else
return streamToString(new ByteArrayInputStream(bs));
}
}

View File

@ -119,5 +119,5 @@ public interface IXMLWriter {
// this is only implemented by an implementation that is producing an xhtml representation, and is able to render elements as hyperlinks
public abstract void link(String href);
public abstract void anchor(String name);
}

View File

@ -902,6 +902,11 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
}
@Override
public void anchor(String name) {
// ignore this
}
@Override
public void decorate(ElementDecoration element) throws IOException {
// nothing...