下面列出了javax.xml.xpath.XPathFunction#javax.xml.xpath.XPathFunctionException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
@Override
public Object evaluate(Object... args){
try{
return xpathFunction.evaluate(Arrays.asList(args));
}catch(XPathFunctionException ex){
throw new RuntimeException(ex);
}
}
@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);
}
}
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);
}
}
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);
}
@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;
}
@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;
}
public Object evaluate(List parameters) throws XPathFunctionException {
String parameter = parameters.get(0).toString();
return parameter.toUpperCase();
}
@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;
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}
public Object evaluate(List list) throws XPathFunctionException {
return "Hello World";
}