import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.servlet.ServletContext;
public class manifestReader {
public static Hashtable<String, String> getManifest(String path, ServletContext context){
Hashtable<String, String> ret = new Hashtable<String, String>();
try {
URL jarURL = context.getResource(path);
InputStream is = jarURL.openStream();
Manifest mf = new Manifest(is);
Attributes att = mf.getMainAttributes();
Set<Entry<Object,Object>> entries = att.entrySet();
Iterator<Entry<Object, Object>> itr = entries.iterator();
while (itr.hasNext()) {
Entry element = (Entry) itr.next();
ret.put(element.getKey().toString(),element.getValue().toString());
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
public static String readManifest(String key, ServletContext application) {
try {
URL jarURL = application.getResource("/META-INF/MANIFEST.MF");
InputStream is = jarURL.openStream();
Manifest mf = new Manifest(is);
Attributes att = mf.getMainAttributes();
return att.getValue(key);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
}