Example usage for org.apache.commons.validator GenericValidator isBlankOrNull

List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isBlankOrNull.

Prototype

public static boolean isBlankOrNull(String value) 

Source Link

Document

Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Usage

From source file:org.squale.welcom.taglib.field.wrap.WBaseTextareaTag.java

/**
 * Ajoute la fonction javascript de validation sur le onchange
 *//*from ww w. j  a v a 2  s . c om*/
protected void updateOnChange() {
    // Ajoute les validation javascript sur le onchange
    setOnchange(getJavascriptForCheckValue() + ((getOnchange() != null) ? getOnchange() : ""));
    if (GenericValidator.isBlankOrNull(getOnchange())) {
        setOnchange(null);
    }
}

From source file:org.squale.welcom.taglib.field.wrap.WBaseTextareaTag.java

/**
 * Ajoute la fonction javascript de validation sur le onchange
 *///w w  w . ja va 2s.  c  om
protected void updateOnBlur() {
    // Ajoute les validation javascript sur le onchange
    setOnblur(getJavascriptForCheckSpecialChar() + ((getOnblur() != null) ? getOnblur() : ""));
    if (GenericValidator.isBlankOrNull(getOnblur())) {
        setOnblur(null);
    }
}

From source file:org.squale.welcom.taglib.field.wrap.WCheckBoxTag.java

/**
 * {@inheritDoc}/*w w  w . ja  v  a 2s  .  c  o  m*/
 */
public int doStartTag() throws JspException {

    // Adapte le style de la case a coh sir on est en charte v2.002
    if (WelcomConfigurator.getCharte() == Charte.V2_002
            && GenericValidator.isBlankOrNull(this.getStyleClass())) {
        this.setStyleClass("normal");
    }

    if (READWRITE.equals(access)) {
        return super.doStartTag();
    } else {
        setDisabled(true);
        if (READSEND.equals(access)) {
            HiddenTag hiddenTag = new HiddenTag();
            // initialize the tag
            LayoutUtils.copyProperties(hiddenTag, this);
            hiddenTag.doStartTag();
            hiddenTag.doEndTag();
        }
        return super.doStartTag();
    }
}

From source file:org.squale.welcom.taglib.field.wrap.WTextareaTag.java

/**
 * {@inheritDoc}//from   ww w.  j  a  v  a 2 s  .  co  m
 */
public int doStartTag() throws JspException {
    // Adapte le style de la case a coh sir on est en charte v2.002
    if (WelcomConfigurator.getCharte() == Charte.V2_002
            && GenericValidator.isBlankOrNull(this.getStyleClass())) {
        this.setStyleClass("normal");
    }

    if (READWRITE.equals(access)) {
        return super.doStartTag();
    } else {
        this.setReadonly(true);
        if (READSEND.equals(access)) {
            HiddenTag hiddenTag = new HiddenTag();
            // initialize the tag
            LayoutUtils.copyProperties(hiddenTag, this);
            hiddenTag.doStartTag();
            hiddenTag.doEndTag();
        }
        return super.doStartTag();
    }
}

From source file:org.squale.welcom.taglib.html.FormTag.java

/**
 * @see org.apache.struts.taglib.html.FormTag#doStartTag()
 *//* ww w.  j av a  2  s .  co m*/
public int doStartTag() throws JspException {
    // Recuperer le fichier des Bundle
    resources = (MessageResources) pageContext.getServletContext().getAttribute(Globals.MESSAGES_KEY);

    // Recupere la locale de la page
    localeRequest = (Locale) pageContext.getSession().getAttribute(Globals.LOCALE_KEY);

    if (!GenericValidator.isBlankOrNull(getOnsubmit())) {
        if (getOnsubmit().startsWith("return ")) {
            setOnsubmit(getOnsubmit().substring(7, getOnsubmit().length()));
            if ((getOnsubmit().trim().length() > 0) && getOnsubmit().trim().endsWith(";")) {
                setOnsubmit(getOnsubmit().trim().substring(0, getOnsubmit().trim().length() - 1));
            }
            setOnsubmit("return " + getOnsubmit() + " && " + functionNameTestSend + "();");
        } else {
            setOnsubmit(getOnsubmit() + " ; return " + functionNameTestSend + "();");
        }
    } else {
        setOnsubmit("return " + functionNameTestSend + "()");
    }

    // Ajout des fonctions
    ResponseUtils.write(pageContext, writeFunctionSingleSend());

    return super.doStartTag();
}

From source file:org.squale.welcom.taglib.html.LinkTag.java

/**
 * @return le title//from ww w .ja va2 s  .  c om
 */
public String computeTitle() {
    if (!GenericValidator.isBlankOrNull(titleKey)) {
        final String titlekeyArgs[] = { titleKeyArg0, titleKeyArg1, titleKeyArg2, titleKeyArg3 };
        String message;
        message = WRequestUtils.message(super.pageContext, titleKey, titlekeyArgs);

        if (GenericValidator.isBlankOrNull(message)) {
            message = titleKey;
        }

        return message;
    } else {
        return super.getTitle();
    }
}

From source file:org.squale.welcom.taglib.html.OptionsTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*w  w w.ja  va 2  s.  c o  m*/
public int doEndTag() throws JspException {
    // Recupere le droit sur la page
    final SelectTag selectTag = (SelectTag) super.pageContext
            .getAttribute("org.squale.welcom.taglib.html.SELECT");

    if (selectTag == null) {
        throw new JspException(messages.getMessage("optionsTag.select"));
    }
    final String pageAccess = selectTag.getResultAccess();

    if ((selectTag.isForceReadWrite() == true) || ((pageAccess != null) && pageAccess.equals(Access.READWRITE))
            || (pageAccess == null)) {
        final StringBuffer sb = new StringBuffer();

        if (collection != null) {
            Object label;
            String stringValue;

            for (final Iterator collIterator = getIterator(collection, null); collIterator.hasNext(); addOption(
                    sb, stringValue, label.toString(), selectTag.isMatched(stringValue))) {
                final Object bean = collIterator.next();
                Object value = null;
                label = null;

                try {
                    if (bean instanceof WCouple) {
                        value = ((WCouple) bean).getValue();
                    } else {
                        value = PropertyUtils.getProperty(bean, property);
                    }

                    if (value == null) {
                        value = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", property, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", property, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", property, collection));
                }

                try {
                    if (bean instanceof WCouple) {
                        label = ((WCouple) bean).getLabel();
                    }

                    if (labelProperty != null) {
                        label = PropertyUtils.getProperty(bean, labelProperty);
                    } else {
                        if (GenericValidator.isBlankOrNull((String) label)) {
                            label = value;
                        }
                    }

                    if (label == null) {
                        label = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
                }

                stringValue = value.toString();
            }
        } else {
            final Iterator valuesIterator = getIterator(name, property);
            Iterator labelsIterator = null;

            if ((labelName == null) && (labelProperty == null)) {
                labelsIterator = getIterator(name, property);
            } else {
                labelsIterator = getIterator(labelName, labelProperty);
            }

            String value;
            String label;

            for (; valuesIterator.hasNext(); addOption(sb, value, label, selectTag.isMatched(value))) {
                value = valuesIterator.next().toString();
                label = value;

                if (labelsIterator.hasNext()) {
                    label = labelsIterator.next().toString();
                }
            }
        }

        ResponseUtils.write(super.pageContext, sb.toString());
    } else {
        if (collection != null) {
            Object label;
            String stringValue;

            for (final Iterator collIterator = getIterator(collection, null); collIterator.hasNext();) {
                final Object bean = collIterator.next();
                Object value = null;
                label = null;

                try {
                    if (bean instanceof WCouple) {
                        value = ((WCouple) bean).getValue();
                    } else {
                        value = PropertyUtils.getProperty(bean, property);
                    }

                    if (value == null) {
                        value = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", property, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", property, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", property, collection));
                }

                try {
                    if (bean instanceof WCouple) {
                        label = ((WCouple) bean).getLabel();
                    }

                    if (labelProperty != null) {
                        label = PropertyUtils.getProperty(bean, labelProperty);
                    } else {
                        if (GenericValidator.isBlankOrNull((String) label)) {
                            label = value;
                        }
                    }

                    if (label == null) {
                        label = "";
                    }
                } catch (final IllegalAccessException _ex) {
                    throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
                } catch (final InvocationTargetException e) {
                    final Throwable t = e.getTargetException();
                    throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
                } catch (final NoSuchMethodException _ex) {
                    throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
                }

                stringValue = value.toString();

                if (selectTag.isMatched(stringValue)) {
                    final StringBuffer results = new StringBuffer();
                    results.append("<span class=\"normalBold\">");
                    results.append(label);
                    results.append("</span>");
                    ResponseUtils.write(super.pageContext, results.toString());
                }
            }
        } else {
            final Iterator valuesIterator = getIterator(name, property);
            Iterator labelsIterator = null;

            if ((labelName == null) && (labelProperty == null)) {
                labelsIterator = getIterator(name, property);
            } else {
                labelsIterator = getIterator(labelName, labelProperty);
            }

            String value;
            String label;

            for (; valuesIterator.hasNext();) {
                value = valuesIterator.next().toString();
                label = value;

                if (labelsIterator.hasNext()) {
                    label = labelsIterator.next().toString();
                }

                if (selectTag.isMatched(value)) {
                    final StringBuffer results = new StringBuffer();
                    results.append("<span class=\"normalBold\">");
                    results.append(label);
                    results.append("</span>");
                    ResponseUtils.write(super.pageContext, results.toString());
                }
            }
        }
    }

    return EVAL_PAGE;
}

From source file:org.squale.welcom.taglib.html.SelectTag.java

/**
 * Calcule les droits du tag//from   w w w.  ja  va2 s .  c  o m
 * 
 * @throws JspException exception pouvant etre levee
 */
public void computeAccess() throws JspException {
    // Recupere le droit sur la page
    resultAccess = (String) pageContext.getAttribute("access");

    // Si il y a un accesskey alors outre passe le droit
    // Si il y a un accesskey alors outre passe le droit ou on combine
    if (!GenericValidator.isBlankOrNull(accessKey)) {
        if ((resultAccess != null) && !(Util.isEquals(resultAccess, Access.READONLY)
                || Util.isEquals(resultAccess, Access.READWRITE) || Util.isEquals(resultAccess, Access.NONE))) {
            throw new JspException(
                    "L'attribut accessKey doit retourner une valeur READWRITE ou READONLY ou NONE (cf getSecuritePage()) : "
                            + resultAccess);
        }

        final Object o = pageContext.getSession().getAttribute(WConstants.USER_KEY);

        if (o != null) {
            if (o instanceof WILogonBeanSecurity) {
                final WILogonBeanSecurity lb = (WILogonBeanSecurity) o;
                final String accessTag = Access.getMultipleSecurityPage(lb, accessKey);

                if ((overridePageAccess == null) || Util.isTrue(overridePageAccess)) {
                    resultAccess = accessTag;
                } else
                // si mis a false explicitement
                if (Util.isEquals(resultAccess, Access.READONLY)
                        && Util.isEquals(accessTag, Access.READWRITE)) {
                    resultAccess = Access.READONLY;
                } else {
                    resultAccess = accessTag;
                }
            }
        }
    }
}

From source file:org.squale.welcom.taglib.htmlarea.CustomToolTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 *///from   w  w  w  .  j  a  v  a  2  s . com
public int doStartTag() throws JspException {
    // Recherche si un parent est du bon type
    Tag curParent = null;

    for (curParent = getParent(); (curParent != null) && !(curParent instanceof HtmlAreaTag);) {
        curParent = curParent.getParent();
    }

    htmlAreaTag = (HtmlAreaTag) curParent;
    edName = htmlAreaTag.getEdName();

    if (htmlAreaTag == null) {
        throw new JspException("customtool tag must be used between htmlarea tag.");
    }

    localeRequest = (Locale) pageContext.getSession().getAttribute(Globals.LOCALE_KEY);
    resources = (MessageResources) pageContext.getServletContext().getAttribute(Globals.MESSAGES_KEY);

    if (type.toUpperCase().equals(BUTTON)) {
        registerButton();
    }

    if (type.toUpperCase().equals(DROPDOWN)) {
        registerDropDown();
    }

    if (!GenericValidator.isBlankOrNull(insert)) {
        final TrimStringBuffer sb = new TrimStringBuffer();

        if (insert.toUpperCase().equals(AFTER)) {
            sb.append(edName + ".config.toolbar[0].push(['" + id + "']);");
        }

        if (insert.toUpperCase().equals(BEFORE)) {
            sb.append(edName + ".config.toolbar[0].unshift(['" + id + "']);");
        }

        ResponseUtils.write(pageContext, sb.toString());
    }

    return EVAL_PAGE;
}

From source file:org.squale.welcom.taglib.htmlarea.CustomToolTag.java

/**
 * @throws JspException exception pouvant etre levee
 *//*  w ww .j a v  a2  s. com*/
private void registerDropDown() throws JspException {
    final TrimStringBuffer sb = new TrimStringBuffer();

    sb.append(edName + ".config.registerDropdown({\n");
    sb.append("id : '" + id + "',\n");

    if (!GenericValidator.isBlankOrNull(tooltip)) {
        String mess = null;

        mess = resources.getMessage(localeRequest, tooltip);

        if (GenericValidator.isBlankOrNull(mess)) {
            mess = tooltip;
        }

        sb.append("tooltip : '" + mess + "',\n");
    }

    if (!GenericValidator.isBlankOrNull(collection)) {
        final Object o = super.pageContext.findAttribute(collection);

        if (o == null) {
            final JspException e = new JspException("Objet " + collection + " introuvable dans le scope");
            RequestUtils.saveException(super.pageContext, e);
            throw e;
        }

        Iterator iter = null;

        if (o instanceof Collection) {
            iter = ((Collection) o).iterator();
        }

        if (o instanceof WComboValueLabel) {
            iter = ((WComboValueLabel) o).iterator();
        }

        if (iter == null) {
            throw new JspException(
                    "Le bean " + collection + "doit tre de type Collection ou WComboValueLabel");
        }

        sb.append("options : {");

        String opt = "";

        while (iter.hasNext()) {
            final Object element = iter.next();

            if (!(element instanceof WCouple)) {
                throw new JspException("Le bean " + collection + "doit contenir des objets de type WCouple");
            }

            final WCouple wc = (WCouple) element;
            String value = wc.getValue();

            if (GenericValidator.isBlankOrNull(value)) {
                value = wc.getLabel();
            }

            opt += ("'" + wc.getLabel() + "':'" + value + "',");
        }

        opt = opt.substring(0, opt.length() - 1);
        sb.append(opt);
        sb.append("},\n");
    } else if (!GenericValidator.isBlankOrNull(options)) {
        String mess = null;

        mess = resources.getMessage(localeRequest, options);

        if (GenericValidator.isBlankOrNull(mess)) {
            mess = options;
        }

        sb.append("options : {" + mess + "},\n");
    } else {
        throw new JspException("Aucune option pour le combo " + id);
    }

    sb.append("refresh  : " + refresh + ",\n");
    sb.append("action   : " + action);
    sb.append("\n});\n");
    ResponseUtils.write(pageContext, sb.toString());
}