public static void showSession(HttpServletRequest req, HttpServletResponse res, PrintStream out) {

    // res.setContentType("text/html");

    // Get the current session object, create one if necessary
    HttpSession session = req.getSession();

    // Increment the hit count for this page. The value is saved
    // in this client's session under the name "snoop.count".
    Integer count = (Integer) session.getAttribute("snoop.count");
    if (count == null) {
      count = 1;
    } else count = count + 1;
    session.setAttribute("snoop.count", count);

    out.println(HtmlWriter.getInstance().getHtmlDoctypeAndOpenTag());
    out.println("<HEAD><TITLE>SessionSnoop</TITLE></HEAD>");
    out.println("<BODY><H1>Session Snoop</H1>");

    // Display the hit count for this page
    out.println(
        "You've visited this page " + count + ((!(count.intValue() != 1)) ? " time." : " times."));

    out.println("<P>");

    out.println("<H3>Here is your saved session data:</H3>");
    Enumeration atts = session.getAttributeNames();
    while (atts.hasMoreElements()) {
      String name = (String) atts.nextElement();
      out.println(name + ": " + session.getAttribute(name) + "<BR>");
    }

    out.println("<H3>Here are some vital stats on your session:</H3>");
    out.println("Session id: " + session.getId() + " <I>(keep it secret)</I><BR>");
    out.println("New session: " + session.isNew() + "<BR>");
    out.println("Timeout: " + session.getMaxInactiveInterval());
    out.println("<I>(" + session.getMaxInactiveInterval() / 60 + " minutes)</I><BR>");
    out.println("Creation time: " + session.getCreationTime());
    out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>");
    out.println("Last access time: " + session.getLastAccessedTime());
    out.println("<I>(" + new Date(session.getLastAccessedTime()) + ")</I><BR>");

    out.println(
        "Requested session ID from cookie: " + req.isRequestedSessionIdFromCookie() + "<BR>");
    out.println("Requested session ID from URL: " + req.isRequestedSessionIdFromURL() + "<BR>");
    out.println("Requested session ID valid: " + req.isRequestedSessionIdValid() + "<BR>");

    out.println("<H3>Test URL Rewriting</H3>");
    out.println("Click <A HREF=\"" + res.encodeURL(req.getRequestURI()) + "\">here</A>");
    out.println("to test that session tracking works via URL");
    out.println("rewriting even when cookies aren't supported.");

    out.println("</BODY></HTML>");
  }
Exemple #2
0
  public void controller(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {

      hsession = HibernateUtil.currentSession();
      sessione = request.getSession();
      tx = hsession.beginTransaction();

      String action = request.getParameter("action");

      if (action == null) action = "home";

      /*if(action.equals("login"))
      login(request, response);*/

      Users u = (Users) sessione.getAttribute("user");

      if (u == null) {
        throw new LoginException();
      } else if (u.getTipo().intValue() < 2) {
        throw new LoginException();
      }

      if (action.equals("home")) accedi(request, response);
      else if (action.equals("chiudi")) chiudiBilancio(request, response);

    } catch (LoginException e) {

      Avviso err = new Avviso(e.getMessage());
      request.setAttribute("err", err);
      nextview = "/./error.jsp";

    } catch (Exception e) {

      Avviso err =
          new Avviso("Errore indefinito. Ricorda di non usare il tasto REFRESH di Explorer!");
      request.setAttribute("err", err);
      System.out.println(e.getMessage());
      nextview = "/./error.jsp";

    } finally {

      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextview);
      if (dispatcher != null) {
        response.encodeURL(nextview);
        dispatcher.forward(request, response);
      }
      HibernateUtil.closeSession();
    }
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if (session == null) {
      response.sendRedirect("login.html");
      return;
    }

    String userName = (String) session.getAttribute("userName");
    if (isMissing(userName)) {
      response.sendRedirect("login.html");
      return;
    }
    String title = request.getParameter("title");
    String link = request.getParameter("link");
    String description = request.getParameter("description");
    session.setAttribute("title", title);
    session.setAttribute("link", link);
    session.setAttribute("description", description);
    String address = "WEB-INF/view/SaveBookmarkPage.jsp";
    String urlEncoding = response.encodeURL(address);
    RequestDispatcher dispatcher = request.getRequestDispatcher(urlEncoding);
    dispatcher.forward(request, response);
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    boolean orderCompleted = true;

    // Get the user's session and shopping cart
    HttpSession session = request.getSession(true);
    ResourceBundle messages = (ResourceBundle) session.getAttribute("messages");
    ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

    if (cart == null) {
      cart = new ShoppingCart();
      session.setAttribute("cart", cart);
    }

    // Update the inventory
    try {
      utx.begin();
      bookDB.buyBooks(cart);
      utx.commit();
    } catch (Exception ex) {
      try {
        utx.rollback();
      } catch (Exception e) {
        System.out.println("Rollback failed: " + e.getMessage());
      }

      System.err.println(ex.getMessage());
      orderCompleted = false;
    }

    // Payment received -- invalidate the session
    session.invalidate();

    // set content type header before accessing the Writer
    response.setContentType("text/html");
    response.setBufferSize(8192);

    PrintWriter out = response.getWriter();

    // then write the response
    out.println(
        "<html>" + "<head><title>" + messages.getString("TitleReceipt") + "</title></head>");

    // Get the dispatcher; it gets the banner to the user
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/banner");

    if (dispatcher != null) {
      dispatcher.include(request, response);
    }

    if (orderCompleted) {
      out.println("<h3>" + messages.getString("ThankYou") + request.getParameter("cardname") + ".");
    } else {
      out.println("<h3>" + messages.getString("OrderError"));
    }

    out.println(
        "<p> &nbsp; <p><strong><a href=\""
            + response.encodeURL(request.getContextPath())
            + "/bookstore\">"
            + messages.getString("ContinueShopping")
            + "</a> &nbsp; &nbsp; &nbsp;"
            + "</body></html>");
    out.close();
  }
  public void processRequest(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    HttpSession session = req.getSession(true);

    root = req.getContextPath();

    String addButton = req.getParameter("addButton");

    try {
      session = req.getSession(true);

      if (session.isNew()) {
        session.invalidate();
        res.setContentType("text/html;charset=UTF-8");

        PrintWriter out = res.getWriter();

        out.println(
            (new StringBuilder())
                .append("<html><HEAD><META HTTP-EQUIV='Refresh' CONTENT='0; URL=")
                .append(root)
                .append("/AID'/></HEAD></html>")
                .toString());
        out.close();
      }
    } catch (IllegalStateException e) {
      res.sendRedirect((new StringBuilder()).append(root).append("/AID").toString());
    }

    String originalQuery = (String) session.getAttribute("query");

    if (addButton != null) {
      String newQueryTerms[] = (String[]) req.getParameterValues("newQueryTerms");

      if ((newQueryTerms == null) || (newQueryTerms.length == 0)) {
        res.sendRedirect(
            res.encodeURL(
                root.concat(
                    (new StringBuilder())
                        .append("/AID?query=")
                        .append(originalQuery.replaceAll("\\s+", "+"))
                        .toString())));
      } else {
        String newQuery = originalQuery.replaceAll("\\s+", "+");

        for (int i = 0; i < newQueryTerms.length; i++) {
          newQuery =
              (new StringBuilder())
                  .append(newQuery)
                  .append("+")
                  .append(newQueryTerms[i])
                  .toString();
        }

        res.sendRedirect(
            res.encodeURL(
                root.concat(
                    (new StringBuilder()).append("/AID?query=").append(newQuery).toString())));
      }
    } else {
      String spellMatrix[] = (String[]) session.getAttribute("retSpellSuggestions");
      String termsInQuery[] = (String[]) session.getAttribute("termsInQuery");
      String wordnetMatrix[][] = (String[][]) session.getAttribute("retWordnetSynsMatrix");
      String synonymMatrix[][] = (String[][]) session.getAttribute("retSynsMatrix");
      String onlineSynMatrix[][] = (String[][]) session.getAttribute("onlineSynMatrix");

      res.setContentType("text/html;charset=UTF-8");

      PrintWriter out = res.getWriter();

      out.println(
          "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>AID Search interface</title>");
      out.println(
          (new StringBuilder())
              .append("<style type='text/css'>@import url(")
              .append(root)
              .append("/css/qckcss.css);")
              .toString());
      out.println("</style>");
      out.println(
          (new StringBuilder())
              .append("<link REL=\"SHORTCUT ICON\" HREF=\"")
              .append(root)
              .append("/images/favicon.ico\">")
              .toString());
      out.println(
          (new StringBuilder())
              .append("<script type=\"text/javascript\" src=\"")
              .append(root)
              .append("/javascript/overlib.js\">")
              .toString());
      out.println("<!-- bla -->");
      out.println("</script>");
      out.println("</head>");
      out.println(
          (new StringBuilder())
              .append("<body bgcolor=white background=\"")
              .append(root)
              .append("/images/background.gif\">")
              .toString());
      out.println("<div id=\"AIDfp\">");
      out.println("<a name=\"top\"/>");
      out.println("  <table border=\"0\" width=600>");
      out.println("<tr><td colspan=3>");
      out.println("<table>");
      out.println("\t<tr valign=\"top\" bgcolor=white><td class=\"navtext\">");
      out.println("\t<div id=\"navlinks\">");
      out.println(
          (new StringBuilder())
              .append("\t\t<img src=\"")
              .append(root)
              .append(
                  "/images/top.png\" width=\"709\" height=\"200\" border=\"0\"><!-- bla --> </img>")
              .toString());
      out.println(
          (new StringBuilder())
              .append(
                  "\t\t<div style=\"position: relative;top: -55px;margin-left: 15px;\"><a href=\"")
              .append(root)
              .append("/\">Home</a></div>")
              .toString());
      out.println(
          "\t\t<div style=\"position: relative;top: -71px;margin-left: 180px;\">Concept Finder</div>");
      out.println(
          "\t\t<div style=\"position: relative;top: -87px;margin-left: 410px;\">Search Details</div>");
      out.println(
          "\t\t<div style=\"position: relative;top: -103px;margin-left: 620px;\">History</div>");
      out.println("</div></td></tr></table>");
      out.println("</td></tr>");
      out.println(
          (new StringBuilder())
              .append("    <form name=\"selectionForm\" method=\"get\" action=\"")
              .append(res.encodeURL(req.getRequestURI()))
              .append("\">")
              .toString());
      out.println("      <tr>");
      out.println("        <td width=33% class='resultItemCenter'>");

      if (synonymMatrix != null) {
        out.println("          Found index-specific syonyms:<br>");
        out.println("          <select name='newQueryTerms' multiple>");

        for (int i = 0; i < synonymMatrix.length; i++) {
          for (int j = 0; j < synonymMatrix[i].length; j++) {
            if (synonymMatrix[i][j] != null) {
              out.println(
                  (new StringBuilder())
                      .append("            <option value='")
                      .append(synonymMatrix[i][j])
                      .append("'>")
                      .append(synonymMatrix[i][j])
                      .append("</option>")
                      .toString());
            }
          }
        }

        out.println("          </select>");
      }

      out.println("        </td>");
      out.println("        <td width=33% class='resultItemCenter'>");

      if (wordnetMatrix != null) {
        out.println("          Found Wordnet syonyms:<br>");
        out.println("          <select name='newQueryTerms' multiple>");

        for (int i = 0; i < wordnetMatrix.length; i++) {
          for (int j = 0; j < wordnetMatrix[i].length; j++) {
            if (wordnetMatrix[i][j] != null) {
              out.println(
                  (new StringBuilder())
                      .append("            <option value='")
                      .append(wordnetMatrix[i][j])
                      .append("'>")
                      .append(wordnetMatrix[i][j])
                      .append("</option>")
                      .toString());
            }
          }
        }

        out.println("          </select>");
      }

      out.println("        </td>");
      out.println("        <td width=33% class='resultItemCenter'>");

      if (onlineSynMatrix != null) {
        out.println("          Found online acronyms:<br>");
        out.println("          <select name='newQueryTerms' multiple>");

        for (int i = 0; i < onlineSynMatrix.length; i++) {
          for (int j = 0; j < onlineSynMatrix[i].length; j++) {
            if (onlineSynMatrix[i][j] != null) {
              out.println(
                  (new StringBuilder())
                      .append("            <option value='")
                      .append(onlineSynMatrix[i][j])
                      .append("'>")
                      .append(onlineSynMatrix[i][j])
                      .append("</option>")
                      .toString());
            }
          }
        }

        out.println("          </select>");
      }

      out.println("        </td>          </tr>");
      out.println("      <tr>");
      out.println("        <td class='resultItemCenter' width=100% colspan=3>");
      out.println("              <hr/>");
      out.println("        </td>");
      out.println("      </tr>");
      out.println("      <tr>");
      out.println("        <td class='resultItemCenter' width=100% colspan=3>");
      out.println("          <input type=submit name=\"addButton\" value=\"Add\">");
      out.println("        </td>");
      out.println("      </tr>");
      out.println("    </form>");
      out.println("  </table>");
      out.println("<div id=\"footer\">");
      out.println("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
      out.println("<tr>");
      out.println(
          (new StringBuilder())
              .append("<td width=\"1%\"><img src=\"")
              .append(root)
              .append(
                  "/images/footer-leftcurve.gif\" width=\"10\" height=\"31\" border=\"0\"/></td>")
              .toString());
      out.println("<td width=\"98%\" bgcolor=\"#\" class=\"footertext\">");
      out.println("<a href=\"#top\">Top</a>");
      out.println("        |\t\t");
      out.println(
          (new StringBuilder())
              .append("<a href=\"")
              .append(root)
              .append("/synonym\">Synonym client</a>")
              .toString());
      out.println("        |\t\t");
      out.println("<a href=\"http://www.vl-e.nl\">Vl-e</a>");
      out.println("</td>");
      out.println(
          (new StringBuilder())
              .append("<td width=\"1%\"><img src=\"")
              .append(root)
              .append(
                  "/images/footer-rightcurve.gif\" width=\"10\" height=\"31\" border=\"0\"/></td>")
              .toString());
      out.println("</tr>");
      out.println("</table>");
      out.println("</div>");
      out.println("</div>");
      out.println("</body>");
      out.println("</html>");
      out.close();
    }
  }
  // The tck uses only get & post requests
  protected void processTCKReq(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    LOGGER.entering(LOG_CLASS, "servlet entry");

    PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
    PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
    PortletConfig portletConfig = (PortletConfig) request.getAttribute("javax.portlet.config");
    long svtTid = Thread.currentThread().getId();
    long reqTid = (Long) portletReq.getAttribute(THREADID_ATTR);

    PrintWriter writer = ((MimeResponse) portletResp).getWriter();

    JSR286DispatcherReqRespTestCaseDetails tcd = new JSR286DispatcherReqRespTestCaseDetails();

    // Create result objects for the tests

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_containsHeader */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.containsHeader must return false"     */
    TestResult tr0 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_CONTAINSHEADER);
    try {
      boolean ok = response.containsHeader("Accept");
      tr0.setTcSuccess(ok == false);
    } catch (Exception e) {
      tr0.appendTcDetail(e.toString());
    }
    tr0.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectURL1 */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeRedirectURL must return null"   */
    TestResult tr1 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL1);
    try {
      String isval = response.encodeRedirectURL("http://www.cnn.com/");
      CompareUtils.stringsEqual(isval, null, tr1);
    } catch (Exception e) {
      tr1.appendTcDetail(e.toString());
    }
    tr1.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectUrl */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeRedirectUrl must return null"   */
    TestResult tr2 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL);
    try {
      String isval = response.encodeRedirectUrl("http://www.cnn.com/");
      CompareUtils.stringsEqual(isval, null, tr2);
    } catch (Exception e) {
      tr2.appendTcDetail(e.toString());
    }
    tr2.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeURL1 */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeURL must provide the same       */
    /* functionality as ResourceResponse.encodeURL"                         */
    TestResult tr3 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL1);
    try {
      String turl = "http://www.apache.org/";
      String hval = (String) response.encodeURL(turl);
      String pval = (String) portletResp.encodeURL(turl);
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr3);
    } catch (Exception e) {
      tr3.appendTcDetail(e.toString());
    }
    tr3.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeUrl */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeUrl must provide the same       */
    /* functionality as ResourceResponse.encodeURL"                         */
    TestResult tr4 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL);
    try {
      String turl = "http://www.apache.org/";
      String hval = (String) response.encodeUrl(turl);
      String pval = (String) portletResp.encodeURL(turl);
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr4);
    } catch (Exception e) {
      tr4.appendTcDetail(e.toString());
    }
    tr4.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getBufferSize */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getBufferSize must provide the same   */
    /* functionality as ResourceResponse.getBufferSize"                     */
    TestResult tr5 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETBUFFERSIZE);
    try {
      int hval = response.getBufferSize();
      int pval = ((ResourceResponse) portletResp).getBufferSize();
      String str =
          "Value "
              + hval
              + " from "
              + "HttpServletResponse"
              + " does not equal value "
              + pval
              + " + ResourceResponse";
      if (hval != pval) {
        tr5.appendTcDetail(str);
      }
      tr5.setTcSuccess(hval == pval);
    } catch (Exception e) {
      tr5.appendTcDetail(e.toString());
    }
    tr5.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getCharacterEncoding */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getCharacterEncoding must provide     */
    /* the same functionality as ResourceResponse.getCharacterEncoding"     */
    TestResult tr6 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCHARACTERENCODING);
    try {
      String hval = response.getCharacterEncoding();
      String pval = ((ResourceResponse) portletResp).getCharacterEncoding();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr6);
    } catch (Exception e) {
      tr6.appendTcDetail(e.toString());
    }
    tr6.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getContentType */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getContentType must provide the       */
    /* same functionality as ResourceResponse.getContentType"               */
    TestResult tr7 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCONTENTTYPE);
    try {
      String hval = response.getContentType();
      String pval = ((ResourceResponse) portletResp).getContentType();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr7);
    } catch (Exception e) {
      tr7.appendTcDetail(e.toString());
    }
    tr7.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getLocale */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getLocale must provide the same       */
    /* functionality as ResourceResponse.getLocale"                         */
    TestResult tr8 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETLOCALE);
    try {
      Locale hl = response.getLocale();
      Locale pl = ((MimeResponse) portletResp).getLocale();
      String hval = hl.getDisplayName();
      String pval = pl.getDisplayName();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr8);
    } catch (Exception e) {
      tr8.appendTcDetail(e.toString());
    }
    tr8.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_isCommitted */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.isCommitted must provide the same     */
    /* functionality as ResourceResponse.isCommitted"                       */
    TestResult tr9 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ISCOMMITTED);
    try {
      boolean hval = response.isCommitted();
      boolean pval = ((ResourceResponse) portletResp).isCommitted();
      String str =
          "Value "
              + hval
              + " from "
              + "HttpServletResponse"
              + " does not equal value "
              + pval
              + " + ResourceResponse";
      if (hval != pval) {
        tr9.appendTcDetail(str);
      }
      tr9.setTcSuccess(hval == pval);
    } catch (Exception e) {
      tr9.appendTcDetail(e.toString());
    }
    tr9.writeTo(writer);
  }
  /**
   * Returns the HTML tag that represents the resource link with the specified <i>text</i> and
   * <i>properties</i>. The original ServletHyperlink object <i>text</i> and <i>properties</i> are
   * not changed/updated.
   *
   * @param text The text.
   * @param properties The Properties.
   * @return The HTML tag.
   */
  public String getTag(String text, Properties properties) {

    // Verify that the link has been set.
    if (getLink() == null) {
      Trace.log(Trace.ERROR, "Attempting to get tag before setting the link.");
      throw new ExtendedIllegalStateException(
          "link", ExtendedIllegalStateException.PROPERTY_NOT_SET);
    }

    // Validate the text parameter.
    if (text == null) throw new NullPointerException("text");

    // create the tag.
    StringBuffer link = new StringBuffer(getLink());

    // path info for servlet ex.- http://myServer/myPathInfo
    if (pathInfo_ != null) {
      // if the link ends with a "/", the path does not need a leading "/"
      if (getLink().endsWith("/")) {
        if (pathInfo_.startsWith("/")) {
          pathInfo_ = pathInfo_.substring(1);
        } else {
          // pathInfo_ = pathInfo_;
        }
      } else // link does not end with a "/", so the path needs to start with "/"
      {
        if (pathInfo_.startsWith("/")) {
          // pathInfo_ = pathInfo_;
        } else {
          pathInfo_ = "/" + pathInfo_;
        }
      }

      // place holder for real implementation...
      link.append(URLEncoder.encode(pathInfo_, false));
    }

    if (properties != null) {
      String name;
      String parmStart = "?";
      Enumeration propertyList = properties.propertyNames();
      while (propertyList.hasMoreElements()) {
        name = (String) propertyList.nextElement();
        link.append(parmStart);
        link.append(URLEncoder.encode(name));
        link.append("=");
        link.append(URLEncoder.encode(properties.getProperty(name)));
        parmStart = "&";
      }
    }

    StringBuffer url = new StringBuffer();

    if (response_ != null) url.append(response_.encodeURL(link.toString()));
    else url.append(link.toString());

    // create the tag.
    StringBuffer buffer = new StringBuffer();

    buffer.append("<a href=\"");
    buffer.append(url.toString());

    String location = getLocation(); // $A3A
    if (location != null) // $A3A
    {
      buffer.append("#"); // $A3A
      buffer.append(location); // $A3A
    }

    buffer.append("\"");

    String name = getName();
    if (name != null) {
      buffer.append(" name=\"");
      buffer.append(name);
      buffer.append("\"");
    }

    String title = getTitle();
    if (title != null) {
      buffer.append(" title=\"");
      buffer.append(title);
      buffer.append("\"");
    }

    String target = getTarget();
    if (target != null) {
      buffer.append(" target=\"");
      buffer.append(target);
      buffer.append("\"");
    }

    buffer.append(getLanguageTag());
    buffer.append(getDirectionTag());
    buffer.append(getAttributeString()); // @Z1A

    buffer.append(">");
    buffer.append(text);
    buffer.append("</a>");

    return buffer.toString();
  }