Fórum

Getting associated WebContent(s) of an asset publisher programmatically

Mike Harris, modificado 12 Anos atrás.

Getting associated WebContent(s) of an asset publisher programmatically

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
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:
        
LayoutTypePortlet lt = (LayoutTypePortlet)layout.getLayoutType(); 
List<portlet> portlets = lt.getPortlets();
for (Portlet portlet : portlets) {
    System.out.println(portlet.getDisplayName());                
}</portlet>


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, modificado 12 Anos atrás.

RE: Getting associated WebContent(s) of an asset publisher programmatically

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
Finally, I found the uuid of the asset entry(ies) like this :

        LayoutTypePortlet lt = (LayoutTypePortlet)layout.getLayoutType(); 
        List<portlet> portlets = lt.getPortlets();
        for (Portlet portlet : portlets) {            
            PortletPreferences preferences =  PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), "<portlet-preferences />");

            String[] assetEntryXmls = preferences.getValues(
                    "assetEntryXml", new String[0]);
            
            for (int i = 0; i &lt; assetEntryXmls.length; i++) {
                Document doc;

                    doc = SAXReaderUtil.read(assetEntryXmls[i]);
                    String assetEntryType = XmlUtil.getContentFromXpath("/asset-entry/asset-entry-type/text()", doc);
                    String assetEntryUuid = XmlUtil.getContentFromXpath("/asset-entry/asset-entry-uuid/text()", doc);
                    
                    System.out.println(i + " : " + assetEntryType + " : " + assetEntryUuid);
                 
            }

        }</portlet>


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.