[opencms-dev] use filename as url instead of standard url mapping for detail pages
Marc Johnen
opencms at johnen.biz
Tue Jun 30 14:29:42 CEST 2015
@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.
More information about the opencms-dev
mailing list