*/
private MarkupRequest createMarkupRequestFrom(List<MarkupType> markupTypes, MimeRequest params, Portlet portlet)
throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState, UnsupportedLocale
{
List<String> desiredMIMETypes = params.getMimeTypes();
MarkupType markupType = null;
// Get the MIME type to use
// todo: MIME type resolution should really be done in common... maybe as part of GTNCOMMON-14?
for (String desiredMIMEType : desiredMIMETypes)
{
desiredMIMEType = desiredMIMEType.trim();
// first deal with full wildcards
if ("*".equals(desiredMIMEType) || "*/*".equals(desiredMIMEType))
{
markupType = markupTypes.get(0);
break;
}
else
{
MediaType mt = MediaType.create(desiredMIMEType);
String superType = mt.getType().getName();
String subType = mt.getSubtype().getName();
boolean isWildcard = "*".equals(subType);
for (MarkupType type : markupTypes)
{
if (isWildcard && type.getMimeType().startsWith(superType))
{
markupType = type;
break;
}
else if (desiredMIMEType.equals(type.getMimeType()))
{
markupType = type;
break;
}
}
}
// if we've found a match, do not examine the other possible matches
if (markupType != null)
{
break;
}
}
// no MIME type was found: error!
if (markupType == null)
{
throw WSRP2ExceptionFactory.throwWSException(UnsupportedMimeType.class, "None of the specified MIME types are supported by portlet '" + portlet.getContext().getId() + "'", null);
}
// use user-desired locales
List<String> desiredLocales = new ArrayList<String>(params.getLocales());
List<String> supportedLocales = new ArrayList<String>(markupType.getLocales());
desiredLocales.retainAll(supportedLocales);
if (desiredLocales.isEmpty())
{
desiredLocales = params.getLocales();
}
// copy MarkupType as this is one shared instance
MarkupType markupTypeCopy = WSRPTypeFactory.createMarkupType(markupType.getMimeType(), markupType.getModes(), markupType.getWindowStates(), desiredLocales);
markupTypeCopy.getExtensions().addAll(markupType.getExtensions());
// get the mode
String mode;
try
{
mode = getMatchingOrFailFrom(markupTypeCopy.getModes(), params.getMode(), PORTLET_MODE);
}
catch (IllegalArgumentException e)
{
throw WSRP2ExceptionFactory.throwWSException(UnsupportedMode.class, "Unsupported mode '" + params.getMode() + "'", e);
}
// get the window state
String windowState;
try
{
windowState = getMatchingOrFailFrom(markupTypeCopy.getWindowStates(), params.getWindowState(), WINDOW_STATE);
}
catch (IllegalArgumentException e)
{
throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class, "Unsupported window state '" + params.getWindowState() + "'", e);
}