зеркало из https://github.com/mozilla/pjs.git
bug 239369, nsRDFXMLSerializer string do, check return values and copy less utf8<->utf16, r=bsmedberg, sr=darin
This commit is contained in:
Родитель
cadd94c8f8
Коммит
a842e48405
|
@ -60,6 +60,14 @@ nsNameSpaceMap::~nsNameSpaceMap()
|
|||
|
||||
nsresult
|
||||
nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix)
|
||||
{
|
||||
nsCString uriUTF8;
|
||||
AppendUTF16toUTF8(aURI, uriUTF8);
|
||||
return Put(uriUTF8, aPrefix);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNameSpaceMap::Put(const nsCSubstring& aURI, nsIAtom* aPrefix)
|
||||
{
|
||||
Entry* entry;
|
||||
|
||||
|
@ -79,7 +87,7 @@ nsNameSpaceMap::Put(const nsAString& aURI, nsIAtom* aPrefix)
|
|||
}
|
||||
|
||||
nsNameSpaceMap::const_iterator
|
||||
nsNameSpaceMap::GetNameSpaceOf(const nsAString& aURI) const
|
||||
nsNameSpaceMap::GetNameSpaceOf(const nsCSubstring& aURI) const
|
||||
{
|
||||
for (Entry* entry = mEntries; entry != nsnull; entry = entry->mNext) {
|
||||
if (StringBeginsWith(aURI, entry->mURI))
|
||||
|
|
|
@ -49,13 +49,13 @@ class nsNameSpaceMap
|
|||
public:
|
||||
class Entry {
|
||||
public:
|
||||
Entry(const nsAString& aURI, nsIAtom* aPrefix)
|
||||
Entry(const nsCSubstring& aURI, nsIAtom* aPrefix)
|
||||
: mURI(aURI), mPrefix(aPrefix), mNext(nsnull) {
|
||||
MOZ_COUNT_CTOR(nsNameSpaceMap::Entry); }
|
||||
|
||||
~Entry() { MOZ_COUNT_DTOR(nsNameSpaceMap::Entry); }
|
||||
|
||||
nsString mURI;
|
||||
nsCString mURI;
|
||||
nsCOMPtr<nsIAtom> mPrefix;
|
||||
|
||||
Entry* mNext;
|
||||
|
@ -67,6 +67,9 @@ public:
|
|||
nsresult
|
||||
Put(const nsAString& aURI, nsIAtom* aPrefix);
|
||||
|
||||
nsresult
|
||||
Put(const nsCSubstring& aURI, nsIAtom* aPrefix);
|
||||
|
||||
class const_iterator {
|
||||
protected:
|
||||
friend class nsNameSpaceMap;
|
||||
|
@ -118,7 +121,7 @@ public:
|
|||
const_iterator last() const {
|
||||
return const_iterator(nsnull); }
|
||||
|
||||
const_iterator GetNameSpaceOf(const nsAString& aURI) const;
|
||||
const_iterator GetNameSpaceOf(const nsCSubstring& aURI) const;
|
||||
|
||||
protected:
|
||||
Entry* mEntries;
|
||||
|
|
|
@ -1185,8 +1185,13 @@ RDFXMLDataSourceImpl::Serialize(nsIOutputStream* aStream)
|
|||
// Add any namespace information that we picked up when reading
|
||||
// the RDF/XML
|
||||
nsNameSpaceMap::const_iterator last = mNameSpaces.last();
|
||||
for (nsNameSpaceMap::const_iterator iter = mNameSpaces.first(); iter != last; ++iter)
|
||||
serializer->AddNameSpace(iter->mPrefix, iter->mURI);
|
||||
for (nsNameSpaceMap::const_iterator iter = mNameSpaces.first();
|
||||
iter != last; ++iter) {
|
||||
// We might wanna change nsIRDFXMLSerializer to nsACString and
|
||||
// use a heap allocated buffer here in the future.
|
||||
NS_ConvertUTF8toUTF16 uri(iter->mURI);
|
||||
serializer->AddNameSpace(iter->mPrefix, uri);
|
||||
}
|
||||
|
||||
// Serialize!
|
||||
nsCOMPtr<nsIRDFXMLSource> source = do_QueryInterface(serializer);
|
||||
|
|
|
@ -195,6 +195,12 @@ rdf_BlockingWrite(nsIOutputStream* stream, const char* buf, PRUint32 size)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
rdf_BlockingWrite(nsIOutputStream* stream, const nsCSubstring& s)
|
||||
{
|
||||
return rdf_BlockingWrite(stream, s.BeginReading(), s.Length());
|
||||
}
|
||||
|
||||
static nsresult
|
||||
rdf_BlockingWrite(nsIOutputStream* stream, const nsAString& s)
|
||||
{
|
||||
|
@ -209,18 +215,17 @@ rdf_BlockingWrite(nsIOutputStream* stream, const nsAString& s)
|
|||
|
||||
PRBool
|
||||
nsRDFXMLSerializer::MakeQName(nsIRDFResource* aResource,
|
||||
nsString& aProperty,
|
||||
nsString& aNameSpacePrefix,
|
||||
nsString& aNameSpaceURI)
|
||||
nsCString& aProperty,
|
||||
nsCString& aNameSpacePrefix,
|
||||
nsCString& aNameSpaceURI)
|
||||
{
|
||||
const char* s;
|
||||
aResource->GetValueConst(&s);
|
||||
NS_ConvertUTF8toUCS2 uri(s);
|
||||
nsCAutoString uri;
|
||||
aResource->GetValueUTF8(uri);
|
||||
|
||||
nsNameSpaceMap::const_iterator iter = mNameSpaces.GetNameSpaceOf(uri);
|
||||
if (iter != mNameSpaces.last()) {
|
||||
if (iter->mPrefix)
|
||||
iter->mPrefix->ToString(aNameSpacePrefix);
|
||||
iter->mPrefix->ToUTF8String(aNameSpacePrefix);
|
||||
else
|
||||
aNameSpacePrefix.Truncate();
|
||||
|
||||
|
@ -283,53 +288,81 @@ nsRDFXMLSerializer::IsContainerProperty(nsIRDFResource* aProperty)
|
|||
|
||||
|
||||
// convert '&', '<', and '>' into "&", "<", and ">", respectively.
|
||||
static const char amp[] = "&";
|
||||
static const char lt[] = "<";
|
||||
static const char gt[] = ">";
|
||||
static const char quot[] = """;
|
||||
|
||||
static void
|
||||
rdf_EscapeAmpersandsAndAngleBrackets(nsString& s)
|
||||
rdf_EscapeAmpersandsAndAngleBrackets(nsCString& s)
|
||||
{
|
||||
// XXX this could be re-written using the new string classes to
|
||||
// just scan the string once. Maybe we should add a
|
||||
// ReplaceSubstrings() function that accepts a list of
|
||||
// target/replace pairs, builds a state machine, blah blah
|
||||
// blah. I'm too lazy to do that now!
|
||||
PRInt32 i;
|
||||
PRUint32 newLength, origLength;
|
||||
newLength = origLength = s.Length();
|
||||
|
||||
// Do ampersands first, so we don't double-escape.
|
||||
i = 0;
|
||||
while ((i = s.FindChar('&', i)) != -1) {
|
||||
s.SetCharAt('&', i);
|
||||
s.Insert(NS_LITERAL_STRING("amp;"), i + 1);
|
||||
i += 4;
|
||||
// Compute the length of the result string.
|
||||
const char* start = s.BeginReading();
|
||||
const char* end = s.EndReading();
|
||||
const char* c = start;
|
||||
while (c != end) {
|
||||
switch (*c) {
|
||||
case '&' :
|
||||
newLength += sizeof(amp) - 2;
|
||||
break;
|
||||
case '<':
|
||||
case '>':
|
||||
newLength += sizeof(gt) - 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
}
|
||||
if (newLength == origLength) {
|
||||
// nothing to escape
|
||||
return;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while ((i = s.FindChar('<', i)) != -1) {
|
||||
s.SetCharAt('&', i);
|
||||
s.Insert(NS_LITERAL_STRING("lt;"), i + 1);
|
||||
i += 3;
|
||||
}
|
||||
// escape the chars from the end back to the front.
|
||||
s.SetLength(newLength);
|
||||
|
||||
i = 0;
|
||||
while ((i = s.FindChar('>', i)) != -1) {
|
||||
s.SetCharAt('&', i);
|
||||
s.Insert(NS_LITERAL_STRING("gt;"), i + 1);
|
||||
i += 3;
|
||||
// Buffer might have changed, get the pointers again
|
||||
start = s.BeginReading(); // begin of string
|
||||
c = start + origLength - 1; // last char in original string
|
||||
char* w = s.EndWriting() - 1; // last char in grown buffer
|
||||
while (c > start) {
|
||||
switch (*c) {
|
||||
case '&' :
|
||||
w -= 4;
|
||||
nsCharTraits<char>::copy(w, amp, sizeof(amp) - 1);
|
||||
break;
|
||||
case '<':
|
||||
w -= 3;
|
||||
nsCharTraits<char>::copy(w, lt, sizeof(lt) - 1);
|
||||
case '>':
|
||||
w -= 3;
|
||||
nsCharTraits<char>::copy(w, gt, sizeof(gt) - 1);
|
||||
break;
|
||||
default:
|
||||
*w = *c;
|
||||
}
|
||||
--w;
|
||||
--c;
|
||||
}
|
||||
}
|
||||
|
||||
// convert '"' to """
|
||||
static void
|
||||
rdf_EscapeQuotes(nsString& s)
|
||||
rdf_EscapeQuotes(nsCString& s)
|
||||
{
|
||||
PRInt32 i = 0;
|
||||
while ((i = s.FindChar('"', i)) != -1) {
|
||||
s.SetCharAt('&', i);
|
||||
s.Insert(NS_LITERAL_STRING("quot;"), i + 1);
|
||||
i += 5;
|
||||
s.Replace(i, 1, quot, sizeof(quot) - 1);
|
||||
i += sizeof(quot) - 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rdf_EscapeAttributeValue(nsString& s)
|
||||
rdf_EscapeAttributeValue(nsCString& s)
|
||||
{
|
||||
rdf_EscapeAmpersandsAndAngleBrackets(s);
|
||||
rdf_EscapeQuotes(s);
|
||||
|
@ -342,40 +375,45 @@ nsRDFXMLSerializer::SerializeInlineAssertion(nsIOutputStream* aStream,
|
|||
nsIRDFResource* aProperty,
|
||||
nsIRDFLiteral* aValue)
|
||||
{
|
||||
nsAutoString property, nameSpacePrefix, nameSpaceURI;
|
||||
nsAutoString attr;
|
||||
nsCAutoString property, nameSpacePrefix, nameSpaceURI;
|
||||
nsCAutoString attr;
|
||||
|
||||
PRBool wasDefinedAtGlobalScope =
|
||||
MakeQName(aProperty, property, nameSpacePrefix, nameSpaceURI);
|
||||
|
||||
if (nameSpacePrefix.Length()) {
|
||||
attr.Append(nameSpacePrefix);
|
||||
attr.Append(PRUnichar(':'));
|
||||
attr.Append(':');
|
||||
}
|
||||
attr.Append(property);
|
||||
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\n "));
|
||||
nsresult rv;
|
||||
rv = rdf_BlockingWrite(aStream,
|
||||
NS_LITERAL_CSTRING("\n "));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!wasDefinedAtGlobalScope && nameSpacePrefix.Length()) {
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("xmlns:"));
|
||||
rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("=\""));
|
||||
rdf_BlockingWrite(aStream, nameSpaceURI);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\" "));
|
||||
nsCAutoString nsutf8 =
|
||||
NS_LITERAL_CSTRING("xmlns:") +
|
||||
nameSpacePrefix +
|
||||
NS_LITERAL_CSTRING("=\"") +
|
||||
nameSpaceURI +
|
||||
NS_LITERAL_CSTRING("\" ");
|
||||
rv = rdf_BlockingWrite(aStream, nsutf8);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
const PRUnichar* value;
|
||||
aValue->GetValueConst(&value);
|
||||
nsAutoString s(value);
|
||||
NS_ConvertUTF16toUTF8 s(value);
|
||||
|
||||
rdf_EscapeAttributeValue(s);
|
||||
|
||||
rdf_BlockingWrite(aStream, attr);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("=\""));
|
||||
rdf_BlockingWrite(aStream, s);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\""));
|
||||
|
||||
return NS_OK;
|
||||
attr.AppendLiteral("=\"");
|
||||
rv = rdf_BlockingWrite(aStream, attr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
s.Append('"');
|
||||
return rdf_BlockingWrite(aStream, s);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -384,27 +422,31 @@ nsRDFXMLSerializer::SerializeChildAssertion(nsIOutputStream* aStream,
|
|||
nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aValue)
|
||||
{
|
||||
nsAutoString property, nameSpacePrefix, nameSpaceURI;
|
||||
nsAutoString tag;
|
||||
nsCAutoString property, nameSpacePrefix, nameSpaceURI;
|
||||
nsCAutoString tag;
|
||||
|
||||
PRBool wasDefinedAtGlobalScope =
|
||||
MakeQName(aProperty, property, nameSpacePrefix, nameSpaceURI);
|
||||
|
||||
if (nameSpacePrefix.Length()) {
|
||||
tag.Append(nameSpacePrefix);
|
||||
tag.Append(PRUnichar(':'));
|
||||
tag.Append(':');
|
||||
}
|
||||
tag.Append(property);
|
||||
|
||||
rdf_BlockingWrite(aStream, " <", 5);
|
||||
rdf_BlockingWrite(aStream, tag);
|
||||
nsresult rv = rdf_BlockingWrite(aStream, " <", 5);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, tag);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!wasDefinedAtGlobalScope && nameSpacePrefix.Length()) {
|
||||
rdf_BlockingWrite(aStream, " xmlns:", 7);
|
||||
rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
rdf_BlockingWrite(aStream, "=\"", 2);
|
||||
rdf_BlockingWrite(aStream, nameSpaceURI);
|
||||
rdf_BlockingWrite(aStream, "\"", 1);
|
||||
nsCAutoString out = NS_LITERAL_CSTRING(" xmlns:") +
|
||||
nameSpacePrefix +
|
||||
NS_LITERAL_CSTRING("=\"") +
|
||||
nameSpaceURI +
|
||||
NS_LITERAL_CSTRING("\"");
|
||||
rv = rdf_BlockingWrite(aStream, out);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFResource> resource;
|
||||
|
@ -413,39 +455,47 @@ nsRDFXMLSerializer::SerializeChildAssertion(nsIOutputStream* aStream,
|
|||
nsCOMPtr<nsIRDFDate> date;
|
||||
|
||||
if ((resource = do_QueryInterface(aValue)) != nsnull) {
|
||||
const char *s;
|
||||
resource->GetValueConst(&s);
|
||||
nsCAutoString uri;
|
||||
resource->GetValueUTF8(uri);
|
||||
|
||||
NS_ConvertUTF8toUTF16 uri(s);
|
||||
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mBaseURLSpec.get()), uri);
|
||||
rdf_MakeRelativeRef(mBaseURLSpec, uri);
|
||||
rdf_EscapeAttributeValue(uri);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFResource1, sizeof(kRDFResource1) - 1);
|
||||
rdf_BlockingWrite(aStream, uri);
|
||||
rdf_BlockingWrite(aStream, kRDFResource2, sizeof(kRDFResource2) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFResource1,
|
||||
sizeof(kRDFResource1) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, kRDFResource2,
|
||||
sizeof(kRDFResource2) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
goto no_close_tag;
|
||||
}
|
||||
else if ((literal = do_QueryInterface(aValue)) != nsnull) {
|
||||
const PRUnichar *value;
|
||||
literal->GetValueConst(&value);
|
||||
nsAutoString s(value);
|
||||
NS_ConvertUTF16toUTF8 s(value);
|
||||
|
||||
rdf_EscapeAmpersandsAndAngleBrackets(s);
|
||||
|
||||
rdf_BlockingWrite(aStream, ">", 1);
|
||||
rdf_BlockingWrite(aStream, s);
|
||||
rv = rdf_BlockingWrite(aStream, ">", 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else if ((number = do_QueryInterface(aValue)) != nsnull) {
|
||||
PRInt32 value;
|
||||
number->GetValue(&value);
|
||||
|
||||
nsAutoString n;
|
||||
nsCAutoString n;
|
||||
n.AppendInt(value);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFParseTypeInteger,
|
||||
sizeof(kRDFParseTypeInteger) - 1);
|
||||
rdf_BlockingWrite(aStream, n);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFParseTypeInteger,
|
||||
sizeof(kRDFParseTypeInteger) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, n);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else if ((date = do_QueryInterface(aValue)) != nsnull) {
|
||||
PRTime value;
|
||||
|
@ -454,21 +504,25 @@ nsRDFXMLSerializer::SerializeChildAssertion(nsIOutputStream* aStream,
|
|||
nsCAutoString s;
|
||||
rdf_FormatDate(value, s);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFParseTypeDate,
|
||||
sizeof(kRDFParseTypeDate) - 1);
|
||||
rdf_BlockingWrite(aStream, s.get(), s.Length());
|
||||
rv = rdf_BlockingWrite(aStream, kRDFParseTypeDate,
|
||||
sizeof(kRDFParseTypeDate) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
// XXX it doesn't support nsIRDFResource _or_ nsIRDFLiteral???
|
||||
// We should serialize nsIRDFInt, nsIRDFDate, etc...
|
||||
NS_WARNING("unknown RDF node type");
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFUnknown, sizeof(kRDFUnknown) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFUnknown, sizeof(kRDFUnknown) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, "</", 2);
|
||||
rdf_BlockingWrite(aStream, tag);
|
||||
rdf_BlockingWrite(aStream, ">\n", 2);
|
||||
rv = rdf_BlockingWrite(aStream, "</", 2);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
tag.AppendLiteral(">\n");
|
||||
return rdf_BlockingWrite(aStream, tag);
|
||||
|
||||
no_close_tag:
|
||||
return NS_OK;
|
||||
|
@ -551,7 +605,7 @@ nsRDFXMLSerializer::SerializeDescription(nsIOutputStream* aStream,
|
|||
nsresult rv;
|
||||
|
||||
PRBool isTypedNode = PR_FALSE;
|
||||
nsAutoString nodeName, nameSpacePrefix, nameSpaceURI;
|
||||
nsCAutoString nodeName, nameSpacePrefix, nameSpaceURI;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> typeNode;
|
||||
mDataSource->GetTarget(aResource, kRDF_type, PR_TRUE, getter_AddRefs(typeNode));
|
||||
|
@ -567,37 +621,43 @@ nsRDFXMLSerializer::SerializeDescription(nsIOutputStream* aStream,
|
|||
}
|
||||
}
|
||||
|
||||
const char* s;
|
||||
rv = aResource->GetValueConst(&s);
|
||||
nsCAutoString uri;
|
||||
rv = aResource->GetValueUTF8(uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ConvertUTF8toUTF16 uri(s);
|
||||
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mBaseURLSpec.get()), uri);
|
||||
rdf_MakeRelativeRef(mBaseURLSpec, uri);
|
||||
rdf_EscapeAttributeValue(uri);
|
||||
|
||||
// Emit an open tag and the subject
|
||||
if (isTypedNode) {
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(" <"));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_STRING(" <"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Watch out for the default namespace!
|
||||
if (!nameSpacePrefix.IsEmpty()) {
|
||||
rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(":"));
|
||||
nameSpacePrefix.Append(':');
|
||||
rv = rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rdf_BlockingWrite(aStream, nodeName);
|
||||
}
|
||||
else
|
||||
rdf_BlockingWrite(aStream, kRDFDescriptionOpen,
|
||||
sizeof(kRDFDescriptionOpen) - 1);
|
||||
if (uri[0] == PRUnichar('#')) {
|
||||
uri.Cut(0, 1);
|
||||
rdf_BlockingWrite(aStream, kIDAttr, sizeof(kIDAttr) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, nodeName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
rdf_BlockingWrite(aStream, kAboutAttr, sizeof(kAboutAttr) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFDescriptionOpen,
|
||||
sizeof(kRDFDescriptionOpen) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (uri[0] == PRUnichar('#')) {
|
||||
uri.Cut(0, 1);
|
||||
rv = rdf_BlockingWrite(aStream, kIDAttr, sizeof(kIDAttr) - 1);
|
||||
}
|
||||
else {
|
||||
rv = rdf_BlockingWrite(aStream, kAboutAttr, sizeof(kAboutAttr) - 1);
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rdf_BlockingWrite(aStream, uri);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\""));
|
||||
uri.Append('"');
|
||||
rv = rdf_BlockingWrite(aStream, uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Any value that's a literal we can write out as an inline
|
||||
// attribute on the RDF:Description
|
||||
|
@ -643,7 +703,8 @@ nsRDFXMLSerializer::SerializeDescription(nsIOutputStream* aStream,
|
|||
|
||||
if (skipped) {
|
||||
// Close the RDF:Description tag.
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(">\n"));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING(">\n"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Now write out resources (which might have their own
|
||||
// substructure) as children.
|
||||
|
@ -688,23 +749,29 @@ nsRDFXMLSerializer::SerializeDescription(nsIOutputStream* aStream,
|
|||
|
||||
// Emit a proper close-tag.
|
||||
if (isTypedNode) {
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(" </"));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING(" </"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Watch out for the default namespace!
|
||||
if (!nameSpacePrefix.IsEmpty()) {
|
||||
rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(":"));
|
||||
// ':' already appended above
|
||||
rv = rdf_BlockingWrite(aStream, nameSpacePrefix);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
nodeName.Append(">\n", 2);
|
||||
rdf_BlockingWrite(aStream, nodeName);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(">\n"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
rv = rdf_BlockingWrite(aStream, kRDFDescriptionClose,
|
||||
sizeof(kRDFDescriptionClose) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
rdf_BlockingWrite(aStream, kRDFDescriptionClose,
|
||||
sizeof(kRDFDescriptionClose) - 1);
|
||||
}
|
||||
else {
|
||||
// If we saw _no_ child properties, then we can don't need a
|
||||
// close-tag.
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(" />\n"));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING(" />\n"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -726,19 +793,25 @@ nsRDFXMLSerializer::SerializeMember(nsIOutputStream* aStream,
|
|||
nsCOMPtr<nsIRDFDate> date;
|
||||
|
||||
static const char kRDFLIOpen[] = " <RDF:li";
|
||||
rdf_BlockingWrite(aStream, kRDFLIOpen, sizeof(kRDFLIOpen) - 1);
|
||||
nsresult rv = rdf_BlockingWrite(aStream, kRDFLIOpen,
|
||||
sizeof(kRDFLIOpen) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if ((resource = do_QueryInterface(aMember)) != nsnull) {
|
||||
const char *s;
|
||||
resource->GetValueConst(&s);
|
||||
nsCAutoString uri;
|
||||
resource->GetValueUTF8(uri);
|
||||
|
||||
NS_ConvertUTF8toUTF16 uri(s);
|
||||
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mBaseURLSpec.get()), uri);
|
||||
rdf_MakeRelativeRef(mBaseURLSpec, uri);
|
||||
rdf_EscapeAttributeValue(uri);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFResource1, sizeof(kRDFResource1) - 1);
|
||||
rdf_BlockingWrite(aStream, uri);
|
||||
rdf_BlockingWrite(aStream, kRDFResource2, sizeof(kRDFResource2) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFResource1,
|
||||
sizeof(kRDFResource1) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, kRDFResource2,
|
||||
sizeof(kRDFResource2) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
goto no_close_tag;
|
||||
}
|
||||
|
@ -747,23 +820,28 @@ static const char kRDFLIOpen[] = " <RDF:li";
|
|||
literal->GetValueConst(&value);
|
||||
static const char kRDFLIOpenGT[] = ">";
|
||||
// close the '<RDF:LI' before adding the literal
|
||||
rdf_BlockingWrite(aStream, kRDFLIOpenGT, sizeof(kRDFLIOpenGT) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFLIOpenGT,
|
||||
sizeof(kRDFLIOpenGT) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString s(value);
|
||||
NS_ConvertUTF16toUTF8 s(value);
|
||||
rdf_EscapeAmpersandsAndAngleBrackets(s);
|
||||
|
||||
rdf_BlockingWrite(aStream, s);
|
||||
rv = rdf_BlockingWrite(aStream, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else if ((number = do_QueryInterface(aMember)) != nsnull) {
|
||||
PRInt32 value;
|
||||
number->GetValue(&value);
|
||||
|
||||
nsAutoString n;
|
||||
nsCAutoString n;
|
||||
n.AppendInt(value);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFParseTypeInteger,
|
||||
sizeof(kRDFParseTypeInteger) - 1);
|
||||
rdf_BlockingWrite(aStream, n);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFParseTypeInteger,
|
||||
sizeof(kRDFParseTypeInteger) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, n);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else if ((date = do_QueryInterface(aMember)) != nsnull) {
|
||||
PRTime value;
|
||||
|
@ -772,21 +850,25 @@ static const char kRDFLIOpenGT[] = ">";
|
|||
nsCAutoString s;
|
||||
rdf_FormatDate(value, s);
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFParseTypeDate,
|
||||
sizeof(kRDFParseTypeDate) - 1);
|
||||
rdf_BlockingWrite(aStream, s.get(), s.Length());
|
||||
rv = rdf_BlockingWrite(aStream, kRDFParseTypeDate,
|
||||
sizeof(kRDFParseTypeDate) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
// XXX it doesn't support nsIRDFResource _or_ nsIRDFLiteral???
|
||||
// We should serialize nsIRDFInt, nsIRDFDate, etc...
|
||||
NS_WARNING("unknown RDF node type");
|
||||
|
||||
rdf_BlockingWrite(aStream, kRDFUnknown, sizeof(kRDFUnknown) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFUnknown, sizeof(kRDFUnknown) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
{
|
||||
static const char kRDFLIClose[] = "</RDF:li>\n";
|
||||
rdf_BlockingWrite(aStream, kRDFLIClose, sizeof(kRDFLIClose) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kRDFLIClose, sizeof(kRDFLIClose) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
no_close_tag:
|
||||
|
@ -799,7 +881,7 @@ nsRDFXMLSerializer::SerializeContainer(nsIOutputStream* aStream,
|
|||
nsIRDFResource* aContainer)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoString tag;
|
||||
nsCAutoString tag;
|
||||
|
||||
// Decide if it's a sequence, bag, or alternation, and print the
|
||||
// appropriate tag-open sequence
|
||||
|
@ -818,8 +900,10 @@ nsRDFXMLSerializer::SerializeContainer(nsIOutputStream* aStream,
|
|||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, " <", 3);
|
||||
rdf_BlockingWrite(aStream, tag);
|
||||
rv = rdf_BlockingWrite(aStream, " <", 3);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, tag);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
// Unfortunately, we always need to print out the identity of the
|
||||
|
@ -827,32 +911,37 @@ nsRDFXMLSerializer::SerializeContainer(nsIOutputStream* aStream,
|
|||
// this because we never really know who else might be referring
|
||||
// to it...
|
||||
|
||||
const char *s;
|
||||
if (NS_SUCCEEDED(aContainer->GetValueConst(&s))) {
|
||||
NS_ConvertUTF8toUTF16 uri(s);
|
||||
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mBaseURLSpec.get()), uri);
|
||||
nsCAutoString uri;
|
||||
if (NS_SUCCEEDED(aContainer->GetValueUTF8(uri))) {
|
||||
rdf_MakeRelativeRef(mBaseURLSpec, uri);
|
||||
|
||||
rdf_EscapeAttributeValue(uri);
|
||||
|
||||
if (uri.First() == PRUnichar('#')) {
|
||||
if (uri.First() == '#') {
|
||||
// Okay, it's actually identified as an element in the
|
||||
// current document, not trying to decorate some absolute
|
||||
// URI. We can use the 'ID=' attribute...
|
||||
|
||||
uri.Cut(0, 1); // chop the '#'
|
||||
rdf_BlockingWrite(aStream, kIDAttr, sizeof(kIDAttr) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kIDAttr, sizeof(kIDAttr) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
// We need to cheat and spit out an illegal 'about=' on
|
||||
// the sequence.
|
||||
rdf_BlockingWrite(aStream, kAboutAttr, sizeof(kAboutAttr) - 1);
|
||||
rv = rdf_BlockingWrite(aStream, kAboutAttr,
|
||||
sizeof(kAboutAttr) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, uri);
|
||||
rdf_BlockingWrite(aStream, "\"", 1);
|
||||
rv = rdf_BlockingWrite(aStream, uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, "\"", 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, ">\n", 2);
|
||||
rv = rdf_BlockingWrite(aStream, ">\n", 2);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// First iterate through each of the ordinal elements (the RDF/XML
|
||||
// syntax doesn't allow us to place properties on RDF container
|
||||
|
@ -882,9 +971,11 @@ nsRDFXMLSerializer::SerializeContainer(nsIOutputStream* aStream,
|
|||
}
|
||||
|
||||
// close the container tag
|
||||
rdf_BlockingWrite(aStream, " </", 4);
|
||||
rdf_BlockingWrite(aStream, tag);
|
||||
rdf_BlockingWrite(aStream, ">\n", 2);
|
||||
rv = rdf_BlockingWrite(aStream, " </", 4);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
tag.Append(">\n", 2);
|
||||
rv = rdf_BlockingWrite(aStream, tag);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Now, we iterate through _all_ of the arcs, in case someone has
|
||||
// applied properties to the bag itself. These'll be placed in a
|
||||
|
@ -926,41 +1017,49 @@ nsRDFXMLSerializer::SerializePrologue(nsIOutputStream* aStream)
|
|||
{
|
||||
static const char kXMLVersion[] = "<?xml version=\"1.0\"?>\n";
|
||||
|
||||
rdf_BlockingWrite(aStream, kXMLVersion, sizeof(kXMLVersion) - 1);
|
||||
nsresult rv;
|
||||
rv = rdf_BlockingWrite(aStream, kXMLVersion, sizeof(kXMLVersion) - 1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// global name space declarations
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("<RDF:RDF "));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("<RDF:RDF "));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsNameSpaceMap::const_iterator first = mNameSpaces.first();
|
||||
nsNameSpaceMap::const_iterator last = mNameSpaces.last();
|
||||
for (nsNameSpaceMap::const_iterator entry = first; entry != last; ++entry) {
|
||||
if (entry != first)
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\n "));
|
||||
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("xmlns"));
|
||||
if (entry != first) {
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("\n "));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("xmlns"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (entry->mPrefix) {
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(":"));
|
||||
nsAutoString prefix;
|
||||
entry->mPrefix->ToString(prefix);
|
||||
rdf_BlockingWrite(aStream, prefix);
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING(":"));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCAutoString prefix;
|
||||
entry->mPrefix->ToUTF8String(prefix);
|
||||
rv = rdf_BlockingWrite(aStream, prefix);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("=\""));
|
||||
rdf_BlockingWrite(aStream, entry->mURI);
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("\""));
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("=\""));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, entry->mURI);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("\""));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING(">\n"));
|
||||
return NS_OK;
|
||||
return rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING(">\n"));
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsRDFXMLSerializer::SerializeEpilogue(nsIOutputStream* aStream)
|
||||
{
|
||||
rdf_BlockingWrite(aStream, NS_LITERAL_STRING("</RDF:RDF>\n"));
|
||||
return NS_OK;
|
||||
return rdf_BlockingWrite(aStream, NS_LITERAL_CSTRING("</RDF:RDF>\n"));
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1018,9 +1117,9 @@ nsRDFXMLSerializer::CollectNamespaces()
|
|||
nsresult
|
||||
nsRDFXMLSerializer::EnsureNameSpaceFor(nsIRDFResource* aResource)
|
||||
{
|
||||
nsAutoString property;
|
||||
nsAutoString nameSpacePrefix;
|
||||
nsAutoString nameSpaceURI;
|
||||
nsCAutoString property;
|
||||
nsCAutoString nameSpacePrefix;
|
||||
nsCAutoString nameSpaceURI;
|
||||
|
||||
if (! MakeQName(aResource, property, nameSpacePrefix, nameSpaceURI)) {
|
||||
#ifdef DEBUG_waterson
|
||||
|
|
|
@ -73,9 +73,9 @@ protected:
|
|||
// Implementation methods
|
||||
PRBool
|
||||
MakeQName(nsIRDFResource* aResource,
|
||||
nsString& aPproperty,
|
||||
nsString& aNameSpacePrefix,
|
||||
nsString& aNameSpaceURI);
|
||||
nsCString& aPproperty,
|
||||
nsCString& aNameSpacePrefix,
|
||||
nsCString& aNameSpaceURI);
|
||||
|
||||
nsresult
|
||||
SerializeInlineAssertion(nsIOutputStream* aStream,
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI)
|
||||
rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI)
|
||||
{
|
||||
// This implementation is extremely simple: e.g., it can't compute
|
||||
// relative paths, or anything fancy like that. If the context URI
|
||||
|
|
|
@ -62,7 +62,7 @@ class nsString;
|
|||
class nsIURI;
|
||||
|
||||
nsresult
|
||||
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI);
|
||||
rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI);
|
||||
|
||||
nsresult
|
||||
rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI);
|
||||
|
|
|
@ -42,6 +42,14 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
necko \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LIBRARY_NAME = rdfdsds
|
||||
IS_COMPONENT = 1
|
||||
|
||||
|
|
|
@ -37,13 +37,13 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFRemoteDataSource.h"
|
||||
#include "rdf.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -56,79 +56,56 @@
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RDF vocabulary describing assertions in inner datasource
|
||||
*
|
||||
* For a particular resource, we want to provide all arcs out and
|
||||
* in that the inner datasource has.
|
||||
* This is done by introducing helper resources for each triple of
|
||||
* the form
|
||||
* x-moz-dsds:<subject-resource-pointer><predicate-resource-pointer>\
|
||||
* <object-node-pointer>
|
||||
* For each triple, that has the resource in question as subject, a
|
||||
* "arcsout" assertion goes from that resource to a x-moz-dsds resource.
|
||||
* For each triple, that has the resource in question as object, a
|
||||
* "arcsin" assertion goes from that resource to a x-moz-dsds resource.
|
||||
* For each x-moz-dsds resource, there is a "subject" arc to the subject,
|
||||
* a "predicate" arc to the predicate and a "object" arc to the object.
|
||||
*
|
||||
* The namespace of this vocabulary is
|
||||
* "http://www.mozilla.org/rdf/vocab/dsds".
|
||||
*
|
||||
* XXX we might want to add a "qname" resource from each resource to a
|
||||
* somewhat canonical "prefix:localname" literal.
|
||||
*/
|
||||
|
||||
#define NS_RDF_DSDS_NAMESPACE_URI "http://www.mozilla.org/rdf/vocab/dsds#"
|
||||
#define NS_RDF_ARCSOUT NS_RDF_DSDS_NAMESPACE_URI "arcsout"
|
||||
#define NS_RDF_ARCSIN NS_RDF_DSDS_NAMESPACE_URI "arcsin"
|
||||
#define NS_RDF_SUBJECT NS_RDF_DSDS_NAMESPACE_URI "subject"
|
||||
#define NS_RDF_PREDICATE NS_RDF_DSDS_NAMESPACE_URI "predicate"
|
||||
#define NS_RDF_OBJECT NS_RDF_DSDS_NAMESPACE_URI "object"
|
||||
|
||||
#define NC_RDF_Name NC_NAMESPACE_URI "Name"
|
||||
#define NC_RDF_Value NC_NAMESPACE_URI "Value"
|
||||
#define NC_RDF_Child NC_NAMESPACE_URI "child"
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
class nsRDFDataSourceDataSource : public nsIRDFDataSource {
|
||||
class nsRDFDataSourceDataSource :
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
|
||||
nsRDFDataSourceDataSource();
|
||||
virtual ~nsRDFDataSourceDataSource();
|
||||
|
||||
/* void Init (in string uri); */
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
|
||||
/* readonly attribute string URI; */
|
||||
NS_IMETHOD GetURI(char * *aURI);
|
||||
|
||||
/* nsIRDFResource GetSource (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFResource **_retval);
|
||||
|
||||
/* nsISimpleEnumerator GetSources (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsISimpleEnumerator **_retval);
|
||||
|
||||
/* nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval);
|
||||
|
||||
/* nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval);
|
||||
|
||||
/* void Assert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD Assert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue);
|
||||
|
||||
/* void Unassert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget); */
|
||||
NS_IMETHOD Unassert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget);
|
||||
|
||||
/* boolean HasAssertion (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, PRBool *_retval);
|
||||
|
||||
/* void AddObserver (in nsIRDFObserver aObserver); */
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *aObserver);
|
||||
|
||||
/* void RemoveObserver (in nsIRDFObserver aObserver); */
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *aObserver);
|
||||
|
||||
/* nsISimpleEnumerator ArcLabelsIn (in nsIRDFNode aNode); */
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *aNode, nsISimpleEnumerator **_retval);
|
||||
|
||||
/* nsISimpleEnumerator ArcLabelsOut (in nsIRDFResource aSource); */
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval);
|
||||
|
||||
/* nsISimpleEnumerator GetAllResources (); */
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator **_retval);
|
||||
|
||||
/* void Flush (); */
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
/* boolean IsCommandEnabled (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments); */
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray * aSources, nsIRDFResource *aCommand, nsISupportsArray * aArguments, PRBool *_retval);
|
||||
|
||||
/* void DoCommand (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments); */
|
||||
NS_IMETHOD DoCommand(nsISupportsArray * aSources, nsIRDFResource *aCommand, nsISupportsArray * aArguments);
|
||||
|
||||
/* void beginUpdateBatch (); */
|
||||
NS_IMETHOD BeginUpdateBatch();
|
||||
|
||||
/* void endUpdateBatch (); */
|
||||
NS_IMETHOD EndUpdateBatch();
|
||||
|
||||
private:
|
||||
char *mURI;
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsCString mURI;
|
||||
nsCOMPtr<nsIRDFDataSource> mDataSource;
|
||||
|
||||
static nsIRDFResource* kNC_Name;
|
||||
static nsIRDFResource* kNC_Value;
|
||||
|
@ -141,19 +118,34 @@ nsIRDFResource* nsRDFDataSourceDataSource::kNC_Value=nsnull;
|
|||
nsIRDFResource* nsRDFDataSourceDataSource::kNC_Child=nsnull;
|
||||
|
||||
|
||||
nsRDFDataSourceDataSource::nsRDFDataSourceDataSource():
|
||||
mURI(nsnull),
|
||||
mDataSource(nsnull)
|
||||
nsRDFDataSourceDataSource::nsRDFDataSourceDataSource()
|
||||
{
|
||||
}
|
||||
|
||||
nsRDFDataSourceDataSource::~nsRDFDataSourceDataSource()
|
||||
{
|
||||
nsCRT::free(mURI);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsRDFDataSourceDataSource, nsIRDFDataSource)
|
||||
NS_IMPL_ISUPPORTS2(nsRDFDataSourceDataSource,
|
||||
nsIRDFDataSource,
|
||||
nsIRDFRemoteDataSource)
|
||||
|
||||
/**
|
||||
* Implement nsIRDFRemoteDataSource
|
||||
*/
|
||||
|
||||
/* readonly attribute boolean loaded; */
|
||||
NS_IMETHODIMP nsRDFDataSourceDataSource::GetLoaded(PRBool *aLoaded)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote =
|
||||
do_QueryInterface(mDataSource);
|
||||
if (remote) {
|
||||
return remote->GetLoaded(aLoaded);
|
||||
}
|
||||
*aLoaded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void Init (in string uri); */
|
||||
NS_IMETHODIMP
|
||||
|
@ -161,16 +153,31 @@ nsRDFDataSourceDataSource::Init(const char *uri)
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mURI) nsCRT::free(mURI);
|
||||
mURI = nsCRT::strdup(uri);
|
||||
mURI = uri;
|
||||
|
||||
// cut off "rdf:datasource?"
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "rdf:datasource");
|
||||
nsCAutoString mInnerURI;
|
||||
mInnerURI = Substring(mURI, prefix.Length() + 1);
|
||||
// bail if datasorce is empty or we're trying to inspect ourself
|
||||
if (mInnerURI.IsEmpty() || mInnerURI == prefix) {
|
||||
mURI.Truncate();
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
nsCOMPtr<nsIRDFService> rdf(do_GetService(kRDFServiceCID, &rv));
|
||||
rv = rdf->GetDataSource(mInnerURI.get(), getter_AddRefs(mDataSource));
|
||||
if (NS_FAILED(rv)) {
|
||||
mURI.Truncate();
|
||||
NS_WARNING("Could not get inner datasource");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// get RDF resources
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdf(do_GetService(kRDFServiceCID, &rv));
|
||||
if (!kNC_Name) {
|
||||
rdf->GetResource(NC_RDF_Name, &kNC_Name);
|
||||
rdf->GetResource(NC_RDF_Child, &kNC_Child);
|
||||
rdf->GetResource(NC_RDF_Value, &kNC_Value);
|
||||
rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_Name), &kNC_Name);
|
||||
rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_Child), &kNC_Child);
|
||||
rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_Value), &kNC_Value);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_alecf
|
||||
|
@ -180,6 +187,33 @@ nsRDFDataSourceDataSource::Init(const char *uri)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void Refresh (in boolean aBlocking); */
|
||||
NS_IMETHODIMP nsRDFDataSourceDataSource::Refresh(PRBool aBlocking)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote =
|
||||
do_QueryInterface(mDataSource);
|
||||
if (remote) {
|
||||
return remote->Refresh(aBlocking);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void Flush (); */
|
||||
NS_IMETHODIMP nsRDFDataSourceDataSource::Flush()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* void FlushTo (in string aURI); */
|
||||
NS_IMETHODIMP nsRDFDataSourceDataSource::FlushTo(const char *aURI)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement nsIRDFDataSource
|
||||
*/
|
||||
|
||||
/* readonly attribute string URI; */
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataSourceDataSource::GetURI(char * *aURI)
|
||||
|
@ -187,7 +221,7 @@ nsRDFDataSourceDataSource::GetURI(char * *aURI)
|
|||
#ifdef DEBUG_alecf
|
||||
printf("nsRDFDataSourceDataSource::GetURI()\n");
|
||||
#endif
|
||||
*aURI = nsCRT::strdup(mURI);
|
||||
*aURI = ToNewCString(mURI);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -238,11 +272,11 @@ nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource,
|
|||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator **_retval)
|
||||
{
|
||||
#ifdef DEBUG_alecf
|
||||
nsXPIDLCString sourceval;
|
||||
nsXPIDLCString propval;
|
||||
aSource->GetValue(getter_Copies(sourceval));
|
||||
nsXPIDLCString propval;
|
||||
aProperty->GetValue(getter_Copies(propval));
|
||||
#ifdef DEBUG_alecf
|
||||
printf("GetTargets(%s, %s,..)\n", (const char*)sourceval,
|
||||
(const char*)propval);
|
||||
#endif
|
||||
|
@ -252,21 +286,22 @@ nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource,
|
|||
nsCOMPtr<nsISupportsArray> arcs;
|
||||
nsISimpleEnumerator *enumerator;
|
||||
|
||||
if (NS_SUCCEEDED(aProperty.EqualsResource(kNC_Child, &isProp)) &&
|
||||
if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Child, &isProp)) &&
|
||||
isProp) {
|
||||
|
||||
// here we need to determine if we need to extract out the source
|
||||
// or use aSource?
|
||||
if (!PL_strcmp(sourceval, "dsresource:", 11)) {
|
||||
if (StringBeginsWith(sourceval, NS_LITERAL_CSTRING("dsresource:"))) {
|
||||
// somehow get the source
|
||||
rv = mDataSource->ArcLabelsOut(realsource, &enumerator);
|
||||
// XXX ? rv = mDataSource->ArcLabelsOut(realsource, &enumerator);
|
||||
rv = mDataSource->ArcLabelsOut(aSource, &enumerator);
|
||||
} else {
|
||||
rv = mDataSource->ArcLabelsOut(aSource, &enumerator);
|
||||
}
|
||||
// enumerate all the children and create the composite resources
|
||||
PRBool hasMoreArcs=PR_FALSE;
|
||||
|
||||
rv = enumerator->hasMoreElements(&hasMoreArcs);
|
||||
rv = enumerator->HasMoreElements(&hasMoreArcs);
|
||||
while (NS_SUCCEEDED(rv) && hasMoreArcs) {
|
||||
|
||||
// get the next arc
|
||||
|
@ -276,11 +311,11 @@ nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource,
|
|||
|
||||
// get all the resources on the ends of the arc arcs
|
||||
nsCOMPtr<nsISimpleEnumerator> targetEnumerator;
|
||||
rv = mDataSource->GetTargets(aSource, element, PR_TRUE,
|
||||
rv = mDataSource->GetTargets(aSource, arc, PR_TRUE,
|
||||
getter_AddRefs(targetEnumerator));
|
||||
|
||||
PRBool hasMoreTargets;
|
||||
rv = targetEnumerator->hasMoreElements(&hasMoreTargets);
|
||||
rv = targetEnumerator->HasMoreElements(&hasMoreTargets);
|
||||
while (NS_SUCCEEDED(rv) && hasMoreTargets) {
|
||||
// get the next target
|
||||
nsCOMPtr<nsISupports> targetSupports;
|
||||
|
@ -302,19 +337,17 @@ nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource,
|
|||
|
||||
}
|
||||
|
||||
rv = enumerator->hasMoreElements(&hasMoreArcs);
|
||||
rv = enumerator->HasMoreElements(&hasMoreArcs);
|
||||
}
|
||||
|
||||
nsIRDFResource *res = CreateCompositeResource(aSource, aProperty);
|
||||
|
||||
} else if (NS_SUCCEEDED(aProperty.EqualsResource(kNC_Name, &isProp)) &&
|
||||
} else if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Name, &isProp)) &&
|
||||
isProp) {
|
||||
if (!PL_strncmp(sourceval, "dsresource:", 11) {
|
||||
if (StringBeginsWith(sourceval, NS_LITERAL_CSTRING("dsresource:"))) {
|
||||
// extract out the name
|
||||
|
||||
}
|
||||
|
||||
} else if (NS_SUCCEEDED(aProperty.EqualsResource(kNC_Value, &isProp)) &&
|
||||
} else if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Value, &isProp)) &&
|
||||
isProp) {
|
||||
|
||||
|
||||
|
@ -394,24 +427,9 @@ nsRDFDataSourceDataSource::ArcLabelsOut(nsIRDFResource *aSource,
|
|||
printf("ArcLabelsOut(%s)\n", (const char*)sourceval);
|
||||
#endif
|
||||
|
||||
// this is a terrible ugly hack, but it works.
|
||||
// set the datasource if the URI begins with rdf:
|
||||
if (!PL_strncmp((const char*)sourceval, "rdf:", 4)) {
|
||||
#ifdef DEBUG_alecf
|
||||
printf("Ahah! This is a datasource node. Setting the datasource..");
|
||||
#endif
|
||||
nsCOMPtr<nsIRDFService> rdf(do_GetService(kRDFServiceCID, &rv));
|
||||
rv = rdf->GetDataSource((const char*)sourceval, &mDataSource);
|
||||
|
||||
#ifdef DEBUG_alecf
|
||||
printf("done.\n");
|
||||
#endif
|
||||
|
||||
} else {
|
||||
arcs->AppendElement(kNC_Name);
|
||||
arcs->AppendElement(kNC_Value);
|
||||
arcs->AppendElement(kNC_Child);
|
||||
}
|
||||
arcs->AppendElement(kNC_Name);
|
||||
arcs->AppendElement(kNC_Value);
|
||||
arcs->AppendElement(kNC_Child);
|
||||
|
||||
nsArrayEnumerator* cursor =
|
||||
new nsArrayEnumerator(arcs);
|
||||
|
@ -431,13 +449,6 @@ nsRDFDataSourceDataSource::GetAllResources(nsISimpleEnumerator **_retval)
|
|||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
/* void Flush (); */
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataSourceDataSource::Flush()
|
||||
{
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
/* boolean IsCommandEnabled (in nsISupportsArray aSources, in nsIRDFResource aCommand, in nsISupportsArray aArguments); */
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataSourceDataSource::IsCommandEnabled(nsISupportsArray * aSources, nsIRDFResource *aCommand, nsISupportsArray * aArguments, PRBool *_retval)
|
||||
|
|
Загрузка…
Ссылка в новой задаче