001 /*
002 *
003 * $Revision: 15202 $ $Date: 2009-05-15 17:00:44 +0200 (Fri, 15 May 2009) $
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.frontend.servlets;
025
026 import java.io.IOException;
027
028 import javax.servlet.ServletException;
029
030 import org.jdom.Document;
031 import org.mycore.common.MCRConfiguration;
032 import org.mycore.common.MCRSessionMgr;
033
034 /**
035 * This servlet provides some common methods for the editors of the user
036 * management of the mycore system.
037 *
038 * @author Detlev Degenhardt
039 * @version $Revision: 15202 $ $Date: 2009-05-15 17:00:44 +0200 (Fri, 15 May 2009) $
040 */
041 public class MCRUserAdminGUICommons extends MCRServlet {
042
043 private static final long serialVersionUID = 1L;
044
045 protected String pageDir = null;
046
047 protected String noPrivsPage = null;
048
049 protected String cancelPage = null;
050
051 protected String okPage = null;
052
053 /** Initialisation of the servlet */
054 public void init() throws ServletException {
055 super.init();
056 pageDir = MCRConfiguration.instance().getString("MCR.Useradmin.PageDir", "");
057 noPrivsPage = pageDir + MCRConfiguration.instance().getString("MCR.Useradmin.Page.ErrorPrivileges", "useradmin_error_privileges.xml");
058 cancelPage = pageDir + MCRConfiguration.instance().getString("MCR.Useradmin.Page.Cancel", "useradmin_cancel.xml");
059 okPage = pageDir + MCRConfiguration.instance().getString("MCR.Useradmin.Page.OK", "useradmin_ok.xml");
060 }
061
062 /**
063 * This method simply redirects to a page providing information that the
064 * privileges for a use case are not sufficient.
065 *
066 * @param job
067 * The MCRServletJob instance
068 */
069 protected void showNoPrivsPage(MCRServletJob job) throws IOException {
070 job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(getBaseURL() + noPrivsPage));
071
072 return;
073 }
074
075 /**
076 * This method simply redirects to a page providing information that the
077 * current use case was fulfilled successfully.
078 *
079 * @param job
080 * The MCRServletJob instance
081 */
082 protected void showOkPage(MCRServletJob job) throws IOException {
083 job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(getBaseURL() + okPage));
084
085 return;
086 }
087
088 /**
089 * Gather information about the XML document to be shown and the
090 * corresponding XSLT stylesheet and redirect the request to the
091 * LayoutService
092 *
093 * @param job
094 * The MCRServletJob instance
095 * @param styleSheet
096 * String value to select the correct XSL stylesheet
097 * @param jdomDoc
098 * The XML representation to be presented by the LayoutService
099 * @param useStrict
100 * If true, the parameter styleSheet must be used directly as
101 * name of a stylesheet when forwarding to the MCRLayoutService.
102 * If false, styleSheet will be appended by the signature of the
103 * current language. useStrict=true is used when not using a
104 * stylesheet at all because one simply needs the raw XML output.
105 *
106 * @throws ServletException
107 * for errors from the servlet engine.
108 * @throws IOException
109 * for java I/O errors.
110 */
111 protected void doLayout(MCRServletJob job, String styleSheet, Document jdomDoc, boolean useStrict) throws IOException {
112 String language = MCRSessionMgr.getCurrentSession().getCurrentLanguage();
113
114 if (!useStrict) {
115 styleSheet = styleSheet + "-" + language;
116 }
117
118 job.getRequest().getSession().setAttribute("mycore.language", language);
119 job.getRequest().setAttribute("XSL.Style", styleSheet);
120 getLayoutService().doLayout(job.getRequest(), job.getResponse(), jdomDoc);
121 }
122 }