List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.devoteam.srit.xmlloader.rtp.jmf.StackRtp.java
License:Open Source License
/** Creates a specific RTP Msg */ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { MsgRtp msgRtp = new MsgRtp(); // instanciates the channel String channelName = root.attributeValue("sessionName"); Channel channel = getChannel(channelName); if (channel != null) { msgRtp.setChannel(channel);//from ww w . j av a2 s . c o m } else if ((channel == null) && (root.attribute("listenpoint") == null)) { throw new ExecutionException("The channel <name=" + channelName + "> does not exist"); } if (root.element("flow") != null) { throw new Exception("The JMF RTP stack does not support <flow> tag, use the light RTP stack instead"); } List<Element> listPackets = root.elements("packet"); boolean control = parseChannel(listPackets.get(0)); msgRtp.setControl(control); Iterator<Element> iter = listPackets.iterator(); while (iter.hasNext()) { Element packet = iter.next(); RTPPacket rtpPacket = parsePacket(packet); msgRtp.add(rtpPacket); } return msgRtp; }
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 boolean parseChannel(Element root) throws Exception { Element header = root.element("header"); String channel = header.attributeValue("channel"); boolean control = false; if (channel != null) { if (channel.equalsIgnoreCase("control")) { control = true;/*from ww w . ja v a 2 s. c o m*/ } else if (channel.equalsIgnoreCase("data")) { } else { Exception e = new Exception(); throw new ExecutionException("Bad channel attribute " + channel + " for the <header> tag : possible values are <data> or <control>", e); } } return control; }
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 w ww.j a v a 2 s . co 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 void parsePacketHeader(Element packet, Runner runner) throws Exception { Element header = packet.element("header"); String ssrc = header.attributeValue("ssrc"); if (ssrc != null) { long ssrcLong = Long.parseLong(ssrc); this.ssrc = (int) ssrcLong; }//from w ww .j a va 2 s . co m String payloadType = header.attributeValue("payloadType"); if (payloadType != null) { this.payloadType = Integer.parseInt(payloadType); } String seqnum = header.attributeValue("seqnum"); if ((seqnum != null) && (Utils.isInteger(seqnum))) { this.sequenceNumber = Integer.parseInt(seqnum); } String timestamp = header.attributeValue("timestamp"); if ((timestamp != null) && (Utils.isInteger(timestamp))) { this.timestamp = Long.parseLong(timestamp); } String mark = header.attributeValue("mark"); if ((mark != null) && (Utils.isInteger(mark))) this.marker = Integer.parseInt(mark); }
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 w w w . jav a2s. c om*/ 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.rtp.StackRtp.java
License:Open Source License
public MsgRtp parsePacketHeader(Element packet, Runner runner) throws Exception { MsgRtp packetRtp = new MsgRtp(); Element header = packet.element("header"); String ssrc = header.attributeValue("ssrc"); if (ssrc != null) { long ssrcLong = Long.parseLong(ssrc); packetRtp.setSsrc((int) ssrcLong); }/* w w w . j av a 2 s.c o m*/ String payloadType = header.attributeValue("payloadType"); if (payloadType != null) packetRtp.setPayloadType(Integer.parseInt(payloadType)); String seqnum = header.attributeValue("seqnum"); if ((seqnum != null) && (Utils.isInteger(seqnum))) packetRtp.setSequenceNumber(Integer.parseInt(seqnum)); String timestamp = header.attributeValue("timestamp"); if ((timestamp != null) && (Utils.isInteger(timestamp))) packetRtp.setTimestampRTP(Long.parseLong(timestamp)); String mark = header.attributeValue("mark"); if ((mark != null) && (Utils.isInteger(mark))) packetRtp.setMarker(Integer.parseInt(mark)); return packetRtp; }
From source file:com.devoteam.srit.xmlloader.rtsp.StackRtsp.java
License:Open Source License
/** Creates a Channel specific to each Stack */ @Override/*from w w w. j ava2 s. c o m*/ public synchronized 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 (null == transport) { transport = getConfig().getString("listenpoint.TRANSPORT"); if (null == transport) { throw new Exception("Transport(tcp or udp) not set in openChannelRTSP nor in rtsp.properties"); } } else if (!transport.toUpperCase().equals(StackFactory.PROTOCOL_TCP) && !transport.toUpperCase().equals(StackFactory.PROTOCOL_UDP)) { throw new Exception("Transport in openChannelRTSP must be tcp or udp"); } if (existsChannel(name)) { return getChannel(name); } else { return new ChannelRtsp(name, localHost, localPort, remoteHost, remotePort, protocol, transport.toUpperCase()); } }
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 av a2 s . c o 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.ChannelSctp.java
License:Open Source License
/** * Parse the message from XML element /* w w w . j a va2s . co m*/ */ @Override public void parseFromXml(Element root, Runner runner, String protocol) throws Exception { super.parseFromXml(root, runner, protocol); this.initmsg = new sctp_initmsg(); String num_ostreams = root.attributeValue("num_ostreams"); if (num_ostreams == null) { num_ostreams = this.stack.getConfig().getString("connect.NUM_OSTREAMS"); } if (num_ostreams != null) { this.initmsg.sinit_num_ostreams = (short) Integer.parseInt(num_ostreams); GlobalLogger.instance().getApplicationLogger().debug(Topic.PROTOCOL, "initmsg.sinit_num_ostreams=", this.initmsg.sinit_num_ostreams); } String max_instreams = root.attributeValue("max_instreams"); if (max_instreams == null) { max_instreams = this.stack.getConfig().getString("connect.MAX_INSTREAMS"); } if (max_instreams != null) { this.initmsg.sinit_max_instreams = (short) Integer.parseInt(max_instreams); GlobalLogger.instance().getApplicationLogger().debug(Topic.PROTOCOL, "initmsg.sinit_max_instreams=", this.initmsg.sinit_max_instreams); } String max_attempts = root.attributeValue("max_attempts"); if (max_attempts == null) { max_attempts = this.stack.getConfig().getString("connect.MAX_ATTEMPTS"); } if (max_attempts != null) { this.initmsg.sinit_max_attempts = (short) Integer.parseInt(max_attempts); GlobalLogger.instance().getApplicationLogger().debug(Topic.PROTOCOL, "initmsg.sinit_max_attempts=", initmsg.sinit_max_attempts); } String max_init_timeo = root.attributeValue("max_initTimeo"); if (max_init_timeo == null) { max_init_timeo = this.stack.getConfig().getString("connect.MAX_INIT_TIMEO"); } if (max_init_timeo != null) { this.initmsg.sinit_max_init_timeo = (short) Integer.parseInt(max_init_timeo); GlobalLogger.instance().getApplicationLogger().debug(Topic.PROTOCOL, "initmsg.sinit_max_init_timeo=", initmsg.sinit_max_init_timeo); } }
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 va2 s. com*/ */ @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"; }