Java Code Examples for org.dom4j.Element.getUniquePath()

The following are Jave code examples for showing how to use getUniquePath() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: joai-project   File: XMLQueryParser.java   View Source Code Vote up 6 votes
/**
 *  Gets the Lucene Query representation for the given XML Query starting at the Query element.
 *
 * @param  queryElement   A dom4j representation of the Query element
 * @param  queryParser    QueryParser used to parse Lucene syntax based queries and tokenize the text
 * @return                The Lucene Query object representation of this XML Query
 * @exception  Exception  If error
 */
public static Query getLuceneQuery(Element queryElement, QueryParser queryParser) throws Exception {
	// Check if requested to exclude from results, which is an error if not within a boolean clause
	String excludeOrRequire = queryElement.attributeValue("excludeOrRequire");
	if (excludeOrRequire != null)
		throw new Exception("Error parsing document: attribute excludeOrRequire may only be used when the query is enclosed in an encompassing <booleanQuery>. Error found at: " + queryElement.getUniquePath());

	if (queryElement.getName().equals("booleanQuery"))
		return makeBooleanQuery(queryElement, queryParser);
	else if (queryElement.getName().equals("textQuery"))
		return makeLuceneQuery(queryElement, queryParser);
	else if (queryElement.getName().equals("luceneQuery"))
		return makeLuceneQuery(queryElement, queryParser);
	else
		throw new Exception("Error parsing document: invalid element name '<" + queryElement.getName() + ">' at " + queryElement.getUniquePath());
}
 
Example 2
Project: testing_platform   File: Tools.java   View Source Code Vote up 6 votes
private static void read(Element e) {
    String result = "";
    if( !"".equals(targetPath) ){
        return ;
    }
    if (e.nodeCount() > 0) {
        Iterator<Element> it = e.elementIterator();
        while (it.hasNext()) {
            Element ele = it.next();
            if( "CSVDataSet".equals(ele.getName()) ){
                /*if("".equals(targetPath)){ //查到的第一个 CSVDataSet 保存到参数中,
                    targetPath = ele.getUniquePath();
                }*/
                targetPath = ele.getUniquePath();
            }
            read(ele);
        }
    }

}
 
Example 3
Project: joai-project   File: GenericType.java   View Source Code Vote up 5 votes
/**
 *  Constructor - accounting for location and schemaReader.
 *
 * @param  element       NOT YET DOCUMENTED
 * @param  location      NOT YET DOCUMENTED
 * @param  namespace     NOT YET DOCUMENTED
 * @param  schemaReader  NOT YET DOCUMENTED
 */
public GenericType(Element element, String location, Namespace namespace, SchemaReader schemaReader) {
	this.xsdPrefix = schemaReader.getNamespaces().getSchemaNamespace().getPrefix();
	this.location = location;
	this.name = element.attributeValue("name");
	this.element = element;
	this.namespace = namespace;
	this.schemaReader = schemaReader;
	this.path = element.getUniquePath();
	this.type = element.getName();
	if (schemaDocAware)
		extractDocumentation();
	else
		filterChildren(xsdPrefix + ":annotation");
}
 
Example 4
Project: joai-project   File: XMLQueryParser.java   View Source Code Vote up 4 votes
private static Query makeBooleanQuery(Element booleanQueryElement, QueryParser queryParser) throws Exception {
	String operator = booleanQueryElement.valueOf("@type");

	boolean isRequired = false;
	boolean isProhibited = false;

	if (operator == null)
		throw new Exception("Error parsing document: element <booleanQuery> must contain an attribite named 'type' that contains the value 'AND' or 'OR'. Error found at " + booleanQueryElement.getUniquePath());
	else if (operator.equalsIgnoreCase("OR"))
		isRequired = false;
	else if (operator.equalsIgnoreCase("AND"))
		isRequired = true;
	else
		throw new Exception("Error parsing document: element <booleanQuery> must contain an attribite named 'type' that contains the value 'AND' or 'OR' but value '" + operator + "' was found. Error found at " + booleanQueryElement.getUniquePath());

	BooleanQuery booleanQuery = new BooleanQuery();

	// iterate through child elements of booleanClause
	Query query = null;
	for (Iterator i = booleanQueryElement.elementIterator(); i.hasNext(); ) {
		Element element = (Element) i.next();

		// Exclude from results or require (overrides previous boolean designation)?
		String excludeOrRequire = element.attributeValue("excludeOrRequire");
		if (excludeOrRequire != null) {
			excludeOrRequire = excludeOrRequire.trim();
			if (excludeOrRequire.equalsIgnoreCase("exclude")) {
				isRequired = false;
				isProhibited = true;
			}
			else if (excludeOrRequire.equalsIgnoreCase("require")) {
				isRequired = true;
				isProhibited = false;
			}
			else if (excludeOrRequire.equalsIgnoreCase("neither")) {
				isRequired = false;
				isProhibited = false;
			}
			else {
				throw new Exception("Error parsing document: the value of attribute excludeOrRequire must be one of 'exclude', 'require' or 'neither' but '"
					 + excludeOrRequire + "' was found at " + booleanQueryElement.getUniquePath());
			}
		}

		if (element.getName().equals("booleanQuery")) {
			query = makeBooleanQuery(element, queryParser);
			if (query != null) {
				if (isRequired && !isProhibited)
					booleanQuery.add(query, BooleanClause.Occur.MUST);
				else if (!isRequired && isProhibited)
					booleanQuery.add(query, BooleanClause.Occur.MUST_NOT);
				else
					booleanQuery.add(query, BooleanClause.Occur.SHOULD);
			}
		}
		else {
			query = makeLuceneQuery(element, queryParser);
			if (query != null) {
				if (isRequired && !isProhibited)
					booleanQuery.add(query, BooleanClause.Occur.MUST);
				else if (!isRequired && isProhibited)
					booleanQuery.add(query, BooleanClause.Occur.MUST_NOT);
				else
					booleanQuery.add(query, BooleanClause.Occur.SHOULD);
			}
		}
	}

	return applyBoost(booleanQueryElement, booleanQuery);
}
 
Example 5
Project: lams   File: ElementWrapper.java   View Source Code Vote up 4 votes
public String getUniquePath(Element element) {
	return element.getUniquePath( element );
}