[opencms-dev] Re: CmsObject#readAllProjectResources(id) throwsClassCastException

John Emmer jemmer at avega.com
Tue May 10 20:55:24 CEST 2005





> > John Emmer wrote:
> > ...  The new code is below, and it still gets a
> > ClassCastException when I call resIter.next()
> > ...
> >                 List resources = cms.readProjectResources(project);
> >                 for ( Iterator resIter =
> > resources.iterator(); resIter.hasNext(); ) {
> >                     Object next = resIter.next();
> > ...
>
> Alexander Kandzior wrote:
> Sure this can't work as the method just returns Strings that define the
> project view, not CmsResource objects. Have a look at the JavaDoc.

But all I was doing was calling next() on the iterator.  The code that was
casting to CmsResource was commented out -- although I understand that it's
hard to read when everything gets wrapped the way it does for the list.
Anyway, I changed my code to this:

List resources = cms.readProjectResources(project);
for ( Iterator resIter = resources.iterator(); resIter.hasNext(); ) {
  out.println(resIter.next());
}

And it no longer threw the exception.  Strange.

But the only thing in the list was "/", so I finally got the list I was
looking for like this:

CmsObject cms = OpenCms.initCmsObject("Guest");
cms.loginUser("Admin", "admin");
out.println("Accessible Projects<BR>");
out.println("<UL>");
for (Iterator projIter = cms.getAllAccessibleProjects().iterator();
projIter.hasNext();) {
  CmsProject project = (CmsProject) projIter.next();
  out.println("<LI>" + project.toString() + "</LI>");
  out.println("Project Resources<BR>");
  out.println("<OL>");
  List resources = cms.readProjectResources(project);
  for (Iterator resIter = resources.iterator(); resIter.hasNext();) {
     String resourceName = (String) resIter.next();
     List children = cms.readResources(resourceName, CmsResourceFilter.ALL,
true);
     for (Iterator childIter = children.iterator(); childIter.hasNext();) {
         CmsResource resource = (CmsResource) childIter.next();
         I_CmsResourceType type =
OpenCms.getResourceManager().getResourceType(resource.getTypeId());
         out.println("<LI>" + resource.getResourceId().toString() + " : " +
type
                                + " : " + resource.getName() + " : " +
resource.getRootPath()
                                + "</LI>");
    }
    out.println("</OL>");
  }
  out.println("</UL>");
}

Which I present here in case anyone else is also trying to learn how to
navigate the resources.

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

John Emmer
Senior Software Engineer
Avega
200 N. Sepulveda, Suite 600   El Segundo, CA 90245
310-563-3322    jemmer at avega.com





More information about the opencms-dev mailing list