Example usage for org.dom4j DocumentFactory getInstance

List of usage examples for org.dom4j DocumentFactory getInstance

Introduction

In this page you can find the example usage for org.dom4j DocumentFactory getInstance.

Prototype

public static synchronized DocumentFactory getInstance() 

Source Link

Document

Access to singleton implementation of DocumentFactory which is used if no DocumentFactory is specified when building using the standard builders.

Usage

From source file:nl.tue.gale.ae.processor.xmlmodule.VariableModule.java

License:Open Source License

public Element traverse(Element element, Resource resource) throws ProcessorException {
    GaleContext gale = GaleContext.of(resource);
    if (element.attributeValue("name") != null) {
        String name = element.attributeValue("name");
        String text = null;//from ww w  . j av a  2s . c  o  m
        CacheSession<EntityValue> session = gale.openUmSession();
        URI uri = session.resolve(name);
        text = gale.um().get(uri).getValueString();
        GaleUtil.replaceNode(element, DocumentFactory.getInstance().createText(text));
    } else if (element.attribute("expr") != null) {
        String expr = element.attributeValue("expr");
        GaleUtil.replaceNode(element, DocumentFactory.getInstance().createText(gale.eval(expr).toString()));
    }
    return null;
}

From source file:nl.tue.gale.ae.processor.XMLProcessor.java

License:Open Source License

public void traverse(Element element, Resource resource) throws ProcessorException {
    if (element == null)
        return;/*www . j  a v  a  2s  . co  m*/
    Namespace ns = element.getNamespace();
    String tag = null;
    if (ns != Namespace.NO_NAMESPACE) {
        tag = "{" + ns.getURI() + "}" + element.getName();
        if (!moduleTable.containsKey(tag))
            tag = null;
    }
    if (tag == null)
        tag = element.getName();
    if (moduleTable.containsKey(tag)) {
        Module mod = moduleTable.get(tag);
        if (mod.getMimeToHandle().contains(GaleContext.mime(resource))) {
            try {
                element = moduleTable.get(tag).traverse(element, resource);
            } catch (Exception e) {
                e.printStackTrace();
                element = (Element) GaleUtil.replaceNode(element,
                        GaleUtil.createErrorElement("[" + e.getMessage() + "]"));
            }
        }
    }
    traverseChildren(element, resource);
    if ("text/xhtml".equals(GaleContext.mime(resource)))
        if (element != null)
            if ("http://www.w3.org/1999/xhtml".equals(element.getNamespaceURI()))
                element.setQName(DocumentFactory.getInstance().createQName(element.getName(), "",
                        "http://www.w3.org/1999/xhtml"));
}

From source file:nl.tue.gale.common.GaleUtil.java

License:Open Source License

public static Element createNSElement(String name, String ns) {
    return DocumentFactory.getInstance().createElement(DocumentFactory.getInstance().createQName(name, "", ns));
}

From source file:nl.tue.gale.common.GaleUtil.java

License:Open Source License

/**
 * Generates an html span element with the specified error text. The element
 * will have its 'class' attribute set to 'error'.
 * //from  w  w w. java2s.c o  m
 * @param text
 *            the text to use in the generated element
 * @param doc
 *            the <code>Document</code> that the generated element will be a
 *            part of
 * @return the generated span <code>org.w3c.dom.Element</code>
 */
public static Element createErrorElement(String text) {
    Element result = DocumentFactory.getInstance().createElement(
            DocumentFactory.getInstance().createQName("span", "", "http://www.w3.org/1999/xhtml"));
    result.addText(text);
    result.addAttribute("style", "color:#D02020");
    return result;
}

From source file:nl.tue.gale.conversion.aha3.CLConvert.java

License:Open Source License

private void convertTest(Element element) {
    if ("gale".equals(element.getQName().getNamespacePrefix()))
        return;//from  w w w.  j  a v a 2  s. com
    element.setQName(DocumentFactory.getInstance().createQName(element.getName(), "gale",
            "http://gale.tue.nl/adaptation"));
    if (element.getName().equals("test"))
        element.addAttribute("expr", convertExpr(element.attributeValue("expr")));
}

From source file:nl.tue.gale.conversion.aha3.CLConvert.java

License:Open Source License

private void convertA(Element element) {
    if ("conditional".equals(element.attributeValue("class"))) {
        element.addAttribute("class", null);
        element.setQName(// w  w  w  .java  2s. c  om
                DocumentFactory.getInstance().createQName("a", "gale", "http://gale.tue.nl/adaptation"));
    }
}

From source file:nl.tue.gale.conversion.aha3.CLConvert.java

License:Open Source License

@SuppressWarnings("unchecked")
private void convertIf(Element element) {
    if ("gale".equals(element.getQName().getNamespacePrefix()))
        return;/*from   ww  w .jav  a 2s  .c  o  m*/
    element.setQName(DocumentFactory.getInstance().createQName("if", "gale", "http://gale.tue.nl/adaptation"));
    String expr = convertExpr(element.attributeValue("expr"));
    element.addAttribute("expr", expr);
    List<Element> blocks = element.elements("block");
    if (blocks.size() > 0) {
        blocks.get(0).setQName(
                DocumentFactory.getInstance().createQName("then", "gale", "http://gale.tue.nl/adaptation"));
    }
    if (blocks.size() > 1) {
        blocks.get(1).setQName(
                DocumentFactory.getInstance().createQName("else", "gale", "http://gale.tue.nl/adaptation"));
    }
}

From source file:nl.tue.gale.conversion.aha3.CLConvert.java

License:Open Source License

private void convertObject(Element element) {
    if ("text/aha".equals(element.attributeValue("type"))) {
        if (element.attributeValue("name") == null) {
            element.addAttribute("type", null);
            element.setQName(DocumentFactory.getInstance().createQName("object", "gale",
                    "http://gale.tue.nl/adaptation"));
        } else {// www  . ja  v a2s. c  om
            System.out.println("-- found name object: " + element.attributeValue("name"));
            element.addAttribute("type", null);
            element.setQName(DocumentFactory.getInstance().createQName("object", "gale",
                    "http://gale.tue.nl/adaptation"));
            String name = element.attributeValue("name");
            if (name.indexOf(".") >= 0)
                name = name.substring(name.lastIndexOf(".") + 1);
            element.addAttribute("name", name);
        }
    }
}

From source file:nl.tue.gale.dm.GDOMFormat.java

License:Open Source License

public static Element toXML(List<Concept> concepts) {
    DocumentFactory df = DocumentFactory.getInstance();
    Element gdom = df.createElement("gdom", GaleUtil.gdomns);
    Set<URI> uriSet = new HashSet<URI>();
    Set<ConceptRelation> relationSet = new HashSet<ConceptRelation>();
    for (Concept concept : concepts) {
        gdom.add(toXML(concept, df));/*from   w  ww.j av  a2  s  .  c  o m*/
        uriSet.add(concept.getUri());
        for (ConceptRelation cr : concept.getInCR())
            relationSet.add(cr);
        for (ConceptRelation cr : concept.getOutCR())
            relationSet.add(cr);
    }
    for (ConceptRelation cr : relationSet) {
        if (uriSet.contains(cr.getInConcept().getUri()) && uriSet.contains(cr.getOutConcept().getUri()))
            gdom.add(toXML(cr, df));
    }
    return gdom;
}

From source file:nnga.NNGA.java

License:Open Source License

/**
 * Saves all population data to a new XML element and returns it.
 * @param generation number of current generation
 * @return information about population in XML format  
 *//*w  w w. j  a va2s .  c  o  m*/
public Element saveResults(int generation) {
    Element dpopulations = DocumentFactory.getInstance().createElement("populations");

    dpopulations.addAttribute("count", String.valueOf(parameters.getPopulationNumber()));
    dpopulations.addAttribute("generation", String.valueOf(generation));
    dpopulations.addAttribute("randomseed", String.valueOf(this.getSeed()));

    for (SimplePopulation pop : pops) {
        pop.exportXml(dpopulations);
    }

    return dpopulations;
}