Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:net.unicon.academus.apps.permissions.PortletAccessHelper.java

License:Open Source License

public PortletAccessHelper(Element e) {
    Attribute handle = e.attribute("handle");
    if (handle == null)
        throw new IllegalArgumentException("Element <portlet-access> must have a 'handle' attribute");
    this.handle = handle.getValue();

    // parse the broker
    Element e2 = (Element) e.selectSingleNode("access-broker");
    if (e2 == null) {
        throw new IllegalArgumentException("Element <portlet-access> must contain an <access-broker> element.");
    }//from   w w  w  .  j av  a 2  s  .c o m

    this.broker = AccessBroker.parse(e2);

    // get the accessType Enumeration class
    e2 = (Element) e.selectSingleNode("access");
    Attribute impl = e2.attribute("impl");
    if (impl == null) {
        throw new IllegalArgumentException("The element <access> must contain an 'impl' attribute.");
    }

    Class c;
    try {
        c = Class.forName(impl.getValue());

        Method m = c.getMethod("getInstances", null);

        // parse the accessTypes
        /*List access = e.selectNodes("access/accesstype");
        if (access.isEmpty()) {
            throw new IllegalArgumentException(
               "Element <access> must contain at least one <accesstype> element.");
        }
        accessTypes = new AccessType[access.size()];
        String accessId = null;
        for(int i = 0; i < access.size(); i++){
            accessId =  ((Element)access.get(i)).getText();
            accessTypes[i] = (AccessType)m.invoke(null, new Object[] {accessId});
         } */
        accessTypes = (AccessType[]) m.invoke(null, null);
    } catch (ClassNotFoundException e1) {
        throw new RuntimeException("Could not find the class " + impl.getValue(), e1);
    } catch (NoSuchMethodException e3) {
        throw new RuntimeException("Could not find the Method 'getAccessType' on class " + impl.getValue(), e3);
    } catch (IllegalArgumentException e3) {
        throw new RuntimeException(
                "Incorrect arguments passed in the Method 'getAccessType' on class " + impl.getValue(), e3);
    } catch (Exception e4) {
        throw new RuntimeException("Error in invoking the method 'getAccessType' on class " + impl.getValue(),
                e4);
    }
}

From source file:net.unicon.academus.apps.permissions.PortletHelper.java

License:Open Source License

public PortletHelper(Element e) {
    Attribute attrId = e.attribute("handle");
    if (attrId == null)
        throw new IllegalArgumentException("Element <portlet> must have a 'handle' attribute");
    this.handle = attrId.getValue();

    Element e2 = (Element) e.selectSingleNode("label");
    if (e2 == null) {
        throw new IllegalArgumentException("Element <portlet> must contain a <label> element.");
    } else {//w w w .j  a v a 2 s.c o  m
        this.label = e2.getText();
    }

    e2 = (Element) e.selectSingleNode("description");
    if (e2 == null) {
        throw new IllegalArgumentException("Element <portlet> must contain a <description> element.");
    } else {
        this.description = e2.getText();
    }

    List access = e.selectNodes("portlet-access");
    if (access.isEmpty()) {
        throw new IllegalArgumentException(
                "Element <portlet> must contain at least one <portal-access> element.");
    }

    Attribute handle = null;
    this.accessHelpers = new HashMap();

    for (int i = 0; i < access.size(); i++) {
        handle = ((Element) access.get(i)).attribute("handle");
        if (handle == null) {
            throw new IllegalArgumentException("Element <portlet-access> must have a 'handle' attribute.");
        }
        this.accessHelpers.put(handle.getValue(), new PortletAccessHelper(((Element) access.get(i))));
    }

}

From source file:net.unicon.academus.apps.SsoAuthentication.java

License:Open Source License

public static SsoAuthentication parse(Element e) {

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

    SsoAuthentication rslt = null;
    try {

        Class implClass = null; // no default for authentication...
        Attribute impl = e.attribute("impl"); // check this attribute first (new pattern)...
        if (impl == null) {
            // Check the 'old' pattern -- 'handler' attribute...
            impl = e.attribute("handler"); // check this attribute first (new pattern)...
        }
        if (impl != null) {
            implClass = Class.forName(impl.getValue());
        } else {
            // This is a prblem...
            String msg = "Element <authentication> is missing required attribute 'impl'.";
            throw new IllegalArgumentException(msg);
        }

        Method m = implClass.getDeclaredMethod("parse", new Class[] { Element.class });
        rslt = (SsoAuthentication) m.invoke(null, new Object[] { e });

    } catch (Throwable t) {
        String msg = "Unable to create the requested SsoAuthentication instance.";
        throw new RuntimeException(msg, t);
    }

    return rslt;

}

From source file:net.unicon.academus.apps.SsoEntrySimple.java

License:Open Source License

public static SsoEntry parse(Element e) {

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

    // Handle.
    Attribute h = e.attribute("handle");
    if (h == null) {
        String msg = "Element <sso-entry> is missing required attribute 'handle'.";
        throw new IllegalArgumentException(msg);
    }
    String handle = h.getValue();

    // Label.
    Element b = (Element) e.selectSingleNode("label");
    if (b == null) {
        String msg = "Element <sso-entry> is missing required child element <label>.";
        throw new IllegalArgumentException(msg);
    }
    String label = b.getText();

    // Description.
    Element d = (Element) e.selectSingleNode("description");
    if (d == null) {
        String msg = "Element <sso-entry> is missing required child element <description>.";
        throw new IllegalArgumentException(msg);
    }
    String description = d.getText();

    // Window.
    Element w = (Element) e.selectSingleNode("window");
    if (w == null) {
        String msg = "Element <sso-entry> is missing required child element <window>.";
        throw new IllegalArgumentException(msg);
    }
    String window = w.asXML();

    // UIClass.
    Attribute c = e.attribute("class");
    if (c == null) {
        String msg = "Element <target> is missing required attribute 'class'.";
        throw new IllegalArgumentException(msg);
    }
    String uiClass = c.getValue();

    // Authentication.
    Element a = (Element) e.selectSingleNode("authentication");
    SsoAuthentication authentication = null;
    if (a != null) {
        authentication = SsoAuthentication.parse(a);
    }

    // map of all targets
    Map targets = new HashMap();
    for (Iterator it = e.selectNodes("target").iterator(); it.hasNext();) {
        SsoTarget r = SsoTarget.parse((Element) it.next());
        targets.put(r.getHandle(), r);
    }

    // Sequences
    Map sequences = new HashMap();
    for (Iterator it = e.selectNodes("sequence").iterator(); it.hasNext();) {
        Element s = (Element) it.next();
        SsoSequence seq = SsoSequence.parse(s);
        sequences.put(seq.getType(), seq);
    }

    return new SsoEntrySimple(handle, label, description, window, uiClass, authentication, targets, sequences);

}

From source file:net.unicon.academus.apps.SsoSequenceLegacy.java

License:Open Source License

public static SsoSequence parse(Element e) {

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

    // Type.
    Attribute y = e.attribute("type");
    if (y == null) {
        String msg = "Element <sequence> is missing required attribute 'type'.";
        throw new IllegalArgumentException(msg);
    }
    String type = y.getValue();

    // ButtonXml.
    String buttonXml = "";
    Element b = (Element) e.selectSingleNode("sequence-start-trigger");
    if (b != null) {
        buttonXml = b.asXML();
    }

    // TargetIds.
    List list = e.selectNodes("target");
    String[] targetIds = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {

        Element r = (Element) list.get(i);

        Attribute h = r.attribute("handle");
        if (h == null) {
            String msg = "Element <target> is missing required attribute 'handle'.";
            throw new IllegalArgumentException(msg);
        }

        targetIds[i] = h.getValue();

    }

    return new SsoSequenceLegacy(type, targetIds, buttonXml);

}

From source file:net.unicon.academus.apps.SsoTargetSimple.java

License:Open Source License

public static SsoTarget parse(Element e) {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from ww  w .  jav  a2s . c o m
    if (!e.getName().equals("target")) {
        String msg = "Argument 'e [Element]' must be a <target> element.";
        throw new IllegalArgumentException(msg);
    }

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

    // Method.
    Element m = (Element) e.selectSingleNode("method");
    if (m == null) {
        String msg = "Element <target> is missing required child element <method>.";
        throw new IllegalArgumentException(msg);
    }
    String method = m.getText();

    // Url.
    Element u = (Element) e.selectSingleNode("url");
    if (u == null) {
        String msg = "Element <target> is missing required child element <url>.";
        throw new IllegalArgumentException(msg);
    }
    String url = u.getText();

    // Parameters & Evaluators.
    Map params = new HashMap();
    Map evaluators = new HashMap();
    for (Iterator it = e.selectNodes("parameter").iterator(); it.hasNext();) {
        Element p = (Element) it.next();
        String key = p.attribute("name").getValue();
        String val = null;
        if (p.element("evaluate") != null) {
            try {
                String evauluatorImpl = p.element("evaluate").attributeValue("evauluatorImpl");
                //map evaluator to parameter key
                evaluators.put(key, evauluatorImpl);
                //get parameter value
                val = p.selectSingleNode("evaluate").getStringValue();
            } catch (Exception ex) {
                throw new RuntimeException("Problem instantiating IAttributeEvaluator for "
                        + p.selectSingleNode("evaluate").getStringValue(), ex);
            }
        } else {
            val = p.selectSingleNode("value").getText();
        }
        params.put(key, val);
    }

    // Evaluators.

    return new SsoTargetSimple(handle, method, url, params, evaluators);

}

From source file:net.unicon.academus.civisselector.AddToSelBasketAction.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  ww.  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());

    // ToScreen.
    Attribute s = e.attribute("to-screen");
    if (s == null) {
        String msg = "Element <action> is missing required attribute " + "'to-screen'.";
        throw new XmlFormatException(msg);
    }
    String toScreen = s.getValue();

    // Choices.
    String[] choices = new String[0];
    Attribute p = e.attribute("inpt");
    if (p != null) {
        StringTokenizer tokens = new StringTokenizer(p.getValue(), ",");
        choices = new String[tokens.countTokens()];
        for (int i = 0; tokens.hasMoreTokens(); i++) {
            choices[i] = tokens.nextToken();
        }
    }

    return new AddToSelBasketAction(owner, handle, choices, toScreen);

}

From source file:net.unicon.academus.civisselector.CancelBasketAction.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  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) {
        StringTokenizer tokens = new StringTokenizer(p.getValue(), ",");
        choices = new String[tokens.countTokens()];
        for (int i = 0; tokens.hasMoreTokens(); i++) {
            choices[i] = tokens.nextToken();
        }
    }

    return new CancelBasketAction(owner, handle, choices);

}

From source file:net.unicon.academus.civisselector.CloseSearchResults.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 ww .  j a  v  a2s.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) {
        StringTokenizer tokens = new StringTokenizer(p.getValue(), ",");
        choices = new String[tokens.countTokens()];
        for (int i = 0; tokens.hasMoreTokens(); i++) {
            choices[i] = tokens.nextToken();
        }
    }

    return new CloseSearchResults(owner, handle, choices);

}

From source file:net.unicon.academus.civisselector.CloseSelBasketAction.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  ww  .  j  av 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) {
        StringTokenizer tokens = new StringTokenizer(p.getValue(), ",");
        choices = new String[tokens.countTokens()];
        for (int i = 0; tokens.hasMoreTokens(); i++) {
            choices[i] = tokens.nextToken();
        }
    }

    return new CloseSelBasketAction(owner, handle, choices);

}