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:musite.taxonomy.TaxonomyXMLReader.java

License:Open Source License

public TaxonomyTree read(InputStream is) throws IOException {
    if (is == null) {
        throw new IllegalArgumentException();
    }/*w w  w . j  ava  2s  . c o  m*/

    TaxonomyTree tree = new TaxonomyTree();

    SAXReader saxReader = new SAXReader();
    //BufferedInputStream bis = new BufferedInputStream(is);
    //Document document = saxReader.read(new File("c:/catalog/catalog.xml"));

    try {
        Document document = saxReader
                .read(new File("D:/Yao/NetBeansProjects/musite/testData/taxonomy-ancestor_51967.rdf"));
        List list = document.selectNodes("//rdf:RDF");
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            String TaxonomyID = null;
            String Type = null;
            String Rank = null;
            String ScientificName = null;
            ArrayList<String> OtherNames = new ArrayList<String>();
            boolean partOfLineage = false;

            Element element = (Element) iter.next();
            Attribute attribute = element.attribute("rdf:about");
            TaxonomyID = attribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, "");

            Iterator typeIterator = element.elementIterator("rdf:type");
            while (typeIterator.hasNext()) {
                Element typeElement = (Element) typeIterator.next();
                Attribute typeAttribute = typeElement.attribute("rdf:resource");
                Type = typeAttribute.getValue().replaceAll(UniprotTaxonomySettings.TYPE_ADDRESS, "");
            }
            Iterator rankIterator = element.elementIterator("rank");
            while (rankIterator.hasNext()) {
                Element rankElement = (Element) rankIterator.next();
                Attribute rankAttribute = rankElement.attribute("rdf:resource");
                Rank = rankAttribute.getValue().replaceAll(UniprotTaxonomySettings.RANK_ADDRESS, "");
            }
            Iterator scientificnameIterator = element.elementIterator("scientificName");
            while (scientificnameIterator.hasNext()) {
                Element scientificnameElement = (Element) scientificnameIterator.next();
                ScientificName = scientificnameElement.getText();
            }
            Iterator othernameIterator = element.elementIterator("otherName");
            while (othernameIterator.hasNext()) {
                Element othernameElement = (Element) othernameIterator.next();
                String tempname = othernameElement.getText();
                OtherNames.add(tempname);
            }
            Iterator lineageIterator = element.elementIterator("partOfLineage");
            while (lineageIterator.hasNext()) {
                Element lineageElement = (Element) lineageIterator.next();
                String temptext = lineageElement.getText();
                if (temptext.equals("true")) {
                    partOfLineage = true;
                } else
                    partOfLineage = false;
            }

            //create a new node
            TaxonomyNode node = tree.getTaxonomyNode(TaxonomyID);
            if (node == null) {
                node = new TaxonomyNode();
                node.setIdentifier(TaxonomyID);
                tree.addtoNodelist(node);
            }

            node.setOtherNames(OtherNames);
            node.setRank(Rank);
            node.setScientificName(ScientificName);
            node.setType(Type);
            node.setPartOfLineage(partOfLineage);

            //add the parent node
            Iterator subclassIterator = element.elementIterator("rdfs:subClassOf");
            while (subclassIterator.hasNext()) {
                Element subclassElement = (Element) subclassIterator.next();
                Attribute subclassAttribute = subclassElement.attribute("rdf:resource");
                String subclassID = subclassAttribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS,
                        "");
                TaxonomyNode parent = tree.getTaxonomyNode(subclassID);
                if (parent != null) {
                    node.addParent(parent);
                } else {
                    parent = new TaxonomyNode();
                    parent.setIdentifier(subclassID);
                    tree.addtoNodelist(parent);
                    node.addParent(parent);
                }

            }
        }

    } catch (Exception e) {
    }

    return tree;
}

From source file:musite.taxonomy.UniprotTaxonomyXMLReader.java

License:Open Source License

public TaxonomyTree read(InputStream is) throws IOException {
    if (is == null) {
        throw new IllegalArgumentException();
    }/*from   w  w  w.  ja v a2  s .c o m*/
    final TaxonomyTree tree = new TaxonomyTree();
    SAXReader saxReader = new SAXReader();
    final TaxonomyNode currentNode = new TaxonomyNode();

    // entry
    saxReader.addHandler("/RDF/Description", new ElementHandler() {
        public void onStart(ElementPath path) {
            currentNode.clearMembers();
            Element element = path.getCurrent();
            Attribute attribute = element.attribute("about");
            String TaxonomyID = attribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, "");
            currentNode.setIdentifier(TaxonomyID);

        }

        public void onEnd(ElementPath path) {
            // process an element

            //create a new node
            TaxonomyNode node = tree.getTaxonomyNode(currentNode.getIdentifier());
            if (node == null) {
                node = new TaxonomyNode();
                currentNode.copyMembersTo(node);
                tree.addtoNodelist(node);
            } else {
                currentNode.copyMembersTo(node);
            }

            //change the parent from currentNode to node
            ArrayList<TaxonomyNode> parentlist = node.getParents();
            for (int i = 0; i < parentlist.size(); i++) {
                TaxonomyNode parent = parentlist.get(i);
                parent.getChildren().add(node);
            }

            // prune the tree
            Element row = path.getCurrent();
            row.detach();
        }
    });

    // type
    saxReader.addHandler("/RDF/Description/type", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element typeElement = (Element) path.getCurrent();
            Attribute typeAttribute = typeElement.attribute("resource");
            String Type = typeAttribute.getValue().replaceAll(UniprotTaxonomySettings.TYPE_ADDRESS, "");
            currentNode.setType(Type);

        }
    });

    // rank
    saxReader.addHandler("/RDF/Description/rank", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element rankElement = (Element) path.getCurrent();
            Attribute rankAttribute = rankElement.attribute("resource");
            String Rank = rankAttribute.getValue().replaceAll(UniprotTaxonomySettings.RANK_ADDRESS, "");
            currentNode.setRank(Rank);

        }
    });

    // scientificName
    saxReader.addHandler("/RDF/Description/scientificName", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element scientificnameElement = (Element) path.getCurrent();
            String ScientificName = scientificnameElement.getText();
            currentNode.setScientificName(ScientificName);
        }
    });
    // otherName
    saxReader.addHandler("/RDF/Description/otherName", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element othernameElement = (Element) path.getCurrent();
            String tempname = othernameElement.getText();
            currentNode.addOthernames(tempname);

        }
    });

    // partOfLineage
    saxReader.addHandler("/RDF/Description/partOfLineage", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element lineageElement = (Element) path.getCurrent();
            String temptext = lineageElement.getText();
            boolean partOfLineage;
            if (temptext.equals("true")) {
                partOfLineage = true;
            } else
                partOfLineage = false;
            currentNode.setPartOfLineage(partOfLineage);

        }
    });

    // Add parent
    saxReader.addHandler("/RDF/Description/subClassOf", new ElementHandler() {
        public void onStart(ElementPath path) {
            // do nothing
        }

        public void onEnd(ElementPath path) {
            Element subclassElement = (Element) path.getCurrent();
            Attribute subclassAttribute = subclassElement.attribute("resource");
            String subclassID = subclassAttribute.getValue().replaceAll(UniprotTaxonomySettings.ID_ADDRESS, "");
            TaxonomyNode parent = tree.getTaxonomyNode(subclassID);
            if (parent != null) {
                currentNode.addParentOnly(parent);
            } else {
                parent = new TaxonomyNode();
                parent.setIdentifier(subclassID);
                tree.addtoNodelist(parent);
                currentNode.addParentOnly(parent);
            }

        }
    });

    BufferedInputStream bis = new BufferedInputStream(is);

    Document doc;
    try {
        doc = saxReader.read(bis);
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }

    tree.searchRoot();
    return tree;
}

From source file:net.sf.saxon.dom4j.NodeWrapper.java

License:Mozilla Public License

/**
* Get the value of a given attribute of this node
* @param fingerprint The fingerprint of the attribute name
* @return the attribute value if it exists or null if not
*//* w  w w.j  a v  a2 s.  com*/

public String getAttributeValue(int fingerprint) {
    if (nodeKind == Type.ELEMENT) {
        Iterator list = ((Element) node).attributes().iterator();
        NamePool pool = docWrapper.getNamePool();
        while (list.hasNext()) {
            Attribute att = (Attribute) list.next();
            int nameCode = pool.allocate(att.getNamespacePrefix(), att.getNamespaceURI(), att.getName());
            if (fingerprint == (nameCode & 0xfffff)) {
                return att.getValue();
            }
        }
    }
    return null;
}

From source file:net.sf.saxon.option.dom4j.NodeWrapper.java

License:Mozilla Public License

/**
 * Get the string value of a given attribute of this node
 *
 * @param uri   the namespace URI of the attribute name. Supply the empty string for an attribute
 *              that is in no namespace//from  w  w w  . j  a  v  a  2  s.  c  o m
 * @param local the local part of the attribute name.
 * @return the attribute value if it exists, or null if it does not exist. Always returns null
 *         if this node is not an element.
 * @since 9.4
 */
public String getAttributeValue(/*@NotNull*/ String uri, /*@NotNull*/ String local) {
    if (nodeKind == Type.ELEMENT) {
        for (Object o : ((Element) node).attributes()) {
            Attribute att = (Attribute) o;
            if (att.getName().equals(local) && att.getNamespaceURI().equals(uri)) {
                return att.getValue();
            }
        }
    }
    return null;
}

From source file:net.sourceforge.sqlexplorer.preview.XmlPreviewer.java

License:Open Source License

public void createControls(Composite parent, final Object data) throws ExplorerException {
    Element rootElem = getXml(data);
    if (rootElem == null)
        return;/*from   w  w w . ja v a2  s . c  o m*/
    final Object[] root = new Object[] { rootElem };

    TreeViewer tree = new TreeViewer(parent, SWT.SINGLE);
    tree.setContentProvider(new ITreeContentProvider() {
        public void dispose() {
        }

        /**
         * Called to get the top level items
         */
        public Object[] getChildren(Object parentElement) {
            return root;
        }

        /**
         * Called to get the item's children
         */
        public Object[] getElements(Object inputElement) {
            Element elem = (Element) inputElement;
            return elem.elements().toArray();
        }

        public boolean hasChildren(Object element) {
            Element elem = (Element) element;
            List<Element> list = elem.elements();
            return list != null && list.size() > 0;
        }

        public Object getParent(Object element) {
            Element elem = (Element) element;
            return elem.getParent();
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // Nothing
        }
    });

    tree.setLabelProvider(new LabelProvider() {
        public String getText(Object obj) {
            Element elem = (Element) obj;
            StringBuffer result = new StringBuffer();
            result.append('<');
            result.append(elem.getName());

            for (Attribute attr : elem.attributes()) {
                result.append(' ').append(attr.getName()).append('=').append('\"').append(attr.getValue())
                        .append('\"');
            }
            if (!elem.hasContent())
                result.append('/');
            result.append('>');
            return result.toString();
        }
    });

    tree.expandToLevel(1);
}

From source file:net.unicon.academus.apps.blogger.access.AcademusAuthorizationProvider.java

License:Open Source License

/**
 * Initialization method for the authorization provider
 *
 * @param servletConfig ServletConfig for obtaining any initialization parameters
 * @param blojsomConfiguration BlojsomConfiguration for blojsom-specific
 * configuration information//  w  w w  .  ja v  a  2  s  .  com
 * @throws org.blojsom.blog.BlojsomConfigurationException
 *   If there is an error initializing the provider
 */
public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
        throws BlojsomConfigurationException {
    if (_inited)
        return;

    _servletConfig = servletConfig;

    try {
        // Parse the gateway config file.
        String configPath = blojsomConfiguration.getBaseConfigurationDirectory() + ACADEMUS_CONFIGURATION;

        URL configUrl = _servletConfig.getServletContext().getResource(configPath);

        SAXReader reader = new SAXReader();
        Element configElement = (Element) reader.read(configUrl.toString()).getRootElement();

        Element el = (Element) configElement.selectSingleNode("jndi-ref");
        if (el != null) {
            _jndiName = el.getText();
        }

        // Bootstrap all RDBMS Access Brokers.
        List bsList = configElement.selectNodes("//*[@needsDataSource='true']");
        if (!bsList.isEmpty()) {
            DataSource ds = new AcademusDataSource();

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

        // Get Permissions Access Broker.
        List list = configElement.selectNodes("access-broker");
        if (list == null)
            throw new Exception(
                    "AcademusAuthorizationProvider requires one <access-broker> element per blog instance.");
        else {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                el = (Element) it.next();
                AccessBroker ab = AccessBroker.parse(el);
                String handle = el.attribute("handle").getValue().substring(5);
                _logger.debug("Adding AccessBroker for blog instance '" + handle + "'");
                _brokers.put(handle, ab);
            }
        }

        // Get Academus Facade.
        _facade = AcademusFacadeContainer.retrieveFacade();

    } catch (Throwable e) {
        _logger.debug("Error AcademusAuthorizationProvider::init");
        e.printStackTrace(System.err);
        throw new BlojsomConfigurationException(e);
    }

    _logger.debug("Initialized Academus authorization provider");
    _inited = true;

}

From source file:net.unicon.academus.apps.briefcase.BriefcasePortlet.java

License:Open Source License

public void init(PortletConfig config) {

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

    // Initialize.
    StateMachine m = null;//from   w ww  . j  a  v a 2 s. c o m
    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("briefcase");

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

        boolean cacheTemplates = true;

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

        // Prep the drive(s).
        List dList = configElement.selectNodes("drive");
        Drive[] drives = new Drive[dList.size()];
        for (int i = 0; i < drives.length; i++) {
            drives[i] = Drive.parse((Element) dList.get(i));
        }

        // read the selector civis factory information
        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 BriefcaseApplicationContext(drives, id,
                (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 list = new ArrayList();
        IScreen peephole = null;
        Iterator it = ctx.getResourcePaths("/rendering/screens/briefcase/").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);
            if (s.getHandle().equals("welcome")) {
                peephole = s;
            }
            list.add(s);
        }

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

        // initailize a logger for the application
        // read the logging information to activate the specified categories            
        Element loggerElement = (Element) configElement.selectSingleNode("logger");
        if (loggerElement != null) {
            Logger logger = Logger.parse(loggerElement);
            BriefcaseLogger.bootStrap(logger);
        }

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

    initialScreen = m.getScreen(Handle.create("welcome"));

    super.init(id, m);
}

From source file:net.unicon.academus.apps.briefcase.Drive.java

License:Open Source License

public static Drive parse(Element e) {

    // 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("drive")) {
        String msg = "Argument 'e [Element]' must be a <drive> element.";
        throw new IllegalArgumentException(msg);
    }

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

    // MaxFileSize.
    long maxFileSize = 0L;
    Attribute x = e.attribute("max-upload");
    // NB:  Attribute 'max-upload' is optional.
    if (x != null) {
        try {
            maxFileSize = Long.parseLong(x.getValue());
        } catch (Throwable t) {
            String msg = "Attribute 'max-upload' must be a valid integer.";
            throw new RuntimeException(msg, t);
        }
    }

    // Large Icon.
    Attribute lgi = e.attribute("large-icon");
    if (lgi == null) {
        String msg = "Element <drive> is missing required attribute " + "'large-icon'.";
        throw new IllegalArgumentException(msg);
    }
    String largeIcon = lgi.getValue();

    // Open Icon.
    Attribute opi = e.attribute("open-icon");
    if (opi == null) {
        String msg = "Element <drive> is missing required attribute " + "'open-icon'.";
        throw new IllegalArgumentException(msg);
    }
    String openIcon = opi.getValue();

    // Closed Icon.
    Attribute cli = e.attribute("closed-icon");
    if (cli == null) {
        String msg = "Element <drive> is missing required attribute " + "'closed-icon'.";
        throw new IllegalArgumentException(msg);
    }
    String closedIcon = cli.getValue();

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

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

    // ShareTarget.
    Attribute s = e.attribute("share-target");
    String shareTarget = null;
    if (s != null) {
        // Not provided means don't share.
        shareTarget = s.getValue();
    }

    // Broker.
    Element b = (Element) e.selectSingleNode("access-broker");
    if (b == null) {
        String msg = "Element <drive> is missing required child element " + "<access-broker>.";
        throw new IllegalArgumentException(msg);
    }
    AccessBroker broker = AccessBroker.parse(b);

    return new Drive(handle, maxFileSize, largeIcon, openIcon, closedIcon, label, description, shareTarget,
            broker);

}

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

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

}

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

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

}