XML/XSL page configuration
For each page in your application there must be a configuration and a style sheet. This article covers the page configuration. For informations about the style sheet see XML/XSL page style sheets.
Location of page configuration files
Page configuration files should be created in the conf subdirectory of the pages directory. The location of the pages directory can be configured in the config/php/config.php file within the getPagePath() method. Please make sure that the contents of this path can be read by the webserver user.
One .xml file in the conf directory denotes one page. The name of the file without the .xml extension denote the name of the page that has to be the value of the page argument within the URL in order to see this specific page.
Configuration
A page is configured in XML and instantiated with a page factory. For more information about the page factory and the page container see purpose of the page factory. As noted there it is possible to create your own page factory and to use a complete other way of configuring the page, e.g. from a database. For this example we will stick with the XML configuration, on the basis of the example provided on our example page.
<?xml version="1.0" encoding="iso-8859-1"?>
<xj:configuration
xmlns:xj="http://xjconf.net/XJConf"
xmlns:cfg="http://stubbles.net/util/XJConf"
xmlns="http://stubbles.net/websites">
<page>
<properties>
<property name="skin">default</property>
</properties>
<resources>
<resource name="counter">org::stubbles::examples::resources::MyResource</resource>
</resources>
<xmlElement type="org::stubbles::examples::pageelements::TestXMLPageElement" name="Test" />
<xmlElementCachingDecorator lifetime="60">
<xmlElement type="org::stubbles::examples::pageelements::CurrentTimeXMLPageElement" name="cached" />
</xmlElementCachingDecorator>
<xmlElement type="org::stubbles::examples::pageelements::CurrentTimeXMLPageElement" name="uncached" />
<xmlElement type="org::stubbles::examples::pageelements::TestElementWithInjectedResource" name="counter" />
<xmlPassThru fileName="test.xml" name="passThru">
<cfg:stubConfig name="directory" method="getConfigPath" append="/misc"/>
</xmlPassThru>
</page>
</xj:configuration>
You can see several different sections of the configuration file.
Page properties
<properties> <property name="skin">default</property> </properties>
A page may have properties. These are key-value pairs of data that may influence how the page is handled. Currently two properties are directly supported.
| Property name | Usage |
| language | The general language can be configured via the registry with the net.stubbles.language property. However sometimes it may be necessary to mark a certain page as being in a different language. With this property set one can overwrite the general language setting. |
| skin | The skin property can be used to determine which skin the XML post interceptor should use to render the page. If this property is not set the skin named default will be used. (Hence the configuration in this example has the same effect as if the property would not be configured.) More information about the skin can be found on XML/XSL page style sheets. |
| forceSSL | This property will force a redirect to the same page, but with https instead of http if the current request was not in SSL mode. |
Resources
<resources> <resource name="counter">org::stubbles::examples::resources::MyResource</resource> </resources>
Resources are objects which should be instantiated once per session, but you do not care whether and when they are created. Check The session scope for a more detailed introduction into the topic.
All resources are configured inside the <resources> tag. One resource is configured with the <resource>. The name attribute denotes the name of the node under which the resource object itself will be serialized into XML within the XML tree, while the content of the <resource> node contains the full qualified class name to be used for this resource.
Page elements
The rest of the XML nodes within the <page> node are page elements. Page elements are the connector between the controlling and the model part of the MVC component in Stubbles. They access the business logic, and perform operations on it influenced by values from the request and the session. There are two kind of page elements. The first one, <xmlElement> is an abstract one, its type attribute referes to the concrete page element class. This can be used to refer your own page elements, which should implement the net::stubbles::websites::xml::stubXMLPageElement interface. The name attribute will be the name of the node into which the return value of the process() method of the page element will be serialized.
The second one, <xmlElementCachingDecorator>, refers to the concrete class net::stubbles::websites::xml::stubXMLPageElementCachingDecorator which can be used to cache the return values of decorated page element for a certain amount of time. This time frame is set with the lifetime attribute in seconds. Within the <xmlElementCachingDecorator> there can be exactly on other <xmlElement>.
Finally there is a <xmlPassThru> node, which is another concrete page element delivered by Stubbles. It can be used to pass through the contents of a file into the generated XML tree. It has two attributes: filename contains the basename of the file, and directory which contains the location of the file. In this example the directory is configured using an extension, which calls the stubConfig::getConfigPath() method, and sets its return value with /misc/ appended as directory attribute.
Result
The result of the processing of this page configuration is a XML document which looks something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<document page="index">
<session>
<id>91497fb3ce6cca2656d73b3103733e2d</id>
<name>PHPSESSID</name>
<isNew>false</isNew>
<token>
<current>0e5d5519315508fd393a3ca8a7a17a1d</current>
<next>943bd92c169b545e52fd27c70cf72650</next>
</token>
</session>
<Test>
<foo>Hello World!</foo>
</Test>
<cached>
<currentTime>2007-10-01 20:42:15</currentTime>
</cached>
<uncached>
<currentTime>2007-10-01 20:42:27</currentTime>
</uncached>
<counter/>
<passThru>
<content>
<test>
<foo content="This is bar."/>
</test>
</content>
</passThru>
<forms>
<Test/>
<cached/>
<uncached/>
<counter/>
<passThru/>
</forms>
<request/>
<resources>
<counter>
<count>1</count>
</counter>
</resources>
</document>
