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

changeset 374
34abadbdd0e3
parent 367
0a9065936aac
equal deleted inserted replaced
373:4ea722f9cb66 374:34abadbdd0e3
66 * @see Constants#REQ_ATTR_CONTENT_PAGE 66 * @see Constants#REQ_ATTR_CONTENT_PAGE
67 */ 67 */
68 var contentPage = "" 68 var contentPage = ""
69 set(value) { 69 set(value) {
70 field = value 70 field = value
71 request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, jspPath(value)) 71 request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE,
72 Constants.JSP_PATH_PREFIX + value + ".jsp")
72 } 73 }
73 74
74 /** 75 /**
75 * The name of the content page. 76 * The name of the content page.
76 * 77 *
89 */ 90 */
90 var styleSheets = emptyList<String>() 91 var styleSheets = emptyList<String>()
91 set(value) { 92 set(value) {
92 field = value 93 field = value
93 request.setAttribute(Constants.REQ_ATTR_STYLESHEET, 94 request.setAttribute(Constants.REQ_ATTR_STYLESHEET,
94 value.map { it.withExt(".css") } 95 value.map { "$it.css" }
95 ) 96 )
96 } 97 }
97 98
98 /** 99 /**
99 * A list of additional style sheets. 100 * A list of additional style sheets.
102 */ 103 */
103 var javascript = "" 104 var javascript = ""
104 set(value) { 105 set(value) {
105 field = value 106 field = value
106 request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT, 107 request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT,
107 value.withExt(".js") 108 "$value.js"
108 ) 109 )
109 } 110 }
110 111
111 /** 112 /**
112 * The name of the navigation menu JSP. 113 * The name of the navigation menu JSP.
154 val baseHref get() = "${request.scheme}://${request.serverName}$portInfo${request.contextPath}/" 155 val baseHref get() = "${request.scheme}://${request.serverName}$portInfo${request.contextPath}/"
155 156
156 init { 157 init {
157 request.setAttribute(Constants.REQ_ATTR_BASE_HREF, baseHref) 158 request.setAttribute(Constants.REQ_ATTR_BASE_HREF, baseHref)
158 } 159 }
159
160 private fun String.withExt(ext: String) = if (endsWith(ext)) this else plus(ext)
161 private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp")
162 160
163 fun paramIndexed(prefix: String): Map<Int, String> = buildMap { 161 fun paramIndexed(prefix: String): Map<Int, String> = buildMap {
164 for (name in request.parameterNames) { 162 for (name in request.parameterNames) {
165 if (name.startsWith(prefix)) { 163 if (name.startsWith(prefix)) {
166 val key = name.substring(prefix.length).toIntOrNull() 164 val key = name.substring(prefix.length).toIntOrNull()
201 val body: String by lazy { 199 val body: String by lazy {
202 request.reader.lineSequence().joinToString("\n") 200 request.reader.lineSequence().joinToString("\n")
203 } 201 }
204 202
205 private fun forward(jsp: String) { 203 private fun forward(jsp: String) {
206 request.getRequestDispatcher(jspPath(jsp)).forward(request, response) 204 request.setAttribute(Constants.REQ_ATTR_JSP, jsp)
207 } 205 }
208 206
209 fun renderFeed(page: String? = null) { 207 fun renderFeed(page: String? = null) {
210 page?.let { contentPage = it } 208 page?.let { contentPage = it }
211 forward("feed") 209 forward("feed")

mercurial