Example usage for org.jdom2 Document getDescendants

List of usage examples for org.jdom2 Document getDescendants

Introduction

In this page you can find the example usage for org.jdom2 Document getDescendants.

Prototype

@Override
public IteratorIterable<Content> getDescendants() 

Source Link

Document

Returns an iterator that walks over all descendants in document order.

Usage

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static int computeNewID(Document document) {
    int id = 1;/*from www  .  ja  va  2 s .c  o  m*/
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (id < retrieveID(element)) {
                id = retrieveID(element) + 1;
            }
        }
    }
    return id + 1;
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void convertOldNameToNewNames(String oldName, String newName, Document document) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (element.getName().equals(oldName)) {
                element.setName(newName);
            }/*from  w  ww. j  ava2  s . c o  m*/
        }
    }
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void addProperty(String property, String value, Document document, String elementName) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (elementName == null || elementName.equals(element.getName())) {
                element.setAttribute(property, value);
            }/*from  ww w. j a v a 2s . c om*/
        }
    }
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void removeProperty(String property, Document document, String elementName) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (elementName == null || elementName.equals(element.getName())) {
                element.removeAttribute(property);
            }/*w  w w .  j  a  va2s .c  om*/
        }
    }
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void removeProperties(String property, Document document) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            element.removeAttribute(property);
        }//from w ww .  j a  v  a2 s.c o  m
    }
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void removeNamedElements(Document document, String elementName) {
    ArrayList<Element> parentElements = new ArrayList<Element>();
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (!element.getChildren(elementName).isEmpty()) {
                parentElements.add(element);
            }//w  ww.ja va  2 s  .c  o m
        }
    }
    for (Element parent : parentElements) {
        parent.removeChildren(elementName);
    }
    parentElements = null;
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void changePropertyName(String oldPropertyName, String newPropertyName, Document document,
        String elementName) {//from w w w  .  j  a v  a  2 s  .  com
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (elementName == null || elementName.equals(element.getName())) {
                if (element.getAttribute(oldPropertyName) != null) {
                    element.getAttribute(oldPropertyName).setName(newPropertyName);
                }
            }
        }
    }
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static String retrieveVirtualModelInstanceURI(Document document) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (element.getName().equals("AddressedVirtualModelModelSlot")
                    || element.getName().equals("FMLRTModelSlot")) {
                if (element.getAttribute("name") != null
                        && (element.getAttributeValue("name").equals("this")
                                || element.getAttributeValue("name").equals("virtualModelInstance"))
                        && element.getAttribute("virtualModelURI") != null) {
                    return element.getAttributeValue("virtualModelURI");
                }/*from w w w .  j av a 2  s . c o m*/
            }
        }
    }
    return null;
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static String getFlexoConceptID(Document document, String flexoConceptUri) {
    String virtualModelInstanceUri = retrieveVirtualModelInstanceURI(document);
    if (flexoConceptUri.equals(virtualModelInstanceUri)) {
        return document.getRootElement().getAttributeValue("id");
    }/*from   w w  w. j  a va  2  s . co  m*/
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (element.getName().equals("FlexoConcept") || element.getName().equals("EditionPattern")) {
                if ((virtualModelInstanceUri + "#" + element.getAttributeValue("name"))
                        .equals(flexoConceptUri)) {
                    return element.getAttributeValue("id");
                }
            }
        }
    }
    return null;
}

From source file:org.openflexo.foundation.viewpoint.rm.ViewPointResourceImpl.java

License:Open Source License

private static String retrieveVirtualModelInstanceURI(Document document) {
    for (Content content : document.getDescendants()) {
        if (content instanceof Element) {
            Element element = (Element) content;
            if (element.getName().equals("AddressedVirtualModelModelSlot")
                    || element.getName().equals("VirtualModelModelSlot")) {
                if (element.getAttribute("name") != null
                        && (element.getAttributeValue("name").equals("this")
                                || element.getAttributeValue("name").equals("virtualModelInstance"))
                        && element.getAttribute("virtualModelURI") != null) {
                    return element.getAttributeValue("virtualModelURI");
                }// w  ww  . java 2s.c o m
            }
        }
    }
    return null;
}