Liferay:如何获取Web内容文档和媒体的相对路径

时间:2012-10-12 10:04:45

标签: jsf liferay portlet

网络内容下,我将结构设置为具有应用程序字段:“记录媒体”。

通过此字段,用户可以添加各种文件,然后在我的.xhtml中显示。

用户可以将此文档和媒体字段可重复添加到更多文件中。

如何迭代所有添加的文件并获取相关路径。

如果我的文档和媒体字段不可重复,我可以得到这样的相对路径:

    public String getWebContentTitle(String title, String nodeName) throws PortalException, SystemException {
        FacesContext context = FacesContext.getCurrentInstance();
        ThemeDisplay themeDisplay = (ThemeDisplay) context.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
        long groupId = themeDisplay.getScopeGroupId();
        JournalArticle article = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, formatUrlTitle(title));
        String languageKey = context.getExternalContext().getRequestLocale().toString();
        JournalArticleDisplay articleDisplay = JournalContentUtil.getDisplay(groupId, article.getArticleId(), article.getTemplateId(), languageKey, themeDisplay);
        JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(groupId, article.getArticleId());
        String myContent = journalArticle.getContentByLocale(languageKey);

        if (nodeName != null) {
            String nodeText=getParseValue(nodeName, journalArticle, myContent);
            return nodeText;
        } else
        {
            String ret=articleDisplay.getContent(); 
            return ret;
        }
    }

    private String getParseValue(String fieldname, JournalArticle article, String locale) {
        String nodeText = "";
        try {
              Document document = SAXReaderUtil.read(article.getContentByLocale(locale));
              Node node = document.selectSingleNode("/root/dynamic-element[@name='" + fieldname +"']/dynamic-content");
              nodeText = node.getText(); 
        } catch(Exception e){

        }
        return nodeText; 
    }

此方法返回我添加的文档的相对路径(比如horses.pdf)。

我怎样才能获得通过“文档和媒体字段”添加的更多文档的相对路径,这些文档是可重复的并且已经定义了特定的变量名称(比如HorsesPdfs?)

非常感谢任何帮助!

Documents and media field - repeatable (green plus on picture)

1 个答案:

答案 0 :(得分:1)

你可以尝试

DLAppLocalServiceUtil.getFileEntries(REPOSITORY_ID, FOLDER_ID), probably better than DLFileEntry as its the new approach that takes workflows in consideration.

哪里

REPOSITORY_ID = parent group, which is by default LR´s one GroupLocalServiceUtil.getGroup(COMPANY_ID, GroupConstants.GUEST).getGroupId()

COMPANY_ID = PortalUtil.getDefaultCompanyId(); //If just one instance, if not, better to play with CompanyLocalServiceUtil to match your Id

对于FOLDER ID,您可以使用旧的LR的Doc&

的媒体
FOLDER_ID = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; //or find it e.g DLAppLocalServiceUtil.getFolder( repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, FOLDER_NAME).getFolderId();  if you programtically used addFolder(long userId, long repositoryId, long parentFolderId, String name, String description, ServiceContext serviceContext)