001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.jsp;
029
030import java.util.Locale;
031
032import jakarta.servlet.http.HttpServletRequest;
033import jakarta.servlet.http.HttpServletResponse;
034import jakarta.servlet.jsp.JspException;
035import jakarta.servlet.jsp.PageContext;
036
037/**
038 * Provides access to XML content tag functions from scriptlet code.<p>
039 *
040 * Otherwise provides all functions from the parent class <code>{@link org.opencms.jsp.CmsJspActionElement}</code>.<p>
041 *
042 * @since 6.2.0
043 */
044public class CmsJspXmlContentBean extends CmsJspActionElement {
045
046    /**
047     * Empty constructor, required for every JavaBean.
048     *
049     * @see CmsJspActionElement#CmsJspActionElement()
050     */
051    public CmsJspXmlContentBean() {
052
053        super();
054    }
055
056    /**
057     * Constructor, with parameters.
058     *
059     * @param context the JSP page context object
060     * @param req the JSP request
061     * @param res the JSP response
062     *
063     * @see CmsJspActionElement#CmsJspActionElement(PageContext, HttpServletRequest, HttpServletResponse)
064     */
065    public CmsJspXmlContentBean(PageContext context, HttpServletRequest req, HttpServletResponse res) {
066
067        super(context, req, res);
068    }
069
070    /**
071     * Loads a set of <code>{@link org.opencms.xml.I_CmsXmlDocument}</code>, same as
072     * using the <code>&lt;cms:contentload collector="***" param="***" editable="***" /&gt;</code> tag.<p>
073     *
074     * The locale for accessing the content is read form the current OpenCms users request context.<p>
075     *
076     * @param collectorName the collector name to use
077     * @param collectorParam the parameters for the collector
078     * @param editable indicates if "direct edit" support is required (will insert additional HTML)
079     *
080     * @return an XML content container loaded with the selected content
081     *
082     * @throws JspException in case something goes wrong
083     */
084    public I_CmsXmlContentContainer contentload(String collectorName, String collectorParam, boolean editable)
085    throws JspException {
086
087        return contentload(collectorName, collectorParam, getRequestContext().getLocale(), editable);
088    }
089
090    /**
091     * Loads a set of <code>{@link org.opencms.xml.I_CmsXmlDocument}</code>, same as
092     * using the <code>&lt;cms:contentload collector="***" param="***" locale="***" editable="***" /&gt;</code> tag.<p>
093     *
094     * @param collectorName the collector name to use
095     * @param collectorParam the parameters for the collector
096     * @param locale the locale to use to access the content
097     * @param editable indicates if "direct edit" support is required (will insert additional HTML)
098     *
099     * @return an XML content container loaded with the selected content
100     *
101     * @throws JspException in case something goes wrong
102     */
103    public I_CmsXmlContentContainer contentload(
104        String collectorName,
105        String collectorParam,
106        Locale locale,
107        boolean editable)
108    throws JspException {
109
110        return new CmsJspTagContentLoad(null, getJspContext(), collectorName, collectorParam, locale, editable);
111    }
112
113    /**
114     * Loads a set of <code>{@link org.opencms.xml.I_CmsXmlDocument}</code>, same as
115     * using the <code>&lt;cms:contentload collector="***" param="***" locale="***" editable="***" /&gt;</code> tag.<p>
116     *
117     * @param collectorName the collector name to use
118     * @param collectorParam the collector param to use
119     * @param pageIndex the display page index (may contain macros)
120     * @param pageSize the display page size (may contain macros)
121     * @param locale the locale to use to access the content
122     * @param editable indicates if "direct edit" support is required (will insert additional HTML)
123     *
124     * @return an XML content container loaded with the selected content
125     *
126     * @throws JspException in case something goes wrong
127     */
128    public I_CmsXmlContentContainer contentload(
129        String collectorName,
130        String collectorParam,
131        String pageIndex,
132        String pageSize,
133        Locale locale,
134        boolean editable)
135    throws JspException {
136
137        return new CmsJspTagContentLoad(
138            null,
139            getJspContext(),
140            collectorName,
141            collectorParam,
142            pageIndex,
143            pageSize,
144            locale,
145            editable);
146    }
147
148    /**
149     * Enables looping over a list of element values in the given parent container, same as
150     * using the <code>&lt;cms:contentloop element="***" /&gt;</code> tag.<p>
151     *
152     * @param container the XML content container to read the content from
153     * @param element the element to loop over
154     *
155     * @return an XML content container to be used to loop over the selected element values in the parent container
156     */
157    public I_CmsXmlContentContainer contentloop(I_CmsXmlContentContainer container, String element) {
158
159        return new CmsJspTagContentLoop(container, element);
160    }
161
162    /**
163     * Returns the currently looped content element String value from the given XML content container, same as
164     * using the <code>&lt;cms:contentshow /&gt;</code> tag.<p>
165     *
166     * This is to be used with a container initialized by <code>{@link #contentloop(I_CmsXmlContentContainer, String)}</code>,
167     * in this case the element name is already set by the content loop container.<p>
168     *
169     * The locale for accessing the content is read form the current OpenCms users request context.<p>
170     *
171     * @param container the XML content container to read the content from
172     *
173     * @return the selected content element String value from the given XML content container
174     */
175    public String contentshow(I_CmsXmlContentContainer container) {
176
177        return contentshow(container, null, null);
178    }
179
180    /**
181     * Returns the selected content element String value from the given XML content container, same as
182     * using the <code>&lt;cms:contentshow element="***" /&gt;</code> tag.<p>
183     *
184     * The locale for accessing the content is read form the current OpenCms users request context.<p>
185     *
186     * @param container the XML content container to read the content from
187     * @param element the element to show
188     *
189     * @return the selected content element String value from the given XML content container
190     */
191    public String contentshow(I_CmsXmlContentContainer container, String element) {
192
193        return contentshow(container, element, null);
194    }
195
196    /**
197     * Returns the selected content element String value from the given XML content container, same as
198     * using the <code>&lt;cms:contentshow element="***" locale="***" /&gt;</code> tag.<p>
199     *
200     * @param container the XML content container to read the content from
201     * @param element the element to show
202     * @param locale the locale to read the element from
203     *
204     * @return the selected content element String value from the given XML content container
205     */
206    public String contentshow(I_CmsXmlContentContainer container, String element, Locale locale) {
207
208        return CmsJspTagContentShow.contentShowTagAction(container, getJspContext(), element, locale, false);
209    }
210}