diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 000000000..a40f22744
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 000000000..2cd7e95da
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 000000000..45bb0576b
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..9e0563eb9
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..35eb1ddfb
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileSystem.java b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileSystem.java
index 9d2cbae7f..0bd9d5ba4 100644
--- a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileSystem.java
+++ b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileSystem.java
@@ -8,9 +8,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@
* under the License.
*/
-
import java.io.IOException;
import java.net.URI;
import java.nio.file.ClosedFileSystemException;
@@ -49,7 +48,6 @@ protected BundleFileSystem(FileSystem origFS, URI baseURI) {
this.baseURI = baseURI;
this.separator = origFS.getSeparator();
this.source = findSource();
-
}
@Override
@@ -58,26 +56,26 @@ public void close() throws IOException {
return;
}
origFS.close();
- // De-reference the original ZIP file system so it can be
- // garbage collected
origFS = null;
}
protected Path findSource() {
- Path zipRoot = getRootDirectory().getZipPath();
- URI uri = zipRoot.toUri();
- String schemeSpecific;
- if (provider().getJarDoubleEscaping()) {
- schemeSpecific = uri.getSchemeSpecificPart();
- } else {
- // http://dev.mygrid.org.uk/issues/browse/T3-954
- schemeSpecific = uri.getRawSchemeSpecificPart();
+ URI uri = this.baseURI;
+
+ if (uri.getScheme().equals("arcp")) {
+ // Handle arcp:// URI scheme separately
+ return Paths.get(uri.getPath());
}
- if (!schemeSpecific.endsWith("!/")) { // sanity check
- throw new IllegalStateException("Can't parse JAR URI: " + uri);
+
+ // Default handling for zip URIs
+ Path zipRoot = getRootDirectory().getZipPath();
+ String schemeSpecific = uri.getRawSchemeSpecificPart();
+
+ if (!schemeSpecific.endsWith("!/")) {
+ throw new IllegalStateException("Can't parse URI: " + uri);
}
- URI zip = URI.create(schemeSpecific.substring(0,
- schemeSpecific.length() - 2));
+
+ URI zip = URI.create(schemeSpecific.substring(0, schemeSpecific.length() - 2));
return Paths.get(zip); // Look up our path
}
@@ -86,21 +84,14 @@ public URI getBaseURI() {
}
protected BundleFileStore getFileStore() {
- // We assume there's only one file store, as is true for ZipProvider
- return new BundleFileStore(this, getOrigFS().getFileStores().iterator()
- .next());
+ return new BundleFileStore(this, getOrigFS().getFileStores().iterator().next());
}
@Override
public Iterable getFileStores() {
- return Collections. singleton(getFileStore());
+ return Collections.singleton(getFileStore());
}
- /**
- * Thread-safe ClosedFileSystemException test
- *
- * @return
- */
protected FileSystem getOrigFS() {
FileSystem orig = origFS;
if (orig == null || !orig.isOpen()) {
@@ -117,8 +108,7 @@ public Path getPath(String first, String... more) {
@Override
public PathMatcher getPathMatcher(String syntaxAndPattern) {
- final PathMatcher zipMatcher = getOrigFS().getPathMatcher(
- syntaxAndPattern);
+ final PathMatcher zipMatcher = getOrigFS().getPathMatcher(syntaxAndPattern);
return new PathMatcher() {
@Override
public boolean matches(Path path) {
@@ -129,7 +119,7 @@ public boolean matches(Path path) {
@Override
public Iterable getRootDirectories() {
- return Collections. singleton(getRootDirectory());
+ return Collections.singleton(getRootDirectory());
}
public BundlePath getRootDirectory() {
@@ -152,10 +142,7 @@ public UserPrincipalLookupService getUserPrincipalLookupService() {
@Override
public boolean isOpen() {
- if (origFS == null) {
- return false;
- }
- return origFS.isOpen();
+ return origFS != null && origFS.isOpen();
}
@Override
@@ -183,13 +170,11 @@ public Set supportedFileAttributeViews() {
protected Path unwrap(Path bundlePath) {
if (!(bundlePath instanceof BundlePath)) {
- // assume it's already unwrapped for some reason (for instance being
- // null)
return bundlePath;
}
return ((BundlePath) bundlePath).getZipPath();
}
-
+
protected static Path withoutSlash(Path dir) {
if (dir == null) {
return null;
@@ -198,7 +183,7 @@ protected static Path withoutSlash(Path dir) {
if (fname == null) // Root directory?
return dir;
String fnameStr = fname.toString();
- if (! fnameStr.endsWith("/") && ! fnameStr.equals("/"))
+ if (!fnameStr.endsWith("/") && !fnameStr.equals("/"))
return dir;
return dir.resolveSibling(fnameStr.replace("/", ""));
}
@@ -208,10 +193,9 @@ protected BundlePath wrap(Path zipPath) {
return null;
}
if (zipPath instanceof BundlePath) {
- throw new IllegalArgumentException("Did not expect BundlePath: "
- + zipPath);
+ throw new IllegalArgumentException("Did not expect BundlePath: " + zipPath);
}
-
+
return new BundlePath(this, withoutSlash(zipPath));
}
@@ -233,5 +217,4 @@ public void remove() {
}
};
}
-
}
diff --git a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileTypeDetector.java b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileTypeDetector.java
index 03f82722f..63d19faca 100644
--- a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileTypeDetector.java
+++ b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundleFileTypeDetector.java
@@ -1,25 +1,5 @@
package org.apache.taverna.robundle.fs;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -37,54 +17,52 @@
public class BundleFileTypeDetector extends FileTypeDetector {
private static final String APPLICATION_ZIP = "application/zip";
- private static final Charset ASCII = Charset.forName("ASCII");
- private static final Charset LATIN1 = Charset.forName("ISO-8859-1");
+ private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final String MIMETYPE = "mimetype";
+ private static final String ZIP_MAGIC_NUMBER = "PK";
@Override
public String probeContentType(Path path) throws IOException {
-
ByteBuffer buf = ByteBuffer.allocate(256);
- try (SeekableByteChannel byteChannel = Files.newByteChannel(path,
- StandardOpenOption.READ)) {
+
+ try (SeekableByteChannel byteChannel = Files.newByteChannel(path, StandardOpenOption.READ)) {
int read = byteChannel.read(buf);
if (read < 38) {
return null;
}
- ;
}
- buf.flip();
-
- // Look for PK
+ buf.flip();
byte[] firstBytes = buf.array();
- String pk = new String(firstBytes, 0, 2, LATIN1);
- if (!(pk.equals("PK") && firstBytes[2] == 3 && firstBytes[3] == 4)) {
- // Did not match magic numbers of ZIP as specified in ePub OCF
- // http://www.idpf.org/epub/30/spec/epub30-ocf.html#app-media-type
+
+ // Look for ZIP magic number ("PK")
+ String pk = new String(firstBytes, 0, 2, UTF_8);
+ if (!pk.equals(ZIP_MAGIC_NUMBER) || firstBytes[2] != 3 || firstBytes[3] != 4) {
+ // Not a ZIP file
return null;
}
- String mimetype = new String(firstBytes, 30, 8, LATIN1);
+ String mimetype = new String(firstBytes, 30, 8, UTF_8);
if (!mimetype.equals(MIMETYPE)) {
return APPLICATION_ZIP;
}
- // Read the 'mimetype' file.
- try (ZipInputStream is = new ZipInputStream(new ByteArrayInputStream(
- firstBytes))) {
- ZipEntry entry = is.getNextEntry();
- if (!MIMETYPE.equals(entry.getName())) {
+
+ // Read the 'mimetype' file from the ZIP
+ try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(firstBytes))) {
+ ZipEntry entry = zipStream.getNextEntry();
+ if (entry == null || !MIMETYPE.equals(entry.getName())) {
return APPLICATION_ZIP;
}
+
byte[] mediaTypeBuffer = new byte[256];
- int size = is.read(mediaTypeBuffer);
+ int size = zipStream.read(mediaTypeBuffer);
if (size < 1) {
return APPLICATION_ZIP;
}
- return new String(mediaTypeBuffer, 0, size, ASCII);
+ return new String(mediaTypeBuffer, 0, size, UTF_8);
} catch (ZipException | ZipError e) {
+ // Log the error (optional)
return null;
}
}
-
}
diff --git a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundlePath.java b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundlePath.java
index a908f67c7..9b1b47df1 100644
--- a/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundlePath.java
+++ b/taverna-robundle/src/main/java/org/apache/taverna/robundle/fs/BundlePath.java
@@ -8,9 +8,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@
* under the License.
*/
-
import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -36,13 +35,12 @@
public class BundlePath implements Path {
private final BundleFileSystem fs;
-
private final Path zipPath;
protected BundlePath(BundleFileSystem fs, Path zipPath) {
if (fs == null || zipPath == null) {
- throw new NullPointerException();
- }
+ throw new NullPointerException("FileSystem and Path must not be null");
+ }
this.fs = fs;
this.zipPath = zipPath;
}
@@ -133,7 +131,7 @@ public WatchKey register(WatchService watcher, Kind>... events)
@Override
public WatchKey register(WatchService watcher, Kind>[] events,
- Modifier... modifiers) throws IOException {
+ Modifier... modifiers) throws IOException {
throw new UnsupportedOperationException();
}
@@ -184,7 +182,7 @@ public BundlePath toAbsolutePath() {
@Override
public File toFile() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("Conversion to File is unsupported");
}
@Override
@@ -210,16 +208,15 @@ public String toString() {
public URI toUri() {
Path abs = zipPath.toAbsolutePath();
String absStr = abs.toString();
- if (Files.isDirectory(abs) && ! absStr.endsWith("/")) {
+ if (Files.isDirectory(abs) && !absStr.endsWith("/")) {
absStr += "/";
}
-
+
URI pathRel;
try {
pathRel = new URI(null, null, absStr, null);
} catch (URISyntaxException e) {
- throw new IllegalStateException("Can't create URL for " + zipPath,
- e);
+ throw new IllegalStateException("Can't create URL for " + zipPath, e);
}
return fs.getBaseURI().resolve(pathRel);
}
diff --git a/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/Manifest.java b/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/Manifest.java
index 437d9f9dd..2dda228fe 100644
--- a/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/Manifest.java
+++ b/taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/Manifest.java
@@ -68,7 +68,7 @@
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ObjectMapper;
-@JsonPropertyOrder(value = { "@context", "id", "manifest", "conformsTo","createdOn",
+@JsonPropertyOrder(value = { "@context", "id", "manifest", "conformsTo", "createdOn",
"createdBy", "createdOn", "authoredOn", "authoredBy",
"retrievedFrom", "retrievedOn", "retrievedBy",
"history", "aggregates", "annotations", "@graph" })
@@ -169,11 +169,11 @@ public List getAnnotations(final URI about) {
}
// Compare absolute URIs against absolute URIs
return getAnnotations().stream()
- .filter(a -> a.getAboutList().stream()
- .map(manifestBase::resolve)
- .filter(aboutAbs::equals)
- .findAny().isPresent())
- .collect(Collectors.toList());
+ .filter(a -> a.getAboutList().stream()
+ .map(manifestBase::resolve)
+ .filter(aboutAbs::equals)
+ .findAny().isPresent())
+ .collect(Collectors.toList());
}
@JsonIgnore
@@ -207,9 +207,6 @@ public List getConformsTo() {
@JsonProperty(value = "@context")
public List