List of usage examples for org.dom4j Element getText
String getText();
From source file:com.atlassian.jira.plugin.license.LicenseRoleModuleDescriptorImpl.java
License:Open Source License
private static String stripAndAssertNotBlank(final Element element, final String childName) throws PluginParseException { final Element child = element.element(childName); if (child == null) { throw new PluginParseException(format("License role requires '%s' child element.", childName)); }// w w w .j av a2 s . c o m String result = stripToNull(child.getText()); if (result == null) { throw new PluginParseException(format("License role element '%s' must have a value.", childName)); } return result; }
From source file:com.baomidou.springwind.util.yuntongxin.CCPRestSDK.java
License:Open Source License
/** * @description xml??map// ww w. java 2s. co m * @param xml * @return Map */ private HashMap<String, Object> xmlToMap(String xml) { HashMap<String, Object> map = new HashMap<String, Object>(); org.dom4j.Document doc = null; try { doc = org.dom4j.DocumentHelper.parseText(xml); // XML org.dom4j.Element rootElt = doc.getRootElement(); // ? HashMap<String, Object> hashMap2 = new HashMap<String, Object>(); ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>(); for (Iterator i = rootElt.elementIterator(); i.hasNext();) { org.dom4j.Element e = (org.dom4j.Element) i.next(); if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName())) map.put(e.getName(), e.getText()); else { if ("SubAccount".equals(e.getName()) || "TemplateSMS".equals(e.getName()) || "totalCount".equals(e.getName()) || "token".equals(e.getName()) || "callSid".equals(e.getName()) || "state".equals(e.getName()) || "downUrl".equals(e.getName())) { if (!"SubAccount".equals(e.getName()) && !"TemplateSMS".equals(e.getName())) { hashMap2.put(e.getName(), e.getText()); } else if ("SubAccount".equals(e.getName())) { HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { org.dom4j.Element e2 = (org.dom4j.Element) i2.next(); hashMap3.put(e2.getName(), e2.getText()); } arrayList.add(hashMap3); hashMap2.put("SubAccount", arrayList); } else if ("TemplateSMS".equals(e.getName())) { HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { org.dom4j.Element e2 = (org.dom4j.Element) i2.next(); hashMap3.put(e2.getName(), e2.getText()); } arrayList.add(hashMap3); hashMap2.put("TemplateSMS", arrayList); } map.put("data", hashMap2); } else { HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { org.dom4j.Element e2 = (org.dom4j.Element) i2.next(); // hashMap2.put(e2.getName(),e2.getText()); hashMap3.put(e2.getName(), e2.getText()); } if (hashMap3.size() != 0) { hashMap2.put(e.getName(), hashMap3); } else { hashMap2.put(e.getName(), e.getText()); } map.put("data", hashMap2); } } } } catch (org.dom4j.DocumentException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } return map; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing token definition. * //from w w w .j a v a2 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 container definition. * * @param e XML DOM element// w ww . ja v a2 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.bizideal.whoami.utils.cloopen.CCPRestSmsSDK.java
License:Open Source License
/** * @description xml??map//from www. j a v a2 s.c o m * @param xml * @return Map */ private HashMap<String, Object> xmlToMap(String xml) { HashMap<String, Object> map = new HashMap<String, Object>(); Document doc = null; try { doc = DocumentHelper.parseText(xml); // XML Element rootElt = doc.getRootElement(); // ? HashMap<String, Object> hashMap2 = new HashMap<String, Object>(); for (Iterator i = rootElt.elementIterator(); i.hasNext();) { Element e = (Element) i.next(); if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName())) map.put(e.getName(), e.getText()); else { if ("SubAccount".equals(e.getName()) || "totalCount".equals(e.getName()) || "token".equals(e.getName()) || "downUrl".equals(e.getName())) { if (!"SubAccount".equals(e.getName())) { hashMap2.put(e.getName(), e.getText()); } else { ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { Element e2 = (Element) i2.next(); hashMap3.put(e2.getName(), e2.getText()); arrayList.add(hashMap3); } hashMap2.put("SubAccount", arrayList); } map.put("data", hashMap2); } else { HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { Element e2 = (Element) i2.next(); // hashMap2.put(e2.getName(),e2.getText()); hashMap3.put(e2.getName(), e2.getText()); } if (hashMap3.size() != 0) { hashMap2.put(e.getName(), hashMap3); } else { hashMap2.put(e.getName(), e.getText()); } map.put("data", hashMap2); } } } } catch (DocumentException e) { e.printStackTrace(); LoggerUtil.error(e.getMessage()); } catch (Exception e) { LoggerUtil.error(e.getMessage()); e.printStackTrace(); } return map; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ,//w w w . j av a 2 s . c o m * * @param element * * @param optional * * @return * @throws XMLDocException * @throws BaseException */ public static String getContent(Element element, boolean optional) throws BaseException { String content = element.getText(); if (content == null && !optional) { throw new BaseException("UTIL-0001", element.getName() + " element: content expected."); } else { return content; } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ?Element???/*from ww w .j a v a 2s . co m*/ * * * * * * @param element * Element * @return String */ public static String getElementContext(Element element) { if (element == null) { return null; } String str = element.getText(); Element tmp = null; for (Iterator i = element.elementIterator(); i.hasNext();) { tmp = (Element) i.next(); str = str + tmp.asXML(); // do something } return str; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * //from w w w . j av a2s .c o m * @param element * Element * @param path * String * @param attr * String * @return String */ public static String getElementContext(Element element, String path, String attr) { Element el = element.element(path); if (attr == null || attr.trim().equals("")) { return el.getText(); } else { return el.attributeValue(attr); } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ?XPATH ?text "/path/@seq" ? "/path/" ? * /*from www . j av a 2 s .c o m*/ * @param element * Element * @param path * String * @return String * @throws BaseException */ public static String getElementContext(Element element, String path) throws BaseException { if (element == null || path == null) { return null; } Object o = element.selectSingleNode(path); if (o == null) { // return null; } if (o instanceof Element) { // 1? Element Element e = (Element) o; if (e.isTextOnly()) { // text only return e.getText(); } else { // element return generateXMLStringBuffer(e, "").toString(); } } else if (o instanceof Attribute) { // 2? Attribute return ((Attribute) o).getValue(); } else { // 3? Other node return generateXMLStringBuffer(o, "").toString(); } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ?XPATH ?text "/path/@seq" ? "/path/" ? * /*from w w w.ja v a2s. c om*/ * @param element * Element * @param path * String * @return String * @throws BaseException */ public static String[] getElementContextArray(Element element, String path) throws BaseException { if (element == null || path == null) { return null; } List nodes = element.selectNodes(path); String[] eleContext = new String[nodes.size()]; Iterator iter = nodes.iterator(); int length = 0; Object o = null; Element e = null; while (iter.hasNext()) { o = (Object) iter.next(); if (o instanceof Element) { // 1? Element e = (Element) o; if (e.isTextOnly()) { // text only eleContext[length] = e.getText(); length++; } else { // element eleContext[length] = generateXMLStringBuffer(e, "").toString(); length++; } } else if (o instanceof Attribute) { // 2? Attribute eleContext[length] = ((Attribute) o).getValue(); length++; } else { // 3? Other node eleContext[length] = generateXMLStringBuffer(o, "").toString(); length++; } } return eleContext; }