001/* 002 * Copyright 2016 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 */ 016 017package org.ametys.plugins.userdirectory.page; 018 019import org.ametys.plugins.repository.AmetysRepositoryException; 020import org.ametys.plugins.userdirectory.UserDirectoryPageHandler; 021import org.ametys.web.repository.page.Page; 022import org.ametys.web.repository.page.ZoneItem; 023import org.ametys.web.repository.page.jcr.DefaultPage; 024import org.ametys.web.repository.page.virtual.AbstractConfigurableVirtualPage; 025import org.ametys.web.repository.page.virtual.ConfigurableVirtualZoneItem; 026import org.ametys.web.repository.page.virtual.ConfigurableVirtualZoneItemFactory; 027import org.ametys.web.repository.page.virtual.VirtualZoneItemConfiguration; 028 029/** 030 * {@link ZoneItem} holding a content. 031 */ 032public class UserZoneItem extends ConfigurableVirtualZoneItem 033{ 034 /** 035 * Constructor. 036 * @param page the parent {@link UserPage}. 037 * @param configuration The configuration 038 * @param scheme The scheme 039 * @param factory The factory 040 */ 041 public UserZoneItem(AbstractConfigurableVirtualPage page, VirtualZoneItemConfiguration configuration, String scheme, ConfigurableVirtualZoneItemFactory factory) 042 { 043 super(page, configuration, scheme, factory); 044 } 045 046 @Override 047 public String getViewName() throws AmetysRepositoryException 048 { 049 // The view from the configuration of users virtual pages is ignored because the users can choose the view when they set the root page. 050 Page rootPage = getRootPage(); 051 return rootPage != null ? rootPage.getValue(UserDirectoryPageHandler.USER_VIEW_NAME, "main") : "main"; 052 } 053 054 Page getRootPage() 055 { 056 Page parent = _page.getParent(); 057 while (parent != null) 058 { 059 if (parent instanceof DefaultPage) 060 { 061 return parent; 062 } 063 parent = parent.getParent(); 064 } 065 return null; 066 } 067}