Package javax.jcr

Examples of javax.jcr.NamespaceException


            if (!uriToPrefix.containsKey(uri)) {
                return uri;
            }
        }

        throw new NamespaceException(prefix + ": unknown prefix");
    }
View Full Code Here


            if (prefix != null) return prefix;
        }
        // Now check the underlying registry ...
        String prefix = registry.getPrefixForNamespaceUri(uri, false);
        if (prefix == null) {
            throw new NamespaceException(JcrI18n.noNamespaceWithUri.text(uri));
        }
        return prefix;
    }
View Full Code Here

            if (uri != null) return uri;
        }
        // Now check the underlying registry ...
        String uri = registry.getNamespaceForPrefix(prefix);
        if (uri == null) {
            throw new NamespaceException(JcrI18n.noNamespaceWithPrefix.text(prefix));
        }
        return uri;
    }
View Full Code Here

                // The URI must already be registered ...
                String existingPrefix = registry.getPrefixForNamespaceUri(uri, false);
                if (existingPrefix == null) {
                    // Paragraph 1 ...
                    throw new NamespaceException(JcrI18n.unableToRemapUriNotRegisteredInNamespaceRegistry.text(prefix, uri));
                }
                if (existingPrefix.equals(prefix)) return; // Paragraph 2

                // Is the prefix already used in a mapping ...
                String existingUri = registry.getNamespaceForPrefix(prefix);
                if (existingUri != null) {
                    // Is this existing mapping local, or is it in the global (workspace) registry?
                    String globalPrefix = workspaceRegistry.getPrefixForNamespaceUri(existingUri, false);
                    if (!prefix.equals(globalPrefix)) {
                        // Paragraph 3: The mapping is local to the session, so this local mapping should just be reverted ...
                        registry.unregister(existingUri);
                    }

                    // Paragraph 4: The mapping is global, so this is not allowed; the existing ...
                    String msg = JcrI18n.unableToRemapUriUsingPrefixUsedInNamespaceRegistry.text(prefix, uri, existingUri);
                    throw new NamespaceException(msg);
                }

                // Otherwise, the prefix is not already used in a mapping, so we can continue ...

                break;

            case JSR283_SESSION:
                // --------------------------------------
                // JSR-283 Session remapping behavior ...
                // --------------------------------------
                // Section 4.3.3 (of the Draft specification):
                // "All local mappings already present in the Session that include either the specified prefix
                // or the specified uri are removed and the new mapping is added."
                String existingUriForPrefix = registry.getNamespaceForPrefix(prefix);
                if (existingUriForPrefix != null) {
                    registry.unregister(existingUriForPrefix);
                }
                registry.unregister(uri);

                break;

            case WORKSPACE:
                // --------------------------------------------------
                // JSR-170 & JSR-283 Workspace namespace registry ...
                // --------------------------------------------------

                try {
                    session.checkPermission((Path)null, JcrSession.DNA_REGISTER_NAMESPACE_PERMISSION);
                } catch (AccessControlException ace) {
                    throw new AccessDeniedException(ace);
                }

                // Check the zero-length prefix and zero-length URI ...
                if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) {
                    throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text());
                }
                // Check whether the prefix or URI are reserved (case-sensitive) ...
                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));
                }
                break;
            default:
                assert false; // should never happen
        }

        // Check the zero-length prefix and zero-length URI ...
        if (DEFAULT_NAMESPACE_PREFIX.equals(prefix) || DEFAULT_NAMESPACE_URI.equals(uri)) {
            throw new NamespaceException(JcrI18n.unableToChangeTheDefaultNamespace.text());
        }

        // Check whether the prefix begins with 'xml' (in any case) ...
        if (prefix.toLowerCase().startsWith(XML_NAMESPACE_PREFIX)) {
            throw new NamespaceException(JcrI18n.unableToRegisterNamespaceUsingXmlPrefix.text(prefix, uri));
        }

        // The prefix must be a valid XML Namespace prefix (i.e., a valid NCName) ...
        if (!XmlCharacters.isValidName(prefix)) {
            throw new NamespaceException(JcrI18n.unableToRegisterNamespaceWithInvalidPrefix.text(prefix, uri));
        }

        // Now we're sure the prefix and URI are valid and okay for a custom mapping ...
        try {
            registry.register(prefix, uri);
View Full Code Here

        // Look to see whether the prefix is registered ...
        String uri = registry.getNamespaceForPrefix(prefix);
        // It is an error to unregister a namespace that is not registered ...
        if (uri == null) {
            throw new NamespaceException(JcrI18n.unableToUnregisterPrefixForNamespaceThatIsNotRegistered.text(prefix));
        }
        // Unregistering a built-in prefix or URI is invalid ...
        if (STANDARD_BUILT_IN_PREFIXES.contains(prefix)) {
            throw new NamespaceException(JcrI18n.unableToUnregisterReservedNamespacePrefix.text(prefix, uri));
        }
        if (STANDARD_BUILT_IN_URIS.contains(uri)) {
            throw new NamespaceException(JcrI18n.unableToUnregisterReservedNamespaceUri.text(prefix, uri));
        }

        // Now we're sure the prefix is valid and is actually used in a mapping ...
        try {
            registry.unregister(uri);
View Full Code Here

   {
      checkLive();
      NamespaceRegistryImpl nrg = (NamespaceRegistryImpl)workspace.getNamespaceRegistry();
      if (!nrg.isUriRegistered(uri))
      {
         throw new NamespaceException("The specified uri:" + uri + " is not among "
            + "those registered in the NamespaceRegistry");
      }
      if (nrg.isPrefixMaped(prefix))
      {
         throw new NamespaceException("A prefix '" + prefix + "' is currently already mapped to " + nrg.getURI(prefix)
            + " URI persistently in the repository NamespaceRegistry "
            + "and cannot be remapped to a new URI using this method, since this would make any "
            + "content stored using the old URI unreadable.");
      }
      if (namespaces.containsKey(prefix))
      {
         throw new NamespaceException("A prefix '" + prefix + "' is currently already mapped to "
            + namespaces.get(prefix) + " URI transiently within this Session and cannot be "
            + "remapped to a new URI using this method, since this would make any "
            + "content stored using the old URI unreadable.");
      }
      nrg.validateNamespace(prefix, uri);
View Full Code Here

      String prefix = prefixes.get(uri);
      if (prefix != null)
      {
         return prefix;
      }
      throw new NamespaceException("Prefix for " + uri + " not found");
   }
View Full Code Here

   public String getURI(String prefix) throws NamespaceException
   {
      String uri = namespaces.get(prefix);
      if (uri == null)
      {
         throw new NamespaceException("Unknown Prefix " + prefix);
      }
      return uri;
   }
View Full Code Here

   public void unregisterNamespace(String prefix) throws NamespaceException, RepositoryException
   {

      if (namespaces.get(prefix) == null)
      {
         throw new NamespaceException("Prefix " + prefix + " is not registered");
      }

      if (PROTECTED_NAMESPACES.contains(prefix))
      {
         throw new NamespaceException("Prefix " + prefix + " is protected");
      }
      String uri = getURI(prefix);
      if (indexSearcherHolder != null)
      {
         final Set<String> nodes = indexSearcherHolder.getNodesByUri(uri);
         if (nodes.size() > 0)
         {
            StringBuffer buffer = new StringBuffer();
            buffer.append("Fail to unregister namespace");
            buffer.append(prefix);
            buffer.append(" because of following nodes:  ");

            for (String uuid : nodes)
            {
               ItemData item = dataManager.getItemData(uuid);
               if (item != null && item.isNode())
               {
                  buffer.append(item.getQPath().getAsString());
               }
            }
            buffer.append(" contains whese prefix  ");
            throw new NamespaceException(buffer.toString());
         }
      }
      prefixes.remove(uri);
      namespaces.remove(prefix);
      if (persister != null)
View Full Code Here

      if (PROTECTED_NAMESPACES.contains(prefix))
      {
         if (uri == null)
         {
            throw new NamespaceException("Can not remove built-in namespace " + prefix);
         }
         throw new NamespaceException("Can not change built-in namespace " + prefix);
      }
      if (prefix.toLowerCase().startsWith("xml"))
      {
         throw new NamespaceException("Can not re-assign prefix that start with 'xml'");
      }
      if (uri == null)
      {
         throw new NamespaceException("Can not register NULL URI!");
      }
   }
View Full Code Here

TOP

Related Classes of javax.jcr.NamespaceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.