1*ab595ff6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ab595ff6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ab595ff6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ab595ff6SAndrew Rist * distributed with this work for additional information 6*ab595ff6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ab595ff6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ab595ff6SAndrew Rist * "License"); you may not use this file except in compliance 9*ab595ff6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ab595ff6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ab595ff6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ab595ff6SAndrew Rist * software distributed under the License is distributed on an 15*ab595ff6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ab595ff6SAndrew Rist * KIND, either express or implied. See the License for the 17*ab595ff6SAndrew Rist * specific language governing permissions and limitations 18*ab595ff6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ab595ff6SAndrew Rist *************************************************************/ 21*ab595ff6SAndrew Rist 22*ab595ff6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "xml_cdim.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir const char ComponentDescriptionImpl::C_sTagDescription[] 27cdf0e10cSrcweir = "COMPONENTDESCRIPTION"; 28cdf0e10cSrcweir const char ComponentDescriptionImpl::C_sStatus[] 29cdf0e10cSrcweir = "Status"; 30cdf0e10cSrcweir const char * ComponentDescriptionImpl::C_sSubTags[ComponentDescription::tag_MAX] 31cdf0e10cSrcweir = { "None", 32cdf0e10cSrcweir "Name", 33cdf0e10cSrcweir "Description", 34cdf0e10cSrcweir "ModuleName", 35cdf0e10cSrcweir "LoaderName", 36cdf0e10cSrcweir "SupportedService", 37cdf0e10cSrcweir "ProjectBuildDependency", 38cdf0e10cSrcweir "RuntimeModuleDependency", 39cdf0e10cSrcweir "ServiceDependency", 40cdf0e10cSrcweir "Language", 41cdf0e10cSrcweir C_sStatus, 42cdf0e10cSrcweir "Type" 43cdf0e10cSrcweir }; 44cdf0e10cSrcweir 45cdf0e10cSrcweir ComponentDescriptionImpl::ComponentDescriptionImpl() 46cdf0e10cSrcweir // : aTags 47cdf0e10cSrcweir { 48cdf0e10cSrcweir const int i_max = tag_MAX; 49cdf0e10cSrcweir aTags.reserve(i_max); 50cdf0e10cSrcweir 51cdf0e10cSrcweir for (int i = 0; i < i_max; ++i) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir aTags.push_back( new ValueList(E_Tag(i)) ); 54cdf0e10cSrcweir } // end for 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir ComponentDescriptionImpl::~ComponentDescriptionImpl() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir for ( std::vector< ValueList* >::iterator aIter = aTags.begin(); 60cdf0e10cSrcweir aIter != aTags.end(); 61cdf0e10cSrcweir ++aIter ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir delete *aIter; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir inline void 68cdf0e10cSrcweir GetStatusValue( ByteString & o_sValue, const ByteString & i_sStatusTag ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir // o_sValue is always == "" at the beginning. 71cdf0e10cSrcweir 72cdf0e10cSrcweir const char * pStatusValue = strchr(i_sStatusTag.GetBuffer(), '"'); 73cdf0e10cSrcweir if (pStatusValue == 0) 74cdf0e10cSrcweir return; 75cdf0e10cSrcweir pStatusValue++; 76cdf0e10cSrcweir const char * pStatusValueEnd = strrchr(pStatusValue,'"'); 77cdf0e10cSrcweir if (pStatusValueEnd == 0 || pStatusValueEnd - pStatusValue < 1) 78cdf0e10cSrcweir return ; 79cdf0e10cSrcweir 80cdf0e10cSrcweir ByteString sValue(pStatusValue, pStatusValueEnd - pStatusValue); 81cdf0e10cSrcweir o_sValue = sValue; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir ComponentDescriptionImpl::ValueList * 85cdf0e10cSrcweir ComponentDescriptionImpl::GetBeginTag( ByteString & o_sValue, 86cdf0e10cSrcweir const char *& io_pStartOfTag ) const 87cdf0e10cSrcweir { 88cdf0e10cSrcweir o_sValue = ""; 89cdf0e10cSrcweir 90cdf0e10cSrcweir const char * pCurTextEnd = strchr(io_pStartOfTag,'>'); 91cdf0e10cSrcweir if ( 0 == pCurTextEnd ) 92cdf0e10cSrcweir return 0; 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( ComponentDescriptionImpl::CheckEndOfDescription(io_pStartOfTag) ) 95cdf0e10cSrcweir return 0; 96cdf0e10cSrcweir 97cdf0e10cSrcweir ByteString sTag(io_pStartOfTag + 1, pCurTextEnd - io_pStartOfTag - 1); 98cdf0e10cSrcweir io_pStartOfTag += sTag.Len() + 2; 99cdf0e10cSrcweir 100cdf0e10cSrcweir // Special case <Status ... > 101cdf0e10cSrcweir if ( strnicmp(C_sStatus, sTag.GetBuffer(), (sizeof C_sStatus) - 1 ) == 0 ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir GetStatusValue(o_sValue,sTag); 104cdf0e10cSrcweir return aTags[tag_Status]; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir // Regular seeking for matching data list: 108cdf0e10cSrcweir for ( INT32 i = 0; i < tag_MAX; i++ ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if ( 0 == stricmp(sTag.GetBuffer(), C_sSubTags[i]) ) 111cdf0e10cSrcweir return aTags[i]; 112cdf0e10cSrcweir } // end for 113cdf0e10cSrcweir 114cdf0e10cSrcweir return 0; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir const std::vector< ByteString > & 118cdf0e10cSrcweir ComponentDescriptionImpl::DataOf( ComponentDescriptionImpl::E_Tag i_eTag ) const 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if (0 < i_eTag && i_eTag < tag_MAX) 121cdf0e10cSrcweir return *aTags[i_eTag]; 122cdf0e10cSrcweir else 123cdf0e10cSrcweir return ValueList::Null_(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir ByteString 127cdf0e10cSrcweir ComponentDescriptionImpl::DatumOf( ComponentDescriptionImpl::E_Tag i_eTag ) const 128cdf0e10cSrcweir { 129cdf0e10cSrcweir if (0 < i_eTag && i_eTag < tag_MAX) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir ValueList & rValues = *aTags[i_eTag]; 132cdf0e10cSrcweir if (rValues.size() > 0) 133cdf0e10cSrcweir return rValues[0]; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir return ""; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir void 139cdf0e10cSrcweir ComponentDescriptionImpl::ParseUntilStartOfDescription( const char * & io_pBufferPosition ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir for ( const char * pSearch = strchr(io_pBufferPosition,'<'); 142cdf0e10cSrcweir pSearch != 0; 143cdf0e10cSrcweir pSearch = strchr(pSearch+1,'<') ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if ( pSearch != io_pBufferPosition 146cdf0e10cSrcweir && 0 == strnicmp(pSearch+1,C_sTagDescription, strlen(C_sTagDescription)) 147cdf0e10cSrcweir && *(pSearch + strlen(C_sTagDescription) + 1) == '>' ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir io_pBufferPosition = pSearch + strlen(C_sTagDescription) + 2; 150cdf0e10cSrcweir return; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } // end for 153cdf0e10cSrcweir 154cdf0e10cSrcweir io_pBufferPosition = 0; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir BOOL 158cdf0e10cSrcweir ComponentDescriptionImpl::ValueList::MatchesEndTag( const char * i_pTextPosition ) const 159cdf0e10cSrcweir { 160cdf0e10cSrcweir return strnicmp( i_pTextPosition+2, C_sSubTags[eTag], strlen(C_sSubTags[eTag]) ) == 0 161cdf0e10cSrcweir && strncmp(i_pTextPosition,"</",2) == 0 162cdf0e10cSrcweir && *(i_pTextPosition + 2 + strlen(C_sSubTags[eTag]) ) == '>'; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir INT32 166cdf0e10cSrcweir ComponentDescriptionImpl::ValueList::EndTagLength() const 167cdf0e10cSrcweir { 168cdf0e10cSrcweir return strlen(C_sSubTags[eTag]) + 3; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir const ComponentDescriptionImpl::ValueList & 173cdf0e10cSrcweir ComponentDescriptionImpl::ValueList::Null_() 174cdf0e10cSrcweir { 175cdf0e10cSrcweir static const ValueList aNull_(ComponentDescription::tag_None); 176cdf0e10cSrcweir return aNull_; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir 180