JBoss Rich Faces SVN: r18224 - in root/ui/output/trunk/panels/ui/src/main: templates and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-07-23 15:43:09 -0400 (Fri, 23 Jul 2010)
New Revision: 18224
Modified:
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/popupPanel.js
root/ui/output/trunk/panels/ui/src/main/templates/popupPanel.template.xml
Log:
Refactoring script and template for popup panel
Modified: root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/popupPanel.js
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/popupPanel.js 2010-07-23 19:04:24 UTC (rev 18223)
+++ root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/popupPanel.js 2010-07-23 19:43:09 UTC (rev 18224)
@@ -24,10 +24,6 @@
{
jQuery(element).unbind( 'selectstart', selectionEventHandler);
}
- else if (typeof element.style.MozUserSelect!="undefined") //Firefox
- {
- jQuery(element).css('MozUserSelect','');
- }
else //All other (ie: Opera)
{
jQuery(element).unbind( 'mousedown', selectionEventHandler);
@@ -58,7 +54,8 @@
this.scrollerDiv = id + "_content_scroller"
this.borders = new Array();
-
+ this.firstHref = id + "FirstHref";
+ this.lastHref = id + "LastHref";
if (this.options.resizeable) {
this.borders.push(new richfaces.ui.PopupPanel.Border(id + "ResizerN", this, "N-resize", richfaces.ui.PopupPanel.Sizer.N));
this.borders.push(new richfaces.ui.PopupPanel.Border(id + "ResizerE", this, "E-resize", richfaces.ui.PopupPanel.Sizer.E));
@@ -137,7 +134,9 @@
destroy: function() {
this._contentElement = null;
-
+ this.firstOutside = null;
+ this.lastOutside = null;
+ this.firstHref = null;
this.parent = null;
if (this.header) {
this.header.destroy();
@@ -203,7 +202,7 @@
show: function(event, opts) {
if(!this.shown && this.invokeEvent("beforeshow",event,null,element)) {
-
+ this.preventFocus();
var element = this.id;
if (!this.domReattached) {
@@ -266,9 +265,9 @@
if (!this.options.autosized) {
if (options.width && options.width == -1)
- options.width = 600;
+ options.width = 300;
if (options.height && options.height == -1)
- options.height = 400;
+ options.height = 200;
} else{
//options.width = $(this.div+"_headerSpan").width() +20;
}
@@ -296,7 +295,7 @@
}
$(eContentElt).css('height', options.height + (/px/.test(options.height) ? '' : 'px'));
$(this.shadowDiv).css('height', options.height + 4 + (/px/.test(options.height) ? '' : 'px'));
- var headerHeight = $(this.div +"_header")[0].clientHeight;
+ var headerHeight = $(this.div +"_header")[0] ? $(this.div +"_header")[0].clientHeight : 0;
$(this.scrollerDiv).css('height', options.height - headerHeight + (/px/.test(options.height) ? '' : 'px'));
@@ -364,12 +363,92 @@
},
startDrag: function(border) {
- for (var k = 0; k < this.borders.length; k++ ) {
- this.borders[k].hide();
- }
+ //for (var k = 0; k < this.borders.length; k++ ) {
+ //this.borders[k].hide();
+ //}
disableSelection(document.body);
},
+ firstOnfocus: function(event) {
+ var e = $(event.data.popup.firstHref)
+ if (e) {
+ e.focus();
+ }
+ },
+
+ formElements: "|a|input|select|button|textarea|",
+
+ processAllFocusElements: function(root, callback) {
+ var idx = -1;
+ var tagName;
+
+ if (root.focus && root.nodeType == 1 && (tagName = root.tagName) &&
+ // Many not visible elements have focus method, we is had to avoid processing them.
+ (idx = this.formElements.indexOf(tagName.toLowerCase())) != -1 &&
+ this.formElements.charAt(idx - 1) === '|' &&
+ this.formElements.charAt(idx + tagName.length) === '|' &&
+ !root.disabled && root.type!="hidden") {
+ callback.call(this, root);
+ } else {
+ if (root != this.id) {
+ var child = root.firstChild;
+ while (child) {
+ if (!child.style || child.style.display != 'none') {
+ this.processAllFocusElements(child, callback);
+ }
+ child = child.nextSibling;
+ }
+ }
+ }
+ },
+
+ processTabindexes: function(input) {
+ if (!this.firstOutside) {
+ this.firstOutside = input;
+ }
+ if (input.tabIndex && !input.prevTabIndex) {
+ input.prevTabIndex = input.tabIndex;
+ }
+ input.tabIndex = undefined;
+ if (input.accesskey && !input.prevAccesskey) {
+ input.prevAccesskey = input.accesskey;
+ }
+ input.accesskey = undefined;
+ },
+
+ restoreTabindexes: function(input) {
+ if (input.prevTabIndex) {
+ input.tabIndex = input.prevTabIndex;
+ input.prevTabIndex = undefined;
+ }
+ if (input.prevAccesskey) {
+ input.accesskey = input.prevAccesskey;
+ input.prevAccesskey = undefined;
+ }
+ },
+
+ preventFocus: function() {
+ if(this.options.modal){
+ this.processAllFocusElements(document, this.processTabindexes);
+ var popup = this;
+ if (this.firstOutside) {
+
+ jQuery(this.firstOutside).bind("focus", {popup: popup}, this.firstOnfocus);
+ }
+ }
+ },
+
+ restoreFocus: function() {
+ if(this.options.modal){
+ this.processAllFocusElements(document, this.restoreTabindexes);
+
+ if (this.firstOutside) {
+ jQuery(this.firstOutside).unbind("focus", this.firstOnfocus);
+ this.firstOutside = null;
+ }
+ }
+ },
+
endDrag: function(border) {
for (var k = 0; k < this.borders.length; k++ ) {
this.borders[k].show();
@@ -380,6 +459,7 @@
hide: function(event, opts) {
var element = this.id;
+ this.restoreFocus();
if (this.shown && this.invokeEvent("beforehide",event,null,element)) {
this.currentMinHeight = undefined;
Modified: root/ui/output/trunk/panels/ui/src/main/templates/popupPanel.template.xml
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/templates/popupPanel.template.xml 2010-07-23 19:04:24 UTC (rev 18223)
+++ root/ui/output/trunk/panels/ui/src/main/templates/popupPanel.template.xml 2010-07-23 19:43:09 UTC (rev 18224)
@@ -24,7 +24,9 @@
onmousedown="#{component.attributes['onmaskmousedown']}"
onmousemove="#{component.attributes['onmaskmousemove']}"
onmouseover="#{component.attributes['onmaskmouseover']}"
- onmouseout="#{component.attributes['onmaskmouseout']}" class="mp_shade"/>
+ onmouseout="#{component.attributes['onmaskmouseout']}" class="mp_shade">
+ <button class="mp-button" id="#{clientId}FirstHref"></button>
+ </div>
</c:if>
<div id="#{clientId}_shadow" class="mp_shadow"/>
@@ -61,7 +63,6 @@
</c:if>
</div>
-
</div>
<cdk:object type="java.lang.String" name="script" value="#{buildScript(facesContext, component)}" />
<cdk:object type="java.lang.String" name="showScript" value="#{buildShowScript(facesContext, component)}" />
14 years, 5 months
JBoss Rich Faces SVN: r18223 - in root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk: faces and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-23 15:04:24 -0400 (Fri, 23 Jul 2010)
New Revision: 18223
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
Removed:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/
Modified:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
Log:
Marker resources discovery
Resources-related methods in ExternalContextImpl
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -34,7 +34,7 @@
import javax.faces.application.Resource;
-import org.richfaces.cdk.faces.naming.FileNameMapperImpl;
+import org.richfaces.cdk.naming.FileNameMapperImpl;
import org.richfaces.cdk.resource.ResourceFactoryImpl;
import org.richfaces.cdk.resource.ResourceWriterImpl;
import org.richfaces.cdk.resource.ResourcesScannerImpl;
@@ -64,7 +64,9 @@
transform(resourcesScanner.getClassResources(), resourceFactory.getClassResourceFactory()),
transform(resourcesScanner.getURLResources(), resourceFactory.getURLResourceFactory())), notNull());
- ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(new ResourceWriterImpl(dstDir, new FileNameMapperImpl()));
+ ResourceWriterImpl resourceWriter = new ResourceWriterImpl(dstDir, new FileNameMapperImpl());
+ //TODO set webroot
+ ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(resourceWriter, null);
taskFactory.setResources(resources);
taskFactory.setSkins(Lists.newArrayList("blueSky", "ruby", "classic"));
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -21,6 +21,9 @@
*/
package org.richfaces.cdk.faces;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -34,13 +37,21 @@
import javax.faces.context.ExternalContext;
+import com.google.common.collect.Sets;
+
/**
* @author Nick Belaevski
*
*/
public class ExternalContextImpl extends ExternalContext {
+ private String webRoot;
+
private Map<String, String> initParamsMap = new HashMap<String, String>();
+
+ protected void setWebRoot(String webroot) {
+ this.webRoot = webroot;
+ }
/* (non-Javadoc)
* @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
@@ -254,8 +265,7 @@
*/
@Override
public URL getResource(String path) throws MalformedURLException {
- // TODO Auto-generated method stub
- return null;
+ return new URL("file:" + webRoot + path);
}
/* (non-Javadoc)
@@ -263,17 +273,38 @@
*/
@Override
public InputStream getResourceAsStream(String path) {
- // TODO Auto-generated method stub
+ File file = new File(webRoot, path);
+ if (file.exists()) {
+ try {
+ return new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
return null;
}
- /* (non-Javadoc)
- * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
- */
@Override
public Set<String> getResourcePaths(String path) {
- // TODO Auto-generated method stub
- return null;
+ File root = new File(webRoot, path);
+
+ Set<String> result = Sets.newHashSet();
+
+ if (root.exists()) {
+ String[] list = root.list();
+ for (String childName : list) {
+ File child = new File(root, childName);
+ if (child.isDirectory()) {
+ childName += '/';
+ }
+
+ result.add(path + '/' + childName);
+ }
+ }
+
+ return result;
}
/* (non-Javadoc)
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -30,7 +30,6 @@
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseStream;
import javax.faces.context.ResponseWriter;
@@ -46,7 +45,7 @@
private ELContext elContext = new ELContextImpl();
- private ExternalContext externalContext = new ExternalContextImpl();
+ private ExternalContextImpl externalContext = new ExternalContextImpl();
public FacesContextImpl() {
setCurrentInstance(this);
@@ -74,7 +73,7 @@
* @see javax.faces.context.FacesContext#getExternalContext()
*/
@Override
- public ExternalContext getExternalContext() {
+ public ExternalContextImpl getExternalContext() {
// TODO Auto-generated method stub
return externalContext;
}
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -41,6 +41,13 @@
*/
public class FacesImpl implements Faces {
+ private String webroot;
+
+ public FacesImpl(String webroot) {
+ super();
+ this.webroot = webroot;
+ }
+
public void start() {
final SkinFactoryImpl skinFactory = new SkinFactoryImpl();
@@ -71,7 +78,8 @@
}
public void startRequest() {
- new FacesContextImpl();
+ FacesContextImpl facesContextImpl = new FacesContextImpl();
+ facesContextImpl.getExternalContext().setWebRoot(webroot);
assert FacesContext.getCurrentInstance() != null;
}
Copied: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming (from rev 18222, root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming)
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -19,7 +19,7 @@
* 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.cdk.faces.naming;
+package org.richfaces.cdk.naming;
import org.richfaces.cdk.FileNameMapper;
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/MarkerResourcesScanner.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -0,0 +1,61 @@
+/*
+ * 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.cdk.resource;
+
+import org.reflections.scanners.AbstractScanner;
+import org.reflections.vfs.Vfs.File;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MarkerResourcesScanner extends AbstractScanner {
+
+ private static final String RESOURCE_PROPERTIES_EXT = ".resource.properties";
+
+ private static final String META_INF = "META-INF/";
+
+ static final String STORE_KEY = "org.richfaces.cdk.dynamicResourceNames";
+
+ @Override
+ public void scan(Object cls) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void scan(File file) {
+ String relativePath = file.getRelativePath();
+ if (relativePath.startsWith(META_INF) && relativePath.endsWith(RESOURCE_PROPERTIES_EXT)) {
+ Multimap<String, String> store = getStore();
+
+ String className = relativePath.substring(META_INF.length(), relativePath.length() - RESOURCE_PROPERTIES_EXT.length());
+ store.put(STORE_KEY, className);
+ }
+ }
+
+ @Override
+ public boolean acceptsInput(String file) {
+ return true;
+ }
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ReflectionsExt.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -0,0 +1,61 @@
+/*
+ * 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.cdk.resource;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import org.reflections.Configuration;
+import org.reflections.Reflections;
+import org.reflections.scanners.Scanner;
+import org.reflections.util.Utils;
+
+import com.google.common.collect.Multimap;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ReflectionsExt extends Reflections {
+
+ ReflectionsExt() {
+ super();
+ }
+
+ ReflectionsExt(Configuration configuration) {
+ super(configuration);
+ }
+
+ ReflectionsExt(String prefix, Scanner... scanners) {
+ super(prefix, scanners);
+ }
+
+ public Collection<Class<?>> getMarkedClasses() {
+ Map<String, Multimap<String, String>> storeMap = getStore().getStoreMap();
+ Multimap<String, String> scannerMMap = storeMap.get(MarkerResourcesScanner.class.getName());
+ if (scannerMMap == null) {
+ return Collections.emptySet();
+ }
+ return Utils.forNames(scannerMMap.get(MarkerResourcesScanner.STORE_KEY));
+ }
+}
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.Set;
-import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
@@ -53,13 +52,13 @@
public boolean apply(File input) {
return input.getRelativePath().endsWith("META-INF/faces-config.xml");
}
-
+
};
-
+
private static boolean containsFacesConfig(Dir dir) {
return Iterators.any(dir.getFiles().iterator(), IS_FACES_CONFIG);
}
-
+
private static final Predicate<URL> FACES_URL = new Predicate<URL>() {
public boolean apply(URL input) {
@@ -71,23 +70,28 @@
}
}
};
-
+
private Collection<Class<?>> classResources = Sets.newHashSet();
-
+
private Collection<URL> urlResources = Sets.newHashSet();
public void scan() {
Collection<URL> urls = Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
-
- Reflections refl = new Reflections(new ConfigurationBuilder().setUrls(urls).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
-
+
+ ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(urls);
+ configurationBuilder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new MarkerResourcesScanner());
+
+ ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
+
Set<Class<?>> resources = refl.getTypesAnnotatedWith(DynamicResource.class);
-
- //TODO - reflections doesn't handle @Inherited correctly
+
+ // TODO - reflections doesn't handle @Inherited correctly
for (Class<?> resourceClass : resources) {
classResources.add(resourceClass);
classResources.addAll(refl.getSubTypesOf(resourceClass));
}
+
+ classResources.addAll(refl.getMarkedClasses());
}
public Collection<Class<?>> getClassResources() {
Modified: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-23 19:04:24 UTC (rev 18223)
@@ -86,7 +86,7 @@
public Object call() throws Exception {
try {
- faces = new FacesImpl();
+ faces = new FacesImpl(webRoot);
faces.start();
for (Resource resource : resources) {
@@ -104,15 +104,18 @@
}
+ private String webRoot;
+
private ResourceWriter resourceWriter;
private Iterable<Resource> resources = Collections.emptySet();
private Iterable<String> skins = Collections.emptySet();
- public ResourceTaskFactoryImpl(ResourceWriter resourceWriter) {
+ public ResourceTaskFactoryImpl(ResourceWriter resourceWriter, String webRoot) {
super();
this.resourceWriter = resourceWriter;
+ this.webRoot = webRoot;
}
public void setResources(Iterable<Resource> resources) {
14 years, 5 months
JBoss Rich Faces SVN: r18222 - in root/cdk-sandbox/trunk: dynamic-resources-prerenderer and 14 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-23 13:49:26 -0400 (Fri, 23 Jul 2010)
New Revision: 18222
Added:
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/richfaces/
root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/test/java/org/richfaces/cdk/
Log:
dynamic-resources-prerenderer initial check-in
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/pom.xml 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,84 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>dynamic-resources-prerenderer</artifactId>
+
+ <!--
+ <packaging>maven-plugin</packaging>
+ -->
+ <version>4.0.0-SNAPSHOT</version>
+ <name>dynamic-resources-processor</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>reflections-repo</id>
+ <name>Reflections Maven2 Repository</name>
+ <url>http://reflections.googlecode.com/svn/repo</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>2.0.3-b03</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>richfaces-components-ui</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>2.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.reflections</groupId>
+ <artifactId>reflections</artifactId>
+ <version>0.9.5-RC2</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>google-collections</artifactId>
+ <groupId>com.google.collections</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Faces.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,42 @@
+/*
+ * 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.cdk;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface Faces {
+
+ public void start();
+
+ public void stop();
+
+ public void setSkin(String skinName);
+
+ public String getSkin();
+
+ public void startRequest();
+
+ public void stopRequest();
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/FileNameMapper.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -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.cdk;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface FileNameMapper {
+
+ public String createName(String mimeType, String resourceName);
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/Main.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,96 @@
+/*
+ * 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.cdk;
+
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Iterables.concat;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.transform;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.faces.application.Resource;
+
+import org.richfaces.cdk.faces.naming.FileNameMapperImpl;
+import org.richfaces.cdk.resource.ResourceFactoryImpl;
+import org.richfaces.cdk.resource.ResourceWriterImpl;
+import org.richfaces.cdk.resource.ResourcesScannerImpl;
+import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class Main {
+
+ private static ExecutorService createExecutorService() {
+ return Executors.newSingleThreadExecutor();
+ }
+
+ public static void main(String[] args) throws Exception {
+ String dstDir = args[0];
+
+ ResourcesScanner resourcesScanner = new ResourcesScannerImpl();
+ resourcesScanner.scan();
+
+ ResourceFactory resourceFactory = new ResourceFactoryImpl();
+
+ Iterable<Resource> resources = filter(concat(
+ transform(resourcesScanner.getClassResources(), resourceFactory.getClassResourceFactory()),
+ transform(resourcesScanner.getURLResources(), resourceFactory.getURLResourceFactory())), notNull());
+
+ ResourceTaskFactory taskFactory = new ResourceTaskFactoryImpl(new ResourceWriterImpl(dstDir, new FileNameMapperImpl()));
+
+ taskFactory.setResources(resources);
+ taskFactory.setSkins(Lists.newArrayList("blueSky", "ruby", "classic"));
+
+ ExecutorService executorService = createExecutorService();
+ ExecutorCompletionService<Object> completionService = new ExecutorCompletionService<Object>(executorService);
+
+ try {
+ int tasksCounter = 0;
+ for (Callable<Object> task : taskFactory.createTasks()) {
+ completionService.submit(task);
+ tasksCounter++;
+ }
+
+ while (tasksCounter > 0){
+ try {
+ completionService.take().get();
+ } catch (ExecutionException e) {
+ // TODO: handle exception
+ e.getCause().printStackTrace();
+ }
+ tasksCounter--;
+ }
+ } finally {
+ executorService.shutdown();
+ }
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceFactory.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -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.cdk;
+
+import java.net.URL;
+
+import javax.faces.application.Resource;
+
+import com.google.common.base.Function;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceFactory {
+
+ public Function<URL, Resource> getURLResourceFactory();
+
+ public Function<Class<?>, Resource> getClassResourceFactory();
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,41 @@
+/*
+ * 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.cdk;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import javax.faces.application.Resource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceTaskFactory {
+
+ public void setSkins(Iterable<String> skins);
+
+ public void setResources(Iterable<Resource> resources);
+
+ public Collection<Callable<Object>> createTasks();
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourceWriter.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,36 @@
+/*
+ * 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.cdk;
+
+import java.io.IOException;
+
+import javax.faces.application.Resource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourceWriter {
+
+ public void writeResource(String skinName, Resource resource) throws IOException;
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/ResourcesScanner.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -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.cdk;
+
+import java.net.URL;
+import java.util.Collection;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface ResourcesScanner {
+
+ //TODO inclusions/exclusions
+
+ public void scan();
+
+ public Collection<Class<?>> getClassResources();
+
+ public Collection<URL> getURLResources();
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ELContextImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,62 @@
+/*
+ * 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.cdk.faces;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ELContextImpl extends ELContext {
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getELResolver()
+ */
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getFunctionMapper()
+ */
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getVariableMapper()
+ */
+ @Override
+ public VariableMapper getVariableMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/ExternalContextImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,351 @@
+/*
+ * 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.cdk.faces;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ExternalContextImpl extends ExternalContext {
+
+ private Map<String, String> initParamsMap = new HashMap<String, String>();
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#dispatch(java.lang.String)
+ */
+ @Override
+ public void dispatch(String path) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeActionURL(java.lang.String)
+ */
+ @Override
+ public String encodeActionURL(String url) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeNamespace(java.lang.String)
+ */
+ @Override
+ public String encodeNamespace(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)
+ */
+ @Override
+ public String encodeResourceURL(String url) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getApplicationMap()
+ */
+ @Override
+ public Map<String, Object> getApplicationMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getAuthType()
+ */
+ @Override
+ public String getAuthType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getContext()
+ */
+ @Override
+ public Object getContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+ */
+ @Override
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return initParamsMap.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getInitParameterMap()
+ */
+ @Override
+ public Map getInitParameterMap() {
+ // TODO Auto-generated method stub
+ return initParamsMap;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRemoteUser()
+ */
+ @Override
+ public String getRemoteUser() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequest()
+ */
+ @Override
+ public Object getRequest() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestContextPath()
+ */
+ @Override
+ public String getRequestContextPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestCookieMap()
+ */
+ @Override
+ public Map<String, Object> getRequestCookieMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestHeaderMap()
+ */
+ @Override
+ public Map<String, String> getRequestHeaderMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestHeaderValuesMap()
+ */
+ @Override
+ public Map<String, String[]> getRequestHeaderValuesMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestLocale()
+ */
+ @Override
+ public Locale getRequestLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestLocales()
+ */
+ @Override
+ public Iterator<Locale> getRequestLocales() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestMap()
+ */
+ @Override
+ public Map<String, Object> getRequestMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterMap()
+ */
+ @Override
+ public Map<String, String> getRequestParameterMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterNames()
+ */
+ @Override
+ public Iterator<String> getRequestParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestParameterValuesMap()
+ */
+ @Override
+ public Map<String, String[]> getRequestParameterValuesMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestPathInfo()
+ */
+ @Override
+ public String getRequestPathInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getRequestServletPath()
+ */
+ @Override
+ public String getRequestServletPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+ */
+ @Override
+ public URL getResource(String path) throws MalformedURLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+ */
+ @Override
+ public InputStream getResourceAsStream(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+ */
+ @Override
+ public Set<String> getResourcePaths(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getResponse()
+ */
+ @Override
+ public Object getResponse() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getSession(boolean)
+ */
+ @Override
+ public Object getSession(boolean create) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getSessionMap()
+ */
+ @Override
+ public Map<String, Object> getSessionMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#getUserPrincipal()
+ */
+ @Override
+ public Principal getUserPrincipal() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#isUserInRole(java.lang.String)
+ */
+ @Override
+ public boolean isUserInRole(String role) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#log(java.lang.String)
+ */
+ @Override
+ public void log(String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#log(java.lang.String, java.lang.Throwable)
+ */
+ @Override
+ public void log(String message, Throwable exception) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.ExternalContext#redirect(java.lang.String)
+ */
+ @Override
+ public void redirect(String url) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesContextImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,239 @@
+/*
+ * 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.cdk.faces;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FacesContextImpl extends FacesContext {
+
+ private Map<Object, Object> attributes = new HashMap<Object, Object>();
+
+ private ELContext elContext = new ELContextImpl();
+
+ private ExternalContext externalContext = new ExternalContextImpl();
+
+ public FacesContextImpl() {
+ setCurrentInstance(this);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getApplication()
+ */
+ @Override
+ public Application getApplication() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getClientIdsWithMessages()
+ */
+ @Override
+ public Iterator<String> getClientIdsWithMessages() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getExternalContext()
+ */
+ @Override
+ public ExternalContext getExternalContext() {
+ // TODO Auto-generated method stub
+ return externalContext;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMaximumSeverity()
+ */
+ @Override
+ public Severity getMaximumSeverity() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMessages()
+ */
+ @Override
+ public Iterator<FacesMessage> getMessages() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getMessages(java.lang.String)
+ */
+ @Override
+ public Iterator<FacesMessage> getMessages(String clientId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getRenderKit()
+ */
+ @Override
+ public RenderKit getRenderKit() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getRenderResponse()
+ */
+ @Override
+ public boolean getRenderResponse() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseComplete()
+ */
+ @Override
+ public boolean getResponseComplete() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseStream()
+ */
+ @Override
+ public ResponseStream getResponseStream() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#setResponseStream(javax.faces.context.ResponseStream)
+ */
+ @Override
+ public void setResponseStream(ResponseStream responseStream) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getResponseWriter()
+ */
+ @Override
+ public ResponseWriter getResponseWriter() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#setResponseWriter(javax.faces.context.ResponseWriter)
+ */
+ @Override
+ public void setResponseWriter(ResponseWriter responseWriter) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getViewRoot()
+ */
+ @Override
+ public UIViewRoot getViewRoot() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#setViewRoot(javax.faces.component.UIViewRoot)
+ */
+ @Override
+ public void setViewRoot(UIViewRoot root) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#addMessage(java.lang.String, javax.faces.application.FacesMessage)
+ */
+ @Override
+ public void addMessage(String clientId, FacesMessage message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#release()
+ */
+ @Override
+ public void release() {
+ setCurrentInstance(null);
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#renderResponse()
+ */
+ @Override
+ public void renderResponse() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#responseComplete()
+ */
+ @Override
+ public void responseComplete() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.FacesContext#getAttributes()
+ */
+ @Override
+ public Map<Object, Object> getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public ELContext getELContext() {
+ return elContext;
+ }
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/FacesImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,83 @@
+/*
+ * 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.cdk.faces;
+
+import java.util.Collections;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.context.ContextInitParameters;
+import org.ajax4jsf.context.InitParametersStorage;
+import org.richfaces.application.Module;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.application.ServicesFactory;
+import org.richfaces.application.ServicesFactoryImpl;
+import org.richfaces.cdk.Faces;
+import org.richfaces.skin.SkinFactory;
+import org.richfaces.skin.SkinFactoryImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FacesImpl implements Faces {
+
+ public void start() {
+ final SkinFactoryImpl skinFactory = new SkinFactoryImpl();
+
+ final ServicesFactoryImpl serviceFactory = new ServicesFactoryImpl();
+ Module module = new Module() {
+
+ public void configure(ServicesFactory factory) {
+ serviceFactory.setInstance(SkinFactory.class, skinFactory);
+ serviceFactory.setInstance(InitParametersStorage.class, new InitParametersStorage());
+ }
+ };
+ serviceFactory.init(Collections.singleton(module));
+ ServiceTracker.setFactory(serviceFactory);
+ }
+
+ public void stop() {
+ ServiceTracker.release();
+ }
+
+ public void setSkin(String skinName) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.getExternalContext().getInitParameterMap().put(ContextInitParameters.SKIN, skinName);
+ }
+
+ public String getSkin() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return (String) facesContext.getExternalContext().getInitParameterMap().get(ContextInitParameters.SKIN);
+ }
+
+ public void startRequest() {
+ new FacesContextImpl();
+ assert FacesContext.getCurrentInstance() != null;
+ }
+
+ public void stopRequest() {
+ FacesContext.getCurrentInstance().release();
+ assert FacesContext.getCurrentInstance() == null;
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/faces/naming/FileNameMapperImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,50 @@
+/*
+ * 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.cdk.faces.naming;
+
+import org.richfaces.cdk.FileNameMapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileNameMapperImpl implements FileNameMapper {
+
+ private String stripContentClassifier(String mimeType) {
+ int idx = mimeType.lastIndexOf('/');
+ if (idx < 0) {
+ return mimeType;
+ } else {
+ return mimeType.substring(idx + 1);
+ }
+ }
+
+ public String createName(String mimeType, String resourceName) {
+ String fileName = resourceName.toLowerCase().replace('.', '_');
+ String fileExt = stripContentClassifier(mimeType);
+ if (fileExt != null && fileExt.length() != 0) {
+ fileName += ("." + fileExt);
+ }
+
+ return fileName;
+ }
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceFactoryImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -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.cdk.resource;
+
+import java.lang.reflect.Modifier;
+import java.net.URL;
+
+import javax.faces.FacesException;
+import javax.faces.application.Resource;
+
+import org.richfaces.cdk.ResourceFactory;
+import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.Java2DUserResourceWrapperImpl;
+
+import com.google.common.base.Function;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceFactoryImpl implements ResourceFactory {
+
+ private <T> T instantiate(Class<? extends T> clazz) {
+ try {
+ return clazz.newInstance();
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (LinkageError e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ throw new FacesException(clazz.getName());
+ }
+
+ private Function<URL, Resource> urlFunction = new Function<URL, Resource>() {
+ public Resource apply(URL from) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+ private Function<Class<?>, Resource> classFunction = new Function<Class<?>, Resource>() {
+ private Resource createResource(Class<?> classResource) {
+ if (classResource.isInterface() || (classResource.getModifiers() & Modifier.ABSTRACT) != 0) {
+ return null;
+ }
+
+ if (Resource.class.isAssignableFrom(classResource)) {
+ return instantiate(classResource.asSubclass(Resource.class));
+ }
+
+ if (Java2DUserResource.class.isAssignableFrom(classResource)) {
+ Java2DUserResource java2dResource = instantiate(classResource.asSubclass(Java2DUserResource.class));
+ Resource wrapper = new Java2DUserResourceWrapperImpl(java2dResource);
+ wrapper.setResourceName(classResource.getName());
+ return wrapper;
+ }
+
+ return null;
+ }
+
+ private boolean isImageResource(Resource resource) {
+ String contentType = resource.getContentType();
+
+ if (contentType == null) {
+ return false;
+ }
+
+ return contentType.contains("image/");
+ }
+
+ public Resource apply(Class<?> from) {
+ Resource resource = createResource(from);
+ if (resource != null && isImageResource(resource)) {
+ return resource;
+ }
+
+ return null;
+ };
+ };
+
+ public Function<URL, Resource> getURLResourceFactory() {
+ return urlFunction;
+ }
+
+ public Function<Class<?>, Resource> getClassResourceFactory() {
+ return classFunction;
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,92 @@
+/*
+ * 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.cdk.resource;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.faces.application.Resource;
+
+import org.richfaces.cdk.FileNameMapper;
+import org.richfaces.cdk.ResourceWriter;
+
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceWriterImpl implements ResourceWriter {
+
+ private File baseDir;
+
+ private FileNameMapper fileNameMapper;
+
+ public ResourceWriterImpl(String baseDirectoryName, FileNameMapper fileNameMapper) {
+ baseDir = new File(baseDirectoryName);
+ baseDir.mkdirs();
+
+ this.fileNameMapper = fileNameMapper;
+ }
+
+ public void writeResource(String skinName, Resource resource) throws IOException {
+ File skinDir = new File(baseDir, skinName);
+ skinDir.mkdirs();
+
+ File destDir = skinDir;
+ if (resource.getLibraryName() != null && resource.getLibraryName().length() != 0) {
+ destDir = new File(destDir, resource.getLibraryName());
+ destDir.mkdirs();
+ }
+
+ FileOutputStream fos = null;
+ InputStream is = null;
+ try {
+ is = resource.getInputStream();
+ File outFile = new File(destDir, fileNameMapper.createName(resource.getContentType(), resource.getResourceName()));
+ outFile.createNewFile();
+
+ fos = new FileOutputStream(outFile);
+ ByteStreams.copy(is, fos);
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/resource/ResourcesScannerImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,101 @@
+/*
+ * 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.cdk.resource;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Set;
+
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.scanners.TypeAnnotationsScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+import org.reflections.vfs.Vfs;
+import org.reflections.vfs.Vfs.Dir;
+import org.reflections.vfs.Vfs.File;
+import org.reflections.vfs.ZipDir;
+import org.richfaces.cdk.ResourcesScanner;
+import org.richfaces.resource.DynamicResource;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Sets;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourcesScannerImpl implements ResourcesScanner {
+
+ private static final Predicate<File> IS_FACES_CONFIG = new Predicate<File>() {
+
+ public boolean apply(File input) {
+ return input.getRelativePath().endsWith("META-INF/faces-config.xml");
+ }
+
+ };
+
+ private static boolean containsFacesConfig(Dir dir) {
+ return Iterators.any(dir.getFiles().iterator(), IS_FACES_CONFIG);
+ }
+
+ private static final Predicate<URL> FACES_URL = new Predicate<URL>() {
+
+ public boolean apply(URL input) {
+ Dir dir = Vfs.fromURL(input);
+ if (dir instanceof ZipDir) {
+ return containsFacesConfig(dir);
+ } else {
+ return true;
+ }
+ }
+ };
+
+ private Collection<Class<?>> classResources = Sets.newHashSet();
+
+ private Collection<URL> urlResources = Sets.newHashSet();
+
+ public void scan() {
+ Collection<URL> urls = Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
+
+ Reflections refl = new Reflections(new ConfigurationBuilder().setUrls(urls).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
+
+ Set<Class<?>> resources = refl.getTypesAnnotatedWith(DynamicResource.class);
+
+ //TODO - reflections doesn't handle @Inherited correctly
+ for (Class<?> resourceClass : resources) {
+ classResources.add(resourceClass);
+ classResources.addAll(refl.getSubTypesOf(resourceClass));
+ }
+ }
+
+ public Collection<Class<?>> getClassResources() {
+ return classResources;
+ }
+
+ public Collection<URL> getURLResources() {
+ return urlResources;
+ }
+
+}
Added: root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
===================================================================
--- root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java (rev 0)
+++ root/cdk-sandbox/trunk/dynamic-resources-prerenderer/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java 2010-07-23 17:49:26 UTC (rev 18222)
@@ -0,0 +1,135 @@
+/*
+ * 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.cdk.task;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.faces.application.Resource;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.Faces;
+import org.richfaces.cdk.ResourceTaskFactory;
+import org.richfaces.cdk.ResourceWriter;
+import org.richfaces.cdk.faces.FacesImpl;
+import org.richfaces.resource.StateHolderResource;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceTaskFactoryImpl implements ResourceTaskFactory {
+
+ private class ResourcesRendererCallable implements Callable<Object> {
+
+ private Faces faces;
+
+ private String skinName;
+
+ private Iterable<Resource> resources;
+
+ ResourcesRendererCallable(String skinName, Iterable<Resource> resources) {
+ this.skinName = skinName;
+ this.resources = resources;
+ }
+
+ private void renderResource(Resource resource) throws Exception {
+ try {
+ faces.startRequest();
+ faces.setSkin(skinName);
+
+ if (resource instanceof StateHolderResource) {
+ StateHolderResource stateHolderResource = (StateHolderResource) resource;
+ ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
+ stateHolderResource.writeState(FacesContext.getCurrentInstance(), dataOutput);
+
+ //TODO use collected data
+ } else if (resource instanceof StateHolder) {
+ StateHolder stateHolder = (StateHolder) resource;
+ if (!stateHolder.isTransient()) {
+ Object savedData = stateHolder.saveState(FacesContext.getCurrentInstance());
+ //TODO use collected data
+ }
+ }
+
+ resourceWriter.writeResource(faces.getSkin(), resource);
+ } finally {
+ faces.stopRequest();
+ }
+ }
+
+ public Object call() throws Exception {
+ try {
+ faces = new FacesImpl();
+ faces.start();
+
+ for (Resource resource : resources) {
+ renderResource(resource);
+ }
+
+ } finally {
+ faces.stop();
+ faces = null;
+ }
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ }
+
+ private ResourceWriter resourceWriter;
+
+ private Iterable<Resource> resources = Collections.emptySet();
+
+ private Iterable<String> skins = Collections.emptySet();
+
+ public ResourceTaskFactoryImpl(ResourceWriter resourceWriter) {
+ super();
+ this.resourceWriter = resourceWriter;
+ }
+
+ public void setResources(Iterable<Resource> resources) {
+ this.resources = resources;
+ }
+
+ public void setSkins(Iterable<String> skins) {
+ this.skins = skins;
+ }
+
+ public Collection<Callable<Object>> createTasks() {
+ List<Callable<Object>> result = Lists.newArrayList();
+
+ for (String skin : skins) {
+ result.add(new ResourcesRendererCallable(skin, resources));
+ }
+
+ return result;
+ }
+}
14 years, 5 months
JBoss Rich Faces SVN: r18221 - in root: ui/misc/trunk/jquery and 7 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-07-23 13:28:34 -0400 (Fri, 23 Jul 2010)
New Revision: 18221
Added:
root/.svnignore
Modified:
root/
root/ui/misc/trunk/jquery/
root/ui/output/trunk/dist/
root/ui/output/trunk/dist/richfaces-ui-output-api/
root/ui/output/trunk/dist/richfaces-ui-output-ui/
root/ui/output/trunk/panels/
root/ui/output/trunk/panels/api/
root/ui/output/trunk/panels/ui/
root/ui/output/trunk/parent/
Log:
mark working files as ignored
Property changes on: root
___________________________________________________________________
Name: svn:ignore
- target
.settings
.project
.classpath
.clover
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Added: root/.svnignore
===================================================================
--- root/.svnignore (rev 0)
+++ root/.svnignore 2010-07-23 17:28:34 UTC (rev 18221)
@@ -0,0 +1,7 @@
+target
+.settings
+.project
+.classpath
+.clover
+.externalToolBuilders
+
Property changes on: root/ui/misc/trunk/jquery
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/dist
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/dist/richfaces-ui-output-api
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/dist/richfaces-ui-output-ui
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/panels
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/panels/api
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/panels/ui
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
Property changes on: root/ui/output/trunk/parent
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
.externalToolBuilders
14 years, 5 months
JBoss Rich Faces SVN: r18220 - in root: examples/output-demo/trunk/src/main/webapp/examples and 10 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: Alex.Kolonitsky
Date: 2010-07-23 12:43:22 -0400 (Fri, 23 Jul 2010)
New Revision: 18220
Added:
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml
root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java
Modified:
root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml
root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
Log:
Toggle Panel bug fixing and code review
Modified: root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -26,6 +26,10 @@
<from-outcome>togglePanel/client</from-outcome>
<to-view-id>/examples/togglePanel-client.xhtml</to-view-id>
</navigation-case>
+ <navigation-case>
+ <from-outcome>togglePanel/mixed</from-outcome>
+ <to-view-id>/examples/togglePanel-mixed.xhtml</to-view-id>
+ </navigation-case>
<!-- QUnit -->
<navigation-case>
Modified: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -14,7 +14,7 @@
<ui:define name="body">
<f:view>
<h:form id="f">
- <pn:togglePanel id="my_id" activeItem="name1" switchType="ajax"
+ <pn:togglePanel id="panel" activeItem="name1" switchType="ajax"
itemChangeListener="#{togglePanelBean.itemChangeActionListener}" >
<pn:togglePanelItem name="name1">hello name1</pn:togglePanelItem>
<pn:togglePanelItem name="name2">hello name2</pn:togglePanelItem>
@@ -22,19 +22,40 @@
</pn:togglePanel>
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name1" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name1" event="click" />
name1
</h:outputLink>
|
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name2" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name2" event="click" />
name2
</h:outputLink>
|
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name3" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br/>
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@first" event="click"/>
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@prev" event="click"/>
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@next" event="click"/>
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@last" event="click"/>
+ last >|
+ </h:outputLink>
</h:form>
</f:view>
</ui:define>
Modified: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -23,14 +23,37 @@
<pn:toggleControl forPanel="panel" targetItem="name1" event="click" />
name1
</h:outputLink>
+ |
<h:outputLink>
<pn:toggleControl forPanel="panel" targetItem="name2" event="click" />
name2
</h:outputLink>
+ |
<h:outputLink>
<pn:toggleControl forPanel="panel" targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br />
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@first" event="click" />
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@prev" event="click" />
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@next" event="click" />
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@last" event="click" />
+ last >|
+ </h:outputLink>
</h:form>
</ui:define>
</ui:composition>
Added: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml (rev 0)
+++ root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -0,0 +1,61 @@
+<!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:pn="http://richfaces.org/output">
+
+<body>
+<ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="title">Toggle Panel Example</ui:define>
+ <ui:define name="body_head">Toggle Panel Example - Client & Ajax SwitchType</ui:define>
+
+ <ui:define name="body">
+ <h:form id="f">
+ <pn:togglePanel id="panel" activeItem="name1" switchType="client" lang="en">
+ <pn:togglePanelItem name="name1">hello name1 client</pn:togglePanelItem>
+ <pn:togglePanelItem name="name2" switchType="ajax">hello name2 ajax</pn:togglePanelItem>
+ <pn:togglePanelItem name="name3" switchType="server">hello name3 server</pn:togglePanelItem>
+ </pn:togglePanel>
+
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="name1" event="click" />
+ name1 client
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="name2" event="click" />
+ name2 ajax
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="name3" event="click" />
+ name3 server
+ </h:outputLink>
+
+ <br />
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@first" event="click" />
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@prev" event="click" />
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@next" event="click" />
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@last" event="click" />
+ last >|
+ </h:outputLink>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</body>
+</html>
Modified: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -14,24 +14,47 @@
<ui:define name="body">
<f:view>
<h:form id="f">
- <pn:togglePanel id="my_id" activeItem="name1" switchType="server" lang="en">
+ <pn:togglePanel id="panel" activeItem="name1" switchType="server" lang="en">
<pn:togglePanelItem name="name1">hello name1</pn:togglePanelItem>
<pn:togglePanelItem name="name2">hello name2</pn:togglePanelItem>
<pn:togglePanelItem name="name3">hello name3</pn:togglePanelItem>
</pn:togglePanel>
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name1" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name1" event="click" />
name1
</h:outputLink>
+ |
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name2" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name2" event="click" />
name2
</h:outputLink>
+ |
<h:outputLink>
- <pn:toggleControl forPanel="my_id" targetItem="name3" event="click" />
+ <pn:toggleControl forPanel="panel" targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br/>
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@first" event="click"/>
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@prev" event="click"/>
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@next" event="click"/>
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel" targetItem="@last" event="click"/>
+ last >|
+ </h:outputLink>
</h:form>
</f:view>
</ui:define>
Modified: root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml 2010-07-23 16:43:22 UTC (rev 18220)
@@ -34,6 +34,7 @@
<li><h:commandLink value="togglePanel Ajax" action="togglePanel/ajax" /></li>
<li><h:commandLink value="togglePanel Client" action="togglePanel/client" /></li>
<li><h:commandLink value="togglePanel Server" action="togglePanel/server" /></li>
+ <li><h:commandLink value="togglePanel Mixed" action="togglePanel/mixed" /></li>
</ul>
<p>QUnit</p>
<ul>
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -105,7 +105,7 @@
options.put("pushId", push.getListenerId(context));
options.put("clientId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(facesContext, push);
+ HandlersChain handlersChain = new HandlersChain(context, push);
handlersChain.addInlineHandlerFromAttribute(AbstractPush.ON_DATA_AVAILABLE);
handlersChain.addBehaviors(AbstractPush.DATA_AVAILABLE);
handlersChain.addAjaxSubmitFunction();
Added: root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java
===================================================================
--- root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java (rev 0)
+++ root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -0,0 +1,36 @@
+package org.richfaces.event;
+
+/**
+ * @author akolonitsky
+ * @since Jul 20, 2010
+ */
+public interface ItemChangeSource {
+
+ /**
+ * <p>Add a new {@link org.richfaces.event.ItemChangeListener} to the set of listeners
+ * interested in being notified when {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
+ *
+ * @param listener The {@link org.richfaces.event.ItemChangeListener} to be added
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ void addItemChangeListener(ItemChangeListener listener);
+
+ /**
+ * <p>Return the set of registered {@link org.richfaces.event.ItemChangeListener}s for this instance.
+ * If there are no registered listeners, a zero-length array is returned.</p>
+ */
+ ItemChangeListener[] getItemChangeListeners();
+
+ /**
+ * <p>Remove an existing {@link org.richfaces.event.ItemChangeListener} (if any) from the
+ * set of listeners interested in being notified when
+ * {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
+ *
+ * @param listener The {@link org.richfaces.event.ItemChangeListener} to be removed
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ void removeItemChangeListener(ItemChangeListener listener);
+
+}
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -22,20 +22,19 @@
package org.richfaces.component;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
import javax.el.ELException;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UpdateModelException;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
@@ -43,18 +42,15 @@
import javax.faces.event.PhaseId;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreValidateEvent;
-import javax.faces.event.ValueChangeListener;
-import javax.faces.validator.Validator;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
-import org.richfaces.component.util.MessageUtil;
-import org.richfaces.event.ItemChangeEvent;
-import org.richfaces.event.ItemChangeListener;
-
/**
* @author akolonitsky
* @version 1.0
*/
-public abstract class AbstractTogglePanel extends AbstractDivPanel implements EditableValueHolder {
+public abstract class AbstractTogglePanel extends AbstractDivPanel implements ItemChangeSource {
public static final String COMPONENT_TYPE = "org.richfaces.TogglePanel";
@@ -94,18 +90,10 @@
this.submittedActiveItem = String.valueOf(submittedValue);
}
- /**
- * Return the "local value set" state for this component.
- * Calls to <code>setValue()</code> automatically reset
- * this property to <code>true</code>.
- */
public boolean isLocalValueSet() {
return (Boolean) getStateHelper().eval(PropertyKeys.localValueSet, false);
}
- /**
- * Sets the "local value set" state for this component.
- */
public void setLocalValueSet(boolean localValueSet) {
getStateHelper().put(PropertyKeys.localValueSet, localValueSet);
}
@@ -119,9 +107,6 @@
getStateHelper().put(PropertyKeys.valid, valid);
}
- /**
- * <p>Return the "required field" state for this component.</p>
- */
public boolean isRequired() {
return (Boolean) getStateHelper().eval(PropertyKeys.required, false);
}
@@ -145,46 +130,6 @@
getStateHelper().put(PropertyKeys.immediate, immediate);
}
- public MethodBinding getValidator() {
- throw new UnsupportedOperationException();
- }
-
- public void setValidator(MethodBinding validatorBinding) {
- throw new UnsupportedOperationException();
- }
-
- public MethodBinding getValueChangeListener() {
- throw new UnsupportedOperationException();
- }
-
- public void setValueChangeListener(MethodBinding valueChangeMethod) {
- throw new UnsupportedOperationException();
- }
-
- public void addValidator(Validator validator) {
- throw new UnsupportedOperationException();
- }
-
- public Validator[] getValidators() {
- throw new UnsupportedOperationException();
- }
-
- public void removeValidator(Validator validator) {
- throw new UnsupportedOperationException();
- }
-
- public void addValueChangeListener(ValueChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public ValueChangeListener[] getValueChangeListeners() {
- throw new UnsupportedOperationException();
- }
-
- public void removeValueChangeListener(ValueChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
// ----------------------------------------------------- UIComponent Methods
/**
@@ -397,9 +342,6 @@
}
}
- /**
- * Executes validation logic.
- */
private void executeValidate(FacesContext context) {
try {
validate(context);
@@ -433,6 +375,7 @@
}
}
+ @Override
public void queueEvent(FacesEvent event) {
if ((event instanceof ItemChangeEvent) && (event.getComponent() == this)) {
if (isImmediate()) {
@@ -468,10 +411,6 @@
return true;
}
- private boolean isActiveItem(UIComponent kid) {
- return getChildName(kid).equals(getActiveItemValue());
- }
-
private String getActiveItemValue() {
String value = getActiveItem();
if (value == null) {
@@ -480,78 +419,103 @@
return value;
}
- private static boolean isActiveItem(UIComponent kid, String value) {
+ protected boolean isActiveItem(UIComponent kid) {
+ return isActiveItem(kid, getActiveItemValue());
+ }
+
+ protected static boolean isActiveItem(UIComponent kid, String value) {
+ if (kid == null || value == null) {
+ return false;
+ }
+
return getChildName(kid).equals(value);
}
- public String getFirstItem() {
- List<UIComponent> children = getRenderedChildren();
-// if (chi)
+ private static String getChildName(UIComponent item) {
+ if (item == null) {
+ return null;
+ }
- return getChildName(children.get(0));
+ if (!(item instanceof AbstractTogglePanelItem)) {
+ throw new IllegalArgumentException();
+ }
+
+ return ((AbstractTogglePanelItem) item).getName();
}
+
+ public AbstractTogglePanelItem getItemByIndex(final int index) {
+ List<AbstractTogglePanelItem> children = getRenderedChildren();
+ if (index < 0 || index >= children.size()) {
+ return null;
+ }
-// public UIComponent getItemByIndex
+ return children.get(index);
+ }
- private List<UIComponent> getRenderedChildren() {
- List<UIComponent> res = new ArrayList<UIComponent>(getChildCount());
+ private List<AbstractTogglePanelItem> getRenderedChildren() {
+ List<AbstractTogglePanelItem> res = new ArrayList<AbstractTogglePanelItem>(getChildCount());
for (UIComponent child : getChildren()) {
- res.add(child);
+ if (child.isRendered() && child instanceof AbstractTogglePanelItem) {
+ res.add((AbstractTogglePanelItem) child);
+ }
}
return res;
}
public AbstractTogglePanelItem getItem(String name) {
- if (name == null) {
- throw new IllegalArgumentException("Name is required parameter.");
+ if ("@first".equals(name)) {
+ return getFirstItem();
+ } else if ("@prev".equals(name)) {
+ return getPrevItem();
+ } else if ("@next".equals(name)) {
+ return getNextItem();
+ } else if ("@last".equals(name)) {
+ return getLastItem();
+ } else {
+ return getItemByIndex(getChildIndex(name));
}
+ }
- List<UIComponent> children = getChildren();
- int index = getChildIndex(name, children);
- if (index == -1) {
- return null;
- }
- return (AbstractTogglePanelItem) children.get(index);
+ public AbstractTogglePanelItem getFirstItem() {
+ return getItemByIndex(0);
}
- public String getNext(String name) {
- if (name == null) {
- throw new IllegalArgumentException("Name is required parameter.");
- }
+ public AbstractTogglePanelItem getPrevItem() {
+ return getPrevItem(getActiveItem());
+ }
- List<UIComponent> children = getChildren();
+ public AbstractTogglePanelItem getPrevItem(String name) {
+ return getItemByIndex(getChildIndex(name) - 1);
+ }
- int nextItem = getChildIndex(name, children) + 1;
- if (nextItem < children.size()) {
- return getFirstItem();
- } else {
- return getChildName(children.get(nextItem));
- }
+ public AbstractTogglePanelItem getNextItem() {
+ return getNextItem(getActiveItem());
}
- private static int getChildIndex(String name, List<UIComponent> children) {
- int ind = 0;
- while (ind < children.size()) {
- UIComponent child = children.get(ind);
- if (name.equals(getChildName(child))) {
+ public AbstractTogglePanelItem getNextItem(String name) {
+ return getItemByIndex(getChildIndex(name) + 1);
+ }
+
+ public AbstractTogglePanelItem getLastItem() {
+ return getItemByIndex(getRenderedChildren().size() - 1);
+ }
+
+ private int getChildIndex(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name is required parameter.");
+ }
+
+ List<AbstractTogglePanelItem> items = getRenderedChildren();
+ for (int ind = 0; ind < items.size(); ind++) {
+ if (name.equals(items.get(ind).getName())) {
return ind;
}
- ind++;
}
- return -1;
+ return Integer.MIN_VALUE;
}
- private static String getChildName(UIComponent item) {
- // TODO nick - panel can include UIParam children - remove this exception
- if (!(item instanceof AbstractTogglePanelItem)) {
- throw new IllegalStateException("TogglePanel can contain only TogglePanelItem as child.");
- }
-
- return ((AbstractTogglePanelItem) item).getName();
- }
-
// ------------------------------------------------
public String getSubmittedActiveItem() {
@@ -593,35 +557,14 @@
// ------------------------------------------------ Event Processing Methods
- /**
- * <p>Add a new {@link org.richfaces.event.ItemChangeListener} to the set of listeners
- * interested in being notified when {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
- *
- * @param listener The {@link org.richfaces.event.ItemChangeListener} to be added
- * @throws NullPointerException if <code>listener</code>
- * is <code>null</code>
- */
public void addItemChangeListener(ItemChangeListener listener) {
addFacesListener(listener);
}
- /**
- * <p>Return the set of registered {@link org.richfaces.event.ItemChangeListener}s for this instance.
- * If there are no registered listeners, a zero-length array is returned.</p>
- */
public ItemChangeListener[] getItemChangeListeners() {
return (ItemChangeListener[]) getFacesListeners(ItemChangeListener.class);
}
- /**
- * <p>Remove an existing {@link org.richfaces.event.ItemChangeListener} (if any) from the
- * set of listeners interested in being notified when
- * {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
- *
- * @param listener The {@link org.richfaces.event.ItemChangeListener} to be removed
- * @throws NullPointerException if <code>listener</code>
- * is <code>null</code>
- */
public void removeItemChangeListener(ItemChangeListener listener) {
removeFacesListener(listener);
}
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -22,9 +22,12 @@
package org.richfaces.component;
+import org.ajax4jsf.renderkit.RendererUtils;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;
+import java.io.IOException;
/**
* @author akolonitsky
@@ -47,14 +50,6 @@
}
@Override
- public void setParent(UIComponent parent) {
- if (parent != null && !(parent instanceof AbstractTogglePanel)) {
- throw new IllegalArgumentException("Parent of TogglePanelItem can be only TogglePanel.");
- }
- super.setParent(parent);
- }
-
- @Override
public AbstractTogglePanel getParent() {
return (AbstractTogglePanel) super.getParent();
}
@@ -64,6 +59,41 @@
return super.getRenderer(context);
}
+ @Override
+ public void encodeAll(FacesContext context) throws IOException {
+ if (getParent().isActiveItem(this)) {
+ super.encodeAll(context);
+ } else {
+ switch (getSwitchType()) {
+ case client:
+ hidePanelItem(this);
+
+ super.encodeAll(context);
+ break;
+
+ case ajax:
+ context.getResponseWriter().write(getPlaceHolder());
+ break;
+
+ case server:
+ // Do nothing.
+ break;
+
+ default:
+ throw new IllegalStateException("Unknown switch type : " + getSwitchType());
+ }
+ }
+ }
+
+ private String getPlaceHolder() {
+ return "<div id=\"" + getClientId() + "\" style=\"display: none\" ></div>";
+ }
+
+ private static void hidePanelItem(UIComponent item) {
+ //TODO nick - attributes shouldn't be overwritten
+ item.getAttributes().put(RendererUtils.HTML.STYLE_ATTRIBUTE, "display:none");
+ }
+
public abstract String getName();
public abstract SwitchType getSwitchType();
@@ -72,3 +102,6 @@
return "TogglePanelItem {name: " + getName() + ", switchType: " + getSwitchType() + '}';
}
}
+
+
+
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -73,7 +73,7 @@
* <code>MethodExpression</code> whose expected param types match
* those of a zero argument method. The usage requirements for both
* of these <code>MethodExpression</code> instances are described in
- * {@link #processItemChange}.</span></p>
+ * {@link #processItemChange}.</p>
*
* @param methodExpressionOneArg a <code>MethodExpression</code>
* that points to a method that returns <code>void</code> and takes
@@ -87,8 +87,8 @@
ELContext elContext = context.getELContext();
this.methodExpressionZeroArg = context.getApplication().
getExpressionFactory().createMethodExpression(elContext,
- methodExpressionOneArg.getExpressionString(), Void.class,
- ITEM_CHANGE_LISTENER_ZERO_ARG_SIG);
+ methodExpressionOneArg.getExpressionString(), Void.class,
+ ITEM_CHANGE_LISTENER_ZERO_ARG_SIG);
}
/**
@@ -183,8 +183,10 @@
return;
}
- methodExpressionOneArg = (MethodExpression) UIComponentBase.restoreAttachedState(context, ((Object[]) state)[0]);
- methodExpressionZeroArg = (MethodExpression) UIComponentBase.restoreAttachedState(context, ((Object[]) state)[1]);
+ methodExpressionOneArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[0]);
+ methodExpressionZeroArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[1]);
}
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -30,6 +30,7 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractDivPanel;
@@ -61,19 +62,10 @@
writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute("id", component.getClientId(context), "clientId");
- writeAttributes(writer, component, ATTRIBUTES);
+ RendererUtils.getInstance()
+ .encodeAttributesFromArray(context, component, ATTRIBUTES);
}
- private void writeAttributes(ResponseWriter writer, UIComponent component, String[] attributes) throws IOException {
- Map<String, Object> componentAttributes = component.getAttributes();
- for (String attrName : attributes) {
- Object attrValue = componentAttributes.get(attrName);
- if (!"null".equalsIgnoreCase(String.valueOf(attrValue))) {
- writer.writeAttribute(attrName, attrValue, attrName); // TODO Use RendererUtils use writeAttribute
- }
- }
- }
-
@Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
super.doEncodeEnd(writer, context, component);
@@ -86,8 +78,6 @@
protected void writeJavaScript(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
Object script = getScriptObject(context, component);
if (script != null) {
-
- // TODO nick - how does script relate to DIV?
writer.startElement(HTML.SCRIPT_ELEM, component);
writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", "type");
writer.writeText(script, null);
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -46,26 +46,35 @@
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(name = "script/TogglePanelItem.js") })
public class TogglePanelItemRenderer extends DivPanelRenderer {
+
+ private static final String LEAVE = "leave";
+ private static final String ENTER = "enter";
@Override
- protected void writeJavaScript(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
- // All script must be written by TogglePanel using method getScriptObject
+ protected void writeJavaScript(ResponseWriter writer, FacesContext context, UIComponent component)
+ throws IOException {
+
+ // All script should be written by TogglePanel using method getScriptObject
}
@Override
protected JSObject getScriptObject(FacesContext context, UIComponent component) {
- return new JSObject("RichFaces.ui.TogglePanelItem", component.getClientId(), getScriptObjectOptions(context, component));
+ return new JSObject("RichFaces.ui.TogglePanelItem", component.getClientId(),
+ getScriptObjectOptions(context, component));
}
@Override
protected Map<String, Object> getScriptObjectOptions(FacesContext context, UIComponent component) {
AbstractTogglePanelItem panelItem = (AbstractTogglePanelItem) component;
- Map<String, Object> options = new HashMap<String, Object>(2);
+ Map<String, Object> options = new HashMap<String, Object>(5);
options.put("name", panelItem.getName());
options.put("togglePanelId", panelItem.getParent().getClientId());
options.put("switchMode", panelItem.getSwitchType());
+ TogglePanelRenderer.addEventOption(context, component, options, LEAVE);
+ TogglePanelRenderer.addEventOption(context, component, options, ENTER);
+
return options;
}
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -22,26 +22,28 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.AbstractTogglePanelItem;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* @author akolonitsky
* @since -4712-01-01
@@ -57,39 +59,40 @@
private static final String VALUE_POSTFIX = "-value";
+ private static final String ON = "on";
+ private static final String ITEM_CHANGE = "itemchange";
+ private static final String BEFORE_ITEM_CHANGE = "beforeitemchange";
+
@Override
protected void doDecode(FacesContext context, UIComponent component) {
+ AbstractTogglePanel panel = (AbstractTogglePanel) component;
+
Map<String, String> requestMap =
context.getExternalContext().getRequestParameterMap();
// Don't overwrite the value unless you have to!
String newValue = requestMap.get(getActiveItemRequestParamName(context, component));
if (newValue != null) {
- setSubmittedValue(component, newValue);
-
-// if (logger.isLoggable(Level.FINE)) {
-// logger.log(Level.FINE, "new value after decoding {0}", newValue);
-// }
+ panel.setSubmittedActiveItem(newValue);
}
String compClientId = component.getClientId(context);
String clientId = requestMap.get(compClientId);
if (clientId != null && clientId.equals(compClientId)) {
- AbstractTogglePanel panel = (AbstractTogglePanel) component;
AbstractTogglePanelItem panelItem = panel.getItem(newValue);
if (panelItem != null) {
context.getPartialViewContext().getRenderIds().add(panelItem.getClientId(context));
//TODO nick - this should be done on encode, not on decode
- addOnCompleteParam(newValue, panel);
+ addOnCompleteParam(newValue, panel.getClientId());
}
}
}
- private void addOnCompleteParam(String newValue, AbstractTogglePanel panel) {
+ private static void addOnCompleteParam(String newValue, String panelId) {
StringBuilder onComplete = new StringBuilder();
- onComplete.append("RichFaces.$('").append(panel.getClientId()).append("').onCompleteHandler('")
- .append(panel.getActiveItem()).append("','").append(newValue).append("');");
+ onComplete.append("RichFaces.$('").append(panelId)
+ .append("').onCompleteHandler('").append(newValue).append("');");
AjaxContext.getCurrentInstance().appendOncomplete(onComplete.toString());
}
@@ -98,24 +101,6 @@
return component.getClientId(context) + VALUE_POSTFIX;
}
-// @Override
- public void setSubmittedValue(UIComponent component, Object value) {
- if (component instanceof AbstractTogglePanel) {
- ((AbstractTogglePanel) component).setSubmittedActiveItem((String) value);
-
-// if (logger.isLoggable(Level.FINE)) {
-// logger.fine("Set submitted value " + value + " on component ");
-// }
- }
-
- }
-
-
-// @Override
-// public boolean getRendersChildren() {
-// return true;
-// }
-
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent comp) throws IOException {
super.doEncodeBegin(writer, context, comp);
@@ -130,85 +115,48 @@
}
@Override
- protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
- if (component.getChildCount() <= 0) {
- return;
- }
-
- //TODO nick - non-rendered items shouldn't be processed
- for (UIComponent child : component.getChildren()) {
- if (!(child instanceof AbstractTogglePanelItem)) {
- throw new IllegalStateException("Child of TogglePanel can be only TogglePanelItem");
- }
-
- doEncodeChild(context, (AbstractTogglePanel) component, (AbstractTogglePanelItem) child);
- }
- }
-
- private void doEncodeChild(FacesContext facesContext, AbstractTogglePanel panel, AbstractTogglePanelItem item)
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent component)
throws IOException {
-
- boolean isSelected = panel.getActiveItem().equals(item.getName());
- if (isSelected) {
- item.encodeAll(facesContext);
-
- } else {
-
- switch (item.getSwitchType()) {
- case client:
- hidePanelItem(item);
-
- item.encodeAll(facesContext);
- break;
-
- case ajax:
- if (!item.isRendered()) {
- break;
- }
-
- hidePanelItem(item);
- item.encodeBegin(facesContext);
- item.encodeEnd(facesContext);
- break;
-
- case server:
- // Do nothing.
- break;
-
- default:
- throw new IllegalStateException("Unknown switch type : " + item.getSwitchType());
- }
- }
-
-
+
+ renderChildren(context, component);
}
- // TODO why item don't know how it should be rendered
- private static void hidePanelItem(UIComponent item) {
- //TODO nick - attributes shouldn't be overwritten
-
- item.getAttributes().put(HTML.STYLE_ATTRIBUTE, "display:none");
- }
-
@Override
protected JSObject getScriptObject(FacesContext context, UIComponent component) {
- return new JSObject("RichFaces.ui.TogglePanel", component.getClientId(), getScriptObjectOptions(context, component));
+ return new JSObject("RichFaces.ui.TogglePanel",
+ component.getClientId(), getScriptObjectOptions(context, component));
}
@Override
protected Map<String, Object> getScriptObjectOptions(FacesContext context, UIComponent component) {
AbstractTogglePanel panel = (AbstractTogglePanel) component;
- Map<String, Object> options = new HashMap<String, Object>(3);
+ Map<String, Object> options = new HashMap<String, Object>(5);
options.put("activeItem", panel.getValue());
- options.put("switchMode", panel.getSwitchType());
options.put("items", getChildrenScriptObjects(context, panel));
-
options.put("ajax", getAjaxOptions(context, panel));
+ addEventOption(context, panel, options, ITEM_CHANGE);
+ addEventOption(context, panel, options, BEFORE_ITEM_CHANGE);
+
return options;
}
+ public static void addEventOption(FacesContext context, UIComponent component, Map<String, Object> options,
+ String eventName) {
+
+ HandlersChain handlersChain = new HandlersChain(context, component);
+ handlersChain.addInlineHandlerFromAttribute(ON + eventName);
+ handlersChain.addBehaviors(eventName);
+ handlersChain.addAjaxSubmitFunction();
+
+ String handler = handlersChain.toScript();
+ if (handler != null) {
+ options.put(ON + eventName,
+ new JSFunctionDefinition(JSReference.EVENT).addToBody(handler));
+ }
+ }
+
private static AjaxEventOptions getAjaxOptions(FacesContext context, UIComponent panel) {
return AjaxRendererUtils.buildEventOptions(context, panel);
}
Modified: root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -25,6 +25,7 @@
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.event.ItemChangeEvent;
import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
@@ -38,7 +39,6 @@
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagException;
import javax.faces.view.facelets.TagHandler;
-import java.io.IOException;
import java.io.Serializable;
/**
@@ -113,7 +113,7 @@
}
}
- public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
+ public void apply(FaceletContext ctx, UIComponent parent) {
// only process if it's been created
if (parent == null || !ComponentHandler.isNew(parent)) {
@@ -126,7 +126,7 @@
// Allow the composite component to know about the target component.
TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
} else {
- throw new TagException(this.tag, "Parent is not of type EditableValueHolder, type is: " + parent);
+ throw new TagException(this.tag, "Parent is not of type AbstractTogglePanel, type is: " + parent);
}
}
@@ -137,8 +137,7 @@
valueExpr = this.binding.getValueExpression(ctx, ItemChangeListener.class);
}
- AbstractTogglePanel evh = (AbstractTogglePanel) parent;
- //TODO nick - this should be done via API interface define interfaces SelectedItemChangeSource
+ ItemChangeSource evh = (ItemChangeSource) parent;
evh.addItemChangeListener(new LazyItemChangeListener(this.listenerType, valueExpr));
}
Modified: root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
===================================================================
--- root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-23 16:17:45 UTC (rev 18219)
+++ root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-23 16:43:22 UTC (rev 18220)
@@ -38,11 +38,11 @@
* @return {void}
* */
exec : function (oldPanel, newPanel) {
- if (this.comp.switchMode == "server") {
+ if (newPanel.switchMode == "server") {
return this.execServer(oldPanel, newPanel);
- } else if (this.comp.switchMode == "ajax") {
+ } else if (newPanel.switchMode == "ajax") {
return this.execAjax(oldPanel, newPanel);
- } else if (this.comp.switchMode == "client") {
+ } else if (newPanel.switchMode == "client") {
return this.execClient(oldPanel, newPanel);
} else {
rf.log.error("SwitchItems.exec : unknown switchMode (" + this.comp.switchMode + ")");
@@ -130,8 +130,17 @@
* */
__getValueInputId: function () {
return this.comp.id + "-value"
- }
+ },
+ /********************* Events *************************/
+
+ __fireItemChange : function (oldItem, newItem) {
+ return new rf.Event.fireById(this.comp.id, "itemchange", {
+ id: this.comp.id,
+ oldItem : oldItem,
+ newItem : newItem
+ });
+ }
};
/**
@@ -154,7 +163,6 @@
this.options = options;
this.activeItem = this.options.activeItem;
- this.switchMode = this.options.switchMode;
this.items = this.options.items;
},
@@ -220,9 +228,9 @@
* please, remove this method when client side ajax events will be added
*
* */
- onCompleteHandler : function (oldItemName, newItemName) {
- var oldItem = this.__getItemByName(this.items, oldItemName);
- var newItem = this.__getItemByName(this.items, newItemName);
+ onCompleteHandler : function (newItemName) {
+ var oldItem = this.__getItemByName(this.activeItem);
+ var newItem = this.__getItemByName(newItemName);
// Don't do like this and remove it ASAP
new SwitchItems(this).execClient(oldItem, newItem);
@@ -266,7 +274,7 @@
return null;
}
- return this.__getItemName(this.items, itemIndex + 1);
+ return this.__getItemName(itemIndex + 1);
},
/**
@@ -276,7 +284,7 @@
* @return {String} name of first panel item
*/
firstItem: function () {
- return this.__getItemName(this.items, 0);
+ return this.__getItemName(0);
},
/**
@@ -286,7 +294,7 @@
* @return {String} name of last panel item
*/
lastItem: function () {
- return this.__getItemName(this.items, this.items.length - 1);
+ return this.__getItemName(this.items.length - 1);
},
/**
@@ -303,34 +311,13 @@
return null;
}
- return this.__getItemName(this.items, itemIndex - 1);
+ return this.__getItemName(itemIndex - 1);
},
/////////////////////////////////////////////////////////////////////////////////
//// Private
/////////////////////////////////////////////////////////////////////////////////
- /********************* Events *************************/
-
- /**
- * Fire Concealable Event
- * */
- __fireBeforeItemChange : function (oldItem, newItem) {
- return rf.Event.fireById(this.id, "beforeitemchange", {
- id: this.id,
- oldItem : oldItem,
- newItem : newItem
- });
- },
-
- __fireItemChange : function (oldItem, newItem) {
- return new rf.Event.fireById(this.id, "itemchange", {
- id: this.id,
- oldItem : oldItem,
- newItem : newItem
- });
- },
-
/********************* Methods *************************/
__ITEMS_META_NAMES : {
@@ -382,8 +369,17 @@
return item.getName();
},
+ /**
+ * Fire Concealable Event
+ * */
+ __fireBeforeItemChange : function (oldItem, newItem) {
+ return rf.Event.fireById(this.id, "beforeitemchange", {
+ id: this.id,
+ oldItem : oldItem,
+ newItem : newItem
+ });
+ },
-
// class stuff
destroy: function () {
// rf.Event.unbindById(this.options.buttonId, "."+this.namespace);
Added: root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java
===================================================================
--- root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java (rev 0)
+++ root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java 2010-07-23 16:43:22 UTC (rev 18220)
@@ -0,0 +1,150 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.faces.component.UIComponent;
+import java.util.List;
+
+/**
+ * @author akolonitsky
+ * @since Jul 20, 2010
+ */
+public class AbstractTogglePanelTest {
+
+ private static final String ITEM1 = "item1";
+ private static final String ITEM2 = "item2";
+ private static final String ITEM3 = "item3";
+
+ private UITogglePanel panel;
+ private UITogglePanelItem item1;
+ private UITogglePanelItem item2;
+ private UITogglePanelItem item3;
+
+ @Before
+ public void setUp () {
+ panel = new UITogglePanel();
+ List<UIComponent> children = panel.getChildren();
+
+ item1 = createItem(ITEM1);
+ children.add(item1);
+
+ item2 = createItem(ITEM2);
+ children.add(item2);
+
+ item3 = createItem(ITEM3);
+ children.add(item3);
+ }
+
+ @Test
+ public void testGetItemByIndex() {
+ panel.setActiveItem(ITEM1);
+
+ Assert.assertEquals(item1, panel.getItemByIndex(0));
+ Assert.assertEquals(item2, panel.getItemByIndex(1));
+ Assert.assertEquals(item3, panel.getItemByIndex(2));
+ Assert.assertEquals(null, panel.getItemByIndex(3));
+
+ item1.setRendered(false);
+
+ Assert.assertEquals(item2, panel.getItemByIndex(0));
+ Assert.assertEquals(item3, panel.getItemByIndex(1));
+ Assert.assertEquals(null, panel.getItemByIndex(2));
+ Assert.assertEquals(null, panel.getItemByIndex(3));
+
+ item2.setRendered(false);
+ item3.setRendered(false);
+ Assert.assertEquals(null, panel.getItemByIndex(0));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetItem() {
+ Assert.assertEquals(item1, panel.getItem(ITEM1));
+ Assert.assertEquals(item2, panel.getItem(ITEM2));
+ Assert.assertEquals(item3, panel.getItem(ITEM3));
+ Assert.assertEquals(null, panel.getItem("123"));
+
+ panel.getItem(null);
+ }
+
+ @Test
+ public void testItemOrder() {
+ panel.setActiveItem(ITEM1);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(item2, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM2);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(item1, panel.getPrevItem());
+ Assert.assertEquals(item3, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM3);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(item2, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ item1.setRendered(false);
+
+ panel.setActiveItem(ITEM1);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM2);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(item3, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM3);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(item2, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+ }
+
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetChildName() {
+ panel.setActiveItem(ITEM1);
+ Assert.assertTrue(panel.isActiveItem(item1));
+ Assert.assertFalse(panel.isActiveItem(item2));
+ Assert.assertFalse(panel.isActiveItem(null));
+
+ panel.isActiveItem(panel);
+ }
+
+ private static UITogglePanelItem createItem(String name) {
+ UITogglePanelItem item = new UITogglePanelItem();
+ item.setName(name);
+
+ return item;
+ }
+}
14 years, 5 months
JBoss Rich Faces SVN: r18219 - in root: ui/core/trunk/ui/src/main/java/org/richfaces/renderkit and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-23 12:17:45 -0400 (Fri, 23 Jul 2010)
New Revision: 18219
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
Log:
HandlersChain refactoring
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -313,11 +313,11 @@
private static void appendComponentOptions(FacesContext facesContext, UIComponent component,
AjaxEventOptions ajaxEventOptions) {
String behaviorName = "begin";
- HandlersChain handlersChain = new HandlersChain(component);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component);
String inlineHandler = getAjaxOnBegin(component);
- handlersChain.addInlineHandlerAsValue(facesContext, inlineHandler);
- handlersChain.addBehaviors(facesContext, behaviorName);
+ handlersChain.addInlineHandlerAsValue(inlineHandler);
+ handlersChain.addBehaviors(behaviorName);
String handlerScript = handlersChain.toScript();
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -21,9 +21,16 @@
package org.ajax4jsf.renderkit;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.AJAX_FUNCTION_NAME;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildAjaxFunction;
+import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildEventOptions;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
import javax.faces.component.UIComponent;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
@@ -31,12 +38,10 @@
import javax.faces.component.behavior.ClientBehaviorHint;
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -49,24 +54,30 @@
// TODO: review for optimization
private List<String> handlers = new ArrayList<String>(2);
+
+ private FacesContext facesContext;
private UIComponent component;
private Collection<Parameter> parameters;
- public HandlersChain(UIComponent component) {
+ public HandlersChain(FacesContext facesContext, UIComponent component) {
+ this.facesContext = facesContext;
this.component = component;
}
- public HandlersChain(UIComponent component, boolean includeClientId) {
+ public HandlersChain(FacesContext facesContext, UIComponent component, boolean includeClientId) {
+ this.facesContext = facesContext;
this.component = component;
this.includeClientId = includeClientId;
}
- public HandlersChain(UIComponent component, Collection<Parameter> parameters) {
+ public HandlersChain(FacesContext facesContext, UIComponent component, Collection<Parameter> parameters) {
+ this.facesContext = facesContext;
this.component = component;
this.parameters = parameters;
}
- public HandlersChain(UIComponent component, Collection<Parameter> parameters, boolean includeClientId) {
+ public HandlersChain(FacesContext facesContext, UIComponent component, Collection<Parameter> parameters, boolean includeClientId) {
+ this.facesContext = facesContext;
this.component = component;
this.parameters = parameters;
this.includeClientId = includeClientId;
@@ -91,10 +102,10 @@
return behaviors;
}
- private Collection<Parameter> getParameters(FacesContext context) {
+ private Collection<Parameter> getParameters() {
if (parameters == null) {
RendererUtils rendererUtils = RendererUtils.getInstance();
- Map<String, Object> parametersMap = rendererUtils.createParametersMap(context, component);
+ Map<String, Object> parametersMap = rendererUtils.createParametersMap(facesContext, component);
parameters = createParametersList(parametersMap);
}
@@ -106,21 +117,21 @@
return hasSubmittingBehavior;
}
- public void addInlineHandlerAsValue(FacesContext context, String handlerValue) {
+ public void addInlineHandlerAsValue(String handlerValue) {
if (isNotEmpty(handlerValue)) {
handlers.add(handlerValue);
}
}
- public void addInlineHandlerFromAttribute(FacesContext context, String attributeName) {
- addInlineHandlerAsValue(context, (String) component.getAttributes().get(attributeName));
+ public void addInlineHandlerFromAttribute(String attributeName) {
+ addInlineHandlerAsValue((String) component.getAttributes().get(attributeName));
}
- public void addBehaviors(FacesContext context, String domEventName) {
- addBehaviors(context, domEventName, null);
+ public void addBehaviors(String domEventName) {
+ addBehaviors(domEventName, null);
}
- public void addBehaviors(FacesContext context, String domEventName, String logicalEventName) {
+ public void addBehaviors(String domEventName, String logicalEventName) {
String name = domEventName;
List<ClientBehavior> behaviorsList = getBehaviorsList(domEventName);
@@ -133,9 +144,9 @@
return;
}
- ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext(context, component,
- name, includeClientId ? component.getClientId(context) : null,
- getParameters(context));
+ ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, component,
+ name, includeClientId ? component.getClientId(facesContext) : null,
+ getParameters());
for (ClientBehavior clientBehavior : behaviorsList) {
String behaviorScript = clientBehavior.getScript(behaviorContext);
@@ -150,6 +161,21 @@
}
}
+ public void addAjaxSubmitFunction() {
+ if (!this.hasSubmittingBehavior()) {
+ hasSubmittingBehavior = true;
+
+ JSFunction ajaxFunction = buildAjaxFunction(facesContext, component, AJAX_FUNCTION_NAME);
+ AjaxEventOptions eventOptions = buildEventOptions(facesContext, component);
+
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
+
+ this.addInlineHandlerAsValue(ajaxFunction.toScript());
+ }
+ }
+
public String toScript() {
String result = null;
@@ -179,4 +205,5 @@
return parameters;
}
+
}
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -263,10 +263,10 @@
String htmlEventName = "on" + behaviorEventName;
if ((attributesExclusions == null) || (Arrays.binarySearch(attributesExclusions, htmlEventName) < 0)) {
- HandlersChain handlersChain = new HandlersChain(component, parametersList);
+ HandlersChain handlersChain = new HandlersChain(context, component, parametersList);
- handlersChain.addInlineHandlerFromAttribute(context, htmlEventName);
- handlersChain.addBehaviors(context, behaviorEventName);
+ handlersChain.addInlineHandlerFromAttribute(htmlEventName);
+ handlersChain.addBehaviors(behaviorEventName);
String handlerScript = handlersChain.toScript();
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -23,10 +23,6 @@
package org.richfaces.renderkit;
-import static org.ajax4jsf.renderkit.AjaxRendererUtils.AJAX_FUNCTION_NAME;
-import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildAjaxFunction;
-import static org.ajax4jsf.renderkit.AjaxRendererUtils.buildEventOptions;
-
import java.util.Map;
import javax.faces.application.ResourceDependencies;
@@ -35,8 +31,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.log.RichfacesLogger;
@@ -89,22 +83,12 @@
StringBuffer onClick = new StringBuffer();
if (!getUtils().isBooleanAttribute(component, "disabled")) {
- HandlersChain handlersChain = new HandlersChain(component);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component);
- handlersChain.addInlineHandlerFromAttribute(context, "onclick");
- handlersChain.addBehaviors(context, "click", "action");
+ handlersChain.addInlineHandlerFromAttribute("onclick");
+ handlersChain.addBehaviors("click", "action");
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = buildAjaxFunction(context, component, AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions = buildEventOptions(context, component);
-
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
-
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handlerScript = handlersChain.toScript();
if (handlerScript != null) {
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -21,27 +21,26 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
+
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPoll;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionEvent;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author shura
*/
@@ -81,20 +80,11 @@
Integer interval = new Integer(poll.getInterval());
options.put("pollinterval", interval);
options.put("pollId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(poll);
- handlersChain.addInlineHandlerFromAttribute(context, AbstractPoll.ON_TIMER);
- handlersChain.addBehaviors(context, AbstractPoll.TIMER);
+ HandlersChain handlersChain = new HandlersChain(facesContext, poll);
+ handlersChain.addInlineHandlerFromAttribute(AbstractPoll.ON_TIMER);
+ handlersChain.addBehaviors(AbstractPoll.TIMER);
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
- context, poll, AjaxRendererUtils.AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions = AjaxRendererUtils.buildEventOptions(context, poll);
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handler = handlersChain.toScript();
if (handler != null) {
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -35,8 +35,6 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.renderkit.AjaxEventOptions;
-import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
@@ -107,20 +105,11 @@
options.put("pushId", push.getListenerId(context));
options.put("clientId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(push);
- handlersChain.addInlineHandlerFromAttribute(context, AbstractPush.ON_DATA_AVAILABLE);
- handlersChain.addBehaviors(context, AbstractPush.DATA_AVAILABLE);
+ HandlersChain handlersChain = new HandlersChain(facesContext, push);
+ handlersChain.addInlineHandlerFromAttribute(AbstractPush.ON_DATA_AVAILABLE);
+ handlersChain.addBehaviors(AbstractPush.DATA_AVAILABLE);
+ handlersChain.addAjaxSubmitFunction();
- if (!handlersChain.hasSubmittingBehavior()) {
- JSFunction ajaxFunction = AjaxRendererUtils
- .buildAjaxFunction(context, push, AjaxRendererUtils.AJAX_FUNCTION_NAME);
- AjaxEventOptions eventOptions = AjaxRendererUtils.buildEventOptions(context, push);
- if (!eventOptions.isEmpty()) {
- ajaxFunction.addParameter(eventOptions);
- }
- handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
- }
-
String handler = handlersChain.toScript();
if (handler != null) {
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-07-23 14:17:53 UTC (rev 18218)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-07-23 16:17:45 UTC (rev 18219)
@@ -202,9 +202,9 @@
Map<String, Object> attributes = ajaxStatus.getAttributes();
for (String eventName : EVENT_NAMES) {
String eventAttribute = "on" + eventName;
- HandlersChain handlersChain = new HandlersChain(component, true);
- handlersChain.addInlineHandlerFromAttribute(context, eventAttribute);
- handlersChain.addBehaviors(context, eventName);
+ HandlersChain handlersChain = new HandlersChain(facesContext, component, true);
+ handlersChain.addInlineHandlerFromAttribute(eventAttribute);
+ handlersChain.addBehaviors(eventName);
rendererUtils.addToScriptHash(options, eventAttribute,
handlersChain.toScript(), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
14 years, 5 months
JBoss Rich Faces SVN: r18218 - in root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richDataScroller and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-07-23 10:17:53 -0400 (Fri, 23 Jul 2010)
New Revision: 18218
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java
Log:
extended richDataScroller/TestPagination for another fastStep/maxPages values
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:17:03 UTC (rev 18217)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:17:53 UTC (rev 18218)
@@ -328,7 +328,6 @@
List<Object> result = new LinkedList<Object>();
for (int i = 0; i < use.value().length; i++) {
boolean satisfied = false;
- System.out.println(this.getClass().getName());
for (Field field : this.getClass().getDeclaredFields()) {
String name = use.value()[i];
name = StringUtils.replace(name, "*", ".+");
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:17:03 UTC (rev 18217)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:17:53 UTC (rev 18218)
@@ -24,7 +24,7 @@
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
import static org.jboss.test.selenium.locator.LocatorFactory.id;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.*;
import java.net.URL;
@@ -47,9 +47,6 @@
*/
public class TestPagination extends AbstractMetamerTest {
-
-
- private static final int FAST_STEP = 2;
private static final int[] PAGES = new int[] { 3, 6, 1, 4, 6, 2, 4, 5 };
@Inject
@@ -64,11 +61,11 @@
DataTable dataTable = new DataTable(pjq("table.rf-dt[id$=richDataTable]"));
@Inject
- @Use(ints = { 2 })
+ @Use(ints = { 2, 3 })
int fastStep;
@Inject
- @Use(ints = { 3 })
+ @Use(ints = { 3, 4 })
int maxPages;
public TestPagination() {
@@ -85,18 +82,23 @@
public URL getTestUrl() {
return buildUrl(contextPath, "faces/components/richDataScroller/simple.xhtml");
}
-
+ @BeforeMethod
+ public void prepareAttributes() {
+ guardHttp(selenium).type(attributeFastStep, String.valueOf(fastStep));
+ guardHttp(selenium).type(attributeMaxPages, String.valueOf(maxPages));
+ }
@Test
- public void testNumberedPages() {
- dataScroller.setFastStep(FAST_STEP);
+ public void testNumberedPagesWithMaxPagesAndFastStep() {
+ dataScroller.setFastStep(fastStep);
dataScroller.setLastPage(dataScroller.getLastPage());
for (int pageNumber : PAGES) {
String tableText = dataTable.getTableText();
dataScroller.gotoPage(pageNumber);
assertFalse(tableText.equals(dataTable.getTableText()));
+ assertEquals(maxPages, dataScroller.getCountOfVisiblePages());
}
}
@@ -105,10 +107,4 @@
public void invalidateSession() {
super.invalidateSession();
}
-
- @BeforeMethod
- public void prepareAttributes() {
- guardHttp(selenium).type(attributeFastStep, "2");
- guardHttp(selenium).type(attributeMaxPages, "3");
- }
}
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java 2010-07-23 14:17:03 UTC (rev 18217)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java 2010-07-23 14:17:53 UTC (rev 18218)
@@ -33,23 +33,10 @@
*/
public class AssertingDataScroller extends DataScroller {
- private static final String CLASS_DISABLED = "rf-ds-dis";
-
- private Integer fastStep = null;
- private Integer lastPage = null;
-
public AssertingDataScroller(JQueryLocator root) {
super(root);
}
- public void setFastStep(int fastStep) {
- this.fastStep = fastStep;
- }
-
- public void setLastPage(int pageNumber) {
- this.lastPage = pageNumber;
- }
-
@Override
public void gotoPage(int pageNumber) {
int startCount = this.getCountOfVisiblePages();
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java 2010-07-23 14:17:03 UTC (rev 18217)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java 2010-07-23 14:17:53 UTC (rev 18218)
@@ -39,6 +39,8 @@
*/
public class DataScroller {
+ protected static final String CLASS_DISABLED = "rf-ds-dis";
+
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
LocatorReference<JQueryLocator> root = new LocatorReference<JQueryLocator>(null);
@@ -54,11 +56,14 @@
ReferencedLocator<JQueryLocator> firstVisiblePage = ref(root, "> .rf-ds-dtl:first");
ReferencedLocator<JQueryLocator> lastVisiblePage = ref(root, "> .rf-ds-dtl:last");
ReferencedLocator<JQueryLocator> currentPage = ref(root, "> .rf-ds-cur");
+
+ Integer fastStep = null;
+ Integer lastPage = null;
public DataScroller(JQueryLocator root) {
setRoot(root);
}
-
+
public JQueryLocator getRoot() {
return root.getLocator();
}
@@ -66,6 +71,14 @@
public void setRoot(JQueryLocator root) {
this.root.setLocator(root);
}
+
+ public void setFastStep(int fastStep) {
+ this.fastStep = fastStep;
+ }
+
+ public void setLastPage(int pageNumber) {
+ this.lastPage = pageNumber;
+ }
public void gotoFirstPage() {
if (!isFirstPage()) {
@@ -80,27 +93,47 @@
}
public void gotoPage(int pageNumber) {
- while (pageNumber > getLastVisiblePage()) {
+ while (pageNumber > getLastVisiblePage()) {
fastForward();
}
+
while (pageNumber < getFirstVisiblePage()) {
fastRewind();
}
+
clickPageButton(pageNumber);
}
public void fastForward() {
- if (selenium.belongsClass(fastForwardButton, "rf-ds-dis")) {
- throw new AssertionError("fast forward button disabled");
+ if (selenium.belongsClass(fastForwardButton, CLASS_DISABLED)) {
+ if (fastStep != null && lastPage != null) {
+ if (getCurrentPage() + fastStep > lastPage) {
+ gotoPage(getLastVisiblePage());
+ } else {
+ throw new AssertionError("fast forward button disabled");
+ }
+ } else {
+ gotoPage(getLastVisiblePage());
+ }
+ } else {
+ clickFastForward();
}
- clickFastForward();
}
public void fastRewind() {
- if (selenium.belongsClass(fastRewindButton, "rf-ds-dis")) {
- throw new AssertionError("fast rewind button disabled");
+ if (selenium.belongsClass(fastRewindButton, CLASS_DISABLED)) {
+ if (fastStep != null) {
+ if (getCurrentPage() - fastStep <= 0) {
+ gotoPage(getFirstVisiblePage());
+ } else {
+ throw new AssertionError("fast forward button disabled");
+ }
+ } else {
+ gotoPage(getFirstVisiblePage());
+ }
+ } else {
+ clickFastRewind();
}
- clickFastRewind();
}
public int getCountOfVisiblePages() {
14 years, 5 months
JBoss Rich Faces SVN: r18217 - in root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richDataScroller and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-07-23 10:17:03 -0400 (Fri, 23 Jul 2010)
New Revision: 18217
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
Log:
allow access the private/protected fields by parameter injection
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:16:17 UTC (rev 18216)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:17:03 UTC (rev 18217)
@@ -328,6 +328,7 @@
List<Object> result = new LinkedList<Object>();
for (int i = 0; i < use.value().length; i++) {
boolean satisfied = false;
+ System.out.println(this.getClass().getName());
for (Field field : this.getClass().getDeclaredFields()) {
String name = use.value()[i];
name = StringUtils.replace(name, "*", ".+");
@@ -336,6 +337,7 @@
if (pattern.matcher(field.getName()).matches()) {
if (parameterType.isAssignableFrom(field.getType())) {
try {
+ field.setAccessible(true);
result.add(field.get(this));
satisfied = true;
} catch (Exception e) {
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:16:17 UTC (rev 18216)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:17:03 UTC (rev 18217)
@@ -54,9 +54,9 @@
@Inject
@Use(value = { "dataScroller*" })
- public AssertingDataScroller dataScroller;
- public AssertingDataScroller dataScroller1 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
- public AssertingDataScroller dataScroller2 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
+ AssertingDataScroller dataScroller;
+ AssertingDataScroller dataScroller1 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
+ AssertingDataScroller dataScroller2 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
IdLocator attributeFastStep = id("form:attributes:fastStepInput");
IdLocator attributeMaxPages = id("form:attributes:maxPagesInput");
14 years, 5 months
JBoss Rich Faces SVN: r18216 - root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-07-23 10:16:17 -0400 (Fri, 23 Jul 2010)
New Revision: 18216
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
Log:
allow parametrization to create test cases from non-parametric constructors
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:15:35 UTC (rev 18215)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:16:17 UTC (rev 18216)
@@ -218,6 +218,14 @@
}
}
+ if (constructor == null) {
+ try {
+ return new Object[] { this.getClass().newInstance() };
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
Map<NamedType, List<? extends Object>> parameters = new LinkedHashMap<NamedType, List<? extends Object>>();
// fill all parameters with null values to sorted map
@@ -265,12 +273,12 @@
Object[][] combinations = generateCombinations(parameterArray);
Object[] result = new Object[combinations.length];
- for (int i = 0; i < combinations.length; i++) {
- try {
+ try {
+ for (int i = 0; i < combinations.length; i++) {
result[i] = constructor.newInstance(combinations[i]);
- } catch (Exception e) {
- throw new RuntimeException(e);
}
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
return result;
14 years, 5 months
JBoss Rich Faces SVN: r18215 - in root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richDataScroller and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-07-23 10:15:35 -0400 (Fri, 23 Jul 2010)
New Revision: 18215
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
Log:
all @Factory from TestPagination prototype was moved to AbstractMetamerTest
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:14:55 UTC (rev 18214)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractMetamerTest.java 2010-07-23 14:15:35 UTC (rev 18215)
@@ -25,17 +25,31 @@
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.net.URL;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
import org.jboss.test.selenium.AbstractTestCase;
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.encapsulated.JavaScript;
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.internal.NamedType;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Factory;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@@ -53,6 +67,9 @@
public static final long TIMEOUT = 5000;
private String[][] templates;
+ public AbstractMetamerTest() {
+ }
+
/**
* Returns the url to test page to be opened by Selenium
*
@@ -72,7 +89,7 @@
return templates;
}
- return new Object[][]{{"plain"}};
+ return new Object[][] { { "plain" } };
}
/**
@@ -81,7 +98,7 @@
* @param urlParams
*/
@BeforeClass(alwaysRun = true)
- @Parameters({"templates"})
+ @Parameters({ "templates" })
public void initTemplates(@Optional String urlParams) {
if (urlParams == null) {
return;
@@ -172,14 +189,14 @@
assertEquals(selenium.getAlert(), event.getEventName(), event.getEventName()
+ " attribute did not change correctly");
}
-
+
/**
* Hides header, footer and inputs for attributes.
*/
protected void hideControls() {
selenium.getEval(new JavaScript("window.hideControls()"));
}
-
+
/**
* Shows header, footer and inputs for attributes.
*/
@@ -187,4 +204,144 @@
selenium.getEval(new JavaScript("window.showControls()"));
}
+ @Factory
+ public Object[] createTests() {
+ // obtain parametrized constructor
+ Constructor<?> constructor = null;
+ for (Constructor<?> c : this.getClass().getConstructors()) {
+ if (c.getParameterTypes().length > 0) {
+ if (constructor == null) {
+ constructor = c;
+ } else {
+ throw new IllegalStateException("there cannot be more than one parametrized constructor");
+ }
+ }
+ }
+
+ Map<NamedType, List<? extends Object>> parameters = new LinkedHashMap<NamedType, List<? extends Object>>();
+
+ // fill all parameters with null values to sorted map
+ for (int i = 0; i < constructor.getParameterTypes().length; i++) {
+ NamedType namedType = new NamedType(constructor.getParameterTypes()[i],
+ constructor.getParameterAnnotations()[i]);
+
+ if (parameters.containsKey(namedType)) {
+ throw new IllegalStateException("there are ambiguous parameters");
+ } else {
+ parameters.put(namedType, null);
+ }
+ }
+
+ List<Field> injections = new LinkedList<Field>();
+
+ for (Field field : this.getClass().getDeclaredFields()) {
+ if (field.getAnnotation(Inject.class) != null) {
+ if (field.getAnnotation(Use.class) != null) {
+ NamedType namedType = new NamedType(field.getType(), (String) null);
+ if (!parameters.containsKey(namedType)) {
+ namedType = new NamedType(field.getType(), field.getName());
+ }
+ if (!parameters.containsKey(namedType)) {
+ throw new IllegalStateException("cannot find equivalent constructor parameter");
+ }
+
+ parameters.put(namedType, getUseParameter(field.getType(), field.getAnnotation(Use.class)));
+ } else {
+ injections.add(field);
+ }
+ }
+ }
+
+ if (!injections.isEmpty()) {
+ throw new IllegalStateException("all injections weren't satisfied");
+ }
+
+ Object[][] parameterArray = new Object[parameters.size()][];
+ int parameterPosition = 0;
+ for (List<? extends Object> parameter : parameters.values()) {
+ parameterArray[parameterPosition++] = parameter.toArray();
+ }
+
+ Object[][] combinations = generateCombinations(parameterArray);
+
+ Object[] result = new Object[combinations.length];
+ for (int i = 0; i < combinations.length; i++) {
+ try {
+ result[i] = constructor.newInstance(combinations[i]);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return result;
+ }
+
+ private Object[][] generateCombinations(Object[][] toCombine) {
+ int count = 1;
+ for (int outter = 0; outter < toCombine.length; outter++) {
+ count *= toCombine[outter].length;
+ }
+
+ Object[][] result = new Object[count][toCombine.length];
+
+ int[] position = new int[toCombine.length];
+ Arrays.fill(position, 0);
+ // int iterate = 0;
+
+ for (int i = 0; i < count; i++) {
+ result[i] = new Object[toCombine.length];
+
+ for (int j = 0; j < toCombine.length; j++) {
+ result[i][j] = toCombine[j][position[j]];
+ }
+
+ // iterate
+ if (i + 1 < count) {
+ for (int j = 0; j < toCombine.length; j++) {
+ position[j] += 1;
+ if (position[j] < toCombine[j].length) {
+ break;
+ } else {
+ position[j] = 0;
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private List<? extends Object> getUseParameter(Class<?> parameterType, Use use) {
+ if (parameterType == int.class || parameterType == Integer.class) {
+ return Arrays.asList(ArrayUtils.toObject(use.ints()));
+ }
+
+ // tries satisfy parameter from fields
+ List<Object> result = new LinkedList<Object>();
+ for (int i = 0; i < use.value().length; i++) {
+ boolean satisfied = false;
+ for (Field field : this.getClass().getDeclaredFields()) {
+ String name = use.value()[i];
+ name = StringUtils.replace(name, "*", ".+");
+ name = StringUtils.replace(name, "?", ".");
+ Pattern pattern = Pattern.compile(name);
+ if (pattern.matcher(field.getName()).matches()) {
+ if (parameterType.isAssignableFrom(field.getType())) {
+ try {
+ result.add(field.get(this));
+ satisfied = true;
+ } catch (Exception e) {
+ throw new IllegalStateException("the field cannot be obtained");
+ }
+ }
+ }
+ }
+ if (satisfied) {
+ continue;
+ }
+ throw new IllegalStateException("cannot find the field satysfying injection point");
+ }
+ return result;
+ }
+
}
Modified: root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
===================================================================
--- root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:14:55 UTC (rev 18214)
+++ root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23 14:15:35 UTC (rev 18215)
@@ -21,37 +21,24 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richDataScroller;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
import static org.jboss.test.selenium.locator.LocatorFactory.id;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertFalse;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import java.net.URL;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
import org.jboss.test.selenium.locator.IdLocator;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.Named;
import org.richfaces.tests.metamer.ftest.annotations.Use;
-import org.richfaces.tests.metamer.ftest.internal.NamedType;
import org.richfaces.tests.metamer.ftest.richExtendedDataTable.AssertingDataScroller;
import org.richfaces.tests.metamer.ftest.richExtendedDataTable.DataTable;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Factory;
import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
-
/**
* Test the functionality of switching pages using DataScroller bound to DataTable.
*
@@ -60,18 +47,20 @@
*/
public class TestPagination extends AbstractMetamerTest {
+
+
private static final int FAST_STEP = 2;
private static final int[] PAGES = new int[] { 3, 6, 1, 4, 6, 2, 4, 5 };
+
+ @Inject
+ @Use(value = { "dataScroller*" })
+ public AssertingDataScroller dataScroller;
+ public AssertingDataScroller dataScroller1 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
+ public AssertingDataScroller dataScroller2 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
IdLocator attributeFastStep = id("form:attributes:fastStepInput");
IdLocator attributeMaxPages = id("form:attributes:maxPagesInput");
- @Inject
- @Use(value = { "dataScroller*" })
- AssertingDataScroller dataScroller;
- AssertingDataScroller dataScroller1 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
- AssertingDataScroller dataScroller2 = new AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
-
DataTable dataTable = new DataTable(pjq("table.rf-dt[id$=richDataTable]"));
@Inject
@@ -97,146 +86,8 @@
return buildUrl(contextPath, "faces/components/richDataScroller/simple.xhtml");
}
- @Factory
- public Object[] createTests() {
- // obtain parametrized constructor
- Constructor<?> constructor = null;
- for (Constructor<?> c : this.getClass().getConstructors()) {
- if (c.getParameterTypes().length > 0) {
- if (constructor == null) {
- constructor = c;
- } else {
- throw new IllegalStateException("there cannot be more than one parametrized constructor");
- }
- }
- }
+
- Map<NamedType, List<? extends Object>> parameters = new LinkedHashMap<NamedType, List<? extends Object>>();
-
- // fill all parameters with null values to sorted map
- for (int i = 0; i < constructor.getParameterTypes().length; i++) {
- NamedType namedType = new NamedType(constructor.getParameterTypes()[i],
- constructor.getParameterAnnotations()[i]);
-
- if (parameters.containsKey(namedType)) {
- throw new IllegalStateException("there are ambiguous parameters");
- } else {
- parameters.put(namedType, null);
- }
- }
-
- List<Field> injections = new LinkedList<Field>();
-
- for (Field field : this.getClass().getDeclaredFields()) {
- if (field.getAnnotation(Inject.class) != null) {
- if (field.getAnnotation(Use.class) != null) {
- NamedType namedType = new NamedType(field.getType(), (String) null);
- if (!parameters.containsKey(namedType)) {
- namedType = new NamedType(field.getType(), field.getName());
- }
- if (!parameters.containsKey(namedType)) {
- throw new IllegalStateException("cannot find equivalent constructor parameter");
- }
-
- parameters.put(namedType, getUseParameter(field.getType(), field.getAnnotation(Use.class)));
- } else {
- injections.add(field);
- }
- }
- }
-
- if (!injections.isEmpty()) {
- throw new IllegalStateException("all injections weren't satisfied");
- }
-
- Object[][] parameterArray = new Object[parameters.size()][];
- int parameterPosition = 0;
- for (List<? extends Object> parameter : parameters.values()) {
- parameterArray[parameterPosition++] = parameter.toArray();
- }
-
- Object[][] combinations = generateCombinations(parameterArray);
-
- Object[] result = new Object[combinations.length];
- for (int i = 0; i < combinations.length; i++) {
- try {
- result[i] = constructor.newInstance(combinations[i]);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- return result;
- }
-
- private Object[][] generateCombinations(Object[][] toCombine) {
- int count = 1;
- for (int outter = 0; outter < toCombine.length; outter++) {
- count *= toCombine[outter].length;
- }
-
- Object[][] result = new Object[count][toCombine.length];
-
- int[] position = new int[toCombine.length];
- Arrays.fill(position, 0);
- // int iterate = 0;
-
- for (int i = 0; i < count; i++) {
- result[i] = new Object[toCombine.length];
-
- for (int j = 0; j < toCombine.length; j++) {
- result[i][j] = toCombine[j][position[j]];
- }
-
- // iterate
- if (i + 1 < count) {
- for (int j = 0; j < toCombine.length; j++) {
- position[j] += 1;
- if (position[j] < toCombine[j].length) {
- break;
- } else {
- position[j] = 0;
- }
- }
- }
- }
-
- return result;
- }
-
- private List<? extends Object> getUseParameter(Class<?> parameterType, Use use) {
- if (parameterType == int.class || parameterType == Integer.class) {
- return Arrays.asList(ArrayUtils.toObject(use.ints()));
- }
-
- // tries satisfy parameter from fields
- List<Object> result = new LinkedList<Object>();
- for (int i = 0; i < use.value().length; i++) {
- boolean satisfied = false;
- for (Field field : this.getClass().getDeclaredFields()) {
- String name = use.value()[i];
- name = StringUtils.replace(name, "*", ".+");
- name = StringUtils.replace(name, "?", ".");
- Pattern pattern = Pattern.compile(name);
- if (pattern.matcher(field.getName()).matches()) {
- if (parameterType.isAssignableFrom(field.getType())) {
- try {
- result.add(field.get(this));
- satisfied = true;
- } catch (Exception e) {
- throw new IllegalStateException("the field cannot be obtained");
- }
- }
- }
- }
- if (satisfied) {
- continue;
- }
- throw new IllegalStateException("cannot find the field satysfying injection point");
- }
- return result;
- }
-
@Test
public void testNumberedPages() {
dataScroller.setFastStep(FAST_STEP);
14 years, 5 months