package com.piki.server;
import info.bliki.wiki.model.WikiModel;
import com.piki.client.rpc.FormatService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class FormatServiceImpl extends RemoteServiceServlet implements
FormatService {
private ThreadLocal<WikiModel> wikiModel = null;
public String format(String titleBaseUrl, String input)
throws IllegalArgumentException {
if (input == null)
throw new IllegalArgumentException("missing argument inpit");
WikiModel wikiModel = getWikiModel(titleBaseUrl);
try {
wikiModel.setUp();
return wikiModel.render(input);
} finally {
wikiModel.tearDown();
}
}
private synchronized WikiModel getWikiModel(String titleBaseUrl) {
if (wikiModel == null)
wikiModel = new ThreadLocal<WikiModel>();
WikiModel wm = wikiModel.get();
if (wm == null) {
wm = new MyWikiModel(titleBaseUrl + "image/${image}", titleBaseUrl
+ "#wiki:${title}");
wikiModel.set(wm);
}
return wm;
}
}