com.xpn.xwiki.web
Class UploadAction

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

public class UploadAction
extends XWikiAction

Action that handles uploading document attachments. It saves all the uploaded files whose fieldname start with filepath.

Version:
$Id: db24b5b640d7dc3ace9576bcfbab46d6fc38d64d $

Field Summary
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
UploadAction()
           
 
Method Summary
 boolean action(XWikiContext context)
           
protected  String getFileName(String fieldName, FileUploadPlugin fileupload, XWikiContext context)
          Extract the corresponding attachment name for a given file field.
 String render(XWikiContext context)
           
 boolean uploadAttachment(String fieldName, String filename, FileUploadPlugin fileupload, XWikiDocument doc, XWikiContext context)
          Attach a file to the current document.
 
Methods inherited from class com.xpn.xwiki.web.XWikiAction
cleanupComponents, csrfTokenCheck, execute, execute, getRealPath, getTranslatedDocument, handleRevision, initializeContainerComponent, initializeXWikiContext, sendGlobalRedirect, sendRedirect
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, 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

UploadAction

public UploadAction()
Method Detail

action

public boolean action(XWikiContext context)
               throws XWikiException
Overrides:
action in class XWikiAction
Throws:
XWikiException

uploadAttachment

public boolean uploadAttachment(String fieldName,
                                String filename,
                                FileUploadPlugin fileupload,
                                XWikiDocument doc,
                                XWikiContext context)
                         throws XWikiException
Attach a file to the current document.

Parameters:
fieldName - the target file field
filename -
fileupload - the FileUploadPlugin holding the form data
doc - the target document
context - the current request context
Returns:
true if the file was successfully attached, false otherwise.
Throws:
XWikiException - if the form data cannot be accessed, or if the database operation failed

getFileName

protected String getFileName(String fieldName,
                             FileUploadPlugin fileupload,
                             XWikiContext context)
                      throws XWikiException
Extract the corresponding attachment name for a given file field. It can either be specified in a separate form input field, or it is extracted from the original filename.

Parameters:
fieldName - the target file field
fileupload - the FileUploadPlugin holding the form data
context - the current request context
Returns:
a valid attachment name
Throws:
XWikiException - if the form data cannot be accessed, or if the specified filename is invalid

render

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


Copyright © 2004-2013 XWiki. All Rights Reserved.