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 |
0 |
{ |
49 |
0 |
this.requestContext = requestContext; |
50 |
0 |
this.hr = hr; |
51 |
0 |
this.isDesktop = isDesktop; |
52 |
|
|
53 |
0 |
this.headerConfiguration = headerConfiguration; |
54 |
0 |
this.headerResourceRegistry = headerResourceRegistry; |
55 |
0 |
} |
56 |
|
|
57 |
|
public void include(PortletHeaderRequest request, PortletHeaderResponse response, String headerResource) |
58 |
|
throws PortletException |
59 |
|
{ |
60 |
|
try |
61 |
|
{ |
62 |
0 |
HttpServletRequest servletRequest = requestContext.getRequest(); |
63 |
0 |
HttpServletResponse servletResponse = requestContext.getResponse(); |
64 |
0 |
PortletContent content = new PortletContentImpl(); |
65 |
0 |
HttpBufferedResponse bufferedResponse = |
66 |
|
new HttpBufferedResponse(servletResponse, content.getWriter()); |
67 |
0 |
ServletContext crossContext = requestContext.getConfig().getServletContext().getContext(request.getPortletApplicationContextPath()); |
68 |
0 |
RequestDispatcher dispatcher = crossContext.getRequestDispatcher(headerResource); |
69 |
0 |
if (dispatcher != null) |
70 |
0 |
dispatcher.include(servletRequest, bufferedResponse); |
71 |
0 |
bufferedResponse.flushBuffer(); |
72 |
0 |
BufferedReader reader = new BufferedReader(class="keyword">new StringReader(content.getContent())); |
73 |
|
String buffer; |
74 |
0 |
StringBuffer headerText = new StringBuffer(); |
75 |
0 |
while ((buffer = reader.readLine()) != null) |
76 |
|
{ |
77 |
0 |
headerText.append( buffer ).append( "\r\n" ); |
78 |
|
} |
79 |
0 |
tempContent = headerText.toString(); |
80 |
|
} |
81 |
0 |
catch (Exception e) |
82 |
|
{ |
83 |
0 |
throw new PortletException(e); |
84 |
0 |
} |
85 |
0 |
} |
86 |
|
|
87 |
|
protected RequestContext getRequestContext() |
88 |
|
{ |
89 |
0 |
return this.requestContext; |
90 |
|
} |
91 |
|
|
92 |
|
public HeaderResource getHeaderResource() |
93 |
|
{ |
94 |
0 |
return this.hr; |
95 |
|
} |
96 |
|
|
97 |
|
public boolean isDesktop() |
98 |
|
{ |
99 |
0 |
return this.isDesktop; |
100 |
|
} |
101 |
|
|
102 |
|
public Map getHeaderConfiguration() |
103 |
|
{ |
104 |
0 |
return this.headerConfiguration; |
105 |
|
} |
106 |
|
|
107 |
|
public Map getHeaderResourceRegistry() |
108 |
|
{ |
109 |
0 |
return this.headerResourceRegistry; |
110 |
|
} |
111 |
|
|
112 |
|
public String getContent() |
113 |
|
{ |
114 |
0 |
return tempContent; |
115 |
|
} |
116 |
|
} |