Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 47364 invoked from network); 13 Aug 2007 09:19:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Aug 2007 09:19:09 -0000 Received: (qmail 37223 invoked by uid 500); 13 Aug 2007 09:19:07 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 37160 invoked by uid 500); 13 Aug 2007 09:19:07 -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 37145 invoked by uid 99); 13 Aug 2007 09:19:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Aug 2007 02:19:06 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of stefan.guggisberg@gmail.com designates 209.85.128.190 as permitted sender) Received: from [209.85.128.190] (HELO fk-out-0910.google.com) (209.85.128.190) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Aug 2007 09:19:05 +0000 Received: by fk-out-0910.google.com with SMTP id b27so1631527fka for ; Mon, 13 Aug 2007 02:18:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fsOqrSGhnYh393INhbfqJ1/univXAZ7Bw06aNqmWhaTKFECX6CMmhAg6jEazZcMPfr/YPKJiRUraM8qp9W5XNzTRF85Wwn/y3FD/JI+vvGKycvJcDGq7gOk2flhxnw9VMznCeTcdGMBP7z5K9mPFiyd3Bx6xKte6Ijk9IIXQyWI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=NWp4oizJXv2RdMYjG5lHwsteMTrR0Yv3Pkcp36JUug19yfHcZlvU45/CrR8+ifhlDl4+GsPFF53UWP2JtWBlyCrKJxF8veHQVcT6JJDmw8c4FR2doi17o8XFYQ5XyFuftWxD6Ahh6DKXfA0AzT9Y7/XslezsRStT1rzTJnms0nI= Received: by 10.82.178.11 with SMTP id a11mr3449169buf.1186996723970; Mon, 13 Aug 2007 02:18:43 -0700 (PDT) Received: by 10.82.158.11 with HTTP; Mon, 13 Aug 2007 02:18:43 -0700 (PDT) Message-ID: <90a8d1c00708130218l187c245fsc1795be0d48ff69b@mail.gmail.com> Date: Mon, 13 Aug 2007 11:18:43 +0200 From: "Stefan Guggisberg" To: users@jackrabbit.apache.org Subject: Re: Problem with saving binary node data In-Reply-To: <46C01DDB.1090800@planet.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46BC68DA.2080900@planet.nl> <46C01DDB.1090800@planet.nl> X-Virus-Checked: Checked by ClamAV on apache.org On 8/13/07, Nick Stolwijk wrote: > Sometimes friday is not the best day to debug. I've been looking at my > code this morning and found the problem. > > First this line: > > contentNode.setProperty(NODE_PROP_TYPE_DATA, new > FileInputStream(file)); > > and a few lines later: > > contentNode.setProperty(NODE_PROP_TYPE_DATA, ""); > > And wondering why it would keep empty. :D hehe, well, i didn't spot it neither ;) cheers stefan > > Thanks, > > Nick Stolwijk > > Nick Stolwijk wrote: > > We have a problem with Jackrabbit 1.3.1. All the directory and file > > nodes get created, only my files stay empty. Can somebody help me with > > this problem? My code: > > > > public static final String NODE_PROP_TYPE_FOLDER = "nt:folder"; > > public static final String NODE_PROP_TYPE_FILE = "nt:file"; > > public static final String NODE_PROP_TYPE_DATA = "jcr:data"; > > public static final String NODE_PROP_MIME_TYPE = "jcr:mimeType"; > > public static final String NODE_PROP_TYPE_CONTENT = "jcr:content"; > > public static final String NODE_PROP_TYPE_RESOURCE = "nt:resource"; > > public static final String NODE_PROP_LAST_MODIFIED = > > "jcr:lastModified"; > > public static final String NODE_PROP_CREATED = "jcr:created"; > > public static final String NODE_PROP_ENCODING = "jcr:encoding"; > > > > /** > > * Method importFile imports the specified file to the location > > specified by the node path into the JCR. > > * > > * @param file of type File the file to import into the JCR > > * @param relativeSubNode of type String a nodePath relative to the > > configured rootName which should not start or end with a "/" > > * @param relativeNodePath of type String a nodePath relative to > > the specified sub node which should not start or end with a "/" > > * @throws JackrabbitMediaImportException when the specified file > > is invalid or the specified path is invalid > > */ > > public void importFile(final String relativeSubNode, final String > > relativeNodePath, final File file) > > throws JackrabbitMediaImportException { > > checkInitialized(); > > > > try { > > if (null == file) { > > throw new JackrabbitMediaImportException("Failed to > > import file ."); > > } else if (!file.exists()) { > > throw new JackrabbitMediaImportException("Failed to > > import " > > + file.getPath() + ", the file does not exist."); > > } > > > > log.debug("Import " + rootName + "/" + relativeSubNode + > > "/" + relativeNodePath + "/" + file.getName()); > > Node root = getSession().getRootNode(); > > // Navigate to (optionally create on the fly) the location > > specified by the node path > > Node currentFolderNode = getOrCreateNodePath(root, > > rootName + "/" + relativeSubNode + "/" + > > getRelativeNodePathCasing(relativeNodePath)); > > > > log.debug("File will be imported as " + > > currentFolderNode.getPath() + "/" + file.getName()); > > // Store the specified file into the specified node path > > storeFile(currentFolderNode, file); > > root.save(); > > root.getSession().save(); > > } catch (InvalidNodePathException e) { > > throw new JackrabbitMediaImportException("Failed to import " > > + file.getPath() + " to " + relativeNodePath + " of > > the JCR", e); > > } catch (RepositoryException e) { > > throw new JackrabbitMediaImportException("Failed to import > > " + file.getPath() + " into JCR", e); > > } > > } > > > > > > /** > > * Method storeFile does the actual streaming of the file to the JCR. > > * > > * @param folder of type Node which will contain the actual file > > * @param file of type File the file to store > > * @throws JackrabbitMediaImportException when > > */ > > private void storeFile(final Node folder, final File file) throws > > JackrabbitMediaImportException { > > synchronized (mutex) { > > try { > > ValueFactory valueFactory = > > folder.getSession().getValueFactory(); > > > > String filename = > > getFilenamePlusExtensionCasing(file.getName()); > > Node fileNode = folder.addNode(filename, > > NODE_PROP_TYPE_FILE); > > Node contentNode = > > fileNode.addNode(NODE_PROP_TYPE_CONTENT, NODE_PROP_TYPE_RESOURCE); > > contentNode.setProperty(NODE_PROP_TYPE_DATA, new > > FileInputStream(file)); > > > > MimetypesFileTypeMap mimetypesFileTypeMap = new > > MimetypesFileTypeMap(); > > // It does not know PDF by default (...) > > mimetypesFileTypeMap.addMimeTypes("application/pdf pdf > > PDF"); > > > > contentNode.setProperty(NODE_PROP_MIME_TYPE, > > mimetypesFileTypeMap.getContentType(file)); > > contentNode.setProperty(NODE_PROP_LAST_MODIFIED, > > valueFactory.createValue(Calendar.getInstance())); > > contentNode.setProperty(NODE_PROP_TYPE_DATA, ""); > > contentNode.setProperty(NODE_PROP_ENCODING, ""); > > > > // Save the newly added information > > folder.save(); > > } catch (RepositoryException e) { > > throw new JackrabbitMediaImportException("Unable to > > read from / write to repository.", e); > > } catch (FileNotFoundException e) { > > throw new JackrabbitMediaImportException("Failed to > > import " + file.getPath() + " into JCR", e); > > } > > } > > } > > > > With regards, > > > > Nick Stolwijk > > > >