@Override public Element shallowClone() { // simpler than implementing a clone version with no child copy return new Element(tag, baseUri, attributes); }
/** Create a new Element, with this document's base uri. Does not make the new element a child of this document. @param tagName element tag name (e.g. {@code a}) @return new element */ public Element createElement(String tagName) { return new Element(Tag.valueOf(tagName, ParseSettings.preserveCase), this.baseUri()); }
Element insertStartTag(String startTagName) { Element el = new Element(Tag.valueOf(startTagName, settings), baseUri); insert(el); return el; }
/** * Read a svg file and return the svg element (original) and a new symbol element (created from * original). * * @param file Svg file. * @param id ID to use. * @return Svg element (original) and a symbol element (converted). * @throws IOException If something goes wrong. */ private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException { Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first(); Element symbol = new Element(Tag.valueOf("symbol"), "") .attr("id", id) .attr("viewBox", svg.attr("viewBox")); new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild); return new Tuple(svg, symbol); }
/** * Create a new element by tag name, and add it as the first child. * * @param tagName the name of the tag (e.g. {@code div}). * @return the new element, to allow you to add content to it, e.g.: * {@code parent.prependElement("h1").attr("id", "header").text("Welcome");} */ public Element prependElement(String tagName) { Element child = new Element(Tag.valueOf(tagName), baseUri()); prependChild(child); return child; }
/** * Create a new element by tag name, and add it as the last child. * * @param tagName the name of the tag (e.g. {@code div}). * @return the new element, to allow you to add content to it, e.g.: * {@code parent.appendElement("h1").attr("id", "header").text("Welcome");} */ public Element appendElement(String tagName) { Element child = new Element(Tag.valueOf(tagName), baseUri()); appendChild(child); return child; }
@Override public void run(final Config conf) throws Exception { String input = get("input"); if (input == null) { throw new IllegalArgumentException("Required option 'svg-symbol.input' not present"); } Path basedir = Paths.get(get("basedir").toString()); Path dir = basedir.resolve(input); List<CharSequence> cssout = new ArrayList<>(); Element svg = new Element(Tag.valueOf("svg"), ""); attrs("svg", "output").forEach((n, v) -> svg.attr(n, v.toString())); files(dir, file -> { log.debug("{}", file); String id = get("id.prefix") + file.getFileName().toString().replace(".svg", "") + get("id.suffix"); Tuple<Element, Element> rewrite = symbol(file, id); svg.appendChild(rewrite._2); cssout.add(css(id, rewrite._1)); }); write(basedir.resolve(svgPath()), ImmutableList.of(svg.outerHtml())); write(basedir.resolve(cssPath()), cssout); }
Element insert(Token.StartTag startTag) { Tag tag = Tag.valueOf(startTag.name(), settings); // todo: wonder if for xml parsing, should treat all tags as unknown? because it's not html. Element el = new Element(tag, baseUri, settings.normalizeAttributes(startTag.attributes)); insertNode(el); if (startTag.isSelfClosing()) { if (!tag.isKnownTag()) // unknown tag, remember this is self closing for output. see above. tag.setSelfClosing(); } else { stack.add(el); } return el; }
Element insert(Token.StartTag startTag) { // handle empty unknown tags // when the spec expects an empty tag, will directly hit insertEmpty, so won't generate this fake end tag. if (startTag.isSelfClosing()) { Element el = insertEmpty(startTag); stack.add(el); tokeniser.transition(TokeniserState.Data); // handles <script />, otherwise needs breakout steps from script data tokeniser.emit(emptyEnd.reset().name(el.tagName())); // ensure we get out of whatever state we are in. emitted for yielded processing return el; } Element el = new Element(Tag.valueOf(startTag.name(), settings), baseUri, settings.normalizeAttributes(startTag.attributes)); insert(el); return el; }
Element insertEmpty(Token.StartTag startTag) { Tag tag = Tag.valueOf(startTag.name(), settings); Element el = new Element(tag, baseUri, startTag.attributes); insertNode(el); if (startTag.isSelfClosing()) { if (tag.isKnownTag()) { if (!tag.isEmpty()) tokeniser.error("Tag cannot be self closing; not a void tag"); } else // unknown tag, remember this is self closing for output tag.setSelfClosing(); } return el; }
private ElementMeta createSafeElement(Element sourceEl) { String sourceTag = sourceEl.tagName(); Attributes destAttrs = new Attributes(); Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs); int numDiscarded = 0; Attributes sourceAttrs = sourceEl.attributes(); for (Attribute sourceAttr : sourceAttrs) { if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr)) destAttrs.put(sourceAttr); else numDiscarded++; } Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag); destAttrs.addAll(enforcedAttrs); return new ElementMeta(dest, numDiscarded); }
root = new Element(Tag.valueOf("html", settings), baseUri); doc.appendChild(root); stack.add(root);
public void head(Node source, int depth) { if (elementToSkip != null) { return; } if (source instanceof Element) { Element sourceElement = (Element) source; if (isSafeTag(sourceElement)) { String sourceTag = sourceElement.tagName(); Attributes destinationAttributes = sourceElement.attributes().clone(); Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes); destination.appendChild(destinationChild); destination = destinationChild; } else if (source != root) { elementToSkip = sourceElement; } } else if (source instanceof TextNode) { TextNode sourceText = (TextNode) source; TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri()); destination.appendChild(destinationText); } else if (source instanceof DataNode && isSafeTag(source.parent())) { DataNode sourceData = (DataNode) source; DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri()); destination.appendChild(destinationData); } }
break; Element replacement = new Element(Tag.valueOf(node.nodeName(), ParseSettings.preserveCase), tb.getBaseUri()); Element adopter = new Element(formatEl.tag(), tb.getBaseUri()); adopter.attributes().addAll(formatEl.attributes()); Node[] childNodes = furthestBlock.childNodes().toArray(new Node[furthestBlock.childNodeSize()]);
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); Element popupContent = new Element(Tag.valueOf("popup-content"), ""); popupContent.appendChild( designContext.createElement(content.getPopupComponent())); String minimizedHTML = content.getMinimizedValueAsHTML(); if (minimizedHTML != null && !minimizedHTML.isEmpty()) { design.append(minimizedHTML); } design.appendChild(popupContent); }
.getFragmentNodes(); Element mainDiv = new Element(Tag.valueOf("div"), ""); mainDiv.attr("id", context.getAppId()); mainDiv.addClass("v-app"); fragmentNodes.add(new Element(Tag.valueOf("script"), "") .attr("type", "text/javascript").attr("src", pushJS)); fragmentNodes.add(new Element(Tag.valueOf("script"), "") .attr("type", "text/javascript") .attr("src", bootstrapLocation)); Element mainScriptTag = new Element(Tag.valueOf("script"), "") .attr("type", "text/javascript");
private static Element createHtmlImportElement(String url) { final Element htmlImportElement; if (url != null) { htmlImportElement = new Element(Tag.valueOf("link"), "") .attr("rel", "import").attr("href", url); } else { htmlImportElement = new Element(Tag.valueOf("span"), "") .attr("hidden", true); } return htmlImportElement; }
protected Element createMenuElement(MenuItem item, DesignContext context) { Element menuElement = new Element(Tag.valueOf("menu"), "");
private static Element createSafeElement(Element sourceEl) { String sourceTag = sourceEl.tagName(); org.jsoup.nodes.Attributes destAttrs = new org.jsoup.nodes.Attributes(); Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs); org.jsoup.nodes.Attributes sourceAttrs = sourceEl.attributes(); for (Attribute sourceAttr : sourceAttrs) { destAttrs.put(sourceAttr); } return dest; }
@Test public void testAnchor() throws UIMAException { final JCas jCas = JCasSingleton.getJCasInstance(); final StructuralAnnotations sa = new StructuralAnnotations(); final Element anchor = new Element(Tag.valueOf("a"), ""); final AnnotationCollector collector = new AnnotationCollector(); sa.map(jCas, anchor, collector); assertTrue(collector.getAnnotations().get(0) instanceof Anchor); }