* if the attribute already exists in this section.
*/
public String addAttributeAndCheck(Attribute attribute)
throws ManifestException {
if (attribute.getName() == null || attribute.getValue() == null) {
throw new ManifestException(
"Attributes must have name and value");
}
if (attribute.getKey().equalsIgnoreCase(ATTRIBUTE_NAME)) {
warnings
.add("\""
+ ATTRIBUTE_NAME
+ "\" attributes "
+ "should not occur in the main section and must be the "
+ "first element in all other sections: \""
+ attribute.getName() + ": "
+ attribute.getValue() + "\"");
return attribute.getValue();
}
if (attribute.getKey().startsWith(ATTRIBUTE_FROM.toLowerCase())) {
warnings.add("Manifest attributes should not start "
+ "with \"" + ATTRIBUTE_FROM + "\" in \""
+ attribute.getName() + ": " + attribute.getValue()
+ "\"");
} else {
// classpath attributes go into a vector
String attributeKey = attribute.getKey();
if (attributeKey.equalsIgnoreCase(ATTRIBUTE_CLASSPATH)) {
Attribute classpathAttribute = (Attribute) attributes
.get(attributeKey);
if (classpathAttribute == null) {
storeAttribute(attribute);
} else {
warnings.add("Multiple Class-Path attributes "
+ "are supported but violate the Jar "
+ "specification and may not be correctly "
+ "processed in all environments");
Iterator<String> e = attribute.getValues();
while (e.hasNext()) {
String value = e.next();
classpathAttribute.addValue(value);
}
}
} else if (attributes.containsKey(attributeKey)) {
throw new ManifestException("The attribute \""
+ attribute.getName() + "\" may not occur more "
+ "than once in the same section");
} else {
storeAttribute(attribute);
}