You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/09/02 11:24:48 UTC
[1/2] git commit: added a draft implementation MARMOTTA-293 based on
url-encoded paths, open to testing and discussion
Updated Branches:
refs/heads/develop 34771f266 -> 1b697565e
added a draft implementation MARMOTTA-293 based on url-encoded paths, open to testing and discussion
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/00956609
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/00956609
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/00956609
Branch: refs/heads/develop
Commit: 009566090cea4a6bf6042997418cb1cfec9ed104
Parents: 34771f2
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Sep 2 10:08:48 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Sep 2 10:08:48 2013 +0200
----------------------------------------------------------------------
.../services/importer/ImportWatchServiceImpl.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/00956609/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
index 54f16c1..10803cd 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
@@ -20,6 +20,8 @@ package org.apache.marmotta.platform.core.services.importer;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -194,7 +196,17 @@ public class ImportWatchServiceImpl implements ImportWatchService {
if (StringUtils.isBlank(subdir)) {
return contextService.getDefaultContext();
} else {
- return contextService.createContext(configurationService.getBaseContext() + subdir.substring(1));
+ subdir = subdir.substring(1); //remove initial slash
+ if (StringUtils.startsWith(subdir, "http%3A%2F%2F")) {
+ try {
+ return contextService.createContext(URLDecoder.decode(subdir, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ log.error("Error url-decoding context name '{}', so using the default one: {}", subdir, e.getMessage());
+ return contextService.getDefaultContext();
+ }
+ } else {
+ return contextService.createContext(configurationService.getBaseContext() + subdir);
+ }
}
}
[2/2] git commit: some workaround MARMOTTA-297 and encoding hypothesis
Posted by wi...@apache.org.
some workaround MARMOTTA-297 and encoding hypothesis
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/1b697565
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/1b697565
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/1b697565
Branch: refs/heads/develop
Commit: 1b697565ec6c1c9c865c741c899001525c05db75
Parents: 0095660
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Sep 2 11:12:51 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Sep 2 11:12:51 2013 +0200
----------------------------------------------------------------------
parent/pom.xml | 5 +++
platform/marmotta-core/pom.xml | 4 ++
.../services/importer/ImportServiceImpl.java | 9 ++++-
.../importer/ImportWatchServiceImpl.java | 39 ++++++++++++++++++--
4 files changed, 53 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/1b697565/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 283c25e..2576d27 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1320,6 +1320,11 @@
<artifactId>tika-core</artifactId>
<version>1.4</version>
</dependency>
+ <dependency>
+ <groupId>com.ibm.icu</groupId>
+ <artifactId>icu4j</artifactId>
+ <version>51.2</version>
+ </dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/1b697565/platform/marmotta-core/pom.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/pom.xml b/platform/marmotta-core/pom.xml
index 654c052..6ebaaf8 100644
--- a/platform/marmotta-core/pom.xml
+++ b/platform/marmotta-core/pom.xml
@@ -554,6 +554,10 @@
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.ibm.icu</groupId>
+ <artifactId>icu4j</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/1b697565/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportServiceImpl.java
index ddde2ac..2c95d3b 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportServiceImpl.java
@@ -17,6 +17,7 @@
*/
package org.apache.marmotta.platform.core.services.importer;
+import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.platform.core.api.importer.ImportService;
import org.apache.marmotta.platform.core.api.importer.Importer;
import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
@@ -28,6 +29,7 @@ import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
+
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
@@ -97,7 +99,12 @@ public class ImportServiceImpl implements ImportService{
}
private Importer getImporterInstance(String type) throws MarmottaImportException {
- if(!importerMap.containsKey(type)) throw new MarmottaImportException("no importer defined for type "+type);
+ if (StringUtils.contains(type, ';')) {
+ type = type.split(";")[0];
+ }
+ if(!importerMap.containsKey(type)) {
+ throw new MarmottaImportException("no importer defined for type " + type);
+ }
return importerMap.get(type);
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/1b697565/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
index 10803cd..a061dc9 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/importer/ImportWatchServiceImpl.java
@@ -17,6 +17,7 @@
*/
package org.apache.marmotta.platform.core.services.importer;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -52,6 +53,9 @@ import org.openrdf.model.URI;
import org.openrdf.rio.Rio;
import org.slf4j.Logger;
+import com.ibm.icu.text.CharsetDetector;
+import com.ibm.icu.text.CharsetMatch;
+
/**
* Implementation for watching import directory
*
@@ -172,9 +176,10 @@ public class ImportWatchServiceImpl implements ImportWatchService {
@Override
public boolean execImport(File file, URI context) {
try {
- importService.importData(new FileInputStream(file),
- Rio.getParserFormatForFileName(file.getName()).getDefaultMIMEType(),
- userService.getAdminUser(), context);
+ String format = detectFormat(file);
+ FileInputStream is = new FileInputStream(file);
+ URI user = userService.getAdminUser();
+ importService.importData(is, format, user, context);
return true;
} catch (MarmottaImportException e) {
log.error("Error importing file {} from the local directory: {}", file.getAbsolutePath(), e.getMessage());
@@ -184,6 +189,34 @@ public class ImportWatchServiceImpl implements ImportWatchService {
return false;
}
}
+
+ private String detectFormat(File file) throws MarmottaImportException {
+ String format = null;
+ String fileName = file.getName();
+
+ //mimetype detection
+ String mimetype = Rio.getParserFormatForFileName(fileName).getDefaultMIMEType();
+ if (mimetype != null && importService.getAcceptTypes().contains(mimetype)) {
+ format = mimetype;
+ } else {
+ throw new MarmottaImportException("Suitable RDF parser not found");
+ }
+
+ //encoding detection
+ try {
+ BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
+ CharsetDetector cd = new CharsetDetector();
+ cd.setText(bis);
+ CharsetMatch cm = cd.detect();
+ if (cm != null) {
+ format += "; charset=" + cm.getName();
+ }
+ } catch (IOException e) {
+ log.error("Error detecting charset for '{}': {}", fileName, e.getMessage());
+ }
+
+ return format;
+ }
/**
* Get the target context, according the path relative to the base import directory