English 中文(简体)
How to add file with additional properties into Liferay s Document Library
原标题:

I m trying to figure this out, I was asking this question in Liferay s forum here - the last entry.

And only thing I m able to come up with is creating an Expando for FileEntry, which seems very complicated. Who knows if it makes sense. I don t like the expando feature since I couldn t query them via hibernate properly.

Does anybody know the answer for my question in that Liferay forum ?

The problem is that,

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

doesn t let you store any additional information / properties about the file. As a result, one would have to use JackRabbit directly, instead of using Liferay s JCRHook. But you loose all the advantages that Document Library brings.

最佳回答

Yep, the only option is to use Expando AKA custom properties/fields. In case of fileEntry you don t need to create table and columns programmatically but you can set it up in Control Panel > custom fields.

After that you have a few options how to populate the expando values.

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

or if you get the properties from view layer

<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>

and then

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

serviceContext gets populated by parameters in actionRequest and you then just call

fileEntry.getExpandoBridge().setAttributes(serviceContext)

Finally, you may need to query for fileEntries with particular properties

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);
}

Of course, this solution may seem a little complicated, because Liferay Document Library is not a JCR content repository, but it s literally a document library that provides abstraction layer for concrete repo implementations via Hooks, such as JCRHook ( where files are stored into jackrabbit repository ), CMIS support, migration support etc. It also handles permissionChecking, fileVersioning, document workflow and asset management.

So if you intend to do something more complicated and you will have to query the properties/metadata, change them and expand them. You should consider using JCR repository directly...

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签