Author: julien(a)jboss.com
Date: 2008-01-08 10:57:56 -0500 (Tue, 08 Jan 2008)
New Revision: 9457
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCacheInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerMetaInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerModeInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferenceInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferencesInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSecurityInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSessionInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerWindowStateInfo.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/PortletInfoBuilder.java
Log:
first shot for container runtime info using new metadata model
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCacheInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCacheInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCacheInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.portlet.info.CacheInfo;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6697 $
+ */
+public class ContainerCacheInfo implements CacheInfo
+{
+
+ /** . */
+ private int expirationTimeSecs;
+
+ public ContainerCacheInfo(int expirationTimeSecs)
+ {
+ this.expirationTimeSecs = expirationTimeSecs;
+ }
+
+ public int getExpirationSecs()
+ {
+ return expirationTimeSecs;
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerCapabilitiesInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,376 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.portlet.info.CapabilitiesInfo;
+import org.jboss.portal.portlet.info.ModeInfo;
+import org.jboss.portal.portlet.info.WindowStateInfo;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Locale;
+
+/**
+ * This object holds the content type and mode capabilities.
+ * <p/>
+ * Todo : use the media type object ?
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6700 $
+ */
+public class ContainerCapabilitiesInfo implements CapabilitiesInfo
+{
+
+ /** . */
+ private static Set<WindowStateInfo> WINDOW_STATES;
+
+ /** . */
+ private static final String ANY = "*";
+
+ /** . */
+ private static final String ANY_ANY = "*/*";
+
+ /** . */
+ private static final char SEPARATOR = '/';
+
+ static
+ {
+ Set<WindowStateInfo> tmp = new HashSet<WindowStateInfo>();
+ tmp.add(new ContainerWindowStateInfo(WindowState.MAXIMIZED));
+ tmp.add(new ContainerWindowStateInfo(WindowState.MINIMIZED));
+ tmp.add(new ContainerWindowStateInfo(WindowState.NORMAL));
+ WINDOW_STATES = Collections.unmodifiableSet(tmp);
+ }
+
+ /** Maps MIME Type (String) -> Modes (Set), excluding multiple MIME Types
("*", "* / *", "type / *"). */
+ protected final Map<String, Set<Mode>> singleTypeToPortletModes;
+
+ /** Maps MIME Type (String) -> Modes (Set), including multiple MIME Types
("*", "* / *", "type / *"). */
+ protected final Map<String, Set<Mode>> allTypeToPortletModes;
+
+ /** . */
+ protected final Set<Mode> allModes;
+
+ /** . */
+ private final Set<Locale> supportedLocales;
+
+ // case-insensitive
+ // CONTENT TYPE = TYPE / SUBTYPE
+ // SUBTYPE = any char except a TSPECIALS or SPACE or CTLS (??)
+ // TSPECIALS ( ) < > @ , ; : \ " / [ ] ? . =
+
+ public ContainerCapabilitiesInfo()
+ {
+ this.singleTypeToPortletModes = new HashMap<String, Set<Mode>>();
+ this.allTypeToPortletModes = new HashMap<String, Set<Mode>>(); //
Including *
+ this.allModes = new HashSet<Mode>();
+ this.supportedLocales = new HashSet<Locale>();
+ }
+
+ public void add(String contentType, Mode mode)
+ {
+ // Determines which map and key to store the mode under
+ String key;
+ if (ANY.equals(contentType) || ANY_ANY.equals(contentType))
+ {
+ key = ANY;
+ }
+ else
+ {
+ int index = contentType.indexOf(SEPARATOR);
+ if (index == -1)
+ {
+ System.out.println("'" + contentType + "' is not a
valid MIME type: ignoring!");
+ return;
+ }
+
+ String type = contentType.substring(0, index);
+ String subtype = contentType.substring(index + 1);
+
+ if (ANY.equals(subtype))
+ {
+ key = type;
+ }
+ else
+ {
+ key = contentType;
+ // This is a single content type so we need to add it to the single mappings
in addition to all
+ addMode(singleTypeToPortletModes, key, mode);
+ }
+ }
+
+ // Store the mode in the complete mapping
+ addMode(allTypeToPortletModes, key, mode);
+
+ // Add the mode to the known modes
+ allModes.add(mode);
+ }
+
+ private void addMode(Map<String, Set<Mode>> map, String key, Mode mode)
+ {
+ Set<Mode> modes = map.get(key);
+ if (modes == null)
+ {
+ modes = new HashSet<Mode>();
+ map.put(key, modes);
+ }
+ modes.add(mode);
+ }
+
+ /**
+ * Return all modes.
+ *
+ * @return all modes
+ */
+ public Collection<Mode> getModes()
+ {
+ return Collections.unmodifiableCollection(allModes);
+ }
+
+ /**
+ * Return all content types.
+ *
+ * @return all content types
+ */
+ public Collection<String> getAllContentTypes()
+ {
+ return Collections.unmodifiableCollection(allTypeToPortletModes.keySet());
+ }
+
+ /**
+ * Return true if the mode is supported
+ *
+ * @param mode the mode to check
+ * @return true if the mode is supported
+ * @throws IllegalArgumentException if the mode is null
+ */
+ public boolean isModeSupported(Mode mode)
+ {
+ if (mode == null)
+ {
+ throw new IllegalArgumentException("Mode must not be null");
+ }
+ return allModes.contains(mode);
+ }
+
+ /**
+ * Return all the supported modes for this content type.
+ *
+ * @param contentType the content type to check
+ * @throws IllegalArgumentException if the content type is null
+ * @return the set of modes matching the content types support
+ */
+ public Set<Mode> getSupportedModes(String contentType)
+ {
+ if (contentType == null)
+ {
+ throw new IllegalArgumentException("Content type must not be null");
+ }
+
+ int index = contentType.indexOf(SEPARATOR);
+ if (index == -1)
+ {
+ // Not valid content type so return empty set
+ return Collections.emptySet();
+ }
+
+ //
+ Set<Mode> set = new HashSet<Mode>();
+
+ //
+ Set<Mode> contentTypeModes =
singleTypeToPortletModes.get(contentType.toLowerCase());
+ if (contentTypeModes != null)
+ {
+ set.addAll(contentTypeModes);
+ }
+
+ //
+ Set<Mode> typeModes = allTypeToPortletModes.get(contentType.substring(0,
index).toLowerCase());
+ if (typeModes != null)
+ {
+ set.addAll(typeModes);
+ }
+
+ Set<Mode> wildcardModes = allTypeToPortletModes.get(ANY);
+ if (wildcardModes != null)
+ {
+ set.addAll(wildcardModes);
+ }
+
+ return set;
+ }
+
+ /**
+ * Return true if the content type is supported.
+ *
+ * @param contentType the content type
+ * @return true is it is supported
+ * @throws IllegalArgumentException if the content type is null
+ */
+ public boolean isContentTypeSupported(String contentType)
+ {
+ Collection allContentTypes = getAllContentTypes();
+ if (contentType == null)
+ {
+ throw new IllegalArgumentException("Content type must not be null");
+ }
+
+ int index = contentType.indexOf(SEPARATOR);
+ if (index == -1)
+ {
+ // Not valid content type so return false
+ return false;
+ }
+
+ // Try the content type, * or */*
+ if (allContentTypes.contains(contentType) |
+ allContentTypes.contains(contentType.toLowerCase()) |
+ allContentTypes.contains(ANY) |
+ allContentTypes.contains(ANY_ANY))
+ {
+ return true;
+ }
+
+ // Try xxx/*
+ String wildcard = contentType.substring(0, index) + "/*";
+ return allContentTypes.contains(wildcard) |
allContentTypes.contains(wildcard.toLowerCase());
+ }
+
+ /**
+ * Return true if the given content type is supported for the given mode.
+ *
+ * @param mode the mode to check
+ * @param contentType the content type to check
+ * @return true if is it supported
+ * @throws IllegalArgumentException if the content type or the mode is null
+ */
+ public boolean isSupported(Mode mode, String contentType)
+ {
+ if (mode == null)
+ {
+ throw new IllegalArgumentException("Mode must not be null");
+ }
+ if (contentType == null)
+ {
+ throw new IllegalArgumentException("Content type must not be null");
+ }
+
+ int index = contentType.indexOf(SEPARATOR);
+ if (index == -1)
+ {
+ // Not valid content type so return false
+ return false;
+ }
+
+ // Try full name matching
+ Set<Mode> contentTypeModes = singleTypeToPortletModes.get(contentType);
+ if (contentTypeModes != null && contentTypeModes.contains(mode))
+ {
+ return true;
+ }
+
+ // Try full name lowercase matching
+ Set<Mode> lowercaseContentTypeModes =
singleTypeToPortletModes.get(contentType.toLowerCase());
+ if (lowercaseContentTypeModes != null &&
lowercaseContentTypeModes.contains(mode))
+ {
+ return true;
+ }
+
+ // Try type matching
+ String type = contentType.substring(0, index);
+ Set<Mode> typeMode = allTypeToPortletModes.get(type);
+ if (typeMode != null && typeMode.contains(mode))
+ {
+ return true;
+ }
+
+ // Try type matching
+ Set<Mode> lowercaseTypeMode = allTypeToPortletModes.get(type.toLowerCase());
+ if (lowercaseTypeMode != null && lowercaseTypeMode.contains(mode))
+ {
+ return true;
+ }
+
+ // Try wildcard matching
+ Set<Mode> wildcardMode = allTypeToPortletModes.get(ANY);
+ return wildcardMode != null && wildcardMode.contains(mode);
+ }
+
+ // CapabilitiesInfo implementation
**********************************************************************************
+
+ public Set<String> getMimeTypes()
+ {
+ return new HashSet<String>(getAllContentTypes());
+ }
+
+ public Set<ModeInfo> getAllModes()
+ {
+ Set<ModeInfo> infos = new HashSet<ModeInfo>();
+ for (Mode mode : getModes())
+ {
+ infos.add(new ContainerModeInfo(mode));
+ }
+ return infos;
+ }
+
+ public Set<ModeInfo> getModes(String mimeType)
+ {
+ Set<ModeInfo> infos = new HashSet<ModeInfo>();
+ for (Mode mode : getSupportedModes(mimeType))
+ {
+ infos.add(new ContainerModeInfo(mode));
+ }
+ return infos;
+ }
+
+ public Set<WindowStateInfo> getAllWindowStates()
+ {
+ return WINDOW_STATES;
+ }
+
+ public Set<WindowStateInfo> getWindowStates(String mimeType)
+ {
+ if (isContentTypeSupported(mimeType))
+ {
+ return getAllWindowStates();
+ }
+ return Collections.emptySet();
+ }
+
+ public Set<Locale> getAllLocales()
+ {
+ return supportedLocales;
+ }
+
+ public Set<Locale> getLocales(String mimeType)
+ {
+ return getAllLocales();
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerMetaInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerMetaInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerMetaInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.portlet.info.MetaInfo;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6818 $
+ */
+public class ContainerMetaInfo implements MetaInfo
+{
+
+ /** . */
+ private Map<String, LocalizedString> values;
+
+ public ContainerMetaInfo()
+ {
+ this.values = new HashMap<String, LocalizedString>();
+ }
+
+ public void addMetaValue(String key, LocalizedString value)
+ {
+ values.put(key, value);
+ }
+
+ public LocalizedString getMetaValue(String key)
+ {
+ return values.get(key);
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerModeInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerModeInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerModeInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.portlet.info.ModeInfo;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6818 $
+ * @since 2.4
+ */
+class ContainerModeInfo implements ModeInfo
+{
+
+ /** . */
+ private static final LocalizedString DEFAULT_DESCRIPTION = new
LocalizedString("Default Portlet mode description.", Locale.ENGLISH);
+
+ /** . */
+ private final Mode mode;
+
+ public ContainerModeInfo(Mode mode)
+ {
+ if (mode == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.mode = mode;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return DEFAULT_DESCRIPTION; // fix-me
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public String getModeName()
+ {
+ return mode.toString();
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+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.PortletInfo;
+import org.jboss.portal.portlet.info.PreferencesInfo;
+import org.jboss.portal.portlet.info.SecurityInfo;
+import org.jboss.portal.portlet.info.SessionInfo;
+
+/**
+ * For now implementation that use the portlet container directly.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 7242 $
+ */
+public class ContainerPortletInfo implements PortletInfo
+{
+
+ /** . */
+ private ContainerCapabilitiesInfo capabilities;
+
+ /** . */
+ private ContainerPreferencesInfo preferences;
+
+ /** . */
+ private ContainerMetaInfo meta;
+
+ /** . */
+ private ContainerSecurityInfo security;
+
+ /** . */
+ private ContainerCacheInfo cache;
+
+ /** . */
+ private ContainerSessionInfo session;
+
+ /** . */
+ private Boolean remotable;
+
+ public ContainerPortletInfo(
+ ContainerCapabilitiesInfo capabilities,
+ ContainerPreferencesInfo preferences,
+ ContainerMetaInfo meta,
+ ContainerSecurityInfo security,
+ ContainerCacheInfo cache,
+ ContainerSessionInfo session,
+ Boolean remotable)
+ {
+ this.capabilities = capabilities;
+ this.preferences = preferences;
+ this.meta = meta;
+ this.security = security;
+ this.cache = cache;
+ this.session = session;
+ this.remotable = remotable;
+ }
+
+ public CapabilitiesInfo getCapabilities()
+ {
+ return capabilities;
+ }
+
+ public PreferencesInfo getPreferences()
+ {
+ return preferences;
+ }
+
+ public MetaInfo getMeta()
+ {
+ return meta;
+ }
+
+ public SecurityInfo getSecurity()
+ {
+ return security;
+ }
+
+ public CacheInfo getCache()
+ {
+ return cache;
+ }
+
+ public SessionInfo getSession()
+ {
+ return session;
+ }
+
+ public Boolean isRemotable()
+ {
+ return remotable;
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferenceInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferenceInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferenceInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.value.Value;
+import org.jboss.portal.portlet.info.PreferenceInfo;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6818 $
+ */
+public class ContainerPreferenceInfo implements PreferenceInfo
+{
+
+ private String key;
+ private LocalizedString displayName;
+ private LocalizedString description;
+ private Boolean readOnly;
+ private Value value;
+
+ public ContainerPreferenceInfo(String key, LocalizedString displayName,
LocalizedString description, boolean readOnly, Value value)
+ {
+ this.key = key;
+ this.displayName = displayName;
+ this.description = description;
+ this.readOnly = Boolean.valueOf(readOnly);
+ this.value = value;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public LocalizedString getDisplayName()
+ {
+ return displayName;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return description;
+ }
+
+ public Boolean isReadOnly()
+ {
+ return readOnly;
+ }
+
+ /**
+ * Return the value provided by the portlet.xml deployment descriptor.
+ *
+ * @return the preference value associated with this preference meta data
+ */
+ public Value getDefaultValue()
+ {
+ return value;
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferencesInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferencesInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPreferencesInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.value.Value;
+import org.jboss.portal.portlet.info.PreferenceInfo;
+import org.jboss.portal.portlet.info.PreferencesInfo;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6818 $
+ */
+public class ContainerPreferencesInfo implements PreferencesInfo
+{
+
+ /** The cached container preference info. */
+ private final Map<String, PreferenceInfo> content;
+
+ /** . */
+ private final Set<String> keys;
+
+ public ContainerPreferencesInfo()
+ {
+ content = new HashMap<String, PreferenceInfo>();
+ keys = Collections.unmodifiableSet(content.keySet());
+ }
+
+ public ContainerPreferenceInfo getContainerPreference(String key)
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("Preference key must not be
null");
+ }
+ return (ContainerPreferenceInfo)content.get(key);
+ }
+
+ public void addContainerPreference(
+ String name,
+ Value value,
+ boolean readOnly,
+ LocalizedString displayName,
+ LocalizedString description)
+ {
+ ContainerPreferenceInfo pref = new ContainerPreferenceInfo(name, displayName,
description, readOnly, value);
+ content.put(pref.getKey(), pref);
+ }
+
+ public Set<String> getKeys()
+ {
+ return keys;
+ }
+
+ public PreferenceInfo getPreference(String key)
+ {
+ return getContainerPreference(key);
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSecurityInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSecurityInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSecurityInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.portlet.TransportGuarantee;
+import org.jboss.portal.portlet.info.SecurityInfo;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6697 $
+ */
+public class ContainerSecurityInfo implements SecurityInfo
+{
+
+ /** . */
+ private final Set<TransportGuarantee> tgs;
+
+ /** . */
+ private final Set<TransportGuarantee> rotgs;
+
+ public ContainerSecurityInfo()
+ {
+ tgs = new HashSet<TransportGuarantee>();
+ tgs.add(TransportGuarantee.NONE);
+
+ //
+ rotgs = Collections.unmodifiableSet(tgs);
+ }
+
+ public void addTransportGuarantee(TransportGuarantee transportGuarantee)
+ {
+ tgs.add(transportGuarantee);
+ }
+
+ public boolean containsTransportGuarantee(TransportGuarantee transportGuarantee)
+ {
+ return tgs.contains(transportGuarantee);
+ }
+
+ public Set<TransportGuarantee> getTransportGuarantees()
+ {
+ return rotgs;
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSessionInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSessionInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerSessionInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.portlet.info.SessionInfo;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 7226 $
+ */
+public class ContainerSessionInfo implements SessionInfo
+{
+
+ /** . */
+ private boolean distributed;
+
+ ContainerSessionInfo(Boolean distributed)
+ {
+ if (distributed == null)
+ {
+ distributed = false;
+ }
+
+ //
+ this.distributed = distributed;
+ }
+
+ public Boolean getDistributed()
+ {
+ return distributed;
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerWindowStateInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerWindowStateInfo.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerWindowStateInfo.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.portlet.info.WindowStateInfo;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 6818 $
+ * @since 2.4
+ */
+class ContainerWindowStateInfo implements WindowStateInfo
+{
+
+ /** . */
+ private static final LocalizedString DEFAULT_DESCRIPTION = new
LocalizedString("Default window state description.", Locale.ENGLISH);
+
+ /** . */
+ private final WindowState windowState;
+
+ public ContainerWindowStateInfo(WindowState windowState)
+ {
+ if (windowState == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.windowState = windowState;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return DEFAULT_DESCRIPTION; //fix-me
+ }
+
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+
+ public String getWindowStateName()
+ {
+ return windowState.toString();
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/PortletInfoBuilder.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/PortletInfoBuilder.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/PortletInfoBuilder.java 2008-01-08
15:57:56 UTC (rev 9457)
@@ -0,0 +1,228 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portlet.impl.info;
+
+import org.jboss.portal.portlet.impl.metadata.portlet.PortletMetaData;
+import org.jboss.portal.portlet.impl.metadata.portlet.PortletPreferenceMetaData;
+import org.jboss.portal.portlet.impl.metadata.portlet.SupportedLocaleMetaData;
+import org.jboss.portal.portlet.impl.metadata.portlet.SupportsMetaData;
+import org.jboss.portal.portlet.impl.metadata.portlet.PortletModeMetaData;
+import org.jboss.portal.portlet.impl.metadata.security.SecurityConstraintMetaData;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.info.MetaInfo;
+import org.jboss.portal.common.value.Value;
+import org.jboss.portal.common.value.StringValue;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.i18n.ResourceBundleManager;
+import org.jboss.portal.Mode;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortletInfoBuilder
+{
+
+ /** . */
+ private static final String[] KEYS = {MetaInfo.TITLE, MetaInfo.SHORT_TITLE,
MetaInfo.KEYWORDS};
+
+ /** . */
+ private static final String JAVAX_PORTLET = "javax.portlet.";
+
+ /** . */
+ private static final String[] BUNDLE_KEYS = {JAVAX_PORTLET + MetaInfo.TITLE,
JAVAX_PORTLET + MetaInfo.SHORT_TITLE, JAVAX_PORTLET + MetaInfo.KEYWORDS};
+
+ /** . */
+ private PortletMetaData portletMD;
+
+ /** . */
+ private ResourceBundleManager bundleMgr;
+
+ public PortletInfoBuilder(PortletMetaData portletMD, ResourceBundleManager bundleMgr)
+ {
+ this.portletMD = portletMD;
+ this.bundleMgr = bundleMgr;
+ }
+
+ public PortletInfo build()
+ {
+ ContainerCapabilitiesInfo containerCapabilities = buildContainerCapabilities();
+ ContainerPreferencesInfo containerPreferences = buildContainerPreferences();
+ ContainerMetaInfo containerMeta = buildContainerMeta();
+ ContainerSecurityInfo containerSecurity = buildContainerSecurityInfo();
+ ContainerCacheInfo containerCache = buildContainerCache();
+ ContainerSessionInfo containerSession = buildContainerSession();
+
+ //
+ return new ContainerPortletInfo(
+ containerCapabilities,
+ containerPreferences,
+ containerMeta,
+ containerSecurity,
+ containerCache,
+ containerSession,
+ false
+ );
+ }
+
+ private List<Locale> getSupportedLocales()
+ {
+ List<Locale> locales = new ArrayList<Locale>();
+ for (SupportedLocaleMetaData supportedLocaleMD : portletMD.getSupportedLocale())
+ {
+ Locale locale = supportedLocaleMD.getLocale();
+ locales.add(locale);
+ }
+ return locales;
+ }
+
+ private ContainerSecurityInfo buildContainerSecurityInfo()
+ {
+ ContainerSecurityInfo containerSecurity = new ContainerSecurityInfo();
+
+ //
+ for (SecurityConstraintMetaData securityConstraintMD :
portletMD.getPortletApplication().getSecurityConstraints())
+ {
+ if
(securityConstraintMD.getPortletList().getPortletNames().contains(portletMD.getPortletName()))
+ {
+
containerSecurity.addTransportGuarantee(securityConstraintMD.getUserDataConstraint().getTransportQuarantee());
+ }
+ }
+
+ //
+ return containerSecurity;
+ }
+
+ private ContainerSessionInfo buildContainerSession()
+ {
+ return new ContainerSessionInfo(false);
+ }
+
+ private ContainerCacheInfo buildContainerCache()
+ {
+ int expirationCache = portletMD.getExpirationCache();
+
+ //
+ if (expirationCache < 0 && expirationCache != -1)
+ {
+ // log.warn("Seen bad caching expiration value " + expirationTimeSecs
+ " disable caching instead");
+ expirationCache = 0;
+ }
+
+ //
+ return new ContainerCacheInfo(expirationCache);
+ }
+
+ private ContainerCapabilitiesInfo buildContainerCapabilities()
+ {
+ ContainerCapabilitiesInfo capabilities = new ContainerCapabilitiesInfo();
+
+ //
+ for (SupportsMetaData supportsMD : portletMD.getSupports())
+ {
+ // Get the mime type
+ String mimeType = supportsMD.getMimeType().toLowerCase();
+
+ // Add the content type to the view mode
+ // because each content type must handle this view
+ capabilities.add(mimeType, Mode.VIEW);
+
+ // Then process each mode
+ for (PortletModeMetaData modeMD : supportsMD.getPortletModes())
+ {
+ capabilities.add(mimeType, Mode.create(modeMD.getPortletMode()));
+ }
+ }
+
+ //
+ return capabilities;
+ }
+
+ private ContainerMetaInfo buildContainerMeta()
+ {
+ ContainerMetaInfo containerMeta = new ContainerMetaInfo();
+
+ // Construct info from resource bundle manager
+ if (bundleMgr != null)
+ {
+ for (int i = 0; i < KEYS.length; i++)
+ {
+ String key = KEYS[i];
+ Map<Locale, String> tmp = new HashMap<Locale, String>();
+
+ //
+ List<Locale> locales = getSupportedLocales();
+
+ // Add english locale
+ locales.add(Locale.ENGLISH);
+
+ for (Locale locale : locales)
+ {
+ ResourceBundle bundle = bundleMgr.getResourceBundle(locale);
+ try
+ {
+ String value = bundle.getString(BUNDLE_KEYS[i]);
+ tmp.put(locale, value);
+ }
+ catch (MissingResourceException ignore)
+ {
+ }
+ }
+ LocalizedString ls = new LocalizedString(tmp, Locale.ENGLISH);
+ containerMeta.addMetaValue(key, ls);
+ }
+ }
+
+ // Add stuff coming from meta data
+ containerMeta.addMetaValue(MetaInfo.DESCRIPTION, portletMD.getDescription());
+ containerMeta.addMetaValue(MetaInfo.DISPLAY_NAME, portletMD.getDisplayName());
+
+ //
+ return containerMeta;
+ }
+
+ private ContainerPreferencesInfo buildContainerPreferences()
+ {
+ ContainerPreferencesInfo containerPreferences = new ContainerPreferencesInfo();
+
+ //
+ for (PortletPreferenceMetaData portletPreferenceMD :
portletMD.getPortletPreferences().getPortletPreferences().values())
+ {
+ Value value = new StringValue(portletPreferenceMD.getValue().toArray(new
String[portletPreferenceMD.getValue().size()]));
+ LocalizedString displayName =
bundleMgr.getLocalizedValue("javax.portlet.preference.name." +
portletPreferenceMD.getName(), portletPreferenceMD.getName());
+ LocalizedString description =
bundleMgr.getLocalizedValue("javax.portlet.preference.description." +
portletPreferenceMD.getName(), portletPreferenceMD.getName());
+ containerPreferences.addContainerPreference(portletPreferenceMD.getName(),
value, portletPreferenceMD.isReadOnly(), displayName, description);
+ }
+
+ //
+ return containerPreferences;
+ }
+}