01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.aggregator.impl;
18:
19: import java.io.IOException;
20: import java.util.HashMap;
21:
22: import org.apache.jetspeed.PortalReservedParameters;
23: import org.apache.jetspeed.aggregator.PortletAggregator;
24: import org.apache.jetspeed.aggregator.PortletRenderer;
25: import org.apache.jetspeed.exception.JetspeedException;
26: import org.apache.jetspeed.om.page.ContentFragment;
27: import org.apache.jetspeed.om.page.ContentFragmentImpl;
28: import org.apache.jetspeed.om.page.Fragment;
29: import org.apache.jetspeed.request.RequestContext;
30:
31: /**
32: * PortletAggregator builds the content required to render a single portlet.
33: *
34: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
35: * @version $Id: PortletAggregatorImpl.java 543171 2007-05-31 15:55:09Z ate $
36: */
37: public class PortletAggregatorImpl implements PortletAggregator {
38: private PortletRenderer renderer;
39:
40: public PortletAggregatorImpl(PortletRenderer renderer) {
41: this .renderer = renderer;
42: }
43:
44: /* (non-Javadoc)
45: * @see org.apache.jetspeed.aggregator.Aggregator#build(org.apache.jetspeed.request.RequestContext)
46: */
47: public void build(RequestContext context) throws JetspeedException,
48: IOException {
49: // construct Fragment for rendering use with
50: // appropriate id to match portlet entity
51: String entity = context
52: .getRequestParameter(PortalReservedParameters.PORTLET_ENTITY);
53: if (entity == null) {
54: entity = (String) context
55: .getAttribute(PortalReservedParameters.PORTLET_ENTITY);
56: }
57: if (entity == null) {
58: return;
59: }
60: Fragment fragment = context.getPage().getFragmentById(entity);
61: if (fragment == null) {
62: String name = context
63: .getRequestParameter(PortalReservedParameters.PORTLET);
64: if (name == null) {
65: name = (String) context
66: .getAttribute(PortalReservedParameters.PORTLET);
67: }
68: if (name == null) {
69: return;
70: }
71: fragment = new PortletAggregatorFragmentImpl(entity);
72: fragment.setType(Fragment.PORTLET);
73: fragment.setName(name);
74: }
75: ContentFragment contentFragment = new ContentFragmentImpl(
76: fragment, new HashMap());
77: renderer.renderNow(contentFragment, context);
78: context.getResponse().getWriter().write(
79: contentFragment.getRenderedContent());
80: }
81:
82: }
|