if(tempFile == null) throw new BadRequestException("No request content found for PUT");
	public Response doPut(DBBroker broker, File tempFile, String contentType, String docPath) 	throws BadRequestException, PermissionDeniedException {		Response response;		try {			int p = docPath.lastIndexOf('/');			if (p < 0 || p == docPath.length() - 1)				throw new BadRequestException("Bad path: " + docPath);			else {				String collectionName = docPath.substring(0, p);				docPath = docPath.substring(p + 1);				Collection collection = broker.getCollection(collectionName);				if (collection == null) {					LOG.debug("creating collection " + collectionName);					collection = broker.getOrCreateCollection(collectionName);					broker.saveCollection(collection);				}				String url = tempFile.toURI().toASCIIString();				if(contentType == null || contentType.equalsIgnoreCase("text/xml")) {					DocumentImpl doc = collection.addDocument(broker, docPath,							new InputSource(url));					response = new Response();					response.setDescription("Document " + docPath + " stored.");				} 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, docPath, os.toByteArray());					response = new Response();					response.setDescription("Document " + docPath + " stored as binary resource.");				}			}		} catch (SAXParseException e) {			throw new BadRequestException( 					"Parsing exception at " + e.getLineNumber()					+ "/" + e.getColumnNumber() + ": " + e.toString());		} catch (SAXException e) {			Exception o = e.getException();			if(o == null)				o = e;			throw new BadRequestException(					"Parsing exception: " + o.getMessage());		} catch (EXistException e) {			throw new BadRequestException("Internal error: " + e.getMessage());		} catch (IOException e) {			throw new BadRequestException("Internal error: " + e.getMessage());		} catch (TriggerException e) {			throw new PermissionDeniedException(e.getMessage());		} catch (LockException e) {			throw new PermissionDeniedException(e.getMessage());		}		return response;	}