coldfusion - 从 Adob​​e Coldfusion 10 迁移到 Lucee 4.5.1 的问题 - 访问结构

标签 coldfusion lucee

我目前正在尝试将我的网站从 Adob​​e Coldfusion 10 迁移到 Lucee 4.5.1。

我收到以下错误:key [TITLE] 不存在

我使用的代码是:

<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

这目前适用于 Windows 2008 R2 上的 CF10 Developer 和我的共享主机(也是 Windows Server)上的 CF10。我也会承认这是旧代码:)

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,表名是区分大小写的!?

最佳答案

欢迎使用 Adob​​e ColdFusion,语法错误不会立即受到惩罚。

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

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

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

--->

Adobe ColdFusion 中的行为具有误导性和明显错误。 "title.welcome" 是应该放在结构 ress 中的键。取而代之的是,键被分成两个结构,键为 "title""welcome",彼此链接,然后放入结构 ress.

解决此问题的唯一机会是调整 getResourceBundle 函数。在这里,您需要使用 resourceBundle["#thisKEY#"] 重构这些行,以便 thisKEY 创建一个结构链。

关于coldfusion - 从 Adob​​e Coldfusion 10 迁移到 Lucee 4.5.1 的问题 - 访问结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33588213/

相关文章:

linux - 在 Linux 上使用 Coldfusion 写入 USB 闪存驱动器

coldfusion - cfhttp 无法在 lucee 上运行

jquery - 使 .cfm 模板只能通过 ajax 调用访问?

coldfusion - Db2 JDBC 驱动程序加密方法或身份验证方法

coldfusion - 从查询查询中选择行范围

java - Java/ColdFusion 和 Lucee 之间的 identityHashCode 区别

coldfusion - Lucee Document is empty 错误

java - 在 Lucee 上安装 Cassandra Java 驱动程序

pdf - 在另一个ColdFusion报告模板中包含ColdFusion报告模板

mysql - 在 MySQL 中使用 OR 和 HAVING 与使用 AND