diff --git a/src/main/java/net/bootsfaces/component/button/ButtonRenderer.java b/src/main/java/net/bootsfaces/component/button/ButtonRenderer.java index 663f2630d..ea47b846d 100644 --- a/src/main/java/net/bootsfaces/component/button/ButtonRenderer.java +++ b/src/main/java/net/bootsfaces/component/button/ButtonRenderer.java @@ -84,7 +84,7 @@ public void encodeHTML(FacesContext context, Button button) rw.writeAttribute("id", clientId, "id"); rw.writeAttribute("name", clientId, "name"); rw.writeAttribute("type", "button", null); - if(BsfUtils.StringIsValued(button.getDir())) { + if(BsfUtils.isStringValued(button.getDir())) { rw.writeAttribute("dir", button.getDir(), "dir"); } if (style != null) { @@ -98,7 +98,7 @@ public void encodeHTML(FacesContext context, Button button) if (null != clickHandler && clickHandler.length() > 0) { rw.writeAttribute("onclick", clickHandler, null); } - if (BsfUtils.StringIsValued(button.getDismiss())) { + if (BsfUtils.isStringValued(button.getDismiss())) { rw.writeAttribute("data-dismiss", button.getDismiss(), null); } if (button.isDisabled()) { diff --git a/src/main/java/net/bootsfaces/component/colorPicker/ColorPickerRenderer.java b/src/main/java/net/bootsfaces/component/colorPicker/ColorPickerRenderer.java index 045c05009..8161b74a1 100644 --- a/src/main/java/net/bootsfaces/component/colorPicker/ColorPickerRenderer.java +++ b/src/main/java/net/bootsfaces/component/colorPicker/ColorPickerRenderer.java @@ -215,7 +215,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce // build color picker init script rw.startElement("script", colorPicker); rw.writeText("$(function() {" + - "$('#input_" + BsfUtils.EscapeJQuerySpecialCharsInSelector(clientId) + "').minicolors({" + + "$('#input_" + BsfUtils.escapeJQuerySpecialCharsInSelector(clientId) + "').minicolors({" + (colorPicker.getAttributes().get("control") != null ? " control: '" + colorPicker.getAttributes().get("control") + "'," : "") + (colorPicker.getAttributes().get("format") != null ? " format: '" + colorPicker.getAttributes().get("format") + "'," : "") + (colorPicker.getAttributes().get("opacity") != null ? " opacity: " + colorPicker.getAttributes().get("opacity") + "," : "") + diff --git a/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java b/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java index 18c1f0ae1..c1d4a4638 100644 --- a/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java +++ b/src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java @@ -310,7 +310,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce " pageLength: " + pageLength + ", " + " lengthMenu: " + dataTable.getPageLengthMenu() + ", " + " order: " + orderString + ", " + - (BsfUtils.StringIsValued(lang) ? " language: { url: '" + lang + "' } " : "") + + (BsfUtils.isStringValued(lang) ? " language: { url: '" + lang + "' } " : "") + "});" + // "var table = " + widgetVar +".DataTable({fixedHeader: true, responsive: true});" + "var workInProgressErrorMessage = 'Multiple DataTables on the same page are not yet supported when using " + @@ -382,9 +382,9 @@ private String determineLanguage(FacesContext fc, DataTable dataTable) { final Set availableLanguages = new HashSet(Arrays.asList( new String[] {"de", "en", "es", "fr", "hu", "it", "pl", "ru"} )); - if(BsfUtils.StringIsValued(dataTable.getCustomLangUrl())) { + if(BsfUtils.isStringValued(dataTable.getCustomLangUrl())) { return dataTable.getCustomLangUrl(); - } else if(BsfUtils.StringIsValued(dataTable.getLang())) { + } else if(BsfUtils.isStringValued(dataTable.getLang())) { String lang = dataTable.getLang(); if(availableLanguages.contains(lang)) return determineLanguageUrl(fc, lang); } diff --git a/src/main/java/net/bootsfaces/component/defaultCommand/DefaultCommand.java b/src/main/java/net/bootsfaces/component/defaultCommand/DefaultCommand.java index 932317c74..2f2f1719a 100644 --- a/src/main/java/net/bootsfaces/component/defaultCommand/DefaultCommand.java +++ b/src/main/java/net/bootsfaces/component/defaultCommand/DefaultCommand.java @@ -52,7 +52,7 @@ public void encodeEnd(FacesContext context) throws IOException { throw new FacesException("The default command component must be inside a form", null); } else { String target = (String)attrs.get("target"); - if(BsfUtils.StringIsValued(target)) { + if(BsfUtils.isStringValued(target)) { ResponseWriter rw = context.getResponseWriter(); String formId = form.getClientId(); String actionCommandId = BsfUtils.getComponentClientId(target); @@ -61,7 +61,7 @@ public void encodeEnd(FacesContext context) throws IOException { rw.writeText("" + "$(function() { " + - " $('form#" + BsfUtils.EscapeJQuerySpecialCharsInSelector(formId) + " :input').keypress(function (e) { " + + " $('form#" + BsfUtils.escapeJQuerySpecialCharsInSelector(formId) + " :input').keypress(function (e) { " + " if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { " + " document.getElementById('" + actionCommandId + "').click();return false; " + " } else { " + diff --git a/src/main/java/net/bootsfaces/component/focus/Focus.java b/src/main/java/net/bootsfaces/component/focus/Focus.java index db14adc32..1d619e22d 100644 --- a/src/main/java/net/bootsfaces/component/focus/Focus.java +++ b/src/main/java/net/bootsfaces/component/focus/Focus.java @@ -46,13 +46,13 @@ public void encodeEnd(FacesContext context) throws IOException { Map attrs = getAttributes(); String target = (String)attrs.get("target"); - if(!BsfUtils.StringIsValued(target)) { + if(!BsfUtils.isStringValued(target)) { if(this.getParent() != null) target = this.getParent().getId(); } // - if(BsfUtils.StringIsValued(target)) { + if(BsfUtils.isStringValued(target)) { ResponseWriter rw = context.getResponseWriter(); String itemToFocusID = BsfUtils.getComponentClientId(target); diff --git a/src/main/java/net/bootsfaces/component/jumbotron/JumbotronRenderer.java b/src/main/java/net/bootsfaces/component/jumbotron/JumbotronRenderer.java index efe663717..20dd094fd 100644 --- a/src/main/java/net/bootsfaces/component/jumbotron/JumbotronRenderer.java +++ b/src/main/java/net/bootsfaces/component/jumbotron/JumbotronRenderer.java @@ -57,13 +57,13 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx rw.startElement("div", jumbotron); rw.writeAttribute("id",clientId,"id"); - if(BsfUtils.StringIsValued(jumbotron.getStyle())) + if(BsfUtils.isStringValued(jumbotron.getStyle())) rw.writeAttribute("style", jumbotron.getStyle(), "style"); Tooltip.generateTooltip(context, jumbotron, rw); String styleClass = "jumbotron"; - if(BsfUtils.StringIsValued(jumbotron.getStyleClass())) + if(BsfUtils.isStringValued(jumbotron.getStyleClass())) styleClass = styleClass + " " + jumbotron.getStyleClass(); rw.writeAttribute("class", styleClass, "class"); } diff --git a/src/main/java/net/bootsfaces/component/scrollSpy/ScrollSpyRenderer.java b/src/main/java/net/bootsfaces/component/scrollSpy/ScrollSpyRenderer.java index 101712f45..d911a4e23 100644 --- a/src/main/java/net/bootsfaces/component/scrollSpy/ScrollSpyRenderer.java +++ b/src/main/java/net/bootsfaces/component/scrollSpy/ScrollSpyRenderer.java @@ -90,17 +90,17 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce // Get attributes String container = scrollSpy.getContainer(); - if(!BsfUtils.StringIsValued(container)) { + if(!BsfUtils.isStringValued(container)) { container = "body"; } else container = "#" + decodeAndEscapeSelectors(context, component, container); String target = scrollSpy.getTarget(); - if(!BsfUtils.StringIsValued(target)) { + if(!BsfUtils.isStringValued(target)) { target = ".navbar"; } else target = "#" + decodeAndEscapeSelectors(context, component, target); int offset = scrollSpy.getOffset(); - if(!BsfUtils.StringIsValued(target)) { + if(!BsfUtils.isStringValued(target)) { offset = 20; } boolean smooth = scrollSpy.isSmooth(); @@ -160,7 +160,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce */ private String decodeAndEscapeSelectors(FacesContext context, UIComponent component, String selector) { selector = ExpressionResolver.getComponentIDs(context, component, selector); - selector = BsfUtils.EscapeJQuerySpecialCharsInSelector(selector); + selector = BsfUtils.escapeJQuerySpecialCharsInSelector(selector); return selector; } diff --git a/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java b/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java index e37b961ce..3fc0288ea 100644 --- a/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java +++ b/src/main/java/net/bootsfaces/component/tree/TreeRenderer.java @@ -130,7 +130,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce } Tree tree = (Tree) component; String clientId = tree.getClientId(); - String jqClientId = BsfUtils.EscapeJQuerySpecialCharsInSelector(clientId); + String jqClientId = BsfUtils.escapeJQuerySpecialCharsInSelector(clientId); ResponseWriter rw = context.getResponseWriter(); final UIForm form = BsfUtils.getClosestForm(tree); @@ -156,9 +156,9 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce (tree.isShowIcon() ? "showIcon: true," : "") + (tree.isShowCheckbox() ? "showCheckbox: true," : "") + (tree.isEnableLinks() ? "enableLinks: true," : "") + - (BsfUtils.StringIsValued(tree.getCollapseIcon()) ? "collapseIcon: '" + tree.getCollapseIcon() + "'," : "") + - (BsfUtils.StringIsValued(tree.getExpandIcon()) ? "expandIcon: '" + tree.getExpandIcon() + "'," : "") + - (BsfUtils.StringIsValued(tree.getColor()) ? "color: '" + tree.getColor() + "'," : "") + + (BsfUtils.isStringValued(tree.getCollapseIcon()) ? "collapseIcon: '" + tree.getCollapseIcon() + "'," : "") + + (BsfUtils.isStringValued(tree.getExpandIcon()) ? "expandIcon: '" + tree.getExpandIcon() + "'," : "") + + (BsfUtils.isStringValued(tree.getColor()) ? "color: '" + tree.getColor() + "'," : "") + " data: getTreeData(), " + // enable nodeSelected event callback " onNodeSelected: function(event, data) { " + diff --git a/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java b/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java index 4b3ff8b60..bffab185f 100644 --- a/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java +++ b/src/main/java/net/bootsfaces/component/tree/model/TreeModelUtils.java @@ -141,27 +141,27 @@ private static String renderNode(Node node) { sb.append("\"nodeInternalId\": " + node.getNodeId() + ", "); } // TEXT - if(BsfUtils.StringIsValued(node.getText())) { + if(BsfUtils.isStringValued(node.getText())) { sb.append("\"text\": \"" + node.getText() + "\", "); } // ICON - if(BsfUtils.StringIsValued(node.getIcon())) { + if(BsfUtils.isStringValued(node.getIcon())) { sb.append("\"icon\": \"" + node.getIcon() + "\", "); } // SELECTED ICON - if(BsfUtils.StringIsValued(node.getSelectedIcon())) { + if(BsfUtils.isStringValued(node.getSelectedIcon())) { sb.append("\"selectedIcon\": \"" + node.getSelectedIcon() + "\", "); } // COLOR - if(BsfUtils.StringIsValued(node.getColor())) { + if(BsfUtils.isStringValued(node.getColor())) { sb.append("\"color\": \"" + node.getColor() + "\", "); } // BACK COLOR - if(BsfUtils.StringIsValued(node.getBackColor())) { + if(BsfUtils.isStringValued(node.getBackColor())) { sb.append("\"backColor\": \"" + node.getBackColor() + "\", "); } // HREF - if(BsfUtils.StringIsValued(node.getHRef())) { + if(BsfUtils.isStringValued(node.getHRef())) { sb.append("\"href\": \"" + node.getHRef() + "\", "); } // TAGS diff --git a/src/main/java/net/bootsfaces/utils/BsfUtils.java b/src/main/java/net/bootsfaces/utils/BsfUtils.java index 658a3f50e..7a8be2894 100644 --- a/src/main/java/net/bootsfaces/utils/BsfUtils.java +++ b/src/main/java/net/bootsfaces/utils/BsfUtils.java @@ -62,19 +62,19 @@ public static String navigateInAjax(String outcome) * @param str * @return */ - public static boolean StringIsValued(String str) { - if(str != null && !"".equals(str.trim())) return true; - return false; + public static boolean isStringValued(String str) { + return str != null && !"".equals(str.trim()); } /** - * Get the string if is valued, otherwise return default Value + * Get the string if is not null or empty, + * otherwise return the default value * @param str * @param defaultValue * @return */ - public static String StringOrDefault(String str, String defaultValue) { - if(StringIsValued(str)) return str; + public static String stringOrDefault(String str, String defaultValue) { + if(isStringValued(str)) return str; return defaultValue; } @@ -195,25 +195,12 @@ else if (c == '\n') return sb.toString(); } - /** - * Get the string if is not null or empty, - * otherwise return the default value - * - * @param inputValue - * @param defaultReturnValue - * @return - */ - public static String GetOrDefault (String inputValue, String defaultReturnValue) { - if(StringIsValued(inputValue)) return inputValue; - else return defaultReturnValue; - } - /** * Escape special jQuery chars in selector query * @param selector * @return */ - public static String EscapeJQuerySpecialCharsInSelector(String selector) { + public static String escapeJQuerySpecialCharsInSelector(String selector) { String jQuerySpecialChars = "!\"#$%&'()*+,./:;<=>?@[]^`{|}~;"; String[] jsc = jQuerySpecialChars.split("(?!^)"); for(String c: jsc) {