parent.getCollection().releaseDocument(document); brokerPool.release(broker);
closeDocument(document, Lock.READ_LOCK); pool.release(broker);
	public Object getContent() throws XMLDBException {		if (content != null)			return content;		// Case 1: content is an external DOM node		else if (root != null && !(root instanceof NodeValue)) {			DOMSerializer serializer = DOMSerializerPool.getInstance()					.borrowDOMSerializer();			try {				StringWriter writer = new StringWriter();				serializer.setOutputProperties(getProperties());				serializer.setWriter(writer);				serializer.serialize(root);				content = writer.toString();			} catch (TransformerException e) {				throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e						.getMessage(), e);			} finally {				DOMSerializerPool.getInstance().returnDOMSerializer(serializer);			}			return content;			// Case 2: content is an atomic value		} else if (value != null) {			try {				return value.getStringValue();			} catch (XPathException e) {				throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e						.getMessage(), e);			}			// Case 3: content is a file		} else if (file != null) {			try {				content = XMLUtil.readFile(file);				return content;			} catch (IOException e) {				throw new XMLDBException(ErrorCodes.VENDOR_ERROR,						"error while reading resource contents", e);			}			// Case 4: content is a document or internal node		} else {		    DocumentImpl document = null;			DBBroker broker = null;			try {				broker = brokerPool.get(user);				Serializer serializer = broker.getSerializer();				serializer.setUser(user);				serializer.setProperties(getProperties());				if (root != null)					content = serializer.serialize((NodeValue) root);				else {				    document = getDocument(broker, true);					if (!document.getPermissions().validate(user,							Permission.READ))						throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,								"permission denied to read resource");					if (id < 0)						content = serializer.serialize(document);					else {						if (proxy == null)							proxy = new NodeProxy(document, id);						content = serializer.serialize(proxy);					}				}				return content;			} catch (SAXException saxe) {				saxe.printStackTrace();				throw new XMLDBException(ErrorCodes.VENDOR_ERROR, saxe						.getMessage(), saxe);			} catch (EXistException e) {				throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e						.getMessage(), e);			} catch (Exception e) {				e.printStackTrace();				throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e						.getMessage(), e);			} finally {			    parent.getCollection().releaseDocument(document);				brokerPool.release(broker);			}		}	}