Example usage for org.jdom2 Element getAdditionalNamespaces

List of usage examples for org.jdom2 Element getAdditionalNamespaces

Introduction

In this page you can find the example usage for org.jdom2 Element getAdditionalNamespaces.

Prototype

public List<Namespace> getAdditionalNamespaces() 

Source Link

Document

Returns a list of the additional namespace declarations on this element.

Usage

From source file:org.mycore.frontend.editor.MCREditorSubmission.java

License:Open Source License

/**
 * Stores the list of additional namespaces declared in the components
 * element of the editor definition. These namespaces and its prefixes can
 * be used in editor variable paths (var attributes of cells).
 *//*  w  ww  .  j  av a  2 s .  c  om*/
@SuppressWarnings("unchecked")
private void setAdditionalNamespaces(Element editor) {
    Element components = editor.getChild("components");
    List<Namespace> namespaces = components.getAdditionalNamespaces();
    for (Namespace ns : namespaces) {
        nsMap.put(ns.getPrefix(), ns);
    }
    nsMap.put("xml", Namespace.XML_NAMESPACE);
    for (Namespace ns : MCRConstants.getStandardNamespaces()) {
        setNamespaceIfUndefined(ns);
    }
}

From source file:org.mycore.frontend.xeditor.MCREditorSession.java

License:Open Source License

private void addNamespacesFrom(Element element) {
    MCRConstants.registerNamespace(element.getNamespace());
    for (Namespace ns : element.getAdditionalNamespaces()) {
        MCRConstants.registerNamespace(ns);
    }/* ww w.j a  v  a2 s .  com*/
    for (Element child : element.getChildren())
        addNamespacesFrom(child);
}

From source file:org.rometools.feed.module.content.io.ContentModuleParser.java

License:Open Source License

public com.sun.syndication.feed.module.Module parse(org.jdom2.Element element) {
    boolean foundSomething = false;
    ContentModule cm = new ContentModuleImpl();
    List encodeds = element.getChildren("encoded", CONTENT_NS);
    ArrayList contentStrings = new ArrayList();
    ArrayList encodedStrings = new ArrayList();

    if (encodeds.size() > 0) {
        foundSomething = true;//from w ww.  j  av  a 2s  .  c  om

        for (int i = 0; i < encodeds.size(); i++) {
            Element encodedElement = (Element) encodeds.get(i);
            encodedStrings.add(encodedElement.getText());
            contentStrings.add(encodedElement.getText());
        }
    }

    ArrayList contentItems = new ArrayList();
    List items = element.getChildren("items", CONTENT_NS);

    for (int i = 0; i < items.size(); i++) {
        foundSomething = true;

        List lis = ((Element) items.get(i)).getChild("Bag", RDF_NS).getChildren("li", RDF_NS);

        for (int j = 0; j < lis.size(); j++) {
            ContentItem ci = new ContentItem();
            Element li = (Element) lis.get(j);
            Element item = li.getChild("item", CONTENT_NS);
            Element format = item.getChild("format", CONTENT_NS);
            Element encoding = item.getChild("encoding", CONTENT_NS);
            Element value = item.getChild("value", RDF_NS);

            if (value != null) {
                if (value.getAttributeValue("parseType", RDF_NS) != null) {
                    ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS));
                }

                if ((ci.getContentValueParseType() != null)
                        && ci.getContentValueParseType().equals("Literal")) {
                    ci.setContentValue(getXmlInnerText(value));
                    contentStrings.add(getXmlInnerText(value));
                    ci.setContentValueNamespaces(value.getAdditionalNamespaces());
                } else {
                    ci.setContentValue(value.getText());
                    contentStrings.add(value.getText());
                }

                ci.setContentValueDOM(((Element) value.clone()).getContent());
            }

            if (format != null) {
                ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue());
            }

            if (encoding != null) {
                ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue());
            }

            if (item != null) {
                Attribute about = item.getAttribute("about", RDF_NS);

                if (about != null) {
                    ci.setContentAbout(about.getValue());
                }
            }

            contentItems.add(ci);
        }
    }

    cm.setEncodeds(encodedStrings);
    cm.setContentItems(contentItems);
    cm.setContents(contentStrings);

    return (foundSomething) ? cm : null;
}

From source file:org.rometools.feed.module.mediarss.io.RSS20YahooParser.java

License:Open Source License

/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>//from www. ja  v a2 s  .com
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
    boolean ok = false;

    Element rssRoot = document.getRootElement();
    Namespace defaultNS = rssRoot.getNamespace();
    List additionalNSs = rssRoot.getAdditionalNamespaces();

    ok = (defaultNS != null) && defaultNS.equals(getRSSNamespace());

    return ok;
}

From source file:org.yawlfoundation.yawl.scheduling.PlanningGraphCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
/**//www  .jav a 2s. c  o m
 * TODO@tbe: determine order of activities, store them as utilisation relations and sort
 * activities according to utilisation relations
 */
public Collection<Element> getActivityElements(String caseId)
        throws IOException, JDOMException, JaxenException {
    Element element = SchedulingService.getInstance().getSpecificationForCase(caseId);
    Document doc = new Document(element);

    Map<String, String> map = new HashMap<String, String>();
    map.put("bla", element.getNamespace().getURI());
    for (Object o : element.getAdditionalNamespaces()) {
        Namespace ns = (Namespace) o;
        map.put(ns.getPrefix(), ns.getURI());
    }

    org.jaxen.XPath xp = new JDOMXPath("//bla:expression/@query");
    xp.setNamespaceContext(new SimpleNamespaceContext(map));
    List<Attribute> list = xp.selectNodes(doc);
    List<String> activityNames = new ArrayList<String>();
    for (Attribute e : list) {
        String value = e.getValue();
        int startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">");
        int endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">");
        while (startIndex >= 0 && endIndex > startIndex) {
            if (!value.startsWith("<" + XML_EVENT_RECEIVE + ">")) {
                String activityName = value.substring(startIndex + lenActName, endIndex).trim();

                // ignore XPath expressions
                if (!activityName.contains("/") && !activityNames.contains(activityName)) {
                    activityNames.add(activityName);
                }
            }
            value = value.substring(endIndex + lenActName);
            startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">");
            endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">");
        }
    }

    //TODO@tbe: sort activities, only until order of activities can be determined from process model
    final List<String> possibleActivities = Utils
            .parseCSV(PropertyReader.getInstance().getSchedulingProperty("possibleActivitiesSorted"));
    Collections.sort(activityNames, new Comparator<String>() {
        public int compare(String a1, String a2) {
            if (possibleActivities.indexOf(a1) < 0) {
                return -1; // set missing activities at beginning
            } else if (possibleActivities.indexOf(a2) < 0) {
                return 1; // set missing activities at beginning
            } else {
                return possibleActivities.indexOf(a1) - possibleActivities.indexOf(a2);
            }
        }
    });
    logger.debug("activityNames: " + Utils.toString(activityNames));

    Collection<Element> activities = new ArrayList<Element>();
    Element preRelation = null; // relation of previous activity
    for (int i = 0; i < activityNames.size(); i++) {
        String activityName = activityNames.get(i);
        if (i > 0) {
            preRelation.getChild(XML_OTHERACTIVITYNAME).setText(activityName);
        }

        Element activity = FormGenerator.getTemplate(XML_ACTIVITY);
        activities.add(activity);
        activity.getChild(XML_ACTIVITYNAME).setText(activityName);

        if (i < activityNames.size() - 1) {
            preRelation = FormGenerator.getTemplate(XML_UTILISATIONREL);
            activity.addContent(preRelation);
        }
    }
    return activities;
}