diff --git a/mozilla/extensions/webservices/schema/src/nsSchemaAttributes.cpp b/mozilla/extensions/webservices/schema/src/nsSchemaAttributes.cpp index 112a2498313..b9aa4f8db61 100644 --- a/mozilla/extensions/webservices/schema/src/nsSchemaAttributes.cpp +++ b/mozilla/extensions/webservices/schema/src/nsSchemaAttributes.cpp @@ -196,8 +196,9 @@ nsSchemaAttribute::SetUse(PRUint16 aUse) // //////////////////////////////////////////////////////////// nsSchemaAttributeRef::nsSchemaAttributeRef(nsSchema* aSchema, - const nsAString& aRef) - : nsSchemaComponentBase(aSchema), mRef(aRef) + const nsAString& aRef, + const nsAString& aRefNS) + : nsSchemaComponentBase(aSchema), mRef(aRef), mRefNS(aRefNS) { } @@ -222,7 +223,16 @@ nsSchemaAttributeRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler) mIsResolved = PR_TRUE; if (!mAttribute && mSchema) { + if (mRefNS.IsEmpty()) { mSchema->GetAttributeByName(mRef, getter_AddRefs(mAttribute)); + } else { + // use the namespace and type + nsCOMPtr schemaColl; + mSchema->GetCollection(getter_AddRefs(schemaColl)); + NS_ENSURE_STATE(schemaColl); + + schemaColl->GetAttribute(mRef, mRefNS, getter_AddRefs(mAttribute)); + } } if (mAttribute) { @@ -474,8 +484,9 @@ nsSchemaAttributeGroup::AddAttribute(nsISchemaAttributeComponent* aAttribute) // //////////////////////////////////////////////////////////// nsSchemaAttributeGroupRef::nsSchemaAttributeGroupRef(nsSchema* aSchema, - const nsAString& aRef) - : nsSchemaComponentBase(aSchema), mRef(aRef) + const nsAString& aRef, + const nsAString& aRefNS) + : nsSchemaComponentBase(aSchema), mRef(aRef), mRefNS(aRefNS) { } @@ -499,7 +510,21 @@ nsSchemaAttributeGroupRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler) mIsResolved = PR_TRUE; if (!mAttributeGroup && mSchema) { + if (mRefNS.IsEmpty()) { mSchema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup)); + } else { + // use the namespace and type + nsCOMPtr schemaColl; + mSchema->GetCollection(getter_AddRefs(schemaColl)); + NS_ENSURE_STATE(schemaColl); + + // get the right schema + nsCOMPtr schema; + schemaColl->GetSchema(mRefNS, getter_AddRefs(schema)); + NS_ENSURE_STATE(schema); + + schema->GetAttributeGroupByName(mRef, getter_AddRefs(mAttributeGroup)); + } } if (mAttributeGroup) { diff --git a/mozilla/extensions/webservices/schema/src/nsSchemaLoader.cpp b/mozilla/extensions/webservices/schema/src/nsSchemaLoader.cpp index d00b6175c32..d2dd812532b 100644 --- a/mozilla/extensions/webservices/schema/src/nsSchemaLoader.cpp +++ b/mozilla/extensions/webservices/schema/src/nsSchemaLoader.cpp @@ -1015,32 +1015,9 @@ nsSchemaLoader::ProcessElement(nsIWebServiceErrorHandler* aErrorHandler, nsAutoString refNS; // need to handle ns:type - nsresult rv; - nsCOMPtr parserService = - do_GetService("@mozilla.org/parser/parser-service;1", &rv); + rv = ParseNameAndNS(ref, aElement, ref, refNS); NS_ENSURE_SUCCESS(rv, rv); - const nsAFlatString& qName = PromiseFlatString(ref); - const PRUnichar *colon; - rv = parserService->CheckQName(qName, PR_TRUE, &colon); - NS_ENSURE_SUCCESS(rv, rv); - - if (colon) { - const PRUnichar* end; - qName.EndReading(end); - - nsAutoString schemaTypePrefix; - schemaTypePrefix.Assign(Substring(qName.get(), colon)); - ref.Assign(Substring(colon + 1, end)); - - nsCOMPtr domNode3 = do_QueryInterface(aElement); - NS_ENSURE_STATE(domNode3); - - // get the namespace url from the prefix - rv = domNode3->LookupNamespaceURI(schemaTypePrefix, refNS); - NS_ENSURE_SUCCESS(rv, rv); - } - elementRef = new nsSchemaElementRef(aSchema, ref, refNS); if (!elementRef) { return NS_ERROR_OUT_OF_MEMORY; @@ -2584,13 +2561,18 @@ nsSchemaLoader::ProcessModelGroup(nsIWebServiceErrorHandler* aErrorHandler, GetMinAndMax(aElement, &minOccurs, &maxOccurs); // Check for a ref attribute - nsAutoString ref; + nsAutoString ref, refNS; aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref); if ((aTagName == nsSchemaAtoms::sModelGroup_atom) && !ref.IsEmpty()) { + + rv = ParseNameAndNS(ref, aElement, ref, refNS); + NS_ENSURE_SUCCESS(rv, rv); + nsSchemaModelGroupRef* modelGroupRef = new nsSchemaModelGroupRef(aSchema, - ref); + ref, + refNS); if (!modelGroupRef) { return NS_ERROR_OUT_OF_MEMORY; } @@ -2816,11 +2798,14 @@ nsSchemaLoader::ProcessAttribute(nsIWebServiceErrorHandler* aErrorHandler, PRUint16 use; GetUse(aElement, &use); - nsAutoString ref; + nsAutoString ref, refNS; aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref); if (!ref.IsEmpty()) { + rv = ParseNameAndNS(ref, aElement, ref, refNS); + NS_ENSURE_SUCCESS(rv, rv); + nsSchemaAttributeRef* attributeRef = new nsSchemaAttributeRef(aSchema, - ref); + ref, refNS); if (!attributeRef) { return NS_ERROR_OUT_OF_MEMORY; } @@ -2918,12 +2903,17 @@ nsSchemaLoader::ProcessAttributeGroup(nsIWebServiceErrorHandler* aErrorHandler, nsCOMPtr attributeGroup; - nsAutoString ref; + nsAutoString ref, refNS; aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref); if (!ref.IsEmpty()) { + // need to handle ns:type + rv = ParseNameAndNS(ref, aElement, ref, refNS); + NS_ENSURE_SUCCESS(rv, rv); + nsSchemaAttributeGroupRef* attrRef = new nsSchemaAttributeGroupRef(aSchema, - ref); + ref, + refNS); if (!attrRef) { return NS_ERROR_OUT_OF_MEMORY; } @@ -3202,3 +3192,35 @@ nsSchemaLoader::GetMinAndMax(nsIDOMElement* aElement, } } +nsresult +nsSchemaLoader::ParseNameAndNS(const nsAString& aName, nsIDOMElement* aElement, + nsAString& aTypeName, nsAString& aTypeNS) +{ + nsresult rv; + nsCOMPtr parserService = + do_GetService("@mozilla.org/parser/parser-service;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + + const nsAFlatString& qName = PromiseFlatString(aName); + const PRUnichar *colon; + rv = parserService->CheckQName(qName, PR_TRUE, &colon); + NS_ENSURE_SUCCESS(rv, rv); + + if (colon) { + const PRUnichar* end; + qName.EndReading(end); + + nsAutoString schemaTypePrefix; + schemaTypePrefix.Assign(Substring(qName.get(), colon)); + aTypeName.Assign(Substring(colon + 1, end)); + + nsCOMPtr domNode3 = do_QueryInterface(aElement); + NS_ENSURE_STATE(domNode3); + + // get the namespace url from the prefix + rv = domNode3->LookupNamespaceURI(schemaTypePrefix, aTypeNS); + NS_ENSURE_SUCCESS(rv, rv); + } + + return rv; +} diff --git a/mozilla/extensions/webservices/schema/src/nsSchemaLoader.h b/mozilla/extensions/webservices/schema/src/nsSchemaLoader.h index cae523a940d..c6c9a496de3 100644 --- a/mozilla/extensions/webservices/schema/src/nsSchemaLoader.h +++ b/mozilla/extensions/webservices/schema/src/nsSchemaLoader.h @@ -221,6 +221,9 @@ protected: void ConstructArrayName(nsISchemaType* aType, nsAString& aName); + nsresult ParseNameAndNS(const nsAString& aName, nsIDOMElement* aElement, + nsAString& aTypeName, nsAString& aTypeNS); + protected: nsInterfaceHashtable mSchemas; nsCOMPtr mBuiltinCollection; diff --git a/mozilla/extensions/webservices/schema/src/nsSchemaParticles.cpp b/mozilla/extensions/webservices/schema/src/nsSchemaParticles.cpp index 94a5cc4c24f..d2fcfc3daad 100644 --- a/mozilla/extensions/webservices/schema/src/nsSchemaParticles.cpp +++ b/mozilla/extensions/webservices/schema/src/nsSchemaParticles.cpp @@ -286,8 +286,9 @@ nsSchemaModelGroup::AddParticle(nsISchemaParticle* aParticle) // //////////////////////////////////////////////////////////// nsSchemaModelGroupRef::nsSchemaModelGroupRef(nsSchema* aSchema, - const nsAString& aRef) - : nsSchemaParticleBase(aSchema), mRef(aRef) + const nsAString& aRef, + const nsAString& aRefNS) + : nsSchemaParticleBase(aSchema), mRef(aRef), mRefNS(aRefNS) { } @@ -312,7 +313,21 @@ nsSchemaModelGroupRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler) mIsResolved = PR_TRUE; if (!mModelGroup && mSchema) { - mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup)); + if (mRefNS.IsEmpty()) { + mSchema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup)); + } else { + // use the namespace and type + nsCOMPtr schemaColl; + mSchema->GetCollection(getter_AddRefs(schemaColl)); + NS_ENSURE_STATE(schemaColl); + + // get the right schema + nsCOMPtr schema; + schemaColl->GetSchema(mRefNS, getter_AddRefs(schema)); + NS_ENSURE_STATE(schema); + + schema->GetModelGroupByName(mRef, getter_AddRefs(mModelGroup)); + } } if (mModelGroup) { diff --git a/mozilla/extensions/webservices/schema/src/nsSchemaPrivate.h b/mozilla/extensions/webservices/schema/src/nsSchemaPrivate.h index 21365ccc2d6..e8accfaa8c9 100644 --- a/mozilla/extensions/webservices/schema/src/nsSchemaPrivate.h +++ b/mozilla/extensions/webservices/schema/src/nsSchemaPrivate.h @@ -336,7 +336,8 @@ class nsSchemaModelGroupRef : public nsSchemaParticleBase, { public: nsSchemaModelGroupRef(nsSchema* aSchema, - const nsAString& aRef); + const nsAString& aRef, + const nsAString& aRefNS); virtual ~nsSchemaModelGroupRef(); NS_DECL_ISUPPORTS @@ -345,7 +346,7 @@ public: NS_DECL_NSISCHEMAMODELGROUP protected: - nsString mRef; + nsString mRef, mRefNS; nsCOMPtr mModelGroup; }; @@ -447,7 +448,8 @@ class nsSchemaAttributeRef : public nsSchemaComponentBase, public nsISchemaAttribute { public: - nsSchemaAttributeRef(nsSchema* aSchema, const nsAString& aRef); + nsSchemaAttributeRef(nsSchema* aSchema, const nsAString& aRef, + const nsAString& aRefNS); virtual ~nsSchemaAttributeRef(); NS_DECL_ISUPPORTS @@ -460,7 +462,7 @@ public: NS_IMETHOD SetUse(PRUint16 aUse); protected: - nsString mRef; + nsString mRef, mRefNS; nsCOMPtr mAttribute; nsString mDefaultValue; nsString mFixedValue; @@ -496,7 +498,8 @@ class nsSchemaAttributeGroupRef : public nsSchemaComponentBase, public nsISchemaAttributeGroup { public: - nsSchemaAttributeGroupRef(nsSchema* aSchema, const nsAString& aRef); + nsSchemaAttributeGroupRef(nsSchema* aSchema, const nsAString& aRef, + const nsAString& aRefNS); virtual ~nsSchemaAttributeGroupRef(); NS_DECL_ISUPPORTS @@ -505,7 +508,7 @@ public: NS_DECL_NSISCHEMAATTRIBUTEGROUP protected: - nsString mRef; + nsString mRef, mRefNS; nsCOMPtr mAttributeGroup; };