1 17 package org.alfresco.jcr.dictionary; 18 19 import java.util.Collection ; 20 21 import javax.jcr.AccessDeniedException; 22 import javax.jcr.NamespaceException; 23 import javax.jcr.NamespaceRegistry; 24 import javax.jcr.RepositoryException; 25 import javax.jcr.UnsupportedRepositoryOperationException; 26 27 import org.alfresco.service.namespace.NamespaceService; 28 29 30 35 public class NamespaceRegistryImpl implements NamespaceRegistry 36 { 37 38 private boolean allowRegistration; 39 private NamespaceService namespaceService; 40 41 42 47 public NamespaceRegistryImpl(boolean allowRegistraton, NamespaceService namespaceService) 48 { 49 this.allowRegistration = allowRegistraton; 50 this.namespaceService = namespaceService; 51 } 52 53 58 public NamespaceService getNamespaceService() 59 { 60 return this.namespaceService; 61 } 62 63 66 public void registerNamespace(String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException 67 { 68 try 69 { 70 if (!allowRegistration) 71 { 72 throw new UnsupportedRepositoryOperationException(); 73 } 74 namespaceService.registerNamespace(prefix, uri); 75 } 76 catch(org.alfresco.service.namespace.NamespaceException e) 77 { 78 throw new NamespaceException(e); 79 } 80 } 81 82 85 public void unregisterNamespace(String prefix) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException 86 { 87 try 88 { 89 if (!allowRegistration) 90 { 91 throw new UnsupportedRepositoryOperationException(); 92 } 93 namespaceService.unregisterNamespace(prefix); 94 } 95 catch(org.alfresco.service.namespace.NamespaceException e) 96 { 97 throw new NamespaceException(e); 98 } 99 } 100 101 104 public String [] getPrefixes() throws RepositoryException 105 { 106 Collection <String > prefixes = namespaceService.getPrefixes(); 107 return prefixes.toArray(new String [prefixes.size()]); 108 } 109 110 113 public String [] getURIs() throws RepositoryException 114 { 115 Collection <String > uris = namespaceService.getURIs(); 116 return uris.toArray(new String [uris.size()]); 117 } 118 119 122 public String getURI(String prefix) throws NamespaceException, RepositoryException 123 { 124 String uri = namespaceService.getNamespaceURI(prefix); 125 if (uri == null) 126 { 127 throw new NamespaceException("Prefix " + prefix + " is unknown."); 128 } 129 return uri; 130 } 131 132 135 public String getPrefix(String uri) throws NamespaceException, RepositoryException 136 { 137 Collection <String > prefixes = namespaceService.getPrefixes(uri); 138 if (prefixes.size() == 0) 139 { 140 throw new NamespaceException("URI " + uri + " is unknown."); 141 } 142 return prefixes.iterator().next(); 144 } 145 146 } 147 | Popular Tags |