2006-04-24 06:58:02 +00:00
|
|
|
/*
|
|
|
|
* Helma License Notice
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Helma License
|
|
|
|
* Version 2.0 (the "License"). You may not use this file except in
|
|
|
|
* compliance with the License. A copy of the License is available at
|
|
|
|
* http://adele.helma.org/download/helma/license.txt
|
|
|
|
*
|
|
|
|
* Copyright 1998-2006 Helma Software. All Rights Reserved.
|
|
|
|
*
|
2007-01-30 17:53:00 +00:00
|
|
|
* $RCSfile: Skin.js,v $
|
2007-09-28 13:16:38 +00:00
|
|
|
* $Author$
|
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
2006-04-24 06:58:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Fields and methods of the helma.Skin class.
|
2007-12-13 12:21:48 +00:00
|
|
|
* <br /><br />
|
|
|
|
* To use this optional module, its repository needs to be added to the
|
|
|
|
* application, for example by calling app.addRepository('modules/helma/Skin.js')
|
2007-01-30 17:53:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// define the helma namespace, if not existing
|
2006-04-24 06:58:02 +00:00
|
|
|
if (!global.helma) {
|
|
|
|
global.helma = {};
|
|
|
|
}
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* Constructs a new instance of helma.Skin
|
|
|
|
* @class Instances of this class represent a Helma skin. In addition
|
|
|
|
* to the standard skin functionality this class allows creation of
|
|
|
|
* a skin based on a Base64 encoded source.
|
|
|
|
* @param {String} source The source of the skin
|
|
|
|
* @param {Boolean} encFlag If true the source will be Base64-decoded.
|
|
|
|
* @constructor
|
|
|
|
* @returns A newly created instance of helma.Skin
|
|
|
|
*/
|
2006-04-24 06:58:02 +00:00
|
|
|
helma.Skin = function(source, encFlag) {
|
2007-01-30 17:53:00 +00:00
|
|
|
/** @ignore */
|
2006-04-24 06:58:02 +00:00
|
|
|
var Base64 = Packages.helma.util.Base64;
|
|
|
|
|
|
|
|
if (!encFlag) {
|
|
|
|
var skin = createSkin(source);
|
|
|
|
} else {
|
|
|
|
var encoded = source;
|
|
|
|
source = new java.lang.String(source);
|
|
|
|
var bytes = Base64.decode(source.toCharArray());
|
|
|
|
var skin = createSkin(new java.lang.String(bytes, "UTF-8"));
|
|
|
|
}
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/** @ignore */
|
2006-04-24 06:58:02 +00:00
|
|
|
this.toString = function() {
|
|
|
|
return source;
|
|
|
|
};
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the source of the skin as Base64 encoded string
|
|
|
|
* @returns The source of the skin as Base64 encoded string
|
|
|
|
* @type String
|
|
|
|
*/
|
2006-04-24 06:58:02 +00:00
|
|
|
this.valueOf = function() {
|
2007-01-30 17:53:00 +00:00
|
|
|
if (encFlag) {
|
2006-04-24 06:58:02 +00:00
|
|
|
return encoded;
|
2007-01-30 17:53:00 +00:00
|
|
|
}
|
2006-04-24 06:58:02 +00:00
|
|
|
var bytes = new java.lang.String(source).getBytes("UTF-8");
|
|
|
|
return new java.lang.String(Base64.encode(bytes));
|
|
|
|
};
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* Renders the skin.
|
|
|
|
* @param {Object} param An optional parameter object to pass to the skin.
|
|
|
|
*/
|
2006-04-24 06:58:02 +00:00
|
|
|
this.render = function(param) {
|
|
|
|
return renderSkin(skin, param);
|
|
|
|
};
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the rendered skin.
|
|
|
|
* @param {Object} param An optional parameter object to pass to the skin.
|
2007-02-24 13:27:15 +00:00
|
|
|
* @type String
|
2007-01-30 17:53:00 +00:00
|
|
|
*/
|
2006-04-24 06:58:02 +00:00
|
|
|
this.renderAsString = function(param) {
|
|
|
|
return renderSkinAsString(skin, param);
|
|
|
|
};
|
|
|
|
|
2007-01-30 17:53:00 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the skin contains a macro with the name
|
|
|
|
* and optional handler passed as argument.
|
|
|
|
* @param {String} name The name of the macro
|
|
|
|
* @param {String} handler An optional macro handler name
|
|
|
|
* @returns True if the skin contains this macro at least once,
|
|
|
|
* false otherwise.
|
|
|
|
* @type Boolean
|
|
|
|
*/
|
2006-04-24 06:58:02 +00:00
|
|
|
this.containsMacro = function(name, handler) {
|
|
|
|
res.push();
|
|
|
|
res.write("<% *");
|
|
|
|
if (handler) {
|
|
|
|
res.write(handler);
|
|
|
|
res.write(".");
|
|
|
|
}
|
|
|
|
res.write(name);
|
|
|
|
res.write(" *%>");
|
|
|
|
var re = new RegExp(res.pop(), "g");
|
|
|
|
return re.test(source);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i in this)
|
|
|
|
this.dontEnum(i);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
helma.lib = "Skin";
|
|
|
|
helma.dontEnum(helma.lib);
|
|
|
|
for (var i in helma[helma.lib])
|
|
|
|
helma[helma.lib].dontEnum(i);
|
|
|
|
for (var i in helma[helma.lib].prototype)
|
|
|
|
helma[helma.lib].prototype.dontEnum(i);
|
|
|
|
delete helma.lib;
|