jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shrimpywu <imx...@gmail.com>
Subject question about how to provide download link after save file into JCR
Date Tue, 30 Sep 2008 02:42:23 GMT

question about how to provide download link after save file into JCR

i wrote a function to save binary file,  but after i save the file. how can
i get the file????????

[code]
public String saveFile(final File file, final String mimeType, final String
encoding, final User user) {
        return (String) execute(new JcrCallback() {

            public Object doInJcr(Session session) throws IOException,
RepositoryException {

                checkUserFolder(user, session);

                Node root = session.getRootNode();

                JcrConstants jcrConstants = new JcrConstants(session);

                //create the file node 
                Node fileNode =
root.getNode(USER_FOLDER_PREFIX).getNode(user.getUsername()).addNode(file.getName(),
jcrConstants.getNT_FILE());

                //create the mandatory child node - jcr:content
                Node resourseNode =
fileNode.addNode(jcrConstants.getJCR_CONTENT(),
jcrConstants.getNT_RESOURCE());

                resourseNode.setProperty(jcrConstants.getJCR_MIMETYPE(),
mimeType);
                resourseNode.setProperty(jcrConstants.getJCR_ENCODING(),
encoding);
                resourseNode.setProperty(jcrConstants.getJCR_DATA(), new
FileInputStream(file));
                Calendar lastModified = Calendar.getInstance();
                lastModified.setTimeInMillis(file.lastModified());
                resourseNode.setProperty(jcrConstants.getJCR_LASTMODIFIED(),
lastModified);

                session.save();

               
log.debug(resourseNode.getCorrespondingNodePath(session.getWorkspace().getName()));
                return resourseNode.getPath();
            }
        });
    }
[/code]

Here is the bean i used to inject into spring.
[code]
<bean id="repository"
        class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
        <property name="configuration" value="classpath:/repository.xml" />
        <property name="homeDir" value="file:./target/repo" />
    </bean>
[/code]

-- 
View this message in context: http://www.nabble.com/question-about-how-to-provide-download-link-after-save-file-into-JCR-tp19735243p19735243.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message