summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
diff options
context:
space:
mode:
authoradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 01:40:02 +0000
committeradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 01:40:02 +0000
commit8e7db232ee169c8d8513c8e8a84921d905e4af2d (patch)
tree0cc43203723c019a13f23a1b46b466639ed37da0 /branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
parent1dff5319f17ee5bec9588675d43a84e836627a5d (diff)
applying tuscany_2552_domain_search_phillipe_ramalho_08_08_2009.patch and tuscany_2552_domain_manager_phillipe_ramalho_08_08_2009.patch submitted to TUSCANY-2552
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@802637 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
new file mode 100644
index 0000000000..618d984830
--- /dev/null
+++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
@@ -0,0 +1,91 @@
+package org.apache.tuscany.sca.domain.search.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+
+public class WrappedFileContent implements FileContent {
+
+ final private FileContent fileContent;
+
+ public WrappedFileContent(URL url) throws IOException {
+ String protocol = url.getProtocol();
+
+ if (protocol.equals("jar")) {
+ JarURLConnection jarConn = (JarURLConnection) url.openConnection();
+ //Enumeration<JarEntry> entries = jarConn.getJarFile().entries();
+ String file = url.getFile();
+ file = file.substring(file.lastIndexOf('!') + 1);
+
+// if (file.charAt(file.length() - 1) != '/') {
+//
+// int beginIndex;
+//
+// if (file.charAt(0) == '/') {
+// beginIndex = 1;
+//
+// } else {
+// beginIndex = 0;
+// }
+//
+// file = file.substring(beginIndex);
+//
+// while (entries.hasMoreElements()) {
+// String actualFile = entries.nextElement().getName();
+//
+// if (actualFile.charAt(0) == '/') {
+// beginIndex = 1;
+//
+// } else {
+// beginIndex = 0;
+// }
+//
+// if (actualFile.length() - beginIndex == file.length() + 1 && actualFile.charAt(actualFile.length() - 1) == '/') {
+//
+// if (actualFile.startsWith(file, beginIndex)) {
+// file = actualFile;
+//
+// break;
+//
+// }
+//
+// }
+//
+// }
+//
+// }
+
+ this.fileContent = ZipFileContent.createZipFileContent(jarConn.getJarFile(), file);
+
+ } else if (protocol.equals("file")) {
+ this.fileContent = new SystemFileContent(new File(url.getFile()));
+
+ } else {
+ this.fileContent = new DefaultFileContent(url);
+ }
+
+ }
+
+ public FileContent[] getChildren() {
+ return this.fileContent.getChildren();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return this.fileContent.getInputStream();
+ }
+
+ public String getName() {
+ return this.fileContent.getName();
+ }
+
+ public String getPath() {
+ return this.fileContent.getPath();
+ }
+
+ public boolean isLeaf() {
+ return this.fileContent.isLeaf();
+ }
+
+}