Example usage for org.dom4j Element getNamespacePrefix

List of usage examples for org.dom4j Element getNamespacePrefix

Introduction

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

Prototype

String getNamespacePrefix();

Source Link

Document

Returns the namespace prefix of this element if one exists otherwise an empty String is returned.

Usage

From source file:net.unicon.toro.installer.tools.MergeConfiguration.java

License:Open Source License

private void outputElement(Element source, StringBuffer sb, int level) {
    List l = source.elements();/*from ww  w . j av  a 2 s.  c  om*/
    Iterator itr = l.iterator();
    while (itr.hasNext()) {
        Element ee = (Element) itr.next();
        for (int i = 0; i < level; i++) {
            sb.append('\t');
        }
        sb.append(ee.getName()).append(" - ").append(ee.getNamespacePrefix());
        sb.append(" - path: ").append(ee.getPath());
        sb.append('\n');
        if (ee.elements().size() > 0) {
            outputElement(ee, sb, level + 1);
        }
    }
}

From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java

License:Open Source License

public static String getPrefix(Element node) {
    String prefix = node.getNamespacePrefix();
    return prefix;

}

From source file:org.intalio.tempo.workflow.fds.dispatches.EscalateDispatcher.java

License:Open Source License

public Document dispatchRequest(Document request) throws InvalidInputFormatException {
    Namespace ns = new Namespace(NS_PREFIX, NS_URI);
    Element rootElement = request.getRootElement();
    userProcessNamespace = rootElement.getNamespaceURI();
    userProcessPrefix = rootElement.getNamespacePrefix();
    List nodes = DocumentHelper.createXPath("//*").selectNodes(request);
    for (int i = 0; i < nodes.size(); ++i) {
        Element element = (Element) nodes.get(i);
        element.remove(element.getNamespaceForURI(userProcessNamespace));
        element.setQName(new QName(element.getName(), ns));
    }/*from w  w  w . ja va 2s .  c  o  m*/

    rootElement.setQName(new QName("escalateTaskRequest", ns));
    // TODO: fix this in VC!
    return request;
}

From source file:org.jivesoftware.multiplexer.ServerPacketHandler.java

License:Open Source License

/**
 * Handles stanza sent from the server. Route stanzas are forwarded to clients. IQ
 * stanzas are used when the server wants to close a client connection or wants to
 * update the clients connections configurations. Stream errors with condition
 * <tt>system-shutdown</tt> indicate that the server is shutting down. The connection
 * manager will close existing client connections but will keep running.
 *
 * @param stanza stanza sent from the server.
 *///from   w w w.j  a v  a  2 s  .  co  m
public void handle(Element stanza) {
    String tag = stanza.getName();
    if ("route".equals(tag)) {
        // Process wrapped packets
        processRoute(stanza);
    } else if ("iq".equals(tag)) {
        String type = stanza.attributeValue("type");
        if ("set".equals(type)) {
            Element wrapper = stanza.element("session");
            if (wrapper != null) {
                String streamID = wrapper.attributeValue("id");
                // Check if the server is informing us that we need to close a session
                if (wrapper.element("close") != null) {
                    // Get the session that matches the requested stream ID
                    Session session = Session.getSession(streamID);
                    if (session != null) {
                        session.close();
                    }
                } else {
                    Log.warn("Invalid IQ stanza of type SET was received: " + stanza.asXML());
                }
            } else {
                Element configuration = stanza.element("configuration");
                if (configuration != null) {
                    obtainClientOptions(stanza, configuration);
                } else {
                    Log.warn("Invalid IQ stanza of type SET was received: " + stanza.asXML());
                }
            }
        } else if ("result".equals(type)) {
            if (Log.isDebugEnabled()) {
                Log.debug("IQ stanza of type RESULT was discarded: " + stanza.asXML());
            }
        } else if ("error".equals(type)) {
            // Close session if child element is CREATE
            Element wrapper = stanza.element("session");
            if (wrapper != null) {
                String streamID = wrapper.attributeValue("id");
                // Check if the server is informing us that we need to close a session
                if (wrapper.element("create") != null) {
                    // Get the session that matches the requested stream ID
                    Session session = Session.getSession(streamID);
                    if (session != null) {
                        session.close();
                    }
                } else {
                    if (Log.isDebugEnabled()) {
                        Log.debug("IQ stanza of type ERRROR was discarded: " + stanza.asXML());
                    }
                }
            } else {
                if (Log.isDebugEnabled()) {
                    Log.debug("IQ stanza of type ERRROR was discarded: " + stanza.asXML());
                }
            }
        } else {
            if (Log.isDebugEnabled()) {
                Log.debug("IQ stanza with invalid type was discarded: " + stanza.asXML());
            }
        }
    } else if ("error".equals(tag) && "stream".equals(stanza.getNamespacePrefix())) {
        if (stanza.element("system-shutdown") != null) {
            // Close connections to the server and client connections. The connection
            // manager will still be running and accepting client connections. New
            // connections to the server will be created on demand.
            connectionManager.getServerSurrogate().closeAll();
        } else {
            // Some stream error was sent from the server
            Log.warn("Server sent unexpected stream error: " + stanza.asXML());
        }
    } else {
        Log.warn("Unknown stanza type sent to Connection Manager: " + stanza.asXML());
    }
}

From source file:org.jivesoftware.openfire.multiplex.MultiplexerPacketDeliverer.java

License:Open Source License

private void handleUnprocessedPacket(Packet packet) {
    if (packet instanceof Message) {
        messageStrategy.storeOffline((Message) packet);
    } else if (packet instanceof Presence) {
        // presence packets are dropped silently
        //dropPacket(packet);
    } else if (packet instanceof IQ) {
        IQ iq = (IQ) packet;//from  w  ww .ja va  2 s .c  o  m
        // Check if we need to unwrap the packet
        Element child = iq.getChildElement();
        if (child != null && "session".equals(child.getName())
                && "http://jabber.org/protocol/connectionmanager".equals(child.getNamespacePrefix())) {
            Element send = child.element("send");
            if (send != null) {
                // Unwrap packet
                Element wrappedElement = (Element) send.elements().get(0);
                if ("message".equals(wrappedElement.getName())) {
                    handleUnprocessedPacket(new Message(wrappedElement));
                }
            }
        } else {
            // IQ packets are logged but dropped
            Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" + packet.toString());
        }
    }
}

From source file:org.jivesoftware.openfire.net.ComponentStanzaHandler.java

License:Open Source License

@Override
boolean processUnknowPacket(Element doc) throws UnauthorizedException {
    String tag = doc.getName();/*from  w ww  .j av  a2s.c o m*/
    if ("handshake".equals(tag)) {
        // External component is trying to authenticate
        if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) {
            session.close();
        }
        return true;
    } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
        session.close();
        return true;
    } else if ("bind".equals(tag)) {
        // Handle subsequent bind packets
        LocalComponentSession componentSession = (LocalComponentSession) session;
        // Get the external component of this session
        ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
        String initialDomain = component.getInitialSubdomain();
        String extraDomain = doc.attributeValue("name");
        String allowMultiple = doc.attributeValue("allowMultiple");
        if (extraDomain == null || "".equals(extraDomain)) {
            // No new bind domain was specified so return a bad_request error
            Element reply = doc.createCopy();
            reply.add(new PacketError(PacketError.Condition.bad_request).getElement());
            connection.deliverRawText(reply.asXML());
        } else if (extraDomain.equals(initialDomain)) {
            // Component is binding initial domain that is already registered
            // Send confirmation that the new domain has been registered
            connection.deliverRawText("<bind/>");
        } else if (extraDomain.endsWith(initialDomain)) {
            // Only accept subdomains under the initial registered domain
            if (allowMultiple != null && component.getSubdomains().contains(extraDomain)) {
                // Domain already in use so return a conflict error
                Element reply = doc.createCopy();
                reply.add(new PacketError(PacketError.Condition.conflict).getElement());
                connection.deliverRawText(reply.asXML());
            } else {
                try {
                    // Get the requested subdomain
                    String subdomain = extraDomain;
                    int index = extraDomain.indexOf(serverName);
                    if (index > -1) {
                        subdomain = extraDomain.substring(0, index - 1);
                    }
                    InternalComponentManager.getInstance().addComponent(subdomain, component);
                    // Send confirmation that the new domain has been registered
                    connection.deliverRawText("<bind/>");
                } catch (ComponentException e) {
                    Log.error("Error binding extra domain: " + extraDomain + " to component: " + component, e);
                    // Return internal server error
                    Element reply = doc.createCopy();
                    reply.add(new PacketError(PacketError.Condition.internal_server_error).getElement());
                    connection.deliverRawText(reply.asXML());
                }
            }
        } else {
            // Return forbidden error since we only allow subdomains of the intial domain
            // to be used by the same external component
            Element reply = doc.createCopy();
            reply.add(new PacketError(PacketError.Condition.forbidden).getElement());
            connection.deliverRawText(reply.asXML());
        }
        return true;
    }
    return false;
}

From source file:org.jivesoftware.openfire.net.MultiplexerStanzaHandler.java

License:Open Source License

@Override
boolean processUnknowPacket(Element doc) {
    String tag = doc.getName();//from w w w .ja va  2  s  .  c  o  m
    if ("route".equals(tag)) {
        // Process stanza wrapped by the route packet
        processRoute(new Route(doc));
        return true;
    } else if ("handshake".equals(tag)) {
        if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) {
            session.close();
        }
        return true;
    } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
        session.close();
        return true;
    }
    return false;
}

From source file:org.jivesoftware.openfire.net.ServerSocketReader.java

License:Open Source License

/**
 * Remote servers may send subsequent db:result packets so we need to process them in order
 * to validate new domains./*from  ww w .j av  a2s. c om*/
 *
 * @param doc the unknown DOM element that was received
 * @return true if the packet is a db:result packet otherwise false.
 */
@Override
protected boolean processUnknowPacket(Element doc) {
    // Handle subsequent db:result packets
    if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) {
        if (!((LocalIncomingServerSession) session).validateSubsequentDomain(doc)) {
            open = false;
        }
        return true;
    } else if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
        // The Receiving Server is reusing an existing connection for sending the
        // Authoritative Server a request for verification of a key
        ((LocalIncomingServerSession) session).verifyReceivedKey(doc);
        return true;
    }
    return false;
}

From source file:org.jivesoftware.openfire.net.ServerStanzaHandler.java

License:Open Source License

@Override
boolean processUnknowPacket(Element doc) throws UnauthorizedException {
    // Handle subsequent db:result packets
    if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) {
        if (!((LocalIncomingServerSession) session).validateSubsequentDomain(doc)) {
            throw new UnauthorizedException("Failed to validate domain when using piggyback.");
        }//from w  ww  .  ja  v a 2s  . co m
        return true;
    } else if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
        // The Receiving Server is reusing an existing connection for sending the
        // Authoritative Server a request for verification of a key
        ((LocalIncomingServerSession) session).verifyReceivedKey(doc);
        return true;
    }
    return false;
}

From source file:org.jivesoftware.openfire.server.ServerDialback.java

License:Open Source License

/**
 * Authenticates the Originating Server domain with the Receiving Server. Once the domain has
 * been authenticated the Receiving Server will start accepting packets from the Originating
 * Server.<p>/*from   www.  j ava2s . co  m*/
 *
 * The Receiving Server will connect to the Authoritative Server to verify the dialback key.
 * Most probably the Originating Server machine will be the Authoritative Server too.
 *
 * @param socketReader the reader to use for reading the answer from the Receiving Server.
 * @param domain the domain to authenticate.
 * @param hostname the hostname of the remote server (i.e. Receiving Server).
 * @param id the stream id to be used for creating the dialback key.
 * @return true if the Receiving Server authenticated the domain with the Authoritative Server.
 */
public boolean authenticateDomain(OutgoingServerSocketReader socketReader, String domain, String hostname,
        String id) {
    String key = AuthFactory.createDigest(id, getSecretkey());
    Log.debug("ServerDialback: OS - Sent dialback key to host: " + hostname + " id: " + id + " from domain: "
            + domain);

    synchronized (socketReader) {
        // Send a dialback key to the Receiving Server
        StringBuilder sb = new StringBuilder();
        sb.append("<db:result");
        sb.append(" from=\"").append(domain).append("\"");
        sb.append(" to=\"").append(hostname).append("\">");
        sb.append(key);
        sb.append("</db:result>");
        connection.deliverRawText(sb.toString());

        // Process the answer from the Receiving Server
        try {
            while (true) {
                Element doc = socketReader.getElement(RemoteServerManager.getSocketTimeout(),
                        TimeUnit.MILLISECONDS);
                if (doc == null) {
                    Log.debug("ServerDialback: OS - Time out waiting for answer in validation from: " + hostname
                            + " id: " + id + " for domain: " + domain);
                    return false;
                } else if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) {
                    boolean success = "valid".equals(doc.attributeValue("type"));
                    Log.debug("ServerDialback: OS - Validation " + (success ? "GRANTED" : "FAILED") + " from: "
                            + hostname + " id: " + id + " for domain: " + domain);
                    return success;
                } else {
                    Log.warn("ServerDialback: OS - Ignoring unexpected answer in validation from: " + hostname
                            + " id: " + id + " for domain: " + domain + " answer:" + doc.asXML());
                }
            }
        } catch (InterruptedException e) {
            Log.debug("ServerDialback: OS - Validation FAILED from: " + hostname + " id: " + id
                    + " for domain: " + domain, e);
            return false;
        }
    }
}