You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ky...@apache.org on 2005/02/10 19:03:37 UTC
svn commit: r153278 -
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
Author: kylem
Date: Thu Feb 10 10:03:34 2005
New Revision: 153278
URL: http://svn.apache.org/viewcvs?view=rev&rev=153278
Log:
Improved validation of @ManifestAttribute annotation, to ensure conformance with the JAR packaging spec. Resolves BEEHIVE-116.
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java?view=diff&r1=153277&r2=153278
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java (original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java Thu Feb 10 10:03:34 2005
@@ -672,6 +672,62 @@
return null;
}
+ //
+ // These are defined by the JAR spec, Name-value pair section
+ //
+ static final String alphaNum = "ABCDEFGHIJKLMNOPQRSUVWXYZabcdefghijklmnopqrstuvwyz0123456789";
+ static final String headerChar = alphaNum + "_-";
+
+ /**
+ * Validates a manifest attribute. If the attribute is invalid, it will generate
+ * appropriate APT messager entries and return false, else return true.
+ */
+ private boolean isValidManifestAttribute(ManifestAttribute attr)
+ {
+ String name = attr.name();
+ String value = attr.value();
+ boolean isValid = true;
+ if (name.length() == 0)
+ {
+ _env.getMessager().printError(_intfDecl.getPosition(),
+ "@ManifestAttribute name cannot be a zero-length string");
+ isValid = false;
+ }
+ else
+ {
+ if (alphaNum.indexOf(name.charAt(0)) < 0)
+ {
+ _env.getMessager().printError(_intfDecl.getPosition(),
+ "@ManifestAttribute name must begin with an alphanumeric character");
+ isValid = false;
+ }
+ for (int i = 1; i < name.length(); i++)
+ {
+ if (headerChar.indexOf(name.charAt(i)) < 0)
+ {
+ _env.getMessager().printError(_intfDecl.getPosition(),
+ "@ManifestAttribute name contains an invalid character:" +
+ name.charAt(i));
+ isValid = false;
+ break;
+ }
+ }
+ }
+
+ if (value.length() == 0)
+ {
+ _env.getMessager().printError(_intfDecl.getPosition(),
+ "@ManifestAttribute value cannot be a zero-length string");
+ isValid = false;
+ }
+ else
+ {
+ // TODO: validate string contents are valid UTF-8?
+ }
+
+ return isValid;
+ }
+
/**
* Returns the array of ManifestAttributes associated with the AptControlInterface
*/
@@ -689,12 +745,16 @@
{
ManifestAttribute [] attrs = (ManifestAttribute [])annotAttrs.value();
for (int i = 0; i < attrs.length; i++)
- attributes.put(attrs[i].name(), attrs[i].value());
+ {
+ if (isValidManifestAttribute(attrs[i]))
+ attributes.put(attrs[i].name(), attrs[i].value());
+ }
}
- ManifestAttribute annotAttr =_intfDecl.getAnnotation(ManifestAttribute.class);
+ ManifestAttribute annotAttr = _intfDecl.getAnnotation(ManifestAttribute.class);
if (annotAttr != null)
{
- attributes.put(annotAttr.name(), annotAttr.value());
+ if (isValidManifestAttribute(annotAttr))
+ attributes.put(annotAttr.name(), annotAttr.value());
}
return attributes;
}