当前位置: 首页>>代码示例>>Java>>正文


Java XPathException类代码示例

本文整理汇总了Java中javax.xml.xpath.XPathException的典型用法代码示例。如果您正苦于以下问题:Java XPathException类的具体用法?Java XPathException怎么用?Java XPathException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XPathException类属于javax.xml.xpath包,在下文中一共展示了XPathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processFile

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Process the xmlfile named <code>fileName</code> with the given system
 * ID.
 * 
 * @param fileName
 *          meta data file name.
 * @param systemId
 *          system ID.
 */
protected void processFile(String fileName, String systemId)
    throws ValidationException, ParserConfigurationException,
        SAXException, IOException, SchedulerException,
        ClassNotFoundException, ParseException, XPathException {

    prepForProcessing();
    
    log.info("Parsing XML file: " + fileName + 
            " with systemId: " + systemId);
    InputSource is = new InputSource(getInputStream(fileName));
    is.setSystemId(systemId);
    
    process(is);
    
    maybeThrowValidationException();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:XMLSchedulingDataProcessor.java

示例2: processStreamAndScheduleJobs

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Process the xmlfile named <code>fileName</code> with the given system
 * ID.
 * 
 * @param stream
 *          an input stream containing the xml content.
 * @param systemId
 *          system ID.
 */
public void processStreamAndScheduleJobs(InputStream stream, String systemId, Scheduler sched)
    throws ValidationException, ParserConfigurationException,
        SAXException, XPathException, IOException, SchedulerException,
        ClassNotFoundException, ParseException {

    prepForProcessing();

    log.info("Parsing XML from stream with systemId: " + systemId);

    InputSource is = new InputSource(stream);
    is.setSystemId(systemId);

    process(is);
    executePreProcessCommands(sched);
    scheduleJobs(sched);

    maybeThrowValidationException();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:XMLSchedulingDataProcessor.java

示例3: HttpPidMinter

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Create a new HttpPidMinter.
 * @param url The URL for the minter service.  This is the only required argument -- all
 *    other parameters can be blank.
 * @param method The HTTP method (POST, PUT or GET) used to generate a new PID (POST will
 *    be used if the method is blank.
 * @param username If not blank, use this username to connect to the minter service.
 * @param password If not blank, use this password used to connect to the minter service.
 * @param regex If not blank, use this regular expression used to remove unwanted text from the
 *    minter service response.  For example, if the response text is "/foo/bar:baz" and the
 *    desired identifier is "baz", then the regex would be ".*:".
 * @param xpath If not blank, use this XPath expression used to extract the desired identifier
 *    from an XML minter response.
**/
public HttpPidMinter( final String url, final String method, final String username,
    final String password, final String regex, final String xpath ) {

    if (isBlank(url)) {
        throw new IllegalArgumentException("Minter URL must be specified!");
    }

    this.url = url;
    this.method = (method == null ? "post" : method);
    this.username = username;
    this.password = password;
    this.regex = regex;
    if ( !isBlank(xpath) ) {
        try {
            this.xpath = XPathFactory.newInstance().newXPath().compile(xpath);
        } catch ( final XPathException ex ) {
            LOGGER.warn("Error parsing xpath ({}): {}", xpath, ex.getMessage());
            throw new IllegalArgumentException("Error parsing xpath" + xpath, ex);
        }
    }
    this.client = buildClient();
}
 
开发者ID:fcrepo4-exts,项目名称:fcrepo-mint,代码行数:37,代码来源:HttpPidMinter.java

示例4: testMarshal

import javax.xml.xpath.XPathException; //导入依赖的package包/类
public void testMarshal() throws JAXBException, XPathException {
	final PurchaseOrderType purchaseOrder = objectFactory
			.createPurchaseOrderType();
	purchaseOrder.setShipTo(objectFactory.createUSAddress());
	purchaseOrder.getShipTo().setCity("New Orleans");
	final JAXBElement<PurchaseOrderType> purchaseOrderElement = objectFactory
			.createPurchaseOrder(purchaseOrder);

	final Marshaller marshaller = context.createMarshaller();

	final DOMResult result = new DOMResult();
	marshaller.marshal(purchaseOrderElement, result);

	final XPathFactory xPathFactory = XPathFactory.newInstance();

	assertEquals("Wrong city", "New Orleans", xPathFactory.newXPath()
			.evaluate("/purchaseOrder/shipTo/city", result.getNode()));
}
 
开发者ID:highsource,项目名称:hyperjaxb3,代码行数:19,代码来源:JAXBTest.java

示例5: filter

import javax.xml.xpath.XPathException; //导入依赖的package包/类
@Override
public void filter(Document document) throws XPathException {
	Object result = xPathExpression.evaluate(document, XPathConstants.NODESET);
	
	if(result != null) {
		NodeList nodeList = (NodeList)result;
		for(int i = 0; i < nodeList.getLength(); i++) {
			Node item = nodeList.item(i);
			
			anonymize(item);
		}
	} else {
		// do nothing
	}
	
}
 
开发者ID:greenbird,项目名称:xml-formatter-core,代码行数:17,代码来源:XPathNodeAnonymizerFilter.java

示例6: getOptionalElement

import javax.xml.xpath.XPathException; //导入依赖的package包/类
public static final Element getOptionalElement(Element root, String xpath) throws MultipleMatchesException, NestedXPathException {
	try {
		XPathExpression expr = null;
		
		if ((expr = ParserHelper.compiledMap.get(xpath)) == null) {
			expr = getXPathFactory().newXPath().compile(xpath);
			ParserHelper.compiledMap.put(xpath, expr);
		}
		
		// I use a NodeList here instead of an Element because I want to ensure
		// there are not multiple return values
		NodeList nl = (NodeList) expr.evaluate(root, XPathConstants.NODESET);
		
		if (nl.getLength() > 1) {
			throw new MultipleMatchesException(xpath);
		}

		// TODO: Ensure the return value is an Element?
		return (Element) nl.item(0);
	}
	catch (XPathException e) {
		throw new NestedXPathException(e);
	}
}
 
开发者ID:FINRAOS,项目名称:JTAF-XCore,代码行数:25,代码来源:ParserHelper.java

示例7: getListOfRecipes

import javax.xml.xpath.XPathException; //导入依赖的package包/类
public final ArrayList<String> getListOfRecipes() {
    ArrayList<String> nameList = new ArrayList<>();
    XPath xp;
    try {
        xp = XPathFactory.newInstance().newXPath();
        NodeList recipeList =
            (NodeList) xp.evaluate(
                "/RECIPES/RECIPE", recipeDocument, XPathConstants.NODESET);
        if (recipeList.getLength() == 0) {
            LaunchControl.setMessage("No Recipes found in file");
            return null;
        }

        for (int i = 0; i < recipeList.getLength(); i++) {
            Node recipeNode = recipeList.item(i);
            String recipeName = (String) xp.evaluate("NAME/text()",
                    recipeNode, XPathConstants.STRING);
            nameList.add(recipeName);
        }
    } catch (XPathException xpe) {
        BrewServer.LOG.warning("Couldn't run XPATH: " + xpe.getMessage());
        return null;
    }
    return nameList;
}
 
开发者ID:DougEdey,项目名称:SB_Elsinore_Server,代码行数:26,代码来源:BeerXMLReader.java

示例8: applyMerge

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Starts the merge process
 *
 * @param mainDoc  The document to edit.
 * @param mergeDoc The document containing the edit instructions.
 * @throws XPathException A problem parsing the XPath location.
 */
protected void applyMerge(Document mainDoc, Document mergeDoc) throws XPathException {
    NodeList mergeActions = handler.getNodeList(mergeDoc, BASE_XPATH_EXPR);

    for (int i = 0; i < mergeActions.getLength(); i++) {
        Node node = mergeActions.item(i);

        // get the attribute map and action information
        NamedNodeMap attrMap = node.getAttributes();
        String type = attrMap.getNamedItem(ATTR_TYPE).getNodeValue();
        String action = attrMap.getNamedItem(ATTR_ACTION).getNodeValue();
        String xpath = attrMap.getNamedItem(ATTR_XPATH).getNodeValue();
        NodeList actionArgs = node.getChildNodes();

        // perform the transform
        performTransform(mainDoc, type, action, xpath, actionArgs);
    }
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:25,代码来源:MergeDocuments.java

示例9: performTransform

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Performs the transform on the given document with the xpath and node list
 *
 * @param doc           Base document to edit.
 * @param type          The type of element to edit (attribute or node).
 * @param action        The action (add, delete, set) to perform.
 * @param xpath         The XPath location to perform the edit.
 * @param mergeNodeList Action arguments. Nodes to add, attributes to set, etc.
 * @throws XPathException A problem parsing the XPath location.
 */
protected void performTransform(Document doc, String type, String action, String xpath, NodeList mergeNodeList)
        throws XPathException {
    NodeList editNodes = handler.getNodeList(doc, xpath);

    for (int i = 0; i < editNodes.getLength(); i++) {
        Node crntEditNode = editNodes.item(i);

        if (TYPE_ATTRIBUTE.equals(type)) {
            if (ACTION_ADD.equals(action) || ACTION_SET.equals(action)) {
                attributeSet(crntEditNode, mergeNodeList);
            } else if (ACTION_DELETE.equals(action)) {
                attributeDelete(crntEditNode, mergeNodeList);
            }
        } else if (TYPE_NODE.equals(type)) {
            if (ACTION_ADD.equals(action)) {
                nodeAdd(crntEditNode, mergeNodeList);
            } else if (ACTION_DELETE.equals(action)) {
                nodeDelete(crntEditNode);
            }
        }
    }
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:33,代码来源:MergeDocuments.java

示例10: asNodeList

import javax.xml.xpath.XPathException; //导入依赖的package包/类
@Override
public NodeList asNodeList()
{
	try
	{
		return (NodeList) this.xPathExpression.evaluate(this.baseNode, XPathConstants.NODESET);
	}
	catch (XPathException ex)
	{
		throw new FluentXmlProcessingException(ex);
	}
}
 
开发者ID:fluentxml4j,项目名称:fluentxml4j,代码行数:13,代码来源:SelectMultipleFromNodeImpl.java

示例11: cleanXmlFile

import javax.xml.xpath.XPathException; //导入依赖的package包/类
/**
 * Cleans the XML file.
 *  1) Updates formatting and indentation.
 *  2) Removes liquibase "objectQuotingStrategy" attributes.
 *
 * @param file The changelog file.
 */
private static void cleanXmlFile(final File file) throws IOException {
    try {
        final Document doc = readXml(file);
        final XPath xpath = XPathFactory.newInstance().newXPath();
        removeNodes(doc, xpath, "//@objectQuotingStrategy");
        removeNodes(doc, xpath, "//text()[normalize-space()='']");
        writeXml(doc, file);
    } catch (final XPathException ex) {
        throw new IOException(ex.getMessage(), ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:19,代码来源:LiquibaseHelper.java

示例12: pickleXPE

import javax.xml.xpath.XPathException; //导入依赖的package包/类
static byte [] pickleXPE(XPathException xpe) throws IOException {
    ByteArrayOutputStream bos =  new ByteArrayOutputStream();
    ObjectOutputStream xpeos = new ObjectOutputStream(bos);
    xpeos.writeObject(xpe);
    xpeos.close();
    return bos.toByteArray();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:XPathExceptionInitCause.java

示例13: get

import javax.xml.xpath.XPathException; //导入依赖的package包/类
@Override
public Node get(int index) throws XPathException {
    if (index <0 || index >= size()) {
        throw new IndexOutOfBoundsException("Index " + index + " is out of bounds");
    }
    if (nodeList != null) {
        return nodeList.item(index);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:XPathNodesImpl.java

示例14: ClusterDefinitionLoader

import javax.xml.xpath.XPathException; //导入依赖的package包/类
public ClusterDefinitionLoader() {
	try {
		XPath xPath = XPathFactory.newInstance().newXPath();
		clustersExpression = xPath.compile("//clusters/cluster");
		nameExpression = xPath.compile("./name/text()");
		subExpression = xPath.compile("./sub/text()");
		centerXExpression = xPath.compile("./x/text()");
		centerYExpression = xPath.compile("./y/text()");
		colorExpression = xPath.compile("./color/text()");
	}
	catch(XPathException e) {
		throw new DefinitionLoaderException("Could not parse configuration", e);
	}
}
 
开发者ID:spectralmind,项目名称:sonarflow-android,代码行数:15,代码来源:ClusterDefinitionLoader.java

示例15: getClusterNodes

import javax.xml.xpath.XPathException; //导入依赖的package包/类
private List<Node> getClusterNodes(InputStream configurationStream) throws ParserConfigurationException,
		SAXException, IOException, XPathException {
	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
	DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
	Document doc = dBuilder.parse(configurationStream);
	doc.getDocumentElement().normalize();
	NodeList clusterNodes = (NodeList) clustersExpression.evaluate(doc.getDocumentElement(), XPathConstants.NODESET);
	List<Node> nodes = Lists.newArrayList();
	for(int i = 0; i < clusterNodes.getLength(); ++i) {
		nodes.add(clusterNodes.item(i));
	}
	return nodes;
}
 
开发者ID:spectralmind,项目名称:sonarflow-android,代码行数:14,代码来源:ClusterDefinitionLoader.java


注:本文中的javax.xml.xpath.XPathException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。