[opencms-dev] use filename as url instead of standard url mapping for detail pages
Michael Emmerich
m.emmerich at alkacon.com
Tue Jun 30 10:00:04 CEST 2015
Hello Marc,
this does not work out of the box, so you cannot map the filename to the
url in the xsd.
However, it should work to write you own XmlContent hander for this
content type which extends the default one and overwrites the prepare
for write method.
The code in it should be something like this (not tested for filename,
but for other mappings:
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 = !! ADD YOUR NAME HERE !!!
// adjust the url mapping
Set<CmsResource> urlNameMappingResources = new
HashSet<CmsResource>();
urlNameMappingResources.add(content.getFile());
// now actually write the URL name mappings
for (CmsResource resourceForUrlNameMapping :
urlNameMappingResources) {
if
(!CmsResource.isTemporaryFileName(resourceForUrlNameMapping.getRootPath()))
{
I_CmsFileNameGenerator nameGen =
OpenCms.getResourceManager().getNameGenerator();
if (!CmsStringUtil.isEmptyOrWhitespaceOnly(mappedName)) {
mappedName = mappedName.trim();
Iterator<String> nameSeq =
nameGen.getUrlNameSequence(mappedName);
cms.writeUrlNameMapping(nameSeq,
resourceForUrlNameMapping.getStructureId(), locale, false);
}
}
}
return result;
}
Kind regards,
Michael
Am 29.06.2015 um 22:31 schrieb Marc Johnen:
> Hi everyone,
>
> is it possible to use the file name including path as url instead of the
> (rather new mapping) for detail pages?
> I tried using a macro %(request.uri) as urlName, which does not work.
> I found similar questions in the forum, but no solution. For the migration
> of an old website, I need to keep
> the old url's instead of using rewrites for ranking purposes.
>
> Thankful for any hints
>
>
>
>
> -----
> 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-tp25504.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