1 17 package org.alfresco.repo.dictionary; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.Collections ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 25 import org.alfresco.service.namespace.NamespaceException; 26 27 32 public class NamespaceDAOImpl implements NamespaceDAO 33 { 34 35 private List <String > uris = new ArrayList <String >(); 36 private HashMap <String , String > prefixes = new HashMap <String , String >(); 37 38 39 public Collection <String > getURIs() 40 { 41 return Collections.unmodifiableCollection(uris); 42 } 43 44 45 48 public Collection <String > getPrefixes() 49 { 50 return Collections.unmodifiableCollection(prefixes.keySet()); 51 } 52 53 54 57 public void addURI(String uri) 58 { 59 if (uris.contains(uri)) 60 { 61 throw new NamespaceException("URI " + uri + " has already been defined"); 62 } 63 uris.add(uri); 64 } 65 66 67 70 public void addPrefix(String prefix, String uri) 71 { 72 if (!uris.contains(uri)) 73 { 74 throw new NamespaceException("Namespace URI " + uri + " does not exist"); 75 } 76 prefixes.put(prefix, uri); 77 } 78 79 80 83 public void removeURI(String uri) 84 { 85 uris.remove(uri); 86 } 87 88 89 92 public void removePrefix(String prefix) 93 { 94 prefixes.remove(prefix); 95 } 96 97 98 101 public String getNamespaceURI(String prefix) 102 { 103 return prefixes.get(prefix); 104 } 105 106 107 110 public Collection <String > getPrefixes(String URI) 111 { 112 Collection <String > uriPrefixes = new ArrayList <String >(); 113 for (String key : prefixes.keySet()) 114 { 115 String uri = prefixes.get(key); 116 if ((uri != null) && (uri.equals(URI))) 117 { 118 uriPrefixes.add(key); 119 } 120 } 121 return uriPrefixes; 122 } 123 124 } 125 | Popular Tags |