As far as I can tell, you are not doing exactly the same things as for
example DMS is doing on file upload:

            // write file
            this.fileNode = node.createNodeData("document",
javax.jcr.PropertyType.BINARY);
            InputStream in = new FileInputStream(tmpFile);
            this.fileNode.setValue(in);
            IOUtils.closeQuietly(in);

... I don't think you should (or could) create any jcr:xxx properties
directly.

Why can't you try to do the same as above - i.e. get the node and call
Magnolia API to store the binary data in it and let Magnolia handle all
the details of how it will be stored? If you really insist on saving
those binary data directly yourself, then look in the DefaultContent to
see how Magnolia calls JCR APIs to do so.

HTH,
Jan




On Thu, 2009-10-22 at 11:57 +0200, Ernst Bunders wrote:
> Hello
> 
> I'm new to Magnolia, but we are planning to build some websites with
> it in the future, and we are currently in the process of
> experimentation and discovery. The project I'm currently on is
> creating a magnolia importer that will have to create pages and
> paragraphs based on the content of existing websites we own.
> 
> The problem I'm running into is creating images in the repository. At
> first glance it seems obvious enough: just create the node structure
> that the stkTextImage dialog creates. Unfortunately this seems not the
> case. In the below (groovy) code I am creating a  paragraph node, and
> a child 'imageBinary' node. Some utility methods are called but not
> shown here.
> 
> StkTextImage is a container for all repository paragraph properties
> StkImage is a container for all repository image properties.
> 
> ---
> def createParagraph(Content parentNode, StkTextImage paragraph) {
>   def paraCount = parentNode.children.size()
>   def nodeName = ("00" + ++paraCount)[-2..-1]
>   Content paragraphNode = createOrFindContentNode(parentNode, nodeName)
>   createOrFindContentNode(paragraphNode, 'text_files')
>   setDataWhenValue(paragraphNode, 'subtitle', paragraph.title)
>   setDataWhenValue(paragraphNode, 'text', paragraph.textAsHtml)
>   paragraphNode.metaData.setTemplate('stkTextImage')
>   StkImage img = paragraph.image
>   if (img) {
>     if (img.type == 'dms') {
>       //dms specific stuff
>       setDataWhenValue(paragraphNode, 'imageDmsUUID', img.dmsUuid)
>     } else if (img.type == 'upload') {
>       //upload specific stuff
>       imageNode = createOrFindResourceNode(paragraphNode, 'imageBinary')
>       setDataWhenValue(imageNode, "extension", img.fileExtension)
>       setDataWhenValue(imageNode, "fileName",
> "${img.fileName}-(${img.width}x${img.height})")
>       setDataWhenValue(imageNode, "height", "$img.height")
>       setDataWhenValue(imageNode, "width", "$img.width")
>       setDataWhenValue(imageNode, "jcr:data", new
> ByteArrayInputStream(img.imageByteArray))
>       setDataWhenValue(imageNode, "size", "$img.sizeInBytes")
>       setDataWhenValue(imageNode, "jcr:mimeType", 'image/jpeg')
>       setData(imageNode, "jcr:lastModified", wrapInCalendar(new Date()))
>     }
>     //global stuff
>     setDataWhenValue(paragraphNode, 'image', img.type)
>     setDataWhenValue(paragraphNode, 'imageCaption', img.caption)
>     setDataWhenValue(paragraphNode, 'imageCopyright', img.copyright)
>     setDataWhenValue(paragraphNode, 'imageDescription', img.description)
>     setDataWhenValue(paragraphNode, 'imageLocation', paragraph.imageLocation)
>   }
> ---
> 
> This doesn't work though. The error message:
> 
> ---
> An error occurred while executing the script. Error message is no
> definition found in parent node's node type for new node: no matching
> child node definition found for {http://www.jcp.org/jcr/1.0}data
> ---
> 
> I've been playing around with this code for a while, and tried all
> kinds of different approaches. But I guess I'm on the wrong track, and
> need some help.
> 
> Can anybody give me any advice on this?
> 
> I attach two files:
> - the complete listing
> - an xml export of the created Event page (without the image
> obviously, the paragraph is the first one in the 'main' node)
> 
> 
> thanks,
> 
> 
> --
> Ernst bunders
> Developer VPRO
> 
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to