Skip to content

Commit

Permalink
Merge pull request #490 from jsight/xmlfile_param_fix
Browse files Browse the repository at this point in the history
Fixed a bug in xml file parameterization when only a DTD is specified, a...
  • Loading branch information
jsight committed Mar 3, 2015
2 parents 8162a08 + baf4a03 commit 63b7512
Showing 1 changed file with 28 additions and 8 deletions.
Expand Up @@ -370,8 +370,16 @@ else if (iterated instanceof XmlFileModel)
}
else if (xpathString == null)
{
// if the xpath is not set and therefore we have the result already
evaluationStrategy.modelMatched();
// if the xpath is not set and therefore we have the result already
if (fileNamePattern != null)
{
if (!fileNamePattern.parse(xml.getFileName()).submit(event, context))
{
evaluationStrategy.modelSubmissionRejected();
continue;
}
}
evaluationStrategy.modelSubmitted(xml);
resultLocations.add(xml);
}
Expand All @@ -393,7 +401,7 @@ else if (xpathString == null)
this.xmlFileFunctionResolver.registerFunction(WINDUP_NS_URI, "evaluate", new XmlFileEvaluateXPathFunction(evaluationStrategy));
this.xmlFileFunctionResolver.registerFunction(WINDUP_NS_URI, "matches", new XmlFileMatchesXPathFunction(context, store,
paramMatchCache, event));
this.xmlFileFunctionResolver.registerFunction(WINDUP_NS_URI, "persist", new XmlFilePersistXPathFunction(graphContext, xml,
this.xmlFileFunctionResolver.registerFunction(WINDUP_NS_URI, "persist", new XmlFilePersistXPathFunction(event, context, xml,
evaluationStrategy, store, paramMatchCache, resultLocations));

if (compiledXPath == null)
Expand Down Expand Up @@ -424,13 +432,13 @@ else if (xpathString == null)
* This actually does the work.
*/
XmlUtil.xpathNodeList(document, compiledXPath);
evaluationStrategy.modelSubmissionRejected();
}
}
}
Variables.instance(event).setVariable(getOutputVariablesName(), resultLocations);

// reject the last one... this is because we essentially always end up with a blank frame at the end (yes, it's a hack)
evaluationStrategy.modelSubmissionRejected();

ExecutionStatistics.get().end("XmlFile.evaluate");
return !resultLocations.isEmpty();
Expand Down Expand Up @@ -484,17 +492,20 @@ public String toString()

final class XmlFilePersistXPathFunction implements XPathFunction
{
private final GraphContext graphContext;
private final GraphRewrite event;
private final EvaluationContext context;
private final XmlFileModel xml;
private final XmlFileEvaluationStrategy evaluationStrategy;
private final ParameterStore store;
private final XmlFileParameterMatchCache paramMatchCache;
private final List<WindupVertexFrame> resultLocations;

XmlFilePersistXPathFunction(GraphContext graphContext, XmlFileModel xml, XmlFileEvaluationStrategy evaluationStrategy, ParameterStore store,
XmlFilePersistXPathFunction(GraphRewrite event, EvaluationContext context, XmlFileModel xml, XmlFileEvaluationStrategy evaluationStrategy,
ParameterStore store,
XmlFileParameterMatchCache paramMatchCache, List<WindupVertexFrame> resultLocations)
{
this.graphContext = graphContext;
this.event = event;
this.context = context;
this.xml = xml;
this.evaluationStrategy = evaluationStrategy;
this.store = store;
Expand Down Expand Up @@ -527,7 +538,7 @@ public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunc
LocationAwareContentHandler.COLUMN_NUMBER_KEY_NAME);

GraphService<XmlTypeReferenceModel> fileLocationService = new GraphService<XmlTypeReferenceModel>(
graphContext,
event.getGraphContext(),
XmlTypeReferenceModel.class);
XmlTypeReferenceModel fileLocation = fileLocationService.create();
String sourceSnippit = XmlUtil.nodeToString(node);
Expand All @@ -538,7 +549,7 @@ public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunc
fileLocation.setFile(xml);
fileLocation.setXpath(xpathString);
GraphService<NamespaceMetaModel> metaModelService = new GraphService<NamespaceMetaModel>(
graphContext,
event.getGraphContext(),
NamespaceMetaModel.class);
for (Map.Entry<String, String> namespace : namespaces.entrySet())
{
Expand All @@ -552,6 +563,15 @@ public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunc

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

for (Map.Entry<String, String> entry : paramMatchCache.getVariables(frameIdx).entrySet())
{
Parameter<?> param = store.get(entry.getKey());
Expand Down

0 comments on commit 63b7512

Please sign in to comment.