List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:com.devoteam.srit.xmlloader.rtp.flow.MsgRtpFlow.java
License:Open Source License
public ArrayList<Array> parsePacketPayload(Element packet, Runner runner) throws Exception { List<Element> payloads = packet.elements("payload"); ArrayList<Array> listPayloadData = new ArrayList<Array>(); LinkedList<String> listPayload; String format = null;//from w w w .ja va 2 s . c o m String text = null; for (Element element : payloads) { format = element.attributeValue("format"); text = element.getTextTrim(); if (Parameter.matchesParameter(text) && payloads.size() == 1) { // optimisation, use cache Parameter parameter = runner.getParameterPool().get(text); if (format.equalsIgnoreCase("text")) { listPayloadData = (ArrayList<Array>) ParameterCache.getAsAsciiArrayList(parameter); } else if (format.equalsIgnoreCase("binary")) { listPayloadData = (ArrayList<Array>) ParameterCache.getAsHexArrayList(parameter); } else { throw new Exception("format of payload <" + format + "> is unknown"); } } else { listPayload = runner.getParameterPool().parse(text); if (format.equalsIgnoreCase("text")) { for (Iterator<String> it = listPayload.iterator(); it.hasNext();) { listPayloadData.add(new DefaultArray(it.next().getBytes())); } } else if (format.equalsIgnoreCase("binary")) { for (Iterator<String> it = listPayload.iterator(); it.hasNext();) { listPayloadData.add(Array.fromHexString(it.next())); } } else { throw new Exception("format of payload <" + format + "> is unknown"); } } } return listPayloadData; }
From source file:com.devoteam.srit.xmlloader.rtp.flow.StackRtpFlow.java
License:Open Source License
@Override public ArrayList<Array> parsePacketPayload(Element packet, Runner runner) throws Exception { List<Element> payloads = packet.elements("payload"); ArrayList<Array> listPayloadData = new ArrayList<Array>(); LinkedList<String> listPayload; String format = null;/*from w ww . ja v a 2 s.c o m*/ String text = null; for (Element element : payloads) { format = element.attributeValue("format"); text = element.getTextTrim(); if (Parameter.matchesParameter(text) && payloads.size() == 1) { // optimisation, use cache Parameter parameter = runner.getParameterPool().get(text); if (format.equalsIgnoreCase("text")) { listPayloadData = (ArrayList<Array>) ParameterCache.getAsAsciiArrayList(parameter); } else if (format.equalsIgnoreCase("binary")) { listPayloadData = (ArrayList<Array>) ParameterCache.getAsHexArrayList(parameter); } else { throw new Exception("format of payload <" + format + "> is unknown"); } } else { listPayload = runner.getParameterPool().parse(text); if (format.equalsIgnoreCase("text")) { for (Iterator<String> it = listPayload.iterator(); it.hasNext();) { listPayloadData.add(new DefaultArray(it.next().getBytes())); } } else if (format.equalsIgnoreCase("binary")) { for (Iterator<String> it = listPayload.iterator(); it.hasNext();) { listPayloadData.add(Array.fromHexString(it.next())); } } else { throw new Exception("format of payload <" + format + "> is unknown"); } } } return listPayloadData; }
From source file:com.devoteam.srit.xmlloader.rtp.jmf.MsgRtp.java
License:Open Source License
/** Parses then returns an RTP Packet from the XML root element */ private RTPPacket parsePacket(Element root) throws Exception { List<Element> elements = root.elements("payload"); List<byte[]> datas = new LinkedList<byte[]>(); for (Element element : elements) { if (element.attributeValue("format").equalsIgnoreCase("text")) { String text = element.getTextTrim(); datas.add(text.getBytes("UTF8")); } else if (element.attributeValue("format").equalsIgnoreCase("binary")) { String text = element.getTextTrim(); datas.add(Utils.parseBinaryString(text)); }/* w w w .j a v a 2s. c o m*/ } // // Compute total length // int length = 0; for (byte[] data : datas) { length += data.length; } byte[] data = new byte[length + 12]; int i = 0; for (byte[] aData : datas) { for (int j = 0; j < aData.length; j++) { data[i + 12] = aData[j]; i++; } } Packet packet = new Packet(); packet.data = data; RTPPacket rtpPacket = new RTPPacket(packet); // // Parse header tag // Element header = root.element("header"); if (header != null) { String ssrc = header.attributeValue("ssrc"); rtpPacket.ssrc = Integer.parseInt(ssrc); String payloadType = header.attributeValue("payloadType"); rtpPacket.payloadType = Integer.parseInt(payloadType); String seqnum = header.attributeValue("seqnum"); rtpPacket.seqnum = Integer.parseInt(seqnum); String timestamp = header.attributeValue("timestamp"); rtpPacket.timestamp = Integer.parseInt(timestamp); String marker = header.attributeValue("mark"); if (marker != null) { rtpPacket.marker = Integer.parseInt(marker); } rtpPacket.payloadoffset = 12; rtpPacket.payloadlength = data.length - rtpPacket.payloadoffset; rtpPacket.calcLength(); rtpPacket.assemble(1, false); return rtpPacket; } return null; }
From source file:com.devoteam.srit.xmlloader.rtp.jmf.StackRtp.java
License:Open Source License
/** Parses then returns an RTP Packet from the XML root element */ private RTPPacket parsePacket(Element root) throws Exception { List<Element> elements = root.elements("payload"); List<byte[]> datas = new LinkedList<byte[]>(); for (Element element : elements) { if (element.attributeValue("format").equalsIgnoreCase("text")) { String text = element.getTextTrim(); datas.add(text.getBytes("UTF8")); } else if (element.attributeValue("format").equalsIgnoreCase("binary")) { String text = element.getTextTrim(); datas.add(Utils.parseBinaryString(text)); }//from ww w . j a v a 2s . c o m } // // Compute total length // int length = 0; for (byte[] data : datas) { length += data.length; } byte[] data = new byte[length + 12]; int i = 0; for (byte[] aData : datas) { for (int j = 0; j < aData.length; j++) { data[i + 12] = aData[j]; i++; } } Packet packet = new Packet(); packet.data = data; RTPPacket rtpPacket = new RTPPacket(packet); // // Parse header tag // Element header = root.element("header"); String ssrc = header.attributeValue("ssrc"); rtpPacket.ssrc = Integer.parseInt(ssrc); String seqnum = header.attributeValue("seqnum"); rtpPacket.seqnum = Integer.parseInt(seqnum); String timestamp = header.attributeValue("timestamp"); rtpPacket.timestamp = Integer.parseInt(timestamp); String payloadType = header.attributeValue("payloadType"); rtpPacket.payloadType = Integer.parseInt(payloadType); rtpPacket.payloadoffset = 12; rtpPacket.payloadlength = data.length - rtpPacket.payloadoffset; rtpPacket.calcLength(); rtpPacket.assemble(1, false); return rtpPacket; }
From source file:com.devoteam.srit.xmlloader.rtp.MsgRtp.java
License:Open Source License
public ArrayList<Array> parsePacketPayload(Element packet, Runner runner) throws Exception { List<Element> payloads = packet.elements("payload"); SupArray data = new SupArray(); ArrayList<Array> listPayloadData = new ArrayList<Array>(); String format = null;//from ww w.j ava 2 s .c o m String text = null; for (Element element : payloads) { format = element.attributeValue("format"); if (format == null) { format = "binary"; } text = element.getTextTrim(); if (format.equalsIgnoreCase("text")) { data.addLast(new DefaultArray(text.getBytes())); } else if (format.equalsIgnoreCase("binary")) { data.addLast(new DefaultArray(Utils.parseBinaryString(text))); } else { throw new Exception("format of payload <" + format + "> is unknown"); } } listPayloadData.add(data); return listPayloadData; }
From source file:com.devoteam.srit.xmlloader.sctp.MsgSctp.java
License:Open Source License
/** * Parse the message from XML element /*from www.ja 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/* www .j av a 2 s . co 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.tcp.MsgTcp.java
License:Open Source License
/** * Parse the message from XML element //from ww w.ja va 2s.c om */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { List<Element> elements = root.elements("data"); List<byte[]> datas = new LinkedList<byte[]>(); ; try { for (Element element : elements) { if (element.attributeValue("format").equalsIgnoreCase("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 = Utils.replaceNoRegex(text, "\r\n", "\n"); text = Utils.replaceNoRegex(text, "\n", "\r\n"); datas.add(text.getBytes("UTF8")); } else if (element.attributeValue("format").equalsIgnoreCase("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++; } } decode(data); }
From source file:com.devoteam.srit.xmlloader.tcp.StackTcp.java
License:Open Source License
/** Creates a specific Msg */ @Override//from w w w.j av a2 s.c om public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { // // Parse all <data ... /> tags // List<Element> elements = root.elements("data"); List<byte[]> datas = new LinkedList<byte[]>(); ; try { for (Element element : elements) { if (element.attributeValue("format").equalsIgnoreCase("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 = Utils.replaceNoRegex(text, "\r\n", "\n"); text = Utils.replaceNoRegex(text, "\n", "\r\n"); datas.add(text.getBytes("UTF8")); } else if (element.attributeValue("format").equalsIgnoreCase("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++; } } MsgTcp msgTcp = new MsgTcp(data); // instanciates the channel String channelName = root.attributeValue("channel"); // deprecated part // if (channelName == null) channelName = root.attributeValue("connectionName"); // deprecated part // Channel channel = getChannel(channelName); if (channel == null) { throw new ExecutionException("The channel <name=" + channelName + "> does not exist"); } msgTcp.setChannel(getChannel(channelName)); return msgTcp; }
From source file:com.devoteam.srit.xmlloader.tls.MsgTls.java
License:Open Source License
/** * Parse the message from XML element /*w w w . jav a 2s . 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) { if (element.attributeValue("format").equalsIgnoreCase("text")) { String text = element.getText(); // change the \n caractere 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 = Utils.replaceNoRegex(text, "\r\n", "\n"); text = Utils.replaceNoRegex(text, "\n", "\r\n"); datas.add(text.getBytes("UTF8")); } else if (element.attributeValue("format").equalsIgnoreCase("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++; } } decode(data); }