From 449f6a906abe2a8a9ba353d8a79676d97bbf1dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:31:39 +0100 Subject: [PATCH] Controllers migration. --- .../controller/AvatarUploadController.java | 22 +++++----- .../controller/DLNASettingsController.java | 22 +++++----- .../player/controller/EditTagsController.java | 43 +++++++++--------- .../InternetRadioSettingsController.java | 19 ++++---- .../controller/ShareSettingsController.java | 33 ++++++-------- .../controller/SonosSettingsController.java | 23 +++++----- .../TranscodingSettingsController.java | 23 +++++----- .../src/main/resources/libresonic-servlet.xml | 44 ------------------- 8 files changed, 87 insertions(+), 142 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java index 1c829ba9..b20d469c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java @@ -30,6 +30,10 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; +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 org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -50,15 +54,19 @@ import java.util.Map; * * @author Sindre Mehus */ -public class AvatarUploadController extends ParameterizableViewController { +@Controller +@RequestMapping("/avatarUpload") +public class AvatarUploadController { private static final Logger LOG = Logger.getLogger(AvatarUploadController.class); private static final int MAX_AVATAR_SIZE = 64; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String username = securityService.getCurrentUsername(request); @@ -93,9 +101,7 @@ public class AvatarUploadController extends ParameterizableViewController { map.put("username", username); map.put("avatar", settingsService.getCustomAvatar(username)); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("avatarUploadResult","model",map); } private void createAvatar(String fileName, byte[] data, String username, Map map) throws IOException { @@ -132,11 +138,5 @@ public class AvatarUploadController extends ParameterizableViewController { } } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java index 8995c462..4b1deaca 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java @@ -25,7 +25,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -37,12 +41,16 @@ import org.libresonic.player.service.UPnPService; * * @author Sindre Mehus */ -public class DLNASettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/dlnaSettings") +public class DLNASettingsController { + @Autowired private UPnPService upnpService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -52,13 +60,11 @@ public class DLNASettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("dlnaEnabled", settingsService.isDlnaEnabled()); map.put("dlnaServerName", settingsService.getDlnaServerName()); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("dlnaSettings","model",map); } /** @@ -85,11 +91,5 @@ public class DLNASettingsController extends ParameterizableViewController { upnpService.setMediaServerEnabled(dlnaEnabled); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setUpnpService(UPnPService upnpService) { - this.upnpService = upnpService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java index 19f5365d..1edacc7c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java @@ -19,35 +19,41 @@ */ package org.libresonic.player.controller; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.FilenameUtils; -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.metadata.JaudiotaggerParser; import org.libresonic.player.service.metadata.MetaDataParser; import org.libresonic.player.service.metadata.MetaDataParserFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Controller for the page used to edit MP3 tags. * * @author Sindre Mehus */ -public class EditTagsController extends ParameterizableViewController { +@Controller +@RequestMapping("/editTags") +public class EditTagsController { + @Autowired private MetaDataParserFactory metaDataParserFactory; + @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -70,9 +76,7 @@ public class EditTagsController extends ParameterizableViewController { map.put("id", id); map.put("songs", songs); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("editTags","model",map); } private Song createSong(MediaFile file, int index) { @@ -92,13 +96,6 @@ public class EditTagsController extends ParameterizableViewController { return song; } - public void setMetaDataParserFactory(MetaDataParserFactory metaDataParserFactory) { - this.metaDataParserFactory = metaDataParserFactory; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } /** * Contains information about a single song. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java index 649605b9..3ae969bd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java @@ -22,6 +22,10 @@ package org.libresonic.player.controller; import org.libresonic.player.domain.InternetRadio; import org.libresonic.player.service.SettingsService; import org.apache.commons.lang.StringUtils; +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 org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -37,11 +41,14 @@ import java.util.Map; * * @author Sindre Mehus */ -public class InternetRadioSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/internetRadioSettings") +public class InternetRadioSettingsController { + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -54,11 +61,8 @@ public class InternetRadioSettingsController extends ParameterizableViewControll } } - ModelAndView result = super.handleRequestInternal(request, response); map.put("internetRadios", settingsService.getAllInternetRadios(true)); - - result.addObject("model", map); - return result; + return new ModelAndView("internetRadioSettings","model",map); } /** @@ -116,8 +120,5 @@ public class InternetRadioSettingsController extends ParameterizableViewControll return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java index 19113a73..b753b743 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java @@ -30,7 +30,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -48,14 +52,20 @@ import org.libresonic.player.service.ShareService; * * @author Sindre Mehus */ -public class ShareSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/shareSettings") +public class ShareSettingsController { + @Autowired private ShareService shareService; + @Autowired private SecurityService securityService; + @Autowired private MediaFileService mediaFileService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -65,14 +75,12 @@ public class ShareSettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("shareBaseUrl", shareService.getShareBaseUrl()); map.put("shareInfos", getShareInfos(request)); map.put("user", securityService.getCurrentUser(request)); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("shareSettings","model",map); } /** @@ -148,21 +156,6 @@ public class ShareSettingsController extends ParameterizableViewController { return calendar.getTime(); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } public static class ShareInfo { private final Share share; diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java index eb8226b6..36cc02e8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java @@ -25,7 +25,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -37,12 +41,16 @@ import org.libresonic.player.service.SonosService; * * @author Sindre Mehus */ -public class SonosSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/sonosSettings") +public class SonosSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private SonosService sonosService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -52,13 +60,11 @@ public class SonosSettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("sonosEnabled", settingsService.isSonosEnabled()); map.put("sonosServiceName", settingsService.getSonosServiceName()); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("sonosSettings","model",map); } /** @@ -86,11 +92,4 @@ public class SonosSettingsController extends ParameterizableViewController { sonosService.setMusicServiceEnabled(sonosEnabled); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSonosService(SonosService sonosService) { - this.sonosService = sonosService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java index bd28e172..68b1dfb6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java @@ -23,6 +23,10 @@ import org.libresonic.player.domain.Transcoding; import org.libresonic.player.service.TranscodingService; import org.libresonic.player.service.SettingsService; import org.apache.commons.lang.StringUtils; +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 org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -36,12 +40,16 @@ import java.util.Map; * * @author Sindre Mehus */ -public class TranscodingSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/transcodingSettings") +public class TranscodingSettingsController { + @Autowired private TranscodingService transcodingService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -51,15 +59,13 @@ public class TranscodingSettingsController extends ParameterizableViewController map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("transcodings", transcodingService.getAllTranscodings()); map.put("transcodeDirectory", transcodingService.getTranscodeDirectory()); map.put("downsampleCommand", settingsService.getDownsamplingCommand()); map.put("hlsCommand", settingsService.getHlsCommand()); map.put("brand", settingsService.getBrand()); - result.addObject("model", map); - return result; + return new ModelAndView("transcodingSettings","model",map); } /** @@ -136,11 +142,4 @@ public class TranscodingSettingsController extends ParameterizableViewController return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); } - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index ab2adc2d..e19ca95e 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,43 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -166,13 +129,6 @@ multiController multiController videoPlayerController - dlnaSettingsController - sonosSettingsController - shareSettingsController - transcodingSettingsController - internetRadioSettingsController - avatarUploadController - editTagsController avatarController proxyController statusChartController