From: Chris L. <chr...@jb...> - 2006-05-01 04:44:14
|
User: claprun Date: 06/05/01 00:44:09 Added: wsrp/src/main/org/jboss/portal/wsrp/consumer PortletInfo.java Log: Added PortletInfo that builds a PortletInfo object from a PortletDescription. To be used by WSRPConsumerImpl. Revision Changes Path 1.1 date: 2006/05/01 04:44:09; author: claprun; state: Exp;jboss-portal/wsrp/src/main/org/jboss/portal/wsrp/consumer/PortletInfo.java Index: PortletInfo.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.portal.wsrp.consumer; import org.jboss.portal.common.util.LocaleInfo; import org.jboss.portal.portlet.info.CacheInfo; import org.jboss.portal.portlet.info.CapabilitiesInfo; import org.jboss.portal.portlet.info.MetaInfo; import org.jboss.portal.portlet.info.PreferencesInfo; import org.jboss.portal.portlet.info.SecurityInfo; import org.jboss.portal.portlet.info.SessionInfo; import org.jboss.portal.portlet.info.TransactionInfo; import org.jboss.portal.wsrp.WSRPUtils; import org.jboss.portal.wsrp.core.LocalizedString; import org.jboss.portal.wsrp.core.MarkupType; import org.jboss.portal.wsrp.core.PortletDescription; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; /** * @author <a href="mailto:chr...@jb...">Chris Laprun</a> * @version $Revision: 1.1 $ * @since 2.4 (Apr 30, 2006) */ public class PortletInfo implements org.jboss.portal.portlet.info.PortletInfo { private CapabilitiesInfo capabilities; private MetaInfo metaInfo; public PortletInfo(final PortletDescription portletDescription) { if (portletDescription == null) { throw new IllegalArgumentException("PortletDescription cannot be null!"); } createCapabilitiesInfo(portletDescription); createMetaInfo(portletDescription); } public CapabilitiesInfo getCapabilities() { return capabilities; } public PreferencesInfo getPreferences() { throw new UnsupportedOperationException("getPreferences currently not supported!"); } public MetaInfo getMeta() { return metaInfo; } public SecurityInfo getSecurity() { throw new UnsupportedOperationException("getSecurity currently not supported!"); } public CacheInfo getCache() { throw new UnsupportedOperationException("getCache currently not supported!"); } public SessionInfo getSession() { return new SessionInfo() { public boolean isDistributed() { return false; } }; } public TransactionInfo getTransaction() { throw new UnsupportedOperationException("getTransaction currently not supported!"); } public boolean isRemote() { return true; } public Boolean isRemotable() { return Boolean.TRUE; } private void createCapabilitiesInfo(PortletDescription portletDescription) { final MarkupType[] markupTypes = portletDescription.getMarkupTypes(); final Map mimeTypes = new HashMap(markupTypes.length); final Set modes = new HashSet(); final Set windowStates = new HashSet(); final Set locales = new HashSet(); for (int i = 0; i < markupTypes.length; i++) { MarkupType markupType = markupTypes[i]; String mimeType = markupType.getMimeType(); MIMETypeInfo mimeTypeInfo = new MIMETypeInfo(markupType); mimeTypes.put(mimeType, mimeTypeInfo); modes.addAll(mimeTypeInfo.modes); windowStates.addAll(mimeTypeInfo.windowStates); locales.addAll(mimeTypeInfo.locales); } capabilities = new CapabilitiesInfo() { public Set getMimeTypes() { return mimeTypes.keySet(); } public Set getAllModes() { return modes; } public Set getModes(String mimeType) { MIMETypeInfo mimeTypeInfo = (MIMETypeInfo)mimeTypes.get(mimeType); if (mimeTypeInfo == null) { return Collections.EMPTY_SET; } return Collections.unmodifiableSet(mimeTypeInfo.modes); } public Set getAllWindowStates() { return windowStates; } public Set getWindowStates(String mimeType) { MIMETypeInfo mimeTypeInfo = (MIMETypeInfo)mimeTypes.get(mimeType); if (mimeTypeInfo == null) { return Collections.EMPTY_SET; } return Collections.unmodifiableSet(mimeTypeInfo.windowStates); } public Set getAllLocales() { return locales; } public Set getLocales(String mimeType) { MIMETypeInfo mimeTypeInfo = (MIMETypeInfo)mimeTypes.get(mimeType); if (mimeTypeInfo == null) { return Collections.EMPTY_SET; } return Collections.unmodifiableSet(mimeTypeInfo.locales); } }; } private void createMetaInfo(PortletDescription portletDescription) { final Map metaInfos = new HashMap(); metaInfos.put(MetaInfo.DESCRIPTION, createPortalLocalizedStringFrom(portletDescription.getDescription())); metaInfos.put(MetaInfo.DISPLAY_NAME, createPortalLocalizedStringFrom(portletDescription.getDisplayName())); metaInfos.put(MetaInfo.SHORT_TITLE, createPortalLocalizedStringFrom(portletDescription.getShortTitle())); metaInfos.put(MetaInfo.TITLE, createPortalLocalizedStringFrom(portletDescription.getTitle())); // keywords need to be concatenated LocalizedString[] keywords = portletDescription.getKeywords(); if (keywords != null) { int keywordsNb = keywords.length; if (keywordsNb > 0) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < keywordsNb; i++) { LocalizedString keyword = keywords[i]; sb.append(keyword.getValue()); if (i != keywords.length - 1) { sb.append(","); // not the last one, so concatenate a comma to separate } } // fix-me: for now assume that they all have the same language... this could get messy! metaInfos.put(MetaInfo.KEYWORDS, new org.jboss.portal.common.util.LocalizedString(sb.toString(), LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(keywords[0].getLang()).getLocale())); } } metaInfo = new MetaInfo() { public org.jboss.portal.common.util.LocalizedString getMetaValue(String key) { return (org.jboss.portal.common.util.LocalizedString)metaInfos.get(key); } }; } private org.jboss.portal.common.util.LocalizedString createPortalLocalizedStringFrom(LocalizedString wsrpLocalizedString) { if (wsrpLocalizedString == null) { return null; } return new org.jboss.portal.common.util.LocalizedString(wsrpLocalizedString.getValue(), LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(wsrpLocalizedString.getLang()).getLocale()); } class MIMETypeInfo { public MIMETypeInfo(MarkupType markupType) { mimeType = markupType.getMimeType(); String[] modeNames = markupType.getModes(); modes = new HashSet(modeNames.length); for (int i = 0; i < modeNames.length; i++) { modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(modeNames[i])); } String[] windStateNames = markupType.getWindowStates(); windowStates = new HashSet(windStateNames.length); for (int i = 0; i < windStateNames.length; i++) { windowStates.add(WSRPUtils.getJSR168WindowStateFromWSRPName(windStateNames[i])); } String[] localeNames = markupType.getLocales(); for (int i = 0; i < localeNames.length; i++) { LocaleInfo info = LocaleInfo.decodeLocaleInfoFromRFC3066LanguageTag(localeNames[i]); locales.add(info.getLocale()); } } String mimeType; Set modes; Set windowStates; Set locales; } } |