AnsweredAssumed Answered

Issue in parseXMLDocuments

Question asked by winsenthil on Sep 28, 2010
Latest reply on Sep 28, 2010 by janv
Hi..
I am trying to do web content management for a sample jsp file. Created a web project and configured webforms to it.
web form details:
form name: test
test.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:pr="http://www.alfresco.org/alfresco/pr"
           targetNamespace="http://www.alfresco.org/alfresco/pr"
           elementFormDefault="qualified">
  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:normalizedString"/>
        <xs:element name="body" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:pr="http://www.alfresco.org/alfresco/pr"
      xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
      exclude-result-prefixes="xhtml">
<xsl:output method="html"  encoding="UTF-8" indent="yes"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'/>
<xsl:preserve-space elements="*"/>
      
<xsl:template match="/">
    <html>
      <head>
      <title>testing xsl</title>
      </head>
      <body>
      <div id="content">
       <!– BEGIN MAIN CONTENT –>
      <xsl:for-each select="/pr:test/pr:body">
         <xsl:value-of select="/pr:test/pr:body"/>
       </xsl:for-each>
      <!– END MAIN CONTENT –>
      </div>
   </body>
  </html>
  </xsl:template>
</xsl:stylesheet>

My ROOT directory structure will be
ROOT > sample >
Browse folders
META-INF > context.xml
test > place where all my new web contents thatis xml and html to be added are created using webforms
WEB-INF > pr.tld, web.xml , library files
Browse files
sample.jsp

context.xml

<Context path="/" antiResourceLocking="false"  privileged="true">
</Context>

web.xml

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>Sample Website</display-name>
    <description>Sample Website</description>

    <!– enable server side includes for this website –>
    <filter>
        <filter-name>ssi</filter-name>
        <filter-class>
          org.apache.catalina.ssi.SSIFilter
        </filter-class>
        <init-param>
          <param-name>contentType</param-name>
          <param-value>text/.*html.*</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>1</param-value>
        </init-param>
        <init-param>
          <param-name>expires</param-name>
          <param-value>666</param-value>
        </init-param>
        <init-param>
          <param-name>isVirtualWebappRelative</param-name>
          <param-value>1</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>ssi</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

   <!– register the pr tag library –>
    <taglib>
        <taglib-uri>http://www.alfresco.org/alfresco/pr</taglib-uri>
        <taglib-location>/WEB-INF/pr.tld</taglib-location>
    </taglib>

   <!– welcome file is sample.jsp –>
    <welcome-file-list>
        <welcome-file>sample.jsp</welcome-file>
    </welcome-file-list>
</web-app>

pr.tld

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
        version="2.0">

    <tlib-version>1.0</tlib-version>
    <short-name>pr</short-name>
    <uri>http://www.alfresco.org/alfresco/pr</uri>
    <function>
      <name>getContent</name>
      <function-class>org.orgName.bean.ContentBean</function-class>
      <function-signature>java.util.List getContent(javax.servlet.jsp.PageContext)</function-signature>
    </function>
</taglib>

sample.jsp:

<jsp:root version="1.2"
          xmlns:jsp="http://java.sun.com/JSP/Page"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     xmlns:pr="http://www.alfresco.org/alfresco/pr"
          xmlns:fmt="http://java.sun.com/jsp/jstl/fmt">
       
  <jsp:output doctype-root-element="html"
         doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
         doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'/>

  <jsp:directive.page language="java" contentType="text/html; charset=UTF-8"/>
  <jsp:directive.page isELIgnored="false"/>
 
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
          <title>Alfresco Sample WCM</title>
    </head>
    <body>
      sample content
      <!– load all new contents by using the function defined in /WEB-INF/pr.tld –>
      <c:forEach items="${pr:getContent(pageContext)}" var="newContent">
       <p><c:out value="${newContent.content}"/></p>
     </c:forEach>
    </body>
  </html>
</jsp:root>

Included the jar files got from the sample application and my java class ContentBean will be:
ContentBean.Class

package org.orgName.bean;

import java.util.*;
import javax.servlet.jsp.PageContext;
import org.alfresco.web.forms.FormDataFunctions;
import org.alfresco.web.forms.ServletContextFormDataFunctionsAdapter;
import org.w3c.dom.*;

public class ContentBean
{
    private final String content;
    public static List getContent(PageContext pageContext)
        throws Exception
    {
        FormDataFunctions ef = new ServletContextFormDataFunctionsAdapter(pageContext.getServletContext());
        Map entries = ef.parseXMLDocuments("test", "/test");
        List result = new ArrayList(entries.size());
        java.util.Map.Entry entry;
        for(Iterator i$ = entries.entrySet().iterator(); i$.hasNext(); result.add(loadPressRelease((Document)entry.getValue(), (String)entry.getKey())))
        {
            entry = (java.util.Map.Entry)i$.next();
        }

        return result;
    }

    private static ContentBean loadPressRelease(Document d, String fileName)
        throws Exception
    {
        Element a = (Element)d.getElementsByTagName("pr:body").item(0);
        return new ContentBean(a.getFirstChild().getNodeValue());
    }

    public ContentBean(String content)
    {
        this.content = content;
    }

    public String getContent()
    {
        return content;
    }
}

In my code i am using parseXMLDocuments to get the contents from "test" folder. Created new web contents using the web forms.
But getting some following errors in that parseXMLDocuments line

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.el.ELException: Problems calling function 'pr:getContent'
   org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.ssi.SSIFilter.doFilter(SSIFilter.java:110)
root cause

javax.el.ELException: Problems calling function 'pr:getContent'
   org.apache.el.parser.AstFunction.getValue(AstFunction.java:115)
   org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
   org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
   org.apache.jsp.sample_jsp._jspx_meth_c_005fforEach_005f0(sample_jsp.java:109)
   org.apache.jsp.sample_jsp._jspService(sample_jsp.java:82)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.ssi.SSIFilter.doFilter(SSIFilter.java:110)
root cause

java.lang.NullPointerException
   org.alfresco.web.forms.FormDataFunctions.parseXMLDocuments(FormDataFunctions.java:92)
   org.alfresco.web.forms.ServletContextFormDataFunctionsAdapter.parseXMLDocuments(ServletContextFormDataFunctionsAdapter.java:73)
   org.sysvine.bean.ContentBean.getContent(ContentBean.java:18)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.apache.el.parser.AstFunction.getValue(AstFunction.java:110)
   org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
   org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:925)
   org.apache.jsp.sample_jsp._jspx_meth_c_005fforEach_005f0(sample_jsp.java:109)
   org.apache.jsp.sample_jsp._jspService(sample_jsp.java:82)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   org.apache.catalina.ssi.SSIFilter.doFilter(SSIFilter.java:110)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

Can anyone suggest me the reason for the above error?
Thanks…

Outcomes