Java Code Examples for org.eclipse.core.runtime.IPath#addTrailingSeparator()

The following examples show how to use org.eclipse.core.runtime.IPath#addTrailingSeparator() . 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: GitCommitHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private boolean identifyNewCommitResource(HttpServletRequest request, HttpServletResponse response, Repository db, String newCommit)
		throws ServletException {
	try {
		URI u = getURI(request);
		IPath p = new Path(u.getPath());
		IPath np = new Path("/"); //$NON-NLS-1$
		for (int i = 0; i < p.segmentCount(); i++) {
			String s = p.segment(i);
			if (i == 2) {
				s += ".." + GitUtils.encode(newCommit); //$NON-NLS-1$
			}
			np = np.append(s);
		}
		if (p.hasTrailingSeparator())
			np = np.addTrailingSeparator();
		URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), np.toString(), request.getQueryString(), u.getFragment());
		JSONObject result = new JSONObject();
		result.put(ProtocolConstants.KEY_LOCATION, nu);
		OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
		response.setHeader(ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString());
		return true;
	} catch (Exception e) {
		return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
				"An error occurred when identifying a new Commit resource.", e));
	}
}
 
Example 2
Source File: TarLeveledStructureProvider.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a new container tar entry with the specified name, iff it has
 * not already been created. If the parent of the given element does not
 * already exist it will be recursively created as well.
 * @param pathName The path representing the container
 * @return The element represented by this pathname (it may have already existed)
 */
protected TarArchiveEntry createContainer(IPath pathName) {
    IPath newPathName = pathName;
    TarArchiveEntry existingEntry = directoryEntryCache.get(newPathName);
    if (existingEntry != null) {
        return existingEntry;
    }

    TarArchiveEntry parent;
    if (newPathName.segmentCount() == 1) {
        parent = root;
    } else {
        parent = createContainer(newPathName.removeLastSegments(1));
    }
    // Add trailing / so that the entry knows it's a folder
    newPathName = newPathName.addTrailingSeparator();
    TarArchiveEntry newEntry = new TarArchiveEntry(newPathName.toString());
    directoryEntryCache.put(newPathName, newEntry);
    List<TarArchiveEntry> childList = new ArrayList<>();
    children.put(newEntry, childList);

    List<TarArchiveEntry> parentChildList = children.get(parent);
    NonNullUtils.checkNotNull(parentChildList).add(newEntry);
    return newEntry;
}
 
Example 3
Source File: ResourceTreeSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the selected resource(s) as a list of paths relative to the root
 * resource.
 * 
 * @param addTrailingSeparatorToContainerPaths if <code>true</code>, all paths
 *          to containers will end with a trailing slash. This is useful when
 *          the paths are used as filter patterns, since a trailing slash will
 *          include all sub-directories (e.g. foo/ == foo/**).
 */
public List<IPath> chooseResourcePaths(
    boolean addTrailingSeparatorToContainerPaths) {
  List<IResource> resources = chooseResources();

  if (resources != null) {
    List<IPath> paths = new ArrayList<IPath>();

    // Convert each selected IResource into a path relative to the ancestor
    for (IResource resource : resources) {
      int ancestorSegments = rootResource.getFullPath().segmentCount();
      IPath path = resource.getFullPath().removeFirstSegments(
          ancestorSegments).makeRelative();
      if (addTrailingSeparatorToContainerPaths
          && resource instanceof IContainer) {
        path = path.addTrailingSeparator();
      }
      paths.add(path);
    }

    return paths;
  }
  return null;
}
 
Example 4
Source File: MovePackageFragmentRootOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IPath[] renamePatterns(IPath rootPath, IPath[] patterns) {
	IPath[] newPatterns = null;
	int newPatternsIndex = -1;
	for (int i = 0, length = patterns.length; i < length; i++) {
		IPath pattern = patterns[i];
		if (pattern.equals(rootPath)) {
			if (newPatterns == null) {
				newPatterns = new IPath[length];
				System.arraycopy(patterns, 0, newPatterns, 0, i);
				newPatternsIndex = i;
			}
			IPath newPattern = this.destination.removeFirstSegments(1);
			if (pattern.hasTrailingSeparator())
				newPattern = newPattern.addTrailingSeparator();
			newPatterns[newPatternsIndex++] = newPattern;
		}
	}
	return newPatterns;
}
 
Example 5
Source File: GitDiffHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private boolean identifyNewDiffResource(HttpServletRequest request, HttpServletResponse response) throws ServletException {
	try {
		StringWriter writer = new StringWriter();
		IOUtilities.pipe(request.getReader(), writer, false, false);
		JSONObject requestObject = new JSONObject(writer.toString());
		URI u = getURI(request);
		IPath p = new Path(u.getPath());
		IPath np = new Path("/"); //$NON-NLS-1$
		for (int i = 0; i < p.segmentCount(); i++) {
			String s = p.segment(i);
			if (i == 2) {
				s += ".."; //$NON-NLS-1$
				s += GitUtils.encode(requestObject.getString(GitConstants.KEY_COMMIT_NEW));
			}
			np = np.append(s);
		}
		if (p.hasTrailingSeparator())
			np = np.addTrailingSeparator();
		URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), np.toString(), u.getQuery(), u.getFragment());
		JSONObject result = new JSONObject();
		result.put(ProtocolConstants.KEY_LOCATION, nu.toString());
		OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
		response.setHeader(ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString());
		return true;
	} catch (Exception e) {
		return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
				"An error occured when identifying a new Diff resource.", e));
	}
}
 
Example 6
Source File: ImportTraceWizardPage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static String getSourceDirectoryName(String sourceName) {
    IPath result = new Path(sourceName.trim());
    if (result.getDevice() != null && result.segmentCount() == 0) {
        result = result.addTrailingSeparator();
    } else {
        result = result.removeTrailingSeparator();
    }
    return result.toOSString();
}
 
Example 7
Source File: HostingTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
// Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=382760 
public void testDisallowedSiteAccess() throws SAXException, IOException, JSONException, URISyntaxException, CoreException {
	UserInfo userBObject = createUser("userB", "userB");
	String userB = userBObject.getUniqueId();

	// User "test": create file in test's workspace
	final String filename = "foo.html";
	final String fileContent = "<html><body>This is a test file</body></html>";
	WebResponse createdFile = createFileOnServer("", filename, fileContent);
	URL fileLocation = createdFile.getURL();
	IPath filepath = new Path(fileLocation.getPath());
	filepath = filepath.removeFirstSegments(new Path(FILE_SERVLET_LOCATION).segmentCount()); // chop off leading /file/
	filepath = filepath.removeLastSegments(1); // chop off trailing /foo.html
	filepath = filepath.makeAbsolute();
	filepath = filepath.addTrailingSeparator();
	String parentFolder = filepath.toString();

	// User B: Give access to test's workspace
	String bWorkspaceId = workspaceId;
	AuthorizationService.addUserRight(userBObject.getUniqueId(), "/workspace/" + bWorkspaceId);
	AuthorizationService.addUserRight(userBObject.getUniqueId(), "/workspace/" + bWorkspaceId + "/*");

	// User B: create a site against B's workspace that exposes a file in test's workspace
	final String siteName = "My hosted site";
	final String filePath = parentFolder; //"/" + filename;
	final String mountAt = "/"; //"/file.html";
	final JSONArray mappings = makeMappings(new String[][] {{mountAt, filePath}});

	WebRequest createSiteReq = getCreateSiteRequest(siteName, bWorkspaceId, mappings, null);
	setAuthentication(createSiteReq, userB, userB);
	WebResponse createSiteResp = webConversation.getResponse(createSiteReq);
	assertEquals(HttpURLConnection.HTTP_CREATED, createSiteResp.getResponseCode());
	JSONObject siteObject = new JSONObject(createSiteResp.getText());

	// User B: Start the site
	String location = siteObject.getString(ProtocolConstants.HEADER_LOCATION);
	siteObject = startSite(location, userB, userB);

	final JSONObject hostingStatus = siteObject.getJSONObject(SiteConfigurationConstants.KEY_HOSTING_STATUS);
	final String hostedURL = hostingStatus.getString(SiteConfigurationConstants.KEY_HOSTING_STATUS_URL);

	// Attempt to access file on user B's site, should fail
	WebRequest getFileReq = new GetMethodWebRequest(hostedURL + mountAt);
	WebResponse getFileResp = webConversation.getResponse(getFileReq);
	assertEquals(HttpURLConnection.HTTP_FORBIDDEN, getFileResp.getResponseCode());
}
 
Example 8
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void updateFilters(IPath oldPath, IPath newPath) {
	if (oldPath == null)
		return;

	IPath projPath= fNewElement.getJavaProject().getProject().getFullPath();
	if (projPath.isPrefixOf(oldPath)) {
		oldPath= oldPath.removeFirstSegments(projPath.segmentCount()).addTrailingSeparator();
	}
	if (projPath.isPrefixOf(newPath)) {
		newPath= newPath.removeFirstSegments(projPath.segmentCount()).addTrailingSeparator();
	}

	for (Iterator<CPListElement> iter= fExistingEntries.iterator(); iter.hasNext();) {
		CPListElement element= iter.next();
		IPath elementPath= element.getPath();
		if (projPath.isPrefixOf(elementPath)) {
			elementPath= elementPath.removeFirstSegments(projPath.segmentCount());
			if (elementPath.segmentCount() > 0)
				elementPath= elementPath.addTrailingSeparator();
		}

		IPath[] exlusions= (IPath[])element.getAttribute(CPListElement.EXCLUSION);
		if (exlusions != null) {
			for (int i= 0; i < exlusions.length; i++) {
				if (elementPath.append(exlusions[i]).equals(oldPath)) {
					fModifiedElements.add(element);
					exlusions[i]= newPath.removeFirstSegments(elementPath.segmentCount());
				}
			}
			element.setAttribute(CPListElement.EXCLUSION, exlusions);
		}

		IPath[] inclusion= (IPath[])element.getAttribute(CPListElement.INCLUSION);
		if (inclusion != null) {
			for (int i= 0; i < inclusion.length; i++) {
				if (elementPath.append(inclusion[i]).equals(oldPath)) {
					fModifiedElements.add(element);
					inclusion[i]= newPath.removeFirstSegments(elementPath.segmentCount());
				}
			}
			element.setAttribute(CPListElement.INCLUSION, inclusion);
		}
	}
}