从Adobe Coldfusion 10迁移到Lucee 4.5.1的问题-访问结构
我目前正在尝试将我的站点从Adobe Coldfusion 10迁移到Lucee 4.5.1 我收到以下错误:从Adobe Coldfusion 10迁移到Lucee 4.5.1的问题-访问结构,coldfusion,lucee,Coldfusion,Lucee,我目前正在尝试将我的站点从Adobe Coldfusion 10迁移到Lucee 4.5.1 我收到以下错误:键[TITLE]不存在 我使用的代码是: <cfset variables.title = ress.title.welcome> 除了通过我的代码修复所有引用之外,还有其他方法吗?服务器中是否有显示旧行为的设置 更新#1 属性文件如下所示: # @comment title.welcome=Content here 更新#2 这目前适用于Windows 2008 R2
键[TITLE]不存在
我使用的代码是:
<cfset variables.title = ress.title.welcome>
除了通过我的代码修复所有引用之外,还有其他方法吗?服务器中是否有显示旧行为的设置
更新#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 />
var resourceBundle=structNew();//用于保存资源包的结构
...
部分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>
this.ress=loadResourceBundle();
rbFile=GetDirectoryFromPath(expandpath(“/resources/”)和“mgs.properties”;
...
rB=createObject(“java”、“java.util.PropertyResourceBundle”);
fis=createObject(“java”、“java.io.FileInputStream”);
msgFormat=createObject(“java”、“java.text.MessageFormat”);
locale=createObject(“java”、“java.util.locale”);
var isOk=false;//成功旗
var keys=“”;//var用于保存rb键
var resourceBundle=structNew();//用于保存资源包的结构
var thisKey=“”;
var thismg=“”;
var thisLang=listFirst(arguments.rbLocale,“”);
var thisDir=GetDirectoryFromPath(arguments.rbFile);
var thisFile=getFileFromPath(arguments.rbFile);
var thisrfile=thisDir&listFirst(thisFile,“.”&“&arguments.rbLocale&“&listLast(thisFile,“.”);
if(notfileexists(thisrfile))//请尝试使用该语言
thisRBfile=thisDir&listFirst(thisFile,“.”&“&”&thisLang&“&listLast(thisFile,“.”);
if(notfileexists(thisrfile))//仍然为空?将此rb文件剥回基础rb
thisRBFile=arguments.rbFile;
如果(fileExists(thisrffile)){//最后检查,如果失败,则文件不在其应位于的位置
isOK=真;
fis.init(该文件);
rB.init(fis);
keys=rB.getKeys();
while(keys.hasMoreElements()){
thisKEY=keys.nextElement();
thisMSG=rB.handleGetObject(此键);
if(arguments.markDebug)
resourceBundle[“#thisKEY#”]=“****”&thismg;
其他的
resourceBundle[“#thisKEY#”]=thisMSG;
}
fis.close();
}
...
更新#3
FWIW,我使用了EclipseIDE,使用正则表达式进行了查找替换,并用一个值替换了它
正则表达式:((ress\){1}([a-z\.])+)
值:ress[“$3”]
更新#4
所以,使用Lucee和MySQL,表名是区分大小写的 欢迎使用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
--->
#欢迎光临#
AdobeColdFusion中的行为具有误导性,完全错误<代码>“title.welcome”是一个应该放在结构ress
中的键。相反,该键被分成两个结构,其中键“title”
和“welcome”
相互链接,然后放入结构ress
解决此问题的唯一方法是调整
getResourceBundle
函数。在这里,您需要使用resourceBundle[“#thisKEY#”]
重构行,以便thisKEY
创建一个结构链。属性文件项是什么样子的?@Leigh-See-update#1,这就是它的样子。普通香草会将“title.welcome”视为单个键,所以,正如您所描述的,我不希望它在任何引擎中被当作嵌套结构处理。什么类型的对象是utilObj
以及getResourceBundle()
返回什么类型的对象?@Leigh请参阅更新#2,我已经放置了相关的CFC/方法调用…数据库表名?谢谢,我来看看这个。目前在共享的Windows Server/SQL Server主机上,正在考虑迁移到Linux/Lucee/MySQL。。。我一直在路上遇到这样的事情:)同意。它只能通过利用ACF对包含句点的结构键名的奇怪处理来“工作”。正如我上面所说的,我不希望它以这种方式工作——在任何发动机中。
<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>
<cfset ress = { "title.welcome": "Content here" }>
<cfoutput>#ress.title.welcome#</cfoutput>
<!---
>> outputs "Content here" in Adobe ColdFusion
>> throws an exception in Lucee/Railo
--->