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

📄 categorytreeview.jsp

📁 一个免费wap站
💻 JSP
字号:
<?xml version="1.0" encoding="gb2312" ?>
<%@ page language="java" contentType="text/html; charset=gb2312"
	pageEncoding="gb2312"
	import="java.util.*,
		org.w3c.dom.*,
		javax.xml.parsers.*,
		com.eline.wap.common.util.*,
		com.eline.wap.resource.model.*,
		com.eline.wap.resource.exceptions.*,
		com.eline.wap.resource.client.*"%>
<%!
///
/// 用于将资源导入指定的目录
///

private String[] urls = {
		"bookListView.jsp",
		"newsListView.jsp",
		"ringListView.jsp",
		"pictureListView.jsp",
		"j2meListView.jsp",
		"animationListView.jsp",
};
/// <summary>
/// 以字符串形式返回树状视图
/// </summary>
/// <returns> String-xhtml body
///
public String buildCategoryXmlTree(int type) throws ResourceException {
	try {
		// 获取所有的指定类型的类目(按parentId排序)
		CategoryHelper ch = new CategoryHelper();
		List list = ch.getCategoriesForXmlTree(type);

		// 建立xml文档
		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		Document doc = builder.newDocument();

		Element frameTable = doc.createElement("table");
		frameTable.setAttribute("cellspacing", "0");
		frameTable.setAttribute("cellpadding", "0");
		frameTable.setAttribute("border", "0");
		frameTable.setAttribute("width", "100%");
		frameTable.setAttribute("class", "menuBar");
		doc.appendChild(frameTable);
		Element frameRow = doc.createElement("tr");
		frameTable.appendChild(frameRow);
		Element frameCol = doc.createElement("td");
		frameRow.appendChild(frameCol);

		// 建立根目录
		Category rootItem = new Category();
		rootItem.setIndexId(0);
		rootItem.setName("根节点");
		rootItem.setType(type);
		rootItem.setCategoryAttribute(Category.ATTRIBUTE_DIR);
		frameCol.appendChild(newTreeElement(doc, rootItem));

		// 将List中记录转换成xml节点
		for (int i = 0; i < list.size(); i++) {
			Category item = (Category) list.get(i);
			Element parent = null;

			// 获取父节点
			NodeList nodes = frameCol.getElementsByTagName("td");
			for (int j = 0; j < nodes.getLength(); j ++) {
				Element e1 = (Element) nodes.item(j);
				if (e1.getAttribute("id") != null && e1.getAttribute("id").equals("t_" + item.getParentId())) {
					parent = e1;
				}
			}
			
			if (parent == null)	// sorry, we have to ignore this node. because can't found their parent node.
				continue;
			parent.appendChild(newTreeElement(doc, item));
		}
		String xmlBodyOut = XMLUtils.toXmlString(doc.getDocumentElement());

		return xmlBodyOut;

	} catch (Exception e) {
		e.printStackTrace();
		throw new ResourceException(e.getMessage());
	}
}

/// <summary>
/// 创建一个树结点元素
/// </summary>
/// <returns> Element- new element
///
public Element newTreeElement(Document doc, Category item) throws Exception {
	// 框架表
	Element table = doc.createElement("table");
	table.setAttribute("cellspacing", "0");
	table.setAttribute("cellpadding", "0");
	table.setAttribute("border", "0");
	table.setAttribute("width", "100%");
	
	// 第一个tr
	Element tr1 = doc.createElement("tr");
	table.appendChild(tr1);						// <tr>
	Element td11 = doc.createElement("td");
	td11.setAttribute("width", "15");
	tr1.appendChild(td11);						// <td width="15">
	Element img111 = doc.createElement("img");
	img111.setAttribute("id", "i_" + item.getIndexId());
	img111.setAttribute("src", AppSettings.getInstance().getProperty(AppKeys.APP_ROOT) + "/images/prefix_none.gif");
	td11.appendChild(img111);					// <img id="i_0" src="[APP_ROOT]/images/prefix_none.gif" />
	
	Element td12 = doc.createElement("td");
	td12.setAttribute("style", "cursor: hand; white-space: nowrap;");
	td12.setAttribute("onclick", "javascript:treeViewItem_onclick(" + item.getIndexId() + ")");
	tr1.appendChild(td12);						// <td style="cursor: hand" onclick="javascript:treeViewItem_onclick(0)">
	if (item.getCategoryAttribute() == Category.ATTRIBUTE_ITEM) {
		Element hyper = doc.createElement("a");
		hyper.setAttribute("href", urls[item.getType()] + "?categoryId=" + item.getIndexId());
		hyper.setAttribute("target", "list_view");
		td12.appendChild(hyper);
		Text text = doc.createTextNode(item.getDisplayTitle());
		hyper.appendChild(text);
	} else {
		Text t1 = doc.createTextNode(item.getDisplayTitle());
		td12.appendChild(t1);
	}

	// 第二个tr
	Element tr2 = doc.createElement("tr");
	table.appendChild(tr2);						// <tr>
	Element td21 = doc.createElement("td");
	td21.setAttribute("width", "15");
	tr2.appendChild(td21);						// <td width="15"></td>
	Element td22 = doc.createElement("td");
	td22.setAttribute("id", "t_" + item.getIndexId());
	td22.setAttribute("style", "display: none");
	tr2.appendChild(td22);						// <td id="t_0" style="display: none">
	
	return table;
}
%>
<%
int catalogId = StringUtils.getInt(request.getParameter("catalogId"), -1);
if (catalogId < 1) {	// 获取catalogId失败
	response.sendRedirect(SiteUrls.getInstance().getProperty(SiteUrls.CATALOG_FAILURE));
	return;
}
int type = StringUtils.getInt(request.getParameter("type"), Category.TYPE_BOOK);
boolean locked = StringUtils.getBoolean(request.getParameter("lock"), false);
String xhtmlBody = buildCategoryXmlTree(type);

String actionUrl = request.getRequestURI() + "?catalogId=" + catalogId + "&type=" + type + "&lock=" + (locked ? "1" : "0");
System.out.println("categoryTreeView.actionUrl=" + actionUrl);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Insert title here</title>
<style type="text/css">
body, table, td, select, input { font-size: 9pt; font-family: SimSun; }
.button2w { width: 50px; }
.menuBar td { color: #000000; }
.menuBar a { color: #000000; text-decoration: none }
.menuBar a:hover { color: #f08000; text-decoration: underline }
</style>
<script language="javascript">
<!--
function treeViewItem_onclick(id) {
	var subTree = document.all["t_" + id];
	var prefixImg = document.all["i_" + id];
	if (subTree == null)
		return false;
	var display = subTree.style.display;
	if (display == "none") {
		subTree.style.display = "block";
		if (prefixImg != null) {
			prefixImg.src = prefixImg.src.replace("_none.gif", "_block.gif");
		}
	} else {
		subTree.style.display = "none";
		if (prefixImg != null) {
			prefixImg.src = prefixImg.src.replace("_block.gif", "_none.gif");
		}
	}
}
//-->
</script>
</head>
	<body bottomMargin="0" bgcolor="#d4d0c8" leftMargin="0" topMargin="0" rightMargin="0">
		<table cellspacing="1" cellpadding="0" width="500" border="0">
			<tr>
				<td valign="top">
					<table cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td>查找范围:</td>
							<td><select style="width: 120px" name="listType" <%=locked ? "disabled" : ""%>>
									<option value="书籍" selected>书籍</option>
									<option value="资讯">资讯</option>
									<option value="铃声">铃声</option>
								</select></td>
						</tr>
					</table>
				</td>
				<td valign="top"></td>
			</tr>
			<tr>
				<td valign="top">
<div style="background-color: #ffffff; border-right: thin inset; border-top: thin inset; overflow: auto; border-left: thin inset; width: 200px; border-bottom: thin inset; height: 350px">
<%=xhtmlBody %>
</div>
				</td>
				<td valign="top"><iframe style="width: 400px; height: 350px" name="list_view" src="<%=urls[type] %>"></iframe>
				</td>
			</tr>
			<tr>
				<td height="40"></td>
				<td height="40">
					<table id="table12" cellspacing="0" cellpadding="0" border="0">
						<tr>
							<td width="102"><select style="width: 150px" disabled name="selectName">
									<option value="0" selected>栏目名</option>
								</select></td>
							<td></td>
							<td width="40"><input class="button2w" type="button" value="导入" name="buttonSubmit" /></td>
							<td><input class="button2w" type="button" value="关闭" name="buttonCancel" /></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</body>
</html>

⌨️ 快捷键说明

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