📄 walktag.java
字号:
message_num++; return EVAL_BODY_TAG; } else { wd.valid = false; } }// System.out.println("Walk back up the message tree."); // Parent has no more children or exceeded items_per_page, // so reduce message depth by one cm = null; if( thread_depth < 1 ) {// System.out.println(nextItem()); return SKIP_BODY; } if( is_total ) { thread_depth--; shallower++; is_total = false; return EVAL_BODY_TAG; } if( message_num < js.getItemsPerPage() ) { wd = (WalkData)stack.get(thread_depth-1);// System.out.println("Back to parent message: " + wd.getMessage().getID() ); if( wd.getChildIndex() < wd.getChildCount() ) {// System.out.println("Now Parent has a sibling"); cm = tw.getChild(wd.getMessage(),wd.getChildIndex()); wd.setChildIndex(wd.getChildIndex()+1); WalkData nw = null; if( stack.size() <= thread_depth ) { nw = new WalkData(); stack.addLast((Object)nw); } else { // Object reuse is good! nw = (WalkData)stack.get(thread_depth); nw.valid = true; nw.setChildIndex(0); } nw.setMessage(tw,cm); wd = nw; message_num++; return EVAL_BODY_TAG; } else { wd.valid = false; } } thread_depth--; shallower++;// System.out.println("thread_depth=" + thread_depth +// " valid=" + ((WalkData)stack.get(0)).valid); if( thread_depth == 0 && stack.size() > 0 && ((WalkData)stack.get(0)).valid) {// System.out.println("WalkTag page = true"); is_exit = next_page = true; nextHref(); } return EVAL_BODY_TAG; } /** * Method called at end of walk Tag to output content * * @return EVAL_PAGE */ public final int doEndTag() throws JspException { try { if(bodyContent != null) bodyContent.writeOut(bodyContent.getEnclosingWriter()); } catch(java.io.IOException e) { throw new JspException("IO Error: " + e.getMessage()); } return EVAL_PAGE; } /** * Maintains state information while walking a thread tree of * messages. */ public final class WalkData { ForumMessage mes = null; int child_count = 0; int child_index = 0; boolean valid = true; /** * Set the message this WalkData represents */ public final void setMessage(TreeWalker tw, ForumMessage wm) { mes = wm; child_count = tw.getChildCount(wm); } /** * Get the message this WalkData represents * * @return ForumMessage */ public final ForumMessage getMessage() { return mes; } /** * Number of children this message has * * @return total number of child messages this message has */ public final int getChildCount() { return child_count; } /** * Get current index into a messages children we are looking at, * used for iterating through a messages children. * * @return current index into messages children */ public final int getChildIndex() { return child_index; } /** * Set the current index into a messages children, * used for iterating through a messages children. */ public final void setChildIndex(int i) { child_index = i; } } /** * Used by message tag to get current message * * @return current ForumMessage */ public final ForumMessage getMessage() { return cm; } /** * Used by current_depth, while_child, and while_parent tags * to get current depth while walking thread * * @return String - current message depth in thread */ public final int getDepth() { return thread_depth; } /** * Used by while_new_child tag to flag a new depth in the thread * * @return true if thread depth is deeper, false if it isn't any more deeper */ public final boolean isDeeper() { if( deeper > 0 ) { deeper--; return true; } return false; } /** * Used by while_new_parent tag to flag walking back to a * shallower message depth. * * @return true if thread depth is shallower, false if it isn't any more shallow */ public final boolean isShallower() { if( shallower > 0 ) { shallower--; return true; } return false; } /** * Used by is_parent tag to detect if this is a parent message of * the first new message to display after paging to a subsequent * page. * * @return true if this is a parent, false if not */ public final boolean isParent() { if( parent_done ) return false; return true; } /** * Used by is_message tag to detect if this is a new message * below the users messageDepth preference. * * @return true if this is a message below messageDepth, false if not */ public final boolean isMessage() { if( !parent_done ) return false; if( thread_depth < js.getMessageDepth() ) return true; return false; } /** * Used by is_summar tag to detect if this is a new message * greater than or equal to the users messageDepth preference, * but below the users threadDepth preference. * * @return true if this is a message greater than or equal to the users messageDepth preference, but below the users threadDepth preference; false if not */ public final boolean isSummary() { if( !parent_done ) return false; if( thread_depth < js.getMessageDepth() ) return false; if( thread_depth >= js.getThreadDepth() ) return false; return true; } /** * Used by is_total tag to detect if this is a new message * greater than or equal to the users threadDepth preference. * * @return true if this is a new message greater than or equal to the users threadDepth preference, false if not */ public final boolean isTotal() { if( !parent_done ) return false; if( thread_depth >= js.getThreadDepth() && thread_depth >= js.getMessageDepth() ) return true; return false; } /** * Used by message tag to get the total number of child messages * (replies) to the current message. * * @return number of child messages (replies) */ public final int getTotal() { return tw.getRecursiveChildCount(cm); } /** * Used by <b>on_entry</b> tag to detect if this is the first iteration * of the loop. * * @return true or false */ public final boolean isEntry() { return is_entry; } /** * Used by <b>on_exit</b> tag to detect if this is the last iteration * of the loop. * * @return true or false */ public final boolean isExit() { return is_exit; } /** * Used by <b>next_page</b> tag to detect if walk could continue * on another page. * * @return true or false */ public final boolean isNextPage() { return next_page; } /** * Used by <b>prev_page</b> tag to detect if message listing * has a previous page. * * @return true or false */ public final boolean isPrevPage() { return prev_page; } /** * Used by <b>next_item</b> tag to return query portion of an HTML GET href * for paging to next list of messages to walk in thread. * * @return String - query portion of an HTML GET href */ public final String nextItem() { return next_href; } private void nextHref() { StringBuffer args = new StringBuffer(); if( next_page ) { int num = stack.size(); WalkData nw; WalkData pw; boolean back_walk = true; for( int i = num-1; i > 0; i-- ) { nw = (WalkData)stack.get(i);// System.out.println("i: " + i + " ID: " + nw.getMessage().getID() +// " valid=" + nw.valid + " back_walk=" + back_walk +// " Index: " + nw.getChildIndex() + " Count: " + nw.getChildCount()); if( nw.valid ) { if( back_walk ) { if( nw.getChildIndex() >= nw.getChildCount() ) { pw = (WalkData)stack.get(i-1);// System.out.println("previous: " + i + " ID: " + pw.getMessage().getID() +// " valid=" + pw.valid + " back_walk=" + back_walk +// " Index: " + pw.getChildIndex() + " Count: " + pw.getChildCount()); if( pw.getChildIndex() < pw.getChildCount() ) { args.append("walk_back=true&"); args.append("walk_" + i + "=" + nw.getMessage().getID() + "&"); back_walk = false; } } else { back_walk = false; args.append("walk_" + i + "=" + nw.getMessage().getID() + "&"); } } else { args.append("walk_" + i + "=" + nw.getMessage().getID() + "&"); } } } } if( args.length() > 0 ) { args.setLength(args.length()-1); }// System.out.println("WalkTag page args: " + args); next_href = args.toString(); if( current_href != null ) { js.addMessagePage(current_href,next_href); } } /** * Used by <b>prev_item</b> tag to return query portion of an HTML GET href * for paging to previous list of messages. * * @return String - query portion of an HTML GET href */ public final String prevItem() { if( current_href != null ) { String tmp = null; tmp = js.getMessagePage(current_href); if( tmp != null ) return tmp; } return ""; } /** * Set name of thread id to use */ public final void setThread(String tid) { thread = tid; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -