-
1. Re: IPC Portlet calling itself?
roy.russo Sep 27, 2006 9:55 PM (in response to trupoet)What do you mean, your file has links? Do you mean links to resources like gifs/png/jpegs?
-
2. Re: IPC Portlet calling itself?
trupoet Sep 28, 2006 3:49 PM (in response to trupoet)Basically I have a content display portlet that will display a file from Alfresco's CMS repository. Now if the file it displays happens to have HTML links to other files in Alfresco's repository, I want it to link back to the portlet with that file as a parameter.
I was able to get this to work with just 1 portlet successfully....the content itself will simply have a relative link to a file in the repository and the portlet will scan for any links and superimpose a response.createActionURL() into them so that they actually send the filepath as a parameter to the portlet. -
3. Re: IPC Portlet calling itself?
trupoet Sep 28, 2006 6:35 PM (in response to trupoet)So the code that does this is below. What I'm wondering is if I even need the Listener since the portlet is just sending an action to itself? Is the Listener / service stuff only needed for other portlets to call each other? This is of course just POC/Experimenting code here.
public class ContentDisplay extends JBossPortlet { private String RootReferencePath = "/app:company_home"; public void processAction(JBossActionRequest request, JBossActionResponse response) throws PortletException, PortletSecurityException, IOException { String filename = request.getParameter("filename"); if(filename != null) response.setRenderParameter("filename",filename); } protected void doView(JBossRenderRequest rRequest, JBossRenderResponse rResponse) throws PortletException, PortletSecurityException, IOException { String filename = rRequest.getParameter("filename"); if(filename == null) filename = "index.html"; AuthenticationUtils.startSession("admin", "admin"); EngineConfiguration config = AuthenticationUtils.getEngineConfiguration(); try { rResponse.setContentType("text/html"); PrintWriter writer = rResponse.getWriter(); Store STORE = new Store(StoreEnum.workspace, "SpacesStore"); //Root store for Alfresco filename = filename.replaceAll("/","/cm:"); String refPath = RootReferencePath + "/cm:"+filename; Reference reference = new Reference(STORE, null,refPath); ContentServiceLocator contServLocator = new ContentServiceLocator(config); ContentServiceSoapPort contService = (ContentServiceSoapPort)contServLocator.getContentService(); Content[] readResult = contService.read(new Predicate(new Reference[]{reference}, STORE, null), Constants.PROP_CONTENT); Content content = readResult[0]; String contentUrl = content.getUrl() + "?ticket="+AuthenticationUtils.getCurrentTicket(); StringBuilder content2Print = new StringBuilder(); URL url = new URL(contentUrl); URLConnection conn = url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); content2Print.append(br.readLine()); while (br.ready()) { content2Print.append(br.readLine()); } String finalContent = content2Print.toString(); Pattern oldLinks = Pattern.compile("<a href=\"\$"); finalContent = oldLinks.matcher(finalContent).replaceAll("<a href=\""+rResponse.createActionURL()+"&filename="); writer.write(finalContent); writer.close(); } catch(Throwable e) { Log.error(this,"Something bad happened: ",e); } finally { AuthenticationUtils.endSession(); } } public static class Listener implements PortalNodeEventListener { public PortalNodeEvent onEvent(PortalNodeEventBubbler bubbler, PortalNodeEvent event) { PortalNode node = event.getNode(); String nodeName = node.getName(); WindowActionEvent newEvent = null; if(nodeName.equals("ContentDisplayPortlet") && event instanceof WindowActionEvent) { WindowActionEvent wae = (WindowActionEvent) event; if(node != null) { newEvent = new WindowActionEvent(node); newEvent.setMode(wae.getMode()); newEvent.setParameters(wae.getParameters()); } } if(newEvent != null) return newEvent; else return bubbler.dispatch(event); } } }
-
4. Re: IPC Portlet calling itself?
antoine_h Jan 31, 2007 12:05 PM (in response to trupoet)Hello,
you may have find your answer by now.
may be you can also look at the CMSObjectCommandFactory and the CMSObjectURLFactory.
this may be a way to do what you need.
(as for the gif, jpg, etc... sub content of a html page).
see also how it uses the StreamContentCommand.
and how it is used in the CMSPortlet.
hope it helps,