當前位置: 首頁>>代碼示例>>Java>>正文


Java Node類代碼示例

本文整理匯總了Java中org.dom4j.Node的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Node類屬於org.dom4j包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addAtlasProxyClazz

import org.dom4j.Node; //導入依賴的package包/類
public static void addAtlasProxyClazz(Document document, Set<String> nonProxyChannels,  Result result) {

        Element root = document.getRootElement();// Get the root node

        List<? extends Node> serviceNodes = root.selectNodes("//@android:process");

        String packageName = root.attribute("package").getStringValue();

        Set<String> processNames = new HashSet<>();
        processNames.add(packageName);

        for (Node node : serviceNodes) {
            if (null != node && StringUtils.isNotEmpty(node.getStringValue())) {
                String value = node.getStringValue();
                processNames.add(value);
            }
        }

        processNames.removeAll(nonProxyChannels);

        List<String> elementNames = Lists.newArrayList("activity", "service", "provider");

        Element applicationElement = root.element("application");

        for (String processName : processNames) {

            boolean isMainPkg = packageName.equals(processName);
            //boolean isMainPkg = true;
            String processClazzName = processName.replace(":", "").replace(".", "_");

            for (String elementName : elementNames) {

                String fullClazzName = "ATLASPROXY_" +  (isMainPkg ? "" : (packageName.replace(".", "_") + "_" )) +  processClazzName + "_" + StringUtils.capitalize(elementName);

                if ("activity".equals(elementName)) {
                    result.proxyActivities.add(fullClazzName);
                } else if ("service".equals(elementName)) {
                    result.proxyServices.add(fullClazzName);
                } else {
                    result.proxyProviders.add(fullClazzName);
                }

                Element newElement = applicationElement.addElement(elementName);
                newElement.addAttribute("android:name", ATLAS_PROXY_PACKAGE + "." + fullClazzName);

                if (!packageName.equals(processName)) {
                    newElement.addAttribute("android:process", processName);
                }

                boolean isProvider = "provider".equals(elementName);
                if (isProvider) {
                    newElement.addAttribute("android:authorities",
                                            ATLAS_PROXY_PACKAGE + "." + fullClazzName);
                }

            }

        }

    }
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:61,代碼來源:AtlasProxy.java

示例2: remove

import org.dom4j.Node; //導入依賴的package包/類
/**
 *  removes a node from the dom4j Document.
 *
 * @param  xpath  Description of the Parameter
 */
public void remove(String xpath) {
	Node node = doc.selectSingleNode(xpath);
	if (node == null) {
		// prtln("remove could not find node to delete (" + xpath + ")");
		return;
	}

	Element parent = node.getParent();
	if (parent == null) {
		// prtln("remove could not find parent of node to delete (" + xpath + ")");
		return;
	}
	if (!parent.remove(node)) {
		prtlnErr("failed to remove node at " + xpath);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:22,代碼來源:DocMap.java

示例3: query_timestamp

import org.dom4j.Node; //導入依賴的package包/類
/**
    * 用於防釣魚,調用接口query_timestamp來獲取時間戳的處理函數
    * 注意:遠程解析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();
   }
 
開發者ID:dianbaer,項目名稱:epay,代碼行數:34,代碼來源:AlipaySubmit.java

示例4: query_timestamp

import org.dom4j.Node; //導入依賴的package包/類
/**
 * 用於防釣魚,調用接口query_timestamp來獲取時間戳的處理函數
 * 注意:遠程解析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();
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:34,代碼來源:AlipaySubmit.java

示例5: MqResToDto

import org.dom4j.Node; //導入依賴的package包/類
/**
 * 將mq查詢結果包裝成list--dto的形式,dto內容為item中的內容
 * 
 * @param recv
 * @return
 */
public static Map MqResToDto(String recv) {
    // System.out.println("####recv"+recv);
    List res = new ArrayList();
    Map map = new HashMap();
    try {
        Document doc = DocumentHelper.parseText(recv);
        List list = doc.selectNodes("//item");
        Iterator<DefaultElement> it = list.iterator();
        while (it.hasNext()) {
            Map elementdto = XmlUtil.Dom2Map(it.next());
            res.add(elementdto);
        }
        map.put("resultList", res);// 放入結果集
        /* 如果存在REC_MNT,說明是分頁查詢類,需要將總記錄數返回 */
        Node de = doc.selectSingleNode("//REC_MNT");
        if (DataUtil.isNotEmpty(de)) {
            map.put("countInteger", de.getText());
        }
    } catch (Exception e) {
        logger.error("", e);
    }
    return map;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:30,代碼來源:XmlUtil.java

示例6: removeStringValue

import org.dom4j.Node; //導入依賴的package包/類
public static void removeStringValue(File file, String key) throws IOException, DocumentException {

        if (!file.exists()) {
            return;
        }

        Document document = XmlHelper.readXml(file);// Read the XML file
        Element root = document.getRootElement();// Get the root node
        List<? extends Node> nodes = root.selectNodes("//string");
        for (Node node : nodes) {
            Element element = (Element)node;
            String name = element.attributeValue("name");
            if (key.equals(name)) {
                element.getParent().remove(element);
                break;
            }
        }
        // sLogger.warn("[resxmlediter] add " + key + " to " + file.getAbsolutePath());
        XmlHelper.saveDocument(document, file);
    }
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:21,代碼來源:XmlHelper.java

示例7: readConfig

import org.dom4j.Node; //導入依賴的package包/類
private static String readConfig(List<String> configPaths) throws DocumentException {
    SAXReader reader = new SAXReader();
    for (String path : configPaths) {
        File file = new File(path);
        if (file.exists()) {
            Document doc = reader.read(file);
            Element root = doc.getRootElement();
            Iterator<Node> it = root.elementIterator();
            while (it.hasNext()) {
                Node node = it.next();
                if (node != null && "localRepository".equals(node.getName())) {
                    return node.getText();
                }
            }
        }
    }
    return null;
}
 
開發者ID:pingcai,項目名稱:maven-package-gui-installer,代碼行數:19,代碼來源:Application.java

示例8: getRepeatingComplexSingletonChildName

import org.dom4j.Node; //導入依賴的package包/類
/**
 *  Gets the qualified element name of the repeatingComplexSingleton child of
 *  the node specified by the provided path, or an empty string if such a child
 *  does not exist.
 *
 * @param  xpath  NOT YET DOCUMENTED
 * @return        The repeatingComplexSingletonChildName value
 */
public String getRepeatingComplexSingletonChildName(String xpath) {
	String normalizedXPath = XPathUtils.normalizeXPath(xpath);
	Node instanceDocNode = getInstanceDocNode(normalizedXPath);
	if (instanceDocNode != null && instanceDocNode.getNodeType() == org.dom4j.Node.ELEMENT_NODE) {
		List children = ((Element) instanceDocNode).elements();
		if (children.size() == 1) {
			Element childElement = (Element) children.get(0);
			String childPath = childElement.getPath();
			SchemaNode schemaNode = getSchemaNode(childPath);
			if (schemaNode != null && schemaNode.getTypeDef().isComplexType() && isRepeatingElement(childPath))
				return childElement.getQualifiedName();
		}
	}
	return "";
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:24,代碼來源:SchemaHelper.java

示例9: MqResToDto

import org.dom4j.Node; //導入依賴的package包/類
/**
 * 將mq查詢結果包裝成list--dto的形式,dto內容為item中的內容
 * 
 * @param recv
 * @return
 */
public static Map MqResToDto(String recv) {
	// System.out.println("####recv"+recv);
	List res = new ArrayList();
	Map map = new HashMap();
	try {
		Document doc = DocumentHelper.parseText(recv);
		List list = doc.selectNodes("//item");
		Iterator<DefaultElement> it = list.iterator();
		while (it.hasNext()) {
			Map elementdto = XmlUtil.Dom2Map(it.next());
			res.add(elementdto);
		}
		map.put("resultList", res);// 放入結果集
		/*
		 * 如果存在REC_MNT,說明是分頁查詢類,需要將總記錄數返回
		 */
		Node de = doc.selectSingleNode("//REC_MNT");
		if (DataUtil.isNotEmpty(de)) {
			map.put("countInteger", de.getText());
		}
	} catch (Exception e) {
		log.error(XmlUtil.class, e);
	}
	return map;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:32,代碼來源:XmlUtil.java

示例10: put

import org.dom4j.Node; //導入依賴的package包/類
/**
 *  Updates the Document by setting the Text of the Node at the specified
 *  xpath. If there is no node at the specified path, a new one is created.<p>
 *
 *  ISSUE: what if there is no value (one way this happens is when there is a
 *  field in the form but no value is supplied by user. In this case we
 *  shouldn't bother creating a new node because there is no value to insert.
 *  But what if there was formerly a value and the user has deleted it? if the
 *  node is an Element, then should that element be deleted? (The user should
 *  be warned first!) if the node is an attribute, then should that attribute
 *  be deleted? (the user won't be warned, since this does not have the
 *  "ripple" effect that deleting an element can have. (maybe the user should
 *  be warned only if the element has children with values).
 *
 * @param  key  unencoded xpath
 * @param  val  value to assign to node at xpath
 */
public void put(Object key, Object val) {
	String xpath = XPathUtils.decodeXPath((String) key);

	Node node = doc.selectSingleNode(xpath);
	if (node == null) {
		// prtln("DocMap.put(): creating new node for " + xpath);
		try {
			node = createNewNode(xpath);
		} catch (Exception e) {
			prtlnErr("DocMap.put(): couldn't create new node at \"" + xpath + "\": " + e);
			return;
		}
	}
	// 2/28/07 no longer trim values!
	/* 		String trimmed_val = "";
	if (val != null)
		trimmed_val = ((String) val).trim();
	node.setText(trimmed_val);*/
	node.setText(val != null ? (String) val : "");
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:38,代碼來源:DocMap.java

示例11: smartPut

import org.dom4j.Node; //導入依賴的package包/類
/**
 *  Tests xpath against provided schema (via SchemaHelper) before putting
 *  value, creating a new Node if one is not found at xpath.
 *
 * @param  xpath          NOT YET DOCUMENTED
 * @param  value          NOT YET DOCUMENTED
 * @exception  Exception  NOT YET DOCUMENTED
 */
public void smartPut(String xpath, String value) throws Exception {
	if (schemaHelper != null && schemaHelper.getSchemaNode(xpath) == null) {
		throw new Exception("stuffValue got an illegal xpath: " + xpath);
	}

	if (value == null)
		throw new Exception("stuffValue got a null value (which is illegal) for " + xpath);

	Node node = selectSingleNode(xpath);
	if (node == null)
		node = createNewNode(xpath);
	if (node == null)
		throw new Exception("smartPut failed to find or create node: " + xpath);
	else {
		// 2/18/07 no longer trim values!
		// node.setText(value.trim());
		node.setText(value);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:28,代碼來源:DocMap.java

示例12: getInstanceValue

import org.dom4j.Node; //導入依賴的package包/類
public String getInstanceValue(Element element, String appName) throws MissingNodeException {
	Object value = element.selectObject(xpath);
	if (value == null)
		throw new MissingNodeException("Could not get value from element (path=" +
			xpath + ")");
	if (value instanceof List) {
		List list = (List) value;
		value = list.get(0);
	}

	if (value instanceof Node) {
		Node node = (Node) value;
		return node.getText();
	} else if (value instanceof String) {
		return (String) value;
	} else if (value instanceof Number) {
		String s = value.toString();
		if (s.endsWith(".0"))
			s = s.substring(0, s.length() - 2);
		return s;
	} else
		throw new IllegalStateException("Unexpected object returned from xpath query: " + value);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:24,代碼來源:ConvertToARFF.java

示例13: handleRelationField

import org.dom4j.Node; //導入依賴的package包/類
private void handleRelationField(String xPathToField, Document xmlDocument)
{
	List nodes = xmlDocument.selectNodes( xPathToField );
	if(nodes != null){
		for(int i = 0; i< nodes.size(); i++){
			Node currentNode = (Node)nodes.get(i);
			String relation = currentNode.getText();
			
			// Insert the URL if an ID is present...
			if(!relation.toLowerCase().matches(".*http\\:\\/\\/.*|.*ftp\\:\\/\\/.*")){
				String relatedID = relation.substring(relation.indexOf(" ")+1,relation.length());
				
				ResultDocList results = 
					index.searchDocs("id:" + SimpleLuceneIndex.encodeToTerm(relatedID));
				if(results == null || results.size() == 0){
					currentNode.detach();
				}else{
					String url = ((ItemDocReader)((ResultDoc)results.get(0)).getDocReader()).getUrl();
					currentNode.setText(relation.substring(0,relation.indexOf(" ") + 1) + url );				
				}				
			}
		}			
	}			
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:25,代碼來源:ADNToOAIDCFormatConverter.java

示例14: removeCustomLaunches

import org.dom4j.Node; //導入依賴的package包/類
/**
 * Delete the custom header
 *
 * @param document
 * @param manifestOptions
 */
private static void removeCustomLaunches(Document document, ManifestOptions manifestOptions) {
    if (null == manifestOptions) {
        return;
    }
    Element root = document.getRootElement();// Get the root node
    // Update launch information
    if (manifestOptions.getRetainLaunches() != null && manifestOptions.getRetainLaunches().size() > 0) {
        List<? extends Node> nodes = root.selectNodes(
            "//activity/intent-filter/category|//activity-alias/intent-filter/category");
        for (Node node : nodes) {
            Element e = (Element)node;
            if ("android.intent.category.LAUNCHER".equalsIgnoreCase(e.attributeValue("name"))) {
                Element activityElement = e.getParent().getParent();
                String activiyName = activityElement.attributeValue("name");
                if (!manifestOptions.getRetainLaunches().contains(activiyName)) {
                    if (activityElement.getName().equalsIgnoreCase("activity-alias")) {
                        activityElement.getParent().remove(activityElement);
                    } else {
                        e.getParent().remove(e);
                    }
                }
            }
        }
    }
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:32,代碼來源:ManifestFileUtils.java

示例15: getAnyTypeValueOf

import org.dom4j.Node; //導入依賴的package包/類
/**
 *  Gets the anyTypeValueOf attribute of the SchemEditForm object
 *
 * @param  key  a jsp-encoded xpath
 * @return      The anyTypeValueOf value
 */
public Object getAnyTypeValueOf(String key) {
	// prtln("\nGET AnyTypeValueOf(): key = " + key);

	String xpath = XPathUtils.decodeXPath(key);
	// prtln ("\t decodedKey: " + xpath);
	if (this.inputManager != null) {

		String paramName = "anyTypeValueOf(" + key + ")";
		AnyTypeInputField field = (AnyTypeInputField) inputManager.getInputField(paramName);
		if (field != null && field.hasParseError())
			return field.getValue();
	}

	xpath = this.schemaHelper.encodeAnyTypeXpath(xpath);

	Node node = docMap.selectSingleNode(xpath);
	if (node != null) {
		return Dom4jUtils.prettyPrint(node);
	}
	return "";
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:28,代碼來源:SchemEditForm.java


注:本文中的org.dom4j.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。