Coverage Report - pt.digitalis.dif.controller.objects.DIFRequest
 
Classes in this File Line Coverage Branch Coverage Complexity
DIFRequest
0%
0/79
0%
0/6
1,094
 
 1  0
 /**
 2  
  * - Digitalis Internal Framework v2.0 - (C) 2007, Digitalis Informatica. Distribuicao e Gestao de Informatica, Lda.
 3  
  * Estrada de Paco de Arcos num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999
 4  
  * http://www.digitalis.pt
 5  
  */
 6  
 package pt.digitalis.dif.controller.objects;
 7  
 
 8  
 import java.util.HashMap;
 9  
 import java.util.Map;
 10  
 import java.util.Map.Entry;
 11  
 
 12  
 import pt.digitalis.dif.controller.interfaces.IDIFRequest;
 13  
 import pt.digitalis.dif.controller.interfaces.IDIFSession;
 14  
 import pt.digitalis.dif.dem.interfaces.IStage;
 15  
 import pt.digitalis.dif.dem.managers.IDEMManager;
 16  
 import pt.digitalis.dif.ioc.DIFIoCRegistry;
 17  
 import pt.digitalis.dif.utils.ObjectFormatter;
 18  
 
 19  
 /**
 20  
  * Implementation for {@link IDIFRequest}.
 21  
  * 
 22  
  * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
 23  
  * @author Luis Pinto <a href="mailto:lpinto@digitalis.pt">lpinto@digitalis.pt</a>
 24  
  * @created 2007/03/16
 25  
  */
 26  0
 public class DIFRequest implements IDIFRequest {
 27  
 
 28  
     /** The key to the original request stored as an attribute. */
 29  
     final static public String ORIGINAL_REQUEST = "originalRequest";
 30  
 
 31  
     /** Ajax mode, false by default */
 32  0
     private boolean ajaxMode = false;
 33  
 
 34  
     /**
 35  
      * The attribute collection with the values from the original request.
 36  
      */
 37  0
     private Map<String, Object> attributes = new HashMap<String, Object>();
 38  
 
 39  
     /** The descriptor of the client */
 40  
     private ClientDescriptor client;
 41  
 
 42  
     /** Component mode, false by default */
 43  0
     private boolean componentMode = false;
 44  
 
 45  
     /** The requested response format. */
 46  
     private String format;
 47  
 
 48  
     /** Help mode, false by default */
 49  0
     private boolean helpMode = false;
 50  
 
 51  
     /**
 52  
      * The parameter collection with the values from the original request
 53  
      */
 54  0
     private Map<String, Object> parameters = new HashMap<String, Object>();
 55  
 
 56  
     /** Popup mode, false by default */
 57  0
     private boolean popupMode = false;
 58  
 
 59  
     /** REST action, if set in request */
 60  0
     RESTAction restAction = null;
 61  
 
 62  
     /** REST call, false by default */
 63  0
     private boolean restCall = false;
 64  
 
 65  
     /** The requested stage. */
 66  
     private String stage;
 67  
 
 68  
     /** Template mode, false by default */
 69  0
     private boolean templateMode = false;
 70  
 
 71  
     /** The session. */
 72  
     private IDIFSession theSession;
 73  
 
 74  
     /**
 75  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#addAttribute(String, Object)
 76  
      */
 77  
     public void addAttribute(String attributeName, Object attributeValue)
 78  
     {
 79  0
         attributes.put(attributeName, attributeValue);
 80  0
     }
 81  
 
 82  
     /**
 83  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#addParameter(String, Object)
 84  
      */
 85  
     public void addParameter(String parameterName, Object parameterValue)
 86  
     {
 87  0
         parameters.put(parameterName.toLowerCase(), parameterValue);
 88  0
     }
 89  
 
 90  
     /**
 91  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getAttribute(java.lang.String)
 92  
      */
 93  
     public Object getAttribute(String name)
 94  
     {
 95  0
         return this.attributes.get(name);
 96  
     }
 97  
 
 98  
     /**
 99  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getAttributes()
 100  
      */
 101  
     public Map<String, Object> getAttributes()
 102  
     {
 103  0
         return this.attributes;
 104  
     }
 105  
 
 106  
     /**
 107  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getClient()
 108  
      */
 109  
     public ClientDescriptor getClient()
 110  
     {
 111  0
         return client;
 112  
     }
 113  
 
 114  
     /**
 115  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getFormat()
 116  
      */
 117  
     public String getFormat()
 118  
     {
 119  0
         return format;
 120  
     }
 121  
 
 122  
     /**
 123  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getParameter(java.lang.String)
 124  
      */
 125  
     public Object getParameter(String name)
 126  
     {
 127  0
         return this.parameters.get(name.toLowerCase());
 128  
     }
 129  
 
 130  
     /**
 131  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getParameters()
 132  
      */
 133  
     public Map<String, Object> getParameters()
 134  
     {
 135  0
         return this.parameters;
 136  
     }
 137  
 
 138  
     /**
 139  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getRestAction()
 140  
      */
 141  
     public RESTAction getRestAction()
 142  
     {
 143  0
         return restAction;
 144  
     }
 145  
 
 146  
     /**
 147  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getSession()
 148  
      */
 149  
     public IDIFSession getSession()
 150  
     {
 151  0
         return this.theSession;
 152  
     }
 153  
 
 154  
     /**
 155  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getStage()
 156  
      */
 157  
     public String getStage()
 158  
     {
 159  0
         return stage;
 160  
     }
 161  
 
 162  
     /**
 163  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#getStageProxy()
 164  
      */
 165  
     public IStage getStageProxy()
 166  
     {
 167  0
         return DIFIoCRegistry.getRegistry().getImplementation(IDEMManager.class).getStage(getStage());
 168  
     }
 169  
 
 170  
     /**
 171  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#isAjaxMode()
 172  
      */
 173  
     public boolean isAjaxMode()
 174  
     {
 175  0
         return ajaxMode;
 176  
     }
 177  
 
 178  
     /**
 179  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#isComponentMode()
 180  
      */
 181  
     public boolean isComponentMode()
 182  
     {
 183  0
         return componentMode;
 184  
     }
 185  
 
 186  
     /**
 187  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#isHelpMode()
 188  
      */
 189  
     public boolean isHelpMode()
 190  
     {
 191  0
         return helpMode;
 192  
     }
 193  
 
 194  
     /**
 195  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#isPopupMode()
 196  
      */
 197  
     public boolean isPopupMode()
 198  
     {
 199  0
         return popupMode;
 200  
     }
 201  
 
 202  
     /**
 203  
      * Inspector for the 'restCall' attribute.
 204  
      * 
 205  
      * @return the restCall value
 206  
      */
 207  
     public boolean isRestCall()
 208  
     {
 209  0
         return restCall;
 210  
     }
 211  
 
 212  
     /**
 213  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#isTemplateMode()
 214  
      */
 215  
     public boolean isTemplateMode()
 216  
     {
 217  0
         return templateMode;
 218  
     }
 219  
 
 220  
     /**
 221  
      * Modifier for the 'ajaxMode' attribute.
 222  
      * 
 223  
      * @param ajaxMode
 224  
      *            the new ajaxMode value to set
 225  
      */
 226  
     public void setAjaxMode(boolean ajaxMode)
 227  
     {
 228  0
         this.ajaxMode = ajaxMode;
 229  0
     }
 230  
 
 231  
     /**
 232  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setAttributes(Map)
 233  
      */
 234  
     public void setAttributes(Map<String, Object> attributes)
 235  
     {
 236  0
         this.attributes = attributes;
 237  0
     }
 238  
 
 239  
     /**
 240  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setClient(ClientDescriptor)
 241  
      */
 242  
     public void setClient(ClientDescriptor client)
 243  
     {
 244  0
         this.client = client;
 245  0
     }
 246  
 
 247  
     /**
 248  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setComponentMode(boolean)
 249  
      */
 250  
     public void setComponentMode(boolean componentMode)
 251  
     {
 252  0
         this.componentMode = componentMode;
 253  0
     }
 254  
 
 255  
     /**
 256  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setFormat(java.lang.String)
 257  
      */
 258  
     public void setFormat(String format)
 259  
     {
 260  0
         this.format = format;
 261  0
     }
 262  
 
 263  
     /**
 264  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setHelpMode(boolean)
 265  
      */
 266  
     public void setHelpMode(boolean helpMode)
 267  
     {
 268  0
         this.helpMode = helpMode;
 269  0
     }
 270  
 
 271  
     /**
 272  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setParameters(Map)
 273  
      */
 274  
     public void setParameters(Map<String, Object> parameters)
 275  
     {
 276  0
         for (Entry<String, Object> entry: parameters.entrySet())
 277  0
             addParameter(entry.getKey().toLowerCase(), entry.getValue());
 278  0
     }
 279  
 
 280  
     /**
 281  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setPopupMode(boolean)
 282  
      */
 283  
     public void setPopupMode(boolean popupMode)
 284  
     {
 285  0
         this.popupMode = popupMode;
 286  0
     }
 287  
 
 288  
     /**
 289  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setRestAction(pt.digitalis.dif.controller.objects.RESTAction)
 290  
      */
 291  
     public void setRestAction(RESTAction restAction)
 292  
     {
 293  0
         this.restAction = restAction;
 294  0
     }
 295  
 
 296  
     /**
 297  
      * Modifier for the 'restCall' attribute.
 298  
      * 
 299  
      * @param restCall
 300  
      *            the new restCall value to set
 301  
      */
 302  
     public void setRestCall(boolean restCall)
 303  
     {
 304  0
         this.restCall = restCall;
 305  0
     }
 306  
 
 307  
     /**
 308  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setSession(pt.digitalis.dif.controller.interfaces.IDIFSession)
 309  
      */
 310  
     public void setSession(IDIFSession session)
 311  
     {
 312  0
         this.theSession = session;
 313  
 
 314  0
     }
 315  
 
 316  
     /**
 317  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setStage(String)
 318  
      */
 319  
     public void setStage(String newStage)
 320  
     {
 321  0
         this.stage = newStage;
 322  0
     }
 323  
 
 324  
     /**
 325  
      * @see pt.digitalis.dif.controller.interfaces.IDIFRequest#setTemplateMode(boolean)
 326  
      */
 327  
     public void setTemplateMode(boolean templateMode)
 328  
     {
 329  0
         this.templateMode = templateMode;
 330  0
     }
 331  
 
 332  
     /**
 333  
      * Returns the Request object in a human-readable form.
 334  
      * 
 335  
      * @see java.lang.Object#toString()
 336  
      */
 337  
     @Override
 338  
     public String toString()
 339  
     {
 340  
 
 341  0
         ObjectFormatter formatter = new ObjectFormatter();
 342  0
         formatter.addItem("Client", client);
 343  0
         formatter.addItem("stage", stage);
 344  0
         formatter.addItem("Template Mode", templateMode);
 345  0
         formatter.addItem("Component Mode", componentMode);
 346  0
         formatter.addItem("Popup Mode", isPopupMode());
 347  0
         formatter.addItem("REST URL Mode", isRestCall());
 348  0
         formatter.addItem("Help Mode", helpMode);
 349  0
         formatter.addItem("Session", theSession);
 350  
 
 351  0
         Map<String, Object> allowedAttributes = new HashMap<String, Object>();
 352  0
         allowedAttributes.putAll(attributes);
 353  0
         allowedAttributes.remove("PageContentAttribute");
 354  0
         formatter.addItem("Attributes", allowedAttributes);
 355  
 
 356  0
         Map<String, Object> allowedParams = new HashMap<String, Object>();
 357  0
         allowedParams.putAll(parameters);
 358  0
         if (allowedParams.containsKey(PASSWORD_PARAMETER_ID))
 359  0
             allowedParams.put(PASSWORD_PARAMETER_ID, "*****");
 360  0
         if (allowedParams.containsKey("password"))
 361  0
             allowedParams.put("password", "*****");
 362  0
         formatter.addItem("Parameters", allowedParams);
 363  
 
 364  0
         return formatter.getFormatedObject();
 365  
     }
 366  
 }