openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

CMSAction.java (1726B)


      1 package de.openrat.client.action;
      2 
      3 import de.openrat.client.util.CMSConnection;
      4 import de.openrat.client.util.CMSException;
      5 import de.openrat.client.util.CMSNode;
      6 import de.openrat.client.util.CMSResponse;
      7 import de.openrat.client.util.HttpRequest.HttpMethod;
      8 
      9 import javax.security.auth.login.LoginException;
     10 import java.util.Map;
     11 
     12 /**
     13  * This class is NOT threadsafe and should be used by one thread simultaneously.
     14  *
     15  * @author dankert
     16  */
     17 public class CMSAction extends Action {
     18 
     19     public CMSAction(CMSConnection connection) {
     20 
     21         super(connection);
     22     }
     23 
     24     /**
     25      * Custom method call.
     26      *
     27      * @return CMSNode
     28      */
     29     public CMSNode executeView(String action, String method, Map<String, String> parameter) {
     30 
     31         return execute(action,method,parameter,HttpMethod.GET);
     32     }
     33     /**
     34      * Custom method call.
     35      *
     36      * @return CMSNode
     37      */
     38     public CMSNode executePost(String action, String method, Map<String, String> parameter) {
     39 
     40         return execute(action,method,parameter,HttpMethod.POST);
     41     }
     42 
     43 
     44     /**
     45      * Custom method call.
     46      *
     47      * @return CMSNode
     48      */
     49     private CMSNode execute(String action, String method, Map<String, String> parameter,HttpMethod httpMethod) {
     50 
     51         clear();
     52 
     53         for (Map.Entry<String, String> entry : parameter.entrySet())
     54             setParameter(entry.getKey(), entry.getValue());
     55 
     56         try {
     57             CMSResponse response;
     58             if( httpMethod.equals(HttpMethod.GET))
     59                 response = executeView(action, method);
     60             else
     61                 response = executePost(action, method);
     62             return response.getOutput();
     63         } catch (CMSException e) {
     64             throw e;
     65         }
     66     }
     67 }