- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Java 获取 SBT 工具包。效果很好,但在处理文件夹时遇到一些困难:
我需要在社区中创建一个文件夹并将一些文件放入其中。不幸的是,CommunityService
类没有这样的方法。
我可以使用 FileService.createFolder(name, description, shareWith)
方法并与社区共享它,但实际上我只想要社区中的文件,否则它们在文件应用程序(公开的警告消息:“与公共(public)社区共享‘COMMUNITY NAME’将使该文件夹公开。”)
我怎样才能做到这一点?
我检查了社区/文件小部件中的按钮,发现它正在向社区提要发送 POST:
目标网址:https://connections.host.ch/files/form/api/communitycollection/{community-uuid}/feed
发布内容:
<entry xmlns="http://www.w3.org/2005/Atom">
<category term="collection" label="collection" scheme="tag:ibm.com,2006:td/type"></category>
<label xmlns="urn:ibm.com/td" makeUnique="true">TEST Folder</label>
<title>TEST Folder</title>
<summary type="text">teset set e</summary>
</entry>
那么,我可以使用 communityService.createData
方法来调用此 REST 服务吗?如果是,语法是什么?我还没有找到它的任何文档或示例。
此外,我需要在文件夹创建后获取它的 ID,但我可以从响应中解析它..
向新创建的文件夹中添加文件应该很容易(SBT 提供了相应的类和方法),但我还没有使用它:-)
最佳答案
我找到了一个解决方案..尽管我更愿意使用 JSON,而且 Xerces XML 文档的句柄可能不是很优雅,因为我没有使用它的经验......但它有效......
public String createFolderInCommunity() {
String folderId = "";
try {
// this is the atom entry.. would be nices if it was JSON..
String entry = "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:app=\"http://www.w3.org/2007/app\" xmlns:snx=\"http://www.ibm.com/xmlns/prod/sn\">"
+ "<category term=\"collection\" label=\"collection\" scheme=\"tag:ibm.com,2006:td/type\"></category>"
+ "<label xmlns=\"urn:ibm.com/td\" makeUnique=\"true\">TESTssss4444</label>"
+ "<title>Test: "
+ (new Date()).toString()
+ "</title>"
+ "<summary type=\"text\">teset set e</summary>"
+ "</entry>";
// Request URI with the Community ID.. of course the community id
// will be given as a parameter
String requestUri = "/files/form/api/communitycollection/1802d0e8-f6b8-4d51-8db0-75997ed83489/feed";
String payload = entry;
// here would be the point of using APPLICATION_JSON, but did not
// find any documentation about the JSON Object format :-(
ClientService.ContentString cc = new ClientService.ContentString(
payload, CommonConstants.APPLICATION_ATOM_XML);
// create the service uppon the IBM Connections endpoint (in this
// case SSO)
Response response = getEndPoint().getClientService().post(
requestUri, cc);
// Getting the object as a apache xerces DeferredDocumentImpl, with
// which i have absolutely no experience..
DeferredDocumentImpl obj = (DeferredDocumentImpl) response
.getData();
NodeList lstNodes = obj.getFirstChild().getChildNodes();
// so getting the value this way might be clumsy, but it works...
for (int x = 0; x < lstNodes.getLength(); x++) {
String name = lstNodes.item(x).getNodeName();
if (name.equals("td:uuid")) {
folderId = lstNodes.item(x).getFirstChild()
.getTextContent();
break;
}
}
} catch (Exception e) {
Util.logError(e);
}
return folderId;
}
关于java - IBM SBT : Create a folder in a community,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26912475/
我是一名优秀的程序员,十分优秀!