本文整理汇总了Java中org.dom4j.xpath.DefaultXPath类的典型用法代码示例。如果您正苦于以下问题:Java DefaultXPath类的具体用法?Java DefaultXPath怎么用?Java DefaultXPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultXPath类属于org.dom4j.xpath包,在下文中一共展示了DefaultXPath类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeValue
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* Extracts the value of the supplied attribute
*
* @param element
* element with attribute in question
* @param attributeName
* name of the attribute in question
* @param failIfNotFound
* determines if exception should be thrown if attribute is not
* found
* @return value of the attribute in question, null if not found and
* failIfNotFound is set to false
* @throws GenericArtifactParsingException
* exception thrown is attribute is missing and failIfNotFound
* is set to true
*/
public static String getAttributeValue(Element element,
String attributeName, boolean failIfNotFound)
throws GenericArtifactParsingException {
XPath xpath = new DefaultXPath("@" + attributeName);
xpath.setNamespaceURIs(ccfNamespaceMap);
Node attributeNode = xpath.selectSingleNode(element);
if (attributeNode == null) {
if (failIfNotFound) {
throw new GenericArtifactParsingException("Missing attribute: "
+ attributeName + " in element " + element.getName());
} else {
return null;
}
} else {
return attributeNode.getText();
}
}
示例2: parse
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* 解析测试套件配置文件
* @param suiteInputStream 配置文件输入流
* @return 测试套件对象
* @throws DocumentException
*/
public Suite parse(InputStream suiteInputStream) throws DocumentException
{
SAXReader reader = new SAXReader();
reader.setEncoding("utf-8");
Document document = reader.read(suiteInputStream);
simpleNamespaceContext.addNamespace("ns", NS_URI);
XPath xpath = new DefaultXPath("/ns:suite");
xpath.setNamespaceContext(simpleNamespaceContext);
Element suiteEle = (Element) xpath.selectSingleNode(document);
if (suiteEle == null)
{
suiteEle = document.getRootElement();
// throw new RuntimeException("Can not found suite config.");
}
Suite suite = new Suite();
String xmlConfPath = suiteEle.attributeValue("pageConfig");
String pagePackage = suiteEle.attributeValue("pagePackage", "");
String rows = suiteEle.attributeValue("rows", "1");
String lackLines = suiteEle.attributeValue("lackLines", "nearby");
String errorLines = suiteEle.attributeValue("errorLines", "stop");
String afterSleep = suiteEle.attributeValue("afterSleep", "0");
suite.setXmlConfPath(xmlConfPath);
suite.setPagePackage(pagePackage);
suite.setRows(rows);
suite.setLackLines(lackLines);
suite.setErrorLines(errorLines);
suite.setAfterSleep(Long.parseLong(afterSleep));
pagesParse(document, suite);
return suite;
}
示例3: getAttributeValue
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* Extracts the value of the supplied attribute
*
* @param element
* element with attribute in question
* @param attributeName
* name of the attribute in question
* @return value of the attribute in question
* @throws GenericArtifactParsingException
* exception s thrown is attribute is missing
*/
private static String getAttributeValue(Element element,
String attributeName) throws GenericArtifactParsingException {
// TODO Cash constructed XPath objects?
// XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" +
// attributeName);
XPath xpath = new DefaultXPath("@" + attributeName);
xpath.setNamespaceURIs(ccfNamespaceMap);
Node attributeNode = xpath.selectSingleNode(element);
if (attributeNode == null)
throw new GenericArtifactParsingException("Missing attribute: "
+ attributeName + " in element " + element.getName());
else
return attributeNode.getText();
}
示例4: getAttributeValueWithoutException
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* Extracts the value of the supplied attribute without throwing an
* exception if missing
*
* @param element
* element with attribute in question
* @param attributeName
* name of the attribute in question
* @return value of the attribute in question, null if attribute is missing
*
*/
private static String getAttributeValueWithoutException(Element element,
String attributeName) {
// TODO Cash constructed XPath objects?
// XPath xpath = new DefaultXPath("@" + CCF_NAMESPACE_PREFIX + ":" +
// attributeName);
XPath xpath = new DefaultXPath("@" + attributeName);
xpath.setNamespaceURIs(ccfNamespaceMap);
Node attributeNode = xpath.selectSingleNode(element);
if (attributeNode == null)
return null;
else
return attributeNode.getText();
}
示例5: extractBoxConstraint
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
private int[] extractBoxConstraint(Element root) {
int[] result = new int[4];
String nodeName = currentToken.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
return result;
}
示例6: render
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
public void render(final InputStream in, final OutputStream out, final Map<String , String> config)
throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read(in);
XPath xpath = new DefaultXPath("/l:LexML/l:Metadado/l:Identificacao");
Map<String,String> ns = new HashMap<String,String>();
ns.put("l","http://www.lexml.gov.br/1.0");
xpath.setNamespaceURIs(ns);
Node n = xpath.selectSingleNode(document);
//System.out.println("n:" + n);
//System.out.println("attributes: " + ((Element) n).attributes());
String urn = ((Element)n).attributeValue("URN");
//System.out.println("urn:" + urn);
String[] urnComps = urn.split(":");
String autoridade = urnComps[3];
String tipoNorma = urnComps[4];
RendererPDFContext ctx = new RendererPDFContext(autoridade,tipoNorma);
ctx.addConfig(config);
Element root = document.getRootElement();
ctx.setOutputStream(out);
new PDFBuilder(ctx, root).build();
}
示例7: getUrl
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* @param browser
* @param ver
* @param os 操作系统名称
* @param arch CUP架构(32或者64位)
* @return 找不到返回null
*/
public String getUrl(String browser, String ver, String os, String arch)
{
String xpathStr = String.format("//drivers/driver[@type='%s']/supports/browser[@version='%s']",
browser, ver);
XPath xpath = new DefaultXPath(xpathStr);
String path = null;
@SuppressWarnings("unchecked")
List<Element> nodes = xpath.selectNodes(document);
String driverVer = null;
for(Element ele : nodes)
{
@SuppressWarnings("unchecked")
List<Element> itemList = ele.getParent().getParent().element("items").elements("item");
for(Element item : itemList)
{
if(os.equals(item.attributeValue("os")) && arch.equals(item.attributeValue("arch")))
{
path = item.attributeValue("path");
break;
}
}
driverVer = ele.getParent().getParent().attributeValue("version");
break;
}
if(driverVer != null && !driverVer.trim().equals(""))
{
String base = document.getRootElement().attributeValue("base");
String subPath = "";
for(Browser bro : browserList())
{
if(browser.equals(bro.getName()))
{
subPath = bro.getPath();
break;
}
}
if("win32".equals(os))
{
arch = "";
}
path = base + subPath + "/" + driverVer + "/" + browser + "driver_" + os + arch + ".zip";
}
else
{
path = null;
}
return path;
}
示例8: supportBrowser
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
/**
* @return 支持的浏览器以及版本列表
*/
public Map<String, Set<String>> supportBrowser()
{
Map<String, Set<String>> browserMap = new HashMap<String, Set<String>>();
String xpathStr = String.format("//drivers/driver");
XPath xpath = new DefaultXPath(xpathStr);
@SuppressWarnings("unchecked")
List<Element> nodes = xpath.selectNodes(document);
for(Element ele : nodes)
{
String type = ele.attributeValue("type");
Set<String> verList = new TreeSet<String>(new Comparator<String>(){
@Override
public int compare(String o1, String o2)
{
return o2.compareTo(o1);
}
});
@SuppressWarnings("unchecked")
List<Element> verEleList = ele.element("supports").elements("browser");
for(Element verEle : verEleList)
{
String ver = verEle.attributeValue("version");
verList.add(ver);
}
Set<String> oldVerList = browserMap.get(type);
if(oldVerList == null)
{
browserMap.put(type, verList);
}
else
{
oldVerList.addAll(verList);
}
}
return browserMap;
}
示例9: initialValue
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
@Override
protected XPath initialValue() {
return new DefaultXPath(this.xpath);
}
示例10: initialValue
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
@Override
protected XPath initialValue() {
return new DefaultXPath("descendant-or-self::text() | descendant-or-self::*/@*");
}
示例11: createObject
import org.dom4j.xpath.DefaultXPath; //导入依赖的package包/类
public XPath createObject(String key) {
return new DefaultXPath(key);
}