public static boolean dumpItem(int itemId) {
   String pageName = ItemDefinitions.getItemDefinitions(itemId).getName();
   if (pageName == null || pageName.equals("null")) return false;
   pageName = pageName.replace("(p)", "");
   pageName = pageName.replace("(p+)", "");
   pageName = pageName.replace("(p++)", "");
   pageName = pageName.replaceAll(" ", "_");
   try {
     WebPage page = new WebPage("http://runescape.wikia.com/wiki/" + pageName);
     try {
       page.load();
     } catch (Exception e) {
       System.out.println("Invalid page: " + itemId + ", " + pageName);
       return false;
     }
     boolean isNextLine = false;
     for (String line : page.getLines()) {
       if (!isNextLine) {
         if (line.equals(
             "<th nowrap=\"nowrap\"><a href=\"/wiki/Examine\" title=\"Examine\">Examine</a>"))
           isNextLine = true;
       } else {
         String examine = line.replace("</th><td> ", "");
         examine = examine.replace("</th><td>", "");
         examine = examine.replace("<i> ", "");
         examine = examine.replace("</i> ", "");
         examine = examine.replace("&lt;colour&gt; ", "");
         examine = examine.replace("(bright/thick/warm)", "bright");
         examine = examine.replace("(Temple of Ikov) ", "");
         examine = examine.replace("(Fight Arena) ", "");
         try {
           BufferedWriter writer = new BufferedWriter(new FileWriter("itemExamines.txt", true));
           writer.write(itemId + " - " + examine);
           writer.newLine();
           writer.flush();
           writer.close();
         } catch (IOException e) {
           e.printStackTrace();
         }
         return true;
       }
     }
   } catch (MalformedURLException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
     return dumpItem(itemId);
   }
   return false;
 }
Beispiel #2
0
 /**
  * Returns the title of the <code>WebPage</code> corresponding to the <code>RequestContext</code>.
  * The page may need to be partially executed.
  *
  * @param ctx
  */
 public static String getTitle(WebPage page, RequestContext ctx) throws Exception {
   // Attach the request context to this thread
   RequestContext prevCtx = RequestContext.setCurrent(ctx);
   try {
     // Check authorization
     if (page.isAuthorized() == false) {
       throw new UnauthorizedException();
     }
     page.init();
     return page.getTitle();
   } finally {
     // Restore the request context for this thread
     RequestContext.setCurrent(prevCtx);
   }
 }
Beispiel #3
0
 protected WCRectangle fwkGetScreenRect(boolean available) {
   if (log.isLoggable(Level.FINER)) {
     log.log(Level.FINER, "getScreenRect({0})", available);
   }
   WebPageClient pageClient = page.getPageClient();
   return pageClient != null ? pageClient.getScreenBounds(available) : null;
 }
  public static void writeMenu(
      PrintWriter out,
      RequestProperties reqState,
      String menuID,
      boolean expandableMenu,
      boolean showIcon,
      int descriptionType,
      boolean showMenuHelp)
      throws IOException {
    PrivateLabel privLabel = reqState.getPrivateLabel();
    Locale locale = reqState.getLocale();
    String parentPageName = null;
    Account account = reqState.getCurrentAccount();

    /* disable menu help if menu description is not displayed */
    boolean showInline = false;
    if (descriptionType == ExpandMenu.DESC_NONE) {
      showMenuHelp = false;
      showInline = true;
    }

    /* sub style classes */
    String topMenuID =
        !StringTools.isBlank(menuID) ? menuID : (expandableMenu ? "expandMenu" : "fixedMenu");
    String groupClass = "menuGroup";
    String leafClass = "itemLeaf";
    String leafDescClass = "itemLeafDesc";
    String helpClass = "itemLeafHelp";
    String helpPadClass = "itemLeafHelpPad";
    String leafIconClass = "itemLeafIcon";

    /* start menu */
    out.println("<ul id='" + topMenuID + "'>");

    /* iterate through menu groups */
    Map<String, MenuGroup> menuMap = privLabel.getMenuGroupMap();
    for (String mgn : menuMap.keySet()) {
      MenuGroup mg = menuMap.get(mgn);
      if (!mg.showInTopMenu()) {
        // skip this group
        // Print.logInfo("Skipping menu group: %s", mgn);
        continue;
      }

      boolean didDisplayGroup = false;
      for (WebPage wp : mg.getWebPageList(reqState)) {
        String menuName = wp.getPageName();
        String iconURI = showIcon ? wp.getMenuIconImage() : null; // may be blank/null
        String menuHelp = wp.getMenuHelp(reqState, parentPageName);
        String url = wp.encodePageURL(reqState); // , RequestProperties.TRACK_BASE_URI());

        /* skip login page */
        if (menuName.equalsIgnoreCase(Constants.PAGE_LOGIN)) {
          // omit login
          // Print.logInfo("Skipping login page: %s", menuName);
          continue;
        }

        /* skip sysAdmin pages */
        if (wp.systemAdminOnly() && !Account.isSystemAdmin(account)) {
          continue;
        }

        /* skip pages that are not ok to display */
        if (!wp.isOkToDisplay(reqState)) {
          continue;
        }

        /* menu description */
        String menuDesc = null;
        switch (descriptionType) {
          case DESC_NONE:
            menuDesc = null;
            break;
          case DESC_SHORT:
            menuDesc = wp.getNavigationDescription(reqState);
            break;
          case DESC_LONG:
          default:
            menuDesc = wp.getMenuDescription(reqState, parentPageName);
            break;
        }

        /* skip this menu item? */
        if (StringTools.isBlank(menuDesc) && StringTools.isBlank(iconURI)) {
          // Print.logWarn("Menu name has no description: %s", menuName);
          continue;
        }

        /* start menu group */
        if (!didDisplayGroup) {
          // open Menu Group
          didDisplayGroup = true;
          out.write("<li class='" + groupClass + "'>" + mg.getTitle(locale) + "\n");
          if (showInline) {
            out.write("<br><table cellpadding='0' cellspacing='0' border='0'><tr>\n");
          } else {
            out.write("<ul>\n"); // <-- start menu sub group
          }
        }

        /* menu anchor/link */
        String anchorStart = "<a";
        if (!StringTools.isBlank(menuHelp)) {
          anchorStart += " title=\"" + menuHelp + "\"";
        }
        String target =
            StringTools.blankDefault(wp.getTarget(), "_self"); // ((WebPageURL)wp).getTarget();
        if (target.startsWith("_")) {
          anchorStart += " href=\"" + url + "\"";
          anchorStart += " target=\"" + target + "\"";
        } else {
          PixelDimension pixDim = wp.getWindowDimension();
          if (pixDim != null) {
            int W = pixDim.getWidth();
            int H = pixDim.getHeight();
            anchorStart +=
                " onclick=\"javascript:openFixedWindow('"
                    + url
                    + "','"
                    + target
                    + "',"
                    + W
                    + ","
                    + H
                    + ")\"";
            anchorStart += " style=\"text-decoration: underline; color: blue; cursor: pointer;\"";
          } else {
            anchorStart += " href=\"" + url + "\"";
            anchorStart += " target=\"" + target + "\"";
          }
        }
        anchorStart += ">";

        /* inline? */
        if (showInline) {

          /* menu icon (will not be blank here) */
          out.write("<td class='" + leafIconClass + "'>");
          if (!StringTools.isBlank(iconURI)) {
            out.write(
                anchorStart + "<img class='" + leafIconClass + "' src='" + iconURI + "'/></a>");
          } else {
            out.write("&nbsp;");
          }
          out.write("</td>");

        } else {

          /* start menu list item */
          out.write("<li class='" + leafClass + "'>");

          /* special case for non-icons */
          if (StringTools.isBlank(iconURI)) {

            /* menu description/help */
            if (!StringTools.isBlank(menuDesc)) {
              out.write(
                  "<span class='" + leafDescClass + "'>" + anchorStart + menuDesc + "</a></span>");
              if (showMenuHelp && !StringTools.isBlank(menuHelp)) {
                out.write("<br>");
                out.write("<span class='" + helpPadClass + "'>" + menuHelp + "</span>");
              }
            }

          } else {
            // this section may not appear as expected on IE

            /* start table */
            out.write("<table class='" + leafClass + "' cellpadding='0' cellspacing='0'>");
            out.write("<tr>");

            /* menu icon */
            if (!StringTools.isBlank(iconURI)) {
              out.write("<td class='" + leafIconClass + "'>");
              out.write(
                  anchorStart + "<img class='" + leafIconClass + "' src='" + iconURI + "'/></a>");
              out.write("</td>");
            }

            /* menu description/help */
            if (!StringTools.isBlank(menuDesc)) {
              out.write("<td class='" + leafDescClass + "'>");
              out.write(
                  "<span class='" + leafDescClass + "'>" + anchorStart + menuDesc + "</a></span>");
              if (showMenuHelp && !StringTools.isBlank(menuHelp)) {
                out.write("<br>");
                out.write("<span class='" + helpClass + "'>" + menuHelp + "</span>");
              }
              out.write("</td>");
            }

            /* end table */
            out.write("</tr>");
            out.write("</table>");
          }

          /* end menu list item */
          out.write("</li>\n");
        }
      }

      /* end menu group */
      if (didDisplayGroup) {
        if (showInline) {
          out.write("</tr></table>\n");
        } else {
          out.write("</ul>\n");
        }
        out.write("</li>\n");
      }
    }

    /* end of menu */
    out.write("</ul>\n");

    /* init menu if expandable */
    if (expandableMenu) {
      out.write(
          "<script type=\"text/javascript\"> new ExpandMenu('" + topMenuID + "'); </script>\n");
    }
  }
Beispiel #5
0
  public static WebPage lookup(RequestContext ctx) throws Exception {
    Class<? extends WebPage> pageClass = null;

    //		String cmd1 = ctx.getCommand(1);
    //		String cmd2 = ctx.getCommand(2);
    //		Class<? extends WebPage> pageClass = null;
    //		if (cmd2!=null)
    //		{
    //			pageClass = pages.get(cmd1 + "/" + cmd2);
    //		}
    //		if (pageClass==null)
    //		{
    //			pageClass = pages.get(cmd1);
    //		}

    // For guided setup pages, dispatch based on what comes after the "setup/" prefix
    String setupPrefix = UrlGenerator.COMMAND_SETUP + "/";
    String cmd = ctx.getCommand();
    if (cmd.startsWith(setupPrefix)) {
      cmd = cmd.substring(setupPrefix.length());

      int slash = cmd.length();
      do {
        pageClass = pages.get(cmd.substring(0, slash));
        slash = cmd.lastIndexOf("/", slash - 1);
      } while (slash > 0 && pageClass == null);
    }

    // Look up by exact command
    cmd = ctx.getCommand();
    if (pageClass == null) {
      int slash = cmd.length();
      do {
        pageClass = pages.get(cmd.substring(0, slash));
        slash = cmd.lastIndexOf("/", slash - 1);
      } while (slash > 0 && pageClass == null);
    }

    // Lookup by suffix
    if (pageClass == null) {
      //			String cmd = ctx.getCommand();
      int dot = cmd.lastIndexOf(".");
      if (dot >= 0) {
        pageClass = pages.get("*" + cmd.substring(dot));
      }
    }

    if (pageClass == null) {
      return null;
    }

    // Instantiate
    WebPage pg = pageClass.newInstance();
    if (pg == null) {
      return null;
    }

    // Create envelope if needed
    if (pg.isEnvelope() && envelope != null) {
      WebPage env = (WebPage) envelope.newInstance();
      if (env != null) {
        env.setChild(pg);
        pg = env;
      }
    }

    return pg;
  }
Beispiel #6
0
  /**
   * Executes the <code>WebPage</code> corresponding to the <code>RequestContext</code>.
   *
   * @param ctx
   */
  public static void execute(WebPage page, RequestContext ctx) throws Exception {
    // Attach the request context to this thread
    RequestContext prevCtx = RequestContext.setCurrent(ctx);

    try {
      // Check authorization
      if (page.isAuthorized() == false) {
        throw new UnauthorizedException();
      }

      // Redirect from HTTP to HTTPS and vice versa, as needed
      // But do not redirect POST requests from HTTPS to HTTP since they cause infinite redirection
      // loop
      boolean ssl = page.isSecureSocket() && Setup.isSSL();
      if (ssl != ctx.isSecureSocket()
          && Channel.isSupportsSecureSocket(ctx.getChannel())
          && (ctx.getMethod().equalsIgnoreCase("GET") || ssl == true)) {
        throw new SecureSocketException();
      }

      // Update last activity date of user once every 1/4 session
      Date now = new Date();
      User user = UserStore.getInstance().load(ctx.getUserID());
      if (user != null
          && (ctx.getMethod().equalsIgnoreCase("POST") || Channel.isPush(ctx.getChannel()) == false)
          && (user.getLastActive() == null
              || user.getLastActive().getTime() + Setup.getSessionLength() / 4L < now.getTime())) {
        user = (User) user.clone();
        user.setLastActive(now);
        UserStore.getInstance().save(user);
      }

      page.init();

      if (ctx.getMethod().equalsIgnoreCase("POST")) {
        // Counter XSS attacks by checking that form data includes the session ID
        String sessionParam = ctx.getParameter(RequestContext.PARAM_SESSION);
        boolean sessionParamMatch =
            sessionParam != null && sessionParam.equals(ctx.getSessionID().toString());
        if (page.isProtectXSS() && ctx.getSessionID() != null && !sessionParamMatch) {
          throw new BadRequestException();
        }

        // Validate and commit the form
        if (page.isActionable()) {
          try {
            page.validate();

            // Actions
            if (!Util.isEmpty(ctx.getParameter(RequestContext.PARAM_ACTION))) {
              // Log the event
              LogEntryStore.log(new ActionLogEntry());
            }

            page.setCommitted(true);
            page.commit(); // May throw RedirectException, PageNotFoundException, etc.
          } catch (WebFormException webFormExc) {
            page.setFormException(webFormExc);
          }
        } else {
          // Page does not support POST
          throw new PageNotFoundException();
        }
      }
      page.render();
    } finally {
      // Restore the request context for this thread
      RequestContext.setCurrent(prevCtx);
    }
  }
Beispiel #7
0
 protected int fwkGetScreenDepth() {
   log.log(Level.FINER, "getScreenDepth");
   WebPageClient pageClient = page.getPageClient();
   return pageClient != null ? pageClient.getScreenDepth() : 24;
 }