int p = docName.lastIndexOf('/'); if (p < 0 || p == docName.length() - 1) throw new EXistException("Illegal document path"); String collectionName = docName.substring(0, p); docName = docName.substring(p + 1); Collection collection = broker.getCollection(collectionName); if (collection == null) { HttpServer.LOG.debug("creating collection " + collectionName); collection = broker.getOrCreateCollection(collectionName); broker.saveCollection(collection); } String uri = tempFile.toURI().toASCIIString(); DocumentImpl doc = collection.addDocument(broker, docName, new InputSource(uri)); result = formatErrorMsg("document " + docName + " stored.", OK); } catch (SAXParseException e) { result = formatErrorMsg("Parsing exception at " + e.getLineNumber() + ":" + e.getColumnNumber() + "\n" + e.toString(), PARSE_ERROR); errcode = HTTP_BAD_REQUEST; } catch (SAXException e) { Exception o = e.getException(); o.printStackTrace(); result = formatErrorMsg(o.toString(), PARSE_ERROR); errcode = HTTP_BAD_REQUEST; } catch (Exception e) { e.printStackTrace(); result = formatErrorMsg(e.toString(), PARSE_ERROR); errcode = HTTP_BAD_REQUEST;
response = doPut(broker, tempFile, contentType, docPath); } catch (BadRequestException e) { response = new Response(HTTP_BAD_REQUEST, e.getMessage()); } catch (PermissionDeniedException e) { response = new Response(HTTP_FORBIDDEN, e.getMessage());
	protected void put(File tempFile, String docName, int len) {		String result;		int errcode = HTTP_OK;		try {			int p = docName.lastIndexOf('/');			if (p < 0 || p == docName.length() - 1)				throw new EXistException("Illegal document path");			String collectionName = docName.substring(0, p);			docName = docName.substring(p + 1);			Collection collection = broker.getCollection(collectionName);			if (collection == null) {				HttpServer.LOG.debug("creating collection " + collectionName);				collection = broker.getOrCreateCollection(collectionName);				broker.saveCollection(collection);			}			String uri = tempFile.toURI().toASCIIString();			DocumentImpl doc = collection.addDocument(broker, docName,					new InputSource(uri));			result = formatErrorMsg("document " + docName + " stored.", OK);		} catch (SAXParseException e) {			result = formatErrorMsg("Parsing exception at " + e.getLineNumber()					+ ":" + e.getColumnNumber() + "\n" + e.toString(),					PARSE_ERROR);			errcode = HTTP_BAD_REQUEST;		} catch (SAXException e) {			Exception o = e.getException();			o.printStackTrace();			result = formatErrorMsg(o.toString(), PARSE_ERROR);			errcode = HTTP_BAD_REQUEST;		} catch (Exception e) {			e.printStackTrace();			result = formatErrorMsg(e.toString(), PARSE_ERROR);			errcode = HTTP_BAD_REQUEST;		}		try {			DataOutputStream out = new DataOutputStream(					new BufferedOutputStream(sock.getOutputStream()));			out.writeBytes("HTTP/1.0 " + errcode + " OK\n" + stdHeaders					+ "Content-Type: text/xml\n" + "Content-Length: "					+ result.length() + "\n\n");			byte[] resultData = result.getBytes("UTF8");			out.write(resultData, 0, resultData.length);			out.flush();			out.close();		} catch (IOException io) {			HttpServer.LOG.warn(io);		}	}