AnsweredAssumed Answered

Issues while using custom content types.

Question asked by amit_wmw@yahoo.com on Apr 3, 2009
Hello,

I have created a very simple custom content model, scModel.xml (in C:\Alfresco\tomcat\shared\classes\alfresco\extension).

<model name="sc:somecomodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

<!– Optional meta-data about the model –>
<description>Someco Model</description>
<author>Optaros</author>
<version>1.0</version>
<!– Imports are required to allow references to definitions in other models –>
<imports>
<!– Import Alfresco Dictionary Definitions –>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!– Import Alfresco Content Domain Model Definitions –>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
</imports>
<!– Introduction of new namespaces defined by this model –>
<namespaces>
<namespace uri="http://www.someco.com/model/content/1.0" prefix="sc" />
</namespaces>

<types>
<!– Enterprise-wide generic document type –>
<type name="sc:doc">
<title>Someco Document</title>
<parent>cm:content</parent>
</type>
<type name="sc:marketingDoc">
<title>Someco Marketing Document</title>
<parent>sc:doc</parent>
</type>

</types>
</model>

And have registered this model in example-model-context.xml as below (in C:\Alfresco\tomcat\shared\classes\alfresco\extension).

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <!– Registration of new models –>   
   

   <bean id="extension1.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/scModel.xml</value>
            
            </list>
        </property>
    </bean>

</beans>

But I am unable to use it in my java code. While trying to add new node it gives me exception.

Node rootNode = session.getRootNode();
         
         Node companyHome = rootNode.getNode("app:company_home");
      
           // create the content node
                   
           Node newnode = companyHome.addNode("sc:"+ document.getName(),"sc:doc");

After executing this code I get below errors:

11:17:09,095 INFO  [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
error while creating nodes org.alfresco.service.namespace.NamespaceException: [color=#FF0000]Namespace prefix sc is not mapped to a namespace URI[/color]org.alfresco.service.namespace.NamespaceException: Namespace prefix sc is not mapped to a namespace URI
   at org.alfresco.service.namespace.QName.createQName(QName.java:103)
   at org.alfresco.service.namespace.QName.createQName(QName.java:125)
   at org.alfresco.jcr.item.JCRPath$SimpleElement.<init>(JCRPath.java:118)
   at org.alfresco.jcr.item.JCRPath.<init>(JCRPath.java:70)
   at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:152)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:138)
   at $Proxy85.addNode(Unknown Source)
   at org.hcl.grcmip.workflow.document.jcr.impl.JCRTemplateImpl.save(JCRTemplateImpl.java:63)
   at org.hcl.grcmip.workflow.document.vo.impl.Main.main(Main.java:30)

Please suggest how should I go about it. I am quite stuck.

Thanks
Amit.

Outcomes