Java Code Examples for org.eclipse.emf.common.util.URI#segments()

The following examples show how to use org.eclipse.emf.common.util.URI#segments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeURI.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private U appendRelativeURI(URI relativeURI) {
	String[] segments = relativeURI.segments();
	if (segments.length == 0) {
		throw new IllegalArgumentException("Cannot append empty URI.");
	}
	if (!URI.validSegments(segments)) {
		throw new IllegalArgumentException(String.valueOf(relativeURI));
	}
	if (segments.length == 1 && segments[0].isEmpty()) {
		throw new IllegalArgumentException("Use withTrailingPathDelimiter instead");
	}
	for (int i = 0; i < segments.length - 1; i++) {
		if (segments[i].isEmpty()) {
			throw new IllegalArgumentException("Cannot add intermediate empty segments");
		}
	}
	URI base = withTrailingPathDelimiter().toURI();
	URI result = relativeURI.resolve(base);
	return createFrom(result);
}
 
Example 2
Source File: UriUtil.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * A URI is a prefix of another URI if:
 * <br/>
 * <ul>
 * 	<li>Both have the same scheme</li>
 * 	<li>The prefix ends with a trailing separator</li>
 * 	<li>The segments of both URIs match up to the prefix's length</li>
 * </ul>
 */
public static boolean isPrefixOf(URI prefix, URI uri) {
	if (prefix.scheme() == null || !prefix.scheme().equals(uri.scheme()))
		return false;
	String[] prefixSeg = prefix.segments();
	String[] uriSeg = uri.segments();
	if (prefixSeg.length == 0 || uriSeg.length == 0)
		return false;
	if (!prefix.hasTrailingPathSeparator())
		return false;
	if (uriSeg.length < prefixSeg.length - 1)
		return false;
	for (int i = 0; i < prefixSeg.length - 1; i++)
		if (!uriSeg[i].equals(prefixSeg[i]))
			return false;
	return true;
}