org.opencms.jsp.util
Class CmsJspVfsAccessBean

java.lang.Object
  extended by org.opencms.jsp.util.CmsJspVfsAccessBean

public final class CmsJspVfsAccessBean
extends java.lang.Object

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
Version:
$Revision: 1.7 $
Author:
Alexander Kandzior
See Also:
CmsJspContentAccessBean

Nested Class Summary
 class CmsJspVfsAccessBean.CmsExistsResourceTransformer
          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.
 class CmsJspVfsAccessBean.CmsExistsXmlTransformer
          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.
 class CmsJspVfsAccessBean.CmsPropertyLoaderSingleTransformer
          Transformer that a properties of a resource from the OpenCms VFS, the input is used as String for the property name to read.
 class CmsJspVfsAccessBean.CmsPropertyLoaderTransformer
          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.
 class CmsJspVfsAccessBean.CmsResourceLoaderTransformer
          Transformer that loads a resource from the OpenCms VFS, the input is used as String for the resource name to read.
 class CmsJspVfsAccessBean.CmsVfsLinkTransformer
          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.
 class CmsJspVfsAccessBean.CmsXmlContentAccessTransformer
          Provides XML content access beans for VFS resources.
 
Field Summary
static java.lang.String ATTRIBUTE_VFS_ACCESS_BEAN
          Request context attribute for indicating the model file for a create resource operation.
 
Method Summary
static CmsJspVfsAccessBean create(CmsObject cms)
          Creates a new instance of the JSP VFS access utility bean.
 CmsObject getCmsObject()
          Returns the OpenCms user context this bean was initialized with.
 CmsRequestContext getContext()
          Short form for getRequestContext().
 java.util.Map getExists()
          Short form for getExistsResource().
 java.util.Map getExistsResource()
          Returns a map that lazily checks if a resources exists in the OpenCms VFS.
 java.util.Map getExistsXml()
          Returns a map that lazily checks if a resources exists in the VFS and is of type XML content or XML page.
 boolean getFlushCaches()
          Flushes the internal caches of this VFS access bean.
 java.util.Map getLink()
          Returns a map that lazily calculates links to files in the OpenCms VFS, which has been adjusted according to the web application path and the OpenCms static export rules.
 java.util.Map getProperty()
          Short form for getReadProperties().
 java.util.Map getPropertySearch()
          Short form for getReadPropertiesSearch().
 java.util.Map getReadProperties()
          Returns a map that lazily reads all resource properties from the OpenCms VFS, without search.
 java.util.Map getReadPropertiesSearch()
          Returns a map that lazily reads all resource properties from the OpenCms VFS, with search.
 java.util.Map getReadResource()
          Returns a map that lazily reads resources from the OpenCms VFS.
 java.util.Map getReadXml()
          Returns a map that lazily reads XML documents from the OpenCms VFS that are wrapped using a CmsJspContentAccessBean.
 CmsRequestContext getRequestContext()
          Returns the OpenCms request context the current user this bean was initialized with.
 java.util.Map getResource()
          Short form for getReadResource().
 java.util.Map getXml()
          Short form for getReadXml().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_VFS_ACCESS_BEAN

public static final java.lang.String ATTRIBUTE_VFS_ACCESS_BEAN
Request context attribute for indicating the model file for a create resource operation.

Method Detail

create

public static CmsJspVfsAccessBean create(CmsObject 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.

Parameters:
cms - the current OpenCms user context
Returns:
a new instance of the JSP VFS access utility bean

getCmsObject

public CmsObject getCmsObject()
Returns the OpenCms user context this bean was initialized with.

Returns:
the OpenCms user context this bean was initialized with

getContext

public CmsRequestContext getContext()
Short form for getRequestContext().

Usage example on a JSP with the EL:

 The current URI is: ${cms:vfs(pageContext).context.uri}
 

Returns:
the OpenCms request context the current user this bean was initialized with
See Also:
getRequestContext()

getExists

public java.util.Map getExists()
Short form for 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>
 

Returns:
a map that lazily reads resources from the OpenCms VFS
See Also:
getExistsResource()

getExistsResource

public java.util.Map 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>

Returns:
a map that lazily checks if a resources exists in the OpenCms VFS
See Also:
for a short form of this method

getExistsXml

public java.util.Map getExistsXml()
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>
 

Returns:
a map that lazily checks if a resources exists in the VFS and is of type XML content or XML page

getFlushCaches

public boolean getFlushCaches()
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 CmsObject, see create(CmsObject). Normally there is a new 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 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.

Returns:
always returns true

getLink

public java.util.Map getLink()
Returns a map that lazily calculates links to files in the OpenCms VFS, which has 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>

Returns:
a map that lazily calculates links to resources in the OpenCms VFS
See Also:
CmsJspActionElement.link(String), CmsJspTagLink.linkTagAction(String, javax.servlet.ServletRequest)

getProperty

public java.util.Map getProperty()
Short form for getReadProperties().

Usage example on a JSP with the EL:

 Title property of the "/index.html" resource: ${cms:vfs(pageContext).property['/index.html']['Title']}
 

Returns:
a map that lazily reads all resource properties from the OpenCms VFS, without search
See Also:
getReadProperties()

getPropertySearch

public java.util.Map getPropertySearch()
Short form for getReadPropertiesSearch().

Usage example on a JSP with the EL:

 Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).propertySearch['/index.html']['Title']}
 

Returns:
a map that lazily reads all resource properties from the OpenCms VFS, with search
See Also:
getReadPropertiesSearch()

getReadProperties

public java.util.Map getReadProperties()
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>

Returns:
a map that lazily reads all resource properties from the OpenCms VFS, without search
See Also:
for a short form of this method

getReadPropertiesSearch

public java.util.Map getReadPropertiesSearch()
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>

Returns:
a map that lazily reads all resource properties from the OpenCms VFS, with search
See Also:
for a short form of this method

getReadResource

public java.util.Map getReadResource()
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>

Returns:
a map that lazily reads resources from the OpenCms VFS
See Also:
for a short form of this method

getReadXml

public java.util.Map getReadXml()
Returns a map that lazily reads XML documents from the OpenCms VFS that are wrapped using a CmsJspContentAccessBean.

Usage example on a JSP with the EL:

 Title of "/text.xml": ${cms:vfs(pageContext).readXml['/text.xml'].value['Title']}
 

Returns:
a map that lazily reads wrapped XML documents from the OpenCms VFS
See Also:
for a short form of this method

getRequestContext

public CmsRequestContext getRequestContext()
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}
 

Returns:
the OpenCms request context the current user this bean was initialized with
See Also:
for a short form of this method

getResource

public java.util.Map getResource()
Short form for getReadResource().

Usage example on a JSP with the EL:

 Root path of the "/index.html" resource: ${cms:vfs(pageContext).resource['/index.html'].rootPath}
 

Returns:
a map that lazily reads resources from the OpenCms VFS
See Also:
getReadResource()

getXml

public java.util.Map getXml()
Short form for getReadXml().

Usage example on a JSP with the EL:

 Title of "/text.xml": ${cms:vfs(pageContext).xml['/text.xml'].value['Title']}
 

Returns:
a map that lazily reads wrapped XML documents from the OpenCms VFS
See Also:
getReadXml()