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