/// <summary> /// BuildHyperLink /// </summary> /// <param name="bookID"></param> /// <param name="url"></param> /// <returns></returns> public Hyperlink BuildHyperLink(int bookID, string url, string tocId) { try { if (string.IsNullOrEmpty(url)) { return(null); } else if (IsExternalHyperlink(url)) { return(new ExternalHyperlink(BuildRemoteUrl(url, bookID))); } else if (IsAnchorHyperLink(url)) { return(new AnchorHyperlink(url)); } else { var queryParams = ValidateHelper.ParseUrl(url); if (queryParams == null) { if (currentBook != null) { string attachmentFileName = null; FileType fileType; if (IsAttachmentHyperlink(url, out attachmentFileName, out fileType)) { return(new AttachmentHyperlink(Path.Combine(currentBook.GetDirectory(), attachmentFileName), fileType)); } } } else if (queryParams != null && queryParams.Count > 0) { if (queryParams.ContainsKey(DLMapping.LINK_TEXT)) { if (queryParams[DLMapping.LINK_TEXT].Contains(DLMapping.SUBORDINATE_TEXT) && queryParams[DLMapping.LINK_TEXT].Contains(DLMapping.LEGISLATION_TEXT)) { return(new Hiddenlink()); } } //looseleaf://opendocument?linktype=urjpdf&citation=BC201109206&filename=1109206.pdf //looseleaf://...citeref?ctype=case&element=citefrag_span&decisiondate_year=2001&caseref_ID=cr000118&caseref_spanref=cr000118-001&reporter_value=nswlr&volume_num=53&page_num=198&LinkName=(2001) 53 NSWLR 198 //looseleaf://opendocument?dpsi=P-0098&refpt=CPV.RC1GD.64-01-600&remotekey1=REFPTID&service=DOC-ID&LinkName=[I 64.01.600] if (currentBook != null) { string dpsiCodeLink = queryParams.ContainsKey(DLMapping.ATRRIBUTE_DPSI) ? queryParams[DLMapping.ATRRIBUTE_DPSI] : "-9999"; string refptLink = queryParams.ContainsKey(DLMapping.ATRRIBUTE_REF_POINTER) ? queryParams[DLMapping.ATRRIBUTE_REF_POINTER] : "-9999"; bool isIntraHyperlink = (currentBook.DpsiCode.Equals(dpsiCodeLink)); if (isIntraHyperlink && !String.IsNullOrEmpty(tocId)) { int tocID = -1; if (int.TryParse(tocId, out tocID)) { return(new IntraHyperlink(tocID, refptLink)); } } else { string premiumKey = DLMapping.PREMIUM_PREFIX + dpsiCodeLink + "|" + refptLink; string standardKey = dpsiCodeLink + "|" + refptLink; DlBook targetDlbook = null; if (!interBookDictionary.ContainsKey(premiumKey) && !interBookDictionary.ContainsKey(standardKey)) { DlBook targetFtcDlbook = null; DlBook targetStandardDlbook = null; if (!intraBookLinkDictionary.ContainsKey(DLMapping.PREMIUM_PREFIX + dpsiCodeLink) && !dpsiCodeLink.StartsWith(DLMapping.PREMIUM_PREFIX)) { targetFtcDlbook = publicationAccess.GetDlBookByDpsiCode(GlobalAccess.Instance.UserCredential, DLMapping.PREMIUM_PREFIX + dpsiCodeLink); intraBookLinkDictionary.Add(DLMapping.PREMIUM_PREFIX + dpsiCodeLink, targetFtcDlbook); } else if (!dpsiCodeLink.StartsWith(DLMapping.PREMIUM_PREFIX)) { targetFtcDlbook = intraBookLinkDictionary[DLMapping.PREMIUM_PREFIX + dpsiCodeLink]; } if (!intraBookLinkDictionary.ContainsKey(dpsiCodeLink)) { targetStandardDlbook = publicationAccess.GetDlBookByDpsiCode(GlobalAccess.Instance.UserCredential, dpsiCodeLink); intraBookLinkDictionary.Add(dpsiCodeLink, targetStandardDlbook); } else { targetStandardDlbook = intraBookLinkDictionary[dpsiCodeLink]; } targetDlbook = GetBookByPriority(targetFtcDlbook, targetStandardDlbook, targetDlbook); if (targetDlbook != null) { if (!targetBookIdDictionary.ContainsKey(dpsiCodeLink)) { targetBookIdDictionary.Add(dpsiCodeLink, targetDlbook.BookId); } bool hasDownloaded = (targetDlbook.DlStatus == (short)DlStatusEnum.Downloaded); if (hasDownloaded) { var contentLinkDetail = packageAccess.GetTOCDetailByRemoteLinkID(targetDlbook.GetDecryptedDbFullName(), refptLink); if (contentLinkDetail != null) { interBookDictionary.Add(targetDlbook.DpsiCode + "|" + refptLink, contentLinkDetail); return(new InternalHyperlink(targetDlbook.BookId, contentLinkDetail.ID, refptLink)); } else { interBookDictionary.Add(targetDlbook.DpsiCode + "|" + refptLink, null); } } } } else if (interBookDictionary.ContainsKey(premiumKey)) { if (interBookDictionary[premiumKey] != null && targetBookIdDictionary.ContainsKey(dpsiCodeLink)) { return(new InternalHyperlink(targetBookIdDictionary[dpsiCodeLink], interBookDictionary[premiumKey].ID, refptLink)); } } else if (interBookDictionary.ContainsKey(standardKey)) { if (interBookDictionary[standardKey] != null && targetBookIdDictionary.ContainsKey(dpsiCodeLink)) { return(new InternalHyperlink(targetBookIdDictionary[dpsiCodeLink], interBookDictionary[standardKey].ID, refptLink)); } } } } var additionalQueryString = ValidateHelper.ConstructQueryString(queryParams); return(new ExternalHyperlink(BuildRemoteUrl(additionalQueryString, bookID))); } return(new ExternalHyperlink(url)); } } catch (Exception ex) { throw; } finally { } }