Ignore:
Timestamp:
12/18/13 09:51:19 (10 years ago)
Author:
keeloo
Message:
 
Location:
vlo/branches/to-wicket-1.6
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • vlo/branches/to-wicket-1.6/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/VloWebApplication.java

    r4021 r4199  
    1010import javax.servlet.ServletContext;
    1111import org.apache.wicket.Application;
    12 import org.apache.wicket.PageParameters;
    13 import org.apache.wicket.Request;
    1412import org.apache.wicket.RequestCycle;
     13import org.apache.wicket.request.RequestParameters;
    1514import org.apache.wicket.Response;
    1615import org.apache.wicket.protocol.http.WebApplication;
    1716import org.apache.wicket.protocol.http.WebRequest;
    1817import org.apache.wicket.protocol.http.WebRequestCycle;
    19 import org.apache.wicket.protocol.http.WebSession;
    20 import org.apache.wicket.request.RequestParameters;
     18import org.apache.wicket.protocol.http.WebResponse;
    2119
    2220/**
     
    3129   
    3230    /**
    33      * Customized client request cycle<br><br>
     31     * Customised client request cycle<br><br>
    3432     *
    3533     * <intercept resquest in order to update session parameter list>
    3634     *
    37      * Add behavior to the web request handling by retrieving persistent
     35     * Add behaviour to the web request handling by retrieving persistent
    3836     * parameters to the application from from client requests, and store
    3937     * the in the application object.
     
    4745
    4846        /**
    49          * Add the behavior to the beginning of the processing of a request
     47         * Add the behaviour to the beginning of the processing of a request
    5048         */
    5149        @Override
     
    6462            } else {
    6563                // check if the users requests a different theme
    66                 if (object[0].matches(((ThemedSession)getSession()).getCurrentTheme().name)) {
     64                if (object[0].matches(((VloSession)getSession()).getCurrentTheme().name)) {
    6765                    // current theme requested, nothing to do
    6866                } else {
    6967                    // different theme requested, compose it
    70                     ((ThemedSession)getSession()).setCurrentTheme(new Theme (object[0]));
    71                     // remember the theme as a persistent parameter
    72                     ((ThemedSession)getSession()).persistentParameters.put("theme", object[0]);
     68                    ((VloSession)getSession()).setCurrentTheme(new Theme (object[0]));
     69                    // remember the theme as a vlo session page parameter
     70                    ((VloSession)getSession()).vloSessionPageParameters.add("theme", object[0]);
    7371                }
    7472            }
    7573        }
    7674    }
    77 
    78     /**
    79      * Put the the customized request cycle up for installation<br><br>
    80      *
    81      * Note that casting the request to a WebRequest is assumed to be safe.
    82      *
    83      * @param request the request to be passed on the the new handler
    84      * @param response the response to be passed on the the new handler
    85      * @return the new handler
    86      */
    87     @Override
    88     public RequestCycle newRequestCycle(Request request, Response response){
    8975       
    90         /* Pass on the application object and  parameters to new the request
    91          * cycle when creating it.
    92          */
    93         CustomCycle cycle = new CustomCycle(this, (WebRequest)request, response);
    94        
    95         return cycle;
    96     }
    97    
    98     /**
    99      * Compose a map to be included in the HTML document, designating the
    100      * positions of the links to partner web sites
    101      *
    102      * @return
    103      */
    104     private String getClarinDPartnerLinkMap(){
    105         String map;
    106        
    107         map = "<map name=\"partnerLinks\">\n";
    108         map = map + "</map>";
    109        
    110         return map;
    111     }
    112    
    113     /**
    114      * Compose a map to be included in the HTML document, designating the
    115      * positions of the links to partner web sites
    116      *
    117      * @return
    118      */
    119     private String getDefaultPartnerLinkMap(){
    120         String map;
    121        
    122         map = "<map name=\"partnerLinks\">\n";
    123         map = appendToPartnerLinkMap (map,
    124                 "114.00,65,167.50,104",
    125                 "http://www.clarin.eu",
    126                 "clarin link");
    127         map = appendToPartnerLinkMap (map,
    128                 "177.00,65,214,104",
    129                 "http://wals.info",
    130                 "wals link");
    131         map = appendToPartnerLinkMap (map,
    132                 "229,65,279,104",
    133                 "http://linguistlist.org",
    134                 "linguistlist link");
    135         map = appendToPartnerLinkMap (map,
    136                 "290,65,320,104",
    137                 "http://www.elra.info",
    138                 "elra link");
    139         map = appendToPartnerLinkMap (map,
    140                 "328,65,370,104",
    141                 "http://www.mpi.nl/dobes",
    142                 "dobes link");
    143         map = appendToPartnerLinkMap (map,
    144                 "379,65,428,104",
    145                 "http://www.dfki.de/web",
    146                 "dfki link");
    147         map = appendToPartnerLinkMap (map,
    148                 "434,65,484,104",
    149                 "http://www.delaman.org",
    150                 "deleman link");
    151        
    152         map = map + "</map>";
    153        
    154         return map;
    155     }
    156    
    157     /**
    158      * Add a link location to the map indicating the partner links
    159      *
    160      * @param map
    161      * @return
    162      */
    163     private String appendToPartnerLinkMap(String map, String coordinates,
    164             String URL, String alt) {
    165        
    166         if (map == null) {
    167           map = "<map name=\"partnerLinks\">\n";
    168         } else if (map.equals("")) {
    169             map = "<map name=\"partnerLinks\">\n";
    170         }
    171        
    172         map = map + "<AREA SHAPE=\"rect\" COORDS=\"" + coordinates + "\" HREF=\"" +
    173                 URL + "\" alt=\"" + alt + "\"/>\n";
    174        
    175         return map;
    176     }
    177    
    178     public class ThemedSession extends WebSession {
    179        
    180         /**
    181          * Remember the parameters that should persist in URLs to VLO pages
    182          * <br><br>
    183          */
    184         public PageParameters persistentParameters = new PageParameters();
    185        
    186         /**
    187          *
    188          * @return
    189          */
    190         public PageParameters getPersistentParameters (){
    191             return persistentParameters;
    192         }
    193 
    194         /**
    195          * Reflect the persistent parameters in the page parameter map<br><br>
    196          *
    197          * @param parameters a page parameter map
    198          * @return the page parameter map including the current persistent
    199          * parameters
    200          */
    201         public PageParameters reflectPersistentParameters(PageParameters parameters) {
    202 
    203             parameters.putAll(persistentParameters);
    204 
    205             // parameters.add("theme", "defaultTheme");
    206             return parameters;
    207         }
    208 
    209         /**
    210          * Theme currently applied in the VLO web application
    211          */
    212         private Theme currentTheme = new Theme ("defaultTheme");
    213 
    214         public ThemedSession(Application application, Request request) {
    215             super(application, request);
    216         }
    217 
    218         public Theme getCurrentTheme() {
    219             return currentTheme;
    220         }
    221 
    222         public void setCurrentTheme(Theme currentTheme) {
    223             this.currentTheme = currentTheme;
    224         }
    225     }
    226    
    227 
    228     @Override
    229     public ThemedSession newSession(Request request, Response response) {
    230        
    231         return new ThemedSession(this, request);
    232     }
    233    
    234     /**
    235      * A theme is composed from a page title, a CSS file, two image files, and a
    236      * partner link map relating coordinates in the right image to partner links
    237      */
    238     public class Theme {
    239 
    240         public String name, pageTitle, topLeftImage, topRightImage, cssFile,
    241                 partnerLinkMap;
    242 
    243         /**
    244          * Compose a theme<br><br>
    245          *
    246          * @param name the name of the theme to be composed
    247          */
    248         public Theme(String themeName) {
    249            
    250             String prefix = VloConfig.getReverseProxyPrefix();
    251 
    252             if (themeName.matches("CLARIN-D")) {
    253                 // select the CLARIN-D theme's components
    254                
    255                 pageTitle = "CLARIN-D Virtual Language Observatory - Resources";
    256                 topLeftImage = "Images/topleft-clarin-d.png";
    257                 topRightImage = "Images/topright-clarin-d.png";
    258                 if (prefix.length() == 0) {
    259                     cssFile = "css/clarin-d.css";
    260                 } else {
    261                     cssFile = prefix + "css/clarin-d.css";
    262                 }
    263                 partnerLinkMap = getClarinDPartnerLinkMap();
    264                 name = "CLARIN-D";
    265             } else {
    266                 // select the default theme elements
    267                 pageTitle = "CLARIN Virtual Language Observatory - Resources";
    268                 topLeftImage = "Images/topleftvlo.gif";
    269                 topRightImage = "Images/toprightvlo.gif";
    270 
    271                 if (prefix.length() == 0) {
    272                     cssFile = "css/main.css";
    273                 } else {
    274                     cssFile = prefix + "css/main.css";
    275                 }
    276                 partnerLinkMap = getDefaultPartnerLinkMap();
    277                 name = "defaultTheme";
    278             }
    279             // remember the theme as a persistent parameter
    280             // getPersistentParameters.put("theme", name);
    281         }
    282     }
    283 
    28476    /**
    28577     * Flag indicating whether or not the application object lives in a web
     
    320112            VloContextConfig.switchToExternalConfig(servletContext);
    321113        }
     114       
     115        // install the custom request cycle
     116        WebRequest req = (WebRequest) RequestCycle.get().getRequest();
     117        WebResponse res = (WebResponse) RequestCycle.get().getResponse();
     118           
     119        CustomCycle cycle;
     120        cycle = new CustomCycle(this, req, res);
    322121
    323122        // creata an object referring to the search results
Note: See TracChangeset for help on using the changeset viewer.