1 23 24 package com.sun.enterprise.deployment.deploy.shared; 25 26 import java.io.File ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.net.URI ; 30 import java.util.Vector ; 31 import java.util.Enumeration ; 32 import java.util.jar.JarFile ; 33 import java.util.jar.Manifest ; 34 import java.util.zip.ZipEntry ; 35 import com.sun.enterprise.util.io.FileUtils; 36 37 44 public class DeploymentPlanArchive extends AbstractArchive { 45 46 JarFile jarFile = null; 48 49 String archiveUri = null; 51 52 Vector elements=null; 54 55 String subArchiveUri=null; 56 57 60 public DeploymentPlanArchive() { 61 } 62 63 67 public void open(String path) throws IOException { 68 archiveUri = path; 69 File f = new File (path); 70 if (f.exists()) { 71 jarFile = new JarFile (f); 72 } 73 } 74 75 79 public long getArchiveSize() throws NullPointerException , SecurityException { 80 if(getArchiveUri() == null) { 81 return -1; 82 } 83 File tmpFile = new File (getArchiveUri()); 84 return(tmpFile.length()); 85 } 86 87 90 public void close() throws java.io.IOException { 91 if (jarFile!=null) { 92 jarFile.close(); 93 jarFile=null; 94 } 95 } 96 97 100 public void closeEntry() throws java.io.IOException { 101 } 103 104 107 public void closeEntry(AbstractArchive sub) throws java.io.IOException { 108 } 110 111 114 public boolean delete() { 115 File f = new File (archiveUri); 116 if (f.exists()) { 117 return FileUtils.deleteFile(f); 118 } 119 return false; 120 } 121 122 125 public Enumeration entries() { 126 128 if (elements==null) { 129 synchronized(this) { 130 elements = new Vector (); 131 for (Enumeration e = jarFile.entries();e.hasMoreElements();) { 132 ZipEntry ze = (ZipEntry ) e.nextElement(); 133 if (!ze.isDirectory() && !ze.getName().equals( 134 JarFile.MANIFEST_NAME)) { 135 elements.add(ze.getName()); 136 } 137 } 138 } 139 } 140 141 Vector entries = new Vector (); 142 for (Enumeration e = elements.elements();e.hasMoreElements();) { 143 144 String entryName = (String ) e.nextElement(); 145 146 String mangledName = entryName; 147 String prefix = "META-INF/"; 148 if (entryName.indexOf("sun-web.xml")!=-1) { 149 prefix = "WEB-INF/"; 150 } 151 if (subArchiveUri != null && entryName.startsWith(subArchiveUri)) { 152 mangledName = mangledName.substring(subArchiveUri.length()+1); 153 } 154 if (entryName.endsWith(".dbschema")) { 155 mangledName = mangledName.replaceAll("#", "/"); 156 } else { 157 mangledName = prefix + mangledName; 158 } 159 160 if (subArchiveUri==null) { 161 if ((entryName.indexOf(".jar.")!=-1) || 163 (entryName.indexOf(".war.")!=-1) || 164 (entryName.indexOf(".rar."))!=-1) { 165 166 continue; 168 } 169 entries.add(mangledName); 170 } else { 171 if (entryName.startsWith(subArchiveUri)) { 173 entries.add(mangledName); 174 } 175 } 176 } 177 return entries.elements(); 178 } 179 180 184 public Enumeration entries(java.util.Enumeration embeddedArchives) { 185 return entries(); 186 } 187 188 191 public boolean exists() { 192 File f = new File (archiveUri); 193 return f.exists(); 194 } 195 196 199 public String getArchiveUri() { 200 return archiveUri; 201 } 202 203 206 public AbstractArchive getEmbeddedArchive(String name) throws java.io.IOException { 207 if (jarFile==null) { 208 return null; 209 } 210 DeploymentPlanArchive dpArchive = new DeploymentPlanArchive(); 211 dpArchive.jarFile = new JarFile (archiveUri); 212 dpArchive.archiveUri = archiveUri + File.separator + name; 213 dpArchive.subArchiveUri = name; 214 dpArchive.elements = elements; 215 return dpArchive; 216 } 217 218 221 public InputStream getEntry(String name) throws IOException { 222 223 if (name.endsWith(".dbschema")) { 226 name = name.replaceAll("/", "#"); 227 } else { 228 name = name.substring(name.lastIndexOf('/')+1); 229 } 230 231 if (subArchiveUri==null) { 232 234 return getElement(name); 235 } else { 236 String mangledName = subArchiveUri + "." + 239 name; 240 return getElement(mangledName); 241 242 } 243 } 244 245 private InputStream getElement(String name) throws IOException { 246 if (elements.contains(name)) { 247 return jarFile.getInputStream(jarFile.getEntry(name)); 248 } else { 249 return null; 250 } 251 } 252 253 256 public java.util.jar.Manifest getManifest() throws java.io.IOException { 257 return new Manifest (); 259 } 260 261 264 public java.net.URI getURI() { 265 File f = new File (archiveUri); 266 try { 267 return new URI ("jar://" + f.toURI().getSchemeSpecificPart()); 268 } catch(java.net.URISyntaxException e) { 269 return null; 270 } 271 } 272 273 276 public java.io.OutputStream putNextEntry(String name) throws java.io.IOException { 277 throw new UnsupportedOperationException (); 279 } 280 281 284 public boolean renameTo(String name) { 285 File f = new File (archiveUri); 286 boolean result = FileUtils.renameFile(f, new File (name)); 287 if (result) { 288 archiveUri = name; 289 } 290 return result; 291 292 } 293 294 } 295 | Popular Tags |