Collection collection = broker.getCollection(collectionName); if (collection == null) throw new EXistException("Collection " + collectionName + " not found"); if (!replace) { DocumentImpl old = collection.getDocument(broker, docName); if (old != null) throw new PermissionDeniedException( "Old document exists and overwrite is not allowed");
Collection collection = null; Indexer indexer; InputSource source; try { collection = broker.openCollection(collectionName, Lock.WRITE_LOCK); if (collection == null) throw new EXistException("Collection " + collectionName + " not found"); if (!replace) { DocumentImpl old = collection.getDocument(broker, docName); if (old != null) throw new PermissionDeniedException( "Old document exists and overwrite is not allowed"); } String uri; try { uri = new URI(file.toURL().toString()).toASCIIString(); } catch (Exception e) { uri = file.getAbsolutePath(); } source = new InputSource(uri); indexer = collection.validate(broker, docName, source); } finally { if(collection != null) collection.release();
	public boolean parseLocal(User user, String localFile, String docName,			boolean replace) throws EXistException, PermissionDeniedException, LockException,			SAXException, TriggerException {		File file = new File(localFile);		if (!file.canRead())			throw new EXistException("unable to read file " + localFile);		DBBroker broker = null;		DocumentImpl doc = null;		try {			broker = brokerPool.get(user);			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)				throw new EXistException("Collection " + collectionName						+ " not found");			if (!replace) {				DocumentImpl old = collection.getDocument(broker, docName);				if (old != null)					throw new PermissionDeniedException(							"Old document exists and overwrite is not allowed");			}			String uri;			try {				uri = new URI(file.toURL().toString()).toASCIIString();			} catch (Exception e) {				uri = file.getAbsolutePath();			}			collection.addDocument(broker, docName, new InputSource(uri));		} finally {			brokerPool.release(broker);		}		file.delete();		documentCache.clear();		return doc != null;	}