Example usage for java.util.jar Attributes keySet

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

Introduction

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

Prototype

public Set<Object> keySet() 

Source Link

Document

Returns a Set view of the attribute names (keys) contained in this Map.

Usage

From source file:org.kepler.kar.karxml.KarXmlGenerator.java

/**
 * Read in all attributes for the entry and append them to the xml.
 * // w ww . jav  a 2  s .co  m
 * @param entry
 */
private void appendXmlForEntryAttributes(KAREntry entry) {

    karxml.append(tab + tab + "<karEntryAttributes>" + nl);

    // the name of a KAREntry is not found in it's attributes
    // must get it directly
    String entryName = entry.getName();
    karxml.append(tab + tab + tab + "<Name>" + nl);
    karxml.append(tab + tab + tab + tab + entryName + nl);
    karxml.append(tab + tab + tab + "</Name>" + nl);

    Attributes atts = entry.getAttributes();

    for (Object att : atts.keySet()) {
        // System.out.println( att.toString() );
        if (att instanceof Name) {

            Name attrName = (Name) att;
            String value = atts.getValue(attrName);

            karxml.append(tab + tab + tab + "<" + attrName + ">" + nl);
            karxml.append(tab + tab + tab + tab + value + nl);
            karxml.append(tab + tab + tab + "</" + attrName + ">" + nl);

        }
    }

    karxml.append(tab + tab + "</karEntryAttributes>" + nl);

}

From source file:org.teragrid.portal.filebrowser.applet.ConfigOperation.java

private void readVersionInformation() {
    InputStream stream = null;/* w w  w. j a v  a 2s  . c o  m*/
    try {
        JarFile tgfmJar = null;
        URL jarname = Class.forName("org.teragrid.portal.filebrowser.applet.ConfigOperation")
                .getResource("ConfigOperation.class");
        JarURLConnection c = (JarURLConnection) jarname.openConnection();
        tgfmJar = c.getJarFile();
        stream = tgfmJar.getInputStream(tgfmJar.getEntry("META-INF/MANIFEST.MF"));
        Manifest manifest = new Manifest(stream);
        Attributes attributes = manifest.getMainAttributes();
        for (Object attributeName : attributes.keySet()) {
            if (((Attributes.Name) attributeName).toString().equals(("Implementation-Version"))) {
                ConfigSettings.SOFTWARE_VERSION = attributes.getValue("Implementation-Version");
            } else if (((Attributes.Name) attributeName).toString().equals(("Built-Date"))) {
                ConfigSettings.SOFTWARE_BUILD_DATE = attributes.getValue("Built-Date");
            }

            LogManager
                    .debug(attributeName + ": " + attributes.getValue((Attributes.Name) attributeName) + "\n");
        }

        stream.close();
    } catch (Exception e) {
        LogManager.error("Failed to retreive version information.", e);
    } finally {
        try {
            stream.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.wso2.carbon.wsdl2code.POMGenerator.java

public static String getVersion(String artifact) throws Exception {

    java.io.File file = new java.io.File(artifact);
    java.util.jar.JarFile jar = new java.util.jar.JarFile(file);
    java.util.jar.Manifest manifest = jar.getManifest();

    String versionNumber = "";
    java.util.jar.Attributes attributes = manifest.getMainAttributes();
    if (attributes != null) {
        java.util.Iterator it = attributes.keySet().iterator();
        while (it.hasNext()) {
            java.util.jar.Attributes.Name key = (java.util.jar.Attributes.Name) it.next();
            String keyword = key.toString();
            if (keyword.equals("Implementation-Version") || keyword.equals("Bundle-Version")) {
                versionNumber = (String) attributes.get(key);
                break;
            }/*  w ww.j  av  a2s.  com*/
        }
    }
    jar.close();

    if (versionNumber != null && !versionNumber.equals("")) {
        return versionNumber;
    }

    //if manifest does not contain version number it had to be extracted from the file name
    String fileName = file.getName().substring(0, file.getName().lastIndexOf("."));
    if (fileName.contains(".")) {
        String majorVersion = fileName.substring(0, fileName.indexOf("."));
        String minorVersion = fileName.substring(fileName.indexOf("."));
        int delimiter = majorVersion.lastIndexOf("-");
        if (majorVersion.indexOf("_") > delimiter)
            delimiter = majorVersion.indexOf("_");
        majorVersion = majorVersion.substring(delimiter + 1, fileName.indexOf("."));
        versionNumber = majorVersion + minorVersion;
    }

    return versionNumber;

}