Publishing images from child tables

Is it possible to publish images from a child table using 6.5-style search generated content lists and binary templates?

I have a set of content types left over from my 5.7 implementation that I’m trying to update to the 6.5 way of doing things. We have images stored in BLOBs in child tables (I know, this is not ideal, but its what i was given to work with).

I need to build a content list that will list each child table entry and a templace that will publish them.

Does anyone have an example of this… or any advice?


I had indended to start with the template and work backward. I was able to get the mime type with a JEXL expression like this:

$t = $sys.params.get(“sys_sortrank”); $n = $rx.string.extractNumber($t[0]).intValue(); $i = $tools.math.sub($n,1);
$rx.asmhelper.childValues($sys.item, “ads”, “rx:img_type” ).get($i).string

What this does is load the sortrank from the query string, parse the query string’s value into an integer, get the child index by subtracting 1, and attempt to get the mime type of that numbered child.

But the same doesn’t work for the binary data itself. I tried this:

$t = $sys.params.get(“sys_sortrank”); $n = $rx.string.extractNumber($t[0]).intValue(); $i = $tools.math.sub($n,1);
$rx.asmhelper.childValues($sys.item, “ads”, “rx:img” ).get($i).string.getBytes()

Turns out that the image data gets corrupted using this method. I delved into the java classes and it seems that PSInputStreamValue is the issue here… It uses a string buffer to read binary data, and as such, i’d assume that if a null byte exists in the data stream, then it’ll terminate the string and hence the data for the image would be incomplete.

So… if I want to continue with this method, I’d need to do something like:

$stream = $rx.asmhelper.childValues($sys.item, “ads”, “rx:img” ).get($i).getStream();

and then try to load the data manually… but I can’t figure out how to create a new instance of a byte array… or any class, for that matter.

Any suggestions or alternatives?

Thanks in advance.

When you create a binary template, the value of $sys.binary is a Property object, not a String.

So, if you can get the Property object with some statement like (as you suggest):

$rx.asmhelper.childValues($sys.item, “ads”, “rx:img” ).get($i)

That should be good enough. It’s also possible to walk through the child nodes programmatically without calling $rx.asmhelper.

#set($myChildren = $sys.item.getNodes("ads"))
#foreach($myChild in $myChildren)
   #set($xyz = $myChild.getProperty("rx:img"))
   ## do something to the image
#end

I hope this helps

Dave

This problem was never resolved originally so we are tackling it again.
Using the method dbenua suggested, we have this so far.

$sys.binary is defined as:
$myChildren = $sys.item.getNodes("IMAGES");
foreach($myChild in $myChildren){
     $image = $myChild.getProperty("rx:image");
     $image;
}

$sys.mimetype is defined as:
$myChildren = $sys.item.getNodes("IMAGES");
foreach($myChild in $myChildren){
     $image = $myChild.getProperty("rx:image_type");
     $image.String;
}

The new problem we are encountering is that of the multiple images we have in the child table, only the last one is publishing. What do we need to do for all images to publish? Also, how should the Location Scheme Parameter value be set?

Thanks.
Endora

I’m trying to do something similar.

I have created a binary template for each row (I am only allowing a small number of rows), e.g. template for row n has

$sys.binary = $rx.asmhelper.childValues($sys.item, “images”, “rx:image”).get(n)

$sys.mimetype = $rx.asmhelper.childValues($sys.item, “images”, “rx:image_type”).get(n).string

Then I have created a location scheme for each possible template to specify the filename used during upload:

expression = $sys.pub_path +$rx.asmhelper.childValues($sys.item, ‘images’, ‘rx:upload_filename’).get(n).string

The big problem here is there is no check to see that the row exists. One possible solution is a content list for each row, with the where clause checking whether the child row exists. I don’t know how to do that in JSR170 though.

Thanks,
Andrew

You’re correct that you need 1 template per binary: that’s true of binary templates generally.

The last time we built something like this we used a custom template expander (to expand just the templates for which data exists). Unfortunately, that customer had some very specific requirements, and we could not build something generic.

This requires a fair amount of Java logic, you cannot just use JSR-170 queries.

Are you saying that 6.5 doesn’t have any support for images in child tables at all (other than creating a custom template expander)? Having 1 binary template for each child table image defeats the purpose of using the child table.

Is the recommended approach to use Slots for relating multiple images to a content type?

Thanks,
Veeren

No, I’m not saying that we don’t support images in child tables. I’m saying that images in child tables have a place in specific applications.

Whenever you assemble a template (ANY template), you get one “object” (file, page, image, etc) back from the Assembler. You cannot therefore make one request to the assembler and get all of your images, you can only get one image at a time.

If you are “linking” images to an HTML page (which is what I understand from your question), then there really 2 results you care about: the actual binary image file, and the snippet of HTML that goes into the page (and contains the URL of the image file).

If this is what you are doing, you should ALWAYS have a separate item for the image, and link them with a slot.

On the other hand, if you know that you need one and only one image, but you’re not sure which one, then perhaps using a child table for images makes some sense. You need to put some logic into your templates that selects which image you want to display (or publish).

I hope this clears this up somewhat.

Dave

Dave,

thank you for the explaination; it certainly does help. Just to make sure I’ve got it, here’s our specific situation:

We have some old 5.7 style applications that we are converting to the 6.5 style. One of these applicaitons is an editor for an Article content type that has an image gallery. The image gallery was created using a child table, which held the content for each image, caption, etc. The child table was used so that users would be able to update/edit the images in the gallery within the main editor.

From your post I understand that something like this wouldn’t be easily implemented in the 6.5 style since there would be no way to retrieve the binary data for each image in the child table through a single binary tempalte. And that the best way to do something like this would be through a slot.

Please let me know if i’m understanding this correctly.

Thanks,
Veeren