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

📄 wsuploadfile.java

📁 OA典型例子
💻 JAVA
字号:
package com.jspsmart.upload;

/**
 * <p>Title:      公文系统webservices接口 </p>
 * <p>Description:提供文件上传接口 </p>
 * <p>Copyright:   suresnese (c) 2004</p>
 * <p>Company:     suresense</p>
 * @author not attributable
 * @version 1.0
 */

import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.apache.soap.encoding.soapenc.Base64;
import java.io.FileOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.util.*;
import com.sure.util.*;
import com.sure.oa.orgnization.*;
import com.sure.oa.recvdoc.*;

public class WSUploadFile {
  public WSUploadFile() {
  }
  private static String FILECODE="FileCode";
  private static String FILEPATH="FilePath";
  private static String TransIdList="TransIdList";
  private static String XMLHEAD="<?xml version=\"1.0\" encoding=\"GB2312\" ?>";

  /**
   * 根据单位ID列表,获得单位的名称
   * @输入xml字符串,单位ID列表
   * @输出xml字符串,单位名称列表
   */
  public synchronized String getUnitList(String xmlFlow) {
    System.out.println(xmlFlow);
    String retValue="",transIdList="",unitIdList="",docId="";
    try {
      Document doc=getDocument(xmlFlow);
      transIdList=getTagValue(doc,TransIdList);
      docId=getTagValue(doc,"DocId");
      unitIdList=RecvPermissionManager.getUnitIdListByTransId(docId,transIdList);
      if (unitIdList != null && !unitIdList.equals("")) {
         String strTemp[] = StringUtils.split(unitIdList, ",");
         for (int i = 0; i < strTemp.length; i++) {
           if (strTemp[i].equals("0")){
             retValue = retValue +"未知,";
           }else{
             retValue = retValue +UnitManager.getUnitName(Integer.parseInt(strTemp[i])) + ",";

           }
         }
      }
      if(retValue.length()>1) retValue=retValue.substring(0,retValue.length()-1);
      retValue=strToXMLReturn("0",retValue);
    }
    catch (Exception e) {
      e.printStackTrace();
      retValue=strToXMLReturn("1",e.getMessage());
    }
    finally {
      System.out.println(retValue);
      return retValue;
    }
  }

  /**
   * 上传文件到服务器
   * @param  xml字符串     文件流和路径
   * @return xml字符串     "0"成功 "1"失败
   */
  public synchronized  String uploadFile(String xmlFlow) {
    //System.out.println(xmlFlow);
    xmlFlow=xmlFlow.substring(0,xmlFlow.indexOf("</Root>"))+"</Root>";
    //System.out.println("xmlFlow   =      "+xmlFlow);
    String retValue="",filePath="";
    byte[] bt;
    try {
      Document doc=getDocument(xmlFlow);
      //存储文件
      filePath=new String(Base64.decode(getTagValue(doc,FILEPATH)));
      //System.out.println(filePath);
      bt=Base64.decode(getTagValue(doc,FILECODE));
      File file=new File(filePath);
      FileOutputStream fos=new FileOutputStream(file);
      fos.write(bt);
      fos.close();
      retValue=strToXMLReturn("0","成功");
    }
    catch (Exception e) {
      e.printStackTrace();
      retValue=strToXMLReturn("1",e.getMessage());
    }
    finally {
      return retValue;
    }
  }

  private String strToXMLReturn(String errorCode,String errorDesc) {
    return XMLHEAD+"<Root><Return><ErrorCode>"+errorCode+"</ErrorCode><ErrorDes>"+errorDesc+"</ErrorDes></Return></Root>";
  }
  /**
   * 根据XML字符串得到Document对象
   * @param strValue   XML字符串
   * @return
   */
  private Document getDocument(String strValue) throws Exception {
    DOMParser parser = new DOMParser();
    InputStream input = new ByteArrayInputStream(strValue.getBytes());
    InputSource source = new InputSource(input);
    parser.parse(source);
    Document doc = parser.getDocument();
    return doc;
  }

  private String getTagValue(Document doc, String tagName){
    try{
      Node node = doc.getElementsByTagName(tagName).item(0);
      return node.getChildNodes().item(0).getNodeValue();
    }catch(NullPointerException e){
      return "";
    }
  }
 }

⌨️ 快捷键说明

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