简单小例子学会企业内容管理 IBM CM API开发

一、IBM CM 创建CM连接

import com.ibm.mm.sdk.common.DKException;
import com.ibm.mm.sdk.common.DKServerDefICM;
import com.ibm.mm.sdk.common.dkCollection;
import com.ibm.mm.sdk.common.dkIterator;
import com.ibm.mm.sdk.server.DKDatastoreICM;

public class CMConnection {

	/**
	 * IBM CM连接
	 */
	public static void main(String[] args) throws DKException, Exception {
		cmConnection();
	}

	public static void cmConnection() throws DKException, Exception {

		DKDatastoreICM dsICM;

		dsICM = new DKDatastoreICM();
		
		System.out.println("***************创建CM连接***************");

		dsICM.connect("icmnlsdb","icmadmin","icmadmin","");  //"icmnlsdb":CM连接配置文件cmbcmenv.properties,ICMSERVER=;"xxxxxx":用户名,密码

		
		System.out.println("***************断开CM连接***************");
		dsICM.disconnect();
		dsICM.destroy(); // Destroy reference
	}
}

二、IBM CM 单个文件上传下载

import com.ibm.mm.sdk.common.DKConstant;
import com.ibm.mm.sdk.common.DKException;
import com.ibm.mm.sdk.common.DKResults;
import com.ibm.mm.sdk.common.DKRetrieveOptionsICM;
import com.ibm.mm.sdk.common.DKTextICM;
import com.ibm.mm.sdk.server.DKDatastoreICM;

public class CMDownload_byPID {
	public static void main(String[] args) throws DKException, Exception {
		cmDownload_byPID();
	}

	//单个文件上传下载 
	public static void cmDownload_byPID() throws DKException, Exception {
		DKDatastoreICM dsICM = null;

		dsICM = new DKDatastoreICM();

		System.out.println("***************第一步:创建CM连接***************");

		dsICM.connect("icmnlsdb", "icmadmin", "icmadmin", "");

		DKResults results = null;

		System.out.println("***************第二步:指定文档项类型,上传文档***************");
		DKTextICM text = (DKTextICM) dsICM.createDDO("test_item_type",
				DKConstant.DK_CM_ITEM);

		text.setMimeType("text/plain");

		text.add("D:/Text1.txt"); //保存内容"D:/Text1.txt"到CM

		System.out.println("***************第三步:根据PID,下载文档***************");	
		String textPidString  =  text.getPidObject().pidString();
		text  = (DKTextICM)  dsICM.createDDOFromPID(textPidString);
		
        DKRetrieveOptionsICM dkRetrieveOptions = DKRetrieveOptionsICM.createInstance(dsICM);//设置获取哪些数据
        dkRetrieveOptions.resourceContent(true);
        
        text.retrieve("D:/Text2.txt",dkRetrieveOptions.dkNVPair());
        

		System.out.println("***************断开CM连接********");
		dsICM.disconnect();
		dsICM.destroy();
	}

}

©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页