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.engine.CancelChangesAction.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  ava 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 CancelChangesAction(owner, handle, choices);

}

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

    return new ChangeNameFilterAction(owner, handle, choices);
}

From source file:net.unicon.academus.apps.permissions.engine.ChangePermissionsPageAction.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 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("mode");
    if (m == null) {
        String msg = "Element <action> is missing required attribute " + "'mode'.";
        throw new XmlFormatException(msg);
    }
    PageChange change = PageChange.getInstance(m.getValue());

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

}

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);
    }//w w w.j  av  a 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);
    }/*www  . ja  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) {
        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 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) {
        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 w  w. j  a va 2s . 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);
    }//w w  w  . 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) {
        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);
    }/*from  www . jav  a 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 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;//from w  ww.ja  v  a  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);

}