[opencms-dev] How to add a relation
Paul-Inge Flakstad
flakstad at npolar.no
Mon Aug 31 11:07:16 CEST 2009
Michael - you just saved me a bunch of work..! =D
Many many MANY thanks for helping me - it works like a charm! ;-)
Cheers (loud ones!),
Paul :)
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Michael Moossen
> Sent: 31. august 2009 10:53
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] How to add a relation
>
> Hi Paul!
>
> Hi, Paul!
>
> ufff... i just tried it by myself, and it was not easy to
> figure out how
> to do it right :(
>
> and i got to the conclusion that the element matching mechanism needs
> some improvements ;)
>
> well, what you have to do for getting it working is to define
> the rules
> in each nested schema and not in the outer schema.
>
> in your case, you need to define the rule in the schema defining your
> Image value, and there you should, of course, use the simple
> element name:
>
> <relation element="URI" type="strong" invalidate="false" />
>
> HTH
>
> -------------------
> Michael Moossen
>
> Alkacon Software GmbH - The OpenCms Experts
> http://www.alkacon.com - http://www.opencms.org
>
> Paul-Inge Flakstad schrieb:
> > Thanks for replying, Michael! :)
> >
> > I tried putting this:
> >
> > <relation element="Paragraph/Image/URI" type="strong"
> invalidate="false" />
> >
> > in my XSD for "MyPage".
> >
> > There were no errors this time, but when trying to publish
> a the page with related resources, the image pointed to by
> the above mentioned URI is not in the publish list. Examining
> the control code, I found the following:
> >
> > <MyPages xmlns...>
> > <MyPage language="en">
> > ...
> > <Paragraph>
> > ...
> > <Image>
> > <URI>
> > <link type="WEAK">
> > <target><![CDATA[/sites/mysite/images/image.jpg]]></target>
> > <uuid>379b0271-9602-11de-8605-00237dea8b58</uuid>
> > </link>
> > </URI>
> > <Title/>
> > <Text name="Text0">
> > <links/>
> > <content/>
> > </Text>
> > <Source/>
> > </Image>
> > ...
> > </Paragraph>
> > ...
> > </MyPage>
> > </MyPages>
> >
> > So nothing's changed, it seems? The link is still weak, and
> no there's no other <link> element for the image either...
> Why is that? Any ideas on how to fix it?
> >
> > Again, what I need is for images referred to inside
> xmlcontents to be published along with the page. Currently,
> I'm writing my own event listener code to administrate a
> custom relation type (strong one) from the page to the image.
> In my opinion, that's kinda overkill, and shouldn't be
> necessary, since the relations annotation should be
> sufficient. But as long as I cannot get it to work...well,
> I'm just out of options. =|
> >
> > -Paul
> >
> >> -----Original Message-----
> >> From: opencms-dev-bounces at opencms.org
> >> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of
> Michael Moossen
> >> Sent: 31. august 2009 08:39
> >> To: The OpenCms mailing list
> >> Subject: Re: [opencms-dev] How to add a relation
> >>
> >> Hi Paul!
> >>
> >> I thought i did already answer this...
> >> But well, better late than never ;)
> >>
> >> > "XML content value "Paragraph/Image/URI" used for this
> >> check rule is
> >> > not optional."
> >> Here the problem is the invalidation mechanism:
> >> By 'very' default when you do not have any relation rules,
> >> relations are
> >> weak and do not invalidate.
> >> But when adding a relation rule specifying only the type, the
> >> invalidate
> >> default value is true(or node), and for this the node has to
> >> be optional.
> >> so to prevent that just set the invalidate attribute to false.
> >>
> >> HTH
> >>
> >> -------------------
> >> Michael Moossen
> >>
> >> Alkacon Software GmbH - The OpenCms Experts
> >> http://www.alkacon.com - http://www.opencms.org
> >>
> >> Paul-Inge Flakstad schrieb:
> >>> Hi Michael,
> >>>
> >>> Thanks for your reply, it helped me understand the
> >> behaviour. I had already read your presentation
> >>> (that's actually why I put a shout-out to you, mentioning
> >> your name in my previous mail), but I
> >>> couldn't seem to extract this difference in weak and strong
> >> links from it.
> >>> Like I explained, I've tried to put an annotation in my
> >> XSD, defining the image link as strong, but
> >>> since the image container (where the VfsFile element is)
> >> and it's parent container are both optional,
> >>> I get an error stating:
> >>>
> >>> "XML content value "Paragraph/Image/URI" used for this
> >> check rule is not optional."
> >>> when I try to create a new resource of the type in question.
> >>>
> >>> So, is there any way to get around this? Is it possible to
> >> set xmlcontent relations to be
> >>> strong by default, for example..?
> >>>
> >>> Also, if you or anybody else knows about any tutorial or
> >> how-to on defining custom relations, please
> >>> let me know. :)
> >>>
> >>> Cheers,
> >>> - Paul
> >>>
> >>>> -----Original Message-----
> >>>> From: opencms-dev-bounces at opencms.org
> >>>> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of
> >> Michael Moossen
> >>>> Sent: 20. august 2009 16:27
> >>>> To: The OpenCms mailing list
> >>>> Subject: Re: [opencms-dev] How to add a relation
> >>>>
> >>>> Hi Paul-Inge!
> >>>>
> >>>> Yes, this is the intented behaviour.
> >>>>
> >>>> The keyword here is relation type, which can be weak or strong.
> >>>>
> >>>> "related resources" are strong relations and xmlcontent
> >>>> relations are by
> >>>> default weak.
> >>>>
> >>>> for more details see:
> >>>> http://opencms.org/export/sites/opencms/en/events/opencms_days
> >>>> _2008/slides/T2_MichaelMoossen.pdf
> >>>>
> >>>> -------------------
> >>>> Michael Moossen
> >>>>
> >>>> Alkacon Software GmbH - The OpenCms Experts
> >>>> http://www.alkacon.com - http://www.opencms.org
> >>>>
> >>>> Paul-Inge Flakstad schrieb:
> >>>>> I've gotten no answers on this question, so I'm just
> >>>> posting an update.
> >>>>>
> >>>>> I don't get how the CRE is supposed to work. Seems to me that
> >>>>> it actually doesn't work like it's supposed to(?). I've got
> >>>> a structured
> >>>>> content type, which is a just a type of general page. It nests
> >>>>> paragraphs which in turn nests image containers (where you
> >>>>> can VfsFile-link to the image). Pretty straightforward,
> >>>> nothing special.
> >>>>>
> >>>>> If I add a picture to the page, save, and then look at the
> >>>> relations
> >>>>> using the context menu's "Link relations to/from", I
> can see the
> >>>>> relation between the page and the image just fine. So a
> relation
> >>>>> has definitively been established.
> >>>>>
> >>>>> But when I try to publish the page "with related
> >>>> resources", the system
> >>>>> apparently fails to recognize the relation, as no image
> >>>> file appears in
> >>>>> the publish list, only the page itself... WHY? The relation
> >>>> clearly exists!
> >>>>>
> >>>>>
> >>>>> I've tried other approaches to try to force the
> behaviour I want:
> >>>>>
> >>>>> Tried to manually add a relation using a simple .jsp that calls
> >>>>> addRelationToResource. However, I was only able to add
> the types
> >>>>> CATEGORY and OU_RESOURCE. All the other types caused
> >>>>> IllegalArgumentExceptions. And still, "publish with related
> >>>> resources"
> >>>>> did not include the image when trying to publish the
> general page.
> >>>>>
> >>>>> Tried to Add the relation in the XSD, but that didn't work
> >>>> either (some
> >>>>> elements are optional, which caused this approach to
> >> produce mostly
> >>>>> errors when trying to create new general pages).
> >>>>>
> >>>>>
> >>>>> Can anybody shed some light on why the "publish with
> >>>> related resources"
> >>>>> behaves like this? Is it a configuration issue?
> >>>>> Also, I would still like to see an example on how to
> >>>> programatically add
> >>>>> a new relation between two resources (and how to define a
> >>>> new type of
> >>>>> relation).
> >>>>>
> >>>>> Anyone? (Michael Moossen..? :) )
> >>>>>
> >>>>>
> >>>>> All the best,
> >>>>> Paul
> >>>>>
> >>>>>
> >>>> --------------------------------------------------------------
> >>>> ----------
> >>>>> *From:* opencms-dev-bounces at opencms.org
> >>>>> [mailto:opencms-dev-bounces at opencms.org] *On Behalf Of
> >>>> *Paul-Inge
> >>>>> Flakstad
> >>>>> *Sent:* 13. august 2009 20:40
> >>>>> *To:* opencms-dev at opencms.org
> >>>>> *Subject:* [opencms-dev] How to add a relation
> >>>>>
> >>>>> Hi everyone
> >>>>>
> >>>>> I'm trying to programatically add a relation between
> >>>> two resources,
> >>>>> and things are not going so well.
> >>>>>
> >>>>> What I want to do is establish a relation between an
> >> xmlcontents
> >>>>> type resource (structured content) and an image resource, so
> >>>>> that the image gets published when the xmlcontents file
> >>>> is published
> >>>>> with related resources. This is actually quite
> >>>> important, because
> >>>>> many editors forget to publish images, resulting in an
> >>>> error message
> >>>>> for any user who's not logged in...
> >>>>>
> >>>>> I'm putting my code inside a Java class method that
> >> creates the
> >>>>> image (thumbnail) resource. When using the call like
> >> this (tried
> >>>>> other CmsRelationTypes as well, same result):
> >>>>> cmso.addRelationToResource("/en/index.html",
> >>>>> "/images/thumbs/image.jpg",
> >> CmsRelationType.JSP_WEAK.getName());
> >>>>>
> >>>>> I get the following error:
> >>>>> Error while adding a relation from resource
> >> "/en/index.html" to
> >>>>> resource "/images/thumbs/image.jpg" with type "JSP_WEAK".
> >>>>>
> >>>>> Can anyone tell me what I'm doing wrong - and/or show
> >>>> me how it's done?
> >>>>>
> >>>>> Cheers,
> >>>>> Paul
> >>>>>
> >>>>>
> >>>>>
> >>>> --------------------------------------------------------------
> >>>> ----------
> >>>>> _______________________________________________
> >>>>> This mail is sent to you from the opencms-dev mailing list
> >>>>> To change your list options, or to unsubscribe from the
> >>>> list, please visit
> >>>>> http://lists.opencms.org/mailman/listinfo/opencms-dev
> >>>> _______________________________________________
> >>>> This mail is sent to you from the opencms-dev mailing list
> >>>> To change your list options, or to unsubscribe from the list,
> >>>> please visit
> >>>> http://lists.opencms.org/mailman/listinfo/opencms-dev
> >>>>
> >>> _______________________________________________
> >>> This mail is sent to you from the opencms-dev mailing list
> >>> To change your list options, or to unsubscribe from the
> >> list, please visit
> >>> http://lists.opencms.org/mailman/listinfo/opencms-dev
> >> _______________________________________________
> >> This mail is sent to you from the opencms-dev mailing list
> >> To change your list options, or to unsubscribe from the list,
> >> please visit
> >> http://lists.opencms.org/mailman/listinfo/opencms-dev
> >>
> >
> > _______________________________________________
> > This mail is sent to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the
> list, please visit
> > http://lists.opencms.org/mailman/listinfo/opencms-dev
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list,
> please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
More information about the opencms-dev
mailing list