<fim-prefix>ranslator.Translator;
import org.olat.core.logging.AssertException;
import org.olat.core.util.FileUtils;
import org.olat.core.util.ZipUtil;
import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.vfs.filters.VFSSystemItemFilter;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * Description:<br>
 * Provides a CreateItemForm and creates a zip file if input valid.
 * 
 * <P>
 * Initial Date:  30.01.2008 <br>
 * @author Lavinia Dumitrescu
 */
public class CmdZip extends FormBasicController implements FolderCommand {
	
	private int status = FolderCommandStatus.STATUS_SUCCESS;	

	private VFSContainer currentContainer;
	private FileSelection selection;
	private TextElement textElement;
	
	@Autowired
	private VFSRepositoryService vfsRepositoryService;
	
	protected CmdZip(UserRequest ureq, WindowControl wControl) {
		super(ureq, wControl);
	}
	
	@Override
	public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator trans) {
		setTranslator(trans);
		currentContainer = folderComponent.getCurrentContainer();
		if (currentContainer.canWrite() != VFSConstants.YES) {
			throw new AssertException("Cannot write to current folder.");
		}
		
		status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
		if(status == FolderCommandStatus.STATUS_FAILED) {
			return null;
		}
		// BUG: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
		// selection = new FileSelection(ureq, folderComponent.getCurrentContainerPath());
		// FIXED:
	<fim-middle>	selection = new FileSelection(ureq, folderComponent.getCurrentContainer(), folderComponent.getCurrentContainerPath());
		status = FolderCommandHelper.sanityCheck3(wControl, folderComponent, selection)<fix-suffix>;
		if(status == FolderCommandStatus.STATUS_FAILED) {
			return null;
		}
		
		if(selection.getFiles().isEmpty()) {
			status = FolderCommandStatus.STATUS_FAILED;
			wControl.setWarning(trans.translate("warning.file.selection.empty"));
			return null;
		}
		
		initForm(ureq);
		return this;
	}
	
	@Override
	protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
		String files = selection.renderAsHtml();
		uifactory.addStaticExampleText("zip.confirm", files, formLayout);
		
		textElement = uifactory.addTextElement("fileName", "zip.name", 20, "", formLayout);
		textElement.setMandatory(true);			
		uifactory.addStaticTextElement("extension", null, translate("zip.extension"), formLayout);
		
		FormLayoutContainer formButtons = FormLayoutContainer.createButtonLayout("formButton", getTranslator());
		formLayout.add(formButtons);
		uifactory.addFormSubmitButton("submit","zip.button", formButtons);
		uifactory.addFormCancelButton("cancel", formButtons, u<|endoftext|>