Java Code Examples for org.eclipse.core.runtime.URIUtil#append()
The following examples show how to use
org.eclipse.core.runtime.URIUtil#append() .
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: HostedSiteServlet.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Returns paths constructed by rewriting pathInfo using rules from the hosted site's mappings. * Paths are ordered from most to least specific match. * @param site The hosted site. * @param pathInfo Path to be rewritten. * @param queryString * @return The rewritten path. May be either:<ul> * <li>A path to a file in the Orion workspace, eg. <code>/ProjectA/foo/bar.txt</code></li> * <li>An absolute URL pointing to another site, eg. <code>http://foo.com/bar.txt</code></li> * </ul> * @return The rewritten paths. * @throws URISyntaxException */ private URI[] getMapped(IHostedSite site, IPath pathInfo, String queryString) throws URISyntaxException { final Map<String, List<String>> map = site.getMappings(); final IPath originalPath = pathInfo; IPath path = originalPath.removeTrailingSeparator(); List<URI> uris = new ArrayList<URI>(); String rest = null; final int count = path.segmentCount(); for (int i = 0; i <= count; i++) { List<String> base = map.get(path.toString()); if (base != null) { rest = originalPath.removeFirstSegments(count - i).toString(); for (int j = 0; j < base.size(); j++) { URI uri = (rest.equals("") || rest.equals("/")) ? new URI(base.get(j)) : URIUtil.append(new URI(base.get(j)), rest); uris.add(createUri(uri, queryString)); } } path = path.removeLastSegments(1); } if (uris.size() == 0) // No mapping for / return null; else return uris.toArray(new URI[uris.size()]); }
Example 2
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static void encodeChildren(IFileStore dir, URI location, JSONObject result, int depth, boolean addLocation) throws CoreException { if (depth <= 0) return; JSONArray children = new JSONArray(); //more efficient to ask for child information in bulk for certain file systems IFileInfo[] childInfos = dir.childInfos(EFS.NONE, null); for (IFileInfo childInfo : childInfos) { IFileStore childStore = dir.getChild(childInfo.getName()); String name = childInfo.getName(); if (childInfo.isDirectory()) name += "/"; //$NON-NLS-1$ URI childLocation = URIUtil.append(location, name); JSONObject childResult = ServletFileStoreHandler.toJSON(childStore, childInfo, addLocation ? childLocation : null); if (childInfo.isDirectory()) encodeChildren(childStore, childLocation, childResult, depth - 1); children.put(childResult); } try { result.put(ProtocolConstants.KEY_CHILDREN, children); } catch (JSONException e) { // cannot happen throw new RuntimeException(e); } }
Example 3
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException { //setup and precondition checks JSONObject requestObject = OrionServlet.readJSONRequest(request); String name = computeName(request, requestObject); if (name.length() == 0) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null)); IFileStore toCreate = dir.getChild(name); if (!name.equals(toCreate.getName()) || name.contains(":")) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad file name: " + name, null)); int options = getCreateOptions(request); boolean destinationExists = toCreate.fetchInfo(EFS.NONE, null).exists(); if (!validateOptions(request, response, toCreate, destinationExists, options)) return true; //perform the operation if (performPost(request, response, requestObject, toCreate, options)) { //write the response URI location = URIUtil.append(getURI(request), name); JSONObject result = ServletFileStoreHandler.toJSON(toCreate, toCreate.fetchInfo(EFS.NONE, null), location); result.append("FileEncoding", System.getProperty("file.encoding")); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, location).toASCIIString()); //response code should indicate if a new resource was actually created or not response.setStatus(destinationExists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED); } return true; }
Example 4
Source File: JavadocConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void validateURL(URL location) throws MalformedURLException, URISyntaxException { URI path= URIUtil.toURI(location); URI index = URIUtil.append(path, "index.html"); //$NON-NLS-1$ URI packagelist = URIUtil.append(path, "package-list"); //$NON-NLS-1$ URL indexURL = URIUtil.toURL(index); URL packagelistURL = URIUtil.toURL(packagelist); boolean suc= checkURLConnection(indexURL) && checkURLConnection(packagelistURL); if (suc) { showConfirmValidationDialog(indexURL); } else { MessageDialog.openWarning(fShell, fTitle, fInvalidMessage); } }
Example 5
Source File: GitTreeHandlerV1.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Override public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, String pathString) throws ServletException { IPath path = pathString == null ? Path.EMPTY : new Path(pathString); int segmentCount = path.segmentCount(); if (getMethod(request) == Method.GET && ( segmentCount == 0 || ("workspace".equals(path.segment(0)) && path.segmentCount() == 2) || //$NON-NLS-1$ ("file".equals(path.segment(0)) && path.segmentCount() == 2) //$NON-NLS-1$ )) { String userId = request.getRemoteUser(); if (userId == null) { statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, "User name not specified", null)); return false; } try { UserInfo user = OrionConfiguration.getMetaStore().readUser(userId); URI baseLocation = new URI("orion", null, request.getServletPath(), null, null); baseLocation = URIUtil.append(baseLocation, Tree.RESOURCE); baseLocation = URIUtil.append(baseLocation, "file"); //$NON-NLS-N$ if (segmentCount == 0) { OrionServlet.writeJSONResponse(request, response, UserInfoResourceHandler.toJSON(user, baseLocation), JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } WorkspaceInfo workspace = OrionConfiguration.getMetaStore().readWorkspace(path.segment(1)); if (workspace != null) { JSONArray children = new JSONArray(); for (String projectName : workspace.getProjectNames()) { ProjectInfo project = OrionConfiguration.getMetaStore().readProject(workspace.getUniqueId(), projectName); if (isAccessAllowed(user.getUserName(), project)) { IPath projectPath = GitUtils.pathFromProject(workspace, project); Map<IPath, File> gitDirs = GitUtils.getGitDirs(projectPath, Traverse.GO_DOWN); for (Map.Entry<IPath, File> entry : gitDirs.entrySet()) { JSONObject repo = listEntry(entry.getKey().lastSegment(), 0, true, 0, baseLocation, entry.getKey().toPortableString()); children.put(repo); } } } JSONObject result = listEntry(workspace.getFullName(), 0, true, 0, baseLocation, workspace.getUniqueId()); //$NON-NLS-1$ result.put(ProtocolConstants.KEY_ID, workspace.getUniqueId()); result.put(ProtocolConstants.KEY_CHILDREN, children); OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred while obtaining workspace data.", e)); } return true; } return super.handleRequest(request, response, pathString); }
Example 6
Source File: UserHandlerV1.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private boolean handleUsersGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, JSONException, CoreException { List<String> users = getAllUsers(); String startParam = req.getParameter(START); String rowsParam = req.getParameter(ROWS); int start = 0, rows = 0, count = 0; if (startParam != null && !(startParam.length() == 0)) { start = Integer.parseInt(startParam); if (start < 0) { start = 0; } } else { start = 0; } if (rowsParam != null && !(rowsParam.length() == 0)) { rows = Integer.parseInt(rowsParam); if (rows < 0) { rows = 20; // default is to return 20 at a time } } else { // if there's no start and no rows then return the default first 20 users rows = 20; // default is to return 20 at a time } ArrayList<JSONObject> userJSONs = new ArrayList<JSONObject>(); URI location = ServletResourceHandler.getURI(req); for (String userId : users) { if (count >= start + rows) { break; } if (count++ < start) { continue; } URI userLocation = URIUtil.append(location, userId); UserInfo userInfo = OrionConfiguration.getMetaStore().readUser(userId); userJSONs.add(formJson(userInfo, userLocation, req.getContextPath())); } JSONObject json = new JSONObject(); json.put(USERS, userJSONs); json.put(USERS_START, start); json.put(USERS_ROWS, rows); json.put(USERS_LENGTH, users.size()); OrionServlet.writeJSONResponse(req, resp, json); return true; }
Example 7
Source File: WorkspaceResourceHandler.java From orion.server with Eclipse Public License 1.0 | 4 votes |
/** * Returns the location of the project's content (conforming to File REST API). */ static URI computeProjectURI(URI parentLocation, WorkspaceInfo workspace, ProjectInfo project) { return URIUtil.append(parentLocation, ".." + Activator.LOCATION_FILE_SERVLET + '/' + workspace.getUniqueId() + '/' + project.getFullName() + '/'); //$NON-NLS-1$ }