templates.plugins.spincast-cookies.spincast-cookies.html Maven / Gradle / Ivy
{#==========================================
Spincast Cookies plugin
==========================================#}
{% extends "../../layout.html" %}
{% block sectionClasses %}plugins plugins-spincast-cookies{% endblock %}
{% block meta_title %}Plugins - Spincast Cookies{% endblock %}
{% block meta_description %}Spincast Cookies plugin provides functionalities to read and write cookies.{% endblock %}
{% block scripts %}
{% endblock %}
{% block body %}
    
    
     
        
             Spincast Cookies plugin
            
                 default
                
             
        
    
    
    
    
        
        
        
        
            
            
                
                    
                    Overview
                
                
                    The Spincast Cookies plugin provides functionalities
                    to read and write cookies. It mainly consists of a request context add-on :
                    "ICookiesRequestContextAddon", which is 
                    mounted as .cookies() on the default Spincast request context. 
                
                
                    The plugin also provides an implementation for the "ICookie" object.
                
             
            
            
                
                    
                    Installation
                
                
                    If you use the spincast-default artifact, this plugin is already installed so
                    you have nothing more to do!
                
                
                    
                    If you start from scratch using the spincast-core artifact, you can use the
                    plugin by adding this artifact to your project:
                    
                        
                            
<dependency>
    <groupId>org.spincast</groupId>
    <artifactId>spincast-plugins-cookies</artifactId>
    <version>{{spincastCurrrentVersion}}</version>
</dependency> 
                        
                      
                
                
                    
                    You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:
                    
                        
                            
Injector guice = Guice.createInjector(
        new SpincastCoreGuiceModule(args),
        new SpincastCookiesPluginGuiceModule(IAppRequestContext.class)
        // other modules...
        ); 
                        
                       
                
                
                    ... or by using the install(...) method from your custom Guice module:
                    
                        
                            
public class AppModule extends SpincastCoreGuiceModule {
    @Override
    protected void configure() {
        super.configure();
        install(new SpincastCookiesPluginGuiceModule(getRequestContextType()));
        // other modules...
    }
    
    // ...
} 
                        
                       
                
             
            
            
                
                    
                    The request context add-on
                
                
                    
                        
                            
                                
 Quick example :
                                public void myHandler(IAppRequestContext context) {
    ICookie myCookie = context.cookies().getCookie("myCookie");
    if(myCookie != null) {
        System.out.println(myCookie.getName() + " : " + myCookie.getValue());
    }
    //...
} 
                            
                        
                    
                
                
                    
                        
 Methods :
                        
                        
                        
                        
     
- 
    
Map<String, ICookie> getCookies()
    
        Gets the current cookies in a Map, using their names as the keys.
    
 
- 
    
ICookie getCookie(String name)
    
        Gets a cookie.
        
    
 
- 
    
void addCookie(ICookie cookie)
    
        Adds a cookie.
    
 
- 
    
void addCookie(String name, String value)
    
        Adds a cookie using the specified name and value.
    
 
- 
    
void addCookie(String name, String value, String path, String domain, Date expires, boolean secure,                           boolean httpOnly, boolean discard, int version)
    
        Adds a cookie, using all possible configurations.
    
 
- 
    
void deleteCookie(String name)
    
        Deletes a cookie. In fact, this sets the cookie's expires date in the
 past so the user's browser will remove it.
 isExpired() will return true after you called
 this method.
    
 
- 
    
void deleteAllCookies()
    
        Deletes all cookies. In fact, this sets their expires date in the
 past so the user's browser will remove them.
    
 
- 
    
void resetCookies()
    
        Resets the current cookies to the original ones
 of the request.
    
 
                            
                        
                    
                
             
            
            
            
        
    
    
 
{% endblock %}    
 Spincast Cookies