如何将具有其他属性的文件添加到Liferay的文档库中

时间:2011-03-18 19:51:58

标签: java liferay document-library jcr liferay-6

我想弄明白这一点,我在Liferay's forum here - 最后一个条目中问这个问题。

我唯一能想到的就是为FileEntry创建一个Expando,这看起来非常复杂。谁知道它是否有意义。我不喜欢expando功能,因为我无法通过hibernate正确查询它们。

有人在Liferay论坛上知道我的问题的答案吗?

问题是,

DLAppLocalServiceUtil.addFileEntry(...);
DLLocalServiceUtil.addFile(....);

不允许您存储有关该文件的任何其他信息/属性。因此,人们必须直接使用JackRabbit,而不是使用Liferay的JCRHook。但是你放弃了文档库带来的所有优势。

1 个答案:

答案 0 :(得分:3)

是的,唯一的选择是使用Expando AKA自定义属性/字段。在fileEntry的情况下,您不需要以编程方式创建表和列,但您可以在控制面板>中设置它。自定义字段。

之后,您可以选择如何填充expando值。

fileEntry.getExpandoBridge().setAttribute("propName", "propValue")

或者如果您从视图层获取属性

<liferay-ui:custom-attributes-available className="<%= DLFileEntry.class.getName() %>">
    <liferay-ui:custom-attribute-list
        className="<%= DLFileEntry.class.getName() %>"
        classPK="<%= (fileVersion != null) ? fileVersion.getFileVersionId() : 0 %>"
        editable="<%= true %>"
        label="<%= true %>"
        />
</liferay-ui:custom-attributes-available>

然后

ServiceContext serviceContext = ServiceContextFactory.getInstance(
            DLFileEntry.class.getName(), actionRequest);

serviceRetext由actionRequest中的参数填充,然后您只需调用

fileEntry.getExpandoBridge().setAttributes(serviceContext)

最后,您可能需要查询具有特定属性的fileEntries

public Hits search() {
     Map<String, Serializable> attributes = new HashMap<String, Serializable>();
     attributes.put("propertyName", "propertyValue");

     SearchContext searchContext = new SearchContext();
     searchContext.setAttributes(attributes);
     Indexer indexer = IndexerRegistryUtil.getIndexer(FileEntry.class);
     return indexer.search(searchContext);
}

当然,这个解决方案可能看起来有点复杂,因为Liferay文档库不是JCR内容存储库,但它实际上是一个文档库,它通过Hooks为具体的repo实现提供抽象层,例如JCRHook(存储文件的地方)进入jackrabbit存储库),CMIS支持,迁移支持等。它还处理permissionChecking,fileVersioning,文档工作流和资产管理。

因此,如果您打算执行更复杂的操作,则必须查询属性/元数据,更改它们并展开它们。您应该考虑直接使用JCR存储库...