01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/shared/control/tag/ContentTypeMapTag.java $
03: * $Id:ContentTypeMapTag.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.shared.control.tag;
21:
22: import java.io.IOException;
23:
24: import javax.servlet.jsp.JspException;
25: import javax.servlet.jsp.tagext.TagSupport;
26:
27: import org.sakaiproject.content.api.ContentTypeImageService;
28: import org.sakaiproject.metaobj.shared.model.MimeType;
29:
30: /**
31: * Created by IntelliJ IDEA.
32: * User: John Ellis
33: * Date: Jul 28, 2005
34: * Time: 9:23:55 AM
35: * To change this template use File | Settings | File Templates.
36: */
37: public class ContentTypeMapTag extends TagSupport {
38:
39: private static final String MAP_TYPE_IMAGE = "image";
40: private static final String MAP_TYPE_NAME = "name";
41: private static final String MAP_TYPE_EXTENSION = "extension";
42:
43: private MimeType fileType;
44: private String mapType;
45:
46: public ContentTypeMapTag() {
47: init();
48: }
49:
50: public int doStartTag() throws JspException {
51: String result = getValue(fileType.getValue(), mapType,
52: getImageTypeService());
53: try {
54: pageContext.getOut().write(result);
55: } catch (IOException e) {
56: throw new JspException(e);
57: }
58: return super .doStartTag();
59: }
60:
61: protected void init() {
62: mapType = MAP_TYPE_IMAGE;
63: }
64:
65: protected String getValue(String fileType, String mapType,
66: ContentTypeImageService service) {
67: if (mapType.equals(MAP_TYPE_IMAGE)) {
68: return service.getContentTypeImage(fileType);
69: } else if (mapType.equals(MAP_TYPE_NAME)) {
70: return service.getContentTypeDisplayName(fileType);
71: } else if (mapType.equals(MAP_TYPE_EXTENSION)) {
72: return service.getContentTypeExtension(fileType);
73: } else {
74: return null;
75: }
76: }
77:
78: protected ContentTypeImageService getImageTypeService() {
79: return org.sakaiproject.content.cover.ContentTypeImageService
80: .getInstance();
81: }
82:
83: public MimeType getFileType() {
84: return fileType;
85: }
86:
87: public void setFileType(MimeType fileType) {
88: this .fileType = fileType;
89: }
90:
91: public String getMapType() {
92: return mapType;
93: }
94:
95: public void setMapType(String mapType) {
96: this.mapType = mapType;
97: }
98:
99: }
|