Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keys 配置文件的 reserved 属性 #1156

Open
DigitalPlatform opened this issue Aug 31, 2022 · 0 comments
Open

keys 配置文件的 reserved 属性 #1156

DigitalPlatform opened this issue Aug 31, 2022 · 0 comments

Comments

@DigitalPlatform
Copy link
Owner

DigitalPlatform commented Aug 31, 2022

假如一个数据库的 keys 配置文件被系统管理员定制修改过,然而又用了(内务的系统管理窗“数据库”属性页的)刷新数据库定义功能,会自动把系统管理员定制过的 keys 配置文件内容覆盖为安装包内相应 keys 模板文件的内容。这样系统管理员定制过的内容就丢失了。

为了避免出现这种问题,保护系统管理员定制的内容不被刷新数据库定义功能破坏,最新版 dp2library 允许我们在 keys 配置文件中,为需要保护的(根下一级)元素添加 reserved="true" 属性,这样当刷新数据库定义的时候,这些元素就不会被覆盖。

一般主要会保护 key table script 三种元素。

注意 script 元素在旧版本中是不允许重复出现的,在最新版中允许重复出现。重复一般是为了给第二个 script 元素添加 reserved 属性,把它保护起来,而第一个 script 元素(它没有被保护)则由刷新功能支配。

下面举例说明用法。假设我们为中文图书库的 keys 配置文件末尾(root 元素以内)增加如下片段:

  <key reserved="true">
    <xpath nstable="">//marc:record/marc:datafield[@tag='991']/marc:subfield[@code='a']</xpath>
    <from>991</from>
    <table ref="991" />
  </key>
  <table name="991" id="200" type="wkey" reserved="true">
    <convert>
      <string style="#test,upper" />
    </convert>
    <convertquery>
      <string style="upper" />
    </convertquery>
    <caption lang="zh-CN">991</caption>
    <caption lang="en">991</caption>
  </table>
  <script reserved="true"><![CDATA[

partial class MyKeysHost
{
    public void test()
    {
       this.ResultString = this.InputString + "append";
    }
}

]]></script>

然后把第一个 script 元素内的 MyKeysHost 定义行修改为:

public partial class MyKeysHost : KeysHost

(也就是说为 class 前增加了一个 partial 关键字)

最后,为实验考虑,需手动把安装包的 templates 目录中相应类型的 keys 模板文件内容也做修改,为第一个 script 元素内的 MyKeysHost 定义行增加 partial 关键字。

这样,当我们刷新这个数据库的定义的时候,上述带有 reserved 属性的元素就会得到保留。

由于保留的这个 table 元素中用到了脚本函数 #test,这才引出了第二个 script 元素存在的必要性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant