JSXSLTProcessor.cpp [plain text]
#include "config.h"
#if ENABLE(XSLT)
#include "JSXSLTProcessor.h"
#include "XSLTProcessor.h"
#include "JSXSLTProcessor.lut.h"
#include "kjs_dom.h"
#include "JSDocument.h"
#include "Document.h"
#include "DocumentFragment.h"
using namespace WebCore;
namespace KJS {
const ClassInfo JSXSLTProcessor::info = { "XSLTProcessor", 0, 0 };
KJS_DEFINE_PROTOTYPE(XSLTProcessorPrototype)
KJS_IMPLEMENT_PROTOTYPE("XSLTProcessor", XSLTProcessorPrototype)
JSXSLTProcessor::JSXSLTProcessor(JSObject* prototype)
: DOMObject(prototype)
, m_impl(new XSLTProcessor())
{
}
JSXSLTProcessor::~JSXSLTProcessor()
{
ScriptInterpreter::forgetDOMObject(m_impl.get());
}
JSValue* jsXSLTProcessorPrototypeFunctionImportStylesheet(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
JSValue *nodeVal = args[0];
if (nodeVal->isObject(&JSNode::info)) {
JSNode* node = static_cast<JSNode*>(nodeVal);
processor.importStylesheet(node->impl());
return jsUndefined();
}
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionTransformToFragment(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
JSValue *nodeVal = args[0];
JSValue *docVal = args[1];
if (nodeVal->isObject(&JSNode::info) && docVal->isObject(&JSDocument::info)) {
WebCore::Node* node = static_cast<JSNode*>(nodeVal)->impl();
Document* doc = static_cast<Document*>(static_cast<JSDocument *>(docVal)->impl());
return toJS(exec, processor.transformToFragment(node, doc).get());
}
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionTransformToDocument(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
JSValue *nodeVal = args[0];
if (nodeVal->isObject(&JSNode::info)) {
JSNode* node = static_cast<JSNode*>(nodeVal);
RefPtr<Document> resultDocument = processor.transformToDocument(node->impl());
if (resultDocument)
return toJS(exec, resultDocument.get());
return jsUndefined();
}
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionSetParameter(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
if (args[1]->isUndefinedOrNull() || args[2]->isUndefinedOrNull())
return jsUndefined(); String namespaceURI = args[0]->toString(exec);
String localName = args[1]->toString(exec);
String value = args[2]->toString(exec);
processor.setParameter(namespaceURI, localName, value);
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionGetParameter(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
if (args[1]->isUndefinedOrNull())
return jsUndefined();
String namespaceURI = args[0]->toString(exec);
String localName = args[1]->toString(exec);
String value = processor.getParameter(namespaceURI, localName);
if (!value.isNull())
return jsString(value);
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionRemoveParameter(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
if (args[1]->isUndefinedOrNull())
return jsUndefined();
String namespaceURI = args[0]->toString(exec);
String localName = args[1]->toString(exec);
processor.removeParameter(namespaceURI, localName);
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionClearParameters(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
processor.clearParameters();
return jsUndefined();
}
JSValue* jsXSLTProcessorPrototypeFunctionReset(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
processor.reset();
return jsUndefined();
}
XSLTProcessorConstructorImp::XSLTProcessorConstructorImp(ExecState *exec)
: DOMObject(exec->lexicalGlobalObject()->objectPrototype())
{
putDirect(exec->propertyNames().prototype, XSLTProcessorPrototype::self(exec), None);
}
bool XSLTProcessorConstructorImp::implementsConstruct() const
{
return true;
}
JSObject* XSLTProcessorConstructorImp::construct(ExecState* exec, const List& args)
{
return new JSXSLTProcessor(XSLTProcessorPrototype::self(exec));
}
}
#endif // ENABLE(XSLT)