public string GetContent(string uri, string templateUri = "") { LoggerService.Debug(">>GetContent({0})", LoggingCategory.Performance, uri); TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); T.ComponentPresentationFactory cpFactory = GetComponentPresentationFactory(tcmUri.PublicationId); T.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) { LoggerService.Debug("<<GetContent({0}) - by ct id", LoggingCategory.Performance, uri); return cp.Content; } } if (!string.IsNullOrEmpty(selectByOutputFormat)) { cp = cpFactory.GetComponentPresentationWithOutputFormat(tcmUri.ItemId, selectByOutputFormat); if (cp != null) { LoggerService.Debug("<<GetContent({0}) - by output format", LoggingCategory.Performance, uri); return cp.Content; } } LoggerService.Debug("GetContent: about to get component presentations with Highst Priority for {0}", LoggingCategory.Performance, tcmUri.ToString()); cp = cpFactory.GetComponentPresentationWithHighestPriority(tcmUri.ItemId); LoggerService.Debug("GetContent: get component presentations with Highst Priority for {0}", LoggingCategory.Performance, tcmUri.ToString()); if (cp != null) return cp.Content; //foreach (Tridion.ContentDelivery.DynamicContent.ComponentPresentation _cp in cps) //{ // if (_cp != null) // { // LoggerService.Debug("<<GetContent({0}) - find all", LoggingCategory.Performance, uri); // return _cp.Content; // } //} LoggerService.Debug("<<GetContent({0}) - not found", LoggingCategory.Performance, uri); return string.Empty; }
protected void Page_Load(object sender, EventArgs e) { // get the current logged in user string user = HttpContext.Current.User.Identity.Name; if (!String.IsNullOrEmpty(user)) { // set LogonUser TridionTreeView.LogonUser = user; } // process querystring parameters string start = Request.QueryString["start"]; string types = Request.QueryString["types"]; string pubid = Request.QueryString["pubid"]; if (!String.IsNullOrEmpty(start)) { // override StartFromUri TridionTreeView.StartFromUri = start; } else if (!String.IsNullOrEmpty(pubid)) { // override StartFromUri with current publication id TcmUri uri = new TcmUri(pubid); TridionTreeView.StartFromUri = uri.ToString(); } if (!String.IsNullOrEmpty(types)) { // override SelectTypes TridionTreeView.SelectTypes = Convert.ToInt32(types); } }
/// <summary> /// Constructor to create a BaseBinaryPathProvider /// </summary> /// <param name="engine">The SDL Web publish engine</param> /// <param name="package">The SDL Web publish package</param> public BaseBinaryPathProvider(Engine engine, Package package) { Engine = engine; Package = package; String targetStructureGroupParam = package.GetValue("sg_PublishBinariesTargetStructureGroup"); if (targetStructureGroupParam != null) { if (!TcmUri.IsValid(targetStructureGroupParam)) { log.Error(String.Format("TargetStructureGroup '{0}' is not a valid TCMURI. Exiting template.", targetStructureGroupParam)); return; } Publication publication = TridionUtils.GetPublicationFromContext(package, engine); TcmUri localTargetStructureGroupTcmUri = TridionUtils.GetLocalUri(new TcmUri(publication.Id), new TcmUri(targetStructureGroupParam)); targetStructureGroupUri = new TcmUri(localTargetStructureGroupTcmUri); log.Debug($"targetStructureGroupUri = {targetStructureGroupUri.ToString()}"); } String stripTcmUrisFromBinaryUrlsParam = package.GetValue("stripTcmUrisFromBinaryUrls"); if (stripTcmUrisFromBinaryUrlsParam != null) { stripTcmUrisFromBinaryUrls = stripTcmUrisFromBinaryUrlsParam.ToLower() == "yes" || stripTcmUrisFromBinaryUrlsParam.ToLower() == "true"; } log.Debug($"stripTcmUrisFromBinaryUrls = {stripTcmUrisFromBinaryUrls}"); }
public string ResolveLink(string componentUri) { TcmUri uri = new TcmUri(componentUri); if (!uri.Equals(emptyTcmUri)) { Cache cache = HttpContext.Current.Cache; string cacheKey = String.Format(CACHEKEY_FORMAT, componentUri); if (cache[cacheKey] != null) { return (String)cache[cacheKey]; } else { Link link = componentLink.GetLink(uri.ToString()); if (!link.IsResolved) { return null; } cache.Insert(cacheKey, link.Url, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero); //TODO should this be configurable? return link.Url; } } return null; }
private static string ResolveBinaryLink(TcmUri tcmUri, int localizationId = 0) { int publicationId = localizationId == 0 ? tcmUri.PublicationId : localizationId; BinaryLink linker = new BinaryLink(publicationId); Link link = linker.GetLink(tcmUri.ToString(), null, null, null, false); return(link.IsResolved ? link.Url : null); }
public static TcmUri GetLocalUri(TcmUri uriPublication, TcmUri uriItem) { TcmUri uriReturn = new TcmUri(uriItem.ItemId, uriItem.ItemType, uriPublication.ItemId); TemplatingLogger log = TemplatingLogger.GetLogger(typeof(TemplateUtilities)); log.Info("(getLocalUri)Old URI was:" + uriItem.ToString()); log.Info("(getLocalUri)New URI is:" + uriReturn.ToString()); return uriReturn; }
internal string GetUriInBlueprintContext(string itemId, string publicationId) { TcmUri itemUri = new TcmUri(itemId); TcmUri publicationUri = new TcmUri(publicationId); TcmUri inContext = new TcmUri(itemUri.ItemId, itemUri.ItemType, publicationUri.ItemId); return(inContext.ToString()); }
public static TcmUri GetLocalUri(TcmUri uriPublication, TcmUri uriItem) { TcmUri uriReturn = new TcmUri(uriItem.ItemId, uriItem.ItemType, uriPublication.ItemId); TemplatingLogger log = TemplatingLogger.GetLogger(typeof(TemplateUtilities)); log.Info("(getLocalUri)Old URI was:" + uriItem.ToString()); log.Info("(getLocalUri)New URI is:" + uriReturn.ToString()); return(uriReturn); }
protected virtual void PublishItem(Item item, TcmUri itemUri) { Stream itemStream = null; // See if some template set itself as the applied template on this item TcmUri appliedTemplateUri = null; if (item.Properties.ContainsKey(Item.ItemPropertyTemplateUri)) { appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]); } try { string publishedPath; if (targetStructureGroupUri == null) { log.Debug("no structure group defined, publishing binary with default settings"); Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]); // Note: it is dangerous to specify the CT URI as variant ID without a structure group, because it will fail if you publish the same MMC from two or more CTs! // So I removed the variant ID altogether (QS, 20-10-2011) log.Debug(string.Format("publishing mm component {0} without variant id", mmComp.Id)); Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp); publishedPath = binary.Url; log.Debug(string.Format("binary is published to url {0}", publishedPath)); } else { Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]); string fileName = ConstructFileName(mmComp, currentTemplate.Id); StructureGroup targetSG = (StructureGroup)engine.GetObject(targetStructureGroupUri); itemStream = item.GetAsStream(); if (itemStream == null) { // All items can be converted to a stream? log.Error(String.Format("Cannot get item '{0}' as stream", itemUri.ToString())); } //byte[] data = new byte[itemStream.Length]; //itemStream.Read(data, 0, data.Length); //itemStream.Close(); log.Debug(string.Format("publishing mm component {0} to structure group {1} with variant id {2} and filename {3}", mmComp.Id, targetStructureGroupUri.ToString(), currentTemplate.Id, fileName)); Binary b = engine.PublishingContext.RenderedItem.AddBinary(item.GetAsStream(), fileName, targetSG, currentTemplate.Id, mmComp, mmComp.BinaryContent.MultimediaType.MimeType); publishedPath = b.Url; //publishedPath = engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroupUri, data, fileName); log.Debug(string.Format("binary is published to url {0}", publishedPath)); } log.Debug("binary published, published path = " + publishedPath); item.Properties[Item.ItemPropertyPublishedPath] = publishedPath; } finally { if (itemStream != null) { itemStream.Close(); } } }
public static XElement GetListXml(this TcmUri tcmUri, ItemType[] itemTypes, bool recursive) { var filter = new OrganizationalItemItemsFilterData { ItemTypes = itemTypes, Recursive = recursive }; return(Wrapper.Instance.GetListXml(tcmUri.ToString(), filter)); }
public string GetVersionlessUri(string id) { TcmUri uri = new TcmUri(id); if (uri.IsVersionless) { return(id); } uri = new TcmUri(uri.ItemId, uri.ItemType, uri.PublicationId); return(uri.ToString()); }
public string ResolveLink(string componentUri) { TcmUri uri = new TcmUri(componentUri); if (!uri.Equals(emptyTcmUri)) { Link link = componentLink.GetLink(uri.ToString()); return link.IsResolved ? link.Url : null; } return null; }
public string ResolveLink(string componentUri) { TcmUri uri = new TcmUri(componentUri); if (!uri.Equals(emptyTcmUri)) { Link link = componentLink.GetLink(uri.ToString()); return(link.IsResolved ? link.Url : null); } return(null); }
public static T GetItem <T>(this TcmUri tcmUri) where T : IdentifiableObjectData { T result; try { result = ((T)Wrapper.Instance.Read(tcmUri.ToString(), new ReadOptions())); } catch (Exception e) { result = default(T); } return(result); }
private void PublishItem(Item item, TcmUri itemUri) { Stream itemStream = null; // See if some template set itself as the applied template on this item TcmUri appliedTemplateUri = null; if (item.Properties.ContainsKey(Item.ItemPropertyTemplateUri)) { appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]); } try { string publishedPath; if (targetStructureGroup == null) { log.Debug("no structure group defined, publishing binary with default settings"); Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]); //Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp); Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp, currentTemplate.Id); publishedPath = binary.Url; } else { string fileName = TridionUtils.ConstructFileName(item); log.Debug("publishing binary into structure group " + targetStructureGroup.ItemId.ToString()); itemStream = item.GetAsStream(); if (itemStream == null) { // All items can be converted to a stream? log.Error(String.Format("Cannot get item '{0}' as stream", itemUri.ToString())); } byte[] data = new byte[itemStream.Length]; itemStream.Read(data, 0, data.Length); publishedPath = engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroup, data, fileName); } log.Debug("binary published, published path = " + publishedPath); item.Properties[Item.ItemPropertyPublishedPath] = publishedPath; } finally { if (itemStream != null) { itemStream.Close(); } } }
public IViewModel BuildViewModel(TcmUri Id) { IViewModel model = null; if (Id.ItemTypeId == 64) { model = BuildViewModel(GetPage(Id)); } else { IComponentPresentation component; if (TryGetComponentPresentation(out component, Id.ToString())) { model = BuildViewModel(component); } } return(model); }
public virtual string ResolveLink(string sourcePageUri, string componentUri, string excludeComponentTemplateUri) { TcmUri componentUriToLinkTo = new TcmUri(componentUri); TcmUri pageUri = new TcmUri(sourcePageUri); TcmUri componentTemplateUri = new TcmUri(excludeComponentTemplateUri); if (!componentUriToLinkTo.Equals(emptyTcmUri)) { Link link = GetComponentLink(componentUriToLinkTo).GetLink(pageUri.ToString(), componentUriToLinkTo.ToString(), componentTemplateUri.ToString(), String.Empty, String.Empty, false, LinkToAnchor); if (!link.IsResolved) { return null; } return LinkToAnchor && link.Anchor != "0" ? string.Format("{0}#{1}", link.Url, TridionHelper.GetLocalAnchorTag(pageUri, componentUriToLinkTo, componentTemplateUri, link.Anchor)) : link.Url; } return null; }
public string ResolveLink(string sourcePageUri, string componentUri, string excludeComponentTemplateUri) { TcmUri componentUriToLinkTo = new TcmUri(componentUri); TcmUri pageUri = new TcmUri(sourcePageUri); TcmUri componentTemplateUri = new TcmUri(excludeComponentTemplateUri); if (!componentUriToLinkTo.Equals(emptyTcmUri)) { Link link = componentLink.GetLink(pageUri.ToString(), componentUriToLinkTo.ToString(), componentTemplateUri.ToString(), String.Empty, String.Empty, false, false); if (!link.IsResolved) { return null; } return link.Url; } return null; }
public virtual string ResolveLink(string sourcePageUri, string componentUri, string excludeComponentTemplateUri) { TcmUri componentUriToLinkTo = new TcmUri(componentUri); TcmUri pageUri = new TcmUri(sourcePageUri); TcmUri componentTemplateUri = new TcmUri(excludeComponentTemplateUri); if (!componentUriToLinkTo.Equals(emptyTcmUri)) { Link link = componentLink.GetLink(pageUri.ToString(), componentUriToLinkTo.ToString(), componentTemplateUri.ToString(), String.Empty, String.Empty, false, LinkToAnchor); if (!link.IsResolved) { return(null); } return(LinkToAnchor && link.Anchor != "0" ? string.Format("{0}#{1}", link.Url, TridionHelper.GetLocalAnchorTag(pageUri, componentUriToLinkTo, componentTemplateUri, link.Anchor)) : link.Url); } return(null); }
public string ResolveLink(string sourcePageUri, string componentUri, string excludeComponentTemplateUri) { TcmUri componentUriToLinkTo = new TcmUri(componentUri); TcmUri pageUri = new TcmUri(sourcePageUri); TcmUri componentTemplateUri = new TcmUri(excludeComponentTemplateUri); if (!componentUriToLinkTo.Equals(emptyTcmUri)) { Link link = componentLink.GetLink(pageUri.ToString(), componentUriToLinkTo.ToString(), componentTemplateUri.ToString(), String.Empty, String.Empty, false, false); if (!link.IsResolved) { return(null); } return(link.Url); } return(null); }
public virtual string ResolveLink(string sourcePageUri, string componentUri, string excludeComponentTemplateUri) { TcmUri componentUriToLinkTo = new TcmUri(componentUri); TcmUri pageUri = new TcmUri(sourcePageUri); TcmUri componentTemplateUri = new TcmUri(excludeComponentTemplateUri); var linkToAnchor = Configuration.LinkToAnchor; if (!componentUriToLinkTo.Equals(emptyTcmUri)) { Link link = GetComponentLink(componentUriToLinkTo).GetLink(pageUri.ToString(), componentUriToLinkTo.ToString(), componentTemplateUri.ToString(), String.Empty, String.Empty, false, linkToAnchor); if (!link.IsResolved) { return(null); } return(linkToAnchor && link.Anchor != "0" ? string.Format("{0}#{1}", link.Url, Configuration.UseUriAsAnchor.GetLocalAnchorTag(componentUriToLinkTo, link.Anchor)) : link.Url); } return(null); }
protected virtual object MapString(string stringValue, Type targetType, string pageContextId, Localization localization) { if (targetType == typeof(RichText)) { return(new RichText(stringValue)); } if (targetType == typeof(Link)) { // Trying to map a text field to a Link (?); if the text is a TCM URI, it can work... if (!ContentManager.TcmUri.IsValid(stringValue)) { throw new DxaException($"Cannot map string to type Link: '{stringValue}'"); } if (localization != null) { TcmUri tcmUri = new TcmUri(stringValue) { PublicationId = int.Parse(localization.Id) }; stringValue = tcmUri.ToString(); } ILinkResolverExt linkResolverExt = SiteConfiguration.LinkResolver as ILinkResolverExt; return(new Link { Id = stringValue.Split('-')[1], Url = (linkResolverExt == null) ? SiteConfiguration.LinkResolver.ResolveLink(stringValue, resolveToBinary: true) : linkResolverExt.ResolveLink(stringValue, pageContextId: pageContextId, resolveToBinary: true) }); } if (!string.IsNullOrEmpty(stringValue) && targetType == typeof(int) && stringValue.Contains(".")) { // Simple cast from floating point to int return((int)(double)Convert.ChangeType(stringValue, typeof(double), CultureInfo.InvariantCulture.NumberFormat)); } return(Convert.ChangeType(stringValue, targetType, CultureInfo.InvariantCulture.NumberFormat)); }
public bool HasPageChanged(TcmUri tcmUri) { DateTime lastPublishedDate = DateTime.MinValue; string stringUri = tcmUri.ToString(); if (CacheService.ContainsLastPublishDate(stringUri)) { lastPublishedDate = CacheService.GetLastPublishDate(stringUri); } var dbLastPublishedDate = GetLastPublishedDateByUri(stringUri); if (lastPublishedDate != DateTime.MinValue && lastPublishedDate.Subtract(dbLastPublishedDate).TotalSeconds >= 0) { return(false); } else { CacheService.SetLastPublishDate(stringUri, dbLastPublishedDate); return(true); } }
public void Save(bool checkOutIfNeeded = false) { if (checkOutIfNeeded) { if (!Content.IsEditable.GetValueOrDefault()) { Client.CheckOut(Content.Id, true, null); } } if (string.IsNullOrEmpty(Content.Title)) { Content.Title = "No title specified!"; } // Item titles cannot contain backslashes :) if (Content.Title.Contains("\\")) { Content.Title = Content.Title.Replace("\\", "/"); } Content.Content = _fields.ToString(); TcmUri contentId = new TcmUri(Content.Id); if (!contentId.IsVersionless) { contentId = new TcmUri(contentId.ItemId, contentId.ItemType, contentId.PublicationId); Content.Id = contentId.ToString(); } try { Content = (ComponentData)Client.Save(Content, ReadOptions); Client.CheckIn(Content.Id, null); } catch (Exception ex) { Console.WriteLine("Ooops, something went wrong saving component " + Content.Title); Console.WriteLine(ex.Message); } }
public bool Contains(TcmUri uri) { XmlNode node = m_TridionList.SelectSingleNode(String.Format("//tcm:{0}[@ID = '{1}']", ItemXmlName, uri.ToString()), NSManager); return(node != null); }
/// <summary> /// Gets a FolderModel object. /// </summary> /// <param name="tcmUri"></param> /// <returns></returns> public dynamic GetFolder(TcmUri tcmUri) { return GetFolder(tcmUri.ToString()); }
/// <summary> /// Gets a ComponentTemplateModel object. /// </summary> /// <param name="tcmUri"></param> /// <returns></returns> public dynamic GetComponentTemplate(TcmUri tcmUri) { return(GetComponentTemplate(tcmUri.ToString())); }
public void Save(bool checkOutIfNeeded = false) { if (checkOutIfNeeded) { if (!Content.IsEditable.GetValueOrDefault()) { Client.CheckOut(Content.Id, true, null); } } if (string.IsNullOrEmpty(Content.Title)) Content.Title = "No title specified!"; // Item titles cannot contain backslashes :) if (Content.Title.Contains("\\")) Content.Title = Content.Title.Replace("\\", "/"); Content.Content = _fields.ToString(); TcmUri contentId = new TcmUri(Content.Id); if(!contentId.IsVersionless) { contentId = new TcmUri(contentId.ItemId, contentId.ItemType, contentId.PublicationId); Content.Id = contentId.ToString(); } try { Content = (ComponentData)Client.Save(Content, ReadOptions); Client.CheckIn(Content.Id, null); } catch (Exception ex) { Console.WriteLine("Ooops, something went wrong saving component " + Content.Title); Console.WriteLine(ex.Message); } }
/// <summary> /// Gets a ComponentTemplateModel object. /// </summary> /// <param name="tcmUri"></param> /// <returns></returns> public dynamic GetComponentTemplate(TcmUri tcmUri) { return GetComponentTemplate(tcmUri.ToString()); }
public bool HasPageChanged(TcmUri tcmUri) { DateTime lastPublishedDate = DateTime.MinValue; string stringUri = tcmUri.ToString(); if (CacheService.ContainsLastPublishDate(stringUri)) { lastPublishedDate = CacheService.GetLastPublishDate(stringUri); } var dbLastPublishedDate = GetLastPublishedDateByUri(stringUri); if (lastPublishedDate != DateTime.MinValue && lastPublishedDate.Subtract(dbLastPublishedDate).TotalSeconds >= 0) { return false; } else { CacheService.SetLastPublishDate(stringUri, dbLastPublishedDate); return true; } }
public dynamic GetPage(TcmUri tcmUri) { return(GetPage(tcmUri.ToString())); }
/// <summary> /// Initializes a new instance of the <see> /// <cref>TridionOutputHandler</cref> /// </see> /// class. /// </summary> /// <param name="tcmUri">The TCM URI.</param> /// <param name="engine">The engine.</param> /// <param name="package">The package.</param> public FieldOutputHandler(TcmUri tcmUri, Engine engine, Package package) { if (!TcmUri.IsValid(tcmUri.ToString())) { Log.Error(tcmUri + " is not a valid URI. Failed to initialize Output Handler!"); } else { switch (tcmUri.ItemType) { case ItemType.Component: try { _component = new Component(tcmUri, engine.GetSession()); _currentItem = _component; if (_component.ComponentType == ComponentType.Normal) { _contentFields = new ItemFields(_component.Content, _component.Schema); } if (_component.Metadata != null) _metadataFields = new ItemFields(_component.Metadata, _component.Schema); } catch (Exception ex) { Log.Error("Unable to iniatilize fields for component with ID " + tcmUri + "\r\n Exception: " + ex); } break; case ItemType.Page: try { _page = new Page(tcmUri, engine.GetSession()); _currentItem = _page; if (_page.Metadata != null) { _metadataFields = new ItemFields(_page.Metadata, _page.MetadataSchema); } else { Log.Error("Only pages with metadata are allowed."); } } catch (Exception ex) { Log.Error("Unable to initialize fields for page with ID " + tcmUri + "\r\n Exception: " + ex); } break; case ItemType.Publication: try { _publication = new Publication(tcmUri, engine.GetSession()); _currentItem = null; if (_publication.Metadata != null) { _metadataFields = new ItemFields(_publication.Metadata, _publication.MetadataSchema); } else { Log.Error("Only Publications with Metadata are supported!"); } } catch (Exception ex) { Log.Error("Unable to initialize fields for publication with ID " + tcmUri + "\r\n Exception: " + ex); } break; case ItemType.StructureGroup: try { _structureGroup = new StructureGroup(tcmUri, engine.GetSession()); _currentItem = _structureGroup; if (_structureGroup.Metadata != null) { _metadataFields = new ItemFields(_structureGroup.Metadata, _structureGroup.MetadataSchema); } else { Log.Error("Only Structure Groups with Metadata are supported!"); } } catch (Exception ex) { Log.Error("Unable to initialize fields for Structure Group with ID " + tcmUri + "\r\n Exception: " + ex); } break; case ItemType.Folder: try { _folder = new Folder(tcmUri, engine.GetSession()); _currentItem = _folder; if (_folder.Metadata != null) { _metadataFields = new ItemFields(_folder.Metadata, _folder.MetadataSchema); } else { Log.Error("Only Folders with Metadata are supported!"); } } catch (Exception ex) { Log.Error("Unable to initialize fields for Folder with ID " + tcmUri + "\r\n Exception: " + ex); } break; case ItemType.Category: try { _category = new Category(tcmUri, engine.GetSession()); _currentItem = _category; if (_category.Metadata != null) { _metadataFields = new ItemFields(_category.Metadata, _category.MetadataSchema); } else { Log.Error("Only Categories with Metadata are supported!"); } } catch (Exception ex) { Log.Error("Unable to initialize fields for Category with ID " + tcmUri + " \r\n Exception: " + ex); } break; case ItemType.Keyword: try { _keyword = new Keyword(tcmUri, engine.GetSession()); _currentItem = _keyword; if (_keyword.Metadata != null) { _metadataFields = new ItemFields(_keyword.Metadata, _keyword.MetadataSchema); _escapeOutput = true; } else { Log.Error("Only Keywords with Metadata are supported!"); } } catch (Exception ex) { Log.Error("Unable to initialize fields for Keyword with ID " + tcmUri + " \r\n Exception: " + ex); } break; } _engine = engine; _package = package; _itemType = tcmUri.ItemType; } }
public byte[] GetBinaryByUrl(string url) { string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now? IList metas = null; BinaryMeta binaryMeta = null; if (this.PublicationId == 0) { metas = BinaryMetaFactory.GetMetaByUrl(encodedUrl); if (metas.Count == 0) { throw new BinaryNotFoundException(); } binaryMeta = metas[0] as BinaryMeta; } else { binaryMeta = BinaryMetaFactory.GetMetaByUrl(this.PublicationId, encodedUrl); if (binaryMeta == null) throw new BinaryNotFoundException(); } TcmUri uri = new TcmUri(binaryMeta.PublicationId,binaryMeta.Id,16,0); Tridion.ContentDelivery.DynamicContent.BinaryFactory factory = new BinaryFactory(); BinaryData binaryData = string.IsNullOrEmpty(binaryMeta.VariantId) ? factory.GetBinary(uri.ToString()) : factory.GetBinary(uri.ToString(),binaryMeta.VariantId); return binaryData == null ? null : binaryData.Bytes; }
/// <summary> /// TreeNodePopulate event handler /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event arguments</param> public void PopulateNode(Object sender, TreeNodeEventArgs e) { XmlDocument doc = new XmlDocument(); TcmUri uri = new TcmUri(e.Node.Value); if (uri.IsUriNull) // the root node { PublicationsFilterData filter = new PublicationsFilterData(); XElement publications = _client.GetSystemWideListXml(filter); doc.Load(publications.CreateReader()); } else { switch (uri.ItemType) { case ItemType.Publication: PublicationData pub = (PublicationData)_client.Read(uri.ToString(), new ReadOptions()); TreeNode tnF = CreateTreeNode(pub.RootFolder.Title, pub.RootFolder.IdRef); TreeNode tnS = CreateTreeNode(pub.RootStructureGroup.Title, pub.RootStructureGroup.IdRef); TreeNode tnC = CreateTreeNode("Categories and Keywords", string.Format("tcm:{0}-0-131200", uri.ItemId)); if (tnF != null) { e.Node.ChildNodes.Add(tnF); } if (tnS != null) { e.Node.ChildNodes.Add(tnS); } if (tnC != null) { e.Node.ChildNodes.Add(tnC); } break; case ItemType.Folder: XElement items = _client.GetListXml(uri.ToString(), new OrganizationalItemItemsFilterData() { Recursive = false }); doc.Load(items.CreateReader()); break; case ItemType.WorkItem: // fake type id, representing the categories & keywords node! items = _client.GetListXml(string.Format("tcm:0-{0}-1", uri.PublicationId), new TaxonomiesFilterData()); doc.Load(items.CreateReader()); break; case ItemType.StructureGroup: items = _client.GetListXml(uri.ToString(), new OrganizationalItemItemsFilterData() { Recursive = false }); doc.Load(items.CreateReader()); break; case ItemType.Category: items = _client.GetListXml(uri.ToString(), new KeywordsFilterData() { IsRoot = true }); doc.Load(items.CreateReader()); break; case ItemType.Keyword: items = _client.GetListXml(uri.ToString(), new ChildKeywordsFilterData()); doc.Load(items.CreateReader()); break; default: break; } } foreach (XmlElement item in doc.SelectNodes("//tcm:Item", _nsMgr)) { TreeNode tNode = CreateTreeNode(item.GetAttribute("Title"), item.GetAttribute("ID")); if (tNode != null) { e.Node.ChildNodes.Add(tNode); } } }
public dynamic GetStructureGroup(TcmUri tcmUri) { return GetStructureGroup(tcmUri.ToString()); }
public dynamic GetStructureGroup(TcmUri tcmUri) { return(GetStructureGroup(tcmUri.ToString())); }
protected virtual void PublishItem(Item item, TcmUri itemUri) { Stream itemStream = null; // See if some template set itself as the applied template on this item TcmUri appliedTemplateUri = null; if (item.Properties.ContainsKey(Item.ItemPropertyTemplateUri)) { appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]); } try { string publishedPath; if (targetStructureGroupUri == null) { log.Debug("no structure group defined, publishing binary with default settings"); Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]); // Note: it is dangerous to specify the CT URI as variant ID without a structure group, because it will fail if you publish the same MMC from two or more CTs! // So I removed the variant ID altogether (QS, 20-10-2011) log.Debug(string.Format("publishing mm component {0} without variant id", mmComp.Id)); Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp); publishedPath = binary.Url; log.Debug(string.Format("binary is published to url {0}", publishedPath)); } else { Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]); string fileName = ConstructFileName(mmComp, currentTemplate.Id); StructureGroup targetSG = (StructureGroup)engine.GetObject(targetStructureGroupUri); itemStream = item.GetAsStream(); if (itemStream == null) { // All items can be converted to a stream? log.Error(String.Format("Cannot get item '{0}' as stream", itemUri.ToString())); } //byte[] data = new byte[itemStream.Length]; //itemStream.Read(data, 0, data.Length); //itemStream.Close(); log.Debug(string.Format("publishing mm component {0} to structure group {1} with variant id {2} and filename {3}", mmComp.Id, targetStructureGroupUri.ToString(), currentTemplate.Id, fileName)); Binary b = engine.PublishingContext.RenderedItem.AddBinary(item.GetAsStream(), fileName, targetSG, currentTemplate.Id, mmComp, mmComp.BinaryContent.MultimediaType.MimeType); publishedPath = b.Url; //publishedPath = engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroupUri, data, fileName); log.Debug(string.Format("binary is published to url {0}", publishedPath)); } log.Debug("binary published, published path = " + publishedPath); item.Properties[Item.ItemPropertyPublishedPath] = publishedPath; } finally { if (itemStream != null) itemStream.Close(); } }
public dynamic GetPage(TcmUri tcmUri) { return GetPage(tcmUri.ToString()); }
private XmlNode CreateComponentLink(XmlNode node, string componentTemplateUri, TcmUri item) { XmlElement componentLink = node.OwnerDocument.CreateElement("tridion", "ComponentLink", "http://tridion.com/"); componentLink.SetAttribute("PageURI", _package.GetByName("Page.ID").GetAsString()); componentLink.SetAttribute("ComponentURI", item.ToString()); componentLink.SetAttribute("TemplateURI", componentTemplateUri); componentLink.SetAttribute("LinkText", node.InnerXml); componentLink.SetAttribute("LinkAttributes", "title=\"" + node.Attributes["title", Constants.XlinkNamespace].Value + "\""); componentLink.SetAttribute("runat", "server"); componentLink.SetAttribute("TextOnFail", "true"); return componentLink; }
public string GetContent(string uri, string templateUri = "") { LoggerService.Debug(">>GetContent({0})", LoggingCategory.Performance, uri); TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); T.ComponentPresentationFactory cpFactory = GetComponentPresentationFactory(tcmUri.PublicationId); T.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) { LoggerService.Debug("<<GetContent({0}) - by ct id", LoggingCategory.Performance, uri); return(cp.Content); } } if (!string.IsNullOrEmpty(selectByOutputFormat)) { cp = cpFactory.GetComponentPresentationWithOutputFormat(tcmUri.ItemId, selectByOutputFormat); if (cp != null) { LoggerService.Debug("<<GetContent({0}) - by output format", LoggingCategory.Performance, uri); return(cp.Content); } } LoggerService.Debug("GetContent: about to get component presentations with Highst Priority for {0}", LoggingCategory.Performance, tcmUri.ToString()); cp = cpFactory.GetComponentPresentationWithHighestPriority(tcmUri.ItemId); LoggerService.Debug("GetContent: get component presentations with Highst Priority for {0}", LoggingCategory.Performance, tcmUri.ToString()); if (cp != null) { return(cp.Content); } LoggerService.Debug("<<GetContent({0}) - not found", LoggingCategory.Performance, uri); return(string.Empty); }
/// <summary> /// Gets a KeywordModel object. /// </summary> /// <param name="tcmUri">The TcmUri of the keyword to get.</param> /// <returns></returns> public dynamic GetKeyword(TcmUri tcmUri) { return GetKeyword(tcmUri.ToString()); }
private void ProcessImageComponent(XmlNode node) { TcmUri tcmUri = new TcmUri(node.Attributes["xlink:href"].Value); Item binaryItem = AddBinaryToPackage(tcmUri); Utilities.AddAttribute(node, XmlConstants.TRIDION_HREF_ATTRIB, Constants.TcmNamespace, tcmUri.ToString()); Utilities.AddAttribute(node, XmlConstants.TRIDION_TYPE_ATTRIB, Constants.TcmNamespace, XmlConstants.TRIDION_MULTIMEDIALINK_ATTRIBVAL); Utilities.AddAttribute(node, XmlConstants.TRIDION_TARGET_ATTRIB, Constants.TcmNamespace, XmlConstants.SRC); Utilities.AddAttribute(node, XmlConstants.SRC, String.Empty); }
public IPage GetPage(TcmUri pageId) { var page = _pageFactory.GetPage(pageId.ToString()); return(page); }
public string GetContent(string uri, string templateUri = "") { LoggerService.Debug(">>GetContent({0})", LoggingCategory.Performance, uri); TcmUri tcmUri = new TcmUri(uri); TcmUri templateTcmUri = new TcmUri(templateUri); T.ComponentPresentationFactory cpFactory = GetComponentPresentationFactory(tcmUri.PublicationId); T.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) { LoggerService.Debug("<<GetContent({0}) - by ct id", LoggingCategory.Performance, uri); return(cp.Content); } } if (!string.IsNullOrEmpty(selectByOutputFormat)) { cp = cpFactory.GetComponentPresentationWithOutputFormat(tcmUri.ItemId, selectByOutputFormat); if (cp != null) { LoggerService.Debug("<<GetContent({0}) - by output format", LoggingCategory.Performance, uri); return(cp.Content); } } LoggerService.Debug("GetContent: about to find all component presentations for {0}", LoggingCategory.Performance, tcmUri.ToString()); IList cps = cpFactory.FindAllComponentPresentations(tcmUri.ItemId); LoggerService.Debug("GetContent: found all component presentations for {0}", LoggingCategory.Performance, tcmUri.ToString()); foreach (Tridion.ContentDelivery.DynamicContent.ComponentPresentation _cp in cps) { if (_cp != null) { if (_cp.Content.Contains("<Component")) { LoggerService.Debug("<<GetContent({0}) - find all", LoggingCategory.Performance, uri); return(_cp.Content); } } } LoggerService.Debug("<<GetContent({0}) - not found", LoggingCategory.Performance, uri); return(string.Empty); }
public string GetVersionlessUri(string id) { TcmUri uri = new TcmUri(id); if (uri.IsVersionless) return id; uri = new TcmUri(uri.ItemId, uri.ItemType, uri.PublicationId); return uri.ToString(); }
public byte[] GetBinaryByUrl(string url) { string encodedUrl = HttpUtility.UrlPathEncode(url); // ?? why here? why now? IList metas = null; BinaryMeta binaryMeta = null; if (this.PublicationId == 0) { metas = BinaryMetaFactory.GetMetaByUrl(encodedUrl); if (metas.Count == 0) { throw new BinaryNotFoundException(); } binaryMeta = metas[0] as BinaryMeta; } else { binaryMeta = BinaryMetaFactory.GetMetaByUrl(this.PublicationId, encodedUrl); if (binaryMeta == null) { throw new BinaryNotFoundException(); } } TcmUri uri = new TcmUri(binaryMeta.PublicationId, binaryMeta.Id, 16, 0); Tridion.ContentDelivery.DynamicContent.BinaryFactory factory = new BinaryFactory(); BinaryData binaryData = string.IsNullOrEmpty(binaryMeta.VariantId) ? factory.GetBinary(uri.ToString()) : factory.GetBinary(uri.ToString(), binaryMeta.VariantId); return(binaryData == null ? null : binaryData.Bytes); }
internal string GetUriInBlueprintContext(string itemId, string publicationId) { if (TcmUri.UriNull == itemId) return null; TcmUri itemUri = new TcmUri(itemId); TcmUri publicationUri = new TcmUri(publicationId); TcmUri inContext = new TcmUri(itemUri.ItemId, itemUri.ItemType, publicationUri.ItemId); return inContext.ToString(); }
public static string StripTcmUri(this TcmUri tcmUri) { var tcm = tcmUri.ToString(); return(tcm.Replace(":", string.Empty).Replace("-", string.Empty)); }
/// <summary> /// Gets a KeywordModel object. /// </summary> /// <param name="tcmUri">The TcmUri of the keyword to get.</param> /// <returns></returns> public dynamic GetKeyword(TcmUri tcmUri) { return(GetKeyword(tcmUri.ToString())); }