Skip to content

Commit

Permalink
Remove unecessary XmlDao reference
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraZizka committed Jun 21, 2014
1 parent 6362ef9 commit 17e4e7e
Showing 1 changed file with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.jboss.windup.config.parser;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.ConfigurationException;
import javax.inject.Inject;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
Expand All @@ -11,54 +8,45 @@
import javax.xml.xpath.XPathFactory;
import org.jboss.windup.config.ConfigurationException;
import org.jboss.windup.config.GraphRewrite;

import org.jboss.windup.config.condition.GraphCondition;
import org.jboss.windup.rules.apps.xml.dao.XmlResourceDao;
import org.jboss.windup.graph.model.resource.XmlResourceModel;
import org.ocpsoft.rewrite.context.EvaluationContext;
import org.w3c.dom.Document;


public class XPathMatchesCondition extends GraphCondition
{

@Inject
XmlResourceDao xmlDao;

protected final XPathExpression xpathExpression;

public XPathMatchesCondition(String pattern, NamespaceContext context)
{
final XPathFactory xPathFactory = XPathFactory.newInstance();
final XPath xpath = xPathFactory.newXPath();
xpath.setNamespaceContext(context);
try
{
try {
xpathExpression = xpath.compile(pattern);
}
catch (final XPathExpressionException e)
{
catch (final XPathExpressionException e) {
throw new ConfigurationException("Exception parsing the XPath pattern: " + pattern, e);
}
}

@Override
public boolean evaluate(GraphRewrite event, EvaluationContext context)
{
if (event.getResource() instanceof XmlResourceModel)
if( ! (event.getResource() instanceof XmlResourceModel) )
return false;

final XmlResourceModel resource = (XmlResourceModel) event.getResource();
try
{
final XmlResourceModel resource = (XmlResourceModel) event.getResource();
try
{
final Document document = resource.asDocument();
final Boolean result = (Boolean) xpathExpression.evaluate(document, XPathConstants.BOOLEAN);
return result;
}
catch (final Exception e)
{
throw new RuntimeException("Exception evaluating rule.", e);
}
final Document document = resource.asDocument();
final Boolean result = (Boolean) xpathExpression.evaluate(document, XPathConstants.BOOLEAN);
return result;
}
catch (final Exception e)
{
throw new RuntimeException("Exception evaluating rule.", e);
}
return false;
}

}

0 comments on commit 17e4e7e

Please sign in to comment.