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 ResourceServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	public ResourceServlet(JeeBase jeethrows IOException {
		super(jee);
	}
	public void doGet(String tokenUser uHttpServletRequest requestHttpServletResponse responsethrows ServletExceptionIOException {
			throw new IllegalStateException("You do not have permission to manage templates.");
		}
		Template template = .getTemplateManager().getTemplate(request.getParameter("template"));
		Resource resource = template.getResource(request.getParameter("name"));
		String error = null;
		String info = null;
		// Set header value
		if(request.getParameter("name") != null && request.getParameter("content") != null) {
			if(request.getParameter("a") == null || !request.getParameter("a").equals(u.getFormAuthToken())) {
				throw new IllegalArgumentException("Invalid authentication token.");
			}
			.getAPI().upsertTemplateResource(utemplate.getName(), resource.getName(), request.getParameter("content").getBytes("UTF-8"), false);
			template.defineResource(resource.getName(), (request.getParameter("content")).getBytes("UTF-8"), resource.isBinary());
			response.setHeader("Location".get("base.url""") + "/resource?template=" + StringHelper.urlEscape(template.getName()) + "&name=" + StringHelper.urlEscape(resource.getName()) + "&saved=");
			response.setStatus(302);
			return;
		}
		if(request.getParameter("saved") != null) {
			info = "<p>Saved changes to this resource.</p>";
		}
		ST page = .getPage(u"resource");
		page.add("t"template);
		page.add("info"info);
		page.add("content"new String(resource.getData(), "UTF-8"));
		page.add("template"template.getName());
		page.add("name"resource.getName());
		page.add("error"error);
		page.add("breadcrumbs"new Breadcrumb("Templates""/templates"));
		page.add("breadcrumbs"new Breadcrumb(template.getName(), "/template?name=" + StringHelper.urlEscape(template.getName())));
		page.add("breadcrumbs"new Breadcrumb(resource.getName(), null));
		page.add("auth"u.getFormAuthToken());
		response.getWriter().write(page.render());
	}
New to GrepCode? Check out our FAQ X