KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > galleries > CmsOpenGallery


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/galleries/CmsOpenGallery.java,v $
3  * Date : $Date: 2005/06/27 23:22:15 $
4  * Version: $Revision: 1.11 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.galleries;
33
34 import org.opencms.file.CmsResource;
35 import org.opencms.i18n.CmsMessageContainer;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.CmsRuntimeException;
40 import org.opencms.main.OpenCms;
41 import org.opencms.workplace.CmsDialog;
42 import org.opencms.workplace.CmsWorkplaceSettings;
43
44 import javax.servlet.http.HttpServletRequest JavaDoc;
45 import javax.servlet.http.HttpServletResponse JavaDoc;
46 import javax.servlet.jsp.PageContext JavaDoc;
47
48 import org.apache.commons.logging.Log;
49
50 /**
51  * Provides methods for open gallery dialog.<p>
52  *
53  * The following files use this class:
54  * <ul>
55  * <li>/commons/opengallery.jsp
56  * </ul>
57  * <p>
58  *
59  * @author Armen Markarian
60  *
61  * @version $Revision: 1.11 $
62  *
63  * @since 6.0.0
64  */

65 public class CmsOpenGallery extends CmsDialog {
66
67     /** The dialog type. */
68     public static final String JavaDoc DIALOG_TYPE = "opengallery";
69
70     /** The log object for this class. */
71     private static final Log LOG = CmsLog.getLog(CmsOpenGallery.class);
72
73     /**
74      * Public constructor with JSP action element.<p>
75      *
76      * @param jsp an initialized JSP action element
77      */

78     public CmsOpenGallery(CmsJspActionElement jsp) {
79
80         super(jsp);
81     }
82
83     /**
84      * Public constructor with JSP variables.<p>
85      *
86      * @param context the JSP page context
87      * @param req the JSP request
88      * @param res the JSP response
89      */

90     public CmsOpenGallery(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
91
92         this(new CmsJspActionElement(context, req, res));
93     }
94
95     /**
96      * Generates a javascript window open for the requested gallery type.<p>
97      *
98      * @return a javascript window open for the requested gallery type
99      */

100     public String JavaDoc openGallery() {
101
102         StringBuffer JavaDoc jsOpener = new StringBuffer JavaDoc(32);
103         String JavaDoc galleryType = null;
104         try {
105             CmsResource res = getCms().readResource(getParamResource());
106             if (res != null) {
107                 // get gallery path
108
String JavaDoc galleryPath = getParamResource();
109                 if (!galleryPath.endsWith("/")) {
110                     galleryPath += "/";
111                 }
112                 // get the matching gallery type name
113
galleryType = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
114                 String JavaDoc galleryUri = A_CmsGallery.PATH_GALLERIES
115                     + A_CmsGallery.OPEN_URI_SUFFIX
116                     + "?"
117                     + A_CmsGallery.PARAM_GALLERY_TYPENAME
118                     + "="
119                     + galleryType;
120                 jsOpener.append("window.open('");
121                 jsOpener.append(getJsp().link(galleryUri));
122                 jsOpener.append("&");
123                 jsOpener.append(A_CmsGallery.PARAM_DIALOGMODE);
124                 jsOpener.append("=");
125                 jsOpener.append(A_CmsGallery.MODE_VIEW);
126                 jsOpener.append("&");
127                 jsOpener.append(A_CmsGallery.PARAM_GALLERYPATH);
128                 jsOpener.append("=");
129                 jsOpener.append(galleryPath);
130                 jsOpener.append("', '");
131                 jsOpener.append(galleryType);
132                 jsOpener.append("','width=650, height=700, resizable=yes, top=100, left=270, status=yes');");
133             }
134         } catch (CmsException e) {
135             // requested type is not configured
136
CmsMessageContainer message = Messages.get().container(Messages.ERR_OPEN_GALLERY_1, galleryType);
137             LOG.error(message.key(), e);
138             throw new CmsRuntimeException(message, e);
139         }
140
141         return jsOpener.toString();
142     }
143
144     /**
145      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
146      */

147     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
148
149         // fill the parameter values in the get/set methods
150
fillParamValues(request);
151         // set the dialog type
152
setParamDialogtype(DIALOG_TYPE);
153     }
154 }
Popular Tags