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

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

Introduction

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

Prototype

public static String stripToNull(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

Usage

From source file:com.activecq.samples.replication.impl.ReverseReplicatorImpl.java

private boolean isWhitelisted(final Resource resource) {
    if (pathWhitelist.length <= 0) {
        return true;
    }/*from   ww  w. j  a va2  s  .  c o m*/

    for (String regex : pathWhitelist) {
        if (StringUtils.stripToNull(regex) == null) {
            continue;
        }

        log.debug("White : " + regex + " vs " + resource.getPath());

        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(resource.getPath());
        if (m.find()) {
            return true;
        }
    }

    return false;
}

From source file:com.adobe.acs.tools.tag_maker.impl.TagMakerServlet.java

private InputStream stripLineEnds(InputStream is, String charset, char chartoStrip) throws IOException {
    log.debug("Stripping [ {} ] from the end of lines.", chartoStrip);

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
        String line = StringUtils.stripToNull(lineIterator.next());
        if (line != null) {
            line = StringUtils.stripEnd(line, String.valueOf(chartoStrip));
            printStream.println(line);// w  ww  .  j  ava 2  s.c o  m
        }
    }

    return new ByteArrayInputStream(baos.toByteArray());
}

From source file:com.adobe.acs.commons.forms.helpers.impl.PostFormHelperImpl.java

/**
 * Gets the Form Selector for the form POST request
 *
 * @param slingRequest//from  ww w .  jav a2 s  . co m
 * @return
 */
public String getFormSelector(final SlingHttpServletRequest slingRequest) {
    final String requestSuffix = slingRequest.getRequestPathInfo().getSuffix();
    if (StringUtils.equals(requestSuffix, this.getSuffix())
            || !StringUtils.startsWith(requestSuffix, this.getSuffix() + "/")) {
        return null;
    }

    final int segments = StringUtils.split(this.getSuffix(), '/').length;
    if (segments < 1) {
        return null;
    }

    final String formSelector = PathInfoUtil.getSuffixSegment(slingRequest, segments);
    return StringUtils.stripToNull(formSelector);
}

From source file:com.activecq.samples.replication.impl.ReverseReplicatorImpl.java

private boolean isBlacklisted(Resource resource) {
    if (pathBlacklist.length <= 0) {
        return false;
    }/*w  ww. j  a va 2s.c  o m*/

    for (String regex : pathBlacklist) {
        if (StringUtils.stripToNull(regex) == null) {
            continue;
        }

        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(resource.getPath());
        if (m.find()) {
            return true;
        }
    }

    return false;
}

From source file:com.activecq.samples.replication.impl.ReverseReplicatorImpl.java

private boolean hasValidPrimaryType(Resource resource) {
    if (primaryTypes.length <= 0) {
        return true;
    }//  w  ww. j a va2  s  .  co  m

    ValueMap properties = resource.adaptTo(ValueMap.class);

    for (final String primaryType : primaryTypes) {
        if (StringUtils.stripToNull(primaryType) == null) {
            continue;
        }

        String tmp = properties.get(JcrConstants.JCR_PRIMARYTYPE, String.class);
        log.debug("PT : " + tmp + " vs " + primaryType);
        if (StringUtils.equals(primaryType, tmp)) {
            return true;
        }
    }

    return false;
}

From source file:com.activecq.samples.replication.impl.ReverseReplicatorImpl.java

private boolean hasValidProperty(Resource resource) {
    if (propertyMatches.isEmpty()) {
        return true;
    }/*w w  w . j a v a  2  s.c o  m*/
    // Removal event
    if (resource.adaptTo(Node.class) == null) {
        return true;
    }

    ValueMap properties = resource.adaptTo(ValueMap.class);

    for (final String property : propertyMatches.keySet()) {
        if (StringUtils.stripToNull(property) == null) {
            continue;
        }

        final String value = (String) propertyMatches.get(property);

        if (properties.containsKey(property)) {
            String tmp = properties.get(property, String.class);
            if (StringUtils.equals(value, tmp)) {
                log.debug("Expected(" + property + ": " + value + ") -> Actual(" + property + ": " + tmp + ")");
                return true;
            }
        }
    }

    return false;
}

From source file:com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Find the JCR full path to the most appropriate Error Page.
 *
 * @param request/*from w w w  .ja  v  a 2 s.  c o m*/
 * @param errorResource
 * @return
 */
@Override
@SuppressWarnings("squid:S3776")
public String findErrorPage(SlingHttpServletRequest request, Resource errorResource) {
    if (!isEnabled()) {
        return null;
    }

    final String errorsPath = findErrorsPath(request, errorResource);

    Resource errorPage = null;
    if (StringUtils.isNotBlank(errorsPath)) {
        final ResourceResolver resourceResolver = errorResource.getResourceResolver();
        final String errorPath = errorsPath + "/" + getErrorPageName(request);
        errorPage = getResource(resourceResolver, errorPath);

        if (errorPage == null && StringUtils.isNotBlank(errorsPath)) {
            log.trace(
                    "No error-specific errorPage could be found, use the 'default' error errorPage for the Root content path");
            errorPage = resourceResolver.resolve(errorsPath);
        }
    }

    String errorPagePath = null;
    if (errorPage == null || ResourceUtil.isNonExistingResource(errorPage)) {
        log.trace("no custom error page could be found");
        if (this.hasSystemErrorPage()) {
            errorPagePath = this.getSystemErrorPagePath();
            log.trace("using system error page [ {} ]", errorPagePath);
        }
    } else {
        errorPagePath = errorPage.getPath();
    }

    if (errorImagesEnabled && this.isImageRequest(request)) {

        if (StringUtils.startsWith(this.errorImagePath, "/")) {
            // Absolute path
            return this.errorImagePath;
        } else if (StringUtils.isNotBlank(errorPagePath)) {
            // Selector or Relative path; compute path based off found error page

            if (StringUtils.startsWith(this.errorImagePath, ".")) {
                final String selectorErrorImagePath = errorPagePath + this.errorImagePath;
                log.debug("Using selector-based error image: {}", selectorErrorImagePath);
                return selectorErrorImagePath;
            } else {
                final String relativeErrorImagePath = errorPagePath + "/"
                        + StringUtils.removeStart(this.errorImagePath, "/");
                log.debug("Using relative path-based error image: {}", relativeErrorImagePath);
                return relativeErrorImagePath;
            }
        } else {
            log.warn("Error image path found, but no error page could be found so relative path cannot "
                    + "be applied: {}", this.errorImagePath);
        }
    } else if (StringUtils.isNotBlank(errorPagePath)) {
        errorPagePath = StringUtils.stripToNull(applyExtension(errorPagePath));
        log.debug("Using resolved error page: {}", errorPagePath);
        return errorPagePath;
    } else {
        log.debug("ACS AEM Commons Error Page Handler is enabled but mis-configured. A valid error image"
                + " handler nor a valid error page could be found.");
    }
    return null;
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Escapes JCR node names for search; Especially important for nodes that start with numbers
 *
 * @param name//from w  w  w . j  a  v a 2 s. co  m
 * @return
 */
private String escapeNodeName(String name) {
    name = StringUtils.stripToNull(name);
    if (name == null) {
        return "";
    }

    return ISO9075.encode(name);
}

From source file:com.feedzai.commons.sql.abstraction.engine.impl.MySqlEngine.java

@Override
protected void dropFks(final String table) throws DatabaseEngineException {
    String schema = StringUtils.stripToNull(properties.getSchema());
    ResultSet rs = null;//from w  w  w. j a v  a  2 s . c o m
    try {
        getConnection();
        rs = conn.getMetaData().getImportedKeys(null, schema, table);
        Set<String> fks = new HashSet<String>();
        while (rs.next()) {
            fks.add(rs.getString("FK_NAME"));
        }
        for (String fk : fks) {
            try {
                executeUpdate(String.format("alter table %s drop foreign key %s",
                        quotize(table, escapeCharacter()), quotize(fk, escapeCharacter())));
            } catch (Exception e) {
                logger.warn("Could not drop foreign key '{}' on table '{}'", fk, table);
                logger.debug("Could not drop foreign key.", e);
            }
        }
    } catch (Exception e) {
        throw new DatabaseEngineException("Error dropping foreign key", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception a) {
            logger.trace("Error closing result set.", a);
        }
    }
}

From source file:com.adobe.acs.tools.csv_asset_importer.impl.CsvAssetImporterServlet.java

/**
 * Adds a populated terminating field to the ends of CSV entries.
 * If the last entry in a CSV row is empty, the CSV library has difficulty understanding that is the end of the row.
 *
 * @param is        the CSV file as an inputstream
 * @param separator The field separator/*  www  .j  a  v a2  s  . c  o  m*/
 * @param charset   The charset
 * @return An inputstream that is the same as is, but each line has a populated line termination entry
 * @throws IOException
 */
private InputStream terminateLines(final InputStream is, final char separator, final String charset)
        throws IOException {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
        String line = StringUtils.stripToNull(lineIterator.next());

        if (line != null) {
            line += separator + TERMINATED;
            printStream.println(line);
        }
    }

    return new ByteArrayInputStream(baos.toByteArray());
}