/// <summary> /// Sets the keyword filters using a list of keyword uri strings /// </summary> /// <param name="keywordUris"></param> public void SetKeywordFilters(List <String> keywordUris) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); List <Keyword> keywords = keywordUris.Select(kwUri => taxonomyFactory.GetTaxonomyKeyword(kwUri)).Where(kw => kw != null).ToList(); SetKeywordFilters(keywords); }
protected virtual void Dispose(bool isDisposed) { if (!isDisposed) { if (_taxonomyFactory != null) { _taxonomyFactory.Dispose(); _taxonomyFactory = null; } } }
protected virtual void Dispose(bool isDisposed) { if (isDisposed) { return; } if (_taxonomyFactory == null) { return; } _taxonomyFactory.Dispose(); _taxonomyFactory = null; }
/// <summary> /// Sets the keyword filters using a list of keyword uri strings /// </summary> /// <param name="keywordUris"></param> public void SetKeywordFilters(List<String> keywordUris) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); List<Keyword> keywords = new List<Keyword>(); foreach (string kwUri in keywordUris) { Keyword kw = taxonomyFactory.GetTaxonomyKeyword(kwUri); if (kw != null) { keywords.Add(kw); } } SetKeywordFilters(keywords); }
/// <summary> /// Gets a list of keyword objects based on their URIs /// </summary> /// <param name="keywordUris"></param> /// <returns></returns> public static List<Keyword> LoadKeywords(List<string> keywordUris) { List<Keyword> res = new List<Keyword>(); TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); foreach (string uri in keywordUris) { Keyword kw = taxonomyFactory.GetTaxonomyKeyword(uri); if (kw != null) { res.Add(kw); } } return res; }
/// <summary> /// Sets the keyword filters using a list of keyword uri strings /// </summary> /// <param name="keywordUris"></param> public void SetKeywordFilters(List <String> keywordUris) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); List <Keyword> keywords = new List <Keyword>(); foreach (string kwUri in keywordUris) { Keyword kw = taxonomyFactory.GetTaxonomyKeyword(kwUri); if (kw != null) { keywords.Add(kw); } } SetKeywordFilters(keywords); }
/// <summary> /// Gets a list of keyword objects based on their URIs /// </summary> /// <param name="keywordUris"></param> /// <returns></returns> public static List <Keyword> LoadKeywords(List <string> keywordUris) { List <Keyword> res = new List <Keyword>(); TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); foreach (string uri in keywordUris) { Keyword kw = taxonomyFactory.GetTaxonomyKeyword(uri); if (kw != null) { res.Add(kw); } } return(res); }
protected override IEnumerable <SitemapItem> ExpandDescendants(string keywordUri, string taxonomyUri, NavigationFilter filter, ILocalization localization) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); TaxonomyFilter taxonomyFilter = new DepthFilter(filter.DescendantLevels, DepthFilter.FilterDown); Keyword contextKeyword = taxonomyFactory.GetTaxonomyKeywords(taxonomyUri, taxonomyFilter, keywordUri); if (contextKeyword == null) { throw new TridionDocsApiException(); } TaxonomyNode contextTaxonomyNode = CreateTaxonomyNode(contextKeyword, filter.DescendantLevels, filter, localization); return(contextTaxonomyNode.Items); }
//private static List<XmlDocument> BuildAndExecute(int contentRepositoryId, Criteria[] criteria, int nbrOfRecords) //{ // Query query; // List<XmlDocument> results; // PublicationCriteria publicationCriteria = new PublicationCriteria(contentRepositoryId); // Criteria searchCriteria = CriteriaFactory.And(criteria); // searchCriteria = CriteriaFactory.And(searchCriteria, publicationCriteria); // query = new Query { Criteria = searchCriteria }; // SortParameter sortParameter = new SortParameter(SortParameter.ItemTitle, SortParameter.Ascending); // LimitFilter limitFilter = new LimitFilter(nbrOfRecords); // results = ExecuteQuery(query, limitFilter, sortParameter); // return results; //} /// <summary> /// this method shall be used to return the component based on a categories and keywords /// </summary> /// <param name="category"></param> /// <param name="keywords"></param> /// <param name="contentRepositoryId"></param> /// <returns></returns> //public static List<XmlDocument> GetComponentsByKeywords(string[] category, string[] keywords, int contentRepositoryId, int nbrOfRecords) //{ // List<XmlDocument> results; // Criteria criteria = null; // KeywordCriteria keywordCriteria; // ItemTypeCriteria typeCriteria = new ItemTypeCriteria(TRIDION_ITEMTYPE); // for (int i = 0; i < keywords.Length; i++) // { // keywordCriteria = new KeywordCriteria(category[i], keywords[i]); // if (i == 0) // { // criteria = CriteriaFactory.And(keywordCriteria, typeCriteria); // } // else // { // criteria = CriteriaFactory.And(keywordCriteria, criteria); // } // } // results = BuildAndExecute(contentRepositoryId, new Criteria[] { criteria }, nbrOfRecords); // return results; //} /// <summary> /// this method shall be used to return the component based on a category /// </summary> /// <param name="category"></param> /// <param name="contentRepositoryId"></param> /// <param name="nbrOfRecords"></param> /// <returns></returns> //public static List<XmlDocument> GetComponentsByCategory(string category, int contentRepositoryId, int nbrOfRecords) //{ // List<XmlDocument> results; // CategoryCriteria categoryCriteria = new CategoryCriteria(category); // ItemTypeCriteria typeCriteria = new ItemTypeCriteria(TRIDION_ITEMTYPE); // results = BuildAndExecute(contentRepositoryId, new Criteria[] { categoryCriteria, typeCriteria }, nbrOfRecords); // return results; //} /// <summary> /// GetContentRepositoryId shall return the Publication Id from TCM URI /// </summary> /// <param name="URI"></param> /// <returns></returns> ////public static int GetContentRepositoryId(string URI) ////{ //// int contentRepositoryId; //// if (!string.IsNullOrEmpty(URI)) //// { //// // Todo: optimize regex expression //// Regex tcmURIPattern = new Regex(TCM_URI_PATTERN); //// Regex tcmURIComponentPattern = new Regex(TCM_URI_COMPONENT_PATTERN); //// if (!(tcmURIPattern.IsMatch(URI)) && !(tcmURIComponentPattern.IsMatch(URI))) //// { //// string logString = "An error has occurred. The request trace is: " + Environment.NewLine; //// logString = string.Concat(logString, string.Format("Invalid Item URI:{0}", URI)); //// ESI4TLogger.WriteLog(ELogLevel.WARN, logString); //// throw new ESI4TIndexingException(TCM_URI_INVALID_CODE, TCM_URI_INVALID_VALUE); //// } //// TCMURI uri = new TCMURI(URI); //// contentRepositoryId = uri.GetPublicationId(); //// } //// else //// { //// contentRepositoryId = 0; //// } //// return contentRepositoryId; ////} /// <summary> /// Execute Query will execute the query and will return the list of Xml if the component /// </summary> /// <param name="query"></param> /// <param name="limitFilter"></param> /// <param name="sortParameter"></param> /// <returns></returns> //public static List<XmlDocument> ExecuteQuery(Query query, LimitFilter limitFilter, SortParameter sortParameter) //{ // List<XmlDocument> results = null; // query.AddSorting(sortParameter); // query.AddLimitFilter(limitFilter); // string[] compURIList = query.ExecuteQuery(); // if (compURIList != null && compURIList.Length > 0) // { // results = new List<XmlDocument>(); // for (int componentCount = 0; componentCount < compURIList.Length; componentCount++) // { // results.Add(GetComponent(compURIList[componentCount])); // } // } // return results; //} /// <summary> /// /// </summary> /// <param name="schemaId"></param> /// <param name="contentRepositoryId"></param> /// <param name="noOfRecords"></param> /// <returns></returns> //public static List<XmlDocument> GetContentByType(int schemaId, int contentRepositoryId, int noOfRecords) //{ // List<XmlDocument> results; // ItemSchemaCriteria schemaCriteria = new ItemSchemaCriteria(schemaId); // ItemTypeCriteria typeCriteria = new ItemTypeCriteria(TRIDION_ITEMTYPE); // results = BuildAndExecute(contentRepositoryId, new Criteria[] { schemaCriteria, typeCriteria }, noOfRecords); // return results; //} /// <summary> /// /// </summary> /// <param name="URI"></param> /// <returns></returns> //public static XmlDocument GetComponent(string URI) //{ // ComponentPresentationFactory cpf; // XmlDocument result = null; // int contentRepositoryId = GetContentRepositoryId(URI); // cpf = new ComponentPresentationFactory(contentRepositoryId); // ComponentPresentation cp = cpf.GetComponentPresentationWithHighestPriority(URI); // if (cp != null && (!string.IsNullOrEmpty(cp.Content))) // { // result = new XmlDocument(); // result.LoadXml(cp.Content); // } // else // { // result = null; // } // return result; //} /// <summary> /// Return the keywords based on Taxonomy /// </summary> public static Keyword GetKeywords(int contentRepositoryId, int contentId, int itemType) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); string URI = string.Format(TCM_URI_FORMAT, contentRepositoryId, contentId, itemType); Keyword keyWord; if (itemType == TRIDION_KEYWORDTYPE) { keyWord = taxonomyFactory.GetTaxonomyKeyword(URI); } else { keyWord = taxonomyFactory.GetTaxonomyKeywords(URI); } return(keyWord); }
//WebRequestContext.Localization //public static List<string> LoadOptionsFromCategory(string categoryName, Localization localization) //{ // var list = new List<string>(); // TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); // string[] taxonomyIds = taxonomyFactory.GetTaxonomies(GetPublicationTcmUri(localization)); // foreach (string taxonomyId in taxonomyIds) // { // Keyword taxonomyRoot = taxonomyFactory.GetTaxonomyKeywords(taxonomyId); // if (taxonomyRoot.KeywordName.Equals(categoryName)) // { // list.AddRange(taxonomyRoot.KeywordChildren.Cast<Keyword>().Select(k => k.KeywordName)); // return list; // } // } // return list; //} public static List <OptionModel> LoadOptionsFromCategory(string categoryName, Localization localization) { var list = new List <OptionModel>(); TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); string[] taxonomyIds = taxonomyFactory.GetTaxonomies(GetPublicationTcmUri(localization)); foreach (string taxonomyId in taxonomyIds) { Keyword taxonomyRoot = taxonomyFactory.GetTaxonomyKeywords(taxonomyId); if (taxonomyRoot.KeywordName.Equals(categoryName)) { list.AddRange(taxonomyRoot.KeywordChildren.Cast <Keyword>().Select(k => new OptionModel { Value = new TcmUri(k.KeywordUri).ItemId.ToString(), DisplayText = k.KeywordName })); return(list); } } return(list); }
public static Keyword LoadKeyword(string keywordUri) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); return taxonomyFactory.GetTaxonomyKeyword(keywordUri); }
public static Keyword LoadKeyword(string keywordUri) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); return(taxonomyFactory.GetTaxonomyKeyword(keywordUri)); }
/// <summary> /// Gets a list of keyword objects based on their URIs /// </summary> /// <param name="keywordUris"></param> /// <returns></returns> public static List <Keyword> LoadKeywords(List <string> keywordUris) { TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); return(keywordUris.Select(uri => taxonomyFactory.GetTaxonomyKeyword(uri)).Where(kw => kw != null).ToList()); }
public bool TryGetKeyword(string categoryUriToLookIn, string keywordName, out IKeyword keyword) { using (TaxonomyFactory taxFactory = new TaxonomyFactory()) { var taxonomyUri = categoryUriToLookIn; //Create filter to retrieve all keywords in a taxonomy CompositeFilter compFilter = new CompositeFilter(); compFilter.DepthFiltering(DepthFilter.UnlimitedDepth, DepthFilter.FilterUp); compFilter.DepthFiltering(DepthFilter.UnlimitedDepth, DepthFilter.FilterDown); //Get keywords in taxonomy (hierarchically) IEnumerable <Keyword> taxonomy = null; try { //Ugly way to see if a taxonomy exists. Alternative is to loop through all taxonomys in Tridion and check if the categoryUriToLookIn exists... taxonomy = taxFactory.GetTaxonomyKeywords(categoryUriToLookIn, compFilter, new TaxonomyHierarchyFormatter()).KeywordChildren.Cast <Keyword>(); } catch (Exception) { //TODO: Trace keyword = null; return(false); } //Search in taxonomy Keyword foundKeyword = null; foreach (var currentKeyword in taxonomy) { string currentKeywordName = currentKeyword.KeywordName; if (currentKeywordName != keywordName) { foundKeyword = recursive(currentKeyword.KeywordChildren.Cast <Keyword>().ToList(), keywordName); } else { foundKeyword = currentKeyword; } if (foundKeyword != null) { Tridion.Extensions.DynamicDelivery.ContentModel.Keyword returnKeyword = new ContentModel.Keyword(); Keyword par = foundKeyword.ParentKeyword; do { Tridion.Extensions.DynamicDelivery.ContentModel.Keyword newParentKeyword = new ContentModel.Keyword(); newParentKeyword.Id = par.KeywordUri; newParentKeyword.TaxonomyId = par.TaxonomyUri; newParentKeyword.Title = par.KeywordName; returnKeyword.ParentKeywords.Add(newParentKeyword); //Add the parentkeyword to the list par = par.ParentKeyword; } while (par != null); //Add remaining properties to the returnKeyword returnKeyword.Id = foundKeyword.KeywordUri; returnKeyword.TaxonomyId = foundKeyword.TaxonomyUri; returnKeyword.Title = foundKeyword.KeywordName; keyword = returnKeyword; return(true); } } keyword = null; return(false); //Keyword not found } }
public bool TryGetKeyword(string categoryUriToLookIn, string keywordName, out IKeyword keyword) { using (TaxonomyFactory taxFactory = new TaxonomyFactory()) { var taxonomyUri = categoryUriToLookIn; //Create filter to retrieve all keywords in a taxonomy CompositeFilter compFilter = new CompositeFilter(); compFilter.DepthFiltering(DepthFilter.UnlimitedDepth, DepthFilter.FilterUp); compFilter.DepthFiltering(DepthFilter.UnlimitedDepth, DepthFilter.FilterDown); //Get keywords in taxonomy (hierarchically) IEnumerable<Keyword> taxonomy = null; try { //Ugly way to see if a taxonomy exists. Alternative is to loop through all taxonomys in Tridion and check if the categoryUriToLookIn exists... taxonomy = taxFactory.GetTaxonomyKeywords(categoryUriToLookIn, compFilter, new TaxonomyHierarchyFormatter()).KeywordChildren.Cast<Keyword>(); } catch (Exception) { //TODO: Trace keyword = null; return false; } //Search in taxonomy Keyword foundKeyword = null; foreach (var currentKeyword in taxonomy) { string currentKeywordName = currentKeyword.KeywordName; if (currentKeywordName != keywordName) { foundKeyword = recursive(currentKeyword.KeywordChildren.Cast<Keyword>().ToList(), keywordName); } else { foundKeyword = currentKeyword; } if (foundKeyword != null) { Tridion.Extensions.DynamicDelivery.ContentModel.Keyword returnKeyword = new ContentModel.Keyword(); Keyword par = foundKeyword.ParentKeyword; do { Tridion.Extensions.DynamicDelivery.ContentModel.Keyword newParentKeyword = new ContentModel.Keyword(); newParentKeyword.Id = par.KeywordUri; newParentKeyword.TaxonomyId = par.TaxonomyUri; newParentKeyword.Title = par.KeywordName; returnKeyword.ParentKeywords.Add(newParentKeyword); //Add the parentkeyword to the list par = par.ParentKeyword; } while (par != null); //Add remaining properties to the returnKeyword returnKeyword.Id = foundKeyword.KeywordUri; returnKeyword.TaxonomyId = foundKeyword.TaxonomyUri; returnKeyword.Title = foundKeyword.KeywordName; keyword = returnKeyword; return true; } } keyword = null; return false; //Keyword not found } }