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:cgeo.geocaching.connector.oc.OCApiConnector.java

public void addAuthentication(final Parameters params) {
    if (StringUtils.isBlank(cK)) {
        throw new IllegalStateException(
                "empty OKAPI OAuth token for host " + getHost() + ". fix your keys.xml");
    }/*  w w  w. j  a va  2s .co  m*/
    final String rotCK = CryptUtils.rot13(cK);
    // check that developers are not using the Ant defined properties without any values
    if (StringUtils.startsWith(rotCK, "${")) {
        throw new IllegalStateException(
                "invalid OKAPI OAuth token '" + rotCK + "' for host " + getHost() + ". fix your keys.xml");
    }
    params.put(CryptUtils.rot13("pbafhzre_xrl"), rotCK);
}

From source file:com.erudika.para.storage.AWSFileStore.java

@Override
public InputStream load(String path) {
    if (StringUtils.startsWith(path, "/")) {
        path = path.substring(1);/*w  w  w. j  a va2  s  .  co  m*/
    }
    if (!StringUtils.isBlank(path)) {
        S3Object file = s3.getObject(bucket, path);
        return file.getObjectContent();
    }
    return null;
}

From source file:com.github.ferstl.depgraph.graph.style.StyleKey.java

private static boolean wildcardMatch(String value1, String value2) {
    if (StringUtils.endsWith(value1, "*")) {
        return StringUtils.startsWith(value2, value1.substring(0, value1.length() - 1));
    }// w w w  .j  a  va 2s. com

    return match(value1, value2);
}

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

/**
 * Returns a schema name for index objects based on the DB name
 * assigned to the bag and the persistent field.
 *
 * @param aBag Field bag with DB name assigned.
 * @param aField Field to base the index name on.
 *
 * @return Schema name of the index object.
 *
 * @throws NSException Catch-all exception for any SQL related issue.
 *//* w w w  . j  a v a 2  s .  com*/
public String schemaName(DataBag aBag, DataField aField) throws NSException {
    String dbName = aBag.getName();
    if (StringUtils.isEmpty(dbName))
        throw new NSException("The name for the persistent bag is undefined.");

    String indexName;
    String fieldName = aField.getName();
    if (mSQLConnection.isAutoNamingEnabled()) {
        if (StringUtils.startsWith(dbName, NS_INDEX_PREFIX)) {
            if (StringUtils.contains(dbName, fieldName))
                indexName = dbName;
            else
                indexName = String.format("%s_%s_%s", NS_INDEX_PREFIX, dbName, fieldName);
        } else
            indexName = String.format("%s_%s_%s", NS_INDEX_PREFIX, dbName, fieldName);
    } else
        indexName = String.format("%s_%s", dbName, fieldName);

    return indexName;
}

From source file:com.constellio.model.services.users.sync.FastBindConnectionControl.java

@SuppressWarnings("unchecked")
public LDAPFastBind(String ldapurl, Boolean followReferences, boolean activeDirectory) {
    env = new Hashtable();
    //This can make LDAP search slow : http://stackoverflow.com/questions/16412236/how-to-resolve-javax-naming-partialresultexception
    //env.put(Context.REFERRAL, "follow");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.PROVIDER_URL, ldapurl);
    env.put("java.naming.ldap.attributes.binary", "tokenGroups objectSid");
    if (followReferences) {
        env.put(Context.REFERRAL, "follow");
    }//from www . j  a v a2  s  .c o m

    if (StringUtils.startsWith(ldapurl, "ldaps")) {
        //env.put(Context.SECURITY_PROTOCOL, "ssl");
        env.put("java.naming.ldap.factory.socket",
                "com.constellio.model.services.users.sync.ldaps.DummySSLSocketFactory");
    }

    if (activeDirectory) {
        connCtls = new Control[] { new FastBindConnectionControl() };
    } else {
        connCtls = new Control[] {};
    }

    //first time we initialize the context, no credentials are supplied
    //therefore it is an anonymous bind.      

    /*try {
       ctx = new InitialLdapContext(env, connCtls);
            
    } catch (NamingException e) {
       throw new RuntimeNamingException(e.getMessage());
    }*/
    //FIX de Vincent pour o a q
    try {
        ctx = new InitialLdapContext(env, connCtls);
    } catch (NamingException e) {
        if (activeDirectory) {
            connCtls = new Control[] {};
            try {
                ctx = new InitialLdapContext(env, connCtls);
            } catch (NamingException e2) {
                throw new RuntimeException(e);
            }
        } else {
            throw new RuntimeException(e);
        }
    }
}

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

private String buildAuditResultUrl(String webappUrl) {
    try {/*from   w  w  w.j  a va2  s.  c  o m*/
        for (Object obj : FileUtils.readLines(project.getLastBuild().getLogFile())) {
            String line = (String) obj;
            if (StringUtils.startsWith(line, "Audit Id")) {
                return doBuildAuditResultUrl(line, webappUrl);
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(ProjectAsqatasunAction.class.getName()).log(Level.SEVERE, null, ex);
    }
    return webappUrl;
}

From source file:com.glaf.core.interceptor.MethodInterceptor.java

public void before(Method method, Object[] args, Object target) throws Throwable {
    logger.debug("-------------MethodInterceptor.before------------");
    String targetName = target.getClass().getName();
    String methodName = method.getName();
    logger.debug("target:" + targetName);
    logger.debug("method:" + methodName);
    if (StringUtils.startsWith(targetName, "org.springframework.web.servlet.view")) {
        return;/* ww w .  ja  va2  s . co  m*/
    }
    String operation = targetName + "." + methodName;
    String actorId = Authentication.getAuthenticatedActorId();
    boolean authorized = false;

    String ip = null;

    for (int i = 0; i < args.length; i++) {
        logger.debug("args:" + args[i]);
        if (args[i] instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) args[i];
            if (request != null) {
                ip = RequestUtils.getIPAddress(request);
                actorId = RequestUtils.getActorId(request);
                logger.debug("IP:" + ip + ", actorId:" + actorId);
            }
        }
    }

    // 
    if (checkSystemFunction(operation)) {
        // 
        if (checkUserFunction(actorId, methodName)) {
            logger.debug("method is in user functions");
            authorized = true;
        }
    } else {// ?
        logger.debug("method isn't in system functions");
        authorized = true;
    }

    try {
        LoginContext loginContext = IdentityFactory.getLoginContext(actorId);
        if (loginContext.isSystemAdministrator()) {
            /**
             * ???
             */
            authorized = true;
        }
        User user = loginContext.getUser();
        SysLog sysLog = new SysLog();
        sysLog.setAccount(user.getActorId());
        sysLog.setOperate(operation);
        sysLog.setIp(ip);
        sysLog.setCreateTime(new Date());
        sysLog.setFlag(authorized ? 1 : 0);

        ISysLogService sysLogService = ContextFactory.getBean("sysLogService");
        sysLogService.create(sysLog);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (!authorized) {
        throw new AthenticationException("No Privileges.");
    }
}

From source file:com.erudika.para.storage.LocalFileStore.java

@Override
public String store(String path, InputStream data) {
    if (StringUtils.startsWith(path, File.separator)) {
        path = path.substring(1);/*from w w  w .  j  a v a 2  s  . com*/
    }
    if (StringUtils.isBlank(path)) {
        return null;
    }
    int maxFileSizeMBytes = Config.getConfigInt("para.localstorage.max_filesize_mb", 10);
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    try {
        if (data.available() > 0 && data.available() <= (maxFileSizeMBytes * 1024 * 1024)) {
            File f = new File(folder + File.separator + path);
            if (f.canWrite()) {
                fos = new FileOutputStream(f);
                bos = new BufferedOutputStream(fos);
                int read = 0;
                byte[] bytes = new byte[1024];
                while ((read = data.read(bytes)) != -1) {
                    bos.write(bytes, 0, read);
                }
                return f.getAbsolutePath();
            }
        }
    } catch (IOException e) {
        logger.error(null, e);
    } finally {
        try {
            fos.close();
            bos.close();
            data.close();
        } catch (IOException e) {
            logger.error(null, e);
        }
    }
    return null;
}

From source file:com.glaf.core.config.SystemProperties.java

/**
 * ?/*w  w w . j  av a 2 s . c o m*/
 * 
 * @return
 */
public static String getFileStorageRootPath() {
    if (StringUtils.isNotEmpty(conf.get("fs_storage_path"))) {
        String path = conf.get("fs_storage_path");
        if (StringUtils.startsWith(path, "${webapp.root}")) {
            path = StringTools.replaceIgnoreCase(path, "${webapp.root}", getAppPath());
        }
        if (StringUtils.startsWith(path, "${webapp.root.config}")) {
            path = StringTools.replaceIgnoreCase(path, "${webapp.root.config}", getConfigRootPath());
        }
        return path;
    }
    return getConfigRootPath();
}

From source file:io.github.moosbusch.lumpi.gui.impl.Expression.java

public String getSubExpression(int startIndex, int tokenCount) {
    String separator = new String(new char[] { getSeparatorChar() });
    String result = "";
    if (tokenCount == 0) {
        return get(startIndex);
    } else {//from  w  w w  .  ja va 2s. co m
        StringBuilder buf = new StringBuilder();
        buf.append(result);
        for (int cnt = 0; cnt < tokenCount; cnt++) {
            String token = get(startIndex + cnt);
            buf.append(getSeparatorChar());
            buf.append(token);
        }
        if (StringUtils.startsWith(result, separator)) {
            result = StringUtils.substringAfter(result, separator);
        }
        if (StringUtils.endsWith(result, separator)) {
            result = StringUtils.substringBeforeLast(result, separator);
        }
    }
    return result;
}