⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indicationformatter.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            Boolean canLocalize = false;#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)            Locale locale;            canLocalize = _canLocalize(contentLangs, locale);#endif            // Empty brackets (e.g. []), gets all values of the array            if (sizeOfArrayIndexStr == 0)            {                arrayValues.append("[");                for (Uint32 i=0; i<arraySize; i++)                {#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)                    if (canLocalize)                    {                        arrayValues.append(_localizeBooleanStr(                            booleanValue[i], locale));                    }                    else                    {                        arrayValues.append(_getBooleanStr(booleanValue[i]));                    }#else                    arrayValues.append(_getBooleanStr(booleanValue[i]));#endif                    if ( i < arraySize-1)                    {                        arrayValues.append(",");                    }                }                arrayValues.append("]");            }            else            {#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)                if (canLocalize)                {                    arrayValues = _localizeBooleanStr(                        booleanValue[arrayIndex], locale);                }                else                {                    arrayValues = _getBooleanStr(booleanValue[arrayIndex]);                }#else                arrayValues = _getBooleanStr(booleanValue[arrayIndex]);#endif            }            break;        }        case CIMTYPE_CHAR16:        {            Array<Char16> propertyValueChar16;            propertyValue.get(propertyValueChar16);            // Empty brackets (e.g. []), gets all values of the array            if (sizeOfArrayIndexStr == 0)            {                arrayValues.append("[");                for (Uint32 i=0; i<arraySize; i++)                {                    arrayValues.append(propertyValueChar16[i]);                    if ( i < arraySize-1)                    {                        arrayValues.append(",");                    }                }                arrayValues.append("]");            }            else            {                arrayValues.append(propertyValueChar16[arrayIndex]);            }            break;        }        case CIMTYPE_STRING:        {            Array<String> propertyValueString;            propertyValue.get(propertyValueString);            // Empty brackets (e.g. []), gets all values of the array            if (sizeOfArrayIndexStr == 0)            {                arrayValues.append("[");                for (Uint32 i=0; i<arraySize; i++)                {                    arrayValues.append(propertyValueString[i]);                    if ( i < arraySize-1)                    {                        arrayValues.append(",");                    }                }                arrayValues.append("]");            }            else            {                arrayValues.append(propertyValueString[arrayIndex]);            }            break;        }        case CIMTYPE_DATETIME:        {            Array<CIMDateTime> propertyValueDateTime;            propertyValue.get(propertyValueDateTime);            Boolean canLocalize = false;#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)            Locale locale;            canLocalize = _canLocalize(contentLangs, locale);#endif            // Empty brackets (e.g. []), gets all values of the array            if (sizeOfArrayIndexStr == 0)            {                arrayValues.append("[");                for (Uint32 i=0; i<arraySize; i++)                {#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)                    if (canLocalize)                    {                        arrayValues.append(_localizeDateTime(                            propertyValueDateTime[i], locale));                    }                    else                    {                        arrayValues.append(propertyValueDateTime[i].toString());                    }#else                    arrayValues.append(propertyValueDateTime[i].toString());#endif                    if ( i < arraySize-1)                    {                        arrayValues.append(",");                    }                }                arrayValues.append("]");            }            else            {#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)                if (canLocalize)                {                    arrayValues.append(_localizeDateTime(                        propertyValueDateTime[arrayIndex], locale));                }                else                {                    arrayValues.append(propertyValueDateTime                        [arrayIndex].toString());                }#else                arrayValues.append(propertyValueDateTime                    [arrayIndex].toString());#endif            }            break;        }        case CIMTYPE_REFERENCE:        {            Array<CIMObjectPath> propertyValueRef;            propertyValue.get(propertyValueRef);            // Empty brackets (e.g. []), gets all values of the array            if (sizeOfArrayIndexStr == 0)            {                arrayValues.append("[");                for (Uint32 i=0; i<arraySize; i++)                {                    arrayValues.append(propertyValueRef[i].toString());                    if ( i < arraySize-1)                    {                        arrayValues.append(",");                    }                }                arrayValues.append("]");            }            else            {                arrayValues.append(propertyValueRef                    [arrayIndex].toString());            }            break;        }        default:        {            arrayValues.append("UNKNOWN");            PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,                "Unknown CIMType: " + type);            break;        }    }    PEG_METHOD_EXIT();    return arrayValues;}String IndicationFormatter::_getBooleanStr(    const CIMValue & booleanCIMValue){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_getBooleanStr");    Boolean propertyValueBoolean;    booleanCIMValue.get(propertyValueBoolean);    if (propertyValueBoolean)    {        PEG_METHOD_EXIT();        return "true";    }    else    {        PEG_METHOD_EXIT();        return "false";    }}String IndicationFormatter::_getBooleanStr(    const Boolean & booleanValue){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_getBooleanStr");    if (booleanValue)    {        PEG_METHOD_EXIT();        return "true";    }    else    {        PEG_METHOD_EXIT();        return "false";    }}#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)Boolean IndicationFormatter::_canLocalize(    const ContentLanguageList& contentLangs,    Locale& locale){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_canLocalize");    if (!InitializeICU::initICUSuccessful())    {        return false;    }    // If the Content-Languages has multiple language tag, do not localize    if (contentLangs.size() > 1)    {        // there is more then one language tags        PEG_METHOD_EXIT();        return false;    }    else if (contentLangs.size() == 1)    {        // get the locale        LanguageTag languageTag = contentLangs.getLanguageTag(0);        String language = languageTag.getLanguage();        String country = languageTag.getCountry();        String variant = languageTag.getVariant();        locale = Locale((const char *) language.getCString(),                        (const char *) country.getCString(),                        (const char *) variant.getCString());        // the locale is bogus state        if (locale.isBogus())        {            PEG_METHOD_EXIT();            return false;        }        else        {            PEG_METHOD_EXIT();            return true;        }    }    else    {        locale = Locale::getDefault();        PEG_METHOD_EXIT();        return true;    }}String IndicationFormatter::_localizeDateTime(    const CIMDateTime& propertyValueDateTime,    const Locale& locale){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_localizeDateTime");    // Convert dateTimeValue to be microSeconds,    // the number of microseconds from the epoch starting    // 0/0/0000 (12 am Jan 1, 1BCE)    //    CIMDateTime dateTimeValue = propertyValueDateTime;    Uint64 dateTimeValueInMicroSecs =        dateTimeValue.toMicroSeconds();    // In ICU, as UTC milliseconds from the epoch starting    // (1 January 1970 0:00 UTC)    CIMDateTime dt;    dt.set("19700101000000.000000+000");    // Convert dateTimeValue to be milliSeconds,    // the number of milliSeconds from the epoch starting    // (1 January 1970 0:00 UTC)    UDate dateTimeValueInMilliSecs =       (Sint64)(dateTimeValueInMicroSecs - dt.toMicroSeconds())/1000;    // Create a formatter for DATE and TIME with medium length    // such as Jan 12, 1952 3:30:32pm    DateFormat *fmt;    try    {        if (locale == 0)        {            fmt = DateFormat::createDateTimeInstance(                DateFormat::MEDIUM, DateFormat::MEDIUM);        }        else        {            fmt = DateFormat::createDateTimeInstance(                DateFormat::MEDIUM, DateFormat::MEDIUM, locale);        }    }    catch (Exception& e)    {        PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, e.getMessage());        PEG_METHOD_EXIT();        return dateTimeValue.toString();    }    catch (...)    {        PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,        "Caught General Exception During DateFormat::createDateTimeInstance");        PEG_METHOD_EXIT();        return dateTimeValue.toString();    }    if (fmt == 0)    {        PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,            "Memory allocation error creating DateTime instance.");        PEG_METHOD_EXIT();        return dateTimeValue.toString();    }    // Format the Date and Time    UErrorCode status = U_ZERO_ERROR;    UnicodeString dateTimeUniStr;    fmt->format(dateTimeValueInMilliSecs, dateTimeUniStr, status);    if (U_FAILURE(status))    {        delete fmt;        PEG_METHOD_EXIT();        return dateTimeValue.toString();    }    // convert UnicodeString to char *    char dateTimeBuffer[256];    char *extractedStr = 0;    // Copy the contents of the string into dateTimeBuffer    Uint32 strLen = dateTimeUniStr.extract(0, sizeof(dateTimeBuffer),                                           dateTimeBuffer);    // There is not enough space in dateTimeBuffer    if (strLen > sizeof(dateTimeBuffer))    {        extractedStr = new char[strLen + 1];        strLen = dateTimeUniStr.extract(0, strLen + 1, extractedStr);    }    else    {        extractedStr = dateTimeBuffer;    }    String datetimeStr = extractedStr;    if (extractedStr != dateTimeBuffer)    {        delete extractedStr;    }    delete fmt;    PEG_METHOD_EXIT();    return datetimeStr;}String IndicationFormatter::_localizeBooleanStr(    const Boolean& booleanValue,    const Locale& locale){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_localizeBooleanStr");    if (booleanValue)    {        MessageLoaderParms parms(            "IndicationFormatter.IndicationFormatter._MSG_BOOLEAN_TRUE",            "true");        PEG_METHOD_EXIT();        return MessageLoader::getMessage(parms);    }    else    {        MessageLoaderParms parms(            "IndicationFormatter.IndicationFormatter._MSG_BOOLEAN_FALSE",            "false");        PEG_METHOD_EXIT();        return MessageLoader::getMessage(parms);    }}#endifPEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -