Java Code Examples for org.eclipse.core.runtime.URIUtil#fromString()

The following examples show how to use org.eclipse.core.runtime.URIUtil#fromString() . 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: TransferTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testImportAndUnzip() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	//start the import
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip");
	File source = new File(FileLocator.toFileURL(entry).getPath());
	long length = source.length();
	String importPath = getImportRequestPath(directoryPath);
	PostMethodWebRequest request = new PostMethodWebRequest(importPath);
	request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
	setAuthentication(request);
	WebResponse postResponse = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
	String location = postResponse.getHeaderField("Location");
	assertNotNull(location);
	URI importURI = URIUtil.fromString(importPath);
	location = importURI.resolve(location).toString();
	doImport(source, length, location);

	//assert the file has been unzipped in the workspace
	assertTrue(checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/js/navigate-tree/navigate-tree.js"));
}
 
Example 2
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testImportFile() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	//start the import
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip");
	File source = new File(FileLocator.toFileURL(entry).getPath());
	long length = source.length();
	String importPath = getImportRequestPath(directoryPath);
	PostMethodWebRequest request = new PostMethodWebRequest(importPath);
	request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
	request.setHeaderField("X-Xfer-Options", "raw");

	request.setHeaderField("Slug", "client.zip");
	setAuthentication(request);
	WebResponse postResponse = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
	String location = postResponse.getHeaderField("Location");
	assertNotNull(location);
	URI importURI = URIUtil.fromString(importPath);
	location = importURI.resolve(location).toString();

	doImport(source, length, location);

	//assert the file is present in the workspace
	assertTrue(checkFileExists(directoryPath + "/client.zip"));
	//assert that imported file has same content as original client.zip
	assertTrue(checkContentEquals(source, directoryPath + "/client.zip"));
}
 
Example 3
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testImportDBCSFilename() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	//start the import
	// file with DBCS character in the filename.
	String filename = "\u3042.txt";
	File source = null;
	try {
		source = createTempFile(filename, "No content");
		long length = source.length();
		String importPath = getImportRequestPath(directoryPath);
		PostMethodWebRequest request = new PostMethodWebRequest(importPath);
		request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
		request.setHeaderField("X-Xfer-Options", "raw");

		request.setHeaderField("Slug", Slug.encode(filename));
		setAuthentication(request);
		WebResponse postResponse = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
		String location = postResponse.getHeaderField("Location");
		assertNotNull(location);
		URI importURI = URIUtil.fromString(importPath);
		location = importURI.resolve(location).toString();

		doImport(source, length, location, "text/plain");

		//assert the file is present in the workspace
		assertTrue(checkFileExists(directoryPath + File.separator + filename));
		//assert that imported file has same content as original client.zip
		assertTrue(checkContentEquals(source, directoryPath + File.separator + filename));
	} finally {
		// Delete the temp file
		FileUtils.deleteQuietly(source);
	}
}
 
Example 4
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testImportFileMultiPart() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip");
	File source = new File(FileLocator.toFileURL(entry).getPath());

	// current server implementation cannot handle binary data, thus base64-encode client.zip before import
	File expected = EFS.getStore(makeLocalPathAbsolute(directoryPath + "/expected.txt")).toLocalFile(EFS.NONE, null);
	byte[] expectedContent = Base64.encode(FileUtils.readFileToByteArray(source));
	FileUtils.writeByteArrayToFile(expected, expectedContent);

	//start the import
	long length = expectedContent.length;
	String importPath = getImportRequestPath(directoryPath);
	PostMethodWebRequest request = new PostMethodWebRequest(importPath);
	request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
	request.setHeaderField("X-Xfer-Options", "raw");
	request.setHeaderField("Slug", "actual.txt");
	setAuthentication(request);
	WebResponse postResponse = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
	String location = postResponse.getHeaderField("Location");
	assertNotNull(location);
	URI importURI = URIUtil.fromString(importPath);
	location = importURI.resolve(location).toString();

	// perform the upload
	doImport(expected, length, location, "multipart/mixed;boundary=foobar");

	//assert the file is present in the workspace
	assertTrue(checkFileExists(directoryPath + "/actual.txt"));
	//assert that actual.txt has same content as expected.txt
	assertTrue(checkContentEquals(expected, directoryPath + "/actual.txt"));
}
 
Example 5
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testImportWithPostZeroByteFile() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	//start the import
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/zeroByteFile.txt");
	File source = new File(FileLocator.toFileURL(entry).getPath());
	long length = source.length();
	assertEquals(length, 0);
	String importPath = getImportRequestPath(directoryPath);
	PostMethodWebRequest request = new PostMethodWebRequest(importPath);
	request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
	request.setHeaderField("X-Xfer-Options", "raw");

	request.setHeaderField("Slug", "zeroByteFile.txt");
	setAuthentication(request);
	WebResponse postResponse = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
	String location = postResponse.getHeaderField("Location");
	assertNotNull(location);
	URI importURI = URIUtil.fromString(importPath);
	location = importURI.resolve(location).toString();

	doImport(source, length, location, "text/plain");

	//assert the file is present in the workspace
	assertTrue(checkFileExists(directoryPath + "/zeroByteFile.txt"));
}
 
Example 6
Source File: FileSystemTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected URI makeLocalPathAbsolute(String path) {
	String absolutePath = getAbsolutePath(path);
	try {
		return URIUtil.fromString(absolutePath);
	} catch (URISyntaxException e) {
		fail(e.getMessage());
		return null;
	}
}
 
Example 7
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testImportEmojiFilename() throws CoreException, IOException, SAXException, URISyntaxException {
	//create a directory to upload to
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);

	//start the import
	// file with Emoji characters in the filename.
	// U+1F60A: SMILING FACE WITH SMILING EYES ("\ud83d\ude0a")
	// U+1F431: CAT FACE ("\ud83d\udc31")
	// U+1F435: MONKEY FACE ("\ud83d\udc35")
	String filename = "\ud83d\ude0a\ud83d\udc31\ud83d\udc35.txt";
	String contents = "Emoji characters: \ud83d\ude0a\ud83d\udc31\ud83d\udc35";
	File source = null;
	try {
		source = createTempFile(filename, contents);
		long length = source.length();

		String importPath = getImportRequestPath(directoryPath);
		PostMethodWebRequest request = new PostMethodWebRequest(importPath);
		request.setHeaderField("X-Xfer-Content-Length", Long.toString(length));
		request.setHeaderField("X-Xfer-Options", "raw");

		request.setHeaderField("Slug", Slug.encode(filename));
		setAuthentication(request);
		WebResponse postResponse = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode());
		String location = postResponse.getHeaderField("Location");
		assertNotNull(location);
		URI importURI = URIUtil.fromString(importPath);
		location = importURI.resolve(location).toString();

		doImport(source, length, location, "text/plain");

		//assert the file is present in the workspace
		assertTrue(checkFileExists(directoryPath + File.separator + filename));
		//assert that imported file has same content as original client.zip
		assertTrue(checkContentEquals(source, directoryPath + File.separator + filename));
	} finally {
		// Delete the temp file
		FileUtils.deleteQuietly(source);
	}
}
 
Example 8
Source File: LocalWebServerHttpRequestHandler.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void handleRequest(HttpRequest request, HttpResponse response, boolean head) throws HttpException,
		IOException, CoreException, URISyntaxException
{
	String target = URLDecoder.decode(request.getRequestLine().getUri(), IOUtil.UTF_8);
	URI uri = URIUtil.fromString(target);
	IFileStore fileStore = uriMapper.resolve(uri);
	IFileInfo fileInfo = fileStore.fetchInfo();
	if (fileInfo.isDirectory())
	{
		fileInfo = getIndex(fileStore);
		if (fileInfo.exists())
		{
			fileStore = fileStore.getChild(fileInfo.getName());
		}
	}
	if (!fileInfo.exists())
	{
		response.setStatusCode(HttpStatus.SC_NOT_FOUND);
		response.setEntity(createTextEntity(MessageFormat.format(
				Messages.LocalWebServerHttpRequestHandler_FILE_NOT_FOUND, uri.getPath())));
	}
	else if (fileInfo.isDirectory())
	{
		response.setStatusCode(HttpStatus.SC_FORBIDDEN);
		response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_FORBIDDEN));
	}
	else
	{
		response.setStatusCode(HttpStatus.SC_OK);
		if (head)
		{
			response.setEntity(null);
		}
		else
		{
			File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor());
			final File temporaryFile = (file == null) ? fileStore.toLocalFile(EFS.CACHE, new NullProgressMonitor())
					: null;
			response.setEntity(new NFileEntity((file != null) ? file : temporaryFile, getMimeType(fileStore
					.getName()))
			{
				@Override
				public void close() throws IOException
				{
					try
					{
						super.close();
					}
					finally
					{
						if (temporaryFile != null && !temporaryFile.delete())
						{
							temporaryFile.deleteOnExit();
						}
					}
				}
			});
		}
	}
}