Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:net.unicon.academus.apps.gateway.engine.UpdateCredentialsAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//  w  w w.  ja v a 2  s .  c  om
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    return new UpdateCredentialsAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.messaging.BatchImporter.java

License:Open Source License

public static MessageCenter configure(String configFile, String mcenter) throws Exception {
    Element configElement = (Element) (new SAXReader()).read(configFile).selectSingleNode("messaging");

    configElement = ConfigHelper.handle(configElement, false);

    // Bootstrap datasources with SimpleDataSource...
    List bsList = configElement.selectNodes("//*[@needsDataSource='true']");
    if (!bsList.isEmpty()) {
        try {/*from  w  w w  .jav a2  s  . co m*/
            DataSource ds = new SimpleDataSource();

            for (Iterator it = bsList.iterator(); it.hasNext();) {
                Element e = (Element) it.next();

                Attribute impl = e.attribute("impl");
                if (impl == null)
                    throw new IllegalArgumentException("Elements with the 'needsDataSource' attribute "
                            + " must have an 'impl' attribute.");

                Class.forName(impl.getValue()).getDeclaredMethod("bootstrap", new Class[] { DataSource.class })
                        .invoke(null, new Object[] { ds });
            }
        } catch (Throwable e) {
            e.printStackTrace(System.err);
            error("Failed the DataSource bootstrapping. Please correct any errors.");
        }
    }

    // Handle any global configuration for the message factories.
    List mList = configElement.selectNodes("message-factory");
    for (Iterator mIt = mList.iterator(); mIt.hasNext();) {
        Element e = (Element) mIt.next();
        Attribute impl = e.attribute("impl");
        if (impl == null)
            throw new IllegalArgumentException("Element <message-factory> must have an 'impl'" + " attribute.");
        try {
            Class.forName(impl.getValue()).getDeclaredMethod("parse", new Class[] { Element.class })
                    .invoke(null, new Object[] { e });
        } catch (Throwable t) {
            throw new RuntimeException("Failed to parse the <message-factory> element.", t);
        }
    }

    Element e = (Element) configElement.selectSingleNode("message-center[@id='" + mcenter + "']");

    return new MessageCenter(e);
}

From source file:net.unicon.academus.apps.messaging.engine.ChangeMessagePageAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from   w w  w .j a  va2  s . c o  m
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner+' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    // Move.
    Attribute m = e.attribute("move");
    if (m == null) {
        String msg = "Element <action> is missing required attribute " + "'mode'.";
        throw new XmlFormatException(msg);
    }
    PageChange change = PageChange.getInstance(m.getValue());

    return new ChangeMessagePageAction(owner, handle, choices, change);

}

From source file:net.unicon.academus.apps.messaging.engine.ChangeMessageSortAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }// w  w w .j  a v  a2 s  . c o m
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner+' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    // Mode.
    Attribute m = e.attribute("mode");
    if (m == null) {
        String msg = "Element <action> is missing required attribute " + "'mode'.";
        throw new XmlFormatException(msg);
    }
    String mode = m.getValue();

    return new ChangeMessageSortAction(owner, handle, choices, mode);

}

From source file:net.unicon.academus.apps.messaging.engine.ChangeRecipientSortAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from w  w  w.j a  v a  2  s  .c o m
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner+' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    // Mode.
    Attribute m = e.attribute("mode");
    if (m == null) {
        String msg = "Element <action> is missing required attribute " + "'mode'.";
        throw new XmlFormatException(msg);
    }
    String mode = m.getValue();

    return new ChangeRecipientSortAction(owner, handle, choices, mode);

}

From source file:net.unicon.academus.apps.messaging.engine.ChangeReportPageAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from   w  w w.  ja  v  a 2s  .c o  m
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner+' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    // Move.
    Attribute m = e.attribute("move");
    if (m == null) {
        String msg = "Element <action> is missing required attribute " + "'mode'.";
        throw new XmlFormatException(msg);
    }
    PageChange change = PageChange.getInstance(m.getValue());

    return new ChangeReportPageAction(owner, handle, choices, change);

}

From source file:net.unicon.academus.apps.messaging.engine.ComposeMessageAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from   w  w  w.  j  a  v a  2s  .c o m*/
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    // Mode (Edit or Preview).
    String mode = "edit";
    p = e.attribute("mode");
    if (p != null) {
        mode = p.getValue().toLowerCase();
    }

    return new ComposeMessageAction(owner, handle, choices, mode);

}

From source file:net.unicon.academus.apps.messaging.engine.ComposeNavigateAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/* w  w  w  . j a  v a2 s .c o  m*/
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p == null)
        throw new XmlFormatException("ComposeNavigateAction requires attribute 'inpt'.");
    choices = p.getValue().split(",");

    p = e.attribute("to-screen");
    if (p == null)
        throw new XmlFormatException("ComposeNavigateAction requires attribute 'to-screen'.");
    String nextScreen = p.getValue().toLowerCase();

    return new ComposeNavigateAction(owner, handle, choices, nextScreen);

}

From source file:net.unicon.academus.apps.messaging.engine.ComposeNavigateSelectorAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from w w w .j a  v a 2s.  c o  m
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p == null)
        throw new XmlFormatException("ComposeNavigateAction requires attribute 'inpt'.");
    choices = p.getValue().split(",");

    p = e.attribute("to-screen");
    if (p == null)
        throw new XmlFormatException("ComposeNavigateAction requires attribute 'to-screen'.");
    String nextScreen = p.getValue().toLowerCase();

    return new ComposeNavigateSelectorAction(owner, handle, choices, nextScreen);

}

From source file:net.unicon.academus.apps.messaging.engine.ConfirmDeleteAction.java

License:Open Source License

public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }/*from   www.ja va2 s  . co  m*/
    if (!e.getName().equals("action")) {
        String msg = "Argument 'e [Element]' must be an <action> element.";
        throw new IllegalArgumentException(msg);
    }
    if (owner == null) {
        String msg = "Argument 'owner' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <action> is missing required attribute " + "'handle'.";
        throw new XmlFormatException(msg);
    }
    Handle handle = Handle.create(h.getValue());

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        choices = p.getValue().split(",");
    }

    return new ConfirmDeleteAction(owner, handle, choices);

}