AnsweredAssumed Answered

List xml documents associated with template using JAVA

Question asked by parrym on Apr 21, 2009
I have this code which works from a jsp page successfully:

   public static List<PortalBean> getPortalChoices(final PageContext pageContext) throws Exception {
      final FormDataFunctions ef = new ServletContextFormDataFunctionsAdapter(pageContext.getServletContext());
      final Map<String, Document> entries = ef.parseXMLDocuments("portal", "/portals/");
      final List<PortalBean> result = new ArrayList<PortalBean>(entries.size());
      for (Map.Entry<String, Document> entry : entries.entrySet()) {
         final String fileName = entry.getKey();
         final Document d = entry.getValue();
         final Element n = (Element)d.getElementsByTagName("po:title").item(0);
         result.add(new PortalBean(n.getFirstChild().getNodeValue(),fileName));
      }
      return result;
   }

so far all I have this working from an alfresco xsl is this:


   public static String test() {
      return "This is a test";
   }

using


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:java="http://xml.apache.org/xslt/java">
   <xsl:output exclude-result-prefixes="fn java xsl xs"/>
   <xsl:template match="/">
      <xsl:value-of select="java:com.mysite.solutions.web.bean.po.PortalBean.test()" />
   </xsl:template>
</xsl:stylesheet>

How do I run the getPortalChoices from the xsl document as I can't seem to find a PageContext to pass to the function.

or

How can i rewrite the getPortalChoices function to return a list of the xml documents it finds (just the filenames is all I really need and I can then use alf:parseXMLDocument in the xsl).

Thanks

Outcomes