com.gantzgulch.sharing.controller.SharedFilesController.java Source code

Java tutorial

Introduction

Here is the source code for com.gantzgulch.sharing.controller.SharedFilesController.java

Source

/*
 * Copyright 2011 GantzGulch, Inc.
 * 
 * This file is part of GantzFileSharing.
 * 
 * GantzFileSharing is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GantzFileSharing is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GantzFileSharing.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.gantzgulch.sharing.controller;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.gantzgulch.sharing.domain.SharedFile;
import com.gantzgulch.sharing.service.SharedFileManager;

@Controller
@RequestMapping("/secure/files.htm")
public class SharedFilesController {

    private final SharedFileManager sharedFileManager;

    @Autowired
    public SharedFilesController(SharedFileManager sharedFileManager) {
        this.sharedFileManager = sharedFileManager;
    }

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView doGet() throws Exception {
        List<SharedFile> sharedFiles = sharedFileManager.findAll();
        Collections.sort(sharedFiles, new SharedFile.UploadDateComparator(true));
        return new ModelAndView(".files", "files", sharedFiles);
    }

}