本文整理汇总了Java中org.apache.xpath.XPathAPI.selectNodeList方法的典型用法代码示例。如果您正苦于以下问题:Java XPathAPI.selectNodeList方法的具体用法?Java XPathAPI.selectNodeList怎么用?Java XPathAPI.selectNodeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathAPI
的用法示例。
在下文中一共展示了XPathAPI.selectNodeList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseBdxClasses
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Parses the BDX classes configuration.
*
* @param pNode the node
* @throws RuntimeException if an error occurred while parsing the BDX classes configuration.
*/
protected void parseBdxClasses(Node pNode) {
try {
NodeList tNodeList = XPathAPI.selectNodeList(pNode,
"//AsTransportConfiguration/BdxClass");
for (int i = 0; i < tNodeList.getLength(); i++) {
Node tNode = tNodeList.item(i);
CwfDataIf tTree = AsUtil.parse((Element) tNode);
String tClassName = tTree.getProperty("className");
if (!mBdxClasses.contains(tClassName)) {
AsDef.ensureClassName(tClassName);
mBdxClasses.add(tClassName);
}
}
}
catch (TransformerException e) {
throw new RuntimeException("Error selecting BDX class source node", e);
}
}
示例2: cutSalaries
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public static void cutSalaries(Document doc, String xpath)
throws TransformerException {
// Get the matching elements
NodeList nodelist = XPathAPI.selectNodeList(doc, xpath);
// Process the elements in the nodelist
for (int i=0; i<nodelist.getLength(); i++) {
// Get element
Element elem = (Element)nodelist.item(i);
// Transform content of element
double before = Double.parseDouble(elem.getTextContent());
double after = before / 2;
elem.setTextContent(Double.toString(after));
}
}
示例3: parseServices
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Parses the service configuration
* @param pNode the node to parse from
* @throws AsInitializationException
*/
protected void parseServices(Element pNode) throws AsInitializationException {
try {
NodeList tNodeList = XPathAPI.selectNodeList(pNode, "//AsServices/service");
for (int i = 0; i < tNodeList.getLength(); i++) {
Node tNode = tNodeList.item(i);
CwfDataIf tTree = AsUtil.parse((Element) tNode);
String tServiceClass = tTree.getProperty("serviceClass");
String tRequestClass = tTree.getProperty("requestClass");
createAndRegisterService(tRequestClass, tServiceClass);
}
}
catch (TransformerException e) {
throw new RuntimeException("Error selecting service source node", e);
}
}
示例4: parse
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
protected void parse(Node pNode) {
try {
NodeList tNodeList = XPathAPI.selectNodeList(pNode, "//AsBeanFactory/bean");
for (int i = 0; i < tNodeList.getLength(); i++) {
Node tNode = tNodeList.item(i);
CwfDataIf tTree = AsUtil.parse((Element) tNode);
String tInterface = tTree.getProperty("interface");
String tClass = tTree.getProperty("class");
boolean tSingleton = tTree.getBooleanProperty("singleton") == Boolean.TRUE;
boolean tParameters = tTree.getBooleanProperty("parameters") == Boolean.TRUE;
Class<?> tInterfaceClass = Class.forName(tInterface);
Class<?> tImplementationClass = Class.forName(tClass);
mBeanConfiguration.addConfiguration(tInterfaceClass, tImplementationClass, tSingleton, tParameters);
}
}
catch (Exception e) {
throw new RuntimeException("Error selecting bean source node", e);
}
}
示例5: addReferences
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private void addReferences() {
try {
Node tDoc = As.getConfigXmlParser().getConfigurationDocument();
NodeList tNodeList = XPathAPI.selectNodeList(tDoc, "//" + TAG_AS_CACHE + "/" + TAG_CACHE_REFERENCE);
for (int i = 0; i < tNodeList.getLength(); i++) {
Node tNode = tNodeList.item(i);
CwfDataIf tTree = AsUtil.parse((Element) tNode);
String tType = tTree.getProperty(ATTR_TYPE);
String tField = tTree.getProperty(ATTR_FIELD);
addReference(tType, tField);
}
}
catch (TransformerException e) {
throw new RuntimeException("Error selecting cache reference node", e);
}
}
示例6: main
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Document doc = XmlUtils.loadDoc("/testcode/xpath/data.xml");
String input = args.length != 0 ? args[1] : "guess' or '1'='1";
String query = "//groups/group[@id='" + input + "']/writeAccess/text()";
//selectNodeIterator
NodeIterator iterator = XPathAPI.selectNodeIterator(doc, query);
XmlUtils.printNodeIterator(iterator);
//selectNodeList
NodeList nodeList = XPathAPI.selectNodeList(doc, query);
XmlUtils.printNodeList(nodeList);
//selectSingleNode
Node node = XPathAPI.selectSingleNode(doc, query);
XmlUtils.printNode(node);
//Static string (safe)
Node node2 = XPathAPI.selectSingleNode(doc, "//groups/group[@id='guess']/writeAccess/text()".toLowerCase());
XmlUtils.printNode(node2);
}
示例7: noError
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Checks, if errors were reported during execution
*
* @return true, if no error was logged in the log file
*/
protected boolean noError() {
// if there is no result file, there is an error
if (result == null)
return false;
try {
NodeList nodes = XPathAPI.selectNodeList(result.document,
"//r:Error|//r:FatalError",
result.document.getDocumentElement());
if (nodes.getLength() > 0)
return false;
} catch (TransformerException e) {
fail("An error occured processing an Xpath expression on the log file.");
e.printStackTrace();
return false;
}
return true;
}
示例8: getSignatureResourceName
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private String getSignatureResourceName(URL url)
throws IOException, ParserConfigurationException, SAXException, TransformerException {
InputStream inputStream = url.openStream();
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
ZipEntry zipEntry;
while (null != (zipEntry = zipInputStream.getNextEntry())) {
if (false == "[Content_Types].xml".equals(zipEntry.getName())) {
continue;
}
Document contentTypesDocument = loadDocument(zipInputStream);
Element nsElement = contentTypesDocument.createElement("ns");
nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns",
"http://schemas.openxmlformats.org/package/2006/content-types");
NodeList nodeList = XPathAPI.selectNodeList(contentTypesDocument,
"/tns:Types/tns:Override[@ContentType='application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml']/@PartName",
nsElement);
if (nodeList.getLength() == 0) {
return null;
}
String partName = nodeList.item(0).getTextContent();
LOG.debug("part name: " + partName);
partName = partName.substring(1); // remove '/'
return partName;
}
return null;
}
示例9: parse
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
protected void parse(Element pNode) {
try {
NodeList tNodeList = XPathAPI.selectNodeList(pNode, "//" + TAG_AS_DICTIONARY);
for (int i = 0; i < tNodeList.getLength(); i++) {
Node tNode = tNodeList.item(i);
CwfDataIf tTree = AsUtil.parse((Element) tNode);
String tPath = tTree.getProperty(ATTR_PATH);
parse(tPath);
}
}
catch (TransformerException e) {
throw new RuntimeException("Error selecting plugin source node", e);
}
}
示例10: getInheritedModules
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Gets the inherited modules.
*
* @param pDocument the document
* @return the inherited modules
* @throws TransformerException the transformer exception
*/
public static List<String> getInheritedModules(Document pDocument) throws TransformerException {
List<String> tModules = new ArrayList<String>();
NodeList tElem = XPathAPI.selectNodeList(pDocument.getDocumentElement(), "/Configuration/inherits");
for (int i = 0; i < tElem.getLength(); i++) {
tModules.add(((Element) tElem.item(i)).getAttribute("name"));
}
return tModules;
}
示例11: assembleModule
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Assemble module.
*
* @return the document
* @throws TransformerException in case an error occurred during the transformation process.
* @throws DOMException in case of a DOM traversing problem.
* @throws ParserConfigurationException in case an error occurred during the parsing of the configuration
*/
private Document assembleModule()
throws TransformerException, DOMException, ParserConfigurationException {
// create empty document
DocumentBuilderFactory tFactory = DocumentBuilderFactory.newInstance();
Document tDoc = tFactory.newDocumentBuilder().getDOMImplementation().createDocument(null, null, null);
Element tRoot = tDoc.createElement("Configuration");
tDoc.appendChild(tRoot);
System.out.println("AsXmlTool: assemble AS configuration");
for (String tModule : getModuleLoadOrder()) {
System.out.println("...module " + tModule);
Document tC = mDocuments.get(tModule);
NodeList tElem = XPathAPI.selectNodeList(tC.getDocumentElement(), "/Configuration/*");
for (int j = 0; j < tElem.getLength(); j++) {
Element tNode = (Element) tElem.item(j);
if (tNode.getTagName().equals("Version")) {
continue;
}
if (tNode.getTagName().equals("inherits")) {
continue;
}
tRoot.appendChild(tDoc.createTextNode(tNode.getPreviousSibling().getNodeValue()));
tNode.setAttribute("module", tModule);
tNode.getParentNode().removeChild(tNode);
tDoc.adoptNode(tNode);
tRoot.appendChild(tNode);
}
}
return tDoc;
}
示例12: getAllNodesByName
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Selects nodes by name.
*
* @param pNode the node to parse from
* @param pTagName the tag name to select
* @return a list of nodes matching the given name
* @throws AsInitializationException in case an exception occurred
* during the parsing of the specified element.
*/
protected NodeList getAllNodesByName(Element pNode, String pTagName) throws AsInitializationException {
try {
// no xml name space
return XPathAPI.selectNodeList(pNode, pTagName);
}
catch (TransformerException e) {
throw new AsInitializationException("Error selecting " + pTagName + " source node", e);
}
}
示例13: getTapClass
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public static Class<?> getTapClass(String pClassShortName) throws Exception {
if (cTapTypeMap == null) {
cTapTypeMap = new HashMap<String, Class<?>>();
cSearchPackages = new ArrayList<String>();
InputStream tStream = getResourceAsStream("/com/cinnober/as/conf/ASTransportConfig.xml");
Document tDocument = getDocument(tStream);
NodeList tNodes = XPathAPI.selectNodeList(tDocument.getDocumentElement(), "//SearchPackage");
for (int i = 0; i < tNodes.getLength(); i++) {
Element tNode = (Element) tNodes.item(i);
cSearchPackages.add(tNode.getAttribute("packageName"));
}
// Last resort, try some standard Java packages
cSearchPackages.add("java.lang");
cSearchPackages.add("java.util");
}
if (cTapTypeMap.containsKey(pClassShortName)) {
return cTapTypeMap.get(pClassShortName);
}
Class<?> tClass = null;
for (String tPackage : cSearchPackages) {
try {
tClass = Class.forName(tPackage + "." + pClassShortName);
cTapTypeMap.put(pClassShortName, tClass);
return tClass;
}
catch (ClassNotFoundException e) {
// No action
}
}
// no class found!
cTapTypeMap.put(pClassShortName, null);
return null;
}
示例14: getNodes
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public static NodeList getNodes(Node baseNode, String xpathExpression, Element nsElement) {
try {
NodeList nodeList = XPathAPI.selectNodeList(baseNode, xpathExpression, nsElement);
return nodeList;
} catch (TransformerException e) {
throw new RuntimeException("XPath error: " + e.getMessage(), e);
}
}
示例15: getResources
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private Map<String, String> getResources(byte[] document)
throws IOException, ParserConfigurationException, SAXException, TransformerException {
Map<String, String> signatureResources = new HashMap<String, String>();
ByteArrayInputStream bais = new ByteArrayInputStream(document);
ZipInputStream zipInputStream = new ZipInputStream(bais);
ZipEntry zipEntry;
while (null != (zipEntry = zipInputStream.getNextEntry())) {
if (!"[Content_Types].xml".equals(zipEntry.getName())) {
continue;
}
Document contentTypesDocument = OOXMLSignatureFacet.loadDocument(zipInputStream);
Element nsElement = contentTypesDocument.createElement("ns");
nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns",
"http://schemas.openxmlformats.org/package/2006/content-types");
for (String contentType : OOXMLSignatureFacet.contentTypes) {
NodeList nodeList = XPathAPI.selectNodeList(contentTypesDocument,
"/tns:Types/tns:Override[@ContentType='" + contentType + "']/@PartName", nsElement);
for (int nodeIdx = 0; nodeIdx < nodeList.getLength(); nodeIdx++) {
String partName = nodeList.item(nodeIdx).getTextContent();
LOG.debug("part name: " + partName);
partName = partName.substring(1); // remove '/'
signatureResources.put(partName, contentType);
}
}
break;
}
return signatureResources;
}