Example usage for org.jdom2 Element getNamespace

List of usage examples for org.jdom2 Element getNamespace

Introduction

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

Prototype

public Namespace getNamespace() 

Source Link

Document

Returns the element's Namespace .

Usage

From source file:net.instantcom.mm7.MM7Response.java

License:Open Source License

@Override
public Element save(Element parent) {
    Element e = super.save(parent);
    Element status = new Element("Status", e.getNamespace());
    if (statusCode > 0) {
        status.addContent(new Element("StatusCode", e.getNamespace()).setText(Integer.toString(statusCode)));
        status.addContent(new Element("StatusText", e.getNamespace()).setText(statusText));
    }/*w w w .  j a  va2  s .  c o m*/
    e.addContent(status);
    return e;
}

From source file:net.instantcom.mm7.SubmitReq.java

License:Open Source License

public Element save(Element parent) {
    Element e = super.save(parent);
    e.setName("SubmitReq");
    if (!recipients.isEmpty()) {
        Element r = new Element("Recipients", e.getNamespace());
        addRecipients(r, RecipientType.TO);
        addRecipients(r, RecipientType.CC);
        addRecipients(r, RecipientType.BCC);
        if (r.getContentSize() > 0) {
            e.addContent(r);/* w w w.  ja va 2  s.  c  om*/
        }
    }
    if (serviceCode != null) {
        e.addContent(new Element("ServiceCode", e.getNamespace()).setText(serviceCode));
    }
    if (linkedId != null) {
        e.addContent(new Element("LinkedID", e.getNamespace()).setText(linkedId));
    }
    if (messageClass != null) {
        e.addContent(new Element("MessageClass", e.getNamespace()).setText(messageClass.toString()));
    }
    if (timeStamp != null) {
        e.addContent(
                new Element("TimeStamp", e.getNamespace()).setText(new RelativeDate(timeStamp).toString()));
    }
    if (replyChargingSize != null) {
        e.addContent(new Element("ReplyChargingSize", e.getNamespace()).setText(replyChargingSize.toString()));
    }
    if (replyDeadline != null) {
        e.addContent(new Element("ReplyDeadline", e.getNamespace()).setText(replyDeadline.toString()));
    }
    if (earlistDeliveryTime != null) {
        e.addContent(
                new Element("EarlistDeliveryTime", e.getNamespace()).setText(earlistDeliveryTime.toString()));
    }
    if (expiryDate != null) {
        e.addContent(new Element("ExpiryDate", e.getNamespace()).setText(expiryDate.toString()));
    }
    if (deliveryReport != null) {
        e.addContent(
                new Element("DeliveryReport", e.getNamespace()).setText(deliveryReport ? "True" : "False"));
    }
    if (readReply != null) {
        e.addContent(new Element("ReadReply", e.getNamespace()).setText(readReply ? "True" : "False"));
    }
    if (priority != null) {
        e.addContent(new Element("Priority", e.getNamespace()).setText(priority.toString()));
    }
    if (subject != null) {
        e.addContent(new Element("Subject", e.getNamespace()).setText(subject.toString()));
    }
    if (chargedParty != null) {
        e.addContent(new Element("ChargedParty", e.getNamespace()).setText(chargedParty.toString()));
    }
    if (chargedPartyId != null) {
        e.addContent(new Element("ChargedPartyID", e.getNamespace()).setText(chargedPartyId.toString()));
    }
    if (distributionIndicator != null) {
        e.addContent(new Element("DistributionIndicator", e.getNamespace())
                .setText(distributionIndicator ? "True" : "False"));
    }

    // deliveryCondition
    if (applicID != null) {
        e.addContent(new Element("ApplicID", e.getNamespace()).setText(applicID));
    }
    if (replyApplicID != null) {
        e.addContent(new Element("ReplyApplicID", e.getNamespace()).setText(replyApplicID));
    }
    if (auxApplicId != null) {
        e.addContent(new Element("AuxApplicId", e.getNamespace()).setText(auxApplicId));
    }
    if (contentClass != null) {
        e.addContent(new Element("ContentClass", e.getNamespace()).setText(contentClass.toString()));
    }
    if (drmContent != null) {
        e.addContent(new Element("DRMContent", e.getNamespace()).setText(drmContent ? "True" : "False"));
    }
    if (content != null) {
        Element c = new Element("Content", e.getNamespace());
        if (allowAdaptations != null) {
            c.setAttribute("allowAdaptations", allowAdaptations ? "True" : "False");
        }
        c.setAttribute("href", "cid:mm7-content");
        e.addContent(c);
    }

    return e;
}

From source file:net.instantcom.mm7.SubmitRsp.java

License:Open Source License

@Override
public Element save(Element parent) {
    Element e = super.save(parent);
    if (messageId != null) {
        e.addContent(new Element("MessageID", e.getNamespace()).setText(messageId));
    }/*w w w . j av  a 2s .  c om*/
    return e;
}

From source file:no.imr.stox.functions.utils.JDOMUtils.java

public static void insertElement(Element elm, int idx, String name, String text) {
    if (name == null || text == null || name.isEmpty() || text.isEmpty()) {
        return;/*w  w w .j ava 2  s  .co m*/
    }
    if (elm == null) {
        return;
    }
    Element c = new Element(name, elm.getNamespace());
    c.setText(text);
    if (idx == -1) {
        elm.addContent(c);
    } else {
        elm.addContent(idx, c);
    }
}

From source file:no.imr.stox.functions.utils.JDOMUtils.java

public static String getNodeValue(Element node, String nodeName, String missingStr) {
    String res;/*from w w  w . j  av a  2s  . c  om*/
    if (node == null) {
        return null;
    }
    Attribute a = node.getAttribute(nodeName);
    if (a != null) {
        res = a.getValue();
    } else {
        res = node.getChildText(nodeName, node.getNamespace());
        if (res == null || res.isEmpty()) {
            res = missingStr;
        }
    }
    return res;
}

From source file:no.imr.stox.functions.utils.JDOMUtils.java

public static Element getChild(Element node, String nodeName) {
    return node.getChild(nodeName, node.getNamespace());
}

From source file:org.apache.marmotta.ucuenca.wk.provider.scopus.ScopusAuthorSearchProvider.java

License:Apache License

@Override
public List<String> parseResponse(String resource, String requestUrl, Model triples, InputStream input,
        String contentType) throws DataRetrievalException {
    log.debug("Request Successful to {0}", requestUrl);
    try {//from ww  w . j  av  a2 s . c  o m
        ValueFactory factory = ValueFactoryImpl.getInstance();
        final Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(input);
        Element aux = doc.getRootElement();
        for (Element element : aux.getChildren("entry", aux.getNamespace())) {
            String authorIDParam = element.getChildText("identifier", NAMESPACE_DC);
            String authorURL = element.getChildText("url", NAMESPACE_PRISM);
            ClientConfiguration conf = new ClientConfiguration();
            LDClient ldClient = new LDClient(conf);

            if (authorIDParam != null) {
                Model candidateModel = null;
                String authorUrlResourceCleaned = URLRESOURCE.replace("AuthorIdParam", authorIDParam)
                        .replace("apiKeyParam", apiKeyParam);
                triples.add(factory.createURI(resource), FOAF.MEMBER, factory.createURI(authorURL));

                ClientResponse response = ldClient.retrieveResource(authorUrlResourceCleaned);
                Model authorModel = response.getData();
                if (candidateModel == null) {
                    candidateModel = authorModel;
                } else {
                    candidateModel.addAll(authorModel);
                }

                triples.addAll(candidateModel);

            }

        }

    } catch (IOException e) {
        throw new DataRetrievalException("I/O error while parsing HTML response", e);
    } catch (JDOMException e) {
        throw new DataRetrievalException("could not parse XML response. It is not in proper XML format", e);
    }

    return Collections.emptyList();
}

From source file:org.apache.marmotta.ucuenca.wk.provider.scopus.ScopusPublicationSearchProvider.java

License:Apache License

@Override
public List<String> parseResponse(String resource, String requestUrl, Model triples, InputStream input,
        String contentType) throws DataRetrievalException {
    log.debug("Request Successful to {0}", requestUrl);
    try {/*from w w w. j av  a 2 s . c om*/
        final Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(input);
        Element aux = doc.getRootElement();
        boolean ecuatoriano = false;
        for (Element element : aux.getChildren("entry", aux.getNamespace())) {
            if (affiliationEcuador(element.getChildren("affiliation", NAMESPACE_ATOM))) {
                ecuatoriano = true;
                break;
            }
        }
        if (ecuatoriano) {
            for (Element element : aux.getChildren("entry", aux.getNamespace())) {
                String abstractDoiParam = element.getChildText("doi", NAMESPACE_PRISM);
                String abstractURLParam = element.getChildText("url", NAMESPACE_PRISM);
                String abstractAbstractParam = element.getChildText("description", NAMESPACE_DC);
                List<String> creatorsList = new ArrayList<>();
                List<Element> creators = element.getChildren("author", NAMESPACE_ATOM);
                for (Element author : creators) {
                    creatorsList.add(author.getChildText("author-url", NAMESPACE_ATOM));
                }

                ClientConfiguration conf = new ClientConfiguration();
                LDClient ldClient = new LDClient(conf);
                if (abstractDoiParam != null) {
                    Model candidateModel = null;
                    String authorUrlResourceCleaned = URL_RESOURCE_PUBLICATION
                            .replace("DOIParam", abstractDoiParam).replace("apiKeyParam", apiKeyParam);

                    ClientResponse response = ldClient.retrieveResource(authorUrlResourceCleaned);
                    ValueFactory factory = ValueFactoryImpl.getInstance();
                    triples.add(
                            factory.createURI(
                                    "http://api.elsevier.com/content/author/author_id/" + authorIdParam),
                            FOAF.PUBLICATIONS, factory.createURI(abstractURLParam));
                    if (abstractAbstractParam != null) {
                        triples.add(factory.createStatement(factory.createURI(abstractURLParam),
                                factory.createURI("http://purl.org/ontology/bibo/abstract"),
                                factory.createLiteral(abstractAbstractParam)));
                    }
                    for (String uriCreator : creatorsList) {
                        triples.add(factory.createStatement(factory.createURI(abstractURLParam),
                                factory.createURI("http://purl.org/dc/terms/contributor"),
                                factory.createURI(uriCreator)));

                    }
                    Model authorModel = response.getData();
                    if (candidateModel == null) {
                        candidateModel = authorModel;
                    } else {
                        candidateModel.addAll(authorModel);
                    }
                    triples.addAll(candidateModel);

                }

            }
        }
    } catch (IOException e) {
        throw new DataRetrievalException("I/O error while parsing HTML response", e);
    } catch (JDOMException e) {
        throw new DataRetrievalException("could not parse XML response. It is not in proper XML format", e);
    }
    return Collections.emptyList();
}

From source file:org.apache.maven.artifact.repository.metadata.io.jdom.MetadataJDOMWriter.java

License:Apache License

/**
 * Method iteratePlugin./*from   w ww  . j ava  2  s . c om*/
 * 
 * @param counter
 * @param childTag
 * @param parentTag
 * @param list
 * @param parent
 */
protected void iteratePlugin(final IndentationCounter counter, final Element parent,
        final java.util.Collection list, final java.lang.String parentTag, final java.lang.String childTag) {
    final boolean shouldExist = (list != null) && (list.size() > 0);
    final Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        final Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        final IndentationCounter innerCount = new IndentationCounter(counter.getDepth() + 1);
        while (it.hasNext()) {
            final Plugin value = (Plugin) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updatePlugin(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}

From source file:org.apache.maven.artifact.repository.metadata.io.jdom.MetadataJDOMWriter.java

License:Apache License

/**
 * Method iterateSnapshotVersion.//  ww  w.j av  a 2 s  . c  o  m
 * 
 * @param counter
 * @param childTag
 * @param parentTag
 * @param list
 * @param parent
 */
protected void iterateSnapshotVersion(final IndentationCounter counter, final Element parent,
        final java.util.Collection list, final java.lang.String parentTag, final java.lang.String childTag) {
    final boolean shouldExist = (list != null) && (list.size() > 0);
    final Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        final Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        final IndentationCounter innerCount = new IndentationCounter(counter.getDepth() + 1);
        while (it.hasNext()) {
            final SnapshotVersion value = (SnapshotVersion) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updateSnapshotVersion(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}