Marcel, thanks!
I can now get baxck my MS-Word file!
an optional encoding when supported by the mime type

How can I find out which mime type supports and/or requires which encoding? Does the JCR-API support me here?

Thanks for help,
Dirk

BTW: Is there a comprehensive demo application I can have a look at to further endeepen my JCR knowledge ?

docResourceNode.setProperty("jcr:mimeType", docMimeType);
        //resourceNode.setProperty("jcr:encoding", ""); //Needed?

Am 24.04.2006 um 08:46 schrieb Marcel Reutegger:

Dirk V. Schesmer wrote:

Hi All,
I'd like to ask for help telling me how I can extract the content of file testwordfile.doc and save it in the local file system. I am already able to save it successfully into my jackrabbit repository using the addDocFile() method below. Also, I can find it using the saveDocMethod() also shown below. But how to extract the content, to determine e.g. the mime type and to set the encoding needed to save it successfully?

an nt:resource is just a binary stream and may have an optional encoding when supported by the mime type. e.g. a word document will not have an encoding, but a plain text file will have one.

to read the document from the repository you simply navigate to the binary data property and get the value as an input stream:

Node resource = ...
InputStream in = resource.getProperty("jcr:data").getStream();
// now spool the stream to a local file...


regards
 marcel

Any help appreciated!
Dirk V. Schesmer
Stuttgart/Germany
-------
public void addDocFile(Node root, Session session) throws Exception {
        Node folderNode = root.addNode("foldernode", "nt:folder");
        File docFile = new
File("/Users/dschesmer/jackrabbitJCR/ testdocuments/testwordfile.doc");
        Node docFileNode = folderNode.addNode(docFile.getName(),
                                              "nt:file");
        String docMimeType = "application/msword";
        Node docResourceNode = docFileNode.addNode("jcr:content",
                "nt:resource");
        docResourceNode.setProperty("jcr:mimeType", docMimeType);
        //resourceNode.setProperty("jcr:encoding", ""); //Needed?
        docResourceNode.setProperty("jcr:data", new
                                    FileInputStream(docFile));
        Calendar docLastModified = Calendar.getInstance();
        docLastModified.setTimeInMillis(docFile.lastModified());
docResourceNode.setProperty("jcr:lastModified", docLastModified);
        session.save();
    }
public void saveDocFile(Node root, Session session) throws Exception {
        //Now do my test search
        Workspace workspace = session.getWorkspace();
        QueryManager queryManager = workspace.getQueryManager();
        Query query =
                queryManager.createQuery(
                        "/jcr:root/foldernode//*", Query.XPATH);
        QueryResult result = query.execute();
        NodeIterator niter = result.getNodes();
        while (niter.hasNext()) {
            Node n = niter.nextNode();
// toDo: extract word doc and save it into the file system...
            System.out.println("node: "+n);
        }
    }


Reply via email to