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

changeset 198
94f174d591ab
parent 195
9c7aff3cbb14
child 199
59393c8cc557
equal deleted inserted replaced
197:0a2ad22ac656 198:94f174d591ab
84 set(value) { 84 set(value) {
85 field = value 85 field = value
86 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value) 86 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value)
87 } 87 }
88 88
89 var feedPath = ""
90 set(value) {
91 field = value
92 request.setAttribute(Constants.REQ_ATTR_FEED_HREF, baseHref + value)
93 }
94
89 /** 95 /**
90 * The view object. 96 * The view object.
91 * 97 *
92 * @see Constants#REQ_ATTR_VIEWMODEL 98 * @see Constants#REQ_ATTR_VIEWMODEL
93 */ 99 */
96 field = value 102 field = value
97 request.setAttribute(Constants.REQ_ATTR_VIEWMODEL, value) 103 request.setAttribute(Constants.REQ_ATTR_VIEWMODEL, value)
98 } 104 }
99 105
100 /** 106 /**
107 * Additional port info, if necessary.
108 */
109 private val portInfo =
110 if ((request.scheme == "http" && request.serverPort == 80)
111 || (request.scheme == "https" && request.serverPort == 443)
112 ) "" else ":${request.serverPort}"
113
114 /**
101 * The base path of this application. 115 * The base path of this application.
102 */ 116 */
103 val baseHref get() = "${request.scheme}://${request.serverName}:${request.serverPort}${request.contextPath}/" 117 val baseHref get() = "${request.scheme}://${request.serverName}$portInfo${request.contextPath}/"
118
119 init {
120 feedPath = "feed/projects.rss"
121 }
104 122
105 private fun String.withExt(ext: String) = if (endsWith(ext)) this else plus(ext) 123 private fun String.withExt(ext: String) = if (endsWith(ext)) this else plus(ext)
106 private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp") 124 private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp")
107 125
108 fun param(name: String): String? = request.getParameter(name) 126 fun param(name: String): String? = request.getParameter(name)
109 fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray() 127 fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray()
110 128
111 fun forward(jsp: String) { 129 private fun forward(jsp: String) {
112 request.getRequestDispatcher(jspPath(jsp)).forward(request, response) 130 request.getRequestDispatcher(jspPath(jsp)).forward(request, response)
131 }
132
133 fun renderFeed(page: String? = null) {
134 page?.let { contentPage = it }
135 forward("feed")
113 } 136 }
114 137
115 fun render(page: String? = null) { 138 fun render(page: String? = null) {
116 page?.let { contentPage = it } 139 page?.let { contentPage = it }
117 forward("site") 140 forward("site")

mercurial