View the DQSD CVS repository here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Update of /cvsroot/dqsd/dqsd/addons/genealogy
In directory usw-pr-cvs1:/tmp/cvs-serv14597/addons/genealogy

Modified Files:
        census.xml genealogy_lib.js usgw.xml 
Added Files:
        at95.xml 
Log Message:
added 1895 atlas search
updated census, usgw to go straight to counties if specified
updated genealogy_lib to support the updated and new searches

--- NEW FILE: at95.xml ---
<search function="at95">
  <name>1895 U.S. Atlas</name>
  <description>
    Goto 1895 U.S. Atlas state and county web pages.<br/>
    <div class="helpboxDescLabels">Examples:</div>
    <table class="helpboxDescTable">
      <tr><td>at95 berrien, mi</td></tr>
      <tr><td>at95 virginia</td></tr>
    </table>
  </description>
  <link>http://www.livgenmi.com/1895</link>
  <category>Genealogy</category>
  <contributor>Brent Beardsley</contributor>

  <script src="addons/genealogy/genealogy_lib.js"></script>
  <script><![CDATA[
    function at95(q)
    {
      if( nullArgs("at95", q) )
        return false;

      if (!genealogy_check_lib_version("1.4")) {
        return false;
      }

      var search_url = "http://www.livgenmi.com/1895";;
      var state = genealogy_parse_place_state(q);
      var county = genealogy_parse_place_county(q);
      var state_abbrev = genealogy_lookup_place_abbrev(state);
      if (state_abbrev.length > 0) {
        var state_url = 
"http://www.livgenmi.com/"+state_abbrev.toLowerCase()+"1895mp"; 
        var county_url = "http://www.livgenmi.com/"+county.replace(new RegExp("\\s", 
"gim"), "").toLowerCase()+state_abbrev.toUpperCase()+".htm";
        var county_list_url = 
"http://www.livgenmi.com/"+state_abbrev.toLowerCase()+"county.htm";
        if (county.length > 0) {
          if (genealogy_webpage_exists(county_url)) {
            search_url = county_url;
          } else {
            search_url = county_list_url;
          }
        } else {
          search_url = state_url;
        }
      }
      openSearchWindow(search_url);
    }
    ]]>
  </script>
</search>
Index: census.xml
===================================================================
RCS file: /cvsroot/dqsd/dqsd/addons/genealogy/census.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** census.xml  21 Sep 2002 07:26:55 -0000      1.3
--- census.xml  25 Sep 2002 15:26:12 -0000      1.4
***************
*** 5,9 ****
      <div class="helpboxDescLabels">Examples:</div>
      <table class="helpboxDescTable">
!       <tr><td>census mi</td></tr>
        <tr><td>census alaska</td></tr>
      </table>
--- 5,9 ----
      <div class="helpboxDescLabels">Examples:</div>
      <table class="helpboxDescTable">
!       <tr><td>census berrien, mi</td></tr>
        <tr><td>census alaska</td></tr>
      </table>
***************
*** 22,49 ****
          return false;
  
!       if (!genealogy_check_lib_version("1.3")) {
!       return false;
!       }
  
!       var census_links = 
genealogy_get_known_page_links("http://www.census-online.com/links/";);
        var state = genealogy_parse_place_state(q);
        var county = genealogy_parse_place_county(q);
        var search_place_num = genealogy_lookup_place(state);
        if (search_place_num >= 0) {
        if (county.length > 0) {
!         var webpage = genealogy_get_webpage(census_links[search_place_num]);
          var links = genealogy_get_page_links(webpage, county);
          if (links != null && links.length > 0) {
!               var linkToOpen = genealogy_build_url(census_links[search_place_num], 
genealogy_link_get_href(links[0]));
!               openSearchWindow(linkToOpen);
!         } else {
!           openSearchWindow(census_links[search_place_num]);
          }
-       } else {
-           openSearchWindow(census_links[search_place_num]);
        }
-       } else {
-       openSearchWindow("http://www.census-online.com/links/";);
        }
      }
      ]]>
--- 22,45 ----
          return false;
  
!       if (!genealogy_check_lib_version("1.3")) { 
!         return false; 
!       } 
  
!       var search_url = "http://www.census-online.com/links/";;
!       var census_links = genealogy_get_known_page_links(search_url);
        var state = genealogy_parse_place_state(q);
        var county = genealogy_parse_place_county(q);
        var search_place_num = genealogy_lookup_place(state);
        if (search_place_num >= 0) {
+         search_url = census_links[search_place_num];
        if (county.length > 0) {
!         var webpage = genealogy_get_webpage(search_url);
          var links = genealogy_get_page_links(webpage, county);
          if (links != null && links.length > 0) {
!               search_url = genealogy_build_url(search_url, 
genealogy_link_get_href(links[0]));
          }
        }
        }
+       openSearchWindow(search_url);
      }
      ]]>

Index: genealogy_lib.js
===================================================================
RCS file: /cvsroot/dqsd/dqsd/addons/genealogy/genealogy_lib.js,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** genealogy_lib.js    21 Sep 2002 07:26:55 -0000      1.3
--- genealogy_lib.js    25 Sep 2002 15:26:12 -0000      1.4
***************
*** 1,4 ****
      var genealogy_debug = 0;
!     var genealogy_lib_version = "1.3";
  
        var genealogy_states = new Array(
--- 1,4 ----
      var genealogy_debug = 0;
!     var genealogy_lib_version = "1.4";
  
        var genealogy_states = new Array(
***************
*** 16,20 ****
        "OHIO", "OKLAHOMA", "OREGON",
        "PENNSYLVANIA",
!       "RHODE_ISLAND",
        "SOUTH CAROLINA", "SOUTH DAKOTA",
        "TENNESSEE", "TEXAS",
--- 16,20 ----
        "OHIO", "OKLAHOMA", "OREGON",
        "PENNSYLVANIA",
!       "RHODE ISLAND",
        "SOUTH CAROLINA", "SOUTH DAKOTA",
        "TENNESSEE", "TEXAS",
***************
*** 34,38 ****
        "KS", "KY",
        "LA",
!       "ME", "MD", "MA", "MI", "MN", "MI", "MS", "MT",
        "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND",
        "OH", "OK", "OR", 
--- 34,38 ----
        "KS", "KY",
        "LA",
!       "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT",
        "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND",
        "OH", "OK", "OR", 
***************
*** 59,62 ****
--- 59,65 ----
           start++;
     }
+    if (start >= end)   {
+          return "";
+    }
     while (str.charAt(end) == ' ') {
           end--;
***************
*** 65,69 ****
           return str.substring(start, end+1);
     } else {
!               return str;
     }
  }
--- 68,72 ----
           return str.substring(start, end+1);
     } else {
!        return str;
     }
  }
***************
*** 106,109 ****
--- 109,119 ----
  }
  
+ function genealogy_log(msg)
+ {
+       if (genealogy_debug != null && genealogy_debug != 0) {
+         appendFile("genealogy.log", msg+"\r\n");
+       }
+ }
+ 
  function genealogy_error(msg)
  {
***************
*** 314,344 ****
                        }
                }
!       }
  
        // it must be a relative link
        var last_backslash = cur_url.lastIndexOf('/');
!       if (last_backslash > 5) {
!               // not the :// <-
                return cur_url.substring(0, last_backslash+1)+link_url;
        } else {
!               genealogy_error("Problem building url {cur_url: "+cur_url+", link_url: 
"+link_url);
!               return link_url;
        }
  
  }
  
  
! function genealogy_get_webpage(webpage_url, search_name, refresh_time)
  {
-       // if search_name not specified || refresh_time == 0 || search_name.cache does 
not exist || (current date - search_name.cache date) > refresh_time) Re-download from 
web
        var http_obj = new ActiveXObject("Microsoft.XMLHTTP");
!       http_obj.Open('GET',webpage_url,false);
!       http_obj.Send();
!       return http_obj.responseText;
  }
  
  function genealogy_link_get_href(link)
  {
!       var links_regex = new RegExp("<a href=\"(.*?)\".*?>(.*?)<\/a>", "gim");
        var parts = links_regex.exec(link);
        if (parts != null && parts.length > 1) {
--- 324,430 ----
                        }
                }
!       } else if (link_url.match("^#")) {
!               return cur_url + link_url;
!       } 
  
        // it must be a relative link
        var last_backslash = cur_url.lastIndexOf('/');
!       var last_period = cur_url.lastIndexOf('.');
!       if (last_backslash > 6 && last_period > last_backslash) {
!               // not the :// and has a filename at the end of the url
                return cur_url.substring(0, last_backslash+1)+link_url;
        } else {
!               if (last_backslash == cur_url.length-1) {
!                       return cur_url+link_url;
!               } else {
!                       return cur_url+"/"+link_url;
!               }
        }
  
  }
+ function genealogy_get_webpage(webpage_url, search_name, refresh_time)
+ {
+       // TODO: caching - 
+       //   if search_name not specified || 
+       //      refresh_time == 0 || 
+       //      search_name.cache does not exist || 
+       //      (current date - search_name.cache date) > refresh_time)
+       //   then Re-download from web
+       return genealogy_webpage_get(webpage_url);
+ }
  
+ function genealogy_webpage_get(webpage_url)
+ {
+       var xmlhttp = false;
+       try     {
+               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");               
+       } catch (e) {
+               xmlhttp = false;
+       }
+       if (!xmlhttp) {
+               return "";
+       }
+     xmlhttp.Open('GET',webpage_url,false);
+       try     {
+               xmlhttp.Send();
+       }
+       catch (e) {
+               xmlhttp = null;
+               return "";
+       }
+       var page_src = xmlhttp.responseText;
+       xmlhttp = null;
+       return page_src;
+ }
  
! function genealogy_webpage_exists(webpage_url)
  {
        var http_obj = new ActiveXObject("Microsoft.XMLHTTP");
!       http_obj.Open('HEAD',webpage_url,false);
!       try {
!               http_obj.Send();
!       }
!       catch (e) {
!               return false;
!       }
!       var status = http_obj.status;
!       http_obj = null;
!       return (status == 200) ? true : false;
! }
! 
! function genealogy_webpage_get_links(webpage_src)
! {
!       var list = new Array();
!       var links_regex = new RegExp("<a (.*?)>.*?<\/a>", "gim");
!       var new_source = webpage_src.replace(/\r|\n/g, ' '); 
!       var link = null;
!       var i = 0;
!       while ( (link = links_regex.exec(new_source)) != null) {
!               list[i] = link[0];
!               i++;
!       }
!       return list;
! }
! 
! function genealogy_links_get_matching_named_links(links, matching_regex, 
not_matching_regex)
! {
!       var list = new Array();
!       var j = 0;
!       for (var i=0; i < links.length; i++) {
!               var name = genealogy_link_get_name(links[i]);
!               var matching = (matching_regex == null || (matching_regex != null && 
matching_regex.test(name))) ? true : false;
!               var not_matching = (not_matching_regex == null || 
!not_matching_regex.test(name)) ? true : false;
!               genealogy_alert("name: "+name+", matching: "+matching+", not_matching: 
"+not_matching);
!               if (matching && not_matching) {
!                       list[j] = links[i];
!                       j++;
!               }
!       }
!       return list;
  }
  
  function genealogy_link_get_href(link)
  {
!       var links_regex = new RegExp("href=\"(.*?)\"", "gim");
        var parts = links_regex.exec(link);
        if (parts != null && parts.length > 1) {
***************
*** 350,357 ****
  function genealogy_link_get_name(link)
  {
!       var links_regex = new RegExp("<a href=\"(.*?)\".*?>(.*?)<\/a>", "gim");
        var parts = links_regex.exec(link);
!       if (parts != null && parts.length > 2) {
!               return parts[2];
        }
        return "";
--- 436,445 ----
  function genealogy_link_get_name(link)
  {
!       var links_regex = new RegExp("<a.*?>(.*?)<\/a>", "gim");
        var parts = links_regex.exec(link);
!       if (parts != null && parts.length > 1) {
!               // replace <br> tags with space, strip rest of tags, replace &nbsp; 
with space, replace &amp; with &, replace multiple spaces with one space
!               var name = 
genealogy_trim(genealogy_strip_tags(parts[1].replace(/\<br\>/gim, " 
")).replace(/&nbsp;/gim, " ").replace(/&amp;/gim, "&").replace(/\s{2,}/gim, " "));
!               return name;
        }
        return "";
***************
*** 360,388 ****
  function genealogy_get_page_links(webpage_source, matching_name)
  {
!       var matching_name_regex = null;
!       if (matching_name != null) {
!               matching_name_regex = new RegExp(matching_name, "i");
!       }
!       var links_regex = new RegExp("<a href=\"(.*?)\".*?>(.*?)<\/a>", "gim");
!       //var links_regex = new RegExp("<a.*?\/a>", "gim");
!       var link;
!       var arr = new Array();
! 
!       // replace cr/lf with space for regex to work better
!       var new_source = webpage_source.replace(/\r|\n/g, ' '); 
! 
!       // add links to array
!       var i = 0;
!       while ( (link = links_regex.exec(new_source)) != null) {
!               if (matching_name_regex != null) {
!                       var link_name = link[2];
!                       if (!link_name.match(matching_name_regex)) {
!                               continue;
!                       }
!               }
!               arr[i] = link[0];
!               i++;
        }
-       return arr;
  }
  
--- 448,457 ----
  function genealogy_get_page_links(webpage_source, matching_name)
  {
!       var links = genealogy_webpage_get_links(webpage_source);
!       if (matching_name != null && matching_name.length > 0){
!               return genealogy_links_get_matching_named_links(links, new 
RegExp(matching_name, "i"), null);
!       } else {
!               return links;
        }
  }
  
***************
*** 391,395 ****
--- 460,466 ----
        var webpage = genealogy_get_webpage(webpage_url);
        var links = genealogy_get_page_links(webpage, matching_name);
+       genealogy_log("done with genealogy_get_page_links for matching_name: 
+"+matching_name);
        if (links != null && links.length > 0) {
+               genealogy_log("calling genealogy_build_url for matching_name: 
+"+matching_name);
                return genealogy_build_url(webpage_url, 
genealogy_link_get_href(links[0]));
        } else {
***************
*** 414,418 ****
                }
        }
!       genealogy_error("This search requires version '"+required_version+" of 
genealogy_lib.js");
        return false;
  }
--- 485,489 ----
                }
        }
!       genealogy_error("This search requires version "+required_version+" of 
genealogy_lib.js");
        return false;
  }
***************
*** 439,443 ****
        }
        var webpage_source = genealogy_get_webpage(webpage_url, search_name, 
refresh_time);
!       var links_regex = new RegExp("<a href=\"(.*?)\".*?>(.*?)<\/a>", "i");
        var replace_spaces_regex = new RegExp("_");
        var replace_nothing_regex = new RegExp("\n\.");
--- 510,515 ----
        }
        var webpage_source = genealogy_get_webpage(webpage_url, search_name, 
refresh_time);
!       var links_regex = new RegExp("<a.*?href=\"(.*?)\".*?>(.*?)<\/a>", "i");
!       var replace_multiple_spaces = new RegExp("\\s{2,}", "gim");
        var replace_spaces_regex = new RegExp("_");
        var replace_nothing_regex = new RegExp("\n\.");
***************
*** 458,463 ****
                if (link == null || link.length != 3)
                        continue;
!               genealogy_alert(link[2] + " "+link[1]);
!               var place = 
genealogy_trim(genealogy_strip_tags(link[2].replace(replace_spaces_regex, " 
").replace(replace_nothing_regex, "")));
                if (match_regex != null) {
                        if (!place.match(match_regex))
--- 530,535 ----
                if (link == null || link.length != 3)
                        continue;
!               genealogy_log(link[2] + " "+link[1]);
!               var place = 
genealogy_trim(genealogy_strip_tags(link[2].replace(replace_spaces_regex, " 
").replace(replace_nothing_regex, "")).replace(replace_multiple_spaces, " "));
                if (match_regex != null) {
                        if (!place.match(match_regex))
***************
*** 469,473 ****
                        }
                }
!               genealogy_alert("\""+place+"\"");
                var place_num = genealogy_lookup_place(place);
                if (place_num == -1)
--- 541,545 ----
                        }
                }
!               genealogy_log("\""+place+"\"");
                var place_num = genealogy_lookup_place(place);
                if (place_num == -1)

Index: usgw.xml
===================================================================
RCS file: /cvsroot/dqsd/dqsd/addons/genealogy/usgw.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** usgw.xml    22 Aug 2002 20:23:50 -0000      1.2
--- usgw.xml    25 Sep 2002 15:26:12 -0000      1.3
***************
*** 5,9 ****
      <div class="helpboxDescLabels">Examples:</div>
      <table class="helpboxDescTable">
!       <tr><td>usgw mi</td></tr>
        <tr><td>usgw district of columbia</td></tr>
      </table>
--- 5,9 ----
      <div class="helpboxDescLabels">Examples:</div>
      <table class="helpboxDescTable">
!       <tr><td>usgw berrien, mi</td></tr>
        <tr><td>usgw district of columbia</td></tr>
      </table>
***************
*** 23,33 ****
          return false;
  
!       var links = 
genealogy_get_known_page_links("http://www.usgenweb.org/statelinkstext.html";);
!       var search_place_num = genealogy_lookup_place(q);
        if (search_place_num >= 0) {
!         openSearchWindow(links[search_place_num]);
        } else {
!       openSearchWindow("http://www.usgenweb.org/statelinks-table.html";);
        }
      }
      ]]>
--- 23,126 ----
          return false;
  
!       if (!genealogy_check_lib_version("1.4")) {
!       return false;
!       }
! 
!       var state_search_url = 'http://www.usgenweb.org/statelinks-table.html';
!       var args = parseArgs(q, "map, table, list");
!       if (args.switches.length > 0) {
!       switch (args.switches[0].name) {
!       case 'map':
!         state_search_url = 'http://www.usgenweb.org/statelinks.html';
!         break;
!       case 'list':
!         state_search_url = 'http://www.usgenweb.org/statelinkstext.html';
!         break;
!       case 'table':
!       default:
!         state_search_url = 'http://www.usgenweb.org/statelinks-table.html';
!         break;
!       }
!       }
! 
!       var search_url = "http://www.usgenweb.org/statelinks-table.html";;
!       var state = genealogy_parse_place_state(args.q);
!       var county = genealogy_parse_place_county(args.q);
!       var links = genealogy_get_known_page_links(search_url);
!       var search_place_num = genealogy_lookup_place(state);
!       var page_src = null;
        if (search_place_num >= 0) {
!         // got a valid state
!         search_url = links[search_place_num];
!       if (county.length > 0) {
!         // has a county, too
!         page_src = genealogy_webpage_get(search_url);
!         links = genealogy_webpage_get_links(page_src);
!         if (links.length == 1) {
!           // if only one link assume it's a redirect
!           genealogy_alert("only one link available assuming it's a redirect.");
!           search_url = genealogy_build_url(search_url, 
genealogy_link_get_href(links[0]));
!           page_src = genealogy_webpage_get(search_url);
!           links = genealogy_webpage_get_links(page_src)
!         }
!           var county_regex = new RegExp("^"+county+"( County)?", "i");
!         genealogy_alert("looking for "+county);
!         var matching_links = genealogy_links_get_matching_named_links(links, 
county_regex, null);
!         if (matching_links.length > 0) {
!           // found the county link
!           search_url = genealogy_build_url(search_url, 
genealogy_link_get_href(matching_links[0]));           
!         } else {
!           // look for the county list page
!           genealogy_alert("didn't find county so looking for county list page");
!           var ignore_regex = new RegExp("\\bMap\\b", "i");
!           var county_list_regex = new RegExp(
!               "("+
!               "Alphabetical List|"+
!               "County Alphabetical Index|"+
!               "County Sites|"+
!               "County List|"+
!               "County Links|"+
!               "County Table|"+
!               "County Listings|"+
!               "County Pages|"+
!               "County Selection|"+
!               "Counties Selection List|"+
!               "List of Counties|"+
!               "Ohio's 88 Counties|"+
!               "Parish Sites|"+
!               "Research by County|"+
!               "Select a (.*?)County|"+
!               "Table with (.*?)Links|"+
!               "Table Listing|"+
!               "Quick Links|"+
!               "^Counties( [A-Z]-[A-Z])?$|"+
!               "^List$|"+
!               "^Table version$"+
!               ")",
!               "i"
!           );
!           matching_links = genealogy_links_get_matching_named_links(links, 
county_list_regex, ignore_regex);
!           if (matching_links.length > 0) {
!             // got the county list page now look for the county again
!             search_url = genealogy_build_url(search_url, 
genealogy_link_get_href(matching_links[0]));         
!             genealogy_alert("found county list page at "+search_url+" now looking 
for "+county);
!               page_src = genealogy_webpage_get(search_url);
!             links = genealogy_webpage_get_links(page_src);
!             matching_links = genealogy_links_get_matching_named_links(links, 
county_regex, null);
!             if (matching_links.length > 0) {
!               // got the county
!               search_url = genealogy_build_url(search_url, 
genealogy_link_get_href(matching_links[0]));               
!             } else {
!               genealogy_alert("couldn't find county - giving up.");
!             }
!             } else {
!               genealogy_alert("couldn't find county list page - giving up.");
!           }
!         }
!       }
        } else {
!         search_url = state_search_url;
        }
+       openSearchWindow(search_url);
      }
      ]]>




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
DQSD-CVS mailing list
https://lists.sourceforge.net/lists/listinfo/dqsd-cvs
DQSD CVS repository:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Reply via email to