欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

检测函数 asp class

程序员文章站 2022-04-14 20:45:10
复制代码 代码如下:<% dim cmd set cmd = new cls_command class ...
复制代码 代码如下:

<%
dim cmd
set cmd = new cls_command
class cls_command
    private re

    public function ispositiveinteger(value)
        set re = new regexp
        re.pattern = "^[1-9][\d]*$"
        re.ignorecase = true
        re.global = true
        ispositiveinteger = re.test(value)
        set re = nothing
    end function

    public function isdigit(vstring)
        if vstring = "" then isdigit = false : exit function
        set re = new regexp
        re.pattern = "^[a-z]+$"
        re.global = true
        re.ignorecase = true
        re.multiline = true
        isdigit = re.test(vstring)
        set re = nothing
    end function

    public function isalpha(vstring)
        if vstring = "" then isalpha = false : exit function
        set re = new regexp
        re.pattern = "^[\d]+$"
        re.global = true
        re.ignorecase = true
        re.multiline = true
        isalpha = re.test(vstring)
        set re = nothing
    end function

    public function isalphadigit(vstring)
        if vstring = "" then isalphadigit = false : exit function
        set re = new regexp
        re.pattern = "^[a-za-z\d]+$"
        re.global = true
        re.ignorecase = true
        re.multiline = true
        isalphadigit = re.test(vstring)
        set re = nothing
    end function

    dim templatecontent,templatedebug
    public sub loadtemplate(templatename)
        on error resume next
        dim templateobject,templatefile
        set templateobject=server.createobject("scripting.filesystemobject")
        set templatefile=templateobject.opentextfile(server.mappath(templatename))
        if err.number <> 0 then
            err.clear
            set templatefile=nothing
            set templateobject=nothing
            templatedebug=1
        end if
        templatecontent=templatefile.readall
        templatefile.close
        set templatefile=nothing
        set templateobject=nothing
    end sub

    dim htmlcontent,creatdebug
    public sub buildfile(catalogue, htmlname)
        on error resume next
        if not checkfolder(catalogue) then
            creatdebug=1
            exit sub
        end if
        dim creatobject,creatfile
        set creatobject=server.createobject("scripting.filesystemobject")
        set creatfile=creatobject.createtextfile(server.mappath(catalogue & htmlname),true,false)
        if err.number <> 0 then
            set creatfile=nothing
            set creatobject=nothing
            err.clear
            creatdebug=1
            exit sub
        end if
        creatfile.write(htmlcontent)
        creatfile.close
        set creatfile=nothing
        set creatobject=nothing
    end sub

    private function checkfolder(byval localpath)
        on error resume next
        dim fileobject
        dim patharr,path_level,pathtmp,cpath
        localpath = replace(localpath,"\","/") 
        set fileobject=server.createobject("scripting.filesystemobject") 
        patharr = split(localpath,"/") 
        path_level = ubound(patharr)
        dim i
        for i = 0 to path_level 
            if i = 0 then 
                pathtmp = patharr(0) & "/"
            else
                pathtmp = pathtmp & patharr(i) & "/"
            end if
            cpath = left(pathtmp,len(pathtmp)-1)
            if not fileobject.folderexists(server.mappath(cpath)) then fileobject.createfolder(server.mappath(cpath))
        next
        set fileobject=nothing
        if err.number<>0 then
            err.clear
            checkfolder = false
        else
            checkfolder = true
        end if
    end function

    public function writecache(appname, value)
        application.lock
        application(appname) = value
        application.unlock
    end function

    public function clearcache(appname)
        application.lock
        application.contents.remove(appname)
        application.unlock
    end function

    public sub outputjavainfo(message)
        response.expires = 0
        response.expiresabsolute = now() - 1
        response.addheader "pragma","no-cache"
        response.addheader "cache-control","private"
        response.cachecontrol = "no-cache"
        response.contenttype = "application/x-javascript"
        response.write "document.getelementbyid(""updateinfo"").innerhtml = """ & message & """;"
        response.end
    end sub

    public sub outputinterhtml(message, showtype)
        response.write message
        if showtype = 1 then
            response.flush
        else
            response.end
        end if
    end sub
end class
%>