/** * Determines if two copied tokens are equal. */ private static boolean areCopiedTokensEqual(TagNode token1, TagNode token2) { return token1.name.equals(token2.name) && token1.getAttributes().equals(token2.getAttributes()); }
@Override public Map<String, Object> initMap() { Map<String, String> rMap = rootNode.getAttributes(); // repack the map <string,string> -> <string,object> rMap.entrySet().forEach(e -> map.put(e.getKey(), e.getValue())); return super.map; }
public boolean satisfy(TagNode tagNode) { return tagNode == null ? false : tagNode.getAttributes().containsKey(attName.toLowerCase()); } }
public boolean satisfy(TagNode tagNode) { return tagNode == null ? false : tagNode.getAttributes().containsKey( attName.toLowerCase() ); } }
public boolean satisfy(TagNode tagNode) { if (tagNode != null) { for (Map.Entry<String, String> entry : tagNode.getAttributes().entrySet()) { if ((attNameRegex == null || attNameRegex.matcher(entry.getKey()).find()) && (attValueRegex == null || attValueRegex.matcher(entry.getValue()).find())) { return true; } } } return false; } }
public boolean satisfy(TagNode tagNode) { if (tagNode != null ) { for(Map.Entry<String, String>entry: tagNode.getAttributes().entrySet()) { if ( (attNameRegex == null || attNameRegex.matcher(entry.getKey()).find()) && (attValueRegex == null || attValueRegex.matcher( entry.getValue() ).find())) { return true; } } } return false; } }
private boolean hasIdAttributeSet(TagNode tagNode) { Map<String, String> attributes = tagNode.getAttributes(); return !isEmptyString(attributes.get(ID_ATTRIBUTE_NAME)); }
private boolean hasIdAttributeSet(TagNode tagNode) { Map < String, String > attributes = tagNode.getAttributes(); return !isEmptyString(attributes.get(ID_ATTRIBUTE_NAME)); }
/** * Add attributes from specified map to the specified tag. * If some attribute already exist it is preserved. * @param tag * @param attributes */ private void addAttributesToTag(TagNode tag, Map<String, String> attributes) { if (attributes != null) { Map<String, String> tagAttributes = tag.getAttributes(); for(Map.Entry< String, String > currEntry : attributes.entrySet()) { String attName = currEntry.getKey(); if ( !tagAttributes.containsKey(attName) ) { String attValue = currEntry.getValue(); tag.addAttribute(attName, attValue); } } } }
/** * Add attributes from specified map to the specified tag. * If some attribute already exist it is preserved. * * @param tag * @param attributes */ private void addAttributesToTag(TagNode tag, Map<String, String> attributes) { if (attributes != null) { Map<String, String> tagAttributes = tag.getAttributes(); for (Map.Entry<String, String> currEntry : attributes.entrySet()) { String attName = currEntry.getKey(); if (!tagAttributes.containsKey(attName)) { String attValue = currEntry.getValue(); tag.addAttribute(attName, attValue); } } } }
Map<String, String> tagAtttributes = node.getAttributes();
private void filterAttributes(final TagNode node) { final Element allowedElement = elements.get(node.getName()); final Map<String, String> attributes = node.getAttributes().entrySet().stream() .filter(attribute -> allowedElement.hasAttribute(attribute.getKey())) .collect(Collectors.toMap(attribute -> attribute.getKey(), attribute -> { final String value = attribute.getValue(); final String normalizedValue = cleanCRLFTAB(CharacterReferenceNormalizer.normalize(value.toLowerCase().trim())); if (omitJavascriptProtocol && (normalizedValue.startsWith(JAVASCRIPT_PROTOCOL) || checkDataAttrValue(node.getName(), attribute.getKey(), normalizedValue))) { return ""; } return value; })); node.setAttributes(attributes); }
public static void cleanInvalidAttributes(TagNode parent) { List nodes = parent.getChildren(); if (nodes != null) { for (int i = 0; i < nodes.size(); i++) { Object curChild = nodes.get(i); if (curChild instanceof TagNode) { TagNode curNode = (TagNode)curChild; Map attrMap = curNode.getAttributes(); Set<String> toRemove = new HashSet<String>(); for (Object entryObj : attrMap.entrySet()) { Entry entry = (Entry)entryObj; String attrName = (String)entry.getKey(); if (!HtmlExtractUtils.isValidAttribute(attrName)) { toRemove.add(attrName); } } for (String remove : toRemove) { curNode.removeAttribute(remove); } cleanInvalidAttributes(curNode); } } } } }
protected void serializeOpenTag(TagNode tagNode, Writer writer, boolean newLine) throws IOException { if ( !isForbiddenTag(tagNode)) { String tagName = tagNode.getName(); Map tagAtttributes = tagNode.getAttributes();
TagNode subTagNode = (TagNode) item; Element subelement = document.createElement( subTagNode.getName() ); Map attributes = subTagNode.getAttributes(); Iterator entryIterator = attributes.entrySet().iterator(); while (entryIterator.hasNext()) {
private HeadlessTagNode(TagNode wrappedNode) { super(""); getAttributes().putAll(wrappedNode.getAttributes()); addChildren(wrappedNode.getAllChildren()); setDocType(wrappedNode.getDocType()); Map<String, String> nsDecls = getNamespaceDeclarations(); if (nsDecls != null) { Map<String, String> wrappedNSDecls = wrappedNode.getNamespaceDeclarations(); if (wrappedNSDecls != null) { nsDecls.putAll(wrappedNSDecls); } } } }
for (Map.Entry<String, String> entry: tagNode.getAttributes().entrySet()) { String attName = entry.getKey(); if (!nsAware && Utils.getXmlNSPrefix(attName) != null ) {
private HeadlessTagNode(TagNode wrappedNode) { super(""); getAttributes().putAll(wrappedNode.getAttributes()); addChildren(wrappedNode.getAllChildren()); setDocType(wrappedNode.getDocType()); Map<String, String> nsDecls = getNamespaceDeclarations(); if (nsDecls != null) { Map<String, String> wrappedNSDecls = wrappedNode.getNamespaceDeclarations(); if (wrappedNSDecls != null) { nsDecls.putAll(wrappedNSDecls); } } } }
private void setAttributes(TagNode node, Element element) { for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue(); if (escapeXml) { attrValue = Utils.escapeXml(attrValue, props, true); } String attPrefix = Utils.getXmlNSPrefix(attrName); Namespace ns = null; if (attPrefix != null) { attrName = Utils.getXmlName(attrName); if (props.isNamespacesAware()) { String nsURI = node.getNamespaceURIOnPath(attPrefix); if (nsURI == null) { nsURI = attPrefix; } if (!attPrefix.startsWith("xml")) { ns = Namespace.getNamespace(attPrefix, nsURI); } } } if (ns == null) { element.setAttribute(attrName, attrValue); } else { element.setAttribute(attrName, attrValue, ns); } } }
private void setAttributes(TagNode node, Element element) { for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue();