View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.gateway.kernel;
21  
22  import java.util.LinkedHashMap;
23  import java.util.Map;
24  
25  /**
26   *
27   */
28  public abstract class AbstractHttpBusinessRequest {
29    protected final LinkedHashMap<String, AbstractHttpField> fields;
30    protected final HttpPage page;
31  
32    /**
33     * Default constructor
34     *
35     * @param fields
36     * @param page
37     */
38    protected AbstractHttpBusinessRequest(
39        final LinkedHashMap<String, AbstractHttpField> fields,
40        final HttpPage page) {
41      this.fields = fields;
42      this.page = page;
43    }
44  
45    /**
46     * @return the Map<String, AbstractHttpField> associated with the
47     *     current request
48     */
49    public final Map<String, AbstractHttpField> getMapHttpFields() {
50      return fields;
51    }
52  
53    /**
54     * @return the HTML header or null if set through definition
55     */
56    public abstract String getHeader();
57  
58    /**
59     * @return the HTML Footer or null if set through definition
60     */
61    public abstract String getFooter();
62  
63    /**
64     * @return True if the HTML output will be a Form
65     */
66    public abstract boolean isForm();
67  
68    /**
69     * @return the HTML Begin of Form (including URI) or null if set through
70     *     definition
71     */
72    public abstract String getBeginForm();
73  
74    /**
75     * @return the HTML End of Form or null if set through definition
76     */
77    public abstract String getEndForm();
78  
79    /**
80     * @param field
81     *
82     * @return the HTML field form or null if set standard
83     */
84    public abstract String getFieldForm(AbstractHttpField field);
85  
86    /**
87     * @return the HTML Next Field in Form or null if set through definition
88     */
89    public abstract String getNextFieldInForm();
90  
91    /**
92     * Called if fieldtovalidate is true
93     *
94     * @param field
95     *
96     * @return True if the field is valid
97     */
98    public abstract boolean isFieldValid(AbstractHttpField field);
99  
100   /**
101    * Note that mandatory fields is tested outside of the
102    * AbstractHttpBusinessRequest
103    *
104    * @return True if according to known informations this request is valid
105    */
106   public abstract boolean isRequestValid();
107 
108   /**
109    * @return the string that contains the ContentType in HTML format (as
110    *     "text/html")
111    */
112   public abstract String getContentType();
113 
114   /**
115    * Utility mainly used for PUT where the content is coming out of the
116    * decoder
117    *
118    * @return the main FileUpload as AbstractHttpField for the current request
119    */
120   public abstract AbstractHttpField getMainFileUpload();
121 
122   /**
123    * Used at the end of the request to release the resources
124    */
125   public final void cleanRequest() {
126     for (final AbstractHttpField field : fields.values()) {
127       field.clean();
128     }
129     fields.clear();
130   }
131 }