SDKNode.jsx
Summary
Supporting class; backing node for extension handling samples.
See:
Class Summary
|
SDKNode |
Supporting class; backing node for extension handling samples. |
function SDKNode(name, iscontainer)
{
this.children = new Array();
this.childrenNames = {};
this.name = name;
this.path = "/" + name;
this.parent = undefined;
this.container = iscontainer;
this.iconPath = new File($.fileName).parent.fsName + "/resources";
this.metadata = undefined;
this.setCustomInfosetData();
}
SDKNode.prototype.addNode = function(node)
{
if(!this.getChildNode(node.getName()))
{
if(this.name.substr(0,10) != "SearchNode")
{
node.parent = this;
}
this.childrenNames[node.name] = node;
this.children.push(node);
return true;
}
return false;
}
SDKNode.prototype.getFirstChildNode = function() { return this.children[0]; }
SDKNode.prototype.getChildNode = function(name)
{
SDKNode.counter++;
return this.childrenNames[name];
}
SDKNode.prototype.findChildNode = function(name)
{
var found = this.getChildNode(name);
if(found instanceof SDKNode)
{
return found;
}
else
{
for(index in this.children)
{
found = this.children[index].findChildNode(name);
if(found instanceof SDKNode)
{
return found;
}
}
}
return false;
}
SDKNode.prototype.findChildNodeFromPath = function(uri)
{
var pathParts = uri.split("/");
var currentNode = this;
var searching = true;
var pos = 1;
while(searching)
{
if(typeof pathParts[pos+2] != "undefined")
{
pos++;
currentNode = currentNode.getChildNode(pathParts[pos]);
}
else
{
currentNode = currentNode.getChildNode(pathParts[pos+1]);
searching = false;
}
}
if(currentNode instanceof Object && currentNode != false)
{
return currentNode;
}
else
{
return false;
}
}
SDKNode.prototype.getChildren = function(){ return this.children; }
SDKNode.prototype.getChildrenNames = function(){ return this.childrenNames; }
SDKNode.prototype.getPath = function()
{
var path = this.path;
var parent = this.parent;
while(parent)
{
var fullPath = parent.path + path;
parent = parent.getParent();
path = fullPath;
}
return path;
}
SDKNode.prototype.listChildren = function()
{
var kids = this.getChildren();
for(var i = 0;i < kids.length;i++)
{
$.writeln(kids[i].getPath());
kids[i].listChildren();
}
}
SDKNode.prototype.hasChildren = function() { return this.children.length > 0; }
SDKNode.prototype.getParent = function() { return this.parent; }
SDKNode.prototype.removeNode = function(node)
{
var name = node.getName();
delete this.childrenNames[name];
var tmp = new Array();
for(var i = 0;i < this.children.length;i++)
{
if(this.children[i].name != name)
{
tmp.push(this.children[i]);
}
}
this.children = tmp;
}
SDKNode.prototype.updateNode = function(node, oldName)
{
delete this.childrenNames[oldName];
this.childrenNames[node.getName()] = node;
}
SDKNode.prototype.cloneNode = function()
{
var c = new Object();
for( var i in this)
{
c[i] = this[i]
}
c.parent = undefined;
return c;
}
SDKNode.prototype.setName = function(name)
{
var oldName = this.name;
this.name = name;
this.path = "/" + name;
if(this.parent != undefined)
{
this.parent.updateNode(this, oldName);
}
}
SDKNode.prototype.isContainer = function() { return this.container; }
SDKNode.prototype.getName = function() { return this.name; }
SDKNode.prototype.getFileUrl = function()
{
return "file:///" + this.iconPath + "/BEHFileIcon512.png";
}
SDKNode.prototype.getIcon = function()
{
if(this.isContainer())
{
return new BitmapData(this.iconPath + "/BEHFolderIcon32.png");
}
else
{
return new BitmapData(this.iconPath + "/BEHFileIcon32.png");
}
}
SDKNode.prototype.getThumb = function()
{
if(this.isContainer())
{
return new BitmapData(this.iconPath + "/BEHFolderIcon128.png");
}
else
{
return new BitmapData(this.iconPath + "/BEHFileIcon128.png");
}
}
SDKNode.prototype.getPreview = function()
{
if(this.isContainer())
{
return new BitmapData(this.iconPath + "/BEHFolderIcon512.png");
}
else
{
return new BitmapData(this.iconPath + "/BEHFileIcon512.png");
}
}
SDKNode.prototype.getMetadata = function()
{
if(this.metadata == undefined)
{
var xmpMeta = new XMPMeta( );
var d = new Date()
d.setFullYear(2007,0,1);
d.setHours(1, 0, 0, 0);
var xmptoday = new XMPDateTime(d);
xmptoday.convertToLocalTime();
xmpMeta.setProperty( XMPConst.NS_EXIF, "DateTime", xmptoday);
xmpMeta.setProperty( XMPConst.NS_EXIF, "DateTimeOriginal", xmptoday);
xmpMeta.setProperty(XMPConst.NS_XMP, "CreatorTool", "Bridge SDK");
xmpMeta.setProperty(XMPConst.NS_XMP, "CreateDate", xmptoday);
xmpMeta.setProperty(XMPConst.NS_XMP, "MetadataDate", xmptoday);
xmpMeta.setProperty(XMPConst.NS_DC, "creator", "Created by the Bridge SDK");
xmpMeta.setProperty(XMPConst.NS_DC, "title", this.name);
xmpMeta.setProperty(XMPConst.NS_DC, "description", "A Bridge SDK node");
XMPMeta.registerNamespace("http://ns.adobe.bridge.sdk/a/", "extHanA");
xmpMeta.setProperty("http://ns.adobe.bridge.sdk/a/", "Description", "Some custom metadata added to a script defined node");
xmpMeta.setProperty("http://ns.adobe.bridge.sdk/a/", "ID", Math.floor(Math.random()*30));
var newXmp = xmpMeta.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT );
this.metadata = new Metadata( newXmp );
}
return this.metadata;
}
SDKNode.prototype.setLabelRating = function(type, val)
{
md = this.getMetadata();
md.namespace = "http://ns.adobe.com/xap/1.0/";
if(type == "Rating")
{
md.Rating = val;
}
else
{
md.Label = val;
}
}
SDKNode.prototype.getLabelRating = function(type)
{
var retval = 0;
md = this.getMetadata();
md.namespace = "http://ns.adobe.com/xap/1.0/";
if(type == "Rating")
{
retval = md.Rating;
}
else
{
retval = md.Label;
}
return retval;
}
SDKNode.prototype.setMetadata = function(md)
{
this.metadata = md;
}
SDKNode.prototype.setCustomInfosetData = function()
{
this.customString = "A Simple String for node: " + this.name;
this.customNumber = (this.container) ? 1234 : 9876;
this.customDate = new Date().toString();
this.customArray = ["Array", "Of", "Strings"];
this.customBool = true;
}
SDKNode.prototype.getCustomString = function(){ return this.customString; }
SDKNode.prototype.getCustomNumber = function(){ return this.customNumber; }
SDKNode.prototype.getCustomDate = function(){ return this.customDate; }
SDKNode.prototype.getCustomArray = function(){ return this.customArray; }
SDKNode.prototype.getCustomBool = function(){ return this.customBool; }
SDKNode.prototype.setCustomString = function(s){ this.customString = s; }
SDKNode.prototype.setCustomNumber = function(n){ this.customNumber = n; }
SDKNode.prototype.setCustomDate = function(d){ this.customDate = d; }
SDKNode.prototype.setCustomArray = function(a){ this.customArray = a; }
SDKNode.prototype.setCustomBool = function(b){ this.customBool = b; }
http://www.adobe.com/devnet/bridge
Documentation generated by
JSDoc on Tue Apr 27 10:21:34 2010