>>>
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?
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);
}
}
|