added sanity checks for delimiters
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 14 Oct 2014 08:48:46 +0000 (08:48 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 14 Oct 2014 08:48:46 +0000 (08:48 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index dbf17e601efb437a7e2303c4b8a8e221993a5624..484a133579ee30ddfa7fe9602f0cc232ceb9c900 100644 (file)
@@ -670,7 +670,11 @@ public class PreferencesUtil implements IPreferenceKeys {
         StringBuilder sb = new StringBuilder();
         for(MetadataRepositoryElement p2Repo : p2Repos) {
             sb.append(P2_REPOSITORIES_DELIM);
         StringBuilder sb = new StringBuilder();
         for(MetadataRepositoryElement p2Repo : p2Repos) {
             sb.append(P2_REPOSITORIES_DELIM);
-            sb.append(p2Repo.getName());
+            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
+                sb.append("-");
+            } else {
+                sb.append(p2Repo.getName());
+            }
             sb.append(P2_REPOSITORY_FIELDS_DELIM);
             sb.append(p2Repo.getLocation().toString());
             sb.append(P2_REPOSITORY_FIELDS_DELIM);
             sb.append(P2_REPOSITORY_FIELDS_DELIM);
             sb.append(p2Repo.getLocation().toString());
             sb.append(P2_REPOSITORY_FIELDS_DELIM);
@@ -690,21 +694,24 @@ public class PreferencesUtil implements IPreferenceKeys {
         String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
         if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
             StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
         String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
         if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
             StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
+
             while(p2ReposPrefST.hasMoreTokens()) {
                 String p2RepoStr = p2ReposPrefST.nextToken();
                 StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
             while(p2ReposPrefST.hasMoreTokens()) {
                 String p2RepoStr = p2ReposPrefST.nextToken();
                 StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
-                String nickname = p2ReposStrST.nextToken();
-                URI uri = null;
-                try {
-                    uri = new URI(p2ReposStrST.nextToken());
-                } catch (URISyntaxException e) {
-                    continue;
+                if(p2ReposStrST.countTokens()==3) {
+                    String nickname = p2ReposStrST.nextToken();
+                    URI uri = null;
+                    try {
+                        uri = new URI(p2ReposStrST.nextToken());
+                    } catch (URISyntaxException e) {
+                        continue;
+                    }
+                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
+                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
+                    mre.setNickname(nickname);
+                    mre.setEnabled(enabled);
+                    p2Repos.add(mre);
                 }
                 }
-                boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
-                MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
-                mre.setNickname(nickname);
-                mre.setEnabled(enabled);
-                p2Repos.add(mre);
             }
         }
 
             }
         }