public void GetComponentPresentationFromComponent() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("component"); Assert.IsNotNull(cp); Assert.IsFalse(string.IsNullOrEmpty(cp.Component.Title) || cp.ComponentTemplate == null); }
public void GetComponentPresentations() { IList <IComponentPresentation> cps = ComponentPresentationFactory.GetComponentPresentations(new string[] { "tcm:0-1", "tcm:0-2" }); Assert.IsTrue(cps.Count == 2); Assert.IsNotNull(cps[0].Component.Title); }
public void ComponentId() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "componentlink"); TestViewModelA model = ViewModelFactory.BuildViewModel(cp) as TestViewModelA; Assert.IsNotNull(model.Id, "ComponentId is not set"); }
public void GetComponentPresentation() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation(""); Assert.IsNotNull(cp); Assert.IsFalse(string.IsNullOrEmpty(cp.Component.Title) || string.IsNullOrEmpty(cp.ComponentTemplate.Title)); Assert.IsNotNull(cp.Conditions[0]); }
static void Main(string[] args) { Regex regex = new Regex(@"href=\""(?<url>.*?)\""", RegexOptions.IgnoreCase | RegexOptions.Multiline); foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink()) { String url = componentLink.GetLinkAsString("tcm:0-0-0", uri, "tcm:0-0-0", String.Empty, String.Empty, false, false); if (!String.IsNullOrEmpty(url)) { Match match = regex.Match(url); if (match.Success) Utilities.OutputLink(uri, match.Groups["url"].Value); else Console.WriteLine("Error resolving component link for {0}: Invalid url {1}.", uri, url); } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory()) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) Utilities.OutputDCP(uri, presentation.Content); else Console.WriteLine("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public void ResolveLinkWithPageUri() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", ""); Assert.IsNotNull(cp); TridionLinkProvider.link2 = "/this/link/works/too.html"; string url = ViewModelFactory.LinkResolver.ResolveUrl(cp.Component, "tcm:2-2-64"); Assert.IsNotNull(url); Assert.AreEqual(url, "/this/link/works/too.html"); }
/// <summary> /// Returns the Component contents which could be found. Components that couldn't be found don't appear in the list. /// </summary> /// <param name="componentUris"></param> /// <returns></returns> public List <string> GetContentMultiple(string[] componentUris) { TcmUri uri = new TcmUri(componentUris.First()); ComponentPresentationFactory cpFactory = new ComponentPresentationFactory(uri.PublicationId); var components = componentUris .Select(componentUri => (Tridion.ContentDelivery.DynamicContent.ComponentPresentation)cpFactory.FindAllComponentPresentations(componentUri)[0]) .Where(cp => cp != null) .Select(cp => cp.Content) .ToList(); return(components); }
/// <summary> /// Returns the Component contents which could be found. Components that couldn't be found don't appear in the list. /// </summary> /// <param name="componentUris"></param> /// <returns></returns> public List<string> GetContentMultiple(string[] componentUris) { TcmUri uri = new TcmUri(componentUris.First()); ComponentPresentationFactory cpFactory = new ComponentPresentationFactory(uri.PublicationId); var components = componentUris .Select(componentUri => (Tridion.ContentDelivery.DynamicContent.ComponentPresentation)cpFactory.FindAllComponentPresentations(componentUri)[0]) .Where(cp => cp != null) .Select(cp => cp.Content) .ToList(); return components; }
public string GetContent(string uri, string templateUri = "") { TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); Tridion.ContentDelivery.DynamicContent.ComponentPresentationFactory cpFactory = new ComponentPresentationFactory(PublicationId); Tridion.ContentDelivery.DynamicContent.ComponentPresentation cp = null; if (!String.IsNullOrEmpty(templateUri)) { cp = cpFactory.GetComponentPresentation(tcmUri.ItemId, templateTcmUri.ItemId); if (cp != null) { return(cp.Content); } } if (!string.IsNullOrEmpty(selectByComponentTemplateId)) { cp = cpFactory.GetComponentPresentation(tcmUri.ItemId, Convert.ToInt32(selectByComponentTemplateId)); if (cp != null) { return(cp.Content); } } if (!string.IsNullOrEmpty(selectByOutputFormat)) { cp = cpFactory.GetComponentPresentationWithOutputFormat(tcmUri.ItemId, selectByOutputFormat); if (cp != null) { return(cp.Content); } } IList cps = cpFactory.FindAllComponentPresentations(tcmUri.ItemId); foreach (Tridion.ContentDelivery.DynamicContent.ComponentPresentation _cp in cps) { if (_cp != null) { if (_cp.Content.Contains("<Component")) { return(_cp.Content); } } } return(string.Empty); }
public void MapAbstractEmbeddedField() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "embedded"); Assert.IsNotNull(cp); EmbeddingModel vm = ViewModelFactory.BuildViewModel(cp) as EmbeddingModel; Assert.IsNotNull(vm); EmbeddedModel em = vm.Embedded as EmbeddedModel; Assert.IsNotNull(em); Assert.IsTrue(em.Heading == "some heading"); }
public void MapConcreteKeywordField() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "keyword"); Assert.IsNotNull(cp); KeywordContainingModel vm = ViewModelFactory.BuildViewModel(cp) as KeywordContainingModel; Assert.IsNotNull(vm); KeywordModel km = vm.ConcreteKeyword; Assert.IsNotNull(km); Assert.IsTrue(km.Heading == "some heading"); }
private string ResolveRichText(string input) { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", ""); Field richTextField = new Field() { Name = "richtext", Values = new List <string>() { input } }; cp.Component.Fields.Add(richTextField.Name, richTextField); return((string)ViewModelFactory.RichTextResolver.Resolve(cp.Component.Fields["richtext"].Value)); }
public void KeywordIdAsTcmUri() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "keyword"); Assert.IsNotNull(cp); KeywordContainingModel vm = ViewModelFactory.BuildViewModel(cp) as KeywordContainingModel; Assert.IsNotNull(vm); KeywordModel km = vm.ConcreteKeyword; Assert.IsNotNull(km); Assert.IsNotNull(km.KeywordId, "KeywordId is not set"); }
public void MapConcreteLink() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "componentlink"); Assert.IsNotNull(cp); IViewModel vm = ViewModelFactory.BuildViewModel(cp); Assert.IsNotNull(vm); TestViewModelB b = ((TestViewModelA)vm).ConcreteLink[0]; Assert.IsNotNull(b); Assert.IsTrue(b.Heading == "some heading"); }
public void MapComponentId() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "componentId"); Assert.IsNotNull(cp); IViewModel vm = ViewModelFactory.BuildViewModel(cp); Assert.IsNotNull(vm); TestViewModelA b = (TestViewModelA)vm; Assert.IsNotNull(b); Assert.IsTrue(b.Id.ItemId == 8975); Assert.IsTrue(b.Id.PublicationId == 5); }
public void MapFieldsIgnoreCase() { IComponentPresentation cp = ComponentPresentationFactory.GetComponentPresentation("", "componentIgnoreCase"); Assert.IsNotNull(cp); //ViewModelFactory.LoadViewModels(); IViewModel vm = ViewModelFactory.BuildViewModel(cp); Assert.IsNotNull(vm); TestViewModelB b = ((TestViewModelA)vm).ConcreteLink[0]; Assert.IsNotNull(b); /// Assert.IsTrue(b.Heading == "some heading"); }
internal static IComponentPresentationFactory GetComponentPresentationFactory(Localization localization) { lock (_componentPresentationFactories) { IComponentPresentationFactory componentPresentationFactory; if (!_componentPresentationFactories.TryGetValue(localization.LocalizationId, out componentPresentationFactory)) { IPublicationResolver publicationResolver = new PublicationResolver(localization); IProvidersCommonServices providersCommonServices = new ProvidersCommonServices(publicationResolver, _logger, _config); IFactoryCommonServices factoryCommonServices = new FactoryCommonServices(publicationResolver, _logger, _config, CreateCacheAgent()); componentPresentationFactory = new ComponentPresentationFactory( new TridionComponentPresentationProvider(providersCommonServices), factoryCommonServices); _componentPresentationFactories.Add(localization.LocalizationId, componentPresentationFactory); } return(componentPresentationFactory); } }
public string GetContent(string uri, string templateUri = "") { TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); Tridion.ContentDelivery.DynamicContent.ComponentPresentationFactory cpFactory = new ComponentPresentationFactory(PublicationId); Tridion.ContentDelivery.DynamicContent.ComponentPresentation cp = null; if (!String.IsNullOrEmpty(templateUri)) { cp = cpFactory.GetComponentPresentation(tcmUri.ItemId, templateTcmUri.ItemId); if (cp != null) return cp.Content; } if (!string.IsNullOrEmpty(selectByComponentTemplateId)) { cp = cpFactory.GetComponentPresentation(tcmUri.ItemId, Convert.ToInt32(selectByComponentTemplateId)); if (cp != null) return cp.Content; } if (!string.IsNullOrEmpty(selectByOutputFormat)) { cp = cpFactory.GetComponentPresentationWithOutputFormat(tcmUri.ItemId, selectByOutputFormat); if (cp != null) return cp.Content; } IList cps = cpFactory.FindAllComponentPresentations(tcmUri.ItemId); foreach (Tridion.ContentDelivery.DynamicContent.ComponentPresentation _cp in cps) { if (_cp != null) { if (_cp.Content.Contains("<Component")) { return _cp.Content; } } } return string.Empty; }
/// <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); }
public void GetLastPublishedDate() { DateTime lastPublishDate = ComponentPresentationFactory.GetLastPublishedDate("tcm:0-1"); Assert.IsFalse(lastPublishDate == default(DateTime)); }
static void Main(String[] args) { try { IJvmLoader loader = JvmLoader.GetJvmLoader(); Console.WriteLine("CodeMesh using Java: {0}", loader.JvmPath); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Java virtual machine could not be loaded\n{0}", Utilities.FormatException(ex)); Console.ReadKey(); return; } foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink(Utilities.PublicationUri)) { Link link = componentLink.GetLink(uri); if (link != null && link.IsResolved) Utilities.OutputLink(uri, link.Url); else Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory(Utilities.PublicationUri)) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.Write("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
static void Main(string[] args) { Regex regex = new Regex(@"href=\""(?<url>.*?)\""", RegexOptions.IgnoreCase | RegexOptions.Multiline); foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink()) { String url = componentLink.GetLinkAsString("tcm:0-0-0", uri, "tcm:0-0-0", String.Empty, String.Empty, false, false); if (!String.IsNullOrEmpty(url)) { Match match = regex.Match(url); if (match.Success) { Utilities.OutputLink(uri, match.Groups["url"].Value); } else { Console.WriteLine("Error resolving component link for {0}: Invalid url {1}.", uri, url); } } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory()) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.WriteLine("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
static void Main(String[] args) { try { IJvmLoader loader = JvmLoader.GetJvmLoader(); Console.WriteLine("CodeMesh using Java: {0}", loader.JvmPath); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Java virtual machine could not be loaded\n{0}", Utilities.FormatException(ex)); Console.ReadKey(); return; } foreach (String uri in Utilities.LinkUris) { try { using (ComponentLink componentLink = new ComponentLink(Utilities.PublicationUri)) { Link link = componentLink.GetLink(uri); if (link != null && link.IsResolved) { Utilities.OutputLink(uri, link.Url); } else { Console.WriteLine("Error resolving component link for {0}: Link is null or not resolved.", uri); } } } catch (Exception ex) { Console.WriteLine("Error resolving component link for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } foreach (String uri in Utilities.BrokerUris) { try { using (ComponentPresentationFactory factory = new ComponentPresentationFactory(Utilities.PublicationUri)) { ComponentPresentation presentation = factory.GetComponentPresentationWithHighestPriority(uri); if (presentation != null) { Utilities.OutputDCP(uri, presentation.Content); } else { Console.Write("Error retrieving dynamic component presentation for {0}: Presentation is null.", uri); } } } catch (Exception ex) { Console.WriteLine("Error retrieving dynamic component presentation for {0}:\n{1}", uri, Utilities.FormatException(ex)); } } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }