Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-1795

ModeShape does not allow importing a XML file that declares a default XML namespace

    XMLWordPrintable

Details

    • Hide

      Write a simple XML file, such as:

      <?xml version="1.0" encoding="utf-8"?>
      <root xmlns="http://www.ns.com">
          <element>value</element>
      </root>
      

      Then, in your code, register the default namespace's URI with the workspace namespace registry, as follows:

         NamespaceRegistry nsR = session.getWorkspace().getNamespaceRegistry();
         nsR.registerNamespace( "ns", "http://www.ns.com" );
      

      Then, import the XML file under some JCR node of your repository, as follows:

         InputStream input = new FileInputStream( xmlFile );
         session.importXML( n, input, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
      

      The call to the importXML() method raises the following exception:

      javax.jcr.RepositoryException: Prefix  is already permanently mapped
      

      But the XML default namespace declaration should be simply ignored, since a JCR namespace which is mapped to the same URI already exists.

      Show
      Write a simple XML file, such as: <?xml version= "1.0" encoding= "utf-8" ?> <root xmlns= "http://www.ns.com" > <element> value </element> </root> Then, in your code, register the default namespace's URI with the workspace namespace registry, as follows: NamespaceRegistry nsR = session.getWorkspace().getNamespaceRegistry(); nsR.registerNamespace( "ns" , "http: //www.ns.com" ); Then, import the XML file under some JCR node of your repository, as follows: InputStream input = new FileInputStream( xmlFile ); session.importXML( n, input, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); The call to the importXML() method raises the following exception: javax.jcr.RepositoryException: Prefix is already permanently mapped But the XML default namespace declaration should be simply ignored, since a JCR namespace which is mapped to the same URI already exists.

    Description

      When importing a XML file (using the Session.importXML() method) that declares a default namespace (xmlns="URI"), you get the following error:

          javax.jcr.RepositoryException: Prefix  is already permanently mapped
      

      This makes sense since JCR always creates a JCR namespace identified by the empty prefix. And according to the JCR specs:

      For each XML namespace declaration with prefix P and URI U:
      a. If the namespace registry already contains a mapping of some prefix P' to U (where P' may or may not be equal to P) then the namespace registry is left unchanged."

      The code should discover that the default namespace does not match a registered namespace and it should therefore register it and use this for the XML default namespace rather than throw the exception.

      Attachments

        Activity

          People

            rhauch Randall Hauch (Inactive)
            laurent99 Laurent CROS (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: