com.xpn.xwiki.wysiwyg.client.util
Class ResourceName

java.lang.Object
  extended by com.xpn.xwiki.wysiwyg.client.util.ResourceName

public class ResourceName
extends java.lang.Object

Stores a resource reference: the wiki, space, page and attached file name, if it's the case. It allows parsing from and serializing to a string, in a org.xwiki.bridge.DocumentName form, i.e. wiki:Space.Page@attachment . Note: As opposed to org.xwiki.bridge.DocumentName, this class is designed to also parse and process relative references, such as attachment.png, or Page@filename@attachment.png, in which case the missing values will be set to empty. Thus, relative references to resources can be stored and processed (@see resolveRelativeTo(ResourceName)). However, the assumption that if a reference is relative then its specified values are continuous (cannot have wiki specified, space missing and page specified).
FIXME: this logic should NOT be duplicated on the client, but since it's needed in frequent enough situations (resolving relative links, resolving an attachment location: current page or another page), it's not worth making a call to the server just to have such a string parsed or serialized.
TODO: should do most of the parsing on the server and send already modeled data to the client so that no parsing whatsoever is needed on the client any longer.

Version:
$Id: ResourceName.java 24761 2009-10-29 15:45:32Z mflorea $

Constructor Summary
ResourceName()
          Default constructor.
ResourceName(java.lang.String serialized, boolean asFile)
          Builds a resource from the passed string representation, interpreted as a file or not, as specified by the asFile parameter.
ResourceName(java.lang.String wiki, java.lang.String space, java.lang.String page, java.lang.String file)
          Builds a resource from the passed wiki, space, page and file.
 
Method Summary
 void clear()
          Clears this resource name, i.e.
 boolean equals(java.lang.Object obj)
          
 void fromString(java.lang.String reference, boolean asFile)
          Parses the passed string as a string reference to this resource (i.e.
 java.lang.String getFile()
           
 java.lang.String getPage()
           
 ResourceName getRelativeTo(ResourceName resource)
          Returns minimal representation of the current resource relative to the passed resource.
 java.lang.String getSpace()
           
 java.lang.String getWiki()
           
 int hashCode()
          
 boolean matchesUpToPage(ResourceName resource)
          Compares this resource with the passed resource to check if the values for the components match up to the page component, inclusive.
 ResourceName resolveRelativeTo(ResourceName resource)
          Resolves the current resource relative to the passed resource.
 void setFile(java.lang.String file)
           
 void setPage(java.lang.String page)
           
 void setSpace(java.lang.String space)
           
 void setWiki(java.lang.String wiki)
           
 java.lang.String toString()
          Creates the String representation of the resource, in the form wiki:Space.Page@file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceName

public ResourceName()
Default constructor.


ResourceName

public ResourceName(java.lang.String wiki,
                    java.lang.String space,
                    java.lang.String page,
                    java.lang.String file)
Builds a resource from the passed wiki, space, page and file.

Parameters:
wiki - the wiki to build the resource for
space - the space to build the resource for
page - the page to build the resource for
file - the file to build the resource for

ResourceName

public ResourceName(java.lang.String serialized,
                    boolean asFile)
Builds a resource from the passed string representation, interpreted as a file or not, as specified by the asFile parameter.

Parameters:
serialized - the serialized form of the resource reference
asFile - true if the serialized form should be interpreted as a file, false otherwise.
Method Detail

getWiki

public java.lang.String getWiki()
Returns:
the wiki

setWiki

public void setWiki(java.lang.String wiki)
Parameters:
wiki - the wiki to set

getSpace

public java.lang.String getSpace()
Returns:
the space

setSpace

public void setSpace(java.lang.String space)
Parameters:
space - the space to set

getPage

public java.lang.String getPage()
Returns:
the page

setPage

public void setPage(java.lang.String page)
Parameters:
page - the page to set

getFile

public java.lang.String getFile()
Returns:
the file

setFile

public void setFile(java.lang.String file)
Parameters:
file - the file to set

clear

public void clear()
Clears this resource name, i.e. sets everything on null.


fromString

public void fromString(java.lang.String reference,
                       boolean asFile)
Parses the passed string as a string reference to this resource (i.e. in the form wiki:Space.Page@attachment) and stores it in the current object.

Parameters:
reference - the string form of a resource reference, wiki:Space.Page@attachment
asFile - the passed reference should be parsed as a reference to an attached file
See Also:
resolveRelativeTo(ResourceName)

resolveRelativeTo

public ResourceName resolveRelativeTo(ResourceName resource)
Resolves the current resource relative to the passed resource.

Parameters:
resource - the resource to resolve relative to
Returns:
a new resource, which represents this resource resolved relative to the passed resource

getRelativeTo

public ResourceName getRelativeTo(ResourceName resource)
Returns minimal representation of the current resource relative to the passed resource. E.g. xwiki:Main.RecentChanges relative to xwiki:Main.WebHome will be RecentChanges; xwiki:XWiki.ClassSheet relative to xwiki:Main.WebHome will be XWiki.ClassSheet. This resource is considered to be either fully specified, either relative to resource, so that any missing components are considered to be the components from resource.

Parameters:
resource - the resource to which the relative resource is to be built
Returns:
the resource which represents this resource relative to the passed resource

toString

public java.lang.String toString()
Creates the String representation of the resource, in the form wiki:Space.Page@file.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this resource
See Also:
fromString(String, boolean)

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

matchesUpToPage

public boolean matchesUpToPage(ResourceName resource)
Compares this resource with the passed resource to check if the values for the components match up to the page component, inclusive. If there are components missing in the current resource, they will be considered matching so that relative resources are matched only on the specified components.

Parameters:
resource - the resource to compare this resource to
Returns:
true if this resource matches up to the page component (inclusive) (if the resource referred by this ResourceName is in the same page with the passed resource), or false otherwise


Copyright © 2004-2010 XWiki. All Rights Reserved.