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

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

Introduction

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

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:com.hybris.datahub.core.util.OutboundServiceCsvUtilsUnitTest.java

@Test
public void testConvertMapToCsv_ShouldHandleNullValues() {
    testProductMap.put("propertyWithNullValue", null);
    final String[] objArray = csvUtils.convertMapToCsv(testProductMap);

    Assert.assertEquals(2, objArray.length);
    Assert.assertTrue(StringUtils.contains(objArray[0], "propertyWithNullValue"));
    Assert.assertTrue(StringUtils.contains(objArray[1], ",,"));
}

From source file:edu.ku.brc.specify.toycode.RegAdder.java

/**
 * @param trackId//from   w  w  w .  j  a va2  s.com
 * @param mv
 * @param pStmt
 * @throws SQLException
 */
private void doTrackInserts(final int trackId, final HashMap<String, String> mv, final PreparedStatement pStmt)
        throws SQLException {
    for (String key : mv.keySet()) {
        String value = mv.get(key);
        pStmt.setString(1, key);
        if (!StringUtils.contains(value, ".") && StringUtils.isNumeric(value) && value.length() < 10) {
            pStmt.setInt(2, Integer.parseInt(value));
            pStmt.setNull(3, java.sql.Types.VARCHAR);

        } else if (value.length() < STR_SIZE + 1) {
            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, value);

        } else {
            String v = value.substring(0, STR_SIZE);
            System.err.println(
                    "Error - On line " + lineNo + " Value[" + value + "] too big trunccating to[" + v + "]");

            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, v);
        }
        pStmt.setInt(4, trackId);

        //System.out.println(pStmt2.toString());

        int rv = pStmt.executeUpdate();
        if (rv != 1) {
            for (String k : mv.keySet()) {
                System.out.println("[" + k + "][" + mv.get(k) + "]");
            }
            System.err.println("------------------------ Line No: " + lineNo);
            throw new RuntimeException("Error insert trackitem for Id: " + trackId);
        }
    }
}

From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java

public static boolean isNumberType(String rdbType) {
    if (rdbType == null)
        return false;

    // ??  ?? ?  ?.. decimal(8) 
    if (StringUtils.contains(rdbType, "(")) {
        rdbType = StringUtils.substringBefore(rdbType, "(");
    }//  w  ww  .  j  av  a 2 s  .  c o  m

    Integer intType = mapTypes.get(rdbType.toUpperCase());

    if (intType == null)
        return false;

    return isNumberType(intType);
}

From source file:com.datastax.driver.core.ExceptionsTest.java

/**
 * Tests DriverInternalError./*from   w  ww.  j  ava 2s. c  o m*/
 * Tests basic message, rethrow, and copy abilities.
 */
@Test(groups = "integration")
public void driverInternalError() throws Exception {
    String errorMessage = "Test Message";

    try {
        throw new DriverInternalError(errorMessage);
    } catch (DriverInternalError e1) {
        try {
            throw new DriverInternalError(e1);
        } catch (DriverInternalError e2) {
            assertTrue(StringUtils.contains(e2.getMessage(), errorMessage));

            DriverInternalError copy = (DriverInternalError) e2.copy();
            assertEquals(copy.getMessage(), e2.getMessage());
        }
    }
}

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.converter.impl.DefaultImpexConverter.java

protected boolean doesNotContainNewLine(final String string) {
    return !StringUtils.contains(string, CharUtils.LF);
}

From source file:edu.monash.merc.system.remote.HttpHpaFileGetter.java

public boolean importHPAXML(String remoteFile, String localFile) {
    //use httpclient to get the remote file
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(remoteFile);

    ZipInputStream zis = null;/*from w ww  .  j  av  a2  s .co m*/
    FileOutputStream fos = null;
    try {
        HttpResponse response = httpClient.execute(httpGet);
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream in = entity.getContent();
                zis = new ZipInputStream(in);
                ZipEntry zipEntry = zis.getNextEntry();
                while (zipEntry != null) {
                    String fileName = zipEntry.getName();
                    if (StringUtils.contains(fileName, HPA_FILE_NAME)) {
                        System.out.println("======= found file.");
                        File aFile = new File(localFile);
                        fos = new FileOutputStream(aFile);
                        byte[] buffer = new byte[BUFFER_SIZE];
                        int len;
                        while ((len = zis.read(buffer)) > 0) {
                            fos.write(buffer, 0, len);
                        }
                        fos.flush();
                        break;
                    }
                }
            }
        } else {
            throw new DMRemoteException("can't get the file from " + remoteFile);
        }
    } catch (Exception ex) {
        throw new DMRemoteException(ex);
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
            if (zis != null) {
                zis.closeEntry();
                zis.close();
            }
            httpClient.getConnectionManager().shutdown();
        } catch (Exception e) {
            //ignore whatever caught
        }
    }
    return true;
}

From source file:com.acc.controller.StoreFinderController.java

protected List<PointOfServiceData> filterOptions(final String options,
        final StoreFinderSearchPageData<PointOfServiceData> result) {
    List<PointOfServiceData> results = null;
    if (!StringUtils.contains(options, "HOURS")) {
        results = Lists.transform(result.getResults(), new Function<PointOfServiceData, PointOfServiceData>() {

            @Override/*from w ww  .  j  ava 2 s .co m*/
            public PointOfServiceData apply(@Nullable final PointOfServiceData input) {
                input.setOpeningHours(null);
                input.setUrl(null);
                return input;
            }
        });
    } else {
        results = result.getResults();
    }
    return results;
}

From source file:com.adobe.acs.commons.search.impl.NodeExistsPredicateEvaluator.java

@Override
@SuppressWarnings("squid:S3776")
public final boolean includes(final Predicate predicate, final Row row, final EvaluationContext context) {
    boolean or = predicate.getBool(OR);

    if (log.isDebugEnabled()) {
        if (or) {
            log.debug("NodeExistsPredicatorEvaluator evaluating as [ OR ]");
        } else {/*  www  .ja  v  a2 s .co m*/
            log.debug("NodeExistsPredicatorEvaluator evaluating as [ AND ]");
        }
    }

    for (final Map.Entry<String, String> entry : predicate.getParameters().entrySet()) {
        boolean ruleIncludes = false;

        String operation = entry.getKey();
        if (StringUtils.contains(operation, "_")) {
            operation = StringUtils.substringAfterLast(entry.getKey(), "_");
        }

        try {
            if (EXISTS_REL_PATH.equals(operation)) {
                ruleIncludes = row.getNode().hasNode(entry.getValue());
            } else if (NOT_EXISTS_REL_PATH.equals(operation)) {
                ruleIncludes = !row.getNode().hasNode(entry.getValue());
            } else if (!OR.equals(operation)) {
                log.debug("Invalid operation [ {} ]", operation);
            }

            // Return quickly from the evaluation loop
            if (or && ruleIncludes) {
                // If OR condition; return true on the first condition match
                if (log.isDebugEnabled()) {
                    log.debug("Including [ {} ] based on [ {}  -> {} ] as part of [ OR ]", row.getPath(),
                            operation, entry.getValue());
                }
                return true;
            } else if (!or && !ruleIncludes) {
                // If AND condition; return true on the first condition failure
                if (log.isDebugEnabled()) {
                    log.debug("Excluding [ {} ] based on [ {}  -> {} ] as part of [ AND ]", row.getPath(),
                            operation, entry.getValue());
                }

                return false;
            }
        } catch (RepositoryException e) {
            log.error("Unable to check if Node [ {} : {} ] via the nodeExists QueryBuilder predicate",
                    new String[] { entry.getKey(), entry.getValue() }, e);
        }
    }

    if (or) {
        // For ORs, if a true condition was met in the loop, the method would have already returned true, so must be false.
        if (log.isDebugEnabled()) {
            try {
                log.debug("Excluding [ {} ] based on NOT matching conditions as part of [ OR ]", row.getPath());
            } catch (RepositoryException e) {
                log.error("Could not obtain path from for Result row in predicate evaluator", e);
            }
        }
        return false;
    } else {
        // If ANDs, if a false condition was met in the loop, the method would have already returned false, so must be true.
        if (log.isDebugEnabled()) {
            try {
                log.debug("Include [ {} ] based on ALL matching conditions as part of [ AND ]", row.getPath());
            } catch (RepositoryException e) {
                log.error("Could not obtain path from for Result row in predicate evaluator", e);
            }
        }
        return true;
    }
}

From source file:com.edgenius.wiki.render.MarkupUtil.java

/**
 * Add slash "\" before any markup keyword. The reverse method is escapeMarkupToEntity();
 * /*  w  w w  .j  av  a2 s  .c  om*/
 * OK, this method looks complicated now(2009/05/05).  Because input escText may include some uniqueKey, which is replacement of HTML tag.
 * These uniqueKey won't be calculated into leadNonWord or endNonWord,i.e., not as border. For example, 
 * 
 * my text uniqueK[text]uniqueK has key. (Originally, this text looks like "my text <p>[text]</p> has key.", P tag is replace into uniqueK)
 * 
 * Markup [text] won't be treat as surrounding by 'K' and 'u'.  It will be ' '. So the second parameter of this method, skippedTagKey, 
 * will be skipped during processing.  
 * 
 * @param escText
 * @return
 */
public static String escapeMarkupToSlash(String escText, String skippedTagKey) {
    //plus "\" as it is keyword for escape
    if (StringUtils.isBlank(escText))
        return escText;

    StringBuffer sb = new StringBuffer();
    int len = escText.length();

    //use \n as first start, means text start. 
    char lastCh = '\n';
    //text start, leadNonWord is true
    boolean leadNonWord = true;
    boolean endNonWord = true;

    char[] skipped = (skippedTagKey == null || skippedTagKey.length() == 0) ? null
            : skippedTagKey.toCharArray();
    for (int idx = 0; idx < len; idx++) {
        if (skipped != null) {
            //try to see if the following piece of string is skipped key or not. 
            //if it is skipped key, then just append key to result and continue.
            StringBuffer skipBuf = skipKey(escText, idx, skipped);
            if (skipBuf != null) {
                sb.append(skipBuf);
                idx += skipBuf.length() - 1;
                continue;
            }
        }

        char ch = escText.charAt(idx);
        if (StringUtils.contains(FilterRegxConstants.FILTER_ANYTEXT_KEYWORD, ch)) {
            sb.append("\\").append(ch);
        } else if (leadNonWord && StringUtils.contains(FilterRegxConstants.FILTER_SURR_NON_WORD_KEYWORD, ch)) {
            sb.append("\\").append(ch);
        } else if (lastCh == '\n'
                && StringUtils.contains(FilterRegxConstants.FILTER_ONLYLINESTART_KEYWORD, ch)) {
            sb.append("\\").append(ch);
        } else {
            //check if this char is tailed by non-word character 
            //assume ch is last char, endNonWord is true then
            if (StringUtils.contains(FilterRegxConstants.FILTER_SURR_NON_WORD_KEYWORD, ch)) {
                endNonWord = true;
                StringBuffer skipBuf = null;
                if (idx < len - 1) {
                    //get next char to check if this non-word
                    if (skipped != null) {
                        skipBuf = skipKey(escText, idx + 1, skipped);
                        if (skipBuf != null) {
                            idx += skipBuf.length();
                        }
                    }
                    //need check idx again as it modified if skipBuf is not empty
                    if (idx < len - 1) {
                        char nextCh = escText.charAt(idx + 1);
                        endNonWord = FilterRegxConstants.NON_WORD_PATTERN
                                .matcher(Character.valueOf(nextCh).toString()).matches();
                    }
                }
                if (endNonWord) {
                    sb.append("\\").append(ch);
                } else {
                    sb.append(ch);
                }
                if (skipBuf != null)
                    sb.append(skipBuf);
            } else {
                sb.append(ch);
            }
        }
        leadNonWord = FilterRegxConstants.NON_WORD_PATTERN.matcher(Character.valueOf(ch).toString()).matches();
        lastCh = ch;
    }
    //next line is very rough escape, now replace by above exact escape
    //EscapeUtil.escapeBySlash(escText,(FilterRegxConstants.FILTER_KEYWORD+"\\").toCharArray());
    return sb.toString();
}

From source file:gemlite.core.webapp.pages.file.JarFilePage.java

@RequestMapping(value = "/deploy")
    @ResponseBody//from ww w . j  a  va 2 s  . com
    public String deploy(@RequestParam("deployId") long deployId) {
        JarFileService service = JpaContext.getService(JarFileService.class);

        ReleasedJarFile jarFile = service.getFileById(deployId);
        ActiveFileId activeFile = service.findActiveByName(jarFile.getModuleName());
        //    if (activeFile != null && activeFile.getFileId() == jarFile.getFileId())
        //      return model;
        if (activeFile == null)
            activeFile = new ActiveFileId();
        activeFile.setFileId(jarFile.getFileId());
        activeFile.setModuleName(jarFile.getModuleName());
        activeFile.setModuleType(jarFile.getModuleType());
        service.updateActiveFileId(activeFile);

        DeployParameter param = new DeployParameter(jarFile.getModuleName(), jarFile.getModuleType(),
                jarFile.getContent());
        Object result = FunctionUtil.deploy(param);
        LogUtil.getCoreLog().info("deploy->" + result);
        //?result
        if (StringUtils.contains(result.toString(), "success")) {
            jarFile.setUpdate_count(jarFile.getUpdate_count() + 1);
            service.save(jarFile);
            return "success";
        } else
            return result.toString();
    }