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); }
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); }
private static string ResolveComponentLink(TcmUri tcmUri, int localizationId = 0) { int publicationId = localizationId == 0 ? tcmUri.PublicationId : localizationId; ComponentLink linker = new ComponentLink(publicationId); Link link = linker.GetLink(tcmUri.ItemId); return link.IsResolved ? link.Url : null; }
/// <summary> /// Creates a new Link instance and returnes this as a string /// </summary> /// <param name="title">Attribute to include in the link as string</param> /// //example<a href="..">title</a> /// <param name="tcmuri">tcmUri of the Component as string</param> /// <returns>url string</returns> public static string ComponentLinkMethod(string tcmuri) { MI4TLogger.WriteLog(ELogLevel.INFO, "Entering method TridionDataHelper.ComponentLinkMethod"); ComponentLink componentLink = null; Link link = null; int publicationID; String linkUrl = string.Empty; try { publicationID = TridionDataHelper.GetContentRepositoryId(tcmuri); MI4TLogger.WriteLog(ELogLevel.DEBUG, "Publication ID: " + publicationID); componentLink = new ComponentLink(publicationID); link = componentLink.GetLink(tcmuri); MI4TLogger.WriteLog(ELogLevel.DEBUG, "ComponentLink: " + link); if (link.IsResolved) { linkUrl = link.Url; } MI4TLogger.WriteLog(ELogLevel.INFO, "Link URL : " + linkUrl); } catch (Exception ex) { MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace); } finally { componentLink.Dispose(); componentLink = null; link = null; } MI4TLogger.WriteLog(ELogLevel.INFO, "Exiting method TridionDataHelper.ComponentLinkMethod"); return(linkUrl); }
private static string ResolveComponentLink(Tridion.ContentManager.TcmUri tcmUri, Localization localization) { ComponentLink linker = new ComponentLink(GetPublicationUri(tcmUri, localization)); Link link = linker.GetLink(tcmUri.ItemId); return(link.IsResolved ? link.Url : null); }
private static string ResolveComponentLink(TcmUri tcmUri, int localizationId = 0) { int publicationId = localizationId == 0 ? tcmUri.PublicationId : localizationId; ComponentLink linker = new ComponentLink(publicationId); Link link = linker.GetLink(tcmUri.ItemId); return(link.IsResolved ? link.Url : null); }
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(); }
private static string ResolveComponentLink(string uri, int localizationId = 0) { //TODO should we have a single (static) link object? var linker = new ComponentLink(localizationId==0 ? GetPublicationIdFromUri(uri) : localizationId); var link = linker.GetLink(GetItemIdFromUri(uri)); return link.IsResolved ? link.Url : null; }
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(); }