Sun, 03 Sep 2023 12:02:44 +0200
fonts and styles are now cachable - fixes #286
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * Copyright 2021 Mike Becker. All rights reserved. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Redistribution and use in source and binary forms, with or without |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * modification, are permitted provided that the following conditions are met: |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * 1. Redistributions of source code must retain the above copyright |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * notice, this list of conditions and the following disclaimer. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * notice, this list of conditions and the following disclaimer in the |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * documentation and/or other materials provided with the distribution. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | package de.uapcore.lightpit |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
28 | import de.uapcore.lightpit.dao.DataAccessObject |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
29 | import de.uapcore.lightpit.viewmodel.NavMenu |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
30 | import de.uapcore.lightpit.viewmodel.View |
254
55ca6cafc3dd
#233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
31 | import jakarta.servlet.http.HttpServletRequest |
55ca6cafc3dd
#233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
32 | import jakarta.servlet.http.HttpServletResponse |
55ca6cafc3dd
#233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
33 | import jakarta.servlet.http.HttpSession |
205
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
34 | import java.util.* |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | import kotlin.math.min |
225
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
36 | import java.sql.Date as SqlDate |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
38 | typealias MappingMethod = (HttpRequest, DataAccessObject) -> Unit |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
39 | typealias PathParameters = Map<String, String> |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
40 | |
209
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
41 | sealed interface ValidationResult<T> |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
42 | class ValidationError<T>(val message: String): ValidationResult<T> |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
43 | class ValidatedValue<T>(val result: T): ValidationResult<T> |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
44 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
45 | class HttpRequest( |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
46 | val request: HttpServletRequest, |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
47 | val response: HttpServletResponse, |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
48 | val pathParams: PathParameters = emptyMap() |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
49 | ) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
50 | val session: HttpSession = request.session |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
51 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
52 | val remoteUser: String? = request.remoteUser |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
53 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
54 | /** |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
55 | * The name of the content page. |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
56 | * |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
57 | * @see Constants#REQ_ATTR_CONTENT_PAGE |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
58 | */ |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
59 | var contentPage = "" |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
60 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
61 | field = value |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
62 | request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, jspPath(value)) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
63 | } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
64 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
65 | /** |
205
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
66 | * The name of the content page. |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
67 | * |
207
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
68 | * @see Constants#REQ_ATTR_PAGE_TITLE |
205
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
69 | */ |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
70 | var pageTitle = "" |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
71 | set(value) { |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
72 | field = value |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
73 | request.setAttribute(Constants.REQ_ATTR_PAGE_TITLE, value) |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
74 | } |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
75 | |
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
76 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
77 | * A list of additional style sheets. |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
78 | * |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
79 | * @see Constants#REQ_ATTR_STYLESHEET |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
80 | */ |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
81 | var styleSheets = emptyList<String>() |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
82 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
83 | field = value |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
84 | request.setAttribute(Constants.REQ_ATTR_STYLESHEET, |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
85 | value.map { it.withExt(".css") } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
86 | ) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
87 | } |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | /** |
207
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
90 | * A list of additional style sheets. |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
91 | * |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
92 | * @see Constants#REQ_ATTR_JAVASCRIPT |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
93 | */ |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
94 | var javascript = "" |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
95 | set(value) { |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
96 | field = value |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
97 | request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT, |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
98 | value.withExt(".js") |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
99 | ) |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
100 | } |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
101 | |
479dd7993ef9
#22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents:
205
diff
changeset
|
102 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
103 | * The name of the navigation menu JSP. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | * |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
105 | * @see Constants#REQ_ATTR_NAVIGATION |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | */ |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
107 | var navigationMenu: NavMenu? = null |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
108 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
109 | field = value |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
110 | request.setAttribute(Constants.REQ_ATTR_NAVIGATION, navigationMenu) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
111 | } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
112 | |
199
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
113 | var redirectLocation: String? = null |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
114 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
115 | field = value |
199
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
116 | if (value == null) { |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
117 | request.removeAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION) |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
118 | } else { |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
119 | request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value) |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
120 | } |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
121 | } |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | |
199
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
123 | var feedPath: String? = null |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
124 | set(value) { |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
125 | field = value |
199
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
126 | if (value == null) { |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
127 | request.removeAttribute(Constants.REQ_ATTR_FEED_HREF) |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
128 | } else { |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
129 | request.setAttribute(Constants.REQ_ATTR_FEED_HREF, baseHref + value) |
59393c8cc557
#109 adds RSS feed button to project header and changes feed output slightly
Mike Becker <universe@uap-core.de>
parents:
198
diff
changeset
|
130 | } |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
131 | } |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
132 | |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
134 | * The view object. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | * |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
136 | * @see Constants#REQ_ATTR_VIEWMODEL |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
137 | */ |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
138 | var view: View? = null |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
139 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
140 | field = value |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
141 | request.setAttribute(Constants.REQ_ATTR_VIEWMODEL, value) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
142 | } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
143 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
144 | /** |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
145 | * Additional port info, if necessary. |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
146 | */ |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
147 | private val portInfo = |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
148 | if ((request.scheme == "http" && request.serverPort == 80) |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
149 | || (request.scheme == "https" && request.serverPort == 443) |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
150 | ) "" else ":${request.serverPort}" |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
151 | |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
152 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
153 | * The base path of this application. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | */ |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
155 | val baseHref get() = "${request.scheme}://${request.serverName}$portInfo${request.contextPath}/" |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
156 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
157 | private fun String.withExt(ext: String) = if (endsWith(ext)) this else plus(ext) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
158 | private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp") |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
159 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
160 | fun param(name: String): String? = request.getParameter(name) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
161 | fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray() |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | |
210 | 163 | fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>), |
164 | defaultValue: T, errorMessages: MutableList<String>): T { | |
209
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
165 | return when (val result = validator(param(name))) { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
166 | is ValidationError -> { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
167 | errorMessages.add(i18n(result.message)) |
210 | 168 | defaultValue |
209
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
169 | } |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
170 | is ValidatedValue -> { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
171 | result.result |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
172 | } |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
173 | } |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
174 | } |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
175 | |
284
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
176 | val body: String by lazy { |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
177 | request.reader.lineSequence().joinToString("\n") |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
178 | } |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
179 | |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
180 | private fun forward(jsp: String) { |
195 | 181 | request.getRequestDispatcher(jspPath(jsp)).forward(request, response) |
182 | } | |
183 | ||
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
184 | fun renderFeed(page: String? = null) { |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
185 | page?.let { contentPage = it } |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
186 | forward("feed") |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
187 | } |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
188 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
189 | fun render(page: String? = null) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
190 | page?.let { contentPage = it } |
195 | 191 | forward("site") |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
192 | } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
193 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
194 | fun renderCommit(location: String? = null) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
195 | location?.let { redirectLocation = it } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
196 | contentPage = Constants.JSP_COMMIT_SUCCESSFUL |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
197 | render() |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
198 | } |
205
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
199 | |
260 | 200 | fun i18n(key: String): String = ResourceBundle.getBundle("localization/strings", response.locale).getString(key) |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
201 | } |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | * A path pattern optionally containing placeholders. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | * The special directories . and .. are disallowed in the pattern. |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
207 | * Placeholders start with a % sign. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | * @param pattern the pattern |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | class PathPattern(pattern: String) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | private val nodePatterns: List<String> |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | private val collection: Boolean |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | private fun parse(pattern: String): List<String> { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | val nodes = pattern.split("/").filter { it.isNotBlank() }.toList() |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | require(nodes.none { it == "." || it == ".." }) { "Path must not contain '.' or '..' nodes." } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | return nodes |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | * Matches a path against this pattern. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | * The path must be canonical in the sense that no . or .. parts occur. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | * @param path the path to match |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | * @return true if the path matches the pattern, false otherwise |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | fun matches(path: String): Boolean { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | if (collection xor path.endsWith("/")) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | val nodes = parse(path) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | if (nodePatterns.size != nodes.size) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | for (i in nodePatterns.indices) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | val pattern = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | val node = nodes[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
235 | if (pattern.startsWith("%")) continue |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | if (pattern != node) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | return true |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | * Returns the path parameters found in the specified path using this pattern. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | * The return value of this method is undefined, if the patter does not match. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | * @param path the path |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
246 | * @return the path parameters, if any, or an empty map |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | * @see .matches |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | fun obtainPathParameters(path: String): PathParameters { |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
250 | val params = mutableMapOf<String, String>() |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
251 | val nodes = parse(path) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | for (i in 0 until min(nodes.size, nodePatterns.size)) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | val pattern = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | val node = nodes[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
255 | if (pattern.startsWith("%")) { |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | params[pattern.substring(1)] = node |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | return params |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | override fun hashCode(): Int { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | val str = StringBuilder() |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | for (node in nodePatterns) { |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
265 | if (node.startsWith("%")) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
266 | str.append("/%") |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | } else { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | str.append('/') |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | str.append(node) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
271 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | if (collection) str.append('/') |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | return str.toString().hashCode() |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | override fun equals(other: Any?): Boolean { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | if (other is PathPattern) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | if (collection xor other.collection || nodePatterns.size != other.nodePatterns.size) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | for (i in nodePatterns.indices) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
280 | val left = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
281 | val right = other.nodePatterns[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
282 | if (left.startsWith("%") && right.startsWith("%")) continue |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | if (left != right) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | return true |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | } else { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
287 | return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | init { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | nodePatterns = parse(pattern) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | collection = pattern.endsWith("/") |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
295 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | |
225
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
297 | // <editor-fold desc="Validators"> |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
298 | |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
299 | fun dateOptValidator(input: String?): ValidationResult<SqlDate?> { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
300 | return if (input.isNullOrBlank()) { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
301 | ValidatedValue(null) |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
302 | } else { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
303 | try { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
304 | ValidatedValue(SqlDate.valueOf(input)) |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
305 | } catch (ignored: IllegalArgumentException) { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
306 | ValidationError("validation.date.format") |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
307 | } |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
308 | } |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
309 | } |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
310 | |
227
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
311 | fun boolValidator(input: String?): ValidationResult<Boolean> { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
312 | return if (input.isNullOrBlank()) { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
313 | ValidatedValue(false) |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
314 | } else { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
315 | ValidatedValue(!(input.equals("false", true) || input == "0")) |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
316 | } |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
317 | } |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
318 | |
225
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
319 | // </editor-fold> |