From bb321982a1dedbd7d2d5410ad066b652677364c1 Mon Sep 17 00:00:00 2001 From: David Morley Date: Tue, 5 Jan 2016 21:37:48 -0600 Subject: [PATCH] Rename package to conform with site name --- spring-thymeleaf/pom.xml | 2 +- .../baeldung/thymeleaf/config/WebApp.java | 72 ++++----- .../thymeleaf/config/WebMVCConfig.java | 146 +++++++++--------- .../thymeleaf/controller/HomeController.java | 2 +- .../controller/StudentController.java | 139 +++++++++-------- .../thymeleaf/formatter/NameFormatter.java | 60 +++---- .../baeldung/thymeleaf/model/Student.java | 120 +++++++------- 7 files changed, 270 insertions(+), 271 deletions(-) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/config/WebApp.java (91%) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/config/WebMVCConfig.java (92%) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/controller/HomeController.java (94%) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/controller/StudentController.java (92%) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/formatter/NameFormatter.java (91%) rename spring-thymeleaf/src/main/java/{org => com}/baeldung/thymeleaf/model/Student.java (91%) diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index ae7451a74e..16e6849f93 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.baeldung + com.baeldung spring-thymeleaf 0.1-SNAPSHOT war diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebApp.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java similarity index 91% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebApp.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java index 45752a6269..89ad7e601e 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebApp.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebApp.java @@ -1,36 +1,36 @@ -package org.baeldung.thymeleaf.config; - -import javax.servlet.ServletRegistration.Dynamic; - -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -/** - * Java configuration file that is used for web application initialization - */ -public class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer { - - public WebApp() { - super(); - } - - @Override - protected Class[] getRootConfigClasses() { - return null; - } - - @Override - protected Class[] getServletConfigClasses() { - return new Class[] { WebMVCConfig.class }; - } - - @Override - protected String[] getServletMappings() { - return new String[] { "/" }; - } - - @Override - protected void customizeRegistration(final Dynamic registration) { - super.customizeRegistration(registration); - } - -} +package com.baeldung.thymeleaf.config; + +import javax.servlet.ServletRegistration.Dynamic; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +/** + * Java configuration file that is used for web application initialization + */ +public class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer { + + public WebApp() { + super(); + } + + @Override + protected Class[] getRootConfigClasses() { + return null; + } + + @Override + protected Class[] getServletConfigClasses() { + return new Class[] { WebMVCConfig.class }; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } + + @Override + protected void customizeRegistration(final Dynamic registration) { + super.customizeRegistration(registration); + } + +} diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebMVCConfig.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java similarity index 92% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebMVCConfig.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java index c5bd460eee..51c60247a1 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/config/WebMVCConfig.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java @@ -1,73 +1,73 @@ -package org.baeldung.thymeleaf.config; - -import org.baeldung.thymeleaf.formatter.NameFormatter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Description; -import org.springframework.context.support.ResourceBundleMessageSource; -import org.springframework.format.FormatterRegistry; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.thymeleaf.spring4.SpringTemplateEngine; -import org.thymeleaf.spring4.view.ThymeleafViewResolver; -import org.thymeleaf.templateresolver.ServletContextTemplateResolver; - -@Configuration -@EnableWebMvc -@ComponentScan({ "org.baeldung.thymeleaf" }) -/** - * Java configuration file that is used for Spring MVC and Thymeleaf - * configurations - */ -public class WebMVCConfig extends WebMvcConfigurerAdapter { - - @Bean - @Description("Thymeleaf Template Resolver") - public ServletContextTemplateResolver templateResolver() { - ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); - templateResolver.setPrefix("/WEB-INF/views/"); - templateResolver.setSuffix(".html"); - templateResolver.setTemplateMode("HTML5"); - - return templateResolver; - } - - @Bean - @Description("Thymeleaf Template Engine") - public SpringTemplateEngine templateEngine() { - SpringTemplateEngine templateEngine = new SpringTemplateEngine(); - templateEngine.setTemplateResolver(templateResolver()); - - return templateEngine; - } - - @Bean - @Description("Thymeleaf View Resolver") - public ThymeleafViewResolver viewResolver() { - ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); - viewResolver.setTemplateEngine(templateEngine()); - viewResolver.setOrder(1); - return viewResolver; - } - - @Bean - @Description("Spring Message Resolver") - public ResourceBundleMessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - messageSource.setBasename("messages"); - return messageSource; - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/"); - } - - @Override - @Description("Custom Conversion Service") - public void addFormatters(FormatterRegistry registry) { - registry.addFormatter(new NameFormatter()); - } -} +package com.baeldung.thymeleaf.config; + +import com.baeldung.thymeleaf.formatter.NameFormatter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Description; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.thymeleaf.spring4.SpringTemplateEngine; +import org.thymeleaf.spring4.view.ThymeleafViewResolver; +import org.thymeleaf.templateresolver.ServletContextTemplateResolver; + +@Configuration +@EnableWebMvc +@ComponentScan({ "com.baeldung.thymeleaf" }) +/** + * Java configuration file that is used for Spring MVC and Thymeleaf + * configurations + */ +public class WebMVCConfig extends WebMvcConfigurerAdapter { + + @Bean + @Description("Thymeleaf Template Resolver") + public ServletContextTemplateResolver templateResolver() { + ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); + templateResolver.setPrefix("/WEB-INF/views/"); + templateResolver.setSuffix(".html"); + templateResolver.setTemplateMode("HTML5"); + + return templateResolver; + } + + @Bean + @Description("Thymeleaf Template Engine") + public SpringTemplateEngine templateEngine() { + SpringTemplateEngine templateEngine = new SpringTemplateEngine(); + templateEngine.setTemplateResolver(templateResolver()); + + return templateEngine; + } + + @Bean + @Description("Thymeleaf View Resolver") + public ThymeleafViewResolver viewResolver() { + ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); + viewResolver.setTemplateEngine(templateEngine()); + viewResolver.setOrder(1); + return viewResolver; + } + + @Bean + @Description("Spring Message Resolver") + public ResourceBundleMessageSource messageSource() { + ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); + messageSource.setBasename("messages"); + return messageSource; + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/"); + } + + @Override + @Description("Custom Conversion Service") + public void addFormatters(FormatterRegistry registry) { + registry.addFormatter(new NameFormatter()); + } +} diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/HomeController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java similarity index 94% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/HomeController.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java index 505dc8303b..a28d059acc 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/HomeController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/HomeController.java @@ -1,4 +1,4 @@ -package org.baeldung.thymeleaf.controller; +package com.baeldung.thymeleaf.controller; import java.text.DateFormat; import java.util.Date; diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/StudentController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java similarity index 92% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/StudentController.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java index 3bef22cdae..912eb521f4 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/controller/StudentController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/StudentController.java @@ -1,70 +1,69 @@ -package org.baeldung.thymeleaf.controller; - -import java.util.ArrayList; -import java.util.List; - -import javax.validation.Valid; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import org.baeldung.thymeleaf.model.Student; - -/** - * Handles requests for the student model. - * - */ -@Controller -public class StudentController { - - @RequestMapping(value = "/saveStudent", method = RequestMethod.POST) - public String saveStudent(@Valid @ModelAttribute Student student, BindingResult errors, Model model) { - if (!errors.hasErrors()) { - // get mock objects - List students = buildStudents(); - // add current student - students.add(student); - model.addAttribute("students", students); - } - return ((errors.hasErrors()) ? "addStudent" : "listStudents"); - } - - @RequestMapping(value = "/addStudent", method = RequestMethod.GET) - public String addStudent(Model model) { - model.addAttribute("student", new Student()); - return "addStudent"; - } - - @RequestMapping(value = "/listStudents", method = RequestMethod.GET) - public String listStudent(Model model) { - - model.addAttribute("students", buildStudents()); - - return "listStudents"; - } - - private List buildStudents() { - List students = new ArrayList(); - - Student student1 = new Student(); - student1.setId(1001); - student1.setName("John Smith"); - student1.setGender('M'); - student1.setPercentage(Float.valueOf("80.45")); - - students.add(student1); - - Student student2 = new Student(); - student2.setId(1002); - student2.setName("Jane Williams"); - student2.setGender('F'); - student2.setPercentage(Float.valueOf("60.25")); - - students.add(student2); - return students; - } -} +package com.baeldung.thymeleaf.controller; + +import java.util.ArrayList; +import java.util.List; + +import javax.validation.Valid; + +import com.baeldung.thymeleaf.model.Student; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * Handles requests for the student model. + * + */ +@Controller +public class StudentController { + + @RequestMapping(value = "/saveStudent", method = RequestMethod.POST) + public String saveStudent(@Valid @ModelAttribute Student student, BindingResult errors, Model model) { + if (!errors.hasErrors()) { + // get mock objects + List students = buildStudents(); + // add current student + students.add(student); + model.addAttribute("students", students); + } + return ((errors.hasErrors()) ? "addStudent" : "listStudents"); + } + + @RequestMapping(value = "/addStudent", method = RequestMethod.GET) + public String addStudent(Model model) { + model.addAttribute("student", new Student()); + return "addStudent"; + } + + @RequestMapping(value = "/listStudents", method = RequestMethod.GET) + public String listStudent(Model model) { + + model.addAttribute("students", buildStudents()); + + return "listStudents"; + } + + private List buildStudents() { + List students = new ArrayList(); + + Student student1 = new Student(); + student1.setId(1001); + student1.setName("John Smith"); + student1.setGender('M'); + student1.setPercentage(Float.valueOf("80.45")); + + students.add(student1); + + Student student2 = new Student(); + student2.setId(1002); + student2.setName("Jane Williams"); + student2.setGender('F'); + student2.setPercentage(Float.valueOf("60.25")); + + students.add(student2); + return students; + } +} diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/formatter/NameFormatter.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java similarity index 91% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/formatter/NameFormatter.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java index 9c07ef8d14..a5d2366390 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/formatter/NameFormatter.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/formatter/NameFormatter.java @@ -1,30 +1,30 @@ -package org.baeldung.thymeleaf.formatter; - -import java.text.ParseException; -import java.util.Locale; - -import org.springframework.format.Formatter; -import org.thymeleaf.util.StringUtils; - -/** - * - * Name formatter class that implements the Spring Formatter interface. - * Formats a name(String) and return the value with spaces replaced by commas. - * - */ -public class NameFormatter implements Formatter { - - @Override - public String print(String input, Locale locale) { - return formatName(input, locale); - } - - @Override - public String parse(String input, Locale locale) throws ParseException { - return formatName(input, locale); - } - - private String formatName(String input, Locale locale) { - return StringUtils.replace(input, " ", ","); - } -} +package com.baeldung.thymeleaf.formatter; + +import java.text.ParseException; +import java.util.Locale; + +import org.springframework.format.Formatter; +import org.thymeleaf.util.StringUtils; + +/** + * + * Name formatter class that implements the Spring Formatter interface. + * Formats a name(String) and return the value with spaces replaced by commas. + * + */ +public class NameFormatter implements Formatter { + + @Override + public String print(String input, Locale locale) { + return formatName(input, locale); + } + + @Override + public String parse(String input, Locale locale) throws ParseException { + return formatName(input, locale); + } + + private String formatName(String input, Locale locale) { + return StringUtils.replace(input, " ", ","); + } +} diff --git a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/model/Student.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java similarity index 91% rename from spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/model/Student.java rename to spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java index f21169dbcf..bce99f286c 100644 --- a/spring-thymeleaf/src/main/java/org/baeldung/thymeleaf/model/Student.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/model/Student.java @@ -1,60 +1,60 @@ -package org.baeldung.thymeleaf.model; - -import java.io.Serializable; - -import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; - -/** - * - * Simple student POJO with few fields - * - */ -public class Student implements Serializable { - - private static final long serialVersionUID = -8582553475226281591L; - - @NotNull(message = "Student ID is required.") - @Min(value = 1000, message = "Student ID must be at least 4 digits.") - private Integer id; - - @NotNull(message = "Student name is required.") - private String name; - - @NotNull(message = "Student gender is required.") - private Character gender; - - private Float percentage; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Character getGender() { - return gender; - } - - public void setGender(Character gender) { - this.gender = gender; - } - - public Float getPercentage() { - return percentage; - } - - public void setPercentage(Float percentage) { - this.percentage = percentage; - } -} +package com.baeldung.thymeleaf.model; + +import java.io.Serializable; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +/** + * + * Simple student POJO with few fields + * + */ +public class Student implements Serializable { + + private static final long serialVersionUID = -8582553475226281591L; + + @NotNull(message = "Student ID is required.") + @Min(value = 1000, message = "Student ID must be at least 4 digits.") + private Integer id; + + @NotNull(message = "Student name is required.") + private String name; + + @NotNull(message = "Student gender is required.") + private Character gender; + + private Float percentage; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Character getGender() { + return gender; + } + + public void setGender(Character gender) { + this.gender = gender; + } + + public Float getPercentage() { + return percentage; + } + + public void setPercentage(Float percentage) { + this.percentage = percentage; + } +}