在 Qt/webkit 中合并多个资源路径的工作方法?
我正在编写一个使用 Qt/webkit 来显示文档的应用程序。 它们基于 XML,并将 XSLT 应用于文档以获得最终结果 HTML 中的表示。
每个文档可以引用各种资源:
- /usr/share/app/common 中的系统共享项目
- /home/user/.config/app/custom_styles 中的用户特定项目
- /document/document_things 中的文档特定项目
该文档包含数学由 jsMath 脚本处理, 它们位于系统共享区域。还有常见的 图像和 CSS 样式。
每个用户都可以验证文档的部分内容并拥有自己的权限 他的主目录中的设置,例如 css 样式。
最后,每个文档都有它自己的 uniq 资源, 可以是任何东西——视频、档案或脚本。
应用程序加载文档并知道每个文档的 3 个路径 资源并将它们传递到 XSLT 中以生成最终的 HTML将被加载到QWebView中呈现 对于用户来说。
问题是我需要正确设置 baseURL webview,这确实很棘手:
方案问题:windows 和 linux 处理 file:/// 和简单的 '/' 开头 URL在不同方面有所不同,导致代码混乱(添加 Windows 上路径中的字母)
另外,我刚刚发现 Qt 4.8.0 的 URL 不能以“/”结尾 - 带有 这个 webkit 会产生安全错误,抱怨跨站点脚本。 我必须在 QWebSettings 中设置各种安全设置,例如 LocalContentCanAccessFileUrls 可以正常工作。
这些微妙的事情确实很难调试和维护,尤其是当 您考虑的是跨平台和各种 qt/webkit 版本 到处部署(顺便说一句,4.7 只是错误的 XSLT 上的段错误...)
所以,问题是:
1)考虑到我需要,使用什么作为生成的 HTML 的基本 url 包含来自不同地方的多种资源和工作 JS ?
2)是否值得尝试创建结合所有内容的“虚拟”目录 使用符号链接或类似的东西的资源? 这可以解决基本网址的问题,但我不确定是否可以 功能在 Windows 上可用,并且希望保留仅 Qt 的解决方案。
当我考虑未来时,问题变得更加复杂 - 我想 能够从网络加载文档并在本地保留用户资源。
关于如何处理混乱有什么建议吗?
I'm writing an application that uses Qt/webkit to display documents.
They are XML based and XSLT is applied to the document to get final
representation in HTML.
Each document can refer to various resources:
- System shared items in /usr/share/app/common
- User-specific items in /home/user/.config/app/custom_styles
- Document-specific items in /document/document_things
the document contains math which is processed by jsMath scripts,
which are located in system-shared area. There are also common
images and CSS styles.
Each user can ovveride parts of the document and has his own
settings in his home directory, for example css styles.
Finally, each document comes with it's own uniq resources,
what can be anything - videos, archives or scripts.
Application loads the document and knows 3 paths for each
of resources and passes them into XSLT to generate final
HTML which will be loaded into QWebView to be presented
for the user.
The issue is that I need to setup baseURL correctly for
the webview, which is really tricky:
scheme issues: windows and linux treat file:/// and simple '/' starting
URLS differently in different aspects, producing a mess in code (add
letters in path on windows)
also, I've just found that URL can't end in '/' with Qt 4.8.0 - with
this webkit produces security error, complaining about cross-site scripting.
I have to set various security settings in QWebSettings like
LocalContentCanAccessFileUrls for things to work.
Such subtle things are really hard to debug and maintain especially when
you have cross-platforming in mind and a zoo of various qt/webkit versions
deployed everywhere (btw, 4.7 just segfaults on incorrect XSLT...)
So, the questions are:
1) What to use as base url for generated HTML considering that I need
to include multiple resources from various places and working JS ?
2) Is it worth to attempt to create 'virtual' directory combining all
resources using symlinks or something similar?
This would solve problem with base url, but I'm not sure if such
functionality is available on Windows and want to stay with Qt-only solution..
The issue becomes more complex, when I think about future - I'd like
to enable to load documents from web and still have user resources locally.
Any suggestions on how to deal with the mess ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论