Author: chris.laprun(a)jboss.com
Date: 2006-12-13 00:30:22 -0500 (Wed, 13 Dec 2006)
New Revision: 5816
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
Log:
- Added implementation for getPortletPropertyDescription (untested).
- Added stub to check user authorization, needs to be implemented.
- Now use key instead of display name for the property name. Need to check that this is
correct!
- Moved common.LocalizedString to wsrp.LocalizedString conversion method to WSRPUtils.
- Added more creation methods to WSRPTypeFactory.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2006-12-13 03:48:34 UTC
(rev 5815)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2006-12-13 05:30:22 UTC
(rev 5816)
@@ -25,6 +25,7 @@
import org.jboss.portal.server.PortalConstants;
+import javax.xml.namespace.QName;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Random;
@@ -166,7 +167,10 @@
/** The value of SessionContext.expires if the session will never expire. */
public static final int SESSION_NEVER_EXPIRES = -1;
+ /** A QName representing the string type defined as part of XML Schemas Part 2 */
+ public static final QName XSD_STRING = new
QName("http://www.w3.org/2001/XMLSchema", "string");
+
private WSRPConstants()
{
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2006-12-13 03:48:34 UTC
(rev 5815)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2006-12-13 05:30:22 UTC
(rev 5816)
@@ -50,6 +50,8 @@
import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
import org.jboss.portal.wsrp.core.PortletContext;
import org.jboss.portal.wsrp.core.PortletDescription;
+import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
+import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
import org.jboss.portal.wsrp.core.Property;
import org.jboss.portal.wsrp.core.PropertyDescription;
import org.jboss.portal.wsrp.core.RegistrationContext;
@@ -662,6 +664,7 @@
* value(xsd:string), @xml:lang, @resourceName(xsd:string)?
*
* @return
+ * @since 2.6
*/
public static LocalizedString createLocalizedString(String lang, String resourceName,
String value)
{
@@ -675,9 +678,34 @@
*
* @param value
* @return
+ * @since 2.6
*/
public static LocalizedString createLocalizedString(String value)
{
return createLocalizedString("en", null, value);
}
+
+ /**
+ * portletDescription(PortletDescription), resourceList(ResourceList)?,
extensions(Extension)*
+ *
+ * @param portletDescription
+ * @return
+ * @since 2.6
+ */
+ public static PortletDescriptionResponse
createPortletDescriptionResponse(PortletDescription portletDescription)
+ {
+ return new PortletDescriptionResponse(portletDescription, null, null);
+ }
+
+ /**
+ * modelDescription(ModelDescription)?, resourceList(ResourceList)?,
extensions(Extension)*
+ *
+ * @param propertyDescriptions
+ * @return
+ * @since 2.6
+ */
+ public static PortletPropertyDescriptionResponse
createPortletPropertyDescriptionResponse(PropertyDescription[] propertyDescriptions)
+ {
+ return new
PortletPropertyDescriptionResponse(createModelDescription(propertyDescriptions), null,
null);
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2006-12-13 03:48:34 UTC (rev
5815)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2006-12-13 05:30:22 UTC (rev
5816)
@@ -283,6 +283,11 @@
}
}
+ /**
+ * @param registrationInfo
+ * @return
+ * @since 2.6
+ */
public static ModelDescription convertRegistrationPropertiesToModelDescription(Map
registrationInfo)
{
ParameterValidation.throwIllegalArgExceptionIfNull(registrationInfo,
"registration info");
@@ -303,6 +308,11 @@
return WSRPTypeFactory.createModelDescription(propertyDescriptions);
}
+ /**
+ * @param propertyDescription
+ * @return
+ * @since 2.6
+ */
public static PropertyDescription
convertToPropertyDescription(RegistrationPropertyDescription propertyDescription)
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription,
"RegistrationPropertyDescription");
@@ -323,12 +333,23 @@
return propDesc;
}
+ /**
+ * @param regLocalizedString
+ * @return
+ * @since 2.6
+ */
public static org.jboss.portal.wsrp.core.LocalizedString
convertToWSRPLocalizedString(LocalizedString regLocalizedString)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(regLocalizedString,
"LocalizedString");
return
WSRPTypeFactory.createLocalizedString(LocaleInfo.getRFC3066LanguageTagFor(regLocalizedString.getLocale()),
regLocalizedString.getResourceName(), regLocalizedString.getValue());
}
+ /**
+ * @param consumerAgent
+ * @throws IllegalArgumentException
+ * @since 2.6
+ */
public static void validateConsumerAgent(String consumerAgent) throws
IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerAgent,
"consumer agent", null);
@@ -346,4 +367,39 @@
}
throw new IllegalArgumentException("'" + consumerAgent + "'
is not a valid Consumer Agent.");
}
+
+ /**
+ * Creates a WSRP LocalizedString based on the best (according to the specified
desired locales) value of the given
+ * LocalizedString.
+ *
+ * @param localizedString the LocalizedString from which a localized value is to be
extracted
+ * @param desiredLocales the supported locales orderd by user preference, if no
desiredLocales are given, the
+ * default local will be used.
+ * @return the best (according to the specified desired locales) value for the given
LocalizedString or
+ * <code>null</code> if no such value can be found.
+ * @since 2.6
+ */
+ public static org.jboss.portal.wsrp.core.LocalizedString
convertToWSRPLocalizedString(org.jboss.portal.common.util.LocalizedString
localizedString,
+
String[] desiredLocales)
+ {
+ if (localizedString == null)
+ {
+ return null;
+ }
+
+ if (desiredLocales == null || desiredLocales.length == 0)
+ {
+ desiredLocales = new
String[]{LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault())};
+ }
+
+ org.jboss.portal.common.util.LocalizedString.Value bestMapping =
localizedString.getPreferredOrBestLocalizedMappingFor(desiredLocales);
+ if (bestMapping != null)
+ {
+ Locale locale = bestMapping.getLocale();
+ String value = bestMapping.getString();
+ String language = LocaleInfo.decodeLocaleInfo(locale).getRFC3066LanguageTag();
+ return WSRPTypeFactory.createLocalizedString(language, null, value);
+ }
+ return null;
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2006-12-13
03:48:34 UTC (rev 5815)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2006-12-13
05:30:22 UTC (rev 5816)
@@ -32,7 +32,9 @@
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.info.PreferenceInfo;
+import org.jboss.portal.portlet.info.PreferencesInfo;
import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
@@ -52,8 +54,10 @@
import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
import org.jboss.portal.wsrp.core.Property;
+import org.jboss.portal.wsrp.core.PropertyDescription;
import org.jboss.portal.wsrp.core.PropertyList;
import org.jboss.portal.wsrp.core.SetPortletProperties;
+import org.jboss.portal.wsrp.core.UserContext;
import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType;
import java.rmi.RemoteException;
@@ -73,6 +77,7 @@
private static final String GET_PORTLET_PROPERTY_DESCRIPTION =
"GetPortletPropertyDescription";
private static final String GET_PORTLET_PROPERTIES =
"GetPortletProperties";
private static final String PORTLET_CONTEXT = "PortletContext";
+ private static final String GET_PORTLET_DESCRIPTION =
"GetPortletDescription";
PortletManagementHandler(WSRPProducerImpl producer)
{
@@ -83,16 +88,24 @@
throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault,
InconsistentParametersFault,
MissingParametersFault, InvalidRegistrationFault, OperationFailedFault,
RemoteException
{
- WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletDescription,
"getPortletDescription");
+ WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletDescription,
GET_PORTLET_DESCRIPTION);
producer.checkRegistration(getPortletDescription.getRegistrationContext());
- String handle = getPortletDescription.getPortletContext().getPortletHandle();
- return new PortletDescriptionResponse(
- producer.getPortletDescription(handle,
getPortletDescription.getDesiredLocales()),
- null, null);
+ PortletContext portletContext = getPortletDescription.getPortletContext();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_DESCRIPTION);
+
+ String handle = portletContext.getPortletHandle();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(handle, "portlet
handle", PORTLET_CONTEXT);
+
+ UserContext userContext = getPortletDescription.getUserContext();
+ checkUserAuthorization(userContext);
+
+ return
WSRPTypeFactory.createPortletDescriptionResponse(producer.getPortletDescription(handle,
getPortletDescription.getDesiredLocales()));
}
- public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription getPortletPropertyDescription)
throws MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault,
InvalidRegistrationFault, AccessDeniedFault, InvalidHandleFault, OperationFailedFault,
RemoteException
+ public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription
getPortletPropertyDescription)
+ throws MissingParametersFault, InconsistentParametersFault,
InvalidUserCategoryFault, InvalidRegistrationFault,
+ AccessDeniedFault, InvalidHandleFault, OperationFailedFault, RemoteException
{
WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletPropertyDescription,
GET_PORTLET_PROPERTY_DESCRIPTION);
@@ -101,10 +114,37 @@
producer.checkRegistration(getPortletPropertyDescription.getRegistrationContext());
+ UserContext userContext = getPortletPropertyDescription.getUserContext();
+ checkUserAuthorization(userContext);
+
+ String[] desiredLocales = getPortletPropertyDescription.getDesiredLocales();
Portlet portlet = getPortletFrom(portletContext);
PortletInfo info = portlet.getInfo();
+ PreferencesInfo prefsInfo = info.getPreferences();
- return null; // todo: implement
+ PropertyDescription[] descs = null;
+ if (prefsInfo != null)
+ {
+ Set keySey = prefsInfo.getKeys();
+ descs = new PropertyDescription[keySey.size()];
+ int index = 0;
+ for (Iterator keys = keySey.iterator(); keys.hasNext();)
+ {
+ PreferenceInfo prefInfo = (PreferenceInfo)keys.next();
+
+ // WSRP Spec 8.7: return only the portion of the Portlet's persistent
state is allowed to modify
+ if (!prefInfo.isReadOnly().booleanValue())
+ {
+ //todo: check what we should use key
+ PropertyDescription desc =
WSRPTypeFactory.createPropertyDescription(prefInfo.getKey(), WSRPConstants.XSD_STRING);
+
desc.setLabel(WSRPUtils.convertToWSRPLocalizedString(prefInfo.getDisplayName(),
desiredLocales));
+
desc.setHint(WSRPUtils.convertToWSRPLocalizedString(prefInfo.getDescription(),
desiredLocales));
+ descs[index++] = desc;
+ }
+ }
+ }
+
+ return WSRPTypeFactory.createPortletPropertyDescriptionResponse(descs);
}
public PortletContext clonePortlet(ClonePortlet clonePortlet) throws
InvalidUserCategoryFault, AccessDeniedFault, OperationFailedFault, InvalidHandleFault,
InvalidRegistrationFault, InconsistentParametersFault, MissingParametersFault,
RemoteException
@@ -131,6 +171,9 @@
producer.checkRegistration(getPortletProperties.getRegistrationContext());
+ UserContext userContext = getPortletProperties.getUserContext();
+ checkUserAuthorization(userContext);
+
String[] names = getPortletProperties.getNames();
Set keys = getKeysFromNames(names);
@@ -172,7 +215,7 @@
prefInfo = info.getPreferences().getPreference(key);
displayName = prefInfo.getDisplayName();
String lang =
LocaleInfo.getRFC3066LanguageTagFor(displayName.getDefaultLocale());
- resProperties[i] =
WSRPTypeFactory.createProperty(displayName.getDefaultString(), lang, value.asString());
+ resProperties[i] = WSRPTypeFactory.createProperty(key, lang,
value.asString()); //todo: check what we should use key
}
result.setProperties(resProperties);
@@ -186,6 +229,15 @@
}
}
+ private void checkUserAuthorization(UserContext userContext)
+ {
+ //todo: implement
+ if (userContext != null)
+ {
+
+ }
+ }
+
private Set getKeysFromNames(String[] names)
{
Set keys = null;
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2006-12-13
03:48:34 UTC (rev 5815)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2006-12-13
05:30:22 UTC (rev 5816)
@@ -25,7 +25,6 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.LocaleInfo;
-import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
@@ -182,11 +181,6 @@
{
log.debug("Constructing portlet description for: " + id);
- if (desiredLocales == null)
- {
- desiredLocales = new
String[]{LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault())};
- }
-
CapabilitiesInfo capInfo = portletInfo.getCapabilities();
Collection allMimeTypes = capInfo.getMimeTypes();
MarkupType[] markupTypes = new MarkupType[allMimeTypes.size()];
@@ -210,21 +204,21 @@
MetaInfo metaInfo = portletInfo.getMeta();
// description
-
desc.setDescription(getBestLocalizedValueFrom(metaInfo.getMetaValue(MetaInfo.DESCRIPTION),
desiredLocales));
+
desc.setDescription(WSRPUtils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DESCRIPTION),
desiredLocales));
// short title
-
desc.setShortTitle(getBestLocalizedValueFrom(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE),
desiredLocales));
+
desc.setShortTitle(WSRPUtils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE),
desiredLocales));
// title
- desc.setTitle(getBestLocalizedValueFrom(metaInfo.getMetaValue(MetaInfo.TITLE),
desiredLocales));
+
desc.setTitle(WSRPUtils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.TITLE),
desiredLocales));
// display name
-
desc.setDisplayName(getBestLocalizedValueFrom(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME),
desiredLocales));
+
desc.setDisplayName(WSRPUtils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME),
desiredLocales));
// keywords
// metaInfo contains comma-separated keywords: we need to extract them into an
array
org.jboss.portal.wsrp.core.LocalizedString concatenatedKeywords =
- getBestLocalizedValueFrom(metaInfo.getMetaValue(MetaInfo.KEYWORDS),
desiredLocales);
+ WSRPUtils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.KEYWORDS),
desiredLocales);
if (concatenatedKeywords != null)
{
String commaSeparatedKeywords = concatenatedKeywords.getValue();
@@ -298,30 +292,4 @@
return result;
}
-
- /**
- * Retrieves the best (according to the specified desired locales) value for the given
localized portlet metadata.
- *
- * @param portletMetadata the localized metadata from which a localized value is to be
extracted
- * @param desiredLocales the supported locales orderd by user preference
- * @return the best (according to the specified desired locales) value for the given
localized portlet metadata or
- * <code>null</code> if no such value can be found.
- */
- private org.jboss.portal.wsrp.core.LocalizedString
getBestLocalizedValueFrom(LocalizedString portletMetadata, String[] desiredLocales)
- {
- if (portletMetadata == null)
- {
- return null;
- }
-
- LocalizedString.Value bestMapping =
portletMetadata.getPreferredOrBestLocalizedMappingFor(desiredLocales);
- if (bestMapping != null)
- {
- Locale locale = bestMapping.getLocale();
- String value = bestMapping.getString();
- String language = LocaleInfo.decodeLocaleInfo(locale).getRFC3066LanguageTag();
- return WSRPTypeFactory.createLocalizedString(language, null, value);
- }
- return null;
- }
}