001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.vfs;
031:
032: import com.caucho.loader.EnvironmentLocal;
033: import com.caucho.make.CachedDependency;
034: import com.caucho.util.Alarm;
035: import com.caucho.util.CacheListener;
036: import com.caucho.util.Log;
037: import com.caucho.util.LruCache;
038: import com.caucho.util.L10N;
039:
040: import java.io.FileNotFoundException;
041: import java.io.IOException;
042: import java.io.InputStream;
043: import java.lang.ref.SoftReference;
044: import java.security.cert.Certificate;
045: import java.util.*;
046: import java.util.jar.JarEntry;
047: import java.util.jar.JarFile;
048: import java.util.jar.Manifest;
049: import java.util.logging.Level;
050: import java.util.logging.Logger;
051: import java.util.zip.ZipEntry;
052: import java.util.zip.ZipFile;
053: import java.util.zip.ZipInputStream;
054:
055: /**
056: * Maps Jar entries to the Jar
057: */
058: public class JarCache {
059: private static final Logger log = Logger.getLogger(JarCache.class
060: .getName());
061: private static final L10N L = new L10N(JarCache.class);
062:
063: private final HashMap<String, JarNode> _map = new HashMap<String, JarNode>();
064: private final JarNode _root;
065:
066: private Boolean _isSigned;
067:
068: JarCache() {
069: _root = new JarNode("", "");
070: _map.put("/", _root);
071: }
072:
073: JarNode get(String name) {
074: JarNode node = _map.get(name);
075:
076: if (node != null)
077: return node;
078:
079: if (name.endsWith("/"))
080: name = name.substring(0, name.length() - 1);
081:
082: return _map.get(name);
083: }
084:
085: void add(ZipEntry entry) {
086: String name = entry.getName();
087:
088: JarNode node = addNode(name);
089:
090: node.fill(entry);
091:
092: if (node.isDirectory())
093: _map.put(name + "/", node);
094: }
095:
096: Boolean isSigned() {
097: return _isSigned;
098: }
099:
100: void setSigned(Boolean isSigned) {
101: _isSigned = isSigned;
102: }
103:
104: private JarNode addNode(String childName) {
105: if (childName.endsWith("/"))
106: childName = childName.substring(0, childName.length() - 1);
107:
108: String mapName = childName;
109:
110: if (!mapName.startsWith("/"))
111: mapName = "/" + mapName;
112:
113: JarNode node = _map.get(mapName);
114:
115: if (node != null)
116: return node;
117:
118: JarNode parent;
119: int len = childName.length();
120: int p = childName.lastIndexOf('/', len - 1);
121:
122: if (p < 0) {
123: parent = _root;
124:
125: node = new JarNode(mapName, childName);
126: } else {
127: String parentName = childName.substring(0, p + 1);
128: parent = addNode(parentName);
129:
130: node = new JarNode(childName, childName.substring(p + 1));
131: }
132:
133: _map.put(mapName, node);
134:
135: parent.addChild(node);
136:
137: return node;
138: }
139: }
|