Jackrabbit File Upload Download

Source: Internet
Author: User

1. In the configuration file config.properties: File.rmi=http://localhost:7000/rmi

2. Download Jackrabbit-standalone-2.10.1.jar, open the service:java -jar Jackrabbit-Standalone-2.1. 0.jar --Port 7000

3.

 Public classJackrabbitfileserviceimplImplementsFileservice {Private StaticRepository Repository;  Public Staticsession Initsession () {Session session=NULL; if(NULL==repository) {            Try{Repository=NewUrlremoterepository (Readconfig.getvalue ("File.rmi")); } Catch(malformedurlexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        }        Try{Session=repository.login (NewSimplecredentials ("admin", "admin". ToCharArray ())); } Catch(loginexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(repositoryexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        returnsession; } @Override PublicString Save (InputStream is,Longfilesize) {String FileId=Keyprovider.getprimarykey (); Try{Session Session=initsession (); Node Root=Session.getrootnode (); String MimeType= "Application/octet-stream"; Node Filenode= Root.addnode (FileId, "Nt:file"); Node Resnode= Filenode.addnode ("Jcr:content", "Nt:resource"); Resnode.setproperty ("Jcr:mimetype", MimeType); Resnode.setproperty ("Jcr:encoding", "" "); Resnode.setproperty ("Jcr:data", is); Calendar lastmodified=calendar.getinstance (); Resnode.setproperty ("Jcr:lastmodified", lastmodified);            Session.save ();            Is.close ();        Session.logout (); }Catch(Exception e) {e.printstacktrace (); }        returnfileId; } @Override PublicInputStream Getfilebyid (String fileId) {InputStream is=NULL; Try{Session Session=initsession (); Node Root=Session.getrootnode (); if(root!=NULL) {Nodeiterator filenodes=root.getnodes (fileId);  while(Filenodes.hasnext ()) {Node n=Filenodes.nextnode (); Nodeiterator Ni1=n.getnodes ();  while(Ni1.hasnext ()) {Node N1=Ni1.nextnode (); if(N1.getname (). Equals ("Jcr:content") ) { is= N1.getproperty ("Jcr:data"). GetStream ();        }}}} session.logout (); }Catch(Exception e) {e.printstacktrace (); }        returnis ; }    }



Jackrabbit File Upload Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.