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
<!--- 
  errorcontext.cfm reads the file specified by a TAGCONTEXT-type struct 
  and returns an array of structures which contain the text of  the failing 
  line,and lines near it, along with their line numbers.
 
  @param errorLocation  - the TAGCONTEXT entry for the failed template/line.
  @param showcontext    - number of additional lines before/after failure displayed.
  @param resultVariable - the name of the caller's var where the resulting 
 
--->
 
<cfparam name="attributes.errorLocation">
<cfparam name="attributes.showcontext">
<cfparam name="attributes.resultVariable">
 
<cfif thistag.executionmode is "start">
 
    <!--- localization --->
    <cfset locale = createObject("java", "java.util.Locale").getDefault().getLanguage()>
    <cfset l10n_caller = "detail">
    
    <cftry>
        <cfif FileExists("exception_#locale#.xml")>
            <cfinclude template="exception_#locale#.xml">
        <cfelse>
            <cfinclude template="exception_en.xml">
        </cfif>
        <cfcatch>
            <cfinclude template="exception_en.xml">
        </cfcatch>
    </cftry>
    
    <cfset result = ArrayNew(1)>
    <cfscript>
        try
        {
        firstLine = attributes.errorLocation.line - attributes.showcontext;
        lastLine  = attributes.errorLocation.line + attributes.showcontext;
 
        //create an instance of VFSFileFactory to fetch the intputstream
        vfsfilefactory = createObject("java", "coldfusion.vfs.VFSFileFactory");
        
        //get the input stream for the file
        inputStream = vfsfilefactory.getInputStream(attributes.errorLocation.Template);
        
        //  Wrap a InputStreamReader in a LineNumberReader to read the CFML template as text.
        inputStreamReaderClass = createObject("java", "java.io.InputStreamReader");
        inputStreamReader = inputStreamReaderClass.init(inputStream);
        
        lineReaderClass = createObject("java", "java.io.LineNumberReader" );
        lineReader = lineReaderClass.init(inputStreamReader);
 
        currentLine = lineReader.readLine();
 
        while ( isDefined("currentLine") and lineReader.getLineNumber() lte lastLine )
        {
            if ( lineReader.getLineNumber() gte firstLine )
            {
                lineInfoStruct            = structNew();
                lineInfoStruct.line       = currentLine;
                lineInfoStruct.lineNumber = lineReader.getLineNumber();
                ArrayAppend(result, lineInfoStruct);
            }
            currentLine = lineReader.readLine();
        }
        } catch ( "Any" ex) {
            lineInfoStruct = structNew();
            lineInfoStruct.line = s_unable;
            lineInfoStruct.lineNumber = -1;
            lineInfoStruct.diagnostic = ex;
                
            ArrayAppend(result, lineInfoStruct);
        }
        finally
        {
            if(isDefined("lineReader"))
            {
                lineReader.close();
            }
        }    
 
    </cfscript>
 
    <cfset setVariable("caller.#attributes.resultVariable#", result )>
</cfif>