Example usage for org.dom4j QName get

List of usage examples for org.dom4j QName get

Introduction

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

Prototype

public static QName get(String qualifiedName, String uri) 

Source Link

Usage

From source file:com.cladonia.schema.XMLSchema.java

License:Open Source License

private void getNames(SchemaModel model, Vector elementNames, Vector attributeNames, String parentElementName,
        Hashtable elementChildren, Hashtable elementAttributes) {
    Vector models = model.getModels();

    if (models != null) {
        for (int i = 0; i < models.size(); i++) {
            getNames((SchemaModel) models.elementAt(i), elementNames, attributeNames, parentElementName,
                    elementChildren, elementAttributes);
        }/*from  w  w w . j  a  va 2  s  .c  o m*/
    }

    Vector elements = model.getElements();
    Vector childElements = (Vector) elementChildren.get(parentElementName);

    if (childElements == null) {
        childElements = new Vector();
        elementChildren.put(parentElementName, childElements);
    }

    if (elements != null) {
        for (int i = 0; i < elements.size(); i++) {
            SchemaElement element = ((SchemaElement) elements.elementAt(i));
            boolean isGlobal = element.isReference();

            if (isGlobal) {
                // resolve the reference to be used here but don't 
                // continue with it...
                element.resolveReference();
            }

            //            System.out.println( ">>> XMLSchema.getNames()");      
            Vector subs = element.getSubstituteElements();
            //            System.out.println( "<<< XMLSchema.getNames()");      

            if (subs.size() > 0) {
                for (int j = 0; j < subs.size(); j++) {
                    SchemaElement sub = (SchemaElement) subs.elementAt(j);

                    QName ename = QName.get(sub.getName(), sub.getNamespace());
                    if (!childElements.contains(ename)) {
                        //                     System.out.println( "XMLSchema add substituteElement ["+sub.getName()+"]");      
                        childElements.addElement(ename);
                    }
                }
            } else {
                QName ename = QName.get(element.getName(), element.getNamespace());
                if (!childElements.contains(ename)) {
                    childElements.addElement(ename);
                }
            }

            if (!isGlobal) {
                // the element is part of the global elements ...
                getNames(element, elementNames, attributeNames, element.getName(), elementChildren,
                        elementAttributes);
            }
        }
    }
}

From source file:com.flaptor.hounder.searcher.OpenSearch.java

License:Apache License

/**
 * Creates a OpenSearch's compatible DOM document.
 * The generated dom contains only valid xml characters (infringing chars are removed).
 * Compliant with OpenSearch 1.0 with most of the Nutch 0.8.1 extensions.
 * @param baseUrl the url of the webapp/*from   w ww.  ja  v  a  2s .c  o  m*/
 * @param htmlSearcher the name of the component (servlet/jsp) that returns the search results in an HTML page
 * @param opensearchSearcher the name of the component (servlet/jsp) that returns the search results in an OpenSearch RSS page
 * @param extraParams the parameters present in the request, not passed explicitly (such as sort, reverse, etc.)
 * @param queryString the query string, as entered by the user
 * @param start the offset of the first result
 * @param count the number of results requested (the actual number of results found may be smaller)
 * @param sr the SearchResults structure containing the result of performing the query
 * @return a DOM document
 * <br>An empty sr argument means that no results were found.
 */
public static final Document buildDom_1_0(String baseUrl, String htmlSearcher, String opensearchSearcher,
        String extraParams, String queryString, int start, int count, GroupedSearchResults sr, int status,
        String statusMessage, boolean useXslt) {

    String encodedQuery = null;
    try {
        encodedQuery = URLEncoder.encode(queryString, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // Should never happen!
        encodedQuery = "";
    }
    Document dom = DocumentHelper.createDocument();
    if (useXslt) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("type", "text/xsl");
        map.put("href", xsltPath);
        dom.addProcessingInstruction("xml-stylesheet", map);
    }

    Namespace opensearchNs = DocumentHelper.createNamespace("opensearch", XMLNS_A9_OPENSEARCH_1_0);
    Namespace hounderNs = DocumentHelper.createNamespace("hounder", XMLNS_HOUNDER_OPENSEARCH_1_0);
    Element root;
    Element channel;
    if (!useXslt) {
        root = dom.addElement("rss").addAttribute("version", "2.0");
        channel = root.addElement("channel");
    } else {
        channel = dom.addElement("searchResults");
        root = channel;
    }
    root.add(opensearchNs);
    root.add(hounderNs);

    channel.addElement("title").addText(titlePrefix + " " + DomUtil.filterXml(queryString));
    channel.addElement("link")
            .addText(baseUrl + "/" + htmlSearcher + "?query=" + encodedQuery + "&start=" + start + extraParams);
    channel.addElement("description").addText(descPrefix + " " + DomUtil.filterXml(queryString));
    channel.addElement(QName.get("totalResults", opensearchNs))
            .addText(Integer.toString(sr.totalGroupsEstimation()));
    channel.addElement(QName.get("startIndex", opensearchNs)).addText(Integer.toString(start));
    channel.addElement(QName.get("itemsPerPage", opensearchNs)).addText(Integer.toString(count));
    channel.addElement(QName.get("query", hounderNs)).addText(DomUtil.filterXml(queryString));
    AQuery suggestedQuery = sr.getSuggestedQuery();
    if (null != suggestedQuery) {
        channel.addElement(QName.get("suggestedQuery", hounderNs))
                .addText(DomUtil.filterXml(suggestedQuery.toString()));
    }
    channel.addElement(QName.get("status", hounderNs)).addText(Integer.toString(status));
    channel.addElement(QName.get("statusDesc", hounderNs)).addText(statusMessage);
    if (sr.lastDocumentOffset() > 0) {
        channel.addElement(QName.get("nextPage", hounderNs)).addText(baseUrl + "/" + opensearchSearcher
                + "?query=" + encodedQuery + "&start=" + (sr.lastDocumentOffset()) + extraParams);
    }

    for (int i = 0; i < sr.groups(); i++) {
        Vector<org.apache.lucene.document.Document> docs = sr.getGroup(i).last();
        Element parent = null;
        for (int j = 0; j < docs.size(); j++) {
            org.apache.lucene.document.Document doc = sr.getGroup(i).last().get(j);
            if (0 == j) {// j=0 is head of group. j>0 is tail
                parent = createAndAddElement(doc, channel, hounderNs);
            } else {
                createAndAddElement(doc, parent, hounderNs);
            }

        }
    }
    return dom;
}

From source file:com.flaptor.hounder.searcher.OpenSearch.java

License:Apache License

private static Element createAndAddElement(org.apache.lucene.document.Document doc, Element parent,
        Namespace hounderNs) {//from w w  w.j  a va2  s .  c om
    String link = StringUtil.nullToEmpty(doc.get(linkField)).trim();
    String description = StringUtil.nullToEmpty(doc.get(descField)).trim();
    String title = StringUtil.nullToEmpty(doc.get(titleField)).trim();
    if ("".equals(title)) {
        title = link;
    }

    Element item = parent.addElement("item");
    item.addElement("title").addText(DomUtil.filterXml(title));
    item.addElement("link").addText(linkPrefix + DomUtil.filterXml(link));
    String desc = DomUtil.filterXml(description);
    System.out.println("===================================================================================");
    System.out.println("description: " + description);
    System.out.println("-----------------------------------------------------------------------------------");
    System.out.println("desc: " + desc);
    System.out.println("===================================================================================");
    item.addElement("description").addText(desc);

    for (Iterator iter = doc.getFields().iterator(); iter.hasNext();) {
        Field f = (Field) iter.next();
        if (fieldsToShow.contains(f.name())) {
            item.addElement(QName.get(f.name(), hounderNs)).addText(DomUtil.filterXml(f.stringValue()));
        }
    }
    return item;
}

From source file:com.flaptor.util.parser.HtmlParser.java

License:Apache License

private void removeNamespace(Element elem) {
    if (null != elem) {
        elem.remove(elem.getNamespace());
        elem.setQName(QName.get(elem.getName(), Namespace.NO_NAMESPACE));
        removeNamespace(elem.content());
    }//from  ww  w .  j  a  v a2 s.co m
}

From source file:com.hand.hemp.push.server.xmpp.handler.IQAuthHandler.java

License:Open Source License

/**
 * Constructor.//  w  w  w .j a v a 2s. c  om
 */
public IQAuthHandler() {
    clientService = ServiceLocator.getClientService();
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    if (AuthManager.isPlainSupported()) {
        probeResponse.addElement("password");
    }
    if (AuthManager.isDigestSupported()) {
        probeResponse.addElement("digest");
    }
    probeResponse.addElement("resource");
}

From source file:com.hand.hemp.push.server.xmpp.handler.IQRegisterHandler.java

License:Open Source License

/**
 * Constructor./*from  ww w.  j  a  v a2s .c  om*/
 */
public IQRegisterHandler() {
    clientService = ServiceLocator.getClientService();
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    probeResponse.addElement("password");
    probeResponse.addElement("email");
    probeResponse.addElement("name");
}

From source file:com.hand.hemp.push.server.xmpp.push.NotificationManager.java

License:Open Source License

/**
 * Creates a new notification IQ and returns it.
 *
 * @param apiKey//from w  w  w  .  ja va 2  s  .c om
 * @param title
 * @param message
 * @param uri
 * @return
 */
private IQ createNotificationIQ(String apiKey, String title, String message, String uri) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    // String id = String.valueOf(System.currentTimeMillis());

    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apiKey);
    if (title == null) {
        title = " ";
    }
    notification.addElement("title").setText(title);
    notification.addElement("message").setText(message);

    if (uri == null) {
        uri = " ";
    }
    notification.addElement("uri").setText(uri);

    IQ iq = new IQ();
    iq.setType(IQ.Type.set);
    iq.setChildElement(notification);

    return iq;
}

From source file:com.jpsycn.wggl.mobile.androidpn.xmpp.push.NotificationManager.java

License:Open Source License

/**
 * Creates a new notification IQ and returns it.
 *//*ww w. jav a 2s. c o  m*/
private IQ createNotificationIQ(String apiKey, String title, String message, String uri) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    // String id = String.valueOf(System.currentTimeMillis());

    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apiKey);
    notification.addElement("title").setText(title);
    notification.addElement("message").setText(message);
    notification.addElement("uri").setText(null == uri ? "" : uri);

    IQ iq = new IQ();
    iq.setType(IQ.Type.set);
    iq.setChildElement(notification);

    return iq;
}

From source file:com.sun.tools.xjc.reader.dtd.bindinfo.DOM4JLocator.java

License:Open Source License

/** Sets the location information to a specified element. */
public static void setLocationInfo(Element e, Locator loc) {
    e.addAttribute(QName.get(systemId, locationNamespace), loc.getSystemId());
    e.addAttribute(QName.get(column, locationNamespace), Integer.toString(loc.getLineNumber()));
    e.addAttribute(QName.get(line, locationNamespace), Integer.toString(loc.getColumnNumber()));
}

From source file:com.sun.tools.xjc.reader.dtd.bindinfo.DOM4JLocator.java

License:Open Source License

/**
 * Gets the location information from an element.
 * //  ww w . jav  a2s .com
 * <p>
 * For this method to work, the setLocationInfo method has to be
 * called before.
 */
public static Locator getLocationInfo(final Element e) {
    if (e.attribute(QName.get(systemId, locationNamespace)) == null)
        return null; // no location information

    return new Locator() {
        public int getLineNumber() {
            return Integer.parseInt(e.attributeValue(QName.get(line, locationNamespace)));
        }

        public int getColumnNumber() {
            return Integer.parseInt(e.attributeValue(QName.get(column, locationNamespace)));
        }

        public String getSystemId() {
            return e.attributeValue(QName.get(systemId, locationNamespace));
        }

        // we are not interested in PUBLIC ID.
        public String getPublicId() {
            return null;
        }
    };
}