List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.devoteam.srit.xmlloader.gtppr.data.GtpHeaderV2.java
License:Open Source License
public void parseXml(Element header, GtppDictionary dictionary) throws Exception { String msgName = header.attributeValue("name"); String msgType = header.attributeValue("type"); if ((msgType != null) && (msgName != null)) throw new Exception("type and name of the message " + msgName + " must not be set both"); if ((msgType == null) && (msgName == null)) throw new Exception("One of the parameter type or name of the message header must be set"); if (msgName != null) { this.name = msgName; this.messageType = dictionary.getMessageTypeFromName(msgName); } else if (msgType != null) { this.messageType = Integer.parseInt(msgType); this.name = dictionary.getMessageNameFromType(this.messageType); }// w w w . j a va 2 s . co m String msgPiggyFlag = header.attributeValue("piggyFlag"); if (msgPiggyFlag != null) { piggyFlag = Integer.parseInt(msgPiggyFlag); } String msgTeidFlag = header.attributeValue("teidFlag"); if (msgTeidFlag != null) { teidFlag = Integer.parseInt(msgTeidFlag); } String msgSeqNum = header.attributeValue("sequenceNumber"); if (msgSeqNum != null) { sequenceNumber = Integer.parseInt(msgSeqNum); } String msgTunnelEndpointId = header.attributeValue("tunnelEndpointId"); if (msgTunnelEndpointId != null) { tunnelEndpointId = Integer.parseInt(msgTunnelEndpointId); } }
From source file:com.devoteam.srit.xmlloader.gtppr.GtppDictionary.java
License:Open Source License
private void parseFile(InputStream stream) throws Exception { Element node = null; GtppMessage msg = null;/*from ww w . j a v a 2 s. co m*/ Tag tlv = null; String length = null; String format = null; int i = 0; SAXReader reader = new SAXReader(); Document document = reader.read(stream); //parsing des messages List listMessages = document.selectNodes("/dictionary/message"); for (i = 0; i < listMessages.size(); i++) { node = (Element) listMessages.get(i); msg = new GtppMessage(); msg.setHeader(new GtpHeaderPrime()); msg.getHeader().setName(node.attributeValue("name")); msg.getHeader().setMessageType(Integer.parseInt(node.attributeValue("messageType"))); for (Iterator it = node.elementIterator(); it.hasNext();) { Element element = (Element) it.next(); String name = element.getName(); if (name.equalsIgnoreCase("tv") || name.equalsIgnoreCase("tlv") || name.equalsIgnoreCase("tliv")) { if (name.equalsIgnoreCase("tv")) { tlv = new TagTV(); } else if (name.equalsIgnoreCase("tlv")) { tlv = new TagTLIV(); } else if (name.equalsIgnoreCase("tliv")) { tlv = new TagTLIV(); } tlv.setName(element.attributeValue("name")); String value = element.attributeValue("mandatory"); if (value != null && !value.equalsIgnoreCase("cond")) { tlv.setMandatory(Boolean.parseBoolean(value)); } else//case of cond, considered as optional { tlv.setMandatory(false); } msg.addTLV(tlv); } } messagesList.put(msg.getHeader().getName(), msg); messageTypeToNameList.put(msg.getHeader().getMessageType(), msg.getHeader().getName()); messageNameToTypeList.put(msg.getHeader().getName(), msg.getHeader().getMessageType()); } //parsing des TLV List listTLV = document.selectNodes("/dictionary/tv | /dictionary/tlv | /dictionary/tliv"); for (i = 0; i < listTLV.size(); i++) { node = (Element) listTLV.get(i); String name = node.getName(); if (name.equalsIgnoreCase("tv")) { tlv = new TagTV(); } else if (name.equalsIgnoreCase("tlv")) { tlv = new TagTLV(); } else if (name.equalsIgnoreCase("tliv")) { tlv = new TagTLIV(); } tlv.setName(node.attributeValue("name")); tlv.setTag(Integer.parseInt(node.attributeValue("tag"))); length = node.attributeValue("length"); if (length != null) { tlv.setLength(Integer.parseInt(length)); tlv.setFixedLength(true); } format = node.attributeValue("format"); if (format != null) { tlv.setFormat(format); if (format.equals("list")) { tlv.setValue(new LinkedList<GtppAttribute>()); parseAtt((Attribute) tlv, node); } } tlvList.put(tlv.getName(), tlv); tlvTagToNameList.put(tlv.getTag(), tlv.getName()); tlvNameToTagList.put(tlv.getName(), tlv.getTag()); } }
From source file:com.devoteam.srit.xmlloader.gtppr.GtppDictionary.java
License:Open Source License
private void parseAtt(Attribute att, Element node) throws Exception { String length = null;/*from w w w. j a va 2s.c o m*/ String format = null; //travel through all attribute for (Iterator it = node.elementIterator(); it.hasNext();) { Element element = (Element) it.next(); GtppAttribute attribute = new GtppAttribute(); attribute.setName(element.attributeValue("name")); length = element.attributeValue("length"); if (length != null && (length.length() != 0)) attribute.setLength(Integer.parseInt(length)); format = element.attributeValue("format"); if (format != null) { attribute.setFormat(format); if (format.equals("list")) { attribute.setValue(new LinkedList<GtppAttribute>()); parseAtt((Attribute) attribute, element);//recursif call } } ((LinkedList<GtppAttribute>) att.getValue()).add(attribute); } }
From source file:com.devoteam.srit.xmlloader.gtppr.StackGtpp.java
License:Open Source License
/** Creates a Channel specific to each Stack */ @Override// w w w . j a va2s.c o m public 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"); if (existsChannel(name)) { return getChannel(name); } else { if (null != localHost) localHost = InetAddress.getByName(localHost).getHostAddress(); else localHost = "0.0.0.0"; if (null != remoteHost) remoteHost = InetAddress.getByName(remoteHost).getHostAddress(); return new ChannelGtpp(name, localHost, localPort, remoteHost, remotePort, protocol); } }
From source file:com.devoteam.srit.xmlloader.gtppr.StackGtpp.java
License:Open Source License
private void parseTLVs(Element root, GtppMessage msg, GtppDictionary dictionary) throws Exception { List<Element> tlvs = root.elements(); List<Element> attributes = null; Tag tlv = null;// ww w.j ava2s. c o m String value = null; String length = null; for (Element element : tlvs) { String name = element.getName(); if (name.equalsIgnoreCase("tv") || name.equalsIgnoreCase("tlv") || name.equalsIgnoreCase("tliv")) { value = element.attributeValue("name"); if (value != null) tlv = dictionary.getTLVFromName(value); else { value = element.attributeValue("tag"); if (value != null) tlv = dictionary.getTLVFromTag(Integer.parseInt(value)); } if (tlv != null) { length = element.attributeValue("length"); if (length != null) { if ((tlv.getLength() > 0) && (tlv.getLength() != Integer.parseInt(length))) { GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, "TLV length for " + tlv.toString() + "is not according to size given in dictionary"); } if (value.equalsIgnoreCase("auto")) tlv.setLength(value.length()); else tlv.setLength(Integer.parseInt(length)); } value = element.attributeValue("value"); if (value != null) { setAttributeValue((Attribute) tlv, value); } else { //check if there is attribute inside the TLV attributes = element.elements("attribute"); parseAtt((Attribute) tlv, attributes); } if (tlv.getLength() == -1)//if no size is given in the dictionary { if (!(tlv.getValue() instanceof LinkedList)) tlv.setLength(((byte[]) tlv.getValue()).length); else tlv.setLength(tlv.getArray().length - 3);//- 3 to remove the tag and length bytes } } else { //add tlv to message even if unknown value = element.attributeValue("value"); tlv = new TagTLV(); tlv.setName(element.attributeValue("name")); tlv.setLength(Integer.parseInt(element.attributeValue("length"))); tlv.setValue(value.getBytes()); } msg.addTLV(tlv); tlv = null; } } }
From source file:com.devoteam.srit.xmlloader.gtppr.StackGtpp.java
License:Open Source License
private void parseAtt(Attribute att, List<Element> attributes) throws Exception { LinkedList<Object> listAtt = null; String value = null;// w w w. j a v a 2 s . com for (Element elementAtt : attributes) { value = elementAtt.attributeValue("name"); listAtt = ((LinkedList) att.getValue()); for (int i = 0; i < listAtt.size(); i++) { if (listAtt.get(i) instanceof GtppAttribute) { GtppAttribute attribute = (GtppAttribute) listAtt.get(i); if (attribute.getName().equalsIgnoreCase(value)) { if (!attribute.getFormat().equalsIgnoreCase("list")) { if (attribute.getValueQuality())//duplicate att in case it is already set { GtppAttribute duplicateAtt = attribute.clone(); attribute = duplicateAtt; listAtt.add(attribute); } value = elementAtt.attributeValue("value"); if (attribute.getValueQuality())//if an attribute already exist with the same name, duplicate it in the list { listAtt.add(i + 1, attribute.clone()); attribute = (GtppAttribute) listAtt.get(i + 1); } setAttributeValue(attribute, value); break; } else//if this attribute is also a list => recursive call { parseAtt(attribute, elementAtt.elements("attribute")); } } } else if (listAtt.get(i) instanceof LinkedList) { LinkedList list = (LinkedList) listAtt.get(i); for (int j = 0; j < list.size(); j++) parseAtt((Attribute) list.get(j), elementAtt.elements("attribute")); } if (i == listAtt.size())//insert attribute at the place given in this list { GtppAttribute newAtt = new GtppAttribute(); newAtt.setName(value); value = elementAtt.attributeValue("value"); newAtt.setValue(value.getBytes()); listAtt.add(attributes.indexOf(elementAtt), newAtt); break; } } } }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
public void fill(final List<Element> elts, boolean resetDefaults) { if (this.elements == null) { for (Element e : elts) { try { String value = e.attributeValue("value"); if (null != value) { e.attribute("value").setValue(parsing(value)); }//from w ww .j av a 2s.c o m } catch (Exception ee) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, ee, "Error in editable parameters window hile parsing parameters value : ", e); } } this.elements = new LinkedList<Element>(); elementsOrigin = new LinkedList<Element>(); if (resetDefaults) { elementsDefault = new LinkedList<Element>(); this.elements.clear(); for (Element e : elts) { this.elements.add(e.createCopy()); elementsDefault.add(e.createCopy()); } } else { this.elements.clear(); for (Element e : elts) { this.elements.add(e.createCopy()); } } EventQueue.invokeLater(new Runnable() { public void run() { doFill(elements); } }); } }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
/** * Sets the tree data./*from w w w. ja v a 2 s .c o m*/ * * @param elements */ private void doFill(List<Element> elements) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); jTree1.setRootVisible(false); String key = null; for (Element e : elements) { if (e.attributeValue("name").contains(".")) { String name = e.attributeValue("name"); DefaultMutableTreeNode eltNode = getExistingNode(name, root); if (eltNode == null) { eltNode = new DefaultMutableTreeNode(name.substring(1, name.indexOf("."))); if (key == null) key = name.substring(0, name.indexOf(".")); name = name.substring(name.indexOf(".") + 1); if (name.contains(".")) eltNode.add(getNodeChild(name)); root.add(eltNode); } else { int max = 0; DefaultMutableTreeNode depth = eltNode; while (!depth.isRoot()) { depth = (DefaultMutableTreeNode) depth.getParent(); max++; } for (int i = 0; i < max; i++) name = name.substring(name.indexOf(".") + 1); if (name.contains(".")) eltNode.add(getNodeChild(name)); } } } if (root.getChildCount() == 0) { DefaultMutableTreeNode eltNode = new DefaultMutableTreeNode("Default"); root.add(eltNode); } ((DefaultTreeModel) jTree1.getModel()).setRoot(root); ((DefaultTreeModel) jTree1.getModel()).reload(); fillTable(getEltsForTable(key)); this.jButtonOK.setEnabled(false); }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
/** * Returns the elements concerned by the key (node selected in the tree) * * @param key - TreePath in string format * @return//from w w w.j a va 2s .c o m */ private List<Element> getEltsForTable(String key) { if (key == null) return this.elements; if (key.contains("[root,")) key = key.substring(7, key.length() - 1); // 7 => '[root, ' else key = key.substring(1, key.length() - 1); key = key.replaceAll(", ", "."); List<Element> dispElts = new LinkedList<Element>(); for (Element e : this.elements) { if (e.attributeValue("name").contains(".")) { if (e.attributeValue("name").startsWith("[" + key + ".")) { Element elt = e.createCopy(); elt.attribute("name").setValue(e.attributeValue("name").substring(key.length() + 2, e.attributeValue("name").length() - 1)); dispElts.add(elt); } } else dispElts.add(e.createCopy()); } return dispElts; }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
public void apply(List<Element> elts) { if (elts != null) { this.jButtonOK.setEnabled(true); valueChanged = true;/*from w ww . ja va2 s .c o m*/ String key = ""; if (jTree1.getSelectionPath() == null) { for (Element e : elts) { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); String name = (String) pair.get(0); if (!name.startsWith("[")) name = "[" + name + "]"; if (e.attributeValue("name").equalsIgnoreCase(name)) { e.attribute("value").setValue((String) pair.get(2)); } } } } else { key = jTree1.getSelectionPath().toString(); key = key.substring(7, key.length() - 1); // 7 => '[root, ' key = key.replaceAll(", ", "."); for (Element e : elts) { if (e.attributeValue("name").contains(".")) { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); if (e.attributeValue("name").equalsIgnoreCase("[" + key + "." + pair.get(0) + "]")) { e.attribute("value").setValue((String) pair.get(2)); } } } else { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); String name = (String) pair.get(0); if (!name.startsWith("[")) name = "[" + name + "]"; if (e.attributeValue("name").equalsIgnoreCase(name)) { e.attribute("value").setValue((String) pair.get(2)); } } } } } } }