jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: Accessing Word and PDF Content
Date Mon, 24 Apr 2006 06:46:52 GMT
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);
>         }
>     }
> 
> 


Mime
View raw message