Skip to content

Commit 4cb6b7b

Browse files
author
emarx
committed
- adding customized install method either in KBox.getResource and KBox.install
1 parent fccca2e commit 4cb6b7b

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

kbox.core.test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>org.aksw.kbox</groupId>
3030
<artifactId>kbox.core</artifactId>
31-
<version>0.0.1-alpha1</version>
31+
<version>0.0.1-alpha2</version>
3232
</dependency>
3333
</dependencies>
3434
<repositories>

kbox.core.test/src/test/java/org/aksw/kbox/KBoxTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public void testResourceFolderMethods() throws MalformedURLException, Exception
1616
String currentResourceFolder = KBox.getResourceFolder();
1717
KBox.setResourceFolder("c:" + File.separator);
1818
assertEquals("c:" + File.separator, KBox.getResourceFolder());
19-
KBox.setResourceFolder(KBox.KBOX_DIR);
2019
KBox.setResourceFolder(currentResourceFolder);
2120
}
2221

@@ -36,13 +35,13 @@ public void testPublishMethods() throws MalformedURLException, Exception {
3635
File test = KBox.getResource(new URL("http://tttt"));
3736
assertEquals(null, test);
3837
URL fileToInstall = new URL("http://downloads.dbpedia.org/3.8/en/contents-nt.txt");
39-
File rboxedFile = KBox.getResource(fileToInstall);
38+
File kboxedFile = KBox.getResource(fileToInstall);
4039
KBox.install(new URL("http://test.org/context.txt"), fileToInstall);
4140
String path = KBox.URLToPath(new URL("http://test.org/context.txt"));
4241
File inDisk = new File(KBox.getResourceFolder() + File.separator + path);
4342
assertEquals(true, inDisk.exists());
44-
rboxedFile = KBox.getResource(new URL("http://test.org/context.txt"));
45-
assertEquals(rboxedFile.getPath(), inDisk.getPath());
43+
kboxedFile = KBox.getResource(new URL("http://test.org/context.txt"));
44+
assertEquals(kboxedFile.getPath(), inDisk.getPath());
4645
}
4746

4847
}

kbox.core/src/main/java/org/aksw/kbox/KBox.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ public static File getResource(URL url, boolean install) throws Exception {
181181
return resource;
182182
}
183183

184+
/**
185+
* Get a local representation of the remote resource.
186+
* If the representation of the resource already exists,
187+
* return it, otherwise create a local representation and
188+
* return it.
189+
*
190+
* @param url - the remote URL of the resource to be retrieved.
191+
* @param install - specify if the resource should be installed (true) or not (false).
192+
* @param method - the method that will be used to install the resource
193+
* in case it is not installed and install install param is set true.
194+
*
195+
* @return a file pointing to a local materialization of the resource.
196+
* @throws Exception if the resource can not be located or some error occurs during
197+
* the local resource materialization.
198+
*/
199+
public static File getResource(URL url, Install method, boolean install) throws Exception {
200+
File resource = new File(URLToAbsolutePath(url));
201+
if(!resource.exists() && !install) {
202+
return null;
203+
} else if(resource.exists() && !install) {
204+
return resource;
205+
}
206+
install(url, url, method);
207+
return resource;
208+
}
209+
184210
/**
185211
* Get a local representation of the remote resource.
186212
* If the representation of the resource already exists,
@@ -266,4 +292,44 @@ public static void install(URL url, InputStream inputStream) throws Exception {
266292
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
267293
}
268294
}
295+
296+
/**
297+
* Publish a given file in a given URL local directory.
298+
* This function allows KBox to serve files to applications, acting as proxy to the publised file.
299+
* The file that is published in a give URL u will be located when the client execute
300+
* the function KBox.getResource(u).
301+
*
302+
* @param source - the URL of the file that is going to be published at the given URL.
303+
* @param dest - the URL where the file is going to be published. *
304+
* @param install - a customized method for installation.
305+
*
306+
* @throws Exception if the resource does not exist or can not be copied or some error
307+
* occurs during the resource publication.
308+
*/
309+
public static void install(URL source, URL dest, Install install) throws Exception {
310+
install.install(source, dest);
311+
}
312+
313+
/**
314+
* Install a given ZIP file from a given URL.
315+
*
316+
* @param source the source URL containing the ZIP file to be installed.
317+
* @param dest the URL whereas the source will be installed.
318+
* @throws Exception if an error occurs during the installation.
319+
*/
320+
public static void installFromZip(URL source, URL dest) throws Exception {
321+
ZipInstall zipInstall = new ZipInstall();
322+
install(source, dest, zipInstall);
323+
}
324+
325+
/**
326+
* Install a given ZIP file from a given URL.
327+
*
328+
* @param source the source URL containing the ZIP file to be installed.
329+
* @throws Exception if an error occurs during the installation.
330+
*/
331+
public static void installFromZip(URL source) throws Exception {
332+
ZipInstall zipInstall = new ZipInstall();
333+
install(source, source, zipInstall);
334+
}
269335
}

kbox.kibe.test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>org.aksw.kbox</groupId>
3030
<artifactId>kbox.kibe</artifactId>
31-
<version>0.0.1-alpha1</version>
31+
<version>0.0.1-alpha2</version>
3232
</dependency>
3333
</dependencies>
3434
<repositories>

kbox.kibe/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>org.aksw.kbox</groupId>
2525
<artifactId>kbox.core</artifactId>
26-
<version>0.0.1-alpha1</version>
26+
<version>0.0.1-alpha2</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>org.apache.jena</groupId>

0 commit comments

Comments
 (0)