1 17 package org.apache.catalina.util; 18 19 import java.util.Iterator ; 20 import java.util.jar.Manifest ; 21 import java.util.jar.Attributes ; 22 import java.util.ArrayList ; 23 24 33 public class ManifestResource { 34 35 37 public static final int SYSTEM = 1; 39 public static final int WAR = 2; 40 public static final int APPLICATION = 3; 41 42 private ArrayList availableExtensions = null; 43 private ArrayList requiredExtensions = null; 44 45 private String resourceName = null; 46 private int resourceType = -1; 47 48 public ManifestResource(String resourceName, Manifest manifest, 49 int resourceType) { 50 this.resourceName = resourceName; 51 this.resourceType = resourceType; 52 processManifest(manifest); 53 } 54 55 60 public String getResourceName() { 61 return resourceName; 62 } 63 64 69 public ArrayList getAvailableExtensions() { 70 return availableExtensions; 71 } 72 73 78 public ArrayList getRequiredExtensions() { 79 return requiredExtensions; 80 } 81 82 84 89 public int getAvailableExtensionCount() { 90 return (availableExtensions != null) ? availableExtensions.size() : 0; 91 } 92 93 98 public int getRequiredExtensionCount() { 99 return (requiredExtensions != null) ? requiredExtensions.size() : 0; 100 } 101 102 108 public boolean requiresExtensions() { 109 return (requiredExtensions != null) ? true : false; 110 } 111 112 118 public boolean isFulfilled() { 119 if (requiredExtensions == null) { 120 return false; 121 } 122 Iterator it = requiredExtensions.iterator(); 123 while (it.hasNext()) { 124 Extension ext = (Extension)it.next(); 125 if (!ext.isFulfilled()) return false; 126 } 127 return true; 128 } 129 130 public String toString() { 131 132 StringBuffer sb = new StringBuffer ("ManifestResource["); 133 sb.append(resourceName); 134 135 sb.append(", isFulfilled="); 136 sb.append(isFulfilled() +""); 137 sb.append(", requiredExtensionCount ="); 138 sb.append(getRequiredExtensionCount()); 139 sb.append(", availableExtensionCount="); 140 sb.append(getAvailableExtensionCount()); 141 switch (resourceType) { 142 case SYSTEM : sb.append(", resourceType=SYSTEM"); break; 143 case WAR : sb.append(", resourceType=WAR"); break; 144 case APPLICATION : sb.append(", resourceType=APPLICATION"); break; 145 } 146 sb.append("]"); 147 return (sb.toString()); 148 } 149 150 151 153 private void processManifest(Manifest manifest) { 154 availableExtensions = getAvailableExtensions(manifest); 155 requiredExtensions = getRequiredExtensions(manifest); 156 } 157 158 168 private ArrayList getRequiredExtensions(Manifest manifest) { 169 170 Attributes attributes = manifest.getMainAttributes(); 171 String names = attributes.getValue("Extension-List"); 172 if (names == null) 173 return null; 174 175 ArrayList extensionList = new ArrayList (); 176 names += " "; 177 178 while (true) { 179 180 int space = names.indexOf(' '); 181 if (space < 0) 182 break; 183 String name = names.substring(0, space).trim(); 184 names = names.substring(space + 1); 185 186 String value = 187 attributes.getValue(name + "-Extension-Name"); 188 if (value == null) 189 continue; 190 Extension extension = new Extension(); 191 extension.setExtensionName(value); 192 extension.setImplementationURL 193 (attributes.getValue(name + "-Implementation-URL")); 194 extension.setImplementationVendorId 195 (attributes.getValue(name + "-Implementation-Vendor-Id")); 196 String version = attributes.getValue(name + "-Implementation-Version"); 197 extension.setImplementationVersion(version); 198 extension.setSpecificationVersion 199 (attributes.getValue(name + "-Specification-Version")); 200 extensionList.add(extension); 201 } 202 return extensionList; 203 } 204 205 215 private ArrayList getAvailableExtensions(Manifest manifest) { 216 217 Attributes attributes = manifest.getMainAttributes(); 218 String name = attributes.getValue("Extension-Name"); 219 if (name == null) 220 return null; 221 222 ArrayList extensionList = new ArrayList (); 223 224 Extension extension = new Extension(); 225 extension.setExtensionName(name); 226 extension.setImplementationURL( 227 attributes.getValue("Implementation-URL")); 228 extension.setImplementationVendor( 229 attributes.getValue("Implementation-Vendor")); 230 extension.setImplementationVendorId( 231 attributes.getValue("Implementation-Vendor-Id")); 232 extension.setImplementationVersion( 233 attributes.getValue("Implementation-Version")); 234 extension.setSpecificationVersion( 235 attributes.getValue("Specification-Version")); 236 237 extensionList.add(extension); 238 239 return extensionList; 240 } 241 242 } 243 | Popular Tags |