KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListOpenResourceAction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListOpenResourceAction.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.3 $
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.list;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsResourceFilter;
36 import org.opencms.i18n.CmsMessageContainer;
37 import org.opencms.site.CmsSiteManager;
38 import org.opencms.util.CmsStringUtil;
39
40 /**
41  * Opens the selected resource in a new window.<p>
42  *
43  * Be sure your list updates the cms context, overriding the {@link org.opencms.workplace.list.A_CmsListDialog#getList()} method, like:
44  * <pre>
45  * // assure we have the right cms
46  * CmsHtmlList list = super.getList();
47  * if (list != null) {
48  * CmsListColumnDefinition col = list.getMetadata().getColumnDefinition(LIST_COLUMN_NAME);
49  * if (col != null) {
50  * ((CmsListOpenResourceAction)col.getDefaultAction(LIST_DEFACTION_OPEN)).setCms(getCms());
51  * }
52  * }
53  * return list;
54  * </pre>
55  *
56  * @author Michael Moossen
57  *
58  * @version $Revision: 1.3 $
59  *
60  * @since 6.0.0
61  */

62 public class CmsListOpenResourceAction extends A_CmsListDefaultJsAction {
63
64     /** Cms context. */
65     private CmsObject m_cms;
66
67     /** Id of the column with the resource root path. */
68     private final String JavaDoc m_resColumnPathId;
69
70     /**
71      * Default Constructor.<p>
72      *
73      * @param id the unique id
74      * @param cms the cms context
75      * @param resColumnPathId the id of the column with the resource root path
76      */

77     public CmsListOpenResourceAction(String JavaDoc id, CmsObject cms, String JavaDoc resColumnPathId) {
78
79         super(id);
80         m_resColumnPathId = resColumnPathId;
81         m_cms = cms;
82         setName(Messages.get().container(Messages.GUI_OPENRESOURCE_ACTION_NAME_0));
83         setHelpText(Messages.get().container(Messages.GUI_OPENRESOURCE_ACTION_HELP_0));
84     }
85
86     /**
87      * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getHelpText()
88      */

89     public CmsMessageContainer getHelpText() {
90
91         if (isEnabled()) {
92             return super.getHelpText();
93         }
94         return Messages.get().container(Messages.GUI_OPENRESOURCE_ACTION_DISABLED_HELP_0);
95     }
96
97     /**
98      * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isEnabled()
99      */

100     public boolean isEnabled() {
101
102         if (getResourceName() != null) {
103             return super.isEnabled();
104         }
105         return false;
106     }
107
108     /**
109      * @see org.opencms.workplace.list.A_CmsListDefaultJsAction#jsCode()
110      */

111     public String JavaDoc jsCode() {
112
113         StringBuffer JavaDoc jsCode = new StringBuffer JavaDoc(256);
114         jsCode.append("javascript:top.openwinfull('");
115         jsCode.append(getResourceName());
116         jsCode.append("')");
117         return jsCode.toString();
118     }
119
120     /**
121      * Sets the cms context.<p>
122      *
123      * @param cms the cms context to set
124      */

125     public void setCms(CmsObject cms) {
126
127         m_cms = cms;
128     }
129
130     /**
131      * Returns the most possible right resource name.<p>
132      *
133      * @return the most possible right resource name
134      */

135     private String JavaDoc getResourceName() {
136
137         String JavaDoc resource = getItem().get(m_resColumnPathId).toString();
138         if (!m_cms.existsResource(resource, CmsResourceFilter.DEFAULT)) {
139             String JavaDoc siteRoot = CmsSiteManager.getSiteRoot(resource);
140             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) {
141                 resource = resource.substring(siteRoot.length());
142             }
143             if (!m_cms.existsResource(resource, CmsResourceFilter.DEFAULT)) {
144                 resource = null;
145             }
146         }
147         return resource;
148     }
149 }
Popular Tags