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

The following are Jave code examples for showing how to use startsWith() 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: solo-spring   File: Markdowns.java   View Source Code Vote up 6 votes
/**
 * Converts the specified markdown text to HTML.
 *
 * @param markdownText
 *            the specified markdown text
 * @return converted HTML, returns {@code null} if the specified markdown
 *         text is "" or {@code null}, returns "Markdown error" if exception
 */
public static String toHTML(final String markdownText) {
	if (StringUtils.isBlank(markdownText)) {
		return "";
	}

	final PegDownProcessor pegDownProcessor = new PegDownProcessor(
			Extensions.ALL_OPTIONALS | Extensions.ALL_WITH_OPTIONALS, 5000);
	String ret = pegDownProcessor.markdownToHtml(markdownText);

	if (!StringUtils.startsWith(ret, "<p>")) {
		ret = "<p>" + ret + "</p>";
	}

	return ret;
}
 
Example 2
Project: accumulate   File: ExecuteTimeInterceptor.java   View Source Code Vote up 6 votes
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
	Long long1 = (Long) request.getAttribute(EXECUTE_TIME_ATTRIBUTE_NAME);
	if (long1 == null) {
		Long long2 = (Long) request.getAttribute(START_TIME_ATTRIBUTE_NAME);
		Long long3 = Long.valueOf(System.currentTimeMillis());
		long1 = Long.valueOf(long3.longValue() - long2.longValue());
		request.setAttribute(START_TIME_ATTRIBUTE_NAME, long2);
	}
	if (modelAndView != null) {
		String s = modelAndView.getViewName();
		if (!StringUtils.startsWith(s, "redirect:"))
			modelAndView.addObject(EXECUTE_TIME_ATTRIBUTE_NAME, long1);
	}
	if (logger.isDebugEnabled()) {
		logger.debug((new StringBuilder("[")).append(handler).append("] executeTime: ").append(long1).append("ms").toString());
	}
}
 
Example 3
Project: patternlab-for-sling   File: HtlScriptParser.java   View Source Code Vote up 6 votes
private static String resolveAbsolutePathToPattern(String path, String projectSlingPrefix, String projectName, String currentPatternPath) {
    if (StringUtils.startsWith(path, projectSlingPrefix + PatternLabConstants.SLASH + projectName)
            || StringUtils.startsWith(path, projectSlingPrefix + PatternLabConstants.SLASH + projectName)) {
        return path;
    } else if (StringUtils.startsWith(path, projectName)) {
        return PatternLabConstants.SLASH + projectSlingPrefix + PatternLabConstants.SLASH + path;
    }
    String[] pathElements = StringUtils.split(path, PatternLabConstants.SLASH);
    StringBuilder absolutePath = new StringBuilder(StringUtils.substringBeforeLast(currentPatternPath, PatternLabConstants.SLASH));
    for (String pathElement : pathElements) {
        if (StringUtils.equals(pathElement, FILESYSTEM_BACK_PATH)) {
            absolutePath = new StringBuilder(StringUtils.substringBeforeLast(currentPatternPath, PatternLabConstants.SLASH));
        } else {
            absolutePath.append(PatternLabConstants.SLASH).append(pathElement);
        }
    }

    return absolutePath.toString();
}
 
Example 4
Project: Quora-Marketing   File: QuoraCrawler.java   View Source Code Vote up 6 votes
private void scrapLinksForSearchJSoup(String keyWord, int cityId) {
	// log("crawling for keyword : " + keyWord + " and city: " +cityId);
	String url = QuoraConstants.getUrl(keyWord, cityId);
	Document doc = getDocument(url);

	Elements els = doc.select("div.g");

	for (Element el : els) {
		String quoraUrl = el.getElementsByTag("cite").text();
		quoraUrl = StringUtils.replace(quoraUrl, " ", "");
		if (!StringUtils.startsWith(quoraUrl, "http")) {
			quoraUrl = "http://" + quoraUrl;
		}
		if (!uniqueQuoraLinks.contains(quoraUrl)) {
			crawlQuoraPage(quoraUrl, true);
		}
	}
}
 
Example 5
Project: easyweb   File: ObjectUtils.java   View Source Code Vote up 6 votes
/**
 * 注解到对象复制,只复制能匹配上的方法。
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object){
	if (annotation != null){
		Class<?> annotationClass = annotation.getClass();
		if (null == object) {
			return;
		}
		Class<?> objectClass = object.getClass();
		for (Method m : objectClass.getMethods()){
			if (StringUtils.startsWith(m.getName(), "set")){
				try {
					String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
					Object obj = annotationClass.getMethod(s).invoke(annotation);
					if (obj != null && !"".equals(obj.toString())){
						m.invoke(object, obj);
					}
				} catch (Exception e) {
					// 忽略所有设置失败方法
				}
			}
		}
	}
}
 
Example 6
Project: util   File: URLResourceUtil.java   View Source Code Vote up 5 votes
/**
 * 兼容无前缀, classpath://, file:// 的情况获取文件
 * 
 * 如果以classpath:// 定义的文件不存在会抛出IllegalArgumentException异常,以file://定义的则不会
 */
public static File asFile(String generalPath) throws IOException {
	if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
		String resourceName = StringUtils.substringAfter(generalPath, CLASSPATH_PREFIX);
		return getFileByURL(ResourceUtil.asUrl(resourceName));
	}
	try {
		// try URL
		return getFileByURL(new URL(generalPath));
	} catch (MalformedURLException ex) {
		// no URL -> treat as file path
		return new File(generalPath);
	}
}
 
Example 7
Project: OpenLRW   File: DefaultUserIdConverter.java   View Source Code Vote up 5 votes
@Override
public String convert(Tenant tenant, Event event) {
  
  String convertedUserId = null;
  
  Agent agent = event.getAgent();
  String agentId = agent.getId();
  
  if (StringUtils.isNotBlank(agentId)
      && StringUtils.startsWith(agentId, "http")) {
    Map<String, String> tenantMetadata = tenant.getMetadata();
    if (tenantMetadata != null && !tenantMetadata.isEmpty()) {
      String tenantUserPrefix = tenantMetadata.get(Vocabulary.TENANT_USER_PREFIX);
      if (StringUtils.isNotBlank(tenantUserPrefix)) {
        String agentIdAfterPrefix = StringUtils.substringAfter(agentId, tenantUserPrefix);
        if (StringUtils.startsWith(agentIdAfterPrefix, "/")) {
          convertedUserId = StringUtils.substringAfter(agentIdAfterPrefix, "/");
        }
        else {
          convertedUserId = agentIdAfterPrefix;
        }
      }
    }
    else {
      convertedUserId = StringUtils.substringAfterLast(agentId, "/");
    }
  }
  else {
    convertedUserId = agentId;
  }
  
  return convertedUserId;
}
 
Example 8
Project: pprxmtr   File: S3.java   View Source Code Vote up 5 votes
public static boolean fileExistsInBucket(String filenamePrefix) {
	try {
		ObjectListing ol = S3.listObjects(properties.getProperty(S3_BUCKET_NAME));
		List<S3ObjectSummary> objects = ol.getObjectSummaries();
		for (S3ObjectSummary os : objects) {
			if (StringUtils.startsWith(os.getKey(), filenamePrefix)) {
				LOG.info("Found file {} from S3 bucket.", filenamePrefix);
				return true;
			}
		}
	} catch (AmazonServiceException e) {
		LOG.error("Exception occured when checking if file exists in S3.", e);
	}
	return false;
}
 
Example 9
Project: pprxmtr   File: S3.java   View Source Code Vote up 5 votes
public static String getS3KeyFromBucket(String filenamePrefix) {
	try {
		ObjectListing ol = S3.listObjects(properties.getProperty(S3_BUCKET_NAME));
		List<S3ObjectSummary> objects = ol.getObjectSummaries();
		for (S3ObjectSummary os : objects) {
			if (StringUtils.startsWith(os.getKey(), filenamePrefix)) {
				LOG.info("Found file {} from S3 bucket.", filenamePrefix);
				return os.getKey();
			}
		}
	} catch (AmazonServiceException e) {
		LOG.error("Exception occured when checking if file exists in S3.", e);
	}
	return StringUtils.EMPTY;
}
 
Example 10
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 5 votes
private static String[] replaceWithSysPropUserHome(final String[] pathArray) {
    if (ArrayUtils.isEmpty(pathArray)) {
        return pathArray;
    }
    final String SYS_PROP_USER_HOME = System.getProperty("user.home");
    for (int index = 0; index < pathArray.length; index++) {
        if (StringUtils.startsWith(pathArray[index], "~")) {
            pathArray[index] = StringUtils.replaceOnce(pathArray[index], "~", SYS_PROP_USER_HOME);
        }
    }
    return pathArray;
}
 
Example 11
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 12
Project: cyberduck   File: MappingMimeTypeService.java   View Source Code Vote up 5 votes
@Override
public String getMime(final String filename) {
    if(StringUtils.startsWith(filename, "._")) {
        return DEFAULT_CONTENT_TYPE;
    }
    // Reads from mime.types in classpath
    return types.getMimetype(StringUtils.lowerCase(filename));
}
 
Example 13
Project: EasyPackage   File: PathUtil.java   View Source Code Vote up 5 votes
public static String getPath(String path) {
    if (StringUtils.isBlank(path)) {
        path = StringUtils.EMPTY;
    }
    if (!StringUtils.startsWith(path, Constants.Path.ROOT)) {
        path = Constants.Path.ROOT + path;
    }
    if (StringUtils.isNotBlank(Config.getContextPath())
            && !StringUtils.startsWith(path, Config.getContextPath())) {
        path = Config.getContextPath() + path;
    }
    return path;
}
 
Example 14
Project: kinota-server   File: JwtTokenUtil.java   View Source Code Vote up 5 votes
public String extractTokenFromHeader(HttpServletRequest req) {
    String token = null;
    String header = req.getHeader(JWT_TOKEN_HEADER);
    if (!StringUtils.isEmpty(header)) {
        if (StringUtils.startsWith(header.trim(), "Bearer")) {
            token = StringUtils.remove(header, "Bearer").trim();
        }
    }
    return token;
}
 
Example 15
Project: hybris-integration-intellij-idea-plugin   File: BpDiagramColorManagerIml.java   View Source Code Vote up 5 votes
@Override
public Color getEdgeColor(final DiagramEdge edge) {
    final String edgeType = edge.getRelationship().toString();

    if (StringUtils.isBlank(edgeType) || "OK".equalsIgnoreCase(edgeType)) {
        return new JBColor(
            new Color(9, 128, 0),
            new Color(9, 128, 0)
        );
    }

    if ("NOK".equalsIgnoreCase(edgeType) || "ERROR".equalsIgnoreCase(edgeType) || "FAIL".equalsIgnoreCase(edgeType)) {
        return new JBColor(
            new Color(161, 49, 42),
            new Color(161, 49, 42)
        );
    }

    final String timeoutLabel = HybrisI18NBundleUtils.message("hybris.business.process.timeout");

    if (StringUtils.startsWith(edgeType, timeoutLabel)) {
        return new JBColor(
            new Color(161, 49, 42),
            new Color(161, 49, 42)
        );
    }

    return new JBColor(
        new Color(71, 71, 71),
        new Color(155, 158, 161)
    );
}
 
Example 16
Project: patternlab-for-sling   File: PatternModel.java   View Source Code Vote up 5 votes
public PatternModel(Resource resource, String patternsPath, String patternId, ResourceResolver resourceResolver) throws IOException {
    this.id = PatternLabUtils.constructPatternId(resource.getPath(), patternsPath);
    this.name = StringUtils.lowerCase(PatternLabUtils.getResourceTitleOrName(resource));
    this.template = StringUtils.EMPTY;
    this.path = resource.getPath();
    this.dataPath = StringUtils.EMPTY;
    this.displayed = StringUtils.isBlank(patternId) || StringUtils.startsWith(getId(), patternId);
    this.breadcrumb = Lists.newArrayList(new BreadcrumbItemModel(id, name));
    this.code = PatternLabUtils.getDataFromFile(path, resourceResolver);
    this.data = null;
    final String descriptionPath = StringUtils.substringBeforeLast(path, PatternLabConstants.SELECTOR) + PatternLabConstants.DESCRIPTION_EXT;
    this.description = PatternLabUtils.getDataFromFile(descriptionPath, resourceResolver);
    this.embeddedPatterns = Sets.newHashSet();
    this.includingPatterns = Sets.newHashSet();
}
 
Example 17
Project: iab-spiders-and-robots-java-client   File: ExcludeRecord.java   View Source Code Vote up 4 votes
private boolean isUserAgentPatternPresent(String userAgentLowCase) {
    return startOfStringFlag ? StringUtils.startsWith(userAgentLowCase, userAgentPattern) :
            StringUtils.contains(userAgentLowCase, userAgentPattern);
}
 
Example 18
Project: cyberduck   File: UserDefaultsPreferences.java   View Source Code Vote up 4 votes
@Override
protected void setDefaults() {
    // Parent defaults
    super.setDefaults();

    defaults.put("tmp.dir", FoundationKitFunctionsLibrary.NSTemporaryDirectory());

    final NSBundle bundle = this.bundle;
    if(null != bundle) {
        if(bundle.objectForInfoDictionaryKey("CFBundleName") != null) {
            defaults.put("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString());
        }
        if(bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright") != null) {
            defaults.put("application.copyright", bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright").toString());
        }
        if(bundle.objectForInfoDictionaryKey("CFBundleIdentifier") != null) {
            defaults.put("application.identifier", bundle.objectForInfoDictionaryKey("CFBundleIdentifier").toString());
        }
        if(bundle.objectForInfoDictionaryKey("CFBundleShortVersionString") != null) {
            defaults.put("application.version", bundle.objectForInfoDictionaryKey("CFBundleShortVersionString").toString());
        }
        if(bundle.objectForInfoDictionaryKey("CFBundleVersion") != null) {
            defaults.put("application.revision", bundle.objectForInfoDictionaryKey("CFBundleVersion").toString());
        }
        defaults.put("application.receipt.path", String.format("%s/Contents/_MASReceipt", bundle.bundlePath()));
    }
    final Local resources = ApplicationResourcesFinderFactory.get().find();
    defaults.put("application.bookmarks.path", String.format("%s/Bookmarks", resources.getAbsolute()));
    defaults.put("application.profiles.path", String.format("%s/Profiles", resources.getAbsolute()));

    defaults.put("update.feed.release", "https://version.cyberduck.io/changelog.rss");
    defaults.put("update.feed.beta", "https://version.cyberduck.io/beta/changelog.rss");
    defaults.put("update.feed.nightly", "https://version.cyberduck.io/nightly/changelog.rss");
    // Fix #9395
    if(!StringUtils.startsWith(this.getProperty(Updater.PROPERTY_FEED_URL), Scheme.https.name())) {
        this.deleteProperty(Updater.PROPERTY_FEED_URL);
        this.save();
    }

    defaults.put("bookmark.import.filezilla.location", "~/.config/filezilla/sitemanager.xml");
    defaults.put("bookmark.import.fetch.location", "~/Library/Preferences/com.fetchsoftworks.Fetch.Shortcuts.plist");
    defaults.put("bookmark.import.flow.location", "~/Library/Application Support/Flow/Bookmarks.plist");
    defaults.put("bookmark.import.interarchy.location", "~/Library/Application Support/Interarchy/Bookmarks.plist");
    defaults.put("bookmark.import.transmit.location", "~/Library/Preferences/com.panic.Transmit.plist");
    defaults.put("bookmark.import.transmit4.location", "~/Library/Application Support/Transmit/Favorites/Favorites.xml");
    defaults.put("bookmark.import.crossftp.location", "~/.crossftp/sites.xml");
    defaults.put("bookmark.import.fireftp.location", "~/Library/Application Support/Firefox/Profiles");
    defaults.put("bookmark.import.expandrive3.location", "~/Library/Application Support/ExpanDrive/favorites.js");
    defaults.put("bookmark.import.expandrive4.location", "~/Library/Application Support/ExpanDrive/expandrive4.favorites.js");
    defaults.put("bookmark.import.expandrive5.location", "~/Library/Application Support/ExpanDrive/expandrive5.favorites.js");
    defaults.put("bookmark.import.expandrive6.location", "~/Library/Application Support/ExpanDrive/expandrive6.favorites.js");
    if(LocalFactory.get("~/Downloads").exists()) {
        // For 10.5+ this usually exists and should be preferrred
        defaults.put("queue.download.folder", "~/Downloads");
    }
    else {
        defaults.put("queue.download.folder", "~/Desktop");
    }
    defaults.put("browser.filesize.decimal", String.valueOf(!Factory.Platform.osversion.matches("10\\.5.*")));

    // SSL Keystore
    defaults.put("connection.ssl.keystore.type", "KeychainStore");
    defaults.put("connection.ssl.keystore.provider", "Apple");

    defaults.put("network.interface.blacklist", "awdl0 utun0");

    defaults.put("browser.window.tabbing.identifier", "browser.window.tabbing.identifier");
    // Allow to show transfers in browser window as tab
    defaults.put("queue.window.tabbing.identifier", "browser.window.tabbing.identifier");
}
 
Example 19
Project: cyberduck   File: TildeExpander.java   View Source Code Vote up 4 votes
public String abbreviate(final String name) {
    if(StringUtils.startsWith(name, preferences.getProperty("local.user.home"))) {
        return Local.HOME + StringUtils.removeStart(name, preferences.getProperty("local.user.home"));
    }
    return name;
}
 
Example 20
Project: mensa-api   File: LabelCache.java   View Source Code Vote up 4 votes
private boolean isLabel(Label label, String simplifiedSearchText) {
    String simplifiedLabelName = simplify(label.getName());
    return simplifiedLabelName.equals(simplifiedSearchText) || StringUtils.startsWith(simplifiedLabelName, simplifiedSearchText) || StringUtils.startsWith(simplifiedSearchText, simplifiedLabelName);
}