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

Sat, 30 Dec 2023 13:34:06 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 30 Dec 2023 13:34:06 +0100
changeset 297
24155683fc89
parent 292
703591e739f4
child 311
bf67e0ff7131
permissions
-rw-r--r--

add another stupid magic command to gradle file because things stop working by default

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
292
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
29 import de.uapcore.lightpit.entities.HasNode
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
30 import de.uapcore.lightpit.viewmodel.NavMenu
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
31 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
32 import jakarta.servlet.http.HttpServletRequest
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 227
diff changeset
33 import jakarta.servlet.http.HttpServletResponse
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 227
diff changeset
34 import jakarta.servlet.http.HttpSession
205
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
35 import java.util.*
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 import kotlin.math.min
225
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
37 import java.sql.Date as SqlDate
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
39 typealias MappingMethod = (HttpRequest, DataAccessObject) -> Unit
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
40 typealias PathParameters = Map<String, String>
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
41
292
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
42 sealed class OptionalPathInfo<in T : HasNode>(info: T) {
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
43 class Specific<T: HasNode>(val elem: T) : OptionalPathInfo<T>(elem)
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
44 data object All : OptionalPathInfo<HasNode>(object : HasNode { override val node = "-"})
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
45 data object None : OptionalPathInfo<HasNode>(object : HasNode { override val node = "~"})
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
46 data object NotFound : OptionalPathInfo<HasNode>(object : HasNode { override val node = ""})
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
47 val node = info.node
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
48 }
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
49
209
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
50 sealed interface ValidationResult<T>
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
51 class ValidationError<T>(val message: String): ValidationResult<T>
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
52 class ValidatedValue<T>(val result: T): ValidationResult<T>
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
53
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
54 class HttpRequest(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
55 val request: HttpServletRequest,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
56 val response: HttpServletResponse,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
57 val pathParams: PathParameters = emptyMap()
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 val session: HttpSession = request.session
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
60
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
61 val remoteUser: String? = request.remoteUser
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
62
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 * The name of the content page.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
65 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
66 * @see Constants#REQ_ATTR_CONTENT_PAGE
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
67 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
68 var contentPage = ""
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
69 set(value) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
70 field = value
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
71 request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, jspPath(value))
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
72 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
73
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
74 /**
205
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
75 * The name of the content page.
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
76 *
207
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
77 * @see Constants#REQ_ATTR_PAGE_TITLE
205
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
78 */
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
79 var pageTitle = ""
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
80 set(value) {
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
81 field = value
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
82 request.setAttribute(Constants.REQ_ATTR_PAGE_TITLE, value)
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
83 }
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
84
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
85 /**
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
86 * A list of additional style sheets.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
87 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
88 * @see Constants#REQ_ATTR_STYLESHEET
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
89 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
90 var styleSheets = emptyList<String>()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
91 set(value) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
92 field = value
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
93 request.setAttribute(Constants.REQ_ATTR_STYLESHEET,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
94 value.map { it.withExt(".css") }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
95 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
96 }
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 /**
207
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
99 * A list of additional style sheets.
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 * @see Constants#REQ_ATTR_JAVASCRIPT
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
102 */
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
103 var javascript = ""
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
104 set(value) {
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
105 field = value
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
106 request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT,
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
107 value.withExt(".js")
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
108 )
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
109 }
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
110
479dd7993ef9 #22 adds possibility to edit own comments
Mike Becker <universe@uap-core.de>
parents: 205
diff changeset
111 /**
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
112 * 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
113 *
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
114 * @see Constants#REQ_ATTR_NAVIGATION
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 */
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
116 var navigationMenu: NavMenu? = null
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
117 set(value) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
118 field = value
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
119 request.setAttribute(Constants.REQ_ATTR_NAVIGATION, navigationMenu)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
120 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
121
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
122 var redirectLocation: String? = null
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
123 set(value) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
124 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
125 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
126 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
127 } 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
128 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
129 }
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
130 }
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131
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
132 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
133 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
134 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
135 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
136 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
137 } 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
138 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
139 }
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
140 }
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
141
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 /**
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
143 * The view object.
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 *
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
145 * @see Constants#REQ_ATTR_VIEWMODEL
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
146 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
147 var view: View? = null
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
148 set(value) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
149 field = value
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
150 request.setAttribute(Constants.REQ_ATTR_VIEWMODEL, value)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
151 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
152
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
153 /**
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
154 * 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
155 */
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
156 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
157 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
158 || (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
159 ) "" 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
160
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
161 /**
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
162 * The base path of this application.
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 */
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
164 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
165
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
166 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
167 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
168
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
169 fun param(name: String): String? = request.getParameter(name)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
170 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
171
210
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
172 fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>),
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
173 defaultValue: T, errorMessages: MutableList<String>): T {
209
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
174 return when (val result = validator(param(name))) {
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
175 is ValidationError -> {
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
176 errorMessages.add(i18n(result.message))
210
37fbdcb422b7 minor code changes
Mike Becker <universe@uap-core.de>
parents: 209
diff changeset
177 defaultValue
209
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
178 }
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
179 is ValidatedValue -> {
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
180 result.result
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
181 }
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
182 }
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
183 }
c9c6abf167c7 #21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents: 207
diff changeset
184
292
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
185
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
186 fun <T : HasNode> lookupPathParam(paramName: String, list: List<T>): OptionalPathInfo<T> {
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
187 return when (val node = this.pathParams[paramName]) {
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
188 null -> OptionalPathInfo.All
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
189 "-" -> OptionalPathInfo.All
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
190 "~" -> OptionalPathInfo.None
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
191 else -> list.find { it.node == node }
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
192 ?.let { OptionalPathInfo.Specific(it) }
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
193 ?: OptionalPathInfo.NotFound
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
194 }
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
195 }
703591e739f4 add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents: 284
diff changeset
196
284
671c1c8fbf1c add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents: 260
diff changeset
197 val body: String by lazy {
671c1c8fbf1c add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents: 260
diff changeset
198 request.reader.lineSequence().joinToString("\n")
671c1c8fbf1c add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents: 260
diff changeset
199 }
671c1c8fbf1c add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents: 260
diff changeset
200
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
201 private fun forward(jsp: String) {
195
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
202 request.getRequestDispatcher(jspPath(jsp)).forward(request, response)
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
203 }
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
204
198
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
205 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
206 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
207 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
208 }
94f174d591ab fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents: 195
diff changeset
209
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
210 fun render(page: String? = null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
211 page?.let { contentPage = it }
195
9c7aff3cbb14 #109 - add RSS feed
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
212 forward("site")
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
213 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
214
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
215 fun renderCommit(location: String? = null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
216 location?.let { redirectLocation = it }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
217 contentPage = Constants.JSP_COMMIT_SUCCESSFUL
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
218 render()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
219 }
205
7725a79416f3 #115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents: 199
diff changeset
220
260
fb2ae2d63a56 some minor style fixes
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
221 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
222 }
179
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 /**
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 * A path pattern optionally containing placeholders.
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 * The special directories . and .. are disallowed in the pattern.
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
228 * Placeholders start with a % sign.
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 * @param pattern the pattern
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 */
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 class PathPattern(pattern: String) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 private val nodePatterns: List<String>
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 private val collection: Boolean
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 private fun parse(pattern: String): List<String> {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 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
238 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
239 return nodes
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 /**
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 * Matches a path against this pattern.
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 * 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
245 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 * @param path the path to match
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 * @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
248 */
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 fun matches(path: String): Boolean {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 if (collection xor path.endsWith("/")) return false
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 if (nodePatterns.size != nodes.size) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 for (i in nodePatterns.indices) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 val pattern = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 val node = nodes[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
256 if (pattern.startsWith("%")) continue
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 if (pattern != node) return false
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 true
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 /**
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 * 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
264 * 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
265 *
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 * @param path the path
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 * @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
268 * @see .matches
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 */
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 fun obtainPathParameters(path: String): PathParameters {
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
271 val params = mutableMapOf<String, String>()
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 val nodes = parse(path)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 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
274 val pattern = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 val node = nodes[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
276 if (pattern.startsWith("%")) {
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 params[pattern.substring(1)] = node
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 return params
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 override fun hashCode(): Int {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 val str = StringBuilder()
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 for (node in nodePatterns) {
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
286 if (node.startsWith("%")) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
287 str.append("/%")
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 } else {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 str.append('/')
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 str.append(node)
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 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 if (collection) str.append('/')
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 return str.toString().hashCode()
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
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 override fun equals(other: Any?): Boolean {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 if (other is PathPattern) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 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
300 for (i in nodePatterns.indices) {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 val left = nodePatterns[i]
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 val right = other.nodePatterns[i]
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents: 179
diff changeset
303 if (left.startsWith("%") && right.startsWith("%")) continue
179
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304 if (left != right) return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 return true
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 } else {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 return false
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 init {
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 nodePatterns = parse(pattern)
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 collection = pattern.endsWith("/")
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 }
623c340058f3 migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317
225
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
318 // <editor-fold desc="Validators">
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
319
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
320 fun dateOptValidator(input: String?): ValidationResult<SqlDate?> {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
321 return if (input.isNullOrBlank()) {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
322 ValidatedValue(null)
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
323 } else {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
324 try {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
325 ValidatedValue(SqlDate.valueOf(input))
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
326 } catch (ignored: IllegalArgumentException) {
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
327 ValidationError("validation.date.format")
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
328 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
329 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
330 }
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
331
227
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
332 fun boolValidator(input: String?): ValidationResult<Boolean> {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
333 return if (input.isNullOrBlank()) {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
334 ValidatedValue(false)
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
335 } else {
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
336 ValidatedValue(!(input.equals("false", true) || input == "0"))
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
337 }
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
338 }
f0ede8046b59 #162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
339
225
87328572e36f #159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents: 210
diff changeset
340 // </editor-fold>

mercurial