Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

In this page you can find the example usage for org.dom4j QName QName.

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:de.innovationgate.webgate.api.query.rss.WGDocumentImplRSS1.java

License:Open Source License

public Object getMetaData(String type)
        throws WGSystemException, WGIllegalArgumentException, WGBackendException {

    if (type.equals(WGContent.META_TITLE)) {
        return this.item.elementText("title");
    } else if (type.equals(WGContent.META_VIRTUAL_LINK)) {
        return this.item.elementText("link");
    } else if (type.equals(WGContent.META_VIRTUAL_LINK_TYPE)) {
        return WGContent.VIRTUALLINKTYPE_EXTERNAL;
    } else if (type.equals(WGDocument.META_CREATED) || type.equals(WGDocument.META_LASTMODIFIED)) {
        try {/*from  w w  w.ja  va2s  .  co m*/
            return this.DATE_FORMATTER.parse(this.item.elementText(new QName("date", dcns)));
        } catch (ParseException e) {
            return new Date();
        }
    } else if (type.equals(WGContent.META_AUTHOR)) {
        return this.item.elementText(new QName("creator", dcns));
    } else if (type.equals(WGContent.META_STRUCTENTRY)) {
        String key = this.item.elementText("guid");
        if (key == null || key.equals("")) {
            key = this.key;
        }
        return key;
    } else if (type.equals(WGContent.META_KEYWORDS)) {
        return this.item.elements("category");
    } else if (type.equals(WGContent.META_LANGUAGE)) {
        String lang = this.channel.elementText(new QName("language", dcns));
        if (lang == null || lang.equals("")) {
            lang = "uni";
        } else if (lang.indexOf("-") != -1) {
            lang = lang.substring(0, lang.indexOf("-"));
        }
        return lang;
    } else {
        return super.getMetaData(type);
    }

}

From source file:de.innovationgate.webgate.api.query.rss.WGResultSetImpl.java

License:Open Source License

private List getItemsList() {

    if (this.itemsList == null) {

        if (isRSS1) {
            this.itemsList = this.doc.getRootElement().elements(new QName("item", Namespace.get(NS_RSS1_PURL)));
            if (this.itemsList.size() == 0) {
                this.itemsList = this.doc.getRootElement()
                        .elements(new QName("item", Namespace.get(NS_RSS1_NETSCAPE)));
            }// w  ww .ja  v  a  2s.co  m
        } else {
            this.itemsList = this.doc.selectNodes("//item");
        }
    }
    return this.itemsList;

}

From source file:de.innovationgate.webgate.api.query.rss.WGResultSetImpl.java

License:Open Source License

private Element getChannel() {

    if (this.channel == null) {
        if (isRSS1) {
            this.channel = (Element) this.doc.getRootElement()
                    .element(new QName("channel", Namespace.get(NS_RSS1_PURL)));
            if (this.channel == null) {
                this.channel = (Element) this.doc.getRootElement()
                        .element(new QName("channel", Namespace.get(NS_RSS1_NETSCAPE)));
            }/*from   w  w w .j  a  va  2 s.c  o  m*/
        } else {
            this.channel = (Element) this.doc.selectSingleNode("//channel");
        }
    }
    return this.channel;
}

From source file:de.innovationgate.wgpublisher.webtml.actions.TMLAction.java

License:Open Source License

public static TMLAction buildActionFromScriptModule(WGCSSJSModule mod, ObjectStrategy defaultObjectStrategy)
        throws TMLActionException, WGAPIException {

    String code = mod.getCode().trim();
    TMLAction action = null;//from  w  w w .ja va2 s .  c  om

    // See if code is surrounded by <tml:action> Tag. Parse it out to get
    // flags
    if (code.startsWith("<tml:action")) {
        List<String> codelines = WGUtils.deserializeCollection(code, "\n");
        if (codelines.size() < 2) {
            throw new TMLActionException(
                    "Too few lines for action script module. A script module that begins with <tml:action> must a) have this tag on a separate line and b) end with </tml:action> on a separate line");
        }

        // Take first and last line of code and try to parse them as XML
        String actionXML = ACTION_XML_PREFIX + ((String) codelines.get(0))
                + ((String) codelines.get(codelines.size() - 1)) + ACTION_XML_SUFFIX;
        String actionCode = "";
        if (codelines.size() >= 3) {
            actionCode = WGUtils.serializeCollection(codelines.subList(1, codelines.size() - 1), "\n");
        }

        // Parse out action flags
        boolean master = false;
        boolean async = false;
        boolean debounce = true;
        int timeout = RhinoExpressionEngine.DEFAULT_SCRIPTTIMEOUT;
        try {

            Document actionDOM = DocumentHelper.parseText(actionXML);
            Element actionElement = actionDOM.getRootElement()
                    .element(new QName("action", new Namespace("tml", "urn:webtml")));
            master = WGUtils.stringToBoolean(actionElement.attributeValue("master", "false"));
            async = WGUtils.stringToBoolean(actionElement.attributeValue("async", "false"));
            debounce = WGUtils.stringToBoolean(actionElement.attributeValue("debounce", "true"));
            try {
                timeout = Integer.parseInt(actionElement.attributeValue("timeout",
                        new Integer(RhinoExpressionEngine.DEFAULT_SCRIPTTIMEOUT).toString()));
            } catch (NumberFormatException e) {
                throw new TMLActionException(
                        "Unparseable action timeout: " + actionElement.attributeValue("timeout"));
            }
            action = new TMLAction(actionCode, master, async, debounce, ORIGIN_SCRIPT_MODULE);
            action.setTimeout(timeout);
        } catch (DocumentException e) {
            throw new TMLActionException("Unable to build action from script module", e);
        }
    }

    // No tag surrounds the action code. Take the code unmodified
    else {
        action = new TMLAction(code, false, false, true, ORIGIN_SCRIPT_MODULE);
    }

    if (action != null) {
        action.setDesignReference(new DesignResourceReference(mod));
        action.setModuleDate(mod.getLastModified());
        action.setID(action.getModuleDatabase() + "/" + action.getModuleName());

        // Determine object strategy: May be modified by strategy determined on module.
        ObjectStrategy objectStrategy = defaultObjectStrategy;
        String determinedObjectStrategyStr = (String) mod
                .getExtensionData(RhinoExpressionEngine.EXTDATA_OBJECTSTRATEGY);
        if (determinedObjectStrategyStr != null) {
            objectStrategy = ObjectStrategy.valueOf(determinedObjectStrategyStr);
        }
        action.setObjectStrategy(objectStrategy);

        // Determine name of eventually included object from original filename
        String sourceFileName = mod.getSourceFileName();
        if (sourceFileName != null) {
            String objectName = DesignDirectory.getTMLScriptObjectName(sourceFileName);
            action.setObjectName(objectName);
        }

    }
    return action;

}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Roster.java

License:Open Source License

/**
 * Adds a new item to the roster. If the roster packet already contains an item
 * using the same JID, the information in the existing item will be overwritten
 * with the new information.<p>/*from w ww  . j a  va2s  .c o m*/
 *
 * The XMPP specification recommends that if the roster item is associated with another
 * instant messaging user (human), that the JID be in bare form (e.g. user@domain).
 * Use the {@link JID#toBareJID() toBareJID()} method for a bare JID.
 *
 * @param jid the JID.
 * @param name the nickname.
 * @param ask the ask type.
 * @param subscription the subscription type.
 * @param groups a Collection of groups.
 * @return the newly created item.
 */
@SuppressWarnings("unchecked")
public Item addItem(JID jid, String name, Ask ask, Subscription subscription, Collection<String> groups) {
    if (jid == null) {
        throw new NullPointerException("JID cannot be null");
    }
    if (subscription == null) {
        throw new NullPointerException("Subscription cannot be null");
    }
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query == null) {
        query = element.addElement("query", "jabber:iq:roster");
    }
    Element item = null;
    for (Iterator<Element> i = query.elementIterator("item"); i.hasNext();) {
        Element el = i.next();
        if (el.attributeValue("jid").equals(jid.toString())) {
            item = el;
        }
    }
    if (item == null) {
        item = query.addElement("item");
    }
    item.addAttribute("jid", jid.toBareJID());
    item.addAttribute("name", name);
    if (ask != null) {
        item.addAttribute("ask", ask.toString());
    }
    item.addAttribute("subscription", subscription.toString());
    // Erase existing groups in case the item previously existed.
    for (Iterator<Element> i = item.elementIterator("group"); i.hasNext();) {
        item.remove(i.next());
    }
    // Add in groups.
    if (groups != null) {
        for (String group : groups) {
            item.addElement("group").setText(group);
        }
    }
    return new Item(jid, name, ask, subscription, groups);
}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Roster.java

License:Open Source License

/**
 * Removes an item from this roster./*from   w ww  .  j a  va2  s  . c  o  m*/
 *
 * @param jid the JID of the item to remove.
 */
@SuppressWarnings("unchecked")
public void removeItem(JID jid) {
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query != null) {
        for (Iterator<Element> i = query.elementIterator("item"); i.hasNext();) {
            Element item = i.next();
            if (item.attributeValue("jid").equals(jid.toString())) {
                query.remove(item);
                return;
            }
        }
    }
}

From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Roster.java

License:Open Source License

/**
 * Returns an unmodifiable copy of the {@link Item Items} in the roster packet.
 *
 * @return an unmodifable copy of the {@link Item Items} in the roster packet.
 *//*from www  . j  a  v  a  2s  .c om*/
@SuppressWarnings("unchecked")
public Collection<Item> getItems() {
    Collection<Item> items = new ArrayList<Item>();
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query != null) {
        for (Iterator<Element> i = query.elementIterator("item"); i.hasNext();) {
            Element item = i.next();
            String jid = item.attributeValue("jid");
            String name = item.attributeValue("name");
            String ask = item.attributeValue("ask");
            String subscription = item.attributeValue("subscription");
            Collection<String> groups = new ArrayList<String>();
            for (Iterator<Element> j = item.elementIterator("group"); j.hasNext();) {
                Element group = j.next();
                groups.add(group.getText().trim());
            }
            Ask askStatus = ask == null ? null : Ask.valueOf(ask);
            Subscription subStatus = subscription == null ? null : Subscription.valueOf(subscription);
            items.add(new Item(new JID(jid), name, askStatus, subStatus, groups));
        }
    }
    return Collections.unmodifiableCollection(items);
}

From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java

private Identifier createOrLookupUser(TripleStore es, String user) throws TripleStoreException, IOException {
    Identifier uid = null;/*w w w. j av  a2 s.c  o m*/

    if (!StringUtils.isBlank(user)) {
        // lookup the user from the event triplestore
        String query = "SELECT ?sub WHERE { ?sub <" + rdfNS + "type> ?type . ?type <" + rdfNS
                + "label> '\"mads:PersonalName\"' . " + "?sub <" + madsNS
                + "authoritativeLabel> ?val . FILTER ( lcase( ?val ) =  lcase('\"" + user + "\"'))}";
        BindingIterator it = es.sparqlSelect(query);
        if (it.hasNext())
            uid = Identifier.publicURI(it.nextBinding().get("sub"));
        else {
            // mint ARK for the new user
            String minterURL = idMinters.get(minterDefault) + "1";
            String userARK = HttpUtil.get(minterURL);
            userARK = userARK.replaceAll(".*/", "").trim();
            uid = userID = Identifier.publicURI(idNS + userARK);

            Namespace madsNamespace = new Namespace("mads", madsNS);
            Namespace rdfNamespace = new Namespace("rdf", rdfNS);
            Element rdf = createRdfRootElement();
            Element name = rdf.addElement(new QName("PersonalName", madsNamespace));
            name.addAttribute(new QName("about", rdfNamespace), uid.getId());
            addTextElement(name, "authoritativeLabel", madsNamespace, user);
            Element el = addElement(name, "elementList", madsNamespace);
            el.addAttribute(new QName("parseType", rdfNamespace), "Collection");
            Element ne = addElement(el, "NameElement", madsNamespace);
            addTextElement(ne, "elementValue", madsNamespace, user);

            // add the user record to the event triplestore
            InputStream in = new ByteArrayInputStream(rdf.getDocument().asXML().getBytes());
            Map info = objectEdit(userARK, true, in, null, null, null, null, es, es, null);
            in.close();
            int statusCode = (int) info.get("statusCode");
            if (statusCode != 201)
                throw new TripleStoreException(
                        "Error status code" + statusCode + ": " + (String) info.get("message"));

        }
    }
    return uid;
}

From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java

private static Element addElement(Branch parent, String elemName, Namespace ns) {
    return parent.addElement(new QName(elemName, ns));
}

From source file:edu.ucsd.library.dams.jhove.MyJhoveBase.java

License:Open Source License

public static void removeNS(Element elem) {
    elem.remove(elem.getNamespace());//w  ww .  j av  a 2  s.c o m
    elem.setQName(new QName(elem.getQName().getName(), Namespace.NO_NAMESPACE));
    // fix children
    List children = elem.elements();
    for (int i = 0; i < children.size(); i++) {
        Element child = (Element) children.get(i);
        removeNS(child);
    }
}