void fetchtr_ui( const char *fileName, MetaTranslator *tor, const char * /* defaultContext */, bool mustExist ) { QFile f( fileName ); if ( !f.open(IO_ReadOnly) ) { if ( mustExist ) fprintf( stderr, "lupdate error: cannot open UI file '%s': %s\n", fileName, strerror(errno) ); return; } QTextStream t( &f ); QXmlInputSource in( t ); QXmlSimpleReader reader; reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" "-only-CharData", FALSE ); QXmlDefaultHandler *hand = new UiHandler( tor, fileName ); reader.setContentHandler( hand ); reader.setErrorHandler( hand ); if ( !reader.parse(in) ) fprintf( stderr, "%s: Parse error in UI file\n", fileName ); reader.setContentHandler( 0 ); reader.setErrorHandler( 0 ); delete hand; f.close(); }
bool KDReports::Report::loadFromXML( QIODevice* iodevice, ErrorDetails* details ) { QDomDocument doc; // Read document from the QIODevice, check for errors // We need to be able to see the space in <text> </text>, this is why // we activate the "report-whitespace-only-CharData" feature. // Unfortunately this leads to lots of whitespace text nodes in between real // elements in the rest of the document, watch out for that. if (iodevice->isOpen()) iodevice->reset(); //need to do that to allow consecutive calls of loadFromXML() QXmlInputSource source( iodevice ); QXmlSimpleReader reader; reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespaces" ), false ); reader.setFeature( QLatin1String( "http://xml.org/sax/features/namespace-prefixes" ), true ); reader.setFeature( QLatin1String( "http://trolltech.com/xml/features/report-whitespace-only-CharData" ), true ); QString errorMsg; int errorLine = 0, errorColumn = 0; bool ret = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn ); if( !ret ) { if ( details ) { details->setLine( errorLine ); details->setColumn( errorColumn ); details->setDriverMessage( errorMsg ); } else qWarning( "Malformed XML read in KDReports::Report::loadFromXML(): error message = %s, error line = %d, error column = %d", qPrintable( errorMsg ), errorLine, errorColumn ); return false; } return loadFromXML( doc, details ); }
bool MetaTranslator::load( const QString& filename ) { QFile f( filename ); if ( !f.open(QIODevice::ReadOnly) ) return false; QXmlInputSource in( &f ); QXmlSimpleReader reader; reader.setFeature( "http://xml.org/sax/features/namespaces", false ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", true ); TsHandler *hand = new TsHandler( this ); reader.setContentHandler( static_cast<QXmlDefaultHandler*>(hand) ); reader.setErrorHandler( static_cast<QXmlDefaultHandler*>(hand) ); bool ok = reader.parse( in ); reader.setContentHandler( 0 ); reader.setErrorHandler( 0 ); m_language = hand->language(); makeFileNamesAbsolute(QFileInfo(filename).absoluteDir()); delete hand; f.close(); return ok; }
bool loadUI(Translator &translator, const QString &filename, ConversionData &cd) { cd.m_sourceFileName = filename; QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { cd.appendError(QString::fromLatin1("Cannot open %1: %2") .arg(filename, file.errorString())); return false; } QXmlInputSource in(&file); QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false); reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); reader.setFeature(QLatin1String( "http://trolltech.com/xml/features/report-whitespace-only-CharData"), false); UiReader handler(translator, cd); reader.setContentHandler(&handler); reader.setErrorHandler(&handler); bool result = reader.parse(in); if (!result) cd.appendError(QLatin1String("Parse error in UI file")); reader.setContentHandler(0); reader.setErrorHandler(0); return result; }
bool PhraseBook::load( const QString& filename ) { QFile f( filename ); if ( !f.open(IO_ReadOnly) ) return FALSE; QTextStream t( &f ); QXmlInputSource in( t ); QXmlSimpleReader reader; // don't click on these! reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" "-only-CharData", FALSE ); QXmlDefaultHandler *hand = new QphHandler( this ); reader.setContentHandler( hand ); reader.setErrorHandler( hand ); bool ok = reader.parse( in ); reader.setContentHandler( 0 ); reader.setErrorHandler( 0 ); delete hand; f.close(); if ( !ok ) clear(); return ok; }
int main( int argc, char **argv ) { QApplication app( argc, argv ); QFile xmlFile( argc == 2 ? argv[1] : "fnord.xml" ); QXmlInputSource source( &xmlFile ); QXmlSimpleReader reader; QGrid * container = new QGrid( 3 ); QListView * nameSpace = new QListView( container, "table_namespace" ); StructureParser * handler = new StructureParser( nameSpace ); reader.setContentHandler( handler ); reader.parse( source ); QListView * namespacePrefix = new QListView( container, "table_namespace_prefix" ); handler->setListView( namespacePrefix ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); source.reset(); reader.parse( source ); QListView * prefix = new QListView( container, "table_prefix"); handler->setListView( prefix ); reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); source.reset(); reader.parse( source ); // namespace label (void) new QLabel( "Default:\n" "http://xml.org/sax/features/namespaces: TRUE\n" "http://xml.org/sax/features/namespace-prefixes: FALSE\n", container ); // namespace prefix label (void) new QLabel( "\n" "http://xml.org/sax/features/namespaces: TRUE\n" "http://xml.org/sax/features/namespace-prefixes: TRUE\n", container ); // prefix label (void) new QLabel( "\n" "http://xml.org/sax/features/namespaces: FALSE\n" "http://xml.org/sax/features/namespace-prefixes: TRUE\n", container ); app.setMainWidget( container ); container->show(); return app.exec(); }
bool PhraseBook::load(const QString &fileName, bool *langGuessed) { QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) return false; m_fileName = fileName; QXmlInputSource in(&f); QXmlSimpleReader reader; // don't click on these! reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false); reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); reader.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace" "-only-CharData"), false); QphHandler *hand = new QphHandler(this); reader.setContentHandler(hand); reader.setErrorHandler(hand); bool ok = reader.parse(in); reader.setContentHandler(0); reader.setErrorHandler(0); Translator::languageAndCountry(hand->language(), &m_language, &m_country); *langGuessed = false; if (m_language == QLocale::C) { QLocale sys; m_language = sys.language(); m_country = sys.country(); *langGuessed = true; } QString lang = hand->sourceLanguage(); if (lang.isEmpty()) { m_sourceLanguage = QLocale::C; m_sourceCountry = QLocale::AnyCountry; } else { Translator::languageAndCountry(lang, &m_sourceLanguage, &m_sourceCountry); } delete hand; f.close(); if (!ok) { qDeleteAll(m_phrases); m_phrases.clear(); } else { emit listChanged(); } return ok; }
void Compiler::download() { FileProvider provider; QString fileName; if ( provider.get( Settings::self()->wsdlUrl(), fileName, Settings::self()->ignoreSslErrors() ) ) { QFile file( fileName ); if ( !file.open( QIODevice::ReadOnly ) ) { qDebug("Unable to download file %s", Settings::self()->wsdlUrl().toEncoded().constData()); provider.cleanUp(); QCoreApplication::exit( 1 ); return; } //qDebug() << "parsing" << fileName; QXmlInputSource source( &file ); QXmlSimpleReader reader; reader.setFeature( QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true ); QString errorMsg; int errorLine, errorCol; QDomDocument doc; if ( !doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorCol ) ) { qDebug( "%s at (%d,%d)", qPrintable( errorMsg ), errorLine, errorCol ); QCoreApplication::exit( 2 ); return; } parse( doc.documentElement() ); provider.cleanUp(); } }
bool AIMLParser::loadAiml(const QString &filename) { QDomDocument doc( "mydocument" ); QFile file( filename ); if ( !file.open( IO_ReadOnly ) ) return false; QXmlInputSource src(&file); QXmlSimpleReader reader; reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", true); QString msg; int line, col; if ( !doc.setContent( &src, &reader, &msg, &line, &col ) ) { file.close(); _logStream << QString("Error while parsing %1: %2 (line %3 - col %4)\n").arg(filename).arg(msg).arg(line).arg(col); return false; } file.close(); parseCategories(doc); return true; }
bool GpxFile::readFile(QString fname, bool pe) { GpxParser handler(*this); QFile file( fname ); QXmlInputSource source( &file ); QXmlSimpleReader reader; reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false); reader.setContentHandler( &handler ); reader.parse( source ); if (pe) purgeEmptyTracks(); return true; }
void fetchtr_ui( const char *fileName, MetaTranslator *tor, const char * /* defaultContext */, bool mustExist ) { QFile f( fileName ); if ( !f.open(QIODevice::ReadOnly) ) { if ( mustExist ) { #if defined(_MSC_VER) && _MSC_VER >= 1400 char buf[100]; strerror_s(buf, sizeof(buf), errno); fprintf( stderr, "pylupdate5 error: cannot open UI file '%s': %s\n", fileName, buf ); #else fprintf( stderr, "pylupdate5 error: cannot open UI file '%s': %s\n", fileName, strerror(errno) ); #endif } return; } QXmlInputSource in( &f ); QXmlSimpleReader reader; reader.setFeature( "http://xml.org/sax/features/namespaces", false ); reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", true ); reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" "-only-CharData", false ); QXmlDefaultHandler *hand = new UiHandler( tor, fileName ); reader.setContentHandler( hand ); reader.setErrorHandler( hand ); if ( !reader.parse(in) ) fprintf( stderr, "%s: Parse error in UI file\n", fileName ); reader.setContentHandler( 0 ); reader.setErrorHandler( 0 ); delete hand; f.close(); }
QDomDocument DocumentSource::asDomDocument() const { if (!d->parsed) { QXmlInputSource source; source.setData(d->array); QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), true); if (!d->domDoc.setContent(&source, &reader)) d->domDoc.clear(); d->parsed = true; } return d->domDoc; }
// currently unused bool Parser::parse( ParserContext *context, QXmlInputSource *source ) { QXmlSimpleReader reader; reader.setFeature( QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true ); QString errorMsg; int errorLine, errorCol; QDomDocument doc; if ( !doc.setContent( source, &reader, &errorMsg, &errorLine, &errorCol ) ) { qDebug( "%s at (%d,%d)", qPrintable( errorMsg ), errorLine, errorCol ); return false; } QDomElement element = doc.documentElement(); const QName name( element.tagName() ); if ( name.localName() != QLatin1String("schema") ) { qDebug( "document element is '%s'", qPrintable( element.tagName() ) ); return false; } return parseSchemaTag( context, element ); }
void XmlSync::load(QString path, quint32 order) { QFile structFile(path); QXmlSimpleReader simpleread; QXmlInputSource input; QDomDocument *xmlData; QDomElement *root; if(!structFile.open(QIODevice::ReadOnly | QIODevice::Text)) { fatalExit("Failed to open input file!"); } if (order == 0) //Input file { xmlData = &xmlData_in; root = &root_in; } else //Template file { xmlData = &xmlData_out; root = &root_out; } //Use QXmlSimpleReader to read document since the default kills whitespace nodes which are needed. simpleread.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData"), true); input.setData(structFile.readAll()); xmlData->setContent(&input, &simpleread); structFile.close(); // Get root *root = xmlData->documentElement(); if(root->isNull()) { fatalExit("Root of the input XML file was not detected!"); } }
void load( const QString& filename ) { QFile file( filename ); if ( !file.open( IO_ReadOnly ) ) { Console::instance()->send( tr( "Unable to open %1!\n" ).arg( filename ) ); return; } filenames.push_back( filename ); QXmlInputSource input( &file ); QXmlSimpleReader reader; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); reader.setContentHandler( this ); reader.setErrorHandler( this ); reader.parse( &input, false ); filenames.pop_back(); }
// Recursive Function for Importing Script Sections bool cDefinitions::ImportSections( const QString& FileName ) { QFile File( FileName ); if ( !File.open( IO_ReadOnly ) ) { Console::instance()->send( "Unable to open " ); Console::instance()->send( FileName ); Console::instance()->send( "!\n" ); return false; } QXmlInputSource input( &File ); QXmlSimpleReader reader; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); cXmlHandler handler( impl, FileName ); reader.setContentHandler( &handler ); reader.setErrorHandler( &handler ); reader.parse( &input, false ); File.close(); return true; }
void Main::UpdateList() { StructureList handler; handler.setIgnoreCase(m_IgnoreCase); handler.setIgnoreAccents(m_IgnoreAccents); AuxiliarGUI::m=this; int (*ptrFunction)(QString)=NULL; ptrFunction = lib2class; handler.setAddFunction(ptrFunction); QString search = ui.paraula->text(); handler.setWord(search); char letter; QString idioma; ui.llistat->show(); //prepare the path if (m_idioma_actiu == Auxiliar::eng2cat() ) { idioma="cateng"; } else { idioma="engcat"; } if (!isValidWord(search)) { ui.definicio->setPlainText(""); //not valid input* return; } letter=lletra_buscar(search); QFile xmlFile(m_directori_usuari+"/"+idioma+"/"+letter+".dic"); if (!xmlFile.exists()) { showError(tr("Cannot open dictionary file. Check configuration directory and permissions")); } else { Auxiliar::debug("File2: "+m_directori_usuari+"/"+idioma+"/"+letter+".dic"); QXmlInputSource source( &xmlFile ); QXmlSimpleReader reader; reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData",false); //if we don't use it, we get more entries because spaces... reader.setContentHandler(&handler); handler.setParaula(search); reader.parse(source); WordData d = handler.getWordData(); ui.definicio->setPlainText(""); ui.definicio->setPlainText(""); m_searched=search; selectItem(); } }
TestResult::Status TestBaseLine::verify(const QString &serializedInput) const { switch(m_type) { case SchemaIsValid: /* Fall through. */ case Text: { if(serializedInput == details()) return TestResult::Pass; else return TestResult::Fail; } case Fragment: /* Fall through. */ case XML: { /* Read the baseline and the serialized input into two QDomDocuments, and compare * them deeply. We wrap fragments in a root node such that it is well-formed XML. */ QDomDocument output; { /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that * QDomDocument does whitespace stripping when calling setContent(QString). In other words, * this workarounds a bug. */ QXmlInputSource source; source.setData((m_type == XML ? serializedInput : QLatin1String("<r>") + serializedInput + QLatin1String("</r>")).toUtf8()); QString outputReadingError; QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); const bool success = output.setContent(&source, &reader, &outputReadingError); if(!success) return TestResult::Fail; Q_ASSERT(success); } QDomDocument baseline; { QXmlInputSource source; source.setData((m_type == XML ? details() : QLatin1String("<r>") + details() + QLatin1String("</r>")).toUtf8()); QString baselineReadingError; QXmlSimpleReader reader; reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); const bool success = baseline.setContent(&source, &reader, &baselineReadingError); if(!success) return TestResult::Fail; /* This piece of code workaround a bug in QDom, which treats XML prologs as processing * instructions and make them available in the tree as so. */ if(m_type == XML) { /* $doc/r/node() */ const QDomNodeList children(baseline.childNodes()); const int len = children.length(); for(int i = 0; i < len; ++i) { const QDomNode &child = children.at(i); if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml")) { baseline.removeChild(child); break; } } } Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO, qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError))); } if(isDeepEqual(output, baseline)) return TestResult::Pass; else { pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString(); return TestResult::Fail; } } case Ignore: return TestResult::Pass; case Inspect: return TestResult::NotTested; case ExpectedError: { /* This function is only called for Text/XML/Fragment tests. */ return TestResult::Fail; } } Q_ASSERT(false); return TestResult::Fail; }
void XMLDocument::open(const QString &file) { EnumType::enums.clear(); filename = file; FieldFactory *fieldFactory = new FieldFactory; XMLParser parser(fieldFactory, file); ifstream test(file.toStdString().c_str(),ios::in); if (!test) { docType = "Plugin"; plugin = new Plugin("","","","","","", "", false, false, false, false); attribute = new Attribute("","",QString(),"","",""); plugin->atts = attribute; return; } else { test.close(); } try { QFile xmlFile(file); QXmlInputSource source(&xmlFile); QXmlSimpleReader reader; ErrorHandler errorhandler; reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", false); reader.setContentHandler(&parser); reader.setErrorHandler(&errorhandler); bool success = reader.parse(source); if (!success) { cerr << "Error parsing input file " << file.toStdString() << endl; exit(-1); } docType = parser.docType; plugin = parser.plugin; if (docType == "Attribute") attribute = parser.attribute; else { if (!plugin->atts) { plugin->atts = new Attribute(QString(),QString(),QString(),QString(),QString(),QString()); } attribute = plugin->atts; } #if !defined(_WIN32) struct stat s; stat(file.toStdString().c_str(), &s); if (!(s.st_mode & S_IWUSR)) { QMessageBox::warning(0,"Warning","File is not writable."); } if (attribute && attribute->codeFile) { stat(attribute->codeFile->FileName().toStdString().c_str(), &s); if (!(s.st_mode & S_IWUSR)) { QMessageBox::warning(0,"Warning","Code file is not writable."); } } #endif } catch (const char *s) { cerr << "ERROR: " << s << endl; exit(-1); } catch (const QString &s) { cerr << "ERROR: " << s.toStdString() << endl; exit(-1); } }
void ProcessFile(QString file) { QString docType; Plugin *plugin = NULL; Attribute *attribute = NULL; EnumType::enums.clear(); currentInputDir = ""; int lastslash = file.lastIndexOf("/"); if (lastslash < 0) lastslash = file.lastIndexOf("\\"); if (lastslash >= 0) currentInputDir = file.left(lastslash+1); FieldFactory *fieldFactory = new FieldFactory; XMLParser parser(fieldFactory, file); try { QFile xmlFile(file); QXmlInputSource source(&xmlFile); QXmlSimpleReader reader; ErrorHandler errorhandler; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false); reader.setContentHandler(&parser); reader.setErrorHandler(&errorhandler); reader.parse(source); docType = parser.docType; plugin = parser.plugin; if (docType == "Attribute") attribute = parser.attribute; else if(plugin != NULL) attribute = plugin->atts; } catch (const char *s) { cErr << "ERROR: " << s << Endl; Die(); } catch (const QString &s) { cErr << "ERROR: " << s.toStdString().c_str() << Endl; Die(); } if (docType.isNull()) { cErr << "Error in parsing " << file.toStdString().c_str() << Endl; Die(); } if (print) { cOut << "--------------------------------------------------------------" << "---" << Endl; cOut << " Parsed document of type " << docType << Endl; cOut << "--------------------------------------------------------------" << "---" << Endl; cOut << Endl; } // test mode try { if (print) { for (size_t i=0; i<EnumType::enums.size(); i++) { EnumType::enums[i]->Print(cOut); cOut << Endl; } if (docType == "Plugin") { if(plugin != NULL) plugin->Print(cOut); } else if (docType == "Attribute") { if(attribute != NULL) attribute->Print(cOut); } else { cErr << "Document type " << docType << "not supported" << Endl; Die(); } cOut << Endl; } CallGenerator(docType, attribute, plugin, file); cOut.flush(); cErr.flush(); delete attribute; delete plugin; } catch (const char *s) { cErr << "ERROR: " << s << Endl; Die(); } catch (const QString &s) { cErr << "ERROR: " << s << Endl; Die(); } }
void Main::treballaBuscar() { StructureParser handler; QString buscar = ui.paraula->text(); QString buscar_orig = ui.paraula->text(); char lletra; QString idioma; //per preparar el path if (m_idioma_actiu== Auxiliar::eng2cat() ) { idioma="cateng"; } else { idioma="engcat"; } if (!isValidWord(buscar)) { showError(tr("You have to write a word. The word has to start with a letter.")); ui.definicio->setPlainText(""); //not valid input } else { //TODO: clean this crazy if-else! lletra=lletra_buscar(buscar); QFile xmlFile(m_directori_usuari+"/"+idioma+"/"+lletra+".dic"); if (!xmlFile.exists()) { showError(tr("Cannot open dictionary file. Check configuration directory and permissions")); } else { Auxiliar::debug("File: "+m_directori_usuari+"/"+idioma+"/"+lletra+".dic"); QXmlInputSource source( &xmlFile ); QXmlSimpleReader reader; reader.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData",false); //if we don't use it, we get more entries because spaces... reader.setContentHandler( &handler ); handler.setParaula(buscar_orig); reader.parse(source); WordData d = handler.getWordData(); ui.definicio->setPlainText(""); if (d.getNum()!=0) { ui.definicio->show(); ui.llistat->hide(); QString definicio; for (int i=0;i<d.getNum();i++) { if (i==0) { definicio=d.getEntry(i); } else { definicio+="<BR><BR>"+d.getEntry(i); } } ui.definicio->setHtml(definicio); } else if (d.getNum()==0) { //No word found or buscar == 1: we show the list ui.definicio->setPlainText(""); ui.definicio->hide(); ui.llistat->show(); //loadList(&handler); m_searched=buscar_orig; selectItem(); if (d.getNum()==0) { showError(tr("Exact match not found")); } } m_numberFound=d.getNum(); } } }