htmltree.cls source

00001 /*----------------------------------------------------------------------------*/
00002 /*                                                                            */
00003 /*   Copyright (c) 2004-2009 William  Data  Systems Ltd. and Geoff Stevens.   */
00004 /*   All rights reserved.                                                     */
00005 /*                                                                            */
00006 /*   This program and the  accompanying  materials are made available under   */
00007 /*   the terms of the  Common  Public  License  v1.0 which accompanies this   */
00008 /*   distribution. A  copy  is  also  available  at  the following address:   */
00009 /*   http://www.opensource.org/licenses/cpl1.0.php                            */
00010 /*                                                                            */
00011 /*   Redistribution and use in  source  and  binary  forms, with or without   */
00012 /*   modification, are  permitted  provided  that  the following conditions   */
00013 /*   are met:                                                                 */
00014 /*                                                                            */
00015 /*   Redistributions  of  source  code  must  retain  the  above  copyright   */
00016 /*   notice, this list of conditions and the following disclaimer.            */
00017 /*                                                                            */
00018 /*   Redistributions in  binary  form  must  reproduce  the above copyright   */
00019 /*   notice, this list of  conditions  and  the following disclaimer in the   */
00020 /*   documentation and/or other materials provided with the distribution.     */
00021 /*                                                                            */
00022 /*   Neither the name or trademarks  of  William Data Systems nor the names   */
00023 /*   of its  contributors  may  be  used  to  endorse  or  promote products   */
00024 /*   derived from this software without specific prior written permission.    */
00025 /*                                                                            */
00026 /*   DISCLAIMER                                                               */
00027 /*                                                                            */
00028 /*   THIS SOFTWARE IS PROVIDED  BY  THE  COPYRIGHT HOLDERS AND CONTRIBUTORS   */
00029 /*   "AS IS" AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT   */
00030 /*   LIMITED TO, THE IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR   */
00031 /*   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT   */
00032 /*   OWNER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,   */
00033 /*   SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT NOT   */
00034 /*   LIMITED TO, PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES; LOSS OF USE,   */
00035 /*   DATA, OR PROFITS; OR BUSINESS  INTERRUPTION) HOWEVER CAUSED AND ON ANY   */
00036 /*   THEORY OF LIABILITY, WHETHER  IN  CONTRACT,  STRICT LIABILITY, OR TORT   */
00037 /*   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN  ANY WAY OUT OF THE USE   */
00038 /*   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
00039 /*                                                                            */
00040 /*----------------------------------------------------------------------------*/
00041 --  make tree html from filetree
00042 --
00043 --
00044  
00045 -- for all the boilerplate
00046 ::REQUIRES 'fsobjects.cls'
00047  
00048 -- to generate unique ids
00049 ::REQUIRES 'hashfunction.cls'
00050  
00051 -- files, folders, rexx and text documents
00052 ::REQUIRES 'documents.cls'
00053  
00054 -- html images to build the tree view
00055 ::REQUIRES 'nodes.cls'
00056  
00057  
00058 -- render rexx file tree as HTML
00059 ::CLASS htmltree PUBLIC
00060 ::ATTRIBUTE tree       -- the tree of folders and files
00061 ::ATTRIBUTE foldernum  -- unique number for each folder in tree
00062 ::ATTRIBUTE hdest      -- html output path
00063 ::ATTRIBUTE title      -- tree title
00064  
00065 -- install 
00066 -- @param title   - what to call the tree
00067 -- @param tree    - tree of folders and files
00068 -- @param hdest   - path to which to write HTML output
00069 ::METHOD init
00070   use strict arg title, tree, hdest
00071  
00072   self~title = title
00073   self~tree = tree
00074   self~hdest = hdest
00075   self~foldernum = 0
00076  
00077 -- walk the tree and emit corrsponding HTML
00078 ::METHOD maketreehtml 
00079  
00080   -- tree page head
00081   tp = .head_html~new~text
00082  
00083   -- stylesheet, title and script
00084   tp~queue(.nodes~prodssheet)
00085   tp~queue('<title>My Tree View</title>')
00086   .treescript_html~new~addq(tp)
00087  
00088   -- head is complete
00089   tp~queue('</head>')
00090  
00091   -- prepare body
00092   tp~queue('<body class="ftvtree"')
00093   tp~queue('<div class="directory">')
00094   tp~queue('<h3>'self~title'</h3>')
00095  
00096   -- process tree
00097   -- recursively walk tree, emitting html
00098   self~emittreehtml(tp, self~tree, .queue~new, .true)
00099  
00100   tp~queue('</div></body></html>')
00101  
00102   -- write tree html to disk
00103   rc = SysFileDelete(self~hdest'tree.html')
00104   s = .stream~new(self~hdest'tree.html')
00105   rc = s~arrayout(tp)
00106   s~close
00107  
00108  
00109 -- process a folder into html
00110 -- @param outq - a queue for html output
00111 -- @param f - the folder to process
00112 -- @param leftq - a queue of <img> tags representing the
00113 --        lines to the left of this folder in the tree
00114 -- @param islast - when .true, this folder is the last item at 
00115 --        the current tree level
00116 ::METHOD emittreehtml PRIVATE
00117   use arg outq, f, leftq, islast
00118   self~foldernum = self~foldernum + 1
00119  
00120   -- assemble left queue into a single string
00121   xleftq = ''
00122   do i over leftq
00123     xleftq = i || xleftq
00124   end
00125  
00126   -- decide which descender to add
00127   if f~files~items > 0 & \islast
00128     then myline = .nodes~vertline
00129     else myline = .nodes~blankline
00130  
00131   -- set up left queue for subfolders
00132   -- by pushing the descender onto the stack
00133   leftq~push(myline)
00134  
00135   do i over f~folders
00136      -- suppress empty folders
00137     if i~files~items = 0
00138       then iterate
00139  
00140     -- is the subfolder the last item at this level?
00141     if i = f~folders[f~folders~last] & f~files~items = 0
00142       then flast = .true
00143       else flast = .false
00144  
00145     -- html for folder
00146     node = ''
00147     node = node || '<p>'
00148     node = node || xleftq || myline
00149     if flast
00150       then node = node || .nodes~closednodelast(self~foldernum+1)
00151       else node = node || .nodes~closednode(self~foldernum+1)
00152     node = node || .nodes~folderclosed(self~foldernum+1)
00153     node = node || i~foldername
00154     outq~queue(node)
00155  
00156     -- folder contents in a div
00157     outq~queue('<div id="folder'self~foldernum+1'">')
00158  
00159     self~emittreehtml(outq, i, leftq, flast)
00160  
00161     outq~queue('</div>')
00162  
00163   end
00164  
00165   -- process files in this folder
00166   do i over f~files
00167     iscode = .false
00168     node = ''
00169     if i = f~files[f~files~last]
00170       then flast = .true
00171       else flast = .false
00172  
00173     node = node || '<p>'
00174     if islast
00175       then node = node || xleftq || .nodes~blankline
00176       else node = node || xleftq || .nodes~vertline
00177  
00178     if i~istxt
00179       then do
00180              if flast
00181                then node = node || .nodes~lastnode
00182                else node = node || .nodes~node
00183              node = node || .nodes~doc
00184              node = node || '<a class="el" href="'i~document~hsrcurl'" target="basefrm">'
00185              node = node || '&nbsp;' i~filename'</a>'
00186              node = node || '</p>'
00187            end
00188       else do
00189              -- rexx program is expandable
00190              self~foldernum = self~foldernum + 1
00191              if flast
00192                then node = node || .nodes~closednodelast(self~foldernum)
00193                else node = node || .nodes~closednode(self~foldernum)
00194              if i~document~isoo
00195                then node = node || .nodes~oorx(self~foldernum)
00196                else node = node || .nodes~clrx(self~foldernum)
00197              iscode = .true
00198              node = node || '<a class="el" href="'i~document~hdocurl'" target="basefrm">'
00199              node = node || '&nbsp;'i~filename'</a>'
00200              node = node || '<a class="el" href="'i~document~hsrcurl'" target="basefrm">'
00201              node = node || '&nbsp;src</a>'
00202              node = node || '</p>'
00203            end
00204  
00205     outq~queue(node)
00206  
00207     if iscode
00208       then do
00209              -- dissect program into a div
00210              outq~queue('<div id="folder'self~foldernum'">')
00211              node = ''
00212              if flast
00213                then leftq~push(.nodes~blankline)
00214                else leftq~push(.nodes~vertline)
00215  
00216              -- process program
00217              self~treerexxprogram(outq, i, leftq, flast)
00218  
00219              -- remove fline
00220              gigo = leftq~pull
00221  
00222              outq~queue('</div>')
00223            end
00224  
00225  
00226  
00227   end
00228  
00229   -- remove myline
00230   gigo = leftq~pull
00231  
00232   return
00233  
00234 -- render a rexx program as tree html and
00235 -- install references in tree
00236 ::METHOD treerexxprogram PRIVATE
00237   use arg outq, rfile, leftq, islast
00238  
00239   -- get the rexx document from the file
00240   rexxd = rfile~document
00241  
00242   -- assemble left queue into a single string
00243   xleftq = ''
00244   do i over leftq
00245     xleftq = i || xleftq
00246   end
00247  
00248   -- keep track of what we've already emitted
00249   emitted = .bag~new
00250  
00251   -- walk the featurelist, adding structure as we go
00252   -- Items contained within a class are one level
00253   -- down from the top of the Rexx program
00254   hadreq = .false -- only produce one requires icon and link in the tree
00255   do j = 1 to rexxd~featurelist~items
00256     i = rexxd~featurelist[j]
00257  
00258     -- check not already emitted
00259     if emitted~hasindex(i)
00260       then iterate
00261     emitted~put(i)
00262  
00263     last = .false
00264     if j = rexxd~featurelist~items
00265       then last = .true
00266  
00267     select
00268       when i~type = 'PROC'
00269         then nop
00270       when i~type = 'LABL'
00271         then nop
00272       when i~type = 'ROUT'
00273         then nop
00274       when i~type = 'REQU'
00275         then do
00276                if hadreq
00277                  then iterate
00278                hadreq = .true
00279              end
00280       when i~type = 'OPTS'
00281         then nop
00282  
00283       -- methods, attributes and constants are folded within class
00284       when i~type = 'METH'
00285         then iterate
00286       when i~type = 'ATTR'
00287         then iterate
00288       when i~type = 'CONS'
00289         then iterate
00290  
00291       -- expand class into folder
00292       when i~type = 'CLAS'
00293         then do
00294               self~htmlclass(outq, rexxd, i, xleftq, emitted)
00295               iterate
00296              end
00297       otherwise do
00298                   say 'unknown' i~type
00299                   exit
00300                 end
00301     end
00302  
00303  
00304  
00305     node = '<p>'
00306     if last
00307        then node = node || xleftq || .nodes~lastnode ||i~largeicon
00308        else node = node || xleftq || .nodes~node || i~largeicon
00309  
00310  
00311     if i~type = 'REQU'
00312       then tag = 'requires directives'
00313       else tag = i~rexxname
00314  
00315     node = node || '<a class="el" href="'rexxd~hdocurl'#'i~hdocanchor'" target="basefrm">&nbsp;'tag'</a>'
00316     node = node || '&nbsp;...&nbsp'
00317     node = node || '<a class="el" href="'rexxd~hsrcurl'#'i~hsrcanchor'" target="basefrm">'
00318     node = node || 'src</a>'
00319  
00320     node = node || '</p>'
00321     outq~queue(node)
00322  
00323   end
00324  
00325   return
00326  
00327  
00328 -- emit tree html for a class
00329 -- @param outq - queue to which to add html
00330 -- @param rexxd - rexxdocument
00331 -- @param rdc - rdclass
00332 -- @param xleftq - expanded left queue
00333 -- @param emitted - bag of emitted objects
00334 ::METHOD htmlclass
00335    use arg outq, rexxd, rdc, xleftq, emitted
00336  
00337    emitted~put(rdc)
00338  
00339    last = .false
00340  
00341    self~foldernum = self~foldernum+1
00342    if rdc~public
00343      then icon = .nodes~rclass(self~foldernum)
00344      else icon = .nodes~rclassp(self~foldernum)
00345  
00346    -- look for following class or routine
00347    -- to see if we're last in top level list
00348    nf = rexxd~nextfeature(rdc~feature, 'CLAS ROUT')
00349    if nf = .nil
00350      then last = .true
00351  
00352    node = '<p>'
00353    if last
00354      then do
00355             node = node || xleftq || .nodes~closednodelast(self~foldernum) || icon
00356           end
00357      else do
00358             node = node || xleftq || .nodes~closednode(self~foldernum) || icon
00359           end
00360  
00361   node = node || '<a class="el" href="'rdc~hdocurl'" target="basefrm">&nbsp;'rdc~rexxname'</a>'
00362   node = node || '&nbsp;...&nbsp'
00363   node = node || '<a class="el" href="'rexxd~hsrcurl'#'rdc~hsrcanchor'" target="basefrm">'
00364   node = node || 'src</a>'
00365  
00366   node = node || '</p>'
00367   outq~queue(node)
00368   outq~queue('<div id=folder'self~foldernum' style="display: none">')
00369  
00370   if last
00371     then classline = .nodes~blankline
00372     else classline = .nodes~vertline
00373   do m over rdc~methods
00374     emitted~put(m)
00375     if m~type = 'LABL'
00376       then iterate
00377     node = '<p>'
00378     if m = rdc~methods[rdc~methods~last]
00379       then node = node || xleftq || classline || .nodes~lastnode || m~largeicon
00380       else node = node || xleftq || classline || .nodes~node || m~largeicon
00381  
00382     node = node || '<a class="el" href="'rdc~hdocurl'#'m~hdocanchor'" target="basefrm">&nbsp;'m~rexxname'</a>'
00383     node = node || '&nbsp;...&nbsp'
00384     node = node || '<a class="el" href="'rexxd~hsrcurl'#'m~hsrcanchor'" target="basefrm">'
00385     node = node || 'src</a>'
00386  
00387     node = node || '</p>'
00388     outq~queue(node)
00389  
00390   end
00391  
00392   outq~queue('</div>')
00393   return
00394  
00395  

Get RexxLiterate at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on 31 Aug 2010 05:20:28 for RexxLiterate by rexxliterate  0.0.1