001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.request.resource; 018 019import org.apache.wicket.request.Request; 020import org.apache.wicket.request.Response; 021import org.apache.wicket.request.handler.resource.ResourceRequestHandler; 022import org.apache.wicket.request.mapper.parameter.PageParameters; 023import org.apache.wicket.util.io.IClusterable; 024import org.apache.wicket.util.lang.Args; 025 026/** 027 * Resource is an object capable of writing output to response. 028 * 029 * @author Matej Knopp 030 */ 031@FunctionalInterface 032public interface IResource extends IClusterable 033{ 034 /** 035 * Attributes that are provided to resource in the {@link IResource#respond(Attributes)} method. 036 * Attributes are set by the {@link ResourceRequestHandler}. 037 * 038 * @author Matej Knopp 039 */ 040 class Attributes 041 { 042 private final Request request; 043 private final Response response; 044 private final PageParameters parameters; 045 046 /** 047 * Construct. 048 * 049 * @param request 050 * 051 * @param response 052 * @param parameters 053 */ 054 public Attributes(Request request, Response response, PageParameters parameters) 055 { 056 Args.notNull(request, "request"); 057 Args.notNull(response, "response"); 058 059 this.request = request; 060 this.response = response; 061 this.parameters = parameters; 062 } 063 064 /** 065 * Construct. 066 * 067 * @param request 068 * @param response 069 */ 070 public Attributes(Request request, Response response) 071 { 072 this(request, response, null); 073 } 074 075 /** 076 * Returns current request. 077 * 078 * @return current request 079 */ 080 public Request getRequest() 081 { 082 return request; 083 } 084 085 /** 086 * Returns current response. The resource must write output to the response. 087 * 088 * @return response 089 */ 090 public Response getResponse() 091 { 092 return response; 093 } 094 095 /** 096 * Returns additional parameters extracted from the request. If resource is created mounted 097 * {@link ResourceReference}, this method returns all (indexed and query) parameters after 098 * the mount path. For non mounted {@link ResourceReference}s this method will only return 099 * the query parameters. For component specific resources the behavior depends on the 100 * component. 101 * 102 * @return page parameters or <code>null</code> 103 */ 104 public PageParameters getParameters() 105 { 106 return parameters; 107 } 108 } 109 110 /** 111 * Renders this resource to response using the provided attributes. 112 * 113 * @param attributes 114 */ 115 void respond(Attributes attributes); 116}