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