Page Blocks

Hosting sponsored by:

Point In Space

 

API: Cnfg

Filename:
fwpCnfg_loadFile.ctag

Released With:
5.0.0

Current Version:
1.2.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpCnfg_loadFile (Tag)

Description

Loads into a variable any of several configuration file types used for the framework. Will automatically search the site /site/configs/ folder and the module's local /_resources/configs/ folder. The tag can be instructed to merge or not merge files if one is found in both folders. Alternately, a full file pathname can be given to load a specific file not in the usual /configs/ folder locations.

The file is loaded without modification. Use some of the other fwpCnfg tags to process the config data. Alternately, use one of the other fwpCnfg_load tags which integrate file loading and parsing of specific config file structures.

Syntax

var|local:varName = fwpCnfg_loadFile: fileName, -nomerge=true;

Parameters & Member Tags

file (unnamed) = required : either a complete filename with extension, or a full pathname. If a file name is specified without any path component, the tag will search the standard /configs/ folders. If a file with a path is specified, the complete virtual host root relative path must be specified, and the tag will load that one specific file.

-withoutMerging = optional : if not specified, the default behavior is to append a file found in /_resources/configs/ folder to the end of a file found in /site/configs/ folder. If -withoutMerging is used, and a file is found in both folders, only the contents of the file from the /_resources/configs/ folder will be loaded. (Previous -nomerge param name is deprecated).

Examples

var:'myCnfgData' = fwpCnfg_loadFile:'custom.cnfg';

var:'myCnfgData' = fwpCnfg_loadFile:'custom.cnfg', -withoutMergng;

var:'myCnfgData' = fwpCnfg_loadFile:'/nonstandard/config/path/custom.cnfg';

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpCnfg_loadFile.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpCnfg_loadFile }
    {rsrcHTTP=        www.pageblocks.org/reference/fwpCnfg_loadFile }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            This tag loads a configuration file }

    {maintvsrn=        1.2.0 }
    {maintrelease=    5.2.0 }
    {maintdate=        2007-06-09 }
    {maintauthor=    Greg Willits }
    {maintnotes=    updated debug and error handling systems,
                     changed some internal vars for better readability }

    {maintvsrn=        1.1.1 }
    {maintrelease=    5.1.4 }
    {maintdate=        2006-11-19 }
    {maintauthor=    Greg Willits }
    {maintnotes=    changed file not found error handling to simply return false }

    {maintvsrn=        1.1 }
    {maintrelease=    5.1.0 }
    {maintdate=        2006-05-26 }
    {maintauthor=    Greg Willits }
    {maintnotes=    converted timers to fwp_timer ctype,
                    add tagTrace }

    {maintvsrn=        1.0.1 }
    {maintrelease=    5.0.3 }
    {maintdate=        2006-05-26 }
    {maintauthor=    Greg Willits }
    {maintnotes=    added removal of leading BOM after file_read }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_tag:'fwpCnfg_loadFile', -priority='replace',
    -required='file',
    -optional='username',
    -optional='password';

//    -withoutMerging (-nomerge deprecated)

    ($fw_debug >= fw_kChatty) ? $fw_tagTracer->(add:'fwpCnfg_loadFile', -file = #file);

    ((var_defined:'fw_timer') && $fw_debugTimers) ? $fw_timer->(start:'cnfgTagLoadFile');

    local:
        'fileName'            = @#file,
        'configData'        = string,
        'configLine'        = string,
        'configPath'        = string,
        'fw_sCnfgPath'        = string,
        'fw_mCnfgPath'        = string,
        'fw_sFilePath'        = string,
        'fw_mFilePath'        = string,
        'fileNotFound'        = false,
        'fileError'            = false,
        'triedToLoad'        = array,
        'withoutMerging'    = true;

//    look for inputs for pageblocks mode or full spec mode
//    username and password for file tags

    if: !(local:'username');
        local:'fw_nm' = $fw_gFilesUser;
        local:'fw_pw' = $fw_gFilesPswd;
    else;
        local:'fw_nm' = @local:'username';
        local:'fw_pw' = @local:'password';
    /if;

//    location and type of config files

    if: (#fileName >> '/');
        //    use supplied file name as complete pathname
        #configPath    = #fileName;
    else;
        //    convert file name to a PB config paths
        #fw_sCnfgPath    = (var:'fw_sPath')->'configs';
        #fw_mCnfgPath    = (var:'fw_mPath')->'configs';
    /if;

//    set behavior for when both global and local files are found

    (params >> '-withoutMerging') || (params >> '-nomerge')
        ? #withoutMerging = false;

//    load the file data

    inline:
        -username = #fw_nm,
        -password = #fw_pw;

        if: #fw_sCnfgPath;
            //    framework files
    
            #fw_sFilePath = #fw_sCnfgPath + #fileName;
            #fw_mFilePath = #fw_mCnfgPath + #fileName;

            if: file_exists: #fw_sFilePath || file_exists: #fw_mFilePath;
                if: (file_exists: #fw_sFilePath);
                    #configData = (file_read:#fw_sFilePath);
                    (file_currentError: -errorCode) != 0 ? #fileError = file_currentError;
                /if;
                if: #withoutMerging && (file_exists: #fw_mFilePath);
                    #configData += (file_read:#fw_mFilePath);
                    (file_currentError: -errorCode) != 0 ? #fileError = file_currentError;
                else: !(#withoutMerging) && (file_exists: #fw_mFilePath);
                    #configData = (file_read:#fw_mFilePath);
                    (file_currentError: -errorCode) != 0 ? #fileError = file_currentError;
                /if;
            else;
                #fileNotFound = true;
                #triedToLoad->(insert: #fw_sFilePath);
                #triedToLoad->(insert: #fw_mFilePath);
            /if;
    
        else;
            //    manually specified files
    
            if: file_exists: #configPath;
                #configData = (file_read: #configPath);
                (file_currentError: -errorCode) != 0 ? #fileError = file_currentError;
            else;
                #fileNotFound = true;
                #triedToLoad->(insert: #configPath);
            /if;
        /if;
        
        #configData->(removeleading:bom_utf8);
        #configData->(removeleading:bom_utf16BE);
        #configData->(removeleading:bom_utf16LE);
        #configData->(removeleading:bom_utf32BE);
        #configData->(removeleading:bom_utf32LE);

    /inline;

    $fw_debugTimers ? $fw_timer->(stop:'cnfgTagLoadFile');

    if: #fileError;
        $fw_error->(insert:'5201'='fwpCnfg_loadFile');
        $fw_debug ? $fw_apiError->(insert:'5203'=#fileName + '```' + #fileError);
        $fw_debug ? $fw_tagTracer->(add:'fwpCnfg_loadFile', -ERROR = 'file error ' + #fileError, -file = #fileName);
        $fw_criticalLog ? log_critical:('pbError : fwpCnfg_loadFile got error reading file ' + #fileName);
        return: string;
    /if;

    if: #fileNotFound;
        $fw_error->(insert:'5201'='fwpCnfg_loadFile');
        $fw_debug ? $fw_apiError->(insert:'5202'=#fileName);
        $fw_debug ? $fw_tagTracer->(add:'fwpCnfg_loadFile', -ERROR = 'file not found or access not allowed. Tried to load: ' + (#triedToLoad->join));
        $fw_criticalLog ? log_critical:('pbError : fwpCnfg_loadFile could not find, or could not access, file ' + #fileName);
        return: string;
    /if;

    return: #configData;

/define_tag;

?>

© 2002-2012, pageblocks.org