@@ -0,0 +1,2501 @@
+/**%0A * Copyright 2011 55 Minutes (http://www.55minutes.com)%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage fiftyfive.wicket.resource;%0A%0Aimport org.apache.wicket.protocol.http.WebApplication;%0Aimport org.apache.wicket.request.IRequestHandler;%0Aimport org.apache.wicket.request.IRequestMapper;%0Aimport org.apache.wicket.request.Request;%0Aimport org.apache.wicket.request.Url;%0Aimport org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;%0Aimport org.apache.wicket.util.string.Strings;%0A%0A/**%0A * Enables a Wicket application to have its static resources proxied by a CDN, for example%0A * by Amazon Cloudfront. TODO%0A */%0Apublic class SimpleCDN implements IRequestMapper%0A%7B%0A    private String baseUrl;%0A    private IRequestMapper delegate;%0A    private boolean delegated = false;%0A    %0A    public SimpleCDN(String baseUrl)%0A    %7B%0A        this.baseUrl = baseUrl;%0A    %7D%0A    %0A    public void install(WebApplication app)%0A    %7B%0A        this.delegate = app.getRootRequestMapperAsCompound();%0A        app.mount(this);%0A    %7D%0A    %0A    public Url mapHandler(IRequestHandler requestHandler)%0A    %7B%0A        // CDN doesn't apply to non-resources%0A        if(!(requestHandler instanceof ResourceReferenceRequestHandler)) return null;%0A        %0A        // Prevent infinite recursion in case this CDN is also contained within the delegate%0A        if(this.delegated) return null;%0A        %0A        Url url = null;%0A        try%0A        %7B%0A            this.delegated = true;%0A            url = this.delegate.mapHandler(requestHandler);%0A            if(url != null && url.getQueryParameters().isEmpty())%0A            %7B%0A                url = Url.parse(Strings.join(%22/%22, this.baseUrl, url.toString()));%0A            %7D%0A        %7D%0A        finally%0A        %7B%0A            this.delegated = false;%0A        %7D%0A        return url;%0A    %7D%0A    %0A    public IRequestHandler mapRequest(Request request)%0A    %7B%0A        return null;%0A    %7D%0A    %0A    public int getCompatibilityScore(Request request)%0A    %7B%0A        return 0;%0A    %7D%0A%7D%0A

Introduce SimpleCDN