SobekCM.Library.HTML.Item_HtmlSubwriter.Write_HTML C# (CSharp) Method

Write_HTML() public method

Writes the HTML generated by this item html subwriter directly to the response stream
This begins writing this page, up to the item-level main menu
public Write_HTML ( TextWriter Output, Custom_Tracer Tracer ) : bool
Output System.IO.TextWriter Stream to which to write the HTML for this subwriter
Tracer SobekCM.Tools.Custom_Tracer Trace object keeps a list of each method executed and important milestones in rendering
return bool
        public override bool Write_HTML(TextWriter Output, Custom_Tracer Tracer)
        {
            Tracer.Add_Trace("Item_HtmlSubwriter.Write_HTML", "Begin writing the item viewer, up to the item-level main menu");

            Tracer.Add_Trace("Item_HtmlSubwriter.Write_HTML", "Begin writing the item viewer, up to the item-level main menu");

            // If this is for a fragment, do nothing
            if (!String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Fragment))
                return false;

            Output.WriteLine();

            //// Just return if this is the pageviewer
            //if (pageViewer.ItemViewer_Type == ItemViewer_Type_Enum.GnuBooks_PageTurner)
            //{
            //    return true;
            //}

            // Put an itemscope div around here for micro-data purposes
            Output.WriteLine("<!-- Unstyled div placed around entire item information to support schema.org microdata -->");
            Output.WriteLine("<section itemscope itemtype=\"http:schema.org/ItemPage\">");
            Output.WriteLine();

            // The item viewer can choose to override the standard item titlebar
            if (!behaviors.Contains(HtmlSubwriter_Behaviors_Enum.Item_Subwriter_Suppress_Titlebar))
            {
                Output.WriteLine("<!-- Show the title and any other important item information -->");
                Output.WriteLine("<section id=\"sbkIsw_Titlebar\" role=\"banner\">");

                if ( is_bib_level )
                {
                    string grouptitle = "NO TITLE";
                    if ((currentItem.Behaviors != null) && (!String.IsNullOrWhiteSpace(currentItem.Behaviors.GroupTitle)))
                        grouptitle = currentItem.Behaviors.GroupTitle;
                    if (grouptitle.Length > 125)
                    {
                        Output.WriteLine("\t<h1 itemprop=\"name\"><abbr title=\"" + grouptitle + "\">" + grouptitle.Substring(0, 120) + "..</abbr></h1>");
                    }
                    else
                    {
                        Output.WriteLine("\t<h1 itemprop=\"name\">" + grouptitle + "</h1>");
                    }
                }
                else
                {
                    string final_title = currentItem.Title ?? "NO TITLE";

                    // Add the Title if there is one
                    if (final_title.Length > 0)
                    {
                        // Is this a newspaper?
                        bool newspaper = (String.Compare(currentItem.Behaviors.GroupType, "NEWSPAPER", StringComparison.OrdinalIgnoreCase) == 0);

                        // Does a custom setting override the default behavior to add a date?
                        if ((newspaper) && (UI_ApplicationCache_Gateway.Settings.Contains_Additional_Setting("Item Viewer.Include Date In Title")) && (UI_ApplicationCache_Gateway.Settings.Get_Additional_Setting("Item Viewer.Include Date In Title").ToUpper() == "NEVER"))
                            newspaper = false;

                        // Add the date if it should be added
                        if ((newspaper) && ( !String.IsNullOrEmpty(currentItem.Web.Date)))
                        {
                            if (final_title.Length > 125)
                            {
                                Output.WriteLine("\t<h1 itemprop=\"name\"><abbr title=\"" + final_title + "\">" + final_title.Substring(0, 120) + "..</abbr> ( " + currentItem.Web.Date + " )</h1>");
                            }
                            else
                            {
                                Output.WriteLine("\t<h1 itemprop=\"name\">" + final_title + " ( " + currentItem.Web.Date + " )</h1>");
                            }
                        }
                        else
                        {
                            if (final_title.Length > 125)
                            {
                                Output.WriteLine("\t<h1 itemprop=\"name\"><abbr title=\"" + final_title + "\">" + final_title.Substring(0, 120) + "..</abbr></h1>");
                            }
                            else
                            {
                                Output.WriteLine("\t<h1 itemprop=\"name\">" + final_title + "</h1>");
                            }
                        }
                    }

                    // Add the link if there is one
                    // Links_BriefItemMapper
                    if ((currentItem.Web != null ) && ( !String.IsNullOrEmpty(currentItem.Web.Title_Box_Additional_Link)))
                    {
                        // Get the translated TYPE
                        string type = UI_ApplicationCache_Gateway.Translation.Get_Translation((currentItem.Web.Title_Box_Additional_Link_Type ?? "Related Link"), RequestSpecificValues.Current_Mode.Language);

                        // Add the link
                        Output.WriteLine("\t" + currentItem.Web.Title_Box_Additional_Link + " ( " + type + " )<br />");
                    }

                    // If there is an ACCESSION number and this is an ARTIFACT, include that at the top
                    BriefItem_DescriptiveTerm accessNumber = currentItem.Get_Description("Accession Number");
                    if ((accessNumber != null) && (accessNumber.Values != null) && (accessNumber.Values.Count > 0 ))
                    {
                        Output.WriteLine("\t" + UI_ApplicationCache_Gateway.Translation.Get_Translation("Accession number", RequestSpecificValues.Current_Mode.Language) + " " + accessNumber.Values[0].Value + "<br />");
                    }
                }

                Output.WriteLine("</section>");
                Output.WriteLine();
            }

            // The item viewer can choose to override the standard item menu
            if ((!behaviors.Contains(HtmlSubwriter_Behaviors_Enum.Item_Subwriter_Suppress_Item_Menu)) && ( menuProvider != null ))
            {
                // Determine the current mode
                string currentCode = RequestSpecificValues.Current_Mode.ViewerCode ?? String.Empty;
                if (prototyper != null)
                    currentCode = prototyper.ViewerCode;

                // Let the menu provider write the menu
                menuProvider.Add_Main_Menu(Output, currentCode, itemRestrictedFromUserByIp, itemCheckedOutByOtherUser, currentItem, RequestSpecificValues.Current_Mode, RequestSpecificValues.Current_User, Tracer);
            }

            return true;
        }

Usage Example

コード例 #1
0
        private void Finish_writing_html(SobekCM_Item CurrentItem, Page_TreeNode CurrentPage, string Filename, string TextFileLocation )
        {
            bool textSearchable = CurrentItem.Behaviors.Text_Searchable;
            CurrentItem.Behaviors.Text_Searchable = false;
            if (staticSobekcmLocation.Length > 0)
                SobekCM_Library_Settings.Base_Directory = staticSobekcmLocation;

            // Get the skin
            if ((CurrentItem.Behaviors.Web_Skin_Count > 0) && ( !CurrentItem.Behaviors.Web_Skins.Contains( defaultSkin.ToUpper())))
                currentMode.Skin = CurrentItem.Behaviors.Web_Skins[0];

            // Get the skin object
            SobekCM_Skin_Object skinObject = skinsCollection[currentMode.Skin];
            if (skinObject == null)
            {
                skinObject = assistant.Get_HTML_Skin(currentMode, skinsCollection, false, null);
                skinsCollection.Add(skinObject);
            }

            // Create the HTML writer
            Item_HtmlSubwriter itemWriter = new Item_HtmlSubwriter(CurrentItem, CurrentPage, null, codeManager, translations, true, true, currentMode, null, String.Empty, null, tracer) { Mode = currentMode, Skin = skinObject };
            SobekCM_Library_Settings.Base_SobekCM_Location_Relative = currentMode.Base_URL;
            if ((SobekCM_Library_Settings.Base_SobekCM_Location_Relative.Length == 0) || (SobekCM_Library_Settings.Base_SobekCM_Location_Relative.Contains("localhost")))
            {
                SobekCM_Library_Settings.Base_SobekCM_Location_Relative = primaryWebServerUrl;
                currentMode.Base_URL = SobekCM_Library_Settings.Base_SobekCM_Location_Relative;
            }

            // Now that the item viewer is built, set the robot flag to suppress some checks
            currentMode.Is_Robot = true;

            // Create the TextWriter
            StreamWriter writer = new StreamWriter(Filename, false, Encoding.UTF8);

            writer.WriteLine("<!DOCTYPE html>");
            writer.WriteLine("<html>");
            writer.WriteLine("<head>");
            writer.WriteLine("  <title>" + CurrentItem.Bib_Info.Main_Title + "</title>");
            writer.WriteLine();
            writer.WriteLine("  <!-- " + SobekCM_Library_Settings.System_Name + " : SobekCM Digital Repository -->");
            writer.WriteLine();
            writer.WriteLine("  <link href=\"" + SobekCM_Library_Settings.System_Base_URL + "default/SobekCM.min.css\" rel=\"stylesheet\" type=\"text/css\" />");
            writer.WriteLine("  <script type=\"text/javascript\" src=\"" + SobekCM_Library_Settings.System_Base_URL + "default/scripts/jquery/jquery-1.10.2.min.js\"></script>");
            writer.WriteLine("  <script type=\"text/javascript\" src=\"" + SobekCM_Library_Settings.System_Base_URL + "default/scripts/sobekcm_full.min.js\"></script>");
            writer.WriteLine("  <link href=\"" + SobekCM_Library_Settings.System_Base_URL + "default/SobekCM_Item.min.css\" rel=\"stylesheet\" type=\"text/css\" />");

            writer.WriteLine("  <meta name=\"robots\" content=\"index, follow\" />");
            if (skinObject.CSS_Style.Length > 0)
            {
                writer.WriteLine("  <link href=\"" + SobekCM_Library_Settings.System_Base_URL + skinObject.CSS_Style + "\" rel=\"stylesheet\" type=\"text/css\" />");
            }

            string image_src = currentMode.Base_URL + "/" + CurrentItem.Web.AssocFilePath + "/" + CurrentItem.Behaviors.Main_Thumbnail;
            writer.WriteLine("  <link rel=\"image_src\" href=\"" + image_src.Replace("\\", "/").Replace("//", "/").Replace("http:/", "http://") + "\" />");

            writer.WriteLine("</head>");
            writer.WriteLine("<body>");

            // Is this item DARK or PRIVATE
            if ((CurrentItem.Behaviors.Dark_Flag) || ( CurrentItem.Behaviors.IP_Restriction_Membership < 0 ))
            {
                writer.WriteLine("THIS ITEM IS CURRENTLY DARK OR PRIVATE");
                writer.WriteLine("</body>");
                writer.WriteLine("</html>");
                writer.Flush();
                writer.Close();
                return;
            }

            // Add the header
            Display_Header(writer, itemWriter.Skin, CurrentItem);

            // Begin to write the item view
            itemWriter.Write_HTML(writer, tracer);

            if ((CurrentItem.Behaviors.Wordmark_Count > 0) || ((CurrentItem.Web.Static_PageCount > 1) && (CurrentItem.Web.Static_Division_Count > 1)))
            {
                writer.WriteLine("<nav id=\"sbkIsw_Leftnavbar\" style=\"padding-top:3px\">");

                // Write the table of contents as static HTML, rather than the TreeView web control
                if ((CurrentItem.Web.Static_PageCount > 1) && (CurrentItem.Web.Static_Division_Count > 1))
                {
                    writer.WriteLine("  <div class=\"sbkIsw_ShowTocRow\">");
                    writer.WriteLine("    <div class=\"sbkIsw_UpToc\">HIDE TABLE OF CONTENTS</div>");
                    writer.WriteLine("  </div>");

                    writer.WriteLine("<div class=\"sbkIsw_TocTreeView\">");

                    // load the table of contents in the tree
                    TreeView treeView1 = new TreeView();
                    itemWriter.Create_TreeView_From_Divisions(treeView1);

                    // Step through all the parent nodes
                    writer.WriteLine("  <table cellspacing=\"4px\">");
                    foreach (TreeNode thisNode in treeView1.Nodes)
                    {
                        writer.WriteLine("    <tr><td width=\"9px\">&nbsp;</td><td>" + thisNode.Text.Replace("sbkIsw_SelectedTocTreeViewItem", "sbkIsw_TocTreeViewItem") + "</td></tr>");
                    }
                    writer.WriteLine("  </table>");
                    writer.WriteLine("</div>");
                }

            }

            itemWriter.Write_Additional_HTML(writer, tracer);

            //Literal citationLiteral = (Literal)placeHolder.Controls[0];
            //writer.WriteLine(citationLiteral.Text);
            //placeHolder.Controls.Clear();

            writer.WriteLine("<!-- COMMENT HERE -->");

            // Close out this tables and form
            writer.WriteLine("       </tr>");

            // If this is IP restricted, show nothing else
            if (CurrentItem.Behaviors.IP_Restriction_Membership == 0)
            {
                // Add the download list if there are some
                if (CurrentItem.Divisions.Download_Tree.Has_Files)
                {
                    writer.WriteLine("       <tr>");
                    // Create the downloads viewer to ouput the html
                    Download_ItemViewer downloadViewer = new Download_ItemViewer {CurrentItem = CurrentItem, CurrentMode = currentMode};

                    // Add the HTML for this now
                    downloadViewer.Write_Main_Viewer_Section(writer, tracer);
                    writer.WriteLine("       </tr>");
                }

                // If there is a table of contents write it again, this time it will be complete
                // and also show a hierarchy if there is one
                if ((CurrentItem.Web.Static_PageCount > 1) && (CurrentItem.Web.Static_Division_Count > 1))
                {
                    writer.WriteLine("       <tr>");
                    writer.WriteLine("         <td align=\"left\"><span class=\"SobekViewerTitle\">Table of Contents</span></td>");
                    writer.WriteLine("       </tr>");

                    writer.WriteLine("       <tr>");
                    writer.WriteLine("          <td>");
                    writer.WriteLine("            <div class=\"sbkCiv_Citation\">");

                    foreach (abstract_TreeNode treeNode in CurrentItem.Divisions.Physical_Tree.Roots)
                    {
                        recursively_write_toc(writer, treeNode, "&nbsp; &nbsp; ");
                    }

                    writer.WriteLine("            </div>");
                    writer.WriteLine("          </td>");
                    writer.WriteLine("       </tr>");
                }

                // Is the text file location included, in which case any full text should be appended to the end?
                if ((TextFileLocation.Length > 0) && (Directory.Exists(TextFileLocation)))
                {
                    // Get the list of all TXT files in this division
                    string[] text_files = Directory.GetFiles(TextFileLocation, "*.txt");
                    Dictionary<string, string> text_files_existing = new Dictionary<string, string>();
                    foreach (string thisTextFile in text_files)
                    {
                        string text_filename = (new FileInfo(thisTextFile)).Name.ToUpper();
                        text_files_existing[text_filename] = text_filename;
                    }

                    // Are there ANY text files?
                    if (text_files.Length > 0)
                    {
                        // If this has page images, check for related text files
                        List<string> text_files_included = new List<string>();
                        bool started = false;
                        if (CurrentItem.Divisions.Physical_Tree.Has_Files)
                        {
                            // Go through the first 100 text pages
                            List<abstract_TreeNode> pages = CurrentItem.Divisions.Physical_Tree.Pages_PreOrder;
                            int page_count = 0;
                            foreach (Page_TreeNode thisPage in pages)
                            {
                                // Keep track of the page count
                                page_count++;

                                // Look for files in this page
                                if (thisPage.Files.Count > 0)
                                {
                                    bool found_non_thumb_file = false;
                                    foreach (SobekCM_File_Info thisFile in thisPage.Files)
                                    {
                                        // Make sure this is not a thumb
                                        if (thisFile.System_Name.ToLower().IndexOf("thm.jpg") < 0)
                                        {
                                            found_non_thumb_file = true;
                                            string root = thisFile.File_Name_Sans_Extension;
                                            if (text_files_existing.ContainsKey(root.ToUpper() + ".TXT"))
                                            {
                                                string text_file = TextFileLocation + "\\" + thisFile.File_Name_Sans_Extension + ".txt";

                                                // SInce this is marked to be included, save this name
                                                text_files_included.Add(root.ToUpper() + ".TXT");

                                                // For size reasons, we only include the text from the first 100 pages
                                                if (page_count <= 100)
                                                {
                                                    if (!started)
                                                    {
                                                        writer.WriteLine("       <tr>");
                                                        writer.WriteLine("         <td align=\"left\"><span class=\"SobekViewerTitle\">Full Text</span></td>");
                                                        writer.WriteLine("       </tr>");
                                                        writer.WriteLine("       <tr>");
                                                        writer.WriteLine("          <td>");
                                                        writer.WriteLine("            <div class=\"sbkCiv_Citation\">");

                                                        started = true;
                                                    }

                                                    try
                                                    {
                                                        StreamReader reader = new StreamReader(text_file);
                                                        string text_line = reader.ReadLine();
                                                        while (text_line != null)
                                                        {
                                                            writer.WriteLine(text_line + "<br />");
                                                            text_line = reader.ReadLine();
                                                        }
                                                        reader.Close();
                                                    }
                                                    catch
                                                    {
                                                        writer.WriteLine("Unable to read file: " + text_file);
                                                    }

                                                    writer.WriteLine("<br /><br />");
                                                }
                                            }

                                        }

                                        // If a suitable file was found, break here
                                        if (found_non_thumb_file)
                                            break;
                                    }
                                }
                            }

                            // End this if it was ever started
                            if (started)
                            {
                                writer.WriteLine("            </div>");
                                writer.WriteLine("          </td>");
                                writer.WriteLine("       </tr>");
                            }
                        }

                        // Now, check for any other valid text files
                        List<string> additional_text_files = text_files_existing.Keys.Where(ThisTextFile => (!text_files_included.Contains(ThisTextFile.ToUpper())) && (ThisTextFile.ToUpper() != "AGREEMENT.TXT") && (ThisTextFile.ToUpper().IndexOf("REQUEST") != 0)).ToList();

                        // Now, include any additional text files, which would not be page text files, possiblye
                        // full text for included PDFs, Powerpoint, Word Doc, etc..
                        started = false;
                        foreach (string thisTextFile in additional_text_files)
                        {
                            if (!started)
                            {
                                writer.WriteLine("       <tr>");
                                writer.WriteLine("         <td align=\"left\"><span class=\"SobekViewerTitle\">Full Text</span></td>");
                                writer.WriteLine("       </tr>");
                                writer.WriteLine("       <tr>");
                                writer.WriteLine("          <td>");
                                writer.WriteLine("            <div class=\"sbkCiv_Citation\">");

                                started = true;
                            }

                            string text_file = TextFileLocation + "\\" + thisTextFile;

                            try
                            {

                                StreamReader reader = new StreamReader(text_file);
                                string text_line = reader.ReadLine();
                                while (text_line != null)
                                {
                                    writer.WriteLine(text_line + "<br />");
                                    text_line = reader.ReadLine();
                                }
                                reader.Close();
                            }
                            catch
                            {
                                writer.WriteLine("Unable to read file: " + text_file);
                            }

                            writer.WriteLine("<br /><br />");
                        }

                        // End this if it was ever started
                        if (started)
                        {
                            writer.WriteLine("            </div>");
                            writer.WriteLine("          </td>");
                            writer.WriteLine("       </tr>");
                        }
                    }
                }
            }

            writer.WriteLine("      </table>");
            writer.WriteLine("      </div>");

            // Write the footer
            Display_Footer(writer, itemWriter.Skin);

            writer.WriteLine("</body>");
            writer.WriteLine("</html>");

            writer.Flush();
            writer.Close();

            // Restore the text searchable flag and robot flag
            currentMode.Is_Robot = false;
            CurrentItem.Behaviors.Text_Searchable = textSearchable;
        }
All Usage Examples Of SobekCM.Library.HTML.Item_HtmlSubwriter::Write_HTML