major overhaul of the manage app's api-documentation functions.
things can now be rendered to static html, new helma features are supported (prototype extension), everyhting is done in a nice and clean way with skins.
This commit is contained in:
parent
76bbe4053b
commit
7633e98eea
59 changed files with 1052 additions and 578 deletions
|
@ -1,17 +1,67 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
||||
<HTML>
|
||||
<% skin name="head" %>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title></title>
|
||||
<style type="text/css">
|
||||
|
||||
body, p, td, th, li {
|
||||
font-family: verdana, sans-serif;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
big.top {
|
||||
font-size: 18pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
big {
|
||||
font-size: 13pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight:bold;
|
||||
color: #cc3333;
|
||||
text-decoration:none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
.navig {
|
||||
font-size: 9px;
|
||||
text-decoration: none;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
li {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
|
||||
.mainbox {
|
||||
border-color:#999999;
|
||||
padding-top:5px;
|
||||
padding-bottom:5px;
|
||||
border-bottom-width:1px;
|
||||
border-bottom-style:dotted;
|
||||
}
|
||||
|
||||
.headline {
|
||||
font-weight:bold;
|
||||
background:#dfdfdf;
|
||||
border-color:#999999;
|
||||
padding-top:5px;
|
||||
padding-bottom:5px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table width="90%" border="0" cellspacing="1" cellpadding="5" bgcolor="#000000">
|
||||
<tr>
|
||||
<td width="200" nowrap align="left" valign="top" bgcolor="#cccc99">
|
||||
<p><a href="<% root.href action="main" %>"><img src="<% root.href action="image" %>" title="helma" border="0" width="174" height="35" align="baseline" style="border-width:3px;border-color:white;"></a></p>
|
||||
<% docapplication.skin name="navig" %></td>
|
||||
<td align="left" valign="top" bgcolor="#ffffff"><% response.body %></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<% response.body %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -10,11 +10,10 @@ function scheduler() {
|
|||
|
||||
|
||||
/**
|
||||
* initializes app.data.requestStat storage on startup,
|
||||
* initializes app.data.stat storage on startup,
|
||||
* creates app.data.addressFilter
|
||||
*/
|
||||
function onStart() {
|
||||
app.data.requestStat = new HopObject();
|
||||
app.data.addressFilter = createAddressFilter();
|
||||
}
|
||||
|
||||
|
@ -47,29 +46,28 @@ function createAddressFilter() {
|
|||
|
||||
|
||||
/**
|
||||
* updates the request stats in app.data.requestStat every 5 minutes
|
||||
* updates the stats in app.data.stat every 5 minutes
|
||||
*/
|
||||
function appStat() {
|
||||
if ( app.data.requestStat==null ) {
|
||||
app.data.requestStat = new HopObject();
|
||||
}
|
||||
if( (new Date()-300000) < app.data.requestStat.lastRun ) {
|
||||
function appStat () {
|
||||
if (app.data.stat==null)
|
||||
app.data.stat = new HopObject ();
|
||||
if ((new Date()-300000) < app.data.stat.lastRun)
|
||||
return;
|
||||
}
|
||||
var arr = root.getApplications();
|
||||
for ( var i=0; i<arr.length; i++ ) {
|
||||
var tmp = app.data.requestStat.get(arr[i].getName());
|
||||
if ( tmp==null ) {
|
||||
var arr = root.getApplications ();
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
var tmp = app.data.stat.get (arr[i].getName());
|
||||
if (tmp==null) {
|
||||
tmp = new HopObject();
|
||||
tmp.lastTotal = 0;
|
||||
tmp.last5Min = 0;
|
||||
}
|
||||
var ct = arr[i].getRequestCount();
|
||||
tmp.last5Min = ct - tmp.lastTotal;
|
||||
tmp.lastTotal = ct;
|
||||
app.data.requestStat.set(arr[i].getName(), tmp);
|
||||
tmp.lastTotalRequestCount = 0;
|
||||
tmp.lastTotalErrorCount = 0;
|
||||
}
|
||||
tmp.requestCount = arr[i].getRequestCount () - tmp.lastTotalRequestCount;
|
||||
tmp.lastTotalRequestCount = arr[i].getRequestCount ();
|
||||
tmp.errorCount = arr[i].getErrorCount () - tmp.lastTotalErrorCount;
|
||||
tmp.lastTotalErrorCount = arr[i].getErrorCount ();
|
||||
app.data.stat.set (arr[i].getName(), tmp);
|
||||
}
|
||||
app.data.requestStat.lastRun = new Date();
|
||||
app.data.stat.lastRun = new Date();
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,7 +75,7 @@ function appStat() {
|
|||
* utility function to sort object-arrays by name
|
||||
*/
|
||||
function sortByName(a,b) {
|
||||
if ( a.name>b.name )
|
||||
if ( a.name>b.name)
|
||||
return 1;
|
||||
else if ( a.name==b.name )
|
||||
return 0;
|
||||
|
@ -132,8 +130,6 @@ function checkAuth(appObj) {
|
|||
// check against application
|
||||
var appUsername = appObj.getProperty("adminusername");
|
||||
var appPassword = appObj.getProperty("adminpassword");
|
||||
if ( appUsername==null || appUsername=="" || appPassword==null || appPassword=="" )
|
||||
return forceStealth();
|
||||
if ( md5username==appUsername && md5password==appPassword )
|
||||
return true;
|
||||
}
|
||||
|
@ -149,7 +145,7 @@ function checkAddress() {
|
|||
app.log("denied request from " + req.data.http_remotehost );
|
||||
// forceStealth seems a bit like overkill here.
|
||||
// display a message that the ip address must be added to server.properties
|
||||
res.write ("Access to address "+req.data.http_remotehost+" denied.");
|
||||
res.write ("Access from address "+req.data.http_remotehost+" denied.");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -169,14 +165,7 @@ function forceAuth(realm) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* response is reset to 404 / notfound
|
||||
*/
|
||||
function forceStealth() {
|
||||
res.reset();
|
||||
res.status = 404;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -302,3 +291,16 @@ function formatCount(ct, par) {
|
|||
else
|
||||
return par.plural;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* tries to make out if this server is running linux from java's system properties
|
||||
*/
|
||||
function isLinux () {
|
||||
var str = java.lang.System.getProperty("os.name");
|
||||
return (str!=null && str.toLowerCase().indexOf("linux")!=-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
176
Global/renderFunctions.js
Normal file
176
Global/renderFunctions.js
Normal file
|
@ -0,0 +1,176 @@
|
|||
|
||||
|
||||
function renderLink (docEl, param) {
|
||||
var text = "";
|
||||
if (docEl.getType () == docEl.APPLICATION || docEl.getType () == docEl.PROTOTYPE) {
|
||||
text = docEl.getName ();
|
||||
} else if (docEl.getType () == docEl.SKIN) {
|
||||
text = docEl.getName () + ".skin";
|
||||
} else if (docEl.getType () == docEl.MACRO) {
|
||||
if (docEl.getParentElement () && docEl.getParentElement().getName()!="global") {
|
||||
text = docEl.getParentElement ().getName () + ".";
|
||||
}
|
||||
var str = docEl.getName ();
|
||||
if (str.indexOf("_macro")) {
|
||||
text += str.substring (0, str.length-6);
|
||||
}
|
||||
} else if (docEl.getType () == docEl.FUNCTION) {
|
||||
var text = docEl.getName () + " (";
|
||||
var arr = docEl.listParameters ();
|
||||
for (var i=0; i<arr.length ;i++) {
|
||||
text += arr[i];
|
||||
if (i<arr.length-1)
|
||||
text += ", ";
|
||||
}
|
||||
text += ")";
|
||||
} else {
|
||||
text = docEl.getName ();
|
||||
}
|
||||
param.href = docEl.href ("main");
|
||||
if (!param.target) {
|
||||
param.target = "main";
|
||||
}
|
||||
return renderLinkTag (param) + text + '</a>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function renderLinkTag (param) {
|
||||
var sb = new java.lang.StringBuffer ();
|
||||
sb.append ('<a');
|
||||
for (var i in param) {
|
||||
sb.append (' ');
|
||||
sb.append (i);
|
||||
sb.append ('="');
|
||||
sb.append (param[i]);
|
||||
sb.append ('"');
|
||||
}
|
||||
sb.append ('>');
|
||||
return sb.toString ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* renders the name of the location relative to the application
|
||||
* root.
|
||||
*/
|
||||
function renderLocation (docEl, param) {
|
||||
var f = docEl.getLocation ();
|
||||
if (f.isDirectory ())
|
||||
return f.getName ();
|
||||
else {
|
||||
return f.getParentFile ().getName () + "/" + f.getName ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* renders tag list.
|
||||
* @param param.skin skin to render on found DocTags
|
||||
* @param param.separator String printed between tags
|
||||
* @param param.type type string (param|return|author|version|see) to filter tags.
|
||||
*/
|
||||
function renderTags (docEl, param) {
|
||||
var skinname = (param.skin) ? param.skin : "main";
|
||||
var type = -1;
|
||||
if (param.type=="param" || param.type=="params")
|
||||
type = Packages.helma.doc.DocTag.PARAMETER;
|
||||
else if (param.type=="return" || param.type=="returns")
|
||||
type = Packages.helma.doc.DocTag.RETURN;
|
||||
else if (param.type=="author")
|
||||
type = Packages.helma.doc.DocTag.AUTHOR;
|
||||
else if (param.type=="version")
|
||||
type = Packages.helma.doc.DocTag.VERSION;
|
||||
else if (param.type=="see")
|
||||
type = Packages.helma.doc.DocTag.SEE;
|
||||
else if (param.type=="deprecated")
|
||||
type = Packages.helma.doc.DocTag.DEPRECATED;
|
||||
else if (param.type=="overrides")
|
||||
type = Packages.helma.doc.DocTag.OVERRIDES;
|
||||
var str = "";
|
||||
var arr = docEl.listTags ();
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
if (arr[i].getType () == type) {
|
||||
if (param.type=="see" || param.type=="overrides") {
|
||||
param.link = renderReference (arr[i], docEl);
|
||||
}
|
||||
str += arr[i].renderSkinAsString (skinname, param);
|
||||
str += (param.separator) ? param.separator : "";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* renders a reference to functions in other prototypes, masks
|
||||
* urls in a see tag
|
||||
* (see- and overrides-tags)
|
||||
* @param docTagObj
|
||||
* @param docEl needed to be able to walk up to application object
|
||||
*/
|
||||
function renderReference (docTagObj, docEl) {
|
||||
// prepare the text:
|
||||
var text = docTagObj.getText ();
|
||||
text = new java.lang.String (text);
|
||||
text = text.trim ();
|
||||
if (text.indexOf("http://")==0) {
|
||||
// an url is a simple job
|
||||
return '<a href="' + text + '" target="_new">' + text + '</a>';
|
||||
} else {
|
||||
// make sure we only use the first item in the text so that unlinked comments
|
||||
// can follow, store & split the that
|
||||
var tok = new java.util.StringTokenizer (text);
|
||||
var tmp = tok.nextToken ();
|
||||
text = " " + text.substring (tmp.length + 1);
|
||||
var parts = tmp.split(".");
|
||||
// try to find the application object
|
||||
var obj = docEl;
|
||||
while (obj!=null) {
|
||||
if (obj.getType () == Packages.helma.doc.DocElement.APPLICATION) {
|
||||
var appObj = obj;
|
||||
break;
|
||||
}
|
||||
obj = obj.getParentElement ();
|
||||
}
|
||||
var protoObj = appObj.getChildElement ("prototype_" + parts[0]);
|
||||
if (protoObj==null) {
|
||||
// prototype wasn't found, return the unlinked tag
|
||||
return tmp + text;
|
||||
}
|
||||
if (parts.length==1) {
|
||||
// no function specified, return the linked prototype
|
||||
return '<a href="' + protoObj.href ("main") + '">' + format (tmp) + '</a>' + text;
|
||||
}
|
||||
// try to find a function object:
|
||||
var arr = protoObj.listChildren ();
|
||||
for (var i=0; i<arr.length; i++) {
|
||||
if (arr[i].getName () == parts [1]) {
|
||||
return '<a href="' + arr[i].href("main") + '">' + format(tmp) + '</a>' + text;
|
||||
}
|
||||
}
|
||||
// function not found:
|
||||
return tmp + text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* function rendering a comment.
|
||||
* @param param.length comment is shortened to the given length.
|
||||
* @returns string
|
||||
*/
|
||||
function renderComment (docEl, param) {
|
||||
var str = docEl.getComment ();
|
||||
if (param.length) {
|
||||
if (param.length < str.length) {
|
||||
return str.substring (0, param.length) + " ...";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue