jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shanmugam Gopal" <haishanmu...@hotmail.com>
Subject Re: FW: Custom Node Types XML
Date Tue, 29 Aug 2006 16:40:49 GMT
Hi,

This works fine..Thanks for your suggestions.
I want to write some more custom nodes extending nt:file and 
nt:unstructured.
I have all the following custom node definitions in a single file.

Once, it is registered, I am not able to add more custom node definitions to 
that file.
It says javax.jcr. NamespaceException. : Mapping already exists.

Also I found that it is not possible to unregister the namesapce.

Then, How can I add additional node definitons that cnd file and register?



>From: "Stefan Guggisberg" <stefan.guggisberg@gmail.com>
>Reply-To: users@jackrabbit.apache.org
>To: users@jackrabbit.apache.org
>Subject: Re: FW: Custom Node Types XML
>Date: Fri, 25 Aug 2006 16:40:11 +0200
>
>On 8/25/06, Shanmugam Gopal <haishanmugam@hotmail.com> wrote:
>>Hai,
>>
>>Yeah..I edited Custom_nodetypes.xml and put that configuration.
>>Ok..I learned from jackrabbit.apache.org that we need to create some cnd
>>file for custom node type
>>and register using CompactNodeTypeDefReader.
>>
>>Now I am facing the following proble. Pls help me to get rid off this. I 
>>am
>>struggling with this problem for past couple of weeks. It will be better, 
>>If
>>we post proper document with comple example.
>>
>>I am trying to create a node like nt:resource with one more property 
>>called
>>jcr:user
>>I saved the following configuration in myappResource.cnd file.
>>
>>[myapp:resource] > mix:referencable
>>- jcr:encoding
>>- jcr:mimeType mandatory
>>- jcr:data (binary) mandatory
>>- jcr:lastModified (date) mandatory ignore
>>- jcr:user
>
>why don't you just extend nt:resource?
>
>e.g.
>
>[myapp:resource] > nt:resource
>- myapp:user (string)
>
>note that you shouldn't use the reserved prefixes (jcr, nt, ...)
>in your own node types.
>
>you can use the following code to register your new node type
>using the above definition:
>
>        NamespaceRegistry nsReg = wsp.getNamespaceRegistry();
>        nsReg.registerNamespace("myapp", "http://www.acme.com/myapp");
>
>        JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
>                session.getWorkspace().getNodeTypeManager();
>        manager.registerNodeTypes(new 
>FileInputStream("myapp_resource.cnd"),
>                JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
>
>
>cheers
>stefan
>
>>
>>I am using the following code to register the custom node.(Got it from
>>apache site).
>>
>>import javax.jcr.Workspace;
>>import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
>>import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
>>import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
>>import 
>>org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
>>import java.io.FileReader;
>>import java.util.List;
>>import java.util.Iterator
>>
>>public class CustomNodeTypeExample {
>>     public static void RegisterCustomNodeTypes(Workspace ws, String
>>cndFileName){
>>         // Read in the CND file
>>         FileReader fileReader = new FileReader(cndFileName);
>>         // Create a CompactNodeTypeDefReader
>>         CompactNodeTypeDefReader cndReader = new
>>CompactNodeTypeDefReader(fileReader, cndFileName);
>>         // Get the List of NodeTypeDef objects
>>         List ntdList = cndReader.getNodeTypeDefs;
>>         // Get the NodeTypeManager from the Workspace.
>>         // Note that it must be cast from the generic JCR NodeTypeManager 
>>to
>>the
>>         // Jackrabbit-specific implementation.
>>         NodeTypeManagerImpl ntmgr
>>=(NodeTypeManagerImpl)ws.getNodeTypeManager();
>>         // Acquire the NodeTypeRegistry
>>         NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry();
>>         // Loop through the prepared NodeTypeDefs
>>         for (Iterator i = ntdList.iterator(); i.hasNext();) {
>>             // Get the NodeTypeDef...
>>             NodeTypeDef ntd = (NodeTypeDef)i.next();
>>             // ...and register it
>>             ntreg.registerNodeType(ntd);
>>         }
>>    }
>>}
>>
>>
>>But I am getting the following exception:
>>org.apache.jackrabbit.core.nodetype.compact.ParseException: Error while
>>parsing 'myapp:resource' (D:\customNode\customNode.cnd, line 1)
>>         at
>>org.apache.jackrabbit.core.nodetype.compact.Lexer.fail(Lexer.java:146)
>>
>>If I use the following XML format
>>
>><?xml version="1.0" encoding="iso-8859-1"?>
>>< nodeTypes xmlns:my="http://www.mycompany/my/1.0";>
>><nodeType name="my:resource"
>>           isMixin="false"
>>           hasOrderableChildNodes="false"
>>           primaryItemName="jcr:data">
>>     <supertypes>
>>         <supertype>nt:base</supertype>
>>         <supertype>mix:referenceable</supertype>
>>     </supertypes>
>>     <propertyDefinition name="jcr:encoding"
>>                         requiredType="String"
>>                         autoCreated="false"
>>                         mandatory="false"
>>                         onParentVersion="COPY"
>>                         protected="false"
>>                         multiple="false"/>
>>
>>     <propertyDefinition name="jcr:mimeType"
>>                         requiredType="String"
>>                         autoCreated="false"
>>                         mandatory="true"
>>                         onParentVersion="COPY"
>>                         protected="false"
>>                         multiple="false"/>
>>
>>     <propertyDefinition name="jcr:data"
>>                         requiredType="Binary"
>>                         autoCreated="false"
>>                         mandatory="true"
>>                         onParentVersion="COPY"
>>                         protected="false"
>>                         multiple="false"/>
>>
>>     <propertyDefinition name="jcr:lastModified"
>>                         requiredType="Date"
>>                         autoCreated="false"
>>                         mandatory="true"
>>                         onParentVersion="IGNORE"
>>                         protected="false"
>>                         multiple="false"/>
>>
>>    <propertyDefinition name="jcr:user"
>>                         requiredType="String"
>>                         autoCreated="false"
>>                         mandatory="true"
>>                         onParentVersion="IGNORE"
>>                         protected="false"
>>                         multiple="false"/>
>></nodeType>
>></nodeTypes>
>>
>>I am getting the following exception
>>org.apache.jackrabbit.core.nodetype.compact.ParseException: Missing = in
>>namespace decl. (D:\customNode\customNode.xml, line 1)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> >From: "Stefan Guggisberg" <stefan.guggisberg@gmail.com>
>> >Reply-To: users@jackrabbit.apache.org
>> >To: users@jackrabbit.apache.org
>> >Subject: Re: FW: Custom Node Types XML
>> >Date: Thu, 24 Aug 2006 15:39:58 +0200
>> >
>> >On 8/24/06, Shanmugam Gopal <haishanmugam@hotmail.com> wrote:
>> >>Hi,
>> >>
>> >>I am trying to create a custom node by extending nt:resource so that I 
>>can
>> >>add some custom properties to that node.
>> >>
>> >>Following is the Custom_nodetypes.xml configuration.
>> >
>> >did you edit custom_nodetypes.xml manually?
>> >
>> >custom_nodetypes.xml is used internally for persisting node types
>> >registered through the api. it's *not* meant to be
>> >user-provided/manipulated
>> >and therefore *not* supported.
>> >
>> >you should use the approproate api (e.g.
>> >org.apache.jackrabbit.api.JackrabbitNodeTypeManager) for registering
>> >custom node types.
>> >
>> >cheers
>> >stefan
>> >
>> >>
>> >><?xml version="1.0" encoding="UTF-8"?>
>> >>
>> >><nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
>> >>xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
>> >>xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
>> >>xmlns:plateau="http://www.apache.org/jackrabbit/plateau"
>> >>xmlns:mix="http://www.jcp.org/jcr/mix/1.0">
>> >><nodeType name="plateau:resource" isMixin="false"
>> >>hasOrderableChildNodes="false" primaryItemName="jcr:data">
>> >>
>> >>      <supertypes>
>> >>
>> >>              <supertype>nt:resource</supertype>
>> >>
>> >>      </supertypes>
>> >>
>> >>      <propertyDefinition name="plateau:username" requiredType="String"
>> >>autoCreated="false" mandatory="false" onParentVersion="COPY"
>> >>protected="false" multiple="false"/>
>> >>
>> >>      <propertyDefinition name="plateau:Author" requiredType="String"
>> >>autoCreated="false" mandatory="false" onParentVersion="COPY"
>> >>protected="false" multiple="false"/>
>> >>
>> >></nodeType>
>> >></nodeTypes>
>> >>
>> >>But I am getting the Following ClassCastException while registering 
>>this
>> >>custom node.
>> >>
>> >>
>> >> >java.lang.ClassCastException
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.util.DOMWalker.iterateElements(DOMWalker.java
>> >> >:219)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader.getNodeTypeDefs(N
>> >> >odeTypeReader.java:118)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader.read(NodeTypeRead
>> >> >er.java:64)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.NodeTypeDefStore.load(NodeTypeDefSto
>> >> >re.java:54)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.loadCustomNodeTypeD
>> >> >efs(NodeTypeRegistry.java:1681)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.<init>(NodeTypeRegi
>> >> >stry.java:210)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.nodetype.NodeTypeRegistry.create(NodeTypeRegi
>> >> >stry.java:123)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.RepositoryImpl.createNodeTypeRegistry(Reposit
>> >> >oryImpl.java:501)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:238
>> >> >)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:514
>> >> >)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.j2ee.RepositoryStartupServlet.createRepository(Rep
>> >> >ositoryStartupServlet.java:301)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.j2ee.RepositoryStartupServlet.initRepository(Repos
>> >> >itoryStartupServlet.java:272)
>> >> >
>> >> >         at
>> >> 
>> >org.apache.jackrabbit.j2ee.RepositoryStartupServlet.init(RepositoryStart
>> >> >upServlet.java:189)
>> >> >
>> >> >         at 
>>javax.servlet.GenericServlet.init(GenericServlet.java:211)
>> >>
>> >>
>> >>
>> >>Is there any wrong with the custom node definition ??
>> >>
>> >>Regards,
>> >>Shanmugam G
>> >>
>> >>_________________________________________________________________
>> >>Shah Rukh fan? Know all about the Baadshah of Bollywood. On MSN Search
>> >>http://server1.msn.co.in/profile/shahrukh.asp
>> >>
>> >>
>>
>>_________________________________________________________________
>>Spice up your IM conversations. New, colorful and animated emoticons. Get
>>chatting! http://server1.msn.co.in/SP05/emoticons/
>>
>>

_________________________________________________________________
Spice up your IM conversations. New, colorful and animated emoticons. Get 
chatting! http://server1.msn.co.in/SP05/emoticons/


Mime
View raw message