summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-09-17 12:50:31 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-09-21 15:04:42 (GMT)
commit79ef57eeb4585122c91093d9638bcbd0f4c3568c (patch)
tree85bae17f61b345aff1fbd2f8b60ed4066a5a2fcb /tools
parentdd3a5c4558cf9398b8560cd8cded3e51963990e9 (diff)
downloadQt-79ef57eeb4585122c91093d9638bcbd0f4c3568c.zip
Qt-79ef57eeb4585122c91093d9638bcbd0f4c3568c.tar.gz
Qt-79ef57eeb4585122c91093d9638bcbd0f4c3568c.tar.bz2
Letting the xmlpatternsvalidator tool properly handle relative paths
Since QXmlSchemaValidator resolves relative paths against the executable location, we use QUrl::fromLocalFile before passing them along. This is a more typical behavior for command-line applications and fixes the autotest. Reviewed-by: Frans Englich
Diffstat (limited to 'tools')
-rw-r--r--tools/xmlpatternsvalidator/main.cpp87
1 files changed, 42 insertions, 45 deletions
diff --git a/tools/xmlpatternsvalidator/main.cpp b/tools/xmlpatternsvalidator/main.cpp
index 2fbe176..eef8132 100644
--- a/tools/xmlpatternsvalidator/main.cpp
+++ b/tools/xmlpatternsvalidator/main.cpp
@@ -43,6 +43,7 @@
#include <QtCore/QDebug>
#include <QtCore/QFile>
+#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QtXmlPatterns/QXmlSchema>
#include <QtXmlPatterns/QXmlSchemaValidator>
@@ -62,14 +63,15 @@ int main(int argc, char **argv)
{
InvalidMode,
SchemaOnlyMode,
- SchemaAndInstanceMode,
- InstanceOnlyMode
+ InstanceOnlyMode,
+ SchemaAndInstanceMode
};
const QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName(QLatin1String("xmlpatternsvalidator"));
- if (argc != 2 && argc != 3) {
+ QStringList arguments = QCoreApplication::arguments();
+ if (arguments.size() != 2 && arguments.size() != 3) {
qDebug() << QXmlPatternistCLI::tr("usage: xmlpatternsvalidator (<schema url> | <instance url> <schema url> | <instance url>)");
return ParseError;
}
@@ -77,57 +79,52 @@ int main(int argc, char **argv)
// parse command line arguments
ExecutionMode mode = InvalidMode;
- if (argc == 2) {
- // either it is a schema or instance document
+ QUrl schemaUri;
+ QUrl instanceUri;
- QString url = QFile::decodeName(argv[1]);
- if (url.toLower().endsWith(QLatin1String(".xsd"))) {
- mode = SchemaOnlyMode;
- } else {
- // as we could validate all types of xml documents, don't check the extension here
- mode = InstanceOnlyMode;
+ {
+ QUrl url = arguments[1];
+
+ if (url.isRelative())
+ url = QUrl::fromLocalFile(arguments[1]);
+
+ if (arguments.size() == 2) {
+ // either it is a schema or instance document
+
+ if (arguments[1].toLower().endsWith(QLatin1String(".xsd"))) {
+ schemaUri = url;
+ mode = SchemaOnlyMode;
+ } else {
+ // as we could validate all types of xml documents, don't check the extension here
+ instanceUri = url;
+ mode = InstanceOnlyMode;
+ }
+ } else if (arguments.size() == 3) {
+ instanceUri = url;
+ schemaUri = arguments[2];
+
+ if (schemaUri.isRelative())
+ schemaUri = QUrl::fromLocalFile(schemaUri.toString());
+
+ mode = SchemaAndInstanceMode;
}
- } else if (argc == 3) {
- mode = SchemaAndInstanceMode;
}
- // do validation
+ // Validate schema
QXmlSchema schema;
-
- if (mode == SchemaOnlyMode) {
- const QString schemaUri = QFile::decodeName(argv[1]);
-
- schema.load(QUrl(schemaUri));
-
- if (schema.isValid())
- return Valid;
- else
- return Invalid;
- } else if (mode == SchemaAndInstanceMode) {
- const QString instanceUri = QFile::decodeName(argv[1]);
- const QString schemaUri = QFile::decodeName(argv[2]);
-
- schema.load(QUrl(schemaUri));
-
+ if (InstanceOnlyMode != mode) {
+ schema.load(schemaUri);
if (!schema.isValid())
return Invalid;
-
- QXmlSchemaValidator validator(schema);
- if (validator.validate(QUrl(instanceUri)))
- return Valid;
- else
- return Invalid;
- } else if (mode == InstanceOnlyMode) {
- const QString instanceUri = QFile::decodeName(argv[1]);
-
- QXmlSchemaValidator validator(schema);
- if (validator.validate(QUrl(instanceUri)))
- return Valid;
- else
- return Invalid;
}
- Q_ASSERT(false);
+ if (SchemaOnlyMode == mode)
+ return Valid;
+
+ // Validate instance
+ QXmlSchemaValidator validator(schema);
+ if (validator.validate(instanceUri))
+ return Valid;
return Invalid;
}