Esempio n. 1
0
XMLSize_t DOMXPathResultImpl::getSnapshotLength() const
{
    if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
        return fSnapshot->size();
    else
        throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 2
0
bool DOMXPathResultImpl::snapshotItem(XMLSize_t index)
{
    if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
    {
        fIndex = index;
        return fIndex < fSnapshot->size();
    }
    else
      throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
DOMXPathExpressionImpl::DOMXPathExpressionImpl(const XMLCh *expression, const DOMXPathNSResolver *resolver, MemoryManager* const manager) :
 fStringPool(NULL),
 fParsedExpression(NULL),
 fExpression(NULL),
 fMoveToRoot(false),
 fMemoryManager(manager)
{
    if(expression==NULL || *expression==0)
        throw DOMXPathException(DOMXPathException::INVALID_EXPRESSION_ERR, 0, fMemoryManager);

    CleanupType cleanup(this, &DOMXPathExpressionImpl::cleanUp);
    fStringPool = new (fMemoryManager) XMLStringPool(109, fMemoryManager);
    // MatchPath will complain if the expression starts with '/', add a "." in front of it and start from the document root
    if(*expression==chForwardSlash)
    {
        fExpression=(XMLCh*)fMemoryManager->allocate((XMLString::stringLen(expression)+2)*sizeof(XMLCh));
        *fExpression = chPeriod;
        *(fExpression+1) = chNull;
        XMLString::catString(fExpression, expression);
        fMoveToRoot=true;
    }
    else
        fExpression=XMLString::replicate(expression);

    try
    {
        WrapperForXPathNSResolver wrappedResolver(fStringPool, resolver, fMemoryManager);
        fParsedExpression = new (fMemoryManager) MatchXPath(fExpression, fStringPool, &wrappedResolver, 0, true, fMemoryManager);
    }
    catch(const XPathException& )
    {
        throw DOMXPathException(DOMXPathException::INVALID_EXPRESSION_ERR, 0, fMemoryManager);
    }
    catch(const OutOfMemoryException&)
    {
        cleanup.release();

        throw;
    }

    cleanup.release();
}
Esempio n. 4
0
DOMNode* DOMXPathResultImpl::getNodeValue() const
{
  if(fType == ANY_UNORDERED_NODE_TYPE || fType == FIRST_ORDERED_NODE_TYPE)
  {
    return fSnapshot->size() > 0 ? fSnapshot->elementAt(0) : 0;
  }
  else if (fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
  {
    return fIndex < fSnapshot->size() ? fSnapshot->elementAt(fIndex) : 0;
  }
  else
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
DOMXPathResult* DOMXPathExpressionImpl::evaluate(const DOMNode *contextNode,
                                                 DOMXPathResult::ResultType type,
                                                 DOMXPathResult* result) const
{
    if(type!=DOMXPathResult::FIRST_ORDERED_NODE_TYPE && type!=DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE &&
       type!=DOMXPathResult::ANY_UNORDERED_NODE_TYPE && type!=DOMXPathResult::UNORDERED_NODE_SNAPSHOT_TYPE)
        throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);

    if(contextNode==NULL || contextNode->getNodeType()!=DOMNode::ELEMENT_NODE)
        throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);

    JanitorMemFunCall<DOMXPathResultImpl> r_cleanup (
      0, &DOMXPathResultImpl::release);
    DOMXPathResultImpl* r=(DOMXPathResultImpl*)result;
    if(r==NULL)
    {
      r=new (fMemoryManager) DOMXPathResultImpl(type, fMemoryManager);
      r_cleanup.reset (r);
    }
    else
        r->reset(type);

    XPathMatcher matcher(fParsedExpression, fMemoryManager);
    matcher.startDocumentFragment();

    if(fMoveToRoot)
    {
        contextNode=contextNode->getOwnerDocument();
        if(contextNode==NULL)
            throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);

        QName qName(contextNode->getNodeName(), 0, fMemoryManager);
        SchemaElementDecl elemDecl(&qName);
        RefVectorOf<XMLAttr> attrList(0, true, fMemoryManager);
        matcher.startElement(elemDecl, 0, XMLUni::fgZeroLenString, attrList, 0);
        DOMNode* child=contextNode->getFirstChild();
        while(child)
        {
            if(child->getNodeType()==DOMNode::ELEMENT_NODE)
                testNode(&matcher, r, (DOMElement*)child);
            child=child->getNextSibling();
        }
        matcher.endElement(elemDecl, XMLUni::fgZeroLenString);
    }
    else
        testNode(&matcher, r, (DOMElement*)contextNode);

    r_cleanup.release ();
    return r;
}
Esempio n. 6
0
bool DOMXPathResultImpl::getInvalidIteratorState() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 7
0
bool DOMXPathResultImpl::iterateNext()
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 8
0
const XMLCh* DOMXPathResultImpl::getStringValue() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 9
0
double DOMXPathResultImpl::getNumberValue() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 10
0
int DOMXPathResultImpl::getIntegerValue() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 11
0
bool DOMXPathResultImpl::getBooleanValue() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 12
0
bool DOMXPathResultImpl::isNode() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}
Esempio n. 13
0
const DOMTypeInfo* DOMXPathResultImpl::getTypeInfo() const
{
    throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
}