开放源码 CMS 入门,第 3 部分: 构建定制存储
2010-04-16 00:00:00 来源:WEB开发网与 CreateDocument 方法不同,UpdateDocument 方法(见清单 6)需要确保它有一个 sforce ID(也叫做 SFID)。如果 SFID 还没有作为文档的属性存储下来,则首先必须执行一个查询,以便从 salesforce.com 获得它。
清单 6. UpdateDocument
public String UpdateDocument(NodeRev
isionDescriptor revisionDescriptor, File doc){
String docName = revisionDescriptor.getName();
String description = revisionDescriptor.getETag();
ID authorId = new ID("YourauthorIDString");
ID docId = new ID((String)revisionDescrip
tor.getProperty("SFID").getValue());
if (docId == null || docId.getValue().length() != 18) {
try {
QueryResult qr = binding.query(
"Select Id From Document");
SObject[] recs = qr.getRecords();
for (int i = 0; i < recs.length; i++) {
SObject object = recs[i];
if (object instanceof Document) {
Document d = (Document) qr.getRecords(i);
if (d.getName().compareToIgnoreCase(docName)
== 0){
docId = d.getId();
break;
}
}
}
if (docId == null) throw new InvalidSObjectFault(
ExceptionCode.UNKNOWN_EXCEPTION,
"docId == null,
possibly doc " + docName + " not found");
} catch (UnexpectedErrorFault e2) {
e2.printStackTrace();
} catch (InvalidSObjectFault e2) {
e2.printStackTrace();
} catch (MalformedQueryFault e2) {
e2.printStackTrace();
} catch (InvalidFieldFault e2) {
e2.printStackTrace();
} catch (RemoteException e2) {
e2.printStackTrace();
}
}
System.out.println("//// UpdateDocument ////");
System.out.println("docName=" + docName);
System.out.println("File doc=" + doc.toString());
System.out.println("Description=" + description);
System.out.println("authorId=" + authorId.getValue());
System.out.println("docId=" + docId.getValue());
String retStatus = "Success";
int fileLength = (int) doc.length();
byte[] body = new byte[fileLength];
//Verify that we are already authenticated, if not
//call the login function to do so
if (!loggedIn) {
if (!login()) {
return "Bad SalesForce Login";
}
}
try {
FileInputStream fis = new FileInputStream(doc);
fileLength = fis.read(body);
} catch (FileNotFoundException e) {
retStatus = "Error Failed to UpdateDocument:"
+ e.getLocalizedMessage();
e.printStackTrace();
return retStatus;
} catch (IOException e1) {
retStatus = "Error Failed to UpdateDocument:"
+ e1.getLocalizedMessage();
e1.printStackTrace();
return retStatus;
}
if (authorId == null) {
//default to current user
authorId = this.loginResult.getUserId();
}
try {
Document document;
SObject[] sObjects = new SObject[1];
document = new Document();
document.setName(docName);
document.setBody(body);
document.setDescription(description);
document.setAuthorId(authorId);
document.setId(docId);
sObjects[0] = document;
//create the object(s) by sending the array
//to the web service
SaveResult[] sr = binding.update(sObjects);
for (int i = 0; i < sr.length; i++) {
SaveResult result = sr[i];
if (result.isSuccess()) {
retStatus = "Success Updated Document " +
docName;
} else {
Error[] ers = (Error[]) result.getErrors();
retStatus = "Error:";
for (int j = 0; j < ers.length; j++) {
Error error = ers[j];
retStatus += error.getMessage() + ";";
System.out.println("error.getStatusCode():"
+ error.getStatusCode());
System.out.println(retStatus);
}
}
}
} catch (UnexpectedErrorFault uef) {
this.getLogger().log(uef.getExceptionMessage());
} catch (Exception ex) {
retStatus = "\nFailed to Update Document, " + docName
+ ", error message was: \n" + ex.getMessage();
System.out.println(retStatus);
}
return retStatus;
}
- ››CmsTop采集图文教程
- ››cmstop如何更换系统默认模板
- ››CmsTop大众版视频教程之:文章采集教程
- ››CMS行业价值和方向在哪里 究竟还剩下些什么?
- ››开放的云让业务更“闪亮”
- ››开放源码 CMS 入门,第 1 部分: 下载、安装和开始...
- ››开放源码 CMS 入门,第 2 部分: 通过 Eclipse 构建...
- ››开放源码 CMS 入门,第 3 部分: 构建定制存储
- ››开放源码 CMS 入门,第 5 部分: 为 Jakarta Slide...
- ››开放源码 CMS 入门,第 6 部分: 为 Jakarta Slide...
- ››CMS阅读功能 for v 7.5
- ››开放标准、开放源码和 Domino 6: 通过 Python 和 ...
更多精彩
赞助商链接