1 11 12 package org.eclipse.osgi.baseadaptor.bundlefile; 13 14 import java.io.*; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.security.AccessController ; 18 import java.util.*; 19 import org.eclipse.osgi.framework.internal.core.Constants; 20 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 21 import org.eclipse.osgi.framework.internal.protocol.bundleresource.Handler; 22 import org.eclipse.osgi.framework.util.SecureAction; 23 import org.eclipse.osgi.util.ManifestElement; 24 25 33 abstract public class BundleFile { 34 protected static final String PROP_SETPERMS_CMD = "osgi.filepermissions.command"; static final SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); 36 39 protected File basefile; 40 private int mruIndex = -1; 41 42 46 public BundleFile() { 47 } 49 50 55 public BundleFile(File basefile) { 56 this.basefile = basefile; 57 } 58 59 67 abstract public File getFile(String path, boolean nativeCode); 68 69 76 abstract public BundleEntry getEntry(String path); 77 78 92 abstract public Enumeration getEntryPaths(String path); 93 94 98 abstract public void close() throws IOException; 99 100 104 abstract public void open() throws IOException; 105 106 112 abstract public boolean containsDir(String dir); 113 114 120 public URL getResourceURL(String path, long hostBundleID) { 121 return getResourceURL(path, hostBundleID, 0); 122 } 123 124 131 public URL getResourceURL(String path, long hostBundleID, int index) { 132 BundleEntry bundleEntry = getEntry(path); 133 if (bundleEntry == null) 134 return null; 135 if (path.length() == 0 || path.charAt(0) != '/') 136 path = '/' + path; 137 try { 138 return secureAction.getURL(Constants.OSGI_RESOURCE_URL_PROTOCOL, Long.toString(hostBundleID), index, path, new Handler(bundleEntry)); 140 } catch (MalformedURLException e) { 141 return null; 142 } 143 } 144 145 149 public File getBaseFile() { 150 return basefile; 151 } 152 153 void setMruIndex(int index) { 154 mruIndex = index; 155 } 156 157 int getMruIndex() { 158 return mruIndex; 159 } 160 161 165 public static void setPermissions(File file) { 166 String commandProp = FrameworkProperties.getProperty(PROP_SETPERMS_CMD); 167 if (commandProp == null) 168 return; 169 String [] temp = ManifestElement.getArrayFromList(commandProp, " "); ArrayList command = new ArrayList(temp.length + 1); 171 boolean foundFullPath = false; 172 for (int i = 0; i < temp.length; i++) { 173 if ("[fullpath]".equals(temp[i])) { command.add(file.getAbsolutePath()); 175 foundFullPath = true; 176 } 177 else 178 command.add(temp[i]); 179 } 180 if (!foundFullPath) 181 command.add(file.getAbsolutePath()); 182 try { 183 Runtime.getRuntime().exec((String []) command.toArray(new String [command.size()])).waitFor(); 184 } catch (Exception e) { 185 e.printStackTrace(); 186 } 187 } 188 189 public String toString() { 190 return String.valueOf(basefile); 191 } 192 } 193 | Popular Tags |