📄 messagelooptag.java
字号:
} catch(Exception e) {
}
if( ft == null ) {
throw new JspException("Yazd message_loop tag could not find forum.");
}
// Get the HTML input parameter begin to setup where message_loop
// should start
ServletRequest req = pageContext.getRequest();
String tmp = req.getParameter("begin");
if( tmp != null && tmp.length() > 0 ) {
try {
begin = Integer.valueOf(tmp).intValue();
} catch(NumberFormatException e) {
}
}
QueryTag qt = null;
try {
qt = (QueryTag)pageContext.getAttribute(query,PageContext.PAGE_SCOPE);
} catch(Exception e) {
throw new JspException(
"Yazd message tag, could not find query tag with id: " + query);
}
Map properties = qt.getQuery();
Query q = ft.getForum().createQuery();
if( properties.get("beforeDate") != null ) {
tmp = (String)properties.get("beforeDate");
try {
if( tmp != null && tmp.length() > 0 ) {
Date date = new Date(Long.valueOf(tmp).longValue());
q.setBeforeDate(date);
}
} catch(Exception e) {
throw new JspException("Yazd message tag, bad query tag beforeDate");
}
}
if( properties.get("afterDate") != null ) {
tmp = (String)properties.get("afterDate");
try {
if( tmp != null && tmp.length() > 0 ) {
Date date = new Date(Long.valueOf(tmp).longValue());
q.setAfterDate(date);
}
} catch(Exception e) {
throw new JspException("Yazd message tag, bad query tag afterDate");
}
}
if( properties.get("queryString") != null ) {
tmp = (String)properties.get("queryString");
if( tmp == null ) {
throw new JspException("Yazd message tag, bad query tag queryString");
}
if( tmp.length() > 0 )
q.setQueryString(tmp);
}
if( properties.get("userID") != null ) {
tmp = (String)properties.get("userID");
try {
ProfileManager pm = jr.getProfileManager();
User user = pm.getUser(tmp);
q.filterOnUser(user);
} catch(UserNotFoundException ue) {
// System.out.println("Search Query User: " + tmp + " not found.");
} catch(Exception e) {
throw new JspException("Yazd message tag, bad query tag userID:" +
e.getMessage());
}
}
mit = q.results(begin,js.getItemsPerPage());
if( mit == null ) {
throw new JspException("Yazd message_loop tag could not get Iterator for forum messages.");
}
if( !mit.hasNext() )
return SKIP_BODY;
cm = (ForumMessage)mit.next();
message_num++;
if( !mit.hasNext() ) {
is_exit = true;
if( message_num >= js.getItemsPerPage() )
next_page = true;
}
if( begin > 0 )
prev_page = true;
return EVAL_BODY_TAG;
}
/**
* Method called at end of each message_loop Tag Body
*
* @return an EVAL_BODY_TAG if message_loop should continue, or a SKIP_BODY if message_loop is completed.
*/
public final int doAfterBody() throws JspException
{
is_entry = prev_page = false;
message_num++;
if( !mit.hasNext() ) {
return SKIP_BODY;
}
cm = (ForumMessage)mit.next();
if( !mit.hasNext() ) {
is_exit = true;
if( message_num >= js.getItemsPerPage() )
next_page = true;
}
return EVAL_BODY_TAG;
}
/**
* Method called at end of message_loop Tag
* @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;
}
/**
* Set the forum message query to use
*/
public final void setQuery(String qry)
{
query = qry;
}
/**
* Used by <b>message</b> tag to get the current ForumMessage
*
* @return ForumMessage
*/
public final ForumMessage getMessage()
{
return cm;
}
/**
* Return total number of messages in thread, required by
* GetNestedMessage.
*
* @return String - thread MessageCount
*/
public final int getTotal()
{
return 0;
}
/**
* 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 message listing 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.
*
* @return String - query portion of an HTML GET href
*/
public final String nextItem()
{
return "begin=" + (begin+message_num);
}
/**
* 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()
{
int prev = begin - js.getItemsPerPage();
if( prev < 0 )
prev = 0;
return "begin=" + prev;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -