org.opencms.relations
Class CmsLink

java.lang.Object
  extended by org.opencms.relations.CmsLink

public class CmsLink
extends Object

A single link entry in the link table.

Since:
6.0.0

Field Summary
static String ATTRIBUTE_INTERNAL
          Name of the internal attribute of the link node.
static String ATTRIBUTE_NAME
          Name of the name attribute of the elements node.
static String ATTRIBUTE_TYPE
          Name of the type attribute of the elements node.
static String DEFAULT_NAME
          Default link name.
static CmsRelationType DEFAULT_TYPE
          Default link type.
static String DUMMY_URI
          A dummy uri.
static String NODE_ANCHOR
          Name of the anchor node.
static String NODE_QUERY
          Name of the query node.
static String NODE_TARGET
          Name of the target node.
static String NODE_UUID
          Name of the UUID node.
static CmsLink NULL_LINK
          Constant for the NULL link.
 
Constructor Summary
CmsLink(Element element)
          Reconstructs a link object from the given XML node.
CmsLink(String name, CmsRelationType type, CmsUUID structureId, String uri, boolean internal)
          Creates a new link object without a reference to the xml page link element.
CmsLink(String name, CmsRelationType type, String uri, boolean internal)
          Creates a new link object without a reference to the xml page link element.
 
Method Summary
 void checkConsistency(CmsObject cms)
          Checks and updates the structure id or the path of the target.
 boolean equals(Object obj)
          A link is considered equal if the link target and the link type is equal.
 String getAnchor()
          Returns the anchor of this link.
 Element getElement()
          Returns the xml node element representing this link object.
 String getLink(CmsObject cms)
          Returns the processed link.
 String getLink(CmsObject cms, boolean processEditorLinks)
          Deprecated. use getLink(CmsObject) instead, the process editor option is set using the OpenCms request context attributes
 String getName()
          Returns the macro name of this link.
 String getParameter(String name)
          Returns the first parameter value for the given parameter name.
 Map<String,String[]> getParameterMap()
          Returns the map of parameters of this link.
 Set<String> getParameterNames()
          Returns the set of available parameter names for this link.
 String[] getParameterValues(String name)
          Returns all parameter values for the given name.
 String getQuery()
          Returns the query of this link.
 String getSitePath()
          Returns the vfs link of the target if it is internal.
protected  String getSitePath(String uri)
          Helper method for getting the site path for a uri.
 String getSiteRoot()
          Return the site root if the target of this link is internal, or null otherwise.
 CmsUUID getStructureId()
          The structure id of the linked resource.
 String getTarget()
          Returns the target (destination) of this link.
 CmsRelationType getType()
          Returns the type of this link.
 String getUri()
          Returns the raw uri of this link.
 String getVfsUri()
          Deprecated. Use getSitePath() instead
 int hashCode()
           
 boolean isInternal()
          Returns if the link is internal.
 String toString()
           
 void updateLink(String uri)
          Updates the uri of this link with a new value.
 void updateLink(String target, String anchor, String query)
          Updates the uri of this link with a new target, anchor and query.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTRIBUTE_INTERNAL

public static final String ATTRIBUTE_INTERNAL
Name of the internal attribute of the link node.

See Also:
Constant Field Values

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
Name of the name attribute of the elements node.

See Also:
Constant Field Values

ATTRIBUTE_TYPE

public static final String ATTRIBUTE_TYPE
Name of the type attribute of the elements node.

See Also:
Constant Field Values

DEFAULT_NAME

public static final 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 String DUMMY_URI
A dummy uri.

See Also:
Constant Field Values

NODE_ANCHOR

public static final String NODE_ANCHOR
Name of the anchor node.

See Also:
Constant Field Values

NODE_QUERY

public static final String NODE_QUERY
Name of the query node.

See Also:
Constant Field Values

NODE_TARGET

public static final String NODE_TARGET
Name of the target node.

See Also:
Constant Field Values

NODE_UUID

public static final String NODE_UUID
Name of the UUID node.

See Also:
Constant Field Values

NULL_LINK

public static final CmsLink NULL_LINK
Constant for the NULL link.

Constructor Detail

CmsLink

public CmsLink(Element element)
Reconstructs a link object from the given XML node.

Parameters:
element - the XML node containing the link information

CmsLink

public CmsLink(String name,
               CmsRelationType type,
               CmsUUID structureId,
               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 link
type - the type of this link
structureId - the structure id of the link
uri - the link uri
internal - indicates if the link is internal within OpenCms

CmsLink

public CmsLink(String name,
               CmsRelationType type,
               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 link
type - the type of this link
uri - the link uri
internal - 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(Object obj)
A link is considered equal if the link target and the link type is equal.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getAnchor

public String getAnchor()
Returns the anchor of this link.

Returns:
the anchor or null if undefined

getElement

public Element getElement()
Returns the xml node element representing this link object.

Returns:
the xml node element representing this link object

getLink

public String getLink(CmsObject cms)
Returns the processed link.

Parameters:
cms - the current OpenCms user context, can be null
Returns:
the processed link

getLink

@Deprecated
public String getLink(CmsObject cms,
                                 boolean processEditorLinks)
Deprecated. use getLink(CmsObject) instead, the process editor option is set using the OpenCms request context attributes

Returns the processed link.

Parameters:
cms - the current OpenCms user context, can be null
processEditorLinks - this parameter is not longer used
Returns:
the processed link

getName

public String getName()
Returns the macro name of this link.

Returns:
the macro name name of this link

getParameter

public String getParameter(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 Map<String,String[]> getParameterMap()
Returns the map of parameters of this link.

Returns:
the map of parameters

getParameterNames

public Set<String> getParameterNames()
Returns the set of available parameter names for this link.

Returns:
the parameter names

getParameterValues

public String[] getParameterValues(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 String getQuery()
Returns the query of this link.

Returns:
the query or null if undefined

getSitePath

public String getSitePath()
Returns the vfs link of the target if it is internal.

Returns:
the full link destination or null if the link is not internal

getSiteRoot

public String getSiteRoot()
Return the site root if the target of this link is internal, or null 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 String getTarget()
Returns the target (destination) of this link.

Returns:
the target the target (destination) of this link

getType

public CmsRelationType getType()
Returns the type of this link.

Returns:
the type of this link

getUri

public String getUri()
Returns the raw uri of this link.

Returns:
the uri

getVfsUri

@Deprecated
public String getVfsUri()
Deprecated. Use getSitePath() instead

Returns 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 class Object
See Also:
Object.hashCode()

isInternal

public boolean isInternal()
Returns if the link is internal.

Returns:
true if the link is a local link

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

updateLink

public void updateLink(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 with scheme://authority/path#anchor?query

updateLink

public void updateLink(String target,
                       String anchor,
                       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 link
anchor - the anchor or null if undefined
query - the query or null if undefined

getSitePath

protected String getSitePath(String uri)
Helper method for getting the site path for a uri.

Parameters:
uri - a VFS uri
Returns:
the site path