List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
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 a2s . com*/ 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 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) { 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); }
From source file:com.devoteam.srit.xmlloader.tls.StackTls.java
License:Open Source License
/** Creates a Channel specific to each Stack */ @Override/* ww w . ja va2 s . c om*/ public Channel parseChannelFromXml(Element root, String protocol) throws Exception { String name = root.attributeValue("name"); // deprecated part // if (name == null) name = root.attributeValue("connectionName"); // deprecated part // 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 { return new ChannelTls(name, localHost, localPort, remoteHost, remotePort, protocol); } }
From source file:com.devoteam.srit.xmlloader.tls.StackTls.java
License:Open Source License
/** Creates a specific Msg */ @Override//from w ww . j av a 2 s.c o m 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++; } } MsgTls msgtls = new MsgTls(data); // instanciates the conn 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"); } msgtls.setChannel(getChannel(channelName)); return msgtls; }
From source file:com.devoteam.srit.xmlloader.ucp.data.UcpMessage.java
License:Open Source License
/** * Parse the message from XML element /*from w ww . j a v a2 s .com*/ */ public void parseMsgFromXml(Element root) throws Exception { // header Element header = root.element("header"); String msgName = header.attributeValue("name"); String msgOT = header.attributeValue("OT"); if ((msgOT != null) && (msgName != null)) throw new Exception("OT and name of the message " + msgName + " must not be set both"); if ((msgOT == null) && (msgName == null)) throw new Exception("One of the parameter OT and name of the message header must be set"); StackUcp stack = (StackUcp) StackFactory.getStack(StackFactory.PROTOCOL_UCP); if (msgName != null) { this.name = msgName; this.operationType = stack.ucpDictionary.getMessageOperationTypeFromName(msgName); if (this.operationType == null) throw new Exception("Message <" + msgName + "> is unknown in the dictionary"); } if (msgOT != null) { this.name = stack.ucpDictionary.getMessageNameFromOperationType(msgOT); if (this.name == null) throw new Exception("Message with OperationType <" + msgOT + "> is unknown in the dictionary"); this.operationType = msgOT; } this.messageType = header.attributeValue("MT"); this.transactionNumber = header.attributeValue("TRN"); this.parseAttributes(root); this.calculLength();//calcul the length with attribute from the attribute }
From source file:com.devoteam.srit.xmlloader.ucp.data.UcpMessage.java
License:Open Source License
public void parseAttributes(Element root) throws Exception { List<Element> attributes = root.elements("attribute"); List<Element> imbricateAttributes = null; List<Element> xserAttributes = null; UcpAttribute att = null;/*w w w. j av a 2 s .c o m*/ UcpAttribute att2 = null; for (Element element : attributes) { att = new UcpAttribute(); att.setName(element.attributeValue("name")); //check imbricate attribute + extra service(xser) to send imbricateAttributes = element.selectNodes("attribute"); xserAttributes = element.selectNodes("xser"); if (imbricateAttributes.size() != 0) { att.setValue(new Vector<UcpAttribute>()); for (Element element2 : imbricateAttributes) { att2 = new UcpAttribute(); att2.setName(element2.attributeValue("name")); att2.setValue(element2.attributeValue("value")); ((Vector<UcpAttribute>) att.getValue()).add(att2); } } else if (xserAttributes.size() != 0) { parseXser(xserAttributes, att); } else { String encoding = element.attributeValue("encoding"); if ((encoding != null) && (encoding.equalsIgnoreCase("true"))) { att.setFormat("encodedString"); } att.setValue(element.attributeValue("value")); } this.addAttribute(att); } }
From source file:com.devoteam.srit.xmlloader.ucp.data.UcpMessage.java
License:Open Source License
public void parseXser(List<Element> list, UcpAttribute att) throws Exception { UcpXser ser = null;/*from w ww .j a va 2 s .c o m*/ att.setValue(new Vector<UcpXser>()); for (Element element : list) { ser = new UcpXser(); ser.setType(element.attributeValue("type")); ser.setLength(Integer.parseInt(element.attributeValue("length"))); ser.setValue(element.attributeValue("value").toUpperCase()); ((Vector<UcpXser>) att.getValue()).add(ser); } }
From source file:com.devoteam.srit.xmlloader.ucp.MsgUcp.java
License:Open Source License
/** * Parse the message from XML element //from w ww . j av a 2 s . c o m */ @Override public void parseFromXml(Boolean request, Element root, Runner runner) throws Exception { this.ucpMessage = new UcpMessage(); // header Element header = root.element("header"); String msgName = header.attributeValue("name"); String msgOT = header.attributeValue("OT"); if ((msgOT != null) && (msgName != null)) throw new Exception("OT and name of the message " + msgName + " must not be set both"); if ((msgOT == null) && (msgName == null)) throw new Exception("One of the parameter OT and name of the message header must be set"); if (msgName != null) { this.ucpMessage.setName(msgName); ucpMessage.setOperationType(((StackUcp) stack).ucpDictionary.getMessageOperationTypeFromName(msgName)); if (ucpMessage.getOperationType() == null) throw new Exception("Message <" + msgName + "> is unknown in the dictionary"); } if (msgOT != null) { this.ucpMessage.setName(((StackUcp) stack).ucpDictionary.getMessageNameFromOperationType(msgOT)); if (this.ucpMessage.getName() == null) throw new Exception("Message with OperationType <" + msgOT + "> is unknown in the dictionary"); this.ucpMessage.setOperationType(msgOT); } this.ucpMessage.setMessageType(header.attributeValue("MT")); this.ucpMessage.setTransactionNumber(header.attributeValue("TRN")); parseAttributes(root, this.ucpMessage); this.ucpMessage.calculLength();//calcul the length with attribute from the attribute }
From source file:com.devoteam.srit.xmlloader.ucp.MsgUcp.java
License:Open Source License
private void parseAttributes(Element root, UcpMessage msg) throws Exception { List<Element> attributes = root.elements("attribute"); List<Element> imbricateAttributes = null; List<Element> xserAttributes = null; UcpAttribute att = null;// w w w . j a v a 2 s . c o m UcpAttribute att2 = null; for (Element element : attributes) { att = new UcpAttribute(); att.setName(element.attributeValue("name")); //check imbricate attribute + extra service(xser) to send imbricateAttributes = element.selectNodes("attribute"); xserAttributes = element.selectNodes("xser"); if (imbricateAttributes.size() != 0) { att.setValue(new Vector<UcpAttribute>()); for (Element element2 : imbricateAttributes) { att2 = new UcpAttribute(); att2.setName(element2.attributeValue("name")); att2.setValue(element2.attributeValue("value")); ((Vector<UcpAttribute>) att.getValue()).add(att2); } } else if (xserAttributes.size() != 0) { parseXser(xserAttributes, att); } else { String encoding = element.attributeValue("encoding"); if ((encoding != null) && (encoding.equalsIgnoreCase("true"))) { att.setFormat("encodedString"); } att.setValue(element.attributeValue("value")); } msg.addAttribute(att); } }
From source file:com.devoteam.srit.xmlloader.ucp.MsgUcp.java
License:Open Source License
private void parseXser(List<Element> list, UcpAttribute att) throws Exception { UcpXser ser = null;/*from w w w .j a v a 2s . c o m*/ att.setValue(new Vector<UcpXser>()); for (Element element : list) { ser = new UcpXser(); ser.setType(element.attributeValue("type")); ser.setLength(Integer.parseInt(element.attributeValue("length"))); ser.setValue(element.attributeValue("value").toUpperCase()); ((Vector<UcpXser>) att.getValue()).add(ser); } }