/// <summary> /// Validates the incoming request. /// </summary> /// <param name="context">The HttpContext for the incoming HTTP request.</param> /// <param name="errorMessage">The HTTP Status Code if the request is invalid.</param> /// <returns>True if the request is valid, False otherwise.</returns> public override bool ValidateRequest(HttpContext context, out string errorMessage) { // Verify that type of request is edit member or edit media request. AtomPubRequestType requestType = AtomPubHelper.GetAtomPubRequestType(context, base.BaseUri); if (!(AtomPubRequestType.EditMember == requestType || AtomPubRequestType.EditMedia == requestType)) { errorMessage = Resources.ATOMPUB_INVALID_URL; return(false); } bool isAtomEntryType = AtomPubHelper.IsAtomEntryMediaType(context.Request.ContentType); if (requestType == AtomPubRequestType.EditMember && !isAtomEntryType) { errorMessage = Resources.ATOMPUB_UNSUPPORTED_CONTENT_TYPE; return(false); } // Get the requested member type and its id for verifying it existents. string collectionName = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.CollectionName); if (!string.IsNullOrEmpty(collectionName) && AtomPubHelper.IsValidCollectionType(collectionName)) { string memberId = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.Id); if (!string.IsNullOrEmpty(memberId) && AtomPubHelper.IsValidGuid(memberId)) { errorMessage = string.Empty; return(true); } else { errorMessage = Resources.ATOMPUB_INVALID_RESOURCE_ID; return(false); } } else { errorMessage = Resources.ATOMPUB_UNSUPPORTED_COLLECTION_NAME; return(false); } }
/// <summary> /// Create resource using metadata. /// </summary> /// <param name="dataSection">Metadata Section containing metadata of the resource.</param> /// <returns>A resource of type ScholarlyWork or its derived type.</returns> private static ScholarlyWork CreateResouceUsingMetsMetadata(MetadataSection dataSection) { if (null == dataSection) { throw new ArgumentNullException("dataSection"); } ScholarlyWork resource = null; Type resourceType = null; // Get the resource type specified in METS document. if (null != dataSection.DescriptiveMetadata && null != dataSection.DescriptiveMetadata.ResourceType && 0 < dataSection.DescriptiveMetadata.ResourceType.Count) { string resourceTypeName = dataSection.DescriptiveMetadata.ResourceType[0]; // Check if the resource type is derived from ScholarlyWork, // as Sword & AtomPub supports only ScholarlyWork and its derivatives. if (AtomPubHelper.IsValidCollectionType(resourceTypeName)) { resourceType = CoreHelper.GetSystemResourceType(resourceTypeName); } } // Take ScholarlyWork as default resource type. if (null == resourceType) { resourceType = typeof(ScholarlyWork); } // Create resource of type ScholarlyWork or its derived types. resource = Activator.CreateInstance(resourceType, false) as ScholarlyWork; if (null == resource) { throw new SwordException(Properties.Resources.UNSUPPORTED_RESOURCE_TYPE); } return(resource); }
/// <summary> /// Validates the request uri and returns the appropriate error message. /// If the request is valid, 'error' with empty string is returned. /// </summary> /// <param name="context">HttpContext containing the request object.</param> /// <param name="errorMessage">Contains the error message.</param> /// <returns>True if the request is valid, else false.</returns> public override bool ValidateRequest(HttpContext context, out string errorMessage) { bool isValid = false; AtomPubRequestType requestType = AtomPubHelper.GetAtomPubRequestType(context, base.BaseUri); switch (requestType) { case AtomPubRequestType.Collection: // Get collection name string collectionName = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.CollectionName); // If valid collection name, then proceed. if (!string.IsNullOrEmpty(collectionName) && AtomPubHelper.IsValidCollectionType(collectionName)) { errorMessage = string.Empty; isValid = true; } else { errorMessage = Properties.Resources.ATOMPUB_UNSUPPORTED_COLLECTION_NAME; isValid = false; } break; case AtomPubRequestType.Unknwon: default: errorMessage = Properties.Resources.ATOMPUB_INVALID_URL; isValid = false; break; } return(isValid); }
/// <summary> /// Gets all the resource types that inherit from ScholarlyWork, including ScholarlyWork. /// </summary> /// <returns>An array of strings containing the resource type names.</returns> string[] IAtomPubStoreReader.GetCollectionNames() { List <string> resourceTypes = new List <string>(); using (ZentityContext zentityContext = CoreHelper.CreateZentityContext()) { resourceTypes = new List <string>(); // Get all resource types which are derived from ScholarlyWork as // only ScholarlyWork type supports authors list. foreach (ResourceType typeInfo in CoreHelper.GetResourceTypes(zentityContext)) { if (AtomPubHelper.IsValidCollectionType(typeInfo.Name)) { resourceTypes.Add(typeInfo.Name); } } } return(resourceTypes .OrderBy(name => name) .ToArray()); }
/// <summary> /// Validates the request uri and returns the appropriate error message. /// If the request is valid, 'error' with empty string is returned. /// Following requests are considered as valid : /// 1. Service Document Uri /// 2. Collection Uri /// 3. Collection Uri for next / previous page /// 4. Member resource Uri /// 5. Media Entry resource Uri /// </summary> /// <param name="context">HttpContext containing the request object.</param> /// <param name="errorMessage">Contains the error message.</param> /// <returns>True if the request is valid, else false.</returns> public override bool ValidateRequest(HttpContext context, out string errorMessage) { errorMessage = string.Empty; AtomPubRequestType requestType = AtomPubHelper.GetAtomPubRequestType(context, base.BaseUri); if (AtomPubRequestType.Unknwon == requestType) { errorMessage = Resources.ATOMPUB_INVALID_URL; return(false); } // If ServiceDocument uri then no need of further validations. if (AtomPubRequestType.ServiceDocument == requestType) { return(true); } // Get collection name string collectionName = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.CollectionName); bool isValid = false; // If valid collection name, then proceed. if (!string.IsNullOrEmpty(collectionName) && AtomPubHelper.IsValidCollectionType(collectionName)) { switch (requestType) { case AtomPubRequestType.Collection: isValid = true; break; case AtomPubRequestType.CollectionWithPageNo: string strPageNo = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.PageNo); long pageNumber = 0; if (!long.TryParse(strPageNo, out pageNumber)) { errorMessage = Resources.ATOMPUB_INVALID_PAGE_NUMBER; } else { isValid = true; } break; case AtomPubRequestType.EditMember: case AtomPubRequestType.EditMedia: // Get the requested id for verify it is GUID string memberId = AtomPubHelper.GetValueOfParameterFromUri(context, base.BaseUri, AtomPubParameterType.Id); if (AtomPubHelper.IsValidGuid(memberId)) { isValid = true; } else { errorMessage = Resources.ATOMPUB_INVALID_RESOURCE_ID; } break; default: isValid = false; errorMessage = Resources.ATOMPUB_INVALID_URL; break; } } else { errorMessage = Resources.ATOMPUB_UNSUPPORTED_COLLECTION_NAME; } return(isValid); }