Example usage for org.apache.commons.lang3 StringUtils deleteWhitespace

List of usage examples for org.apache.commons.lang3 StringUtils deleteWhitespace

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils deleteWhitespace.

Prototype

public static String deleteWhitespace(final String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

 StringUtils.deleteWhitespace(null)         = null StringUtils.deleteWhitespace("")           = "" StringUtils.deleteWhitespace("abc")        = "abc" StringUtils.deleteWhitespace("   ab  c  ") = "abc" 

Usage

From source file:org.wrml.runtime.schema.generator.SchemaGenerator.java

private JavaBytecodeMethod generateMethod(final String name, final JavaBytecodeType returnType,
        final JavaBytecodeType argumentType, final JavaBytecodeAnnotation... annotations) {

    final JavaBytecodeMethod method = new JavaBytecodeMethod();
    method.setName(StringUtils.deleteWhitespace(name));
    method.setDescriptor(generateMethodDescriptor(returnType, argumentType));
    method.setSignature(generateMethodSignature(returnType, argumentType));
    addAnnotations(method, annotations);
    return method;
}

From source file:org.wso2.analytics.esb.siddhi.extension.CompressedEventProcessor.java

/**
 * Get the definition of the output fields
 * //from  w  ww.  ja v  a2  s.c  om
 * @return  Name and type of decompressed fields
 */
private static Map<String, String> getOutputFields() {
    Map<String, String> fields = new LinkedHashMap<String, String>();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        String[] lines = IOUtils.toString(classLoader.getResourceAsStream("decompressedEventDefinition"))
                .split("\n");
        for (String line : lines) {
            if (!StringUtils.startsWithIgnoreCase(line, "#") && StringUtils.isNotEmpty(line)) {
                String[] fieldDef = StringUtils.deleteWhitespace(line).split(":");
                if (fieldDef.length == 2) {
                    fields.put(fieldDef[0], fieldDef[1]);
                }
            }
        }
    } catch (IOException e) {
        new ExecutionPlanCreationException(
                "Error occured while reading decompressed event definitions: " + e.getMessage(), e);
    }
    return fields;
}

From source file:org.zanata.action.ProjectHome.java

/**
 * Check the name by removing any whitespaces in the string and
 * make sure it contains at least an alphanumeric char
 *///from w w w .ja  v  a 2 s  .  co m
public boolean isValidName(String name) {
    String trimmedName = StringUtils.deleteWhitespace(name);
    for (char c : trimmedName.toCharArray()) {
        if (Character.isDigit(c) || Character.isLetter(c)) {
            return true;
        }
    }
    return false;
}

From source file:rapture.repo.UnversionedRepoTest.java

@Test
public void testNoMetaDelete() throws InterruptedException {
    String docURI = TEST_REPO_URI1 + "/toDelete2.json";

    UnversionedRepo repo = (UnversionedRepo) Kernel.INSTANCE.getRepo(TEST_REPO_URI1.substring(2));
    KeyStore docStore = UnversionedTestHelper.getDocStore(repo.getMetaHandler());
    String docPath = new RaptureURI(docURI, Scheme.DOCUMENT).getDocPath();
    docStore.put(docPath, defContent);/*from  w  w w.j a  v a2s  . c om*/

    DocumentWithMeta dm = Kernel.getDoc().getDocAndMeta(ctx, docURI);
    assertEquals(StringUtils.deleteWhitespace(defContent), StringUtils.deleteWhitespace(dm.getContent()));
    assertEquals(docPath, dm.getDisplayName());
    assertNull(dm.getMetaData());

    Long beforeDelete = beforeAndSleep();
    Kernel.getDoc().deleteDoc(ctx, docURI);
    Long afterDelete = afterAndSleep();

    dm = Kernel.getDoc().getDocAndMeta(ctx, docURI);
    assertNull(dm.getContent());
    assertEquals(docPath, dm.getDisplayName());
    assertNotNull(dm.getMetaData());

    assertTrue(beforeDelete < dm.getMetaData().getCreatedTimestamp());
    assertTrue(afterDelete > dm.getMetaData().getCreatedTimestamp());
    assertEquals(dm.getMetaData().getModifiedTimestamp(), dm.getMetaData().getCreatedTimestamp());
    assertTrue(dm.getMetaData().getDeleted());
    assertEquals(-1, dm.getMetaData().getVersion().intValue());

}

From source file:scan.Scan.java

/**
 * cleanString method. This method is passed a string of text, the 'dirty string' and returns a 
 * 'cleaned string'. The cleaning process involves removing white spaces, accents and making all
 * characters lowercase. This process could be extend to remove punctuation as well.  
 * //from  www .  j  a  va 2  s  . c  om
 * The purpose of this process is simplify matching between two strings.
 * 
 * @param dirtySrString a string that is unprocessed and is to be cleaned
 * @return returns a string that has been cleaned
 */
protected String cleanString(String dirtySrString) {
    String cleanString;
    cleanString = StringUtils.lowerCase(dirtySrString);
    cleanString = StringUtils.deleteWhitespace(cleanString);
    cleanString = StringUtils.stripAccents(cleanString);
    return cleanString;
}

From source file:tw.edu.chit.struts.action.util.AjaxLicenseCodeSearch.java

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    AdminManager am = (AdminManager) ac.getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);

    String licenseNameOrCode = request.getParameter("code").replaceAll("\\|", "");
    int limit = StringUtils.isBlank(request.getParameter("l")) ? -1
            : Integer.parseInt(request.getParameter("l"));
    response.setContentType("text/xml;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");

    if (StringUtils.isNotBlank(licenseNameOrCode)) {

        LicenseCode code = new LicenseCode();
        code.setName("%" + licenseNameOrCode + "%");
        Example example = Example.create(code).ignoreCase().enableLike(MatchMode.ANYWHERE);
        List<Order> orders = new LinkedList<Order>();
        orders.add(Order.asc("code"));
        List<LicenseCode> codes = (List<LicenseCode>) am.findSQLWithCriteria(LicenseCode.class, example, null,
                orders, limit);//from   w  w  w. j a v  a 2s  .c  o m

        if (codes.isEmpty()) {
            code = new LicenseCode();
            try {
                code.setCode(licenseNameOrCode);
                example = Example.create(code).ignoreCase().enableLike(MatchMode.START);
                codes = (List<LicenseCode>) am.findSQLWithCriteria(LicenseCode.class, example, null, orders,
                        limit);
            } catch (Exception e) {
                code.setCode(null);
                example = Example.create(code).ignoreCase().enableLike(MatchMode.START);
                codes = (List<LicenseCode>) am.findSQLWithCriteria(LicenseCode.class, example, null, orders,
                        limit);
            }

        }

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        buffer.append("<message>");
        String tmpStr = null;
        for (LicenseCode lc : codes) {
            // ?"&"?
            tmpStr = String.format("%s|%s|%s", StringUtils.trimToEmpty(lc.getCode().toString()),
                    StringUtils.replace(StringUtils.replace(
                            StringUtils.replace(StringUtils.trimToEmpty(lc.getName()), "", "("), "", ")"),
                            "&", ""),
                    StringUtils.deleteWhitespace(StringUtils.trimToEmpty(lc.getLevel())));
            buffer.append("<name>").append(tmpStr).append("</name>");
        }

        buffer.append("</message>");
        //System.out.println(buffer.toString());
        response.getWriter().write(buffer.toString());
    } else {
        response.getWriter().write("");
    }

}

From source file:ubic.gemma.core.datastructure.matrix.ExpressionDataWriterUtils.java

public static String constructBioAssayName(BioMaterial bioMaterial, Collection<BioAssay> bioAssays) {
    String colBuf = (bioMaterial.getName() + DELIMITER_BETWEEN_BIOMATERIAL_AND_BIOASSAYS)
            + StringUtils.join(bioAssays, ".");

    String colName = StringUtils.deleteWhitespace(colBuf);

    return constructRCompatibleBioAssayName(colName);
}

From source file:uk.co.q3c.v7.base.navigate.TextReaderSitemapProvider.java

/**
 * process a line of text from the file into the appropriate section
 * //from   w  w  w  . j  a va2s  . co m
 * @param line
 */
private void divideIntoSections(String line, int linenum) {
    String strippedLine = StringUtils.deleteWhitespace(line);
    if (strippedLine.startsWith("#")) {
        commentLines++;
        return;
    }
    if (Strings.isNullOrEmpty(strippedLine)) {
        blankLines++;
        return;
    }
    if (strippedLine.startsWith("[")) {
        if ((!strippedLine.endsWith("]"))) {
            log.warn("section requires closing ']' at line " + linenum);
        } else {
            String sectionName = strippedLine.substring(1, strippedLine.length() - 1);

            List<String> section = new ArrayList<>();
            try {
                SectionName key = SectionName.valueOf(sectionName);
                currentSection = key;
                sections.put(key, section);
            } catch (IllegalArgumentException iae) {
                log.warn(
                        "Invalid section '{}' in site map file, this section has been ignored. Only sections {} are allowed.",
                        sectionName, getSections().toString());
            }

        }
        return;
    }

    List<String> section = sections.get(currentSection);
    if (section != null) {
        section.add(strippedLine);
    }

}

From source file:uk.org.funcube.fcdw.server.processor.DataProcessor.java

@Transactional(readOnly = false)
@RequestMapping(value = "/{siteId}/", method = RequestMethod.POST)
public ResponseEntity<String> uploadData(@PathVariable String siteId,
        @RequestParam(value = "digest") String digest, @RequestBody String body) {

    // get the user from the repository
    List<UserEntity> users = userDao.findBySiteId(siteId);

    if (users.size() != 0) {

        String hexString = StringUtils.substringBetween(body, "=", "&");
        hexString = hexString.replace("+", " ");

        String authKey = userAuthKeys.get(siteId);
        final UserEntity user = users.get(0);

        try {//www  . j  av a  2 s .  c o  m

            if (authKey == null) {
                if (user != null) {
                    authKey = user.getAuthKey();
                    userAuthKeys.put(siteId, authKey);
                } else {
                    LOG.error(USER_WITH_SITE_ID + siteId + NOT_FOUND);
                    return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED);
                }
            }

            final String calculatedDigest = calculateDigest(hexString, authKey, null);
            final String calculatedDigestUTF8 = calculateDigest(hexString, authKey, new Integer(8));
            final String calculatedDigestUTF16 = calculateDigest(hexString, authKey, new Integer(16));

            if (null != digest && (digest.equals(calculatedDigest) || digest.equals(calculatedDigestUTF8))
                    || digest.equals(calculatedDigestUTF16)) {

                hexString = StringUtils.deleteWhitespace(hexString);

                final int frameId = Integer.parseInt(hexString.substring(0, 2), 16);
                final int frameType = frameId & 63;
                final int satelliteId = (frameId & (128 + 64)) >> 6;
                final int sensorId = frameId % 2;
                final String binaryString = convertHexBytePairToBinary(
                        hexString.substring(2, hexString.length()));
                final Date now = clock.currentDate();
                final RealTime realTime = new RealTime(satelliteId, frameType, sensorId, now, binaryString);
                final long sequenceNumber = realTime.getSequenceNumber();

                if (sequenceNumber != -1) {

                    final List<HexFrameEntity> frames = hexFrameDao
                            .findBySatelliteIdAndSequenceNumberAndFrameType(satelliteId, sequenceNumber,
                                    frameType);

                    HexFrameEntity hexFrame = null;

                    if (frames != null && frames.size() == 0) {
                        hexFrame = new HexFrameEntity((long) satelliteId, (long) frameType, sequenceNumber,
                                hexString, now, true);

                        hexFrame.getUsers().add(user);

                        hexFrameDao.save(hexFrame);

                        RealTimeEntity realTimeEntity = new RealTimeEntity(realTime);

                        realTimeDao.save(realTimeEntity);

                    } else {
                        hexFrame = frames.get(0);

                        hexFrame.getUsers().add(user);

                        hexFrameDao.save(hexFrame);
                    }
                }

                return new ResponseEntity<String>("OK", HttpStatus.OK);
            } else {
                LOG.error(USER_WITH_SITE_ID + siteId + HAD_INCORRECT_DIGEST + ", received: " + digest
                        + ", calculated: " + calculatedDigest);
                return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED);
            }
        } catch (final Exception e) {
            LOG.error(e.getMessage());
            return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
        }

    } else {
        LOG.error("Site id: " + siteId + " not found in database");
        return new ResponseEntity<String>("UNAUTHORIZED", HttpStatus.UNAUTHORIZED);
    }

}

From source file:uk.q3c.krail.core.navigate.sitemap.DefaultFileSitemapLoader.java

/**
 * process a line of text from the file into the appropriate section
 *
 * @param line//from   w w  w .  ja v  a 2s  . c  o  m
 */
private void divideIntoSections(String source, String line, int linenum) {
    String strippedLine = StringUtils.deleteWhitespace(line);
    if (strippedLine.startsWith("#")) {
        commentLines++;
        return;
    }
    if (Strings.isNullOrEmpty(strippedLine)) {
        blankLines++;
        return;
    }
    if (strippedLine.startsWith("[")) {
        if ((!strippedLine.endsWith("]"))) {
            addWarning(source, SECTION_MISSING_CLOSING, linenum);
        } else {
            String sectionName = strippedLine.substring(1, strippedLine.length() - 1);

            List<String> section = new ArrayList<>();
            try {
                SectionName key = SectionName.valueOf(sectionName);
                currentSection = key;
                sections.put(key, section);
            } catch (IllegalArgumentException iae) {
                addWarning(source, SECTION_NOT_VALID_FOR_SITEMAP, sectionName, getSections().toString());
            }

        }
        return;
    }

    List<String> section = sections.get(currentSection);
    if (section != null) {
        section.add(strippedLine);
    }

}