jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject jena git commit: JENA-662 : Filename handling in FileModelAssembler
Date Fri, 02 Jan 2015 13:31:52 GMT
Repository: jena
Updated Branches:
  refs/heads/master 98e2c391c -> e3b6d4410


JENA-662 : Filename handling in FileModelAssembler


This closes #16

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e3b6d441
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e3b6d441
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e3b6d441

Branch: refs/heads/master
Commit: e3b6d4410036d4af2ee8fa6a0329bcf5b43f8adb
Parents: 98e2c39
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Jan 2 13:31:36 2015 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Jan 2 13:31:36 2015 +0000

----------------------------------------------------------------------
 .../assemblers/FileModelAssembler.java          | 17 ++++++-
 .../assembler/test/TestFileModelAssembler.java  | 50 ++++++++++++++++++--
 2 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e3b6d441/jena-core/src/main/java/com/hp/hpl/jena/assembler/assemblers/FileModelAssembler.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/assembler/assemblers/FileModelAssembler.java
b/jena-core/src/main/java/com/hp/hpl/jena/assembler/assemblers/FileModelAssembler.java
index 68e26f8..338504f 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/assembler/assemblers/FileModelAssembler.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/assembler/assemblers/FileModelAssembler.java
@@ -19,6 +19,12 @@
 package com.hp.hpl.jena.assembler.assemblers;
 
 import java.io.File ;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.hp.hpl.jena.assembler.Assembler ;
 import com.hp.hpl.jena.assembler.JA ;
@@ -32,6 +38,9 @@ import com.hp.hpl.jena.util.FileUtils ;
 
 public class FileModelAssembler extends NamedModelAssembler implements Assembler
     {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(FileModelAssembler.class);
+
     @Override
     protected Model openEmptyModel( Assembler a, Resource root, Mode mode )
         {
@@ -90,6 +99,12 @@ public class FileModelAssembler extends NamedModelAssembler implements
Assembler
 
     private String getDirectoryName( Resource root )
         {
-        return getRequiredResource( root, JA.directory ).getURI().replaceFirst( "file:",
"" );
+        String dir = getRequiredResource( root, JA.directory ).getURI().replaceFirst( "file:",
"" );
+        try {
+            dir = URLDecoder.decode(dir, StandardCharsets.UTF_8.name());
+        } catch (UnsupportedEncodingException e) {
+            LOGGER.warn(String.format("Failed to decode dir %s: %s", dir, e.getMessage()),
e);
+        }
+        return dir;
         }
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/e3b6d441/jena-core/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
b/jena-core/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
index cd9fb62..b5a0efb 100644
--- a/jena-core/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
@@ -18,18 +18,33 @@
 
 package com.hp.hpl.jena.assembler.test;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 
-import com.hp.hpl.jena.assembler.*;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.BadObjectException;
+import com.hp.hpl.jena.assembler.JA;
+import com.hp.hpl.jena.assembler.Mode;
 import com.hp.hpl.jena.assembler.assemblers.FileModelAssembler;
 import com.hp.hpl.jena.graph.impl.FileGraph;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.shared.*;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.shared.JenaException;
 import com.hp.hpl.jena.util.FileUtils;
 
 public class TestFileModelAssembler extends AssemblerTestBase
     {
- 
+
+    @Rule
+    private final TemporaryFolder tempFolder = new TemporaryFolder();
+
     public TestFileModelAssembler( String name )
         { super( name );  }
 
@@ -234,4 +249,31 @@ public class TestFileModelAssembler extends AssemblerTestBase
         Model m = a.openModel( root  );
         assertSame( model, m );
         }
+
+    @Test
+    public void testDecodeDirectoryName() throws IOException
+        {
+            // TODO: JenaTestBase is mixing JUnit3 and JUnit4 classes, and the
+            // rule doesn't get called correctly.
+            tempFolder.create();
+            assertTrue(tempFolder.getRoot().isDirectory());
+            File folderWithSpace = tempFolder.newFolder("folder with space");
+            folderWithSpace.mkdir();
+            File modelFile = new File(folderWithSpace, "file with space.ttl");
+            modelFile.createNewFile();
+            String graphs = "";
+            graphs += "@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> . ";
+            graphs += "<http://example.org/file> a ja:FileModel ; ";
+            graphs += "ja:directory <file:///" + tempFolder.getRoot().getAbsolutePath()
+ "/folder%20with%20space/> ; ";
+            graphs += "ja:modelName \"" + modelFile.getName() + "\" . ";
+
+            InputStream is = new ByteArrayInputStream(graphs.getBytes());
+
+            Model model = ModelFactory.createDefaultModel();
+            model.read(is, "http://example.org/", "TURTLE");
+            Resource r = model.createResource("http://example.org/file");
+            Model assemblerModel = (Model) Assembler.general.open(r);
+            assertNotNull(assemblerModel);
+            tempFolder.delete();
+        }
     }


Mime
View raw message