Project

General

Profile

« Previous | Next » 

Revision 510

Added by bojilova over 23 years ago

XSLT transformation on "login" and "logout" action

View differences:

lib/style/login.xsl
1
<?xml version="1.0"?>
2
<!--
3
  * login.xsl
4
  *
5
  *      Authors: Jivka Bojilova
6
  *    Copyright: 2000 Regents of the University of California and the 
7
  *               National Center for Ecological Analysis and Synthesis
8
  *  For Details: http://www.nceas.ucsb.edu/
9
  *      Created: 2000 July 20
10
  *    File Info: '$Id$' 
11
  *
12
  * This is an XSLT (http://www.w3.org/TR/xslt) stylesheet designed to
13
  * convert an XML file with information about login action
14
  * into an HTML format suitable for rendering with modern web browsers.
15
-->
16
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
17
  <xsl:output method="html"/>
18

  
19
  <xsl:template match="/">
20
    <html>
21
      <xsl:apply-templates name="login"/>
22
    </html>
23
  </xsl:template>
24

  
25
  <xsl:template match="*" name="login">
26
  <xsl:choose>
27

  
28
    <xsl:when test="name(self::node())='login'">
29
      <head>
30
        <link rel="stylesheet" type="text/css" 
31
              href="@html-path@/style/rowcol.css" />
32
        <script language="JavaScript">
33
          <![CDATA[
34
          window.location="@html-path@/metacat.html"
35
          ]]>
36
        </script>
37
      </head>
38
      <body class="emlbody">
39
	<noscript>
40
          Please click <a href="@html-path@/metacat.html">here</a>
41
          to enter Metacat. To disable this message in the future
42
          please enable JavaScript on your browser.
43
        </noscript>
44
      </body>
45
    </xsl:when>
46

  
47
    <xsl:when test="name(self::node())='unauth_login'">
48
      <head>
49
        <link rel="stylesheet" type="text/css" 
50
              href="@html-path@/style/rowcol.css" />
51
        <script language="JavaScript">
52
              <![CDATA[
53
              window.location="@html-path@/login.html"
54
              ]]>
55
        </script>
56
      </head>
57
      <body class="emlbody">
58
	<noscript>
59
              Please click <a href="@html-path@/login.html">here</a>
60
              to enter Metacat. To disable this message in the future
61
              please enable JavaScript on your browser.
62
        </noscript>
63
      </body>
64
    </xsl:when>
65

  
66
    <xsl:when test="name(self::node())='logout'">
67
      <head>
68
        <link rel="stylesheet" type="text/css" 
69
              href="@html-path@/style/rowcol.css" />
70
        <script language="JavaScript">
71
              <![CDATA[
72
              window.location="@html-path@/index.html"
73
              ]]>
74
        </script>
75
      </head>
76
      <body class="emlbody">
77
        <noscript>
78
              Please click <a href="@html-path@/index.html">here</a>
79
              to enter Metacat. To disable this message in the future
80
              please enable JavaScript on your browser.
81
        </noscript>
82
      </body>
83
    </xsl:when>
84

  
85
    <xsl:when test="name(self::node())='error_login'">
86
      <head>
87
        <link rel="stylesheet" type="text/css" 
88
              href="@html-path@/style/rowcol.css" />
89
      </head>
90
      <body class="emlbody">
91
        <p style="color:red"> <b> Error Page </b> </p>
92
        <p> <xsl:value-of select="message"/> </p>
93
        <p> <a href="@html-path@/login.html">Try again</a> 
94
            <a href="@html-path@/index.html">Continue</a>  </p>
95
      </body>
96
    </xsl:when>
97

  
98
  </xsl:choose>
99
  </xsl:template>
100

  
101
</xsl:stylesheet>
0 102

  
src/loadstylesheets.sql
33 33
       VALUES ('XSL', '-//NCEAS//resource//EN', '-//W3C//HTML//EN',
34 34
                '-//NCEAS//resource.xsl',
35 35
                'http://dev.nceas.ucsb.edu/metadata/style/resource.xsl');
36
INSERT INTO xml_catalog (entry_type, source_doctype, target_doctype,
37
       public_id, system_id)
38
       VALUES ('XSL', '-//NCEAS//login//EN', '-//W3C//HTML//EN',
39
                '-//NCEAS//login.xsl',
40
                'http://dev.nceas.ucsb.edu/metadata/style/login.xsl');
41

  
src/edu/ucsb/nceas/metacat/AuthSession.java
58 58
    try { 
59 59
      if ( authService.authenticate(username, password) ) {
60 60
        this.session = getSession(request, username, password);
61
        message = "User Authentication successful";
62
        this.statusMessage = formatOutput("success", message);
61
        message = "Authentication successful for user: " + username;
62
        this.statusMessage = formatOutput("login", message);
63 63
        return true;
64 64
      } else {  
65 65
        message = "Authentication failed for user: " + username;
66
        this.statusMessage = formatOutput("unauth_login", message);
67
        return false;
66 68
      }    
67 69
    } catch ( ConnectException ce ) {
68 70
      message = "Connection to the authentication service failed. " 
......
71 73
      message = ise.getMessage();
72 74
    }
73 75
 
74
    this.statusMessage = formatOutput("error", message);
76
    this.statusMessage = formatOutput("error_login", message);
75 77
    return false;
76 78
  }
77 79

  
......
145 147
      
146 148
    out.append("<?xml version=\"1.0\"?>\n");
147 149
    out.append("<" + tag + ">");
148
    if ( tag.equals("error") ) {
149
      out.append(message);
150
    } else {
151
      out.append("\n  <message>" + message + "</message>\n");
152
      String username = (String)this.session.getAttribute("username");
153
      out.append("  <username>" + username + "</username>\n");
154
    }  
150
    out.append("\n  <message>" + message + "</message>\n");
155 151
    out.append("</" + tag + ">");
156 152
    
157 153
    return out.toString();
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
400 400
        conn = util.getConnection();
401 401
        DBTransform trans = new DBTransform(conn);
402 402
        response.setContentType("text/html");
403
        // user authentication successful
404
        if (isValid) {
405
        //  trans.transformXMLDocument(sess.getMessage(), "-//NCEAS//login//EN",
406
        //                             "-//W3C//HTML//EN", out);
407
          response.sendRedirect(
408
                   response.encodeRedirectUrl(htmlpath + "/metacat.html"));
409

  
410
        // unsuccessful user authentication 
411
        } else {
412
        //  trans.transformXMLDocument(sess.getMessage(), "-//NCEAS//nologin//EN",
413
        //                             "-//W3C//HTML//EN", out);
414
          response.sendRedirect(htmlpath + "/login.html");
415
        }
403
        trans.transformXMLDocument(sess.getMessage(), "-//NCEAS//login//EN",
404
                                   "-//W3C//HTML//EN", out);
416 405
        util.returnConnection(conn); 
417 406
      } catch(Exception e) {
418 407
        util.returnConnection(conn); 
......
423 412
      response.setContentType("text/xml");
424 413
      out.println(sess.getMessage()); 
425 414
    }
415
        
416
/* WITHOUT XSLT transformation
417
    // redirects response to html page
418
    if (qformat.equals("html")) {
419
      // user authentication successful
420
      if (isValid) {
421
        response.sendRedirect(
422
                 response.encodeRedirectUrl(htmlpath + "/metacat.html"));
423
      // unsuccessful user authentication 
424
      } else {
425
        response.sendRedirect(htmlpath + "/login.html");
426
      }
427
    // any output is returned  
428
    } else {
429
      response.setContentType("text/xml");
430
      out.println(sess.getMessage()); 
431
    }
432
*/        
426 433

  
427
//    if (action.equals("Login Client")) {
428
//      out.println(sess.getMessage());
429
//    } else {
430
//      try {
431
//        if (isValid) {
432
//          if (un.equals("public")) {
433
//            response.sendRedirect(
434
//                   response.encodeRedirectUrl(htmlpath + "/index.html"));
435
//          } else {
436
//            response.sendRedirect(
437
//                   response.encodeRedirectUrl(htmlpath + "/metacat.html"));
438
//          }
439
//        } else {
440
//          response.sendRedirect(htmlpath + "/login.html");
441
//        }
442
//      } catch ( java.io.IOException ioe) {
443
//        String message = "handleLoginAction() - " +
444
//                    "Error on redirect of HttpServletResponse: " + 
445
//                    ioe.getMessage();
446
//        out.println(message);
447
//      }                
448
//    }
449 434
  }    
450 435

  
451 436
  /** 
......
463 448
    // produce output
464 449
    StringBuffer output = new StringBuffer();
465 450
    output.append("<?xml version=\"1.0\"?>");
466
    output.append("<success>");
467
    output.append("User logout.");
468
    output.append("</success>");
451
    output.append("<logout>");
452
    output.append("User logged out");
453
    output.append("</logout>");
469 454

  
470 455
    //format and transform the output
471 456
    if (qformat.equals("html")) {
......
474 459
        conn = util.getConnection();
475 460
        DBTransform trans = new DBTransform(conn);
476 461
        response.setContentType("text/html");
477
        //trans.transformXMLDocument(output, "-//NCEAS//logout//EN", 
478
        //                           "-//W3C//HTML//EN", out);
479
        response.sendRedirect(htmlpath + "/index.html"); 
462
        trans.transformXMLDocument(output.toString(), "-//NCEAS//login//EN", 
463
                                   "-//W3C//HTML//EN", out);
480 464
        util.returnConnection(conn); 
481 465
      } catch(Exception e) {
482 466
        util.returnConnection(conn); 
......
487 471
      out.println(output.toString()); 
488 472
    }
489 473

  
474
/* WITHOUT XSLT transformation
475
    // redirects response to html page
476
    if (qformat.equals("html")) {
477
        response.sendRedirect(htmlpath + "/index.html"); 
478
      } catch(Exception e) {
479
        util.returnConnection(conn); 
480
      } 
481
    // any output is returned  
482
    } else {
483
      response.setContentType("text/xml");
484
      out.println(output.toString()); 
485
    }
486
*/
490 487
  }
491 488

  
492 489
  

Also available in: Unified diff