Mon, 05 Aug 2024 18:40:47 +0200
add new global issues page - fixes #404
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. |
311
bf67e0ff7131
add new global issues page - fixes #404
Mike Becker <universe@uap-core.de>
parents:
292
diff
changeset
|
87 | * TODO: remove this unnecessary attribute and merge all style sheets into one global |
184
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 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
133 | * The view object. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | * |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
135 | * @see Constants#REQ_ATTR_VIEWMODEL |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
136 | */ |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
137 | var view: View? = null |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
138 | set(value) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
139 | field = value |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
140 | request.setAttribute(Constants.REQ_ATTR_VIEWMODEL, value) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
141 | } |
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 | /** |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
144 | * 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
|
145 | */ |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
146 | 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
|
147 | 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
|
148 | || (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
|
149 | ) "" 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
|
150 | |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
151 | /** |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
152 | * The base path of this application. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
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 | 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
|
155 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
156 | 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
|
157 | 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
|
158 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
159 | fun param(name: String): String? = request.getParameter(name) |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
160 | 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
|
161 | |
210 | 162 | fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>), |
163 | defaultValue: T, errorMessages: MutableList<String>): T { | |
209
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
164 | return when (val result = validator(param(name))) { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
165 | is ValidationError -> { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
166 | errorMessages.add(i18n(result.message)) |
210 | 167 | defaultValue |
209
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
168 | } |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
169 | is ValidatedValue -> { |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
170 | result.result |
c9c6abf167c7
#21 adds input validation mechanism
Mike Becker <universe@uap-core.de>
parents:
207
diff
changeset
|
171 | } |
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 | |
292
703591e739f4
add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents:
284
diff
changeset
|
175 | |
703591e739f4
add possibility to show issues w/o version or component - fixes #335
Mike Becker <universe@uap-core.de>
parents:
284
diff
changeset
|
176 | 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
|
177 | 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
|
178 | 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
|
179 | "-" -> 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
|
180 | "~" -> 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
|
181 | 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
|
182 | ?.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
|
183 | ?: 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
|
184 | } |
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 | |
284
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
187 | val body: String by lazy { |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
188 | request.reader.lineSequence().joinToString("\n") |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
189 | } |
671c1c8fbf1c
add full support for commit references - fixes #276
Mike Becker <universe@uap-core.de>
parents:
260
diff
changeset
|
190 | |
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
191 | private fun forward(jsp: String) { |
195 | 192 | request.getRequestDispatcher(jspPath(jsp)).forward(request, response) |
193 | } | |
194 | ||
198
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
195 | 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
|
196 | 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
|
197 | 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
|
198 | } |
94f174d591ab
fixes wrong handling of feeds - only one channel per feed is allowed
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
199 | |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
200 | fun render(page: String? = null) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
201 | page?.let { contentPage = it } |
195 | 202 | forward("site") |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
203 | } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
204 | |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
205 | fun renderCommit(location: String? = null) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
206 | location?.let { redirectLocation = it } |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
207 | contentPage = Constants.JSP_COMMIT_SUCCESSFUL |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
208 | render() |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
209 | } |
205
7725a79416f3
#115 adds custom page titles
Mike Becker <universe@uap-core.de>
parents:
199
diff
changeset
|
210 | |
260 | 211 | 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
|
212 | } |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | * A path pattern optionally containing placeholders. |
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 | * The special directories . and .. are disallowed in the pattern. |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
218 | * Placeholders start with a % sign. |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | * @param pattern the pattern |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | class PathPattern(pattern: String) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | private val nodePatterns: List<String> |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | private val collection: Boolean |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | private fun parse(pattern: String): List<String> { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | 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
|
228 | 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
|
229 | return nodes |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | } |
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 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | * Matches a path against this pattern. |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | * 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
|
235 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | * @param path the path to match |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | * @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
|
238 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | fun matches(path: String): Boolean { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | if (collection xor path.endsWith("/")) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | val nodes = parse(path) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | if (nodePatterns.size != nodes.size) return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | for (i in nodePatterns.indices) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | val pattern = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | val node = nodes[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
246 | if (pattern.startsWith("%")) continue |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | if (pattern != node) return false |
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 | return true |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
250 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
251 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | /** |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | * 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
|
254 | * 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
|
255 | * |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | * @param path the path |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | * @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
|
258 | * @see .matches |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | */ |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | fun obtainPathParameters(path: String): PathParameters { |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
261 | val params = mutableMapOf<String, String>() |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | val nodes = parse(path) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | 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
|
264 | val pattern = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
265 | val node = nodes[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
266 | if (pattern.startsWith("%")) { |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | params[pattern.substring(1)] = node |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | } |
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 | return params |
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 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | override fun hashCode(): Int { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | val str = StringBuilder() |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | for (node in nodePatterns) { |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
276 | if (node.startsWith("%")) { |
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
277 | str.append("/%") |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | } else { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | str.append('/') |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
280 | str.append(node) |
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 | if (collection) str.append('/') |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | return str.toString().hashCode() |
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 | override fun equals(other: Any?): Boolean { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | if (other is PathPattern) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | 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
|
290 | for (i in nodePatterns.indices) { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | val left = nodePatterns[i] |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | val right = other.nodePatterns[i] |
184
e8eecee6aadf
completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
293 | if (left.startsWith("%") && right.startsWith("%")) continue |
179
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | if (left != right) return false |
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 | return true |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | } else { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
298 | return false |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
300 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
301 | |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
302 | init { |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
303 | nodePatterns = parse(pattern) |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
304 | collection = pattern.endsWith("/") |
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 | } |
623c340058f3
migrates the utility classes for the AbstractServlet
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
307 | |
225
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
308 | // <editor-fold desc="Validators"> |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
309 | |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
310 | fun dateOptValidator(input: String?): ValidationResult<SqlDate?> { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
311 | return if (input.isNullOrBlank()) { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
312 | ValidatedValue(null) |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
313 | } else { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
314 | try { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
315 | ValidatedValue(SqlDate.valueOf(input)) |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
316 | } catch (ignored: IllegalArgumentException) { |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
317 | ValidationError("validation.date.format") |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
318 | } |
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 | } |
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
321 | |
227
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
322 | fun boolValidator(input: String?): ValidationResult<Boolean> { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
323 | return if (input.isNullOrBlank()) { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
324 | ValidatedValue(false) |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
325 | } else { |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
326 | ValidatedValue(!(input.equals("false", true) || input == "0")) |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
327 | } |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
328 | } |
f0ede8046b59
#162 adds active flag to component
Mike Becker <universe@uap-core.de>
parents:
225
diff
changeset
|
329 | |
225
87328572e36f
#159 adds release and eol dates
Mike Becker <universe@uap-core.de>
parents:
210
diff
changeset
|
330 | // </editor-fold> |