[opencms-dev] use filename as url instead of standard url mapping for detail pages
Michael Emmerich
m.emmerich at alkacon.com
Tue Jun 30 15:28:41 CEST 2015
Marc,
1) I don't think that this behaviour can be changed wit the current
implementation of the UrlNameMapping and resolver without changing the
core code there.
2) Right now, you can only have one detail page for a content type for
each subsite map. This is caused by the link resolver, which can only
map one detail page per sitemap.
In theory you could use multiple detialpage, but then you would need to
write your own link resolving mechanism for you news.
Kind regards,
Michael
Am 30.06.2015 um 14:29 schrieb Marc Johnen:
> @Kai: I tried this thank you, but then the URL will look something like this
> http://localhost:8080/opencms/grid-demo/blog/blog-entries/4e974368-583e-11e4-8db5-005056b61161/
>
> @Michael:
> Thank you, writing a ContentHandler was easy (see code below) at least
> concerning the mapping of the filename to the url.
> But I still have two problems with that:
>
> 1. The generated url always ends with a slash (e.g.
> http://localhost:8080/opencms/grid-demo/blog/testVerzeichnis/test123.html),
> but for my use case it shouldn't.
>
> 2. The structure of the site should be like
> /news/a/ab/news1.html
> /news/b/xyz/news2.html
> ... (dozens of folders)
>
> When I instert a folder to UrlNameMapping (which only works when not using
> the NameGenerator),
> these url's can't be resolved. To make that work I'd probably have to adjust
> the mechanism
> of resolving url's as well?
>
> I could create dozens of subsitemaps (one for each folder) to address that
> issue, which is not very elegant.
>
> Any ideas?
>
> Thanks a lot
> Marc
>
>
>
> package biz.johnen.xml.content;
>
> import java.util.Iterator;
>
> import org.opencms.file.CmsFile;
> import org.opencms.file.CmsObject;
> import org.opencms.loader.I_CmsFileNameGenerator;
> import org.opencms.main.CmsException;
> import org.opencms.main.OpenCms;
> import org.opencms.xml.content.CmsDefaultXmlContentHandler;
> import org.opencms.xml.content.CmsXmlContent;
>
> /**
> * Overrides resolveMappings(). Otherwise the same as
> CmsXmlDefaultContentHandler.
> */
> public class CmsUrlXmlContentHandler extends CmsDefaultXmlContentHandler {
>
> public CmsUrlXmlContentHandler() {
> super();
> }
>
> @Override
> public CmsFile prepareForWrite(CmsObject cms, CmsXmlContent content,
> CmsFile file) throws CmsException
> {
>
> // first call super implementation
> CmsFile result = super.prepareForWrite(cms, content, file);
>
> // define the name for mapping
> String mappedName = file.getName();
> I_CmsFileNameGenerator nameGen =
> OpenCms.getResourceManager().getNameGenerator();
> Iterator<String> nameSequence =
> nameGen.getUrlNameSequence(mappedName);
>
> // adjust the url mapping
> cms.writeUrlNameMapping(nameSequence,
> content.getFile().getStructureId(),
> cms.getRequestContext().getLocale().toString(), false);
>
> return result;
> }
> }
>
> in xsd entered the following lin in xsd:appinfo
>
> <handler class="biz.johnen.xml.content.CmsUrlXmlContentHandler" />
>
>
>
>
>
> -----
> Greetings
> Marc Johnen
> http://www.johnen.biz
> --
> View this message in context: http://opencms.996256.n3.nabble.com/use-filename-as-url-instead-of-standard-url-mapping-for-detail-pages-tp25504p25518.html
> Sent from the OpenCMS mailing list archive at Nabble.com.
> _______________________________________________
> 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
http://www.alkacon.com
http://www.opencms.org
Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 54613
More information about the opencms-dev
mailing list