* @param exchange
* @throws java.io.IOException
* @throws org.dbwiki.exception.WikiException
*/
protected void respondTo(Exchange<?> exchange) throws java.io.IOException, org.dbwiki.exception.WikiException {
ServerResponseHandler responseHandler = null;
HttpRequest request = new HttpRequest(new RequestURL(exchange,""), users());
if (request.type().isIndex()) {
responseHandler = this.getHomepageResponseHandler(request);
} else if (request.type().isCreate()) {
responseHandler = new ServerResponseHandler(request, _wikiTitle + " - Create Database Wiki");
responseHandler.put(HtmlContentGenerator.ContentContent, new DatabaseWikiFormPrinter("Create Database Wiki"));
} else if (request.type().isEdit()) {
DatabaseWiki wiki = this.getRequestWiki(request, RequestParameter.ParameterEdit);
responseHandler = new ServerResponseHandler(request, _wikiTitle + " - Edit Database Wiki");
responseHandler.put(HtmlContentGenerator.ContentContent, new DatabaseWikiFormPrinter(wiki.getProperties(), RequestParameterAction.ActionUpdate, "Edit Database Wiki"));
} else if (request.type().isReset()) {
this.resetWikiConfiguration(this.getRequestWiki(request, RequestParameter.ParameterReset));
responseHandler = this.getHomepageResponseHandler(request);
} else if (request.type().isAction()) {
RequestParameterAction action = RequestParameter.actionParameter(request.parameters().get(RequestParameter.ParameterAction));
if (action.actionInsert()) {
responseHandler = this.getInsertWikiResponseHandler(request);
} else if (action.actionCancel()) {
responseHandler = this.getHomepageResponseHandler(request);
} else if (action.actionUpdate()) {
responseHandler = this.getUpdateWikiResponseHandler(request);
} else {
throw new WikiRequestException(WikiRequestException.InvalidRequest, request.toString());
}
} else {
throw new WikiRequestException(WikiRequestException.InvalidRequest, request.toString());
}
File template = null;
//
// TODO: Improve handling of individual home pages.
//
// This part is still a bit tricky. In order to identify whether the response handler results from
// a call to getHomepageResponseHandler() we rely on the fact that only getHomepageResponseHandler()
// adds content handler for Menu and Content.
//
if (responseHandler.contains(HtmlContentGenerator.ContentMenu) && responseHandler.contains(HtmlContentGenerator.ContentContent)) {
template = _homepageTemplate;
} else {
template = _formTemplate;
}