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.administration;
029
030import org.opencms.i18n.CmsEncoder;
031import org.opencms.jsp.CmsJspActionElement;
032import org.opencms.workplace.CmsDialog;
033
034import java.util.Iterator;
035import java.util.Map;
036import java.util.Map.Entry;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import javax.servlet.jsp.JspWriter;
041import javax.servlet.jsp.PageContext;
042
043/**
044 * Workplace class for /system/workplace/views/admin/admin-editor.jsp .<p>
045 *
046 * @since 6.0.0
047 */
048public class CmsAdminEditorWrapper extends CmsDialog {
049
050    /**
051     * Public constructor with JSP action element.<p>
052     *
053     * @param jsp an initialized JSP action element
054     */
055    public CmsAdminEditorWrapper(CmsJspActionElement jsp) {
056
057        super(jsp);
058    }
059
060    /**
061     * Public constructor with JSP variables.<p>
062     *
063     * @param context the JSP page context
064     * @param req the JSP request
065     * @param res the JSP response
066     */
067    public CmsAdminEditorWrapper(PageContext context, HttpServletRequest req, HttpServletResponse res) {
068
069        this(new CmsJspActionElement(context, req, res));
070    }
071
072    /**
073     * Returns all parameters of the current workplace class
074     * as hidden field tags that can be inserted in a form.<p>
075     *
076     * @return all parameters of the current workplace class
077     * as hidden field tags that can be inserted in a html form
078     */
079    @Override
080    public String allParamsAsHidden() {
081
082        StringBuffer result = new StringBuffer(512);
083        Map<String, Object> params = allParamValues();
084        Iterator<Entry<String, Object>> i = params.entrySet().iterator();
085        while (i.hasNext()) {
086            Entry<String, Object> entry = i.next();
087            result.append("<input type=\"hidden\" name=\"");
088            result.append(entry.getKey());
089            result.append("\" value=\"");
090            String encoded = CmsEncoder.escapeXml(entry.getValue().toString());
091            result.append(encoded);
092            result.append("\">\n");
093        }
094        return result.toString();
095    }
096
097    /**
098     * Performs the dialog actions depending on the initialized action and displays the dialog form.<p>
099     *
100     * @throws Exception if writing to the JSP out fails
101     */
102    public void displayDialog() throws Exception {
103
104        initAdminTool();
105        getToolManager().setCurrentToolPath(this, getParentPath());
106
107        JspWriter out = getJsp().getJspContext().getOut();
108        out.print(htmlStart());
109        out.print(bodyStart(null));
110        out.print("<form name='editor' method='post' target='_top' action='");
111        out.print(getJsp().link("/system/workplace/editors/editor.jsp"));
112        out.print("'>\n");
113        out.print(allParamsAsHidden());
114        out.print("</form>\n");
115        out.print("<script>\n");
116        out.print("document.forms['editor'].submit();\n");
117        out.print("</script>\n");
118        out.print(dialogContentStart(getParamTitle()));
119        out.print(dialogContentEnd());
120        out.print(dialogEnd());
121        out.print(bodyEnd());
122        out.print(htmlEnd());
123    }
124}