Search code examples
javaopencms

OpenCMS - howto explose a flat structure instead of a folder/tree structure


I would like to have a tree/ folder structure for my content but would like all pages to be served as a flat URL. E.g.

the page located at /cat1/subcat2/tulips.html would be served at:

http://example.com/tulips.html

and the page located at /cat5/roses.html would be served at:

http://example.com/roses.html

I would need all links to be automatically calculated and ensure that there are no conflicts.

Is this possible with opencms?

Thanks,

Assaf


Solution

  • A rough outline how I'd to approach this:

    You would first get the list of all the resources via <cms:contentload> (http://www.bng-galiza.org/opencms/opencms/alkacon-documentation/documentation_taglib/docu_tag_contentload.html), taglib or the respective java API in java code as you need some coding anyway, and then create new resources of type 'external link' in your OpenCms root folder, pointing to your targets; probably using something like

    getCms().createResource(newFileName, templateFile.getTypeId());
    

    or similar method (as external link isn't structured content) for it.

    You could wrap this logic up into a java class and schedule it as a scheduled job, I guess it's sufficient, as long as you don't need it right away and some delay is acceptable. Otherwise you'd need to hook it into the publishing flow.