2015-11-07 40 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