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);
| }
| }
|
| }
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3975039#3975039
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3975039
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user