1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/login_template.xhtml Fri Jun 01 23:17:45 2007 +0000 1.3 @@ -0,0 +1,45 @@ 1.4 +<?xml version="1.0" encoding="iso-8859-1"?> 1.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 1.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 1.7 +<html xmlns="http://www.w3.org/1999/xhtml" 1.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 1.9 +<head> 1.10 + <title>Very Simple Login</title> 1.11 + <script type="text/javascript" src="{$root}scripts/sarissa.js"> </script> 1.12 + <script type="text/javascript" src="{$root}scripts/XSLForms.js"> </script> 1.13 +</head> 1.14 + 1.15 +<body template:element="login"> 1.16 +<h1 template:i18n="-">Login</h1> 1.17 + 1.18 +<form method="post"> 1.19 + <table cellspacing="0" cellpadding="5" id="login-info"> 1.20 + <thead> 1.21 + <tr> 1.22 + <th class="heading" colspan="2" template:i18n="-">Login</th> 1.23 + </tr> 1.24 + </thead> 1.25 + <tbody> 1.26 + <tr template:element="error" template:init="no"> 1.27 + <th class="error" template:i18n="-">Error</th> 1.28 + <td><span template:i18n="{@message}">error message</span></td> 1.29 + </tr> 1.30 + <tr> 1.31 + <th template:i18n="-">Username</th> 1.32 + <td><input type="text" template:attribute-field="username" name="..." value="..." size="20"/></td> 1.33 + </tr> 1.34 + <tr> 1.35 + <th template:i18n="-">Password</th> 1.36 + <td><input type="password" template:attribute-field="password" name="..." value="..." size="20"/></td> 1.37 + </tr> 1.38 + <tr> 1.39 + <td colspan="2"> 1.40 + <input type="submit" value="{template:i18n('Log in!')}" name="login" /> 1.41 + </td> 1.42 + </tr> 1.43 + </tbody> 1.44 + </table> 1.45 +</form> 1.46 + 1.47 +</body> 1.48 +</html>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/scripts/XSLForms.js Fri Jun 01 23:17:45 2007 +0000 2.3 @@ -0,0 +1,178 @@ 2.4 +// Area update functions. 2.5 + 2.6 +function requestUpdateArea(url, sourceAreasStr, targetName, targetAreasStr, elementPath) { 2.7 + 2.8 + var fieldNames = new Array(); 2.9 + var targetFieldNames = new Array(); 2.10 + 2.11 + for (var i = 0; i < document.forms.length; i++) { 2.12 + var form = document.forms[i]; 2.13 + for (var j = 0; j < form.elements.length; j++) { 2.14 + var fieldName = form.elements[j].name; 2.15 + checkField(fieldName, sourceAreasStr, fieldNames); 2.16 + checkField(fieldName, targetAreasStr, targetFieldNames); 2.17 + } 2.18 + } 2.19 + 2.20 + return _requestUpdate(url, fieldNames, targetName, targetFieldNames, elementPath); 2.21 +} 2.22 + 2.23 +// Field list update functions. 2.24 + 2.25 +function requestUpdate(url, fieldNamesStr, targetName, targetFieldNamesStr, elementPath) { 2.26 + 2.27 + return _requestUpdate(url, fieldNamesStr.split(","), targetName, targetFieldNamesStr.split(","), elementPath); 2.28 +} 2.29 + 2.30 +// Internal functions. 2.31 + 2.32 +function checkField(fieldName, areasStr, areaFieldNames) { 2.33 + 2.34 + // Process each area name. 2.35 + 2.36 + var areaArray = areasStr.split(","); 2.37 + for (var i = 0; i < areaArray.length; i++) { 2.38 + var areaName = areaArray[i]; 2.39 + 2.40 + // Skip empty area names (arising through empty elements in the CSV list). 2.41 + 2.42 + if (areaName == "") { 2.43 + continue; 2.44 + } 2.45 + 2.46 + if (fieldName.indexOf(areaName) == 0) { 2.47 + areaFieldNames.push(fieldName); 2.48 + } 2.49 + } 2.50 +} 2.51 + 2.52 +function _requestUpdate(url, fieldNames, targetName, targetFieldNames, elementPath) { 2.53 + 2.54 + // Note that XMLHttpRequest access may be denied if Mozilla believes that 2.55 + // this resource's URL and the supplied URL are different. 2.56 + 2.57 + var xmlhttp = new XMLHttpRequest(); 2.58 + xmlhttp.open("POST", url, false); 2.59 + 2.60 + // Add the element path specification. 2.61 + 2.62 + var requestBody = ("element-path=" + elementPath); 2.63 + 2.64 + // Send the controlling field value. 2.65 + 2.66 + requestBody += addFields(fieldNames, false); 2.67 + requestBody += addFields(targetFieldNames, true); 2.68 + 2.69 + // Load the remote document with the given parameters sent as text in the request body. 2.70 + 2.71 + xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 2.72 + xmlhttp.send(requestBody); 2.73 + 2.74 + // Parse the result document. 2.75 + 2.76 + var newDocument = Sarissa.getDomDocument(); 2.77 + newDocument = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml"); 2.78 + 2.79 + // Find the definition of the affected field in the result document. 2.80 + 2.81 + var newElement = newDocument.getElementById(targetName); 2.82 + var targetElement = document.getElementById(targetName); 2.83 + 2.84 + // Insert the new definition into the current document. 2.85 + 2.86 + if (newElement != null && targetElement != null) { 2.87 + var importedElement = document.importNode(newElement, true); 2.88 + targetElement.parentNode.replaceChild(importedElement, targetElement); 2.89 + //importedElement.setAttribute("style", "background-color:red;"); 2.90 + } 2.91 + 2.92 + // NOTE: Test Konqueror bug. 2.93 + 2.94 + //showMismatch(targetFieldNameArray); 2.95 + 2.96 + return false; 2.97 +} 2.98 + 2.99 +function addFields(fieldNames, disable) { 2.100 + 2.101 + var requestBody = ""; 2.102 + 2.103 + // Process each target field name. 2.104 + // Add the values of the dependent fields. 2.105 + 2.106 + for (var i = 0; i < fieldNames.length; i++) { 2.107 + var fieldName = fieldNames[i]; 2.108 + 2.109 + // Skip empty field names (arising through empty elements in the CSV list). 2.110 + 2.111 + if (fieldName == "") { 2.112 + continue; 2.113 + } 2.114 + 2.115 + // Find the values of the target field. 2.116 + 2.117 + var fieldValue; 2.118 + var fieldNodes = document.getElementsByName(fieldName); 2.119 + for (var v = 0; v < fieldNodes.length; v++) { 2.120 + 2.121 + // Test for different field types. 2.122 + 2.123 + if (fieldNodes[v].options) { 2.124 + for (var opt = 0; opt < fieldNodes[v].options.length; opt++) { 2.125 + if (fieldNodes[v].options[opt].selected) { 2.126 + fieldValue = fieldNodes[v].options[opt].value; 2.127 + requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue)); 2.128 + } 2.129 + } 2.130 + } else if (fieldNodes[v].type != 'checkbox' && fieldNodes[v].type != 'radio' || fieldNodes[v].checked) { 2.131 + fieldValue = fieldNodes[v].value; 2.132 + requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue)); 2.133 + } 2.134 + } 2.135 + 2.136 + // NOTE: Konqueror hack: disable fields. 2.137 + 2.138 + if (disable) { 2.139 + disableFields(fieldName); 2.140 + } 2.141 + } 2.142 + 2.143 + return requestBody; 2.144 +} 2.145 + 2.146 +function disableFields(targetFieldName) { 2.147 + 2.148 + for (var i = 0; i < document.forms.length; i++) { 2.149 + var form = document.forms[i]; 2.150 + for (var j = 0; j < form.elements.length; j++) { 2.151 + if (form.elements[j].name == targetFieldName) { 2.152 + form.elements[j].name = ""; 2.153 + } 2.154 + } 2.155 + } 2.156 +} 2.157 + 2.158 +function showMismatch(targetFieldNameArray) { 2.159 + 2.160 + // Show how the number of field elements with a given name can be different 2.161 + // from the number known to the DOM Level 0 part of the API. 2.162 + 2.163 + for (var h = 0; h < targetFieldNameArray.length; h++) { 2.164 + var targetFieldName = targetFieldNameArray[h]; 2.165 + var targetFieldNodes = document.getElementsByName(targetFieldName); 2.166 + alert("Nodes for " + targetFieldName + ": " + targetFieldNodes.length); 2.167 + 2.168 + var count = 0; 2.169 + for (var i = 0; i < document.forms.length; i++) { 2.170 + var form = document.forms[i]; 2.171 + for (var j = 0; j < form.elements.length; j++) { 2.172 + if (form.elements[j].name == targetFieldName) { 2.173 + count++; 2.174 + } 2.175 + } 2.176 + } 2.177 + alert("Fields for " + targetFieldName + ": " + count); 2.178 + } 2.179 +} 2.180 + 2.181 +// vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/scripts/sarissa.js Fri Jun 01 23:17:45 2007 +0000 3.3 @@ -0,0 +1,616 @@ 3.4 +/** 3.5 + * ==================================================================== 3.6 + * About 3.7 + * ==================================================================== 3.8 + * Sarissa cross browser XML library 3.9 + * @version 0.9.6 3.10 + * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net 3.11 + * 3.12 + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs. 3.13 + * The library supports Gecko based browsers like Mozilla and Firefox, 3.14 + * Internet Explorer (5.5+ with MSXML3.0+) and, last but not least, KHTML based browsers like 3.15 + * Konqueror and Safari. 3.16 + * 3.17 + * ==================================================================== 3.18 + * Licence 3.19 + * ==================================================================== 3.20 + * This program is free software; you can redistribute it and/or modify 3.21 + * it under the terms of the GNU General Public License version 2 or 3.22 + * the GNU Lesser General Public License version 2.1 as published by 3.23 + * the Free Software Foundation (your choice of the two). 3.24 + * 3.25 + * This program is distributed in the hope that it will be useful, 3.26 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.27 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.28 + * GNU General Public License or GNU Lesser General Public License for more details. 3.29 + * 3.30 + * You should have received a copy of the GNU General Public License 3.31 + * or GNU Lesser General Public License along with this program; if not, 3.32 + * write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 3.33 + * or visit http://www.gnu.org 3.34 + * 3.35 + */ 3.36 +/** 3.37 + * <p>Sarissa is a utility class. Provides static methods for DOMDocument and 3.38 + * XMLHTTP objects, DOM Node serializatrion to XML strings and other goodies.</p> 3.39 + * @constructor 3.40 + */ 3.41 +function Sarissa(){}; 3.42 +/** @private */ 3.43 +Sarissa.PARSED_OK = "Document contains no parsing errors"; 3.44 +/** 3.45 + * Tells you whether transformNode and transformNodeToObject are available. This functionality 3.46 + * is contained in sarissa_ieemu_xslt.js and is deprecated. If you want to control XSLT transformations 3.47 + * use the XSLTProcessor 3.48 + * @deprecated 3.49 + * @type boolean 3.50 + */ 3.51 +Sarissa.IS_ENABLED_TRANSFORM_NODE = false; 3.52 +/** 3.53 + * tells you whether XMLHttpRequest (or equivalent) is available 3.54 + * @type boolean 3.55 + */ 3.56 +Sarissa.IS_ENABLED_XMLHTTP = false; 3.57 +/** 3.58 + * tells you whether selectNodes/selectSingleNode is available 3.59 + * @type boolean 3.60 + */ 3.61 +Sarissa.IS_ENABLED_SELECT_NODES = false; 3.62 +var _sarissa_iNsCounter = 0; 3.63 +var _SARISSA_IEPREFIX4XSLPARAM = ""; 3.64 +var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true; 3.65 +var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument; 3.66 +var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature; 3.67 +var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE; 3.68 +var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1; 3.69 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1; 3.70 + 3.71 +if(!window.Node || !window.Node.ELEMENT_NODE){ 3.72 + var Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12}; 3.73 +}; 3.74 + 3.75 +// IE initialization 3.76 +if(_SARISSA_IS_IE){ 3.77 + // for XSLT parameter names, prefix needed by IE 3.78 + _SARISSA_IEPREFIX4XSLPARAM = "xsl:"; 3.79 + // used to store the most recent ProgID available out of the above 3.80 + var _SARISSA_DOM_PROGID = ""; 3.81 + var _SARISSA_XMLHTTP_PROGID = ""; 3.82 + /** 3.83 + * Called when the Sarissa_xx.js file is parsed, to pick most recent 3.84 + * ProgIDs for IE, then gets destroyed. 3.85 + * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object 3.86 + * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled 3.87 + */ 3.88 + pickRecentProgID = function (idList, enabledList){ 3.89 + // found progID flag 3.90 + var bFound = false; 3.91 + for(var i=0; i < idList.length && !bFound; i++){ 3.92 + try{ 3.93 + var oDoc = new ActiveXObject(idList[i]); 3.94 + o2Store = idList[i]; 3.95 + bFound = true; 3.96 + for(var j=0;j<enabledList.length;j++) 3.97 + if(i <= enabledList[j][1]) 3.98 + Sarissa["IS_ENABLED_"+enabledList[j][0]] = true; 3.99 + }catch (objException){ 3.100 + // trap; try next progID 3.101 + }; 3.102 + }; 3.103 + if (!bFound) 3.104 + throw "Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")"; 3.105 + idList = null; 3.106 + return o2Store; 3.107 + }; 3.108 + // pick best available MSXML progIDs 3.109 + _SARISSA_DOM_PROGID = pickRecentProgID(["Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"], [["SELECT_NODES", 2],["TRANSFORM_NODE", 2]]); 3.110 + _SARISSA_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]); 3.111 + _SARISSA_THREADEDDOM_PROGID = pickRecentProgID(["Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0"]); 3.112 + _SARISSA_XSLTEMPLATE_PROGID = pickRecentProgID(["Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0"], [["XSLTPROC", 2]]); 3.113 + // we dont need this anymore 3.114 + pickRecentProgID = null; 3.115 + //============================================ 3.116 + // Factory methods (IE) 3.117 + //============================================ 3.118 + // see non-IE version 3.119 + Sarissa.getDomDocument = function(sUri, sName){ 3.120 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID); 3.121 + // if a root tag name was provided, we need to load it in the DOM 3.122 + // object 3.123 + if (sName){ 3.124 + // if needed, create an artifical namespace prefix the way Moz 3.125 + // does 3.126 + if (sUri){ 3.127 + oDoc.loadXML("<a" + _sarissa_iNsCounter + ":" + sName + " xmlns:a" + _sarissa_iNsCounter + "=\"" + sUri + "\" />"); 3.128 + // don't use the same prefix again 3.129 + ++_sarissa_iNsCounter; 3.130 + } 3.131 + else 3.132 + oDoc.loadXML("<" + sName + "/>"); 3.133 + }; 3.134 + return oDoc; 3.135 + }; 3.136 + // see non-IE version 3.137 + Sarissa.getParseErrorText = function (oDoc) { 3.138 + var parseErrorText = Sarissa.PARSED_OK; 3.139 + if(oDoc.parseError != 0){ 3.140 + parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason + 3.141 + "\nLocation: " + oDoc.parseError.url + 3.142 + "\nLine Number " + oDoc.parseError.line + ", Column " + 3.143 + oDoc.parseError.linepos + 3.144 + ":\n" + oDoc.parseError.srcText + 3.145 + "\n"; 3.146 + for(var i = 0; i < oDoc.parseError.linepos;i++){ 3.147 + parseErrorText += "-"; 3.148 + }; 3.149 + parseErrorText += "^\n"; 3.150 + }; 3.151 + return parseErrorText; 3.152 + }; 3.153 + // see non-IE version 3.154 + Sarissa.setXpathNamespaces = function(oDoc, sNsSet) { 3.155 + oDoc.setProperty("SelectionLanguage", "XPath"); 3.156 + oDoc.setProperty("SelectionNamespaces", sNsSet); 3.157 + }; 3.158 + /** 3.159 + * Basic implementation of Mozilla's XSLTProcessor for IE. 3.160 + * Reuses the same XSLT stylesheet for multiple transforms 3.161 + * @constructor 3.162 + */ 3.163 + XSLTProcessor = function(){ 3.164 + this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID); 3.165 + this.processor = null; 3.166 + }; 3.167 + /** 3.168 + * Impoprts the given XSLT DOM and compiles it to a reusable transform 3.169 + * @argument xslDoc The XSLT DOMDocument to import 3.170 + */ 3.171 + XSLTProcessor.prototype.importStylesheet = function(xslDoc){ 3.172 + // convert stylesheet to free threaded 3.173 + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID); 3.174 + converted.loadXML(xslDoc.xml); 3.175 + this.template.stylesheet = converted; 3.176 + this.processor = this.template.createProcessor(); 3.177 + // (re)set default param values 3.178 + this.paramsSet = new Array(); 3.179 + }; 3.180 + /** 3.181 + * Transform the given XML DOM 3.182 + * @argument sourceDoc The XML DOMDocument to transform 3.183 + * @return The transformation result as a DOM Document 3.184 + */ 3.185 + XSLTProcessor.prototype.transformToDocument = function(sourceDoc){ 3.186 + this.processor.input = sourceDoc; 3.187 + var outDoc = new ActiveXObject(_SARISSA_DOM_PROGID); 3.188 + this.processor.output = outDoc; 3.189 + this.processor.transform(); 3.190 + return outDoc; 3.191 + }; 3.192 + /** 3.193 + * Not sure if this works in IE. Maybe this will allow non-well-formed 3.194 + * transformation results (i.e. with no single root element) 3.195 + * @argument sourceDoc The XML DOMDocument to transform 3.196 + * @return The transformation result as a DOM Fragment 3.197 + */ 3.198 + XSLTProcessor.prototype.transformToFragment = function(sourceDoc, ownerDocument){ 3.199 + return this.transformToDocument(sourceDoc); 3.200 + }; 3.201 + /** 3.202 + * Set global XSLT parameter of the imported stylesheet 3.203 + * @argument nsURI The parameter namespace URI 3.204 + * @argument name The parameter base name 3.205 + * @argument value The new parameter value 3.206 + */ 3.207 + XSLTProcessor.prototype.setParameter = function(nsURI, name, value){ 3.208 + /* nsURI is optional but cannot be null */ 3.209 + if(nsURI){ 3.210 + this.processor.addParameter(name, value, nsURI); 3.211 + }else{ 3.212 + this.processor.addParameter(name, value); 3.213 + }; 3.214 + /* update updated params for getParameter */ 3.215 + if(!this.paramsSet[""+nsURI]){ 3.216 + this.paramsSet[""+nsURI] = new Array(); 3.217 + }; 3.218 + this.paramsSet[""+nsURI][name] = value; 3.219 + }; 3.220 + /** 3.221 + * Gets a parameter if previously set by setParameter. Returns null 3.222 + * otherwise 3.223 + * @argument name The parameter base name 3.224 + * @argument value The new parameter value 3.225 + * @return The parameter value if reviously set by setParameter, null otherwise 3.226 + */ 3.227 + XSLTProcessor.prototype.getParameter = function(nsURI, name){ 3.228 + if(this.paramsSet[""+nsURI] && this.paramsSet[""+nsURI][name]) 3.229 + return this.paramsSet[""+nsURI][name]; 3.230 + else 3.231 + return null; 3.232 + }; 3.233 +} 3.234 +else{ /* end IE initialization, try to deal with real browsers now ;-) */ 3.235 + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){ 3.236 + if(window.XMLDocument){ 3.237 + /** 3.238 + * <p>Emulate IE's onreadystatechange attribute</p> 3.239 + */ 3.240 + XMLDocument.prototype.onreadystatechange = null; 3.241 + /** 3.242 + * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p> 3.243 + * <ul><li>1 == LOADING,</li> 3.244 + * <li>2 == LOADED,</li> 3.245 + * <li>3 == INTERACTIVE,</li> 3.246 + * <li>4 == COMPLETED</li></ul> 3.247 + */ 3.248 + XMLDocument.prototype.readyState = 0; 3.249 + /** 3.250 + * <p>Emulate IE's parseError attribute</p> 3.251 + */ 3.252 + XMLDocument.prototype.parseError = 0; 3.253 + 3.254 + // NOTE: setting async to false will only work with documents 3.255 + // called over HTTP (meaning a server), not the local file system, 3.256 + // unless you are using Moz 1.4+. 3.257 + // BTW the try>catch block is for 1.4; I haven't found a way to check if 3.258 + // the property is implemented without 3.259 + // causing an error and I dont want to use user agent stuff for that... 3.260 + var _SARISSA_SYNC_NON_IMPLEMENTED = false; 3.261 + try{ 3.262 + /** 3.263 + * <p>Emulates IE's async property for Moz versions prior to 1.4. 3.264 + * It controls whether loading of remote XML files works 3.265 + * synchronously or asynchronously.</p> 3.266 + */ 3.267 + XMLDocument.prototype.async = true; 3.268 + _SARISSA_SYNC_NON_IMPLEMENTED = true; 3.269 + }catch(e){/* trap */}; 3.270 + /** 3.271 + * <p>Keeps a handle to the original load() method. Internal use and only 3.272 + * if Mozilla version is lower than 1.4</p> 3.273 + * @private 3.274 + */ 3.275 + XMLDocument.prototype._sarissa_load = XMLDocument.prototype.load; 3.276 + 3.277 + /** 3.278 + * <p>Overrides the original load method to provide synchronous loading for 3.279 + * Mozilla versions prior to 1.4, using an XMLHttpRequest object (if 3.280 + * async is set to false)</p> 3.281 + * @returns the DOM Object as it was before the load() call (may be empty) 3.282 + */ 3.283 + XMLDocument.prototype.load = function(sURI) { 3.284 + var oDoc = document.implementation.createDocument("", "", null); 3.285 + Sarissa.copyChildNodes(this, oDoc); 3.286 + this.parseError = 0; 3.287 + Sarissa.__setReadyState__(this, 1); 3.288 + try { 3.289 + if(this.async == false && _SARISSA_SYNC_NON_IMPLEMENTED) { 3.290 + var tmp = new XMLHttpRequest(); 3.291 + tmp.open("GET", sURI, false); 3.292 + tmp.send(null); 3.293 + Sarissa.__setReadyState__(this, 2); 3.294 + Sarissa.copyChildNodes(tmp.responseXML, this); 3.295 + Sarissa.__setReadyState__(this, 3); 3.296 + } 3.297 + else { 3.298 + this._sarissa_load(sURI); 3.299 + }; 3.300 + } 3.301 + catch (objException) { 3.302 + this.parseError = -1; 3.303 + } 3.304 + finally { 3.305 + if(this.async == false){ 3.306 + Sarissa.__handleLoad__(this); 3.307 + }; 3.308 + }; 3.309 + return oDoc; 3.310 + }; 3.311 + };//if(window.XMLDocument) 3.312 + 3.313 + /** 3.314 + * <p>Ensures the document was loaded correctly, otherwise sets the 3.315 + * parseError to -1 to indicate something went wrong. Internal use</p> 3.316 + * @private 3.317 + */ 3.318 + Sarissa.__handleLoad__ = function(oDoc){ 3.319 + if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror") 3.320 + oDoc.parseError = -1; 3.321 + Sarissa.__setReadyState__(oDoc, 4); 3.322 + }; 3.323 + 3.324 + /** 3.325 + * <p>Attached by an event handler to the load event. Internal use.</p> 3.326 + * @private 3.327 + */ 3.328 + _sarissa_XMLDocument_onload = function(){ 3.329 + Sarissa.__handleLoad__(this); 3.330 + }; 3.331 + 3.332 + /** 3.333 + * <p>Sets the readyState property of the given DOM Document object. 3.334 + * Internal use.</p> 3.335 + * @private 3.336 + * @argument oDoc the DOM Document object to fire the 3.337 + * readystatechange event 3.338 + * @argument iReadyState the number to change the readystate property to 3.339 + */ 3.340 + Sarissa.__setReadyState__ = function(oDoc, iReadyState){ 3.341 + oDoc.readyState = iReadyState; 3.342 + if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") 3.343 + oDoc.onreadystatechange(); 3.344 + }; 3.345 + /** 3.346 + * <p>Factory method to obtain a new DOM Document object</p> 3.347 + * @argument sUri the namespace of the root node (if any) 3.348 + * @argument sUri the local name of the root node (if any) 3.349 + * @returns a new DOM Document 3.350 + */ 3.351 + Sarissa.getDomDocument = function(sUri, sName){ 3.352 + var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null); 3.353 + oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false); 3.354 + return oDoc; 3.355 + }; 3.356 + };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT) 3.357 +}; 3.358 +//========================================== 3.359 +// Common stuff 3.360 +//========================================== 3.361 +if(!window.DOMParser){ 3.362 + /** 3.363 + * DOMParser is a utility class, used to construct DOMDocuments from XML strings 3.364 + * @constructor 3.365 + */ 3.366 + DOMParser = function() { 3.367 + }; 3.368 + /** 3.369 + * Construct a new DOM Document from the given XMLstring 3.370 + * @param sXml the given XML string 3.371 + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). 3.372 + * @return a new DOM Document from the given XML string 3.373 + */ 3.374 + DOMParser.prototype.parseFromString = function(sXml, contentType){ 3.375 + var doc = Sarissa.getDomDocument(); 3.376 + doc.loadXML(sXml); 3.377 + return doc; 3.378 + }; 3.379 + 3.380 +}; 3.381 + 3.382 +if(window.XMLHttpRequest){ 3.383 + Sarissa.IS_ENABLED_XMLHTTP = true; 3.384 +} 3.385 +else if(_SARISSA_IS_IE){ 3.386 + /** 3.387 + * Emulate XMLHttpRequest 3.388 + * @constructor 3.389 + */ 3.390 + XMLHttpRequest = function() { 3.391 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID); 3.392 + }; 3.393 + Sarissa.IS_ENABLED_XMLHTTP = true; 3.394 +}; 3.395 + 3.396 +if(!window.document.importNode && _SARISSA_IS_IE){ 3.397 + try{ 3.398 + /** 3.399 + * Implements importNode for the current window document in IE using innerHTML. 3.400 + * Testing showed that DOM was multiple times slower than innerHTML for this, 3.401 + * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML) 3.402 + * please gimme a call. 3.403 + * @param oNode the Node to import 3.404 + * @param bChildren whether to include the children of oNode 3.405 + * @returns the imported node for further use 3.406 + */ 3.407 + window.document.importNode = function(oNode, bChildren){ 3.408 + var importNode = document.createElement("div"); 3.409 + if(bChildren) 3.410 + importNode.innerHTML = Sarissa.serialize(oNode); 3.411 + else 3.412 + importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false)); 3.413 + return importNode.firstChild; 3.414 + }; 3.415 + }catch(e){}; 3.416 +}; 3.417 +if(!Sarissa.getParseErrorText){ 3.418 + /** 3.419 + * <p>Returns a human readable description of the parsing error. Usefull 3.420 + * for debugging. Tip: append the returned error string in a <pre> 3.421 + * element if you want to render it.</p> 3.422 + * <p>Many thanks to Christian Stocker for the initial patch.</p> 3.423 + * @argument oDoc The target DOM document 3.424 + * @returns The parsing error description of the target Document in 3.425 + * human readable form (preformated text) 3.426 + */ 3.427 + Sarissa.getParseErrorText = function (oDoc){ 3.428 + var parseErrorText = Sarissa.PARSED_OK; 3.429 + if(oDoc.parseError != 0){ 3.430 + /*moz*/ 3.431 + if(oDoc.documentElement.tagName == "parsererror"){ 3.432 + parseErrorText = oDoc.documentElement.firstChild.data; 3.433 + parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data; 3.434 + }/*konq*/ 3.435 + else if(oDoc.documentElement.tagName == "html"){ 3.436 + parseErrorText = Sarissa.getText(oDoc.documentElement.getElementsByTagName("h1")[0], false) + "\n"; 3.437 + parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("body")[0], false) + "\n"; 3.438 + parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false); 3.439 + }; 3.440 + }; 3.441 + return parseErrorText; 3.442 + }; 3.443 +}; 3.444 +Sarissa.getText = function(oNode, deep){ 3.445 + var s = ""; 3.446 + var nodes = oNode.childNodes; 3.447 + for(var i=0; i < nodes.length; i++){ 3.448 + var node = nodes[i]; 3.449 + var nodeType = node.nodeType; 3.450 + if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){ 3.451 + s += node.data; 3.452 + } 3.453 + else if(deep == true 3.454 + && (nodeType == Node.ELEMENT_NODE 3.455 + || nodeType == Node.DOCUMENT_NODE 3.456 + || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){ 3.457 + s += Sarissa.getText(node, true); 3.458 + }; 3.459 + }; 3.460 + return s; 3.461 +}; 3.462 +if(window.XMLSerializer){ 3.463 + /** 3.464 + * <p>Factory method to obtain the serialization of a DOM Node</p> 3.465 + * @returns the serialized Node as an XML string 3.466 + */ 3.467 + Sarissa.serialize = function(oDoc){ 3.468 + return (new XMLSerializer()).serializeToString(oDoc); 3.469 + }; 3.470 +}else{ 3.471 + if((Sarissa.getDomDocument("","foo", null)).xml){ 3.472 + // see non-IE version 3.473 + Sarissa.serialize = function(oDoc) { 3.474 + // TODO: check for HTML document and return innerHTML instead 3.475 + return oDoc.xml; 3.476 + }; 3.477 + /** 3.478 + * Utility class to serialize DOM Node objects to XML strings 3.479 + * @constructor 3.480 + */ 3.481 + XMLSerializer = function(){}; 3.482 + /** 3.483 + * Serialize the given DOM Node to an XML string 3.484 + * @param oNode the DOM Node to serialize 3.485 + */ 3.486 + XMLSerializer.prototype.serializeToString = function(oNode) { 3.487 + return oNode.xml; 3.488 + }; 3.489 + }; 3.490 +}; 3.491 + 3.492 +/** 3.493 + * strips tags from a markup string 3.494 + */ 3.495 +Sarissa.stripTags = function (s) { 3.496 + return s.replace(/<[^>]+>/g,""); 3.497 +}; 3.498 +/** 3.499 + * <p>Deletes all child nodes of the given node</p> 3.500 + * @argument oNode the Node to empty 3.501 + */ 3.502 +Sarissa.clearChildNodes = function(oNode) { 3.503 + while(oNode.hasChildNodes()){ 3.504 + oNode.removeChild(oNode.firstChild); 3.505 + }; 3.506 +}; 3.507 +/** 3.508 + * <p> Copies the childNodes of nodeFrom to nodeTo</p> 3.509 + * <p> <b>Note:</b> The second object's original content is deleted before 3.510 + * the copy operation, unless you supply a true third parameter</p> 3.511 + * @argument nodeFrom the Node to copy the childNodes from 3.512 + * @argument nodeTo the Node to copy the childNodes to 3.513 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false 3.514 + */ 3.515 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { 3.516 + if(!bPreserveExisting){ 3.517 + Sarissa.clearChildNodes(nodeTo); 3.518 + }; 3.519 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument; 3.520 + var nodes = nodeFrom.childNodes; 3.521 + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { 3.522 + for(var i=0;i < nodes.length;i++) { 3.523 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); 3.524 + }; 3.525 + } 3.526 + else{ 3.527 + for(var i=0;i < nodes.length;i++) { 3.528 + nodeTo.appendChild(nodes[i].cloneNode(true)); 3.529 + }; 3.530 + }; 3.531 +}; 3.532 + 3.533 +/** 3.534 + * <p> Moves the childNodes of nodeFrom to nodeTo</p> 3.535 + * <p> <b>Note:</b> The second object's original content is deleted before 3.536 + * the move operation, unless you supply a true third parameter</p> 3.537 + * @argument nodeFrom the Node to copy the childNodes from 3.538 + * @argument nodeTo the Node to copy the childNodes to 3.539 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false 3.540 + */ 3.541 +Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { 3.542 + if(!bPreserveExisting){ 3.543 + Sarissa.clearChildNodes(nodeTo); 3.544 + }; 3.545 + 3.546 + var nodes = nodeFrom.childNodes; 3.547 + // if within the same doc, just move, else copy and delete 3.548 + if(nodeFrom.ownerDocument == nodeTo.ownerDocument){ 3.549 + nodeTo.appendChild(nodes[i]); 3.550 + }else{ 3.551 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument; 3.552 + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { 3.553 + for(var i=0;i < nodes.length;i++) { 3.554 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); 3.555 + }; 3.556 + } 3.557 + else{ 3.558 + for(var i=0;i < nodes.length;i++) { 3.559 + nodeTo.appendChild(nodes[i].cloneNode(true)); 3.560 + }; 3.561 + }; 3.562 + Sarissa.clearChildNodes(nodeFrom); 3.563 + }; 3.564 + 3.565 +}; 3.566 + 3.567 +/** 3.568 + * <p>Serialize any object to an XML string. All properties are serialized using the property name 3.569 + * as the XML element name. Array elements are rendered as <code>array-item</code> elements, 3.570 + * using their index/key as the value of the <code>key</code> attribute.</p> 3.571 + * @argument anyObject the object to serialize 3.572 + * @argument objectName a name for that object 3.573 + * @return the XML serializationj of the given object as a string 3.574 + */ 3.575 +Sarissa.xmlize = function(anyObject, objectName, indentSpace){ 3.576 + indentSpace = indentSpace?indentSpace:''; 3.577 + var s = indentSpace + '<' + objectName + '>'; 3.578 + var isLeaf = false; 3.579 + if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String 3.580 + || anyObject instanceof Boolean || anyObject instanceof Date){ 3.581 + s += Sarissa.escape(""+anyObject); 3.582 + isLeaf = true; 3.583 + }else{ 3.584 + s += "\n"; 3.585 + var itemKey = ''; 3.586 + var isArrayItem = anyObject instanceof Array; 3.587 + for(var name in anyObject){ 3.588 + s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " "); 3.589 + }; 3.590 + s += indentSpace; 3.591 + }; 3.592 + return s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n"); 3.593 +}; 3.594 + 3.595 +/** 3.596 + * Escape the given string chacters that correspond to the five predefined XML entities 3.597 + * @param sXml the string to escape 3.598 + */ 3.599 +Sarissa.escape = function(sXml){ 3.600 + return sXml.replace(/&/g, "&") 3.601 + .replace(/</g, "<") 3.602 + .replace(/>/g, ">") 3.603 + .replace(/"/g, """) 3.604 + .replace(/'/g, "'"); 3.605 +}; 3.606 + 3.607 +/** 3.608 + * Unescape the given string. This turns the occurences of the predefined XML 3.609 + * entities to become the characters they represent correspond to the five predefined XML entities 3.610 + * @param sXml the string to unescape 3.611 + */ 3.612 +Sarissa.unescape = function(sXml){ 3.613 + return sXml.replace(/'/g,"'") 3.614 + .replace(/"/g,"\"") 3.615 + .replace(/>/g,">") 3.616 + .replace(/</g,"<") 3.617 + .replace(/&/g,"&"); 3.618 +}; 3.619 +// EOF
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_comments.xsl Fri Jun 01 23:17:45 2007 +0000 4.3 @@ -0,0 +1,41 @@ 4.4 +<?xml version="1.0" encoding="utf-8"?> 4.5 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 4.6 + version="1.0"> 4.7 + 4.8 + <!-- Add or process comment elements inside item elements. --> 4.9 + <!-- This transformation must happen after type elements have been populated. --> 4.10 + 4.11 + <xsl:template match="item"> 4.12 + <!-- Copy the element and its contents. --> 4.13 + <xsl:copy> 4.14 + <xsl:apply-templates select="@*"/> 4.15 + <!-- Ensure an options element. --> 4.16 + <xsl:call-template name="options"/> 4.17 + <xsl:apply-templates select="*[local-name() != 'options']"/> 4.18 + </xsl:copy> 4.19 + </xsl:template> 4.20 + 4.21 + <!-- Investigate options elements. --> 4.22 + 4.23 + <xsl:template name="options"> 4.24 + <!-- Make the element. --> 4.25 + <options> 4.26 + <!-- Only for certain element types... --> 4.27 + <xsl:if test="type/type-enum[@value='P' and @value-is-set]"> 4.28 + <!-- Add comments. --> 4.29 + <comment> 4.30 + <xsl:apply-templates select="options/comment/@value"/> 4.31 + </comment> 4.32 + </xsl:if> 4.33 + </options> 4.34 + </xsl:template> 4.35 + 4.36 + <!-- Replicate unknown elements. --> 4.37 + 4.38 + <xsl:template match="@*|*|node()"> 4.39 + <xsl:copy> 4.40 + <xsl:apply-templates select="@*|*|node()"/> 4.41 + </xsl:copy> 4.42 + </xsl:template> 4.43 + 4.44 +</xsl:stylesheet>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_multivalue_label_template.xhtml Fri Jun 01 23:17:45 2007 +0000 5.3 @@ -0,0 +1,62 @@ 5.4 +<?xml version="1.0" encoding="iso-8859-1"?> 5.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 5.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 5.7 +<html xmlns="http://www.w3.org/1999/xhtml" 5.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 5.9 +<head> 5.10 + <title>Example</title> 5.11 + <script type="text/javascript" src="scripts/sarissa.js"> </script> 5.12 + <script type="text/javascript" src="scripts/XSLForms.js"> </script> 5.13 +</head> 5.14 +<body template:element="structure"> 5.15 +<form action="" method="POST"> 5.16 + 5.17 +<!-- Template text between the start and the interesting part. --> 5.18 + 5.19 +<div template:element="item"> 5.20 + <p> 5.21 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 5.22 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 5.23 + </p> 5.24 + <p> 5.25 + Item type: 5.26 + <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple" 5.27 + onchange="requestUpdate( 5.28 + 'comments', 5.29 + '{template:list-attribute('type-enum', 'value')}', 5.30 + '{template:other-elements(../options)}', 5.31 + '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}', 5.32 + '/structure/item')"> 5.33 + <option template:multiple-choice-list-value="type-enum,value,selected,template:i18n(text())" value="..." /> 5.34 + </select> 5.35 + </p> 5.36 + <p template:element="options" template:id="comment-node" id="{template:this-element()}"> 5.37 + <span template:element="comment">Comment: 5.38 + <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"> 5.39 + Some comment 5.40 + </textarea> 5.41 + </span> 5.42 + </p> 5.43 + <p> 5.44 + Itself containing more items: 5.45 + </p> 5.46 + <p template:element="subitem"> 5.47 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 5.48 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 5.49 + </p> 5.50 + <p> 5.51 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 5.52 + </p> 5.53 +</div> 5.54 +<p> 5.55 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 5.56 +</p> 5.57 +<p> 5.58 + <input name="update" type="submit" value="Update" /> 5.59 +</p> 5.60 + 5.61 +<!-- Template text between the interesting part and the end. --> 5.62 + 5.63 +</form> 5.64 +</body> 5.65 +</html>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_multivalue_template.xhtml Fri Jun 01 23:17:45 2007 +0000 6.3 @@ -0,0 +1,62 @@ 6.4 +<?xml version="1.0" encoding="iso-8859-1"?> 6.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 6.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 6.7 +<html xmlns="http://www.w3.org/1999/xhtml" 6.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 6.9 +<head> 6.10 + <title>Example</title> 6.11 + <script type="text/javascript" src="scripts/sarissa.js"> </script> 6.12 + <script type="text/javascript" src="scripts/XSLForms.js"> </script> 6.13 +</head> 6.14 +<body template:element="structure"> 6.15 +<form action="" method="POST"> 6.16 + 6.17 +<!-- Template text between the start and the interesting part. --> 6.18 + 6.19 +<div template:element="item"> 6.20 + <p> 6.21 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 6.22 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 6.23 + </p> 6.24 + <p> 6.25 + Item type: 6.26 + <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple" 6.27 + onchange="requestUpdate( 6.28 + 'comments', 6.29 + '{template:list-attribute('type-enum', 'value')}', 6.30 + '{template:other-elements(../options)}', 6.31 + '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}', 6.32 + '/structure/item')"> 6.33 + <option template:multiple-choice-list-value="type-enum,value,selected" value="..." /> 6.34 + </select> 6.35 + </p> 6.36 + <p template:element="options" template:id="comment-node" id="{template:this-element()}"> 6.37 + <span template:element="comment">Comment: 6.38 + <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"> 6.39 + Some comment 6.40 + </textarea> 6.41 + </span> 6.42 + </p> 6.43 + <p> 6.44 + Itself containing more items: 6.45 + </p> 6.46 + <p template:element="subitem"> 6.47 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 6.48 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 6.49 + </p> 6.50 + <p> 6.51 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 6.52 + </p> 6.53 +</div> 6.54 +<p> 6.55 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 6.56 +</p> 6.57 +<p> 6.58 + <input name="update" type="submit" value="Update" /> 6.59 +</p> 6.60 + 6.61 +<!-- Template text between the interesting part and the end. --> 6.62 + 6.63 +</form> 6.64 +</body> 6.65 +</html>
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_template.xhtml Fri Jun 01 23:17:45 2007 +0000 7.3 @@ -0,0 +1,44 @@ 7.4 +<?xml version="1.0" encoding="iso-8859-1"?> 7.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 7.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 7.7 +<html xmlns="http://www.w3.org/1999/xhtml" 7.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 7.9 +<head> 7.10 + <title>Example</title> 7.11 +</head> 7.12 +<body template:element="structure"> 7.13 +<form action="" method="POST"> 7.14 + 7.15 +<!-- Template text between the start and the interesting part. --> 7.16 + 7.17 +<div template:element="item"> 7.18 + <p> 7.19 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 7.20 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 7.21 + </p> 7.22 + <p> 7.23 + Item type: 7.24 + <select template:multiple-choice-field="type,value" name="..."> 7.25 + <option template:multiple-choice-value="type-enum,value,selected" value="..." /> 7.26 + </select> 7.27 + </p> 7.28 + <p> 7.29 + Itself containing more items: 7.30 + </p> 7.31 + <p template:element="subitem"> 7.32 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 7.33 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 7.34 + </p> 7.35 + <p> 7.36 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 7.37 + </p> 7.38 +</div> 7.39 +<p> 7.40 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 7.41 +</p> 7.42 + 7.43 +<!-- Template text between the interesting part and the end. --> 7.44 + 7.45 +</form> 7.46 +</body> 7.47 +</html>
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_types.xml Fri Jun 01 23:17:45 2007 +0000 8.3 @@ -0,0 +1,7 @@ 8.4 +<?xml version="1.0"?> 8.5 +<type> 8.6 + <type-enum value="(Not selected)"/> 8.7 + <type-enum value="Important"/> 8.8 + <type-enum value="Not important"/> 8.9 + <type-enum value="Personal"/> 8.10 +</type>
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/structure_types_label.xml Fri Jun 01 23:17:45 2007 +0000 9.3 @@ -0,0 +1,7 @@ 9.4 +<?xml version="1.0"?> 9.5 +<type> 9.6 + <type-enum value="0">(Not selected)</type-enum> 9.7 + <type-enum value="I">Important</type-enum> 9.8 + <type-enum value="N">Not important</type-enum> 9.9 + <type-enum value="P">Personal</type-enum> 9.10 +</type>
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/examples/Common/VerySimpleWithLogin/Resources/translations.xml Fri Jun 01 23:17:45 2007 +0000 10.3 @@ -0,0 +1,15 @@ 10.4 +<?xml version="1.0" encoding="iso-8859-1"?> 10.5 +<translations> 10.6 + <locale> 10.7 + <code value="en"/> 10.8 + <code value="en_GB"/> 10.9 + </locale> 10.10 + <locale> 10.11 + <code value="nb"/> 10.12 + <code value="nb_NO"/> 10.13 + <translation value="(Not selected)">(Ikke valgt)</translation> 10.14 + <translation value="Important">Viktig</translation> 10.15 + <translation value="Not important">Ikke viktig</translation> 10.16 + <translation value="Personal">Personlig</translation> 10.17 + </locale> 10.18 +</translations>
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/examples/Common/VerySimpleWithLogin/__init__.py Fri Jun 01 23:17:45 2007 +0000 11.3 @@ -0,0 +1,171 @@ 11.4 +#!/usr/bin/env python 11.5 + 11.6 +"A very simple example application." 11.7 + 11.8 +import WebStack.Generic 11.9 +import XSLForms.Resources.WebResources 11.10 +import XSLForms.Utils 11.11 +import os 11.12 + 11.13 +# Site map imports. 11.14 + 11.15 +from WebStack.Resources.ResourceMap import MapResource 11.16 +from WebStack.Resources.Selectors import EncodingSelector, PathSelector 11.17 +from WebStack.Resources.Static import DirectoryResource 11.18 +from WebStack.Resources.Login import LoginAuthenticator 11.19 +import XSLForms.Resources.Login 11.20 + 11.21 +# Configuration settings. 11.22 + 11.23 +encoding = "utf-8" 11.24 + 11.25 +# Resource classes. 11.26 + 11.27 +class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource): 11.28 + 11.29 + "A very simple resource providing a hierarchy of editable fields." 11.30 + 11.31 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 11.32 + template_resources = { 11.33 + #"structure" : ("structure_template.xhtml", "structure_output.xsl") 11.34 + #"structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl") 11.35 + "structure" : ("structure_multivalue_label_template.xhtml", "structure_output.xsl") 11.36 + } 11.37 + init_resources = { 11.38 + #"structure" : ("structure_template.xhtml", "structure_input.xsl") 11.39 + #"structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl") 11.40 + "structure" : ("structure_multivalue_label_template.xhtml", "structure_input.xsl") 11.41 + } 11.42 + transform_resources = { 11.43 + "comments" : ["structure_comments.xsl"] 11.44 + } 11.45 + document_resources = { 11.46 + #"types" : "structure_types.xml" 11.47 + "types" : "structure_types_label.xml", 11.48 + "translations" : "translations.xml" 11.49 + } 11.50 + in_page_resources = { 11.51 + "comments" : ("structure", "structure_output_comments.xsl", "comment-node") 11.52 + } 11.53 + 11.54 + def respond_to_form(self, trans, form): 11.55 + 11.56 + """ 11.57 + Respond to a request having the given transaction 'trans' and the given 11.58 + 'form' information. 11.59 + """ 11.60 + 11.61 + in_page_resource = self.get_in_page_resource(trans) 11.62 + parameters = form.get_parameters() 11.63 + documents = form.get_documents() 11.64 + 11.65 + # Ensure the presence of a document. 11.66 + 11.67 + if documents.has_key("structure"): 11.68 + structure = documents["structure"] 11.69 + else: 11.70 + structure = form.new_instance("structure") 11.71 + 11.72 + # Add and remove elements according to the selectors found. 11.73 + 11.74 + selectors = form.get_selectors() 11.75 + XSLForms.Utils.remove_elements(selectors.get("remove2")) 11.76 + XSLForms.Utils.add_elements(selectors.get("add2"), "subitem") 11.77 + XSLForms.Utils.remove_elements(selectors.get("remove")) 11.78 + XSLForms.Utils.add_elements(selectors.get("add"), "item") 11.79 + 11.80 + # Initialise the document, adding enumerations/ranges. 11.81 + 11.82 + structure_xsl = self.prepare_initialiser("structure") 11.83 + types_xml = self.prepare_document("types") 11.84 + structure = self.get_result([structure_xsl], structure, references={"type" : types_xml}) 11.85 + 11.86 + # Add the comments. 11.87 + 11.88 + comments_xsl_list = self.prepare_transform("comments") 11.89 + structure = self.get_result(comments_xsl_list, structure) 11.90 + 11.91 + # Start the response. 11.92 + 11.93 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding)) 11.94 + 11.95 + # Ensure that an output stylesheet exists. 11.96 + 11.97 + if in_page_resource in self.in_page_resources.keys(): 11.98 + trans_xsl = self.prepare_fragment(in_page_resource) 11.99 + stylesheet_parameters = self.prepare_parameters(parameters) 11.100 + else: 11.101 + trans_xsl = self.prepare_output("structure") 11.102 + stylesheet_parameters = {} 11.103 + 11.104 + # Complete the response. 11.105 + 11.106 + try: 11.107 + stylesheet_parameters["locale"] = trans.get_content_languages()[0] 11.108 + except IndexError: 11.109 + pass 11.110 + self.send_output(trans, [trans_xsl], structure, stylesheet_parameters, 11.111 + references={"translations" : self.prepare_document("translations")}) 11.112 + 11.113 +class LoginResource(XSLForms.Resources.Login.LoginResource): 11.114 + 11.115 + "Special login screen for this application." 11.116 + 11.117 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 11.118 + template_resources = { 11.119 + "login" : ("login_template.xhtml", "login_output.xsl"), 11.120 + } 11.121 + 11.122 +# Site map initialisation. 11.123 + 11.124 +def get_site(host): 11.125 + 11.126 + "Return a simple Web site resource." 11.127 + 11.128 + # Authentication objects. 11.129 + 11.130 + secret_key="this_must_be_secret" 11.131 + credentials = [ 11.132 + ("badger", "123"), 11.133 + ("vole", "abc") 11.134 + ] 11.135 + authenticator = LoginAuthenticator(secret_key, credentials) 11.136 + login_redirect_authenticator = LoginRedirectAuthenticator(secret_key) 11.137 + 11.138 + # Get the main resource and the directory used by the application. 11.139 + 11.140 + very_simple_resource = VerySimpleResource() 11.141 + directory = very_simple_resource.resource_dir 11.142 + 11.143 + # Get some login resources. 11.144 + 11.145 + login_redirect_resource = XSLForms.Resources.Login.LoginRedirectResource(secret_key) 11.146 + login_resource = LoginResource( 11.147 + host, 11.148 + resource=very_simple_resource, 11.149 + authenticator=login_redirect_authenticator 11.150 + ) 11.151 + 11.152 + # Make a simple Web site. 11.153 + 11.154 + resource = MapResource({ 11.155 + # Static resources: 11.156 + "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}), 11.157 + # Login resource: 11.158 + "login" : login_resource, 11.159 + # Main page and in-page resources: 11.160 + # (Now protected!) 11.161 + None : login_redirect_resource 11.162 + }) 11.163 + 11.164 + # Wrap the resource up with information about the application root. 11.165 + 11.166 + return EncodingSelector(PathSelector(resource), encoding) 11.167 + 11.168 +# Resource preparation ahead of time - useful for making installations. 11.169 + 11.170 +def prepare_resources(): 11.171 + for cls in [VerySimpleResource]: 11.172 + XSLForms.Resources.WebResources.prepare_resources(cls) 11.173 + 11.174 +# vim: tabstop=4 expandtab shiftwidth=4