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

Nick Panienski panienski at codecentric.de
Wed Mar 16 10:43:00 CET 2005


Hi,

first of all, thanks for the fast reply. We found a solution for the problem
- maybe it's useful for someone else as well, so here is the working code
(sorry for the German commentary and the line breaks... just copy/paste it
to your favourite ide...). It's a recursive method that searches down the
vfs tree for an index.html.

	/** stellt das CmsJspActionElement zur Verfügung */
	public CmsJspActionElement getCmsJspActionElement(PageContext
pageContext) {
		CmsJspActionElement cms = new
CmsJspActionElement(pageContext,
				(HttpServletRequest)
pageContext.getRequest(),
				(HttpServletResponse)
pageContext.getResponse()); 
		return cms;
	}

	/** liefert abhängig von der Navigationsstruktur die erste
verfügbare index.html */
	public String getNextIndex(PageContext pageContext, String folder) {
		CmsJspActionElement cms =
getCmsJspActionElement(pageContext);
		// wenn es im aktuellen Verzeichnis eine index.html gibt
		if
(getCmsJspActionElement(pageContext).getCmsObject().existsResource(folder+"i
ndex.html")){
			// dann dieses Verzeichnis als Lokation für die
index.html zurück geben
			return folder;
		} else {
			// ansonsten im nächsten Unterverzeichnis der
aktuellen Navigationselement nachsehen.
			List subFolderNavi =
getCmsJspActionElement(pageContext).getNavigation().getNavigationForFolder(f
older);
			// gibt es noch Navigationselemente?
			if (subFolderNavi.size() > 0) {
				// wenn ja, nächstes Element nehmen und
wieder mit getNextIndex() nach index suchen
				// nächstes NavElement holen
				CmsJspNavElement nextNavElement =
(CmsJspNavElement)
getCmsJspActionElement(pageContext).getNavigation().getNavigationForFolder(f
older).get(0);
				// den Pfad dieses Elements holen
				String nextFolder =
nextNavElement.getResourceName();
				// den Pfad an getNextIndex() übergeben
				return getNextIndex(pageContext,
nextFolder);
			} else {
				// wenn nein, dann ...
				/** TODO:
				 * was soll passieren wenn keine index.html
gefunden
				 * wird (darf eigentlich nicht vorkommen,
Redakteur Fehler!)
				 * return "/" nur 'Zwischenlösung'.
				 */
				return "/";
			}
		}
	}

Bye
Nick

> -----Ursprüngliche Nachricht-----
> Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-
> bounces at opencms.org] Im Auftrag von Thomas Maerz
> Gesendet: Donnerstag, 10. März 2005 13:31
> An: The OpenCms mailing list
> Betreff: Re: [opencms-dev] How to locate files in the vfs?!
> 
> "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
> 
> 
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev




More information about the opencms-dev mailing list