Mercurial > hg > easaier-soundaccess
view data/fileio/AudioSourceInfoReader.cpp @ 244:ec2ca3fbd957
update AudioSourceInfoReader and SparqlResultsReader according to new sparql query
author | lbajardsilogic |
---|---|
date | Fri, 28 Mar 2008 12:22:56 +0000 |
parents | 87495ac7710a |
children | 2ea04b3f9141 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* Sound Access EASAIER client application. Silogic 2007. Laure Bajard. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #include "AudioSourceInfoReader.h" #include <iostream> AudioSourceInfoReader::AudioSourceInfoReader(AudioSourceInfoModel* model) { m_model = model; } bool AudioSourceInfoReader::parse(const QString & filename) { AudioSourceInfoHandler handler(m_model); QXmlSimpleReader reader; reader.setContentHandler(&handler); reader.setErrorHandler(&handler); QFile file(filename); if (!file.open(QFile::ReadOnly | QFile::Text)) { return false; } QXmlInputSource xmlInputSource(&file); if (reader.parse(xmlInputSource)) { return true; } return false; } AudioSourceInfoHandler::AudioSourceInfoHandler(AudioSourceInfoModel* model) : QXmlDefaultHandler(), m_model(model), m_inBinding(false), m_curBindingName("") {} bool AudioSourceInfoHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes) { /*QString name = qName.toLower(); bool ok = false; // Valid element names: // easaierResource // dc:identifier // dc:title // dc:creator... if (name == "easaierresource") { // nothing needed ok = true; } else { ok = true; QString id = attributes.value("id"); name.append(id); m_model->addInfo(name, attributes.value("value")); } if (!ok) { std::cerr << "WARNING: connexion config-XML: Failed to completely process element \"" << name.toLocal8Bit().data() << "\"" << std::endl; } return true;*/ QString name = qName.toLower(); bool ok = false; // Valid element names: // // sparql // head // variable // results // result // binding if (name == "sparql") { // nothing needed ok = true; } else if (name == "head") { // nothing needed ok = true; } else if (name == "variable") { // nothing needed ok = true; } else if (name == "results") { // nothing needed ok = true; } else if (name == "result") { ok = true; } else if (name == "binding") { m_curBindingName = attributes.value("name"); ok = true; } else if ( (name == "uri") || (name == "literal") ) { m_inBinding = true; ok = true; } if (!ok) { std::cerr << "WARNING: AudioSourceInfoHandler-XML: Failed to completely process element \"" << name.toLocal8Bit().data() << "\"" << std::endl; } return true; } bool AudioSourceInfoHandler::endElement(const QString &namespaceURI, const QString &localName, const QString &qName) { QString name = qName.toLower(); if ( (name == "uri") || (name == "literal") ) { m_inBinding = false; m_curBindingName = ""; } else if (name == "result") { m_model->addInfo("composer", m_composer); m_model->addInfo("arranger", m_arranger); m_composer.clear(); m_arranger.clear(); m_composer.append(" -"); m_arranger.append(" -"); } return true; } bool AudioSourceInfoHandler::characters(const QString &str) { if (m_inBinding) { if (m_curBindingName.contains("composer")) { m_composer.append(" " + str); } else if (m_curBindingName.contains("arranger")) { m_arranger.append(" " + str); } else { m_model->addInfo(m_curBindingName, str); } } return true; } bool AudioSourceInfoHandler::error(const QXmlParseException &exception) { QString errorString; errorString += QString("ERROR: connexion AudioSourceInfoHandler-XML: %1 at line %2, column %3") .arg(exception.message()) .arg(exception.lineNumber()) .arg(exception.columnNumber()); std::cerr << errorString.toLocal8Bit().data() << std::endl; return QXmlDefaultHandler::error(exception); } bool AudioSourceInfoHandler::fatalError(const QXmlParseException &exception) { QString errorString; errorString += QString("FATAL ERROR: connexion AudioSourceInfoHandler-XML: %1 at line %2, column %3") .arg(exception.message()) .arg(exception.lineNumber()) .arg(exception.columnNumber()); std::cerr << errorString.toLocal8Bit().data() << std::endl; return QXmlDefaultHandler::fatalError(exception); }