Home directory for Malawi's wwwroot
Duncan Ewan
2021-02-19 3e758c29e0fde36fc088efcfc88f9a3014432b64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<cfscript>
    function GetAncestors(cd) {
        var ancestors = ArrayNew(1);
        if ( StructKeyExists( cd, 'extends' ) )
            ancestors = GetAncestors( cd.extends ) ;
        
        ArrayAppend( ancestors, cd ) ;
        
        return ancestors ;
    
    }
 
    /**
    *    Gets ancestors (interfaces) from given interface metadata
    *    It only get direct ancestors.
    *
    *    @param cd Meta data of the interface whose ancestors are to be obtained.
    *    @returns ancestors - Array of meta data of direct ancestors
    */    
    function GetInterfaceAncestors(cd) {
        var ancestors = ArrayNew(1);
        
        if (not IsStruct(cd))
            return ancestors;
            
        if (StructKeyExists(cd,'extends')) {
            for (intf in cd.extends)
            {
                ArrayAppend(ancestors,cd.extends[#intf#]);
            }
        } 
        return ancestors;
    }
 
    /**
    *    Checks if given metadata belongs to interface or component
    *     
    *    @param cd Metadata of component or interface
    *    @return true if it is an interface else false
    */
    function IsInterface(cd) {
        if (IsStruct(cd) and StructKeyExists(cd,'type') and cd.type eq "interface")
            return true;
        return false;
    }
 
    /**
    *    Gets array of only direct imlpemented interfaces.
    
    *    @param cd Metadata of the Component
    *    @return Array of metadata (Struct) of direct implemented interfaces
    */    
    function GetImplementedInterfaces(cd) {
        var interfaces = ArrayNew(1);
        
        if (not IsStruct(cd)) 
            return interfaces;
            
        if (StructKeyExists(cd,'implements')) {
            for (itf in cd.implements) {
                ArrayAppend(interfaces,cd.implements[#itf#]);
            }
        }
            
        return interfaces;
    }
 
    function GetMethods(ancestors) {
        
        var methods = StructNew() ;
        var curAncestor = "";
        var curMethod = "";
        
        for ( i=1; i lte ArrayLen(ancestors); i=i+1 ) {
            curAncestor = ancestors[i] ;
            
            if ( StructKeyExists( curAncestor, 'functions' ) )
                for ( j=1; j lte ArrayLen( curAncestor.functions ); j=j+1 ) {
                    curMethod = StructNew() ;
                    curMethod.metadata = curAncestor.functions[j] ;
                    curMethod.implementedIn = curAncestor.name ;
                    if ( i eq ArrayLen(ancestors)                                 // don't exclude any method 1)from this
                        or not StructKeyExists( curMethod.metadata, 'access' )     // 2)that does not have 'access' attribute
                        or curMethod.metadata.access neq 'private' ) {            // 3)that does not have access='private'
                        methods[curmethod.metadata.name] = curMethod ;
                    }
                }
        
        }    
        return methods ;
    }
    
    /**
    *    Gets methods of given interface metadata and its parents. Gets methods recursively
    
    *    @param cd - Metadata of an interface
    *    @param methods - Struct of methods obtained so far. 
    *    @param originalInterface - A flag indicating if this method is being called for 
    *                            the original interface for which are obtaining methods. 
    *                            For recursive calls, this flag is set to false.
    *    @return Struct. Key is method name. Value is a Struct contining metadata of the method,
    *                    and name of the interface where it is defined
    *                    
    */
    function GetInterfaceMethods(cd, methods, originalInterface) {
        var curMethod = "";
        
        if (not IsStruct(cd))
            return methods;
            
        if (StructKeyExists(cd,'extends')) {
            for (intf in cd.extends)
            {
                methods = GetInterfaceMethods(cd.extends[#intf#],methods,false);
            }
        } 
                
        if ( StructKeyExists( cd, 'functions' ) ) {
            for ( j=1; j lte ArrayLen( cd.functions ); j=j+1 ) {
                curMethod = StructNew() ;
                curMethod.metadata = cd.functions[j] ;
                curMethod.implementedIn = cd.name ;
                if ( originalInterface                                 // don't exclude any method 1)from this
                    or not StructKeyExists( curMethod.metadata, 'access' )     // 2)that does not have 'access' attribute
                    or curMethod.metadata.access neq 'private' ) {            // 3)that does not have access='private'
                    methods[curmethod.metadata.name] = curMethod ;
                }
            }//of for (j = 1; j lte ArrayLen(currAncestorchain); j = j+1)
        }
        
        return methods;
    }
 
    function GetProperties(ancestors) {
        
        var properties = StructNew();
        var curAncestor = "";
        var curProperty = "";
        
        for ( i=1; i lte ArrayLen(ancestors); i=i+1 ) {
            curAncestor = ancestors[i] ;
            
            if ( StructKeyExists( curAncestor, 'properties' ) )
                for ( j=1; j lte ArrayLen( curAncestor.properties ); j=j+1 ) {
                    curProperty = StructNew() ;
                    curProperty.metadata = curAncestor.properties[j] ;
                    curProperty.implementedIn = curAncestor.name ;
                    properties[curProperty.metadata.name] = curProperty ;
                }
        
        }    
        return properties ;
    
    }
    
    function GetFullComponentName( name ) {
        var package = "";
        if ( Find( '.', name ) )
            return name ;
        else {
            package = ListDeleteAt( cd.name, ListLen( cd.name, '.' ), '.' ) ;
            return ListAppend( package, name, '.' ) ;
        }
    }
 
    function GetShortComponentName( name ) {
        var package ="";
        var referencePackage = "";
        if ( Find( '.', name ) ) {
            package = ListDeleteAt( name, ListLen( name, '.' ), '.' ) ;
            referencePackage = ListDeleteAt( cd.name, ListLen( cd.name, '.' ), '.' ) ;
            if ( package eq referencePackage )
                return ListLast( name, '.' ) ;
            else
                return name ;
        } else
            return name ;
    
    }
    
    function GetURLToViewer( fullName, anchor ) {
        var url = '#getpageContext().getRequest().getContextPath()#/CFIDE/componentutils/cfcexplorer.cfc?method=getcfcinhtml&name=' & fullName ;
        if ( anchor neq '' )
            url = url & '&##' & anchor ;
        return url ;
    }
    
    function GetLinkForType( type, captionType ) {
        var caption = "";
        
        if ( ListFindNoCase( 'string,numeric,boolean,date,any,binary,UUID,variableName,query,array,struct,object', type ) )
            return type ;
        else {
            caption = GetShortComponentName( type ) ;
            type = GetFullComponentName( type ) ;
            if ( captionType eq "LONG" )
                caption = type ;
            if ( type eq cd.name )
                return caption ;
            else
                return "<a href=""" & GetURLToViewer( type, '' ) & """>" & caption & "</a>" ;
        }
    }
    
    function GetLinkForMethod( methodName, componentName ) {
        return "<a href=""" & 
            GetURLToViewer( GetFullComponentName(componentName), 'method_' & methodName ) &
            """>" & methodName & "</a>" ;
    }
 
    // returns path with forward slashes without a trailing slash
    function GetNormalizedPath( path ) {
        path = Replace( path, '\', '/', 'ALL' ) ;
        if ( Right( path, 1 ) eq '/' )
            path = RemoveChars( path, Len(path), 1     ) ;
        return path ;
    }
    
    // returns true if root is longer (closer to the path) than
    // the closestRoot and if path is under the root
    function IsResolvable( path, root, closestRoot ) {
        return ( Len(root) gt Len(closestRoot )
                and Find( root, path, 1 ) eq 1 ) ;
    }
    
    // returns full component name; 
    // when calling this function path must be resolvable
    function ResolveName( path, root, mapping ) {
        var name = RemoveChars( path, 1, Len(root) ) ; // remove root
        name = Left( name, Len(name) - 4 ) ;    // remove '.cfc'
        name = mapping & name ;            // prepend mapping
        
        // remove leading slash
        if ( Left( name, 1 ) eq '/' )
            name = RemoveChars( name, 1, 1) ;
        
        // convert slashes to dots and return
        return Replace( name, '/', '.', 'ALL' ) ;
    }
</cfscript>