📄 indicationformatter.cpp
字号:
{ for (Uint32 i = 0; i < indicationClass.getPropertyCount(); i++) { indicationClassProperties.append( indicationClass.getProperty(i).getName().getString()); } } // partial properties are selected else { Array<CIMName> propertyNames = propertyList.getPropertyNameArray(); for (Uint32 j = 0; j < propertyNames.size(); j++) { indicationClassProperties.append(propertyNames[j].getString()); } } // check if the textFormatParams is contained in the // indicationClassProperties for (Uint32 k = 0; k < textFormatParams.size(); k++) { if (!Contains(indicationClassProperties, textFormatParams[k])) { // The property name in TextFormatParameters is not // included in the select clause of the associated filter query MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter." "_MSG_MISS_MATCHED_PROPERTY_NAME", "The property name $0 in $1 does not match the properties " "in the select clause", textFormatParams[k], _PROPERTY_TEXTFORMATPARAMETERS.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER, exceptionStr); } } PEG_METHOD_EXIT();}void IndicationFormatter::_isValidIndex( const char* indexStr){ PEG_METHOD_ENTER(TRC_IND_FORMATTER, "IndicationFormatter::_isValidIndex"); String exceptionStr; String indexSubStr = indexStr; Uint32 space = indexSubStr.find(" "); if (space != PEG_NOT_FOUND) { String restIndexSubStr = indexSubStr.subString(space, PEG_NOT_FOUND); // skip the appended space from the indexSubStr Uint32 k = 0; while (restIndexSubStr[k] == ' ') { k++; } restIndexSubStr = restIndexSubStr.subString(k, PEG_NOT_FOUND); if (restIndexSubStr.size() == 0) { indexSubStr = indexSubStr.subString(0, space); } // invalid index string [12 xxx] else { // invalid index string MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_INVALID_INDEX", "Invalid index string $0", indexStr); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER, exceptionStr); } } Uint32 i = 0; while ((indexSubStr[i] >= '0') && (indexSubStr[i] <= '9')) { i++; } // invalid index string [12xxx} if (i != indexSubStr.size() ) { // invalid index string MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_INVALID_INDEX", "Invalid index string $0", indexStr); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER, exceptionStr); } PEG_METHOD_EXIT();}String IndicationFormatter::getFormattedIndText( const CIMInstance& subscription, const CIMInstance& indication, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::getFormattedIndText"); String indicationText; String textFormat = String::EMPTY; CIMValue textFormatValue; CIMValue textFormatParamsValue; Array<String> textFormatParams; // get TextFormat from subscription Uint32 textFormatPos = subscription.findProperty(_PROPERTY_TEXTFORMAT); // if the property TextFormat is not found, // indication is constructed with default format if (textFormatPos == PEG_NOT_FOUND) { indicationText = _formatDefaultIndicationText(indication, contentLangs); } else { textFormatValue = subscription.getProperty(textFormatPos).getValue(); // if the value of textFormat is NULL, // indication is constructed with default format if (textFormatValue.isNull()) { indicationText = _formatDefaultIndicationText(indication, contentLangs); } else { // get TextFormatParameters from subscription Uint32 textFormatParamsPos = subscription.findProperty( _PROPERTY_TEXTFORMATPARAMETERS); if (textFormatParamsPos != PEG_NOT_FOUND) { textFormatParamsValue = subscription.getProperty( textFormatParamsPos).getValue(); } // constructs indication with specified format if ((textFormatValue.getType() == CIMTYPE_STRING) && !(textFormatValue.isArray())) { textFormatValue.get(textFormat); if (!textFormatParamsValue.isNull()) { if ((textFormatParamsValue.getType() == CIMTYPE_STRING) && (textFormatParamsValue.isArray())) { textFormatParamsValue.get(textFormatParams); } } indicationText = _formatIndicationText( textFormat, textFormatParams, indication, contentLangs); } else { indicationText = _formatDefaultIndicationText(indication, contentLangs); } } } PEG_METHOD_EXIT(); return indicationText;}String IndicationFormatter::_formatDefaultIndicationText( const CIMInstance& indication, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::_formatDefaultIndicationText"); CIMInstance indicationInstance = indication.clone(); String propertyName; String indicationStr; Uint32 propertyCount = indicationInstance.getPropertyCount(); indicationStr.append("Indication (default format):"); Boolean canLocalize = false;#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU) Locale locale; canLocalize = _canLocalize(contentLangs, locale);#endif for (Uint32 i=0; i < propertyCount; i++) { CIMProperty property = indicationInstance.getProperty(i); propertyName = property.getName().getString(); CIMValue propertyValue = property.getValue(); Boolean valueIsNull = propertyValue.isNull(); Boolean isArray = propertyValue.isArray(); indicationStr.append(propertyName); indicationStr.append(" = "); CIMType type = propertyValue.getType(); if (!valueIsNull) { if (isArray) { indicationStr.append( _getArrayValues(propertyValue, "", contentLangs)); } else // value is not an array {#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU) if (canLocalize) { if (type == CIMTYPE_DATETIME) { CIMDateTime dateTimeValue; propertyValue.get(dateTimeValue); indicationStr.append( _localizeDateTime(dateTimeValue, locale)); } else if (type == CIMTYPE_BOOLEAN) { Boolean booleanValue; propertyValue.get(booleanValue); indicationStr.append( _localizeBooleanStr(booleanValue, locale)); } else { indicationStr.append(propertyValue.toString()); } } else { if (type == CIMTYPE_BOOLEAN) { indicationStr.append(_getBooleanStr(propertyValue)); } else { indicationStr.append(propertyValue.toString()); } }#else if (type == CIMTYPE_BOOLEAN) { indicationStr.append(_getBooleanStr(propertyValue)); } else { indicationStr.append(propertyValue.toString()); }#endif } } else { indicationStr.append("NULL"); } if (i < propertyCount -1) { indicationStr.append(", "); } propertyName.clear(); } PEG_METHOD_EXIT(); return indicationStr;}String IndicationFormatter::_formatIndicationText( const String& textFormat, const Array<String>& textFormatParams, const CIMInstance& indication, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::_formatIndicationText"); String indicationText; String textStr; String indicationFormat = textFormat; String propertyValue; String propertyParam; String propertyIndexStr; char propertyIndexBuffer[16]; Sint32 propertyIndex; Uint32 leftBrace = textFormat.find("{"); Uint32 rightBrace; Uint32 comma; Uint32 leftBracket; Uint32 rightBracket; String arrayIndexStr; indicationText.clear(); // Parsing the specified indication text format. // As an example, a format string for a UPS AlertIndication // could be defined as follows: A {4, string} UPS Alert was // detected on the device {6[1]}. while (leftBrace != PEG_NOT_FOUND) { textStr.clear(); propertyParam.clear(); propertyIndexStr.clear(); arrayIndexStr.clear(); // there is a left brace textStr = indicationFormat.subString(0, leftBrace); indicationText.append(textStr); indicationFormat = indicationFormat.subString(leftBrace+1, PEG_NOT_FOUND); rightBrace = indicationFormat.find("}"); // expecting a right brace if (rightBrace != PEG_NOT_FOUND) { // gets property index which is inside braces. // The supported formats are: {index} or {index, type} // or {index[x]} or {index[x], type} propertyParam = indicationFormat.subString(0, rightBrace); comma = propertyParam.find(","); // A dynamic content has syntax {index, type} or {index[x], type} if (comma != PEG_NOT_FOUND) { propertyParam = propertyParam.subString(0, comma); } leftBracket = propertyParam.find("["); // A dynamic content has syntax {index} or {index, type} if (leftBracket == PEG_NOT_FOUND) { propertyIndexStr = propertyParam; } // A dynamic content has syntax {index[x]} or {index[x], type} else { propertyIndexStr = propertyParam.subString(0,leftBracket); propertyParam = propertyParam.subString( leftBracket, PEG_NOT_FOUND); rightBracket = propertyParam.find("]"); arrayIndexStr = propertyParam.subString(1, rightBracket-1); } sprintf(propertyIndexBuffer, "%s", (const char *) propertyIndexStr.getCString()); try { _isValidIndex(propertyIndexBuffer); propertyIndex = atoi(propertyIndexBuffer); } catch (CIMException& c) { propertyIndex = -1; PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, c.getMessage()); } // property index is out of range if ((propertyIndex < 0) || ((Uint32)propertyIndex >= textFormatParams.size())) { propertyValue = "UNKNOWN"; } else { // get indication property value propertyValue = _getIndPropertyValue( textFormatParams[propertyIndex], arrayIndexStr, indication, contentLangs); } indicationText.append(propertyValue); } indicationFormat = indicationFormat.subString(rightBrace+1, PEG_NOT_FOUND); leftBrace = indicationFormat.find("{"); } indicationText.append(indicationFormat); PEG_METHOD_EXIT(); return indicationText;}String IndicationFormatter::_getIndPropertyValue( const String& specifiedPropertyName, const String& arrayIndexStr, const CIMInstance& indication, const ContentLanguageList& contentLangs){ PEG_METHOD_ENTER(TRC_IND_FORMATTER, "IndicationFormatter::_getIndPropertyValue"); CIMInstance indicationInstance = indication.clone(); String propertyName; Boolean canLocalize = false;#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU) Locale locale; canLocalize = _canLocalize(contentLangs, locale);#endif for (Uint32 i=0; i < indicationInstance.getPropertyCount(); i++) { CIMProperty property = indicationInstance.getProperty(i); propertyName = property.getName().getString(); // get specified property value if (String::equalNoCase(propertyName, specifiedPropertyName)) { CIMValue propertyValue = property.getValue(); Boolean valueIsNull = propertyValue.isNull(); CIMType type = propertyValue.getType(); if (!valueIsNull) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -