diff options
author | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-17 06:24:15 +0000 |
---|---|---|
committer | adrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-17 06:24:15 +0000 |
commit | 53c043ac18ca8dd9d7f823bf7a399058c305003d (patch) | |
tree | 5b8184792065accca1e5a68092d0960db455cda6 /branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java | |
parent | a4f020f2df42181bf54587acddb3b748ff5f698f (diff) |
committing domain-search changes from patch tuscany_2552_phillipe_ramalho_08_16_2009.patch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@804871 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/ZipFileContent.java | 407 |
1 files changed, 201 insertions, 206 deletions
diff --git a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java index dff258ec4e..15f9bb6feb 100644 --- a/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java +++ b/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java @@ -31,296 +31,291 @@ import java.util.zip.ZipFile; */ public class ZipFileContent implements FileContent { - final private ZipFile file; + final private ZipFile file; - final private ZipEntry entry; + final private ZipEntry entry; - private FileContent[] children; + private FileContent[] children; - private ZipFileContent(ZipFile file, ZipEntry entry) { - this.file = file; - this.entry = entry; + private ZipFileContent(ZipFile file, ZipEntry entry) { + this.file = file; + this.entry = entry; - } + } - public InputStream getInputStream() throws IOException { - return this.file.getInputStream(this.entry); - } + public InputStream getInputStream() throws IOException { + return this.file.getInputStream(this.entry); + } - public String getPath() { - return this.file.getName() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' - + this.entry.getName(); - } + public String getPath() { + return this.file.getName() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' + this.entry.getName(); + } - public FileContent[] getChildren() { - return this.children; - } + public FileContent[] getChildren() { + return this.children; + } - public String getName() { - return this.entry.getName(); -// int lastSlashIndex = name.lastIndexOf('/'); -// -// if (lastSlashIndex == -1) { -// return name; -// } -// -// if (lastSlashIndex == name.length() - 1 && name.length() > 1) { -// lastSlashIndex = name.lastIndexOf('/', name.length() - 2); -// -// if (lastSlashIndex == -1) { -// return name.substring(0, name.length() - 1); -// } -// -// return name.substring(lastSlashIndex + 1, name.length() - 1); -// -// } -// -// return name.substring(lastSlashIndex + 1); + public String getName() { + return this.entry.getName(); + // int lastSlashIndex = name.lastIndexOf('/'); + // + // if (lastSlashIndex == -1) { + // return name; + // } + // + // if (lastSlashIndex == name.length() - 1 && name.length() > 1) { + // lastSlashIndex = name.lastIndexOf('/', name.length() - 2); + // + // if (lastSlashIndex == -1) { + // return name.substring(0, name.length() - 1); + // } + // + // return name.substring(lastSlashIndex + 1, name.length() - 1); + // + // } + // + // return name.substring(lastSlashIndex + 1); - } + } - public boolean isLeaf() { - return !this.entry.isDirectory(); - } + public boolean isLeaf() { + return !this.entry.isDirectory(); + } - public static ZipFileContent[] createZipFileContent(ZipFile file) { - Enumeration<? extends ZipEntry> entries = file.entries(); + public static ZipFileContent[] createZipFileContent(ZipFile file) { + Enumeration<? extends ZipEntry> entries = file.entries(); - if (!entries.hasMoreElements()) { - return null; - } + if (!entries.hasMoreElements()) { + return null; + } - HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>(); + HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>(); - do { - ZipEntry entry = entries.nextElement(); - String name = entry.getName(); + do { + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); - if (name.length() > 0) { + if (name.length() > 0) { - String[] path = name.split("/"); + String[] path = name.split("/"); - ZipMap current = roots.get(path[0]); + ZipMap current = roots.get(path[0]); - if (current == null) { - current = new ZipMap(); - roots.put(path[0], current); + if (current == null) { + current = new ZipMap(); + roots.put(path[0], current); - if (path.length == 1) { - current.setEntry(file, entry); - continue; + if (path.length == 1) { + current.setEntry(file, entry); + continue; - } + } - } + } - for (int i = 1; i < path.length - 1; i++) { - ZipMap actual = current.get(path[i]); + for (int i = 1; i < path.length - 1; i++) { + ZipMap actual = current.get(path[i]); - if (actual == null) { - actual = new ZipMap(); - current.put(path[i], actual); + if (actual == null) { + actual = new ZipMap(); + current.put(path[i], actual); - } + } - current = actual; + current = actual; - } + } - ZipMap entryMap = current.get(path[path.length - 1]); + ZipMap entryMap = current.get(path[path.length - 1]); - if (entryMap == null) { - entryMap = new ZipMap(); - current.put(path[path.length - 1], entryMap); + if (entryMap == null) { + entryMap = new ZipMap(); + current.put(path[path.length - 1], entryMap); - } + } - entryMap.setEntry(file, entry); + entryMap.setEntry(file, entry); - } + } - } while (entries.hasMoreElements()); + } while (entries.hasMoreElements()); - for (ZipMap map : roots.values()) { - createZipFileContentChildren(map); - } + for (ZipMap map : roots.values()) { + createZipFileContentChildren(map); + } - ZipFileContent[] ret = new ZipFileContent[roots.size()]; - int i = 0; + ZipFileContent[] ret = new ZipFileContent[roots.size()]; + int i = 0; - for (ZipMap rootMap : roots.values()) { - ret[i++] = rootMap.zipContent; - } + for (ZipMap rootMap : roots.values()) { + ret[i++] = rootMap.zipContent; + } - return ret; + return ret; - } + } - public static ZipFileContent createZipFileContent(ZipFile file, - String filePath) { + public static ZipFileContent createZipFileContent(ZipFile file, String filePath) { - Enumeration<? extends ZipEntry> entries = file.entries(); + Enumeration<? extends ZipEntry> entries = file.entries(); - if (!entries.hasMoreElements()) { - return null; - } + if (!entries.hasMoreElements()) { + return null; + } - int beginIndex; - int endIndex; + int beginIndex; + int endIndex; - if (filePath.charAt(0) == '/') { - beginIndex = 1; + if (filePath.charAt(0) == '/') { + beginIndex = 1; - } else { - beginIndex = 0; - } + } else { + beginIndex = 0; + } - ZipMap root = new ZipMap(); - - if (filePath.length() > 1 - && filePath.charAt(filePath.length() - 1) == '/') { - endIndex = filePath.length() - 1; + ZipMap root = new ZipMap(); - } else { - endIndex = filePath.length(); - } + if (filePath.length() > 1 && filePath.charAt(filePath.length() - 1) == '/') { + endIndex = filePath.length() - 1; - filePath = filePath.substring(beginIndex, endIndex); - // HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>(); + } else { + endIndex = filePath.length(); + } - do { - ZipEntry entry = entries.nextElement(); - String name = entry.getName(); + filePath = filePath.substring(beginIndex, endIndex); + // HashMap<String, ZipMap> roots = new HashMap<String, ZipMap>(); - if (name.length() > 0) { - - if (name.charAt(name.length() - 1) == '/') { - endIndex = 1; - - } else { - endIndex = 0; - } - - if (name.length() - endIndex == filePath.length()) { - root.setEntry(file, entry); - - } else if (filePath.length() == 0 || (name.startsWith(filePath) && name.charAt(filePath.length()) == '/')) { - - name = name.substring(filePath.length()); - String[] path = name.split("/"); + do { + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); - ZipMap current = root; + if (name.length() > 0) { - // if (current == null) { - // current = new ZipMap(); - // roots.put(path[0], current); - // - // if (path.length == 1) { - // current.setEntry(file, entry); - // continue; - // - // } - // - // } + if (name.charAt(name.length() - 1) == '/') { + endIndex = 1; - if (path.length > 0) { + } else { + endIndex = 0; + } - int i; - - if (path[0].length() == 0) { - i = 1; - - } else { - i = 0; - } - - for (; i < path.length - 1; i++) { - ZipMap actual = current.get(path[i]); + if (name.length() - endIndex == filePath.length()) { + root.setEntry(file, entry); - if (actual == null) { - actual = new ZipMap(); - current.put(path[i], actual); + } else if (filePath.length() == 0 || (name.startsWith(filePath) && name.charAt(filePath.length()) == '/')) { - } + name = name.substring(filePath.length()); + String[] path = name.split("/"); - current = actual; + ZipMap current = root; - } + // if (current == null) { + // current = new ZipMap(); + // roots.put(path[0], current); + // + // if (path.length == 1) { + // current.setEntry(file, entry); + // continue; + // + // } + // + // } - ZipMap entryMap = current.get(path[path.length - 1]); + if (path.length > 0) { - if (entryMap == null) { - entryMap = new ZipMap(); - current.put(path[path.length - 1], entryMap); + int i; - } - - entryMap.setEntry(file, entry); + if (path[0].length() == 0) { + i = 1; - } + } else { + i = 0; + } - } + for (; i < path.length - 1; i++) { + ZipMap actual = current.get(path[i]); - } + if (actual == null) { + actual = new ZipMap(); + current.put(path[i], actual); - } while (entries.hasMoreElements()); + } - createZipFileContentChildren(root); + current = actual; - return root.zipContent; + } - } + ZipMap entryMap = current.get(path[path.length - 1]); - private static void createZipFileContentChildren(ZipMap map) { - ZipFileContent[] children = new ZipFileContent[map.size()]; - int i = 0; + if (entryMap == null) { + entryMap = new ZipMap(); + current.put(path[path.length - 1], entryMap); - for (ZipMap childMap : map.values()) { + } - if (childMap.zipContent == null) { - throw new RuntimeException( - "could not load zip file hierarchy for file: " - + map.zipContent.file); - } + entryMap.setEntry(file, entry); - children[i++] = childMap.zipContent; + } - createZipFileContentChildren(childMap); + } - } + } - map.zipContent.children = children; + } while (entries.hasMoreElements()); - } + createZipFileContentChildren(root); - @Override - public String toString() { - return this.file.getName() + '/' + this.entry.getName(); - } + return root.zipContent; - private static class ZipMap extends HashMap<String, ZipMap> { + } - private static final long serialVersionUID = 6514645087432837480L; + private static void createZipFileContentChildren(ZipMap map) { + ZipFileContent[] children = new ZipFileContent[map.size()]; + int i = 0; - ZipFileContent zipContent; + for (ZipMap childMap : map.values()) { - void setEntry(ZipFile zipFile, ZipEntry entry) { - this.zipContent = new ZipFileContent(zipFile, entry); - } + if (childMap.zipContent == null) { + throw new RuntimeException("could not load zip file hierarchy for file: " + map.zipContent.file); + } - ZipFileContent[] getChildren() { + children[i++] = childMap.zipContent; - ZipFileContent ret[] = new ZipFileContent[this.size()]; - int i = 0; + createZipFileContentChildren(childMap); - for (ZipMap actual : this.values()) { - ret[i++] = actual.zipContent; - } + } - return ret; + map.zipContent.children = children; - } + } - } + @Override + public String toString() { + return this.file.getName() + '/' + this.entry.getName(); + } + + private static class ZipMap extends HashMap<String, ZipMap> { + + private static final long serialVersionUID = 6514645087432837480L; + + ZipFileContent zipContent; + + void setEntry(ZipFile zipFile, ZipEntry entry) { + this.zipContent = new ZipFileContent(zipFile, entry); + } + + ZipFileContent[] getChildren() { + + ZipFileContent ret[] = new ZipFileContent[this.size()]; + int i = 0; + + for (ZipMap actual : this.values()) { + ret[i++] = actual.zipContent; + } + + return ret; + + } + + } } |