add system property setting for found config path

This commit is contained in:
Jörg Prante 2020-09-16 11:34:15 +02:00
parent 2e19c8829a
commit ef3d38a4a5
4 changed files with 33 additions and 30 deletions

View file

@ -59,7 +59,9 @@ public class ConfigLoader {
Arrays.asList(fileNamesWithoutSuffix)); Arrays.asList(fileNamesWithoutSuffix));
} }
private Settings.Builder createClasspathSettings(ClassLoader classLoader, String applicationName, String fileNameWithoutSuffix) private Settings.Builder createClasspathSettings(ClassLoader classLoader,
String applicationName,
String fileNameWithoutSuffix)
throws IOException { throws IOException {
for (String suffix : List.of(YML, YAML, JSON)) { for (String suffix : List.of(YML, YAML, JSON)) {
InputStream inputStream = classLoader.getResourceAsStream(applicationName + '-' + InputStream inputStream = classLoader.getResourceAsStream(applicationName + '-' +
@ -83,6 +85,7 @@ public class ConfigLoader {
logger.info("trying " + path.toString()); logger.info("trying " + path.toString());
if (Files.exists(path)) { if (Files.exists(path)) {
logger.info("found path: " + path); logger.info("found path: " + path);
System.setProperty("config.path", path.getParent().toString());
return createSettingsFromStream(Files.newInputStream(path), suffix); return createSettingsFromStream(Files.newInputStream(path), suffix);
} }
} }

View file

@ -370,24 +370,24 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
* @param triple a triple * @param triple a triple
* @throws IOException if yield does not work * @throws IOException if yield does not work
*/ */
protected void yield(Triple triple) throws IOException { protected void yieldTriple(Triple triple) throws IOException {
if (builder != null) { if (builder != null) {
builder.receive(triple); builder.receive(triple);
} }
} }
private void yield(Object s, Object p, Object o) throws IOException { private void yieldTriple(Object s, Object p, Object o) throws IOException {
yield(new DefaultTriple(resource.newSubject(s), resource.newPredicate(p), resource.newObject(o))); yieldTriple(new DefaultTriple(resource.newSubject(s), resource.newPredicate(p), resource.newObject(o)));
} }
// produce a (possibly) reified triple // produce a (possibly) reified triple
private void yield(Object s, IRI p, Object o, IRI reified) throws IOException { private void yieldTriple(Object s, IRI p, Object o, IRI reified) throws IOException {
yield(s, p, o); yieldTriple(s, p, o);
if (reified != null) { if (reified != null) {
yield(reified, RDF_TYPE, RDF_STATEMENT); yieldTriple(reified, RDF_TYPE, RDF_STATEMENT);
yield(reified, RDF_SUBJECT, s); yieldTriple(reified, RDF_SUBJECT, s);
yield(reified, RDF_PREDICATE, p); yieldTriple(reified, RDF_PREDICATE, p);
yield(reified, RDF_OBJECT, o); yieldTriple(reified, RDF_OBJECT, o);
} }
} }
@ -473,7 +473,7 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
// we have the subject // we have the subject
if (!iri.equals(RDF_DESCRIPTION)) { if (!iri.equals(RDF_DESCRIPTION)) {
// this is a typed node, so assert the type // this is a typed node, so assert the type
yield(frame.node, RDF_TYPE, iri); yieldTriple(frame.node, RDF_TYPE, iri);
} }
// now process attribute-specified predicates // now process attribute-specified predicates
for (int i = 0; i < attrs.getLength(); i++) { for (int i = 0; i < attrs.getLength(); i++) {
@ -481,7 +481,7 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
String aUri = attrs.getURI(i) + attrs.getLocalName(i); String aUri = attrs.getURI(i) + attrs.getLocalName(i);
String aVal = attrs.getValue(i); String aVal = attrs.getValue(i);
if (!aUri.startsWith(RDF_STRING) && !aQn.startsWith("xml:")) { if (!aUri.startsWith(RDF_STRING) && !aQn.startsWith("xml:")) {
yield(frame.node, IRI.create(aUri), aVal); yieldTriple(frame.node, IRI.create(aUri), aVal);
} }
} }
// is this node the value of some enclosing predicate? // is this node the value of some enclosing predicate?
@ -492,7 +492,7 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
ppFrame.collection.add(frame.node); ppFrame.collection.add(frame.node);
} else { // not a collection } else { // not a collection
// this subject is the value of its enclosing predicate // this subject is the value of its enclosing predicate
yield(ancestorSubject(stack), parentPredicate(stack), frame.node); yieldTriple(ancestorSubject(stack), parentPredicate(stack), frame.node);
} }
} }
} }
@ -515,7 +515,7 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
// parse attrs to see if the value of this pred is a uriref // parse attrs to see if the value of this pred is a uriref
IRI object = getObjectNode(stack, attrs); IRI object = getObjectNode(stack, attrs);
if (object != null) { if (object != null) {
yield(ancestorSubject(stack), frame.node, object, frame.reification); yieldTriple(ancestorSubject(stack), frame.node, object, frame.reification);
} else { } else {
// this predicate encloses pcdata, prepare to accumulate // this predicate encloses pcdata, prepare to accumulate
pcdata = new StringBuilder(); pcdata = new StringBuilder();
@ -526,7 +526,7 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
switch (parseType) { switch (parseType) {
case "Resource": case "Resource":
object = object == null ? blankNode().id() : object; object = object == null ? blankNode().id() : object;
yield(ancestorSubject(stack), frame.node, object, frame.reification); yieldTriple(ancestorSubject(stack), frame.node, object, frame.reification);
// perform surgery on the current frame // perform surgery on the current frame
frame.node = object; frame.node = object;
frame.isSubject = true; frame.isSubject = true;
@ -562,13 +562,13 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
&& !aQn.startsWith("xml:")) { && !aQn.startsWith("xml:")) {
if (object == null) { if (object == null) {
object = blankNode().id(); object = blankNode().id();
yield(ancestorSubject(stack), frame.node, object); yieldTriple(ancestorSubject(stack), frame.node, object);
} }
if (aUri.equals(RDF_TYPE)) { if (aUri.equals(RDF_TYPE)) {
yield(object, RDF_TYPE, aVal); yieldTriple(object, RDF_TYPE, aVal);
} else { } else {
Literal value = withLanguageTag(new DefaultLiteral(aVal), stack); Literal value = withLanguageTag(new DefaultLiteral(aVal), stack);
yield(object, aUri, value); yieldTriple(object, aUri, value);
} }
} }
} }
@ -601,35 +601,35 @@ public class RdfXmlContentParser<R extends RdfContentParams> implements RdfConst
// this is a predicate closing // this is a predicate closing
if (xmlLiteral != null) { // it was an XMLLiteral if (xmlLiteral != null) { // it was an XMLLiteral
Literal value = new DefaultLiteral(xmlLiteral.toString()).type(RDF_XMLLITERAL); Literal value = new DefaultLiteral(xmlLiteral.toString()).type(RDF_XMLLITERAL);
yield(ancestorSubject(stack), parentPredicate(stack), value); yieldTriple(ancestorSubject(stack), parentPredicate(stack), value);
xmlLiteral = null; xmlLiteral = null;
} else if (pcdata != null) { // we have an RDF literal } else if (pcdata != null) { // we have an RDF literal
IRI u = ppFrame.datatype == null ? null : IRI.create(ppFrame.datatype); IRI u = ppFrame.datatype == null ? null : IRI.create(ppFrame.datatype);
Literal value = withLanguageTag(new DefaultLiteral(pcdata.toString()).type(u), stack); Literal value = withLanguageTag(new DefaultLiteral(pcdata.toString()).type(u), stack);
// deal with reification // deal with reification
IRI reification = ppFrame.reification; IRI reification = ppFrame.reification;
yield(ancestorSubject(stack), ppFrame.node, value, reification); yieldTriple(ancestorSubject(stack), ppFrame.node, value, reification);
// no longer collect pcdata // no longer collect pcdata
pcdata = null; pcdata = null;
} else if (ppFrame.isCollection) { // deal with collections } else if (ppFrame.isCollection) { // deal with collections
if (ppFrame.collection.isEmpty()) { if (ppFrame.collection.isEmpty()) {
// in this case, the value of this property is rdf:nil // in this case, the value of this property is rdf:nil
yield(ppFrame.collectionHead.subject(), yieldTriple(ppFrame.collectionHead.subject(),
ppFrame.collectionHead.predicate(), ppFrame.collectionHead.predicate(),
resource.newObject(RDF_NIL)); resource.newObject(RDF_NIL));
} else { } else {
yield(ppFrame.collectionHead); yieldTriple(ppFrame.collectionHead);
Object prevNode = null; Object prevNode = null;
Object node = ppFrame.collectionHead.object(); Object node = ppFrame.collectionHead.object();
for (IRI item : ppFrame.collection) { for (IRI item : ppFrame.collection) {
if (prevNode != null) { if (prevNode != null) {
yield(prevNode, RDF_REST, node); yieldTriple(prevNode, RDF_REST, node);
} }
yield(node, RDF_FIRST, item); yieldTriple(node, RDF_FIRST, item);
prevNode = node; prevNode = node;
node = blankNode().id(); node = blankNode().id();
} }
yield(prevNode, RDF_REST, RDF_NIL); yieldTriple(prevNode, RDF_REST, RDF_NIL);
} }
} }
} }

View file

@ -1,13 +1,13 @@
group = org.xbib group = org.xbib
name = content name = content
version = 2.5.0 version = 2.5.1
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 6.6.1
xbib.net.version = 2.1.0 xbib.net.version = 2.1.0
jackson.version = 2.11.1 jackson.version = 2.11.2
jackson.databind.version = 2.11.1 jackson.databind.version = 2.11.2
woodstox.version = 6.2.1 woodstox.version = 6.2.1
snakeyaml.version = 1.26 snakeyaml.version = 1.27
xbib-datastructures-tiny.version = 0.0.1 xbib-datastructures-tiny.version = 0.0.1
mockito.version = 3.3.3 mockito.version = 3.3.3
asciidoclet.version = 1.5.6 asciidoclet.version = 1.5.6