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

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

    penkween

      Hi,

               

              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.

       

      Notes:

      - 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.

       

       

      RepositoryConfig.xml

      =====================================================================================================

      <?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:classname="org.modeshape.connector.filesystem.FileSystemSource"

                            mode:description="The repository for our content"

                            mode:workspaceRootPath="./repofs"

                            mode:defaultWorkspaceName="workspace1"

                            mode:creatingWorkspacesAllowed="false"

                            mode:extraPropertiesBehavior="store"

                            mode:exclusionPattern="^.*\.modeshape$"

                            mode:rootNodeUuid="fd129c12-81a8-42ed-aa4b-820dba49e6f1"

                            mode:updatesAllowed="true" >

                </mode:source>

           </mode:sources>

       

       

           <mode:repositories> 

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

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

       

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

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

                      </mode:nodeTypes>

       

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

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

                      </namespaces>

       

                </mode:repository>

          </mode:repositories>

       

      </configuration>

       

       

      acme.cnd

      =====================================================================================================

      [acme:taggable] mixin

      - acme:tags (STRING) multiple

       

      [acme:checksum] mixin

      - acme:sha1 (STRING) mandatory

       

       

       

      Codes

      ======================================================================================================

              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) {

                          break;

                      }

                  }

       

                  //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"};

                  node.setProperty("acme:tags",tags);

       

                 //Save and logout

                  session.save();

                  session.logout();

       

      Errors

      ======================================================================================================

      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