Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用FileNet API获取文档集中文档的最新版本的检索名称_Java_Filenet P8_Filenet_Filenet Content Engine - Fatal编程技术网

Java 使用FileNet API获取文档集中文档的最新版本的检索名称

Java 使用FileNet API获取文档集中文档的最新版本的检索名称,java,filenet-p8,filenet,filenet-content-engine,Java,Filenet P8,Filenet,Filenet Content Engine,我有一段代码: Folder fold = Factory.Folder.fetchInstance(os, folderPath, null); DocumentSet docs = fold.get_ContainedDocuments(); Iterator it = docs.iterator(); Document retr; try { while (it.hasNext()) { retr = (Document)it.next(); St

我有一段代码:

Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
DocumentSet docs = fold.get_ContainedDocuments();
Iterator it = docs.iterator();

Document retr;
try {
    while (it.hasNext()) {
        retr = (Document)it.next();
        String name = retr.get_Name();
        System.out.println(name);

        if(name.equals(fileName)) {
            System.out.println("Match Found");
            System.out.println("Document Name : " + retr.get_Name());
            return retr;
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}
目前,这段代码可以很好地检索具有特定文件名的文档。我想添加到该文件中,以便它也可以选择具有该名称的文件的最新版本。我该怎么办


我已经考虑在现有的if中添加一个额外的if,但我担心会影响性能。

如果您正在归档文档(或文档的子类),所包含的文档将是当前文档版本。在这种情况下,当前文档版本为(按使用顺序):

  • 发布的版本(如果有),其他
  • 当前版本(如果有),否则
  • 预订版本

您不能使用
Folder.file
方法将特定文档版本归档到文件夹中,因此您将始终在文件夹中设置具有最新版本的
文档集
,这是您可以执行的操作,以获取文档的最新版本

    Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
        DocumentSet docs = fold.get_ContainedDocuments();
        Iterator it = docs.iterator();

        Document retr;
        try {
            while (it.hasNext()) {
                retr = (Document)it.next();
                String name = retr.get_Name();
                System.out.println(name);

                if(name.equals(fileName)) {

                    System.out.println("Match Found");
                    System.out.println("Document Name : " + retr.get_Name());
//here you are checking the document for the name. It also can happen that, this document might have more than version but the title remained same for each version. You can get the latest version like

                    return retr.get_CurrentVersion();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

我认为性能不是问题。为什么不试一下,自己测量一下,然后把结果贴出来作为答案。你的题目和你的问题并不匹配。您是在尝试排序,还是只是在请求时尝试检索某个文档?@ChristopherPowell我正在尝试检索该文档。也许我的措辞令人困惑。