@Override public boolean matches(Element root, Element element) { List<org.jsoup.nodes.Attribute> values = element.attributes().asList(); for (org.jsoup.nodes.Attribute attribute : values) { if (lowerCase(attribute.getKey()).startsWith(keyPrefix)) return true; } return false; }
/** * Clears the children and attributes of the given element. * * @param design * the element to be cleared */ public static void clearElement(Element design) { Attributes attr = design.attributes(); for (Attribute a : attr.asList()) { attr.remove(a.getKey()); } List<Node> children = new ArrayList<>(); children.addAll(design.childNodes()); for (Node node : children) { node.remove(); } }
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 static Map<String, String> getSignalToUrlMapping(Element scriptDocument) { return scriptDocument.getElementsByAttributeStarting(FORM_SIGNAL_ATTR_PREFIX).stream() .flatMap(element -> element.attributes().asList().stream()) .filter(allAttr -> allAttr.getKey().startsWith(FORM_SIGNAL_ATTR_PREFIX)) .collect( Collectors.toMap(e -> e.getKey().replace(FORM_SIGNAL_ATTR_PREFIX, StringUtils.EMPTY), Entry::getValue)); } }
private void clearFromActionAttributes(Element item) { item.attributes().asList().stream() .filter(attr -> attr.getKey().matches(ACTION_FORM_ATTRIBUTES_PATTERN)) .forEach(attr -> item.removeAttr(attr.getKey())); }
/** * @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; }
/** * @param attributes A list of attribs * @return Returns a mutable map parsed out of the attribute list */ 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())) continue; else attrs.put(a.getKey(), a.getValue()); return attrs; }
/** * Factory method that creates context from the {@link Fragment}. All services and params are * extracted to separate entries. * * @param fragment - fragment from which the context will be created. * @return a FragmentContext that wraps given fragment. */ public static FragmentContext from(Fragment fragment) { Document document = Jsoup.parseBodyFragment(fragment.content()); Element scriptTag = document.body().child(0); List<Attribute> attributes = scriptTag.attributes().asList(); Map<String, Attribute> serviceAttributes = attributes.stream() .filter(attribute -> attribute.getKey().matches(DATA_SERVICE)) .collect(Collectors .toMap(attribute -> ServiceAttributeUtil.extractNamespace(attribute.getKey()), Function.identity())); Map<String, Attribute> paramsAttributes = attributes.stream() .filter(attribute -> attribute.getKey().matches(DATA_PARAMS)) .collect(Collectors .toMap(attribute -> ServiceAttributeUtil.extractNamespace(attribute.getKey()), Function.identity())); return new FragmentContext() .fragment(fragment) .services( serviceAttributes.entrySet().stream() .map(entry -> new ServiceEntry(entry.getValue(), paramsAttributes.get(entry.getKey()))) .collect(Collectors.toList()) ); }
Element scriptTag = document.body().child(0); List<Attribute> attributes = scriptTag.attributes().asList();
private static String getAttribute(Fragment fragment, String attributeId) { Document document = Jsoup.parseBodyFragment(fragment.content()); Element scriptTag = document.body().child(0); List<Attribute> attributes = scriptTag.attributes().asList(); return attributes.stream() .filter(a -> StringUtils.equals(attributeId, a.getKey())) .findFirst() .map(Attribute::getValue) .orElse(null); }
private EditDialog parseEditDialog(Node node) { EditDialog editDialog = new EditDialog(); editDialog.setElement(node.nodeName()); for (Attribute attribute : node.attributes().asList()) { editDialog.addAttribute(attribute.getKey(), attribute.getValue()); } return editDialog; }