@Override public String primitiveValue() { try { return new XhtmlComposer(false).compose(getValue()); } catch (IOException e) { } return null; }
private void loadCache() throws FHIRFormatError, IOException { File[] files = new File(cacheFolder).listFiles(); for (File f : files) { if (f.getName().endsWith(".xml")) { final FileInputStream is = new FileInputStream(f); try { Resource r = context.newXmlParser().setOutputStyle(IParser.OutputStyle.PRETTY).parse(is); if (r instanceof OperationOutcome) { OperationOutcome oo = (OperationOutcome) r; expansions.put(ToolingExtensions.getExtension(oo,VS_ID_EXT).getValue().toString(), new ValueSetExpander.ValueSetExpansionOutcome(new XhtmlComposer(true, false).composePlainText(oo.getText().getDiv()))); } else { ValueSet vs = (ValueSet) r; expansions.put(vs.getUrl(), new ValueSetExpander.ValueSetExpansionOutcome(vs, null)); } } catch (Exception theE) { throw new FHIRFormatError(theE); } finally { IOUtils.closeQuietly(is); } } } }
@Override public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { switch (hash) { case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<NarrativeStatus> case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div))}; // XhtmlNode default: return super.getProperty(hash, name, checkValid); } }
public void compose(IXMLWriter xml, XhtmlNode node) throws IOException { compose(xml, node, false); }
public String composePlainText(XhtmlNode x) { StringBuilder b = new StringBuilder(); composePlainText(x, b, false); return b.toString().trim(); }
private void writeElement(String indent, XhtmlNode node, boolean noPrettyOverride) throws IOException { if (!pretty || noPrettyOverride) indent = ""; // html self closing tags: http://xahlee.info/js/html5_non-closing_tag.html if (node.getChildNodes().size() == 0 && (xml || Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"))) dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (pretty && !noPrettyOverride ? "\r\n" : "")); else { boolean act = node.allChildrenAreText(); if (act || !pretty || noPrettyOverride) dst.append(indent + "<" + node.getName() + attributes(node)+">"); else dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n"); if (node.getName() == "head" && node.getElement("meta") == null) dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (pretty && !noPrettyOverride ? "\r\n" : "")); for (XhtmlNode c : node.getChildNodes()) writeNode(indent + " ", c, noPrettyOverride || node.isNoPretty()); if (act) dst.append("</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text) dst.append((pretty && !noPrettyOverride ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); else dst.append(indent + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); } }
public void compose(Element div, XhtmlNode x) { for (XhtmlNode child : x.getChildNodes()) { appendChild(div, child); } }
public String composeEx(XhtmlNode node) { try { return compose(node); } catch (IOException e) { throw new Error(e); } }
lastWS = composePlainText(n, b, lastWS);
private void writeElement(String indent, XhtmlNode node, boolean noPrettyOverride) throws IOException { if (!pretty || noPrettyOverride) indent = ""; // html self closing tags: http://xahlee.info/js/html5_non-closing_tag.html if (node.getChildNodes().size() == 0 && (xml || Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"))) dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (pretty && !noPrettyOverride ? "\r\n" : "")); else { boolean act = node.allChildrenAreText(); if (act || !pretty || noPrettyOverride) dst.append(indent + "<" + node.getName() + attributes(node)+">"); else dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n"); if (node.getName() == "head" && node.getElement("meta") == null) dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (pretty && !noPrettyOverride ? "\r\n" : "")); for (XhtmlNode c : node.getChildNodes()) writeNode(indent + " ", c, noPrettyOverride || node.isNoPretty()); if (act) dst.append("</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text) dst.append((pretty && !noPrettyOverride ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); else dst.append(indent + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : "")); } }
private void appendChild(Element e, XhtmlNode node) { if (node.getNodeType() == NodeType.Comment) e.appendChild(e.getOwnerDocument().createComment(node.getContent())); else if (node.getNodeType() == NodeType.DocType) throw new Error("not done yet"); else if (node.getNodeType() == NodeType.Instruction) e.appendChild(e.getOwnerDocument().createProcessingInstruction("", node.getContent())); else if (node.getNodeType() == NodeType.Text) e.appendChild(e.getOwnerDocument().createTextNode(node.getContent())); else if (node.getNodeType() == NodeType.Element) { Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName()); e.appendChild(child); for (XhtmlNode c : node.getChildNodes()) { appendChild(child, c); } } else throw new Error("Unknown node type: "+node.getNodeType().toString()); }
@Override public String toString() { switch (nodeType) { case Document: case Element: try { return new XhtmlComposer(XhtmlComposer.HTML).compose(this); } catch (IOException e) { return super.toString(); } case Text: return this.content; case Comment: return "<!-- "+this.content+" -->"; case DocType: return "<? "+this.content+" />"; case Instruction: return "<? "+this.content+" />"; } return super.toString(); }
public static String getErrorDescription(OperationOutcome error) { if (error.hasText() && error.getText().hasDiv()) return new XhtmlComposer(XhtmlComposer.XML).composePlainText(error.getText().getDiv()); StringBuilder b = new StringBuilder(); for (OperationOutcomeIssueComponent t : error.getIssue()) if (t.getSeverity() == IssueSeverity.ERROR) b.append("Error:" +t.getDetails()+"\r\n"); else if (t.getSeverity() == IssueSeverity.FATAL) b.append("Fatal:" +t.getDetails()+"\r\n"); else if (t.getSeverity() == IssueSeverity.WARNING) b.append("Warning:" +t.getDetails()+"\r\n"); else if (t.getSeverity() == IssueSeverity.INFORMATION) b.append("Information:" +t.getDetails()+"\r\n"); return b.toString(); }
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case -892481550: return getStatusElement(); case 99473: /*div*/ if (div == null) div = new XhtmlNode(NodeType.Element, "div"); return new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div)); default: return super.makeProperty(hash, name); } }
private void composeElement(IXMLWriter xml, XhtmlNode node, boolean noPrettyOverride) throws IOException { for (String n : node.getAttributes().keySet()) { if (n.equals("xmlns")) xml.setDefaultNamespace(node.getAttributes().get(n)); else if (n.startsWith("xmlns:")) xml.namespace(n.substring(6), node.getAttributes().get(n)); else xml.attribute(n, node.getAttributes().get(n)); } xml.enter(XHTML_NS, node.getName()); for (XhtmlNode n : node.getChildNodes()) compose(xml, n, noPrettyOverride || node.isNoPretty()); xml.exit(XHTML_NS, node.getName()); }
public String composePlainText(XhtmlNode x) { StringBuilder b = new StringBuilder(); composePlainText(x, b, false); return b.toString().trim(); }
public void compose(Element div, XhtmlNode x) { for (XhtmlNode child : x.getChildNodes()) { appendChild(div, child); } }
@Override public String getValueAsString() { if (isEmpty()) { return null; } try { String retVal = new XhtmlComposer(XhtmlComposer.HTML).compose(this); retVal = XhtmlDt.preprocessXhtmlNamespaceDeclaration(retVal); return retVal; } catch (Exception e) { // TODO: composer shouldn't throw exception like this throw new RuntimeException(e); } }
OperationOutcome oo = (OperationOutcome) r; expansions.put(ToolingExtensions.getExtension(oo,VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN)); } else if (r instanceof ValueSet) { ValueSet vs = (ValueSet) r;
@Override public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { switch (hash) { case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<NarrativeStatus> case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div))}; // XhtmlNode default: return super.getProperty(hash, name, checkValid); } }