1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "xml_cdim.hxx" 29 30 const char ComponentDescriptionImpl::C_sTagDescription[] 31 = "COMPONENTDESCRIPTION"; 32 const char ComponentDescriptionImpl::C_sStatus[] 33 = "Status"; 34 const char * ComponentDescriptionImpl::C_sSubTags[ComponentDescription::tag_MAX] 35 = { "None", 36 "Name", 37 "Description", 38 "ModuleName", 39 "LoaderName", 40 "SupportedService", 41 "ProjectBuildDependency", 42 "RuntimeModuleDependency", 43 "ServiceDependency", 44 "Language", 45 C_sStatus, 46 "Type" 47 }; 48 49 ComponentDescriptionImpl::ComponentDescriptionImpl() 50 // : aTags 51 { 52 const int i_max = tag_MAX; 53 aTags.reserve(i_max); 54 55 for (int i = 0; i < i_max; ++i) 56 { 57 aTags.push_back( new ValueList(E_Tag(i)) ); 58 } // end for 59 } 60 61 ComponentDescriptionImpl::~ComponentDescriptionImpl() 62 { 63 for ( std::vector< ValueList* >::iterator aIter = aTags.begin(); 64 aIter != aTags.end(); 65 ++aIter ) 66 { 67 delete *aIter; 68 } 69 } 70 71 inline void 72 GetStatusValue( ByteString & o_sValue, const ByteString & i_sStatusTag ) 73 { 74 // o_sValue is always == "" at the beginning. 75 76 const char * pStatusValue = strchr(i_sStatusTag.GetBuffer(), '"'); 77 if (pStatusValue == 0) 78 return; 79 pStatusValue++; 80 const char * pStatusValueEnd = strrchr(pStatusValue,'"'); 81 if (pStatusValueEnd == 0 || pStatusValueEnd - pStatusValue < 1) 82 return ; 83 84 ByteString sValue(pStatusValue, pStatusValueEnd - pStatusValue); 85 o_sValue = sValue; 86 } 87 88 ComponentDescriptionImpl::ValueList * 89 ComponentDescriptionImpl::GetBeginTag( ByteString & o_sValue, 90 const char *& io_pStartOfTag ) const 91 { 92 o_sValue = ""; 93 94 const char * pCurTextEnd = strchr(io_pStartOfTag,'>'); 95 if ( 0 == pCurTextEnd ) 96 return 0; 97 98 if ( ComponentDescriptionImpl::CheckEndOfDescription(io_pStartOfTag) ) 99 return 0; 100 101 ByteString sTag(io_pStartOfTag + 1, pCurTextEnd - io_pStartOfTag - 1); 102 io_pStartOfTag += sTag.Len() + 2; 103 104 // Special case <Status ... > 105 if ( strnicmp(C_sStatus, sTag.GetBuffer(), (sizeof C_sStatus) - 1 ) == 0 ) 106 { 107 GetStatusValue(o_sValue,sTag); 108 return aTags[tag_Status]; 109 } 110 111 // Regular seeking for matching data list: 112 for ( INT32 i = 0; i < tag_MAX; i++ ) 113 { 114 if ( 0 == stricmp(sTag.GetBuffer(), C_sSubTags[i]) ) 115 return aTags[i]; 116 } // end for 117 118 return 0; 119 } 120 121 const std::vector< ByteString > & 122 ComponentDescriptionImpl::DataOf( ComponentDescriptionImpl::E_Tag i_eTag ) const 123 { 124 if (0 < i_eTag && i_eTag < tag_MAX) 125 return *aTags[i_eTag]; 126 else 127 return ValueList::Null_(); 128 } 129 130 ByteString 131 ComponentDescriptionImpl::DatumOf( ComponentDescriptionImpl::E_Tag i_eTag ) const 132 { 133 if (0 < i_eTag && i_eTag < tag_MAX) 134 { 135 ValueList & rValues = *aTags[i_eTag]; 136 if (rValues.size() > 0) 137 return rValues[0]; 138 } 139 return ""; 140 } 141 142 void 143 ComponentDescriptionImpl::ParseUntilStartOfDescription( const char * & io_pBufferPosition ) 144 { 145 for ( const char * pSearch = strchr(io_pBufferPosition,'<'); 146 pSearch != 0; 147 pSearch = strchr(pSearch+1,'<') ) 148 { 149 if ( pSearch != io_pBufferPosition 150 && 0 == strnicmp(pSearch+1,C_sTagDescription, strlen(C_sTagDescription)) 151 && *(pSearch + strlen(C_sTagDescription) + 1) == '>' ) 152 { 153 io_pBufferPosition = pSearch + strlen(C_sTagDescription) + 2; 154 return; 155 } 156 } // end for 157 158 io_pBufferPosition = 0; 159 } 160 161 BOOL 162 ComponentDescriptionImpl::ValueList::MatchesEndTag( const char * i_pTextPosition ) const 163 { 164 return strnicmp( i_pTextPosition+2, C_sSubTags[eTag], strlen(C_sSubTags[eTag]) ) == 0 165 && strncmp(i_pTextPosition,"</",2) == 0 166 && *(i_pTextPosition + 2 + strlen(C_sSubTags[eTag]) ) == '>'; 167 } 168 169 INT32 170 ComponentDescriptionImpl::ValueList::EndTagLength() const 171 { 172 return strlen(C_sSubTags[eTag]) + 3; 173 } 174 175 176 const ComponentDescriptionImpl::ValueList & 177 ComponentDescriptionImpl::ValueList::Null_() 178 { 179 static const ValueList aNull_(ComponentDescription::tag_None); 180 return aNull_; 181 } 182 183 184