summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@nokia.com>2010-02-24 15:45:30 (GMT)
committerPeter Hartmann <peter.hartmann@nokia.com>2010-03-08 17:31:35 (GMT)
commitdb20aff5bf81a6a935fbb89bf103351dc7a9215d (patch)
tree0d70484af653ae0efaeda3cf445891399aa69b1e
parentd62f8e1e593acbb69b22ed4f941f2bebbb82dd14 (diff)
downloadQt-db20aff5bf81a6a935fbb89bf103351dc7a9215d.zip
Qt-db20aff5bf81a6a935fbb89bf103351dc7a9215d.tar.gz
Qt-db20aff5bf81a6a935fbb89bf103351dc7a9215d.tar.bz2
QXmlSchema internals: include/import/redefine schemas only once
According to the Schema standard, loading a schema needs only be done once for each schema location. Currently, there was a problem with indirect includes (and imports/redefines): a In this scenario, schema a would only remember to have loaded / \ b, but not d, which resulted in an error when c was loading d b c again and the types in d were redefined. | | d d Reviewed-by: Tobias Koenig <tokoe@kde.org> Task-number: QTBUG-8394
-rw-r--r--src/xmlpatterns/schema/qxsdschemaparser.cpp48
-rw-r--r--src/xmlpatterns/schema/qxsdschemaparser_p.h22
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-datatype.xsd6
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-import-a.xsd5
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-import-b.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-import-c.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-include-a.xsd5
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-include-b.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-include-c.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-redefine-a.xsd5
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-redefine-b.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/files/indirect-redefine-c.xsd4
-rw-r--r--tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp15
13 files changed, 124 insertions, 6 deletions
diff --git a/src/xmlpatterns/schema/qxsdschemaparser.cpp b/src/xmlpatterns/schema/qxsdschemaparser.cpp
index 6ed28af..fd0b95c 100644
--- a/src/xmlpatterns/schema/qxsdschemaparser.cpp
+++ b/src/xmlpatterns/schema/qxsdschemaparser.cpp
@@ -264,16 +264,31 @@ XsdSchemaParser::XsdSchemaParser(const XsdSchemaContext::Ptr &context, const Xsd
setupBuiltinTypeNames();
}
+void XsdSchemaParser::addIncludedSchemas(const NamespaceSet &schemas)
+{
+ m_includedSchemas += schemas;
+}
+
void XsdSchemaParser::setIncludedSchemas(const NamespaceSet &schemas)
{
m_includedSchemas = schemas;
}
+void XsdSchemaParser::addImportedSchemas(const NamespaceSet &schemas)
+{
+ m_importedSchemas += schemas;
+}
+
void XsdSchemaParser::setImportedSchemas(const NamespaceSet &schemas)
{
m_importedSchemas = schemas;
}
+void XsdSchemaParser::addRedefinedSchemas(const NamespaceSet &schemas)
+{
+ m_redefinedSchemas += schemas;
+}
+
void XsdSchemaParser::setRedefinedSchemas(const NamespaceSet &schemas)
{
m_redefinedSchemas = schemas;
@@ -297,6 +312,7 @@ void XsdSchemaParser::setDocumentURI(const QUrl &uri)
// prevent to get included/imported/redefined twice
m_includedSchemas.insert(uri);
m_importedSchemas.insert(uri);
+ m_redefinedSchemas.insert(uri);
}
QUrl XsdSchemaParser::documentURI() const
@@ -594,8 +610,14 @@ void XsdSchemaParser::parseInclude()
parser.setIncludedSchemas(m_includedSchemas);
parser.setImportedSchemas(m_importedSchemas);
parser.setRedefinedSchemas(m_redefinedSchemas);
- if (!parser.parse(XsdSchemaParser::IncludeParser))
+ if (!parser.parse(XsdSchemaParser::IncludeParser)) {
return;
+ } else {
+ // add indirectly loaded schemas to the list of already loaded ones
+ addIncludedSchemas(parser.m_includedSchemas);
+ addImportedSchemas(parser.m_importedSchemas);
+ addRedefinedSchemas(parser.m_redefinedSchemas);
+ }
}
}
@@ -684,8 +706,14 @@ void XsdSchemaParser::parseImport()
parser.setIncludedSchemas(m_includedSchemas);
parser.setImportedSchemas(m_importedSchemas);
parser.setRedefinedSchemas(m_redefinedSchemas);
- if (!parser.parse(XsdSchemaParser::ImportParser))
+ if (!parser.parse(XsdSchemaParser::ImportParser)) {
return;
+ } else {
+ // add indirectly loaded schemas to the list of already loaded ones
+ addIncludedSchemas(parser.m_includedSchemas);
+ addImportedSchemas(parser.m_importedSchemas);
+ addRedefinedSchemas(parser.m_redefinedSchemas);
+ }
}
}
} else {
@@ -702,8 +730,14 @@ void XsdSchemaParser::parseImport()
parser.setIncludedSchemas(m_includedSchemas);
parser.setImportedSchemas(m_importedSchemas);
parser.setRedefinedSchemas(m_redefinedSchemas);
- if (!parser.parse(XsdSchemaParser::ImportParser))
+ if (!parser.parse(XsdSchemaParser::ImportParser)) {
return;
+ } else {
+ // add indirectly loaded schemas to the list of already loaded ones
+ addIncludedSchemas(parser.m_includedSchemas);
+ addImportedSchemas(parser.m_importedSchemas);
+ addRedefinedSchemas(parser.m_redefinedSchemas);
+ }
}
}
} else {
@@ -839,8 +873,14 @@ void XsdSchemaParser::parseRedefine()
parser.setIncludedSchemas(m_includedSchemas);
parser.setImportedSchemas(m_importedSchemas);
parser.setRedefinedSchemas(m_redefinedSchemas);
- if (!parser.parse(XsdSchemaParser::RedefineParser))
+ if (!parser.parse(XsdSchemaParser::RedefineParser)) {
return;
+ } else {
+ // add indirectly loaded schemas to the list of already loaded ones
+ addIncludedSchemas(parser.m_includedSchemas);
+ addImportedSchemas(parser.m_importedSchemas);
+ addRedefinedSchemas(parser.m_redefinedSchemas);
+ }
delete reply;
}
diff --git a/src/xmlpatterns/schema/qxsdschemaparser_p.h b/src/xmlpatterns/schema/qxsdschemaparser_p.h
index ad5e9ce..80d44a5 100644
--- a/src/xmlpatterns/schema/qxsdschemaparser_p.h
+++ b/src/xmlpatterns/schema/qxsdschemaparser_p.h
@@ -120,20 +120,38 @@ namespace QPatternist
typedef QSet<QUrl> NamespaceSet;
/**
+ * Adds @p schemas to the list of already included schemas, so the parser
+ * can detect multiple includes of the same schema.
+ */
+ void addIncludedSchemas(const NamespaceSet &schemas);
+
+ /**
* Sets which @p schemas have been included already, so the parser
- * can detect circular includes.
+ * can detect multiple includes of the same schema.
*/
void setIncludedSchemas(const NamespaceSet &schemas);
/**
+ * Adds @p schemas to the list of already imported schemas, so the parser
+ * can detect multiple imports of the same schema.
+ */
+ void addImportedSchemas(const NamespaceSet &schemas);
+
+ /**
* Sets which @p schemas have been imported already, so the parser
* can detect circular imports.
*/
void setImportedSchemas(const NamespaceSet &schemas);
/**
+ * Adds @p schemas to the list of already redefined schemas, so the parser
+ * can detect multiple redefines of the same schema.
+ */
+ void addRedefinedSchemas(const NamespaceSet &schemas);
+
+ /**
* Sets which @p schemas have been redefined already, so the parser
- * can detect circular redefines.
+ * can detect multiple redefines of the same schema.
*/
void setRedefinedSchemas(const NamespaceSet &schemas);
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-datatype.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-datatype.xsd
new file mode 100644
index 0000000..60f3e4f
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-datatype.xsd
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:simpleType name="testType">
+ <xsd:list itemType="xsd:int" />
+ </xsd:simpleType>
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-import-a.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-import-a.xsd
new file mode 100644
index 0000000..e6da433
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-import-a.xsd
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:import schemaLocation="indirect-import-b.xsd" namespace="http://qt.nokia.com/test2" />
+ <xsd:import schemaLocation="indirect-import-c.xsd" namespace="http://qt.nokia.com/test2" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-import-b.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-import-b.xsd
new file mode 100644
index 0000000..88be377
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-import-b.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test2">
+ <xsd:import schemaLocation="indirect-datatype.xsd" namespace="http://qt.nokia.com/test" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-import-c.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-import-c.xsd
new file mode 100644
index 0000000..88be377
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-import-c.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test2">
+ <xsd:import schemaLocation="indirect-datatype.xsd" namespace="http://qt.nokia.com/test" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-include-a.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-include-a.xsd
new file mode 100644
index 0000000..02ca5c5
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-include-a.xsd
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:include schemaLocation="indirect-include-b.xsd" />
+ <xsd:include schemaLocation="indirect-include-c.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-include-b.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-include-b.xsd
new file mode 100644
index 0000000..efaba74
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-include-b.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:include schemaLocation="indirect-datatype.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-include-c.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-include-c.xsd
new file mode 100644
index 0000000..efaba74
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-include-c.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:include schemaLocation="indirect-datatype.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-redefine-a.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-a.xsd
new file mode 100644
index 0000000..4f0804c
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-a.xsd
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:redefine schemaLocation="indirect-redefine-b.xsd" />
+ <xsd:redefine schemaLocation="indirect-redefine-c.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-redefine-b.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-b.xsd
new file mode 100644
index 0000000..019a127
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-b.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:redefine schemaLocation="indirect-datatype.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/files/indirect-redefine-c.xsd b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-c.xsd
new file mode 100644
index 0000000..019a127
--- /dev/null
+++ b/tests/auto/xmlpatternsvalidator/files/indirect-redefine-c.xsd
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://qt.nokia.com/test" targetNamespace="http://qt.nokia.com/test">
+ <xsd:redefine schemaLocation="indirect-datatype.xsd" />
+</xsd:schema>
diff --git a/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp b/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
index 6d4ed69..7aab47f 100644
--- a/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
+++ b/tests/auto/xmlpatternsvalidator/tst_xmlpatternsvalidator.cpp
@@ -196,6 +196,21 @@ void tst_XmlPatternsValidator::xsdSupport_data() const
<< 1
<< (QStringList() << QLatin1String("files/instance.xml"))
<< QString();
+
+ QTest::newRow("A schema with an indirectly included type")
+ << 0
+ << (QStringList() << QLatin1String("files/indirect-include-a.xsd"))
+ << QString();
+
+ QTest::newRow("A schema with an indirectly imported type")
+ << 0
+ << (QStringList() << QLatin1String("files/indirect-import-a.xsd"))
+ << QString();
+
+ QTest::newRow("A schema with an indirectly redefined type")
+ << 0
+ << (QStringList() << QLatin1String("files/indirect-redefine-a.xsd"))
+ << QString();
}
QTEST_MAIN(tst_XmlPatternsValidator)