EasyCFM.COM ColdFusion Forums / ASP to CFML / Need this converted to CFM from ASP

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Need this converted to CFM from ASP

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

bubberJ
05-04-2005 @ 9:02 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 8
Joined: Apr 2005

Any help is appriciated. dont know what to do with this one.

<%@ LANGUAGE=VBScript %>
<%

'
' $Name: MQSA_Samples_v2 $
'

advantage_server = "xml.sa.mapquest.com"
clientId = "xxxxxxxx"
password = "xxxxxxxx"
templatePath = "xslt/"
formUrl = Request.ServerVariables("SCRIPT_NAME")

'*******************************************************************************
' No changes are necessary below this line
'*******************************************************************************

Function generate_xml (error_no)
    xml = "<?xml version='1.0' encoding='ISO-8859-1'?>" & vbNewLine & "<advantage>"

    If error_no = 0 Then
         xml = xml & "<locMap>"
    Else
         xml = xml & "<error><code>" & error_no & "</code>"
    End If

    Dim orig_node_test, dest_node_test, loc_node_test, matches
    Set orig_node_test = New Regexp
    Set dest_node_test = New Regexp
    Set loc_node_test = New Regexp
    orig_node_test.Pattern = "^orig(.+)"
    dest_node_test.Pattern = "^dest(.+)"
    loc_node_test.Pattern = "^loc_(.+)"
    origin_node = ""
    dest_node = ""
    loc_node = ""
    param_node = ""
    For Each key In Params
        param_node = param_node & "<" & key & ">" & Params(key) & "</" & key & ">"
        Set matches = orig_node_test.Execute(key)
        If matches.Count > 0 Then
            node = Right(matches(0).Value, Len(matches(0).Value) - 4)
            origin_node = origin_node & "<" & node & ">" & Params(key) & "</" & node & ">"
        Else
            Set matches = dest_node_test.Execute(key)
            If matches.Count > 0 Then
                node = Right(matches(0).Value, Len(matches(0).Value) - 4)
                dest_node = dest_node & "<" & node & ">" & Params(key) & "</" & node & ">"
            Else
                Set matches = loc_node_test.Execute(key)
                If matches.Count > 0 Then
                    node = Right(matches(0).Value, Len(matches(0).Value) - 4)
                    loc_node = loc_node & "<" & node & ">" & Params(key) & "</" & node & ">"
                Else
                    Select Case key
                        Case "address", "city", "stateProvince", "postalCode", "country"
                            loc_node = loc_node & "<" & key & ">" & Params(key) & "</" & key & ">"
                    End Select
                End If ' loc
            End If ' dest
        End If ' orig
    Next
    input = ""
    If Len(origin_node) > 0 Then
        input = input & "<origin count='1'><location>" & origin_node & "</location></origin>"
    End If
    If Len(dest_node) > 0 Then
        input = input & "<destination count='1'><location>" & dest_node & "</location></destination>"
    End If
    If Len(loc_node) > 0 Then
        input = input & "<locations count='1'><location>" & loc_node & "</location></locations>"
    End If
    xml = xml & "<parameters>" & param_node & "</parameters>"
    xml = xml & "<input>" & input & "</input>"
    If error_no = 0 Then
         xml = xml & "</locMap>"
    Else
         xml = xml & "</error>"
    End If
     xml = xml & "</advantage>" & vbNewLine
    generate_xml = xml
End Function

If clientId = "" Or advantage_server = "" Then
    Response.Write "Error: the 'clientId' and 'advantage_server' variables must be set at the top of this file."
    Response.End
End If

'
' What kinda of input are we looking at?
'
Dim Params
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Set Params = Request.Form
Else
    Set Params = Request.QueryString
End If

'
' Set some defaults
'
transaction = "locmap"
template = "map.xsl"

'
' Generate the url to the Advantage server
'
urlParams = ""
url = Params("url")

If Len(url) = 0 Then
    If len(trim(Params)) > 0 _
       and Params("transaction") <> "poimap" _
       and Params("identifyicon")  = "" Then
       If (Params("template") = "route" ) or (Params("template") = "route_search")  then
          If (    (   (Params("origstateProvince") = "" and Params("&origstateProvince") = "")_
                       or (Params("origcity") = "" and Params("&origcity") = "")) _
                    and ( Params("origpostalCode") = "" and Params("&origpostalCode") = "")_
                    and Params("origrecordId")   = "" _
                    and Params("origlatitude")   = "" _
                    and Params("origlongitude")  = ""  ) then
                    error=9000
          End If
          If (    (   (Params("deststateProvince") = "" and Params("&deststateProvince") = "") _
                        or (Params("destcity") = "" and Params("&destcity") = "")) _
                     and (Params("destpostalCode") = "" and Params("&destpostalCode") = "")_
                     and Params("destrecordId")   = "" _
                     and Params("destlatitude")   = "" _
                     and Params("destlongitude")  = ""  ) then
                     error=9000
          End If
       Else
          If (    (   (Params("stateProvince") = "" and Params("&stateProvince") = "") _
                        or (Params("city") = "" and Params("&city") = "")) _
                     and ( Params("postalCode") = "" and Params("&postalCode") = "") _
                     and Params("recordId")   = "" _
                     and Params("latitude")   = "" _
                     and Params("longitude")  = ""  ) then
                     error=9000
          End If
       End If
    End If

    For Each key In Params
            Select Case key
                Case "template"
                  If Params(key)= "" then
                    template ="map.xsl"
                  else
                    template = Params(key) & ".xsl"
                  end if
                Case "transaction"
                    transaction = Params(key)
                Case Else
                    key_val = Server.URLEncode(Params(key))
                    if Lcase(key) = "clientid" then
                        key_val = clientId
                    end if
                    if (left(key,1) = "&") then
                        key1 = (mid(key,2,len(key)))
                        urlParams = urlParams & "&" & Server.URLEncode(key1) & "=" & key_val
                    else
                        urlParams = urlParams & "&" & Server.URLEncode(key) & "=" & key_val
                    end if
            End Select
    Next
    url = "http://" & advantage_server & "/?clientId=" & clientId & "&transaction=" & transaction & urlParams
Else
    urlParams=1
    template = Params("template")
    If Len(template) > 0 Then
       template = Params("template") & ".xsl"
    End if
    url = "http://" & advantage_server & "/?clientId=" & clientId & "&" & url
End If

'
' if we don't have enough info to call the Advantage server
' or if there's an, error we'll generate a basic XML doc to apply a template to
' otherwise we'll get the xml from the Advantaage server
'
Dim doc
Set doc = server.CreateObject("MSXML2.FreeThreadedDOMDocument")
doc.async = False
doc.validateOnParse = False
doc.resolveExternals = False

If Len(urlParams) = 0 Then
    doc.loadXML(generate_xml(0)) ' no error
Else
    If Len(password) > 0 Then
        url = url & "&passwd=" & password
    End if
    Dim xmlhttp
    Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
    ' Connect to sever
    xmlhttp.Open "GET", url, false
    on error resume next
    xmlhttp.Send
    If (error <> 0 ) Then
        doc.loadXML(generate_xml(9001)) ' 9001 = failed to get XML from server
    Else
      doc.setProperty "ServerHTTPRequest", True
      If doc.loadxml(xmlhttp.ResponseText) then
        strBuffer=xmlhttp.ResponseText
        strlen = Len(strBuffer)

        'Response back from visiting URL
        ContentLength = xmlhttp.getResponseHeader("Content-Length")
        Set xmlhttp = Nothing

        If (error <> 0) Then
          Set doc = server.CreateObject("MSXML2.FreeThreadedDOMDocument")
          doc.async = False
          doc.validateOnParse = False
          doc.resolveExternals = False
          doc.loadXML(generate_xml(9000)) ' 9000 = incomplete input
        End If

        If (trim(strlen) <> trim(ContentLength)) Then
          Set doc = server.CreateObject("MSXML2.FreeThreadedDOMDocument")
          doc.async = False
          doc.validateOnParse = False
          doc.resolveExternals = False
          doc.loadXML(generate_xml(9001)) ' 9001 = failed to get XML from server
        End If

      Else
        If (doc.parseError.errorCode <> 0) Then
          Set doc = server.CreateObject("MSXML2.FreeThreadedDOMDocument")
          doc.async = False
          doc.validateOnParse = False
          doc.resolveExternals = False
          doc.loadXML(generate_xml(9001)) ' 9001 = failed to get XML from server
        End If
      End If
    End If
End if

'
' parse the xsl and transform the xml with it
'
Dim objXSLDoc
Set objXSLDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXSLDoc.async = False
objXSLDoc.validateOnParse = False
objXSLDoc.resolveExternals = False
objXSLDoc.load Server.MapPath(templatePath & template)

If (objXSLDoc.parseError.errorCode <> 0) Then
  Response.Write objXSLDoc.parseError.reason
  Response.end
End If

Dim objXSLTemplate
Set objXSLTemplate = Server.CreateObject("MSXML2.XSLTemplate")
Set objXSLTemplate.stylesheet = objXSLDoc

Dim xslProcessor
Set xslProcessor = objXSLTemplate.createProcessor()
xslProcessor.AddParameter "formUrl", formUrl
xslProcessor.input = doc
xslProcessor.output = Response
xslProcessor.transform

'
' clean up
'
Set doc = Nothing
Set objXSLDoc = Nothing
Set xslProcessor = Nothing
Set objXSLTemplate = Nothing
%>

e996sh
05-04-2005 @ 2:55 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 49
Joined: Mar 2004

Don't know anything about asp but it looks like it is just parsing an xml page form mapquest.  Take a look at http://tutorial208.easycfm.com/.




Website Designed and Developed by Pablo Varando.