When I connect to the repository with webdav I can see the whole filestructure with the files, but they are size 0 and when opened they don't have content. Also, when I make a dump of the database it is 23 MB in size instead of the 500 MB I was expecting.
I haven't tried it with an older version. Monthday we are going to debug the problem, but I was wondering if someone already had the same problem. The multiple save statements were there of a little debug session we had today. The other remark about the Calendar I will also implement monthday. Thanks for the input, Nick Stolwijk -----Original Message----- From: Stefan Guggisberg [mailto:[EMAIL PROTECTED] Sent: Fri 8/10/2007 4:14 PM To: [email protected] Subject: Re: Problem with saving binary node data hi nick On 8/10/07, Nick Stolwijk <[EMAIL PROTECTED]> 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: does your code work with a previous jackrabbit release (e.g. 1.3)? what do you mean by 'my files stay empty'? btw: i couldn't find anything inherently wrong with your code, only some minor issue. e.g. redundant save calls: storeFile(currentFolderNode, file); // => calls currentFolderNode.save(), // unnecessary because of following // statement root.save(); root.getSession().save(); // redundant unneccessary Value creation: contentNode.setProperty(NODE_PROP_LAST_MODIFIED, valueFactory.createValue(Calendar.getInstance())); can be replaced by contentNode.setProperty(NODE_PROP_LAST_MODIFIED, Calendar.getInstance()); cheers stefan > > 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 <null>."); > } 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 >
