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

The following examples show how to use org.eclipse.emf.common.util.URI#isRelative() . 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: URIUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Adds empty authority to the given URI. Necessary for windows platform. */
public static URI addEmptyAuthority(URI uri) {
	if (uri.isFile() && !uri.hasAuthority() && !uri.isRelative()) {
		uri = URI.createHierarchicalURI(uri.scheme(), "", uri.device(), uri.segments(), uri.query(),
				uri.fragment());
	}
	return uri;
}
 
Example 2
Source File: LazyStandaloneSetup.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private URI createURI(String path) {
    if (path == null) {
        throw new IllegalArgumentException();
    }

    URI uri = URI.createURI(path);
    if (uri.isRelative()) {
        URI resolvedURI = URI.createFileURI(new File(path).getAbsolutePath());
        return resolvedURI;
    }
    return uri;
}
 
Example 3
Source File: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private static URI getResolvedImportUri(Resource context, URI uri) {
	URI contextURI = context.getURI();
	if (contextURI.isHierarchical() && !contextURI.isRelative() && (uri.isRelative() && !uri.isEmpty())) {
		uri = uri.resolve(contextURI);
	}
	return uri;
}
 
Example 4
Source File: XtendXtext2EcorePostProcessor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected URI getXtendFileLocation(GeneratedMetamodel metamodel) {
	URI uri = metamodel.eResource().getURI();
	// check if uri can be used for resolve
	if (!uri.isHierarchical() || uri.isRelative())
		return null;
	uri = URI.createURI(Strings.lastToken(getExtensionName(metamodel), "::")).appendFileExtension(
			XtendFile.FILE_EXTENSION).resolve(uri);
	return uri;
}
 
Example 5
Source File: DefaultTraceURIConverter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public SourceRelativeURI getURIForTrace(Resource resource) {
	if (configProvider != null) {
		IProjectConfig projectConfig = configProvider.getProjectConfig(resource.getResourceSet());
		if (projectConfig != null) {
			return getURIForTrace(projectConfig, new AbsoluteURI(resource.getURI()));
		}
	}
	// tests and in-memory resources often use relative uris, e.g. __synthetic.mydsl
	URI uri = resource.getURI();
	if (uri.isRelative()) {
		return new SourceRelativeURI(uri);
	}
	return getURIForTrace(uri);
}
 
Example 6
Source File: LazyStandaloneSetup.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private URI createURI(String path) {
    if (path == null) {
        throw new IllegalArgumentException();
    }

    URI uri = URI.createURI(path);
    if (uri.isRelative()) {
        URI resolvedURI = URI.createFileURI(new File(path).getAbsolutePath());
        return resolvedURI;
    }
    return uri;
}
 
Example 7
Source File: StandaloneSetup.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Copied from super class.
 *
 * @param path
 *          path to genmodel
 * @return URI
 */
private URI createURI(final String path) {
  if (path == null) {
    throw new IllegalArgumentException();
  }

  URI uri = URI.createURI(path);
  if (uri.isRelative()) {
    return URI.createFileURI(new File(path).getAbsolutePath());
  }
  return uri;
}
 
Example 8
Source File: ExternalLibraryWorkspace.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileURI fromURI(URI uri) {
	if (!uri.isFile() || uri.isRelative()) {
		return null;
	}
	return new FileURI(uriExtensions.withEmptyAuthority(uri));
}
 
Example 9
Source File: N4JSRuntimeCore.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<? extends IN4JSSourceContainer> findN4JSSourceContainer(URI nestedLocation) {
	if (nestedLocation == null || (nestedLocation.isFile() && nestedLocation.isRelative())) {
		return Optional.absent();
	} else {
		return model.findN4JSSourceContainer(nestedLocation);
	}
}
 
Example 10
Source File: N4JSResource.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setURI(URI uri) {
	if (uri != null) {
		if (uri.isFile() && !uri.isRelative()) {
			if (!uri.hasAuthority()) {
				throw new IllegalArgumentException("File URI without authority: " + uri);
			}
		}
	}
	super.setURI(uri);
}
 
Example 11
Source File: AutoDiscoveryFileBasedWorkspace.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileURI fromURI(URI unsafe) {
	if (!unsafe.isFile() || unsafe.isRelative()) {
		unsafe = URIUtils.normalize(unsafe);
		if (unsafe.isRelative()) {
			return null;
		}
	}
	return super.fromURI(unsafe);
}
 
Example 12
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 13
Source File: ResourceUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Finds the file corresponding to the specified URI, using a URI converter if necessary (and provided) to normalize
 * it.
 * 
 * @param uri
 *            a URI
 * @param converter
 *            an optional URI converter (may be <code>null</code>)
 * 
 * @return the file, if available in the workspace
 */
private static IFile getFile(URI uri, URIConverter converter, boolean considerArchives) {
	IFile result = null;

	if (considerArchives && uri.isArchive()) {
		class MyArchiveURLConnection extends ArchiveURLConnection {
			public MyArchiveURLConnection(String url) {
				super(url);
			}

			public String getNestedURI() {
				try {
					return getNestedURL();
				} catch (IOException exception) {
					return ""; //$NON-NLS-1$
				}
			}
		}
		MyArchiveURLConnection archiveURLConnection = new MyArchiveURLConnection(uri.toString());
		result = getFile(URI.createURI(archiveURLConnection.getNestedURI()), converter, considerArchives);
	} else if (uri.isPlatformResource()) {
		IPath path = new Path(uri.toPlatformString(true));
		result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
	} else if (uri.isFile() && !uri.isRelative()) {
		result = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(uri.toFileString()));
	} else {
		// normalize, to see whether we can resolve it this time
		if (converter != null) {
			URI normalized = converter.normalize(uri);

			if (!uri.equals(normalized)) {
				// recurse on the new URI
				result = getFile(normalized, converter, considerArchives);
			}
		}
	}

	if ((result == null) && !uri.isRelative()) {
		try {
			IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(
					new java.net.URI(uri.toString()));
			if (files.length > 0) {
				// set the result to be the first file found
				result = files[0];
			}
		} catch (URISyntaxException e) {
			// won't get this because EMF provides a well-formed URI
		}
	}

	return result;
}
 
Example 14
Source File: Repository.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isManaged(Resource resource) {
    URI resourceURI = resource.getURI();
    if (resourceURI.isRelative())
        resourceURI = resourceURI.resolve(baseURI);
    return resourceURI.toString().startsWith(baseURI.toString());
}
 
Example 15
Source File: AbstractPortableURIsTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 16
Source File: AbstractPortableURIsTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertPortableURI(URI uri) {
	if (uri.isRelative()) {
		String path = uri.path();
		assertFalse(uri.toString() + " is not portable", path.startsWith(".."));
	}
}
 
Example 17
Source File: TraceRegionSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public <Location, Region> Region doReadFrom(DataInput dataStream, Strategy<Region, Location> reader, Region parent, int version)
		throws IOException {
	int offset = dataStream.readInt();
	int length = dataStream.readInt();
	int lineNumber = dataStream.readInt();
	int endLineNumber = dataStream.readInt();
	boolean useForDebugging = version < VERSION_5 || dataStream.readBoolean();
	int locationSize = dataStream.readInt();
	List<Location> allLocations = Lists.newArrayListWithCapacity(locationSize);
	while(locationSize != 0) {
		int locationOffset = dataStream.readInt();
		int locationLength = dataStream.readInt();
		int locationLineNumber = dataStream.readInt();
		int locationEndLineNumber = dataStream.readInt();
		final SourceRelativeURI path;
		if (dataStream.readBoolean()) {
			if (version < VERSION_5) {
				URI uri = URI.createURI(dataStream.readUTF());
				if (version == VERSION_3 && !uri.isRelative()) {
					if (uri.isPlatform()) {
						String platformString = uri.toPlatformString(false);
						path = new SourceRelativeURI(platformString.substring(platformString.indexOf('/') + 1));
					} else if (uri.isFile()) {
						path = new SourceRelativeURI(uri.lastSegment());
					} else {
						path = SourceRelativeURI.fromAbsolute(uri);
					}
				} else {
					path = new SourceRelativeURI(uri);
				}
			} else {
				path = new SourceRelativeURI(dataStream.readUTF());
			}
		} else {
			path = null;
		}
		if(version == VERSION_3) {
			if (dataStream.readBoolean()) // true, if a project is specified
				dataStream.readUTF(); // read and skip the project name
		}
		allLocations.add(reader.createLocation(locationOffset, locationLength, locationLineNumber, locationEndLineNumber, path));
		locationSize--;
	}
	Region result = reader.createRegion(offset, length, lineNumber, endLineNumber, useForDebugging, allLocations, parent);
	int childrenSize = dataStream.readInt();
	while(childrenSize != 0) {
		doReadFrom(dataStream, reader, result, version);
		childrenSize--;
	}
	return result;
}
 
Example 18
Source File: SourceRelativeURI.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static SourceRelativeURI fromAbsolute(URI uri) {
	if (uri.isRelative()) {
		throw new IllegalArgumentException(uri.toString());
	}
	return new SourceRelativeURI(uri.path().substring(1));
}
 
Example 19
Source File: SourceRelativeURI.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public SourceRelativeURI(URI sourceRelativeURI) {
	super(sourceRelativeURI);
	if (!sourceRelativeURI.isRelative() || sourceRelativeURI.path().startsWith("/")) {
		throw new IllegalArgumentException(String.valueOf(sourceRelativeURI));
	}
}
 
Example 20
Source File: RepoRelativePathHolder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private URI fixupURI(Resource res) {
	URI uri = res.getURI();
	if (uri.isFile() && !uri.isRelative())
		return uriExtensions.withEmptyAuthority(uri);
	return uri;
}