[opencms-dev] Map external data to OpenCMS seo urls

Michael Emmerich m.emmerich at alkacon.com
Tue Feb 25 15:12:24 CET 2014


Hello Asger,

maybe the "ResourceInit Handler" can help you.

What is a ResourceInit handler ?

  *      It allows to read a different resource than the one shown in
    the URI
  *      "Normal" behaviour of OpenCms:
      o       The URI maps to a resource in the VFS
      o       If the URI maps to a non existing file in the VFS, a
        404-Error is thrown
  *      With a ResourceInit handler, we can use a “virtual” URI that
    does not exist in the VFS

Example:

www.myserver.com/opencms/opencms/index.html

     is mapped to

/sites/default/index.html

With ResourceInit Handler the following is possible:

www.myserver.com/opencms/opencms/special/index.html

     is mapped to

/sites/default/internal/specialfolder/index.html

But the URI keeps the same!

Implementation & Configuration

  * ResourceInit Handler must implement the interface
    org.opencms.main.I_CmsResourceInit and the method initResource
    Is configured in the opencms-system.xml:

     <resourceinit>
     ...
     <resourceinithandler class="com.alkacon.MyInitHandler"/>
     ...
     </resourceinit>

Multiple ResourceInit handlers can configured

  * Handlers will executed in the order of the configuration
  * ResourceInit hander analyses the URI and returns a CmsResource
  * Each handler should have an exclusive trigger in the URI which
    signals that it should be used

Code example

public class MyInitHandler implements I_CmsResourceInit {

     /** trigger path. */
     public static final String HANDLER_PATH = “/special/";

     public CmsResource initResource(CmsResource resource,
CmsObject cms,
HttpServletRequest request,
HttpServletResponse response) throws CmsResourceInitException {

         // only process this handler if there is a real request
         if (request != null) {
             String uri = cms.getRequestContext().getUri();

             // only process those requests that start with the trigger path
             if (uri.startsWith(HANDLER_PATH)) {

                     // extract the uri of the resource we really wanted 
to read
                     uri = uri.substring(HANDLER_PATH.length(), 
uri.length());
                     // do your implementation here

             }
         }
         return resource;
     }
}


In your implementaion you should extract your product id form the url 
and save (for example as a reqeust attribute) so that you can access it 
in your jsp again.


Kind regards,

Michael Emmerich

> Hi,
>
> I’m looking to build a website where roughly half the content will come from a backend system, namely products and categories.
>
> I’m not keen to synchronize these to OpenCMS, as the backend already provides the Webservice / EJB interfaces I need.
>
> I can easily make the whole thing work, if I create a custom function (“DisplayProduct.jsp”) that takes a partnumber as a query parameter, look up the data, and render it accordingly.
>
> However, I would like to get a nice looking URL for the data; and I’m willing to limit the product display urls to one subfolder, i.e.
>
> /opencms/opencms/<etc>/products/AB123124
>
> with AB123124 being the partnumber of the product.
>
> Now, ideally, I would be able to register a 404 handler in the products subfolder, and use the PATH_INFO to get the missing bit (AB123124), but I can’t grog how I can do that nicely.
>
> Is this possible?
>
>
> Or could I somehow just register all the SEO urls from the backend somewhere, and have them all map to the DisplayProduct.jsp  (preferably not as mod_rewrite or some such).
>
> Med venlig hilsen/Best Regards
>
> Asger Jensen
> Head of Production
>
> E-mail: akj at tmnet.dk
> Mobile: +45 2630 6502
>
>
>
> Niels Hemmingsens Gade 9
> 1153 København K | Denmark
> +45 3344 8555 | www.tmnet.dk
>
>   
>
> _______________________________________________
> 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/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
> -- 
> Alkacon Software GmbH - The OpenCms Experts
> Michael Emmerich
>
> Email: m.emmerich at alkacon.com
>   
> http://www.alkacon.com
> http://www.opencms.org
>
>
> Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 54613
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20140225/066f6c5e/attachment.htm>


More information about the opencms-dev mailing list