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 WIN32_NO_STATUS
30 # include <libxml/parser.h>
31 //# include <libxml/xmlerror.h>
36 //#include "winuser.h"
40 #include "msxml_private.h"
42 #include <wine/debug.h>
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
49 IXSLTemplate IXSLTemplate_iface
;
58 IXSLProcessor IXSLProcessor_iface
;
61 xsltemplate
*stylesheet
;
68 static HRESULT
XSLProcessor_create(xsltemplate
*, IXSLProcessor
**);
70 static inline xsltemplate
*impl_from_IXSLTemplate( IXSLTemplate
*iface
)
72 return CONTAINING_RECORD(iface
, xsltemplate
, IXSLTemplate_iface
);
75 static inline xslprocessor
*impl_from_IXSLProcessor( IXSLProcessor
*iface
)
77 return CONTAINING_RECORD(iface
, xslprocessor
, IXSLProcessor_iface
);
80 static void xsltemplate_set_node( xsltemplate
*This
, IXMLDOMNode
*node
)
82 if (This
->node
) IXMLDOMNode_Release(This
->node
);
84 if (node
) IXMLDOMNode_AddRef(node
);
87 static HRESULT WINAPI
xsltemplate_QueryInterface(
92 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
93 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
95 if ( IsEqualGUID( riid
, &IID_IXSLTemplate
) ||
96 IsEqualGUID( riid
, &IID_IDispatch
) ||
97 IsEqualGUID( riid
, &IID_IUnknown
) )
101 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
103 return *ppvObject
? S_OK
: E_NOINTERFACE
;
107 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
109 return E_NOINTERFACE
;
112 IUnknown_AddRef((IUnknown
*)*ppvObject
);
116 static ULONG WINAPI
xsltemplate_AddRef( IXSLTemplate
*iface
)
118 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
119 ULONG ref
= InterlockedIncrement( &This
->ref
);
120 TRACE("(%p)->(%d)\n", This
, ref
);
124 static ULONG WINAPI
xsltemplate_Release( IXSLTemplate
*iface
)
126 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
127 ULONG ref
= InterlockedDecrement( &This
->ref
);
129 TRACE("(%p)->(%d)\n", This
, ref
);
132 if (This
->node
) IXMLDOMNode_Release( This
->node
);
133 release_dispex(&This
->dispex
);
140 static HRESULT WINAPI
xsltemplate_GetTypeInfoCount( IXSLTemplate
*iface
, UINT
* pctinfo
)
142 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
143 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
146 static HRESULT WINAPI
xsltemplate_GetTypeInfo(
148 UINT iTInfo
, LCID lcid
,
149 ITypeInfo
** ppTInfo
)
151 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
152 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
153 iTInfo
, lcid
, ppTInfo
);
156 static HRESULT WINAPI
xsltemplate_GetIDsOfNames(
158 REFIID riid
, LPOLESTR
* rgszNames
,
159 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
161 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
162 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
163 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
166 static HRESULT WINAPI
xsltemplate_Invoke(
168 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
169 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
170 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
172 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
173 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
174 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
177 static HRESULT WINAPI
xsltemplate_putref_stylesheet( IXSLTemplate
*iface
,
180 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
182 TRACE("(%p)->(%p)\n", This
, node
);
186 xsltemplate_set_node(This
, NULL
);
190 /* FIXME: test for document type */
191 xsltemplate_set_node(This
, node
);
196 static HRESULT WINAPI
xsltemplate_get_stylesheet( IXSLTemplate
*iface
,
199 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
201 FIXME("(%p)->(%p): stub\n", This
, node
);
205 static HRESULT WINAPI
xsltemplate_createProcessor( IXSLTemplate
*iface
,
206 IXSLProcessor
**processor
)
208 xsltemplate
*This
= impl_from_IXSLTemplate( iface
);
210 TRACE("(%p)->(%p)\n", This
, processor
);
212 if (!processor
) return E_INVALIDARG
;
214 return XSLProcessor_create(This
, processor
);
217 static const struct IXSLTemplateVtbl XSLTemplateVtbl
=
219 xsltemplate_QueryInterface
,
222 xsltemplate_GetTypeInfoCount
,
223 xsltemplate_GetTypeInfo
,
224 xsltemplate_GetIDsOfNames
,
226 xsltemplate_putref_stylesheet
,
227 xsltemplate_get_stylesheet
,
228 xsltemplate_createProcessor
231 static const tid_t xsltemplate_iface_tids
[] = {
236 static dispex_static_data_t xsltemplate_dispex
= {
240 xsltemplate_iface_tids
243 HRESULT
XSLTemplate_create(IUnknown
*outer
, void **ppObj
)
247 TRACE("(%p, %p)\n", outer
, ppObj
);
249 if(outer
) FIXME("support aggregation, outer\n");
251 This
= heap_alloc( sizeof (*This
) );
253 return E_OUTOFMEMORY
;
255 This
->IXSLTemplate_iface
.lpVtbl
= &XSLTemplateVtbl
;
258 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IXSLTemplate_iface
, &xsltemplate_dispex
);
260 *ppObj
= &This
->IXSLTemplate_iface
;
262 TRACE("returning iface %p\n", *ppObj
);
267 /*** IXSLProcessor ***/
268 static HRESULT WINAPI
xslprocessor_QueryInterface(
269 IXSLProcessor
*iface
,
273 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
274 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
276 if ( IsEqualGUID( riid
, &IID_IXSLProcessor
) ||
277 IsEqualGUID( riid
, &IID_IDispatch
) ||
278 IsEqualGUID( riid
, &IID_IUnknown
) )
282 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
284 return *ppvObject
? S_OK
: E_NOINTERFACE
;
288 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
290 return E_NOINTERFACE
;
293 IUnknown_AddRef((IUnknown
*)*ppvObject
);
297 static ULONG WINAPI
xslprocessor_AddRef( IXSLProcessor
*iface
)
299 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
300 ULONG ref
= InterlockedIncrement( &This
->ref
);
301 TRACE("(%p)->(%d)\n", This
, ref
);
305 static ULONG WINAPI
xslprocessor_Release( IXSLProcessor
*iface
)
307 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
308 ULONG ref
= InterlockedDecrement( &This
->ref
);
310 TRACE("(%p)->(%d)\n", This
, ref
);
313 if (This
->input
) IXMLDOMNode_Release(This
->input
);
314 if (This
->output
) IStream_Release(This
->output
);
315 SysFreeString(This
->outstr
);
316 IXSLTemplate_Release(&This
->stylesheet
->IXSLTemplate_iface
);
317 release_dispex(&This
->dispex
);
324 static HRESULT WINAPI
xslprocessor_GetTypeInfoCount( IXSLProcessor
*iface
, UINT
* pctinfo
)
326 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
327 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
330 static HRESULT WINAPI
xslprocessor_GetTypeInfo(
331 IXSLProcessor
*iface
,
332 UINT iTInfo
, LCID lcid
,
333 ITypeInfo
** ppTInfo
)
335 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
336 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
337 iTInfo
, lcid
, ppTInfo
);
340 static HRESULT WINAPI
xslprocessor_GetIDsOfNames(
341 IXSLProcessor
*iface
,
342 REFIID riid
, LPOLESTR
* rgszNames
,
343 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
345 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
346 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
347 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
350 static HRESULT WINAPI
xslprocessor_Invoke(
351 IXSLProcessor
*iface
,
352 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
353 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
354 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
356 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
357 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
358 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
361 static HRESULT WINAPI
xslprocessor_put_input( IXSLProcessor
*iface
, VARIANT input
)
363 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
364 IXMLDOMNode
*input_node
;
367 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&input
));
369 /* try IXMLDOMNode directly first */
370 if (V_VT(&input
) == VT_UNKNOWN
)
371 hr
= IUnknown_QueryInterface(V_UNKNOWN(&input
), &IID_IXMLDOMNode
, (void**)&input_node
);
372 else if (V_VT(&input
) == VT_DISPATCH
)
373 hr
= IDispatch_QueryInterface(V_DISPATCH(&input
), &IID_IXMLDOMNode
, (void**)&input_node
);
376 IXMLDOMDocument
*doc
;
378 hr
= DOMDocument_create(MSXML_DEFAULT
, NULL
, (void**)&doc
);
383 hr
= IXMLDOMDocument_load(doc
, input
, &b
);
385 hr
= IXMLDOMDocument_QueryInterface(doc
, &IID_IXMLDOMNode
, (void**)&input_node
);
386 IXMLDOMDocument_Release(doc
);
392 if (This
->input
) IXMLDOMNode_Release(This
->input
);
393 This
->input
= input_node
;
399 static HRESULT WINAPI
xslprocessor_get_input( IXSLProcessor
*iface
, VARIANT
*input
)
401 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
403 FIXME("(%p)->(%p): stub\n", This
, input
);
407 static HRESULT WINAPI
xslprocessor_get_ownerTemplate(
408 IXSLProcessor
*iface
,
409 IXSLTemplate
**template)
411 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
413 FIXME("(%p)->(%p): stub\n", This
, template);
417 static HRESULT WINAPI
xslprocessor_setStartMode(
418 IXSLProcessor
*iface
,
422 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
424 FIXME("(%p)->(%s %s): stub\n", This
, debugstr_w(p
), debugstr_w(uri
));
428 static HRESULT WINAPI
xslprocessor_get_startMode(
429 IXSLProcessor
*iface
,
432 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
434 FIXME("(%p)->(%p): stub\n", This
, p
);
438 static HRESULT WINAPI
xslprocessor_get_startModeURI(
439 IXSLProcessor
*iface
,
442 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
444 FIXME("(%p)->(%p): stub\n", This
, uri
);
448 static HRESULT WINAPI
xslprocessor_put_output(
449 IXSLProcessor
*iface
,
452 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
456 FIXME("(%p)->(%s): semi-stub\n", This
, debugstr_variant(&output
));
458 switch (V_VT(&output
))
465 hr
= IUnknown_QueryInterface(V_UNKNOWN(&output
), &IID_IStream
, (void**)&stream
);
473 if (This
->output
) IStream_Release(This
->output
);
474 This
->output
= stream
;
480 static HRESULT WINAPI
xslprocessor_get_output(
481 IXSLProcessor
*iface
,
484 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
486 TRACE("(%p)->(%p)\n", This
, output
);
488 if (!output
) return E_INVALIDARG
;
492 V_VT(output
) = VT_UNKNOWN
;
493 V_UNKNOWN(output
) = (IUnknown
*)This
->output
;
494 IStream_AddRef(This
->output
);
496 else if (This
->outstr
)
498 V_VT(output
) = VT_BSTR
;
499 V_BSTR(output
) = SysAllocString(This
->outstr
);
502 V_VT(output
) = VT_EMPTY
;
507 static HRESULT WINAPI
xslprocessor_transform(
508 IXSLProcessor
*iface
,
511 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
514 TRACE("(%p)->(%p)\n", This
, ret
);
516 if (!ret
) return E_INVALIDARG
;
518 SysFreeString(This
->outstr
);
519 hr
= IXMLDOMNode_transformNode(This
->input
, This
->stylesheet
->node
, &This
->outstr
);
526 /* output to stream */
527 hr
= IStream_Write(This
->output
, This
->outstr
, SysStringByteLen(This
->outstr
), &len
);
528 *ret
= len
== SysStringByteLen(This
->outstr
) ? VARIANT_TRUE
: VARIANT_FALSE
;
532 *ret
= VARIANT_FALSE
;
537 static HRESULT WINAPI
xslprocessor_reset( IXSLProcessor
*iface
)
539 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
541 FIXME("(%p): stub\n", This
);
545 static HRESULT WINAPI
xslprocessor_get_readyState(
546 IXSLProcessor
*iface
,
549 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
551 FIXME("(%p)->(%p): stub\n", This
, state
);
555 static HRESULT WINAPI
xslprocessor_addParameter(
556 IXSLProcessor
*iface
,
561 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
563 FIXME("(%p)->(%s %s %s): stub\n", This
, debugstr_w(p
), debugstr_variant(&var
),
568 static HRESULT WINAPI
xslprocessor_addObject(
569 IXSLProcessor
*iface
,
573 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
575 FIXME("(%p)->(%p %s): stub\n", This
, obj
, debugstr_w(uri
));
579 static HRESULT WINAPI
xslprocessor_get_stylesheet(
580 IXSLProcessor
*iface
,
583 xslprocessor
*This
= impl_from_IXSLProcessor( iface
);
585 FIXME("(%p)->(%p): stub\n", This
, node
);
589 static const struct IXSLProcessorVtbl XSLProcessorVtbl
=
591 xslprocessor_QueryInterface
,
593 xslprocessor_Release
,
594 xslprocessor_GetTypeInfoCount
,
595 xslprocessor_GetTypeInfo
,
596 xslprocessor_GetIDsOfNames
,
598 xslprocessor_put_input
,
599 xslprocessor_get_input
,
600 xslprocessor_get_ownerTemplate
,
601 xslprocessor_setStartMode
,
602 xslprocessor_get_startMode
,
603 xslprocessor_get_startModeURI
,
604 xslprocessor_put_output
,
605 xslprocessor_get_output
,
606 xslprocessor_transform
,
608 xslprocessor_get_readyState
,
609 xslprocessor_addParameter
,
610 xslprocessor_addObject
,
611 xslprocessor_get_stylesheet
614 static const tid_t xslprocessor_iface_tids
[] = {
619 static dispex_static_data_t xslprocessor_dispex
= {
623 xslprocessor_iface_tids
626 HRESULT
XSLProcessor_create(xsltemplate
*template, IXSLProcessor
**ppObj
)
630 TRACE("(%p)\n", ppObj
);
632 This
= heap_alloc( sizeof (*This
) );
634 return E_OUTOFMEMORY
;
636 This
->IXSLProcessor_iface
.lpVtbl
= &XSLProcessorVtbl
;
641 This
->stylesheet
= template;
642 IXSLTemplate_AddRef(&template->IXSLTemplate_iface
);
643 init_dispex(&This
->dispex
, (IUnknown
*)&This
->IXSLProcessor_iface
, &xslprocessor_dispex
);
645 *ppObj
= &This
->IXSLProcessor_iface
;
647 TRACE("returning iface %p\n", *ppObj
);