[opencms-dev] <cms:parse> usage
Olli Aro
olli_aro at yahoo.co.uk
Fri Sep 26 15:05:58 CEST 2008
The whole point of this is that you can parse through the content inside the
tag and do what ever you like with that content. The most common application
would be to manipulate content. For example we have used this in order to
ensure that all images in the content have width and height attributes set.
Below is some code for you for this application:
/*
* (non-Javadoc)
* @see org.opencms.util.CmsHtmlParser#visitTag(org.htmlparser.Tag)
*/
public void visitTag(Tag tag) {
int scalingWidth=0;
int scalingHeight=0;
boolean scaleActive=false;
//Get scaling configurations from the request.
CmsRequestContext request=_cms.getRequestContext();
try{
scalingWidth=Integer.parseInt(request.getAttribute(ModuleHelpers.CONTENT_IMA
GE_SCALING_WIDTH).toString());
scaleActive=true;
}catch(Exception e){
scalingWidth=0;
}
try{
scalingHeight=Integer.parseInt(request.getAttribute(ModuleHelpers.CONTENT_IM
AGE_SCALING_HEIGHT).toString());
scaleActive=true;
}catch(Exception e){
scalingHeight=0;
}
//Concentrate only on image references.
if(tag.getTagName().equals("IMG") && scaleActive){
//Rewrite the width and height attributes if not set and
already.
if(scalingWidth>0 && tag.getAttribute("WIDTH")==null)
tag.setAttribute("WIDTH",Integer.toString(scalingWidth));
if(scalingHeight>0 && tag.getAttribute("HEIGHT")==null)
tag.setAttribute("HEIGHT",Integer.toString(scalingHeight));
}
super.visitTag(tag);
}
Regards,
Olli
-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of kk
Sent: 26 September 2008 12:42
To: opencms-dev at opencms.org
Subject: Re: [opencms-dev] <cms:parse> usage
Thanks for help Olli,
yes I got the <cms:parse> Tag working, but I am still a little confused
about what is possible with the I_CmsHtmlNodeVisitor Interface. Do you have
any Code Examples about this?
I think the tutorial on opencms Wiki is very good for the start, but it
needs a lot of experience with opencms to really understand everything that
is possible.
So it would be a great help, if anyone can post a realcode example, where
the custom Parser is in use. I am thinking about posting my Code on Wiki
perhaps, if everything works fine.
kk
_______________________________________________
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/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list