6 Replies Latest reply on May 30, 2010 5:14 PM by bcarothers

    Registering Namespaces in config file

    androbit

      Hello Community,

      After setting up a repositoy I tried to use the image sequencer in my current project, but I am not able to register the "image" prefix. The sequencer is throwing this:

       

      org.modeshape.graph.property.NamespaceException: There is no namespace  registered for the prefix "image"
      

       

      Am I using the

      <mode:namespaces>
      

      Tag wrong (seeconfig below) ? I adapted the use from the repositories example.

       

      I also tried to register via code with

      session.getWorkspace().getNamespaceRegistry().registerNamespace("image", "http://www.modeshape.org/images/1.0");
      

       

      but thats not working either.  There are no other error log entries besides the exeption.

       

      Could somebody clear this up for me? How to register a namespace properly?

      Thanks for reading!

       

       

      <mode:sequencers>
              <mode:sequencer jcr:name="Image Sequencer" mode:classname="org.modeshape.sequencer.image.ImageMetadataSequencer">
                  <mode:description>Image metadata sequencer</mode:description>        
                  <mode:pathExpression>//(*.(jpg|jpeg|gif|bmp|pcx|png)[*])/jcr:content[@jcr:data] => /images/$1</mode:pathExpression>
              </mode:sequencer>
          </mode:sequencers>
      
      
          <!-- Define the JCR repositories -->
          <mode:repositories>
              <!-- Specify the source that should be used for the repository -->
              <mode:repository jcr:name="cleanAtticRepository">
                  <mode:source>repositorySource</mode:source>
                  <!-- Define the options for the JCR repository, using camelcase version of JcrRepository.Option names-->
                  <mode:options jcr:primaryType="mode:options">
                      <mode:projectNodeTypes jcr:primaryType="mode:option" mode:value="false"/>
                  </mode:options>
                  <mode:nodeTypes mode:resource="sequencer.cnd" />
              <mode:namespaces jcr:primaryType="mode:namespaces">
                      <image jcr:primaryType="mode:namespace" mode:uri="http://www.modeshape.org/images/1.0" />
                  </mode:namespaces>
              </mode:repository>
          </mode:repositories>
      
        • 1. Re: Registering Namespaces in config file
          bcarothers

          What you did does not work, but I think that it should.

           

          ModeShape basically has a tree of namespace registries that handle the translation from prefixes to URIs and back.  There's a top-level namespace registry at the JcrEngine level and separate registries for each JCR repository.  The repository registries are based on the top-level registry but can also add additional mappings that only apply to that repository.

           

          When you add namespaces to the repository (with the mode:namespaces tag), you are adding them in the namespace registry for that repository only.  But sequencers use the top-level repository.  That's why your sequencer doesn't recognize the mapping.  I suspect that the other error that you're seeing when you try to register from JCR is because that prefix is already mapped.

           

          I suspect that this behavior will be changed in trunk in the next few days, but in the meantime, a workaround is to add some code like this to wherever you initialize your JcrEngine:

           

          JcrConfiguration config = ...;

          JcrEngine engine = config.loadFrom(...).build();

           

          String uri = ...;

          engine.getExecutionContext().getNamespaceRegistry().register("image", uri);

           

          Once you do this, you can comment out the mode:namespaces section from your configuration file for now.

           

          So, in short, you're not wrong - this should work.  Thanks for catching this!

          • 2. Re: Registering Namespaces in config file
            androbit

            Thanks for clearing this up, good to know whats happening!

             

            I am getting the JCR repository from JNDI and I dont want to introduce modeshape as dependency at the moment, so I can't use the workaround.

            Is there already an issue for this? I will work with the trunk as soon as its fixed.

            • 3. Re: Registering Namespaces in config file
              bcarothers

              I've created MODE-771 to track a fix to this issue.  It should be in trunk sometime between tomorrow morning (EST) and Monday morning (EST).

              • 4. Re: Registering Namespaces in config file
                bcarothers

                I committed the MODE-771 changes to trunk a few minutes ago.  Please let me know if this resolves your problem.  Thanks!

                • 5. Re: Registering Namespaces in config file
                  androbit

                  Thank you very much! I built modeshape from trunk today and its sequencing my uploaded images now . I appreciate your fast response and support!

                  • 6. Re: Registering Namespaces in config file
                    bcarothers

                    Good deal.  Thanks for the feedback!