From users-return-9112-apmail-jackrabbit-users-archive=jackrabbit.apache.org@jackrabbit.apache.org Tue Sep 30 09:22:26 2008 Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 43112 invoked from network); 30 Sep 2008 09:22:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Sep 2008 09:22:26 -0000 Received: (qmail 24279 invoked by uid 500); 30 Sep 2008 09:22:22 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 24014 invoked by uid 500); 30 Sep 2008 09:22:21 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 24003 invoked by uid 99); 30 Sep 2008 09:22:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Sep 2008 02:22:21 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of douglasjose@gmail.com designates 209.85.198.233 as permitted sender) Received: from [209.85.198.233] (HELO rv-out-0506.google.com) (209.85.198.233) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Sep 2008 09:21:18 +0000 Received: by rv-out-0506.google.com with SMTP id k40so2990013rvb.31 for ; Tue, 30 Sep 2008 02:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=YierAp1MKjwD8fyhsz5XiDvESK67MwWjasX7/QA9P4U=; b=Ku0tc7WvJue55+6LT/4oheujQOeojfhY+CyUDdKJ/RfLGlOWzaOH252sfyKZwiGXhi xi8qhllSCfXQEkRrsEXF7uymwu5T7AqAvMORuS1TlyAHk1sQoWSUa3M/qDqKzb5yF8lE XbfFFrhWX7StOKF0WsnZ12kx3nlUmpdnTN62A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=ZEIVELIB85rhNuaopPdQJ8VxHUZYr/KXOXtV6O4dhzfgPynLSr2jX2RljCGvrsZs4v lOIbhDeE3u+grN3uXCuR4PgA/MgTSSMDVw+A595j2K8AVkBjUqthKbXQW7NRxmJFTyt+ T1Eeba6C5xUcv+hIzkIskEVp51Q8eQ9GxsE7k= Received: by 10.141.105.18 with SMTP id h18mr3212865rvm.207.1222766511393; Tue, 30 Sep 2008 02:21:51 -0700 (PDT) Received: by 10.141.19.15 with HTTP; Tue, 30 Sep 2008 02:21:51 -0700 (PDT) Message-ID: <2adfc1e90809300221t38aa03baj85b2c2f147dc3e37@mail.gmail.com> Date: Tue, 30 Sep 2008 11:21:51 +0200 From: "=?ISO-8859-1?Q?Douglas_Jos=E9?=" To: users@jackrabbit.apache.org Subject: Re: question about how to provide download link after save file into JCR In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <19735243.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Hello Alexander and shrimpywu, Not satisfied with using WebDAV to download a file from my repository (I could not easily prevent the user from being prompted for credentials), I wrote my own download servlet (the option 2 suggested by Alexander). Following is the source code. To use it, you just need to render a link to the servlet mapping, appending the path in your repository to the node to be downloaded. Regards, Douglas package br.com.hapkidocontato.site.presentation; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.apache.commons.io.IOUtils; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.jcr.Session; import javax.jcr.Item; import javax.jcr.RepositoryException; import javax.jcr.Node; import java.io.IOException; import java.io.InputStream; import br.com.hapkidocontato.site.business.repository.RepositoryConfigurator; /** * @author Douglas Rodrigues */ public class RepositoryDownloadServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); Session session = ((Session) ctx.getBean("jcrSession")); String path = request.getPathInfo(); try { Node node = (Node) session.getItem(path); if (!node.getPrimaryNodeType().getName().equalsIgnoreCase("nt:file")) { throw new ServletException("Impossible to download from nodetype " + node.getPrimaryNodeType().getName() + ". Only nt:file accepted."); } InputStream is = node.getNode("jcr:content").getProperty("jcr:data").getValue().getStream(); IOUtils.copy(is, response.getOutputStream()); } catch (RepositoryException e) { throw new ServletException("Error reading content", e); } } } On Tue, Sep 30, 2008 at 9:20 AM, Alexander Klimetschek wrote: > > You could use the WebDav server [1] (use the SimpleWebdavServlet) that > comes with the jackrabbit-webapp to access the repository over > Http/Webdav. > > Or you could program your own servlet that reads the file data using > the JCR API and provides it over HTTP. > > Regards, > Alex > > [1] http://jackrabbit.apache.org/jackrabbit-jcr-server.html > > On Tue, Sep 30, 2008 at 4:42 AM, shrimpywu wrote: > > > > 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] > > > class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean"> > > > > > > > > [/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. > > > > > > > > -- > Alexander Klimetschek > alexander.klimetschek@day.com -- Douglas Jose http://douglasjose.com - "Use free software. Help us make a free world."