Example usage for java.util.jar Attributes containsKey

List of usage examples for java.util.jar Attributes containsKey

Introduction

In this page you can find the example usage for java.util.jar Attributes containsKey.

Prototype

public boolean containsKey(Object name) 

Source Link

Document

Returns true if this Map contains the specified attribute name (key).

Usage

From source file:org.lockss.plugin.PluginManager.java

/**
 * Given a file representing a JAR, retrieve a list of available
 * plugin classes to load./* w  w w .j a  v  a  2  s.com*/
 */
private List<String> getJarPluginClasses(File blessedJar) throws IOException {
    JarFile jar = new JarFile(blessedJar);
    Manifest manifest = jar.getManifest();
    Map entries = manifest.getEntries();
    List<String> plugins = new ArrayList<String>();

    for (Iterator manIter = entries.keySet().iterator(); manIter.hasNext();) {
        String key = (String) manIter.next();

        Attributes attrs = manifest.getAttributes(key);

        if (attrs.containsKey(LOADABLE_PLUGIN_ATTR)) {
            String s = StringUtil.replaceString(key, "/", ".");

            String pluginName = null;

            if (StringUtil.endsWithIgnoreCase(key, ".class")) {
                pluginName = StringUtil.replaceString(s, ".class", "");
                log.debug2("Adding '" + pluginName + "' to plugin load list.");
                plugins.add(pluginName);
            } else if (StringUtil.endsWithIgnoreCase(key, ".xml")) {
                pluginName = StringUtil.replaceString(s, ".xml", "");
                log.debug2("Adding '" + pluginName + "' to plugin load list.");
                plugins.add(pluginName);
            }
        }

    }

    jar.close();

    return plugins;
}

From source file:org.rhq.plugins.jbossas.util.FileContentDelegate.java

/**
 * Write the SHA256 to the manifest using the RHQ-Sha256 attribute tag.
 *
 * @param deploymentFolder app deployment folder
 * @param sha SHA256//  ww  w . jav  a2 s. co  m
 * @throws IOException
 */
private void writeSHAToManifest(File deploymentFolder, String sha) throws IOException {
    File manifestFile = new File(deploymentFolder, MANIFEST_RELATIVE_PATH);
    Manifest manifest;
    if (manifestFile.exists()) {
        FileInputStream inputStream = new FileInputStream(manifestFile);
        try {
            manifest = new Manifest(inputStream);
        } finally {
            inputStream.close();
        }
    } else {
        manifest = new Manifest();
        manifestFile.getParentFile().mkdirs();
        manifestFile.createNewFile();
    }

    Attributes attribs = manifest.getMainAttributes();

    //The main section of the manifest file does not get saved if both of
    //these two attributes are missing. Please see Attributes implementation.
    if (!attribs.containsKey(Attributes.Name.MANIFEST_VERSION.toString())
            && !attribs.containsKey(Attributes.Name.SIGNATURE_VERSION.toString())) {
        attribs.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
    }

    attribs.putValue(RHQ_SHA_256, sha);

    FileOutputStream outputStream = new FileOutputStream(manifestFile);
    try {
        manifest.write(outputStream);
    } finally {
        outputStream.close();
    }
}