Author: julien(a)jboss.com
Date: 2007-07-12 08:37:06 -0400 (Thu, 12 Jul 2007)
New Revision: 7732
Added:
trunk/faces/src/main/org/jboss/portal/faces/loader/
trunk/faces/src/main/org/jboss/portal/faces/loader/FacesClassLoader.java
trunk/faces/src/main/org/jboss/portal/faces/loader/FacesLoaderServlet.java
trunk/faces/src/main/org/jboss/portal/faces/loader/FacesPortlet.java
Modified:
trunk/core-admin/build.xml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portlet.xml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/web.xml
trunk/faces/build.xml
Log:
Faces loader implementation
Modified: trunk/core-admin/build.xml
===================================================================
--- trunk/core-admin/build.xml 2007-07-12 05:27:37 UTC (rev 7731)
+++ trunk/core-admin/build.xml 2007-07-12 12:37:06 UTC (rev 7732)
@@ -186,29 +186,41 @@
<!-- portal-core-admin-lib.jar -->
<jar jarfile="${build.lib}/portal-core-admin-lib.jar">
- <fileset dir="${build.classes}">
- </fileset>
+ <fileset dir="${build.classes}"/>
</jar>
+ <!-- portal-admin.war -->
+ <copy todir="${build.resources}/portal-admin.war/WEB-INF/lib2">
+ <fileset dir="${apache.myfaces.lib}"
includes="myfaces-api.jar,myfaces-impl.jar,jstl.jar"/>
+ <fileset dir="${build.lib}"
includes="portal-core-admin-lib.jar"/>
+ <fileset dir="${apache.myfaces.lib}"
includes="myfaces-api.jar,myfaces-impl.jar,jstl.jar"/>
+ <fileset dir="${jboss.portal-faces.root}/lib"
includes="portal-faces-lib.jar"/>
+ <fileset dir="../core-admin/src/etc/sun-jsf"
includes="jsf-example.jar"/>
+ <fileset dir="${facelets.facelets.lib}"
includes="jsf-facelets.jar"/>
+ <fileset dir="${el.el.lib}"
includes="el-api.jar,el-ri.jar"/>
+ <fileset dir="${portals.bridges/jsf.portlet.lib}"
includes="jsf-portlet.jar"/>
+ </copy>
+ <copy todir="${build.resources}/portal-admin.war">
+ <fileset dir="${source.bin}/portal-admin-war"/>
+ <fileset dir="${build.resources}/portal-admin-war"/>
+ </copy>
+
<!-- portal-admin.sar -->
<copy todir="${build.resources}/portal-admin.sar">
<fileset dir="${build.resources}/portal-admin-sar"/>
</copy>
<copy todir="${build.resources}/portal-admin.sar/lib">
- <fileset dir="${build.lib}"
includes="portal-core-admin-lib.jar"/>
- <!--<fileset dir="."
includes="jsf-portlet.jar"/>-->
+ <fileset dir="${jboss.portal-faces.root}/lib"
includes="portal-faces-loader-lib.jar"/>
+
<!-- For JSF -->
- <fileset dir="${jboss.portal-faces.root}/lib"
includes="portal-faces-lib.jar"/>
- <fileset dir="../core-admin/src/etc/sun-jsf"
includes="jsf-example.jar"/>
- <fileset dir="${facelets.facelets.lib}"
includes="jsf-facelets.jar"/>
- <fileset dir="${el.el.lib}"
includes="el-api.jar,el-ri.jar"/>
- <fileset dir="${portals.bridges/jsf.portlet.lib}"
includes="jsf-portlet.jar"/>
+ <fileset dir="${apache.beanutils.lib}"
includes="commons-beanutils.jar"/>
+ <fileset dir="${apache.digester.lib}"
includes="commons-digester-1.6.jar"/>
+ <fileset dir="${commons.el.lib}"
includes="commons-el.jar"/>
+
</copy>
-
<copy
todir="${build.resources}/portal-admin.sar/portal-admin.war">
- <fileset dir="${build.resources}/portal-admin-war"/>
- <fileset dir="${source.bin}/portal-admin-war"/>
+ <fileset dir="${build.resources}/portal-admin.war"/>
</copy>
</target>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portlet.xml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portlet.xml 2007-07-12
05:27:37 UTC (rev 7731)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portlet.xml 2007-07-12
12:37:06 UTC (rev 7732)
@@ -31,9 +31,9 @@
<description>Administration Portlet</description>
<portlet-name>AdminPortlet</portlet-name>
<display-name>Administration Portlet</display-name>
-
<portlet-class>org.jboss.portal.faces.portlet.JSFMetaBridgePortlet</portlet-class>
+
<portlet-class>org.jboss.portal.faces.loader.FacesPortlet</portlet-class>
<init-param>
- <name>VIEW</name>
+ <name>default-view</name>
<value>/WEB-INF/jsf/objects.xhtml</value>
</init-param>
<supports>
@@ -49,9 +49,9 @@
<description>Dashboard Configurator Portlet</description>
<portlet-name>DashboardConfigPortlet</portlet-name>
<display-name>Dashboard Configurator Portlet</display-name>
-
<portlet-class>org.jboss.portal.faces.portlet.JSFMetaBridgePortlet</portlet-class>
+
<portlet-class>org.jboss.portal.faces.loader.FacesPortlet</portlet-class>
<init-param>
- <name>VIEW</name>
+ <name>default-view</name>
<value>/WEB-INF/jsf/dashboard/dashboard.xhtml</value>
</init-param>
<expiration-cache>-1</expiration-cache>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/web.xml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/web.xml 2007-07-12 05:27:37
UTC (rev 7731)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/web.xml 2007-07-12 12:37:06
UTC (rev 7732)
@@ -77,13 +77,7 @@
<!-- The JSF servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+
<servlet-class>org.jboss.portal.faces.loader.FacesLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-
- <!-- The JSF meta bridge bootstrap -->
- <listener>
- <display-name> Faces Meta Bridge Bootstrap</display-name>
-
<listener-class>org.jboss.portal.faces.portlet.JSFMetaBridgeBootstrap</listener-class>
- </listener>
</web-app>
Modified: trunk/faces/build.xml
===================================================================
--- trunk/faces/build.xml 2007-07-12 05:27:37 UTC (rev 7731)
+++ trunk/faces/build.xml 2007-07-12 12:37:06 UTC (rev 7732)
@@ -154,10 +154,16 @@
<!-- portal-faces-lib.jar -->
<mkdir dir="${build.lib}"/>
<jar jarfile="${build.lib}/portal-faces-lib.jar">
- <fileset dir="${build.classes}"/>
+ <fileset dir="${build.classes}"
excludes="org/jboss/portal/faces/loader/**"/>
<fileset dir="${build.resources}/portal-faces-lib-jar"
includes="**/*"/>
</jar>
+ <!-- portal-faces-loader-lib.jar -->
+ <mkdir dir="${build.lib}"/>
+ <jar jarfile="${build.lib}/portal-faces-loader-lib.jar">
+ <fileset dir="${build.classes}"
includes="org/jboss/portal/faces/loader/**"/>
+ </jar>
+
<!-- portal-faces.war -->
<mkdir dir="${build.resources}/portal-faces-war/WEB-INF/lib"/>
<copy todir="${build.resources}/portal-faces-war/WEB-INF/lib">
Added: trunk/faces/src/main/org/jboss/portal/faces/loader/FacesClassLoader.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/loader/FacesClassLoader.java
(rev 0)
+++ trunk/faces/src/main/org/jboss/portal/faces/loader/FacesClassLoader.java 2007-07-12
12:37:06 UTC (rev 7732)
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.loader;
+
+import org.apache.log4j.Logger;
+
+import java.net.URLClassLoader;
+import java.net.URL;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FacesClassLoader extends URLClassLoader
+{
+
+ /** . */
+ private final Logger log = Logger.getLogger(FacesClassLoader.class);
+
+ public FacesClassLoader(URL[] urls, ClassLoader classLoader)
+ {
+ super(urls, classLoader);
+ }
+
+ private final Map cache = new HashMap();
+
+ protected synchronized Class loadClass(String name, boolean resolve) throws
ClassNotFoundException
+ {
+ if (name.startsWith("javax.faces") ||
name.startsWith("org.apache.myfaces"))
+ {
+ log.debug("Want to load " + name + " locally");
+ return locateClass(name);
+ }
+
+ //
+ try
+ {
+ log.debug("Want to load " + name + " will delegate");
+ return super.loadClass(name, resolve);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.debug("Not found in the parent will try to load " + name + "
locally");
+ return locateClass(name);
+ }
+ }
+
+ private Class locateClass(String name) throws ClassNotFoundException
+ {
+ //
+ Class clazz = (Class)cache.get(name);
+
+ //
+ if (clazz == null)
+ {
+ clazz = findClass(name);
+ cache.put(name, clazz);
+ }
+
+ //
+ return clazz;
+ }
+
+}
Added: trunk/faces/src/main/org/jboss/portal/faces/loader/FacesLoaderServlet.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/loader/FacesLoaderServlet.java
(rev 0)
+++ trunk/faces/src/main/org/jboss/portal/faces/loader/FacesLoaderServlet.java 2007-07-12
12:37:06 UTC (rev 7732)
@@ -0,0 +1,195 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.loader;
+
+import org.apache.log4j.Logger;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextEvent;
+import java.net.URL;
+import java.util.ArrayList;
+import java.io.File;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FacesLoaderServlet extends HttpServlet
+{
+
+ /** . */
+ private final static Logger log = Logger.getLogger(FacesLoaderServlet.class);
+
+ /** . */
+ private final String servletContextListenerClassName =
"org.apache.myfaces.webapp.StartupServletContextListener";
+
+ /** . */
+ private FacesClassLoader loader;
+
+ /** . */
+ private ServletContextListener listener;
+
+ /** . */
+ private Servlet servlet;
+
+ public void init() throws ServletException
+ {
+ try
+ {
+ ServletContext ctx = getServletConfig().getServletContext();
+
+ ArrayList tmp = new ArrayList();
+ File f = new File(ctx.getRealPath("/WEB-INF/lib2/"));
+ File[] libs = f.listFiles();
+ for (int i = 0; i < libs.length; i++)
+ {
+ File lib = libs[i];
+ URL libURL = lib.toURL();
+ log.debug("Added " + libURL + " to faces class loader");
+ tmp.add(libURL);
+ }
+ URL[] urls = (URL[])tmp.toArray(new URL[tmp.size()]);
+
+ //
+ loader = new FacesClassLoader(urls,
Thread.currentThread().getContextClassLoader());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ //
+ if (loader != null)
+ {
+
getServletConfig().getServletContext().setAttribute("FACESCLASSLOADER",
loader);
+ ClassLoader containerLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+
+ //
+ try
+ {
+ // Perform myfaces bootstrap
+ initMyFaces();
+
+ //
+ initFacesServlet();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(containerLoader);
+ }
+ }
+ }
+
+ public void destroy()
+ {
+ if (loader != null)
+ {
+ ClassLoader containerLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+
+ //
+ try
+ {
+ //
+ destroyFacesServlet();
+
+ //
+ destroyMyFaces();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(containerLoader);
+ }
+ }
+ }
+
+
+ private void initFacesServlet()
+ {
+ try
+ {
+ Class facesServletClass =
loader.loadClass("javax.faces.webapp.FacesServlet");
+ servlet = (Servlet)facesServletClass.newInstance();
+ servlet.init(getServletConfig());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void destroyFacesServlet()
+ {
+ if (servlet != null)
+ {
+ servlet.destroy();
+ }
+ }
+
+ private void initMyFaces()
+ {
+ try
+ {
+ Class bridgeClass =
Thread.currentThread().getContextClassLoader().loadClass(servletContextListenerClassName);
+ log.debug("Obtain bridge bootstrap class " + bridgeClass.getName());
+ listener = (ServletContextListener)bridgeClass.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ // It is not an error, this happens when we run with Sun RI
+ log.debug("Bridge bootstrap not available " +
servletContextListenerClassName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.error("Bridge bootstrap not accessible " +
servletContextListenerClassName, e);
+ }
+ catch (InstantiationException e)
+ {
+ log.error("Bridge bootstrap not instantiable " +
servletContextListenerClassName, e);
+ }
+
+ //
+ if (listener != null)
+ {
+ log.debug("About to initialize the bridge bootstrap");
+ ServletContextEvent event = new
ServletContextEvent(getServletConfig().getServletContext());
+ listener.contextInitialized(event);
+ }
+ }
+
+ private void destroyMyFaces()
+ {
+ if (listener != null)
+ {
+ log.debug("About to destroy the bridge bootstrap");
+ ServletContextEvent event = new
ServletContextEvent(getServletConfig().getServletContext());
+ listener.contextDestroyed(event);
+ }
+ }
+
+}
Added: trunk/faces/src/main/org/jboss/portal/faces/loader/FacesPortlet.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/loader/FacesPortlet.java
(rev 0)
+++ trunk/faces/src/main/org/jboss/portal/faces/loader/FacesPortlet.java 2007-07-12
12:37:06 UTC (rev 7732)
@@ -0,0 +1,118 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.loader;
+
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FacesPortlet implements Portlet
+{
+
+ /** . */
+ private Portlet portlet;
+
+ /** . */
+ private ClassLoader loader;
+
+ public void init(PortletConfig config) throws PortletException
+ {
+ try
+ {
+ loader =
(ClassLoader)config.getPortletContext().getAttribute("FACESCLASSLOADER");
+ if (loader != null)
+ {
+ ClassLoader containerLoader =
Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ try
+ {
+ Class facesServletClass =
loader.loadClass("org.apache.myfaces.portlet.MyFacesGenericPortlet");
+ portlet = (Portlet)facesServletClass.newInstance();
+ portlet.init(config);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(containerLoader);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void processAction(ActionRequest request, ActionResponse response) throws
PortletException, PortletSecurityException, IOException
+ {
+ if (portlet != null)
+ {
+ ClassLoader containerLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ try
+ {
+ portlet.processAction(request, response);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(containerLoader);
+ }
+ }
+ }
+
+ public void render(RenderRequest request, RenderResponse response) throws
PortletException, PortletSecurityException, IOException
+ {
+ if (portlet != null)
+ {
+ ClassLoader containerLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ try
+ {
+ portlet.render(request, response);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(containerLoader);
+ }
+ }
+ }
+
+ public void destroy()
+ {
+ if (portlet != null)
+ {
+ portlet.destroy();
+ portlet = null;
+ loader = null;
+ }
+ }
+}