private void processFootNodeRef(IXMLWriter xml, XhtmlNode n) { throw new Error("element "+n.getName()+" not handled yet"); }
private void processTFoot(IXMLWriter xml, XhtmlNode n) { throw new Error("element "+n.getName()+" not handled yet"); }
private void processFootNote(IXMLWriter xml, XhtmlNode n) { throw new Error("element "+n.getName()+" not handled yet"); }
public XhtmlNode getElement(String name) { for (XhtmlNode n : childNodes) if (n.getNodeType() == NodeType.Element && name.equals(n.getName())) return n; return null; }
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" : "")); } }
list.add(new Piece(null, c.getContent(), null)); else if (c.getNodeType() == NodeType.Element) { if (c.getName().equals("a")) { list.add(new Piece(c.getAttribute("href"), c.allText(), c.getAttribute("title"))); } else if (c.getName().equals("b") || c.getName().equals("em") || c.getName().equals("strong")) { list.add(new Piece(null, c.allText(), null).setStyle("font-face: bold")); } else if (c.getName().equals("code")) { list.add(new Piece(null, c.allText(), null).setStyle("padding: 2px 4px; color: #005c00; background-color: #f9f2f4; white-space: nowrap; border-radius: 4px")); } else if (c.getName().equals("i")) { list.add(new Piece(null, c.allText(), null).setStyle("font-style: italic")); } else if (c.getName().equals("pre")) { Piece p = new Piece(c.getName()).setStyle("white-space: pre; font-family: courier"); list.add(p); p.getChildren().addAll(c.getChildNodes()); } else if (c.getName().equals("ul") || c.getName().equals("ol")) { Piece p = new Piece(c.getName()); list.add(p); p.getChildren().addAll(c.getChildNodes()); } else if (c.getName().equals("i")) { list.add(new Piece(null, c.allText(), null).setStyle("font-style: italic")); } else if (c.getName().equals("h1")||c.getName().equals("h2")||c.getName().equals("h3")||c.getName().equals("h4")) { Piece p = new Piece(c.getName()); list.add(p); p.getChildren().addAll(c.getChildNodes()); } else if (c.getName().equals("br")) { list.add(new Piece(c.getName())); } else { throw new Error("Not handled yet: "+c.getName());
return; case Element: if (n.getName().equals("br")) processBreak(xml, n); else if (n.getName().equals("h2")) processCaption(xml, n); else if (n.getName().equals("col")) processCol(xml, n); else if (n.getName().equals("colgroup")) processColGroup(xml, n); else if (n.getName().equals("span")) processContent(xml, n); else if (n.getName().equals("footnote")) processFootNote(xml, n); else if (n.getName().equals("footnoteRef")) processFootNodeRef(xml, n); else if (n.getName().equals("li")) processItem(xml, n); else if (n.getName().equals("linkHtml")) processlinkHtml(xml, n); else if (n.getName().equals("ul") || n.getName().equals("ol")) processList(xml, n); else if (n.getName().equals("p")) processParagraph(xml, n); else if (n.getName().equals("img")) processRenderMultiMedia(xml, n); else if (n.getName().equals("sub")) processSub(xml, n); else if (n.getName().equals("sup"))
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; }
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 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()); }
private void checkInnerNames(List<ValidationMessage> errors, Element e, String path, List<XhtmlNode> list) { for (XhtmlNode node : list) { if (node.getNodeType() == NodeType.Element) { rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.existsInList(node.getName(), "p", "br", "div", "h1", "h2", "h3", "h4", "h5", "h6", "a", "span", "b", "em", "i", "strong", "small", "big", "tt", "small", "dfn", "q", "var", "abbr", "acronym", "cite", "blockquote", "hr", "address", "bdo", "kbd", "q", "sub", "sup", "ul", "ol", "li", "dl", "dt", "dd", "pre", "table", "caption", "colgroup", "col", "thead", "tr", "tfoot", "tbody", "th", "td", "code", "samp", "img", "map", "area" ), "Illegal element name in the XHTML ('"+node.getName()+"')"); for (String an : node.getAttributes().keySet()) { boolean ok = an.startsWith("xmlns") || Utilities.existsInList(an, "title", "style", "class", "id", "lang", "xml:lang", "dir", "accesskey", "tabindex", // tables "span", "width", "align", "valign", "char", "charoff", "abbr", "axis", "headers", "scope", "rowspan", "colspan") || Utilities.existsInList(node.getName()+"."+an, "a.href", "a.name", "img.src", "img.border", "div.xmlns", "blockquote.cite", "q.cite", "a.charset", "a.type", "a.name", "a.href", "a.hreflang", "a.rel", "a.rev", "a.shape", "a.coords", "img.src", "img.alt", "img.longdesc", "img.height", "img.width", "img.usemap", "img.ismap", "map.name", "area.shape", "area.coords", "area.href", "area.nohref", "area.alt", "table.summary", "table.width", "table.border", "table.frame", "table.rules", "table.cellspacing", "table.cellpadding", "pre.space" ); if (!ok) rule(errors, IssueType.INVALID, e.line(), e.col(), path, false, "Illegal attribute name in the XHTML ('"+an+"' on '"+node.getName()+"')"); } checkInnerNames(errors, e, path, node.getChildNodes()); } } }
private void checkInnerNames(List<ValidationMessage> errors, Element e, String path, List<XhtmlNode> list) { for (XhtmlNode node : list) { if (node.getNodeType() == NodeType.Element) { rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.existsInList(node.getName(), "p", "br", "div", "h1", "h2", "h3", "h4", "h5", "h6", "a", "span", "b", "em", "i", "strong", "small", "big", "tt", "small", "dfn", "q", "var", "abbr", "acronym", "cite", "blockquote", "hr", "address", "bdo", "kbd", "q", "sub", "sup", "ul", "ol", "li", "dl", "dt", "dd", "pre", "table", "caption", "colgroup", "col", "thead", "tr", "tfoot", "tbody", "th", "td", "code", "samp", "img", "map", "area" ), "Illegal element name in the XHTML ('"+node.getName()+"')"); for (String an : node.getAttributes().keySet()) { boolean ok = an.startsWith("xmlns") || Utilities.existsInList(an, "title", "style", "class", "id", "lang", "xml:lang", "dir", "accesskey", "tabindex", // tables "span", "width", "align", "valign", "char", "charoff", "abbr", "axis", "headers", "scope", "rowspan", "colspan") || Utilities.existsInList(node.getName()+"."+an, "a.href", "a.name", "img.src", "img.border", "div.xmlns", "blockquote.cite", "q.cite", "a.charset", "a.type", "a.name", "a.href", "a.hreflang", "a.rel", "a.rev", "a.shape", "a.coords", "img.src", "img.alt", "img.longdesc", "img.height", "img.width", "img.usemap", "img.ismap", "map.name", "area.shape", "area.coords", "area.href", "area.nohref", "area.alt", "table.summary", "table.width", "table.border", "table.frame", "table.rules", "table.cellspacing", "table.cellpadding", "pre.space" ); if (!ok) rule(errors, IssueType.INVALID, e.line(), e.col(), path, false, "Illegal attribute name in the XHTML ('"+an+"' on '"+node.getName()+"')"); } checkInnerNames(errors, e, path, node.getChildNodes()); } } }
private void checkInnerNames(List<ValidationMessage> errors, Element e, String path, List<XhtmlNode> list) { for (XhtmlNode node : list) { if (node.getNodeType() == NodeType.Element) { rule(errors, IssueType.INVALID, e.line(), e.col(), path, Utilities.existsInList(node.getName(), "p", "br", "div", "h1", "h2", "h3", "h4", "h5", "h6", "a", "span", "b", "em", "i", "strong", "small", "big", "tt", "small", "dfn", "q", "var", "abbr", "acronym", "cite", "blockquote", "hr", "address", "bdo", "kbd", "q", "sub", "sup", "ul", "ol", "li", "dl", "dt", "dd", "pre", "table", "caption", "colgroup", "col", "thead", "tr", "tfoot", "tbody", "th", "td", "code", "samp", "img", "map", "area" ), "Illegal element name in the XHTML ('"+node.getName()+"')"); for (String an : node.getAttributes().keySet()) { boolean ok = an.startsWith("xmlns") || Utilities.existsInList(an, "title", "style", "class", "id", "lang", "xml:lang", "dir", "accesskey", "tabindex", // tables "span", "width", "align", "valign", "char", "charoff", "abbr", "axis", "headers", "scope", "rowspan", "colspan") || Utilities.existsInList(node.getName()+"."+an, "a.href", "a.name", "img.src", "img.border", "div.xmlns", "blockquote.cite", "q.cite", "a.charset", "a.type", "a.name", "a.href", "a.hreflang", "a.rel", "a.rev", "a.shape", "a.coords", "img.src", "img.alt", "img.longdesc", "img.height", "img.width", "img.usemap", "img.ismap", "map.name", "area.shape", "area.coords", "area.href", "area.nohref", "area.alt", "table.summary", "table.width", "table.border", "table.frame", "table.rules", "table.cellspacing", "table.cellpadding", "pre.space", "td.nowrap" ); if (!ok) rule(errors, IssueType.INVALID, e.line(), e.col(), path, false, "Illegal attribute name in the XHTML ('"+an+"' on '"+node.getName()+"')"); } checkInnerNames(errors, e, path, node.getChildNodes()); } } }
private void processList(IXMLWriter xml, XhtmlNode n) throws IOException, FHIRException { if (n.getName().equals("ol")) xml.attribute("listType", "ordered"); else xml.attribute("listType", "unordered"); processAttributes(n, xml, "id", "language", "styleCode"); xml.enter("list"); processChildren(xml, n); xml.exit("list"); }
readChar(); QName n = new QName(readToTagEnd()); if (node.getName().equals(n.getName())) return; else throw new FHIRFormatError("Malformed XHTML: Found \"</"+n.getName()+">\" expecting \"</"+node.getName()+">\""+descLoc()); for (int i = parents.size() - 1; i >= 0; i--) if (parents.get(i).getName().equals(n)) unwindPoint = parents.get(i); throw new FHIRFormatError("Unable to Parse HTML - node '" + node.getName() + "' has unexpected content '"+peekChar()+"' (last text = '"+lastText+"'"+descLoc());
rule(errors, IssueType.INVALID, e.line(), e.col(), path, "div".equals(xhtml.getName()), "Wrong name on the XHTML ('"+ns+"') - must start with div");
rule(errors, IssueType.INVALID, e.line(), e.col(), path, "div".equals(xhtml.getName()), "Wrong name on the XHTML ('"+ns+"') - must start with div");
rule(errors, IssueType.INVALID, e.line(), e.col(), path, "div".equals(xhtml.getName()), "Wrong name on the XHTML ('"+ns+"') - must start with div");