KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsEditPointer


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsEditPointer.java,v $
3  * Date : $Date: 2005/07/13 14:30:36 $
4  * Version: $Revision: 1.13 $
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.commons;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsResource;
36 import org.opencms.i18n.CmsEncoder;
37 import org.opencms.jsp.CmsJspActionElement;
38 import org.opencms.security.CmsPermissionSet;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.workplace.CmsDialog;
41 import org.opencms.workplace.CmsWorkplaceSettings;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45 import javax.servlet.jsp.JspException JavaDoc;
46 import javax.servlet.jsp.PageContext JavaDoc;
47
48 /**
49  * The edit pointer dialog changes the link target of a pointer resource.<p>
50  *
51  * The following files use this class:
52  * <ul>
53  * <li>/commons/editpointer.jsp
54  * </ul>
55  * <p>
56  *
57  * @author Andreas Zahner
58  *
59  * @version $Revision: 1.13 $
60  *
61  * @since 6.0.0
62  */

63 public class CmsEditPointer extends CmsDialog {
64
65     /** The dialog type.<p> */
66     public static final String JavaDoc DIALOG_TYPE = "newlink";
67
68     /** Request parameter name for the link target.<p> */
69     public static final String JavaDoc PARAM_LINKTARGET = "linktarget";
70
71     /** Stores the value of the link target.<p> */
72     private String JavaDoc m_paramLinkTarget;
73
74     /**
75      * Public constructor with JSP action element.<p>
76      *
77      * @param jsp an initialized JSP action element
78      */

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

91     public CmsEditPointer(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
92
93         this(new CmsJspActionElement(context, req, res));
94     }
95
96     /**
97      * Changes the link target of the pointer.<p>
98      *
99      * @throws JspException if inclusion of error dialog fails
100      */

101     public void actionChangeLinkTarget() throws JspException JavaDoc {
102
103         try {
104             // check the resource lock state
105
checkLock(getParamResource());
106             // change the link target
107
CmsFile editFile = getCms().readFile(getParamResource());
108             editFile.setContents(getParamLinkTarget().getBytes());
109             getCms().writeFile(editFile);
110             // close the dialog window
111
actionCloseDialog();
112         } catch (Throwable JavaDoc e) {
113             // error changing link target, show error dialog
114
setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_CHANGE_LINK_TARGET_0));
115             includeErrorpage(this, e);
116         }
117     }
118
119     /**
120      * Returns the old link target value of the pointer resource to edit.<p>
121      *
122      * @return the old link target value
123      * @throws JspException if problems including sub-elements occur
124      *
125      */

126     public String JavaDoc getOldTargetValue() throws JspException JavaDoc {
127
128         String JavaDoc linkTarget = "";
129         if (CmsStringUtil.isEmpty(getParamLinkTarget())) {
130             // this is the initial dialog call, get link target value
131
try {
132                 // get pointer contents
133
CmsFile file = getCms().readFile(getParamResource());
134                 linkTarget = new String JavaDoc(file.getContents());
135             } catch (Throwable JavaDoc e1) {
136                 // error reading file, show error dialog
137
setParamMessage(Messages.get().getBundle(getLocale()).key(
138                     Messages.ERR_GET_LINK_TARGET_1,
139                     getParamResource()));
140                 includeErrorpage(this, e1);
141
142             }
143         }
144         return CmsEncoder.escapeXml(linkTarget);
145     }
146
147     /**
148      * Returns the link target request parameter value.<p>
149      *
150      * @return the link target request parameter value
151      */

152     public String JavaDoc getParamLinkTarget() {
153
154         return m_paramLinkTarget;
155     }
156
157     /**
158      * Sets the link target request parameter value.<p>
159      *
160      * @param linkTarget the link target request parameter value
161      */

162     public void setParamLinkTarget(String JavaDoc linkTarget) {
163
164         m_paramLinkTarget = linkTarget;
165     }
166
167     /**
168      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
169      */

170     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
171
172         // fill the parameter values in the get/set methods
173
fillParamValues(request);
174         
175         // check the required permissions to edit the pointer
176
if (! checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
177             // no write permissions for the resource, set cancel action to close dialog
178
setParamAction(DIALOG_CANCEL);
179         }
180         
181         // set the dialog type
182
setParamDialogtype(DIALOG_TYPE);
183         // set the action for the JSP switch
184
if (DIALOG_OK.equals(getParamAction())) {
185             // ok button pressed, change link target
186
setAction(ACTION_OK);
187         } else if (DIALOG_CANCEL.equals(getParamAction())) {
188             // cancel button pressed
189
setAction(ACTION_CANCEL);
190         } else {
191             // first call of dialog
192
setAction(ACTION_DEFAULT);
193             // build title for change link target dialog
194
setParamTitle(key(Messages.GUI_CHLINK_1, new Object JavaDoc[] {CmsResource.getName(getParamResource())}));
195         }
196     }
197
198 }
199
Popular Tags