javax.xml.xpath.XPathFunctionException Java Examples

The following examples show how to use javax.xml.xpath.XPathFunctionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlFileFunctionResolver.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public XPathFunction resolveFunction(final QName functionName, final int arity)
{
    if (functionMap.containsKey(functionName))
    {
        return new XPathFunction()
        {
            @Override
            public Object evaluate(List args) throws XPathFunctionException
            {
                return functionMap.get(functionName).evaluate(args);
            }
        };
    }
    return originalResolver.resolveFunction(functionName, arity);
}
 
Example #2
Source File: XmlFileStartFrameXPathFunction.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunctionException
{
    int frameIdx = ((Double) args.get(0)).intValue();
    LOG.fine("startFrame(" + frameIdx + ")!");
    paramMatchCache.addFrame(frameIdx);
    return true;
}
 
Example #3
Source File: XmlFileEvaluateXPathFunction.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunctionException
{
    int frameIdx = ((Double) args.get(0)).intValue();
    boolean expressionResult = (Boolean) args.get(1);
    LOG.fine("evaluate(" + frameIdx + ", " + expressionResult + ")");
    return expressionResult;
}
 
Example #4
Source File: XStreamSafeSearchFunction.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private String getXPathExpressionParameter(List parameters) throws XPathFunctionException {
	if (parameters.size() < 1) {
		throw new XPathFunctionException("First parameter must be an XPath expression.");
	}
	if (!(parameters.get(0) instanceof String)) {
		throw new XPathFunctionException("First parameter must be an XPath expression String");
	}
	return (String)parameters.get(0);
}
 
Example #5
Source File: XStreamSafeSearchFunction.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public Object evaluate(List parameters) throws XPathFunctionException {
	String xPathExpression = getXPathExpressionParameter(parameters);
	evaluator.setXpath(xpath);
	//Node rootSearchNode = getRootSearchNodeParameter(parameters);
	try {
		return evaluator.evaluate(xPathExpression, rootNode);
	} catch (XPathExpressionException e) {
		throw new XPathFunctionException(e);
	}
}
 
Example #6
Source File: XPathFunctionFromUserFunction.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nullable
public Object evaluate (final List aArgs) throws XPathFunctionException
{
  try
  {
    // Convert the parameters
    final Sequence [] aSequences = new Sequence [aArgs.size ()];
    if (aArgs.size () > 0)
    {
      // Create a new context per evaluation
      final XPathContextMajor aXPathContext = m_aXQController.newXPathContext ();

      int nIndex = 0;
      for (final Object aArg : aArgs)
      {
        // Ripped from Saxon itself; genericType is not needed
        final JPConverter aConverter = JPConverter.allocate (aArg.getClass (), null, m_aConfiguration);
        // Convert to Sequence
        aSequences[nIndex] = aConverter.convert (aArg, aXPathContext);
        ++nIndex;
      }
    }
    // Finally invoke user function
    return m_aUserFunc.call (aSequences, m_aXQController);
  }
  catch (final Exception ex)
  {
    // Wrap all exceptions
    throw new XPathFunctionException (ex);
  }
}
 
Example #7
Source File: Functions.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluate(Object... args){
    try{
        return xpathFunction.evaluate(Arrays.asList(args));
    }catch(XPathFunctionException ex){
        throw new RuntimeException(ex);
    }
}
 
Example #8
Source File: TestFunctionResolver.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluate(List args) throws XPathFunctionException{
    char[] ch = ((String)args.get(0)).toCharArray();
    for(int i=0, j=ch.length-1; i<j; i++, j--){
        char temp = ch[i];
        ch[i] = ch[j];
        ch[j] = temp;
    }
    return new String(ch);
}
 
Example #9
Source File: XmlFileXpathValidator.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunctionException
{
    int frameIdx = ((Double) args.get(0)).intValue();
    NodeList arg1 = (NodeList) args.get(1);
    String nodeText = XmlUtil.nodeListToString(arg1);
    LOG.fine("persist(" + frameIdx + ", " + nodeText + ")");

    for (int i = 0; i < arg1.getLength(); i++)
    {
        Node node = arg1.item(i);
        if (xpathResultMatch != null)
        {
            if (!node.toString().matches(xpathResultMatch))
            {
                continue;
            }
        }
        // Everything passed for this Node. Start creating XmlTypeReferenceModel for it.
        int lineNumber = (int) node.getUserData(
                    LocationAwareContentHandler.LINE_NUMBER_KEY_NAME);
        int columnNumber = (int) node.getUserData(
                    LocationAwareContentHandler.COLUMN_NUMBER_KEY_NAME);

        GraphService<XmlTypeReferenceModel> fileLocationService = new GraphService<>(
                    event.getGraphContext(),
                    XmlTypeReferenceModel.class);
        XmlTypeReferenceModel fileLocation = fileLocationService.create();
        String sourceSnippit = XmlUtil.nodeToString(node);
        fileLocation.setSourceSnippit(sourceSnippit);
        fileLocation.setLineNumber(lineNumber);
        fileLocation.setColumnNumber(columnNumber);
        fileLocation.setLength(node.toString().length());
        fileLocation.setFile(xml);
        fileLocation.setXpath(xpathString);
        GraphService<NamespaceMetaModel> metaModelService = new GraphService<>(
                    event.getGraphContext(),
                    NamespaceMetaModel.class);
        for (Map.Entry<String, String> namespace : namespaces.entrySet())
        {
            NamespaceMetaModel metaModel = metaModelService.create();
            metaModel.setSchemaLocation(namespace.getKey());
            metaModel.setSchemaLocation(namespace.getValue());
            metaModel.addXmlResource(xml);
            fileLocation.addNamespace(metaModel);
        }
        resultLocations.add(fileLocation);

        evaluationStrategy.modelSubmissionRejected();
        evaluationStrategy.modelMatched();

        if (fileNameValidator.getFileNamePattern() != null && !fileNameValidator.getFileNamePattern().parse(xml.getFileName()).submit(event, context))
        {
            evaluationStrategy.modelSubmissionRejected();
            continue;
        }

        for (Map.Entry<String, String> entry : paramMatchCache.getVariables().entrySet())
        {
            Parameter<?> param = store.get(entry.getKey());
            String value = entry.getValue();
            if (!evaluationStrategy.submitValue(param, value))
            {
                evaluationStrategy.modelSubmissionRejected();
                return false;
            }
        }
        evaluationStrategy.modelSubmitted(fileLocation);
        evaluationStrategy.modelMatched();
    }

    return true;
}
 
Example #10
Source File: UpperCaseFunction.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public Object evaluate(List parameters) throws XPathFunctionException {
	String parameter = parameters.get(0).toString();
	return parameter.toUpperCase();
}
 
Example #11
Source File: XPathExFuncTest.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #12
Source File: XPathExFuncTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #13
Source File: XPathExFuncTest.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #14
Source File: XPathExFuncTest.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #15
Source File: XPathExFuncTest.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #16
Source File: XPathExFuncTest.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #17
Source File: XPathExFuncTest.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #18
Source File: XPathExFuncTest.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #19
Source File: SecureProcessingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #20
Source File: XPathExFuncTest.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #21
Source File: XPathExFuncTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #22
Source File: XPathExFuncTest.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #23
Source File: XPathExFuncTest.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }
 
Example #24
Source File: XPathExFuncTest.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
public Object evaluate(List list) throws XPathFunctionException {

            return "Hello World";
        }