Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mike Harris
Getting associated WebContent(s) of an asset publisher programmatically
March 6, 2012 12:26 PM
Answer

Mike Harris

Rank: Junior Member

Posts: 91

Join Date: March 28, 2011

Recent Posts

My goal is to find all web content(s) associated to asset publishers inside a page.

I'm able to get a Portlet object and check if it's an asset publisher or not:
1       
2LayoutTypePortlet lt = (LayoutTypePortlet)layout.getLayoutType();
3List<Portlet> portlets = lt.getPortlets();
4for (Portlet portlet : portlets) {
5    System.out.println(portlet.getDisplayName());               
6}


After that, I'm lost. How can I take that Portlet object and find the ids (or other informations) about Web Contests that are associated to it in its configuration?
Mike Harris
RE: Getting associated WebContent(s) of an asset publisher programmatically
March 6, 2012 1:09 PM
Answer

Mike Harris

Rank: Junior Member

Posts: 91

Join Date: March 28, 2011

Recent Posts

Finally, I found the uuid of the asset entry(ies) like this :

 1        LayoutTypePortlet lt = (LayoutTypePortlet)layout.getLayoutType();
 2        List<Portlet> portlets = lt.getPortlets();
 3        for (Portlet portlet : portlets) {            
 4            PortletPreferences preferences =  PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), "<portlet-preferences />");
 5
 6            String[] assetEntryXmls = preferences.getValues(
 7                    "assetEntryXml", new String[0]);
 8            
 9            for (int i = 0; i < assetEntryXmls.length; i++) {
10                Document doc;
11
12                    doc = SAXReaderUtil.read(assetEntryXmls[i]);
13                    String assetEntryType = XmlUtil.getContentFromXpath("/asset-entry/asset-entry-type/text()", doc);
14                    String assetEntryUuid = XmlUtil.getContentFromXpath("/asset-entry/asset-entry-uuid/text()", doc);
15                   
16                    System.out.println(i + " : " + assetEntryType + " : " + assetEntryUuid);
17                
18            }
19
20        }


XMLUtil is just a class that I wrote that runs an XPath query on the Document object.
Wow, that was something. ;)

Note that it will probably crash if you have other portlets than asset publisher, I didn't tested for this. So it's not production ready.