component(path [, type])
Last updated May 13, 2003
Version: 1 | Requires: ColdFusion MX | Library: DataManipulationLib
Description:
This UDF will create an instance of a CFC based upon a relative or absolute path or even upon the standard dot notation used in the createObject("component") function.
I tried to make the "type" argument somewhat intelligent and it'll probably work correctly 99% of the time for you, but if you want to be absolutely sure you get the expected behavior, specify the type argument for the function.
Return Values:
Returns a CFC.
Example:
// "normal.dot.notation");
component("normal.dot.notation");
// invoke a component from a sub
// directory off the current web
// directory
component("./sub/directory/com.cfc");
// invoke a component on another drive
component("d:\components\com.cfc", "absolute");
Parameters:
| Name | Description | Required |
|---|---|---|
| path | Path for the component. | Yes |
| type | Type of the path. Possible values are "component" (normal dot notation), "relative" and "absolute". Defaults to component. | No |
Full UDF Source:
<cfscript>
/**
* Creates a CFC instance based upon a relative, absolute or dot notation path.
*
* @param path Path for the component. (Required)
* @param type Type of the path. Possible values are "component" (normal dot notation), "relative" and "absolute". Defaults to component. (Optional)
* @return Returns a CFC.
* @author Dan G. Switzer, II (dswitzer@pengoworks.com)
* @version 1, May 13, 2003
*/
function component(path){
var sPath=Arguments.path;var oProxy="";var oFile="";var sType="";
if( arrayLen(Arguments) gt 1 ) sType = lCase(Arguments[2]);
// determine a default type
if( len(sType) eq 0 ){
if( (sPath DOES NOT CONTAIN ".") OR ((sPath CONTAINS ".") AND (sPath DOES NOT CONTAIN "/") AND (sPath DOES NOT CONTAIN "\")) ) sType = "component";
else sType = "relative";
}
// create the component
switch( left(sType,1) ){
case "c":
return createObject("component", sPath);
break;
default:
if( left(sType, 1) neq "a" ) sPath = expandPath(sPath);
oProxy = createObject("java", "coldfusion.runtime.TemplateProxy");
oFile = createObject("java", "java.io.File");
oFile.init(sPath);
return oProxy.resolveFile(getPageContext(), oFile);
break;
}
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)