org.xwiki.model.script
Class ModelScriptService

java.lang.Object
  extended by org.xwiki.model.script.ModelScriptService
All Implemented Interfaces:
org.xwiki.script.service.ScriptService

@Component
@Named(value="model")
@Singleton
public class ModelScriptService
extends Object
implements org.xwiki.script.service.ScriptService

Provides Model-specific Scripting APIs.

Since:
2.3M1
Version:
$Id: e936d337858255f12b233ddb8ca5042184058d12 $

Constructor Summary
ModelScriptService()
           
 
Method Summary
 AttachmentReference createAttachmentReference(DocumentReference documentReference, String fileName)
          Creates an AttachmentReference from a file name and a reference to the document holding that file.
 DocumentReference createDocumentReference(String wiki, String space, String page)
          Create a Document Reference from a passed wiki, space and page names, which can be empty strings or null in which case they are resolved using the resolver.
 DocumentReference createDocumentReference(String wiki, String space, String page, String hint)
          Create a Document Reference from a passed wiki, space and page names, which can be empty strings or null in which case they are resolved against the Resolver having the hint passed as parameter.
 EntityReference createEntityReference(String name, EntityType type)
          Creates any EntityReference from a string.
 EntityReference createEntityReference(String name, EntityType type, EntityReference parent)
          Creates any EntityReference from a string.
 SpaceReference createSpaceReference(String spaceName, WikiReference parent)
          Creates a SpaceReference from a string representing the space name.
 WikiReference createWikiReference(String wikiName)
          Creates a WikiReference from a string representing the wiki name.
 String getEntityReferenceValue(EntityType type)
          Get the current value for a specific entity type, like the current space or wiki name.
 String getEntityReferenceValue(EntityType type, String hint)
          Get the value configured for a specific entity type, like the space name or wiki name.
 AttachmentReference resolveAttachment(String stringRepresentation, Object... parameters)
           
 AttachmentReference resolveAttachment(String stringRepresentation, String hint, Object... parameters)
           
 DocumentReference resolveDocument(String stringRepresentation, Object... parameters)
           
 DocumentReference resolveDocument(String stringRepresentation, String hint, Object... parameters)
           
 ObjectReference resolveObject(String stringRepresentation, Object... parameters)
           
 ObjectReference resolveObject(String stringRepresentation, String hint, Object... parameters)
           
 ObjectPropertyReference resolveObjectProperty(String stringRepresentation, Object... parameters)
           
 ObjectPropertyReference resolveObjectProperty(String stringRepresentation, String hint, Object... parameters)
           
 SpaceReference resolveSpace(String stringRepresentation, Object... parameters)
           
 SpaceReference resolveSpace(String stringRepresentation, String hint, Object... parameters)
           
 String serialize(EntityReference reference, Object... parameters)
           
 String serialize(EntityReference reference, String hint, Object... parameters)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelScriptService

public ModelScriptService()
Method Detail

createDocumentReference

public DocumentReference createDocumentReference(String wiki,
                                                 String space,
                                                 String page)
Create a Document Reference from a passed wiki, space and page names, which can be empty strings or null in which case they are resolved using the resolver.

Parameters:
wiki - the wiki reference name to use (can be empty or null)
space - the space reference name to use (can be empty or null)
page - the page reference name to use (can be empty or null)
Returns:
the typed Document Reference object or null if no Resolver with the passed hint could be found
Since:
2.3M2

createDocumentReference

public DocumentReference createDocumentReference(String wiki,
                                                 String space,
                                                 String page,
                                                 String hint)
Create a Document Reference from a passed wiki, space and page names, which can be empty strings or null in which case they are resolved against the Resolver having the hint passed as parameter. Valid hints are for example "default", "current", "currentmixed".

Parameters:
wiki - the wiki reference name to use (can be empty or null)
space - the space reference name to use (can be empty or null)
page - the page reference name to use (can be empty or null)
hint - the hint of the Resolver to use in case any parameter is empty or null
Returns:
the typed Document Reference object or null if no Resolver with the passed hint could be found

createAttachmentReference

public AttachmentReference createAttachmentReference(DocumentReference documentReference,
                                                     String fileName)
Creates an AttachmentReference from a file name and a reference to the document holding that file.

Parameters:
documentReference - a reference to the document the file is attached to
fileName - the name of a file attached to a document
Returns:
a reference to the specified attachment
Since:
2.5M2

createWikiReference

@Unstable
public WikiReference createWikiReference(String wikiName)
Creates a WikiReference from a string representing the wiki name.

Parameters:
wikiName - the wiki name (eg "xwiki")
Returns:
the reference to the wiki
Since:
5.0M1

createSpaceReference

@Unstable
public SpaceReference createSpaceReference(String spaceName,
                                                    WikiReference parent)
Creates a SpaceReference from a string representing the space name.

Parameters:
spaceName - the space name (eg "Main")
parent - the wiki reference in which the space is located
Returns:
the reference to the space
Since:
5.0M1

createEntityReference

@Unstable
public EntityReference createEntityReference(String name,
                                                      EntityType type)
Creates any EntityReference from a string.

Parameters:
name - the entity reference name (eg "page")
type - the entity type (eg "wiki", "space", "document", etc)
Returns:
the created reference
Since:
5.0M1

createEntityReference

@Unstable
public EntityReference createEntityReference(String name,
                                                      EntityType type,
                                                      EntityReference parent)
Creates any EntityReference from a string.

Parameters:
name - the entity reference name (eg "page")
type - the entity type (eg "wiki", "space", "document", etc)
parent - the entity parent
Returns:
the created reference
Since:
5.0M1

resolveSpace

@Unstable
public SpaceReference resolveSpace(String stringRepresentation,
                                            Object... parameters)
Parameters:
stringRepresentation - the space reference specified as a String (using the "wiki:space" format and with special characters escaped where required)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a space reference relative to another entity reference
Returns:
the typed Space Reference object (resolved using the resolver)
Since:
5.0M1

resolveSpace

@Unstable
public SpaceReference resolveSpace(String stringRepresentation,
                                            String hint,
                                            Object... parameters)
Parameters:
stringRepresentation - the space reference specified as a String (using the "wiki:space" format and with special characters escaped where required)
hint - the hint of the Resolver to use in case any part of the reference is missing (no wiki or no space specified)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a space reference relative to another entity reference
Returns:
the typed Space Reference object or null if no Resolver with the passed hint could be found
Since:
5.0M1

resolveDocument

public DocumentReference resolveDocument(String stringRepresentation,
                                         Object... parameters)
Parameters:
stringRepresentation - the document reference specified as a String (using the "wiki:space.page" format and with special characters escaped where required)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a document reference relative to another entity reference
Returns:
the typed Document Reference object (resolved using the resolver)
Since:
2.3M2

resolveDocument

public DocumentReference resolveDocument(String stringRepresentation,
                                         String hint,
                                         Object... parameters)
Parameters:
stringRepresentation - the document reference specified as a String (using the "wiki:space.page" format and with special characters escaped where required)
hint - the hint of the Resolver to use in case any part of the reference is missing (no wiki specified, no space or no page)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a document reference relative to another entity reference
Returns:
the typed Document Reference object or null if no Resolver with the passed hint could be found

resolveAttachment

public AttachmentReference resolveAttachment(String stringRepresentation,
                                             Object... parameters)
Parameters:
stringRepresentation - an attachment reference specified as String (using the "wiki:space.page@file" format and with special characters escaped where required)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an attachment reference relative to another entity reference
Returns:
the corresponding typed AttachmentReference object (resolved using the resolver)
Since:
2.5M2

resolveAttachment

public AttachmentReference resolveAttachment(String stringRepresentation,
                                             String hint,
                                             Object... parameters)
Parameters:
stringRepresentation - an attachment reference specified as String (using the "wiki:space.page@file" format and with special characters escaped where required)
hint - the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no space or no page)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an attachment reference relative to another entity reference
Returns:
the corresponding typed AttachmentReference object
Since:
2.5M2

resolveObject

public ObjectReference resolveObject(String stringRepresentation,
                                     Object... parameters)
Parameters:
stringRepresentation - an object reference specified as String (using the "wiki:space.page^object" format and with special characters escaped where required)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an object reference relative to another entity reference
Returns:
the corresponding typed ObjectReference object (resolved using the resolver)
Since:
3.2M3

resolveObject

public ObjectReference resolveObject(String stringRepresentation,
                                     String hint,
                                     Object... parameters)
Parameters:
stringRepresentation - an object reference specified as String (using the "wiki:space.page^object" format and with special characters escaped where required)
hint - the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no space or no page)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an object reference relative to another entity reference
Returns:
the corresponding typed ObjectReference object
Since:
3.2M3

resolveObjectProperty

public ObjectPropertyReference resolveObjectProperty(String stringRepresentation,
                                                     Object... parameters)
Parameters:
stringRepresentation - an object property reference specified as String (using the "wiki:space.page^object.property" format and with special characters escaped where required)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an object property reference relative to another entity reference
Returns:
the corresponding typed ObjectReference object (resolved using the resolver)
Since:
3.2M3

resolveObjectProperty

public ObjectPropertyReference resolveObjectProperty(String stringRepresentation,
                                                     String hint,
                                                     Object... parameters)
Parameters:
stringRepresentation - an object property reference specified as String (using the "wiki:space.page^object.property" format and with special characters escaped where required)
hint - the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no space or no page)
parameters - extra parameters to pass to the resolver; you can use these parameters to resolve an object property reference relative to another entity reference
Returns:
the corresponding typed ObjectReference object
Since:
3.2M3

serialize

public String serialize(EntityReference reference,
                        Object... parameters)
Parameters:
reference - the entity reference to transform into a String representation
parameters - the optional extra parameters to pass to the Serializer; they are passed directly to EntityReferenceSerializer.serialize(org.xwiki.model.reference.EntityReference, Object...)
Returns:
the string representation of the passed entity reference (using the "compact" serializer)
Since:
2.3M2

serialize

public String serialize(EntityReference reference,
                        String hint,
                        Object... parameters)
Parameters:
reference - the entity reference to transform into a String representation
hint - the hint of the Serializer to use (valid hints are for example "default", "compact", "local")
parameters - the optional extra parameters to pass to the Serializer; they are passed directly to EntityReferenceSerializer.serialize(org.xwiki.model.reference.EntityReference, Object...)
Returns:
the string representation of the passed entity reference

getEntityReferenceValue

public String getEntityReferenceValue(EntityType type)
Get the current value for a specific entity type, like the current space or wiki name. This doesn't return a proper entity reference, but just the string value that should be used for that type of entity.

Parameters:
type - the target entity type; from Velocity it's enough to use a string with the uppercase name of the entity, like 'SPACE'
Returns:
the current value for the requested entity type
Since:
4.3M1

getEntityReferenceValue

public String getEntityReferenceValue(EntityType type,
                                      String hint)
Get the value configured for a specific entity type, like the space name or wiki name. This doesn't return a proper entity reference, but just the string value that should be used for that type of entity.

Parameters:
type - the target entity type; from Velocity it's enough to use a string with the uppercase name of the entity, like 'SPACE'
hint - the hint of the value provider to use (valid hints are for example "default", "current" and "currentmixed")
Returns:
the configured value for the requested entity type, for example "Main" for the default space or "WebHome" for the default space homepage
Since:
4.3M1


Copyright © 2004-2013 XWiki. All Rights Reserved.