001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.commons;
029
030import org.opencms.file.CmsPropertyDefinition;
031import org.opencms.jsp.CmsJspActionElement;
032import org.opencms.main.CmsException;
033import org.opencms.main.OpenCms;
034import org.opencms.util.CmsUUID;
035import org.opencms.widgets.CmsDisplayWidget;
036import org.opencms.workplace.CmsWidgetDialog;
037import org.opencms.workplace.CmsWidgetDialogParameter;
038import org.opencms.workplace.tools.CmsToolDialog;
039
040import java.util.ArrayList;
041
042import javax.servlet.http.HttpServletRequest;
043import javax.servlet.http.HttpServletResponse;
044import javax.servlet.jsp.PageContext;
045
046/**
047 * Dialog to edit new or existing user in the administration view.<p>
048 *
049 * @since 6.0.0
050 */
051public class CmsResourceInfoDialog extends CmsWidgetDialog {
052
053    /** localized messages Keys prefix. */
054    public static final String KEY_PREFIX = "resourceinfo";
055
056    /** Defines which pages are valid for this dialog. */
057    protected static final String[] PAGES = {"page1"};
058
059    /** The user object that is edited on this dialog. */
060    private String m_path;
061
062    /** Stores the value of the request parameter for the user id. */
063    private String m_title;
064
065    /**
066     * Public constructor with JSP action element.<p>
067     *
068     * @param jsp an initialized JSP action element
069     */
070    public CmsResourceInfoDialog(CmsJspActionElement jsp) {
071
072        super(jsp);
073    }
074
075    /**
076     * Public constructor with JSP variables.<p>
077     *
078     * @param context the JSP page context
079     * @param req the JSP request
080     * @param res the JSP response
081     */
082    public CmsResourceInfoDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
083
084        this(new CmsJspActionElement(context, req, res));
085    }
086
087    /**
088     * Commits the edited user to the db.<p>
089     */
090    @Override
091    public void actionCommit() {
092
093        // no saving is done
094        setCommitErrors(new ArrayList<Throwable>());
095    }
096
097    /**
098     * Returns the file.<p>
099     *
100     * @return the file
101     */
102    public String getPath() {
103
104        return m_path;
105    }
106
107    /**
108     * Returns the title.<p>
109     *
110     * @return the title
111     */
112    public String getTitle() {
113
114        return m_title;
115    }
116
117    /**
118     * Sets the file.<p>
119     *
120     * @param file the file to set
121     */
122    public void setPath(String file) {
123
124        m_path = file;
125    }
126
127    /**
128     * Sets the title.<p>
129     *
130     * @param title the title to set
131     */
132    public void setTitle(String title) {
133
134        m_title = title;
135    }
136
137    /**
138     * @see org.opencms.workplace.tools.CmsToolDialog#computeUpLevelLink()
139     */
140    @Override
141    protected String computeUpLevelLink() {
142
143        // if adminProject is set, go back to the project file list in the administration
144        String adminProject = getJsp().getRequest().getParameter(CmsToolDialog.PARAM_ADMIN_PROJECT);
145        if ((adminProject != null) && CmsUUID.isValidUUID(adminProject)) {
146            String upLevelLink = OpenCms.getLinkManager().substituteLink(
147                getCms(),
148                "/system/workplace/views/admin/admin-main.jsp")
149                + "?path=%2Fprojects%2Ffiles&action=initial&projectid="
150                + adminProject;
151            return upLevelLink;
152        } else {
153            return super.computeUpLevelLink();
154        }
155    }
156
157    /**
158     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
159     *
160     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
161     *
162     * @param dialog the dialog (page) to get the HTML for
163     * @return the dialog HTML for all defined widgets of the named dialog (page)
164     */
165    @Override
166    protected String createDialogHtml(String dialog) {
167
168        StringBuffer result = new StringBuffer(1024);
169
170        result.append(createWidgetTableStart());
171        // show error header once if there were validation errors
172        result.append(createWidgetErrorHeader());
173        // create the widgets for the first dialog page
174        result.append(dialogBlockStart(key(Messages.GUI_RESOURCE_INFO_0)));
175        result.append(createWidgetTableStart());
176        result.append(createDialogRowsHtml(0, 1));
177        result.append(createWidgetTableEnd());
178        result.append(dialogBlockEnd());
179
180        result.append(createWidgetTableEnd());
181        return result.toString();
182    }
183
184    /**
185     * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd()
186     */
187    @Override
188    protected String defaultActionHtmlEnd() {
189
190        return "";
191    }
192
193    /**
194     * Creates the list of widgets for this dialog.<p>
195     */
196    @Override
197    protected void defineWidgets() {
198
199        // initialize the user object to use for the dialog
200        initFileInfo();
201
202        setKeyPrefix(KEY_PREFIX);
203
204        addWidget(new CmsWidgetDialogParameter(this, "path", PAGES[0], new CmsDisplayWidget()));
205        addWidget(new CmsWidgetDialogParameter(this, "title", PAGES[0], new CmsDisplayWidget()));
206    }
207
208    /**
209     * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
210     */
211    @Override
212    protected String[] getPageArray() {
213
214        return PAGES;
215    }
216
217    /**
218     * Initializes the user object.<p>
219     */
220    protected void initFileInfo() {
221
222        try {
223            // edit an existing user, get the user object from db
224            m_path = getParamResource();
225            m_title = getCms().readPropertyObject(m_path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("-");
226        } catch (CmsException e) {
227            // should never happen
228        }
229    }
230}