org.apache.sling.servlets.post.impl.helper
Class SlingFileUploadHandler

java.lang.Object
  extended by org.apache.sling.servlets.post.impl.helper.SlingFileUploadHandler

public class SlingFileUploadHandler
extends Object

Handles file uploads.

Simple example:

<form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./portrait" /> </form> this will create a nt:file node below "/home/admin" if the node type of "admin" is (derived from) nt:folder, a nt:resource node otherwise.

Filename example:

<form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./*" /> </form> same as above, but uses the filename of the uploaded file as name for the new node.

Type hint example:

<form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./portrait" /> <input type="hidden" name="./portrait@TypeHint" value="my:file" /> </form> this will create a new node with the type my:file below admin. if the hinted type extends from nt:file an intermediate file node is created otherwise directly a resource node.


Field Summary
static String JCR_CONTENT
           
static String JCR_DATA
           
static String JCR_ENCODING
           
static String JCR_LASTMODIFIED
           
static String JCR_MIMETYPE
           
static String NT_FILE
           
static String NT_FOLDER
           
static String NT_RESOURCE
           
static String NT_UNSTRUCTURED
           
 
Constructor Summary
SlingFileUploadHandler(javax.servlet.ServletContext servletCtx)
          Constructs file upload handler
 
Method Summary
 void setFile(javax.jcr.Node parent, RequestProperty prop, List<Modification> changes)
          Uses the file(s) in the request parameter for creation of new nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NT_FOLDER

public static final String NT_FOLDER
See Also:
Constant Field Values

NT_FILE

public static final String NT_FILE
See Also:
Constant Field Values

NT_RESOURCE

public static final String NT_RESOURCE
See Also:
Constant Field Values

NT_UNSTRUCTURED

public static final String NT_UNSTRUCTURED
See Also:
Constant Field Values

JCR_CONTENT

public static final String JCR_CONTENT
See Also:
Constant Field Values

JCR_LASTMODIFIED

public static final String JCR_LASTMODIFIED
See Also:
Constant Field Values

JCR_MIMETYPE

public static final String JCR_MIMETYPE
See Also:
Constant Field Values

JCR_ENCODING

public static final String JCR_ENCODING
See Also:
Constant Field Values

JCR_DATA

public static final String JCR_DATA
See Also:
Constant Field Values
Constructor Detail

SlingFileUploadHandler

public SlingFileUploadHandler(javax.servlet.ServletContext servletCtx)
Constructs file upload handler

Parameters:
servletCtx - the post processor
Method Detail

setFile

public void setFile(javax.jcr.Node parent,
                    RequestProperty prop,
                    List<Modification> changes)
             throws javax.jcr.RepositoryException
Uses the file(s) in the request parameter for creation of new nodes. if the parent node is a nt:folder a new nt:file is created. otherwise just a nt:resource. if the name is '*', the filename of the uploaded file is used.

Parameters:
parent - the parent node
prop - the assembled property info
Throws:
javax.jcr.RepositoryException - if an error occurs


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.