01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
11:
12: import java.io.File;
13: import java.io.InputStream;
14: import java.util.zip.ZipEntry;
15: import java.util.zip.ZipFile;
16:
17: import org.eclipse.core.resources.IStorage;
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.core.runtime.IPath;
20: import org.eclipse.core.runtime.IStatus;
21: import org.eclipse.core.runtime.Path;
22: import org.eclipse.core.runtime.PlatformObject;
23: import org.eclipse.core.runtime.Status;
24: import org.eclipse.pde.internal.ui.IPDEUIConstants;
25:
26: public class JarEntryFile extends PlatformObject implements IStorage {
27:
28: private ZipFile fZipFile;
29: private String fEntryName;
30:
31: public JarEntryFile(ZipFile zipFile, String entryName) {
32: fZipFile = zipFile;
33: fEntryName = entryName;
34: }
35:
36: /* (non-Javadoc)
37: * @see org.eclipse.core.resources.IStorage#getContents()
38: */
39: public InputStream getContents() throws CoreException {
40: try {
41: ZipEntry zipEntry = fZipFile.getEntry(fEntryName);
42: return fZipFile.getInputStream(zipEntry);
43: } catch (Exception e) {
44: throw new CoreException(new Status(IStatus.ERROR,
45: IPDEUIConstants.PLUGIN_ID, IStatus.ERROR, e
46: .getMessage(), e));
47: }
48: }
49:
50: /* (non-Javadoc)
51: * @see org.eclipse.core.resources.IStorage#getFullPath()
52: */
53: public IPath getFullPath() {
54: return new Path(fEntryName);
55: }
56:
57: /* (non-Javadoc)
58: * @see org.eclipse.core.resources.IStorage#getName()
59: */
60: public String getName() {
61: return getFullPath().lastSegment();
62: }
63:
64: /* (non-Javadoc)
65: * @see org.eclipse.core.resources.IStorage#isReadOnly()
66: */
67: public boolean isReadOnly() {
68: return true;
69: }
70:
71: /* (non-Javadoc)
72: * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
73: */
74: public Object getAdapter(Class adapter) {
75: if (adapter.equals(ZipFile.class))
76: return fZipFile;
77: if (adapter.equals(File.class))
78: return new File(fZipFile.getName());
79: return super .getAdapter(adapter);
80: }
81:
82: public String toString() {
83: return "JarEntryFile[" + fZipFile.getName() + "::" + fEntryName + "]"; //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
84: }
85:
86: public boolean equals(Object obj) {
87: if (!(obj instanceof JarEntryFile))
88: return false;
89: return toString().equals(obj.toString());
90: }
91:
92: }
|