好的,我已经尝试了以下内容,并没有产生我所希望的效果。我有一个reference.conf
指定相对于前缀的文件系统位置,看起来有点像这样:
// reference.conf
myapp {
// The dummy path makes the error message easy to diagnose
s3.prefix = "s3://environment/variable/S3_PREFIX/missing"
s3.prefix = ${?S3_PREFIX}
file1 = ${myapp.s3.prefix}"/file1.csv"
file2 = ${myapp.s3.prefix}"/file2.csv"
// ...
}
然后我提供了一个看似或多或少的application.conf
文件:
// application.conf
myapp.s3.prefix = "s3://some-bucket/some/path/to/the/files"
myapp.file2 = "s3://some-other-bucket/some/path/file2.csv"
现在,当我的应用程序执行ConfigFactory.load()
时,来自:
reference.conf
文件,执行替换,并生成Config
对象,其中:
myapp.s3.prefix = "/environment/variable/S3_PREFIX/missing"
myapp.file1 = "/environment/variable/S3_PREFIX/missing/file1.csv"
myapp.file2 = "/environment/variable/S3_PREFIX/missing/file2.csv"
。application.conf
文件并生成Config
对象,其中:
library.prefix = "/some/path/to/the/files"
myapp.file2 = "s3://some-other-bucket/some/path/file2.csv"
。reference.conf
对象作为后备。因此生成的Config
对象具有:
library.prefix = "s3://some-bucket/some/path/to/the/files"
(如application.conf
)library.file1 = "s3://environment/variable/S3_PREFIX/missing/file1.csv"
(如reference.conf
)。library.file2 = "s3://some-other-bucket/some/path/file2.csv"
(如application.conf
)。但正如您可能已经从我的示例中猜到的那样,我尝试做的是让reference.conf
指定默认路径 relative 到根目录,并允许任何混合两者:
application.conf
的默认根目录,以便从那里查找reference.conf
的默认相对路径。application.conf
中任何单个文件的路径,以便应用程序可以使用不在根目录中的路径。到目前为止,我唯一能够提出的是:
// reference.conf
myapp {
// The dummy path makes the error message easy to diagnose
s3.prefix = "s3:/environment/variable/S3_PREFIX/missing"
s3.prefix = ${?S3_PREFIX}
file1 = "file1.csv"
file2 = "file2.csv"
// ...
}
// application.conf
myapp.s3.prefix = "s3://some-bucket/some/path/to/the/files"
myapp.file2 = "s3://some-other-bucket/some/path/file2.csv"
// The Java code for using the config must append prefix and file location,
// and needs to have smarts about relative vs. absolute paths.
final Config CONF = ConfigFactory.load();
String getS3URLFor(String file) {
String root = CONF.getString("myapp.s3.prefix");
String path = CONF.getString("myapp." + file);
return relativeVsAbsoluteSensitiveMerge(root, path);
}
String relativeVsAbsoluteSensitiveMerge(String root, String path) {
if (isAbsoluteReference(path)) {
return path;
} else {
return root + "/" + path;
}
}
boolean isAbsoluteReference(String path) {
// ...
}
我不太喜欢这个解决方案。谁能想到更好的东西?
答案 0 :(得分:1)
您可以先解析然后解决:
var currentTR = $("<tr><td><input type='file'/></td></tr>");
$(this).closest('tr').before(currentTR);