Monday, November 08, 2010 at 12:01 AM.
system.verbs.apps.Manila.windowTypes.types.manilaTemplate.scripts.siteStructure.outlineToXml
on outlineToXml (adrOutline) {
<<Changes:
<<2/11/04; 1:58:45 AM by JES
<<Added support for redirects from within a Manila site structure.
<<12/22/01; 3:53:29 AM by JES
<<Call latinToMac.macToLatin instead of playlist.convertToLatin.
<<12/19/01; 2:46:03 PM by JES
<<Added some msg calls to let the user know that we're building the site structure XML. This is important for large site structure outlines, like the DocServer site structure outline.
<<7/22/01; 12:32:07 AM by JES
<<Encode xml entities in name and description attributes.
<<3/18/01; 4:23:29 PM by PBS
<<Close <category> tags that don't contain any stories or other categories. Fixes the bug reported on this page: http://radio.userland.com/discuss/msgReader$5625?mode=day
<<12/31/00; 5:18:02 PM by JES
<<On Macs, convert opml text from Mac to latin.
<<Fri, Dec 8, 2000 at 1:07:34 PM by JES
<<Bug fix: Always add non-empty descriptions for categories, not just when the category doesn't have an associated message number.
<<Tuesday, September 19, 2000 at 2:24:04 PM by PBS
<<Get description attributes and add to XML text.
<<Wed, Aug 23, 2000 at 2:26:50 AM by PBS
<<Created. Turn a fancy site structure editor into its plain XML text representation. Return XML text. This is just like an outline renderer -- it's a special case of outline renderer.
local (xmlText = "<hierarchy>\r");
local (localOutline = adrOutline^); //use a copy so as not to make the screen go nuts
local (oldTarget = target.set (@localOutline));
op.setDisplay (false); //it's faster
op.firstSummit ();
op.fullexpand ();
local (level = 1);
on add (s) {
xmlText = xmlText + string.filledString ('\t', level) + s + "\r"};
on getDescription (adrAtts) { //PBS 09/19/00: get description attribute
if not defined (adrAtts^.description) {
return ("")};
return (string.trimWhiteSpace (adrAtts^.description))};
on visit (message="Building site structure XML: ") {
loop {
local (ctSubs = op.countSubs (1));
local (flHasSubs = ctSubs > 0);
local (s = "");
local (linetext = op.getLineText ());
local (atts);
op.attributes.getAll (@atts);
case atts.type {
"manilaSiteStructureMessage" {
if string.lower (linetext) != "index" { //special case
local (msgNum = atts.msgNum);
local (name = atts.name);
local (pathname = string.trimWhiteSpace (linetext));
msg (message + pathname + "...");
local (description = getDescription (@atts));
if string.lower (name) == "untitled" {
name = pathname};
if description == "" { //it's already been white-space-trimmed
add ("<story msgNum=\"" + msgNum + "\" name=\"" + name + "\"" + " pathname=\"" + pathName + "\"/>")}
else { //PBS 09/19/00: add description to XML
add ("<story msgNum=\"" + msgNum + "\" name=\"" + name + "\"" + " pathname=\"" + pathName + "\"><description>" + description + "</description></story>")}}};
"manilaSiteStructureCategory" {
local (name = atts.name);
local (pathname = string.trimWhiteSpace (linetext));
local (description = getDescription (@atts));
if string.lower (name) == "untitled" {
name = pathname};
local (msgNum);
local (cursor = op.getCursor ());
bundle { //look ahead for index item
if op.go (right, 1) {
loop {
local (linetext = op.getLineText ());
if string.lower (linetext) == "index" {
local (atts);
op.attributes.getAll (@atts);
msgNum = atts.msgNum;
break};
if not (op.go (down, 1)) {
break}};
op.setCursor (cursor)}};
if msgNum != nil {
add ("<category msgNum=\"" + msgNum + "\" name=\"" + name + "\"" + " pathname=\"" + pathName + "\">")}
else {
add ("<category name=\"" + name + "\"" + " pathname=\"" + pathName + "\">")};
if description != "" { //it's already been white-space-trimmed //12/08/00 JES: always add non-empty descriptions, not just when msgNum == nil.
add ("<description>" + description + "</description>")}; //PBS 09/19/00: add description
if flHasSubs {
op.go (right, 1);
level++;
visit (message + pathname + "/");
add ("</category>");
level--;
op.go (left, 1)}
else { //PBS 03/18/01: close off categories that don't contain anything
add ("</category>")}};
"manilaSiteStructureRedirect" {
local (url = atts.url);
local (pathname = string.trimWhiteSpace (linetext));
msg (message + pathname + "...");
add ("<redirect pathname=\"" + pathName + "\" url=\"" + url + "\"/>")}};
if not (op.go (down, 1)) {
break}}};
visit ();
try {target.set (oldTarget)};
xmlText = xmlText + "</hierarchy>";
if system.environment.isMac {
xmltext = latinToMac.macToLatin (xmlText)};
return (xmlText)}
<<bundle //test code
<<wp.newTextObject (outlineToXml (window.frontmost ()), @workspace.xtext)
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.