3

The requirement is as follows,

When a new web content(corresponding to a particular structure, say A) is published, it should automatically get updated on the Asset Publisher portlet (default functionality of Asset Publisher).

By default the Title of the web content is what appears as a link on the Asset Publisher for different web contents. Instead of this I want the content of an element (say name) of structure A to appear as a link. Clicking on this link should open an Alloy UI Popup containing the corresponding Web content.

For this to happen I created a new 'display style' jsp using hooks (tweaked the abstracts.jsp).

Wrote this scriptlet in the .jsp:

<%
String personName=null;
JournalArticle journalArticle=null;
String myContent=null;
Document document = null;
Node node=null;
Node node1=null;
Node node2=null;
Node node3=null;
int noOfWords=0;
String pic=null;
String aboutMe=null;

double version=0;

try {
    version=JournalArticleLocalServiceUtil.getLatestVersion(assetRenderer.getGroupId(), "14405");
    journalArticle = JournalArticleLocalServiceUtil.getArticle(assetRenderer.getGroupId() , "14405",version);

    myContent = journalArticle.getContent();    

    document = SAXReaderUtil.read(new StringReader(myContent));        
    node = document.selectSingleNode("/root/dynamic-element[@name='personName']/dynamic-content"); 

    if (node.getText().length() > 0) {            
        personName = node.getText();        
    }    

    node1 = document.selectSingleNode("/root/dynamic-element[@name='pic']/dynamic-content");
    if (node1.getText().length() > 0) {         
        pic = node1.getText();
    }

    node2 = document.selectSingleNode("/root/dynamic-element[@name='noOfWords']/dynamic-content");
    if (node2.getText().length() > 0) {
        noOfWords = Integer.parseInt(node2.getText());        
    }

    node3 = document.selectSingleNode("/root/dynamic-element[@name='aboutMe']/dynamic-content");
    if (node3.getText().length() > 0) {            
        aboutMe = node3.getText(). substring(0,noOfWords)+"....";        
    }
} catch (PortalException e) {
    e.printStackTrace();
} catch (DocumentException e) {
    e.printStackTrace();
}
%>

But here the articleId needs to be hard coded.

I want to fetch the articleId here as and when a new web content is published i.e. dynamically.

Which API should be used here?

Any help is appreciated.

Thanks.

Prakash K
  • 11,669
  • 6
  • 51
  • 109
irene
  • 37
  • 1
  • 9

1 Answers1

1

This method works for me on the latest version of Liferay - Liferay 6.1.1 CE GA2, but I think it should works without any changes on previous versions too.

Briefly, you could use getClassPK() method of the AssetEntry instance.

In all of the display jsps you get asset entry as request attribute:

AssetEntry assetEntry = (AssetEntry)request.getAttribute("view.jsp-assetEntry");

And then to get latest version of journal article that's associated with asset entry instead of using:

double version = 
        JournalArticleLocalServiceUtil.getLatestVersion(assetRenderer.getGroupId(),
        articleId);
JournalArticle journalArticle = 
        JournalArticleLocalServiceUtil.getArticle(assetRenderer.getGroupId(), 
        articleId, version);

you could just write:

JournalArticle journalArticle = 
        JournalArticleLocalServiceUtil.getLatestArticle(assetEntry.getClassPK());

Hope this helps.

Artem Shafranov
  • 2,655
  • 19
  • 19
  • Thnks a lot for the reply!!!really helpful...It solved one purpose of mine ,but the other is still unsolved..On clicking on the link I need the corresponding web content /article to open up.so in the url i would still need groupId,articleId,version. How do I get these? – irene Sep 25 '12 at 09:41
  • Once you've got instance of JournalArticle you've also got all the getters to obtain what you need: journalArticle.getGroupId(), journalArticle.getArticleId(), journalArticle.getVersion(). Try to use them for your task. In case you don't succeed, please, create another, more specific question. It's would be difficult to answer in comments. – Artem Shafranov Sep 25 '12 at 11:48
  • Thanks again..n yep..i will be posting another question regarding this.Hope you can help me out there too. – irene Sep 25 '12 at 12:35