private boolean handleCopyMoveProject(HttpServletRequest request, HttpServletResponse response, WorkspaceInfo workspace, JSONObject data) throws ServletException, IOException {
//resolve the source location to a file system location
String sourceLocation = data.optString(ProtocolConstants.HEADER_LOCATION);
IFileStore source = null;
ProjectInfo sourceProject = null;
try {
if (sourceLocation != null) {
//could be either a workspace or file location
if (sourceLocation.startsWith(Activator.LOCATION_WORKSPACE_SERVLET)) {
sourceProject = projectForMetadataLocation(getMetaStore(), toOrionLocation(request, sourceLocation));
if (sourceProject != null)
source = sourceProject.getProjectStore();
} else {
//file location - remove servlet name prefix
source = resolveSourceLocation(request, sourceLocation);
}
}
} catch (Exception e) {
handleError(request, response, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Invalid source location: {0}", sourceLocation), e);
return true;
}
//null result means we didn't find a matching project
if (source == null) {
handleError(request, response, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Source does not exist: {0}", sourceLocation));
return true;
}
int options1 = getCreateOptions(request);
if (!validateOptions(request, response, options1))
return true;
//get the slug first
String destinationName = request.getHeader(ProtocolConstants.HEADER_SLUG);
//If the data has a name then it must be used due to UTF-8 issues with names Bug 376671
try {
if (data.has(ProtocolConstants.KEY_NAME)) {
destinationName = data.getString(ProtocolConstants.KEY_NAME);
}
} catch (JSONException e) {
//key is valid so cannot happen
}
if (!validateProjectName(workspace, destinationName, request, response))
return true;
if ((options1 & CREATE_MOVE) != 0) {
return handleMoveProject(request, response, workspace, source, sourceProject, sourceLocation, destinationName);
} else if ((options1 & CREATE_COPY) != 0) {
//first create the destination project
JSONObject projectObject = new JSONObject();
try {
projectObject.put(ProtocolConstants.KEY_NAME, destinationName);
} catch (JSONException e) {
//should never happen
throw new RuntimeException(e);
}
//copy the project data from source
ProjectInfo destinationProject = createProject(request, response, workspace, projectObject);
String sourceName = source.getName();
try {
source.copy(destinationProject.getProjectStore(), EFS.OVERWRITE, null);
} catch (CoreException e) {
handleError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, NLS.bind("Error copying project {0} to {1}", sourceName, destinationName));
return true;
}
URI baseLocation = getURI(request);