JBoss Rich Faces SVN: r14472 - in branches/community/3.3.X/test-applications/richfaces-docs/src/main: webapp/WEB-INF and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: msorokin
Date: 2009-06-04 06:05:27 -0400 (Thu, 04 Jun 2009)
New Revision: 14472
Modified:
branches/community/3.3.X/test-applications/richfaces-docs/src/main/java/org/docs/richfaces/Editor.java
branches/community/3.3.X/test-applications/richfaces-docs/src/main/webapp/WEB-INF/web.xml
Log:
Modified: branches/community/3.3.X/test-applications/richfaces-docs/src/main/java/org/docs/richfaces/Editor.java
===================================================================
--- branches/community/3.3.X/test-applications/richfaces-docs/src/main/java/org/docs/richfaces/Editor.java 2009-06-04 00:49:57 UTC (rev 14471)
+++ branches/community/3.3.X/test-applications/richfaces-docs/src/main/java/org/docs/richfaces/Editor.java 2009-06-04 10:05:27 UTC (rev 14472)
@@ -3,7 +3,21 @@
public class Editor {
String edit;
+
+ private String pageText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
+
+
+
+
+ public String getPageText() {
+ return pageText;
+ }
+
+ public void setPageText(String pageText) {
+ this.pageText = pageText;
+ }
+
public String getEdit() {
return edit;
}
Modified: branches/community/3.3.X/test-applications/richfaces-docs/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/community/3.3.X/test-applications/richfaces-docs/src/main/webapp/WEB-INF/web.xml 2009-06-04 00:49:57 UTC (rev 14471)
+++ branches/community/3.3.X/test-applications/richfaces-docs/src/main/webapp/WEB-INF/web.xml 2009-06-04 10:05:27 UTC (rev 14472)
@@ -1,75 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>Archetype Created Web Application</display-name>
- <context-param>
- <param-name>javax.faces.CONFIG_FILES</param-name>
- <param-value>/WEB-INF/faces-config.xml</param-value>
- </context-param>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
- <param-value>server</param-value>
- </context-param>
-
- <context-param>
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>Archetype Created Web Application</display-name>
+ <context-param>
+ <param-name>javax.faces.CONFIG_FILES</param-name>
+ <param-value>/WEB-INF/faces-config.xml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <context-param>
<param-name>org.richfaces.queue.global.enabled</param-name>
<param-value>#{globalQueue.globalQueue}</param-value>
-
</context-param>
-
-
- <context-param>
+ <context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>#{skin.skin}</param-value>
</context-param>
-
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>#{skin.standardSkinning}</param-value>
</context-param>
- <!--
- -->
- <filter>
- <display-name>Ajax4jsf Filter</display-name>
- <filter-name>ajax4jsf</filter-name>
- <filter-class>org.ajax4jsf.Filter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>ajax4jsf</filter-name>
- <servlet-name>Faces Servlet</servlet-name>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
- <dispatcher>ERROR</dispatcher>
- </filter-mapping>
-
-
-
-
-
- <context-param>
- <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
- <param-value>.xhtml</param-value>
- </context-param>
-
- <servlet>
- <servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>/faces/*</url-pattern>
- </servlet-mapping>
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+ <!--
+ -->
+ <filter>
+ <display-name>Ajax4jsf Filter</display-name>
+ <filter-name>ajax4jsf</filter-name>
+ <filter-class>org.ajax4jsf.Filter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ajax4jsf</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
- <login-config>
- <auth-method>BASIC</auth-method>
- </login-config>
-
-
-
+ <!--
+ login-config> <auth-method>BASIC</auth-method> </login-config
+ -->
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Protected Site</web-resource-name>
+ <url-pattern>/admin/*</url-pattern>
+ <http-method>DELETE</http-method>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ <http-method>PUT</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <!-- Roles that have access -->
+ <role-name>admin</role-name>
+ <role-name>user</role-name>
+
+
+ </auth-constraint>
+ </security-constraint>
+ <!-- BASIC authentication -->
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>Basic Authentication</realm-name>
+ </login-config>
+ <!-- Define security roles -->
+ <security-role>
+ <description>admin</description>
+ <role-name>admin</role-name>
+ </security-role>
+ <security-role>
+ <description>user</description>
+ <role-name>user</role-name>
+ </security-role>
</web-app>
15 years, 7 months
JBoss Rich Faces SVN: r14471 - in branches/community/3.3.X/framework/api: src/main/java/org/ajax4jsf/javascript and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-06-03 20:49:57 -0400 (Wed, 03 Jun 2009)
New Revision: 14471
Added:
branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ResponseWriterWrapper.java
branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java
branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/
branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ResponseWriterWrapperTest.java
branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java
branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java
Removed:
branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
Modified:
branches/community/3.3.X/framework/api/pom.xml
branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
Log:
https://jira.jboss.org/jira/browse/RF-7247
Modified: branches/community/3.3.X/framework/api/pom.xml
===================================================================
--- branches/community/3.3.X/framework/api/pom.xml 2009-06-04 00:38:38 UTC (rev 14470)
+++ branches/community/3.3.X/framework/api/pom.xml 2009-06-04 00:49:57 UTC (rev 14471)
@@ -20,5 +20,17 @@
<artifactId>commons-beanutils</artifactId>
<version>1.7.0</version>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ResponseWriterWrapper.java
===================================================================
--- branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ResponseWriterWrapper.java (rev 0)
+++ branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ResponseWriterWrapper.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -0,0 +1,88 @@
+/**
+ * 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.ajax4jsf.javascript;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.faces.context.ResponseWriter;
+
+final class ResponseWriterWrapper extends Writer {
+
+ private static final int BUFFER_SIZE = 1024;
+
+ private final ResponseWriter responseWriter;
+
+ private char[] writeBuffer;
+
+ ResponseWriterWrapper(ResponseWriter responseWriter) {
+ this.responseWriter = responseWriter;
+ }
+
+ @Override
+ public void close() throws IOException {
+ responseWriter.close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ responseWriter.flush();
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ responseWriter.writeText(cbuf, off, len);
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ responseWriter.writeText(str, null);
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ char cbuf[];
+ if (len <= BUFFER_SIZE) {
+ if (writeBuffer == null) {
+ writeBuffer = new char[BUFFER_SIZE];
+ }
+
+ cbuf = writeBuffer;
+ } else {
+ cbuf = new char[len];
+ }
+
+ str.getChars(off, off + len, cbuf, 0);
+
+ responseWriter.writeText(cbuf, 0, len);
+ }
+
+ @Override
+ public void write(int c) throws IOException {
+ if (writeBuffer == null){
+ writeBuffer = new char[BUFFER_SIZE];
+ }
+ writeBuffer[0] = (char) c;
+
+ responseWriter.writeText(writeBuffer, 0, 1);
+ }
+}
\ No newline at end of file
Modified: branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
===================================================================
--- branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2009-06-04 00:38:38 UTC (rev 14470)
+++ branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -22,13 +22,16 @@
package org.ajax4jsf.javascript;
import java.beans.PropertyDescriptor;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.faces.FacesException;
+import javax.faces.context.ResponseWriter;
import org.apache.commons.beanutils.PropertyUtils;
@@ -46,79 +49,71 @@
}
- /**
- * Convert any Java Object to JavaScript representation ( as possible ).
- * @param obj
- * @return
- */
- public static String toScript(Object obj) {
+ private static void writeScriptToStream(Writer writer, Object obj) throws IOException {
if (null == obj) {
- return "null";
+ writer.write("null");
} else if (obj instanceof ScriptString) {
- return ((ScriptString) obj).toScript();
+ writer.write(((ScriptString) obj).toScript());
} else if (obj.getClass().isArray()) {
- StringBuilder ret = new StringBuilder("[");
+ writer.write("[");
boolean first = true;
for (int i = 0; i < Array.getLength(obj); i++) {
Object element = Array.get(obj, i);
if (!first) {
- ret.append(',');
+ writer.write(',');
}
- ret.append(toScript(element));
+ writeScriptToStream(writer, element);
first = false;
}
- return ret.append("] ").toString();
+
+ writer.write("] ");
} else if (obj instanceof Collection) {
// Collections put as JavaScript array.
@SuppressWarnings("unchecked")
Collection<Object> collection = (Collection<Object>) obj;
- StringBuilder ret = new StringBuilder("[");
+ writer.write("[");
boolean first = true;
for (Iterator<Object> iter = collection.iterator(); iter.hasNext();) {
Object element = iter.next();
if (!first) {
- ret.append(',');
+ writer.write(',');
}
- ret.append(toScript(element));
+ writeScriptToStream(writer, element);
first = false;
}
- return ret.append("] ").toString();
+ writer.write("] ");
} else if (obj instanceof Map) {
// Maps put as JavaScript hash.
@SuppressWarnings("unchecked")
Map<Object, Object> map = (Map<Object, Object>) obj;
- StringBuilder ret = new StringBuilder("{");
+ writer.write("{");
boolean first = true;
for (Map.Entry<Object, Object> entry : map.entrySet()) {
if (!first) {
- ret.append(',');
+ writer.write(',');
}
- addEncodedString(ret, entry.getKey());
- ret.append(":");
- ret.append(toScript(entry.getValue()));
+ writeEncodedString(writer, entry.getKey());
+ writer.write(":");
+ writeScriptToStream(writer, entry.getValue());
first = false;
}
- return ret.append("} ").toString();
+ writer.write("} ");
} else if (obj instanceof Number || obj instanceof Boolean) {
// numbers and boolean put as-is, without conversion
- return obj.toString();
+ writer.write(obj.toString());
} else if (obj instanceof String) {
// all other put as encoded strings.
- StringBuilder ret = new StringBuilder();
- addEncodedString(ret, obj);
- return ret.toString();
+ writeEncodedString(writer, obj);
} else if (obj instanceof Enum) {
// all other put as encoded strings.
- StringBuilder ret = new StringBuilder();
- addEncodedString(ret, obj);
- return ret.toString();
+ writeEncodedString(writer, obj);
} else if (obj.getClass().getName().startsWith("java.sql.")) {
- StringBuilder ret = new StringBuilder("{");
+ writer.write("{");
boolean first = true;
for (PropertyDescriptor propertyDescriptor :
PropertyUtils.getPropertyDescriptors(obj)) {
@@ -134,23 +129,28 @@
}
if (!first) {
- ret.append(',');
+ writer.write(',');
}
- addEncodedString(ret, key);
- ret.append(":");
- ret.append(toScript(value));
+ writeEncodedString(writer, key);
+ writer.write(":");
+ writeScriptToStream(writer, value);
first = false;
}
- return ret.append("} ").toString();
- }
+ writer.write("} ");
+ } else {
+ // All other objects threaded as Java Beans.
+ writer.write("{");
- // All other objects threaded as Java Beans.
- try {
- StringBuilder ret = new StringBuilder("{");
- PropertyDescriptor[] propertyDescriptors = PropertyUtils
- .getPropertyDescriptors(obj);
+ PropertyDescriptor[] propertyDescriptors;
+ try {
+ propertyDescriptors = PropertyUtils.getPropertyDescriptors(obj);
+ } catch (Exception e) {
+ throw new FacesException(
+ "Error in conversion Java Object to JavaScript", e);
+ }
+
boolean first = true;
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String key = propertyDescriptor.getName();
@@ -158,39 +158,80 @@
continue;
}
if (!first) {
- ret.append(',');
+ writer.write(',');
}
- addEncodedString(ret, key);
- ret.append(":");
- ret.append(toScript(PropertyUtils.getProperty(obj, key)));
+ writeEncodedString(writer, key);
+ writer.write(":");
+
+ Object propertyValue;
+ try{
+ propertyValue = PropertyUtils.getProperty(obj, key);
+ } catch (Exception e) {
+ throw new FacesException(
+ "Error in conversion Java Object to JavaScript", e);
+ }
+
+ writeScriptToStream(writer, propertyValue);
first = false;
}
- return ret.append("} ").toString();
- } catch (Exception e) {
- throw new FacesException(
- "Error in conversion Java Object to JavaScript", e);
+
+ writer.write("} ");
}
}
+
+ public static void writeToStream(final ResponseWriter responseWriter, Object obj) throws IOException {
+ writeScriptToStream(new ResponseWriterWrapper(responseWriter), obj);
+ }
+
+ /**
+ * Convert any Java Object to JavaScript representation ( as possible ).
+ * @param obj
+ * @return
+ */
+ public static String toScript(Object obj) {
+ StringBuilder sb = new StringBuilder();
+ try {
+ writeScriptToStream(new StringBuilderWriter(sb), obj);
+ } catch (IOException e) {
+ //ignore
+ }
+ return sb.toString();
+ }
+ public static void writeEncodedString(Writer w, Object obj) throws IOException {
+ w.write("'");
+ writeEncoded(w, obj);
+ w.write("'");
+ }
+
public static void addEncodedString(StringBuilder buff, Object obj) {
- buff.append("'");
- addEncoded(buff, obj);
- buff.append("'");
-
+ try {
+ writeEncodedString(new StringBuilderWriter(buff), obj);
+ } catch (IOException e) {
+ //ignore
+ }
}
- public static void addEncoded(StringBuilder buff, Object obj) {
+ public static void writeEncoded(Writer w, Object obj) throws IOException {
JSEncoder encoder = new JSEncoder();
char chars[] = obj.toString().toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (!encoder.compile(c)) {
- buff.append(encoder.encode(c));
+ w.write(encoder.encode(c));
} else {
- buff.append(c);
+ w.write(c);
}
}
}
+
+ public static void addEncoded(StringBuilder buff, Object obj) {
+ try {
+ writeEncoded(new StringBuilderWriter(buff), obj);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
public static String getValidJavascriptName(String s) {
Added: branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java
===================================================================
--- branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java (rev 0)
+++ branches/community/3.3.X/framework/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -0,0 +1,84 @@
+/**
+ * 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.ajax4jsf.javascript;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+final class StringBuilderWriter extends Writer {
+
+ private StringBuilder builder;
+
+ public StringBuilderWriter(StringBuilder builder) {
+ super();
+ this.builder = builder;
+ }
+
+ /**
+ * Closing this writer doesn't have any effect
+ */
+ @Override
+ public void close() throws IOException {
+ //do nothing
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#flush()
+ */
+ @Override
+ public void flush() throws IOException {
+ //do nothing
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#write(char[], int, int)
+ */
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ builder.append(cbuf, off, len);
+ }
+
+ @Override
+ public void write(char[] cbuf) throws IOException {
+ builder.append(cbuf);
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ builder.append(str);
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ builder.append(str, off, off + len);
+ }
+
+ @Override
+ public void write(int c) throws IOException {
+ builder.append((char) c);
+ }
+
+}
Deleted: branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
===================================================================
--- branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java 2009-06-04 00:38:38 UTC (rev 14470)
+++ branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -1,223 +0,0 @@
-/**
- * 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.ajax4jsf.framework.util.javascript;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import org.ajax4jsf.javascript.ScriptUtils;
-
-import junit.framework.TestCase;
-
-/**
- * @author shura
- *
- */
-public class ScriptUtilsTest extends TestCase {
-
- /**
- * @author shura
- *
- */
- public static class Bean {
-
- int _integer;
- boolean _bool;
- Object _foo;
-
- public Bean() {
- }
- /**
- * @param ineger
- * @param bool
- * @param foo
- */
- public Bean(int ineger, boolean bool, Object foo) {
- this._integer = ineger;
- this._bool = bool;
- this._foo = foo;
- }
- /**
- * @return the bool
- */
- public boolean isBool() {
- return this._bool;
- }
- /**
- * @param bool the bool to set
- */
- public void setBool(boolean bool) {
- this._bool = bool;
- }
- /**
- * @return the ineger
- */
- public int getInteger() {
- return this._integer;
- }
- /**
- * @param ineger the ineger to set
- */
- public void setInteger(int ineger) {
- this._integer = ineger;
- }
- /**
- * @return the foo
- */
- public Object getFoo() {
- return this._foo;
- }
- /**
- * @param foo the foo to set
- */
- public void setFoo(Object foo) {
- this._foo = foo;
- }
- }
-
- /**
- * @param name
- */
- public ScriptUtilsTest(String name) {
- super(name);
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testStringToScript() {
- Object obj = "foo";
- assertEquals("'foo'", ScriptUtils.toScript(obj));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testArrayToScript() {
- int[] obj = {1,2,3,4,5};
- assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
- }
-
- public void testSqlDate() {
- java.sql.Time obj = new java.sql.Time(1);
- assertNotNull(ScriptUtils.toScript(obj));
-
- java.sql.Date obj1 = new java.sql.Date(1);
- assertNotNull(ScriptUtils.toScript(obj1));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testTwoDimentionalArrayToScript() {
- int[][] obj = {{1,2},{3,4}};
- assertEquals("[[1,2] ,[3,4] ] ", ScriptUtils.toScript(obj));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testTwoDimentionalStringArrayToScript() {
- String[][] obj = {{"one","two"},{"three","four"}};
- assertEquals("[['one','two'] ,['three','four'] ] ", ScriptUtils.toScript(obj));
- Map<String, Object> map = new TreeMap<String, Object>();
- map.put("a", obj);
- map.put("b", "c");
- assertEquals("{'a':[['one','two'] ,['three','four'] ] ,'b':'c'} ", ScriptUtils.toScript(map));
- }
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testListToScript() {
- List<Integer> obj = new ArrayList<Integer>();
- obj.add(new Integer(1));
- obj.add(new Integer(2));
- obj.add(new Integer(3));
- obj.add(new Integer(4));
- obj.add(new Integer(5));
- assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testSetToScript() {
- Set<Integer> obj = new TreeSet<Integer>();
- obj.add(new Integer(1));
- obj.add(new Integer(2));
- obj.add(new Integer(3));
- obj.add(new Integer(4));
- obj.add(new Integer(5));
- assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
- }
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testObjectArrayToScript() {
- Bean[] obj = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
- assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testObjectListToScript() {
- Bean[] array = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
- List<Bean> obj = Arrays.asList(array);
- assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
- */
- public void testMapToScript() {
- TreeMap<String, String> obj = new TreeMap<String, String>();
- obj.put("a", "foo");
- obj.put("b", "bar");
- obj.put("c", "baz");
- assertEquals("{'a':'foo','b':'bar','c':'baz'} ", ScriptUtils.toScript(obj));
- }
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncodedString(java.lang.StringBuffer, java.lang.Object)}.
- */
- public void testAddEncodedString() {
- StringBuilder buff = new StringBuilder();
- ScriptUtils.addEncodedString(buff, "foo");
- assertEquals("'foo'", buff.toString());
- }
-
- /**
- * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncoded(java.lang.StringBuffer, java.lang.Object)}.
- */
- public void testAddEncoded() {
- StringBuilder buff = new StringBuilder();
- ScriptUtils.addEncoded(buff, "foo\"\'");
- assertEquals("foo\\\"\\\'", buff.toString());
- }
-
-
-}
Added: branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ResponseWriterWrapperTest.java
===================================================================
--- branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ResponseWriterWrapperTest.java (rev 0)
+++ branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ResponseWriterWrapperTest.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -0,0 +1,209 @@
+/**
+ * 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.ajax4jsf.javascript;
+
+import static org.easymock.EasyMock.aryEq;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.reportMatcher;
+import static org.easymock.classextension.EasyMock.createStrictMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+import java.io.Writer;
+import java.lang.reflect.Array;
+import java.util.Random;
+
+import javax.faces.context.ResponseWriter;
+
+import junit.framework.TestCase;
+
+import org.easymock.IArgumentMatcher;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class ResponseWriterWrapperTest extends TestCase {
+
+ private ResponseWriter mockWriter;
+
+ private Writer writer;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mockWriter = createStrictMock(ResponseWriter.class);
+ writer = new ResponseWriterWrapper(mockWriter);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.writer = null;
+ this.mockWriter = null;
+ }
+
+ public void testWrite1() throws Exception {
+ char[] cs = new char[] {'a', 'b'};
+ mockWriter.writeText(cs, 0, 2);
+ replay(mockWriter);
+
+ writer.write(cs);
+ verify(mockWriter);
+ }
+
+ private static char[] expectSingleChar(final char c) {
+ reportMatcher(new IArgumentMatcher() {
+
+ private String failureMessage;
+
+ public void appendTo(StringBuffer sb) {
+ sb.append(failureMessage);
+ }
+
+ public boolean matches(Object o) {
+ if (!(o instanceof char[])) {
+ failureMessage = "Array of chars expected as argument";
+ } else {
+ if (Array.getLength(o) == 0) {
+ failureMessage = "Array should be of non-zero length";
+ } else {
+ if (Array.getChar(o, 0) != c) {
+ failureMessage = "["+c+"] expected as [0] char";
+ }
+ }
+ }
+
+ return failureMessage == null;
+ }
+
+ });
+
+ return null;
+ }
+
+ private static char[] expectFirstChars(final char[] cs) {
+ return expectFirstChars(cs, cs.length);
+ }
+
+ private static char[] expectFirstChars(final char[] cs, final int length) {
+ reportMatcher(new IArgumentMatcher() {
+
+ private String failureMessage;
+
+ public void appendTo(StringBuffer sb) {
+ sb.append(failureMessage);
+ }
+
+ public boolean matches(Object o) {
+ if (!(o instanceof char[])) {
+ failureMessage = "Array of chars expected as argument";
+ } else {
+ char[] argChars = (char[]) o;
+ if (argChars.length < length) {
+ failureMessage = "Array should have minimum " + length + " length, but has only: " + argChars.length;
+ } else {
+ for (int i = 0; i < length; i++) {
+ if (argChars[i] != cs[i]) {
+ failureMessage = "Char at offset [" + i + "] mismath: expected " + cs[i] + " but was " + argChars[i];
+ break;
+ }
+ }
+ }
+ }
+
+ return failureMessage == null;
+ }
+
+ });
+
+ return null;
+ }
+
+ public void testWrite2() throws Exception {
+ mockWriter.writeText(expectSingleChar((char) 0x5678), eq(0), eq(1));
+ mockWriter.writeText(expectSingleChar((char) 0xBA98), eq(0), eq(1));
+ replay(mockWriter);
+ writer.write(0x12345678);
+ writer.write(0xFECDBA98);
+ verify(mockWriter);
+ }
+
+ public void testWrite3() throws Exception {
+ mockWriter.writeText(eq("test"), (String) isNull());
+ replay(mockWriter);
+ writer.write("test");
+ verify(mockWriter);
+ }
+
+ public void testWrite4() throws Exception {
+ mockWriter.writeText(aryEq("abcd".toCharArray()), eq(1), eq(2));
+ mockWriter.writeText(aryEq("efgh".toCharArray()), eq(0), eq(3));
+ mockWriter.writeText(aryEq("ijklm".toCharArray()), eq(2), eq(3));
+
+ replay(mockWriter);
+ writer.write("abcd".toCharArray(), 1, 2);
+ writer.write("efgh".toCharArray(), 0, 3);
+ writer.write("ijklm".toCharArray(), 2, 3);
+ verify(mockWriter);
+ }
+
+ public void testWrite5() throws Exception {
+ mockWriter.writeText(expectFirstChars("string to".toCharArray()), eq(0), eq(9));
+ mockWriter.writeText(expectFirstChars("one".toCharArray()), eq(0), eq(3));
+
+ replay(mockWriter);
+ writer.write("string to test", 0, 9);
+ writer.write("short one", 6, 3);
+ verify(mockWriter);
+ }
+
+ public void testWrite6() throws Exception {
+ char[] cs = new char[4098];
+ int length = cs.length - 2;
+
+ for (int i = 0; i < cs.length; i++) {
+ cs[i] = (char) new Random().nextInt(Character.MAX_VALUE + 1);
+ }
+
+ mockWriter.writeText(expectFirstChars(cs, length), eq(0), eq(length));
+ replay(mockWriter);
+ writer.write(String.valueOf(cs), 0, length);
+ verify(mockWriter);
+ }
+
+ public void testFlush() throws Exception {
+ mockWriter.flush();
+ replay(mockWriter);
+ writer.flush();
+ verify(mockWriter);
+ }
+
+ public void testClose() throws Exception {
+ mockWriter.close();
+ replay(mockWriter);
+ writer.close();
+ verify(mockWriter);
+ }
+}
Copied: branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java (from rev 14467, branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java)
===================================================================
--- branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java (rev 0)
+++ branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -0,0 +1,307 @@
+/**
+ * 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.ajax4jsf.javascript;
+
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.classextension.EasyMock.createNiceMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.faces.context.ResponseWriter;
+
+import junit.framework.TestCase;
+
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+
+/**
+ * @author shura
+ *
+ */
+public class ScriptUtilsTest extends TestCase {
+
+ /**
+ * @author shura
+ *
+ */
+ public static class Bean {
+
+ int _integer;
+ boolean _bool;
+ Object _foo;
+
+ public Bean() {
+ }
+ /**
+ * @param ineger
+ * @param bool
+ * @param foo
+ */
+ public Bean(int ineger, boolean bool, Object foo) {
+ this._integer = ineger;
+ this._bool = bool;
+ this._foo = foo;
+ }
+ /**
+ * @return the bool
+ */
+ public boolean isBool() {
+ return this._bool;
+ }
+ /**
+ * @param bool the bool to set
+ */
+ public void setBool(boolean bool) {
+ this._bool = bool;
+ }
+ /**
+ * @return the ineger
+ */
+ public int getInteger() {
+ return this._integer;
+ }
+ /**
+ * @param ineger the ineger to set
+ */
+ public void setInteger(int ineger) {
+ this._integer = ineger;
+ }
+ /**
+ * @return the foo
+ */
+ public Object getFoo() {
+ return this._foo;
+ }
+ /**
+ * @param foo the foo to set
+ */
+ public void setFoo(Object foo) {
+ this._foo = foo;
+ }
+ }
+
+ /**
+ * @param name
+ */
+ public ScriptUtilsTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testStringToScript() {
+ Object obj = "foo";
+ assertEquals("'foo'", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testArrayToScript() {
+ int[] obj = {1,2,3,4,5};
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+
+ public void testSqlDate() {
+ java.sql.Time obj = new java.sql.Time(1);
+ assertNotNull(ScriptUtils.toScript(obj));
+
+ java.sql.Date obj1 = new java.sql.Date(1);
+ assertNotNull(ScriptUtils.toScript(obj1));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testTwoDimentionalArrayToScript() {
+ int[][] obj = {{1,2},{3,4}};
+ assertEquals("[[1,2] ,[3,4] ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testTwoDimentionalStringArrayToScript() {
+ String[][] obj = {{"one","two"},{"three","four"}};
+ assertEquals("[['one','two'] ,['three','four'] ] ", ScriptUtils.toScript(obj));
+ Map<String, Object> map = new TreeMap<String, Object>();
+ map.put("a", obj);
+ map.put("b", "c");
+ assertEquals("{'a':[['one','two'] ,['three','four'] ] ,'b':'c'} ", ScriptUtils.toScript(map));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testListToScript() {
+ List<Integer> obj = new ArrayList<Integer>();
+ obj.add(new Integer(1));
+ obj.add(new Integer(2));
+ obj.add(new Integer(3));
+ obj.add(new Integer(4));
+ obj.add(new Integer(5));
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testSetToScript() {
+ Set<Integer> obj = new TreeSet<Integer>();
+ obj.add(new Integer(1));
+ obj.add(new Integer(2));
+ obj.add(new Integer(3));
+ obj.add(new Integer(4));
+ obj.add(new Integer(5));
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testObjectArrayToScript() {
+ Bean[] obj = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
+ assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testObjectListToScript() {
+ Bean[] array = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
+ List<Bean> obj = Arrays.asList(array);
+ assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testMapToScript() {
+ TreeMap<String, String> obj = new TreeMap<String, String>();
+ obj.put("a", "foo");
+ obj.put("b", "bar");
+ obj.put("c", "baz");
+ assertEquals("{'a':'foo','b':'bar','c':'baz'} ", ScriptUtils.toScript(obj));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncodedString(java.lang.StringBuffer, java.lang.Object)}.
+ */
+ public void testAddEncodedString() {
+ StringBuilder buff = new StringBuilder();
+ ScriptUtils.addEncodedString(buff, "foo");
+ assertEquals("'foo'", buff.toString());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncoded(java.lang.StringBuffer, java.lang.Object)}.
+ */
+ public void testAddEncoded() {
+ StringBuilder buff = new StringBuilder();
+ ScriptUtils.addEncoded(buff, "foo\"\'");
+ assertEquals("foo\\\"\\\'", buff.toString());
+ }
+
+ /**
+ * Test method for {@link ScriptUtils#toScript(Object)}
+ */
+ public void testNull() throws Exception {
+ assertEquals("null", ScriptUtils.toScript(null));
+ }
+
+ /**
+ * Test method for {@link ScriptUtils#toScript(Object)}
+ */
+ public void testScriptString() throws Exception {
+ assertEquals("alert(x<y);", ScriptUtils.toScript(new JSLiteral("alert(x<y);")));
+ }
+
+ private static enum TestEnum {
+ A, B, C;
+
+ @Override
+ public String toString() {
+ return "TestEnum: " + super.toString();
+ }
+ }
+
+ /**
+ * Test method for {@link ScriptUtils#toScript(Object)}
+ */
+ public void testEnum() throws Exception {
+ assertEquals("'TestEnum: B'", ScriptUtils.toScript(TestEnum.B));
+ }
+
+ private void assertCaptureEquals(Capture<? extends Object> capture, String expected) {
+ StringBuilder sb = new StringBuilder();
+ List<? extends Object> list = capture.getValues();
+ for (Object o : list) {
+ assertNotNull(o);
+ sb.append(o);
+ }
+
+ assertEquals(expected, sb.toString().trim());
+ }
+
+ /**
+ * Test method for {@link ScriptUtils#writeToStream(javax.faces.context.ResponseWriter, Object)}
+ */
+ public void testWriteToStream() throws Exception {
+ ResponseWriter mockWriter = createNiceMock(ResponseWriter.class);
+ Capture<? extends Object> capture = new Capture<Object>(CaptureType.ALL) {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4915440411892856583L;
+
+ @Override
+ public void setValue(Object value) {
+ if (value instanceof char[]) {
+ char[] cs = (char[]) value;
+ super.setValue(new String(cs, 0, 1));
+ } else {
+ super.setValue(value);
+ }
+ }
+ };
+
+
+ mockWriter.writeText(capture(capture), (String) isNull());
+ expectLastCall().anyTimes();
+ mockWriter.writeText((char[])capture(capture), eq(0), eq(1));
+ expectLastCall().anyTimes();
+
+ replay(mockWriter);
+ ScriptUtils.writeToStream(mockWriter, Collections.singletonMap("delay", Integer.valueOf(1500)));
+ verify(mockWriter);
+
+ assertCaptureEquals(capture, "{'delay':1500}");
+ }
+}
Added: branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java
===================================================================
--- branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java (rev 0)
+++ branches/community/3.3.X/framework/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java 2009-06-04 00:49:57 UTC (rev 14471)
@@ -0,0 +1,97 @@
+/**
+ * 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.ajax4jsf.javascript;
+
+import java.io.Writer;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class StringBuilderWriterTest extends TestCase {
+
+ private StringBuilder builder;
+
+ private Writer writer;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.builder = new StringBuilder();
+ this.writer = new StringBuilderWriter(this.builder);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.builder = null;
+ this.writer = null;
+ }
+
+ public void testWrite() throws Exception {
+ writer.write(new char[] {'a', 'b'});
+ assertEquals("ab", builder.toString());
+ }
+
+ public void testWrite2() throws Exception {
+ writer.write(0x12345678);
+
+ String s = builder.toString();
+ assertEquals(1, s.length());
+ assertEquals(0x5678, s.charAt(0));
+ }
+
+ public void testWrite3() throws Exception {
+ writer.write("test");
+
+ assertEquals("test", builder.toString());
+ }
+
+ public void testWrite4() throws Exception {
+ writer.write("abcd".toCharArray(), 1, 2);
+ assertEquals("bc", builder.toString());
+ writer.write("efgh".toCharArray(), 0, 3);
+ assertEquals("bcefg", builder.toString());
+ writer.write("ijkl".toCharArray(), 2, 2);
+ assertEquals("bcefgkl", builder.toString());
+ }
+
+ public void testWrite5() throws Exception {
+ writer.write("abcd", 1, 2);
+ assertEquals("bc", builder.toString());
+ writer.write("efgh", 0, 3);
+ assertEquals("bcefg", builder.toString());
+ writer.write("ijklm", 2, 3);
+ assertEquals("bcefgklm", builder.toString());
+ }
+
+ public void testFlush() throws Exception {
+ writer.flush();
+ }
+
+ public void testClose() throws Exception {
+ writer.close();
+ }
+}
15 years, 7 months
JBoss Rich Faces SVN: r14470 - in branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements: std and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-06-03 20:38:38 -0400 (Wed, 03 Jun 2009)
New Revision: 14470
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
Log:
https://jira.jboss.org/jira/browse/RF-7247
Modified: branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
===================================================================
--- branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-04 00:06:54 UTC (rev 14469)
+++ branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-04 00:38:38 UTC (rev 14470)
@@ -38,6 +38,7 @@
import org.ajax4jsf.templatecompiler.elements.std.SetTemplateElement;
import org.ajax4jsf.templatecompiler.elements.vcp.AjaxRenderedAreaElement;
import org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.FWriteAsScript;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderScriptsElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderStylesElement;
import org.apache.commons.logging.Log;
@@ -76,6 +77,7 @@
mapClasses.put("c:forEach", ForEachTemplateElement.class.getName());
mapClasses.put("f:clientid", FClientIDTemplateElement.class.getName());
mapClasses.put("f:clientId", FClientIDTemplateElement.class.getName());
+ mapClasses.put("f:writeAsScript", FWriteAsScript.class.getName());
mapClasses.put("f:insertComponent",
"org.ajax4jsf.templatecompiler.elements.vcp.InsertComponent");
Modified: branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
===================================================================
--- branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-04 00:06:54 UTC (rev 14469)
+++ branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-04 00:38:38 UTC (rev 14470)
@@ -51,12 +51,18 @@
super(element, componentBean);
NamedNodeMap nnm = element.getAttributes();
- variableName = nnm.getNamedItem("var").getNodeValue();
- if (variableName == null || variableName.length() == 0) {
+ Node varNode = nnm.getNamedItem("var");
+ if (varNode == null) {
throw new RuntimeException("'var' attribute required for c:scriptObject tag!");
}
- this.getComponentBean().addVariable(variableName, VARIABLE_TYPE);
+ variableName = varNode.getNodeValue();
+
+ try {
+ this.getComponentBean().addVariable(variableName, VARIABLE_TYPE.getName());
+ } catch (CompilationException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
}
private static ThreadLocal<String> variableNamesStorage = new ThreadLocal<String>();
Added: branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java
===================================================================
--- branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java (rev 0)
+++ branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java 2009-06-04 00:38:38 UTC (rev 14470)
@@ -0,0 +1,56 @@
+/**
+ * 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.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class FWriteAsScript extends TemplateElementBase {
+
+ private String value;
+
+ public FWriteAsScript(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ Node node = element.getAttributes().getNamedItem("value");
+ if (node == null) {
+ throw new RuntimeException("'value' attribute is required for f:writeAsScript tag!");
+ }
+
+ value = ELParser.compileEL(node.getNodeValue(), componentBean);
+ }
+
+ public String getBeginElement() throws CompilationException {
+ return String.format("org.ajax4jsf.javascript.ScriptUtils.writeToStream(writer, %s);\n", value);
+ }
+
+ public String getEndElement() throws CompilationException {
+ return null;
+ }
+}
15 years, 7 months
JBoss Rich Faces SVN: r14469 - branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-06-03 20:06:54 -0400 (Wed, 03 Jun 2009)
New Revision: 14469
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java
Log:
https://jira.jboss.org/jira/browse/RF-7247
Modified: branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
===================================================================
--- branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-03 18:19:07 UTC (rev 14468)
+++ branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-04 00:06:54 UTC (rev 14469)
@@ -26,7 +26,6 @@
import org.ajax4jsf.templatecompiler.builder.CompilationContext;
import org.ajax4jsf.templatecompiler.builder.CompilationException;
import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
-import org.ajax4jsf.templatecompiler.elements.TemplateElement;
import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
import org.apache.velocity.VelocityContext;
import org.w3c.dom.NamedNodeMap;
@@ -60,16 +59,14 @@
this.getComponentBean().addVariable(variableName, VARIABLE_TYPE);
}
- @Override
- public void addSubElement(TemplateElement e) {
- super.addSubElement(e);
-
- if (e instanceof ScriptOptionTemplateElement) {
- ((ScriptOptionTemplateElement) e).setMapName(variableName);
- }
- }
+ private static ThreadLocal<String> variableNamesStorage = new ThreadLocal<String>();
public String getBeginElement() throws CompilationException {
+ if (variableNamesStorage.get() != null) {
+ throw new CompilationException("Nested c:scriptObject tags aren't allowed!");
+ }
+ variableNamesStorage.set(variableName);
+
VelocityContext context = new VelocityContext();
context.put("variable", this.variableName);
context.put("type", VARIABLE_TYPE.getName().replace('$', '.'));
@@ -85,6 +82,11 @@
}
public String getEndElement() {
+ variableNamesStorage.set(null);
return null;
}
+
+ static String getVariableName() {
+ return variableNamesStorage.get();
+ }
}
\ No newline at end of file
Modified: branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java
===================================================================
--- branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java 2009-06-03 18:19:07 UTC (rev 14468)
+++ branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java 2009-06-04 00:06:54 UTC (rev 14469)
@@ -48,8 +48,6 @@
private String defaultValue;
- private String mapName;
-
private String variables = null;
private String attributes = null;
@@ -152,10 +150,6 @@
}
}
- public void setMapName(String mapName) {
- this.mapName = mapName;
- }
-
protected String getTemplateName() {
return TEMPLATE;
}
@@ -163,7 +157,7 @@
public String getBeginElement() throws CompilationException {
VelocityContext context = new VelocityContext();
- context.put("mapName", mapName);
+ context.put("mapName", ScriptObjectTemplateElement.getVariableName());
context.put("valuesList", values);
if (!isEmpty(defaultValue)) {
15 years, 7 months
JBoss Rich Faces SVN: r14468 - in branches/community/3.3.X/ui/virtualEarth/src: main/templates and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-06-03 14:19:07 -0400 (Wed, 03 Jun 2009)
New Revision: 14468
Modified:
branches/community/3.3.X/ui/virtualEarth/src/main/resources/org/richfaces/renderkit/html/css/virtualEarth.xcss
branches/community/3.3.X/ui/virtualEarth/src/main/templates/virtualEarth.jspx
branches/community/3.3.X/ui/virtualEarth/src/test/java/org/richfaces/component/VirtualEarthComponentTest.java
Log:
RF-7317
Modified: branches/community/3.3.X/ui/virtualEarth/src/main/resources/org/richfaces/renderkit/html/css/virtualEarth.xcss
===================================================================
--- branches/community/3.3.X/ui/virtualEarth/src/main/resources/org/richfaces/renderkit/html/css/virtualEarth.xcss 2009-06-03 18:15:48 UTC (rev 14467)
+++ branches/community/3.3.X/ui/virtualEarth/src/main/resources/org/richfaces/renderkit/html/css/virtualEarth.xcss 2009-06-03 18:19:07 UTC (rev 14468)
@@ -3,7 +3,7 @@
xmlns:u='http:/jsf.exadel.com/template/util'
xmlns="http://www.w3.org/1999/xhtml" >
<f:verbatim><![CDATA[
-.dr-ve{
+.rich-virtualEarth{
width:400px;
height:400px;
}
Modified: branches/community/3.3.X/ui/virtualEarth/src/main/templates/virtualEarth.jspx
===================================================================
--- branches/community/3.3.X/ui/virtualEarth/src/main/templates/virtualEarth.jspx 2009-06-03 18:15:48 UTC (rev 14467)
+++ branches/community/3.3.X/ui/virtualEarth/src/main/templates/virtualEarth.jspx 2009-06-03 18:19:07 UTC (rev 14468)
@@ -22,7 +22,7 @@
<h:styles>css/virtualEarth.xcss</h:styles>
<h:scripts>new org.ajax4jsf.javascript.PrototypeScript(),script/virtualEarth.js</h:scripts>
-<div id="#{clientId}" style="position:relative; width:400px; height:400px;#{style}" class="dr-ve rich-virtualEarth #{component.attributes['styleClass']}"
+<div id="#{clientId}" style="position:relative; width:400px; height:400px;#{style}" class="rich-virtualEarth #{component.attributes['styleClass']}"
x:passThruWithExclusions="id, styleClass,style,class"
>
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=#{component.attr...'version']}" />
Modified: branches/community/3.3.X/ui/virtualEarth/src/test/java/org/richfaces/component/VirtualEarthComponentTest.java
===================================================================
--- branches/community/3.3.X/ui/virtualEarth/src/test/java/org/richfaces/component/VirtualEarthComponentTest.java 2009-06-03 18:15:48 UTC (rev 14467)
+++ branches/community/3.3.X/ui/virtualEarth/src/test/java/org/richfaces/component/VirtualEarthComponentTest.java 2009-06-03 18:19:07 UTC (rev 14468)
@@ -92,7 +92,6 @@
assertNotNull(htmlVirtualEarth);
assertTrue("div".equals(htmlVirtualEarth.getTagName()));
- assertTrue(htmlVirtualEarth.getAttributeValue("class").contains("dr-ve"));
assertTrue(htmlVirtualEarth.getAttributeValue("class").contains("rich-virtualEarth"));
}
15 years, 7 months
JBoss Rich Faces SVN: r14467 - branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-06-03 14:15:48 -0400 (Wed, 03 Jun 2009)
New Revision: 14467
Modified:
branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
Log:
A4J.AJAX.TestReplacedGetElementByIdVisibility() incorrect variable initialization fixed
Modified: branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-06-03 18:13:04 UTC (rev 14466)
+++ branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2009-06-03 18:15:48 UTC (rev 14467)
@@ -1779,12 +1779,11 @@
A4J.AJAX.TestReplacedGetElementByIdVisibility = function() {
if (!A4J.AJAX._replacedGetElementByIdVisibilityTested) {
A4J.AJAX._replacedGetElementByIdVisibilityTested = true;
+ A4J.AJAX._testReplacedGetElementByIdVisibility = true;
A4J.AJAX.TestScriptEvaluation();
if (A4J.AJAX._scriptEvaluated) {
try {
- A4J.AJAX._testReplacedGetElementByIdVisibility = true;
-
var _span = document.createElement("span");
document.body.appendChild(_span);
15 years, 7 months
JBoss Rich Faces SVN: r14466 - branches/community/3.3.X/docs/faq/en/src/main/docbook/module.
by richfaces-svn-commits@lists.jboss.org
Author: smukhina
Date: 2009-06-03 14:13:04 -0400 (Wed, 03 Jun 2009)
New Revision: 14466
Modified:
branches/community/3.3.X/docs/faq/en/src/main/docbook/module/RFCfaq.xml
Log:
https://jira.jboss.org/jira/browse/RF-7289 corrected FAQ entry text 1.76 that caused misunderstanding
Modified: branches/community/3.3.X/docs/faq/en/src/main/docbook/module/RFCfaq.xml
===================================================================
--- branches/community/3.3.X/docs/faq/en/src/main/docbook/module/RFCfaq.xml 2009-06-03 17:56:32 UTC (rev 14465)
+++ branches/community/3.3.X/docs/faq/en/src/main/docbook/module/RFCfaq.xml 2009-06-03 18:13:04 UTC (rev 14466)
@@ -2501,7 +2501,7 @@
<para>The following order, in which filters are defined and mapped in web.xml, is important for <emphasis role="bold">
<property><rich:fileUpload></property>
</emphasis> component proper work with MyFaces.
- Note that the extension filter should be mapped on faces servlet not to *.jsf (!) to provide this sequence work correctly.
+ Note that the extension filter should be mapped on faces servlet not to <url-pattern> element to provide this sequence work correctly.
</para>
<para>
<emphasis role="bold">Example:</emphasis>
15 years, 7 months
JBoss Rich Faces SVN: r14465 - branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html.
by richfaces-svn-commits@lists.jboss.org
Author: Alex.Kolonitsky
Date: 2009-06-03 13:56:32 -0400 (Wed, 03 Jun 2009)
New Revision: 14465
Modified:
branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
Log:
New node for ID j_id_jsp_1897617803_67:filterListMenu_menu_script is not present in response
https://jira.jboss.org/jira/browse/RF-3540
Modified: branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java
===================================================================
--- branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-06-03 17:53:34 UTC (rev 14464)
+++ branches/community/3.3.X/ui/menu-components/src/main/java/org/richfaces/renderkit/html/AbstractMenuRenderer.java 2009-06-03 17:56:32 UTC (rev 14465)
@@ -44,181 +44,188 @@
/**
* @author Maksim Kaszynski
- *
+ *
*/
public abstract class AbstractMenuRenderer extends HeaderResourcesRendererBase {
-
- private final InternetResource[] scripts = {
- new org.ajax4jsf.javascript.PrototypeScript(),
- new org.ajax4jsf.javascript.AjaxScript(),
- getResource("scripts/menu.js") };
-
- @Override
- protected InternetResource[] getScripts() {
- return scripts;
- }
-
- @Override
- protected InternetResource[] getStyles() {
- return super.getStyles();
- }
-
- public void encodeScript(FacesContext context, UIComponent component) throws IOException {
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(getLayerScript(context, component));
-
- List children = component.getChildren();
- for(Iterator it = children.iterator();it.hasNext();) {
- buffer.append(getItemScript(context, (UIComponent) it.next()));
- }
-
- ResponseWriter out = context.getResponseWriter();
- String script = buffer.append(";").toString();
- out.write(script);
- }
-
- protected abstract String getLayerScript(FacesContext context, UIComponent layer);
-
- protected String getItemScript(FacesContext context, UIComponent kid) {
- String itemId = null;
- boolean closeOnClick = true;
- Integer flagGroup = null;
- boolean disabled = false;
- if (kid instanceof UIMenuItem) {
- UIMenuItem menuItem = (UIMenuItem) kid;
- itemId = kid.getClientId(context);
- disabled = menuItem.isDisabled();
- if (disabled) {
- closeOnClick = false;
- }
- } else if (kid instanceof UIMenuGroup) {
- UIMenuGroup menuGroup = (UIMenuGroup) kid;
- itemId = kid.getClientId(context);
- closeOnClick = false;
- if ((disabled = menuGroup.isDisabled())) {
- flagGroup = Integer.valueOf(2);
- } else {
- flagGroup = Integer.valueOf(1);
- }
- }
- if (itemId != null) {
- JSFunction function = new JSFunction(".addItem");
- function.addParameter(itemId);
- ScriptOptions options = new ScriptOptions(kid);
-
- options.addEventHandler("onmouseout");
- options.addEventHandler("onmouseover");
-
- if (closeOnClick) {
- options.addOption("closeOnClick", Boolean.TRUE);
- }
- options.addOption("flagGroup", flagGroup);
-
- options.addOption("styleClass");
- options.addOption("style");
- options.addOption("itemClass");
- options.addOption("itemStyle");
- options.addOption("disabledItemClass");
- options.addOption("disabledItemStyle");
- options.addOption("selectItemClass");
- options.addOption("labelClass");
- options.addOption("selectedLabelClass");
- options.addOption("disabledLabelClass");
-
- options.addOption("selectClass");
- options.addOption("selectStyle");
- options.addOption("iconClass");
-
- if (disabled) {
- options.addOption("disabled", Boolean.TRUE);
- }
-
- options.addEventHandler("onselect");
-
- function.addParameter(options);
- return function.toScript();
- }
- return "";
- }
-
- public boolean getRendersChildren() {
- return true;
- }
-
- public void encodeChildren(FacesContext context, UIComponent component)
- throws IOException {
- List flatListOfNodes = new LinkedList();
- String width = (String) component.getAttributes().get("popupWidth");
-
- flatten(component.getChildren(), flatListOfNodes);
- processLayer(context, component, width);
-
- for (Iterator iter = flatListOfNodes.iterator(); iter.hasNext();) {
- UIMenuGroup node = (UIMenuGroup) iter.next();
- if (node.isRendered() && !node.isDisabled())
- processLayer(context, node, width);
- }
- }
-
- public void processLayer(FacesContext context, UIComponent layer, String width) throws IOException {
- String clientId = layer.getClientId(context);
-
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.DIV_ELEM, layer);
- writer.writeAttribute(HTML.id_ATTRIBUTE, clientId+"_menu", null);
- processLayerStyles(context, layer, writer);
- writer.startElement(HTML.DIV_ELEM, layer);
- writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-bg", null);
- encodeItems(context, layer);
-
- writer.startElement(HTML.DIV_ELEM, layer);
- writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-strut", null);
- writer.startElement(HTML.DIV_ELEM, layer);
- writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-strut", null);
- writer.writeAttribute(HTML.style_ATTRIBUTE, width!=null && width.length() > 0 ? "width: " + HtmlUtil.qualifySize(width) : "", null);
- writer.write(" ");
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.DIV_ELEM);
-
- writer.endElement(HTML.DIV_ELEM);
- writer.endElement(HTML.DIV_ELEM);
-
- writer.startElement(HTML.SCRIPT_ELEM, layer);
- writer.writeAttribute(HTML.id_ATTRIBUTE, clientId+"_menu_script", null);
- writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
- encodeScript(context, layer);
- writer.endElement(HTML.SCRIPT_ELEM);
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
- Set renderedAreas = ajaxContext.getAjaxRenderedAreas();
- renderedAreas.add(clientId + "_menu_script");
- }
-
- public void encodeItems(FacesContext context, UIComponent component) throws IOException {
- List kids = component.getChildren();
- Iterator it = kids.iterator();
- while (it.hasNext()) {
- UIComponent kid = (UIComponent)it.next();
- if (kid instanceof UIMenuGroup || kid instanceof UIMenuItem || kid instanceof UIMenuSeparator) {
- renderChild(context, kid);
- }
- }
- }
-
- private void flatten(List kids, List flatList){
- if(kids != null){
- for (Iterator iter = kids.iterator(); iter.hasNext();) {
- UIComponent kid = (UIComponent) iter.next();
- if (kid instanceof UIMenuGroup) {
- UIMenuGroup node = (UIMenuGroup) kid;
- flatList.add(node);
- flatten(node.getChildren(), flatList);
- }
- }
- }
- }
-
- protected abstract void processLayerStyles(FacesContext context, UIComponent layer, ResponseWriter writer) throws IOException;
-
+
+ private final InternetResource[] scripts = {
+ new org.ajax4jsf.javascript.PrototypeScript(),
+ new org.ajax4jsf.javascript.AjaxScript(),
+ getResource("scripts/menu.js") };
+
+ @Override
+ protected InternetResource[] getScripts() {
+ return scripts;
+ }
+
+ @Override
+ protected InternetResource[] getStyles() {
+ return super.getStyles();
+ }
+
+ public void encodeScript(FacesContext context, UIComponent component)
+ throws IOException {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("alert('Hello Cfif!!!');").append(
+ getLayerScript(context, component));
+
+ List children = component.getChildren();
+ for (Iterator it = children.iterator(); it.hasNext();) {
+ buffer.append(getItemScript(context, (UIComponent) it.next()));
+ }
+
+ ResponseWriter out = context.getResponseWriter();
+ String script = buffer.append(";").toString();
+ out.write(script);
+ }
+
+ protected abstract String getLayerScript(FacesContext context,
+ UIComponent layer);
+
+ protected String getItemScript(FacesContext context, UIComponent kid) {
+ String itemId = null;
+ boolean closeOnClick = true;
+ Integer flagGroup = null;
+ boolean disabled = false;
+ if (kid instanceof UIMenuItem) {
+ UIMenuItem menuItem = (UIMenuItem) kid;
+ itemId = kid.getClientId(context);
+ disabled = menuItem.isDisabled();
+ if (disabled) {
+ closeOnClick = false;
+ }
+ } else if (kid instanceof UIMenuGroup) {
+ UIMenuGroup menuGroup = (UIMenuGroup) kid;
+ itemId = kid.getClientId(context);
+ closeOnClick = false;
+ if ((disabled = menuGroup.isDisabled())) {
+ flagGroup = Integer.valueOf(2);
+ } else {
+ flagGroup = Integer.valueOf(1);
+ }
+ }
+ if (itemId != null) {
+ JSFunction function = new JSFunction(".addItem");
+ function.addParameter(itemId);
+ ScriptOptions options = new ScriptOptions(kid);
+
+ options.addEventHandler("onmouseout");
+ options.addEventHandler("onmouseover");
+
+ if (closeOnClick) {
+ options.addOption("closeOnClick", Boolean.TRUE);
+ }
+ options.addOption("flagGroup", flagGroup);
+
+ options.addOption("styleClass");
+ options.addOption("style");
+ options.addOption("itemClass");
+ options.addOption("itemStyle");
+ options.addOption("disabledItemClass");
+ options.addOption("disabledItemStyle");
+ options.addOption("selectItemClass");
+ options.addOption("labelClass");
+ options.addOption("selectedLabelClass");
+ options.addOption("disabledLabelClass");
+
+ options.addOption("selectClass");
+ options.addOption("selectStyle");
+ options.addOption("iconClass");
+
+ if (disabled) {
+ options.addOption("disabled", Boolean.TRUE);
+ }
+
+ options.addEventHandler("onselect");
+
+ function.addParameter(options);
+ return function.toScript();
+ }
+ return "";
+ }
+
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ public void encodeChildren(FacesContext context, UIComponent component)
+ throws IOException {
+ List flatListOfNodes = new LinkedList();
+ String width = (String) component.getAttributes().get("popupWidth");
+
+ flatten(component.getChildren(), flatListOfNodes);
+ processLayer(context, component, width);
+
+ for (Iterator iter = flatListOfNodes.iterator(); iter.hasNext();) {
+ UIMenuGroup node = (UIMenuGroup) iter.next();
+ if (node.isRendered() && !node.isDisabled())
+ processLayer(context, node, width);
+ }
+ }
+
+ public void processLayer(FacesContext context, UIComponent layer,
+ String width) throws IOException {
+ String clientId = layer.getClientId(context);
+
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, layer);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, clientId + "_menu", null);
+ processLayerStyles(context, layer, writer);
+ writer.startElement(HTML.DIV_ELEM, layer);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-bg", null);
+ encodeItems(context, layer);
+
+ writer.startElement(HTML.DIV_ELEM, layer);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-strut",
+ null);
+ writer.startElement(HTML.DIV_ELEM, layer);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, "rich-menu-list-strut",
+ null);
+ writer.writeAttribute(HTML.style_ATTRIBUTE, width != null
+ && width.length() > 0 ? "width: " + HtmlUtil.qualifySize(width)
+ : "", null);
+ writer.write(" ");
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+
+ writer.startElement(HTML.SCRIPT_ELEM, layer);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, clientId + "_menu_script",
+ null);
+ writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+ encodeScript(context, layer);
+ writer.endElement(HTML.SCRIPT_ELEM);
+ }
+
+ public void encodeItems(FacesContext context, UIComponent component)
+ throws IOException {
+ List<UIComponent> kids = component.getChildren();
+ Iterator<UIComponent> it = kids.iterator();
+ while (it.hasNext()) {
+ UIComponent kid = (UIComponent) it.next();
+ if (kid instanceof UIMenuGroup || kid instanceof UIMenuItem
+ || kid instanceof UIMenuSeparator) {
+ renderChild(context, kid);
+ }
+ }
+ }
+
+ private void flatten(List kids, List flatList) {
+ if (kids != null) {
+ for (Iterator iter = kids.iterator(); iter.hasNext();) {
+ UIComponent kid = (UIComponent) iter.next();
+ if (kid instanceof UIMenuGroup) {
+ UIMenuGroup node = (UIMenuGroup) kid;
+ flatList.add(node);
+ flatten(node.getChildren(), flatList);
+ }
+ }
+ }
+ }
+
+ protected abstract void processLayerStyles(FacesContext context,
+ UIComponent layer, ResponseWriter writer) throws IOException;
+
}
15 years, 7 months
JBoss Rich Faces SVN: r14464 - in branches/community/3.3.X/ui/gmap/src: main/templates and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-06-03 13:53:34 -0400 (Wed, 03 Jun 2009)
New Revision: 14464
Modified:
branches/community/3.3.X/ui/gmap/src/main/resources/org/richfaces/renderkit/html/css/gmap.xcss
branches/community/3.3.X/ui/gmap/src/main/templates/gmap.jspx
branches/community/3.3.X/ui/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java
Log:
RF-7317
Modified: branches/community/3.3.X/ui/gmap/src/main/resources/org/richfaces/renderkit/html/css/gmap.xcss
===================================================================
--- branches/community/3.3.X/ui/gmap/src/main/resources/org/richfaces/renderkit/html/css/gmap.xcss 2009-06-03 17:47:22 UTC (rev 14463)
+++ branches/community/3.3.X/ui/gmap/src/main/resources/org/richfaces/renderkit/html/css/gmap.xcss 2009-06-03 17:53:34 UTC (rev 14464)
@@ -3,7 +3,7 @@
xmlns:u='http:/jsf.exadel.com/template/util'
xmlns="http://www.w3.org/1999/xhtml" >
<f:verbatim><![CDATA[
-.dr-gmap{
+.rich-gmap{
width:400px;
height:400px;
}
Modified: branches/community/3.3.X/ui/gmap/src/main/templates/gmap.jspx
===================================================================
--- branches/community/3.3.X/ui/gmap/src/main/templates/gmap.jspx 2009-06-03 17:47:22 UTC (rev 14463)
+++ branches/community/3.3.X/ui/gmap/src/main/templates/gmap.jspx 2009-06-03 17:53:34 UTC (rev 14464)
@@ -29,7 +29,7 @@
<h:styles>css/gmap.xcss</h:styles>
<h:scripts>new org.ajax4jsf.javascript.PrototypeScript(),script/gmap.js</h:scripts>
-<div id="#{clientId}" class="dr-gmap rich-gmap #{component.attributes['styleClass']}" x:passThruWithExclusions="id,class,styleClass">
+<div id="#{clientId}" class="rich-gmap #{component.attributes['styleClass']}" x:passThruWithExclusions="id,class,styleClass">
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=#{key}&hl=#{locale}" />
<script type="text/javascript">
Modified: branches/community/3.3.X/ui/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java
===================================================================
--- branches/community/3.3.X/ui/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java 2009-06-03 17:47:22 UTC (rev 14463)
+++ branches/community/3.3.X/ui/gmap/src/test/java/org/richfaces/component/GmapComponentTest.java 2009-06-03 17:53:34 UTC (rev 14464)
@@ -96,7 +96,6 @@
assertTrue("div".equals(htmlGmap.getTagName()));
assertEquals(htmlGmap.getAttributeValue("style"), TEST_STYLE);
- assertTrue(htmlGmap.getAttributeValue("class").contains("dr-gmap"));
assertTrue(htmlGmap.getAttributeValue("class").contains("rich-gmap"));
}
15 years, 7 months