/** * Sets the value of * * @param theString * @throws Exception */ public void setDivAsString(String theString) { XhtmlNode div; if (StringUtils.isNotBlank(theString)) { div = new XhtmlNode(); div.setValueAsString(theString); } else { div = null; } setDiv(div); }
public static boolean compareDeep(XhtmlNode div1, XhtmlNode div2, boolean allowNull) { if (div1 == null && div2 == null && allowNull) return true; if (div1 == null || div2 == null) return false; return div1.equalsDeep(div2); }
public XhtmlNode getElement(String name) { for (XhtmlNode n : childNodes) if (n.getNodeType() == NodeType.Element && name.equals(n.getName())) return n; return null; }
public XhtmlNode addInstruction(String content) { if (!(nodeType == NodeType.Document)) throw new Error("Wrong node type"); XhtmlNode node = new XhtmlNode(NodeType.Instruction); node.setContent(content); childNodes.add(node); return node; }
public String allText() { if (childNodes == null || childNodes.isEmpty()) return getContent(); StringBuilder b = new StringBuilder(); for (XhtmlNode n : childNodes) if (n.getNodeType() == NodeType.Text) b.append(n.getContent()); else if (n.getNodeType() == NodeType.Element) b.append(n.allText()); return b.toString(); }
private void checkInnerNS(List<ValidationMessage> errors, Element e, String path, List<XhtmlNode> list) { for (XhtmlNode node : list) { if (node.getNodeType() == NodeType.Element) { String ns = node.getNsDecl(); rule(errors, IssueType.INVALID, e.line(), e.col(), path, ns == null || FormatUtilities.XHTML_NS.equals(ns), "Wrong namespace on the XHTML ('"+ns+"')"); checkInnerNS(errors, e, path, node.getChildNodes()); } } }
private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(node.getLocalName()); defaultNS = checkNS(res, node, defaultNS); for (int i = 0; i < node.getAttributes().getLength(); i++) { Attr attr = (Attr) node.getAttributes().item(i); if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns")) res.getAttributes().put(attr.getName(), attr.getValue()); } Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { res.addText(child.getTextContent()); } else if (child.getNodeType() == Node.COMMENT_NODE) { res.addComment(child.getTextContent()); } else if (child.getNodeType() == Node.ELEMENT_NODE) { if (elementIsOk(child.getLocalName())) res.getChildNodes().add(parseNode((Element) child, defaultNS)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc()); child = child.getNextSibling(); } return res; }
public String getDivAsString() { XhtmlNode div = getDiv(); if (div != null && !div.isEmpty()) { return div.getValueAsString(); } else { return null; } }
if (xhtml != null) { // if it is null, this is an error already noted in the parsers String ns = xhtml.getNsDecl(); rule(errors, IssueType.INVALID, e.line(), e.col(), path, FormatUtilities.XHTML_NS.equals(ns), "Wrong namespace on the XHTML ('"+ns+"')"); checkInnerNS(errors, e, path, xhtml.getChildNodes()); rule(errors, IssueType.INVALID, e.line(), e.col(), path, "div".equals(xhtml.getName()), "Wrong name on the XHTML ('"+ns+"') - must start with div"); checkInnerNames(errors, e, path, xhtml.getChildNodes());
public XhtmlNode generate(TableModel model, String imagePath, int border, Set<String> outputTracker) throws IOException, FHIRException { checkModel(model); XhtmlNode table = new XhtmlNode(NodeType.Element, "table").setAttribute("border", Integer.toString(border)).setAttribute("cellspacing", "0").setAttribute("cellpadding", "0"); table.setAttribute("style", "border: " + border + "px #F0F0F0 solid; font-size: 11px; font-family: verdana; vertical-align: top;"); XhtmlNode tr = table.addTag("tr"); tr.setAttribute("style", "border: " + Integer.toString(1 + border) + "px #F0F0F0 solid; font-size: 11px; font-family: verdana; vertical-align: top;"); XhtmlNode tc = null; for (Title t : model.getTitles()) { tc = renderCell(tr, t, "th", null, null, null, false, null, "white", 0, imagePath, border, outputTracker); if (t.width != 0) tc.setAttribute("style", "width: "+Integer.toString(t.width)+"px"); tc.addTag("span").setAttribute("style", "float: right").addTag("a").setAttribute("title", "Legend for this format").setAttribute("href", model.getDocoRef()).addTag("img").setAttribute("alt", "doco").setAttribute("style", "background-color: inherit").setAttribute("src", model.getDocoImg()); tr = table.addTag("tr"); tc = tr.addTag("td"); tc.setAttribute("class", "hierarchy"); tc.setAttribute("colspan", Integer.toString(model.getTitles().size())); tc.addTag("br"); XhtmlNode a = tc.addTag("a").setAttribute("title", translate("sd.doco", "Legend for this format")).setAttribute("href", model.getDocoRef()); if (model.getDocoImg() != null) a.addTag("img").setAttribute("alt", "doco").setAttribute("style", "background-color: inherit").setAttribute("src", model.getDocoImg()); a.addText(" "+translate("sd.doco", "Documentation for this format"));
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()); }
private XhtmlNode renderCell(XhtmlNode tr, Cell c, String name, String icon, String hint, List<Integer> indents, boolean hasChildren, String anchor, String color, int lineColor, String imagePath, int border, Set<String> outputTracker) throws IOException { XhtmlNode tc = tr.addTag(name); tc.setAttribute("class", "hierarchy"); if (indents != null) { tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_spacer.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); tc.setAttribute("style", "vertical-align: top; text-align : left; background-color: "+color+"; border: "+ border +"px #F0F0F0 solid; padding:0px 4px 0px 4px; white-space: nowrap; background-image: url("+imagePath+checkExists(indents, hasChildren, lineColor, outputTracker)+")"); for (int i = 0; i < indents.size()-1; i++) { switch (indents.get(i)) { case NEW_SLICER: case NEW_SLICE: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_blank.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); break; case CONTINUE_REGULAR: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vline.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); break; case CONTINUE_SLICER: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vline_slicer.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); break; case CONTINUE_SLICE: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vline_slice.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); break; default: switch (indents.get(indents.size()-1)) { case NEW_REGULAR: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", "."); break; case NEW_SLICER: tc.addTag("img").setAttribute("src", srcFor(imagePath, "tbl_vjoin_end_slicer.png")).setAttribute("style", "background-color: inherit").setAttribute("class", "hierarchy").setAttribute("alt", ".");
public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException { String id = getLogicalMappingId(sd); if (id == null) return null; String prefix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_PREFIX); String suffix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_SUFFIX); if (prefix == null || suffix == null) return null; // we build this by text. Any element that has a mapping, we put it's mappings inside it.... StringBuilder b = new StringBuilder(); b.append(prefix); ElementDefinition root = sd.getSnapshot().getElementFirstRep(); String m = getMapping(root, id); if (m != null) b.append(m+"\r\n"); addChildMappings(b, id, "", sd, root, false); b.append("\r\n"); b.append(suffix); b.append("\r\n"); StructureMap map = parse(b.toString(), sd.getUrl()); map.setId(tail(map.getUrl())); if (!map.hasStatus()) map.setStatus(PublicationStatus.DRAFT); map.getText().setStatus(NarrativeStatus.GENERATED); map.getText().setDiv(new XhtmlNode(NodeType.Element, "div")); map.getText().getDiv().addTag("pre").addText(render(map)); return map; }
public XhtmlNode parseHtmlNode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError { XhtmlNode res = parseNode(xpp); if (res.getNsDecl() == null) res.getAttributes().put("xmlns", XHTML_NS); return res; } private XhtmlNode parseNode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
public Narrative copy() { Narrative dst = new Narrative(); copyValues(dst); dst.status = status == null ? null : status.copy(); dst.div = div == null ? null : div.copy(); return dst; }
public boolean hasDiv() { return this.div != null && !this.div.isEmpty(); }
/** * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.) */ public XhtmlNode getDiv() { if (this.div == null) if (Configuration.errorOnAutoCreate()) throw new Error("Attempt to auto-create Narrative.div"); else if (Configuration.doAutoCreate()) this.div = new XhtmlNode(); // cc return this.div; }
public boolean allChildrenAreText() { boolean res = true; for (XhtmlNode n : childNodes) res = res && n.getNodeType() == NodeType.Text; return res; }
protected void composeXhtml(String name, XhtmlNode html) throws IOException { if (!Utilities.noString(xhtmlMessage)) { xml.enter(XhtmlComposer.XHTML_NS, name); xml.comment(xhtmlMessage, false); xml.exit(XhtmlComposer.XHTML_NS, name); } else { XhtmlComposer comp = new XhtmlComposer(XhtmlComposer.XML, htmlPretty); // name is also found in the html and should the same // ? check that boolean oldPretty = xml.isPretty(); xml.setPretty(htmlPretty); if (html.getNodeType() != NodeType.Text && html.getNsDecl() == null) xml.namespace(XhtmlComposer.XHTML_NS, null); comp.compose(xml, html); xml.setPretty(oldPretty); } }