Package org.opencms.main
Class CmsContextInfo
- java.lang.Object
-
- org.opencms.main.CmsContextInfo
-
- All Implemented Interfaces:
java.io.Serializable
public class CmsContextInfo extends java.lang.Object implements java.io.Serializable
Contains user information for automated creation of aCmsRequestContext
during system runtime.- Since:
- 6.0.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTRIBUTE_REQUEST_TIME
Name of the http session attribute the request time is stored in.static long
CURRENT_TIME
Indicates the request time should always be the current time.static java.lang.String
LOCALHOST
Localhost ip used in fallback cases.
-
Constructor Summary
Constructors Constructor Description CmsContextInfo()
Creates a new instance, initializing the variables with some reasonable default values.CmsContextInfo(java.lang.String userName)
Creates a new instance, initializing the user name as provided and all other vaiables with the same default values as inCmsContextInfo()
.CmsContextInfo(CmsRequestContext requestContext)
Creates a new instance with all context variables initialized from the given request context.CmsContextInfo(CmsUser user, CmsProject project, java.lang.String requestedUri, CmsSiteMatcher requestMatcher, java.lang.String siteRoot, boolean isSecureRequest, java.util.Locale locale, java.lang.String encoding, java.lang.String remoteAddr, long requestTime, java.lang.String ouFqn, boolean isForceAbsoluteLinks)
Creates a new instance with all context variables initialized.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkFrozen()
Checks if this context info configuration is frozen.java.lang.Object
clone()
Creates a clone of this context info object.void
freeze()
Finalizes (freezes) the configuration of this context information.CmsResource
getDetailResource()
Gets the detail content resource.java.lang.String
getEncoding()
Returns the encoding.java.util.Locale
getLocale()
Returns the locale.java.lang.String
getLocaleName()
Returns the locale name.java.lang.String
getOuFqn()
Returns the fully qualified name of the organizational unit.CmsProject
getProject()
Returns the project, ornull
if the project has not been configured.java.lang.String
getProjectName()
Returns the project name.java.lang.String
getRemoteAddr()
Returns the remote ip address.java.lang.String
getRequestedUri()
Returns the requested uri.CmsSiteMatcher
getRequestMatcher()
Returns the matcher for the current request, that is the host part of the URI from the original http request.long
getRequestTime()
Returns the request time used for validation of resource publication and expiration dates.java.lang.String
getSiteRoot()
Returns the siteroot.CmsUser
getUser()
Returns the user, ornull
if the user has not been configured.java.lang.String
getUserName()
Returns the username.boolean
isForceAbsoluteLinks()
Returns true if links to the current site should be generated with a server prefix.boolean
isSecureRequest()
Returns true if this a secure request.void
setDetailResource(CmsResource detailResource)
Sets the detail content resource.void
setEncoding(java.lang.String encoding)
Sets the encoding.void
setForceAbsoluteLinks(boolean isForceAbsoluteLinks)
Enables/disables usage of the server prefix for links to the current site.void
setIsSecureRequest(boolean isSecureRequest)
Sets the 'isSecureRequest' attribute.void
setLocale(java.util.Locale locale)
Sets the locale.void
setLocaleName(java.lang.String localeName)
Sets the locale name.void
setOuFqn(java.lang.String ouFqn)
Sets the fully qualified name of the organizational unit.void
setProjectName(java.lang.String projectName)
Sets the project name.void
setRemoteAddr(java.lang.String remoteAddr)
Sets the remote ip address.void
setRequestedUri(java.lang.String requestedUri)
Sets the requested uri.void
setRequestMatcher(CmsSiteMatcher requestMatcher)
Sets the matcher for the current request, that is the host part of the URI from the original http request.void
setRequestTime(long requestTime)
Sets the request time used for validation of resource publication and expiration dates.void
setSiteRoot(java.lang.String siteRoot)
Sets the siteroot.void
setUserName(java.lang.String userName)
Sets the username.
-
-
-
Field Detail
-
ATTRIBUTE_REQUEST_TIME
public static final java.lang.String ATTRIBUTE_REQUEST_TIME
Name of the http session attribute the request time is stored in.- See Also:
- Constant Field Values
-
CURRENT_TIME
public static final long CURRENT_TIME
Indicates the request time should always be the current time.- See Also:
- Constant Field Values
-
LOCALHOST
public static final java.lang.String LOCALHOST
Localhost ip used in fallback cases.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsContextInfo
public CmsContextInfo()
Creates a new instance, initializing the variables with some reasonable default values.The default values are:
- User name
- (configured default guest user)
- Project name
- Online
- Requested URI
- /
- Site root
- /
- Locale name
- (configured default locale name)
- Encoding
- (configured default system encoding)
- Remote address
- 127.0.0.1
- Organizational unit
- /
-
CmsContextInfo
public CmsContextInfo(CmsRequestContext requestContext)
Creates a new instance with all context variables initialized from the given request context.- Parameters:
requestContext
- the request context to initialize this context info with
-
CmsContextInfo
public CmsContextInfo(CmsUser user, CmsProject project, java.lang.String requestedUri, CmsSiteMatcher requestMatcher, java.lang.String siteRoot, boolean isSecureRequest, java.util.Locale locale, java.lang.String encoding, java.lang.String remoteAddr, long requestTime, java.lang.String ouFqn, boolean isForceAbsoluteLinks)
Creates a new instance with all context variables initialized.- Parameters:
user
- the user to create the context withproject
- the project to create the context withrequestedUri
- the request URI to create the context withrequestMatcher
- the matcher for the current request, that is the host part of the URI from the original http requestsiteRoot
- the site root to create the context withisSecureRequest
- if this a secure requestlocale
- the locale to create the context withencoding
- the encoding to create the context withremoteAddr
- the remote ip address to create the context withrequestTime
- the time of the request (used for resource publication / expiration date)ouFqn
- the fully qualified name of the organizational unit to create the context withisForceAbsoluteLinks
- a flag indicating whether links to the current site should be generated with a server prefix
-
CmsContextInfo
public CmsContextInfo(java.lang.String userName)
Creates a new instance, initializing the user name as provided and all other vaiables with the same default values as inCmsContextInfo()
.- Parameters:
userName
- the user name to create the context with- See Also:
CmsContextInfo()
-
-
Method Detail
-
clone
public java.lang.Object clone()
Creates a clone of this context info object.- Overrides:
clone
in classjava.lang.Object
- See Also:
Object.clone()
-
freeze
public void freeze()
Finalizes (freezes) the configuration of this context information.After this entry has been frozen, any attempt to change the configuration of this context info with one of the "set..." methods will lead to a
RuntimeException
.
-
getDetailResource
public CmsResource getDetailResource()
Gets the detail content resource.- Returns:
- the detail content resource
-
getEncoding
public java.lang.String getEncoding()
Returns the encoding.- Returns:
- the encoding
- See Also:
CmsRequestContext.getEncoding()
-
getLocale
public java.util.Locale getLocale()
Returns the locale.- Returns:
- the locale
- See Also:
CmsRequestContext.getLocale()
-
getLocaleName
public java.lang.String getLocaleName()
Returns the locale name.- Returns:
- the locale name
- See Also:
CmsRequestContext.getLocale()
-
getOuFqn
public java.lang.String getOuFqn()
Returns the fully qualified name of the organizational unit.- Returns:
- the fully qualified name of the organizational unit
-
getProject
public CmsProject getProject()
Returns the project, ornull
if the project has not been configured.If the project has not been configured, at last the project name will be available.
- Returns:
- the project
- See Also:
getProjectName()
,CmsRequestContext.getCurrentProject()
-
getProjectName
public java.lang.String getProjectName()
Returns the project name.- Returns:
- the project name
- See Also:
getProject()
,CmsRequestContext.getCurrentProject()
-
getRemoteAddr
public java.lang.String getRemoteAddr()
Returns the remote ip address.- Returns:
- the remote ip address
- See Also:
CmsRequestContext.getRemoteAddress()
-
getRequestedUri
public java.lang.String getRequestedUri()
Returns the requested uri.- Returns:
- the requested uri
- See Also:
CmsRequestContext.getUri()
-
getRequestMatcher
public CmsSiteMatcher getRequestMatcher()
Returns the matcher for the current request, that is the host part of the URI from the original http request.- Returns:
- the matcher for the current request, that is the host part of the URI from the original http request
-
getRequestTime
public long getRequestTime()
Returns the request time used for validation of resource publication and expiration dates.- Returns:
- the request time used for validation of resource publication and expiration dates
- See Also:
CmsRequestContext.getRequestTime()
-
getSiteRoot
public java.lang.String getSiteRoot()
Returns the siteroot.- Returns:
- the siteroot
- See Also:
CmsRequestContext.getSiteRoot()
-
getUser
public CmsUser getUser()
Returns the user, ornull
if the user has not been configured.If the user has not been configured, at last the user name will be available.
- Returns:
- the user
- See Also:
getUserName()
,CmsRequestContext.getCurrentUser()
-
getUserName
public java.lang.String getUserName()
Returns the username.- Returns:
- the username
- See Also:
getUser()
,CmsRequestContext.getCurrentUser()
-
isForceAbsoluteLinks
public boolean isForceAbsoluteLinks()
Returns true if links to the current site should be generated with a server prefix.- Returns:
- true if links to current site should be absolute
-
isSecureRequest
public boolean isSecureRequest()
Returns true if this a secure request.- Returns:
- true if this is a secure request
-
setDetailResource
public void setDetailResource(CmsResource detailResource)
Sets the detail content resource.- Parameters:
detailResource
- the detail content resource to set
-
setEncoding
public void setEncoding(java.lang.String encoding)
Sets the encoding.- Parameters:
encoding
- the encoding to set- See Also:
CmsRequestContext.setEncoding(String)
-
setForceAbsoluteLinks
public void setForceAbsoluteLinks(boolean isForceAbsoluteLinks)
Enables/disables usage of the server prefix for links to the current site.- Parameters:
isForceAbsoluteLinks
- true if links to the current site should be generated with a server prefix
-
setIsSecureRequest
public void setIsSecureRequest(boolean isSecureRequest)
Sets the 'isSecureRequest' attribute.- Parameters:
isSecureRequest
- true if this a secure request
-
setLocale
public void setLocale(java.util.Locale locale)
Sets the locale.Setting the locale name will override the currently selected locale and vice-versa. The locale name and the locale will always match.
- Parameters:
locale
- the locale to set- See Also:
setLocaleName(String)
,CmsRequestContext.getLocale()
-
setLocaleName
public void setLocaleName(java.lang.String localeName)
Sets the locale name.Setting the locale name will override the currently selected locale and vice-versa. The locale name and the locale will always match.
- Parameters:
localeName
- the locale name to set- See Also:
setLocale(Locale)
,CmsRequestContext.getLocale()
-
setOuFqn
public void setOuFqn(java.lang.String ouFqn)
Sets the fully qualified name of the organizational unit.- Parameters:
ouFqn
- the fully qualified name of the organizational unit to set
-
setProjectName
public void setProjectName(java.lang.String projectName)
Sets the project name.- Parameters:
projectName
- the project name to set- See Also:
CmsRequestContext.getCurrentProject()
-
setRemoteAddr
public void setRemoteAddr(java.lang.String remoteAddr)
Sets the remote ip address.- Parameters:
remoteAddr
- the remote ip address- See Also:
CmsRequestContext.getRemoteAddress()
-
setRequestedUri
public void setRequestedUri(java.lang.String requestedUri)
Sets the requested uri.- Parameters:
requestedUri
- the requested uri to set- See Also:
CmsRequestContext.setUri(String)
-
setRequestMatcher
public void setRequestMatcher(CmsSiteMatcher requestMatcher)
Sets the matcher for the current request, that is the host part of the URI from the original http request.- Parameters:
requestMatcher
- the matcher for the current request
-
setRequestTime
public void setRequestTime(long requestTime)
Sets the request time used for validation of resource publication and expiration dates.- Parameters:
requestTime
- the request time to set- See Also:
CmsRequestContext.getRequestTime()
-
setSiteRoot
public void setSiteRoot(java.lang.String siteRoot)
Sets the siteroot.- Parameters:
siteRoot
- the siteroot to set- See Also:
CmsRequestContext.setSiteRoot(String)
-
setUserName
public void setUserName(java.lang.String userName)
Sets the username.- Parameters:
userName
- the username to set- See Also:
CmsRequestContext.getCurrentUser()
-
checkFrozen
protected void checkFrozen() throws CmsRuntimeException
Checks if this context info configuration is frozen.- Throws:
CmsRuntimeException
- in case the configuration is already frozen
-
-