001/* 002 * Copyright 2013 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.cart; 017 018import java.time.ZonedDateTime; 019import java.util.ArrayList; 020import java.util.List; 021 022import org.ametys.cms.contenttype.ContentTypeExtensionPoint; 023import org.ametys.cms.contenttype.ContentTypesHelper; 024import org.ametys.cms.repository.Content; 025import org.ametys.core.user.UserIdentity; 026import org.ametys.runtime.i18n.I18nizableText; 027 028/** 029 * Implementation of a {@link CartElement} wrapping a {@link Content} 030 * 031 */ 032public class ContentElement implements CartElement 033{ 034 private Content _content; 035 private ContentTypesHelper _cTypesHelper; 036 private ContentTypeExtensionPoint _cTypesEP; 037 038 /** 039 * Constructor 040 * @param content The content 041 * @param cTypesHelper The content types helper 042 * @param cTypesEP The extension point for content types 043 */ 044 public ContentElement (Content content, ContentTypesHelper cTypesHelper, ContentTypeExtensionPoint cTypesEP) 045 { 046 _content = content; 047 _cTypesHelper = cTypesHelper; 048 _cTypesEP = cTypesEP; 049 } 050 051 @Override 052 public String getId() 053 { 054 return _content.getId(); 055 } 056 057 @Override 058 public I18nizableText getTitle() 059 { 060 return new I18nizableText(_content.getTitle()); 061 } 062 063 @Override 064 public I18nizableText getDescription() 065 { 066 return new I18nizableText(""); 067 } 068 069 @Override 070 public List<I18nizableText> getGroups () 071 { 072 List<I18nizableText> cTypesLabel = new ArrayList<>(); 073 074 for (String cTypeId : _content.getTypes()) 075 { 076 cTypesLabel.add(_cTypesEP.getExtension(cTypeId).getLabel()); 077 } 078 return cTypesLabel; 079 } 080 081 @Override 082 public ZonedDateTime getCreationDate() 083 { 084 return _content.getCreationDate(); 085 } 086 087 @Override 088 public UserIdentity getCreator() 089 { 090 return _content.getCreator(); 091 } 092 093 @Override 094 public ZonedDateTime getLastModified() 095 { 096 return _content.getLastModified(); 097 } 098 099 @Override 100 public UserIdentity getLastContributor() 101 { 102 return _content.getLastContributor(); 103 } 104 105 @Override 106 public String getType() 107 { 108 return "content"; 109 } 110 111 @Override 112 public String getGlyphIcon() 113 { 114 return _cTypesHelper.getIconGlyph(_content); 115 } 116 117 @Override 118 public String getSmallIcon() 119 { 120 return _cTypesHelper.getSmallIcon(_content); 121 } 122 123 @Override 124 public String getMediumIcon() 125 { 126 return _cTypesHelper.getMediumIcon(_content); 127 } 128 129 /** 130 * Get the content 131 * @return The content 132 */ 133 public Content getContent() 134 { 135 return _content; 136 } 137}