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

📄 dom4jutility.java

📁 本源码为教学管理信息系统
💻 JAVA
字号:
/**
 * Copyright (c) 2002-2005 by HeiLongJiang Oliveinfo Industry Co.,Ltd.
 * All rights reserved.
 */
package com.wygl.xmlhttp;

import java.io.DataInputStream;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.wygl.taglib.SelectOptions;
/**
 * @author:xiexd
 * Created on 2005-12-16
 * 为XMLHTTP服务的数据转换器
 */
public class Dom4jUtility { 
	
  	
   /**
   * 将DataInputStream解析,并且存入String中
   * @param in DataInputStream  xml文件转换成的DataInputStream对象
   * @throws Exception
   * @return String
   */
	public static String inStream2String(DataInputStream in) throws Exception{
		try {
	        String resultString;
			Document document=new SAXReader().read(in);
			Element root  = document.getRootElement();
			resultString = new String();//[Integer.parseInt(root.attribute("count").getText())];
			int icount = 0;
			for (Iterator i = root.elementIterator("row");i.hasNext();) {
				resultString = StringUtility.getDecodeStr(((Element) i.next()).getTextTrim());
			}
			return resultString;
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}
	}
	
   /**
   * 将 List 转换为String类型的字符串,其中list放的是com.olive.xmlhttp.SelectOptions
   * @param list List
   * @throws Exception
   * @return String
   */
	public static String list2String(List list)throws Exception {
		StringBuffer srtnString = new StringBuffer();
		try {   
			int listSize=list.size();
		    if (listSize==1){			    	
		    	srtnString.append(((SelectOptions)list.get(0)).getTexts());
				srtnString.append(",");
				srtnString.append(((SelectOptions)list.get(0)).getValues());
		    }
			if(listSize>1){
				srtnString.append(((SelectOptions)list.get(0)).getTexts());
				srtnString.append(",");
				srtnString.append(((SelectOptions)list.get(0)).getValues());
 			    for(int i=1;i<listSize;i++){
					srtnString.append(";");
					srtnString.append(((SelectOptions)list.get(i)).getTexts());
					srtnString.append(",");
					srtnString.append(((SelectOptions)list.get(i)).getValues());
 								
 				}
			    	
			}
			if(srtnString.length()>0){
				return srtnString.toString();
			}else{
				return "";
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}
	}
   /**
   * 将 一维数组转换为String类型的字符串
   * @param sOneArray String[]
   * @throws Exception
   * @return String
   */
	public static String sOneArray2XmlString(String[] sOneArray)throws Exception {
		StringBuffer srtnString = new StringBuffer();
		try {
			 Document doc = DocumentHelper.createDocument();
			 Element root = doc.addElement("root");
			for(int i = 0 ; i < sOneArray.length ; i++){
				Element row = root.addElement("row");
				if (sOneArray[i]!=null){
				  row.addText(StringUtility.getEncodeStr(sOneArray[i]));
				}
			}
			return doc.asXML();
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception(e.getMessage());
		}
	}
}

⌨️ 快捷键说明

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