001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.aggregator.impl;
018:
019: import java.io.BufferedReader;
020: import java.io.StringReader;
021: import java.util.Map;
022:
023: import javax.portlet.PortletException;
024: import javax.servlet.RequestDispatcher;
025: import javax.servlet.ServletContext;
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.jetspeed.aggregator.PortletContent;
030: import org.apache.jetspeed.headerresource.HeaderResource;
031: import org.apache.jetspeed.portlet.PortletHeaderRequest;
032: import org.apache.jetspeed.portlet.PortletHeaderResponse;
033: import org.apache.jetspeed.request.RequestContext;
034:
035: public class PortletHeaderResponseImpl implements PortletHeaderResponse {
036: private RequestContext requestContext;
037: private HeaderResource hr;
038: private String tempContent;
039:
040: private boolean isDesktop;
041:
042: private Map headerConfiguration;
043: private Map headerResourceRegistry;
044:
045: public PortletHeaderResponseImpl(RequestContext requestContext,
046: HeaderResource hr, boolean isDesktop,
047: Map headerConfiguration, Map headerResourceRegistry) {
048: this .requestContext = requestContext;
049: this .hr = hr;
050: this .isDesktop = isDesktop;
051:
052: this .headerConfiguration = headerConfiguration;
053: this .headerResourceRegistry = headerResourceRegistry;
054: }
055:
056: public void include(PortletHeaderRequest request,
057: PortletHeaderResponse response, String headerResource)
058: throws PortletException {
059: try {
060: HttpServletRequest servletRequest = requestContext
061: .getRequest();
062: HttpServletResponse servletResponse = requestContext
063: .getResponse();
064: PortletContent content = new PortletContentImpl();
065: HttpBufferedResponse bufferedResponse = new HttpBufferedResponse(
066: servletResponse, content.getWriter());
067: ServletContext crossContext = requestContext.getConfig()
068: .getServletContext().getContext(
069: request.getPortletApplicationContextPath());
070: RequestDispatcher dispatcher = crossContext
071: .getRequestDispatcher(headerResource);
072: if (dispatcher != null)
073: dispatcher.include(servletRequest, bufferedResponse);
074: bufferedResponse.flushBuffer();
075: BufferedReader reader = new BufferedReader(
076: new StringReader(content.getContent()));
077: String buffer;
078: StringBuffer headerText = new StringBuffer();
079: while ((buffer = reader.readLine()) != null) {
080: headerText.append(buffer).append("\r\n");
081: }
082: tempContent = headerText.toString();
083: } catch (Exception e) {
084: throw new PortletException(e);
085: }
086: }
087:
088: protected RequestContext getRequestContext() {
089: return this .requestContext;
090: }
091:
092: public HeaderResource getHeaderResource() {
093: return this .hr;
094: }
095:
096: public boolean isDesktop() {
097: return this .isDesktop;
098: }
099:
100: public Map getHeaderConfiguration() {
101: return this .headerConfiguration;
102: }
103:
104: public Map getHeaderResourceRegistry() {
105: return this .headerResourceRegistry;
106: }
107:
108: public String getContent() {
109: return tempContent;
110: }
111: }
|