Update of /cvsroot/babeldoc/babeldoc/modules/core/build/core/scripts
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10822/modules/core/build/core/scripts
Added Files:
attrdefault.js attrcheck.js servicexml.js
Log Message:
Minor update
--- NEW FILE: attrdefault.js ---
/**
* This script checks for the presence of attributes on the document
* and if the attribute is not found sets it to the default value
*
* It expects the associative (complex) configuration option attrs.*
* to be defined otherwise it does nothing.
*/
var getAttr=new Array;
getAttr[0]="attrs";
var nvpairarray=stage.getOptionList(getAttr);
var length = nvpairarray.length;
var keys = document.keys();
for(var i = 0; i < length; ++i) {
var pair = nvpairarray[i];
var attrname = pair.getFirst();
var attrdefault = pair.getSecond();
if(!keys.contains(attrname)) {
document.put(attrname, attrdefault);
}
}
--- NEW FILE: attrcheck.js ---
/**
* This script checks for the presence of attributes on the document
* and prints the associated message if the attribute is not found.
*
* It expects the associative (complex) configuration option attrs.*
* to be defined otherwise it does nothing.
*/
var getAttr=new Array;
getAttr[0]="attrs";
var nvpairarray=stage.getOptionList(getAttr);
var length = nvpairarray.length;
var keys = document.keys();
for(var i = 0; i < length; ++i) {
var pair = nvpairarray[i];
var attrname = pair.getFirst();
var attrerror = pair.getSecond();
if(!keys.contains(attrname)) {
stage.setError(attrerror);
break;
}
}
--- NEW FILE: servicexml.js ---
/**
* For all the service types with the same prefix (ie. PipelineStage.), get the
* IConfigInfo object and then on each one, call the toXml method. Aggregate the
* all the xml files.
*
* Configuration files:
*
* 1. serviceType - the serviceType to scan for.
* 2. rootElement - the root element in the document
*
*/
importClass(Packages.com.babeldoc.core.service.ServiceFactory);
var serviceType = stage.getOptions("serviceType");
var rootElement = stage.getOptions("rootElement");
var services = ServiceFactory.getAllServices(serviceType);
var keyset = services.keySet();
var keyiter = keyset.iterator();
var bufr = new java.lang.StringBuffer();
bufr.append("<"+rootElement+">");
while(keyiter.hasNext()) {
var key = serviceType+"."+keyiter.next();
var obj = ServiceFactory.getService(key);
var info = obj.getInfo();
if(info!=null) {
var xmlfrag = info.toXml();
bufr.append(xmlfrag);
}
}
bufr.append("</"+rootElement+">");
document.setBytes(bufr.toString().getBytes());
document.setMimeType("text/xml");
|