Class ModelScriptService

  • All Implemented Interfaces:
    org.xwiki.script.service.ScriptService

    @Component
    @Named("model")
    @Singleton
    public class ModelScriptService
    extends Object
    implements org.xwiki.script.service.ScriptService
    Provides Model-specific Scripting APIs.
    Since:
    2.3M1
    Version:
    $Id: 2484c8fa1c464a02ef61d460567fd091ec3c64a5 $
    • 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 "current" 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,
                                                         List<String> spaces,
                                                         String page)
        Create a Document Reference from a passed wiki, list of spaces and page names, which can be empty strings or null in which case they are resolved using the "current" resolver.
        Parameters:
        wiki - the wiki reference name to use (can be empty or null)
        spaces - the list of spaces 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:
        7.2M2
      • createDocumentReference

        public DocumentReference createDocumentReference​(DocumentReference reference,
                                                         Locale locale)
        Create a new reference with the passed Locale.
        Parameters:
        reference - the reference (with or without locale)
        locale - the locale of the new reference
        Returns:
        the typed Document Reference object
        Since:
        5.4RC1
      • 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
      • createDocumentReference

        public DocumentReference createDocumentReference​(String wiki,
                                                         List<String> spaces,
                                                         String page,
                                                         String hint)
        Create a Document Reference from a passed wiki, list of spaces 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)
        spaces - the spaces list 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
        Since:
        7.2M2
      • createPageReference

        public PageReference createPageReference​(String wiki,
                                                 String... pages)
        Create a Page Reference from a passed wiki and pages names, which can be empty strings or null in which case they are resolved using the "current" resolver.
        Parameters:
        wiki - the wiki reference name to use (can be empty or null)
        pages - the page reference names to use (can be empty or null)
        Returns:
        the typed PAge Reference object or null if no Resolver with the passed hint could be found
        Since:
        10.6RC1
      • createPageReference

        public PageReference createPageReference​(String wiki,
                                                 List<String> pages,
                                                 Locale locale)
        Create a Page Reference from a passed wiki, list of page names, which can be empty strings or null in which case they are resolved using the "current" resolver.
        Parameters:
        wiki - the wiki reference name to use (can be empty or null)
        pages - the list of pages name to use (can be empty or null)
        locale - the locale of the page
        Returns:
        the typed Document Reference object or null if no Resolver with the passed hint could be found
        Since:
        10.6RC1
      • createPageReference

        public PageReference createPageReference​(String wiki,
                                                 List<String> pages,
                                                 Locale locale,
                                                 String hint)
        Create a Page Reference from a passed wiki, list of pages 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)
        pages - the pages list to use (can be empty or null)
        locale - the locale of the page
        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
        Since:
        10.6RC1
      • 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
      • createPageAttachmentReference

        public PageAttachmentReference createPageAttachmentReference​(PageReference pageReference,
                                                                     String fileName)
        Creates a PageAttachmentReference from a file name and a reference to the page holding that file.
        Parameters:
        pageReference - a reference to the page the file is attached to
        fileName - the name of a file attached to a page
        Returns:
        a reference to the specified attachment
        Since:
        10.6RC1
      • createObjectPropertyReference

        public ObjectPropertyReference createObjectPropertyReference​(String propertyName,
                                                                     ObjectReference objectReference)
        Creates an ObjectPropertyReference from a property name and the reference of the object having that property.
        Parameters:
        propertyName - the property name
        objectReference - the object reference
        Returns:
        the reference of the specified object property
        Since:
        12.10.11, 13.4.6, 13.10RC1
      • createWikiReference

        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

        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
      • createSpaceReference

        public SpaceReference createSpaceReference​(String spaceName,
                                                   SpaceReference parent)
        Creates a SpaceReference from a string representing the space name and the reference of the parent space.
        Parameters:
        spaceName - the space name (e.g. "Main")
        parent - the reference of the parent space
        Returns:
        the reference to the space
        Since:
        7.3RC1
      • createSpaceReference

        public SpaceReference createSpaceReference​(List<String> spaces,
                                                   WikiReference parent)
        Creates a SpaceReference from a list of string representing the space name and the name of its parents.
        Parameters:
        spaces - the list of the spaces name (eg ["A", "B", "C"])
        parent - the wiki reference in which the space is located
        Returns:
        the reference to the space
        Since:
        7.2M2
      • createEntityReference

        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

        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

        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 "current" resolver)
        Since:
        5.0M1
      • resolveSpace

        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 "current" 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
      • resolvePage

        public PageReference resolvePage​(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 "current" resolver)
        Since:
        2.3M2
      • resolvePage

        public PageReference resolvePage​(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 "current" 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
      • resolvePageAttachment

        public PageAttachmentReference resolvePageAttachment​(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 PageAttachmentReference object (resolved using the "current" resolver)
        Since:
        2.5M2
      • resolvePageAttachment

        public PageAttachmentReference resolvePageAttachment​(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 PageAttachmentReference object
        Since:
        10.6RC1
      • 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 "current" 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
      • resolvePageObject

        public PageObjectReference resolvePageObject​(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 PageObjectReference object (resolved using the "current" resolver)
        Since:
        10.6RC1
      • resolvePageObject

        public PageObjectReference resolvePageObject​(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 PageObjectReference object
        Since:
        10.6RC1
      • 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 ObjectPropertyReference object (resolved using the "current" 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 ObjectPropertyReference object
        Since:
        3.2M3
      • resolvePageObjectProperty

        public PageObjectPropertyReference resolvePageObjectProperty​(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 ObjectPropertyReference object (resolved using the "current" resolver)
        Since:
        10.6RC1
      • resolvePageObjectProperty

        public PageObjectPropertyReference resolvePageObjectProperty​(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 ObjectPropertyReference object
        Since:
        10.6RC1
      • resolveClassProperty

        public ClassPropertyReference resolveClassProperty​(String stringRepresentation,
                                                           Object... parameters)
        Parameters:
        stringRepresentation - a class property reference specified as String (using the "wiki:Space.Class^property" format and with special characters escaped where required)
        parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a class property reference relative to another entity reference
        Returns:
        the corresponding typed ClassPropertyReference object (resolved using the "current" resolver)
        Since:
        5.4.2, 6.0M1
      • resolveClassProperty

        public ClassPropertyReference resolveClassProperty​(String stringRepresentation,
                                                           String hint,
                                                           Object... parameters)
        Parameters:
        stringRepresentation - a class property reference specified as String (using the "wiki:Space.Class^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 a class property reference relative to another entity reference
        Returns:
        the corresponding typed ClassPropertyReference object
        Since:
        5.4.2, 6.0M1
      • resolvePageClassProperty

        public PageClassPropertyReference resolvePageClassProperty​(String stringRepresentation,
                                                                   Object... parameters)
        Parameters:
        stringRepresentation - a class property reference specified as String (using the "wiki:Space/Class/property" format and with special characters escaped where required)
        parameters - extra parameters to pass to the resolver; you can use these parameters to resolve a class property reference relative to another entity reference
        Returns:
        the corresponding typed ClassPropertyReference object (resolved using the "current" resolver)
        Since:
        10.6RC1
      • resolvePageClassProperty

        public PageClassPropertyReference resolvePageClassProperty​(String stringRepresentation,
                                                                   String hint,
                                                                   Object... parameters)
        Parameters:
        stringRepresentation - a class property reference specified as String (using the "wiki:Space/Class/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 a class property reference relative to another entity reference
        Returns:
        the corresponding typed ClassPropertyReference object
        Since:
        10.6RC1
      • getEntityReferenceValue

        @Deprecated
        public String getEntityReferenceValue​(EntityType type)
        Deprecated.
        since 7.4.1/8.0M1, use getEntityReference(EntityType)
        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

        @Deprecated
        public String getEntityReferenceValue​(EntityType type,
                                              String hint)
        Deprecated.
        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
      • getEntityReference

        public EntityReference getEntityReference​(EntityType type)
        Get the current reference configured for a specific entity type, like the space reference or wiki reference. This doesn't return a full entity reference, but just the part 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 reference for the requested entity type, for example "Main" for the default space or "WebHome" for the default space homepage
        Since:
        7.2M1
      • getEntityReference

        public EntityReference getEntityReference​(EntityType type,
                                                  String hint)
        Get the reference configured for a specific entity type, like the space reference or wiki reference. This doesn't return a full entity reference, but just the part 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 EntityReferenceProvider 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:
        7.2M1
      • toTree

        public EntityReferenceTree toTree​(Iterable<? extends EntityReference> references)
        Convert passed references to a tree of references.
        Parameters:
        references - the references
        Returns:
        the references as a tree
        Since:
        5.4RC1
      • toTree

        public EntityReferenceTree toTree​(EntityReference... references)
        Convert passed references to a tree of references.
        Parameters:
        references - the references
        Returns:
        the references as a tree
        Since:
        5.4RC1
      • escape

        public String escape​(String name,
                             EntityType type)
        Escape the passed entity name according to reference syntax.
        Parameters:
        name - the name of the entity
        type - the type of the entity
        Returns:
        the escaped version of the passed name
        Since:
        7.2M1