Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.jee.servlet;
 
Display and allow updating all current system configuration settings.
public class SettingServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	public SettingServlet(JeeBase jeethrows IOException {
		super(jee);
	}
	@SuppressWarnings("unchecked")
	public void doGet(String tokenUser uHttpServletRequest requestHttpServletResponse responsethrows ServletExceptionIOException {
		String error = null;
		// Set header value
		if(request.getParameter("name") != null && request.getParameter("value") != null) {
			if(request.getParameter("a") == null || !request.getParameter("a").equals(u.getFormAuthToken())) {
				throw new IllegalArgumentException("Invalid authentication token.");
			}
			.getAPI().upsertSetting(urequest.getParameter("name"), request.getParameter("value"));
			response.setHeader("Location".get("base.url""") + "/settings?s=added");
			response.setStatus(302);
			return;
		}
		// Clear header value
		if(request.getParameter("name") != null && request.getParameter("value") == null) {
			if(request.getParameter("a") == null || !request.getParameter("a").equals(u.getFormAuthToken())) {
				throw new IllegalArgumentException("Invalid authentication token.");
			}
			.getAPI().removeSetting(urequest.getParameter("name"));
			response.setHeader("Location".get("base.url""") + "/settings?s=removed");
			response.setStatus(302);
			return;
		}
		List<KeyValuesettings = .getAPI().getSettings(u);
		ST page = .getPage(u"settings");
		page.add("settings"settings);
		page.add("error"error);
		page.add("breadcrumbs"new Breadcrumb("Configuration settings"null));
		page.add("auth"u.getFormAuthToken());
		response.getWriter().write(page.render());
	}
New to GrepCode? Check out our FAQ X