Beispiel #1
0
        // Public methods

        public void ProcessDocument()
        {
            this.document = this.browser.Document;
            this.previous = this.url;
            this.url      = this.browser.LocationURL.ToString();
            if (PACER.IsPacerUrl(this.url))
            {
                System.Windows.Forms.MessageBox.Show("Found PACER URL!", "Found PACER URL");
                this.court = PACER.GetCourtFromUrl(this.url);
            }
            else
            {
                this.court = null;
                return;
            }

            if (PACER.IsDocketQueryUrl(this.url))
            {
                this.ProcessDocketQuery();
            }
            if (PACER.IsDocketDisplayUrl(this.url))
            {
                this.ProcessDocketDisplay();
            }
            if (PACER.IsAttachmentMenuPage(this.url, this.document))
            {
                this.ProcessAttachmentMenuPage();
            }
            if (PACER.IsSingleDocumentPage(this.url, this.document))
            {
                this.ProcessSingleDocumentPage();
            }
            this.ProcessLinks();
        }
Beispiel #2
0
        private bool SingleDocumentHandler(IHTMLEventObj e)
        {
            IHTMLElement form    = e.srcElement;
            string       docid   = PACER.GetDocumentIdFromUrl(this.browser.LocationURL);
            string       urlpath = this.browser.LocationURL;

            FormData data = new FormData();

            foreach (IHTMLElement input in ((HTMLFormElement)form).getElementsByTagName("input"))
            {
                if (input.getAttribute("type") == "text")
                {
                    data.Append(input.getAttribute("name"), input.innerText);
                }
            }

            (new XHR(form.getAttribute("action"), data, "arraybuffer", (XHR.Callback)((type, responseData) => {
                byte[] responseBytes = (byte[])responseData;
                if (type == "application/pdf")
                {
                    string filepath = SaveTemporaryPdf(responseBytes);
                    string html = "<body><iframe src=\"file://" + filepath + "\"></iframe></body>";
                    this.ShowPdfPage(docid, urlpath, filepath, html);
                }
                else
                {
                    string html = Encoding.UTF8.GetString(responseBytes);
                    this.ShowPdfPage(docid, urlpath, null, html);
                }
            }))).Send();

            return(true);
        }
Beispiel #3
0
        public static void ConvertDocumentUrl(string url, ConvertDocumentUrlCallback callback)
        {
            string schemeHost = (new Regex(@"^\w+://[^/]+")).Match(url).ToString();
            string query      = (new Regex(@"\?.*")).Match(url).ToString();
            string queryurl   = schemeHost + "/cgi-bin/document_link.pl?document" + query.Replace('?', 'K').Replace('&', 'K').Replace('=', 'V');

            NameValueCollection data = HttpUtility.ParseQueryString(query);

            (new XHR(queryurl, null, "text", (type, responseData) => {
                string newurl = (string)responseData;
                callback(newurl, PACER.GetDocumentIdFromUrl(newurl), data["caseid"], data["de_seq_num"], data["dm_id"], data["doc_num"]);
            })).Send();
        }
Beispiel #4
0
        private void ProcessDocketDisplay()
        {
            string casenum = PACER.GetCaseNumberFromUrl(this.previous);

            if (!String.IsNullOrEmpty(casenum))
            {
                string filename = PACER.GetBaseNameFromUrl(this.url).Replace(".pl", ".html");
                UploadDocket(this.court, casenum, filename, "text/html", this.document.documentElement.innerHTML, (success) => {
                    if (success)
                    {
                        this.ShowUploadNotification("Docket uploaded to the public archive.");
                    }
                });
            }
        }
Beispiel #5
0
        // Callback methods

        private void LinkMouseOverHandler(IHTMLEventObj e)
        {
            IHTMLElement a = e.srcElement;

            if ((a == null) || (a.tagName.ToLower() != "a"))
            {
                return;
            }
            string url = a.getAttribute("href");

            if (PACER.IsConvertibleDocumentUrl(url))
            {
                PACER.ConvertDocumentUrl(url, (newurl, docid, caseid, deseqnum, dmid, docnum) => {
                    UploadMetadata(this.court, docid, caseid, deseqnum, dmid, docnum, null);
                });
            }
        }
Beispiel #6
0
        private void ProcessDocketQuery()
        {
            GetAvailabilityForDocket(this.court, PACER.GetCaseNumberFromUrl(url), (responseData) => {
                CaseQueryResponse caseQueryResponse = (CaseQueryResponse)responseData;
                if (!String.IsNullOrEmpty(caseQueryResponse.docket_url))
                {
                    // <a title="..." href="..."><img src="..."/> ... </a>
                    IHTMLElement a = this.document.createElement("a");
                    a.setAttribute("title", "Docket is available for free from RECAP.");
                    a.setAttribute("href", caseQueryResponse.docket_url);

                    IHTMLElement img = this.document.createElement("img");
                    img.setAttribute("src", "file://" + Path.Combine(typeof(RECAP).Assembly.Location, "icon-16.png"));

                    a.innerText = " Get this docket as of " + caseQueryResponse.timestamp + " for free from RECAP.";
                    ((HTMLAnchorElement)a).insertAdjacentElement("afterBegin", img);

                    // <br/>
                    IHTMLElement br = this.document.createElement("br");

                    // <small> ... </small>
                    IHTMLElement small = this.document.createElement("small");
                    small.innerText    = "Note that archived dockets may be out of date.";

                    // <div class="recap-banner">
                    //   <a> ... </a>
                    //   <br/>
                    //   <small> ... </small>
                    // </div>
                    IHTMLElement div = this.document.createElement("div");
                    div.setAttribute("className", "recap-banner");
                    ((HTMLDivElement)div).insertAdjacentElement("beforeEnd", a);
                    ((HTMLDivElement)div).insertAdjacentElement("beforeEnd", br);
                    ((HTMLDivElement)div).insertAdjacentElement("beforeEnd", small);

                    // <form><div> ... </div></form>
                    foreach (IHTMLElement form in this.document.getElementsByTagName("form"))
                    {
                        ((HTMLFormElement)form).insertAdjacentElement("beforeEnd", div);
                    }
                }
            });
        }
Beispiel #7
0
        private void ProcessLinks()
        {
            IHTMLElementCollection links = this.document.getElementsByTagName("a");
            List <string>          urls  = new List <string>();

            foreach (IHTMLElement link in links)
            {
                string url = link.getAttribute("href");
                if (PACER.IsDocumentUrl(url))
                {
                    urls.Add(url);
                }
            }
            if (urls.Count > 0)
            {
                GetAvailabilityForDocuments(urls.ToArray(), (responseData) => {
                    Hashtable queryResponse = (Hashtable)responseData;
                    foreach (IHTMLElement link in links)
                    {
                        string url = link.getAttribute("href");
                        if (queryResponse.Contains(url) && ((Hashtable)queryResponse[url]).Contains("filename"))
                        {
                            // <a class="..." title="..." href="..."><img src="..."/></a>
                            IHTMLElement a = this.document.createElement("a");
                            a.setAttribute("className", "recap-inline");
                            a.setAttribute("title", "Available for free from RECAP.");
                            a.setAttribute("href", (string)((Hashtable)queryResponse[url])["filename"]);

                            IHTMLElement img = this.document.createElement("img");
                            img.setAttribute("src", "file://" + Path.Combine(typeof(RECAP).Assembly.Location, "icon-16.png"));

                            ((HTMLAnchorElement)a).insertAdjacentElement("beforeEnd", img);

                            // Insert new <a> ... </a> before existing <a> ... </a>
                            ((HTMLAnchorElement)link).insertAdjacentElement("afterEnd", a);
                        }
                    }
                });
            }
            ((HTMLDocumentEvents2_Event)this.document).onmouseover += new HTMLDocumentEvents2_onmouseoverEventHandler(this.LinkMouseOverHandler);
        }
Beispiel #8
0
        private static void GetAvailabilityForDocuments(string[] urls, ObjectCallback callback)
        {
            if (urls.Length > 0)
            {
                string court = PACER.GetCourtFromUrl(urls[0]);
                if (!String.IsNullOrEmpty(court))
                {
                    string url = SERVER_ROOT + "/query/";

                    Hashtable query = new Hashtable();
                    query["court"] = court;
                    query["urls"]  = urls;
                    string data = "json=" + HttpUtility.UrlEncode(JSON.Stringify(query));

                    XHR xhr = (new XHR(url, data, "json", (type, responseData) => { callback(responseData); }));
                    xhr.Send();
                }
                else
                {
                    callback(new Object());
                }
            }
        }
Beispiel #9
0
 public static bool IsConvertibleDocumentUrl(string url)
 {
     return((new Regex(@"/cgi-bin/show_docs")).IsMatch(url) && (PACER.GetCourtFromUrl(url) != null));
 }
Beispiel #10
0
 public static bool IsDocumentUrl(string url)
 {
     return((new Regex(@"(/doc1/\d+|/cgi-bin/show_doc)")).IsMatch(url) && (PACER.GetCourtFromUrl(url) != null));
 }