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.permissions.engine.ChangePermissionsSortAction.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.  java 2  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 ChangePermissionsSortAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.permissions.engine.ChangeViewFilterAction.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 ww.j  a v a2s.com*/
    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 ChangeViewFilterAction(owner, handle, choices);
}

From source file:net.unicon.academus.apps.permissions.engine.GoToPortletAction.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  a2s  .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(",");
    }

    return new GoToPortletAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.permissions.engine.RemoveEntriesAction.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 ww.j  a v  a2  s .com*/
    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 RemoveEntriesAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.permissions.engine.SaveChangesAction.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  a2  s.  com*/
    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 SaveChangesAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.permissions.engine.SetPermissionsItemsPerPageAction.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);
    }/*ww  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(",");
    }

    return new SetPermissionsItemsPerPageAction(owner, handle, choices);

}

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

License:Open Source License

public void init(PortletConfig config) {

    // Instance Id.
    id = config.getInitParameter("Id");
    session_key = id + ":CONTEXT";

    // Initialize.
    StateMachine m = null;//w w  w .java  2s.c  om
    try {

        PortletContext ctx = config.getPortletContext();

        // Parse the config file.
        String configPath = (String) config.getInitParameter("configPath");
        SAXReader reader = new SAXReader();
        URL configUrl = ctx.getResource(configPath);
        Element configElement = (Element) reader.read(configUrl.toString()).selectSingleNode("permissions");

        boolean useXsltc = Boolean.valueOf(configElement.attributeValue("useXsltc"));

        boolean cacheTemplates = true;

        if (configElement.attributeValue("cacheTemplates") != null) {
            cacheTemplates = Boolean.valueOf(configElement.attributeValue("cacheTemplates"));
        }

        configElement = ConfigHelper.handle(configElement);

        // read the portlet specified
        Map portletMap = new HashMap();

        List pList = configElement.selectNodes("portlet");
        if (!pList.isEmpty()) {
            try {
                Element e = null;
                Element eLabel = null;
                Element eDesc = null;
                Element eAccess = null;

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

                    Attribute portletHandle = e.attribute("handle");
                    if (portletHandle == null)
                        throw new IllegalArgumentException(
                                "The <portlet> Element" + " must have a 'handle' attribute.");

                    portletMap.put(portletHandle.getValue(), new PortletHelper(e));
                }
            } catch (Throwable e) {
                throw new RuntimeException("Failed the Portlet reading.", e);
            }
        }

        List civisFactories = new ArrayList();
        ICivisFactory cFac = null;
        Map groupRestrictors = new HashMap();
        Element el = (Element) configElement.selectSingleNode("civis[@id='addressBook']");
        if (el != null) {
            Attribute impl = el.attribute("impl");
            if (impl == null)
                throw new IllegalArgumentException("Element <civis> must have an 'impl'" + " attribute.");
            try {
                cFac = (ICivisFactory) Class.forName(impl.getValue())
                        .getDeclaredMethod("parse", new Class[] { Element.class })
                        .invoke(null, new Object[] { el });

                civisFactories.add(cFac);
            } catch (Throwable t) {
                throw new RuntimeException("Failed to parse the <civis> element.", t);
            }

            // parse for the group restrictor

            Element gAttr = (Element) el.selectSingleNode("restrictor");
            if (gAttr != null) {
                Attribute a = gAttr.attribute("impl");
                IGroupRestrictor restrictor = (IGroupRestrictor) Class.forName(a.getValue()).newInstance();

                groupRestrictors.put(cFac.getUrl(), restrictor);

            } else {
                throw new IllegalArgumentException("Element <civis> must have an 'restrictor'" + " element.");
            }

        }

        // Construct the application context.
        context = new PermissionsApplicationContext(id, portletMap,
                (ICivisFactory[]) (civisFactories.toArray(new ICivisFactory[0])), groupRestrictors);

        // Construct the rendering engine;
        URL xslUrl = ctx.getResource("/rendering/templates/layout.xsl");
        Source trans = new StreamSource(xslUrl.toString());
        IWarlockFactory fac = null;

        if (useXsltc) {
            fac = new XmlWarlockFactory(trans, TransletsConstants.xsltcTransformerFactoryImplementation,
                    TransletsConstants.xsltcDebug, TransletsConstants.xsltcPackage,
                    TransletsConstants.xsltcGenerateTranslet, TransletsConstants.xsltcAutoTranslet,
                    TransletsConstants.xsltcUseClasspath, cacheTemplates);
        } else {
            fac = new XmlWarlockFactory(trans, cacheTemplates);
        }

        // Construct the screens;
        List screenList = new ArrayList();
        List libList = new ArrayList();
        Iterator it = ctx.getResourcePaths("/rendering/screens/permissions/").iterator();
        while (it.hasNext()) {
            String path = (String) it.next();
            URL screenUrl = ctx.getResource(path);
            Element e = (Element) reader.read(screenUrl.toString()).getRootElement();
            if (e.getName().equals("screen")) {
                screenList.add(e);
            } else if (e.getName().equals("library")) {
                libList.add(e);
            }
        }

        // construct the selector screens
        it = ctx.getResourcePaths("/rendering/screens/selector/").iterator();
        while (it.hasNext()) {
            String path = (String) it.next();
            URL screenUrl = ctx.getResource(path);
            Element e = (Element) reader.read(screenUrl.toString()).getRootElement();
            if (e.getName().equals("screen")) {
                screenList.add(e);
            } else if (e.getName().equals("library")) {
                libList.add(e);
            }
        }

        IScreen peephole = null;
        Element[] libs = (Element[]) libList.toArray(new Element[0]);
        IScreen[] screens = new IScreen[screenList.size()];
        for (int i = 0; i < screens.length; i++) {
            Element e = (Element) screenList.get(i);
            IScreen s = fac.parseScreen(e, libs);
            if (s.getHandle().getValue().endsWith("welcome")) {
                peephole = s;
            }
            screens[i] = s;
        }

        // Build the state machine.
        m = new StateMachine(context, screens, peephole);

    } catch (Throwable t) {
        String msg = "PermissionsPortlet failed to initialize.  See stack " + "trace below.";
        throw new RuntimeException(msg, t);
    }

    initialScreen = m.getPeephole();

    super.init(id, m);

}

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.");
    }// ww w . ja  v 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 {//from  w  ww .j a v  a2 s .  com
        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);
    }//  ww  w. jav  a  2  s. c  om
    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;

}