List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing token definition. * // www. j av a 2 s .c o m * @param e XML DOM element * @return Parsed token. If the token existed before, returns the same (possibly * altered) instance. */ private Token parseToken(Element e) { String name = e.attributeValue("name"); if (name == null) { return null; } Token token; if (tokens.containsKey(name)) { token = tokens.get(name); } else { token = new Token(name); tokens.put(name, token); } boolean clean = false; for (Element ce : e.elements()) { // add the attribute if ("a".equals(ce.getName())) { Argument a = parseArgument(ce, name); if (a != null) { if (!clean) { token.getArguments().clear(); clean = true; } token.addArgument(a); } } else if ("d".equals(ce.getName())) { token.setDescription(ce.getText()); } } return token; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing token definition. * * @param e XML DOM element/*w ww . j a va 2 s . c o m*/ * @param parentName Name of the parent element (currently unused - 20100905) * @return Parsed token. If the token existed before, returns the same (possibly * altered) instance. */ private Argument parseArgument(Element e, String parentName) { String type = e.attributeValue("type"); if (type == null) { return null; } boolean required = Boolean.parseBoolean(e.attributeValue("required")); Argument argument = null; if ("enum".equals(type)) { Set<String> items = new HashSet<String>(); for (Element ee : e.elements()) { if ("e".equals(ee.getName())) { items.add(ee.attributeValue("name")); } } argument = new Argument(type, items); } else if ("range".equals(type)) { int min = 0; int max = 0; try { min = Integer.parseInt(e.attributeValue("min")); max = Integer.parseInt(e.attributeValue("max")); argument = new Argument(type, min, max); } catch (NumberFormatException ex) { return null; } } else if ("int".equals(type)) { argument = new Argument(type); } else if ("string".equals(type)) { String id = e.attributeValue("id"); String ref = e.attributeValue("ref"); if (id != null) { // [NOTE] inline "default" id can only be a flat list. if (!ids.containsKey(id)) { Id idObject = new Id(id); ids.put(id, idObject); // we might load a description later... } } argument = new Argument(type, id, ref); } String desc = e.elementText("d"); if (desc != null && argument != null) { argument.setDescription(desc); } argument.setLabel(e.attributeValue(Constants.XML_ARGUMENT_LABLE)); return argument; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing container definition. * * @param e XML DOM element/*from www. j a v a 2 s .c o m*/ * @return Parsed container. If the container existed before, returns the same (possibly * altered) instance. */ private Container parseContainer(Element e) { String name = e.attributeValue("name"); if (name == null) { return null; } Container container; if (containers.containsKey(name)) { container = containers.get(name); } else { container = new Container(name); containers.put(name, container); } boolean clean = false; for (Element ce : e.elements()) { // add the attribute if ("a".equals(ce.getName())) { Argument a = parseArgument(ce, name); if (a != null) { if (!clean) { container.getArguments().clear(); clean = true; } container.addArgument(a); } } else if ("c".equals(ce.getName())) { Container cc = parseContainer(ce); if (cc != null) { if (!container.getContainers().containsKey(cc.getName())) { container.addContainer(cc); } } } else if ("t".equals(ce.getName())) { Token ct = parseToken(ce); if (ct != null) { if (!container.getTokens().containsKey(ct.getName())) { container.addToken(ct); } } } else if ("d".equals(ce.getName())) { container.setDescription(ce.getText()); } } return container; }
From source file:com.bullx.heartbeat.Result.java
License:Open Source License
public Result(Element e) { if (null == e) { return;//from w w w. jav a 2 s. c o m } this.code = Integer.valueOf(e.attributeValue("code")); if (0 != this.code) { Element errorXml = e.element("error"); if (null != errorXml) { this.errorcode = I2Error.codeOf(errorXml.attributeValue("errorcode")); List<Element> attrNodeList = errorXml.elements(); for (Element a : attrNodeList) { this.attr.put(a.attributeValue("name"), a.attributeValue("value")); } } } }
From source file:com.cnd.greencube.server.util.dom4j.XmlUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static void removeChildren(Element el) { for (Iterator<Element> iter = el.elements().iterator(); iter.hasNext();) { el.remove(iter.next());/*from ww w . j a va 2s . c o m*/ } }
From source file:com.compliance.webapp.filter.LicenseFilter.java
public Boolean resolve(HttpServletRequest hRequest) { Boolean fileIsExist = false;//w w w. j av a 2s . co m try { String path = hRequest.getSession().getServletContext().getRealPath("/"); File file = new File(path + "compliance.licence"); if (file.exists()) { fileIsExist = true; FileInputStream in = null; in = new FileInputStream(file); byte[] buf = new byte[4096]; int len = in.read(buf, 0, 4096); in.close(); byte[] buffer = new byte[len]; for (int i = 0; i < len; i++) { buffer[i] = buf[i]; } char[] key1 = { 0x3F, 0xEE, 0x3F, 0x5A, 0xAE, 0xFA, 0x1F, 0x0A }; char[] key2 = { 0x3D, 0xAE, 0x3A, 0x5B, 0x3F, 0x6A, 0x11, 0xAA }; char[] key3 = { 0x0B, 0x9E, 0xDF, 0x2A, 0xAA, 0xF0, 0x7D, 0x6E }; buffer = EncodeUtil.xorDecode(buffer, key3); buffer = EncodeUtil.xorDecode(buffer, key2); buffer = EncodeUtil.xorDecode(buffer, key1); // ?XML Document document = DocumentHelper.parseText(new String(buffer)); Element root = document.getRootElement(); if (root.getName().equals("reginfo")) { List<Element> elementsList = root.elements(); Iterator<Element> iterator = elementsList.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); if (element.getName().equals("name")) { Serial.SERIAL_NAME = element.getText(); } else if (element.getName().equals("versions")) { Serial.SERIAL_VERSIONS = element.getText(); } else if (element.getName().equals("auth_day")) { Serial.SERIAL_AUTH_DAY = Integer.parseInt(element.getText()); } else if (element.getName().equals("gen_time")) { Serial.SERIAL_GEN_TIME = Long.parseLong(element.getText()); } else if (element.getName().equals("resource_num")) { Serial.SERIAL_RESOURCE_NUM = Integer.parseInt(element.getText()); } else if (element.getName().equals("sign")) { Serial.SERIAL_SIGN = element.getText(); } } } } } catch (Exception e) { fileIsExist = false; e.printStackTrace(); } return fileIsExist; }
From source file:com.ctrip.infosec.rule.action.FrozenAccount.java
/** * ?/* w ww.j ava2s . c o m*/ * * @param params * @return */ private static Map frozenOrNot(Map params) { beforeInvoke("FrozenAccount.frozenOrNot"); Map<String, String> result = new HashMap(); try { StringBuilder content = new StringBuilder(); content.append("<Uid>").append(params.get("uid")).append("</Uid>"); content.append("<OperStatus>").append(params.get("operStatus")).append("</OperStatus>"); content.append("<Oper>").append(params.get("oper")).append("</Oper>"); content.append("<Remark>").append(params.get("remark")).append("</Remark>"); String request = "<FULogMessageRequest>" + content.toString() + "</FULogMessageRequest>"; String xml = ESBClient.requestESB("Payment.CardRisk.InfoSecurity.EnterFULogMessage", request); if (xml == null || xml.isEmpty()) { return result; } Document document = DocumentHelper.parseText(xml); String xpath = "/Response/FULogMessageResponse"; List<Element> list = document.selectNodes(xpath); if (list == null || list.isEmpty()) { /*xpath = "/Response/Header"; Element header = (Element)document.selectSingleNode(xpath); Attribute resultCode = header.attribute("ResultCode"); Attribute resultMsg = header.attribute("ResultMsg"); result.put("resultCode",resultCode.getValue()); result.put("resultMsg",resultMsg.getValue());*/ result.put("result", xml); return result; } for (Element subElement : list) { Iterator iterator = subElement.elements().iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); result.put(element.getName(), element.getStringValue()); } } } catch (Exception ex) { fault("FrozenAccount.frozenOrNot"); logger.error(Contexts.getLogPrefix() + "invoke FrozenAccount.frozenOrNot fault.", ex); } finally { afterInvoke("FrozenAccount.frozenOrNot"); } return result; }
From source file:com.devoteam.srit.xmlloader.asn1.BN_ASNMessage.java
License:Open Source License
public void parseFromXML(Element root) throws Exception { this.className = root.attributeValue("className"); List<Element> children = root.elements(); for (Element element : children) { Class thisClass = Class.forName(className); int pos = className.lastIndexOf('.'); String packageName = ""; if (pos > 0) { packageName = className.substring(0, pos + 1); }//w ww .ja v a 2 s . c o m this.asnObject = thisClass.newInstance(); String resultPath = ""; XMLToASNParser.getInstance().parseFromXML(resultPath, this, this.asnObject, element, packageName); } }
From source file:com.devoteam.srit.xmlloader.asn1.XMLToASNParser.java
License:Open Source License
public void parseFromXML(String resultPath, ASNMessage message, Object objClass, Element root, String ClasseName) throws Exception { // parsing XML List<Element> children = root.elements(); for (Element element : children) { Class thisClass = objClass.getClass(); Field field = this.findField(objClass, element); if (field != null) { //Object subObject = instanceClass(field.getType().getCanonicalName(), ClasseName); //field.setAccessible(true); //field.set(objClass, subObject); //initObject(subObject, element, ClasseName); //field.setAccessible(true); //field.set(objClass, parseField(element, field.getType().getCanonicalName(), ClasseName)); initField(resultPath, message, objClass, element, field, ClasseName); }/*from w w w . j a v a 2s . c om*/ } }
From source file:com.devoteam.srit.xmlloader.asn1.XMLToASNParser.java
License:Open Source License
public Object parseField(String resultPath, ASNMessage message, Element element, Field field, String type, Object object, String className) throws Exception { // manage the embedded objects Embedded embedded = message.getEmbeddedByInitial(type); if (embedded == null && field != null) { embedded = message.getEmbeddedByInitial(field.getName()); }//from w w w .ja v a 2s . co m if (embedded != null) { String replace = embedded.getReplace(); Class subClass = Class.forName(replace); Object objEmbbeded = subClass.newInstance(); parseFromXML(resultPath, message, objEmbbeded, (Element) element.elements().get(0), className); IEncoder<Object> encoderEmbedded = CoderFactory.getInstance().newEncoder("BER"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); encoderEmbedded.encode(objEmbbeded, outputStream); byte[] bytesEmbedded = outputStream.toByteArray(); //Array arraybytesEmbedded = new DefaultArray(bytesEmbedded); Object obj = null; if (!type.equals("byte[]")) { Class cl = Class.forName(type); Constructor constr = cl.getConstructor(); constr.setAccessible(true); obj = constr.newInstance(); Field[] fields = cl.getDeclaredFields(); fields[0].setAccessible(true); fields[0].set(obj, bytesEmbedded); } else { obj = bytesEmbedded; } return obj; } Object value = null; if (type.equals("java.lang.Boolean") || type.equals("boolean")) { value = Boolean.valueOf(element.getTextTrim()).booleanValue(); } else if (type.equals("java.lang.String") || type.equals("String")) { value = element.getTextTrim(); } else if (type.equals("java.lang.Integer") || type.equals("int")) { value = Integer.parseInt(element.getTextTrim()); } else if (type.equals("java.lang.Float") || type.equals("float")) { value = Float.parseFloat(element.getTextTrim()); } else if (type.equals("java.lang.Short") || type.equals("short")) { value = Short.parseShort(element.getTextTrim()); } else if (type.equals("java.lang.Long") || type.equals("long")) { value = Long.parseLong(element.getTextTrim()); } else if (type.equals("java.lang.Byte") || type.equals("byte")) { value = Byte.parseByte(element.getTextTrim()); } else if (type.equals("byte[]")) { // not a simple value so return return new DefaultArray(Utils.parseBinaryString("h" + element.getTextTrim())).getBytes(); } else if (type.endsWith(".EnumType")) { String elementText = element.getTextTrim(); int pos = elementText.indexOf(ASNToXMLConverter.TAG_SEPARATOR); if (pos > 0) { elementText = elementText.substring(0, pos); } Class[] classes = object.getClass().getClasses(); Object[] objects = null; if (classes.length >= 1) { objects = classes[0].getEnumConstants(); Object objFind = null; for (int i = 0; i < objects.length; i++) { objFind = objects[i]; if (objFind.toString().equals(elementText)) { break; } } // not a simple value so return return objFind; } return null; } else { String classNameCurrent = type.substring(type.lastIndexOf(".") + 1); if (!className.equals("") && (type.contains(className)) && (!(type.equals(className + classNameCurrent)))) { // static class : h225.h323_className$staticClass type = type.substring(0, type.lastIndexOf(".")) + "$" + type.substring(type.lastIndexOf(".") + 1); } // calculate the element name to build the result path String elementName = element.getName(); int iPos = elementName.indexOf(ASNToXMLConverter.TAG_SEPARATOR); if (iPos > 0) { elementName = elementName.substring(0, iPos); } resultPath = resultPath + "." + elementName; Object obj = Class.forName(type).newInstance(); //Object objComplexClass = this.instanceClass(obj.getClass().getName(), className); parseFromXML(resultPath, message, obj, element, className); // not a simple value so return return obj; } // get the condition for embedded objects String elementName = resultPath; int iPos = resultPath.lastIndexOf("."); if (iPos > 0) { elementName = resultPath.substring(iPos + 1); } String condition = elementName + "=" + value; List<Embedded> embeddedList = ASNDictionary.getInstance().getEmbeddedByCondition(condition); if (embeddedList != null) { message.addConditionalEmbedded(embeddedList); } return value; }