Search in sources :

Example 21 with HeaderItem

use of org.apache.wicket.markup.head.HeaderItem in project wicket by apache.

the class DecoratingHeaderResponseTest method decoratedStringPrepend.

/**
 * Basic IHeaderResponseDecorator, just prepending the DECORATED string to resource name.
 *
 * @throws IOException
 * @throws ResourceStreamNotFoundException
 * @throws ParseException
 */
@Test
public void decoratedStringPrepend() throws IOException, ResourceStreamNotFoundException, ParseException {
    tester.getApplication().setHeaderResponseDecorator(new IHeaderResponseDecorator() {

        @Override
        public IHeaderResponse decorate(IHeaderResponse response) {
            return new ResourceAggregator(new DecoratingHeaderResponse(response) {

                @Override
                public void render(HeaderItem item) {
                    if (item instanceof JavaScriptReferenceHeaderItem) {
                        JavaScriptReferenceHeaderItem original = (JavaScriptReferenceHeaderItem) item;
                        item = JavaScriptHeaderItem.forReference(new PackageResourceReference("DECORATED-" + original.getReference().getName()), original.getId());
                    }
                    super.render(item);
                }
            });
        }
    });
    tester.startPage(TestPage.class);
    XmlPullParser parser = new XmlPullParser();
    parser.parse(tester.getLastResponseAsString());
    XmlTag tag = parser.nextTag();
    boolean isDecorated = false;
    do {
        if (tag.isOpen() && "script".equals(tag.getName())) {
            isDecorated = tag.getAttribute("src").toString().contains("DECORATED");
            if (!isDecorated) {
                fail();
            }
            break;
        }
    } while ((tag = parser.nextTag()) != null);
    assertTrue(isDecorated);
}
Also used : JavaScriptReferenceHeaderItem(org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) XmlPullParser(org.apache.wicket.markup.parser.XmlPullParser) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) ResourceAggregator(org.apache.wicket.markup.head.ResourceAggregator) HeaderItem(org.apache.wicket.markup.head.HeaderItem) JavaScriptHeaderItem(org.apache.wicket.markup.head.JavaScriptHeaderItem) JavaScriptReferenceHeaderItem(org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem) XmlTag(org.apache.wicket.markup.parser.XmlTag) Test(org.junit.Test)

Example 22 with HeaderItem

use of org.apache.wicket.markup.head.HeaderItem in project wicket by apache.

the class WicketWebSocketJQueryResourceReference method getDependencies.

@Override
public List<HeaderItem> getDependencies() {
    final ResourceReference wicketAjaxReference;
    if (Application.exists()) {
        wicketAjaxReference = Application.get().getJavaScriptLibrarySettings().getWicketAjaxReference();
    } else {
        wicketAjaxReference = WicketAjaxJQueryResourceReference.get();
    }
    List<HeaderItem> dependencies = super.getDependencies();
    dependencies.add(JavaScriptHeaderItem.forReference(wicketAjaxReference));
    return dependencies;
}
Also used : JavaScriptResourceReference(org.apache.wicket.request.resource.JavaScriptResourceReference) WicketAjaxJQueryResourceReference(org.apache.wicket.ajax.WicketAjaxJQueryResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) HeaderItem(org.apache.wicket.markup.head.HeaderItem) JavaScriptHeaderItem(org.apache.wicket.markup.head.JavaScriptHeaderItem)

Aggregations

HeaderItem (org.apache.wicket.markup.head.HeaderItem)22 PriorityHeaderItem (org.apache.wicket.markup.head.PriorityHeaderItem)10 Test (org.junit.Test)10 JavaScriptHeaderItem (org.apache.wicket.markup.head.JavaScriptHeaderItem)7 JavaScriptResourceReference (org.apache.wicket.request.resource.JavaScriptResourceReference)6 ResourceReference (org.apache.wicket.request.resource.ResourceReference)5 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)2 CssHeaderItem (org.apache.wicket.markup.head.CssHeaderItem)2 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)2 WicketAjaxJQueryResourceReference (org.apache.wicket.ajax.WicketAjaxJQueryResourceReference)1 IReferenceHeaderItem (org.apache.wicket.markup.head.IReferenceHeaderItem)1 IWrappedHeaderItem (org.apache.wicket.markup.head.IWrappedHeaderItem)1 JavaScriptReferenceHeaderItem (org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem)1 ResourceAggregator (org.apache.wicket.markup.head.ResourceAggregator)1 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)1 DecoratingHeaderResponse (org.apache.wicket.markup.html.DecoratingHeaderResponse)1 XmlPullParser (org.apache.wicket.markup.parser.XmlPullParser)1 XmlTag (org.apache.wicket.markup.parser.XmlTag)1 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)1