Package org.opencms.relations
Class CmsLink
- java.lang.Object
-
- org.opencms.relations.CmsLink
-
public class CmsLink extends java.lang.Object
A single link entry in the link table.- Since:
- 6.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTRIBUTE_INTERNAL
Name of the internal attribute of the link node.static java.lang.String
ATTRIBUTE_NAME
Name of the name attribute of the elements node.static java.lang.String
ATTRIBUTE_TYPE
Name of the type attribute of the elements node.static java.lang.String
CUSTOM_LINK_HANDLER
request context attribute to pass in a custom link renderer.static java.lang.String
DEFAULT_NAME
Default link name.static CmsRelationType
DEFAULT_TYPE
Default link type.static java.lang.String
DUMMY_URI
A dummy uri.static java.lang.String
NODE_ANCHOR
Name of the anchor node.static java.lang.String
NODE_QUERY
Name of the query node.static java.lang.String
NODE_TARGET
Name of the target node.static java.lang.String
NODE_UUID
Name of the UUID node.static CmsLink
NULL_LINK
Constant for the NULL link.
-
Constructor Summary
Constructors Constructor Description CmsLink(java.lang.String name, CmsRelationType type, java.lang.String uri, boolean internal)
Creates a new link object without a reference to the xml page link element.CmsLink(java.lang.String name, CmsRelationType type, CmsUUID structureId, java.lang.String uri, boolean internal)
Creates a new link object without a reference to the xml page link element.CmsLink(org.dom4j.Element element)
Reconstructs a link object from the given XML node.CmsLink(CmsLinkInfo linkInfo)
Creates a new link from the given link info bean.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
checkConsistency(CmsObject cms)
Checks and updates the structure id or the path of the target.boolean
equals(java.lang.Object obj)
A link is considered equal if the link target and the link type is equal.java.lang.String
getAnchor()
Returns the anchor of this link.org.dom4j.Element
getElement()
Returns the xml node element representing this link object.java.lang.String
getLink(CmsObject cms)
Returns the processed link.java.lang.String
getLink(CmsObject cms, boolean processEditorLinks)
Deprecated.usegetLink(CmsObject)
instead, the process editor option is set using the OpenCms request context attributesjava.lang.String
getName()
Returns the macro name of this link.java.lang.String
getParameter(java.lang.String name)
Returns the first parameter value for the given parameter name.java.util.Map<java.lang.String,java.lang.String[]>
getParameterMap()
Returns the map of parameters of this link.java.util.Set<java.lang.String>
getParameterNames()
Returns the set of available parameter names for this link.java.lang.String[]
getParameterValues(java.lang.String name)
Returns all parameter values for the given name.java.lang.String
getQuery()
Returns the query of this link.CmsResource
getResource()
Returns the resource this link points to, if it is an internal link and has already been initialized via checkConsistency.java.lang.String
getSitePath()
Deprecated.usegetSitePath(CmsObject)
insteadprotected java.lang.String
getSitePath(java.lang.String uri)
Helper method for getting the site path for a uri.java.lang.String
getSitePath(CmsObject cms)
Returns the path of the link target relative to the current site.java.lang.String
getSiteRoot()
Return the site root if the target of this link is internal, ornull
otherwise.CmsUUID
getStructureId()
The structure id of the linked resource.java.lang.String
getTarget()
Returns the target (destination) of this link.java.lang.String
getTargetWithQuery()
Gets the target with the query appended, if there is one.CmsRelationType
getType()
Returns the type of this link.java.lang.String
getUri()
Returns the raw uri of this link.java.lang.String
getVfsUri()
Deprecated.UsegetSitePath()
insteadint
hashCode()
boolean
isInternal()
Returns if the link is internal.CmsLinkInfo
toLinkInfo()
Converts this link to a link info object.java.lang.String
toString()
void
updateLink(java.lang.String uri)
Updates the uri of this link with a new value.void
updateLink(java.lang.String target, java.lang.String anchor, java.lang.String query)
Updates the uri of this link with a new target, anchor and query.
-
-
-
Field Detail
-
ATTRIBUTE_INTERNAL
public static final java.lang.String ATTRIBUTE_INTERNAL
Name of the internal attribute of the link node.- See Also:
- Constant Field Values
-
ATTRIBUTE_NAME
public static final java.lang.String ATTRIBUTE_NAME
Name of the name attribute of the elements node.- See Also:
- Constant Field Values
-
ATTRIBUTE_TYPE
public static final java.lang.String ATTRIBUTE_TYPE
Name of the type attribute of the elements node.- See Also:
- Constant Field Values
-
DEFAULT_NAME
public static final java.lang.String DEFAULT_NAME
Default link name.- See Also:
- Constant Field Values
-
DEFAULT_TYPE
public static final CmsRelationType DEFAULT_TYPE
Default link type.
-
DUMMY_URI
public static final java.lang.String DUMMY_URI
A dummy uri.- See Also:
- Constant Field Values
-
NODE_ANCHOR
public static final java.lang.String NODE_ANCHOR
Name of the anchor node.- See Also:
- Constant Field Values
-
NODE_QUERY
public static final java.lang.String NODE_QUERY
Name of the query node.- See Also:
- Constant Field Values
-
NODE_TARGET
public static final java.lang.String NODE_TARGET
Name of the target node.- See Also:
- Constant Field Values
-
NODE_UUID
public static final java.lang.String NODE_UUID
Name of the UUID node.- See Also:
- Constant Field Values
-
CUSTOM_LINK_HANDLER
public static final java.lang.String CUSTOM_LINK_HANDLER
request context attribute to pass in a custom link renderer.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsLink
public CmsLink(CmsLinkInfo linkInfo)
Creates a new link from the given link info bean.- Parameters:
linkInfo
- the link info bean
-
CmsLink
public CmsLink(org.dom4j.Element element)
Reconstructs a link object from the given XML node.- Parameters:
element
- the XML node containing the link information
-
CmsLink
public CmsLink(java.lang.String name, CmsRelationType type, CmsUUID structureId, java.lang.String uri, boolean internal)
Creates a new link object without a reference to the xml page link element.- Parameters:
name
- the internal name of this linktype
- the type of this linkstructureId
- the structure id of the linkuri
- the link uriinternal
- indicates if the link is internal within OpenCms
-
CmsLink
public CmsLink(java.lang.String name, CmsRelationType type, java.lang.String uri, boolean internal)
Creates a new link object without a reference to the xml page link element.- Parameters:
name
- the internal name of this linktype
- the type of this linkuri
- the link uriinternal
- indicates if the link is internal within OpenCms
-
-
Method Detail
-
checkConsistency
public void checkConsistency(CmsObject cms)
Checks and updates the structure id or the path of the target.- Parameters:
cms
- the cms context
-
equals
public boolean equals(java.lang.Object obj)
A link is considered equal if the link target and the link type is equal.- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
getAnchor
public java.lang.String getAnchor()
Returns the anchor of this link.- Returns:
- the anchor or null if undefined
-
getElement
public org.dom4j.Element getElement()
Returns the xml node element representing this link object.- Returns:
- the xml node element representing this link object
-
getLink
public java.lang.String getLink(CmsObject cms)
Returns the processed link.- Parameters:
cms
- the current OpenCms user context, can benull
- Returns:
- the processed link
-
getLink
@Deprecated public java.lang.String getLink(CmsObject cms, boolean processEditorLinks)
Deprecated.usegetLink(CmsObject)
instead, the process editor option is set using the OpenCms request context attributesReturns the processed link.- Parameters:
cms
- the current OpenCms user context, can benull
processEditorLinks
- this parameter is not longer used- Returns:
- the processed link
-
getName
public java.lang.String getName()
Returns the macro name of this link.- Returns:
- the macro name name of this link
-
getParameter
public java.lang.String getParameter(java.lang.String name)
Returns the first parameter value for the given parameter name.- Parameters:
name
- the name of the parameter- Returns:
- the first value for this name or
null
-
getParameterMap
public java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
Returns the map of parameters of this link.- Returns:
- the map of parameters
-
getParameterNames
public java.util.Set<java.lang.String> getParameterNames()
Returns the set of available parameter names for this link.- Returns:
- the parameter names
-
getParameterValues
public java.lang.String[] getParameterValues(java.lang.String name)
Returns all parameter values for the given name.- Parameters:
name
- the name of the parameter- Returns:
- all parameter values or
null
-
getQuery
public java.lang.String getQuery()
Returns the query of this link.- Returns:
- the query or null if undefined
-
getResource
public CmsResource getResource()
Returns the resource this link points to, if it is an internal link and has already been initialized via checkConsistency.Returns null otherwise.
- Returns:
- the resource this link points to
-
getSitePath
@Deprecated public java.lang.String getSitePath()
Deprecated.usegetSitePath(CmsObject)
insteadReturns the vfs link of the target if it is internal.- Returns:
- the full link destination or null if the link is not internal
-
getSitePath
public java.lang.String getSitePath(CmsObject cms)
Returns the path of the link target relative to the current site.- Parameters:
cms
- the CMS context- Returns:
- the site path
-
getSiteRoot
public java.lang.String getSiteRoot()
Return the site root if the target of this link is internal, ornull
otherwise.- Returns:
- the site root if the target of this link is internal, or
null
otherwise
-
getStructureId
public CmsUUID getStructureId()
The structure id of the linked resource.- Returns:
- structure id of the linked resource
-
getTarget
public java.lang.String getTarget()
Returns the target (destination) of this link.- Returns:
- the target the target (destination) of this link
-
getTargetWithQuery
public java.lang.String getTargetWithQuery()
Gets the target with the query appended, if there is one.- Returns:
- the target with the query
-
getType
public CmsRelationType getType()
Returns the type of this link.- Returns:
- the type of this link
-
getUri
public java.lang.String getUri()
Returns the raw uri of this link.- Returns:
- the uri
-
getVfsUri
@Deprecated public java.lang.String getVfsUri()
Deprecated.UsegetSitePath()
insteadReturns the vfs link of the target if it is internal.- Returns:
- the full link destination or null if the link is not internal
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
isInternal
public boolean isInternal()
Returns if the link is internal.- Returns:
- true if the link is a local link
-
toLinkInfo
public CmsLinkInfo toLinkInfo()
Converts this link to a link info object.- Returns:
- the link info object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
updateLink
public void updateLink(java.lang.String uri)
Updates the uri of this link with a new value.Also updates the structure of the underlying XML page document this link belongs to.
Note that you can not update the "internal" or "type" values of the link, so the new link must be of same type (A, IMG) and also remain either an internal or external link.
- Parameters:
uri
- the uri to update this link withscheme://authority/path#anchor?query
-
updateLink
public void updateLink(java.lang.String target, java.lang.String anchor, java.lang.String query)
Updates the uri of this link with a new target, anchor and query.If anchor and/or query are
null
, this features are not used.Note that you can not update the "internal" or "type" values of the link, so the new link must be of same type (A, IMG) and also remain either an internal or external link.
Also updates the structure of the underlying XML page document this link belongs to.
- Parameters:
target
- the target (destination) of this linkanchor
- the anchor or null if undefinedquery
- the query or null if undefined
-
getSitePath
protected java.lang.String getSitePath(java.lang.String uri)
Helper method for getting the site path for a uri.- Parameters:
uri
- a VFS uri- Returns:
- the site path
-
-