0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: package org.apache.jetspeed.aggregator.impl;
0018:
0019: import java.io.IOException;
0020: import java.util.Iterator;
0021: import java.util.Map;
0022: import java.util.HashMap;
0023: import java.util.List;
0024: import java.util.ArrayList;
0025: import java.util.Collections;
0026:
0027: import javax.portlet.Portlet;
0028:
0029: import org.apache.commons.logging.Log;
0030: import org.apache.commons.logging.LogFactory;
0031:
0032: import org.apache.jetspeed.aggregator.FailedToRenderFragmentException;
0033: import org.apache.jetspeed.aggregator.PageAggregator;
0034: import org.apache.jetspeed.container.state.NavigationalState;
0035: import org.apache.jetspeed.container.url.BasePortalURL;
0036: import org.apache.jetspeed.container.window.PortletWindowAccessor;
0037: import org.apache.jetspeed.decoration.DecorationFactory;
0038: import org.apache.jetspeed.exception.JetspeedException;
0039: import org.apache.jetspeed.factory.PortletFactory;
0040: import org.apache.jetspeed.headerresource.HeaderResource;
0041: import org.apache.jetspeed.headerresource.HeaderResourceFactory;
0042: import org.apache.jetspeed.headerresource.HeaderResourceLib;
0043: import org.apache.jetspeed.om.common.portlet.PortletApplication;
0044: import org.apache.jetspeed.om.page.ContentFragment;
0045: import org.apache.jetspeed.om.page.ContentPage;
0046: import org.apache.jetspeed.portlet.PortletHeaderRequest;
0047: import org.apache.jetspeed.portlet.PortletHeaderResponse;
0048: import org.apache.jetspeed.portlet.SupportsHeaderPhase;
0049: import org.apache.jetspeed.request.RequestContext;
0050: import org.apache.jetspeed.PortalReservedParameters;
0051: import org.apache.pluto.om.portlet.PortletDefinition;
0052: import org.apache.pluto.om.window.PortletWindow;
0053:
0054: /**
0055: * HeaderAggregator builds the content required to render a page of portlets.
0056: *
0057: * @author <a href="mailto:raphael@apache.org">Rapha�l Luta </a>
0058: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
0059: * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
0060: * @version $Id: HeaderAggregatorImpl.java 359125 2005-12-26 23:16:39Z rwatler $
0061: */
0062: public class HeaderAggregatorImpl implements PageAggregator {
0063: protected final static Log log = LogFactory
0064: .getLog(HeaderAggregatorImpl.class);
0065: protected final static String EOL = "\r\n"; // html eol
0066:
0067: private PortletFactory factory;
0068: private PortletWindowAccessor windowAccessor;
0069: private HeaderResourceFactory headerResourceFactory;
0070: private DecorationFactory decorationFactory;
0071:
0072: private boolean isDesktop;
0073:
0074: private Map headerConfiguration;
0075: private Map headerResourceRegistry;
0076: private Map headerDynamicConfigurationDefault;
0077: private Map headerNamedResourcesDefault;
0078: private Map headerNamedResourcesAddedFragmentsDefault;
0079:
0080: /** base portal URL to override default URL server info from servlet */
0081: private BasePortalURL baseUrlAccess = null;
0082:
0083: public HeaderAggregatorImpl(PortletFactory factory,
0084: PortletWindowAccessor windowAccessor,
0085: HeaderResourceFactory headerResourceFactory,
0086: boolean isDesktop, Map headerConfiguration,
0087: Map headerResourceRegistry,
0088: DecorationFactory decorationFactory) {
0089: this (factory, windowAccessor, headerResourceFactory, isDesktop,
0090: headerConfiguration, headerResourceRegistry,
0091: decorationFactory, null);
0092: }
0093:
0094: public HeaderAggregatorImpl(PortletFactory factory,
0095: PortletWindowAccessor windowAccessor,
0096: HeaderResourceFactory headerResourceFactory,
0097: boolean isDesktop, Map headerConfiguration,
0098: Map headerResourceRegistry,
0099: DecorationFactory decorationFactory,
0100: BasePortalURL baseUrlAccess) {
0101: this .factory = factory;
0102: this .windowAccessor = windowAccessor;
0103: this .headerResourceFactory = headerResourceFactory;
0104: this .isDesktop = isDesktop;
0105: this .baseUrlAccess = baseUrlAccess;
0106: this .decorationFactory = decorationFactory;
0107: initializeHeaderConfiguration(headerConfiguration,
0108: headerResourceRegistry);
0109: }
0110:
0111: /**
0112: * Initialize header configuration, making immutable copies of the data structures and
0113: * compiling as much finished static header content as possible (to minimize repetitive work per request)
0114: */
0115: private void initializeHeaderConfiguration(Map headerConfigArg,
0116: Map headerRsrcRegistryArg) {
0117: this .headerConfiguration = null;
0118: this .headerResourceRegistry = null;
0119: this .headerDynamicConfigurationDefault = null;
0120: this .headerNamedResourcesDefault = null;
0121: this .headerNamedResourcesAddedFragmentsDefault = null;
0122:
0123: if (headerConfigArg != null && headerConfigArg.size() > 0) {
0124: // attempt to make safe immutable copy of headerConfigArg
0125: HashMap headerConfig = new HashMap();
0126: Iterator headerConfigEntryIter = headerConfigArg.entrySet()
0127: .iterator();
0128: while (headerConfigEntryIter.hasNext()) {
0129: Map.Entry headerConfigEntry = (Map.Entry) headerConfigEntryIter
0130: .next();
0131: Object headerConfigKey = headerConfigEntry.getKey();
0132: Object headerConfigVal = headerConfigEntry.getValue();
0133: if (headerConfigVal instanceof Map) {
0134: headerConfig.put(headerConfigKey, Collections
0135: .unmodifiableMap(new HashMap(
0136: (Map) headerConfigVal)));
0137: } else if (headerConfigVal instanceof List) {
0138: headerConfig.put(headerConfigKey, Collections
0139: .unmodifiableList(new ArrayList(
0140: (List) headerConfigVal)));
0141: } else {
0142: headerConfig.put(headerConfigKey, headerConfigVal);
0143: }
0144: }
0145: this .headerConfiguration = Collections
0146: .unmodifiableMap(headerConfig);
0147:
0148: // make modifiable copy of headerRsrcRegistryArg - is made immutable at end of initializeHeaderConfiguration()
0149: Map headerRsrcRegistry = null;
0150: if (headerRsrcRegistryArg != null
0151: && headerRsrcRegistryArg.size() > 0) {
0152: headerRsrcRegistry = new HashMap(headerRsrcRegistryArg);
0153: // leave modifiable during initializeHeaderConfigurationDefaults() protocol
0154: // (so that entries can be removed - possibly leading to an empty map which will save a bunch of gratuitous lookups)
0155: } else {
0156: headerRsrcRegistry = new HashMap();
0157: }
0158: this .headerResourceRegistry = headerRsrcRegistry;
0159:
0160: HashMap namedResourcesDefault = new HashMap();
0161: HashMap namedResourcesAddedFragmentsDefault = new HashMap();
0162:
0163: Map dynamicConfigurationDefault = initializeHeaderConfigurationDefaults(
0164: namedResourcesDefault,
0165: namedResourcesAddedFragmentsDefault);
0166: if (dynamicConfigurationDefault != null)
0167: this .headerDynamicConfigurationDefault = Collections
0168: .unmodifiableMap(dynamicConfigurationDefault);
0169:
0170: this .headerNamedResourcesDefault = Collections
0171: .unmodifiableMap(namedResourcesDefault);
0172: this .headerNamedResourcesAddedFragmentsDefault = Collections
0173: .unmodifiableMap(namedResourcesAddedFragmentsDefault);
0174:
0175: this .headerResourceRegistry = null;
0176: if (headerRsrcRegistry != null
0177: && headerRsrcRegistry.size() > 0) {
0178: this .headerResourceRegistry = Collections
0179: .unmodifiableMap(headerRsrcRegistry);
0180: }
0181: }
0182: }
0183:
0184: /**
0185: * Initialize dynamic-header-configuration and call initializeHeaderConfigurationEntryDefaults() for
0186: * each key in headerConfiguration Map, allowing for each to add resources and settings to:
0187: * headerNamedResourcesDefault, headerNamedResourcesAddedFragmentsDefault and headerDynamicConfigurationDefault
0188: *
0189: * If no specific handler is defined for a headerConfiguration key, the entry is copied to headerDynamicConfigurationDefault
0190: * otherwise the handler is responsible for adding information to headerDynamicConfigurationDefault
0191: *
0192: * headerConfiguration handlers are currently defined for the headerConfiguration keys:
0193: * "header.order" - HeaderResource.HEADER_CONFIG_ORDER
0194: * "header.types" - HeaderResource.HEADER_CONFIG_TYPES
0195: * "header.requiredflag" - HeaderResource.HEADER_CONFIG_REQUIREDFLAG
0196: * "dojo" - HeaderResource.HEADER_CONFIG_DOJO
0197: * "desktop" - HeaderResource.HEADER_CONFIG_DESKTOP
0198: */
0199: protected Map initializeHeaderConfigurationDefaults(
0200: HashMap namedResourcesDefault,
0201: HashMap namedResourcesAddedFragmentsDefault) {
0202: if (this .headerConfiguration == null) {
0203: return null;
0204: }
0205:
0206: HashMap headerDynamicConfigurationDefault = new HashMap();
0207:
0208: initializeHeaderOrderConfigurationDefaults(
0209: namedResourcesDefault,
0210: namedResourcesAddedFragmentsDefault,
0211: headerDynamicConfigurationDefault);
0212:
0213: // setting header.basetag type - without adding it to order
0214: setNamedHeaderResourceProperties(
0215: HeaderResource.HEADER_SECTION_BASE_TAG,
0216: HeaderResource.HEADER_TYPE_BASE_TAG, null,
0217: headerDynamicConfigurationDefault);
0218:
0219: Iterator hConfigEntryIter = this .headerConfiguration.entrySet()
0220: .iterator();
0221: while (hConfigEntryIter.hasNext()) {
0222: Map.Entry hConfigEntry = (Map.Entry) hConfigEntryIter
0223: .next();
0224: Object hConfigKey = hConfigEntry.getKey();
0225: Object hConfigVal = hConfigEntry.getValue();
0226:
0227: if (!initializeHeaderConfigurationEntryDefaults(hConfigKey,
0228: hConfigVal, namedResourcesDefault,
0229: namedResourcesAddedFragmentsDefault,
0230: headerDynamicConfigurationDefault)) {
0231: if (hConfigVal instanceof Map) {
0232: headerDynamicConfigurationDefault.put(hConfigKey,
0233: Collections.unmodifiableMap(new HashMap(
0234: (Map) hConfigVal)));
0235: } else if (hConfigVal instanceof List) {
0236: headerDynamicConfigurationDefault.put(hConfigKey,
0237: Collections.unmodifiableList(new ArrayList(
0238: (List) hConfigVal)));
0239: } else {
0240: headerDynamicConfigurationDefault.put(hConfigKey,
0241: hConfigVal);
0242: }
0243: }
0244: }
0245: initializeMissingHeaderConfigurationEntryDefaults(
0246: namedResourcesDefault,
0247: namedResourcesAddedFragmentsDefault,
0248: headerDynamicConfigurationDefault);
0249:
0250: postinitializeHeaderOrderConfigurationDefaults(headerDynamicConfigurationDefault);
0251:
0252: return headerDynamicConfigurationDefault;
0253: }
0254:
0255: protected void initializeHeaderOrderConfigurationDefaults(
0256: HashMap namedResourcesDefault,
0257: HashMap namedResourcesAddedFragmentsDefault,
0258: HashMap headerDynamicConfigurationDefault) {
0259: if (this .headerConfiguration != null) {
0260: List headerOrderConfigList = (List) this .headerConfiguration
0261: .get(HeaderResource.HEADER_CONFIG_ORDER);
0262: if (headerOrderConfigList != null
0263: && headerOrderConfigList.size() > 0) {
0264: ArrayList headerOrderList = new ArrayList();
0265: Map headerNames = new HashMap();
0266: Iterator headerOrderListIter = headerOrderConfigList
0267: .iterator();
0268: while (headerOrderListIter.hasNext()) {
0269: Object headerNameObj = headerOrderListIter.next();
0270: if (headerNameObj != null) {
0271: String headerName = headerNameObj.toString();
0272: if (headerName != null
0273: && headerName.length() > 0) {
0274: headerOrderList.add(headerName);
0275: headerNames.put(headerName, Boolean.TRUE);
0276: }
0277: }
0278: }
0279: // add modifiable structures at this point - so that later initialization steps can manipulate the defaults
0280: // needs to be made unmodifiable at end of processing by calling postinitializeHeaderOrderConfigurationDefaults()
0281: headerDynamicConfigurationDefault.put(
0282: HeaderResource.HEADER_CONFIG_ORDER,
0283: headerOrderList);
0284: headerDynamicConfigurationDefault.put(
0285: HeaderResource.HEADER_INTERNAL_INCLUDED_NAMES,
0286: headerNames);
0287: }
0288:
0289: Map headerTypes = null;
0290: Map headerTypesConfig = (Map) this .headerConfiguration
0291: .get(HeaderResource.HEADER_CONFIG_TYPES);
0292: if (headerTypesConfig != null
0293: && headerTypesConfig.size() > 0) {
0294: headerTypes = new HashMap();
0295: Iterator headerTypesConfigIter = headerTypesConfig
0296: .entrySet().iterator();
0297: while (headerTypesConfigIter.hasNext()) {
0298: Map.Entry headerTypeEntry = (Map.Entry) headerTypesConfigIter
0299: .next();
0300: Object headerNameObj = headerTypeEntry.getKey();
0301: Object headerTypeObj = headerTypeEntry.getValue();
0302: if (headerNameObj != null && headerTypeObj != null) {
0303: String headerName = headerNameObj.toString();
0304: int headerTypeId = HeaderResourceLib
0305: .getHeaderTypeId(headerTypeObj
0306: .toString());
0307: if (headerName != null) {
0308: if (headerTypeId >= 0) {
0309: headerTypes.put(headerName,
0310: new Object[] {
0311: new Integer(
0312: headerTypeId),
0313: null });
0314: } else {
0315: log
0316: .error("HeaderAggregatorImpl.initializeHeaderOrderConfigurationDefaults() ignoring specification of unknown header section type; header-section-name="
0317: + headerName
0318: + " header-section-type="
0319: + headerTypeObj
0320: .toString());
0321: }
0322: }
0323: }
0324: }
0325: }
0326:
0327: Map headerRequiredFlagConfig = (Map) this .headerConfiguration
0328: .get(HeaderResource.HEADER_CONFIG_REQUIREDFLAG);
0329: if (headerRequiredFlagConfig != null
0330: && headerRequiredFlagConfig.size() > 0) {
0331: if (headerTypes == null) {
0332: headerTypes = new HashMap();
0333: }
0334: Iterator headerRequiredFlagConfigIter = headerRequiredFlagConfig
0335: .entrySet().iterator();
0336: while (headerRequiredFlagConfigIter.hasNext()) {
0337: Map.Entry headerRequiredFlagEntry = (Map.Entry) headerRequiredFlagConfigIter
0338: .next();
0339: Object headerNameObj = headerRequiredFlagEntry
0340: .getKey();
0341: Object headerReqFlagObj = headerRequiredFlagEntry
0342: .getValue();
0343: if (headerNameObj != null
0344: && headerReqFlagObj != null) {
0345: String headerName = headerNameObj.toString();
0346: String headerReqFlag = headerReqFlagObj
0347: .toString();
0348: if (headerName != null
0349: && headerName.length() > 0
0350: && headerReqFlag != null) {
0351: Object[] headerTypePair = (Object[]) headerTypes
0352: .get(headerName);
0353: if (headerTypePair != null) {
0354: headerTypePair[1] = headerReqFlag;
0355: } else {
0356: headerTypePair = new Object[] { null,
0357: headerReqFlag };
0358: headerTypes.put(headerName,
0359: headerTypePair);
0360: }
0361: }
0362: }
0363: }
0364: }
0365: if (headerTypes != null && headerTypes.size() > 0) {
0366: headerDynamicConfigurationDefault
0367: .put(HeaderResource.HEADER_CONFIG_TYPES,
0368: headerTypes);
0369: }
0370: }
0371: }
0372:
0373: protected void postinitializeHeaderOrderConfigurationDefaults(
0374: HashMap headerDynamicConfigurationDefault) {
0375: if (headerDynamicConfigurationDefault != null) {
0376: Map headerNames = (Map) headerDynamicConfigurationDefault
0377: .get(HeaderResource.HEADER_INTERNAL_INCLUDED_NAMES);
0378: if (headerNames != null) {
0379: headerDynamicConfigurationDefault.put(
0380: HeaderResource.HEADER_INTERNAL_INCLUDED_NAMES,
0381: Collections.unmodifiableMap(headerNames));
0382: }
0383: Map headerTypes = (Map) headerDynamicConfigurationDefault
0384: .get(HeaderResource.HEADER_CONFIG_TYPES);
0385: if (headerTypes != null) {
0386: headerDynamicConfigurationDefault.put(
0387: HeaderResource.HEADER_CONFIG_TYPES, Collections
0388: .unmodifiableMap(headerTypes));
0389: }
0390: List headerOrderList = (List) headerDynamicConfigurationDefault
0391: .get(HeaderResource.HEADER_CONFIG_ORDER);
0392: if (headerOrderList != null) {
0393: headerDynamicConfigurationDefault.put(
0394: HeaderResource.HEADER_CONFIG_ORDER, Collections
0395: .unmodifiableList(headerOrderList));
0396: }
0397: }
0398: }
0399:
0400: /**
0401: * Intended as derived class hook into header configuration process
0402: *
0403: * @return true if headerConfigKey has been processed or false if default processing should occur
0404: */
0405: protected boolean initializeHeaderConfigurationEntryDefaults(
0406: Object headerConfigKey, Object headerConfigValue,
0407: HashMap namedResourcesDefault,
0408: HashMap namedResourcesAddedFragmentsDefault,
0409: HashMap headerDynamicConfigurationDefault) {
0410: if (headerConfigKey.equals(HeaderResource.HEADER_CONFIG_ORDER)
0411: || headerConfigKey
0412: .equals(HeaderResource.HEADER_CONFIG_TYPES)
0413: || headerConfigKey
0414: .equals(HeaderResource.HEADER_CONFIG_REQUIREDFLAG)) {
0415: // do nothing - processed earlier with call to initializeHeaderOrderConfigurationDefaults()
0416: return true;
0417: } else if (headerConfigKey
0418: .equals(HeaderResource.HEADER_CONFIG_DOJO)) {
0419: initializeDojoHeaderConfigurationDefaults(
0420: (Map) headerConfigValue, namedResourcesDefault,
0421: namedResourcesAddedFragmentsDefault,
0422: headerDynamicConfigurationDefault);
0423: return true;
0424: } else if (headerConfigKey
0425: .equals(HeaderResource.HEADER_CONFIG_DESKTOP)) {
0426: initializeDesktopHeaderConfigurationDefaults(
0427: (Map) headerConfigValue, namedResourcesDefault,
0428: namedResourcesAddedFragmentsDefault,
0429: headerDynamicConfigurationDefault);
0430: return true;
0431: }
0432: return false;
0433: }
0434:
0435: protected void initializeMissingHeaderConfigurationEntryDefaults(
0436: HashMap namedResourcesDefault,
0437: HashMap namedResourcesAddedFragmentsDefault,
0438: HashMap headerDynamicConfigurationDefault) {
0439: if (isDesktop()) {
0440: if (this .headerConfiguration
0441: .get(HeaderResource.HEADER_CONFIG_DOJO) == null) {
0442: initializeDojoHeaderConfigurationDefaults(null,
0443: namedResourcesDefault,
0444: namedResourcesAddedFragmentsDefault,
0445: headerDynamicConfigurationDefault);
0446: }
0447: if (this .headerConfiguration
0448: .get(HeaderResource.HEADER_CONFIG_DESKTOP) == null) {
0449: initializeDesktopHeaderConfigurationDefaults(null,
0450: namedResourcesDefault,
0451: namedResourcesAddedFragmentsDefault,
0452: headerDynamicConfigurationDefault);
0453: }
0454: }
0455: }
0456:
0457: protected void registerAndOrderNamedHeaderResource(
0458: String headerName, String headerType, String headerReqFlag,
0459: Map headerDynamicConfigurationDefault) {
0460: orderNamedHeaderResource(headerName,
0461: headerDynamicConfigurationDefault);
0462: setNamedHeaderResourceProperties(headerName, headerType,
0463: headerReqFlag, headerDynamicConfigurationDefault);
0464: }
0465:
0466: protected void orderNamedHeaderResource(String headerName,
0467: Map headerDynamicConfigurationDefault) {
0468: if (headerName != null) {
0469: Map headerNames = (Map) headerDynamicConfigurationDefault
0470: .get(HeaderResource.HEADER_INTERNAL_INCLUDED_NAMES);
0471: if (headerNames == null) {
0472: headerNames = new HashMap();
0473: headerDynamicConfigurationDefault.put(
0474: HeaderResource.HEADER_INTERNAL_INCLUDED_NAMES,
0475: headerNames);
0476: }
0477:
0478: Object headerNamesVal = headerNames.get(headerName);
0479: if (headerNamesVal == null) {
0480: List headerOrderList = (List) headerDynamicConfigurationDefault
0481: .get(HeaderResource.HEADER_CONFIG_ORDER);
0482: if (headerOrderList == null) {
0483: headerOrderList = new ArrayList();
0484: headerDynamicConfigurationDefault.put(
0485: HeaderResource.HEADER_CONFIG_ORDER,
0486: headerOrderList);
0487: }
0488:
0489: headerOrderList.add(headerName);
0490: headerNames.put(headerName, Boolean.TRUE);
0491: }
0492: }
0493: }
0494:
0495: protected void setNamedHeaderResourceProperties(String headerName,
0496: String headerType, String headerReqFlag,
0497: Map headerDynamicConfigurationDefault) {
0498: if (headerName != null) {
0499: int headerTypeId = HeaderResourceLib
0500: .getHeaderTypeId(headerType);
0501:
0502: boolean headerRefFlagSpecified = (headerReqFlag != null && headerReqFlag
0503: .length() > 0);
0504: if (headerTypeId < 0 && !headerRefFlagSpecified) {
0505: log
0506: .error("HeaderAggregatorImpl.registerAndOrderNamedHeaderResource() ignoring specification of unknown header section type; header-section-name="
0507: + headerName
0508: + " header-section-type="
0509: + headerType);
0510: }
0511:
0512: if ((headerTypeId >= 0) || headerRefFlagSpecified) {
0513: Map headerTypes = (Map) headerDynamicConfigurationDefault
0514: .get(HeaderResource.HEADER_CONFIG_TYPES);
0515: if (headerTypes == null) {
0516: headerTypes = new HashMap();
0517: headerDynamicConfigurationDefault.put(
0518: HeaderResource.HEADER_CONFIG_TYPES,
0519: headerTypes);
0520: }
0521:
0522: Object[] headerTypePair = (Object[]) headerTypes
0523: .get(headerName);
0524: if (headerTypePair == null) {
0525: headerTypePair = new Object[] { null, null };
0526: headerTypes.put(headerName, headerTypePair);
0527: }
0528: if (headerTypePair[0] == null && headerTypeId >= 0) { // change only if value from configuration is null
0529: headerTypePair[0] = new Integer(headerTypeId);
0530: }
0531: if (headerTypePair[1] == null && headerReqFlag != null
0532: && headerReqFlag.length() > 0) { // change only if value from configuration is null
0533: headerTypePair[1] = headerReqFlag;
0534: }
0535: }
0536: }
0537: }
0538:
0539: protected boolean canAddHeaderNamedResourceFragment(
0540: String headerFragmentName,
0541: HashMap namedResourcesAddedFragmentsDefault,
0542: String[] registryContent) {
0543: if (headerFragmentName != null
0544: && !namedResourcesAddedFragmentsDefault
0545: .containsKey(headerFragmentName)) {
0546: namedResourcesAddedFragmentsDefault.put(headerFragmentName,
0547: Boolean.TRUE);
0548: if (registryContent != null) {
0549: String registryContentVal = (String) this .headerResourceRegistry
0550: .get(headerFragmentName);
0551: registryContent[0] = registryContentVal;
0552: if (registryContentVal != null) {
0553: this .headerResourceRegistry
0554: .remove(headerFragmentName);
0555: }
0556: }
0557: return true;
0558: }
0559: if (registryContent != null) {
0560: registryContent[0] = null;
0561: }
0562: return false;
0563: }
0564:
0565: protected void initializeDesktopHeaderConfigurationDefaults(
0566: Map desktopConfigMap, HashMap namedResourcesDefault,
0567: HashMap namedResourcesAddedFragmentsDefault,
0568: HashMap headerDynamicConfigurationDefault) {
0569: if (desktopConfigMap == null) {
0570: desktopConfigMap = new HashMap();
0571: }
0572:
0573: StringBuffer desktopDojoConfigContent = new StringBuffer();
0574:
0575: String layoutDecorationDefaultName = HeaderResource.HEADER_CONFIG_DESKTOP_LAYOUT_DECORATION_DEFAULT;
0576: String layoutDecoration = (String) desktopConfigMap
0577: .get(layoutDecorationDefaultName);
0578: if (layoutDecoration != null && layoutDecoration.length() > 0) {
0579: decorationFactory
0580: .setDefaultDesktopLayoutDecoration(layoutDecoration);
0581: }
0582:
0583: String portletDecorationDefaultName = HeaderResource.HEADER_CONFIG_DESKTOP_PORTLET_DECORATION_DEFAULT;
0584: String portletDecoration = (String) desktopConfigMap
0585: .get(portletDecorationDefaultName);
0586: if (portletDecoration == null
0587: || portletDecoration.length() == 0) {
0588: portletDecoration = decorationFactory
0589: .getDefaultDesktopPortletDecoration();
0590: }
0591: if (portletDecoration != null && portletDecoration.length() > 0) {
0592: if (canAddHeaderNamedResourceFragment(
0593: portletDecorationDefaultName,
0594: namedResourcesAddedFragmentsDefault, null)) {
0595: desktopDojoConfigContent
0596: .append(" ")
0597: .append(
0598: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0599: .append(".windowDecoration = \"").append(
0600: portletDecoration).append("\";")
0601: .append(EOL);
0602: }
0603: decorationFactory
0604: .setDefaultDesktopPortletDecoration(portletDecoration);
0605: }
0606:
0607: String desktopPageAjaxNavName = HeaderResource.HEADER_CONFIG_DESKTOP_PAGE_AJAXNAVIGATION;
0608: String desktopPageAjaxNav = HeaderResourceLib
0609: .makeJSONBoolean(desktopConfigMap
0610: .get(desktopPageAjaxNavName));
0611: if (desktopPageAjaxNav != null
0612: && canAddHeaderNamedResourceFragment(
0613: desktopPageAjaxNavName,
0614: namedResourcesAddedFragmentsDefault, null)) {
0615: desktopDojoConfigContent
0616: .append(" ")
0617: .append(
0618: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0619: .append(".ajaxPageNavigation = ").append(
0620: desktopPageAjaxNav).append(";").append(EOL);
0621: }
0622:
0623: String desktopWindowTilingName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_TILING;
0624: String desktopWindowTiling = HeaderResourceLib
0625: .makeJSONBoolean(desktopConfigMap
0626: .get(desktopWindowTilingName));
0627: if (desktopWindowTiling != null
0628: && canAddHeaderNamedResourceFragment(
0629: desktopWindowTilingName,
0630: namedResourcesAddedFragmentsDefault, null)) {
0631: desktopDojoConfigContent
0632: .append(" ")
0633: .append(
0634: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0635: .append(".windowTiling = ").append(
0636: desktopWindowTiling).append(";")
0637: .append(EOL);
0638: }
0639:
0640: String desktopWindowHeightExpandName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_HEIGHT_EXPAND;
0641: String desktopWindowHeightExpand = HeaderResourceLib
0642: .makeJSONBoolean(desktopConfigMap
0643: .get(desktopWindowHeightExpandName));
0644: if (desktopWindowHeightExpand != null
0645: && canAddHeaderNamedResourceFragment(
0646: desktopWindowHeightExpandName,
0647: namedResourcesAddedFragmentsDefault, null)) {
0648: desktopDojoConfigContent
0649: .append(" ")
0650: .append(
0651: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0652: .append(".windowHeightExpand = ").append(
0653: desktopWindowHeightExpand).append(";")
0654: .append(EOL);
0655: }
0656:
0657: String desktopWindowHeightName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_HEIGHT;
0658: String desktopWindowHeight = HeaderResourceLib.makeJSONInteger(
0659: desktopConfigMap.get(desktopWindowHeightName), true);
0660: if (desktopWindowHeight != null
0661: && canAddHeaderNamedResourceFragment(
0662: desktopWindowHeightName,
0663: namedResourcesAddedFragmentsDefault, null)) {
0664: desktopDojoConfigContent
0665: .append(" ")
0666: .append(
0667: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0668: .append(".windowHeight = ").append(
0669: desktopWindowHeight).append(";")
0670: .append(EOL);
0671: }
0672:
0673: String desktopWindowWidthName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_WIDTH;
0674: String desktopWindowWidth = HeaderResourceLib.makeJSONInteger(
0675: desktopConfigMap.get(desktopWindowWidthName), true);
0676: if (desktopWindowWidth != null
0677: && canAddHeaderNamedResourceFragment(
0678: desktopWindowWidthName,
0679: namedResourcesAddedFragmentsDefault, null)) {
0680: desktopDojoConfigContent
0681: .append(" ")
0682: .append(
0683: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0684: .append(".windowWidth = ").append(
0685: desktopWindowWidth).append(";").append(EOL);
0686: }
0687:
0688: List actionList = new ArrayList();
0689:
0690: String windowActionButtonOrderName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_ORDER;
0691: String actionButtonOrderContent = HeaderResourceLib
0692: .makeJSONStringArray((List) desktopConfigMap
0693: .get(windowActionButtonOrderName), actionList);
0694: if (actionButtonOrderContent != null
0695: && actionButtonOrderContent.length() > 0) {
0696: if (canAddHeaderNamedResourceFragment(
0697: windowActionButtonOrderName,
0698: namedResourcesAddedFragmentsDefault, null)) {
0699: desktopDojoConfigContent
0700: .append(" ")
0701: .append(
0702: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0703: .append(
0704: HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_ORDER)
0705: .append(" = ").append(actionButtonOrderContent)
0706: .append(";").append(EOL);
0707: }
0708: }
0709:
0710: String windowActionNoImageName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_NOIMAGE;
0711: String actionNoImageContent = HeaderResourceLib
0712: .makeJSONStringArray((List) desktopConfigMap
0713: .get(windowActionNoImageName), actionList);
0714: if (actionNoImageContent != null
0715: && actionNoImageContent.length() > 0) {
0716: if (canAddHeaderNamedResourceFragment(
0717: windowActionNoImageName,
0718: namedResourcesAddedFragmentsDefault, null)) {
0719: desktopDojoConfigContent
0720: .append(" ")
0721: .append(
0722: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0723: .append(
0724: HeaderResource.DESKTOP_JSON_WINDOW_ACTION_NOIMAGE)
0725: .append(" = ").append(actionNoImageContent)
0726: .append(";").append(EOL);
0727: }
0728: }
0729:
0730: String windowActionMenuOrderName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_MENU_ORDER;
0731: String actionMenuOrderContent = HeaderResourceLib
0732: .makeJSONStringArray((List) desktopConfigMap
0733: .get(windowActionMenuOrderName), actionList);
0734: if (actionMenuOrderContent != null
0735: && actionMenuOrderContent.length() > 0) {
0736: if (canAddHeaderNamedResourceFragment(
0737: windowActionMenuOrderName,
0738: namedResourcesAddedFragmentsDefault, null)) {
0739: desktopDojoConfigContent
0740: .append(" ")
0741: .append(
0742: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0743: .append(
0744: HeaderResource.DESKTOP_JSON_WINDOW_ACTION_MENU_ORDER)
0745: .append(" = ").append(actionMenuOrderContent)
0746: .append(";").append(EOL);
0747: }
0748: }
0749:
0750: headerDynamicConfigurationDefault
0751: .put(
0752: HeaderResource.HEADER_INTERNAL_CONFIG_DESKTOP_WINDOW_ACTION,
0753: actionList);
0754:
0755: String windowActionButtonTooltipName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_TOOLTIP;
0756: String windowActionButtonTooltip = HeaderResourceLib
0757: .makeJSONBoolean(desktopConfigMap
0758: .get(windowActionButtonTooltipName));
0759: if (windowActionButtonTooltip != null
0760: && canAddHeaderNamedResourceFragment(
0761: windowActionButtonTooltipName,
0762: namedResourcesAddedFragmentsDefault, null)) {
0763: desktopDojoConfigContent
0764: .append(" ")
0765: .append(
0766: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0767: .append(
0768: HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_TOOLTIP)
0769: .append(" = ").append(windowActionButtonTooltip)
0770: .append(";").append(EOL);
0771: }
0772:
0773: String windowActionButtonMaxName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_MAX;
0774: String windowActionButtonMax = HeaderResourceLib
0775: .makeJSONInteger(desktopConfigMap
0776: .get(windowActionButtonMaxName), false);
0777: if (windowActionButtonMax != null
0778: && canAddHeaderNamedResourceFragment(
0779: windowActionButtonMaxName,
0780: namedResourcesAddedFragmentsDefault, null)) {
0781: desktopDojoConfigContent
0782: .append(" ")
0783: .append(
0784: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0785: .append(
0786: HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_MAX)
0787: .append(" = ").append(windowActionButtonMax)
0788: .append(";").append(EOL);
0789: }
0790:
0791: String windowIconEnabledName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_ENABLED;
0792: String iconEnabledContent = HeaderResourceLib
0793: .makeJSONBoolean(desktopConfigMap
0794: .get(windowIconEnabledName));
0795: if (iconEnabledContent != null
0796: && iconEnabledContent.length() > 0) {
0797: if (canAddHeaderNamedResourceFragment(
0798: windowIconEnabledName,
0799: namedResourcesAddedFragmentsDefault, null)) {
0800: desktopDojoConfigContent
0801: .append(" ")
0802: .append(
0803: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0804: .append(
0805: HeaderResource.DESKTOP_JSON_WINDOW_ICON_ENABLED)
0806: .append(" = ").append(iconEnabledContent)
0807: .append(";").append(EOL);
0808: }
0809: }
0810:
0811: String windowIconPathName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_PATH;
0812: String iconPathContent = (String) desktopConfigMap
0813: .get(windowIconPathName);
0814: if (iconPathContent != null && iconPathContent.length() > 0) {
0815: if (canAddHeaderNamedResourceFragment(windowIconPathName,
0816: namedResourcesAddedFragmentsDefault, null)) {
0817: desktopDojoConfigContent
0818: .append(" ")
0819: .append(
0820: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0821: .append(
0822: HeaderResource.DESKTOP_JSON_WINDOW_ICON_PATH)
0823: .append(" = \"").append(iconPathContent)
0824: .append("\";").append(EOL);
0825: }
0826: }
0827:
0828: String windowTitlebarEnabledName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_TITLEBAR_ENABLED;
0829: String titlebarEnabledContent = HeaderResourceLib
0830: .makeJSONBoolean(desktopConfigMap
0831: .get(windowTitlebarEnabledName));
0832: if (titlebarEnabledContent != null
0833: && titlebarEnabledContent.length() > 0) {
0834: if (canAddHeaderNamedResourceFragment(
0835: windowTitlebarEnabledName,
0836: namedResourcesAddedFragmentsDefault, null)) {
0837: desktopDojoConfigContent
0838: .append(" ")
0839: .append(
0840: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0841: .append(
0842: HeaderResource.DESKTOP_JSON_WINDOW_TITLEBAR_ENABLED)
0843: .append(" = ").append(titlebarEnabledContent)
0844: .append(";").append(EOL);
0845: }
0846: }
0847:
0848: String windowResizebarEnabledName = HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_RESIZEBAR_ENABLED;
0849: String resizebarEnabledContent = HeaderResourceLib
0850: .makeJSONBoolean(desktopConfigMap
0851: .get(windowResizebarEnabledName));
0852: if (resizebarEnabledContent != null
0853: && resizebarEnabledContent.length() > 0) {
0854: if (canAddHeaderNamedResourceFragment(
0855: windowResizebarEnabledName,
0856: namedResourcesAddedFragmentsDefault, null)) {
0857: desktopDojoConfigContent
0858: .append(" ")
0859: .append(
0860: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME_SCOPE)
0861: .append(
0862: HeaderResource.DESKTOP_JSON_WINDOW_TITLEBAR_ENABLED)
0863: .append(" = ").append(resizebarEnabledContent)
0864: .append(";").append(EOL);
0865: }
0866: }
0867:
0868: String pageActionButtonTooltipName = HeaderResource.HEADER_CONFIG_DESKTOP_PAGE_ACTION_BUTTON_TOOLTIP;
0869: String pageActionButtonTooltip = HeaderResourceLib
0870: .makeJSONBoolean(desktopConfigMap
0871: .get(pageActionButtonTooltipName));
0872: if (pageActionButtonTooltip != null
0873: && canAddHeaderNamedResourceFragment(
0874: pageActionButtonTooltipName,
0875: namedResourcesAddedFragmentsDefault, null)) {
0876: desktopDojoConfigContent
0877: .append(" ")
0878: .append(
0879: HeaderResource.HEADER_INTERNAL_DOJO_CONFIG_JETSPEED_VAR_NAME)
0880: .append(".pageActionButtonTooltip = ").append(
0881: pageActionButtonTooltip).append(";")
0882: .append(EOL);
0883: }
0884:
0885: if (desktopDojoConfigContent.length() > 0) {
0886: namedResourcesDefault.put(
0887: HeaderResource.HEADER_SECTION_DOJO_CONFIG,
0888: desktopDojoConfigContent.toString());
0889: }
0890:
0891: StringBuffer desktopInitScript = new StringBuffer();
0892: desktopInitScript
0893: .append(" function doRender(bindArgs,portletEntityId) { ");
0894: desktopInitScript.append(
0895: "jetspeed.doRender(bindArgs,portletEntityId); }")
0896: .append(EOL);
0897: desktopInitScript
0898: .append(" function doAction(bindArgs,portletEntityId) { ");
0899: desktopInitScript.append(
0900: "jetspeed.doAction(bindArgs,portletEntityId); }")
0901: .append(EOL);
0902: desktopInitScript.append(
0903: " dojo.addOnLoad( jetspeed.initializeDesktop );")
0904: .append(EOL);
0905: if (canAddHeaderNamedResourceFragment("desktop.init",
0906: namedResourcesAddedFragmentsDefault, null)) {
0907: namedResourcesDefault.put(
0908: HeaderResource.HEADER_SECTION_DESKTOP_INIT,
0909: desktopInitScript.toString());
0910: setNamedHeaderResourceProperties(
0911: HeaderResource.HEADER_SECTION_DESKTOP_INIT,
0912: HeaderResource.HEADER_TYPE_SCRIPT_BLOCK_START,
0913: null, headerDynamicConfigurationDefault);
0914: }
0915: }
0916:
0917: /**
0918: * Read dojo header configuration settings and compile dojo header resource defaults
0919: */
0920: protected void initializeDojoHeaderConfigurationDefaults(
0921: Map dojoConfigMap, HashMap namedResourcesDefault,
0922: HashMap namedResourcesAddedFragmentsDefault,
0923: HashMap headerDynamicConfigurationDefault) {
0924: if (dojoConfigMap == null) {
0925: dojoConfigMap = new HashMap();
0926: }
0927: String[] registryContent = new String[] { null };
0928:
0929: // add dojo.enable and dojo.path to dynamic configuration
0930: String dojoEnableName = HeaderResource.HEADER_CONFIG_DOJO_ENABLE;
0931: Object dojoEnableObj = dojoConfigMap.get(dojoEnableName);
0932: String dojoEnable = ((dojoEnableObj == null) ? (String) null
0933: : dojoEnableObj.toString());
0934: if (dojoEnable == null || !dojoEnable.equals("true")) {
0935: dojoEnable = "false";
0936: }
0937: headerDynamicConfigurationDefault.put(dojoEnableName,
0938: dojoEnable);
0939: String dojoPath = (String) dojoConfigMap
0940: .get(HeaderResource.HEADER_CONFIG_DOJO_PATH);
0941: if (dojoPath == null || dojoPath.length() == 0) {
0942: dojoPath = "/javascript/dojo/";
0943: }
0944: headerDynamicConfigurationDefault.put(
0945: HeaderResource.HEADER_CONFIG_DOJO_PATH, dojoPath);
0946:
0947: // dojo parameters - djConfig parameters
0948: boolean dojoDebugEnabled = false;
0949: String dojoParamDebug = (String) dojoConfigMap
0950: .get(HeaderResource.HEADER_CONFIG_DOJO_PARAM_ISDEBUG);
0951: String dojoParamDebugAtAllCosts = null;
0952: if (dojoParamDebug != null)
0953: dojoParamDebug = dojoParamDebug.toLowerCase();
0954: if (dojoParamDebug == null || dojoParamDebug.length() == 0
0955: || dojoParamDebug.equals("false")) {
0956: dojoParamDebug = null;
0957: } else if (dojoParamDebug.equals("true")) {
0958: dojoDebugEnabled = true;
0959: dojoParamDebugAtAllCosts = (String) dojoConfigMap
0960: .get(HeaderResource.HEADER_CONFIG_DOJO_PARAM_DEBUGALLCOSTS);
0961: if (dojoParamDebugAtAllCosts != null) {
0962: dojoParamDebugAtAllCosts = dojoParamDebugAtAllCosts
0963: .toLowerCase();
0964: if (!dojoParamDebugAtAllCosts.equals("true")) {
0965: dojoParamDebugAtAllCosts = null;
0966: }
0967: }
0968: }
0969:
0970: String dojoParamPreventBackBtnFix = (String) dojoConfigMap
0971: .get(HeaderResource.HEADER_CONFIG_DOJO_PARAM_PREVENT_BACKBUTTON_FIX);
0972: String dojoParams = (String) dojoConfigMap
0973: .get(HeaderResource.HEADER_CONFIG_DOJO_PARAMS);
0974: if (dojoParamDebug != null || dojoParamDebugAtAllCosts != null
0975: || dojoParamPreventBackBtnFix != null
0976: || dojoParams != null) {
0977: StringBuffer dojoConfigContent = new StringBuffer();
0978: boolean addedMembers = false;
0979: if (dojoParams != null && dojoParams.length() > 0) {
0980: dojoConfigContent.append(dojoParams);
0981: addedMembers = true;
0982: }
0983: if (dojoParamDebug != null && dojoParamDebug.length() > 0) {
0984: if (addedMembers) {
0985: dojoConfigContent.append(", ");
0986: }
0987: dojoConfigContent.append("isDebug: ").append(
0988: dojoParamDebug);
0989: addedMembers = true;
0990: }
0991: if (dojoParamDebugAtAllCosts != null
0992: && dojoParamDebugAtAllCosts.length() > 0) {
0993: if (addedMembers) {
0994: dojoConfigContent.append(", ");
0995: }
0996: dojoConfigContent.append("debugAtAllCosts: ").append(
0997: dojoParamDebugAtAllCosts);
0998: addedMembers = true;
0999: }
1000: if (dojoParamPreventBackBtnFix != null
1001: && dojoParamPreventBackBtnFix.length() > 0) {
1002: if (addedMembers) {
1003: dojoConfigContent.append(", ");
1004: }
1005: dojoConfigContent.append("preventBackButtonFix: ")
1006: .append(dojoParamPreventBackBtnFix);
1007: addedMembers = true;
1008: }
1009: if (addedMembers) {
1010: dojoConfigContent.append(", ");
1011: }
1012: dojoConfigContent.append(
1013: HeaderResource.HEADER_INTERNAL_JETSPEED_VAR_NAME)
1014: .append(": {}");
1015: addedMembers = true;
1016:
1017: if (canAddHeaderNamedResourceFragment(
1018: HeaderResource.HEADER_CONFIG_DOJO_PARAMS,
1019: namedResourcesAddedFragmentsDefault,
1020: registryContent)) {
1021: String dojoParamContent = dojoConfigContent.toString();
1022: if (registryContent[0] != null) {
1023: dojoParamContent = registryContent[0];
1024: }
1025: if (dojoParamContent.length() > 0) {
1026: namedResourcesDefault
1027: .put(
1028: HeaderResource.HEADER_SECTION_DOJO_PARAMETERS,
1029: (" var djConfig = {"
1030: + dojoParamContent + "};" + EOL));
1031: }
1032: }
1033: registerAndOrderNamedHeaderResource(
1034: HeaderResource.HEADER_SECTION_DOJO_PARAMETERS,
1035: HeaderResource.HEADER_TYPE_SCRIPT_BLOCK_START,
1036: dojoEnableName, headerDynamicConfigurationDefault);
1037: }
1038:
1039: // dojo preinit - for automatically added members to djConfig (eg. djConfig.baseScriptUri="...")
1040: // - adding to order only at this point
1041: // - if header contains content, generated content will not be added
1042: registerAndOrderNamedHeaderResource(
1043: HeaderResource.HEADER_SECTION_DOJO_PREINIT, null,
1044: dojoEnableName, headerDynamicConfigurationDefault);
1045:
1046: // dojo config - for adding members to djConfig (eg. djConfig.parseWidgets=false)
1047: // - adding to order only at this point
1048: registerAndOrderNamedHeaderResource(
1049: HeaderResource.HEADER_SECTION_DOJO_CONFIG, null,
1050: dojoEnableName, headerDynamicConfigurationDefault);
1051:
1052: // dojo init - script tag for dojo.js
1053: // - adding to order only at this point
1054: // - if header contains content, generated content will not be added
1055: registerAndOrderNamedHeaderResource(
1056: HeaderResource.HEADER_SECTION_DOJO_INIT,
1057: HeaderResource.HEADER_TYPE_SCRIPT_TAG, dojoEnableName,
1058: headerDynamicConfigurationDefault);
1059:
1060: // dojo requires - core libraries
1061: List dojoRequiresCore = (List) dojoConfigMap
1062: .get(HeaderResource.HEADER_CONFIG_DOJO_REQUIRES_CORE);
1063: if (dojoRequiresCore != null && dojoRequiresCore.size() > 0) {
1064: StringBuffer dojoRequiresContent = new StringBuffer();
1065: Iterator dojoRequiresCoreIter = dojoRequiresCore.iterator();
1066: while (dojoRequiresCoreIter.hasNext()) {
1067: String dojoReq = (String) dojoRequiresCoreIter.next();
1068: if (dojoReq != null && dojoReq.length() > 0) {
1069: if (canAddHeaderNamedResourceFragment(dojoReq,
1070: namedResourcesAddedFragmentsDefault,
1071: registryContent)) {
1072: if (registryContent[0] != null) {
1073: String dojoReqFromRegistry = HeaderResourceLib
1074: .makeJavascriptStatement(
1075: registryContent[0], " ",
1076: true);
1077: if (dojoReqFromRegistry.length() > 0) {
1078: dojoRequiresContent
1079: .append(registryContent[0]);
1080: }
1081: } else {
1082: dojoRequiresContent.append(
1083: " dojo.require(\"").append(
1084: dojoReq).append("\");").append(EOL);
1085: }
1086: }
1087: }
1088: }
1089: namedResourcesDefault.put(
1090: HeaderResource.HEADER_SECTION_DOJO_REQUIRES_CORE,
1091: dojoRequiresContent.toString());
1092: registerAndOrderNamedHeaderResource(
1093: HeaderResource.HEADER_SECTION_DOJO_REQUIRES_CORE,
1094: null, dojoEnableName,
1095: headerDynamicConfigurationDefault);
1096: }
1097:
1098: // dojo modules path definition
1099: List dojoModulesPath = (List) dojoConfigMap
1100: .get(HeaderResource.HEADER_CONFIG_DOJO_MODULES_PATH);
1101: if (dojoModulesPath != null && dojoModulesPath.size() > 0) {
1102: StringBuffer dojoModulesPathContent = new StringBuffer();
1103: boolean addedContent = false;
1104: Iterator dojoModulesPathIter = dojoModulesPath.iterator();
1105: while (dojoModulesPathIter.hasNext()) {
1106: String dojoModule = (String) dojoModulesPathIter.next();
1107: if (dojoModule != null && dojoModule.length() > 0) {
1108: if (canAddHeaderNamedResourceFragment(dojoModule,
1109: namedResourcesAddedFragmentsDefault,
1110: registryContent)) {
1111: String dojoModuleContent = null;
1112: if (registryContent[0] != null) {
1113: dojoModuleContent = registryContent[0];
1114: } else {
1115: dojoModuleContent = dojoModule;
1116: }
1117: dojoModuleContent = HeaderResourceLib
1118: .makeJavascriptStatement(
1119: dojoModuleContent, " ", true);
1120: if (dojoModuleContent.length() > 0) {
1121: dojoModulesPathContent
1122: .append(dojoModuleContent);
1123: addedContent = true;
1124: }
1125: }
1126: }
1127: }
1128: if (addedContent) {
1129: namedResourcesDefault
1130: .put(
1131: HeaderResource.HEADER_SECTION_DOJO_MODULES_PATH,
1132: dojoModulesPathContent.toString());
1133: registerAndOrderNamedHeaderResource(
1134: HeaderResource.HEADER_SECTION_DOJO_MODULES_PATH,
1135: null, dojoEnableName,
1136: headerDynamicConfigurationDefault);
1137: }
1138: }
1139:
1140: // dojo modules namespace definition
1141: List dojoModulesNamespace = (List) dojoConfigMap
1142: .get(HeaderResource.HEADER_CONFIG_DOJO_MODULES_NAMESPACE);
1143: if (dojoModulesNamespace != null
1144: && dojoModulesNamespace.size() > 0) {
1145: StringBuffer dojoModulesNamespaceContent = new StringBuffer();
1146: boolean addedContent = false;
1147: Iterator dojoModulesNamespaceIter = dojoModulesNamespace
1148: .iterator();
1149: while (dojoModulesNamespaceIter.hasNext()) {
1150: String dojoModuleWidget = (String) dojoModulesNamespaceIter
1151: .next();
1152: if (dojoModuleWidget != null
1153: && dojoModuleWidget.length() > 0) {
1154: if (canAddHeaderNamedResourceFragment(
1155: dojoModuleWidget,
1156: namedResourcesAddedFragmentsDefault,
1157: registryContent)) {
1158: String dojoModuleContent = null;
1159: if (registryContent[0] != null) {
1160: dojoModuleContent = registryContent[0];
1161: } else {
1162: dojoModuleContent = dojoModuleWidget;
1163: }
1164: dojoModuleContent = HeaderResourceLib
1165: .makeJavascriptStatement(
1166: dojoModuleContent, " ", true);
1167: if (dojoModuleContent.length() > 0) {
1168: dojoModulesNamespaceContent
1169: .append(dojoModuleContent);
1170: addedContent = true;
1171: }
1172: }
1173: }
1174: }
1175: if (addedContent) {
1176: namedResourcesDefault
1177: .put(
1178: HeaderResource.HEADER_SECTION_DOJO_MODULES_NAMESPACE,
1179: dojoModulesNamespaceContent.toString());
1180: // registerAndOrderNamedHeaderResource called below
1181: }
1182: }
1183:
1184: // dojo requires - module libraries (from add-on modules)
1185: List dojoRequiresModules = (List) dojoConfigMap
1186: .get(HeaderResource.HEADER_CONFIG_DOJO_REQUIRES_MODULES);
1187: if (dojoRequiresModules != null
1188: && dojoRequiresModules.size() > 0) {
1189: HashMap addedReqs = null;
1190: if (dojoDebugEnabled)
1191: addedReqs = new HashMap();
1192: StringBuffer dojoRequiresContent = new StringBuffer();
1193: Iterator dojoRequiresModulesIter = dojoRequiresModules
1194: .iterator();
1195: while (dojoRequiresModulesIter.hasNext()) {
1196: String dojoReq = (String) dojoRequiresModulesIter
1197: .next();
1198: if (dojoReq != null && dojoReq.length() > 0) {
1199: if (canAddHeaderNamedResourceFragment(dojoReq,
1200: namedResourcesAddedFragmentsDefault,
1201: registryContent)) {
1202: if (registryContent[0] != null) {
1203: String dojoReqFromRegistry = HeaderResourceLib
1204: .makeJavascriptStatement(
1205: registryContent[0], " ",
1206: true);
1207: if (dojoReqFromRegistry.length() > 0) {
1208: dojoRequiresContent
1209: .append(registryContent[0]);
1210: }
1211: } else {
1212: dojoRequiresContent.append(
1213: " dojo.require(\"").append(
1214: dojoReq).append("\");").append(EOL);
1215: if (dojoDebugEnabled)
1216: addedReqs.put(dojoReq, dojoReq);
1217: }
1218: }
1219: }
1220: }
1221: if (dojoDebugEnabled) {
1222: if (addedReqs.get(HeaderResource.HEADER_DEBUG_REQUIRES) == null) {
1223: dojoRequiresContent
1224: .append(" dojo.require(\"")
1225: .append(
1226: HeaderResource.HEADER_DEBUG_REQUIRES)
1227: .append("\");").append(EOL);
1228: }
1229: }
1230: namedResourcesDefault
1231: .put(
1232: HeaderResource.HEADER_SECTION_DOJO_REQUIRES_MODULES,
1233: dojoRequiresContent.toString());
1234: registerAndOrderNamedHeaderResource(
1235: HeaderResource.HEADER_SECTION_DOJO_REQUIRES_MODULES,
1236: null, dojoEnableName,
1237: headerDynamicConfigurationDefault);
1238: }
1239:
1240: // dojo writeincludes
1241: // - adding to order only at this point
1242: // - if header contains content, generated content will not be added
1243: registerAndOrderNamedHeaderResource(
1244: HeaderResource.HEADER_SECTION_DOJO_WRITEINCLUDES,
1245: HeaderResource.HEADER_TYPE_SCRIPT_BLOCK_START,
1246: dojoEnableName, headerDynamicConfigurationDefault);
1247:
1248: // dojo widget module - register widget packages (eg. dojo.widget.manager.registerWidgetPackage('jetspeed.ui.widget'))
1249: // - default resource added above
1250: registerAndOrderNamedHeaderResource(
1251: HeaderResource.HEADER_SECTION_DOJO_MODULES_NAMESPACE,
1252: HeaderResource.HEADER_TYPE_SCRIPT_BLOCK_START,
1253: dojoEnableName, headerDynamicConfigurationDefault);
1254:
1255: // dojo style bodyexpand
1256: setNamedHeaderResourceProperties(
1257: HeaderResource.HEADER_SECTION_DOJO_STYLE_BODYEXPAND,
1258: HeaderResource.HEADER_TYPE_STYLE_BLOCK, dojoEnableName,
1259: headerDynamicConfigurationDefault);
1260:
1261: // dojo style bodyexpand noscroll
1262: setNamedHeaderResourceProperties(
1263: HeaderResource.HEADER_SECTION_DOJO_STYLE_BODYEXPAND_NOSCROLL,
1264: HeaderResource.HEADER_TYPE_STYLE_BLOCK, dojoEnableName,
1265: headerDynamicConfigurationDefault);
1266: }
1267:
1268: /**
1269: * Builds the portlet set defined in the context into a portlet tree.
1270: *
1271: * @return Unique Portlet Entity ID
1272: */
1273: public void build(RequestContext context) throws JetspeedException,
1274: IOException {
1275: ContentPage page = context.getPage();
1276: if (null == page) {
1277: throw new JetspeedException(
1278: "Failed to find PSML Pin ContentPageAggregator.build");
1279: }
1280:
1281: ContentFragment root = page.getRootContentFragment();
1282:
1283: if (root == null) {
1284: throw new JetspeedException(
1285: "No root ContentFragment found in ContentPage");
1286: }
1287:
1288: // add named-resources and named-resources-added maps as request attributes
1289: Map dynamicConfigDefault = getHeaderDynamicConfigurationDefault();
1290: Map namedResourcesDefault = getHeaderNamedResourcesDefault();
1291: Map namedResourcesAddedFragmentsDefault = getHeaderNamedResourcesAddedFragmentsDefault();
1292:
1293: /*if ( log.isDebugEnabled() && namedResourcesDefault != null )
1294: {
1295: Iterator namedResourcesDefaultIter = namedResourcesDefault.entrySet().iterator();
1296: while ( namedResourcesDefaultIter.hasNext() )
1297: {
1298: Map.Entry rsrcEntry = (Map.Entry)namedResourcesDefaultIter.next();
1299: Object rsrcVal = rsrcEntry.getValue();
1300: log.debug( rsrcEntry.getKey().toString() + ": " + EOL + ( rsrcVal != null ? rsrcVal.toString() : "null" ) );
1301: }
1302: }*/
1303:
1304: if (dynamicConfigDefault != null
1305: || namedResourcesDefault != null
1306: || namedResourcesAddedFragmentsDefault != null) {
1307: Map existingNamedResources = (Map) context
1308: .getAttribute(PortalReservedParameters.HEADER_NAMED_RESOURCE_ATTRIBUTE);
1309: if (existingNamedResources == null) {
1310: if (dynamicConfigDefault == null) {
1311: context
1312: .setAttribute(
1313: PortalReservedParameters.HEADER_CONFIGURATION_ATTRIBUTE,
1314: new HashMap());
1315: } else {
1316: HashMap dynamicConfig = new HashMap();
1317: Iterator hConfigEntryIter = dynamicConfigDefault
1318: .entrySet().iterator();
1319: while (hConfigEntryIter.hasNext()) {
1320: Map.Entry hConfigEntry = (Map.Entry) hConfigEntryIter
1321: .next();
1322: Object hConfigKey = hConfigEntry.getKey();
1323: Object hConfigVal = hConfigEntry.getValue();
1324: if (hConfigVal instanceof Map) {
1325: dynamicConfig.put(hConfigKey, new HashMap(
1326: (Map) hConfigVal));
1327: } else if (hConfigVal instanceof List) {
1328: dynamicConfig.put(hConfigKey,
1329: new ArrayList((List) hConfigVal));
1330: } else {
1331: dynamicConfig.put(hConfigKey, hConfigVal);
1332: }
1333: }
1334: context
1335: .setAttribute(
1336: PortalReservedParameters.HEADER_CONFIGURATION_ATTRIBUTE,
1337: dynamicConfig);
1338: }
1339:
1340: if (namedResourcesDefault != null) {
1341: context
1342: .setAttribute(
1343: PortalReservedParameters.HEADER_NAMED_RESOURCE_ATTRIBUTE,
1344: new HashMap(namedResourcesDefault));
1345: }
1346: if (namedResourcesAddedFragmentsDefault != null) {
1347: context
1348: .setAttribute(
1349: PortalReservedParameters.HEADER_NAMED_RESOURCE_ADDED_FRAGMENTS_ATTRIBUTE,
1350: new HashMap(
1351: namedResourcesAddedFragmentsDefault));
1352: }
1353: }
1354: }
1355: if (getHeaderResourceRegistry() != null) {
1356: context
1357: .setAttribute(
1358: PortalReservedParameters.HEADER_NAMED_RESOURCE_REGISTRY_ATTRIBUTE,
1359: getHeaderResourceRegistry());
1360: }
1361:
1362: // handle maximized state
1363: boolean atLeastOneHasHeaderPhase = false;
1364: NavigationalState nav = context.getPortalURL()
1365: .getNavigationalState();
1366: PortletWindow window = nav.getMaximizedWindow();
1367: if (null != window) {
1368: ContentFragment maxedContentFragment = page
1369: .getContentFragmentById(window.getId().toString());
1370: if (maxedContentFragment != null) {
1371: atLeastOneHasHeaderPhase = renderHeaderFragment(
1372: context, maxedContentFragment);
1373: }
1374: } else {
1375: atLeastOneHasHeaderPhase = aggregateAndRender(root,
1376: context, page);
1377: }
1378:
1379: if (atLeastOneHasHeaderPhase) {
1380:
1381: }
1382: }
1383:
1384: protected boolean aggregateAndRender(ContentFragment fragment,
1385: RequestContext context, ContentPage page)
1386: throws FailedToRenderFragmentException {
1387: boolean atLeastOneHasHeaderPhase = false;
1388: boolean hasHeaderPhase = false;
1389: if (fragment.getContentFragments() != null
1390: && fragment.getContentFragments().size() > 0) {
1391: Iterator children = fragment.getContentFragments()
1392: .iterator();
1393: while (children.hasNext()) {
1394: ContentFragment child = (ContentFragment) children
1395: .next();
1396: if (!"hidden".equals(fragment.getState())) {
1397: hasHeaderPhase = aggregateAndRender(child, context,
1398: page);
1399: if (hasHeaderPhase) {
1400: atLeastOneHasHeaderPhase = true;
1401: }
1402: }
1403: }
1404: }
1405: hasHeaderPhase = renderHeaderFragment(context, fragment);
1406: if (hasHeaderPhase) {
1407: atLeastOneHasHeaderPhase = true;
1408: }
1409: return atLeastOneHasHeaderPhase;
1410: }
1411:
1412: protected boolean renderHeaderFragment(RequestContext context,
1413: ContentFragment fragment) {
1414: try {
1415: if (!fragment.getType().equals(ContentFragment.LAYOUT)) {
1416: PortletWindow portletWindow = getPortletWindowAccessor()
1417: .getPortletWindow(fragment);
1418: PortletDefinition pd = portletWindow.getPortletEntity()
1419: .getPortletDefinition();
1420: if (pd != null
1421: && getPortletFactory()
1422: .isPortletApplicationRegistered(
1423: (PortletApplication) pd
1424: .getPortletApplicationDefinition())) {
1425: String portletApplicationContextPath = pd
1426: .getPortletApplicationDefinition()
1427: .getWebApplicationDefinition()
1428: .getContextRoot();
1429: Portlet portlet = getPortletFactory()
1430: .getPortletInstance(
1431: context
1432: .getConfig()
1433: .getServletContext()
1434: .getContext(
1435: portletApplicationContextPath),
1436: pd).getRealPortlet();
1437: if (portlet != null
1438: && portlet instanceof SupportsHeaderPhase) {
1439: log.debug("renderHeaderFragment: "
1440: + pd.getName()
1441: + " supports header phase");
1442:
1443: HeaderResource hr = getHeaderResourceFactory()
1444: .getHeaderResource(context,
1445: this .baseUrlAccess,
1446: isDesktop(),
1447: getHeaderConfiguration());
1448: PortletHeaderRequest headerRequest = new PortletHeaderRequestImpl(
1449: context, portletWindow,
1450: portletApplicationContextPath);
1451: PortletHeaderResponse headerResponse = new PortletHeaderResponseImpl(
1452: context, hr, isDesktop(),
1453: getHeaderConfiguration(),
1454: getHeaderResourceRegistry());
1455: ((SupportsHeaderPhase) portlet).doHeader(
1456: headerRequest, headerResponse);
1457: return true;
1458: }
1459: }
1460: }
1461: return false;
1462: } catch (Exception e) {
1463: log.error("renderHeaderFragment failed", e);
1464: }
1465: return false;
1466: }
1467:
1468: protected PortletFactory getPortletFactory() {
1469: return this .factory;
1470: }
1471:
1472: protected PortletWindowAccessor getPortletWindowAccessor() {
1473: return this .windowAccessor;
1474: }
1475:
1476: protected HeaderResourceFactory getHeaderResourceFactory() {
1477: return this .headerResourceFactory;
1478: }
1479:
1480: protected boolean isDesktop() {
1481: return this .isDesktop;
1482: }
1483:
1484: protected Map getHeaderConfiguration() {
1485: return this .headerConfiguration;
1486: }
1487:
1488: protected Map getHeaderResourceRegistry() {
1489: return this .headerResourceRegistry;
1490: }
1491:
1492: protected Map getHeaderDynamicConfigurationDefault() {
1493: return this .headerDynamicConfigurationDefault;
1494: }
1495:
1496: protected Map getHeaderNamedResourcesDefault() {
1497: return this .headerNamedResourcesDefault;
1498: }
1499:
1500: protected Map getHeaderNamedResourcesAddedFragmentsDefault() {
1501: return this .headerNamedResourcesAddedFragmentsDefault;
1502: }
1503:
1504: protected BasePortalURL getBaseUrlAccess() {
1505: return this.baseUrlAccess;
1506: }
1507: }
|