Search in sources :

Example 11 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class SearchPlugin method replyDisabled.

/**
	 * Constructs a IQ result stanza, based on the request stanza that is provided as an argument. The stanza tells the recipient that this
	 * service is currently unavailable.
	 * 
	 * @param packet
	 *            The request IQ stanza to which a result will be returned.
	 * @return A result stanza, telling the user that this service is unavailable.
	 */
private static IQ replyDisabled(IQ packet) {
    IQ replyPacket = IQ.createResultIQ(packet);
    Element reply = replyPacket.setChildElement("query", NAMESPACE_JABBER_IQ_SEARCH);
    final DataForm unavailableForm = new DataForm(DataForm.Type.cancel);
    unavailableForm.setTitle(LocaleUtils.getLocalizedString("advance.user.search.title", "search"));
    unavailableForm.addInstruction(LocaleUtils.getLocalizedString("search.service_unavailable", "search"));
    reply.add(unavailableForm.getElement());
    return replyPacket;
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm)

Example 12 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class SearchPlugin method extractSearchQuery.

/**
	 * This utilty method extracts the search query from the request. A query is defined as a set of key->value pairs, where the key denotes
	 * a search field, and the value contains the value that was filled out by the user for that field.
	 * 
	 * The query can be specified in one of two ways. The first way is a query is formed is by filling out any of the the standard search
	 * fields. The other search method makes use of extended data forms. Search queries that are supplied to this
	 * {@link #extractSearchQuery(Element)} that make use of this last method get forwarded to {@link #extractExtendedSearchQuery(Element)}.
	 * 
	 * @param incomingForm
	 *            The form from which to extract the query
	 * @return The search query for a particular user search request.
	 */
@SuppressWarnings("unchecked")
private Hashtable<String, String> extractSearchQuery(Element incomingForm) {
    if (incomingForm.element(QName.get("x", "jabber:x:data")) != null) {
        // forward the request.
        return extractExtendedSearchQuery(incomingForm);
    }
    final Hashtable<String, String> searchList = new Hashtable<String, String>();
    // since not all clients request which fields are available for
    // searching attempt to match submitted fields with available search
    // fields
    Iterator<Element> iter = incomingForm.elementIterator();
    while (iter.hasNext()) {
        Element element = iter.next();
        String name = element.getName();
        if (fieldLookup.containsKey(name)) {
            // make best effort to map the fields submitted by
            // the client to those that Openfire can search
            reverseFieldLookup.put(fieldLookup.get(name), name);
            searchList.put(fieldLookup.get(name), element.getText());
        }
    }
    return searchList;
}
Also used : Hashtable(java.util.Hashtable) Element(org.dom4j.Element)

Example 13 with Element

use of org.dom4j.Element in project Openfire by igniterealtime.

the class SipComponent method processIQ.

private void processIQ(IQ iq) {
    IQ reply = IQ.createResultIQ(iq);
    String namespace = iq.getChildElement().getNamespaceURI();
    Element childElement = iq.getChildElement().createCopy();
    reply.setChildElement(childElement);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElement.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "SIP Controller");
            childElement.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElement.addElement("feature").addAttribute("var", "http://www.jivesoftware.com/protocol/sipark");
        }
    } else if (NAMESPACE.equals(namespace)) {
        if (iq.getTo().getNode() == null && iq.getFrom() != null) {
            SipAccount sipAccount = SipAccountDAO.getAccountByUser(iq.getFrom().toBareJID().split("@")[0]);
            if (iq.getChildElement().element("status") == null) {
                if (sipAccount != null && sipAccount.isEnabled()) {
                    // There is a SIP mapping for this user so return mapping information
                    Element registration = childElement.addElement("registration");
                    registration.addElement("jid").setText(sipAccount.getUsername() + "@" + componentManager.getServerName());
                    registration.addElement("username").setText(sipAccount.getSipUsername());
                    registration.addElement("authUsername").setText(sipAccount.getAuthUsername());
                    registration.addElement("displayPhoneNum").setText(sipAccount.getDisplayName());
                    registration.addElement("password").setText(sipAccount.getPassword());
                    registration.addElement("server").setText(sipAccount.getServer());
                    registration.addElement("stunServer").setText(sipAccount.getStunServer());
                    registration.addElement("stunPort").setText(sipAccount.getStunPort());
                    registration.addElement("useStun").setText(String.valueOf(sipAccount.isUseStun()));
                    registration.addElement("voicemail").setText(sipAccount.getVoiceMailNumber());
                    registration.addElement("enabled").setText(String.valueOf(sipAccount.isEnabled()));
                    registration.addElement("outboundproxy").setText(sipAccount.getOutboundproxy());
                    registration.addElement("promptCredentials").setText(String.valueOf(sipAccount.isPromptCredentials()));
                } else {
                    // No SIP mapping was found
                    reply.getChildElement().addAttribute("type", "unregistered");
                }
            } else {
                if (sipAccount != null) {
                    Element status = iq.getChildElement().element("status");
                    if (!status.getTextTrim().equals("")) {
                        sipAccount.setStatus(SipRegisterStatus.valueOf(status.getTextTrim()));
                        try {
                            SipAccountDAO.update(sipAccount);
                        } catch (SQLException e) {
                            Log.error(e.getMessage(), e);
                        }
                    }
                }
            }
        }
    } else {
        // Answer an error since the server can't handle the requested
        // namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
    Log.debug("PACKET SENT: " + reply.toXML());
}
Also used : SQLException(java.sql.SQLException) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) SQLException(java.sql.SQLException)

Example 14 with Element

use of org.dom4j.Element in project hibernate-orm by hibernate.

the class RevisionInfoConfiguration method generateRevisionInfoRelationMapping.

private Element generateRevisionInfoRelationMapping() {
    final Document document = globalCfg.getEnversService().getXmlHelper().getDocumentFactory().createDocument();
    final Element revRelMapping = document.addElement("key-many-to-one");
    revRelMapping.addAttribute("type", revisionPropType);
    revRelMapping.addAttribute("class", revisionInfoEntityName);
    if (revisionPropSqlType != null) {
        // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
        MetadataTools.addColumn(revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false);
    }
    return revRelMapping;
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 15 with Element

use of org.dom4j.Element in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method addRevisionType.

void addRevisionType(Element anyMapping, Element anyMappingEnd, boolean isKey) {
    final Element revTypeProperty = MetadataTools.addProperty(anyMapping, verEntCfg.getRevisionTypePropName(), verEntCfg.getRevisionTypePropType(), true, isKey);
    revTypeProperty.addAttribute("type", "org.hibernate.envers.internal.entities.RevisionTypeType");
    // Adding the end revision, if appropriate
    addEndRevision(anyMappingEnd);
}
Also used : Element(org.dom4j.Element)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64