From: akl Date: Fri, 27 Jul 2007 15:33:45 +0000 (+0000) Subject: New XML parser is used to read new structure of XMl file. X-Git-Tag: IMP_BR_4~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e0a8c04ce4a86946270fd95884fba8e4b2a738b3;p=tools%2Finstall.git New XML parser is used to read new structure of XMl file. --- diff --git a/src/SALOME_XmlHandler.cxx b/src/SALOME_XmlHandler.cxx index f0a8be4..c216183 100644 --- a/src/SALOME_XmlHandler.cxx +++ b/src/SALOME_XmlHandler.cxx @@ -14,6 +14,8 @@ #include #include #include +#include +#include // ================================================================ /*! @@ -28,7 +30,6 @@ static bool isBoolAttributeSet( const QString& attr ) { attr.lower() == "ok" || ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) ); } - // ================================================================ /*! * ::environmentVariable [ static ] @@ -92,22 +93,23 @@ static QString substituteVars( const QString& str ) { */ // ================================================================ StructureParser::StructureParser( SALOME_InstallWizard* wizard ) - : QXmlDefaultHandler(), - myWizard( wizard ), - myTree( 0 ), + : myWizard( wizard ), + myModules( 0 ), + myPrereqs( 0 ), myTargetDir( 0 ), myTempDir( 0 ) { } // ================================================================ /*! - * StructureParser::setProductsList + * StructureParser::setProductsLists * Sets products list view */ // ================================================================ -void StructureParser::setProductsList( ProductsView* tree ) +void StructureParser::setProductsLists( ProductsView* mtree, ProductsView* ptree ) { - myTree = tree; + myModules = mtree; + myPrereqs = ptree; } // ================================================================ /*! @@ -136,111 +138,206 @@ void StructureParser::setTempDir( QLineEdit* dir ) } // ================================================================ /*! - * StructureParser::startElement - * Begins parsing of the xml dom-element - */ -// ================================================================ -bool StructureParser::startElement( const QString& /*namespaceURI*/, - const QString& /*localName*/, - const QString& qName, - const QXmlAttributes& attributes) + * StructureParser::getConfigInfo + * Parse 'config' part of the XML file + */ +// ================================================================ +void StructureParser::getConfigInfo(const QDomElement &theElem) { - ___MESSAGE___( qName ); - ___MESSAGE___( attributes.length() ); - QCheckListItem* element; - if (( qName == "config" ) && ( attributes.length() > 0 ) ) { - QString myVersion, myCaption, myCopyright, myLicense, myOS; - if ( attributes.value( "version" ) ) { - myVersion = attributes.value( "version" ).stripWhiteSpace(); + QString myVersion, myCaption, myCopyright, myLicense, myPlatforms; + if ( theElem.attribute( "version" ) ) { + myVersion = theElem.attribute( "version" ).stripWhiteSpace(); if ( myWizard && !myVersion.isEmpty() ) myWizard->setVersion( myVersion ); } - if ( attributes.value( "caption" ) ) { - myCaption = attributes.value( "caption" ).arg( myVersion ).stripWhiteSpace(); + if ( theElem.attribute( "caption" ) ) { + myCaption = theElem.attribute( "caption" ).arg( myVersion ).stripWhiteSpace(); if ( myWizard && !myCaption.isEmpty() ) myWizard->setCaption( myCaption ); } - if ( attributes.value( "copyright" ) ) { - myCopyright = attributes.value( "copyright" ).stripWhiteSpace(); + if ( theElem.attribute( "copyright" ) ) { + myCopyright = theElem.attribute( "copyright" ).stripWhiteSpace(); if ( myWizard && !myCopyright.isEmpty() ) myWizard->setCopyright( myCopyright ); } - if ( attributes.value( "license" ) ) { - myLicense = attributes.value( "license" ).stripWhiteSpace(); + if ( theElem.attribute( "license" ) ) { + myLicense = theElem.attribute( "license" ).stripWhiteSpace(); if ( myWizard && !myLicense.isEmpty() ) myWizard->setLicense( myLicense ); } - if ( attributes.value( "os" ) ) { - myOS = attributes.value( "os" ).stripWhiteSpace(); - if ( myWizard && !myOS.isEmpty() ) - myWizard->setOS( myOS ); + if ( theElem.attribute( "platforms" ) ) { +// myPlatforms = theElem.attribute( "platforms" ).stripWhiteSpace(); +// if ( myWizard && !myPlatforms.isEmpty() ) +// myWizard->setPlatforms( myPlatforms ); + } + if ( theElem.attribute( "targetdir" ) ) { + if ( myTargetDir ) + myTargetDir->setText( substituteVars( theElem.attribute( "targetdir" ) ) ); + } + if ( theElem.attribute( "tempdir" ) ) { + if ( myTempDir ) + myTempDir->setText( substituteVars( theElem.attribute( "tempdir" ) ) ); + } +} +// ================================================================ +/*! + * StructureParser::getButtonsInfo + * Parse 'buttons' part of the XML file + */ +// ================================================================ +void StructureParser::getButtonsInfo(const QDomNode &theNode) +{ + QString aLabel, aTootip, aScript; + for( QDomNode node = theNode.firstChild(); !node.isNull(); node = node.nextSibling() ) { + if ( !node.isElement() ) + continue; + QDomElement elem = node.toElement(); + if ( isBoolAttributeSet( elem.attribute( "disable" ) ) ) + continue; + aLabel = ""; aTootip = ""; aScript = ""; + if ( elem.attribute( "label" ) ) + aLabel = elem.attribute( "label" ).stripWhiteSpace(); + if ( elem.attribute( "tooltip" ) ) + aTootip = elem.attribute( "tooltip" ).stripWhiteSpace(); + if ( elem.attribute( "script" ) ) + aScript = elem.attribute( "script" ).stripWhiteSpace(); + if ( !aLabel.isEmpty() ) { + if ( node == theNode.firstChild() ) + myWizard->addFinishButton( aLabel, aTootip, aScript, true ); + else + myWizard->addFinishButton( aLabel, aTootip, aScript ); } - } - else if (( qName == "button" ) && ( attributes.length() > 0 ) && myTree && myWizard ) { - if ( isBoolAttributeSet( attributes.value( "disable" ) ) ) - return true; - - QString myLabel, myTootip, myScript; - if ( attributes.value( "label" ) ) - myLabel = attributes.value( "label" ).stripWhiteSpace(); - if ( attributes.value( "tooltip" ) ) - myTootip = attributes.value( "tooltip" ).stripWhiteSpace(); - if ( attributes.value( "script" ) ) - myScript = attributes.value( "script" ).stripWhiteSpace(); - if ( !myLabel.isEmpty() ) - myWizard->addFinishButton( myLabel, myTootip, myScript ); - } - else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) { - if ( isBoolAttributeSet( attributes.value( "disable" ) ) ) - return true; - - QString install = attributes.value( "install" ); - QStringList supported = QStringList::split( ",", attributes.value( "supported" ) ); - QString script = attributes.value( "script" ); - QStringList deps = QStringList(); - if ( attributes.value( "dependancies" ) != "" ) - deps = QStringList::split( ",", attributes.value( "dependancies" ), false ); - element = myTree->addItem( attributes.value( "name" ), attributes.value( "version" ), install, supported, script ); - QStringList diskspace = QStringList::split(",",attributes.value( "installdiskspace" ) ); - QString descr = QString::null; - if ( attributes.value( "description" ) != "" ) - descr = attributes.value( "description" ).stripWhiteSpace(); - QString ctx = QString::null; - if ( attributes.value( "context" ) != "" ) - ctx = attributes.value( "context" ).stripWhiteSpace().lower(); - bool pickUp = isBoolAttributeSet( attributes.value( "pickupenv" ) ); - myWizard->setDependancies( element, - Dependancies( attributes.value( "name" ), - deps, - ( diskspace.count() > 0 ? diskspace[ 0 ].toInt() : 0 ), - ( diskspace.count() > 1 ? diskspace[1].toInt() : ( diskspace.count() > 0 ? diskspace[0].toInt() : 0 ) ), - attributes.value( "temporarydiskspace" ).toInt(), - install, - descr, - ctx, - pickUp ) ); } - else if (( qName == "path" ) && ( attributes.length() > 0 ) && myWizard ) { - if ( myTargetDir ) - myTargetDir->setText( substituteVars( attributes.value( "targetdir" ) ) ); +} +// ================================================================ +/*! + * StructureParser::getProductsInfo + * Parse 'products' part of the XML file + */ +// ================================================================ +void StructureParser::getProductsInfo( const QDomNode &theNode ) +{ + MapDependencies mapDeps; + QCheckListItem* element; - if ( myTempDir ) { - if ( !attributes.value( "tempdir" ).stripWhiteSpace().isEmpty() ) - myTempDir->setText( substituteVars( attributes.value( "tempdir" ) ) ); - } + QDomNode docNode = theNode.parentNode(); + getDependenciesInfo( docNode, mapDeps ); + + for( QDomNode prodNode = theNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) { + if ( !prodNode.isElement() ) + continue; + for( QDomNode instNode = prodNode.firstChild(); !instNode.isNull(); instNode = instNode.nextSibling() ) { + if ( !instNode.isElement() ) + continue; + QDomElement instElem = instNode.toElement(); + if ( instElem.attribute( "os" ) != myWizard->getPlatform() ) + continue; + if ( isBoolAttributeSet( instElem.attribute( "disable" ) ) ) + break; // current product is skip + QDomElement prodElem = prodNode.toElement(); + + QStringList diskspace = QStringList::split( ",", instElem.attribute( "installdiskspace" ) ); + long binreq = diskspace[ 0 ].toInt(); + long srcreq = diskspace[ 1 ].toInt(); + long cmplreq = diskspace[ 2 ].toInt(); + + QString name = prodElem.attribute( "name" ).stripWhiteSpace(); + QString type = prodElem.attribute( "type" ).stripWhiteSpace().lower(); + bool pickUp = isBoolAttributeSet( instElem.attribute( "pickupenv" ) ); + QString script = instElem.attribute( "script" ); + InstallationType instType = myWizard->getInstType(); + QStringList typesList = QStringList::split( ",", type ); + long prodSize = ( instType == Binaries ? (binreq + srcreq) : + instType == Sources ? srcreq : + cmplreq ); + if ( typesList.find( "component" ) != typesList.end() ) { + element = myModules->addItem( name, + QString::number( prodSize ) + " KB", + script ); + } + else + element = myPrereqs->addItem( name, + QString::number( prodSize ) + " KB", + script ); + QString descr = QString::null; + if ( prodElem.attribute( "description" ) != "" ) + descr = prodElem.attribute( "description" ).stripWhiteSpace(); + myWizard->setDependancies + ( element, + Dependancies( name, + mapDeps[ name ], + binreq, + srcreq, + cmplreq, + instElem.attribute( "temporarydiskspace" ).toInt(), + instElem.attribute( "version" ), + descr, + type, + pickUp ) ); + } } - return true; } // ================================================================ /*! - * StructureParser::endElement - * Finishes parsing of the xml dom-element + * StructureParser::getDependencies + * Parse 'dependencies' part of the XML file */ // ================================================================ -bool StructureParser::endElement( const QString&, - const QString&, - const QString& ) +void StructureParser::getDependenciesInfo( QDomNode &theNode, MapDependencies &theDepends ) { - return true; + QDomNode depsNode = theNode.namedItem( "dependencies" ); + QStringList depsList = QStringList(); + for( QDomNode prodNode = depsNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) { + if ( !prodNode.isElement() ) + continue; + QDomElement prodElem = prodNode.toElement(); + QString prodName = prodElem.attribute( "name" ).stripWhiteSpace(); + if ( theDepends.contains( prodName ) ) + continue; + depsList.clear(); + for ( QDomNode depNode = prodNode.firstChild(); !depNode.isNull(); depNode = depNode.nextSibling() ) { + if ( !depNode.isElement() ) + continue; + QDomElement depElem = depNode.toElement(); + QString depName = depElem.text(); + if ( depName.isEmpty() ) + continue; + if ( !depsList.contains( depName ) ) + depsList.append( depName ); + } + theDepends[ prodName ] = depsList; + } } +// ================================================================ +/*! + * StructureParser::readXmlFile + * Read XML configuration file for the current platform + */ +// ================================================================ +void StructureParser::readXmlFile(QString theFileName) +{ + QDomDocument doc( "xml_doc" ); + QFile file( theFileName ); + if ( !file.open( IO_ReadOnly ) ) + return; + if ( !doc.setContent( &file ) ) { + file.close(); + return; + } + file.close(); + + QDomElement docElem = doc.documentElement(); + for( QDomNode node = docElem.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QString nodeName = node.nodeName(); + if ( nodeName == "config" && node.isElement() ) { + getConfigInfo( node.toElement() ); + } + else if ( nodeName == "buttons" && node.hasChildNodes() && myModules && myWizard ) { + getButtonsInfo( node ); + } + else if ( nodeName == "products" && node.hasChildNodes() && myModules && myWizard ) { + getProductsInfo( node ); + } + } +} diff --git a/src/SALOME_XmlHandler.hxx b/src/SALOME_XmlHandler.hxx index bda9d92..acff974 100644 --- a/src/SALOME_XmlHandler.hxx +++ b/src/SALOME_XmlHandler.hxx @@ -8,7 +8,11 @@ #ifndef __SALOME_XmlHandler #define __SALOME_XmlHandler -#include +#include +#include +#include + +typedef QMap MapDependencies; /*! Class StructureParser: parses xml-description file and populates the list of the products @@ -16,31 +20,34 @@ class ProductsView; class SALOME_InstallWizard; class QLineEdit; +class QDom; -class StructureParser: public QXmlDefaultHandler +class StructureParser { public: // constructor StructureParser( SALOME_InstallWizard* wizard = 0 ); // set control widgets - void setProductsList( ProductsView* view ); + void setProductsLists( ProductsView* mview, ProductsView* pview ); void setTargetDir( QLineEdit* dir ); void setTempDir( QLineEdit* dir ); - // begins parsing of the xml dom-element - bool startElement( const QString&, - const QString&, - const QString& , - const QXmlAttributes& ); - // finishes parsing of the xml dom-element of the xml dom-element - bool endElement( const QString&, - const QString&, - const QString& ); + // parse 'config' part of the XML file + void getConfigInfo( const QDomElement &elem ); + // parse 'buttons' part of the XML file + void getButtonsInfo( const QDomNode &node ); + // parse 'products' part of the XML file + void getProductsInfo( const QDomNode &node ); + // parse 'dependencies' part of the XML file + void getDependenciesInfo( QDomNode &node, MapDependencies &depends ); + // read XML configuration file + void readXmlFile(QString theFileName); private: SALOME_InstallWizard* myWizard; // Salome Pro installation wizard's main window - ProductsView* myTree; // products list view + ProductsView* myModules; // modules list view + ProductsView* myPrereqs; // prerequisites list view QLineEdit* myTargetDir; // target directory widget QLineEdit* myTempDir; // temp directory widget };