Create Document using Java API

View: New views
2 Messages — Rating Filter:   Alert me  

Create Document using Java API

by jiveforums-ecm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am in the process of creating a document using Nuxeo. I am using the EJB Remote API.

Following is the method that i use to do the create document.

CoreSession session = getDocumentManager();
DocumentModel ws = session.getDocument(new PathRef(
                                "/default-domain/workspaces/test"));
String name = "TestEJBAPI_demo3";
DocumentModel dm = new DocumentModelImpl(ws.getPathAsString(), name, "File");
dm.setProperty("dublincore", "title", name);
dm.setProperty("file", "filename", name);
File file = new File("c:/test.doc");
InputStreamSource src = new InputStreamSource(new FileInputStream(file));
StreamingBlob streamingBlob = new StreamingBlob(src,
                                "application/msword");
dm.setProperty("file", "content", streamingBlob);
session.createDocument(dm);
session.save();

But while executing this i am getting exceptions at each setproperty step as mentioned below:

java.lang.NullPointerException
        at org.nuxeo.runtime.api.Framework.getLocalService(Framework.java:181)
        at org.nuxeo.ecm.core.schema.TypeRef.load(TypeRef.java:102)
        at org.nuxeo.ecm.core.schema.TypeRef.get(TypeRef.java:74)
        at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.hasSchema(DocumentModelImpl.java:707)
        at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.loadDataModel(DocumentModelImpl.java:459)
        at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.getDataModel(DocumentModelImpl.java:499)
        at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.setProperty(DocumentModelImpl.java:697)
        at com.nuxeo.test.SampleEJB3Client.createDocument(SampleEJB3Client.java:189)
        at com.nuxeo.test.SampleEJB3Client.main(SampleEJB3Client.java:175)


Also i want to know on how to add custom properties to a Document.

Thanks in advance.

Regards
Ajai G
--
Posted by "ajaiking" at Nuxeo Discussions <http://nuxeo.org/discussions>
View the complete thread: <http://www.nuxeo.org/discussions/thread.jspa?threadID=2599#7323>
_______________________________________________
ECM mailing list
ECM@...
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm

Re: Create Document using Java API

by jiveforums-ecm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is an sample that may help you :
http://doc.nuxeo.org/xwiki/bin/view/FAQ/SampleRemoteJava

About creating new properties, you have to define a new schema containing them, then define a new doctype using this schema; these are done with contributions (XML stuff), on the server side. All is well explained in the reference :
http://doc.nuxeo.org/5.2/books/nuxeo-book/html/documents.html
--
Posted by "wanKA" at Nuxeo Discussions <http://nuxeo.org/discussions>
View the complete thread: <http://www.nuxeo.org/discussions/thread.jspa?threadID=2599#7325>
_______________________________________________
ECM mailing list
ECM@...
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm