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);
}
}
}
}
}
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&p1=v1\" media=\"some&bad&media\" id=\"markupId\" />", response.toString());
}
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());
}
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&bad%id\" defer=\"defer\" charset=\"some&bad%%charset\" src=\"some/url;jsessionid=1234?p1=v1&p2=v2\"></script>\n", response.toString());
}
Aggregations