I have some doubts about retrieving a pdf file from Jackrabbit.
Currently I stored a PDF file in Jackrabbit like this:
File newFile = new File("d:\\BIRTRefCard.pdf");
Repository repository = null;
Session session = null;
try {
repository = new TransientRepository();
//jackrabbit's default JAAS LoginModule (SimpleLoginModule) is just a dummy
//implementation which only distinguishes between anonymous/non-anonymous
//login's. any non-anonymous login has full read/write permissions.
session = repository.login(new
SimpleCredentials("johndoe","password".toCharArray()));
Node root = session.getRootNode();
Node fileNode = root.addNode(newFile.getName(), "nt:file");
//create the mandatory child node - jcr:content
Node resNode = fileNode.addNode("jcr:content", "nt:resource");
InputStream in = new FileInputStream(newFile);
resNode.setProperty("jcr:mimeType", "application/pdf");
resNode.setProperty("jcr:data", in);
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(newFile.lastModified());
resNode.setProperty("jcr:lastModified", lastModified);
session.save();
} catch (LoginException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
session.logout();
}
But how can I get the pdf file back from the system?
I tried something like the code below but I am not sure if it is the correct
way. I want to stream this pdf to the client
Node root = session.getRootNode();
Node content = root.getNode("BIRTRefCard.pdf/jcr:content");
final InputStream in = content.getProperty("jcr:data").getStream();
final String mime = content.getProperty("jcr:mimeType").getString();
.....
Pls help.
Thanks in advance
________________________________
The information contained in this communication is confidential, intended
solely for the use of the individual or entity to whom it is addressed and may
be legally privileged and protected by professional secrecy. Access to this
message by anyone else is unauthorized. If you are not the intended recipient,
any disclosure, copying, or distribution of the message, or any action or
omission taken by you in reliance on it is prohibited and may be unlawful.
Please immediately contact the sender if you have received this message in
error. This email does not constitute any commitment from Cordys Holding BV or
any of its subsidiaries except when expressly agreed in a written agreement
between the intended recipient and Cordys Holding BV or its subsidiaries.
Cordys is neither liable for the proper and complete transmission of the
information contained in this communication nor for any delay in its receipt.
Cordys does not guarantee that the integrity of this communication has been
maintained nor that the communication is free of viruses, interceptions or
interference. If you are not the intended recipient of this communication
please return the communication to the sender and delete and destroy all copies.