98 Star 569 Fork 123

闲.大赋(李家智) / Beetl

 / 详情

使用CompositeResourceLoader中include无法正确定位?

待办的
创建于  
2019-07-03 09:40

该问题是怎么引起的?

public static String getRelPath(String siblings, String resourceId) {
String relResourceId = null;
if (resourceId != null && resourceId.length() != 0) {
char cs = resourceId.charAt(0);
if (cs != '\' && cs != '/') {
int i = siblings.length() - 1;

            boolean find;
            for(find = false; i > 0; --i) {
                char c = siblings.charAt(i);
                if (c == '\\' || c == '/') {
                    find = true;
                    break;
                }
            }

            if (find) {
                String parent = siblings.substring(0, i + 1);
                 **relResourceId = parent.concat(resourceId);** 
            } else {
                relResourceId = resourceId;
            }
        } else {
            relResourceId = resourceId;
        }

        if (isOutsideOfRoot(relResourceId)) {
            throw new RuntimeException("不能访问外部文件或者模板");
        } else {
            return relResourceId;
        }
    } else {
        throw new RuntimeException("资源ID为空,参数错");
    }
}

重现步骤

relResourceId = parent.concat(resourceId);
没有把 分割符 删除后再拼接。
比如:include("http:/xxx.html"){},不应该把http:也拼接进来。

报错信息

include是否有更合理的写法?

评论 (5)

preemyin 创建了任务

不太懂你需求,说出的你的需求来,输入图片说明

这是一个人提供得,你可以参考这个类写一个

@闲.大赋(李家智) ,因为使用使用CompositeResourceLoader 组合ClassPathResourceLoader和FileResourceLoader,现在想在FileResourceLoader里面使用include标签,发现找不到对应的资源,跟踪代码发现发现relResourceId = parent.concat(resourceId);返回的是:
父目录+http:/xxx.html,也就是无法找到正确的模板资源。

哦,不清楚你场景,为什么用http:/xxx.html方式了,我理解文件还是classpah,都是文件模式,在beetl中有个单元测试CompositeResourceLoader CompositeResourceLoaderTest你可以参考一下,另外如果你觉得include有问题,你可以重新覆盖,注册一个自己的include实现

TAG.include= org.beetl.ext.tag.YourIncludeTag

@闲.大赋(李家智) ,好的,谢谢,我自己实现了include,不过确实存在CompositeResourceLoader 中include加载不到的问题,http:是为了方便标注是从classpath下面的模板文件还是file下面的模板文件。

好的,我看看include

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
29 xiandafu 1678706040
Java
1
https://gitee.com/xiandafu/beetl.git
git@gitee.com:xiandafu/beetl.git
xiandafu
beetl
Beetl

搜索帮助