1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xml_cdim.cxx,v $
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
[]
37 const char * ComponentDescriptionImpl::C_sSubTags
[ComponentDescription::tag_MAX
]
44 "ProjectBuildDependency",
45 "RuntimeModuleDependency",
52 ComponentDescriptionImpl::ComponentDescriptionImpl()
55 const int i_max
= tag_MAX
;
58 for (int i
= 0; i
< i_max
; ++i
)
60 aTags
.push_back( new ValueList(E_Tag(i
)) );
64 ComponentDescriptionImpl::~ComponentDescriptionImpl()
66 for ( std::vector
< ValueList
* >::iterator aIter
= aTags
.begin();
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)
83 const char * pStatusValueEnd
= strrchr(pStatusValue
,'"');
84 if (pStatusValueEnd
== 0 || pStatusValueEnd
- pStatusValue
< 1)
87 ByteString
sValue(pStatusValue
, pStatusValueEnd
- pStatusValue
);
91 ComponentDescriptionImpl::ValueList
*
92 ComponentDescriptionImpl::GetBeginTag( ByteString
& o_sValue
,
93 const char *& io_pStartOfTag
) const
97 const char * pCurTextEnd
= strchr(io_pStartOfTag
,'>');
98 if ( 0 == pCurTextEnd
)
101 if ( ComponentDescriptionImpl::CheckEndOfDescription(io_pStartOfTag
) )
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
]) )
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
];
130 return ValueList::Null_();
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)
146 ComponentDescriptionImpl::ParseUntilStartOfDescription( const char * & io_pBufferPosition
)
148 for ( const char * pSearch
= strchr(io_pBufferPosition
,'<');
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;
161 io_pBufferPosition
= 0;
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
]) ) == '>';
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
);