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.loader;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsPropertyDefinition;
032import org.opencms.file.CmsResource;
033import org.opencms.main.CmsException;
034import org.opencms.main.OpenCms;
035import org.opencms.xml.containerpage.CmsXmlContainerPage;
036import org.opencms.xml.containerpage.CmsXmlContainerPageFactory;
037
038import java.io.IOException;
039
040import javax.servlet.ServletException;
041import javax.servlet.ServletRequest;
042import javax.servlet.http.HttpServletRequest;
043import javax.servlet.http.HttpServletResponse;
044
045/**
046 * OpenCms loader for resources of type <code>{@link org.opencms.file.types.CmsResourceTypeXmlContainerPage}</code>.<p>
047 *
048 * It is just a xml-content loader with template capabilities.<p>
049 *
050 * @since 7.6
051 */
052public class CmsXmlContainerPageLoader extends CmsXmlContentLoader {
053
054    /** The id of this loader. */
055    public static final int CONTAINER_PAGE_RESOURCE_LOADER_ID = 11;
056
057    /**
058     * Default constructor.<p>
059     */
060    public CmsXmlContainerPageLoader() {
061
062        // empty
063    }
064
065    /**
066     * @see org.opencms.loader.I_CmsResourceLoader#getLoaderId()
067     */
068    @Override
069    public int getLoaderId() {
070
071        return CONTAINER_PAGE_RESOURCE_LOADER_ID;
072    }
073
074    /**
075     * Returns a String describing this resource loader, which is (localized to the system default locale)
076     * <code>"The OpenCms default resource loader for container page"</code>.<p>
077     *
078     * @return a describing String for the ResourceLoader
079     */
080    @Override
081    public String getResourceLoaderInfo() {
082
083        return Messages.get().getBundle().key(Messages.GUI_LOADER_CONTAINERPAGE_DEFAULT_DESC_0);
084    }
085
086    /**
087     * @see org.opencms.loader.A_CmsXmlDocumentLoader#isUsableForTemplates()
088     */
089    @Override
090    public boolean isUsableForTemplates() {
091
092        return true;
093    }
094
095    /**
096     * @see org.opencms.loader.A_CmsXmlDocumentLoader#load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
097     */
098    @Override
099    public void load(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res)
100    throws ServletException, IOException, CmsException {
101
102        CmsTemplateLoaderFacade loaderFacade = OpenCms.getResourceManager().getTemplateLoaderFacade(
103            cms,
104            req,
105            resource,
106            getTemplatePropertyDefinition());
107        setTemplateRequestAttributes(loaderFacade, req);
108        loaderFacade.getLoader().load(cms, loaderFacade.getLoaderStartResource(), req, res);
109    }
110
111    /**
112     * @see org.opencms.loader.A_CmsXmlDocumentLoader#getTemplatePropertyDefinition()
113     */
114    @Override
115    protected String getTemplatePropertyDefinition() {
116
117        return CmsPropertyDefinition.PROPERTY_TEMPLATE;
118    }
119
120    /**
121     * @see org.opencms.loader.A_CmsXmlDocumentLoader#unmarshalXmlDocument(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest)
122     */
123    @Override
124    protected CmsXmlContainerPage unmarshalXmlDocument(CmsObject cms, CmsResource resource, ServletRequest req)
125    throws CmsException {
126
127        return CmsXmlContainerPageFactory.unmarshal(cms, resource, req);
128    }
129}