Java Code Examples for org.dom4j.Node

The following are top voted examples for showing how to use org.dom4j.Node. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: atlas   File: AtlasProxy.java   View source code 9 votes vote down vote up
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);
                }

            }

        }

    }
 
Example 2
Project: joai-project   File: DocMap.java   View source code 7 votes vote down vote up
/**
 *  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);
	}
}
 
Example 3
Project: epay   File: AlipaySubmit.java   View source code 6 votes vote down vote up
/**
    * 用于防钓鱼,调用接口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();
   }
 
Example 4
Project: framework   File: AlipaySubmit.java   View source code 6 votes vote down vote up
/**
 * 用于防钓鱼,调用接口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();
}
 
Example 5
Project: iBase4J-Common   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * 将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;
}
 
Example 6
Project: atlas   File: XmlHelper.java   View source code 6 votes vote down vote up
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);
    }
 
Example 7
Project: maven-package-gui-installer   File: Application.java   View source code 6 votes vote down vote up
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;
}
 
Example 8
Project: joai-project   File: SchemaHelper.java   View source code 6 votes vote down vote up
/**
 *  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 "";
}
 
Example 9
Project: iBase4J   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * 将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;
}
 
Example 10
Project: joai-project   File: DocMap.java   View source code 6 votes vote down vote up
/**
 *  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 : "");
}
 
Example 11
Project: joai-project   File: DocMap.java   View source code 6 votes vote down vote up
/**
 *  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);
	}
}
 
Example 12
Project: parabuild-ci   File: ConvertToARFF.java   View source code 6 votes vote down vote up
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);
}
 
Example 13
Project: joai-project   File: ADNToOAIDCFormatConverter.java   View source code 6 votes vote down vote up
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 );				
				}				
			}
		}			
	}			
}
 
Example 14
Project: atlas   File: ManifestFileUtils.java   View source code 6 votes vote down vote up
/**
 * 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);
                    }
                }
            }
        }
    }
}
 
Example 15
Project: joai-project   File: SchemEditForm.java   View source code 6 votes vote down vote up
/**
 *  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 "";
}
 
Example 16
Project: joai-project   File: FrameworkConfigReader.java   View source code 6 votes vote down vote up
/**
 *  Gets the schemaPathMap attribute of the FrameworkConfigReader object
 *
 * @return    The schemaPathMap value
 */
public SchemaPathMap getSchemaPathMap() {
	if (this.schemaPathMap == null) {
		// prtln ("getSchemaPathMap()");
		schemaPathMap = new SchemaPathMap();
		Node schemaPathsNode = getNode("/frameworkConfigRecord/schemaInfo/paths");
		if (schemaPathsNode != null) {
			Element schemaPathsElement = (Element) schemaPathsNode;
			for (Iterator i = schemaPathsElement.elementIterator(); i.hasNext(); ) {
				Element pathElement = (Element) i.next();
				SchemaPath schemaPath = new SchemaPath(pathElement);
				schemaPathMap.putPath(schemaPath);
			}
		}
	}
	return schemaPathMap;
}
 
Example 17
Project: joai-project   File: FrameworkConfigReader.java   View source code 6 votes vote down vote up
/**
 *  Gets the pageList attribute of the FrameworkConfigReader object
 *
 * @return    The pageList value
 */
public PageList getPageList() {
	if (this.pageList == null) {
		pageList = new PageList();
		Node editorPagesNode = getNode("/frameworkConfigRecord/editorInfo/editorPages");
		if (editorPagesNode != null) {
			Element fieldInfoElement = (Element) editorPagesNode;
			for (Iterator i = fieldInfoElement.elementIterator(); i.hasNext(); ) {
				Element editorPage = (Element) i.next();
				String pageLabel = editorPage.attributeValue("pageLabel");
				String elementName = editorPage.getText();
				pageList.addPage(elementName, pageLabel);
			}
		}
		String firstPage = getNodeText("/frameworkConfigRecord/editorInfo/firstPage");
		if (firstPage == null || firstPage.trim().length() == 0)
			firstPage = this.getRootElementName();
		pageList.setFirstPage(firstPage);
		pageList.setHomePage(getXmlFormat() + ".index");
	}
	return pageList;
}
 
Example 18
Project: joai-project   File: CollectionConfigReader.java   View source code 6 votes vote down vote up
/**
 *  Gets the statusMap attribute of the CollectionConfigReader object
 *
 * @return    The statusMap value
 */
public Map getStatusMap() {
	if (statusMap == null) {
		statusMap = new HashMap();
		Node statusFlagsNode = getNode(statusFlagsPath);
		if (statusFlagsNode != null) {
			Element statusFlagsElement = (Element) statusFlagsNode;
			for (Iterator i = statusFlagsElement.elementIterator(); i.hasNext(); ) {
				Element statusFlagElement = (Element) i.next();
				try {
					StatusFlag statusFlag = new StatusFlag(statusFlagElement);
					statusMap.put(statusFlag.getLabel(), statusFlag);
				} catch (Exception e) {
					prtln("getStatusMapError: " + e.getMessage());
				}
			}
		}
	}
	return statusMap;
}
 
Example 19
Project: joai-project   File: CollectionConfigReader.java   View source code 6 votes vote down vote up
/**
 *  NOTE: if we edit the config record via schemedit, the record is
 *  automatically updated and then we have to reload it. But if we edit the
 *  statusMap via another editor, then this method is necessary to update the
 *  config file
 *
 * @param  sMap           The new statusMap value
 * @exception  Exception  NOT YET DOCUMENTED
 */
public void setStatusMap(Map sMap) throws Exception {
	// prtln ("setStatusMap()");
	Node statusFlagsNode = getNode(statusFlagsPath);
	if (statusFlagsNode == null) {
		statusFlagsNode = getDocMap().createNewNode(statusFlagsPath);
		if (statusFlagsNode == null)
			throw new Exception("statusMap node could not found or created");
	}
	Element statusFlagsElement = (Element) statusFlagsNode;
	statusFlagsElement.clearContent();
	statusMap = null;

	for (Iterator i = sMap.keySet().iterator(); i.hasNext(); ) {
		String status = (String) i.next();
		String description = (String) sMap.get(status);

		Element statusFlag = statusFlagsElement.addElement("statusFlag");

		Element statusElement = statusFlag.addElement("status");
		statusElement.setText(status);

		Element descriptionElement = statusFlag.addElement("description");
		descriptionElement.setText(description);
	}
}
 
Example 20
Project: joai-project   File: CollectionConfigReader.java   View source code 6 votes vote down vote up
/**
 *  Sets the tupleMap attribute of the CollectionConfigReader object
 *
 * @param  tMap           The new tupleMap value
 * @exception  Exception  NOT YET DOCUMENTED
 */
public void setTupleMap(Map tMap) throws Exception {
	Node tuplesNode = getNode(tuplesPath);
	if (tuplesNode == null) {
		tuplesNode = getDocMap().createNewNode(tuplesPath);
		if (tuplesNode == null)
			throw new Exception("tupleMap node could not found or created");
	}
	Element tuplesElement = (Element) tuplesNode;
	tuplesElement.clearContent();
	tupleMap = null;

	for (Iterator i = tMap.keySet().iterator(); i.hasNext(); ) {
		String name = (String) i.next();
		String value = (String) tMap.get(name);

		Element tuple = tuplesElement.addElement("tuple");

		Element statusElement = tuple.addElement("name");
		statusElement.setText(name);

		Element descriptionElement = tuple.addElement("value");
		descriptionElement.setText(value);
	}
}
 
Example 21
Project: JAVA-   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * 将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;
}
 
Example 22
Project: parabuild-ci   File: EclipseClasspath.java   View source code 5 votes vote down vote up
public Plugin(String directory, boolean isDependent)
		throws DocumentException, EclipseClasspathException, IOException {
	this.directory = directory;
	this.isDependent = isDependent;
	this.requiredPluginIdList = new LinkedList<String>();
	this.exportedLibraryList = new LinkedList<String>();

	// Figure out whether this is an old-style (Eclipse 2.1.x)
	// or new-style (3.0, OSGI-based) plugin.

	boolean oldStyle = false;

	Document document = null;
	File pluginDescriptorFile = new File(directory + File.separator + "plugin.xml");
	if (pluginDescriptorFile.isFile()) {
		SAXReader reader = new SAXReader();
		document = reader.read(new EclipseXMLReader(new FileReader(pluginDescriptorFile)));

		Node plugin = document.selectSingleNode("/plugin");
		if (plugin == null)
			throw new EclipseClasspathException("No plugin node in plugin descriptor");

		oldStyle = !plugin.valueOf("@id").equals("");
	}

	// Get the plugin id

	if (oldStyle) {
		parseOldPluginDescriptor(directory, document, isDependent);
	} else {
		parseNewPluginDescriptor(directory, isDependent);
	}
}
 
Example 23
Project: joai-project   File: SchemaHelperTester.java   View source code 5 votes vote down vote up
/**
 *  Displays specific info about all the SchemaNodeMap schemaNodes that wrap
 *  attribute elements from the schema
 */
public void displayAttributes() {
	prtln("Attributes from the SchemaNodeMap");
	List attrXPaths = schemaNodeMap.getKeys(Node.ATTRIBUTE_NODE);
	for (Iterator i = attrXPaths.iterator(); i.hasNext(); ) {
		String xpath = (String) i.next();
		SchemaNode schemaNode = (SchemaNode) schemaNodeMap.getValue(xpath);
		String use = schemaNode.getAttr("use");
		// prtln("\n" + xpath + "\n\tdataType: " + schemaNode.getDataTypeName() + "\n\tuse: " + use);
		prtln("\n" + xpath + "\n\tdataType: " + schemaNode.getTypeDef().getName() + "\n\tuse: " + use);
	}
}
 
Example 24
Project: lams   File: AbstractType.java   View source code 5 votes vote down vote up
protected static void replaceNode(Node container, Element value) {
	if ( container!=value ) { //not really necessary, I guess...
		Element parent = container.getParent();
		container.detach();
		value.setName( container.getName() );
		value.detach();
		parent.add(value);
	}
}
 
Example 25
Project: joai-project   File: NsdlDcReader.java   View source code 5 votes vote down vote up
private String getValue (String xpath) {
	XPath xpathObj = DocumentHelper.createXPath(xpath);
	xpathObj.setNamespaceURIs(getNSMap());
	Node node = xpathObj.selectSingleNode(doc);
	if (node != null)
		return node.getText();
	else
		return null;
}
 
Example 26
Project: sonarqube-rule-xml-generator   File: RuleXmlGenerator.java   View source code 5 votes vote down vote up
private Node findByType(List<Node> findbugsAbstract, String type) {
    for (Node node : findbugsAbstract) {
        if (Objects.equal(type, node.valueOf("@type"))) {
            return node;
        }
    }
    throw new IllegalArgumentException("cannot find " + type);
}
 
Example 27
Project: xpath-to-xml   File: Dom4jNavigator.java   View source code 5 votes vote down vote up
@Override
public void remove(Dom4jNode node) {
    final Node wrappedNode = node.getNode();
    final Element parent = wrappedNode.getParent();
    if (parent != null) {
        parent.remove(wrappedNode);
    } else {
        throw new XmlBuilderException("Unable to remove node " + node
                + ". Node either root or in detached state");
    }
}
 
Example 28
Project: iunet-blog   File: XmlUtil.java   View source code 5 votes vote down vote up
public static String tryGetItemText(Node node, String itemName, String defaultValue) {
	if (node == null)
		return defaultValue;

	Node item = node.selectSingleNode(itemName);
	if (item == null)
		return defaultValue;

	return item.getText();
}
 
Example 29
Project: TestDemo1-github   File: Dom4jHelper.java   View source code 5 votes vote down vote up
/**
 * 遍历解析元素
 * @param element
 */
public void treeWalk(Element element) {
    for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
        Node node = element.node(i);
        if ( node instanceof Element ) {
            treeWalk( (Element) node );
        }
        else {
            // 处理....
        }
    }
}
 
Example 30
Project: joai-project   File: WebServiceClient.java   View source code 5 votes vote down vote up
/**
 *  Gets the responseError attribute of the WebServiceClient class
 *
 *@param  doc  Description of the Parameter
 *@return      The responseError value
 */
public static String getResponseError(Document doc) {
	try {
		Node errorNode = doc.selectSingleNode("/DDSWebService/error");
		if (errorNode != null) {
			return errorNode.getText().trim();
		}
	} catch (Exception e) {
		prtln("getResponseError() " + e);
	}
	return "";
}
 
Example 31
Project: joai-project   File: NewsOppsFileIndexingWriter.java   View source code 5 votes vote down vote up
public String[] getUrls() throws Exception {
	// Announcement url
	Node node = getDom4jDoc().selectSingleNode("/news-oppsRecord/announcementURL");
	if (node == null)
		return null;
	return new String[]{node.getText()};
}
 
Example 32
Project: parabuild-ci   File: CheckMessages.java   View source code 5 votes vote down vote up
public Attribute checkAttribute(Node node, String attrName) throws DocumentException {
	if (!(node instanceof Element))
		throw new CheckMessagesException("Node is not an element", this, node);
	Element element = (Element) node;
	Attribute attr = element.attribute(attrName);
	if (attr == null)
		throw new CheckMessagesException("Missing " + attrName + " attribute", this, node);
	return attr;
}
 
Example 33
Project: joai-project   File: NewsOppsFileIndexingWriter.java   View source code 5 votes vote down vote up
private Date getPostDate() throws Exception {
	Date date = null;
	Node node = getDom4jDoc().selectSingleNode("/news-oppsRecord/postDate");
	if (node != null)
		date = MetadataUtils.parseUnionDateType(node.getText());
	return date;
}
 
Example 34
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View source code 5 votes vote down vote up
/**
 *  Returns the accession date or null if this collection is not currently accessioned.
 *
 * @return                The accession date or null
 * @exception  Exception  This method should throw and Exception with appropriate error message if an error
 *      occurs.
 */
protected Date getAccessionDate() throws Exception {
	if (!getAccessionStatus().equals("accessioned"))
		return null;
	Node dateElement = getDom4jDoc().selectSingleNode("/collectionRecord/approval/collectionStatuses/collectionStatus[@state='Accessioned']");
	if (dateElement != null)
		return MetadataUtils.parseUnionDateType(((Element) dateElement).attribute("date").getText());
	return null;
}
 
Example 35
Project: parabuild-ci   File: CheckMessages.java   View source code 5 votes vote down vote up
/**
 * Build collection of the values of given attribute
 * in all nodes matching given XPath expression.
 */
public Set<String> collectAttributes(String xpath, String attrName)
	throws DocumentException {
	HashSet<String> result = new HashSet<String>();

	for (Iterator i = xpathIterator(xpath); i.hasNext(); ) {
		Node node = (Node) i.next();
		String value = checkAttribute(node, attrName).getValue();
		result.add(value);
	}

	return result;
}
 
Example 36
Project: atlas   File: ManifestFileUtils.java   View source code 5 votes vote down vote up
private static void fillFullClazzName(Element root, String packageName, String type) {
    List<? extends Node> applicatNodes = root.selectNodes("//" + type);
    for (Node node : applicatNodes) {
        Element element = (Element)node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (attribute.getValue().startsWith(".")) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }
}
 
Example 37
Project: joai-project   File: SequenceGuard.java   View source code 5 votes vote down vote up
/**
 *  NOT YET DOCUMENTED
 *
 * @param  node  NOT YET DOCUMENTED
 * @return       NOT YET DOCUMENTED
 */
static String pp(Node node) {
	try {
		return (Dom4jUtils.prettyPrint(node));
	} catch (Exception e) {
		return (e.getMessage());
	}
}
 
Example 38
Project: joai-project   File: ChoiceGuard.java   View source code 5 votes vote down vote up
/**
 *  NOT YET DOCUMENTED
 *
 * @param  node  NOT YET DOCUMENTED
 * @return       NOT YET DOCUMENTED
 */
static String pp(Node node) {
	try {
		return (Dom4jUtils.prettyPrint(node));
	} catch (Exception e) {
		return (e.getMessage());
	}
}
 
Example 39
Project: xpath-to-xml   File: Dom4jNavigator.java   View source code 5 votes vote down vote up
@Override
public void prependCopy(Dom4jNode node) throws XmlBuilderException {
    final Node wrappedNode = node.getNode();
    if (Node.ELEMENT_NODE != wrappedNode.getNodeType()) {
        throw new XmlBuilderException("Unable to copy non-element node " + node);
    }
    final Element parent = wrappedNode.getParent();
    if (null == parent) {
        throw new XmlBuilderException("Unable to prepend - no parent found of " + node);
    }
    final int prependIndex = parent.indexOf(wrappedNode);
    final Element copiedNode = ((Element) wrappedNode).createCopy();
    parent.elements().add(prependIndex, copiedNode);
}
 
Example 40
Project: joai-project   File: CompositorGuard.java   View source code 5 votes vote down vote up
/**
 *  NOT YET DOCUMENTED
 *
 * @param  node  NOT YET DOCUMENTED
 * @return       NOT YET DOCUMENTED
 */
static String pp(Node node) {
	try {
		return (Dom4jUtils.prettyPrint(node));
	} catch (Exception e) {
		return (e.getMessage());
	}
}