@Test( expected = NamespaceException.class ) public void shouldNotAllowRegisteringPrefixThatStartsWithUppercaseXml() throws Exception { registry.registerNamespace("XMLw", "http: }
@Override public synchronized void registerNamespace( String prefix, String uri ) throws NamespaceException, RepositoryException { CheckArg.isNotNull(prefix, "prefix"); CheckArg.isNotNull(uri, "uri"); checkSession(); if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) { throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text()); } if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri)); } if (!XmlCharacters.isValidNcName(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } try { session.nameFactory().create(prefix); } catch (ValueFormatException e) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } String existingPrefixForURI = registry.getPrefixForNamespaceUri(uri, false); if (prefix.equals(existingPrefixForURI)) { return; } boolean global = false; switch (behavior) { case SESSION: String existingUriForPrefix = registry.getNamespaceForPrefix(prefix); if (existingUriForPrefix != null) { registry.unregister(existingUriForPrefix); } registry.unregister(uri); break; case WORKSPACE: global = true; if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri)); } if (STANDARD_BUILT_IN_URIS.contains(uri)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri)); } try { session.checkWorkspacePermission(session.workspaceName(), ModeShapePermissions.REGISTER_NAMESPACE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } if (existingPrefixForURI != null) { checkURINotInUse(uri); } registry.unregister(uri); break; default: assert false; } try { registry.register(prefix, uri); session.signalNamespaceChanges(global); } catch (RuntimeException e) { throw new RepositoryException(e.getMessage(), e.getCause()); } }
JcrNamespaceRegistry implements org.modeshape.jcr.api.NamespaceRegistry { @Override public synchronized void registerNamespace( String prefix, String uri ) throws NamespaceException, RepositoryException { CheckArg.isNotNull(prefix, "prefix"); CheckArg.isNotNull(uri, "uri"); checkSession(); if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) { throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text()); } if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri)); } if (!XmlCharacters.isValidNcName(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } try { session.nameFactory().create(prefix); } catch (ValueFormatException e) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } String existingPrefixForURI = registry.getPrefixForNamespaceUri(uri, false); if (prefix.equals(existingPrefixForURI)) { return; } boolean global = false; switch (behavior) { case SESSION: String existingUriForPrefix = registry.getNamespaceForPrefix(prefix); if (existingUriForPrefix != null) { registry.unregister(existingUriForPrefix); } registry.unregister(uri); break; case WORKSPACE: global = true; if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri)); } if (STANDARD_BUILT_IN_URIS.contains(uri)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri)); } try { session.checkWorkspacePermission(session.workspaceName(), ModeShapePermissions.REGISTER_NAMESPACE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } if (existingPrefixForURI != null) { checkURINotInUse(uri); } registry.unregister(uri); break; default: assert false; } try { registry.register(prefix, uri); session.signalNamespaceChanges(global); } catch (RuntimeException e) { throw new RepositoryException(e.getMessage(), e.getCause()); } } }
JcrNamespaceRegistry implements org.modeshape.jcr.api.NamespaceRegistry { @Override public synchronized void registerNamespace( String prefix, String uri ) throws NamespaceException, RepositoryException { CheckArg.isNotNull(prefix, "prefix"); CheckArg.isNotNull(uri, "uri"); checkSession(); if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) { throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text()); } if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri)); } if (!XmlCharacters.isValidNcName(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } try { session.nameFactory().create(prefix); } catch (ValueFormatException e) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } String existingPrefixForURI = registry.getPrefixForNamespaceUri(uri, false); if (prefix.equals(existingPrefixForURI)) { return; } boolean global = false; switch (behavior) { case SESSION: String existingUriForPrefix = registry.getNamespaceForPrefix(prefix); if (existingUriForPrefix != null) { registry.unregister(existingUriForPrefix); } registry.unregister(uri); break; case WORKSPACE: global = true; if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri)); } if (STANDARD_BUILT_IN_URIS.contains(uri)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri)); } try { session.checkWorkspacePermission(session.workspaceName(), ModeShapePermissions.REGISTER_NAMESPACE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } if (existingPrefixForURI != null) { checkURINotInUse(uri); } registry.unregister(uri); break; default: assert false; } try { registry.register(prefix, uri); session.signalNamespaceChanges(global); } catch (RuntimeException e) { throw new RepositoryException(e.getMessage(), e.getCause()); } } protected  JcrNamespaceRegistry( NamespaceRegistry workspaceRegistry,
                                    JcrSession session );   JcrNamespaceRegistry( Behavior behavior,
                          NamespaceRegistry localRegistry,
                          NamespaceRegistry workspaceRegistry,
                          JcrSession session ); }
JcrNamespaceRegistry implements org.modeshape.jcr.api.NamespaceRegistry { @Override public synchronized void registerNamespace( String prefix, String uri ) throws NamespaceException, RepositoryException { CheckArg.isNotNull(prefix, "prefix"); CheckArg.isNotNull(uri, "uri"); checkSession(); if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) { throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text()); } if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri)); } if (!XmlCharacters.isValidNcName(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } try { session.nameFactory().create(prefix); } catch (ValueFormatException e) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } String existingPrefixForURI = registry.getPrefixForNamespaceUri(uri, false); if (prefix.equals(existingPrefixForURI)) { return; } boolean global = false; switch (behavior) { case SESSION: String existingUriForPrefix = registry.getNamespaceForPrefix(prefix); if (existingUriForPrefix != null) { registry.unregister(existingUriForPrefix); } registry.unregister(uri); break; case WORKSPACE: global = true; if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri)); } if (STANDARD_BUILT_IN_URIS.contains(uri)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri)); } try { session.checkWorkspacePermission(session.workspaceName(), ModeShapePermissions.REGISTER_NAMESPACE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } if (existingPrefixForURI != null) { checkURINotInUse(uri); } registry.unregister(uri); break; default: assert false; } try { registry.register(prefix, uri); session.signalNamespaceChanges(global); } catch (RuntimeException e) { throw new RepositoryException(e.getMessage(), e.getCause()); } } protected  JcrNamespaceRegistry( NamespaceRegistry workspaceRegistry,
                                    JcrSession session );   JcrNamespaceRegistry( Behavior behavior,
                          NamespaceRegistry localRegistry,
                          NamespaceRegistry workspaceRegistry,
                          JcrSession session ); @Override String getPrefix( String uri ); @Override String[] getPrefixes(); @Override String getURI( String prefix ); @Override String[] getURIs(); @Override boolean isRegisteredPrefix( String prefix ); @Override boolean isRegisteredUri( String uri ); @Override synchronized void registerNamespace( String prefix,
                                                String uri ); @Override synchronized void unregisterNamespace( String prefix ); @Override String registerNamespace( String uri ); @Override String toString(); }
JcrNamespaceRegistry implements org.modeshape.jcr.api.NamespaceRegistry { @Override public synchronized void registerNamespace( String prefix, String uri ) throws NamespaceException, RepositoryException { CheckArg.isNotNull(prefix, "prefix"); CheckArg.isNotNull(uri, "uri"); checkSession(); if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) { throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text()); } if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri)); } if (!XmlCharacters.isValidNcName(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } try { session.nameFactory().create(prefix); } catch (ValueFormatException e) { throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri)); } String existingPrefixForURI = registry.getPrefixForNamespaceUri(uri, false); if (prefix.equals(existingPrefixForURI)) { return; } boolean global = false; switch (behavior) { case SESSION: String existingUriForPrefix = registry.getNamespaceForPrefix(prefix); if (existingUriForPrefix != null) { registry.unregister(existingUriForPrefix); } registry.unregister(uri); break; case WORKSPACE: global = true; if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespacePrefix.text(prefix, uri)); } if (STANDARD_BUILT_IN_URIS.contains(uri)) { throw new NamespaceException(JcrI18n.unableToRegisterReservedNamespaceUri.text(prefix, uri)); } try { session.checkWorkspacePermission(session.workspaceName(), ModeShapePermissions.REGISTER_NAMESPACE); } catch (AccessControlException ace) { throw new AccessDeniedException(ace); } if (existingPrefixForURI != null) { checkURINotInUse(uri); } registry.unregister(uri); break; default: assert false; } try { registry.register(prefix, uri); session.signalNamespaceChanges(global); } catch (RuntimeException e) { throw new RepositoryException(e.getMessage(), e.getCause()); } } protected  JcrNamespaceRegistry( NamespaceRegistry workspaceRegistry,
                                    JcrSession session );   JcrNamespaceRegistry( Behavior behavior,
                          NamespaceRegistry localRegistry,
                          NamespaceRegistry workspaceRegistry,
                          JcrSession session ); @Override String getPrefix( String uri ); @Override String[] getPrefixes(); @Override String getURI( String prefix ); @Override String[] getURIs(); @Override boolean isRegisteredPrefix( String prefix ); @Override boolean isRegisteredUri( String uri ); @Override synchronized void registerNamespace( String prefix,
                                                String uri ); @Override synchronized void unregisterNamespace( String prefix ); @Override String registerNamespace( String uri ); @Override String toString();  }