String url; try { url = new URI(tempFile.toURL().toString()).toASCIIString(); } catch (URISyntaxException e1) { url = tempFile.toString(); }
String url = tempFile.toURI().toASCIIString();
	public void process(User user, HttpServletRequest request,			HttpServletResponse response, String path) throws ServletException, IOException {		File tempFile = saveRequestContent(request);		String url;		try {			url = new URI(tempFile.toURL().toString()).toASCIIString();		} catch (URISyntaxException e1) {			url = tempFile.toString();		}		String contentType = request.getContentType();		DBBroker broker = null;		Collection collection = null;		boolean collectionLocked = true;		try {			broker = pool.get(user);			if(path == null)				path = "";			if(path.endsWith("/"))				path = path.substring(0, path.length() - 1);			int p = path.lastIndexOf('/');			if(p < 1) {				response.sendError(HttpServletResponse.SC_CONFLICT, "No collection specified for PUT");				return;			}			String collectionName = path.substring(0, p);			path = path.substring(p + 1);						collection = broker.openCollection(collectionName, Lock.WRITE_LOCK);			if(collection == null) {				response.sendError(HttpServletResponse.SC_CONFLICT, "Parent collection " + collectionName +				" not found");				return;			}			if(collection.hasChildCollection(path)) {				response.sendError(HttpServletResponse.SC_CONFLICT, "Cannot overwrite an existing collection with a resource");				return;			}			if(contentType == null) {				contentType = URLConnection.guessContentTypeFromName(path);			}			LOG.debug("storing document " + path + "; content-type = " + contentType);			if(contentType == null || contentType.equalsIgnoreCase("text/xml") ||					contentType.equals("application/xml")) {				InputSource is = new InputSource(url);				IndexInfo info = collection.validate(broker, path, is);				collection.release();				collectionLocked = false;				collection.store(broker, info, is, false);			} else {				byte[] chunk = new byte[4096];				ByteArrayOutputStream os = new ByteArrayOutputStream();				FileInputStream is = new FileInputStream(tempFile);				int l;				while((l = is.read(chunk)) > -1) {					os.write(chunk, 0, l);				}				collection.addBinaryResource(broker, path, os.toByteArray());			}		} catch (EXistException e) {			throw new ServletException("Failed to store resource: " + e.getMessage(), e);		} catch (PermissionDeniedException e) {			response.sendError(HttpServletResponse.SC_FORBIDDEN);		} catch (TriggerException e) {			response.sendError(HttpServletResponse.SC_FORBIDDEN);		} catch (SAXException e) {			response.sendError(HttpServletResponse.SC_BAD_REQUEST);		} catch (LockException e) {			response.sendError(HttpServletResponse.SC_CONFLICT);		} finally {			if(collectionLocked)				collection.release();			pool.release(broker);		}		response.setStatus(HttpServletResponse.SC_CREATED);	}