📄 attributes.java
字号:
/* Attributes.java -- Represents attribute name/value pairs from a Manifest Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.util.jar;import java.util.Collection;import java.util.Hashtable;import java.util.Map;import java.util.Set;/** * Represents attribute name/value pairs from a Manifest as a Map. * The names of an attribute are represented by the * <code>Attributes.Name</code> class and should confirm to the restrictions * described in that class. Note that the Map interface that Attributes * implements allows you to put names and values into the attribute that don't * follow these restriction (and are not really Atrribute.Names, but if you do * that it might cause undefined behaviour later). * <p> * If you use the constants defined in the inner class Name then you can be * sure that you always access the right attribute names. This makes * manipulating the Attributes more or less type safe. * <p> * Most of the methods are wrappers to implement the Map interface. The really * useful and often used methods are <code>getValue(Name)</code> and * <code>getValue(String)</code>. If you actually want to set attributes you * may want to use the <code>putValue(String, String)</code> method * (sorry there is no public type safe <code>putValue(Name, String)</code> * method). * * @see java.util.jar.Attributes.Name * @author Mark Wielaard (mark@klomp.org) */public class Attributes implements Cloneable, Map{ // Fields /** * The map that holds all the attribute name/value pairs. In this * implementation it is actually a Hashtable, but that can be different in * other implementations. */ protected Map map; // Inner class /** * Represents a name of a Manifest Attribute. Defines a couple of well * know names for the general main attributes, stand alone application * attributes, applet attributes, extension identification attributes, * package versioning and sealing attributes, file contents attributes, * bean objects attribute and signing attributes. See the * * <p>The characters of a Name must obey the following restrictions:</p> * * <ul> * <li>Must contain at least one character</li> * <li>The first character must be alphanumeric (a-z, A-Z, 0-9)</li> * <li>All other characters must be alphanumeric, a '-' or a '_'</li> * </ul> * * <p>When comparing Names (with <code>equals</code>) all characters are * converted to lowercase. But you can get the original case sensitive * string with the <code>toString()</code> method.</p> * * <p>Most important attributes have a constant defined in this * class. Some other attributes used in Manifest files are: * <ul> * <li> "Created-By" - General main attribute, tool and version * that created this Manifest file.</li> * <li> "Java-Bean" - Bean objects attribute, whether the entry is a Bean. * Value is either "true" or "false".</li> * <li> "Magic" - Signing attribute, application specific signing attribute. * Must be understood by the manifest parser when present to validate the * jar (entry).</li> * </ul> * * @since 1.2 * @author Mark Wielaard (mark@klomp.org) */ public static class Name { // General Main Attributes /** * General main attribute - * the version of this Manifest file. */ public static final Name MANIFEST_VERSION = new Name("Manifest-Version"); /** * General main attribute - * the version of the jar file signature. */ public static final Name SIGNATURE_VERSION = new Name("Signature-Version"); /** * General main attribute - * (relative) file paths of the libraries/classpaths that the Classes in * this jar file depend on. Paths are separated by spaces. */ public static final Name CLASS_PATH = new Name("Class-Path"); /** * Stand alone application attribute - * the entry (without the .class ending) that is the main * class of this jar file. */ public static final Name MAIN_CLASS = new Name("Main-Class"); /** * Applet attribute - * a list of extension libraries that the applet in this * jar file depends on. * For every named extension there should be some Attributes in the * Manifest manifest file with the following Names: * <ul> * <li> <extension>-Extension-Name: * unique name of the extension</li> * <li> <extension>-Specification-Version: * minimum specification version</li> * <li> <extension>-Implementation-Version: * minimum implementation version</li> * <li> <extension>-Implementation-Vendor-Id: * unique id of implementation vendor</li> * <li> <extension>-Implementation-URL: * where the latest version of the extension library can be found</li> * </ul> */ public static final Name EXTENSION_LIST = new Name("Extension-List"); /** * Extension identification attribute - * the name if the extension library contained in the jar. */ public static final Name EXTENSION_NAME = new Name("Extension-Name"); /** * Extension identification attribute - * synonym for <code>EXTENSTION_NAME</code>. */ public static final Name EXTENSION_INSTALLATION = EXTENSION_NAME; // Package versioning and sealing attributes /** * Package versioning - * name of extension library contained in this jar. */ public static final Name IMPLEMENTATION_TITLE = new Name("Implementation-Title"); /** * Package versioning - * version of the extension library contained in this jar. */ public static final Name IMPLEMENTATION_VERSION = new Name("Implementation-Version"); /** * Package versioning - * name of extension library creator contained in this jar. */ public static final Name IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor"); /** * Package versioning - * unique id of extension library creator. */ public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id"); /** * Package versioning - * location where this implementation can be downloaded. */ public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL"); /** * Package versioning - * title of the specification contained in this jar. */ public static final Name SPECIFICATION_TITLE = new Name("Specification-Title"); /** * Package versioning - * version of the specification contained in this jar. */ public static final Name SPECIFICATION_VERSION = new Name("Specification-Version"); /** * Package versioning - * organisation that maintains the specification contains in this * jar. */ public static final Name SPECIFICATION_VENDOR = new Name("Specification-Vendor"); /** * Package sealing - * whether (all) package(s) is(/are) sealed. Value is either "true" * or "false". */ public static final Name SEALED = new Name("Sealed"); /** * File contents attribute - * Mime type and subtype for the jar entry. */ public static final Name CONTENT_TYPE = new Name("Content-Type"); /** The (lowercase) String representation of this Name */ private final String name; /** The original String given to the constructor */ private final String origName; // Constructor /** * Creates a new Name from the given String. * Throws an IllegalArgumentException if the given String is empty or * contains any illegal Name characters. * * @param name the name of the new Name * @exception IllegalArgumentException if name isn't a valid String * representation of a Name * @exception NullPointerException if name is null */ public Name(String name) throws IllegalArgumentException, NullPointerException { // name must not be null // this will throw a NullPointerException if it is char chars[] = name.toCharArray(); // there must be at least one character if (chars.length == 0) throw new IllegalArgumentException ("There must be at least one character in a name"); // first character must be alphanum char c = chars[0]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))) throw new IllegalArgumentException("First character must be alphanum"); // all other characters must be alphanums, '-' or '_' for (int i = 1; i < chars.length; i++) { c = chars[i]; if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '-') || (c == '_'))) throw new IllegalArgumentException ("Characters must be alphanums, '-' or '_'"); } // Still here? Then convert to lower case and be done. // Store the original name for toString(); this.origName = name; this.name = name.toLowerCase(); } /** * Returns the hash code of the (lowercase) String representation of * this Name. */ public int hashCode() { return name.hashCode(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -