1/* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include "config.h" 32#include "V8XSLTProcessor.h" 33 34#include "Document.h" 35#include "DocumentFragment.h" 36#include "Node.h" 37 38#include "V8Binding.h" 39#include "V8Document.h" 40#include "V8DocumentFragment.h" 41#include "V8Node.h" 42#include "V8Proxy.h" 43#include "XSLTProcessor.h" 44 45#include <wtf/RefPtr.h> 46 47namespace WebCore { 48 49v8::Handle<v8::Value> V8XSLTProcessor::constructorCallback(const v8::Arguments& args) 50{ 51 INC_STATS("DOM.XSLTProcessor.Constructor"); 52 return V8Proxy::constructDOMObject<XSLTProcessor>(args, &info); 53} 54 55 56v8::Handle<v8::Value> V8XSLTProcessor::importStylesheetCallback(const v8::Arguments& args) 57{ 58 INC_STATS("DOM.XSLTProcessor.importStylesheet"); 59 if (!V8Node::HasInstance(args[0])) 60 return v8::Undefined(); 61 62 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 63 64 Node* node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); 65 imp->importStylesheet(node); 66 return v8::Undefined(); 67} 68 69 70v8::Handle<v8::Value> V8XSLTProcessor::transformToFragmentCallback(const v8::Arguments& args) 71{ 72 INC_STATS("DOM.XSLTProcessor.transformToFragment"); 73 if (!V8Node::HasInstance(args[0]) || !V8Document::HasInstance(args[1])) 74 return v8::Undefined(); 75 76 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 77 78 Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); 79 Document* owner = V8Document::toNative(v8::Handle<v8::Object>::Cast(args[1])); 80 RefPtr<DocumentFragment> result = imp->transformToFragment(source, owner); 81 return toV8(result.release()); 82} 83 84 85v8::Handle<v8::Value> V8XSLTProcessor::transformToDocumentCallback(const v8::Arguments& args) 86{ 87 INC_STATS("DOM.XSLTProcessor.transformToDocument"); 88 89 if (!V8Node::HasInstance(args[0])) 90 return v8::Undefined(); 91 92 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 93 94 Node* source = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])); 95 if (!source) 96 return v8::Undefined(); 97 98 RefPtr<Document> result = imp->transformToDocument(source); 99 if (!result) 100 return v8::Undefined(); 101 102 return toV8(result.release()); 103} 104 105 106v8::Handle<v8::Value> V8XSLTProcessor::setParameterCallback(const v8::Arguments& args) 107{ 108 INC_STATS("DOM.XSLTProcessor.setParameter"); 109 if (isUndefinedOrNull(args[1]) || isUndefinedOrNull(args[2])) 110 return v8::Undefined(); 111 112 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 113 114 String namespaceURI = toWebCoreString(args[0]); 115 String localName = toWebCoreString(args[1]); 116 String value = toWebCoreString(args[2]); 117 imp->setParameter(namespaceURI, localName, value); 118 119 return v8::Undefined(); 120} 121 122 123v8::Handle<v8::Value> V8XSLTProcessor::getParameterCallback(const v8::Arguments& args) 124{ 125 INC_STATS("DOM.XSLTProcessor.getParameter"); 126 if (isUndefinedOrNull(args[1])) 127 return v8::Undefined(); 128 129 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 130 131 String namespaceURI = toWebCoreString(args[0]); 132 String localName = toWebCoreString(args[1]); 133 String result = imp->getParameter(namespaceURI, localName); 134 if (result.isNull()) 135 return v8::Undefined(); 136 137 return v8String(result); 138} 139 140v8::Handle<v8::Value> V8XSLTProcessor::removeParameterCallback(const v8::Arguments& args) 141{ 142 INC_STATS("DOM.XSLTProcessor.removeParameter"); 143 if (isUndefinedOrNull(args[1])) 144 return v8::Undefined(); 145 146 XSLTProcessor* imp = V8XSLTProcessor::toNative(args.Holder()); 147 148 String namespaceURI = toWebCoreString(args[0]); 149 String localName = toWebCoreString(args[1]); 150 imp->removeParameter(namespaceURI, localName); 151 return v8::Undefined(); 152} 153 154} // namespace WebCore 155