Why do you need URL rewriting?
|
| Initial Path | Resulting Portlet Parameters |
|---|---|
/example1/page1?name1=value1&name2=value2 |
|
?name1=value1&name2=value2 |
|
Assuming the current value of orbeon.path is /example1/page1:
../example2/page2?name1=value1&name2=value2
|
|
URL rewriting in XForms markup
Similarities and differences
The goal behind URL rewriting in XForms is similar to that of URL rewriting in HTML/XHTML: making your life easier!Here are the similarities and differences between XForms documents and pure HTML/XHTML documents:
- Author-specified URLs present on XHTML elements
- go through the XForms process without modification and are rewritten by the regular XHTML rewriting process described above
- except that Attribute Value Templates (AVTs) on XHTML elements are processed by the XForms engine
- Author-specified URLs present on XForms elements
- are processed by the XForms engine (see details below)
- In addition:
- The XForms processor outputs links to some internal resources not specified by the form author:
- JavaScript
- CSS
- some images such as
- /ops/images/xforms/spacer.gif
- /ops/images/xforms/help.png
- /ops/images/xforms/calendar.png
- Certain controls can output resources or HTML markup containing URLs
- xforms:output[@appearance = 'xxforms:download' or @mediatype = ('text/html', 'image/*')]
- xforms:label/hint/help/alert may contain dynamically-produced HTML
Service URLs
xforms:instance- the
srcorresourceattribute links to an external instance definition
<xforms:instance src="/my-app/initial-data.xml"/>
- This feature allows for improved modularity by separating an XForms instance definition from an XHTML page. It also allows for producing XForms instances dynamically.
- NOTE: if the instance to load is a static file on the server, it is advised for performance reasons to specify an absolute URL instead, e.g.:
<xforms:instance src="oxf:/apps/my-app/initial-data.xml"/> xforms:model- the
schemaattribute links to an external schema definition
<xforms:model schema="/my-app/schema.xsd">
...
</xforms:model> - NOTE: if the schema to load is a static file on the server, it is
advised for performance reasons to specify an absolute URL instead,
e.g.:
<xforms:model schema="oxf:/apps/my-app/schema.xsd">
...
</xforms:model> xforms:submission(except with the GET method andreplace="all"combination)
- the
actionorresourceattributes specifies the URL of the submission
<xforms:submission id="my-submission" method="post" resource="/my-app/service/save" replace="instance" .../> - NOTE: if the submission uses the GET method and loads is a static file on the server, it is
advised for performance reasons to specify an absolute URL instead,
e.g.:
<xforms:submission id="my-submission" method="get" resource="oxf:/apps/my-app/service/read"replace="instance".../>
Instances, submissions and schemas are loaded as service URLs:
- They typically address services running on the application server running Orbeon Forms or another server.
- The base URL against which service URLs are resolved can be configured separately using the
oxf.url-rewriting.service.base-uriproperty. - If the base URL is an absolute path instead of an absolute URL, the scheme, server name and port are obtained from the current request.
Render URLs
xforms:load- the
resourceattribute specifies an URL that must be loaded on the client after the action completes
<xforms:load resource="/fr/orbeon/builder/summary"/>
xforms:submissionwith GET method andreplace="all"
- the
actionorresourceattributes specifies the URL of the submission
<xforms:submission id="my-submission" method="get" resource="/my-app/page2" replace="all" .../> xhtml:a- the
hrefattribute specifies an URL that must be loaded on the client when the user activates the anchor - this is handled by XForms when
- the attribute is specified as an AVT, e.g.
<a href="{/my/link}"> - the element is dynamically produced by
xforms:outputwith HTML mediatype - the element is a descendant of
xforms:label,xforms:help,xforms:hint, orxforms:alert
Resource URLs
xforms:outputwith image mediatype- the single-node binding points to the URL of an image to load on the client
<xforms:output bind="my-image" mediatype="image/*"/>
xhtml:img- the
srcattribute specifies an URL that must be loaded on the client - this is handled by XForms when
- the attribute is specified as an AVT, e.g.
<img src="{/my/image}"> - the element is dynamically produced by
xforms:outputwith HTML mediatype - the element is a descendant of
xforms:label,xforms:help,xforms:hint, orxforms:alert xforms:message, xforms:label,xforms:help,xforms:hint, andxforms:alert- these elements may use an
srcattribute to refer to external content.
- NOTE: XForms 1.1 moves responsibility for the
srcattribute on these elements to the host language. It is advised not to use this attribute.
NOTE: As of October 2009, as described above only the HTML <a href> and <img src> are processed specially by the XForms engine. This is a current limitation and ideally all the HTML elements described in the previous section should be processed.
xml:base resolution
All non-absolute URLs processed by the XForms engine are resolved relatively to a base URI. The base URI is, by default, the path of the request URL that caused the processing of the XForms page, with special handling of the servlet context if necessary. It is also possible to override this behavior by adding an explicitxml:base attribute on an XForms element or any ancestor element. Processing goes as follows:- All URLs first go through
xml:baseresolution to produce an absolute URL or an absolute path. - Then the URLs are rewritten according to rules depending on the type of URL.
xml:base attribute processing is performed in plain HTML/XHTML documents that do not contain any XForms, with the exception of the oxf:xinclude processor which performs such resolution for purposes of resolving inclusion URLs, and adds xml:base attributes to its output as per the XInclude specification. Examples of service URL resolution
Assume the following:- URL requesting the current page:
http://a.org/orbeon/app/page1 - Orbeon Forms deployed context:
orbeon
| oxf.url-rewriting.service.base-uri property | Initial URL | Resolved URL | Comment |
|---|---|---|---|
| blank or missing property |
http://b.com/instance
|
http://b.com/instance
|
Absolute URL is left untouched. |
/instance
|
http://a.org/orbeon/instance
|
Absolute path resolves against the servlet context. |
|
page2/instance
|
http://a.org/orbeon/app/page2/instance
|
Relative path resolves against the request URL. |
|
http://example.org/my/context
|
http://b.com/instance
|
http://b.com/instance
|
Absolute URL is left untouched. |
/instance
|
http://example.org/my/context/instance
|
|
|
page2/instance
|
http://example.org/my/context/app/page2/instance |
|
|
/my/context
|
http://b.com/instance
|
http://b.com/instance
|
Absolute URL is left untouched. |
/instance
|
http://a.org/my/context/instance
|
|
|
page2/instance
|
http://a.org/my/context/app/page2/instance
|
|
[TODO: portlet examples]
Examples of render URL resolution
| Initial URL | Resolved URL | Comment |
|---|---|---|
http://www.google.com/
|
http://www.google.com/
|
Absolute URL is left untouched. |
/app/page2
|
http://a.org/orbeon/app/page2
|
Absolute path resolves against the servlet context. |
../app2/page1
|
http://a.org/orbeon/app2/page1
|
Relative path resolves against the request URL. |
[TODO: portlet examples]
Examples of resource URL resolution
[TODO: servlet examples][TODO: portlet examples]
URL rewriting in separate deployment
What's different
In separate deployment, the XForms engine has to perform extra rewriting work:- The URLs you write in your application must point to your own web application.
- URLs produced by Orbeon Forms for its internal use, such as CSS, JavaScript and image resources, must point to the Orbeon Forms web application.
Versioned resources
In separate deployment, versioned resources are enabled only for Orbeon Forms resources. Your application resources are not versioned.
Known limitations
Portlets
-
The input document should not contain:
- Elements and attribute containing the string
wsrp_rewrite - Namespace URIs containing the string
wsrp_rewrite - Processing instructions containing the string
wsrp_rewrite
- Elements and attribute containing the string
-
It is not possible to specify:
- A destination portlet mode
- A destination window state
- A secure URL
Implementation notes
These notes are destined to the Orbeon Forms contributor:ServletExternalContextreturns the original values returned by the servlet API, except in case of inclusion, where the request attributes specifying the location the included servlet are used.oxf:xforms-to-xhtmlproduces output which contains non-rewritten URLs.- Rewriting of the XHTML resulting from XForms processing is performed by
oxf:xhtml-rewrite. - For Ajax responses, rewriting is performed separately for URLs (images, load, GET submission) and HTML output.
- The servlet rewriting algorithm is implemented in
URLRewriterUtils. - This uses the fact that a request was forwarded, or that an Orbeon filter was present, to alter the result.
- When the Orbeon filter is in use, it is expected that "everything" goes through the filter:
- requests for Orbeon CSS, JavaScript and image resources
- requests for /xforms-server and /xforms-server-submit
- NOTE: later, this constraint could be relaxed (assuming the session is still forwarded)