Class SkinAction

  • All Implemented Interfaces:
    com.xpn.xwiki.internal.web.LegacyAction

    @Component
    @Named("skin")
    @Singleton
    public class SkinAction
    extends XWikiAction

    Action for serving skin files. It allows skins to be defined using XDocuments as skins, by letting files be placed as text fields in an XWiki.XWikiSkins object, or as attachments to the document, or as a file in the filesystem. If the file is not found in the current skin, then it is searched in its base skin, and eventually in the default base skins,

    This action indicates that the results should be publicly cacheable for 30 days.

    Since:
    1.0
    Version:
    $Id: dd694284bd294a59f4ff3e4da72473840cb7ccf5 $
    • Constructor Detail

      • SkinAction

        public SkinAction()
    • Method Detail

      • getSkinFilePath

        public String getSkinFilePath​(String filename,
                                      String skin)
                               throws IOException
        Get the path for the given skin file in the given skin.
        Parameters:
        filename - Name of the file.
        skin - Name of the skin to search in.
        Throws:
        IOException - if filename is invalid
      • getResourceFilePath

        public String getResourceFilePath​(String filename)
                                   throws IOException
        Get the path for the given file in resources.
        Parameters:
        filename - Name of the file.
        Throws:
        IOException - if filename is invalid
      • renderFileFromObjectField

        public boolean renderFileFromObjectField​(String filename,
                                                 XWikiDocument doc,
                                                 XWikiContext context)
                                          throws IOException
        Tries to serve the content of an XWikiSkins object field as a skin file.
        Parameters:
        filename - The name of the skin file that should be rendered.
        doc - The skin document.
        context - The current request context.
        Returns:
        true if the object exists, and the field is set to a non-empty value, and its content was successfully sent.
        Throws:
        IOException - If the response cannot be sent.
      • renderFileFromAttachment

        public boolean renderFileFromAttachment​(String filename,
                                                XWikiDocument doc,
                                                XWikiContext context)
                                         throws IOException,
                                                XWikiException
        Tries to serve the content of an attachment as a skin file.
        Parameters:
        filename - The name of the skin file that should be rendered.
        doc - The skin document.
        context - The current request context.
        Returns:
        true if the attachment was found and its content was successfully sent.
        Throws:
        IOException - If the response cannot be sent.
        XWikiException - If the attachment cannot be loaded.
      • isJavascriptMimeType

        public boolean isJavascriptMimeType​(String mimetype)
        Checks if a mimetype indicates a javascript file.
        Parameters:
        mimetype - The mime type to check.
        Returns:
        true if the mime type represents a javascript file.
      • isCssMimeType

        public boolean isCssMimeType​(String mimetype)
        Checks if a mimetype indicates a CSS file.
        Parameters:
        mimetype - The mime type to check.
        Returns:
        true if the mime type represents a css file.
      • setupHeaders

        @Deprecated
        protected void setupHeaders​(XWikiResponse response,
                                    String mimetype,
                                    Date lastChanged,
                                    int length)
        Deprecated.
        Sets several headers to properly identify the response.
        Parameters:
        response - The servlet response object, where the headers should be set.
        mimetype - The mimetype of the file. Used in the "Content-Type" header.
        lastChanged - The date of the last change of the file. Used in the "Last-Modified" header.
        length - The length of the content (in bytes). Used in the "Content-Length" header.
      • setupHeaders

        protected void setupHeaders​(XWikiResponse response,
                                    String mimetype,
                                    Date lastChanged,
                                    long length)
        Sets several headers to properly identify the response.
        Parameters:
        response - The servlet response object, where the headers should be set.
        mimetype - The mimetype of the file. Used in the "Content-Type" header.
        lastChanged - The date of the last change of the file. Used in the "Last-Modified" header.
        length - The length of the content (in bytes). Used in the "Content-Length" header.
        Since:
        11.10, 11.3.6, 10.11.10