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.table.ColOrderTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///from w w w  .  ja v  a 2s . c  o  m
public int doEndTag() throws JspException {
    final String pageAccess = (String) pageContext.getAttribute("access");

    if ((pageAccess != null) && pageAccess.equals(Access.READONLY) && !forceReadWrite) {
        return SKIP_BODY;
    }

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

    // Recuperer le fichier des Bundle
    final MessageResources resources = (MessageResources) pageContext.getServletContext()
            .getAttribute(Globals.MESSAGES_KEY);

    final ColOrder c = new ColOrder();

    if (key == null) {
        key = property;
    }

    c.setKey(key);
    c.setProperty(property);
    c.setParamId(paramId);
    c.setParamName(paramName);
    c.setParamProperty(paramProperty);
    c.setLink(href);
    c.setWidth(width);
    c.setPageContext(pageContext);

    if (!GenericValidator.isBlankOrNull(toolTipKeyDown)) {
        c.setTitleDown(resources.getMessage(localeRequest, toolTipKeyDown));
    }

    if (!GenericValidator.isBlankOrNull(toolTipKeyUp)) {
        c.setTitleUp(resources.getMessage(localeRequest, toolTipKeyUp));
    }

    colsTag.addCellule(c);

    return EVAL_PAGE;
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * Recherche si la ligne n'est pas slectionne via une proprit indiqu dans l'attribut property de colSelect.
 * //from   ww w.j a v a2  s  .  c o m
 * @param bean bean associ au tag cols (collection des lignes)
 * @return true si la ligne est slectionne
 * @throws JspException
 */
private boolean isColSelected(final Object bean, final int i) throws JspException {
    Iterator iter = cols.iterator();
    while (iter.hasNext()) {
        Object col = iter.next();
        if (col instanceof ColSelect) {
            ColSelect colSelect = (ColSelect) col;
            if (!GenericValidator.isBlankOrNull(colSelect.getProperty())) {
                try {
                    String value = BeanUtils.getProperty(bean, colSelect.getProperty());

                    if (value.equalsIgnoreCase("true")) {
                        return true;
                    } else {
                        return false;
                    }

                } catch (final Exception e) {
                    log.error(e, e);
                    throw new JspException(
                            "Impossible de recupere la clef " + colSelect.getProperty() + " sur le bean");
                }
            }
        }
        if (col instanceof ColSingleSelect) {
            ColSingleSelect colSelect = (ColSingleSelect) col;
            return colSelect.getLineIsSelected(bean, i);
        }
    }
    return false;
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * Ecrit les ancienne case a cocher//w w  w  .  j ava 2  s  . co m
 * 
 * @param o objet de la ligne
 * @param pIdIndex index
 * @param style style non selectionn
 * @param styleselect style si selectionn
 * @param currentStyle Sytle courant
 * @param wdt taille
 * @return le flux html de la check box
 * @throws JspException
 */
private String writeLegacyCheckBox(final Object o, final Integer pIdIndex, String style, String styleselect,
        String currentStyle, String wdt) throws JspException {
    final TrimStringBuffer sb = new TrimStringBuffer();

    if (WelcomConfigurator.getCharte() == Charte.V2_002) {
        currentStyle = "normal";
    }

    // Si on est en mode checkbox sans avec envoie un table des case a coch coch
    if (isSelectTr()) {
        String key = "";
        try {
            key = BeanUtils.getProperty(o, selectProperty);
        } catch (final Exception e) {
            log.error(e, e);
            throw new JspException("Impossible de recupere la clef");
        }

        String name = getTable().getName();

        if (!GenericValidator.isBlankOrNull(getTable().getProperty())) {
            name = getTable().getProperty();
        }

        name = "check_" + name;

        if (!enableSingleSelect) {
            sb.append("<td" + wdt + " classSelect=\"" + styleselect + "\" classDefault=\"" + style + "\">");
            sb.append("<input type=\"hidden\" name=\"checkName\" value=\"" + name + "\">");
            sb.append("<input class=\"" + currentStyle + "\" type=\"checkbox\" name=\"" + name + "\" value=\""
                    + key + "\" onclick='check(this);'");
            sb.append("></td>");
        } else {
            sb.append("<td" + wdt + " classSelect=\"" + styleselect + "\" classDefault=\"" + style
                    + "\"><input class=\"" + currentStyle + "\" type=\"checkbox\" name=\"" + name
                    + "\" value=\"" + key + "\" onclick='checkSingle(this);'");
            sb.append("></td>");
        }
    }

    // Si on utilise le mode WIselected
    if (isSelectCheckBox()) {
        if (o instanceof WISelectable) {
            String name = getTable().getName();

            if (!GenericValidator.isBlankOrNull(getTable().getProperty())) {
                name = getTable().getProperty();
            }

            if (!enableSingleSelect) {
                sb.append("<td ");
                sb.append(wdt + " classSelect=\"" + styleselect + "\" classDefault=\"" + style + "\">");

                if (Util.isFalse(
                        WelcomConfigurator.getMessage(WelcomConfigurator.OPTIFLUX_AUTORESET_CHECKBOX))) {
                    sb.append("<input type=\"hidden\" name=\"checkName\" value=\"" + name + "[" + pIdIndex
                            + "].selected" + "\">");
                }

                sb.append("<input class=\"" + currentStyle + "\" type=\"checkbox\" name=\"" + name + "["
                        + pIdIndex + "].selected" + "\" value=\"true\" onclick='check(this);'");

                if (((WISelectable) o).isSelected()) {
                    sb.append(" checked ");
                }

                sb.append("></td>");
            } else {
                sb.append("<td ");
                sb.append(wdt + " classSelect=\"" + styleselect + "\" classDefault=\"" + style
                        + "\"><input class=\"" + currentStyle + "\" type=\"checkbox\" name=\"" + name + "["
                        + pIdIndex + "].selected" + "\" value=\"true\" onclick='checkSingle(this);'");

                if (((WISelectable) o).isSelected()) {
                    sb.append(" checked ");
                }

                sb.append("></td>");
            }
        } else {
            throw new JspException("Bean must be of type WFormSelectable or WISelectable : " + o.getClass());
        }
    }
    return sb.toString();
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * Ecrit la cellule de la table//from  ww w .  ja  v a2s . co  m
 * 
 * @param o objet a representer
 * @param index index numero de ligne
 * @param style style style de la ligne
 * @param pIdIndex Index
 * @param styleSelect Style selectionne
 * @param sb StringBuffer
 * @param col Colonne
 */
private void writeColumnValue(final Object o, final int index, final String style, final int pIdIndex,
        final String styleSelect, final TrimStringBuffer sb, final Col col) {
    internalValue = "";
    if (col.isWriteTD()) {
        sb.append("\t\t<td ");

        if (!GenericValidator.isBlankOrNull(col.getContentStyle())) {
            sb.append("style=\"");

            if (WelcomConfigurator.getCharte() == Charte.V2_001) {
                sb.append("padding-left:2px;");
            }
            sb.append(col.getContentStyle());
            sb.append("\" ");
        }

        try {
            getColumnValue(o, col);
        } catch (final JspException e) {
            log.error(e, e);
        }
        if (InternalTableUtil.isTruncated(internalValue, col.getContentTruncate(), col.getType())) {
            sb.append("title=\"");
            sb.append(internalValue);
            sb.append("\" ");
        }

        if (!GenericValidator.isBlankOrNull(col.getContentClass())) {
            sb.append("class=\"");
            sb.append(col.getContentClass());
            sb.append("\" ");
        }

        if ((table.isDisplayHeader() == false) && !GenericValidator.isBlankOrNull(col.getWidth())) {
            sb.append("width=\"" + col.getWidth() + "\" ");
        }

        sb.append("\t\t>");
    }

    if (col.isContentNoWrap()) {
        sb.append("<nobr>");
        sb.append(writeContentColumnValue(o, col, getPosition(index), pIdIndex, style, styleSelect));
        sb.append("</nobr>");
    } else {
        sb.append(writeContentColumnValue(o, col, getPosition(index), pIdIndex, style, styleSelect));
    }

    if (col.isWriteTD()) {
        sb.append("</td>\n");
    }
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * @param o l'object a representer// www.java  2 s . c o  m
 * @param col colonne a representer
 * @throws JspException exception pouvant etre levee
 */
private void getColumnValue(final Object o, final Col col) throws JspException {
    Object ovalue = null;
    if (GenericValidator.isBlankOrNull(internalValue)) {
        if (!GenericValidator.isBlankOrNull(col.getProperty())) {
            ovalue = LayoutUtils.getProperty(o, col.getProperty());
            if (ovalue != null) {
                if (!(ovalue instanceof Date)) {
                    internalValue = ResponseUtils.filter(ovalue.toString());
                }
            } else {
                // Recupere celle spcifi
                if (!GenericValidator.isBlankOrNull(col.getEmptyKey())) {
                    internalValue = col.getEmptyKey();
                } else {
                    internalValue = WelcomConfigurator.getMessageWithCfgChartePrefix(".default.char.if.empty");
                }
            }
            // Si on est sur une date on doit faire un traitement spcifique
            if ((col.getType() != null) && (col.getType().equals(ColComparator.TYPE_DATE))) {
                if ((ovalue instanceof Date) || (((DateUtil.parseAllDate(internalValue))) != null)) {
                    SimpleDateFormat df;
                    if (col.getDateFormatKey() != null) {
                        df = new SimpleDateFormat(table.getResources().getMessage(table.getLocaleRequest(),
                                col.getDateFormatKey()), table.getLocaleRequest());
                    } else if (col.getDateFormat() != null) {
                        df = new SimpleDateFormat(col.getDateFormat(), table.getLocaleRequest());
                    } else {
                        df = Util.formatDtHr;
                    }
                    if (ovalue instanceof Date) {
                        internalValue = df.format((Date) ovalue);
                    } else {
                        internalValue = df.format(DateUtil.parseAllDate(internalValue));
                    }
                }
            }
        }
    }
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * @param position Position ou se trouve le curseur
 * @param o objet a representer/*from  w  w w.ja  v a  2  s.  c o  m*/
 * @param col colonne a representer
 * @param index Index
 * @param style Style
 * @param styleSelect Style selectionne
 * @return html correspondant a la cellule : objet o colonne col
 */
private String writeContentColumnValue(final Object o, final Col col, final int position, final int index,
        final String style, final String styleSelect) {
    try {
        final String val = col.getCurrentValue(position, o, index, style, styleSelect, table.getPageLength());

        if (!GenericValidator.isBlankOrNull(val)) {
            return val;
        }
        getColumnValue(o, col);

        if (GenericValidator.isBlankOrNull(internalValue)) {
            return WelcomConfigurator.getMessageWithCfgChartePrefix(".default.char.if.empty");
        }

        if ((o instanceof WIEditable) && ((WIEditable) o).isEdited() && col.isEditable()) {
            final String ovalue = internalValue;
            internalValue = "<input type=\"text\" name=\"" + getPropertyFull(index) + "." + col.getProperty()
                    + "\"";
            if (!GenericValidator.isBlankOrNull(ovalue)) {
                internalValue += " value=\"" + ResponseUtils.filter(ovalue.toString()) + "\"";
            }
            internalValue += ">";
        } else {

            pageContext.setAttribute(id, o);

            final String href = col.getHref();
            pageContext.removeAttribute(id);

            internalValue = InternalTableUtil.getTruncatedString(internalValue, col.getContentTruncate(),
                    col.getType());

            if (href != null) {
                internalValue = "<A HREF='" + href + "'>" + internalValue + "</A>";
            }
        }

        return internalValue;
    } catch (final Exception e) {
        log.error(e, e);

        return null;
    }
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * @return true si la ligne est selectionnable (bean pas besoin d'etre en session)
 *///from  w w  w.j  a v  a  2 s .c  om
private boolean isSelectTr() {
    final String pageAccess = (String) pageContext.getAttribute("access");
    boolean res = false;
    boolean test = false;
    test = !GenericValidator.isBlankOrNull(selectProperty);

    if (test) {
        res = true;

        if (pageAccess.equals(Access.READONLY) && !forceReadWrite) {
            res = false;
        } else {
            res = true;
        }
    }

    return res;
}

From source file:org.squale.welcom.taglib.table.Cols.java

/**
 * @return Nom du formulaire//from ww w.j  ava  2 s.  c om
 */
public String getFormName() {
    if (GenericValidator.isBlankOrNull(formName)) {
        formName = getTable().getFormName();
    }
    return formName;
}

From source file:org.squale.welcom.taglib.table.ColSelect.java

/**
 * @param bean : Bean/*w w  w.j a  va2  s.c  om*/
 * @param position la position de la colonne
 * @param idIndex Index
 * @param style Style
 * @param styleSelect Style selectionne
 * @return le html gnr
 */

public String getSpecificContent(final int position, final Object bean, final int idIndex, final String style,
        final String styleSelect, final int pageLength) {

    String result = null;

    if (bean instanceof WISelectable) {
        if ((!getProperty().equals("")) && (!getProperty().equals("selected"))) {
            result = "Attention, le bean '" + bean.getClass()
                    + "' implmente dj WISelectable, on ne tient donc pas compte de la property '"
                    + getProperty() + "'";
        }
        setProperty("selected");
    } else if (GenericValidator.isBlankOrNull(getProperty())) {
        result = "le bean '" + bean.getClass()
                + "' doit implmenter WISelectable, ou l'attribut property du tag <ColSelect> doit tre renseigner";
    }

    if (result == null) {
        result = writeSpecificContent(bean, idIndex, style, styleSelect);
    }

    return result;
}

From source file:org.squale.welcom.taglib.table.ColSelect.java

/**
 * Ecrit le contenu spcifique/* www .  j  a va2 s . c o  m*/
 * 
 * @param bean bean
 * @param idIndex index
 * @param style style
 * @param styleSelect style select
 * @return le contenu HTML
 */
private String writeSpecificContent(final Object bean, final int idIndex, final String style,
        final String styleSelect) {

    final StringBuffer sb = new StringBuffer();

    String checked = getChecked(bean);

    String name = getCols().getTable().getName();
    String wdt = "";
    String st = style;

    if (isNeedWriteWidth(idIndex)) {
        wdt = " width=\"" + getWidth() + "\"";
    }
    if (WelcomConfigurator.getCharte() == Charte.V2_002) {
        st = "normal";
    }

    if (!GenericValidator.isBlankOrNull(getCols().getTable().getProperty())) {
        name = getCols().getTable().getProperty();
    }

    // Creation du TD
    sb.append("<td ");
    sb.append(wdt);
    sb.append(" classSelect=\"");
    sb.append(styleSelect);
    sb.append("\" classDefault=\"");
    sb.append(style);
    sb.append("\">");

    // Ajout de la gestion auto ...
    if (Util.isFalse(WelcomConfigurator.getMessage(WelcomConfigurator.OPTIFLUX_AUTORESET_CHECKBOX))) {
        sb.append("<input type=\"hidden\" name=\"checkName\" value=\"" + name + "[" + idIndex + "].selected"
                + "\">");
    }

    // Creation de la check box
    sb.append("<input class=\"");
    sb.append(st);
    sb.append("\" type=\"checkbox\" name=\"");
    sb.append(name);
    sb.append("[");
    sb.append(idIndex);
    sb.append("].");
    if (!GenericValidator.isBlankOrNull(getProperty())) {
        sb.append(getProperty());
    } else {
        sb.append("selected");
    }
    sb.append("\" value=\"true\"");

    if (!enableSingleSelect) {
        sb.append("onclick=\"check(this);");
    } else {
        sb.append("onclick=\"checkSingle(this);");
    }
    if (!GenericValidator.isBlankOrNull(onclick)) {
        sb.append(onclick);
    }
    sb.append(";\"");

    if (Util.isTrue(checked)) {
        sb.append(" checked ");
    }

    sb.append("></td>");

    return sb.toString();
}