Author: nbelaevski
Date: 2010-09-09 19:54:09 -0400 (Thu, 09 Sep 2010)
New Revision: 19151
Added:
trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java
trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibraryFactory.java
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceLibraryFactoryImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java
trunk/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml
trunk/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java
trunk/core/impl/src/test/java/org/richfaces/resource/ResourceLibraryTest.java
trunk/core/impl/src/test/java/org/richfaces/view/
trunk/core/impl/src/test/java/org/richfaces/view/facelets/
trunk/core/impl/src/test/java/org/richfaces/view/facelets/AnyComponentHandler.java
trunk/core/impl/src/test/resources/META-INF/richfaces/
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/dynamic.library.properties
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/static.library.properties
trunk/core/impl/src/test/resources/META-INF/test.taglib.xml
trunk/core/impl/src/test/resources/org/richfaces/resource/
trunk/core/impl/src/test/resources/org/richfaces/resource/simple.xhtml
Modified:
trunk/core/api/src/main/java/org/richfaces/resource/ResourceKey.java
trunk/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
trunk/core/impl/src/main/java/org/richfaces/util/PropertiesUtil.java
Log:
Support for resource libraries check in
Modified: trunk/core/api/src/main/java/org/richfaces/resource/ResourceKey.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/ResourceKey.java 2010-09-09
20:57:36 UTC (rev 19150)
+++ trunk/core/api/src/main/java/org/richfaces/resource/ResourceKey.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -21,6 +21,7 @@
*/
package org.richfaces.resource;
+import com.google.common.base.Function;
import com.google.common.base.Objects;
/**
@@ -29,6 +30,12 @@
*/
public class ResourceKey {
+ public static final Function<String, ResourceKey> FACTORY = new
Function<String, ResourceKey>() {
+ public ResourceKey apply(String from) {
+ return new ResourceKey(from);
+ };
+ };
+
private String resourceName;
private String libraryName;
Added: trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java
(rev 0)
+++ trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceLibrary {
+
+ public ResourceKey[] getResources(FacesContext context);
+
+}
Added: trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibraryFactory.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibraryFactory.java
(rev 0)
+++
trunk/core/api/src/main/java/org/richfaces/resource/ResourceLibraryFactory.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceLibraryFactory {
+
+ public ResourceLibrary getResourceLibrary(String name, String library);
+
+}
Modified: trunk/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-09-09
20:57:36 UTC (rev 19150)
+++ trunk/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -8,6 +8,8 @@
import org.richfaces.renderkit.AjaxDataSerializerImpl;
import org.richfaces.resource.DefaultResourceCodec;
import org.richfaces.resource.ResourceCodec;
+import org.richfaces.resource.ResourceLibraryFactory;
+import org.richfaces.resource.ResourceLibraryFactoryImpl;
import org.richfaces.skin.SkinFactory;
import org.richfaces.skin.SkinFactoryImpl;
@@ -22,6 +24,7 @@
factory.setInstance(Uptime.class, new Uptime());
factory.setInstance(DependencyInjector.class, new
DependencyInjectionServiceImpl());
factory.setInstance(MessageFactory.class, new MessageFactoryImpl(new
BundleLoader()));
+ factory.setInstance(ResourceLibraryFactory.class, new
ResourceLibraryFactoryImpl());
}
}
Added:
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java
(rev 0)
+++
trunk/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.resource.ResourceKey;
+import org.richfaces.resource.ResourceLibrary;
+import org.richfaces.resource.ResourceLibraryFactory;
+
+import com.google.common.base.Joiner;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceLibraryRenderer extends Renderer {
+
+ public static final String RENDERER_TYPE =
"org.richfaces.renderkit.ResourceLibraryRenderer";
+
+ public static final String RESOURCE_LIBRARY_EXTENSION = ".reslib";
+
+ private static final Logger LOGGER = RichfacesLogger.RENDERKIT.getLogger();
+
+ private static final Joiner COLON_JOINER = Joiner.on(':').skipNulls();
+
+ public ResourceLibraryRenderer() {
+ super();
+ }
+
+ private void setupResourceAttributes(UIComponent component, ResourceKey resourceKey)
{
+ Map<String, Object> attributes = component.getAttributes();
+
+ attributes.put("name", resourceKey.getResourceName());
+
+ String libraryName = resourceKey.getLibraryName();
+ if (libraryName != null) {
+ attributes.put("library", libraryName);
+ } else {
+ attributes.remove("library");
+ }
+ }
+
+ @Override
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
+ Map<String, Object> attributes = component.getAttributes();
+
+ String name = (String) attributes.get("name");
+
+ if (!name.endsWith(RESOURCE_LIBRARY_EXTENSION)) {
+ throw new IllegalArgumentException("Resource library name: " + name
+ " is incorrect");
+ }
+
+ name = name.substring(0, name.length() - RESOURCE_LIBRARY_EXTENSION.length());
+
+ String library = (String) attributes.get("library");
+
+ ResourceLibraryFactory factory =
ServiceTracker.getService(ResourceLibraryFactory.class);
+ ResourceLibrary resourceLibrary = factory.getResourceLibrary(name, library);
+
+ if (resourceLibrary == null) {
+ LOGGER.error("Resource library is null: " +
COLON_JOINER.join(library, name));
+ return;
+ }
+
+ Application application = context.getApplication();
+ UIComponent resourceComponent = null;
+
+ for (ResourceKey resourceKey: resourceLibrary.getResources(context)) {
+ String rendererType =
application.getResourceHandler().getRendererTypeForResourceName(resourceKey.getResourceName());
+
+ if (resourceComponent == null) {
+ resourceComponent =
application.createComponent(UIOutput.COMPONENT_TYPE);
+ resourceComponent.setTransient(true);
+ component.getChildren().add(resourceComponent);
+ }
+
+ resourceComponent.setRendererType(rendererType);
+ setupResourceAttributes(resourceComponent, resourceKey);
+
+ resourceComponent.encodeAll(context);
+ }
+ }
+
+}
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-09-09
20:57:36 UTC (rev 19150)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -27,7 +27,6 @@
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Properties;
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
@@ -179,9 +178,7 @@
private <V> Map<ResourceKey, V> readMappings(Function<Entry<String,
String>, V> producer, String mappingFileName) {
Map<ResourceKey, V> result = Maps.newHashMap();
- Properties properties = new Properties();
- PropertiesUtil.loadProperties(properties, mappingFileName);
- for (Entry<String, String> entry :
Maps.fromProperties(properties).entrySet()) {
+ for (Entry<String, String> entry :
PropertiesUtil.loadProperties(mappingFileName).entrySet()) {
result.put(new ResourceKey(entry.getKey()), producer.apply(entry));
}
Modified: trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-09-09
20:57:36 UTC (rev 19150)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -42,6 +42,7 @@
import org.richfaces.cache.Cache;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.renderkit.html.ResourceLibraryRenderer;
import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
import org.richfaces.util.Util;
@@ -291,6 +292,10 @@
return "javax.faces.resource.Stylesheet";
}
+ if (resourceName.endsWith(ResourceLibraryRenderer.RESOURCE_LIBRARY_EXTENSION)) {
+ return ResourceLibraryRenderer.RENDERER_TYPE;
+ }
+
return defaultHandler.getRendererTypeForResourceName(resourceName);
}
Added:
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceLibraryFactoryImpl.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/resource/ResourceLibraryFactoryImpl.java
(rev 0)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/ResourceLibraryFactoryImpl.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+import java.util.Map;
+
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.util.PropertiesUtil;
+
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.MapMaker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceLibraryFactoryImpl implements ResourceLibraryFactory {
+
+ private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
+
+ private static final Joiner SLASH_JOINER = Joiner.on('/').skipNulls();
+
+ private static final Splitter COMA_SPLITTER =
Splitter.on(',').omitEmptyStrings().trimResults();
+
+ private Map<ResourceKey, ResourceLibrary> instances = new
MapMaker().makeComputingMap(new Function<ResourceKey, ResourceLibrary>() {
+
+ public ResourceLibrary apply(ResourceKey from) {
+ String propsResourceName = from.getResourceName() +
".library.properties";
+
+ Map<String, String> props =
PropertiesUtil.loadProperties("META-INF/richfaces/" +
SLASH_JOINER.join(from.getLibraryName(), propsResourceName));
+
+ String libraryClass = props.get("class");
+ String resources = props.get("resources");
+
+ if (libraryClass != null) {
+ try {
+ Class<?> clazz = Class.forName(libraryClass.trim(), false,
Thread.currentThread().getContextClassLoader());
+ return (ResourceLibrary) clazz.newInstance();
+ } catch (ClassNotFoundException e) {
+ LOGGER.error(e.getMessage(), e);
+ } catch (InstantiationException e) {
+ LOGGER.error(e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ } else if (resources != null) {
+ Iterable<ResourceKey> keys =
Iterables.transform(COMA_SPLITTER.split(resources), ResourceKey.FACTORY);
+ return new StaticResourceLibrary(Iterables.toArray(keys,
ResourceKey.class));
+ } else {
+ LOGGER.error("'class' or 'resources' properties
should be declared in library descriptor: " + from);
+ }
+
+ return null;
+ }
+ });
+
+ public ResourceLibrary getResourceLibrary(String name, String library) {
+ return instances.get(new ResourceKey(name, library));
+ }
+
+}
Added: trunk/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java
(rev 0)
+++
trunk/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+class StaticResourceLibrary implements ResourceLibrary {
+
+ private ResourceKey[] keys;
+
+ public StaticResourceLibrary(ResourceKey[] keys) {
+ super();
+ this.keys = keys;
+ }
+
+ public ResourceKey[] getResources(FacesContext context) {
+ return keys;
+ }
+
+}
Modified: trunk/core/impl/src/main/java/org/richfaces/util/PropertiesUtil.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/util/PropertiesUtil.java 2010-09-09
20:57:36 UTC (rev 19150)
+++ trunk/core/impl/src/main/java/org/richfaces/util/PropertiesUtil.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -26,12 +26,15 @@
import java.net.URL;
import java.text.MessageFormat;
import java.util.Enumeration;
+import java.util.Map;
import java.util.Properties;
import org.ajax4jsf.resource.util.URLToStreamHelper;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
+import com.google.common.collect.Maps;
+
/**
* @author Nick Belaevski
*
@@ -87,4 +90,11 @@
return loaded;
}
+
+ public static Map<String, String> loadProperties(String location) {
+ Properties props = new Properties();
+ loadProperties(props, location);
+ return Maps.fromProperties(props);
+ }
+
}
Added: trunk/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml
===================================================================
--- trunk/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml
(rev 0)
+++
trunk/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+ version="2.0">
+ <name>richfaces</name>
+
+ <render-kit>
+ <renderer>
+ <component-family>javax.faces.Output</component-family>
+
<renderer-type>org.richfaces.renderkit.ResourceLibraryRenderer</renderer-type>
+
<renderer-class>org.richfaces.renderkit.html.ResourceLibraryRenderer</renderer-class>
+ </renderer>
+ </render-kit>
+
+</faces-config>
Added: trunk/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java
(rev 0)
+++
trunk/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DynamicResourceLibrary implements ResourceLibrary {
+
+ private ResourceKey[] keys = new ResourceKey[] {
+ new ResourceKey("skinning_classes.ecss"), new
ResourceKey("jquery.js", null)
+ };
+
+ public ResourceKey[] getResources(FacesContext context) {
+ return keys;
+ }
+
+}
Added: trunk/core/impl/src/test/java/org/richfaces/resource/ResourceLibraryTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/resource/ResourceLibraryTest.java
(rev 0)
+++
trunk/core/impl/src/test/java/org/richfaces/resource/ResourceLibraryTest.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.resource;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponentBase;
+
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Element;
+
+import com.gargoylesoftware.htmlunit.html.HtmlLink;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceLibraryTest {
+
+ @ResourceDependency(library = "org.richfaces", name =
"static.reslib")
+ public static class StaticLibraryComponent extends UIComponentBase {
+
+ @Override
+ public String getFamily() {
+ return null;
+ }
+
+ }
+
+ @ResourceDependency(library = "org.richfaces", name =
"dynamic.reslib")
+ public static class DynamicLibraryComponent extends UIComponentBase {
+
+ @Override
+ public String getFamily() {
+ return null;
+ }
+
+ }
+
+ private String nextUri(Iterator<?> itr) {
+ assertTrue(itr.hasNext());
+
+ Element elt = (Element) itr.next();
+
+ if (elt instanceof HtmlScript) {
+ return ((HtmlScript) elt).getSrcAttribute();
+ } else if (elt instanceof HtmlLink) {
+ return ((HtmlLink) elt).getHrefAttribute();
+ }
+
+ throw new UnsupportedOperationException(elt.toString());
+ }
+
+ private HtmlUnitEnvironment environment;
+
+ @Before
+ public void setUp() throws Exception {
+ environment = new HtmlUnitEnvironment();
+
environment.getServer().addInitParameter("org.richfaces.enableControlSkinning",
"false");
+
+ environment.withResource("/index.xhtml",
"org/richfaces/resource/simple.xhtml");
+ environment.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testStaticLibrary() throws Exception {
+ environment.getApplication().addComponent("testComponent",
StaticLibraryComponent.class.getName());
+
+ HtmlPage page = environment.getPage("/index.jsf");
+ Iterator<?> itr = page.getByXPath("//head/link |
//head/script").iterator();
+
+ String uri;
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("jsf.js"));
+ assertTrue(uri.contains("javax.faces"));
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("jquery.js"));
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("richfaces.js"));
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("skinning_both.ecss"));
+
+ assertFalse(itr.hasNext());
+ }
+
+ @Test
+ public void testDynamicLibrary() throws Exception {
+ environment.getApplication().addComponent("testComponent",
DynamicLibraryComponent.class.getName());
+
+ HtmlPage page = environment.getPage("/index.jsf");
+ Iterator<?> itr = page.getByXPath("//head/link |
//head/script").iterator();
+
+ String uri;
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("skinning_classes.ecss"));
+
+ uri = nextUri(itr);
+ assertTrue(uri.contains("jquery.js"));
+
+ assertFalse(itr.hasNext());
+ }
+}
+
Added: trunk/core/impl/src/test/java/org/richfaces/view/facelets/AnyComponentHandler.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/view/facelets/AnyComponentHandler.java
(rev 0)
+++
trunk/core/impl/src/test/java/org/richfaces/view/facelets/AnyComponentHandler.java 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.view.facelets;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletHandler;
+import javax.faces.view.facelets.Tag;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributes;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class AnyComponentHandler extends ComponentHandler {
+
+ private static class ComponentConfigWrapper implements ComponentConfig {
+
+ private String componentType;
+
+ private String rendererType;
+
+ private ComponentConfig config;
+
+ public ComponentConfigWrapper(String componentType, String rendererType,
ComponentConfig config) {
+ super();
+ this.componentType = componentType;
+ this.rendererType = rendererType;
+ this.config = config;
+ }
+
+ public Tag getTag() {
+ return config.getTag();
+ }
+
+ public String getComponentType() {
+ return componentType;
+ }
+
+ public FaceletHandler getNextHandler() {
+ return config.getNextHandler();
+ }
+
+ public String getRendererType() {
+ return rendererType;
+ }
+
+ public String getTagId() {
+ return config.getTagId();
+ }
+
+ }
+
+ public AnyComponentHandler(ComponentConfig config) {
+ super(wrapConfig(config));
+ }
+
+ private static ComponentConfig wrapConfig(ComponentConfig config) {
+ TagAttributes attributes = config.getTag().getAttributes();
+
+ TagAttribute rendererType = attributes.get("rendererType");
+ TagAttribute componentType = attributes.get("componentType");
+
+ return new ComponentConfigWrapper(getLiteralAttributeValue(componentType),
+ getLiteralAttributeValue(rendererType), config);
+ }
+
+ private static String getLiteralAttributeValue(TagAttribute attr) {
+ return attr != null ? attr.getValue() : null;
+ }
+}
Added:
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/dynamic.library.properties
===================================================================
---
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/dynamic.library.properties
(rev 0)
+++
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/dynamic.library.properties 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1 @@
+class=org.richfaces.resource.DynamicResourceLibrary
\ No newline at end of file
Added:
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/static.library.properties
===================================================================
---
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/static.library.properties
(rev 0)
+++
trunk/core/impl/src/test/resources/META-INF/richfaces/org.richfaces/static.library.properties 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1 @@
+resources=javax.faces:jsf.js, jquery.js, richfaces.js, skinning_both.ecss
\ No newline at end of file
Added: trunk/core/impl/src/test/resources/META-INF/test.taglib.xml
===================================================================
--- trunk/core/impl/src/test/resources/META-INF/test.taglib.xml
(rev 0)
+++ trunk/core/impl/src/test/resources/META-INF/test.taglib.xml 2010-09-09 23:54:09 UTC
(rev 19151)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0" id="a4j">
+ <
namespace>http://richfaces.org/testing</namespace>
+
+ <tag>
+ <tag-name>anyComponent</tag-name>
+ <component>
+ <!-- component-type is not used and taken from tag attributes -->
+ <component-type>dummyComponent</component-type>
+
<handler-class>org.richfaces.view.facelets.AnyComponentHandler</handler-class>
+ </component>
+ </tag>
+</facelet-taglib>
Added: trunk/core/impl/src/test/resources/org/richfaces/resource/simple.xhtml
===================================================================
--- trunk/core/impl/src/test/resources/org/richfaces/resource/simple.xhtml
(rev 0)
+++ trunk/core/impl/src/test/resources/org/richfaces/resource/simple.xhtml 2010-09-09
23:54:09 UTC (rev 19151)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:testing="http://richfaces.org/testing">
+<h:head>
+</h:head>
+<h:body>
+ <testing:anyComponent componentType="testComponent" />
+</h:body>
+</html>
\ No newline at end of file