SiteMesh3.0.0 读取xml配置的bug及修复

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">今天用SiteMesh3.0.0 做网站项目,遇到模板总是无法正确匹配的问题,我使用mapping元素定义匹配规则时,发现sitemesh不能正常匹配到模板。</span>

我的sitemesh3.xml是这么定义的

<mapping>
<span style="white-space:pre">	</span><path>/game/*</path>
<span style="white-space:pre">	</span><decorator>/_decorators/mobile-common.theme.ftl</decorator>
</mapping>
<mapping>
<span style="white-space:pre">	</span><path>/game/list/*</path>
<span style="white-space:pre">	</span><decorator>/_decorators/mobile-games.theme.ftl</decorator>
<span style="white-space:pre">	</span><decorator>/_decorators/mobile-common.theme.ftl</decorator>
</mapping>


阅读org.sitemesh.config.xml.XmlConfigurator的代码才发现,原来是sitemesh的代码出了点问题导致无法正常读取path子元素,

修改40-50行的代码即可解决该问题。

3.0.0原始代码

        // Decorator mappings
        for (Xml mapping : xml.children("mapping")) {
            List<Xml> paths = xml.children("path");
            if (!paths.isEmpty()) {
                for (Xml path : xml.children("mapping")) {
                    addDecoratorPaths(builder, mapping, path.text());
                }
            } else {
                addDecoratorPaths(builder, mapping, mapping.attribute("path", "/*"));
            }
        }

修复的代码:

        // Decorator mappings zhongqiang:基于对3.0.0版本,修正对mapping的path子元素的支持。
        for (Xml mapping : xml.children("mapping")) {
            List<Xml> paths = mapping.children("path");
            if (!paths.isEmpty()) {
                for (Xml path : paths) {
                    addDecoratorPaths(builder, mapping, path.text());
                }
            } else {
                addDecoratorPaths(builder, mapping, mapping.attribute("path", "/*"));
            }
        }



(完)

可以参考github。

https://github.com/sitemesh/sitemesh3/blob/35896aebcd2c3a8c22e8a797919630dd8537e6fd/sitemesh/src/main/java/org/sitemesh/config/xml/XmlConfigurator.java

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值