4 Replies Latest reply on Aug 18, 2011 3:17 AM by Danny C

    How to add custom properties to File System Node (ie. nt:file or nt:folder) via Mixin

    Danny C Newbie



              How do we actually add custom properties for example "tags" to a File System Node (of type nt:file or nt:folder) via Mixin ? I have already turned on extraPropertiesBehavior to "store" and I can get and list all the nodes inside the repository("myrepofs") and I can see ".modeshape" files are created. But when I am trying to add custom properties to a nt:file node,  I keep getting some errors with the configuration xml ,mixin cnd, codes as shown below:


               Anyone, Pls help ! I plan to use Modeshape for my project but I am really stuck here. Thank in advance.



      - I am using Modeshape 2.6.0 Beta 2 and currently focus using it for FileSystem store only.

      - I am following the tutorial at --> http://modeshape.wordpress.com/2010/09/01/custom-properties-on-ntfile-and-ntfolder-nodes/ 

      - I am testing this using just a local java program after managed to pull in all required Jar libraries (not within any Jboss As 7) for simplicity.

      - The official Modeshape 2.6.0 Beta 2 example programs run well and OK in the same environment. But the examples just doesn't show how to add custom properties.





      <?xml version="1.0" encoding="UTF-8"?>

      <configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">


           <mode:sources jcr:primaryType="nt:unstructured">

                <mode:source jcr:name="FILESYSTEM Store"


                            mode:description="The repository for our content"







                            mode:updatesAllowed="true" >






                <mode:repository jcr:name="myrepofs">

                     <mode:source>FILESYSTEM Store</mode:source>


                      <mode:nodeTypes jcr:primaryType="mode:nodeTypes">

                           <jcr:nodeTypes mode:resource="/acme.cnd" />



                      <namespaces jcr:primaryType="mode:namespaces">

                           <acme jcr:primaryType="mode:namespace" mode:uri="http://www.modeshape.org/examples/acme/1.0"/>











      [acme:taggable] mixin

      - acme:tags (STRING) multiple


      [acme:checksum] mixin

      - acme:sha1 (STRING) mandatory






              String configUrl = "file:///C:/test/configRepository.xml?repositoryName=myrepofs";

              Map<String, String> parameters = Collections.singletonMap("org.modeshape.jcr.URL", configUrl);

              Repository repository = null;

              Session session = null;


                //Get Repository - OK

                 for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {

                      repository = factory.getRepository(parameters);

                      if (repository != null) {





                  //Login to Repository without any credentials - OK

                  session = repository.login();


                  //Get Node - OK

                  Node node = session.getNode("/folder1/hello.txt");  //OK - This file is in the file system store

                  printNodeInfo(node);   //OK and it dump out the node info as expected


                 //Try to Add extra property via Mixin

                  node.addMixin("acme:taggable");  <----------------------FAIL ! Program stop here (Pls refer to Errors dump below)

                  String[] tags = {"non-work"};



                 //Save and logout






      14:03:42,123  INFO Completed starting the "myrepofs" repository


      Exception in thread "main" org.modeshape.graph.property.ValueFormatException: Error converting String to a Name: acme:taggable

          at org.modeshape.graph.property.basic.NameValueFactory.create(NameValueFactory.java:130)

          at org.modeshape.graph.property.basic.NameValueFactory.create(NameValueFactory.java:83)

          at org.modeshape.graph.property.basic.NameValueFactory.create(NameValueFactory.java:55)

          at org.modeshape.jcr.JcrNodeTypeManager.getNodeType(JcrNodeTypeManager.java:133)

          at org.modeshape.jcr.AbstractJcrNode.addMixin(AbstractJcrNode.java:1152)

          at test.Test5FS.main(Test5FS.java:79)

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

          at org.modeshape.graph.property.basic.NameValueFactory.create(NameValueFactory.java:116)

          ... 5 more