1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/examples/BaseHTTPRequestHandler/VerySimpleWithOpenIDApp.py Sun Feb 03 20:05:15 2008 +0000 1.3 @@ -0,0 +1,18 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy 1.7 +import VerySimpleWithOpenID 1.8 + 1.9 +# Get a simple Web site. 1.10 + 1.11 +host = "http://localhost:8080" # or an absolute URL (without path) 1.12 +secret_key = "this_must_be_secret" 1.13 + 1.14 +resource = VerySimpleWithOpenID.get_site(host, secret_key) 1.15 + 1.16 +# Special magic incantation. 1.17 + 1.18 +print "Serving..." 1.19 +deploy(resource, handle_errors=0) 1.20 + 1.21 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/examples/Common/OpenIDLogin/__init__.py Sun Feb 03 20:04:44 2008 +0000 2.2 +++ b/examples/Common/OpenIDLogin/__init__.py Sun Feb 03 20:05:15 2008 +0000 2.3 @@ -1,4 +1,5 @@ 2.4 #!/usr/bin/env python 2.5 +# -*- coding: iso-8859-1 -*- 2.6 2.7 "An OpenID login provider." 2.8 2.9 @@ -38,7 +39,8 @@ 2.10 2.11 credentials = [ 2.12 ((host + "/badger", "badger"), "abc"), 2.13 - ((host + "/vole", "vole"), "xyz") 2.14 + ((host + "/vole", "vole"), "xyz"), 2.15 + ((host + u"/זרו", u"זרו"), u"ֶ״ֵ") 2.16 ] 2.17 login_authenticator = Authenticator(credentials) 2.18 2.19 @@ -66,6 +68,19 @@ 2.20 </body> 2.21 </html> 2.22 """ % (host, host), ContentType("text/html")), 2.23 + u"זרו" : 2.24 + StringResource(u""" 2.25 + <html> 2.26 + <head> 2.27 + <link rel="openid2.provider openid.server" href="%s/login" /> 2.28 + <link rel="openid2.local_id openid.delegate" href="%s/זרו" /> 2.29 + <title>Home Page for זרו</title> 2.30 + </head> 2.31 + <body> 2.32 + <p>Home page for the OpenID authenticated user, <code>זרו</code>.</p> 2.33 + </body> 2.34 + </html> 2.35 + """ % (host, host), ContentType("text/html", "iso-8859-1")), 2.36 "vole" : 2.37 StringResource(""" 2.38 <html>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/initiation_success_template.xhtml Sun Feb 03 20:05:15 2008 +0000 3.3 @@ -0,0 +1,23 @@ 3.4 +<?xml version="1.0" encoding="iso-8859-1"?> 3.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 3.7 +<html xmlns="http://www.w3.org/1999/xhtml" 3.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 3.9 +<head> 3.10 + <title>Authenticate via OpenID</title> 3.11 +</head> 3.12 + 3.13 +<body template:element="success"> 3.14 +<h1>Authenticate via OpenID</h1> 3.15 + 3.16 + <form action="{@provider}" method="POST" name="openid_redirect"> 3.17 + <input name="openid.ns" type="hidden" value="{@ns}" /> 3.18 + <input name="openid.mode" type="hidden" value="{@mode}" /> 3.19 + <input name="openid.return_to" type="hidden" value="{@return_to}" /> 3.20 + <input name="openid.claimed_id" type="hidden" value="{@claimed_id}" /> 3.21 + <input name="openid.identity" type="hidden" value="{@identity}" /> 3.22 + <p>Please proceed to the OpenID provider: <input name="proceed" type="submit" value="Proceed!" /></p> 3.23 + </form> 3.24 + 3.25 +</body> 3.26 +</html>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/initiation_template.xhtml Sun Feb 03 20:05:15 2008 +0000 4.3 @@ -0,0 +1,31 @@ 4.4 +<?xml version="1.0" encoding="iso-8859-1"?> 4.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 4.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4.7 +<html xmlns="http://www.w3.org/1999/xhtml" 4.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 4.9 +<head> 4.10 + <title>Authenticate via OpenID</title> 4.11 +</head> 4.12 + 4.13 +<body template:element="initiation"> 4.14 +<h1>Authenticate via OpenID</h1> 4.15 + 4.16 +<form method="post" name="openid_identifier"> 4.17 + <table cellspacing="0" cellpadding="5" id="initiation-info"> 4.18 + <tbody> 4.19 + <tr> 4.20 + <th>OpenID Identifier (URL)</th> 4.21 + <td><input type="text" template:attribute-field="identity" name="..." value="..." size="20"/></td> 4.22 + </tr> 4.23 + <tr> 4.24 + <td colspan="2"> 4.25 + <input type="submit" value="Login" name="initiate" /> 4.26 + </td> 4.27 + </tr> 4.28 + </tbody> 4.29 + </table> 4.30 + <input type="hidden" template:attribute-field="app" name="..." value="..."/> 4.31 +</form> 4.32 + 4.33 +</body> 4.34 +</html>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/login_template.xhtml Sun Feb 03 20:05:15 2008 +0000 5.3 @@ -0,0 +1,46 @@ 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>Login</title> 5.11 +</head> 5.12 + 5.13 +<body template:element="login"> 5.14 +<h1>Login</h1> 5.15 + 5.16 +<form method="post"> 5.17 + <table cellspacing="0" cellpadding="5" id="login-info"> 5.18 + <thead> 5.19 + <tr> 5.20 + <th class="heading" colspan="2">Login</th> 5.21 + </tr> 5.22 + </thead> 5.23 + <tbody> 5.24 + <tr template:element="error" template:init="no"> 5.25 + <th>Error</th> 5.26 + <td><span template:attribute-area="message,replace">error message</span></td> 5.27 + </tr> 5.28 + <tr> 5.29 + <th>Username</th> 5.30 + <td><input type="text" template:attribute-field="username" name="..." value="..." size="20"/></td> 5.31 + </tr> 5.32 + <tr> 5.33 + <th>Password</th> 5.34 + <td><input type="password" template:attribute-field="password" name="..." value="..." size="20"/></td> 5.35 + </tr> 5.36 + <tr> 5.37 + <td colspan="2"> 5.38 + <input type="submit" value="Log in!" name="login" /> 5.39 + </td> 5.40 + </tr> 5.41 + </tbody> 5.42 + </table> 5.43 + <input type="hidden" template:attribute-field="return_to" name="..." value="..."/> 5.44 + <input type="hidden" template:attribute-field="claimed_id" name="..." value="..."/> 5.45 + <input type="hidden" template:attribute-field="identity" name="..." value="..."/> 5.46 +</form> 5.47 + 5.48 +</body> 5.49 +</html>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/scripts/XSLForms.js Sun Feb 03 20:05:15 2008 +0000 6.3 @@ -0,0 +1,178 @@ 6.4 +// Area update functions. 6.5 + 6.6 +function requestUpdateArea(url, sourceAreasStr, targetName, targetAreasStr, elementPath) { 6.7 + 6.8 + var fieldNames = new Array(); 6.9 + var targetFieldNames = new Array(); 6.10 + 6.11 + for (var i = 0; i < document.forms.length; i++) { 6.12 + var form = document.forms[i]; 6.13 + for (var j = 0; j < form.elements.length; j++) { 6.14 + var fieldName = form.elements[j].name; 6.15 + checkField(fieldName, sourceAreasStr, fieldNames); 6.16 + checkField(fieldName, targetAreasStr, targetFieldNames); 6.17 + } 6.18 + } 6.19 + 6.20 + return _requestUpdate(url, fieldNames, targetName, targetFieldNames, elementPath); 6.21 +} 6.22 + 6.23 +// Field list update functions. 6.24 + 6.25 +function requestUpdate(url, fieldNamesStr, targetName, targetFieldNamesStr, elementPath) { 6.26 + 6.27 + return _requestUpdate(url, fieldNamesStr.split(","), targetName, targetFieldNamesStr.split(","), elementPath); 6.28 +} 6.29 + 6.30 +// Internal functions. 6.31 + 6.32 +function checkField(fieldName, areasStr, areaFieldNames) { 6.33 + 6.34 + // Process each area name. 6.35 + 6.36 + var areaArray = areasStr.split(","); 6.37 + for (var i = 0; i < areaArray.length; i++) { 6.38 + var areaName = areaArray[i]; 6.39 + 6.40 + // Skip empty area names (arising through empty elements in the CSV list). 6.41 + 6.42 + if (areaName == "") { 6.43 + continue; 6.44 + } 6.45 + 6.46 + if (fieldName.indexOf(areaName) == 0) { 6.47 + areaFieldNames.push(fieldName); 6.48 + } 6.49 + } 6.50 +} 6.51 + 6.52 +function _requestUpdate(url, fieldNames, targetName, targetFieldNames, elementPath) { 6.53 + 6.54 + // Note that XMLHttpRequest access may be denied if Mozilla believes that 6.55 + // this resource's URL and the supplied URL are different. 6.56 + 6.57 + var xmlhttp = new XMLHttpRequest(); 6.58 + xmlhttp.open("POST", url, false); 6.59 + 6.60 + // Add the element path specification. 6.61 + 6.62 + var requestBody = ("element-path=" + elementPath); 6.63 + 6.64 + // Send the controlling field value. 6.65 + 6.66 + requestBody += addFields(fieldNames, false); 6.67 + requestBody += addFields(targetFieldNames, true); 6.68 + 6.69 + // Load the remote document with the given parameters sent as text in the request body. 6.70 + 6.71 + xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 6.72 + xmlhttp.send(requestBody); 6.73 + 6.74 + // Parse the result document. 6.75 + 6.76 + var newDocument = Sarissa.getDomDocument(); 6.77 + newDocument = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml"); 6.78 + 6.79 + // Find the definition of the affected field in the result document. 6.80 + 6.81 + var newElement = newDocument.getElementById(targetName); 6.82 + var targetElement = document.getElementById(targetName); 6.83 + 6.84 + // Insert the new definition into the current document. 6.85 + 6.86 + if (newElement != null && targetElement != null) { 6.87 + var importedElement = document.importNode(newElement, true); 6.88 + targetElement.parentNode.replaceChild(importedElement, targetElement); 6.89 + //importedElement.setAttribute("style", "background-color:red;"); 6.90 + } 6.91 + 6.92 + // NOTE: Test Konqueror bug. 6.93 + 6.94 + //showMismatch(targetFieldNames); 6.95 + 6.96 + return false; 6.97 +} 6.98 + 6.99 +function addFields(fieldNames, disable) { 6.100 + 6.101 + var requestBody = ""; 6.102 + 6.103 + // Process each target field name. 6.104 + // Add the values of the dependent fields. 6.105 + 6.106 + for (var i = 0; i < fieldNames.length; i++) { 6.107 + var fieldName = fieldNames[i]; 6.108 + 6.109 + // Skip empty field names (arising through empty elements in the CSV list). 6.110 + 6.111 + if (fieldName == "") { 6.112 + continue; 6.113 + } 6.114 + 6.115 + // Find the values of the target field. 6.116 + 6.117 + var fieldValue; 6.118 + var fieldNodes = document.getElementsByName(fieldName); 6.119 + for (var v = 0; v < fieldNodes.length; v++) { 6.120 + 6.121 + // Test for different field types. 6.122 + 6.123 + if (fieldNodes[v].options) { 6.124 + for (var opt = 0; opt < fieldNodes[v].options.length; opt++) { 6.125 + if (fieldNodes[v].options[opt].selected) { 6.126 + fieldValue = fieldNodes[v].options[opt].value; 6.127 + requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue)); 6.128 + } 6.129 + } 6.130 + } else if (fieldNodes[v].type != 'checkbox' && fieldNodes[v].type != 'radio' || fieldNodes[v].checked) { 6.131 + fieldValue = fieldNodes[v].value; 6.132 + requestBody += ("&" + encodeURIComponent(fieldName) + "=" + encodeURIComponent(fieldValue)); 6.133 + } 6.134 + } 6.135 + 6.136 + // NOTE: Konqueror hack: disable fields. 6.137 + 6.138 + if (disable) { 6.139 + disableFields(fieldName); 6.140 + } 6.141 + } 6.142 + 6.143 + return requestBody; 6.144 +} 6.145 + 6.146 +function disableFields(targetFieldName) { 6.147 + 6.148 + for (var i = 0; i < document.forms.length; i++) { 6.149 + var form = document.forms[i]; 6.150 + for (var j = 0; j < form.elements.length; j++) { 6.151 + if (form.elements[j].name == targetFieldName) { 6.152 + form.elements[j].name = ""; 6.153 + } 6.154 + } 6.155 + } 6.156 +} 6.157 + 6.158 +function showMismatch(targetFieldNameArray) { 6.159 + 6.160 + // Show how the number of field elements with a given name can be different 6.161 + // from the number known to the DOM Level 0 part of the API. 6.162 + 6.163 + for (var h = 0; h < targetFieldNameArray.length; h++) { 6.164 + var targetFieldName = targetFieldNameArray[h]; 6.165 + var targetFieldNodes = document.getElementsByName(targetFieldName); 6.166 + alert("Nodes for " + targetFieldName + ": " + targetFieldNodes.length); 6.167 + 6.168 + var count = 0; 6.169 + for (var i = 0; i < document.forms.length; i++) { 6.170 + var form = document.forms[i]; 6.171 + for (var j = 0; j < form.elements.length; j++) { 6.172 + if (form.elements[j].name == targetFieldName) { 6.173 + count++; 6.174 + } 6.175 + } 6.176 + } 6.177 + alert("Fields for " + targetFieldName + ": " + count); 6.178 + } 6.179 +} 6.180 + 6.181 +// vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/scripts/sarissa.js Sun Feb 03 20:05:15 2008 +0000 7.3 @@ -0,0 +1,688 @@ 7.4 +/** 7.5 + * ==================================================================== 7.6 + * About 7.7 + * ==================================================================== 7.8 + * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs. 7.9 + * The library supports Gecko based browsers like Mozilla and Firefox, 7.10 + * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera 7.11 + * @version ${project.version} 7.12 + * @author: @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net 7.13 + * 7.14 + * ==================================================================== 7.15 + * Licence 7.16 + * ==================================================================== 7.17 + * Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher, 7.18 + * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher 7.19 + * (see <a href="asl.txt">asl.txt</a>). This means you can choose one of the three and use that if you like. If 7.20 + * you make modifications under the ASL, i would appreciate it if you submitted those. 7.21 + * In case your copy of Sarissa does not include the license texts, you may find 7.22 + * them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and 7.23 + * <a href="http://www.apache.org">http://www.apache.org</a>. 7.24 + * 7.25 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 7.26 + * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 7.27 + * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE 7.28 + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 7.29 + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 7.30 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 7.31 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 7.32 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 7.33 + */ 7.34 +/** 7.35 + * <p>Sarissa is a utility class. Provides "static" methods for DOMDocument, 7.36 + * DOM Node serialization to XML strings and other utility goodies.</p> 7.37 + * @constructor 7.38 + */ 7.39 +function Sarissa(){}; 7.40 +Sarissa.VERSION = "${project.version}"; 7.41 +Sarissa.PARSED_OK = "Document contains no parsing errors"; 7.42 +Sarissa.PARSED_EMPTY = "Document is empty"; 7.43 +Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error"; 7.44 +Sarissa.IS_ENABLED_TRANSFORM_NODE = false; 7.45 +var _sarissa_iNsCounter = 0; 7.46 +var _SARISSA_IEPREFIX4XSLPARAM = ""; 7.47 +var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true; 7.48 +var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument; 7.49 +var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature; 7.50 +var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE; 7.51 +var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("safari") != -1 || navigator.userAgent.toLowerCase().indexOf("konqueror") != -1; 7.52 +var _SARISSA_IS_SAFARI_OLD = _SARISSA_IS_SAFARI && parseInt((navigator.userAgent.match(/AppleWebKit\/(\d+)/)||{})[1]) < 420; 7.53 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1; 7.54 +var _SARISSA_IS_OPERA = navigator.userAgent.toLowerCase().indexOf("opera") != -1; 7.55 +if(!window.Node || !Node.ELEMENT_NODE){ 7.56 + 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}; 7.57 +}; 7.58 + 7.59 +//This breaks for(x in o) loops in the old Safari 7.60 +if(_SARISSA_IS_SAFARI_OLD){ 7.61 + HTMLHtmlElement = document.createElement("html").constructor; 7.62 + Node = HTMLElement = {}; 7.63 + HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__; 7.64 + HTMLDocument = Document = document.constructor; 7.65 + var x = new DOMParser(); 7.66 + XMLDocument = x.constructor; 7.67 + Element = x.parseFromString("<Single />", "text/xml").documentElement.constructor; 7.68 + x = null; 7.69 +} 7.70 +if(typeof XMLDocument == "undefined" && typeof Document !="undefined"){ XMLDocument = Document; } 7.71 + 7.72 +// IE initialization 7.73 +if(_SARISSA_IS_IE){ 7.74 + // for XSLT parameter names, prefix needed by IE 7.75 + _SARISSA_IEPREFIX4XSLPARAM = "xsl:"; 7.76 + // used to store the most recent ProgID available out of the above 7.77 + var _SARISSA_DOM_PROGID = ""; 7.78 + var _SARISSA_XMLHTTP_PROGID = ""; 7.79 + var _SARISSA_DOM_XMLWRITER = ""; 7.80 + /** 7.81 + * Called when the Sarissa_xx.js file is parsed, to pick most recent 7.82 + * ProgIDs for IE, then gets destroyed. 7.83 + * @private 7.84 + * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object 7.85 + * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled 7.86 + */ 7.87 + Sarissa.pickRecentProgID = function (idList){ 7.88 + // found progID flag 7.89 + var bFound = false, e; 7.90 + for(var i=0; i < idList.length && !bFound; i++){ 7.91 + try{ 7.92 + var oDoc = new ActiveXObject(idList[i]); 7.93 + var o2Store = idList[i]; 7.94 + bFound = true; 7.95 + }catch (objException){ 7.96 + // trap; try next progID 7.97 + e = objException; 7.98 + }; 7.99 + }; 7.100 + if (!bFound) { 7.101 + throw "Could not retrieve a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")"; 7.102 + }; 7.103 + idList = null; 7.104 + return o2Store; 7.105 + }; 7.106 + // pick best available MSXML progIDs 7.107 + _SARISSA_DOM_PROGID = null; 7.108 + _SARISSA_THREADEDDOM_PROGID = null; 7.109 + _SARISSA_XSLTEMPLATE_PROGID = null; 7.110 + _SARISSA_XMLHTTP_PROGID = null; 7.111 + if(!window.XMLHttpRequest){ 7.112 + /** 7.113 + * Emulate XMLHttpRequest 7.114 + * @constructor 7.115 + */ 7.116 + XMLHttpRequest = function() { 7.117 + if(!_SARISSA_XMLHTTP_PROGID){ 7.118 + _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]); 7.119 + }; 7.120 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID); 7.121 + }; 7.122 + }; 7.123 + // we dont need this anymore 7.124 + //============================================ 7.125 + // Factory methods (IE) 7.126 + //============================================ 7.127 + // see non-IE version 7.128 + Sarissa.getDomDocument = function(sUri, sName){ 7.129 + if(!_SARISSA_DOM_PROGID){ 7.130 + _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]); 7.131 + }; 7.132 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID); 7.133 + // if a root tag name was provided, we need to load it in the DOM object 7.134 + if (sName){ 7.135 + // create an artifical namespace prefix 7.136 + // or reuse existing prefix if applicable 7.137 + var prefix = ""; 7.138 + if(sUri){ 7.139 + if(sName.indexOf(":") > 1){ 7.140 + prefix = sName.substring(0, sName.indexOf(":")); 7.141 + sName = sName.substring(sName.indexOf(":")+1); 7.142 + }else{ 7.143 + prefix = "a" + (_sarissa_iNsCounter++); 7.144 + }; 7.145 + }; 7.146 + // use namespaces if a namespace URI exists 7.147 + if(sUri){ 7.148 + oDoc.loadXML('<' + prefix+':'+sName + " xmlns:" + prefix + "=\"" + sUri + "\"" + " />"); 7.149 + } else { 7.150 + oDoc.loadXML('<' + sName + " />"); 7.151 + }; 7.152 + }; 7.153 + return oDoc; 7.154 + }; 7.155 + // see non-IE version 7.156 + Sarissa.getParseErrorText = function (oDoc) { 7.157 + var parseErrorText = Sarissa.PARSED_OK; 7.158 + if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.parseError.errorCode != 0){ 7.159 + parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason + 7.160 + "\nLocation: " + oDoc.parseError.url + 7.161 + "\nLine Number " + oDoc.parseError.line + ", Column " + 7.162 + oDoc.parseError.linepos + 7.163 + ":\n" + oDoc.parseError.srcText + 7.164 + "\n"; 7.165 + for(var i = 0; i < oDoc.parseError.linepos;i++){ 7.166 + parseErrorText += "-"; 7.167 + }; 7.168 + parseErrorText += "^\n"; 7.169 + } 7.170 + else if(oDoc.documentElement == null){ 7.171 + parseErrorText = Sarissa.PARSED_EMPTY; 7.172 + }; 7.173 + return parseErrorText; 7.174 + }; 7.175 + // see non-IE version 7.176 + Sarissa.setXpathNamespaces = function(oDoc, sNsSet) { 7.177 + oDoc.setProperty("SelectionLanguage", "XPath"); 7.178 + oDoc.setProperty("SelectionNamespaces", sNsSet); 7.179 + }; 7.180 + /** 7.181 + * Basic implementation of Mozilla's XSLTProcessor for IE. 7.182 + * Reuses the same XSLT stylesheet for multiple transforms 7.183 + * @constructor 7.184 + */ 7.185 + XSLTProcessor = function(){ 7.186 + if(!_SARISSA_XSLTEMPLATE_PROGID){ 7.187 + _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID(["Msxml2.XSLTemplate.6.0", "MSXML2.XSLTemplate.3.0"]); 7.188 + }; 7.189 + this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID); 7.190 + this.processor = null; 7.191 + }; 7.192 + /** 7.193 + * Imports the given XSLT DOM and compiles it to a reusable transform 7.194 + * <b>Note:</b> If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those 7.195 + * @argument xslDoc The XSLT DOMDocument to import 7.196 + */ 7.197 + XSLTProcessor.prototype.importStylesheet = function(xslDoc){ 7.198 + if(!_SARISSA_THREADEDDOM_PROGID){ 7.199 + _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID(["MSXML2.FreeThreadedDOMDocument.6.0", "MSXML2.FreeThreadedDOMDocument.3.0"]); 7.200 + }; 7.201 + xslDoc.setProperty("SelectionLanguage", "XPath"); 7.202 + xslDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"); 7.203 + // convert stylesheet to free threaded 7.204 + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID); 7.205 + // make included/imported stylesheets work if exist and xsl was originally loaded from url 7.206 + try{ 7.207 + converted.resolveExternals = true; 7.208 + converted.setProperty("AllowDocumentFunction", true); 7.209 + } 7.210 + catch(e){ 7.211 + // Ignore. "AllowDocumentFunction" is only supported in MSXML 3.0 SP4 and later. 7.212 + }; 7.213 + if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() = 'import' or local-name() = 'include']") != null){ 7.214 + converted.async = false; 7.215 + converted.load(xslDoc.url); 7.216 + } else { 7.217 + converted.loadXML(xslDoc.xml); 7.218 + }; 7.219 + converted.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"); 7.220 + var output = converted.selectSingleNode("//xsl:output"); 7.221 + this.outputMethod = output ? output.getAttribute("method") : "html"; 7.222 + this.template.stylesheet = converted; 7.223 + this.processor = this.template.createProcessor(); 7.224 + // for getParameter and clearParameters 7.225 + this.paramsSet = []; 7.226 + }; 7.227 + 7.228 + /** 7.229 + * Transform the given XML DOM and return the transformation result as a new DOM document 7.230 + * @argument sourceDoc The XML DOMDocument to transform 7.231 + * @return The transformation result as a DOM Document 7.232 + */ 7.233 + XSLTProcessor.prototype.transformToDocument = function(sourceDoc){ 7.234 + // fix for bug 1549749 7.235 + if(_SARISSA_THREADEDDOM_PROGID){ 7.236 + this.processor.input=sourceDoc; 7.237 + var outDoc=new ActiveXObject(_SARISSA_DOM_PROGID); 7.238 + this.processor.output=outDoc; 7.239 + this.processor.transform(); 7.240 + return outDoc; 7.241 + } 7.242 + else{ 7.243 + if(!_SARISSA_DOM_XMLWRITER){ 7.244 + _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID(["Msxml2.MXXMLWriter.6.0", "Msxml2.MXXMLWriter.3.0", "MSXML2.MXXMLWriter", "MSXML.MXXMLWriter", "Microsoft.XMLDOM"]); 7.245 + }; 7.246 + this.processor.input = sourceDoc; 7.247 + var outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER); 7.248 + this.processor.output = outDoc; 7.249 + this.processor.transform(); 7.250 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID); 7.251 + oDoc.loadXML(outDoc.output+""); 7.252 + return oDoc; 7.253 + }; 7.254 + }; 7.255 + 7.256 + /** 7.257 + * Transform the given XML DOM and return the transformation result as a new DOM fragment. 7.258 + * <b>Note</b>: The xsl:output method must match the nature of the owner document (XML/HTML). 7.259 + * @argument sourceDoc The XML DOMDocument to transform 7.260 + * @argument ownerDoc The owner of the result fragment 7.261 + * @return The transformation result as a DOM Document 7.262 + */ 7.263 + XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) { 7.264 + this.processor.input = sourceDoc; 7.265 + this.processor.transform(); 7.266 + var s = this.processor.output; 7.267 + var f = ownerDoc.createDocumentFragment(); 7.268 + if (this.outputMethod == 'text') { 7.269 + f.appendChild(ownerDoc.createTextNode(s)); 7.270 + } else if (ownerDoc.body && ownerDoc.body.innerHTML) { 7.271 + var container = ownerDoc.createElement('div'); 7.272 + container.innerHTML = s; 7.273 + while (container.hasChildNodes()) { 7.274 + f.appendChild(container.firstChild); 7.275 + } 7.276 + } 7.277 + else { 7.278 + var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID); 7.279 + if (s.substring(0, 5) == '<?xml') { 7.280 + s = s.substring(s.indexOf('?>') + 2); 7.281 + } 7.282 + var xml = ''.concat('<my>', s, '</my>'); 7.283 + oDoc.loadXML(xml); 7.284 + var container = oDoc.documentElement; 7.285 + while (container.hasChildNodes()) { 7.286 + f.appendChild(container.firstChild); 7.287 + } 7.288 + } 7.289 + return f; 7.290 + }; 7.291 + 7.292 + /** 7.293 + * Set global XSLT parameter of the imported stylesheet 7.294 + * @argument nsURI The parameter namespace URI 7.295 + * @argument name The parameter base name 7.296 + * @argument value The new parameter value 7.297 + */ 7.298 + XSLTProcessor.prototype.setParameter = function(nsURI, name, value){ 7.299 + // make value a zero length string if null to allow clearing 7.300 + value = value ? value : ""; 7.301 + // nsURI is optional but cannot be null 7.302 + if(nsURI){ 7.303 + this.processor.addParameter(name, value, nsURI); 7.304 + }else{ 7.305 + this.processor.addParameter(name, value); 7.306 + }; 7.307 + // update updated params for getParameter 7.308 + nsURI = "" + (nsURI || ""); 7.309 + if(!this.paramsSet[nsURI]){ 7.310 + this.paramsSet[nsURI] = new Array(); 7.311 + }; 7.312 + this.paramsSet[nsURI][name] = value; 7.313 + }; 7.314 + /** 7.315 + * Gets a parameter if previously set by setParameter. Returns null 7.316 + * otherwise 7.317 + * @argument name The parameter base name 7.318 + * @argument value The new parameter value 7.319 + * @return The parameter value if reviously set by setParameter, null otherwise 7.320 + */ 7.321 + XSLTProcessor.prototype.getParameter = function(nsURI, name){ 7.322 + nsURI = "" + (nsURI || ""); 7.323 + if(this.paramsSet[nsURI] && this.paramsSet[nsURI][name]){ 7.324 + return this.paramsSet[nsURI][name]; 7.325 + }else{ 7.326 + return null; 7.327 + }; 7.328 + }; 7.329 + /** 7.330 + * Clear parameters (set them to default values as defined in the stylesheet itself) 7.331 + */ 7.332 + XSLTProcessor.prototype.clearParameters = function(){ 7.333 + for(var nsURI in this.paramsSet){ 7.334 + for(var name in this.paramsSet[nsURI]){ 7.335 + if(nsURI!=""){ 7.336 + this.processor.addParameter(name, "", nsURI); 7.337 + }else{ 7.338 + this.processor.addParameter(name, ""); 7.339 + }; 7.340 + }; 7.341 + }; 7.342 + this.paramsSet = new Array(); 7.343 + }; 7.344 +}else{ /* end IE initialization, try to deal with real browsers now ;-) */ 7.345 + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){ 7.346 + /** 7.347 + * <p>Ensures the document was loaded correctly, otherwise sets the 7.348 + * parseError to -1 to indicate something went wrong. Internal use</p> 7.349 + * @private 7.350 + */ 7.351 + Sarissa.__handleLoad__ = function(oDoc){ 7.352 + Sarissa.__setReadyState__(oDoc, 4); 7.353 + }; 7.354 + /** 7.355 + * <p>Attached by an event handler to the load event. Internal use.</p> 7.356 + * @private 7.357 + */ 7.358 + _sarissa_XMLDocument_onload = function(){ 7.359 + Sarissa.__handleLoad__(this); 7.360 + }; 7.361 + /** 7.362 + * <p>Sets the readyState property of the given DOM Document object. 7.363 + * Internal use.</p> 7.364 + * @private 7.365 + * @argument oDoc the DOM Document object to fire the 7.366 + * readystatechange event 7.367 + * @argument iReadyState the number to change the readystate property to 7.368 + */ 7.369 + Sarissa.__setReadyState__ = function(oDoc, iReadyState){ 7.370 + oDoc.readyState = iReadyState; 7.371 + oDoc.readystate = iReadyState; 7.372 + if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") { 7.373 + oDoc.onreadystatechange(); 7.374 + } 7.375 + }; 7.376 + Sarissa.getDomDocument = function(sUri, sName){ 7.377 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null); 7.378 + if(!oDoc.onreadystatechange){ 7.379 + 7.380 + /** 7.381 + * <p>Emulate IE's onreadystatechange attribute</p> 7.382 + */ 7.383 + oDoc.onreadystatechange = null; 7.384 + }; 7.385 + if(!oDoc.readyState){ 7.386 + /** 7.387 + * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p> 7.388 + * <ul><li>1 == LOADING,</li> 7.389 + * <li>2 == LOADED,</li> 7.390 + * <li>3 == INTERACTIVE,</li> 7.391 + * <li>4 == COMPLETED</li></ul> 7.392 + */ 7.393 + oDoc.readyState = 0; 7.394 + }; 7.395 + oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false); 7.396 + return oDoc; 7.397 + }; 7.398 + if(window.XMLDocument){ 7.399 + // do nothing 7.400 + }// TODO: check if the new document has content before trying to copynodes, check for error handling in DOM 3 LS 7.401 + else if(_SARISSA_HAS_DOM_FEATURE && window.Document && !Document.prototype.load && document.implementation.hasFeature('LS', '3.0')){ 7.402 + //Opera 9 may get the XPath branch which gives creates XMLDocument, therefore it doesn't reach here which is good 7.403 + /** 7.404 + * <p>Factory method to obtain a new DOM Document object</p> 7.405 + * @argument sUri the namespace of the root node (if any) 7.406 + * @argument sUri the local name of the root node (if any) 7.407 + * @returns a new DOM Document 7.408 + */ 7.409 + Sarissa.getDomDocument = function(sUri, sName){ 7.410 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null); 7.411 + return oDoc; 7.412 + }; 7.413 + } 7.414 + else { 7.415 + Sarissa.getDomDocument = function(sUri, sName){ 7.416 + var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null); 7.417 + // looks like safari does not create the root element for some unknown reason 7.418 + if(oDoc && (sUri || sName) && !oDoc.documentElement){ 7.419 + oDoc.appendChild(oDoc.createElementNS(sUri, sName)); 7.420 + }; 7.421 + return oDoc; 7.422 + }; 7.423 + }; 7.424 + };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT) 7.425 +}; 7.426 +//========================================== 7.427 +// Common stuff 7.428 +//========================================== 7.429 +if(!window.DOMParser){ 7.430 + if(_SARISSA_IS_SAFARI){ 7.431 + /* 7.432 + * DOMParser is a utility class, used to construct DOMDocuments from XML strings 7.433 + * @constructor 7.434 + */ 7.435 + DOMParser = function() { }; 7.436 + /** 7.437 + * Construct a new DOM Document from the given XMLstring 7.438 + * @param sXml the given XML string 7.439 + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). 7.440 + * @return a new DOM Document from the given XML string 7.441 + */ 7.442 + DOMParser.prototype.parseFromString = function(sXml, contentType){ 7.443 + var xmlhttp = new XMLHttpRequest(); 7.444 + xmlhttp.open("GET", "data:text/xml;charset=utf-8," + encodeURIComponent(sXml), false); 7.445 + xmlhttp.send(null); 7.446 + return xmlhttp.responseXML; 7.447 + }; 7.448 + }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && Sarissa.getDomDocument(null, "bar").xml){ 7.449 + DOMParser = function() { }; 7.450 + DOMParser.prototype.parseFromString = function(sXml, contentType){ 7.451 + var doc = Sarissa.getDomDocument(); 7.452 + doc.loadXML(sXml); 7.453 + return doc; 7.454 + }; 7.455 + }; 7.456 +}; 7.457 + 7.458 +if((typeof(document.importNode) == "undefined") && _SARISSA_IS_IE){ 7.459 + try{ 7.460 + /** 7.461 + * Implementation of importNode for the context window document in IE. 7.462 + * If <code>oNode</code> is a TextNode, <code>bChildren</code> is ignored. 7.463 + * @param oNode the Node to import 7.464 + * @param bChildren whether to include the children of oNode 7.465 + * @returns the imported node for further use 7.466 + */ 7.467 + document.importNode = function(oNode, bChildren){ 7.468 + var tmp; 7.469 + if (oNode.nodeName=='#text') { 7.470 + return document.createTextElement(oNode.data); 7.471 + } 7.472 + else { 7.473 + if(oNode.nodeName == "tbody" || oNode.nodeName == "tr"){ 7.474 + tmp = document.createElement("table"); 7.475 + } 7.476 + else if(oNode.nodeName == "td"){ 7.477 + tmp = document.createElement("tr"); 7.478 + } 7.479 + else if(oNode.nodeName == "option"){ 7.480 + tmp = document.createElement("select"); 7.481 + } 7.482 + else{ 7.483 + tmp = document.createElement("div"); 7.484 + }; 7.485 + if(bChildren){ 7.486 + tmp.innerHTML = oNode.xml ? oNode.xml : oNode.outerHTML; 7.487 + }else{ 7.488 + tmp.innerHTML = oNode.xml ? oNode.cloneNode(false).xml : oNode.cloneNode(false).outerHTML; 7.489 + }; 7.490 + return tmp.getElementsByTagName("*")[0]; 7.491 + }; 7.492 + 7.493 + }; 7.494 + }catch(e){ }; 7.495 +}; 7.496 +if(!Sarissa.getParseErrorText){ 7.497 + /** 7.498 + * <p>Returns a human readable description of the parsing error. Usefull 7.499 + * for debugging. Tip: append the returned error string in a <pre> 7.500 + * element if you want to render it.</p> 7.501 + * <p>Many thanks to Christian Stocker for the initial patch.</p> 7.502 + * @argument oDoc The target DOM document 7.503 + * @returns The parsing error description of the target Document in 7.504 + * human readable form (preformated text) 7.505 + */ 7.506 + Sarissa.getParseErrorText = function (oDoc){ 7.507 + var parseErrorText = Sarissa.PARSED_OK; 7.508 + if(!oDoc.documentElement){ 7.509 + parseErrorText = Sarissa.PARSED_EMPTY; 7.510 + } else if(oDoc.documentElement.tagName == "parsererror"){ 7.511 + parseErrorText = oDoc.documentElement.firstChild.data; 7.512 + parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data; 7.513 + } else if(oDoc.getElementsByTagName("parsererror").length > 0){ 7.514 + var parsererror = oDoc.getElementsByTagName("parsererror")[0]; 7.515 + parseErrorText = Sarissa.getText(parsererror, true)+"\n"; 7.516 + } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){ 7.517 + parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR; 7.518 + }; 7.519 + return parseErrorText; 7.520 + }; 7.521 +}; 7.522 +Sarissa.getText = function(oNode, deep){ 7.523 + var s = ""; 7.524 + var nodes = oNode.childNodes; 7.525 + for(var i=0; i < nodes.length; i++){ 7.526 + var node = nodes[i]; 7.527 + var nodeType = node.nodeType; 7.528 + if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){ 7.529 + s += node.data; 7.530 + } else if(deep == true 7.531 + && (nodeType == Node.ELEMENT_NODE 7.532 + || nodeType == Node.DOCUMENT_NODE 7.533 + || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){ 7.534 + s += Sarissa.getText(node, true); 7.535 + }; 7.536 + }; 7.537 + return s; 7.538 +}; 7.539 +if(!window.XMLSerializer 7.540 + && Sarissa.getDomDocument 7.541 + && Sarissa.getDomDocument("","foo", null).xml){ 7.542 + /** 7.543 + * Utility class to serialize DOM Node objects to XML strings 7.544 + * @constructor 7.545 + */ 7.546 + XMLSerializer = function(){}; 7.547 + /** 7.548 + * Serialize the given DOM Node to an XML string 7.549 + * @param oNode the DOM Node to serialize 7.550 + */ 7.551 + XMLSerializer.prototype.serializeToString = function(oNode) { 7.552 + return oNode.xml; 7.553 + }; 7.554 +}; 7.555 + 7.556 +/** 7.557 + * strips tags from a markup string 7.558 + */ 7.559 +Sarissa.stripTags = function (s) { 7.560 + return s.replace(/<[^>]+>/g,""); 7.561 +}; 7.562 +/** 7.563 + * <p>Deletes all child nodes of the given node</p> 7.564 + * @argument oNode the Node to empty 7.565 + */ 7.566 +Sarissa.clearChildNodes = function(oNode) { 7.567 + // need to check for firstChild due to opera 8 bug with hasChildNodes 7.568 + while(oNode.firstChild) { 7.569 + oNode.removeChild(oNode.firstChild); 7.570 + }; 7.571 +}; 7.572 +/** 7.573 + * <p> Copies the childNodes of nodeFrom to nodeTo</p> 7.574 + * <p> <b>Note:</b> The second object's original content is deleted before 7.575 + * the copy operation, unless you supply a true third parameter</p> 7.576 + * @argument nodeFrom the Node to copy the childNodes from 7.577 + * @argument nodeTo the Node to copy the childNodes to 7.578 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false 7.579 + */ 7.580 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { 7.581 + if(_SARISSA_IS_SAFARI && nodeTo.nodeType == Node.DOCUMENT_NODE){ // SAFARI_OLD ?? 7.582 + nodeTo = nodeTo.documentElement; //Appearantly there's a bug in safari where you can't appendChild to a document node 7.583 + } 7.584 + 7.585 + if((!nodeFrom) || (!nodeTo)){ 7.586 + throw "Both source and destination nodes must be provided"; 7.587 + }; 7.588 + if(!bPreserveExisting){ 7.589 + Sarissa.clearChildNodes(nodeTo); 7.590 + }; 7.591 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument; 7.592 + var nodes = nodeFrom.childNodes; 7.593 + if(typeof(ownerDoc.importNode) != "undefined") { 7.594 + for(var i=0;i < nodes.length;i++) { 7.595 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); 7.596 + }; 7.597 + } else { 7.598 + for(var i=0;i < nodes.length;i++) { 7.599 + nodeTo.appendChild(nodes[i].cloneNode(true)); 7.600 + }; 7.601 + }; 7.602 +}; 7.603 + 7.604 +/** 7.605 + * <p> Moves the childNodes of nodeFrom to nodeTo</p> 7.606 + * <p> <b>Note:</b> The second object's original content is deleted before 7.607 + * the move operation, unless you supply a true third parameter</p> 7.608 + * @argument nodeFrom the Node to copy the childNodes from 7.609 + * @argument nodeTo the Node to copy the childNodes to 7.610 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is 7.611 + */ 7.612 +Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { 7.613 + if((!nodeFrom) || (!nodeTo)){ 7.614 + throw "Both source and destination nodes must be provided"; 7.615 + }; 7.616 + if(!bPreserveExisting){ 7.617 + Sarissa.clearChildNodes(nodeTo); 7.618 + }; 7.619 + var nodes = nodeFrom.childNodes; 7.620 + // if within the same doc, just move, else copy and delete 7.621 + if(nodeFrom.ownerDocument == nodeTo.ownerDocument){ 7.622 + while(nodeFrom.firstChild){ 7.623 + nodeTo.appendChild(nodeFrom.firstChild); 7.624 + }; 7.625 + } else { 7.626 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument; 7.627 + if(typeof(ownerDoc.importNode) != "undefined") { 7.628 + for(var i=0;i < nodes.length;i++) { 7.629 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); 7.630 + }; 7.631 + }else{ 7.632 + for(var i=0;i < nodes.length;i++) { 7.633 + nodeTo.appendChild(nodes[i].cloneNode(true)); 7.634 + }; 7.635 + }; 7.636 + Sarissa.clearChildNodes(nodeFrom); 7.637 + }; 7.638 +}; 7.639 + 7.640 +/** 7.641 + * <p>Serialize any <strong>non</strong> DOM object to an XML string. All properties are serialized using the property name 7.642 + * as the XML element name. Array elements are rendered as <code>array-item</code> elements, 7.643 + * using their index/key as the value of the <code>key</code> attribute.</p> 7.644 + * @argument anyObject the object to serialize 7.645 + * @argument objectName a name for that object 7.646 + * @return the XML serialization of the given object as a string 7.647 + */ 7.648 +Sarissa.xmlize = function(anyObject, objectName, indentSpace){ 7.649 + indentSpace = indentSpace?indentSpace:''; 7.650 + var s = indentSpace + '<' + objectName + '>'; 7.651 + var isLeaf = false; 7.652 + if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String 7.653 + || anyObject instanceof Boolean || anyObject instanceof Date){ 7.654 + s += Sarissa.escape(""+anyObject); 7.655 + isLeaf = true; 7.656 + }else{ 7.657 + s += "\n"; 7.658 + var isArrayItem = anyObject instanceof Array; 7.659 + for(var name in anyObject){ 7.660 + s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " "); 7.661 + }; 7.662 + s += indentSpace; 7.663 + }; 7.664 + return (s += (objectName.indexOf(' ')!=-1?"</array-item>\n":"</" + objectName + ">\n")); 7.665 +}; 7.666 + 7.667 +/** 7.668 + * Escape the given string chacters that correspond to the five predefined XML entities 7.669 + * @param sXml the string to escape 7.670 + */ 7.671 +Sarissa.escape = function(sXml){ 7.672 + return sXml.replace(/&/g, "&") 7.673 + .replace(/</g, "<") 7.674 + .replace(/>/g, ">") 7.675 + .replace(/"/g, """) 7.676 + .replace(/'/g, "'"); 7.677 +}; 7.678 + 7.679 +/** 7.680 + * Unescape the given string. This turns the occurences of the predefined XML 7.681 + * entities to become the characters they represent correspond to the five predefined XML entities 7.682 + * @param sXml the string to unescape 7.683 + */ 7.684 +Sarissa.unescape = function(sXml){ 7.685 + return sXml.replace(/'/g,"'") 7.686 + .replace(/"/g,"\"") 7.687 + .replace(/>/g,">") 7.688 + .replace(/</g,"<") 7.689 + .replace(/&/g,"&"); 7.690 +}; 7.691 +// EOF
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_comments.xsl Sun Feb 03 20:05:15 2008 +0000 8.3 @@ -0,0 +1,41 @@ 8.4 +<?xml version="1.0" encoding="utf-8"?> 8.5 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 8.6 + version="1.0"> 8.7 + 8.8 + <!-- Add or process comment elements inside item elements. --> 8.9 + <!-- This transformation must happen after type elements have been populated. --> 8.10 + 8.11 + <xsl:template match="item"> 8.12 + <!-- Copy the element and its contents. --> 8.13 + <xsl:copy> 8.14 + <xsl:apply-templates select="@*"/> 8.15 + <!-- Ensure an options element. --> 8.16 + <xsl:call-template name="options"/> 8.17 + <xsl:apply-templates select="*[local-name() != 'options']"/> 8.18 + </xsl:copy> 8.19 + </xsl:template> 8.20 + 8.21 + <!-- Investigate options elements. --> 8.22 + 8.23 + <xsl:template name="options"> 8.24 + <!-- Make the element. --> 8.25 + <options> 8.26 + <!-- Only for certain element types... --> 8.27 + <xsl:if test="type/type-enum[@value='P' and @value-is-set]"> 8.28 + <!-- Add comments. --> 8.29 + <comment> 8.30 + <xsl:apply-templates select="options/comment/@value"/> 8.31 + </comment> 8.32 + </xsl:if> 8.33 + </options> 8.34 + </xsl:template> 8.35 + 8.36 + <!-- Replicate unknown elements. --> 8.37 + 8.38 + <xsl:template match="@*|*|node()"> 8.39 + <xsl:copy> 8.40 + <xsl:apply-templates select="@*|*|node()"/> 8.41 + </xsl:copy> 8.42 + </xsl:template> 8.43 + 8.44 +</xsl:stylesheet>
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_multivalue_label_template.xhtml Sun Feb 03 20:05:15 2008 +0000 9.3 @@ -0,0 +1,62 @@ 9.4 +<?xml version="1.0" encoding="iso-8859-1"?> 9.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 9.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 9.7 +<html xmlns="http://www.w3.org/1999/xhtml" 9.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 9.9 +<head> 9.10 + <title>Example</title> 9.11 + <script type="text/javascript" src="scripts/sarissa.js"> </script> 9.12 + <script type="text/javascript" src="scripts/XSLForms.js"> </script> 9.13 +</head> 9.14 +<body template:element="structure"> 9.15 +<form action="" method="POST"> 9.16 + 9.17 +<!-- Template text between the start and the interesting part. --> 9.18 + 9.19 +<div template:element="item"> 9.20 + <p> 9.21 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 9.22 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 9.23 + </p> 9.24 + <p> 9.25 + Item type: 9.26 + <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple" 9.27 + onchange="requestUpdate( 9.28 + 'comments', 9.29 + '{template:list-attribute('type-enum', 'value')}', 9.30 + '{template:other-elements(../options)}', 9.31 + '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}', 9.32 + '/structure/item')"> 9.33 + <option template:multiple-choice-list-value="type-enum,value,selected,template:i18n(text())" value="..." /> 9.34 + </select> 9.35 + </p> 9.36 + <p template:element="options" template:section="comment-node" id="{template:this-element()}"> 9.37 + <span template:element="comment">Comment: 9.38 + <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"> 9.39 + Some comment 9.40 + </textarea> 9.41 + </span> 9.42 + </p> 9.43 + <p> 9.44 + Itself containing more items: 9.45 + </p> 9.46 + <p template:element="subitem"> 9.47 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 9.48 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 9.49 + </p> 9.50 + <p> 9.51 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 9.52 + </p> 9.53 +</div> 9.54 +<p> 9.55 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 9.56 +</p> 9.57 +<p> 9.58 + <input name="update" type="submit" value="Update" /> 9.59 +</p> 9.60 + 9.61 +<!-- Template text between the interesting part and the end. --> 9.62 + 9.63 +</form> 9.64 +</body> 9.65 +</html>
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_multivalue_template.xhtml Sun Feb 03 20:05:15 2008 +0000 10.3 @@ -0,0 +1,62 @@ 10.4 +<?xml version="1.0" encoding="iso-8859-1"?> 10.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 10.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 10.7 +<html xmlns="http://www.w3.org/1999/xhtml" 10.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 10.9 +<head> 10.10 + <title>Example</title> 10.11 + <script type="text/javascript" src="scripts/sarissa.js"> </script> 10.12 + <script type="text/javascript" src="scripts/XSLForms.js"> </script> 10.13 +</head> 10.14 +<body template:element="structure"> 10.15 +<form action="" method="POST"> 10.16 + 10.17 +<!-- Template text between the start and the interesting part. --> 10.18 + 10.19 +<div template:element="item"> 10.20 + <p> 10.21 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 10.22 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 10.23 + </p> 10.24 + <p> 10.25 + Item type: 10.26 + <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple" 10.27 + onchange="requestUpdate( 10.28 + 'comments', 10.29 + '{template:list-attribute('type-enum', 'value')}', 10.30 + '{template:other-elements(../options)}', 10.31 + '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}', 10.32 + '/structure/item')"> 10.33 + <option template:multiple-choice-list-value="type-enum,value,selected" value="..." /> 10.34 + </select> 10.35 + </p> 10.36 + <p template:element="options" template:section="comment-node" id="{template:this-element()}"> 10.37 + <span template:element="comment">Comment: 10.38 + <textarea template:attribute-area="value,insert" name="..." cols="40" rows="3"> 10.39 + Some comment 10.40 + </textarea> 10.41 + </span> 10.42 + </p> 10.43 + <p> 10.44 + Itself containing more items: 10.45 + </p> 10.46 + <p template:element="subitem"> 10.47 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 10.48 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 10.49 + </p> 10.50 + <p> 10.51 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 10.52 + </p> 10.53 +</div> 10.54 +<p> 10.55 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 10.56 +</p> 10.57 +<p> 10.58 + <input name="update" type="submit" value="Update" /> 10.59 +</p> 10.60 + 10.61 +<!-- Template text between the interesting part and the end. --> 10.62 + 10.63 +</form> 10.64 +</body> 10.65 +</html>
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_template.xhtml Sun Feb 03 20:05:15 2008 +0000 11.3 @@ -0,0 +1,44 @@ 11.4 +<?xml version="1.0" encoding="iso-8859-1"?> 11.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 11.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 11.7 +<html xmlns="http://www.w3.org/1999/xhtml" 11.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 11.9 +<head> 11.10 + <title>Example</title> 11.11 +</head> 11.12 +<body template:element="structure"> 11.13 +<form action="" method="POST"> 11.14 + 11.15 +<!-- Template text between the start and the interesting part. --> 11.16 + 11.17 +<div template:element="item"> 11.18 + <p> 11.19 + Some item: <input template:attribute-field="value" name="..." type="text" value="..." /> 11.20 + <input template:selector-field="remove" name="..." type="submit" value="Remove" /> 11.21 + </p> 11.22 + <p> 11.23 + Item type: 11.24 + <select template:multiple-choice-field="type,value" name="..."> 11.25 + <option template:multiple-choice-value="type-enum,value,selected" value="..." /> 11.26 + </select> 11.27 + </p> 11.28 + <p> 11.29 + Itself containing more items: 11.30 + </p> 11.31 + <p template:element="subitem"> 11.32 + Sub-item: <input template:attribute-field="subvalue" name="..." type="text" value="..." /> 11.33 + <input template:selector-field="remove2" name="..." type="submit" value="Remove" /> 11.34 + </p> 11.35 + <p> 11.36 + <input template:selector-field="add2,subitem" name="..." type="submit" value="Add subitem" /> 11.37 + </p> 11.38 +</div> 11.39 +<p> 11.40 + <input template:selector-field="add,item" name="..." type="submit" value="Add item" /> 11.41 +</p> 11.42 + 11.43 +<!-- Template text between the interesting part and the end. --> 11.44 + 11.45 +</form> 11.46 +</body> 11.47 +</html>
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_types.xml Sun Feb 03 20:05:15 2008 +0000 12.3 @@ -0,0 +1,7 @@ 12.4 +<?xml version="1.0"?> 12.5 +<type> 12.6 + <type-enum value="(Not selected)"/> 12.7 + <type-enum value="Important"/> 12.8 + <type-enum value="Not important"/> 12.9 + <type-enum value="Personal"/> 12.10 +</type>
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/structure_types_label.xml Sun Feb 03 20:05:15 2008 +0000 13.3 @@ -0,0 +1,7 @@ 13.4 +<?xml version="1.0"?> 13.5 +<type> 13.6 + <type-enum value="0">(Not selected)</type-enum> 13.7 + <type-enum value="I">Important</type-enum> 13.8 + <type-enum value="N">Not important</type-enum> 13.9 + <type-enum value="P">Personal</type-enum> 13.10 +</type>
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/success_template.xhtml Sun Feb 03 20:05:15 2008 +0000 14.3 @@ -0,0 +1,19 @@ 14.4 +<?xml version="1.0" encoding="iso-8859-1"?> 14.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 14.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 14.7 +<html xmlns="http://www.w3.org/1999/xhtml" 14.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 14.9 +<head> 14.10 + <title>Very Simple Login Succeeded</title> 14.11 +</head> 14.12 + 14.13 +<body template:element="success"> 14.14 +<h1>Login Successful</h1> 14.15 + 14.16 + <form action="{@location}" method="POST" name="openid_redirect"> 14.17 + <input template:element="field" name="{@name}" type="hidden" value="{@value}" /> 14.18 + <p>Please proceed to the application: <input name="proceed" type="submit" value="Proceed!" /></p> 14.19 + </form> 14.20 + 14.21 +</body> 14.22 +</html>
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/examples/Common/VerySimpleWithOpenID/Resources/translations.xml Sun Feb 03 20:05:15 2008 +0000 15.3 @@ -0,0 +1,15 @@ 15.4 +<?xml version="1.0" encoding="iso-8859-1"?> 15.5 +<translations> 15.6 + <locale> 15.7 + <code value="en"/> 15.8 + <code value="en_GB"/> 15.9 + </locale> 15.10 + <locale> 15.11 + <code value="nb"/> 15.12 + <code value="nb_NO"/> 15.13 + <translation value="(Not selected)">(Ikke valgt)</translation> 15.14 + <translation value="Important">Viktig</translation> 15.15 + <translation value="Not important">Ikke viktig</translation> 15.16 + <translation value="Personal">Personlig</translation> 15.17 + </locale> 15.18 +</translations>
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/examples/Common/VerySimpleWithOpenID/__init__.py Sun Feb 03 20:05:15 2008 +0000 16.3 @@ -0,0 +1,231 @@ 16.4 +#!/usr/bin/env python 16.5 +# -*- coding: iso-8859-1 -*- 16.6 + 16.7 +"A very simple example application." 16.8 + 16.9 +import WebStack.Generic 16.10 +import XSLForms.Resources.WebResources 16.11 +import XSLForms.Utils 16.12 +import os 16.13 + 16.14 +# Site map imports. 16.15 + 16.16 +from WebStack.Resources.ResourceMap import MapResource 16.17 +from WebStack.Resources.Selectors import EncodingSelector, PathSelector 16.18 +from WebStack.Resources.Static import DirectoryResource, StringResource 16.19 +from XSLForms.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator 16.20 +from XSLForms.Resources.OpenIDRedirect import OpenIDRedirectResource, OpenIDRedirectAuthenticator 16.21 +from XSLForms.Resources.OpenIDInitiation import OpenIDInitiationResource 16.22 + 16.23 +# Configuration settings. 16.24 + 16.25 +encoding = "utf-8" 16.26 + 16.27 +# Resource classes. 16.28 + 16.29 +class VerySimpleResource(XSLForms.Resources.WebResources.XSLFormsResource): 16.30 + 16.31 + "A very simple resource providing a hierarchy of editable fields." 16.32 + 16.33 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 16.34 + template_resources = { 16.35 + #"structure" : ("structure_template.xhtml", "structure_output.xsl") 16.36 + #"structure" : ("structure_multivalue_template.xhtml", "structure_output.xsl") 16.37 + "structure" : ("structure_multivalue_label_template.xhtml", "structure_output.xsl") 16.38 + } 16.39 + init_resources = { 16.40 + #"structure" : ("structure_template.xhtml", "structure_input.xsl") 16.41 + #"structure" : ("structure_multivalue_template.xhtml", "structure_input.xsl") 16.42 + "structure" : ("structure_multivalue_label_template.xhtml", "structure_input.xsl") 16.43 + } 16.44 + transform_resources = { 16.45 + "comments" : ["structure_comments.xsl"] 16.46 + } 16.47 + document_resources = { 16.48 + #"types" : "structure_types.xml" 16.49 + "types" : "structure_types_label.xml", 16.50 + "translations" : "translations.xml" 16.51 + } 16.52 + in_page_resources = { 16.53 + "comments" : ("structure", "structure_output_comments.xsl", "comment-node") 16.54 + } 16.55 + 16.56 + def respond_to_form(self, trans, form): 16.57 + 16.58 + """ 16.59 + Respond to a request having the given transaction 'trans' and the given 16.60 + 'form' information. 16.61 + """ 16.62 + 16.63 + in_page_resource = self.get_in_page_resource(trans) 16.64 + parameters = form.get_parameters() 16.65 + documents = form.get_documents() 16.66 + 16.67 + # Ensure the presence of a document. 16.68 + 16.69 + if documents.has_key("structure"): 16.70 + structure = documents["structure"] 16.71 + else: 16.72 + structure = form.new_instance("structure") 16.73 + 16.74 + # Add and remove elements according to the selectors found. 16.75 + 16.76 + selectors = form.get_selectors() 16.77 + XSLForms.Utils.remove_elements(selectors.get("remove2")) 16.78 + XSLForms.Utils.add_elements(selectors.get("add2"), "subitem") 16.79 + XSLForms.Utils.remove_elements(selectors.get("remove")) 16.80 + XSLForms.Utils.add_elements(selectors.get("add"), "item") 16.81 + 16.82 + # Initialise the document, adding enumerations/ranges. 16.83 + 16.84 + structure_xsl = self.prepare_initialiser("structure") 16.85 + types_xml = self.prepare_document("types") 16.86 + structure = self.get_result([structure_xsl], structure, references={"type" : types_xml}) 16.87 + 16.88 + # Add the comments. 16.89 + 16.90 + comments_xsl_list = self.prepare_transform("comments") 16.91 + structure = self.get_result(comments_xsl_list, structure) 16.92 + 16.93 + # Start the response. 16.94 + 16.95 + trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", encoding)) 16.96 + 16.97 + # Ensure that an output stylesheet exists. 16.98 + 16.99 + if in_page_resource in self.in_page_resources.keys(): 16.100 + trans_xsl = self.prepare_fragment(in_page_resource) 16.101 + stylesheet_parameters = self.prepare_parameters(parameters) 16.102 + else: 16.103 + trans_xsl = self.prepare_output("structure") 16.104 + stylesheet_parameters = {} 16.105 + 16.106 + # Complete the response. 16.107 + 16.108 + try: 16.109 + stylesheet_parameters["locale"] = trans.get_content_languages()[0] 16.110 + except IndexError: 16.111 + pass 16.112 + self.send_output(trans, [trans_xsl], structure, stylesheet_parameters, 16.113 + references={"translations" : self.prepare_document("translations")}) 16.114 + 16.115 +class InitiationResource(XSLForms.Resources.OpenIDInitiation.OpenIDInitiationResource): 16.116 + 16.117 + "Special initiation screen for this application." 16.118 + 16.119 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 16.120 + template_resources = { 16.121 + "initiation" : ("initiation_template.xhtml", "initiation_output.xsl"), 16.122 + "success" : ("initiation_success_template.xhtml", "initiation_success_output.xsl") 16.123 + } 16.124 + 16.125 +class LoginResource(XSLForms.Resources.OpenIDLogin.OpenIDLoginResource): 16.126 + 16.127 + "Special login screen for this application." 16.128 + 16.129 + resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") 16.130 + template_resources = { 16.131 + "login" : ("login_template.xhtml", "login_output.xsl"), 16.132 + "success" : ("success_template.xhtml", "success_output.xsl") 16.133 + } 16.134 + 16.135 +# Site map initialisation. 16.136 + 16.137 +def get_site(host, secret_key, use_redirect=1): 16.138 + 16.139 + "Return a simple Web site resource." 16.140 + 16.141 + # Authentication objects. 16.142 + 16.143 + credentials = [ 16.144 + ("badger", "123"), 16.145 + ("vole", "abc") 16.146 + ] 16.147 + login_authenticator = Authenticator(credentials) 16.148 + login_redirect_authenticator = OpenIDRedirectAuthenticator(secret_key, host) 16.149 + 16.150 + # Get the main resource and the directory used by the application. 16.151 + 16.152 + very_simple_resource = VerySimpleResource() 16.153 + directory = very_simple_resource.resource_dir 16.154 + 16.155 + # Get some initiation/login resources. 16.156 + 16.157 + login_redirect_resource = XSLForms.Resources.OpenIDRedirect.OpenIDRedirectResource( 16.158 + host, 16.159 + "initiation", # see below 16.160 + resource=very_simple_resource, 16.161 + authenticator=login_redirect_authenticator, 16.162 + logout_parameter_name="logout" 16.163 + ) 16.164 + initiation_resource = InitiationResource(use_redirect=use_redirect) 16.165 + login_resource = LoginResource(login_authenticator, use_redirect) 16.166 + 16.167 + # Make a simple Web site. 16.168 + 16.169 + resource = MapResource({ 16.170 + # Static resources: 16.171 + "scripts" : DirectoryResource(os.path.join(directory, "scripts"), {"js" : "text/javascript"}), 16.172 + # Initiation resource: 16.173 + "initiation" : initiation_resource, 16.174 + # Login resource: 16.175 + "login" : login_resource, 16.176 + 16.177 + # Some local OpenID pages. 16.178 + 16.179 + "badger" : 16.180 + StringResource(""" 16.181 + <html> 16.182 + <head> 16.183 + <link rel="openid2.provider openid.server" href="%s/login" /> 16.184 + <link rel="openid2.local_id openid.delegate" href="%s/badger" /> 16.185 + <title>Badger's Home Page</title> 16.186 + </head> 16.187 + <body> 16.188 + <p>Home page for the OpenID authenticated user, <code>badger</code>.</p> 16.189 + </body> 16.190 + </html> 16.191 + """ % (host, host), WebStack.Generic.ContentType("text/html")), 16.192 + u"זרו" : 16.193 + StringResource(u""" 16.194 + <html> 16.195 + <head> 16.196 + <link rel="openid2.provider openid.server" href="%s/login" /> 16.197 + <link rel="openid2.local_id openid.delegate" href="%s/זרו" /> 16.198 + <title>Home Page for זרו</title> 16.199 + </head> 16.200 + <body> 16.201 + <p>Home page for the OpenID authenticated user, <code>זרו</code>.</p> 16.202 + </body> 16.203 + </html> 16.204 + """ % (host, host), WebStack.Generic.ContentType("text/html", "iso-8859-1")), 16.205 + "vole" : 16.206 + StringResource(""" 16.207 + <html> 16.208 + <head> 16.209 + <link rel="openid2.provider openid.server" href="%s/login" /> 16.210 + <link rel="openid2.local_id openid.delegate" href="%s/vole" /> 16.211 + <title>Vole's Home Page</title> 16.212 + </head> 16.213 + <body> 16.214 + <p>Home page for the OpenID authenticated user, <code>vole</code>.</p> 16.215 + </body> 16.216 + </html> 16.217 + """ % (host, host), WebStack.Generic.ContentType("text/html")), 16.218 + 16.219 + # Main page and in-page resources: 16.220 + # (Now protected!) 16.221 + None : login_redirect_resource 16.222 + }) 16.223 + 16.224 + # Wrap the resource up with information about the application root. 16.225 + 16.226 + return EncodingSelector(PathSelector(resource), encoding) 16.227 + 16.228 +# Resource preparation ahead of time - useful for making installations. 16.229 + 16.230 +def prepare_resources(): 16.231 + for cls in [VerySimpleResource, LoginResource, InitiationResource]: 16.232 + XSLForms.Resources.WebResources.prepare_resources(cls) 16.233 + 16.234 +# vim: tabstop=4 expandtab shiftwidth=4
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/examples/Twisted/VerySimpleWithOpenIDApp.py Sun Feb 03 20:05:15 2008 +0000 17.3 @@ -0,0 +1,18 @@ 17.4 +#!/usr/bin/env python 17.5 + 17.6 +from WebStack.Adapters.Twisted import deploy 17.7 +import VerySimpleWithOpenID 17.8 + 17.9 +# Get a simple Web site. 17.10 + 17.11 +host = "http://localhost:8080" # or an absolute URL (without path) 17.12 +secret_key = "this_must_be_secret" 17.13 + 17.14 +resource = VerySimpleWithOpenID.get_site(host, secret_key) 17.15 + 17.16 +# Special magic incantation. 17.17 + 17.18 +print "Serving..." 17.19 +deploy(resource, handle_errors=0) 17.20 + 17.21 +# vim: tabstop=4 expandtab shiftwidth=4