(file) Return to MessageLoader.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

File: [Pegasus] / pegasus / src / Pegasus / Common / MessageLoader.h (download)
Revision: 1.25, Tue May 20 17:40:43 2008 UTC (16 years, 1 month ago) by kumpf
Branch: MAIN
CVS Tags: TASK_PEP328_SOLARIS_NEVADA_PORT, TASK-PEP328_SOLARIS_NEVADA_PORT-root, TASK-PEP328_SOLARIS_NEVADA_PORT-branch, TASK-PEP328_SOLARIS_IX86_CC_PORT-root, TASK-PEP328_SOLARIS_IX86_CC_PORT-branch-v2, TASK-PEP328_SOLARIS_IX86_CC_PORT-branch, RELEASE_2_8_2-RC1, RELEASE_2_8_2, RELEASE_2_8_1-RC1, RELEASE_2_8_1, RELEASE_2_8_0_BETA, RELEASE_2_8_0-RC2, RELEASE_2_8_0-RC1, RELEASE_2_8_0-FC, RELEASE_2_8_0, RELEASE_2_8-root, RELEASE_2_8-branch, Makefile
Changes since 1.24: +6 -51 lines
BUG#: 7675
TITLE: Avoid ICU dependency in MessageLoader.h
DESCRIPTION: Encapsulate the inclusion of ICU header files within MessageLoader.cpp.

//%2006////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation, The Open Group.
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; Symantec Corporation; The Open Group.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//==============================================================================
//
//%/////////////////////////////////////////////////////////////////////////////

#ifndef Pegasus_MessageLoader_h
#define Pegasus_MessageLoader_h

#include <cstdlib>
#include <cctype>
#include <Pegasus/Common/Linkage.h>
#include <Pegasus/Common/Config.h>
#include <Pegasus/Common/String.h>
#include <Pegasus/Common/Formatter.h>
#include <Pegasus/Common/AcceptLanguageList.h>
#include <Pegasus/Common/ContentLanguageList.h>

PEGASUS_NAMESPACE_BEGIN

/**
    MessageLoaderParms class is basically a stuct class containing public
    variables that control the way MessageLoader behaves. MessageLoader uses
    the fields in this class to decide where and how to load messages from
    the message resources.
 */
class PEGASUS_COMMON_LINKAGE MessageLoaderParms
{
public:

    /**
        String msg_id: unique message identifier for a particular
        message in a message resource
     */
    String msg_id;

    /**
        String default_msg: the default message to use if a message
        cannot be loaded from a message resource
     */
    String default_msg;

    /**
        String msg_src_path: this path tells MessageLoader where to
        find message resources.
        It can be empty, fully qualified or relative to $PEGASUS_HOME
     */
    String msg_src_path;

    /**
        AcceptLanguageList acceptlanguages: This contains the languages
        that are acceptable by the caller of MessageLoader::getMessage()
        or openMessageFile(). That is, MessageLoader will do its best to
        return a message in a language that was specified in this container.
        This container is naturally ordered using the quality values
        attached to the languages and MessageLoader iterates through this
        container in its natural ordering.  This container is used by
        MessageLoader to load messages if it is not empty.
     */
    AcceptLanguageList acceptlanguages;

    /**
        ContentLanguageList contentlanguages: This is set by
        MessageLoader::getMessage() and after a message has been loaded
        from either a message resource or the default message, or by
        MessageLoader::openMessageFile() after it has identified and
        opened a message resource. After the call to
        MessageLoader::getMessage() or MessageLoader::openMessageFile(),
        the caller can check the MessageLoaderParms.contentlanguages
        object to see what MessageLoader set it to. In all cases where a
        message is returned from MessageLoader::getMessage() or will be
        returned from MessageLoader::getMessage2(), this field will be
        set to match the language that the message was (or will be)
        found in.
     */
    ContentLanguageList contentlanguages;

    /**
        Boolean useProcessLocale: Default is false, if true, MessageLoader
        uses the system default language to loads messages from.
     */
    Boolean useProcessLocale;

    /**
        Boolean useThreadLocale: Default is true, this tells
        MessageLoader to use the AcceptLanguageList container
        from the current Pegasus thread.
     */
    Boolean useThreadLocale;

    /**
        const Formatter::Arg&0-9: These are assigned the various
        substitutions necessary to properly format the message being
        extracted.  MessageLoader substitutes these in the correct
        places in the message being returned from
        MessageLoader::getMessage()
     */
    Formatter::Arg arg0;
    Formatter::Arg arg1;
    Formatter::Arg arg2;
    Formatter::Arg arg3;
    Formatter::Arg arg4;
    Formatter::Arg arg5;
    Formatter::Arg arg6;
    Formatter::Arg arg7;
    Formatter::Arg arg8;
    Formatter::Arg arg9;

    /** Constructor */
    MessageLoaderParms();

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg,
        const Formatter::Arg& arg0,
        const Formatter::Arg& arg1,
        const Formatter::Arg& arg2,
        const Formatter::Arg& arg3,
        const Formatter::Arg& arg4,
        const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
        const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
        const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
        const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
        const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg);

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg,
        const Formatter::Arg& arg0);

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg,
        const Formatter::Arg& arg0,
        const Formatter::Arg& arg1);

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg,
        const Formatter::Arg& arg0,
        const Formatter::Arg& arg1,
        const Formatter::Arg& arg2);

    /** Constructor */
    MessageLoaderParms(
        const String& id,
        const String& msg,
        const Formatter::Arg& arg0,
        const Formatter::Arg& arg1,
        const Formatter::Arg& arg2,
        const Formatter::Arg& arg3);

    MessageLoaderParms(
        const char* id,
        const char* msg);

    MessageLoaderParms(
        const char* id,
        const char* msg,
        const String& arg0);

    MessageLoaderParms(
        const char* id,
        const char* msg,
        const String& arg0,
        const String& arg1);

    /** Converts to string. */
    String toString();

    ~MessageLoaderParms();

private:

    void* _resbundl;

    void _init();

    friend class MessageLoader;
    friend class MessageLoaderICU;
};


/**
    MessageLoader is a static class resposible for looking up messages in
    message resources.
    For specific behaviour details of this class see the Globalization HOWTO.
 */
class PEGASUS_COMMON_LINKAGE MessageLoader
{
public:

    /**
        Retrieves a message from a message resource
        @param parms MessageLoaderParms - controls the behaviour of how a
        message is retrieved
        @return String - the formatted message
     */
    static String getMessage(MessageLoaderParms& parms);

    /**
        Opens a message resource bundle.  If unsuccessful, a subsequent call
        to getMessage2() with the specified MessageLoaderParms object will
        result in the default message being formatted.
        ATTN: Do we want *real* error codes for this?
        @param parms MessageLoaderParms - controls the behaviour of how a
            message is retrieved, this parameter should be used *ONLY* on
            subsequent calls to getMessage2() and closeMessageFile().
     */
    static void openMessageFile(MessageLoaderParms& parms);

    /**
        Closes a message resource bundle.
        @param parms MessageLoaderParms - identifies a previously opened
            resource bundle returned from openMessageFile().
     */
    static void closeMessageFile(MessageLoaderParms& parms);

    /**
        Retrieves a message from a message resource previously opened by
        openMessageFile()
        @param parms MessageLoaderParms - controls the behaviour of how a
            message is retrieved, and is the same MessageLoaderParms
            parameter that was passed to openMessageFile().
        @return String - the formatted message
     */
    static String getMessage2(MessageLoaderParms& parms);

    static void setPegasusMsgHome(String home);

    static void setPegasusMsgHomeRelative(const String& argv0);

    static String getQualifiedMsgPath(const String& path);

    static Boolean _useProcessLocale;

    static Boolean _useDefaultMsg;

    static AcceptLanguageList _acceptlanguages;

private:

    static String formatDefaultMessage(MessageLoaderParms& parms);

    static void initPegasusMsgHome(const String& startDir);

    static void checkDefaultMsgLoading();

    static String pegasus_MSG_HOME;
};

PEGASUS_NAMESPACE_END

#endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2