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

📄 soapserver.java

📁 OA典型例子
💻 JAVA
字号:
package com.sure.soapserver;

import org.apache.xerces.utils.Base64;
import com.sure.oa.archive.*;
import com.sure.oa.gdfile.*;
import com.sure.oa.senddoc.*;
import com.sure.oa.attachment.*;
import com.sure.oa.orgnization.*;
import com.sure.util.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import org.apache.xerces.parsers.DOMParser;
import org.apache.xml.serialize.XMLSerializer;
import org.xml.sax.InputSource;
import org.w3c.dom.*;

public class SoapServer{
  private PrintWriter log;

  /**
   * 客户端调用方法,
   * @param xml
   * @传入应用服务器数据库
   */
  public String  saveFromOa(String fileString){
     String retValue = "0";
     SendDocFormManager sMg=new SendDocFormManager();
     try{
       SendDocForm u = new SendDocForm();
       InputStream input = new ByteArrayInputStream(fileString.getBytes());
       InputSource source = new InputSource(input);
       DOMParser parser = new DOMParser();
       parser.parse(source);
       Document doc = parser.getDocument();
       Node node;
       //log = new PrintWriter(new FileWriter("logs/inport.log", true), true);
       //log.println("---" + getTagValue(doc,"发文字号") + "开始导入时间:"+new java.util.Date()+"---");
       u.setCreateUnitId(getTagValue(doc, "发文机关"));
       String unitId=UnitManager.getUnitId(getTagValue(doc, "发文机关"));
       String docNo=getTagValue(doc, "发文字号");
       u.setDocNoPre(docNo.substring(0,docNo.indexOf("[")));
       u.setYearNo(docNo.substring(docNo.indexOf("["),docNo.indexOf("]")));
       u.setWaterNo(docNo.substring(docNo.indexOf("]")));
       u.setDocTitle(getTagValue(doc, "标题"));
       u.setSecret(getTagValue(doc, "秘密等级"));
       u.setSaveTime(getTagValue(doc,"保密期限"));
       u.setEmergency(getTagValue(doc, "紧急程度"));
       u.setPublishDate(getTagValue(doc, "发文日期"));
       u.setPublishPerson(getTagValue(doc, "签发人"));
       // System.out.println(getTagValue(doc,"发文时间"));
       u.setCreateDate(getTagValue(doc,"扩展要素","要素名称","发文时间"));
       u.setSendTo(getTagValue(doc, "主送机关"));
       u.setCc(getTagValue(doc, "抄送机关"));
       u.setSubject(getTagValue(doc, "主题词"));
       u.setPrintDate(getTagValue(doc,"印发日期"));
       u.setPrintUnit(getTagValue(doc,"印发机关"));
       u.setPrintnumber(getTagValue(doc,"印发份数"));
       u.setCreator(getTagValue(doc,"录入人"));
       u.setCheckPerson(getTagValue(doc,"扩展要素","要素名称","校对人"));
       u.setSealPerson(getTagValue(doc,"扩展要素","要素名称","盖章人"));
       u.setSealTime(getTagValue(doc,"扩展要素","要素名称","盖章时间"));
       u.setDocMemo(getTagValue(doc,"来文备注"));
       u.setDocId(0);
       int intId=sMg.saveDoc(u);
       node=doc.getElementsByTagName("正文").item(0);
       saveAttach(node, intId,"0",unitId);
       NodeList attachList = doc.getElementsByTagName("附件");
       for(int i = 0; i < attachList.getLength(); i++){
         node = attachList.item(i);
         saveAttach(node, intId,"1",unitId);
       }
       //log.println("---" + "完成时间:"+new java.util.Date()+"---");
     }catch(Exception e) {
       retValue="1";
       //log.println("---"+e.getMessage()+"---");
       e.printStackTrace();
     }
     finally{
       //log.println("--------------" +"END"+"--------------");
       return  retValue;
     }
   }

  /**
   * @param docId
   * @上传OA服务器
   */
  public int  uploadOa(int docId){
    int  retValue=0;
    try{
      GuiDocForm form = GuiDocFormManager.getDoc(docId);
      String xml = form.toXML().toString();
    }
    catch(Exception e){
      e.printStackTrace();
    }
    return  retValue;
  }

  /**
   * 根据标签名和DOC返回一个节点值
   * @Author mengzy 2004-4-12
   */
  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 "";
    }
  }
  private String getEncodeTagValue(Document doc, String tagName){
    return new String(Base64.decode(getTagValue(doc, tagName).getBytes()));
  }
  private String getTagValue(Document doc, String tagName,String attrName,String attrValue){
    String retValue="";
    try{
      Node node;
      NodeList nodes = doc.getElementsByTagName(tagName);
      for(int i = 0; i < nodes.getLength(); i++){
         node = nodes.item(i);
         if(node.getAttributes().getNamedItem(attrName).getNodeValue().equals(attrValue)){
             retValue=node.getChildNodes().item(0).getNodeValue();
         }
      }
    }catch(NullPointerException e){
      e.printStackTrace();
    }
    finally {
      return  retValue;
    }
  }


  /**
   * 根据Node和属性名返回一个属性值
   * @Author mengzy 2004-4-12
   */
  private String getNodeTagValue(Node node, String tagName){
    try{
      return node.getAttributes().getNamedItem(tagName).getNodeValue();
    }catch(NullPointerException e){
      return "";
    }
  }
  private String getEncodeNodeTagValue(Node node, String tagName){
    return new String(Base64.decode(getNodeTagValue(node, tagName).getBytes()));
  }

  /**
   * 保存正文或附件,并且在相应的磁盘目录创建文件
   * @author:mengzy  2004-4-18
   */
  private int saveAttach(Node node, int itemId,String status,String unitId) throws IOException{
    int intId = 0;
    try{
      attachmentManager amg = new attachmentManager();
      Calendar cal = new GregorianCalendar();
      cal.setTime(new Date());
      String month = Integer.toString(cal.get(cal.MONTH));
      String year = Integer.toString(cal.get(cal.YEAR));
      String path=amg.getUploadPath();
      path="/upload/"+unitId+"/"+year+"/"+month+"/";
      attachment attachment;
      attachment = new attachment();
      attachment.setFileId(0);
      attachment.setTitle(getNodeTagValue(node,"title"));
      attachment.setPath(path);
      attachment.setFileName(getNodeTagValue(node,"fileName"));
      attachment.setFileSize(getNodeTagValue(node,"fileSize"));
      attachment.setMimeType(getNodeTagValue(node,"mimetype"));
      attachment.setTableName("sendDocForm");
      attachment.setDocId(Integer.toString(itemId));
      attachment.setStatus(status);
      attachment.setOrderBy(0);
      amg.saveAttachment(attachment);
      intId = attachment.getFileId().intValue();
      Writer writer=new FileWriter(path+getNodeTagValue(node,"site")+"/"+getNodeTagValue(node,"fileName"));
      byte[] content=Base64.decode(node.getChildNodes().item(0).getNodeValue().getBytes());
      writer.write(content.toString());
      writer.close();
    }
    catch(Exception e){
      e.printStackTrace();
    }
    return intId;
  }

  public static void  main(String args[]){
    try{
       GuiDocForm form = GuiDocFormManager.getDoc(6);
       StringBuffer  ret=form.toXML();
       //File f=new File("E:\\hgxm\\document.xml");
       //if(f.exists()){System.out.println("文件有!");}
       //InputStream input = new BufferedInputStream(new FileInputStream("E:\\hgxm\\document.xml"));
       //InputSource source = new InputSource(input);
       //DOMParser parser = new DOMParser();
       //parser.parse(source);
       //Document doc = parser.getDocument();
       //Node node=doc.getElementsByTagName("正文").item(0);
       //FileOutputStream MyFileWriter=new FileOutputStream("E:\\还原文件.gd");
       //byte[] content=Base64.decode(node.getChildNodes().item(0).getNodeValue().getBytes());
       //InputStream  MyFileReader=new ByteArrayInputStream(content);
       //int c;
       //while ((c = MyFileReader.read()) != -1)
          //MyFileWriter.write(c);
       //MyFileWriter.close();
       //MyFileReader.close();
    }
    catch(Exception e){
       e.printStackTrace();
    }
  }

}

⌨️ 快捷键说明

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