2006-07-13 18:21:53 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-07-13 18:21:53 +04:00
|
|
|
|
|
|
|
#include "txNodeSetAdaptor.h"
|
|
|
|
#include "txXPathTreeWalker.h"
|
|
|
|
|
|
|
|
txNodeSetAdaptor::txNodeSetAdaptor()
|
2008-11-01 03:52:06 +03:00
|
|
|
: txXPathObjectAdaptor(),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWritable(true)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
|
2008-11-01 03:52:06 +03:00
|
|
|
: txXPathObjectAdaptor(aNodeSet),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWritable(false)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
|
2006-07-13 18:21:53 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
txNodeSetAdaptor::Init()
|
|
|
|
{
|
2008-11-01 03:52:06 +03:00
|
|
|
if (!mValue) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mValue = new txNodeSet(nullptr);
|
2006-07-13 18:21:53 +04:00
|
|
|
}
|
|
|
|
|
2008-11-01 03:52:06 +03:00
|
|
|
return mValue ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2006-07-13 18:21:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2006-07-13 18:21:53 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex > (uint32_t)NodeSet()->size()) {
|
2006-07-13 18:21:53 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2008-11-01 03:52:06 +03:00
|
|
|
return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
|
2006-07-13 18:21:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex > (uint32_t)NodeSet()->size()) {
|
2006-07-13 18:21:53 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString result;
|
2008-11-01 03:52:06 +03:00
|
|
|
txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
|
2006-07-13 18:21:53 +04:00
|
|
|
|
2011-11-20 15:18:26 +04:00
|
|
|
*aResult = txDouble::toDouble(result);
|
2006-07-13 18:21:53 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex > (uint32_t)NodeSet()->size()) {
|
2006-07-13 18:21:53 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2008-11-01 03:52:06 +03:00
|
|
|
txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
|
2006-07-13 18:21:53 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
txNodeSetAdaptor::GetLength(uint32_t *aLength)
|
2006-07-13 18:21:53 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
*aLength = (uint32_t)NodeSet()->size();
|
2006-07-13 18:21:53 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
txNodeSetAdaptor::Add(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
|
|
|
|
|
2006-11-17 00:42:25 +03:00
|
|
|
nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
|
2011-10-17 18:59:28 +04:00
|
|
|
true));
|
2006-07-13 18:21:53 +04:00
|
|
|
|
2008-11-01 03:52:06 +03:00
|
|
|
return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
|
2006-07-13 18:21:53 +04:00
|
|
|
}
|