2 * XSLTemplate/XSLProcessor support
4 * Copyright 2011 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 IXSLTemplate IXSLTemplate_iface;
55 IXSLProcessor IXSLProcessor_iface;
58 xsltemplate *stylesheet;
65 static HRESULT XSLProcessor_create(xsltemplate*, IXSLProcessor**);
67 static inline xsltemplate *impl_from_IXSLTemplate( IXSLTemplate *iface )
69 return CONTAINING_RECORD(iface, xsltemplate, IXSLTemplate_iface);
72 static inline xslprocessor *impl_from_IXSLProcessor( IXSLProcessor *iface )
74 return CONTAINING_RECORD(iface, xslprocessor, IXSLProcessor_iface);
77 static void xsltemplate_set_node( xsltemplate *This, IXMLDOMNode *node )
79 if (This->node) IXMLDOMNode_Release(This->node);
81 if (node) IXMLDOMNode_AddRef(node);
84 static HRESULT WINAPI xsltemplate_QueryInterface(
89 xsltemplate *This = impl_from_IXSLTemplate( iface );
90 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
92 if ( IsEqualGUID( riid, &IID_IXSLTemplate ) ||
93 IsEqualGUID( riid, &IID_IDispatch ) ||
94 IsEqualGUID( riid, &IID_IUnknown ) )
98 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
100 return *ppvObject ? S_OK : E_NOINTERFACE;
104 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
106 return E_NOINTERFACE;
109 IUnknown_AddRef((IUnknown*)*ppvObject);
113 static ULONG WINAPI xsltemplate_AddRef( IXSLTemplate *iface )
115 xsltemplate *This = impl_from_IXSLTemplate( iface );
116 ULONG ref = InterlockedIncrement( &This->ref );
117 TRACE("(%p)->(%d)\n", This, ref);
121 static ULONG WINAPI xsltemplate_Release( IXSLTemplate *iface )
123 xsltemplate *This = impl_from_IXSLTemplate( iface );
124 ULONG ref = InterlockedDecrement( &This->ref );
126 TRACE("(%p)->(%d)\n", This, ref);
129 if (This->node) IXMLDOMNode_Release( This->node );
130 release_dispex(&This->dispex);
137 static HRESULT WINAPI xsltemplate_GetTypeInfoCount( IXSLTemplate *iface, UINT* pctinfo )
139 xsltemplate *This = impl_from_IXSLTemplate( iface );
140 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
143 static HRESULT WINAPI xsltemplate_GetTypeInfo(
145 UINT iTInfo, LCID lcid,
146 ITypeInfo** ppTInfo )
148 xsltemplate *This = impl_from_IXSLTemplate( iface );
149 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
150 iTInfo, lcid, ppTInfo);
153 static HRESULT WINAPI xsltemplate_GetIDsOfNames(
155 REFIID riid, LPOLESTR* rgszNames,
156 UINT cNames, LCID lcid, DISPID* rgDispId )
158 xsltemplate *This = impl_from_IXSLTemplate( iface );
159 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
160 riid, rgszNames, cNames, lcid, rgDispId);
163 static HRESULT WINAPI xsltemplate_Invoke(
165 DISPID dispIdMember, REFIID riid, LCID lcid,
166 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
167 EXCEPINFO* pExcepInfo, UINT* puArgErr )
169 xsltemplate *This = impl_from_IXSLTemplate( iface );
170 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
171 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
174 static HRESULT WINAPI xsltemplate_putref_stylesheet( IXSLTemplate *iface,
177 xsltemplate *This = impl_from_IXSLTemplate( iface );
179 TRACE("(%p)->(%p)\n", This, node);
183 xsltemplate_set_node(This, NULL);
187 /* FIXME: test for document type */
188 xsltemplate_set_node(This, node);
193 static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
196 xsltemplate *This = impl_from_IXSLTemplate( iface );
198 FIXME("(%p)->(%p): stub\n", This, node);
202 static HRESULT WINAPI xsltemplate_createProcessor( IXSLTemplate *iface,
203 IXSLProcessor **processor)
205 xsltemplate *This = impl_from_IXSLTemplate( iface );
207 TRACE("(%p)->(%p)\n", This, processor);
209 if (!processor) return E_INVALIDARG;
211 return XSLProcessor_create(This, processor);
214 static const struct IXSLTemplateVtbl XSLTemplateVtbl =
216 xsltemplate_QueryInterface,
219 xsltemplate_GetTypeInfoCount,
220 xsltemplate_GetTypeInfo,
221 xsltemplate_GetIDsOfNames,
223 xsltemplate_putref_stylesheet,
224 xsltemplate_get_stylesheet,
225 xsltemplate_createProcessor
228 static const tid_t xsltemplate_iface_tids[] = {
233 static dispex_static_data_t xsltemplate_dispex = {
237 xsltemplate_iface_tids
240 HRESULT XSLTemplate_create(IUnknown *outer, void **ppObj)
244 TRACE("(%p, %p)\n", outer, ppObj);
246 if(outer) FIXME("support aggregation, outer\n");
248 This = heap_alloc( sizeof (*This) );
250 return E_OUTOFMEMORY;
252 This->IXSLTemplate_iface.lpVtbl = &XSLTemplateVtbl;
255 init_dispex(&This->dispex, (IUnknown*)&This->IXSLTemplate_iface, &xsltemplate_dispex);
257 *ppObj = &This->IXSLTemplate_iface;
259 TRACE("returning iface %p\n", *ppObj);
264 /*** IXSLProcessor ***/
265 static HRESULT WINAPI xslprocessor_QueryInterface(
266 IXSLProcessor *iface,
270 xslprocessor *This = impl_from_IXSLProcessor( iface );
271 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
273 if ( IsEqualGUID( riid, &IID_IXSLProcessor ) ||
274 IsEqualGUID( riid, &IID_IDispatch ) ||
275 IsEqualGUID( riid, &IID_IUnknown ) )
279 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
281 return *ppvObject ? S_OK : E_NOINTERFACE;
285 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
287 return E_NOINTERFACE;
290 IUnknown_AddRef((IUnknown*)*ppvObject);
294 static ULONG WINAPI xslprocessor_AddRef( IXSLProcessor *iface )
296 xslprocessor *This = impl_from_IXSLProcessor( iface );
297 ULONG ref = InterlockedIncrement( &This->ref );
298 TRACE("(%p)->(%d)\n", This, ref);
302 static ULONG WINAPI xslprocessor_Release( IXSLProcessor *iface )
304 xslprocessor *This = impl_from_IXSLProcessor( iface );
305 ULONG ref = InterlockedDecrement( &This->ref );
307 TRACE("(%p)->(%d)\n", This, ref);
310 if (This->input) IXMLDOMNode_Release(This->input);
311 if (This->output) IStream_Release(This->output);
312 SysFreeString(This->outstr);
313 IXSLTemplate_Release(&This->stylesheet->IXSLTemplate_iface);
314 release_dispex(&This->dispex);
321 static HRESULT WINAPI xslprocessor_GetTypeInfoCount( IXSLProcessor *iface, UINT* pctinfo )
323 xslprocessor *This = impl_from_IXSLProcessor( iface );
324 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
327 static HRESULT WINAPI xslprocessor_GetTypeInfo(
328 IXSLProcessor *iface,
329 UINT iTInfo, LCID lcid,
330 ITypeInfo** ppTInfo )
332 xslprocessor *This = impl_from_IXSLProcessor( iface );
333 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
334 iTInfo, lcid, ppTInfo);
337 static HRESULT WINAPI xslprocessor_GetIDsOfNames(
338 IXSLProcessor *iface,
339 REFIID riid, LPOLESTR* rgszNames,
340 UINT cNames, LCID lcid, DISPID* rgDispId )
342 xslprocessor *This = impl_from_IXSLProcessor( iface );
343 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
344 riid, rgszNames, cNames, lcid, rgDispId);
347 static HRESULT WINAPI xslprocessor_Invoke(
348 IXSLProcessor *iface,
349 DISPID dispIdMember, REFIID riid, LCID lcid,
350 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
351 EXCEPINFO* pExcepInfo, UINT* puArgErr )
353 xslprocessor *This = impl_from_IXSLProcessor( iface );
354 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
355 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
358 static HRESULT WINAPI xslprocessor_put_input( IXSLProcessor *iface, VARIANT input )
360 xslprocessor *This = impl_from_IXSLProcessor( iface );
361 IXMLDOMNode *input_node;
364 TRACE("(%p)->(%s)\n", This, debugstr_variant(&input));
366 /* try IXMLDOMNode directly first */
367 if (V_VT(&input) == VT_UNKNOWN)
368 hr = IUnknown_QueryInterface(V_UNKNOWN(&input), &IID_IXMLDOMNode, (void**)&input_node);
369 else if (V_VT(&input) == VT_DISPATCH)
370 hr = IDispatch_QueryInterface(V_DISPATCH(&input), &IID_IXMLDOMNode, (void**)&input_node);
373 IXMLDOMDocument *doc;
375 hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
380 hr = IXMLDOMDocument_load(doc, input, &b);
382 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&input_node);
383 IXMLDOMDocument_Release(doc);
389 if (This->input) IXMLDOMNode_Release(This->input);
390 This->input = input_node;
396 static HRESULT WINAPI xslprocessor_get_input( IXSLProcessor *iface, VARIANT *input )
398 xslprocessor *This = impl_from_IXSLProcessor( iface );
400 FIXME("(%p)->(%p): stub\n", This, input);
404 static HRESULT WINAPI xslprocessor_get_ownerTemplate(
405 IXSLProcessor *iface,
406 IXSLTemplate **template)
408 xslprocessor *This = impl_from_IXSLProcessor( iface );
410 FIXME("(%p)->(%p): stub\n", This, template);
414 static HRESULT WINAPI xslprocessor_setStartMode(
415 IXSLProcessor *iface,
419 xslprocessor *This = impl_from_IXSLProcessor( iface );
421 FIXME("(%p)->(%s %s): stub\n", This, debugstr_w(p), debugstr_w(uri));
425 static HRESULT WINAPI xslprocessor_get_startMode(
426 IXSLProcessor *iface,
429 xslprocessor *This = impl_from_IXSLProcessor( iface );
431 FIXME("(%p)->(%p): stub\n", This, p);
435 static HRESULT WINAPI xslprocessor_get_startModeURI(
436 IXSLProcessor *iface,
439 xslprocessor *This = impl_from_IXSLProcessor( iface );
441 FIXME("(%p)->(%p): stub\n", This, uri);
445 static HRESULT WINAPI xslprocessor_put_output(
446 IXSLProcessor *iface,
449 xslprocessor *This = impl_from_IXSLProcessor( iface );
453 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_variant(&output));
455 switch (V_VT(&output))
462 hr = IUnknown_QueryInterface(V_UNKNOWN(&output), &IID_IStream, (void**)&stream);
470 if (This->output) IStream_Release(This->output);
471 This->output = stream;
477 static HRESULT WINAPI xslprocessor_get_output(
478 IXSLProcessor *iface,
481 xslprocessor *This = impl_from_IXSLProcessor( iface );
483 TRACE("(%p)->(%p)\n", This, output);
485 if (!output) return E_INVALIDARG;
489 V_VT(output) = VT_UNKNOWN;
490 V_UNKNOWN(output) = (IUnknown*)This->output;
491 IStream_AddRef(This->output);
493 else if (This->outstr)
495 V_VT(output) = VT_BSTR;
496 V_BSTR(output) = SysAllocString(This->outstr);
499 V_VT(output) = VT_EMPTY;
504 static HRESULT WINAPI xslprocessor_transform(
505 IXSLProcessor *iface,
508 xslprocessor *This = impl_from_IXSLProcessor( iface );
511 TRACE("(%p)->(%p)\n", This, ret);
513 if (!ret) return E_INVALIDARG;
515 SysFreeString(This->outstr);
516 hr = IXMLDOMNode_transformNode(This->input, This->stylesheet->node, &This->outstr);
523 /* output to stream */
524 hr = IStream_Write(This->output, This->outstr, SysStringByteLen(This->outstr), &len);
525 *ret = len == SysStringByteLen(This->outstr) ? VARIANT_TRUE : VARIANT_FALSE;
529 *ret = VARIANT_FALSE;
534 static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
536 xslprocessor *This = impl_from_IXSLProcessor( iface );
538 FIXME("(%p): stub\n", This);
542 static HRESULT WINAPI xslprocessor_get_readyState(
543 IXSLProcessor *iface,
546 xslprocessor *This = impl_from_IXSLProcessor( iface );
548 FIXME("(%p)->(%p): stub\n", This, state);
552 static HRESULT WINAPI xslprocessor_addParameter(
553 IXSLProcessor *iface,
558 xslprocessor *This = impl_from_IXSLProcessor( iface );
560 FIXME("(%p)->(%s %s %s): stub\n", This, debugstr_w(p), debugstr_variant(&var),
565 static HRESULT WINAPI xslprocessor_addObject(
566 IXSLProcessor *iface,
570 xslprocessor *This = impl_from_IXSLProcessor( iface );
572 FIXME("(%p)->(%p %s): stub\n", This, obj, debugstr_w(uri));
576 static HRESULT WINAPI xslprocessor_get_stylesheet(
577 IXSLProcessor *iface,
580 xslprocessor *This = impl_from_IXSLProcessor( iface );
582 FIXME("(%p)->(%p): stub\n", This, node);
586 static const struct IXSLProcessorVtbl XSLProcessorVtbl =
588 xslprocessor_QueryInterface,
590 xslprocessor_Release,
591 xslprocessor_GetTypeInfoCount,
592 xslprocessor_GetTypeInfo,
593 xslprocessor_GetIDsOfNames,
595 xslprocessor_put_input,
596 xslprocessor_get_input,
597 xslprocessor_get_ownerTemplate,
598 xslprocessor_setStartMode,
599 xslprocessor_get_startMode,
600 xslprocessor_get_startModeURI,
601 xslprocessor_put_output,
602 xslprocessor_get_output,
603 xslprocessor_transform,
605 xslprocessor_get_readyState,
606 xslprocessor_addParameter,
607 xslprocessor_addObject,
608 xslprocessor_get_stylesheet
611 static const tid_t xslprocessor_iface_tids[] = {
616 static dispex_static_data_t xslprocessor_dispex = {
620 xslprocessor_iface_tids
623 HRESULT XSLProcessor_create(xsltemplate *template, IXSLProcessor **ppObj)
627 TRACE("(%p)\n", ppObj);
629 This = heap_alloc( sizeof (*This) );
631 return E_OUTOFMEMORY;
633 This->IXSLProcessor_iface.lpVtbl = &XSLProcessorVtbl;
638 This->stylesheet = template;
639 IXSLTemplate_AddRef(&template->IXSLTemplate_iface);
640 init_dispex(&This->dispex, (IUnknown*)&This->IXSLProcessor_iface, &xslprocessor_dispex);
642 *ppObj = &This->IXSLProcessor_iface;
644 TRACE("returning iface %p\n", *ppObj);