List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:net.turnbig.pandora.web.Servlets.java
/** * // w w w . j av a 2s.c om * http://domain:port/context/related-path * * @param request * @return related-path */ public static String getRelatedpath(HttpServletRequest request) { String requestURI = request.getRequestURI(); // context-path + path String contextPath = request.getContextPath(); return StringUtils.removeStart(requestURI, contextPath); }
From source file:no.kantega.publishing.common.ContentIdHelperImpl.java
/** * Check url for whether it starts with a site alias. If it does, remove site alias. * Eg site with alias /sitealias and url /sitealias results in url /, url /sitealias/alias gived /alias * @param site to check url against. May be null, then all sites are tested. * @param url Url to test/*w ww .j a va 2 s . co m*/ * @return pair with siteId and adjusted url. If site given is null and no site alias match, the resulting siteId * is -1 and the same url as given is returned. */ private Pair<Integer, String> getUrlAdjustedBySiteAlias(Site site, String url) { String ajustedUrl = url.endsWith("/") ? url : url + "/"; int siteId = -1; if (site == null) { List<Site> sites = siteCache.getSites(); for (Site s : sites) { String siteAliasWithTrailingSlash = s.getAlias().endsWith("/") ? s.getAlias() : s.getAlias() + "/"; if (ajustedUrl.startsWith(siteAliasWithTrailingSlash)) { url = "/" + StringUtils.removeStart(ajustedUrl, siteAliasWithTrailingSlash); siteId = s.getId(); break; } } } else { String siteAliasWithTrailingSlash = site.getAlias().endsWith("/") ? site.getAlias() : site.getAlias() + "/"; if (ajustedUrl.startsWith(siteAliasWithTrailingSlash)) { url = "/" + StringUtils.remove(ajustedUrl, siteAliasWithTrailingSlash); } siteId = site.getId(); } return Pair.of(siteId, url); }
From source file:org.apache.falcon.catalog.CatalogPartitionHandler.java
protected List<String> getDynamicPartitions(Path path, Path staticPath) { String dynPart = path.toUri().getPath().substring(staticPath.toString().length()); dynPart = StringUtils.removeStart(dynPart, "/"); dynPart = StringUtils.removeEnd(dynPart, "/"); if (StringUtils.isEmpty(dynPart)) { return new ArrayList<String>(); }//from w w w . j av a 2s . c om return Arrays.asList(dynPart.split("/")); }
From source file:org.apache.falcon.oozie.feed.OozieFeedWorkflowBuilderTest.java
private COORDINATORAPP getCoordinator(EmbeddedCluster cluster, String appPath) throws Exception { return getCoordinator(cluster.getFileSystem(), new Path(StringUtils.removeStart(appPath, "${nameNode}"))); }
From source file:org.apache.hadoop.hbase.regionserver.TestHdfsSnapshotHRegion.java
@Before public void setUp() throws Exception { Configuration c = TEST_UTIL.getConfiguration(); c.setBoolean("dfs.support.append", true); TEST_UTIL.startMiniCluster(1);/* w w w . j a v a 2 s.com*/ table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY); TEST_UTIL.loadTable(table, FAMILY); // setup the hdfssnapshots client = new DFSClient(TEST_UTIL.getDFSCluster().getURI(), TEST_UTIL.getConfiguration()); String fullUrIPath = TEST_UTIL.getDefaultRootDirPath().toString(); String uriString = TEST_UTIL.getTestFileSystem().getUri().toString(); baseDir = StringUtils.removeStart(fullUrIPath, uriString); client.allowSnapshot(baseDir); }
From source file:org.apache.marmotta.ldclient.provider.youtube.YoutubeVideoPagesProvider.java
@Override public ClientResponse retrieveResource(String resource, LDClientService client, Endpoint endpoint) throws DataRetrievalException { Model model = new TreeModel(); String uri = resource;/*w w w . j av a 2 s .co m*/ URI objUri; try { objUri = new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException("URI '" + uri + "'could not be parsed, it is not a valid URI"); } String video_id = null; if (uri.startsWith(YOUTUBE_V)) { // YouTube short watch video URL String[] p_components = objUri.getPath().split("/"); video_id = p_components[p_components.length - 1]; } else if (resource.startsWith(YOUTUBE_WATCH)) { // YouTube watch video URL List<NameValuePair> params = URLEncodedUtils.parse(objUri, "UTF-8"); for (NameValuePair pair : params) { if ("v".equals(pair.getName())) { video_id = pair.getValue(); break; } } } else if (uri.startsWith(YOUTUBE_GDATA)) { // GData URI video_id = StringUtils.removeStart(uri, YOUTUBE_GDATA); } if (StringUtils.isBlank(video_id)) { String msg = "Not valid video id found in '" + uri + "'"; log.error(msg); throw new DataRetrievalException(msg); } else { model.add(new URIImpl(uri), new URIImpl(FOAF_PRIMARY_TOPIC), new URIImpl(YoutubeVideoProvider.YOUTUBE_BASE_URI + video_id), (Resource) null); // FIXME: add inverse triple, but maybe at the YoutubeVideoProvider ClientResponse clientResponse = new ClientResponse(200, model); clientResponse.setExpires(DateUtils.addYears(new Date(), 10)); return clientResponse; } }
From source file:org.apache.marmotta.ldclient.provider.youtube.YoutubeVideoProvider.java
/** * Build the URL to use to call the webservice in order to retrieve the data for the resource passed as argument. * In many cases, this will just return the URI of the resource (e.g. Linked Data), but there might be data providers * that use different means for accessing the data for a resource, e.g. SPARQL or a Cache. * * * @param resource/*from www . j av a 2 s . c o m*/ * @param endpoint endpoint configuration for the data provider (optional) * @return */ @Override public List<String> buildRequestUrl(String resource, Endpoint endpoint) { String uri = resource; if (uri.startsWith(YOUTUBE_BASE_URI)) { // YouTube video URI, request the GData URI instead String video_id = StringUtils.removeStart(uri, YOUTUBE_BASE_URI); if (StringUtils.isNotBlank(video_id)) return Collections.singletonList(GDATA_VIDEO_FEED + video_id); } return Collections.singletonList(uri); }
From source file:org.apache.marmotta.platform.ldp.webservices.PreferHeader.java
/** * Parse a PreferHeader./*from w w w . ja va2 s .c o m*/ * @param headerValue the header value to parse * @return the parsed PreferHeader */ public static PreferHeader valueOf(String headerValue) { if (StringUtils.isBlank(headerValue)) { log.error("Empty Prefer-Header - what should I do now?"); throw new InvalidArgumentException(); } String pref = null, val = null; final Map<String, String> params = new LinkedHashMap<>(); final String[] parts = headerValue.split("\\s*;\\s"); for (int i = 0; i < parts.length; i++) { final String part = parts[i]; final String[] kv = part.split("\\s*=\\s*", 2); if (i == 0) { pref = StringUtils.trimToNull(kv[0]); if (kv.length > 1) { val = StringUtils.trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\"")); } } else { String p, pval = null; p = StringUtils.trimToNull(kv[0]); if (kv.length > 1) { pval = StringUtils .trimToNull(StringUtils.removeStart(StringUtils.removeEnd(kv[1], "\""), "\"")); } params.put(p, pval); } } final PreferHeader header = new PreferHeader(pref); header.preferenceValue = val; header.params = params; return header; }
From source file:org.apache.maven.plugin.surefire.util.DirectoryScanner.java
private String stripBaseDir(String basedir, String test) { return StringUtils.removeStart(test, basedir); }
From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java
/** * Serializes a map into a URI./* w ww . java2 s . c o m*/ * @param subject the {@link RyaURI} subject of the Entity. Identifies the * thing that is being represented as an Entity. * @param map the {@link Map} of {@link URI}s to {@link Value}s. * @return the Smart {@link URI}. * @throws SmartUriException */ public static URI serializeUri(final RyaURI subject, final Map<URI, Value> map) throws SmartUriException { final String subjectData = subject.getData(); final int fragmentPosition = subjectData.indexOf("#"); String prefix = subjectData; String fragment = null; if (fragmentPosition > -1) { prefix = subjectData.substring(0, fragmentPosition); fragment = subjectData.substring(fragmentPosition + 1, subjectData.length()); } URIBuilder uriBuilder = null; try { if (fragmentPosition > -1) { uriBuilder = new URIBuilder(new java.net.URI("urn://" + fragment)); } else { uriBuilder = new URIBuilder(new java.net.URI(subjectData.replaceFirst(":", "://"))); } } catch (final URISyntaxException e) { throw new SmartUriException("Unable to serialize a Smart URI from the provided properties", e); } final List<NameValuePair> nameValuePairs = new ArrayList<>(); for (final Entry<URI, Value> entry : map.entrySet()) { final URI key = entry.getKey(); final Value value = entry.getValue(); nameValuePairs.add(new BasicNameValuePair(key.getLocalName(), value.stringValue())); } uriBuilder.setParameters(nameValuePairs); URI uri = null; try { if (fragmentPosition > -1) { final java.net.URI partialUri = uriBuilder.build(); final String uriString = StringUtils.removeStart(partialUri.getRawSchemeSpecificPart(), "//"); final URIBuilder fragmentUriBuilder = new URIBuilder(new java.net.URI(prefix)); fragmentUriBuilder.setFragment(uriString); final String fragmentUriString = fragmentUriBuilder.build().toString(); uri = new URIImpl(fragmentUriString); } else { final String uriString = uriBuilder.build().toString(); uri = new URIImpl(uriString); } } catch (final URISyntaxException e) { throw new SmartUriException("Smart URI could not serialize the property map.", e); } return uri; }