internal void WriteMetadata(HttpContext context, ODataRequest req) { var content = ODataHandler.LoadContentByVersionRequest(req.RepositoryPath); if (content == null) { ODataHandler.ResourceNotFound(); return; } var isRoot = content.ContentType.IsInstaceOfOrDerivedFrom("Site"); if (isRoot) { MetaGenerator.WriteMetadata(context.Response.Output, this); } else { MetaGenerator.WriteMetadata(context.Response.Output, this, content, req.IsCollection); } var mimeType = this.MimeType; if (mimeType != null) { context.Response.ContentType = mimeType; } }
//----------------------------------------------------------------------------------------------------------------------------------- operations /// <summary> /// Handles GET operations. Parameters come from the URL or the request stream. /// </summary> /// <param name="portalContext"></param> /// <param name="odataReq"></param> internal void WriteOperationResult(PortalContext portalContext, ODataRequest odataReq) { object response = null; var content = ODataHandler.LoadContentByVersionRequest(odataReq.RepositoryPath); if (content == null) { throw new ContentNotFoundException(string.Format(SNSR.GetString("$Action,ErrorContentNotFound"), odataReq.RepositoryPath)); } var action = ODataHandler.ActionResolver.GetAction(content, odataReq.Scenario, odataReq.PropertyName, null, null); if (action == null) { // check if this is a versioning action (e.g. a checkout) SavingAction.AssertVersioningAction(content, odataReq.PropertyName, true); throw new InvalidContentActionException(InvalidContentActionReason.UnknownAction, content.Path); } if (!action.IsODataOperation) { throw new ODataException("Not an OData operation.", ODataExceptionCode.IllegalInvoke); } if (action.CausesStateChange) { throw new ODataException("OData action cannot be invoked with HTTP GET.", ODataExceptionCode.IllegalInvoke); } if (action.Forbidden || (action.GetApplication() != null && !action.GetApplication().Security.HasPermission(PermissionType.RunApplication))) { throw new InvalidContentActionException("Forbidden action: " + odataReq.PropertyName); } var parameters = GetOperationParameters(action, portalContext.OwnerHttpContext.Request); response = action.Execute(content, parameters); var responseAsContent = response as Content; if (responseAsContent != null) { WriteSingleContent(responseAsContent, portalContext); return; } int count; response = ProcessOperationResponse(response, portalContext, odataReq, out count); //Write(response, portalContext); WriteOperationResult(response, portalContext, odataReq, count); }
internal void WriteContentProperty(String path, string propertyName, bool rawValue, PortalContext portalContext, ODataRequest req) { var content = ODataHandler.LoadContentByVersionRequest(path); if (content == null) { ODataHandler.ContentNotFound(portalContext.OwnerHttpContext, path); return; } if (propertyName == ODataHandler.PROPERTY_ACTIONS) { var backUrl = portalContext.BackUrl; //Get actions without back url: let the client append the back parameter, //as we are in a service here that does not know about the redirect url. var snActions = ODataHandler.ActionResolver.GetActions(content, req.Scenario, string.IsNullOrEmpty(backUrl) ? null : backUrl); var actions = snActions.Where(a => a.IsHtmlOperation).Select(a => new ODataActionItem { Name = a.Name, DisplayName = SNSR.GetString(a.Text), Icon = a.Icon, Index = a.Index, Url = a.Uri, IncludeBackUrl = a.GetApplication() == null ? 0 : (int)a.GetApplication().IncludeBackUrl, ClientAction = a is ClientAction && !string.IsNullOrEmpty(((ClientAction)a).Callback), Forbidden = a.Forbidden }); WriteActionsProperty(portalContext, actions.ToArray(), rawValue); return; } Field field; if (content.Fields.TryGetValue(propertyName, out field)) { var refField = field as ReferenceField; if (refField != null) { var refFieldSetting = refField.FieldSetting as ReferenceFieldSetting; var isMultiRef = true; if (refFieldSetting != null) { isMultiRef = refFieldSetting.AllowMultiple == true; } if (isMultiRef) { WriteMultiRefContents(refField.GetData(), portalContext, req); } else { WriteSingleRefContent(refField.GetData(), portalContext); } } else if (!rawValue) { WriteSingleContent(portalContext, new Dictionary <string, object> { { propertyName, field.GetData() } }); } else { WriteRaw(field.GetData(), portalContext); } } else { //ResourceNotFound(content, propertyName); WriteOperationResult(portalContext, req); } }
//----------------------------------------------------------------------------------------------------------------------------------- contents internal void WriteSingleContent(String path, PortalContext portalContext) { WriteSingleContent(ODataHandler.LoadContentByVersionRequest(path), portalContext); }