Bug 292634 - nsSchemaLoader does not handle ref=ns:type correctly. r/sr=peterv,a=mkaply

This commit is contained in:
doronr%us.ibm.com 2005-05-18 15:34:25 +00:00
Родитель f85d414669
Коммит 97da03d747
4 изменённых файлов: 48 добавлений и 7 удалений

Просмотреть файл

@ -54,6 +54,7 @@ REQUIRES = xpcom \
widget \
content \
js \
htmlparser \
necko \
xmlextras \
$(NULL)

Просмотреть файл

@ -52,6 +52,7 @@
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsNetUtil.h"
#include "nsIParserService.h"
// string includes
#include "nsReadableUtils.h"
@ -1008,8 +1009,36 @@ nsSchemaLoader::ProcessElement(nsIWebServiceErrorHandler* aErrorHandler,
aElement->GetAttribute(NS_LITERAL_STRING("ref"), ref);
if (!ref.IsEmpty()) {
nsSchemaElementRef* elementRef;
elementRef = new nsSchemaElementRef(aSchema, ref);
nsAutoString refNS;
// need to handle ns:type
nsresult rv;
nsCOMPtr<nsIParserService> parserService =
do_GetService("@mozilla.org/parser/parser-service;1", &rv);
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<nsIDOM3Node> 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;
}

Просмотреть файл

@ -673,8 +673,9 @@ nsSchemaElement::GetTargetNamespace(nsAString& aTargetNamespace)
//
////////////////////////////////////////////////////////////
nsSchemaElementRef::nsSchemaElementRef(nsSchema* aSchema,
const nsAString& aRef)
: nsSchemaParticleBase(aSchema), mRef(aRef)
const nsAString& aRef,
const nsAString& aRefNS)
: nsSchemaParticleBase(aSchema), mRef(aRef), mRefNS(aRefNS)
{
}
@ -682,7 +683,7 @@ nsSchemaElementRef::~nsSchemaElementRef()
{
}
NS_IMPL_ISUPPORTS3_CI(nsSchemaElementRef,
NS_IMPL_ISUPPORTS3_CI(nsSchemaElementRef,
nsISchemaComponent,
nsISchemaParticle,
nsISchemaElement)
@ -698,7 +699,16 @@ nsSchemaElementRef::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
mIsResolved = PR_TRUE;
if (!mElement && mSchema) {
mSchema->GetElementByName(mRef, getter_AddRefs(mElement));
if (mRefNS.IsEmpty()) {
mSchema->GetElementByName(mRef, getter_AddRefs(mElement));
} else {
// use the namespace and type
nsCOMPtr<nsISchemaCollection> schemaColl;
mSchema->GetCollection(getter_AddRefs(schemaColl));
NS_ENSURE_STATE(schemaColl);
schemaColl->GetElement(mRef, mRefNS, getter_AddRefs(mElement));
}
}
if (mElement) {

Просмотреть файл

@ -404,7 +404,7 @@ class nsSchemaElementRef : public nsSchemaParticleBase,
public nsISchemaElement
{
public:
nsSchemaElementRef(nsSchema* aSchema, const nsAString& aRef);
nsSchemaElementRef(nsSchema* aSchema, const nsAString& aRef, const nsAString& aRefNS);
virtual ~nsSchemaElementRef();
NS_DECL_ISUPPORTS
@ -414,6 +414,7 @@ public:
protected:
nsString mRef;
nsString mRefNS;
nsCOMPtr<nsISchemaElement> mElement;
};