|
19 | 19 | import eu.europa.ec.itb.shacl.validation.FileManager;
|
20 | 20 | import eu.europa.ec.itb.shacl.validation.ReportSpecs;
|
21 | 21 | import eu.europa.ec.itb.shacl.validation.SHACLReportHandler;
|
| 22 | +import eu.europa.ec.itb.validation.commons.FileInfo; |
22 | 23 | import eu.europa.ec.itb.validation.commons.LocalisationHelper;
|
23 | 24 | import eu.europa.ec.itb.validation.commons.ReportPair;
|
| 25 | +import org.apache.jena.atlas.web.ContentType; |
24 | 26 | import org.apache.jena.query.Query;
|
25 | 27 | import org.apache.jena.query.QueryExecution;
|
26 | 28 | import org.apache.jena.query.QueryExecutionFactory;
|
27 | 29 | import org.apache.jena.query.QueryFactory;
|
28 | 30 | import org.apache.jena.rdf.model.Model;
|
29 | 31 | import org.apache.jena.rdf.model.RDFNode;
|
30 | 32 | import org.apache.jena.rdf.model.Statement;
|
| 33 | +import org.apache.jena.riot.Lang; |
| 34 | +import org.apache.jena.riot.RDFLanguages; |
31 | 35 | import org.slf4j.Logger;
|
32 | 36 | import org.slf4j.LoggerFactory;
|
33 | 37 | import org.springframework.util.MimeType;
|
@@ -115,6 +119,31 @@ public static String handleEquivalentContentSyntaxes(String contentSyntax) {
|
115 | 119 | return contentSyntax;
|
116 | 120 | }
|
117 | 121 |
|
| 122 | + /** |
| 123 | + * Determine the RDF language for the provided file. |
| 124 | + * |
| 125 | + * @param fileInfo The file information. |
| 126 | + * @return The language. |
| 127 | + */ |
| 128 | + public static Lang determineRdfLanguage(FileInfo fileInfo) { |
| 129 | + // First check content type. |
| 130 | + String contentType = handleEquivalentContentSyntaxes(fileInfo.getType()); |
| 131 | + if (isRdfContentSyntax(contentType)) { |
| 132 | + // This is an RDF content type. |
| 133 | + return RDFLanguages.contentTypeToLang(contentType); |
| 134 | + } else { |
| 135 | + // Not an RDF content type. |
| 136 | + ContentType guessedContentType = RDFLanguages.guessContentType(fileInfo.getFile().getName()); |
| 137 | + if (guessedContentType != null) { |
| 138 | + // We guessed the content type from the file name. |
| 139 | + return RDFLanguages.contentTypeToLang(guessedContentType); |
| 140 | + } else { |
| 141 | + // Use the original content type for a best-effort guess. |
| 142 | + return RDFLanguages.contentTypeToLang(fileInfo.getType()); |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + |
118 | 147 | /**
|
119 | 148 | * Make sure badly reported content types are correctly handled.
|
120 | 149 | *
|
|
0 commit comments