├── .gitignore ├── README.md ├── docs └── sources │ └── org │ └── zdevra │ └── guice │ └── mvc │ ├── concept-custom-view.png │ ├── concept-exceptions.png │ ├── concept-main.png │ ├── concept-view-resolver.png │ └── independent-data.png ├── examples ├── converters │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── lime │ │ │ └── examples │ │ │ └── converters │ │ │ ├── AppController.java │ │ │ ├── LimeServletContextListener.java │ │ │ ├── Person.java │ │ │ └── PersonConverterFactory.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ └── web.xml │ │ └── main.ftl ├── freemarker │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── lime │ │ │ └── examples │ │ │ └── freemarker │ │ │ ├── FreemarkerExampleController.java │ │ │ ├── FreemarkerExampleModule.java │ │ │ └── FreemarkerServletContextListener.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ └── web.xml │ │ ├── add.ftl │ │ ├── common.ftl │ │ └── main.ftl ├── interceptors │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── lime │ │ │ └── examples │ │ │ └── interceptors │ │ │ ├── InterceptorsExampleContextListener.java │ │ │ ├── LogInterceptor.java │ │ │ ├── PublicController.java │ │ │ ├── SecuredController.java │ │ │ └── SecurityInterceptor.java │ │ └── webapp │ │ └── WEB-INF │ │ ├── appengine-web.xml │ │ ├── views │ │ └── main.ftl │ │ └── web.xml ├── jsilver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── lime │ │ │ └── examples │ │ │ └── jsilver │ │ │ ├── JSilverExampleController.java │ │ │ ├── JSilverExampleModule.java │ │ │ └── JSilverServletContextListener.java │ │ └── webapp │ │ ├── WEB-INF │ │ ├── appengine-web.xml │ │ └── web.xml │ │ ├── add.jsilver │ │ └── main.jsilver ├── pom.xml └── velocity │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── org │ │ └── zdevra │ │ └── lime │ │ └── examples │ │ └── velocity │ │ ├── VelocityExampleController.java │ │ ├── VelocityExampleModule.java │ │ └── VelocityServletContextListener.java │ └── webapp │ ├── WEB-INF │ ├── appengine-web.xml │ └── web.xml │ ├── add.v │ └── main.v ├── extensions ├── freemarker │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── zdevra │ │ │ └── guice │ │ │ └── mvc │ │ │ ├── exceptions │ │ │ └── FreemarkerViewException.java │ │ │ └── freemarker │ │ │ ├── FreemarkerModule.java │ │ │ ├── FreemarkerScanner.java │ │ │ ├── FreemarkerViewPoint.java │ │ │ ├── annotations │ │ │ └── FreemarkerView.java │ │ │ └── package-info.java │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── guice │ │ │ └── mvc │ │ │ └── freemarker │ │ │ ├── FreemarkerTest.java │ │ │ └── Main.java │ │ └── resources │ │ └── test.ftl ├── jsilver │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── zdevra │ │ │ └── guice │ │ │ └── mvc │ │ │ ├── exceptions │ │ │ └── JSilverViewException.java │ │ │ └── jsilver │ │ │ ├── JSilverModule.java │ │ │ ├── JSilverScanner.java │ │ │ ├── JSilverViewPoint.java │ │ │ ├── ModelCollectionConverter.java │ │ │ ├── ModelConverter.java │ │ │ ├── ModelMapConverter.java │ │ │ ├── ModelObjectConverter.java │ │ │ ├── ModelService.java │ │ │ ├── ModelSilverConverter.java │ │ │ ├── ModelStringConverter.java │ │ │ ├── ServletContextResourceLoader.java │ │ │ ├── annotations │ │ │ └── JSilverView.java │ │ │ └── package-info.java │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── zdevra │ │ │ └── guice │ │ │ └── mvc │ │ │ └── jsilver │ │ │ ├── JSilverTest.java │ │ │ ├── Main.java │ │ │ └── ModelTest.java │ │ └── resources │ │ └── test.jsilver ├── pom.xml └── velocity │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── org │ │ └── zdevra │ │ └── guice │ │ └── mvc │ │ ├── exceptions │ │ └── VelocityViewException.java │ │ └── velocity │ │ ├── VelocityModule.java │ │ ├── VelocityScanner.java │ │ ├── VelocityViewPoint.java │ │ ├── annotations │ │ └── VelocityView.java │ │ └── package-info.java │ └── test │ ├── java │ └── org │ │ └── zdevra │ │ └── guice │ │ └── mvc │ │ └── velocity │ │ ├── Main.java │ │ └── TestVelocity.java │ └── resources │ └── test.velocity ├── lime ├── LICENCE ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── zdevra │ │ └── guice │ │ └── mvc │ │ ├── AbstractInterceptorHandler.java │ │ ├── ClassInvoker.java │ │ ├── ClassScanner.java │ │ ├── ControllerDefinition.java │ │ ├── ControllerModuleBuilder.java │ │ ├── ConversionService.java │ │ ├── DefaultExceptionHandler.java │ │ ├── DefaultViewResolver.java │ │ ├── DirectViewDefinition.java │ │ ├── ExceptionBind.java │ │ ├── ExceptionBindToClass.java │ │ ├── ExceptionBindToInstance.java │ │ ├── ExceptionHandler.java │ │ ├── ExceptionResolver.java │ │ ├── ExceptionResolverBuilder.java │ │ ├── GuiceExceptionResolver.java │ │ ├── HttpMethodType.java │ │ ├── InterceptorChain.java │ │ ├── InterceptorHandler.java │ │ ├── InterceptorService.java │ │ ├── InvokeData.java │ │ ├── MappingData.java │ │ ├── MethodInvoker.java │ │ ├── MethodInvokerDecorator.java │ │ ├── MethodInvokerFilter.java │ │ ├── MethodInvokerImpl.java │ │ ├── ModelAndView.java │ │ ├── ModelMap.java │ │ ├── MultibinderBuilder.java │ │ ├── MvcConverterModule.java │ │ ├── MvcDispatcherServlet.java │ │ ├── MvcModule.java │ │ ├── NamedViewBuilder.java │ │ ├── ServletDefinition.java │ │ ├── Utils.java │ │ ├── ViewExceptionHandler.java │ │ ├── ViewModule.java │ │ ├── ViewPoint.java │ │ ├── ViewResolver.java │ │ ├── ViewScanner.java │ │ ├── ViewScannerService.java │ │ ├── ViewServlet.java │ │ ├── annotations │ │ ├── BooleanConv.java │ │ ├── Controller.java │ │ ├── DELETE.java │ │ ├── DateConv.java │ │ ├── FactoryMethod.java │ │ ├── GET.java │ │ ├── HEAD.java │ │ ├── Model.java │ │ ├── POST.java │ │ ├── PUT.java │ │ ├── Path.java │ │ ├── Priority.java │ │ ├── RedirectView.java │ │ ├── RequestParameter.java │ │ ├── RequestScopedAttribute.java │ │ ├── SessionParameter.java │ │ ├── UriParameter.java │ │ └── View.java │ │ ├── converters │ │ ├── AbstractConverter.java │ │ ├── ArrayConverter.java │ │ ├── BooleanConverterFactory.java │ │ ├── DateConverterFactory.java │ │ ├── DoubleConverterFactory.java │ │ ├── FloatConverterFactory.java │ │ ├── IntegerConverterFactory.java │ │ ├── LongConverterFactory.java │ │ ├── NoConverterFactory.java │ │ ├── StringConverterFactory.java │ │ ├── TypeConverter.java │ │ └── package-info.java │ │ ├── exceptions │ │ ├── AutoConfException.java │ │ ├── IllegalConversionException.java │ │ ├── InvalidJspViewException.java │ │ ├── InvalidMethodParameterException.java │ │ ├── MethodInvokingException.java │ │ ├── MvcConfigurationException.java │ │ ├── MvcException.java │ │ ├── NoConverterException.java │ │ ├── NoMethodInvoked.java │ │ ├── NoViewException.java │ │ ├── NoViewForNameException.java │ │ ├── ObsoleteException.java │ │ ├── ScannerException.java │ │ ├── ViewException.java │ │ ├── ViewPointException.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── parameters │ │ ├── DefaultParamFactory.java │ │ ├── HttpPostParam.java │ │ ├── HttpSessionParam.java │ │ ├── InjectorParam.java │ │ ├── ModelParam.java │ │ ├── ParamMetadata.java │ │ ├── ParamProcessor.java │ │ ├── ParamProcessorFactory.java │ │ ├── ParamProcessorsService.java │ │ ├── RequestParam.java │ │ ├── RequestScopedAttributeParam.java │ │ ├── ResponseParam.java │ │ ├── SessionAttributeParam.java │ │ ├── UriParam.java │ │ └── package-info.java │ │ └── views │ │ ├── HttpRequestForForward.java │ │ ├── JspView.java │ │ ├── NamedView.java │ │ ├── NamedViewScanner.java │ │ ├── RedirectViewPoint.java │ │ ├── RedirectViewScanner.java │ │ └── package-info.java │ └── test │ └── java │ ├── Main.java │ └── org │ └── zdevra │ └── guice │ └── mvc │ ├── AbstractTest.java │ ├── ConversionServiceTest.java │ ├── GuiceExceptionResolverTest.java │ ├── HttpSessinonController.java │ ├── InjectorController.java │ ├── MethodInvokerTest.java │ ├── ModelTest.java │ ├── NamedViewTest.java │ ├── SimpleController.java │ ├── TestModule.java │ ├── TestRequest.java │ ├── TestResponse.java │ ├── TestServlet.java │ ├── TestView.java │ ├── WebTest.java │ ├── case1 │ ├── Case1Controller.java │ ├── Case1Module.java │ └── Case1Test.java │ ├── case10 │ ├── Case10ContextListener.java │ ├── Case10Controller.java │ ├── Case10Log.java │ ├── Case10Test.java │ ├── LogInterceptor.java │ ├── SecurityInterceptor.java │ ├── User.java │ └── webapp │ │ └── WEB-INF │ │ ├── views │ │ └── main.html.jsp │ │ └── web.xml │ ├── case11 │ ├── Case11ContextListener.java │ ├── Case11Controller.java │ ├── Case11Test.java │ └── webapp │ │ └── WEB-INF │ │ └── web.xml │ ├── case2 │ ├── Case2Controller.java │ ├── Case2ControllerImpl.java │ ├── Case2Module.java │ └── Case2Test.java │ ├── case3 │ ├── Case3Controller.java │ ├── Case3Module.java │ ├── Case3ModuleView.java │ └── Case3Test.java │ ├── case4 │ ├── AdvancedCustomException.java │ ├── AdvancedHandledException.java │ ├── AdvancedHandler.java │ ├── Case4Controller.java │ ├── Case4Main.java │ ├── Case4Module.java │ ├── Case4Test.java │ ├── CustomException.java │ ├── CustomExceptionHandler.java │ └── ExceptionForErrorPage.java │ ├── case5 │ ├── Case5Controller.java │ ├── Case5Module.java │ ├── Case5Test.java │ ├── TestViewScanner.java │ └── ToTestView.java │ ├── case6 │ ├── Case6ControllerCars.java │ ├── Case6ControllerPeople.java │ ├── Case6Module.java │ ├── Case6Servlet.java │ ├── Case6Test.java │ └── Case6View.java │ ├── case8 │ ├── Case8Controller.java │ ├── Case8Module.java │ ├── Case8Servlet.java │ ├── Case8Test.java │ ├── FirstPersonConverterFactory.java │ ├── Person.java │ └── SecondPersonConverterFactory.java │ ├── case9 │ ├── Case9ContextListener.java │ ├── Case9Controller.java │ ├── Case9Module.java │ ├── Case9Test.java │ └── webapp │ │ └── WEB-INF │ │ ├── view │ │ ├── form-get.html.jsp │ │ ├── form-post.html.jsp │ │ ├── form.html.jsp │ │ ├── form2.html.jsp │ │ └── success.html.jsp │ │ └── web.xml │ └── casePerformance │ ├── BlogArticlesController.java │ ├── BlogDao.java │ ├── BlogModule.java │ ├── IBlogArticlesController.java │ ├── PerfServlet.java │ ├── PerfTest.java │ ├── ViewAllArticles.java │ └── ViewArticle.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | bin/[^.]* 2 | lib/[^.]* 3 | target/[^.]* 4 | test-output/[^.]* 5 | docs/java-api/[^.]* 6 | out/[^.]* 7 | build.properties 8 | *.jar 9 | *.iml 10 | *.iws 11 | *.ipr 12 | .project 13 | .classpath 14 | .settings/[^.]* 15 | [^.]*.iml 16 | bin/.empty 17 | *.DS_Store 18 | *~ 19 | examples/velocity/target/[^.]* 20 | examples/jsilver/target/[^.]* 21 | examples/freemarker/target/[^.]* 22 | examples/converters/target/[^.]* 23 | examples/async/target/[^.]* 24 | examples/interceptors/target/[^.]* 25 | 26 | /target/ 27 | /examples/target/ 28 | /examples/converters/target/ 29 | /examples/freemarker/target/ 30 | /examples/interceptors/target/ 31 | /lime/target/ 32 | /extensions/velocity/target/ 33 | /extensions/jsilver/target/ 34 | /extensions/freemarker/target/ 35 | /examples/jsilver/target/ 36 | /examples/velocity/target/ 37 | /.idea/ -------------------------------------------------------------------------------- /docs/sources/org/zdevra/guice/mvc/concept-custom-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sn3d/lime-mvc/11062212480ebf7cffb2ee62b0a08ffc001933a8/docs/sources/org/zdevra/guice/mvc/concept-custom-view.png -------------------------------------------------------------------------------- /docs/sources/org/zdevra/guice/mvc/concept-exceptions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sn3d/lime-mvc/11062212480ebf7cffb2ee62b0a08ffc001933a8/docs/sources/org/zdevra/guice/mvc/concept-exceptions.png -------------------------------------------------------------------------------- /docs/sources/org/zdevra/guice/mvc/concept-main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sn3d/lime-mvc/11062212480ebf7cffb2ee62b0a08ffc001933a8/docs/sources/org/zdevra/guice/mvc/concept-main.png -------------------------------------------------------------------------------- /docs/sources/org/zdevra/guice/mvc/concept-view-resolver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sn3d/lime-mvc/11062212480ebf7cffb2ee62b0a08ffc001933a8/docs/sources/org/zdevra/guice/mvc/concept-view-resolver.png -------------------------------------------------------------------------------- /docs/sources/org/zdevra/guice/mvc/independent-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sn3d/lime-mvc/11062212480ebf7cffb2ee62b0a08ffc001933a8/docs/sources/org/zdevra/guice/mvc/independent-data.png -------------------------------------------------------------------------------- /examples/converters/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.zdevra.lime.examples 7 | examples 8 | 0.5-SNAPSHOT 9 | 10 | 11 | org.zdevra.lime.examples 12 | custom-converters 13 | 14 | war 15 | Lime custom converters example 16 | 17 | 18 | 19 | javax.servlet 20 | servlet-api 21 | 22 | 23 | javax.inject 24 | javax.inject 25 | 26 | 27 | aopalliance 28 | aopalliance 29 | 30 | 31 | org.zdevra.lime 32 | lime-freemarker 33 | 34 | 35 | 36 | 37 | custom-converters 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-compiler-plugin 42 | 2.0.2 43 | 44 | 1.6 45 | 1.6 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/converters/src/main/java/org/zdevra/lime/examples/converters/AppController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.converters; 2 | 3 | import org.zdevra.guice.mvc.annotations.Controller; 4 | import org.zdevra.guice.mvc.annotations.Model; 5 | import org.zdevra.guice.mvc.annotations.Path; 6 | import org.zdevra.guice.mvc.annotations.RequestParameter; 7 | import org.zdevra.guice.mvc.annotations.View; 8 | 9 | @Controller 10 | @View("main") 11 | public class AppController { 12 | 13 | @Path("/") 14 | @Model("msg") 15 | public String main() { 16 | return "none"; 17 | } 18 | 19 | @Path("/person/add") 20 | @Model("msg") 21 | public String addPerson(@RequestParameter("person") Person p) { 22 | return p.toString(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/converters/src/main/java/org/zdevra/lime/examples/converters/LimeServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.converters; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.servlet.GuiceServletContextListener; 6 | import org.zdevra.guice.mvc.MvcModule; 7 | import org.zdevra.guice.mvc.freemarker.FreemarkerModule; 8 | import org.zdevra.guice.mvc.freemarker.FreemarkerViewPoint; 9 | 10 | /** 11 | * Context listener prepare a Guice Injector and application's MVC module 12 | */ 13 | public class LimeServletContextListener extends GuiceServletContextListener { 14 | 15 | @Override 16 | protected Injector getInjector() { 17 | return Guice.createInjector(new MvcModule() { 18 | @Override 19 | protected void configureControllers() { 20 | 21 | //setup converter for Person 22 | registerConverter(new PersonConverterFactory()); 23 | 24 | //setup controller 25 | control("/*").withController(AppController.class); 26 | 27 | //setup views 28 | install(new FreemarkerModule(getServletContext())); 29 | bindViewName("main").toViewInstance(new FreemarkerViewPoint("main.ftl")); 30 | } 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/converters/src/main/java/org/zdevra/lime/examples/converters/Person.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.converters; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * User: sn3d 6 | * Date: 9/8/11 7 | * Time: 12:13 PM 8 | * To change this template use File | Settings | File Templates. 9 | */ 10 | public class Person { 11 | 12 | private final String name; 13 | private final String surname; 14 | private final String email; 15 | private final int age; 16 | 17 | public Person(String name, String surname, String email, int age) { 18 | this.name = name; 19 | this.surname = surname; 20 | this.email = email; 21 | this.age = age; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public String getSurname() { 29 | return surname; 30 | } 31 | 32 | public String getEmail() { 33 | return email; 34 | } 35 | 36 | public int getAge() { 37 | return age; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Person{" 43 | + "name='" + name + '\'' 44 | + ", surname='" + surname + '\'' 45 | + ", email='" + email + '\'' 46 | + ", age=" + age 47 | + '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/converters/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Converters example 4 | 1 5 | true 6 | 7 | -------------------------------------------------------------------------------- /examples/converters/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Custom Converter Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.lime.examples.converters.LimeServletContextListener 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/converters/src/main/webapp/main.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Message:

4 | 5 | ${msg} 6 | 7 |

Type a person data:

8 |
9 | Name:
10 | Surname:
11 | Email:
12 | Age:
13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/freemarker/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.zdevra.lime.examples 7 | examples 8 | 0.5-SNAPSHOT 9 | 10 | 11 | org.zdevra.lime.examples 12 | freemarker-example 13 | war 14 | Lime Freemarker example 15 | 16 | 17 | 18 | javax.servlet 19 | servlet-api 20 | 21 | 22 | javax.inject 23 | javax.inject 24 | 25 | 26 | aopalliance 27 | aopalliance 28 | 29 | 30 | org.zdevra.lime 31 | lime-freemarker 32 | 33 | 34 | 35 | 36 | freemarker-example 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 2.0.2 42 | 43 | 1.6 44 | 1.6 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/java/org/zdevra/lime/examples/freemarker/FreemarkerExampleController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.freemarker; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.zdevra.guice.mvc.annotations.Controller; 7 | import org.zdevra.guice.mvc.annotations.Path; 8 | import org.zdevra.guice.mvc.annotations.RequestParameter; 9 | import org.zdevra.guice.mvc.freemarker.annotations.FreemarkerView; 10 | 11 | import com.google.inject.servlet.SessionScoped; 12 | 13 | @Controller 14 | @SessionScoped 15 | @FreemarkerView("main.ftl") 16 | public class FreemarkerExampleController { 17 | 18 | public List names; 19 | 20 | /** 21 | * Class is session scoped, that mean the each 22 | * session has his own instance of class 23 | */ 24 | public FreemarkerExampleController() { 25 | this.names = new ArrayList(5); 26 | } 27 | 28 | /** 29 | * The method returns list of names 30 | */ 31 | @Path("/*") 32 | public List names() { 33 | return this.names; 34 | } 35 | 36 | /** 37 | * Add new name 38 | * @param name 39 | * @return 40 | */ 41 | @Path("/add") 42 | @FreemarkerView("add.ftl") 43 | public String addName(@RequestParameter("name") String name) { 44 | if (this.names.size() < 5) { 45 | this.names.add(name); 46 | return "true"; 47 | } 48 | return "false"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/java/org/zdevra/lime/examples/freemarker/FreemarkerExampleModule.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.freemarker; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | import org.zdevra.guice.mvc.freemarker.FreemarkerModule; 5 | 6 | public class FreemarkerExampleModule extends MvcModule { 7 | 8 | @Override 9 | protected void configureControllers() { 10 | install(new FreemarkerModule(getServletContext())); 11 | control("/*").withController(FreemarkerExampleController.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/java/org/zdevra/lime/examples/freemarker/FreemarkerServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.freemarker; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.servlet.GuiceServletContextListener; 6 | 7 | public class FreemarkerServletContextListener extends GuiceServletContextListener { 8 | 9 | @Override 10 | protected Injector getInjector() { 11 | return Guice.createInjector(new FreemarkerExampleModule()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Freemarker example 4 | 1 5 | true 6 | 7 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Freemarker Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.lime.examples.freemarker.FreemarkerServletContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/webapp/add.ftl: -------------------------------------------------------------------------------- 1 | <#import "common.ftl" as cmn> 2 | <@cmn.mainbody> 3 | 4 | <@cmn.shownames/> 5 | 6 |
7 | <#if addName == "true" > 8 |
Name has been added
9 | <#else> 10 |
Limit of names has been exhausted
11 | 12 | 13 | back 14 | 15 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/webapp/common.ftl: -------------------------------------------------------------------------------- 1 | <#macro shownames> 2 | <#list names as name> 3 |
Name: ${name}
4 | 5 | 6 | 7 | 8 | <#macro mainbody> 9 | 10 | 11 | <#nested> 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/freemarker/src/main/webapp/main.ftl: -------------------------------------------------------------------------------- 1 | <#import "common.ftl" as cmn> 2 | <@cmn.mainbody> 3 | 4 | <@cmn.shownames/> 5 | 6 |
7 | Add name
8 | Name: 9 |
10 | 11 | -------------------------------------------------------------------------------- /examples/interceptors/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.zdevra.lime.examples 7 | examples 8 | 0.5-SNAPSHOT 9 | 10 | 11 | org.zdevra.lime.examples 12 | async 13 | 14 | war 15 | Lime interceptors example 16 | http://code.google.com/p/lime-mvc/ 17 | 18 | 19 | 20 | javax.servlet 21 | servlet-api 22 | 23 | 24 | javax.inject 25 | javax.inject 26 | 27 | 28 | aopalliance 29 | aopalliance 30 | 31 | 32 | org.zdevra.lime 33 | lime-freemarker 34 | 35 | 36 | 37 | 38 | async 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-compiler-plugin 43 | 2.0.2 44 | 45 | 1.6 46 | 1.6 47 | true 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/java/org/zdevra/lime/examples/interceptors/InterceptorsExampleContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.interceptors; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | import org.zdevra.guice.mvc.freemarker.FreemarkerModule; 5 | 6 | import com.google.inject.Guice; 7 | import com.google.inject.Injector; 8 | import com.google.inject.servlet.GuiceServletContextListener; 9 | 10 | public class InterceptorsExampleContextListener extends GuiceServletContextListener { 11 | 12 | @Override 13 | protected Injector getInjector() { 14 | return Guice.createInjector( 15 | new MvcModule() { 16 | @Override 17 | protected void configureControllers() { 18 | install(new FreemarkerModule(getServletContext())); 19 | 20 | //register global log interceptor for all controllers 21 | registerGlobalInterceptor(LogInterceptor.class); 22 | 23 | control("/public/*") 24 | .withController(PublicController.class); 25 | 26 | //register security interceptor for concrete controller 27 | control("/secured/*") 28 | .withController(SecuredController.class) 29 | .interceptor(SecurityInterceptor.class); 30 | 31 | } 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/java/org/zdevra/lime/examples/interceptors/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.interceptors; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import org.zdevra.guice.mvc.InterceptorHandler; 10 | import org.zdevra.guice.mvc.ModelAndView; 11 | 12 | public class LogInterceptor implements InterceptorHandler { 13 | 14 | private static final Logger logger = Logger.getLogger(LogInterceptor.class.getName()); 15 | 16 | @Override 17 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response) { 18 | logger.log(Level.INFO, "processing " + request.getRequestURL().toString()); 19 | return true; 20 | } 21 | 22 | @Override 23 | public void postHandle(HttpServletRequest request, HttpServletResponse response, ModelAndView mav) { 24 | logger.log(Level.INFO, "model:" + mav.getModel()); 25 | } 26 | 27 | @Override 28 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Throwable e) { 29 | logger.log(Level.INFO, "request complete"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/java/org/zdevra/lime/examples/interceptors/PublicController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.interceptors; 2 | 3 | import org.zdevra.guice.mvc.annotations.Controller; 4 | import org.zdevra.guice.mvc.annotations.Model; 5 | import org.zdevra.guice.mvc.annotations.Path; 6 | import org.zdevra.guice.mvc.freemarker.annotations.FreemarkerView; 7 | 8 | @Controller 9 | public class PublicController { 10 | 11 | @Path("/info") 12 | @Model("msg") 13 | @FreemarkerView("/WEB-INF/views/main.ftl") 14 | public String info() { 15 | return "I am public controller."; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/java/org/zdevra/lime/examples/interceptors/SecuredController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.interceptors; 2 | 3 | import org.zdevra.guice.mvc.annotations.Controller; 4 | import org.zdevra.guice.mvc.annotations.Model; 5 | import org.zdevra.guice.mvc.annotations.Path; 6 | import org.zdevra.guice.mvc.annotations.RequestScopedAttribute; 7 | import org.zdevra.guice.mvc.annotations.View; 8 | import org.zdevra.guice.mvc.freemarker.annotations.FreemarkerView; 9 | 10 | @Controller 11 | public class SecuredController { 12 | 13 | @Path("/info") 14 | @Model("msg") 15 | @FreemarkerView("/WEB-INF/views/main.ftl") 16 | public String info(@RequestScopedAttribute("USER") String userName) { 17 | return "I am secured controller with " + userName + " user."; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/java/org/zdevra/lime/examples/interceptors/SecurityInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.interceptors; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.zdevra.guice.mvc.AbstractInterceptorHandler; 7 | 8 | public class SecurityInterceptor extends AbstractInterceptorHandler { 9 | 10 | @Override 11 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response) { 12 | String username = request.getParameter("username"); 13 | String password = request.getParameter("password"); 14 | 15 | if (("admin".equalsIgnoreCase(username)) 16 | && ("pass123".equalsIgnoreCase(password))) { 17 | request.setAttribute("USER", "admin"); 18 | return true; 19 | } 20 | 21 | response.setStatus(401); 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Interceptors example 4 | 1 5 | true 6 | 7 | -------------------------------------------------------------------------------- /examples/interceptors/src/main/webapp/WEB-INF/views/main.ftl: -------------------------------------------------------------------------------- 1 | Hello. ${msg} -------------------------------------------------------------------------------- /examples/interceptors/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Interceptors Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.lime.examples.interceptors.InterceptorsExampleContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/jsilver/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.zdevra.lime.examples 7 | examples 8 | 0.5-SNAPSHOT 9 | 10 | 11 | org.zdevra.lime.examples 12 | jsilver-example 13 | war 14 | 15 | Lime JSilver example 16 | http://code.google.com/p/lime-mvc/ 17 | 18 | 19 | 20 | javax.servlet 21 | servlet-api 22 | 23 | 24 | javax.inject 25 | javax.inject 26 | 27 | 28 | aopalliance 29 | aopalliance 30 | 31 | 32 | org.zdevra.lime 33 | lime-jsilver 34 | 35 | 36 | 37 | 38 | jsilver-example 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-compiler-plugin 43 | 2.0.2 44 | 45 | 1.6 46 | 1.6 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/java/org/zdevra/lime/examples/jsilver/JSilverExampleController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.jsilver; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.zdevra.guice.mvc.annotations.Controller; 7 | import org.zdevra.guice.mvc.annotations.Path; 8 | import org.zdevra.guice.mvc.annotations.RequestParameter; 9 | import org.zdevra.guice.mvc.jsilver.annotations.JSilverView; 10 | 11 | import com.google.inject.servlet.SessionScoped; 12 | 13 | @Controller 14 | @SessionScoped 15 | @JSilverView("main.jsilver") 16 | public class JSilverExampleController { 17 | 18 | public List names; 19 | 20 | /** 21 | * Class is session scoped, that mean the each 22 | * session has his own instance of class 23 | */ 24 | public JSilverExampleController() { 25 | this.names = new ArrayList(5); 26 | } 27 | 28 | /** 29 | * The method returns list of names 30 | */ 31 | @Path("/*") 32 | public List names() { 33 | return this.names; 34 | } 35 | 36 | /** 37 | * Add new name 38 | * @param name 39 | * @return 40 | */ 41 | @Path("/add") 42 | @JSilverView("add.jsilver") 43 | public boolean addName(@RequestParameter("name") String name) { 44 | if (this.names.size() < 5) { 45 | this.names.add(name); 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/java/org/zdevra/lime/examples/jsilver/JSilverExampleModule.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.jsilver; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | import org.zdevra.guice.mvc.jsilver.JSilverModule; 5 | 6 | public class JSilverExampleModule extends MvcModule { 7 | 8 | @Override 9 | protected void configureControllers() { 10 | install(new JSilverModule(getServletContext())); 11 | control("/*").withController(JSilverExampleController.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/java/org/zdevra/lime/examples/jsilver/JSilverServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.jsilver; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.servlet.GuiceServletContextListener; 6 | 7 | public class JSilverServletContextListener extends GuiceServletContextListener { 8 | 9 | @Override 10 | protected Injector getInjector() { 11 | return Guice.createInjector(new JSilverExampleModule()); 12 | } 13 | } -------------------------------------------------------------------------------- /examples/jsilver/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | JSilver example 4 | 1 5 | true 6 | 7 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | JSilver Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.lime.examples.jsilver.JSilverServletContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/webapp/add.jsilver: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
Name has been added
5 | 6 |
Limit of names has been exhausted
7 | 8 | back 9 | 10 | -------------------------------------------------------------------------------- /examples/jsilver/src/main/webapp/main.jsilver: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
Name:
6 | 7 | 8 |
9 | Add name
10 | Name: 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | org.zdevra.lime 7 | lime-parent 8 | 0.5-SNAPSHOT 9 | 10 | 11 | org.zdevra.lime.examples 12 | examples 13 | pom 14 | 15 | Lime examples parent 16 | 17 | 18 | 19 | UTF-8 20 | 21 | 22 | 23 | converters 24 | freemarker 25 | interceptors 26 | jsilver 27 | velocity 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/velocity/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | 7 | org.zdevra.lime.examples 8 | examples 9 | 0.5-SNAPSHOT 10 | 11 | 12 | org.zdevra.lime.examples 13 | velocity-example 14 | 15 | 16 | war 17 | Lime Velocity example 18 | http://code.google.com/p/lime-mvc/ 19 | 20 | 21 | 22 | javax.servlet 23 | servlet-api 24 | 25 | 26 | javax.inject 27 | javax.inject 28 | 29 | 30 | aopalliance 31 | aopalliance 32 | 33 | 34 | org.zdevra.lime 35 | lime-velocity 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-compiler-plugin 44 | 2.0.2 45 | 46 | 1.6 47 | 1.6 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/velocity/src/main/java/org/zdevra/lime/examples/velocity/VelocityExampleController.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.velocity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.zdevra.guice.mvc.annotations.Controller; 7 | import org.zdevra.guice.mvc.annotations.Path; 8 | import org.zdevra.guice.mvc.annotations.RequestParameter; 9 | import org.zdevra.guice.mvc.velocity.annotations.VelocityView; 10 | 11 | import com.google.inject.servlet.SessionScoped; 12 | 13 | @Controller 14 | @SessionScoped 15 | @VelocityView("main.v") 16 | public class VelocityExampleController { 17 | 18 | public List names; 19 | 20 | /** 21 | * Class is session scoped, that mean the each 22 | * session has his own instance of class 23 | */ 24 | public VelocityExampleController() { 25 | this.names = new ArrayList(5); 26 | } 27 | 28 | /** 29 | * The method returns list of names 30 | */ 31 | @Path("/*") 32 | public List names() { 33 | return this.names; 34 | } 35 | 36 | /** 37 | * Add new name 38 | * @param name 39 | * @return 40 | */ 41 | @Path("/add") 42 | @VelocityView("add.v") 43 | public boolean addName(@RequestParameter("name") String name) { 44 | if (this.names.size() < 5) { 45 | this.names.add(name); 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/velocity/src/main/java/org/zdevra/lime/examples/velocity/VelocityExampleModule.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.velocity; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | import org.zdevra.guice.mvc.velocity.VelocityModule; 5 | 6 | public class VelocityExampleModule extends MvcModule { 7 | 8 | @Override 9 | protected void configureControllers() { 10 | install(new VelocityModule(getServletContext())); 11 | control("/*").withController(VelocityExampleController.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/velocity/src/main/java/org/zdevra/lime/examples/velocity/VelocityServletContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.lime.examples.velocity; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.servlet.GuiceServletContextListener; 6 | 7 | public class VelocityServletContextListener extends GuiceServletContextListener { 8 | 9 | @Override 10 | protected Injector getInjector() { 11 | return Guice.createInjector(new VelocityExampleModule()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/velocity/src/main/webapp/WEB-INF/appengine-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Velocity example 4 | 1 5 | true 6 | 7 | -------------------------------------------------------------------------------- /examples/velocity/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Velocity Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.lime.examples.velocity.VelocityServletContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/velocity/src/main/webapp/add.v: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #if ($addName) 5 |
Name has been added
6 | #else 7 |
Limit of names has been exhausted
8 | #end 9 | 10 | back 11 | 12 | -------------------------------------------------------------------------------- /examples/velocity/src/main/webapp/main.v: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #foreach( $name in $names ) 5 |
Name: $name
6 | #end 7 |
8 | 9 |
10 | Add name
11 | Name: 12 |
13 | 14 | -------------------------------------------------------------------------------- /extensions/freemarker/src/main/java/org/zdevra/guice/mvc/exceptions/FreemarkerViewException.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.exceptions; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.zdevra.guice.mvc.exceptions.ViewException; 6 | 7 | /** 8 | * The exception is occured when something wrong happens 9 | * in the Freemarker view 10 | */ 11 | public class FreemarkerViewException extends ViewException { 12 | 13 | public FreemarkerViewException(String viewId, HttpServletRequest request, 14 | Throwable e) { 15 | super(viewId, request, e); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /extensions/freemarker/src/main/java/org/zdevra/guice/mvc/freemarker/annotations/FreemarkerView.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.freemarker.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * This annotation is used in controller and 26 | * tells to Lime MVC we want to render produced 27 | * data via freemarker's template. 28 | *
29 | * example: 30 | *
31 |  * {@literal @}Controller
32 |  * public class MyController {
33 |  *    
34 |  *    {@literal @}Path("/helloworld")
35 |  *    {@literal @}Model("msg")
36 |  *    {@literal @}FreemarkerView("view.ftl")
37 |  *    public String helloWorld() {
38 |  *       ...
39 |  *    }
40 |  * }
41 |  * 
42 | */ 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Target({ElementType.METHOD, ElementType.TYPE}) 45 | public @interface FreemarkerView { 46 | 47 | public String value(); 48 | } 49 | -------------------------------------------------------------------------------- /extensions/freemarker/src/test/java/org/zdevra/guice/mvc/freemarker/FreemarkerTest.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.freemarker; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import junit.framework.Assert; 6 | 7 | import org.testng.annotations.Test; 8 | import org.zdevra.guice.mvc.TestModule; 9 | import org.zdevra.guice.mvc.TestRequest; 10 | import org.zdevra.guice.mvc.TestResponse; 11 | import org.zdevra.guice.mvc.ViewModule; 12 | import org.zdevra.guice.mvc.ViewResolver; 13 | import org.zdevra.guice.mvc.views.NamedView; 14 | 15 | import com.google.inject.Guice; 16 | import com.google.inject.Injector; 17 | 18 | class FreemarkerTestModule extends TestModule { 19 | 20 | @Override 21 | protected void configure() { 22 | super.configure(); 23 | 24 | install(new FreemarkerModule()); 25 | install(new ViewModule() { 26 | @Override 27 | protected void configureViews() { 28 | bindViewName("testview").toViewInstance(new FreemarkerViewPoint("test.ftl")); 29 | } 30 | }); 31 | } 32 | } 33 | 34 | @Test 35 | public class FreemarkerTest { 36 | 37 | @Test 38 | public void testFreemarkerBasic() { 39 | Injector g = Guice.createInjector(new FreemarkerTestModule()); 40 | 41 | //prepare req & resp and render the view 42 | HttpServletRequest req = 43 | TestRequest.builder() 44 | .setAttribute("attr1", "val1") 45 | .setAttribute("attr2", "val2") 46 | .build(); 47 | 48 | TestResponse resp = new TestResponse(); 49 | 50 | //execute view resolving&rendering 51 | ViewResolver vr = g.getInstance(ViewResolver.class); 52 | vr.resolve(NamedView.create("testview"), null, null, req, resp); 53 | String output = resp.getOutputAsStr(); 54 | 55 | //evaluate the result 56 | System.out.println(output); 57 | Assert.assertEquals("Test template val1 and val2", output); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /extensions/freemarker/src/test/java/org/zdevra/guice/mvc/freemarker/Main.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.freemarker; 2 | 3 | public class Main { 4 | 5 | /** 6 | * @param args 7 | */ 8 | public static void main(String[] args) { 9 | try { 10 | FreemarkerTest t = new FreemarkerTest(); 11 | t.testFreemarkerBasic(); 12 | } catch (Exception e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /extensions/freemarker/src/test/resources/test.ftl: -------------------------------------------------------------------------------- 1 | Test template ${attr1} and ${attr2} -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/exceptions/JSilverViewException.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.exceptions; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * Caught when something wrong happens in 7 | * JSilver view. 8 | */ 9 | public class JSilverViewException extends ViewException { 10 | 11 | public JSilverViewException(String viewId, HttpServletRequest request, Throwable e) { 12 | super(viewId, request, e); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ModelCollectionConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import java.util.Collection; 20 | import java.util.Iterator; 21 | import java.util.List; 22 | 23 | import com.google.clearsilver.jsilver.data.Data; 24 | import com.google.inject.Singleton; 25 | 26 | /** 27 | * The class is responsible for converting collections 28 | * to JSilver data 29 | */ 30 | @Singleton 31 | class ModelCollectionConverter implements ModelConverter { 32 | 33 | // ------------------------------------------------------------------------ 34 | @Override 35 | public boolean convert(String name, Object obj, Data data, ModelService convetorService) { 36 | 37 | if (!List.class.isInstance(obj)) { 38 | return false; 39 | } 40 | 41 | Data collectionData = data.createChild(name); 42 | Collection collection = (Collection) obj; 43 | Iterator iterator = collection.iterator(); 44 | 45 | int pos = 0; 46 | while (iterator.hasNext()) { 47 | Object item = iterator.next(); 48 | convetorService.convert(Integer.toString(pos), item, collectionData); 49 | pos++; 50 | } 51 | 52 | return true; 53 | } 54 | // ------------------------------------------------------------------------ 55 | } 56 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ModelConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import com.google.clearsilver.jsilver.data.Data; 20 | 21 | /** 22 | * You will implement this interface for transformations any data 23 | * to the JSilver data. 24 | * 25 | * All objects are transformed to JSilver Data structure via 26 | * Model Service. For your custom objects in the Lime Model use the 27 | * {@link ModelObjectConverter}. 28 | * 29 | * @see ModelObjectConverter 30 | * @see JSilverModule 31 | */ 32 | public interface ModelConverter { 33 | 34 | public boolean convert(String name, Object obj, Data data, ModelService service); 35 | } 36 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ModelMapConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import java.util.Map; 20 | 21 | import com.google.clearsilver.jsilver.data.Data; 22 | import com.google.inject.Singleton; 23 | 24 | /** 25 | * The class provide transformation from Map to JSilver data 26 | */ 27 | @Singleton 28 | class ModelMapConverter implements ModelConverter { 29 | 30 | @Override 31 | public boolean convert(String name, Object obj, Data data, ModelService convertService) { 32 | if (!Map.class.isInstance(obj)) { 33 | return false; 34 | } 35 | 36 | Data mapData = data.createChild(name); 37 | Map map = (Map) obj; 38 | for (Map.Entry e : map.entrySet()) { 39 | String key = e.getKey().toString(); 40 | Object val = e.getValue(); 41 | convertService.convert(key, val, mapData); 42 | } 43 | 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ModelSilverConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import com.google.clearsilver.jsilver.data.Data; 20 | 21 | /** 22 | * This class just take the JSilver data and 23 | * add put the data as symlink to parent. 24 | */ 25 | class ModelSilverConverter implements ModelConverter { 26 | 27 | @Override 28 | public boolean convert(String name, Object obj, Data data, ModelService convertService) { 29 | if (Data.class.isInstance(obj)) { 30 | data.setSymlink(name, (Data) obj); 31 | return true; 32 | } 33 | return false; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ModelStringConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import com.google.clearsilver.jsilver.data.Data; 20 | 21 | /** 22 | * This is default transformations class which is used, if 23 | * there is no converter class for object. 24 | */ 25 | class ModelStringConverter implements ModelConverter { 26 | 27 | @Override 28 | public boolean convert(String name, Object obj, Data data, ModelService service) { 29 | if (obj == null) { 30 | data.setValue(name, "null"); 31 | } 32 | data.setValue(name, obj.toString()); 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/ServletContextResourceLoader.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver; 18 | 19 | import javax.servlet.ServletContext; 20 | 21 | import com.google.clearsilver.jsilver.resourceloader.FileSystemResourceLoader; 22 | 23 | /** 24 | * The class provide loading of jsilver template files 25 | * from web app. 26 | */ 27 | class ServletContextResourceLoader extends FileSystemResourceLoader { 28 | 29 | public ServletContextResourceLoader(ServletContext context) { 30 | super(context.getRealPath("/")); 31 | } 32 | 33 | public ServletContextResourceLoader(ServletContext context, String webappDir) { 34 | super(context.getRealPath(webappDir)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /extensions/jsilver/src/main/java/org/zdevra/guice/mvc/jsilver/annotations/JSilverView.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.jsilver.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * This annotation is used in controller or in 26 | * method aand tells to Lime MVC we want to render 27 | * produced data via JSilver's template. 28 | *
29 | * example: 30 | *
31 |  * {@literal @}Controller
32 |  * public class MyController {
33 |  *    
34 |  *    {@literal @}Path("/helloworld")
35 |  *    {@literal @}Model("msg")
36 |  *    {@literal @}JSilverView("view.jsilver")
37 |  *    public String helloWorld() {
38 |  *       ...
39 |  *    }
40 |  * }
41 | 
42 |  */
43 | @Retention(RetentionPolicy.RUNTIME)
44 | @Target({ElementType.METHOD, ElementType.TYPE})
45 | public @interface JSilverView {
46 | 
47 |     public String value();
48 | }
49 | 


--------------------------------------------------------------------------------
/extensions/jsilver/src/test/java/org/zdevra/guice/mvc/jsilver/Main.java:
--------------------------------------------------------------------------------
 1 | package org.zdevra.guice.mvc.jsilver;
 2 | 
 3 | public class Main {
 4 | 
 5 |     /**
 6 |      * @param args
 7 |      */
 8 |     public static void main(String[] args) {
 9 |         try {
10 |             JSilverTest t = new JSilverTest();
11 |             t.testJSilverView();
12 |         } catch (Exception e) {
13 |             e.printStackTrace();
14 |         }
15 | 
16 |     }
17 | }
18 | 


--------------------------------------------------------------------------------
/extensions/jsilver/src/test/resources/test.jsilver:
--------------------------------------------------------------------------------
1 | Test template  and 


--------------------------------------------------------------------------------
/extensions/pom.xml:
--------------------------------------------------------------------------------
 1 | 
 3 |     4.0.0
 4 |     
 5 |     
 6 |         org.zdevra.lime
 7 |         lime-parent
 8 |         0.5-SNAPSHOT
 9 |     
10 |     
11 |     org.zdevra.lime
12 |     extensions-parent
13 |     pom
14 | 
15 |     Lime extensions parent
16 | 
17 |     
18 |         UTF-8
19 |     
20 |     
21 |     
22 |         freemarker
23 |         jsilver
24 |         velocity
25 |     
26 |     
27 | 
28 | 


--------------------------------------------------------------------------------
/extensions/velocity/src/main/java/org/zdevra/guice/mvc/exceptions/VelocityViewException.java:
--------------------------------------------------------------------------------
 1 | package org.zdevra.guice.mvc.exceptions;
 2 | 
 3 | import javax.servlet.http.HttpServletRequest;
 4 | 
 5 | import org.zdevra.guice.mvc.exceptions.ViewException;
 6 | 
 7 | /**
 8 |  * Caught when something wrong happens in 
 9 |  * Velocity view.
10 |  */
11 | public class VelocityViewException extends ViewException {
12 | 
13 |     public VelocityViewException(String viewId, HttpServletRequest request, Throwable e) {
14 |         super(viewId, request, e);
15 |     }
16 | }
17 | 


--------------------------------------------------------------------------------
/extensions/velocity/src/main/java/org/zdevra/guice/mvc/velocity/annotations/VelocityView.java:
--------------------------------------------------------------------------------
 1 | /*****************************************************************************
 2 |  * Copyright 2011 Zdenko Vrabel
 3 |  *
 4 |  * Licensed under the Apache License, Version 2.0 (the "License");
 5 |  * you may not use this file except in compliance with the License.
 6 |  * You may obtain a copy of the License at
 7 |  *
 8 |  *     http://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  * Unless required by applicable law or agreed to in writing, software
11 |  * distributed under the License is distributed on an "AS IS" BASIS,
12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  * See the License for the specific language governing permissions and
14 |  * limitations under the License.
15 |  * 
16 |  *****************************************************************************/
17 | package org.zdevra.guice.mvc.velocity.annotations;
18 | 
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 | 
24 | /**
25 |  * This annotation is used in controller and is
26 |  * telling to Lime MVC that we want to render a 
27 |  * produced data via Velocity's template.
28 |  * 
29 | * example: 30 | *
31 |  * {@literal @}Controller
32 |  * public class MyController {
33 |  *    
34 |  *    {@literal @}Path("/helloworld")
35 |  *    {@literal @}VelocityView("view.velocity")
36 |  *    public String helloWorld() {
37 |  *       ...
38 |  *    }
39 |  * }
40 |  * 
41 | */ 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Target({ElementType.METHOD, ElementType.TYPE}) 44 | public @interface VelocityView { 45 | 46 | public String value(); 47 | } 48 | -------------------------------------------------------------------------------- /extensions/velocity/src/test/java/org/zdevra/guice/mvc/velocity/Main.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.velocity; 2 | 3 | public class Main { 4 | 5 | /** 6 | * @param args 7 | */ 8 | public static void main(String[] args) { 9 | try { 10 | TestVelocity t = new TestVelocity(); 11 | t.testView2(); 12 | } catch (Exception e) { 13 | e.printStackTrace(); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /extensions/velocity/src/test/resources/test.velocity: -------------------------------------------------------------------------------- 1 | Test template $attr1 and $attr2 -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/DirectViewDefinition.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import java.util.logging.Logger; 20 | 21 | import javax.servlet.http.HttpServlet; 22 | 23 | import com.google.inject.Binder; 24 | 25 | /** 26 | * The class represent definition of direct view in module's building process 27 | * and creates the {@link ViewServlet}. 28 | * 29 | * This class is mainly used by {@link MvcModule} 30 | */ 31 | class DirectViewDefinition extends ServletDefinition { 32 | 33 | private static final Logger logger = Logger.getLogger(DirectViewDefinition.class.getName()); 34 | private final ViewPoint view; 35 | 36 | 37 | /** 38 | * Constructor 39 | */ 40 | public DirectViewDefinition(String urlPattern, ViewPoint view) { 41 | super(urlPattern); 42 | this.view = view; 43 | } 44 | 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | public HttpServlet createServlet(Binder binder) { 51 | logger.info("for path '" + getUrlPattern() + "' should be registered follwing direct view " + this.view.toString()); 52 | binder.requestInjection(view); 53 | return new ViewServlet(view); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/ExceptionBindToClass.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import com.google.inject.Injector; 20 | 21 | /** 22 | * This binding class bind an exception to handler's class. 23 | * A handler lifecycle is under Guice's control. 24 | * 25 | * @see ExceptionHandler 26 | * @see ExceptionBind 27 | * @see GuiceExceptionResolver 28 | */ 29 | class ExceptionBindToClass extends ExceptionBind { 30 | 31 | /** holds {@link ExceptionHandler} implementation which is responsible for exception handling */ 32 | private final Class handlerClass; 33 | 34 | /** 35 | * Constructor 36 | * 37 | * @param handlerClass 38 | * @param exceptionClass 39 | * @param order 40 | */ 41 | public ExceptionBindToClass(Class handlerClass, Class exceptionClass, int order) { 42 | super(exceptionClass, order); 43 | this.handlerClass = handlerClass; 44 | } 45 | 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public ExceptionHandler getHandler(Injector injector) { 52 | return injector.getInstance(handlerClass); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/ExceptionBindToInstance.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import com.google.inject.Injector; 20 | 21 | /** 22 | * This binding class bind an exception to concrete instance 23 | * of the {@link ExceptionHandler}. 24 | * 25 | * @see ExceptionHandler 26 | * @see ExceptionBind 27 | * @see GuiceExceptionResolver 28 | */ 29 | public class ExceptionBindToInstance extends ExceptionBind { 30 | 31 | /** holds reference to exception handler */ 32 | private final ExceptionHandler handler; 33 | 34 | 35 | /** 36 | * Constructor 37 | * @param handler 38 | * @param exceptionClass 39 | * @param order 40 | */ 41 | public ExceptionBindToInstance(ExceptionHandler handler, Class exceptionClass, int order) { 42 | super(exceptionClass, order); 43 | this.handler = handler; 44 | } 45 | 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public ExceptionHandler getHandler(Injector injetor) { 52 | return handler; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/HttpMethodType.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | /** 20 | * Enumeration of the HTTP Methods 21 | */ 22 | public enum HttpMethodType { 23 | 24 | ALL, 25 | GET, 26 | POST, 27 | PUT, 28 | HEAD, 29 | DELETE 30 | } 31 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/InterceptorService.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.Set; 22 | 23 | import com.google.inject.Inject; 24 | 25 | /** 26 | * The service exists as a singleton instance inside Guice. The interceptor 27 | * service gets the chain of the interceptor handlers for concrete method 28 | * invoker. Also this service carries all global interceptors. 29 | */ 30 | public class InterceptorService { 31 | 32 | private Collection globalHandlers; 33 | 34 | 35 | /** 36 | * Constructor 37 | * @param scanners 38 | */ 39 | @Inject 40 | public InterceptorService(Set globalHandlers) { 41 | this.globalHandlers = Collections.unmodifiableCollection(globalHandlers); 42 | } 43 | 44 | 45 | public InterceptorChain getGlobalInterceptorChain() { 46 | return new InterceptorChain(globalHandlers); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/MappingData.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | import com.google.inject.Injector; 22 | 23 | /** 24 | * Simple POJO holds data for invocation like what controller, method 25 | * should be invoked etc. 26 | */ 27 | class MappingData { 28 | 29 | public HttpMethodType httpMethodType; 30 | public String path; 31 | public String resultName; 32 | public Injector injector; 33 | public Class controllerClass; 34 | public Method method; 35 | 36 | /** 37 | * Constructor 38 | */ 39 | public MappingData(Class controllerClass, Method method, HttpMethodType httpMethodType, String path, String resultName, Injector injector) { 40 | this.controllerClass = controllerClass; 41 | this.method = method; 42 | this.path = path; 43 | this.resultName = resultName; 44 | this.httpMethodType = httpMethodType; 45 | this.injector = injector; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/MethodInvokerDecorator.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | /** 20 | * Method invoker's basic decorator. All decorators should extends 21 | * this abstract class. 22 | * 23 | * @author sn3d 24 | */ 25 | abstract class MethodInvokerDecorator implements MethodInvoker { 26 | 27 | /** next method invoker */ 28 | protected final MethodInvoker decoratedInvoker; 29 | 30 | 31 | /** 32 | * Constructor 33 | * @param decoratedInvoker 34 | */ 35 | protected MethodInvokerDecorator(MethodInvoker decoratedInvoker) { 36 | this.decoratedInvoker = decoratedInvoker; 37 | } 38 | 39 | @Override 40 | public final int compareTo(MethodInvoker o) { 41 | return decoratedInvoker.compareTo(o); 42 | } 43 | 44 | @Override 45 | public int getPriority() { 46 | return decoratedInvoker.getPriority(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/MultibinderBuilder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import com.google.inject.Binder; 20 | import com.google.inject.multibindings.Multibinder; 21 | 22 | class MultibinderBuilder { 23 | 24 | // ------------------------------------------------------------------------ 25 | protected final Binder binder; 26 | protected final Multibinder multibinder; 27 | 28 | // ------------------------------------------------------------------------ 29 | /** 30 | * Constructor 31 | */ 32 | public MultibinderBuilder(Binder binder, Class clazz) { 33 | this.binder = binder; 34 | this.multibinder = Multibinder.newSetBinder(binder, clazz); 35 | } 36 | 37 | public void registerClass(Class clazz) { 38 | multibinder.addBinding().to(clazz).asEagerSingleton(); 39 | } 40 | 41 | public void registerInstance(T instance) { 42 | binder.requestInjection(instance); 43 | multibinder.addBinding().toInstance(instance); 44 | } 45 | // ------------------------------------------------------------------------ 46 | } 47 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/ServletDefinition.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import javax.servlet.http.HttpServlet; 20 | 21 | import com.google.inject.Binder; 22 | 23 | /** 24 | * Class is representing data-structure used internally by Lime and 25 | * compose the all necessary data for servlet. 26 | */ 27 | abstract class ServletDefinition { 28 | 29 | private final String urlPattern; 30 | 31 | public abstract HttpServlet createServlet(Binder binder); 32 | 33 | public ServletDefinition(String urlPattern) { 34 | this.urlPattern = urlPattern; 35 | } 36 | 37 | public final String getUrlPattern() { 38 | return urlPattern; 39 | } 40 | } -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/ViewPoint.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import javax.servlet.http.HttpServlet; 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.zdevra.guice.mvc.views.NamedView; 24 | 25 | /** 26 | * You will implement this interface if you want your own view rendering. 27 | */ 28 | public interface ViewPoint { 29 | 30 | public final static ViewPoint NULL_VIEW = NamedView.create("NULL"); 31 | 32 | public void render(ModelMap model, HttpServlet servlet, HttpServletRequest request, HttpServletResponse response); 33 | } 34 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/ViewScanner.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import java.lang.annotation.Annotation; 20 | 21 | /** 22 | * You will implement this interface if you want to add 23 | * your custom annotation scanner for your custom view. 24 | * 25 | * @see ViewScannerService 26 | */ 27 | public interface ViewScanner { 28 | 29 | /** 30 | * Here you will implement looking for your annotation. 31 | * If your annotation is not presents, then you will return 32 | * View.NULL_VIEW. 33 | * 34 | * @param annotations - annotations of the controller or controller's method 35 | * 36 | * @return instance of view for your annotation or View.NULL. Avoid to 37 | * null value. 38 | * 39 | * @throws Exception 40 | */ 41 | public ViewPoint scan(Annotation[] annotations); 42 | } 43 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/BooleanConv.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * The annontation tell to converter how to convert a string to boolean. 27 | * 28 | * Let's assume that we don't want convert regular 'true' 'false' strings, but 29 | * we want convert Y like true a N like false: 30 | * 31 | *
32 |  * {@literal @}Controller
33 |  * public class MyController {
34 |  * 
35 |  *    {@literal @}Path("/method")
36 |  *    public void doSomething( {@literal @}RequestParameter("bool-param") {@literal @}BooleanConv(trueVal="Y", falseVal="N") boolean param) 
37 |  *    {
38 |  *    	
39 |  *    }
40 |  * }
41 |  * 
42 | * 43 | * 44 | * @see BooleanConverter 45 | */ 46 | @Retention(RUNTIME) 47 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 48 | public @interface BooleanConv { 49 | 50 | public String trueVal() default "true"; 51 | 52 | public String falseVal() default "false"; 53 | } 54 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/Controller.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | 22 | /** 23 | * All classes annotated by this annotation are regular MVC conctrolers 24 | * and can be handled by a MVC Dispatcher. 25 | * Also this annotation tells to the LIME which attributes stored in the 26 | * model should be stored in the session as well. 27 | *

28 | * 29 | * Example of the controller with 2 attributes, they will be 30 | * stored in the session. 31 | *

32 | * 33 | *

34 |  * {@literal @}Controller(sessionAttributes={"username", "country"})
35 |  * class MyController() {
36 |  *     ...
37 |  *     {@literal @}Path("/home")
38 |  *     public ModelMap doSomething() {
39 |  *     	   ...
40 |  *         ModelMap m = new ModelMap();
41 |  *         m.addObject("username", username);
42 |  *         m.addObject("country",  country);
43 |  *         return m;
44 |  *     }
45 |  * }
46 |  * 
47 | */ 48 | @Retention(RetentionPolicy.RUNTIME) 49 | public @interface Controller { 50 | 51 | public String[] sessionAttributes() default {}; 52 | 53 | public String view() default ""; 54 | 55 | public String path() default ""; 56 | } 57 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/DELETE.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that the annotated method will 26 | * be invoked only for HTTP DELETE requests. 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target({ElementType.METHOD}) 30 | public @interface DELETE { 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/DateConv.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | import org.zdevra.guice.mvc.converters.DateConverterFactory; 26 | 27 | /** 28 | * The anontation tells to the converter how to convert a string value to the date. 29 | * See the {@link DateConverterFactory} class if you are interesting how to use this annotation. 30 | * 31 | * @see DateConverterFactory 32 | */ 33 | @Retention(RUNTIME) 34 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 35 | public @interface DateConv { 36 | 37 | public String value() default "YYYYMMDD"; 38 | 39 | public String defaultValue() default ""; 40 | } 41 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/FactoryMethod.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * The annotation mark a method, that method is factory. This method will be called 27 | * by Conversion service and creates a object from a input string value. 28 | */ 29 | @Retention(RUNTIME) 30 | @Target({ElementType.METHOD}) 31 | public @interface FactoryMethod { 32 | } 33 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/GET.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that the annotated method will 26 | * be invoked only for HTTP GET requests. 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target({ElementType.METHOD}) 30 | public @interface GET { 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/HEAD.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that the annotated method will 26 | * be invoked only for HTTP HEAD requests. 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target({ElementType.METHOD}) 30 | public @interface HEAD { 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/POST.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that the annotated method will 26 | * be invoked only for HTTP POST requests. 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target({ElementType.METHOD}) 30 | public @interface POST { 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/PUT.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that the annotated method will 26 | * be invoked only for HTTP PUS requests. 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target({ElementType.METHOD}) 30 | public @interface PUT { 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/Priority.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Determines the priority for method and specify the order of methods invocation. 10 | * For instance you have 2 methods in chain for one URL: 11 | * 12 | *
13 |  *    {@literal @}Path("/page/.*")
14 |  *    public void common() {
15 |  *       ...
16 |  *    }
17 |  *
18 |  *    {@literal @}Path("/page/next")
19 |  *    public void next() {
20 |  *       ...
21 |  *    }
22 |  * 
23 | * 24 | * AS default the methods will be invoked in random order. Let's take situation, you wish 25 | * to invoke the 'common' on first place. You have to specify the priority for method: 26 | * 27 | *
28 |  *    {@literal @}Path("/page/.*")
29 |  *    {@literal @}Priority(Priority.HIGH)
30 |  *    public void common() {
31 |  *       ...
32 |  *    }
33 |  * 
34 | * 35 | * That annotation ensure the common() method will be invoked as first and all other methods 36 | * will continue after this method. 37 | * 38 | * @author Zdenko Vrabel (zdenko.vrabel@celum.com) 39 | */ 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Target({ElementType.METHOD}) 42 | public @interface Priority { 43 | 44 | public static final int HIGHEST = Integer.MIN_VALUE; 45 | public static final int DEFAULT = 0; 46 | public static final int LOWEST = Integer.MAX_VALUE; 47 | 48 | public int value(); 49 | } 50 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/RequestScopedAttribute.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * This annotation determines the method's argument will be filled-in 27 | * with value from request's attributes. 28 | * 29 | * Let's assume we've got security interceptor which setup the 'USER' 30 | * request attribute. 31 | * 32 | *
33 |  *    User actualUser = ...;
34 |  *    request.setAttribute("USER", actualUser);
35 |  * 
36 | * 37 | * In our controller, we can fill-in the 'USER' value into method's attribute 38 | * easily: 39 | * 40 | *
41 |  * {@literal @}Controller
42 |  * class MyController {
43 |  *    {@literal @}Path("/department");
44 |  *    public String handleRequest( {@literal @}RequestScopedAttribute("USER") User actualUser ) {
45 |  *    	return "user is:" + user;
46 |  *    }
47 |  * }
48 |  * 
49 | * 50 | */ 51 | @Retention(RUNTIME) 52 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 53 | public @interface RequestScopedAttribute { 54 | 55 | String value(); 56 | } 57 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/SessionParameter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * This method's parameter annotation pick up the value from 27 | * session. 28 | *

29 | * 30 | * example of picking up of the value for the 'user' session param: 31 | *

32 |  * {@literal @}Controller
33 |  * class MyController {
34 |  *    {@literal @}Path("/department");
35 |  *    public String handleRequest( {@literal @}SessionParameter("user") String user ) {
36 |  *    	return "user is:" + user;
37 |  *    }
38 |  * }
39 |  * 
40 | * 41 | * @see org.zdevra.guice.mvc.parameters.SessionAttributeParam 42 | */ 43 | @Retention(RUNTIME) 44 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 45 | public @interface SessionParameter { 46 | 47 | String value(); 48 | } 49 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/annotations/View.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import org.zdevra.guice.mvc.views.NamedView; 25 | import org.zdevra.guice.mvc.views.NamedViewScanner; 26 | 27 | /** 28 | * Annotation for controller and controller's methods 29 | * provide information that the {@link NamedView} should 30 | * be used for controller or method. 31 | * 32 | * This annotation extracted 'view' parameter 33 | * from {@link Controller} and {@link RequestMapping}. 34 | * 35 | * The annotation is processed by {@link NamedViewScanner} 36 | * 37 | * @see NamedView 38 | * @see NamedViewScanner 39 | * @see ViewScannerService 40 | */ 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target({ElementType.METHOD, ElementType.TYPE}) 43 | public @interface View { 44 | 45 | public String value(); 46 | } 47 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/converters/ArrayConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.converters; 18 | 19 | import java.util.LinkedList; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import org.zdevra.guice.mvc.ConversionService.Converter; 24 | 25 | /** 26 | * Converter provide conversion from request to the array of simple types as integer, 27 | * long, enumerations. This converter is not suitable for complex objects with multiple 28 | * values. 29 | */ 30 | public abstract class ArrayConverter implements Converter { 31 | 32 | private final T[] empty; 33 | 34 | protected abstract T convertItem(String value); 35 | 36 | public ArrayConverter(T[] emptyArray) { 37 | this.empty = emptyArray; 38 | } 39 | 40 | @Override 41 | public final T[] convert(String name, Map data) { 42 | String[] values = data.get(name); 43 | if (values == null) { 44 | return empty; 45 | } 46 | 47 | List out = new LinkedList(); 48 | for (int i = 0; i < values.length; ++i) { 49 | T itm = convertItem(values[i]); 50 | if (itm != null) { 51 | out.add(itm); 52 | } 53 | } 54 | return out.toArray(empty); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/converters/NoConverterFactory.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.converters; 18 | 19 | import org.zdevra.guice.mvc.ConversionService; 20 | 21 | import java.lang.annotation.Annotation; 22 | 23 | /** 24 | * The purpose of the dummy class is having some static empty factory for default parameter 25 | * in annotation {@link org.zdevra.guice.mvc.annotations.RequestParameter}. 26 | * 27 | * I need to somehow detect when is converterFactory in RequestParameter defined and when doesn't. 28 | */ 29 | public class NoConverterFactory implements ConversionService.ConverterFactory { 30 | 31 | /** 32 | * {@inheritDoc} 33 | * 34 | * @param type 35 | * @param annotations 36 | * @return 37 | */ 38 | @Override 39 | public ConversionService.Converter createConverter(Class type, Annotation[] annotations) { 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/converters/TypeConverter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.converters; 18 | 19 | import java.util.Map; 20 | 21 | import org.zdevra.guice.mvc.ConversionService.Converter; 22 | 23 | /** 24 | * Abstract class simplify conversion of simple types like integer, float etc 25 | * @param 26 | */ 27 | public abstract class TypeConverter implements Converter { 28 | 29 | /** 30 | * Implements your own conversion method 31 | */ 32 | protected abstract T convertType(String stringValue); 33 | 34 | /** 35 | * Constructor 36 | * @param clazz 37 | */ 38 | public TypeConverter() { 39 | } 40 | 41 | 42 | /** 43 | * {@inheritDoc} 44 | * 45 | * @param name 46 | * @param data 47 | * @return 48 | */ 49 | @Override 50 | public final T convert(String name, Map data) { 51 | String[] values = data.get(name); 52 | if ((values != null) && (values.length > 0)) { 53 | return convertType(values[0]); 54 | } else { 55 | return convertType(""); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/AutoConfException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * The exception signalizing a problem in package when is Autoconfiguration module used. 21 | */ 22 | public class AutoConfException extends MvcException { 23 | 24 | public AutoConfException(Class clazz, Throwable e) { 25 | super("Autoconfiguration module has problem with the class " + clazz.getName(), e); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/IllegalConversionException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * The exception is throwed when MVC is not able converts 21 | * a string value, which is picked up from URL or from Request, to 22 | * the method's parameter of the controller. 23 | * 24 | * If the exception is raised, check the mapping of the controller's 25 | * method. 26 | * 27 | */ 28 | public class IllegalConversionException extends MvcException { 29 | 30 | public IllegalConversionException(String msg) { 31 | super(msg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/InvalidJspViewException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * The exception is throwed if the Jsp is invalid or doesn't exists 21 | */ 22 | public class InvalidJspViewException extends MvcException { 23 | 24 | public InvalidJspViewException(String jspView) { 25 | super("The path to the jsp view '" + jspView + "' is invalid. Example of the valid jsp: '/test.jsp'."); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/InvalidMethodParameterException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import org.zdevra.guice.mvc.parameters.ParamMetadata; 20 | 21 | /** 22 | * The exception is throwed when the controller's method has the parameter 23 | * which source of data is undefined (parameter is without any known annotation 24 | * like {@link UriParameter} etc.. 25 | * 26 | * Solution: Specify the source of data by annotating controller method's 27 | * argument/parameter with some param. annotation 28 | */ 29 | public class InvalidMethodParameterException extends MvcException { 30 | 31 | /** 32 | * Constructor 33 | * @param metadata 34 | */ 35 | public InvalidMethodParameterException(ParamMetadata metadata) { 36 | super("Invalid source of data for parameter. Check the parameters in the controller's method " + metadata.getMethod().getName() + "()."); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/MethodInvokingException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * Wrapper exception. Each exception throwed from controller is wrapped by this 23 | * exception. 24 | * 25 | */ 26 | public class MethodInvokingException extends MvcException { 27 | 28 | /** 29 | * Constructor 30 | */ 31 | public MethodInvokingException(Method method, Throwable e) { 32 | super("Exception raised in the method '" + (method != null ? method.getName() : "") + "()'", e); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/MvcConfigurationException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | public class MvcConfigurationException extends MvcException { 20 | 21 | public MvcConfigurationException(Throwable e) { 22 | super("ERROR in Mvc initialization & configuration. Look on below exception what causes this error.", e); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/MvcException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * All Lime exceptions are derived from this exception 21 | */ 22 | public class MvcException extends RuntimeException { 23 | 24 | public MvcException(String arg0, Throwable arg1) { 25 | super(arg0, arg1); 26 | } 27 | 28 | public MvcException(String arg0) { 29 | super(arg0); 30 | } 31 | 32 | public MvcException(Throwable arg0) { 33 | super(arg0); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/NoConverterException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import org.zdevra.guice.mvc.ConversionService; 20 | 21 | /** 22 | * Lime MVC is not able convert the String value from HTTP request to the 23 | * controller's method's argument type. Check the method's arguments or 24 | * define new converter for the missing type. 25 | * 26 | */ 27 | public class NoConverterException extends MvcException { 28 | 29 | public NoConverterException(Class type) { 30 | super("No converter for String -> " + type.getCanonicalName() + " is defined."); 31 | } 32 | 33 | public NoConverterException(Class factory, Class type) { 34 | super("Invalid converter factory '" + factory.getName() + "' for String -> " + type.getCanonicalName() + " is defined."); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/NoMethodInvoked.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | /** 22 | * The lime throws this exception when no method is invoked for URL request. 23 | * 24 | */ 25 | public class NoMethodInvoked extends MvcException { 26 | 27 | public NoMethodInvoked(HttpServletRequest request) { 28 | super("no method has been invoked for the url:" + request.getRequestURL().toString()); 29 | } 30 | 31 | public NoMethodInvoked(HttpServletRequest request, String controllerName) { 32 | super("no method in the controller " + controllerName + " has been invoked for the url:" + request.getRequestURL().toString()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/NoViewException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | /** 22 | * Exception is throwed when controller has selected no view. 23 | */ 24 | public class NoViewException extends MvcException { 25 | 26 | public NoViewException(HttpServletRequest req) { 27 | super("Controller has selected invalid or undefined view (" + req.getRequestURI() + ")"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/NoViewForNameException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * Exception is throw when the controller select 21 | * view name but in the Mvc Module is no associated view 22 | * to this name. 23 | */ 24 | public class NoViewForNameException extends MvcException { 25 | 26 | public NoViewForNameException(String viewName) { 27 | super("No view is associated to the view name '" + viewName + "'"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/ObsoleteException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * Exception is occurring in these parts, which should be removed in the next release. 21 | */ 22 | public class ObsoleteException extends RuntimeException { 23 | 24 | public ObsoleteException(String replace) { 25 | super("This part is obsolete. It should be removed in the next release. Use a newest " + replace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/ScannerException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | /** 20 | * The exception is throwed by during MVC initialization 21 | * when the controllers are scanned and invokers are created. 22 | */ 23 | public class ScannerException extends MvcException { 24 | 25 | public ScannerException(Class controllerClass, Throwable e) { 26 | super("Exception in scanning of the controller:" + controllerClass.getName() + " error: " + e.getMessage(), e); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/ViewException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | /** 22 | * All view exceptions are derived from this exception 23 | */ 24 | public class ViewException extends MvcException { 25 | 26 | public ViewException(String viewId, HttpServletRequest request, Throwable e) { 27 | super("Error occured in view '" + viewId + " when URL is '" + request.getRequestURI(), e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/ViewPointException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.exceptions; 18 | 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | /** 22 | * Exception it thrown when ViewPoint's rendering fails for some reason. 23 | */ 24 | public class ViewPointException extends MvcException { 25 | 26 | public ViewPointException(String msg, HttpServletRequest request, Throwable e) { 27 | super(msg, e); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | /** 18 | * The package contains all Lime exceptions. 19 | */ 20 | package org.zdevra.guice.mvc.exceptions; -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/parameters/DefaultParamFactory.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.parameters; 18 | 19 | /** 20 | * Default factory is used for all unknown parameters and throws 21 | * exception. 22 | */ 23 | public class DefaultParamFactory implements ParamProcessorFactory { 24 | 25 | /** 26 | * {@inheritDoc} 27 | * 28 | * @param metadata 29 | * @return 30 | */ 31 | @Override 32 | public ParamProcessor buildParamProcessor(ParamMetadata metadata) { 33 | throw new IllegalStateException("illegal parameter in method:" + metadata.getMethod().getName()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/parameters/ParamProcessor.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.parameters; 18 | 19 | import org.zdevra.guice.mvc.InvokeData; 20 | 21 | /** 22 | * You will implement this interface for your custom parameter processing.The processor 23 | * is builded via {@link ParamProcessorFactory} implementation. This factory implementation is then 24 | * registered in {@link ParamProcessorService} 25 | * 26 | * @see ParamProcessorFactory 27 | * @see ParamProcessorService 28 | */ 29 | public interface ParamProcessor { 30 | 31 | public Object getValue(InvokeData data); 32 | } 33 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/parameters/ParamProcessorFactory.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.parameters; 18 | 19 | /** 20 | * You will implement this interface which build your parameter processor. 21 | * 22 | * @see ParamProcessor 23 | * @see ParamProcessorService 24 | */ 25 | public interface ParamProcessorFactory { 26 | 27 | public ParamProcessor buildParamProcessor(ParamMetadata metadata); 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/parameters/package-info.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | /** 18 | * In the package are various classes responsible for processing of various parameters 19 | * in controller methods. These parameter-processors are used when Lime invoke 20 | * controller's method. 21 | * 22 | * This is a right place if you need more informations about how the concrete 23 | * parameter is processed. 24 | * 25 | */ 26 | package org.zdevra.guice.mvc.parameters; -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/views/RedirectViewScanner.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2012 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.views; 18 | 19 | import java.lang.annotation.Annotation; 20 | 21 | import org.zdevra.guice.mvc.Utils; 22 | import org.zdevra.guice.mvc.ViewPoint; 23 | import org.zdevra.guice.mvc.ViewScanner; 24 | import org.zdevra.guice.mvc.annotations.RedirectView; 25 | 26 | /** 27 | * Scanner is looking for {@link RedirectView} annotation and creates initialized 28 | * instance of the {@link RedirectViewPoint} for annotation. 29 | * 30 | */ 31 | public class RedirectViewScanner implements ViewScanner { 32 | 33 | /** 34 | * {@inheritDoc} 35 | * 36 | * @param annotations - annotations of the controller or controller's method 37 | * @return 38 | */ 39 | @Override 40 | public final ViewPoint scan(Annotation[] annotations) { 41 | RedirectView redirectAnnotation = Utils.getAnnotation(RedirectView.class, annotations); 42 | if (redirectAnnotation == null) { 43 | return ViewPoint.NULL_VIEW; 44 | } 45 | return new RedirectViewPoint(redirectAnnotation.value(), redirectAnnotation.contextRelative()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lime/src/main/java/org/zdevra/guice/mvc/views/package-info.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | /** 18 | * The package contains all supported implementations of views. 19 | */ 20 | package org.zdevra.guice.mvc.views; -------------------------------------------------------------------------------- /lime/src/test/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright 2011 Zdenko Vrabel 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *****************************************************************************/ 18 | class Trest { 19 | 20 | public T getTrest() { 21 | return null; 22 | } 23 | } 24 | 25 | class TrestInt extends Trest { 26 | 27 | @Override 28 | public Integer getTrest() { 29 | return 1; 30 | } 31 | } 32 | 33 | class TrestString extends Trest { 34 | 35 | @Override 36 | public String getTrest() { 37 | return "asd"; 38 | } 39 | } 40 | 41 | /** 42 | * This class exists for debugging and testing 43 | * purpose. 44 | * 45 | */ 46 | public class Main { 47 | 48 | public static void main(String[] args) { 49 | try { 50 | Trest x = new TrestInt(); 51 | x.getTrest(); 52 | 53 | 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/HttpSessinonController.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import javax.servlet.http.HttpSession; 20 | 21 | import org.zdevra.guice.mvc.annotations.Controller; 22 | 23 | @Controller 24 | public class HttpSessinonController { 25 | 26 | public String sessionMethod(HttpSession session) { 27 | return "sessionMethod:" + session.getAttribute("test"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/MethodInvokerTest.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc; 2 | 3 | import junit.framework.Assert; 4 | import org.testng.annotations.Test; 5 | import org.zdevra.guice.mvc.parameters.ParamProcessor; 6 | 7 | import java.util.Collections; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Zdenko Vrabel (zdenko.vrabel@celum.com) 13 | */ 14 | @Test 15 | public class MethodInvokerTest { 16 | 17 | @Test 18 | public void sortMethods() { 19 | List paramProcs = Collections.emptyList(); 20 | MappingData data = new MappingData(null, null, HttpMethodType.POST, "", "", null); 21 | 22 | 23 | MethodInvoker a = new MethodInvokerImpl(null, null, null, null, paramProcs, 0); 24 | MethodInvoker b = new MethodInvokerImpl(null, null, null, null, paramProcs, -10); 25 | MethodInvoker c = new MethodInvokerImpl(null, null, null, null, paramProcs, 0); 26 | MethodInvoker d = new MethodInvokerFilter(data, new MethodInvokerImpl(null, null, null, null, paramProcs, 20)); 27 | MethodInvoker e = new MethodInvokerImpl(null, null, null, null, paramProcs, 10); 28 | 29 | List invokers = new LinkedList(); 30 | invokers.add(a); 31 | invokers.add(b); 32 | invokers.add(c); 33 | invokers.add(d); 34 | invokers.add(e); 35 | 36 | Collections.sort(invokers); 37 | 38 | Assert.assertEquals(b, invokers.get(0)); 39 | Assert.assertEquals(e, invokers.get(3)); 40 | Assert.assertEquals(d, invokers.get(4)); 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/ModelTest.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import org.testng.Assert; 20 | import org.testng.annotations.Test; 21 | 22 | @Test 23 | public class ModelTest { 24 | 25 | @Test 26 | public void testConstructor() { 27 | ModelMap m = new ModelMap("test1", "value1"); 28 | String v = (String) m.getObject("test1"); 29 | Assert.assertEquals("value1", v); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/NamedViewTest.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import org.testng.Assert; 20 | import org.testng.annotations.Test; 21 | import org.zdevra.guice.mvc.annotations.Controller; 22 | import org.zdevra.guice.mvc.views.NamedView; 23 | 24 | @Test 25 | public class NamedViewTest { 26 | 27 | @Controller(view = "test") 28 | public static class TestController { 29 | } 30 | 31 | @Controller(view = "") 32 | public static class TestControllerNull { 33 | } 34 | 35 | @Test 36 | public void testControllerToView() { 37 | ViewPoint view = NamedView.create(TestController.class); 38 | Assert.assertNotNull(view); 39 | Assert.assertEquals(view.toString(), "NamedView [name=test]"); 40 | } 41 | 42 | @Test 43 | public void testControllerToViewNull() { 44 | ViewPoint view = NamedView.create(TestControllerNull.class); 45 | ViewPoint viewnull = ViewPoint.NULL_VIEW; 46 | Assert.assertTrue(view == viewnull); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/SimpleController.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import javax.inject.Singleton; 20 | 21 | import org.zdevra.guice.mvc.annotations.Controller; 22 | import org.zdevra.guice.mvc.annotations.GET; 23 | import org.zdevra.guice.mvc.annotations.Path; 24 | import org.zdevra.guice.mvc.annotations.UriParameter; 25 | 26 | @Controller() 27 | @Singleton 28 | public class SimpleController { 29 | 30 | @Path("/someController/(.*)") 31 | @GET 32 | public void controllMethod1(@UriParameter(1) String param) { 33 | System.out.println("invoked with controllMethod1 param=" + param); 34 | } 35 | 36 | @Path("/someController/controllMethod2/(.*)/(.*)") 37 | public void controllMethod2(@UriParameter(1) String param1, @UriParameter(2) String param2) { 38 | System.out.println("invoked with controllMethod2 param1=" + param1 + " param2=" + param2); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/TestModule.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc; 2 | 3 | import org.zdevra.guice.mvc.DefaultViewResolver; 4 | import org.zdevra.guice.mvc.ViewScannerService; 5 | 6 | import com.google.inject.AbstractModule; 7 | 8 | public class TestModule extends AbstractModule { 9 | 10 | @Override 11 | protected void configure() { 12 | bind(ViewScannerService.class); 13 | bind(ViewResolver.class).to(DefaultViewResolver.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/TestServlet.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc; 18 | 19 | import com.google.inject.Guice; 20 | import com.google.inject.Injector; 21 | 22 | public class TestServlet extends MvcDispatcherServlet { 23 | 24 | public TestServlet(Class[] controllers, MvcModule module) { 25 | super(controllers, Guice.createInjector(module)); 26 | } 27 | 28 | public TestServlet(Class controllerClass, Injector injector) { 29 | super(controllerClass, injector); 30 | } 31 | 32 | public TestServlet(Class controllerClass, MvcModule module) { 33 | super(controllerClass, Guice.createInjector(module)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case1/Case1Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case1; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | import org.zdevra.guice.mvc.TestView; 21 | 22 | public class Case1Module extends MvcModule { 23 | 24 | @Override 25 | protected void configureControllers() { 26 | bindViewName("default").toViewInstance(new TestView("0")); 27 | control("/somepath").withView("someview.jsp"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/Case10ContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | 5 | import com.google.inject.Guice; 6 | import com.google.inject.Injector; 7 | import com.google.inject.servlet.GuiceServletContextListener; 8 | 9 | public class Case10ContextListener extends GuiceServletContextListener { 10 | 11 | @Override 12 | protected Injector getInjector() { 13 | return Guice.createInjector(new MvcModule() { 14 | @Override 15 | protected void configureControllers() { 16 | registerGlobalInterceptor(SecurityInterceptor.class); 17 | 18 | control("/case10/*") 19 | .withController(Case10Controller.class); 20 | 21 | 22 | control("/case10log/*") 23 | .withController(Case10Controller.class) 24 | .interceptor(LogInterceptor.class); 25 | 26 | 27 | control("/case10after/*") 28 | .withController(Case10Controller.class); 29 | 30 | } 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/Case10Controller.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | import org.zdevra.guice.mvc.annotations.Controller; 4 | import org.zdevra.guice.mvc.annotations.Model; 5 | import org.zdevra.guice.mvc.annotations.Path; 6 | import org.zdevra.guice.mvc.annotations.RequestScopedAttribute; 7 | import org.zdevra.guice.mvc.annotations.View; 8 | 9 | @Controller 10 | public class Case10Controller { 11 | 12 | @Path("/do-something") 13 | @Model("out") 14 | @View("/WEB-INF/views/main.html.jsp") 15 | public String doSomething(@RequestScopedAttribute("USER") User usr) { 16 | if (usr == null) { 17 | throw new NullPointerException(); 18 | } 19 | return "something:" + usr.toString(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/Case10Log.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class Case10Log { 7 | 8 | private static Case10Log instance; 9 | private List messages; 10 | 11 | public static Case10Log getInstance() { 12 | if (instance == null) { 13 | instance = new Case10Log(); 14 | instance.reset(); 15 | } 16 | return instance; 17 | } 18 | 19 | public void reset() { 20 | this.messages = new LinkedList(); 21 | } 22 | 23 | public void log(String msg) { 24 | System.out.println(msg); 25 | this.messages.add(msg); 26 | } 27 | 28 | public List getMessages() { 29 | return messages; 30 | } 31 | 32 | public int contains(String text) { 33 | int occurence = 0; 34 | for (String m : messages) { 35 | if (m.contains(text)) { 36 | occurence++; 37 | } 38 | } 39 | return occurence; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.zdevra.guice.mvc.InterceptorHandler; 7 | import org.zdevra.guice.mvc.ModelAndView; 8 | 9 | import com.google.inject.Singleton; 10 | 11 | @Singleton 12 | public class LogInterceptor implements InterceptorHandler { 13 | 14 | @Override 15 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response) { 16 | Case10Log.getInstance().log("preHandle executed"); 17 | return true; 18 | } 19 | 20 | @Override 21 | public void postHandle(HttpServletRequest request, HttpServletResponse response, ModelAndView mav) { 22 | Case10Log.getInstance().log("postHandle executed"); 23 | } 24 | 25 | @Override 26 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Throwable e) { 27 | Case10Log.getInstance().log("afterCompletion executed"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/SecurityInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.zdevra.guice.mvc.AbstractInterceptorHandler; 7 | import org.zdevra.guice.mvc.InterceptorHandler; 8 | import org.zdevra.guice.mvc.ModelAndView; 9 | 10 | public class SecurityInterceptor extends AbstractInterceptorHandler { 11 | 12 | @Override 13 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response) { 14 | String username = request.getParameter("username"); 15 | String password = request.getParameter("password"); 16 | 17 | if (("admin".equalsIgnoreCase(username)) 18 | && ("pass123".equalsIgnoreCase(password))) { 19 | request.setAttribute("USER", new User(username, password)); 20 | return true; 21 | } 22 | 23 | response.setStatus(401); 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/User.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case10; 2 | 3 | public class User { 4 | 5 | private final String username; 6 | private final String password; 7 | 8 | public User(String username, String password) { 9 | this.username = username; 10 | this.password = password; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return "User [username=" + username + ", password=" + password + "]"; 16 | } 17 | 18 | public String getUsername() { 19 | return username; 20 | } 21 | 22 | public String getPassword() { 23 | return password; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/webapp/WEB-INF/views/main.html.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | OUT 4 | 5 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case10/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | JSilver Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.guice.mvc.case10.Case10ContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case11/Case11ContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case11; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | 5 | import com.google.inject.Guice; 6 | import com.google.inject.Injector; 7 | import com.google.inject.servlet.GuiceServletContextListener; 8 | 9 | public class Case11ContextListener extends GuiceServletContextListener { 10 | 11 | @Override 12 | protected Injector getInjector() { 13 | return Guice.createInjector(new MvcModule() { 14 | @Override 15 | protected void configureControllers() { 16 | control("/case11/*") 17 | .withController(Case11Controller.class); 18 | } 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case11/Case11Controller.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case11; 2 | 3 | import org.zdevra.guice.mvc.annotations.Controller; 4 | import org.zdevra.guice.mvc.annotations.Model; 5 | import org.zdevra.guice.mvc.annotations.Path; 6 | import org.zdevra.guice.mvc.annotations.RedirectView; 7 | 8 | @Controller 9 | public class Case11Controller { 10 | 11 | @Path("/absolute-redirect") 12 | @Model("param1") 13 | @RedirectView("http://www.google.com") 14 | public String doAbsoluteRedirect() { 15 | return "value1"; 16 | } 17 | 18 | @Path("/relative-redirect") 19 | @Model("param1") 20 | @RedirectView(value = "/welcome", contextRelative = false) 21 | public String doRelativeRedirect() { 22 | return "value1"; 23 | } 24 | 25 | @Path("/relative-context") 26 | @Model("param2") 27 | @RedirectView("/welcome") 28 | public String doRelativeContextRedirect() { 29 | return "value2"; 30 | } 31 | 32 | @Path("/npe") 33 | @Model("param3") 34 | @RedirectView("/welcome") 35 | public String throwSomeError() { 36 | throw new NullPointerException(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case11/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | JSilver Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.guice.mvc.case11.Case11ContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case2/Case2Controller.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case2; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Model; 21 | import org.zdevra.guice.mvc.annotations.Path; 22 | import org.zdevra.guice.mvc.annotations.UriParameter; 23 | 24 | @Controller(view = "default") 25 | public interface Case2Controller { 26 | 27 | @Path("/getcar/(.*)") 28 | @Model("testmsg") 29 | public String getCar(@UriParameter(1) String value); 30 | } 31 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case2/Case2ControllerImpl.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case2; 18 | 19 | import com.google.inject.Singleton; 20 | 21 | @Singleton 22 | public class Case2ControllerImpl implements Case2Controller { 23 | 24 | @Override 25 | public String getCar(String val) { 26 | return "ford-" + val; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case2/Case2Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case2; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | import org.zdevra.guice.mvc.TestView; 21 | 22 | public class Case2Module extends MvcModule { 23 | 24 | @Override 25 | protected void configureControllers() { 26 | bindViewName("default").toViewInstance(new TestView("0")); 27 | bind(Case2Controller.class).to(Case2ControllerImpl.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case3/Case3Controller.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case3; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Path; 21 | import org.zdevra.guice.mvc.annotations.View; 22 | 23 | @Controller(view = "default") 24 | public class Case3Controller { 25 | 26 | @Path("/view/default") 27 | public void defaultView() { 28 | } 29 | 30 | @Path("/view/5") 31 | @View("five") 32 | public void viewFive() { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case3/Case3Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case3; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | import org.zdevra.guice.mvc.TestView; 21 | 22 | class ThreeView extends TestView { 23 | 24 | public ThreeView() { 25 | super("3"); 26 | } 27 | } 28 | 29 | public class Case3Module extends MvcModule { 30 | 31 | @Override 32 | protected void configureControllers() { 33 | install(new Case3ModuleView()); 34 | bindViewName("default").toViewInstance(new TestView("0")); 35 | bindViewName("one").toViewInstance(new TestView("1")); 36 | bindViewName("two").toViewInstance(new TestView("2")); 37 | bindViewName("three").toView(ThreeView.class); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case3/Case3ModuleView.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case3; 2 | 3 | import org.zdevra.guice.mvc.TestView; 4 | import org.zdevra.guice.mvc.ViewModule; 5 | 6 | public class Case3ModuleView extends ViewModule { 7 | 8 | @Override 9 | protected void configureViews() { 10 | bindViewName("five").toViewInstance(new TestView("5")); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/AdvancedCustomException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | public class AdvancedCustomException extends CustomException { 20 | 21 | public AdvancedCustomException() { 22 | super("AdvancedCustomException->"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/AdvancedHandledException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | public class AdvancedHandledException extends CustomException { 20 | 21 | public AdvancedHandledException() { 22 | super("AdvancedHandledException->"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/AdvancedHandler.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.zdevra.guice.mvc.ExceptionHandler; 26 | 27 | public class AdvancedHandler implements ExceptionHandler { 28 | 29 | @Override 30 | public void handleException(Throwable t, HttpServlet servlet, HttpServletRequest req, HttpServletResponse resp) { 31 | try { 32 | resp.getWriter().write("advanced handler:" + t.getMessage()); 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/Case4Controller.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Path; 21 | 22 | @Controller(view = "default") 23 | public class Case4Controller { 24 | 25 | @Path("/expetion/npe") 26 | public void throwNpe() { 27 | throw new NullPointerException(""); 28 | } 29 | 30 | @Path("/expetion/custom") 31 | public void throwCustom() { 32 | throw new CustomException(); 33 | } 34 | 35 | @Path("/expetion/advancedcustom") 36 | public void throwAdvCustom() { 37 | throw new AdvancedCustomException(); 38 | } 39 | 40 | @Path("/expetion/advancedhandledexception") 41 | public void throwAdvHandledException() { 42 | throw new AdvancedHandledException(); 43 | } 44 | 45 | @Path("/expetion/errorview") 46 | public void throwErrorViewException() { 47 | throw new ExceptionForErrorPage(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/Case4Main.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | public class Case4Main { 20 | 21 | public static void main(String[] args) { 22 | try { 23 | Case4Test t = new Case4Test(); 24 | t.prepare(); 25 | t.testDefaultHandler(); 26 | t.testCustomHandler(); 27 | t.testAdvancedCustomHandler(); 28 | t.testAdvancedHandled(); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/Case4Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | import org.zdevra.guice.mvc.TestView; 21 | 22 | public class Case4Module extends MvcModule { 23 | 24 | @Override 25 | protected void configureControllers() { 26 | bindException(CustomException.class).toHandler(CustomExceptionHandler.class); 27 | bindException(AdvancedHandledException.class).toHandlerInstance(new AdvancedHandler()); 28 | bindException(ExceptionForErrorPage.class).toErrorView("errorView"); 29 | bindViewName("default").toViewInstance(new TestView("0")); 30 | bindViewName("errorView").toViewInstance(new TestView("errorpage")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/CustomException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | public class CustomException extends RuntimeException { 20 | 21 | public CustomException() { 22 | super("CustomException"); 23 | } 24 | 25 | public CustomException(String msg) { 26 | super(msg + "CustomException "); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/CustomExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case4; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.zdevra.guice.mvc.ExceptionHandler; 26 | 27 | public class CustomExceptionHandler implements ExceptionHandler { 28 | 29 | @Override 30 | public void handleException(Throwable t, HttpServlet servlet, HttpServletRequest req, HttpServletResponse resp) { 31 | try { 32 | resp.getWriter().write("customized handler:" + t.getMessage()); 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case4/ExceptionForErrorPage.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case4; 2 | 3 | public class ExceptionForErrorPage extends RuntimeException { 4 | } 5 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case5/Case5Controller.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case5; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Model; 21 | import org.zdevra.guice.mvc.annotations.Path; 22 | import org.zdevra.guice.mvc.annotations.View; 23 | 24 | @Controller 25 | @View("one.jsp") 26 | public class Case5Controller { 27 | 28 | @Path("/action/one") 29 | @Model("testmsg") 30 | public String actionOne() { 31 | return "onedata"; 32 | } 33 | 34 | @Path("/action/two") 35 | @View("two.jsp") 36 | @Model("testmsg") 37 | public String actionTwo() { 38 | return "twodata"; 39 | } 40 | 41 | @Path("/action/three") 42 | @Model("testmsg") 43 | @View("three.jsp") 44 | public String actionThree() { 45 | return "threedata"; 46 | } 47 | 48 | @Path("/action/custom") 49 | @Model("testmsg") 50 | @ToTestView 51 | public String actionCustom() { 52 | return "customdata"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case5/Case5Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case5; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | import org.zdevra.guice.mvc.TestView; 21 | 22 | public class Case5Module extends MvcModule { 23 | 24 | @Override 25 | protected void configureControllers() { 26 | registerViewScanner(TestViewScanner.class); 27 | bindViewName("one.jsp").toViewInstance(new TestView("1")); 28 | bindViewName("two.jsp").toViewInstance(new TestView("2")); 29 | bindViewName("three.jsp").toViewInstance(new TestView("3")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case5/TestViewScanner.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case5; 18 | 19 | import java.lang.annotation.Annotation; 20 | 21 | import org.zdevra.guice.mvc.TestView; 22 | import org.zdevra.guice.mvc.Utils; 23 | import org.zdevra.guice.mvc.ViewPoint; 24 | import org.zdevra.guice.mvc.ViewScanner; 25 | 26 | public class TestViewScanner implements ViewScanner { 27 | 28 | @Override 29 | public ViewPoint scan(Annotation[] annotations) { 30 | ToTestView anot = Utils.getAnnotation(ToTestView.class, annotations); 31 | if (anot != null) { 32 | return new TestView("9"); 33 | } 34 | return ViewPoint.NULL_VIEW; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case5/ToTestView.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case5; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target({ElementType.METHOD, ElementType.TYPE}) 26 | public @interface ToTestView { 27 | } 28 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case6/Case6ControllerCars.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case6; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Model; 21 | import org.zdevra.guice.mvc.annotations.Path; 22 | import org.zdevra.guice.mvc.annotations.View; 23 | 24 | @Controller 25 | @View("cars.jsp") 26 | public class Case6ControllerCars { 27 | 28 | @Path("/common") 29 | @Model("msg2") 30 | public String commonMethod() { 31 | return "cars common"; 32 | } 33 | 34 | @Path("/cars") 35 | @Model("msg1") 36 | public String carsMethod() { 37 | return "cars method"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case6/Case6ControllerPeople.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case6; 18 | 19 | import org.zdevra.guice.mvc.annotations.Controller; 20 | import org.zdevra.guice.mvc.annotations.Model; 21 | import org.zdevra.guice.mvc.annotations.Path; 22 | import org.zdevra.guice.mvc.annotations.View; 23 | 24 | @Controller 25 | @View("people.jsp") 26 | public class Case6ControllerPeople { 27 | 28 | @Path("/common") 29 | @Model("msg1") 30 | public String commonMethod() { 31 | return "people common"; 32 | } 33 | 34 | @Path("/people") 35 | @Model("msg1") 36 | public String peopleMethod() { 37 | return "people method"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case6/Case6Module.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case6; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | 21 | public class Case6Module extends MvcModule { 22 | 23 | @Override 24 | protected void configureControllers() { 25 | bindViewName("cars.jsp").toViewInstance(new Case6View("cars.jsp")); 26 | bindViewName("people.jsp").toViewInstance(new Case6View("people.jsp")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case6/Case6Servlet.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case6; 18 | 19 | import org.zdevra.guice.mvc.TestServlet; 20 | 21 | public class Case6Servlet extends TestServlet { 22 | 23 | public Case6Servlet() { 24 | super( 25 | new Class[]{ 26 | Case6ControllerCars.class, 27 | Case6ControllerPeople.class 28 | }, 29 | new Case6Module()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case6/Case6View.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.case6; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.zdevra.guice.mvc.ModelMap; 26 | import org.zdevra.guice.mvc.ViewPoint; 27 | 28 | public class Case6View implements ViewPoint { 29 | 30 | private final String id; 31 | 32 | public Case6View(String id) { 33 | this.id = id; 34 | } 35 | 36 | @Override 37 | public void render(ModelMap model, HttpServlet servlet, HttpServletRequest request, HttpServletResponse response) { 38 | try { 39 | Object msg1 = request.getAttribute("msg1"); 40 | Object msg2 = request.getAttribute("msg2"); 41 | response.getWriter().write("case6 view id:" + id + " msg1:" + msg1 + " msg2:" + msg2); 42 | } catch (IOException e) { 43 | //TODO:dopisat ViewException 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case8/Case8Module.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case8; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | import org.zdevra.guice.mvc.TestView; 5 | 6 | public class Case8Module extends MvcModule { 7 | 8 | @Override 9 | protected void configureControllers() { 10 | registerConverter(FirstPersonConverterFactory.class); 11 | registerConverter(SecondPersonConverterFactory.class); 12 | bindViewName("default").toViewInstance(new TestView("0")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case8/Case8Servlet.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case8; 2 | 3 | import org.zdevra.guice.mvc.TestServlet; 4 | 5 | /** 6 | * Derived servlet from MvcDispatcherServlet 7 | */ 8 | public class Case8Servlet extends TestServlet { 9 | 10 | public Case8Servlet() { 11 | super(Case8Controller.class, new Case8Module()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case8/FirstPersonConverterFactory.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case8; 2 | 3 | import org.zdevra.guice.mvc.ConversionService; 4 | import org.zdevra.guice.mvc.converters.AbstractConverter; 5 | 6 | import java.lang.annotation.Annotation; 7 | import java.util.Map; 8 | 9 | public class FirstPersonConverterFactory implements ConversionService.ConverterFactory { 10 | 11 | @Override 12 | public ConversionService.Converter createConverter(Class type, Annotation[] annotations) { 13 | if (type == Person.class) { 14 | return new FirstPersonConverter(); 15 | } 16 | return null; 17 | } 18 | 19 | private static class FirstPersonConverter extends AbstractConverter { 20 | 21 | @Override 22 | public Person convert(String formName, Map data) { 23 | String name = "1 " + getValue(formName + "-name", data); 24 | String surname = "1 " + getValue(formName + "-surname", data); 25 | return new Person(name, surname); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case8/Person.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case8; 2 | 3 | public class Person { 4 | 5 | private final String name; 6 | private final String surname; 7 | 8 | public Person(String name, String surname) { 9 | this.name = name; 10 | this.surname = surname; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public String getSurname() { 18 | return surname; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Person{" 24 | + "name='" + name + '\'' 25 | + ", surname='" + surname + '\'' 26 | + '}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case8/SecondPersonConverterFactory.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case8; 2 | 3 | import org.zdevra.guice.mvc.ConversionService; 4 | import org.zdevra.guice.mvc.converters.AbstractConverter; 5 | 6 | import java.lang.annotation.Annotation; 7 | import java.util.Map; 8 | 9 | public class SecondPersonConverterFactory implements ConversionService.ConverterFactory { 10 | 11 | @Override 12 | public ConversionService.Converter createConverter(Class type, Annotation[] annotations) { 13 | if (type == Person.class) { 14 | return new SecondPersonConverter(); 15 | } 16 | return null; 17 | } 18 | 19 | private static class SecondPersonConverter extends AbstractConverter { 20 | 21 | @Override 22 | public Person convert(String formName, Map data) { 23 | String name = "2 " + getValue(formName + "-name", data); 24 | String surname = "2 " + getValue(formName + "-surname", data); 25 | return new Person(name, surname); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/Case9ContextListener.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case9; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | import com.google.inject.servlet.GuiceServletContextListener; 6 | 7 | public class Case9ContextListener extends GuiceServletContextListener { 8 | 9 | @Override 10 | protected Injector getInjector() { 11 | return Guice.createInjector(new Case9Module()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/Case9Controller.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case9; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.zdevra.guice.mvc.annotations.Controller; 6 | import org.zdevra.guice.mvc.annotations.GET; 7 | import org.zdevra.guice.mvc.annotations.POST; 8 | import org.zdevra.guice.mvc.annotations.Path; 9 | import org.zdevra.guice.mvc.annotations.View; 10 | 11 | import com.google.inject.Module; 12 | 13 | @Controller 14 | public class Case9Controller { 15 | 16 | @Path("/people/new/second") 17 | @View("/WEB-INF/view/form2.html.jsp") 18 | public Module anotherCall(HttpServletRequest request) { 19 | return null; 20 | } 21 | 22 | @Path("/people") 23 | @View("/WEB-INF/view/success.html.jsp") 24 | public Module submit(HttpServletRequest request) { 25 | return null; 26 | } 27 | 28 | @Path("/people/new") 29 | @View("/WEB-INF/view/form.html.jsp") 30 | public Module showForm() { 31 | return null; 32 | } 33 | 34 | @GET 35 | @Path("/people/rest") 36 | @View("/WEB-INF/view/form-get.html.jsp") 37 | public Module getPeople() { 38 | return null; 39 | } 40 | 41 | @POST 42 | @Path("/people/rest") 43 | @View("/WEB-INF/view/form-post.html.jsp") 44 | public Module postPeople() { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/Case9Module.java: -------------------------------------------------------------------------------- 1 | package org.zdevra.guice.mvc.case9; 2 | 3 | import org.zdevra.guice.mvc.MvcModule; 4 | 5 | public class Case9Module extends MvcModule { 6 | 7 | @Override 8 | protected void configureControllers() { 9 | control("/case9/*").withController(Case9Controller.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/view/form-get.html.jsp: -------------------------------------------------------------------------------- 1 | FORM GET -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/view/form-post.html.jsp: -------------------------------------------------------------------------------- 1 | FORM POST -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/view/form.html.jsp: -------------------------------------------------------------------------------- 1 | FORM -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/view/form2.html.jsp: -------------------------------------------------------------------------------- 1 | FORM 2 -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/view/success.html.jsp: -------------------------------------------------------------------------------- 1 | SUCCESS -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/case9/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | JSilver Example 9 | 10 | 11 | guiceFilter 12 | com.google.inject.servlet.GuiceFilter 13 | 14 | 15 | 16 | guiceFilter 17 | /* 18 | 19 | 20 | 21 | org.zdevra.guice.mvc.case9.Case9ContextListener 22 | 23 | 24 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/BlogArticlesController.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import java.util.List; 20 | 21 | import org.zdevra.guice.mvc.ModelMap; 22 | import org.zdevra.guice.mvc.ModelAndView; 23 | import org.zdevra.guice.mvc.annotations.UriParameter; 24 | 25 | import com.google.inject.Inject; 26 | import com.google.inject.Singleton; 27 | 28 | @Singleton 29 | public class BlogArticlesController implements IBlogArticlesController { 30 | 31 | private final BlogDao dao; 32 | 33 | @Inject 34 | public BlogArticlesController(BlogDao dao) { 35 | this.dao = dao; 36 | } 37 | 38 | public List showAllArticles() { 39 | return dao.getAllArticles(); 40 | } 41 | 42 | public ModelAndView showAllArticlesDirect() { 43 | ModelMap m = new ModelMap("allarticles", dao.getAllArticles()); 44 | return new ModelAndView(m, new ViewAllArticles()); 45 | } 46 | 47 | public String showArticle(@UriParameter(1) int id) { 48 | return dao.getArticle(id); 49 | } 50 | 51 | public ModelAndView showArticleDirect(@UriParameter(1) int id) { 52 | ModelMap m = new ModelMap("article", dao.getArticle(id)); 53 | return new ModelAndView(m, new ViewArticle()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/BlogDao.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import com.google.inject.Singleton; 23 | 24 | @Singleton 25 | public class BlogDao { 26 | 27 | private final String[] articles = { 28 | "Article 1", 29 | "Article 2", 30 | "Article 3", 31 | "Article 4", 32 | "Article 5" 33 | }; 34 | 35 | public List getAllArticles() { 36 | return Arrays.asList(articles); 37 | } 38 | 39 | public String getArticle(int id) { 40 | if (id >= articles.length) { 41 | return "unknown"; 42 | } 43 | return articles[id]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/BlogModule.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import org.zdevra.guice.mvc.MvcModule; 20 | 21 | public class BlogModule extends MvcModule { 22 | 23 | @Override 24 | protected void configureControllers() { 25 | 26 | bind(IBlogArticlesController.class).to(BlogArticlesController.class); 27 | 28 | //setup views 29 | bindViewName("allarticles.jsp").toView(ViewAllArticles.class); 30 | bindViewName("article.jsp").toView(ViewArticle.class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/IBlogArticlesController.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import java.util.List; 20 | 21 | import org.zdevra.guice.mvc.ModelAndView; 22 | import org.zdevra.guice.mvc.annotations.Controller; 23 | import org.zdevra.guice.mvc.annotations.Model; 24 | import org.zdevra.guice.mvc.annotations.Path; 25 | import org.zdevra.guice.mvc.annotations.UriParameter; 26 | import org.zdevra.guice.mvc.annotations.View; 27 | 28 | @Controller 29 | public interface IBlogArticlesController { 30 | 31 | @Path("/blog/allarticles/namedview") 32 | @Model("allarticles") 33 | @View("allarticles.jsp") 34 | public List showAllArticles(); 35 | 36 | @Path("/blog/allarticles/directview") 37 | public ModelAndView showAllArticlesDirect(); 38 | 39 | @Path("/blog/article/(\\d+)/namedview") 40 | @Model("article") 41 | @View("article.jsp") 42 | public String showArticle(@UriParameter(1) int id); 43 | 44 | @Path("/blog/article/(\\d+)/directview") 45 | public ModelAndView showArticleDirect(@UriParameter(1) int id); 46 | } 47 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/PerfServlet.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import org.zdevra.guice.mvc.TestServlet; 20 | 21 | public class PerfServlet extends TestServlet { 22 | 23 | public PerfServlet() { 24 | super( 25 | new Class[]{ 26 | IBlogArticlesController.class 27 | }, 28 | new BlogModule()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/ViewAllArticles.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | import org.zdevra.guice.mvc.ModelMap; 27 | import org.zdevra.guice.mvc.ViewPoint; 28 | 29 | public class ViewAllArticles implements ViewPoint { 30 | 31 | @Override 32 | public void render(ModelMap model, HttpServlet servlet, HttpServletRequest request, HttpServletResponse response) { 33 | try { 34 | List articles = (List) request.getAttribute("allarticles"); 35 | response.getWriter().write("Articles list\n"); 36 | for (String article : articles) { 37 | response.getWriter().write("Article:" + article + "\n"); 38 | } 39 | } catch (IOException e) { 40 | //TODO:view exception 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lime/src/test/java/org/zdevra/guice/mvc/casePerformance/ViewArticle.java: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright 2011 Zdenko Vrabel 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | *****************************************************************************/ 17 | package org.zdevra.guice.mvc.casePerformance; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.zdevra.guice.mvc.ModelMap; 26 | import org.zdevra.guice.mvc.ViewPoint; 27 | 28 | public class ViewArticle implements ViewPoint { 29 | 30 | @Override 31 | public void render(ModelMap model, HttpServlet servlet, HttpServletRequest request, HttpServletResponse response) { 32 | try { 33 | String article = (String) request.getAttribute("article"); 34 | response.getWriter().write("Article detail\n"); 35 | response.getWriter().write("Article:" + article + "\n"); 36 | } catch (IOException e) { 37 | //TODO: dopisat ViewException 38 | } 39 | } 40 | } 41 | --------------------------------------------------------------------------------