
<%
Class Languages
	Private w_objXML,w_xml
	Private w_sysdir,w_languageset,w_langpackpath,w_packname
	Private w_showerr
	Private w_nodename,w_nodeposition
	
	Private Sub Class_Initialize
	    	Set w_objXML =Server.CreateObject("Microsoft.XMLDOM")
		w_sysdir=Web_Get_RootDir(web_c_setupfolder)
		w_languageset="CN"
	End Sub

	Private Sub SetLangPackName()
		Select Case UCASE(w_languageset)
			case "CN":
				w_packname="chinese.xml"
			case "ENG":
				w_packname="english.xml"
			case "FRANCH":
				w_packname="franch.xml"
			case "JAPAN":
				w_packname="japanese.xml"
			case "GER":
				w_packname="german.xml"
		End Select
	End Sub

	Private Sub SetLangPackPath(byval val)
		call SetLangPackName()
		Select Case val
			case "0":
				w_langpackpath=w_sysdir&"languages/"&w_packname
			case "1":
				w_langpackpath=w_sysdir&"template/web_skin1/languages/"&w_packname
		End Select
	End Sub

	Private Function w_splitpara(byval val)
		w_item=split(val,"_")
		if ubound(w_item)<>4 then 
			w_showerr="参数传递有错" 
			exit function 
		end if
		if isnumeric(w_item(3))=false or isnumeric(w_item(1))=false then 
			w_showerr="节点位置须为整数" 
			exit function
		end if
		call SetLangPackPath(w_item(1))
		w_nodename=trim(w_item(2))
		w_nodeposition=w_item(3)
	End Function

 	Private Function w_Get_FileStatus(byval val) 
	  	Set fso = CreateObject("Scripting.FileSystemObject")
  		If (fso.FileExists(val)) Then
    			msg = true
  		Else
    			msg = false
  		End If
  		w_Get_FileStatus = msg
		set fso=nothing
	End Function

	public Function W_ProcessXml(byval val)
		call w_splitpara(val)
		if w_showerr<>"" then
			W_ProcessXml=w_showerr
			exit function
		end if 

		xmlSourceFile = Server.MapPath(w_langpackpath)
		if w_get_filestatus(xmlSourceFile)=false then 
			w_ProcessXml="<font color=red>"&w_packname&"</font> 语言包文件不存在"
			exit function
		else
	    		
			w_objXML.load(xmlSourceFile)  						'把XML文件读入内存
    			Set w_xml=w_objXML.documentElement.selectSingleNode(w_nodename)  	'选取节点
			w_nodeposition_1=split(w_nodeposition,",")
			if clng(w_nodeposition_1(0))>w_xml.childNodes.length then
				W_ProcessXml="xml语言包运行时错误，参数值超过XML节点最大值"
				exit function
			end if 
			select case ubound(w_nodeposition_1)
				case 0:
					W_ProcessXml=w_xml.childNodes.item(w_nodeposition_1(0)).text 
				case 1:
					W_ProcessXml=w_xml.childNodes.item(w_nodeposition_1(0)).childnodes(w_nodeposition_1(1)).text 
			end select 
		end if 
	End Function

	public Function W_Get_Node(itemcontent)
		W_Get_Node=W_ProcessXml(itemcontent)
	End Function

	Private Sub Class_Terminate()
		If IsObject(w_xml) Then 
			Set w_xml=Nothing
		End If

		If IsObject(w_objXML) Then 
			Set w_objXML=Nothing
		End If		
	End Sub
End Class
%>