Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
HI,

I have the following script code in coldfusion (CFM), can anyone helpme to change the below script code to C# or java script.

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?tool=CogentMedicineWebSite&email=cogentmedicine@acr.org&dbfrom=pubmed&id=1[^]

The above link will gives you XML content.

The Function ReadLinkoutReply(strInput) will pass the xml file content as a parameter.

Need to separate the Publishers,Libraries,Aggregators in that xml.

please help me.....
HTML
<cfscript>
function MunchTag(strTag, objInput)
{
    var emark = 0;
    var smark = 0;
    var tagLen = 0;
    if(objInput.offset eq 0)
    {
        smark = Find("<" & strTag & ">", objInput.data);
        emark = Find("</" & strTag & ">", objInput.data);
    }
    else
    {
        smark = Find("<" & strTag & ">", objInput.data, objInput.offset);
        emark = Find("</" & strTag & ">", objInput.data, objInput.offset);
    }
    if((smark eq 0) or (emark eq 0))
    {
        objInput.finished = true;
        return "";
    }
    tagLen = Len(strTag);
    objInput.offset = emark + tagLen + 3;
    smark = smark + tagLen + 2; // move past the opening tag
    return Mid(objInput.data, smark, emark-smark);
}
function NewReply(strReply)
{
    var inStream = StructNew();
    inStream.data = strReply;
    inStream.offset = 0;
    inStream.finished = false;
    return inStream;
}
function MunchOneTag(strTag, strInput)
{
    var inStream = NewReply(strInput);
    return MunchTag(strTag, inStream);
}
function ReadLink(objInput)
{
    var bkmk = 0;
    var str = "";
    var strTag = "";
    var objTag = StructNew(); // this will be thrown away (how else to you initialize this?)
    var link = StructNew();

    link.isValid = false;
    strTag = MunchTag("ObjUrl", objInput);
    If(objInput.finished)
    {
        return link;
    }

    //create a separate stream object for the link tag
    //this prevents us from running past the end and into the next
    objTag = NewReply(strTag);

    str = MunchTag("Url", objTag);
    if(objInput.finished)
    {
        return link;
    }

    //convert relative links
    if(Mid(str, 1, 1) EQ "/")
    {
        str = "http://www.ncbi.nlm.nih.gov" & str;
    }
    link.url = str;

    // minimum valid tag consists of a link
    link.isValid = true;
    link.subjects = ArrayNew(1);
    link.attributes = ArrayNew(1);

    bkmk = objTag.offset;
    str = MunchTag("LinkName", objTag);
    if(objTag.finished)
    {
        objTag.offset = bkmk;
        objTag.finished = false;
        link.name = "No Name";
        link.useName = false;
    }
    else
    {
        link.name = str;
        link.useName = true;
    }

    bkmk = objTag.offset;

    for(str=MunchTag("SubjectType", objTag);objTag.finished EQ false; str=MunchTag("SubjectType", objTag))
    {
        ArrayAppend(link.subjects, str);
    }

    objTag.offset = bkmk;
    objTag.finished = false;
    for(str=MunchTag("Attribute", objTag); objTag.finished EQ false; str=MunchTag("Attribute", objTag))
    {
        ArrayAppend(link.attributes, str);
    }

    objTag.offset = bkmk;
    objTag.finished = false;
    str = MunchTag("Provider", objTag);
    link.provider = ReadProvider(NewReply(str));
    return link;
}
function ReadProvider(objProv)
{
    var str = "";
    var rv = StructNew();

    str = MunchTag("Name", objProv);
    rv.name = str;

    str = MunchTag("Id", objProv);
    rv.id = str;

    str = MunchTag("Url", objProv);
    rv.url = str;

    str = MunchTag("IconUrl", objProv);
    if(objProv.finished)
    {
        rv.icon = "none";
        rv.useIcon = false;
    }
    else
    {
        if(Mid(str, 1, 6) EQ "DB__ft")
        {
            // not sure what this is about, but there are many IconURLs that refer to
            // gif files with no domain or path, and all start with "DB__ft"
            rv.icon = "none";
            rv.useIcon = false;
        }
        else
        {
            rv.icon = str;
            rv.useIcon = true;
        }
    }
    return rv;


}
function ReadLinkoutReply(strInput)
{
    var strFullSet = "";
    var loURLs = StructNew();
    var urlList = StructNew();
    var thisLink = StructNew();
    var fullSet = NewReply(strInput);

    loURLs.links = ArrayNew(1);
    loURLs.count = 0;

    strFullSet = MunchTag("IdUrlSet", fullSet);
    if(fullSet.finished)
    {
        // error - can't find tag or ended prematurely
        loURLs.error = True;
        // to do: look for error description
        return loURLs;
    }

    loURLs.error = False;
    urlList = NewReply(strFullSet);
    // 250 link limit is simply to guarantee script termination
    // this could be raised or even eliminated - if you're feeling lucky
    for(i=1; i LT 250; i = i + 1)
    {
        thisLink = ReadLink(urlList);
        if(thisLink.isValid)
        {
            loURLs.links[i] = thisLink;
            loURLs.count = i;
        }
        else
        {
            break;
        }
    }
    // PDK: code in transition.  We still collect all subjects, but for now
    // we're only going to display publishers, libraries, and aggregators
    loURLs.subjects = "";
    loURLs.publishers = ArrayNew(1);
    loURLs.libraries = ArrayNew(1);
    loURLs.aggregators = ArrayNew(1);

    for(i=1; i LTE ArrayLen(loURLs.links); i = i + 1)
    {
        for(j=1; j LTE ArrayLen(loURLs.links[i].subjects); j=j+1)
        {
            if(ListFind(loURLs.subjects, loURLs.links[i].subjects[j]) EQ 0)
            {
                loURLs.subjects = ListAppend(loURLs.subjects, loURLs.links[i].subjects[j]);
            }
            if(loURLs.links[i].subjects[j] EQ "publishers/providers")
            {
                ArrayAppend(loURLs.publishers, loURLs.links[i]);
            }
            else if(loURLs.links[i].subjects[j] EQ "libraries")
            {
                ArrayAppend(loURLs.libraries, loURLs.links[i]);
            }
            else if(loURLs.links[i].subjects[j] EQ "aggregators")
            {
                ArrayAppend(loURLs.aggregators, loURLs.links[i]);
            }
        }
    }

    loURLs.subjects = ListSort(loURLs.subjects, 'text');

    return loURLs;
}
</cfscript>


Thanks in Advance....
Posted
Updated 11-Mar-20 5:15am
v3
Comments
[no name] 3-Sep-13 8:45am    
You would need to go to a site like www.vworker.com so that you could find someone to hire to do this work for you.
jkirkerx 3-Sep-13 18:34pm    
I could see if you were struck on a line or 2, but to convert the whole thing!, I don't think so.

ASP.net is a strict managed language, and requires declaring variables as Integer, Decimal, String, etc, at least the primitive ones. There is no magic conversion program, It would have to be converted by eye, brain and hand.

I wonder if this is one of those freelancer jobs that you were awarded.

 
Share this answer
 
Refer this link

http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:573[^]

It states that:
Quote:

One should not try this because

1. When converting from one language to another you have to not only
understand the "what" of the code but also the "why". There are some
things that a program must do that one language does that another does
not - it is the job of the programmer to work around those
limitations.

2. Code that writes code is a good and right thing in most cases - but
it is also limited to the knowledge of the programmer that wrote the
original code (see #1). If you get something that will convert CFML
to C# you better be sending in CFC's and not CFML in most cases as, if
memory serves, C# makes extensive use of OOP concepts and class-based
programming.

3. Any time you look into porting an application between two languages
you need to take the time to examine the app and see why you are
planning on porting it and what upgrades or features you may want to
plan in.

Regards..:)
 
Share this answer
 
Using the xml files,fetched the lists based on the tagnames and makes it as a list and displayed without using the same functions to be converted in C# or java script code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900