/** If mods:genre was not mapped by conversion/import function, ignore this publication and do not import */ private static boolean shouldIgnore(Element publication) { return !publication.getDescendants(new ElementFilter("genre", MCRConstants.MODS_NAMESPACE)).hasNext(); }
public static void removeChangeTracking(Element element) { for (Iterator<ProcessingInstruction> iter = element.getDescendants(Filters.processinginstruction()) .iterator(); iter.hasNext();) { if (iter.next().getTarget().startsWith(PREFIX)) { iter.remove(); } } }
private Optional<Element> findDescendant(Element container, String id) { IteratorIterable<Element> descendants = container.getDescendants(new ElementFilter()); return StreamSupport.stream(descendants.spliterator(), false) .filter(e -> hasOrIncludesID(e, id)).findFirst(); }
/** * Moves all namespace declarations in the children of target to the target. * * @param target the namespace are bundled here */ private void moveNamespacesUp(Element target) { Map<String, Namespace> existingNamespaces = getNamespaceMap(target); Map<String, Namespace> newNamespaces = new HashMap<>(); target.getDescendants(new ElementFilter()).forEach(child -> { Map<String, Namespace> childNamespaces = getNamespaceMap(child); childNamespaces.forEach((prefix, ns) -> { if (existingNamespaces.containsKey(prefix) || newNamespaces.containsKey(prefix)) { return; } newNamespaces.put(prefix, ns); }); }); newNamespaces.forEach((prefix, ns) -> target.addNamespaceDeclaration(ns)); }