创建新的格式化程序¶
目标¶
监督槽式成型机机械
了解处理者、匹配者的概念
创建小型格式化程序
行使¶
添加一个新的格式化程序,该格式化程序在基本布局中显示元数据的所有文本信息。
更新上一个格式化程序以显示文本字段的标签。
使用格式化程序模板系统呈现处理程序的视图
向格式化程序视图添加样式。
创建用于呈现元素的树
使用iso元素的翻译
使用默认树样式
使用所有默认视图格式化程序元素
自定义默认格式化程序视图
重载处理程序方法
更正¶
去https://github.com/fgravin/core-geonetwork/commits/foss4g
一。创建新的格式化程序-在/schemas/iso19139/src/main/plugin/iso19139/formatter中创建名为“foss4g”的新文件夹-在此新文件夹中创建新的groovy文件-文本信息存储在 gco:CharacterString
handlers.add 'gco:CharacterString', {el -> "<div>${el.text()}</div>"}
添加匹配器并与一起玩
name
和text
性质。
handlers.add select: {el -> !el.'gco:CharacterString'.text().isEmpty()}, {el -> "<div><b>${el.name()}</b> - ${el.text()}</div>" }
使用
handlers.fileResult
功能
view.groovy
handlers.add select: {el -> !el.'gco:CharacterString'.text().isEmpty()}, {el -> handlers.fileResult('foss4g/elem.html', [name: el.name(), text: el.text()]) }
elem.html
<dl> <dt>{{name}}</dt> <dd>{{text}}</dd> </dl>
在wro4j检查过的文件夹中添加一个自定义的less文件并将其链接到格式化程序
formatter.less
dt { width: 230px; font-weight: normal; font-style: italic; color: #555555; clear: none; padding-left: 15px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; float: left; } dd { margin-left: 250px; border-left: 1px solid #999999; padding-left: 1em; background: #eeeeee; }
view.groovy
handlers.start { '''<link rel="stylesheet" href="../../static/formatter.css"/> <div class="container">''' } handlers.end { '</div>' } handlers.add select: {el -> !el.'gco:CharacterString'.text().isEmpty()}, {el -> handlers.fileResult('foss4g/elem.html', [name: el.name(), text: el.text()]) }
使用
fmt-repeat-only-children
在模板和prent()
功能。
view.groovy
... handlers.add select: {el -> !el.'gco:CharacterString'.text().isEmpty()}, group: true, {els -> def elements = els.collect {el -> [name: el.name(), text: el.text()] } handlers.fileResult('foss4g/elem.html', [elements: elements, parent: els[0].parent().name()]) }
elem.html
<dl> <h3>{{parent}}</h3> <div fmt-repeat="el in elements" fmt-repeat-only-children="true"> <dt>{{el.name}}</dt> <dd>{{el.text}}</dd> </div> </dl>
见
nodeLabel
功能
view.groovy
... handlers.add select: {el -> !el.'gco:CharacterString'.text().isEmpty()}, group: true, {els -> def elements = els.collect {el -> [name: f.nodeLabel(el), text: el.text()] } handlers.fileResult('foss4g/elem.html', [elements: elements, parent: f.nodeLabel(els[0].parent())]) }
添加
gn-metadata-view
类来更新容器的处理程序。
view.groovy
handlers.start { '''<div class="gn-metadata-view container">''' } handlers.end { '</div>' } def isoHandlers = new iso19139.Handlers(handlers, f, env) handlers.add select: isoHandlers.matchers.isTextEl, isoHandlers.isoTextEl handlers.add name: 'Container Elements', select: isoHandlers.matchers.isContainerEl, priority: -1, isoHandlers.commonHandlers.entryEl(f.&nodeLabel, isoHandlers.addPackageViewClass) isoHandlers.addExtentHandlers()
见
SummaryFactory
班级。
view.groovy
import iso19139.SummaryFactory def isoHandlers = new iso19139.Handlers(handlers, f, env) SummaryFactory.summaryHandler({it.parent() is it.parent()}, isoHandlers) isoHandlers.addDefaultHandlers()
将自定义选项添加到
SummaryFactory
view.groovy
import iso19139.SummaryFactory def isoHandlers = new iso19139.Handlers(handlers, f, env) def factory = new SummaryFactory(isoHandlers, {summary -> summary.title = "My Title" summary.addCompleteNavItem = false summary.addOverviewNavItem = false summary.associated.clear() }) handlers.add name: "Summary Handler", select: {it.parent() is it.parent()}, {factory.create(it).getResult()} isoHandlers.addDefaultHandlers()
将自定义行为添加到
iso19139.Handlers
构造函数
view.groovy
def isoHandlers = new iso19139.Handlers(handlers, f, env) { { def oldImpl = super.isoTextEl isoTextEl = { el -> "----------- ${oldImpl(el)}" } } }