KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsCopyToProject.java,v $
3  * Date : $Date: 2006/03/28 07:53:22 $
4  * Version: $Revision: 1.9 $
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.CmsResource;
35 import org.opencms.file.CmsResourceFilter;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWorkplaceSettings;
41
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.http.HttpServletResponse JavaDoc;
47 import javax.servlet.jsp.JspException JavaDoc;
48 import javax.servlet.jsp.PageContext JavaDoc;
49
50 import org.apache.commons.logging.Log;
51
52 /**
53  * Provides methods for the copy to project dialog.<p>
54  *
55  * The following files use this class:
56  * <ul>
57  * <li>/commons/copytoproject.jsp
58  * </ul>
59  * <p>
60  *
61  * @author Andreas Zahner
62  *
63  * @version $Revision: 1.9 $
64  *
65  * @since 6.0.0
66  */

67 public class CmsCopyToProject extends CmsDialog {
68
69     /** Value for the action: copy the resource to current project. */
70     public static final int ACTION_COPYTOPROJECT = 100;
71
72     /** The dialog type. */
73     public static final String JavaDoc DIALOG_TYPE = "copytoproject";
74
75     /** The log object for this class. */
76     private static final Log LOG = CmsLog.getLog(CmsCopyToProject.class);
77
78     /**
79      * Public constructor with JSP action element.<p>
80      *
81      * @param jsp an initialized JSP action element
82      */

83     public CmsCopyToProject(CmsJspActionElement jsp) {
84
85         super(jsp);
86     }
87
88     /**
89      * Public constructor with JSP variables.<p>
90      *
91      * @param context the JSP page context
92      * @param req the JSP request
93      * @param res the JSP response
94      */

95     public CmsCopyToProject(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
96
97         this(new CmsJspActionElement(context, req, res));
98     }
99
100     /**
101      * Performs the copy to project action, will be called by the JSP page.<p>
102      *
103      * @throws JspException if problems including sub-elements occur
104      */

105     public void actionCopyToProject() throws JspException JavaDoc {
106
107         // save initialized instance of this class in request attribute for included sub-elements
108
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
109         try {
110             // copy the resource to the current project
111
getCms().copyResourceToProject(getParamResource());
112             // close the dialog
113
actionCloseDialog();
114         } catch (Throwable JavaDoc e) {
115             // error copying resource to project, include error page
116
includeErrorpage(this, e);
117         }
118     }
119
120     /**
121      * Returns the HTML containing project information and confirmation question for the JSP.<p>
122      *
123      * @return the HTML containing project information and confirmation question for the JSP
124      */

125     public String JavaDoc buildProjectInformation() {
126
127         StringBuffer JavaDoc result = new StringBuffer JavaDoc(32);
128
129         try {
130             String JavaDoc[] localizedObject = new String JavaDoc[] {getCms().getRequestContext().currentProject().getName()};
131             List JavaDoc resources = getCms().readProjectResources(getCms().getRequestContext().currentProject());
132             Iterator JavaDoc i = resources.iterator();
133             result.append(dialogBlockStart(key(Messages.GUI_COPYTOPROJECT_RESOURCES_0)));
134             if (resources.size() > 0) {
135                 // at least one resource in current project
136
result.append(key(Messages.GUI_COPYTOPROJECT_PART_1, localizedObject));
137                 result.append("<ul style=\"margin-top: 3px; margin-bottom: 3px;\">\n");
138                 String JavaDoc siteRoot = getCms().getRequestContext().getSiteRoot();
139                 while (i.hasNext()) {
140                     // create resource list
141
String JavaDoc resName = (String JavaDoc)i.next();
142                     if (resName.startsWith(siteRoot)) {
143                         // remove current site root from resource name
144
resName = resName.substring(siteRoot.length());
145                     }
146                     result.append("\t<li>");
147                     result.append(resName);
148                     result.append("</li>\n");
149                 }
150                 result.append("</ul>\n");
151             } else {
152                 // no resources in current project
153
result.append(key(Messages.GUI_COPYTOPROJECT_NOPART_1, localizedObject));
154             }
155             result.append(dialogBlockEnd());
156             result.append(dialogSpacer());
157         } catch (CmsException e) {
158             // error reading project resources, should not happen
159
if (LOG.isInfoEnabled()) {
160                 LOG.info(e.getLocalizedMessage());
161             }
162         }
163
164         // determine resource name to show
165
String JavaDoc resName = getParamResource();
166         try {
167             CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
168             if (res.isFolder() && !resName.endsWith("/")) {
169                 resName += "/";
170             }
171         } catch (CmsException e) {
172             // error reading resource, should not happen
173
if (LOG.isInfoEnabled()) {
174                 LOG.info(e.getLocalizedMessage());
175             }
176         }
177         // show confirmation question
178
String JavaDoc[] localizedObject = new String JavaDoc[] {resName, getCms().getRequestContext().currentProject().getName()};
179         result.append(key(Messages.GUI_COPYTOPROJECT_PROJECT_CONFIRMATION_2, localizedObject));
180         return result.toString();
181     }
182
183     /**
184      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
185      */

186     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
187
188         // fill the parameter values in the get/set methods
189
fillParamValues(request);
190         // set the dialog type
191
setParamDialogtype(DIALOG_TYPE);
192         // set the action for the JSP switch
193
if (DIALOG_TYPE.equals(getParamAction())) {
194             setAction(ACTION_COPYTOPROJECT);
195         } else if (DIALOG_CANCEL.equals(getParamAction())) {
196             setAction(ACTION_CANCEL);
197         } else {
198             setAction(ACTION_DEFAULT);
199             // build title for copy to project dialog
200
setParamTitle(key(Messages.GUI_COPYTOPROJECT_TITLE_0));
201         }
202     }
203
204 }
Popular Tags