KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > defaults > master > CmsShowBackofficeMedia


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/master/CmsShowBackofficeMedia.java,v $
3 * Date : $Date: 2005/05/17 13:47:28 $
4 * Version: $Revision: 1.1 $
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 org.opencms.file.CmsObject;
32 import org.opencms.file.CmsRequestContext;
33 import org.opencms.main.CmsException;
34
35 import com.opencms.core.I_CmsSession;
36 import com.opencms.legacy.CmsXmlTemplateLoader;
37 import com.opencms.template.CmsCacheDirectives;
38 import com.opencms.template.CmsXmlTemplate;
39
40 import java.util.Hashtable JavaDoc;
41
42
43 /**
44  * Displays binary files attached to module data.
45  *
46  * @deprecated Will not be supported past the OpenCms 6 release.
47  */

48 public class CmsShowBackofficeMedia extends CmsXmlTemplate {
49
50     static final String JavaDoc C_EMPTY_PICTURE = "empty.gif";
51     static byte[] emptyGIF = new byte[0];
52
53     /**
54      * Gets the content of a defined section in a given template file and its
55      * subtemplates with the given parameters.
56      *
57      * @see #getContent(CmsObject, String, String, Hashtable, String)
58      *
59      * @param cms A_CmsObject Object for accessing system resources.
60      * @param templateFile Filename of the template file.
61      * @param elementName Element name of this template in our parent template.
62      * @param parameters Hashtable with all template class parameters.
63      * @param templateSelector template section that should be processed.
64      *
65      * @return It returns an array of bytes that contains the page.
66      */

67     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
68         // session will be created or fetched
69
CmsRequestContext req = cms.getRequestContext();
70         I_CmsSession session = CmsXmlTemplateLoader.getSession(req, true);
71         byte[] picture = new byte[0];
72         try{
73         //selected media content definition
74
CmsMasterMedia selectedmediaCD=null;
75         //try to get the medias from session
76
try{
77                 selectedmediaCD=(CmsMasterMedia)session.getValue("selectedmediaCD");
78         }catch(Exception JavaDoc e){
79                 e.printStackTrace(System.err);
80         }
81         //no CmsMasterMedia
82
if(selectedmediaCD != null){
83                 picture = selectedmediaCD.getMedia();
84                 String JavaDoc mType = selectedmediaCD.getMimetype();
85                 if (mType == null || mType.equals("")) {
86                     mType = "application/octet-stream";
87                 }
88                 // set the mimetype ...
89
CmsXmlTemplateLoader.getResponse(req).setContentType( mType );
90                 //empty media
91
if(picture==null){
92                     picture = emptyGIF;
93                     // set the mimetype ...
94
CmsXmlTemplateLoader.getResponse(req).setContentType("images/gif");
95                 }
96             }else{
97                 picture = emptyGIF;
98                  // set the mimetype ...
99
CmsXmlTemplateLoader.getResponse(req).setContentType("images/gif");
100         }
101         }catch(Exception JavaDoc exx){
102                 exx.printStackTrace(System.err);
103         }
104         return picture;
105     }
106
107
108    /**
109      * gets the caching information from the current template class.
110      *
111      * @param cms CmsObject Object for accessing system resources
112      * @param templateFile Filename of the template file
113      * @param elementName Element name of this template in our parent template.
114      * @param parameters Hashtable with all template class parameters.
115      * @param templateSelector template section that should be processed.
116      * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
117      */

118     public CmsCacheDirectives getCacheDirectives(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
119
120         // First build our own cache directives.
121
CmsCacheDirectives result = new CmsCacheDirectives(false);
122         return result;
123     }
124 }
Popular Tags