Java Code Examples for org.apache.commons.lang3.StringUtils.endsWith()

The following are Jave code examples for showing how to use endsWith() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kubernetes-elastic-agents   File: GoServerUrlField.java   View Source Code Vote up 6 votes
@Override
public String doValidate(String input)  {
    String validationResult = super.doValidate(input);
    if(StringUtils.isNotBlank(validationResult) || StringUtils.isBlank(input)) {
        return validationResult;
    }

    try {
        URI uri = new URI(input);
        if (uri.getHost().equalsIgnoreCase("localhost") || uri.getHost().equalsIgnoreCase("127.0.0.1")) {
            return this.displayName + " must not be localhost, since this gets resolved on the agents.";
        }
        if (!StringUtils.endsWith(input, "/go")) {
            return this.displayName + " must be in format https://<GO_SERVER_URL>:<GO_SERVER_PORT>/go.";
        }
    } catch (URISyntaxException e) {
        return this.displayName + " must be a valid URL (https://example.com:8154/go).";
    }

    return null;
}
 
Example 2
Project: YiDu-Novel   File: ForbidFilter.java   View Source Code Vote up 6 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String uri = httpRequest.getRequestURI().toString();

    List<Object> forbidFiles = YiDuConstants.yiduConf.getList(YiDuConfig.FORBID_FILES);
    for (Object object : forbidFiles) {
        if (StringUtils.endsWith(uri, (String) object) && !StringUtils.endsWith(uri, "robots.txt")) {
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            // 模拟不存在 返回404
            httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
            logger.warn("the template file was been request :" + uri);
            return;
        }
    }
    chain.doFilter(request, response);
}
 
Example 3
Project: Open_Source_ECOA_Toolset_AS5   File: GenerationUtils.java   View Source Code Vote up 6 votes
public static void clearCreatedFolders(File root) {
	File[] files = root.listFiles();
	try {
		for (File file : files) {
			if (file.getName().equalsIgnoreCase("output")) {
				FileUtils.deleteDirectory(file);
			}
			if (file.getName().equalsIgnoreCase("4-ComponentImplementations")) {
				File[] child = file.listFiles();
				for (File c : child) {
					if (c.isFile())
						FileUtils.forceDelete(c);
					else {
						File[] gChild = c.listFiles();
						for (File gC : gChild) {
							if (gC.isDirectory())
								FileUtils.deleteDirectory(gC);
							else if (!StringUtils.endsWith(gC.getName(), ".impl.xml"))
								FileUtils.forceDelete(gC);
						}
					}
				}
			}
		}
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
Example 4
Project: saluki   File: Proto2Java.java   View Source Code Vote up 6 votes
private File listAllProtoFile(File file) {
    if (file != null) {
        if (file.isDirectory()) {
            File[] fileArray = file.listFiles();
            if (fileArray != null) {
                for (int i = 0; i < fileArray.length; i++) {
                    listAllProtoFile(fileArray[i]);
                }
            }
        } else {
            if (StringUtils.endsWith(file.getName(), "proto")) {
                allProtoFile.add(file);
            }
        }
    }
    return null;
}
 
Example 5
Project: Yidu   File: ForbidFilter.java   View Source Code Vote up 6 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String uri = httpRequest.getRequestURI().toString();

    List<Object> forbidFiles = YiDuConstants.yiduConf.getList(YiDuConfig.FORBID_FILES);
    for (Object object : forbidFiles) {
        if (StringUtils.endsWith(uri, (String) object) && !StringUtils.endsWith(uri, "robots.txt")) {
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            // 模拟不存在 返回404
            httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
            logger.warn("the template file was been request :" + uri);
            return;
        }
    }
    chain.doFilter(request, response);
}
 
Example 6
Project: unitstack   File: DefaultS3Responder.java   View Source Code Vote up 6 votes
@Override
public MockResponse createResponse(MockRequest request) {
  String action = request.getBodyParameters().get(S3RequestTransformer.ACTION);

  if (StringUtils.equals(action, "requestPayment")) {
    return new MockResponse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n"
        + "  <Payer>Requester</Payer></RequestPaymentConfiguration>");
  }
  if (StringUtils.endsWith(action, "tagging")) {
    return new MockResponse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<Tagging xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n"
        + "<TagSet></TagSet></Tagging> ");
  }
  if (StringUtils.isEmpty(action)) {
    return new MockResponse("");
  }
  return super.createResponse(request);
}
 
Example 7
Project: patternlab-for-sling   File: PatternLabUtils.java   View Source Code Vote up 6 votes
public static String constructPatternId(String patternResourcePath, String patternsPath, String templateName, String jsonDataFileName) {
    final String patternPath = StringUtils.substringAfter(patternResourcePath, patternsPath + SLASH);
    final StringBuilder patternIdBuilder = new StringBuilder();
    if (StringUtils.endsWith(patternPath, HTML_EXT)) {
        patternIdBuilder.append(StringUtils.substringBeforeLast(patternPath, HTML_EXT));
    } else {
        patternIdBuilder.append(patternPath);
    }
    if (StringUtils.isNotBlank(templateName)) {
        patternIdBuilder.append(SLASH).append(templateName);
    }
    if (StringUtils.isNotBlank(jsonDataFileName)) {
        final String patternFileName = StringUtils.substringAfterLast(patternPath, SLASH);
        final String fileNameWithoutExt = StringUtils.substringBeforeLast(patternFileName, HTML_EXT);
        final String dataFileSuffix = StringUtils.substringBetween(jsonDataFileName, fileNameWithoutExt
                + SELECTOR, DATA_EXT);
        patternIdBuilder.append(SLASH).append(StringUtils.defaultString(dataFileSuffix, fileNameWithoutExt));
    }
    return StringUtils.replace(patternIdBuilder.toString(), SLASH, PATTERN_ID_REPLACEMENT);
}
 
Example 8
Project: cyberduck   File: URIEncoder.java   View Source Code Vote up 5 votes
/**
 * URL encode a path
 *
 * @param p Path
 * @return URI encoded
 * @see java.net.URLEncoder#encode(String, String)
 */
public static String encode(final String p) {
    try {
        final StringBuilder b = new StringBuilder();
        final StringTokenizer t = new StringTokenizer(p, "/");
        if(!t.hasMoreTokens()) {
            return p;
        }
        if(StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) {
            b.append(Path.DELIMITER);
        }
        while(t.hasMoreTokens()) {
            b.append(URLEncoder.encode(t.nextToken(), "UTF-8"));
            if(t.hasMoreTokens()) {
                b.append(Path.DELIMITER);
            }
        }
        if(StringUtils.endsWith(p, String.valueOf(Path.DELIMITER))) {
            b.append(Path.DELIMITER);
        }
        // Because URLEncoder uses <code>application/x-www-form-urlencoded</code> we have to replace these
        // for proper URI percented encoding.
        return b.toString().replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
    }
    catch(UnsupportedEncodingException e) {
        return p;
    }
}
 
Example 9
Project: bird-java   File: PagedQueryProvider.java   View Source Code Vote up 5 votes
private String getDbFieldName(PagedQueryParam param, String fieldName) {
    Map<String, String> fieldMap = param.getFieldMap();
    String dbFieldName = fieldMap.getOrDefault(fieldName, fieldName);

    if (!StringUtils.startsWith(dbFieldName, "`")) {
        dbFieldName = "`" + dbFieldName;
    }
    if (!StringUtils.endsWith(dbFieldName, "`")) {
        dbFieldName = dbFieldName + "`";
    }
    return dbFieldName;
}
 
Example 10
Project: spring2ts   File: TSOutputProcessor.java   View Source Code Vote up 5 votes
private String relativePath(String source, String dest) {
    Path sourcePath = Paths.get(outputDir.getAbsolutePath(), source).getParent();
    Path destPath = Paths.get(outputDir.getAbsolutePath(), dest).getParent();
    String path = sourcePath.relativize(destPath).toString();
    if(StringUtils.isEmpty(path)) {
        path = "./";
    }
    if(!StringUtils.endsWith(path, "/")) {
        path += "/";
    }
    path = path.replace('\\', '/');
    return path + StringUtils.removeEnd(FilenameUtils.getName(dest), ".ts");
}
 
Example 11
Project: remittanceparse   File: RemittanceParser.java   View Source Code Vote up 5 votes
private void parseTsvLine(ArrayList<String> destination, String source) {
    final String[] split = StringUtils.splitPreserveAllTokens(source, "\t");
    for (String s : split) {
        if (StringUtils.startsWith(s, "\"") && StringUtils.endsWith(s, "\"")) {
            destination.add(s.substring(1, s.length() - 1));
        } else
            destination.add(s);
    }

}
 
Example 12
Project: scoold   File: Profile.java   View Source Code Vote up 5 votes
public static final String id(String userid) {
	if (StringUtils.endsWith(userid, Config.SEPARATOR + "profile")) {
		return userid;
	} else {
		return userid != null ? userid + Config.SEPARATOR + "profile" : null;
	}
}
 
Example 13
Project: jvm-sandbox   File: ModuleJarLoader.java   View Source Code Vote up 5 votes
private File[] toModuleJarFileArray() {
    if (moduleLibDir.exists()
            && moduleLibDir.isFile()
            && moduleLibDir.canRead()
            && StringUtils.endsWith(moduleLibDir.getName(), ".jar")) {
        return new File[]{
                moduleLibDir
        };
    } else {
        return convertFileCollectionToFileArray(
                listFiles(moduleLibDir, new String[]{"jar"}, false)
        );
    }
}
 
Example 14
Project: vscrawler   File: EndsWith.java   View Source Code Vote up 5 votes
@Override
protected boolean handle(String input, String searchString, boolean ignoreCase) {
    if (ignoreCase) {
        return StringUtils.endsWithIgnoreCase(input, searchString);
    } else {
        return StringUtils.endsWith(input, searchString);
    }
}
 
Example 15
Project: patternlab-for-sling   File: PatternPatternCategoryFactoryImpl.java   View Source Code Vote up 5 votes
private List<String> retrieveJsonDataFilesInFolder(Resource filesParentResource, String name) {
    final List<String> patternJsonDataFiles = Lists.newArrayList();
    final Iterator<Resource> children = filesParentResource.listChildren();
    while (children.hasNext()) {
        final Resource childResource = children.next();
        final String childResourceName = childResource.getName();
        if (StringUtils.startsWith(childResourceName, name) && StringUtils.endsWith(childResourceName, PatternLabConstants.DATA_EXT)) {
            patternJsonDataFiles.add(childResourceName);
        }
    }
    return patternJsonDataFiles;
}
 
Example 16
Project: solo-spring   File: PreferenceConsole.java   View Source Code Vote up 4 votes
/**
 * Updates the Qiniu preference by the specified request.
 *
 * @param request
 *            the specified http servlet request, for example,
 * 
 *            <pre>
 * {
 *     "qiniuAccessKey": "",
 *     "qiniuSecretKey": "",
 *     "qiniuDomain": "",
 *     "qiniuBucket": ""
 * }, see {@link org.b3log.solo.model.Option} for more details
 *            </pre>
 *
 * @param response
 *            the specified http servlet response
 * @param context
 *            the specified http request context
 * @throws Exception
 *             exception
 */
@RequestMapping(value = PREFERENCE_URI_PREFIX + "qiniu", method = RequestMethod.PUT)
public void updateQiniu(final HttpServletRequest request, final HttpServletResponse response, @RequestParam String body) throws Exception {
	if (!userQueryService.isAdminLoggedIn(request)) {
		response.sendError(HttpServletResponse.SC_FORBIDDEN);
		return;
	}

	final JSONRenderer renderer = new JSONRenderer();

	try {
		body = URLDecoder.decode(body, "UTF-8");final JSONObject requestJSONObject = new JSONObject(body);

		final String accessKey = requestJSONObject.optString(Option.ID_C_QINIU_ACCESS_KEY).trim();
		final String secretKey = requestJSONObject.optString(Option.ID_C_QINIU_SECRET_KEY).trim();
		String domain = requestJSONObject.optString(Option.ID_C_QINIU_DOMAIN).trim();
		final String bucket = requestJSONObject.optString(Option.ID_C_QINIU_BUCKET).trim();

		final JSONObject ret = new JSONObject();
		renderer.setJSONObject(ret);

		if (StringUtils.isNotBlank(domain) && !StringUtils.endsWith(domain, "/")) {
			domain += "/";
		}

		final JSONObject accessKeyOpt = new JSONObject();
		accessKeyOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_ACCESS_KEY);
		accessKeyOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
		accessKeyOpt.put(Option.OPTION_VALUE, accessKey);
		final JSONObject secretKeyOpt = new JSONObject();
		secretKeyOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_SECRET_KEY);
		secretKeyOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
		secretKeyOpt.put(Option.OPTION_VALUE, secretKey);
		final JSONObject domainOpt = new JSONObject();
		domainOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_DOMAIN);
		domainOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
		domainOpt.put(Option.OPTION_VALUE, domain);
		final JSONObject bucketOpt = new JSONObject();
		bucketOpt.put(Keys.OBJECT_ID, Option.ID_C_QINIU_BUCKET);
		bucketOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_QINIU);
		bucketOpt.put(Option.OPTION_VALUE, bucket);

		optionMgmtService.addOrUpdateOption(accessKeyOpt);
		optionMgmtService.addOrUpdateOption(secretKeyOpt);
		optionMgmtService.addOrUpdateOption(domainOpt);
		optionMgmtService.addOrUpdateOption(bucketOpt);

		ret.put(Keys.STATUS_CODE, true);
		ret.put(Keys.MSG, langPropsService.get("updateSuccLabel"));
	} catch (final ServiceException e) {
		logger.error(e.getMessage(), e);

		final JSONObject jsonObject = QueryResults.defaultResult();

		renderer.setJSONObject(jsonObject);
		jsonObject.put(Keys.MSG, e.getMessage());
	}
	renderer.render(request, response);
}
 
Example 17
Project: Open_Source_ECOA_Toolset_AS5   File: ExtensionFilter.java   View Source Code Vote up 4 votes
@Override
public boolean accept(File dir, String name) {
	return StringUtils.endsWith(name.toLowerCase(), ext.toLowerCase());
}
 
Example 18
Project: saluki   File: GenericInvokeUtils.java   View Source Code Vote up 4 votes
private static boolean isArray(TypeDefinition def) {
    return StringUtils.endsWith(def.getType(), "[]");
}
 
Example 19
Project: bird-java   File: PagedQueryParam.java   View Source Code Vote up 4 votes
/**
 * 根据Class名称初始化select与from
 * 如果select不为空,selectSql = select + tClass反射得到的select
 */
private void initWithClass() {
    if (this.tClass == null) return;


    if (StringUtils.isBlank(this.select)) {
        StringBuilder sb = new StringBuilder();
        List<Field> fields = new ArrayList<>();

        Class tempClass = tClass;
        while (tempClass != null && !tempClass.getName().toLowerCase().equals("java.lang.object")) {
            Field[] tempFields = tempClass.getDeclaredFields();
            fields.addAll(Arrays.asList(tempFields));
            tempClass = tempClass.getSuperclass();
        }

        for (Field field : fields) {
            TableField tableField = field.getAnnotation(TableField.class);
            if (tableField != null && !tableField.exist()) continue;

            String fieldName = field.getName();
            String dbFieldName = tableField == null ? fieldName : tableField.value();
            if (!StringUtils.startsWith(dbFieldName, "`")) {
                sb.append("`");
            }
            sb.append(dbFieldName);
            if (!StringUtils.endsWith(dbFieldName, "`")) {
                sb.append("`");
            }

            if (!fieldName.equals(dbFieldName)) {
                sb.append(" AS ");
                sb.append(fieldName);
            }

            sb.append(",");
        }

        this.select = StringHelper.trimEnd(sb.toString(), ',');
    }

    //如果from为空,则使用tClass的TableName
    if (StringUtils.isBlank(this.from)) {

        TableName tableName = this.tClass.getAnnotation(TableName.class);
        if (tableName != null) {
            this.from = tableName.value();
        }
    }
}
 
Example 20
Project: patternlab-for-sling   File: PatternPatternCategoryFactoryImpl.java   View Source Code Vote up 4 votes
private boolean isFolder(Resource resource) {
    final String primaryType = getPrimaryType(resource);
    return StringUtils.equals(primaryType, PatternLabConstants.NT_FOLDER) || StringUtils.equals(primaryType, PatternLabConstants.SLING_FOLDER) || StringUtils.endsWith(primaryType, PatternLabConstants.SLING_ORDERED_FOLDER);
}