Update ooo320-m1
[ooovba.git] / xml2cmp / source / x2cclass / xml_cdim.cxx
blobc0943e73dd920e64455fda24b839628c66455753
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xml_cdim.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "xml_cdim.hxx"
33 const char ComponentDescriptionImpl::C_sTagDescription[]
34 = "COMPONENTDESCRIPTION";
35 const char ComponentDescriptionImpl::C_sStatus[]
36 = "Status";
37 const char * ComponentDescriptionImpl::C_sSubTags[ComponentDescription::tag_MAX]
38 = { "None",
39 "Name",
40 "Description",
41 "ModuleName",
42 "LoaderName",
43 "SupportedService",
44 "ProjectBuildDependency",
45 "RuntimeModuleDependency",
46 "ServiceDependency",
47 "Language",
48 C_sStatus,
49 "Type"
52 ComponentDescriptionImpl::ComponentDescriptionImpl()
53 // : aTags
55 const int i_max = tag_MAX;
56 aTags.reserve(i_max);
58 for (int i = 0; i < i_max; ++i)
60 aTags.push_back( new ValueList(E_Tag(i)) );
61 } // end for
64 ComponentDescriptionImpl::~ComponentDescriptionImpl()
66 for ( std::vector< ValueList* >::iterator aIter = aTags.begin();
67 aIter != aTags.end();
68 ++aIter )
70 delete *aIter;
74 inline void
75 GetStatusValue( ByteString & o_sValue, const ByteString & i_sStatusTag )
77 // o_sValue is always == "" at the beginning.
79 const char * pStatusValue = strchr(i_sStatusTag.GetBuffer(), '"');
80 if (pStatusValue == 0)
81 return;
82 pStatusValue++;
83 const char * pStatusValueEnd = strrchr(pStatusValue,'"');
84 if (pStatusValueEnd == 0 || pStatusValueEnd - pStatusValue < 1)
85 return ;
87 ByteString sValue(pStatusValue, pStatusValueEnd - pStatusValue);
88 o_sValue = sValue;
91 ComponentDescriptionImpl::ValueList *
92 ComponentDescriptionImpl::GetBeginTag( ByteString & o_sValue,
93 const char *& io_pStartOfTag ) const
95 o_sValue = "";
97 const char * pCurTextEnd = strchr(io_pStartOfTag,'>');
98 if ( 0 == pCurTextEnd )
99 return 0;
101 if ( ComponentDescriptionImpl::CheckEndOfDescription(io_pStartOfTag) )
102 return 0;
104 ByteString sTag(io_pStartOfTag + 1, pCurTextEnd - io_pStartOfTag - 1);
105 io_pStartOfTag += sTag.Len() + 2;
107 // Special case <Status ... >
108 if ( strnicmp(C_sStatus, sTag.GetBuffer(), (sizeof C_sStatus) - 1 ) == 0 )
110 GetStatusValue(o_sValue,sTag);
111 return aTags[tag_Status];
114 // Regular seeking for matching data list:
115 for ( INT32 i = 0; i < tag_MAX; i++ )
117 if ( 0 == stricmp(sTag.GetBuffer(), C_sSubTags[i]) )
118 return aTags[i];
119 } // end for
121 return 0;
124 const std::vector< ByteString > &
125 ComponentDescriptionImpl::DataOf( ComponentDescriptionImpl::E_Tag i_eTag ) const
127 if (0 < i_eTag && i_eTag < tag_MAX)
128 return *aTags[i_eTag];
129 else
130 return ValueList::Null_();
133 ByteString
134 ComponentDescriptionImpl::DatumOf( ComponentDescriptionImpl::E_Tag i_eTag ) const
136 if (0 < i_eTag && i_eTag < tag_MAX)
138 ValueList & rValues = *aTags[i_eTag];
139 if (rValues.size() > 0)
140 return rValues[0];
142 return "";
145 void
146 ComponentDescriptionImpl::ParseUntilStartOfDescription( const char * & io_pBufferPosition )
148 for ( const char * pSearch = strchr(io_pBufferPosition,'<');
149 pSearch != 0;
150 pSearch = strchr(pSearch+1,'<') )
152 if ( pSearch != io_pBufferPosition
153 && 0 == strnicmp(pSearch+1,C_sTagDescription, strlen(C_sTagDescription))
154 && *(pSearch + strlen(C_sTagDescription) + 1) == '>' )
156 io_pBufferPosition = pSearch + strlen(C_sTagDescription) + 2;
157 return;
159 } // end for
161 io_pBufferPosition = 0;
164 BOOL
165 ComponentDescriptionImpl::ValueList::MatchesEndTag( const char * i_pTextPosition ) const
167 return strnicmp( i_pTextPosition+2, C_sSubTags[eTag], strlen(C_sSubTags[eTag]) ) == 0
168 && strncmp(i_pTextPosition,"</",2) == 0
169 && *(i_pTextPosition + 2 + strlen(C_sSubTags[eTag]) ) == '>';
172 INT32
173 ComponentDescriptionImpl::ValueList::EndTagLength() const
175 return strlen(C_sSubTags[eTag]) + 3;
179 const ComponentDescriptionImpl::ValueList &
180 ComponentDescriptionImpl::ValueList::Null_()
182 static const ValueList aNull_(ComponentDescription::tag_None);
183 return aNull_;