2015-11-07 94 views
3

我目前正在試圖從Adobe ColdFusion,請10遷移我的網站Lucee 4.5.1。遷移問題從Adobe ColdFusion的10 Lucee 4.5.1 - 訪問結構

,我發現了以下錯誤:key [TITLE] doesn't exist

我使用的代碼是:

<cfset variables.title = ress.title.welcome> 

,我需要解決這個問題的代碼似乎是:

<cfset variables.title = ress["title.welcome"]> 

我使用JavaRB和加載一個屬性文件(onRequestStart() )並將其設置爲變量ress。

<cfset ress = utilObj.getResourceBundle()> 

除了通過我的代碼來修復所有引用嗎?服務器中是否存在顯示舊行爲的設置?

更新#1

屬性文件看起來是這樣的:

# @comment 
title.welcome=Content here 

更新#2

這當前適用於CF10開發者在Windows 2008 R2和CF10我共享主機也是Windows Server。我也承認這是舊的代碼:)

JavaRB返回從文件的內容的結構:

var resourceBundle=structNew(); // structure to hold resource bundle 
... 
<cfreturn resourceBundle /> 

部分CFC和方法調用...

<cfcomponent name="utils" output="false"> 

    <cfset this.ress = ""> 

    <cffunction name="init"> 
     <cfscript> 
      this.ress = loadResourceBundle(); 
     </cfscript> 
     <cfreturn this> 
    </cffunction> 

    <cffunction name="loadResourceBundle" access="public" output="true"> 
     <!--- Get javaRB ---> 
     <cfinvoke component="#application.cfcPath#.javaRB" method="init" returnvariable="rb"> 
     </cfinvoke> 
     <cfscript> 
      rbFile = GetDirectoryFromPath(expandpath("/resources/")) & "mgs.properties"; 
     </cfscript> 
     <cfreturn rb.getResourceBundle("#rbFile#")> 
    </cffunction> 
    ... 
</cfcomponent> 


<cfcomponent displayname="javaRB" output="no"> 
    <cffunction access="public" name="init" output="No"> 
     <cfscript> 
      rB=createObject("java", "java.util.PropertyResourceBundle"); 
      fis=createObject("java", "java.io.FileInputStream"); 
      msgFormat=createObject("java", "java.text.MessageFormat"); 
      locale=createObject("java","java.util.Locale"); 
     </cfscript> 

     <cfreturn this> 
    </cffunction> 

    <cffunction access="public" name="getResourceBundle" output="No" returntype="struct" hint="reads and parses java resource bundle per locale"> 
     <cfargument name="rbFile" required="Yes" type="string" /> 
     <cfargument name="rbLocale" required="No" type="string" default="en_US" /> 
     <cfargument name="markDebug" required="No" type="boolean" default="false" /> 
     <cfscript> 
      var isOk=false; // success flag 
      var keys=""; // var to hold rb keys 
      var resourceBundle=structNew(); // structure to hold resource bundle 
      var thisKey=""; 
      var thisMSG=""; 
      var thisLang=listFirst(arguments.rbLocale,"_"); 
      var thisDir=GetDirectoryFromPath(arguments.rbFile); 
      var thisFile=getFileFromPath(arguments.rbFile); 
      var thisRBfile=thisDir & listFirst(thisFile,".") & "_"& arguments.rbLocale & "." & listLast(thisFile,"."); 
      if (NOT fileExists(thisRBfile)) //try just the language 
       thisRBfile=thisDir & listFirst(thisFile,".") & "_"& thisLang & "." & listLast(thisFile,"."); 
      if (NOT fileExists(thisRBfile))// still nothing? strip thisRBfile back to base rb 
       thisRBFile=arguments.rbFile; 
      if (fileExists(thisRBFile)) { // final check, if this fails the file is not where it should be 
       isOK=true; 
       fis.init(thisRBFile); 
       rB.init(fis); 
       keys=rB.getKeys(); 
       while (keys.hasMoreElements()) { 
        thisKEY=keys.nextElement(); 
        thisMSG=rB.handleGetObject(thisKey); 
        if (arguments.markDebug) 
         resourceBundle["#thisKEY#"]="****"&thisMSG; 
        else 
         resourceBundle["#thisKEY#"]=thisMSG; 
        } 
       fis.close(); 
       } 
     </cfscript> 
     <cfif isOK> 
      <cfreturn resourceBundle /> 
     <cfelse> 
      <cfthrow message="#e.message#" detail="#e.detail#" type="#e.type#" /> 
     </cfif> 
    </cffunction> 
    ... 
</cfcomponent> 

更新#3

FWIW,我使用了Eclipse IDE,並使用正則表達式進行查找替換,並將其替換爲一個值...

正則表達式:((ress\.){1}(([a-z\.])+))

值:ress["$3"]

更新#4

因此,使用Lucee和MySQL,表名是區分大小寫的!?

+0

屬性文件條目是什麼樣的? – Leigh

+0

@Leigh查看更新#1,這就是它的樣子。 – TekiusFanatikus

+0

一個普通的香草[ResourceBundle](https://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html)會把「title.welcome」當作一個單獨的鍵,所以我不會如你所描述的,在任何引擎中都期望它被作爲嵌套結構來處理。 'utilObj'是什麼類型的對象,'getResourceBundle()'返回什麼類型的對象? – Leigh

回答

4

歡迎Adobe ColdFusion,請,其中句法錯誤是沒有立即處罰。

<cfset ress = { "title.welcome": "Content here" }> 

<cfoutput>#ress.title.welcome#</cfoutput> 
<!--- 

    >> outputs "Content here" in Adobe ColdFusion 
    >> throws an exception in Lucee/Railo 

---> 

Adob​​e ColdFusion中的行爲具有誤導性和明顯的錯誤。 "title.welcome"是應該被放在結構ress的關鍵。相反,關鍵是分成兩個結構的鑰匙"title""welcome",聯繫到對方,然後放入結構ress

解決此問題的唯一方法是調整getResourceBundle函數。在這裏,您需要用resourceBundle["#thisKEY#"]重構行,以便thisKEY創建一個結構鏈。

+0

謝謝,我會看看這個。目前在共享的Windows Server/SQL Server主機上,並考慮遷移到Linux/Lucee/MySQL ......我一直在討論這些事情:) – TekiusFanatikus

+1

同意。它只是通過利用ACF對含有句點的結構鍵名的奇怪處理而「起作用」。正如我上面所說的那樣,我不會指望它以這種方式工作 - 在任何引擎中。 – Leigh