Пример #1
0
  /** goStartTag will be called when we see the "a" tag */
  public int doStartTag() throws JspException {

    // this link could be part of a menu or not
    WallMenu menu = (WallMenu) findAncestorWithClass(this, WallMenu.class);
    if (menu != null) {
      inside_menu = true;
    }
    // WallDocument document = (WallDocument) findAncestorWithClass(this,
    // WallDocument.class);
    WallDocument document =
        (WallDocument) pageContext.getAttribute("wall-document", PageContext.REQUEST_SCOPE);

    try {
      ObjectsManager objectsManager = WurflServletInit.getObjectsManager();
      cm = objectsManager.getCapabilityMatrixInstance();
      uam = objectsManager.getUAManagerInstance();
      request = (HttpServletRequest) pageContext.getRequest();

      // Check the capability string
      warning = TagUtil.checkCapability("preferred_markup");
      if (warning.length() > 0) {
        throw new JspException(warning);
      }

      // get the user agent
      UA = TagUtil.getUA(this.request);
      device_id = uam.getDeviceIDFromUALoose(UA);
      mark_up = cm.getCapabilityForDevice(device_id, "preferred_markup");
      mark_up = TagUtil.getWallMarkup(mark_up);

      if (inside_menu) {
        // XHTML first
        if (mark_up.startsWith("xhtmlmp")) {

          fancy_ok = menu.colorize && menu.menu_css_tag && menu.table_and_css_background;

          // if the user wants to do it fancy and the device allows for it
          if (fancy_ok) {
            try {
              JspWriter out = pageContext.getOut();
              String bgcolorstyle = menu.getBGColor();
              out.print("<tr>");
              out.print(" <td class=\"" + bgcolorstyle + "\">");

              String an = ""; // autonumber
              if (menu.getAutonumber()) {
                an = menu.getAutonumber_index();
                out.print(" " + an);
                out.print(" <a accesskey=\"" + an + "\"");

              } else {
                // maybe mark-up defines it's own
                if (!accesskey.equals("")) {
                  out.print(" " + accesskey + " <a accesskey=\"" + accesskey + "\"");
                } else {
                  out.print("<a");
                }
              }
              // tel number scheme:
              warning = TagUtil.checkCapability("xhtml_make_phone_call_string");
              if (warning.length() > 0) {
                throw new JspException(warning);
              }

              // get the user agent
              String telnum = cm.getCapabilityForDevice(device_id, "xhtml_make_phone_call_string");

              out.print(" href=\"" + telnum + tel + "\">");
            } catch (IOException ioe) {
              System.out.println("Error in a tag <a>: " + ioe);
            }
            return (EVAL_BODY_INCLUDE);
          } else { // for whatever reason, no fancy XHTML menus

            try {
              JspWriter out = pageContext.getOut();
              out.print("<li>");

              // generate icon?
              if (document != null && !opwv_icon.equals("")) {
                if (document.getUseXHTMLExtensions()) {
                  out.print("<img localsrc=\"" + opwv_icon + "\" src=\"\" alt=\"\"/> ");
                }
              }

              String an = ""; // autonumber
              if (menu.getAutonumber()) {
                an = menu.getAutonumber_index();
                out.print("<a accesskey=\"" + an + "\"");
              } else {
                // maybe mark-up defines it's own
                if (!accesskey.equals("")) {
                  out.print("<a accesskey=\"" + accesskey + "\"");
                } else {
                  out.print("<a");
                }
              }

              // tel number scheme:
              warning = TagUtil.checkCapability("xhtml_make_phone_call_string");
              if (warning.length() > 0) {
                throw new JspException(warning);
              }

              // get the user agent
              String telnum = cm.getCapabilityForDevice(device_id, "xhtml_make_phone_call_string");

              if (!telnum.equals("none")) {
                out.print(" href=\"" + telnum + tel + "\">");
              } else {
                out.print(" href=\"#\">" + alt);
              }

            } catch (IOException ioe) {
              System.out.println("Error in a tag <a>: " + ioe);
            }
            return (EVAL_BODY_INCLUDE);
          }
        }

        // CHTML
        if (mark_up.startsWith("chtml")) {

          try {
            JspWriter out = pageContext.getOut();
            String an = ""; // autonumber
            if (menu.getAutonumber()) {
              an = menu.getAutonumber_index();
              String emoji = getEmoji(an);
              out.print(emoji + "&nbsp;<a acceskey=\"" + an + "\"");
            } else {
              // maybe mark-up defines it's own
              if (!accesskey.equals("")) {
                String emoji = getEmoji(accesskey);
                out.print(emoji + "&nbsp;<a accesskey=\"" + accesskey + "\"");
              } else {
                out.print("<a");
              }
            }

            // tel number scheme:
            warning = TagUtil.checkCapability("chtml_make_phone_call_string");
            if (warning.length() > 0) {
              throw new JspException(warning);
            }

            // get the user agent
            String telnum = cm.getCapabilityForDevice(device_id, "chtml_make_phone_call_string");

            if (!telnum.equals("none")) {
              out.print(" href=\"" + telnum + tel + "\"");
              // cti
              if (!cti.equals("")) {
                out.print(" cti=\"" + cti + "\"");
              }
              out.print(">");
            } else {
              out.print(" href=\"#\">" + alt);
            }

          } catch (IOException ioe) {
            System.out.println("Error in a tag <a>: " + ioe);
          }
          return (EVAL_BODY_INCLUDE);
        }

        // WML
        if (mark_up.startsWith("wml")) {
          try {
            JspWriter out = pageContext.getOut();

            // If possible, do menus with select/option/onpick
            warning = TagUtil.checkCapability("menu_with_select_element_recommended");
            if (warning.length() > 0) {
              throw new JspException(warning);
            }
            wml_menu_with_select =
                cm.getCapabilityForDevice(device_id, "menu_with_select_element_recommended");

            if (wml_menu_with_select.equals("true")) {

              // tel number scheme:
              warning = TagUtil.checkCapability("wml_make_phone_call_string");
              if (warning.length() > 0) {
                throw new JspException(warning);
              }

              // get the user agent
              String telnum = cm.getCapabilityForDevice(device_id, "wml_make_phone_call_string");
              if (!telnum.equals("none")) {
                out.print("<option onpick=\"" + telnum + tel + "\">");
              } else {
                out.print("<option onpick=\"#\">" + alt);
              }
              // generate icon?
              if (document != null && !opwv_icon.equals("")) {
                if (document.getUseWMLExtensions()) {
                  out.print("<img localsrc=\"" + opwv_icon + "\" src=\"\" alt=\"\"/>");
                }
              }

            } else {
              // Render with Hyperlinks. extra check for WML. accesskey support
              warning = TagUtil.checkCapability("access_key_support");
              if (warning.length() > 0) {
                throw new JspException(warning);
              }
              accesskey_ok_str = cm.getCapabilityForDevice(device_id, "access_key_support");
              if (accesskey_ok_str.equals("true")) {
                accesskey_ok = true;
              }

              @SuppressWarnings("unused")
              String an = ""; // autonumber
              // accesskey for WML is tricky: extra check accesskey support by
              // WML browser
              // SECOND THOUGHT: I get problems with GATEWAY. removing accesskey
              // for WML for the time being
              if (menu.getAutonumber() && accesskey_ok) {
                an = menu.getAutonumber_index();
                out.print("<a");
                // out.print("<a accesskey=\""+an+"\"");
              }
              if (!menu.getAutonumber() && accesskey_ok) {
                // maybe mark-up defines it's own
                if (!accesskey.equals("")) {
                  out.print("<a");
                  // out.print("<a accesskey=\""+accesskey+"\"");
                } else {
                  out.print("<a");
                }
              }
              if (!accesskey_ok) {
                out.print("<a");
              }

              // tel number scheme:
              warning = TagUtil.checkCapability("wml_make_phone_call_string");
              if (warning.length() > 0) {
                throw new JspException(warning);
              }

              // get the user agent
              String telnum = cm.getCapabilityForDevice(device_id, "wml_make_phone_call_string");

              if (!telnum.equals("none")) {
                out.print(" href=\"" + telnum + tel + "\">");
              } else {
                out.print(" href=\"#\">" + alt);
              }
            }

          } catch (IOException ioe) {
            System.out.println("Error in a tag <a>: " + ioe);
          }
          return (EVAL_BODY_INCLUDE);
        }

      } else {
        // ************ NOT inside a menu! PLAIN LINK!********************

        if (mark_up.startsWith("xhtmlmp")) {

          try {
            JspWriter out = pageContext.getOut();
            // accesskey?
            if (!accesskey.equals("")) {
              out.print("<a accesskey=\"" + accesskey + "\"");
            } else {
              out.print("<a");
            }

            // tel number scheme:
            warning = TagUtil.checkCapability("xhtml_make_phone_call_string");
            if (warning.length() > 0) {
              throw new JspException(warning);
            }

            // get the user agent
            String telnum = cm.getCapabilityForDevice(device_id, "xhtml_make_phone_call_string");

            if (!telnum.equals("none")) {
              out.print(" href=\"" + telnum + tel + "\">");
            } else {
              out.print(" href=\"#\">" + alt);
            }

          } catch (IOException ioe) {
            System.out.println("Error in a tag <a>: " + ioe);
          }
          return (EVAL_BODY_INCLUDE);
        } // end XHTML

        // CHTML
        if (mark_up.startsWith("chtml")) {

          try {
            JspWriter out = pageContext.getOut();
            if (!accesskey.equals("")) {
              out.print("<a accesskey=\"" + accesskey + "\"");
            } else {
              out.print("<a");
            }
            // tel number scheme:
            warning = TagUtil.checkCapability("chtml_make_phone_call_string");
            if (warning.length() > 0) {
              throw new JspException(warning);
            }

            // get the user agent
            String telnum = cm.getCapabilityForDevice(device_id, "chtml_make_phone_call_string");

            if (!telnum.equals("none")) {
              out.print(" href=\"" + telnum + tel + "\"");
              // cti
              if (!cti.equals("")) {
                out.print(" cti=\"" + cti + "\"");
              }
              out.print(">");
            } else {
              out.print(" href=\"#\">" + alt);
            }

          } catch (IOException ioe) {
            System.out.println("Error in a tag <a>: " + ioe);
          }
          return (EVAL_BODY_INCLUDE);
        }

        // WML

        if (mark_up.startsWith("wml")) {

          try {
            JspWriter out = pageContext.getOut();

            if (accesskey_ok) {
              // maybe mark-up defines it's own
              if (!accesskey.equals("")) {
                out.print("<a");
                // Accesskey interferes with gateways and WML 1.1 DTD
                // out.print("<a accesskey=\""+accesskey+"\"");
              } else {
                out.print("<a");
              }
            }
            if (!accesskey_ok) {
              out.print("<a");
            }

            // tel number scheme:
            warning = TagUtil.checkCapability("wml_make_phone_call_string");
            if (warning.length() > 0) {
              throw new JspException(warning);
            }

            // get the user agent
            String telnum = cm.getCapabilityForDevice(device_id, "wml_make_phone_call_string");

            if (!telnum.equals("none")) {
              out.print(" href=\"" + telnum + tel + "\">");
            } else {
              out.print(" href=\"#\">" + alt);
            }

          } catch (IOException ioe) {
            System.out.println("Error in a tag <caller>: " + ioe);
          }
          return (EVAL_BODY_INCLUDE);
        }
      }

    } catch (Exception e) {
      System.out.println("Error in WALL tag 'caller': " + e.getMessage());
      System.out.println("Error: " + e.toString());
    }

    return (SKIP_BODY);
  }