Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.buddycloud.friendfinder.HttpUtils.java

License:Apache License

public static Element consumeXML(String URL) throws Exception {
    SAXReader reader = new SAXReader();
    Document document = reader.read(new java.net.URL(URL));
    return document.getRootElement();
}

From source file:com.chingo247.structureapi.plan.document.AbstractDocumentManager.java

protected boolean isStructurePlan(Document d) {
    return d.getRootElement().getName().equals(Elements.ROOT);
}

From source file:com.chingo247.structureapi.plan.document.PlanDocumentManager.java

License:Open Source License

/**
 * Loads all planDocuments & structureDocuments Multi-Core. Number of cores used is defined by
 * the number of cores available using Runtime.getRuntime.availableProcessors()
 *///from   w  w  w  .  j  a  v a 2  s. c  o m
@Override
public synchronized void loadDocuments() {

    // Go throug all XML files inside the 'Plans' folder
    Iterator<File> it = FileUtils.iterateFiles(structureAPI.getPlanDataFolder(), new String[] { "xml" }, true);
    final List<Future> tasks = new LinkedList<>();
    while (it.hasNext()) {
        final File planDocFile = it.next();
        tasks.add(executor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    SAXReader reader = new SAXReader();
                    Document d = reader.read(planDocFile);
                    // If the RootElement is not 'StructurePlan', skip it
                    if (!isStructurePlan(d)) {
                        return;
                    }
                    List<Element> elements = d.getRootElement().elements();

                    // Form plan document
                    PlanDocument planDocument = new PlanDocument(PlanDocumentManager.this, planDocFile);
                    for (Element pluginElement : elements) {
                        planDocument.putPluginElement(pluginElement.getName(), new PlanDocumentPluginElement(
                                pluginElement.getName(), planDocument, pluginElement));
                    }
                    // Save the document
                    PlanDocumentManager.this.put(planDocument.getRelativePath(), planDocument);
                } catch (DocumentException ex) {
                    Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }));
    }

    // Block until all tasks are done
    for (Future f : tasks) {
        try {
            f.get();
        } catch (InterruptedException | ExecutionException ex) {
            Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex);
            for (Future fu : tasks) {
                fu.cancel(true);
            }
        }
    }
}

From source file:com.chingo247.structureapi.plan.document.StructureDocumentManager.java

/**
 * Loads all structureDocuments multi-threaded. Number of cores used is defined by
 * the number of cores available using Runtime.getRuntime.availableProcessors()
 *///from ww w.ja  v a 2s  .  com
@Override
public synchronized void loadDocuments() {
    Session session = HibernateUtil.getSession();
    JPQLQuery query = new HibernateQuery(session);
    QStructure qs = QStructure.structure;
    List<Structure> structures = query.from(qs).where(qs.state.ne(Structure.State.REMOVED)).list(qs);
    session.close();

    final List<Future> tasks = new LinkedList<>();

    for (final Structure structure : structures) {
        final File structureDocFile = structureAPI.getStructurePlanFile(structure);
        tasks.add(executor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    SAXReader reader = new SAXReader();
                    Document d = reader.read(structureDocFile);
                    // If the RootElement is not 'StructurePlan', skip it
                    if (!isStructurePlan(d)) {
                        return;
                    }
                    List<Element> elements = d.getRootElement().elements();

                    // Form plan document
                    StructureDocument structureDocument = new StructureDocument(StructureDocumentManager.this,
                            structure, structureDocFile);
                    for (Element pluginElement : elements) {
                        structureDocument.putPluginElement(pluginElement.getName(),
                                new StructureDocumentPluginElement(pluginElement.getName(), structureDocument,
                                        pluginElement));
                    }
                    // Save the document
                    put(structure.getId(), structureDocument);
                } catch (DocumentException ex) {
                    Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }));
    }

    // Block until all tasks are done
    for (Future f : tasks) {
        try {
            f.get();
        } catch (InterruptedException | ExecutionException ex) {
            Logger.getLogger(PlanDocumentManager.class.getName()).log(Level.SEVERE, null, ex);
            for (Future fu : tasks) {
                fu.cancel(true);
            }
        }
    }

}

From source file:com.chingo247.structureapi.plan.io.document.StructurePlanDocument.java

License:Open Source License

StructurePlanDocument(File f, Document d) {
    super(f, d.getRootElement());
    Preconditions.checkNotNull(f);//  ww w  .  j  a  v a2  s  .co  m
    Preconditions.checkNotNull(d);

    this.file = f;
    this.doc = d;
}

From source file:com.chingo247.structureapi.plan.StructurePlanManager.java

License:Open Source License

private boolean isStructurePlan(File file) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document d = reader.read(file);
    return d.getRootElement().getName().equals("StructurePlan");
}

From source file:com.chingo247.structureapi.plan.util.PlanDocumentUtil.java

License:Open Source License

public static boolean isStructurePlan(Document d) {
    return d.getRootElement().getName().equals(ROOT_ELEMENT);
}

From source file:com.church.gateway.Global.java

/**
 * Parses the theme xml.//from  www .  j  a va2s.c om
 * 
 * @param xml
 *            the xml
 */
private static void parseThemeXML(String xml) {
    try {
        Document doc = DocumentHelper.parseText(xml);
        Element elmt = doc.getRootElement();
        List l = elmt.selectNodes("/themes/theme");
        Element e = null;
        theme_class = new String[l.size()];
        for (int i = 0; i < l.size(); i++) {
            e = (Element) l.get(i);
            theme_class[i] = e.attribute("class").getValue();
        }
    } catch (DocumentException e) {
        System.out.println(e);
    }
}

From source file:com.church.gateway.Global.java

/**
 * Gets the modified menu xml.//from w  w w.j a  v  a  2s.  c  om
 * 
 * @param disallowed_modules
 *            the disallowed_modules
 * 
 * @return the modified menu xml
 * 
 * @throws Exception
 *             the exception
 */
public static String getModifiedMenuXml(String[] disallowed_modules) throws Exception {
    Document doc = DocumentHelper.parseText(Global.MENUS);
    Element root = doc.getRootElement();
    List<Node> list = root.selectNodes("//menu/menu");
    for (Node node : list) {
        Element elmt = (Element) node;
        if (elmt.attribute("class") != null) {
            for (String module : disallowed_modules)
                if (elmt.attribute("class").getValue().trim().equals(module))
                    elmt.addAttribute("visible", "false");
        }
    }
    return doc.asXML();
}

From source file:com.church.gateway.Global.java

/**
 * Load transition effects./*  w ww  .  ja va  2  s  . c  om*/
 */
private static void loadTransitionEffects() {
    ArrayList<String> display = new ArrayList<String>();
    ArrayList<String> classname = new ArrayList<String>();

    try {
        byte[] xmlbytes = Network.getLocalFile("transitions.xml");
        Document doc = DocumentHelper.parseText(new String(xmlbytes));
        Element root = doc.getRootElement();
        List<Node> nodes = root.selectNodes("transition");
        transitionParameters = new HashMap<String, Object[]>();
        for (Node n : nodes) {
            Element elmt = (Element) n;
            display.add(elmt.selectSingleNode("display").getText());
            classname.add(elmt.selectSingleNode("class").getText());
            List<Node> ps = elmt.selectNodes("parameter");
            if (ps != null) {
                Object[] arr = new Object[ps.size()];
                for (int i = 0; i < ps.size(); i++) {
                    Element ep = (Element) ps.get(i);
                    arr[i] = ep.getTextTrim();
                }
                transitionParameters.put(elmt.selectSingleNode("display").getText(), arr);
            } else
                transitionParameters.put(elmt.selectSingleNode("display").getText(), new Object[] {});
        }
    } catch (DocumentException e) {
        Logger.getLogger(Global.class).error(e, e);
    }
    supportedTransitionClasses = new String[classname.size()];
    supportedTransitions = new String[display.size()];
    for (int i = 0; i < classname.size(); i++) {
        supportedTransitionClasses[i] = classname.get(i) + ":" + display.get(i);
        supportedTransitions[i] = display.get(i);
    }
}