dblevins    2005/08/28 04:55:55

  Added:       examples/moviefun/src/webapp default.css index.jsp setup.jsp
  Log:

  Collapsed ear example (aka. one openejb per webapp)
  
  Revision  Changes    Path
  1.1                  openejb1/examples/moviefun/src/webapp/default.css
  
  Index: default.css
  ===================================================================
  body, p, td, table, tr, .bodytext, .stepfield {
        font-family: Verdana, arial, sans-serif;
        font-size: 11px;
        line-height: 16px;
        color: #000000;
        font-weight: normal;
  }
  
  body {
        margin: 0px;
        padding: 0px;
        text-align: center;
      background-color: #f0f0f0;
  }
  
  #Content {
        text-align: left;
        background-color: #fff;
        padding: 0px;
        margin: 0px;
  }
  
  HR {
        color: 3c78b5;
        height: 1;
  }
  
  A:link, A:visited, A:active, A:hover {
        color: #003366;
  }
  
  h1 A:link, h1 A:visited, h1 A:active {
        text-decoration: none;
  }
  
  h1 A:hover {
      border-bottom: 1px dotted #003366;
  }
  
  input {
        font-family: verdana, geneva, arial, sans-serif;
        font-size: 11px;
        color: #000000;
  }
  
  h1 {
        font-size: 24px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        color: #003366;
        border-bottom: 1px solid #3c78b5;
        padding: 2px;
        margin: 36px 0px 4px 0px;
  }
  
  h2 {
        font-size: 18px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        border-bottom: 1px solid #3c78b5;
        padding: 2px;
        margin: 27px 0px 4px 0px;
  }
  
  h3 {
        font-size: 14px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 21px 0px 4px 0px;
  }
  
  h4 {
        font-size: 12px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 18px 0px 4px 0px;
  }
  
  h4.search {
        font-size: 12px;
        line-height: normal;
        font-weight: normal;
        background-color: #f0f0f0;
        padding: 4px;
        margin: 18px 0px 4px 0px;
  }
  
  h5 {
        font-size: 10px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 14px 0px 4px 0px;
  }
  
  h6 {
        font-size: 8px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 14px 0px 4px 0px;
  }
  
  .smalltext {
      color: #666666;
      font-size: 10px;
  }
  .smalltext a {
      color: #666666;
  }
  
  .tableview table {
      margin: 0;
  }
  
  .tableview th {
      text-align: left;
      color: #003366;
      font-size: 12px;
      padding: 5px 0px 0px 5px;
      border-bottom: 2px solid #3c78b5;
  }
  .tableview td {
      text-align: left;
      border-color: #ccc;
      border-width: 0px 0px 1px 0px;
      border-style: solid;
      margin: 0;
      padding: 4px 10px 4px 5px;
  }
  
  .bottomshadow {
      height: 12px;
      background-image: url("/images/border/border_bottom.gif");
      background-repeat: repeat-x;
  }
  
  .topBarDiv a:link {color: white;}
  .topBarDiv a:visited {color: white;}
  .topBarDiv a:active {color: white;}
  .topBarDiv a:hover {color: white;}
  .topBarDiv {color: white;}
  
  .topBar td {
      background-color: #003366;
  }
  
  
  .basicPanelContainer {border: 1px solid #3c78b5; margin-top: 2px; 
margin-bottom: 8px; width: 100%}
  .basicPanelTitle {padding: 5px; margin: 0px; background-color: #f0f0f0; 
color: black; font-weight: bold;}
  .basicPanelBody {padding: 5px; margin: 0px}
  
  
  
  1.1                  openejb1/examples/moviefun/src/webapp/index.jsp
  
  Index: index.jsp
  ===================================================================
  <%@ page import="java.util.Collection,
                   org.acme.movie.MovieEntity,
                   java.util.Iterator,
                   org.acme.movie.Movie,
                   java.util.Date,
                   java.io.PrintStream,
                   java.util.Map,
                   java.util.HashMap,
                   java.util.ListIterator,
                   java.util.List,
                   javax.ejb.FinderException"%>
  <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  <%
      List movies = null;
      ListIterator listIterator = null;
      int display = 5;
      String action = request.getParameter("action");
  
      if ("Add".equals(action)) {
  
          String title = request.getParameter("title");
          String director = request.getParameter("director");
          String genre = request.getParameter("genre");
          int rating = Integer.parseInt(request.getParameter("rating"));
          String dateString = 
request.getParameter("releaseDate").replaceFirst("^([0-9]{4}$)","$1.01.01");
          Date releaseDate = MovieEntity.DATE_FORMAT.parse(dateString);
  
          MovieEntity.Home.create(title, director, genre, rating, releaseDate);
  
      } else if ("Remove".equals(action)) {
  
          String[] ids = request.getParameterValues("id");
          for (int i = 0; i < ids.length; i++) {
              String id = ids[i];
              MovieEntity.Home.remove(new Integer(id));
          }
  
      } else if (">>".equals(action)) {
  
          movies = (List) session.getAttribute("movies.collection");
          listIterator = (ListIterator) session.getAttribute("movies.iterator");
  
      } else if ("<<".equals(action)) {
  
          movies = (List) session.getAttribute("movies.collection");
          listIterator = (ListIterator) session.getAttribute("movies.iterator");
          for (int i=display*2; i > 0 && listIterator.hasPrevious(); i-- ) {
              listIterator.previous(); // backup
          }
  
      } else if ("findByTitle".equals(action)) {
  
          movies = (List) 
MovieEntity.Home.findByTitle(request.getParameter("key"));
  
      } else if ("findByDirector".equals(action)) {
  
          movies = (List) 
MovieEntity.Home.findByDirector(request.getParameter("key"));
  
      } else if ("findByGenre".equals(action)) {
  
          movies = (List) 
MovieEntity.Home.findByGenre(request.getParameter("key"));
      }
  
      if (movies == null){
          try {
              movies = (List) MovieEntity.Home.findAllMovies();
          } catch (Throwable e) {
              // We must not have run setup yet
              response.sendRedirect("setup.jsp");
              return;
          }
      }
  
      if (listIterator == null) {
          listIterator = movies.listIterator();
      }
  
      session.setAttribute("movies.collection", movies);
      session.setAttribute("movies.iterator", listIterator);
  %>
  <html>
  <head><title>Moviefun :: Index</title>
  <link rel="stylesheet" href="default.css" type="text/css" />
  
  </head>
  <body>
  <p/>
  <div id="Content">
  <table>
  <tr>
  <td>
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr class="topBar">
          <td align="left" width="85%">&nbsp;
              <span class="topBarDiv">Mini-Movie Application</span>
          </td>
          <td align="right" valign="middle" width="1%" nowrap>
              <form method="POST" action="index.jsp" name="findMovie" 
style="padding: 1px; margin: 1px">
              <select name="action">
                  <option value="findByTitle">Title</option>
                  <option value="findByDirector">Director</option>
                  <option value="findByGenre">Genre</option>
              </select>
              <input type="text" name="key" size="20"/>
              <input type="submit" value="Search"/></td>
              </form>
          </td>
      </tr>
      </table>
  
  </td>
  </tr>
  <tr>
  <td>
      <div class="basicPanelContainer" style="width: 100%">
  
          <div class="basicPanelTitle">Movies</div>
  
          <div class="basicPanelBody">
              <form method="POST" action="index.jsp" name="listMovies" 
style="padding: 1px; margin: 1px">
              <table class="tableview" width="100%" cellspacing="0" 
cellpadding="0" style="padding: 5px">
              <tr>
              <th>Title</th>
              <th>Director</th>
              <th>Genre</th>
              <th>Rating</th>
              <th>Year</th>
              <th>&nbsp;</th>
              </tr>
              <%
              int start = listIterator.nextIndex();
              for (int i=display; i > 0 && listIterator.hasNext(); i-- ) {
                  Movie movie = (Movie) listIterator.next();
              %>
              <tr>
              <td width="200"><%=movie.getTitle()%></td>
              <td width="120"><%=movie.getDirector()%></td>
              <td width="90"><%=movie.getGenre()%></td>
              <td width="50"><%=movie.getRating()%></td>
              <td width="50"><%=movie.getReleaseDate().getYear()+1900%></td>
              <td><input type="checkbox" name="id" 
value="<%=movie.getMovieId()%>"></td>
              </tr>
  
              <% } %>
              </table>
              <table width="100%" cellspacing="0" cellpadding="0" 
style="padding: 5px">
              <tr>
              <td>
              <% if (start!=0&&listIterator.hasPrevious()){%><input 
type="submit" name="action" value="<<"/><%}%>
  
              <%=start+1%> - <%=listIterator.nextIndex()%> of <%=movies.size()%>
  
              <% if (listIterator.hasNext()){%><input type="submit" 
name="action" value=">>"/><%}%>
              </td>
              <td align="right">
                  <input type="submit" name="action" value="Remove"/>
              </td>
              </tr>
              </table>
              </form>
          </div>
      </div>
  </td>
  </tr>
  <tr>
  <td>
      <div class="basicPanelContainer" style="width: 100%">
          <div class="basicPanelTitle">Add</div>
          <div class="basicPanelBody">
              <form method="POST" action="index.jsp" name="addMovie" 
style="padding: 1px; margin: 1px">
              <table width="100%" cellspacing="0" cellpadding="0" 
style="padding: 0px">
              <tr>
              <td width="200"><input type="text" name="title" size="29"/></td>
              <td width="120"><input type="text" name="director" 
size="17"/></td>
              <td width="90"><input type="text" name="genre" size="14"/></td>
              <td width="50"><input type="text" name="rating" size="7"/></td>
              <td width="50"><input type="text" name="releaseDate" 
size="7"/></td>
              <td><input type="submit" name="action" value="Add"/></td>
              </tr>
              </table>
              </form>
  
          </div>
      </div>
  </td>
  </tr>
  </table>
  
  
      <div class="bottomshadow"></div>
  
      <div id="poweredby" class="smalltext">
          Powered by
          <a href="http://jakarta.apache.org/tomcat"; class="smalltext">Apache 
Tomcat</a> and
          <a href="http://www.openejb.org"; class="smalltext">OpenEJB</a>.
          <a href="http://jira.codehaus.org/secure/BrowseProject.jspa?id=10401"; 
class="smalltext">Bug/feature request</a>
          <br/>
      </div>
  
  
  </div>
  </body>
  </html>
  
  
  
  1.1                  openejb1/examples/moviefun/src/webapp/setup.jsp
  
  Index: setup.jsp
  ===================================================================
  <%@ page import="
  org.acme.movie.JndiContext,
  java.sql.Connection,
  javax.naming.Context,
  java.sql.Statement,
  java.util.Date,
  org.acme.movie.MovieEntity,
  java.text.SimpleDateFormat,
  javax.sql.DataSource,
  java.util.Collection,
  java.util.Iterator,
  org.acme.movie.Movie"%>
  
  <h2>Setup</h2>
  <%
      //Looking up the DataSource from JNDI
      Context context = JndiContext.LOCAL;
      DataSource dataSource = (DataSource) context.lookup("jdbc/moviedb");
  
      //Opening a connection to the moviedb database<br>
      Connection connection = dataSource.getConnection();
      Statement statement = connection.createStatement();
  
      //Dropping old MOVIE table
      statement.execute("DROP TABLE movie");
  
      //Creating a new MOVIE table
      statement.execute(" CREATE TABLE movie (\n"+
                       "  movieId       int PRIMARY KEY,\n" +
                       "  title         varchar(200) not null,\n" +
                       "  director      varchar(200) not null,\n" +
                       "  genre         varchar(200) not null,\n" +
                       "  rating        int not null,\n" +
                       "  release_date  date not null\n" +
                       ")");
      //Closing connections
      statement.close();
      connection.close();
  
      //Creating an initial set of records using CMP Entities
      SimpleDateFormat date = MovieEntity.DATE_FORMAT;
  
      MovieEntity.Home.create("Wedding Crashers", "David Dobkin", "Comedy", 7 , 
date.parse("2005.07.15"));
      MovieEntity.Home.create("Starsky & Hutch", "Todd Phillips", "Action", 6 , 
date.parse("2004.03.05"));
      MovieEntity.Home.create("Shanghai Knights", "David Dobkin", "Action", 6 , 
date.parse("2003.07.13"));
      MovieEntity.Home.create("I-Spy", "Betty Thomas", "Adventure", 5 , 
date.parse("2002.11.01"));
      MovieEntity.Home.create("The Royal Tenenbaums", "Wes Anderson", "Comedy", 
8 , date.parse("2001.12.14"));
      MovieEntity.Home.create("Zoolander", "Ben Stiller", "Comedy", 6 , 
date.parse("2001.09.28"));
      MovieEntity.Home.create("Shanghai Noon", "Tom Dey", "Comedy", 7 , 
date.parse("2000.05.26"));
      //Done!
  %>
  Done!
  
  <h2>Seeded Database with the Following movies</h2>
  <table width="500">
  <tr>
  <td><b>Title</b></td>
  <td><b>Director</b></td>
  <td><b>Genre</b></td>
  </tr>
  <%
      Collection movies = MovieEntity.Home.findAllMovies();
      for (Iterator iterator = movies.iterator(); iterator.hasNext();) {
          Movie movie = (Movie) iterator.next();
  %>
  <tr>
  <td><%=movie.getTitle()%></td>
  <td><%=movie.getDirector()%></td>
  <td><%=movie.getGenre()%></td>
  </tr>
  
  <%
      }
  %>
  </table>
  
  <h2>Continue</h2>
  <a href="index.jsp">Go to main app</a>
  
  

Reply via email to