List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.devoteam.srit.xmlloader.sigtran.tlv.TlvDictionary.java
License:Open Source License
private void parseFile(InputStream stream) throws Exception { // variables int i = 0;//from w ww . ja va 2 s. c o m int j = 0; int k = 0; SAXReader reader = new SAXReader(); Document document = reader.read(stream); Element root = (Element) document.selectSingleNode("/dictionary"); String ppidStr = root.attributeValue("ppid"); _ppid = Integer.parseInt(ppidStr); //Class and type List listClassType = document.selectNodes("/dictionary/classType/class"); for (i = 0; i < listClassType.size(); i++) { Element classNode = (Element) listClassType.get(i); String classId = classNode.attributeValue("id"); String className = classNode.attributeValue("name"); List listType = classNode.elements("type"); for (j = 0; j < listType.size(); j++) { Element typeNode = (Element) listType.get(j); String typeId = typeNode.attributeValue("id"); String typeName = typeNode.attributeValue("name"); String class_Type = classId; class_Type += ":" + typeId; messageTypeValue.put(typeName, typeId); messageTypeName.put(class_Type, typeName); } try { messageClassValue.put(className, (Integer.decode(classId))); messageClassName.put((Integer.decode(classId)), className); } catch (Exception e) { throw new ExecutionException( "a class id must be an Integer\n" + classNode.asXML().replace(" ", "")); } } //parameters List listParameters = document.selectNodes("/dictionary/parameters/parameter"); for (i = 0; i < listParameters.size(); i++) { Element parameterNode = (Element) listParameters.get(i); String parameterName = parameterNode.attributeValue("name"); String parameterTag = parameterNode.attributeValue("tag"); TlvParameter parameter = new TlvParameter(null, this); if (parameterTag != null) { try { parameter.setTag(Integer.decode(parameterTag)); } catch (Exception e) { throw new ExecutionException( "a tag of a parameter must be an Integer\n" + parameterNode.asXML().replace(" ", "")); } } parameter.setName(parameterName); this.parameter.put(parameterName, parameter); this.parameterName.put(parameter.getTag(), parameterName); List listFields = parameterNode.elements("field"); for (j = 0; j < listFields.size(); j++) { TlvField field = parseField((Element) listFields.get(j)); parameter.getFields().add(field); } } //enumerations List listEnumeration = document.selectNodes("/dictionary/enumerations/enumeration"); for (i = 0; i < listEnumeration.size(); i++) { Element enumerationNode = (Element) listEnumeration.get(i); List listValue = enumerationNode.elements("value"); String enumerationName = enumerationNode.attributeValue("name"); for (j = 0; j < listValue.size(); j++) //-value- { Element valueNode = (Element) listValue.get(j); List listField = valueNode.elements("field"); String valueName = valueNode.attributeValue("name"); String valueCode = valueNode.attributeValue("code"); if (valueCode != null) { try { Integer.decode(valueCode); } catch (Exception e) { throw new ExecutionException( "a valueCode must be an Integer\n" + valueNode.asXML().replace(" ", "")); } } String enumerationName_code = enumerationName + ":" + valueCode; enumerationFromCode.put(enumerationName_code, valueName); String enumerationName_name = enumerationName + ":" + valueName; enumerationFromName.put(enumerationName_name, valueCode); } } }
From source file:com.devoteam.srit.xmlloader.sigtran.tlv.TlvDictionary.java
License:Open Source License
private TlvField parseField(Element fieldNode) throws Exception { String fieldName = fieldNode.attributeValue("name"); String fieldStart = fieldNode.attributeValue("start"); String fieldFormat = fieldNode.attributeValue("format"); String fieldLengthBit = fieldNode.attributeValue("lengthBit"); String fieldLength = fieldNode.attributeValue("length"); String fieldStartBit = fieldNode.attributeValue("startBit"); String fieldValue = fieldNode.attributeValue("enumerationId"); TlvField field = new TlvField(null, this); if (fieldStart != null) { try {// ww w . j a v a 2 s. co m //field.setStart(Integer.decode(fieldStart)); } catch (Exception e) { throw new ExecutionException( "a fieldStart must be an Integer\n" + fieldNode.asXML().replace(" ", "")); } } if (fieldStartBit != null) { try { //field.setStartBit(Integer.decode(fieldStartBit)); } catch (Exception e) { throw new ExecutionException( "a fieldStartBit must be an Integer\n" + fieldNode.asXML().replace(" ", "")); } } if (fieldLengthBit != null) { try { field.setLengthBit(Integer.decode(fieldLengthBit)); } catch (Exception e) { throw new ExecutionException( "a fieldfieldLengthBit must be an Integer\n" + fieldNode.asXML().replace(" ", "")); } } if (fieldLength != null) { try { field.setLength(Integer.decode(fieldLength)); } catch (Exception e) { throw new ExecutionException( "a fieldfieldLength must be an Integer\n" + fieldNode.asXML().replace(" ", "")); } } field.setFormat(fieldFormat); field.setValue(fieldValue); field.setName(fieldName); return field; }
From source file:com.devoteam.srit.xmlloader.sigtran.tlv.TlvField.java
License:Open Source License
/** * Parse a field from a XML file//from ww w .ja v a 2 s. c om * * @param root : path of the field in the XML scenario file * @throws Exception */ public void parseElement(Element root) throws Exception { //Capture the different attribute from the XML file String name = root.attributeValue("name"); String length = root.attributeValue("length"); String lengthBit = root.attributeValue("lengthBit"); String value = root.attributeValue("value"); String format = root.attributeValue("format"); // decode enumeration to value if (_dictionary.getEnumerationCodeFromName(name, value) != null) { value = _dictionary.getEnumerationCodeFromName(name, value); value = "" + (int) Long.parseLong(value); } if (null != value) { _value = value; } if (null != format) { _format = format; } if (null != name) { _name = name; } // check the type is valid if (!("fvo".equalsIgnoreCase(_format) || "integer".equalsIgnoreCase(_format) || "spare".equalsIgnoreCase(_format) || "string".equalsIgnoreCase(_format) || "binary".equalsIgnoreCase(_format))) { throw new ExecutionException( "UA layer : The format of a field must be set integer/string/binary/fvo\n" + root.asXML()); } // if the type is fvo, then search if the fvo message is defined in message if ("fvo".equalsIgnoreCase(_format) && null == _msg.getFvoMessage()) { throw new ExecutionException( "<SS7> tag should be defined in message because there is a 'fvo' type field\n" + root.asXML()); } // override the length if defined in element if (null != lengthBit || null != length) { _length = 0; _lengthBit = 0; if (null != length) { _length = Integer.decode(length); } if (null != lengthBit) { _length += Integer.decode(lengthBit) / 8; _lengthBit = Integer.decode(lengthBit) % 8; } } }
From source file:com.devoteam.srit.xmlloader.sigtran.tlv.TlvMessage.java
License:Open Source License
public void parseMsgFromXml(Element root) throws Exception { //header// www . j av a 2s . com Element header = root.element("header"); String version = header.attributeValue("version"); String reserved = header.attributeValue("reserved"); String messageClass = header.attributeValue("messageClass"); String messageType = header.attributeValue("messageType"); String messageLength = header.attributeValue("messageLength"); if (version != null) { setVersion(Integer.decode(version)); } if (reserved != null) { setReserved(Integer.decode(reserved)); } if (messageClass != null) { try { setMessageClass(Integer.decode(messageClass)); } catch (Exception e) { try { setMessageClass(_dictionary.messageClassValue(messageClass)); } catch (Exception e2) { throw new ExecutionException("The messageClass of the message header is unrecognized\n" + root.asXML().replace(" ", "")); } } } else { throw new ExecutionException( "The messageClass of the message header must be set\n" + root.asXML().replace(" ", "")); } if (messageType != null) { try { setMessageType(Integer.decode(messageType)); } catch (Exception e) { try { setMessageType(_dictionary.messageTypeValue(messageType)); } catch (Exception e2) { throw new ExecutionException("The messageType of the message header is unrecognized\n" + root.asXML().replace(" ", "")); } } } else { throw new ExecutionException( "The messageType of the message header must be set\n" + root.asXML().replace(" ", "")); } if (messageLength != null) { setMessageLength(Integer.decode(messageLength)); } List<Element> parameters = root.elements("parameter"); for (int cpt = 0; cpt < parameters.size(); cpt++) { Element element = parameters.get(cpt); TlvParameter parameter = new TlvParameter(_msg, _dictionary); parameter.parseElement(element); getParameters().add(parameter); } }
From source file:com.devoteam.srit.xmlloader.sigtran.tlv.TlvParameter.java
License:Open Source License
/** * Parse the TLV parameter from the XML element *//*from w ww . j av a2 s. com*/ public void parseElement(Element root) throws Exception { String tagStr = root.attributeValue("tag"); List<Element> listParameters = root.elements("parameter"); List<Element> listFields = root.elements("field"); // try to get parameter def from dictionary TlvParameter dictionaryParameter; int tagInt; try { tagInt = Integer.decode(tagStr); // the tag is already an integer dictionaryParameter = _dictionary.parameter(tagInt, _msg); } catch (Exception e) { // the tag was not an integer dictionaryParameter = _dictionary.parameter(tagStr, _msg); tagInt = dictionaryParameter.getTag(); if (null == dictionaryParameter) { throw new ParsingException("Tag was not an integer and was not found in dictionary.\n", e); } } // set the tag _tag.setValue(tagInt); // if possible, copy human readable name from dictionary if (null != dictionaryParameter) { _name = dictionaryParameter._name; } // parse the inner fields if (!listFields.isEmpty()) { for (Element parameter : listFields) { TlvField tlvField = new TlvField(_msg, _dictionary); // parse a first time (to init name...) tlvField.parseElement(parameter); // if the parameter is defined in the dictionary, then try to find definition of the field if (null != dictionaryParameter) { for (TlvField dictionaryField : dictionaryParameter.getFields()) { if (dictionaryField.getName().equalsIgnoreCase(tlvField.getName())) { tlvField.init(dictionaryField); } } } // parse a second time (to override dictionary values...) tlvField.parseElement(parameter); // check the length has been defined if (("integer".equalsIgnoreCase(tlvField.getFormat()) || "spare".equalsIgnoreCase(tlvField.getFormat())) && (-1 == tlvField.getLength() && -1 == tlvField.getLengthBit())) { throw new ParsingException( "length attributes are not defined, neither in dictionary or in scenario\n" + root.asXML()); } _fields.add(tlvField); } } else if (!listParameters.isEmpty()) { // parse the inner parameters for (Element parameter : listParameters) { TlvParameter tlvParameter = new TlvParameter(_msg, _dictionary); tlvParameter.parseElement(parameter); _parameters.add(tlvParameter); } } }
From source file:com.devoteam.srit.xmlloader.sip.jain.StackSipJain.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override//from ww w. ja va 2 s . co 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.StackSipLight.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override//www. j a v a2s .c om 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; }
From source file:com.devoteam.srit.xmlloader.sip.ListenpointSip.java
License:Open Source License
/** Creates a Listenpoint specific from XML tree*/ public ListenpointSip(Stack stack, Element root) throws Exception { super(stack, root); String transportAttr = root.attributeValue("transport"); if (transportAttr == null) { this.transport = null; }/* w ww .ja v a2 s. com*/ }
From source file:com.devoteam.srit.xmlloader.sip.ListenpointSipCommon.java
License:Open Source License
/** * Parse the listenpoint from XML element *///from w w w. ja v a 2s . c om public void parseFromXml(Element root, Runner runner) throws Exception { super.parseFromXml(root, runner); // DEPRECATED begin this.name = root.attributeValue("name"); if (this.name == null) { this.name = root.attributeValue("providerName"); } // DEPRECATED end }
From source file:com.devoteam.srit.xmlloader.sip.StackSipCommon.java
License:Open Source License
/** Creates a specific SIP Msg */ @Override/* ww w .j a v a2 s . c o m*/ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { MsgSipCommon msgSip = (MsgSipCommon) super.parseMsgFromXml(request, root, runner); // DEPRECATED begin 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."); } // DEPRECATED end return msgSip; }