List of usage examples for org.dom4j Node getName
String getName();
getName
returns the name of this node.
From source file:com.beetle.framework.resource.container.ContainerConfig.java
License:Apache License
/** * ????// w w w. j av a 2s .c om * * @return */ public static List<String> getAllTagNameOfFile() { List<String> names = new ArrayList<String>(); Document doc; try { doc = XMLReader.getXmlDoc(sysconfigFileName); } catch (Exception e) { try { doc = XMLReader.getXmlDoc("SysConfig.xml"); } catch (Exception e1) { doc = null; e1.printStackTrace(); } } if (doc != null) { List<?> nodeList = doc.selectNodes("/Config/Containers/*"); for (int i = 0; i < nodeList.size(); i++) { Node node = (Node) nodeList.get(i); names.add(node.getName()); } nodeList.clear(); } return names; }
From source file:com.boyuanitsm.pay.alipay.util.AlipaySubmit.java
License:Apache License
/** * ?query_timestamp???// ww w. ja va2 s. c om * ??XML???SSL? * @return * @throws IOException * @throws DocumentException * @throws MalformedURLException */ public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { //query_timestamp?URL String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // ????? if (node.getName().equals("is_success") && node.getText().equals("T")) { // ?? List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
From source file:com.dtolabs.shared.resources.ResourceXMLParser.java
License:Apache License
/** * Given xml Node and EntitySet, parse the entity defined in the Node * * @param node DOM node/*from www .j av a2s . c om*/ * @param set entity set holder * * @return parsed Entity object * * @throws ResourceXMLParserException if entity definition was previously found, or another error occurs */ private Entity parseEnt(final Node node, final EntitySet set) throws ResourceXMLParserException { final Entity ent = parseResourceRef(set, node); ent.setResourceType(node.getName()); parseEntProperties(ent, node); parseEntSubAttributes(ent, node); return ent; }
From source file:com.dtolabs.shared.resources.ResourceXMLParser.java
License:Apache License
/** * Parse the DOM attributes as properties for the particular entity node type * * @param ent Entity object//from www . java 2s. com * @param node entity DOM node * * @throws ResourceXMLParserException if the DOM node is an unexpected tag name */ private void parseEntProperties(final Entity ent, final Node node) throws ResourceXMLParserException { if (null == entityProperties.get(node.getName())) { throw new ResourceXMLParserException( "Unexpected entity declaration: " + node.getName() + ": " + reportNodeErrorLocation(node)); } final Element node1 = (Element) node; //load all element attributes as properties for (final Object o : node1.attributes()) { final Attribute attr = (Attribute) o; ent.properties.setProperty(attr.getName(), attr.getStringValue()); } }
From source file:com.feilong.framework.bind.parse.base.StandardXpathExpressionXmlParse.java
License:Apache License
@Override protected Map<String, String> getVarNameAndValueMap(String xml) { if (Validator.isNullOrEmpty(xml)) { throw new IllegalArgumentException("xml can't be null/empty!"); }//from w w w. j a va 2 s.c om Document document = Dom4jUtil.string2Document(xml); @SuppressWarnings("unchecked") List<Node> selectNodes = document.selectNodes(xpathExpression); Map<String, String> varNameAndValueMap = new TreeMap<String, String>(); for (Node node : selectNodes) { String varName = node.getName(); String stringValue = node.getStringValue(); varNameAndValueMap.put(varName, stringValue); } if (log.isDebugEnabled()) { log.debug("varNameAndValueMap:{}", JsonUtil.format(varNameAndValueMap)); } return varNameAndValueMap; }
From source file:com.feilong.framework.netpay.advance.adaptor.doku.util.DokuQueryResultParse.java
License:Apache License
/** * ? wddxPacketXML ,? var name .//from w w w . ja va 2 s. c om * * @param xml * the wddx packet xml * @return the var name and value map */ @Override protected Map<String, String> getVarNameAndValueMap(String xml) { Document document = Dom4jUtil.string2Document(xml); @SuppressWarnings("unchecked") List<Node> selectNodes = document.selectNodes(XPATH_EXPRESSION_VAR); Map<String, String> varNameAndValueMap = new HashMap<String, String>(); for (Node node : selectNodes) { String varName = node.getName(); String stringValue = node.getStringValue(); varNameAndValueMap.put(varName, stringValue); } if (log.isDebugEnabled()) { log.debug("varNameAndValueMap:{}", JsonUtil.format(varNameAndValueMap)); } return varNameAndValueMap; }
From source file:com.feilong.framework.netpay.payment.adaptor.alipay.pconline.AlipayOnlineAdaptor.java
License:Apache License
/** * ?query_timestamp??? <br>/*w w w.j a v a2s .c o m*/ * ??XML???SSL?. * * @return */ private final String getAnti_phishing_key() { // query_timestamp?URL StringBuilder sb = new StringBuilder(); sb.append(gateway); sb.append("?"); sb.append("service=" + service_query_timestamp); sb.append("&"); sb.append("partner=" + partner); InputStream inputStream = null; try { URL url = new URL(sb.toString()); inputStream = url.openStream(); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(inputStream); if (log.isDebugEnabled()) { log.debug("document:{}", document.toString()); // <alipay> // <is_success>T</is_success> // <request> // <param name="service">query_timestamp</param> // <param name="partner">2088201564862550</param> // </request> // <response> // <timestamp> // <encrypt_key>KPr8DuZp5xc031OVxw==</encrypt_key> // </timestamp> // </response> // <sign>1fc434a9045f5681736cd47ee2faa41a</sign> // <sign_type>MD5</sign_type> // </alipay> } StringBuilder result = new StringBuilder(); @SuppressWarnings("unchecked") List<Node> nodeList = document.selectNodes("//alipay/*"); for (Node node : nodeList) { // ????? String name = node.getName(); String text = node.getText(); if (name.equals("is_success") && text.equals("T")) { // ?? @SuppressWarnings("unchecked") List<Node> nodeList1 = document.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } String anti_phishing_key = result.toString(); if (log.isDebugEnabled()) { log.debug("anti_phishing_key value:[{}]", anti_phishing_key); } return anti_phishing_key; } catch (MalformedURLException e) { log.error(e.getClass().getName(), e); } catch (IOException e) { throw new UncheckedIOException(e); } catch (DocumentException e) { log.error(e.getClass().getName(), e); } finally { try { if (null != inputStream) { inputStream.close(); } } catch (IOException e) { throw new UncheckedIOException(e); } } // ?,??? return ""; }
From source file:com.flaptor.hounder.indexer.FieldFormatCheckerModule.java
License:Apache License
/** * Processes the document. Takes the xml document, prints it to the logger, * and returns the same document./*from w w w . j a va 2 s .c om*/ */ protected Document[] internalProcess(final Document doc) { // check that this is a documentAdd // otherwise, skip. Node root = doc.getRootElement(); if (!root.getName().equals("documentAdd")) return new Document[] { doc }; for (String longField : longFields) { Node node = doc.selectSingleNode("//field[@name='" + longField + "']"); if (null == node) { logger.error("Document lacks field " + longField + ". Dropping document. "); if (logger.isDebugEnabled()) { logger.debug(DomUtil.domToString(doc) + " lacks field " + longField); } return new Document[0]; } String text = node.getText(); try { Long.parseLong(text); } catch (NumberFormatException e) { logger.error( "Document has field " + longField + ", but it is not parseable as Long. Dropping document"); if (logger.isDebugEnabled()) { logger.debug(DomUtil.domToString(doc) + " contains field " + longField + " but it is not parseable as Long. Node:" + node.toString() + " - text: " + text); } return new Document[0]; } } // TODO insert more field type checks here Document[] docs = { doc }; return docs; }
From source file:com.funtl.framework.alipay.trade.util.AlipaySubmit.java
License:Apache License
/** * ?query_timestamp???/* www . jav a 2 s .com*/ * ??XML???SSL? * * @return * @throws IOException * @throws DocumentException * @throws MalformedURLException */ public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { //query_timestamp?URL String strUrl = PayManager.HTTPS_MAPI_ALIPAY_COM_GATEWAY_DO + "?" + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // ????? if (node.getName().equals("is_success") && node.getText().equals("T")) { // ?? List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
private void elementNodeProcessor(Node p_node, boolean p_isSource) { Element element = (Element) p_node; String eleStr = element.asXML(); String elementName = element.getName(); boolean isHeaderInfoUT = false; boolean isTuId = false; if (TTXConstants.TU.equalsIgnoreCase(elementName) || (element.getParent() != null && TTXConstants.TUV.equalsIgnoreCase(element.getParent().getName()))) { // latestPosition = TTXConstants.IN_TU; } else if (TTXConstants.UT.equalsIgnoreCase(elementName)) { Attribute att = element.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (att != null) { String value = att.getValue(); // If header info,return as header info has been handled // separately. // This check is not required. isHeaderInfoUT = isHeaderInfo(value); if (isHeaderInfoUT) { return; }/*from w w w . j a va 2 s . co m*/ // If TuId,handle them here. isTuId = isTuId(value); if (isTuId) { // latestPosition = TTXConstants.TU_ID; String tuId = value.substring(value.indexOf(":") + 1).trim(); if (results != null && results.length() > 0) { results.append(TTXConstants.NEW_LINE).append(TTXConstants.NEW_LINE); } results.append(TTXConstants.HASH_MARK).append(tuId).append(TTXConstants.NEW_LINE); return; } } } if (element.nodeCount() > 0) { Iterator nodesIt = element.nodeIterator(); while (nodesIt.hasNext()) { Node node = (Node) nodesIt.next(); String nodeStr = node.asXML(); String nodeName = node.getName(); if (TTXConstants.TUV.equalsIgnoreCase(node.getName())) { Attribute langAtt = ((Element) node).attribute(TTXConstants.TUV_ATT_LANG); String lang = null; if (langAtt != null) { lang = langAtt.getValue(); } if (sourceLanguage != null && sourceLanguage.equals(lang)) { // latestPosition = TTXConstants.IN_SOURCE_TUV; // Not handle source TUV for TTX off-line uploading. // domNodehandler(node, true); } else { // latestPosition = TTXConstants.IN_TARGET_TUV; domNodehandler(node, false); } } else { domNodehandler(node, false); } } } else { if (TTXConstants.UT.equalsIgnoreCase(elementName)) { Attribute displayTextAtt = element.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (displayTextAtt != null) { String attValue = displayTextAtt.getValue(); if (attValue != null && attValue.startsWith(TTXConstants.TU_ID)) { // latestPosition = TTXConstants.TU_ID; String tuId = attValue.substring(attValue.indexOf(":") + 1).trim(); if (results != null && results.length() > 0) { results.append(TTXConstants.NEW_LINE).append(TTXConstants.NEW_LINE); } results.append(TTXConstants.HASH_MARK).append(tuId).append(TTXConstants.NEW_LINE); } else if (attValue != null && attValue.startsWith(TTXConstants.GS)) { Attribute typeValueAtt = element.attribute(TTXConstants.UT_ATT_TYPE); String typeValue = null; if (typeValueAtt != null) { typeValue = typeValueAtt.getValue(); } String gsTag = attValue.substring(attValue.indexOf(":") + 1).trim(); if (typeValue != null && TTXConstants.UT_ATT_TYPE_START.equalsIgnoreCase(typeValue)) { results.append("[").append(gsTag).append("]"); } else if (typeValue != null && TTXConstants.UT_ATT_TYPE_END.equalsIgnoreCase(typeValue)) { results.append("[/").append(gsTag).append("]"); } else { results.append("[").append(gsTag).append("]"); results.append("[/").append(gsTag).append("]"); } } } } else if (TTXConstants.DF.equalsIgnoreCase(elementName)) { // do not handle this. } } }