Android DOM解析

public boolean parseConfigXml() {
		boolean rst = false;
		int count = 0;
		int i;
		UiStoreIcon v = null;
		FileInputStream fin = null;
		InputStream is = null;
		DocumentBuilderFactory factory = null;
		DocumentBuilder builder = null;
		Document doc = null;
		Element root = null;
		NodeList list = null;
		String packageName = null, dlUrl = null, icon = null, apkName = null;
		Element node = null;// (Element) list.item(i);
		int size = -1;
		int maxSize = -1;

		try {
			factory = DocumentBuilderFactory.newInstance();
			builder = factory.newDocumentBuilder();
			try {
				fin = new FileInputStream(CFG_FILE_PATH + CFG_FILE_NAME);
				is = new BufferedInputStream(fin);
			} catch (Exception e) {
				is = mContext.getAssets().open(CFG_FILE_NAME);
			}
			doc = builder.parse(is);
			root = doc.getDocumentElement();
			list = root.getChildNodes();
			count = list.getLength();

			mBingoWidgets.clear();
			mAllWidgets.clear();
			mFixedPosItemList.clear();
			mLinearItemList.clear();

			for (i = 0; i < count; i++) {
				if (Node.ELEMENT_NODE == list.item(i).getNodeType()) {
					node = (Element) list.item(i);
					NodeList childList = null;
					Element childItem = null;
					int k = 0;
					int childListLength = 0;
					BingoWidgetInfo childItemInfo;
					// bt("xxx:node.getNodeName()" + node.getNodeName());
					if (TAG_MAINMENU.equals(node.getNodeName())) {

						mMainMenuCfg.countX = getIntParam(node.getAttribute("countX"));
						mMainMenuCfg.countY = getIntParam(node.getAttribute("countY"));
						mMainMenuCfg.sizeX = getIntParam(node.getAttribute("sizeX"));
						mMainMenuCfg.sizeY = getIntParam(node.getAttribute("sizeY"));
						mMainMenuCfg.fontSize = getIntParam(node.getAttribute("fontSize"));
						mMainMenuCfg.hasGroup = getIntParam(node.getAttribute("hasGroup"));
						mMainMenuCfg.hasBingoWidget = getIntParam(node.getAttribute("hasBingoWidget"));
						mMainMenuCfg.defaultAppIcons = getIntParam(node.getAttribute("defaultAppIcons"));

						childList = node.getElementsByTagName("FixedItem");

						createItem(childList, mLinearItemList, mFixedPosItemList);

						childList = node.getElementsByTagName("AppLink");
						createItem(childList, mLinearItemList, mFixedPosItemList);
						// createItem(childList, mAllWidgets, mAllWidgets);
					} else if (TAG_IDLE.equals(node.getNodeName())) {
						mIdleCfg.fontSize = getIntParam(node.getAttribute("fontSize"));
						mIdleCfg.countX = getIntParam(node.getAttribute("countX"));
						mIdleCfg.countY = getIntParam(node.getAttribute("countY"));

						mIdleCfg.hotSeatCountX = getIntParam(node.getAttribute("hotSeatCountX"));
						mIdleCfg.hotSeatCountY = getIntParam(node.getAttribute("hotSeatCountY"));
						mIdleCfg.pageEffectEnable = getIntParam(node.getAttribute("pageEffectEnable"));
						mIdleCfg.pageSetEnable = getIntParam(node.getAttribute("pageSetEnable"));
						if (node.getAttribute("theme").length() > 0) {
							mIdleCfg.themePath = CFG_FILE_PATH + node.getAttribute("theme");
						} else {
							mIdleCfg.themePath = null;
						}

						if (node.getAttribute("wallpaper").length() > 0) {
							mIdleCfg.wallpaperImagePath = CFG_FILE_PATH + node.getAttribute("wallpaper");
						} else {
							mIdleCfg.wallpaperImagePath = null;
						}
						childList = node.getElementsByTagName("AppFavorite");

						createItem(childList, mAllWidgets, null);

						childList = node.getElementsByTagName("AppWidget");
						createItem(childList, mAllWidgets, null);
						childList = node.getElementsByTagName("HotSeat");
						createItem(childList, mAllWidgets, null);

						childList = node.getElementsByTagName("AppLink");
						createItem(childList, mAllWidgets, mAllWidgets);
					} else if (TAG_BINGOWIDGET.equals(node.getNodeName())) {
						childList = node.getElementsByTagName("BingoWidget");

						createItem(childList, mBingoWidgets, null);
						// childList = node.getElementsByTagName("AppLink");
						// createItem(childList, mBingoWidgets, mBingoWidgets);
					}
				}
			}
			if (mMainMenuCfg.sizeX == -1 || mMainMenuCfg.sizeY == -1) {
				mMainMenuCfg.sizeX = mMainMenuCfg.sizeY = (int) mContext.getResources().getDimension(R.dimen.app_icon_size);
			}
			readConfigFile(false);
		} catch (Exception e) {
			rst = false;
			e.printStackTrace();
		}

		if (fin != null) {
			try {
				fin.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		v = null;
		is = null;
		factory = null;
		builder = null;
		doc = null;
		root = null;
		list = null;
		return rst;
	}

你可能感兴趣的:(Android DOM解析)