if(collection != null) response = new Response(printCollection(broker, collection)); else {
if(collection != null) { if(!collection.getPermissions().validate(broker.getUser(), Permission.READ)) throw new PermissionDeniedException("Not allowed to read collection"); else response = new Response(printCollection(broker, collection)); } else {
	public Response doGet(DBBroker broker, Map parameters, String path) 	throws BadRequestException, PermissionDeniedException, NotFoundException {		int howmany = 10;		int start = 1;		boolean summary = false;		Properties outputProperties = new Properties();		String query = (String) parameters.get("_xpath");		if(query == null)			query = (String) parameters.get("_query");				String p_howmany = (String) parameters.get("_howmany");		if (p_howmany != null) {			try {				howmany = Integer.parseInt(p_howmany);			} catch (NumberFormatException nfe) {				throw new BadRequestException("Parameter _howmany should be an int");			}		}		String p_start = (String) parameters.get("_start");		if (p_start != null) {			try {				start = Integer.parseInt(p_start);			} catch (NumberFormatException nfe) {				throw new BadRequestException("Parameter _start should be an int");			}		}		String option;		if ((option = (String) parameters.get("_summarize")) != null)			summary = option.equals("yes");		if ((option = (String) parameters.get("_indent")) != null)			outputProperties.setProperty(OutputKeys.INDENT, option);		String stylesheet;		if((stylesheet = (String) parameters.get("_xsl"))!= null) {			if(stylesheet.equals("no"))				outputProperties.setProperty(EXistOutputKeys.PROCESS_XSL_PI, stylesheet);			else				outputProperties.setProperty(EXistOutputKeys.STYLESHEET, stylesheet);		} else            outputProperties.setProperty(EXistOutputKeys.PROCESS_XSL_PI, "yes");		String encoding;		if((encoding = (String) parameters.get("_encoding")) !=null)			outputProperties.setProperty(OutputKeys.ENCODING, encoding);		else			encoding = "UTF-8";		Response response = new Response();			if (query != null) {				response.setContent(search(broker, query, path, howmany, start, outputProperties));			} else {				DocumentImpl d = (DocumentImpl) broker.getDocument(path);				if (d == null) {					Collection collection = broker.getCollection(path);					if(collection != null)						response = new Response(printCollection(broker, collection));					else {						throw new NotFoundException("Document " + path + " not found");					}				} else {					if(d.getResourceType() == DocumentImpl.BINARY_FILE) {						response.setContent(broker.getBinaryResourceData((BinaryDocument)d));					} else {						Serializer serializer = broker.getSerializer();						serializer.reset();												if (stylesheet != null) {							serializer.setStylesheet(d, stylesheet);							response.setContentType("text/html");						}						try {							serializer.setProperties(outputProperties);							response.setContent(serializer.serialize(d));							if(serializer.isStylesheetApplied())								response.setContentType("text/html");						} catch (SAXException saxe) {							LOG.warn(saxe);							throw new BadRequestException("Error while serializing XML: " + saxe.getMessage());						}					}				}			}			return response;	}