// 兼容以前的版本 public static string BuildObjectHtmlTable(string strMARC, string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.HttpUrlHitCount) { return(BuildObjectHtmlTable(strMARC, strRecPath, null, style)); }
// 创建 table 中的对象资源局部 XML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectXmlTable(string strMARC, // string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.None, string strMarcSyntax = "unimarc", string strRecPath = null, XmlElement maps_container = null) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) { return(""); } XmlDocument dom = new XmlDocument(); dom.LoadXml("<table/>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; if (strType == null) { strType = ""; } if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || StringUtil.StartsWith(strType, "FrontCover.") == true)) { continue; } string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null List <Map856uResult> u_list = new List <Map856uResult>(); { string u = field.select("subfield[@name='u']").FirstContent; // 2018/10/24 // Hashtable parameters = new Hashtable(); if (maps_container != null && (style & BuildObjectHtmlTableStyle.Template) != 0) { // string strUri = MakeObjectUrl(strRecPath, u); // return: // -1 出错 // 0 没有发生宏替换 // 1 发生了宏替换 int nRet = Map856u(u, strRecPath, maps_container, style, // parameters, out u_list, out string strError); if (nRet == -1) { u_list.Add(new Map856uResult { Result = "!error: 对 858$u 内容 '" + u + "' 进行映射变换时出错: " + strError }); } } else { u_list.Add(new Map856uResult { Result = u }); // WrapUrl == true ? } } string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true || // 2016/9/4 StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "true"; } #if NO string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) { urlLabel = y; } else { urlLabel = f; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strType; } #endif string linkText = ""; if (strMarcSyntax == "unimarc") { linkText = field.select("subfield[@name='2']").FirstContent; } else { linkText = field.select("subfield[@name='y']").FirstContent; } string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(linkText) == false) { urlLabel = linkText; } else { urlLabel = f; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strType; } // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } #if NO string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else { urlTemp = urlLabel; } #endif string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; foreach (Map856uResult u in u_list) { XmlElement line = dom.CreateElement("line"); dom.DocumentElement.AppendChild(line); string strTypeString = (s_3 + " " + strType).Trim(); if (string.IsNullOrEmpty(strTypeString) == false) { line.SetAttribute("type", strTypeString); } string currentUrlLabel = urlLabel; if (string.IsNullOrEmpty(currentUrlLabel) == true) { if (u.AnchorText != null) { currentUrlLabel = Map856uResult.MacroAnchorText(u.AnchorText, currentUrlLabel); } else { currentUrlLabel = u.Result; } } else { if (u.AnchorText != null) { currentUrlLabel = Map856uResult.MacroAnchorText(u.AnchorText, urlLabel); } } if (string.IsNullOrEmpty(currentUrlLabel) == false) { line.SetAttribute("urlLabel", currentUrlLabel); } if (string.IsNullOrEmpty(u.Result) == false) { line.SetAttribute("uri", u.Result); } if (u.Parameters != null && u.Parameters.Count > 0) { line.SetAttribute("uriEnv", StringUtil.BuildParameterString(u.Parameters, ',', '=', "url")); } if (string.IsNullOrEmpty(s_q) == false) { line.SetAttribute("mime", s_q); } if (string.IsNullOrEmpty(strSize) == false) { line.SetAttribute("size", strSize); } if (string.IsNullOrEmpty(s_s) == false) { line.SetAttribute("bytes", s_s); } if (string.IsNullOrEmpty(strSaveAs) == false) { line.SetAttribute("saveAs", strSaveAs); } if (string.IsNullOrEmpty(s_z) == false) { line.SetAttribute("comment", s_z); } nCount++; } } if (nCount == 0) { return(""); } return(dom.DocumentElement.OuterXml); }
/* * <856_maps> * <item type="cxstar" template="http://www.cxstar.com:5000/Book/Detail?pinst=1ca53a3a0001390bce&ruid=%uri%" /> * <item type="default" template="http://*****:*****@"); string uri = parts[0]; string type = parts[1]; XmlNodeList items = null; if (string.IsNullOrEmpty(type)) { items = container.SelectNodes("item[@type='default']"); if (items.Count == 0) { strError = "配置文件中没有配置 type='default' 的 856_maps/item 元素"; return(-1); } } else { items = container.SelectNodes("item[@type='" + type + "']"); if (items.Count == 0) { strError = "配置文件中没有配置 type='" + type + "' 的 856_maps/item 元素"; return(-1); } } foreach (XmlElement item in items) { string template = item.GetAttribute("template"); if (string.IsNullOrEmpty(template)) { strError = "配置文件中元素 " + item.OuterXml + " 没有配置 template 属性"; return(-1); } Hashtable parameters = new Hashtable(); // 取得 _xxxx 属性值 if (parameters != null) { foreach (XmlAttribute attr in item.Attributes) { if (StringUtil.StartsWith(attr.Name, "_")) { parameters[attr.Name.Substring(1)] = attr.Value; } } } string object_path = MakeObjectUrl(strBiblioRecPath, uri); string result = template.Replace("{encoded_object_path}", HttpUtility.UrlEncode(object_path)); result = result.Replace("{encoded_uri}", HttpUtility.UrlEncode(uri)); result = result.Replace("{object_path}", object_path); result = result.Replace("{uri}", uri); result = result.Replace("{getobject_module}", "./getobject.aspx"); string anchorText = item.HasAttribute("anchorText") ? item.GetAttribute("anchorText") : null; bool wrapUrl = DomUtil.IsBooleanTrue(item.GetAttribute("wrapUrl"), true); results.Add(new Map856uResult { Result = result, Parameters = parameters, AnchorText = anchorText, WrapUrl = wrapUrl }); if ((style & BuildObjectHtmlTableStyle.TemplateMultiHit) == 0) { break; } } return(1); }
// 创建 OPAC 详细页面中的对象资源显示局部 HTML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectHtmlTable(string strMARC, string strRecPath, XmlElement maps_container, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.HttpUrlHitCount | BuildObjectHtmlTableStyle.Template, string strMarcSyntax = "unimarc") { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) { return(""); } StringBuilder text = new StringBuilder(); text.Append("<table class='object_table'>"); text.Append("<tr class='column_title'>"); text.Append("<td class='type' style='word-break:keep-all;'>材料</td>"); text.Append("<td class='hitcount'></td>"); text.Append("<td class='link' style='word-break:keep-all;'>链接</td>"); text.Append("<td class='mime' style='word-break:keep-all;'>媒体类型</td>"); text.Append("<td class='size' style='word-break:keep-all;'>尺寸</td>"); text.Append("<td class='bytes' style='word-break:keep-all;'>字节数</td>"); text.Append("</tr>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; // TODO: if (strType == null) { strType = ""; } if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || strType.StartsWith("FrontCover.") == true)) { continue; } string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null List <Map856uResult> u_list = new List <Map856uResult>(); { string u = field.select("subfield[@name='u']").FirstContent; // Hashtable parameters = new Hashtable(); if (maps_container != null && (style & BuildObjectHtmlTableStyle.Template) != 0) { // return: // -1 出错 // 0 没有发生宏替换 // 1 发生了宏替换 int nRet = Map856u(u, strRecPath, maps_container, // parameters, style, out u_list, // strUri, out string strError); //if (nRet == -1) // strUri = "!error:" + strError; if (nRet == -1) { u_list.Add(new Map856uResult { Result = "!error: 对 858$u 内容 '" + u + "' 进行映射变换时出错: " + strError }); } } else { u_list.Add(new Map856uResult { Result = u }); // WrapUrl == true ? } } foreach (Map856uResult result in u_list) { string strUri = MakeObjectUrl(strRecPath, result.Result); Hashtable parameters = result.Parameters; string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true // || StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "&saveas=true"; } string strHitCountImage = ""; string strObjectUrl = strUri; string strPdfUrl = ""; string strThumbnailUrl = ""; if (result.WrapUrl == true) { if (StringUtil.IsHttpUrl(strUri) == false) { // 内部对象 strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs; strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount' alt='hitcount'></img>"; if (s_q == "application/pdf") { strPdfUrl = "./viewpdf.aspx?uri=" + HttpUtility.UrlEncode(strUri); strThumbnailUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri + "/page:1,format=jpeg,dpi:24"); } } else { // http: 或 https: 的情形,即外部 URL if ((style & BuildObjectHtmlTableStyle.HttpUrlHitCount) != 0) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs + "&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath); strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath) + "' alt='hitcount'></img>"; } } } else { strObjectUrl = strUri; strHitCountImage = ""; } string linkText = ""; if (strMarcSyntax == "unimarc") { linkText = field.select("subfield[@name='2']").FirstContent; } else { linkText = field.select("subfield[@name='y']").FirstContent; } string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(linkText) == false) { urlLabel = linkText; } else { urlLabel = f; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strType; } // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strObjectUrl; } // if (StringUtil.StartsWith(strUri, "!error:")) { urlLabel += strUri; } // 2018/11/5 urlLabel = Map856uResult.MacroAnchorText(result.AnchorText, urlLabel); if (string.IsNullOrEmpty(strPdfUrl) == false && string.IsNullOrEmpty(urlLabel) == false) { strPdfUrl += "&title=" + HttpUtility.UrlEncode(urlLabel); } string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { string strParameters = ""; if (parameters != null) { foreach (string name in parameters.Keys) { strParameters += HttpUtility.HtmlAttributeEncode(name) + "='" + HttpUtility.HtmlAttributeEncode(parameters[name] as string) + "' "; // 注意,内容里面是否有单引号? } } urlTemp += "<a class='link' href='" + strObjectUrl + "' " + strParameters.Trim() + " >"; urlTemp += HttpUtility.HtmlEncode( (string.IsNullOrEmpty(strSaveAs) == false ? "下载 " : "") + urlLabel); urlTemp += "</a>"; if (string.IsNullOrEmpty(strPdfUrl) == false) { #if NO // 预览 按钮 urlTemp += "<br/><a href='" + strPdfUrl + "' target='_blank'>"; urlTemp += HttpUtility.HtmlEncode("预览 " + urlLabel); urlTemp += "</a>"; #endif // 缩略图 点按和预览按钮效果相同 urlTemp += "<br/><a class='thumbnail' href='" + strPdfUrl + "' target='_blank' alt='" + HttpUtility.HtmlEncode("在线阅读 " + urlLabel) + "'>"; urlTemp += "<img src='" + strThumbnailUrl + "' alt='" + HttpUtility.HtmlEncode("在线阅读 " + urlLabel) + "'></img>"; urlTemp += "</a>"; } } else { urlTemp = urlLabel; } // Different parts of the item are electronic, using subfield $3 to indicate the part (e.g., table of contents accessible in one file and an abstract in another) // 意思就是,如果有多种部分是电子资源,用 $3 指明当前 856 针对的哪个部分。这时候有多个 856,每个 856 中的 $3 各不相同 string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; text.Append("<tr class='content'>"); text.Append("<td class='type'>" + HttpUtility.HtmlEncode(s_3 + " " + strType) + "</td>"); text.Append("<td class='hitcount' style='text-align: right;'>" + strHitCountImage + "</td>"); text.Append("<td class='link' style='word-break:break-all;'>" + urlTemp + "</td>"); text.Append("<td class='mime'>" + HttpUtility.HtmlEncode(s_q) + "</td>"); text.Append("<td class='size'>" + HttpUtility.HtmlEncode(strSize) + "</td>"); text.Append("<td class='bytes'>" + HttpUtility.HtmlEncode(s_s) + "</td>"); text.Append("</tr>"); if (string.IsNullOrEmpty(s_z) == false) { text.Append("<tr class='comment'>"); text.Append("<td colspan='6'>" + HttpUtility.HtmlEncode(s_z) + "</td>"); text.Append("</tr>"); } nCount++; } } if (nCount == 0) { return(""); } text.Append("</table>"); return(text.ToString()); }
// 创建 table 中的对象资源局部 XML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectXmlTable(string strMARC, // string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.None) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) { return(""); } XmlDocument dom = new XmlDocument(); dom.LoadXml("<table/>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || strType.StartsWith("FrontCover.") == true)) { continue; } string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null string u = field.select("subfield[@name='u']").FirstContent; // string strUri = MakeObjectUrl(strRecPath, u); string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true || // 2016/9/4 StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "true"; } string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) { urlLabel = y; } else { urlLabel = f; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strType; } // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = u; } #if NO string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else { urlTemp = urlLabel; } #endif string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; XmlElement line = dom.CreateElement("line"); dom.DocumentElement.AppendChild(line); string strTypeString = (s_3 + " " + strType).Trim(); if (string.IsNullOrEmpty(strTypeString) == false) { line.SetAttribute("type", strTypeString); } if (string.IsNullOrEmpty(urlLabel) == false) { line.SetAttribute("urlLabel", urlLabel); } if (string.IsNullOrEmpty(u) == false) { line.SetAttribute("uri", u); } if (string.IsNullOrEmpty(s_q) == false) { line.SetAttribute("mime", s_q); } if (string.IsNullOrEmpty(strSize) == false) { line.SetAttribute("size", strSize); } if (string.IsNullOrEmpty(s_s) == false) { line.SetAttribute("bytes", s_s); } if (string.IsNullOrEmpty(strSaveAs) == false) { line.SetAttribute("saveAs", strSaveAs); } if (string.IsNullOrEmpty(s_z) == false) { line.SetAttribute("comment", s_z); } nCount++; } if (nCount == 0) { return(""); } return(dom.DocumentElement.OuterXml); }
// 创建 OPAC 详细页面中的对象资源显示局部 HTML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectHtmlTable(string strMARC, string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.HttpUrlHitCount) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) { return(""); } StringBuilder text = new StringBuilder(); text.Append("<table class='object_table'>"); text.Append("<tr class='column_title'>"); text.Append("<td class='type' style='word-break:keep-all;'>名称</td>"); text.Append("<td class='hitcount'></td>"); text.Append("<td class='link' style='word-break:keep-all;'>链接</td>"); text.Append("<td class='mime' style='word-break:keep-all;'>媒体类型</td>"); text.Append("<td class='size' style='word-break:keep-all;'>尺寸</td>"); text.Append("<td class='bytes' style='word-break:keep-all;'>字节数</td>"); text.Append("</tr>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || strType.StartsWith("FrontCover.") == true)) { continue; } string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null string u = field.select("subfield[@name='u']").FirstContent; string strUri = MakeObjectUrl(strRecPath, u); string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true || StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "&saveas=true"; } string strHitCountImage = ""; string strObjectUrl = strUri; if (StringUtil.IsHttpUrl(strUri) == false) { // 内部对象 strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs; strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount' alt='hitcount'></img>"; } else { // http: 或 https: 的情形,即外部 URL if ((style & BuildObjectHtmlTableStyle.HttpUrlHitCount) != 0) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs + "&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath); strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath) + "' alt='hitcount'></img>"; } } string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) { urlLabel = y; } else { urlLabel = f; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strType; } // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } if (string.IsNullOrEmpty(urlLabel) == true) { urlLabel = strObjectUrl; } string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else { urlTemp = urlLabel; } string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; text.Append("<tr class='content'>"); text.Append("<td class='type'>" + HttpUtility.HtmlEncode(s_3 + " " + strType) + "</td>"); text.Append("<td class='hitcount' style='text-align: right;'>" + strHitCountImage + "</td>"); text.Append("<td class='link' style='word-break:break-all;'>" + urlTemp + "</td>"); text.Append("<td class='mime'>" + HttpUtility.HtmlEncode(s_q) + "</td>"); text.Append("<td class='size'>" + HttpUtility.HtmlEncode(strSize) + "</td>"); text.Append("<td class='bytes'>" + HttpUtility.HtmlEncode(s_s) + "</td>"); text.Append("</tr>"); if (string.IsNullOrEmpty(s_z) == false) { text.Append("<tr class='comment'>"); text.Append("<td colspan='6'>" + HttpUtility.HtmlEncode(s_z) + "</td>"); text.Append("</tr>"); } nCount++; } if (nCount == 0) { return(""); } text.Append("</table>"); return(text.ToString()); }
// 创建 table 中的对象资源局部 XML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectXmlTable(string strMARC, // string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.None) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) return ""; XmlDocument dom = new XmlDocument(); dom.LoadXml("<table/>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || strType.StartsWith("FrontCover.") == true)) continue; string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null string u = field.select("subfield[@name='u']").FirstContent; // string strUri = MakeObjectUrl(strRecPath, u); string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true // 2016/9/4 || StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "true"; } #if NO string strObjectUrl = strUri; if (StringUtil.HasHead(strUri, "http:") == false && StringUtil.HasHead(strUri, "https:") == false) { // 内部对象 strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs; } else { // http: 或 https: 的情形,即外部 URL if ((style & BuildObjectHtmlTableStyle.HttpUrlHitCount) != 0) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs + "&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath); } } #endif string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) urlLabel = y; else urlLabel = f; if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = strType; // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = u; #if NO string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else urlTemp = urlLabel; #endif string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; XmlElement line = dom.CreateElement("line"); dom.DocumentElement.AppendChild(line); string strTypeString = (s_3 + " " + strType).Trim(); if (string.IsNullOrEmpty(strTypeString) == false) line.SetAttribute("type", strTypeString); if (string.IsNullOrEmpty(urlLabel) == false) line.SetAttribute("urlLabel", urlLabel); if (string.IsNullOrEmpty(u) == false) line.SetAttribute("uri", u); if (string.IsNullOrEmpty(s_q) == false) line.SetAttribute("mime", s_q); if (string.IsNullOrEmpty(strSize) == false) line.SetAttribute("size", strSize); if (string.IsNullOrEmpty(s_s) == false) line.SetAttribute("bytes", s_s); if (string.IsNullOrEmpty(strSaveAs) == false) line.SetAttribute("saveAs", strSaveAs); if (string.IsNullOrEmpty(s_z) == false) line.SetAttribute("comment", s_z); nCount++; } if (nCount == 0) return ""; return dom.DocumentElement.OuterXml; }
// 创建 OPAC 详细页面中的对象资源显示局部 HTML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectHtmlTable(string strMARC, string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.HttpUrlHitCount) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) return ""; StringBuilder text = new StringBuilder(); text.Append("<table class='object_table'>"); text.Append("<tr class='column_title'>"); text.Append("<td class='type' style='word-break:keep-all;'>名称</td>"); text.Append("<td class='hitcount'></td>"); text.Append("<td class='link' style='word-break:keep-all;'>链接</td>"); text.Append("<td class='mime' style='word-break:keep-all;'>媒体类型</td>"); text.Append("<td class='size' style='word-break:keep-all;'>尺寸</td>"); text.Append("<td class='bytes' style='word-break:keep-all;'>字节数</td>"); text.Append("</tr>"); int nCount = 0; foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; if (string.IsNullOrEmpty(strType) == false && (style & BuildObjectHtmlTableStyle.FrontCover) == 0 && (strType == "FrontCover" || strType.StartsWith("FrontCover.") == true)) continue; string strSize = (string)table["size"]; string s_q = field.select("subfield[@name='q']").FirstContent; // 注意, FirstContent 可能会返回 null string u = field.select("subfield[@name='u']").FirstContent; string strUri = MakeObjectUrl(strRecPath, u); string strSaveAs = ""; if (string.IsNullOrEmpty(s_q) == true || StringUtil.MatchMIME(s_q, "text") == true || StringUtil.MatchMIME(s_q, "image") == true) { } else { strSaveAs = "&saveas=true"; } string strHitCountImage = ""; string strObjectUrl = strUri; if (StringUtil.HasHead(strUri, "http:") == false && StringUtil.HasHead(strUri, "https:") == false) { // 内部对象 strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs; strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount' alt='hitcount'></img>"; } else { // http: 或 https: 的情形,即外部 URL if ((style & BuildObjectHtmlTableStyle.HttpUrlHitCount) != 0) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri) + strSaveAs + "&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath); strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount&biblioRecPath=" + HttpUtility.UrlEncode(strRecPath) + "' alt='hitcount'></img>"; } } string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) urlLabel = y; else urlLabel = f; if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = strType; // 2015/11/26 string s_z = field.select("subfield[@name='z']").FirstContent; if (string.IsNullOrEmpty(urlLabel) == true && string.IsNullOrEmpty(s_z) == false) { urlLabel = s_z; s_z = ""; } if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = strObjectUrl; string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else urlTemp = urlLabel; string s_3 = field.select("subfield[@name='3']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; text.Append("<tr class='content'>"); text.Append("<td class='type'>" + HttpUtility.HtmlEncode(s_3 + " " + strType) + "</td>"); text.Append("<td class='hitcount' style='text-align: right;'>" + strHitCountImage + "</td>"); text.Append("<td class='link' style='word-break:break-all;'>" + urlTemp + "</td>"); text.Append("<td class='mime'>" + HttpUtility.HtmlEncode(s_q) + "</td>"); text.Append("<td class='size'>" + HttpUtility.HtmlEncode(strSize) + "</td>"); text.Append("<td class='bytes'>" + HttpUtility.HtmlEncode(s_s) + "</td>"); text.Append("</tr>"); if (string.IsNullOrEmpty(s_z) == false) { text.Append("<tr class='comment'>"); text.Append("<td colspan='6'>" + HttpUtility.HtmlEncode(s_z) + "</td>"); text.Append("</tr>"); } nCount++; } if (nCount == 0) return ""; text.Append("</table>"); return text.ToString(); }
// 创建 OPAC 详细页面中的对象资源显示局部 HTML。这是一个 <table> 片段 // 前导语 $3 // 链接文字 $y $f // URL $u // 格式类型 $q // 对象ID $8 // 对象尺寸 $s // 公开注释 $z public static string BuildObjectHtmlTable(string strMARC, string strRecPath, BuildObjectHtmlTableStyle style = BuildObjectHtmlTableStyle.HttpUrlHitCount) { // Debug.Assert(false, ""); MarcRecord record = new MarcRecord(strMARC); MarcNodeList fields = record.select("field[@name='856']"); if (fields.count == 0) return ""; StringBuilder text = new StringBuilder(); text.Append("<table class='object_table'>"); text.Append("<tr class='column_title'>"); text.Append("<td>名称</td>"); text.Append("<td></td>"); text.Append("<td>链接</td>"); text.Append("<td>媒体类型</td>"); text.Append("<td>尺寸</td>"); text.Append("<td>字节数</td>"); text.Append("</tr>"); foreach (MarcField field in fields) { string x = field.select("subfield[@name='x']").FirstContent; Hashtable table = StringUtil.ParseParameters(x, ';', ':'); string strType = (string)table["type"]; string strSize = (string)table["size"]; string u = field.select("subfield[@name='u']").FirstContent; string strUri = MakeObjectUrl(strRecPath, u); string strHitCountImage = ""; string strObjectUrl = strUri; if (StringUtil.HasHead(strUri, "http:") == false && StringUtil.HasHead(strUri, "https:") == false) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri); strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount' alt='hitcount'></img>"; } else { // http: 或 https: 的情形 if ((style & BuildObjectHtmlTableStyle.HttpUrlHitCount) != 0) { strObjectUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strUri); strHitCountImage = "<img src='" + strObjectUrl + "&style=hitcount' alt='hitcount'></img>"; } } string y = field.select("subfield[@name='y']").FirstContent; string f = field.select("subfield[@name='f']").FirstContent; string urlLabel = ""; if (string.IsNullOrEmpty(y) == false) urlLabel = y; else urlLabel = f; if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = strType; if (string.IsNullOrEmpty(urlLabel) == true) urlLabel = strObjectUrl; string urlTemp = ""; if (String.IsNullOrEmpty(strObjectUrl) == false) { urlTemp += "<a href='" + strObjectUrl + "'>"; urlTemp += urlLabel; urlTemp += "</a>"; } else urlTemp = urlLabel; string s_3 = field.select("subfield[@name='3']").FirstContent; string s_q = field.select("subfield[@name='q']").FirstContent; string s_s = field.select("subfield[@name='s']").FirstContent; string s_z = field.select("subfield[@name='z']").FirstContent; text.Append("<tr class='content'>"); text.Append("<td>"+HttpUtility.HtmlEncode(s_3 + " " + strType)+"</td>"); text.Append("<td style='text-align: right;'>" + strHitCountImage + "</td>"); text.Append("<td>" + urlTemp + "</td>"); text.Append("<td>"+HttpUtility.HtmlEncode(s_q)+"</td>"); text.Append("<td>"+HttpUtility.HtmlEncode(strSize)+"</td>"); text.Append("<td>"+HttpUtility.HtmlEncode(s_s)+"</td>"); text.Append("</tr>"); if (string.IsNullOrEmpty(s_z) == false) { text.Append("<tr class='comment'>"); text.Append("<td colspan='5'>" + HttpUtility.HtmlEncode(s_z) + "</td>"); text.Append("</tr>"); } } text.Append("</table>"); return text.ToString(); }