开发者

mozilla extension for transliteration of devanagri to gujarti

开发者 https://www.devze.com 2023-02-18 03:45 出处:网络
i have created an extension for mozilla firefox button,which will transliterate a particular webpage.

i have created an extension for mozilla firefox button,which will transliterate a particular webpage. the button code is pasted in %appdata% of mozilla.the code for button.js is as follows

function doSomething()
{ 
    let url = "http://localhost/aaa/trial.asp";
  let request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
   request.onload = function(aEvent) {

    doc=gBrowser.contentDocument;
    doc.body.innerHTML = "<div>" + gBrowser.contentDocument.body.innerHTML  + "</div>";
    doc.body.innerHTML = "<div style='background-color: gray' >" + aEvent.target.responseText + "</div>"   + gBrowser.contentDocument.body.innerHTML;
    doc.body.innerHTML = gBrowser.contentDocument.body.innerHTML + "<div  id='in_trans_overlay'><a id='in_trans_lnk' href='javascript:hide(0); void 0;'>click here  to see the original page</a></div>" ;
    doc.getElementById("in_trans_overlay").style.left="0px";
    doc.getElementById("in_trans_overlay").style.top="0px";
    doc.getElementById("in_trans_overlay").style.position="fixed"; 
    doc.getElementById("in_trans_overlay").style.backgroundColor="blue";
    //doc.getElementById("in_trans_overlay").style.opacity="0.4";
    doc.getElementById("in_trans_overlay").style.width="100%";
    doc.getElementById("in_trans_overlay").style.zIndex="10";
    doc.getElementById("in_trans_lnk").style.color="white";
    //doc.getElementById("in_trans_lnk").style.opacity="1.0";

    doc.body.childNodes[1].style.display="none";

    hd=doc.getElementsByTagName("head");
    scpt=doc.createElement("script");
    scpt.setAttribute("type", "text/javascript");
    scpt.setAttribute("charset", "UTF-8");
    scpt.setAttribute("src", "http://localhost/aaa/hide.js");
    hd[0].appendChild(scpt);
   };
   request.onerror = function(aEvent) {
        window.alert("Error Status: " + aEvent.target.status );
   };

   request.open("POST", url, true);
   request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   params = gBrowser.contentDocument.body.innerHTML;

   params = "inTransContent=" + encodeURIComponent(params);
   request.setRequestHeader("Content-length", params.length);
   request.setRequestHeader("Connection", "close");

   request.send(params);

}

this code sends an xmlhttprequest and it will execute trial.asp code.

trial.asp contains the following code

<% Dim xmlDoc 
Dim objNodeList
    Dim count

    set xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0")

    xmlDoc.validateOnParse = False
    xmlDoc.async = False

    xmlDoc.loadXML("<div>" & Request.Form("inTransContent")   & "</div>")   

    If (xmlDoc.parseError.errorCode <> 0) Then
        Dim myErr
        Set myErr = xmlDoc.parseError
        Response.Write("<div><br><br><br>" & myErr.reason & "<br>" & myErr.line & "<br>" & myErr.srcText & "</div>")
    Else
          Set objNodeList = xmlDoc.documentElement.selectNodes("//text()")
          count = objNodeList.length

          For i = 1 To count 
               objNodeList(i-1).insertData 0, "XYZ " 
               objNodeList(i-1).insertData objNodeList(i-1).length, " XYZ" 
          Next 

          Response.Write(xmlDoc.documentElement.xml)
   End If

%>

this code will send only the text nodes which are to be transliterated,since i havent progressed much in the for loop so i have replaced it with dummy..which appends xyz before and at the end. i need to convert this asp code because i am going to asp.net. i need to convert this to vb.net or c# code..i will come back to the for loop later..this code should become the default.aspx file in asp.net.

the next thing which is asp.net is that i need a global.asax file the global.asax file contains this code

    protected void Application_Start(object sender, EventArgs e)
    {
        sbyte[,] a = new sbyte[100, 100];
        sbyte[,] b = new sbyte[100, 100];
        int count = 0;
        XDocument docA = XDocument.Load("dev.xml");
        XDocument docB = XDocument.Load("guj.xml");
         var devanagriKeys = (from d in docA.Descendants("mapping")
                                              select new {
                                                  Key = d.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = d.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var gujrathiKeys = (from g in docB.Descendants("mapping")
                                              select new {
                                                  Key = g.Descendants("itrans").FirstOrDefault().Value,
                                                  Character = g.Descendants("character").FirstOrDefault().Value
                                              }).ToArray();
        var crossReference = (from d in devanagriKeys
                              join g in gujrathiKeys on d.Key equals g.Key
                              select new {
                                    d.Key,
                                    Devanagri = d.Character,
                                    Gujrathi = g.Character
                                }).ToList();

this code will take characters from devanagri script and gujrathi script and create a list using itrans as one medium for eg अ in itrans is a while અ in gujarati has same itrans a so a list will be created storing अ and અ because they are having same itrans.

here i need to store this list thing in a session var so that i can use it in the default.asp.. i cant figure that one out properly though.

i had told that i will come back to the for loop of default.aspx, so now in this default.aspx i have to search and replace every text node of devanagri to gujarati and vice versa..

i am also confused because i am using a iis server so i am i supposed to copy a开发者_StackOverflowll the project files of asp.net in the wwwroot folder of inetpub of iis.

i will be thankful if anyone guides me to this!! i am sorry for lots of code..i am stuck badly so i really needed help, if any queries regarding this please feel free to post thanks!!!


It sounds like you want to share items in session variables between your ASP page and your .NET .ASPX page. Did I understand that correctly?

Consider this article: How to Share Session State Between Classic ASP and ASP.NET

You'd probably be better off converting your .asp to a .NET .aspx. Consider the maintainability of your solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消