0001: /******************************************************************************
0002: * JBoss, a division of Red Hat *
0003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
0004: * contributors as indicated by the @authors tag. See the *
0005: * copyright.txt in the distribution for a full listing of *
0006: * individual contributors. *
0007: * *
0008: * This is free software; you can redistribute it and/or modify it *
0009: * under the terms of the GNU Lesser General Public License as *
0010: * published by the Free Software Foundation; either version 2.1 of *
0011: * the License, or (at your option) any later version. *
0012: * *
0013: * This software is distributed in the hope that it will be useful, *
0014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
0015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
0016: * Lesser General Public License for more details. *
0017: * *
0018: * You should have received a copy of the GNU Lesser General Public *
0019: * License along with this software; if not, write to the Free *
0020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
0021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
0022: ******************************************************************************/package org.jboss.portal.wsrp;
0023:
0024: import org.jboss.portal.Mode;
0025: import org.jboss.portal.WindowState;
0026: import org.jboss.portal.common.util.ParameterValidation;
0027: import org.jboss.portal.common.util.Tools;
0028: import org.jboss.portal.portlet.ActionURL;
0029: import org.jboss.portal.portlet.PortletURL;
0030: import org.jboss.portal.portlet.RenderURL;
0031: import org.jboss.portal.portlet.StateString;
0032: import org.jboss.portal.portlet.spi.PortletInvocationContext;
0033: import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
0034: import org.jboss.portal.wsrp.core.CacheControl;
0035: import org.jboss.portal.wsrp.core.ClientData;
0036: import org.jboss.portal.wsrp.core.ClonePortlet;
0037: import org.jboss.portal.wsrp.core.DestroyFailed;
0038: import org.jboss.portal.wsrp.core.DestroyPortlets;
0039: import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
0040: import org.jboss.portal.wsrp.core.GetMarkup;
0041: import org.jboss.portal.wsrp.core.GetPortletDescription;
0042: import org.jboss.portal.wsrp.core.GetPortletProperties;
0043: import org.jboss.portal.wsrp.core.GetPortletPropertyDescription;
0044: import org.jboss.portal.wsrp.core.GetServiceDescription;
0045: import org.jboss.portal.wsrp.core.InitCookie;
0046: import org.jboss.portal.wsrp.core.InteractionParams;
0047: import org.jboss.portal.wsrp.core.LocalizedString;
0048: import org.jboss.portal.wsrp.core.MarkupContext;
0049: import org.jboss.portal.wsrp.core.MarkupParams;
0050: import org.jboss.portal.wsrp.core.MarkupResponse;
0051: import org.jboss.portal.wsrp.core.MarkupType;
0052: import org.jboss.portal.wsrp.core.ModelDescription;
0053: import org.jboss.portal.wsrp.core.ModifyRegistration;
0054: import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
0055: import org.jboss.portal.wsrp.core.PortletContext;
0056: import org.jboss.portal.wsrp.core.PortletDescription;
0057: import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
0058: import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
0059: import org.jboss.portal.wsrp.core.Property;
0060: import org.jboss.portal.wsrp.core.PropertyDescription;
0061: import org.jboss.portal.wsrp.core.PropertyList;
0062: import org.jboss.portal.wsrp.core.RegistrationContext;
0063: import org.jboss.portal.wsrp.core.RegistrationData;
0064: import org.jboss.portal.wsrp.core.ReleaseSessions;
0065: import org.jboss.portal.wsrp.core.ResetProperty;
0066: import org.jboss.portal.wsrp.core.RuntimeContext;
0067: import org.jboss.portal.wsrp.core.ServiceDescription;
0068: import org.jboss.portal.wsrp.core.SessionContext;
0069: import org.jboss.portal.wsrp.core.SetPortletProperties;
0070: import org.jboss.portal.wsrp.core.StateChange;
0071: import org.jboss.portal.wsrp.core.Templates;
0072: import org.jboss.portal.wsrp.core.UpdateResponse;
0073: import org.jboss.portal.wsrp.core.UploadContext;
0074: import org.jboss.portal.wsrp.core.UserContext;
0075:
0076: import javax.xml.namespace.QName;
0077:
0078: /**
0079: * Creates minimally valid instances of WSRP types, populated with default values where possible, as per
0080: * wsrp_v1_types.xsd. See <a href="http://jira.jboss.com/jira/browse/JBPORTAL-808">JBPORTAL-808</a> for more
0081: * information.
0082: *
0083: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
0084: * @version $Revision: 9360 $
0085: * @since 2.4
0086: */
0087: public class WSRPTypeFactory {
0088: private WSRPTypeFactory() {
0089: }
0090:
0091: /** ====== WSRP request objects ====== **/
0092: /**
0093: * registrationContext(RegistrationContext)?, desiredLocales(xsd:string)*
0094: *
0095: * @return
0096: */
0097: public static GetServiceDescription createGetServiceDescription() {
0098: return new GetServiceDescription();
0099: }
0100:
0101: /**
0102: * Same as createMarkupRequest(handle, createDefaultRuntimeContext(), createDefaultMarkupParams())
0103: *
0104: * @param handle
0105: * @return
0106: */
0107: public static GetMarkup createDefaultMarkupRequest(String handle) {
0108: return createMarkupRequest(createPortletContext(handle),
0109: createDefaultRuntimeContext(),
0110: createDefaultMarkupParams());
0111: }
0112:
0113: /**
0114: * registrationContext(RegistrationContext)?, portletContext(PortletContext), runtimeContext(RuntimeContext),
0115: * userContext(UserContext)?, markupParams(MarkupParams)
0116: *
0117: * @param portletContext
0118: * @param runtimeContext
0119: * @param markupParams
0120: * @return
0121: * @throws IllegalArgumentException if one of the required parameters is <code>null</code>
0122: */
0123: public static GetMarkup createMarkupRequest(
0124: PortletContext portletContext,
0125: RuntimeContext runtimeContext, MarkupParams markupParams) {
0126: ParameterValidation.throwIllegalArgExceptionIfNull(
0127: runtimeContext, "RuntimeContext");
0128: ParameterValidation.throwIllegalArgExceptionIfNull(
0129: portletContext, "PortletContext");
0130: ParameterValidation.throwIllegalArgExceptionIfNull(
0131: markupParams, "MarkupParams");
0132:
0133: return new GetMarkup(null, portletContext, runtimeContext,
0134: null, markupParams);
0135: }
0136:
0137: /**
0138: * Same as createPerformBlockingInteraction(portletHandle, {@link #createDefaultRuntimeContext}(), {@link
0139: * #createDefaultMarkupParams}(), {@link #createDefaultInteractionParams}());
0140: *
0141: * @param portletHandle
0142: * @return
0143: */
0144: public static PerformBlockingInteraction createDefaultPerformBlockingInteraction(
0145: String portletHandle) {
0146: return createPerformBlockingInteraction(
0147: createPortletContext(portletHandle),
0148: createDefaultRuntimeContext(),
0149: createDefaultMarkupParams(),
0150: createDefaultInteractionParams());
0151: }
0152:
0153: /**
0154: * {@link org.jboss.portal.wsrp.core.RegistrationContext}?, {@link PortletContext}, {@link RuntimeContext}, {@link
0155: * org.jboss.portal.wsrp.core.UserContext}?, {@link MarkupParams}, {@link InteractionParams}
0156: *
0157: * @param portletContext
0158: * @param runtimeContext
0159: * @param markupParams
0160: * @param interactionParams
0161: * @return
0162: */
0163: public static PerformBlockingInteraction createPerformBlockingInteraction(
0164: PortletContext portletContext,
0165: RuntimeContext runtimeContext, MarkupParams markupParams,
0166: InteractionParams interactionParams) {
0167: ParameterValidation.throwIllegalArgExceptionIfNull(
0168: portletContext, "PortletContext");
0169: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0170: portletContext.getPortletHandle(), "portlet handle",
0171: "PortletContext");
0172: ParameterValidation.throwIllegalArgExceptionIfNull(
0173: runtimeContext, "RuntimeContext");
0174: ParameterValidation.throwIllegalArgExceptionIfNull(
0175: markupParams, "MarkupParams");
0176: ParameterValidation.throwIllegalArgExceptionIfNull(
0177: interactionParams, "InteractionParams");
0178:
0179: return new PerformBlockingInteraction(null, portletContext,
0180: runtimeContext, null, markupParams, interactionParams);
0181: }
0182:
0183: /**
0184: * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
0185: * desiredLocales(xsd:string)*
0186: *
0187: * @param registrationContext
0188: * @param portletHandle handle for the PortletContext
0189: * @return
0190: * @since 2.4.1
0191: */
0192: public static GetPortletDescription createGetPortletDescription(
0193: RegistrationContext registrationContext,
0194: String portletHandle) {
0195: return new GetPortletDescription(registrationContext,
0196: createPortletContext(portletHandle), null, null);
0197: }
0198:
0199: /**
0200: * @param registrationContext
0201: * @param portletContext
0202: * @return
0203: * @since 2.6
0204: */
0205: public static GetPortletDescription createGetPortletDescription(
0206: RegistrationContext registrationContext,
0207: org.jboss.portal.portlet.PortletContext portletContext) {
0208: ParameterValidation.throwIllegalArgExceptionIfNull(
0209: portletContext, "portlet context");
0210: PortletContext wsrpPC = createPortletContext(portletContext
0211: .getId(), portletContext.getState());
0212: return new GetPortletDescription(registrationContext, wsrpPC,
0213: null, null);
0214: }
0215:
0216: /**
0217: * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
0218: * desiredLocales(xsd:string)*
0219: *
0220: * @param registrationContext
0221: * @param portletContext
0222: * @return
0223: * @since 2.4.1
0224: */
0225: public static GetPortletProperties createGetPortletProperties(
0226: RegistrationContext registrationContext,
0227: PortletContext portletContext) {
0228: ParameterValidation.throwIllegalArgExceptionIfNull(
0229: portletContext, "PortletContext");
0230: return new GetPortletProperties(registrationContext,
0231: portletContext, null, null);
0232: }
0233:
0234: /** ====== WSRP Response objects ====== **/
0235:
0236: /**
0237: * ( updateResponse(UpdateResponse) | redirectURL(xsd:string) ), extensions(Extension)*
0238: *
0239: * @return
0240: */
0241: public static BlockingInteractionResponse createBlockingInteractionResponse(
0242: UpdateResponse updateResponse) {
0243: if (updateResponse == null) {
0244: throw new IllegalArgumentException(
0245: "BlockingInteractionResponse requires either an UpdateResponse or a redirect URL.");
0246: }
0247: return new BlockingInteractionResponse(updateResponse, null,
0248: null);
0249: }
0250:
0251: /**
0252: * ( updateResponse(UpdateResponse) | redirectURL(xsd:string) ), extensions(Extension)*
0253: *
0254: * @return
0255: */
0256: public static BlockingInteractionResponse createBlockingInteractionResponse(
0257: String redirectURL) {
0258: if (redirectURL == null || redirectURL.length() == 0) {
0259: throw new IllegalArgumentException(
0260: "BlockingInteractionResponse requires either an UpdateResponse or a redirect URL.");
0261: }
0262: return new BlockingInteractionResponse(null, redirectURL, null);
0263: }
0264:
0265: /**
0266: * sessionContext(SessionContext)?, portletContext(PortletContext)?, markupContext(MarkupContext)?,
0267: * navigationalState(xsd:string)? newWindowState(xsd:string)?, newMode(xsd:string)?
0268: *
0269: * @return
0270: */
0271: public static UpdateResponse createUpdateResponse() {
0272: return new UpdateResponse();
0273: }
0274:
0275: /**
0276: * portletHandle(xsd:string), markupTypes(MarkupType)+, groupID(xsd:string)?, description(LocalizedString)?,
0277: * shortTitle(LocalizedString)?, title(LocalizedString)?, displayName(LocalizedString)?, keywords(LocalizedString)*,
0278: * userCategories(xsd:string)*, userProfileItems(xsd:string)*, usesMethodGet(xsd:boolean[false])?,
0279: * defaultMarkupSecure(xsd:boolean[false])?, onlySecure(xsd:boolean[false])?, userContextStoredInSession(xsd:boolean[false])?,
0280: * templatesStoredInSession(xsd:boolean[false])?, hasUserSpecificState(xsd:boolean[false])?,
0281: * doesUrlTemplateProcessing(xsd:boolean[false])?, extensions(Extension)*
0282: *
0283: * @return
0284: */
0285: public static PortletDescription createPortletDescription(
0286: String portletHandle, MarkupType[] markupTypes) {
0287: checkPortletHandle(portletHandle);
0288:
0289: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0290: markupTypes, "MarkupType");
0291:
0292: PortletDescription portletDescription = new PortletDescription();
0293: portletDescription.setPortletHandle(portletHandle);
0294: portletDescription.setMarkupTypes(markupTypes);
0295: return portletDescription;
0296: }
0297:
0298: private static void checkPortletHandle(String portletHandle) {
0299: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0300: portletHandle, "portlet handle", "PortletDescription");
0301: if (portletHandle.length() > 255) {
0302: throw new IllegalArgumentException(
0303: "Portlet handles must be less than 255 characters long. Was "
0304: + portletHandle.length() + " long.");
0305: }
0306: }
0307:
0308: /**
0309: * Same as createMarkupParams(false, {@link WSRPConstants#DEFAULT_LOCALES}, {@link WSRPConstants#DEFAULT_MIME_TYPES},
0310: * {@link WSRPConstants#VIEW_MODE}, {@link WSRPConstants#NORMAL_WINDOW_STATE})
0311: *
0312: * @return
0313: */
0314: public static MarkupParams createDefaultMarkupParams() {
0315: return createMarkupParams(false, WSRPConstants.DEFAULT_LOCALES,
0316: WSRPConstants.DEFAULT_MIME_TYPES,
0317: WSRPConstants.VIEW_MODE,
0318: WSRPConstants.NORMAL_WINDOW_STATE);
0319: }
0320:
0321: /**
0322: * secureClientCommunication(xsd:boolean), locales(xsd:string)+, mimeTypes(xsd:string)+, mode(xsd:string),
0323: * windowState(xsd:string), clientData({@link org.jboss.portal.wsrp.core.ClientData})?,
0324: * navigationalState(xsd:string)?, markupCharacterSets(xsd:string)*, validateTag(xsd:string)?,
0325: * validNewModes(xsd:string)*, validNewWindowStates(xsd:string)*, extensions({@link
0326: * org.jboss.portal.wsrp.core.Extension})*
0327: *
0328: * @return
0329: */
0330: public static MarkupParams createMarkupParams(
0331: boolean secureClientCommunication, String[] locales,
0332: String[] mimeTypes, String mode, String windowState) {
0333: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0334: locales, "locales");
0335: ParameterValidation.throwIllegalArgExceptionIfNull(mimeTypes,
0336: "MIME types");
0337: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mode,
0338: "mode", "MarkupParams");
0339: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0340: windowState, "window state", "MarkupParams");
0341:
0342: return new MarkupParams(secureClientCommunication, locales,
0343: mimeTypes, mode, windowState, null, null, null, null,
0344: null, null, null);
0345: }
0346:
0347: /**
0348: * Same as createRuntimeContext({@link WSRPConstants#NONE_USER_AUTHENTICATION})
0349: *
0350: * @return
0351: */
0352: public static RuntimeContext createDefaultRuntimeContext() {
0353: return createRuntimeContext(WSRPConstants.NONE_USER_AUTHENTICATION);
0354: }
0355:
0356: /**
0357: * userAuthentication(xsd:string), portletInstanceKey(xsd:string)?, namespacePrefix(xsd:string)?,
0358: * templates(Templates)?, sessionID(xsd:string)?, extensions(Extension)*
0359: *
0360: * @return
0361: */
0362: public static RuntimeContext createRuntimeContext(
0363: String userAuthentication) {
0364: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0365: userAuthentication, "user authentication",
0366: "RuntimeContext");
0367:
0368: RuntimeContext runtimeContext = new RuntimeContext();
0369: runtimeContext.setUserAuthentication(userAuthentication);
0370: return runtimeContext;
0371: }
0372:
0373: /**
0374: * portletHandle(xsd:string), portletState(xsd:base64Binary)?, extensions({@link
0375: * org.jboss.portal.wsrp.core.Extension})*
0376: *
0377: * @param portletHandle
0378: * @return
0379: */
0380: public static PortletContext createPortletContext(
0381: String portletHandle) {
0382: checkPortletHandle(portletHandle);
0383:
0384: PortletContext portletContext = new PortletContext();
0385: portletContext.setPortletHandle(portletHandle);
0386: return portletContext;
0387: }
0388:
0389: /**
0390: * @param portletHandle
0391: * @param portletState
0392: * @return
0393: * @since 2.6
0394: */
0395: public static PortletContext createPortletContext(
0396: String portletHandle, byte[] portletState) {
0397: PortletContext pc = createPortletContext(portletHandle);
0398: pc.setPortletState(portletState);
0399: return pc;
0400: }
0401:
0402: /**
0403: * Same as createInteractionParams(StateChange.readOnly)
0404: *
0405: * @return
0406: */
0407: public static InteractionParams createDefaultInteractionParams() {
0408: return createInteractionParams(StateChange.readOnly);
0409: }
0410:
0411: /**
0412: * portletStateChange({@link StateChange}), interactionState(xsd:string)?, formParameters(NamedString)*,
0413: * uploadContexts(UploadContext)*, extensions(Extension)*
0414: *
0415: * @return
0416: */
0417: public static InteractionParams createInteractionParams(
0418: StateChange portletStateChange) {
0419: ParameterValidation.throwIllegalArgExceptionIfNull(
0420: portletStateChange, "portletStateChange");
0421:
0422: InteractionParams interactionParams = new InteractionParams();
0423: interactionParams.setPortletStateChange(portletStateChange);
0424: return interactionParams;
0425: }
0426:
0427: /**
0428: * registrationContext(RegistrationContext)?
0429: *
0430: * @param registrationContext
0431: * @return
0432: */
0433: public static InitCookie createInitCookie(
0434: RegistrationContext registrationContext) {
0435: return new InitCookie(registrationContext);
0436: }
0437:
0438: /**
0439: * requiresRegistration(xsd:boolean), offeredPortlets(PortletDescription)*, userCategoryDescriptions(ItemDescription)*,
0440: * customUserProfileItemDescriptions(ItemDescription)*, customWindowStateDescriptions(ItemDescription)*,
0441: * customModeDescriptions(ItemDescription)*, requiresInitCookie(CookieProtocol[none])?,
0442: * registrationPropertyDescription(ModelDescription)?, locales(xsd:string)*, resourceList(ResourceList)?,
0443: * extensions(Extension)*
0444: *
0445: * @return
0446: */
0447: public static ServiceDescription createServiceDescription(
0448: boolean requiresRegistration) {
0449: ServiceDescription serviceDescription = new ServiceDescription();
0450: serviceDescription
0451: .setRequiresRegistration(requiresRegistration);
0452: return serviceDescription;
0453: }
0454:
0455: /**
0456: * markupContext(MarkupContext), sessionContext(SessionContext)?, extensions(Extension)*
0457: *
0458: * @return
0459: */
0460: public static MarkupResponse createMarkupResponse(
0461: MarkupContext markupContext) {
0462: ParameterValidation.throwIllegalArgExceptionIfNull(
0463: markupContext, "MarkupContext");
0464:
0465: return new MarkupResponse(markupContext, null, null);
0466: }
0467:
0468: /**
0469: * mimeType: The mime type of the returned markup. The mimeType field MUST be specified whenever markup is returned,
0470: * and if the markupBinary field is used to return the markup, the mime type MUST include the character set for
0471: * textual mime types using the syntax specified in RFC1522[14] (e.g. "text/html; charset=UTF-8"). In this particular
0472: * case this character set MAY be different than the response message.
0473: * <p/>
0474: * useCachedMarkup(xsd:boolean[false])?, mimeType(xsd:string)?, (markupString(xsd:string) |
0475: * markupBinary(xsd:base64Binary)), locale(xsd:string)?, requiresUrlRewriting(xsd:boolean[false])?,
0476: * cacheControl(CacheControl)?, preferredTitle(xsd:string)?, extensions(Extension)*
0477: *
0478: * @return
0479: */
0480: public static MarkupContext createMarkupContext(String mimeType,
0481: String markupString) {
0482: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0483: mimeType, "MIME type", "MarkupContext");
0484: if (markupString == null) {
0485: throw new IllegalArgumentException(
0486: "MarkupContext requires either a non-null markup string or binary markup.");
0487: }
0488: return new MarkupContext(Boolean.FALSE, mimeType, markupString,
0489: null, null, Boolean.FALSE, null, null, null);
0490: }
0491:
0492: /**
0493: * useCachedMarkup(xsd:boolean[false])?, mimeType(xsd:string)?, (markupString(xsd:string) |
0494: * markupBinary(xsd:base64Binary)), locale(xsd:string)?, requiresUrlRewriting(xsd:boolean[false])?,
0495: * cacheControl(CacheControl)?, preferredTitle(xsd:string)?, extensions(Extension)*
0496: *
0497: * @param mimeType The mime type of the returned markup. The mimeType field MUST be specified whenever markup is
0498: * returned, and if the markupBinary field is used to return the markup, the mime type MUST include
0499: * the character set for textual mime types using the syntax specified in RFC1522[14] (e.g.
0500: * "text/html; charset=UTF-8"). In this particular case this character set MAY be different than the
0501: * response message.
0502: * @return a new MarkupContext
0503: */
0504: public static MarkupContext createMarkupContext(String mimeType,
0505: byte[] markupBinary) {
0506: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0507: mimeType, "MIME type", "MarkupContext");
0508: if (markupBinary == null || markupBinary.length == 0) {
0509: throw new IllegalArgumentException(
0510: "MarkupContext requires either a non-null markup string or binary markup.");
0511: }
0512: return new MarkupContext(Boolean.FALSE, mimeType, null,
0513: markupBinary, null, Boolean.FALSE, null, null, null);
0514: }
0515:
0516: /**
0517: * sessionID(xsd:string), expires(xsd:int), extensions(Extension)*
0518: *
0519: * @param sessionID An opaque string the Portlet defines for referencing state that is stored locally on the
0520: * Producer. The maximum length of a sessionID is 4096 characters,
0521: * @param expires Maximum number of seconds between invocations referencing the sessionID before the Producer will
0522: * schedule releasing the related resources. A value of -1 indicates that the sessionID will never
0523: * expire.
0524: * @return a new SessionContext
0525: */
0526: public static SessionContext createSessionContext(String sessionID,
0527: int expires) {
0528: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0529: sessionID, "session Id", "SessionContext");
0530: if (expires < 0) {
0531: throw new IllegalArgumentException(
0532: "SessionContext requires a positive expiration time.");
0533: }
0534: return new SessionContext(sessionID, expires, null);
0535: }
0536:
0537: /**
0538: * For UserProfile and related classes, everything is optional so no need to have factory methods.
0539: * <p/>
0540: * userContextKey(xsd:string), userCategories(xsd:string)*, profile(UserProfile)?, extensions(Extension)*
0541: *
0542: * @return
0543: */
0544: public static UserContext createUserContext(String userContextKey) {
0545: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0546: userContextKey, "user context key", "UserContext");
0547: return new UserContext(userContextKey, null, null, null);
0548: }
0549:
0550: /**
0551: * consumerName(xsd:string), consumerAgent(xsd:string), methodGetSupported(xsd:boolean), consumerModes(xsd:string)*,
0552: * consumerWindowStates(xsd:string)*, consumerUserScopes(xsd:string)*, customUserProfileData(xsd:string)*,
0553: * registrationProperties(Property)*, extensions(Extension)*
0554: *
0555: * @param consumerName A name (preferably unique) that identifies the Consumer [R355] An example of such a name
0556: * would be the Consumer's URL.
0557: * @param methodGetSupported A flag that tells the Producer whether the Consumer has implemented portlet URLs
0558: * (regardless of whether they are written through Consumer URL rewriting or Producer URL
0559: * writing, see [Section 10.2]) in a manner that supports HTML markup containing forms with
0560: * method="get".
0561: * @return
0562: */
0563: public static RegistrationData createRegistrationData(
0564: String consumerName, boolean methodGetSupported) {
0565: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0566: consumerName, "consumer name", "RegistrationData");
0567: RegistrationData regData = createDefaultRegistrationData();
0568: regData.setConsumerName(consumerName);
0569: regData.setMethodGetSupported(methodGetSupported);
0570: return regData;
0571: }
0572:
0573: /**
0574: * Same as createRegistrationData({@link WSRPConstants#DEFAULT_CONSUMER_NAME}, false) using {@link
0575: * WSRPConstants#CONSUMER_AGENT} for the consumer agent.
0576: *
0577: * @return
0578: * @since 2.4.1
0579: */
0580: public static RegistrationData createDefaultRegistrationData() {
0581: return new RegistrationData(
0582: WSRPConstants.DEFAULT_CONSUMER_NAME,
0583: WSRPConstants.CONSUMER_AGENT, false, null, null, null,
0584: null, null, null);
0585: }
0586:
0587: /**
0588: * ( stringValue(xsd:string) | any* ), @name(xsd:string), @xml:lang
0589: *
0590: * @return
0591: */
0592: public static Property createProperty(String name, String lang,
0593: String stringValue) {
0594: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name,
0595: "name", "Property");
0596: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(lang,
0597: "language", "Property");
0598: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0599: stringValue, "String value", "Property");
0600:
0601: return new Property(name, lang, stringValue, null);
0602: }
0603:
0604: private static final ActionURL ACTION_URL = new ActionURL() {
0605: public StateString getInteractionState() {
0606: return StateString
0607: .createFrom(WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0608: + WSRPRewritingConstants.INTERACTION_STATE
0609: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
0610: }
0611:
0612: public StateString getNavigationalState() {
0613: return StateString
0614: .createFrom(WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0615: + WSRPRewritingConstants.NAVIGATIONAL_STATE
0616: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
0617: }
0618:
0619: public Mode getMode() {
0620: return Mode
0621: .create(
0622: WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0623: + WSRPRewritingConstants.MODE
0624: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE,
0625: true);
0626: }
0627:
0628: public WindowState getWindowState() {
0629: return WindowState
0630: .create(
0631: WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0632: + WSRPRewritingConstants.WINDOW_STATE
0633: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE,
0634: true);
0635: }
0636: };
0637:
0638: private static final RenderURL RENDER_URL = new RenderURL() {
0639: public StateString getNavigationalState() {
0640: return StateString
0641: .createFrom(WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0642: + WSRPRewritingConstants.NAVIGATIONAL_STATE
0643: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
0644: }
0645:
0646: public Mode getMode() {
0647: return Mode
0648: .create(
0649: WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0650: + WSRPRewritingConstants.MODE
0651: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE,
0652: true);
0653: }
0654:
0655: public WindowState getWindowState() {
0656: return WindowState
0657: .create(
0658: WSRPRewritingConstants.REWRITE_PARAMETER_OPEN
0659: + WSRPRewritingConstants.WINDOW_STATE
0660: + WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE,
0661: true);
0662: }
0663: };
0664:
0665: /**
0666: * defaultTemplate(xsd:string)?, blockingActionTemplate(xsd:string)?, renderTemplate(xsd:string)?,
0667: * resourceTemplate(xsd:string)?, secureDefaultTemplate(xsd:string)?, secureBlockingActionTemplate(xsd:string)?,
0668: * secureRenderTemplate(xsd:string)?, secureResourceTemplate(xsd:string)?, extensions(Extension)*
0669: *
0670: * @param context
0671: * @return
0672: */
0673: public static Templates createTemplates(
0674: PortletInvocationContext context) {
0675: Templates templates = new Templates();
0676:
0677: templates.setBlockingActionTemplate(createTemplate(context,
0678: ACTION_URL, Boolean.FALSE));
0679: templates.setRenderTemplate(createTemplate(context, RENDER_URL,
0680: Boolean.FALSE));
0681: templates.setSecureBlockingActionTemplate(createTemplate(
0682: context, ACTION_URL, Boolean.TRUE));
0683: templates.setSecureRenderTemplate(createTemplate(context,
0684: RENDER_URL, Boolean.TRUE));
0685:
0686: //fix-me: deal with resources properly, create fake ones for now
0687: templates
0688: .setResourceTemplate(WSRPRewritingConstants.FAKE_RESOURCE_URL);
0689: templates
0690: .setSecureResourceTemplate(WSRPRewritingConstants.FAKE_RESOURCE_URL);
0691:
0692: return templates;
0693: }
0694:
0695: private static String createTemplate(
0696: PortletInvocationContext context, PortletURL url,
0697: Boolean secure) {
0698: String template = context.renderURL(url, secure, null, true);
0699: template = Tools.replace(template,
0700: WSRPRewritingConstants.ENC_OPEN,
0701: WSRPRewritingConstants.REWRITE_PARAMETER_OPEN);
0702: template = Tools.replace(template,
0703: WSRPRewritingConstants.ENC_CLOSE,
0704: WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
0705: return template;
0706: }
0707:
0708: /**
0709: * userAgent(xsd:string)?, extensions(Extension)*
0710: *
0711: * @param userAgent
0712: * @return
0713: */
0714: public static ClientData createClientData(String userAgent) {
0715: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0716: userAgent, "user agent", "ClientData");
0717: return new ClientData(userAgent, null);
0718: }
0719:
0720: /**
0721: * expires(xsd:int), userScope(xsd:string), validateTag(xsd:string)?, extensions(Extension)*
0722: *
0723: * @param expires Number of seconds the markup fragment referenced by this cache control entry remains valid. A
0724: * value of -1 indicates that the markup fragment will never expire.
0725: * @param userScope
0726: * @return
0727: */
0728: public static CacheControl createCacheControl(int expires,
0729: String userScope) {
0730: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0731: userScope, "user scope", "CacheControl");
0732: if (expires < -1) {
0733: throw new IllegalArgumentException(
0734: "Cache expiration time must be greater than -1, "
0735: + "-1 indicating that the cache will never expire.");
0736: }
0737:
0738: return new CacheControl(expires, userScope, null, null);
0739: }
0740:
0741: /**
0742: * registrationHandle(xsd:string), registrationState(xsd:base64Binary)?, extensions(Extension)*
0743: *
0744: * @param registrationHandle
0745: * @return
0746: * @since 2.4.1
0747: */
0748: public static RegistrationContext createRegistrationContext(
0749: String registrationHandle) {
0750: ParameterValidation.throwIllegalArgExceptionIfNull(
0751: registrationHandle, "Registration handle");
0752: return new RegistrationContext(registrationHandle, null, null);
0753: }
0754:
0755: /**
0756: * propertyDescriptions(PropertyDescription)*, modelTypes(ModelTypes)?, extensions(Extension)*
0757: *
0758: * @return
0759: * @since 2.6
0760: */
0761: public static ModelDescription createModelDescription(
0762: PropertyDescription[] propertyDescriptions) {
0763: return new ModelDescription(propertyDescriptions, null, null);
0764: }
0765:
0766: /**
0767: * label(LocalizedString)?, hint(LocalizedString)?, extensions(Extension)*, @name(xsd:string), @type(xsd:QName)
0768: *
0769: * @return
0770: * @since 2.6
0771: */
0772: public static PropertyDescription createPropertyDescription(
0773: String name, QName type) {
0774: ParameterValidation.throwIllegalArgExceptionIfNull(name,
0775: "PropertyDescription name");
0776: ParameterValidation.throwIllegalArgExceptionIfNull(type,
0777: "PropertyDescription type");
0778: return new PropertyDescription(name, type, null, null, null);
0779: }
0780:
0781: /**
0782: * value(xsd:string), @xml:lang, @resourceName(xsd:string)?
0783: *
0784: * @return
0785: * @since 2.6
0786: */
0787: public static LocalizedString createLocalizedString(String lang,
0788: String resourceName, String value) {
0789: ParameterValidation.throwIllegalArgExceptionIfNull(lang,
0790: "LocalizedString language");
0791: ParameterValidation.throwIllegalArgExceptionIfNull(value,
0792: "LocalizedString value");
0793: return new LocalizedString(lang, resourceName, value);
0794: }
0795:
0796: /**
0797: * Same as createLocalizedString("en", null, value)
0798: *
0799: * @param value
0800: * @return
0801: * @since 2.6
0802: */
0803: public static LocalizedString createLocalizedString(String value) {
0804: return createLocalizedString("en", null, value);
0805: }
0806:
0807: /**
0808: * portletDescription(PortletDescription), resourceList(ResourceList)?, extensions(Extension)*
0809: *
0810: * @param portletDescription
0811: * @return
0812: * @since 2.6
0813: */
0814: public static PortletDescriptionResponse createPortletDescriptionResponse(
0815: PortletDescription portletDescription) {
0816: ParameterValidation.throwIllegalArgExceptionIfNull(
0817: portletDescription, "PortletDescription");
0818: return new PortletDescriptionResponse(portletDescription, null,
0819: null);
0820: }
0821:
0822: /**
0823: * modelDescription(ModelDescription)?, resourceList(ResourceList)?, extensions(Extension)*
0824: *
0825: * @param propertyDescriptions
0826: * @return
0827: * @since 2.6
0828: */
0829: public static PortletPropertyDescriptionResponse createPortletPropertyDescriptionResponse(
0830: PropertyDescription[] propertyDescriptions) {
0831: ModelDescription modelDescription = propertyDescriptions == null ? null
0832: : createModelDescription(propertyDescriptions);
0833: return new PortletPropertyDescriptionResponse(modelDescription,
0834: null, null);
0835: }
0836:
0837: /**
0838: * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
0839: * desiredLocales(xsd:string)*
0840: *
0841: * @return
0842: * @since 2.6
0843: */
0844: public static GetPortletPropertyDescription createGetPortletPropertyDescription(
0845: RegistrationContext registrationContext,
0846: PortletContext portletContext, UserContext userContext,
0847: String[] desiredLocales) {
0848: ParameterValidation.throwIllegalArgExceptionIfNull(
0849: portletContext, "PortletContext");
0850: return new GetPortletPropertyDescription(registrationContext,
0851: portletContext, userContext, desiredLocales);
0852: }
0853:
0854: /**
0855: * Same as createGetPortletPropertyDescription(null, createPortletContext(portletHandle), null, null)
0856: *
0857: * @param portletHandle
0858: * @return
0859: * @since 2.6
0860: */
0861: public static GetPortletPropertyDescription createSimpleGetPortletPropertyDescription(
0862: String portletHandle) {
0863: return createGetPortletPropertyDescription(null,
0864: createPortletContext(portletHandle), null, null);
0865: }
0866:
0867: /**
0868: * portletHandle(xsd:string), reason(xsd:string)
0869: *
0870: * @param portletHandle
0871: * @param reason
0872: * @return
0873: * @since 2.6
0874: */
0875: public static DestroyFailed createDestroyFailed(
0876: String portletHandle, String reason) {
0877: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0878: portletHandle, "Portlet handle", "DestroyFailed");
0879: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0880: reason, "Reason for failure", "DestroyFailed");
0881: // todo: check reason should be a fault code from Section 13 of spec but this is not clear...
0882: return new DestroyFailed(portletHandle, reason);
0883: }
0884:
0885: /**
0886: * destroyFailed(DestroyFailed)*, extensions(Extension)*
0887: *
0888: * @param destroyFailed
0889: * @return
0890: * @since 2.6
0891: */
0892: public static DestroyPortletsResponse createDestroyPortletsResponse(
0893: DestroyFailed[] destroyFailed) {
0894: return new DestroyPortletsResponse(destroyFailed, null);
0895: }
0896:
0897: /**
0898: * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
0899: * propertyList(PropertyList)
0900: *
0901: * @param portletContext
0902: * @param propertyList
0903: * @return
0904: * @since 2.6
0905: */
0906: public static SetPortletProperties createSetPortletProperties(
0907: RegistrationContext registrationContext,
0908: PortletContext portletContext, PropertyList propertyList) {
0909: ParameterValidation.throwIllegalArgExceptionIfNull(
0910: portletContext, "PortletContext");
0911: ParameterValidation.throwIllegalArgExceptionIfNull(
0912: propertyList, "PropertyList");
0913:
0914: return new SetPortletProperties(registrationContext,
0915: portletContext, null, propertyList);
0916: }
0917:
0918: /**
0919: * same as createClonePortlet(null, createPortletContext(portletHandle), null)
0920: *
0921: * @param portletHandle
0922: * @return
0923: * @since 2.6
0924: */
0925: public static ClonePortlet createSimpleClonePortlet(
0926: String portletHandle) {
0927: return createClonePortlet(null,
0928: createPortletContext(portletHandle), null);
0929: }
0930:
0931: /**
0932: * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?
0933: *
0934: * @return
0935: * @since 2.6
0936: */
0937: public static ClonePortlet createClonePortlet(
0938: RegistrationContext registrationContext,
0939: PortletContext portletContext, UserContext userContext) {
0940: ParameterValidation.throwIllegalArgExceptionIfNull(
0941: portletContext, "PortletContext");
0942: return new ClonePortlet(registrationContext, portletContext,
0943: userContext);
0944: }
0945:
0946: /**
0947: * registrationContext(RegistrationContext)?, portletHandles(xsd:string)+
0948: *
0949: * @return
0950: * @since 2.6
0951: */
0952: public static DestroyPortlets createDestroyPortlets(
0953: RegistrationContext registrationContext,
0954: String[] portletHandles) {
0955: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0956: portletHandles, "Portlet handles");
0957: return new DestroyPortlets(registrationContext, portletHandles);
0958: }
0959:
0960: /**
0961: * properties(Property)*, resetProperties(ResetProperty)*, extensions(Extension)*
0962: *
0963: * @return
0964: * @since 2.6
0965: */
0966: public static PropertyList createPropertyList() {
0967: return new PropertyList();
0968: }
0969:
0970: /**
0971: * EMPTY, @name(xsd:string)
0972: *
0973: * @param name
0974: * @return
0975: * @since 2.6
0976: */
0977: public static ResetProperty createResetProperty(String name) {
0978: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name,
0979: "Property name", "ResetProperty");
0980:
0981: return new ResetProperty(name);
0982: }
0983:
0984: /**
0985: * registrationContext(RegistrationContext)?, sessionIDs(xsd:string)*
0986: *
0987: * @return
0988: * @since 2.6
0989: */
0990: public static ReleaseSessions createReleaseSessions(
0991: RegistrationContext registrationContext, String[] sessionIDs) {
0992: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
0993: sessionIDs, "Session IDs");
0994:
0995: return new ReleaseSessions(registrationContext, sessionIDs);
0996: }
0997:
0998: /**
0999: * registrationContext(RegistrationContext)?, registrationData(RegistrationData)
1000: *
1001: * @return
1002: * @since 2.6
1003: */
1004: public static ModifyRegistration createModifyRegistration(
1005: RegistrationContext registrationContext,
1006: RegistrationData registrationData) {
1007: ParameterValidation.throwIllegalArgExceptionIfNull(
1008: registrationData, "RegistrationData");
1009:
1010: return new ModifyRegistration(registrationContext,
1011: registrationData);
1012: }
1013:
1014: /**
1015: * mimeType(xsd:string), uploadData(xsd:base64Binary), mimeAttributes(NamedString)*, extensions(Extension)*
1016: *
1017: * @param mimeType
1018: * @param uploadData
1019: * @return
1020: * @since 2.6.2
1021: */
1022: public static UploadContext createUploadContext(String mimeType,
1023: byte[] uploadData) {
1024: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
1025: mimeType, "MIME Type", "UploadContext");
1026: if (uploadData == null || uploadData.length == 0) {
1027: throw new IllegalArgumentException(
1028: "Must pass non-null, non-empty upload data");
1029: }
1030:
1031: return new UploadContext(mimeType, uploadData, null, null);
1032: }
1033: }
|