Monday, November 08, 2010 at 12:01 AM.

system.verbs.apps.Manila.windowTypes.types.manilaTemplate.scripts.siteStructure.xmlToOutline

on xmlToOutline (xmltext, adrOutline) {
	<<Changes:
		<<2/11/04; 1:53:08 AM by JES
			<<Added support for redirects from within a Manila site structure.
		<<12/28/01; 6:23:53 PM by JES
			<<Fixed a bug where site structure outlines would not open on Windows.
		<<12/19/01; 2:27:03 PM by JES
			<<Added some msg calls, so the user has some indication that the outline is being built. This is important for large site structure outlines, like the DocServer site structure outline.
		<<7/22/01; 12:31:40 AM by JES
			<<Decode xml entities in name and description attributes.
		<<12/31/00; 5:11:47 PM by JES
			<<On Macs, convert latin opml text to Mac text.
		<<Tuesday, September 19, 2000 at 2:11:18 PM by PBS
			<<Get descriptions and add as attributes. If an item has no description, then description attribute is "".
		<<Wed, Aug 23, 2000 at 1:45:20 AM by PBS
			<<Created. Build a site structure outline. This script over-rides the plain XML that Pike gives us.
	
	<<local (adrOutline = @adrTable^.outline) //the actual window
	
	local (adrinfo);
	window.attributes.getOne ("adrSiteInfo", @adrinfo, adrOutline);
	local (siteUrl = nameOf (adrinfo^));
	bundle { //if port 80, pull the port out of the siteUrl
		local (parts = string.urlSplit (siteUrl));
		if parts[2] contains ":" {
			if string.nthField (parts[2], ':', 2) == "80" {
				siteUrl = parts[1] + string.nthField (parts[2], ':', 1) + "/" + parts[3]}}};
	
	local (t);
	new (tableType, @t);
	if system.environment.isMac { //12/31/00 JES: convert to Mac text
		xml.compile (latinToMac.convert (xmltext), @t)}
	else {
		xml.compile (xmltext, @t)};
	new (outlineType, adrOutline);
	local (oldTarget = target.set (adrOutline));
	
	on getDescription (adrTable) { //PBS 09/19/00: get an item's description
		local (adrItem);
		for adrItem in adrTable {
			local (itemName = xml.convertToDisplayName (nameOf (adrItem^)));
			if string.lower (itemName) == "description" {
				return (adrItem^)}};
		return ("")};
	
	on doTable (adrTable, flGoneRight, message="Building site structure outline: ") {
		local (dir = down);
		if not flGoneRight {
			dir = right};
		local (adrItem);
		for adrItem in adrTable {
			if typeOf (adrItem^) != tableType {
				continue};
			local (itemName = xml.convertToDisplayName (nameOf (adrItem^)));
			local (lowerName = string.lower (itemName));
			case lowerName {
				"story" {
					local (atts);
					new (tableType, @atts);
					atts.siteUrl = siteUrl;
					atts.type = "manilaSiteStructureMessage";
					atts.msgNum = adrItem^.["/atts"].msgNum;
					atts.name = adrItem^.["/atts"].name;
					atts.description = getDescription (adrItem);
					local (linetext = adrItem^.["/atts"].pathName);
					msg (message + linetext + "...");
					if (sizeOf (adrOutline^) == 1) and (op.getLineText () == "") {
						op.setLineText (linetext)}
					else {
						op.insert (linetext, dir)};
					dir = down;
					op.attributes.addGroup (@atts)};
				"category" {
					local (atts);
					new (tableType, @atts);
					atts.siteUrl = siteUrl;
					atts.type = "manilaSiteStructureCategory";
					local (linetext = adrItem^.["/atts"].pathName);
					if defined (adrItem^.["/atts"].name) {
						atts.name = adrItem^.["/atts"].name}
					else {
						atts.name = adrItem^.["/atts"].pathName};
					atts.description = getDescription (adrItem);
					if (sizeOf (adrOutline^) == 1) and (op.getLineText () == "") {
						op.setLineText (linetext)}
					else {
						op.insert (linetext, dir)};
					op.attributes.addGroup (@atts);
					dir = down;
					if defined (adrItem^.["/atts"].msgNum) {
						local (atts);
						new (tableType, @atts);
						atts.siteUrl = siteUrl;
						atts.type = "manilaSiteStructureMessage";
						atts.msgNum = adrItem^.["/atts"].msgNum;
						atts.name = adrItem^.["/atts"].name;
						linetext = "index";
						op.insert (linetext, right);
						op.attributes.addGroup (@atts);
						doTable (adrItem, true, message + linetext + "/")}
					else {
						doTable (adrItem, false, message + linetext + "/")}};
				"redirect" {
					local (atts);
					new (tableType, @atts);
					atts.siteUrl = siteUrl;
					atts.type = "manilaSiteStructureRedirect";
					atts.url = adrItem^.["/atts"].url;
					local (linetext = adrItem^.["/atts"].pathName);
					if (sizeOf (adrOutline^) == 1) and (op.getLineText () == "") {
						op.setLineText (linetext)}
					else {
						op.insert (linetext, dir)};
					dir = down;
					op.attributes.addGroup (@atts)}}};
		op.go (left, 1)};
	doTable (@t [1], true);
	msg ("");
	
	try {target.set (oldTarget)};
	
	return (true)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.