Skip to content

Commit

Permalink
removed unneeded parser for new annotation based parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schuehly committed Aug 10, 2023
1 parent 6ca7141 commit 3c7c57a
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 443 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ import java.io.File
import java.time.Duration

@Configuration
@ComponentScan("de.tschuehly.spring.viewcomponent.core.component")
@ComponentScan("de.tschuehly.spring.viewcomponent.core")
class ViewComponentAutoConfiguration(
) {


@ConditionalOnProperty("spring.view-component.view-action.enabled", havingValue = "true")
@ComponentScan("de.tschuehly.spring.viewcomponent.core.action")
class ViewActionConfiguration {}

@Bean
@ConditionalOnProperty("spring.view-component.local-development")
fun viewComponentFileSystemWatcher(applicationContext: ApplicationContext): FileSystemWatcher {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
import org.springframework.web.util.pattern.PathPatternParser
import java.lang.reflect.Method
import de.tschuehly.spring.viewcomponent.core.action.ViewActionRegistry.PathMapping
import org.slf4j.LoggerFactory

@Configuration
class ViewActionConfiguration(
val context: ApplicationContext,
Expand All @@ -23,8 +25,9 @@ class ViewActionConfiguration(
fun registerViewActionEndpoints() {
val viewComponentBeans = context.getBeansWithAnnotation(ViewComponent::class.java)

viewComponentBeans.forEach { (viewComponentName, viewComponentBean) ->
viewComponentBeans.forEach { (_, viewComponentBean) ->
val beanType = ClassUtils.getUserClass(viewComponentBean.javaClass)
val viewComponentName = beanType.simpleName
val viewComponentMethods = beanType.methods
processViewComponentBean(viewComponentMethods, viewComponentName, viewComponentBean)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tschuehly.spring.viewcomponent.core.action

import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.RequestMethod
import java.lang.reflect.Method
Expand All @@ -8,11 +9,14 @@ import java.lang.reflect.Method
class ViewActionRegistry {
private val viewActionMapping = mutableMapOf<String, PathMapping>()

private val logger = LoggerFactory.getLogger(ViewActionRegistry::class.java)

fun registerMapping(viewComponentName: String, mapping: PathMapping) {
val key = viewActionKey(viewComponentName, mapping.method.name)
if (viewActionMapping.containsKey(key)) {
throw ViewActionRegistryException("Cannot register duplicate path mapping")
}
logger.info("Registered endpoint ${mapping.path} to $viewComponentName::${mapping.method.name}")
viewActionMapping[key] = mapping
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package de.tschuehly.spring.viewcomponent.core.action
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class PostViewAction(
val path: String = ""
val path: String = ""
)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class GetViewAction(
val path: String = ""
val path: String = ""
)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class PutViewAction(
val path: String = ""
val path: String = ""
)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class PatchViewAction(
val path: String = ""
val path: String = ""
)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class DeleteViewAction(
val path: String = ""
val path: String = ""
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tschuehly.spring.viewcomponent.core.component

import de.tschuehly.spring.viewcomponent.core.IViewContext
import de.tschuehly.spring.viewcomponent.core.action.CapturingResponseWrapper
import de.tschuehly.spring.viewcomponent.core.toMap
import jakarta.servlet.http.HttpServletResponseWrapper
import org.springframework.core.MethodParameter
Expand All @@ -28,21 +27,6 @@ class ViewContextMethodReturnValueHandler : HandlerMethodReturnValueHandler {
} as IViewContext
mavContainer.view = viewContext.componentTemplate
mavContainer.addAllAttributes(viewContext.contextAttributes.toMap())
val response = webRequest.nativeResponse
if (response is HttpServletResponseWrapper) {
setResponseBean(response,viewContext)
}
}


private fun setResponseBean(wrapper: HttpServletResponseWrapper, viewContext: IViewContext) {
if (wrapper is CapturingResponseWrapper) {
wrapper.viewComponentBean = viewContext.componentBean
return
}
val response = wrapper.response
if(response is HttpServletResponseWrapper){
setResponseBean(response, viewContext)
}
}
}

This file was deleted.

Loading

0 comments on commit 3c7c57a

Please sign in to comment.