src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt

Fri, 30 Dec 2022 19:14:04 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 30 Dec 2022 19:14:04 +0100
changeset 264
7d67245e5121
parent 260
fb2ae2d63a56
child 284
671c1c8fbf1c
permissions
-rw-r--r--

disable autocomplete for issue relations

The reason is that autocomplete would suggest issues
from other projects. But we only want the datalist
to serve the suggestions.

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
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
163 fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>),
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
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
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
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
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
176 private fun forward(jsp: String) {
195
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
177 request.getRequestDispatcher(jspPath(jsp)).forward(request, response)
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
178 }
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
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 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
181 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
182 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
183 }
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
184
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
185 fun render(page: String? = null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
186 page?.let { contentPage = it }
195
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
187 forward("site")
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
188 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
189
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
190 fun renderCommit(location: String? = null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
191 location?.let { redirectLocation = it }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
192 contentPage = Constants.JSP_COMMIT_SUCCESSFUL
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
193 render()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
194 }
205
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
195
260
fb2ae2d63a56 some minor style fixes
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
196 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
197 }
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 /**
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 * A path pattern optionally containing placeholders.
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 * The special directories . and .. are disallowed in the pattern.
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
203 * Placeholders start with a % sign.
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 * @param pattern the pattern
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 */
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 class PathPattern(pattern: String) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 private val nodePatterns: List<String>
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 private val collection: Boolean
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 private fun parse(pattern: String): List<String> {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 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
213 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
214 return nodes
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 /**
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 * Matches a path against this pattern.
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 * 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
220 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 * @param path the path to match
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 * @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
223 */
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 fun matches(path: String): Boolean {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 if (collection xor path.endsWith("/")) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 val nodes = parse(path)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 if (nodePatterns.size != nodes.size) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 for (i in nodePatterns.indices) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 val pattern = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 val node = nodes[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
231 if (pattern.startsWith("%")) continue
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 if (pattern != node) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 return true
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236
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 * 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
239 * 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
240 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 * @param path the path
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 * @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
243 * @see .matches
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 fun obtainPathParameters(path: String): PathParameters {
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
246 val params = mutableMapOf<String, String>()
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 val nodes = parse(path)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 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
249 val pattern = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 val node = nodes[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
251 if (pattern.startsWith("%")) {
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 params[pattern.substring(1)] = node
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 return params
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 }
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 override fun hashCode(): Int {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 val str = StringBuilder()
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 for (node in nodePatterns) {
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
261 if (node.startsWith("%")) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
262 str.append("/%")
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 } else {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 str.append('/')
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 str.append(node)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 if (collection) str.append('/')
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 return str.toString().hashCode()
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 override fun equals(other: Any?): Boolean {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 if (other is PathPattern) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 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
275 for (i in nodePatterns.indices) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 val left = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 val right = other.nodePatterns[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
278 if (left.startsWith("%") && right.startsWith("%")) continue
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 if (left != right) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 return true
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 } else {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 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 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 init {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 nodePatterns = parse(pattern)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 collection = pattern.endsWith("/")
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 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292
225
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
293 // <editor-fold desc="Validators">
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
294
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
295 fun dateOptValidator(input: String?): ValidationResult<SqlDate?> {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
296 return if (input.isNullOrBlank()) {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
297 ValidatedValue(null)
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
298 } else {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
299 try {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
300 ValidatedValue(SqlDate.valueOf(input))
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
301 } catch (ignored: IllegalArgumentException) {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
302 ValidationError("validation.date.format")
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
303 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
304 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
305 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
306
227
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
307 fun boolValidator(input: String?): ValidationResult<Boolean> {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
308 return if (input.isNullOrBlank()) {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
309 ValidatedValue(false)
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
310 } else {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
311 ValidatedValue(!(input.equals("false", true) || input == "0"))
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
312 }
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
313 }
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
314
225
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
315 // </editor-fold>

mercurial