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

📄 foldertreeleftframebean.java

📁 JSP实现的强大功能树型结构框架,非常实用
💻 JAVA
字号:
/** * <p>Title:       folderTreeLeftFrameBean - GCS Document Repository</p> * <p>Description: JavaBean used on folderTreeLeftFrame.jsp page for dynamic content.</p> * <p>Copyright:   Copyright (c) 2002</p> * <p>Company:     Bank of America</p> * @author         Kevin L. Peterson * @version        2.0 */package com.boa.gcib.gcsdr;import java.util.*;import java.sql.*;import com.opentext.api.*;/** * folderTreeLeftFrameBean is JavaBean used on folderTreeLeftFrame.jsp * page for dynamic content. */public class folderTreeLeftFrameBean implements Runnable {  private final static int    ALL_CHILD_OBJECTS         = 0;  private final static int    FOLDER_CHILD_OBJECTS      = 1;  private final static int    DOCUMENT_CHILD_OBJECTS    = 2;  private final static int    MAX_COLUMN_COUNT          = 3;  private String definedTree     												= "";  private int rootNodeID       												  = 0;  private LiveLinkDocFileLoad fileLoad                  = null;  private PreparedStatement stmtFolderChild             = null;  protected String stmtName                             = "stmtFolderTreeChildren";  protected String baseNodeName  												= "aux";  protected String RootFolder    												= DocMgmtGlobal.templateRootFolder;  protected String UseTextLinks  												= "1";  protected String StartAllOpen  												= "0";  protected String IconPath      												= "'" + DocMgmtGlobal.webAppHome + "/images/'";  protected String RightPageLink 												= DocMgmtGlobal.webAppHome + "/FormServer.jsp?NODE_ID=";  /**   * getFileLoad obtains an instantiation of a LiveLinkDocFileLoad   * object from a pool of such objects using the static method,   * LiveLinkDocFileLoad.getFileLoad().   *   * @return LiveLinkDocFileLoad instantiated object   */  protected LiveLinkDocFileLoad	getFileLoad() {    if ( fileLoad == null ) {      fileLoad = LiveLinkDocFileLoad.getFileLoad();    }    return fileLoad;  }  /**   * setFileLoad returns an instantiated LiveLinkDocFileLoad object   * to the pool of such objects using the static method,   * LiveLinkDocFileLoad.setFileLoad(LLObj) when a servlet or method   * no longer needs a Livelink connection object.   *   * @param  LLObj LiveLinkDocFileLoad instantiated object   * @return void (no return value)   */  protected void setFileLoad(LiveLinkDocFileLoad LLObj) {    LiveLinkDocFileLoad.setFileLoad(LLObj);    fileLoad = null;  }	/**	 * init checks the environment to set up defaults based on this system.	 */	protected boolean init() {    boolean bSuccess = false;    try {      LiveLinkDocFileLoad LLObj = getFileLoad();      RootFolder    			= DocMgmtGlobal.templateRootFolder;      DocDetails rootNode = LLObj.getFolder(RootFolder);      rootNodeID          = rootNode.nodeID;      bSuccess            = rootNode.isFolder();    } catch (Exception e) {      LogObject.logError("folderTreeLeftFrameBean.init() --> ", e);    }    return bSuccess;  }	/**	 * getChildList uses a PreparedStatement object to get a ResultSet	 * of child nodes with the parent having the value of ParentNode	 * and returns it as an ArrayList of String arrays. The stmtFolderChild	 * property is initialized from the Livelink object and is called	 * repeatedly until no further children are left below the root	 * node. This is a parameterized query which is assigned ParentNode	 * as the parameter. This allows this object, once created, to be	 * reused by merely assigning a different parameter value and calling	 * the executeQuery() method. Only child nodes which are folders	 * are returned by the query.	 *	 * @param  ParentNode int value of the parent node to find children of.	 * @return ArrayList of String[] objects representing the rows of	 *         the resultset.	 */	protected ArrayList getChildList(int ParentNode) {    ArrayList vRet 					= new ArrayList();    PreparedStatement stmt 	= null;    ResultSet rs 						= null;    try {      stmt = getStmtFolderChild();      stmt.setInt(1, ParentNode);      rs = stmt.executeQuery();      while (rs.next()) {        // make an array of String objects for each row in the resultset        String[] cols = new String[MAX_COLUMN_COUNT];        // get each field in a record into a String in an array        for ( int i = 0; i < MAX_COLUMN_COUNT; i++ ) {          cols[i] = rs.getString(i + 1);        }        // add the array of strings to the ArrayList        vRet.add(cols);      }      rs.close();      vRet.trimToSize();    } catch (Exception e) {      LogObject.logException("folderTreeLeftFrameBean.getChildList() Error: " , e);    }    return vRet;  }	/**	 * This implements the run() method specified by the Runnable	 * interface. A thread can be created which builds the script and	 * assigns it to the global static singleton object as a String.	 */	public void run() {    definedTree = buildScript();    DocMgmtGlobal.setFolderTree(definedTree);  }	/**	 * buildRoot constructs the initial script text for the root of the	 * JavaScript folder tree. All this is done before the Livelink	 * folders are navigated to build the rest of the tree. A StringBuffer	 * is passed to add to for efficiency.	 *	 * @param  buff StringBuffer to be appended to with lines to output	 * @return void (the modified StringBuffer is returned)	 */	private void buildRoot(StringBuffer buff) {		// first print lines required by the JavaScript Treeview author    buff.append("// You can find instructions for this file here: \n");    buff.append("// http://www.treeview.net \n");    buff.append("\n");    buff.append("// Decide if the names are links or just the icons \n");    buff.append("USETEXTLINKS = ");      buff.append(UseTextLinks);      buff.append(";  //replace 0 with 1 for hyperlinks \n");    buff.append("\n");    buff.append("// Decide if the tree is to start all open or just showing the root folders \n");    buff.append("STARTALLOPEN = ");      buff.append(StartAllOpen);      buff.append("; // replace 0 with 1 to show the whole tree \n");    buff.append("\n");    buff.append("ICONPATH = ");      buff.append(IconPath);      buff.append("; // if the gif's folder is a subfolder, for example: 'images/' \n");    buff.append("\n");		// This is the beginning of the JavaScript tree line    buff.append("foldersTree = gFld(\"<i>");      buff.append(RootFolder);      buff.append("</i>\", \"");      buff.append(RightPageLink);      buff.append(Integer.toString(rootNodeID));      buff.append("\"); \n");            // end of the line  }	/**	 * buildChildNodes is used recursively to add nodes to the root of	 * the JavaScript folder tree. One line is created each time this	 * method is called. If there are child nodes, the method is called	 * recursively to create the child node lines. The lines are indented	 * hierarchically to make them easier to read.	 * <P>	 * Makes a text that looks like this:	 * <BR>	 * <BR>	 foldersTree = gFld("<i>Templates</i>", "/FormServer.jsp?NODE_ID=621534");	 * <BR>	   aux1 = insFld(foldersTree, gFld("AAA-DAVE", "/FormServer.jsp?NODE_ID=1496841"));	 * <BR>	   aux1 = insFld(foldersTree, gFld("AAA-LES", "/FormServer.jsp?NODE_ID=1496842"));	 * <BR>	     aux2 = insFld(aux1, gFld("Infinity Only Folder", "/FormServer.jsp?NODE_ID=1484215"));	 * <BR>	     aux2 = insFld(aux1, gFld("Shared Folder", "/FormServer.jsp?NODE_ID=1484327"));	 * <BR>	   aux1 = insFld(foldersTree, gFld("Depository", "/FormServer.jsp?NODE_ID=621254"));	 * <BR>	 * </P>	 * @param  buff StringBuffer to add to (passed on through)	 * @param  parentObj String representation of the parent JavaScript node variable	 * @param  treeLevel integer for what level deep we have gone (used for indenting)	 * @param  parentNode integer Livelink parent node id to find children of	 * @return void (the modified StringBuffer is returned)	 */	private void buildChildNodes(StringBuffer buff,                               String parentObj,                               int treeLevel,                               int parentNode) {		// avoid errors if called with no parentNode parameter value		if ( parentNode <= 0 ) {      return;    }    boolean hasChildren = true;    String newNode   		= baseNodeName + Integer.toString(treeLevel);    String indent    		= "";    int newTreeLevel 		= treeLevel + 1;    int newNodeID     	= 0;		// index values for the row string array    int IDX_NODE_ID 		= 0;    int IDX_NODE_NAME 	= 1;    int IDX_CHILDNODE 	= 2;		// create the prefix blank string to use for indenting by tree level.		for ( int i = 0; i < treeLevel; i++ ) {      indent += "  ";    }    try {      // now we must recursively go through all leaves of the tree      ArrayList childNodes = getChildList(parentNode);      // now navigate through the list and recursively call this method for each child folder node      for ( ListIterator iList = childNodes.listIterator(); iList.hasNext(); ) {        // get a row as a String array from the list        String[] row = (String[]) iList.next();        newNodeID    = Integer.parseInt(row[IDX_NODE_ID]);        hasChildren  = ( Integer.parseInt(row[IDX_CHILDNODE]) > 0 );        // building one line for the JavaScript of the tree        buff.append(indent);              // indent lines hierarchically to make the script easier to read        buff.append(newNode);             // identify the node being created        buff.append(" = insFld(");        // call function to insert a folder into a parent folder        buff.append(parentObj);           // String parameter for the node to add this node to as a child        buff.append(", gFld(\"");         // call inner function to build a new folder object        buff.append(row[IDX_NODE_NAME]);  // String parameter for the display name of the new child folder        buff.append("\", \"");            // comma separator of function parameters        buff.append(RightPageLink);       // String parameter for the URL link to be activated by clicking        buff.append(row[IDX_NODE_ID]);    // String representation of the node ID to be passed to servlet        buff.append("\")); \n");          // end the function call line and output a newline character        if ( hasChildren ) {          // Only look for sub-folders if this node has child items          buildChildNodes(buff, newNode, newTreeLevel, newNodeID);        }      }			// free up any resources this ArrayList is using for garbage collection      childNodes.clear();    } catch (Exception e) {      LogObject.logDebug("folderTreeLeftFrameBean.buildChildNodes() parentFolder --> " + Integer.toString(parentNode));      LogObject.logError("folderTreeLeftFrameBean.buildChildNodes() --> ", e);    }  }	/**	 * getDefinedTree is the getter for the definedTree property. It	 * obtains a string from DocMgmtGlobal using its getFolderTree()	 * method.	 *	 * @return String to assign to the JavaScript for the folder tree.	 */	public String getDefinedTree() {    // definedTree = buildScript();    definedTree = DocMgmtGlobal.getFolderTree();    return definedTree;  }	/**	 * setDefinedTree is the setter for the definedTree property. It	 * assigns a string to the definedTree property. This is not really	 * used since the property is to be maintained internally.	 *	 * @param  newValue String value to assign to definedTree if not null.	 * @return void (no return value)	 */  public void setDefinedTree(String newValue) {    if ( newValue != null ) {      definedTree = newValue;    }  }	/**	 * buildScript is the main method to use to build the string for	 * the definedTree property. It obtains a LiveLink object to use	 * to read the folder structure of the template area and when it	 * is done, returns the object back to a pool.	 *	 * @return String JavaScript to use for the tree.	 */	public String buildScript() {    StringBuffer buff = new StringBuffer("");    if ( init() ) {      buildRoot(buff);      LiveLinkDocFileLoad LLObj = getFileLoad();      buildChildNodes(buff, "foldersTree", 1, rootNodeID);      setStmtFolderChild(stmtFolderChild);      setFileLoad(LLObj);    }    return buff.toString();  }	/**	 * getRootNodeID getter for rootNodeID.	 *	 * @return integer value of the rootNodeID.	 */	public int getRootNodeID() {    return rootNodeID;  }	/**	 * setRootNodeID setter for rootNodeID.	 *	 * @param  newRootNode integer value to set rootNodeID to.	 * @return void (no return value)	 */  public void setRootNodeID(int newRootNode) {    rootNodeID = newRootNode;  }	/**	 * setStmtFolderChild setter for stmtFolderChild property. This	 * method does not follow the expected operation of a property	 * setter in that it takes a returned PreparedStatement object	 * that is passed as a parameter and closes it. It also removes	 * from the LiveLink object the PreparedStatement created for	 * stmtName when getStmtFolderChild() was called. Finally, it	 * sets the stmtFolderChild property to null.	 *	 * @param  newStmtFolderChild PreparedStatement object being returned.	 * @return void (no return value)	 */	public void setStmtFolderChild(PreparedStatement newStmtFolderChild) {    try {      LiveLinkDocFileLoad LLObj =	getFileLoad();      LLObj.closeStatementByName(stmtName);      if ( (newStmtFolderChild != null) ) {        newStmtFolderChild.close();      }    } catch (SQLException e) {      LogObject.logError("folderTreeLeftFrameBean.setStmtFolderChild() --> ", e);    }    stmtFolderChild = null;  }	/**	 * getStmtFolderChild getter for stmtFolderChild property. This	 * method creates the SQL for the PreparedStatement property and	 * adds it to the LiveLink object unless one already exists there.	 *	 * @return PreparedStatement object created or retrieved.	 */	public PreparedStatement getStmtFolderChild() {    if ( stmtFolderChild == null ) {      String querySQL =        "SELECT DATAID, NAME, CHILDCOUNT " +          "FROM DTREE " +         "WHERE PARENTID = ? " +           "AND SUBTYPE  = 0 " +        "ORDER BY NAME";      LiveLinkDocFileLoad LLObj =	getFileLoad();      stmtFolderChild = LLObj.getStatementByName(stmtName, querySQL);    }    return stmtFolderChild;  }}

⌨️ 快捷键说明

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