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:fr.penet.beans.RunsBean.java

protected void startTitleStatsCommon(URL urlJob, int runId) throws IOException, SQLException {
    message = "";
    BufferedReader reader = new BufferedReader(new InputStreamReader(urlJob.openStream()));
    String line;/*from   w  w  w . ja v a2s .c  om*/
    final String PREFIX = "Mapper started. Job id : ";
    String jobId = null;
    while ((line = reader.readLine()) != null) {
        if (StringUtils.startsWith(line, PREFIX)) {
            jobId = line.substring(PREFIX.length());
            break;
        }
    }
    reader.close();
    if (jobId == null) {
        message = "Error starting job";
        return;
    }
    CrawlMapReduceJob job = CrawlMapReduceJob.builder().runId(runId).appengineMRId(jobId).build();
    job.insert(conn);
    message = "Job " + jobId + " started";
}

From source file:io.wcm.handler.url.impl.Externalizer.java

/**
 * Checks if the given URL is already externalized.
 * For this check some heuristics are applied.
 * @param url URL/*from   ww  w.  j  a va  2  s .  co m*/
 * @return true if path is already externalized.
 */
public static boolean isExternalized(String url) {
    return StringUtils.contains(url, "://") // protocol detected
            || StringUtils.startsWith(url, "//") // protocol-relative mode detected
            || StringUtils.startsWith(url, "mailto:") // mailto link detected
            || StringUtils.startsWith(url, "#"); // anchor or integrator placeholder detected
}

From source file:glluch.com.ontotaxoseeker.FreelingTagger.java

/**
 * Given a freeling list of senteces processes it and return all the nouns in the list.
 * @param ls a freeling list of senteces.
 * @return Terms, all the nouns terms in the sentences.
 *//*w  w  w. j a  v  a  2s  .co  m*/
protected static Terms tagOnlyNouns(ListSentence ls) throws IOException {
    Terms terms = new Terms();
    //debug("freelingtager tagOnlyNouns");
    ListSentenceIterator sIt = new ListSentenceIterator(ls);
    while (sIt.hasNext()) {
        Sentence s = sIt.next();
        ListWordIterator wIt = new ListWordIterator(s);
        while (wIt.hasNext()) {
            Word w = wIt.next();
            //debug(w.getLemma()+" "+w.getTag());
            if (StringUtils.startsWith(w.getTag(), "N")) {
                Term t = new Term(w);
                terms.addOne(t);
            }

        }

    }

    TestsGen.save(terms);

    return terms;

}

From source file:com.glaf.base.modules.sys.interceptor.AuthorizeInterceptor.java

/**
 * // w  ww. j a  va2  s . c  o m
 * 
 * @param methodName
 * @param ip
 * @param flag
 */
private void createLog(String account, String methodName, String ip, int flag) {
    if (StringUtils.startsWith(methodName, "org.springframework.web.servlet.view")) {
        return;
    }
    SysLog log = new SysLog();
    SysUser user = (SysUser) ContextUtil.get(account);
    if (user != null) {
        log.setAccount(user.getName() + "[" + user.getAccount() + "]");
        log.setIp(ip);
        log.setCreateTime(new Date());
        log.setOperate(methodName);
        log.setFlag(flag);
        try {
            ISysLogService logService = ContextFactory.getBean("sysLogService");
            logService.create(log);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }
}

From source file:com.nridge.core.ds.rdbms.SQLTable.java

/**
 * If the auto-naming feature is enabled against the SQL connection,
 * then this method will return an updated table name based on the
 * DB name assigned to the field bag.  Otherwise, it simply returns
 * the DB name./*  w  w w . ja  v  a 2  s. c  om*/
 *
 * @param aBag Bag of fields.
 *
 * @return Table name.
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 */
public String schemaName(DataBag aBag) throws NSException {
    String dbName = aBag.getName();
    if (StringUtils.isEmpty(dbName))
        throw new NSException("The name for the data bag is undefined.");

    String tableName;
    if ((mSQLConnection.isAutoNamingEnabled()) && (!StringUtils.startsWith(dbName, NS_TABLE_PREFIX)))
        tableName = String.format("%s_%s", NS_TABLE_PREFIX, dbName);
    else
        tableName = dbName;

    return tableName;
}

From source file:com.nridge.connector.common.con_com.publish.PSolr.java

/**
 * Convenience method that returns the value of a property using
 * the concatenation of the property prefix and suffix values.
 * If the property is not found, then the default value parameter
 * will be returned./*from ww  w . j ava  2s.com*/
 *
 * @param aSuffix Property name suffix.
 * @param aDefaultValue Default value.
 *
 * @return Matching property value or the default value.
 */
private String getCfgString(String aSuffix, String aDefaultValue) {
    String propertyName;

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

    return mAppMgr.getString(propertyName, aDefaultValue);
}

From source file:ch.cyberduck.core.ftp.FTPListResponseReader.java

@Override
public AttributedList<Path> read(final Path directory, final List<String> replies,
        final ListProgressListener listener)
        throws IOException, FTPInvalidListException, ConnectionCanceledException {
    final AttributedList<Path> children = new AttributedList<Path>();
    // At least one entry successfully parsed
    boolean success = false;
    // Call hook for those implementors which need to perform some action upon the list after it has been created
    // from the server stream, but before any clients see the list
    parser.preParse(replies);/*  ww w .j  av a 2 s . c  o  m*/
    for (String line : replies) {
        final FTPFile f = parser.parseFTPEntry(line);
        if (null == f) {
            continue;
        }
        final String name = f.getName();
        if (!success) {
            if (lenient) {
                // Workaround for #2410. STAT only returns ls of directory itself
                // Workaround for #2434. STAT of symbolic link directory only lists the directory itself.
                if (directory.getName().equals(name)) {
                    log.warn(String.format("Skip %s matching parent directory name", f.getName()));
                    continue;
                }
                if (name.contains(String.valueOf(Path.DELIMITER))) {
                    if (!name.startsWith(directory.getAbsolute() + Path.DELIMITER)) {
                        // Workaround for #2434.
                        log.warn(String.format("Skip %s with delimiter in name", name));
                        continue;
                    }
                }
            }
        }
        success = true;
        if (name.equals(".") || name.equals("..")) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Skip %s", f.getName()));
            }
            continue;
        }
        final Path parsed = new Path(directory, PathNormalizer.name(name),
                f.getType() == FTPFile.DIRECTORY_TYPE ? EnumSet.of(Path.Type.directory)
                        : EnumSet.of(Path.Type.file));
        switch (f.getType()) {
        case FTPFile.SYMBOLIC_LINK_TYPE:
            parsed.setType(EnumSet.of(Path.Type.file, Path.Type.symboliclink));
            // Symbolic link target may be an absolute or relative path
            final String target = f.getLink();
            if (StringUtils.isBlank(target)) {
                log.warn(String.format("Missing symbolic link target for %s", parsed));
                final EnumSet<AbstractPath.Type> type = parsed.getType();
                type.remove(AbstractPath.Type.symboliclink);
            } else if (StringUtils.startsWith(target, String.valueOf(Path.DELIMITER))) {
                parsed.setSymlinkTarget(new Path(target, EnumSet.of(Path.Type.file)));
            } else if (StringUtils.equals("..", target)) {
                parsed.setSymlinkTarget(directory);
            } else if (StringUtils.equals(".", target)) {
                parsed.setSymlinkTarget(parsed);
            } else {
                parsed.setSymlinkTarget(new Path(directory, target, EnumSet.of(Path.Type.file)));
            }
            break;
        }
        if (parsed.isFile()) {
            parsed.attributes().setSize(f.getSize());
        }
        parsed.attributes().setOwner(f.getUser());
        parsed.attributes().setGroup(f.getGroup());
        Permission.Action u = Permission.Action.none;
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) {
            u = u.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)) {
            u = u.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            u = u.or(Permission.Action.execute);
        }
        Permission.Action g = Permission.Action.none;
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) {
            g = g.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)) {
            g = g.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            g = g.or(Permission.Action.execute);
        }
        Permission.Action o = Permission.Action.none;
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)) {
            o = o.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)) {
            o = o.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            o = o.or(Permission.Action.execute);
        }
        final Permission permission = new Permission(u, g, o);
        if (f instanceof FTPExtendedFile) {
            permission.setSetuid(((FTPExtendedFile) f).isSetuid());
            permission.setSetgid(((FTPExtendedFile) f).isSetgid());
            permission.setSticky(((FTPExtendedFile) f).isSticky());
        }
        parsed.attributes().setPermission(permission);
        final Calendar timestamp = f.getTimestamp();
        if (timestamp != null) {
            parsed.attributes().setModificationDate(timestamp.getTimeInMillis());
        }
        children.add(parsed);
    }
    if (!success) {
        throw new FTPInvalidListException(children);
    }
    return children;
}

From source file:kenh.xscript.Environment.java

/**
 * Load element packages from system properties.
 * If system property has name starts with <code>kenh.xscript.element.packages</code>,
 * it will be loaded by xScript./*from  w  w w .j  a v  a2 s  .  c  o  m*/
 */
private void loadElementPackages_SystemProperties() {
    Properties p = System.getProperties();
    Set keys = p.keySet();
    for (Object key_ : keys) {
        if (key_ instanceof String) {
            String key = (String) key_;
            if (StringUtils.startsWith(key, ELEMENTS_PATH_PREFIX + ".")) {
                String name = StringUtils.substringAfter(key, ELEMENTS_PATH_PREFIX + ".");
                String funcPackage = p.getProperty(key);
                setElementPackage(name, funcPackage);
            }
        }
    }
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.ValueConverterTest.java

@Test
public void testDate() {
    assertTrue(StringUtils.startsWith(underTest.toString("prop", sampleDate), "{Date}2010-09-05T15:10:20"));
}

From source file:alfio.manager.FileUploadManager.java

private Map<String, String> getAttributes(UploadBase64FileModification file) {
    if (!StringUtils.startsWith(file.getType(), "image/")) {
        return Collections.emptyMap();
    }/*from   ww  w .  j a v a 2s .  c o m*/

    try {
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(file.getFile()));
        Map<String, String> attributes = new HashMap<>();
        attributes.put(FileBlobMetadata.ATTR_IMG_WIDTH, String.valueOf(image.getWidth()));
        attributes.put(FileBlobMetadata.ATTR_IMG_HEIGHT, String.valueOf(image.getHeight()));
        return attributes;
    } catch (IOException e) {
        log.error("error while processing image: ", e);
        return Collections.emptyMap();
    }
}