Package org.apache.wiki.attachment

## Class AttachmentServlet

- java.lang.Object
- - javax.servlet.GenericServlet
  - - javax.servlet.http.HttpServlet
    - - org.apache.wiki.attachment.AttachmentServlet

All Implemented Interfaces:
  `java.io.Serializable`, `javax.servlet.Servlet`, `javax.servlet.ServletConfig`

    public class AttachmentServlet
    extends javax.servlet.http.HttpServlet

This is the chief JSPWiki attachment management servlet. It is used for both uploading new content and downloading old content. It can handle most common cases, e.g. check for modifications and return 304's as necessary.

Authentication is done using JSPWiki's normal AAA framework.

This servlet is also capable of managing dynamically created attachments.

Since:
  1.9.45.
See Also:
  Serialized Form

### Constructor Summary

Constructors
`AttachmentServlet()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `doGet​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)` Serves a GET with two parameters: 'wikiname' specifying the wikiname of the attachment, 'version' specifying the version indicator.
`protected void` `doOptions​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)` Implements the OPTIONS method.
`void` `doPost​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)` Grabs mime/multipart data and stores it into the temporary area.
`protected boolean` `executeUpload​(Context context, java.io.InputStream data, java.lang.String filename, java.lang.String errorPage, java.lang.String parentPage, java.lang.String changenote, long contentLength)`
`void` `init​(javax.servlet.ServletConfig config)` Initializes the servlet from Engine properties.
`protected java.lang.String` `upload​(javax.servlet.http.HttpServletRequest req)` Uploads a specific mime multipart input set, intercepts exceptions.

### Methods inherited from class javax.servlet.http.HttpServlet

`doDelete, doHead, doPut, doTrace, getLastModified, service, service`

### Methods inherited from class javax.servlet.GenericServlet

`destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AttachmentServlet

    public AttachmentServlet()

### Method Detail

#### init

    public void init​(javax.servlet.ServletConfig config)
              throws javax.servlet.ServletException

Initializes the servlet from Engine properties.

Specified by:
  `init` in interface `javax.servlet.Servlet`
Overrides:
  `init` in class `javax.servlet.GenericServlet`
Throws:
  `javax.servlet.ServletException`

#### doOptions

    protected void doOptions​(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res)

Implements the OPTIONS method.

Overrides:
  `doOptions` in class `javax.servlet.http.HttpServlet`
Parameters:
  `req` - The servlet request
  `res` - The servlet response

#### doGet

    public void doGet​(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
               throws java.io.IOException

Serves a GET with two parameters: 'wikiname' specifying the wikiname of the attachment, 'version' specifying the version indicator.

Overrides:
  `doGet` in class `javax.servlet.http.HttpServlet`
Throws:
  `java.io.IOException`

#### doPost

    public void doPost​(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
                throws java.io.IOException

Grabs mime/multipart data and stores it into the temporary area. Uses other parameters to determine which name to store as.

The input to this servlet is generated by an HTML FORM with two parts. The first, named 'page', is the WikiName identifier for the parent file. The second, named 'content', is the binary content of the file.

Overrides:
  `doPost` in class `javax.servlet.http.HttpServlet`
Throws:
  `java.io.IOException`

#### upload

    protected java.lang.String upload​(javax.servlet.http.HttpServletRequest req)
                               throws RedirectException,
                                      java.io.IOException

Uploads a specific mime multipart input set, intercepts exceptions.

Parameters:
  `req` - The servlet request
Returns:
  The page to which we should go next.
Throws:
  `RedirectException` - If there's an error and a redirection is needed
  `java.io.IOException` - If upload fails

#### executeUpload

    protected boolean executeUpload​(Context context,
                                    java.io.InputStream data,
                                    java.lang.String filename,
                                    java.lang.String errorPage,
                                    java.lang.String parentPage,
                                    java.lang.String changenote,
                                    long contentLength)
                             throws RedirectException,
                                    java.io.IOException,
                                    ProviderException

Parameters:
  `context` - the wiki context
  `data` - the input stream data
  `filename` - the name of the file to upload
  `errorPage` - the place to which you want to get a redirection
  `parentPage` - the page to which the file should be attached
  `changenote` - The change note
  `contentLength` - The content length
Returns:
  `true` if upload results in the creation of a new page; `false` otherwise
Throws:
  `RedirectException` - If the content needs to be redirected
  `java.io.IOException` - If there is a problem in the upload.
  `ProviderException` - If there is a problem in the backend.