Skip to content

Commit

Permalink
WW-4308 Extracts method and increases visibility to allow subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Aug 1, 2014
1 parent 09012d7 commit 1dd8730
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected String buildErrorMessage(Throwable e, Object[] args) {
return LocalizedTextUtil.findText(this.getClass(), errorKey, defaultLocale, e.getMessage(), args);
}

private void processUpload(HttpServletRequest request, String saveDir) throws FileUploadException, UnsupportedEncodingException {
protected void processUpload(HttpServletRequest request, String saveDir) throws FileUploadException, UnsupportedEncodingException {
for (FileItem item : parseRequest(request, saveDir)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found item " + item.getFieldName());
Expand All @@ -136,7 +136,7 @@ private void processUpload(HttpServletRequest request, String saveDir) throws Fi
}
}

private void processFileField(FileItem item) {
protected void processFileField(FileItem item) {
if (LOG.isDebugEnabled()) {
LOG.debug("Item is a file upload");
}
Expand All @@ -158,7 +158,7 @@ private void processFileField(FileItem item) {
files.put(item.getFieldName(), values);
}

private void processNormalFormField(FileItem item, String charset) throws UnsupportedEncodingException {
protected void processNormalFormField(FileItem item, String charset) throws UnsupportedEncodingException {
if (LOG.isDebugEnabled()) {
LOG.debug("Item is a normal form field");
}
Expand All @@ -182,14 +182,19 @@ private void processNormalFormField(FileItem item, String charset) throws Unsupp
item.delete();
}

private List<FileItem> parseRequest(HttpServletRequest servletRequest, String saveDir) throws FileUploadException {
protected List<FileItem> parseRequest(HttpServletRequest servletRequest, String saveDir) throws FileUploadException {
DiskFileItemFactory fac = createDiskFileItemFactory(saveDir);
ServletFileUpload upload = createServletFileUpload(fac);
return upload.parseRequest(createRequestContext(servletRequest));
}

protected ServletFileUpload createServletFileUpload(DiskFileItemFactory fac) {
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setSizeMax(maxSize);
return upload.parseRequest(createRequestContext(servletRequest));
return upload;
}

private DiskFileItemFactory createDiskFileItemFactory(String saveDir) {
protected DiskFileItemFactory createDiskFileItemFactory(String saveDir) {
DiskFileItemFactory fac = new DiskFileItemFactory();
// Make sure that the data is written to file
fac.setSizeThreshold(0);
Expand Down Expand Up @@ -350,7 +355,7 @@ private String getCanonicalName(String filename) {
* @param req the request.
* @return a new request context.
*/
private RequestContext createRequestContext(final HttpServletRequest req) {
protected RequestContext createRequestContext(final HttpServletRequest req) {
return new RequestContext() {
public String getCharacterEncoding() {
return req.getCharacterEncoding();
Expand Down

0 comments on commit 1dd8730

Please sign in to comment.