001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.galleries; 029 030import org.opencms.file.CmsResource; 031import org.opencms.json.JSONException; 032import org.opencms.json.JSONObject; 033import org.opencms.jsp.CmsJspActionElement; 034import org.opencms.loader.CmsLoaderException; 035import org.opencms.main.CmsLog; 036import org.opencms.main.OpenCms; 037 038import javax.servlet.http.HttpServletRequest; 039import javax.servlet.http.HttpServletResponse; 040import javax.servlet.jsp.PageContext; 041 042import org.apache.commons.logging.Log; 043 044/** 045 * Provides the specific constants, members and helper methods to generate the content of the download gallery dialog 046 * used in the XML content editors, WYSIWYG editors and context menu.<p> 047 * 048 * @since 7.5.0 049 */ 050public class CmsAjaxDownloadGallery extends A_CmsAjaxGallery { 051 052 /** Type name of the download gallery. */ 053 public static final String GALLERYTYPE_NAME = "downloadgallery"; 054 055 /** The uri suffix for the gallery start page. */ 056 public static final String OPEN_URI_SUFFIX = GALLERYTYPE_NAME + "/index.jsp"; 057 058 /** The log object for this class. */ 059 private static final Log LOG = CmsLog.getLog(CmsAjaxDownloadGallery.class); 060 061 /** The resource type id of this gallery instance. */ 062 private int m_galleryTypeId; 063 064 /** 065 * Public empty constructor, required for {@link A_CmsAjaxGallery#createInstance(String, CmsJspActionElement)}.<p> 066 */ 067 public CmsAjaxDownloadGallery() { 068 069 // noop 070 } 071 072 /** 073 * Public constructor with JSP action element.<p> 074 * 075 * @param jsp an initialized JSP action element 076 */ 077 public CmsAjaxDownloadGallery(CmsJspActionElement jsp) { 078 079 super(jsp); 080 081 } 082 083 /** 084 * Public constructor with JSP variables.<p> 085 * 086 * @param context the JSP page context 087 * @param req the JSP request 088 * @param res the JSP response 089 */ 090 public CmsAjaxDownloadGallery(PageContext context, HttpServletRequest req, HttpServletResponse res) { 091 092 this(new CmsJspActionElement(context, req, res)); 093 } 094 095 /** 096 * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#getGalleryItemsTypeId() 097 * 098 * @return -1 for download gallery type 099 */ 100 @Override 101 public int getGalleryItemsTypeId() { 102 103 return -1; 104 } 105 106 /** 107 * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#getGalleryTypeId() 108 */ 109 @Override 110 public int getGalleryTypeId() { 111 112 try { 113 m_galleryTypeId = OpenCms.getResourceManager().getResourceType(GALLERYTYPE_NAME).getTypeId(); 114 } catch (CmsLoaderException e) { 115 // resource type not found, log error 116 if (LOG.isErrorEnabled()) { 117 LOG.error(e.getLocalizedMessage(), e); 118 } 119 } 120 return m_galleryTypeId; 121 } 122 123 /** 124 * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#getGalleryTypeName() 125 */ 126 @Override 127 public String getGalleryTypeName() { 128 129 return GALLERYTYPE_NAME; 130 } 131 132 /** 133 * Fills the JSON object with the specific information used for download file resource type.<p> 134 * 135 * <ul> 136 * <li><code>mimetype</code>: file mimetype.</li> 137 * </ul> 138 * 139 * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) 140 * 141 */ 142 @Override 143 protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { 144 145 try { 146 // file mimetype 147 String mt = OpenCms.getResourceManager().getMimeType(getJsp().link(sitePath), null); 148 if (mt.equals("application/msword") 149 || mt.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { 150 mt = "application/msword"; 151 } else if (mt.equals("application/pdf")) { 152 mt = "application/pdf"; 153 } else if (mt.equals("application/vnd.ms-excel") 154 || mt.equals("application/excel") 155 || mt.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { 156 mt = "application/excel"; 157 } else if (mt.equals("application/vnd.ms-powerpoint") 158 || mt.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) { 159 mt = "application/powerpoint"; 160 } else if (mt.equals("image/jpeg") 161 || mt.equals("image/gif") 162 || mt.equals("image/png") 163 || mt.equals("image/tiff")) { 164 mt = "image/image"; 165 } else if (mt.equals("text/plain")) { 166 mt = "text/plain"; 167 } else if (mt.equals("text/html")) { 168 mt = "text/html"; 169 } else 170 if (mt.equals("application/zip") || mt.equals("application/x-gzip") || mt.equals("application/x-tar")) { 171 mt = "application/archiv"; 172 } else { 173 mt = "unknown/mimetype"; 174 } 175 jsonObj.put("mimetype", mt); 176 177 } catch (JSONException e) { 178 if (LOG.isErrorEnabled()) { 179 LOG.error(e.getLocalizedMessage(), e); 180 } 181 } 182 } 183}