Class WysiwygEditorScriptService

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

    @Component
    @Named("wysiwyg")
    @Singleton
    public class WysiwygEditorScriptService
    extends Object
    implements org.xwiki.script.service.ScriptService
    The WYSIWYG editor API exposed to server-side scripts like Velocity.
    Version:
    $Id: 5365a9bd5b8737e859c516e669fb45bf56600c5d $
    • Constructor Detail

      • WysiwygEditorScriptService

        public WysiwygEditorScriptService()
    • Method Detail

      • isSyntaxSupported

        public boolean isSyntaxSupported​(String syntaxId)
        Checks if there is a parser and a renderer available for the specified syntax.

        This method should be called before attempting to load the WYSIWYG editor.

        Parameters:
        syntaxId - the syntax identifier, like xwiki/2.0
        Returns:
        true if the specified syntax is currently supported by the editor, false otherwise
      • getHTMLSyntax

        @Unstable
        public org.xwiki.rendering.syntax.Syntax getHTMLSyntax()
        Returns:
        The syntax identifier of the rendered HTML.
        Since:
        14.1RC1
      • parseAndRender

        @Deprecated
        public String parseAndRender​(String html,
                                     String syntaxId)
        Deprecated.
        Parses the given HTML fragment and renders the result in annotated XHTML syntax.

        This method is currently used in wysiwyginput.vm and its purpose is to refresh the content of the WYSIWYG editor. This method is called for instance when a macro is inserted or edited.

        Parameters:
        html - the HTML fragment to be rendered
        syntaxId - the storage syntax identifier
        Returns:
        the XHTML result of rendering the given HTML fragment
      • parseAndRender

        public String parseAndRender​(String html,
                                     org.xwiki.rendering.syntax.Syntax syntax,
                                     EntityReference sourceReference)
        Parses the given HTML fragment and renders the result in annotated XHTML syntax.

        This method is currently used in wysiwyginput.vm and its purpose is to refresh the content of the WYSIWYG editor. This method is called for instance when a macro is inserted or edited.

        Parameters:
        html - the HTML fragment to be rendered
        syntax - the storage syntax identifier
        sourceReference - the reference of the html (where it's coming from)
        Returns:
        the XHTML result of rendering the given HTML fragment
        Since:
        11.9RC1
      • parseAndRender

        @Unstable
        public String parseAndRender​(String html,
                                     org.xwiki.rendering.syntax.Syntax syntax,
                                     EntityReference sourceReference,
                                     boolean restricted)
        Parses the given HTML fragment and renders the result in annotated XHTML syntax.

        This method is currently used in wysiwyginput.vm and its purpose is to refresh the content of the WYSIWYG editor. This method is called for instance when a macro is inserted or edited.

        Parameters:
        html - the HTML fragment to be rendered
        syntax - the storage syntax identifier
        sourceReference - the reference of the html (where it's coming from)
        restricted - true if the content of this property should be executed in a restricted content, false otherwise
        Returns:
        the XHTML result of rendering the given HTML fragment
        Since:
        14.10, 14.4.7, 13.10.11
      • render

        public String render​(DocumentReference templateReference)
        Produces the input for the editor by rendering the specified content template as a full HTML page, making sure the skin extension hooks are resolved. The template is rendered in the context of the current document and the Velocity context is not isolated so you can put the data needed by the template in the Velocity context before calling this method. The advantage of using this method to obtain the editor input is that the editor doesn't have to make an additional HTTP request for the content template.
        Parameters:
        templateReference - specifies the document that serves as the template for the editor content
        Returns:
        the result of rendering the specified content template
      • toAnnotatedXHTML

        @Deprecated
        public String toAnnotatedXHTML​(String source,
                                       String syntaxId)
        Deprecated.
        since 11.9RC1 use
        Converts the given source text from the specified syntax to annotated XHTML, which can be used as input for the WYSIWYG editor.
        Parameters:
        source - the text to be converted
        syntaxId - the syntax identifier
        Returns:
        the annotated XHTML result of the conversion
      • toAnnotatedXHTML

        public String toAnnotatedXHTML​(String source,
                                       org.xwiki.rendering.syntax.Syntax syntax,
                                       EntityReference sourceReference)
        Converts the given source text from the specified syntax to annotated XHTML, which can be used as input for the WYSIWYG editor.
        Parameters:
        source - the text to be converted
        syntax - the syntax of the source
        sourceReference - the reference of the source
        Returns:
        the annotated XHTML result of the conversion
        Since:
        11.9RC1
      • toAnnotatedXHTML

        @Unstable
        public String toAnnotatedXHTML​(String source,
                                       org.xwiki.rendering.syntax.Syntax syntax,
                                       EntityReference sourceReference,
                                       boolean restricted)
        Converts the given source text from the specified syntax to annotated XHTML, which can be used as input for the WYSIWYG editor.
        Parameters:
        source - the text to be converted
        syntax - the syntax of the source
        sourceReference - the reference of the source
        restricted - true if the content of this property should be executed in a restricted content, false otherwise
        Returns:
        the annotated XHTML result of the conversion
        Since:
        14.10, 14.4.7, 13.10.11
      • fromAnnotatedXHTML

        public String fromAnnotatedXHTML​(String html,
                                         String targetSyntaxId)
        Converts the given annotated HTML produced by the WYSIWYG editor to the specified target syntax.
        Parameters:
        html - the annotated HTML to be converted
        targetSyntaxId - the target syntax
        Returns:
        the result of converting the given annotated HTML to the specified target syntax
        Since:
        10.10RC1
      • importOfficeAttachment

        public String importOfficeAttachment​(AttachmentReference attachmentReference,
                                             Map<String,​Object> parameters)
        Builds the annotated XHTML needed to import the specified office attachment in the WYSIWYG editor.
        Parameters:
        attachmentReference - the office attachment to import
        parameters - the import parameters; filterStyles controls whether styles are filtered when importing office text documents; useOfficeViewer controls whether the office viewer macro is used instead of converting the content of the office file to wiki syntax
        Returns:
        the annotated XHTML needed to import the specified attachment into the content of the WYSIWYG editor