/**************************************************************/
======String Function For Domino Web Using==Start=======
------By FangZeYu 2003.10.28
------Secondly 2005.05.14
Location.HREF/URL Analysys
Functions For DOMINO Web Development
As String.prototype.Function
允许http://或者https://这样的url,其余的协议表达,不属于本函数群针对范围。
以下约定,以便于函数处理:
①、lcase;②、/或者其escapeString向/的转换不在这里进行;
③、不承认其它任何的异常状态,预期的url是完全合法的,
本函数群属于一个对象类:DOMUrl,出于使用便利的目的,同时将这些做在String.prototype下,
对象应该拥有static Function,DOMUrl.fun1(s1 , pars)
等效于:(new DOMUrl(s1)).fun1(pars);
等效于:s1.fun1(pars);
以下内容引自于Domino Designer Help中的相关章节:
Domino URL commands have the syntax:
http://Host/DominoObject?Action&Arguments
Where
Host = a DNS entry or an IP address
DominoObject = a Domino construct (for example, a database, view, document, form, navigator, agent, and so on). URL commands for accessing DominoObjects use the following syntax: http://Host/Database/DominoObject?Action&Arguments where Database = the database in which the DominoObject resides.
Action = the desired operation on the specified DominoObject (For example, ?OpenDatabase, ?OpenView, ?OpenDocument, ?EditDocument, ?OpenForm, and so on).
Arguments = a qualifier of the action (for example, Count = 10 combined with the ?OpenView action limits the number of rows displayed in a view to 10).
一般的来说,基本domino web url有以下的格式(http和https等同):
打开数据库:http://server_host:port/dbpath/dbname?opendatabase
打开视图: http://server_host:port/dbpath/dbname/viewname?(openview|readViewEntries)
打开文档: http://server_host:port/dbpath/dbname/viewname/unid?(opendocument|editdocument)
创建文档: http://server_host:port/dbpath/dbname/formname?(openform|createdocument)
代理: http://server_host:port/dbpath/dbname/agentName?openagent
导航: http://server_host:port/dbpath/dbname/navigatorName?opennavagitor
帧:
domino服务器自身的“定位”方式有非一般的情况,需要注意的地方有:
支持内容方式:
①、path信息中,可能包含有连续的两个“/”的路径,这个是合法的,在本函数群中,支持该情况,但是强烈建议避免该情况。
②、任何一个内部的设计元素,view、form、page、agent、navagitor等等,除了name或者alias以外,还可以用id、unid来定位
③、对于document,在视图检索的时候,还可以支持key方式;
④、视图本身的名称中,可能就是一个多层次的表现:如视图名称为folder1/sub2,url表现就是folder1/sub2。一般情况下请不要使用这样的名称。
非支持内容方式: !注意!
①、一般的来说,数据库定位是dbpath/dbname=dbfilename这个方式,但是也可以通过副本id,或者还有别的方式,!不支持!
②、action是implicict的。在no pars的情况下。
domGetServerName: 获取server信息,server 的hostName or ipAddress
domGetSName
domGetServer: 获取http://**..com.cn这样的内容
domGetScheme: 获取协议名称,http or https
domGetPort: port信息,返回一个代表正整数的字符串或者空字符串,注意:后面的情况可能是为空,也可能是出错
domGetServerFull: 获取整个的server和port信息,http://**.com.cn:port这样的内容,如果没有port信息,则和domGetServer一样
domGetFullServer
domGetDatabase: 获取http://**.com.cn/path/example1.nsf这部分信息
domGetDBName: 获取数据库名称,不包含目录信息
domGetDBPath: 获取数据库的路径信息。 !注意!本信息原本应该有根目录标志“/”作为开头字符,出于外部程序处理的便利,将其丢弃。下同。
domGetPathName: 获取数据库的全路径信息DBPath+DBName
domGetView: 获取url中一直到指定viewname信息的部分
domGetViewName: 获取viewname信息
domGetVName
domGetAction: 获取action
domGetObject: 获取url中到?之前的部分
domGetObjectName: 获取object的名称,不包括前面的信息。对于数据库,则等同于DBName,数据库内元素则是该元素的名称或者id
domGetOName:
domGetParameter: 获取par值,对于无参数或者开关参数,返回空字符串,这样的情况下,如果必要,请用domHasPar来辅助
domGetPar
domHasParameter: 检测是否存在参数,一般情况下,对于开关参数使用该方法
domHasPar
domGetAllPars: 返回所有的参数,以list的格式,注意,开关参数,在这里返回的是pars[parTag]=null,这样的情况下,对于四种值可以分开:
domGetAllParameters ①、par="value",一般值 ②、par=,空字符串 ③、par,开关值开,返回null ④、无,开关值关,返回的是undefined
domGetAllParTags: 返回所有的参数的names,以数组的格式。
domGetAllParNames
/**************************************************************/
function DOMUrl(sDomUrl){
this._url=sDomUrl;
}
_p=DOMUrl.prototype;
_p.toString=function(){
return this._url;
}
function DOMUrl._doRegCheck(s1 , reg1){
try{
var arr1=reg1.exec(s1);
if(!arr1) return "";
return arr1[1];
}
catch(e1){
throw(e1);
}
}
_p.domGetServer=function(){
return DOMUrl._doRegCheck(this , new RegExp("^(https?://[^/:]+)" , "i"));
}
_p.domGetServerName=_p.domGetSName=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://([^/:]+)(?::|/)" , "i"));
}
_p.domGetScheme=function(){
return DOMUrl._doRegCheck(this , new RegExp("^(http|https):" , "i"));
}
_p.domGetPort=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://[^/:]+:([//d]+)/" , "i"));
}
_p.domGetServerFull=_p.domGetFullServer=function(){
return DOMUrl._doRegCheck(this , new RegExp("^(https?://[^/]+)/" , "i"));
}
_p.domGetDatabase=function(){
return DOMUrl._doRegCheck(this , new RegExp("^(https?://[^/]+(?:/[^/]*)*/[^/]+//.nsf)(?://?|/)" , "i"));
}
_p.domGetDBName=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://[^/]+(?:/[^/]*)*/([^/]+//.nsf)(?://?|/)" , "i"));
}
_p.domGetDBPath=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://[^/]+((?:/[^/]*)*)/[^/]+//.nsf(?://?|/)" , "i")).substr(1);
}
_p.domGetPathName=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://[^/]+((?:/[^/]*)*/[^/]+//.nsf)(?://?|/)" , "i")).substr(1);
}
_p.domGetView=function(){
return DOMUrl._doRegCheck(this , new RegExp("^(https?://[^/]+(?:/[^/]*)*/[^/]+//.nsf(?:/[^/]+)+)(?://?openview|//?readviewentries|/[^//?]+//?)" , "i"));
}
_p.domGetViewName=_p.domGetVName=function(){
return DOMUrl._doRegCheck(this , new RegExp("^https?://[^/]+(?:/[^/]*)*/[^/]+//.nsf((?:/[^/]+)+)(?://?openview|//?readviewentries|/[^//?]+//?)" , "i")).substr(1);;
}
_p.domGetAction=function(){
return DOMUrl._doRegCheck(this , /^https?:[^/?]+/?([^&]+)/i);
}
_p.domGetParameter=_p.domGetPar=function(sTag){
return DOMUrl._doRegCheck(this , new RegExp("&"+sTag+"=([^&]+)" , "i"));
}
_p.domHasParameter=_p.domHasPar=function(sTag){
return (new RegExp("&"+sTag+"(=|&|//b)" , "i")).exec(this)!=null ;
}
_p.domGetObject=function(){
return DOMUrl._doRegCheck(this , /^(https?:[^/?]+)/?[^&]+/i);
}
_p.domGetObjectName=_p.domGetOName=function(){
return DOMUrl._doRegCheck(this , /^https?:[^/?]+//([^//]+)/?[^&]+/i);
}
_p.domGetAllPars=_p.domGetAllParameters=function(){
var ret1={};
var sAP=DOMUrl._doRegCheck(this , new RegExp("https?://[^//?]+//?(.*)" , "i"));
var arr1=sAP.split("&");
for (var i=1 ; i<arr1.length; i++){
var arr2=arr1[i].split("=");
if(!arr2[1]) arr2[1]=null;
ret1[arr2[0]]=arr2[1];
}
return ret1;
}
_p.domGetAllParNames=_p.domGetAllParTags=function(){
var ret1=new Array();
var sAP=DOMUrl._doRegCheck(this , new RegExp("https?://[^//?]+//?(.*)" , "i"));
var arr1=sAP.split("&");
for (var i=1 ; i<arr1.length; i++)
ret1[i-1]=arr1[i].split("=")[0];
return ret1;
}
// 做prototype函数的static格式
function _drawStatic(_cName , _pFunName){
var ss="";
ss+=_cName+"."+_pFunName;
ss+="=function(){";
ss+=" var s1=arguments[0];"
ss+=" var _funName='"+_pFunName+"';"
ss+=" var _o=new "+_cName+"(s1);"
ss+=' var ss=_funName+"( ";'
ss+=' for (var i=1 ; i<arguments.length; i++)'
ss+=' ss+="arguments["+i+"] ,";'
ss+=' ss=ss.substr(0 , ss.length-1)+")";'
ss+=' return eval("_o."+ss);'
ss+="};"
eval(ss);
}
function DOMUrl._doPrototypes(_c){
var reg1=new RegExp("^function[//s]+([//S]+)[//s]?//(" , "i");
var arr1=reg1.exec(_c.toString());
var _cName=arr1[1];
for (sTag in _c.prototype){
if ("toString valueOf".indexOf(sTag)>-1) continue;
if (typeof(_c.prototype[sTag])!="function") continue;
eval("String.prototype."+sTag+"="+_cName+".prototype."+sTag);
_drawStatic(_cName , sTag);
}
}
DOMUrl._doPrototypes(DOMUrl);
/**************************************************************/
======String Function For Domino Web Using==End=========
/**************************************************************/
/**************************************************************/
======Array Function For Web Using=========Start=======
---- From Bindows --
/**************************************************************/
Array.prototype.indexOf=function(o){
for(var i=0;i<this.length;i++)
if(this[i]==o)return i;
return -1;
};
Array.prototype.lastIndexOf=function(o){
for(var i=this.length-1;i>=0;i--)
if(this[i]==o)return i;
return -1;
};
Array.prototype.contains=function(o){
return this.indexOf(o)!= -1;
};
Array.prototype.copy=function(o){
return this.concat();
};
Array.prototype.insertAt=function(o,i){
this.splice(i,0,o);
};
Array.prototype.insertBefore=function(o,o2){
var i=this.indexOf(o2);
if(i== -1)this.push(o);
else this.splice(i,0,o);
};
Array.prototype.removeAt=function(i){
this.splice(i,1);
};
Array.prototype.remove=function(o){
var i=this.indexOf(o);
if(i!= -1)this.splice(i,1);
};
Array.prototype.add=function(o){
}
Array.prototype.append=function(o,bCanRepeat){
this.splice(this.length,0,o);
}
Array.prototype.trim=function(){
var i;
for (i=0; i<this.length;i++)
if (this[i]=="")
this.removeAt(i--);
return this;
}
Array.prototype.addArray=function(arr1){
var i;
for (i=0; i<arr1.length ; i++)
this.add(arr1[i]);
return this;
}
/**************************************************************/
======Array Function For Web Using==End=========
/**************************************************************/
function _getFieldValue(vField){
if (typeof(vField)=="string") vField=document.all(vField);
var sRet="" , vRet=new Array();
if (vField[0] && !vField.tagName){ //如果是多个域
for (var i=0 ; i<vField.length ; i++){
var _t=_getFieldValue(vField[i]);
if (_t!=null)
vRet[vRet.length]=_t;
}
return vRet;
}
// 如果是select
if (vField.tagName=="SELECT"){
for (var i=0; i<vField.options.length ;i++)
if (vField.options[i].selected)
vRet[vRet.length]=(vField.options[i].value)?vField.options[i].value:vField.options[i].text;
return vRet;
}
// 处理textarea
if (vField.tagName=="TEXTAREA")
return vField.value;
// 对于其余的非input元素,抛弃。
if (vField.tagName!="INPUT")
return null;
// 处理一般input
if (".button.file.hidden.password.text.".indexOf(vField.type.toLowerCase())>0){
return vField.value;
}
// 处理radio,checkbox
if (".radion.checkbox.".indexOf(vField.type.toLowerCase())>0){
if (vField.checked) return vField.value;
else return null;
}
return null;
}
/**************************************************************/
======Function Function For Domino Web Using==End=========
/**************************************************************/
Function.prototype.createdByNewInstance=function(){
var _caller=this.caller;
if (!_caller) return false;
var _callerName=_caller.getName();
var _arrName=_callerName.split(".");
if (_arrName.length<2) return false;
if (_arrName.pop()!="newInstance") return false;
var _myName=this.getName();
if(_myName.join(".")!=_myName) return false;
return true;
}
Function.prototype.getName=function(){
var _reg=/function(?:[/s]+([^/s/(]+)[/s]*)?/([^/)]*/)/;
var _arr1=_reg.exec(this.toString());
if(!_arr1) return "";
return _arr1[1];
}
Function.prototype.addInstance=function(_ins){
if(!this._instances) this._instances=new Array();
this._instances.push(_ins);
}
Function.prototype.countInstance=function(){
if(!this._instances) return 0;
return this._instances.length;
}
Function.prototype.getInstances=function(){
if (!this._instances) this._instances=new Array();
return this._instances;
}
Function.prototype.delInstance=function(i){
if (i>this.countInstance()) return false;
this._instances.splice(i-1,1);
return true;
}
Function.prototype.newInstance=function(){
}
String.prototype.trim=function(){
return this.replace(/(^/s+)|/s+$/g,"");
}