You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2009/08/17 08:24:17 UTC
svn commit: r804871 [3/3] - in
/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search:
./ impl/
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ResultProcessorList.java Mon Aug 17 06:24:15 2009
@@ -30,158 +30,157 @@
*
* @version $Rev$ $Date$
*/
-public class ResultProcessorList extends LinkedList<ResultProcessor> implements
- ResultProcessor {
+public class ResultProcessorList extends LinkedList<ResultProcessor> implements ResultProcessor {
- private static final long serialVersionUID = 7147307292452694895L;
- private HashMap<String, ResultHashMap> resultRoots = new HashMap<String, ResultHashMap>();
+ private static final long serialVersionUID = 7147307292452694895L;
- private ResultFactory<? extends Result> resultFactory;
-
- public ResultProcessorList(ResultFactory<? extends Result> resultFactory) {
- this.resultFactory = resultFactory;
- }
+ private HashMap<String, ResultHashMap> resultRoots = new HashMap<String, ResultHashMap>();
- public Result process(Document document, Result result) {
+ private ResultFactory<? extends Result> resultFactory;
- if (result == null) {
- result = this.resultFactory.createResult(document);
-
- if (result == null) {
- return null;
- }
-
- }
+ public ResultProcessorList(ResultFactory<? extends Result> resultFactory) {
+ this.resultFactory = resultFactory;
+ }
- ResultHashMap resultHashMap;
+ public Result process(Document document, Result result) {
- String parent = document.get(SearchFields.PARENT_FIELD);
+ if (result == null) {
+ result = this.resultFactory.createResult(document);
- if (parent == null) {
- resultHashMap = new ResultHashMap(result);
- resultRoots.put(result.getValue(), resultHashMap);
+ if (result == null) {
+ return null;
+ }
- } else {
+ }
- ParentField parentField = new ParentField(parent);
- HashMap<String, ResultHashMap> current = this.resultRoots;
- //Result currentResult = null;
- int elementsCount = parentField.getElementsCount();
+ ResultHashMap resultHashMap;
- for (int i = 0; i < elementsCount; i++) {
- String actualName = parentField.getElementName(i);
- String type = parentField.getElementType(i);
+ String parent = document.get(SearchFields.PARENT_FIELD);
- if (actualName.length() > 0) {
- ResultHashMap actualResultHashMap = current.get(actualName);
+ if (parent == null) {
+ resultHashMap = new ResultHashMap(result);
+ resultRoots.put(result.getValue(), resultHashMap);
- if (actualResultHashMap == null) {
- ResultHashMap aux = new ResultHashMap(type, parentField
- .getElementName(i));
+ } else {
- current.put(aux.result.getValue(), aux);
-// if (current.put(aux.result.getValue(), aux) == null
-// && currentResult != null) {
-// currentResult.addContent(aux.result);
-// }
+ ParentField parentField = new ParentField(parent);
+ HashMap<String, ResultHashMap> current = this.resultRoots;
+ // Result currentResult = null;
+ int elementsCount = parentField.getElementsCount();
- current = aux;
- //currentResult = aux.result;
+ for (int i = 0; i < elementsCount; i++) {
+ String actualName = parentField.getElementName(i);
+ String type = parentField.getElementType(i);
- } else {
- current = actualResultHashMap;
- //currentResult = actualResultHashMap.result;
+ if (actualName.length() > 0) {
+ ResultHashMap actualResultHashMap = current.get(actualName);
- }
+ if (actualResultHashMap == null) {
+ ResultHashMap aux = new ResultHashMap(type, parentField.getElementName(i));
- }
+ current.put(aux.result.getValue(), aux);
+ // if (current.put(aux.result.getValue(), aux) == null
+ // && currentResult != null) {
+ // currentResult.addContent(aux.result);
+ // }
- }
+ current = aux;
+ // currentResult = aux.result;
- resultHashMap = current.get(result.getValue());
+ } else {
+ current = actualResultHashMap;
+ // currentResult = actualResultHashMap.result;
- if (resultHashMap == null) {
- resultHashMap = new ResultHashMap(result);
- current.put(result.getValue(), resultHashMap);
+ }
-// if (currentResult != null) {
-// currentResult.addContent(result);
-// }
+ }
- }
+ }
- }
+ resultHashMap = current.get(result.getValue());
- for (ResultProcessor processor : this) {
- result = processor.process(document, result);
- }
+ if (resultHashMap == null) {
+ resultHashMap = new ResultHashMap(result);
+ current.put(result.getValue(), resultHashMap);
- resultHashMap.result = result;
+ // if (currentResult != null) {
+ // currentResult.addContent(result);
+ // }
- return result;
+ }
- }
-
- private static void addContentsToResult(ResultHashMap resultHashMap) {
-
- for (ResultHashMap actual : resultHashMap.values()) {
- addContentsToResult(actual);
-
- resultHashMap.result.addContent(actual.result);
-
- }
-
- }
+ }
- public Result[] createResultRoots() {
- int size = this.resultRoots.size();
+ for (ResultProcessor processor : this) {
+ result = processor.process(document, result);
+ }
- if (size == 0) {
- return new Result[0];
- }
+ resultHashMap.result = result;
- Result[] res = new Result[size];
+ return result;
- int i = 0;
- for (ResultHashMap resultHashMap : this.resultRoots.values()) {
-
- addContentsToResult(resultHashMap);
- res[i++] = resultHashMap.result;
-
- }
-
- this.resultRoots.clear();
+ }
- return res;
+ private static void addContentsToResult(ResultHashMap resultHashMap) {
- }
+ for (ResultHashMap actual : resultHashMap.values()) {
+ addContentsToResult(actual);
- private Result createResult(String field, String value) {
- Result result = this.resultFactory.createResult(field, value);
-
- if (result != null) {
- return result;
- }
+ resultHashMap.result.addContent(actual.result);
- throw new IllegalArgumentException();
+ }
- }
+ }
- private class ResultHashMap extends HashMap<String, ResultHashMap> {
+ public Result[] createResultRoots() {
+ int size = this.resultRoots.size();
- private static final long serialVersionUID = 7982561264440904411L;
+ if (size == 0) {
+ return new Result[0];
+ }
- Result result;
+ Result[] res = new Result[size];
- ResultHashMap(String type, String name) {
- this(createResult(type, name));
- }
+ int i = 0;
+ for (ResultHashMap resultHashMap : this.resultRoots.values()) {
- ResultHashMap(Result result) {
- this.result = result;
- }
+ addContentsToResult(resultHashMap);
+ res[i++] = resultHashMap.result;
- }
+ }
+
+ this.resultRoots.clear();
+
+ return res;
+
+ }
+
+ private Result createResult(String field, String value) {
+ Result result = this.resultFactory.createResult(field, value);
+
+ if (result != null) {
+ return result;
+ }
+
+ throw new IllegalArgumentException();
+
+ }
+
+ private class ResultHashMap extends HashMap<String, ResultHashMap> {
+
+ private static final long serialVersionUID = 7982561264440904411L;
+
+ Result result;
+
+ ResultHashMap(String type, String name) {
+ this(createResult(type, name));
+ }
+
+ ResultHashMap(Result result) {
+ this.result = result;
+ }
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SearchFields.java Mon Aug 17 06:24:15 2009
@@ -24,50 +24,50 @@
*/
public interface SearchFields {
- final public static String ARTIFACT_FIELD = "artifact";
-
- final public static String COMPONENT_TYPE_FIELD = "componenttype";
-
- final public static String REFERENCE_FIELD = "reference";
-
- final public static String COMPOSITE_FIELD = "composite";
-
- final public static String SERVICE_FIELD = "service";
-
- final public static String BINDING_FIELD = "binding";
-
- final public static String CONTRIBUTION_FIELD = "contribution";
-
- final public static String COMPONENT_FIELD = "component";
-
- final public static String TYPE_FIELD = "type";
-
- final public static String PARENT_FIELD = "parent";
-
- final public static String IMPLEMENTS_FIELD = "implements";
-
- final public static String SERVICE_NAME_FIELD = "servicename";
-
- final public static String SERVICE_INTERFACE_FIELD = "serviceinterface";
-
- final public static String SERVICE_INTERFACE_CALLBACK_FIELD = "serviceinterfacecallback";
-
- final public static String REFERENCE_NAME_FIELD = "referencename";
-
- final public static String REFERENCE_INTERFACE_FIELD = "referenceinterface";
-
- final public static String REFERENCE_INTERFACE_CALLBACK_FIELD = "referenceinterfacecallback";
-
- final public static String IMPORTEDBY_FIELD = "importedby";
-
- final public static String EXPORTEDBY_FIELD = "exportedby";
-
- final public static String INCLUDEDBY_FIELD = "includedby";
-
- final public static String PROPERTY_KEY_FIELD = "propertykey";
-
- final public static String VALUE_FIELD = "propertyvalue";
-
- final public static String FILE_CONTENT_FIELD = "filecontent";
+ final public static String ARTIFACT_FIELD = "artifact";
+
+ final public static String COMPONENT_TYPE_FIELD = "componenttype";
+
+ final public static String REFERENCE_FIELD = "reference";
+
+ final public static String COMPOSITE_FIELD = "composite";
+
+ final public static String SERVICE_FIELD = "service";
+
+ final public static String BINDING_FIELD = "binding";
+
+ final public static String CONTRIBUTION_FIELD = "contribution";
+
+ final public static String COMPONENT_FIELD = "component";
+
+ final public static String TYPE_FIELD = "type";
+
+ final public static String PARENT_FIELD = "parent";
+
+ final public static String IMPLEMENTS_FIELD = "implements";
+
+ final public static String SERVICE_NAME_FIELD = "servicename";
+
+ final public static String SERVICE_INTERFACE_FIELD = "serviceinterface";
+
+ final public static String SERVICE_INTERFACE_CALLBACK_FIELD = "serviceinterfacecallback";
+
+ final public static String REFERENCE_NAME_FIELD = "referencename";
+
+ final public static String REFERENCE_INTERFACE_FIELD = "referenceinterface";
+
+ final public static String REFERENCE_INTERFACE_CALLBACK_FIELD = "referenceinterfacecallback";
+
+ final public static String IMPORTEDBY_FIELD = "importedby";
+
+ final public static String EXPORTEDBY_FIELD = "exportedby";
+
+ final public static String INCLUDEDBY_FIELD = "includedby";
+
+ final public static String PROPERTY_KEY_FIELD = "propertykey";
+
+ final public static String VALUE_FIELD = "propertyvalue";
+
+ final public static String FILE_CONTENT_FIELD = "filecontent";
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/SystemFileContent.java Mon Aug 17 06:24:15 2009
@@ -29,48 +29,48 @@
*/
public class SystemFileContent implements FileContent {
- private static final long serialVersionUID = -8337926886777467728L;
+ private static final long serialVersionUID = -8337926886777467728L;
- final boolean leaf;
-
- final private File file;
-
- public SystemFileContent(File file) {
- this.leaf = !file.isDirectory();
- this.file = file;
-
- }
-
- public File getFile() {
- return this.file;
- }
-
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- public FileContent[] getChildren() {
- File[] files = this.file.listFiles();
- FileContent[] ret = new FileContent[files.length];
-
- for (int i = 0; i < files.length; i++) {
- ret[i] = new SystemFileContent(files[i]);
- }
-
- return ret;
-
- }
-
- public boolean isLeaf() {
- return this.leaf;
- }
-
- public String getName() {
- return this.file.getName();
- }
-
- public String getPath() {
- return this.file.getPath();
- }
+ final boolean leaf;
+
+ final private File file;
+
+ public SystemFileContent(File file) {
+ this.leaf = !file.isDirectory();
+ this.file = file;
+
+ }
+
+ public File getFile() {
+ return this.file;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return new FileInputStream(this.file);
+ }
+
+ public FileContent[] getChildren() {
+ File[] files = this.file.listFiles();
+ FileContent[] ret = new FileContent[files.length];
+
+ for (int i = 0; i < files.length; i++) {
+ ret[i] = new SystemFileContent(files[i]);
+ }
+
+ return ret;
+
+ }
+
+ public boolean isLeaf() {
+ return this.leaf;
+ }
+
+ public String getName() {
+ return this.file.getName();
+ }
+
+ public String getPath() {
+ return this.file.getPath();
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/WrappedFileContent.java Mon Aug 17 06:24:15 2009
@@ -30,84 +30,85 @@
*/
public class WrappedFileContent implements FileContent {
- final private FileContent fileContent;
+ final private FileContent fileContent;
- public WrappedFileContent(URL url) throws IOException {
- String protocol = url.getProtocol();
+ 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();
- }
+ 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();
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipDocumentProcessor.java Mon Aug 17 06:24:15 2009
@@ -31,66 +31,73 @@
* @version $Rev$ $Date$
*/
public class ZipDocumentProcessor implements DocumentProcessor {
-
- public Object getDocumentKey(Object object) {
- if (object instanceof File) {
- File file = (File) object;
- String path = file.getPath();
-
- if (path != null && path.length() == 0) {
- return null;
- }
-
- return path;
-
- }
-
- throw new IllegalArgumentException();
-
- }
-
- public Document process(DocumentProcessor parentProcessor,
- DocumentMap documents, Object object, Document document,
- String parent) {
-
- if (object instanceof SystemFileContent) {
- SystemFileContent file = (SystemFileContent) object;
-
- try {
- ZipFile zip = new ZipFile(file.getFile());
-
- if (document == null) {
- document = documents.get(file.getPath());
- }
-
- parent += DomainPathAnalyzer.PATH_SEPARATOR
- + SearchFields.ARTIFACT_FIELD
- + DomainPathAnalyzer.TYPE_SEPARATOR + "jar:file:" + file.getPath() + DomainPathAnalyzer.ARCHIVE_SEPARATOR + '/' + file.getName()
- + DomainPathAnalyzer.URI_SEPARATOR + file.getName();
-
- document.add(new Field(SearchFields.ARTIFACT_FIELD, file.getName(), Field.Store.YES,
- Field.Index.ANALYZED));
-
- ZipFileContent[] zipFiles = ZipFileContent.createZipFileContent(zip);
-
- for (ZipFileContent zipFile : zipFiles) {
-
- parentProcessor.process(parentProcessor, documents,
- zipFile, document, parent);
-
- }
-
- return document;
-
- } catch (IOException e) {
- // ignore file
- }
-
- }
-
- return null;
+ public Object getDocumentKey(Object object) {
- }
+ if (object instanceof File) {
+ File file = (File)object;
+ String path = file.getPath();
+
+ if (path != null && path.length() == 0) {
+ return null;
+ }
+
+ return path;
+
+ }
+
+ throw new IllegalArgumentException();
+
+ }
+
+ public Document process(DocumentProcessor parentProcessor,
+ DocumentMap documents,
+ Object object,
+ Document document,
+ String parent) {
+
+ if (object instanceof SystemFileContent) {
+ SystemFileContent file = (SystemFileContent)object;
+
+ try {
+ ZipFile zip = new ZipFile(file.getFile());
+
+ if (document == null) {
+ document = documents.get(file.getPath());
+ }
+
+ parent +=
+ DomainPathAnalyzer.PATH_SEPARATOR + SearchFields.ARTIFACT_FIELD
+ + DomainPathAnalyzer.TYPE_SEPARATOR
+ + "jar:file:"
+ + file.getPath()
+ + DomainPathAnalyzer.ARCHIVE_SEPARATOR
+ + '/'
+ + file.getName()
+ + DomainPathAnalyzer.URI_SEPARATOR
+ + file.getName();
+
+ document.add(new Field(SearchFields.ARTIFACT_FIELD, file.getName(), Field.Store.YES,
+ Field.Index.ANALYZED));
+
+ ZipFileContent[] zipFiles = ZipFileContent.createZipFileContent(zip);
+
+ for (ZipFileContent zipFile : zipFiles) {
+
+ parentProcessor.process(parentProcessor, documents, zipFile, document, parent);
+
+ }
+
+ return document;
+
+ } catch (IOException e) {
+ // ignore file
+ }
+
+ }
+
+ return null;
+
+ }
}
Modified: tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java?rev=804871&r1=804870&r2=804871&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java (original)
+++ tuscany/branches/sca-java-1.x/modules/domain-search/src/main/java/org/apache/tuscany/sca/domain/search/impl/ZipFileContent.java Mon Aug 17 06:24:15 2009
@@ -31,296 +31,291 @@
*/
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;
+
+ }
+
+ }
}