//# 1 errors, 165 messages
//#
/*
    //#uploadfileaction.java:1:1: class: net.sourceforge.pebble.web.action.UploadFileAction
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.web.action;

import net.sourceforge.pebble.Constants;
import net.sourceforge.pebble.PebbleContext;
import net.sourceforge.pebble.domain.FileManager;
import net.sourceforge.pebble.domain.FileMetaData;
import net.sourceforge.pebble.domain.Blog;
import net.sourceforge.pebble.domain.BlogManager;
import net.sourceforge.pebble.web.view.RedirectView;
import net.sourceforge.pebble.web.view.View;
import net.sourceforge.pebble.web.view.impl.FileTooLargeView;
import net.sourceforge.pebble.web.view.impl.NotEnoughSpaceView;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Iterator;
import java.util.List;

/**
 * Superclass for actions that allow the user to upload a file.
 *
 * @author    Simon Brown
 */
public abstract class UploadFileAction extends AbstractFileAction {
    //#uploadfileaction.java:63: method: void net.sourceforge.pebble.web.action.UploadFileAction.net.sourceforge.pebble.web.action.UploadFileAction()
    //#input(void net.sourceforge.pebble.web.action.UploadFileAction()): this
    //#unanalyzed(void net.sourceforge.pebble.web.action.UploadFileAction()): Effects-of-calling:net.sourceforge.pebble.web.action.SecureAction
    //#uploadfileaction.java:63: end of method: void net.sourceforge.pebble.web.action.UploadFileAction.net.sourceforge.pebble.web.action.UploadFileAction()

  private static final Log log = LogFactory.getLog(UploadFileAction.class);
    //#uploadfileaction.java:65: method: net.sourceforge.pebble.web.action.UploadFileAction.net.sourceforge.pebble.web.action.UploadFileAction__static_init
    //#uploadfileaction.java:65: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: net.sourceforge.pebble.web.action.UploadFileAction__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction]
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getLocalizedString(Ljava/lang/String;)Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getRoles(Ljavax/servlet/http/HttpServletRequest;)[Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getType()Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lnet/sourceforge/pebble/web/view/View;
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.writeFile(Lnet/sourceforge/pebble/domain/FileManager;Ljava/lang/String;Ljava/lang/String;Lorg/apache/commons/fileupload/FileItem;)V
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): log
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/AbstractFileAction.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction]
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/Action.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction]
    //#output(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/SecureAction.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction]
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/AbstractFileAction.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/Action.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): net/sourceforge/pebble/web/action/SecureAction.__Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getLocalizedString(Ljava/lang/String;)Ljava/lang/String; == &net/sourceforge/pebble/web/action/Action.getLocalizedString
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model; == &net/sourceforge/pebble/web/action/Action.getModel
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getRoles(Ljavax/servlet/http/HttpServletRequest;)[Ljava/lang/String; == &getRoles
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.getType()Ljava/lang/String; == &getType
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lnet/sourceforge/pebble/web/view/View; == &process
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V == &net/sourceforge/pebble/web/action/Action.setModel
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): __Dispatch_Table.writeFile(Lnet/sourceforge/pebble/domain/FileManager;Ljava/lang/String;Ljava/lang/String;Lorg/apache/commons/fileupload/FileItem;)V == &writeFile
    //#post(net.sourceforge.pebble.web.action.UploadFileAction__static_init): init'ed(log)
    //#uploadfileaction.java:65: end of method: net.sourceforge.pebble.web.action.UploadFileAction.net.sourceforge.pebble.web.action.UploadFileAction__static_init

  /**
   * Peforms the processing associated with this action.
   *
   * @param request  the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    //#uploadfileaction.java:75: method: View net.sourceforge.pebble.web.action.UploadFileAction.process(HttpServletRequest, HttpServletResponse)
    //#uploadfileaction.java:75: Warning: suspicious precondition
    //#    the precondition for this.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    suspicious precondition index: [5]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Descendant_Table[net/sourceforge/pebble/web/action/UploadFileAction]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Descendant_Table[net/sourceforge/pebble/web/action/UploadFileToBlogAction]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Descendant_Table[net/sourceforge/pebble/web/action/UploadFileToThemeAction]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Descendant_Table[net/sourceforge/pebble/web/action/UploadImageToBlogAction]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Descendant_Table[others]
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#input(View process(HttpServletRequest, HttpServletResponse)): __Dispatch_Table.getType()Ljava/lang/String;
    //#input(View process(HttpServletRequest, HttpServletResponse)): log
    //#input(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).__Tag
    //#input(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).configuration
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/PebbleContext.__Descendant_Table[net/sourceforge/pebble/PebbleContext]
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/PebbleContext.__Dispatch_Table.getConfiguration()Lnet/sourceforge/pebble/Configuration;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/PebbleContext.instance
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadFileToBlogAction.__Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadFileToBlogAction.__Dispatch_Table.getType()Ljava/lang/String;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadFileToThemeAction.__Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadFileToThemeAction.__Dispatch_Table.getType()Ljava/lang/String;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadImageToBlogAction.__Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/action/UploadImageToBlogAction.__Dispatch_Table.getType()Ljava/lang/String;
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/model/Model.__Descendant_Table[net/sourceforge/pebble/web/model/Model]
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/model/Model.__Descendant_Table[others]
    //#input(View process(HttpServletRequest, HttpServletResponse)): net/sourceforge/pebble/web/model/Model.__Dispatch_Table.get(Ljava/lang/String;)Ljava/lang/Object;
    //#input(View process(HttpServletRequest, HttpServletResponse)): request
    //#input(View process(HttpServletRequest, HttpServletResponse)): response
    //#input(View process(HttpServletRequest, HttpServletResponse)): this
    //#input(View process(HttpServletRequest, HttpServletResponse)): this.__Tag
    //#input(View process(HttpServletRequest, HttpServletResponse)): this.model
    //#input(View process(HttpServletRequest, HttpServletResponse)): this.model.__Tag
    //#input(View process(HttpServletRequest, HttpServletResponse)): this.model.data
    //#output(View process(HttpServletRequest, HttpServletResponse)): new FileTooLargeView(process#4) num objects
    //#output(View process(HttpServletRequest, HttpServletResponse)): new NotEnoughSpaceView(process#10) num objects
    //#output(View process(HttpServletRequest, HttpServletResponse)): new RedirectView(process#12) num objects
    //#output(View process(HttpServletRequest, HttpServletResponse)): return_value
    //#new obj(View process(HttpServletRequest, HttpServletResponse)): new FileTooLargeView(process#4)
    //#new obj(View process(HttpServletRequest, HttpServletResponse)): new NotEnoughSpaceView(process#10)
    //#new obj(View process(HttpServletRequest, HttpServletResponse)): new RedirectView(process#12)
    //#pre[5] (View process(HttpServletRequest, HttpServletResponse)): this.__Tag in {net/sourceforge/pebble/web/action/UploadFileAction, net/sourceforge/pebble/web/action/UploadFileToBlogAction, net/sourceforge/pebble/web/action/UploadFileToThemeAction, net/sourceforge/pebble/web/action/UploadImageToBlogAction}
    //#pre[6] (View process(HttpServletRequest, HttpServletResponse)): this.model != null
    //#pre[7] (View process(HttpServletRequest, HttpServletResponse)): this.model.__Tag == net/sourceforge/pebble/web/model/Model
    //#pre[8] (View process(HttpServletRequest, HttpServletResponse)): this.model.data != null
    //#pre[1] (View process(HttpServletRequest, HttpServletResponse)): (soft) net.sourceforge.pebble.PebbleContext__static_init.new PebbleContext(PebbleContext__static_init#1).configuration != null
    //#pre[3] (View process(HttpServletRequest, HttpServletResponse)): (soft) response != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): java.lang.Integer:parseInt(...)@105 in 0..9
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): java.lang.Integer:parseInt(...)@119 in 0..9
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): java.util.HashMap:get(...)@63 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): java.util.Iterator:next(...)@103 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): java.util.Iterator:next(...)@116 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.Configuration:getFileUploadSize(...)@88 in -8_388_608..16_777_215
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.domain.FileManager:getFileMetaData(...)@155 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.DiskFileUpload:parseRequest(...)@95 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@104 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@105 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@105 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@108 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@118 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@119 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getFieldName(...)@119 != null
    //#presumption(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.logging.LogFactory:getLog(...)@65 != null
    //#post(View process(HttpServletRequest, HttpServletResponse)): return_value in Addr_Set{null,&new NotEnoughSpaceView(process#10),&new FileTooLargeView(process#4),&new RedirectView(process#12)}
    //#post(View process(HttpServletRequest, HttpServletResponse)): new FileTooLargeView(process#4) num objects <= 1
    //#post(View process(HttpServletRequest, HttpServletResponse)): new NotEnoughSpaceView(process#10) num objects <= 1
    //#post(View process(HttpServletRequest, HttpServletResponse)): new RedirectView(process#12) num objects <= 1
    //#unanalyzed(View process(HttpServletRequest, HttpServletResponse)): Effects-of-calling:net.sourceforge.pebble.domain.FileManager:getFile
    //#unanalyzed(View process(HttpServletRequest, HttpServletResponse)): Effects-of-calling:java.io.File:mkdirs
    //#unanalyzed(View process(HttpServletRequest, HttpServletResponse)): Effects-of-calling:java.io.File
    //#unanalyzed(View process(HttpServletRequest, HttpServletResponse)): Effects-of-calling:org.apache.commons.fileupload.FileItem:write
    //#unanalyzed(View process(HttpServletRequest, HttpServletResponse)): Effects-of-calling:java.util.HashMap:get
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.lang.String:equals(...)@108: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.lang.String:equals(...)@140: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.lang.String:length(...)@123: {1..4_294_967_295}, {0}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.lang.String:startsWith(...)@104: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.lang.String:startsWith(...)@118: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.util.Iterator:hasNext(...)@102: {1}, {0}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): java.util.Iterator:hasNext(...)@115: {1}, {0}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.domain.FileManager:hasEnoughSpace(...)@135: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): net.sourceforge.pebble.domain.FileManager:isUnderneathRootDirectory(...)@129: {1}, {0}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:getSize(...)@118: {-9_223_372_036_854_775_808..0}, {1..18_446_744_073_709_551_615}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:isFormField(...)@104: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:isFormField(...)@108: {0}, {1}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileItem:isFormField(...)@118: {1}, {0}
    //#test_vector(View process(HttpServletRequest, HttpServletResponse)): org.apache.commons.fileupload.FileUpload:isMultipartContent(...)@84: {0}, {1}

    String type = getType();
    //#uploadfileaction.java:77: Warning: method not available
    //#    -- call on String getType()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String getType()
    String path = "";
    String[] filenames = new String[10];

    FileManager fileManager = new FileManager(blog, type);
    //#uploadfileaction.java:81: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.domain.FileManager(Blog, String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.domain.FileManager(Blog, String)

    try {
      boolean isMultipart = FileUpload.isMultipartContent(request);
    //#uploadfileaction.java:84: Warning: method not available
    //#    -- call on bool org.apache.commons.fileupload.FileUpload:isMultipartContent(HttpServletRequest)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool org.apache.commons.fileupload.FileUpload:isMultipartContent(HttpServletRequest)

      if (isMultipart) {
        DiskFileUpload upload = new DiskFileUpload();
    //#uploadfileaction.java:87: Warning: method not available
    //#    -- call on void org.apache.commons.fileupload.DiskFileUpload()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.fileupload.DiskFileUpload()
        long sizeInBytes = PebbleContext.getInstance().getConfiguration().getFileUploadSize() * 1024; // convert to bytes
    //#uploadfileaction.java:88: Warning: method not available
    //#    -- call on long net.sourceforge.pebble.Configuration:getFileUploadSize()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: long net.sourceforge.pebble.Configuration:getFileUploadSize()
        upload.setSizeMax(sizeInBytes);
    //#uploadfileaction.java:89: Warning: method not available
    //#    -- call on void org.apache.commons.fileupload.DiskFileUpload:setSizeMax(long)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.fileupload.DiskFileUpload:setSizeMax(long)
        upload.setSizeThreshold((int)sizeInBytes/4);
    //#uploadfileaction.java:90: Warning: method not available
    //#    -- call on void org.apache.commons.fileupload.DiskFileUpload:setSizeThreshold(int)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.fileupload.DiskFileUpload:setSizeThreshold(int)
        upload.setRepositoryPath(System.getProperty("java.io.tmpdir"));
    //#uploadfileaction.java:91: Warning: method not available
    //#    -- call on void org.apache.commons.fileupload.DiskFileUpload:setRepositoryPath(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.fileupload.DiskFileUpload:setRepositoryPath(String)

        List items;
        try {
          items = upload.parseRequest(request);
    //#uploadfileaction.java:95: Warning: method not available
    //#    -- call on List org.apache.commons.fileupload.DiskFileUpload:parseRequest(HttpServletRequest)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: List org.apache.commons.fileupload.DiskFileUpload:parseRequest(HttpServletRequest)
        } catch (FileUploadBase.SizeLimitExceededException e) {
          return new FileTooLargeView();
    //#uploadfileaction.java:97: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.web.view.impl.FileTooLargeView()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.web.view.impl.FileTooLargeView()
        }

        // find the form fields first
        Iterator it = items.iterator();
        while (it.hasNext()) {
          FileItem item = (FileItem)it.next();
          if (item.isFormField() && item.getFieldName().startsWith("filename")) {
    //#uploadfileaction.java:104: Warning: method not available
    //#    -- call on bool org.apache.commons.fileupload.FileItem:isFormField()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool org.apache.commons.fileupload.FileItem:isFormField()
    //#uploadfileaction.java:104: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getFieldName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getFieldName()
            int index = Integer.parseInt(item.getFieldName().substring(item.getFieldName().length()-1));
    //#uploadfileaction.java:105: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getFieldName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getFieldName()
            filenames[index] = item.getString();
    //#uploadfileaction.java:106: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getString()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getString()
            log.debug("index is " + index + ", filename is " + filenames[index]);
    //#uploadfileaction.java:107: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
          } else if (item.isFormField() && item.getFieldName().equals("path")) {
    //#uploadfileaction.java:108: Warning: method not available
    //#    -- call on bool org.apache.commons.fileupload.FileItem:isFormField()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool org.apache.commons.fileupload.FileItem:isFormField()
    //#uploadfileaction.java:108: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getFieldName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getFieldName()
            path = item.getString();
    //#uploadfileaction.java:109: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getString()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getString()
          }
        }

        // now the actual files
        it = items.iterator();
        while (it.hasNext()) {
          FileItem item = (FileItem)it.next();

          if (!item.isFormField() && item.getSize() > 0 && item.getFieldName().startsWith("file")) {
    //#uploadfileaction.java:118: Warning: method not available
    //#    -- call on bool org.apache.commons.fileupload.FileItem:isFormField()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool org.apache.commons.fileupload.FileItem:isFormField()
    //#uploadfileaction.java:118: Warning: method not available
    //#    -- call on long org.apache.commons.fileupload.FileItem:getSize()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: long org.apache.commons.fileupload.FileItem:getSize()
    //#uploadfileaction.java:118: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getFieldName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getFieldName()
            int index = Integer.parseInt(item.getFieldName().substring(item.getFieldName().length()-1));
    //#uploadfileaction.java:119: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getFieldName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getFieldName()

            // if the filename hasn't been specified, use that from the file
            // being uploaded
            if (filenames[index] == null || filenames[index].length() == 0) {
    //#uploadfileaction.java:123: ?use of default init
    //#    init'ed(filenames[index])
    //#    severity: SUPPRESSED
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    basic block: bb_19
    //#    assertion: init'ed(filenames[index])
    //#    VN: filenames[index]
    //#    Expected: Univ-VN-Set
    //#    Bad: {Invalid}
    //#    Attribs:  Ptr  Bad only invalid  Uncertain
              filenames[index] = item.getName();
    //#uploadfileaction.java:124: Warning: method not available
    //#    -- call on String org.apache.commons.fileupload.FileItem:getName()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String org.apache.commons.fileupload.FileItem:getName()
            }

            File destinationDirectory = fileManager.getFile(path);
    //#uploadfileaction.java:127: Warning: method not available
    //#    -- call on File net.sourceforge.pebble.domain.FileManager:getFile(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: File net.sourceforge.pebble.domain.FileManager:getFile(String)
            File file = new File(destinationDirectory, filenames[index]);
            if (!fileManager.isUnderneathRootDirectory(file)) {
    //#uploadfileaction.java:129: Warning: method not available
    //#    -- call on bool net.sourceforge.pebble.domain.FileManager:isUnderneathRootDirectory(File)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool net.sourceforge.pebble.domain.FileManager:isUnderneathRootDirectory(File)
              response.setStatus(HttpServletResponse.SC_FORBIDDEN);
              return null;
            }

            long itemSize = item.getSize()/1024;
    //#uploadfileaction.java:134: Warning: method not available
    //#    -- call on long org.apache.commons.fileupload.FileItem:getSize()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: long org.apache.commons.fileupload.FileItem:getSize()
            if (FileManager.hasEnoughSpace(blog, itemSize)) {
    //#uploadfileaction.java:135: Warning: method not available
    //#    -- call on bool net.sourceforge.pebble.domain.FileManager:hasEnoughSpace(Blog, double)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: bool net.sourceforge.pebble.domain.FileManager:hasEnoughSpace(Blog, double)
              log.debug("Writing file " + filenames[index] + ", size is " + item.getSize());
    //#uploadfileaction.java:136: Warning: method not available
    //#    -- call on long org.apache.commons.fileupload.FileItem:getSize()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: long org.apache.commons.fileupload.FileItem:getSize()
    //#uploadfileaction.java:136: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
              writeFile(fileManager, path, filenames[index], item);

              // if it's a theme file, also create a copy in blog.dir/theme
              if (type.equals(FileMetaData.THEME_FILE)) {
                writeFile(new FileManager(blog, FileMetaData.BLOG_DATA), "/theme" + path, filenames[index], item);
    //#uploadfileaction.java:141: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.domain.FileManager(Blog, String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.domain.FileManager(Blog, String)
              }
            } else {
              return new NotEnoughSpaceView();
    //#uploadfileaction.java:144: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.web.view.impl.NotEnoughSpaceView()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.web.view.impl.NotEnoughSpaceView()
            }
          }
        }
      }

      blog.info("Files uploaded.");
    //#uploadfileaction.java:150: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.domain.Blog:info(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.domain.Blog:info(String)
    } catch (Exception e) {
      throw new ServletException(e);
    }

    FileMetaData directory = fileManager.getFileMetaData(path);
    //#uploadfileaction.java:155: Warning: method not available
    //#    -- call on FileMetaData net.sourceforge.pebble.domain.FileManager:getFileMetaData(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: FileMetaData net.sourceforge.pebble.domain.FileManager:getFileMetaData(String)

    return new RedirectView(blog.getUrl() + directory.getUrl());
    //#uploadfileaction.java:157: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.Blog:getUrl()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.Blog:getUrl()
    //#uploadfileaction.java:157: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.domain.FileMetaData:getUrl()
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: String net.sourceforge.pebble.domain.FileMetaData:getUrl()
    //#uploadfileaction.java:157: Warning: method not available
    //#    -- call on void net.sourceforge.pebble.web.view.RedirectView(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: View process(HttpServletRequest, HttpServletResponse)
    //#    unanalyzed callee: void net.sourceforge.pebble.web.view.RedirectView(String)
    //#uploadfileaction.java:157: end of method: View net.sourceforge.pebble.web.action.UploadFileAction.process(HttpServletRequest, HttpServletResponse)
  }

  /**
   * Helper method to write a file.
   *
   * @param fileManager   a FileManager instance
   * @param path          the path where to save the file
   * @param filename      the filename
   * @param item          the uploaded item
   * @throws Exception    if something goes wrong writing the file
   */
  private void writeFile(FileManager fileManager, String path, String filename, FileItem item) throws Exception {
    File destinationDirectory = fileManager.getFile(path);
    //#uploadfileaction.java:170: method: void net.sourceforge.pebble.web.action.UploadFileAction.writeFile(FileManager, String, String, FileItem)
    //#uploadfileaction.java:170: Warning: method not available
    //#    -- call on File net.sourceforge.pebble.domain.FileManager:getFile(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: void writeFile(FileManager, String, String, FileItem)
    //#    unanalyzed callee: File net.sourceforge.pebble.domain.FileManager:getFile(String)
    //#input(void writeFile(FileManager, String, String, FileItem)): fileManager
    //#input(void writeFile(FileManager, String, String, FileItem)): filename
    //#input(void writeFile(FileManager, String, String, FileItem)): item
    //#input(void writeFile(FileManager, String, String, FileItem)): path
    //#pre[1] (void writeFile(FileManager, String, String, FileItem)): fileManager != null
    //#pre[3] (void writeFile(FileManager, String, String, FileItem)): item != null
    //#presumption(void writeFile(FileManager, String, String, FileItem)): net.sourceforge.pebble.domain.FileManager:getFile(...)@170 != null
    destinationDirectory.mkdirs();

    File file = new File(destinationDirectory, filename);
    item.write(file);
    //#uploadfileaction.java:174: Warning: method not available
    //#    -- call on void org.apache.commons.fileupload.FileItem:write(File)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.UploadFileAction
    //#    method: void writeFile(FileManager, String, String, FileItem)
    //#    unanalyzed callee: void org.apache.commons.fileupload.FileItem:write(File)
  }
    //#uploadfileaction.java:175: end of method: void net.sourceforge.pebble.web.action.UploadFileAction.writeFile(FileManager, String, String, FileItem)

  /**
   * Gets the type of this upload (blog image, blog file or theme file).
   *
   * @return    a String representing the type
   * @see       net.sourceforge.pebble.domain.FileMetaData
   */
  protected abstract String getType();

  /**
   * Gets a list of all roles that are allowed to access this action.
   *
   * @return  an array of Strings representing role names
   */
  public abstract String[] getRoles(HttpServletRequest request);

}    //#uploadfileaction.java:: end of class: net.sourceforge.pebble.web.action.UploadFileAction
