Project

General

Profile

« Previous | Next » 

Revision 311

Added by bojilova over 24 years ago

Added support for "anonymous" user

View differences:

lib/queform.html
1
<!--
2
  * queform.html
3
  *
4
  *      Authors: Jivka Bojilova
5
  *    Copyright: 2000 Regents of the University of California and the
6
  *               National Center for Ecological Analysis and Synthesis
7
  *  For Details: http://www.nceas.ucsb.edu/
8
  *      Created: 2000 April 5
9
  *      Version: 0.01
10
  *    File Info: '$Id$'
11
  * 
12
  * This is an HTML document for displaying examples of the use of 
13
  * Oracle XML tools for query only
14
-->
15
<html>
16
<head>
17
<title>MetaCat</title>
18
</head>
19
<body bgcolor="white">
20
<table width="100%">
21
<tr><td colspan="2">
22
<b>MetaCat Query</b> -- a simple database query against MetaCat
23
</td></tr>
24
<tr><td width="40%" valign="top">
25
<form action="/servlets/MetaCatServlet" target="right" method="POST">
26
  <input type="hidden" name="action" value="query">
27
  <input type="text" name="query" value="NCEAS%" size="15">
28
  <input type="submit" value="Run query"><br />
29
  Format: 
30
  <input type="radio" name="qformat" value="xml">XML
31
  <input type="radio" name="qformat" value="html" checked>HTML
32
  <br />
33
  Return: &nbsp;
34
  <select name=doctype>
35
  <option value="-//NCEAS//eml-dataset//EN">eml-dataset
36
  <option value="any">Any
37
  </select>
38
</form>
39
</td>
40
<td valign="top">
41
<font size="-1">
42
For the test database, some valid values for the search that produce document
43
results include "Value1" and "lakename" and maybe "122W"
44
<p>
45
To view results that are XML formatted in this demo, it is easiest to use 
46
Internet Explorer 5. Although Netscape browsers will allow you to 
47
download XML documents, only IE5 will display XML at this time.
48
</font>
49
</td>
50
</tr>
51
</table>
52
</body>
53
</html>
0 54

  
lib/sexpire.html
9 9
  *      Version: 0.01
10 10
  *    File Info: '$Id$'
11 11
  * 
12
  * This is an HTML document for displaying metadata catalog tools
12
  * This is an HTML document for showing session expiration message
13 13
-->
14 14
<HTML>
15 15
<HEAD>
lib/query.html
1
<!--
2
  * query.html
3
  *
4
  *      Authors: Jivka Bojilova
5
  *    Copyright: 2000 Regents of the University of California and the
6
  *               National Center for Ecological Analysis and Synthesis
7
  *  For Details: http://www.nceas.ucsb.edu/
8
  *      Created: 2000 April 5
9
  *      Version: 0.01
10
  *    File Info: '$Id$'
11
  * 
12
  * This is an HTML document for displaying metadata catalog tools
13
-->
14
  <HTML>
15
  <HEAD>
16
  <TITLE>MetaCat</TITLE>
17
  </HEAD> 
18
  <FRAMESET COLS="*" FRAMEBORDER=0 BORDER=0>
19

  
20
    <FRAMESET ROWS="165,*"  FRAMEBORDER=0 BORDER=0>
21
    
22
    <FRAME SRC="queform.html" BORDER=0 NAME="left">
23

  
24
    <FRAME SRC="/servlets/MetaCatServlet?action=query&query=NCEAS%25&qformat=html&doctype=-//NCEAS//eml-dataset//EN" BORDER=0 NAME="right">
25

  
26
    </FRAMESET>
27
  </FRAMESET>
0 28

  
lib/login.html
9 9
  *      Version: 0.01
10 10
  *    File Info: '$Id$'
11 11
  * 
12
  * This is an HTML document for displaying metadata catalog tools
12
  * This is an HTML document for login to MetaCat
13 13
-->
14 14
<HTML>
15 15
<HEAD>
16 16
<TITLE>MetaCat</TITLE>
17
<script language="JavaScript">
18
   function PutFocus(theForm) {
19
	theForm.Go.focus()
20
   }
21
</script>
17 22
</HEAD>
18
<BODY bgcolor="#FFFFFF">
23
<BODY bgcolor="#FFFFFF" onLoad="PutFocus(document.forms[0]);">
19 24

  
20 25
  <P>&nbsp;
21
  <P>
26

  
22 27
  <FORM ACTION="/servlets/MetaCatServlet" METHOD="POST">
28
    Login as "anonymous" user in <b>MetaCat</b>
23 29
    <INPUT TYPE="hidden" NAME="action" VALUE="Login">
24
    <P>Username
30
    <INPUT TYPE="hidden" NAME="username" VALUE="anonymous">
31
    <INPUT TYPE="hidden" NAME="password">
32
    <INPUT TYPE="submit" NAME="Go" VALUE=" Go ">
33
  </FORM>
34

  
35
  <HR WIDTH="300" ALIGN="left">
36

  
37
  <FORM ACTION="/servlets/MetaCatServlet" METHOD="POST">
38
    Login as registered user in <b>MetaCat</b>
39
    <INPUT TYPE="hidden" NAME="action" VALUE="Login">
40
    <P>Username &nbsp;&nbsp;&nbsp;
25 41
    <INPUT TYPE="text" NAME="username" SIZE="15">
26
    <P>Password
27
    <INPUT TYPE="password" NAME="password" SIZE="15">
28
    <P>
29
    <INPUT TYPE="submit" VALUE="Login">
42
    <P>Password &nbsp;&nbsp;&nbsp;
43
    <INPUT TYPE="password" NAME="password" SIZE="15">&nbsp;&nbsp;&nbsp;
44
    <INPUT TYPE="submit" VALUE=" Login ">
30 45
  </FORM>
31 46

  
32 47
</BODY>
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
80 80
  private ServletConfig		config = null;
81 81
  private ServletContext	context = null;
82 82
  private Hashtable 		connectionPool = new Hashtable();
83
  //private connection  conn = null;
84
  //private DBQuery		queryobj = null;
85
  //private DBReader    docreader = null;
86
  //private DBTransform dbt = null;
87
  //private DBUtil      dbutil = null;
88 83
  private String 		resultStyleURL = null;
89 84
  private String 		xmlcatalogfile = null;
90 85
  private String 		saxparser = null;
......
124 119
        System.err.println("Error creating pool of database connections");
125 120
        System.err.println(e.getMessage());
126 121
      }
127
/*
128
      try {
129
        // Open a connection to the database
130
        conn = util.openDBConnection();
131

  
132
        queryobj = new DBQuery(conn,saxparser);
133
        docreader = new DBReader(conn);
134
        dbt = new DBTransform(conn);
135
        dbutil = new DBUtil(conn);
136

  
137
      } catch (Exception e) {
138
        System.err.println("Error creating pool of database connections");
139
        System.err.println(e.getMessage());
140
      }
141
*/
142 122
    } catch ( ServletException ex ) {
143 123
      throw ex;
144 124
    }
......
179 159
        System.err.println(e.getMessage());
180 160
      }
181 161
    }    
182
/*    
183
    if (conn == null) {
184
      System.err.println("Connection to database lost.  Reopening...");
185
      try {
186
        // Open a connection to the database
187
        conn = util.openDBConnection();
188
  
189
        queryobj = new DBQuery(conn, saxparser);
190
        docreader = new DBReader(conn);
191
        dbt = new DBTransform(conn);
192
        dbutil = new DBUtil(conn);
193
  
194
      } catch (Exception e) {
195
        System.err.println("Error opening database connection");
196
      }
197
    }
198
*/
199 162
    // Get a handle to the output stream back to the client
200 163
    PrintWriter out = response.getWriter();
201 164
    //response.setContentType("text/html");
......
246 209
    }
247 210

  
248 211
// Jivka added  
212
    String username = null;
249 213
    // handle login action
250 214
    if (action.equals("Login") || action.equals("Login Client")) {
251 215
      handleLoginAction(out, params, request, response);
......
256 220
      response.sendRedirect("/xmltodb/lib/login.html"); 
257 221
    // aware of session expiration on every request  
258 222
    } else {    
259
      //HttpSession sess = request.getSession(false);
260
      HttpSession sess = request.getSession(true);
223
      HttpSession sess = request.getSession(false);
224
      //HttpSession sess = request.getSession(true);
261 225
      if (sess == null) { 
262 226
        // session expired or has not been stored b/w user requests
263 227
        // redirect to session expiration message page
264 228
        response.sendRedirect("/xmltodb/lib/sexpire.html"); 
265 229
      }
230
      username = (String)sess.getValue("username");
266 231
    }    
267 232
// End of Jivka added
268 233

  
......
277 242
        out.println(se.getMessage());
278 243
      }
279 244
    } else if (action.equals("insert") || action.equals("update")) {
280
      handleInsertOrUpdateAction(out, params, response);
245
      if ( username == "anonymous" ) {
246
        out.println("You are not authorized to use that option.");
247
      } else {
248
        handleInsertOrUpdateAction(out, params, response);
249
      }
281 250
    } else if (action.equals("delete")) {
282
      handleDeleteAction(out, params, response);
251
      if ( username == "anonymous" ) {
252
        out.println("You are not authorized to use that option");
253
      } else {
254
        handleDeleteAction(out, params, response);
255
      }
283 256
    } else if (action.equals("validate")) {
284
      handleValidateAction(out, params, response);  
257
      if ( username == "anonymous" ) {
258
        out.println("You are not authorized to use that option");
259
      } else {
260
        handleValidateAction(out, params, response);  
261
      }
285 262
    } else if (action.equals("getdatadoc")) {
286 263
      handleGetDataDocumentAction(out, params, response);  
287 264
    } else if (action.equals("getdoctypes")) {
......
317 294
      out.println(e.getMessage());
318 295
    }
319 296

  
297
    if ( un == "anonymous" ) {
298
        try {
299
            response.sendRedirect(
300
            response.encodeRedirectUrl("/xmltodb/lib/query.html"));
301
        } catch (java.io.IOException ioe) {
302
            sess.disconnect();            
303
            out.println("<?xml version=\"1.0\"?>");
304
            out.println("<error>");
305
            out.println("MetaCatServlet.handleLoginAction() - " +
306
                        "Error on redirect of HttpServletResponse: " + 
307
                        ioe.getMessage());
308
            out.println("</error>");
309
        }    
310
    }
311
    
320 312
    try { 
321 313
        if (sess.userAuth(un, pw)) {
322 314
            try {
......
807 799

  
808 800
/**
809 801
 * '$Log$
802
 * 'Revision 1.55  2000/08/01 18:26:50  bojilova
803
 * 'added Pool of Connections
804
 * 'DBQuery, DBReader, DBTransform, DBUtil are created on every request and use the connections from the Pool
805
 * 'same with DBWriter and DBValidate
806
 * '
810 807
 * 'Revision 1.54  2000/07/27 23:12:21  bojilova
811 808
 * 'Added "getdoctypes" and "getdataguide" action handlers
812 809
 * '

Also available in: Unified diff