com.xpn.xwiki.web
Class SkinAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by com.xpn.xwiki.web.XWikiAction
          extended by com.xpn.xwiki.web.SkinAction

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: 9783d268266d881ebebb11e4ca2ee6756a7bd01c $

Field Summary
 
Fields inherited from class org.apache.struts.action.Action
servlet
 
Constructor Summary
SkinAction()
           
 
Method Summary
 String getResourceFilePath(String filename)
          Get the path for the given file in resources.
 String getSkinFilePath(String filename, String skin)
          Get the path for the given skin file in the given skin.
 boolean isCssMimeType(String mimetype)
          Checks if a mimetype indicates a CSS file.
 boolean isJavascriptMimeType(String mimetype)
          Checks if a mimetype indicates a javascript file.
 String render(String path, XWikiContext context)
           
 String render(XWikiContext context)
           
 boolean renderFileFromAttachment(String filename, XWikiDocument doc, XWikiContext context)
          Tries to serve the content of an attachment as a skin file.
 boolean renderFileFromObjectField(String filename, XWikiDocument doc, XWikiContext context)
          Tries to serve the content of an XWikiSkins object field as a skin file.
protected  void setupHeaders(XWikiResponse response, String mimetype, Date lastChanged, int length)
          Sets several headers to properly identify the response.
 
Methods inherited from class com.xpn.xwiki.web.XWikiAction
action, cleanupComponents, csrfTokenCheck, execute, execute, getRealPath, getTranslatedDocument, handleRevision, initializeContainerComponent, initializeXWikiContext, sendGlobalRedirect, sendRedirect
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SkinAction

public SkinAction()
Method Detail

render

public String render(XWikiContext context)
              throws XWikiException
Overrides:
render in class XWikiAction
Throws:
XWikiException

render

public String render(String path,
                     XWikiContext context)
              throws XWikiException,
                     IOException
Throws:
XWikiException
IOException

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

protected void setupHeaders(XWikiResponse response,
                            String mimetype,
                            Date lastChanged,
                            int 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.


Copyright © 2004–2014 XWiki. All rights reserved.