ColdFusion GetPageContext() Massive Exploration
Posted June 6, 2007 at 7:37 PM by Ben Nadel
Over the past few months, I have been giving some free time to exploring ColdFusion's GetPageContext() function. The data available through this function is maaaaassive in scope. I thought it would be a fun little project, but it is just overwhelming, and I fear, not that useful. There is some really cool stuff in there, but it's in the minority (at least from my standpoint).
I was originally going to do an exhaustive search before I posted any results, but I don't know if I am ever going to finish. As such, I have decided to post what I have so far; and then, as I have time to update this, I will update this post. If I find anything cool, I will post referencing back to this post, but mostly, I will just update this when I have a few free moments.
Stuff that has ".........." is just stuff I have not explored yet.
coldfusion.runtime.NeoPageContext ( Returned from GetPageContext() )
Extends: javax.servlet.jsp.PageContextSymTab_findBuiltinScope
Searches for a built-in scope with the given name. If the scope can be found, it returns a reference to it. If it cannot be found it returns null.
Parameters: java.lang.String
Returns: java.util.Map (ie. ColdFusion Struct)[[cfset objRequestScope = GetPageContext().SymTab_findBuiltinScope( "request" ) /]]
SymTab_findSimpleName
Searches "local" scopes to find a variable with the given simple name. Returns value of variable. This will not search scopes like APPLIACTION, SESSION, REQUEST.
Parameters: java.lang.String
Returns: java.lang.Object[[cfset foo = "bar" /]]
##GetPageContext().SymTab_findSimpleName( "foo" )##Outputs: "bar"
[[cfset foo = StructNew() /]]
##GetPageContext().SymTab_findSimpleName( "foo" )##Outputs: [empty struct]
SymTab_resolveDottedName
Gets the value of a variable at the given variable name using dot-notation.
Parameters: java.lang.String
Returns: java.lang.Object[[cfset APPLICATION.Azure = "hottie" /]]
##GetPageContext().SymTab_resolveDottedName( "APPLICATION.Azure" )##Outputs: hottie
SymTab_resolveSplitName
Cannot determine use. Seems to act similar to SymTab_resolveDottedName but takes an array of strings rather than a simple string value. Seems to fail if array is more than one value.
Parameters: [ java.lang.String ]
Returns: java.lang.Object[[cfset Girls = StructNew() /]]
##GetPageContext().SymTab_resolveSplitName( ListToArray( "Girls" ) )/]]Outputs: [Empty Struct]
SymTab_setBuiltinCFScopes
Adds a ColdFusion scope to the stack of scopes that will be searched when looking for a given value.
Parameters: coldfusion.runtime.Scope
Returns: void[[cfset APPLICATION.Azure = "hottie" /]]
##GetPageContext().SymTab_setBuiltinCFScopes( "Azure" )##
##Azure##Outputs: [empty string]
Outputs: [CFERROR: UNDEFINED VARIABLE][[cfset APPLICATION.Azure = "hottie" /]]
[[cfset GetPageContext().SymTab_setBuiltinCFScopes( APPLICATION ) /]]
##GetPageContext().SymTab_setBuiltinCFScopes( "Azure" )##
##Azure##Outputs: hottie
Outputs: hottieSymTab_setDottedName
Sets the given variable name to the given value.
Parameters: java.lang.String, java.lang.Object
Returns: void[[cfset GetPageContext().SymTab_setDottedName( "REQUEST.Libby", "sexy" ) /]]
##REQUEST.Libby##Outputs: sexy
SymTab_setSimpleName
Seems to act the same as SymTab_setDottedName(). Sets a the given variable to the given value.
Parameters: java.lang.String, java.lang.Object
Returns: void[[cfset GetPageContext().SymTab_setSimpleName( "REQUEST.Libby", "sexy" ) /]]
##REQUEST.Libby##Outputs: sexy
SymTab_setSplitNameInMap
Puts the value in the given map (ie. ColdFusion structure). Value is placed based on the key-chain defined by the given array.
Parameters: java.util.Map, [ java.lang.Object ], java.lang.Object
Returns: void[[cfset Girls = StructNew() /]]
[[cfset GetPageContext().SymTab_setSplitNameInMap(
Girls,
ListToArray( "Libby,Hotness" ),
"8.0"
) /]]
[[cfdump var="##Girls##" /]]Outputs: { Libby: { Hotness: 8.0 } }
SymTab_setValidatedSplitNameInString
Creates a struct at the given name (param 1) and sets the given value in the struct based on the path defined by the array.
Parameters: java.lang.String, [ java.lang.Object ], java.lang.Object
Returns: void[[cfset GetPageContext().SymTab_setSplitNameInMap(
"Hotties",
ListToArray( "Libby,Hotness" ),
"8.0"
) /]]
[[cfdump var="##Hotties##" /]]Outputs: { Libby: { Hotness: 8.0 } }
emitWhitespace
I did not bother playing around with this.
Parameters: java.io.Writer, java.lang.String
Returns: voidequals
Test the equality of an object to the page context.
Parameters: java.lang.Object
Returns: boolean[[cfset PageContext = GetPageContext() /]]
##PageContext.equals( GetPageContext() )##Outputs: YES
findAttribute
Seems to search ColdFusion scopes for the variable with the given name. Seems very similar to SymTab_findSimpleName(). The searchable scopes is affected by SymTab_setBuiltinCFScopes().
Parameters: java.lang.String
Returns: java.lang.Object[[cfset Anne = "saucy" /]]
##GetPageContext().findAttribute( "Anne" )##Outputs: saucy
flushOutput
Flushs the content buffer to the output. (ie. CFFlush).
Parameters:
Returns:forward
This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application (source). This creates a "new" page request without refreshing the client page. Seems to maintain the REQUEST scope but clears all other non-persisting scopes.
Parameters: java.lang.String
Returns: voidgetActiveFunctionLocalScope
Gets the local scope of the current function which contains var'd variables and the ARGUMENTS scope. Returns NULL if there is no local scope.
Parameters:
Returns: coldfusion.runtime.LocalScope[[cffunction name="FN"]] [[cfset var Nicole = "very naught" /]]
[[cfdump var="##GetPageContext().getActiveFunctionLocalScope()##" /> /]]
[[/cffunction]]
[[cfset FN() /]]Outputs: { ARGUMENTS: {}, Nicole: "very naughty" }
getAttribute
Return the object associated with the name in the page scope or null if not found. (source). Appears to only check the VARIABLES scope and is not affected by SymTab_setBuiltinCFScopes().
Parameters: java.lang.String
Returns: java.lang.Object[[cfset VARIABLES.Fantacy = "Christina" /]]
##GetPageContext().getAttribute( "Fantasy" )##Outputs: Christina
getAttribute
Return the object associated with the name in the specified scope or null if not found. (source). Scope index (param 2) is a constant of the Page Context (which I cannot seem to access).
Parameters: java.lang.String, int
Returns: java.lang.ObjectgetAttributeNamesInScope
Returns an enumeration of the keys in the given scope.
Parameters: int
Returns: java.util.Enumeration[[cfset VARIABLES.Fantacy = "Christina" /]]
[[cfset objEnum = GetPageContext().getAttributeNamesInScope( JavaCast( "int", 1 ) ) /]]
[[cfloop condition="objEnum.HasMoreElements()"]]
##objEnum.NextElement()##
[[/cfloop]]Outputs: Christina
getAttributesScope
Get the scope where a given attribute is defined. (source). Returns the index of the scope. Cannot seem to figure out which scopes it will or will not search. Returns zero if not found.
Parameters: java.lang.String
Returns: intgetBuiltInScopes
Returns a structure of all the built-in ColdFusion structures. CAUTION: If you CFDump this out, you might get HUGE HUGE HUGE and potentially circular results.
Parameters:
Returns: coldfusion.runtime.ScopegetCFOutput
Returns the current JSP Writer??? CFOutput extends coldfusion.runtime.NeoJspWriter extends javax.servlet.jsp.JspWriter extends java.io.Writer
Parameters:
Returns: coldfusion.runtime.CFOutputgetCFOutput().cfoutput
I could not figure out what this does.
Parameters: boolean
Returns: voidgetCFOutput().clear
Clears the content buffer that has not yet been flushed to the client. Does not throw an error if content has already been flushed.
Parameters:
Returns: voidgetCFOutput().clearAll
Clears the content buffer that has not yet been flushed to the client. Does not throw an error if content has already been flushed.Not sure how the "All" part comes into play.
Parameters:
Returns: voidgetCFOutput().clearBuffer
Clears the content buffer that has not yet been flushed to the client. Does not throw an error if content has already been flushed.Not sure how the "All" part comes into play.
Parameters:
Returns: voidgetCFOutput().close
Could not figure out what this does. Supposed to close the output stream, but did not have any affect.
Parameters:
Returns: voidgetCFOutput().enablecfoutputonly
Turns off on (true) and off (false) the page setting for enabling CFOutput only.
Parameters: boolean
Returns: void[[cfset GetPageContext().GetCFOutput().enablecfoutputonly( JavaCast( "boolean", true ) ) /]]
Hey, what's up?
[[cfoutput]]
Not much.
[[/cfoutput]]Outputs: Not much.
getCFOutput().flush
Flushed the content buffer to the client. Seems to do the same thing as the CFFlush tag.
Parameters:
Returns: voidgetCFOutput().getBuffer
Gets the current content buffer. coldfusion.runtime.CharBuffer extends java.io.CharArrayWriter extends java.io.Writer
Parameters:
Returns: coldfusion.runtime.CharBuffergetCFOutput().getBuffer().close
Close the stream. This method does not release the buffer, since its contents might still be required. (source). I could not really get this to do anything.
Parameters:
Returns: voidgetCFOutput().getBuffer().findStringNoCase
This returns the (zero-based) index of the string in the existing buffer and -1 if the string is not found. This only checks buffer content that has not yet been flushed to the client.
Parameters: java.lang.String
Returns: intgetCFOutput().getBuffer().findStringNoCase
This returns the (zero-based) index of the string in the existing buffer and -1 if the string is not found. The second argument is the index at which to start searching. This only checks buffer content that has not yet been flushed to the client.
Parameters: java.lang.String, int
Returns: intgetCFOutput().getBuffer().flush
This didn't seem to do anything. I could still set header values after this was called so apparently it didn't flush anything.
Parameters:
Returns: voidgetCFOutput().getBuffer().getCharAt
Gets the characters in the content buffer located at the given (zero-based) index value.
Parameters: int
Returns: chargetCFOutput().getBuffer().replace
I could not figure out how to call this properly.
Parameters: int, int, int, [ Char ]
Returns: voidgetCFOutput().getBuffer().replace
This starts at the given (zero-based) buffer index (param 1) and writes X number of characters (param 2) from the given string (param 3) to the buffer. Param 2 CANNOT be longer than the given string.
Parameters: int, int, java.lang.String
Returns: voidgetCFOutput().getBuffer().replace
This starts at the given (zero-based) buffer index (param 1) and overwrites the content buffer with the given string (param 2).
Parameters: int, java.lang.String
Returns: voidgetCFOutput().getBuffer().reset
Resets the buffer so that you can use it again without throwing away the already allocated buffer. (source). Could not really figure out what this did. It didn't seem to clear the buffer or anything.
Parameters:
Returns: voidgetCFOutput().getBuffer().setCharAt
Set the character at the given index (param 1) to the character denoted by the given ASCII number (param 2).
Parameters: int, char
Returns: voidABC [[cfset GetPageContext().getCFOutput().getBuffer().setCharAt( 0, Asc( "Z" ) ) /]]
Outputs: ZBC
getCFOutput().getBuffer().setCount
Could not figure out what this does.
Parameters: int
Returns: voidgetCFOutput().getBuffer().size
This returns the current size of the content buffer.
Parameters:
Returns: int12345#GetPageContext().getCFOutput().getBuffer().size()#
Outputs: 5
getCFOutput().getBuffer().substring
Gets the substring of the content buffer starting at the given index (param 1) and continuing to the second index (param 2).
Parameters: int, int
Returns: java.lang.StringgetCFOutput().getBuffer().toCharArray
Returns an array of Character objects reflective of the content buffer. This can be accessed as a ColdFusion array to get the individual characters.
Parameters:
Returns: [ Char ]getCFOutput().getBuffer().toString
Returns a string of the content buffer data.
Parameters:
Returns: java.lang.StringgetCFOutput().getBuffer().write
I could not get this to work.
Parameters: [ Char ]
Returns: voidgetCFOutput().getBuffer().write
I could not get this to work.
Parameters: [ Char ], int, int
Returns: voidgetCFOutput().getBuffer().write
I could not get this to work.
Parameters: int
Returns: voidgetCFOutput().getBuffer().write
I could not get this to work.
Parameters: java.lang.String
Returns: voidgetCFOutput().getBuffer().write
I could not get this to work.
Parameters: java.lang.String, int, int
Returns: voidgetCFOutput().getBuffer().writeTo
Writes the current buffer content to another writer. I did not mess with this.
Parameters: java.io.Writer
Returns:getCFOutput().getBuffer().writeTo
I am guessing this writes the current buffer at the given offset for the given legnth to another writer. I did not mess with this.
Parameters: java.io.Writer, int, int
Returns:
getCFOutput().getBufferSize
Returns the size of the buffer in bytes, or 0 is unbuffered. (source)
Parameters:
Returns: intgetCFOutput().getDisableCount
Not sure what this is supposed to do.
Parameters:
Returns: intgetCFOutput().getLogicalMark
Seems to get some sort of character index of the current buffer. If the content is flushed, this index is reset.
Parameters:
Returns: intgetCFOutput().getOutputCount
Gets the number of CFOuput tags that wrap this statement.
Parameters:
Returns: intgetCFOutput().getRemaining
Returns the number of bytes unused in the buffer. (source).
Parameters: -
Returns: -getCFOutput().getString
Returns the content of the current buffer as a string.
Parameters:
Returns: java.lang.StringgetCFOutput().getWriter
Gets the current writer (that writes to the current buffer I assume).
Parameters:
Returns: javax.servlet.jsp.JspWritergetCFOutput().isAutoFlush
Returns whether or not the buffer will auto flush the buffer to the client before throwing an overlof exception.
Parameters:
Returns: booleangetCFOutput().newLine
Writes a new line character to the buffer.
Parameters:
Returns: voidgetCFOutput().print
Prints the given value to the content buffer.
Parameters: [ Char ] | boolean | char | double | float | int | java.lang.Object | java.lang.String | long
Returns: void[[cfset GetPageContext().getCFOutput().print( "Hey there hot momma" ) /]]
Outputs: Hey there hot momma
getCFOutput().println
Prints the given value to the content buffer and then terminates the line (prints a line break).
Parameters: [ Char ] | boolean | char | double | float | int | java.lang.Object | java.lang.String | long
Returns: voidgetCFOutput().setFlushThreshold
I assume this sets the number of bytes the buffer will hold before it is flushed to the client. I did not mess with this.
Parameters: int
Returns: voidgetCFOutput().setIsTopBuffer
I could not figure out what this does.
Parameters: boolean
Returns: voidgetCFOutput().setLogicalMark
Sets some sort of internal index for the buffer. Messing with this value will cause some of the buffer to never be flushed. Couldn't figure out how it translated.
Parameters: int
Returns: voidgetCFOutput().whitespaceTerminated
Seems to set the flag for killing white space created by ColdFusion tags. Not really sure about that.
Parameters:
Returns: voidgetCFOutput().write
Write the character array to the content buffer.
Parameters: [ char ]
Returns: voidgetCFOutput().write
Writes the given character array to the buffer starting at the given offset (param 2) for the given length (param 3).
Parameters: [ char ], int, int
Returns: void[[cfset GetPageContext().getCFOutput().write( "123456789", JavaCast( "int", 3 ), JavaCast( "int", 2 ) ) /]]
Outputs: 45
getCFOutput().write
Not sure what this does.
Parameters: int
Returns: voidgetCFOutput().write
Writes the given string to the content buffer.
Parameters: java.lang.String
Returns:getCFOutput().write
Writes the given string to the content buffer starting at the given offset (param 2) for the given length (param 3).
Parameters: java.lang.String, int, int
Returns: voidgetCFOutput().writeHeader
Writes the given content to the output so long as no content has to be flushed to the client. Writes the content to beginning of the buffer even if the buffer has already been populated. I believe this is NOT actually writing to the buffer, but some sort of buffer-head. Writing values to the header seem NOT to affect other buffer-related manipulation (which is why I think it might not actually change the buffer itself).
Parameters: java.lang.String
Returns: booleanSTART [[cfset GetPageContext().getCFOutput().writeHeader( "END" ) /]]
Outputs: END START
getCFScopes
Returns an array of some of the ColdFusion scopes. Not sure exactly which it returns. Not all of them.
Parameters:
Returns: java.util.VectorgetClass
Returns the Java class of the current object.
Parameters:
Returns: java.lang.ClassgetDefaultQuery
Could not determine what this does.
Parameters:
Returns: coldfusion.runtime.QueryVectorgetException
Returns the current exception object. Could not figure how to get a value from this. CFTry / CFCatch did not allow any return value.
Parameters:
Returns: java.lang.ExceptiongetFusionContext
Not exactly sure what a Fusion Context is. I suppose it is the context in which the current ColdFusion page request is executing (not that means much of anything either).
Parameters:
Returns: coldfusion.filter.FusionContextgetFusionContext().SymTab_finalizeAfterRequest
Not sure what this does. Attempts to use it seemed to throw a 500 NULL error.
Parameters: boolean
Returns: voidgetFusionContext().SymTab_initForRequest
Not sure what this does. Attempts to use it seemed to throw a 500 NULL error.
Parameters: boolean
Returns:getFusionContext().SymTab_popActiveScope
I assume this is used to manipulate the scope chain. I couldn't figure out how to mess with this.
Parameters:
Returns: voidgetFusionContext().SymTab_pushActiveScope
I assume this is used to manipulate the scope chain. I couldn't figure out how to mess with this.
Parameters: coldfusion.runtime.Scope
Returns: voidgetFusionContext().SymTab_pushActiveScope
I assume this is used to manipulate the scope chain. I couldn't figure out how to mess with this.
Parameters: coldfusion.runtime.VariableScope
Returns: voidgetFusionContext().SymTab_setApplicationScope
Set's the given struct as the struct to be used as the APPLICATION scope.
Parameters: java.lang.Object
Returns: voidgetFusionContext().SymTab_setClientScope
Set's the given struct as the struct to be used as the CLIENT scope.
Parameters: java.lang.Object
Returns: voidgetFusionContext().SymTab_setSessionScope
Set's the given struct as the struct to be used as the SESSION scope.
Parameters: java.lang.Object
Returns: voidgetFusionContext().addExceptionHandler
I assume this addes a handler for a given exception type. Could not figure out even how to mess with this.
Parameters: java.lang.String, java.lang.Class, java.lang.String
Returns: voidgetFusionContext().createContextData
Could not figure out how to use this.
Parameters: javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.io.OutputStream
Returns: coldfusion.filter.FusionContext$FusionContextDatagetFusionContext().getApplicationEventEnableStatus
No idea what this does.
Parameters:
Returns: booleangetFusionContext().getApplicationName
Returns the name of the application as defined in the CFApplication tag or the ApplicationName value of the Application.cfc component.
Parameters:
Returns: java.lang.StringgetFusionContext().getCurrent
Returns the current fusion context reference.
Parameters:
Returns: coldfusion.filter.FusionContextgetFusionContext().getEventContext
I could not figure out how to use this.
Parameters:
Returns: coldfusion.eventgateway.EventContextgetFusionContext().getFormScope
Returns a reference to the current FORM scope (struct).
Parameters:
Returns: coldfusion.filter.FormScopegetFusionContext().getPagePath
Returns the full template path of the executing page. Seems to be the same as GetBaseTemplatePath().
Parameters:
Returns: java.lang.StringgetFusionContext().getRealPath
Seems to simply append the given path to the web root's server path.
Parameters: java.lang.String
Returns: java.lang.StringgetFusionContext().getRequest
Upon a cursory glance at the available methods, this seems to be the same thing as GetPageContext().GetRequest(), but I have not tested to see if it is going different things.
Parameters:
Returns: javax.servlet.http.HttpServletRequestgetFusionContext().getRequestContent
Could not figure out what this was doing. I assume it gets the binary data of the request?
Parameters:
Returns: [ B ]getFusionContext().getResponse
Gets the page response object. javax.servlet.http.HttpServletResponseWrapper extends javax.servlet.ServletResponseWrapper extends java.lang.Object.
Upon a cursory glance of the available methods, this appears to be the same thing at GetPageContext().GetResponse(). I did not test to see if it functions any differently.
Parameters:
Returns: javax.servlet.http.HttpServletResponsegetFusionContext().getSecurePassword
Could not figure out what this does.
Parameters:
Returns: java.lang.StringgetFusionContext().getSecureTable
Could not figure out what this does.
Parameters: -
Returns: coldfusion.runtime.SecurityTablegetFusionContext().getSecureUsername
Could not figure out what this does.
Parameters:
Returns: java.lang.StringgetFusionContext().getServlet
coldfusion.CfmServlet extends javax.servlet.http.HttpServlet extends javax.servlet.GenericServlet extends java.lang.Object.
I did not bother checking to see what this does.
Parameters:
Returns: javax.servlet.ServletgetFusionContext().getServletContext
I did not bother checking to see what this does.
Parameters:
Returns: javax.servlet.ServletContextgetFusionContext().getSession
Returns the Http session that binds the http client to the http server. jrun.servlet.session.JRunSession extends java.util.Hashtable extends java.util.Dictionary extends java.lang.Object ..............................
Parameters:
Returns: javax.servlet.http.HttpSessiongetFusionContext().getSession().clear
.........................
Parameters: -
Returns: -getFusionContext().getSession().clearAttributeSet
.........................
Parameters: -
Returns: -getFusionContext().getSession().contains
.........................
Parameters: -
Returns: -getFusionContext().getSession().containsKey
.........................
Parameters: -
Returns: -getFusionContext().getSession().containsValue
.........................
Parameters: -
Returns: -getFusionContext().getSession().elements
.........................
Parameters: -
Returns: -getFusionContext().getSession().entrySet
.........................
Parameters: -
Returns: -getFusionContext().getSession().equals
.........................
Parameters: -
Returns: -getFusionContext().getSession().get
.........................
Parameters: -
Returns: -getFusionContext().getSession().getAttribute
.........................
Parameters: -
Returns: -getFusionContext().getSession().getAttributeNames
.........................
Parameters: -
Returns: -getFusionContext().getSession().getClass
.........................
Parameters: -
Returns: -getFusionContext().getSession().getCreationTime
.........................
Parameters: -
Returns: -getFusionContext().getSession().getId
.........................
Parameters: -
Returns: -getFusionContext().getSession().getLastAccessedTime
.........................
Parameters: -
Returns: -getFusionContext().getSession().getMaxInactiveInterval
.........................
Parameters: -
Returns: -getFusionContext().getSession().getServletContext
.........................
Parameters: -
Returns: -getFusionContext().getSession().getSessionContext
.........................
Parameters: -
Returns: -getFusionContext().getSession().getValue
.........................
Parameters: -
Returns: -getFusionContext().getSession().getValueNames
.........................
Parameters: -
Returns: -getFusionContext().getSession().invalidate
.........................
Parameters: -
Returns: -getFusionContext().getSession().isAttributeSet
.........................
Parameters: -
Returns: -getFusionContext().getSession().isEmpty
.........................
Parameters: -
Returns: -getFusionContext().getSession().isNew
.........................
Parameters: -
Returns: -getFusionContext().getSession().isSessionValid
.........................
Parameters: -
Returns: -getFusionContext().getSession().isTimedOut
.........................
Parameters: -
Returns: -getFusionContext().getSession().keySet
.........................
Parameters: -
Returns: -getFusionContext().getSession().keys
.........................
Parameters: -
Returns: -getFusionContext().getSession().put
.........................
Parameters: -
Returns: -getFusionContext().getSession().putAll
.........................
Parameters: -
Returns: -getFusionContext().getSession().putValue
.........................
Parameters: -
Returns: -getFusionContext().getSession().remove
.........................
Parameters: -
Returns: -getFusionContext().getSession().removeAttribute
.........................
Parameters: -
Returns: -getFusionContext().getSession().removeValue
.........................
Parameters: -
Returns: -getFusionContext().getSession().setAttribute
.........................
Parameters: -
Returns: -getFusionContext().getSession().setMaxInactiveInterval
.........................
Parameters: -
Returns: -getFusionContext().getSession().setTimedOut
.........................
Parameters: -
Returns: -getFusionContext().getSession().size
.........................
Parameters: -
Returns: -getFusionContext().getSession().updateLastAccessTime
.........................
Parameters: -
Returns: -getFusionContext().getSession().values
.........................
Parameters: -
Returns: -
getFusionContext().getStartTime
Returns the date/time stamp at which the page request started processing.
Parameters:
Returns: java.util.DategetFusionContext().getUseMappings
No idea what this does.
Parameters:
Returns: booleangetFusionContext().isRemoting
Did not test this, but I assume this checks to see if the page is being run by a remote service (ie. Flash remoting, or web service)?
Parameters:
Returns: booleangetFusionContext().setApplicationEventEnableStatus
No idea what this does.
Parameters: boolean
Returns: voidgetFusionContext().setApplicationName
Could not get this to work. Calling this did not seem to have any affect on the name stored in the APPLIACTION scope.
Parameters: java.lang.String
Returns: voidgetFusionContext().setCurrent
No idea what this does.
Parameters: coldfusion.filter.FusionContext
Returns: coldfusion.filter.FusionContextgetFusionContext().setEventContext
No idea what this does.
Parameters: coldfusion.eventgateway.EventContext
Returns: voidgetFusionContext().setIsRemoting
Sets the flag that is returned by IsRemoting() method. Not sure what else this affects (if anything).
Parameters: boolean
Returns: booleangetFusionContext().setPagePath
Messing with this seemed to break the rest of the page processing. I could not even CFDump out CGI directly after setting this.
Parameters: java.lang.String
Returns: voidgetFusionContext().setRequestErrorHandler
Not sure what this does.
Parameters: java.lang.String, java.lang.String
Returns: voidgetFusionContext().setSecureCredentials
Not sure what this does.
Parameters: java.lang.String, java.lang.String
Returns: voidgetFusionContext().setSecureTable
Not sure what this does.
Parameters: coldfusion.runtime.SecurityTable
Returns: voidgetFusionContext().setServletObjects
Not sure what this does.
Parameters: javax.servlet.Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse
Returns: voidgetFusionContext().setUseMappings
Not sure what this does.
Parameters: boolean
Returns: voidgetFusionContext().setValidationErrorHandler
Not sure what this does.
Parameters: java.lang.String
Returns: void
getOut
Returns the current value of the out object (a JspWriter). (source)
................................
Parameters:
Returns: javax.servlet.jsp.JspWritergetPage
Returns the current value of the page object (a Servlet). (source). This seems to contain all the page-accessable values including all ColdFusion methods.
...................................
Parameters:
Returns: java.lang.ObjectgetRandomNumberGenerator
Returns a random number generator.
Parameters:
Returns: java.util.RandomgetRandomNumberGenerator
This returns a cryptographically strong pseudo-random number generator. (source). Can provide the algorithm to be used.
Parameters: java.lang.String
Returns: java.security.SecureRandomgetRequest
Return the current value of the request object (a ServletRequest). (source). javax.servlet.ServletRequest extends jrun.servlet.ForwardRequest extends jrun.servlet.RequestWrapper extends javax.servlet.http.HttpServletRequestWrapper extends javax.servlet.ServletRequestWrapper.
Parameters:
Returns: javax.servlet.ServletRequestgetRequest().getAttribute
.........................
Parameters: java.lang.String
Returns: java.lang.ObjectgetRequest().getAttributeNames
.........................
Parameters:
Returns: java.util.EnumerationgetRequest().getAuthType
.........................
Parameters:
Returns: java.lang.StringgetRequest().getCharacterEncoding
.........................
Parameters:
Returns: java.lang.StringgetRequest().getContentLength
.........................
Parameters:
Returns: intgetRequest().getContentType
.........................
Parameters:
Returns: java.lang.StringgetRequest().getContextPath
.........................
Parameters:
Returns: java.lang.StringgetRequest().getCookies
.........................
Parameters:
Returns: [ javax.servlet.http.Cookie ]getRequest().getDateHeader
.........................
Parameters: java.lang.String
Returns: longgetRequest().getHeader
.........................
Parameters: java.lang.String
Returns: java.lang.StringgetRequest().getHeaderNames
.........................
Parameters:
Returns: java.util.EnumerationgetRequest().getHeaders
.........................
Parameters: java.lang.String
Returns: java.util.EnumerationgetRequest().getHttpRequest
.........................
Parameters:
Returns: javax.servlet.http.HttpServletRequestgetRequest().getInputStream
.........................
Parameters:
Returns: javax.servlet.ServletInputStreamgetRequest().getIntHeader
.........................
Parameters: java.lang.String
Returns: intgetRequest().getLocale
.........................
Parameters:
Returns: java.util.LocalegetRequest().getLocales
.........................
Parameters:
Returns: java.util.EnumerationgetRequest().getMethod
.........................
Parameters:
Returns: java.lang.StringgetRequest().getParameter
.........................
Parameters: java.lang.String
Returns: java.lang.StringgetRequest().getParameterMap
.........................
Parameters:
Returns: java.util.MapgetRequest().getParameterNames
.........................
Parameters:
Returns: java.util.EnumerationgetRequest().getParameterValues
.........................
Parameters: java.lang.String
Returns: [ java.lang.String ]getRequest().getPathInfo
.........................
Parameters:
Returns: java.lang.StringgetRequest().getPathTranslated
.........................
Parameters:
Returns: java.lang.StringgetRequest().getProtocol
.........................
Parameters:
Returns: java.lang.StringgetRequest().getQueryString
.........................
Parameters:
Returns: java.lang.StringgetRequest().getReader
.........................
Parameters:
Returns: java.io.BufferedReadergetRequest().getRealPath
.........................
Parameters: java.lang.String
Returns: java.lang.StringgetRequest().getRemoteAddr
.........................
Parameters:
Returns: java.lang.StringgetRequest().getRemoteHost
.........................
Parameters:
Returns: java.lang.StringgetRequest().getRemoteUser
.........................
Parameters: java.lang.String
Returns: java.lang.StringgetRequest().getRequest
.........................
Parameters:
Returns: javax.servlet.ServletRequestgetRequest().getRequestDispatcher
.........................
Parameters: java.lang.String
Returns: javax.servlet.RequestDispatchergetRequest().getRequestURI
.........................
Parameters:
Returns: java.lang.StringgetRequest().getRequestURL
.........................
Parameters:
Returns: java.lang.StringBuffergetRequest().getRequestWrapper
.........................
Parameters:
Returns: jrun.servlet.ForwardRequestgetRequest().getRequestedSessionId
.........................
Parameters:
Returns: java.lang.StringgetRequest().getScheme
.........................
Parameters:
Returns: java.lang.StringgetRequest().getServerName
.........................
Parameters:
Returns: java.lang.StringgetRequest().getServerPort
.........................
Parameters:
Returns: intgetRequest().getServletName
.........................
Parameters:
Returns: java.lang.StringgetRequest().getServletPath
.........................
Parameters:
Returns: java.lang.StringgetRequest().getSession
.........................
Parameters:
Returns: javax.servlet.http.HttpSessiongetRequest().getSession
.........................
Parameters: boolean
Returns: javax.servlet.http.HttpSessiongetRequest().getUserPrincipal
.........................
Parameters:
Returns: java.security.PrincipalgetRequest().isRequestedSessionIdFromCookie
.........................
Parameters:
Returns: booleangetRequest().isRequestedSessionIdFromURL
.........................
Parameters:
Returns: booleangetRequest().isRequestedSessionIdFromUrl
.........................
Parameters:
Returns: booleangetRequest().isRequestedSessionIdValid
.........................
Parameters:
Returns: booleangetRequest().isSecure
.........................
Parameters:
Returns: booleangetRequest().isUserInRole
.........................
Parameters: java.lang.String
Returns: booleangetRequest().removeAttribute
.........................
Parameters: java.lang.String
Returns: voidgetRequest().setAttribute
.........................
Parameters: java.lang.String, java.lang.Object
Returns: voidgetRequest().setCharacterEncoding
.........................
Parameters: java.lang.String
Returns: voidgetRequest().setRequest
.........................
Parameters: javax.servlet.ServletRequest
Returns: voidgetRequest().setRequestWrapper
.........................
Parameters: jrun.servlet.ForwardRequest
Returns: voidgetRequest().setServletName
.........................
Parameters: java.lang.String
Returns: void
getResponse
The current value of the response object (a ServletResponse). (source). javax.servlet.ServletResponse extends coldfusion.jsp.JspWriterIncludeResponse extends coldfusion.jsp.HttpServletResponseWrapper extends coldfusion.jsp.ServletResponseWrapper
.........................
Parameters:
Returns: javax.servlet.ServletResponsegetResponse().addCookie
Adds a cookie to the reponse. The cookie value will not show up in ColdFusion's COOKIE scope until the next page refresh (when the browser will send that cookie in the next request).
Parameters: javax.servlet.http.Cookie
Returns: voidgetResponse().addDateHeader
Adds a response header with the given name and date-value. Not exactly sure what this means. This allows the response header to have multiple values. They will become a list of the sent in values.
Parameters: java.lang.String, long
Returns: voidgetResponse().addHeader
Adds a response header with the given name and value. This allows the response header to have multiple values. They will become a list of the sent in values.
Parameters: java.lang.String, java.lang.String
Returns: voidgetResponse().addIntHeader
Adds a response header with the given name and integer value. Not really sure what this does. This allows the response header to have multiple values. They will become a list of the sent in values.
Parameters: java.lang.String, int
Returns: voidgetResponse().containsHeader
Returns a boolean indicating whether the named response header has already been set.
Parameters: java.lang.String
Returns: booleangetResponse().encodeRedirectURL
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method. (source)
Parameters: java.lang.String
Returns: java.lang.StringgetResponse().encodeRedirectUrl
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method. (source)
Parameters: java.lang.String
Returns: java.lang.StringgetResponse().encodeURL
Encodes the given URL if encoding is needed. (source)
Parameters: java.lang.String
Returns: java.lang.StringgetResponse().encodeUrl
Encodes the given URL if encoding is needed. (source)
Parameters: java.lang.String
Returns: java.lang.StringgetResponse().flushBuffer
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
Parameters:
Returns: voidgetResponse().getBufferSize
Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.
Parameters:
Returns: intgetResponse().getCharacterEncoding
Returns the name of the charset used for the MIME body sent in this response.
Parameters:
Returns: java.lang.StringgetResponse().getLocale
Returns the locale assigned to the response. If no locale has been set (such as with SetLocale()) then it returns null.
Parameters:
Returns: java.util.LocalegetResponse().getOutputStream
Returns a ServletOutputStream suitable for writing binary data in the response.
Parameters:
Returns: javax.servlet.ServletOutputStreamgetResponse().getResponse
Return the wrapped ServletResponse object. I am not really sure how this differs from the wrapping response object in terms of functionality. (source)
Parameters:
Returns: javax.servlet.ServletResponsegetResponse().getWriter
Returns a PrintWriter object that can send character text to the client. This can write character data to the buffer unline GetOutputStream() which can only take binary data.
Parameters:
Returns: java.io.PrintWritergetResponse().isCommitted
Returns a boolean indicating if the response has been committed (as in, has anything been flushed to the client yet including header values).
Parameters:
Returns: booleangetResponse().reset
Clears any data that exists in the buffer as well as the status code and headers. I could not actually get this to work. It didn't seem to reset the buffer even when nothing had yet been flushed. (source)
Parameters:
Returns: voidgetResponse().resetBuffer
Clears the content of the underlying buffer in the response without clearing headers or status code. I could not get this one to work. (source)
Parameters:
Returns: voidgetResponse().sendError
Sends an error response to the client using the specified status code and clearing the buffer. The name of the error gets sent as "Unknown." (source)
Parameters: int
Returns: voidgetResponse().sendError
Sends an error response to the client using the specified status code and status message and clearing the buffer. This seemed to pass the value, but I don't know what meaning it has. (source)
Parameters: int, java.lang.String
Returns: voidgetResponse().sendRedirect
Sends a temporary redirect response to the client using the specified redirect location URL. This will act just like the CFLocation tag.
Parameters: java.lang.String
Returns: voidgetResponse().setBufferSize
Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. I did not bother messing with this.
Parameters: int
Returns: voidgetResponse().setContentLength
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header. If you set it too small, the content will be cut off. If you set it too big, the browser will keep waiting for more content to come.
Parameters: int
Returns: voidgetResponse().setContentType
Sets the content type of the response being sent to the client. If obtaining a PrintWriter, this method should be called first. This works like the CFCotent tag / type variable.
Parameters: java.lang.String
Returns:getResponse().setDateHeader
Sets a response header with the given name and date-value. I did not bother messing with this.
Parameters: java.lang.String, long
Returns: voidgetResponse().setHeader
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.
Parameters: java.lang.String, java.lang.String
Returns: voidgetResponse().setIntHeader
Sets a response header with the given name and integer value. If the header had already been set, the new value overwrites the previous one.
Parameters: java.lang.String, int
Returns: voidgetResponse().setLocale
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. I did not bother messing with this one. (source)
Parameters: java.util.Locale
Returns: voidgetResponse().setResponse
Sets the response being wrapped. I did not figure out how to mess with this one (nor did I try very hard). (source)
Parameters: javax.servlet.ServletResponse
Returns: voidgetResponse().setStatus
Sets the status code for this response. This method is used to set the return status code when there is no error
Parameters: int
Returns: voidgetResponse().setStatus
Sets the status code for this response. This method is used to set the return status code when there is no error
Parameters: int, java.lang.String
Returns: void
getServletConfig
Returns the ServletConfig instance. (source).
Parameters:
Returns: javax.servlet.ServletConfiggetServletContext
Returns the ServletContext instance. (source).
Parameters:
Returns: javax.servlet.ServletContextgetSession
Returns the current value of the session object (an HttpSession). (source). I could not get this to work.
Parameters:
Returns: javax.servlet.http.HttpSessiongetSuperScope
I didn't bother messing with this.
Parameters:
Returns: coldfusion.runtime.LocalScopegetTagHandlerInstance
Not sure what this does.
Parameters: java.lang.Class
Returns: java.lang.ObjectgetTagHandlerInstance
Not sure what this does.
Parameters: java.lang.Class, int
Returns: java.lang.ObjectgetVariableScope
Returns the page's VARIABLES scope. Not exactly sure what this is doing. I assume this changed from CFC to page scope.
Parameters:
Returns: coldfusion.runtime.VariableScopehandlePageException
This method is intended to process an unhandled "page" level exception by redirecting the exception to either the specified error page for this JSP, or if none was specified, to perform some implementation dependent action. (source) I could not figure out how to use this.
Parameters: java.lang.Exception
Returns: voidhandlePageException
This method is identical to the handlePageException(Exception), except that it accepts a Throwable. This is the preferred method to use as it allows proper implementation of the errorpage semantics. (source) I could not figure out how to use this.
Parameters: java.lang.Throwable
Returns: voidhashCode
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. (source)
Parameters:
Returns: intinclude
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. The output of the target resources processing of the request is written directly to the ServletResponse output stream. (source). Not exactly sure what this does. It appears to include a NEW page request. Cannot get it to stop having 500 NULL error.
Parameters: java.lang.String
Returns: void[[cfset GetPageContext().include( "./test.cfm" ) /]]
initialize
I did NOT want to mess with this one. The initialize method is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response within it's _jspService() method. (source).
Parameters: javax.servlet.Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String, boolean, int, boolean
Returns: voidinitializeForMultiThread
I did NOT want to mess with this one.
Parameters: java.lang.Object, javax.servlet.jsp.PageContext, coldfusion.runtime.VariableScope
Returns: voidinitializeWith
I did NOT want to mess with this one.
Parameters: java.lang.Object, javax.servlet.jsp.PageContext, coldfusion.runtime.VariableScope
Returns: voidinitializeWith
I did NOT want to mess with this one.
Parameters: javax.servlet.jsp.PageContext
Returns: voidinitializeWith
I did NOT want to mess with this one.
Parameters: javax.servlet.jsp.PageContext, boolean
Returns:notify
Keep getting this CF error "current thread not owner null". Wakes up a single thread that is waiting on this object's monitor. (source)
Parameters:
Returns: voidnotifyAll
Keep getting this CF error "current thread not owner null". Wakes up all threads that are waiting on this object's monitor. (source)
Parameters:
Returns: voidpopBody
I did NOT want to mess with this one. Return the previous JspWriter "out" saved by the matching pushBody(), and update the value of the "out" attribute in the page scope attribute namespace of the PageConxtext. (source).
Parameters:
Returns: javax.servlet.jsp.JspWriterpopFunctionLocalScope
I could not figure how to use this one. I assume this is how ColdFusion handles function scope chaining.
Parameters:
Returns: voidpopQueryScope
I could not figure how to use this one. I assume this is how ColdFusion handles nested query loops.
Parameters:
Returns: voidpopSuperScope
I could not figure how to use this one. I assume this is how ColdFusion handles nested CFC constructors.
Parameters:
Returns: voidpopWSManagementSetting
I did NOT want to mess with this one.
Parameters:
Returns: voidpropagateDefaultQueryScope
I could not figure how to use this one.
Parameters: coldfusion.runtime.NeoPageContext
Returns: voidpushBody
Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext. (source).
Parameters:
Returns: javax.servlet.jsp.tagext.BodyContentpushNewFunctionLocalScope
I did not want to mess with this one. I assume this is how ColdFusion handles local scope chains.
Parameters:
Returns: coldfusion.runtime.LocalScopepushNewFunctionLocalScope
I did not want to mess with this one. I assume this is how ColdFusion handles local scope chains.
Parameters: coldfusion.runtime.LocalScope
Returns: voidpushQueryScope
I did not want to mess with this one. I assume this is how ColdFusion handles nexted query loops.
Parameters: coldfusion.sql.QueryTable
Returns: voidpushSuperScope
I did not want to mess with this one. I assume this is how ColdFusion handles construtor scope chains (CFC extension).
Parameters: coldfusion.runtime.Scope
Returns: voidpushWSManagementSetting
No idea what this does.
Parameters: java.lang.Boolean
Returns: voidrelease
This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize(). (source). I could not figure out how to use this.
Parameters:
Returns: voidremoveAttribute
Removes the given variable from the page scope. I am not sure which scopes it is searched. Definitely VARIABLES. Not sure what else.
Parameters: java.lang.String
Returns: voidremoveAttribute
Removes the given variable from the given scope. Cannot get this one to work. The scope constants are undefined in the page context.
Parameters: java.lang.String, int
Returns: voidresetLocalScopes
I did not want to mess with this one.
Parameters:
Returns: voidsearchScopes
Could not figure how to use this.
Parameters: coldfusion.runtime.ScopeSearchResult
Returns: booleansetArrayAttribute
Sets the given array (param 2) to a variable of the given name (param 1). Not sure how this is different from SymTab_setSimpleName() or setAttribute().
Parameters: java.lang.String, java.lang.Object
Returns: void[[cfset GetPageContext().setArrayAttribute( "REQUEST.Nicole", "busty" ) /]]
##REQUEST.Nicole##Outputs: busty
setAttribute
Sets the given value (param 2) to a variable of the given name (param 1). Not sure how this is different from SymTab_setSimpleName() or setArrayAttribute().
Parameters: java.lang.String, java.lang.Object
Returns: void[[cfset GetPageContext().setAttribute( "REQUEST.Nicole", "very naughty" ) /]]
##REQUEST.Nicole##Outputs: very naughty
setAttribute
Sets the given value (param 2) to a variable of the given name (param 1) within the given scope (param 3). Could not get this to work in any predictable way.
Parameters: java.lang.String, java.lang.Object, int
Returns:setFlushOutput
Turns on (true) and off (false) the flushing of content to the client. If you set it to false, no more content will be flushed, however, actions will continue to be processed and an internal buffer is still be created.
Parameters: boolean
Returns:setImplicitCFScopes
Set the ColdFusion scopes that are automatically searched when scope-less variables are referenced. This seems to be the same as setBuiltinCFScopes().
Parameters: java.util.Vector
Returns: void[[cfset REQUEST.Kim = "silly" /]]
##Kim##Outputs: [CFERROR: UNDEFINED VARIABLE]
[[cfset REQUEST.Kim = "silly" /]]
[[cfset arrScopes = ArrayNew( 1 ) /]] [[cfset ArrayAppend( arrScopes, REQUEST ) /]] [[cfset GetPageContext().setImplicitCFScopes( arrScopes ) /]] ##Kim##Outputs: silly
setVariableScope
Set the VARIABLES scope for the page. Not sure exactly what this is doing; I assume it is how the VARIABLES scope is changed from CFC to page.
Parameters: coldfusion.runtime.VariableScope
Returns: voidtoString
Returns a string representation of the object. (source).
Parameters:
Returns: java.lang.Stringwait
I did not want to mess with this one.
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. (source).
Parameters:
Returns: voidwait
Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. (source). When I try to invoke this, I get a CF Error "current thread not owner".
Parameters: long
Returns: voidwait
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. (source). When I try to invoke this, I get a CF Error "current thread not owner".
Parameters: long, int
Returns: void
Reader Comments
Ben,
Congrats for making that HUGE list. This is some interesting information. Have you thought up any interesting tricks using the above functions, or was this an exercise in seeing how CF is put together?
DW
Awesome list Ben! Here's one you can add:
""
getCFOutput().getDisableCount
Not sure what this is supposed to do.
""
This method is used for handling <cfsetting enablecfoutputonly="true">.
Whenever you use this tag the Output Disable Count increases by one, doing <cfsetting enablecfoutputonly="false"> decreases it by one.
This is used when the server tries to figure out if content outside a cfoutput should be output to the page. Output only happens outside a cfoutput if the Disable Count is 0.
This is actually very useful if you're trying to figure out why content isn't being output, and you want to search for that enablecfoutputonly="true" that has no matching enablecfoutputonly="false" :)
For an example see:
This behavior is also mentioned in the docs:
http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-pc6.htm
""
If you nest cfsetting tags: to make HTML output visible, you must match each enableCFoutputOnly = "Yes" statement with an enableCFoutputOnly = "No" statement. For example, after five enableCFoutputOnly = "Yes" statements, to enable HTML output, you must have five corresponding enableCFoutputOnly = "No" statements.
""
(This is because the disable count must return to 0 for output outside cfoutput to work.)
""
If HTML output is enabled (no matter how many enableCFoutputOnly = "No" statements have been processed) the first enableCFoutputOnly = "Yes" statement blocks output.
""
(This is because you're just going from 0 to 1)
Excellent work Ben.
I'm bookmarking this one.
Cheers.
--
Adam
@Dan,
I did this cause GetPageContext() is not really documented very well anywhere and I really wanted to learn a little about, see if there is some cool stuff under here. A lot of the Java stuff is a little hard for me to wrap my head around. Like, I don't really understand what a Servlet is and things of that nature.
As far as cool stuff - there is some interesting things. The different buffers you can have access to - the character buffer and the binary buffer. Of course, that sort of stuff is nicely packaged by ColdFusion so you don't have to see it (ex. CFContent / VARIABLE attribute will write to the binary buffer (I assume)).
The things I like most:
getFusionContext().getStartTime
- Gets the date/time the page started processing
getResponse().isCommitted
- Determines if the headers have been flushed. I think Ray Camden uses that in his ColdFire code.
SymTab_setBuiltinCFScopes
- You can add scopes to the vactor of scops that ColdFusion will search for variable names. I would not suggest messing with it, but it's cool to see how that can be controlled.
@Elliot,
Thanks for the tip. I tried looking into it, but I had no idea what it was doing. I will update my post. I can see how something like that could be very useful, especially with something like my ColdFusion custom tag for CFSetting ( http://bennadel.com/index.cfm?dax=blog:297.view ).
@Adam,
Thanks. I hope to keep expanding on it as there are many parts of not looked at yet.
Damn! Enough said.
Hi Ben,
Thanks for posting this list! I did not find what I was looking for though, which is: the methods that have to do with setting the cfhtmlhead's text into the output.
Did you perhaps find anything in getPageContext() that has to do with <cfhtmlhead> ?
The actual answer I'm searching for, is: how can the contents which are set with <cfhtmlhead> be reset / removed / suppressed?
Thanks anyway for the exploration. "I learned something today..." :)
@Paul,
While I am not exactly sure how the CFHtmlHead tag works, my guess is that it is just replacing the HTML </head> with [content]</head> in the current content buffer. Remember, the HTML really has nothing to do with ColdFusion, so it's not there are any special hooks that ColdFusion is using. The best it can really do is look at the content that has not yet been flushed to the screen.
When you say you want to suppress it or remove it, I am not sure what you mean. The CFHtmlHead content must be put in explicitly. If you don't want to use it, then just don't put it in your code.
If you tell me a bit more about your situation, maybe I can help you come up with a better solution.
Hi Ben, thanks for your answer.
cfhtmlhead does not work the way you guessed in your answer.
If you create a cfm page with these 3 lines:
output 1<br />
<cfhtmlhead text="output 2 (with cfhtmlhead)<br />" />
output 3<br />
and then output it, you will see the second line (written with cfhtmlhead) is on top.
This is because CF checks, just before flushing the contents to the user, if a <head> tag exists, and if so, put the text inside the <head>. otherwise, the text will be placed at the beginning of the file.
CF does not check the existence of the <head> tag while the <cfhtmlhead> tag is executing, but only at the _end_ of the request (or while the first cfflush is done).
This can be tested by adding a 4th line to the test cfm page:
<head></head>
You will see the cfhtmlhead text will now be at the bottom of the output, because it is put inside the <head> section.
Okay, enough testing.
Because coldfusion saves up the cfhtmlhead text value untill the first output is sent to the browser, I figured there must be a way to get to that stored text. And more important, to manipulate that text.
A normal <cfcontent reset="yes" /> does not get rid of the text, nor does a clearBuffer() etc.
My reason for wanting to know is pure CF enthousiasm; off course we can write a cfif around the cfhtmlhead tag, but I would just like to find out how it is done. And I'm working with 4 other cf enthousiasts who also don't know the answer to this, so it's even a bigger challenge to find out :)
I stilll think it should be somewhere inside the getPageContext() env., but haven't found it.
Interesting. I see what you are saying now. Yeah, it must be held in some separate buffer because I think you can call CFHtmlHead several times before the flush and the result is the aggregate of the various calls.
I can't say that I know how to clear that buffer or even read it, off hand. GetPageContext() is so freakin' huge! I will let you know if I come across anything.
Paul is right, it's buffered and then appended when the content is flushed to the client. If a <head> exists it's added to that, else it just ends up appended to the beginning of the buffer.
Unfortunately there is no real API for doing what you want, even in the internals of the CF engine. I guess they just didn't think we'd need to clear or get the head content? However, using reflection we can do everything you're looking to do.
I put together a simple API: http://enfinitystudios.thaposse.net/personal/coldfusion/cfhtmlhead-api.cfm
Enjoy. :)
Elliott, wow, I'm impressed!
The function resetCfHtmlHead() is exactly what I was looking for! And I mean exactly!
Are you using these functions in dev environment, or did you just create them as an example for your post?
And especially, how did you know where to look, within the getPageContext()? Decompiled CF ;-) ? Or working at Adobe perhaps?
Anyway, thanks for the script, I really appreciate it!
btw: tested it on CF 8,0,0,165965 (beta 2), and works like a charm.
@Paul
It's not that easy to look into most Objects MetaData using the <cfdump...> Tag.
For example, you could dump the PageContext's MetaData:
<cfset pc = GetPageContext()>
<cfdump var="#pc#">
You can dump almost everything, but of course it will still remain basic meta data. You can guess what it actually does, and of course, call it and try it out.
@Thomas
Some of the mentioned functions (in the cfc) are not exposed by dumping them, they are typed as private.
Therefore I was wondering how Elliott found out about the function initHeaderBuffer(), and the field 'headerBuffer' etc.
DJ Java Decompiler FTW!
http://members.fortunecity.com/neshkov/dj.html
I used this neat program to find bugs, or actually work arounds of known bugs in ColdFusion.
There is also the rather useful ClassViewer.class floating around (well actually I've only eveer seen the .java file on the web, but it amounts to the same thing).
If passed an object, it will use reflection to output all the object's member variables, methods, expected arguments (and types), and return types, as text. Quite a bit easier to understand than a decomp-ed Java class.
I spent 5min googling for it and drew a blank... if anyone wants the source code and cannot find it, drop me a line at adam_junk@hotmail.com, and I'll flick it to you.
--
Adam
@Elliot,
That's pretty nifty. I wish I understood the getCFHtmlHeadContent() method a bit better, but at that point, I think I just need to learn some Java goodness.
@Adam,
Yeah, some guy at my office was using some cool program to decompile Java files. I will talk to him next week see if he can remember what it was.
@Ben
The field headerBuffer is where writeHeader() is appending when you call that method, which is really all <cfhtmlhead> does.
The field is declared as:
private CharArrayWriter headerBuffer;
in the class and it looks like CF lazy allocates that writer so it'll be null if you haven't called <cfhtmlhead> yet.
So the first thing I do is get a reference to the Field object that represents all "headerBuffer" fields (member variables) for NeoJspWriter objects.
Now we have a problem, the field is private so trying to use it directly will throw an access exception. Like calling a private function in CF on an instance of a component. So we setAccesible(true) so we can access it.
Now we can use the get( instance ) function on the Field object to get the private field.
Now we have another problem. If we haven't called <cfhtmlhead> yet we'd get an error when we try to return because the get() returned null. To work around this we can use isDefined() which effectively is a shortcut to check if a variable evaluates to null.
That allows us to get the field and then return an empty string if it's null. If it's not null then we have a CharArrayWriter that has the cfhtmlhead content in it. To make that useful in ColdFusion we call toString() on it which turns the array into a string (much like a StringBuffer).
And there you go! You can do some pretty wicked stuff with CF if you get down and dirty with the Java reflection API.
You might also want to see:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Field.html
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Method.html
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html
On an interesting note today I figured out how to replicate the <cfdbinfo type="tables"> call in CF6 and CF7 using similar inspection techniques. I've also got adding mappings and custom tag paths worked out.
I'll blog about that soon and then people without the resources to upgrade to CF8 can realize many of the same benefits. Even more important using this technique we should be able to write frameworks that work with both CF8, CF7 and CF6 and still get the benefits of things like cfdbinfo!
ColdFusion rocks. I wish more people could see that. :)
@Paul
Nope, I work for TeraTech, not Adobe. ;) Figuring out how CF works internally isn't terribly hard though. While you could decompile the classes, you can just use the java reflection API to learn a whole lot about what's really going on inside the engine.
I figured it out by deduction. If you were going to hold data to be output into the output buffer in a specific place (in the <head>) you'd want to store that data somewhere in the output buffer so when it was flushed it would get added. I know the NeoPageContext#flush() method is what is called when you do a cfflush, so that's where I started looking.
So I looked at getPageContext().getOut() and saw there was a writeHeader() method that took a string. So I tested that and found it was the same as cfhtmlhead.
The next step was looking for an API to get to whatever that thing changed. Unfortunately there isn't one so I looked at getDeclaredFields() to check the instance members. Fortunately there was one nicely named headerBuffer, so I checked the contents of that after I used writeHeader() and sure enough that's where the data was.
Next I played around with it and realized that I'd get a nasty null error if I hadn't called cfhtmlhead or writeHeader() when I tried to get the buffer so I knew I needed to add the null check to it.
I've not really tested that in a production environment, it was just a proof of concept I put together when I saw your comment. I can't imagine it should cause you any major problems though.
There is one side effect that I have noticed though. If you cfflush the output and then call cfhtmlhead you normally get an exception, even if the <head> hasn't been output yet. However, after you call resetCFHtmlHead() in my api you can cfhtmlhead again and not get an exception.
The writeCFHtmlHead() function also *never* throws an exception, even if a flush has already happened. It just fails silently. This seems to imply that the error that is usually thrown is from inside the coldfusion.tagext.html.HtmlHeadTag and not in the NeoJspWriter#writeHeader() function.
I guess these are kind of a features, right? :)
I tested it with CF8. And it seems that it didn't work anymore. The getCFHtmlHeadContent() of the API return an error on out.getClass().getDeclaredField("headerBuffer")
After a look around the headerBuffer doesn't exist in getDeclaredFields.
I used "appendHeaderBuffer" instead.
Nice team work Ben and Elliott.
I was interested in utilizing getCFHtmlHeadContent using cf8 on IIS.
Neither out.getClass().getDeclaredField("headerBuffer") or out.getClass().getDeclaredField("appendHeaderBuffer") did the trick.
But getPageContext().getOut().getString() did return the current buffer, both head and body.
Pretty handy.
I did find that getPageContext() needs to be used outside cfsilent tags. ie. </cfsilent><cfset parentFile=#getPageContext().getOut().getString()><cfsilent>
So I was able to search the head for my script before (re)appending it include_once style.
I suppose you could add a substring to the request and find everything between the head tags returning just the head content.
JD-GUI 0.2.7 > DJ Java Decompiler
http://java.decompiler.free.fr/
You can pass in the entire cfusion.jar file and have a poke around.
FTW!
Great stuff re the CFHtmlHead stuff. getPageContext().getOut().getString() did what I wanted (which was to get all content including any htmlhead stuff).
Thanks
I lie. getPageContext().getOut().getString() didn't return me anything :(
Elliot's api is no longer web accessible - any one have a copy?
Wow. This is taking me back to the days of yore. Programming in machine or assembly language. Controlling each buffer. Makes my brain hurt again. I don't know enough java to know how to do some of this stuff. Maybe I need to learn Java.
So let's get down and dirty. What can I do with some of this stuff? Anybody come up with a use for it on a web app?
@Don,
It is useful when you need to get at things in the page that are not readily available. These are usually outside cases. The biggest one that I use is: getResponse().isCommitted(). I'll use this to see if I can perform a CFLocation or whether or not I need to abort (usually in the OnError() event handler).
Other than that though, I rarely go into the page context.
Thanks again Ben, one of your blog posts has come up trumps again! :)
I had several old applications and wanted to save a chunk of bandwidth on them. After using a little information from here I came up with an onrequestend (.cfm in this case) that hashes the buffer Hash(GetPageContext().getCFOutput().getBuffer().toString()) and adds the hash a header called ETag. If the hash matches the cgi.HTTP_IF_NONE_MATCH sent by the browser, I wipe the buffer and send a 304 status code "Not modified".
I owe you a beer for digging that function up for me :)
@David,
Oh that's a cool concept! Very interesting.
I've just blogged about the idea in case you're really interested. Slowly expanding it's usage on my applications as well and it's looking good.
@David,
I'll have to check it out.
@ben
Great work!
Provides another option to intercepting the message body. (In addition to cfsavecontent.)
page.cfm
<div>foo</div>
application.cfc (cfsavecontent)
<cfcomponent>
<cffunction name="onRequest"><
cfset var temp={}/><
cfsilent>
<cfsavecontent variable="temp.original"><cfinclude template="#arguments[1]#"/></cfsavecontent>
<cfset temp.new=temp.original/>
<cfset temp.new=trim(temp.new)/>
<cfset temp.new=reReplace(temp.new, "foo", "boo", "all")/>
</cfsilent
><cfoutput>#toString(temp.new)#</cfoutput><
/cffunction>
</cfcomponent>
application.cfc (getPageContext)
<cfcomponent>
<cffunction name="onRequest"><
cfset var temp={}/><
cfinclude template="#arguments[1]#"/><
cfsilent>
<cfset temp.original=getPageContext().getOut().getBuffer().toString()/>
<cfset temp.new=temp.original/>
<cfset temp.new=reReplace(temp.new, "foo", "boo", "all")/>
<cfcontent reset="true"/>
</cfsilent
><cfoutput>#toString(temp.new)#</cfoutput><
/cffunction>
</cfcomponent>
output
<div>boo</div>
Alex, why are you setting temp.new to temp.original? I can see this if you are going to compare the 2 at some point, and maybe you do, but otherwise it is a wasted step that doubles the storage needed because now you have 2 variables with the same content. Of course I'm not sure I understand why you are putting all this in the Application.cfc in the first place. Please explain this in simple words of less than 1 syllable. :) (It's Friday and my brain is already on the weekend)
@don,
> why are you setting temp.new to temp.original?
Just to demonstrate the replacement.
You're right. Leaving the original string is not a good idea for performance.
> why you are putting all this in the Application.cfc in the first place
To do some fancy post-processing on the body content.
- Add some XSRF/CSRF token to all link/form URIs.
- Clean up whitespace (intelligently).
- Resolve relative URIS. (For SEO or other.)
- Add header, footer.
Hi,
I actually found this post useful. I recently acquired a SSL certificate for my website and when I switched over to HTTPS Internet Explorer would throw an error when trying to download a dynamically generated xls/csv report. I tracked down the issue to a microsoft support page here http://support.microsoft.com/kb/812935/ that explains it.
Essentially the issue was some stuff in the HTTP Headers that was automatically generated by <cfcontent> was causing the issue. The two possible solutions (proposed to me by Raymond Camden) was to scrap <cfcontent> all together and specify all the headers myself using <cfheader> or use the getPageContext() object to overwrite the existing HTTP header. I figured the latter was a better solution because the former would require me to add headers for all the defaults <cfcontent> created but I was only interested in replacing a small portion of them.
Thanks to your post I was able to make sense of getPageContext() and found the proper method for overwriting the existing headers.
I found by adding the following two lines after <cfcontent> call I was able to correct the issue (works in IE7 & IE8 for sure)
<cfset getPageContext().getResponse().setHeader("Cache-control","must-revalidate, post-check=0, pre-check=0")>
<cfset getPageContext().getResponse().setHeader("Pragma","public")>
Thanks,
Asaf
@Asaf,
Ah very interesting. I was not aware of that bug with IE. Thanks for pointing out the solution.
anyone know how you can get the same data as getParameterMap() returns only for a multipart form post? james and i have been hunting around and need to get this for something we're working on in cfwheels.
@Tony,
Are you talking about processing a FORM file post without using CFFile?
Oooo! I've been after file information without using cffile for ages. It's on my list to pester Adobe for in the next release.
I know that CF8 handles uploads slightly differently and to help improve memory usage it doesn't hold the full POST request body in memory anymore (it's there in CF7).
What bugs me is that deep down somewhere in GetPageContext() or another hidden place, CF knows the real uploaded filename. I just wish it'd tell us without having to do a cffile(action=upload) which actually just moves and renames the uploaded file.
Never found out where this secret is kept... yet ;)
GetPageContext().getFusionContext().getPagePath()
Can be used in a CFC function to get the name of the file that defines the cfc. Not the same as GetBaseTemplatePath() which returns the page that spawned the request.
I'm still searching for the name of the currently executing function, for a custom error logging mechanism.
I can't believe with all the reflection stuff in CF that there isn't an easy way to get the name of the function that is executing. CF devs: this._currentFunction would be really handy!!!!
Sean
Oh yeah, here's what's sad: There is this gem:
GetPageContext().getFusionContext().methodCalledName
but it's a private property and there is no getter function. ARRRGGGHHHHH!!!!!!
Sean
@Sean
You don't need to use GetPageContext().getFusionContext().getPagePath(), just use GetCurrentTemplatePath() instead (which really just calls getPagePath() anyway).
As for the methodCalledName private property, use GetFunctionCalledName() which was added in CF9. The methodCalledName property was added to allow this new function.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS7cc222be8a31a47d-6e8b7083122cebfc8f2-8000.html
GetCurrentTemplatePath always returns my front controller (index.cfm) and never the file that defines the cfc.
Glad to hear cf9 has what I'm looking for. Thanks Ben!
Sean
Oops. Didn't notice the difference between GetBaseTemplatePath and GetCurrentTemplatePath. I'll check that out. Thanks.
@David,
Call me crazy, but I think the form field should hold the name of the TMP file path that has been uploaded (before you move/rename via CFFile/upload). That said, I have heard a number of people talk about getting more access to the file data in the latest versions of ColdFusion.
@Sean,
If you want, I have a whole post on general path usage overviews in ColdFusion. There is *some* unexpected behavior, but for the most part, this works:
http://www.bennadel.com/blog/597-ColdFusion-Path-Usage-And-Manipulation-Overview.htm
@Ben, your crazy ;)
No, you're right, the form field does hold the name of the TMP file path. But it's with the temporary file name as well, ending in .tmp. This is handy for checking the size of the uploaded file without touching cffile(action=upload) but not the file type itself. Somewhere it's being kept secret from us.
@David,
Ah, I see; I misunderstood what you meant before. I thought you must wanted to know where the file was, not what the file actually was named (or what type it was)... which, of course, makes perfect sense in retrospect :)
Hey Ben, just wanted to throw this out there:
##CFScript##
myURL = "http://www.example.com/";
getPageContext().getResponse().sendRedirect(myURL);
##/CFScript##
can do some funky things if you don't use the encodeRedirectURL() method on your URL you want to redirect to.
In my particular case, I had a CF page with a form that sends the user to a SQL Server Reporting Services report with params based on user input, set to render as a PDF. Just using sendRedirect() alone caused the browser to interpret the PDF stream as html/text, so it would output gibberish. Doing the following fixed the problem (the browser prompted for a file download, rather than output the PDF stream to the browser):
##CFScript##
myURL = getPageContext().getResponse().encodeRedirectURL("http://www.example.com/");
getPageContext().getResponse().sendRedirect(myURL);
##/CFScript##
Cheers.
@Graeme,
Very interesting stuff. I haven't made too much use of the page context in a while. May I ask why you are using this sendRedirect() rather than using CFLocation - simply because you are in CFScript?
@Ben,
Pretty much. I started programming web apps with PHP and more recently ASP.NET C#, so ColdFusion's tag based syntax becomes a little difficult to for me to mentally parse, especially when dealing with CF on an HTML page.
To keep from confusing myself I try to stick to CF tags when using CF to generate or modify HTML output and use CFScript when I'm writing code that's not inline with elements that will be rendered on the browser, if that makes sense.
@Graeme,
No worries at all; the good news is, with ColdFusion 9, you can really stick to the script almost all the time (even with CFLocation).
Incredibly useful, when you have comments in Application scope or whatever driving your document into quirks mode:
Just before the <HTML> tag, do this (I've put this in a customtag called "cf_fixheader":
<!--- takes any generated content up to this point and sticks it inside the head! --->
<cfset sofar = getPageContext().getCFOutput().getBuffer()>
<cfhtmlhead text="<!-- GENERATED BEFORE DOCTYPE: -->#sofar#<!-- END GENERATED BEFORE DOCTYPE -->">
<cfset getPageContext().getCFOutput().clearBuffer()>
Hi Ben
I come back to this blog post all the time when I am ferreting around in the page context object. Cheers.
Just a note: getBuiltInScopes() has been removed from getPageContext() as of CF9.
This sux, but... well... there you go.
--
Adam
Also it looks like getCookies() has been removed from the getPageContext().getRequest() request object.
Actually that's wrong. If you just dump out getPageContext().getRequest() it hasn't got a getCookies method. But the method will dump something out if a cookie exists.
Hi Ben
Five years on, and I'm still referring back to this blog post.
Good work, mate.
--
Adam



