Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java

License:Open Source License

public String getParameterValue(String name) {
    if (null != this.elements) {
        for (Element elts : this.elements) {
            if (name.equalsIgnoreCase(elts.attributeValue("name"))) {
                return elts.attributeValue("value");
            }/*w  ww  . jav a  2  s.  c o  m*/
        }
        return null;
    } else {
        return null;
    }
}

From source file:com.devoteam.srit.xmlloader.gui.model.ModelEditableParameters.java

License:Open Source License

public void fill(List<Element> elts) {
    this.clear();
    this.modelElements = elts;

    for (Element element : elts) {
        String[] line = new String[3];

        //TODO: check name is unique in jTable column 0
        line[0] = element.attributeValue("name");
        if (null != element.attributeValue("description")) {
            line[1] = element.attributeValue("description");
        }//from   w w w .  j a  va 2s. c  om
        line[2] = element.attributeValue("value");

        addRow(line);
    }
}

From source file:com.devoteam.srit.xmlloader.gui.model.ModelEditableParameters.java

License:Open Source License

public void apply(List<Element> elts) {
    Vector dataVector = this.getDataVector();
    for (Element element : elts) {
        Iterator<Vector> iterator = (Iterator<Vector>) dataVector.iterator();
        while (iterator.hasNext()) {
            Vector pair = iterator.next();
            if (element.attributeValue("name").equals((String) pair.get(0))) {
                element.attribute("value").setValue((String) pair.get(2));
            }//  w  w  w . ja  v  a  2s.  com
        }
    }
}

From source file:com.devoteam.srit.xmlloader.h323.h225cs.StackH225cs.java

License:Open Source License

@Override
public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception {

    MsgH225cs msgh225cs = new MsgH225cs(root);

    // OBSOLETE instanciates the listenpoint (compatibility with old grammar)
    String listenpointName = root.attributeValue("providerName");
    Listenpoint listenpoint = getListenpoint(listenpointName);
    if (listenpoint == null && listenpointName != null) {
        throw new ExecutionException("The listenpoint <name=" + listenpointName + "> does not exist");
    }/*from  www .  j a  v a2s .  c o m*/
    msgh225cs.setListenpoint(listenpoint);

    if (request != null && request && !msgh225cs.isRequest()) {
        throw new ExecutionException(
                "You specify to send a request using a <sendRequestXXX ...> tag, but the message you will send is not really a request.");
    }
    if (request != null && !request && msgh225cs.isRequest()) {
        throw new ExecutionException(
                "You specify to send a response using a <sendResponseXXX ...> tag, but the message you will send is not really a response.");
    }

    return msgh225cs;
}

From source file:com.devoteam.srit.xmlloader.h323.h225cs.StackH225cs.java

License:Open Source License

@Override
public Channel parseChannelFromXml(Element root, String protocol) throws Exception {
    String name = root.attributeValue("name");
    String localHost = root.attributeValue("localHost");
    String localPort = root.attributeValue("localPort");
    String remoteHost = root.attributeValue("remoteHost");
    String remotePort = root.attributeValue("remotePort");

    if (existsChannel(name)) {
        return getChannel(name);
    } else {//from   www  .j  a  v  a2  s  .co m
        if (null != localHost) {
            localHost = InetAddress.getByName(localHost).getHostAddress();
        } else {
            localHost = "0.0.0.0";
        }

        if (null != remoteHost) {
            remoteHost = InetAddress.getByName(remoteHost).getHostAddress();
        }

        return new ChannelH225cs(name, localHost, localPort, remoteHost, remotePort, protocol);
    }
}

From source file:com.devoteam.srit.xmlloader.http.StackHttp.java

License:Open Source License

/** Creates a channel specific to each Stack */
@Override//from   w  w  w . java 2 s .  c  om
public Channel parseChannelFromXml(Element root, String protocol) throws Exception {
    String channelName = root.attributeValue("name");

    //part to don't have regression
    if (channelName == null || channelName.equalsIgnoreCase("")) {
        channelName = root.attributeValue("connectionName");
    }

    String localHost = root.attributeValue("localHost");
    String localPort = root.attributeValue("localPort");
    String remoteUrl = root.attributeValue("remoteURL");
    String remoteHost = null;
    String remotePort = null;

    URI uri = null;
    try {
        uri = new URI(remoteUrl);
        remotePort = String.valueOf(uri.getPort());
    } catch (Exception e) {
        throw new ExecutionException("Can't create URI from : " + remoteUrl, e);
    }

    boolean secure = false;
    String scheme = uri.getScheme();
    if (scheme == null) {
        scheme = getConfig().getString("client.DEFAULT_PROTOCOL");
    }

    if (scheme.equalsIgnoreCase("https")) {
        secure = true;
    } else {
        secure = false;
    }

    remoteHost = Utils.formatIPAddress(uri.getHost());

    if (uri.getPort() > 0) {
        remotePort = String.valueOf(uri.getPort());
    } else {
        if (secure) {
            remotePort = getConfig().getString("client.DEFAULT_HTTPS_PORT", "443");
        } else {
            remotePort = getConfig().getString("client.DEFAULT_HTTP_PORT", "80");
        }
    }

    if (existsChannel(channelName)) {
        return getChannel(channelName);
    } else {
        if (getConfig().getBoolean("USE_NIO")) {
            return new NIOChannelHttp(channelName, localHost, localPort, remoteHost, remotePort, protocol,
                    secure);
        } else {
            return new BIOChannelHttp(channelName, localHost, localPort, remoteHost, remotePort, protocol,
                    secure);
        }
    }
}

From source file:com.devoteam.srit.xmlloader.http.StackHttp.java

License:Open Source License

/** Creates a specific HTTP Msg */
@Override/*from  w  ww .j a v a2  s  .com*/
public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception {
    String text = root.getText();

    MsgHttp msgHttp = new MsgHttp(text);

    //
    // Try to find the channel
    //
    String channelName = root.attributeValue("channel");
    //part to don't have regression
    if (channelName == null || channelName.equalsIgnoreCase("")) {
        channelName = root.attributeValue("connectionName");
    }

    String remoteUrl = root.attributeValue("remoteURL");
    //part to don't have regression
    if (remoteUrl == null || remoteUrl.equalsIgnoreCase("")) {
        remoteUrl = root.attributeValue("server");
    }

    //
    // If the message is not a request, it is a response.
    // The channel to use will be obtained from the
    // channel of the transaction-associated request.
    if (msgHttp.isRequest()) {
        Channel channel = null;
        // case the channelName is specified
        if (channelName != null && !channelName.equalsIgnoreCase("")) {
            channel = getChannel(channelName);
        }
        // case the remoteXXX is specified
        if (remoteUrl != null && !remoteUrl.equalsIgnoreCase("")) {
            channel = getChannel(remoteUrl);
            if (channel == null) {
                //part to don't have regression
                DefaultElement defaultElement = new DefaultElement("openChannelHTTP");
                defaultElement.addAttribute("remoteURL", remoteUrl);
                defaultElement.addAttribute("name", remoteUrl);
                channel = this.parseChannelFromXml(defaultElement, StackFactory.PROTOCOL_HTTP);
                openChannel(channel);
                channel = getChannel(remoteUrl);
            }
        }
        if (channel == null) {
            throw new ExecutionException("The channel named " + channelName + " does not exist");
        }
        // call to getTransactionId to generate it NOW (important)
        // it can be generated now because this is a request from xml
        msgHttp.getTransactionId();

        msgHttp.setChannel(channel);
    } else {
        if (channelName != null) {
            throw new ExecutionException(
                    "You can not specify the \"channel\" attribute while sending a response (provided by the HTTP protocol).");
        }
        if (remoteUrl != null) {
            throw new ExecutionException(
                    "You can not specify the \"remoteURL\" attribute while sending a response (provided by the HTTP protocol).");
        }
    }

    return msgHttp;
}

From source file:com.devoteam.srit.xmlloader.imap.StackImap.java

License:Open Source License

/** Creates a Channel specific to each Stack */
@Override/* w ww .j ava 2s  .c  o m*/
public Channel parseChannelFromXml(Element root, String protocol) throws Exception {
    String name = root.attributeValue("name");
    String localHost = root.attributeValue("localHost");
    String localPort = root.attributeValue("localPort");
    String remoteHost = root.attributeValue("remoteHost");
    String remotePort = root.attributeValue("remotePort");
    String transport = root.attributeValue("transport");

    if ((remoteHost == null) || (remotePort == null)) {
        throw new Exception("Missing one of the remoteHost or remotePort parameter to create channel.");
    }

    if (localHost == null) {
        localHost = Utils.getLocalAddress().getHostAddress();
    }

    if (transport == null)
        transport = "tcp";

    if (!transport.equalsIgnoreCase("tcp") && !transport.equalsIgnoreCase("tls"))
        throw new Exception("Allowed transport for IMAP channel are tcp or tls.(not " + transport + ")");

    if (existsChannel(name)) {
        return getChannel(name);
    } else {
        return new ChannelImap(name, localHost, localPort, remoteHost, remotePort, protocol, transport);
    }
}

From source file:com.devoteam.srit.xmlloader.imap.StackImap.java

License:Open Source License

/** Creates a specific Msg */
@Override//from   ww w.  j a  v a  2s.c  o m
public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception {
    MsgImap msg = new MsgImap(root.getText().trim());

    String channelName = root.attributeValue("channel");
    if (existsChannel(channelName)) {
        ChannelImap channel = (ChannelImap) getChannel(channelName);

        // code imported from channel. we must now set the transaction ID BEFORE
        // sending the request (modifications on the generic stack)
        msg.setTransactionId(channel.getTransactionId());

        if (channel.isServer())//pour un server (envoi d'une reponse)
        {
            channel.checkTransationResponse(msg,
                    channel.getChannel().getRemoteHost() + channel.getChannel().getRemotePort());
        } else//pour un client (envoi d'une requete)
        {
            msg = (MsgImap) channel.checkTransationRequest(msg,
                    channel.getChannel().getLocalHost() + channel.getChannel().getLocalPort());
        }
    }
    return msg;
}

From source file:com.devoteam.srit.xmlloader.mgcp.StackMgcp.java

License:Open Source License

@Override
public Msg parseMsgFromXml(Boolean request, org.dom4j.Element root, Runner runner) throws Exception {
    String text = root.getText();
    MsgMgcp msgmgcp = new MsgMgcp(text);

    // OBSOLETE instanciates the listenpoint (compatibility with old grammar)
    String listenpointName = root.attributeValue("providerName");
    Listenpoint listenpoint = getListenpoint(listenpointName);
    if (listenpoint == null && listenpointName != null) {
        throw new ExecutionException("The listenpoint <name=" + listenpointName + "> does not exist");
    }//from w w  w  .j a  va2s.c  om
    msgmgcp.setListenpoint(listenpoint);

    if (request != null && request && !msgmgcp.isRequest()) {
        throw new ExecutionException(
                "You specify to send a request using a <sendRequestXXX ...> tag, but the message you will send is not really a request.");
    }
    if (request != null && !request && msgmgcp.isRequest()) {
        throw new ExecutionException(
                "You specify to send a response using a <sendResponseXXX ...> tag, but the message you will send is not really a response.");
    }

    return msgmgcp;
}