[opencms-dev] cms:parse tag usage

Michael Emmerich m.emmerich at alkacon.com
Thu Sep 11 10:48:14 CEST 2008


Olli,

> Thanks for this Michael. Also, can you tell me, if I write my own parser is
> extending org.opencms.util.CmsHtmlParser the best approach or something
> else?


Well, try the following:

The class that is given in the <cms:parse> tag should extend 
A_CmsConfiguredHtmlParser.

In the required createVisitorInstance method you must create an instance 
of the visitor object that extends the CmsHtmlParser and implements the 
I_CmsHtmlNodeVisitor.

Kind regards,
Michael Emmerich


> Regards,
> 
> Olli
> 
> P.S. when I get this working I will document it to OpenCms Wiki, I promise
> :)
> 
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Michael Emmerich
> Sent: 10 September 2008 14:37
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] cms:parse tag usage
> 
> If you use the <cms:parse> or <cms:decorate> tag and have a 
> <cms:include> inside, this include must use the cacheable="false" 
> attribute for the include tag.
> 
> 
> Kind regards,
> Michael Emmerich
> 
> 
> Claus Priisholm schrieb:
>> Hi
>>
>> Nope - I looked at the decorate tag at one point, but it did not do what 
>> I wanted. But I was having problems catching the output from the include 
>> tag similar to what you describe, until someone hinted me that I should 
>> disable the cache. And it did the trick - a simple way of testing if you 
>> get what you expect:
>>
>> <c:set var="stuff"><cms:include ... /></c:set>
>>
>> and then check
>>
>> pageContext.getAttribute("stuff")
>>
>> But before I got so far I implemented a tomcat filter to do the job 
>> instead. There I am using org.htmlparser.Parser to do the work for me:
>>
>> Parser parser = Parser.createParser(source, encoding);
>> NodeList nl = parser.parse(null);
>>
>> Html root = null;
>> for(int i = 0; i< nl.size(); i++) {
>> 	if(nl.elementAt(i) instanceof Html) {
>> 		root = (Html)nl.elementAt(i);
>> 		break;
>> 	}
>> }
>>
>> NodeList list = root.searchFor(LinkTag.class, true);
>>
>> ...and so forth.
>>
>> Other options could be JTidy or NekoHTML to do the parsing. Seem to 
>> recall that HTMLParser wants your document to start with <html> and not 
>> be a partial document.
>>
>> Olli Aro wrote:
>>> Hi Claus,
>>>
>>> Have you ever used cms:parse tag? Do you know how it should work and how
> to
>>> write a custom parser?
>>>
>>> I created my own test parser as direct copy of
>>> org.opencms.util.CmsHtmlParser and still don't get any content through,
> so
>>> maybe I am doing something wrong.
>>>
>>> Regards,
>>>
>>> Olli
>>>
>>> -----Original Message-----
>>> From: Claus Priisholm [mailto:claus.priisholm at gmail.com] On Behalf Of
> Claus
>>> Priisholm
>>> Sent: 09 September 2008 14:38
>>> To: olli_aro at yahoo.co.uk; The OpenCms mailing list
>>> Subject: Re: [opencms-dev] need some help on customizing the <cms:link>
> tag
>>> What I ran into once I was trying to capture output from the include-tag 
>>> was that if it is cached, the only output your tag get to see is 
>>> something that looks like 32 bit ident... So to catch the output of 
>>> those tags that supports the flex cache you must set "cacheable" to 
>>> false (on the include tag).
>>>
>>> Olli Aro wrote:
>>>> Ok, added some debugging info to my parser class and it looks that that
>>> one
>>>> is getting called ok with the following tag:
>>>>
>>>> <cms:parse parserClass="myClassName" param="config">
>>>> 		<cms:include element="body" editable="true" />
>>>> </cms:parse>
>>>>
>>>> So, it must be that I have something wrong with my parser
> implementation.
>>>> Maybe I will create a copy of org.opencms.util.CmsHtmlParser and take it
>>>> from there... But still if anyone do have custom parser class for me to
>>> show
>>>> that would be very useful :)
>>>>
>>>> Regards,
>>>>
>>>> Olli
>>>>
>>>> -----Original Message-----
>>>> From: opencms-dev-bounces at opencms.org
>>>> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Olli Aro
>>>> Sent: 09 September 2008 12:41
>>>> To: 'The OpenCms mailing list'
>>>> Subject: Re: [opencms-dev] need some help on customizing the <cms:link>
>>> tag
>>>> Hi Michael,
>>>>
>>>> Do you have example usage for <cms:parse> tag? How to use it in template
>>> and
>>>> what is the best way to implement your own parser? Also, if you would
> have
>>> a
>>>> sample custom parser class that would be very useful.
>>>>
>>>> I tried to use it with extending org.opencms.util.CmsHtmlParser,
> returning
>>>> this as my own implementation of
>>>> org.opencms.jsp.parse.A_CmsConfiguredHtmlParser and then doing:
>>>>
>>>> <cms:parse parserClass="myClassName" param="config">
>>>> 		<cms:include element="body" editable="true" />
>>>> </cms:parse>
>>>>
>>>> but that did not render anything for the content.
>>>>
>>>> Regards,
>>>>
>>>> Olli
>>>>
>>>> -----Original Message-----
>>>> From: opencms-dev-bounces at opencms.org
>>>> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Michael Emmerich
>>>> Sent: 04 September 2008 16:26
>>>> To: The OpenCms mailing list
>>>> Subject: Re: [opencms-dev] need some help on customizing the <cms:link>
>>> tag
>>>> Kunkun,
>>>>
>>>>> Hi Kunkun,
>>>>>  
>>>>> for the first part of your question you can possibly use the 
>>>>> <cms:decorate>-Tag. For further details have a look at the 
>>>>> OpenCms-Documentation Modules.
>>>> the <cms:decorate> tag only modified text nodes, this would not help.
>>>>
>>>> Use the <cms:parse> tag and write your own parser that is triggered by 
>>>> link tags. Modifiy the link tags with the id, e.g. the hash code of the 
>>>> target and write this into a database.
>>>> Sonthing that holds the id, the target and the number of hits.
>>>> In addition add some code to your link that starts a ajax request when 
>>>> the link is klicked. The target of this ajax reqeust must receive the id
> 
>>>> and increase the number of hits for this id.
>>>>
>>>> HTH,
>>>> Michael
>>>>
>>>>
> ------------------------------------------------------------------------
>>>>> *Von:* opencms-dev-bounces at opencms.org 
>>>>> [mailto:opencms-dev-bounces at opencms.org] *Im Auftrag von *kk
>>>>> *Gesendet:* Donnerstag, 4. September 2008 16:58
>>>>> *An:* opencms-dev at opencms.org
>>>>> *Betreff:* [opencms-dev] need some help on customizing the <cms:link>
> tag
>>>>> Dear together,
>>>>>  
>>>>> my name is kunkun. I am a computerscience-student in Germany. I am 
>>>>> working on a project, which extends opencms with some new features.
>>>>>  
>>>>> The problem is:
>>>>>  
>>>>> 1. I have to mark the links, that i create on a site, with something 
>>>>> like an ID.
>>>>> 2. Then i have to log the Link ID, whenever the link is clicked on the 
>>>>> site, when it is made online.
>>>>>  
>>>>> Can u give me some Ideas, how to do that?
>>>>>  
>>>>> My idea is to create a class, which inherits the internal link class of
> 
>>>>> OpenCms, and change the html-code that is generated during constuction 
>>>>> of the link.
>>>>>  
>>>>> But with which class should I start. There is a class named 
>>>>> CmsJspTagLink, which can be used with <cms:link>.
>>>>> The class CmsLinkManager is also used to substitute the name for links 
>>>>> inside the VFS System. But how do i do
>>>>> it in general purpose not only for internal links?
>>>>>  
>>>>> I am looking for some ideas asap.
>>>>>  
>>>>> Thank u very much.
>>>>>  
>>>>> Kunkun
>>>>>
>>>>>
>>>>>
> ------------------------------------------------------------------------
>>>>>
>>>>> _______________________________________________
>>>>> 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
> 

-- 
Michael Emmerich

-------------------

Alkacon Software GmbH - The OpenCms Experts
http://www.alkacon.com
http://www.opencms.org



More information about the opencms-dev mailing list