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

📄 creatmenu.java

📁 用ajax实现的下拉菜单功能
💻 JAVA
字号:
package com;

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.IOException;
import java.net.URL;

import org.xml.sax.SAXException;

/**
 * 读取XML文件,并且通过权限设置生成js文件
 * 使用说明:如有不懂请留言 http://hi.csdn.net/wpabbs
 * @author WuPeng
 * @version 1.0
 */

public class creatMenu {
	public creatMenu() {
	}

	int objcount = 0; // 菜单个数

	public String readDom(String roles) throws IOException, SAXException,
			ParserConfigurationException {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		URL url = creatMenu.class.getResource("/");
		Document doc = db.parse(url + "/menu-config.xml");
		NodeList list = doc.getElementsByTagName("Menu");
		setObjcount(list.getLength());
		String str = "";
		String str1 = "";
		String str2 = "";
		int id = 1;
		for (int i = 0; i < list.getLength(); i++) {
			Node ele = list.item(i);
				str1 = "mm" + id + "=new mainMenu('#','"
				+ ele.getAttributes().getNamedItem("title").getNodeValue()
				+ "','#');";
				for (Node node = ele.getFirstChild(); node != null; node = node
						.getNextSibling()) {
					if (node.getNodeType() == Node.ELEMENT_NODE) {
						String[] roless = roles.split(",");
						for(int k = 0; k < roless.length; k++){
							if (node.getAttributes().getNamedItem("roles")
									.getNodeValue().indexOf(roless[k]) != -1) {
								str2 += "mm"
										+ id
										+ ".addSub(new subMenu('"
										+ node.getAttributes().getNamedItem(
												"target").getNodeValue()
										+ "','"
										+ node.getAttributes()
												.getNamedItem("title")
												.getNodeValue()
										+ "','"
										+ node.getAttributes().getNamedItem(
												"location").getNodeValue() + "'));";
								break;
							} 
							
							
						}
						
					}
	
			}
				if(!str2.equals(""))
					str += str1 + str2;
				str1 = "";
				str2 = "";
				id++;
		}
		return str;
	}

	public int getObjcount() {
		return objcount;
	}

	public void setObjcount(int objcount) {
		this.objcount = objcount;
	}

}

⌨️ 快捷键说明

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