Project

General

Profile

1
<?xml version="1.0" encoding="UTF-8"?>
2
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
3
    
4
    <!-- to change the content type or response encoding change the following line -->
5
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
6
    <jsp:directive.page import="edu.ucsb.nceas.metacat.client.MetacatClient"/>
7
    <jsp:directive.page import="edu.ucsb.nceas.metacat.client.MetacatFactory"/>
8
    
9
    
10
    
11
    <jsp:declaration>
12
        final String                        LDAP_DOMAIN = ",dc=ecoinformatics,dc=org";
13
        private String                      action, usr, pwd, posted_ldapUserName;
14
        private MetacatClient               metacatClient;
15
        private String                      metacatClientResponse, organization;
16
        private String                      doUploadResponse = "";
17
    </jsp:declaration>
18
    
19
    
20
    <html xmlns="http://www.w3.org/1999/xhtml">
21
        <head>
22
            
23
            <jsp:scriptlet>
24
                action = request.getParameter("loginAction");
25
                usr = request.getParameter("username");
26
                pwd = request.getParameter("password");
27
                organization = request.getParameter("organization");
28
                
29
                posted_ldapUserName = "uid=" + usr + ",o=" + organization + LDAP_DOMAIN;
30
                metacatClient = MetacatClient.getMetacatClient(request);
31
                
32
                if (action != null) {
33
                try {
34
                if (action.equals("Login")) {
35
                metacatClientResponse = metacatClient.login(posted_ldapUserName, pwd);
36
                metacatClient.setUser(usr, metacatClientResponse);
37
                } else if (action.equals("Logout")) {
38
                metacatClientResponse = metacatClient.logout();
39
                metacatClient.setUser(usr, metacatClientResponse);
40
                }
41
                } catch (Exception ex) {
42
                System.out.println("*** SaeonLogin.jspx ***\n" + ex);
43
                if (action == null)
44
                System.out.println(" ---> action is null");
45
                else if (metacatClient == null)
46
                System.out.println(" ---> metacatClient is null");
47
                else if (usr == null)
48
                System.out.println(" ---> usr is null");
49
                }
50
                } else {
51
                try {
52
                doUploadResponse = metacatClient.doMetadataUpload(request);
53
                } catch (Exception ex) {
54
                System.out.println("SaeonUpload.jspx, jsp scriptlet exception thrown:  " + ex.getMessage());
55
                }
56
                }
57
            </jsp:scriptlet>
58
            
59
            <script type="text/javascript">
60
                
61
                function allowSubmit(formObj) {
62
                    var     result = true;
63
                    var     action = "";
64

    
65
                    action = trim(formObj.elements["loginAction"].value);
66
                    if (action == "Login") {
67
                        if (isEmpty(formObj.elements["username"])) {
68
                            result = false;
69
                            alert("User name is required");
70
                        } else if (isEmpty(formObj.elements["organization"])) {
71
                            result = false;
72
                            alert("Organization is required");
73
                        } else if (isEmpty(formObj.elements["password"])) {
74
                            result = false;
75
                            alert("Password is required");
76
                        }
77
                    }
78
                    
79
                    return(result);
80
                }
81
                
82
                function isEmpty(aTextField) {
83
                    var value = trim(aTextField.value);
84
                    var result = ((value.length == 0) || (value == null));
85
                    return(result);
86
                }
87

    
88
		function trim(stringToTrim) {
89
			return(stringToTrim.replace(/^\s+|\s+$/g,""));
90
		}
91
                
92
                function frameExists(frameName) {
93
                    var result = false;
94
                    
95
                    for (var i=0; i &lt; parent.frames.length ;i++) {
96
                        if (parent.frames[i].name == frameName)
97
                         result = true;
98
                    }
99
                    return(result);
100
                }
101
                
102
                function allowUploadSubmit(formObj) {
103
                    var     result = true;
104

    
105
                        if (isEmpty(formObj.elements["fileName"])) {
106
                            result = false;
107
                            alert("Complete file name is required");
108
                        }
109
                    }
110
                    return(result);
111
                }
112
            </script>
113
            
114
            <title>SANParks - Kruger National Park Data Repository</title>
115
            <link href="knp.css" rel="stylesheet" type="text/css"/>
116
            
117
        </head>
118
        <body>
119
            <br/>
120
            <li>Login
121
                <jsp:scriptlet>
122
                    if (!metacatClient.isLoggedIn()) {
123
                </jsp:scriptlet>
124
                <form name="loginForm" method="post" action="SaeonLogin.jspx" onsubmit="return allowSubmit(this)">
125
                    <input name="qformat" value="knp" type="hidden"/>
126
                    <table>
127
                        <tr>
128
                            <td>
129
                                <span class="required">User name</span>
130
                            </td>
131
                            <td>
132
                                <input name="username" value="" type="text" style="width: 140"/>
133
                            </td>
134
                            <td rowspan="3" class="regtext" align="right" valign="top" style="width: 160" >
135
                                <div>
136
                                    <!-- Config param follows -->
137
                                    <a href="http://localhost:8084/cgiScripts/cgi-bin/ldapweb.cgi" target="_parent">create a new account</a>
138
                                </div>
139
                            </td>
140
                        </tr>
141
                        <tr>
142
                            <td>
143
                                <span class="required">Organization</span>
144
                            </td>
145
                            <td>
146
                                <select name="organization" style="width: 140">
147
                                    <option value="SANParks" selected="">SANParks</option>
148
                                    <option value="SAEON">SAEON</option>
149
                                    <option value="NCEAS">NCEAS</option>
150
                                    <option value="unaffiliated">unaffiliated</option>
151
                                </select>
152
                            </td>
153
                        </tr>
154
                        <tr>
155
                            <td>
156
                                <span class="required">Password</span>
157
                            </td>
158
                            <td>
159
                                <input name="password" value="" type="password" style="width: 140" maxlength="50"/>
160
                            </td>
161
                        </tr>
162
                        <tr>
163
                            <td colspan="2" align="center">
164
                                <input name="loginAction" value="Login" type="submit" class="button_login"/>
165
                            </td>
166
                        </tr>
167
                    </table>
168
                </form>
169
                <jsp:scriptlet>
170
                    } else {
171
                    metacatClient.setLoginResponse(metacatClientResponse);
172
                </jsp:scriptlet>
173
                <form name="logoutForm" method="post" action="SaeonLogin.jspx">
174
                    <input name="qformat" value="knp" type="hidden"/>
175
                    <table>
176
                        <tr>
177
                            <td>
178
                                <div class="regtext">Account: <jsp:expression>metacatClient.getLoginResponseElement("name")</jsp:expression></div>
179
                            </td>
180
                            <td rowspan="2" class="regtext" align="right" valign="top" style="width: 160" >
181
                                <div>
182
                                    <!-- Config param follows -->
183
                                    <a href="http://localhost:8084/cgiScripts/cgi-bin/ldapweb.cgi?stage=resetpass" target="_parent">reset your password</a>
184
                                </div>
185
                                <div>
186
                                    <!-- Config param follows -->
187
                                    <a href="http://localhost:8084/cgiScripts/cgi-bin/ldapweb.cgi?stage=changepass" target="_parent">change your password</a>
188
                                </div>
189
                            </td>
190
                        </tr>
191
                        <tr>
192
                            <td>
193
                                <p class="regtext"><jsp:expression>metacatClient.getLoginResponseElement("message")</jsp:expression></p>
194
                            </td>
195
                        </tr>
196
                        <tr>
197
                            <td align="center">
198
                                <input name="loginAction" value="Logout" type="submit" class="button_login"/>
199
                            </td>
200
                        </tr>
201
                    </table>
202
                </form>
203
                <jsp:scriptlet>
204
                    }
205
                </jsp:scriptlet>
206
                
207
                <!-- File Upload Form -->
208
                <br/>
209
                <br/>
210
            </li>
211
            <li>Data Package Upload
212
                <br/>
213
                <jsp:scriptlet>
214
                    if (metacatClient == null || !metacatClient.isLoggedIn()) {
215
                </jsp:scriptlet>
216
                <div class="regtext">
217
                    You must be logged into your user account before uploading a data set.
218
                </div>
219
                <jsp:scriptlet>
220
                    } else {
221
                </jsp:scriptlet>
222
                <form name="uploadForm" method="post" action="SaeonLogin.jspx" enctype="multipart/form-data" 
223
                      onsubmit="return allowSubmit(this)">
224
                    <table>
225
                        <tr>
226
                            <td colspan="2">
227
                                <p class="regtext">Enter the Meta Data File (required)</p>
228
                            </td>
229
                        </tr>
230
                        <tr>
231
                            <td>
232
                                <input name="fileName" accept="xml" type="file" size="60" />
233
                            </td>
234
                        </tr>
235
                        <!-- Data fields -->
236
                        <tr>
237
                            <td colspan="2">
238
                                <p class="regtext">Enter Data File 1 (optional)</p>
239
                            </td>
240
                        </tr>
241
                        <tr>
242
                            <td colspan="2">
243
                                <input name="dataFileName1" type="file" size="60" />
244
                            </td>
245
                        </tr>
246
                        <tr>
247
                            <td colspan="2">
248
                                <p class="regtext">Enter Data File 2 (optional)</p>
249
                            </td>
250
                        </tr>
251
                        <tr>
252
                            <td colspan="2">
253
                                <input name="dataFileName2" type="file" size="60" />
254
                            </td>
255
                        </tr>
256
                        <tr>
257
                            <td colspan="2">
258
                                <p class="regtext">Enter Data File 3 (optional)</p>
259
                            </td>
260
                        </tr>
261
                        <tr>
262
                            <td colspan="2">
263
                                <input name="dataFileName3" type="file" size="60" />
264
                            </td>
265
                        </tr>
266
                        <tr>
267
                            <td colspan="2">
268
                                <p class="regtext">Enter Data File 4 (optional)</p>
269
                            </td>
270
                        </tr>
271
                        <tr>
272
                            <td colspan="2">
273
                                <input name="dataFileName4" type="file" size="60" />
274
                            </td>
275
                        </tr>
276
                        <tr>
277
                            <td colspan="2">
278
                                <p class="regtext">Enter Data File 5 (optional)</p>
279
                            </td>
280
                        </tr>
281
                        <tr>
282
                            <td colspan="2">
283
                                <input name="dataFileName5" type="file" size="60" />
284
                            </td>
285
                        </tr>
286
                        <tr>
287
                            <td align="left">
288
                                <span class="regtext"><jsp:expression>doUploadResponse</jsp:expression></span>
289
                            </td>
290
                            <td align="right">
291
                                <input name="uploadAction" value="Upload" type="submit" class="button_login"/>
292
                            </td>
293
                        </tr>
294
                    </table>
295
                </form>
296
                <jsp:scriptlet>
297
                    }
298
                </jsp:scriptlet>
299
            </li>
300
        </body>
301
    </html>
302
</jsp:root>
(1-1/10)