ACE-518 Added validation to keys for attributes and tags.

git-svn-id: https://svn.apache.org/repos/asf/ace/trunk@1683872 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java b/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
index 545b6d7..6044089 100644
--- a/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
+++ b/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.apache.ace.client.repository.Associatable;
 import org.apache.ace.client.repository.Association;
@@ -55,6 +56,7 @@
     private final Map<Class, List<Association>> m_associations = new HashMap<Class, List<Association>>();
     private final ChangeNotifier m_notifier;
     private final String m_xmlNode;
+    private static final Pattern VALID_KEY_PATTERN = Pattern.compile("[a-zA-Z]([a-zA-Z0-9_:.-])*");
 
     private volatile boolean m_deleted = false;
     private volatile boolean m_busy = false;
@@ -189,6 +191,7 @@
         if (value == null || key == null) {
             throw new IllegalArgumentException("Invalid key/value pair: " + key + "/" + value);
         }
+        validateKey(key);
         for (String s : getDefiningKeys()) {
             if (s.equals(key)) {
                 throw new UnsupportedOperationException("The defining attribute " + key + " is not allowed to be changed.");
@@ -235,6 +238,7 @@
         if (value == null || key == null) {
             throw new IllegalArgumentException("Invalid key/value pair: " + key + "/" + value);
         }
+        validateKey(key);
         String result = null;
         synchronized (m_attributes) {
             ensureCurrent();
@@ -249,6 +253,12 @@
         return result;
     }
 
+    private void validateKey(String key) {
+        if (!VALID_KEY_PATTERN.matcher(key).matches()) {
+            throw new IllegalArgumentException("Invalid key " + key + " does not match regex pattern " + VALID_KEY_PATTERN.pattern());
+        }
+    }
+
     @Override
     public String removeTag(String key) {
         String result = null;