/// <summary> Display search results in simple XML format </summary> /// <param name="Output"> Stream to which to write the text for this main writer </param> protected internal void display_search_results(TextWriter Output) { // Get the URL and network roots string url = SobekCM_Library_Settings.Image_URL; string network = SobekCM_Library_Settings.Image_Server_Network; string base_url = currentMode.Base_URL.Replace("sobekcm_data.aspx", ""); // Write the header first Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "); Output.WriteLine("<ResultSet Page=\"" + currentMode.Page + "\" Total=\"" + base.results_statistics.Total_Titles + "\">"); // Now, add XML for each title string lastBibID = string.Empty; foreach (iSearch_Title_Result thisResult in base.paged_results) { if (thisResult.BibID != lastBibID) { if (lastBibID.Length > 0) { Output.WriteLine("</TitleResult>"); } Output.WriteLine("<TitleResult ID=\"" + thisResult.BibID + "\">"); lastBibID = thisResult.BibID; } // Determine folder from BibID string folder = thisResult.BibID.Substring(0, 2) + "/" + thisResult.BibID.Substring(2, 2) + "/" + thisResult.BibID.Substring(4, 2) + "/" + thisResult.BibID.Substring(6, 2) + "/" + thisResult.BibID.Substring(8); // Now, add XML for each item for (int i = 0; i < thisResult.Item_Count; i++) { iSearch_Item_Result itemResult = thisResult.Get_Item(i); Output.WriteLine("\t<ItemResult ID=\"" + thisResult.BibID + "_" + itemResult.VID + "\">"); Output.Write("\t\t<Title>"); Write_XML(Output, itemResult.Title); Output.WriteLine("</Title>"); if (itemResult.PubDate.Length > 0) { Output.Write("\t\t<Date>"); Write_XML(Output, itemResult.PubDate); Output.WriteLine("</Date>"); } Output.WriteLine("\t\t<Location>"); Output.WriteLine("\t\t\t<URL>" + base_url + thisResult.BibID + "/" + itemResult.VID + "</URL>"); Output.WriteLine("\t\t\t<Folder type=\"web\">" + url + folder + "/" + itemResult.VID + "</Folder>"); Output.WriteLine("\t\t\t<Folder type=\"network\">" + network + folder.Replace("/", "\\") + "\\" + itemResult.VID + "</Folder>"); Output.WriteLine("\t\t</Location>"); Output.WriteLine("\t</ItemResult>"); } } if (base.paged_results.Count > 0) { Output.WriteLine("</TitleResult>"); } Output.WriteLine("</ResultSet>"); }
/// <summary> Writes the search or browse information in JSON format directly to the output stream </summary> /// <param name="Output"> Stream to which to write the JSON search or browse information </param> /// <param name="All_Items_Lookup"> Lookup object used to pull basic information about any item loaded into this library </param> protected internal void display_search_results(TextWriter Output) { // If results are null, or no results, return empty string if ((RequestSpecificValues.Paged_Results == null) || (RequestSpecificValues.Results_Statistics == null) || (RequestSpecificValues.Results_Statistics.Total_Items <= 0)) { return; } Output.Write("["); // Step through all the results int i = 1; foreach (iSearch_Title_Result titleResult in RequestSpecificValues.Paged_Results) { // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine a thumbnail string thumb = currentGreenstoneImageRoot + titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + firstItemResult.MainThumbnail; if ((thumb.ToUpper().IndexOf(".JPG") < 0) && (thumb.ToUpper().IndexOf(".GIF") < 0)) { thumb = Static_Resources_Gateway.Nothumb_Jpg; } thumb = thumb.Replace("\\", "/").Replace("//", "/").Replace("http:/", "http://"); // Was a previous item/title included here? if (i > 1) { Output.Write(","); } Output.Write("{\"collection_item\":{\"name\":\"" + firstItemResult.Title.Trim().Replace("\"", "'") + "\",\"url\":\"" + UI_ApplicationCache_Gateway.Settings.Servers.System_Base_URL + titleResult.BibID + "/" + firstItemResult.VID + "\",\"collection_code\":\"\",\"id\":\"" + titleResult.BibID + "_" + firstItemResult.VID + "\",\"thumb_url\":\"" + thumb + "\"}}"); i++; } Output.Write("]"); }
/// <summary> Writes the search or browse information in JSON format directly to the output stream </summary> /// <param name="Output"> Stream to which to write the JSON search or browse information </param> /// <param name="All_Items_Lookup"> Lookup object used to pull basic information about any item loaded into this library </param> protected internal void display_search_results(TextWriter Output, Item_Lookup_Object All_Items_Lookup) { // If results are null, or no results, return empty string if ((paged_results == null) || (results_statistics == null) || (results_statistics.Total_Items <= 0)) { return; } Output.Write("["); // Step through all the results int i = 1; foreach (iSearch_Title_Result titleResult in paged_results) { // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine a thumbnail string thumb = currentGreenstoneImageRoot + titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + firstItemResult.MainThumbnail; if ((thumb.ToUpper().IndexOf(".JPG") < 0) && (thumb.ToUpper().IndexOf(".GIF") < 0)) { thumb = currentMode.Default_Images_URL + "NoThumb.jpg"; } thumb = thumb.Replace("\\", "/").Replace("//", "/").Replace("http:/", "http://"); // Was a previous item/title included here? if (i > 1) { Output.Write(","); } Output.Write("{\"collection_item\":{\"name\":\"" + firstItemResult.Title.Trim().Replace("\"", "'") + "\",\"url\":\"" + SobekCM_Library_Settings.System_Base_URL + titleResult.BibID + "/" + firstItemResult.VID + "\",\"collection_code\":\"\",\"id\":\"" + titleResult.BibID + "_" + firstItemResult.VID + "\",\"thumb_url\":\"" + thumb + "\"}}"); i++; } Output.Write("]"); }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="MainPlaceHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder MainPlaceHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Custom_Thumbnail_ResultsViewer.Add_HTML", "Rendering results in thumbnail view"); } // If results are null, or no results, return empty string if ((PagedResults == null) || (ResultsStats == null) || (ResultsStats.Total_Items <= 0)) { return; } // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = RequestSpecificValues.Current_Mode.Base_URL; if (RequestSpecificValues.Current_Mode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = RequestSpecificValues.Current_Mode.Base_URL + "l/"; } // Should the publication date be shown? bool showDate = RequestSpecificValues.Current_Mode.Sort >= 10; // Start this table StringBuilder resultsBldr = new StringBuilder(5000); //Add the necessary JavaScript, CSS files resultsBldr.AppendLine(" <script type=\"text/javascript\" src=\"" + Static_Resources_Gateway.Sobekcm_Thumb_Results_Js + "\"></script>"); // Start this table resultsBldr.AppendLine("<div style=\"width:80%;margin-left:auto;margin-right:auto\">"); resultsBldr.AppendLine("<h2>Timeline View</h2>"); foreach (iSearch_Title_Result titleResult in PagedResults) { bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if ((RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Aggregation) && (RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Browse_Info)) { internal_link = base_url + titleResult.BibID + textRedirectStem; } string title; if (multiple_title) { // Determine term to use string multi_term = "volume"; if (titleResult.MaterialType.ToUpper() == "NEWSPAPER") { multi_term = titleResult.Item_Count > 1 ? "issues" : "issue"; } else { if (titleResult.Item_Count > 1) { multi_term = "volumes"; } } if ((showDate)) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + titleResult.GroupTitle; } else { title = titleResult.GroupTitle; } } else { title = titleResult.GroupTitle + "<br />( " + titleResult.Item_Count + " " + multi_term + " )"; } } else { if (showDate) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + firstItemResult.Title; } else { title = firstItemResult.Title; } } else { title = firstItemResult.Title; } } // Add the title resultsBldr.AppendLine("<a href=\"" + internal_link + "\">" + title + "</a><br />"); } // End this div resultsBldr.AppendLine("</div>"); // Add this to the html table Literal mainLiteral = new Literal { Text = resultsBldr.ToString() }; MainPlaceHolder.Controls.Add(mainLiteral); }
protected void Write_Single_Row(StringBuilder resultsBldr, iSearch_Title_Result titleRow, int index_in_page, string textRedirectStem, string base_url, bool internal_user) { // Start this row resultsBldr.AppendLine("\t<tr valign=\"top\">"); iSearch_Item_Result itemRow = titleRow.Get_Item(0); string identifier = titleRow.BibID.ToUpper() + "_" + itemRow.VID; // Add the actions as the first column resultsBldr.Append("\t\t<td class=\"SobekFolderActionLink\" width=\"170px\" >( "); resultsBldr.Append("<a title=\"Remove this item from your bookshelf\" href=\"\" onclick=\"return remove_item( '" + identifier + "' );\">remove</a> | "); resultsBldr.Append("<a title=\"Move this item to a new bookshelf\" href=\"\" name=\"item_move_" + index_in_page + "\" id=\"item_move_" + index_in_page + "\" onclick=\"return move_form_open('item_move_" + index_in_page + "', '" + identifier + "' );\">move</a> | "); resultsBldr.Append("<a title=\"Send this item to a friend\" href=\"\" name=\"item_send_" + index_in_page + "\" id=\"item_send_" + index_in_page + "\" onclick=\"return email_form_open('item_send_" + index_in_page + "', '" + identifier + "' );\">send</a>"); if (internal_user) { resultsBldr.Append(" | <a title=\"Edit this item\" href=\"" + RequestSpecificValues.Current_Mode.Base_URL + "my/edit/" + titleRow.BibID + "/" + itemRow.VID + "\" name=\"item_edit_" + index_in_page + "\" id=\"item_edit_" + index_in_page + "\" >edit</a> )</td>\n"); } else { resultsBldr.AppendLine(" ) </td>"); } // Add the check box resultsBldr.AppendLine("\t\t<td><input title=\"Select or unselect this item\" type=\"checkbox\" name=\"item_select_" + index_in_page.ToString() + "\" id=\"item_select_" + index_in_page.ToString() + "\" value=\"" + identifier + "\" /></td>"); string user_notes = titleRow.UserNotes; // Add the title and user notes next resultsBldr.Append("\t\t<td><a href=\"" + base_url + titleRow.BibID + "/" + itemRow.VID + textRedirectStem + "\">" + itemRow.Title); if ((itemRow.Level1_Text.Length > 0) || (itemRow.Level2_Text.Length > 0) || (itemRow.Level3_Text.Length > 0)) { resultsBldr.Append(" ( "); if (itemRow.Level1_Text.Length > 0) { resultsBldr.Append(itemRow.Level1_Text); } if (itemRow.Level2_Text.Length > 0) { resultsBldr.Append(" - " + itemRow.Level2_Text); } if (itemRow.Level3_Text.Length > 0) { resultsBldr.Append(" - " + itemRow.Level3_Text); } resultsBldr.Append(" ) "); } resultsBldr.AppendLine("</a>"); if (!String.IsNullOrEmpty(user_notes)) { resultsBldr.AppendLine("<br />" + user_notes + " <span class=\"SobekFolderActionLink\">( <a href=\"\" onclick=\"return edit_notes_form_open('item_send_" + index_in_page + "', '" + identifier + "','" + user_notes.Replace("\"", "%22").Replace("'", "%27").Replace("=", "%3D").Replace("&", "%26") + "' );\">edit note</a> )</span></td>"); } else { resultsBldr.AppendLine("<br /><span class=\"SobekFolderActionLink\">( <a href=\"\" onclick=\"return edit_notes_form_open('item_send_" + index_in_page + "', '" + identifier + "','' );\" >add note</a> )</span></td>"); } // End this row resultsBldr.AppendLine("\t</tr>"); }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="placeHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder placeHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Export_File_ResultsViewer.Add_HTML", "Rendering results in text view"); } //// Sort this by BIbID //resultTable.Sort("BibID"); //// Determine which rows to display //int lastRow = base.LastRow; //int startRow = base.StartRow(lastRow); //// prepare to step through each title to display //List<SobekCM_Item_Collection.SobekCM_Item_Row> itemRows = new List<SobekCM_Item_Collection.SobekCM_Item_Row>(); // Prepare to build an output StringBuilder resultsBldr = new StringBuilder(5000); int currentPage = RequestSpecificValues.Current_Mode.Page.HasValue ? RequestSpecificValues.Current_Mode.Page.Value : 1; if (currentPage < 2) { resultsBldr.Append("<br />" + Environment.NewLine + "<div class=\"SobekHomeText\">" + Environment.NewLine + "<blockquote>" + Environment.NewLine); resultsBldr.Append("This option allows you to export the list of results which match your search or browse to an excel document or CSV file for download.<br /><br />"); resultsBldr.Append("Select the file type below to create the report:"); resultsBldr.Append("<blockquote>"); //currentMode.Page = 2; //resultsBldr.Append("<a href=\"" + currentMode.Redirect_URL() + "\">Excel Spreadsheet file (XLSX)</a><br /><br />"); RequestSpecificValues.Current_Mode.Page = 3; resultsBldr.Append("<a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode) + "\">Excel Spreadsheet file (XLS)</a><br /><br />"); RequestSpecificValues.Current_Mode.Page = 4; resultsBldr.Append("<a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode) + "\">Comma-seperated value text file (CSV)</a><br /><br />"); //currentMode.Page = 5; //resultsBldr.Append("<a href=\"" + currentMode.Redirect_URL() + "\">HTML Table (HTML)</a><br /><br />"); resultsBldr.Append("</blockquote>"); resultsBldr.Append("</blockquote>"); resultsBldr.Append("<br /><br />"); resultsBldr.Append("</div>"); // Add this to the page Literal mainLiteral = new Literal { Text = resultsBldr.ToString() }; placeHolder.Controls.Add(mainLiteral); } else { string filename = RequestSpecificValues.Current_Mode.Instance_Name; // Set the Gembox spreadsheet license key string from_db = String.Empty; string key = String.Empty; if (UI_ApplicationCache_Gateway.Settings.Contains_Additional_Setting("Spreadsheet Library License")) { try { key = UI_ApplicationCache_Gateway.Settings.Get_Additional_Setting("Spreadsheet Library License"); SecurityInfo thisDecryptor = new SecurityInfo(); string encryptedPassword = thisDecryptor.DecryptString(from_db, "*h3kj(83", "unsalted"); } catch (Exception) { } } SpreadsheetInfo.SetLicense(key); // Create the excel file and worksheet ExcelFile excelFile = new ExcelFile(); ExcelWorksheet excelSheet = excelFile.Worksheets.Add(RequestSpecificValues.Current_Mode.Instance_Name); excelFile.Worksheets.ActiveWorksheet = excelSheet; // Create the header cell style CellStyle headerStyle = new CellStyle { HorizontalAlignment = HorizontalAlignmentStyle.Left, Font = { Weight = ExcelFont.BoldWeight } }; headerStyle.FillPattern.SetSolid(Color.Yellow); headerStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin); // Create the title cell style CellStyle titleStyle = new CellStyle { HorizontalAlignment = HorizontalAlignmentStyle.Left, Font = { Weight = ExcelFont.BoldWeight, Size = 12 * 20 } }; // Set the default style CellStyle defaultStyle = new CellStyle(); defaultStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin); const int columnSelector = 0; int row = 0; if (RequestSpecificValues.Current_Mode.Page != 4) { // Add the title excelSheet.Cells[1, columnSelector].Value = "Search or browse result list"; excelSheet.Cells[1, columnSelector].Style = titleStyle; row = 3; } // Add the column headers excelSheet.Cells[row, columnSelector].Value = "System ID"; excelSheet.Cells[row, columnSelector].Style = headerStyle; excelSheet.Cells[row, columnSelector + 1].Value = "Link"; excelSheet.Cells[row, columnSelector + 1].Style = headerStyle; excelSheet.Cells[row, columnSelector + 2].Value = "Group Title"; excelSheet.Cells[row, columnSelector + 2].Style = headerStyle; excelSheet.Cells[row, columnSelector + 3].Value = "Item Title"; excelSheet.Cells[row, columnSelector + 3].Style = headerStyle; excelSheet.Cells[row, columnSelector + 4].Value = "Date"; excelSheet.Cells[row, columnSelector + 4].Style = headerStyle; excelSheet.Cells[row, columnSelector + 5].Value = "Author"; excelSheet.Cells[row, columnSelector + 5].Style = headerStyle; excelSheet.Cells[row, columnSelector + 6].Value = "Publisher"; excelSheet.Cells[row, columnSelector + 6].Style = headerStyle; excelSheet.Cells[row, columnSelector + 7].Value = "Format"; excelSheet.Cells[row, columnSelector + 7].Style = headerStyle; excelSheet.Cells[row, columnSelector + 8].Value = "Edition"; excelSheet.Cells[row, columnSelector + 8].Style = headerStyle; excelSheet.Cells[row, columnSelector + 9].Value = "Subjects"; excelSheet.Cells[row, columnSelector + 9].Style = headerStyle; excelSheet.Cells[row, columnSelector + 10].Value = "Measurement"; excelSheet.Cells[row, columnSelector + 10].Style = headerStyle; excelSheet.Cells[row, columnSelector + 11].Value = "Style / Period"; excelSheet.Cells[row, columnSelector + 11].Style = headerStyle; excelSheet.Cells[row, columnSelector + 12].Value = "Technique"; excelSheet.Cells[row, columnSelector + 12].Style = headerStyle; excelSheet.Cells[row, columnSelector + 13].Value = "Institution"; excelSheet.Cells[row, columnSelector + 13].Style = headerStyle; excelSheet.Cells[row, columnSelector + 14].Value = "Donor"; excelSheet.Cells[row, columnSelector + 14].Style = headerStyle; excelSheet.Cells[row, columnSelector + 15].Value = "OCLC"; excelSheet.Cells[row, columnSelector + 15].Style = headerStyle; excelSheet.Cells[row, columnSelector + 16].Value = "ALEPH"; excelSheet.Cells[row, columnSelector + 16].Style = headerStyle; excelSheet.Cells[row, columnSelector + 17].Value = "Serial1"; excelSheet.Cells[row, columnSelector + 17].Style = headerStyle; excelSheet.Cells[row, columnSelector + 18].Value = "Serial2"; excelSheet.Cells[row, columnSelector + 18].Style = headerStyle; excelSheet.Cells[row, columnSelector + 19].Value = "Serial3"; excelSheet.Cells[row, columnSelector + 19].Style = headerStyle; // Set the correct widths excelSheet.Columns[columnSelector].Width = 12 * 256; excelSheet.Columns[columnSelector + 1].Width = 8 * 256; excelSheet.Columns[columnSelector + 2].Width = 40 * 256; excelSheet.Columns[columnSelector + 3].Width = 40 * 256; excelSheet.Columns[columnSelector + 4].Width = 20 * 256; excelSheet.Columns[columnSelector + 5].Width = 14 * 256; excelSheet.Columns[columnSelector + 6].Width = 14 * 256; excelSheet.Columns[columnSelector + 7].Width = 20 * 256; excelSheet.Columns[columnSelector + 8].Width = 20 * 256; excelSheet.Columns[columnSelector + 9].Width = 20 * 256; excelSheet.Columns[columnSelector + 10].Width = 20 * 256; excelSheet.Columns[columnSelector + 11].Width = 20 * 256; excelSheet.Columns[columnSelector + 12].Width = 20 * 256; excelSheet.Columns[columnSelector + 13].Width = 20 * 256; excelSheet.Columns[columnSelector + 14].Width = 20 * 256; excelSheet.Columns[columnSelector + 15].Width = 20 * 256; excelSheet.Columns[columnSelector + 16].Width = 20 * 256; excelSheet.Columns[columnSelector + 17].Width = 20 * 256; excelSheet.Columns[columnSelector + 18].Width = 20 * 256; excelSheet.Columns[columnSelector + 19].Width = 20 * 256; row++; // Add each row foreach (iSearch_Title_Result titleResult in PagedResults) { for (int item_count = 0; item_count < titleResult.Item_Count; item_count++) { iSearch_Item_Result itemResult = titleResult.Get_Item(item_count); excelSheet.Cells[row, columnSelector].Value = titleResult.BibID + "_" + itemResult.VID; excelSheet.Cells[row, columnSelector + 1].Value = RequestSpecificValues.Current_Mode.Base_URL + titleResult.BibID + "/" + itemResult.VID; excelSheet.Cells[row, columnSelector + 2].Value = titleResult.GroupTitle.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); excelSheet.Cells[row, columnSelector + 3].Value = itemResult.Title.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 4].Value = itemResult.PubDate.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 5].Value = titleResult.Author.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 6].Value = titleResult.Publisher.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 7].Value = titleResult.Format.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 8].Value = titleResult.Edition.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 9].Value = titleResult.Subjects.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 10].Value = titleResult.Measurement.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 11].Value = titleResult.Style_Period.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 12].Value = titleResult.Technique.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 13].Value = titleResult.Institution.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 14].Value = titleResult.Donor.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //if (titleResult.OCLC_Number > 1) // excelSheet.Cells[row, columnSelector + 15].Value = titleResult.OCLC_Number.ToString(); //if (titleResult.ALEPH_Number > 1) // excelSheet.Cells[row, columnSelector + 16].Value = titleResult.ALEPH_Number.ToString(); //excelSheet.Cells[row, columnSelector + 17].Value = itemResult.Level1_Text.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 18].Value = itemResult.Level2_Text.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); //excelSheet.Cells[row, columnSelector + 19].Value = itemResult.Level3_Text.Replace("<i>", "").Replace("</i>", "").Replace("&", "&"); row++; } } // Set the border excelSheet.Cells.GetSubrange("A4", "T" + row).SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Medium); excelSheet.Cells.GetSubrange("A4", "t4").SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Medium); if (Tracer != null) { Tracer.Add_Trace("Export_File_ResultsViewer.Add_HTML", "Clearing response"); } // Clear any response until now HttpContext.Current.Response.Clear(); // Output in proper format to the user switch (RequestSpecificValues.Current_Mode.Page) { //case 2: // System.Web.HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats"; // System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".xlsx"); // // With XLSX it is a bit more complicated as MS Packaging API can't write // // directly to Response.OutputStream. Therefore we use temporary MemoryStream. // System.IO.MemoryStream ms = new System.IO.MemoryStream(); // excelFile.SaveXlsx(ms); // ms.WriteTo(System.Web.HttpContext.Current.Response.OutputStream); // break; case 3: HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".xls"); excelFile.SaveXls(HttpContext.Current.Response.OutputStream); break; case 4: HttpContext.Current.Response.ContentType = "text/csv"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".csv"); excelFile.SaveCsv(HttpContext.Current.Response.OutputStream, CsvType.CommaDelimited); break; //case 5: // System.Web.HttpContext.Current.Response.ContentType = "text/html"; // System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + "Report18.html"); // System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(System.Web.HttpContext.Current.Response.OutputStream, new UTF8Encoding(false)); // excelFile.SaveHtml(writer, null, true); // writer.Close(); // break; } if (Tracer != null) { Tracer.Add_Trace("Export_File_ResultsViewer.Add_HTML", "Ending response"); } HttpContext.Current.Response.End(); } }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="MainPlaceHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder MainPlaceHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Thumbnail_ResultsWriter.Add_HTML", "Rendering results in thumbnail view"); } // If results are null, or no results, return empty string if ((Paged_Results == null) || (Results_Statistics == null) || (Results_Statistics.Total_Items <= 0)) { return; } // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = CurrentMode.Base_URL; if (CurrentMode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = CurrentMode.Base_URL + "l/"; } // Should the publication date be shown? bool showDate = false; if (CurrentMode.Sort >= 10) { showDate = true; } // Start this table StringBuilder resultsBldr = new StringBuilder(5000); //Add the necessary JavaScript, CSS files //resultsBldr.AppendLine("<script type=\"text/javascript\" src=\"" + CurrentMode.Base_URL + "default/scripts/jquery/jquery-1.10.2.min.js\"></script>"); //resultsBldr.AppendLine("<script type=\"text/javascript\" src=\"" + CurrentMode.Base_URL + "default/scripts/jquery/jquery.qtip.min.js\"></script>"); //resultsBldr.AppendLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + CurrentMode.Base_URL + "default/scripts/jquery/jquery.qtip.min.css\" /> "); // resultsBldr.AppendLine("<script type=\"text/javascript\" src=\"" + CurrentMode.Base_URL + "default/scripts/jquery/jquery-ui-1.10.1.js\"></script>"); resultsBldr.AppendLine(" <script type=\"text/javascript\" src=\"" + CurrentMode.Base_URL + "default/scripts/sobekcm_thumb_results.js\"></script>"); // Start this table resultsBldr.AppendLine("<table align=\"center\" width=\"100%\" cellspacing=\"15px\">"); resultsBldr.AppendLine("\t<tr>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t</tr>"); resultsBldr.AppendLine("\t<tr valign=\"top\">"); // Step through all the results int col = 0; int title_count = 0; foreach (iSearch_Title_Result titleResult in Paged_Results) { title_count++; // Should a new row be started if (col == 4) { col = 0; resultsBldr.AppendLine("\t</tr>"); // Horizontal Line resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"4\"></td></tr>"); resultsBldr.AppendLine("\t<tr valign=\"top\">"); } bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if ((CurrentMode.Mode == Display_Mode_Enum.Aggregation) && (CurrentMode.Aggregation_Type == Aggregation_Type_Enum.Browse_Info)) { internal_link = base_url + titleResult.BibID + textRedirectStem; } resultsBldr.AppendLine("\t\t<td align=\"center\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" onclick=\"window.location.href='" + internal_link + "';\" >"); string title; if (multiple_title) { // Determine term to use string multi_term = "volume"; if (titleResult.MaterialType.ToUpper() == "NEWSPAPER") { multi_term = titleResult.Item_Count > 1 ? "issues" : "issue"; } else { if (titleResult.Item_Count > 1) { multi_term = "volumes"; } } if ((showDate)) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + titleResult.GroupTitle; } else { title = titleResult.GroupTitle; } } else { title = titleResult.GroupTitle + "<br />( " + titleResult.Item_Count + " " + multi_term + " )"; } } else { if (showDate) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + firstItemResult.Title; } else { title = firstItemResult.Title; } } else { title = firstItemResult.Title; } } // Start the HTML for this item resultsBldr.AppendLine("<table width=\"150px\">"); //// Is this restricted? bool restricted_by_ip = false; if ((titleResult.Item_Count == 1) && (firstItemResult.IP_Restriction_Mask > 0)) { int comparison = firstItemResult.IP_Restriction_Mask & current_user_mask; if (comparison == 0) { restricted_by_ip = true; } } // Calculate the thumbnail // Add the thumbnail if ((firstItemResult.MainThumbnail.ToUpper().IndexOf(".JPG") < 0) && (firstItemResult.MainThumbnail.ToUpper().IndexOf(".GIF") < 0)) { resultsBldr.AppendLine("<tr><td><span id=\"sbkThumbnailSpan" + title_count + "\"><a href=\"" + internal_link + "\"><img id=\"sbkThumbnailImg" + title_count + "\" src=\"" + CurrentMode.Default_Images_URL + "NoThumb.jpg\" /></a></span></td></tr>"); } else { string thumb = SobekCM_Library_Settings.Image_URL + titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + (firstItemResult.MainThumbnail).Replace("\\", "/").Replace("//", "/"); resultsBldr.AppendLine("<tr><td><span id=\"sbkThumbnailSpan" + title_count + "\"><a href=\"" + internal_link + "\"><img id=\"sbkThumbnailImg" + title_count + "\"src=\"" + thumb + "\" alt=\"MISSING THUMBNAIL\" /></a></span></td></tr>"); } #region Add the div displayed as a tooltip for this thumbnail on hover const string VARIES_STRING = "<span style=\"color:Gray\">( varies )</span>"; //Add the hidden item values for display in the tooltip resultsBldr.AppendLine("<tr style=\"display:none;\"><td colspan=\"100%\"><div id=\"descThumbnail" + title_count + "\" >"); // Add each element to this table resultsBldr.AppendLine("\t\t\t<table cellspacing=\"0px\">"); if (multiple_title) { //<a href=\"" + internal_link + "\"> resultsBldr.AppendLine("\t\t\t\t<tr style=\"height:40px;\" valign=\"middle\"><td colspan=\"3\"><span class=\"qtip_BriefTitle\" style=\"color: #a5a5a5;font-weight: bold;font-size:13px;\">" + titleResult.GroupTitle.Replace("<", "<").Replace(">", ">") + "</span> </td></tr>"); resultsBldr.AppendLine("<tr><td colspan=\"100%\"><br/></td></tr>"); } else { resultsBldr.AppendLine( "\t\t\t\t<tr style=\"height:40px;\" valign=\"middle\"><td colspan=\"3\"><span class=\"qtip_BriefTitle\" style=\"color: #a5a5a5;font-weight: bold;font-size:13px;\">" + firstItemResult.Title.Replace("<", "<").Replace(">", ">") + "</span> </td></tr><br/>"); resultsBldr.AppendLine("<tr><td colspan=\"100%\"><br/></td></tr>"); } if ((titleResult.Primary_Identifier_Type.Length > 0) && (titleResult.Primary_Identifier.Length > 0)) { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(titleResult.Primary_Identifier_Type, CurrentMode.Language) + ":</td><td> </td><td>" + System.Web.HttpUtility.HtmlDecode(titleResult.Primary_Identifier) + "</td></tr>"); } if (CurrentMode.Internal_User) { resultsBldr.AppendLine("\t\t\t\t<tr><td>BibID:</td><td> </td><td>" + titleResult.BibID + "</td></tr>"); if (titleResult.OPAC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<tr><td>OPAC:</td><td> </td><td>" + titleResult.OPAC_Number + "</td></tr>"); } if (titleResult.OCLC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<tr><td>OCLC:</td><td> </td><td>" + titleResult.OCLC_Number + "</td></tr>"); } } for (int i = 0; i < Results_Statistics.Metadata_Labels.Count; i++) { string field = Results_Statistics.Metadata_Labels[i]; string value = titleResult.Metadata_Display_Values[i]; Metadata_Search_Field thisField = SobekCM_Library_Settings.Metadata_Search_Field_By_Name(field); string display_field = string.Empty; if (thisField != null) { display_field = thisField.Display_Term; } if (display_field.Length == 0) { display_field = field.Replace("_", " "); } if (value == "*") { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>" + System.Web.HttpUtility.HtmlDecode(VARIES_STRING) + "</td></tr>"); } else if (value.Trim().Length > 0) { if (value.IndexOf("|") > 0) { bool value_found = false; string[] value_split = value.Split("|".ToCharArray()); foreach (string thisValue in value_split) { if (thisValue.Trim().Trim().Length > 0) { if (!value_found) { resultsBldr.AppendLine("\t\t\t\t<tr valign=\"top\"><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>"); value_found = true; } resultsBldr.Append(System.Web.HttpUtility.HtmlDecode(thisValue) + "<br />"); } } if (value_found) { resultsBldr.AppendLine("</td></tr>"); } } else { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>" + System.Web.HttpUtility.HtmlDecode(value) + "</td></tr>"); } } } if (titleResult.Snippet.Length > 0) { resultsBldr.AppendLine("\t\t\t\t<tr><td colspan=\"3\"><br />“..." + titleResult.Snippet.Replace("<em>", "<span class=\"texthighlight\">").Replace("</em>", "</span>") + "...”</td></tr>"); } resultsBldr.AppendLine("\t\t\t</table>"); // End this row // resultsBldr.AppendLine("\t\t<br />"); //// Add children, if there are some //if (multiple_title) //{ // // Add this to the place holder // Literal thisLiteral = new Literal // { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace( "</role>", "</i>") }; // MainPlaceHolder.Controls.Add(thisLiteral); // resultsBldr.Remove(0, resultsBldr.Length); // Add_Issue_Tree(MainPlaceHolder, titleResult, current_row, textRedirectStem, base_url); //} //resultsBldr.AppendLine("\t\t</td>"); //resultsBldr.AppendLine("\t</tr>"); // Add a horizontal line // resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>"); // End this table // resultsBldr.AppendLine("</table>"); resultsBldr.AppendLine("</div></td></tr>"); #endregion // Add the title resultsBldr.AppendLine("<tr><td align=\"center\"><span class=\"SobekThumbnailText\">" + title + "</span></td></tr>"); // If this was access restricted, add that if (restricted_by_ip) { resultsBldr.AppendLine("<tr><td align=\"center\"><span class=\"RestrictedItemText\">Access Restricted</span></td></tr>"); } // Finish this one thumbnail resultsBldr.AppendLine("</table></td>"); col++; } // Finish this row out while (col < 4) { resultsBldr.AppendLine("\t\t<td> </td>"); col++; } // End this table resultsBldr.AppendLine("\t</tr>"); resultsBldr.AppendLine("</table>"); // Add this to the html table Literal mainLiteral = new Literal { Text = resultsBldr.ToString() }; MainPlaceHolder.Controls.Add(mainLiteral); }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="MainPlaceHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder MainPlaceHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Brief_ResultsWriter.Add_HTML", "Rendering results in brief view"); } // If results are null, or no results, return empty string if ((PagedResults == null) || (ResultsStats == null) || (ResultsStats.Total_Items <= 0)) { return; } const string VARIES_STRING = "<span style=\"color:Gray\">( varies )</span>"; // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = RequestSpecificValues.Current_Mode.Base_URL; if (RequestSpecificValues.Current_Mode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = RequestSpecificValues.Current_Mode.Base_URL + "l/"; } // Start the results StringBuilder resultsBldr = new StringBuilder(2000); resultsBldr.AppendLine("<section class=\"sbkBrv_Results\">"); // Set the counter for these results from the page int current_page = RequestSpecificValues.Current_Mode.Page.HasValue ? RequestSpecificValues.Current_Mode.Page.Value : 1; int result_counter = ((current_page - 1) * Results_Per_Page) + 1; Tracer.Add_Trace("Brief_ResultsViewer.Add_HTML", "There are [" + PagedResults.Count + "] results @ [" + Results_Per_Page + "] per page."); // Step through all the results int current_row = 0; foreach (iSearch_Title_Result titleResult in PagedResults) { bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Aggregation) // browse info only { internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; } // Start this row string title = firstItemResult.Title.Replace("<", "<").Replace(">", ">"); if (multiple_title) { title = titleResult.GroupTitle.Replace("<", "<").Replace(">", ">"); resultsBldr.AppendLine("\t<section class=\"sbkBrv_SingleResult\">"); } else { resultsBldr.AppendLine("\t<section class=\"sbkBrv_SingleResult\" onclick=\"window.location.href='" + internal_link.Replace("'", "\\'") + "';\" >"); } // Add the counter as the first column resultsBldr.AppendLine("\t\t<div class=\"sbkBrv_SingleResultNum\">" + result_counter + "</div>"); resultsBldr.Append("\t\t<div class=\"sbkBrv_SingleResultThumb\">"); //// Is this restricted? bool restricted_by_ip = false; if ((titleResult.Item_Count == 1) && (firstItemResult.IP_Restriction_Mask > 0)) { int comparison = firstItemResult.IP_Restriction_Mask & CurrentUserMask; if (comparison == 0) { restricted_by_ip = true; } } // Calculate the thumbnail string thumb = titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + (firstItemResult.MainThumbnail).Replace("\\", "/").Replace("//", "/"); // Draw the thumbnail if ((thumb.ToUpper().IndexOf(".JPG") < 0) && (thumb.ToUpper().IndexOf(".GIF") < 0)) { resultsBldr.AppendLine("<a href=\"" + internal_link + "\"><img src=\"" + Static_Resources_Gateway.Nothumb_Jpg + "\" border=\"0px\" class=\"resultsThumbnail\" alt=\"MISSING THUMBNAIL\" /></a></div>"); } else { resultsBldr.AppendLine("<a href=\"" + internal_link + "\"><img src=\"" + UI_ApplicationCache_Gateway.Settings.Servers.Image_URL + thumb + "\" class=\"resultsThumbnail\" alt=\"" + title.Replace("\"", "") + "\" /></a></div>"); } resultsBldr.AppendLine("\t\t<div class=\"sbkBrv_SingleResultDesc\">"); // If this was access restricted, add that if (restricted_by_ip) { resultsBldr.AppendLine("\t\t\t<span class=\"RestrictedItemText\">" + UI_ApplicationCache_Gateway.Translation.Get_Translation("Access Restricted", RequestSpecificValues.Current_Mode.Language) + "</span>"); } if (multiple_title) { resultsBldr.AppendLine("\t\t\t<span class=\"briefResultsTitle\"><a href=\"" + internal_link + "\">" + titleResult.GroupTitle.Replace("<", "<").Replace(">", ">") + "</a></span>"); } else { resultsBldr.AppendLine( "\t\t\t<span class=\"briefResultsTitle\"><a href=\"" + internal_link + "\" onclick=\"cancelPropagation(event);\">" + firstItemResult.Title.Replace("<", "<").Replace(">", ">") + "</a></span>"); } // Add each element to this table resultsBldr.AppendLine("\t\t\t<dl class=\"sbkBrv_SingleResultDescList\">"); if ((!String.IsNullOrEmpty(titleResult.Primary_Identifier_Type)) && (!String.IsNullOrEmpty(titleResult.Primary_Identifier))) { resultsBldr.AppendLine("\t\t\t\t<dt>" + UI_ApplicationCache_Gateway.Translation.Get_Translation(titleResult.Primary_Identifier_Type, RequestSpecificValues.Current_Mode.Language) + ":</dt><dd>" + titleResult.Primary_Identifier + "</dd>"); } if ((RequestSpecificValues.Current_User != null) && (RequestSpecificValues.Current_User.LoggedOn) && (RequestSpecificValues.Current_User.Is_Internal_User)) { resultsBldr.AppendLine("\t\t\t\t<dt>BibID:</dt><dd>" + titleResult.BibID + "</dd>"); if (titleResult.OPAC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<dt>OPAC:</dt><dd>" + titleResult.OPAC_Number + "</dd>"); } if (titleResult.OCLC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<dt>OCLC:</dt><dd>" + titleResult.OCLC_Number + "</dd>"); } } for (int i = 0; i < ResultsStats.Metadata_Labels.Count; i++) { string field = ResultsStats.Metadata_Labels[i]; // Somehow the metadata for this item did not fully save in the database. Break out, rather than // throw the exception if ((titleResult.Metadata_Display_Values == null) || (titleResult.Metadata_Display_Values.Length <= i)) { break; } string value = titleResult.Metadata_Display_Values[i]; Metadata_Search_Field thisField = UI_ApplicationCache_Gateway.Settings.Metadata_Search_Field_By_Name(field); string display_field = string.Empty; if (thisField != null) { display_field = thisField.Display_Term; } if (display_field.Length == 0) { display_field = field.Replace("_", " "); } if (value == "*") { resultsBldr.AppendLine("\t\t\t\t<dt>" + UI_ApplicationCache_Gateway.Translation.Get_Translation(display_field, RequestSpecificValues.Current_Mode.Language) + ":</dt><dd>" + HttpUtility.HtmlDecode(VARIES_STRING) + "</dd>"); } else if (value.Trim().Length > 0) { if (value.IndexOf("|") > 0) { bool value_found = false; string[] value_split = value.Split("|".ToCharArray()); foreach (string thisValue in value_split) { if (thisValue.Trim().Trim().Length > 0) { if (!value_found) { resultsBldr.Append("\t\t\t\t<dt>" + UI_ApplicationCache_Gateway.Translation.Get_Translation(display_field, RequestSpecificValues.Current_Mode.Language) + ":</dt>"); value_found = true; } resultsBldr.Append("<dd>" + HttpUtility.HtmlDecode(thisValue) + "</dd>"); } } if (value_found) { resultsBldr.AppendLine(); } } else { resultsBldr.AppendLine("\t\t\t\t<dt>" + UI_ApplicationCache_Gateway.Translation.Get_Translation(display_field, RequestSpecificValues.Current_Mode.Language) + ":</dt><dd>" + HttpUtility.HtmlDecode(value) + "</dd>"); } } } resultsBldr.AppendLine("\t\t\t</dl>"); if (!String.IsNullOrEmpty(titleResult.Snippet)) { resultsBldr.AppendLine("\t\t\t<div class=\"sbkBrv_SearchResultSnippet\">“..." + titleResult.Snippet.Replace("<em>", "<span class=\"texthighlight\">").Replace("</em>", "</span>") + "...”</div>"); } // Add children, if there are some if (multiple_title) { // Add this to the place holder Literal thisLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(thisLiteral); resultsBldr.Remove(0, resultsBldr.Length); Add_Issue_Tree(MainPlaceHolder, titleResult, current_row, textRedirectStem, base_url); } resultsBldr.AppendLine("\t\t</div>"); resultsBldr.AppendLine("\t</section>"); resultsBldr.AppendLine(); // Increment the result counters result_counter++; current_row++; } // End this table resultsBldr.AppendLine("</section>"); // Add this to the HTML page Literal mainLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(mainLiteral); }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="MainPlaceHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder MainPlaceHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Brief_ResultsWriter.Add_HTML", "Rendering results in brief view"); } // If results are null, or no results, return empty string if ((Paged_Results == null) || (Results_Statistics == null) || (Results_Statistics.Total_Items <= 0)) { return; } const string VARIES_STRING = "<span style=\"color:Gray\">( varies )</span>"; // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = CurrentMode.Base_URL; if (CurrentMode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = CurrentMode.Base_URL + "l/"; } // Start the results StringBuilder resultsBldr = new StringBuilder(2000); resultsBldr.AppendLine("<br />"); resultsBldr.AppendLine("<table>"); // Set the counter for these results from the page int result_counter = ((CurrentMode.Page - 1) * Results_Per_Page) + 1; // Step through all the results int current_row = 0; foreach (iSearch_Title_Result titleResult in Paged_Results) { bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if (CurrentMode.Mode == Display_Mode_Enum.Aggregation) // browse info only { internal_link = base_url + titleResult.BibID + textRedirectStem; } // Start this row if (multiple_title) { resultsBldr.AppendLine("\t<tr valign=\"top\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" >"); } else { resultsBldr.AppendLine("\t<tr valign=\"top\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" onclick=\"window.location.href='" + internal_link + "';\" >"); } // Add the counter as the first column resultsBldr.AppendLine("\t\t<td><br /><b>" + result_counter + "</b></td>\t\t<td valign=\"top\" width=\"150\">"); //// Is this restricted? bool restricted_by_ip = false; if ((titleResult.Item_Count == 1) && (firstItemResult.IP_Restriction_Mask > 0)) { int comparison = firstItemResult.IP_Restriction_Mask & current_user_mask; if (comparison == 0) { restricted_by_ip = true; } } // Calculate the thumbnail string thumb = titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + (firstItemResult.MainThumbnail).Replace("\\", "/").Replace("//", "/"); // Draw the thumbnail if ((thumb.ToUpper().IndexOf(".JPG") < 0) && (thumb.ToUpper().IndexOf(".GIF") < 0)) { resultsBldr.AppendLine("<a href=\"" + internal_link + "\"><img src=\"" + CurrentMode.Default_Images_URL + "NoThumb.jpg\" border=\"0px\" class=\"resultsThumbnail\" alt=\"MISSING THUMBNAIL\" /></a></td>"); } else { resultsBldr.AppendLine("<a href=\"" + internal_link + "\"><img src=\"" + SobekCM_Library_Settings.Image_URL + thumb + "\" class=\"resultsThumbnail\" alt=\"MISSING THUMBNAIL\" /></a></td>"); } resultsBldr.AppendLine("\t\t<td>"); // If this was access restricted, add that if (restricted_by_ip) { resultsBldr.AppendLine("<span class=\"RestrictedItemText\">" + Translator.Get_Translation("Access Restricted", CurrentMode.Language) + "</span>"); } // Add each element to this table resultsBldr.AppendLine("\t\t\t<table cellspacing=\"0px\">"); if (multiple_title) { resultsBldr.AppendLine("\t\t\t\t<tr style=\"height:40px;\" valign=\"middle\"><td colspan=\"3\"><span class=\"briefResultsTitle\"><a href=\"" + internal_link + "\">" + titleResult.GroupTitle.Replace("<", "<").Replace(">", ">") + "</a></span> </td></tr>"); } else { resultsBldr.AppendLine( "\t\t\t\t<tr style=\"height:40px;\" valign=\"middle\"><td colspan=\"3\"><span class=\"briefResultsTitle\"><a href=\"" + internal_link + "\">" + firstItemResult.Title.Replace("<", "<").Replace(">", ">") + "</a></span> </td></tr>"); } if ((titleResult.Primary_Identifier_Type.Length > 0) && (titleResult.Primary_Identifier.Length > 0)) { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(titleResult.Primary_Identifier_Type, CurrentMode.Language) + ":</td><td> </td><td>" + titleResult.Primary_Identifier + "</td></tr>"); } if (CurrentMode.Internal_User) { resultsBldr.AppendLine("\t\t\t\t<tr><td>BibID:</td><td> </td><td>" + titleResult.BibID + "</td></tr>"); if (titleResult.OPAC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<tr><td>OPAC:</td><td> </td><td>" + titleResult.OPAC_Number + "</td></tr>"); } if (titleResult.OCLC_Number > 1) { resultsBldr.AppendLine("\t\t\t\t<tr><td>OCLC:</td><td> </td><td>" + titleResult.OCLC_Number + "</td></tr>"); } } for (int i = 0; i < Results_Statistics.Metadata_Labels.Count; i++) { string field = Results_Statistics.Metadata_Labels[i]; string value = titleResult.Metadata_Display_Values[i]; Metadata_Search_Field thisField = SobekCM_Library_Settings.Metadata_Search_Field_By_Name(field); string display_field = string.Empty; if (thisField != null) { display_field = thisField.Display_Term; } if (display_field.Length == 0) { display_field = field.Replace("_", " "); } if (value == "*") { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>" + System.Web.HttpUtility.HtmlDecode(VARIES_STRING) + "</td></tr>"); } else if (value.Trim().Length > 0) { if (value.IndexOf("|") > 0) { bool value_found = false; string[] value_split = value.Split("|".ToCharArray()); foreach (string thisValue in value_split) { if (thisValue.Trim().Trim().Length > 0) { if (!value_found) { resultsBldr.AppendLine("\t\t\t\t<tr valign=\"top\"><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>"); value_found = true; } resultsBldr.Append(System.Web.HttpUtility.HtmlDecode(thisValue) + "<br />"); } } if (value_found) { resultsBldr.AppendLine("</td></tr>"); } } else { resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(display_field, CurrentMode.Language) + ":</td><td> </td><td>" + System.Web.HttpUtility.HtmlDecode(value) + "</td></tr>"); } } } //if (titleResult.Author.Length > 0) //{ // string creatorString = "Author"; // if (titleResult.MaterialType.ToUpper().IndexOf("ARTIFACT") == 0) // { // creatorString = "Creator"; // } // if (titleResult.Author == "*") // { // resultsBldr.AppendLine("\t\t\t\t<tr><td>" + Translator.Get_Translation(creatorString, CurrentMode.Language) + ":</td><td> </td><td>" + VARIES_STRING + "</td></tr>"); // } // else // { // bool author_found = false; // string[] author_split = titleResult.Author.Split("|".ToCharArray()); // foreach (string thisAuthor in author_split) // { // if (thisAuthor.ToUpper().IndexOf("PUBLISHER") < 0) // { // if (!author_found) // { // resultsBldr.AppendLine("\t\t\t\t<tr valign=\"top\"><td>" +Translator.Get_Translation(creatorString, CurrentMode.Language) + ":</td><td> </td><td>"); // author_found = true; // } // resultsBldr.Append(thisAuthor + "<br />"); // } // } // if (author_found) // { // resultsBldr.AppendLine("</td></tr>"); // } // } //} if (titleResult.Snippet.Length > 0) { resultsBldr.AppendLine("\t\t\t\t<tr><td colspan=\"3\"><br />“..." + titleResult.Snippet.Replace("<em>", "<span class=\"texthighlight\">").Replace("</em>", "</span>") + "...”</td></tr>"); } resultsBldr.AppendLine("\t\t\t</table>"); // End this row resultsBldr.AppendLine("\t\t<br />"); // Add children, if there are some if (multiple_title) { // Add this to the place holder Literal thisLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(thisLiteral); resultsBldr.Remove(0, resultsBldr.Length); Add_Issue_Tree(MainPlaceHolder, titleResult, current_row, textRedirectStem, base_url); } resultsBldr.AppendLine("\t\t</td>"); resultsBldr.AppendLine("\t</tr>"); // Add a horizontal line resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>"); // Increment the result counters result_counter++; current_row++; } // End this table resultsBldr.AppendLine("</table>"); // Add this to the HTML page Literal mainLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(mainLiteral); }
private void Add_Item_Info_And_Map(string textRedirectStem, string base_url, int map_number, List <iSearch_Title_Result> titles_for_current_map, PlaceHolder placeHolder, StringBuilder builder) { // Set some values before iterating through the item rows const string variesString = "<span style=\"color:Gray\">( varies )</span>"; // Step through each collection of items by bib id for this coordinate and see if this is a collection of points bool point_collection_map = false; bool polygon_map = false; if (titles_for_current_map[0].Spatial_Coordinates.Length > 0) { if (titles_for_current_map[0].Spatial_Coordinates[0] == 'P') { point_collection_map = true; } else { polygon_map = true; } } // Add the map division here builder.AppendLine(" <tr><td bgcolor=\"" + LINE_COLOR + "\" colspan=\"3\"></td></tr>"); builder.AppendLine(" <tr valign=\"top\">"); if (point_collection_map) { builder.AppendLine(" <td colspan=\"2\"><div id=\"map" + map_number + "\" style=\"width: 450px; height: 450px\"></div></td>"); builder.AppendLine(" <td>"); builder.AppendLine(" <table width=\"380px\">"); } if (polygon_map) { builder.AppendLine(" <td align=\"center\"><div id=\"map" + map_number + "\" style=\"width: 250px; height: 250px\"></div></td>"); builder.AppendLine(" <td colspan=\"2\">"); builder.AppendLine(" <table width=\"580px\">"); // Put a note here about the number of matches if (titles_for_current_map.Count > 1) { int total_items = titles_for_current_map.Sum(title_in_map => title_in_map.Item_Count); if (total_items != titles_for_current_map.Count) { builder.AppendLine(" <tr><td colspan=\"3\"><span style=\"color: gray;\"><center><em>The following " + total_items + " matches in " + titles_for_current_map.Count + " sets share the same coordinate information</em></center></span></td></tr>"); } else { builder.AppendLine(" <tr><td colspan=\"3\"><span style=\"color: gray;\"><center><em>The following " + total_items + " matches share the same coordinate information</em></center></span></td></tr>"); } } } if ((!point_collection_map) && (!polygon_map)) { builder.AppendLine(" <td colspan=\"3\">"); builder.AppendLine(" <table width=\"100%\">"); // Put a note here about the number of matches if (titles_for_current_map.Count > 1) { int total_items = titles_for_current_map.Sum(title_in_map => title_in_map.Item_Count); if (total_items != titles_for_current_map.Count) { builder.AppendLine(" <tr><td colspan=\"3\"><span style=\"color: gray;\"><center><em>The following " + total_items + " matches in " + titles_for_current_map.Count + " sets have no coordinate information</em></center></span></td></tr>"); } else { builder.AppendLine(" <tr><td colspan=\"3\"><span style=\"color: gray;\"><center><em>The following " + total_items + " matches have no coordinate information</em></center></span></td></tr>"); } } } // Now, add all the individual item information for each bib id in this map int titles_per_this_map = 0; int items_per_this_map = 0; string last_link = String.Empty; int polygons_added_to_this_map = 0; int coordinates_per_this_map = 1; string coords = String.Empty; foreach (iSearch_Title_Result titleResult in titles_for_current_map) { // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Increment the number of items/titles per this coordiante titles_per_this_map++; // If this is not the first, add a line if (titles_per_this_map > 1) { if ((polygon_map) || (titleResult.Spatial_Coordinates != coords)) { builder.AppendLine(" <tr><td bgcolor=\"" + LINE_COLOR + "\" colspan=\"3\"></td></tr>"); } else { builder.AppendLine(" <tr><td></td><td bgcolor=\"" + LINE_COLOR + "\" colspan=\"3\"></td></tr>"); } } // Increment by the number of items in this collection of items items_per_this_map += 1; // Are there multiple volumes to be displayed here? bool multiple = false; string pubdate = firstItemResult.PubDate; if (titleResult.Item_Count > 1) { multiple = true; // This will not include the item details, just the tree builder.AppendLine(" <tr>"); // If this is a point (and the first point of this coordinate) add the point information here if (point_collection_map) { if (titleResult.Spatial_Coordinates != coords) { // Add the icon for the google marker builder.AppendLine(" <tr><td width=\"30\"><img src=\"" + icon_by_number(coordinates_per_this_map) + "\" /></td>"); // Look ahead to see if multiple items have the same coordinate int index = titles_for_current_map.IndexOf(titleResult); int matching_titles_for_this_point = 1; while ((index >= 0) && ((index + 1) < titles_for_current_map.Count)) { if (titles_for_current_map[index + 1].Spatial_Coordinates == titleResult.Spatial_Coordinates) { matching_titles_for_this_point++; } else { break; } index++; } if (matching_titles_for_this_point > 1) { builder.AppendLine(" <td colspan=\"2\"><span style=\"color: gray;\"><center><em>The following " + matching_titles_for_this_point + " titles have the same coordinate point</em></center></span></td>"); builder.AppendLine(" </tr>"); builder.AppendLine(" <tr>"); builder.AppendLine(" <td> </td>"); } coords = titleResult.Spatial_Coordinates; coordinates_per_this_map++; } else { builder.AppendLine(" <td> </td>"); } } else { builder.AppendLine(" <td> </td>"); } builder.AppendLine(" <td colspan=\"2\">"); // Write all the collected HTML to a literal, since we will be adding a // tree view control to the web page next Literal literal = new Literal { Text = builder.ToString() }; placeHolder.Controls.Add(literal); builder.Remove(0, builder.Length); // Draw the tree of all matching issues Add_Issue_Tree(placeHolder, titleResult, currentResultCount, textRedirectStem, base_url); // Finish this table in the item results view builder.AppendLine(" </td>"); builder.AppendLine(" </tr>"); // Check if the pub date is the same for all items if ((pubdate.Length > 0) && (pubdate != "-1")) { for (int i = 0; i < titleResult.Item_Count; i++) { if (titleResult.Get_Item(i).PubDate != pubdate) { pubdate = String.Empty; break; } } } } else { // If this is a point (and the first point of this coordinate) add the point information here if (point_collection_map) { if (titleResult.Spatial_Coordinates != coords) { // Add the icon for the google marker builder.AppendLine(" <tr><td width=\"30\"><img src=\"" + icon_by_number(coordinates_per_this_map) + "\" /></td>"); // Look ahead to see if multiple items have the same coordinate int index = titles_for_current_map.IndexOf(titleResult); int matching_titles_for_this_point = 1; while ((index >= 0) && ((index + 1) < titles_for_current_map.Count)) { if (titles_for_current_map[index + 1].Spatial_Coordinates == titleResult.Spatial_Coordinates) { matching_titles_for_this_point++; } else { break; } index++; } if (matching_titles_for_this_point > 1) { builder.AppendLine(" <td colspan=\"2\"><span style=\"color: gray;\"><center><em>The following " + matching_titles_for_this_point + " titles have the same coordinate point</em></center></span></td>"); builder.AppendLine(" </tr>"); builder.AppendLine(" <tr>"); builder.AppendLine(" <td> </td>"); } coords = titleResult.Spatial_Coordinates; coordinates_per_this_map++; } else { builder.AppendLine(" <td> </td>"); } builder.AppendLine("<td colspan=\"2\"><a href=\"" + base_url + titleResult.BibID.ToUpper() + "/" + firstItemResult.VID + textRedirectStem + "\">" + firstItemResult.Title + "</a>"); } else { builder.AppendLine(" <tr><td></td><td colspan=\"2\"><a href=\"" + base_url + titleResult.BibID.ToUpper() + "/" + firstItemResult.VID + textRedirectStem + "\">" + firstItemResult.Title + "</a>"); // Save this link, just in case it is the only area in this map last_link = base_url + titleResult.BibID.ToUpper() + "/" + firstItemResult.VID + textRedirectStem; } } // Add the bib id and vid if (CurrentMode.Internal_User) { builder.AppendLine(" <tr height=\"10px\"><td> </td><td>BibID:</td><td>" + titleResult.BibID.ToUpper() + "</td></tr>"); if (!multiple) { builder.AppendLine(" <tr height=\"10px\"><td> </td><td>VID:</td><td>" + firstItemResult.VID + "</td></tr>"); } } // Add the publication date if ((pubdate.Length > 0) && (pubdate != "-1")) { builder.AppendLine(" <tr height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Date", CurrentMode.Language) + ":</td><td>" + pubdate + "</td></tr>"); } // Add any authors if (titleResult.Author.Length > 0) { if (titleResult.Author == "*") { builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Author", CurrentMode.Language) + ":</td><td>" + variesString + "</td></tr>"); } else { bool author_found = false; string[] author_split = titleResult.Author.Split("|".ToCharArray()); foreach (string thisAuthor in author_split) { if (thisAuthor.ToUpper().IndexOf("PUBLISHER") < 0) { if (!author_found) { builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Author", CurrentMode.Language) + ":</td><td>"); author_found = true; } builder.Append(thisAuthor + "<br />"); } } if (author_found) { builder.AppendLine("</td></tr>"); } } } // Add any publishers if (titleResult.Publisher.Length > 0) { if (titleResult.Publisher == "*") { builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Publisher", CurrentMode.Language) + ":</td><td>" + variesString + "</td></tr>"); } else { string[] publisher_split = titleResult.Publisher.Split("|".ToCharArray()); builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Publisher", CurrentMode.Language) + ":</td><td>"); foreach (string thisPublisher in publisher_split) { builder.Append(thisPublisher.Replace("<", "").Replace(">", "") + "<br />"); } builder.AppendLine(); } } // Add the format if ((!multiple) && (titleResult.Format.Length > 0)) { if (titleResult.Format == "*") { builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Format", CurrentMode.Language) + ":</td><td>" + variesString + "</td></tr>"); } else { builder.AppendLine(" <tr height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Format", CurrentMode.Language) + ":</td><td>" + titleResult.Format.Replace("[", " ").Replace("]", " ") + "</td></tr>"); } } // Add the donor if (titleResult.Donor.Length > 0) { if (titleResult.Donor == "*") { builder.AppendLine(" <tr valign=\"top\" height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Donor", CurrentMode.Language) + ":</td><td>" + variesString + "</td></tr>"); } else { builder.AppendLine(" <tr height=\"10px\"><td> </td><td>" + Translator.Get_Translation("Donor", CurrentMode.Language) + ":</td><td>" + titleResult.Donor + "</td></tr>"); } } // Increment the row counter currentResultCount++; } // End this map row builder.AppendLine(" </table>"); builder.AppendLine(" </td>"); builder.AppendLine(" </tr>"); if ((point_collection_map) || (polygon_map)) { // Clear the last latitude and longitude information double max_lat = -90; double max_long = -180; double min_lat = 90; double min_long = 180; // Now, start to add the map javascript information to the building javascript mapScriptHtml.AppendLine(); mapScriptHtml.AppendLine(" var map" + map_number + "_center = new google.maps.LatLng(<%CENTERINFO" + map_number + "%>);"); mapScriptHtml.AppendLine(" var map" + map_number + "_options = { zoom: <%ZOOMINFO" + map_number + "%>, center: map" + map_number + "_center, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, streetViewControl: false };"); mapScriptHtml.AppendLine(" var map" + map_number + " = new google.maps.Map(document.getElementById(\"map" + map_number + "\"), map" + map_number + "_options);"); // Step through each coordinate/title collection for this map int point_index = 1; coords = "A"; foreach (iSearch_Title_Result items_per_bib in titles_for_current_map) { // Add this coordinate information to the if (items_per_bib.Spatial_Coordinates.Length > 0) { string[] coords_splitter = items_per_bib.Spatial_Coordinates.Split("|,".ToCharArray()); // If this was a point, add this point if (items_per_bib.Spatial_Coordinates[0] == 'P') { if (items_per_bib.Spatial_Coordinates != coords) { coords = items_per_bib.Spatial_Coordinates; // Add the marker to the map script mapScriptHtml.AppendLine(" var marker" + map_number + "_" + point_index + " = new google.maps.Marker({ position: new google.maps.LatLng(" + coords_splitter[1] + ", " + coords_splitter[2] + "), map: map" + map_number + ", icon: \"" + icon_by_number(point_index) + "\" });"); point_index++; // Check the new boundaries check_boundaries(coords_splitter[1], coords_splitter[2], ref max_lat, ref max_long, ref min_lat, ref min_long); } } else { if (items_per_bib.Spatial_Coordinates != coords) { coords = items_per_bib.Spatial_Coordinates; if (coords_splitter.Length == 5) { mapScriptHtml.AppendLine(" var polygon" + polyCount + "_outline = [ new google.maps.LatLng(" + coords_splitter[1] + "," + coords_splitter[2] + "), new google.maps.LatLng(" + coords_splitter[1] + "," + coords_splitter[4] + "), new google.maps.LatLng(" + coords_splitter[3] + "," + coords_splitter[4] + "), new google.maps.LatLng(" + coords_splitter[3] + "," + coords_splitter[2] + "), new google.maps.LatLng(" + coords_splitter[1] + "," + coords_splitter[2] + ")];"); mapScriptHtml.AppendLine(" var polygon" + polyCount + " = new google.maps.Polygon({ paths: polygon" + polyCount + "_outline, strokeColor: \"#f33f00\", strokeOpacity: 1, strokeWeight: 5, fillColor: \"#ff0000\", fillOpacity: 0.2 });"); mapScriptHtml.AppendLine(" polygon" + polyCount + ".setMap(map" + map_number + ");"); check_boundaries(coords_splitter[1], coords_splitter[2], ref max_lat, ref max_long, ref min_lat, ref min_long); check_boundaries(coords_splitter[3], coords_splitter[4], ref max_lat, ref max_long, ref min_lat, ref min_long); } else { bool first = true; mapScriptHtml.Append(" var polygon" + polyCount + "_outline = [ "); int point = 1; while ((point + 2) <= coords_splitter.Length) { if (!first) { mapScriptHtml.Append(","); } else { first = false; } mapScriptHtml.Append("new google.maps.LatLng(" + coords_splitter[point] + ", " + coords_splitter[point + 1] + ")"); check_boundaries(coords_splitter[point], coords_splitter[point + 1], ref max_lat, ref max_long, ref min_lat, ref min_long); point += 2; } mapScriptHtml.AppendLine("];"); mapScriptHtml.AppendLine(" var polygon" + polyCount + " = new google.maps.Polygon({ paths: polygon" + polyCount + "_outline, strokeColor: \"#f33f00\", strokeOpacity: 1, strokeWeight: 5, fillColor: \"#ff0000\", fillOpacity: 0.2 });"); mapScriptHtml.AppendLine(" polygon" + polyCount + ".setMap(map" + map_number + ");"); } // Finish the last polygon by adding the link, if there should be one if ((items_per_this_map == 1) && (last_link.Length > 0)) { mapScriptHtml.AppendLine(" google.maps.event.addListener(polygon" + polyCount + ", 'click', function redirect" + polyCount + "() { window.location.href = \"" + last_link + "\"; }); "); } polyCount++; polygons_added_to_this_map++; } } } } try { // Compute the center and zoom of the last map double mid_lat = (max_lat + min_lat) / 2; double mid_long = (max_long + min_long) / 2; int zoom = compute_zoom(max_lat, max_long, min_lat, min_long); if (coords[0] == 'A') { zoom--; } if ((polygons_added_to_this_map == 0) && (point_index <= 1)) { zoom = 6; } mapScriptHtml.Replace("<%CENTERINFO" + map_number + "%>", mid_lat + ", " + mid_long); mapScriptHtml.Replace("<%ZOOMINFO" + map_number + "%>", zoom.ToString()); } catch { mapScriptHtml.Replace("<%CENTERINFO" + map_number + "%>", "0, 0"); mapScriptHtml.Replace("<%ZOOMINFO" + map_number + "%>", "8"); } } }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="MainPlaceHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder MainPlaceHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Table_ResultsWriter.Add_HTML", "Rendering results in table view"); } // If results are null, or no results, return empty string if ((PagedResults == null) || (ResultsStats == null) || (ResultsStats.Total_Items <= 0)) { return; } // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = RequestSpecificValues.Current_Mode.Base_URL; if (RequestSpecificValues.Current_Mode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = RequestSpecificValues.Current_Mode.Base_URL + "l/"; } // Start the results StringBuilder resultsBldr = new StringBuilder(5000); resultsBldr.AppendLine("<br />"); resultsBldr.AppendLine("<table width=\"100%\">"); // Start the header row and add the 'No.' part short?currentOrder = RequestSpecificValues.Current_Mode.Sort; if (RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Results) { RequestSpecificValues.Current_Mode.Sort = 0; resultsBldr.AppendLine("\t<tr valign=\"bottom\" align=\"left\">"); resultsBldr.AppendLine("\t\t<td width=\"30px\"><span class=\"SobekTableSortText\"><a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode).Replace("&", "&") + "\"><strong>No.</strong></a></span></td>"); } else { resultsBldr.AppendLine("\t<tr valign=\"bottom\" align=\"left\">\n\t\t<td>No.</td>"); } // Add the title column RequestSpecificValues.Current_Mode.Sort = 1; resultsBldr.AppendLine("\t\t<td><span class=\"SobekTableSortText\"><a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode).Replace("&", "&") + "\"><strong>" + UI_ApplicationCache_Gateway.Translation.Get_Translation("Title", RequestSpecificValues.Current_Mode.Language) + "</strong></a></span></td>"); // Add the date column RequestSpecificValues.Current_Mode.Sort = 10; resultsBldr.AppendLine("\t\t<td><span class=\"SobekTableSortText\"><a href=\"" + UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode).Replace("&", "&") + "\"><strong>" + UI_ApplicationCache_Gateway.Translation.Get_Translation("Date", RequestSpecificValues.Current_Mode.Language) + "</strong></a></span></td>"); RequestSpecificValues.Current_Mode.Sort = currentOrder; resultsBldr.AppendLine("\t</tr>"); resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>"); // Set the counter for these results from the page int page = RequestSpecificValues.Current_Mode.Page.HasValue ? Math.Max(RequestSpecificValues.Current_Mode.Page.Value, ((ushort)1)) : 1; int result_counter = ((page - 1) * Results_Per_Page) + 1; int current_row = 0; // Step through all the results foreach (iSearch_Title_Result titleResult in PagedResults) { bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); //// Is this restricted? //bool restricted_by_ip = false; //if ((titleResult.Item_Count == 1) && (firstItemResult.IP_Restriction_Mask > 0)) //{ // int comparison = dbItem.IP_Range_Membership & base.current_user_mask; // if (comparison == 0) // { // restricted_by_ip = true; // } //} // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if ((RequestSpecificValues.Current_Mode.Mode == Display_Mode_Enum.Aggregation) && (RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Browse_Info)) { internal_link = base_url + titleResult.BibID + textRedirectStem; } // Start this row if (multiple_title) { resultsBldr.AppendLine("\t<tr valign=\"top\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" >"); } else { resultsBldr.AppendLine("\t<tr valign=\"top\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" onclick=\"window.location.href='" + internal_link + "';\" >"); } // Add the counter as the first column resultsBldr.AppendLine("\t\t<td>" + result_counter + "</td>"); // Add differently depending on the child row count if (!multiple_title) { if (!String.IsNullOrEmpty(firstItemResult.Link)) { resultsBldr.AppendLine("\t\t<td>" + firstItemResult.Title + " ( <a href=\"" + firstItemResult.Link + "\">external resource</a> | <a href=\"" + internal_link + "\">internal citation</a> )</td>"); } else { resultsBldr.AppendLine("\t\t<td><a href=\"" + internal_link + "\">" + firstItemResult.Title + "</a></td>"); } resultsBldr.AppendLine("\t\t<td>" + firstItemResult.PubDate + "</td></tr>"); } else { resultsBldr.AppendLine("\t\t<td colspan=\"2\">"); // Add this to the place holder Literal thisLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(thisLiteral); resultsBldr.Remove(0, resultsBldr.Length); Add_Issue_Tree(MainPlaceHolder, titleResult, current_row, textRedirectStem, base_url); resultsBldr.AppendLine("\t</td></tr>"); } // Add a horizontal line resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"3\"></td></tr>"); // Increment the result counters result_counter++; current_row++; } // End this table resultsBldr.AppendLine("</table>"); // Add this to the html table Literal mainLiteral = new Literal { Text = resultsBldr.ToString().Replace("<role>", "<i>").Replace("</role>", "</i>") }; MainPlaceHolder.Controls.Add(mainLiteral); }
/// <summary> Display search results in simple XML format </summary> /// <param name="Output"> Stream to which to write the text for this main writer </param> protected internal void display_search_results(TextWriter Output) { // Get the URL and network roots string url = SobekCM_Library_Settings.Image_URL; string network = SobekCM_Library_Settings.Image_Server_Network; string base_url = currentMode.Base_URL.Replace("sobekcm_data.aspx", ""); // Write the header first Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "); Output.WriteLine("<ResultSet Page=\"" + currentMode.Page + "\" Total=\"" + base.results_statistics.Total_Titles + "\">"); // Now, add XML for each title string lastBibID = string.Empty; foreach (iSearch_Title_Result thisResult in base.paged_results) { if (thisResult.BibID != lastBibID) { if (lastBibID.Length > 0) { Output.WriteLine("</TitleResult>"); } Output.WriteLine("<TitleResult ID=\"" + thisResult.BibID + "\">"); lastBibID = thisResult.BibID; } // Determine folder from BibID string folder = thisResult.BibID.Substring(0, 2) + "/" + thisResult.BibID.Substring(2, 2) + "/" + thisResult.BibID.Substring(4, 2) + "/" + thisResult.BibID.Substring(6, 2) + "/" + thisResult.BibID.Substring(8); // Now, add XML for each item for (int i = 0; i < thisResult.Item_Count; i++) { iSearch_Item_Result itemResult = thisResult.Get_Item(i); Output.WriteLine("\t<ItemResult ID=\"" + thisResult.BibID + "_" + itemResult.VID + "\">"); Output.Write("\t\t<Title>"); Write_XML(Output, itemResult.Title); Output.WriteLine("</Title>"); if (itemResult.PubDate.Length > 0) { Output.Write("\t\t<Date>"); Write_XML(Output, itemResult.PubDate); Output.WriteLine("</Date>"); } Output.WriteLine("\t\t<Location>"); Output.WriteLine("\t\t\t<URL>" + base_url + thisResult.BibID + "/" + itemResult.VID + "</URL>"); Output.WriteLine("\t\t\t<Folder type=\"web\">" + url + folder + "/" + itemResult.VID + "</Folder>"); Output.WriteLine("\t\t\t<Folder type=\"network\">" + network + folder.Replace("/", "\\") + "\\" + itemResult.VID + "</Folder>"); Output.WriteLine("\t\t</Location>"); Output.WriteLine("\t</ItemResult>"); } } if (base.paged_results.Count > 0) { Output.WriteLine("</TitleResult>"); } Output.WriteLine("</ResultSet>"); //SobekCM.Resource_Object.Database.DataSets.UFDC_All_Items simplified_xml = new SobekCM.Resource_Object.Database.DataSets.UFDC_All_Items(); //List<Results.SobekCM_Item_Collection.SobekCM_Item_Row> itemRows; //for ( int i = 0 ; i < search_results.Title_Count ; i++ ) //{ // Results.SobekCM_Item_Collection.SobekCM_Item_Group_Row titleRow = search_results.GetRow(i); // // Get the related child rows // itemRows = titleRow.Child_Rows; // // Step through each child row and add to the new table // foreach (SobekCM.Library.Results.SobekCM_Item_Collection.SobekCM_Item_Row itemRow in itemRows) // { // Application_State.Single_Item dbItem = allItems.Item_By_Bib_VID(titleRow.BibID, itemRow.VID, null ); // Application_State.Multiple_Volume_Item dbTitle = allItems.Title_By_Bib(titleRow.BibID); // if ((dbItem != null) && ( dbTitle != null )) // { // simplified_xml.Add_Row(titleRow.BibID, itemRow.VID, itemRow.Title, current_greenstone_image_root + dbTitle.File_Root + "/" + dbItem.VID_String ); // } // } //} //// Write this information //simplified_xml.WriteXml(Output, XmlWriteMode.WriteSchema); }
/// <summary> Adds the controls for this result viewer to the place holder on the main form </summary> /// <param name="placeHolder"> Main place holder ( "mainPlaceHolder" ) in the itemNavForm form into which the the bulk of the result viewer's output is displayed</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <returns> Sorted tree with the results in hierarchical structure with volumes and issues under the titles and sorted by serial hierarchy </returns> public override void Add_HTML(PlaceHolder placeHolder, Custom_Tracer Tracer) { if (Tracer != null) { Tracer.Add_Trace("Thumbnail_ResultsWriter.Add_HTML", "Rendering results in thumbnail view"); } // If results are null, or no results, return empty string if ((Paged_Results == null) || (Results_Statistics == null) || (Results_Statistics.Total_Items <= 0)) { return; } // Get the text search redirect stem and (writer-adjusted) base url string textRedirectStem = Text_Redirect_Stem; string base_url = CurrentMode.Base_URL; if (CurrentMode.Writer_Type == Writer_Type_Enum.HTML_LoggedIn) { base_url = CurrentMode.Base_URL + "l/"; } // Should the publication date be shown? bool showDate = false; if (CurrentMode.Sort >= 10) { showDate = true; } // Start this table StringBuilder resultsBldr = new StringBuilder(5000); // Start this table resultsBldr.AppendLine("<table align=\"center\" width=\"100%\" cellspacing=\"15px\">"); resultsBldr.AppendLine("\t<tr>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t\t<td width=\"25%\"> </td>"); resultsBldr.AppendLine("\t</tr>"); resultsBldr.AppendLine("\t<tr valign=\"top\">"); // Step through all the results int col = 0; foreach (iSearch_Title_Result titleResult in Paged_Results) { // Should a new row be started if (col == 4) { col = 0; resultsBldr.AppendLine("\t</tr>"); // Horizontal Line resultsBldr.AppendLine("\t<tr><td bgcolor=\"#e7e7e7\" colspan=\"4\"></td></tr>"); resultsBldr.AppendLine("\t<tr valign=\"top\">"); } bool multiple_title = titleResult.Item_Count > 1; // Always get the first item for things like the main link and thumbnail iSearch_Item_Result firstItemResult = titleResult.Get_Item(0); // Determine the internal link to the first (possibly only) item string internal_link = base_url + titleResult.BibID + "/" + firstItemResult.VID + textRedirectStem; // For browses, just point to the title if (CurrentMode.Mode == Display_Mode_Enum.Aggregation_Browse_Info) { internal_link = base_url + titleResult.BibID + textRedirectStem; } resultsBldr.AppendLine("\t\t<td align=\"center\" onmouseover=\"this.className='tableRowHighlight'\" onmouseout=\"this.className='tableRowNormal'\" onclick=\"window.location.href='" + internal_link + "';\" >"); string title; if (multiple_title) { // Determine term to use string multi_term = "volume"; if (titleResult.MaterialType.ToUpper() == "NEWSPAPER") { multi_term = titleResult.Item_Count > 1 ? "issues" : "issue"; } else { if (titleResult.Item_Count > 1) { multi_term = "volumes"; } } if ((showDate)) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + titleResult.GroupTitle; } else { title = titleResult.GroupTitle; } } else { title = titleResult.GroupTitle + "<br />( " + titleResult.Item_Count + " " + multi_term + " )"; } } else { if (showDate) { if (firstItemResult.PubDate.Length > 0) { title = "[" + firstItemResult.PubDate + "] " + firstItemResult.Title; } else { title = firstItemResult.Title; } } else { title = firstItemResult.Title; } } // Start the HTML for this item resultsBldr.AppendLine("<table width=\"150px\">"); //// Is this restricted? bool restricted_by_ip = false; if ((titleResult.Item_Count == 1) && (firstItemResult.IP_Restriction_Mask > 0)) { int comparison = firstItemResult.IP_Restriction_Mask & current_user_mask; if (comparison == 0) { restricted_by_ip = true; } } // Calculate the thumbnail // Add the thumbnail if ((firstItemResult.MainThumbnail.ToUpper().IndexOf(".JPG") < 0) && (firstItemResult.MainThumbnail.ToUpper().IndexOf(".GIF") < 0)) { resultsBldr.AppendLine("<tr><td><a href=\"" + internal_link + "\"><img src=\"" + CurrentMode.Default_Images_URL + "NoThumb.jpg\" /></a></td></tr>"); } else { string thumb = SobekCM_Library_Settings.Image_URL + titleResult.BibID.Substring(0, 2) + "/" + titleResult.BibID.Substring(2, 2) + "/" + titleResult.BibID.Substring(4, 2) + "/" + titleResult.BibID.Substring(6, 2) + "/" + titleResult.BibID.Substring(8) + "/" + firstItemResult.VID + "/" + (firstItemResult.MainThumbnail).Replace("\\", "/").Replace("//", "/"); resultsBldr.AppendLine("<tr><td><a href=\"" + internal_link + "\"><img src=\"" + thumb + "\" alt=\"MISSING THUMBNAIL\" /></a></td></tr>"); } // Add the title resultsBldr.AppendLine("<tr><td align=\"center\"><span class=\"SobekThumbnailText\">" + title + "</span></td></tr>"); // If this was access restricted, add that if (restricted_by_ip) { resultsBldr.AppendLine("<tr><td align=\"center\"><span class=\"RestrictedItemText\">Access Restricted</span></td></tr>"); } // Finish this one thumbnail resultsBldr.AppendLine("</table></td>"); col++; } // Finish this row out while (col < 4) { resultsBldr.AppendLine("\t\t<td> </td>"); col++; } // End this table resultsBldr.AppendLine("\t</tr>"); resultsBldr.AppendLine("</table>"); // Add this to the html table Literal mainLiteral = new Literal { Text = resultsBldr.ToString() }; placeHolder.Controls.Add(mainLiteral); }
public void Simple_Results_JSON(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_JSON", "Parse request to determine search requested"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Additional results arguments // limit number of results int artificial_result_limitation = -1; Boolean isNumeric = false; if (!String.IsNullOrEmpty(QueryString["limit_results"])) { isNumeric = Int32.TryParse(QueryString["limit_results"], out artificial_result_limitation); if (!isNumeric) { artificial_result_limitation = -1; } else if (artificial_result_limitation < 1) { artificial_result_limitation = -1; } } int pagenum = 1; if (!String.IsNullOrEmpty(QueryString["page"])) { isNumeric = Int32.TryParse(QueryString["page"], out pagenum); if (!isNumeric) { pagenum = 1; } else if (pagenum < 1) { pagenum = 1; } else if (pagenum > 1) { artificial_result_limitation = -1; } } // Was a collection indicated? if (UrlSegments.Count > 0) { args.Aggregation = UrlSegments[0]; } // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_JSON", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_JSON", "Returned aggregation was NULL... aggregation code may not be valid"); if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_JSON", "Perform the search"); Search_Results_Statistics resultsStats; List <iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, false, tracer, out resultsStats, out resultsPage); // Was this in debug mode? // If this was debug mode, then just write the tracer if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.Output.WriteLine("{\"stats\":{\"total_items\":\"" + resultsStats.Total_Items + "\",\"total_titles\":\"" + resultsStats.Total_Titles + "\"},"); Response.Output.WriteLine(" \"results\":["); // Map to the results object title / item tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_JSON", "Map to the results object title / item"); int items_counter = 0; int resultnum = 0; if (resultsPage != null) { foreach (iSearch_Title_Result thisResult in resultsPage) { // Every results should have an item if (thisResult.Item_Count == 0) { continue; } else { resultnum++; } if (artificial_result_limitation != -1 && resultnum > artificial_result_limitation) { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Reached limit [" + artificial_result_limitation + "]."); break; } // Was this NOT the first item? if (items_counter > 0) { Response.Output.WriteLine(","); } Response.Output.Write(" "); items_counter++; // add each descriptive field over iSearch_Item_Result itemResult = thisResult.Get_Item(0); string bibid = thisResult.BibID; string title = thisResult.GroupTitle; string vid = itemResult.VID; string thumbnail = itemResult.MainThumbnail; // {"bibid":"1212", "vid":"00001", "title":"sdsd", "subjects":["subj1", "subj2", "subj3"] }, Response.Output.Write("{ \"bibid\":\"" + bibid + "\", \"vid\":\"" + vid + "\", "); Response.Output.Write("\"title\":\"" + HttpUtility.HtmlEncode(title) + "\","); Response.Output.Write("\"url_item\":\"" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + bibid + "/" + vid + "/\","); Response.Output.Write("\"url_thumbnail\":\"" + Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL + SobekFileSystem.AssociFilePath(bibid, vid).Replace("\\", "/") + thumbnail + "\""); int field_index = 0; if (resultsStats.Metadata_Labels.Count > 0) { foreach (string metadataTerm in resultsStats.Metadata_Labels) { if (!String.IsNullOrWhiteSpace(thisResult.Metadata_Display_Values[field_index])) { // how to display this metadata field? string metadataTermDisplay = metadataTerm; string termString = thisResult.Metadata_Display_Values[field_index]; Response.Output.Write(",\"" + metadataTermDisplay + "\":["); int individual_term_counter = 0; if (termString.IndexOf("|") > 0) { string[] splitter = termString.Split("|".ToCharArray()); foreach (string thisSplit in splitter) { if (!String.IsNullOrWhiteSpace(thisSplit)) { if (individual_term_counter > 0) { Response.Output.Write(", \"" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "\""); } else { Response.Output.Write("\"" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "\""); } individual_term_counter++; } } } else { Response.Output.Write("\"" + HttpUtility.HtmlEncode(termString.Trim()) + "\""); } Response.Output.Write("]"); } field_index++; } } Response.Output.Write("}"); } } Response.Output.WriteLine(); Response.Output.WriteLine(" ]"); Response.Output.WriteLine("} "); // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } }
public void Simple_Results_XML(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug) { // Local trace Custom_Tracer tracer = new Custom_Tracer(); tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML"); // Get all the searh field necessary from the query string Results_Arguments args = new Results_Arguments(QueryString); // Additional results arguments // limit number of results int artificial_result_limitation = -1; Boolean isNumeric = false; if (!String.IsNullOrEmpty(QueryString["limit_results"])) { isNumeric = Int32.TryParse(QueryString["limit_results"], out artificial_result_limitation); if (!isNumeric) { artificial_result_limitation = -1; } else if (artificial_result_limitation < 1) { artificial_result_limitation = -1; } } int pagenum = 1; if (!String.IsNullOrEmpty(QueryString["page"])) { isNumeric = Int32.TryParse(QueryString["page"], out pagenum); if (!isNumeric) { pagenum = 1; } else if (pagenum < 1) { pagenum = 1; } else if (pagenum > 1) { artificial_result_limitation = -1; } } // Was a collection indicated? if (UrlSegments.Count > 0) { args.Aggregation = UrlSegments[0]; } // Get the aggregation object (we need to know which facets to use, etc.. ) tracer.Add_Trace("SimpleResultsEndpoints.Get_Search_Results_Set", "Get the '" + args.Aggregation + "' item aggregation (for facets, etc..)"); Complete_Item_Aggregation aggr = AggregationServices.get_complete_aggregation(args.Aggregation, true, tracer); // If no aggregation was returned, that is an error if (aggr == null) { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Returned aggregation was NULL... aggregation code may not be valid"); if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } Response.ContentType = "text/plain"; Response.Output.WriteLine("Error occurred or aggregation '" + args.Aggregation + "' not valid"); Response.StatusCode = 500; return; } // Perform the search tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Perform the search"); Search_Results_Statistics resultsStats; List <iSearch_Title_Result> resultsPage; ResultsEndpointErrorEnum error = Get_Search_Results(args, aggr, false, tracer, out resultsStats, out resultsPage); // Was this in debug mode? // If this was debug mode, then just write the tracer if (IsDebug) { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Debug mode detected"); Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } try { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Begin writing the XML result to the response"); Response.Output.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"); int count_pages = (int)Math.Floor((double)resultsStats.Total_Items / 20); if (count_pages == 0) { count_pages = 1; } if (pagenum > count_pages) { pagenum = count_pages; } Response.Output.WriteLine("<results total_items=\"" + resultsStats.Total_Items + "\" total_titles=\"" + resultsStats.Total_Titles + "\" page_count=\"" + count_pages + "\" max_results_per_page=\"20\""); if (artificial_result_limitation != -1) { Response.Output.WriteLine("limit_results=\"" + artificial_result_limitation + "\""); } Response.Output.WriteLine(">"); // Map to the results object title / item tracer.Add_Trace("SimpleResultsEndpoints.Get_Search_Results_Set", "Map to the results object title / item"); // resultnum int resultnum = 0; if (pagenum > 1) { resultnum = ((pagenum - 1) * 20); } if (resultsPage != null) { foreach (iSearch_Title_Result thisResult in resultsPage) { // Every results should have an item if (thisResult.Item_Count == 0) { continue; } else { resultnum++; } if (artificial_result_limitation != -1 && resultnum > artificial_result_limitation) { tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Reached limit [" + artificial_result_limitation + "]."); break; } // add each descriptive field over iSearch_Item_Result itemResult = thisResult.Get_Item(0); string bibid = thisResult.BibID; string title = thisResult.GroupTitle; string vid = itemResult.VID; string thumbnail = itemResult.MainThumbnail; Response.Output.WriteLine(" <result resultnum=\"" + resultnum + "\" bibid=\"" + bibid + "\" vid=\"" + vid + "\">"); Response.Output.WriteLine(" <title>" + HttpUtility.HtmlEncode(title) + "</title>"); Response.Output.WriteLine(" <url_item>" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + bibid + "/" + vid + "/</url_item>"); if (!String.IsNullOrEmpty(thumbnail)) { try { Response.Output.WriteLine(" <url_thumbnail>" + Engine_ApplicationCache_Gateway.Settings.Servers.Image_URL + SobekFileSystem.AssociFilePath(bibid, vid).Replace("\\", "/") + thumbnail.Trim() + "</url_thumbnail>"); } catch (Exception ee) { Response.Output.WriteLine("ERROR WRITING THUMBNAIL"); Response.Output.WriteLine(ee.Message); Response.Output.WriteLine(ee.StackTrace); } } int field_index = 0; if (resultsStats.Metadata_Labels.Count > 0) { Response.Output.WriteLine("<metadata>"); foreach (string metadataTerm in resultsStats.Metadata_Labels) { if (!String.IsNullOrWhiteSpace(thisResult.Metadata_Display_Values[field_index])) { // how to display this metadata field? string metadataTermDisplay = metadataTerm; string termString = thisResult.Metadata_Display_Values[field_index]; if (termString.IndexOf("|") > 0) { string[] splitter = termString.Split("|".ToCharArray()); foreach (string thisSplit in splitter) { if (!String.IsNullOrWhiteSpace(thisSplit)) { Response.Output.WriteLine(" <" + metadataTermDisplay + ">" + HttpUtility.HtmlEncode(thisSplit.Trim()) + "</" + metadataTermDisplay + ">"); } } } else { Response.Output.WriteLine(" <" + metadataTermDisplay + ">" + HttpUtility.HtmlEncode(termString.Trim()) + "</" + metadataTermDisplay + ">"); } } field_index++; } Response.Output.WriteLine("</metadata>"); } Response.Output.WriteLine(" </result>"); } } Response.Output.WriteLine("</results>"); tracer.Add_Trace("SimpleResultsEndpoints.Simple_Results_XML", "Done writing the XML result to the response"); } catch (Exception ee) { Response.Output.Write(ee.Message); Response.Output.Write(ee.StackTrace); } // If an error occurred, return the error switch (error) { case ResultsEndpointErrorEnum.Database_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Database_Timeout_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Database timeout"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Solr_Exception: Response.ContentType = "text/plain"; Response.Output.WriteLine("Solr exception"); Response.StatusCode = 500; return; case ResultsEndpointErrorEnum.Unknown: Response.ContentType = "text/plain"; Response.Output.WriteLine("Unknown error"); Response.StatusCode = 500; return; } // If debug, show the trace if (IsDebug) { Response.ContentType = "text/plain"; Response.Output.WriteLine("DEBUG MODE DETECTED"); Response.Output.WriteLine(); Response.Output.WriteLine(tracer.Text_Trace); return; } }