JSXSLTProcessor.cpp [plain text]
#include "config.h"
#ifdef KHTML_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, 0 };
KJS_DEFINE_PROTOTYPE(XSLTProcessorProto)
KJS_IMPLEMENT_PROTOFUNC(XSLTProcessorProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("XSLTProcessor", XSLTProcessorProto, XSLTProcessorProtoFunc)
JSXSLTProcessor::JSXSLTProcessor(ExecState *exec) : m_impl(new XSLTProcessor())
{
setPrototype(XSLTProcessorProto::self(exec));
}
JSXSLTProcessor::~JSXSLTProcessor()
{
ScriptInterpreter::forgetDOMObject(m_impl.get());
}
JSValue *XSLTProcessorProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{
if (!thisObj->inherits(&KJS::JSXSLTProcessor::info))
return throwError(exec, TypeError);
XSLTProcessor &processor = *static_cast<JSXSLTProcessor *>(thisObj)->impl();
switch (id) {
case JSXSLTProcessor::ImportStylesheet:
{
JSValue *nodeVal = args[0];
if (nodeVal->isObject(&DOMNode::info)) {
DOMNode *node = static_cast<DOMNode *>(nodeVal);
processor.importStylesheet(node->impl());
return jsUndefined();
}
break;
}
case JSXSLTProcessor::TransformToFragment:
{
JSValue *nodeVal = args[0];
JSValue *docVal = args[1];
if (nodeVal->isObject(&DOMNode::info) && docVal->isObject(&JSDocument::info)) {
Node* node = static_cast<DOMNode *>(nodeVal)->impl();
Document* doc = static_cast<Document*>(static_cast<JSDocument *>(docVal)->impl());
return toJS(exec, processor.transformToFragment(node, doc).get());
}
break;
}
case JSXSLTProcessor::TransformToDocument:
{
JSValue *nodeVal = args[0];
if (nodeVal->isObject(&DOMNode::info)) {
DOMNode *node = static_cast<DOMNode *>(nodeVal);
RefPtr<Document> resultDocument = processor.transformToDocument(node->impl());
if (resultDocument)
return toJS(exec, resultDocument.get());
return jsUndefined();
}
break;
}
case JSXSLTProcessor::SetParameter:
{
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.impl(), localName.impl(), value.impl());
return jsUndefined();
}
case JSXSLTProcessor::GetParameter:
{
if (args[1]->isUndefinedOrNull())
return jsUndefined();
String namespaceURI = args[0]->toString(exec);
String localName = args[1]->toString(exec);
StringImpl *value = processor.getParameter(namespaceURI.impl(), localName.impl()).get();
if (value)
return jsString(UString(String(value)));
return jsUndefined();
}
case JSXSLTProcessor::RemoveParameter:
{
if (args[1]->isUndefinedOrNull())
return jsUndefined();
String namespaceURI = args[0]->toString(exec);
String localName = args[1]->toString(exec);
processor.removeParameter(namespaceURI.impl(), localName.impl());
return jsUndefined();
}
case JSXSLTProcessor::ClearParameters:
processor.clearParameters();
return jsUndefined();
case JSXSLTProcessor::Reset:
processor.reset();
return jsUndefined();
}
return jsUndefined();
}
XSLTProcessorConstructorImp::XSLTProcessorConstructorImp(ExecState *exec)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
putDirect(prototypePropertyName, XSLTProcessorProto::self(exec), None);
}
}
#endif // KHTML_XSLT