Embedded Objects - Text File

Embed a text file from file system. docBase is the base dir of files, and filePath is the relative path under the docBase. filePath supports request parameters. #{param.Foo} stands for the value of request parameter Foo.

For example, load the index.html under #{website.home}/userGuide. #{website.home} is the root directory of current website.


<object xmlns="http://www.cmobilecom.com/af/objects" 
	id="object1" type="textFile">
   <docBase>#{website.home}/userGuide</docBase>
   <filePath>index.html</filePath>
   <charset>UTF-8</charset>
   <mimeType>text/html</mimeType>  
   <preText><![CDATA[<textArea readonly rows="10" cols="120">]]></preText>
   <postText><![CDATA[</textArea>]]></postText>   
</object>
charset is file encoding. mimeType can be text/html, text/plain or text/xml. default mimeType is text/html, and the text will not be escaped. The text will be escaped for text/xml and text/plain.

preText is the text that will be added to the beginning of the text. postText is the text that will be appended to the end of the text. both preText and postText are optional.

Example: suppose there is a user guide directory under [website.home] directory:

[website.home]/userGuide/index.html
[website.home]/userGuide/examples/example1.html
[website.home]/userGuide/examples/example2.html
[website.home]/userGuide/images/image1.gif
[website.home]/userGuide/css/example.css
The URL pattern is /userGuide/[filePath]. So the URL rewriting rule is:

<url-rewriting>
	<rule>
		<pattern>^/userGuide/(.+)\.html$</pattern>
		<page>/index.xhtml</page>
		<parameter name="pageIdentifier">userGuide</parameter>
		<parameter name="filePath">$1.html</parameter>
	</rule>
</url-rewriting>
The URL /userGuide/index.html will be rewritten as:
	/index.xhtml?pageIdentifier=userGuide&filePath=index.html
The URL /userGuide/examples/example2.html will be rewritten as:
	/index.xhtml?pageIdentifier=userGuide&filePath=examples/example2.html
Embed the user guide into a page whose pageIdentifier is userGuide:

<object xmlns="http://www.cmobilecom.com/af/objects" 
	id="textFile1" type="textFile">
   <docBase>#{website.home}/userGuide</docBase>
   <filePath>#{param.filePath}</filePath>
</object>
#{param.filePath} is the value of the created request parameter "filePath", and #{website.home} is the root dir of current website. so the physical file to be embedded for the URL /userGuide/examples/example2.html is
	[website.home]/userGuide/examples/example2.html
To process requests for files other than HTML, for example, images/css files, forward them to wwwFiles servlet.

<url-rewriting>
	<rule>
		<pattern>^/userGuide/(.+)\.html$</pattern>
		<page>/index.xhtml</page>
		<parameter name="pageIdentifier">userGuide</parameter>
		<parameter name="filePath">$1.html</parameter>
	</rule>
	
	<rule>
		<pattern>^/userGuide/(.+)$</pattern>
		<page>/wwwFiles/userGuide/$1</page>
	</rule>	
</url-rewriting>
The URL /userGuide/images/image1.gif will be rewritten as:
	/wwwFiles/userGuide/images/image1.gif
The URL /userGuide/css/example.css will be rewritten as:
	/wwwFiles/userGuide/css/example.css
The wwwFiles servlet will load the file userGuide/css/example.css under the current website root directory [website.home]. By default the wwwFiles servlet is configured in web.xml. For detail, see the File Access section of Website module documentation.