Example usage for org.dom4j Element normalize

List of usage examples for org.dom4j Element normalize

Introduction

In this page you can find the example usage for org.dom4j Element normalize.

Prototype

void normalize();

Source Link

Document

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.

Usage

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

License:Open Source License

@SuppressWarnings("unchecked")
private void traverse(Element textElement) {
    boolean flat = ("true".equals(textElement.attributeValue("flat")));
    List<Element> elements = ImmutableList.copyOf((List<Element>) textElement.elements());
    for (Element element : elements) {
        textElement.content().add(textElement.content().indexOf(element),
                DocumentFactory.getInstance().createText("(% " + GaleUtil.serializeXML(element) + " %)"));
        textElement.remove(element);/*  w ww  .  j  a v a2  s.com*/
    }
    textElement.normalize();
    List<Node> content = ImmutableList.copyOf((List<Node>) textElement.content());
    for (Node node : content)
        if (node.getNodeType() == Node.TEXT_NODE) {
            textElement.content().addAll(textElement.content().indexOf(node), parse(node.getText(), flat));
            textElement.content().remove(node);
        }
}

From source file:org.danann.cernunnos.runtime.XmlGrammar.java

License:Apache License

public Task newTask(Element e, Task parent) {

    // Assertions...
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*  w w  w .  ja  va 2  s.  c om*/
    // NB:  parent may be null...

    // Elements that define tasks *must* be normalized...
    e.normalize();

    String name = e.getName();
    Entry n = getEntry(name, Entry.Type.TASK);

    Task rslt = null;
    EntityConfig config = null;
    try {

        // Create & bootstrap the result...
        config = prepareEntryConfig(n, e);
        rslt = (Task) n.getFormula().getImplementationClass().newInstance();
        rslt.init(config);

    } catch (Throwable t) {
        String msg = "Unable to create the specified task:  " + name;
        throw new RuntimeException(msg, t);
    }

    return new RuntimeTaskDecorator(rslt, config);

}

From source file:org.danann.cernunnos.xml.ReadDocumentPhrase.java

License:Apache License

/**
 * Loads a DOM4J document from the specified contact and location and returns the root Element
 *///  ww w.ja v a 2  s.  c o m
protected Element loadDocument(String ctx_str, String loc_str, EntityResolver resolver) {
    try {
        final URL ctx = new URL(ctx_str);
        final URL doc = new URL(ctx, loc_str);

        // Use an EntityResolver if provided...
        final SAXReader rdr = new SAXReader();
        if (resolver != null) {
            rdr.setEntityResolver(resolver);
        }

        // Read by passing a URL -- don't manage the URLConnection yourself...
        final Element rslt = rdr.read(doc).getRootElement();
        rslt.normalize();
        return rslt;

    } catch (Throwable t) {
        String msg = "Unable to read the specified document:" + "\n\tCONTEXT=" + ctx_str + "\n\tLOCATION="
                + loc_str;
        throw new RuntimeException(msg, t);
    }
}