package com.zhangjun.xml;

import java.io.PrintStream;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class AddItem
{
  public void addItem(Document dom, Element row, ResultSet rs, int col, String sOrder, String sLink, int id)
  {
    try
    {
      ResultSetMetaData tz = rs.getMetaData();
      String sName = tz.getColumnName(col);
      String sType = tz.getColumnTypeName(col);
      String sValue;
      if (rs.getString(col) == null) {
        sValue = "";
      }
      else {
        sValue = toGBK(rs.getString(col).trim());
      }
      Element item = dom.createElement("item");
      row.appendChild(item);
      item.setAttribute("id", "" + id);

      Element name = dom.createElement("name");
      item.appendChild(name);
      name.appendChild(dom.createTextNode(sName));
      Element value = dom.createElement("value");
      item.appendChild(value);
      value.appendChild(dom.createTextNode(sValue));
      Element type = dom.createElement("type");
      item.appendChild(type);
      type.appendChild(dom.createTextNode(sType));
      Element order = dom.createElement("order");
      item.appendChild(order);
      order.appendChild(dom.createTextNode(sOrder));
      Element link = dom.createElement("link");
      item.appendChild(link);
      link.appendChild(dom.createTextNode(sLink));
    }
    catch (Exception e)
    {
      System.out.println("com.zhangjun.xml.addItem  rs ID:" + e);
    }
  }

  public void addItem(Document dom, Element row, ResultSet rs, int col, String sOrder, String sLink, int id, String dbserver)
  {
    try
    {
      ResultSetMetaData tz = rs.getMetaData();
      String sName = tz.getColumnName(col);
      String sType = tz.getColumnTypeName(col);
      String sValue = null;
      if (rs.getString(col) == null) {
        sValue = "";
      }
      else if (dbserver.equals("sql"))
        sValue = toGBK(rs.getString(col).trim());
      else if (dbserver.equals("oracle")) {
        sValue = rs.getString(col).trim();
      }
      Element item = dom.createElement("item");
      row.appendChild(item);
      item.setAttribute("id", "" + id);
      Element name = dom.createElement("name");
      item.appendChild(name);
      name.appendChild(dom.createTextNode(sName));
      Element value = dom.createElement("value");
      item.appendChild(value);
      value.appendChild(dom.createTextNode(sValue));
      Element type = dom.createElement("type");
      item.appendChild(type);
      type.appendChild(dom.createTextNode(sType));
      Element order = dom.createElement("order");
      item.appendChild(order);
      order.appendChild(dom.createTextNode(sOrder));
      Element link = dom.createElement("link");
      item.appendChild(link);
      link.appendChild(dom.createTextNode(sLink));
    }
    catch (Exception e)
    {
      System.out.println("com.zhangjun.xml.addItem  " + dbserver + ":" + e);
    }
  }

  public void addItem(Document dom, Element row, String title, String content, String sOrder, String sLink, int id)
  {
    try
    {
      Element item = dom.createElement("item");
      row.appendChild(item);
      item.setAttribute("id", "" + id);
      Element name = dom.createElement("name");
      item.appendChild(name);
      name.appendChild(dom.createTextNode(title));
      Element value = dom.createElement("value");
      item.appendChild(value);
      if (!(sLink.equals("HTML")))
        value.appendChild(dom.createTextNode(content));
      else
        value.appendChild(dom.createCDATASection(content));
      Element type = dom.createElement("type");
      item.appendChild(type);
      type.appendChild(dom.createTextNode("String"));
      Element order = dom.createElement("order");
      item.appendChild(order);
      order.appendChild(dom.createTextNode(sOrder));
      Element link = dom.createElement("link");
      item.appendChild(link);
      link.appendChild(dom.createTextNode(sLink));
    }
    catch (Exception e)
    {
      System.out.println("com.zhangjun.xml.addItem  content:" + e);
    }
  }

  public String toGBK(String str)
  {
    String strNew = new String();
    try {
      byte[] bbb = str.getBytes("ISO8859_1");
      strNew = new String(bbb, 0, bbb.length, "GBK");
    }
    catch (Exception e)
    {
      System.out.println(e);
    }
    return strNew;
  }
}
最近下载更多
一直都会顺利的小吴  LV5 2022年2月16日
无名氏111  LV32 2021年9月14日
缘------  LV9 2021年6月28日
能不能不存在  LV13 2021年1月15日
amour1  LV11 2020年12月13日
EdgarLi  LV14 2020年8月6日
soscat2000  LV3 2020年7月6日
谁打我多多  LV6 2020年6月10日
yezhi123  LV4 2020年5月28日
sunlea  LV17 2020年4月26日
最近浏览更多
cz8857216  LV4 3月8日
fesfefe  LV13 1月26日
uni-code_0123  LV1 2023年11月11日
EFWAGGFAWGR 2023年10月19日
暂无贡献等级
微信网友_6467077197238272  LV1 2023年5月8日
lironggang  LV38 2023年3月28日
zjc010726 2023年3月15日
暂无贡献等级
qwqw900619  LV4 2022年7月16日
nbzhou2013  LV14 2022年4月4日
一直都会顺利的小吴  LV5 2022年2月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友