List of usage examples for org.dom4j Element getText
String getText();
From source file:com.devoteam.srit.xmlloader.rtsp.MsgRtsp.java
License:Open Source License
/** * Parse the message from XML element /* w ww. jav a2s. c om*/ */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); this.message = new TextMessage(getProtocol(), true, ((StackRtsp) stack).addCRLFContent, null); this.message.parse(text); this.message.setGenericfirstline(new FirstLine(this.message.getFirstLineString(), getProtocol())); if (((FirstLine) (this.message.getGenericfirstline())).isRequest()) { extractRemoteData(); } }
From source file:com.devoteam.srit.xmlloader.rtsp.StackRtsp.java
License:Open Source License
/** Creates a specific Msg */ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); MsgRtsp msg = new MsgRtsp(text, true, addCRLFContent); String remoteHostAttr = root.attributeValue("remoteHost"); if (remoteHostAttr != null) { msg.setRemoteHost(remoteHostAttr); }//from w w w . j a va 2 s .co m String remotePortAttr = root.attributeValue("remotePort"); if (remotePortAttr != null) { msg.setRemotePort(Integer.parseInt(remotePortAttr)); } String listenpointAttr = root.attributeValue("listenpoint"); if (listenpointAttr != null) { Listenpoint listenpoint = getListenpoint(listenpointAttr); msg.setListenpoint(listenpoint); msg.setChannel( listenpoint.prepareChannel(msg, msg.getRemoteHost(), msg.getRemotePort(), msg.getTransport())); } return msg; }
From source file:com.devoteam.srit.xmlloader.sctp.MsgSctp.java
License:Open Source License
/** * Parse the message from XML element //from w ww. j a v a2 s .c o m */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { List<Element> elements = root.elements("data"); List<byte[]> datas = new LinkedList<byte[]>(); for (Element element : elements) { switch (DataType.valueOf(element.attributeValue("format"))) { case text: { String text = element.getText(); // change the \n caractre to \r\n caracteres because the dom librairy return only \n. // this could make some trouble when the length is calculated in the scenario text = text.replace("\r\n", "\n"); text = text.replace("\n", "\r\n"); datas.add(text.getBytes("UTF8")); break; } case binary: { String text = element.getTextTrim(); datas.add(Utils.parseBinaryString(text)); } } } // // Compute total length // int length = 0; for (byte[] data : datas) { length += data.length; } byte[] data = new byte[length]; int i = 0; for (byte[] aData : datas) { for (int j = 0; j < aData.length; j++) { data[i] = aData[j]; i++; } } SCTPData sctpData = new SCTPData(data); String stream = root.attributeValue("stream"); if (stream != null) { sctpData.sndrcvinfo.sinfo_stream = (short) Integer.parseInt(stream); } String ssn = root.attributeValue("ssn"); if (ssn != null) { sctpData.sndrcvinfo.sinfo_ssn = (short) Integer.parseInt(ssn); } String flags = root.attributeValue("flags"); if (flags != null) { sctpData.sndrcvinfo.sinfo_flags = (short) Integer.parseInt(flags); } String ppid = root.attributeValue("ppid"); if (ppid != null) { sctpData.sndrcvinfo.sinfo_ppid = Integer.parseInt(ppid); } String context = root.attributeValue("context"); if (context != null) { sctpData.sndrcvinfo.sinfo_context = Integer.parseInt(context); } String ttl = root.attributeValue("ttl"); if (ttl != null) { sctpData.sndrcvinfo.sinfo_timetolive = Integer.parseInt(ttl); } String tsn = root.attributeValue("tsn"); if (tsn != null) { sctpData.sndrcvinfo.sinfo_tsn = Integer.parseInt(tsn); } String cumtsn = root.attributeValue("cumtsn"); if (cumtsn != null) { sctpData.sndrcvinfo.sinfo_cumtsn = Integer.parseInt(cumtsn); } String aid = root.attributeValue("aid"); if (aid != null) { sctpData.sndrcvinfo.sinfo_assoc_id = new AssociationId(Long.parseLong(aid)); } this.sctpData = new SCTPData(sctpData.sndrcvinfo, sctpData.getData()); this.type = "DATA"; }
From source file:com.devoteam.srit.xmlloader.sctp.StackSctp.java
License:Open Source License
/** Creates a specific Msg */ @Override/*from w ww. ja va 2 s.c o m*/ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String stream = root.attributeValue("stream"); String ssn = root.attributeValue("ssn"); String flags = root.attributeValue("flags"); String ppid = root.attributeValue("ppid"); String context = root.attributeValue("context"); String ttl = root.attributeValue("ttl"); String tsn = root.attributeValue("tsn"); String cumtsn = root.attributeValue("cumtsn"); String aid = root.attributeValue("aid"); List<Element> elements = root.elements("data"); List<byte[]> datas = new LinkedList<byte[]>(); try { for (Element element : elements) { switch (DataType.valueOf(element.attributeValue("format"))) { case text: { String text = element.getText(); // change the \n caractre to \r\n caracteres because the dom librairy return only \n. // this could make some trouble when the length is calculated in the scenario text = text.replace("\r\n", "\n"); text = text.replace("\n", "\r\n"); datas.add(text.getBytes("UTF8")); break; } case binary: { String text = element.getTextTrim(); datas.add(Utils.parseBinaryString(text)); } } } } catch (Exception e) { throw new ExecutionException(e); } // // Compute total length // int length = 0; for (byte[] data : datas) { length += data.length; } byte[] data = new byte[length]; int i = 0; for (byte[] aData : datas) { for (int j = 0; j < aData.length; j++) { data[i] = aData[j]; i++; } } SCTPData sctpData = new SCTPData(data); if (stream != null) sctpData.sndrcvinfo.sinfo_stream = (short) Integer.parseInt(stream); if (ssn != null) sctpData.sndrcvinfo.sinfo_ssn = (short) Integer.parseInt(ssn); if (flags != null) sctpData.sndrcvinfo.sinfo_flags = (short) Integer.parseInt(flags); if (ppid != null) sctpData.sndrcvinfo.sinfo_ppid = (short) Integer.parseInt(ppid); if (context != null) sctpData.sndrcvinfo.sinfo_context = (short) Integer.parseInt(context); if (ttl != null) sctpData.sndrcvinfo.sinfo_timetolive = (short) Integer.parseInt(ttl); if (tsn != null) sctpData.sndrcvinfo.sinfo_tsn = (short) Integer.parseInt(tsn); if (cumtsn != null) sctpData.sndrcvinfo.sinfo_cumtsn = (short) Integer.parseInt(cumtsn); if (aid != null) sctpData.sndrcvinfo.sinfo_assoc_id = new AssociationId(Integer.parseInt(aid)); MsgSctp msgSctp = new MsgSctp(sctpData); String channelName = root.attributeValue("channel"); // deprecated part // if (channelName == null) channelName = root.attributeValue("connectionName"); // deprecated part // // instanciates the channel Channel channel = getChannel(channelName); if (channel == null) { throw new ExecutionException("The channel <name=" + channelName + "> does not exist"); } msgSctp.setChannel(channel); return msgSctp; }
From source file:com.devoteam.srit.xmlloader.sip.jain.MsgSip.java
License:Open Source License
/** * Parse the message from XML element /* ww w . j a v a2s . co m*/ */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); MessageFactory messageFactory = SipFactory.getInstance().createMessageFactory(); text = text.trim(); text = text.replace("\r\n", "\n"); text = text.replace("\n", "\r\n"); if (text.startsWith("SIP/")) { sipMessage = (SIPResponse) messageFactory.createResponse(text + "\r\n\r\n"); } else { sipMessage = (SIPMessage) messageFactory.createRequest(text + "\r\n\r\n"); } int posContent = text.indexOf("\r\n\r\n"); if (posContent >= 0) { String contentString = text.substring(posContent).trim(); // bug NSN equipment : add a CRLF at the end of the Content if (((StackSipCommon) stack).addCRLFContent == 1) { contentString = contentString + "\r\n"; } ContentTypeHeader contentType = sipMessage.getContentTypeHeader(); sipMessage.setContent(contentString, contentType); } }
From source file:com.devoteam.srit.xmlloader.sip.jain.MsgSipJain.java
License:Open Source License
/** * Parse the message from XML element // w w w.j a v a2 s .c o m */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); MessageFactory messageFactory = SipFactory.getInstance().createMessageFactory(); text = text.trim(); text = text.replace("\r\n", "\n"); text = text.replace("\n", "\r\n"); if (text.startsWith("SIP/")) { sipMessage = (SIPResponse) messageFactory.createResponse(text + "\r\n\r\n"); } else { sipMessage = (SIPMessage) messageFactory.createRequest(text + "\r\n\r\n"); } int posContent = text.indexOf("\r\n\r\n"); if (posContent >= 0) { String contentString = text.substring(posContent).trim(); // bug NSN equipment : add a CRLF at the end of the Content if (((StackSip) stack).addCRLFContent == 1) { contentString = contentString + "\r\n"; } ContentTypeHeader contentType = sipMessage.getContentTypeHeader(); sipMessage.setContent(contentString, contentType); } }
From source file:com.devoteam.srit.xmlloader.sip.jain.StackSipJain.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override/* ww w .jav a2s.c o m*/ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); int addCRLFContent = ((StackSip) StackFactory.getStack(StackFactory.PROTOCOL_SIP)).addCRLFContent; MsgSipJain msgSip = new MsgSipJain(text, addCRLFContent); // OBSOLETE instanciates the listenpoint (compatibility with old grammar) String listenpointName = root.attributeValue("providerName"); if (listenpointName != null) { Listenpoint listenpoint = getListenpoint(listenpointName); if (listenpoint == null && listenpointName != null) { throw new ExecutionException("The listenpoint <name=" + listenpointName + "> does not exist"); } msgSip.setListenpoint(listenpoint); } if (request != null && request && !msgSip.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 && msgSip.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 msgSip; }
From source file:com.devoteam.srit.xmlloader.sip.light.MsgSip.java
License:Open Source License
/** * Parse the message from XML element /*from ww w . j a va 2 s. c o m*/ */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); StackSip stackSip = (StackSip) stack; this.message = new TextMessage(getProtocol(), true, stackSip.addCRLFContent, stackSip.contentBinaryTypes); this.message.setCompressedHeader(compressedHeader); this.message.setMultiHeader(multiHeader); this.message.parse(text); this.message.setGenericfirstline(new FirstLine(this.message.getFirstLineString(), getProtocol())); }
From source file:com.devoteam.srit.xmlloader.sip.light.MsgSipLight.java
License:Open Source License
/** * Parse the message from XML element //from w ww . j a va 2s . c om */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); StackSipLight stackSip = (StackSipLight) stack; this.message = new TextMessage(getProtocol(), true, stackSip.addCRLFContent, stackSip.contentBinaryTypes); this.message.setCompressedHeader(compressedHeader); this.message.setMultiHeader(multiHeader); this.message.parse(text); this.message.setGenericfirstline(new FirstLine(this.message.getFirstLineString(), getProtocol())); }
From source file:com.devoteam.srit.xmlloader.sip.light.StackSipLight.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override/* www. j av a 2 s . com*/ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); MsgSipLight msgSip = new MsgSipLight(text, true, addCRLFContent); // OBSOLETE instanciates the listenpoint (compatibility with old grammar) String listenpointName = root.attributeValue("providerName"); if (listenpointName != null) { Listenpoint listenpoint = getListenpoint(listenpointName); if (listenpoint == null && listenpointName != null) { throw new ExecutionException("The listenpoint <name=" + listenpointName + "> does not exist"); } msgSip.setListenpoint(listenpoint); } if (request != null && request && !msgSip.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 && msgSip.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 msgSip; }