[opencms-dev] CmsJspNavElement and getCmsObject

Sebastian Himberger sebastian.himberger at gmx.de
Sun Apr 2 11:06:15 CEST 2006


Hi,

you can not cast a CmsJspNavElement into an CmsJspActionElement since 
the latter is no subclass of the first(CmsObject no = 
((CmsJspActionElement)ne).getCmsObject();). So i would create the 
CmsJspActionElement and the CmsObject outside your loop and then just 
call a method on them:

CmsJspActionElement cmsa = new CmsJspActionElement(pageContext, request, 
response)
CmsObject cmso = cmsa.getCmsObject();

while (...) {
  ...
  if (...) {
     List l = cmso.readResources(ne.getResourceName());
  }
}

I hope i got your questions right. I've not looked up the excact API so 
please bear with me if there are some minor errors in the code.

best regards
Sebastian

Christoph P. Kukulies schrieb:
> I'm looping through the site and want to build a kind of
> sitemap tree , but what is listed in the list should be controlled
> by a property that is applied to each item (file or folder) in the tree.
>
> I chose the following method to get the navigation tree:
> List list =
>     builder.getSiteNavigation("/"+cms.property("locale","search")+"/",-1);
>     Iterator it = list.iterator();
>
>    while(it.hasNext()){
>              String s="";
>              out.println("<br>");
>              CmsJspNavElement ne = (CmsJspNavElement)it.next();
>              if(!ne.getResourceName().endsWith(".htm")){ // Hack
>                   CmsObject no = ((CmsJspActionElement)ne).getCmsObject();
>                   List items = no.readResources(filename,CmsResourceFilter.ALL);
>               } else {
>                   List items = null;
>               } 
>               java.util.Iterator nt = items.iterator();
>       for(int i=0; i< ne.getNavTreeLevel();i++)
>          s=s+"-";
>       out.println(s + ne.getNavText() + ne.getLocale() + ne.getFileName() +
>      "Resourcename:" + ne.getResourceName());
>    
>    }
>
> The above is full of bugs and bad programming style, but I hope you get the
> idea from this.
>
> When I arrive at a navelement, that is a folder, I want to enumerate all
> files in that folder.
>
> My problem is to get the CmsObject in the moment when I arrive at 
> a CmsJspNavElement (that's what I have in the list), to apply the 
> readResources() method.
>
> Hope someone could give me the right tip.
>
>
> --
> Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
>
> _______________________________________________
> 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