/** * Includes another view. */ public void include(Object it, String view) throws IOException, JellyException { _include(it,request.getWebApp().getKlass(it),view); }
protected JellyContext createContext(final StaplerRequest req, StaplerResponse rsp, Script script, Object it) { CustomJellyContext context = new CustomJellyContext(); // let Jelly see the whole classes context.setClassLoader(req.getWebApp().getClassLoader()); // so TagScript.getBodyText() will use HTMLWriterOutput context.setVariable(XMLOutputFactory.class.getName(), this); return context; }
protected JellyContext createContext(final StaplerRequest req, StaplerResponse rsp, Script script, Object it) { CustomJellyContext context = new CustomJellyContext(); // let Jelly see the whole classes context.setClassLoader(req.getWebApp().getClassLoader()); // so TagScript.getBodyText() will use HTMLWriterOutput context.setVariable(XMLOutputFactory.class.getName(), this); return context; }
private void _include(Object it, Klass clazz, String view) throws IOException, JellyException { JellyClassTearOff t = request.getWebApp().getMetaClass(clazz).loadTearOff(JellyClassTearOff.class); Script s = t.findScript(view); if(s==null) throw new IllegalArgumentException("No such view: "+view+" for "+clazz); JellyContext context = new JellyContext(getContext()); if(it!=null) context.setVariable("it",it); context.setVariable("from", it); ClassLoader old = Thread.currentThread().getContextClassLoader(); if (clazz.clazz instanceof Class) Thread.currentThread().setContextClassLoader(((Class)clazz.clazz).getClassLoader()); try { s.run(context,output); } finally { Thread.currentThread().setContextClassLoader(old); } }
@Override public Object invoke(StaplerRequest request, StaplerResponse response, Object instance, Object[] arguments) throws IllegalAccessException, InvocationTargetException, ServletException { if (!request.getMethod().equals("POST")) { for (ErrorCustomizer handler : ServiceLoader.load(ErrorCustomizer.class, request.getWebApp().getClassLoader())) { ForwardToView forwardToView = handler.getForwardView(); if (forwardToView != null) { throw new InvocationTargetException(forwardToView.with("requestURL", request.getRequestURLWithQueryString().toString())); } } throw new InvocationTargetException(new HttpResponses.HttpResponseException() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); rsp.addHeader("Allow", "POST"); rsp.setContentType("text/html"); PrintWriter w = rsp.getWriter(); w.println("<html><head><title>POST required</title></head><body>"); w.println("POST is required for " + target.getQualifiedName() + "<br>"); w.println("<form method='POST'><input type='submit' value='Try POSTing'></form>"); w.println("</body></html>"); } }); } return target.invoke(request, response, instance, arguments); } }
@Override public Object invoke(StaplerRequest request, StaplerResponse response, Object instance, Object[] arguments) throws IllegalAccessException, InvocationTargetException, ServletException { if (!request.getMethod().equals("POST")) { for (ErrorCustomizer handler : ServiceLoader.load(ErrorCustomizer.class, request.getWebApp().getClassLoader())) { ForwardToView forwardToView = handler.getForwardView(); if (forwardToView != null) { throw new InvocationTargetException(forwardToView.with("requestURL", request.getRequestURLWithQueryString().toString())); } } throw new InvocationTargetException(new HttpResponses.HttpResponseException() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); rsp.addHeader("Allow", "POST"); rsp.setContentType("text/html"); PrintWriter w = rsp.getWriter(); w.println("<html><head><title>POST required</title></head><body>"); w.println("POST is required for " + target.getQualifiedName() + "<br>"); w.println("<form method='POST'><input type='submit' value='Try POSTing'></form>"); w.println("</body></html>"); } }); } return target.invoke(request, response, instance, arguments); } }
public void doIndex(StaplerRequest req,StaplerResponse rsp) throws IOException { rsp.setContentType("text/html"); String crumb = req.getWebApp().getCrumbIssuer().issueCrumb(); PrintWriter w = rsp.getWriter(); w.println("<html><body><script src='prototype'></script><script src='script'></script>"); w.println("<script>var v = makeStaplerProxy('/','"+crumb+"',['foo','bar']);var callback = function(t){var x=t.responseObject();alert(typeof(x)+':'+x)};</script>"); w.println("</body></html>"); }