[參考]Domino中Java代理編寫的Showfile參考

import java.util.Vector;

import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;

// 表單顯示代理1.0
// 作者:wnight88
// 2009年2月27日
public class showfileNew extends AgentBase
{
  String htmlString = "";
  String path = "";
  String viewName = "";

  public String getHeadHtml(Vector headList)
  {
    String tempString = "";
    tempString = tempString
        + "<table class=tbbg align=center cellpadding=2 cellspacing=1>";
    tempString = tempString + "<tr class=toptrbg>";
    for (int i = 0; i < headList.size(); i++)
    {
      tempString = tempString + "<td align=center nowrap>"
          + headList.get(i) + "</td>";
    }
    tempString = tempString + "<td align=center nowrap>選擇</td>";
    tempString = tempString + "</tr>";
    return tempString;
  }

  public String getBodyHtml(Vector fieldsList, ViewEntry entry,
      String fieldNameOfLink) throws NotesException
  {
    String tempString = "<tr class=trbg>";
    Document doc = entry.getDocument();
    for (int i = 0; i < fieldsList.size(); i++)
    {
      tempString = tempString + "<td>";
      if (((String) fieldsList.get(i)).equals(fieldNameOfLink))
      {
        tempString = tempString + "<a href='" + path + "/" + viewName
            + "/" + doc.getUniversalID() + "?opendocument'>";
        tempString = tempString
            + doc.getItemValueString((String) fieldsList.get(i));
        tempString = tempString + "</a>";

      }
      else
      {
        tempString = tempString
            + doc.getItemValueString((String) fieldsList.get(i));
      }
      tempString = tempString + "</td>";
    }
    tempString = tempString + "<td align=center nowrap>"
        + "<input class='hinput' type='checkbox' name='SelDoc' value="
        + doc.getUniversalID() + "></td>";
    tempString = tempString + "</tr>";
    return tempString;
  }

  public void NotesMain()
  {

    try
    {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      Database currentDB = agentContext.getCurrentDatabase();

      // 當前文檔
      Document currentDoc = agentContext.getDocumentContext();

      // 獲取要列出記錄的視圖名稱
      viewName = currentDoc.getItemValueString("viewName");
      // 獲取每頁顯示行數
      int lineNum = currentDoc.getItemValueInteger("lineNum");
      // 當前表單地址
      String url = currentDoc.getItemValueString("curl");
      // 當前頁
      int currentPage = currentDoc.getItemValueInteger("curpage");
      path = currentDoc.getItemValueString("path");
      View view = currentDB.getView(viewName);
      ViewEntryCollection vec = view.getAllEntries();

      // 計算總文檔數和總頁數
      int totalDoc, totalPage;
      totalDoc = vec.getCount();
      if (totalDoc % lineNum == 0)
      {
        totalPage = totalDoc / lineNum;
      }
      else
      {
        totalPage = (totalDoc / lineNum) + 1;
      }

      // 計算每頁開始的文檔號、結束的文檔號
      int beginDocNo, endDocNo;
      if (currentPage == 1)
      {
        if (currentPage != totalPage)
        {
          beginDocNo = 1;
          endDocNo = lineNum;
        }
        else
        {
          beginDocNo = 1;
          endDocNo = totalDoc;
        }
      }
      else if (totalDoc < lineNum)
      {
        beginDocNo = 1;
        endDocNo = totalDoc;
      }
      else
      {
        beginDocNo = currentPage * lineNum - lineNum;
        if (currentPage != totalPage)
        {
          endDocNo = currentPage * lineNum;
        }
        else
        {
          endDocNo = totalDoc;
        }
      }

      // 顯示頭信息
      Vector headList = currentDoc.getItemValue("headSet");
      htmlString = htmlString + this.getHeadHtml(headList);

      // 顯示記錄內容
      Vector fieldsOfBody = currentDoc.getItemValue("fieldsOfBody");
      String fieldNameOfLink = currentDoc
          .getItemValueString("filedNameOfLink");
      for (int i = beginDocNo; i <= endDocNo; i++)
      {
        htmlString = htmlString
            + this.getBodyHtml(fieldsOfBody, vec.getNthEntry(i),
                fieldNameOfLink);
      }
      htmlString = htmlString + "</tr>";
      htmlString = htmlString + "</table>";
      currentDoc.replaceItemValue("htmlStr", htmlString);

      // 顯示分頁信息
      int prePageNo, nextPageNo, firstPageNo, lastPageNo;
      if (currentPage <= 1)
      {
        prePageNo = 1;
        nextPageNo = 2;
      }
      else if (currentPage >= totalPage)
      {
        prePageNo = currentPage - 1;
        nextPageNo = currentPage;
      }
      else
      {
        prePageNo = currentPage - 1;
        nextPageNo = currentPage + 1;
      }
      firstPageNo = 1;
      lastPageNo = totalPage;
      String firstPageURL, lastPageURL, prePageURL, nextPageURL;
      firstPageURL = "/" + url + "&page=" + firstPageNo;
      lastPageURL = "/" + url + "&page=" + lastPageNo;
      prePageURL = "/" + url + "&page=" + prePageNo;
      nextPageURL = "/" + url + "&page=" + nextPageNo;
      htmlString = "";
      htmlString = htmlString
          + "<table border=0 align=center cellpadding=2 cellspacing=1 >"
          + "<tr bgcolor=ffffff><td>";
      htmlString = htmlString + "共有" + totalDoc + "個文檔 合計" + totalPage
          + "頁 ";
      htmlString = htmlString + "<a href='" + firstPageURL
          + "'>[首頁]</a> ";
      htmlString = htmlString + "<a href='" + prePageURL + "'>[上一頁]</a> ";
      htmlString = htmlString + "<a href='" + nextPageURL
          + "'>[下一頁]</a> ";
      htmlString = htmlString + "<a href='" + lastPageURL + "'>[尾頁]</a> ";
      htmlString = htmlString + "</td>";
      htmlString = htmlString + "</tr>";
      htmlString = htmlString + "</table>";

      currentDoc.replaceItemValue("pageStr", htmlString);
      // (Your code goes here)

    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章