Release 1.6-rc2.
[wine/testsucceed.git] / dlls / msxml3 / stylesheet.c
blob9106b404a03f61a813ecd52a39792858cf2bc328
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "msxml6.h"
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
43 typedef struct
45 DispatchEx dispex;
46 IXSLTemplate IXSLTemplate_iface;
47 LONG ref;
49 IXMLDOMNode *node;
50 } xsltemplate;
52 typedef struct
54 DispatchEx dispex;
55 IXSLProcessor IXSLProcessor_iface;
56 LONG ref;
58 xsltemplate *stylesheet;
59 IXMLDOMNode *input;
61 IStream *output;
62 BSTR outstr;
63 } xslprocessor;
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);
80 This->node = node;
81 if (node) IXMLDOMNode_AddRef(node);
84 static HRESULT WINAPI xsltemplate_QueryInterface(
85 IXSLTemplate *iface,
86 REFIID riid,
87 void** ppvObject )
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 ) )
96 *ppvObject = iface;
98 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
100 return *ppvObject ? S_OK : E_NOINTERFACE;
102 else
104 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
105 *ppvObject = NULL;
106 return E_NOINTERFACE;
109 IUnknown_AddRef((IUnknown*)*ppvObject);
110 return S_OK;
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);
118 return 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);
127 if ( ref == 0 )
129 if (This->node) IXMLDOMNode_Release( This->node );
130 release_dispex(&This->dispex);
131 heap_free( This );
134 return ref;
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(
144 IXSLTemplate *iface,
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(
154 IXSLTemplate *iface,
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(
164 IXSLTemplate *iface,
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,
175 IXMLDOMNode *node)
177 xsltemplate *This = impl_from_IXSLTemplate( iface );
179 TRACE("(%p)->(%p)\n", This, node);
181 if (!node)
183 xsltemplate_set_node(This, NULL);
184 return S_OK;
187 /* FIXME: test for document type */
188 xsltemplate_set_node(This, node);
190 return S_OK;
193 static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
194 IXMLDOMNode **node)
196 xsltemplate *This = impl_from_IXSLTemplate( iface );
198 FIXME("(%p)->(%p): stub\n", This, node);
199 return E_NOTIMPL;
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,
217 xsltemplate_AddRef,
218 xsltemplate_Release,
219 xsltemplate_GetTypeInfoCount,
220 xsltemplate_GetTypeInfo,
221 xsltemplate_GetIDsOfNames,
222 xsltemplate_Invoke,
223 xsltemplate_putref_stylesheet,
224 xsltemplate_get_stylesheet,
225 xsltemplate_createProcessor
228 static const tid_t xsltemplate_iface_tids[] = {
229 IXSLTemplate_tid,
233 static dispex_static_data_t xsltemplate_dispex = {
234 NULL,
235 IXSLTemplate_tid,
236 NULL,
237 xsltemplate_iface_tids
240 HRESULT XSLTemplate_create(IUnknown *outer, void **ppObj)
242 xsltemplate *This;
244 TRACE("(%p, %p)\n", outer, ppObj);
246 if(outer) FIXME("support aggregation, outer\n");
248 This = heap_alloc( sizeof (*This) );
249 if(!This)
250 return E_OUTOFMEMORY;
252 This->IXSLTemplate_iface.lpVtbl = &XSLTemplateVtbl;
253 This->ref = 1;
254 This->node = NULL;
255 init_dispex(&This->dispex, (IUnknown*)&This->IXSLTemplate_iface, &xsltemplate_dispex);
257 *ppObj = &This->IXSLTemplate_iface;
259 TRACE("returning iface %p\n", *ppObj);
261 return S_OK;
264 /*** IXSLProcessor ***/
265 static HRESULT WINAPI xslprocessor_QueryInterface(
266 IXSLProcessor *iface,
267 REFIID riid,
268 void** ppvObject )
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 ) )
277 *ppvObject = iface;
279 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
281 return *ppvObject ? S_OK : E_NOINTERFACE;
283 else
285 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
286 *ppvObject = NULL;
287 return E_NOINTERFACE;
290 IUnknown_AddRef((IUnknown*)*ppvObject);
291 return S_OK;
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);
299 return 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);
308 if ( ref == 0 )
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);
315 heap_free( This );
318 return ref;
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;
362 HRESULT hr;
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);
371 else
373 IXMLDOMDocument *doc;
375 hr = DOMDocument_create(MSXML_DEFAULT, NULL, (void**)&doc);
376 if (hr == S_OK)
378 VARIANT_BOOL b;
380 hr = IXMLDOMDocument_load(doc, input, &b);
381 if (hr == S_OK)
382 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&input_node);
383 IXMLDOMDocument_Release(doc);
387 if (hr == S_OK)
389 if (This->input) IXMLDOMNode_Release(This->input);
390 This->input = input_node;
393 return hr;
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);
401 return E_NOTIMPL;
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);
411 return E_NOTIMPL;
414 static HRESULT WINAPI xslprocessor_setStartMode(
415 IXSLProcessor *iface,
416 BSTR p,
417 BSTR uri)
419 xslprocessor *This = impl_from_IXSLProcessor( iface );
421 FIXME("(%p)->(%s %s): stub\n", This, debugstr_w(p), debugstr_w(uri));
422 return E_NOTIMPL;
425 static HRESULT WINAPI xslprocessor_get_startMode(
426 IXSLProcessor *iface,
427 BSTR *p)
429 xslprocessor *This = impl_from_IXSLProcessor( iface );
431 FIXME("(%p)->(%p): stub\n", This, p);
432 return E_NOTIMPL;
435 static HRESULT WINAPI xslprocessor_get_startModeURI(
436 IXSLProcessor *iface,
437 BSTR *uri)
439 xslprocessor *This = impl_from_IXSLProcessor( iface );
441 FIXME("(%p)->(%p): stub\n", This, uri);
442 return E_NOTIMPL;
445 static HRESULT WINAPI xslprocessor_put_output(
446 IXSLProcessor *iface,
447 VARIANT output)
449 xslprocessor *This = impl_from_IXSLProcessor( iface );
450 IStream *stream;
451 HRESULT hr;
453 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_variant(&output));
455 switch (V_VT(&output))
457 case VT_EMPTY:
458 stream = NULL;
459 hr = S_OK;
460 break;
461 case VT_UNKNOWN:
462 hr = IUnknown_QueryInterface(V_UNKNOWN(&output), &IID_IStream, (void**)&stream);
463 break;
464 default:
465 hr = E_FAIL;
468 if (hr == S_OK)
470 if (This->output) IStream_Release(This->output);
471 This->output = stream;
474 return hr;
477 static HRESULT WINAPI xslprocessor_get_output(
478 IXSLProcessor *iface,
479 VARIANT *output)
481 xslprocessor *This = impl_from_IXSLProcessor( iface );
483 TRACE("(%p)->(%p)\n", This, output);
485 if (!output) return E_INVALIDARG;
487 if (This->output)
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);
498 else
499 V_VT(output) = VT_EMPTY;
501 return S_OK;
504 static HRESULT WINAPI xslprocessor_transform(
505 IXSLProcessor *iface,
506 VARIANT_BOOL *ret)
508 xslprocessor *This = impl_from_IXSLProcessor( iface );
509 HRESULT hr;
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);
517 if (hr == S_OK)
519 if (This->output)
521 ULONG len = 0;
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;
528 else
529 *ret = VARIANT_FALSE;
531 return hr;
534 static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
536 xslprocessor *This = impl_from_IXSLProcessor( iface );
538 FIXME("(%p): stub\n", This);
539 return E_NOTIMPL;
542 static HRESULT WINAPI xslprocessor_get_readyState(
543 IXSLProcessor *iface,
544 LONG *state)
546 xslprocessor *This = impl_from_IXSLProcessor( iface );
548 FIXME("(%p)->(%p): stub\n", This, state);
549 return E_NOTIMPL;
552 static HRESULT WINAPI xslprocessor_addParameter(
553 IXSLProcessor *iface,
554 BSTR p,
555 VARIANT var,
556 BSTR uri)
558 xslprocessor *This = impl_from_IXSLProcessor( iface );
560 FIXME("(%p)->(%s %s %s): stub\n", This, debugstr_w(p), debugstr_variant(&var),
561 debugstr_w(uri));
562 return E_NOTIMPL;
565 static HRESULT WINAPI xslprocessor_addObject(
566 IXSLProcessor *iface,
567 IDispatch *obj,
568 BSTR uri)
570 xslprocessor *This = impl_from_IXSLProcessor( iface );
572 FIXME("(%p)->(%p %s): stub\n", This, obj, debugstr_w(uri));
573 return E_NOTIMPL;
576 static HRESULT WINAPI xslprocessor_get_stylesheet(
577 IXSLProcessor *iface,
578 IXMLDOMNode **node)
580 xslprocessor *This = impl_from_IXSLProcessor( iface );
582 FIXME("(%p)->(%p): stub\n", This, node);
583 return E_NOTIMPL;
586 static const struct IXSLProcessorVtbl XSLProcessorVtbl =
588 xslprocessor_QueryInterface,
589 xslprocessor_AddRef,
590 xslprocessor_Release,
591 xslprocessor_GetTypeInfoCount,
592 xslprocessor_GetTypeInfo,
593 xslprocessor_GetIDsOfNames,
594 xslprocessor_Invoke,
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,
604 xslprocessor_reset,
605 xslprocessor_get_readyState,
606 xslprocessor_addParameter,
607 xslprocessor_addObject,
608 xslprocessor_get_stylesheet
611 static const tid_t xslprocessor_iface_tids[] = {
612 IXSLProcessor_tid,
616 static dispex_static_data_t xslprocessor_dispex = {
617 NULL,
618 IXSLProcessor_tid,
619 NULL,
620 xslprocessor_iface_tids
623 HRESULT XSLProcessor_create(xsltemplate *template, IXSLProcessor **ppObj)
625 xslprocessor *This;
627 TRACE("(%p)\n", ppObj);
629 This = heap_alloc( sizeof (*This) );
630 if(!This)
631 return E_OUTOFMEMORY;
633 This->IXSLProcessor_iface.lpVtbl = &XSLProcessorVtbl;
634 This->ref = 1;
635 This->input = NULL;
636 This->output = NULL;
637 This->outstr = NULL;
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);
646 return S_OK;