jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mila Yuliani <mila.yuli...@meruvian.org>
Subject How to upload image from jackrabbit
Date Wed, 14 Apr 2010 01:23:26 GMT
Hi all,

I have problem of my jackrabbit..:(
i'm new in jackrabbit for upload and display content. i'm using velocity for
view from client. my case is for upload photo and display photo from
repository node jcr. here the code :

 1. formRegister.vm :
 ...
             <tr>
               <td width="25%" height="26" align="right"
class="tdleft">Upload Photo :&nbsp;&nbsp;</td>
               <td class="tdright">&nbsp;&nbsp;<input type="file" size="23"
name="docUpload" value="$!employee.docUpload"></td>
             </tr>
 ...

 2. class Pojo is named Employee.java :
 ...
     private String docUpload="";
     private String docUploadName="";
     private String docUploadPath="";

 3. SaveEmployee.java for saving into database and repository jcr :
     private File docUpload;
     private String docUploadFileName;
    private String docUploadContentType;

     public String execute(){
              if(docUpload != null) {
                 employee.setDocUploadName(docUploadFileName);
                 employee.setDocUploadPath(docUpload.getPath());
                 try {
                     repoManager.importFile(repoManager.getRootNode(),
docUpload, getId());
                     repoManager.save();
                 } catch (RepositoryException e) {
                     e.printStackTrace();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
             manager.save(employee);

 4. this RepositoryDao for Data Access Object Jackrabbit:

      public void importFile(Node parentnode, File file, String key) throws
RepositoryException, IOException {
         String mimeType = new MimetypesFileTypeMap().getContentType(file);
         if (mimeType==null) mimeType="application/octet-stream";

         Node fileNode = parentnode.addNode(key, "nt:file");

         Node resNode = fileNode.addNode("jcr:content", "nt:resource");
         resNode.addMixin("mix:versionable"); //set node mixin type
         //resNode.setProperty("jcr:versionLabels", file.getName());
         resNode.setProperty("jcr:mimeType", mimeType);
         resNode.setProperty("jcr:encoding", "");
         resNode.setProperty("jcr:data", new FileInputStream(file));
         Calendar lastModified = Calendar.getInstance();
         lastModified.setTimeInMillis(file.lastModified());
         resNode.setProperty("jcr:lastModified", lastModified);

     }

    public void save()
     throws AccessDeniedException, ItemExistsException,
ConstraintViolationException,
            InvalidItemStateException, VersionException, LockException,
            NoSuchNodeTypeException, RepositoryException {
         jcrSession.save();
     }

 5. here is from database :
 DocUploadName : screenshot-2.png
 DocUploadPath   :
/home/Documents/mils/workspace/Papaje/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/cimeng/upload_66774dc6_127f8062761__8000_00000023.tmp

 that's mean is data has upload successfully into database, right?
 so, how i can get image name from docUploadName and it's from repository
node jackrabbit.

 Correct me if I'm wrong..:)

-- 
Best Regards,

Mila Yuliani
Developer Blueoxygen Workspace
Meruvian - Indonesia
Office Phone : (021)935 865 77
Mobile : 02199869875

Mime
View raw message