* BAEL-86

* Added Themes and Beans

* Improvements and fully tested locally
This commit is contained in:
Adam InTae Gerard 2017-04-21 22:00:42 -05:00 committed by KevinGilmore
parent caab7829e7
commit 7a96484ba3
42 changed files with 384 additions and 1203 deletions

View File

@ -0,0 +1,3 @@
## Relevant articles:
- [Spring DispatcherServlet](http://www.baeldung.com/spring-dispatcher-servlet)

View File

@ -1,96 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>spring-dispatcher-servlet</artifactId>
<packaging>war</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<version>1.0.0</version>
<name>spring-dispatcher-servlet</name>
<properties>
<springframework.version>4.3.7.RELEASE</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
<scope>provided</scope>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>${thymeleaf.version}</version>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1655215</version>
<configuration>
<path>/springdispatcherservlet</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>springdispatcherservlet</finalName>
</build>
<properties>
<!-- Spring -->
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<!-- logging -->
<org.slf4j.version>1.7.21</org.slf4j.version>
<!-- various -->
<javax.servlet.version>3.1.0</javax.servlet.version>
<!-- Maven plugins -->
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
<jetty-maven-plugin.version>9.3.14.v20161028</jetty-maven-plugin.version>
</properties>
</project>
</project>

View File

@ -1,30 +0,0 @@
package com.baeldung.spring.dispatcher.servlet;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class DispatcherServletApplication implements org.springframework.web.WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(RootConfiguration.class);
servletContext.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext webContext =
new AnnotationConfigWebApplicationContext();
webContext.register(WebConfiguration.class);
DispatcherServlet dispatcherServlet = new DispatcherServlet(webContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher",
dispatcherServlet);
servlet.addMapping("/*");
MultipartConfigElement multipartConfigElement =
new MultipartConfigElement("/tmp");
servlet.setMultipartConfig(multipartConfigElement);
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.spring.dispatcher.servlet;
import com.baeldung.spring.dispatcher.servlet.models.Task;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.*;
@Configuration
public class RootConfiguration {
@Bean
public Map<String, List<Task>> taskList() {
Map<String, List<Task>> taskMap = new HashMap<>();
List<Task> taskList = new ArrayList<>();
taskList.add(new Task("Clean the dishes!", new Date()));
taskMap.put("Cid", taskList);
return taskMap;
}
}

View File

@ -1,129 +0,0 @@
package com.baeldung.spring.dispatcher.servlet;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.ui.context.support.ResourceBundleThemeSource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import org.springframework.web.servlet.theme.CookieThemeResolver;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
import javax.servlet.ServletContext;
import java.util.Locale;
@Configuration
@ComponentScan("com.baeldung.spring.dispatcher.servlet.web")
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/public/**")
.addResourceLocations("/public/");
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
registry.addInterceptor(themeChangeInterceptor());
}
@Bean
public ServletContextTemplateResolver templateResolver(ServletContext servletContext) {
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(servletContext);
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine(ServletContextTemplateResolver templateResolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
return templateEngine;
}
@Bean
public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine);
return viewResolver;
}
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
messageSource.setFallbackToSystemLocale(false);
return messageSource;
}
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setDefaultLocale(Locale.ENGLISH);
localeResolver.setCookieName("locale");
localeResolver.setCookieMaxAge(-1);
return localeResolver;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
localeChangeInterceptor.setIgnoreInvalidLocale(true);
return localeChangeInterceptor;
}
@Bean
public ResourceBundleThemeSource themeSource() {
ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource();
themeSource.setBasenamePrefix("theme-");
themeSource.setFallbackToSystemLocale(false);
return themeSource;
}
@Bean
public ThemeResolver themeResolver() {
CookieThemeResolver themeResolver = new CookieThemeResolver();
themeResolver.setDefaultThemeName("robotask");
themeResolver.setCookieName("theme");
themeResolver.setCookieMaxAge(-1);
return themeResolver;
}
@Bean
public ThemeChangeInterceptor themeChangeInterceptor() {
ThemeChangeInterceptor themeChangeInterceptor = new ThemeChangeInterceptor();
themeChangeInterceptor.setParamName("theme");
return themeChangeInterceptor;
}
@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
@Bean
public HandlerExceptionResolver handlerExceptionResolver() {
return new ExceptionHandlerExceptionResolver();
}
}

View File

@ -1,58 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.models;
import java.util.UUID;
public class Attachment {
private String id;
private String name;
private String description;
public Attachment() {
this.id = UUID.randomUUID().toString();
}
public Attachment(String name, String description) {
this();
this.name = name;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Attachment that = (Attachment) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return id.hashCode();
}
}

View File

@ -1,52 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.models;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
public class Task {
private String description;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm")
private Date due;
private Set<Attachment> attachments = new HashSet<>();
public Task() {
}
public Task(Date due) {
this.due = due;
}
public Task(String description, Date due) {
this.description = description;
this.due = due;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getDue() {
return due;
}
public void setDue(Date due) {
this.due = due;
}
public Set<Attachment> getAttachments() {
return attachments;
}
public void setAttachments(Set<Attachment> attachments) {
this.attachments = attachments;
}
}

View File

@ -1,17 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping("/attachments")
public interface AttachmentController {
@GetMapping("/{attachmentId}")
ResponseEntity<FileSystemResource> getAttachment(
@PathVariable("attachmentId") String attachmentId,
@RequestParam(name = "download", required = false, defaultValue = "false") boolean forcedDownload
);
}

View File

@ -1,45 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import com.baeldung.spring.dispatcher.servlet.models.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import java.net.URLConnection;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Controller
public class AttachmentControllerImpl implements AttachmentController {
@Autowired
private Map<String, List<Task>> taskMap;
@Override
public ResponseEntity<FileSystemResource> getAttachment(
@PathVariable("attachmentId") String attachmentId,
@RequestParam(name = "download", required = false, defaultValue = "false") boolean forcedDownload
) {
FileSystemResource resource = new FileSystemResource("/tmp/" + attachmentId);
HttpHeaders headers = new HttpHeaders();
taskMap.values().stream()
.flatMap(Collection::stream)
.flatMap(t -> t.getAttachments().stream())
.filter(a -> a.getId().equals(attachmentId))
.findFirst()
.ifPresent(a -> {
headers.add("Content-Disposition",
"attachment; filename=" + a.getName());
headers.add("Content-Type", forcedDownload ?
MediaType.APPLICATION_OCTET_STREAM_VALUE :
URLConnection.guessContentTypeFromName(a.getName()));
});
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@ControllerAdvice
public class GlobalDefaultExceptionHandler {
@ExceptionHandler(Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("exception", e);
modelAndView.addObject("url", request.getRequestURL());
modelAndView.setViewName("error");
return modelAndView;
}
}

View File

@ -1,13 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/")
public interface HomeController {
@GetMapping("/*")
String home(
Model model
);
}

View File

@ -1,25 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import com.baeldung.spring.dispatcher.servlet.models.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
public class HomeControllerImpl implements HomeController {
@Autowired
private Map<String, List<Task>> taskMap;
@Override
public String home(Model model) {
List<String> users = taskMap.keySet().stream()
.sorted()
.collect(Collectors.toList());
model.addAttribute("users", users);
return "home";
}
}

View File

@ -1,49 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import com.baeldung.spring.dispatcher.servlet.models.Task;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RequestMapping("/tasks")
public interface TaskController {
@GetMapping("/{username}/list")
String listTasks(
@PathVariable("username") String username,
Model model
);
@GetMapping("/{username}/add")
String addTask(
@PathVariable("username") String username,
Model model
);
@PostMapping("/{username}/add")
String addTask(
@PathVariable("username") String username,
@ModelAttribute Task task
);
@GetMapping("/{username}/get/{id}")
String getTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
Model model
);
@GetMapping("/{username}/get/{id}/attach")
String attachToTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
Model model
);
@PostMapping("/{username}/get/{id}/attach")
String attachToTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
@RequestParam("attachment") MultipartFile attachment,
@RequestParam("description") String description
);
}

View File

@ -1,111 +0,0 @@
package com.baeldung.spring.dispatcher.servlet.web;
import com.baeldung.spring.dispatcher.servlet.models.Attachment;
import com.baeldung.spring.dispatcher.servlet.models.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
@Controller
public class TaskControllerImpl implements TaskController {
@Autowired
private Map<String, List<Task>> taskMap;
@Override
public String listTasks(
@PathVariable("username") String username,
Model model
) {
List<Task> tasks = taskMap.get(username).stream()
.sorted(Comparator.comparing(Task::getDue))
.collect(Collectors.toList());
model.addAttribute("username", username);
model.addAttribute("tasks", tasks);
return "task-list";
}
@Override
public String addTask(
@PathVariable("username") String username,
Model model
) {
model.addAttribute("username", username);
model.addAttribute("task", new Task(new Date()));
return "task-add";
}
@Override
public String addTask(
@PathVariable("username") String username,
@ModelAttribute Task task
) {
List<Task> taskList = taskMap.get(username);
if (taskList == null) {
taskList = new ArrayList<>();
}
taskList.add(task);
taskMap.put(username, taskList);
return "redirect:list";
}
@Override
public String getTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
Model model
) {
Task task = taskMap.get(username).get(id);
model.addAttribute("username", username);
model.addAttribute("id", id);
model.addAttribute("task", task);
return "task-get";
}
@Override
public String attachToTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
Model model
) {
model.addAttribute("username", username);
model.addAttribute("id", id);
return "task-attach";
}
@Override
public String attachToTask(
@PathVariable("username") String username,
@PathVariable("id") int id,
@RequestParam("attachment") MultipartFile multipartFile,
@RequestParam("description") String description
) {
Task task = taskMap.get(username).get(id);
Attachment attachment = new Attachment(multipartFile.getOriginalFilename(),
description);
task.getAttachments().add(attachment);
try (InputStream inputStream =
new BufferedInputStream(multipartFile.getInputStream());
OutputStream outputStream =
new BufferedOutputStream(Files.newOutputStream(
Paths.get("/tmp", attachment.getId())))) {
byte[] buf = new byte[1024 * 16];
int len;
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len);
}
} catch (IOException e) {
throw new RuntimeException("Failed to upload file!", e);
}
return "redirect:./";
}
}

View File

@ -0,0 +1,83 @@
package com.baeldung.springdispatcherservlet.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.ui.context.support.ResourceBundleThemeSource;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.theme.CookieThemeResolver;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import java.io.IOException;
@Configuration
@EnableWebMvc
@ComponentScan("com.baeldung.springdispatcherservlet")
public class AppConfig extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
}
/** Multipart file uploading configuratioin */
@Bean
public CommonsMultipartResolver multipartResolver() throws IOException {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSize(10000000);
return resolver;
}
/** View resolver for JSP */
@Bean
public UrlBasedViewResolver viewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
/** Static resource locations including themes*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**/*")
.addResourceLocations("/", "/resources/")
.setCachePeriod(3600)
.resourceChain(true)
.addResolver(new PathResourceResolver());
}
/** BEGIN theme configuration */
@Bean
public ResourceBundleThemeSource themeSource(){
ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource();
themeSource.setDefaultEncoding("UTF-8");
themeSource.setBasenamePrefix("themes.");
return themeSource;
}
@Bean
public CookieThemeResolver themeResolver(){
CookieThemeResolver resolver = new CookieThemeResolver();
resolver.setDefaultThemeName("default");
resolver.setCookieName("example-theme-cookie");
return resolver;
}
@Bean
public ThemeChangeInterceptor themeChangeInterceptor(){
ThemeChangeInterceptor interceptor = new ThemeChangeInterceptor();
interceptor.setParamName("theme");
return interceptor;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(themeChangeInterceptor());
}
/** END theme configuration */
}

View File

@ -0,0 +1,23 @@
package com.baeldung.springdispatcherservlet.configuration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
context.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(context));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}

View File

@ -0,0 +1,41 @@
package com.baeldung.springdispatcherservlet.controller;
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.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletContext;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
@Controller
public class MultipartController {
@Autowired
ServletContext context;
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ModelAndView FileuploadController(@RequestParam("file") MultipartFile file) {
ModelAndView modelAndView = new ModelAndView("index");
try {
InputStream in = file.getInputStream();
String path = new File(".").getAbsolutePath();
FileOutputStream f = new FileOutputStream(path.substring(0, path.length()-1)+ "/uploads/" + file.getOriginalFilename());
int ch;
while ((ch = in.read()) != -1) {
f.write(ch);
}
f.flush();
f.close();
modelAndView.getModel().put("message", "File uploaded successfully!");
} catch (Exception e) {
System.out.println("Exception uploading multipart: " + e);
}
return modelAndView;
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.springdispatcherservlet.controller;
import com.baeldung.springdispatcherservlet.domain.User;
import com.baeldung.springdispatcherservlet.services.UserService;
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.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/example", method = RequestMethod.GET)
@ResponseBody
public User fetchUserExample() {
return userService.exampleUser();
}
@RequestMapping(value = "/name", method = RequestMethod.GET)
@ResponseBody
public User fetchUserByFirstName(@RequestParam(value = "firstName") String firstName) {
return userService.fetchUserByFirstName(firstName);
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.springdispatcherservlet.controller;
import com.baeldung.springdispatcherservlet.domain.User;
import com.baeldung.springdispatcherservlet.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/rest/user")
public class UserRestController {
@Autowired
private UserService userService;
@RequestMapping(value = "/example", method = RequestMethod.GET)
public User fetchUserExample() {
return userService.exampleUser();
}
@RequestMapping(value = "/name", method = RequestMethod.GET)
public User fetchUserByFirstName(@RequestParam(value = "firstName") String firstName) {
return userService.fetchUserByFirstName(firstName);
}
}

View File

@ -0,0 +1,41 @@
package com.baeldung.springdispatcherservlet.domain;
public class User {
private long id;
private String firstName;
private String lastName;
public User(long id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public User() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.springdispatcherservlet.services;
import org.springframework.stereotype.Service;
import com.baeldung.springdispatcherservlet.domain.User;
@Service
public class UserService {
public User fetchUserByFirstName(String firstName) {
return new User(1, firstName, "Everyperson");
}
public User exampleUser() {
return new User(1, "Example", "Everyperson");
}
}

View File

@ -1,3 +0,0 @@
## Info ##
- The diagram is created with [yed](http://www.yworks.com/products/yed)

View File

@ -1,372 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java" xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
<!--Created by yEd 3.16.2.1-->
<key attr.name="Beschreibung" attr.type="string" for="graph" id="d0"/>
<key for="port" id="d1" yfiles.type="portgraphics"/>
<key for="port" id="d2" yfiles.type="portgeometry"/>
<key for="port" id="d3" yfiles.type="portuserdata"/>
<key attr.name="url" attr.type="string" for="node" id="d4"/>
<key attr.name="description" attr.type="string" for="node" id="d5"/>
<key for="node" id="d6" yfiles.type="nodegraphics"/>
<key for="graphml" id="d7" yfiles.type="resources"/>
<key attr.name="url" attr.type="string" for="edge" id="d8"/>
<key attr.name="description" attr.type="string" for="edge" id="d9"/>
<key for="edge" id="d10" yfiles.type="edgegraphics"/>
<graph edgedefault="directed" id="G">
<data key="d0"/>
<node id="n0" yfiles.foldertype="group">
<data key="d4"/>
<data key="d6">
<y:ProxyAutoBoundsNode>
<y:Realizers active="0">
<y:GroupNode>
<y:Geometry height="600.0" width="1200.0" x="-187.59999999999997" y="60.18125000000006"/>
<y:Fill color="#FAFAFA" color2="#FAFAFA" transparent="false"/>
<y:BorderStyle color="#795548" type="dashed" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" backgroundColor="#FAFAFA" borderDistance="0.0" fontFamily="Roboto Mono" fontSize="20" fontStyle="plain" height="27.4375" horizontalTextPosition="center" iconTextGap="4" lineColor="#00695C" modelName="internal" modelPosition="t" textColor="#212121" verticalTextPosition="bottom" visible="true" width="340.0546875" x="429.97265625" y="0.0">Servlet Engine (e.g. Tomcat)</y:NodeLabel>
<y:Shape type="roundrectangle"/>
<y:State closed="false" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>
<y:Insets bottom="15" bottomF="15.0" left="15" leftF="15.0" right="15" rightF="15.0" top="15" topF="15.0"/>
<y:BorderInsets bottom="46" bottomF="45.78125" left="23" leftF="23.30000000000001" right="44" rightF="43.80000000000018" top="90" topF="89.98124999999999"/>
</y:GroupNode>
<y:GroupNode>
<y:Geometry height="50.0" width="50.0" x="473.0" y="280.0"/>
<y:Fill color="#F5F5F5" transparent="false"/>
<y:BorderStyle color="#000000" type="dashed" width="1.0"/>
<y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#EBEBEB" borderDistance="0.0" fontFamily="Dialog" fontSize="15" fontStyle="plain" hasLineColor="false" height="21.4609375" horizontalTextPosition="center" iconTextGap="4" modelName="internal" modelPosition="t" textColor="#000000" verticalTextPosition="bottom" visible="true" width="65.201171875" x="-7.6005859375" y="0.0">Folder 1</y:NodeLabel>
<y:Shape type="roundrectangle"/>
<y:State closed="true" closedHeight="50.0" closedWidth="50.0" innerGraphDisplayEnabled="false"/>
<y:Insets bottom="5" bottomF="5.0" left="5" leftF="5.0" right="5" rightF="5.0" top="5" topF="5.0"/>
<y:BorderInsets bottom="0" bottomF="0.0" left="0" leftF="0.0" right="0" rightF="0.0" top="0" topF="0.0"/>
</y:GroupNode>
</y:Realizers>
</y:ProxyAutoBoundsNode>
</data>
<graph edgedefault="directed" id="n0:">
<node id="n0::n0">
<data key="d6">
<y:GenericNode configuration="com.yworks.flowchart.onPageReference">
<y:Geometry height="180.0" width="270.0" x="683.5999999999999" y="192.60000000000005"/>
<y:Fill color="#212121" color2="#616161" transparent="false"/>
<y:BorderStyle color="#FAFAFA" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Roboto Mono" fontSize="21" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="28.609375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#FAFAFA" verticalTextPosition="bottom" visible="true" width="130.0205078125" x="69.98974609375" y="75.69531249999997">Controller<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:StyleProperties>
<y:Property class="java.lang.Boolean" name="y.view.ShadowNodePainter.SHADOW_PAINTING" value="true"/>
</y:StyleProperties>
</y:GenericNode>
</data>
</node>
<node id="n0::n1">
<data key="d6">
<y:GenericNode configuration="BevelNode2">
<y:Geometry height="34.0" width="69.0" x="464.29999999999995" y="274.6000000000002"/>
<y:Fill color="#FFC107" transparent="false"/>
<y:BorderStyle hasColor="false" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" borderDistance="8.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#212121" verticalTextPosition="bottom" visible="true" width="58.0087890625" x="5.49560546875" y="4.453125">Model<y:LabelModel>
<y:SmartNodeLabelModel distance="8.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:StyleProperties>
<y:Property class="java.lang.Boolean" name="ModernNodeShadow" value="true"/>
</y:StyleProperties>
</y:GenericNode>
</data>
</node>
<node id="n0::n2">
<data key="d6">
<y:SVGNode>
<y:Geometry height="66.76200103759766" width="56.554100036621094" x="-149.29999999999995" y="249.21899948120125"/>
<y:Fill color="#CCCCFF" transparent="false"/>
<y:BorderStyle color="#000000" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" hasText="false" height="4.0" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#000000" verticalTextPosition="bottom" visible="true" width="4.0" x="26.277050018310547" y="70.76200103759766">
<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="-0.5" nodeRatioX="0.0" nodeRatioY="0.5" offsetX="0.0" offsetY="4.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:SVGNodeProperties usingVisualBounds="true"/>
<y:SVGModel svgBoundsPolicy="0">
<y:SVGContent refid="1"/>
</y:SVGModel>
</y:SVGNode>
</data>
</node>
<node id="n0::n3">
<data key="d6">
<y:GenericNode configuration="BevelNode2">
<y:Geometry height="34.0" width="69.0" x="226.89999999999975" y="389.60000000000014"/>
<y:Fill color="#FFC107" transparent="false"/>
<y:BorderStyle hasColor="false" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" borderDistance="8.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#212121" verticalTextPosition="bottom" visible="true" width="58.0087890625" x="5.49560546875" y="4.453125">Model<y:LabelModel>
<y:SmartNodeLabelModel distance="8.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:StyleProperties>
<y:Property class="java.lang.Boolean" name="ModernNodeShadow" value="true"/>
</y:StyleProperties>
</y:GenericNode>
</data>
</node>
<node id="n0::n4">
<data key="d4"/>
<data key="d6">
<y:GenericNode configuration="com.yworks.flowchart.terminator">
<y:Geometry height="130.0" width="230.0" x="60.0" y="217.60000000000005"/>
<y:Fill color="#212121" color2="#616161" transparent="false"/>
<y:BorderStyle color="#FAFAFA" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Roboto Mono" fontSize="21" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="28.609375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#FAFAFA" verticalTextPosition="bottom" visible="true" width="218.23486328125" x="5.882568359375" y="50.69531249999997">DispatcherServlet<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:StyleProperties>
<y:Property class="java.lang.Boolean" name="y.view.ShadowNodePainter.SHADOW_PAINTING" value="false"/>
</y:StyleProperties>
</y:GenericNode>
</data>
</node>
<node id="n0::n5">
<data key="d6">
<y:GenericNode configuration="com.yworks.flowchart.document">
<y:Geometry height="120.0" width="230.0" x="60.0" y="479.4000000000001"/>
<y:Fill color="#212121" color2="#616161" transparent="false"/>
<y:BorderStyle color="#FAFAFA" type="line" width="1.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Roboto Mono" fontSize="21" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="28.609375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#FAFAFA" verticalTextPosition="bottom" visible="true" width="167.82666015625" x="31.086669921875" y="45.6953125">View Template<y:LabelModel>
<y:SmartNodeLabelModel distance="4.0"/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/>
</y:ModelParameter>
</y:NodeLabel>
<y:StyleProperties>
<y:Property class="java.lang.Boolean" name="y.view.ShadowNodePainter.SHADOW_PAINTING" value="true"/>
</y:StyleProperties>
</y:GenericNode>
</data>
</node>
</graph>
</node>
<edge id="e0" source="n0::n4" target="n0">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
<y:LineStyle color="#000000" type="line" width="1.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e0" source="n0::n5" target="n0::n4">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-38.30000000000018" sy="-18.399999999999864" tx="-37.30000000000018" ty="3.6000000000001364"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.0" textColor="#212121" verticalTextPosition="bottom" visible="true" width="155.224609375" x="-179.1814364795589" y="-35.230035400390534">Return Control<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e1" source="n0::n4" target="n0::n5">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="48.69999999999982" sy="-5.399999999999864" tx="48.69999999999982" ty="-12.399999999999864"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="1.0" textColor="#212121" verticalTextPosition="bottom" visible="true" width="166.0263671875" x="24.00000305175763" y="96.57254638671884">Render Response<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e2" source="n0::n4" target="n0::n0">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="7.699999999999818" sy="-36.399999999999864" tx="3.699999999999818" ty="-36.399999999999864"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.5" textColor="#212121" verticalTextPosition="bottom" visible="true" width="176.828125" x="119.53513793945308" y="-49.093746948242">Delegate Request<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e3" source="n0::n0" target="n0::n4">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="4.699999999999818" sy="29.600000000000136" tx="55.69999999999982" ty="29.600000000000136"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.0" textColor="#212121" verticalTextPosition="bottom" visible="true" width="328.0615234375" x="-388.2225097656251" y="23.99998779296891">Delegate Rendering of Response<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="e1" source="n0" target="n0::n4">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-409.1" sy="-128.18124999999975" tx="-6.5" ty="-35.39999999999975"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="20.0" fontFamily="Roboto Mono" fontSize="14" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" hasText="false" height="4.0" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.0" textColor="#FAFAFA" verticalTextPosition="bottom" visible="true" width="4.0" x="-190.89999995231625" y="-171.81874999999994">
<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e4" source="n0::n2" target="n0::n4">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="7.622949981689459" sy="-29.69998781681062" tx="-4.399999999999977" ty="-29.69998781681062"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.0" textColor="#212121" verticalTextPosition="bottom" visible="true" width="176.828125" x="4.834180450439476" y="-49.093746972084006">Incoming Request<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e5" source="n0::n4" target="n0::n2">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-16.399999999999977" sy="27.16233534321384" tx="28.290377113176618" ty="27.16233534321384"/>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.0" textColor="#212121" verticalTextPosition="bottom" visible="true" width="166.0263671875" x="-165.36247482299802" y="24.00000624165142">Return Response<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e6" source="n0::n0" target="n0::n0">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
<y:Point x="912.5999999999999" y="125.60000000000002"/>
</y:Path>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="standard" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.25" textColor="#212121" verticalTextPosition="bottom" visible="true" width="155.224609375" x="-200.05571079132665" y="-142.76877441406248">Handle Request<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
<edge id="n0::e7" source="n0::n0" target="n0::n0">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="0.0" sy="0.0" tx="0.0" ty="0.0">
<y:Point x="862.5999999999999" y="459.2000000000001"/>
</y:Path>
<y:LineStyle color="#212121" type="line" width="4.0"/>
<y:Arrows source="standard" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="24.0" fontFamily="Roboto Mono" fontSize="18" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="25.09375" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="anywhere" ratio="0.25" textColor="#212121" verticalTextPosition="bottom" visible="true" width="133.62109375" x="-61.31919657274125" y="63.13254394531259">Create Model<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
</data>
</edge>
</graph>
<data key="d7">
<y:Resources>
<y:Resource id="1">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="57px" height="67px" viewBox="0 0 57 67" enable-background="new 0 0 57 67" xml:space="preserve"&gt;
&lt;g&gt;
&lt;radialGradient id="neck_x5F_white_1_" cx="28.0298" cy="-751.9429" r="11.4464" fx="25.7969" fy="-753.1596" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#B38E5D"/&gt;
&lt;stop offset="1" style="stop-color:#805126"/&gt;
&lt;/radialGradient&gt;
&lt;path id="neck_x5F_white_2_" fill="url(#neck_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M19.278,37.799h18.188
v13.23c-1.313,0.371-17.173,0.436-18.188,0.172V37.799z"/&gt;
&lt;radialGradient id="SVGID_1_" cx="27.481" cy="-760.3003" r="31.0533" fx="21.4231" fy="-763.6011" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#B38E5D"/&gt;
&lt;stop offset="1" style="stop-color:#805126"/&gt;
&lt;/radialGradient&gt;
&lt;path fill="url(#SVGID_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M49.529,51.225c-4.396-4.396-10.951-5.884-12.063-6.109
V37.8H19.278c0,0,0.038,6.903,0,6.868c0,0-6.874,0.997-12.308,6.432C1.378,56.691,0.5,62.77,0.5,62.77
c0,1.938,1.575,3.492,3.523,3.492h48.51c1.947,0,3.521-1.558,3.521-3.492C56.055,62.768,54.211,55.906,49.529,51.225z"/&gt;
&lt;radialGradient id="face_x5F_white_1_" cx="27.7827" cy="-732.2632" r="23.424" fx="23.2131" fy="-734.753" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#B38E5D"/&gt;
&lt;stop offset="1" style="stop-color:#805126"/&gt;
&lt;/radialGradient&gt;
&lt;path id="face_x5F_white_2_" fill="url(#face_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M43.676,23.357
c0.086,10.199-6.738,18.52-15.246,18.586c-8.503,0.068-15.467-8.146-15.553-18.344C12.794,13.4,19.618,5.079,28.123,5.012
C36.627,4.945,43.59,13.158,43.676,23.357z"/&gt;
&lt;linearGradient id="face_highlight_1_" gradientUnits="userSpaceOnUse" x1="2941.4297" y1="5674.7988" x2="2965.0596" y2="5768.2505" gradientTransform="matrix(0.275 0 0 0.2733 -783.3976 -1542.678)"&gt;
&lt;stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.42"/&gt;
&lt;stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.12"/&gt;
&lt;/linearGradient&gt;
&lt;path id="face_highlight_2_" fill="url(#face_highlight_1_)" d="M27.958,6.333c-6.035,0.047-10.747,4.493-12.787,10.386
c-0.664,1.919-0.294,4.043,0.98,5.629c2.73,3.398,5.729,6.283,9.461,8.088c3.137,1.518,7.535,2.385,11.893,1.247
c2.274-0.592,3.988-2.459,4.375-4.766c0.183-1.094,0.293-2.289,0.283-3.553C42.083,13.952,36.271,6.268,27.958,6.333z"/&gt;
&lt;path id="path9833_2_" fill="#4B4B4B" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" d="M28.372,0.5
C17.537,0.5,8.269,7.748,9.153,26.125c0.563,6.563,5.862,12.042,9.366,13.531c-2.929-10.968-0.304-25.021-0.585-25.526
c-0.281-0.505,3.536,6.728,3.536,6.728l3.183-8.312c5.541,4.28,0.393,11.309,1.049,11.058c4.26-1.631,5.34-9.228,5.34-9.228
s2.729,3.657,2.701,5.504c-0.054,3.562,2.194-6.067,2.194-6.067l1.027,2.031c6.727,9.822,3.684,16.208,1.654,22.781
c15.665-0.703,12.289-10.48,9.658-18.407C43.59,6.092,39.206,0.5,28.372,0.5z"/&gt;
&lt;radialGradient id="collar_x5F_body_2_" cx="15.1587" cy="-763.7056" r="32.4004" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#B0E8FF"/&gt;
&lt;stop offset="1" style="stop-color:#74AEEE"/&gt;
&lt;/radialGradient&gt;
&lt;path id="collar_x5F_body_1_" fill="url(#collar_x5F_body_2_)" stroke="#5491CF" d="M0.5,62.768c0,1.938,1.575,3.494,3.523,3.494
h48.51c1.947,0,3.521-1.559,3.521-3.494c0,0-1.844-6.861-6.525-11.543c-4.815-4.813-11.244-6.146-11.244-6.146
c-1.771,1.655-5.61,2.802-10.063,2.802c-4.453,0-8.292-1.146-10.063-2.802c0,0-5.755,0.586-11.189,6.021
C1.378,56.689,0.5,62.768,0.5,62.768z"/&gt;
&lt;radialGradient id="collar_x5F_r_2_" cx="31.5" cy="-753.832" r="9.2834" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#80CCFF"/&gt;
&lt;stop offset="1" style="stop-color:#74AEEE"/&gt;
&lt;/radialGradient&gt;
&lt;path id="collar_x5F_r_1_" fill="url(#collar_x5F_r_2_)" stroke="#5491CF" d="M38.159,41.381c0,0-0.574,2.369-3.013,4.441
c-2.108,1.795-5.783,2.072-5.783,2.072l3.974,6.217c0,0,2.957-1.637,5.009-3.848c1.922-2.072,1.37-5.479,1.37-5.479L38.159,41.381z
"/&gt;
&lt;radialGradient id="collar_x5F_l_2_" cx="19.1377" cy="-753.873" r="9.2837" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#80CCFF"/&gt;
&lt;stop offset="1" style="stop-color:#74AEEE"/&gt;
&lt;/radialGradient&gt;
&lt;path id="collar_x5F_l_1_" fill="url(#collar_x5F_l_2_)" stroke="#5491CF" d="M18.63,41.422c0,0,0.576,2.369,3.012,4.441
c2.109,1.793,5.785,2.072,5.785,2.072l-3.974,6.217c0,0-2.957-1.637-5.007-3.85c-1.922-2.072-1.37-5.48-1.37-5.48L18.63,41.422z"/&gt;
&lt;radialGradient id="Knob2_2_" cx="27.8872" cy="9.9414" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#80CCFF"/&gt;
&lt;stop offset="1" style="stop-color:#74AEEE"/&gt;
&lt;/radialGradient&gt;
&lt;circle id="Knob2_1_" fill="url(#Knob2_2_)" stroke="#5491CF" cx="28.258" cy="56.254" r="0.584"/&gt;
&lt;radialGradient id="Knob1_2_" cx="27.9253" cy="3.6973" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"&gt;
&lt;stop offset="0" style="stop-color:#80CCFF"/&gt;
&lt;stop offset="1" style="stop-color:#74AEEE"/&gt;
&lt;/radialGradient&gt;
&lt;circle id="Knob1_1_" fill="url(#Knob1_2_)" stroke="#5491CF" cx="28.296" cy="62.499" r="0.584"/&gt;
&lt;/g&gt;
&lt;/svg&gt;
</y:Resource>
</y:Resources>
</data>
</graphml>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

View File

@ -1,22 +0,0 @@
home.title=Welcome to TaskTools!
task.add.description=description
task.add.due=due
task.add.header=Adding a task to {0}''s list:
task.add.submit=Submit
task.add.title={0}: task add
task.attach.attachment=attached file
task.attach.description=description
task.attach.header=task #{0}: attach file
task.attach.submit=Submit
task.attach.title=#{0}: Attach file
task.get.attach=Attach file
task.get.attachments=attachments:
task.get.download=Download
task.get.header=task #{0}:
task.get.list=Back
task.get.title={0}: task details
task.list.add-new=Add new
task.list.details=Details
task.list.header={0}''s tasks:
task.list.home=Home
task.list.title={0}: task list

View File

@ -1,22 +0,0 @@
home.title=Willkommen bei TaskTools!
task.add.description=Beschreibung
task.add.due=f\u00e4llig
task.add.header=F\u00fcge eine Aufgabe zu {0}''s Liste hinzu:
task.add.submit=Senden
task.add.title={0}: Task hinzuf\u00fcgen
task.attach.attachment=Angeh\u00e4ngte Datei
task.attach.description=Beschreibung
task.attach.header=Task #{0}: Datei anh\u00e4ngen
task.attach.submit=Senden
task.attach.title=#{0}: Datei anh\u00e4ngen
task.get.attach=Datei anh\u00e4ngen
task.get.attachments=Anh\u00e4nge:
task.get.download=Download
task.get.header=Task #{0}:
task.get.list=Zur\u00fcck
task.get.title={0}: Task Details
task.list.add-new=Neuer Task
task.list.details=Details
task.list.header={0}''s Tasks:
task.list.home=Startseite
task.list.title={0}: Task Liste

View File

@ -1 +0,0 @@
stylesheet=/public/css/themes/post_it.css

View File

@ -1 +0,0 @@
stylesheet=/public/css/themes/robotask.css

View File

@ -0,0 +1 @@
styleSheet=/resources/css/default.css

View File

@ -0,0 +1 @@
styleSheet=/resources/css/example.css

View File

@ -0,0 +1,30 @@
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<title>Spring Dispatcher</title>
<link rel="stylesheet" href="${ctx}/<spring:theme code='styleSheet'/>" type="text/css"/>
</head>
<body>
<h2>Hello World!</h2>
<br/>
<a href="${ctx}/?theme=example">Switch Theme!</a>
<a href="${ctx}/?theme=default">Switch Theme!</a>
<br/>
<br/>
<br/>
<form action="${ctx}/upload" method="post" enctype="multipart/form-data">
<label>Upload a file! </label><input type="file" name="file"/>
<input type="submit" value="Upload File"/>
</form>
<br/>
<br/>
${message}
</body>
</html>

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Error</title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2>Error:</h2>
<p th:text="|URL: ${url}|"></p>
<p th:text="${exception}"></p>
</body>
</html>

View File

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{home.title}"></title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2>TaskTools</h2>
<ul>
<li th:each="username : ${users}">
<a th:href="@{/tasks/{username}/list(username=${username})}" th:text="${username}"></a>
</li>
</ul>
</body>
</html>

View File

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{task.add.title(${username})}"></title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2 th:text="#{task.add.header(${username})}"></h2>
<form method="post" action="#" th:action="@{/tasks/{username}/add(username=${username})}" th:object="${task}">
<input type="text" th:field="*{description}" th:placeholder="#{task.add.description}"/>
<input type="datetime-local" th:field="*{due}" th:placeholder="#{task.add.due}"/>
<input type="submit" th:value="#{task.add.submit}"/>
</form>
</body>
</html>

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{task.attach.title(${id})}"></title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2 th:text="#{task.attach.header(${id})}"></h2>
<form method="post" action="#" enctype="multipart/form-data"
th:action="@{/tasks/{username}/get/{id}/attach(username=${username},id=${id})}">
<input type="file" name="attachment" th:placeholder="#{task.attach.attachment}"/>
<input type="text" name="description" th:placeholder="#{task.attach.description}"/>
<input type="submit" th:value="#{task.attach.submit}"/>
</form>
</body>
</html>

View File

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{task.get.title(${task.description})}"></title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2 th:text="#{task.get.header(${id})}"></h2>
<p th:text="${task.due}"></p>
<p th:text="${task.description}"></p>
<hr/>
<p th:text="#{task.get.attachments}"></p>
<dl th:each="attachment : ${task.attachments}">
<dt><img src="#" th:src="@{/attachments/{id}(id=${attachment.id})}"></dt>
<dt>
<span th:text="${attachment.name}"></span>
<a class="button" th:href="@{/attachments/{id}(id=${attachment.id},download=true)}"
th:text="#{task.get.download}"></a>
</dt>
<dd th:text="${attachment.description}"></dd>
</dl>
<p>
<a th:href="@{/tasks/{username}/list(username=${username})}" th:text="#{task.get.list}"></a>
<a th:href="@{/tasks/{username}/get/{id}/attach(username=${username},id=${id})}" th:text="#{task.get.attach}"></a>
</p>
</body>
</html>

View File

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{task.list.title(${username})}"></title>
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
<link rel="stylesheet" type="text/css" th:href="${#themes.code('stylesheet')}">
</head>
<body>
<h2 th:text="#{task.list.header(${username})}"></h2>
<ul>
<li th:each="task : ${tasks}">
<p th:text="*{task.due}"></p>
<p th:text="*{task.description}"></p>
<a th:href="@{/tasks/{username}/get/{id}(username=${username},id=${taskStat.index})}" th:text="#{task.list.details}"></a>
</li>
</ul>
<p>
<a th:href="@{/}" th:text="#{task.list.home}"></a>
<a th:href="@{/tasks/{username}/add(username=${username})}" th:text="#{task.list.add-new}"></a>
</p>
</body>
</html>

View File

@ -1,8 +0,0 @@
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: #2196f3;
background-color: #e0e0e0;
}

View File

@ -1,8 +0,0 @@
@import url('https://fonts.googleapis.com/css?family=Indie+Flower');
* {
font-family: 'Indie Flower', sans-serif;
font-size: 18px;
color: #ffeb3b;
background-color: #212121;
}

View File

@ -1,8 +0,0 @@
@import url('https://fonts.googleapis.com/css?family=Roboto');
* {
font-family: Roboto, sans-serif;
font-size: 1em;
color: #212121;
background-color: #fafafa;
}

View File

@ -0,0 +1,4 @@
h2 {
color: green;
font-weight: 400;
}

View File

@ -0,0 +1,4 @@
h2 {
color: red;
font-weight: 700;
}