Skip to content
Snippets Groups Projects
Commit ee5defdb authored by Dean Jonas Finkes's avatar Dean Jonas Finkes
Browse files

added matcher

parent 9d6962c4
No related branches found
No related tags found
No related merge requests found
package controller;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.Transaction;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import java2sdg.db.Neo4Jdb;
public class Matcher {
public ArrayList<String> applyCP(String pathToDB, String pathToPatternFolder)
throws ParserConfigurationException, SAXException, IOException {
File dir = new File(pathToPatternFolder);
ArrayList<String> matchingCPs = new ArrayList<String>();
if (dir.isDirectory()) {
File[] patterns = dir.listFiles();
if (patterns.length > 0) {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc;
Element root;
GraphDatabaseService db = new Neo4Jdb(pathToDB).getGraphDatabaseService();
for (int i = 0; i < patterns.length; i++) {
doc = dBuilder.parse(patterns[i]);
doc.normalize();
root = doc.getDocumentElement();
String name = root.getElementsByTagName("name").item(0).getTextContent();
String cpQuery = root.getElementsByTagName("cp").item(0).getTextContent();
try (Transaction tx = db.beginTx(); Result result = db.execute(cpQuery)) {
if (result.hasNext()) {
matchingCPs.add(name);
}
tx.success();
}
}
db.shutdown();
}
}
return matchingCPs;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment