⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yazdrequest.java

📁 这是学习Java必须读懂两套源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public final ForumThread getThread() throws JspException
  {
    Forum cf = getForum();
    ForumThread ct = null;

    int threadid = js.getThreadID();
    if( threadid < 0 ) {
      Iterator threads = cf.threads(0,1);
      if( threads.hasNext() ) {
        ct = (ForumThread)threads.next();
      }
    } else {
      try {
        ct = cf.getThread(threadid);
      } catch(ForumThreadNotFoundException e) {
        throw new JspException("Could not find thread with ID:" + threadid);
      }
    }
    if( ct == null ) {
      throw new JspException("Yazd thread tag, no threads available for user.");
    }

    return ct;
  }

  /**
   * Gets the current message user is viewing by current message or
   * defaults to first message in current thread.
   *
   * Used by the <b>message</b> tag.
   *
   * @return currently selected Message
   */
  public final ForumMessage getMessage() throws JspException
  {
    ForumThread ct = getThread();
    ForumMessage cm = null;

    int messageid = js.getMessageID();
    try {
      if( messageid < 0 ) {
        cm = ct.getRootMessage();
      } else {
        cm = ct.getMessage(messageid);
      }
    } catch(ForumMessageNotFoundException e) {
        throw new JspException("Could not find message with messageID: " +
           messageid);
    }
    if( cm == null ) {
      throw new JspException("Yazd message tag, no messages available for user.");
    }

    return cm;
  }

  /**
   * NumberOfForums property which can be obtained by the JSP page
   * using the <b>authorize</b> script variable with
   * &lt;jsp:getProperty name=<i>"id"</i> property="numberOfForums"/&gt;
   *
   * @return number of Forums user is authorized to view
   */
  public final String getNumberOfForums() throws JspException
  {
    return "" + getForumFactory().getForumCount();
  }

  /**
   * Date and time of users last visit (integer) property which can be
   * obtained by the JSP page using the <b>authorize</b> script variable with
   * &lt;jsp:getProperty name=<i>"id"</i> property="lastVisit"/&gt;
   *
   * @return date and time of users last visit
   */
  public final String getLastVisit()
  {
    return "" + js.getLastVisit().getTime();
  }

  /**
   * Method used by many tags to add an error to the list of errors
   * which can be returned using the <b>error_loop</b> tag.
   */
  public final void addError(String err)
  {
    error.add((Object)new StringBuffer(err));
  }

  /**
   * Method used by <b>if_error</b> and <b>error_loop</b> tags to
   * get the list of user errors.
   *
   * @return a List of user errors
   */
  public final List getErrorList()
  {
    return error;
  }

  /**
   * Used by the JSP page to set the error for the current request
   * using the <b>authorize</b> script variable with
   * &lt;jsp:setProperty name=<i>"id"</i> property="error" value="<i>string</i>"/&gt;
   */
  public final void setError(String err)
  {
    error.clear();
    error.add((Object)new StringBuffer(err));
  }

  /**
   * Test whether current user is anonymous.
   *
   * @return boolean - true or false
   */
  public final boolean isAnonymous()
  {
    if( js.getLoggedIn() )
      return false;
    return true;
  }

  /**
   * MessageDepth property which can be obtained by the JSP page
   * using the <b>authorize</b> script variable with
   * &lt;jsp:getProperty name=<i>"id"</i> property="messageDepth"/&gt;
   *
   * @return user message_depth display preference
   */
  public final String getMessageDepth()
  {
    return "" + js.getMessageDepth();
  }

  /**
   * Used by the JSP page to set the message_depth display preferences of
   * user for current session using the <b>authorize</b> script variable with
   * &lt;jsp:setProperty name=<i>"id"</i> property="messageDepth" value="<i>integer</i>"/&gt;
   */
  public final void setMessageDepth(String s)
  {
    try {
      js.setMessageDepth(Integer.valueOf(s).intValue());
    } catch(NumberFormatException e) {
    }
  }

  /**
   * ThreadDepth property which can be obtained by the JSP page
   * using the <b>authorize</b> script variable with
   * &lt;jsp:getProperty name=<i>"id"</i> property="threadDepth"/&gt;
   *
   * @return user thread_depth display preference
   */
  public final String getThreadDepth()
  {
    return "" + js.getThreadDepth();
  }

  /**
   * Used by the JSP page to set the thread_depth display preferences of
   * user for current session using the <b>authorize</b> script variable with
   * &lt;jsp:setProperty name=<i>"id"</i> property="theadDepth" value="<i>integer</i>"/&gt;
   */
  public final void setThreadDepth(String s)
  {
    try {
      js.setThreadDepth(Integer.valueOf(s).intValue());
    } catch(NumberFormatException e) {
    }
  }

  /**
   * ItemsPerPage property which can be obtained by the JSP page
   * using the <b>authorize</b> script variable with
   * &lt;jsp:getProperty name=<i>"id"</i> property="itemsPerPage"/&gt;
   *
   * @return user items_per_page display preference
   */
  public final String getItemsPerPage()
  {
    return "" + js.getItemsPerPage();
  }

  /**
   * Used by the JSP page to set the items_per_page display preferences of
   * user for current session using the <b>authorize</b> script variable with
   * &lt;jsp:setProperty name=<i>"id"</i> property="itemsPerPage" value="<i>integer</i>"/&gt;
   */
  public final void setItemsPerPage(String s)
  {
    try {
      js.setItemsPerPage(Integer.valueOf(s).intValue());
    } catch(NumberFormatException e) {
    }
  }

  /**
   * Generate a random password.
   *
   * @return an 8 character password
   */
  public final String GeneratePassword()
  {
    return StringUtils.randomString(8);
  }

  /**
   * Method used by many tags to get the ForumFactory.
   *
   * @return ForumFactory
   */
  public final ForumFactory getForumFactory() throws JspException
  {
    checkYazdState();
    return ff;
  }

  /**
   * Method used by many tags to get the User ProfileManager.
   *
   * @return User ProfileManager
   */
  public final ProfileManager getProfileManager() throws JspException
  {
    checkYazdState();
    if( pm == null )
      pm = ff.getProfileManager();
    if( pm == null )
      throw new JspException("Could not get ProfileManager.");
    return pm;
  }

  /**
   * Method used by many YazdRequest methods to make sure
   * the necessary resources are available.
   *
   * @throws JspException if a resource can not be found
   */
  private void checkYazdState() throws JspException
  {
    if( js == null || js.getAuthorization() == null )
      throw new JspException("YazdState not set for YazdRequest");
    if( ff == null )
      ff = ForumFactory.getInstance(js.getAuthorization());
    if( ff == null )
      throw new JspException("Could not get ForumFactory.");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -