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.briefcase.engine.SubmitShareeAction.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  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);
    }

    // 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();

    // 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 SubmitShareeAction(owner, handle, choices, toScreen);

}

From source file:net.unicon.academus.apps.briefcase.engine.ToggleNameSorting.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. 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());

    // 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 ToggleNameSorting(owner, handle, choices, toScreen);

}

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

    return new UpdateFileAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.briefcase.engine.UploadAction.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  a2  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 UploadAction(owner, handle, choices);

}

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

    return new WelcomePageAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.briefcase.migrate.BriefcaseMigrator.java

License:Open Source License

public static void main(String[] args) {

    System.out.println("Starting Briefcase portlet migration of data from Academus 1.5 " + " to Academus 1.6");

    if (args.length == 2) {
        try {/*from w  w  w .  jav a 2 s.  c  om*/
            DataSource ds = new SimpleDataSource();

            SAXReader reader = new SAXReader();

            // replace the old urls with the new classpaths
            System.out.println("Updating the resource urls.");
            updateUrl(ds);
            updateSharedResourceUrls(ds);

            // replace the OWNER access type.
            System.out.println("Updating the accessTypes.");
            updateAccessType(ds);

            // set the uni_sequence table for the RdbmsAccessBroker Counter
            // and the FSA_Kernel_Sequencer
            updateSequencers(ds);

            // read the old config file
            // and correct the classpaths for all the access brokers.  
            Document oldDoc = reader.read(args[0]);

            DOMDocumentFactory dFac = new DOMDocumentFactory();

            // Get all access brokers
            List brokers = oldDoc.selectNodes("//access-broker");
            Element broker = null;

            // Change access brokers to point to alchemist instead of academus
            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                String implValue = broker.attributeValue("impl").replaceFirst("academus", "alchemist");
                broker.addAttribute("impl", implValue);
            }

            // Get the Access Broker under the personal Drive, and make sure it's a JIT broker
            Element targetsJitAccessBroker = (Element) ((Element) oldDoc.selectNodes(
                    "/briefcase/drive[@handle='personal']/access-broker[@impl='net.unicon.alchemist.access.jit.JitAccessBroker']")
                    .get(0)).detach();

            // Only enter this code if the personal drive section was successful selected
            if (targetsJitAccessBroker != null) {

                // Create new permissions element, mirroring targets element
                Element permissionsJitAccessBroker = (Element) targetsJitAccessBroker.clone();

                // Change handles
                targetsJitAccessBroker.addAttribute("handle", "personal-resourses-t");
                permissionsJitAccessBroker.addAttribute("handle", "personal-resourses-p");

                // Create new permissions access-broker
                Element permAccessBroker = dFac.createElement(new QName("access-broker"), 2);
                permAccessBroker.addAttribute("handle", "personal-jit");
                permAccessBroker.addAttribute("impl", PermissionsAccessBroker.class.getName());

                // Create new access element and add it to permAccessBroker
                Element permAccess = dFac.createElement(new QName("access"), 1);
                permAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permAccessBroker.add(permAccess);

                // Create targets and permissions elements and add to the new permissions access-broker
                Element targets = permAccessBroker.addElement("targets");
                targets.add(targetsJitAccessBroker);

                Element permissions = permAccessBroker.addElement("permissions");
                permissions.add(permissionsJitAccessBroker);

                // Add new permissions access broker to the drive
                Element curDrive = (Element) oldDoc.selectNodes("/briefcase/drive[@handle='personal']").get(0);
                curDrive.add(permAccessBroker);

                //
                // Change targets internals
                //

                List targetsAccess = targets.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < targetsAccess.size(); i++) {

                    // Add impl attribute with value of fully-qualified class name
                    ((Element) targetsAccess.get(i)).addAttribute("impl", DummyAccessType.class.getName());

                    // Get all child type elements and remove them
                    List types = ((Element) targetsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        ((Element) types.get(j)).detach();
                    }

                    // Add a single dummy element
                    Element eType = dFac.createElement(new QName("type"), 2);
                    eType.addAttribute("value", "GRANT");
                    eType.addAttribute("handle", "DUMMY");

                    ((Element) targetsAccess.get(i)).add(eType);

                }

                // Add internal access broker's access element
                Element targetsIAccessBroker = (Element) (targets.selectNodes("access-broker/access-broker")
                        .get(0));
                Element targetsIAccess = dFac.createElement(new QName("access"), 1);
                targetsIAccess.addAttribute("impl", DummyAccessType.class.getName());
                targetsIAccessBroker.add(targetsIAccess);

                //
                // Change permissions internals
                //

                List permissionsAccess = permissions.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < permissionsAccess.size(); i++) {
                    // Add impl attribute with value of fully-qualified class name
                    ((Element) permissionsAccess.get(i)).addAttribute("impl",
                            BriefcaseAccessType.class.getName());

                    // Get all child type elements and replace them
                    List types = ((Element) permissionsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        Attribute value = ((Element) types.get(j)).attribute("value");
                        String text = value.getValue();
                        value.setValue("GRANT");

                        if (text.equals("0")) {
                            BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                            ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                            for (int k = 1; k < aTypes.length; k++) {
                                Element eType = dFac.createElement(new QName("type"), 2);
                                eType.addAttribute("value", "GRANT");
                                eType.addAttribute("handle", aTypes[k].getName());
                                ((Element) permissionsAccess.get(i)).add(eType);
                            }
                        } else {
                            ((Element) types.get(j)).addAttribute("handle",
                                    BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                        }
                    }

                }

                // Change other elements in the permissions section
                List permissionsBehavior = permissions.selectNodes("access-broker/jit-rule/behavior");
                for (int i = 0; i < permissionsBehavior.size(); i++) {
                    Element trigger = (Element) ((Element) permissionsBehavior.get(i)).elements("trigger")
                            .get(0);
                    Element target = (Element) ((Element) permissionsBehavior.get(i)).elements("target").get(0);
                    Element creator = (Element) ((Element) permissionsBehavior.get(i)).elements("creator")
                            .get(0);

                    // Insert trigger text into target
                    target.addAttribute("type", "GROUP");
                    target.addText(trigger.getText());

                    // Remove current creator element
                    creator.detach();

                    // Add new current creator element
                    Element eCreator = dFac.createElement(new QName("creator"), 1);
                    eCreator.addAttribute("impl", DummyCreator.class.getName());
                    ((Element) permissionsBehavior.get(i)).add(eCreator);
                }

                // Change internal access broker's name
                Element permissionsIAccessBroker = (Element) (permissions
                        .selectNodes("access-broker/access-broker").get(0));
                permissionsIAccessBroker.addAttribute("handle", "personal-resources-p-i");

                // Add internal access broker's access element
                Element permissionsIAccess = dFac.createElement(new QName("access"), 1);
                permissionsIAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permissionsIAccessBroker.add(permissionsIAccess);

            }

            List access = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access");
            for (int i = 0; i < access.size(); i++) {

                // Add impl attribute with value of fully-qualified class name
                ((Element) access.get(i)).addAttribute("impl", BriefcaseAccessType.class.getName());

                List types = ((Element) access.get(i)).elements();
                for (int j = 0; j < types.size(); j++) {
                    Attribute value = ((Element) types.get(j)).attribute("value");
                    String text = value.getValue();
                    value.setValue("GRANT");

                    if (text.equals("0")) {
                        BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                        ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                        for (int k = 1; k < aTypes.length; k++) {
                            Element eType = dFac.createElement(new QName("type"), 2);
                            eType.addAttribute("value", "GRANT");
                            eType.addAttribute("handle", aTypes[k].getName());
                            ((Element) access.get(i)).add(eType);
                        }
                    } else {
                        ((Element) types.get(j)).addAttribute("handle",
                                BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                    }
                }
            }

            // add impl attribute to specify the UserDirectory impl to user-attribute element
            List userAttr = oldDoc.selectNodes("//user-attribute");
            for (int i = 0; i < userAttr.size(); i++) {
                ((Element) userAttr.get(i)).addAttribute("impl",
                        "net.unicon.academus.apps.briefcase.UserAttributeDirectory");
            }

            //replace the resource factory urls  
            List entries = oldDoc
                    .selectNodes("/briefcase/drive[@handle!='personal']//access-broker/entry[@target!='']");
            for (int i = 0; i < entries.size(); i++) {
                ((Element) entries.get(i)).addAttribute("target", ((Element) entries.get(i))
                        .attributeValue("target").replaceAll("academus.resource.factory", "demetrius.fac"));
            }

            // add access element to specify the AccessType to the RdbmsAccessBroker
            brokers = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access-broker[@impl='"
                    + RdbmsAccessBroker.class.getName() + "']");

            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                Element eType = dFac.createElement(new QName("access"), 1);
                eType.addAttribute("impl", BriefcaseAccessType.class.getName());
                broker.add(eType);
            }

            // add the civis address book information.
            Element drive = (Element) oldDoc.selectSingleNode("briefcase");
            drive.addComment("Civis implementation to be used to resolve usernames and group paths"
                    + " to academus users and groups. This should not require"
                    + " modification, as it utilized the Academus framework for gathering this"
                    + " information.");

            Element civis = dFac.createElement("civis");
            civis.addAttribute("id", "addressBook");
            civis.addAttribute("impl", "net.unicon.civis.fac.academus.AcademusCivisFactory");

            Element restrictor = dFac.createElement("restrictor");
            restrictor.addAttribute("impl", "net.unicon.civis.grouprestrictor.AcademusGroupRestrictor");
            civis.add(restrictor);

            drive.add(civis);

            File f = new File(args[1]);
            PrintWriter pw = new PrintWriter(new FileOutputStream(f));
            pw.write(oldDoc.asXML());
            pw.flush();
            pw.close();

            System.out.println(
                    "Done. Enjoy !! \n Remember to the use the migrated config file with the 1.6 deploy.");

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        usage();
    }

}

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

License:Open Source License

public static Method getParser(Element e, Class defaultClass) {

    // Assertions.
    if (e == null) {
        String msg = "Argument 'e [Element]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }//from  w ww . j a  va 2s .co m
    if (defaultClass == null) {
        String msg = "Argument 'defaultClass' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    Class implClass = defaultClass; // duh...
    Attribute impl = e.attribute("impl");
    if (impl != null) {
        String implementationClassName = "unknown class";
        try {
            implementationClassName = impl.getValue();

            // exception for backwards compatibility of SsoEntry impl declaration
            // in configuration files.
            String ssoEntryClassName = SsoEntry.class.getName();
            String ssoEntrySimpleClassName = SsoEntrySimple.class.getName();
            if (ssoEntryClassName.equals(implementationClassName)) {
                LOG.warn("impl=\"" + ssoEntryClassName + "\" appeared in Gateway configuration.  "
                        + "This declaration is deprecated and instead should be impl=\""
                        + ssoEntrySimpleClassName + "\"");
                implementationClassName = ssoEntrySimpleClassName;
            }

            implClass = Class.forName(implementationClassName);
        } catch (Throwable t) {
            String msg = "Unable to create a parser for the specified implementation:  " + impl.getValue();
            throw new RuntimeException(msg, t);
        }
    }

    Method rslt = null;
    try {
        rslt = implClass.getDeclaredMethod("parse", new Class[] { Element.class });
    } catch (Throwable t) {
        String msg = "Unable to create a parser for the specified implementation:  " + implClass.getName();
        throw new RuntimeException(msg, t);
    }

    return rslt;

}

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

License:Open Source License

public static Element handle(Element configElement, boolean handleDataSource) {
    // Resolve imports
    List elist = configElement.selectNodes("//import");
    if (!elist.isEmpty()) {
        for (Iterator it = elist.iterator(); it.hasNext();) {
            Element e = (Element) it.next();

            String fname = null;//from w w  w .j  a  va 2 s .  c o m
            Attribute t = e.attribute("src");
            if (t == null) {
                throw new IllegalArgumentException("Element <import> must contain an attribute 'src'.");
            }
            fname = t.getValue();

            String xpath = null;
            t = e.attribute("select");
            if (t == null) {
                throw new IllegalArgumentException("Element <import> must contain an attribute 'select'.");
            }
            xpath = t.getValue();

            Element e2 = null;
            try {

                // first try the classloader
                URL url = ConfigHelper.class.getResource(fname);

                // next try an url
                if (url == null) {
                    try {
                        url = new URL(fname);
                    } catch (MalformedURLException mue) {
                        // try a file
                        File f = new File(fname);
                        if (!f.exists()) {
                            throw new Exception(); // will get caught below
                        }
                        url = new URL("file", null, fname);
                    }
                }
                e2 = (Element) ConfigHelper.handle((new SAXReader()).read(url.toString()).getRootElement())
                        .selectSingleNode(xpath);
            } catch (Exception ex) {
                throw new RuntimeException(
                        "Unable to import requested document (" + fname + ") and xpath (" + xpath + ")", ex);
            }

            if (e2 == null)
                throw new IllegalArgumentException(
                        "XPath expression [" + xpath + "] failed to resolve into an element.");

            // Replace the import with the selected node definition
            e.getParent().add(e2.detach());
            e.detach();
        }
    }

    elist = configElement.selectNodes("//copy-of");
    if (!elist.isEmpty()) {
        for (Iterator it = elist.iterator(); it.hasNext();) {
            Element e = (Element) it.next();

            String xpath = null;
            Attribute t = e.attribute("select");
            if (t == null) {
                throw new IllegalArgumentException("Element <copy-of> must contain an attribute 'select'.");
            }
            xpath = t.getValue();

            Element e2 = (Element) configElement.selectSingleNode(xpath);
            if (e2 == null)
                throw new IllegalArgumentException(
                        "The given xpath expression did not resolve into a node: " + xpath);

            // Replace the copy-of with the selected node definition
            e.getParent().add(e2.createCopy());
            e.detach();
        }
    }

    elist = configElement.selectNodes("//value-of");
    if (!elist.isEmpty()) {
        for (Iterator it = elist.iterator(); it.hasNext();) {
            Element e = (Element) it.next();

            String xpath = null;
            Attribute t = e.attribute("select");
            if (t == null) {
                throw new IllegalArgumentException("Element <value-of> must contain an attribute 'select'.");
            }
            xpath = t.getValue();

            Element e2 = (Element) configElement.selectSingleNode(xpath);
            if (e2 == null)
                throw new IllegalArgumentException(
                        "The given xpath expression did not resolve into a node: " + xpath);

            // Replace the value-of with the text of the selected node definition
            e.getParent().setText(e2.getText());
            e.detach();
        }
    }

    if (handleDataSource) {
        String jndiName = null;
        Element el = (Element) configElement.selectSingleNode("jndi-ref");
        if (el != null)
            jndiName = el.getText();

        // Bootstrap datasources...
        elist = configElement.selectNodes("//*[@needsDataSource='true']");
        if (jndiName != null && !elist.isEmpty()) {
            try {
                DataSource ds = new AcademusDataSource();

                for (Iterator it = elist.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) {
                throw new RuntimeException("Failed the DataSource bootstrapping", e);
            }
        }
    }

    return configElement;
}

From source file:net.unicon.academus.apps.content.NavigateAction.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. jav  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 NavigateAction(owner, handle, choices);

}

From source file:net.unicon.academus.apps.content.WebContentPortlet.java

License:Open Source License

public void init(PortletConfig config) {

    // Instance Id.
    this.id = config.getInitParameter("Id");

    // Initialize.
    IScreen peephole = null;/*w w  w.  java 2 s  . c o m*/
    StateMachine m = null;
    try {

        int timer = Integer.parseInt(config.getInitParameter("userContextTimer"));
        userContextMap = TimedCache.getCache("ssoAuthentication", timer);

        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("web-content");

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

        boolean cacheTemplates = true;

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

        // AJAX form population
        String ajaxCallbackUrl = null;

        Element ajaxElement = (Element) configElement.selectSingleNode("wcms-sso/ajax-callback-url");
        if (ajaxElement != null) {
            ajaxCallbackUrl = ajaxElement.getText();
        }

        // Obtain the sso broker.
        Element brkrElement = (Element) configElement.selectSingleNode("wcms-sso/access-broker");
        AccessBroker ssoBroker = AccessBroker.parse(brkrElement);

        // Obtain the content broker.
        brkrElement = (Element) configElement.selectSingleNode("access-broker");
        AccessBroker contentBroker = AccessBroker.parse(brkrElement);

        // Obtain the BodyXpath.
        Attribute x = configElement.attribute("body-xpath");
        if (x == null) {
            String msg = "Element <web-content> is missing required " + "attribute 'body-xpath'.";
            throw new RuntimeException(msg);
        }
        String bodyXpath = x.getValue();

        // Obtain the input tags for PageGuid and ProjectGuid.
        Attribute t = configElement.attribute("input-tags");
        if (t == null) {
            String msg = "Element <web-content> is missing required " + "attribute 'input-tags'.";
            throw new RuntimeException(msg);
        }
        String inputTags = t.getValue();

        // Parse the rewriting rules.
        List list = configElement.selectNodes("url-rewriting/pattern");
        UrlRewritingRule[] rules = new UrlRewritingRule[list.size()];
        for (int i = 0; i < rules.length; i++) {
            Element e = (Element) list.get(i);
            rules[i] = UrlRewritingRule.parse(e);
        }

        x = configElement.attribute("filter-config");
        XHTMLFilterConfig filterConfig = null;
        if (x != null && x.getValue().length() > 0) {
            filterConfig = XHTMLFilter.getConfiguration(x.getValue());
        }

        // Construct the application context.
        context = new WebContentApplicationContext(ssoBroker, contentBroker, bodyXpath, inputTags, filterConfig,
                rules, new SsoHandlerXML(), ajaxCallbackUrl);

        // 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);
        }

        // Choose a peephole.
        Attribute p = configElement.attribute("peephole");
        if (p != null) {
            String path = p.getValue();
            if (path.trim().length() != 0) {
                URL screenUrl = ctx.getResource(path);
                Element e = (Element) reader.read(screenUrl.toString()).selectSingleNode("screen");
                peephole = fac.parseScreen(e);
            }
        }

        // Construct the screens.
        list = new ArrayList();
        Iterator it = ctx.getResourcePaths("/rendering/screens/content/").iterator();
        while (it.hasNext()) {
            String path = (String) it.next();
            URL screenUrl = ctx.getResource(path);
            Element e = (Element) reader.read(screenUrl.toString()).selectSingleNode("screen");
            IScreen s = fac.parseScreen(e);
            list.add(s);
        }

        // Build the state machine.
        IScreen[] screens = (IScreen[]) list.toArray(new IScreen[0]);
        m = new StateMachine(context, screens, peephole);

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

    // Construct the user attributes collection.
    try {
        IEntityStore store = new JvmEntityStore();
        IOption oName = store.createOption(net.unicon.penelope.Handle.create("id"), null,
                TypeText1024.INSTANCE);
        IOption oPswd = store.createOption(net.unicon.penelope.Handle.create("password"), null,
                TypeText1024.INSTANCE);
        IChoice choice = store.createChoice(net.unicon.penelope.Handle.create("user.login"), null,
                new IOption[] { oName, oPswd }, 2, 2);
        userAttributes = store.createChoiceCollection(net.unicon.penelope.Handle.create("userAttributes"), null,
                new IChoice[] { choice });
    } catch (Throwable t) {
        String msg = "WebContentPortlet failed to initialize user " + "attributes.  See stack trace below.";
        throw new RuntimeException(msg, t);
    }

    if (peephole != null) {
        initialQuery = new StateQueryImpl("<state />");
        initialScreen = peephole;
    } else {
        initialQuery = null;
        initialScreen = m.getScreen(Handle.create("index"));
    }

    super.init(id, m);

}