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

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

Introduction

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

Prototype

public static boolean startsWith(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:com.anrisoftware.globalpom.format.latlong.LongitudeFormat.java

private void formatCoordinate(StringBuffer buff, double d) {
    String s = sexagesimalFormatFactory.create(decimal).format(d);
    if (StringUtils.startsWith(s, "-")) {
        s = s.substring(1);/*w  w  w.ja v  a  2  s.  c  o m*/
    }
    buff.append(s);
    if (signum(d) > 0.0) {
        buff.append(WHITE);
        buff.append(EAST);
    } else {
        buff.append(WHITE);
        buff.append(WEST);
    }
}

From source file:com.nesscomputing.httpserver.log.file.FileRequestLog.java

@Override
public void log(final Request request, final Response response) {
    final String requestUri = request.getRequestURI();

    for (String blackListEntry : blackList) {
        if (StringUtils.startsWith(requestUri, blackListEntry)) {
            return;
        }/*from   w w  w. j  ava 2  s  .  c  o  m*/
    }

    final PrintWriter requestLogWriter = requestLogWriterHolder.get();
    if (requestLogWriter != null) {
        synchronized (this) {
            for (Iterator<String> it = logFields.iterator(); it.hasNext();) {
                // Parse out fields that have parameters e.g. header:X-Trumpet-Track, and print
                String[] chunks = StringUtils.split(it.next(), ":");

                final LogField field = knownFields.get(chunks[0]);
                if (chunks.length == 1) {
                    requestLogWriter.print(ObjectUtils.toString(field.log(request, response, null)));
                } else if (chunks.length == 2) {
                    requestLogWriter.print(ObjectUtils.toString(field.log(request, response, chunks[1])));
                }

                if (it.hasNext()) {
                    requestLogWriter.print("\t");
                }
            }
            requestLogWriter.println();
        }
    }
}

From source file:com.nridge.connector.common.con_com.crawl.CrawlFollow.java

/**
 * Determines if the name parameter matches the list of URIs
 * to follow./*from   w  w  w .  j av  a  2  s.  c  o  m*/
 *
 * @param aName File name (could be a URL).
 *
 * @return <i>true</i> if it matches, <i>false</i> otherwise.
 */
public boolean isMatched(String aName) {
    Logger appLogger = mAppMgr.getLogger(this, "isMatched");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    if (StringUtils.isNotEmpty(aName)) {
        for (String followName : mFollowList) {
            if (StringUtils.startsWith(aName, followName))
                return true;
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return false;
}

From source file:jenkins.plugins.asqatasun.AsqatasunRunner.java

/**
 * //from   ww w . j a v  a2  s  .com
 * @param logFile
 * @param ps
 * @throws IOException 
 */
public void extractDataAndPrintOut(File logFile, PrintStream ps) throws IOException {
    ps.println("");
    boolean isFirstMark = true;
    boolean isFirstNbPassed = true;
    boolean isFirstNbFailed = true;
    boolean isFirstNbFailedOccurences = true;
    boolean isFirstNbNmi = true;
    boolean isFirstNbNa = true;
    boolean isFirstNbNt = true;
    for (Object obj : FileUtils.readLines(logFile)) {
        String line = (String) obj;
        if (StringUtils.startsWith(line, "Subject")) {
            ps.println("");
            ps.println(line);
        } else if (StringUtils.startsWith(line, "Audit terminated")) {
            ps.println(line);
        } else if (StringUtils.startsWith(line, "RawMark")) {
            ps.println(line.replace("RawMark", "Mark"));
            if (isFirstMark) {
                mark = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).replaceAll("%", "")
                        .trim();
                isFirstMark = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Passed")) {
            nbPassed = getNbStatus(ps, isFirstNbPassed, line);
            isFirstNbPassed = false;
        } else if (StringUtils.startsWith(line, "Nb Failed test")) {
            nbFailed = getNbStatus(ps, isFirstNbFailed, line);
            isFirstNbFailed = false;
        } else if (StringUtils.startsWith(line, "Nb Failed occurences")) {
            nbFailedOccurences = getNbStatus(ps, isFirstNbFailedOccurences, line);
            isFirstNbFailedOccurences = false;
        } else if (StringUtils.startsWith(line, "Nb Pre-qualified")) {
            nbNmi = getNbStatus(ps, isFirstNbNmi, line);
            isFirstNbNmi = false;
        } else if (StringUtils.startsWith(line, "Nb Not Applicable")) {
            nbNa = getNbStatus(ps, isFirstNbNa, line);
            isFirstNbNa = false;
        } else if (StringUtils.startsWith(line, "Nb Not Tested")) {
            nbNt = getNbStatus(ps, isFirstNbNt, line);
            isFirstNbNt = false;
        } else if (StringUtils.startsWith(line, "Audit Id")) {
            ps.println(line);
            auditId = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
        }
    }
    ps.println("");
}

From source file:com.wallissoftware.pushstate.client.PushStateHistorianImpl.java

private String stripRelativePath(final String ptoken) {
    final String relPath = this.stripStartSlash(this.relativePath);
    final String token = this.stripStartSlash(ptoken);

    if (StringUtils.startsWith(token, relPath)) {
        return this.stripStartSlash(StringUtils.substring(token, relPath.length()));
    }/*w w  w .  jav a  2s  . c  om*/
    return token;
}

From source file:com.adobe.acs.commons.wcm.vanity.impl.VanityURLServiceImpl.java

/**
 * Checks if the provided vanity path is a valid redirect
 *
 * @param pathScope The content path to scope the vanity path too.
 * @param vanityPath Vanity path that needs to be validated.
 * @param request SlingHttpServletRequest object used for performing query/lookup
 * @return return true if the vanityPath is a registered sling:vanityPath under /content
 *//*from www  .j av a  2s. c  o  m*/
protected boolean isVanityPath(String pathScope, String vanityPath, SlingHttpServletRequest request)
        throws RepositoryException {
    final Resource vanityResource = request.getResourceResolver().resolve(vanityPath);

    if (vanityResource != null) {
        String targetPath = null;

        if (vanityResource.isResourceType("sling:redirect")) {
            targetPath = vanityResource.getValueMap().get("sling:target", String.class);
        } else if (!StringUtils.equals(vanityPath, vanityResource.getPath())) {
            targetPath = vanityResource.getPath();
        }

        if (targetPath != null && StringUtils.startsWith(targetPath,
                StringUtils.defaultIfEmpty(pathScope, DEFAULT_PATH_SCOPE))) {
            log.debug("Found vanity resource at [ {} ] for sling:vanityPath [ {} ]", targetPath, vanityPath);
            return true;
        }
    }

    return false;
}

From source file:com.nridge.core.app.mail.MailManager.java

/**
 * Convenience method that returns the value of an application
 * manager configuration property using the concatenation of
 * the property prefix and suffix values.
 *
 * @param aSuffix Property name suffix./*from   w  w w.  jav  a  2  s.  co m*/
 * @return Matching property value.
 */
public String getCfgString(String aSuffix) {
    String propertyName;

    if (StringUtils.startsWith(aSuffix, "."))
        propertyName = mCfgPropertyPrefix + aSuffix;
    else
        propertyName = mCfgPropertyPrefix + "." + aSuffix;

    return mAppMgr.getString(propertyName);
}

From source file:gobblin.runtime.spec_store.FSSpecStore.java

@Override
public boolean exists(URI specUri) throws IOException {
    Preconditions.checkArgument(null != specUri, "Spec URI should not be null");

    FileStatus[] fileStatuses = fs.listStatus(this.fsSpecStoreDirPath);
    for (FileStatus fileStatus : fileStatuses) {
        if (StringUtils.startsWith(fileStatus.getPath().getName(), specUri.toString())) {
            return true;
        }// w  w  w .  jav a 2  s .  c om
    }

    return false;
}

From source file:com.adeptj.modules.security.jwt.internal.JwtKeys.java

static PublicKey createVerificationKey(SignatureAlgorithm signatureAlgo, String publicKey) {
    LOGGER.info("Creating RSA verification key!!");
    Assert.isTrue(StringUtils.startsWith(publicKey, PUB_KEY_HEADER), INVALID_PUBLIC_KEY_MSG);
    try {// w w  w .  j a va 2 s  .  co m
        KeyFactory keyFactory = KeyFactory.getInstance(signatureAlgo.getFamilyName());
        byte[] publicKeyData = Base64.getDecoder().decode(publicKey.replace(PUB_KEY_HEADER, EMPTY)
                .replace(PUB_KEY_FOOTER, EMPTY).replaceAll(REGEX_SPACE, EMPTY).trim().getBytes(UTF_8));
        LOGGER.info("Creating X509EncodedKeySpec from public key !!");
        return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyData));
    } catch (GeneralSecurityException ex) {
        LOGGER.error(ex.getMessage(), ex);
        throw new KeyInitializationException(ex.getMessage(), ex);
    }
}

From source file:com.nesscomputing.httpserver.log.syslog.SyslogRequestLog.java

@Override
public void log(final Request request, final Response response) {
    if (syslog == null) {
        return;/*ww  w  . j a  v  a2s.  c  o m*/
    }

    final String requestUri = request.getRequestURI();

    for (String blackListEntry : blackList) {
        if (StringUtils.startsWith(requestUri, blackListEntry)) {
            return;
        }
    }

    final String messageId = UUID.randomUUID().toString().replace("-", "");

    final Map<String, Builder<String, String>> builderMap = Maps.newHashMap();

    final Builder<String, String> logBuilder = ImmutableMap.builder();
    builderMap.put("l@" + ianaIdentifier, logBuilder);

    if (galaxyConfig != null) {
        if (galaxyConfig.getEnv().getAgentId() != null) {
            logBuilder.put("si", galaxyConfig.getEnv().getAgentId());
        }
        if (galaxyConfig.getDeploy().getConfig() != null) {
            logBuilder.put("sc", galaxyConfig.getDeploy().getConfig());
        }
    }

    for (Iterator<String> it = logFields.iterator(); it.hasNext();) {
        // Parse out fields that have parameters e.g. header:X-Trumpet-Track, and print
        final String[] chunks = StringUtils.split(it.next(), ":");

        final LogField field = knownFields.get(chunks[0]);
        if (chunks.length == 1) {
            final Object result = field.log(request, response, null);
            if (result != null) {
                logBuilder.put(field.getShortName(), result.toString());
            }
        } else if (chunks.length == 2) {
            final String fieldName = field.getShortName() + "@" + ianaIdentifier;
            Builder<String, String> subBuilder = builderMap.get(fieldName);
            if (subBuilder == null) {
                subBuilder = new Builder<String, String>();
                builderMap.put(fieldName, subBuilder);
            }
            final String fieldKey = chunks[1].toLowerCase(Locale.ENGLISH).replace("=", "_");
            final Object result = field.log(request, response, chunks[1]);
            if (result != null) {
                subBuilder.put(fieldKey, result.toString());
            }
        }
    }

    final String threadName = StringUtils.replaceChars(Thread.currentThread().getName(), " \t", "");

    final StructuredSyslogMessage structuredMessage = new StructuredSyslogMessage(messageId, threadName,
            Maps.transformValues(builderMap, new Function<Builder<String, String>, Map<String, String>>() {
                @Override
                public Map<String, String> apply(final Builder<String, String> builder) {
                    return builder.build();
                }
            }), null);
    syslog.info(structuredMessage);
}