WebCore/xml/XPathEvaluator.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright 2005 Frerich Raabe <raabe@kde.org>
       
     3  * Copyright (C) 2006 Apple Computer, Inc.
       
     4  *
       
     5  * Redistribution and use in source and binary forms, with or without
       
     6  * modification, are permitted provided that the following conditions
       
     7  * are met:
       
     8  * 
       
     9  * 1. Redistributions of source code must retain the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer.
       
    11  * 2. Redistributions in binary form must reproduce the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer in the
       
    13  *    documentation and/or other materials provided with the distribution.
       
    14  * 
       
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
       
    17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
       
    18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
       
    19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
       
    20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    25  */
       
    26 
       
    27 #include "config.h"
       
    28 #include "XPathEvaluator.h"
       
    29 
       
    30 #if ENABLE(XPATH)
       
    31 
       
    32 #include "ExceptionCode.h"
       
    33 #include "NativeXPathNSResolver.h"
       
    34 #include "Node.h"
       
    35 #include "XPathExpression.h"
       
    36 #include "XPathResult.h"
       
    37 #include "XPathUtil.h"
       
    38 
       
    39 namespace WebCore {
       
    40 
       
    41 using namespace XPath;
       
    42     
       
    43 PassRefPtr<XPathExpression> XPathEvaluator::createExpression(const String& expression,
       
    44                                                              XPathNSResolver* resolver,
       
    45                                                              ExceptionCode& ec)
       
    46 {
       
    47     return XPathExpression::createExpression(expression, resolver, ec);
       
    48 }
       
    49 
       
    50 PassRefPtr<XPathNSResolver> XPathEvaluator::createNSResolver(Node* nodeResolver)
       
    51 {
       
    52     return NativeXPathNSResolver::create(nodeResolver);
       
    53 }
       
    54 
       
    55 PassRefPtr<XPathResult> XPathEvaluator::evaluate(const String& expression,
       
    56                                                  Node* contextNode,
       
    57                                                  XPathNSResolver* resolver,
       
    58                                                  unsigned short type,
       
    59                                                  XPathResult* result,
       
    60                                                  ExceptionCode& ec)
       
    61 {
       
    62     if (!isValidContextNode(contextNode)) {
       
    63         ec = NOT_SUPPORTED_ERR;
       
    64         return 0;
       
    65     }
       
    66 
       
    67     ec = 0;
       
    68     RefPtr<XPathExpression> expr = createExpression(expression, resolver, ec);
       
    69     if (ec)
       
    70         return 0;
       
    71     
       
    72     return expr->evaluate(contextNode, type, result, ec);
       
    73 }
       
    74 
       
    75 }
       
    76 
       
    77 #endif // ENABLE(XPATH)