this.loader = new ResourceLoader(new RdfResourceImporter(indexingDataset), true,true);
loader.addResource(sourceFileOrDirectory);
}
@Override
public void setConfiguration(Map<String,Object> config) {
IndexingConfig indexingConfig = (IndexingConfig)config.get(IndexingConfig.KEY_INDEXING_CONFIG);
//first init the RDF Model
this.indexingDataset = Utils.getTDBDataset(config);
//second we need to check if we need to import RDF files to the RDF model
//create the ResourceLoader
this.loader = new ResourceLoader(new RdfResourceImporter(indexingDataset), true);
Object value = config.get(PARAM_IMPORTED_FOLDER);
String importedFolderName;
if(value != null && !value.toString().isEmpty()){
importedFolderName = value.toString();
} else {
importedFolderName = DEFAULT_IMPORTED_FOLDER_NAME;
}
File importedFolder = new File(indexingConfig.getSourceFolder(),importedFolderName);
log.info("Imported RDF File Folder: {}",importedFolder);
this.loader.setImportedDir(importedFolder);
//check if importing is deactivated
boolean importSource = true; //default is true
value = config.get(PARAM_IMPORT_SOURCE);
if(value != null){
importSource = Boolean.parseBoolean(value.toString());
}
if(importSource){ // if we need to import ... check the source config
log.info("Importing RDF data from:");
value = config.get(PARAM_SOURCE_FILE_OR_FOLDER);
if(value == null){ //if not set use the default
value = DEFAULT_SOURCE_FOLDER_NAME;
}
for(String source : value.toString().split(",")){
File sourceFileOrDirectory = indexingConfig.getSourceFile(source);
if(sourceFileOrDirectory.exists()){
//register the configured source with the ResourceLoader
this.loader.addResource(sourceFileOrDirectory);
} else {
if(FilenameUtils.getExtension(source).isEmpty()){
//non existent directory -> create
//This is typically the case if this method is called to
//initialise the default configuration. So we will try
//to create the directory users need to copy the source
//RDF files.
if(!sourceFileOrDirectory.mkdirs()){
log.warn("Unable to create directory {} configured to improt RDF data from. " +
"You will need to create this directory manually before copying the" +
"RDF files into it.",sourceFileOrDirectory);
//this would not be necessary because the directory will
//be empty - however I like to be consistent and have
//all configured and existent files & dirs added the the
//resource loader
this.loader.addResource(sourceFileOrDirectory);
}
} else {
log.warn("Unable to find RDF source {} within the indexing Source folder ",source,indexingConfig.getSourceFolder());
}
}
}
if(log.isInfoEnabled()){
for(String registeredSource : loader.getResources(ResourceState.REGISTERED)){
log.info(" > "+registeredSource);
}
}
} else {
log.info("Importing RDF data deactivated by parameer {}={}"+PARAM_IMPORT_SOURCE,value);
}
//STANBOL-765: parsed bnode-prefix from parsed configuration.
value = config.get(PARAM_BNODE_STATE);
final Boolean bnodeState;
if(value != null){
bnodeState = value instanceof Boolean ? (Boolean) value :
Boolean.parseBoolean(value.toString());
} else if(config.containsKey(PARAM_BNODE_STATE)){ //support key without value
bnodeState = true;
} else {
bnodeState = null; //undefined
}
if(bnodeState == null || bnodeState){ //null or enabled -> consider prefix
value = config.get(PARAM_BNODE_PREFIX);
if(value != null){
try {
new URI(value.toString());
} catch (URISyntaxException e) {
throw new IllegalArgumentException("The configured "+PARAM_BNODE_PREFIX+"='"
+ value.toString() + "' MUST BE a valid URI!");
}
bnodePrefix = value.toString();
} else if(bnodeState != null) { //use default prefix if bnodeState is true
bnodePrefix = String.format("urn:bnode:%s:",indexingConfig.getName());
} // else bnodeState == null and no custom prefix -> disable by default
}
if(bnodePrefix != null){
log.info("Indexing of Bnodes enabled (prefix: {}",bnodePrefix);
} else {