You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by Apache Wiki <wi...@apache.org> on 2005/07/08 20:55:38 UTC

[Jackrabbit Wiki] Update of "ExamplesPage" by RobertRitchy

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jackrabbit Wiki" for change notification.

The following page has been changed by RobertRitchy:
http://wiki.apache.org/jackrabbit/ExamplesPage

New page:
= Examples Page =


This page will be used to show solutions to common problems related to JSR 170.


'''Importing a File'''
{{{
    public Node importFile (Node folderNode, File file, String mimeType,
            String encoding) throws RepositoryException, IOException
    {
        //create the file node - see section 6.7.22.6 of the spec
        Node fileNode = folderNode.addNode (file.getName (), "nt:file");
        
        //create the manditory child node - jcr:content
        Node resNode = fileNode.addNode ("jcr:content", "nt:resource");
        resNode.setProperty ("jcr:mimeType", mimeType);
        resNode.setProperty ("jcr:encoding", encoding);
        resNode.setProperty ("jcr:data", new FileInputStream (file));
        Calendar lastModified = Calendar.getInstance ();
        lastModified.setTimeInMillis (file.lastModified ());
        resNode.setProperty ("jcr:lastModified", lastModified);

        return fileNode;
    }
}}}