JBoss Rich Faces SVN: r17724 - root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-07-05 14:38:30 -0400 (Mon, 05 Jul 2010)
New Revision: 17724
Modified:
root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
Log:
apply checkstyle fixes
Modified: root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-07-05 18:23:38 UTC (rev 17723)
+++ root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-07-05 18:38:30 UTC (rev 17724)
@@ -56,6 +56,12 @@
private static final Set<ClientBehaviorHint> HINTS = Collections.unmodifiableSet(EnumSet
.of(ClientBehaviorHint.SUBMITTING));
+ private static final Set<String> ALL_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.ALL);
+ private static final Set<String> FORM_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.FORM);
+ private static final Set<String> THIS_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.THIS);
+ private static final Set<String> REGION_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.REGION);
+ private static final Set<String> NONE_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.NONE);
+
enum PropertyKeys {
data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId, render,
status, disabled, limitRender, immediate, bypassUpdates
@@ -65,12 +71,6 @@
private Set<String> render;
- private static final Set<String> ALL_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.ALL);
- private static final Set<String> FORM_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.FORM);
- private static final Set<String> THIS_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.THIS);
- private static final Set<String> REGION_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.REGION);
- private static final Set<String> NONE_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.NONE);
-
@Override
public void setLiteralAttribute(String name, Object value) {
if (compare(PropertyKeys.data, name)) {
14 years, 6 months
JBoss Rich Faces SVN: r17723 - root/core/trunk/impl/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-07-05 14:23:38 -0400 (Mon, 05 Jul 2010)
New Revision: 17723
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
Log:
fix division by zero
Modified: root/core/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-07-05 17:06:08 UTC (rev 17722)
+++ root/core/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-07-05 18:23:38 UTC (rev 17723)
@@ -274,7 +274,15 @@
}
public int getRelativeRowIndex() {
- return (getRowIndex() % getRows());
+ int rows = getRows();
+ if(rows == 0) {
+ rows = getRowCount();
+ }
+
+ int rowIndex = getRowIndex();
+ rows = (rows == 0) ? rowIndex : (rowIndex % rows);
+
+ return (rows);
}
public String getRelativeClientId(FacesContext facesContext) {
14 years, 6 months
JBoss Rich Faces SVN: r17722 - in root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces: taglib and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-07-05 13:06:08 -0400 (Mon, 05 Jul 2010)
New Revision: 17722
Modified:
root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java
Log:
RF-8772
Modified: root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
===================================================================
--- root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-07-05 16:59:18 UTC (rev 17721)
+++ root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-07-05 17:06:08 UTC (rev 17722)
@@ -93,12 +93,12 @@
getStateHelper().put(PropertyKeys.fastStep, fastStep);
}
- public String getFor() {
+ public String getForComponent() {
return (String) getStateHelper().eval(PropertyKeys.forComponent);
}
- public void setFor(String f) {
- getStateHelper().put(PropertyKeys.forComponent, f);
+ public void setForComponent(String forComponent) {
+ getStateHelper().put(PropertyKeys.forComponent, forComponent);
}
public int getMaxPages() {
@@ -183,7 +183,7 @@
*/
public UIComponent getDataTable() {
- String forAttribute = (String) getStateHelper().get(PropertyKeys.forComponent);
+ String forAttribute = (String) getAttributes().get(PropertyKeys.forComponent.toString());
UIComponent forComp;
if (forAttribute == null) {
Modified: root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java
===================================================================
--- root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java 2010-07-05 16:59:18 UTC (rev 17721)
+++ root/ui/iteration/trunk/datascroller/ui/src/main/java/org/richfaces/taglib/DatascrollerTagHandler.java 2010-07-05 17:06:08 UTC (rev 17722)
@@ -116,6 +116,7 @@
MetaRuleset ruleset = super.createMetaRuleset(type);
ruleset.addRule(PAGERULE);
ruleset.addRule(SCROLL_LISTENER_RULE);
+ ruleset.alias("for", "forComponent");
return ruleset;
}
}
14 years, 6 months
JBoss Rich Faces SVN: r17721 - in root/examples-sandbox/trunk/components: combobox-demo and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 12:59:18 -0400 (Mon, 05 Jul 2010)
New Revision: 17721
Added:
root/examples-sandbox/trunk/components/combobox-demo/
root/examples-sandbox/trunk/components/combobox-demo/pom.xml
root/examples-sandbox/trunk/components/combobox-demo/src/main/java/
Removed:
root/examples-sandbox/trunk/components/autocomplete-demo/
Modified:
root/examples-sandbox/trunk/components/combobox-demo/src/main/webapp/WEB-INF/faces-config.xml
root/examples-sandbox/trunk/components/pom.xml
Log:
Renamed autocomplete-demo module into combobox
Copied: root/examples-sandbox/trunk/components/combobox-demo (from rev 17715, root/examples-sandbox/trunk/components/autocomplete-demo)
Added: root/examples-sandbox/trunk/components/combobox-demo/pom.xml
===================================================================
--- root/examples-sandbox/trunk/components/combobox-demo/pom.xml (rev 0)
+++ root/examples-sandbox/trunk/components/combobox-demo/pom.xml 2010-07-05 16:59:18 UTC (rev 17721)
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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>
+
+ <parent>
+ <groupId>org.richfaces</groupId>
+ <artifactId>richfaces-parent</artifactId>
+ <version>7</version>
+ </parent>
+
+ <groupId>org.richfaces.examples-sandbox</groupId>
+ <artifactId>combobox-demo</artifactId>
+ <packaging>war</packaging>
+ <version>4.0.0-SNAPSHOT</version>
+ <name>RichFaces Examples: ComboBox</name>
+
+ <properties>
+ <snapshotRepository>dav:https://repository.jboss.org/nexus/content/repositories/snapshots/</snapshotRepository>
+ <jetty.port>8080</jetty.port>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <richfaces.checkstyle.version>1</richfaces.checkstyle.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-bom</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.richfaces.ui.inputs-sandbox</groupId>
+ <artifactId>combobox</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- TODO: this should be inherited from richfaces-ui-iteration-ui -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <!-- API implementation for runtime -->
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
+ <!-- JSF -->
+ <dependency>
+ <groupId>${jsf2.api.groupid}</groupId>
+ <artifactId>${jsf2.api.artifactid}</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${jsf2.impl.groupid}</groupId>
+ <artifactId>${jsf2.impl.artifactid}</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <!-- Configure checkstyle report for this module -->
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.richfaces</groupId>
+ <artifactId>richfaces-build-checkstyle
+ </artifactId>
+ <version>${richfaces.checkstyle.version}
+ </version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-beta-1</version>
+ <configuration>
+ <fail>false</fail>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.18</version>
+ <configuration>
+ <scanIntervalSeconds>10</scanIntervalSeconds>
+ <connectors>
+ <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+ <port>${jetty.port}</port>
+ <maxIdleTime>60000</maxIdleTime>
+ </connector>
+ </connectors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>jee6</id>
+ <dependencies>
+ <dependency>
+ <groupId>${jsf2.api.groupid}</groupId>
+ <artifactId>${jsf2.api.artifactid}</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${jsf2.impl.groupid}</groupId>
+ <artifactId>${jsf2.impl.artifactid}</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <repositories>
+ <repository>
+ <id>maven-repository2.dev.java.net</id>
+ <name>Java.net Repository for Maven 2</name>
+ <url>http://download.java.net/maven/2</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+</project>
\ No newline at end of file
Modified: root/examples-sandbox/trunk/components/combobox-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- root/examples-sandbox/trunk/components/autocomplete-demo/src/main/webapp/WEB-INF/faces-config.xml 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/examples-sandbox/trunk/components/combobox-demo/src/main/webapp/WEB-INF/faces-config.xml 2010-07-05 16:59:18 UTC (rev 17721)
@@ -4,5 +4,4 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
-<managed-bean>
-</faces-config>
+</faces-config>
\ No newline at end of file
Modified: root/examples-sandbox/trunk/components/pom.xml
===================================================================
--- root/examples-sandbox/trunk/components/pom.xml 2010-07-05 16:52:13 UTC (rev 17720)
+++ root/examples-sandbox/trunk/components/pom.xml 2010-07-05 16:59:18 UTC (rev 17721)
@@ -16,7 +16,7 @@
<name>Richfaces Examples Sandbox: Component Demos Aggregator</name>
<modules>
- <module>autocomplete-demo</module>
+ <module>combobox-demo</module>
</modules>
<dependencies>
14 years, 6 months
JBoss Rich Faces SVN: r17720 - in root/ui-sandbox/inputs/trunk: combobox and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 12:52:13 -0400 (Mon, 05 Jul 2010)
New Revision: 17720
Added:
root/ui-sandbox/inputs/trunk/combobox/
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AutocompleteLayout.java
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/package-info.java
Removed:
root/ui-sandbox/inputs/trunk/autocomplete/
Modified:
root/ui-sandbox/inputs/trunk/combobox/pom.xml
root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java
root/ui-sandbox/inputs/trunk/pom.xml
Log:
Renamed autocomplete module into combobox
Copied: root/ui-sandbox/inputs/trunk/combobox (from rev 17715, root/ui-sandbox/inputs/trunk/autocomplete)
Modified: root/ui-sandbox/inputs/trunk/combobox/pom.xml
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/pom.xml 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/ui-sandbox/inputs/trunk/combobox/pom.xml 2010-07-05 16:52:13 UTC (rev 17720)
@@ -28,8 +28,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces.ui.inputs-sandbox</groupId>
- <artifactId>autocomplete</artifactId>
- <name>Richfaces UI Sandbox Components: Autocomplete Input Component</name>
+ <artifactId>combobox</artifactId>
+ <name>Richfaces UI Sandbox Components: ComboBox Input Component</name>
<packaging>jar</packaging>
<build>
@@ -124,8 +124,8 @@
</dependencies>
<scm>
- <connection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui-sandbox/inputs/trun...</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui-sandbox/inputs/trun...</developerConnection>
+ <connection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui-sandbox/inputs/trun...</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui-sandbox/inputs/trun...</developerConnection>
<url>http://fisheye.jboss.org/browse/richfaces</url>
</scm>
</project>
\ No newline at end of file
Added: root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AutocompleteLayout.java
===================================================================
--- root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AutocompleteLayout.java (rev 0)
+++ root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/AutocompleteLayout.java 2010-07-05 16:52:13 UTC (rev 17720)
@@ -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.component;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO nick - move to API
+public enum AutocompleteLayout {
+
+ table,
+ list,
+ grid,
+ //TODO nick - rename into 'simple'?
+ div
+}
Added: root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/package-info.java
===================================================================
--- root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/package-info.java (rev 0)
+++ root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/component/package-info.java 2010-07-05 16:52:13 UTC (rev 17720)
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+/**
+ * Implementation of RichFaces data lists
+ */
+(a)org.richfaces.cdk.annotations.TagLibrary(uri="http://richfaces.org/combobox", shortName="comboBox")
+package org.richfaces.component;
Modified: root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/ui-sandbox/inputs/trunk/combobox/src/main/java/org/richfaces/renderkit/AutocompleteRenderer.java 2010-07-05 16:52:13 UTC (rev 17720)
@@ -0,0 +1,5 @@
+package org.richfaces.renderkit;
+
+class AutocompleteRenderer {
+
+}
\ No newline at end of file
Modified: root/ui-sandbox/inputs/trunk/pom.xml
===================================================================
--- root/ui-sandbox/inputs/trunk/pom.xml 2010-07-05 15:41:15 UTC (rev 17719)
+++ root/ui-sandbox/inputs/trunk/pom.xml 2010-07-05 16:52:13 UTC (rev 17720)
@@ -36,7 +36,7 @@
<modules>
<module>parent</module>
- <module>autocomplete</module>
+ <module>combobox</module>
</modules>
<scm>
14 years, 6 months
JBoss Rich Faces SVN: r17719 - in root/core/trunk: impl/src/main/java/org/richfaces/resource and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 11:41:15 -0400 (Mon, 05 Jul 2010)
New Revision: 17719
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
Log:
ResourceCodec interface moved to API
Copied: root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java (from rev 17716, root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java)
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05 15:41:15 UTC (rev 17719)
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package org.richfaces.resource;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public interface ResourceCodec {
+
+ public String encodeResourceRequestPath(FacesContext context, String resourceName, Object resourceData, String resourceVersion);
+
+ public String encodeJSFMapping(FacesContext context, String resourcePath);
+
+ public String decodeResourceName(FacesContext context, String requestPath);
+
+ public Object decodeResourceData(FacesContext context, String requestPath);
+
+ public String decodeResourceVersion(FacesContext context, String requestPath);
+
+ public String getResourceKey(FacesContext context, String requestPath);
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05 15:10:53 UTC (rev 17718)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05 15:41:15 UTC (rev 17719)
@@ -1,25 +0,0 @@
-/**
- *
- */
-package org.richfaces.resource;
-
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-public interface ResourceCodec {
-
- public String encodeResourceRequestPath(FacesContext context, String resourceName, Object resourceData, String resourceVersion);
-
- public String encodeJSFMapping(FacesContext context, String resourcePath);
-
- public String decodeResourceName(FacesContext context, String requestPath);
-
- public Object decodeResourceData(FacesContext context, String requestPath);
-
- public String decodeResourceVersion(FacesContext context, String requestPath);
-
- public String getResourceKey(FacesContext context, String requestPath);
-}
14 years, 6 months
JBoss Rich Faces SVN: r17718 - in root/ui/core/trunk/ui/src: test/java/org/richfaces/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 11:10:53 -0400 (Mon, 05 Jul 2010)
New Revision: 17718
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java
root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java
Log:
https://jira.jboss.org/browse/RF-8752
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java 2010-07-05 13:35:42 UTC (rev 17717)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractAttachQueue.java 2010-07-05 15:10:53 UTC (rev 17718)
@@ -81,8 +81,12 @@
public abstract String getOnrequestdequeue();
@Attribute
- public abstract String getQueueId();
+ public abstract String getName();
+ public String getQueueId() {
+ return getName();
+ }
+
@Override
public String getFamily() {
return COMPONENT_FAMILY;
Modified: root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java
===================================================================
--- root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-07-05 13:35:42 UTC (rev 17717)
+++ root/ui/core/trunk/ui/src/test/java/org/richfaces/component/QueueRendererTest.java 2010-07-05 15:10:53 UTC (rev 17718)
@@ -61,7 +61,7 @@
"'form': {'requestDelay': 400}," +
"'form:firstAttach': {'timeout': 300, 'requestGroupingId': 'request'}," +
"'second': {'requestDelay': 400, 'timeout': 100, 'ignoreDupResponses': true}," +
- "'form:linkAttach': {'timeout': 500}," +
+ "'form:linkAttach': {'timeout': 500, 'queueId': 'second'}," +
"'form:secondAttach': {}" +
"});";
14 years, 6 months
JBoss Rich Faces SVN: r17717 - in root/ui/core/trunk/ui/src/main: java/org/richfaces/resource and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 09:35:42 -0400 (Mon, 05 Jul 2010)
New Revision: 17717
Removed:
root/ui/core/trunk/ui/src/main/resources/META-INF/org.richfaces.resource.MediaOutputResource.resource.properties
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java
Log:
Resources fwk refactoring
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-07-05 12:55:55 UTC (rev 17716)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-07-05 13:35:42 UTC (rev 17717)
@@ -23,6 +23,16 @@
package org.richfaces.component;
+import java.io.OutputStream;
+import java.util.Date;
+
+import javax.el.MethodExpression;
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+
import org.ajax4jsf.resource.ResourceComponent2;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
@@ -31,18 +41,10 @@
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.resource.MediaOutputResource;
+import org.richfaces.resource.UserResourceWrapper;
import org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor;
import org.richfaces.webapp.taglib.MethodExpressionMethodBindingAdaptor;
-import javax.el.MethodExpression;
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.faces.component.UIOutput;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import java.util.Date;
-import java.io.OutputStream;
-
/**
* @author shura
*
@@ -120,11 +122,11 @@
public Resource getResource() {
FacesContext facesContext = getFacesContext();
ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler();
- MediaOutputResource resource =
- (MediaOutputResource) resourceHandler.createResource(MediaOutputResource.class.getName());
+ Resource resource = resourceHandler.createResource(MediaOutputResource.class.getName());
+
+ MediaOutputResource mediaResource = (MediaOutputResource) ((UserResourceWrapper) resource).getWrapped();
+ mediaResource.initialize(this);
- resource.initialize(this);
-
return resource;
}
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-07-05 12:55:55 UTC (rev 17716)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-07-05 13:35:42 UTC (rev 17717)
@@ -27,6 +27,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
@@ -40,7 +42,13 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class MediaOutputResource extends AbstractCacheableResource implements StateHolder {
+@DynamicResource
+public class MediaOutputResource implements StateHolder, UserResource, CacheableResource {
+
+ private String contentType;
+
+ private boolean cacheable;
+
private MethodExpression contentProducer;
private ValueExpression expiresExpression;
@@ -54,7 +62,6 @@
private ValueExpression timeToLiveExpression;
private Object userData;
- @Override
public InputStream getInputStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -107,4 +114,44 @@
this.expiresExpression = uiMediaOutput.getValueExpression("expires");
this.timeToLiveExpression = uiMediaOutput.getValueExpression("timeToLive");
}
+
+ public boolean isCacheable(FacesContext context) {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public Date getExpires(FacesContext context) {
+ return null;
+ }
+
+ public int getTimeToLive(FacesContext context) {
+ return -1;
+ }
+
+ public String getEntityTag(FacesContext context) {
+ return null;
+ }
+
+ public Map<String, String> getResponseHeaders() {
+ return null;
+ }
+
+ public Date getLastModified() {
+ return null;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public int getContentLength() {
+ return -1;
+ }
}
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-07-05 12:55:55 UTC (rev 17716)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-07-05 13:35:42 UTC (rev 17717)
@@ -23,11 +23,15 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
import java.util.Map;
+import javax.faces.application.Resource;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.component.PushEventTracker;
import org.richfaces.component.PushListenersManager;
@@ -37,16 +41,19 @@
*/
//TODO make this a singleton
-public class PushResource extends AbstractBaseResource {
+@DynamicResource
+public class PushResource extends Resource {
- @Override
+ public PushResource() {
+ setResourceName(getClass().getName());
+ }
+
public InputStream getInputStream() throws IOException {
return null;
}
- @Override
public Map<String, String> getResponseHeaders() {
- Map<String, String> headers = super.getResponseHeaders();
+ Map<String, String> headers = new HashMap<String, String>();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
String pushId = externalContext.getRequestParameterMap().get("id");
@@ -64,4 +71,27 @@
return headers;
}
+
+ public String getContentType() {
+ return null;
+ }
+
+ @Override
+ public String getRequestPath() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ResourceCodec resourceCodec = ServiceTracker.getService(ResourceCodec.class);
+
+ String requestPath = resourceCodec.encodeResourceRequestPath(facesContext, getResourceName(), null, null);
+ return resourceCodec.encodeJSFMapping(facesContext, requestPath);
+ }
+
+ @Override
+ public URL getURL() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean userAgentNeedsUpdate(FacesContext context) {
+ return true;
+ }
}
Deleted: root/ui/core/trunk/ui/src/main/resources/META-INF/org.richfaces.resource.MediaOutputResource.resource.properties
===================================================================
14 years, 6 months
JBoss Rich Faces SVN: r17716 - in root/core/trunk: impl/src/main/java/org/ajax4jsf/context and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-05 08:55:55 -0400 (Mon, 05 Jul 2010)
New Revision: 17716
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
Log:
Resources fwk refactoring
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import javax.faces.FacesWrapper;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface Java2DUserResourceWrapper extends FacesWrapper<Java2DUserResource> {
+
+ public Java2DUserResource getWrapped();
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import javax.faces.FacesWrapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface UserResourceWrapper extends FacesWrapper<UserResource> {
+
+ public UserResource getWrapped();
+
+}
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -21,8 +21,6 @@
package org.ajax4jsf.context;
-import java.util.concurrent.ConcurrentMap;
-
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.FacesException;
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -158,9 +158,9 @@
String resourceName = getResourceName();
Object resourceData = Util.saveResourceState(context, this);
String resourceVersion = getResourceVersion();
- String resourceUri = resourceCodec.encodeResource(context, resourceName, resourceData, resourceVersion);
+ String resourceUri = resourceCodec.encodeResourceRequestPath(context, resourceName, resourceData, resourceVersion);
- resourceUri = Util.encodeResourceURL(context, resourceUri);
+ resourceUri = Util.encodeJSFURL(context, resourceUri);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Request path for {0} resource is: {1}", String.valueOf(resourceName),
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -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.resource;
+
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.FacesWrapper;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.util.Util;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class BaseResourceWrapper<T> extends AbstractCacheableResource implements VersionedResource, StateHolder,
+ FacesWrapper<T> {
+
+ private T resourceObject;
+
+ public BaseResourceWrapper(T resourceObject) {
+ super();
+ this.resourceObject = resourceObject;
+ }
+
+ protected abstract Map<String, String> getWrappedResourceResponseHeaders();
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ Map<String, String> headers = super.getResponseHeaders();
+
+ Map<String, String> userHeaders = getWrappedResourceResponseHeaders();
+ if (userHeaders != null) {
+ headers.putAll(userHeaders);
+ }
+
+ return headers;
+ }
+
+ public String getVersion() {
+ if (resourceObject instanceof VersionedResource) {
+ return ((VersionedResource) resourceObject).getVersion();
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isCacheable(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).isCacheable(context);
+ }
+
+ return false;
+ }
+
+ @Override
+ public Date getExpires(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getExpires(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getEntityTag(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getEntityTag(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public int getTimeToLive(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getTimeToLive(context);
+ }
+
+ return 0;
+ }
+
+ public boolean isTransient() {
+ if (resourceObject instanceof StateHolderResource) {
+ return ((StateHolderResource) resourceObject).isTransient();
+ }
+
+ if (resourceObject instanceof StateHolder) {
+ return ((StateHolder) resourceObject).isTransient();
+ }
+
+ return true;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ if (resourceObject instanceof StateHolder) {
+ ((StateHolder) resourceObject).setTransient(newTransientValue);
+ }
+ }
+
+ public Object saveState(FacesContext context) {
+ return Util.saveResourceState(context, resourceObject);
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Util.restoreResourceState(context, resourceObject, state);
+ }
+
+ public T getWrapped() {
+ return resourceObject;
+ }
+
+}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -94,7 +94,7 @@
return sb.toString();
}
- public String encodeResource(FacesContext context, String resourceName, Object resourceData, String resourceVersion) {
+ public String encodeResourceRequestPath(FacesContext context, String resourceName, Object resourceData, String resourceVersion) {
String encodedDataString = null;
boolean isBytesArray = false;
if (resourceData != null) {
@@ -110,6 +110,10 @@
+ encodeResource(context, resourceName, encodedDataString, isBytesArray, resourceVersion);
}
+ public String encodeJSFMapping(FacesContext context, String resourcePath) {
+ return Util.encodeJSFURL(context, resourcePath);
+ }
+
public String getResourceKey(FacesContext context, String requestPath) {
Map<String, String> paramMap = context.getExternalContext().getRequestParameterMap();
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -1,163 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.resource;
-
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-import javax.imageio.ImageIO;
-
-import org.ajax4jsf.util.HtmlColor;
-import org.ajax4jsf.util.HtmlDimensions;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class Java2DUserResourceAdaptor implements UserResource {
-
- private Java2DUserResource j2DUserResource;
-
- public Java2DUserResourceAdaptor(Java2DUserResource userResource) {
- this.j2DUserResource = userResource;
- }
-
- public InputStream getInputStream() throws IOException {
- Dimension dimension = j2DUserResource.getDimension();
- int width = dimension.width;
- int height = dimension.height;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- ImageType imageType = j2DUserResource.getImageType();
-
- if ((width > 0) && (height > 0)) {
- BufferedImage image = imageType.createImage(width, height);
- Graphics2D g2d = image.createGraphics();
-
- try {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
-
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
-
- j2DUserResource.paint(g2d, dimension);
- } finally {
- g2d.dispose();
- }
-
- try {
- ImageIO.write(image, imageType.getFormatName(), baos);
- } finally {
- try {
- baos.close();
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- return new ByteArrayInputStream(baos.toByteArray());
- }
-
- public String getContentType() {
- return j2DUserResource.getImageType().getMimeType();
- }
-
- protected String getValueParameter(FacesContext context, String name) {
- SkinFactory skinFactory = SkinFactory.getInstance();
-
- Skin skin = skinFactory.getSkin(context);
- String value = (String) skin.getParameter(context, name);
-
- if (value == null || value.length() == 0) {
- skin = skinFactory.getDefaultSkin(context);
- value = (String) skin.getParameter(context, name);
- }
-
- return value;
- }
-
- protected Integer getColorValueParameter(FacesContext context, String name, boolean useDefault) {
- Skin skin;
- if (useDefault) {
- skin = SkinFactory.getInstance().getDefaultSkin(context);
- } else {
- skin = SkinFactory.getInstance().getSkin(context);
- }
-
- return decodeColor((String) skin.getParameter(context, name));
- }
-
- protected Integer getHeight(FacesContext context, String heightParamName) {
- SkinFactory skinFactory = SkinFactory.getInstance();
- Skin skin = skinFactory.getSkin(context);
-
- String height = (String) skin.getParameter(context, heightParamName);
- if (height == null || height.length() == 0) {
- skin = skinFactory.getDefaultSkin(context);
- height = (String) skin.getParameter(context, heightParamName);
- }
-
- if (height != null && height.length() != 0) {
- return Integer.valueOf(HtmlDimensions.decode(height).intValue());
- } else {
- return Integer.valueOf(16);
- }
- }
-
- protected Integer decodeColor(String value) {
- if (value != null && value.length() != 0) {
- return Integer.valueOf(HtmlColor.decode(value).getRGB());
- } else {
- return null;
- }
- }
-
- public int getContentLength() {
- return -1;
- }
-
- public Date getLastModified() {
- return j2DUserResource.getLastModified();
- }
-
- public Map<String, String> getResponseHeaders() {
- return j2DUserResource.getResponseHeaders();
- }
-
-}
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.imageio.ImageIO;
+
+import org.ajax4jsf.util.HtmlColor;
+import org.ajax4jsf.util.HtmlDimensions;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class Java2DUserResourceWrapperImpl extends BaseResourceWrapper<Java2DUserResource>
+ implements Java2DUserResourceWrapper {
+
+ public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject) {
+ super(resourceObject);
+ }
+
+ public InputStream getInputStream() throws IOException {
+ Java2DUserResource j2DUserResource = getWrapped();
+ Dimension dimension = j2DUserResource.getDimension();
+ int width = dimension.width;
+ int height = dimension.height;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ ImageType imageType = j2DUserResource.getImageType();
+
+ if ((width > 0) && (height > 0)) {
+ BufferedImage image = imageType.createImage(width, height);
+ Graphics2D g2d = image.createGraphics();
+
+ try {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
+
+ g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
+ RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+
+ j2DUserResource.paint(g2d, dimension);
+ } finally {
+ g2d.dispose();
+ }
+
+ try {
+ ImageIO.write(image, imageType.getFormatName(), baos);
+ } finally {
+ try {
+ baos.close();
+ } catch (IOException e) {
+
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ public String getContentType() {
+ return getWrapped().getImageType().getMimeType();
+ }
+
+ protected String getValueParameter(FacesContext context, String name) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
+
+ Skin skin = skinFactory.getSkin(context);
+ String value = (String) skin.getParameter(context, name);
+
+ if (value == null || value.length() == 0) {
+ skin = skinFactory.getDefaultSkin(context);
+ value = (String) skin.getParameter(context, name);
+ }
+
+ return value;
+ }
+
+ protected Integer getColorValueParameter(FacesContext context, String name, boolean useDefault) {
+ Skin skin;
+ if (useDefault) {
+ skin = SkinFactory.getInstance().getDefaultSkin(context);
+ } else {
+ skin = SkinFactory.getInstance().getSkin(context);
+ }
+
+ return decodeColor((String) skin.getParameter(context, name));
+ }
+
+ protected Integer getHeight(FacesContext context, String heightParamName) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
+ Skin skin = skinFactory.getSkin(context);
+
+ String height = (String) skin.getParameter(context, heightParamName);
+ if (height == null || height.length() == 0) {
+ skin = skinFactory.getDefaultSkin(context);
+ height = (String) skin.getParameter(context, heightParamName);
+ }
+
+ if (height != null && height.length() != 0) {
+ return Integer.valueOf(HtmlDimensions.decode(height).intValue());
+ } else {
+ return Integer.valueOf(16);
+ }
+ }
+
+ protected Integer decodeColor(String value) {
+ if (value != null && value.length() != 0) {
+ return Integer.valueOf(HtmlColor.decode(value).getRGB());
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected Map<String, String> getWrappedResourceResponseHeaders() {
+ return getWrapped().getResponseHeaders();
+ }
+
+ @Override
+ protected Date getLastModified(FacesContext context) {
+ return getWrapped().getLastModified();
+ }
+}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -39,11 +39,15 @@
return Util.legacyDecodeResourceVersion(requestPath);
}
- public String encodeResource(FacesContext context, String resourceName, Object resourceData, String resourceVersion) {
+ public String encodeResourceRequestPath(FacesContext context, String resourceName, Object resourceData, String resourceVersion) {
return ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
+ Util.legacyEncodeResourceData(resourceName, resourceData, resourceVersion);
}
+ public String encodeJSFMapping(FacesContext context, String resourcePath) {
+ return Util.encodeJSFURL(context, resourcePath);
+ }
+
public String getResourceKey(FacesContext context, String requestPath) {
return requestPath;
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -11,8 +11,10 @@
*/
public interface ResourceCodec {
- public String encodeResource(FacesContext context, String resourceName, Object resourceData, String resourceVersion);
-
+ public String encodeResourceRequestPath(FacesContext context, String resourceName, Object resourceData, String resourceVersion);
+
+ public String encodeJSFMapping(FacesContext context, String resourcePath);
+
public String decodeResourceName(FacesContext context, String requestPath);
public Object decodeResourceData(FacesContext context, String requestPath);
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -44,8 +44,8 @@
import org.ajax4jsf.cache.Cache;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
import org.richfaces.util.Util;
-import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
import org.slf4j.Logger;
/**
@@ -415,11 +415,11 @@
if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
Java2DUserResource java2DUserResource = (Java2DUserResource) loadedClass.newInstance();
wrappedResource = java2DUserResource;
- resource = new UserResourceAdaptor(new Java2DUserResourceAdaptor(java2DUserResource), java2DUserResource);
+ resource = new Java2DUserResourceWrapperImpl(java2DUserResource);
} else if (UserResource.class.isAssignableFrom(loadedClass)) {
UserResource userResource = (UserResource) loadedClass.newInstance();
wrappedResource = userResource;
- resource = new UserResourceAdaptor(userResource, userResource);
+ resource = new UserResourceWrapperImpl(userResource);
} else {
Class<? extends Resource> resourceClass = loadedClass.asSubclass(Resource.class);
resource = (Resource) resourceClass.newInstance();
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -1,152 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Map;
-
-import javax.faces.component.StateHolder;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.util.Util;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class UserResourceAdaptor extends AbstractCacheableResource implements VersionedResource, StateHolder {
-
- private UserResource userResource;
-
- private Object wrappedResource;
-
- public UserResourceAdaptor(UserResource userResource, Object wrappedResource) {
- super();
- this.userResource = userResource;
- this.wrappedResource = wrappedResource;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- return userResource.getInputStream();
- }
-
- @Override
- public Map<String, String> getResponseHeaders() {
- Map<String, String> headers = super.getResponseHeaders();
-
- Map<String, String> userHeaders = userResource.getResponseHeaders();
- if (userHeaders != null) {
- headers.putAll(userHeaders);
- }
-
- return headers;
- }
-
- @Override
- public String getContentType() {
- return userResource.getContentType();
- }
-
- @Override
- protected int getContentLength(FacesContext context) {
- return userResource.getContentLength();
- }
-
- @Override
- protected Date getLastModified(FacesContext context) {
- return userResource.getLastModified();
- }
-
- public String getVersion() {
- if (wrappedResource instanceof VersionedResource) {
- return ((VersionedResource) wrappedResource).getVersion();
- }
-
- return null;
- }
-
- @Override
- public boolean isCacheable(FacesContext context) {
- if (wrappedResource instanceof CacheableResource) {
- return ((CacheableResource) wrappedResource).isCacheable(context);
- }
-
- return false;
- }
-
- @Override
- public Date getExpires(FacesContext context) {
- if (wrappedResource instanceof CacheableResource) {
- return ((CacheableResource) wrappedResource).getExpires(context);
- }
-
- return null;
- }
-
- @Override
- public String getEntityTag(FacesContext context) {
- if (wrappedResource instanceof CacheableResource) {
- return ((CacheableResource) wrappedResource).getEntityTag(context);
- }
-
- return null;
- }
-
- @Override
- public int getTimeToLive(FacesContext context) {
- if (wrappedResource instanceof CacheableResource) {
- return ((CacheableResource) wrappedResource).getTimeToLive(context);
- }
-
- return 0;
- }
-
- public boolean isTransient() {
- if (wrappedResource instanceof StateHolderResource) {
- return ((StateHolderResource) wrappedResource).isTransient();
- }
-
- if (wrappedResource instanceof StateHolder) {
- return ((StateHolder) wrappedResource).isTransient();
- }
-
- return true;
- }
-
- public void setTransient(boolean newTransientValue) {
- if (wrappedResource instanceof StateHolder) {
- ((StateHolder) wrappedResource).setTransient(newTransientValue);
- }
- }
-
- public Object saveState(FacesContext context) {
- return Util.saveResourceState(context, wrappedResource);
- }
-
- public void restoreState(FacesContext context, Object state) {
- Util.restoreResourceState(context, wrappedResource, state);
- }
-
-}
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class UserResourceWrapperImpl extends BaseResourceWrapper<UserResource> implements UserResourceWrapper {
+
+ public UserResourceWrapperImpl(UserResource resourceObject) {
+ super(resourceObject);
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return getWrapped().getInputStream();
+ }
+
+ @Override
+ protected Map<String, String> getWrappedResourceResponseHeaders() {
+ return getWrapped().getResponseHeaders();
+ }
+
+ @Override
+ public String getContentType() {
+ return getWrapped().getContentType();
+ }
+
+ @Override
+ protected int getContentLength(FacesContext context) {
+ return getWrapped().getContentLength();
+ }
+
+ @Override
+ protected Date getLastModified(FacesContext context) {
+ return getWrapped().getLastModified();
+ }
+
+}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -379,7 +379,7 @@
return data;
}
- public static String encodeResourceURL(FacesContext context, String url) {
+ public static String encodeJSFURL(FacesContext context, String url) {
String mapping = Util.getMappingForRequest(context);
String resourcePath = url;
Modified: root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-07-03 00:20:40 UTC (rev 17715)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-07-05 12:55:55 UTC (rev 17716)
@@ -41,9 +41,9 @@
import org.easymock.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
import org.richfaces.application.ServiceTracker;
-import org.richfaces.jsr330.Module;
import org.richfaces.jsr330.InjectorConfig;
import org.richfaces.jsr330.InjectorImpl;
+import org.richfaces.jsr330.Module;
import org.richfaces.util.Util;
/**
@@ -132,13 +132,13 @@
String resourceState = "data";
final ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+ EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
EasyMock.aryEq(resourceState.getBytes()), EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource0/4_0_alpha/data");
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+ EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
EasyMock.eq(null), EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource1/4_0_alpha");
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+ EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockResource"),
EasyMock.eq(null), EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource2/4_0_alpha");
EasyMock.replay(resourceCodec);
14 years, 6 months
JBoss Rich Faces SVN: r17715 - in root/cdk/branches/RF8755/plugins/generator/src: main/java/org/richfaces/cdk/templatecompiler/model and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-07-02 20:20:40 -0400 (Fri, 02 Jul 2010)
New Revision: 17715
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
Log:
tests and implementation for attributes.
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -98,33 +98,33 @@
*
*/
// TODO externalize
- static final String RENDER_KIT_UTILS_CLASS_NAME = "org.richfaces.renderkit.RenderKitUtils";
+ public static final String RENDER_KIT_UTILS_CLASS_NAME = "org.richfaces.renderkit.RenderKitUtils";
/**
*
*/
- static final String RESPONSE_WRITER_VARIABLE = "responseWriter";
+ public static final String RESPONSE_WRITER_VARIABLE = "responseWriter";
/**
*
*/
- static final String COMPONENT_VARIABLE = "component";
+ public static final String COMPONENT_VARIABLE = "component";
/**
*
*/
- static final String THIS_VARIABLE = "this";
+ public static final String THIS_VARIABLE = "this";
/**
*
*/
- static final String SUPER_VARIABLE = "super";
+ public static final String SUPER_VARIABLE = "super";
/**
*
*/
- static final String FACES_CONTEXT_VARIABLE = "facesContext";
+ public static final String FACES_CONTEXT_VARIABLE = "facesContext";
/**
*
*/
static final String CLIENT_ID_VARIABLE = "clientId";
- static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES = ImmutableMap.<String, Object> builder()
+ public static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES = ImmutableMap.<String, Object> builder()
.put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE)
.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
.put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
@@ -355,7 +355,7 @@
StartElementStatement startElementStatement = addStatement(StartElementStatement.class);
startElementStatement.setElementName(elementName.getLocalPart());
AttributesStatement attributesStatement = addStatement(AttributesStatement.class);
- attributesStatement.setAttributes(elementAttributes);
+ attributesStatement.processAttributes(anyElement,attributes);
// Set<String> writtenAttributes = new HashSet<String>();
// boolean shouldEncodePassThrough = false;
// String[] passThroughExclusions = null;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/AnyElement.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -22,10 +22,11 @@
*/
package org.richfaces.cdk.templatecompiler.model;
-
+import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
import java.util.Map;
import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.namespace.QName;
import org.richfaces.cdk.CdkException;
@@ -40,8 +41,10 @@
public class AnyElement extends ModelFragment {
private QName name;
+ private String passThrough;
+ private String passThroughWithExclusions;
- private Map<QName, Object> attributes = Maps.newHashMap();
+ private Map<QName, Object> attributes = Maps.newTreeMap(QNAME_COMPARATOR);
/**
* <p class="changed_added_4_0"></p>
@@ -63,6 +66,40 @@
/**
* <p class="changed_added_4_0"></p>
+ * @return the passThrough
+ */
+ @XmlAttribute(namespace=Template.CDK_NAMESPACE)
+ public String getPassThrough() {
+ return this.passThrough;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param passThrough the passThrough to set
+ */
+ public void setPassThrough(String passThrough) {
+ this.passThrough = passThrough;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the passThroughWithExclusions
+ */
+ @XmlAttribute(namespace=Template.CDK_NAMESPACE)
+ public String getPassThroughWithExclusions() {
+ return this.passThroughWithExclusions;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param passThroughWithExclusions the passThroughWithExclusions to set
+ */
+ public void setPassThroughWithExclusions(String passThroughWithExclusions) {
+ this.passThroughWithExclusions = passThroughWithExclusions;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
*
* @return the attributes
*/
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -25,12 +25,15 @@
import java.io.Serializable;
+import javax.xml.XMLConstants;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.namespace.QName;
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
*/
@XmlRootElement(name = "root", namespace = Template.CDK_NAMESPACE)
@@ -40,12 +43,14 @@
public static final String CDK_NAMESPACE = "http://richfaces.org/cdk/core";
+ public static final String CDK_PASS_THROUGH_NAMESPACE = "http://richfaces.org/cdk/passThrough";
+
public static final String COMPOSITE_NAMESPACE = "http://richfaces.org/cdk/jsf/composite";
public static final String XHTML_EL_NAMESPACE = "http://richfaces.org/cdk/xhtml-el";
public static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
-
+
private static final long serialVersionUID = -6900382133123748812L;
private String templatePath;
@@ -63,8 +68,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the interface
*/
@XmlElement(name = "interface", namespace = COMPOSITE_NAMESPACE)
@@ -73,17 +79,20 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
- * @param interface1 the interface to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param interface1
+ * the interface to set
*/
public void setInterface(CompositeInterface interface1) {
this.compositeInterface = interface1;
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the implementation
*/
@XmlElement(name = "implementation", namespace = COMPOSITE_NAMESPACE)
@@ -92,12 +101,22 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
- * @param implementation the implementation to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param implementation
+ * the implementation to set
*/
public void setImplementation(CompositeImplementation implementation) {
this.compositeImplementation = implementation;
}
+ public static boolean isDefaultNamespace(QName name) {
+ return isDefaultNamespace(name.getNamespaceURI());
+ }
+
+ public static boolean isDefaultNamespace(String namespace) {
+ return XMLConstants.NULL_NS_URI.equals(namespace) || XHTML_EL_NAMESPACE.equals(namespace)
+ || XHTML_NAMESPACE.equals(namespace);
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -1,35 +1,222 @@
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collection;
import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.regex.Pattern;
import javax.xml.namespace.QName;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.attributes.Attribute;
+import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
+import org.richfaces.cdk.attributes.Attribute.Kind;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.RendererClassVisitor;
+import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.Template;
+import org.richfaces.cdk.util.Pair;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Provider;
+import com.google.inject.internal.Sets;
import com.google.inject.name.Named;
public class AttributesStatement extends StatementsContainer {
+ private static final Splitter PASS_THGOUGH_SPLITTER = Splitter.on(Pattern.compile("\\s*,\\s*"));
+
private final Schema attributesSchema;
private final Provider<WriteAttributeStatement> statementProvider;
private final Provider<WriteAttributesSetStatement> passThroughStatementProvider;
- private final ELParser parser;
+ private final Logger logger;
+ private QName elementName;
@Inject
public AttributesStatement((a)Named(Template.XHTML_EL_NAMESPACE) Schema attributesSchema,
Provider<WriteAttributeStatement> attributeStatementProvider,
- Provider<WriteAttributesSetStatement> passThroughStatementProvider, ELParser parser) {
+ Provider<WriteAttributesSetStatement> passThroughStatementProvider, Logger logger) {
this.attributesSchema = attributesSchema;
this.statementProvider = attributeStatementProvider;
this.passThroughStatementProvider = passThroughStatementProvider;
- this.parser = parser;
+ this.logger = logger;
}
- public void setAttributes(Map<QName, Object> attributes) {
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param attributes
+ * @param componentAttributes
+ */
+ public void processAttributes(AnyElement element, Collection<PropertyBase> componentAttributes) {
+ Set<String> processedAttributes = Sets.newHashSet();
+ Map<String, String> passThroughAttributes = Maps.newTreeMap();
+ this.elementName = element.getName();
+ for (Map.Entry<QName, Object> entry : element.getAttributes().entrySet()) {
+ QName qName = entry.getKey();
+ if (Template.CDK_NAMESPACE.equals(qName.getNamespaceURI())) {
+ // TODO - CDK attributes should be assigned to AnyElement attribute, log error.
+ } else {
+ Object value = entry.getValue();
+ String localAttributeName = qName.getLocalPart();
+ if (Template.CDK_PASS_THROUGH_NAMESPACE.equals(qName.getNamespaceURI())) {
+ // TODO - check empty attribute value.
+ // pass through attribute in format <div pf:class="styleClass" />
+ passThroughAttributes.put(localAttributeName, value.toString());
+ processedAttributes.add(localAttributeName);
+ } else if (Template.isDefaultNamespace(qName.getNamespaceURI())) {
+ Attribute schemaAttribute = getSchemaAttribute(localAttributeName);
+ setupAttributeStatement(qName, value, schemaAttribute);
+ processedAttributes.add(localAttributeName);
+ } else {
+ setupAttributeStatement(qName, value, getGenericAttribute(localAttributeName));
+ }
+ }
+ }
+ String passThrough = element.getPassThrough();
+ if (null != passThrough) {
+ // cdk:passThrough="class:styleClass,style , id:clientId"
+ Iterable<String> split = PASS_THGOUGH_SPLITTER.split(passThrough);
+ for (String attribute : split) {
+ String[] split2 = attribute.split(":");
+ String attributeName = split2[0];
+ if (processedAttributes.add(attributeName)) {
+ Attribute schemaAttribute = getSchemaAttribute(attributeName);
+ String componentAttributeName =
+ split2.length > 1 ? split2[1] : schemaAttribute.getComponentAttributeName();
+ // WriteAttributeStatement writeAttributeStatement = createAttributeStatement();
+ // processPassThroughAttribute(componentAttributes, QName.valueOf(attributeName),
+ // writeAttributeStatement, componentAttributeName);
+ passThroughAttributes.put(attributeName, componentAttributeName);
+ }
+ }
+ }
+ String passThroughWithExclusions = element.getPassThroughWithExclusions();
+ if (null != passThroughWithExclusions) {
+ // cdk:passThroughWithExclusions="id,class,style"
+ Map<String, Element> elements = attributesSchema.getElements();
+ String elementLocalName = elementName.getLocalPart();
+ if (Template.isDefaultNamespace(elementName) && elements.containsKey(elementLocalName)) {
+ Element schemaElement = elements.get(elementLocalName);
+ Iterable<String> exclusions = PASS_THGOUGH_SPLITTER.split(passThroughWithExclusions);
+ Iterables.addAll(processedAttributes, exclusions);
+ for (Attribute schemaAttribute : schemaElement.getAttributes().values()) {
+ if(!processedAttributes.contains(schemaAttribute.getName())){
+ passThroughAttributes.put(schemaAttribute.getName(), schemaAttribute.getComponentAttributeName());
+ }
+ }
+ }
+ }
+ if(!passThroughAttributes.isEmpty()){
+ WriteAttributesSetStatement writeAttributesSetStatement = passThroughStatementProvider.get();
+ addStatement(writeAttributesSetStatement);
+ // TODO - setup passThrough statement
+ }
+ }
+ private void processPassThroughAttribute(Collection<PropertyBase> componentAttributes, QName qName,
+ String componentAttributeName) {
+ // Pass through attribute which value represents component attribute.
+ Attribute schemaAttribute = getSchemaAttribute(qName.getLocalPart());
+ // TODO -send statement directly ?
+ String expression =
+ "#{" + RendererClassVisitor.ENCODE_METHOD_VARIABLES.get("componentVariable") + ".getAttributes().get(\""
+ + componentAttributeName + "\")}";
+ WriteAttributeStatement writeAttributeStatement = setupAttributeStatement(qName, expression, schemaAttribute);
+ // Check for behavior events.
+ if (Kind.GENERIC.equals(schemaAttribute.getKind())) {
+ try {
+ PropertyBase componentAttribute = findComponentAttribute(componentAttributeName, componentAttributes);
+ Set<EventName> eventNames = componentAttribute.getEventNames();
+ writeAttributeStatement.setEvents(Iterables.transform(eventNames, new Function<EventName, String>() {
+ @Override
+ public String apply(EventName from) {
+ return from.getName();
+ }
+ }));
+ } catch (NoSuchElementException e) {
+ // Ignore it, no behavior such attribute defined.
+ logger.warn("Attribute " + componentAttributeName + " was not defined for renderer");
+ }
+ }
}
+
+ private WriteAttributeStatement createAttributeStatement() {
+ WriteAttributeStatement writeAttributeStatement = statementProvider.get();
+ addStatement(writeAttributeStatement);
+ return writeAttributeStatement;
+ }
+
+ private PropertyBase findComponentAttribute(final String name, Collection<PropertyBase> componentAttributes)
+ throws NoSuchElementException {
+ return Iterables.find(componentAttributes, new Predicate<PropertyBase>() {
+ @Override
+ public boolean apply(PropertyBase input) {
+ return name.equals(input.getName());
+ }
+ });
+
+ }
+
+ private WriteAttributeStatement setupAttributeStatement(QName qName,Object value,
+ Attribute schemaAttribute) {
+ WriteAttributeStatement writeAttributeStatement = createAttributeStatement();
+ String defaultValue = schemaAttribute.getDefaultValue();
+ switch (schemaAttribute.getKind()) {
+ case GENERIC:
+ writeAttributeStatement.setAttribute(qName, value, defaultValue);
+ break;
+ case URI:
+ writeAttributeStatement.setUriAttribute(qName, value, defaultValue);
+ break;
+ case BOOLEAN:
+ writeAttributeStatement.setBooleanAttribute(qName, value, defaultValue);
+ break;
+ }
+ return writeAttributeStatement;
+ }
+
+ protected Kind getAttributeKind(String attributeName) {
+ return getSchemaAttribute(attributeName).getKind();
+ }
+
+ protected Attribute getSchemaAttribute(String attributeName) {
+ Attribute result;
+ Map<String, Element> elements = attributesSchema.getElements();
+ String elementLocalName = elementName.getLocalPart();
+ if (Template.isDefaultNamespace(elementName) && elements.containsKey(elementLocalName)) {
+ Element schemaElement = elements.get(elementLocalName);
+ if (schemaElement.getAttributes().containsKey(attributeName)) {
+ result = schemaElement.getAttributes().get(attributeName);
+ } else {
+ result = getGenericAttribute(attributeName);
+ }
+ } else {
+ result = getGenericAttribute(attributeName);
+ }
+ return result;
+ }
+
+ protected Attribute getGenericAttribute(String name) {
+ Attribute attribute = new Attribute(name);
+ attribute.setKind(Kind.GENERIC);
+ // TODO - check default exceptions like class -> styleClass;
+ if ("class".equals(name)) {
+ attribute.setComponentAttributeName("styleClass");
+
+ } else {
+ attribute.setComponentAttributeName(name);
+ }
+ return attribute;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -33,9 +33,6 @@
private String[] values;
- public CaseStatement() {
- this(null);
- }
@Inject
public CaseStatement(@TemplateModel FreeMarkerRenderer renderer) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -44,7 +44,7 @@
public class FreeMarkerTemplateStatementBase extends StatementsContainer {
protected StatementsContainer parent;
- private final String templateName;
+ private String templateName;
private final FreeMarkerRenderer renderer;
private final Set<JavaImport> imports = Sets.newTreeSet(JavaImport.COMPARATOR);
private final EnumSet<HelperMethod> requiredMethods = EnumSet.noneOf(HelperMethod.class);
@@ -73,6 +73,14 @@
}
}
+ /**
+ * <p class="changed_added_4_0">Some templates use modelItem variable</p>
+ * @return
+ */
+ public Object getModelItem() {
+ return this;
+ }
+
@Override
public Iterable<JavaImport> getRequiredImports() {
parse();
@@ -96,6 +104,10 @@
requiredMethods.add(helperMethod);
}
}
+
+ public void setTemplateName(String templateName) {
+ this.templateName = templateName+".ftl";
+ }
public void addConstant(String type, String name, String code) {
JavaField field = new JavaField(new ReferencedType(type),name);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -21,8 +21,19 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.inject.Inject;
@@ -31,28 +42,89 @@
*/
public class WriteAttributeStatement extends FreeMarkerTemplateStatementBase {
- private String name;
+ private String attributeName;
private TypedTemplateStatement valueExpression;
+ private final ELParser parser;
+ private final Logger log;
+
+ private String defaultValue;
+
+ private Iterable<String> events = Collections.emptyList();
+
+
@Inject
- public WriteAttributeStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ public WriteAttributeStatement(@TemplateModel FreeMarkerRenderer renderer,ELParser parser,Logger log) {
super(renderer,"write-attribute");
+ this.parser = parser;
+ this.log = log;
}
- public void setAttribute(String name,TypedTemplateStatement expression) {
- this.name = name;
- this.valueExpression = expression;
- addRequiredMethods(HelperMethod.WRITE_ATTRIBUTE);
+ public void setAttribute(QName qName,Object object, String defaultValue) {
+ this.defaultValue = defaultValue;
+ setAttributeName(qName);
+ parseExpression(object, TypesFactory.OBJECT_TYPE);
}
- public String getName() {
- return name;
+ public void setUriAttribute(QName qName, Object value, String defaultValue) {
+ setTemplateName("write-uri-attribute");
+ setAttribute(qName, value, defaultValue);
}
+ public void setBooleanAttribute(QName qName, Object value, String defaultValue) {
+ setTemplateName("write-boolean-attribute");
+ setAttribute(qName, value, defaultValue);
+ }
+
+ private void parseExpression(Object object, ELType objectType) {
+ try {
+ valueExpression = parser.parse(object.toString(), this, objectType);
+ this.addStatement(valueExpression);
+ } catch (ParsingException e) {
+ log.error("Error parsing expression for attribute "+getAttributeName(), e);
+ }
+ }
+
+ private void setAttributeName(QName qName) {
+ StringBuilder nameBuilder = new StringBuilder();
+ if(!XMLConstants.DEFAULT_NS_PREFIX.equals(qName.getPrefix())){
+ nameBuilder.append(qName.getPrefix()).append(':');
+ }
+ this.attributeName = nameBuilder.append(qName.getLocalPart()).toString();
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
public TypedTemplateStatement getValue() {
return valueExpression;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the defaultValue
+ */
+ public String getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param iterable the events to set
+ */
+ public void setEvents(Iterable<String> iterable) {
+ this.events = iterable;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the events
+ */
+ public Iterable<String> getEvents() {
+ return this.events;
+ }
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2010-07-03 00:20:40 UTC (rev 17715)
@@ -1 +1 @@
-RenderKitUtils.renderAttribute(${facesContextVariable}, "${modelItem.attributeName}", ${modelItem.valueExpression});
\ No newline at end of file
+RenderKitUtils.renderAttribute(${facesContextVariable}, "${modelItem.attributeName}", ${modelItem.value.code});
\ No newline at end of file
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -0,0 +1,178 @@
+/*
+ * $Id$
+ *
+ * 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.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.attributes.Attribute;
+import org.richfaces.cdk.attributes.Attribute.Kind;
+import org.richfaces.cdk.attributes.Element;
+import org.richfaces.cdk.attributes.Schema;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.ModelSet;
+import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.model.PropertyModel;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.model.AnyElement;
+import org.richfaces.cdk.templatecompiler.model.Template;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+import com.google.inject.name.Names;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(CdkTestRunner.class)
+public class AttributesStatementTest extends CdkTestBase {
+
+ @Mock
+ private Logger log;
+
+ @Mock
+ private ELParser parser;
+ @Mock
+ private TypedTemplateStatement parsedExpression;
+
+ @Mock
+ @TemplateModel
+ private FreeMarkerRenderer renderer;
+
+ @Inject
+ private AttributesStatement statement;
+
+ @Inject
+ private MockController controller;
+
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ Schema schema = new Schema();
+ Element element = new Element("div");
+ createSchemaAttribute(element, "class",null,Kind.GENERIC);
+ createSchemaAttribute(element, "href",null,Kind.URI);
+ createSchemaAttribute(element, "disabled",null,Kind.BOOLEAN);
+ schema.addElement(element);
+ binder.bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toInstance(schema);
+ }
+ private void createSchemaAttribute(Element element, String name,String defaultValue,Kind kind) {
+ Attribute attribute = new Attribute(name);
+ attribute.setDefaultValue(defaultValue);
+ attribute.setComponentAttributeName(name+"Component");
+ attribute.setKind(kind);
+ element.addAttribute(attribute);
+ }
+ /**
+ * Test method for {@link org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map, java.util.Collection)}.
+ * @throws Exception
+ */
+ @Test
+ public void testProcessSimpleHtmlAttribute() throws Exception {
+ expect(parser.parse(eq("header"), isA(WriteAttributeStatement.class), same(TypesFactory.OBJECT_TYPE))).andReturn(parsedExpression);
+ parsedExpression.setParent(isA(WriteAttributeStatement.class));expectLastCall();
+ processAttributes("div", "id", "header");
+ assertEquals(1, statement.getStatements().size());
+ assertThat(statement.getStatements().get(0), instanceOf(WriteAttributeStatement.class));
+ }
+ private void processAttributes(String element, String attribute, String value) throws Exception {
+ Collection<PropertyBase> componentAttributes = createComponentAttributes();
+ processAttributes(element, attribute, value, componentAttributes);
+ }
+ private void processAttributes(String element, String attribute, String value, Collection<PropertyBase> componentAttributes) throws Exception {
+ controller.replay();
+ AnyElement anyElement = new AnyElement();
+ anyElement.setName(QName.valueOf(element));
+ anyElement.getAttributes().putAll(createAttributesMap(attribute, value));
+ statement.processAttributes(anyElement, componentAttributes);
+ controller.verify();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map, java.util.Collection)}.
+ */
+ @Test
+ public void testProcessLiteralAttribute() {
+ fail("Not yet implemented");
+ }
+ /**
+ * Test method for {@link org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map, java.util.Collection)}.
+ */
+ @Test
+ public void testProcessElAttribute() {
+ fail("Not yet implemented");
+ }
+ /**
+ * Test method for {@link org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map, java.util.Collection)}.
+ */
+ @Test
+ public void testProcessHtmlAttributeWithBehavior() {
+ fail("Not yet implemented");
+ }
+
+ private Map<QName, Object> createAttributesMap(String name, String value){
+ ImmutableMap<QName,Object> map = ImmutableMap.<QName, Object>of(QName.valueOf(name),value);
+ return map;
+ }
+
+ private PropertyBase createComponentAttribute(String name,String ...events) {
+ PropertyBase property = new PropertyModel();
+ property.setName(name);
+ for (String event : events) {
+ EventName eventName = new EventName();
+ eventName.setName(event);
+ property.getEventNames().add(eventName);
+ }
+ return property;
+ }
+
+ private Collection<PropertyBase> createComponentAttributes(PropertyBase ...properties) {
+ ModelSet<PropertyBase> attributes = ModelSet.<PropertyBase>create();
+ for (PropertyBase prop : properties) {
+ attributes.add(prop);
+ }
+ return attributes;
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-02 18:23:59 UTC (rev 17714)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -2,7 +2,6 @@
import static org.junit.Assert.*;
-import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -11,25 +10,15 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.MockController;
import org.richfaces.cdk.Stub;
-import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
-import org.richfaces.cdk.generate.freemarker.DefaultImports;
-import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
-import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
-import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
-import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
-import com.google.inject.Binder;
import com.google.inject.Inject;
-import com.google.inject.TypeLiteral;
-import freemarker.template.ObjectWrapper;
@RunWith(CdkTestRunner.class)
-public class FreeMarkerTemplateStatementTest1 extends CdkTestBase {
+public class FreeMarkerTemplateStatementTest1 extends FreeMarkerTestBase {
private static final String FOO_CODE = "private static final String foo;";
@@ -37,25 +26,10 @@
private Logger log;
@Inject
- @TemplateModel
- private FreeMarkerRenderer renderer;
-
-
-
- @Inject
private MockController controller;
- @Override
- public void configure(Binder binder) {
- super.configure(binder);
- binder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
- binder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
- binder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
- binder.bind(new TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
- }
-
public FreeMarkerTemplateStatementBase setUpStatement(String template) {
FreeMarkerTemplateStatementBase freeMarkerStatement = new FreeMarkerTemplateStatementBase(renderer, template);
return freeMarkerStatement;
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -0,0 +1,66 @@
+/*
+ * $Id$
+ *
+ * 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.cdk.templatecompiler.statements;
+
+import java.util.Map;
+
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.DefaultImports;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
+import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
+import org.richfaces.cdk.templatecompiler.RendererClassVisitor;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+import com.google.inject.TypeLiteral;
+
+import freemarker.template.ObjectWrapper;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class FreeMarkerTestBase extends CdkTestBase {
+
+ @Inject
+ @TemplateModel
+ protected FreeMarkerRenderer renderer;
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ binder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
+ binder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
+ binder.bind(new TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
+ binder.bind(new TypeLiteral<Map<String, Object>>() {
+ }).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java 2010-07-03 00:20:40 UTC (rev 17715)
@@ -0,0 +1,50 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
+(a)RunWith(CdkTestRunner.class)
+public class WriteAttributeTest extends FreeMarkerTestBase {
+ private static final String HTTP_EXAMPLE_COM = "http://example.com/";
+
+ @Stub
+ private Logger log;
+
+ @Mock
+ private ELParser parser;
+ @Mock
+ private TypedTemplateStatement parsedExpression;
+
+ @Inject
+ private MockController controller;
+
+ @Inject
+ private WriteAttributeStatement statement;
+
+ @Test
+ public void testWriteLiteral() throws Exception {
+ expect(parser.parse(HTTP_EXAMPLE_COM, statement, TypesFactory.OBJECT_TYPE)).andReturn(parsedExpression);
+ expect(parsedExpression.getCode()).andStubReturn(HTTP_EXAMPLE_COM);
+ expect(parsedExpression.isLiteral()).andStubReturn(true);
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+ statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM);
+ String code = statement.getCode();
+ controller.verify();
+
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 6 months