Java Code Examples for org.springframework.web.bind.ServletRequestUtils#getRequiredIntParameter()

The following examples show how to use org.springframework.web.bind.ServletRequestUtils#getRequiredIntParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(path = "/getAlbumInfo")
public void getAlbumInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");

    MediaFile mediaFile = this.mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, SubsonicRESTController.ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    AlbumNotes albumNotes = this.lastFmService.getAlbumNotes(mediaFile);

    AlbumInfo result = getAlbumInfoInternal(albumNotes);
    Response res = createResponse();
    res.setAlbumInfo(result);
    this.jaxbWriter.writeResponse(request, response, res);
}
 
Example 2
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(path = "/getAlbumInfo2")
public void getAlbumInfo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");

    Album album = this.albumDao.getAlbum(id);
    if (album == null) {
        error(request, response, SubsonicRESTController.ErrorCode.NOT_FOUND, "Album not found.");
        return;
    }
    AlbumNotes albumNotes = this.lastFmService.getAlbumNotes(album);

    AlbumInfo result = getAlbumInfoInternal(albumNotes);
    Response res = createResponse();
    res.setAlbumInfo(result);
    this.jaxbWriter.writeResponse(request, response, res);
}
 
Example 3
Source File: PlaylistController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound"));
    }

    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.getPartyModeEnabled());
    map.put("initialPaginationSize", userSettings.getPaginationSize());

    return new ModelAndView("playlist","model",map);
}
 
Example 4
Source File: ExportPlayListController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Playlist playlist = playlistService.getPlaylist(id);
    if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;

    }
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\"");

    playlistService.exportPlaylist(id, response.getOutputStream());
    return null;
}
 
Example 5
Source File: PlaylistController.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound.view"));
    }

    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.isPartyModeEnabled());

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
}
 
Example 6
Source File: EditTagsController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile dir = mediaFileService.getMediaFile(id);
    List<MediaFile> files = mediaFileService.getChildrenOf(dir, true, false, true, false);

    Map<String, Object> map = new HashMap<String, Object>();
    if (!files.isEmpty()) {
        map.put("defaultArtist", files.get(0).getArtist());
        map.put("defaultAlbum", files.get(0).getAlbumName());
        map.put("defaultYear", files.get(0).getYear());
        map.put("defaultGenre", files.get(0).getGenre());
    }
    map.put("allGenres", JaudiotaggerParser.getID3V1Genres());

    List<Song> songs = new ArrayList<Song>();
    for (int i = 0; i < files.size(); i++) {
        songs.add(createSong(files.get(i), i));
    }
    map.put("id", id);
    map.put("songs", songs);

    return new ModelAndView("editTags","model",map);
}
 
Example 7
Source File: ChangeCoverArtController.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String artist = request.getParameter("artist");
    String album = request.getParameter("album");
    MediaFile dir = mediaFileService.getMediaFile(id);

    if (StringUtils.isBlank(artist)) {
        artist = dir.getArtist();
    }
    if (StringUtils.isBlank(album)) {
        album = dir.getAlbumName();
    }

    Map<String, Object> map = new HashMap<>();
    map.put("id", id);
    map.put("artist", artist);
    map.put("album", album);


    return new ModelAndView("changeCoverArt","model",map);
}
 
Example 8
Source File: VideoPlayerController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = securityService.getCurrentUser(request);
    Map<String, Object> map = new HashMap<String, Object>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile file = mediaFileService.getMediaFile(id);
    mediaFileService.populateStarredDate(file, user.getUsername());

    Double duration = file.getDuration();
    Integer playerId = playerService.getPlayer(request, response).getId();
    String url = NetworkService.getBaseUrl(request);
    String streamUrl = url + "stream?id=" + file.getId() + "&player=" + playerId + "&format=mp4";
    String coverArtUrl = url + "coverArt.view?id=" + file.getId();

    map.put("video", file);
    map.put("streamUrl", streamUrl);
    map.put("remoteStreamUrl", streamUrl);
    map.put("remoteCoverArtUrl", coverArtUrl);
    map.put("duration", duration);
    map.put("bitRates", BIT_RATES);
    map.put("defaultBitRate", DEFAULT_BIT_RATE);
    map.put("user", user);

    return new ModelAndView("videoPlayer", "model", map);
}
 
Example 9
Source File: ExportPlayListController.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping
public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Playlist playlist = playlistService.getPlaylist(id);
    if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;

    }
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\"");

    playlistService.exportPlaylist(id, response.getOutputStream());
    return null;
}
 
Example 10
Source File: PodcastChannelController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<>();
    ModelAndView result = new ModelAndView();
    result.addObject("model", map);

    int channelId = ServletRequestUtils.getRequiredIntParameter(request, "id");

    map.put("user", securityService.getCurrentUser(request));
    map.put("channel", podcastService.getChannel(channelId));
    map.put("episodes", podcastService.getEpisodes(channelId));
    return result;
}
 
Example 11
Source File: RandomPlayQueueController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
private List<MusicFolder> getMusicFolders(HttpServletRequest request) throws ServletRequestBindingException {
    String username = securityService.getCurrentUsername(request);
    Integer selectedMusicFolderId = ServletRequestUtils.getRequiredIntParameter(request, "musicFolderId");
    if (selectedMusicFolderId == -1) {
        selectedMusicFolderId = null;
    }
    return settingsService.getMusicFoldersForUser(username, selectedMusicFolderId);
}
 
Example 12
Source File: SetMusicFileInfoController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@PostMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);

    if ("comment".equals(action)) {
        mediaFile.setComment(StringEscapeUtils.escapeHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }

    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}
 
Example 13
Source File: SetMusicFileInfoController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);

    if ("comment".equals(action)) {
        mediaFile.setComment(StringUtil.toHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }

    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}
 
Example 14
Source File: PodcastChannelController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();
    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);

    int channelId = ServletRequestUtils.getRequiredIntParameter(request, "id");

    map.put("user", securityService.getCurrentUser(request));
    map.put("channel", podcastService.getChannel(channelId));
    map.put("episodes", podcastService.getEpisodes(channelId));
    return result;
}
 
Example 15
Source File: MultiController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {

        int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
        Playlist playlist = playlistService.getPlaylist(id);
        if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return null;

        }
        response.setContentType("application/x-download");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\"");

        playlistService.exportPlaylist(id, response.getOutputStream());
        return null;
    }
 
Example 16
Source File: RandomPlayQueueController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private List<MusicFolder> getMusicFolders(HttpServletRequest request) throws ServletRequestBindingException {
    String username = securityService.getCurrentUsername(request);
    Integer selectedMusicFolderId = ServletRequestUtils.getRequiredIntParameter(request, "musicFolderId");
    if (selectedMusicFolderId == -1) {
        selectedMusicFolderId = null;
    }
    return settingsService.getMusicFoldersForUser(username, selectedMusicFolderId);
}
 
Example 17
Source File: SetRatingController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Integer rating = ServletRequestUtils.getIntParameter(request, "rating");
    if (rating == 0) {
        rating = null;
    }
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    String username = securityService.getCurrentUsername(request);
    ratingService.setRatingForUser(username, mediaFile, rating);

    return new ModelAndView(new RedirectView("main.view?id=" + id));
}
 
Example 18
Source File: SetRatingController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Integer rating = ServletRequestUtils.getIntParameter(request, "rating");
    if (rating == 0) {
        rating = null;
    }

    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    String username = securityService.getCurrentUsername(request);
    ratingService.setRatingForUser(username, mediaFile, rating);

    return new ModelAndView(new RedirectView("main.view?id=" + id));
}
 
Example 19
Source File: VideoPlayerController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = securityService.getCurrentUser(request);
    Map<String, Object> map = new HashMap<String, Object>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile file = mediaFileService.getMediaFile(id);
    mediaFileService.populateStarredDate(file, user.getUsername());

    Integer duration = file.getDurationSeconds();
    String playerId = playerService.getPlayer(request, response).getId();
    String url = request.getRequestURL().toString();
    String streamUrl = url.replaceFirst("/videoPlayer.view.*", "/stream?id=" + file.getId() + "&player=" + playerId);
    String coverArtUrl = url.replaceFirst("/videoPlayer.view.*", "/coverArt.view?id=" + file.getId());

    // Rewrite URLs in case we're behind a proxy.
    if (settingsService.isRewriteUrlEnabled()) {
        String referer = request.getHeader("referer");
        streamUrl = StringUtil.rewriteUrl(streamUrl, referer);
        coverArtUrl = StringUtil.rewriteUrl(coverArtUrl, referer);
    }

    String remoteStreamUrl = settingsService.rewriteRemoteUrl(streamUrl);
    String remoteCoverArtUrl = settingsService.rewriteRemoteUrl(coverArtUrl);

    map.put("video", file);
    map.put("streamUrl", streamUrl);
    map.put("remoteStreamUrl", remoteStreamUrl);
    map.put("remoteCoverArtUrl", remoteCoverArtUrl);
    map.put("duration", duration);
    map.put("bitRates", BIT_RATES);
    map.put("defaultBitRate", DEFAULT_BIT_RATE);
    map.put("licenseInfo", settingsService.getLicenseInfo());
    map.put("user", user);

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
}
 
Example 20
Source File: SetMusicFileInfoController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@PostMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);

    if ("comment".equals(action)) {
        mediaFile.setComment(StringEscapeUtils.escapeHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }

    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}