Example usage for org.apache.commons.lang StringUtils stripEnd

List of usage examples for org.apache.commons.lang StringUtils stripEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils stripEnd.

Prototype

public static String stripEnd(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the end of a String.

Usage

From source file:org.apache.ivory.entity.FeedHelper.java

public static String normalizePartitionExpression(String part1, String part2) {
    String partExp = StringUtils.stripToEmpty(part1) + "/" + StringUtils.stripToEmpty(part2);
    partExp = partExp.replaceAll("//+", "/");
    partExp = StringUtils.stripStart(partExp, "/");
    partExp = StringUtils.stripEnd(partExp, "/");
    return partExp;
}

From source file:org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableFormLayoutRenderer.java

/**
 * Calculate the widths of each column based on the description of width and
 * columns attributes//  w  w w  . j  a  v  a  2s  .c o m
 * 
 * @return List of widths for each column
 */
public String[] _getColumnWidths(FacesBean bean) {

    if (this._getWidth(bean) == null) {
        return null;
    }
    if (this._getWidth(bean).equals("")) {
        return null;
    }
    String columns = this._getColumns(bean);

    String[] sw = StringUtils.split(columns, ';');
    if (sw.length == 0) {
        return null;
    }
    String[] widths = new String[sw.length];

    double absolutePixels = 0; // Defines how many absolute space has
    double maxRelative = 0;

    for (int i = 0; i < sw.length; i++) {
        String col = sw[i];
        if (StringUtils.contains(col, '*')) {
            String col1 = StringUtils.stripEnd(col, "*");
            sw[i] = col1; // remove *
            try {
                Double relative = Double.parseDouble(col1);
                widths[i] = null;
                maxRelative += relative;
            } catch (NumberFormatException e) {
                widths[i] = "-2";
            }
        } else {
            // Measures in pixels, let it as is
            widths[i] = col;
            absolutePixels += Double.parseDouble(col);
        }
    }

    Double cellspacing = null;
    try {
        cellspacing = Double.parseDouble("" + this._getCellspacing(bean));
    } catch (NumberFormatException e) {
        cellspacing = 0d;
    }

    if (_isPercentWidth(bean)) {
        //Calculate as relative width
        Double width = null;
        width = Double.parseDouble("" + this._getWidthValue(bean));
        // Now calculate the widths based on
        double actualwidth = 0;
        double remainingspace = 100d;
        for (int i = 0; i < sw.length; i++) {
            String col = sw[i];
            String col1 = widths[i];

            if (col1 == null) {
                if (remainingspace > 0) {
                    widths[i] = ""
                            + (new Double(remainingspace * Double.parseDouble(col) / maxRelative).intValue())
                            + "%";
                } else {
                    // Nothing happens
                    widths[i] = "0";
                }
            } else {
                // Nothing happens
                actualwidth = actualwidth + Double.parseDouble(StringUtils.stripEnd(col1, "%"));
            }
        }

    } else {
        //Calculate as absolute width
        Double width = null;
        try {
            width = Double.parseDouble("" + this._getWidth(bean));
            // Now calculate the widths based on
            double actualwidth = cellspacing;
            double remainingspace = width - absolutePixels - (cellspacing * (sw.length + 1));
            for (int i = 0; i < sw.length; i++) {
                String col = sw[i];
                String col1 = widths[i];

                if (col1 == null) {
                    if (remainingspace > 0) {
                        widths[i] = "" + (new Double(remainingspace * Double.parseDouble(col) / maxRelative)
                                .intValue());
                    } else {
                        // Nothing happens
                        widths[i] = "0";
                    }
                } else {
                    // Nothing happens
                    actualwidth = actualwidth + Double.parseDouble(col1) + cellspacing;
                }
            }
        } catch (NumberFormatException e) {
            for (int i = 0; i < sw.length; i++) {
                //String col = sw[i];
                String col1 = widths[i];
                if (col1 == null) {

                } else {
                    // Nothing happens
                }
            }
        }
    }
    return widths;
}

From source file:org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableFormLayoutRenderer.java

public String[] _getRowHeights(FacesBean bean) {
    if (this._getHeight(bean) == null) {
        return null;
    }//from w  w w  .j ava2  s.  c o  m
    if (this._getHeight(bean).equals("")) {
        return null;
    }
    String rows = this._getRows(bean);

    String[] sw = StringUtils.split(rows, ';');
    if (sw.length == 0) {
        return null;
    }
    String[] heights = new String[sw.length];

    double absolutePixels = 0; // Defines how many absolute space has
    double maxRelative = 0;

    for (int i = 0; i < sw.length; i++) {
        String col = sw[i];
        if (StringUtils.contains(col, '*')) {
            String col1 = StringUtils.stripEnd(col, "*");
            sw[i] = col1; // remove *
            try {
                Double relative = Double.parseDouble(col1);
                heights[i] = null;
                maxRelative += relative;
            } catch (NumberFormatException e) {
                heights[i] = "-2";
            }
        } else {
            // Measures in pixels, let it as is
            heights[i] = col;
            absolutePixels += Double.parseDouble(col);
        }
    }

    Double cellspacing = null;
    try {
        cellspacing = Double.parseDouble("" + this._getCellspacing(bean));
        cellspacing = 0d;
    } catch (NumberFormatException e) {
        cellspacing = 0d;
    }

    Double height = null;
    try {
        height = Double.parseDouble("" + this._getHeight(bean));
        // Now calculate the heights based on
        double actualheight = cellspacing;
        double remainingspace = height - absolutePixels - (cellspacing * (sw.length + 1));
        for (int i = 0; i < sw.length; i++) {
            String col = sw[i];
            String col1 = heights[i];

            if (col1 == null) {
                if (remainingspace > 0) {
                    heights[i] = ""
                            + (new Double(remainingspace * Double.parseDouble(col) / maxRelative).intValue());
                } else {
                    // Nothing happens
                    heights[i] = "0";
                }
            } else {
                // Nothing happens
                actualheight = actualheight + Double.parseDouble(col1) + cellspacing;
            }
        }
    } catch (NumberFormatException e) {
        for (int i = 0; i < sw.length; i++) {
            //String col = sw[i];
            String col1 = heights[i];
            if (col1 == null) {

            } else {
                // Nothing happens
            }
        }
    } catch (NullPointerException e) {

    }
    return heights;
}

From source file:org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableFormLayoutRenderer.java

@SuppressWarnings("unchecked")
private void _encodeFormColumns(FacesContext context, RenderingContext arc, UIComponent component,
        FacesBean bean, ResponseWriter rw, FormItemInfo visibleFormItemInfo, List<FormItem> visibleItems)
        throws IOException {

    if (visibleItems.isEmpty())
        return;//from  ww w.j a v a 2s.co m

    String[] columnWidths = this._getColumnWidths(bean);

    // List columnWidths = (List) component.getAttributes().get(
    // START COLUMN DEFINE

    if (columnWidths != null) {
        rw.startElement("colgroup", null);
        for (int i = 0; i < columnWidths.length; i++) {
            if (columnWidths[i] != null) {
                if (_isPercentWidth(bean)) {
                    int cellWidth = ((Integer) Integer.parseInt(StringUtils.stripEnd(columnWidths[i], "%")))
                            .intValue();
                    if (cellWidth != -2) {
                        // cellWidth += getCellPadding(context, component,
                        // i);
                        rw.startElement("col", null);
                        rw.writeAttribute("width", columnWidths[i], null);
                        rw.endElement("col");
                    }
                } else {
                    int cellWidth = ((Integer) Integer.parseInt(columnWidths[i])).intValue();
                    if (cellWidth != -2) {
                        // cellWidth += getCellPadding(context, component,
                        // i);
                        rw.startElement("col", null);
                        rw.writeAttribute("width", Integer.toString(cellWidth), null);
                        rw.endElement("col");
                    }
                }
            }

        }
        rw.endElement("colgroup");
    }

    rw.startElement("thead", null);
    rw.startElement("tr", null);
    for (int i = 0; i < columnWidths.length; i++) {

        if (columnWidths[i] != null) {
            if (_isPercentWidth(bean)) {
                int cellWidth = ((Integer) Integer.parseInt(StringUtils.stripEnd(columnWidths[i], "%")))
                        .intValue();
                if (cellWidth != -2) {
                    rw.startElement("td", null);
                    rw.writeAttribute("width", columnWidths[i], null);
                    rw.endElement("td");
                }
            } else {
                int cellWidth = ((Integer) Integer.parseInt(columnWidths[i])).intValue();
                if (cellWidth != -2) {
                    // cellWidth += getCellPadding(context, component,
                    // i);
                    rw.startElement("td", null);
                    rw.writeAttribute("width", Integer.toString(cellWidth), null);
                    rw.endElement("td");
                }
            }
        }

    }
    rw.endElement("tr");
    rw.endElement("thead");
    // END COLUMN DEFINE

    rw.startElement("tbody", null); // the outer tbody

    //START ROW DEFINE
    List<Row> rows = visibleFormItemInfo.getLayoutRows();

    String[] rowHeights = this._getRowHeights(bean);
    //String[] columnWidths = this._getColumnWidths(bean);

    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        Row row = rows.get(rowIndex);

        if (!row.isHidden()) {
            rw.startElement("tr", null);
            renderStyleClass(context, arc, AF_TABLE_FORM_COLUMN_STYLE_CLASS);

            if (rowHeights != null) {
                rw.writeAttribute("height", rowHeights[rowIndex], null);
            }

            List cells = row.getElements();

            int numColumn = 0; // This is for count the actual column for
            // set the width of the cell

            for (int columnIndex = 0; columnIndex < cells.size(); columnIndex++) {
                Object object = cells.get(columnIndex);
                if (object.toString().equals(TableFormLayoutRenderer.USED)) {
                    continue; // ignore the markers UIGridLayout.Used
                }
                if (object.equals(TableFormLayoutRenderer.FREE)) {
                    continue;
                }
                UIComponent cell = (UIComponent) object;

                if (!cell.isRendered()) {
                    continue;
                }

                int spanX = 1;
                int spanY = 1;

                //LOG.info("CELL:" + cell.toString());
                //LOG.info("Renderer:" + cell.getRendererType());
                //String rendererType = cell.getRendererType();               
                if (LabelAndMessageRenderer.class.isAssignableFrom(context.getRenderKit()
                        .getRenderer(cell.getFamily(), cell.getRendererType()).getClass())) {
                    spanX = this.getSpanXLabel(cell) + this.getSpanXItem(cell);
                    spanY = this.getSpanY(cell);
                } else {
                    spanX = this.getSpanX(cell);
                    spanY = this.getSpanY(cell);
                }

                String cw = this.calculateSize(bean, columnWidths, numColumn, spanX);

                if (columnWidths != null) {
                    numColumn += spanX;
                }

                String ch = this.calculateSize(bean, rowHeights, rowIndex, spanY);

                rw.startElement("td", null);
                rw.writeAttribute("colspan", spanX, null);
                rw.writeAttribute("rowspan", spanY, null);

                rw.startElement("table", cell);
                if (_isPercentWidth(bean)) {
                    OutputUtils.renderLayoutTableAttributes(context, arc, "0", "0", "100%");
                } else {
                    OutputUtils.renderLayoutTableAttributes(context, arc, "0", "0", cw);
                }
                renderStyleClass(context, arc, AF_TABLE_FORM_CONTENT_CELL_STYLE_CLASS);
                //rw.writeAttribute("width", cw, null);

                rw.startElement("tr", null);
                rw.startElement("td", cell);
                rw.startElement("div", cell);

                String style = (String) cell.getAttributes().get("style");
                if (style != null) {
                    String cad = "";
                    if (columnWidths != null) {
                        cad = ";width:" + cw + "px";
                    }
                    if (rowHeights != null) {
                        cad += ";height:" + ch + "px";
                    }
                    //System.out.println("SET:" + style + cad);
                    cell.getAttributes().put("style", style + cad);

                } else {
                    String cad = "";
                    if (columnWidths != null) {
                        cad = ";width:" + cw + "px";
                    }
                    if (rowHeights != null) {
                        cad += ";height:" + ch + "px";
                    }
                    // System.out.println("SET:" + style + ";width:" + cw
                    // + "px" + ";height:" + ch + "px");
                    cell.getAttributes().put("style", cad);
                }
                rw.startElement("table", null); // inner table
                OutputUtils.renderLayoutTableAttributes(context, arc, "0", "0", "100%");

                if (LabelAndMessageRenderer.class.isAssignableFrom(context.getRenderKit()
                        .getRenderer(cell.getFamily(), cell.getRendererType()).getClass())) {
                    if (_isPercentWidth(bean)) {

                        String labelWidth = this.calculateSize(bean, columnWidths, numColumn - spanX,
                                this.getSpanXLabel(cell));
                        String fieldWidth = this.calculateSize(bean, columnWidths,
                                numColumn - this.getSpanXItem(cell), this.getSpanXItem(cell));

                        int maxPercentWidth = Integer.parseInt(StringUtils.stripEnd(labelWidth, "%"))
                                + Integer.parseInt(StringUtils.stripEnd(fieldWidth, "%"));

                        rw.startElement("colgroup", null);
                        rw.startElement("col", null);
                        rw.writeAttribute("width", (Integer.parseInt(StringUtils.stripEnd(labelWidth, "%"))
                                * 100 / maxPercentWidth) + "%", null);
                        rw.endElement("col");
                        rw.startElement("col", null);
                        rw.writeAttribute("width", (Integer.parseInt(StringUtils.stripEnd(fieldWidth, "%"))
                                * 100 / maxPercentWidth) + "%", null);
                        rw.endElement("col");
                        rw.endElement("colgroup");

                        rw.startElement("thead", null);
                        rw.startElement("tr", null);
                        rw.startElement("td", null);
                        rw.writeAttribute("width", (Integer.parseInt(StringUtils.stripEnd(labelWidth, "%"))
                                * 100 / maxPercentWidth) + "%", null);
                        rw.endElement("td");
                        rw.startElement("td", null);
                        rw.writeAttribute("width", (Integer.parseInt(StringUtils.stripEnd(fieldWidth, "%"))
                                * 100 / maxPercentWidth) + "%", null);
                        rw.endElement("td");
                        rw.endElement("tr");
                        rw.endElement("thead");
                    } else {
                        rw.startElement("colgroup", null);
                        rw.startElement("col", null);
                        rw.writeAttribute("width", this.calculateSize(bean, columnWidths, numColumn - spanX,
                                this.getSpanXLabel(cell)), null);
                        rw.endElement("col");
                        rw.startElement("col", null);
                        rw.writeAttribute("width", this.calculateSize(bean, columnWidths,
                                numColumn - this.getSpanXItem(cell), this.getSpanXItem(cell)), null);
                        rw.endElement("col");
                        rw.endElement("colgroup");

                        rw.startElement("thead", null);
                        rw.startElement("tr", null);
                        rw.startElement("td", null);
                        rw.writeAttribute("width", this.calculateSize(bean, columnWidths, numColumn - spanX,
                                this.getSpanXLabel(cell)), null);
                        rw.endElement("td");
                        rw.startElement("td", null);
                        rw.writeAttribute("width", this.calculateSize(bean, columnWidths,
                                numColumn - this.getSpanXItem(cell), this.getSpanXItem(cell)), null);
                        rw.endElement("td");
                        rw.endElement("tr");
                        rw.endElement("thead");
                    }
                }

                rw.startElement("tbody", null); // inner tbody

                String rowHeight = this.calculateSize(bean, rowHeights, rowIndex, spanY);
                rw.startElement("tr", null); // label row                    
                renderStyleClass(context, arc, AF_TABLE_FORM_CONTENT_CELL_STYLE_CLASS);

                if (!rowHeight.equals("0")) {
                    rw.writeAttribute("height", rowHeight, null);
                }

                //Now i have to modify inlineContentStyle to add height value
                if (LabelAndMessageRenderer.class.isAssignableFrom(context.getRenderKit()
                        .getRenderer(cell.getFamily(), cell.getRendererType()).getClass())) {
                    FacesBean cbean = getFacesBean(cell);

                    FacesBean.Type ctype = cbean.getType();

                    PropertyKey _cstyle = ctype.findKey("contentStyle");

                    String cstyle = (String) cbean.getProperty(_cstyle);
                    //LOG.info("contentStyle:"+cstyle);

                    if (!StringUtils.contains(cstyle, "height")) {
                        if (!rowHeight.equals("0")) {
                            cbean.setProperty(_cstyle,
                                    (cstyle == null ? "" : cstyle) + ";height: " + rowHeight + "px");
                        }
                    }

                    cstyle = (String) cbean.getProperty(_cstyle);

                    if (!StringUtils.contains(cstyle, "width")) {
                        /*
                        Integer colWidth = Integer
                            .parseInt(this.calculateSize(bean,
                                    columnWidths, numColumn
                                            - this.getSpanXItem(cell),
                                    this.getSpanXItem(cell)))
                            - (this.getSpanXItem(cell) == 1 ? this
                                    ._getCellspacing(bean) : 0) - 3;
                        */
                        cbean.setProperty(_cstyle, (cstyle == null ? "" : cstyle) + ";width: 100%"); // + colWidth + "px" //100%
                    }

                    _encodeFormItem2(context, arc, rw, false, cell);
                } else {
                    rw.startElement("td", null);
                    _encodeFormItem2(context, arc, rw, false, cell);
                    rw.endElement("td");
                }

                rw.endElement("tr"); // field row
                rw.endElement("tbody"); // inner tbody
                rw.endElement("table"); // inner table

                rw.endElement("div");
                rw.endElement("td");
                rw.endElement("tr");

                rw.endElement("table");
                rw.endElement("td");

            }
            rw.endElement("tr");
        }
    }
}

From source file:org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableFormLayoutRenderer.java

public String calculateSize(FacesBean bean, String[] sizes, int num, int span) {
    String cw = "0";
    if (sizes != null) {
        //LOG.debug("calculateSize:" + sizes.toString() + " " + num + " "
        //        + span);
        if (span == 1) {
            cw = sizes[num];/* www. j av  a 2 s. co  m*/
            //numColumn++;
        } else {
            if (_isPercentWidth(bean)) {
                int cw1 = 0;
                for (int i = num; i < num + span; i++) {
                    cw1 += Integer.parseInt(StringUtils.stripEnd(sizes[i], "%"));
                }
                //cw1 = cw1 + this._getCellspacing(bean) * (span - 1);
                cw = "" + cw1;
            } else {
                int cw1 = 0;
                for (int i = num; i < num + span; i++) {
                    cw1 += Integer.parseInt(sizes[i]);
                }
                cw1 = cw1 + this._getCellspacing(bean) * (span - 1);
                cw = "" + cw1;
            }
        }
    }
    return cw;
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Create a new sequence from the information in the schema metadata.
 */// w w w .ja  va  2  s.c  om
protected Sequence newSequence(ResultSet sequenceMeta) throws SQLException {
    Sequence seq = new Sequence();
    seq.setSchemaIdentifier(fromDBName(StringUtils.stripEnd(sequenceMeta.getString("SEQUENCE_SCHEMA"), null),
            DBIdentifierType.SCHEMA));
    seq.setIdentifier(fromDBName(StringUtils.stripEnd(sequenceMeta.getString("SEQUENCE_NAME"), null),
            DBIdentifierType.SEQUENCE));
    return seq;
}

From source file:org.apache.openjpa.util.StringId.java

public StringId(Class<?> cls, String key) {
    super(cls);
    this.key = (key == null) ? "" : StringUtils.stripEnd(key, null);
}

From source file:org.apache.openjpa.util.StringId.java

public StringId(Class<?> cls, String key, boolean subs) {
    super(cls, subs);
    this.key = (key == null) ? "" : StringUtils.stripEnd(key, null);
}

From source file:org.apache.tajo.datum.TimestampDatum.java

@Override
public String asChars() {
    if (getMillisOfSecond() > 0) {
        return StringUtils.stripEnd(dateTime.toString(FRACTION_FORMATTER), "0");
    } else {// w  w  w  .j  ava  2 s  .c  o m
        return dateTime.toString(DEFAULT_FORMATTER);
    }
}

From source file:org.apache.tajo.engine.function.string.RTrim.java

@Override
public Datum eval(Tuple params) {
    if (params.isBlankOrNull(0)) {
        return NullDatum.get();
    }/*from   w w  w  . ja va2 s . c o  m*/

    String value = params.getText(0);
    if (!hasTrimCharacters) {
        return DatumFactory.createText(StringUtils.stripEnd(value, null));
    } else {
        return DatumFactory.createText(StringUtils.stripEnd(value, params.getText(1)));
    }
}