001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH (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, 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.gwt;
029
030import org.opencms.i18n.CmsLocaleManager;
031import org.opencms.main.OpenCms;
032import org.opencms.util.CmsStringUtil;
033
034import java.io.IOException;
035import java.util.Locale;
036
037import javax.servlet.ServletRequest;
038import javax.servlet.ServletResponse;
039
040/**
041 * Exports the register client messages into a single JavaScript resource.<p>
042 */
043public class CmsMessagesService extends CmsGwtService {
044
045    /** The serial version id. */
046    private static final long serialVersionUID = 3072608993796119377L;
047
048    /** The client messages to export. */
049    private static final I_CmsClientMessageBundle[] CLIENT_MESSGAE_BUNDLES = new I_CmsClientMessageBundle[] {
050        ClientMessages.get(),
051        org.opencms.ade.containerpage.ClientMessages.get(),
052        org.opencms.ade.contenteditor.ClientMessages.get(),
053        org.opencms.ade.galleries.ClientMessages.get(),
054        org.opencms.ade.postupload.ClientMessages.get(),
055        org.opencms.ade.publish.ClientMessages.get(),
056        org.opencms.ade.sitemap.ClientMessages.get(),
057        org.opencms.ade.upload.ClientMessages.get(),
058        org.opencms.gwt.seo.ClientMessages.get()};
059
060    /**
061     * @see org.opencms.gwt.CmsGwtService#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
062     */
063    @Override
064    public void service(ServletRequest request, ServletResponse response) throws IOException {
065
066        try {
067            response.setCharacterEncoding(request.getCharacterEncoding());
068            response.setContentType("text/javascript");
069            Locale locale;
070            String localeString = request.getParameter(CmsLocaleManager.PARAMETER_LOCALE);
071            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(localeString)) {
072                locale = CmsLocaleManager.getLocale(localeString);
073            } else {
074                locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject());
075            }
076            for (int i = 0; i < CLIENT_MESSGAE_BUNDLES.length; i++) {
077                response.getWriter().append(CLIENT_MESSGAE_BUNDLES[i].export(locale, false)).append("\n");
078            }
079            response.getWriter().flush();
080        } finally {
081            clearThreadStorage();
082        }
083    }
084}