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.ugc.page; 017 018import java.util.Locale; 019import java.util.Map; 020 021import org.ametys.cms.repository.Content; 022import org.ametys.runtime.i18n.I18nizableText; 023import org.ametys.web.repository.page.Page; 024 025import com.google.common.collect.ImmutableMap; 026 027/** 028 * The information about a {@link UGCTransitionalPage} 029 */ 030public interface TransitionalPageInformation 031{ 032 /** 033 * Gets the unique key of the transitional page 034 * @return the unique key of the transitional page 035 */ 036 String getKey(); 037 038 /** 039 * Gets the value of the classification attribute for the transitional page 040 * @return the value of the classification attribute for the transitional page 041 */ 042 String getAttributeValue(); 043 044 /** 045 * Gets the title of the transitional page 046 * @return the title of the transitional page 047 */ 048 String getTitle(); 049 050 /** 051 * Gets the information as a map 052 * @return the information as a map 053 */ 054 default Map<String, String> getInfo() 055 { 056 return ImmutableMap.of( 057 UGCPageHandler.ATTRIBUTE_TRANSITIONAL_PAGE_METADATA_VALUE, getAttributeValue(), 058 UGCPageHandler.ATTRIBUTE_TRANSITIONAL_PAGE_TITLE, getTitle()); 059 } 060 061 /** 062 * UGC pages are classified by a linked Content on their UG Content (for instance entries of a reference table) 063 */ 064 static class TypeContent implements TransitionalPageInformation 065 { 066 private Content _content; 067 private Page _rootPage; 068 069 TypeContent(Content content, Page rootPage) 070 { 071 _content = content; 072 _rootPage = rootPage; 073 } 074 075 @Override 076 public String getKey() 077 { 078 return _content.getName(); 079 } 080 081 @Override 082 public String getAttributeValue() 083 { 084 return _content.getId(); 085 } 086 087 @Override 088 public String getTitle() 089 { 090 return _content.getTitle(new Locale(_rootPage.getSitemapName())); 091 } 092 } 093 094 /** 095 * UGC pages are classified by entries of an enumerator 096 */ 097 static class TypeEnum implements TransitionalPageInformation 098 { 099 private String _key; 100 private I18nizableText _text; 101 private UGCPageHandler _ugcPageHandler; 102 103 TypeEnum(UGCPageHandler ugcPageHandler, String key, I18nizableText text) 104 { 105 _ugcPageHandler = ugcPageHandler; 106 _key = key; 107 _text = text; 108 } 109 110 @Override 111 public String getKey() 112 { 113 return _key; 114 } 115 116 @Override 117 public String getAttributeValue() 118 { 119 return _key; 120 } 121 122 @Override 123 public String getTitle() 124 { 125 return _ugcPageHandler._i18nUtils.translate(_text); 126 } 127 } 128}