@Override protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) { if ("src".equalsIgnoreCase(attr.getKey())) { String src = attr.getValue(); if (StrUtils.isNotBlank(src) && src.toLowerCase().startsWith("javascript")) { return false; } } return ("img".equals(tagName) && "src".equals(attr.getKey()) && attr.getValue().startsWith("data:;base64")) || super.isSafeAttribute(tagName, el, attr); } }
private void copyAttributes(org.jsoup.nodes.Node source, Element el) { for (Attribute attribute : source.attributes()) { // valid xml attribute names are: ^[a-zA-Z_:][-a-zA-Z0-9_:.] String key = attribute.getKey().replaceAll("[^-a-zA-Z0-9_:.]", ""); if (key.matches("[a-zA-Z_:][-a-zA-Z0-9_:.]*")) el.setAttribute(key, attribute.getValue()); } }
public Entry<String, String> next() { return new Attribute(attr.getKey().substring(dataPrefix.length()), attr.getValue()); }
/** * Finds any namespaces defined in this element. Returns any tag prefix. */ private String updateNamespaces(org.jsoup.nodes.Element el) { // scan the element for namespace declarations // like: xmlns="blah" or xmlns:prefix="blah" Attributes attributes = el.attributes(); for (Attribute attr : attributes) { String key = attr.getKey(); String prefix; if (key.equals(xmlnsKey)) { prefix = ""; } else if (key.startsWith(xmlnsPrefix)) { prefix = key.substring(xmlnsPrefix.length()); } else { continue; } namespacesStack.peek().put(prefix, attr.getValue()); } // get the element prefix if any int pos = el.tagName().indexOf(":"); return pos > 0 ? el.tagName().substring(0, pos) : ""; }
/** Set a new attribute, or replace an existing one by key. @param attribute attribute with case sensitive key @return these attributes, for chaining */ public Attributes put(Attribute attribute) { Validate.notNull(attribute); put(attribute.getKey(), attribute.getValue()); attribute.parent = this; return this; }
String attrKey = attr.getKey(); if (expect.hasKeyIgnoreCase(attrKey)) { return expect.getIgnoreCase(attrKey).equals(attr.getValue());
private boolean testValidProtocol(Element el, Attribute attr, Set<Protocol> protocols) { // try to resolve relative urls to abs, and optionally update the attribute so output html has abs. // rels without a baseuri get removed String value = el.absUrl(attr.getKey()); if (value.length() == 0) value = attr.getValue(); // if it could not be made abs, run as-is to allow custom unknown protocols if (!preserveRelativeLinks) attr.setValue(value); for (Protocol protocol : protocols) { String prot = protocol.toString(); if (prot.equals("#")) { // allows anchor links if (isValidAnchor(value)) { return true; } else { continue; } } prot += ":"; if (lowerCase(value).startsWith(prot)) { return true; } } return false; }
void processAttributes(Node node) { Attributes attributes = myState.myAttributes; if (myOptions.outputAttributesIdAttr || !myOptions.outputAttributesNamesRegex.isEmpty()) { final org.jsoup.nodes.Attributes nodeAttributes = node.attributes(); boolean idDone = false; if (myOptions.outputAttributesIdAttr) { String id = nodeAttributes.get("id"); if (id == null || id.isEmpty()) { id = nodeAttributes.get("name"); } if (id != null && !id.isEmpty()) { attributes.replaceValue("id", id); idDone = true; } } if (!myOptions.outputAttributesNamesRegex.isEmpty()) { for (org.jsoup.nodes.Attribute attribute : nodeAttributes) { if (idDone && (attribute.getKey().equals("id") || attribute.getKey().equals("name"))) { continue; } if (attribute.getKey().matches(myOptions.outputAttributesNamesRegex)) { attributes.replaceValue(attribute.getKey(), attribute.getValue()); } } } } }
public void dumpHtmlTree(FormattingAppendable out, Node node) { out.line().append(node.nodeName()); for (org.jsoup.nodes.Attribute attribute : node.attributes().asList()) { out.append(' ').append(attribute.getKey()).append("=\"").append(attribute.getValue()).append("\""); } out.line().indent(); for (Node child : node.childNodes()) { dumpHtmlTree(out, child); } out.unIndent(); }
private void copyAttributes(org.jsoup.nodes.Node source, Element el) { for (Attribute attribute : source.attributes()) { // valid xml attribute names are: ^[a-zA-Z_:][-a-zA-Z0-9_:.] String key = attribute.getKey().replaceAll("[^-a-zA-Z0-9_:.]", ""); if (key.matches("[a-zA-Z_:][-a-zA-Z0-9_:.]*")) el.setAttribute(key, attribute.getValue()); } }
private void copyAttributes(org.jsoup.nodes.Node source, org.w3c.dom.Element el) { for (Attribute attribute : source.attributes()) { // valid xml attribute names are: ^[a-zA-Z_:][-a-zA-Z0-9_:.] String key = attribute.getKey().replaceAll("[^-a-zA-Z0-9_:.]", ""); if (key.matches("[a-zA-Z_:][-a-zA-Z0-9_:.]*")) el.setAttribute(key, attribute.getValue()); } } }
private Attributes computeAttributes() { AttributesImpl attributes = new AttributesImpl(); for (Attribute attr : element.attributes()) { attributes.addAttribute(null, attr.getKey(), null, null, attr.getValue()); } return attributes; }
private org.xml.sax.Attributes convertAttributes(final Attributes jsoup) { final AttributesImpl sax = new AttributesImpl(); jsoup.forEach(a -> sax.addAttribute(NS, a.getKey(), a.getKey(), "", a.getValue())); return sax; }
/** * @param attributes A list of attribs * @return Returns a mutable map parsed out of the attribute list */ public static Map<String, String> parseAttribs(Attributes attributes) { Map<String, String> attrs = new LinkedHashMap<String, String>(attributes.size() + 4); for (Attribute a : attributes.asList()) if (!SKIP_ATTR.contains(a.getKey())) attrs.put(a.getKey(), a.getValue()); return attrs; }
/** * @param attributes A list of attribs * @return Returns a mutable map parsed out of the attribute list */ public static Map<String, String> parseAttribs(Attributes attributes) { Map<String, String> attrs = new LinkedHashMap<String, String>(attributes.size() + 4); for (Attribute a : attributes.asList()) if (!SKIP_ATTR.contains(a.getKey())) attrs.put(a.getKey(), a.getValue()); return attrs; }
public void copyAttributes(Element src) { Attributes attrs = src.attributes(); Iterator<Attribute> it = attrs.iterator(); Attribute attr; while (it.hasNext()) { attr = it.next(); this.attr(attr.getKey(), attr.getValue()); } } }
public ServiceEntry(Attribute serviceAttribute, Attribute paramsAttribute) { this.namespace = ServiceAttributeUtil.extractNamespace(serviceAttribute.getKey()); this.name = serviceAttribute.getValue(); this.params = getParams(paramsAttribute); this.cacheKey = String.format("%s|%s", getName(), getParams()); }