001/* 002 * Copyright 2019 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.odfweb.repository; 017 018import java.util.NoSuchElementException; 019 020import org.ametys.plugins.repository.AmetysObject; 021import org.ametys.plugins.repository.AmetysObjectIterable; 022import org.ametys.plugins.repository.AmetysObjectIterator; 023import org.ametys.plugins.repository.AmetysRepositoryException; 024import org.ametys.plugins.repository.UnknownAmetysObjectException; 025import org.ametys.web.repository.page.Page; 026import org.ametys.web.repository.page.virtual.AbstractConfigurableVirtualPage; 027import org.ametys.web.repository.page.virtual.VirtualPageConfiguration; 028 029/** 030 * Common class for ODF virtual pages 031 * @param <T> The type of factory to use 032 * 033 */ 034public abstract class AbstractOdfPage<T extends AbstractOdfPageFactory> extends AbstractConfigurableVirtualPage<T> 035{ 036 /** 037 * The constructor of abstract odf pages 038 * @param root the odf root page. 039 * @param configuration The abstract virtual page configuration 040 * @param scheme The scheme 041 * @param factory The factory 042 */ 043 public AbstractOdfPage(Page root, VirtualPageConfiguration configuration, String scheme, T factory) 044 { 045 super(root, configuration, scheme, factory); 046 } 047 048 @SuppressWarnings("unchecked") 049 @Override 050 public AmetysObjectIterable<? extends AmetysObject> getChildren() throws AmetysRepositoryException 051 { 052 return getChildrenPages(); 053 } 054 055 @Override 056 public AmetysObjectIterable< ? extends Page> getChildrenPages(boolean includeInvisiblePages) throws AmetysRepositoryException 057 { 058 return getChildrenPages(); 059 } 060 061 @Override 062 public Page getChildPageAt(int index) throws UnknownAmetysObjectException, AmetysRepositoryException 063 { 064 if (index < 0) 065 { 066 throw new AmetysRepositoryException("Child page index cannot be negative"); 067 } 068 069 AmetysObjectIterator<? extends Page> childPages = getChildrenPages().iterator(); 070 071 try 072 { 073 childPages.skip(index); 074 return childPages.next(); 075 } 076 catch (NoSuchElementException e) 077 { 078 throw new UnknownAmetysObjectException("There's no child page at index " + index + " for page " + this.getId()); 079 } 080 } 081}