我正在开发基于REST API的Alfresco客户端。
但是我还没有找到一种方法可以检索带有路径的节点。
[ base url: /alfresco/api/-default-/public/alfresco/versions/1 , api version: 1 ]
你能告诉我我该怎么做吗?
下面的代码将按预期从文件夹/文件路径返回noderef。
public static void main(String[] args) throws IOException {
client = new AlfrescoClient.Builder().connect("http://localhost:8080/alfresco", "admin", "admin").build();
NodeRepresentation node = findNodeByPath("Sites/testsite/documentLibrary/TestFolder/UploadTest.txt");
System.out.println(node == null ? "null" : node.getName());
}
private static NodeRepresentation findNodeByPath(String path) throws IOException {
if (path.startsWith("/"))
path = path.substring(1);
if (path.endsWith("/"))
path = path.substring(0, path.length() - 1);
return findNodeByPath("-root-", path);
}
private static NodeRepresentation findNodeByPath(String parentNodeId, String path) throws IOException {
String[] pathParts = path.split("/");
String name = pathParts[0];
String remaining = pathParts.length == 1 ? "" : path.substring(name.length() + 1, path.length());
List<NodeRepresentation> children = client.getNodesAPI().listNodeChildrenCall(parentNodeId).execute().body()
.getList();
for (NodeRepresentation child : children) {
if (child.getName().equals(name)) {
return pathParts.length == 1 ? child : findNodeByPath(child.getId(), remaining);
}
}
return null;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句