You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2010/12/20 04:59:38 UTC
svn commit: r1050978 - in /geronimo/server/trunk/plugins/myfaces:
geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/
geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/
geronimo-myfaces/src/main/java/...
Author: xuhaihong
Date: Mon Dec 20 03:59:37 2010
New Revision: 1050978
URL: http://svn.apache.org/viewvc?rev=1050978&view=rev
Log:
Implement facelet configuration SPI to find tag xml files in the deployed web application
Added:
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java (with props)
Modified:
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java?rev=1050978&r1=1050977&r2=1050978&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces-builder/src/main/java/org/apache/geronimo/myfaces/deployment/MyFacesModuleBuilderExtension.java Mon Dec 20 03:59:37 2010
@@ -130,6 +130,14 @@ public class MyFacesModuleBuilderExtensi
}
};
+ public static final EARContext.Key<Set<ConfigurationResource>> JSF_FACELET_CONFIG_RESOURCES = new EARContext.Key<Set<ConfigurationResource>>() {
+
+ @Override
+ public Set<ConfigurationResource> get(Map<EARContext.Key, Object> context) {
+ return (Set<ConfigurationResource>) context.get(this);
+ }
+ };
+
public MyFacesModuleBuilderExtension(@ParamAttribute(name = "defaultEnvironment") Environment defaultEnvironment,
@ParamAttribute(name = "providerFactoryNameQuery") AbstractNameQuery providerFactoryNameQuery,
@ParamReference(name = "NamingBuilders", namingType = NameFactory.MODULE_BUILDER) NamingBuilder namingBuilders) {
@@ -158,7 +166,6 @@ public class MyFacesModuleBuilderExtensi
if (!hasFacesServlet(webApp)) {
return;
}
-
EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), defaultEnvironment);
}
@@ -168,6 +175,7 @@ public class MyFacesModuleBuilderExtensi
return;
}
module.getEarContext().getGeneralData().put(JSF_META_INF_CONFIGURATION_RESOURCES, findMetaInfConfigurationResources(earContext, module));
+ module.getEarContext().getGeneralData().put(JSF_FACELET_CONFIG_RESOURCES, findFaceletConfigResources(earContext, module));
}
public void initContext(EARContext earContext, Module module, Bundle bundle) throws DeploymentException {
@@ -258,6 +266,7 @@ public class MyFacesModuleBuilderExtensi
AbstractName myFacesWebAppContextName = moduleContext.getNaming().createChildName(moduleName, "myFacesWebAppContext", "MyFacesWebAppContext");
GBeanData myFacesWebAppContextData = new GBeanData(myFacesWebAppContextName, MyFacesWebAppContext.class);
+ myFacesWebAppContextData.setAttribute("faceletConfigResources", JSF_FACELET_CONFIG_RESOURCES.get(earContext.getGeneralData()));
ClassLoader deploymentClassLoader = new BundleClassLoader(bundle);
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
@@ -448,10 +457,7 @@ public class MyFacesModuleBuilderExtensi
// Scan config files named as faces-config.xml or *.faces-config.xml under META-INF
if (name.equals("META-INF/faces-config.xml") || (name.startsWith("META-INF/") && name.endsWith(".faces-config.xml"))) {
//TODO Double check the relative jar file path once EAR is really supported
- //TODO Should find a way to avoid the file copying
- String destination = "META-INF/WEB-INF_lib_" + file.getName() + "/" + name;
- earContext.addFile(module.resolve(destination), jarFile, zipEntry);
- metaInfConfigurationResources.add(new ConfigurationResource("WEB-INF/lib/" + file.getName(), name, destination));
+ metaInfConfigurationResources.add(new ConfigurationResource("WEB-INF/lib/" + file.getName(), name));
}
}
} catch (Exception e) {
@@ -466,11 +472,14 @@ public class MyFacesModuleBuilderExtensi
File webInfClassesDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "META-INF");
if (webInfClassesDirectory.exists() && webInfClassesDirectory.isDirectory()) {
for (File file : webInfClassesDirectory.listFiles()) {
+ if (file.isDirectory()) {
+ continue;
+ }
String fileName = file.getName();
if (fileName.equals("faces-config.xml") || fileName.endsWith(".faces-config.xml")) {
//TODO Double check the relative jar file path once EAR is really supported
String filePath = "WEB-INF/classes/META-INF/" + fileName;
- metaInfConfigurationResources.add(new ConfigurationResource(null, filePath, filePath));
+ metaInfConfigurationResources.add(new ConfigurationResource(null, filePath));
}
}
}
@@ -478,17 +487,92 @@ public class MyFacesModuleBuilderExtensi
File baseDirectory = new File(earContext.getBaseDir() + File.separator + "META-INF");
if (baseDirectory.exists() && baseDirectory.isDirectory()) {
for (File file : baseDirectory.listFiles()) {
+ if (file.isDirectory()) {
+ continue;
+ }
String fileName = file.getName();
if (fileName.equals("faces-config.xml") || fileName.endsWith(".faces-config.xml")) {
//TODO Double check the relative jar file path once EAR is really supported
String filePath = "META-INF/" + fileName;
- metaInfConfigurationResources.add(new ConfigurationResource(null, filePath, filePath));
+ metaInfConfigurationResources.add(new ConfigurationResource(null, filePath));
}
}
}
return metaInfConfigurationResources;
}
+ protected Set<ConfigurationResource> findFaceletConfigResources(EARContext earContext, Module module) throws DeploymentException {
+ Set<ConfigurationResource> faceletConfigResources = new HashSet<ConfigurationResource>();
+ //1. jar files in the WEB-INF/lib folder
+ File libDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "lib");
+ if (libDirectory.exists()) {
+ for (File file : libDirectory.listFiles()) {
+ if (!file.getName().endsWith(".jar")) {
+ continue;
+ }
+ try {
+ if (!JarUtils.isJarFile(file)) {
+ continue;
+ }
+ } catch (IOException e) {
+ continue;
+ }
+ ZipInputStream in = null;
+ JarFile jarFile = null;
+ try {
+ jarFile = new JarFile(file);
+ in = new ZipInputStream(new FileInputStream(file));
+ ZipEntry zipEntry;
+
+ while ((zipEntry = in.getNextEntry()) != null) {
+ String name = zipEntry.getName();
+ // Scan config files named as faces-config.xml or *.faces-config.xml under META-INF
+ if (name.startsWith("META-INF/") && name.endsWith(".taglib.xml")) {
+ //TODO Double check the relative jar file path once EAR is really supported
+ faceletConfigResources.add(new ConfigurationResource("WEB-INF/lib/" + file.getName(), name));
+ }
+ }
+ } catch (Exception e) {
+ throw new DeploymentException("Can not preprocess myfaces application configuration resources", e);
+ } finally {
+ IOUtils.close(in);
+ JarUtils.close(jarFile);
+ }
+ }
+ }
+ //2. WEB-INF/classes/META-INF folder
+ File webInfClassesDirectory = new File(earContext.getBaseDir() + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "META-INF");
+ if (webInfClassesDirectory.exists() && webInfClassesDirectory.isDirectory()) {
+ for (File file : webInfClassesDirectory.listFiles()) {
+ if (file.isDirectory()) {
+ continue;
+ }
+ String fileName = file.getName();
+ if (fileName.equals("faces-config.xml") || fileName.endsWith(".taglib.xml")) {
+ //TODO Double check the relative jar file path once EAR is really supported
+ String filePath = "WEB-INF/classes/META-INF/" + fileName;
+ faceletConfigResources.add(new ConfigurationResource(null, filePath));
+ }
+ }
+ }
+ //3. META-INF folder
+ File baseDirectory = new File(earContext.getBaseDir() + File.separator + "META-INF");
+ if (baseDirectory.exists() && baseDirectory.isDirectory()) {
+ for (File file : baseDirectory.listFiles()) {
+ if (file.isDirectory()) {
+ continue;
+ }
+ String fileName = file.getName();
+ if (fileName.endsWith(".taglib.xml")) {
+ //TODO Double check the relative jar file path once EAR is really supported
+ String filePath = "META-INF/" + fileName;
+ faceletConfigResources.add(new ConfigurationResource(null, filePath));
+ }
+ }
+ }
+ return faceletConfigResources;
+ }
+
private boolean hasFacesServlet(WebApp webApp) {
for (Servlet servlet : webApp.getServlet()) {
if (servlet.getServletClass() != null && FACES_SERVLET_NAME.equals(servlet.getServletClass().trim())) {
Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java?rev=1050978&r1=1050977&r2=1050978&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/config/resource/ConfigurationResource.java Mon Dec 20 03:59:37 2010
@@ -32,12 +32,9 @@ public class ConfigurationResource imple
private String jarFilePath;
- private String tempPath;
-
- public ConfigurationResource(String jarFilePath, String configurationResourcePath, String tempPath) {
+ public ConfigurationResource(String jarFilePath, String configurationResourcePath) {
this.jarFilePath = jarFilePath;
- this.configurationResourcePath = configurationResourcePath;
- this.tempPath = tempPath;
+ this.configurationResourcePath = configurationResourcePath.startsWith("/") ? configurationResourcePath : "/" + configurationResourcePath;
}
public String getConfigurationResourcePath() {
@@ -57,7 +54,10 @@ public class ConfigurationResource imple
}
public URL getConfigurationResourceURL(Bundle bundle) throws MalformedURLException {
- return bundle.getEntry(tempPath);
+ if (jarFilePath == null) {
+ return bundle.getEntry(configurationResourcePath);
+ }
+ return new URL("jar:" + bundle.getEntry(jarFilePath) + "!" + configurationResourcePath);
}
@Override
Added: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java?rev=1050978&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java (added)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java Mon Dec 20 03:59:37 2010
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.myfaces.facelet;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.geronimo.myfaces.webapp.MyFacesWebAppContext;
+import org.apache.geronimo.osgi.web.WebApplicationConstants;
+import org.apache.myfaces.spi.FaceletConfigResourceProvider;
+import org.apache.myfaces.spi.FaceletConfigResourceProviderFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoFaceletConfigResourceProviderFactory extends FaceletConfigResourceProviderFactory {
+
+ private FaceletConfigResourceProvider faceletConfigResourceProvider;
+
+ @Override
+ public FaceletConfigResourceProvider createFaceletConfigResourceProvider(ExternalContext externalContext) {
+ if (faceletConfigResourceProvider == null) {
+ Bundle bundle = ((BundleContext) externalContext.getApplicationMap().get(WebApplicationConstants.BUNDLE_CONTEXT_ATTRIBUTE)).getBundle();
+ final MyFacesWebAppContext myFacesWebAppContext = MyFacesWebAppContext.getMyFacesWebAppContext(bundle);
+ faceletConfigResourceProvider = new FaceletConfigResourceProvider() {
+
+ @Override
+ public Collection<URL> getFaceletTagLibConfigurationResources(ExternalContext arg0) throws IOException {
+ return myFacesWebAppContext.getRuntimeFaceletConfigResources();
+ }
+
+ };
+ }
+ return faceletConfigResourceProvider;
+ }
+
+}
Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/facelet/GeronimoFaceletConfigResourceProviderFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java?rev=1050978&r1=1050977&r2=1050978&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/GeronimoStartupServletContextListener.java Mon Dec 20 03:59:37 2010
@@ -20,11 +20,13 @@ package org.apache.geronimo.myfaces.weba
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
+import org.apache.geronimo.myfaces.facelet.GeronimoFaceletConfigResourceProviderFactory;
import org.apache.geronimo.myfaces.info.GeronimoFacesConfigurationMergerFactory;
import org.apache.geronimo.osgi.web.WebApplicationConstants;
import org.apache.geronimo.web.WebAttributeName;
import org.apache.geronimo.web.info.WebAppInfo;
import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+import org.apache.myfaces.spi.FaceletConfigResourceProviderFactory;
import org.apache.myfaces.spi.FacesConfigurationMergerFactory;
import org.apache.myfaces.webapp.StartupServletContextListener;
import org.osgi.framework.Bundle;
@@ -49,6 +51,7 @@ public class GeronimoStartupServletConte
runtimeSpiProviders.put(FacesConfigurationMergerFactory.class.getName(), Arrays.asList(GeronimoFacesConfigurationMergerFactory.class.getName()));
ServiceProviderFinderFactory.setServiceProviderFinder(servletContext, new GeronimoServiceProviderFinder(runtimeSpiProviders, webAppContext.getClassLoader()));*/
servletContext.setAttribute(FacesConfigurationMergerFactory.class.getName(), new GeronimoFacesConfigurationMergerFactory());
+ servletContext.setAttribute(FaceletConfigResourceProviderFactory.class.getName(), new GeronimoFaceletConfigResourceProviderFactory());
super.contextInitialized(servletContextEvent);
}
}
Modified: geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java?rev=1050978&r1=1050977&r2=1050978&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java (original)
+++ geronimo/server/trunk/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/webapp/MyFacesWebAppContext.java Mon Dec 20 03:59:37 2010
@@ -17,7 +17,12 @@
package org.apache.geronimo.myfaces.webapp;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.geronimo.gbean.GBeanLifecycle;
@@ -25,6 +30,7 @@ import org.apache.geronimo.gbean.annotat
import org.apache.geronimo.gbean.annotation.ParamAttribute;
import org.apache.geronimo.gbean.annotation.ParamSpecial;
import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.apache.geronimo.myfaces.config.resource.ConfigurationResource;
import org.apache.myfaces.config.element.FacesConfigData;
import org.osgi.framework.Bundle;
@@ -42,11 +48,23 @@ public class MyFacesWebAppContext implem
private ClassLoader classLoader;
- public MyFacesWebAppContext(@ParamAttribute(name = "facesConfigData") FacesConfigData facesConfigData, @ParamSpecial(type = SpecialAttributeType.bundle) Bundle bundle,
- @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) {
+ private List<URL> faceletConfigResources;
+
+ public MyFacesWebAppContext(@ParamAttribute(name = "facesConfigData") FacesConfigData facesConfigData,
+ @ParamAttribute(name = "faceletConfigResources") Set<ConfigurationResource> faceletConfigResources,
+ @ParamSpecial(type = SpecialAttributeType.bundle) Bundle bundle,
+ @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) {
this.bundle = bundle;
this.facesConfigData = facesConfigData;
this.classLoader = classLoader;
+ this.faceletConfigResources = new ArrayList<URL>(faceletConfigResources.size());
+ try {
+ for (ConfigurationResource faceletConfigResource : faceletConfigResources) {
+ this.faceletConfigResources.add(faceletConfigResource.getConfigurationResourceURL(bundle));
+ }
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
}
public FacesConfigData getFacesConfigData() {
@@ -57,6 +75,10 @@ public class MyFacesWebAppContext implem
return classLoader;
}
+ public List<URL> getRuntimeFaceletConfigResources() {
+ return faceletConfigResources;
+ }
+
@Override
public void doFail() {
try {