Ignore markdown files in RDF directories.

People want to document the RDF directories (such as rdf/abox/filegraph) by adding README.md files
Such files produce either a warning or an exception, depending on the directory and who is reading.
Modify to ignore any file with a .md extension.
This commit is contained in:
Jim Blake 2015-03-20 15:34:53 -04:00
parent ed0b7f0f0d
commit abea644f46
3 changed files with 18 additions and 8 deletions

View file

@ -40,8 +40,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ModelSerializationFormat; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ModelSerializationFormat;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
// This ContextListener must run after the JenaDataSourceSetup ContextListener // This ContextListener must run after the JenaDataSourceSetup ContextListener
@ -164,6 +164,8 @@ public class FileGraphSetup implements ServletContextListener {
model.read( fis, null, "N3" ); model.read( fis, null, "N3" );
} else if ( fn.endsWith(".owl") || fn.endsWith(".rdf") || fn.endsWith(".xml") ) { } else if ( fn.endsWith(".owl") || fn.endsWith(".rdf") || fn.endsWith(".xml") ) {
model.read( fis, null, "RDF/XML" ); model.read( fis, null, "RDF/XML" );
} else if ( fn.endsWith(".md") ) {
// Ignore markdown files - documentation.
} else { } else {
log.warn("Ignoring " + type + " file graph " + p + " because the file extension is unrecognized."); log.warn("Ignoring " + type + " file graph " + p + " because the file extension is unrecognized.");
} }

View file

@ -34,7 +34,10 @@ public class RDFFilesLoader {
private static final String FIRST_TIME = "firsttime"; private static final String FIRST_TIME = "firsttime";
private static final String EVERY_TIME = "everytime"; private static final String EVERY_TIME = "everytime";
/** Path filter that ignores sub-directories and hidden files. */ /**
* Path filter that ignores sub-directories, hidden files, and markdown
* files.
*/
private static final DirectoryStream.Filter<Path> RDF_FILE_FILTER = new DirectoryStream.Filter<Path>() { private static final DirectoryStream.Filter<Path> RDF_FILE_FILTER = new DirectoryStream.Filter<Path>() {
@Override @Override
public boolean accept(Path p) throws IOException { public boolean accept(Path p) throws IOException {
@ -46,6 +49,9 @@ public class RDFFilesLoader {
+ p + "' ignored."); + p + "' ignored.");
return false; return false;
} }
if (p.toString().endsWith(".md")) {
return false;
}
return true; return true;
} }
}; };
@ -61,8 +67,8 @@ public class RDFFilesLoader {
public static void loadFirstTimeFiles(String modelPath, Model model, public static void loadFirstTimeFiles(String modelPath, Model model,
boolean firstTime) { boolean firstTime) {
if (firstTime) { if (firstTime) {
Set<Path> paths = getPaths(locateHomeDirectory(), RDF, Set<Path> paths = getPaths(locateHomeDirectory(), RDF, modelPath,
modelPath, FIRST_TIME); FIRST_TIME);
for (Path p : paths) { for (Path p : paths) {
readOntologyFileIntoModel(p, model); readOntologyFileIntoModel(p, model);
} }
@ -128,8 +134,8 @@ public class RDFFilesLoader {
} }
/** /**
* Find the paths to RDF files in this directory. Sub-directories and hidden * Find the paths to RDF files in this directory. Sub-directories, hidden
* files are ignored. * files, and markdown files are ignored.
*/ */
private static Set<Path> getPaths(String parentDir, String... strings) { private static Set<Path> getPaths(String parentDir, String... strings) {
Path dir = Paths.get(parentDir, strings); Path dir = Paths.get(parentDir, strings);
@ -153,7 +159,7 @@ public class RDFFilesLoader {
private static void readOntologyFileIntoModel(Path p, Model model) { private static void readOntologyFileIntoModel(Path p, Model model) {
String format = getRdfFormat(p); String format = getRdfFormat(p);
log.debug("Loading "+ p); log.debug("Loading " + p);
try (InputStream stream = new FileInputStream(p.toFile())) { try (InputStream stream = new FileInputStream(p.toFile())) {
model.read(stream, null, format); model.read(stream, null, format);
log.debug("...successful"); log.debug("...successful");

View file

@ -532,7 +532,9 @@ public class UpdateKnowledgeBase {
try { try {
FileInputStream fis = new FileInputStream(f); FileInputStream fis = new FileInputStream(f);
try { try {
if (f.getName().endsWith(".n3")) { if (f.getName().endsWith(".md")) {
// Markdown files are documentation - skip.
} else if (f.getName().endsWith(".n3")) {
om.read(fis, null, "N3"); om.read(fis, null, "N3");
} else { } else {
om.read(fis, null, "RDF/XML"); om.read(fis, null, "RDF/XML");