普元EOS简单运算逻辑的编写

package zqz;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

import org.w3c.dom.*;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import com.primeton.tp.common.xml.XmlUtil;
import com.primeton.tp.core.api.BizContext;

/**
 * @author qzzha
 * @version 1.0
 * @date 2012-11-6
 * @class_displayName EosBizletApplication
 * 学习普元EOS简单运算逻辑的编写
 */

public class EosBizletApplication {

 /*
  * 根据SQL查询数据库,返回LIST类型数据集合,类似于普元自带构建 BL_runFormatSql
  * 主要学习内容:熟悉普元运算逻辑;获取属性;设置属性;怎样返回查询结果
  *
  */
 public static int BL_queryFromDb(Document doc, BizContext param)
   throws Exception {
  Node listNode = (Node) param.getParaObjectAt(0);
  String sql = (String) param.getParaObjectAt(1);

  // Entity节点名称使用type属性值,没有则使用"entity"
  NamedNodeMap attrs = listNode.getAttributes();
  String entity = "";
  if (attrs.getNamedItem("type") != null) {
   entity = attrs.getNamedItem("type").getNodeValue();
  }
  if (entity == null || "".equals(entity)) {
   entity = "entity";
  }

  // entity
  Element entityNode = null;
  // filed
  Element filedNode = null;

  PreparedStatement ps = null;
  ResultSet rs = null;
  Connection conn = null;
  // 获取连接
  conn = param.getDBBroker().getConnection();
  ps = conn.prepareStatement(sql);
  rs = ps.executeQuery();
  // 获取元数据
  ResultSetMetaData rsdd = rs.getMetaData();
  int count = rsdd.getColumnCount();
  int rows = 0;
  while (rs.next()) {
   entityNode = doc.createElement(entity);
   // 设置rowNum属性值 第几条记录
   entityNode.setAttribute("rowNum", "" + rows);
   for (int i = 1; i <= count; i++) {
    // 创建以查询列名命名的元素
    filedNode = doc.createElement(rsdd.getColumnName(i));
    // 增加文本元素
    filedNode.appendChild(doc.createTextNode(rs.getString(rsdd
      .getColumnName(i))));
    entityNode.appendChild(filedNode);
   }
   listNode.appendChild(entityNode);
   rows++;
  }
  // 设置rowNum属性值 总记录条数
  ((Element) listNode).setAttribute("rowNum", "" + rows);
  return 1;
 }

 /*
  * 字符串处理应用 字符串处理之后返回
  */
 public static int BL_GetAffixURL(Document doc, BizContext param)
   throws Exception {
  Node param0 = (Node) param.getParaObjectAt(0);
  String fileName = (String) param.getParaObjectAt(1);
  String filePath = (String) param.getParaObjectAt(2);
  // 加密,集团ITSM规定URL不能有中文
  fileName = encryptBASE64(fileName);
  filePath = encryptBASE64(filePath);
  // ip
  String url = "http://ip:9080/jt_itsm/pageFile/fileDown2.jsp?filename="
    + fileName + "&path=" + filePath;
  XmlUtil.setNodeValue(param0, url);
  return 1;
 }

 /**
  * * BASE64加密 * *
  *
  * @param key *
  * @return *
  * @throws Exception
  */
 public static String encryptBASE64(String s) throws Exception {
  byte[] key = s.getBytes();
  return (new BASE64Encoder()).encodeBuffer(key);
 }

 /**
  * * BASE64解密 * *
  *
  * @param key *
  * @return *
  * @throws Exception
  */
 public static String decryptBASE64(String key) throws Exception {
  byte[] b = (new BASE64Decoder()).decodeBuffer(key);
  return new String(b);
 }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值