Search in sources :

Example 11 with StringResponse

use of org.apache.wicket.response.StringResponse in project wicket by apache.

the class Component method internalRenderHead.

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!
 *
 * Print to the web response what ever the component wants to contribute to the head section.
 * Make sure that all attached behaviors are asked as well.
 * <p>
 * NOT intended for overriding by framework clients. Rather, use
 * {@link Component#renderHead(org.apache.wicket.markup.head.IHeaderResponse)}
 * </p>
 *
 * @param container
 *            The HtmlHeaderContainer
 */
public void internalRenderHead(final HtmlHeaderContainer container) {
    if (isVisibleInHierarchy() && isRenderAllowed()) {
        if (log.isDebugEnabled()) {
            log.debug("internalRenderHead: {}", toString(false));
        }
        IHeaderResponse response = container.getHeaderResponse();
        // Allow component to contribute
        if (response.wasRendered(this) == false) {
            StringResponse markupHeaderResponse = new StringResponse();
            Response oldResponse = getResponse();
            RequestCycle.get().setResponse(markupHeaderResponse);
            try {
                // Make sure the markup source strategy contributes to the header first
                // to be backward compatible. WICKET-3761
                getMarkupSourcingStrategy().renderHead(this, container);
                CharSequence headerContribution = markupHeaderResponse.getBuffer();
                if (Strings.isEmpty(headerContribution) == false) {
                    response.render(StringHeaderItem.forString(headerContribution));
                }
            } finally {
                RequestCycle.get().setResponse(oldResponse);
            }
            // Then let the component itself to contribute to the header
            renderHead(response);
            response.markRendered(this);
        }
        // Then ask all behaviors
        for (Behavior behavior : getBehaviors()) {
            if (isBehaviorAccepted(behavior)) {
                if (response.wasRendered(behavior) == false) {
                    behavior.renderHead(this, response);
                    List<IClusterable> pair = Arrays.asList(this, behavior);
                    response.markRendered(pair);
                }
            }
        }
    }
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) IClusterable(org.apache.wicket.util.io.IClusterable) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Behavior(org.apache.wicket.behavior.Behavior)

Example 12 with StringResponse

use of org.apache.wicket.response.StringResponse in project wicket by apache.

the class CssUtilsTest method writeLinkUrl.

/**
 * https://issues.apache.org/jira/browse/WICKET-4546
 *
 * @throws Exception
 */
@Test
public void writeLinkUrl() throws Exception {
    StringResponse response = new StringResponse();
    String url = "some/url;jsessionid=1234?with=parameters&p1=v1";
    String media = "some&bad&media";
    CssUtils.writeLinkUrl(response, url, media, "markupId");
    assertEquals("<link rel=\"stylesheet\" type=\"text/css\" href=\"some/url;jsessionid=1234?with=parameters&amp;p1=v1\" media=\"some&amp;bad&amp;media\" id=\"markupId\" />", response.toString());
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Test(org.junit.Test)

Example 13 with StringResponse

use of org.apache.wicket.response.StringResponse in project wicket by apache.

the class JavaScriptUtilsTest method writeJavaScript.

/**
 */
@Test
public void writeJavaScript() {
    StringResponse response = new StringResponse();
    JavaScriptUtils.writeJavaScript(response, "var message = 'Scripts are written to the <script></script> tag'");
    assertEquals(// 
    "<script type=\"text/javascript\" >\n" + // 
    "/*<![CDATA[*/\n" + // 
    "var message = 'Scripts are written to the <script><\\/script> tag'\n" + // 
    "/*]]>*/\n" + "</script>\n", response.toString());
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Test(org.junit.Test)

Example 14 with StringResponse

use of org.apache.wicket.response.StringResponse in project wicket by apache.

the class JavaScriptUtilsTest method writeJavaScriptUrl.

/**
 * https://issues.apache.org/jira/browse/WICKET-4546
 *
 * @throws Exception
 */
@Test
public void writeJavaScriptUrl() throws Exception {
    StringResponse response = new StringResponse();
    String url = "some/url;jsessionid=1234?p1=v1&p2=v2";
    String id = "some&bad%id";
    boolean defer = true;
    String charset = "some&bad%%charset";
    JavaScriptUtils.writeJavaScriptUrl(response, url, id, defer, charset);
    assertEquals("<script type=\"text/javascript\" id=\"some&amp;bad%id\" defer=\"defer\" charset=\"some&amp;bad%%charset\" src=\"some/url;jsessionid=1234?p1=v1&p2=v2\"></script>\n", response.toString());
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Test(org.junit.Test)

Aggregations

StringResponse (org.apache.wicket.response.StringResponse)14 Response (org.apache.wicket.request.Response)8 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)7 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)5 Test (org.junit.Test)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Request (org.apache.wicket.request.Request)2 WebResponse (org.apache.wicket.request.http.WebResponse)2 Before (org.junit.Before)2 Application (org.apache.wicket.Application)1 Component (org.apache.wicket.Component)1 Behavior (org.apache.wicket.behavior.Behavior)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 HeaderItem (org.apache.wicket.markup.head.HeaderItem)1 PageHeaderItem (org.apache.wicket.markup.head.PageHeaderItem)1 DecoratingHeaderResponse (org.apache.wicket.markup.html.DecoratingHeaderResponse)1 HtmlHeaderContainer (org.apache.wicket.markup.html.internal.HtmlHeaderContainer)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1