All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.jsp.util.CmsJspContentLoadBean Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.jsp.util;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Allows JSP access to the results of a <cms:contentload ... > operation using the JSTL and EL.

* * @since 7.0.2 * * @see org.opencms.jsp.CmsJspTagContentLoad * @see CmsJspContentAccessBean */ public class CmsJspContentLoadBean { /** The OpenCms context of the current user. */ protected CmsObject m_cms; /** The List of results form the content loader. */ protected List m_content; /** The selected locale for accessing entries from the XML content. */ protected Locale m_locale; /** * No argument constructor, required for a JavaBean.

* * You must call {@link #init(CmsObject, Locale, List)} and provide the * required values when you use this constructor.

* * @see #init(CmsObject, Locale, List) */ public CmsJspContentLoadBean() { // must call init() manually later } /** * Creates a new context bean using the OpenCms context of the current user.

* * The current request context locale is used.

* * @param cms the OpenCms context of the current user * @param content the content to access, must contain Object of type {@link CmsResource} */ public CmsJspContentLoadBean(CmsObject cms, List content) { this(cms, cms.getRequestContext().getLocale(), content); } /** * Creates a new context bean using the OpenCms context of the current user with the given locale.

* * @param cms the OpenCms context of the current user * @param locale the Locale to use when accessing the content * @param content the content to access, must contain Object of type {@link CmsResource} */ public CmsJspContentLoadBean(CmsObject cms, Locale locale, List content) { init(cms, locale, content); } /** * Converts a list of {@link CmsResource} objects to a list of {@link CmsJspContentAccessBean} objects, * using the current request context locale.

* * @param cms the current OpenCms user context * @param resources a list of of {@link CmsResource} objects that should be converted * * @return a list of {@link CmsJspContentAccessBean} objects created from the given {@link CmsResource} objects */ public static List convertResourceList(CmsObject cms, List resources) { return convertResourceList(cms, cms.getRequestContext().getLocale(), resources); } /** * Converts a list of {@link CmsResource} objects to a list of {@link CmsJspContentAccessBean} objects, * using the given locale.

* * @param cms the current OpenCms user context * @param locale the default locale to use when accessing the content * @param resources a list of of {@link CmsResource} objects that should be converted * * @return a list of {@link CmsJspContentAccessBean} objects created from the given {@link CmsResource} objects */ public static List convertResourceList( CmsObject cms, Locale locale, List resources) { List result = new ArrayList(resources.size()); for (int i = 0, size = resources.size(); i < size; i++) { CmsResource res = resources.get(i); result.add(new CmsJspContentAccessBean(cms, locale, res)); } return result; } /** * Returns the OpenCms user context this bean was initialized with.

* * @return the OpenCms user context this bean was initialized with */ public CmsObject getCmsObject() { return m_cms; } /** * Returns a List of {@link CmsJspContentAccessBean} instances, which have been wrapped around * the original {@link CmsResource} instances of the collector result.

* * @return a List of {@link CmsJspContentAccessBean} instances, which have been wrapped around * the original {@link CmsResource} instances of the collector result.

*/ public List getContent() { return m_content; } /** * Returns the Locale this bean was initialized with.

* * @return the locale this bean was initialized with */ public Locale getLocale() { return m_locale; } /** * Initialize this instance.

* * @param cms the OpenCms context of the current user * @param locale the Locale to use when accessing the content * @param content the content to access, must contain Object of type {@link CmsResource} */ public void init(CmsObject cms, Locale locale, List content) { m_cms = cms; m_locale = locale; m_content = convertResourceList(m_cms, m_locale, content); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy