public HeaderBufferingWebResponse(WebResponse originalResponse) { this.originalResponse = originalResponse; bufferedResponse = new BufferedWebResponse(originalResponse); }
/** * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. */ public final void filter() { if (redirectURL == null && buffer.length() != 0) { this.buffer = filter(buffer); } }
@Override public void reset() { if (buffering) { // still buffering so just reset the buffer of meta data bufferedResponse.reset(); } else { // the original response is never reset (see class javadoc) throw new IllegalStateException("Response is no longer buffering!"); } }
/** * Collects the html generated by rendering a page. * * @param page * supplier of the page * @return the html rendered by the panel */ public CharSequence renderPage(final Supplier<? extends Page> page) { return inThreadContext(() -> { Request request = newRequest(); BufferedWebResponse response = new BufferedWebResponse(null); RequestCycle cycle = application.createRequestCycle(request, response); ThreadContext.setRequestCycle(cycle); page.get().renderPage(); return response.getText(); }); }
BufferedWebResponse response = new BufferedWebResponse(originalResponse); response.writeMetaData(originalResponse); return null;
@Override public void afterRender(final Component component) { final RequestCycle requestCycle = RequestCycle.get(); try { BufferedWebResponse tempResponse = (BufferedWebResponse)requestCycle.getResponse(); if (component instanceof Page && originalResponse instanceof WebResponse) { tempResponse.writeMetaData((WebResponse) originalResponse); } // Transform the data CharSequence output = transform(component, tempResponse.getText()); originalResponse.write(output); } catch (Exception ex) { throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex); } finally { // Restore the original response object requestCycle.setResponse(originalResponse); } }
/** * Saves url to redirect to when buffered response is flushed. Implementations should encode the * URL to make sure cookie-less operation is supported in case clients forgot. * * @param url * The URL to redirect to */ public final void redirect(final String url) { if (redirectURL != null) { throw new WicketRuntimeException("Already redirecting to '" + redirectURL + "'. Cannot redirect more than once"); } // encode to make sure no caller forgot this this.redirectURL = encodeURL(url).toString(); }
/** * Parse the grid component to a {@link Sheet} object * * @param workbook * @throws IOException * @throws ResourceStreamNotFoundException * @throws ParseException */ public void parse(Component tableComponent) throws IOException, ResourceStreamNotFoundException, ParseException { try { BufferedWebResponse mockResponse = doRequest(tableComponent); doParse(mockResponse.getText(), tableComponent); } finally { afterParse(tableComponent); } }
@Override public void write(byte[] array) { write(array, 0, array.length); }
@Override public void writeMetaData(WebResponse webResponse) { bufferedResponse.writeMetaData(webResponse); }
/** * Collects the html generated by rendering a page. * * @param page * supplier of the page * @return the html rendered by the panel */ public CharSequence renderPage(final Supplier<? extends Page> page) { return inThreadContext(() -> { Request request = newRequest(); BufferedWebResponse response = new BufferedWebResponse(null); RequestCycle cycle = application.createRequestCycle(request, response); ThreadContext.setRequestCycle(cycle); page.get().renderPage(); return response.getText(); }); }
BufferedWebResponse response = new BufferedWebResponse(originalResponse); response.writeMetaData(originalResponse); return null;
@Override public void afterRender(final Component component) { final RequestCycle requestCycle = RequestCycle.get(); try { BufferedWebResponse tempResponse = (BufferedWebResponse)requestCycle.getResponse(); if (component instanceof Page && originalResponse instanceof WebResponse) { tempResponse.writeMetaData((WebResponse) originalResponse); } // Transform the data CharSequence output = transform(component, tempResponse.getText()); originalResponse.write(output); } catch (Exception ex) { throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex); } finally { // Restore the original response object requestCycle.setResponse(originalResponse); } }
/** * Saves url to redirect to when buffered response is flushed. Implementations should encode the * URL to make sure cookie-less operation is supported in case clients forgot. * * @param url * The URL to redirect to */ @Override public final void redirect(final String url) { if (redirectURL != null) { throw new WicketRuntimeException("Already redirecting to '" + redirectURL + "'. Cannot redirect more than once"); } // encode to make sure no caller forgot this redirectURL = encodeURL(url).toString(); }
/** * Replaces the text in this response * * @param text */ public void setText(CharSequence text) { if (dataAction != null) { throw new IllegalStateException("write(byte[]) has already been called."); } if (charSequenceAction != null) { charSequenceAction.builder.setLength(0); } write(text); }
@Override public void writeMetaData(WebResponse webResponse) { bufferedResponse.writeMetaData(webResponse); }
/** * Collects the Html generated by the rendering a page. * <p> * Important note: Must be called on a thread bound to an application's {@link ThreadContext}! * * @param pageProvider * the provider of the page class/instance and its parameters * @return the html rendered by a page * * @see ThreadContext */ public static CharSequence renderPage(final PageProvider pageProvider) { Application application = Application.get(); RequestCycle originalRequestCycle = RequestCycle.get(); BufferedWebResponse tempResponse = new BufferedWebResponse(null); RequestCycle tempRequestCycle = application .createRequestCycle(originalRequestCycle.getRequest(), tempResponse); try { ThreadContext.setRequestCycle(tempRequestCycle); pageProvider.getPageInstance().renderPage(); } finally { ThreadContext.setRequestCycle(originalRequestCycle); } return tempResponse.getText(); }
public HeaderBufferingWebResponse(WebResponse originalResponse) { this.originalResponse = originalResponse; bufferedResponse = new BufferedWebResponse(originalResponse); }
/** * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. */ public final void filter() { if (redirectURL == null && buffer.length() != 0) { buffer = filter(buffer); } }
/** * Replaces the text in this response * * @param text */ public void setText(CharSequence text) { if (dataStream != null) { throw new IllegalStateException("write(byte[]) has already been called."); } if (charSequenceBuilder != null) { charSequenceBuilder.setLength(0); } write(text); }