diff --git a/build.gradle b/build.gradle index cb55cf4..5bb687f 100644 --- a/build.gradle +++ b/build.gradle @@ -39,8 +39,6 @@ repositories { configurations { compile.exclude module: "spring-boot-starter-tomcat" - compile.exclude module: "jquery" - compile.exclude module: "popper.js" compile.exclude module: "follow-redirects" compile.exclude module: "is-buffer" } @@ -49,6 +47,7 @@ dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-web' compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' + compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect' compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' @@ -57,6 +56,12 @@ dependencies { compile group: 'com.ibm.icu', name: 'icu4j', version: '63.1' compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.9.0.202009080501-r' + compile group: 'org.webjars', name: 'jquery', version: '3.6.0' + compile group: 'org.webjars', name: 'bootstrap', version: '4.6.0' + compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' + compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' + + testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' } diff --git a/src/main/java/ru/ulstu/extractor/mvc/GlobalDefaultExceptionHandler.java b/src/main/java/ru/ulstu/extractor/mvc/GlobalDefaultExceptionHandler.java new file mode 100644 index 0000000..022764f --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/GlobalDefaultExceptionHandler.java @@ -0,0 +1,40 @@ +package ru.ulstu.extractor.mvc; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.NoHandlerFoundException; + +import javax.servlet.http.HttpServletRequest; + +@ControllerAdvice +class GlobalDefaultExceptionHandler { + public static final String DEFAULT_ERROR_VIEW = "error"; + + @ExceptionHandler(value = Exception.class) + public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) { + // If the exception is annotated with @ResponseStatus rethrow it and let + // the framework handle it - like the OrderNotFoundException example + // at the start of this post. + // AnnotationUtils is a Spring Framework utility class. + /*if (AnnotationUtils.findAnnotation (e.getClass(), ResponseStatus.class) != null) { + throw e; + } + */ + + // Otherwise setup and send the user to a default error-view. + ModelAndView mav = new ModelAndView(); + mav.addObject("exception", e); + mav.addObject("url", req.getRequestURL()); + mav.setViewName(DEFAULT_ERROR_VIEW); + return mav; + } + + @ExceptionHandler(NoHandlerFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public String handle(NoHandlerFoundException ex) { + return "DEFAULT_ERROR_VIEW"; + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/extractor/mvc/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/mvc/MvcConfiguration.java new file mode 100644 index 0000000..1b55b43 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/MvcConfiguration.java @@ -0,0 +1,23 @@ +package ru.ulstu.extractor.mvc; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class MvcConfiguration implements WebMvcConfigurer { + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/{articlename:\\w+}"); + registry.addRedirectViewController("/", "/index"); + registry.addRedirectViewController("/default", "/home"); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry + .addResourceHandler("/webjars/**") + .addResourceLocations("/webjars/"); + } +} diff --git a/src/main/java/ru/ulstu/extractor/mvc/TemplateConfiguration.java b/src/main/java/ru/ulstu/extractor/mvc/TemplateConfiguration.java new file mode 100644 index 0000000..4a0ad46 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/TemplateConfiguration.java @@ -0,0 +1,19 @@ +package ru.ulstu.extractor.mvc; + +import nz.net.ultraq.thymeleaf.LayoutDialect; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.templateresolver.ITemplateResolver; + +@Configuration +public class TemplateConfiguration { + + @Bean + public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver) { + final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); + templateEngine.addTemplateResolver(templateResolver); + templateEngine.addDialect(new LayoutDialect()); + return templateEngine; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c5d4c5d..c616bb3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,4 +2,6 @@ spring.main.banner-mode=off server.port=8080 # Available levels are: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF logging.level.ru.ulstu=DEBUG -extractor.custom-projects-dir= \ No newline at end of file +extractor.custom-projects-dir= +# Thymeleaf Settings +spring.thymeleaf.cache=false diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html new file mode 100644 index 0000000..86a443c --- /dev/null +++ b/src/main/resources/templates/default.html @@ -0,0 +1,67 @@ + + + + + GitExtractor + + + + + + + + + + +
+ + +
+ +
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index dd06612..bb0ca4a 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -1,53 +1,45 @@ + xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + layout:decorate="~{default}"> - -

Support Friendly Error Page

+
+

Ошибка

- -

- Page: Page URL -

+ +

+ Страница: Page URL +

-

- Occurred: Timestamp -

+

+ Время: Timestamp +

-

- Response Status: status-code error ... -

- -

- Exception: exception - -

Application has encountered an error. Please contact support on - ...

- -

Support may ask you to right click to view page source.

- - -
-
${url}
-
${exception.message}
- -
- - -
- - +

+ Response Status: status-code error ... +

+

+ +

+
+
+
${url}
+
${exception.message}
+
    +
  • ${ste}
  • +
+
+
+
\ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index f37aa8f..939171f 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,30 +1,32 @@ - - + + Простая обработка формы на Spring MVC - -

Форма

-
-

- - - - - - - - - - - -
Тема:
Кому:
Сообщение: