[opencms-dev] How to locate files in the vfs?!

Thomas Maerz thomasmaerz at gmx.de
Thu Mar 10 13:31:21 CET 2005


"Nick Panienski" <panienski at codecentric.de> writes:

> `-- store				Added to Navigation
>     |-- main			Added to Navigation
>     |   `-- index.html
>     `-- sub				Added to Navigation
>         `-- index.html
>
> If a user navigates to the 'store' directory he should automatically be
> directed to the first occurrence of an index.html ('first' maybe based on
> the navigation order).
>
> So, for now the user gets an empty page navigating to the store dir, well,
> for sure, the directory IS empty :)
>
> I need a solution for finding the first "index.html" in the vfs from a given
> dir. Something like getFirstLink("index.html","/store/") which should return
> /store/main/.
> Building the navigation I could then use this function to define the hrefs.
> 'store' would get a href to the index of 'main'.

`-- store				Added to Navigation
    |-- index.jsp


,----[ index.jsp ]
| CmsJspActionElement cms = new CmsJspActionElement( pageContext, request, response );
| CmsObject cmsObject = cms.getCmsObject();
| 
| String uri = cms.getRequestContext().getUri();
| 
| List navigation = CmsJspNavBuilder.getNavigationForFolder( cmsObject, uri );
| 
| for( Iterator it = navigation.iterator(); it.hasNext(); )
| {
|     CmsJspNavElement navElement = ( CmsJspNavElement ) i.next();
| 
|     try
|     {
|         if ( ! navElement.isFolderLink() ) continue;
|         CmsResource resource = cmsObject.readResource( navElement.getResourceName() + "index.html" );
|         cms.getResponse().sendRedirect( cms.link( navElement.getResourceName() ) );
|     }
|     catch ( CmsException e )
|     {
|     }
| }
`----

I didn't try the code above,
you could also put it where you generate your navigation.

Regards,
Thomas




More information about the opencms-dev mailing list