diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
commit | b525a3115f54576017a576ff842dede5e2e3545d (patch) | |
tree | c534b95a9e572b63896467624293a5ca1887d3a3 /xml2cmp/source/x2cclass | |
parent | 9399c662f36c385b0c705eb34e636a9aec450282 (diff) |
initial import
Diffstat (limited to 'xml2cmp/source/x2cclass')
-rw-r--r-- | xml2cmp/source/x2cclass/x2cstl.hxx | 81 | ||||
-rw-r--r-- | xml2cmp/source/x2cclass/xml_cd.hxx | 119 | ||||
-rw-r--r-- | xml2cmp/source/x2cclass/xml_cdff.cxx | 265 | ||||
-rw-r--r-- | xml2cmp/source/x2cclass/xml_cdff.hxx | 138 | ||||
-rw-r--r-- | xml2cmp/source/x2cclass/xml_cdim.cxx | 217 | ||||
-rw-r--r-- | xml2cmp/source/x2cclass/xml_cdim.hxx | 147 |
6 files changed, 967 insertions, 0 deletions
diff --git a/xml2cmp/source/x2cclass/x2cstl.hxx b/xml2cmp/source/x2cclass/x2cstl.hxx new file mode 100644 index 000000000000..53c5a72a7b6c --- /dev/null +++ b/xml2cmp/source/x2cclass/x2cstl.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * $RCSfile: x2cstl.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef UDKSERVICE_X2CSTL_HXX +#define UDKSERVICE_X2CSTL_HXX + + +#if STLPORT_VERSION < 321 +#include <tools/presys.h> +#include <vector.h> +#include <tools/postsys.h> +#else +#include <vector> +#endif // STLPORT_VERSION < 321 + +#ifdef _USE_NO_NAMERSPACES_ +#define std +#endif + + +#endif + + diff --git a/xml2cmp/source/x2cclass/xml_cd.hxx b/xml2cmp/source/x2cclass/xml_cd.hxx new file mode 100644 index 000000000000..3ed8999e34ed --- /dev/null +++ b/xml2cmp/source/x2cclass/xml_cd.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * $RCSfile: xml_cd.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef UDKSERVICE_XML_CD_HXX +#define UDKSERVICE_XML_CD_HXX + + +#include <tools/string.hxx> +#include "x2cstl.hxx" + + + +/** Represents one Component description from an XML file. + DatumOf() is used for tags with only one value. + DataOf() is used, if the tag has multiple values or if + you don't know. +**/ +class ComponentDescription +{ + public: + /** @ATTENTION + Because the enum values are used as array indices: + tag_None must be the first and have the value "0". + tag_MAX must be the last. + The enum values must not be assigned numbers. + **/ + enum E_Tag + { + tag_None = 0, + tag_Name, + tag_Description, + tag_ModuleName, + tag_LoaderName, + tag_SupportedService, + tag_ProjectBuildDependency, + tag_RuntimeModuleDependency, + tag_ServiceDependency, + tag_Language, + tag_Status, + tag_Type, + tag_MAX + }; + + virtual ~ComponentDescription() {} + + /// @return All values of this tag. An empty vector for wrong indices. + virtual const std::vector< ByteString > & + DataOf( + ComponentDescription::E_Tag + i_eTag ) const = 0; + + /// @return The only or the first value of this tag. An empty string for wrong indices. + virtual ByteString DatumOf( + ComponentDescription::E_Tag + i_eTag ) const = 0; +}; + + +#endif + + diff --git a/xml2cmp/source/x2cclass/xml_cdff.cxx b/xml2cmp/source/x2cclass/xml_cdff.cxx new file mode 100644 index 000000000000..deb74d566126 --- /dev/null +++ b/xml2cmp/source/x2cclass/xml_cdff.cxx @@ -0,0 +1,265 @@ +/************************************************************************* + * + * $RCSfile: xml_cdff.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "xml_cdff.hxx" + +#include <string.h> +#include <tools/stream.hxx> +#include "xml_cdim.hxx" +#include <ctype.h> + + +typedef ComponentDescriptionImpl::ValueList CdiValueList; + +class dyn_buffer +{ + public: + dyn_buffer() : s(0) {} + ~dyn_buffer() { if (s) delete [] s; } + operator const char *() const { return s; } + char * operator->() { return s; } + char & operator[]( + INT32 ix ) { return s[ix]; } + void SetSize( + INT32 i_size ) { if (s) delete [] s; s = new char [i_size]; } + private: + char * s; +}; + + +inline BOOL +LoadXmlFile( dyn_buffer & o_rBuffer, + const UniString & i_sXmlFilePath ) +{ + BOOL ret = TRUE; + SvFileStream aXmlFile; + + aXmlFile.Open(i_sXmlFilePath, STREAM_READ); + if (aXmlFile.GetErrorCode() != FSYS_ERR_OK) + ret = FALSE; + if (ret) + { + aXmlFile.Seek(STREAM_SEEK_TO_END); + INT32 nBufferSize = aXmlFile.Tell(); + o_rBuffer.SetSize(nBufferSize + 1); + o_rBuffer[nBufferSize] = '\0'; + aXmlFile.Seek(0); + if (aXmlFile.Read(o_rBuffer.operator->(), nBufferSize) == 0) + ret = FALSE; + } + + aXmlFile.Close(); + return ret; +} + + + +CompDescrsFromAnXmlFile::CompDescrsFromAnXmlFile() + : dpDescriptions(new std::vector< ComponentDescriptionImpl* >), + eStatus(not_yet_parsed) +{ + dpDescriptions->reserve(3); +} + +CompDescrsFromAnXmlFile::~CompDescrsFromAnXmlFile() +{ + Empty(); + delete dpDescriptions; +} + + +BOOL +CompDescrsFromAnXmlFile::Parse( const UniString & i_sXmlFilePath ) +{ + dyn_buffer dpBuffer; + + if (! LoadXmlFile(dpBuffer,i_sXmlFilePath) ) + { + eStatus = cant_read_file; + return FALSE; + } + + const char * pTokenStart = 0; + const char * pBufferPosition = dpBuffer; + INT32 nTokenLength = 0; + BOOL bWithinElement = FALSE; + + CdiValueList * pCurTagData = 0; + ByteString sStatusValue; // Used only if a <Status ...> tag is found. + + + for ( ComponentDescriptionImpl::ParseUntilStartOfDescription(pBufferPosition); + pBufferPosition != 0; + ComponentDescriptionImpl::ParseUntilStartOfDescription(pBufferPosition) ) + { + ComponentDescriptionImpl * pCurCD = 0; + pCurCD = new ComponentDescriptionImpl; + dpDescriptions->push_back(pCurCD); + + for ( ; *pBufferPosition != '\0' && pCurCD != 0; ) + { + switch (*pBufferPosition) + { + case '<' : + if (! bWithinElement) + { + pCurTagData = pCurCD->GetBeginTag(sStatusValue, pBufferPosition); + if (pCurTagData != 0) + { + if (sStatusValue.Len () == 0) + { + // Start new token: + pTokenStart = pBufferPosition; + nTokenLength = 0; + bWithinElement = TRUE;; + } + else + { + // Status tag is already parsed: + pCurTagData->push_back(sStatusValue); + } // endif (sStatusValue.Length () == 0) + } + else if ( ComponentDescriptionImpl::CheckEndOfDescription(pBufferPosition) ) + { + pBufferPosition += ComponentDescriptionImpl::DescriptionEndTagSize(); + pCurCD = 0; + } + else + { + eStatus = inconsistent_file; + return FALSE; + } // endif (pCurTagData != 0) elseif() else + } + else if ( pCurTagData->MatchesEndTag(pBufferPosition) ) + { + // Finish token: + pBufferPosition += pCurTagData->EndTagLength(); + bWithinElement = FALSE; + + // Remove leading and trailing spaces: + while ( isspace(*pTokenStart) ) + { + pTokenStart++; + nTokenLength--; + } + while ( nTokenLength > 0 + && isspace(pTokenStart[nTokenLength-1]) ) + { + nTokenLength--; + } + // Add token to tag values list. + pCurTagData->push_back(ByteString(pTokenStart,nTokenLength)); + } + else + { + nTokenLength++; + ++pBufferPosition; + } // endif (!bWithinElement) else if () else + break; + default: + if (bWithinElement) + { + ++nTokenLength; + } + ++pBufferPosition; + } // end switch + } // end for + + if (bWithinElement) + { + eStatus = inconsistent_file; + return FALSE; + } + } // end for + + return TRUE; +} + +INT32 +CompDescrsFromAnXmlFile::NrOfDescriptions() const +{ + return dpDescriptions->size(); +} + +const ComponentDescription & +CompDescrsFromAnXmlFile::operator[](INT32 i_nIndex) const +{ + static const ComponentDescriptionImpl aNullDescr_; + return 0 <= i_nIndex && i_nIndex < dpDescriptions->size() + ? *(*dpDescriptions)[i_nIndex] + : aNullDescr_; +} + +void +CompDescrsFromAnXmlFile::Empty() +{ + for ( std::vector< ComponentDescriptionImpl* >::iterator aIter = dpDescriptions->begin(); + aIter != dpDescriptions->end(); + ++aIter ) + { + delete *aIter; + } + dpDescriptions->erase( dpDescriptions->begin(), + dpDescriptions->end() ); +} + + + diff --git a/xml2cmp/source/x2cclass/xml_cdff.hxx b/xml2cmp/source/x2cclass/xml_cdff.hxx new file mode 100644 index 000000000000..bb4a9d8f232d --- /dev/null +++ b/xml2cmp/source/x2cclass/xml_cdff.hxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * $RCSfile: xml_cdff.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef UDKSERVICE_XML_CDFF_HXX +#define UDKSERVICE_XML_CDFF_HXX + + +#include <tools/string.hxx> +#include "xml_cd.hxx" + +class ComponentDescriptionImpl; + + +/** @descr + Is able to parse an XML file with Component descriptions. Gives access + to the parsed data. + + Use: + CompDescrsFromAnXmlFile aCds; + UniString aFilepath(...); + if (! aCds.Parse(aFilepath) ) + { + // react on: + aCds.Status(); + } + + With operator[] you get access to ComponentDescriptions + on indices 0 to NrOfDescriptions()-1 . + + For further handling see class ComponentDescription + in xml_cd.hxx . + + It is possible to parse more than one time. Then the old data + are discarded. +**/ +class CompDescrsFromAnXmlFile +{ + public: + enum E_Status + { + ok = 0, + not_yet_parsed, + cant_read_file, + inconsistent_file, + no_tag_found_in_file + }; + + // LIFECYCLE + CompDescrsFromAnXmlFile(); + ~CompDescrsFromAnXmlFile(); + + // OPERATIONS + BOOL Parse( + const UniString & i_sXmlFilePath ); + + // INQUIRY + INT32 NrOfDescriptions() const; + const ComponentDescription & + operator[]( /// @return an empty description, if index does not exist. + INT32 i_nIndex ) const; + CompDescrsFromAnXmlFile::E_Status + Status() const; + + private: + // PRIVATE SERVICES + void Empty(); + + // DATA + std::vector< ComponentDescriptionImpl* > * + dpDescriptions; + E_Status eStatus; +}; + + + + + +#endif + + diff --git a/xml2cmp/source/x2cclass/xml_cdim.cxx b/xml2cmp/source/x2cclass/xml_cdim.cxx new file mode 100644 index 000000000000..caf5b99a4ddf --- /dev/null +++ b/xml2cmp/source/x2cclass/xml_cdim.cxx @@ -0,0 +1,217 @@ +/************************************************************************* + * + * $RCSfile: xml_cdim.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "xml_cdim.hxx" + +const char ComponentDescriptionImpl::C_sTagDescription[] + = "COMPONENTDESCRIPTION"; +const char ComponentDescriptionImpl::C_sStatus[] + = "Status"; +const char * ComponentDescriptionImpl::C_sSubTags[ComponentDescription::tag_MAX] + = { "None", + "Name", + "Description", + "ModuleName", + "LoaderName", + "SupportedService", + "ProjectBuildDependency", + "RuntimeModuleDependency", + "ServiceDependency", + "Language", + C_sStatus, + "Type" + }; + +ComponentDescriptionImpl::ComponentDescriptionImpl() +// : aTags +{ + const int i_max = tag_MAX; + aTags.reserve(i_max); + + for (int i = 0; i < i_max; ++i) + { + aTags.push_back( new ValueList(E_Tag(i)) ); + } // end for +} + +ComponentDescriptionImpl::~ComponentDescriptionImpl() +{ + for ( std::vector< ValueList* >::iterator aIter = aTags.begin(); + aIter != aTags.end(); + ++aIter ) + { + delete *aIter; + } +} + +inline void +GetStatusValue( ByteString & o_sValue, const ByteString & i_sStatusTag ) +{ + // o_sValue is always == "" at the beginning. + + const char * pStatusValue = strchr(i_sStatusTag.GetBuffer(), '"'); + if (pStatusValue == 0) + return; + pStatusValue++; + const char * pStatusValueEnd = strrchr(pStatusValue,'"'); + if (pStatusValueEnd == 0 || pStatusValueEnd - pStatusValue < 1) + return ; + + ByteString sValue(pStatusValue, pStatusValueEnd - pStatusValue); + o_sValue = sValue; +} + +ComponentDescriptionImpl::ValueList * +ComponentDescriptionImpl::GetBeginTag( ByteString & o_sValue, + const char *& io_pStartOfTag ) const +{ + o_sValue = ""; + + const char * pCurTextEnd = strchr(io_pStartOfTag,'>'); + if ( 0 == pCurTextEnd ) + return 0; + + if ( ComponentDescriptionImpl::CheckEndOfDescription(io_pStartOfTag) ) + return 0; + + ByteString sTag(io_pStartOfTag + 1, pCurTextEnd - io_pStartOfTag - 1); + io_pStartOfTag += sTag.Len() + 2; + + // Special case <Status ... > + if ( strnicmp(C_sStatus, sTag.GetBuffer(), (sizeof C_sStatus) - 1 ) == 0 ) + { + GetStatusValue(o_sValue,sTag); + return aTags[tag_Status]; + } + + // Regular seeking for matching data list: + for ( INT32 i = 0; i < tag_MAX; i++ ) + { + if ( 0 == stricmp(sTag.GetBuffer(), C_sSubTags[i]) ) + return aTags[i]; + } // end for + + return 0; +} + +const std::vector< ByteString > & +ComponentDescriptionImpl::DataOf( ComponentDescriptionImpl::E_Tag i_eTag ) const +{ + if (0 < i_eTag && i_eTag < tag_MAX) + return *aTags[i_eTag]; + else + return ValueList::Null_(); +} + +ByteString +ComponentDescriptionImpl::DatumOf( ComponentDescriptionImpl::E_Tag i_eTag ) const +{ + if (0 < i_eTag && i_eTag < tag_MAX) + { + ValueList & rValues = *aTags[i_eTag]; + if (rValues.size() > 0) + return rValues[0]; + } + return ""; +} + +void +ComponentDescriptionImpl::ParseUntilStartOfDescription( const char * & io_pBufferPosition ) +{ + for ( const char * pSearch = strchr(io_pBufferPosition,'<'); + pSearch != 0; + pSearch = strchr(pSearch+1,'<') ) + { + if ( pSearch != io_pBufferPosition + && 0 == strnicmp(pSearch+1,C_sTagDescription, strlen(C_sTagDescription)) + && *(pSearch + strlen(C_sTagDescription) + 1) == '>' ) + { + io_pBufferPosition = pSearch + strlen(C_sTagDescription) + 2; + return; + } + } // end for + + io_pBufferPosition = 0; +} + +BOOL +ComponentDescriptionImpl::ValueList::MatchesEndTag( const char * i_pTextPosition ) const +{ + return strnicmp( i_pTextPosition+2, C_sSubTags[eTag], strlen(C_sSubTags[eTag]) ) == 0 + && strncmp(i_pTextPosition,"</",2) == 0 + && *(i_pTextPosition + 2 + strlen(C_sSubTags[eTag]) ) == '>'; +} + +INT32 +ComponentDescriptionImpl::ValueList::EndTagLength() const +{ + return strlen(C_sSubTags[eTag]) + 3; +} + + +const ComponentDescriptionImpl::ValueList & +ComponentDescriptionImpl::ValueList::Null_() +{ + static const ValueList aNull_(ComponentDescription::tag_None); + return aNull_; +} + + diff --git a/xml2cmp/source/x2cclass/xml_cdim.hxx b/xml2cmp/source/x2cclass/xml_cdim.hxx new file mode 100644 index 000000000000..9e354362bce3 --- /dev/null +++ b/xml2cmp/source/x2cclass/xml_cdim.hxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * $RCSfile: xml_cdim.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:29:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef UDKSERVICE_XML_CDIM_HXX +#define UDKSERVICE_XML_CDIM_HXX + + +#include "xml_cd.hxx" +#include <tools/string.hxx> + + + + + +/** Represents one of the Component descriptions in an XML file. + Implements ComponentDescription and does part of the parsing for class CompDescrsFromAnXmlFile. +**/ +class ComponentDescriptionImpl : public ComponentDescription +{ + public: + class ValueList : public std::vector< ByteString > + { + public: + // LIFECYCLE + ValueList( + E_Tag i_eTag ) + : eTag(i_eTag) {} + // INQUIRY + const char * BeginTag() const; + BOOL MatchesEndTag( + const char * i_pTextPosition ) const; + INT32 EndTagLength() const; + + static const ValueList & + Null_(); + private: + E_Tag eTag; + }; + + // LIFECYCLE + ComponentDescriptionImpl(); + virtual ~ComponentDescriptionImpl(); + + // OPERATIONS + ValueList * GetBeginTag( + ByteString & o_sValue, + const char * & io_pStartOfTag ) const; + static void ParseUntilStartOfDescription( + const char * & io_pBufferPosition ); + static BOOL CheckEndOfDescription( + const char * & io_pBufferPosition ); + // INQUIRY + static INT32 DescriptionEndTagSize(); + + // INTERFACE ComponentDescription + // INQUIRY + virtual const std::vector< ByteString > & + DataOf( /// @return All values of this tag. + ComponentDescription::E_Tag + i_eTag ) const; + virtual ByteString DatumOf( /// @return The only or the first value of this tag. + ComponentDescription::E_Tag + i_eTag ) const; + private: + // DATA + static const char C_sTagDescription[]; + static const char C_sStatus[]; + static const char * C_sSubTags[ComponentDescription::tag_MAX]; + friend class ValueList; + + std::vector< ValueList* > // Dynamic allocated pointers. + aTags; +}; + + +inline BOOL +ComponentDescriptionImpl::CheckEndOfDescription( const char * & io_pBufferPosition ) + { return strnicmp(io_pBufferPosition + 2, C_sTagDescription, strlen(C_sTagDescription)) == 0 + && strncmp(io_pBufferPosition, "</", 2) == 0 + && * (io_pBufferPosition + 2 + strlen(C_sTagDescription)) == '>'; } + +inline INT32 +ComponentDescriptionImpl::DescriptionEndTagSize() + { return strlen(C_sTagDescription) + 3; } + + +#endif + + |