Author: alexsmirnov
Date: 2008-09-30 17:41:52 -0400 (Tue, 30 Sep 2008)
New Revision: 10628
Added:
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/Queue.java
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueueImpl.java
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueuesManager.java
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java
Removed:
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java
Modified:
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/cache/ServletContextInitMap.java
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/css/CssCompressor.java
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
branches/jsf2.0/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
branches/jsf2.0/framework/impl/src/test/java/org/ajax4jsf/css/CssCompressorTest.java
Log:
marged changes from trunk rev 10627
Modified:
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java
===================================================================
---
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -51,8 +51,6 @@
*/
protected ViewHandler _handler;
- private boolean _initialized = false;
-
/**
* @param handler - to wrap.
*/
@@ -64,7 +62,6 @@
* @see
javax.faces.application.ViewHandler#calculateLocale(javax.faces.context.FacesContext)
*/
public Locale calculateLocale(FacesContext context) {
- fillChain(context);
return _handler.calculateLocale(context);
}
@@ -72,7 +69,6 @@
* @see
javax.faces.application.ViewHandler#calculateRenderKitId(javax.faces.context.FacesContext)
*/
public String calculateRenderKitId(FacesContext context) {
- fillChain(context);
return _handler.calculateRenderKitId(context);
}
@@ -80,7 +76,6 @@
* @see javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext,
java.lang.String)
*/
public UIViewRoot createView(FacesContext context, String viewId) {
- fillChain(context);
return _handler.createView(context, viewId);
}
@@ -88,7 +83,6 @@
* @see
javax.faces.application.ViewHandler#getActionURL(javax.faces.context.FacesContext,
java.lang.String)
*/
public String getActionURL(FacesContext context, String url) {
- fillChain(context);
return _handler.getActionURL(context, url);
}
@@ -96,7 +90,6 @@
* @see
javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext,
java.lang.String)
*/
public String getResourceURL(FacesContext context, String url) {
- fillChain(context);
return _handler.getResourceURL(context, url);
}
@@ -104,7 +97,6 @@
* @see javax.faces.application.ViewHandler#renderView(javax.faces.context.FacesContext,
javax.faces.component.UIViewRoot)
*/
public void renderView(FacesContext context, UIViewRoot root) throws IOException,
FacesException {
- fillChain(context);
_handler.renderView(context, root);
}
@@ -112,7 +104,6 @@
* @see
javax.faces.application.ViewHandler#restoreView(javax.faces.context.FacesContext,
java.lang.String)
*/
public UIViewRoot restoreView(FacesContext context, String viewId) {
- fillChain(context);
return _handler.restoreView(context, viewId);
}
@@ -120,7 +111,6 @@
* @see
javax.faces.application.ViewHandler#writeState(javax.faces.context.FacesContext)
*/
public void writeState(FacesContext context) throws IOException {
- fillChain(context);
_handler.writeState(context);
}
@@ -143,38 +133,37 @@
return _handler.calculateCharacterEncoding(context);
}
/**
- * Fill view-handlers chain for alternate handlers.
+ * <p>Fill view-handlers chain for alternate handlers.</p>
+ * <p><em>NOTE:</em> Calls to this method should be synchronized
externally since 3.3.0 version</p>
+ *
* @param context
*/
- synchronized protected void fillChain( FacesContext context){
- if(!_initialized){
- _initialized = true;
- String handlers = context.getExternalContext().getInitParameter(HANDLERS);
- if(null != handlers){
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- String[] classes = handlers.split(",");
- for (int i = 0; i < classes.length; i++) {
- String handlerClass = classes[i];
- if (_log.isDebugEnabled()) {
- _log.debug(Messages.getMessage(Messages.CREATE_ALTERNATE_HANDLER, handlerClass));
- }
+ public void fillChain( FacesContext context){
+ String handlers = context.getExternalContext().getInitParameter(HANDLERS);
+ if(null != handlers){
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ String[] classes = handlers.split(",");
+ for (int i = 0; i < classes.length; i++) {
+ String handlerClass = classes[i];
+ if (_log.isDebugEnabled()) {
+ _log.debug(Messages.getMessage(Messages.CREATE_ALTERNATE_HANDLER, handlerClass));
+ }
+ try {
+ Class<?> clazz = classLoader.loadClass(handlerClass);
try {
- Class<?> clazz = classLoader.loadClass(handlerClass);
- try {
- Constructor<?> constructor = clazz
- .getConstructor(new Class[] { ViewHandler.class });
- _handler = (ViewHandler) constructor
- .newInstance(new Object[] { _handler });
- } catch (NoSuchMethodException e) {
- // No constructor with parent class - create simple instance
- if (_log.isWarnEnabled()) {
- _log.warn(Messages.getMessage(Messages.ALTERNATE_HANDLER_CONSTRUCTOR_WARNING));
- }
- _handler = (ViewHandler) clazz.newInstance();
+ Constructor<?> constructor = clazz
+ .getConstructor(new Class[] { ViewHandler.class });
+ _handler = (ViewHandler) constructor
+ .newInstance(new Object[] { _handler });
+ } catch (NoSuchMethodException e) {
+ // No constructor with parent class - create simple instance
+ if (_log.isWarnEnabled()) {
+ _log.warn(Messages.getMessage(Messages.ALTERNATE_HANDLER_CONSTRUCTOR_WARNING));
}
- } catch (Exception e) {
- _log.error(Messages.getMessage(Messages.VIEW_HANDLER_INSTANTIATION_ERROR), e);
+ _handler = (ViewHandler) clazz.newInstance();
}
+ } catch (Exception e) {
+ _log.error(Messages.getMessage(Messages.VIEW_HANDLER_INSTANTIATION_ERROR), e);
}
}
}
Modified:
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
===================================================================
---
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -22,6 +22,7 @@
package org.ajax4jsf.javascript;
import java.beans.PropertyDescriptor;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
@@ -161,4 +162,56 @@
}
}
}
+
+ public static String getValidJavascriptName(String s) {
+
+ StringBuffer buf = null;
+ for (int i = 0, len = s.length(); i < len; i++) {
+ char c = s.charAt(i);
+
+ if (Character.isLetterOrDigit(c)||c=='_' ) {
+ // allowed char
+ if (buf != null)
+ buf.append(c);
+ } else {
+ if (buf == null) {
+ buf = new StringBuffer(s.length() + 10);
+ buf.append(s.substring(0, i));
+ }
+
+ buf.append('_');
+ if (c < 16) {
+ // pad single hex digit values with '0' on the left
+ buf.append('0');
+ }
+
+ if (c < 128) {
+ // first 128 chars match their byte representation in UTF-8
+ buf.append(Integer.toHexString(c).toUpperCase());
+ } else {
+ byte[] bytes;
+ try {
+ bytes = Character.toString(c).getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+
+ for (int j = 0; j < bytes.length; j++) {
+ int intVal = bytes[j];
+ if (intVal < 0) {
+ // intVal will be >= 128
+ intVal = 256 + intVal;
+ } else if (intVal < 16) {
+ // pad single hex digit values with '0' on the left
+ buf.append('0');
+ }
+ buf.append(Integer.toHexString(intVal).toUpperCase());
+ }
+ }
+ }
+
+ }
+
+ return buf == null ? s : buf.toString();
+ }
}
Copied: branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/Queue.java (from
rev 10627, trunk/framework/api/src/main/java/org/ajax4jsf/model/Queue.java)
===================================================================
--- branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/Queue.java
(rev 0)
+++ branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/Queue.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -0,0 +1,21 @@
+/**
+ *
+ */
+package org.ajax4jsf.model;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public interface Queue {
+
+ String getName();
+
+ Integer getRequestDelay();
+
+ Integer getTimeout();
+
+ Boolean getLimitToList();
+
+ Boolean getIgnoreDupResponses();
+}
Copied: branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueueImpl.java
(from rev 10627, trunk/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java)
===================================================================
--- branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueueImpl.java
(rev 0)
+++
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueueImpl.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -0,0 +1,96 @@
+package org.ajax4jsf.model;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class QueueImpl implements Queue {
+
+ private FacesContext context;
+
+ private ValueExpression nameExpression;
+
+ private ValueExpression requestDelayExpression;
+
+ private ValueExpression timeoutExpression;
+
+ private ValueExpression ignoreDupResponsesExpression;
+
+ private ValueExpression limitToListExpression;
+
+ public QueueImpl() {
+ this(null);
+ }
+
+ public QueueImpl(FacesContext context) {
+ if(context == null) {
+ this.context = FacesContext.getCurrentInstance();
+ } else {
+ this.context = context;
+ }
+ }
+
+ public String getName() {
+ String name = null;
+ if (nameExpression != null) {
+ name = (String) nameExpression.getValue(context.getELContext());
+ }
+ return name;
+ }
+
+ public Integer getRequestDelay() {
+ Integer requestDelay = null;
+ if (requestDelayExpression != null) {
+ requestDelay = (Integer) requestDelayExpression.getValue(context.getELContext());
+ }
+ return requestDelay;
+ }
+
+ public Integer getTimeout() {
+ Integer timeout = null;
+ if (timeoutExpression != null) {
+ timeout = (Integer) timeoutExpression.getValue(context.getELContext());
+ }
+ return timeout;
+ }
+
+ public Boolean getIgnoreDupResponses() {
+ Boolean ignoreDupResponses = null;
+ if (ignoreDupResponsesExpression != null) {
+ ignoreDupResponses = (Boolean)
ignoreDupResponsesExpression.getValue(context.getELContext());
+ }
+ return ignoreDupResponses;
+ }
+
+ public Boolean getLimitToList() {
+ Boolean limitToList = null;
+ if (limitToListExpression != null) {
+ limitToList = (Boolean) limitToListExpression.getValue(context.getELContext());
+ }
+ return limitToList;
+ }
+
+ public void setNameExpression(ValueExpression nameExpression) {
+ this.nameExpression = nameExpression;
+ }
+
+ public void setRequestDelayExpression(ValueExpression requestDelayExpression) {
+ this.requestDelayExpression = requestDelayExpression;
+ }
+
+ public void setTimeoutExpression(ValueExpression timeoutExpression) {
+ this.timeoutExpression = timeoutExpression;
+ }
+
+ public void setIgnoreDupResponsesExpression(
+ ValueExpression ignoreDupResponsesExpression) {
+ this.ignoreDupResponsesExpression = ignoreDupResponsesExpression;
+ }
+
+ public void setLimitToListExpression(ValueExpression limitToListExpression) {
+ this.limitToListExpression = limitToListExpression;
+ }
+}
Copied: branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueuesManager.java
(from rev 10627, trunk/framework/api/src/main/java/org/ajax4jsf/model/QueuesManager.java)
===================================================================
--- branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueuesManager.java
(rev 0)
+++
branches/jsf2.0/framework/api/src/main/java/org/ajax4jsf/model/QueuesManager.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -0,0 +1,56 @@
+package org.ajax4jsf.model;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class QueuesManager {
+
+ static private final String MAP_KEY_PREFIX = QueuesManager.class.getSimpleName();
+
+ static public void put(Queue queue, FacesContext context) throws
IllegalArgumentException{
+ if (context == null) {
+ context = FacesContext.getCurrentInstance();
+ }
+ String name = queue.getName();
+ String key = MAP_KEY_PREFIX + name;
+ Map<String, Object> attributes = context.getViewRoot().getAttributes();
+ if (!attributes.containsKey(key)) {
+ attributes.put(key, queue);
+ } else {
+ throw new IllegalArgumentException("Queue whis name '" + name +
"' has already been used");
+ }
+ }
+
+ static public void put(Queue queue) throws IllegalArgumentException {
+ put(queue, null);
+ }
+
+ static public Queue get(String name, FacesContext context) {
+ if (context == null) {
+ context = FacesContext.getCurrentInstance();
+ }
+ Object object = context.getViewRoot().getAttributes().get(MAP_KEY_PREFIX + name);
+ return (Queue)object;
+ }
+
+ static public Queue get(String name) {
+ return get(name, null);
+ }
+
+ static public Queue remove(String name, FacesContext context) {
+ if (context == null) {
+ context = FacesContext.getCurrentInstance();
+ }
+ Object object = context.getViewRoot().getAttributes().remove(MAP_KEY_PREFIX + name);
+ return (Queue)object;
+ }
+
+ static public Queue remove(String name) {
+ return remove(name, null);
+ }
+}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/cache/ServletContextInitMap.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/cache/ServletContextInitMap.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/cache/ServletContextInitMap.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -64,7 +64,7 @@
}
public void remove() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("This map is read-only");
}
};
@@ -75,6 +75,7 @@
int result = 0;
Enumeration<String> initNames = servletContext.getInitParameterNames();
while (initNames.hasMoreElements()) {
+ initNames.nextElement();
result++;
}
@@ -86,7 +87,19 @@
}
};
}
+
+ public String remove(Object key) {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+ public String put(String key, String value) {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
+ public void putAll(Map<? extends String, ? extends String> m) {
+ throw new UnsupportedOperationException("This map is read-only");
+ }
+
}
class ServletContextInitMapEntry<K, V> implements Map.Entry<K, V> {
@@ -100,11 +113,6 @@
this.value = value;
}
- public ServletContextInitMapEntry(K key) {
- super();
- this.key = key;
- }
-
public K getKey() {
return key;
}
@@ -114,9 +122,7 @@
}
public V setValue(V value) {
- V oldValue = this.value;
- this.value = value;
- return oldValue;
+ throw new UnsupportedOperationException("This map is read-only");
}
}
\ No newline at end of file
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/css/CssCompressor.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/css/CssCompressor.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/css/CssCompressor.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -15,142 +15,180 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.ajax4jsf.resource.CountingOutputWriter;
-
public class CssCompressor {
- private StringBuffer srcsb = null;
+ private StringBuffer srcsb = null;
- public CssCompressor(StringBuffer buffer) throws IOException {
- srcsb = buffer;
- }
+ public CssCompressor(StringBuffer buffer) throws IOException {
+ srcsb = buffer;
+ }
- public int compress(Writer out, int linebreakpos)
- throws IOException {
-
- Pattern p;
- Matcher m;
- String css;
- StringBuffer sb;
- int startIndex, endIndex;
- int bytesLength;
+ public int compress(Writer out, int linebreakpos) throws IOException {
- // Remove all comment blocks...
- sb = new StringBuffer(srcsb.toString());
- while ((startIndex = sb.indexOf("/*")) >= 0) {
- endIndex = sb.indexOf("*/", startIndex + 2);
- if (endIndex >= startIndex + 2)
- sb.delete(startIndex, endIndex + 2);
- }
+ Pattern p;
+ Matcher m;
+ String css;
+ StringBuffer sb;
+ int startIndex, endIndex;
- css = sb.toString();
+ // Remove all comment blocks...
+ startIndex = 0;
+ boolean iemac = false;
+ boolean preserve = false;
+ sb = new StringBuffer(srcsb.toString());
+ while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
+ preserve = sb.length() > startIndex + 2
+ && sb.charAt(startIndex + 2) == '!';
+ endIndex = sb.indexOf("*/", startIndex + 2);
+ if (endIndex < 0) {
+ if (!preserve) {
+ sb.delete(startIndex, sb.length());
+ }
+ } else if (endIndex >= startIndex + 2) {
+ if (sb.charAt(endIndex - 1) == '\\') {
+ // Looks like a comment to hide rules from IE Mac.
+ // Leave this comment, and the following one, alone...
+ startIndex = endIndex + 2;
+ iemac = true;
+ } else if (iemac) {
+ startIndex = endIndex + 2;
+ iemac = false;
+ } else if (!preserve) {
+ sb.delete(startIndex, endIndex + 2);
+ } else {
+ startIndex = endIndex + 2;
+ }
+ }
+ }
- // Normalize all whitespace strings to single spaces. Easier to work with that
way.
- css = css.replaceAll("\\s+", " ");
+ css = sb.toString();
- // Remove the spaces before the things that should not have spaces before them.
- // But, be careful not to turn "p :link {...}" into
"p:link{...}"
- // Swap out any pseudo-class colons with the token, and then swap back.
- sb = new StringBuffer();
- p = Pattern.compile("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
- m = p.matcher(css);
- while (m.find()) {
- String s = m.group();
- s = s.replaceAll(":", "___PSEUDOCLASSCOLON___");
- m.appendReplacement(sb, s);
- }
- m.appendTail(sb);
- css = sb.toString();
- css = css.replaceAll("\\s+([!{};:>+\\(\\)\\],])", "$1");
- css = css.replaceAll("___PSEUDOCLASSCOLON___", ":");
+ // Normalize all whitespace strings to single spaces. Easier to work
+ // with that way.
+ css = css.replaceAll("\\s+", " ");
- // Remove the spaces after the things that should not have spaces after them.
- css = css.replaceAll("([!{}:;>+\\(\\[,])\\s+", "$1");
+ // Make a pseudo class for the Box Model Hack
+ css = css.replaceAll("\"\\\\\"}\\\\\"\"",
"___PSEUDOCLASSBMH___");
- // Add the semicolon where it's missing.
- css = css.replaceAll("([^;\\}])}", "$1;}");
+ // Remove the spaces before the things that should not have spaces
+ // before them.
+ // But, be careful not to turn "p :link {...}" into "p:link{...}"
+ // Swap out any pseudo-class colons with the token, and then swap back.
+ sb = new StringBuffer();
+ p = Pattern.compile("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
+ m = p.matcher(css);
+ while (m.find()) {
+ String s = m.group();
+ s = s.replaceAll(":", "___PSEUDOCLASSCOLON___");
+ m.appendReplacement(sb, s);
+ }
+ m.appendTail(sb);
+ css = sb.toString();
+ css = css.replaceAll("\\s+([!{};:>+\\(\\)\\],])", "$1");
+ css = css.replaceAll("___PSEUDOCLASSCOLON___", ":");
- // Replace 0(px,em,%) with 0.
- css = css.replaceAll("([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)",
"$1$2");
+ // Remove the spaces after the things that should not have spaces after
+ // them.
+ css = css.replaceAll("([!{}:;>+\\(\\[,])\\s+", "$1");
- // Replace 0 0 0 0; with 0.
- css = css.replaceAll(":0 0 0 0;", ":0;");
- css = css.replaceAll(":0 0 0;", ":0;");
- css = css.replaceAll(":0 0;", ":0;");
- // Replace background-position:0; with background-position:0 0;
- css = css.replaceAll("background-position:0;",
"background-position:0 0;");
+ // Add the semicolon where it's missing.
+ css = css.replaceAll("([^;\\}])}", "$1;}");
- // Replace 0.6 to .6, but only when preceded by : or a white-space
- css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");
+ // Replace 0(px,em,%) with 0.
+ css = css.replaceAll("([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)",
"$1$2");
- // Shorten colors from rgb(51,102,153) to #336699
- // This makes it more likely that it'll get further compressed in the next
step.
- p = Pattern.compile("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
- m = p.matcher(css);
- sb = new StringBuffer();
- while (m.find()) {
- String[] rgbcolors = m.group(1).split(",");
- StringBuffer hexcolor = new StringBuffer("#");
- for (int i = 0; i < rgbcolors.length; i++) {
- int val = Integer.parseInt(rgbcolors[i]);
- if (val < 16) {
- hexcolor.append("0");
- }
- hexcolor.append(Integer.toHexString(val));
- }
- m.appendReplacement(sb, hexcolor.toString());
- }
- m.appendTail(sb);
- css = sb.toString();
+ // Replace 0 0 0 0; with 0.
+ css = css.replaceAll(":0 0 0 0;", ":0;");
+ css = css.replaceAll(":0 0 0;", ":0;");
+ css = css.replaceAll(":0 0;", ":0;");
+ // Replace background-position:0; with background-position:0 0;
+ css = css.replaceAll("background-position:0;",
+ "background-position:0 0;");
- // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
- // the color is not preceded by either ", " or =. Indeed, the property
- // filter: chroma(color="#FFFFFF");
- // would become
- // filter: chroma(color="#FFF");
- // which makes the filter break in IE.
- p =
Pattern.compile("([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
- m = p.matcher(css);
- sb = new StringBuffer();
- while (m.find()) {
- // Test for AABBCC pattern
- if (m.group(3).equalsIgnoreCase(m.group(4)) &&
- m.group(5).equalsIgnoreCase(m.group(6)) &&
- m.group(7).equalsIgnoreCase(m.group(8))) {
- m.appendReplacement(sb, m.group(1) + m.group(2) + "#" +
m.group(3) + m.group(5) + m.group(7));
- } else {
- m.appendReplacement(sb, m.group());
- }
- }
- m.appendTail(sb);
- css = sb.toString();
+ // Replace 0.6 to .6, but only when preceded by : or a white-space
+ css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");
- // Remove empty rules.
- css = css.replaceAll("[^\\}]+\\{;\\}", "");
+ // Shorten colors from rgb(51,102,153) to #336699
+ // This makes it more likely that it'll get further compressed in the
+ // next step.
+ p = Pattern.compile("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
+ m = p.matcher(css);
+ sb = new StringBuffer();
+ while (m.find()) {
+ String[] rgbcolors = m.group(1).split(",");
+ StringBuffer hexcolor = new StringBuffer("#");
+ for (int i = 0; i < rgbcolors.length; i++) {
+ int val = Integer.parseInt(rgbcolors[i]);
+ if (val < 16) {
+ hexcolor.append("0");
+ }
+ hexcolor.append(Integer.toHexString(val));
+ }
+ m.appendReplacement(sb, hexcolor.toString());
+ }
+ m.appendTail(sb);
+ css = sb.toString();
- if (linebreakpos >= 0) {
- // Some source control tools don't like it when files containing lines
longer
- // than, say 8000 characters, are checked in. The linebreak option is used
in
- // that case to split long lines after a specific column.
- int i = 0;
- int linestartpos = 0;
- sb = new StringBuffer(css);
- while (i < sb.length()) {
- char c = sb.charAt(i++);
- if (c == '}' && i - linestartpos > linebreakpos) {
- sb.insert(i, '\n');
- linestartpos = i;
- }
- }
+ // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
+ // the color is not preceded by either ", " or =. Indeed, the property
+ // filter: chroma(color="#FFFFFF");
+ // would become
+ // filter: chroma(color="#FFF");
+ // which makes the filter break in IE.
+ p = Pattern
+ .compile("([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
+ m = p.matcher(css);
+ sb = new StringBuffer();
+ while (m.find()) {
+ // Test for AABBCC pattern
+ if (m.group(3).equalsIgnoreCase(m.group(4))
+ && m.group(5).equalsIgnoreCase(m.group(6))
+ && m.group(7).equalsIgnoreCase(m.group(8))) {
+ m.appendReplacement(sb, m.group(1) + m.group(2) + "#"
+ + m.group(3) + m.group(5) + m.group(7));
+ } else {
+ m.appendReplacement(sb, m.group());
+ }
+ }
+ m.appendTail(sb);
+ css = sb.toString();
- css = sb.toString();
- }
+ // Remove empty rules.
+ css = css.replaceAll("[^\\}]+\\{;\\}", "");
- // Trim the final string (for any leading or trailing white spaces)
- css = css.trim();
- bytesLength = css.length(); // * CountingOutputWriter.sizeOfChar;
- // Write the output...
- out.write(css);
- return bytesLength;
- }
+ if (linebreakpos >= 0) {
+ // Some source control tools don't like it when files containing
+ // lines longer
+ // than, say 8000 characters, are checked in. The linebreak option
+ // is used in
+ // that case to split long lines after a specific column.
+ int i = 0;
+ int linestartpos = 0;
+ sb = new StringBuffer(css);
+ while (i < sb.length()) {
+ char c = sb.charAt(i++);
+ if (c == '}' && i - linestartpos > linebreakpos) {
+ sb.insert(i, '\n');
+ linestartpos = i;
+ }
+ }
+
+ css = sb.toString();
+ }
+
+ // Replace the pseudo class for the Box Model Hack
+ css = css.replaceAll("___PSEUDOCLASSBMH___",
"\"\\\\\"}\\\\\"\"");
+
+ // Replace multiple semi-colons in a row by a single one
+ // See SF bug #1980989
+ css = css.replaceAll(";;+", ";");
+
+ // Trim the final string (for any leading or trailing white spaces)
+ css = css.trim();
+
+ // Write the output...
+ out.write(css);
+
+ return css.length();
+ }
}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -80,11 +80,18 @@
FacesContext facesContext = event.getFacesContext();
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
+
if (!(viewHandler instanceof AjaxViewHandler)) {
if(log.isDebugEnabled()){
log.debug("Set AjaxViewHandler on top of chain");
}
- application.setViewHandler(new AjaxViewHandler(viewHandler));
+
+ AjaxViewHandler ajaxViewHandler = new AjaxViewHandler(viewHandler);
+ ajaxViewHandler.fillChain(facesContext);
+
+ application.setViewHandler(ajaxViewHandler);
+ } else {
+ ((AjaxViewHandler) viewHandler).fillChain(facesContext);
}
initialized = true;
}
Copied: branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model (from rev 10627,
trunk/framework/impl/src/main/java/org/ajax4jsf/model)
Deleted: branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -1,96 +0,0 @@
-package org.ajax4jsf.model;
-
-import javax.el.ValueExpression;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Konstantin Mishin
- *
- */
-public class QueueImpl implements Queue {
-
- private FacesContext context;
-
- private ValueExpression nameExpression;
-
- private ValueExpression requestDelayExpression;
-
- private ValueExpression timeoutExpression;
-
- private ValueExpression ignoreDupResponsesExpression;
-
- private ValueExpression limitToListExpression;
-
- public QueueImpl() {
- this(null);
- }
-
- public QueueImpl(FacesContext context) {
- if(context == null) {
- this.context = FacesContext.getCurrentInstance();
- } else {
- this.context = context;
- }
- }
-
- public String getName() {
- String name = null;
- if (nameExpression != null) {
- name = (String) nameExpression.getValue(context.getELContext());
- }
- return name;
- }
-
- public Integer getRequestDelay() {
- Integer requestDelay = null;
- if (requestDelayExpression != null) {
- requestDelay = (Integer) requestDelayExpression.getValue(context.getELContext());
- }
- return requestDelay;
- }
-
- public Integer getTimeout() {
- Integer timeout = null;
- if (timeoutExpression != null) {
- timeout = (Integer) timeoutExpression.getValue(context.getELContext());
- }
- return timeout;
- }
-
- public Boolean getIgnoreDupResponses() {
- Boolean ignoreDupResponses = null;
- if (ignoreDupResponsesExpression != null) {
- ignoreDupResponses = (Boolean)
ignoreDupResponsesExpression.getValue(context.getELContext());
- }
- return ignoreDupResponses;
- }
-
- public Boolean getLimitToList() {
- Boolean limitToList = null;
- if (limitToListExpression != null) {
- limitToList = (Boolean) limitToListExpression.getValue(context.getELContext());
- }
- return limitToList;
- }
-
- public void setNameExpression(ValueExpression nameExpression) {
- this.nameExpression = nameExpression;
- }
-
- public void setRequestDelayExpression(ValueExpression requestDelayExpression) {
- this.requestDelayExpression = requestDelayExpression;
- }
-
- public void setTimeoutExpression(ValueExpression timeoutExpression) {
- this.timeoutExpression = timeoutExpression;
- }
-
- public void setIgnoreDupResponsesExpression(
- ValueExpression ignoreDupResponsesExpression) {
- this.ignoreDupResponsesExpression = ignoreDupResponsesExpression;
- }
-
- public void setLimitToListExpression(ValueExpression limitToListExpression) {
- this.limitToListExpression = limitToListExpression;
- }
-}
Copied: branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java
(from rev 10627, trunk/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java)
===================================================================
--- branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java
(rev 0)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/model/QueueImpl.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -0,0 +1,96 @@
+package org.ajax4jsf.model;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class QueueImpl implements Queue {
+
+ private FacesContext context;
+
+ private ValueExpression nameExpression;
+
+ private ValueExpression requestDelayExpression;
+
+ private ValueExpression timeoutExpression;
+
+ private ValueExpression ignoreDupResponsesExpression;
+
+ private ValueExpression limitToListExpression;
+
+ public QueueImpl() {
+ this(null);
+ }
+
+ public QueueImpl(FacesContext context) {
+ if(context == null) {
+ this.context = FacesContext.getCurrentInstance();
+ } else {
+ this.context = context;
+ }
+ }
+
+ public String getName() {
+ String name = null;
+ if (nameExpression != null) {
+ name = (String) nameExpression.getValue(context.getELContext());
+ }
+ return name;
+ }
+
+ public Integer getRequestDelay() {
+ Integer requestDelay = null;
+ if (requestDelayExpression != null) {
+ requestDelay = (Integer) requestDelayExpression.getValue(context.getELContext());
+ }
+ return requestDelay;
+ }
+
+ public Integer getTimeout() {
+ Integer timeout = null;
+ if (timeoutExpression != null) {
+ timeout = (Integer) timeoutExpression.getValue(context.getELContext());
+ }
+ return timeout;
+ }
+
+ public Boolean getIgnoreDupResponses() {
+ Boolean ignoreDupResponses = null;
+ if (ignoreDupResponsesExpression != null) {
+ ignoreDupResponses = (Boolean)
ignoreDupResponsesExpression.getValue(context.getELContext());
+ }
+ return ignoreDupResponses;
+ }
+
+ public Boolean getLimitToList() {
+ Boolean limitToList = null;
+ if (limitToListExpression != null) {
+ limitToList = (Boolean) limitToListExpression.getValue(context.getELContext());
+ }
+ return limitToList;
+ }
+
+ public void setNameExpression(ValueExpression nameExpression) {
+ this.nameExpression = nameExpression;
+ }
+
+ public void setRequestDelayExpression(ValueExpression requestDelayExpression) {
+ this.requestDelayExpression = requestDelayExpression;
+ }
+
+ public void setTimeoutExpression(ValueExpression timeoutExpression) {
+ this.timeoutExpression = timeoutExpression;
+ }
+
+ public void setIgnoreDupResponsesExpression(
+ ValueExpression ignoreDupResponsesExpression) {
+ this.ignoreDupResponsesExpression = ignoreDupResponsesExpression;
+ }
+
+ public void setLimitToListExpression(ValueExpression limitToListExpression) {
+ this.limitToListExpression = limitToListExpression;
+ }
+}
Modified:
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
===================================================================
---
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -24,11 +24,13 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.regex.Pattern;
import javax.faces.application.ViewHandler;
import javax.servlet.Filter;
@@ -38,7 +40,6 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import javax.servlet.ServletResponseWrapper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
@@ -201,6 +202,41 @@
}
}
+ private static final Pattern AMPERSAND = Pattern.compile("&+");
+
+ private Map<String, String> parseQueryString(String queryString) {
+ if (queryString != null) {
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ String[] nvPairs = AMPERSAND.split(queryString);
+ for (String nvPair : nvPairs) {
+ if (nvPair.length() == 0) {
+ continue;
+ }
+
+ int eqIdx = nvPair.indexOf('=');
+ if (eqIdx >= 0) {
+ try {
+ String name = URLDecoder.decode(nvPair.substring(0, eqIdx), "UTF-8");
+ if (!parameters.containsKey(name)) {
+ String value = URLDecoder.decode(nvPair.substring(eqIdx + 1), "UTF-8");
+
+ parameters.put(name, value);
+ }
+ } catch (UnsupportedEncodingException e) {
+ //log warning and skip this parameter
+ log.warn(e.getLocalizedMessage(), e);
+ }
+ }
+ }
+
+ return parameters;
+ } else {
+
+ return Collections.EMPTY_MAP;
+ }
+ }
+
private boolean isMultipartRequest(HttpServletRequest request) {
if (!"post".equals(request.getMethod().toLowerCase())) {
return false;
@@ -225,19 +261,23 @@
return false;
}
- private boolean checkFileCount(HttpServletRequest request) {
- HttpSession session = request.getSession();
- Map<String, Integer> map = (Map<String, Integer>) session
- .getAttribute(UPLOADED_COUNTER);
- if (map != null) {
- String id = request.getParameter("id");
- if (id != null) {
- Integer i = map.get(id);
- if (i != null && i == 0) {
- return false;
+ private boolean checkFileCount(HttpServletRequest request, String idParameter) {
+ HttpSession session = request.getSession(false);
+
+ if (session != null) {
+ Map<String, Integer> map = (Map<String, Integer>)
session.getAttribute(UPLOADED_COUNTER);
+
+ if (map != null) {
+ String id = idParameter;
+ if (id != null) {
+ Integer i = map.get(id);
+ if (i != null && i == 0) {
+ return false;
+ }
}
}
}
+
return true;
}
@@ -292,94 +332,97 @@
* @throws ServletException
*/
protected void processUploadsAndHandleRequest(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- String uid = httpRequest.getParameter(UPLOAD_FILES_ID);
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+
+ Map<String, String> queryParamMap =
parseQueryString(httpRequest.getQueryString());
+ String uid = queryParamMap.get(UPLOAD_FILES_ID);
- if (uid != null) {
-
- if (isMultipartRequest(httpRequest)) {
- MultipartRequest multipartRequest = new MultipartRequest(httpRequest, createTempFiles,
maxRequestSize, uid);
- Map<String, MultipartRequest> sessionsMap = null;
- Map<String, Object> percentMap = null;
-
- try {
- if (isFileSizeRestricted(request, maxRequestSize)) {
-
- boolean sendError = Boolean.parseBoolean(request.getParameter(SEND_HTTP_ERROR));
- if (sendError) {
- response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
- System.err.println("ERROR " +
HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE + "request entity is larger than the
server is willing or able to process.");
- return;
+ if (uid != null) {
+
+ if (isMultipartRequest(httpRequest)) {
+ MultipartRequest multipartRequest = new MultipartRequest(httpRequest,
createTempFiles, maxRequestSize, uid);
+ Map<String, MultipartRequest> sessionsMap = null;
+ Map<String, Object> percentMap = null;
+
+ try {
+ if (isFileSizeRestricted(request, maxRequestSize)) {
+
+ boolean sendError = Boolean.parseBoolean(queryParamMap.get(SEND_HTTP_ERROR));
+ if (sendError) {
+ response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
+ System.err.println("ERROR " +
HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE + "request entity is larger than the
server is willing or able to process.");
+ return;
+ } else {
+ printResponse(response, "<html
id=\"_richfaces_file_upload_size_restricted\"></html>");
+ }
+
+ } else if (!checkFileCount(httpRequest, queryParamMap.get("id"))) {
+ printResponse(response, "<html
id=\"_richfaces_file_upload_forbidden\"></html>");
+ } else {
+
+ HttpSession session = httpRequest.getSession();
+ synchronized (session) {
+ sessionsMap = (Map<String, MultipartRequest>)
session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+ percentMap = (Map<String, Object>) session.getAttribute(PERCENT_BEAN_NAME);
+ if (sessionsMap == null) {
+ sessionsMap = Collections.synchronizedMap(new HashMap<String,
MultipartRequest>());
+ session.setAttribute(REQUESTS_SESSIONS_BEAN_NAME, sessionsMap);
+ }
+ if (percentMap == null) {
+ percentMap = new HashMap<String, Object>();
+ session.setAttribute(PERCENT_BEAN_NAME, percentMap);
+ }
+ }
+
+ /* associate percent value with file entry uid */
+ percentMap.put(uid, 0);
+ sessionsMap.put(uid, multipartRequest);
+
+ if (multipartRequest.parseRequest()) {
+ handleRequest(multipartRequest, multipartRequest.isFormUpload() ? response :
+ new HttpServletResponseWrapper(response){
+ @Override
+ public void setContentType(String type) {
+ super.setContentType(BaseXMLFilter.TEXT_HTML + ";charset=UTF-8");
+ }
+ }, chain);
+ } else {
+ printResponse(response, "<html
id=\"_richfaces_file_upload_stopped\"></html>");
+ }
+
+ }
+
+ } finally {
+
+ if (sessionsMap != null) {
+ sessionsMap.remove(uid);
+ percentMap.remove(uid);
+ }
+
+ }
} else {
- printResponse(response, "<html
id=\"_richfaces_file_upload_size_restricted\"></html>");
- }
-
- } else if (!checkFileCount(httpRequest)) {
- printResponse(response, "<html
id=\"_richfaces_file_upload_forbidden\"></html>");
- } else {
-
- HttpSession session = httpRequest.getSession();
- synchronized (session) {
- sessionsMap = (Map<String, MultipartRequest>)
session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
- percentMap = (Map<String, Object>) session.getAttribute(PERCENT_BEAN_NAME);
- if (sessionsMap == null) {
- sessionsMap = Collections.synchronizedMap(new HashMap<String,
MultipartRequest>());
- session.setAttribute(REQUESTS_SESSIONS_BEAN_NAME, sessionsMap);
- }
- if (percentMap == null) {
- percentMap = new HashMap<String, Object>();
- session.setAttribute(PERCENT_BEAN_NAME, percentMap);
- }
- }
-
- /* associate percent value with file entry uid */
- percentMap.put(uid, 0);
- sessionsMap.put(uid, multipartRequest);
-
- if (multipartRequest.parseRequest()) {
- handleRequest(multipartRequest, multipartRequest.isFormUpload() ? response :
- new HttpServletResponseWrapper(response){
- @Override
- public void setContentType(String type) {
- super.setContentType(BaseXMLFilter.TEXT_HTML + ";charset=UTF-8");
- }
- }, chain);
- } else {
- printResponse(response, "<html
id=\"_richfaces_file_upload_stopped\"></html>");
- }
-
- }
-
- } finally {
-
- if (sessionsMap != null) {
- sessionsMap.remove(uid);
- percentMap.remove(uid);
- }
-
- }
- } else {
-
- if
("richfaces_file_upload_action_stop".equals(httpRequest.getParameter("action")))
{
- HttpSession session = httpRequest.getSession();
- Map<String, MultipartRequest> sessions = (Map<String,
MultipartRequest>) session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
- if (sessions != null) {
- MultipartRequest multipartRequest = sessions.get(uid);
- if (multipartRequest != null) {
- multipartRequest.stop();
+ if
("richfaces_file_upload_action_stop".equals(queryParamMap.get("action")))
{
+ HttpSession session = httpRequest.getSession(false);
+ if (session != null) {
+ Map<String, MultipartRequest> sessions = (Map<String,
MultipartRequest>) session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+
+ if (sessions != null) {
+ MultipartRequest multipartRequest = sessions.get(uid);
+ if (multipartRequest != null) {
+ multipartRequest.stop();
+ }
+ handleRequest(request, response, chain);
+ }
+ }
+ } else {
+ handleRequest(request, response, chain);
+ }
}
+ } else {
handleRequest(request, response, chain);
- }
-
- } else {
- handleRequest(request, response, chain);
}
- }
- } else {
- handleRequest(request, response, chain);
}
- }
/**
* @param httpServletRequest
Modified: branches/jsf2.0/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- branches/jsf2.0/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-09-30
17:21:21 UTC (rev 10627)
+++ branches/jsf2.0/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-09-30
21:41:52 UTC (rev 10628)
@@ -552,6 +552,10 @@
this.onafterajax = onafterajax;
};
+A4J.AJAX.AjaxListener = function(type, callback){
+ this[type] = callback;
+};
+
A4J.AJAX._listeners= [];
A4J.AJAX.AddListener = function(listener){
A4J.AJAX._listeners.push(listener);
@@ -559,7 +563,15 @@
A4J.AJAX.removeListeners = function(listener){
A4J.AJAX._listeners = [];
};
+A4J.AJAX.removeListener = function(listener){
+ for (var i=A4J.AJAX._listeners.length-1;i>=0;i--){
+ if (A4J.AJAX._listeners[i] == listener){
+ A4J.AJAX._listeners.splice(i,1);
+ }
+ }
+};
+
//head element transformers
A4J.AJAX.HeadElementTransformer = function(elt){
this.elt = elt;
@@ -753,6 +765,13 @@
// statusID - DOM id request status tags.
// oncomplete - function for call after complete request.
A4J.AJAX.SubmitRequest = function( containerId, formId ,domEvt , options ) {
+ // Process listeners.
+ for(var li = 0; li < A4J.AJAX._listeners.length; li++){
+ var listener = A4J.AJAX._listeners[li];
+ if(listener.onbeforeajax){
+ listener.onbeforeajax(formId,domEvt,options);
+ }
+ }
// First - run onsubmit event for client-side validation.
LOG.debug("NEW AJAX REQUEST !!! with form :"+formId );
// var form = A4J.AJAX.locateForm(event);
Modified:
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
===================================================================
---
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2008-09-30
21:41:52 UTC (rev 10628)
@@ -29,12 +29,12 @@
},
// Public functions
getInnerHTML : function(context) {
- var html = "";
+ var children = [];
for (var i = 0; i < this.childs.length; i++)
{
- html += this.childs[i].getContent(context);
+ children.push(this.childs[i].getContent(context));
}
- return html;
+ return children.join('');
},
// Escape XML symbols - < > & ' ...
xmlEscape : function(value) {
Modified:
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
===================================================================
---
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2008-09-30
21:41:52 UTC (rev 10628)
@@ -2,6 +2,18 @@
window.Richfaces = {};
}
+Richfaces.mergeStyles = function(userStyles,commonStyles) {
+ var i;
+ for(i in userStyles) {
+ if (typeof userStyles[i] == "object") {
+ this.mergeStyles(userStyles[i],commonStyles[i]);
+ } else {
+ commonStyles[i] += " " + userStyles[i];
+ }
+ }
+ return commonStyles;
+};
+
Richfaces.getComputedStyle = function(eltId, propertyName) {
var elt = $(eltId);
Modified:
branches/jsf2.0/framework/impl/src/test/java/org/ajax4jsf/css/CssCompressorTest.java
===================================================================
---
branches/jsf2.0/framework/impl/src/test/java/org/ajax4jsf/css/CssCompressorTest.java 2008-09-30
17:21:21 UTC (rev 10627)
+++
branches/jsf2.0/framework/impl/src/test/java/org/ajax4jsf/css/CssCompressorTest.java 2008-09-30
21:41:52 UTC (rev 10628)
@@ -7,6 +7,7 @@
package org.ajax4jsf.css;
import java.io.IOException;
+import java.io.StringWriter;
import junit.framework.TestCase;
@@ -81,7 +82,24 @@
}
+ public void testSequentialComments() throws Exception {
+ StringBuffer cssBuffer = new StringBuffer("/* copyright */ body { color: red; }
/* abc *//* cde */ html { color: red; } /* copyright end */");
+ CssCompressor compressor = new CssCompressor(cssBuffer);
+ StringWriter stringWriter = new StringWriter();
+ compressor.compress(stringWriter, -1);
+ stringWriter.close();
+ assertEquals("body{color:red;}html{color:red;}",
stringWriter.toString());
+ }
-
+ public void testFakeComment() throws Exception {
+ //this test won't go as our CSS compressor is not aware of possible /**/ in url
+
+ //StringBuffer cssBuffer = new StringBuffer("/* copyright */ body { /* my style
*/ background-image: url(/*/); color: red; background-image: url(/****/); } /* copyright
end */");
+ //CssCompressor compressor = new CssCompressor(cssBuffer);
+ //StringWriter stringWriter = new StringWriter();
+ //compressor.compress(stringWriter, -1);
+ //stringWriter.close();
+
//assertEquals("body{background-image:url(/*/);color:red;background-image:url(/****/);}",
stringWriter.toString());
+ }
}