// Use WebAppXhtmlBuilder.nui // Global procedures for writing XHTML
//> doc.begin
//> This package defines a global set of procedures that is used for writing XHTML
//> directly into the output stream of a WebApp application.
//>
//> For test purposes it may be used to write to a file (by virtue of the
//> XHTML_SetOutputFile method).
//>
//> The cXmlBuilder class (of XmlBuilder.nui) let's you build standard XML DOM
//> documents with no pain of object handle house keeping. As a second feature
//> it lets you output the XML to a sequential channel as elements are being added (as
//> opposed to building the complete document in memory first, which is the standard
//> XML way).
//>
//> This package transforms this basic service into a set of globally defined
//> procedures for writing XHTML code directly into the output stream of a web
//> application.
//>
//>
//> A XHTML document can be generated like this:
//>
//> send XHTML_StartXhtml
//> send XHTML_OpeningOath // This example generates a complete XHTML document.
//> send XHTML_Add_Open_Element "html"
//> send XHTML_Add_Attribute "xmlns" "http://www.w3.org/1999/xhtml"
//>
//> send XHTML_Add_Attribute "xml:lang" "en"
//> send XHTML_Add_Attribute "lang" "en"
//>
//> send XHTML_Add_Open_Element "head"
//> send XHTML_Add_Closed_Element "title" "test page"
//> send XHTML_Close_Element // head
//> send XHTML_Add_Open_Element "body"
//> // Generate the body of the document here.
//> send XHTML_Close_Element // body
//> send XHTML_Close_Element // html
//> send XHTML_EndXhtml
//>
//> will get you this:
//>
//>
//>
//>
//>
//> test page
//>
//>
//>
//>
//>
//> doc.end
Use ExtendedItemProp.nui // cExtendedItemPropertyArray class
Use XmlBuilder.nui // cXmlBuilder class (XML building made easy)
Use Files.nui // Utilities for handling file related stuff (No User Interface)
Use css.nui // CSS things
// global
integer ghWebAppHtmlBuilder
class cWebAppHtmlBuilder is a cXmlBuilder
procedure construct_object
forward send construct_object
set pbTextAreaException to TRUE
set pbScriptException to TRUE
property string psOutputFile public ""
// The priv.OpenCount property allows for handling "nested" outputs
property integer priv.OpenCount public 0
property integer pbTest public FALSE
property integer priv.iTestIndent public 0
property integer priv.bEven public TRUE
property integer pbOemToAnsiState public FALSE
end_procedure
procedure decrement_indentation
set priv.iTestIndent to (priv.iTestIndent(self)-1)
end_procedure
procedure increment_indentation
set priv.iTestIndent to (priv.iTestIndent(self)+1)
end_procedure
procedure write string lsValue
integer lbIndent liMax
string lsIndent lsOpen lsClose
if (pbTest(self)) begin // If we're in test mode, do a lot of stuff
if (right(lsValue,2)="/>") move 0 to lbIndent
else if (left(lsValue,2)="") move -1 to lbIndent
else begin
get HowManyWords lsValue "> " to liMax
get ExtractWord lsValue "> " 1 to lsOpen
get ExtractWord lsValue "> " liMax to lsclose
if (lowercase(lsOpen)=lowercase(lsclose) and liMax<>1) move 0 to lbIndent
else move 1 to lbIndent
end
if (lbIndent=-1) send decrement_indentation
move (replaces("&",lsValue,"&")) to lsValue
move (replaces('"',lsValue,""")) to lsValue
move (replaces("<",lsValue,"<")) to lsValue
move (replaces(">",lsValue,">")) to lsValue
move (repeat(" ",2*priv.iTestIndent(self))) to lsIndent
if (priv.bEven(self)) move (''+lsIndent+lsValue+'
') to lsValue
else move (''+lsIndent+lsValue+'
') to lsValue
set priv.bEven to (not(priv.bEven(self)))
forward send write lsValue
if (lbIndent=1) send increment_indentation
end
else forward send write lsValue
end_procedure
procedure Add_Closed_Element string lsElement string lsValue
if (pbOemToAnsiState(self)) get StringOemToAnsi lsValue to lsValue
forward send Add_Closed_Element lsElement lsValue
end_procedure
procedure Add_Closed_Element_CData string lsElement string lsValue
if (pbOemToAnsiState(self)) get StringOemToAnsi lsValue to lsValue
forward send Add_Closed_Element_CData lsElement lsValue
end_procedure
procedure Add_Attribute string lsAttr string lsValue
if (pbOemToAnsiState(self)) get StringOemToAnsi lsValue to lsValue
forward send Add_Attribute lsAttr lsValue
end_procedure
end_class // cWebAppHtmlBuilder
desktop_section
object oWebAppHtmlBuilder is a cWebAppHtmlBuilder
move self to ghWebAppHtmlBuilder
end_object
end_desktop_section
//> The XHTML_StartXhtml/XHTML_EndXhtml are used to start and stop outputting
//> XHTML. In order to allow for writing stand alone components that may at the
//> same time function as part of larger components, it is possible to nest
//> several sets of XHTML_StartXhtml/XHTML_EndXhtml. The inner sets are simply
//> ignored.
procedure XHTML_StartXhtml global string lsTmp
integer liChannel liOpenCount
string lsFileName
if num_arguments gt 0 set psOutputFile of ghWebAppHtmlBuilder to lsTmp
get priv.OpenCount of ghWebAppHtmlBuilder to liOpenCount
if (liOpenCount=0) begin
set priv.iTestIndent of ghWebAppHtmlBuilder to 0
get psOutputFile of ghWebAppHtmlBuilder to lsFileName
if (lsFileName<>"") begin
get SEQ_DirectOutput lsFileName to liChannel
if (liChannel<0) error 781 "Illegal channel number (WebAppXhtmlBuilder.nui)"
send begin_xml_write_seq of ghWebAppHtmlBuilder liChannel
end
else send begin_xml_write_webapp_stream of ghWebAppHtmlBuilder
set pbOemToAnsiState of ghWebAppHtmlBuilder to (lsFileName<>"")
if (pbTest(ghWebAppHtmlBuilder)) begin
set pbTest of ghWebAppHtmlBuilder to false
send XHTML_Add_Open_Element "html"
send XHTML_Add_Attribute "xmlns" "http://www.w3.org/1999/xhtml"
send XHTML_Add_Attribute "xml:lang" "en"
send XHTML_Add_Attribute "lang" "en"
send XHTML_Add_Open_Element "head"
send XHTML_Add_Closed_Element "title" "View XHTML source"
send XHTML_Close_Element // head
send XHTML_Add_Open_Element "body"
send XHTML_Add_Open_Element "div"
send XHTML_Add_Attribute "style" "white-space:nowrap;font-family:courier;"
send flush_buffer of ghWebAppHtmlBuilder
set pbTest of ghWebAppHtmlBuilder to true
end
end
increment liOpenCount
set priv.OpenCount of ghWebAppHtmlBuilder to liOpenCount
end_procedure
//> send XHTML_StartXhtml
//> send XHTML_OpeningOath // This example generates a complete XHTML document.
//> send XHTML_Add_Open_Element "html"
//> send XHTML_Add_Attribute "xmlns" "http://www.w3.org/1999/xhtml"
//>
//> send XHTML_Add_Attribute "xml:lang" "en"
//> send XHTML_Add_Attribute "lang" "en"
//>
//> send XHTML_Add_Open_Element "head"
//> send XHTML_Add_Closed_Element "title" "test page"
//> send XHTML_Close_Element // head
//> send XHTML_Add_Open_Element "body"
//> // Generate the body of the document here.
//> send XHTML_Close_Element // body
//> send XHTML_Close_Element // html
//> send XHTML_EndXhtml
//> Use this immediately after XHTML_StartXhtml if you're generating a complete XHTML document.
procedure XHTML_OpeningOath global // Swear that you'll output valid XHTML
send write of ghWebAppHtmlBuilder ''
set priv.iTestIndent of ghWebAppHtmlBuilder to 0
send write of ghWebAppHtmlBuilder ('')
set priv.iTestIndent of ghWebAppHtmlBuilder to 0
end_procedure
procedure XHTML_EndXhtml global
integer liOpenCount
string lsFileName
get priv.OpenCount of ghWebAppHtmlBuilder to liOpenCount
decrement liOpenCount
if (liOpenCount=0) begin
if (pbTest(ghWebAppHtmlBuilder)) begin
set pbTest of ghWebAppHtmlBuilder to false
send flush_buffer of ghWebAppHtmlBuilder
send XHTML_Close_Element // div
send XHTML_Close_Element // body
send XHTML_Close_Element // html
set pbTest of ghWebAppHtmlBuilder to true
end
get psOutputFile of ghWebAppHtmlBuilder to lsFileName
send end_xml of ghWebAppHtmlBuilder
if (lsFileName<>"") send SEQ_CloseOutput (priv.piChannel(ghWebAppHtmlBuilder))
end
set priv.OpenCount of ghWebAppHtmlBuilder to liOpenCount
end_procedure
//> Call this to make the output go to a file instead of the WebApp output stream.
procedure XHTML_SetOutputFile global string lsFile
set psOutputFile of ghWebAppHtmlBuilder to lsFile
end_procedure
//> For the rest of the procedures look in the XmlBuilder.nui for explanation.
procedure XHTML_SetProtectValueData global integer lbValue
set pbProtectValueData of ghWebAppHtmlBuilder to lbValue
end_procedure
//procedure XHTML_SetTextAreaException global integer lbValue
// set pbTextAreaException of ghWebAppHtmlBuilder to lbValue
//end_procedure
procedure XHTML_Add_Open_Element global string lsElement
send Add_Open_Element of ghWebAppHtmlBuilder lsElement
end_procedure
procedure XHTML_Add_Closed_Element global string lsElement string lsValue
send Add_Closed_Element of ghWebAppHtmlBuilder lsElement lsValue
end_procedure
procedure XHTML_Add_Closed_Element_CData global string lsElement string lsValue
send Add_Closed_Element_CData of ghWebAppHtmlBuilder lsElement lsValue
end_procedure
procedure XHTML_Close_Element global
send Close_Element of ghWebAppHtmlBuilder
end_procedure
procedure XHTML_Add_Attribute global string lsAttr string lsValue
send Add_Attribute of ghWebAppHtmlBuilder lsAttr lsValue
end_procedure
procedure XHTML_Add_Closed_Element_Number global string lsElement number lnValue
send Add_Closed_Element_Number of ghWebAppHtmlBuilder lsElement lnValue
end_procedure
procedure XHTML_Add_Closed_Element_Date global string lsElement date ldValue
send Add_Closed_Element_Date of ghWebAppHtmlBuilder lsElement ldValue
end_procedure
procedure XHTML_Stream_Data global string lsHTML
send stream of ghWebAppHtmlBuilder lsHTML
end_procedure
procedure XHTML_Add_VerticalSpace global string lsHeight
send XHTML_Add_Closed_Element "div" "ÿ"
send XHTML_Add_Attribute "style" ("height:"+lsHeight+";width:20px")
end_procedure
procedure XHTML_Add_HorizontalSpace global string lsWidth
send XHTML_Add_Closed_Element "span" "ÿ"
send XHTML_Add_Attribute "style" ("width:"+lsWidth+";height:5px")
end_procedure
//>
procedure XHTML_Add_Attribute_Css_Style global
string lsStyle
get CSS_InLineStyle to lsStyle
if (lsStyle<>"") send XHTML_Add_Attribute "style" lsStyle
end_procedure