[richfaces-svn-commits] JBoss Rich Faces SVN: r18640 - in trunk/core/impl/src: main/resources/META-INF/resources and 1 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Sun Aug 15 15:28:03 EDT 2010
Author: nbelaevski
Date: 2010-08-15 15:28:03 -0400 (Sun, 15 Aug 2010)
New Revision: 18640
Modified:
trunk/core/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js
trunk/core/impl/src/test/resources/javascript/4_0_0.html
Log:
https://jira.jboss.org/browse/RF-7816
HtmlUtil refactoring
Modified: trunk/core/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2010-08-15 18:52:28 UTC (rev 18639)
+++ trunk/core/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2010-08-15 19:28:03 UTC (rev 18640)
@@ -21,16 +21,19 @@
package org.richfaces.component.util;
-import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.renderkit.RendererUtils;
-import org.ajax4jsf.util.HtmlDimensions;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.util.HtmlDimensions;
+
+import com.google.common.base.Strings;
+
/**
* @author Nick Belaevski - nbelaevski at exadel.com created 09.02.2007
*/
@@ -124,39 +127,27 @@
return false;
}
- private static boolean isEmpty(String s) {
- return (s == null) || (s.length() == 0);
- }
-
- public static String concatClasses(String... classes) {
+ private static String concat(char separator, String... strings) {
StringBuilder result = new StringBuilder();
- for (String className : classes) {
- if (!isEmpty(className)) {
+ for (String s : strings) {
+ if (!Strings.isNullOrEmpty(s)) {
if (result.length() != 0) {
- result.append(' ');
+ result.append(separator);
}
- result.append(className.trim());
+ result.append(s.trim());
}
}
return result.toString();
}
+
+ public static String concatClasses(String... classes) {
+ return concat(' ', classes);
+ }
public static String concatStyles(String... styles) {
- StringBuilder result = new StringBuilder();
-
- for (String style : styles) {
- if (!isEmpty(style)) {
- if (result.length() != 0) {
- result.append(';');
- }
-
- result.append(style.trim());
- }
- }
-
- return result.toString();
+ return concat(';', styles);
}
}
Modified: trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js 2010-08-15 18:52:28 UTC (rev 18639)
+++ trunk/core/impl/src/main/resources/META-INF/resources/richfaces.js 2010-08-15 19:28:03 UTC (rev 18640)
@@ -143,129 +143,29 @@
return s.replace(CSS_METACHARS_PATTERN, "\\$1");
};
- richfaces.log = (function(jQuery) {
- var LOG_LEVELS = {'debug': 1, 'info': 2, 'warn': 3, 'error': 4};
- var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info': 'blue', 'warn': 'gold', 'error': 'red'};
- var DEFAULT_LOG_LEVEL = LOG_LEVELS['info'];
- var currentLogLevel = DEFAULT_LOG_LEVEL;
+ richfaces.log = {
+ debug: function(text) {
+ },
- var consoleInitialized = false;
+ info: function(text) {
+ },
- var setLevel = function(level) {
- currentLogLevel = LOG_LEVELS[level] || DEFAULT_LOG_LEVEL;
- if (consoleInitialized) {
- getConsole().find("select.rich-log-element").val(currentLogLevel);
- }
- clear();
- };
+ warn: function(text) {
+ },
- var setLevelFromSelect = function(iLevel) {
- currentLogLevel = iLevel || DEFAULT_LOG_LEVEL;
- };
+ error: function(text) {
+ },
+
+ setLevel: function(level) {
+ },
- var clear = function() {
- if (window.console && useBrowserConsole) {
- window.console.clear();
- } else {
- var console = getConsole();
- console.children(".rich-log-contents").children().remove();
- }
- };
-
- var getConsole = function() {
- var console = jQuery('#richfaces\\.log');
- if (console.length != 0) {
- if (!consoleInitialized) {
- consoleInitialized = true;
-
- var clearBtn = console.children("button.rich-log-element");
- if (clearBtn.length == 0) {
- clearBtn = jQuery("<button type='button' class='rich-log-element'>Clear</button>").appendTo(console);
- }
- clearBtn.click(clear);
-
- var levelSelect = console.children("select.rich-log-element");
- if (levelSelect.length == 0) {
- levelSelect = jQuery("<select class='rich-log-element' name='richfaces.log' />").appendTo(console);
- }
-
- if (levelSelect.children().length == 0) {
- for (var level in LOG_LEVELS) {
- jQuery("<option value='" + LOG_LEVELS[level]+ "'>" + level + "</option>").appendTo(levelSelect);
- }
- }
-
- levelSelect.val(currentLogLevel);
- levelSelect.change(function(event) { clear(); setLevelFromSelect(parseInt(jQuery(this).val(), 10)); return false;});
-
- var consoleEntries = console.children(".rich-log-contents");
- if (consoleEntries.length == 0) {
- consoleEntries = jQuery("<div class='rich-log-contents'></div>").appendTo(console);
- }
- }
- }
-
- return console;
- };
-
- var useBrowserConsole = false;
-
- var AM_PM = /(\s*(?:a|p)m)$/i;
-
- var getMessagePrefix = function(level) {
- var date = new Date();
- var formattedDate = date.toLocaleTimeString();
-
- var ms = (date.getMilliseconds() + 1000).toString().substr(1);
- if (AM_PM.test(formattedDate)) {
- formattedDate = formattedDate.replace(AM_PM, "." + ms + "$1");
- } else {
- formattedDate += "." + ms;
- }
-
- return level + '[' + formattedDate.replace() + ']: ';
- };
-
- var appendConsoleEntry = function(level, messagePrefix, messageText, console) {
- //TODO - cache jQuery("<element>")?
- var newEntry = jQuery(document.createElement("div")).appendTo(console.children(".rich-log-contents"));
- jQuery("<span style='color: " + LOG_LEVEL_COLORS[level] + "'></span>").appendTo(newEntry).text(messagePrefix);
-
- var entrySpan = jQuery(document.createElement("span")).appendTo(newEntry);
- if (typeof messageText != 'object' || !messageText.appendTo) {
- entrySpan.text(messageText);
- } else {
- messageText.appendTo(entrySpan);
- }
- };
-
- var appendBrowserConsoleEntry = function(level, text) {
- window.console[level]();
- };
-
- var appendMessage = function(level, message) {
- if (window.console && useBrowserConsole) {
- var text = getMessagePrefix(level) + message;
- appendBrowserConsoleEntry(level, text);
- } else {
- var console = getConsole();
- if (LOG_LEVELS[level] >= currentLogLevel && console.length != 0) {
- var messagePrefix = getMessagePrefix(level);
- appendConsoleEntry(level, messagePrefix, message, console);
- }
- }
- };
-
- var methods = {setLevel: setLevel, clear: clear};
- for (var logLevel in LOG_LEVELS) {
- var f = function(text) {
- appendMessage(arguments.callee.logLevel, text);
- };
- f.logLevel = logLevel;
- methods[logLevel] = f;
+ getLevel: function() {
+ return 'info';
+ },
+
+ clear: function() {
}
- return methods;
- }(jQuery));
+ };
/**
* Evaluates chained properties for the "base" object.
Modified: trunk/core/impl/src/test/resources/javascript/4_0_0.html
===================================================================
--- trunk/core/impl/src/test/resources/javascript/4_0_0.html 2010-08-15 18:52:28 UTC (rev 18639)
+++ trunk/core/impl/src/test/resources/javascript/4_0_0.html 2010-08-15 19:28:03 UTC (rev 18640)
@@ -34,22 +34,16 @@
ok(!jQuery("input", form).size());
});
- test("RichFaces.log test", function() {
- expect(7);
- var log = jQuery("#richfaces\\.log");
+ test("RichFaces.log stub test", function() {
+ //none of these calls shouldn't fail
RichFaces.log.error("some error");
+ RichFaces.log.warn("some warn");
RichFaces.log.info("some info");
- log = jQuery("#richfaces\\.log .rich-log-contents");
- equals(log.find("div").size(), 2);
- equals(log.find("div:contains('some error')").size(), 1);
- equals(log.find("div:contains('some info')").size(), 1);
- RichFaces.log.setLevel("error");
- equals(log.find("div").size(), 0);
- RichFaces.log.error("some error");
- RichFaces.log.info("some info");
- equals(log.find("div").size(), 1);
- equals(log.find("div:contains('some error')").size(), 1);
- equals(log.find("div:contains('some info')").size(), 0);
+ RichFaces.log.debug("some debug");
+
+ RichFaces.log.clear();
+ RichFaces.log.getLevel();
+ RichFaces.log.setLevel('info');
});
test("RichFaces.getValue test", function() {
More information about the richfaces-svn-commits
mailing list