[opencms-dev] Adding a user-defined relation
Paul-Inge Flakstad
flakstad at npolar.no
Wed Aug 26 09:41:32 CEST 2009
Thanks! =D
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Michael Moossen
> Sent: 26. august 2009 09:21
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] Adding a user-defined relation
>
> Hi Paul-Inge!
>
> great job!
>
> -------------------
> Michael Moossen
>
> Alkacon Software GmbH - The OpenCms Experts
> http://www.alkacon.com - http://www.opencms.org
>
> Paul-Inge Flakstad schrieb:
> > Self-replying. :-)
> >
> > This was easy to do once I found out how, but actually
> finding out how was
> > a little tricky. I couldn't find much on the web and had to
> resolve to
> > the old
> > "browse-the-source-code-you-f**ing-noob" to get a grip. I
> haven't tested
> > this
> > much, so I don't know if I'm actually doing it right, but so far it
> > seems to
> > be working.
> > ---
> >
> > To add a user-defined custom relation type, you'll have to edit
> > opencms-vfs.xml.
> > (opencms-vfs.xml is one of OpenCms' configuration files,
> and is found in:
> > $TOMCAT_HOME/webapps/$OPENCMS_WEBAPP_NAME/WEB-INF/config/)
> >
> > Find the <resources> node in this file, and add your
> relation inside it
> > like this:
> >
> > <resources>
> > ....
> > <relationtypes>
> > <relationtype name="YOUR_RELATIONTYPE_NAME"
> type="strong" /><!--
> > the type can be either strong or weak -->
> > </relationtypes>
> > ...
> > </resources>
> >
> > (Note that the <relationtypes> element does not exist out
> of the box. It
> > does not
> > matter where you decide to put it, as long as it becomes an
> "immediate
> > child"
> > to the <resources> element. I placed mine directly after
> </mimetypes>.)
> >
> > In order for these changes to take effect, re-initialize OpenCms
> > (restart Tomcat).
> >
> > You can test that your new relation type exists by listing
> all relation
> > types.
> > Use a simple JSP like this one to do that:
> >
> > <%@ page import="org.opencms.relations.*, java.util.*"
> session="true" %>
> > <%
> > List relationTypesAll = CmsRelationType.getAll();
> > CmsRelationType rt = null;
> > Iterator i = relationTypesAll.iterator();
> > out.print("<ul>");
> > while (i.hasNext()) {
> > rt = (CmsRelationType)i.next();
> > out.print("<li>NAME: " + rt.getName() + ", TYPE: " +
> rt.getType());
> > }
> > out.print("</ul>");
> > %>
> >
> >
> > To use a relation programatically:
> > CmsRelationType rt =
> CmsRelationType.valueOf("YOUR_RELATIONTYPE_NAME");
> > yourCmsObjectInstance.addRelationToResource(fromResourcePath,
> > toResourcePath, rt.getName());
> >
> >
> > Cheers,
> > Paul
> >
> >
> --------------------------------------------------------------
> ----------
> > *From:* opencms-dev-bounces at opencms.org
> > [mailto:opencms-dev-bounces at opencms.org] *On Behalf Of
> *Paul-Inge Flakstad
> > *Sent:* 25. august 2009 17:10
> > *To:* opencms-dev at opencms.org
> > *Subject:* [opencms-dev] Adding a user-defined relation
> >
> > Hello list!
> >
> > I've tried to add a user-defined relation to OpenCms using the
> > following approaches:
> > 1.) in a JSP file by calling the constructor in
> > org.opencms.relations.CmsRelationType.
> > 2.) by creating a module with an action class, and
> calling the above
> > mentioned constructor
> > from the action class' initialize-method.
> >
> > Approach 1.) produced an error.
> > Approach 2.) did not produce any error, but when
> getting the list of
> > relation types from
> > CmsRelationType.getAll(), my user-defined relation is not there.
> > Also, trying to use
> > my user-defined relation with addRelationToResource()
> does not work.
> > It gives an
> > exception telling me that:
> >
> > The value "801" can not be parsed into an enum element of type
> > "org.opencms.relations.CmsRelationType"
> >
> > (Which btw is kinda interesting, sice I actually try to use the
> > value "901", not "801", which is
> > the ID I assigned my user-defined relation.)
> >
> > Is anyone able to tell me how to add a user-defined relation?
> >
> > Thanks,
> > 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
>
More information about the opencms-dev
mailing list