org.opencms.jsp.util.CmsJspVfsAccessBean Maven / Gradle / Ivy
Show all versions of opencms-test Show documentation
/*
* 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.CmsProject;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.file.types.CmsResourceTypeXmlContent;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsLocaleGroup;
import org.opencms.jsp.CmsJspResourceWrapper;
import org.opencms.jsp.util.CmsJspValueTransformers.CmsLocalePropertyLoaderTransformer;
import org.opencms.jsp.util.CmsJspValueTransformers.CmsPropertyLoaderTransformer;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.util.CmsCollectionsGenericWrapper;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.collections.Transformer;
import org.apache.commons.logging.Log;
/**
* Provides utility methods that allow convenient access to the OpenCms VFS,
* indented to be used from a JSP with the JSTL or EL.
*
* @since 7.0.2
*
* @see CmsJspContentAccessBean
*/
public final class CmsJspVfsAccessBean {
/**
* Transformer that loads a resource from the OpenCms VFS,
* the input is used as String for the resource name to read.
*/
public class CmsAvailableLocaleLoaderTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
List result;
// read the available locales
result = OpenCms.getLocaleManager().getAvailableLocales(getCmsObject(), String.valueOf(input));
return result;
}
}
/**
* Provides Booleans that indicate if a specified resource exists in the OpenCms VFS,
* the input is used as String for the resource name to read.
*/
public class CmsExistsResourceTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
return Boolean.valueOf(getReadResource().get(input) != null);
}
}
/**
* Provides Booleans that indicate if a specified resource exists in the OpenCms VFS
* and is of type XML content or XML page,
* the input is used as String for the resource name to read.
*/
public class CmsExistsXmlTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
// first read the resource using the lazy map
CmsResource resource = getReadResource().get(input);
return Boolean.valueOf(
(resource != null)
&& (CmsResourceTypeXmlPage.isXmlPage(resource)
|| CmsResourceTypeXmlContent.isXmlContent(resource)));
}
}
/**
* Transformer that loads a resource permission from the OpenCms VFS,
* the input is used as String for the resource name to read the permissions for.
*/
public class CmsPermissionsLoaderTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
CmsPermissionSet result;
try {
// read the requested resource permissions
result = getCmsObject().getPermissions((String)input);
} catch (CmsException e) {
// unable to read resource, return null
result = null;
}
return result;
}
}
/**
* Transformer that a properties of a resource from the OpenCms VFS,
* the input is used as String for the property name to read.
*/
public class CmsPropertyLoaderSingleTransformer implements Transformer {
/** The resource where the properties are read from. */
private CmsResource m_resource;
/** Indicates if properties should be searched when loaded. */
private boolean m_search;
/**
* Creates a new property loading Transformer.
*
* @param resource the resource where the properties are read from
* @param search indicates if properties should be searched when loaded
*/
public CmsPropertyLoaderSingleTransformer(CmsResource resource, boolean search) {
m_resource = resource;
m_search = search;
}
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
String result;
try {
// read the properties of the requested resource
result = getCmsObject().readPropertyObject(m_resource, String.valueOf(input), m_search).getValue();
} catch (CmsException e) {
// in case of any error we assume the property does not exist
result = null;
}
return result;
}
}
/**
* Transformer that loads a resource from the OpenCms VFS,
* the input is used as String for the resource name to read.
*/
public class CmsResourceLoaderTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
CmsResource result;
try {
// read the requested resource
result = CmsJspElFunctions.convertResource(getCmsObject(), input);
} catch (CmsException e) {
// unable to read resource, return null
result = null;
}
return result;
}
}
/**
* Transformer that loads properties of a resource from the OpenCms VFS with another lazy map,
* the input is used as String for the resource name to read.
*/
public class CmsResourceLocalePropertyLoaderTransformer implements Transformer {
/** Indicates if properties should be searched when loaded. */
private boolean m_search;
/**
* Creates a new property loading Transformer.
*
* @param search indicates if properties should be searched when loaded
*/
public CmsResourceLocalePropertyLoaderTransformer(boolean search) {
m_search = search;
}
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
Map result = null;
// first read the resource using the lazy map
CmsResource resource = getReadResource().get(input);
if (resource != null) {
result = CmsCollectionsGenericWrapper.createLazyMap(
new CmsLocalePropertyLoaderTransformer(getCmsObject(), resource, m_search));
}
// result may still be null
return (result == null) ? Collections.EMPTY_MAP : result;
}
}
/**
* Transformer that loads properties of a resource from the OpenCms VFS with another lazy map,
* the input is used as String for the resource name to read.
*/
public class CmsResourcePropertyLoaderTransformer implements Transformer {
/** Indicates if properties should be searched when loaded. */
private boolean m_search;
/**
* Creates a new property loading Transformer.
*
* @param search indicates if properties should be searched when loaded
*/
public CmsResourcePropertyLoaderTransformer(boolean search) {
m_search = search;
}
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
Map result = null;
// first read the resource using the lazy map
CmsResource resource = getReadResource().get(input);
if (resource != null) {
result = CmsCollectionsGenericWrapper.createLazyMap(
new CmsPropertyLoaderTransformer(getCmsObject(), resource, m_search));
}
// result may still be null
return (result == null) ? Collections.EMPTY_MAP : result;
}
}
/**
* Transformer that calculates links to resources in the OpenCms VFS,
* the input is used as String for the resource name to use as link target.
*
* This is using the same logic as
* {@link org.opencms.jsp.CmsJspTagLink#linkTagAction(String, javax.servlet.ServletRequest)}.
*/
public class CmsVfsLinkTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
return OpenCms.getLinkManager().substituteLink(
getCmsObject(),
CmsLinkManager.getAbsoluteUri(String.valueOf(input), getCmsObject().getRequestContext().getUri()));
}
}
/**
* Provides XML content access beans for VFS resources.
*/
public class CmsXmlContentAccessTransformer implements Transformer {
/**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/
public Object transform(Object input) {
CmsJspContentAccessBean result = null;
// first read the resource using the lazy map
CmsResource resource = getReadResource().get(input);
if ((resource != null)
&& (CmsResourceTypeXmlPage.isXmlPage(resource) || CmsResourceTypeXmlContent.isXmlContent(resource))) {
// make sure we have a resource that really is an XML content
result = new CmsJspContentAccessBean(getCmsObject(), resource);
}
return result;
}
}
/** Request context attribute for indicating the model file for a create resource operation. */
public static final String ATTRIBUTE_VFS_ACCESS_BEAN = CmsJspVfsAccessBean.class.getName() + ".VFS_ACCESS_BEAN";
/** Logger instance for this class. */
private static final Log LOG = CmsLog.getLog(CmsJspVfsAccessBean.class);
/** The OpenCms context of the current user. */
protected CmsObject m_cms;
/** Contains booleans that indicate if a resource exists in the VFS. */
private Map m_existsResource;
/** Contains booleans that indicate if a resource exists and is an XML content. */
private Map m_existsXml;
/** Links calculated for the OpenCms VFS. */
private Map m_links;
/** Resource permissions loaded from the OpenCms VFS. */
private Map m_permissions;
/** Properties loaded from the OpenCms VFS. */
private Map> m_properties;
/** Properties loaded locale specific from the OpenCms VFS. */
private Map>> m_propertiesLocale;
/** Properties loaded from the OpenCms VFS with search. */
private Map> m_propertiesSearch;
/** Properties loaded locale specific from the OpenCms VFS with search. */
private Map>> m_propertiesSearchLocale;
/** Available locales as determined by the {@link org.opencms.i18n.CmsLocaleManager} */
private Map> m_availableLocales;
/** Resources loaded from the OpenCms VFS. */
private Map m_resources;
/** XML contents read from the VFS. */
private Map m_xmlContent;
/**
* Creates a new context bean using the OpenCms context of the current user.
*
* @param cms the OpenCms context of the current user
*/
private CmsJspVfsAccessBean(CmsObject cms) {
m_cms = cms;
}
/**
* Creates a new instance of the JSP VFS access utility bean.
*
* To prevent multiple creations of the bean during a request, the OpenCms request context
* attributes are used to cache the created VFS access utility bean.
*
* @param cms the current OpenCms user context
*
* @return a new instance of the JSP VFS access utility bean
*/
public static CmsJspVfsAccessBean create(CmsObject cms) {
CmsJspVfsAccessBean result;
Object attribute = cms.getRequestContext().getAttribute(ATTRIBUTE_VFS_ACCESS_BEAN);
if (attribute != null) {
result = (CmsJspVfsAccessBean)attribute;
} else {
result = new CmsJspVfsAccessBean(cms);
cms.getRequestContext().setAttribute(ATTRIBUTE_VFS_ACCESS_BEAN, result);
}
return result;
}
/**
* Returns a lazily generated map from site paths of resources to the available locales for the resource.
*
* @return a lazily generated map from site paths of resources to the available locales for the resource.
*/
public Map> getAvailableLocales() {
if (m_availableLocales == null) {
// create lazy map only on demand
m_availableLocales = CmsCollectionsGenericWrapper.createLazyMap(new CmsAvailableLocaleLoaderTransformer());
}
return m_availableLocales;
}
/**
* 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;
}
/**
* Short form for {@link #getRequestContext()}.
*
* Usage example on a JSP with the EL:
* The current URI is: ${cms:vfs(pageContext).context.uri}
*
*
* @return the OpenCms request context of the current user this bean was initialized with
*
* @see #getRequestContext()
*/
public CmsRequestContext getContext() {
return getRequestContext();
}
/**
* Returns the current project from the context.
*
* Usage example on a JSP with the EL:
* The current project name is: ${cms:vfs(pageContext).currentProject.name}
*
*
* @return the current project
*/
public CmsProject getCurrentProject() {
return m_cms.getRequestContext().getCurrentProject();
}
/**
* Returns the current user from the context.
*
* Usage example on a JSP with the EL:
* The current user name is: ${cms:vfs(pageContext).currentUser.name}
*
*
* @return the current user
*/
public CmsUser getCurrentUser() {
return m_cms.getRequestContext().getCurrentUser();
}
/**
* Short form for {@link #getExistsResource()}.
*
* Usage example on a JSP with the EL / JSTL:
* <c:if test="${cms:vfs(pageContext).exists['/checkme.html']}" >
* The resource "/checkme.html" exists.
* </c:if>
*
*
* @return a map that lazily reads resources from the OpenCms VFS
*
* @see #getExistsResource()
*/
public Map getExists() {
return getExistsResource();
}
/**
* Returns a map that lazily checks if a resources exists in the OpenCms VFS.
*
* Usage example on a JSP with the EL / JSTL:
* <c:if test="${cms:vfs(pageContext).existsResource['/checkme.html']}" >
* The resource "/checkme.html" exists.
* </c:if>
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* <c:if test="${content.vfs.existsResource['/checkme.html']}" >
* The resource "/checkme.html" exists.
* </c:if>
* </cms:contentload>
*
* @return a map that lazily checks if a resources exists in the OpenCms VFS
*
* @see #getExists() for a short form of this method
*/
public Map getExistsResource() {
if (m_existsResource == null) {
// create lazy map only on demand
m_existsResource = CmsCollectionsGenericWrapper.createLazyMap(new CmsExistsResourceTransformer());
}
return m_existsResource;
}
/**
* Returns a map that lazily checks if a resources exists in the VFS and is of type XML content or XML page.
*
* Usage example on a JSP with the EL / JSTL:
* <c:if test="${cms:vfs(pageContext).existsXml['/text.xml']}" >
* The resource "/text.xml" exists and is an XML document.
* </c:if>
*
*
* @return a map that lazily checks if a resources exists in the VFS and is of type XML content or XML page
*/
public Map getExistsXml() {
if (m_existsXml == null) {
// create lazy map only on demand
m_existsXml = CmsCollectionsGenericWrapper.createLazyMap(new CmsExistsXmlTransformer());
}
return m_existsXml;
}
/**
* Flushes the internal caches of this VFS access bean.
*
* The VFS access bean uses lazy initialized Maps for all access, but once a value has been
* read it is cached in the Map and not read again from the VFS. This means the lazy Maps
* act as another layer of cache to the VFS.
*
* The VFS access bean instance itself is cached in the OpenCms request context attributes of the {@link CmsObject},
* see {@link #create(CmsObject)}. Normally there is a new {@link CmsObject} created for
* all incoming requests, so the live-time of the VFS access bean is short.
* In that case the caching of the lazy Maps should improve performance and not be an issue.
* However, in rare cases an instance of a {@link CmsObject} may be kept for a long time in
* some custom code. In theses cases flushing the caches of the lazy Maps manually may be required, otherwise
* the Map caches may be out of sync with the VFS.
*
* @return always returns true
*/
public boolean getFlushCaches() {
m_resources = null;
m_properties = null;
m_propertiesSearch = null;
return true;
}
/**
* Returns a map that lazily calculates links to files in the OpenCms VFS,
* which have been adjusted according to the web application path and the
* OpenCms static export rules.
*
* Please note that the target is always assumed to be in the OpenCms VFS, so you can't use
* this method for links external to OpenCms.
*
* Relative links are converted to absolute links, using the current element URI as base.
*
* Relative links are converted to absolute links, using the current OpenCms request context URI as base.
*
* Usage example on a JSP with the EL:
* Link to the "/index.html" file: ${cms:vfs(pageContext).link['/index.html']}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Link to the "/index.html" file: ${content.vfs.link['/index.html']}
* </cms:contentload>
*
* @return a map that lazily calculates links to resources in the OpenCms VFS
*
* @see org.opencms.jsp.CmsJspActionElement#link(String)
* @see org.opencms.jsp.CmsJspTagLink#linkTagAction(String, javax.servlet.ServletRequest)
*/
public Map getLink() {
if (m_links == null) {
// create lazy map only on demand
m_links = CmsCollectionsGenericWrapper.createLazyMap(new CmsVfsLinkTransformer());
}
return m_links;
}
/**
* Gets a lazy loading map used to access locale variants of a resource with a given path.
*
* Usage in JSP: ${myvfsaccessbeaninstance.localeResource['/foo/bar/index.html']['de']}
*
* @return the lazy loading map
*/
public Map> getLocaleResource() {
return CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {
@SuppressWarnings("synthetic-access")
public Object transform(Object arg) {
if (!(arg instanceof String)) {
return new HashMap();
}
String path = (String)arg;
try {
CmsResource res = m_cms.readResource(path);
CmsJspResourceWrapper wrapper = new CmsJspResourceWrapper(m_cms, res);
return wrapper.getLocaleResource();
} catch (Exception e) {
LOG.warn(e.getLocalizedMessage(), e);
return new HashMap();
}
}
});
}
/**
* Returns a lazy loading map used to detect the main locale of a resource which is part of a locale group.
*
* Usage in JSPs: ${myvfsaccessbeaninstance.mainLocale['/foo/index.html']}
*
* @return the lazy loading map
*/
public Map getMainLocale() {
return CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {
@SuppressWarnings("synthetic-access")
public Object transform(Object arg) {
if (!(arg instanceof String)) {
return null;
}
String path = (String)arg;
try {
CmsResource res = m_cms.readResource(path);
CmsLocaleGroup localeGroup = m_cms.getLocaleGroupService().readLocaleGroup(res);
return localeGroup.getMainLocale();
} catch (Exception e) {
LOG.warn(e.getLocalizedMessage(), e);
return null;
}
}
});
}
/**
* Short form for {@link #getReadPermissions()}.
*
* Usage example on a JSP with the EL:
* Permission string of the "/index.html" resource: ${cms:vfs(pageContext).readPermissions['/index.html'].permissionString}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Permission string of the "/index.html" resource: ${content.vfs.readPermissions['/index.html'].permissionString}
* </cms:contentload>
*
* @return a map that lazily reads resource permissions from the OpenCms VFS
*
* @see #getReadPermissions()
*/
public Map getPermissions() {
return getReadPermissions();
}
/**
* Short form for {@link #getReadProperties()}.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource: ${cms:vfs(pageContext).property['/index.html']['Title']}
*
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, without search
*
* @see #getReadProperties()
*/
public Map> getProperty() {
return getReadProperties();
}
/**
* Short form for {@link #getReadPropertiesLocale()}.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource for locale "de": ${cms:vfs(pageContext).property['/index.html']['de']['Title']}
*
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, without search
*
* @see #getReadPropertiesLocale()
*/
public Map>> getPropertyLocale() {
return getReadPropertiesLocale();
}
/**
* Short form for {@link #getReadPropertiesSearch()}.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).propertySearch['/index.html']['Title']}
*
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, with search
*
* @see #getReadPropertiesSearch()
*/
public Map> getPropertySearch() {
return getReadPropertiesSearch();
}
/**
* Short form for {@link #getReadPropertiesSearchLocale()}.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource (searched) for locale "de": ${cms:vfs(pageContext).propertySearch['/index.html']['de']['Title']}
*
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, with search
*
* @see #getReadPropertiesSearchLocale()
*/
public Map>> getPropertySearchLocale() {
return getReadPropertiesSearchLocale();
}
/**
* Returns a map that lazily reads resource permissions from the OpenCms VFS.
*
* Usage example on a JSP with the EL:
* Permission string of the "/index.html" resource: ${cms:vfs(pageContext).readPermissions['/index.html'].permissionString}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Permission string of the "/index.html" resource: ${content.vfs.readPermissions['/index.html'].permissionString}
* </cms:contentload>
*
* @return a map that lazily reads resource permissions from the OpenCms VFS
*
* @see #getPermissions() for a short form of this method
*/
public Map getReadPermissions() {
if (m_permissions == null) {
// create lazy map only on demand
m_permissions = CmsCollectionsGenericWrapper.createLazyMap(new CmsPermissionsLoaderTransformer());
}
return m_permissions;
}
/**
* Returns a map that lazily reads all resource properties from the OpenCms VFS, without search.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource: ${cms:vfs(pageContext).readProperties['/index.html']['Title']}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Title property of the "/index.html" resource: ${content.vfs.readProperties['/index.html']['Title']}
* </cms:contentload>
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, without search
*
* @see #getProperty() for a short form of this method
*/
public Map> getReadProperties() {
if (m_properties == null) {
// create lazy map only on demand
m_properties = CmsCollectionsGenericWrapper.createLazyMap(new CmsResourcePropertyLoaderTransformer(false));
}
return m_properties;
}
/**
* Returns a map that lazily reads all resource properties from the OpenCms VFS, without search.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource for locale "de": ${cms:vfs(pageContext).readProperties['/index.html']['de']['Title']}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Title property of the "/index.html" resource: ${content.vfs.readProperties['/index.html']['Title']}
* </cms:contentload>
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, without search
*
* @see #getProperty() for a short form of this method
*/
public Map>> getReadPropertiesLocale() {
if (m_propertiesLocale == null) {
// create lazy map only on demand
m_propertiesLocale = CmsCollectionsGenericWrapper.createLazyMap(
new CmsResourceLocalePropertyLoaderTransformer(false));
}
return m_propertiesLocale;
}
/**
* Returns a map that lazily reads all resource properties from the OpenCms VFS, with search.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).readPropertiesSearch['/index.html']['Title']}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Title property of the "/index.html" resource (searched): ${content.vfs.readPropertiesSearch['/index.html']['Title']}
* </cms:contentload>
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, with search
*
* @see #getPropertySearch() for a short form of this method
*/
public Map> getReadPropertiesSearch() {
if (m_propertiesSearch == null) {
// create lazy map only on demand
m_propertiesSearch = CmsCollectionsGenericWrapper.createLazyMap(
new CmsResourcePropertyLoaderTransformer(true));
}
return m_propertiesSearch;
}
/**
* Returns a map that lazily reads all resource properties from the OpenCms VFS, with search and provides locale specific access to them.
*
* Usage example on a JSP with the EL:
* Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).readPropertiesSearch['/index.html']['Title']}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Title property of the "/index.html" resource (searched) for locale "de": ${content.vfs.readPropertiesSearchLocale['/index.html']['de']['Title']}
* </cms:contentload>
*
* @return a map that lazily reads all resource properties from the OpenCms VFS, with search
*
* @see #getPropertySearch() for a short form of this method
*/
public Map>> getReadPropertiesSearchLocale() {
if (m_propertiesSearchLocale == null) {
// create lazy map only on demand
m_propertiesSearchLocale = CmsCollectionsGenericWrapper.createLazyMap(
new CmsResourceLocalePropertyLoaderTransformer(true));
}
return m_propertiesSearchLocale;
}
/**
* Returns a map that lazily reads resources from the OpenCms VFS.
*
* Usage example on a JSP with the EL:
* Root path of the "/index.html" resource: ${cms:vfs(pageContext).readResource['/index.html'].rootPath}
*
*
* Usage example on a JSP with the <cms:contentaccess>
tag:
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* Root path of the "/index.html" resource: ${content.vfs.readResource['/index.html'].rootPath}
* </cms:contentload>
*
* @return a map that lazily reads resources from the OpenCms VFS
*
* @see #getResource() for a short form of this method
*/
public Map getReadResource() {
if (m_resources == null) {
// create lazy map only on demand
m_resources = CmsCollectionsGenericWrapper.createLazyMap(new CmsResourceLoaderTransformer());
}
return m_resources;
}
/**
* Returns a map that lazily reads XML documents from the OpenCms VFS that are wrapped using a
* {@link CmsJspContentAccessBean}.
*
* Usage example on a JSP with the EL:
* Title of "/text.xml": ${cms:vfs(pageContext).readXml['/text.xml'].value['Title']}
*
*
* @return a map that lazily reads wrapped XML documents from the OpenCms VFS
*
* @see #getXml() for a short form of this method
*/
public Map getReadXml() {
if (m_xmlContent == null) {
// create lazy map only on demand
m_xmlContent = CmsCollectionsGenericWrapper.createLazyMap(new CmsXmlContentAccessTransformer());
}
return m_xmlContent;
}
/**
* Returns the OpenCms request context the current user this bean was initialized with.
*
* Usage example on a JSP with the EL:
* The current URI is: ${cms:vfs(pageContext).requestContext.uri}
*
*
* @return the OpenCms request context the current user this bean was initialized with
*
* @see #getContext() for a short form of this method
*/
public CmsRequestContext getRequestContext() {
return m_cms.getRequestContext();
}
/**
* Short form for {@link #getReadResource()}.
*
* Usage example on a JSP with the EL:
* Root path of the "/index.html" resource: ${cms:vfs(pageContext).resource['/index.html'].rootPath}
*
*
* @return a map that lazily reads resources from the OpenCms VFS
*
* @see #getReadResource()
*/
public Map getResource() {
return getReadResource();
}
/**
* Short form for {@link #getReadXml()}.
*
* Usage example on a JSP with the EL:
* Title of "/text.xml": ${cms:vfs(pageContext).xml['/text.xml'].value['Title']}
*
*
* @return a map that lazily reads wrapped XML documents from the OpenCms VFS
*
* @see #getReadXml()
*/
public Map getXml() {
return getReadXml();
}
}