<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld"  prefix="html-el"  %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld"  prefix="bean-el"  %>
<%@ taglib uri="/WEB-INF/struts-logic-el.tld" prefix="logic-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<html-el:html>
<head>
<title>Test struts logic-el Match Tags</title>
</head>
<body bgcolor="white">

<div align="center">
<h1>Test struts logic-el Match Tags</h1>
</div>

<jsp:useBean id="bean" scope="page" class="org.apache.struts.webapp.exercise.TestBean"/>
<c:set var="jcookie" value='${cookie["JSESSIONID"].value}'/>
<c:set var="uaheader" value='${header["User-Agent"]}'/>
<c:set var="rparam" value='${param["param1"]}'/>
<%
  pageContext.setAttribute("string", "String test value");
%>

<table border="1">
  <tr>
    <th>Test Type</th>
    <th>Variable Content</th>
    <th>Value Content</th>
    <th>Correct Value Test</th>
    <th>Test Result</th>
  </tr>
  <tr>
    <td>Cookie / Any</td>
    <%-- This isn't an exact parallel.  With "bean:cookie", you can specify a
					 default value.  That would take another step with this. --%>
    <td><c:out value="${jcookie}"/></td>
    <td>0</td>
    <td>contains</td>
    <td>
      <c:choose>
       <c:when test="${not empty jcookie}">
        <%-- The functionality of "logic:match" will eventually be available
				 through a string function in the EL expression. --%>
        <logic-el:match expr="${jcookie}" value="0">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${jcookie}" value="0">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Cookie / End</td>
    <td><c:out value="${jcookie}"/></td>
    <td>0</td>
    <td>ends with</td>
    <td>
      <c:choose>
       <c:when test="${not empty jcookie}">
        <logic-el:match expr="${jcookie}" location="end" value="0">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${jcookie}" location="end" value="0">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Cookie / Start</td>
    <td><c:out value="${jcookie}"/></td>
    <td>0</td>
    <td>starts with</td>
    <td>
      <c:choose>
       <c:when test="${not empty jcookie}">
        <logic-el:match expr="${jcookie}" location="start" value="0">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${jcookie}" location="start" value="0">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Header / Any</td>
    <td><c:out value="${uaheader}"/></td>
    <td>Mozilla</td>
    <td>contains</td>
    <td>
      <c:choose>
       <c:when test="${not empty uaheader}">
        <logic-el:match expr="${uaheader}" value="Mozilla">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${uaheader}" value="Mozilla">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Header / End</td>
    <td><c:out value="${uaheader}"/></td>
    <td>Mozilla</td>
    <td>ends with</td>
    <td>
      <c:choose>
       <c:when test="${not empty uaheader}">
        <logic-el:match expr="${uaheader}" location="end" value="Mozilla">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${uaheader}" location="end" value="Mozilla">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Header / Start</td>
    <td><c:out value="${uaheader}"/></td>
    <td>Mozilla</td>
    <td>starts with</td>
    <td>
      <c:choose>
       <c:when test="${not empty uaheader}">
        <logic-el:match expr="${uaheader}" location="start" value="Mozilla">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${uaheader}" location="start" value="Mozilla">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Name / Any</td>
    <td><c:out value="${string}"/></td>
    <td>value</td>
    <td>contains</td>
    <td>
      <logic-el:match name="string" value="value">
        match
      </logic-el:match>
      <logic-el:notMatch name="string" value="value">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
  <tr>
    <td>Name / End</td>
    <td><c:out value="${string}"/></td>
    <td>value</td>
    <td>ends with</td>
    <td>
      <logic-el:match name="string" location="end" value="value">
        match
      </logic-el:match>
      <logic-el:notMatch name="string" location="end" value="value">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
  <tr>
    <td>Name / Start</td>
    <td><c:out value="${string}"/></td>
    <td>value</td>
    <td>starts with</td>
    <td>
      <logic-el:match name="string" location="start" value="value">
        match
      </logic-el:match>
      <logic-el:notMatch name="string" location="start" value="value">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
  <tr>
    <td>Parameter / Any</td>
    <td><c:out value="${rparam}"/></td>
    <td>value1</td>
    <td>contains</td>
    <td>
      <c:choose>
       <c:when test="${not empty rparam}">
        <logic-el:match expr="${rparam}" value="value1">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${rparam}" value="value1">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Parameter / End</td>
    <td><c:out value="${rparam}"/></td>
    <td>value1</td>
    <td>ends with</td>
    <td>
      <c:choose>
       <c:when test="${not empty rparam}">
        <logic-el:match expr="${rparam}" location="end" value="value1">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${rparam}" location="end" value="value1">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Parameter / Start</td>
    <td><c:out value="${rparam}"/></td>
    <td>value1</td>
    <td>starts with</td>
    <td>
      <c:choose>
       <c:when test="${not empty rparam}">
        <logic-el:match expr="${rparam}" location="start" value="value1">
         match
        </logic-el:match>
        <logic-el:notMatch expr="${rparam}" location="start" value="value1">
         notMatch
        </logic-el:notMatch>
       </c:when>
       <c:otherwise>
        missing
       </c:otherwise>
      </c:choose>
    </td>
  </tr>
  <tr>
    <td>Property / Any</td>
    <td><c:out value="${bean.stringProperty}"/></td>
    <td>FOO</td>
    <td>contains</td>
    <td>
      <logic-el:match expr="${bean.stringProperty}" value="FOO">
        match
      </logic-el:match>
      <logic-el:notMatch expr="${bean.stringProperty}" value="FOO">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
  <tr>
    <td>Property / End</td>
    <td><c:out value="${bean.stringProperty}"/></td>
    <td>FOO</td>
    <td>ends with</td>
    <td>
      <logic-el:match expr="${bean.stringProperty}" location="end" value="FOO">
        match
      </logic-el:match>
      <logic-el:notMatch expr="${bean.stringProperty}"
							    location="end" value="FOO">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
  <tr>
    <td>Property / Start</td>
    <td><c:out value="${bean.stringProperty}"/></td>
    <td>FOO</td>
    <td>starts with</td>
    <td>
      <logic-el:match expr="${bean.stringProperty}"
                      location="start" value="FOO">
        match
      </logic-el:match>
      <logic-el:notMatch expr="${bean.stringProperty}"
             location="start" value="FOO">
        notMatch
      </logic-el:notMatch>
    </td>
  </tr>
</table>

</body>
</html-el:html>
