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

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

Introduction

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

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:edu.ku.brc.specify.dbsupport.SpecifySchemaUpdateService.java

/**
 * @param connection//w ww . j  a  v  a  2  s.  c om
 */
public void fixDuplicatedPaleoContexts(final Connection conn) {
    String sql = "SELECT PaleoContextID FROM (SELECT pc.PaleoContextID, COUNT(pc.PaleoContextID) cnt "
            + "FROM paleocontext pc INNER JOIN collectionobject co ON pc.PaleoContextID = co.PaleoContextID "
            + "GROUP BY pc.PaleoContextID) T1 WHERE cnt > 1 ";

    String coSQL = "SELECT CollectionObjectID FROM collectionobject WHERE PaleoContextID = ";

    List<String> pcFieldNames = getFieldNamesFromSchema(conn, "paleocontext");
    String fieldStr = buildSelectFieldList(pcFieldNames, null);
    fieldStr = StringUtils.remove(fieldStr, "PaleoContextID, ");

    StringBuilder sb = new StringBuilder("INSERT INTO paleocontext (");
    sb.append(fieldStr);
    sb.append(") SELECT ");
    sb.append(fieldStr);
    sb.append(" FROM paleocontext WHERE PaleoContextID = ?");

    String updateSQL = sb.toString();
    //System.out.println(updateSQL);

    boolean isErr = false;
    PreparedStatement pStmt = null;
    PreparedStatement pStmt2 = null;
    try {
        pStmt = conn.prepareStatement(updateSQL, Statement.RETURN_GENERATED_KEYS);
        pStmt2 = conn
                .prepareStatement("UPDATE collectionobject SET PaleoContextID=? WHERE CollectionObjectID = ?");

        for (Integer pcId : BasicSQLUtils.queryForInts(conn, sql)) {
            Vector<Integer> colObjIds = BasicSQLUtils.queryForInts(conn, coSQL + pcId);
            for (int i = 1; i < colObjIds.size(); i++) {
                pStmt.setInt(1, pcId);
                int rv = pStmt.executeUpdate();
                if (rv == 1) {
                    Integer newPCId = BasicSQLUtils.getInsertedId(pStmt);
                    pStmt2.setInt(1, newPCId);
                    pStmt2.setInt(2, colObjIds.get(i));
                    rv = pStmt2.executeUpdate();
                    if (rv != 1) {
                        log.error("Error updating co " + colObjIds.get(i));
                        isErr = true;
                    }
                } else {
                    log.error("Error updating pc " + pcId);
                    isErr = true;
                }
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NavigationTreeMgr.class, ex);
    } finally {
        try {
            if (pStmt != null)
                pStmt.close();
            if (pStmt2 != null)
                pStmt2.close();
        } catch (SQLException ex) {
        }
    }

    if (isErr) {
        UIRegistry
                .showError("There was an error updating the duplicated PaleoContexts\nPlease contact support.");
    }
}

From source file:net.sourceforge.openutils.mgnlcriteria.advanced.JcrContainsCriteriaSearchTest.java

@Test
public void testTest1() throws Exception {
    String textEnteredByUser = "test?";
    Criteria criteria = criteria(textEnteredByUser, true);
    Assert.assertEquals(StringUtils.remove(criteria.toXpathExpression(), ' '),
            "//*[((@jcr:primaryType='mgnl:page')and(jcr:contains(@title,'test\\?')))]orderby@jcr:scoredescending");
    AdvancedResult advResult = null;//from ww w. j av a2 s  . com
    try {
        advResult = criteria.execute();
    } catch (JCRQueryException e) {
        Assert.fail("Invalid query. " + e.getMessage());
    }
    Assert.assertNotNull(advResult);
    Assert.assertEquals(advResult.getTotalSize(), 1);
    ResultIterator<? extends Node> items = advResult.getItems();
    Node item = items.next();
    Assert.assertEquals(CriteriaTestUtils.title(item), "hello test? world");
}

From source file:net.sourceforge.openutils.mgnlcriteria.advanced.JcrContainsCriteriaSearchTest.java

@Test
public void testTest2() throws Exception {
    String textEnteredByUser = "te?st";
    Criteria criteria = criteria(textEnteredByUser, true);
    Assert.assertEquals(StringUtils.remove(criteria.toXpathExpression(), ' '),
            "//*[((@jcr:primaryType='mgnl:page')and(jcr:contains(@title,'te\\?st')))]orderby@jcr:scoredescending");
    AdvancedResult advResult = null;// w w w .  ja  v a  2 s .co m
    try {
        advResult = criteria.execute();
    } catch (JCRQueryException e) {
        Assert.fail("Invalid query. " + e.getMessage());
    }
    Assert.assertNotNull(advResult);
    Assert.assertEquals(advResult.getTotalSize(), 1);
    ResultIterator<? extends Node> items = advResult.getItems();
    Node item = items.next();
    Assert.assertEquals(CriteriaTestUtils.title(item), "hello te?st world");
}

From source file:net.sourceforge.openutils.mgnlcriteria.advanced.JcrContainsCriteriaSearchTest.java

@Test
public void testMilano() throws Exception {
    String textEnteredByUser = "\"Milano\"";
    Criteria criteria = criteria(textEnteredByUser, true);
    Assert.assertEquals(StringUtils.remove(criteria.toXpathExpression(), ' '),
            "//*[((@jcr:primaryType='mgnl:page')and(jcr:contains(@title,'\\\"Milano\\\"')))]orderby@jcr:scoredescending");
    AdvancedResult advResult = null;//w w w  .  j a  v  a  2 s  .  com
    try {
        advResult = criteria.execute();
    } catch (JCRQueryException e) {
        Assert.fail("Invalid query. " + e.getMessage());
    }
    Assert.assertNotNull(advResult);
    Assert.assertEquals(advResult.getTotalSize(), 1);
    ResultIterator<? extends Node> items = advResult.getItems();
    Node item = items.next();
    Assert.assertEquals(CriteriaTestUtils.title(item), "hello \"Milano\" world");
}

From source file:net.sourceforge.openutils.mgnlcriteria.advanced.JcrContainsCriteriaSearchTest.java

@Test
public void testColonEscape() throws Exception {
    String textEnteredByUser = "l:u";
    Criteria criteria = criteria(textEnteredByUser, true);
    Assert.assertEquals(StringUtils.remove(criteria.toXpathExpression(), ' '),
            "//*[((@jcr:primaryType='mgnl:page')and(jcr:contains(@title,'l\\:u')))]orderby@jcr:scoredescending");
    AdvancedResult advResult = null;/*from   w  w  w . ja v a  2  s .c  om*/
    try {
        advResult = criteria.execute();
    } catch (JCRQueryException e) {
        Assert.fail("Invalid query. " + e.getMessage());
    }
    Assert.assertNotNull(advResult);
    Assert.assertEquals(advResult.getTotalSize(), 1);
    ResultIterator<? extends Node> items = advResult.getItems();
    Node item = items.next();
    Assert.assertEquals(CriteriaTestUtils.title(item), "hello l:u");
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.CriteriaTest.java

/**
 * Tests the xpath query statement produced by a Criteria instance.
 * @throws Exception/*w w w . j a  v  a 2 s .c  om*/
 */
@Test
public void testToXpathExpression() throws Exception {
    Criteria criteria = toXpathExpressionJavadocExampleCriteria();

    Calendar begin = Calendar.getInstance();
    begin.set(1999, Calendar.JANUARY, 1);
    begin.set(Calendar.HOUR_OF_DAY, 0);
    begin.set(Calendar.MINUTE, 0);
    begin.set(Calendar.SECOND, 0);
    begin.set(Calendar.MILLISECOND, 0);
    Calendar end = Calendar.getInstance();
    end.set(2001, Calendar.DECEMBER, 31);
    end.set(Calendar.HOUR_OF_DAY, 0);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.MILLISECOND, 0);
    end.add(Calendar.MILLISECOND, -1);
    end.add(Calendar.DAY_OF_YEAR, 1);

    String expectedStmt = "//pets//*" + "[((jcr:contains(@title, 'Lucky')) and (@petType='dog')"
            + " and (@birthDate >=xs:dateTime('" + XPathTextUtils.toXsdDate(begin) + "')"
            + " and @birthDate <=xs:dateTime('" + XPathTextUtils.toXsdDate(end) + "')))]"
            + " order by @title descending";

    log.debug(expectedStmt);

    // @birthDate >=xs:dateTime('1999-01-01T00:00:00.000+01:00')
    // and
    // @birthDate <=xs:dateTime('2001-12-31T23:59:59.999+01:00')

    String actualStmt = criteria.toXpathExpression();

    Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' '));
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.ConjunctionTest.java

/**
 * @throws Exception//from w  w w. jav a2 s.c o  m
 */
@Test
public void testImplicitConjunction() throws Exception {
    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
            .setBasePath("/").add(Restrictions.eq("MetaData/@mgnl:template", "t-photogallery-sheet"))
            .add(Restrictions.isNotNull("@playlist")).addOrder(Order.desc("@photogalleryDate"));

    String expectedStmt = "//*" + "[((MetaData/@mgnl:template='t-photogallery-sheet') and @playlist)]"
            + " order by @photogalleryDate descending";
    String actualStmt = criteria.toXpathExpression();
    Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' '));
}

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.ConjunctionTest.java

/**
 * @throws Exception/*from  w  w  w  . j av  a  2s . c  om*/
 */
@Test
public void testExplicitConjunction() throws Exception {
    Junction conjunction = Restrictions.conjunction()
            .add(Restrictions.eq("MetaData/@mgnl:template", "t-photogallery-sheet"))
            .add(Restrictions.isNotNull("@playlist"));
    Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
            .setBasePath("/").add(conjunction).addOrder(Order.desc("@photogalleryDate"));

    String expectedStmt = "//*" + "[(((MetaData/@mgnl:template='t-photogallery-sheet') and @playlist))]"
            + " order by @photogalleryDate descending";
    String actualStmt = criteria.toXpathExpression();
    Assert.assertEquals(StringUtils.remove(actualStmt, ' '), StringUtils.remove(expectedStmt, ' '));
}

From source file:net.unit8.axebomber.parser.TableHeader.java

public TableHeader(Range range) {
    this.sheet = range.getSheet().getSubstance();
    for (int rowIndex = range.getFirstRowNum(); rowIndex <= range.getLastRowNum(); rowIndex++) {
        String currentLabel = null;
        int colLastIndex = Math.min(this.sheet.getRow(rowIndex).getLastCellNum(), range.getLastColumnNum());
        int colFirstIndex = Math.max(this.sheet.getRow(rowIndex).getFirstCellNum(), range.getFirstColumnNum());
        for (int colIndex = colFirstIndex; colIndex <= colLastIndex; colIndex++) {
            Cell cell = range.getSheet().cell(colIndex, rowIndex);
            String value = StringUtils.remove(StringUtils.trim(cell.toString()), "\n");
            if (StringUtils.isNotBlank(value)) {
                currentLabel = value;/*from   www .ja  v  a  2s . com*/
                labelColumns.put(currentLabel, colIndex);
            }
            if (StringUtils.isNotBlank(currentLabel)) {
                String parentLabel = columnLabels.get(colIndex);
                if (parentLabel != null) {
                    List<String> children = labelRelations.get(parentLabel);
                    if (children == null) {
                        children = new ArrayList<String>();
                        labelRelations.put(parentLabel, children);
                    }
                    if (!children.contains(currentLabel))
                        children.add(currentLabel);
                }
                columnLabels.put(colIndex, currentLabel);
            }
        }
    }
    this.labelRowIndex = range.getLastRowNum();
}

From source file:net.unit8.axebomber.parser.TableHeader.java

private void scanColumnLabel(Cell beginCell) {
    int rowIndex = beginCell.getRowIndex();
    org.apache.poi.ss.usermodel.Row row = sheet.getRow(rowIndex);
    String currentValue = null;//from w ww . j  a  v a2s . c  om
    for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
        Cell cell = getCell(i, rowIndex);
        if (cell == null)
            continue;
        String label = StringUtils.remove(StringUtils.trim(cell.toString()), "\n");
        if (!cell.toString().equals("")) {
            labelColumns.put(label, i);
            currentValue = label;
        }
        if (currentValue != null)
            columnLabels.put(i, currentValue);
    }
}