Source code: com/opencms/defaults/master/CmsShowBackofficeMedia.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/defaults/master/CmsShowBackofficeMedia.java,v $
3 * Date : $Date: 2003/04/01 15:20:18 $
4 * Version: $Revision: 1.6 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 package com.opencms.defaults.master;
30
31 import com.opencms.core.CmsException;
32 import com.opencms.core.I_CmsSession;
33 import com.opencms.file.CmsObject;
34 import com.opencms.file.CmsRequestContext;
35 import com.opencms.template.CmsCacheDirectives;
36 import com.opencms.template.CmsXmlTemplate;
37
38 import java.util.Hashtable;
39
40
41 /**
42 * Displays binary files attached to module data.
43 */
44 public class CmsShowBackofficeMedia extends CmsXmlTemplate {
45
46 static final String C_EMPTY_PICTURE = "empty.gif";
47 static byte[] emptyGIF = new byte[0];
48
49 /**
50 * Gets the content of a defined section in a given template file and its
51 * subtemplates with the given parameters.
52 *
53 * @see #getContent(CmsObject, String, String, Hashtable, String)
54 *
55 * @param cms A_CmsObject Object for accessing system resources.
56 * @param templateFile Filename of the template file.
57 * @param elementName Element name of this template in our parent template.
58 * @param parameters Hashtable with all template class parameters.
59 * @param templateSelector template section that should be processed.
60 *
61 * @return It returns an array of bytes that contains the page.
62 */
63 public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
64 // session will be created or fetched
65 CmsRequestContext req = cms.getRequestContext();
66 I_CmsSession session = (I_CmsSession) req.getSession(true);
67 byte[] picture = new byte[0];
68 try{
69 //selected media content definition
70 CmsMasterMedia selectedmediaCD=null;
71 //try to get the medias from session
72 try{
73 selectedmediaCD=(CmsMasterMedia)session.getValue("selectedmediaCD");
74 }catch(Exception e){
75 e.printStackTrace(System.err);
76 }
77 //no CmsMasterMedia
78 if(selectedmediaCD != null){
79 picture = selectedmediaCD.getMedia();
80 String mType = selectedmediaCD.getMimetype();
81 if (mType == null || mType.equals("")) {
82 mType = "application/octet-stream";
83 }
84 // set the mimetype ...
85 req.getResponse().setContentType( mType );
86 //empty media
87 if(picture==null){
88 picture = emptyGIF;
89 // set the mimetype ...
90 req.getResponse().setContentType("images/gif");
91 }
92 }else{
93 picture = emptyGIF;
94 // set the mimetype ...
95 req.getResponse().setContentType("images/gif");
96 }
97 }catch(Exception exx){
98 exx.printStackTrace(System.err);
99 }
100 return picture;
101 }
102
103
104 /**
105 * gets the caching information from the current template class.
106 *
107 * @param cms CmsObject Object for accessing system resources
108 * @param templateFile Filename of the template file
109 * @param elementName Element name of this template in our parent template.
110 * @param parameters Hashtable with all template class parameters.
111 * @param templateSelector template section that should be processed.
112 * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
113 */
114 public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
115
116 // First build our own cache directives.
117 CmsCacheDirectives result = new CmsCacheDirectives(false);
118 return result;
119 }
120 }