necker
necker

Reputation: 7163

Liferay: How to get relative paths to web contents's documents and media

Under Web content I set my structure to have an application field: "Documents an media".

Through this field user can add various files which are then displayed in my .xhtml.

User can make this "Documents and media" field repeatable to add more files.

How could I iterate through all added files and get their relative paths.

If my Documents and media field is not repeatable I can get relative path like this:

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

This method return relative path to my added document (say horses.pdf).

How could I get relative paths to more documents added through "Documents and media field", which is repeatable and has defined specific Variable name (say HorsesPdfs?)

Any help would be greatly appreciated!

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

Upvotes: 0

Views: 2645

Answers (1)

Whimusical
Whimusical

Reputation: 6649

You could try

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

Where

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

For FOLDER ID, you can use root older of LR´s Doc & Media which is

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) 

Upvotes: 1

Related Questions