基于磁盘文件的自动 GWT ClientBundles
目前,我正在我的应用中充分利用 GWT 的 ClientBundles。它工作正常,但我有大量资源,为每个文件手动创建 Java 接口变得很乏味:
@ClientBundle.Source("world_war_ii.txt")
public ExternalTextResource worldWarII();
@ClientBundle.Source("spain.txt")
public ExternalTextResource spain();
@ClientBundle.Source("france.txt")
public ExternalTextResource france();
我希望能够(也许在编译时)动态列出给定目录中的每个 *.txt 文件,然后可以在运行时访问它们,可能作为数组 ExternalTextResource[]
,而不必在我的代码中显式列出它们。可能有数百个这样的资源,并且将它们手动枚举为代码将非常痛苦且难以维护。
ClientBundle 文档明确指出“提供文件系统抽象”不是目标,因此不幸的是,这似乎不允许我尝试做的事情。
处理运行时必须可用的大量外部资源的最佳方法是什么?生成器有帮助吗?
I'm currently making good use of GWT's ClientBundles in my app. It works fine, but I have a large number of resources and it becomes tedious to manually create Java interfaces for each file:
@ClientBundle.Source("world_war_ii.txt")
public ExternalTextResource worldWarII();
@ClientBundle.Source("spain.txt")
public ExternalTextResource spain();
@ClientBundle.Source("france.txt")
public ExternalTextResource france();
I'd like to be able to (perhaps at compile time) dynamically list every *.txt file in a given directory, and then have run-time access to them, perhaps as an array ExternalTextResource[]
, rather than having to explicitly list them in my code. There may be hundreds of such resources, and enumerating them manually as code would be very painful and unmaintainable.
The ClientBundle
documentation explicitly says that "to provide a file-system abstraction" is a non-goal, so unfortunately this seems to disallow what I'm trying to do.
What's the best way to deal with a large number of external resources that must be available at run-time? Would a generator help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终遵循了 此建议:在服务器上执行文件操作,然后通过 RPC 调用返回文件(元)数据列表。
事实证明这相当简单,并且还允许我在列表中返回轻量级引用(文件名),我用它来填充
Tree
客户端;当用户单击TreeItem
时,将下载实际的文本内容。I ended up following this advice: perform the file operations on the server, and then return a list of the file (meta)data via an RPC call.
This turns out to be fairly simple, and also allows me to return lightweight references (filenames) in the list, which I use to populate a
Tree
client-side; when the user clicks on aTreeItem
the actual text contents are downloaded.CssResource
有一个自动生成器 - 也许你可以看看其代码并根据您的需要进行修改?There's an automatic generator for
CssResource
- maybe you could look at its code and modify it to your needs?