diff --git a/src/main/java/de/thm/arsnova/PaginationListDecorator.java b/src/main/java/de/thm/arsnova/PaginationListDecorator.java index 8a5cf2c31c24c41c98db1a97e9f5379a15bf025b..9dd4f092b5f89632f2eaafa01e126b42aec26d98 100644 --- a/src/main/java/de/thm/arsnova/PaginationListDecorator.java +++ b/src/main/java/de/thm/arsnova/PaginationListDecorator.java @@ -22,6 +22,11 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; +/** + * Extends {@link List}s with the ability to paginate. + * + * @param <T> type of the List items + */ public class PaginationListDecorator<T> implements List<T> { private final List<T> list; private List<T> subList; @@ -45,30 +50,48 @@ public class PaginationListDecorator<T> implements List<T> { } } + /** + * @return the original (not paginated) List + */ public List<T> getList() { return list; } + /** + * @return the number of skipped items + */ public int getOffset() { return offset; } + /** + * @param offset the number of items to be skipped + */ public void setOffset(final int offset) { this.offset = offset; checkRange(); subList = list.subList(this.offset, this.offset + this.limit); } + /** + * @return the size limit of the paginated list + */ public int getLimit() { return limit; } + /** + * @param limit the size limit for the resulting list + */ public void setLimit(final int limit) { this.limit = limit; checkRange(); subList = list.subList(this.offset, this.offset + this.limit); } + /** + * @return the size of the original (not paginated) List + */ public int getTotalSize() { return list.size(); } diff --git a/src/main/java/de/thm/arsnova/aop/RangeAspect.java b/src/main/java/de/thm/arsnova/aop/RangeAspect.java index 3279ded73994d809e3023eecc2be9993fde8d000..03bd80fb085317e73b49fdfa431fa2d05106756c 100644 --- a/src/main/java/de/thm/arsnova/aop/RangeAspect.java +++ b/src/main/java/de/thm/arsnova/aop/RangeAspect.java @@ -37,6 +37,11 @@ import de.thm.arsnova.PaginationListDecorator; import de.thm.arsnova.controller.PaginationController; import de.thm.arsnova.services.ResponseProviderService; +/** + * An aspect which parses requests for pagination parameters in a "Range" header and adds a "Content-Range" header to + * the response. It only applies to methods of {@link PaginationController}s annotated with + * {@link de.thm.arsnova.web.Pagination} which return a {@link List}. + */ @Component @Aspect @Profile("!test") @@ -52,8 +57,7 @@ public class RangeAspect { private static final Logger logger = LoggerFactory.getLogger(RangeAspect.class); - /** Sets start and end parameters based on request's range header - * and sets content range header for the response + /** Sets start and end parameters based on request's range header and sets content range header for the response. * * @param controller * @throws Throwable diff --git a/src/main/java/de/thm/arsnova/controller/PaginationController.java b/src/main/java/de/thm/arsnova/controller/PaginationController.java index 9b1c7db094e4d58a7ec3c8aa3877e2619b2eb7d5..a36a0501074f4a2902c258d1efa36e3eaf532c56 100644 --- a/src/main/java/de/thm/arsnova/controller/PaginationController.java +++ b/src/main/java/de/thm/arsnova/controller/PaginationController.java @@ -17,6 +17,9 @@ */ package de.thm.arsnova.controller; +/** + * Adds pagination properties to controllers. + */ public class PaginationController extends AbstractController { protected int offset = -1; protected int limit = -1; diff --git a/src/main/java/de/thm/arsnova/services/ResponseProviderService.java b/src/main/java/de/thm/arsnova/services/ResponseProviderService.java index 19b1713f7d2a9e6a475d49fa139cf83573fbcec7..f8cd8a9b05823d1b30cfce211d3192e714f5f6e3 100644 --- a/src/main/java/de/thm/arsnova/services/ResponseProviderService.java +++ b/src/main/java/de/thm/arsnova/services/ResponseProviderService.java @@ -19,6 +19,9 @@ package de.thm.arsnova.services; import javax.servlet.http.HttpServletResponse; +/** + * Allows access to the {@link HttpServletResponse} outside of Controllers. + */ public interface ResponseProviderService { public void setResponse(HttpServletResponse response); diff --git a/src/main/java/de/thm/arsnova/web/Pagination.java b/src/main/java/de/thm/arsnova/web/Pagination.java index e8f60df651ce9017941dfb6e7de16ba788b8e722..f8f8a98242e8a0d7beba182962fdaa77eac7b934 100644 --- a/src/main/java/de/thm/arsnova/web/Pagination.java +++ b/src/main/java/de/thm/arsnova/web/Pagination.java @@ -23,6 +23,10 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Marks controller methods for pagination. For pagination to work the controller class has to specialize + * {@link de.thm.arsnova.controller.PaginationController} and the return value has to be a List. + */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Documented diff --git a/src/main/java/de/thm/arsnova/web/ResponseInterceptorHandler.java b/src/main/java/de/thm/arsnova/web/ResponseInterceptorHandler.java index 27f15d10e977de8d5ab4b75d0c1211ecf1c76fef..15e157c01a3b2b68814d23c06fbc55c1be4eb977 100644 --- a/src/main/java/de/thm/arsnova/web/ResponseInterceptorHandler.java +++ b/src/main/java/de/thm/arsnova/web/ResponseInterceptorHandler.java @@ -26,6 +26,10 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import de.thm.arsnova.services.ResponseProviderService; +/** + * Injects a {@link HttpServletResponse} into {@link ResponseProviderService} to allow access to it outside of + * Controllers. + */ @Component public class ResponseInterceptorHandler extends HandlerInterceptorAdapter {