1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.aggregator.impl;
18
19 import java.io.BufferedReader;
20 import java.io.StringReader;
21 import java.util.Map;
22
23 import javax.portlet.PortletException;
24 import javax.servlet.RequestDispatcher;
25 import javax.servlet.ServletContext;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.apache.jetspeed.aggregator.PortletContent;
30 import org.apache.jetspeed.headerresource.HeaderResource;
31 import org.apache.jetspeed.portlet.PortletHeaderRequest;
32 import org.apache.jetspeed.portlet.PortletHeaderResponse;
33 import org.apache.jetspeed.request.RequestContext;
34
35
36 public class PortletHeaderResponseImpl implements PortletHeaderResponse
37 {
38 private RequestContext requestContext;
39 private HeaderResource hr;
40 private String tempContent;
41
42 private boolean isDesktop;
43
44 private Map headerConfiguration;
45 private Map headerResourceRegistry;
46
47 public PortletHeaderResponseImpl( RequestContext requestContext, HeaderResource hr, boolean isDesktop, Map headerConfiguration, Map headerResourceRegistry )
48 {
49 this.requestContext = requestContext;
50 this.hr = hr;
51 this.isDesktop = isDesktop;
52
53 this.headerConfiguration = headerConfiguration;
54 this.headerResourceRegistry = headerResourceRegistry;
55 }
56
57 public void include(PortletHeaderRequest request, PortletHeaderResponse response, String headerResource)
58 throws PortletException
59 {
60 try
61 {
62 HttpServletRequest servletRequest = requestContext.getRequest();
63 HttpServletResponse servletResponse = requestContext.getResponse();
64 PortletContent content = new PortletContentImpl();
65 HttpBufferedResponse bufferedResponse =
66 new HttpBufferedResponse(servletResponse, content.getWriter());
67 ServletContext crossContext = requestContext.getConfig().getServletContext().getContext(request.getPortletApplicationContextPath());
68 RequestDispatcher dispatcher = crossContext.getRequestDispatcher(headerResource);
69 if (dispatcher != null)
70 dispatcher.include(servletRequest, bufferedResponse);
71 bufferedResponse.flushBuffer();
72 BufferedReader reader = new BufferedReader(new StringReader(content.getContent()));
73 String buffer;
74 StringBuffer headerText = new StringBuffer();
75 while ((buffer = reader.readLine()) != null)
76 {
77 headerText.append( buffer ).append( "\r\n" );
78 }
79 tempContent = headerText.toString();
80 }
81 catch (Exception e)
82 {
83 throw new PortletException(e);
84 }
85 }
86
87 protected RequestContext getRequestContext()
88 {
89 return this.requestContext;
90 }
91
92 public HeaderResource getHeaderResource()
93 {
94 return this.hr;
95 }
96
97 public boolean isDesktop()
98 {
99 return this.isDesktop;
100 }
101
102 public Map getHeaderConfiguration()
103 {
104 return this.headerConfiguration;
105 }
106
107 public Map getHeaderResourceRegistry()
108 {
109 return this.headerResourceRegistry;
110 }
111
112 public String getContent()
113 {
114 return tempContent;
115 }
116 }