use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class LocalizedImageResource method onResourceRequested.
/**
* @param parameters
* page parameters
*/
public final void onResourceRequested(PageParameters parameters) {
bind();
RequestCycle requestCycle = RequestCycle.get();
Attributes attributes = new Attributes(requestCycle.getRequest(), requestCycle.getResponse(), parameters);
resource.respond(attributes);
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class FilteringHeaderResponse method get.
/**
* @return the FilteringHeaderResponse being used in this RequestCycle
*/
public static FilteringHeaderResponse get() {
RequestCycle requestCycle = RequestCycle.get();
if (requestCycle == null) {
throw new IllegalStateException("You can only get the FilteringHeaderResponse when there is a RequestCycle present");
}
FilteringHeaderResponse response = requestCycle.getMetaData(RESPONSE_KEY);
if (response == null) {
throw new IllegalStateException("No FilteringHeaderResponse is present in the request cycle. This may mean that you have not decorated the header response with a FilteringHeaderResponse. Simply calling the FilteringHeaderResponse constructor sets itself on the request cycle");
}
return response;
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class ServletWebResponseTest method encodeRedirectAbsoluteUrl.
/**
* WICKET-5582 absolute URLs stay absolute after encoding
*/
@Test
public void encodeRedirectAbsoluteUrl() {
final String url = "http://localhost:8080/path";
ServletWebRequest webRequest = mock(ServletWebRequest.class);
when(webRequest.isAjax()).thenReturn(Boolean.FALSE);
Url baseUrl = Url.parse("./baseUrl");
baseUrl.setProtocol("http");
baseUrl.setHost("someHost");
baseUrl.setPort(80);
when(webRequest.getClientUrl()).thenReturn(baseUrl);
UrlRenderer renderer = new UrlRenderer(webRequest);
RequestCycle requestCycle = mock(RequestCycle.class);
ThreadContext.setRequestCycle(requestCycle);
when(requestCycle.getUrlRenderer()).thenReturn(renderer);
HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
when(httpServletResponse.encodeRedirectURL(Matchers.eq(url))).thenReturn(url + ";foo");
ServletWebResponse webResponse = new ServletWebResponse(webRequest, httpServletResponse);
assertEquals(url + ";foo", webResponse.encodeRedirectURL(url));
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class AbstractMarkupFilter method getRequestUniqueId.
/**
* Returns an id using the request-relative counter associated with the
* underlying {@link org.apache.wicket.markup.MarkupResourceStream}'s owner container
* (see {@link org.apache.wicket.markup.MarkupResourceStream#getContainerInfo()}).
* This can be useful for autocomponent tags that need to get a tag id.
*
* @return
* the request-relative id
*/
protected int getRequestUniqueId() {
RequestCycle requestCycle = RequestCycle.get();
Map<String, AtomicInteger> markupUniqueCounters = requestCycle.getMetaData(REQUEST_COUNTER_KEY);
ContainerInfo containerInfo = getMarkupResourceStream().getContainerInfo();
String cacheKey = containerInfo != null ? containerInfo.getContainerClass().getCanonicalName() : null;
if (markupUniqueCounters == null) {
markupUniqueCounters = new HashMap<>();
requestCycle.setMetaData(REQUEST_COUNTER_KEY, markupUniqueCounters);
}
AtomicInteger counter = markupUniqueCounters.get(cacheKey);
if (counter == null) {
counter = new AtomicInteger();
markupUniqueCounters.put(cacheKey, counter);
}
int cacheHash = cacheKey == null ? 0 : cacheKey.hashCode();
// using the same algorithm of String#hashCode()
return cacheHash * 31 + counter.getAndIncrement();
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class ModalWindow method getWindowOpenJavaScript.
/**
* Returns the javascript used to open the window. Subclass
* {@link #postProcessSettings(AppendingStringBuffer)} to modify the JavaScript if needed.
*
* See WICKET-12
*
* @return javascript that opens the window
*/
protected final String getWindowOpenJavaScript() {
JSONObject settings = new JSONObject();
settings.put("minWidth", getMinimalWidth());
settings.put("minHeight", getMinimalHeight());
settings.put("className", getCssClassName());
settings.put("width", getInitialWidth());
if ((isUseInitialHeight() == true) || (isCustomComponent() == false)) {
settings.put("height", getInitialHeight());
} else {
settings.put("height", (Object) null);
}
settings.put("resizable", isResizable());
if (isResizable() == false) {
settings.put("widthUnit", getWidthUnit());
settings.put("heightUnit", getHeightUnit());
}
if (isCustomComponent() == false) {
Page page = createPage();
if (page == null) {
throw new WicketRuntimeException("Error creating page for modal dialog.");
}
CharSequence pageUrl;
RequestCycle requestCycle = RequestCycle.get();
page.getSession().getPageManager().touchPage(page);
if (page.isPageStateless()) {
pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
} else {
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
pageUrl = requestCycle.urlFor(handler);
}
settings.put("src", pageUrl);
} else {
settings.put("element", new JSONFunction("document.getElementById(\"" + getContentMarkupId() + "\")"));
}
if (getCookieName() != null) {
settings.put("cookieId", getCookieName());
}
String title = getTitle() != null ? getTitle().getObject() : null;
if (title != null) {
settings.put("title", getDefaultModelObjectAsString(title));
}
if (getMaskType() == MaskType.TRANSPARENT) {
settings.put("mask", "transparent");
} else if (getMaskType() == MaskType.SEMI_TRANSPARENT) {
settings.put("mask", "semi-transparent");
}
settings.put("autoSize", autoSize);
settings.put("unloadConfirmation", showUnloadConfirmation());
// set true if we set a windowclosedcallback
boolean haveCloseCallback = false;
// notification request
if (windowClosedCallback != null) {
WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
settings.put("onClose", new JSONFunction("function() { " + behavior.getCallbackScript() + " }"));
haveCloseCallback = true;
}
// close window property (thus cleaning the shown flag)
if ((closeButtonCallback != null) || (haveCloseCallback == false)) {
CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
settings.put("onCloseButton", new JSONFunction("function() { " + behavior.getCallbackScript() + "; return false; }"));
}
postProcessSettings(settings);
AppendingStringBuffer buffer = new AppendingStringBuffer(500);
buffer.append("var settings = ");
buffer.append(settings.toString());
buffer.append(";");
buffer.append(getShowJavaScript());
return buffer.toString();
}
Aggregations