if(!collection.getPermissions().validate(user, Permission.READ)) throw new PermissionDeniedException("Insufficient privileges to read resource");
if(!collection.getPermissions().validate(user, Permission.READ)) { collection.release(); throw new PermissionDeniedException("Insufficient privileges to read resource"); }
	public String getDocument(User user, String name, Hashtable parametri)			throws Exception {		long start = System.currentTimeMillis();		DBBroker broker = null;		String stylesheet = null;		String encoding = "UTF-8";		String processXSL = "yes";		Hashtable styleparam = null;		Collection collection = null;		DocumentImpl doc = null;		try {			broker = brokerPool.get(user);			Configuration config = broker.getConfiguration();			String option = (String) config					.getProperty("serialization.enable-xinclude");			String prettyPrint = (String) config					.getProperty("serialization.indent");			int pos = name.lastIndexOf('/');			String collName = name.substring(0, pos);			String docName = name.substring(pos + 1);						collection = broker.getCollection(collName);			if (collection == null) {				LOG.debug("collection " + collName + " not found!");				return null;			}			if(!collection.getPermissions().validate(user, Permission.READ))			    throw new PermissionDeniedException("Insufficient privileges to read resource");			doc = collection.getDocumentWithLock(broker, docName);			if (doc == null) {				LOG.debug("document " + name + " not found!");				throw new EXistException("document not found");			}			if(!doc.getPermissions().validate(user, Permission.READ))			    throw new PermissionDeniedException("Insufficient privileges to read resource " + docName);			Serializer serializer = broker.getSerializer();			if (parametri != null) {				for (Enumeration en = parametri.keys(); en.hasMoreElements(); ) {					String param = (String) en.nextElement();					String paramvalue = parametri.get(param).toString();					//LOG.debug("-------Parametri passati:"+param+":					// "+paramvalue);					if (param.equals(EXistOutputKeys.EXPAND_XINCLUDES)) {						option = (paramvalue.equals("yes")) ? "true" : "false";					}					if (param.equals(OutputKeys.INDENT)) {						prettyPrint = paramvalue;					}					if (param.equals(OutputKeys.ENCODING)) {						encoding = paramvalue;					}					if (param.equals(EXistOutputKeys.STYLESHEET)) {						stylesheet = paramvalue;					}					if (param.equals(EXistOutputKeys.STYLESHEET_PARAM)) {						styleparam = (Hashtable) parametri.get(param);					}					if (param.equals(OutputKeys.DOCTYPE_SYSTEM)) {						serializer.setProperty(OutputKeys.DOCTYPE_SYSTEM,								paramvalue);					}					if(param.equals(EXistOutputKeys.PROCESS_XSL_PI)) {						serializer.setProperty(EXistOutputKeys.PROCESS_XSL_PI, paramvalue);					}				}			}			if (option.equals("true")) {				serializer.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes");			} else {				serializer.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, "no");			}			serializer.setProperty(OutputKeys.ENCODING, encoding);			serializer.setProperty(OutputKeys.INDENT, prettyPrint);			if (stylesheet != null) {				if (stylesheet.indexOf(":") < 0) {					if (!stylesheet.startsWith("/")) {						// make path relative to current collection						stylesheet = collection.getName() + '/' + stylesheet;					}				}				serializer.setStylesheet(stylesheet);				// set stylesheet param if present				if (styleparam != null) {					for (Enumeration en1 = styleparam.keys(); en1							.hasMoreElements(); ) {						String param1 = (String) en1.nextElement();						String paramvalue1 = styleparam.get(param1).toString();						// System.out.println("-->"+param1+"--"+paramvalue1);						serializer								.setStylesheetParamameter(param1, paramvalue1);					}				}			}			String xml = serializer.serialize(doc);			return xml;		} catch (NoSuchMethodError nsme) {			nsme.printStackTrace();			return null;		} finally {		    if(collection != null)		        collection.releaseDocument(doc);			brokerPool.release(broker);		}	}