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.Collections; 020import java.util.List; 021 022import org.ametys.core.user.UserIdentity; 023import org.ametys.core.util.DateUtils; 024import org.ametys.plugins.explorer.resources.Resource; 025import org.ametys.runtime.i18n.I18nizableText; 026 027/** 028 * Implementation of a {@link CartElement} wrapping a {@link Resource} 029 * 030 */ 031public class ResourceElement implements CartElement 032{ 033 private Resource _resource; 034 035 /** 036 * Constructor 037 * @param resource The resource 038 */ 039 public ResourceElement (Resource resource) 040 { 041 _resource = resource; 042 } 043 044 @Override 045 public String getId() 046 { 047 return _resource.getId(); 048 } 049 050 @Override 051 public I18nizableText getTitle() 052 { 053 return new I18nizableText(_resource.getName()); 054 } 055 056 @Override 057 public I18nizableText getDescription() 058 { 059 return new I18nizableText(""); 060 } 061 062 @Override 063 public List<I18nizableText> getGroups() 064 { 065 return Collections.singletonList(new I18nizableText("plugin.cart", "PLUGINS_CART_UITOOL_CART_RESOURCES_GROUP")); 066 } 067 068 @Override 069 public ZonedDateTime getCreationDate() 070 { 071 return DateUtils.asZonedDateTime(_resource.getCreationDate()); 072 } 073 074 @Override 075 public UserIdentity getCreator() 076 { 077 return _resource.getCreator(); 078 } 079 080 @Override 081 public ZonedDateTime getLastModified() 082 { 083 return DateUtils.asZonedDateTime(_resource.getLastModified()); 084 } 085 086 @Override 087 public UserIdentity getLastContributor() 088 { 089 return _resource.getLastContributor(); 090 } 091 092 @Override 093 public String getType() 094 { 095 return "resource"; 096 } 097 098 @Override 099 public String getGlyphIcon() 100 { 101 int index = _resource.getName().lastIndexOf("."); 102 String extension = _resource.getName().substring(index + 1); 103 104 switch (extension) 105 { 106 case "css": 107 return "ametysicon-css5"; 108 case "csv": 109 return "ametysicon-file-extension-csv"; 110 case "doc": 111 return "ametysicon-file-extension-doc"; 112 case "docx": 113 return "ametysicon-file-extension-docx"; 114 case "html": 115 case "htm": 116 case "xhtml": 117 return "ametysicon-file-extension-html"; 118 case "png": 119 case "jpg": 120 case "jpeg": 121 case "bmp": 122 case "gif": 123 return "ametysicon-image2"; 124 case "pdf": 125 return "ametysicon-pdf17"; 126 case "ppt": 127 return "ametysicon-ppt"; 128 case "pptx": 129 return "ametysicon-pptx"; 130 case "txt": 131 return "ametysicon-txt"; 132 case "avi": 133 case "mov": 134 case "swf": 135 case "wmv": 136 case "flv": 137 case "mpeg": 138 case "mpg": 139 return "ametysicon-movie16"; 140 case "xml": 141 return "ametysicon-xml6"; 142 case "xls": 143 return "ametysicon-xls1"; 144 case "xlsx": 145 return "ametysicon-xlsx"; 146 case "zip": 147 return "ametysicon-zip6"; 148 case "rar": 149 case "odp": 150 return "ametysicon-odp2"; 151 case "odt": 152 return "ametysicon-odt5"; 153 case "jar": 154 return "ametysicon-jar3"; 155 case "pps": 156 return "ametysicon-pps2"; 157 case "psd": 158 return "ametysicon-psd3"; 159 case "tar": 160 case "tgz": 161 return "ametysicon-tar1"; 162 case "mp3": 163 case "mod": 164 case "mid": 165 return "ametysicon-music168"; 166 default: 167 return "ametysicon-question-mark1"; 168 } 169 } 170 171 @Override 172 public String getSmallIcon() 173 { 174 return null; 175 } 176 177 @Override 178 public String getMediumIcon() 179 { 180 return null; 181 } 182 183 /** 184 * Get the resource 185 * @return The resource 186 */ 187 public Resource getResource() 188 { 189 return _resource; 190 } 191}