Bug 663728, use ids of nodes in xml datasources, r=jonas

This commit is contained in:
Neil Deakin 2011-07-04 10:39:06 -04:00
Родитель 74aecf92be
Коммит 7618552aa5
10 изменённых файлов: 67 добавлений и 39 удалений

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

@ -51,8 +51,30 @@ NS_IMPL_ISUPPORTS1(nsXULTemplateResultXML, nsIXULTemplateResult)
nsXULTemplateResultXML::nsXULTemplateResultXML(nsXMLQuery* aQuery,
nsIDOMNode* aNode,
nsXMLBindingSet* aBindings)
: mId(++sTemplateId), mQuery(aQuery), mNode(aNode)
: mQuery(aQuery), mNode(aNode)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(mNode);
// If the node has an id, create the uri from it. Otherwise, there isn't
// anything to identify the node with so just use a somewhat random number.
nsCOMPtr<nsIAtom> id = content->GetID();
if (id) {
nsCOMPtr<nsIURI> uri = content->GetBaseURI();
nsCAutoString spec;
uri->GetSpec(spec);
mId = NS_ConvertUTF8toUTF16(spec);
nsAutoString idstr;
id->ToString(idstr);
mId += NS_LITERAL_STRING("#") + idstr;
}
else {
nsAutoString rowid(NS_LITERAL_STRING("row"));
rowid.AppendInt(++sTemplateId);
mId.Assign(rowid);
}
if (aBindings)
mRequiredValues.SetBindingSet(aBindings);
}
@ -97,9 +119,7 @@ nsXULTemplateResultXML::GetMayProcessChildren(PRBool* aMayProcessChildren)
NS_IMETHODIMP
nsXULTemplateResultXML::GetId(nsAString& aId)
{
nsAutoString rowid(NS_LITERAL_STRING("row"));
rowid.AppendInt(mId);
aId.Assign(rowid);
aId = mId;
return NS_OK;
}

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

@ -38,6 +38,7 @@
#define nsXULTemplateResultXML_h__
#include "nsCOMPtr.h"
#include "nsIURI.h"
#include "nsIRDFResource.h"
#include "nsXULTemplateQueryProcessorXML.h"
#include "nsIXULTemplateResult.h"
@ -62,8 +63,11 @@ public:
protected:
// result id
PRUint32 mId;
// ID used for persisting data. It is constructed using the mNode's
// base uri plus the node's id to form 'baseuri#id'. If the node has no
// id, then an id of the form 'row<some number>' is generated. In the
// latter case, persistence will not work as there won't be a unique id.
nsAutoString mId;
// query that generated the result
nsCOMPtr<nsXMLQuery> mQuery;

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

@ -1,15 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE zoo [
<!ATTLIST species id ID #REQUIRED>
]>
<zoo>
<class>
<name>Reptiles</name>
<species id="Chamaeleo chamaelon" name="Chameleon" specimens="2"/>
<species id="Chamaeleo-chamaelon" name="Chameleon" specimens="2"/>
</class>
<class>
<name>Birds</name>
<species id="Dromaius novaehollandiae" name="Emu" specimens="12"/>
<species id="Tyto alba" name="Barn Owl" specimens="4"/>
<species id="Corvus corax" name="Raven" specimens="0"/>
<species id="Dromaius-novaehollandiae" name="Emu" specimens="12"/>
<species id="Tyto-alba" name="Barn Owl" specimens="4"/>
<species id="Corvus-corax" name="Raven" specimens="0"/>
<location>Aviary</location>
</class>
</zoo>

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

@ -30,10 +30,10 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<button anyid="true" label="Chameleon 2"/>
<button anyid="true" label="Emu 12"/>
<button anyid="true" label="Barn Owl 4"/>
<button anyid="true" label="Raven 0"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" label="Chameleon 2"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" label="Emu 12"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" label="Barn Owl 4"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" label="Raven 0"/>
</output>;
var changes = [];

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

@ -30,19 +30,19 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<hbox anyid="true">
<hbox id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon">
<button label="Chameleon"/>
<label value="9"/>
</hbox>
<hbox anyid="true">
<hbox id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae">
<button label="Emu"/>
<label value="3"/>
</hbox>
<hbox anyid="true">
<hbox id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba">
<button label="Barn Owl"/>
<label value="8"/>
</hbox>
<hbox anyid="true">
<hbox id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax">
<button label="Raven"/>
<label value="5"/>
</hbox>

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

@ -30,10 +30,10 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<button anyid="true" label="Chameleon 2"/>
<button anyid="true" label="Emu 12"/>
<button anyid="true" label="Barn Owl 4"/>
<button anyid="true" label="Raven 0"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" label="Chameleon 2"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" label="Emu 12"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" label="Barn Owl 4"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" label="Raven 0"/>
</output>;
var changes = [];

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

@ -30,10 +30,10 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<button anyid="true" label="(Dromaius novaehollandiae) is a large bird"/>
<button anyid="true" label="(Tyto alba) Barn Owl"/>
<button anyid="true" label="(Corvus corax) Raven"/>
<label anyid="true" value="Chameleon"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" label="(Dromaius-novaehollandiae) is a large bird"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" label="(Tyto-alba) Barn Owl"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" label="(Corvus-corax) Raven"/>
<label id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" value="Chameleon"/>
</output>;
var changes = [];
@ -47,7 +47,7 @@ var changes = [];
<assign var="?id" expr="concat('(', @id, ')')"/>
</query>
<rule>
<where subject="?id" rel="equals" value="(Dromaius novaehollandiae)"/>
<where subject="?id" rel="equals" value="(Dromaius-novaehollandiae)"/>
<action>
<button uri="?" label="?id is a large bird"/>
</action>

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

@ -32,13 +32,13 @@ var expectedOutput =
<output>
<groupbox anyid="true" container="true" empty="false">
<caption label="Reptiles false"/>
<label anyid="true" value="Chameleon"/>
<label id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" value="Chameleon"/>
</groupbox>
<groupbox anyid="true" container="true" empty="false">
<caption label="Birds true"/>
<label anyid="true" value="Emu"/>
<label anyid="true" value="Barn Owl"/>
<label anyid="true" value="Raven"/>
<label id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" value="Emu"/>
<label id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" value="Barn Owl"/>
<label id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" value="Raven"/>
</groupbox>
</output>;

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

@ -30,10 +30,10 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<button anyid="true" label="Barn Owl"/>
<button anyid="true" label="Chameleon"/>
<button anyid="true" label="Emu"/>
<button anyid="true" label="Raven"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" label="Barn Owl"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" label="Chameleon"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" label="Emu"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" label="Raven"/>
</output>;
var changes = [];

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

@ -30,10 +30,10 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =
<output>
<button anyid="true" label="Barn Owl"/>
<button anyid="true" label="Emu"/>
<button anyid="true" label="Raven"/>
<button anyid="true" label="Chameleon"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Tyto-alba" label="Barn Owl"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Dromaius-novaehollandiae" label="Emu"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Corvus-corax" label="Raven"/>
<button id="chrome://mochitests/content/chrome/content/xul/templates/tests/chrome/animals.xml#Chamaeleo-chamaelon" label="Chameleon"/>
</output>;
var changes = [];