List of usage examples for org.dom4j Element getText
String getText();
From source file:com.devoteam.srit.xmlloader.genscript.ScriptGenerator.java
License:Open Source License
public void generateTest() throws Exception { // Si le fichier n'existe pas dj if (!fileRoot.exists()) { test = new Test("Genscript", "Script converted from capture"); }//w ww .j a v a2s.c om // Si le fichier de sortie existe dj else { // On ouvre le fichier existant File xml = fileRoot; Document testDoc; SAXReader reader = new SAXReader(); testDoc = reader.read(xml); Element testExistant = testDoc.getRootElement(); // On gnre un nouvel objet test partir de l'lment existant dans le fichier test = new Test(testExistant.attributeValue("name"), testExistant.attributeValue("description")); test.setTest(testExistant); } // On tente de rcuprer le testcase gnrer Element testcaseExistant = null; for (Iterator i = test.getTest().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("testcase") && elem.attribute("name").getText().equals(testcaseName)) { testcaseExistant = elem; } } // On rcupre les paramtres existants for (Iterator i = test.getTest().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("parameter")) { Param p = new Param(elem.attributeValue("name"), "test", elem.attributeValue("operation") + "," + elem.attributeValue("value"), null, Param.TARGET_SENDCLIENT); p.setName(p.getFamily()); p.setRemplacedValue(elem.attributeValue("value")); ParamGenerator.getInstance().recordParam(p); } } // Si le testcase n'existe pas encore if (testcaseExistant == null) { // On le crait testcase = new TestCase(testcaseName, "Testcase generate from capture", "true"); test.getTest().add(testcase.getTestCase()); } // Sinon on gnre un testcase partir de celui existant dans le fichier else { testcase = new TestCase(testcaseExistant.attributeValue("name"), testcaseExistant.attributeValue("description"), testcaseExistant.attributeValue("state")); testcase.setTestCase(testcaseExistant); // On rcupre les paramtres existants for (Iterator i = testcase.getTestCase().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("parameter")) { Param p = new Param(elem.attributeValue("name"), "testcase", elem.attributeValue("operation") + "," + elem.attributeValue("value"), null, Param.TARGET_SENDCLIENT); p.setName(p.getFamily()); p.setRemplacedValue(elem.attributeValue("value")); ParamGenerator.getInstance().recordParam(p); } } } // On ajoute le testcase dans le test test.addTestCase(testcase); // On tente de rcuprer le scenario Element scenarioExistant = null; // On enregistre les scenarios de ce testcase for (Iterator j = testcase.getTestCase().elements().iterator(); j.hasNext();) { Element elem = (Element) j.next(); if (elem.getName().equals("scenario") && elem.getText().contains(listeFiltre.get(0).getHostPort().toString())) { scenarioExistant = elem; } else if (elem.getName().equals("scenario")) { Scenario sc = new Scenario(elem.attributeValue("name"), elem.getText(), listeFiltre); testcase.addScenario(sc); } } // Si le scenario n'existe pas encore if (scenarioExistant == null) { // On le crait scenario = new Scenario(getScenarioName(), getScenarioPath(), listeFiltre); testcase.getTestCase().add(scenario.toXmlElement()); } else { scenario = new Scenario(scenarioExistant.attributeValue("name"), scenarioExistant.getText(), listeFiltre); scenario.setScenario(scenarioExistant); } // On ajoute ce scenario au testcase testcase.addScenario(scenario); }
From source file:com.devoteam.srit.xmlloader.h248.MsgH248.java
License:Open Source License
/** * Parse the message from XML element //from w w w. ja v a 2 s. c o m */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText().trim(); if ("CRLF".equals(((StackH248) this.stack).endLineCharacters)) { text = Utils.replaceNoRegex(text, "\n", "\r\n"); } else if ("CR".equals(((StackH248) this.stack).endLineCharacters)) { text = Utils.replaceNoRegex(text, "\n", "\r"); } else if ("LF".equals(((StackH248) this.stack).endLineCharacters)) { } else { throw new ExecutionException( "The \"END_LINE_CHARACTERS\" configuration parameter should be a string from the list {CRLF, LF, CR}"); } decode(text.getBytes()); }
From source file:com.devoteam.srit.xmlloader.h248.StackH248.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override// w w w .j a va2 s. co m public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText().trim(); if ("CRLF".equals(endLineCharacters)) { text = Utils.replaceNoRegex(text, "\n", "\r\n"); } else if ("CR".equals(endLineCharacters)) { text = Utils.replaceNoRegex(text, "\n", "\r"); } else if ("LF".equals(endLineCharacters)) { } else { throw new ExecutionException( "The \"END_LINE_CHARACTERS\" configuration parameter should be a string from the list {CRLF, LF, CR}"); } MsgH248 msgH248 = new MsgH248(text); return msgH248; }
From source file:com.devoteam.srit.xmlloader.http.StackHttp.java
License:Open Source License
/** Creates a specific HTTP Msg */ @Override/*from www. ja va 2 s . co m*/ 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.MsgImap.java
License:Open Source License
/** * Parse the message from XML element /*from w ww . ja va 2s .c o m*/ */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText().trim(); decode(text.getBytes()); }
From source file:com.devoteam.srit.xmlloader.imap.StackImap.java
License:Open Source License
/** Creates a specific Msg */ @Override/*from w w w.java 2 s . co 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.MsgMgcp.java
License:Open Source License
/** * Parse the message from XML element /*from w w w . ja v a 2 s . co m*/ */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); decode(text.getBytes()); }
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 v a 2 s. c o m 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; }
From source file:com.devoteam.srit.xmlloader.msrp.StackMsrp.java
License:Open Source License
/** Creates a specific Msg */ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); return new MsgMsrp(text); }
From source file:com.devoteam.srit.xmlloader.pop.StackPop.java
License:Open Source License
/** Creates a specific Msg */ @Override//from w ww. j a v a 2 s . c o m public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { MsgPop msg = new MsgPop(root.getText().trim()); String channelName = root.attributeValue("channel"); String transactionId = root.attributeValue("transactionId"); if (null != channelName && existsChannel(channelName)) { msg.setChannel(getChannel(channelName)); } if (null != transactionId) { Trans trans = super.getInTransaction(new TransactionId(transactionId)); msg.setChannel(trans.getBeginMsg().getChannel()); } ChannelPop channel = (ChannelPop) msg.getChannel(); if (channel.isServer()) { channel.checkTransactionResponse(msg); } else { channel.checkTransactionRequest(msg); } return msg; }