List of usage examples for org.jdom2.filter AbstractFilter AbstractFilter
AbstractFilter
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
/** * Liste tous les lments dont le champ fieldParam <b>commence</b> par la chane de caractres "value", parmi les fils de l'lment racine. * <i>A n'utiliser que pour chercher des volumes par leur nom.</i> * @param root Le noeud contenant les lments parmi lesquels on effectue la recherche * @param fieldParam Le champ sur lequel porte la recherche * @param value La valeur du champ fieldParam * @return la liste des lments rpondant au critre. *//*from w w w. ja v a 2 s .com*/ public List<Element> findVolumes(Element root, String fieldParam, String value) { final String field = fieldParam; final String identity = value; Filter<Element> f = new AbstractFilter<Element>() { @Override public Element filter(Object o) { if (o instanceof Element) { Element element = (Element) o; String name = getVolumeName(element.getAttributeValue(field)); if (name.startsWith(identity)) { return element; } } return null; } }; return root.getContent(f); }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
/** * Renvoie l'lment dont l'attribut "pk" correspond <code>idNumber</code> parmi les fils de l'lment <code>racine</code> * @param racine //from w w w .j a v a 2s .c om * @param idNumber * @return L'lment demand ou <code>null</code> si celui-ci n'a pas t trouv. */ public Element findElement(Element racine, String idNumber) { final String id = idNumber; Filter<Element> f = new AbstractFilter<Element>() { @Override public Element filter(Object o) { if (o instanceof Element) { Element element = (Element) o; if (element.getAttributeValue("pk").equals(id)) { return element; } } return null; } }; List<Element> elements = racine.getContent(f); if (elements != null) { if (elements.size() > 0) return elements.get(0); } return null; }
From source file:fr.crnan.videso3d.databases.aip.AIP.java
License:Open Source License
public List<Element> findElementsByChildId(Element root, String childParam, String value) { final String child = childParam; final String childID = value; Filter<Element> f = new AbstractFilter<Element>() { @Override//w ww .j ava2 s . c om public Element filter(Object o) { if (o instanceof Element) { Element element = (Element) o; String pkChild = element.getChild(child).getAttributeValue("pk"); if (pkChild.equals(childID)) { return (Element) o; } } return null; } }; return root.getContent(f); }
From source file:org.openconcerto.xml.JDOM2Utils.java
License:Open Source License
/** * Get the filtered content of an element, optionnaly merging adjacent {@link Text}. Adjacent * text can only happen programmatically. * // w w w.j av a 2s .c om * @param elem the parent. * @param pred which content to return. * @param mergeText <code>true</code> if adjacent Text should be merged into one, * <code>false</code> to leave the list as it is. * @return the filtered content (not supportting {@link Iterator#remove()}). */ public static Iterator<Content> getContent(final Element elem, final IPredicate<? super Content> pred, final boolean mergeText) { final Iterator<Content> iter = (Iterator<Content>) elem.getContent(new AbstractFilter<Content>() { @Override public Content filter(Object obj) { final Content c = (Content) obj; return pred.evaluateChecked(c) ? c : null; } }).iterator(); if (!mergeText) return iter; return new Iterator<Content>() { private Content next = null; @Override public boolean hasNext() { return this.next != null || iter.hasNext(); } @Override public Content next() { if (this.next != null) { final Content res = this.next; this.next = null; return res; } Content res = iter.next(); assert res != null; if (res instanceof Text && iter.hasNext()) { this.next = iter.next(); Text concatText = null; while (this.next instanceof Text) { if (concatText == null) { concatText = new Text(res.getValue()); } concatText.append((Text) this.next); this.next = iter.hasNext() ? iter.next() : null; } assert this.next != null; if (concatText != null) res = concatText; } return res; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }